3a4cc910b058849ec11c714806ace2800b681ce0
[openwrt/staging/neocturne.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sun, 20 Nov 2022 23:01:00 +0100
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: drop generic vlan rx offload,
4 only use DSA untagging
5
6 Through testing I found out that hardware vlan rx offload support seems to
7 have some hardware issues. At least when using multiple MACs and when receiving
8 tagged packets on the secondary MAC, the hardware can sometimes start to emit
9 wrong tags on the first MAC as well.
10
11 In order to avoid such issues, drop the feature configuration and use the
12 offload feature only for DSA hardware untagging on MT7621/MT7622 devices which
13 only use one MAC.
14
15 Signed-off-by: Felix Fietkau <nbd@nbd.name>
16 ---
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -1898,9 +1898,7 @@ static int mtk_poll_rx(struct napi_struc
21
22 while (done < budget) {
23 unsigned int pktlen, *rxdcsum;
24 - bool has_hwaccel_tag = false;
25 struct net_device *netdev;
26 - u16 vlan_proto, vlan_tci;
27 dma_addr_t dma_addr;
28 u32 hash, reason;
29 int mac = 0;
30 @@ -2035,36 +2033,21 @@ static int mtk_poll_rx(struct napi_struc
31 skb_checksum_none_assert(skb);
32 skb->protocol = eth_type_trans(skb, netdev);
33
34 - if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
35 - mtk_ppe_check_skb(eth->ppe[0], skb, hash);
36 -
37 - if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
38 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
39 - if (trxd.rxd3 & RX_DMA_VTAG_V2) {
40 - vlan_proto = RX_DMA_VPID(trxd.rxd4);
41 - vlan_tci = RX_DMA_VID(trxd.rxd4);
42 - has_hwaccel_tag = true;
43 - }
44 - } else if (trxd.rxd2 & RX_DMA_VTAG) {
45 - vlan_proto = RX_DMA_VPID(trxd.rxd3);
46 - vlan_tci = RX_DMA_VID(trxd.rxd3);
47 - has_hwaccel_tag = true;
48 - }
49 - }
50 -
51 /* When using VLAN untagging in combination with DSA, the
52 * hardware treats the MTK special tag as a VLAN and untags it.
53 */
54 - if (has_hwaccel_tag && netdev_uses_dsa(netdev)) {
55 - unsigned int port = vlan_proto & GENMASK(2, 0);
56 + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) &&
57 + (trxd.rxd2 & RX_DMA_VTAG) && netdev_uses_dsa(netdev)) {
58 + unsigned int port = RX_DMA_VPID(trxd.rxd3) & GENMASK(2, 0);
59
60 if (port < ARRAY_SIZE(eth->dsa_meta) &&
61 eth->dsa_meta[port])
62 skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
63 - } else if (has_hwaccel_tag) {
64 - __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan_tci);
65 }
66
67 + if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
68 + mtk_ppe_check_skb(eth->ppe[0], skb, hash);
69 +
70 skb_record_rx_queue(skb, 0);
71 napi_gro_receive(napi, skb);
72
73 @@ -2887,29 +2870,11 @@ static netdev_features_t mtk_fix_feature
74
75 static int mtk_set_features(struct net_device *dev, netdev_features_t features)
76 {
77 - struct mtk_mac *mac = netdev_priv(dev);
78 - struct mtk_eth *eth = mac->hw;
79 netdev_features_t diff = dev->features ^ features;
80 - int i;
81
82 if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
83 mtk_hwlro_netdev_disable(dev);
84
85 - /* Set RX VLAN offloading */
86 - if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
87 - return 0;
88 -
89 - mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
90 - MTK_CDMP_EG_CTRL);
91 -
92 - /* sync features with other MAC */
93 - for (i = 0; i < MTK_MAC_COUNT; i++) {
94 - if (!eth->netdev[i] || eth->netdev[i] == dev)
95 - continue;
96 - eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
97 - eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
98 - }
99 -
100 return 0;
101 }
102
103 @@ -3223,30 +3188,6 @@ static int mtk_open(struct net_device *d
104 struct mtk_eth *eth = mac->hw;
105 int i, err;
106
107 - if (mtk_uses_dsa(dev) && !eth->prog) {
108 - for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
109 - struct metadata_dst *md_dst = eth->dsa_meta[i];
110 -
111 - if (md_dst)
112 - continue;
113 -
114 - md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
115 - GFP_KERNEL);
116 - if (!md_dst)
117 - return -ENOMEM;
118 -
119 - md_dst->u.port_info.port_id = i;
120 - eth->dsa_meta[i] = md_dst;
121 - }
122 - } else {
123 - /* Hardware special tag parsing needs to be disabled if at least
124 - * one MAC does not use DSA.
125 - */
126 - u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
127 - val &= ~MTK_CDMP_STAG_EN;
128 - mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
129 - }
130 -
131 err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
132 if (err) {
133 netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
134 @@ -3285,6 +3226,35 @@ static int mtk_open(struct net_device *d
135 phylink_start(mac->phylink);
136 netif_tx_start_all_queues(dev);
137
138 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
139 + return 0;
140 +
141 + if (mtk_uses_dsa(dev) && !eth->prog) {
142 + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
143 + struct metadata_dst *md_dst = eth->dsa_meta[i];
144 +
145 + if (md_dst)
146 + continue;
147 +
148 + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
149 + GFP_KERNEL);
150 + if (!md_dst)
151 + return -ENOMEM;
152 +
153 + md_dst->u.port_info.port_id = i;
154 + eth->dsa_meta[i] = md_dst;
155 + }
156 + } else {
157 + /* Hardware special tag parsing needs to be disabled if at least
158 + * one MAC does not use DSA.
159 + */
160 + u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
161 + val &= ~MTK_CDMP_STAG_EN;
162 + mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
163 +
164 + mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
165 + }
166 +
167 return 0;
168 }
169
170 @@ -3769,10 +3739,9 @@ static int mtk_hw_init(struct mtk_eth *e
171 if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
172 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
173 mtk_w32(eth, val | MTK_CDMP_STAG_EN, MTK_CDMP_IG_CTRL);
174 - }
175
176 - /* Enable RX VLan Offloading */
177 - mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
178 + mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
179 + }
180
181 /* set interrupt delays based on current Net DIM sample */
182 mtk_dim_rx(&eth->rx_dim.work);
183 @@ -4412,7 +4381,7 @@ static int mtk_add_mac(struct mtk_eth *e
184 eth->netdev[id]->hw_features |= NETIF_F_LRO;
185
186 eth->netdev[id]->vlan_features = eth->soc->hw_features &
187 - ~(NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX);
188 + ~NETIF_F_HW_VLAN_CTAG_TX;
189 eth->netdev[id]->features |= eth->soc->hw_features;
190 eth->netdev[id]->ethtool_ops = &mtk_ethtool_ops;
191
192 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
193 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
194 @@ -48,7 +48,6 @@
195 #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
196 NETIF_F_RXCSUM | \
197 NETIF_F_HW_VLAN_CTAG_TX | \
198 - NETIF_F_HW_VLAN_CTAG_RX | \
199 NETIF_F_SG | NETIF_F_TSO | \
200 NETIF_F_TSO6 | \
201 NETIF_F_IPV6_CSUM |\