Do not learn addresses on the CPU port of the KSZ9477 family and LAN937x. Set ds->assisted_learning_on_cpu_port instead, so that DSA adds the addresses that the bridge learns on ports outside the switch as static entries on the CPU port. The patch "report the trapped link-local groups" lets the bridge forward some trapped frames in software, for example BPDUs while STP is off. It sends them back through the CPU port with the original source address, and a learning CPU port would record the sender there. Frames from the other switch ports to that sender would then end at the CPU. I saw this on a KSZ9893. While a KSZ9477 offloads HSR, the CPU port learns as before, because DSA adds no entries for HSR ports. HSR and a bridge use the same CPU port, so it cannot learn for one and not for the other; they are no longer offloaded at the same time. This combination was already problematic before this patch: with a bridge on top of hsr0, the CPU port could learn the ring nodes. Signed-off-by: Oleksij Rempel --- Q: Does a refused HSR join really fall back to software HSR? A: Not after an earlier HSR offload on that port: ksz9477_hsr_leave() does not clear the HSR feature flags that ksz9477_hsr_join() sets, so the HSR core still treats forwarding as offloaded. This is older than this series, and I did not fix it here. Q: Why not a static CPU-port entry for the HSR MAC address instead? A: I cannot test HSR offload, and HSR is not related to this problem. That would be a separate change to the HSR offload code. Changes in v2: - Turn learning on the CPU port back on while HSR is offloaded (sashiko). - Do not offload HSR and a bridge at the same time. - Flush what the CPU port learned when HSR offload ends. --- drivers/net/dsa/microchip/ksz9477.c | 49 ++++++++++++++++++++++++++------ drivers/net/dsa/microchip/ksz_common.c | 9 ++++++ drivers/net/dsa/microchip/lan937x_main.c | 9 +----- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 98211d9835734c52f25dcbf7494df45166bcc8da..2b563e44945413b95941776146b05399cda11ab8 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,7 @@ 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. - */ - 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); @@ -1897,6 +1890,29 @@ static int ksz9477_tc_cbs_set_cinc(struct ksz_device *dev, int port, u32 val) */ #define KSZ9477_SUPPORTED_HSR_FEATURES (NETIF_F_HW_HSR_DUP | NETIF_F_HW_HSR_FWD) +/* The HSR ports are in no bridge, so DSA adds no static entry for the HSR + * MAC address on the CPU port. Let the CPU port learn it while HSR is + * offloaded, so that frames to that address are not flooded to the other + * ring port. + */ +static void ksz9477_hsr_cpu_learning(struct dsa_switch *ds, int port, + bool learning) +{ + struct ksz_device *dev = ds->priv; + struct ksz_port *p; + int cpu_port; + + cpu_port = dsa_upstream_port(ds, port); + p = &dev->ports[cpu_port]; + + p->learning = learning; + ksz_port_stp_state_set(ds, cpu_port, p->stp_state); + + /* Drop what the CPU port learned while HSR was offloaded */ + if (!learning) + ksz9477_flush_dyn_mac_table(ds, cpu_port); +} + static int ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr, struct netlink_ext_ack *extack) @@ -1937,6 +1953,17 @@ static int ksz9477_hsr_join(struct dsa_switch *ds, int port, return -EOPNOTSUPP; } + /* The CPU port learns while HSR is offloaded, so it would also learn + * the senders of frames that an offloaded bridge forwards in software. + */ + dsa_switch_for_each_user_port(hsr_dp, ds) { + if (dsa_port_bridge_dev_get(hsr_dp)) { + NL_SET_ERR_MSG_MOD(extack, + "HSR offload not supported while a bridge is offloaded - using software HSR"); + return -EOPNOTSUPP; + } + } + /* Self MAC address filtering, to avoid frames traversing * the HSR ring more than once. */ @@ -1963,6 +1990,8 @@ static int ksz9477_hsr_join(struct dsa_switch *ds, int port, data |= HSR_DUPLICATE_DISCARD; data &= ~HSR_NODE_UNICAST; ksz_write8(dev, REG_HSR_ALU_CTRL_0__1, data); + + ksz9477_hsr_cpu_learning(ds, port, true); } /* Enable per port self-address filtering. @@ -1998,8 +2027,10 @@ static int ksz9477_hsr_leave(struct dsa_switch *ds, int port, ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, PORT_SRC_ADDR_FILTER, false); dev->hsr_ports &= ~BIT(port); - if (!dev->hsr_ports) + if (!dev->hsr_ports) { dev->hsr_dev = NULL; + ksz9477_hsr_cpu_learning(ds, port, false); + } ksz_switch_macaddr_put(ds); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 78af51c182b91d4903c002b1b3f65be9599d19e2..86959d5ac16eb21fb7e1d984f6e65afc2a8593f6 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2798,6 +2798,15 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port, bool *tx_fwd_offload, struct netlink_ext_ack *extack) { + struct ksz_device *dev = ds->priv; + + /* See ksz9477_hsr_join() */ + if (dev->hsr_ports) { + NL_SET_ERR_MSG_MOD(extack, + "Bridge offload not supported while HSR is offloaded"); + return -EOPNOTSUPP; + } + /* port_stp_state_set() will be called after to put the port in * appropriate state so there is no need to do anything. */ diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index f0fb9498026120b3069b31d01bd0252be6f15403..6e95630f99008ea2c02fc4998a004a34d732b2dd 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,7 @@ 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. - */ - 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