* [PATCH net v5 1/8] net: dsa: b53: initialize the jumbo frame size register offset
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
@ 2026-11-12 18:01 ` Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:01 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 a2a5754c413c..ca2ba8c157b7 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 related [flat|nested] 14+ messages in thread* [PATCH net v5 2/8] net: dsa: b53: fix the SRAB grant timeout check
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
@ 2026-11-12 18:01 ` Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
` (5 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:01 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 83a03fca142a..f4689078ccd5 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 related [flat|nested] 14+ messages in thread* [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
@ 2026-11-12 18:01 ` Florian Fainelli
2026-11-16 19:02 ` netdev-bot+sashiko
2026-11-12 18:01 ` [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:01 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 making
a new entry from stale bin contents.
Deleting an entry which is not present now returns -ENOENT, including
when the lookup ran out of space (-ENOSPC), where it previously returned
0 in that case.
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 ca2ba8c157b7..cc42b2a4870a 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 related [flat|nested] 14+ messages in thread* Re: [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry
2026-11-12 18:01 ` [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
@ 2026-11-16 19:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:02 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 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] In b53_arl_op() (drivers/net/dsa/b53/b53_common.c), the code
does not do what the commit message says about return values.
--
net: dsa: b53: clear stale state when creating an ARL entry
This patch clears the b53_arl_entry in b53_arl_op() before a new ARL
entry is created, so a multicast add no longer ORs the port into the
forwarding bitmap of an unrelated bin. It also returns early when
deleting an entry that is not present, so stale bin contents are no
longer written back.
> Deleting an entry which is not present now returns -ENOENT, including
> when the lookup ran out of space (-ENOSPC), where it previously returned
> 0 in that case.
[Severity: Medium]
Is this paragraph accurate? The code below seems to keep returning 0 for
a delete of an absent entry in both cases.
When the lookup misses, b53_arl_read() returns one of two values:
drivers/net/dsa/b53/b53_common.c:b53_arl_read() {
...
return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
}
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 1f5776dfaae2e..dac6013f8fe29 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;
The -ENOSPC case is not changed by this patch. With is_valid == false it
still returns 0, not -ENOENT.
> case -ENOENT:
> + if (!is_valid)
> + return 0;
> +
The new early return in the -ENOENT case also gives 0 for a delete.
Before this patch, the -ENOENT delete path fell through to
b53_arl_write_entry() and returned b53_arl_rw_op(dev, 0), which is
normally 0. So b53_fdb_del() and b53_mdb_del() get 0 for an absent entry
both before and after this change. The real difference is that the stale
bin is no longer written back.
Keeping 0 looks like the right behavior. b53_mdb_del() logs an error on
any non-zero return:
drivers/net/dsa/b53/b53_common.c:b53_mdb_del() {
...
ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
mutex_unlock(&priv->arl_mutex);
if (ret)
dev_err(ds->dev, "failed to delete MDB entry\n");
...
}
Returning -ENOENT there would produce errors during normal teardown.
None of the later patches in the series touch b53_arl_op(), so the code
is the same at the end of the series.
Could this paragraph be dropped, or reworded to describe the change the
code actually makes? Or was a code change from an earlier version of the
patch left out?
> /* 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;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (2 preceding siblings ...)
2026-11-12 18:01 ` [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
@ 2026-11-12 18:01 ` Florian Fainelli
2026-11-16 19:02 ` netdev-bot+sashiko
2026-11-12 18:01 ` [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
` (3 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:01 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.
Clear the capture-port field when the final source is removed so a later
rule can select a new destination. This also fixes b53_mirror_del(),
which tried to clear the destination with ~mirror->to_local_port. That
only cleared the bits set in the port number, so a stale capture port
could remain after the last source was removed.
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 cc42b2a4870a..715a0969eacb 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 related [flat|nested] 14+ messages in thread* Re: [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations
2026-11-12 18:01 ` [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
@ 2026-11-16 19:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:02 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 more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message describes the b53_mirror_del() capture-port
change as a separate bug fix ("This also fixes b53_mirror_del() ... a…
--
net: dsa: b53: reject conflicting mirror destinations
This patch makes b53_mirror_add() read B53_MIR_CAP_CTL before it changes
any source mask. While mirroring is enabled, it rejects a rule for a
different capture port and returns an extack message. It also changes
b53_mirror_del() so that the whole CAP_PORT_MASK field is cleared along
with MIRROR_EN when the last source is removed.
> Clear the capture-port field when the final source is removed so a later
> rule can select a new destination. This also fixes b53_mirror_del(),
> which tried to clear the destination with ~mirror->to_local_port. That
> only cleared the bits set in the port number, so a stale capture port
> could remain after the last source was removed.
[Severity: Low]
Is this paragraph accurate? A later rule doesn't seem to need
b53_mirror_del() to clear CAP_PORT_MASK in order to select a new
destination.
In drivers/net/dsa/b53/b53_common.c, the new conflict check in
b53_mirror_add() only applies while MIRROR_EN is set:
if ((cap_ctl & MIRROR_EN) &&
(cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
The add path also always rewrites the field:
cap_ctl &= ~CAP_PORT_MASK;
cap_ctl |= mirror->to_local_port;
cap_ctl |= MIRROR_EN;
b53_mirror_del() clears MIRROR_EN in the same statement. Once that bit
is clear, leftover bits in CAP_PORT_MASK affect neither the hardware nor
the check.
Before this patch, the old reg &= ~mirror->to_local_port could leave a
stale value in only one case: after one rule had overwritten another
rule's destination. This patch now rejects that case. Even then,
MIRROR_EN was cleared at the same time, and the next add overwrote the
field.
A later patch in this series, "net: dsa: b53: harden mirror register
programming", describes the same change this way: "Clearing the inactive
capture-port field is cleanup."
Could the commit message call the b53_mirror_del() change a cleanup
instead of a separate fix?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (3 preceding siblings ...)
2026-11-12 18:01 ` [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
@ 2026-11-12 18:01 ` Florian Fainelli
2026-11-16 19:02 ` netdev-bot+sashiko
2026-11-12 18:02 ` [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
` (2 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:01 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")
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 715a0969eacb..6b4a94a97d66 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 related [flat|nested] 14+ messages in thread* Re: [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit
2026-11-12 18:01 ` [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
@ 2026-11-16 19:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:02 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 more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The Fixes: tag covers only one of the two bugs this patch fixes.
--
net: dsa: b53: use the correct override register 2 Gbps bit
This patch picks the 2 Gbps speed bit per register in
b53_force_port_config(). The IMP override register uses
PORT_OVERRIDE_SPEED_2000M and the per-port GMII override registers use
GMII_PO_SPEED_2000M. As a result, lower speeds clear the correct bit and
2 Gbps sets the correct bit on GMII ports.
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 64e04c5731a69..d8dafa9e0c44d 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
[ ... ]
> @@ -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;
[Severity: Low]
This isn't a bug, but should the Fixes: tag also cover the 2 Gbps set
path? The commit message has:
Fixes: b6a8a5477fe9 ("net: dsa: b53: fix resetting speed and pause on forced link")
b6a8a5477fe9 added the clear of PORT_OVERRIDE_SPEED_2000M at lower speeds.
On the GMII register that clear removes GMII_PO_EN (BIT(6)) and leaves a
stale GMII_PO_SPEED_2000M behind. That part of the patch matches the tag.
The change in case 2000 fixes an older problem. On a GMII port, ORing in
PORT_OVERRIDE_SPEED_2000M has always set GMII_PO_EN and never
GMII_PO_SPEED_2000M (BIT(7)), so 2 Gbps was never selected on that
register.
The case 2000 line goes back to 967dd82ffc52. Later, 63f8428b4077 switched
the code from cpu_port to imp_port, which moved BCM5301x CPU port 5 back
onto the GMII register path, and that path still set BIT(6).
In the current tree, the only caller that passes speed = 2000 is
b53_phylink_mac_link_up():
if ((is5301x(dev) || dev->chip_id == BCM58XX_DEVICE_ID) &&
dsa_is_cpu_port(ds, port)) {
tx_pause = true;
rx_pause = true;
speed = 2000;
}
That code came from 41af38324341 ("net: dsa: b53: restore the NSP IMP port
2 Gbps mode"). It also covers BCM5301x CPU ports 5 and 7, which go through
B53_GMII_PORT_OVERRIDE_CTRL(port).
The commit message says the patch makes it so "2 Gbps sets it". Would an
extra Fixes: tag for 41af38324341 describe what the patch fixes more
accurately?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (4 preceding siblings ...)
2026-11-12 18:01 ` [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
@ 2026-11-12 18:02 ` Florian Fainelli
2026-11-16 19:02 ` netdev-bot+sashiko
2026-11-12 18:02 ` [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
2026-11-12 18:02 ` [PATCH net v5 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Florian Fainelli
7 siblings, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:02 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 +++
drivers/net/dsa/bcm_sf2.c | 6 ++--
3 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 6b4a94a97d66..7f5bae290eaa 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);
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 1c846f6d7802..6570279cc040 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -996,9 +996,11 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
if (priv->hw_params.num_gphy == 1)
bcm_sf2_gphy_enable_set(ds, true);
- ds->ops->setup(ds);
+ ret = ds->ops->setup(ds);
+ if (ret && !priv->wol_ports_mask)
+ clk_disable_unprepare(priv->clk);
- return 0;
+ return ret;
}
static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
--
2.53.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits
2026-11-12 18:02 ` [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
@ 2026-11-16 19:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:02 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: 1 · Medium: 1 · Low: 0
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).
- [High] This patch changes bcm_sf2_sw_resume()
(drivers/net/dsa/bcm_sf2.c).
- [Medium] The new error path in bcm_sf2_sw_resume() gates the switch
clock (`if (ret && !priv->wol_ports_mask)…
--
net: dsa: b53: reference count shared mirror source bits
This commit adds reference counts for each port's ingress and egress
mirror source bits in b53. A bit is only cleared when its last tc
matchall filter is removed. It also adds a b53_mirror_init() helper and
changes bcm_sf2_sw_resume() to return the result of ds->ops->setup().
[ ... ]
> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 1747a1f20c78e..98a4a62ca73a2 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -996,9 +996,11 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
> if (priv->hw_params.num_gphy == 1)
> bcm_sf2_gphy_enable_set(ds, true);
>
> - ds->ops->setup(ds);
> + ret = ds->ops->setup(ds);
> + if (ret && !priv->wol_ports_mask)
> + clk_disable_unprepare(priv->clk);
>
> - return 0;
> + return ret;
> }
[Severity: High]
Does this make every other system resume fail, starting with the first?
bcm_sf2_sw_setup() is not safe to run twice. It ends with:
return b53_setup_devlink_resources(ds);
Probe already registers the "VLAN" devlink resource through
dsa_switch_setup() -> ops->setup. Only bcm_sf2_sw_teardown() removes it.
On resume the call chain is:
bcm_sf2_sw_resume()
bcm_sf2_sw_setup()
b53_setup_devlink_resources()
dsa_devlink_resource_register()
__devl_resource_register()
if (resource)
return -EEXIST;
b53_setup_devlink_resources() then jumps to out:, calls
dsa_devlink_resources_unregister(ds) and returns -EEXIST. Before this
patch that error was ignored. Now bcm_sf2_sw_resume() returns it and
also gates the switch clock.
dsa_switch_resume() then returns early:
if (ds->ops->resume)
ret = ds->ops->resume(ds);
if (ret)
return ret;
As a result, dsa_user_resume() never runs for any user port. Without
netif_device_attach() or phylink_start(), all user ports stay down
after an ordinary suspend/resume.
The failure path unregistered the resources, so the next resume
succeeds and the one after that fails again.
The clock is already off after a failed resume. The next
bcm_sf2_sw_suspend() (when wol_ports_mask is 0) and bcm_sf2_sw_remove()
will each call clk_disable_unprepare() again. Can that underflow the
enable/prepare counts?
The commit message only covers mirror refcounting and does not mention
this resume change. With the Fixes: tag, a stable backport would bring
this change along. Could this change be split into its own patch, after
making the setup path safe to run again on resume?
[Severity: Medium]
On this new error path, gating the clock is the only rollback. By this
point the switch is out of reset, the crossbar is configured and the
GPHY is powered on through bcm_sf2_gphy_enable_set(ds, true).
bcm_sf2_sw_setup() may also have enabled ports already. Nothing marks
the device as clock-gated, and the switch stays bound.
On the next system suspend, dsa_switch_suspend() still calls
bcm_sf2_sw_suspend():
bcm_sf2_intr_disable(priv);
...
bcm_sf2_port_disable(ds, port);
}
if (!priv->wol_ports_mask)
clk_disable_unprepare(priv->clk);
Won't this access switch registers while the clock is gated? It then
calls clk_disable_unprepare() a second time, which would trigger the
clk core already disabled/unprepared warnings.
Callbacks that run under RTNL, such as b53_mirror_del() when a tc
filter is deleted, can still run and would also access registers with
the clock off.
Before this patch, a setup failure on resume left the clock enabled.
The rst and cfp failure paths already roll back only partially in the
same way, but this path runs after the GPHY has been powered up. Given
the devlink -EEXIST issue above, it would be hit on every other resume.
It would also be hit on any register I/O failure inside setup, for
example in b53_enable_mcast_snooping(), or later in the series in
b53_mirror_init().
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (5 preceding siblings ...)
2026-11-12 18:02 ` [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
@ 2026-11-12 18:02 ` Florian Fainelli
2026-11-16 19:02 ` netdev-bot+sashiko
2026-11-12 18:02 ` [PATCH net v5 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Florian Fainelli
7 siblings, 1 reply; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:02 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, propagating initialization failures. 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.
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 7f5bae290eaa..a2d46cceca47 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 6570279cc040..ccc836c0718c 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1063,6 +1063,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 related [flat|nested] 14+ messages in thread* Re: [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming
2026-11-12 18:02 ` [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
@ 2026-11-16 19:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 19:02 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 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] Speculative; needs datasheet confirmation.
- [Low] This patch fixes a regression that an earlier patch in the same
series introduced, but its message says nothing about that or about…
- [Low] The commit message says the patch will "Clear capture control and
both source-control registers during b53 and bcm_sf2 setup".
--
net: dsa: b53: harden mirror register programming
This commit calls b53_mirror_init() from b53_setup() and
bcm_sf2_sw_setup() to reset the mirror registers at setup. It checks
every mirror register read and write in b53_mirror_add() and
b53_mirror_del(), and only increments the source reference count after
programming succeeds. It also uses the ingress/egress source masks,
instead of MIRROR_EN, to decide whether the capture destination is in use.
> 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.
[ ... ]
> Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")
[Severity: Low]
Is ed3af5fd08eb the right commit for the first problem described here?
Before this series, b53_mirror_add() overwrote B53_MIR_CAP_CTL and never
rejected a rule. The check that can reject a first rule because of stale
firmware state was added earlier in this series, by "net: dsa: b53: reject
conflicting mirror destinations":
if ((cap_ctl & MIRROR_EN) &&
(cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
...
return -EOPNOTSUPP;
}
That patch does not clear the capture state at setup.
The same is true of the reference count increment that runs after
unchecked register accesses. It comes from "net: dsa: b53: reference count
shared mirror source bits". That patch also defined and exported
b53_mirror_init() but never called it, so this patch cannot build without
it.
All three patches carry the same Fixes: ed3af5fd08eb tag, and none of them
says what order they need to go in.
Suppose "reject conflicting mirror destinations" is picked up for stable
on its own. On a switch where the bootloader or a previous kernel left
MIRROR_EN set with a different capture port, would the first tc matchall
mirred rule then fail with -EOPNOTSUPP?
Could these fixes be folded into the patches that introduced the problems?
If not, could the commit message name those patches and the required
ordering?
> 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: Medium]
Are the mirror register offsets the same on every chip family that goes
through b53_setup()?
With this call, b53_mirror_init() writes zero to Management page offsets
0x10 (B53_MIR_CAP_CTL), 0x12 (B53_IG_MIR_CTL) and 0x1C (B53_EG_MIR_CTL) at
every setup, on every chip_id:
ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, 0);
...
ret = b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, 0);
...
ret = b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, 0);
Before this patch, these offsets were only written when a user installed a
matchall mirror rule.
The driver already treats the BCM63xx Management page layout as different
in at least one place:
#define B53_AGING_TIME_CONTROL 0x06
#define B53_AGING_TIME_CONTROL_63XX 0x08
The mirror registers have no 63xx variant, though. Nothing in the tree
confirms these offsets for BCM63xx either way, so this may be fine.
If BCM63xx, or another supported family, has a different register at 0x10,
0x12 or 0x1C, would that register now be silently zeroed on every boot?
A write to the wrong register would still return success here.
[ ... ]
> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 98a4a62ca73a2..85ea32fb501db 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -1063,6 +1063,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;
> +
[Severity: Low]
The commit message says:
Clear capture control and both source-control registers during b53 and
bcm_sf2 setup, propagating initialization failures.
b53_mirror_init() does more than clear these registers. After writing zero
to them, it rebuilds the source masks from dev->ports[].mirror_count[] and
writes the capture port back:
cap_ctl = MIRROR_EN | dev->mirror_port;
On bcm_sf2 this also runs on every resume:
bcm_sf2_sw_resume()
ds->ops->setup()
bcm_sf2_sw_setup()
b53_mirror_init()
So with this patch, active tc mirror rules are restored from software state
after each resume. A failed mirror register access also makes resume fail.
No patch in the series describes this restore behaviour. Could the commit
message mention it, so that readers don't expect resume to wipe active
mirror rules?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v5 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
` (6 preceding siblings ...)
2026-11-12 18:02 ` [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
@ 2026-11-12 18:02 ` Florian Fainelli
7 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-12 18:02 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 a2d46cceca47..5bdf9cf147b3 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 related [flat|nested] 14+ messages in thread