* [PATCH v1 1/3] net: dsa: Add global forwarding mode support
@ 2025-03-12 11:20 Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation Oleksij Rempel
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Oleksij Rempel @ 2025-03-12 11:20 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation
2025-03-12 11:20 [PATCH v1 1/3] net: dsa: Add global forwarding mode support Oleksij Rempel
@ 2025-03-12 11:20 ` Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 3/3] net: dsa: sja1105: Add support for global forwarding mode Oleksij Rempel
2025-03-14 16:13 ` [PATCH v1 1/3] net: dsa: Add global forwarding mode support Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2025-03-12 11:20 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
Add documentation for Distributed Switch Architecture (DSA) support in
Barebox. It introduces the `forwarding` parameter, which allows
configuring a DSA switch to operate in either isolated mode (default) or
forwarding mode.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
Documentation/user/networking.rst | 74 +++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index 2306cb6a60d1..71703f064bee 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -186,3 +186,77 @@ barebox:
The netconsole can be used just like any other console. Note, however, that the
simple console protocol is UDP based, so there is no guarantee about packet
loss.
+
+DSA (Distributed Switch Architecture) Support in Barebox
+--------------------------------------------------------
+
+Barebox includes support for DSA (Distributed Switch Architecture), allowing
+for basic configuration and management of network switches within the
+bootloader.
+
+DSA enables network devices to use a switch framework where each port of the
+switch is treated as a separate network interface, while still allowing packet
+forwarding between ports when enabled.
+
+DSA Configuration
+^^^^^^^^^^^^^^^^^
+
+DSA switches are managed through device parameters, similar to network
+interfaces. Each switch is identified as a separate device, typically named
+``switch0`` or ``switch@00`` depending on the bus address.
+
+Global Forwarding Control
+"""""""""""""""""""""""""
+
+A parameter, ``forwarding``, allows configuring whether a switch operates
+in **isolated mode** (default) or **forwarding mode**:
+
+- **Isolated Mode** (default): Each port is treated as an independent interface,
+ with no forwarding between ports.
+
+- **Forwarding Mode**: The switch allows forwarding of packets between ports,
+ acting as a traditional non-managed switch.
+
+To check the current DSA switch settings, use:
+
+.. code-block:: sh
+
+ barebox:/ devinfo switch0
+ Parameters:
+ forwarding: 0 (type: bool)
+
+To enable forwarding mode:
+
+.. code-block:: sh
+
+ dev.switch0.forwarding=1
+
+To disable forwarding and revert to isolated mode:
+
+.. code-block:: sh
+
+ dev.switch0.forwarding=0
+
+Persisting Configuration
+""""""""""""""""""""""""
+
+To ensure that the forwarding mode setting persists across reboots,
+it can be stored as a nonvolatile (nv) variable:
+
+.. code-block:: sh
+
+ nv dev.switch0.forwarding=1
+
+This will configure the switch to always boot in forwarding mode.
+
+Integration with Network Interfaces
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Each port of the DSA switch is exposed as an independent network interface in
+Barebox. However, when forwarding is enabled, packets can be forwarded between
+these interfaces without requiring intervention from the CPU.
+
+To configure network settings for individual ports, use standard network
+configuration variables (e.g., ``eth0.ipaddr``, ``eth0.mode``, etc.). These
+settings are applied per port and are independent of the global switch
+forwarding configuration.
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1 3/3] net: dsa: sja1105: Add support for global forwarding mode
2025-03-12 11:20 [PATCH v1 1/3] net: dsa: Add global forwarding mode support Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation Oleksij Rempel
@ 2025-03-12 11:20 ` Oleksij Rempel
2025-03-14 16:13 ` [PATCH v1 1/3] net: dsa: Add global forwarding mode support Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2025-03-12 11:20 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
Add support for global forwarding mode in the SJA1105 DSA driver,
allowing dynamic control over whether the switch forwards traffic
between all ports or restricts communication to only CPU-port
connections.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/sja1105.c | 77 +++++++++++++++++++++++++++++++++----------
1 file changed, 59 insertions(+), 18 deletions(-)
diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index 4ef30b8c81f1..aaf9237dc19d 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -1230,11 +1230,13 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv)
return 0;
}
-static void sja1105_setup_tagging(struct sja1105_private *priv, int port)
+static void sja1105_setup_tagging(struct sja1105_private *priv, int port,
+ bool forward_all)
{
struct sja1105_vlan_lookup_entry *vlan;
struct dsa_switch *ds = &priv->ds;
int cpu = ds->cpu_port;
+ u8 vlan_mask;
/* The CPU port is implicitly configured by
* configuring the front-panel ports
@@ -1246,8 +1248,16 @@ static void sja1105_setup_tagging(struct sja1105_private *priv, int port)
priv->pvid[port] = DSA_8021Q_DIR_TX | DSA_8021Q_PORT(port);
- vlan[port].vmemb_port = BIT(port) | BIT(cpu);
- vlan[port].vlan_bc = BIT(port) | BIT(cpu);
+ if (forward_all) {
+ /* All ports in the same VLAN */
+ vlan_mask = (1 << ds->num_ports) - 1;
+ } else {
+ /* Only allow port ↔ CPU communication */
+ vlan_mask = BIT(port) | BIT(cpu);
+ }
+
+ vlan[port].vmemb_port = vlan_mask;
+ vlan[port].vlan_bc = vlan_mask;
vlan[port].tag_port = BIT(cpu);
vlan[port].vlanid = priv->pvid[port];
vlan[port].type_entry = SJA1110_VLAN_D_TAG;
@@ -1269,7 +1279,7 @@ static int sja1105_init_vlan(struct sja1105_private *priv)
table->entry_count = ds->num_ports;
for (port = 0; port < ds->num_ports; port++)
- sja1105_setup_tagging(priv, port);
+ sja1105_setup_tagging(priv, port, false);
return 0;
}
@@ -1283,33 +1293,47 @@ sja1105_port_allow_traffic(struct sja1105_l2_forwarding_entry *l2_fwd,
l2_fwd[from].fl_domain |= BIT(to);
}
-static int sja1105_init_l2_forwarding(struct sja1105_private *priv)
+static int sja1105_init_l2_forwarding(struct sja1105_private *priv,
+ bool forward_all)
{
struct sja1105_l2_forwarding_entry *l2fwd;
struct dsa_switch *ds = &priv->ds;
struct sja1105_table *table;
int cpu = ds->cpu_port;
- int i;
+ int i, j;
table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING];
- table->entries = calloc(SJA1105_MAX_L2_FORWARDING_COUNT,
- table->ops->unpacked_entry_size);
- if (!table->entries)
- return -ENOMEM;
+ if (!table->entries) {
+ table->entries = calloc(SJA1105_MAX_L2_FORWARDING_COUNT,
+ table->ops->unpacked_entry_size);
+ if (!table->entries)
+ return -ENOMEM;
+ }
table->entry_count = SJA1105_MAX_L2_FORWARDING_COUNT;
l2fwd = table->entries;
- /* First 5 entries define the forwarding rules */
- for (i = 0; i < ds->num_ports; i++) {
- if (i == cpu)
- continue;
-
- sja1105_port_allow_traffic(l2fwd, i, cpu);
- sja1105_port_allow_traffic(l2fwd, cpu, i);
+ if (forward_all) {
+ /* Forwarding mode: All ports can talk to each other */
+ for (i = 0; i < ds->num_ports; i++) {
+ for (j = 0; j < ds->num_ports; j++) {
+ if (i == j)
+ continue;
+ sja1105_port_allow_traffic(l2fwd, i, j);
+ }
+ }
+ } else {
+ /* Default mode: Each port only forwards to/from the CPU */
+ for (i = 0; i < ds->num_ports; i++) {
+ if (i == cpu)
+ continue;
+ sja1105_port_allow_traffic(l2fwd, i, cpu);
+ sja1105_port_allow_traffic(l2fwd, cpu, i);
+ }
}
+
/* Next 8 entries define VLAN PCP mapping from ingress to egress.
* Leave them unpopulated (implicitly 0) but present.
*/
@@ -1490,7 +1514,7 @@ static int sja1105_static_config_init(struct sja1105_private *priv)
rc = sja1105_init_mii_settings(priv);
if (rc < 0)
return rc;
- rc = sja1105_init_l2_forwarding(priv);
+ rc = sja1105_init_l2_forwarding(priv, false);
if (rc < 0)
return rc;
rc = sja1105_init_l2_forwarding_params(priv);
@@ -2866,12 +2890,29 @@ static int sja1105_cpu_port_enable(struct dsa_port *dp, int port,
return sja1105_static_config_reload(priv);
}
+static int sja1105_set_forwarding(struct dsa_switch *ds, bool enable)
+{
+ struct device *dev = ds->dev;
+ struct sja1105_private *priv = dev_get_priv(dev);
+ int port, ret;
+
+ for (port = 0; port < ds->num_ports; port++)
+ sja1105_setup_tagging(priv, port, enable);
+
+ ret = sja1105_init_l2_forwarding(priv, enable);
+ if (ret)
+ return ret;
+
+ return sja1105_static_config_reload(priv);
+}
+
static const struct dsa_switch_ops sja1105_dsa_ops = {
.port_pre_enable = sja1105_port_pre_enable,
.port_enable = sja1105_cpu_port_enable,
.adjust_link = sja1105_adjust_link,
.xmit = sja1105_xmit,
.rcv = sja1105_rcv,
+ .set_forwarding = sja1105_set_forwarding,
};
static int sja1105_init(struct sja1105_private *priv)
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/3] net: dsa: Add global forwarding mode support
2025-03-12 11:20 [PATCH v1 1/3] net: dsa: Add global forwarding mode support Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 3/3] net: dsa: sja1105: Add support for global forwarding mode Oleksij Rempel
@ 2025-03-14 16:13 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-03-14 16:13 UTC (permalink / raw)
To: barebox, Oleksij Rempel
On Wed, 12 Mar 2025 12:20:55 +0100, Oleksij Rempel wrote:
> 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)
>
> [...]
Applied, thanks!
[1/3] net: dsa: Add global forwarding mode support
https://git.pengutronix.de/cgit/barebox/commit/?id=e49028e88017 (link may not be stable)
[2/3] Documentation: networking: Add DSA switch support documentation
https://git.pengutronix.de/cgit/barebox/commit/?id=861b6fcd7943 (link may not be stable)
[3/3] net: dsa: sja1105: Add support for global forwarding mode
https://git.pengutronix.de/cgit/barebox/commit/?id=816fb00dbf28 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-14 16:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-12 11:20 [PATCH v1 1/3] net: dsa: Add global forwarding mode support Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation Oleksij Rempel
2025-03-12 11:20 ` [PATCH v1 3/3] net: dsa: sja1105: Add support for global forwarding mode Oleksij Rempel
2025-03-14 16:13 ` [PATCH v1 1/3] net: dsa: Add global forwarding mode support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox