Skip to contentSkip to conversation

Introduce DSA Ethernet switch class and Felix driver

PATCH New Vladimir Oltean 1 participant 11 messages Feb 16, 2021

Subsystems (5)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

v5 cover Introduce DSA Ethernet switch class and Felix driver

From: Vladimir Oltean <[email protected]>

DSA stands for Distributed Switch Architecture and it is a subsystem introduced in the Linux kernel to support switches that:
- have an Ethernet link up to the CPU
- use some form of tagging to identify the source/destination port for Rx/Tx
- may be cascaded in tree-like structures.

DSA is described in depth here:
https://www.kernel.org/doc/Documentation/networking/dsa/dsa.txt

This patch set introduces a DSA class in U-Boot to support drivers of DSA switches. DSA drivers have to implement the following ops:
- enable/disable of switch ports,
- insert a tag in frames being transmitted, used by the switch to select the egress port,
- parse a tag in frames being received, used for Rx traffic.

DSA class code deals with presentation of switch ports as Ethernet interfaces, deals with the master Ethernet device for I/O and helps with parsing of the DT assuming the structure follows the DSA kernel binding.

Support for switch cascading is not included yet.

In the sandbox environment, the DSA sandbox driver, the switch ports and master eth interface look like this:
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------
[...]

 eth           4  [ + ]   eth_sandbox           |-- dsa-test-eth
 dsa           0  [ + ]   dsa_sandbox           |-- dsa-test
 eth           5  [ + ]   dsa-port              |   |-- lan0
 eth           6  [ + ]   dsa-port              |   `-- lan1

=> setenv ethact lan1
=> ping 1.2.3.5
Using lan1 device
host 1.2.3.5 is alive
=>

This patch set also introduces a driver for the Ethernet switch integrated into NXP LS1028A, called Felix. The switch has 4 front panel ports, I/O to/from it is done though an ENETC Ethernet interface and meta-data is carried between the switch and the driver though an additional header pre-pended to the original frame.
Network commands like tftp can be used on these front panel ports. The ports are disabled unless used so they do not cause issues on network topologies that include loops.

Felix as seen on LS1028A RDB:
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------
[...]

 dsa           0  [ + ]   felix-switch          |   |-- felix-switch
 eth           4  [ + ]   dsa-port              |   |   |-- swp0
 eth           5  [ + ]   dsa-port              |   |   |-- swp1
 eth           6  [ + ]   dsa-port              |   |   |-- swp2
 eth           7  [ + ]   dsa-port              |   |   `-- swp3

=> mdio list
[...]
10 - Vitesse VSC8514 <--> swp0
11 - Vitesse VSC8514 <--> swp1
12 - Vitesse VSC8514 <--> swp2
13 - Vitesse VSC8514 <--> swp3

NOTE:
This patchset is a major rework of the dsa-class code since the last
submission from May 5th:
https://patchwork.ozlabs.org/project/uboot/cover/1588700588-8587-1-git-send-email-claudiu.manoil at nxp.com/ The basic concepts and data path operation (tagging) in the DSA class
code remain the same as in the initial patchset from Alex, however the
external API has been changed significantly (simplified), the driver
model integration has been improved to the point that the DSA class
code no longer needs to allocate extra memory internally (via malloc),
reduced memory footprint, internal state data moved from the external
API and internalized, cleaner external API, internal code reworked,
completely reworked DSA sandbox driver and unit tests for better coverage
and to integrate better with the eth sandbox driver and tests, etc.

v5:
Fix the DSA driver not probing in the sandbox, and the net_retry test failing due to that:
- Made PHY_FIXED work with live OF.
- Made DSA user ports [ not just CPU ports as before ], and any other callers of dm_eth_phy_connect, work with fixed-link.

v4:
- Implemented the TODO for having a phy_device on the CPU port.
- Enabled CONFIG_PHY_FIXED which is a new dependency of CONFIG_DM_DSA.

v3:
- Removed all infrastructure associated with dsa_foreach_port, which is no longer needed.
- Only inherit the DSA master's MAC address if the environment does not already have a specific MAC address that should be used for the DSA port.
- Be compatible with the new "ethernet-ports" container name which has been introduced in the Linux kernel as commit 85e05d263ed2 ("net: dsa:
of: Allow ethernet-ports as encapsulating node") in v5.9.
- Fixed the felix driver not getting its ports initialized, due to dsa_foreach_port() being actually unusable when called from the probe function of the DSA udevice - the eth port udevices are _not_ yet probed at that point. We are now initializing all ports from the .port_enable() callback of each eth udevice.
- Deleted the unit tests associated with the infrastructure for dsa_foreach_port, since that function no longer exists.
- Enabled the config options for the Kontron LS1028A board too.

v2: Switch node structure defined in dtsi now consistent with the Linux switch node definition. Moved aliases from dtsi to the RDB dts to minimize impact on other boards (and for improved flexibility).

Alex Marginean (3):
drivers: net: add Felix DSA switch driver
arm: dts: ls1028a: add Ethernet switch node and dependencies
configs: ls1028a: enable the Ethernet switch driver

Claudiu Manoil (2):
net: introduce DSA class for Ethernet switches
sandbox: add a DSA sandbox driver and unit test

Vladimir Oltean (4):
net: phy: fixed: be compatible with live OF tree
net: phy: fixed: support speeds of 2500 and 10000
net: phy: introduce fixed_phy_create for DSA CPU ports
net: mdio: teach dm_eth_connect_phy_handle to connect to fixed PHY

 arch/Kconfig                                 |   2 +
 arch/arm/dts/fsl-ls1028a-rdb.dts             |  64 +++
 arch/arm/dts/fsl-ls1028a.dtsi                |  55 ++-
 arch/sandbox/dts/test.dts                    |  48 ++
 configs/kontron_sl28_defconfig               |   3 +
 configs/ls1028aqds_tfa_SECURE_BOOT_defconfig |   3 +
 configs/ls1028aqds_tfa_defconfig             |   3 +
 configs/ls1028ardb_tfa_SECURE_BOOT_defconfig |   3 +
 configs/ls1028ardb_tfa_defconfig             |   3 +
 drivers/net/Kconfig                          |  24 +
 drivers/net/Makefile                         |   1 +
 drivers/net/dsa_sandbox.c                    | 179 +++++++
 drivers/net/fsl_enetc.h                      |   5 +
 drivers/net/mscc_eswitch/Kconfig             |   8 +
 drivers/net/mscc_eswitch/Makefile            |   1 +
 drivers/net/mscc_eswitch/felix_switch.c      | 414 ++++++++++++++++
 drivers/net/phy/fixed.c                      |  34 +-
 drivers/net/phy/phy.c                        |  59 ++-
 include/configs/sandbox.h                    |   2 +
 include/dm/uclass-id.h                       |   1 +
 include/net.h                                |   6 +
 include/net/dsa.h                            | 165 +++++++
 include/phy.h                                |  21 +
 net/Makefile                                 |   1 +
 net/dsa-uclass.c                             | 478 +++++++++++++++++++
 net/mdio-uclass.c                            |  12 +-
 test/dm/Makefile                             |   1 +
 test/dm/dsa.c                                |  82 ++++
 test/dm/eth.c                                |  10 +-
 29 files changed, 1660 insertions(+), 28 deletions(-)
 create mode 100644 drivers/net/dsa_sandbox.c
 create mode 100644 drivers/net/mscc_eswitch/felix_switch.c
 create mode 100644 include/net/dsa.h
 create mode 100644 net/dsa-uclass.c
 create mode 100644 test/dm/dsa.c
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v5 1/9 net: phy: fixed: be compatible with live OF tree

From: Vladimir Oltean <[email protected]>

On systems that use CONFIG_OF_LIVE, the "ofnode" type is defined as const struct device_node *np, while on the flat DT systems it is defined as a long of_offset into gd->fdt_blob.

It is desirable that the fixed PHY driver uses the higher-level ofnode abstraction instead of parsing gd->fdt_blob directly, because that enables it to work on live OF systems.

The fixed PHY driver has used a nastyyyyy hack since its introduction in commit db40c1aa1c10 ("drivers/net/phy: add fixed-phy / fixed-link support"), which is to pass the long gd->fdt_blob offset inside int phydev->addr (a value that normally holds the MDIO bus address at which the PHY responds). Even ignoring the fact that the types were already mismatched leading to a potential truncation (flat OF offset was supposed to be a long and not an int), we really cannot extend this hack any longer, because there's no way an int will hold the other representation of ofnode, the struct device_node *np.

So we unfortunately need to do the right thing, which is to use the framework introduced by Grygorii Strashko in commit eef0b8a930d1 ("net:
phy: add ofnode node to struct phy_device"). This will populate phydev->node for the fixed PHY.

Note that phydev->node will not be valid in the probe function, since that is called synchronously from phy_device_create and we really have no way of passing the ofnode directly through the phy_device_create API. So we do what other drivers do too: we move the OF parsing logic from the .probe to the .config method of the PHY driver.

---
Changes in v5:
Patch is new.

 drivers/net/phy/fixed.c | 31 ++++++++++++++++++++++---------
 drivers/net/phy/phy.c   | 24 ++++++++++++++----------
 2 files changed, 36 insertions(+), 19 deletions(-)
drivers/net/phy/fixed.c +22 -9
index 3228672fc4ae..d117a50719a2 100644
@@ -15,15 +15,16 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-int fixedphy_probe(struct phy_device *phydev)
+static int fixedphy_of_init(struct phy_device *phydev)
 {
+	ofnode node = phy_get_ofnode(phydev);
 	struct fixed_link *priv;
-	int ofnode = phydev->addr;
 	u32 val;
 
-	/* check for mandatory properties within fixed-link node */
-	val = fdt_getprop_u32_default_node(gd->fdt_blob,
-					   ofnode, 0, "speed", 0);
+	if (!ofnode_valid(node))
+		return -EINVAL;
+
+	val = ofnode_read_u32_default(node, "speed", 0);
 	if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000) {
 		printf("ERROR: no/invalid speed given in fixed-link node!");
 		return -EINVAL;
@@ -32,14 +33,26 @@ int fixedphy_probe(struct phy_device *phydev)
 	priv = malloc(sizeof(*priv));
 	if (!priv)
 		return -ENOMEM;
+
 	memset(priv, 0, sizeof(*priv));
 
 	phydev->priv = priv;
 
 	priv->link_speed = val;
-	priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex");
-	priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause");
-	priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause");
+	priv->duplex = ofnode_read_bool(node, "full-duplex");
+	priv->pause = ofnode_read_bool(node, "pause");
+	priv->asym_pause = ofnode_read_bool(node, "asym-pause");
+
+	return 0;
+}
+
+static int fixedphy_config(struct phy_device *phydev)
+{
+	int err;
+
+	err = fixedphy_of_init(phydev);
+	if (err)
+		return err;
 
 	/* fixed-link phy must not be reset by core phy code */
 	phydev->flags |= PHY_FLAG_BROKEN_RESET;
@@ -70,7 +83,7 @@ static struct phy_driver fixedphy_driver = {
 	.mask		= 0xffffffff,
 	.name		= "Fixed PHY",
 	.features	= PHY_GBIT_FEATURES | SUPPORTED_MII,
-	.probe		= fixedphy_probe,
+	.config		= fixedphy_config,
 	.startup	= fixedphy_startup,
 	.shutdown	= fixedphy_shutdown,
 };
drivers/net/phy/phy.c +14 -10
index a2be3987364c..e88c93c4180d 100644
@@ -987,19 +987,23 @@ static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
 					    phy_interface_t interface)
 #endif
 {
+	ofnode node = dev_ofnode(dev), subnode;
 	struct phy_device *phydev = NULL;
-	int sn;
 	const char *name;
 
-	sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
-	while (sn > 0) {
-		name = fdt_get_name(gd->fdt_blob, sn, NULL);
-		if (name && strcmp(name, "fixed-link") == 0) {
-			phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false,
-						   interface);
-			break;
-		}
-		sn = fdt_next_subnode(gd->fdt_blob, sn);
+	for (subnode = ofnode_first_subnode(node); ofnode_valid(subnode);
+	     subnode = ofnode_next_subnode(node)) {
+		name = ofnode_get_name(subnode);
+
+		if (!name || strcmp(name, "fixed-link") != 0)
+			continue;
+
+		phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false,
+					   interface);
+		if (phydev)
+			phydev->node = subnode;
+
+		break;
 	}
 
 	return phydev;
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v5 2/9 net: phy: fixed: support speeds of 2500 and 10000

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

Unlike the Linux fixed PHY driver, the one in U-Boot does not attempt to emulate the clause 22 register set of a gigabit copper PHY driver through the swphy framework. Therefore, the limitation of being unable to support speeds higher than gigabit in fixed-link does not apply to the U-Boot fixed PHY driver. This makes the fixed-link U-Boot implementation more similar to the one from phylink, which can work with any valid link speed.

---
Changes in v5:
None.

Changes in v4:
Patch is new.

 drivers/net/phy/fixed.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/fixed.c +2 -1
index d117a50719a2..ae6b44bec81c 100644
@@ -25,7 +25,8 @@ static int fixedphy_of_init(struct phy_device *phydev)
 		return -EINVAL;
 
 	val = ofnode_read_u32_default(node, "speed", 0);
-	if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000) {
+	if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 &&
+	    val != SPEED_2500 && val != SPEED_10000) {
 		printf("ERROR: no/invalid speed given in fixed-link node!");
 		return -EINVAL;
 	}
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH v5 3/9 net: phy: introduce fixed_phy_create for DSA CPU ports

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

The DSA (Distributed Switch Architecture) implementation has made a design decision when it got introduced to the Linux kernel in 2008. That was to hide away from the user the CPU-facing Ethernet MAC, since it does not make sense to register it as a struct net_device (UCLASS_ETH udevice for U-Boot), because that would never be beneficial for a user:
they would not be able to use it for traffic, since conceptually, a packet delivered to the CPU port should loop back into the system.

Nonetheless, DSA has had numerous growing pains due to the lack of a struct net_device for the CPU port, but so far it has overcome them. It is unlikely at this stage of maturity that this aspect of it will change.

We would like U-Boot to present the same information as Linux, to be at parity in terms of number of interfaces, so that ethNaddr environment variables could directly be associated between U-Boot and Linux. Therefore, we would implicitly like U-Boot to hide the CPU port from the user as well.

But the paradox is that DSA still needs a struct phy_device to inform the driver of the parameters of the link that it should configure the CPU port to. The problem is that the phy_device is typically returned via a call to phy_connect, which needs an udevice to attach the PHY to, and to search its ofnode for the 'fixed-link' property. But we don't have an udevice to present for the CPU port.

Since 99% of DSA setups are MAC-to-MAC connections between the switch and the host Ethernet controller, the struct phy_device is going to be a fixed PHY. This simplifies things quite a bit. In U-Boot, a fixed PHY does not need an MDIO bus, and does not need an attached dev either. Basically, the phy_connect call doesn't do any connection, it just creates the fixed PHY.

The proposal of this patch is to introduce a new fixed_phy_create function which will take a single argument: the ofnode that holds this:

	port at 4 {
		reg = <4>;
		phy-mode = "internal";

		fixed-link {
			speed = <2500>;
			full-duplex;
		};
	};

and probe a fixed PHY driver using the information from this ofnode. DSA will probably be the only user of this function.

---
Changes in v5:
Use the new API for creating a fixed PHY (introduced in patch 1), which is to put the ofnode in phydev->node instead of phydev->addr.

Changes in v4:
Patch is new.

 drivers/net/phy/phy.c | 35 +++++++++++++++++++++++++++++++++++
 include/phy.h         | 21 +++++++++++++++++++++
 2 files changed, 56 insertions(+)
drivers/net/phy/phy.c +35 -0
index e88c93c4180d..a3b294054d18 100644
@@ -977,6 +977,41 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
 #endif
 
 #ifdef CONFIG_PHY_FIXED
+/**
+ * fixed_phy_create() - create an unconnected fixed-link pseudo-PHY device
+ * @node: OF node for the container of the fixed-link node
+ *
+ * Description: Creates a struct phy_device based on a fixed-link of_node
+ * description. Can be used without phy_connect by drivers which do not expose
+ * a UCLASS_ETH udevice.
+ */
+struct phy_device *fixed_phy_create(ofnode node)
+{
+	phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
+	struct phy_device *phydev;
+	const char *if_str;
+	ofnode subnode;
+
+	if_str = ofnode_read_string(node, "phy-mode");
+	if (!if_str) {
+		if_str = ofnode_read_string(node, "phy-interface-type");
+	}
+	if (if_str) {
+		interface = phy_get_interface_by_name(if_str);
+	}
+
+	subnode = ofnode_find_subnode(node, "fixed-link");
+	if (!ofnode_valid(subnode)) {
+		return NULL;
+	}
+
+	phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface);
+	if (phydev)
+		phydev->node = subnode;
+
+	return phydev;
+}
+
 #ifdef CONFIG_DM_ETH
 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
 					    struct udevice *dev,
include/phy.h +21 -0
index 7750efd8bb5c..2754421ed4fb 100644
@@ -402,6 +402,27 @@ int phy_reset(struct phy_device *phydev);
 struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
 		phy_interface_t interface);
 
+#ifdef CONFIG_PHY_FIXED
+
+/**
+ * fixed_phy_create() - create an unconnected fixed-link pseudo-PHY device
+ * @node: OF node for the container of the fixed-link node
+ *
+ * Description: Creates a struct phy_device based on a fixed-link of_node
+ * description. Can be used without phy_connect by drivers which do not expose
+ * a UCLASS_ETH udevice.
+ */
+struct phy_device *fixed_phy_create(ofnode node);
+
+#else
+
+static inline struct phy_device *fixed_phy_create(ofnode node)
+{
+	return NULL;
+}
+
+#endif
+
 #ifdef CONFIG_DM_ETH
 
 /**
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v5 4/9 net: mdio: teach dm_eth_connect_phy_handle to connect to fixed PHY

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

dm_eth_connect_phy_handle has all the info it needs in order to hide away from the UCLASS_ETH caller the fact that it is attached to a fixed-link PHY. So only attempt to search for a phy-handle if we've exhausted the fixed-link option first.

---
Changes in v5:
None.

 net/mdio-uclass.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/mdio-uclass.c +10 -2
index 697e5f838d94..766d4711cc23 100644
@@ -177,9 +177,10 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
 /* Connect to a PHY linked in eth DT node */
 struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
 {
-	const char *if_str;
+	ofnode node = dev_ofnode(ethdev), subnode;
 	phy_interface_t interface;
 	struct phy_device *phy;
+	const char *if_str;
 	int i;
 
 	if (!dev_has_ofnode(ethdev)) {
@@ -200,7 +201,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
 	if (interface == PHY_INTERFACE_MODE_NONE)
 		dev_dbg(ethdev, "can't find interface mode, default to NONE\n");
 
-	phy = dm_eth_connect_phy_handle(ethdev, interface);
+	subnode = ofnode_find_subnode(node, "fixed-link");
+	if (ofnode_valid(subnode)) {
+		phy = phy_connect(NULL, 0, ethdev, interface);
+		if (phy)
+			phy->node = subnode;
+	} else {
+		phy = dm_eth_connect_phy_handle(ethdev, interface);
+	}
 
 	if (!phy)
 		return NULL;
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH v5 4/9 net: mdio: teach dm_eth_connect_phy_handle to connect to fixed PHY

Quoted 9 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

dm_eth_connect_phy_handle has all the info it needs in order to hide away from the UCLASS_ETH caller the fact that it is attached to a fixed-link PHY. So only attempt to search for a phy-handle if we've exhausted the fixed-link option first.

---

Ouch, the function name in the commit message is wrong, I meant dm_eth_phy_connect but I pasted the wrong one. The patch is correct though. Should have not hurried.

author maintainer
#6 lore raw

PATCH v5 5/9 net: introduce DSA class for Ethernet switches

In reply to Vladimir Oltean

From: Claudiu Manoil <[email protected]>

DSA stands for Distributed Switch Architecture (a presentation here:
https://netdevconf.info/2.1/papers/distributed-switch-architecture.pdf)
and it covers switches that are connected to the host CPU through an Ethernet (typically MAC-to-MAC) link. Generally, DSA switches use frame tags to pass information about the source/destination ports to/from CPU. This way, the CPU has full individual awareness of the front-facing switch ports.

Front panel ports are presented as regular ethernet devices in U-Boot and they are expected to support the typical networking commands.

The use case for U-Boot is to use DSA switches as port multipliers, for things such as TFTP over a specific switch port. The switching ability is deemed to be too dangerous to be enabled from the bootloader without network protection features such as Spanning Tree Protocol, and is therefore not supported at all, in lack of a good reason.

Some DSA switches may be cascaded in a multi-chip setup; the DSA class code does not currently support this.

---
v5: Adjusted commit message.

v4: Implemented the TODO for having a phy_device on the CPU port.

v3:
- Removed all infrastructure associated with dsa_foreach_port, which is no longer needed.
- Only inherit the DSA master's MAC address if the environment does not already have a specific MAC address that should be used for the DSA port.
- Be compatible with the new "ethernet-ports" container name which has been introduced in the Linux kernel as commit 85e05d263ed2 ("net: dsa:
of: Allow ethernet-ports as encapsulating node") in v5.9.

v2: none

 drivers/net/Kconfig    |  15 ++
 include/dm/uclass-id.h |   1 +
 include/net.h          |   6 +
 include/net/dsa.h      | 165 ++++++++++++++
 net/Makefile           |   1 +
 net/dsa-uclass.c       | 478 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 666 insertions(+)
 create mode 100644 include/net/dsa.h
 create mode 100644 net/dsa-uclass.c
drivers/net/Kconfig +15 -0
index 971a57224821..0e84c22b5075 100644
@@ -37,6 +37,21 @@ config DM_MDIO_MUX
 	  This is currently implemented in net/mdio-mux-uclass.c
 	  Look in include/miiphy.h for details.
 
+config DM_DSA
+	bool "Enable Driver Model for DSA switches"
+	depends on DM_ETH && DM_MDIO
+	depends on PHY_FIXED
+	help
+	  Enable driver model for DSA switches
+
+	  Adds UCLASS_DSA class supporting switches that follow the Distributed
+	  Switch Architecture (DSA).  These switches rely on the presence of a
+	  management switch port connected to an Ethernet controller capable of
+	  receiving frames from the switch.  This host Ethernet controller is
+	  called the "master" Ethernet interface in DSA terminology.
+	  This is currently implemented in net/dsa-uclass.c, refer to
+	  include/net/dsa.h for API details.
+
 config MDIO_SANDBOX
 	depends on DM_MDIO && SANDBOX
 	default y
include/dm/uclass-id.h +1 -0
index ae4425d7a57a..d75de368c5a8 100644
@@ -46,6 +46,7 @@ enum uclass_id {
 	UCLASS_DISPLAY,		/* Display (e.g. DisplayPort, HDMI) */
 	UCLASS_DSI_HOST,	/* Display Serial Interface host */
 	UCLASS_DMA,		/* Direct Memory Access */
+	UCLASS_DSA,		/* Distributed (Ethernet) Switch Architecture */
 	UCLASS_EFI,		/* EFI managed devices */
 	UCLASS_ETH,		/* Ethernet device */
 	UCLASS_ETH_PHY,		/* Ethernet PHY device */
include/net.h +6 -0
index 13da69b7c145..b95d6a6f60eb 100644
@@ -499,7 +499,13 @@ struct icmp_hdr {
  * maximum packet size and multiple of 32 bytes =  1536
  */
 #define PKTSIZE			1522
+#ifndef CONFIG_DM_DSA
 #define PKTSIZE_ALIGN		1536
+#else
+/* Maximum DSA tagging overhead (headroom and/or tailroom) */
+#define DSA_MAX_OVR		256
+#define PKTSIZE_ALIGN		(1536 + DSA_MAX_OVR)
+#endif
 
 /*
  * Maximum receive ring size; that is, the number of packets
include/net/dsa.h new file +165 -0

165 lines not on this page · raw message

net/Makefile +1 -0
index 76527f704c47..fb3eba840fff 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_NET)      += arp.o
 obj-$(CONFIG_CMD_BOOTP) += bootp.o
 obj-$(CONFIG_CMD_CDP)  += cdp.o
 obj-$(CONFIG_CMD_DNS)  += dns.o
+obj-$(CONFIG_DM_DSA)   += dsa-uclass.o
 ifdef CONFIG_DM_ETH
 obj-$(CONFIG_NET)      += eth-uclass.o
 else
net/dsa-uclass.c new file +478 -0

478 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH v5 6/9 sandbox: add a DSA sandbox driver and unit test

In reply to Vladimir Oltean

From: Claudiu Manoil <[email protected]>

The DSA sandbox driver is used for unit testing the DSA class code. It implements a simple 2 port switch plus 1 CPU port, and uses a very simple tag to identify the ports.
The DSA sandbox device is connected via CPU port to a regular Ethernet sandbox device, called 'dsa-test-eth, managed by the existing eth sandbox driver. The 'dsa-test-eth' is not intended for testing the eth class code however, but it is used to emulate traffic through the 'lan0' and 'lan1' front pannel switch ports. To achieve this the dsa sandbox driver registers a tx handler for the 'dsa-test-eth' device. The switch ports, labeled as 'lan0' and 'lan1', are also registered as eth devices by the dsa class code this time. So pinging through these switch ports is as easy as:
=> setenv ethact lan0
=> ping 1.2.3.5

Unit tests for the dsa class code were also added. The 'dsa_probe' test exercises most API functions from dsa.h. The 'dsa' unit test simply exercises ARP/ICMP traffic through the two switch ports, including tag injection and extraction, with the help of the dsa sandbox driver.
I took care to minimize the impact on the existing eth unit tests, though some adjustments needed to be made with the addition of extra eth interfaces used by the dsa unit tests. The additional eth interfaces also require MAC addresses, these have been added to the sandbox default environment.

---
v5: make SANDBOX imply PHY_FIXED, a DSA dependency.

v4: none.

v3:
- deleted the unit tests associated with the infrastructure for dsa_foreach_port, since that function no longer exists.
- added fixed-link and phy-mode to lan0 from the sandbox device tree. We don't support ports that don't have a PHY and are not fixed-link either.

v2: none

 arch/Kconfig              |   2 +
 arch/sandbox/dts/test.dts |  48 ++++++++++
 drivers/net/Kconfig       |   9 ++
 drivers/net/Makefile      |   1 +
 drivers/net/dsa_sandbox.c | 179 ++++++++++++++++++++++++++++++++++++++
 include/configs/sandbox.h |   2 +
 test/dm/Makefile          |   1 +
 test/dm/dsa.c             |  82 +++++++++++++++++
 test/dm/eth.c             |  10 +--
 9 files changed, 329 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/dsa_sandbox.c
 create mode 100644 test/dm/dsa.c
arch/Kconfig +2 -0
index 6c8167826cf8..f114a025fa5b 100644
@@ -161,6 +161,8 @@ config SANDBOX
 	imply CMD_CLONE
 	imply SILENT_CONSOLE
 	imply BOOTARGS_SUBST
+	imply PHY_FIXED
+	imply DM_DSA
 
 config SH
 	bool "SuperH architecture"
arch/sandbox/dts/test.dts +48 -0

61 lines not on this page · raw message

drivers/net/Kconfig +9 -0
index 0e84c22b5075..f96ee642494a 100644
@@ -78,6 +78,15 @@ config DM_ETH_PHY
 	help
 	  Enable driver model for Ethernet Generic PHY .
 
+config DSA_SANDBOX
+	depends on DM_DSA && SANDBOX
+	default y
+	bool "Sandbox: Mocked DSA driver"
+	help
+	  This driver implements a dummy DSA switch connected to a dummy sandbox
+	  Ethernet device used as DSA master, to test DSA class code, including
+	  exported DSA API and datapath processing of Ethernet traffic.
+
 menuconfig NETDEVICES
 	bool "Network device support"
 	depends on NET
drivers/net/Makefile +1 -0
index a19511aaa7ba..108138fdb972 100644
@@ -22,6 +22,7 @@ obj-$(CONFIG_ETH_DESIGNWARE_SOCFPGA) += dwmac_socfpga.o
 obj-$(CONFIG_ETH_DESIGNWARE_S700) += dwmac_s700.o
 obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o
 obj-$(CONFIG_DNET) += dnet.o
+obj-$(CONFIG_DSA_SANDBOX) += dsa_sandbox.o
 obj-$(CONFIG_DM_ETH_PHY) += eth-phy-uclass.o
 obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
drivers/net/dsa_sandbox.c new file +179 -0

179 lines not on this page · raw message

include/configs/sandbox.h +2 -0
index e0708fe57395..91f636b2c102 100644
@@ -93,7 +93,9 @@
 #endif
 
 #define SANDBOX_ETH_SETTINGS		"ethaddr=00:00:11:22:33:44\0" \
+					"eth2addr=00:00:11:22:33:48\0" \
 					"eth3addr=00:00:11:22:33:45\0" \
+					"eth4addr=00:00:11:22:33:48\0" \
 					"eth5addr=00:00:11:22:33:46\0" \
 					"eth6addr=00:00:11:22:33:47\0" \
 					"ipaddr=1.2.3.4\0"
test/dm/Makefile +1 -0
index e70e50f40243..42dc2d56a764 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o
 obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
+obj-$(CONFIG_DM_DSA) += dsa.o
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_FIRMWARE) += firmware.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/dsa.c new file +82 -0

82 lines not on this page · raw message

test/dm/eth.c +5 -5
index fa8a69da7013..e4ee69561064 100644
@@ -53,8 +53,8 @@ static int dm_test_eth_alias(struct unit_test_state *uts)
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth at 10004000", env_get("ethact"));
 
-	/* Expected to fail since eth2 is not defined in the device tree */
-	env_set("ethact", "eth2");
+	/* Expected to fail since eth1 is not defined in the device tree */
+	env_set("ethact", "eth1");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth at 10002000", env_get("ethact"));
 
@@ -227,7 +227,7 @@ static int _dm_test_net_retry(struct unit_test_state *uts)
 	 * the active device should be eth0
 	 */
 	sandbox_eth_disable_response(1, true);
-	env_set("ethact", "eth at 10004000");
+	env_set("ethact", "lan1");
 	env_set("netretry", "yes");
 	sandbox_eth_skip_timeout();
 	ut_assertok(net_loop(PING));
@@ -237,11 +237,11 @@ static int _dm_test_net_retry(struct unit_test_state *uts)
 	 * eth1 is disabled and netretry is no, so the ping should fail and the
 	 * active device should be eth1
 	 */
-	env_set("ethact", "eth at 10004000");
+	env_set("ethact", "lan1");
 	env_set("netretry", "no");
 	sandbox_eth_skip_timeout();
 	ut_asserteq(-ENONET, net_loop(PING));
-	ut_asserteq_str("eth at 10004000", env_get("ethact"));
+	ut_asserteq_str("lan1", env_get("ethact"));
 
 	return 0;
 }
Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH v5 7/9 drivers: net: add Felix DSA switch driver

In reply to Vladimir Oltean

From: Alex Marginean <[email protected]>

This driver is used for the Ethernet switch integrated into NXP LS1028A. Felix on LS1028A has 4 front panel ports and two internal ports, I/O to/from the switch is done through an ENETC Ethernet interface. The 4 front panel ports are available as Ethernet interfaces and can be used with the typical network commands like tftp.

---
v5: none

v4: none

v3: dsa_foreach_port() does not work when called from the probe function
of the DSA udevice, because the eth port udevices are _not_ yet probed at that point. To fix this, we are now initializing all ports from the .port_enable() callback of each eth udevice.

v2: none

 drivers/net/fsl_enetc.h                 |   5 +
 drivers/net/mscc_eswitch/Kconfig        |   8 +
 drivers/net/mscc_eswitch/Makefile       |   1 +
 drivers/net/mscc_eswitch/felix_switch.c | 414 ++++++++++++++++++++++++
 4 files changed, 428 insertions(+)
 create mode 100644 drivers/net/mscc_eswitch/felix_switch.c
drivers/net/fsl_enetc.h +5 -0
index 37e7e858435b..110c1d78fbc6 100644
@@ -201,6 +201,11 @@ struct enetc_priv {
 /* PCS replicator block for USXGMII */
 #define ENETC_PCS_DEVAD_REPL		0x1f
 
+#define ENETC_PCS_REPL_LINK_TIMER_1	0x12
+#define  ENETC_PCS_REPL_LINK_TIMER_1_DEF	0x0003
+#define ENETC_PCS_REPL_LINK_TIMER_2	0x13
+#define  ENETC_PCS_REPL_LINK_TIMER_2_DEF	0x06a0
+
 /* ENETC external MDIO registers */
 #define ENETC_MDIO_BASE		0x1c00
 #define ENETC_MDIO_CFG		0x00
drivers/net/mscc_eswitch/Kconfig +8 -0
index 80dd22f98b7f..ccf7822dbe7a 100644
@@ -36,3 +36,11 @@ config MSCC_SERVAL_SWITCH
 	select PHYLIB
 	help
 	  This driver supports the Serval network switch device.
+
+config MSCC_FELIX_SWITCH
+	bool "Felix switch driver"
+	depends on DM_DSA && DM_PCI
+	select FSL_ENETC
+	help
+	  This driver supports the Ethernet switch integrated in the
+	  NXP LS1028A SoC.
drivers/net/mscc_eswitch/Makefile +1 -0
index d583fe9fc4bb..22342ed11417 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_MSCC_LUTON_SWITCH) += luton_switch.o mscc_xfer.o mscc_mac_table.o m
 obj-$(CONFIG_MSCC_JR2_SWITCH) += jr2_switch.o mscc_xfer.o mscc_miim.o
 obj-$(CONFIG_MSCC_SERVALT_SWITCH) += servalt_switch.o mscc_xfer.o mscc_miim.o
 obj-$(CONFIG_MSCC_SERVAL_SWITCH) += serval_switch.o mscc_xfer.o mscc_mac_table.o mscc_miim.o
+obj-$(CONFIG_MSCC_FELIX_SWITCH) += felix_switch.o
drivers/net/mscc_eswitch/felix_switch.c new file +414 -0

414 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH v5 8/9 arm: dts: ls1028a: add Ethernet switch node and dependencies

In reply to Vladimir Oltean

From: Alex Marginean <[email protected]>

The definition follows the DSA binding in kernel and describes the switch, its ports and PHYs. The switch node has the same structure as in Linux and this patch enables it (and relevant ports) for the LS1028A RDB board.

ENETC PF6 is the 2nd Eth controller linked to the switch on LS1028A, it is not used in U-Boot and was disabled. Ethernet port aliases were also added to better manage the multitude of ports available now.

---
v5: none.

v4: none.

v3: Added a comment denoting the PHY model present on the RDB.

v2: Switch node structure defined in dtsi now consistent with the Linux switch node definition. Moved aliases from dtsi to the RDB DTS to minimize impact on other boards (and for improved flexibility).

 arch/arm/dts/fsl-ls1028a-rdb.dts | 64 ++++++++++++++++++++++++++++++++
 arch/arm/dts/fsl-ls1028a.dtsi    | 55 ++++++++++++++++++++++++++-
 2 files changed, 118 insertions(+), 1 deletion(-)
arch/arm/dts/fsl-ls1028a-rdb.dts +64 -0
index 85b4815b2ed7..3432fca35269 100644
@@ -15,6 +15,12 @@
 	compatible = "fsl,ls1028a-rdb", "fsl,ls1028a";
 	aliases {
 		spi0 = &fspi;
+		eth0 = &enetc0;
+		eth1 = &enetc2;
+		eth2 = &mscc_felix_port0;
+		eth3 = &mscc_felix_port1;
+		eth4 = &mscc_felix_port2;
+		eth5 = &mscc_felix_port3;
 	};
 };
 
@@ -131,9 +137,67 @@
 	phy-handle = <&rdb_phy0>;
 };
 
+&enetc2 {
+	status = "okay";
+};
+
+&mscc_felix {
+	status = "okay";
+};
+
+&mscc_felix_port0 {
+	label = "swp0";
+	phy-handle = <&sw_phy0>;
+	phy-mode = "qsgmii";
+	status = "okay";
+};
+
+&mscc_felix_port1 {
+	label = "swp1";
+	phy-handle = <&sw_phy1>;
+	phy-mode = "qsgmii";
+	status = "okay";
+};
+
+&mscc_felix_port2 {
+	label = "swp2";
+	phy-handle = <&sw_phy2>;
+	phy-mode = "qsgmii";
+	status = "okay";
+};
+
+&mscc_felix_port3 {
+	label = "swp3";
+	phy-handle = <&sw_phy3>;
+	phy-mode = "qsgmii";
+	status = "okay";
+};
+
+&mscc_felix_port4 {
+	ethernet = <&enetc2>;
+	status = "okay";
+};
+
 &mdio0 {
 	status = "okay";
 	rdb_phy0: phy at 2 {
 		reg = <2>;
 	};
+
+	/* VSC8514 QSGMII PHY */
+	sw_phy0: phy at 10 {
+		reg = <0x10>;
+	};
+
+	sw_phy1: phy at 11 {
+		reg = <0x11>;
+	};
+
+	sw_phy2: phy at 12 {
+		reg = <0x12>;
+	};
+
+	sw_phy3: phy at 13 {
+		reg = <0x13>;
+	};
 };
arch/arm/dts/fsl-ls1028a.dtsi +54 -1

63 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH v5 9/9 configs: ls1028a: enable the Ethernet switch driver

In reply to Vladimir Oltean

From: Alex Marginean <[email protected]>

The switch driver for LS1028A Ethernet switch is now compiled in for the NXP LS1028A reference design boards and for the Kontron SMARC-sAL28.

---
v5: none

v4: enabled CONFIG_PHY_FIXED which is a new dependency of CONFIG_DM_DSA

v3: enable the config options for the Kontron board too.

v2: none

 configs/kontron_sl28_defconfig               | 3 +++
 configs/ls1028aqds_tfa_SECURE_BOOT_defconfig | 3 +++
 configs/ls1028aqds_tfa_defconfig             | 3 +++
 configs/ls1028ardb_tfa_SECURE_BOOT_defconfig | 3 +++
 configs/ls1028ardb_tfa_defconfig             | 3 +++
 5 files changed, 15 insertions(+)
configs/kontron_sl28_defconfig +3 -0
index 1759d5e1b92e..d56709689b38 100644
@@ -84,6 +84,9 @@ CONFIG_DM_MDIO=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_FSL_ENETC=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_DSA=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
configs/ls1028aqds_tfa_SECURE_BOOT_defconfig +3 -0
index eaf903f65427..93b13b472942 100644
@@ -62,6 +62,9 @@ CONFIG_DM_MDIO_MUX=y
 CONFIG_E1000=y
 CONFIG_FSL_ENETC=y
 CONFIG_MDIO_MUX_I2CREG=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_DSA=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
configs/ls1028aqds_tfa_defconfig +3 -0
index 248c64048296..c915069f283a 100644
@@ -68,6 +68,9 @@ CONFIG_DM_MDIO_MUX=y
 CONFIG_E1000=y
 CONFIG_FSL_ENETC=y
 CONFIG_MDIO_MUX_I2CREG=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_DSA=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
configs/ls1028ardb_tfa_SECURE_BOOT_defconfig +3 -0
index 240e4204ae57..45d9f40043d9 100644
@@ -59,6 +59,9 @@ CONFIG_DM_MDIO=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_FSL_ENETC=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_DSA=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
configs/ls1028ardb_tfa_defconfig +3 -0
index 493fe7c377a1..cff68a3cc823 100644
@@ -65,6 +65,9 @@ CONFIG_DM_MDIO=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_FSL_ENETC=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_DSA=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
Signature · 1 line
2.25.1