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,
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.
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
15 Signed-off-by: Felix Fietkau <nbd@nbd.name>
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -1849,9 +1849,7 @@ static int mtk_poll_rx(struct napi_struc
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;
30 @@ -1986,36 +1984,21 @@ static int mtk_poll_rx(struct napi_struc
31 skb_checksum_none_assert(skb);
32 skb->protocol = eth_type_trans(skb, netdev);
34 - if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
35 - mtk_ppe_check_skb(eth->ppe[0], skb, hash);
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;
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;
51 /* When using VLAN untagging in combination with DSA, the
52 * hardware treats the MTK special tag as a VLAN and untags it.
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);
60 if (port < ARRAY_SIZE(eth->dsa_meta) &&
62 skb_dst_set_noref(skb, ð->dsa_meta[port]->dst);
63 - } else if (has_hwaccel_tag) {
64 - __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan_tci);
67 + if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
68 + mtk_ppe_check_skb(eth->ppe[0], skb, hash);
70 skb_record_rx_queue(skb, 0);
71 napi_gro_receive(napi, skb);
73 @@ -2833,29 +2816,11 @@ static netdev_features_t mtk_fix_feature
75 static int mtk_set_features(struct net_device *dev, netdev_features_t features)
77 - struct mtk_mac *mac = netdev_priv(dev);
78 - struct mtk_eth *eth = mac->hw;
79 netdev_features_t diff = dev->features ^ features;
82 if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
83 mtk_hwlro_netdev_disable(dev);
85 - /* Set RX VLAN offloading */
86 - if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
89 - mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
92 - /* sync features with other MAC */
93 - for (i = 0; i < MTK_MAC_COUNT; i++) {
94 - if (!eth->netdev[i] || eth->netdev[i] == dev)
96 - eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
97 - eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
103 @@ -3169,30 +3134,6 @@ static int mtk_open(struct net_device *d
104 struct mtk_eth *eth = mac->hw;
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];
114 - md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
119 - md_dst->u.port_info.port_id = i;
120 - eth->dsa_meta[i] = md_dst;
123 - /* Hardware special tag parsing needs to be disabled if at least
124 - * one MAC does not use DSA.
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);
131 err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
133 netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
134 @@ -3233,6 +3174,35 @@ static int mtk_open(struct net_device *d
135 phylink_start(mac->phylink);
136 netif_tx_start_all_queues(dev);
138 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
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];
148 + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
153 + md_dst->u.port_info.port_id = i;
154 + eth->dsa_meta[i] = md_dst;
157 + /* Hardware special tag parsing needs to be disabled if at least
158 + * one MAC does not use DSA.
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);
164 + mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
170 @@ -3717,10 +3687,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);
176 - /* Enable RX VLan Offloading */
177 - mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
178 + mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
181 /* set interrupt delays based on current Net DIM sample */
182 mtk_dim_rx(ð->rx_dim.work);
183 @@ -4360,7 +4329,7 @@ static int mtk_add_mac(struct mtk_eth *e
184 eth->netdev[id]->hw_features |= NETIF_F_LRO;
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;
192 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
193 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
195 #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
197 NETIF_F_HW_VLAN_CTAG_TX | \
198 - NETIF_F_HW_VLAN_CTAG_RX | \
199 NETIF_F_SG | NETIF_F_TSO | \