[PATCH v1 1/3] net: dsa: Add global forwarding mode support
Oleksij Rempel
o.rempel at pengutronix.de
Wed Mar 12 04:20:55 PDT 2025
This patch introduces a global forwarding mode control for DSA switches
in Barebox. It adds a new `forwarding` parameter that allows enabling
or disabling forwarding between all ports on a DSA switch.
This enables users to configure global forwarding dynamically via:
dev.switch0.forwarding=1 # Enable forwarding
dev.switch0.forwarding=0 # Disable forwarding (isolated mode)
Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
drivers/net/dsa.c | 12 ++++++++++++
include/dsa.h | 4 ++++
2 files changed, 16 insertions(+)
diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
index a451a1a35e8b..537e9dd72ac6 100644
--- a/drivers/net/dsa.c
+++ b/drivers/net/dsa.c
@@ -4,6 +4,7 @@
#include <dma.h>
#include <dsa.h>
#include <of_net.h>
+#include <param.h>
u32 dsa_user_ports(struct dsa_switch *ds)
{
@@ -431,6 +432,13 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
return ret;
}
+static int dsa_set_forwarding(struct param_d *p, void *priv)
+{
+ struct dsa_switch *ds = priv;
+
+ return ds->ops->set_forwarding(ds, ds->forwarding_enable);
+}
+
int dsa_register_switch(struct dsa_switch *ds)
{
int ret;
@@ -448,6 +456,10 @@ int dsa_register_switch(struct dsa_switch *ds)
return -EINVAL;
}
+ if (ds->ops->set_forwarding)
+ dev_add_param_bool(ds->dev, "forwarding", dsa_set_forwarding,
+ NULL, &ds->forwarding_enable, ds);
+
ret = dsa_switch_parse_ports_of(ds, ds->dev->of_node);
if (ret)
return ret;
diff --git a/include/dsa.h b/include/dsa.h
index 527941c26949..ecf7c4f429f3 100644
--- a/include/dsa.h
+++ b/include/dsa.h
@@ -56,6 +56,9 @@ struct dsa_switch_ops {
int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val);
void (*adjust_link)(struct eth_device *dev);
+
+ /* enable/disable forwarding between all ports on the switch */
+ int (*set_forwarding)(struct dsa_switch *ds, bool enable);
};
struct dsa_port {
@@ -84,6 +87,7 @@ struct dsa_switch {
struct mii_bus *slave_mii_bus;
u32 phys_mii_mask;
void *priv;
+ u32 forwarding_enable;
};
static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
--
2.39.5
More information about the barebox
mailing list