kernel: move accepted mtk_eth_soc patches to generic-backport
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 732-00-net-ethernet-mtk_eth_soc-drop-generic-vlan-rx-offloa.patch
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 @@ -1967,29 +1967,16 @@ static int mtk_poll_rx(struct napi_struc
21 if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
22 mtk_ppe_check_skb(eth->ppe[0], skb, hash);
23
24 - if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
25 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
26 - if (trxd.rxd3 & RX_DMA_VTAG_V2)
27 - __vlan_hwaccel_put_tag(skb,
28 - htons(RX_DMA_VPID(trxd.rxd4)),
29 - RX_DMA_VID(trxd.rxd4));
30 - } else if (trxd.rxd2 & RX_DMA_VTAG) {
31 - __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)),
32 - RX_DMA_VID(trxd.rxd3));
33 - }
34 - }
35 -
36 /* When using VLAN untagging in combination with DSA, the
37 * hardware treats the MTK special tag as a VLAN and untags it.
38 */
39 - if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) {
40 - unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0);
41 + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) &&
42 + (trxd.rxd2 & RX_DMA_VTAG) && netdev_uses_dsa(netdev)) {
43 + unsigned int port = RX_DMA_VPID(trxd.rxd3) & GENMASK(2, 0);
44
45 if (port < ARRAY_SIZE(eth->dsa_meta) &&
46 eth->dsa_meta[port])
47 skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
48 -
49 - __vlan_hwaccel_clear_tag(skb);
50 }
51
52 skb_record_rx_queue(skb, 0);
53 @@ -2806,29 +2793,11 @@ static netdev_features_t mtk_fix_feature
54
55 static int mtk_set_features(struct net_device *dev, netdev_features_t features)
56 {
57 - struct mtk_mac *mac = netdev_priv(dev);
58 - struct mtk_eth *eth = mac->hw;
59 netdev_features_t diff = dev->features ^ features;
60 - int i;
61
62 if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
63 mtk_hwlro_netdev_disable(dev);
64
65 - /* Set RX VLAN offloading */
66 - if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
67 - return 0;
68 -
69 - mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
70 - MTK_CDMP_EG_CTRL);
71 -
72 - /* sync features with other MAC */
73 - for (i = 0; i < MTK_MAC_COUNT; i++) {
74 - if (!eth->netdev[i] || eth->netdev[i] == dev)
75 - continue;
76 - eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
77 - eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
78 - }
79 -
80 return 0;
81 }
82
83 @@ -3142,30 +3111,6 @@ static int mtk_open(struct net_device *d
84 struct mtk_eth *eth = mac->hw;
85 int i, err;
86
87 - if (mtk_uses_dsa(dev) && !eth->prog) {
88 - for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
89 - struct metadata_dst *md_dst = eth->dsa_meta[i];
90 -
91 - if (md_dst)
92 - continue;
93 -
94 - md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
95 - GFP_KERNEL);
96 - if (!md_dst)
97 - return -ENOMEM;
98 -
99 - md_dst->u.port_info.port_id = i;
100 - eth->dsa_meta[i] = md_dst;
101 - }
102 - } else {
103 - /* Hardware special tag parsing needs to be disabled if at least
104 - * one MAC does not use DSA.
105 - */
106 - u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
107 - val &= ~MTK_CDMP_STAG_EN;
108 - mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
109 - }
110 -
111 err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
112 if (err) {
113 netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
114 @@ -3206,6 +3151,35 @@ static int mtk_open(struct net_device *d
115 phylink_start(mac->phylink);
116 netif_tx_start_all_queues(dev);
117
118 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
119 + return 0;
120 +
121 + if (mtk_uses_dsa(dev) && !eth->prog) {
122 + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
123 + struct metadata_dst *md_dst = eth->dsa_meta[i];
124 +
125 + if (md_dst)
126 + continue;
127 +
128 + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
129 + GFP_KERNEL);
130 + if (!md_dst)
131 + return -ENOMEM;
132 +
133 + md_dst->u.port_info.port_id = i;
134 + eth->dsa_meta[i] = md_dst;
135 + }
136 + } else {
137 + /* Hardware special tag parsing needs to be disabled if at least
138 + * one MAC does not use DSA.
139 + */
140 + u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
141 + val &= ~MTK_CDMP_STAG_EN;
142 + mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
143 +
144 + mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
145 + }
146 +
147 return 0;
148 }
149
150 @@ -3690,10 +3664,9 @@ static int mtk_hw_init(struct mtk_eth *e
151 if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
152 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
153 mtk_w32(eth, val | MTK_CDMP_STAG_EN, MTK_CDMP_IG_CTRL);
154 - }
155
156 - /* Enable RX VLan Offloading */
157 - mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
158 + mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
159 + }
160
161 /* set interrupt delays based on current Net DIM sample */
162 mtk_dim_rx(&eth->rx_dim.work);
163 @@ -4331,7 +4304,7 @@ static int mtk_add_mac(struct mtk_eth *e
164 eth->netdev[id]->hw_features |= NETIF_F_LRO;
165
166 eth->netdev[id]->vlan_features = eth->soc->hw_features &
167 - ~(NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX);
168 + ~NETIF_F_HW_VLAN_CTAG_TX;
169 eth->netdev[id]->features |= eth->soc->hw_features;
170 eth->netdev[id]->ethtool_ops = &mtk_ethtool_ops;
171
172 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
173 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
174 @@ -48,7 +48,6 @@
175 #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
176 NETIF_F_RXCSUM | \
177 NETIF_F_HW_VLAN_CTAG_TX | \
178 - NETIF_F_HW_VLAN_CTAG_RX | \
179 NETIF_F_SG | NETIF_F_TSO | \
180 NETIF_F_TSO6 | \
181 NETIF_F_IPV6_CSUM |\