[PATCH net-next v6 2/4] net: dsa: add bridge member iteration macro and port mask helper

From: Daniel Golle

Date: Sat Mar 21 2026 - 20:21:24 EST


Drivers that offload bridges need to iterate over the ports that are
members of a given bridge, for example to rebuild per-port forwarding
bitmaps when membership changes. Currently each driver must open-code
this by combining dsa_switch_for_each_user_port() with a
dsa_port_offloads_bridge() check, or cache bridge membership within
the driver.

Add dsa_bridge_for_each_member() to express this pattern directly, and
a dsa_bridge_ports() helper that returns a bitmask of member ports,
matching the existing dsa_user_ports() and dsa_cpu_ports() helpers.

Signed-off-by: Daniel Golle <daniel@xxxxxxxxxxxxxx>
---
v6: new patch

include/net/dsa.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 1c6f6c3b88e86..4f43d518f3de3 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -838,6 +838,22 @@ static inline bool dsa_port_tree_same(const struct dsa_port *a,
return a->ds->dst == b->ds->dst;
}

+#define dsa_bridge_for_each_member(_dp, _ds, _bridge) \
+ dsa_switch_for_each_user_port((_dp), (_ds)) \
+ if (dsa_port_offloads_bridge((_dp), (_bridge)))
+
+static inline u32 dsa_bridge_ports(struct dsa_switch *ds,
+ const struct dsa_bridge *bridge)
+{
+ struct dsa_port *dp;
+ u32 mask = 0;
+
+ dsa_bridge_for_each_member(dp, ds, bridge)
+ mask |= BIT(dp->index);
+
+ return mask;
+}
+
typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
bool is_static, void *data);
struct dsa_switch_ops {
--
2.53.0