summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-01-16 14:44:59 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-01-23 09:21:37 +0100
commit57e15d58cf6b29dd5fdf2bd217eccc9b39fdff58 (patch)
tree2e47cdfeacf30a52d035767a0db617d8bb7ef5e5
parente4bf61b0fa56e766d677ded495d8e3f37a2e0ba8 (diff)
downloadbarebox-57e15d58cf6b29dd5fdf2bd217eccc9b39fdff58.tar.gz
barebox-57e15d58cf6b29dd5fdf2bd217eccc9b39fdff58.tar.xz
net: dsa: add some helpers to ease porting kernel drivers
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@pengutronix.de> Link: https://lore.barebox.org/20230116134501.2006391-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/dsa.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/dsa.h b/include/dsa.h
index 3a170475cb..001c4899ba 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__ */