e75459696b6c9540cb4460aa81f2703965f6eba0
[openwrt/staging/xback.git] /
1 From: Vladimir Oltean <vladimir.oltean@nxp.com>
2 Date: Tue, 7 Feb 2023 12:30:27 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: fix DSA TX tag hwaccel for switch
4 port 0
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Arınç reports that on his MT7621AT Unielec U7621-06 board and MT7623NI
10 Bananapi BPI-R2, packets received by the CPU over mt7530 switch port 0
11 (of which this driver acts as the DSA master) are not processed
12 correctly by software. More precisely, they arrive without a DSA tag
13 (in packet or in the hwaccel area - skb_metadata_dst()), so DSA cannot
14 demux them towards the switch's interface for port 0. Traffic from other
15 ports receives a skb_metadata_dst() with the correct port and is demuxed
16 properly.
17
18 Looking at mtk_poll_rx(), it becomes apparent that this driver uses the
19 skb vlan hwaccel area:
20
21 union {
22 u32 vlan_all;
23 struct {
24 __be16 vlan_proto;
25 __u16 vlan_tci;
26 };
27 };
28
29 as a temporary storage for the VLAN hwaccel tag, or the DSA hwaccel tag.
30 If this is a DSA master it's a DSA hwaccel tag, and finally clears up
31 the skb VLAN hwaccel header.
32
33 I'm guessing that the problem is the (mis)use of API.
34 skb_vlan_tag_present() looks like this:
35
36 #define skb_vlan_tag_present(__skb) (!!(__skb)->vlan_all)
37
38 So if both vlan_proto and vlan_tci are zeroes, skb_vlan_tag_present()
39 returns precisely false. I don't know for sure what is the format of the
40 DSA hwaccel tag, but I surely know that lowermost 3 bits of vlan_proto
41 are 0 when receiving from port 0:
42
43 unsigned int port = vlan_proto & GENMASK(2, 0);
44
45 If the RX descriptor has no other bits set to non-zero values in
46 RX_DMA_VTAG, then the call to __vlan_hwaccel_put_tag() will not, in
47 fact, make the subsequent skb_vlan_tag_present() return true, because
48 it's implemented like this:
49
50 static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
51 __be16 vlan_proto, u16 vlan_tci)
52 {
53 skb->vlan_proto = vlan_proto;
54 skb->vlan_tci = vlan_tci;
55 }
56
57 What we need to do to fix this problem (assuming this is the problem) is
58 to stop using skb->vlan_all as temporary storage for driver affairs, and
59 just create some local variables that serve the same purpose, but
60 hopefully better. Instead of calling skb_vlan_tag_present(), let's look
61 at a boolean has_hwaccel_tag which we set to true when the RX DMA
62 descriptors have something. Disambiguate based on netdev_uses_dsa()
63 whether this is a VLAN or DSA hwaccel tag, and only call
64 __vlan_hwaccel_put_tag() if we're certain it's a VLAN tag.
65
66 Arınç confirms that the treatment works, so this validates the
67 assumption.
68
69 Link: https://lore.kernel.org/netdev/704f3a72-fc9e-714a-db54-272e17612637@arinc9.com/
70 Fixes: 2d7605a72906 ("net: ethernet: mtk_eth_soc: enable hardware DSA untagging")
71 Reported-by: Arınç ÜNAL <arinc.unal@arinc9.com>
72 Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
73 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
74 Reviewed-by: Felix Fietkau <nbd@nbd.name>
75 Signed-off-by: David S. Miller <davem@davemloft.net>
76 ---
77
78 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
79 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
80 @@ -1829,7 +1829,9 @@ static int mtk_poll_rx(struct napi_struc
81
82 while (done < budget) {
83 unsigned int pktlen, *rxdcsum;
84 + bool has_hwaccel_tag = false;
85 struct net_device *netdev;
86 + u16 vlan_proto, vlan_tci;
87 dma_addr_t dma_addr;
88 u32 hash, reason;
89 int mac = 0;
90 @@ -1969,27 +1971,29 @@ static int mtk_poll_rx(struct napi_struc
91
92 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
93 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
94 - if (trxd.rxd3 & RX_DMA_VTAG_V2)
95 - __vlan_hwaccel_put_tag(skb,
96 - htons(RX_DMA_VPID(trxd.rxd4)),
97 - RX_DMA_VID(trxd.rxd4));
98 + if (trxd.rxd3 & RX_DMA_VTAG_V2) {
99 + vlan_proto = RX_DMA_VPID(trxd.rxd4);
100 + vlan_tci = RX_DMA_VID(trxd.rxd4);
101 + has_hwaccel_tag = true;
102 + }
103 } else if (trxd.rxd2 & RX_DMA_VTAG) {
104 - __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)),
105 - RX_DMA_VID(trxd.rxd3));
106 + vlan_proto = RX_DMA_VPID(trxd.rxd3);
107 + vlan_tci = RX_DMA_VID(trxd.rxd3);
108 + has_hwaccel_tag = true;
109 }
110 }
111
112 /* When using VLAN untagging in combination with DSA, the
113 * hardware treats the MTK special tag as a VLAN and untags it.
114 */
115 - if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) {
116 - unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0);
117 + if (has_hwaccel_tag && netdev_uses_dsa(netdev)) {
118 + unsigned int port = vlan_proto & GENMASK(2, 0);
119
120 if (port < ARRAY_SIZE(eth->dsa_meta) &&
121 eth->dsa_meta[port])
122 skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
123 -
124 - __vlan_hwaccel_clear_tag(skb);
125 + } else if (has_hwaccel_tag) {
126 + __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan_tci);
127 }
128
129 skb_record_rx_queue(skb, 0);