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 --- 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 |= 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