History

net: dsa: tag_qca: add define for handling mgmt Ethernet packet

Add all the required define to prepare support for mgmt read/write in Ethernet packet. Any packet of this type has to be dropped as the only use of these special packet is receive ack for an mgmt write request or receive data for an mgmt read request. A struct is used that emulates the Ethernet header but is used for a different purpose.

Ansuel Smith committed 4 years ago

Commit c2ee8181 parent 101c04c2 files · +56 −3Browse files

Unified · Split

2 files
  1. include/linux/dsa/tag_qca.h +44 −0
  2. net/dsa/tag_qca.c +12 −3
include/linux/dsa/tag_qca.h+44−0
@@ -12,10 +12,54 @@ · 11 unmodified lines
12#define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)12#define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
13#define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0)13#define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0)
14 14
15/* Packet type for recv */
16#define QCA_HDR_RECV_TYPE_NORMAL 0x0
17#define QCA_HDR_RECV_TYPE_MIB 0x1
18#define QCA_HDR_RECV_TYPE_RW_REG_ACK 0x2
19
15#define QCA_HDR_XMIT_VERSION GENMASK(15, 14)20#define QCA_HDR_XMIT_VERSION GENMASK(15, 14)
16#define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11)21#define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11)
17#define QCA_HDR_XMIT_CONTROL GENMASK(10, 8)22#define QCA_HDR_XMIT_CONTROL GENMASK(10, 8)
18#define QCA_HDR_XMIT_FROM_CPU BIT(7)23#define QCA_HDR_XMIT_FROM_CPU BIT(7)
19#define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0)24#define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0)
20 25
26/* Packet type for xmit */
27#define QCA_HDR_XMIT_TYPE_NORMAL 0x0
28#define QCA_HDR_XMIT_TYPE_RW_REG 0x1
29
30/* Check code for a valid mgmt packet. Switch will ignore the packet
31 * with this wrong.
32 */
33#define QCA_HDR_MGMT_CHECK_CODE_VAL 0x5
34
35/* Specific define for in-band MDIO read/write with Ethernet packet */
36#define QCA_HDR_MGMT_SEQ_LEN 4 /* 4 byte for the seq */
37#define QCA_HDR_MGMT_COMMAND_LEN 4 /* 4 byte for the command */
38#define QCA_HDR_MGMT_DATA1_LEN 4 /* First 4 byte for the mdio data */
39#define QCA_HDR_MGMT_HEADER_LEN (QCA_HDR_MGMT_SEQ_LEN + \
40 QCA_HDR_MGMT_COMMAND_LEN + \
41 QCA_HDR_MGMT_DATA1_LEN)
42
43#define QCA_HDR_MGMT_DATA2_LEN 12 /* Other 12 byte for the mdio data */
44#define QCA_HDR_MGMT_PADDING_LEN 34 /* Padding to reach the min Ethernet packet */
45
46#define QCA_HDR_MGMT_PKT_LEN (QCA_HDR_MGMT_HEADER_LEN + \
47 QCA_HDR_LEN + \
48 QCA_HDR_MGMT_DATA2_LEN + \
49 QCA_HDR_MGMT_PADDING_LEN)
50
51#define QCA_HDR_MGMT_SEQ_NUM GENMASK(31, 0) /* 63, 32 */
52#define QCA_HDR_MGMT_CHECK_CODE GENMASK(31, 29) /* 31, 29 */
53#define QCA_HDR_MGMT_CMD BIT(28) /* 28 */
54#define QCA_HDR_MGMT_LENGTH GENMASK(23, 20) /* 23, 20 */
55#define QCA_HDR_MGMT_ADDR GENMASK(18, 0) /* 18, 0 */
56
57/* Special struct emulating a Ethernet header */
58struct qca_mgmt_ethhdr {
59 u32 command; /* command bit 31:0 */
60 u32 seq; /* seq 63:32 */
61 u32 mdio_data; /* first 4byte mdio */
62 __be16 hdr; /* qca hdr */
63} __packed;
64
21#endif /* __TAG_QCA_H */65#endif /* __TAG_QCA_H */
net/dsa/tag_qca.c+12−3
@@ -32,10 +32,12 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) · 31 unmodified lines
32 32
33static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)33static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
34{34{
35 u8 ver;35 u8 ver, pk_type;
36 u16 hdr;
37 int port;
38 __be16 *phdr;36 __be16 *phdr;
37 int port;
38 u16 hdr;
39
40 BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
39 41
40 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))42 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
41 return NULL;43 return NULL;
@@ -48,6 +50,13 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev) · 6 unmodified lines
48 if (unlikely(ver != QCA_HDR_VERSION))50 if (unlikely(ver != QCA_HDR_VERSION))
49 return NULL;51 return NULL;
50 52
53 /* Get pk type */
54 pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
55
56 /* Ethernet MDIO read/write packet */
57 if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK)
58 return NULL;
59
51 /* Remove QCA tag and recalculate checksum */60 /* Remove QCA tag and recalculate checksum */
52 skb_pull_rcsum(skb, QCA_HDR_LEN);61 skb_pull_rcsum(skb, QCA_HDR_LEN);
53 dsa_strip_etype_header(skb, QCA_HDR_LEN);62 dsa_strip_etype_header(skb, QCA_HDR_LEN);