4375cd08b8a1dcf6d56be8d4117b334c7b5bdcb8
[openwrt/openwrt.git] /
1 From 31eb6b4386ad91930417e3f5c8157a4b5e31cbd5 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:27 +0100
4 Subject: [PATCH 08/16] net: dsa: tag_qca: add support for handling mgmt and
5 MIB Ethernet packet
6
7 Add connect/disconnect helper to assign private struct to the DSA switch.
8 Add support for Ethernet mgmt and MIB if the DSA driver provide an handler
9 to correctly parse and elaborate the data.
10
11 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
12 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
13 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16 include/linux/dsa/tag_qca.h | 7 +++++++
17 net/dsa/tag_qca.c | 39 ++++++++++++++++++++++++++++++++++---
18 2 files changed, 43 insertions(+), 3 deletions(-)
19
20 diff --git a/include/linux/dsa/tag_qca.h b/include/linux/dsa/tag_qca.h
21 index 1fff57f2937b..4359fb0221cf 100644
22 --- a/include/linux/dsa/tag_qca.h
23 +++ b/include/linux/dsa/tag_qca.h
24 @@ -72,4 +72,11 @@ struct mib_ethhdr {
25 __be16 hdr; /* qca hdr */
26 } __packed;
27
28 +struct qca_tagger_data {
29 + void (*rw_reg_ack_handler)(struct dsa_switch *ds,
30 + struct sk_buff *skb);
31 + void (*mib_autocast_handler)(struct dsa_switch *ds,
32 + struct sk_buff *skb);
33 +};
34 +
35 #endif /* __TAG_QCA_H */
36 diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
37 index be792cf687d9..57d2e00f1e5d 100644
38 --- a/net/dsa/tag_qca.c
39 +++ b/net/dsa/tag_qca.c
40 @@ -5,6 +5,7 @@
41
42 #include <linux/etherdevice.h>
43 #include <linux/bitfield.h>
44 +#include <net/dsa.h>
45 #include <linux/dsa/tag_qca.h>
46
47 #include "dsa_priv.h"
48 @@ -32,6 +33,9 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
49
50 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
51 {
52 + struct qca_tagger_data *tagger_data;
53 + struct dsa_port *dp = dev->dsa_ptr;
54 + struct dsa_switch *ds = dp->ds;
55 u8 ver, pk_type;
56 __be16 *phdr;
57 int port;
58 @@ -39,6 +43,8 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
59
60 BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
61
62 + tagger_data = ds->tagger_data;
63 +
64 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
65 return NULL;
66
67 @@ -53,13 +59,19 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
68 /* Get pk type */
69 pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
70
71 - /* Ethernet MDIO read/write packet */
72 - if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK)
73 + /* Ethernet mgmt read/write packet */
74 + if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK) {
75 + if (likely(tagger_data->rw_reg_ack_handler))
76 + tagger_data->rw_reg_ack_handler(ds, skb);
77 return NULL;
78 + }
79
80 /* Ethernet MIB counter packet */
81 - if (pk_type == QCA_HDR_RECV_TYPE_MIB)
82 + if (pk_type == QCA_HDR_RECV_TYPE_MIB) {
83 + if (likely(tagger_data->mib_autocast_handler))
84 + tagger_data->mib_autocast_handler(ds, skb);
85 return NULL;
86 + }
87
88 /* Remove QCA tag and recalculate checksum */
89 skb_pull_rcsum(skb, QCA_HDR_LEN);
90 @@ -75,9 +87,30 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
91 return skb;
92 }
93
94 +static int qca_tag_connect(struct dsa_switch *ds)
95 +{
96 + struct qca_tagger_data *tagger_data;
97 +
98 + tagger_data = kzalloc(sizeof(*tagger_data), GFP_KERNEL);
99 + if (!tagger_data)
100 + return -ENOMEM;
101 +
102 + ds->tagger_data = tagger_data;
103 +
104 + return 0;
105 +}
106 +
107 +static void qca_tag_disconnect(struct dsa_switch *ds)
108 +{
109 + kfree(ds->tagger_data);
110 + ds->tagger_data = NULL;
111 +}
112 +
113 static const struct dsa_device_ops qca_netdev_ops = {
114 .name = "qca",
115 .proto = DSA_TAG_PROTO_QCA,
116 + .connect = qca_tag_connect,
117 + .disconnect = qca_tag_disconnect,
118 .xmit = qca_tag_xmit,
119 .rcv = qca_tag_rcv,
120 .needed_headroom = QCA_HDR_LEN,
121 --
122 2.34.1
123