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 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 */
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);
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
42 #include <linux/etherdevice.h>
43 #include <linux/bitfield.h>
45 #include <linux/dsa/tag_qca.h>
48 @@ -32,6 +33,9 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
50 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
52 + struct qca_tagger_data *tagger_data;
53 + struct dsa_port *dp = dev->dsa_ptr;
54 + struct dsa_switch *ds = dp->ds;
58 @@ -39,6 +43,8 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
60 BUILD_BUG_ON(sizeof(struct qca_mgmt_ethhdr) != QCA_HDR_MGMT_HEADER_LEN + QCA_HDR_LEN);
62 + tagger_data = ds->tagger_data;
64 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
67 @@ -53,13 +59,19 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
69 pk_type = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
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);
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);
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)
94 +static int qca_tag_connect(struct dsa_switch *ds)
96 + struct qca_tagger_data *tagger_data;
98 + tagger_data = kzalloc(sizeof(*tagger_data), GFP_KERNEL);
102 + ds->tagger_data = tagger_data;
107 +static void qca_tag_disconnect(struct dsa_switch *ds)
109 + kfree(ds->tagger_data);
110 + ds->tagger_data = NULL;
113 static const struct dsa_device_ops qca_netdev_ops = {
115 .proto = DSA_TAG_PROTO_QCA,
116 + .connect = qca_tag_connect,
117 + .disconnect = qca_tag_disconnect,
118 .xmit = qca_tag_xmit,
120 .needed_headroom = QCA_HDR_LEN,