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
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.
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>
16 include/linux/dsa/tag_qca.h | 7 +++++++
17 net/dsa/tag_qca.c | 39 ++++++++++++++++++++++++++++++++++---
18 2 files changed, 43 insertions(+), 3 deletions(-)
20 --- a/include/linux/dsa/tag_qca.h
21 +++ b/include/linux/dsa/tag_qca.h
22 @@ -72,4 +72,11 @@ struct mib_ethhdr {
23 __be16 hdr; /* qca hdr */
26 +struct qca_tagger_data {
27 + void (*rw_reg_ack_handler)(struct dsa_switch *ds,
28 + struct sk_buff *skb);
29 + void (*mib_autocast_handler)(struct dsa_switch *ds,
30 + struct sk_buff *skb);
33 #endif /* __TAG_QCA_H */
34 --- a/net/dsa/tag_qca.c
35 +++ b/net/dsa/tag_qca.c
38 #include <linux/etherdevice.h>
39 #include <linux/bitfield.h>
41 #include <linux/dsa/tag_qca.h>
44 @@ -32,6 +33,9 @@ static struct sk_buff *qca_tag_xmit(stru
46 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
48 + struct qca_tagger_data *tagger_data;
49 + struct dsa_port *dp = dev->dsa_ptr;
50 + struct dsa_switch *ds = dp->ds;
54 @@ -39,6 +43,8 @@ static struct sk_buff *qca_tag_rcv(struc
56 BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
58 + tagger_data = ds->tagger_data;
60 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
63 @@ -53,13 +59,19 @@ static struct sk_buff *qca_tag_rcv(struc
65 pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
67 - /* Ethernet MDIO read/write packet */
68 - if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK)
69 + /* Ethernet mgmt read/write packet */
70 + if (pk_type == QCA_HDR_RECV_TYPE_RW_REG_ACK) {
71 + if (likely(tagger_data->rw_reg_ack_handler))
72 + tagger_data->rw_reg_ack_handler(ds, skb);
76 /* Ethernet MIB counter packet */
77 - if (pk_type == QCA_HDR_RECV_TYPE_MIB)
78 + if (pk_type == QCA_HDR_RECV_TYPE_MIB) {
79 + if (likely(tagger_data->mib_autocast_handler))
80 + tagger_data->mib_autocast_handler(ds, skb);
84 /* Remove QCA tag and recalculate checksum */
85 skb_pull_rcsum(skb, QCA_HDR_LEN);
86 @@ -75,9 +87,30 @@ static struct sk_buff *qca_tag_rcv(struc
90 +static int qca_tag_connect(struct dsa_switch *ds)
92 + struct qca_tagger_data *tagger_data;
94 + tagger_data = kzalloc(sizeof(*tagger_data), GFP_KERNEL);
98 + ds->tagger_data = tagger_data;
103 +static void qca_tag_disconnect(struct dsa_switch *ds)
105 + kfree(ds->tagger_data);
106 + ds->tagger_data = NULL;
109 static const struct dsa_device_ops qca_netdev_ops = {
111 .proto = DSA_TAG_PROTO_QCA,
112 + .connect = qca_tag_connect,
113 + .disconnect = qca_tag_disconnect,
114 .xmit = qca_tag_xmit,
116 .needed_headroom = QCA_HDR_LEN,