Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames
@ 2026-11-26  8:07 Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 1/5] net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded Oleksij Rempel
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Let the bridge decide about the link-local frames that the KSZ9477
family and LAN937x trap to the CPU. These switches trap most link-local
groups (01:80:C2:00:00:0X, for example STP BPDUs and LLDP), but the
tagger marks the frames as forwarded in hardware. So the bridge never
forwards them to the other ports of the switch, whatever group_fwd_mask
says. An FDB or MDB entry for such a group can also make the switch
forward these frames on its own.

The tagger now leaves these frames unmarked, and the driver keeps FDB
and MDB entries for them out of the hardware. As the bridge then sends
some link-local frames back out through the CPU port, the switch no
longer learns addresses there; DSA adds the addresses that the bridge
learns on its other ports, such as Wi-Fi, as static entries instead. An
old FDB bug hits these entries often, so one patch fixes it; without the
series it needs a static entry added over a learned one, so that patch
goes to net-next with the series. The series goes to net-next as it
changes how the bridge handles link-local frames.

To reproduce on a KSZ9893, with link partners on lan1 and lan2:

  ip link add br0 type bridge
  ip link set lan1 master br0 up; ip link set lan2 master br0 up
  ip link set br0 up
  # 0x4000: forward 01:80:C2:00:00:0E
  ip link set br0 type bridge group_fwd_mask 0x4000
  # Send frames to 01:80:C2:00:00:0E into lan1. Without the series
  # none reach lan2; with it, all do.

With STP off, the bridge now also forwards BPDUs between the ports of
the switch. IEEE 802.1Q says a bridge filters frames to the reserved
addresses, including the BPDU address 01:80:C2:00:00:00. The Linux
bridge forwards BPDUs when STP is off, so that other bridges can still
detect a loop through it; see commit a598f6aebea2 ("bridge: relay
bridge multicast pkgs if !STP"). DSA switches whose tagger leaves
trapped or link-local frames unmarked, such as mv88e6xxx and b53,
already behave this way.

The switches driven by ksz8.c (KSZ8463, KSZ87xx, KSZ88x3, KSZ8864,
KSZ8895, KSZ8995XA) keep their behaviour; KSZ8563 and KSZ8567 use the
KSZ9477 code and are covered. The ksz8.c switches have one static MAC
table. It holds the trap entries, the FDB and MDB entries and the local
addresses of the bridge, and on the KSZ88x3 it has only 8 entries, so a
change on the KSZ88x3 can run out of space. Of these switches I can test
only a KSZ8873, so I left them unchanged. Their taggers still mark all
frames as forwarded.

Tested on a KSZ9893.

---
Oleksij Rempel (5):
      net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded
      net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries
      net: dsa: microchip: ksz9477: do not learn addresses on the CPU port
      net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups
      net: dsa: microchip: ksz9477: report the trapped link-local groups

 drivers/net/dsa/microchip/ksz9477.c      | 81 +++++++++++++++++++++++++++++---
 drivers/net/dsa/microchip/ksz_common.h   | 14 ++++++
 drivers/net/dsa/microchip/lan937x_main.c | 16 ++++---
 include/linux/dsa/ksz_common.h           |  8 ++++
 net/dsa/tag_ksz.c                        | 42 ++++++++++++++++-
 5 files changed, 145 insertions(+), 16 deletions(-)
---
base-commit: c2621b518b38ed38e280e008aa33e6c2d302f8cc
change-id: 20261125-ksz-stp-link-local-5c53396cc960

Best regards,
-- 
Oleksij Rempel <o.rempel@pengutronix.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/5] net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
@ 2026-11-26  8:07 ` Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries Oleksij Rempel
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Do not mark trapped link-local frames as forwarded in hardware. The
switch did not forward them, so the mark would be wrong. Whether such a
frame is forwarded is policy, and that belongs to the bridge, not to the
driver.

The switch traps frames to some of the reserved addresses
01:80:C2:00:00:00 to :0F, that is, sends them only to the CPU. For
example:
- 01:80:C2:00:00:00: STP BPDUs
- 01:80:C2:00:00:02: LACP and other slow protocols
- 01:80:C2:00:00:03: 802.1X (EAPOL)
- 01:80:C2:00:00:0E: LLDP, PTP

Some link-local frames must still be marked as forwarded. The KSZ8873,
which uses the same tag as the KSZ9893, traps only 01:80:C2:00:00:00
and floods LLDP frames (01:80:C2:00:00:0E) like normal multicast.
Without the forwarding mark, the bridge could forward such a frame a
second time, if group_fwd_mask allows it. The tail tag does not say
whether a frame was trapped, so the switch driver gives the tagger a
bitmap of the groups the switch traps. No driver fills the bitmap yet,
so frame handling does not change with this patch alone.

Give the KSZ8795 tag a connect callback that allocates the tagger data,
as the tagger now reads it for every KSZ tag protocol.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 include/linux/dsa/ksz_common.h |  8 ++++++++
 net/dsa/tag_ksz.c              | 42 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/include/linux/dsa/ksz_common.h b/include/linux/dsa/ksz_common.h
index 576a99ca698d13cc3debd41a310502b29fc85c63..66d480c435c2f98b5a77bc64422b43414946f143 100644
--- a/include/linux/dsa/ksz_common.h
+++ b/include/linux/dsa/ksz_common.h
@@ -32,6 +32,14 @@ struct ksz_deferred_xmit_work {
 struct ksz_tagger_data {
 	void (*xmit_work_fn)(struct kthread_work *work);
 	void (*hwtstamp_set_state)(struct dsa_switch *ds, bool on);
+	/* Bit N is set if the switch traps frames to 01:80:C2:00:00:0N
+	 * (N = 0x0 to 0xf), that is, sends them to the CPU only. The tagger
+	 * does not mark these frames as forwarded, so the bridge, not the
+	 * switch, decides whether to forward them. Only the switch driver
+	 * writes this bitmap, from .connect_tag_protocol, before the tagger
+	 * receives any frame.
+	 */
+	u16 link_local_to_cpu;
 };
 
 struct ksz_skb_cb {
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index b0340a7be8c9a6dcd52a64117e10fe3e134026e6..16da9daf774904222bd92f771086aa74e1bc390b 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -48,11 +48,28 @@ static void ksz_disconnect(struct dsa_switch *ds)
 {
 	struct ksz_tagger_private *priv = ds->tagger_data;
 
-	kthread_destroy_worker(priv->xmit_worker);
+	/* Tags without deferred xmit have no worker */
+	if (priv->xmit_worker)
+		kthread_destroy_worker(priv->xmit_worker);
+
 	kfree(priv);
 	ds->tagger_data = NULL;
 }
 
+/* Allocate the tagger data, without a deferred xmit worker */
+static int ksz8795_connect(struct dsa_switch *ds)
+{
+	struct ksz_tagger_private *priv;
+
+	priv = kzalloc_obj(*priv);
+	if (!priv)
+		return -ENOMEM;
+
+	ds->tagger_data = priv;
+
+	return 0;
+}
+
 static int ksz_connect(struct dsa_switch *ds)
 {
 	struct ksz_tagger_data *tagger_data;
@@ -81,6 +98,19 @@ static int ksz_connect(struct dsa_switch *ds)
 	return 0;
 }
 
+static bool ksz_link_local_trapped(struct net_device *user, const u8 *addr)
+{
+	struct ksz_tagger_data *tagger_data;
+
+	if (!is_link_local_ether_addr(addr))
+		return false;
+
+	tagger_data = ksz_tagger_data(dsa_user_to_port(user)->ds);
+
+	/* is_link_local_ether_addr() limits addr[5] to 0x00..0x0f */
+	return tagger_data->link_local_to_cpu & BIT(addr[5]);
+}
+
 static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
 				      struct net_device *dev,
 				      unsigned int port, unsigned int len)
@@ -96,7 +126,13 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
 		return NULL;
 	}
 
-	dsa_default_offload_fwd_mark(skb);
+	/* The switch driver reports which link-local groups the switch sends
+	 * to the CPU only. The switch did not forward frames to these groups,
+	 * so do not mark them, and let the bridge apply its own rules
+	 * (group_fwd_mask, STP state).
+	 */
+	if (!ksz_link_local_trapped(skb->dev, eth_hdr(skb)->h_dest))
+		dsa_default_offload_fwd_mark(skb);
 
 	return skb;
 }
@@ -360,6 +396,8 @@ static const struct dsa_device_ops ksz8795_netdev_ops = {
 	.proto	= DSA_TAG_PROTO_KSZ8795,
 	.xmit	= ksz8795_xmit,
 	.rcv	= ksz8795_rcv,
+	.connect = ksz8795_connect,
+	.disconnect = ksz_disconnect,
 	.needed_tailroom = KSZ_INGRESS_TAG_LEN,
 };
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 1/5] net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded Oleksij Rempel
@ 2026-11-26  8:07 ` Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 3/5] net: dsa: microchip: ksz9477: do not learn addresses on the CPU port Oleksij Rempel
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Do not keep the learned port when adding a static FDB entry.

The ALU table of the switch keeps learned (dynamic) and static
entries, one entry per address. An example: the switch has learned
host H on lan1. Then a static FDB entry for H is added on lan2. The
driver does not add a new entry. It finds the learned entry, makes it
static and adds lan2 to its ports. The entry is now static and points
to lan1 and lan2.

When the FDB entry is deleted, the driver removes only lan2. The entry
stays static and still points to lan1. Static entries never age out.
So the switch keeps sending frames for H to lan1, even after H has
moved.

The bug is hit much more often once the driver sets
ds->assisted_learning_on_cpu_port, which the next ksz9477 change does.
DSA then adds a static entry on the CPU port for each address the
bridge learns on ports outside the switch, such as Wi-Fi. If H was
learned on lan1 and then moved to Wi-Fi, the entry for the CPU port
still points to lan1 too.

LAN937x uses the same code.

Found in code review. Confirmed on a KSZ9893; with H learned on lan1,
run:

  bridge fdb replace <H> dev lan2 master static
  bridge fdb del <H> dev lan2 master static
  bridge fdb show    # still shows "<H> dev lan1 self static"

Tested on a KSZ9893 with the commands above and with our labgrid
switch tests: with this patch, no static entry for <H> is left.

Fixes: b987e98e50ab ("dsa: add DSA switch driver for Microchip KSZ9477")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
If bridge fdb replace moves an existing static entry to another port,
the entry still keeps the old port. This patch does not change that.
---
 drivers/net/dsa/microchip/ksz9477.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 972703fe7454f2892b98dc507a1cba0a5c91dabd..98211d9835734c52f25dcbf7494df45166bcc8da 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -800,6 +800,13 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 	/* read ALU entry */
 	ksz9477_read_table(dev, alu_table);
 
+	/* The ALU table holds learned and static entries. If the entry is
+	 * not static (learned, or none found), clear its port map, so that
+	 * the static entry lists only this port.
+	 */
+	if (!(alu_table[0] & ALU_V_STATIC_VALID))
+		alu_table[1] &= ~ALU_V_PORT_MAP;
+
 	/* update ALU entry */
 	alu_table[0] = ALU_V_STATIC_VALID;
 	alu_table[1] |= BIT(port);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/5] net: dsa: microchip: ksz9477: do not learn addresses on the CPU port
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 1/5] net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries Oleksij Rempel
@ 2026-11-26  8:07 ` Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 4/5] net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups Oleksij Rempel
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Do not learn addresses on the CPU port of the KSZ9477 family (including
KSZ8563 and KSZ8567) and LAN937x. The bridge also learns addresses on
ports outside the switch, for example on Wi-Fi. DSA adds these as
static entries on the CPU port, so the switch does not need to learn
them there. DSA already adds the bridge's own addresses there.

This prepares for reporting the trapped link-local groups to the
tagger. The switch sends trapped frames only to the CPU. Once the
groups are reported, the bridge can forward such frames, for example
BPDUs, in software. It sends them back to the switch through the CPU
port, with the sender's source address, and a learning CPU port then
records the sender there. Frames from the other switch ports to the
sender go to the CPU, and the bridge does not send them back out. This
repeats with every such frame the bridge forwards. I saw this on a
KSZ9893 with the report patch applied.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
HSR: the HSR ports are in no bridge, so DSA adds no host entry for the
HSR MAC address. From the code, unicast to the node is now also flooded
to the other ring port, where the CPU port used to learn the address.
---
 drivers/net/dsa/microchip/ksz9477.c      | 15 ++++++++-------
 drivers/net/dsa/microchip/lan937x_main.c | 15 ++++++++-------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 98211d9835734c52f25dcbf7494df45166bcc8da..8271bc742ddc5c92b925b01bedfcf876cfa14078 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1710,7 +1710,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	struct ksz_device *dev = ds->priv;
 	u16 storm_mask, storm_rate;
 	struct dsa_port *dp;
-	struct ksz_port *p;
 	const u16 *regs;
 	int ret;
 
@@ -1792,13 +1791,15 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	if (ret < 0)
 		return ret;
 
-	/* Start with learning disabled on standalone user ports, and enabled
-	 * on the CPU port. In lack of other finer mechanisms, learning on the
-	 * CPU port will avoid flooding bridge local addresses on the network
-	 * in some cases.
+	/* Ask DSA to add the addresses that the bridge learns on ports
+	 * outside the switch as static entries on the CPU port. The CPU
+	 * port itself does not learn: when the bridge forwards a frame in
+	 * software between two ports of the switch, the switch would learn
+	 * the sender on the CPU port. p->learning is never set for the CPU
+	 * port, so ksz_port_stp_state_set() disables learning when DSA sets
+	 * the port to forwarding.
 	 */
-	p = &dev->ports[dev->cpu_port];
-	p->learning = true;
+	ds->assisted_learning_on_cpu_port = true;
 
 	if (dev->irq > 0) {
 		ret = ksz_girq_setup(dev);
diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c
index f0fb9498026120b3069b31d01bd0252be6f15403..7971d120630d173a1bbed6fb98683cee27d8fe89 100644
--- a/drivers/net/dsa/microchip/lan937x_main.c
+++ b/drivers/net/dsa/microchip/lan937x_main.c
@@ -770,7 +770,6 @@ static int lan937x_setup(struct dsa_switch *ds)
 	struct ksz_device *dev = ds->priv;
 	u16 storm_mask, storm_rate;
 	struct dsa_port *dp;
-	struct ksz_port *p;
 	const u16 *regs;
 	int ret;
 
@@ -843,13 +842,15 @@ static int lan937x_setup(struct dsa_switch *ds)
 	if (ret < 0)
 		return ret;
 
-	/* Start with learning disabled on standalone user ports, and enabled
-	 * on the CPU port. In lack of other finer mechanisms, learning on the
-	 * CPU port will avoid flooding bridge local addresses on the network
-	 * in some cases.
+	/* Ask DSA to add the addresses that the bridge learns on ports
+	 * outside the switch as static entries on the CPU port. The CPU
+	 * port itself does not learn: when the bridge forwards a frame in
+	 * software between two ports of the switch, the switch would learn
+	 * the sender on the CPU port. p->learning is never set for the CPU
+	 * port, so ksz_port_stp_state_set() disables learning when DSA sets
+	 * the port to forwarding.
 	 */
-	p = &dev->ports[dev->cpu_port];
-	p->learning = true;
+	ds->assisted_learning_on_cpu_port = true;
 
 	if (dev->irq > 0) {
 		ret = ksz_girq_setup(dev);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 4/5] net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
                   ` (2 preceding siblings ...)
  2026-11-26  8:07 ` [PATCH net-next 3/5] net: dsa: microchip: ksz9477: do not learn addresses on the CPU port Oleksij Rempel
@ 2026-11-26  8:07 ` Oleksij Rempel
  2026-11-26  8:07 ` [PATCH net-next 5/5] net: dsa: microchip: ksz9477: report the trapped link-local groups Oleksij Rempel
  2026-11-26 10:23 ` [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Vladimir Oltean
  5 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Refuse FDB and MDB entries for trapped link-local groups on user ports,
so that they cannot bypass the trap.

The KSZ9477 family looks up a destination address in the address
lookup table (learned and static FDB entries), the static address table
(MDB entries) and the reserved multicast table. The driver traps the
link-local groups with the reserved multicast table: it sends
01:80:C2:00:00:00 to :0F to the CPU only, except :01 (PAUSE frames),
which it drops. On a KSZ9893, an FDB or MDB entry for a trapped group
overrides that rule. The switch then forwards such frames by its own
lookup, while the bridge decides in software whether to forward these
groups:
- with an MDB entry for 01:80:C2:00:00:0E on lan2, the switch forwarded
  these frames from lan1 to lan2, although group_fwd_mask did not allow
  it.
- with a host FDB entry for 01:80:C2:00:00:00, a Blocking port stopped
  passing BPDUs to the CPU, so the bridge moved the port to Listening.

Record the trapped groups when the driver sets up the reserved multicast
table, and refuse to offload such entries on user ports with
-EOPNOTSUPP. bridge fdb add and bridge mdb add still succeed, and the
bridge keeps the entries without the offload flag. In software the
bridge uses only the MDB entries for these groups, so an FDB entry for
such a group has no effect. DSA logs an error for a refused FDB entry,
not for an MDB entry. Accept the entries on the CPU and DSA ports
without a write. Entries for :01 are accepted as before.

A later patch makes the tagger stop marking these frames as already
forwarded by the switch. This patch comes first, so that the switch and
the bridge never both forward such a frame. Until then, frames to a
group with a refused MDB entry are not forwarded between switch ports
at all.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c    | 58 ++++++++++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  2 ++
 2 files changed, 60 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 8271bc742ddc5c92b925b01bedfcf876cfa14078..b972c9fab55c170758dac97bda026e1f29e487f2 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -768,6 +768,27 @@ int ksz9477_port_vlan_del(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+/* True if @addr is a link-local group that the switch sends to the CPU only.
+ * An FDB or MDB entry for such a group would override the trap.
+ */
+static bool ksz9477_link_local_is_trapped(struct ksz_device *dev,
+					  const unsigned char *addr)
+{
+	/* is_link_local_ether_addr() limits addr[5] to 0x00..0x0f */
+	return is_link_local_ether_addr(addr) &&
+	       dev->link_local_to_cpu & BIT(addr[5]);
+}
+
+/* Return -EOPNOTSUPP on a user port, so that the bridge keeps the entry in
+ * software and does not mark it offloaded. Return 0 on the CPU and DSA ports
+ * and write nothing: the bridge adds its host entries there, and they must
+ * not fail.
+ */
+static int ksz9477_link_local_entry_err(struct dsa_switch *ds, int port)
+{
+	return dsa_is_user_port(ds, port) ? -EOPNOTSUPP : 0;
+}
+
 int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 		    const unsigned char *addr, u16 vid, struct dsa_db db)
 {
@@ -776,6 +797,9 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 	u32 data;
 	int ret = 0;
 
+	if (ksz9477_link_local_is_trapped(dev, addr))
+		return ksz9477_link_local_entry_err(ds, port);
+
 	mutex_lock(&dev->alu_mutex);
 
 	/* find any entry with mac & vid */
@@ -840,6 +864,10 @@ int ksz9477_fdb_del(struct dsa_switch *ds, int port,
 	u32 data;
 	int ret = 0;
 
+	/* never written, see ksz9477_link_local_entry_err() */
+	if (ksz9477_link_local_is_trapped(dev, addr))
+		return 0;
+
 	mutex_lock(&dev->alu_mutex);
 
 	/* read any entry with mac & vid */
@@ -989,6 +1017,9 @@ int ksz9477_mdb_add(struct dsa_switch *ds, int port,
 	u32 mac_hi, mac_lo;
 	int err = 0;
 
+	if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+		return ksz9477_link_local_entry_err(ds, port);
+
 	shifts = dev->info->shifts;
 	masks = dev->info->masks;
 
@@ -1069,6 +1100,10 @@ int ksz9477_mdb_del(struct dsa_switch *ds, int port,
 	int index;
 	u32 data;
 
+	/* never written, see ksz9477_link_local_entry_err() */
+	if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+		return 0;
+
 	shifts = dev->info->shifts;
 	masks = dev->info->masks;
 
@@ -1554,8 +1589,21 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 
 static u8 reserved_mcast_map[RESV_MCAST_CNT] = { 0, 1, 3, 16, 32, 33, 2, 17 };
 
+/* Index: group number in the datasheet's Reserved Multicast Address Table,
+ * the same index as reserved_mcast_map. Value: the link-local addresses the
+ * group covers, bit X for 01:80:C2:00:00:0X. The other groups cover
+ * addresses above :0F.
+ */
+static const u16 ksz9477_resv_mcast_link_local[RESV_MCAST_CNT] = {
+	[0] = BIT(0),			/* STP BPDUs */
+	[1] = BIT(1),			/* MAC control (e.g. PAUSE), dropped */
+	[2] = BIT(3),			/* 802.1X (EAPOL) */
+	[6] = BIT(2) | GENMASK(15, 4),	/* LACP, LLDP and others */
+};
+
 int ksz9477_enable_stp_addr(struct ksz_device *dev)
 {
+	u16 link_local_to_cpu = 0;
 	u8 i, ports, update;
 	const u32 *masks;
 	bool override;
@@ -1621,6 +1669,14 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
 			update = ports;
 			break;
 		}
+
+		/* Record the link-local addresses of group i if the switch
+		 * sends it to the CPU only. Group 1 keeps its drop default and
+		 * does not match.
+		 */
+		if (update == BIT(dev->cpu_port))
+			link_local_to_cpu |= ksz9477_resv_mcast_link_local[i];
+
 		if (update != ports || override) {
 			data &= ~dev->port_mask;
 			data |= update;
@@ -1650,6 +1706,8 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
 		}
 	}
 
+	dev->link_local_to_cpu = link_local_to_cpu;
+
 	return 0;
 }
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8819670cbb053eeb73ea4a7685303d9849bd6efb..7b96d110b1f64f4226ee7a371da38cd7e5b3767a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -243,6 +243,8 @@ struct ksz_device {
 	u16 mirror_rx;
 	u16 mirror_tx;
 	u16 port_mask;
+	/* link-local groups sent to the CPU only, bit X: 01:80:C2:00:00:0X */
+	u16 link_local_to_cpu;
 	struct mutex lock_irq;		/* IRQ Access */
 	struct ksz_irq girq;
 	struct ksz_ptp_data ptp_data;

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 5/5] net: dsa: microchip: ksz9477: report the trapped link-local groups
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
                   ` (3 preceding siblings ...)
  2026-11-26  8:07 ` [PATCH net-next 4/5] net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups Oleksij Rempel
@ 2026-11-26  8:07 ` Oleksij Rempel
  2026-11-26 10:23 ` [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Vladimir Oltean
  5 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2026-11-26  8:07 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel,
	netdev, bridge, kernel, Oleksij Rempel

Tell the tagger which link-local groups the KSZ9477 family and LAN937x
trap to the CPU. The tagger then no longer marks these frames as
forwarded in hardware (offload_fwd_mark). The bridge applies
group_fwd_mask and the STP state to them and can forward them to the
other ports of the switch.

Tested on a KSZ9893: with the group_fwd_mask bit for 01:80:C2:00:00:0E
set, the bridge relayed 20 of 20 frames to that group from lan1 to lan2
with this change, and 0 of 20 without it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c      |  1 +
 drivers/net/dsa/microchip/ksz_common.h   | 12 ++++++++++++
 drivers/net/dsa/microchip/lan937x_main.c |  1 +
 3 files changed, 14 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index b972c9fab55c170758dac97bda026e1f29e487f2..3dee81d89c1d7e64314a073980fb648431126a09 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -2109,6 +2109,7 @@ static int ksz9477_connect_tag_protocol(struct dsa_switch *ds,
 
 	tagger_data = ksz_tagger_data(ds);
 	tagger_data->xmit_work_fn = ksz_port_deferred_xmit;
+	ksz_tagger_set_link_local_to_cpu(ds);
 
 	return 0;
 }
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 7b96d110b1f64f4226ee7a371da38cd7e5b3767a..1f96b91016fcfa20f99599c10d4095d7f384f7f6 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -7,6 +7,7 @@
 #ifndef __KSZ_COMMON_H
 #define __KSZ_COMMON_H
 
+#include <linux/dsa/ksz_common.h>
 #include <linux/etherdevice.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
@@ -836,6 +837,17 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)
 		dev->chip_id == LAN9372_CHIP_ID) && port == KSZ_PORT_4;
 }
 
+/* Copy dev->link_local_to_cpu to the tagger. Call this from
+ * connect_tag_protocol: ksz9477_enable_stp_addr() fills the bitmap during
+ * ->setup(), and DSA connects the tagger only after ->setup().
+ */
+static inline void ksz_tagger_set_link_local_to_cpu(struct dsa_switch *ds)
+{
+	struct ksz_device *dev = ds->priv;
+
+	ksz_tagger_data(ds)->link_local_to_cpu = dev->link_local_to_cpu;
+}
+
 static inline int ksz_get_sgmii_port(struct ksz_device *dev)
 {
 	return dev->info->sgmii_port - 1;
diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c
index 7971d120630d173a1bbed6fb98683cee27d8fe89..7452b8c6a73552d9ae4f410dead3b968f22124e5 100644
--- a/drivers/net/dsa/microchip/lan937x_main.c
+++ b/drivers/net/dsa/microchip/lan937x_main.c
@@ -924,6 +924,7 @@ static int lan937x_connect_tag_protocol(struct dsa_switch *ds,
 
 	tagger_data = ksz_tagger_data(ds);
 	tagger_data->xmit_work_fn = ksz_port_deferred_xmit;
+	ksz_tagger_set_link_local_to_cpu(ds);
 
 	return 0;
 }

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames
  2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
                   ` (4 preceding siblings ...)
  2026-11-26  8:07 ` [PATCH net-next 5/5] net: dsa: microchip: ksz9477: report the trapped link-local groups Oleksij Rempel
@ 2026-11-26 10:23 ` Vladimir Oltean
  5 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-26 10:23 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Florian Fainelli, Nikolay Aleksandrov, Ido Schimmel, netdev,
	bridge, kernel

Hi Oleksij,

On Thu, Nov 26, 2026 at 09:07:47AM +0100, Oleksij Rempel wrote:
> Let the bridge decide about the link-local frames that the KSZ9477
> family and LAN937x trap to the CPU. These switches trap most link-local
> groups (01:80:C2:00:00:0X, for example STP BPDUs and LLDP), but the
> tagger marks the frames as forwarded in hardware. So the bridge never
> forwards them to the other ports of the switch, whatever group_fwd_mask
> says. An FDB or MDB entry for such a group can also make the switch
> forward these frames on its own.
> 
> The tagger now leaves these frames unmarked, and the driver keeps FDB
> and MDB entries for them out of the hardware. As the bridge then sends
> some link-local frames back out through the CPU port, the switch no
> longer learns addresses there; DSA adds the addresses that the bridge
> learns on its other ports, such as Wi-Fi, as static entries instead. An
> old FDB bug hits these entries often, so one patch fixes it; without the
> series it needs a static entry added over a learned one, so that patch
> goes to net-next with the series. The series goes to net-next as it
> changes how the bridge handles link-local frames.
> 
> To reproduce on a KSZ9893, with link partners on lan1 and lan2:
> 
>   ip link add br0 type bridge
>   ip link set lan1 master br0 up; ip link set lan2 master br0 up
>   ip link set br0 up
>   # 0x4000: forward 01:80:C2:00:00:0E
>   ip link set br0 type bridge group_fwd_mask 0x4000
>   # Send frames to 01:80:C2:00:00:0E into lan1. Without the series
>   # none reach lan2; with it, all do.
> 
> With STP off, the bridge now also forwards BPDUs between the ports of
> the switch. IEEE 802.1Q says a bridge filters frames to the reserved
> addresses, including the BPDU address 01:80:C2:00:00:00. The Linux
> bridge forwards BPDUs when STP is off, so that other bridges can still
> detect a loop through it; see commit a598f6aebea2 ("bridge: relay
> bridge multicast pkgs if !STP"). DSA switches whose tagger leaves
> trapped or link-local frames unmarked, such as mv88e6xxx and b53,
> already behave this way.
> 
> The switches driven by ksz8.c (KSZ8463, KSZ87xx, KSZ88x3, KSZ8864,
> KSZ8895, KSZ8995XA) keep their behaviour; KSZ8563 and KSZ8567 use the
> KSZ9477 code and are covered. The ksz8.c switches have one static MAC
> table. It holds the trap entries, the FDB and MDB entries and the local
> addresses of the bridge, and on the KSZ88x3 it has only 8 entries, so a
> change on the KSZ88x3 can run out of space. Of these switches I can test
> only a KSZ8873, so I left them unchanged. Their taggers still mark all
> frames as forwarded.
> 
> Tested on a KSZ9893.
> 
> ---
> Oleksij Rempel (5):
>       net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded
>       net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries
>       net: dsa: microchip: ksz9477: do not learn addresses on the CPU port
>       net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups
>       net: dsa: microchip: ksz9477: report the trapped link-local groups
> 
>  drivers/net/dsa/microchip/ksz9477.c      | 81 +++++++++++++++++++++++++++++---
>  drivers/net/dsa/microchip/ksz_common.h   | 14 ++++++
>  drivers/net/dsa/microchip/lan937x_main.c | 16 ++++---
>  include/linux/dsa/ksz_common.h           |  8 ++++
>  net/dsa/tag_ksz.c                        | 42 ++++++++++++++++-
>  5 files changed, 145 insertions(+), 16 deletions(-)
> ---
> base-commit: c2621b518b38ed38e280e008aa33e6c2d302f8cc
> change-id: 20261125-ksz-stp-link-local-5c53396cc960
> 
> Best regards,
> -- 
> Oleksij Rempel <o.rempel@pengutronix.de>
> 

I didn't go into any sort of detail in these patches yet, but they
reminded me of this thread:
https://lore.kernel.org/netdev/20250127125426.3b7cdkb75o5dbcr5@skbuf/

IIRC Tim's problem there still wasn't resolved (he tried to use the
reserved multicast address tables). Does your series address his issue
too?

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-26 10:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:07 [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Oleksij Rempel
2026-11-26  8:07 ` [PATCH net-next 1/5] net: dsa: tag_ksz: do not mark trapped link-local frames as forwarded Oleksij Rempel
2026-11-26  8:07 ` [PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries Oleksij Rempel
2026-11-26  8:07 ` [PATCH net-next 3/5] net: dsa: microchip: ksz9477: do not learn addresses on the CPU port Oleksij Rempel
2026-11-26  8:07 ` [PATCH net-next 4/5] net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups Oleksij Rempel
2026-11-26  8:07 ` [PATCH net-next 5/5] net: dsa: microchip: ksz9477: report the trapped link-local groups Oleksij Rempel
2026-11-26 10:23 ` [PATCH net-next 0/5] net: dsa: microchip: let the bridge decide about link-local frames Vladimir Oltean

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox