1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
3 * Copyright (c) 2011, 2012, Atheros Communications Inc.
4 * Copyright (c) 2014, I2SE GmbH
7 /* Atheros Ethernet framing. Every Ethernet frame is surrounded by an atheros
8 * frame while transmitted over a serial channel.
11 #ifndef _QCA_FRAMING_H
12 #define _QCA_FRAMING_H
14 #include <linux/if_ether.h>
15 #include <linux/if_vlan.h>
16 #include <linux/types.h>
18 /* Frame is currently being received */
19 #define QCAFRM_GATHER 0
21 /* No header byte while expecting it */
22 #define QCAFRM_NOHEAD (QCAFRM_ERR_BASE - 1)
24 /* No tailer byte while expecting it */
25 #define QCAFRM_NOTAIL (QCAFRM_ERR_BASE - 2)
27 /* Frame length is invalid */
28 #define QCAFRM_INVLEN (QCAFRM_ERR_BASE - 3)
30 /* Frame length is invalid */
31 #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
33 /* Min/Max Ethernet MTU: 46/1500 */
34 #define QCAFRM_MIN_MTU (ETH_ZLEN - ETH_HLEN)
35 #define QCAFRM_MAX_MTU ETH_DATA_LEN
37 /* Min/Max frame lengths */
38 #define QCAFRM_MIN_LEN (QCAFRM_MIN_MTU + ETH_HLEN)
39 #define QCAFRM_MAX_LEN (QCAFRM_MAX_MTU + VLAN_ETH_HLEN)
41 /* QCA7K header len */
42 #define QCAFRM_HEADER_LEN 8
44 /* QCA7K footer len */
45 #define QCAFRM_FOOTER_LEN 2
48 #define QCAFRM_ERR_BASE -1000
51 /* HW length is only available on SPI */
52 QCAFRM_HW_LEN0 = 0x8000,
53 QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
54 QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
55 QCAFRM_HW_LEN3 = QCAFRM_HW_LEN2 - 1,
57 /* Waiting first 0xAA of header */
58 QCAFRM_WAIT_AA1 = QCAFRM_HW_LEN3 - 1,
60 /* Waiting second 0xAA of header */
61 QCAFRM_WAIT_AA2 = QCAFRM_WAIT_AA1 - 1,
63 /* Waiting third 0xAA of header */
64 QCAFRM_WAIT_AA3 = QCAFRM_WAIT_AA2 - 1,
66 /* Waiting fourth 0xAA of header */
67 QCAFRM_WAIT_AA4 = QCAFRM_WAIT_AA3 - 1,
69 /* Waiting Byte 0-1 of length (litte endian) */
70 QCAFRM_WAIT_LEN_BYTE0 = QCAFRM_WAIT_AA4 - 1,
71 QCAFRM_WAIT_LEN_BYTE1 = QCAFRM_WAIT_AA4 - 2,
74 QCAFRM_WAIT_RSVD_BYTE1 = QCAFRM_WAIT_AA4 - 3,
75 QCAFRM_WAIT_RSVD_BYTE2 = QCAFRM_WAIT_AA4 - 4,
77 /* The frame length is used as the state until
78 * the end of the Ethernet frame
79 * Waiting for first 0x55 of footer
83 /* Waiting for second 0x55 of footer */
84 QCAFRM_WAIT_552 = QCAFRM_WAIT_551 - 1
87 /* Structure to maintain the frame decoding during reception. */
89 struct qcafrm_handle {
90 /* Current decoding state */
91 enum qcafrm_state state;
92 /* Initial state depends on connection type */
93 enum qcafrm_state init;
95 /* Offset in buffer (borrowed for length too) */
99 u16 qcafrm_create_header(u8 *buf, u16 len);
101 u16 qcafrm_create_footer(u8 *buf);
103 static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
105 handle->init = QCAFRM_HW_LEN0;
106 handle->state = handle->init;
109 static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
111 handle->init = QCAFRM_WAIT_AA1;
112 handle->state = handle->init;
115 s32 qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 recv_byte);
117 #endif /* _QCA_FRAMING_H */