Skip to content

Commit 1a3245f

Browse files
vladimirolteandavem330
authored andcommitted
net: ethernet: mtk_eth_soc: fix DSA TX tag hwaccel for switch port 0
Arınç reports that on his MT7621AT Unielec U7621-06 board and MT7623NI Bananapi BPI-R2, packets received by the CPU over mt7530 switch port 0 (of which this driver acts as the DSA master) are not processed correctly by software. More precisely, they arrive without a DSA tag (in packet or in the hwaccel area - skb_metadata_dst()), so DSA cannot demux them towards the switch's interface for port 0. Traffic from other ports receives a skb_metadata_dst() with the correct port and is demuxed properly. Looking at mtk_poll_rx(), it becomes apparent that this driver uses the skb vlan hwaccel area: union { u32 vlan_all; struct { __be16 vlan_proto; __u16 vlan_tci; }; }; as a temporary storage for the VLAN hwaccel tag, or the DSA hwaccel tag. If this is a DSA master it's a DSA hwaccel tag, and finally clears up the skb VLAN hwaccel header. I'm guessing that the problem is the (mis)use of API. skb_vlan_tag_present() looks like this: #define skb_vlan_tag_present(__skb) (!!(__skb)->vlan_all) So if both vlan_proto and vlan_tci are zeroes, skb_vlan_tag_present() returns precisely false. I don't know for sure what is the format of the DSA hwaccel tag, but I surely know that lowermost 3 bits of vlan_proto are 0 when receiving from port 0: unsigned int port = vlan_proto & GENMASK(2, 0); If the RX descriptor has no other bits set to non-zero values in RX_DMA_VTAG, then the call to __vlan_hwaccel_put_tag() will not, in fact, make the subsequent skb_vlan_tag_present() return true, because it's implemented like this: static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci) { skb->vlan_proto = vlan_proto; skb->vlan_tci = vlan_tci; } What we need to do to fix this problem (assuming this is the problem) is to stop using skb->vlan_all as temporary storage for driver affairs, and just create some local variables that serve the same purpose, but hopefully better. Instead of calling skb_vlan_tag_present(), let's look at a boolean has_hwaccel_tag which we set to true when the RX DMA descriptors have something. Disambiguate based on netdev_uses_dsa() whether this is a VLAN or DSA hwaccel tag, and only call __vlan_hwaccel_put_tag() if we're certain it's a VLAN tag. Arınç confirms that the treatment works, so this validates the assumption. Link: https://lore.kernel.org/netdev/[email protected]/ Fixes: 2d7605a ("net: ethernet: mtk_eth_soc: enable hardware DSA untagging") Reported-by: Arınç ÜNAL <[email protected]> Tested-by: Arınç ÜNAL <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Felix Fietkau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 821de68 commit 1a3245f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
18701870

18711871
while (done < budget) {
18721872
unsigned int pktlen, *rxdcsum;
1873+
bool has_hwaccel_tag = false;
18731874
struct net_device *netdev;
1875+
u16 vlan_proto, vlan_tci;
18741876
dma_addr_t dma_addr;
18751877
u32 hash, reason;
18761878
int mac = 0;
@@ -2010,27 +2012,29 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
20102012

20112013
if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
20122014
if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
2013-
if (trxd.rxd3 & RX_DMA_VTAG_V2)
2014-
__vlan_hwaccel_put_tag(skb,
2015-
htons(RX_DMA_VPID(trxd.rxd4)),
2016-
RX_DMA_VID(trxd.rxd4));
2015+
if (trxd.rxd3 & RX_DMA_VTAG_V2) {
2016+
vlan_proto = RX_DMA_VPID(trxd.rxd4);
2017+
vlan_tci = RX_DMA_VID(trxd.rxd4);
2018+
has_hwaccel_tag = true;
2019+
}
20172020
} else if (trxd.rxd2 & RX_DMA_VTAG) {
2018-
__vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)),
2019-
RX_DMA_VID(trxd.rxd3));
2021+
vlan_proto = RX_DMA_VPID(trxd.rxd3);
2022+
vlan_tci = RX_DMA_VID(trxd.rxd3);
2023+
has_hwaccel_tag = true;
20202024
}
20212025
}
20222026

20232027
/* When using VLAN untagging in combination with DSA, the
20242028
* hardware treats the MTK special tag as a VLAN and untags it.
20252029
*/
2026-
if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) {
2027-
unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0);
2030+
if (has_hwaccel_tag && netdev_uses_dsa(netdev)) {
2031+
unsigned int port = vlan_proto & GENMASK(2, 0);
20282032

20292033
if (port < ARRAY_SIZE(eth->dsa_meta) &&
20302034
eth->dsa_meta[port])
20312035
skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
2032-
2033-
__vlan_hwaccel_clear_tag(skb);
2036+
} else if (has_hwaccel_tag) {
2037+
__vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan_tci);
20342038
}
20352039

20362040
skb_record_rx_queue(skb, 0);

0 commit comments

Comments
 (0)