net: qualcomm: prepare frame decoding for UART driver
authorStefan Wahren <stefan.wahren@i2se.com>
Mon, 29 May 2017 11:57:19 +0000 (13:57 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 30 May 2017 17:57:30 +0000 (13:57 -0400)
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qualcomm/qca_7k_common.c
drivers/net/ethernet/qualcomm/qca_7k_common.h
drivers/net/ethernet/qualcomm/qca_spi.c

index 6d17fbd47c6aebe8d7e8b56baf10d60063310079..0d3daa95cc7009359711a9a30d208f74aef76063 100644 (file)
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_by
 
                if (recv_byte != 0x00) {
                        /* first two bytes of length must be 0 */
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                }
                break;
        case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_by
        case QCAFRM_WAIT_AA4:
                if (recv_byte != 0xAA) {
                        ret = QCAFRM_NOHEAD;
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                } else {
                        handle->state--;
                }
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_by
                len = handle->offset;
                if (len > buf_len || len < QCAFRM_MIN_LEN) {
                        ret = QCAFRM_INVLEN;
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                } else {
                        handle->state = (enum qcafrm_state)(len + 1);
                        /* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_by
        case QCAFRM_WAIT_551:
                if (recv_byte != 0x55) {
                        ret = QCAFRM_NOTAIL;
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                } else {
                        handle->state = QCAFRM_WAIT_552;
                }
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_by
        case QCAFRM_WAIT_552:
                if (recv_byte != 0x55) {
                        ret = QCAFRM_NOTAIL;
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                } else {
                        ret = handle->offset;
                        /* Frame is fully received. */
-                       handle->state = QCAFRM_HW_LEN0;
+                       handle->state = handle->init;
                }
                break;
        }
index 5df7c65d887c6de60fa6218a3ab6d4fa3b9c9e72..07bdd6c4f728a41015b611cfd5a6e04ce839563a 100644 (file)
@@ -61,6 +61,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+       /* HW length is only available on SPI */
        QCAFRM_HW_LEN0 = 0x8000,
        QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
        QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -101,6 +102,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
        /*  Current decoding state */
        enum qcafrm_state state;
+       /* Initial state depends on connection type */
+       enum qcafrm_state init;
 
        /* Offset in buffer (borrowed for length too) */
        u16 offset;
@@ -113,9 +116,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-       handle->state = QCAFRM_HW_LEN0;
+       handle->init = QCAFRM_HW_LEN0;
+       handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
index 43cc7de0b39587636097d9b6583f5ead9d6f52f9..de78f60309a03c2600c9023a884d7a70d6cea18f 100644 (file)
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
        qca->intr_req = 1;
        qca->intr_svc = 0;
        qca->sync = QCASPI_SYNC_UNKNOWN;
-       qcafrm_fsm_init(&qca->frm_handle);
+       qcafrm_fsm_init_spi(&qca->frm_handle);
 
        qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
                                      qca, "%s", dev->name);