Introduce a dsa_to_master helper to find the master interface dedicated
to a given switch port.

Signed-off-by: Vivien Didelot <vivien.dide...@gmail.com>
---
 include/net/dsa.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index c5b45bfeea01..b0be2687bd61 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -356,6 +356,19 @@ static inline bool dsa_is_upstream_port(struct dsa_switch 
*ds, int port)
        return dsa_upstream_port(ds, port) == port;
 }
 
+static inline struct net_device *dsa_to_master(struct dsa_switch *ds, int port)
+{
+       const struct dsa_port *dp = dsa_to_port(ds, port);
+
+       if (dp->type == DSA_PORT_TYPE_CPU)
+               return dp->master;
+
+       if (dp->cpu_dp)
+               return dp->cpu_dp->master;
+
+       return NULL;
+}
+
 static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
 {
        const struct dsa_switch *ds = dp->ds;
-- 
2.21.0

Reply via email to