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