[PATCH net-next 11/12] net: dsa: Add helper to find ds_switch by index
From: Luke Howard
Date: Fri Jul 03 2026 - 03:35:37 EST
From: Andrew Lunn <andrew@xxxxxxx>
The DSA header for an RMU frame includes the switch index to indicate
which switch sent the RMU frame. Add a helper which walks the list of
ports and finds the corresponding switch. Since this is not the hot
path for data frames, the overhead of multiple ports per switch is not
considered a problem.
Signed-off-by: Andrew Lunn <andrew@xxxxxxx>
---
net/dsa/tag.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index cf52283fe9df4..c21d746652601 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -44,6 +44,20 @@ static inline struct net_device *dsa_conduit_find_user(struct net_device *dev,
return NULL;
}
+static inline struct dsa_switch *dsa_conduit_find_switch(struct net_device *dev,
+ int device)
+{
+ struct dsa_port *cpu_dp = dev->dsa_ptr;
+ struct dsa_switch_tree *dst = cpu_dp->dst;
+ struct dsa_port *dp;
+
+ list_for_each_entry(dp, &dst->ports, list)
+ if (dp->ds->index == device)
+ return dp->ds;
+
+ return NULL;
+}
+
/**
* dsa_software_untag_vlan_aware_bridge: Software untagging for VLAN-aware bridge
* @skb: Pointer to received socket buffer (packet)
--
2.43.0