mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused
@ 2026-11-17  0:16 Joseph Telaak
  2026-11-19 21:30 ` netdev-bot+sashiko
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Telaak @ 2026-11-17  0:16 UTC (permalink / raw)
  To: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Florian Fainelli, netdev, linux-kernel, Joseph Telaak

With port 5 as the CPU port, b53_brcm_hdr_setup() puts the switch in
dual-IMP mode, in which frames for the CPU from the user ports still go
to port 8: BPDUs, the IGMP/MLD copies b53_enable_mcast_snooping()
enables, and most traffic of standalone ports. On boards that leave
port 8 unconnected these are lost, so STP never sees its peers and a
loop between two user ports takes the host off the network.

Mirror them to port 5: frames to the bridge group address as they enter
a user port, everything else as it leaves port 8, which is enabled with
its link forced up and in the disabled STP state so that only frames for
the CPU leave it. The switch has one mirror, so tc mirroring is refused.
Frames to 01:80:c2:00:00:02, 03 and 0d still do not reach the CPU from a
bridged port.

Observed on a BCM53125 board in real use, with both user ports cabled
into the same LAN. Tested there with a host sending test frames into a
user port: bridged, BPDUs reached the CPU and forwarding kept working;
standalone, all but EAPOL to 01:80:c2:00:00:03 did, once each. No
selftests were run.

Fixes: 8fab459e69ab ("net: dsa: b53: Enable Broadcom tags for 531x5/539x families")
Signed-off-by: Joseph Telaak <joseph@telaak.dev>
---
Tested on a BCM53125 with this patch on a 7.3-based kernel, which only
lacks b53_enable_mcast_snooping(). Still net-next despite Fixes:, as it
enables port 8 and takes the mirror on every dual-IMP board; I can
resend to net if preferred. Boards that can wire port 8 (5301x, 58xx)
are better off using it.
---
Changes in v2:
- Also mirror what the switch sends to port 8 to port 5 (Jonas's egress
  mirror), with port 8 enabled, its link forced and in the disabled STP
  state, on all dual-IMP chips
- tc mirroring refused with -EOPNOTSUPP (not run on hardware: no clsact
  in the test image)
- Check that port 8 exists and is unused; add Fixes:
- A CFP redirect to port 8, where the chip has a CFP, is left for a
  follow-up
- Link to v1: https://patch.msgid.link/20261111-b53-bpdu-mirror-v1-1-f9f32e9d25db@telaak.dev
---
 drivers/net/dsa/b53/b53_common.c | 48 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/b53/b53_priv.h   |  1 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index b7aff5e238e8..f82139b0c501 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -745,6 +745,10 @@ void b53_disable_port(struct dsa_switch *ds, int port)
 	struct b53_device *dev = ds->priv;
 	u8 reg;
 
+	/* Port 8 carries frames for the CPU to the mirror */
+	if (port == B53_CPU_PORT && dev->cpu_mirror)
+		return;
+
 	/* Disable Tx/Rx for the port */
 	b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
 	reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
@@ -1326,6 +1330,42 @@ int b53_setup_devlink_resources(struct dsa_switch *ds)
 }
 EXPORT_SYMBOL(b53_setup_devlink_resources);
 
+/* With port 5 as the CPU port and port 8 unused, the switch runs in dual-IMP
+ * mode and still traps frames for the CPU from the user ports to port 8.
+ * Mirror them to port 5: frames to the bridge group address as they enter a
+ * user port, everything else as it leaves port 8, which needs Rx/Tx enabled
+ * and its link forced up for that, so b53_disable_port() leaves it alone.
+ * This takes the switch's only mirror.
+ */
+static void b53_setup_cpu_mirror(struct dsa_switch *ds)
+{
+	struct b53_device *dev = ds->priv;
+	int cpu_port = 5;
+
+	dev->cpu_mirror = false;
+	if (dev->tag_protocol == DSA_TAG_PROTO_NONE ||
+	    dev->imp_port != B53_CPU_PORT || B53_CPU_PORT >= ds->num_ports ||
+	    !dsa_is_cpu_port(ds, cpu_port) ||
+	    !dsa_is_unused_port(ds, B53_CPU_PORT))
+		return;
+
+	/* Rx/Tx on, STP disabled: only trapped frames leave port 8 */
+	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(B53_CPU_PORT),
+		   PORT_CTRL_DIS_STATE);
+	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
+		   PORT_OVERRIDE_EN | PORT_OVERRIDE_SPEED_1000M |
+		   PORT_OVERRIDE_FULL_DUPLEX | PORT_OVERRIDE_LINK);
+
+	b53_write48(dev, B53_MGMT_PAGE, B53_IG_MIR_MAC,
+		    ether_addr_to_u64(eth_stp_addr));
+	b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL,
+		    (MIRROR_DA << MIRROR_FILTER_SHIFT) |
+		    (dsa_user_ports(ds) & MIRROR_MASK));
+	b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, BIT(B53_CPU_PORT));
+	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, MIRROR_EN | cpu_port);
+	dev->cpu_mirror = true;
+}
+
 static int b53_setup(struct dsa_switch *ds)
 {
 	struct b53_device *dev = ds->priv;
@@ -1387,6 +1427,8 @@ static int b53_setup(struct dsa_switch *ds)
 			b53_disable_port(ds, port);
 	}
 
+	b53_setup_cpu_mirror(ds);
+
 	ret = b53_enable_mcast_snooping(dev);
 	if (ret)
 		return ret;
@@ -2604,6 +2646,12 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
 	struct b53_device *dev = ds->priv;
 	u16 reg, loc;
 
+	if (dev->cpu_mirror) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "The mirror carries CPU traffic to port 5");
+		return -EOPNOTSUPP;
+	}
+
 	if (ingress)
 		loc = B53_IG_MIR_CTL;
 	else
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index c4d2a41c714f..15f745d79bf4 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -170,6 +170,7 @@ struct b53_device {
 
 	/* run time configuration */
 	bool enable_jumbo;
+	bool cpu_mirror;
 
 	unsigned int num_vlans;
 	struct b53_vlan *vlans;

---
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
change-id: 20261109-b53-bpdu-mirror-d3f66c7a7fd2

Best regards,
--  
Joseph Telaak <joseph@telaak.dev>


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

* Re: [PATCH net-next v2] net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused
  2026-11-17  0:16 [PATCH net-next v2] net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused Joseph Telaak
@ 2026-11-19 21:30 ` netdev-bot+sashiko
  2026-11-19 21:37   ` Joseph Telaak
  0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 21:30 UTC (permalink / raw)
  To: joseph
  Cc: florian.fainelli, jonas.gorski, andrew, olteanv, davem, edumazet,
	kuba, pabeni, f.fainelli, netdev, linux-kernel

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message says the problem and the fix apply to
  "boards that leave port 8 unconnected".
- [Low] The Fixes: attribution is incomplete.
- [Low] `b53_setup_cpu_mirror()` programs global switch state that
  nothing ever restores: `B53_PORT_CTRL(8)` = `PORT_CTRL_DIS_STATE`, the…
- [Low] `b53_setup_cpu_mirror()` hard-codes the IMP state override for
  port 8 to `PORT_OVERRIDE_EN | PORT_OVERRIDE_SPEED_1000M |…

--

net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused

This patch applies when port 5 is the CPU port and port 8 is unused in
DT. In that case b53 uses the switch's single mirror to copy frames to
the bridge group address from user ports to port 5. It also copies all
port 8 egress to port 5, with port 8 enabled and its link forced up, and
refuses tc mirroring while this is active.

> to port 8: BPDUs, the IGMP/MLD copies b53_enable_mcast_snooping()
> enables, and most traffic of standalone ports. On boards that leave
> port 8 unconnected these are lost, so STP never sees its peers and a

[ ... ]

> Fixes: 8fab459e69ab ("net: dsa: b53: Enable Broadcom tags for 531x5/539x families")

[Severity: Low]
Is this Fixes: tag complete? The loss of "most traffic of standalone
ports" seems to come from commit 4227ea91e265 ("net: dsa: b53: prevent
standalone from trying to forward to other ports"). That commit added this
to b53_setup_port():

	if (dsa_is_user_port(ds, port))
		b53_set_eap_mode(dev, port, EAP_MODE_SIMPLIFIED);

Its commit message notes that "effectively this redirects all incoming
traffic to the CPU port". In dual-IMP mode (GC_FRM_MGMT_PORT_M, set by
b53_brcm_hdr_setup() for CPU port 5), that redirect target is port 8.

Before 4227ea91e265, standalone traffic followed the PVLAN/ARL path, which
b53_imp_vlan_setup() points at port 5.

8fab459e69ab is older, so this doesn't lose stable coverage. Would it
still help to also name 4227ea91e265, so that the standalone breakage on
these boards can be traced?

> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index b7aff5e238e85..f82139b0c501c 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c

[ ... ]

> @@ -1326,6 +1330,42 @@ int b53_setup_devlink_resources(struct dsa_switch *ds)

[ ... ]

> +static void b53_setup_cpu_mirror(struct dsa_switch *ds)
> +{
> +	struct b53_device *dev = ds->priv;
> +	int cpu_port = 5;
> +
> +	dev->cpu_mirror = false;
> +	if (dev->tag_protocol == DSA_TAG_PROTO_NONE ||
> +	    dev->imp_port != B53_CPU_PORT || B53_CPU_PORT >= ds->num_ports ||
> +	    !dsa_is_cpu_port(ds, cpu_port) ||
> +	    !dsa_is_unused_port(ds, B53_CPU_PORT))
> +		return;

[Severity: Medium]
The commit message says this is for "boards that leave port 8
unconnected". Can dsa_is_unused_port() tell such a board apart from one
where port 8 is wired inside the SoC and only disabled in DT?

On Northstar (BCM5301x) and NSP (BCM58xx), port 8 is wired inside the SoC
to a GMAC. arch/arm/boot/dts/broadcom/bcm-ns.dtsi has:

	port@8 {
		reg = <8>;
		ethernet = <&gmac2>;

and gmac2 stays enabled. Boards such as bcm4708-netgear-r6250.dts and
bcm47094-luxul-xwr-3100.dts use port 5 as the CPU port and set port@8 to
status = "disabled", so they pass all of these checks.

On those boards, the code below clears RX/TX_DISABLE on port 8 and forces
its link up at 1000/full. Before this patch, b53_disable_port() left port
8 with RX/TX disabled.

Port 8 then transmits the frames the switch traps or redirects to the CPU
(BPDUs, IGMP/MLD copies and, with EAP simplified mode, all standalone
ingress). They go to an internal MAC that DSA does not own and that
bgmac may have probed as an ordinary netdev.

The early return added to b53_disable_port() keeps port 8 enabled for the
life of the switch, with no way to opt out. b53_mirror_add() now also
returns -EOPNOTSUPP on all of these boards.

Should this be limited to chips where port 8 can't be wired internally?
If not, should the commit message say that 5301x/58xx boards with port 8
disabled in DT are affected too? Because of the Fixes: tag, this may also
be picked up for stable.

> +
> +	/* Rx/Tx on, STP disabled: only trapped frames leave port 8 */
> +	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(B53_CPU_PORT),
> +		   PORT_CTRL_DIS_STATE);
> +	b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
> +		   PORT_OVERRIDE_EN | PORT_OVERRIDE_SPEED_1000M |
> +		   PORT_OVERRIDE_FULL_DUPLEX | PORT_OVERRIDE_LINK);

[Severity: Low]
Is a fixed 1000/full override valid for every chip and IMP strapping that
reaches this point? Everywhere else, the driver derives
B53_PORT_OVERRIDE_CTRL from phylink data in b53_force_link() and
b53_force_port_config().

Mirroring port 8 egress only works if port 8 actually transmits what is
queued for it. Suppose the IMP is strapped to a mode whose TX clock comes
from the missing link partner (MAC-mode MII), or the forced speed doesn't
match the strapped interface. Could port 8 then fail to drain, leaving
CPU-bound frames in its egress queue instead of being mirrored?

That depends on whether the mirror copy is taken at enqueue or at transmit
time, which I couldn't confirm from the driver. The patch covers all
dual-IMP chips, but it was only tested on one BCM53125 board.

> +
> +	b53_write48(dev, B53_MGMT_PAGE, B53_IG_MIR_MAC,
> +		    ether_addr_to_u64(eth_stp_addr));
> +	b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL,
> +		    (MIRROR_DA << MIRROR_FILTER_SHIFT) |
> +		    (dsa_user_ports(ds) & MIRROR_MASK));
> +	b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, BIT(B53_CPU_PORT));
> +	b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, MIRROR_EN | cpu_port);
> +	dev->cpu_mirror = true;
> +}

[Severity: Low]
Is anything meant to undo this configuration? b53_teardown() only does
this:

static void b53_teardown(struct dsa_switch *ds)
{
	dsa_devlink_resources_unregister(ds);
}

b53_setup() doesn't roll it back if b53_enable_mcast_snooping() or
b53_setup_devlink_resources() fails afterwards. The early return above
also clears only dev->cpu_mirror and leaves the registers as they were.

On BCM531x5 parts without a reset GPIO, b53_switch_reset() issues no soft
reset; only is539x() and BCM58XX/BCM583XX get one. So this mirror and
port 8 override state can survive an unbind/rebind with a different DT,
or a kexec into another kernel.

Later, with cpu_mirror false, b53_mirror_add() only read-modify-writes
BIT(port) in the mirror control register and the capture port in
B53_MIR_CAP_CTL. Would a tc ingress mirror then inherit the MIRROR_DA
filter and the STP MAC, and copy only STP frames?

The stale BIT(8) in B53_EG_MIR_CTL would also copy all port 8 egress to
the user's capture port. And since B53_EG_MIR_CTL never becomes empty,
can b53_mirror_del() ever clear MIRROR_EN?

Separately, dev->cpu_mirror is set to true without checking any of the
b53_write*() return values. A failed bus write would leave the mirror
partly programmed, while tc mirroring is refused and port 8 stays enabled.
The rest of the driver also ignores b53_write*() errors, though.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-b53-bpdu-mirror-v2-1-c39ab745730f%40telaak.dev

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

* Re: [PATCH net-next v2] net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused
  2026-11-19 21:30 ` netdev-bot+sashiko
@ 2026-11-19 21:37   ` Joseph Telaak
  0 siblings, 0 replies; 3+ messages in thread
From: Joseph Telaak @ 2026-11-19 21:37 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: florian.fainelli, jonas.gorski, andrew, olteanv, davem, edumazet,
	kuba, pabeni, f.fainelli, netdev, linux-kernel

> Can dsa_is_unused_port() tell such a board apart from one where port 8
> is wired inside the SoC and only disabled in DT?

No. On 5301x and 58xx port 8 is wired to gmac2, and boards that use
port 5 disable port 8 in DT, so v2 would enable it and force its link
up toward that MAC. v3 will set the mirror up only on the external
531x5 switches, and add Fixes: 4227ea91e265 for the standalone traffic.

pw-bot: cr

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

end of thread, other threads:[~2026-11-19 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  0:16 [PATCH net-next v2] net: dsa: b53: mirror CPU-bound frames to port 5 when port 8 is unused Joseph Telaak
2026-11-19 21:30 ` netdev-bot+sashiko
2026-11-19 21:37   ` Joseph Telaak

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®