net: dsa: b53: Preliminary fixes
Florian Fainelli
maintainerv5 cover net: dsa: b53: Preliminary fixes
This patch series contains fixes to issues reported by Sashiko on the b53 PCS bug fixes being submitted, and then some more that came from code review and testing.
Except for issue #2, all of the other issues did trigger in testing and needed to be corrected.
Changes in v5:
- resolved build warning in patch #7 by moving b53_mirror_init()'s declaration into patch #6
Changes in v4:
- Return success when deleting an ARL entry that does not exist per
Sashiko's review
- Restrict the 2 Gbps override bit to BCM5301x and BCM58xx
- Restore mirror configuration on resume, moving mirror initialization into the reference-counting patch
- Propagate SF2 setup errors on resume and disable the clock on failure when WoL is inactive
- Add a patch fixing BCM5325/BCM5365 mirror port encoding, including CPU port bitmap translation
Changes in v3:
- patch 2: added Daniel's R-b tag
- patch 3: mention in the commit message that deleting an absent entry now returns -ENOENT, including when the lookup runs out of space
- patch 4: document that the patch also fixes the clear of the capture port field in b53_mirror_del()
- patch 6: reference count the mirror source bits per port and direction, ignoring deletions without a matching reference
- patch 7: new, harden mirror register programming:
- reset the mirror capture and source control registers at setup for b53 and bcm_sf2, since not all switches are reset
- check and propagate all mirror register read/write errors, only taking a source reference once hardware programming succeeded
- use the source masks rather than MIRROR_EN to decide whether the destination is occupied, and write the destination before the source
- log failures in b53_mirror_del() since it cannot return an error
- patch 8: new, fix the mirror capture port encoding on BCM5325 and BCM5365, which use an 11-bit bitmap (CPU port at bit 8) instead of a port ID, and translate the CPU port in the ingress/egress source masks as well (verified against the BCM5325E, BCM5325M and BCM5365P datasheets)
Changes in v2:
- collected Jonas' R-b tags
- corrected logic in patch #3 to propagate -ENOENT, memset after the debug print, translate -ENOSPC to -ENOENT when deleting
Florian Fainelli (8):
net: dsa: b53: initialize the jumbo frame size register offset
net: dsa: b53: fix the SRAB grant timeout check
net: dsa: b53: clear stale state when creating an ARL entry
net: dsa: b53: reject conflicting mirror destinations
net: dsa: b53: use the correct override register 2 Gbps bit
net: dsa: b53: reference count shared mirror source bits
net: dsa: b53: harden mirror register programming
net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365
drivers/net/dsa/b53/b53_common.c | 209 +++++++++++++++++++++++++------ drivers/net/dsa/b53/b53_priv.h | 4 + drivers/net/dsa/b53/b53_regs.h | 1 + drivers/net/dsa/b53/b53_srab.c | 2 +- drivers/net/dsa/bcm_sf2.c | 10 +- 5 files changed, 183 insertions(+), 43 deletions(-)
Signature · 1 line
2.53.0
Florian Fainelli
maintainerPATCH v5 1/8 net: dsa: b53: initialize the jumbo frame size register offset
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.
--- drivers/net/dsa/b53/b53_common.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/dsa/b53/b53_common.c +1 -0
@@ -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;
Signature · 1 line
2.53.0
Florian Fainelli
maintainerPATCH v5 2/8 net: dsa: b53: fix the SRAB grant timeout check
In reply to Florian Fainellib53_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.
--- drivers/net/dsa/b53/b53_srab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/b53/b53_srab.c +1 -1
@@ -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 ;
Signature · 1 line
2.53.0
Florian Fainelli
maintainerPATCH v5 3/8 net: dsa: b53: clear stale state when creating an ARL entry
In reply to Florian FainelliWhen 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.
--- drivers/net/dsa/b53/b53_common.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/dsa/b53/b53_common.c +4 -0
@@ -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",
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
Quoted 3 lines
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;
}drivers/net/dsa/b53/b53_common.c static int b53_arl_op(struct b53_device *dev, int op, int port, · line 2056
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +0
-0@@ -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.
drivers/net/dsa/b53/b53_common.c static int b53_arl_op(struct b53_device *dev, int op, int port, · line 2060
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +3
-0case -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?
Quoted 5 lines
drivers/net/dsa/b53/b53_common.c +1
-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 ;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry
Quoted 84 lines · On 11/16/26 11:02, [email protected] wrote:
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_entryinb53_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.Quoted 3 lines
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; }drivers/net/dsa/b53/b53_common.c static int b53_arl_op(struct b53_device *dev, int op, int port, · line 2056
Quoted 7 lines
drivers/net/dsa/b53/b53_common.c +0
-0@@ -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
-ENOSPCcase is not changed by this patch. Withis_valid== false it still returns 0, not-ENOENT.drivers/net/dsa/b53/b53_common.c static int b53_arl_op(struct b53_device *dev, int op, int port, · line 2060
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +3
-0case -ENOENT : +if (!is_valid) +return 0 ; +The new early return in the
-ENOENTcase also gives 0 for a delete.Before this patch, the
-ENOENTdelete path fell through tob53_arl_write_entry()and returnedb53_arl_rw_op(dev, 0), which is normally 0. Sob53_fdb_del()andb53_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
-ENOENTthere 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?
Quoted 8 lines
Quoted 5 lines
drivers/net/dsa/b53/b53_common.c +1
-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 ;[ ... ]
The paragraph was left over from an earlier version, the code is correct and I will send a v6.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH v5 4/8 net: dsa: b53: reject conflicting mirror destinations
In reply to Florian FainelliThe 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.
--- drivers/net/dsa/b53/b53_common.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/dsa/b53/b53_common.c +19 -10
@@ -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);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations
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…
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.
Quoted 5 lines
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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations
Quoted 52 lines · On 11/16/26 11:02, [email protected] wrote:
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 fixesb53_mirror_del()... a…--
net: dsa: b53: reject conflicting mirror destinations
This patch makes
b53_mirror_add()readB53_MIR_CAP_CTLbefore 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 changesb53_mirror_del()so that the wholeCAP_PORT_MASKfield is cleared along withMIRROR_ENwhen the last source is removed.Quoted 5 lines
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 needb53_mirror_del()to clearCAP_PORT_MASKin order to select a new destination.In
drivers/net/dsa/b53/b53_common.c, the new conflict check inb53_mirror_add()only applies whileMIRROR_ENis 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()clearsMIRROR_ENin the same statement. Once that bit is clear, leftover bits inCAP_PORT_MASKaffect 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_ENwas cleared at the same time, and the next add overwrote the field.
Quoted 7 lines
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's point is correct. b53_mirror_del() clears MIRROR_EN in the same write, and the add path always rewrites CAP_PORT_MASK. A stale capture port therefore has no effect on the hardware or on the conflict check. I have reworded the paragraph accordingly.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH v5 5/8 net: dsa: b53: use the correct override register 2 Gbps bit
In reply to Florian FainelliThe 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.
--- drivers/net/dsa/b53/b53_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/dsa/b53/b53_common.c +6 -3
@@ -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 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit
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…
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.
Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0
-0
[ ... ]
drivers/net/dsa/b53/b53_common.c static void b53_force_port_config(struct b53_device *dev, int port, · line 1460
Quoted 13 lines
drivers/net/dsa/b53/b53_common.c +3
-2@@ -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:
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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit
Quoted 68 lines · On 11/16/26 11:02, [email protected] wrote:
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 usesPORT_OVERRIDE_SPEED_2000Mand the per-port GMII override registers useGMII_PO_SPEED_2000M. As a result, lower speeds clear the correct bit and 2 Gbps sets the correct bit on GMII ports.Quoted 4 lines
drivers/net/dsa/b53/b53_common.c +0
-0[ ... ]
drivers/net/dsa/b53/b53_common.c static void b53_force_port_config(struct b53_device *dev, int port, · line 1460
Quoted 13 lines
drivers/net/dsa/b53/b53_common.c +3
-2@@ -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")
b6a8a5477fe9added the clear ofPORT_OVERRIDE_SPEED_2000Mat lower speeds. On the GMII register that clear removesGMII_PO_EN(BIT(6)) and leaves a staleGMII_PO_SPEED_2000Mbehind. 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_2000Mhas always setGMII_PO_ENand neverGMII_PO_SPEED_2000M(BIT(7)), so 2 Gbps was never selected on that register.The case 2000 line goes back to
967dd82ffc52. Later,63f8428b4077switched the code fromcpu_porttoimp_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; }
Quoted 8 lines
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 throughB53_GMII_PORT_OVERRIDE_CTRL(port).The commit message says the patch makes it so "2 Gbps sets it". Would an extra Fixes: tag for
41af38324341describe what the patch fixes more accurately?
Agreed. I added a Fixes: tag for 41af38324341 ("net: dsa: b53: restore the NSP IMP port 2 Gbps mode"), since that is the caller which passes speed = 2000 and reaches the GMII override registers on BCM5301x CPU ports.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH v5 6/8 net: dsa: b53: reference count shared mirror source bits
In reply to Florian FainelliMultiple 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.
--- 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(-)
drivers/net/dsa/b53/b53_common.c +61 -0
@@ -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
drivers/net/dsa/b53/b53_priv.h +4 -0
@@ -119,6 +119,8 @@ struct b53_pcs {#define B53_N_PCS 2struct 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);
drivers/net/dsa/bcm_sf2.c +4 -2
@@ -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,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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().
[ ... ]
Quoted 6 lines
drivers/net/dsa/bcm_sf2.c +0
-0@@ -996,9 +996,11 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)if (priv->hw_params.num_gphy ==1 )
drivers/net/dsa/bcm_sf2.c static int bcm_sf2_sw_resume(struct dsa_switch *ds) · line 1004
Quoted 10 lines
drivers/net/dsa/bcm_sf2.c +4
-2bcm_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().
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits
Quoted 119 lines · On 11/16/26 11:02, [email protected] wrote:
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 inbcm_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 changesbcm_sf2_sw_resume()to return the result ofds->ops->setup().[ ... ]
Quoted 6 lines
drivers/net/dsa/bcm_sf2.c +0
-0@@ -996,9 +996,11 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)if (priv->hw_params.num_gphy ==1 )drivers/net/dsa/bcm_sf2.c static int bcm_sf2_sw_resume(struct dsa_switch *ds) · line 1004
Quoted 10 lines
drivers/net/dsa/bcm_sf2.c +4
-2bcm_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. Onlybcm_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:, callsdsa_devlink_resources_unregister(ds)and returns-EEXIST. Before this patch that error was ignored. Nowbcm_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. Withoutnetif_device_attach()orphylink_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()(whenwol_ports_maskis 0) andbcm_sf2_sw_remove()will each callclk_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 throughbcm_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 callsbcm_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.
Quoted 9 lines
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
-EEXISTissue 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 inb53_mirror_init().
[High] You are right. bcm_sf2_sw_resume() calls ds->ops->setup(), which
ends in b53_setup_devlink_resources(). The VLAN resource is already registered from probe, so on resume it returns -EEXIST. That error is ignored today. Propagating it would make dsa_switch_resume() return
before dsa_user_resume(), leaving the user ports down. The resume change
does not belong in this patch, so I dropped it in v6. The mirror
re-initialization on resume is unaffected, since bcm_sf2_sw_setup() still calls b53_mirror_init() once the later patch adds it.
[Medium] This only applied to the new error path, which is gone in v6.
pw-bot: cr
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH v5 7/8 net: dsa: b53: harden mirror register programming
In reply to Florian FainelliThe 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.
--- drivers/net/dsa/b53/b53_common.c | 91 ++++++++++++++++++++------------ drivers/net/dsa/bcm_sf2.c | 4 ++ 2 files changed, 61 insertions(+), 34 deletions(-)
drivers/net/dsa/b53/b53_common.c +57 -34
@@ -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);
drivers/net/dsa/bcm_sf2.c +4 -0
@@ -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 */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
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.
Quoted 6 lines
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.
[ ... ]
Quoted 1 line
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?
drivers/net/dsa/b53/b53_common.c static int b53_setup(struct dsa_switch *ds) · line 1366
Quoted 12 lines
drivers/net/dsa/b53/b53_common.c +4
-0@@ -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.
[ ... ]
drivers/net/dsa/bcm_sf2.c static int bcm_sf2_sw_setup(struct dsa_switch *ds) · line 1069
Quoted 12 lines
drivers/net/dsa/bcm_sf2.c +4
-0@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com
Florian Fainelli
maintainerRe: [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming
Quoted 150 lines · On 11/16/26 11:02, [email protected] wrote:
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 andbcm_sf2setup".--
net: dsa: b53: harden mirror register programming
This commit calls
b53_mirror_init()fromb53_setup()andbcm_sf2_sw_setup()to reset the mirror registers at setup. It checks every mirror register read and write inb53_mirror_add()andb53_mirror_del(), and only increments the source reference count after programming succeeds. It also uses the ingress/egress source masks, instead ofMIRROR_EN, to decide whether the capture destination is in use.Quoted 6 lines
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.
[ ... ]
Quoted 1 line
Fixes ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")[Severity: Low]
Ised3af5fd08ebthe right commit for the first problem described here?Before this series,
b53_mirror_add()overwroteB53_MIR_CAP_CTLand 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:
ed3af5fd08ebtag, 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_ENset 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?
drivers/net/dsa/b53/b53_common.c static int b53_setup(struct dsa_switch *ds) · line 1366
Quoted 12 lines
drivers/net/dsa/b53/b53_common.c +4
-0@@ -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 throughb53_setup()?With this call,
b53_mirror_init()writes zero to Management page offsets0x10(B53_MIR_CAP_CTL),0x12(B53_IG_MIR_CTL) and0x1C(B53_EG_MIR_CTL) at every setup, on everychip_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 0x08The 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,0x12or0x1C, would that register now be silently zeroed on every boot? A write to the wrong register would still return success here.[ ... ]
drivers/net/dsa/bcm_sf2.c static int bcm_sf2_sw_setup(struct dsa_switch *ds) · line 1069
Quoted 12 lines
drivers/net/dsa/bcm_sf2.c +4
-0@@ -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_sf2setup, 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_sf2this also runs on every resume:
bcm_sf2_sw_resume()
ds->ops->setup()bcm_sf2_sw_setup() b53_mirror_init()
Quoted 7 lines
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?
[Medium] b53_mirror_add()/b53_mirror_del() are already wired up for every chip handled by b53_switch_ops, including BCM63xx, and they use the same three management page offsets (0x10, 0x12, 0x1C) without any per-chip variant. b53_mirror_init() touches exactly those registers and nothing else, so setup does not write to any register that the mirror callbacks would not already write. The mirror registers are at the same offsets on BCM63xx. In the BCM6368, BCM6362 and BCM63268 register documentation, the Mirror Capture Control, Ingress Mirror Control and Egress Mirror Control registers are at Management page (0x02) offsets 0x10, 0x12 and 0x1C. These are the same registers the existing port_mirror_add/del callbacks program on every b53_switch_ops chip, so zeroing them at setup does not touch an unrelated register.
[Low] Agreed on both. v6 describes the restore of active mirror rules (bcm_sf2 runs setup again on resume) and documents the dependency on "reject conflicting mirror destinations" and "reference count shared mirror source bits".
Signature · 1 line
Florian
Florian Fainelli
maintainerPATCH v5 8/8 net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365
In reply to Florian FainelliBCM5325 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.
--- drivers/net/dsa/b53/b53_common.c | 46 +++++++++++++++++++++++++------- drivers/net/dsa/b53/b53_regs.h | 1 + 2 files changed, 38 insertions(+), 9 deletions(-)
drivers/net/dsa/b53/b53_common.c +37 -9
@@ -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;
drivers/net/dsa/b53/b53_regs.h +1 -0
@@ -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)
Signature · 1 line
2.53.0