mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: stmmac: xgmac: Report the VLAN tag type from the descriptor
@ 2026-11-18 16:21 Maxime Chevallier
  2026-11-18 20:09 ` Nicolai Buchwitz
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Chevallier @ 2026-11-18 16:21 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Paolo Abeni,
	Simon Horman, Maxime Coquelin, Alexandre Torgue, Russell King,
	Lorenzo Bianconi, Nicolai Buchwitz, Ovidiu Panait, Joseph Steel,
	Muhammad Nazim Amirul Nazle Asmade
  Cc: Maxime Chevallier, thomas.petazzoni, Alexis Lothoré,
	netdev, linux-kernel, linux-arm-kernel

Stmmac's double VLAN handling hasn't been working great for a while,
it's been recently reworked for dwmac4 by Ovidiu Panait. In that work,
it was found that the tag stripping hardcodes the 8021Q tag type for
XGMAC while stripping the tag, while the IP actually reports the outer
tag type in the descriptor.

The tag type can be one of 6 different values (note inner/outer is
reversed in the macro names):

 - XGMAC_ET_LT_VLAN_STAG       single S-tag
 - XGMAC_ET_LT_VLAN_CTAG       single C-tag
 - XGMAC_ET_LT_DVLAN_CTAG_CTAG outer C-tag, inner C-tag
 - XGMAC_ET_LT_DVLAN_STAG_STAG outer S-tag, inner S-tag
 - XGMAC_ET_LT_DVLAN_CTAG_STAG outer S-tag, inner C-tag
 - XGMAC_ET_LT_DVLAN_STAG_CTAG outer C-tag, inner S-tag

Report that tag type through a dedicated desc ops and report it to the
stack.

We keep the 8021Q fallback when we don't have the ops, as we don't
set NETIF_F_HW_VLAN_STAG_FILTER on the cores that don't support that.

This has been tested on AgileX5 with the vlan.py selftest.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 .../net/ethernet/stmicro/stmmac/dwxgmac2_descs.c    | 13 +++++++++++++
 drivers/net/ethernet/stmicro/stmmac/hwif.h          |  2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c   |  6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
index 6719ac6e395b..71ce2bc9b5e1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
@@ -76,6 +76,18 @@ static bool dwxgmac2_wrback_get_rx_vlan_valid(struct dma_desc *p)
 	       et_lt <= XGMAC_ET_LT_DVLAN_STAG_CTAG;
 }
 
+static u16 dwxgmac2_wrback_get_rx_vlan_proto(struct dma_desc *p)
+{
+	switch (FIELD_GET(XGMAC_RDES3_ET_LT, le32_to_cpu(p->des3))) {
+	case XGMAC_ET_LT_VLAN_STAG:
+	case XGMAC_ET_LT_DVLAN_STAG_STAG:
+	case XGMAC_ET_LT_DVLAN_CTAG_STAG:
+		return ETH_P_8021AD;
+	default:
+		return ETH_P_8021Q;
+	}
+}
+
 static int dwxgmac2_get_rx_frame_len(struct dma_desc *p, int rx_coe)
 {
 	return (le32_to_cpu(p->des3) & XGMAC_RDES3_PL);
@@ -352,6 +364,7 @@ const struct stmmac_desc_ops dwxgmac210_desc_ops = {
 	.set_rx_owner = dwxgmac2_set_rx_owner,
 	.get_rx_vlan_tci = dwxgmac2_wrback_get_rx_vlan_tci,
 	.get_rx_vlan_valid = dwxgmac2_wrback_get_rx_vlan_valid,
+	.get_rx_vlan_proto = dwxgmac2_wrback_get_rx_vlan_proto,
 	.get_rx_frame_len = dwxgmac2_get_rx_frame_len,
 	.enable_tx_timestamp = dwxgmac2_enable_tx_timestamp,
 	.get_tx_timestamp_status = dwxgmac2_get_tx_timestamp_status,
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 8ae95e91a36a..047bda5cbd92 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -60,6 +60,8 @@ struct stmmac_desc_ops {
 	u16 (*get_rx_vlan_tci)(struct dma_desc *p);
 	/* Get the valid status of descriptor */
 	bool (*get_rx_vlan_valid)(struct dma_desc *p);
+	/* Get the vlan tag proto from the descriptor */
+	u16 (*get_rx_vlan_proto)(struct dma_desc *p);
 	/* Return the transmit status looking at the TDES1 */
 	int (*tx_status)(struct stmmac_extra_stats *x,
 			 struct dma_desc *p, void __iomem *ioaddr);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
index fb9aad748cb3..bf23d82e9f38 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
@@ -209,8 +209,12 @@ static void vlan_rx_hw(struct mac_device_info *hw,
 {
 	if (hw->desc->get_rx_vlan_valid(rx_desc)) {
 		u16 vid = hw->desc->get_rx_vlan_tci(rx_desc);
+		u16 proto = ETH_P_8021Q;
 
-		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
+		if (hw->desc->get_rx_vlan_proto)
+			proto = hw->desc->get_rx_vlan_proto(rx_desc);
+
+		__vlan_hwaccel_put_tag(skb, htons(proto), vid);
 	}
 }
 
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 16:21 [PATCH net-next] net: stmmac: xgmac: Report the VLAN tag type from the descriptor Maxime Chevallier
2026-11-18 20:09 ` Nicolai Buchwitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®