459454e03ba50a7554d2b2361a0a4d86e8bf47bd
[openwrt/staging/rmilecki.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 --- a/include/linux/dsa/tag_qca.h
23 +++ b/include/linux/dsa/tag_qca.h
24 @@ -12,10 +12,54 @@
25 #define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
26 #define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0)
27
28 +/* Packet type for recv */
29 +#define QCA_HDR_RECV_TYPE_NORMAL 0x0
30 +#define QCA_HDR_RECV_TYPE_MIB 0x1
31 +#define QCA_HDR_RECV_TYPE_RW_REG_ACK 0x2
32 +
33 #define QCA_HDR_XMIT_VERSION GENMASK(15, 14)
34 #define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11)
35 #define QCA_HDR_XMIT_CONTROL GENMASK(10, 8)
36 #define QCA_HDR_XMIT_FROM_CPU BIT(7)
37 #define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0)
38
39 +/* Packet type for xmit */
40 +#define QCA_HDR_XMIT_TYPE_NORMAL 0x0
41 +#define QCA_HDR_XMIT_TYPE_RW_REG 0x1
42 +
43 +/* Check code for a valid mgmt packet. Switch will ignore the packet
44 + * with this wrong.
45 + */
46 +#define QCA_HDR_MGMT_CHECK_CODE_VAL 0x5
47 +
48 +/* Specific define for in-band MDIO read/write with Ethernet packet */
49 +#define QCA_HDR_MGMT_SEQ_LEN 4 /* 4 byte for the seq */
50 +#define QCA_HDR_MGMT_COMMAND_LEN 4 /* 4 byte for the command */
51 +#define QCA_HDR_MGMT_DATA1_LEN 4 /* First 4 byte for the mdio data */
52 +#define QCA_HDR_MGMT_HEADER_LEN (QCA_HDR_MGMT_SEQ_LEN + \
53 + QCA_HDR_MGMT_COMMAND_LEN + \
54 + QCA_HDR_MGMT_DATA1_LEN)
55 +
56 +#define QCA_HDR_MGMT_DATA2_LEN 12 /* Other 12 byte for the mdio data */
57 +#define QCA_HDR_MGMT_PADDING_LEN 34 /* Padding to reach the min Ethernet packet */
58 +
59 +#define QCA_HDR_MGMT_PKT_LEN (QCA_HDR_MGMT_HEADER_LEN + \
60 + QCA_HDR_LEN + \
61 + QCA_HDR_MGMT_DATA2_LEN + \
62 + QCA_HDR_MGMT_PADDING_LEN)
63 +
64 +#define QCA_HDR_MGMT_SEQ_NUM GENMASK(31, 0) /* 63, 32 */
65 +#define QCA_HDR_MGMT_CHECK_CODE GENMASK(31, 29) /* 31, 29 */
66 +#define QCA_HDR_MGMT_CMD BIT(28) /* 28 */
67 +#define QCA_HDR_MGMT_LENGTH GENMASK(23, 20) /* 23, 20 */
68 +#define QCA_HDR_MGMT_ADDR GENMASK(18, 0) /* 18, 0 */
69 +
70 +/* Special struct emulating a Ethernet header */
71 +struct qca_mgmt_ethhdr {
72 + u32 command; /* command bit 31:0 */
73 + u32 seq; /* seq 63:32 */
74 + u32 mdio_data; /* first 4byte mdio */
75 + __be16 hdr; /* qca hdr */
76 +} __packed;
77 +
78 #endif /* __TAG_QCA_H */
79 --- a/net/dsa/tag_qca.c
80 +++ b/net/dsa/tag_qca.c
81 @@ -32,10 +32,12 @@ static struct sk_buff *qca_tag_xmit(stru
82
83 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
84 {
85 - u8 ver;
86 - u16 hdr;
87 - int port;
88 + u8 ver, pk_type;
89 __be16 *phdr;
90 + int port;
91 + u16 hdr;
92 +
93 + BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
94
95 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
96 return NULL;
97 @@ -48,6 +50,13 @@ static struct sk_buff *qca_tag_rcv(struc
98 if (unlikely(ver != QCA_HDR_VERSION))
99 return NULL;
100
101 + /* Get pk type */
102 + pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
103 +
104 + /* Ethernet MDIO read/write packet */
105 + if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK)
106 + return NULL;
107 +
108 /* Remove QCA tag and recalculate checksum */
109 skb_pull_rcsum(skb, QCA_HDR_LEN);
110 dsa_strip_etype_header(skb, QCA_HDR_LEN);