Skip to contentSkip to conversation

net: dsa: lantiq_gswip: code improvements

PATCH Superseded Martin Schiller 5 participants 47 messages Jun 6, 2024 – Jun 11, 2024

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#7 lore raw

PATCH 2/13 net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU port

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Add the CPU port to gswip_xrx200_phylink_get_caps() and gswip_xrx300_phylink_get_caps(). It connects through a SoC-internal bus, so the only allowed phy-mode is PHY_INTERFACE_MODE_INTERNAL.

---
 drivers/net/dsa/lantiq_gswip.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/dsa/lantiq_gswip.c +2 -0
index a557049e34f5..b9c7076ce32f 100644
@@ -1516,6 +1516,7 @@ static void gswip_xrx200_phylink_get_caps(struct dsa_switch *ds, int port,
 	case 2:
 	case 3:
 	case 4:
+	case 6:
 		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
 			  config->supported_interfaces);
 		break;
@@ -1547,6 +1548,7 @@ static void gswip_xrx300_phylink_get_caps(struct dsa_switch *ds, int port,
 	case 2:
 	case 3:
 	case 4:
+	case 6:
 		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
 			  config->supported_interfaces);
 		break;
Signature · 1 line
2.39.2
#11 lore raw

PATCH 3/13 net: dsa: lantiq_gswip: Use dev_err_probe where appropriate

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

dev_err_probe() can be used to simplify the existing code. Also it means we get rid of the following warning which is seen whenever the PMAC (Ethernet controller which connects to GSWIP's CPU port) has not been probed yet:
gswip 1e108000.switch: dsa switch register failed: -517

---
 drivers/net/dsa/lantiq_gswip.c | 53 ++++++++++++++++------------------
 1 file changed, 25 insertions(+), 28 deletions(-)
drivers/net/dsa/lantiq_gswip.c +25 -28
index b9c7076ce32f..fcb5929c9c88 100644
@@ -1931,11 +1931,9 @@ static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gph
 	msleep(200);
 
 	ret = request_firmware(&fw, gphy_fw->fw_name, dev);
-	if (ret) {
-		dev_err(dev, "failed to load firmware: %s, error: %i\n",
-			gphy_fw->fw_name, ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to load firmware: %s\n",
+				     gphy_fw->fw_name);
 
 	/* GPHY cores need the firmware code in a persistent and contiguous
 	 * memory area with a 16 kB boundary aligned start address.
@@ -1948,9 +1946,9 @@ static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gph
 		dev_addr = ALIGN(dma_addr, XRX200_GPHY_FW_ALIGN);
 		memcpy(fw_addr, fw->data, fw->size);
 	} else {
-		dev_err(dev, "failed to alloc firmware memory\n");
 		release_firmware(fw);
-		return -ENOMEM;
+		return dev_err_probe(dev, -ENOMEM,
+				     "failed to alloc firmware memory\n");
 	}
 
 	release_firmware(fw);
@@ -1977,8 +1975,8 @@ static int gswip_gphy_fw_probe(struct gswip_priv *priv,
 
 	gphy_fw->clk_gate = devm_clk_get(dev, gphyname);
 	if (IS_ERR(gphy_fw->clk_gate)) {
-		dev_err(dev, "Failed to lookup gate clock\n");
-		return PTR_ERR(gphy_fw->clk_gate);
+		return dev_err_probe(dev, PTR_ERR(gphy_fw->clk_gate),
+				     "Failed to lookup gate clock\n");
 	}
 
 	ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset);
@@ -1998,8 +1996,8 @@ static int gswip_gphy_fw_probe(struct gswip_priv *priv,
 		gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name;
 		break;
 	default:
-		dev_err(dev, "Unknown GPHY mode %d\n", gphy_mode);
-		return -EINVAL;
+		return dev_err_probe(dev, -EINVAL, "Unknown GPHY mode %d\n",
+				     gphy_mode);
 	}
 
 	gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np);
@@ -2050,8 +2048,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 			priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data;
 			break;
 		default:
-			dev_err(dev, "unknown GSWIP version: 0x%x", version);
-			return -ENOENT;
+			return dev_err_probe(dev, -ENOENT,
+					     "unknown GSWIP version: 0x%x",
+					     version);
 		}
 	}
 
@@ -2059,10 +2058,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 	if (match && match->data)
 		priv->gphy_fw_name_cfg = match->data;
 
-	if (!priv->gphy_fw_name_cfg) {
-		dev_err(dev, "GPHY compatible type not supported");
-		return -ENOENT;
-	}
+	if (!priv->gphy_fw_name_cfg)
+		return dev_err_probe(dev, -ENOENT,
+				     "GPHY compatible type not supported");
 
 	priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np);
 	if (!priv->num_gphy_fw)
@@ -2163,8 +2161,8 @@ static int gswip_probe(struct platform_device *pdev)
 			return -EINVAL;
 		break;
 	default:
-		dev_err(dev, "unknown GSWIP version: 0x%x", version);
-		return -ENOENT;
+		return dev_err_probe(dev, -ENOENT,
+				     "unknown GSWIP version: 0x%x", version);
 	}
 
 	/* bring up the mdio bus */
@@ -2172,28 +2170,27 @@ static int gswip_probe(struct platform_device *pdev)
 	if (gphy_fw_np) {
 		err = gswip_gphy_fw_list(priv, gphy_fw_np, version);
 		of_node_put(gphy_fw_np);
-		if (err) {
-			dev_err(dev, "gphy fw probe failed\n");
-			return err;
-		}
+		if (err)
+			return dev_err_probe(dev, err,
+					     "gphy fw probe failed\n");
 	}
 
 	/* bring up the mdio bus */
 	err = gswip_mdio(priv);
 	if (err) {
-		dev_err(dev, "mdio probe failed\n");
+		dev_err_probe(dev, err, "mdio probe failed\n");
 		goto gphy_fw_remove;
 	}
 
 	err = dsa_register_switch(priv->ds);
 	if (err) {
-		dev_err(dev, "dsa switch register failed: %i\n", err);
+		dev_err_probe(dev, err, "dsa switch registration failed\n");
 		goto gphy_fw_remove;
 	}
 	if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
-		dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
-			priv->hw_info->cpu_port);
-		err = -EINVAL;
+		err = dev_err_probe(dev, -EINVAL,
+				    "wrong CPU port defined, HW only supports port: %i",
+				    priv->hw_info->cpu_port);
 		goto disable_switch;
 	}
 
Signature · 1 line
2.39.2
#14 lore raw

PATCH 4/13 net: dsa: lantiq_gswip: Don't manually call gswip_port_enable()

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

We don't need to manually call gswip_port_enable() from within gswip_setup() for the CPU port. DSA does this automatically for us.

---
 drivers/net/dsa/lantiq_gswip.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/dsa/lantiq_gswip.c +0 -2
index fcb5929c9c88..3fd5599fca52 100644
@@ -898,8 +898,6 @@ static int gswip_setup(struct dsa_switch *ds)
 
 	ds->mtu_enforcement_ingress = true;
 
-	gswip_port_enable(ds, cpu_port, NULL);
-
 	ds->configure_vlan_while_not_filtering = false;
 
 	return 0;
Signature · 1 line
2.39.2
#17 lore raw

PATCH 5/13 net: dsa: lantiq_gswip: do also enable or disable cpu port

In reply to Martin Schiller

Before commit 74be4babe72f ("net: dsa: do not enable or disable non user ports"), gswip_port_enable/disable() were also executed for the cpu port in gswip_setup() which disabled the cpu port during initialization.

Let's restore this by removing the dsa_is_user_port checks. Also, let's clean up the gswip_port_enable() function so that we only have to check for the cpu port once.

Fixes 74be4babe72f ("net: dsa: do not enable or disable non user ports")
---
 drivers/net/dsa/lantiq_gswip.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/net/dsa/lantiq_gswip.c +8 -16
index 3fd5599fca52..38b5f743e5ee 100644
@@ -695,13 +695,18 @@ static int gswip_port_enable(struct dsa_switch *ds, int port,
 	struct gswip_priv *priv = ds->priv;
 	int err;
 
-	if (!dsa_is_user_port(ds, port))
-		return 0;
-
 	if (!dsa_is_cpu_port(ds, port)) {
+		u32 mdio_phy = 0;
+
 		err = gswip_add_single_port_br(priv, port, true);
 		if (err)
 			return err;
+
+		if (phydev)
+			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
+
+		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
+				GSWIP_MDIO_PHYp(port));
 	}
 
 	/* RMON Counter Enable for port */
@@ -714,16 +719,6 @@ static int gswip_port_enable(struct dsa_switch *ds, int port,
 	gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
 			  GSWIP_SDMA_PCTRLp(port));
 
-	if (!dsa_is_cpu_port(ds, port)) {
-		u32 mdio_phy = 0;
-
-		if (phydev)
-			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
-
-		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
-				GSWIP_MDIO_PHYp(port));
-	}
-
 	return 0;
 }
 
@@ -731,9 +726,6 @@ static void gswip_port_disable(struct dsa_switch *ds, int port)
 {
 	struct gswip_priv *priv = ds->priv;
 
-	if (!dsa_is_user_port(ds, port))
-		return;
-
 	gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0,
 			  GSWIP_FDMA_PCTRLp(port));
 	gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
Signature · 1 line
2.39.2
#20 lore raw

PATCH 6/13 net: dsa: lantiq_gswip: Use dsa_is_cpu_port() in gswip_port_change_mtu()

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Make the check for the CPU port in gswip_port_change_mtu() consistent with other areas of the driver by using dsa_is_cpu_port().

---
 drivers/net/dsa/lantiq_gswip.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/dsa/lantiq_gswip.c +1 -2
index 38b5f743e5ee..789b8a1076f1 100644
@@ -1464,12 +1464,11 @@ static int gswip_port_max_mtu(struct dsa_switch *ds, int port)
 static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
 {
 	struct gswip_priv *priv = ds->priv;
-	int cpu_port = priv->hw_info->cpu_port;
 
 	/* CPU port always has maximum mtu of user ports, so use it to set
 	 * switch frame size, including 8 byte special header.
 	 */
-	if (port == cpu_port) {
+	if (dsa_is_cpu_port(ds, port)) {
 		new_mtu += 8;
 		gswip_switch_w(priv, VLAN_ETH_HLEN + new_mtu + ETH_FCS_LEN,
 			       GSWIP_MAC_FLEN);
Signature · 1 line
2.39.2
#22 lore raw

PATCH 7/13 net: dsa: lantiq_gswip: Change literal 6 to ETH_ALEN

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

The addr variable in gswip_port_fdb_dump() stores a mac address. Use ETH_ALEN to make this consistent across other drivers.

---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +1 -1
index 789b8a1076f1..c049f505fcc7 100644
@@ -1413,7 +1413,7 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, int port,
 {
 	struct gswip_priv *priv = ds->priv;
 	struct gswip_pce_table_entry mac_bridge = {0,};
-	unsigned char addr[6];
+	unsigned char addr[ETH_ALEN];
 	int i;
 	int err;
 
Signature · 1 line
2.39.2
#24 lore raw

PATCH 8/13 net: dsa: lantiq_gswip: Consistently use macros for the mac bridge table

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Introduce a new GSWIP_TABLE_MAC_BRIDGE_PORT macro and use it throughout the driver. Also update GSWIP_TABLE_MAC_BRIDGE_STATIC to use the BIT() macro. This makes the driver code easier to understand.

---
 drivers/net/dsa/lantiq_gswip.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/dsa/lantiq_gswip.c +6 -3
index c049f505fcc7..ee8296d5b901 100644
@@ -236,7 +236,8 @@
 #define GSWIP_TABLE_ACTIVE_VLAN		0x01
 #define GSWIP_TABLE_VLAN_MAPPING	0x02
 #define GSWIP_TABLE_MAC_BRIDGE		0x0b
-#define  GSWIP_TABLE_MAC_BRIDGE_STATIC	0x01	/* Static not, aging entry */
+#define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging entry */
+#define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned entries */
 
 #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
 
@@ -1307,7 +1308,8 @@ static void gswip_port_fast_age(struct dsa_switch *ds, int port)
 		if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_STATIC)
 			continue;
 
-		if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) != port)
+		if (port != FIELD_GET(GSWIP_TABLE_MAC_BRIDGE_PORT,
+				      mac_bridge.val[0]))
 			continue;
 
 		mac_bridge.valid = false;
@@ -1445,7 +1447,8 @@ static int gswip_port_fdb_dump(struct dsa_switch *ds, int port,
 					return err;
 			}
 		} else {
-			if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) == port) {
+			if (port == FIELD_GET(GSWIP_TABLE_MAC_BRIDGE_PORT,
+					      mac_bridge.val[0])) {
 				err = cb(addr, 0, false, data);
 				if (err)
 					return err;
Signature · 1 line
2.39.2
#26 lore raw

PATCH 9/13 net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU port

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Calling gswip_add_single_port_br() with the CPU port would be a bug because then only the CPU port could talk to itself. Add the CPU port to the validation at the beginning of gswip_add_single_port_br().

---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +1 -1
index ee8296d5b901..d2195271ffe9 100644
@@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
 	unsigned int max_ports = priv->hw_info->max_ports;
 	int err;
 
-	if (port >= max_ports) {
+	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
 		dev_err(priv->dev, "single port for %i supported\n", port);
 		return -EIO;
 	}
Signature · 1 line
2.39.2
#30 lore raw

PATCH 10/13 net: dsa: lantiq_gswip: Fix error message in gswip_add_single_port_br()

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

The error message is printed when the port cannot be used. Update the error message to reflect that.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index d2195271ffe9..3c96a62b8e0a 100644
@@ -658,7 +658,8 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
 	int err;
 
 	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
-		dev_err(priv->dev, "single port for %i supported\n", port);
+		dev_err(priv->dev, "single port for %i is not supported\n",
+			port);
 		return -EIO;
 	}
 
Signature · 1 line
2.39.2
#35 lore raw

PATCH 11/13 net: dsa: lantiq_gswip: Fix comments in gswip_port_vlan_filtering()

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Update the comments in gswip_port_vlan_filtering() so it's clear that there are two separate cases, one for "tag based VLAN" and another one for "port based VLAN".

---
 drivers/net/dsa/lantiq_gswip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/lantiq_gswip.c +2 -2
index 3c96a62b8e0a..f2faee112e33 100644
@@ -786,7 +786,7 @@ static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
 	}
 
 	if (vlan_filtering) {
-		/* Use port based VLAN tag */
+		/* Use tag based VLAN */
 		gswip_switch_mask(priv,
 				  GSWIP_PCE_VCTRL_VSR,
 				  GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
@@ -795,7 +795,7 @@ static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
 		gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_TVM, 0,
 				  GSWIP_PCE_PCTRL_0p(port));
 	} else {
-		/* Use port based VLAN tag */
+		/* Use port based VLAN */
 		gswip_switch_mask(priv,
 				  GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
 				  GSWIP_PCE_VCTRL_VEMR,
Signature · 1 line
2.39.2
#38 lore raw

PATCH 12/13 net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a macro so this becomes obvious when reading the driver code.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index f2faee112e33..4bb894e75b81 100644
@@ -238,6 +238,7 @@
 #define GSWIP_TABLE_MAC_BRIDGE		0x0b
 #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging entry */
 #define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned entries */
+#define  GSWIP_TABLE_MAC_BRIDGE_FID	GENMASK(5, 0)	/* Filtering identifier */
 
 #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
 
@@ -1385,7 +1386,7 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
 	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
 	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
 	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
-	mac_bridge.key[3] = fid;
+	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
 	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
 	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
 	mac_bridge.valid = add;
Signature · 1 line
2.39.2
#42 lore raw

PATCH 13/13 net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

In reply to Martin Schiller

From: Martin Blumenstingl <[email protected]>

Print the port which is not found to be part of a bridge so it's easier to investigate the underlying issue.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index 4bb894e75b81..69035598e8a4 100644
@@ -1377,7 +1377,8 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
 	}
 
 	if (fid == -1) {
-		dev_err(priv->dev, "Port not part of a bridge\n");
+		dev_err(priv->dev,
+			"Port %d is not known to be part of bridge\n", port);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.39.2
#0 lore raw

cover net: dsa: lantiq_gswip: code improvements

This patchset for the lantiq_gswip driver is a collection of minor fixes and coding improvements by Martin Blumenstingl without any real changes in the actual functionality.

Martin Blumenstingl (12):
dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and
fixed-link
net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU
port
net: dsa: lantiq_gswip: Use dev_err_probe where appropriate
net: dsa: lantiq_gswip: Don't manually call gswip_port_enable()
net: dsa: lantiq_gswip: Use dsa_is_cpu_port() in
gswip_port_change_mtu()
net: dsa: lantiq_gswip: Change literal 6 to ETH_ALEN
net: dsa: lantiq_gswip: Consistently use macros for the mac bridge
table
net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU
port
net: dsa: lantiq_gswip: Fix error message in
gswip_add_single_port_br()
net: dsa: lantiq_gswip: Fix comments in gswip_port_vlan_filtering()
net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro
net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

Martin Schiller (1):
net: dsa: lantiq_gswip: do also enable or disable cpu port

 .../bindings/net/dsa/lantiq-gswip.txt         |   6 +
 drivers/net/dsa/lantiq_gswip.c                | 110 +++++++++---------
 2 files changed, 58 insertions(+), 58 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/13 dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link. Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

---
 Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/dsa/lantiq-gswip.txt +6 -0
index 8bb1eff21cb1..e81ba0e0da0f 100644
@@ -96,7 +96,13 @@ switch@e108000 {
 
 		port@6 {
 			reg = <0x6>;
+			phy-mode = "internal";
 			ethernet = <&eth0>;
+
+			fixed-link {
+				speed = <1000>;
+				full-duplex;
+			};
 		};
 	};
 
Signature · 1 line
2.39.2
Acked-by on the v1 series
#46 lore raw
In reply to Martin Schiller
Quoted 24 lines · Martin Schiller

This patchset for the lantiq_gswip driver is a collection of minor fixes and coding improvements by Martin Blumenstingl without any real changes in the actual functionality.

Martin Blumenstingl (12):
dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and
fixed-link
net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU
port
net: dsa: lantiq_gswip: Use dev_err_probe where appropriate
net: dsa: lantiq_gswip: Don't manually call gswip_port_enable()
net: dsa: lantiq_gswip: Use dsa_is_cpu_port() in
gswip_port_change_mtu()
net: dsa: lantiq_gswip: Change literal 6 to ETH_ALEN
net: dsa: lantiq_gswip: Consistently use macros for the mac bridge
table
net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU
port
net: dsa: lantiq_gswip: Fix error message in
gswip_add_single_port_br()
net: dsa: lantiq_gswip: Fix comments in gswip_port_vlan_filtering()
net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro
net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

Quoted 7 lines

Martin Schiller (1):
net: dsa: lantiq_gswip: do also enable or disable cpu port

  .../bindings/net/dsa/lantiq-gswip.txt         |   6 +
  drivers/net/dsa/lantiq_gswip.c                | 110 +++++++++---------
  2 files changed, 58 insertions(+), 58 deletions(-)

Thanks for sending this upstream. I had this on my list for a long time but never started it.

For all patches:

Hauke

maintainer Reviewed-by on v1 1/13
#2 lore raw

Re: [PATCH net-next 01/13] dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

In reply to Martin Schiller
Quoted 9 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link. Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

---

Long-term it would be good to also see a dt-schema conversion.

maintainer
#8 lore raw

Re: [PATCH net-next 02/13] net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU port

In reply to Martin Schiller
Quoted 8 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Add the CPU port to gswip_xrx200_phylink_get_caps() and gswip_xrx300_phylink_get_caps(). It connects through a SoC-internal bus, so the only allowed phy-mode is PHY_INTERFACE_MODE_INTERNAL.

---

This is for the case where those CPU port device tree properties are present, right? In the device trees in current circulation they are not, and DSA skips phylink registration.

maintainer
#12 lore raw

Re: [PATCH net-next 03/13] net: dsa: lantiq_gswip: Use dev_err_probe where appropriate

In reply to Martin Schiller
Quoted 38 lines · Martin Schiller
drivers/net/dsa/lantiq_gswip.c +8 -8
@@ -2050,8 +2048,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 			priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data;
 			break;
 		default:
-			dev_err(dev, "unknown GSWIP version: 0x%x", version);
-			return -ENOENT;
+			return dev_err_probe(dev, -ENOENT,
+					     "unknown GSWIP version: 0x%x",
+					     version);
 		}
 	}
 
@@ -2059,10 +2058,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
 	if (match && match->data)
 		priv->gphy_fw_name_cfg = match->data;
 
-	if (!priv->gphy_fw_name_cfg) {
-		dev_err(dev, "GPHY compatible type not supported");
-		return -ENOENT;
-	}
+	if (!priv->gphy_fw_name_cfg)
+		return dev_err_probe(dev, -ENOENT,
+				     "GPHY compatible type not supported");
 
 	priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np);
 	if (!priv->num_gphy_fw)
@@ -2163,8 +2161,8 @@ static int gswip_probe(struct platform_device *pdev)
 			return -EINVAL;
 		break;
 	default:
-		dev_err(dev, "unknown GSWIP version: 0x%x", version);
-		return -ENOENT;
+		return dev_err_probe(dev, -ENOENT,
+				     "unknown GSWIP version: 0x%x", version);
 	}
 
 	/* bring up the mdio bus */

drivers/net/dsa/lantiq_gswip.c static int gswip_probe(struct platform_device *pdev) · line 2175

Quoted 9 lines
drivers/net/dsa/lantiq_gswip.c +3 -3
@@ -2172,28 +2170,27 @@ static int gswip_probe(struct platform_device *pdev)
 	if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
-		dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
-			priv->hw_info->cpu_port);
-		err = -EINVAL;
+		err = dev_err_probe(dev, -EINVAL,
+				    "wrong CPU port defined, HW only supports port: %i",
+				    priv->hw_info->cpu_port);
 		goto disable_switch;
 	}

Nitpick: there is no terminating \n here.

maintainer
#15 lore raw

Re: [PATCH net-next 04/13] net: dsa: lantiq_gswip: Don't manually call gswip_port_enable()

In reply to Martin Schiller
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

We don't need to manually call gswip_port_enable() from within gswip_setup() for the CPU port. DSA does this automatically for us.

---

Not to mention the first thing in gswip_port_enable(), which is:

	if (!dsa_is_user_port(ds, port))
		return 0;

So the call is dead code anyway.

maintainer
#18 lore raw

Re: [PATCH net-next 05/13] net: dsa: lantiq_gswip: do also enable or disable cpu port

In reply to Martin Schiller
Quoted 3 lines · Martin Schiller

Before commit 74be4babe72f ("net: dsa: do not enable or disable non user ports"), gswip_port_enable/disable() were also executed for the cpu port in gswip_setup() which disabled the cpu port during initialization.

Ah, you also noticed this.

Quoted 6 lines

Let's restore this by removing the dsa_is_user_port checks. Also, let's clean up the gswip_port_enable() function so that we only have to check for the cpu port once.

Fixes 74be4babe72f ("net: dsa: do not enable or disable non user ports")

Fixes tags shouldn't be taken lightly. If you think there's a functional user-visible problem caused by that change, you need to explain what that problem is and what it affects. Additionally, bug fix patches are sent out to the 'net' tree, not bundled up with 'net-next' material (unless they fix a change that's also exclusive to net-next). Otherwise, just drop the 'Fixes' tag.

Quoted 37 lines
---
 drivers/net/dsa/lantiq_gswip.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/net/dsa/lantiq_gswip.c +8 -5
index 3fd5599fca52..38b5f743e5ee 100644
@@ -695,13 +695,18 @@ static int gswip_port_enable(struct dsa_switch *ds, int port,
 	struct gswip_priv *priv = ds->priv;
 	int err;
 
-	if (!dsa_is_user_port(ds, port))
-		return 0;
-
 	if (!dsa_is_cpu_port(ds, port)) {
+		u32 mdio_phy = 0;
+
 		err = gswip_add_single_port_br(priv, port, true);
 		if (err)
 			return err;
+
+		if (phydev)
+			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
+
+		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
+				GSWIP_MDIO_PHYp(port));
 	}
 
 	/* RMON Counter Enable for port */
@@ -714,16 +719,6 @@ static int gswip_port_enable(struct dsa_switch *ds, int port,
 	gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
 			  GSWIP_SDMA_PCTRLp(port));
 
-	if (!dsa_is_cpu_port(ds, port)) {
-		u32 mdio_phy = 0;

drivers/net/dsa/lantiq_gswip.c static int gswip_port_enable(struct dsa_switch *ds, int port, · line 723

Quoted 10 lines
drivers/net/dsa/lantiq_gswip.c +0 -8
-
-		if (phydev)
-			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
-
-		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
-				GSWIP_MDIO_PHYp(port));
-	}
-
 	return 0;
 }

It would be good to state in the commit message that the operation reordering is safe. The commit seems to be concerned mainly with code cleanliness, which does not always take side effects into account.

maintainer Reviewed-by on v1 6/13
#21 lore raw

Re: [PATCH net-next 06/13] net: dsa: lantiq_gswip: Use dsa_is_cpu_port() in gswip_port_change_mtu()

In reply to Martin Schiller
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Make the check for the CPU port in gswip_port_change_mtu() consistent with other areas of the driver by using dsa_is_cpu_port().

---

maintainer Reviewed-by on v1 7/13
#23 lore raw

Re: [PATCH net-next 07/13] net: dsa: lantiq_gswip: Change literal 6 to ETH_ALEN

In reply to Martin Schiller
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The addr variable in gswip_port_fdb_dump() stores a mac address. Use ETH_ALEN to make this consistent across other drivers.

---

maintainer Reviewed-by on v1 8/13
#25 lore raw

Re: [PATCH net-next 08/13] net: dsa: lantiq_gswip: Consistently use macros for the mac bridge table

In reply to Martin Schiller
Quoted 8 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Introduce a new GSWIP_TABLE_MAC_BRIDGE_PORT macro and use it throughout the driver. Also update GSWIP_TABLE_MAC_BRIDGE_STATIC to use the BIT() macro. This makes the driver code easier to understand.

---

maintainer
#27 lore raw

Re: [PATCH net-next 09/13] net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU port

In reply to Martin Schiller
Quoted 27 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Calling gswip_add_single_port_br() with the CPU port would be a bug because then only the CPU port could talk to itself. Add the CPU port to the validation at the beginning of gswip_add_single_port_br().

---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +1 -1
index ee8296d5b901..d2195271ffe9 100644
@@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
 	unsigned int max_ports = priv->hw_info->max_ports;
 	int err;
 
-	if (port >= max_ports) {
+	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
 		dev_err(priv->dev, "single port for %i supported\n", port);
 		return -EIO;
 	}
Signature · 1 line
2.39.2

Isn't the new check effectively dead code?

maintainer
#31 lore raw

Re: [PATCH net-next 10/13] net: dsa: lantiq_gswip: Fix error message in gswip_add_single_port_br()

In reply to Martin Schiller
Quoted 27 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The error message is printed when the port cannot be used. Update the error message to reflect that.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index d2195271ffe9..3c96a62b8e0a 100644
@@ -658,7 +658,8 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
 	int err;
 
 	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
-		dev_err(priv->dev, "single port for %i supported\n", port);
+		dev_err(priv->dev, "single port for %i is not supported\n",
+			port);
 		return -EIO;
 	}
 
Signature · 1 line
2.39.2

Isn't even the original condition (port >= max_ports) dead code? Why not remove the condition altogether?

maintainer
#39 lore raw

Re: [PATCH net-next 12/13] net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro

In reply to Martin Schiller
Quoted 33 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a macro so this becomes obvious when reading the driver code.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index f2faee112e33..4bb894e75b81 100644
@@ -238,6 +238,7 @@
 #define GSWIP_TABLE_MAC_BRIDGE		0x0b
 #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging entry */
 #define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned entries */
+#define  GSWIP_TABLE_MAC_BRIDGE_FID	GENMASK(5, 0)	/* Filtering identifier */
 
 #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
 
@@ -1385,7 +1386,7 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
 	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
 	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
 	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
-	mac_bridge.key[3] = fid;
+	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
 	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
 	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
 	mac_bridge.valid = add;
Signature · 1 line
2.39.2

On second thought, I disagree with the naming scheme of the GSWIP_TABLE_MAC_BRIDGE_* macros. It is completely non obvious that they are non-overlapping, because they have the same name prefix, but:
_STATIC applies to gswip_pce_table_entry :: val[1]
_PORT applies to gswip_pce_table_entry :: val[0]
_FID applies to gswip_pce_table_entry :: key[3]

I think it's all too easy to use the wrong macro on the wrong register field. If the macros incorporated names like VAL1, KEY3 etc, it would be much more obvious. Could you please do that?

maintainer
#43 lore raw

Re: [PATCH net-next 13/13] net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

In reply to Martin Schiller
Quoted 4 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Print the port which is not found to be part of a bridge so it's easier to investigate the underlying issue.

Was there an actual issue which was investigated here? More details?

Quoted 10 lines
---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +0 -0
index 4bb894e75b81..69035598e8a4 100644

drivers/net/dsa/lantiq_gswip.c static int gswip_port_fdb(struct dsa_switch *ds, int port, · line 1383

Quoted 8 lines
drivers/net/dsa/lantiq_gswip.c +2 -1
@@ -1377,7 +1377,8 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
 	}
 
 	if (fid == -1) {
-		dev_err(priv->dev, "Port not part of a bridge\n");
+		dev_err(priv->dev,
+			"Port %d is not known to be part of bridge\n", port);
 		return -EINVAL;
 	}

Actually I would argue this is entirely confusing. There is an earlier check:

	if (!bridge)
		return -EINVAL;

which did _not_ trigger if we're executing this. So the port _is_ a part of a bridge. Just say that no FID is found for bridge %s (bridge->name), which technically _is_ what happened.

maintainer
#36 lore raw

Re: [PATCH net-next 11/13] net: dsa: lantiq_gswip: Fix comments in gswip_port_vlan_filtering()

In reply to Martin Schiller
Quoted 9 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Update the comments in gswip_port_vlan_filtering() so it's clear that there are two separate cases, one for "tag based VLAN" and another one for "port based VLAN".

---

Here and in whatever the previous patch turns into: please make more careful use of the word "fix". It carries connotations of addressing bugs which must be backported. Various automated tools scan the git tree for bug fixes which were apparently "not properly submitted" and mark them for auto-selection to stable. You don't want to cause that for a minor comment.

#9 lore raw

Re: [PATCH net-next 02/13] net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU port

In reply to Vladimir Oltean
Quoted 7 lines · Vladimir Oltean
Quoted 6 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Add the CPU port to gswip_xrx200_phylink_get_caps() and gswip_xrx300_phylink_get_caps(). It connects through a SoC-internal bus, so the only allowed phy-mode is PHY_INTERFACE_MODE_INTERNAL.

Quoted 6 lines
Quoted 2 lines

---

This is for the case where those CPU port device tree properties are present, right? In the device trees in current circulation they are not, and DSA skips phylink registration.

Yes, as far as I know, this driver is mainly, if not exclusively, used in the openWrt environment. These functions were already added here in Oct. 2022 [1].

[1] https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=2683cca5927844594f7835aa983e2690d1e343c6

maintainer Reviewed-by
#10 lore raw

Re: [PATCH net-next 02/13] net: dsa: lantiq_gswip: Only allow phy-mode = "internal" on the CPU port

Quoted 17 lines · Martin Schiller
Quoted 8 lines · Vladimir Oltean
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Add the CPU port to gswip_xrx200_phylink_get_caps() and gswip_xrx300_phylink_get_caps(). It connects through a SoC-internal bus,
so the only allowed phy-mode is PHY_INTERFACE_MODE_INTERNAL.

Quoted 7 lines
Quoted 3 lines

Signed-off-by: Martin Blumenstingl
<[email protected]>
---

This is for the case where those CPU port device tree properties are present, right? In the device trees in current circulation they are not, and DSA skips phylink registration.

Quoted 6 lines

Yes, as far as I know, this driver is mainly, if not exclusively, used in the
openWrt environment. These functions were already added here in Oct. 2022 [1].

[1] https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=2683cca5927844594f7835aa983e2690d1e343c6

Ok. You can add my

#13 lore raw

Re: [PATCH net-next 03/13] net: dsa: lantiq_gswip: Use dev_err_probe where appropriate

In reply to Vladimir Oltean
Quoted 40 lines · Vladimir Oltean
Quoted 39 lines · Martin Schiller
drivers/net/dsa/lantiq_gswip.c +6 -6
@@ -2050,8 +2048,9 @@ static int gswip_gphy_fw_list(struct gswip_priv 
 *priv,
 			priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data;
 			break;
 		default:
-			dev_err(dev, "unknown GSWIP version: 0x%x", version);
-			return -ENOENT;
+			return dev_err_probe(dev, -ENOENT,
+					     "unknown GSWIP version: 0x%x",
+					     version);
 		}
 	}
@@ -2059,10 +2058,9 @@ static int gswip_gphy_fw_list(struct gswip_priv 
 *priv,
 	if (match && match->data)
 		priv->gphy_fw_name_cfg = match->data;
 
-	if (!priv->gphy_fw_name_cfg) {
-		dev_err(dev, "GPHY compatible type not supported");
-		return -ENOENT;
-	}
+	if (!priv->gphy_fw_name_cfg)
+		return dev_err_probe(dev, -ENOENT,
+				     "GPHY compatible type not supported");
 
 	priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np);
drivers/net/dsa/lantiq_gswip.c +2 -2
 	if (!priv->num_gphy_fw)
@@ -2163,8 +2161,8 @@ static int gswip_probe(struct platform_device 
 *pdev)
 			return -EINVAL;
 		break;
 	default:
-		dev_err(dev, "unknown GSWIP version: 0x%x", version);
-		return -ENOENT;
+		return dev_err_probe(dev, -ENOENT,
+				     "unknown GSWIP version: 0x%x", version);
 	}
 
Quoted 14 lines

drivers/net/dsa/lantiq_gswip.c static int gswip_probe(struct platform_device · line 2176

Quoted 12 lines
drivers/net/dsa/lantiq_gswip.c +3 -3
 	/* bring up the mdio bus */
@@ -2172,28 +2170,27 @@ static int gswip_probe(struct platform_device 
 *pdev)
 	if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
-		dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
-			priv->hw_info->cpu_port);
-		err = -EINVAL;
+		err = dev_err_probe(dev, -EINVAL,
+				    "wrong CPU port defined, HW only supports port: %i",
+				    priv->hw_info->cpu_port);
 		goto disable_switch;
 	}

Nitpick: there is no terminating \n here.

Oh, thanks for the hint. I'll correct that (and also check the complete source file for that kind of mistakes).

#16 lore raw

Re: [PATCH net-next 04/13] net: dsa: lantiq_gswip: Don't manually call gswip_port_enable()

In reply to Vladimir Oltean
Quoted 9 lines · Vladimir Oltean
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

We don't need to manually call gswip_port_enable() from within gswip_setup() for the CPU port. DSA does this automatically for us.

---

Quoted 6 lines

Not to mention the first thing in gswip_port_enable(), which is:

	if (!dsa_is_user_port(ds, port))
		return 0;

So the call is dead code anyway.

As you will have noticed, this code will be brought back to life in the next patch.

#19 lore raw

Re: [PATCH net-next 05/13] net: dsa: lantiq_gswip: do also enable or disable cpu port

In reply to Vladimir Oltean
Quoted 12 lines · Vladimir Oltean
Quoted 3 lines · Martin Schiller

Before commit 74be4babe72f ("net: dsa: do not enable or disable non user ports"), gswip_port_enable/disable() were also executed for the cpu port in gswip_setup() which disabled the cpu port during initialization.

Ah, you also noticed this.

Quoted 5 lines

Let's restore this by removing the dsa_is_user_port checks. Also, let's clean up the gswip_port_enable() function so that we only have to check for the cpu port once.

Quoted 8 lines
Quoted 1 line
Fixes 74be4babe72f ("net: dsa: do not enable or disable non user ports")

Fixes tags shouldn't be taken lightly. If you think there's a functional user-visible problem caused by that change, you need to explain what that problem is and what it affects. Additionally, bug fix patches are sent out to the 'net' tree, not bundled up with 'net-next' material (unless they fix a change that's also exclusive to net-next). Otherwise, just drop the 'Fixes' tag.

OK, I will drop the 'Fixes' tag.

Quoted 38 lines
Quoted 38 lines
---
 drivers/net/dsa/lantiq_gswip.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/net/dsa/lantiq_gswip.c +8 -3
index 3fd5599fca52..38b5f743e5ee 100644
@@ -695,13 +695,18 @@ static int gswip_port_enable(struct dsa_switch 
 *ds, int port,
 	struct gswip_priv *priv = ds->priv;
 	int err;
 
-	if (!dsa_is_user_port(ds, port))
-		return 0;
-
 	if (!dsa_is_cpu_port(ds, port)) {
+		u32 mdio_phy = 0;
+
 		err = gswip_add_single_port_br(priv, port, true);
 		if (err)
 			return err;
+
+		if (phydev)
+			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
+
+		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
+				GSWIP_MDIO_PHYp(port));
 	}
 
drivers/net/dsa/lantiq_gswip.c +0 -0
 	/* RMON Counter Enable for port */
@@ -714,16 +719,6 @@ static int gswip_port_enable(struct dsa_switch 
 *ds, int port,
 	gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
 			  GSWIP_SDMA_PCTRLp(port));
 
Quoted 16 lines

drivers/net/dsa/lantiq_gswip.c static int gswip_port_enable(struct dsa_switch *ds, int port, · line 723

Quoted 12 lines
drivers/net/dsa/lantiq_gswip.c +0 -10
-	if (!dsa_is_cpu_port(ds, port)) {
-		u32 mdio_phy = 0;
-
-		if (phydev)
-			mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
-
-		gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
-				GSWIP_MDIO_PHYp(port));
-	}
-
 	return 0;
 }

It would be good to state in the commit message that the operation reordering is safe. The commit seems to be concerned mainly with code cleanliness, which does not always take side effects into account.

Thanks for the hint. I will take it into account in the commit message.

#28 lore raw

Re: [PATCH net-next 09/13] net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU port

In reply to Vladimir Oltean
Quoted 21 lines · Vladimir Oltean
Quoted 20 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Calling gswip_add_single_port_br() with the CPU port would be a bug because then only the CPU port could talk to itself. Add the CPU port to the validation at the beginning of gswip_add_single_port_br().

---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +0 -0
index ee8296d5b901..d2195271ffe9 100644
@@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct 
 gswip_priv *priv, int port, bool add)
 	unsigned int max_ports = priv->hw_info->max_ports;
 	int err;
 
Quoted 10 lines
Quoted 8 lines
drivers/net/dsa/lantiq_gswip.c +1 -1
-	if (port >= max_ports) {
+	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
 		dev_err(priv->dev, "single port for %i supported\n", port);
 		return -EIO;

}
--
2.39.2

Isn't the new check effectively dead code?

As long as the dsa_switch_ops .port_bridge_join and .port_bridge_leave are not executed for the cpu port, I agree with you.

#32 lore raw

Re: [PATCH net-next 10/13] net: dsa: lantiq_gswip: Fix error message in gswip_add_single_port_br()

In reply to Vladimir Oltean
Quoted 26 lines · Vladimir Oltean
Quoted 25 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The error message is printed when the port cannot be used. Update the error message to reflect that.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +2 -1
index d2195271ffe9..3c96a62b8e0a 100644
@@ -658,7 +658,8 @@ static int gswip_add_single_port_br(struct 
 gswip_priv *priv, int port, bool add)
 	int err;
 
 	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
-		dev_err(priv->dev, "single port for %i supported\n", port);
+		dev_err(priv->dev, "single port for %i is not supported\n",
+			port);
 		return -EIO;
 	}
Quoted 6 lines
Quoted 3 lines

--
2.39.2

Isn't even the original condition (port >= max_ports) dead code? Why not remove the condition altogether?

I also agree here if we can be sure, that .port_enable, .port_bridge_join and .port_bridge_leave are only called for "valid" (<= max_ports) ports.

#37 lore raw

Re: [PATCH net-next 11/13] net: dsa: lantiq_gswip: Fix comments in gswip_port_vlan_filtering()

In reply to Vladimir Oltean
Quoted 11 lines · Vladimir Oltean
Quoted 9 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Update the comments in gswip_port_vlan_filtering() so it's clear that there are two separate cases, one for "tag based VLAN" and another one for "port based VLAN".

---

Quoted 6 lines

Here and in whatever the previous patch turns into: please make more careful use of the word "fix". It carries connotations of addressing bugs which must be backported. Various automated tools scan the git tree for bug fixes which were apparently "not properly submitted" and mark them for auto-selection to stable. You don't want to cause that for a minor comment.

OK, I will eliminate the term "fix" wherever it is not appropriate.

maintainer
#29 lore raw

Re: [PATCH net-next 09/13] net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU port

In reply to Martin Schiller
Quoted 36 lines · Martin Schiller
Quoted 24 lines · Vladimir Oltean
Quoted 23 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Calling gswip_add_single_port_br() with the CPU port would be a bug because then only the CPU port could talk to itself. Add the CPU port to
the validation at the beginning of gswip_add_single_port_br().

Signed-off-by: Martin Blumenstingl
<[email protected]>

---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +0 -0
index ee8296d5b901..d2195271ffe9 100644
@@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct
 gswip_priv *priv, int port, bool add)
 	unsigned int max_ports = priv->hw_info->max_ports;
 	int err;
 
Quoted 10 lines
Quoted 8 lines
drivers/net/dsa/lantiq_gswip.c +1 -1
-	if (port >= max_ports) {
+	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
 		dev_err(priv->dev, "single port for %i supported\n", port);
 		return -EIO;

}
--
2.39.2

Isn't the new check effectively dead code?

Quoted 2 lines

As long as the dsa_switch_ops .port_bridge_join and .port_bridge_leave are not executed for the cpu port, I agree with you.

They aren't. The primary trigger for dsa_port_bridge_join() is dsa_user_changeupper(), along with other code paths that replay the operation in certain circumstances, again only for user ports.

maintainer
#33 lore raw

Re: [PATCH net-next 10/13] net: dsa: lantiq_gswip: Fix error message in gswip_add_single_port_br()

In reply to Martin Schiller
Quoted 6 lines · Martin Schiller
Quoted 2 lines · Vladimir Oltean

Isn't even the original condition (port >= max_ports) dead code? Why not remove the condition altogether?

I also agree here if we can be sure, that .port_enable, .port_bridge_join and .port_bridge_leave are only called for "valid" (<= max_ports) ports.

dsa_switch_parse_ports_of() has:

		if (reg >= ds->num_ports) {
			dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n",
				port, reg, ds->num_ports);
			of_node_put(port);
			err = -EINVAL;
			goto out_put_node;
		}
#44 lore raw

Re: [PATCH net-next 13/13] net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

In reply to Vladimir Oltean
Quoted 7 lines · Vladimir Oltean
Quoted 4 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Print the port which is not found to be part of a bridge so it's easier to investigate the underlying issue.

Was there an actual issue which was investigated here? More details?

Well, there are probably still several problems with this driver. Martin Blumenstingl is probably referring to the problem discussed in [1] and [2].

[1] https://github.com/openwrt/openwrt/pull/13200
[2] https://github.com/openwrt/openwrt/pull/13638

Quoted 24 lines
Quoted 11 lines
---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +0 -0
index 4bb894e75b81..69035598e8a4 100644

drivers/net/dsa/lantiq_gswip.c static int gswip_port_fdb(struct dsa_switch *ds, · line 1384

Quoted 9 lines
drivers/net/dsa/lantiq_gswip.c +2 -1
@@ -1377,7 +1377,8 @@ static int gswip_port_fdb(struct dsa_switch *ds, 
 int port,
 	}
 
 	if (fid == -1) {
-		dev_err(priv->dev, "Port not part of a bridge\n");
+		dev_err(priv->dev,
+			"Port %d is not known to be part of bridge\n", port);
 		return -EINVAL;
 	}

Actually I would argue this is entirely confusing. There is an earlier check:

Quoted 6 lines
	if (!bridge)
		return -EINVAL;

which did _not_ trigger if we're executing this. So the port _is_ a part of a bridge. Just say that no FID is found for bridge %s (bridge->name), which technically _is_ what happened.

Yes, you are right. I'll change that.

#34 lore raw

Re: [PATCH net-next 10/13] net: dsa: lantiq_gswip: Fix error message in gswip_add_single_port_br()

In reply to Vladimir Oltean
Quoted 10 lines · Vladimir Oltean
Quoted 6 lines · Martin Schiller
Quoted 2 lines · Vladimir Oltean

Isn't even the original condition (port >= max_ports) dead code? Why not remove the condition altogether?

I also agree here if we can be sure, that .port_enable, .port_bridge_join and .port_bridge_leave are only called for "valid" (<= max_ports) ports.

dsa_switch_parse_ports_of() has:

Quoted 7 lines
		if (reg >= ds->num_ports) {
			dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n",
				port, reg, ds->num_ports);
			of_node_put(port);
			err = -EINVAL;
			goto out_put_node;
		}

OK, so I will remove this check altogether.

maintainer
#45 lore raw

Re: [PATCH net-next 13/13] net: dsa: lantiq_gswip: Improve error message in gswip_port_fdb()

In reply to Martin Schiller
Quoted 8 lines · Martin Schiller
Quoted 7 lines · Vladimir Oltean
Quoted 5 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Print the port which is not found to be part of a bridge so it's easier
to investigate the underlying issue.

Quoted 7 lines
Quoted 1 line

Was there an actual issue which was investigated here? More details?

Well, there are probably still several problems with this driver. Martin Blumenstingl is probably referring to the problem discussed in [1] and [2].

[1] https://github.com/openwrt/openwrt/pull/13200
[2] https://github.com/openwrt/openwrt/pull/13638

Ok, but that doesn't technically exercise this error path.

#40 lore raw

Re: [PATCH net-next 12/13] net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro

In reply to Vladimir Oltean
Quoted 46 lines · Vladimir Oltean
Quoted 34 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a macro so this becomes obvious when reading the driver code.

---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/dsa/lantiq_gswip.c +0 -0
index f2faee112e33..4bb894e75b81 100644
@@ -238,6 +238,7 @@
 #define GSWIP_TABLE_MAC_BRIDGE		0x0b
 #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging 

entry */
#define GSWIP_TABLE_MAC_BRIDGE_PORT GENMASK(7, 4) /* Port on learned
entries */
+#define GSWIP_TABLE_MAC_BRIDGE_FID GENMASK(5, 0) /* Filtering
identifier */

#define XRX200_GPHY_FW_ALIGN (16 * 1024)

drivers/net/dsa/lantiq_gswip.c +1 -1
@@ -1385,7 +1386,7 @@ static int gswip_port_fdb(struct dsa_switch *ds, 
 int port,
 	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
 	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
 	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
-	mac_bridge.key[3] = fid;
+	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
 	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
 	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
Quoted 3 lines

mac_bridge.valid = add;
--
2.39.2

On second thought, I disagree with the naming scheme of the GSWIP_TABLE_MAC_BRIDGE_* macros. It is completely non obvious that they are non-overlapping, because they have the same name prefix, but:
_STATIC applies to gswip_pce_table_entry :: val[1]
_PORT applies to gswip_pce_table_entry :: val[0]
_FID applies to gswip_pce_table_entry :: key[3]

Quoted 3 lines

I think it's all too easy to use the wrong macro on the wrong register field. If the macros incorporated names like VAL1, KEY3 etc, it would be much more obvious. Could you please do that?

OK, so I'll change the macro names to

GSWIP_TABLE_MAC_BRIDGE_KEY3_FID
GSWIP_TABLE_MAC_BRIDGE_VAL0_PORT
GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC

Also the comment of GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC should be changed to /* Static, not aging entry */

While looking again at this diff above, I noticed that val[0] is set incorrectly. Shouldn't it be either "port << 4" or (after the previous patch) "FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_PORT, port);" instead of "BIT(port)"?

#41 lore raw

Re: [PATCH net-next 12/13] net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro

Quoted 3 lines · Martin Schiller

While looking again at this diff above, I noticed that val[0] is set incorrectly. Shouldn't it be either "port << 4" or (after the previous patch) "FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_PORT, port);" instead of "BIT(port)"?

Please ignore this comment. The format of the port specification differs for static and dynamic (learned) entries.

#3 lore raw

Re: [PATCH net-next 01/13] dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

In reply to Martin Schiller
Quoted 6 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link. Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

You did nothing in the binding to describe them. You only extended example, which does not really matter if there is DTS with it.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH net-next 01/13] dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

Quoted 8 lines · Krzysztof Kozlowski
Quoted 6 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link. Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

Quoted 5 lines

You did nothing in the binding to describe them. You only extended example, which does not really matter if there is DTS with it.

Best regards,
Krzysztof

OK, so I'll update subject and commit message to signal that we only update the example code.

maintainer
#5 lore raw

Re: [PATCH net-next 01/13] dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

Quoted 10 lines · Martin Schiller
Quoted 9 lines · Krzysztof Kozlowski
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link.
Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

Quoted 8 lines
Quoted 5 lines

You did nothing in the binding to describe them. You only extended example, which does not really matter if there is DTS with it.

Best regards,
Krzysztof

OK, so I'll update subject and commit message to signal that we only update the example code.

Either convert it or leave it alone. If you are worried about users' DTs being wrong due to copying a bad example, then you should care enough to do the conversion. Given the errors we find in examples, it's likely not the only problem.

Rob

#6 lore raw

Re: [PATCH net-next 01/13] dt-bindings: net: dsa: lantiq_gswip: Add missing phy-mode and fixed-link

Quoted 20 lines · Rob Herring
Quoted 10 lines · Martin Schiller
Quoted 9 lines · Krzysztof Kozlowski
Quoted 7 lines · Martin Schiller

From: Martin Blumenstingl <[email protected]>

The CPU port has to specify a phy-mode and either a phy or a fixed-link.
Since GSWIP is connected using a SoC internal protocol there's no PHY involved. Add phy-mode = "internal" and a fixed-link to describe the communication between the PMAC (Ethernet controller) and GSWIP switch.

Quoted 8 lines
Quoted 5 lines

You did nothing in the binding to describe them. You only extended example, which does not really matter if there is DTS with it.

Best regards,
Krzysztof

OK, so I'll update subject and commit message to signal that we only update the example code.

Quoted 6 lines

Either convert it or leave it alone. If you are worried about users' DTs being wrong due to copying a bad example, then you should care enough to do the conversion. Given the errors we find in examples, it's likely not the only problem.

Rob

Then I will convert the bindings to the new YAML format and send another update of this patch-set.

Thanks,
Martin