# \[PATCH net-next 3/5\] net: dsa: microchip: ksz9477: do not learn addresses on the CPU port

- From: Oleksij Rempel \<o.rempel@pengutronix.de\>
- Date: 2026-11-26 08:08:03 
- List: netdev
- Page: https://ratatoskr.run/netdev/2026/11/18029468
- Thread: https://ratatoskr.run/netdev/2026/11/18029469/t.md

```text
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

```
