6981e7b187fa08adb218b3794669803fee6925ce
[openwrt/staging/xback.git] /
1 From c2ee8181fddb293d296477f60b3eb4fa3ce4e1a6 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:25 +0100
4 Subject: [PATCH 06/16] net: dsa: tag_qca: add define for handling mgmt
5 Ethernet packet
6
7 Add all the required define to prepare support for mgmt read/write in
8 Ethernet packet. Any packet of this type has to be dropped as the only
9 use of these special packet is receive ack for an mgmt write request or
10 receive data for an mgmt read request.
11 A struct is used that emulates the Ethernet header but is used for a
12 different purpose.
13
14 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
15 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18 include/linux/dsa/tag_qca.h | 44 +++++++++++++++++++++++++++++++++++++
19 net/dsa/tag_qca.c | 15 ++++++++++---
20 2 files changed, 56 insertions(+), 3 deletions(-)
21
22 diff --git a/include/linux/dsa/tag_qca.h b/include/linux/dsa/tag_qca.h
23 index c02d2d39ff4a..f366422ab7a0 100644
24 --- a/include/linux/dsa/tag_qca.h
25 +++ b/include/linux/dsa/tag_qca.h
26 @@ -12,10 +12,54 @@
27 #define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
28 #define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0)
29
30 +/* Packet type for recv */
31 +#define QCA_HDR_RECV_TYPE_NORMAL 0x0
32 +#define QCA_HDR_RECV_TYPE_MIB 0x1
33 +#define QCA_HDR_RECV_TYPE_RW_REG_ACK 0x2
34 +
35 #define QCA_HDR_XMIT_VERSION GENMASK(15, 14)
36 #define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11)
37 #define QCA_HDR_XMIT_CONTROL GENMASK(10, 8)
38 #define QCA_HDR_XMIT_FROM_CPU BIT(7)
39 #define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0)
40
41 +/* Packet type for xmit */
42 +#define QCA_HDR_XMIT_TYPE_NORMAL 0x0
43 +#define QCA_HDR_XMIT_TYPE_RW_REG 0x1
44 +
45 +/* Check code for a valid mgmt packet. Switch will ignore the packet
46 + * with this wrong.
47 + */
48 +#define QCA_HDR_MGMT_CHECK_CODE_VAL 0x5
49 +
50 +/* Specific define for in-band MDIO read/write with Ethernet packet */
51 +#define QCA_HDR_MGMT_SEQ_LEN 4 /* 4 byte for the seq */
52 +#define QCA_HDR_MGMT_COMMAND_LEN 4 /* 4 byte for the command */
53 +#define QCA_HDR_MGMT_DATA1_LEN 4 /* First 4 byte for the mdio data */
54 +#define QCA_HDR_MGMT_HEADER_LEN (QCA_HDR_MGMT_SEQ_LEN + \
55 + QCA_HDR_MGMT_COMMAND_LEN + \
56 + QCA_HDR_MGMT_DATA1_LEN)
57 +
58 +#define QCA_HDR_MGMT_DATA2_LEN 12 /* Other 12 byte for the mdio data */
59 +#define QCA_HDR_MGMT_PADDING_LEN 34 /* Padding to reach the min Ethernet packet */
60 +
61 +#define QCA_HDR_MGMT_PKT_LEN (QCA_HDR_MGMT_HEADER_LEN + \
62 + QCA_HDR_LEN + \
63 + QCA_HDR_MGMT_DATA2_LEN + \
64 + QCA_HDR_MGMT_PADDING_LEN)
65 +
66 +#define QCA_HDR_MGMT_SEQ_NUM GENMASK(31, 0) /* 63, 32 */
67 +#define QCA_HDR_MGMT_CHECK_CODE GENMASK(31, 29) /* 31, 29 */
68 +#define QCA_HDR_MGMT_CMD BIT(28) /* 28 */
69 +#define QCA_HDR_MGMT_LENGTH GENMASK(23, 20) /* 23, 20 */
70 +#define QCA_HDR_MGMT_ADDR GENMASK(18, 0) /* 18, 0 */
71 +
72 +/* Special struct emulating a Ethernet header */
73 +struct qca_mgmt_ethhdr {
74 + u32 command; /* command bit 31:0 */
75 + u32 seq; /* seq 63:32 */
76 + u32 mdio_data; /* first 4byte mdio */
77 + __be16 hdr; /* qca hdr */
78 +} __packed;
79 +
80 #endif /* __TAG_QCA_H */
81 diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
82 index f8df49d5956f..f17ed5be20c2 100644
83 --- a/net/dsa/tag_qca.c
84 +++ b/net/dsa/tag_qca.c
85 @@ -32,10 +32,12 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
86
87 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
88 {
89 - u8 ver;
90 - u16 hdr;
91 - int port;
92 + u8 ver, pk_type;
93 __be16 *phdr;
94 + int port;
95 + u16 hdr;
96 +
97 + BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
98
99 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
100 return NULL;
101 @@ -48,6 +50,13 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
102 if (unlikely(ver != QCA_HDR_VERSION))
103 return NULL;
104
105 + /* Get pk type */
106 + pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
107 +
108 + /* Ethernet MDIO read/write packet */
109 + if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK)
110 + return NULL;
111 +
112 /* Remove QCA tag and recalculate checksum */
113 skb_pull_rcsum(skb, QCA_HDR_LEN);
114 dsa_strip_etype_header(skb, QCA_HDR_LEN);
115 --
116 2.34.1
117