[PATCH net-next 3/6] net: dsa: motorcomm: Add BR_FLOOD and BR_MCAST_FLOOD support

From: David Yang

Date: Mon Nov 02 2026 - 12:12:00 EST


Let the hardware flood the unknown unicast / multicast if all other
ports in the bridge have BR_FLOOD / BR_MCAST_FLOOD enabled.

Signed-off-by: David Yang <mmyangfl@xxxxxxxxx>
---
drivers/net/dsa/motorcomm/chip.c | 173 ++++++++++++++++++++++++-------
drivers/net/dsa/motorcomm/chip.h | 4 +
2 files changed, 138 insertions(+), 39 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index fb993cc9607c..907f7a5b0687 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1160,6 +1160,7 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,

static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
{
+ struct yt921x_port *pp = &priv->ports[port];
u32 mask;
u32 ctrl;
int res;
@@ -1190,6 +1191,17 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
if (res)
return res;

+ mask = BIT(port);
+ res = yt921x_reg_clear_bits(priv, YT921X_FILTER_UNK_UCAST, mask);
+ if (res)
+ return res;
+ res = yt921x_reg_clear_bits(priv, YT921X_FILTER_UNK_MCAST, mask);
+ if (res)
+ return res;
+
+ pp->flood = true;
+ pp->mcast_flood = true;
+
return 0;
}

@@ -1225,6 +1237,20 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
return 0;
}

+static u16 yt921x_port_dest(struct yt921x_priv *priv, int port)
+{
+ struct dsa_switch *ds = &priv->ds;
+ struct net_device *bdev;
+ struct dsa_port *dp;
+
+ dp = dsa_to_port(ds, port);
+ bdev = dsa_port_bridge_dev_get(dp);
+ if (!bdev)
+ return 0;
+
+ return dsa_bridge_ports(ds, bdev) | priv->cpu_ports_mask;
+}
+
/* Make sure to include the CPU port in ports_mask, or your bridge will
* not have it.
*/
@@ -1268,6 +1294,63 @@ static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
return 0;
}

+static int
+yt921x_bridge_flood_set_type(struct yt921x_priv *priv, u16 ports_mask, int type)
+{
+ unsigned long targets_mask;
+ u16 flood_ports_xor;
+ u32 filter_ctrl;
+ u16 flood_mask;
+ u32 addr;
+ int port;
+ int res;
+
+ ports_mask &= ~priv->cpu_ports_mask;
+
+ flood_mask = 0;
+ targets_mask = ports_mask;
+ for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
+ struct yt921x_port *pp = &priv->ports[port];
+
+ if (!type ? pp->flood : pp->mcast_flood)
+ flood_mask |= BIT(port);
+ }
+
+ flood_ports_xor = flood_mask ^ ports_mask;
+ filter_ctrl = 0;
+ targets_mask = ports_mask;
+ for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
+ if (!(flood_ports_xor & ~BIT(port)))
+ continue;
+
+ filter_ctrl |= BIT(port);
+ }
+
+ addr = !type ? YT921X_FILTER_UNK_UCAST : YT921X_FILTER_UNK_MCAST;
+ res = yt921x_reg_update_bits(priv, addr, ports_mask, filter_ctrl);
+ if (res)
+ return res;
+
+ /* ACT_UNK is TRAP everywhere but the CPU port, which DROPs; see
+ * yt921x_chip_setup_dsa()
+ */
+
+ return 0;
+}
+
+static int yt921x_bridge_flood_set(struct yt921x_priv *priv, u16 ports_mask)
+{
+ int res;
+
+ for (int type = 0; type < 2; type++) {
+ res = yt921x_bridge_flood_set_type(priv, ports_mask, type);
+ if (res)
+ return res;
+ }
+
+ return 0;
+}
+
static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
{
int res;
@@ -1280,14 +1363,24 @@ static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
if (res)
return res;

+ /* By the time port_bridge_leave() is called, the port is already
+ * unbridged, thus we cannot recompute flood flags for the affected
+ * bridge. This leaves some sub-optimality, but the flood will still
+ * be handled (by the CPU).
+ */
+
return 0;
}

-static int
-yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
+static int yt921x_bridge_join(struct yt921x_priv *priv, int port)
{
+ u16 ports_mask;
int res;

+ ports_mask = yt921x_port_dest(priv, port);
+ if (!ports_mask)
+ return 0;
+
res = yt921x_userport_bridge(priv, port);
if (res)
return res;
@@ -1296,6 +1389,10 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
if (res)
return res;

+ res = yt921x_bridge_flood_set(priv, ports_mask);
+ if (res)
+ return res;
+
return 0;
}

@@ -1304,7 +1401,9 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
struct switchdev_brport_flags flags)
{
struct yt921x_port *pp = &priv->ports[port];
- bool do_flush;
+ bool change_isolated;
+ bool change_flood;
+ u32 ports_mask;
u32 mask;
int res;

@@ -1318,36 +1417,44 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
return res;
}

- /* BR_FLOOD, BR_MCAST_FLOOD: see the comment where ACT_UNK_ACTn_TRAP
- * is set
- */
-
/* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */

- do_flush = false;
+ change_isolated = false;
if (flags.mask & BR_HAIRPIN_MODE) {
pp->hairpin = flags.val & BR_HAIRPIN_MODE;
- do_flush = true;
+ change_isolated = true;
}
if (flags.mask & BR_ISOLATED) {
pp->isolated = flags.val & BR_ISOLATED;
- do_flush = true;
+ change_isolated = true;
}
- if (do_flush) {
- struct dsa_switch *ds = &priv->ds;
- struct dsa_port *dp = dsa_to_port(ds, port);
- struct net_device *bdev;

- bdev = dsa_port_bridge_dev_get(dp);
- if (bdev) {
- u32 ports_mask;
+ change_flood = false;
+ if (flags.mask & BR_FLOOD) {
+ pp->flood = flags.val & BR_FLOOD;
+ change_flood = true;
+ }
+ if (flags.mask & BR_MCAST_FLOOD) {
+ pp->mcast_flood = flags.val & BR_MCAST_FLOOD;
+ change_flood = true;
+ }

- ports_mask = dsa_bridge_ports(ds, bdev);
- ports_mask |= priv->cpu_ports_mask;
- res = yt921x_bridge(priv, ports_mask);
- if (res)
- return res;
- }
+ if (!change_isolated && !change_flood)
+ return 0;
+
+ ports_mask = yt921x_port_dest(priv, port);
+ if (!ports_mask)
+ return 0;
+
+ if (change_isolated) {
+ res = yt921x_bridge(priv, ports_mask);
+ if (res)
+ return res;
+ }
+ if (change_flood) {
+ res = yt921x_bridge_flood_set(priv, ports_mask);
+ if (res)
+ return res;
}

return 0;
@@ -1408,17 +1515,13 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
struct netlink_ext_ack *extack)
{
struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
- u16 ports_mask;
int res;

if (dsa_is_cpu_port(ds, port))
return 0;

- ports_mask = dsa_bridge_ports(ds, bridge.dev);
- ports_mask |= priv->cpu_ports_mask;
-
mutex_lock(&priv->reg_lock);
- res = yt921x_bridge_join(priv, port, ports_mask);
+ res = yt921x_bridge_join(priv, port);
mutex_unlock(&priv->reg_lock);

return res;
@@ -2275,14 +2378,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
if (res)
return res;

- ctrl = GENMASK(10, 0) & ~priv->cpu_ports_mask;
- res = yt921x_reg_write(priv, YT921X_FILTER_UNK_UCAST, ctrl);
- if (res)
- return res;
- res = yt921x_reg_write(priv, YT921X_FILTER_UNK_MCAST, ctrl);
- if (res)
- return res;
-
/* YT921x does not support native DSA port bridging, so we use port
* isolation to emulate it. However, be especially careful that port
* isolation takes _after_ FDB lookups, i.e. if an FDB entry (from
@@ -2291,9 +2386,9 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
* the "bridged" ports, thus we need to trap and handle those packets by
* software.
*
- * If there is no more than one bridge, we might be able to drop them
- * directly given some conditions are met, but we trap them in all cases
- * for now.
+ * In some cases, we may offload the flood action to the hardware. This
+ * is done by fixing UNK_ACT to TRAP, and toggling the FILTER_UNK on the
+ * appropriate ports.
*/
ctrl = 0;
for (int i = 0; i < YT921X_PORT_NUM; i++)
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index fc315f1d8f87..842fd8f83903 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -461,6 +461,10 @@ struct yt921x_port {
bool hairpin:1;
/* BR_ISOLATED */
bool isolated:1;
+ /* BR_FLOOD */
+ bool flood:1;
+ /* BR_MCAST_FLOOD */
+ bool mcast_flood:1;

unsigned short acl_cnt;

--
2.53.0