2 * Copyright (c) 2011, 2012, Atheros Communications Inc.
3 * Copyright (c) 2014, I2SE GmbH
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose with or without fee is hereby granted, provided
7 * that the above copyright notice and this permission notice appear
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Atheros Ethernet framing. Every Ethernet frame is surrounded by an atheros
21 * frame while transmitted over a serial channel.
24 #ifndef _QCA_FRAMING_H
25 #define _QCA_FRAMING_H
27 #include <linux/if_ether.h>
28 #include <linux/if_vlan.h>
29 #include <linux/types.h>
31 /* Frame is currently being received */
32 #define QCAFRM_GATHER 0
34 /* No header byte while expecting it */
35 #define QCAFRM_NOHEAD (QCAFRM_ERR_BASE - 1)
37 /* No tailer byte while expecting it */
38 #define QCAFRM_NOTAIL (QCAFRM_ERR_BASE - 2)
40 /* Frame length is invalid */
41 #define QCAFRM_INVLEN (QCAFRM_ERR_BASE - 3)
43 /* Frame length is invalid */
44 #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
46 /* Min/Max Ethernet MTU */
47 #define QCAFRM_ETHMINMTU 46
48 #define QCAFRM_ETHMAXMTU 1500
50 /* Min/Max frame lengths */
51 #define QCAFRM_ETHMINLEN (QCAFRM_ETHMINMTU + ETH_HLEN)
52 #define QCAFRM_ETHMAXLEN (QCAFRM_ETHMAXMTU + VLAN_ETH_HLEN)
54 /* QCA7K header len */
55 #define QCAFRM_HEADER_LEN 8
57 /* QCA7K footer len */
58 #define QCAFRM_FOOTER_LEN 2
61 #define QCAFRM_ERR_BASE -1000
64 QCAFRM_HW_LEN0
= 0x8000,
65 QCAFRM_HW_LEN1
= QCAFRM_HW_LEN0
- 1,
66 QCAFRM_HW_LEN2
= QCAFRM_HW_LEN1
- 1,
67 QCAFRM_HW_LEN3
= QCAFRM_HW_LEN2
- 1,
69 /* Waiting first 0xAA of header */
70 QCAFRM_WAIT_AA1
= QCAFRM_HW_LEN3
- 1,
72 /* Waiting second 0xAA of header */
73 QCAFRM_WAIT_AA2
= QCAFRM_WAIT_AA1
- 1,
75 /* Waiting third 0xAA of header */
76 QCAFRM_WAIT_AA3
= QCAFRM_WAIT_AA2
- 1,
78 /* Waiting fourth 0xAA of header */
79 QCAFRM_WAIT_AA4
= QCAFRM_WAIT_AA3
- 1,
81 /* Waiting Byte 0-1 of length (litte endian) */
82 QCAFRM_WAIT_LEN_BYTE0
= QCAFRM_WAIT_AA4
- 1,
83 QCAFRM_WAIT_LEN_BYTE1
= QCAFRM_WAIT_AA4
- 2,
86 QCAFRM_WAIT_RSVD_BYTE1
= QCAFRM_WAIT_AA4
- 3,
87 QCAFRM_WAIT_RSVD_BYTE2
= QCAFRM_WAIT_AA4
- 4,
89 /* The frame length is used as the state until
90 * the end of the Ethernet frame
91 * Waiting for first 0x55 of footer
95 /* Waiting for second 0x55 of footer */
96 QCAFRM_WAIT_552
= QCAFRM_WAIT_551
- 1
99 /* Structure to maintain the frame decoding during reception. */
101 struct qcafrm_handle
{
102 /* Current decoding state */
103 enum qcafrm_state state
;
105 /* Offset in buffer (borrowed for length too) */
108 /* Frame length as kept by this module */
112 u16
qcafrm_create_header(u8
*buf
, u16 len
);
114 u16
qcafrm_create_footer(u8
*buf
);
116 static inline void qcafrm_fsm_init(struct qcafrm_handle
*handle
)
118 handle
->state
= QCAFRM_HW_LEN0
;
121 /* Gather received bytes and try to extract a full Ethernet frame
122 * by following a simple state machine.
124 * Return: QCAFRM_GATHER No Ethernet frame fully received yet.
125 * QCAFRM_NOHEAD Header expected but not found.
126 * QCAFRM_INVLEN QCA7K frame length is invalid
127 * QCAFRM_NOTAIL Footer expected but not found.
128 * > 0 Number of byte in the fully received
132 s32
qcafrm_fsm_decode(struct qcafrm_handle
*handle
, u8
*buf
, u16 buf_len
, u8 recv_byte
);
134 #endif /* _QCA_FRAMING_H */