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>,
Vivien Didelot <vivien.didelot@gmail.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net v4 6/8] net: dsa: b53: reference count shared mirror source bits
Date: Mon, 9 Nov 2026 19:50:16 -0800 [thread overview]
Message-ID: <20261110035018.2169370-7-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261110035018.2169370-1-florian.fainelli@broadcom.com>
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 | 3 ++
drivers/net/dsa/bcm_sf2.c | 6 ++--
3 files changed, 68 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..d55fba9bcb1d 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;
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
next prev parent reply other threads:[~2026-11-10 3:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 3:50 [PATCH net v4 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
2026-11-10 3:50 ` Florian Fainelli [this message]
2026-11-10 3:50 ` [PATCH net v4 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
2026-11-10 3:50 ` [PATCH net v4 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 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=20261110035018.2169370-7-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=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=vivien.didelot@gmail.com \
/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
all inboxes | Powered by JetHome®