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 @@ -1993,29 +1993,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);
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));
36 /* When using VLAN untagging in combination with DSA, the
37 * hardware treats the MTK special tag as a VLAN and untags it.
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);
45 if (port < ARRAY_SIZE(eth->dsa_meta) &&
47 skb_dst_set_noref(skb, ð->dsa_meta[port]->dst);
49 - __vlan_hwaccel_clear_tag(skb);
52 skb_record_rx_queue(skb, 0);
53 @@ -2832,29 +2819,11 @@ static netdev_features_t mtk_fix_feature
55 static int mtk_set_features(struct net_device *dev, netdev_features_t features)
57 - struct mtk_mac *mac = netdev_priv(dev);
58 - struct mtk_eth *eth = mac->hw;
59 netdev_features_t diff = dev->features ^ features;
62 if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
63 mtk_hwlro_netdev_disable(dev);
65 - /* Set RX VLAN offloading */
66 - if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
69 - mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
72 - /* sync features with other MAC */
73 - for (i = 0; i < MTK_MAC_COUNT; i++) {
74 - if (!eth->netdev[i] || eth->netdev[i] == dev)
76 - eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
77 - eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
83 @@ -3153,30 +3122,6 @@ static int mtk_open(struct net_device *d
84 struct mtk_eth *eth = mac->hw;
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];
94 - md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
99 - md_dst->u.port_info.port_id = i;
100 - eth->dsa_meta[i] = md_dst;
103 - /* Hardware special tag parsing needs to be disabled if at least
104 - * one MAC does not use DSA.
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);
111 err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
113 netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
114 @@ -3215,6 +3160,35 @@ static int mtk_open(struct net_device *d
115 phylink_start(mac->phylink);
116 netif_tx_start_all_queues(dev);
118 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
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];
128 + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
133 + md_dst->u.port_info.port_id = i;
134 + eth->dsa_meta[i] = md_dst;
137 + /* Hardware special tag parsing needs to be disabled if at least
138 + * one MAC does not use DSA.
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);
144 + mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
150 @@ -3508,10 +3482,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);
156 - /* Enable RX VLan Offloading */
157 - mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
158 + mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
161 /* set interrupt delays based on current Net DIM sample */
162 mtk_dim_rx(ð->rx_dim.work);
163 @@ -4132,7 +4105,7 @@ static int mtk_add_mac(struct mtk_eth *e
164 eth->netdev[id]->hw_features |= NETIF_F_LRO;
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;
172 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
173 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
175 #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
177 NETIF_F_HW_VLAN_CTAG_TX | \
178 - NETIF_F_HW_VLAN_CTAG_RX | \
179 NETIF_F_SG | NETIF_F_ALL_TSO | \