From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
Jonas Gorski <jonas.gorski@gmail.com>,
Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Russell King <linux@armlinux.org.uk>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net v2 4/5] net: dsa: b53: reject conflicting mirror destinations
Date: Wed, 28 Oct 2026 14:23:09 -0700 [thread overview]
Message-ID: <20261028212310.3847553-5-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261028212310.3847553-1-florian.fainelli@broadcom.com>
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.
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 c38e8c5838bd..378f47e7250c 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2543,7 +2543,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;
@@ -2554,11 +2566,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;
}
@@ -2595,10 +2606,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
next prev parent reply other threads:[~2026-10-28 21:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 21:23 [PATCH net v2 0/5] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-10-28 21:23 ` [PATCH net v2 1/5] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-10-28 21:23 ` [PATCH net v2 2/5] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
2026-10-28 21:23 ` [PATCH net v2 3/5] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
2026-10-28 21:23 ` Florian Fainelli [this message]
2026-10-28 21:23 ` [PATCH net v2 5/5] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261028212310.3847553-5-florian.fainelli@broadcom.com \
--to=florian.fainelli@broadcom.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jonas.gorski@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=rmk+kernel@armlinux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox