gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 730-09-v6.3-net-ethernet-mtk_eth_soc-fix-VLAN-rx-hardware-accele.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 28 Oct 2022 11:01:12 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: fix VLAN rx hardware
4 acceleration
5
6 - enable VLAN untagging for PDMA rx
7 - make it possible to disable the feature via ethtool
8 - pass VLAN tag to the DSA driver
9 - untag special tag on PDMA only if no non-DSA devices are in use
10 - disable special tag untagging on 7986 for now, since it's not working yet
11
12 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 ---
14
15 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
16 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 @@ -23,6 +23,7 @@
18 #include <linux/jhash.h>
19 #include <linux/bitfield.h>
20 #include <net/dsa.h>
21 +#include <net/dst_metadata.h>
22
23 #include "mtk_eth_soc.h"
24 #include "mtk_wed.h"
25 @@ -2021,16 +2022,22 @@ static int mtk_poll_rx(struct napi_struc
26 htons(RX_DMA_VPID(trxd.rxd4)),
27 RX_DMA_VID(trxd.rxd4));
28 } else if (trxd.rxd2 & RX_DMA_VTAG) {
29 - __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
30 + __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)),
31 RX_DMA_VID(trxd.rxd3));
32 }
33 + }
34 +
35 + /* When using VLAN untagging in combination with DSA, the
36 + * hardware treats the MTK special tag as a VLAN and untags it.
37 + */
38 + if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) {
39 + unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0);
40
41 - /* If the device is attached to a dsa switch, the special
42 - * tag inserted in VLAN field by hw switch can * be offloaded
43 - * by RX HW VLAN offload. Clear vlan info.
44 - */
45 - if (netdev_uses_dsa(netdev))
46 - __vlan_hwaccel_clear_tag(skb);
47 + if (port < ARRAY_SIZE(eth->dsa_meta) &&
48 + eth->dsa_meta[port])
49 + skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
50 +
51 + __vlan_hwaccel_clear_tag(skb);
52 }
53
54 skb_record_rx_queue(skb, 0);
55 @@ -2858,15 +2865,30 @@ static netdev_features_t mtk_fix_feature
56
57 static int mtk_set_features(struct net_device *dev, netdev_features_t features)
58 {
59 - int err = 0;
60 + struct mtk_mac *mac = netdev_priv(dev);
61 + struct mtk_eth *eth = mac->hw;
62 + netdev_features_t diff = dev->features ^ features;
63 + int i;
64 +
65 + if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
66 + mtk_hwlro_netdev_disable(dev);
67
68 - if (!((dev->features ^ features) & NETIF_F_LRO))
69 + /* Set RX VLAN offloading */
70 + if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
71 return 0;
72
73 - if (!(features & NETIF_F_LRO))
74 - mtk_hwlro_netdev_disable(dev);
75 + mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
76 + MTK_CDMP_EG_CTRL);
77
78 - return err;
79 + /* sync features with other MAC */
80 + for (i = 0; i < MTK_MAC_COUNT; i++) {
81 + if (!eth->netdev[i] || eth->netdev[i] == dev)
82 + continue;
83 + eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
84 + eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
85 + }
86 +
87 + return 0;
88 }
89
90 /* wait for DMA to finish whatever it is doing before we start using it again */
91 @@ -3163,11 +3185,45 @@ found:
92 return NOTIFY_DONE;
93 }
94
95 +static bool mtk_uses_dsa(struct net_device *dev)
96 +{
97 +#if IS_ENABLED(CONFIG_NET_DSA)
98 + return netdev_uses_dsa(dev) &&
99 + dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
100 +#else
101 + return false;
102 +#endif
103 +}
104 +
105 static int mtk_open(struct net_device *dev)
106 {
107 struct mtk_mac *mac = netdev_priv(dev);
108 struct mtk_eth *eth = mac->hw;
109 - int err;
110 + int i, err;
111 +
112 + if (mtk_uses_dsa(dev) && !eth->prog) {
113 + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
114 + struct metadata_dst *md_dst = eth->dsa_meta[i];
115 +
116 + if (md_dst)
117 + continue;
118 +
119 + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
120 + GFP_KERNEL);
121 + if (!md_dst)
122 + return -ENOMEM;
123 +
124 + md_dst->u.port_info.port_id = i;
125 + eth->dsa_meta[i] = md_dst;
126 + }
127 + } else {
128 + /* Hardware special tag parsing needs to be disabled if at least
129 + * one MAC does not use DSA.
130 + */
131 + u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
132 + val &= ~MTK_CDMP_STAG_EN;
133 + mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
134 + }
135
136 err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
137 if (err) {
138 @@ -3688,6 +3744,10 @@ static int mtk_hw_init(struct mtk_eth *e
139 */
140 val = mtk_r32(eth, MTK_CDMQ_IG_CTRL);
141 mtk_w32(eth, val | MTK_CDMQ_STAG_EN, MTK_CDMQ_IG_CTRL);
142 + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
143 + val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
144 + mtk_w32(eth, val | MTK_CDMP_STAG_EN, MTK_CDMP_IG_CTRL);
145 + }
146
147 /* Enable RX VLan Offloading */
148 mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
149 @@ -3907,6 +3967,12 @@ static int mtk_free_dev(struct mtk_eth *
150 free_netdev(eth->netdev[i]);
151 }
152
153 + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
154 + if (!eth->dsa_meta[i])
155 + break;
156 + metadata_dst_free(eth->dsa_meta[i]);
157 + }
158 +
159 return 0;
160 }
161
162 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
163 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
164 @@ -22,6 +22,9 @@
165 #include <linux/bpf_trace.h>
166 #include "mtk_ppe.h"
167
168 +#define MTK_MAX_DSA_PORTS 7
169 +#define MTK_DSA_PORT_MASK GENMASK(2, 0)
170 +
171 #define MTK_QDMA_NUM_QUEUES 16
172 #define MTK_QDMA_PAGE_SIZE 2048
173 #define MTK_MAX_RX_LENGTH 1536
174 @@ -105,6 +108,9 @@
175 #define MTK_CDMQ_IG_CTRL 0x1400
176 #define MTK_CDMQ_STAG_EN BIT(0)
177
178 +/* CDMQ Exgress Control Register */
179 +#define MTK_CDMQ_EG_CTRL 0x1404
180 +
181 /* CDMP Ingress Control Register */
182 #define MTK_CDMP_IG_CTRL 0x400
183 #define MTK_CDMP_STAG_EN BIT(0)
184 @@ -1164,6 +1170,8 @@ struct mtk_eth {
185
186 int ip_align;
187
188 + struct metadata_dst *dsa_meta[MTK_MAX_DSA_PORTS];
189 +
190 struct mtk_ppe *ppe[2];
191 struct rhashtable flow_table;
192