[PATCH 7/9] net: dsa: add some helpers to ease porting kernel drivers

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jan 16 05:44:59 PST 2023


These make port of the realtek driver in a follow-up commit a bit more
similar to the Linux driver.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/dsa.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/dsa.h b/include/dsa.h
index 3a170475cbb8..001c4899ba41 100644
--- a/include/dsa.h
+++ b/include/dsa.h
@@ -84,7 +84,23 @@ struct dsa_switch {
 	u32 phys_mii_mask;
 };
 
+static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
+{
+	if (p >= DSA_MAX_PORTS)
+		return NULL;
+
+	return ds->dp[p];
+}
+
 int dsa_register_switch(struct dsa_switch *ds);
 u32 dsa_user_ports(struct dsa_switch *ds);
 
+#define dsa_switch_for_each_cpu_port(_dp, _dst) \
+	for (_dp = _dst->dp[_dst->cpu_port]; _dp; _dp = NULL)
+
+static inline bool dsa_port_is_cpu(struct dsa_port *port)
+{
+	return port->index == port->ds->cpu_port;
+}
+
 #endif /* __DSA_H__ */
-- 
2.30.2




More information about the barebox mailing list