* [PATCH net v6 1/8] net: dsa: b53: initialize the jumbo frame size register offset
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
The chip data specifies both the jumbo port mask and frame size register
offsets, but b53_switch_init() only copies the former into the device.
Since the device is zero-initialized, b53_set_jumbo() writes the frame
size to offset zero instead of the chip-specific size register at 0x05
or 0x08.
Copy jumbo_size_reg from the chip data along with jumbo_pm_reg so frame
size updates reach the intended register.
Fixes: 967dd82ffc52 ("net: dsa: b53: Add support for Broadcom RoboSwitch")
Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index b7aff5e238e8..1f5776dfaae2 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -3172,6 +3172,7 @@ static int b53_switch_init(struct b53_device *dev)
dev->vta_regs[1] = chip->vta_regs[1];
dev->vta_regs[2] = chip->vta_regs[2];
dev->jumbo_pm_reg = chip->jumbo_pm_reg;
+ dev->jumbo_size_reg = chip->jumbo_size_reg;
dev->imp_port = chip->imp_port;
dev->num_vlans = chip->vlans;
dev->num_arl_bins = chip->arl_bins;
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 2/8] net: dsa: b53: fix the SRAB grant timeout check
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Daniel Machon, Andrew Lunn,
Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Vivien Didelot, open list
b53_srab_request_grant() polls for a grant up to 20 times, but checks for
an iteration count of five to detect a timeout. This rejects a grant
received on the sixth poll and reports success when all 20 polls finish
without a grant. The latter allows a register access to proceed without
ownership of the switch resources.
Check for exhaustion of all 20 iterations instead.
Fixes: 967dd82ffc52 ("net: dsa: b53: Add support for Broadcom RoboSwitch")
Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_srab.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c
index e6d14fdc56fd..7306535a892a 100644
--- a/drivers/net/dsa/b53/b53_srab.c
+++ b/drivers/net/dsa/b53/b53_srab.c
@@ -105,7 +105,7 @@ static int b53_srab_request_grant(struct b53_device *dev)
break;
usleep_range(10, 100);
}
- if (WARN_ON(i == 5))
+ if (WARN_ON(i == 20))
return -EIO;
return 0;
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 3/8] net: dsa: b53: clear stale state when creating an ARL entry
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
When an ARL lookup does not find the requested MAC and VID, b53_arl_read()
returns the first free bin index but leaves the entry populated with the
last bin examined. The multicast add path then ORs the requested port into
that unrelated entry's forwarding bitmap, potentially forwarding packets
to ports which are not members of the multicast group.
Clear the entry before creating a new one. Also return without writing
anything when deleting an entry which is not present, instead of writing
back stale bin contents. The return value for that case is unchanged (0).
Fixes: 5d65b64a3d97 ("net: dsa: b53: Add support for MDB")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 1f5776dfaae2..dac6013f8fe2 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2055,9 +2055,13 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
addr, vid);
return is_valid ? ret : 0;
case -ENOENT:
+ if (!is_valid)
+ return 0;
+
/* We could not find a matching MAC, so reset to a new entry */
dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n",
addr, vid, idx);
+ memset(&ent, 0, sizeof(ent));
break;
default:
dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n",
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 4/8] net: dsa: b53: reject conflicting mirror destinations
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (2 preceding siblings ...)
2026-11-16 21:09 ` [PATCH net v6 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
The mirror capture control register selects one destination for all
ingress and egress mirror sources. Adding a rule for a different capture
port currently overwrites that field and silently redirects all existing
mirror rules.
Read the capture control before changing any source masks and reject a
different destination while mirroring is enabled. Return an extack which
describes the hardware limitation, and propagate a failed capture-control
read rather than making the decision from uninitialized data.
Also clear the whole capture-port field, rather than only the bits set
in ~mirror->to_local_port, when the final source is removed. This is a
cleanup, the field is ignored while MIRROR_EN is clear and is rewritten
by the next add.
Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")
Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index dac6013f8fe2..64e04c5731a6 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2606,7 +2606,19 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
struct netlink_ext_ack *extack)
{
struct b53_device *dev = ds->priv;
- u16 reg, loc;
+ u16 reg, loc, cap_ctl;
+ int ret;
+
+ ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &cap_ctl);
+ if (ret)
+ return ret;
+
+ if ((cap_ctl & MIRROR_EN) &&
+ (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Only one mirroring destination is supported");
+ return -EOPNOTSUPP;
+ }
if (ingress)
loc = B53_IG_MIR_CTL;
@@ -2617,11 +2629,10 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
reg |= BIT(port);
b53_write16(dev, B53_MGMT_PAGE, loc, reg);
- b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
- reg &= ~CAP_PORT_MASK;
- reg |= mirror->to_local_port;
- reg |= MIRROR_EN;
- b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
+ cap_ctl &= ~CAP_PORT_MASK;
+ cap_ctl |= mirror->to_local_port;
+ cap_ctl |= MIRROR_EN;
+ b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
return 0;
}
@@ -2658,10 +2669,8 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
/* Both no longer have ports, let's disable mirroring */
- if (loc_disable && other_loc_disable) {
- reg &= ~MIRROR_EN;
- reg &= ~mirror->to_local_port;
- }
+ if (loc_disable && other_loc_disable)
+ reg &= ~(MIRROR_EN | CAP_PORT_MASK);
b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
}
EXPORT_SYMBOL(b53_mirror_del);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 5/8] net: dsa: b53: use the correct override register 2 Gbps bit
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (3 preceding siblings ...)
2026-11-16 21:09 ` [PATCH net v6 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
The IMP and per-port GMII override registers swap the override-enable and 2
Gbps speed bits. Using the IMP speed bit on a GMII port clears its override
enable and leaves any previous 2 Gbps selection intact. Select the speed
bit alongside the register and enable bit so lower speeds clear the correct
bit and 2 Gbps sets it.
Fixes: b6a8a5477fe9 ("net: dsa: b53: fix resetting speed and pause on forced link")
Fixes: 41af38324341 ("net: dsa: b53: restore the NSP IMP port 2 Gbps mode")
Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 64e04c5731a6..d8dafa9e0c44 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1427,17 +1427,19 @@ static void b53_force_port_config(struct b53_device *dev, int port,
int speed, int duplex,
bool tx_pause, bool rx_pause)
{
- u8 reg, val, off;
+ u8 reg, val, off, speed2000;
/* Override the port settings */
if (port == dev->imp_port) {
off = B53_PORT_OVERRIDE_CTRL;
val = PORT_OVERRIDE_EN;
+ speed2000 = PORT_OVERRIDE_SPEED_2000M;
} else if (is5325(dev)) {
return;
} else {
off = B53_GMII_PORT_OVERRIDE_CTRL(port);
val = GMII_PO_EN;
+ speed2000 = GMII_PO_SPEED_2000M;
}
b53_read8(dev, B53_CTRL_PAGE, off, ®);
@@ -1449,11 +1451,12 @@ static void b53_force_port_config(struct b53_device *dev, int port,
reg &= ~(0x3 << GMII_PO_SPEED_S);
if (is5301x(dev) || is58xx(dev))
- reg &= ~PORT_OVERRIDE_SPEED_2000M;
+ reg &= ~speed2000;
switch (speed) {
case 2000:
- reg |= PORT_OVERRIDE_SPEED_2000M;
+ if (is5301x(dev) || is58xx(dev))
+ reg |= speed2000;
fallthrough;
case SPEED_1000:
reg |= PORT_OVERRIDE_SPEED_1000M;
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 6/8] net: dsa: b53: reference count shared mirror source bits
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (4 preceding siblings ...)
2026-11-16 21:09 ` [PATCH net v6 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Florian Fainelli
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
Multiple tc matchall filters can use the same source port, direction and
capture destination, but the hardware represents that source with one
mask bit. Removing any one filter currently clears the bit even when
another filter still needs it, and can also disable mirroring globally.
Track references to each port's ingress and egress source bits. Program
a bit for the first reference and retain it until the last reference is
removed. Keep the two directions independent and ignore a deletion with
no matching reference to avoid underflow. The tc callbacks serialize this
accounting under RTNL.
Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 61 ++++++++++++++++++++++++++++++++
drivers/net/dsa/b53/b53_priv.h | 4 +++
2 files changed, 65 insertions(+)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index d8dafa9e0c44..98696bce368f 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2604,11 +2604,56 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
}
EXPORT_SYMBOL(b53_get_tag_protocol);
+int b53_mirror_init(struct dsa_switch *ds)
+{
+ struct b53_device *dev = ds->priv;
+ u16 ingress = 0, egress = 0, cap_ctl = 0;
+ unsigned int port;
+ int ret;
+
+ /* A switch reset may leave the previous mirror configuration intact. */
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, 0);
+ if (ret)
+ return ret;
+
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, 0);
+ if (ret)
+ return ret;
+
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, 0);
+ if (ret)
+ return ret;
+
+ /* DSA retains matchall filters across suspend and resume. */
+ for (port = 0; port < dev->num_ports; port++) {
+ if (dev->ports[port].mirror_count[true])
+ ingress |= BIT(port);
+ if (dev->ports[port].mirror_count[false])
+ egress |= BIT(port);
+ }
+
+ if (!(ingress | egress))
+ return 0;
+
+ cap_ctl = MIRROR_EN | dev->mirror_port;
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
+ if (ret)
+ return ret;
+
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ingress);
+ if (ret)
+ return ret;
+
+ return b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, egress);
+}
+EXPORT_SYMBOL(b53_mirror_init);
+
int b53_mirror_add(struct dsa_switch *ds, int port,
struct dsa_mall_mirror_tc_entry *mirror, bool ingress,
struct netlink_ext_ack *extack)
{
struct b53_device *dev = ds->priv;
+ unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
u16 reg, loc, cap_ctl;
int ret;
@@ -2623,6 +2668,11 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
return -EOPNOTSUPP;
}
+ if (*mirror_count) {
+ (*mirror_count)++;
+ return 0;
+ }
+
if (ingress)
loc = B53_IG_MIR_CTL;
else
@@ -2637,6 +2687,9 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
cap_ctl |= MIRROR_EN;
b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
+ (*mirror_count)++;
+ dev->mirror_port = mirror->to_local_port;
+
return 0;
}
EXPORT_SYMBOL(b53_mirror_add);
@@ -2645,9 +2698,17 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
struct dsa_mall_mirror_tc_entry *mirror)
{
struct b53_device *dev = ds->priv;
+ unsigned int *mirror_count =
+ &dev->ports[port].mirror_count[mirror->ingress];
bool loc_disable = false, other_loc_disable = false;
u16 reg, loc;
+ if (!*mirror_count)
+ return;
+
+ if (--(*mirror_count))
+ return;
+
if (mirror->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..df00a5ae46c9 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -119,6 +119,8 @@ struct b53_pcs {
#define B53_N_PCS 2
struct b53_port {
+ /* References to each egress/ingress mirror source mask bit. */
+ unsigned int mirror_count[2];
u16 vlan_ctl_mask;
u16 pvid;
struct ethtool_keee eee;
@@ -170,6 +172,7 @@ struct b53_device {
/* run time configuration */
bool enable_jumbo;
+ unsigned int mirror_port;
unsigned int num_vlans;
struct b53_vlan *vlans;
@@ -545,6 +548,7 @@ int b53_mdb_add(struct dsa_switch *ds, int port,
int b53_mdb_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb,
struct dsa_db db);
+int b53_mirror_init(struct dsa_switch *ds);
int b53_mirror_add(struct dsa_switch *ds, int port,
struct dsa_mall_mirror_tc_entry *mirror, bool ingress,
struct netlink_ext_ack *extack);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (5 preceding siblings ...)
2026-11-16 21:09 ` [PATCH net v6 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
2026-11-19 9:10 ` netdev-bot+sashiko
2026-11-16 21:09 ` [PATCH net v6 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Florian Fainelli
7 siblings, 1 reply; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
The mirror destination check can reject a first rule when a bootloader or
previous kernel left mirroring enabled. Not all supported switches receive
a hardware reset during setup. Unchecked register accesses can also
corrupt mirror state or report an unsuccessful rule installation as
successful. Reference counting must not record a first source reference
until hardware programming has succeeded.
Clear capture control and both source-control registers during b53 and
bcm_sf2 setup, then rebuild the source masks and capture destination from
the mirror reference counts, propagating initialization failures. Since
bcm_sf2 runs setup again on resume, this also restores active mirror
rules after suspend.
Check all mirror register reads and writes and only increment the source
reference count after successful programming. Log deletion failures
because the DSA callback cannot return an error.
Use the source masks to decide whether a destination is occupied. This
preserves the destination when a failed deletion leaves sources enabled,
and permits a new destination after the last source was removed even if
the final capture-control clear failed. Program the capture destination
before the new source so a failed destination write cannot leave a new
source enabled. Clearing the inactive capture-port field is cleanup.
This builds on "net: dsa: b53: reject conflicting mirror destinations" and
"net: dsa: b53: reference count shared mirror source bits", and must be
applied after them.
Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 91 ++++++++++++++++++++------------
drivers/net/dsa/bcm_sf2.c | 4 ++
2 files changed, 61 insertions(+), 34 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 98696bce368f..deb331b3629a 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1360,6 +1360,10 @@ static int b53_setup(struct dsa_switch *ds)
return ret;
}
+ ret = b53_mirror_init(ds);
+ if (ret)
+ return ret;
+
/* setup default vlan for filtering mode */
pvid = b53_default_pvid(dev);
vl = &dev->vlans[pvid];
@@ -2654,14 +2658,25 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
{
struct b53_device *dev = ds->priv;
unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
- u16 reg, loc, cap_ctl;
+ u16 reg, other_reg, loc, other_loc, cap_ctl;
int ret;
+ loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
+ other_loc = ingress ? B53_EG_MIR_CTL : B53_IG_MIR_CTL;
+
+ ret = b53_read16(dev, B53_MGMT_PAGE, loc, ®);
+ if (ret)
+ return ret;
+
+ ret = b53_read16(dev, B53_MGMT_PAGE, other_loc, &other_reg);
+ if (ret)
+ return ret;
+
ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &cap_ctl);
if (ret)
return ret;
- if ((cap_ctl & MIRROR_EN) &&
+ if (((reg | other_reg) & MIRROR_MASK) &&
(cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
NL_SET_ERR_MSG_MOD(extack,
"Only one mirroring destination is supported");
@@ -2673,19 +2688,17 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
return 0;
}
- if (ingress)
- loc = B53_IG_MIR_CTL;
- else
- loc = B53_EG_MIR_CTL;
-
- b53_read16(dev, B53_MGMT_PAGE, loc, ®);
- reg |= BIT(port);
- b53_write16(dev, B53_MGMT_PAGE, loc, reg);
-
+ /* Select the destination before enabling the new source. */
cap_ctl &= ~CAP_PORT_MASK;
cap_ctl |= mirror->to_local_port;
cap_ctl |= MIRROR_EN;
- b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
+ if (ret)
+ return ret;
+
+ ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port));
+ if (ret)
+ return ret;
(*mirror_count)++;
dev->mirror_port = mirror->to_local_port;
@@ -2700,8 +2713,8 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
struct b53_device *dev = ds->priv;
unsigned int *mirror_count =
&dev->ports[port].mirror_count[mirror->ingress];
- bool loc_disable = false, other_loc_disable = false;
- u16 reg, loc;
+ u16 reg, other_reg, loc, other_loc;
+ int ret;
if (!*mirror_count)
return;
@@ -2709,33 +2722,43 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
if (--(*mirror_count))
return;
- if (mirror->ingress)
- loc = B53_IG_MIR_CTL;
- else
- loc = B53_EG_MIR_CTL;
+ loc = mirror->ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
+ other_loc = mirror->ingress ? B53_EG_MIR_CTL : B53_IG_MIR_CTL;
/* Update the desired ingress/egress register */
- b53_read16(dev, B53_MGMT_PAGE, loc, ®);
+ ret = b53_read16(dev, B53_MGMT_PAGE, loc, ®);
+ if (ret)
+ goto err;
+
reg &= ~BIT(port);
- if (!(reg & MIRROR_MASK))
- loc_disable = true;
- b53_write16(dev, B53_MGMT_PAGE, loc, reg);
+ ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg);
+ if (ret)
+ goto err;
/* Now look at the other one to know if we can disable mirroring
* entirely
*/
- if (mirror->ingress)
- b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®);
- else
- b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®);
- if (!(reg & MIRROR_MASK))
- other_loc_disable = true;
-
- b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
- /* Both no longer have ports, let's disable mirroring */
- if (loc_disable && other_loc_disable)
- reg &= ~(MIRROR_EN | CAP_PORT_MASK);
- b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
+ ret = b53_read16(dev, B53_MGMT_PAGE, other_loc, &other_reg);
+ if (ret)
+ goto err;
+
+ if ((reg | other_reg) & MIRROR_MASK)
+ return;
+
+ ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
+ if (ret)
+ goto err;
+
+ reg &= ~(MIRROR_EN | CAP_PORT_MASK);
+ ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
+ if (ret)
+ goto err;
+
+ return;
+
+err:
+ dev_err(dev->dev, "Failed to delete mirror rule for port %d: %d\n",
+ port, ret);
}
EXPORT_SYMBOL(b53_mirror_del);
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 1747a1f20c78..cbaa5de9b107 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1061,6 +1061,10 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
unsigned int port;
int ret;
+ ret = b53_mirror_init(ds);
+ if (ret)
+ return ret;
+
/* Enable all valid ports and disable those unused */
for (port = 0; port < priv->hw_params.num_ports; port++) {
/* IMP port receives special treatment */
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming
2026-11-16 21:09 ` [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
@ 2026-11-19 9:10 ` netdev-bot+sashiko
2026-11-19 18:17 ` Florian Fainelli
0 siblings, 1 reply; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 9:10 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, jonas.gorski, andrew, olteanv, davem, edumazet, kuba,
pabeni, vivien.didelot, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1 (1)
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] This patch fixes a regression that an earlier patch in the
same series introduced.
- [Low] The series is split badly around b53_mirror_init().
Pre-existing issues:
- [Low] At this commit, on BCM5325/BCM5365, the mirror source masks and
capture-port field use the newer-chip encoding.
--
net: dsa: b53: harden mirror register programming
This commit clears and rebuilds the mirror registers during b53 and
bcm_sf2 setup. It also checks every mirror register access in
b53_mirror_add() and b53_mirror_del(), and only increments the source
reference count once programming has succeeded. Whether a destination is
occupied is now decided from the source masks instead of MIRROR_EN.
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 98696bce368fe..deb331b3629a7 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
> @@ -1360,6 +1360,10 @@ static int b53_setup(struct dsa_switch *ds)
> return ret;
> }
>
> + ret = b53_mirror_init(ds);
> + if (ret)
> + return ret;
> +
[Severity: Low]
The commit message says this patch will "Clear capture control and both
source-control registers during b53 and bcm_sf2 setup, then rebuild the
source masks and capture destination from the mirror reference counts".
The diff, however, only adds the calls in b53_setup() and
bcm_sf2_sw_setup().
The previous patch, "net: dsa: b53: reference count shared mirror source
bits", added the body of b53_mirror_init(), its EXPORT_SYMBOL and the
prototype in b53_priv.h. That patch's message only talks about reference
counting, and the function has no callers there.
Could b53_mirror_init() move into this patch, or could the earlier commit
message describe it?
As it stands, cherry-picking this commit through its Fixes: tag without
the previous one would fail to build because b53_mirror_init() is
undefined. The "must be applied after them" note doesn't say that the
dependency is a missing function body.
[ ... ]
> @@ -2654,14 +2658,25 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
> {
> struct b53_device *dev = ds->priv;
> unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
> - u16 reg, loc, cap_ctl;
> + u16 reg, other_reg, loc, other_loc, cap_ctl;
> int ret;
>
> + loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
> + other_loc = ingress ? B53_EG_MIR_CTL : B53_IG_MIR_CTL;
> +
> + ret = b53_read16(dev, B53_MGMT_PAGE, loc, ®);
> + if (ret)
> + return ret;
> +
> + ret = b53_read16(dev, B53_MGMT_PAGE, other_loc, &other_reg);
> + if (ret)
> + return ret;
> +
> ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &cap_ctl);
> if (ret)
> return ret;
>
> - if ((cap_ctl & MIRROR_EN) &&
> + if (((reg | other_reg) & MIRROR_MASK) &&
> (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
[Severity: Medium]
This replaces the (cap_ctl & MIRROR_EN) check that "net: dsa: b53: reject
conflicting mirror destinations" added earlier in this series. Is that
earlier patch a regression on its own?
At that point in the series, nothing in setup clears the mirror
registers. The baseline add path always overwrote B53_MIR_CAP_CTL.
b53_switch_reset() only soft-resets some chips:
if (is539x(dev)) {
b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
}
...
if (dev->chip_id == BCM58XX_DEVICE_ID ||
dev->chip_id == BCM583XX_DEVICE_ID) {
Take one of the other chips with no reset GPIO, where a bootloader or a
kexec'd kernel left MIRROR_EN set with a different capture port. The
first valid tc matchall mirror rule then fails with -EOPNOTSUPP.
If stale source bits were also left set, b53_mirror_del() never clears
MIRROR_EN. Another destination then can't be selected until a power
cycle.
The earlier patch carries Fixes: ed3af5fd08eb and a Reviewed-by, so
stable tooling can pick it up without this one. The "must be applied
after them" note only guards the other direction.
"net: dsa: b53: reference count shared mirror source bits" has a similar
problem. It increments mirror_count after unchecked writes, so a failed
first programming attempt is recorded as success. Later adds for the same
port and direction then return early instead of reprogramming. This
patch fixes that ordering too.
Would it be better to squash the b53_mirror_init() wiring and the
source-mask occupancy check into "reject conflicting mirror
destinations", and the mirror_count reordering into "reference count
shared mirror source bits"? Reordering the series so that no single
commit regresses would also work.
> NL_SET_ERR_MSG_MOD(extack,
> "Only one mirroring destination is supported");
> @@ -2673,19 +2688,17 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
> return 0;
> }
>
> - if (ingress)
> - loc = B53_IG_MIR_CTL;
> - else
> - loc = B53_EG_MIR_CTL;
> -
> - b53_read16(dev, B53_MGMT_PAGE, loc, ®);
> - reg |= BIT(port);
> - b53_write16(dev, B53_MGMT_PAGE, loc, reg);
> -
> + /* Select the destination before enabling the new source. */
> cap_ctl &= ~CAP_PORT_MASK;
> cap_ctl |= mirror->to_local_port;
> cap_ctl |= MIRROR_EN;
> - b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
> + ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
> + if (ret)
> + return ret;
> +
> + ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port));
> + if (ret)
> + return ret;
>
> (*mirror_count)++;
[Severity: Low]
This is a pre-existing issue, but is the source and capture-port encoding
right here for BCM5325/BCM5365?
The source bit is written as BIT(port), so the CPU port uses bit 5 rather
than hardware bit 8. The destination is compared and written as a raw
port number under CAP_PORT_MASK, but these chips expect a port bitmap.
b53_mirror_init() uses the same encoding (cap_ctl = MIRROR_EN |
dev->mirror_port), and so does b53_mirror_del() (reg &= ~BIT(port)). The
hardware can then mirror the wrong source or destination while
mirror_count and mirror_port report the rule as installed.
The encoding goes back to ed3af5fd08eb. A later patch in this series,
"net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365", fixes
it. That patch adds b53_mirror_port_mask(), b53_mirror_capture_port(),
b53_mirror_capture_port_mask() and CAP_PORT_MASK_25, and uses them in the
init, add and del paths.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116210943.1352656-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming
2026-11-19 9:10 ` netdev-bot+sashiko
@ 2026-11-19 18:17 ` Florian Fainelli
0 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-19 18:17 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: netdev, jonas.gorski, andrew, olteanv, davem, edumazet, kuba,
pabeni, vivien.didelot, linux-kernel
On 11/19/26 01:10, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1 (1)
>
> 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] This patch fixes a regression that an earlier patch in the
> same series introduced.
> - [Low] The series is split badly around b53_mirror_init().
>
> Pre-existing issues:
> - [Low] At this commit, on BCM5325/BCM5365, the mirror source masks and
> capture-port field use the newer-chip encoding.
>
> --
>
> net: dsa: b53: harden mirror register programming
>
> This commit clears and rebuilds the mirror registers during b53 and
> bcm_sf2 setup. It also checks every mirror register access in
> b53_mirror_add() and b53_mirror_del(), and only increments the source
> reference count once programming has succeeded. Whether a destination is
> occupied is now decided from the source masks instead of MIRROR_EN.
>
>> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
>> index 98696bce368fe..deb331b3629a7 100644
>> --- a/drivers/net/dsa/b53/b53_common.c
>> +++ b/drivers/net/dsa/b53/b53_common.c
>> @@ -1360,6 +1360,10 @@ static int b53_setup(struct dsa_switch *ds)
>> return ret;
>> }
>>
>> + ret = b53_mirror_init(ds);
>> + if (ret)
>> + return ret;
>> +
>
> [Severity: Low]
> The commit message says this patch will "Clear capture control and both
> source-control registers during b53 and bcm_sf2 setup, then rebuild the
> source masks and capture destination from the mirror reference counts".
> The diff, however, only adds the calls in b53_setup() and
> bcm_sf2_sw_setup().
>
> The previous patch, "net: dsa: b53: reference count shared mirror source
> bits", added the body of b53_mirror_init(), its EXPORT_SYMBOL and the
> prototype in b53_priv.h. That patch's message only talks about reference
> counting, and the function has no callers there.
>
> Could b53_mirror_init() move into this patch, or could the earlier commit
> message describe it?
>
> As it stands, cherry-picking this commit through its Fixes: tag without
> the previous one would fail to build because b53_mirror_init() is
> undefined. The "must be applied after them" note doesn't say that the
> dependency is a missing function body.
>
> [ ... ]
>
>> @@ -2654,14 +2658,25 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
>> {
>> struct b53_device *dev = ds->priv;
>> unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
>> - u16 reg, loc, cap_ctl;
>> + u16 reg, other_reg, loc, other_loc, cap_ctl;
>> int ret;
>>
>> + loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
>> + other_loc = ingress ? B53_EG_MIR_CTL : B53_IG_MIR_CTL;
>> +
>> + ret = b53_read16(dev, B53_MGMT_PAGE, loc, ®);
>> + if (ret)
>> + return ret;
>> +
>> + ret = b53_read16(dev, B53_MGMT_PAGE, other_loc, &other_reg);
>> + if (ret)
>> + return ret;
>> +
>> ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &cap_ctl);
>> if (ret)
>> return ret;
>>
>> - if ((cap_ctl & MIRROR_EN) &&
>> + if (((reg | other_reg) & MIRROR_MASK) &&
>> (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
>
> [Severity: Medium]
> This replaces the (cap_ctl & MIRROR_EN) check that "net: dsa: b53: reject
> conflicting mirror destinations" added earlier in this series. Is that
> earlier patch a regression on its own?
>
> At that point in the series, nothing in setup clears the mirror
> registers. The baseline add path always overwrote B53_MIR_CAP_CTL.
> b53_switch_reset() only soft-resets some chips:
>
> if (is539x(dev)) {
> b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
> b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
> }
> ...
> if (dev->chip_id == BCM58XX_DEVICE_ID ||
> dev->chip_id == BCM583XX_DEVICE_ID) {
>
> Take one of the other chips with no reset GPIO, where a bootloader or a
> kexec'd kernel left MIRROR_EN set with a different capture port. The
> first valid tc matchall mirror rule then fails with -EOPNOTSUPP.
>
> If stale source bits were also left set, b53_mirror_del() never clears
> MIRROR_EN. Another destination then can't be selected until a power
> cycle.
>
> The earlier patch carries Fixes: ed3af5fd08eb and a Reviewed-by, so
> stable tooling can pick it up without this one. The "must be applied
> after them" note only guards the other direction.
>
> "net: dsa: b53: reference count shared mirror source bits" has a similar
> problem. It increments mirror_count after unchecked writes, so a failed
> first programming attempt is recorded as success. Later adds for the same
> port and direction then return early instead of reprogramming. This
> patch fixes that ordering too.
>
> Would it be better to squash the b53_mirror_init() wiring and the
> source-mask occupancy check into "reject conflicting mirror
> destinations", and the mirror_count reordering into "reference count
> shared mirror source bits"? Reordering the series so that no single
> commit regresses would also work.
>
>> NL_SET_ERR_MSG_MOD(extack,
>> "Only one mirroring destination is supported");
>> @@ -2673,19 +2688,17 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
>> return 0;
>> }
>>
>> - if (ingress)
>> - loc = B53_IG_MIR_CTL;
>> - else
>> - loc = B53_EG_MIR_CTL;
>> -
>> - b53_read16(dev, B53_MGMT_PAGE, loc, ®);
>> - reg |= BIT(port);
>> - b53_write16(dev, B53_MGMT_PAGE, loc, reg);
>> -
>> + /* Select the destination before enabling the new source. */
>> cap_ctl &= ~CAP_PORT_MASK;
>> cap_ctl |= mirror->to_local_port;
>> cap_ctl |= MIRROR_EN;
>> - b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
>> + ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
>> + if (ret)
>> + return ret;
>> +
>> + ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port));
>> + if (ret)
>> + return ret;
>>
>> (*mirror_count)++;
>
> [Severity: Low]
> This is a pre-existing issue, but is the source and capture-port encoding
> right here for BCM5325/BCM5365?
>
> The source bit is written as BIT(port), so the CPU port uses bit 5 rather
> than hardware bit 8. The destination is compared and written as a raw
> port number under CAP_PORT_MASK, but these chips expect a port bitmap.
>
> b53_mirror_init() uses the same encoding (cap_ctl = MIRROR_EN |
> dev->mirror_port), and so does b53_mirror_del() (reg &= ~BIT(port)). The
> hardware can then mirror the wrong source or destination while
> mirror_count and mirror_port report the rule as installed.
>
> The encoding goes back to ed3af5fd08eb. A later patch in this series,
> "net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365", fixes
> it. That patch adds b53_mirror_port_mask(), b53_mirror_capture_port(),
> b53_mirror_capture_port_mask() and CAP_PORT_MASK_25, and uses them in the
> init, add and del paths.
>
> [ ... ]
>
Agreed. The conflicting-destination check can reject the first rule
because of stale mirror state, and the reference-counting change can
retain a reference after failed register writes.
I will combine the destination check, mirror initialization, reference
counting and register error handling so these intermediate states are
not introduced. This will also keep b53_mirror_init() and its callers
together.
The BCM5325/BCM5365 encoding issue is addressed by patch #8; I will
move that fix before the combined change.
pw-bot: cr
--
Florian
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net v6 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (6 preceding siblings ...)
2026-11-16 21:09 ` [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
@ 2026-11-16 21:09 ` Florian Fainelli
7 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:09 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vivien Didelot, open list
BCM5325 and BCM5365 use an 11-bit bitmap for the mirror capture port,
whereas newer switches use a four-bit port ID. Programming the port
number directly can select no destination or the wrong destination, and
can select multiple destinations. For example, port 2 requires BIT(2),
but writing 2 selects port 1 instead.
Use the bitmap encoding on BCM5325 and BCM5365, including translating
logical CPU port 5 to hardware bit 8. Apply the corresponding field mask
when checking for a conflicting destination, replacing the destination,
and clearing it after the last mirror source is removed. Keep the port ID
encoding for newer switches.
The ingress and egress mirror source masks use the same layout on these
switches, with the CPU port at bit 8 and bits 5-7 reserved, so apply the
same translation when setting and clearing a source port bit.
Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/dsa/b53/b53_common.c | 46 +++++++++++++++++++++++++-------
drivers/net/dsa/b53/b53_regs.h | 1 +
2 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index deb331b3629a..ee2d27732c0c 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2608,6 +2608,31 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
}
EXPORT_SYMBOL(b53_get_tag_protocol);
+static u16 b53_mirror_capture_port_mask(struct b53_device *dev)
+{
+ if (is5325(dev) || is5365(dev))
+ return CAP_PORT_MASK_25;
+
+ return CAP_PORT_MASK;
+}
+
+static u16 b53_mirror_port_mask(struct b53_device *dev, int port)
+{
+ /* These switches use a bitmap with the CPU port at bit 8. */
+ if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
+ port = B53_CPU_PORT;
+
+ return BIT(port);
+}
+
+static u16 b53_mirror_capture_port(struct b53_device *dev, int port)
+{
+ if (is5325(dev) || is5365(dev))
+ return b53_mirror_port_mask(dev, port);
+
+ return port;
+}
+
int b53_mirror_init(struct dsa_switch *ds)
{
struct b53_device *dev = ds->priv;
@@ -2631,15 +2656,15 @@ int b53_mirror_init(struct dsa_switch *ds)
/* DSA retains matchall filters across suspend and resume. */
for (port = 0; port < dev->num_ports; port++) {
if (dev->ports[port].mirror_count[true])
- ingress |= BIT(port);
+ ingress |= b53_mirror_port_mask(dev, port);
if (dev->ports[port].mirror_count[false])
- egress |= BIT(port);
+ egress |= b53_mirror_port_mask(dev, port);
}
if (!(ingress | egress))
return 0;
- cap_ctl = MIRROR_EN | dev->mirror_port;
+ cap_ctl = MIRROR_EN | b53_mirror_capture_port(dev, dev->mirror_port);
ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
if (ret)
return ret;
@@ -2659,6 +2684,8 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
struct b53_device *dev = ds->priv;
unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
u16 reg, other_reg, loc, other_loc, cap_ctl;
+ u16 cap_mask = b53_mirror_capture_port_mask(dev);
+ u16 cap_port = b53_mirror_capture_port(dev, mirror->to_local_port);
int ret;
loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
@@ -2677,7 +2704,7 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
return ret;
if (((reg | other_reg) & MIRROR_MASK) &&
- (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
+ (cap_ctl & cap_mask) != cap_port) {
NL_SET_ERR_MSG_MOD(extack,
"Only one mirroring destination is supported");
return -EOPNOTSUPP;
@@ -2689,14 +2716,15 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
}
/* Select the destination before enabling the new source. */
- cap_ctl &= ~CAP_PORT_MASK;
- cap_ctl |= mirror->to_local_port;
+ cap_ctl &= ~cap_mask;
+ cap_ctl |= cap_port;
cap_ctl |= MIRROR_EN;
ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
if (ret)
return ret;
- ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port));
+ ret = b53_write16(dev, B53_MGMT_PAGE, loc,
+ reg | b53_mirror_port_mask(dev, port));
if (ret)
return ret;
@@ -2730,7 +2758,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
if (ret)
goto err;
- reg &= ~BIT(port);
+ reg &= ~b53_mirror_port_mask(dev, port);
ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg);
if (ret)
goto err;
@@ -2749,7 +2777,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
if (ret)
goto err;
- reg &= ~(MIRROR_EN | CAP_PORT_MASK);
+ reg &= ~(MIRROR_EN | b53_mirror_capture_port_mask(dev));
ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
if (ret)
goto err;
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index cfdb5ed38326..ee049927a63a 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -239,6 +239,7 @@
/* Mirror capture control register (16 bit) */
#define B53_MIR_CAP_CTL 0x10
#define CAP_PORT_MASK 0xf
+#define CAP_PORT_MASK_25 0x7ff
#define BLK_NOT_MIR BIT(14)
#define MIRROR_EN BIT(15)
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread