From patchwork Tue Oct 18 11:27:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 683643 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3syt9J353xz9ryn for ; Tue, 18 Oct 2016 22:28:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758894AbcJRL17 (ORCPT ); Tue, 18 Oct 2016 07:27:59 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:60374 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbcJRL15 (ORCPT ); Tue, 18 Oct 2016 07:27:57 -0400 Received: from duckbill-v2-sdk.fritz.box ([109.104.48.177]) by mrelayeu.kundenserver.de (mreue004) with ESMTPSA (Nemesis) id 0M0v6Z-1coI023PhP-00vAPs; Tue, 18 Oct 2016 13:27:49 +0200 From: Stefan Wahren To: "David S. Miller" , Greg Kroah-Hartman , Jiri Slaby Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wahren Subject: [PATCH v3 net-next 6/8] net: qualcomm: prepare frame decoding for UART driver Date: Tue, 18 Oct 2016 13:27:32 +0200 Message-Id: <1476790054-27174-7-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476790054-27174-1-git-send-email-stefan.wahren@i2se.com> References: <1476790054-27174-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K0:ZjoMUrwui9xwHSrS6VjyVKu/wjQHac5eIt9dPsEuDf7DMNpQ3nI VbWbyaAFfrOoX0u5E67zm0o1O0+f54SLfRICsn4iD1E0HXy3GuY3pZuhjz5iJsqPeV4u/Cs NaNwCv8Bmox8UoHZHfrgyC004NM/1iML452C+H3ddBTZVoSAJMBVJsza8YtTM7zBg6iulTr FHL2/BybvQ/zOAZEwoGww== X-UI-Out-Filterresults: notjunk:1; V01:K0:lt/umyThcFI=:20lDpO9T4xmVYVSVC+hAfC rBrNKJIZui3/Jd1p0wXbVzalKHFUcEOizOHb1OzW5xI/t7beGXoKAgqmAmj9D3Zr78Y9xgtfZ RRGtjqOPWm0KqCQz8bcIZRYYmIex95kC0/iGqFgy5gWEYO5jQ/menAjwJeiAV7F6QP1AAEgFH 3xS3t3vDWXKkkaopMRAslO8wo2Tx9JkO4jr4LCeXnBSDTfZQCK7vqQi/GJF/rFrckIBZe5t++ m7J0qZ94aufyzeY9wwIg0xxlPV30o2uSi9Mb9nfOXROG3EIcYwmqlqo0rYSpCARy0V6xR5Fjl 1vZrnL7F0p/AtB2XOhgIAesI/aDFvNj+SLn0trnsqhG75Ph6ig/eIa5yBUUQkhvlBz6QSwEEV coMC2kaNpz1UK0GJiN70V4uT8uoIWIo4yvicmHQPgNlFh5kEspt0BlvTlv1SGHSqIMIuNFT9k tT4cS1Fn5TOpmTKDR1fc2vFQ7TefN0My8kKlgdpqiDr6RhwVj339WZpejT5UBlv1ON0MNYML9 QGtfHdB9i8uxdlHHU2Lw1JXeaUgsN2A9O/GvXrjw//9Y/FJlT4f9+c9z4+oDFy0wljQ21QNo/ PzeUSQ+SOFwdhk7PNsHprifFBHEi8JgAffxPiuVLLjse+v8LwvmbaLch0Ct+xYHOTpJWbjqKw L1XALUENRA68by1T3r5+cpQEP6cBYmiQUUvipbHOMe84LmvdYo7YXJQfj1U+JugT1NKI= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/ethernet/qualcomm/qca_common.c | 12 ++++++------ drivers/net/ethernet/qualcomm/qca_common.h | 8 ++++++-- drivers/net/ethernet/qualcomm/qca_spi.c | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/qca_common.c b/drivers/net/ethernet/qualcomm/qca_common.c index 9020c57..7eefdad 100644 --- a/drivers/net/ethernet/qualcomm/qca_common.c +++ b/drivers/net/ethernet/qualcomm/qca_common.c @@ -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_ETHMINLEN) { 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; } diff --git a/drivers/net/ethernet/qualcomm/qca_common.h b/drivers/net/ethernet/qualcomm/qca_common.h index 0fafaaf..c93cfdf07 100644 --- a/drivers/net/ethernet/qualcomm/qca_common.h +++ b/drivers/net/ethernet/qualcomm/qca_common.h @@ -62,6 +62,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, @@ -102,6 +103,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) */ s16 offset; @@ -114,9 +117,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 diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c index e0a5020..36ac07d 100644 --- a/drivers/net/ethernet/qualcomm/qca_spi.c +++ b/drivers/net/ethernet/qualcomm/qca_spi.c @@ -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);