Skip to contentSkip to conversation

net: dsa: brcm: add legacy FCS tag

PATCH Superseded Álvaro Fernández Rojas 3 participants 7 messages Jun 10, 2025 – Jun 11, 2025

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: dsa: brcm: add legacy FCS tag

The existing brcm legacy tag only works with BCM63xx switches. These patches add a new legacy tag for BCM5325 and BCM5365 switches, which require including the FCS and length.

Álvaro Fernández Rojas (3):
net: dsa: tag_brcm: legacy: reorganize functions
net: dsa: tag_brcm: add support for legacy FCS tags
net: dsa: b53: support legacy FCS tags

v2: replace swab32 with cpu_to_le32.

 drivers/net/dsa/b53/Kconfig      |   1 +
 drivers/net/dsa/b53/b53_common.c |   7 +-
 include/net/dsa.h                |   2 +
 net/dsa/Kconfig                  |   8 +++
 net/dsa/tag_brcm.c               | 119 ++++++++++++++++++++++++-------
 5 files changed, 111 insertions(+), 26 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v2 1/3 net: dsa: tag_brcm: legacy: reorganize functions

Move brcm_leg_tag_rcv() definition to top.
This function is going to be shared between two different tags.

---
 net/dsa/tag_brcm.c | 64 +++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

v2: no changes

net/dsa/tag_brcm.c +32 -32
index fe75821623a4f..9f4b0bcd95cde 100644
@@ -213,6 +213,38 @@ MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM, BRCM_NAME);
 #endif
 
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_LEGACY)
+static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb,
+					struct net_device *dev)
+{
+	int len = BRCM_LEG_TAG_LEN;
+	int source_port;
+	u8 *brcm_tag;
+
+	if (unlikely(!pskb_may_pull(skb, BRCM_LEG_TAG_LEN + VLAN_HLEN)))
+		return NULL;
+
+	brcm_tag = dsa_etype_header_pos_rx(skb);
+
+	source_port = brcm_tag[5] & BRCM_LEG_PORT_ID;
+
+	skb->dev = dsa_conduit_find_user(dev, 0, source_port);
+	if (!skb->dev)
+		return NULL;
+
+	/* VLAN tag is added by BCM63xx internal switch */
+	if (netdev_uses_dsa(skb->dev))
+		len += VLAN_HLEN;
+
+	/* Remove Broadcom tag and update checksum */
+	skb_pull_rcsum(skb, len);
+
+	dsa_default_offload_fwd_mark(skb);
+
+	dsa_strip_etype_header(skb, len);
+
+	return skb;
+}
+
 static struct sk_buff *brcm_leg_tag_xmit(struct sk_buff *skb,
 					 struct net_device *dev)
 {
@@ -250,38 +282,6 @@ static struct sk_buff *brcm_leg_tag_xmit(struct sk_buff *skb,
 	return skb;
 }
 
-static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb,
-					struct net_device *dev)
-{
-	int len = BRCM_LEG_TAG_LEN;
-	int source_port;
-	u8 *brcm_tag;
-
-	if (unlikely(!pskb_may_pull(skb, BRCM_LEG_TAG_LEN + VLAN_HLEN)))
-		return NULL;
-
-	brcm_tag = dsa_etype_header_pos_rx(skb);
-
-	source_port = brcm_tag[5] & BRCM_LEG_PORT_ID;
-
-	skb->dev = dsa_conduit_find_user(dev, 0, source_port);
-	if (!skb->dev)
-		return NULL;
-
-	/* VLAN tag is added by BCM63xx internal switch */
-	if (netdev_uses_dsa(skb->dev))
-		len += VLAN_HLEN;
-
-	/* Remove Broadcom tag and update checksum */
-	skb_pull_rcsum(skb, len);
-
-	dsa_default_offload_fwd_mark(skb);
-
-	dsa_strip_etype_header(skb, len);
-
-	return skb;
-}
-
 static const struct dsa_device_ops brcm_legacy_netdev_ops = {
 	.name = BRCM_LEGACY_NAME,
 	.proto = DSA_TAG_PROTO_BRCM_LEGACY,
Signature · 1 line
2.39.5
#3 lore raw

PATCH v2 2/3 net: dsa: tag_brcm: add support for legacy FCS tags

In reply to Álvaro Fernández Rojas

Add support for legacy Broadcom FCS tags, which are similar to DSA_TAG_PROTO_BRCM_LEGACY.
BCM5325 and BCM5365 switches require including the original FCS value and length, as opposed to BCM63xx switches.
Adding the original FCS value and length to DSA_TAG_PROTO_BRCM_LEGACY would impact performance of BCM63xx switches, so it's better to create a new tag.

---
 include/net/dsa.h  |  2 ++
 net/dsa/Kconfig    |  8 +++++
 net/dsa/tag_brcm.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 82 insertions(+), 1 deletion(-)

v2: replace swab32 with cpu_to_le32.

include/net/dsa.h +2 -0
index 55e2d97f247eb..d73ea08800660 100644
@@ -54,11 +54,13 @@ struct tc_action;
 #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE		26
 #define DSA_TAG_PROTO_LAN937X_VALUE		27
 #define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE	28
+#define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE	29
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
 	DSA_TAG_PROTO_BRCM		= DSA_TAG_PROTO_BRCM_VALUE,
 	DSA_TAG_PROTO_BRCM_LEGACY	= DSA_TAG_PROTO_BRCM_LEGACY_VALUE,
+	DSA_TAG_PROTO_BRCM_LEGACY_FCS	= DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE,
 	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
 	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
 	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
net/dsa/Kconfig +8 -0
index 2dfe9063613fe..e6696e8212cf3 100644
@@ -49,6 +49,14 @@ config NET_DSA_TAG_BRCM_LEGACY
 	  Broadcom legacy switches which place the tag after the MAC source
 	  address.
 
+config NET_DSA_TAG_BRCM_LEGACY_FCS
+	tristate "Tag driver for Broadcom legacy switches using in-frame headers, FCS and length"
+	select NET_DSA_TAG_BRCM_COMMON
+	help
+	  Say Y if you want to enable support for tagging frames for the
+	  Broadcom legacy switches which place the tag after the MAC source
+	  address and require the original FCS and length.
+
 config NET_DSA_TAG_BRCM_PREPEND
 	tristate "Tag driver for Broadcom switches using prepended headers"
 	select NET_DSA_TAG_BRCM_COMMON
net/dsa/tag_brcm.c +72 -1

110 lines not on this page · raw message

Signature · 1 line
2.39.5
maintainer
#4 lore raw

Re: [PATCH net-next v2 2/3] net: dsa: tag_brcm: add support for legacy FCS tags

net/dsa/tag_brcm.c DSA_TAG_DRIVER(brcm_legacy_netdev_ops); · line 312

Quoted 4 lines · On Tue, 10 Jun 2025 18:31:53 +0200 Álvaro Fernández Rojas wrote:
net/dsa/tag_brcm.c +4 -0
+	struct dsa_port *dp = dsa_user_to_port(dev);
+	unsigned int fcs_len;
+	u32 fcs_val;
+	u8 *brcm_tag;

nit: please reorder the variable declaration lines longest to shortest

Quoted 4 lines
net/dsa/tag_brcm.c +4 -0
+	/* The Ethernet switch we are interfaced with needs packets to be at
+	 * least 64 bytes (including FCS) otherwise they will be discarded when
+	 * they enter the switch port logic. When Broadcom tags are enabled, we
+	 * need to make sure that packets are at least 70 bytes

net/dsa/tag_brcm.c DSA_TAG_DRIVER(brcm_legacy_netdev_ops); · line 327

Quoted 10 lines
net/dsa/tag_brcm.c +10 -0
+	 * (including FCS and tag) because the length verification is done after
+	 * the Broadcom tag is stripped off the ingress packet.
+	 *
+	 * Let dsa_user_xmit() free the SKB
+	 */
+	if (__skb_put_padto(skb, ETH_ZLEN + BRCM_LEG_TAG_LEN, false))
+		return NULL;
+
+	fcs_len = skb->len;
+	fcs_val = cpu_to_le32(crc32(~0, skb->data, fcs_len) ^ ~0);

sparse (C=1 build flag) complains about the loss of type annotation:

net/dsa/tag_brcm.c:327:17: warning: incorrect type in assignment (different base types)
net/dsa/tag_brcm.c:327:17: expected unsigned int [usertype] fcs_val
net/dsa/tag_brcm.c:327:17: got restricted __le32 [usertype]

Quoted 20 lines
net/dsa/tag_brcm.c +20 -0
+	skb_push(skb, BRCM_LEG_TAG_LEN);
+
+	dsa_alloc_etype_header(skb, BRCM_LEG_TAG_LEN);
+
+	brcm_tag = skb->data + 2 * ETH_ALEN;
+
+	/* Broadcom tag type */
+	brcm_tag[0] = BRCM_LEG_TYPE_HI;
+	brcm_tag[1] = BRCM_LEG_TYPE_LO;
+
+	/* Broadcom tag value */
+	brcm_tag[2] = BRCM_LEG_EGRESS | BRCM_LEG_LEN_HI(fcs_len);
+	brcm_tag[3] = BRCM_LEG_LEN_LO(fcs_len);
+	brcm_tag[4] = 0;
+	brcm_tag[5] = dp->index & BRCM_LEG_PORT_ID;
+
+	/* Original FCS value */
+	if (__skb_pad(skb, ETH_FCS_LEN, false))
+		return NULL;
+	skb_put_data(skb, &fcs_val, ETH_FCS_LEN);
Signature · 1 line
pw-bot: cr
#5 lore raw

PATCH v2 3/3 net: dsa: b53: support legacy FCS tags

In reply to Álvaro Fernández Rojas

Commit 46c5176c586c ("net: dsa: b53: support legacy tags") introduced support for legacy tags, but it turns out that BCM5325 and BCM5365 switches require the original FCS value and length, so they have to be treated differently.

Fixes 46c5176c586c ("net: dsa: b53: support legacy tags")
---
 drivers/net/dsa/b53/Kconfig      | 1 +
 drivers/net/dsa/b53/b53_common.c | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

v2: no changes

drivers/net/dsa/b53/Kconfig +1 -0
index ebaa4a80d5444..915008e8eff53 100644
@@ -5,6 +5,7 @@ menuconfig B53
 	select NET_DSA_TAG_NONE
 	select NET_DSA_TAG_BRCM
 	select NET_DSA_TAG_BRCM_LEGACY
+	select NET_DSA_TAG_BRCM_LEGACY_FCS
 	select NET_DSA_TAG_BRCM_PREPEND
 	help
 	  This driver adds support for Broadcom managed switch chips. It supports
drivers/net/dsa/b53/b53_common.c +5 -2
index 862bdccb74397..222107223d109 100644
@@ -2245,8 +2245,11 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
 		goto out;
 	}
 
-	/* Older models require a different 6 byte tag */
-	if (is5325(dev) || is5365(dev) || is63xx(dev)) {
+	/* Older models require different 6 byte tags */
+	if (is5325(dev) || is5365(dev)) {
+		dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY_FCS;
+		goto out;
+	} else if (is63xx(dev)) {
 		dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY;
 		goto out;
 	}
Signature · 1 line
2.39.5
maintainer Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH net-next v2 3/3] net: dsa: b53: support legacy FCS tags

Quoted 7 lines · Álvaro Fernández Rojas

Commit 46c5176c586c ("net: dsa: b53: support legacy tags") introduced support for legacy tags, but it turns out that BCM5325 and BCM5365 switches require the original FCS value and length, so they have to be treated differently.

Fixes 46c5176c586c ("net: dsa: b53: support legacy tags")
Signature · 1 line
Florian