Skip to contentSkip to conversation

net: dsa: Add ability to elect CPU port

PATCH In review Florian Fainelli 3 participants 6 messages Oct 28, 2019 – Oct 30, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net: dsa: Add ability to elect CPU port

Hi all,

This patch series solves a problem we have with Broadcom switches whereby multiple CPU ports can be defined, and while they should all be possible choices, it may not be desirable to use, say port 5 instead of port 8 because port 8 is hard wired as the management port in the switch logic, or because it simply offers more features.

Add an election callback into the driver to allow the selection of a particular CPU port when multiple are defined.

Florian Fainelli (2):
net: dsa: Add ability to elect CPU port
net: dsa: b53: Add CPU port election callback

 drivers/net/dsa/b53/b53_common.c | 17 +++++++++++++++++
 drivers/net/dsa/b53/b53_priv.h   |  1 +
 drivers/net/dsa/bcm_sf2.c        |  1 +
 include/net/dsa.h                |  1 +
 net/dsa/dsa2.c                   | 19 +++++++++++++++----
 5 files changed, 35 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 net: dsa: Add ability to elect CPU port

In a configuration where multiple CPU ports are declared within the platform configuration, it may be desirable to make sure that a particular CPU port gets used. This is particularly true for Broadcom switch that are fairly flexible to some extent in which port can be the CPU port, yet will be more featureful if port 8 is elected.

---
 include/net/dsa.h |  1 +
 net/dsa/dsa2.c    | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)
include/net/dsa.h +1 -0
index e3c14dc3bab9..f4f209576f8e 100644
@@ -361,6 +361,7 @@ typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
 struct dsa_switch_ops {
 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
 						  int port);
+	int	(*elect_cpu_port)(struct dsa_switch *ds, int port);
 
 	int	(*setup)(struct dsa_switch *ds);
 	void	(*teardown)(struct dsa_switch *ds);
net/dsa/dsa2.c +15 -4
index 214dd703b0cc..31c4b692bd19 100644
@@ -184,14 +184,25 @@ static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst)
 	return complete;
 }
 
-static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
+static struct dsa_port *dsa_tree_find_cpu(struct dsa_switch_tree *dst)
 {
+	struct dsa_switch *ds;
 	struct dsa_port *dp;
+	int err;
 
-	list_for_each_entry(dp, &dst->ports, list)
-		if (dsa_port_is_cpu(dp))
+	list_for_each_entry(dp, &dst->ports, list) {
+		ds = dp->ds;
+		if (!dsa_port_is_cpu(dp))
+			continue;
+
+		if (!ds->ops->elect_cpu_port)
 			return dp;
 
+		err = ds->ops->elect_cpu_port(ds, dp->index);
+		if (err == 0)
+			return dp;
+	}
+
 	return NULL;
 }
 
@@ -199,7 +210,7 @@ static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
 {
 	struct dsa_port *cpu_dp, *dp;
 
-	cpu_dp = dsa_tree_find_first_cpu(dst);
+	cpu_dp = dsa_tree_find_cpu(dst);
 	if (!cpu_dp) {
 		pr_err("DSA: tree %d has no CPU port\n", dst->index);
 		return -EINVAL;
Signature · 1 line
2.17.1
maintainer
#2 lore raw
Quoted 20 lines · Florian Fainelli

In a configuration where multiple CPU ports are declared within the platform configuration, it may be desirable to make sure that a particular CPU port gets used. This is particularly true for Broadcom switch that are fairly flexible to some extent in which port can be the CPU port, yet will be more featureful if port 8 is elected.

net/dsa/dsa2.c +8 -3
-static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
+static struct dsa_port *dsa_tree_find_cpu(struct dsa_switch_tree *dst)
 {
+	struct dsa_switch *ds;
 	struct dsa_port *dp;
+	int err;
 
-	list_for_each_entry(dp, &dst->ports, list)
-		if (dsa_port_is_cpu(dp))
+	list_for_each_entry(dp, &dst->ports, list) {
+		ds = dp->ds;
+		if (!dsa_port_is_cpu(dp))
+			continue;
+

net/dsa/dsa2.c static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) · line 207

Quoted 10 lines
net/dsa/dsa2.c +6 -0
+		if (!ds->ops->elect_cpu_port)
 			return dp;
 
+		err = ds->ops->elect_cpu_port(ds, dp->index);
+		if (err == 0)
+			return dp;
+	}
+
 	return NULL;
 }

Hi Florian

I think is_preferred_cpu_port() would be a better name, and maybe a bool?

Also, i don't think we should be returning NULL at the end like this. If the device tree does not have the preferred port as CPU port, we should use dsa_tree_find_cpu() to pick one of the actually offered CPU ports in DT? It sounds like your hardware will still work if any port is used as the CPU port.

And maybe we need a is_valid_cpu_port()? Some of the chipsets only have a subset which can be CPU ports, the hardware is not as flexible. The core can then validate the CPU port really is valid, rather than the driver, e.g. qca8k, validating the CPU port in setup() and returning an error.

Andrew

#3 lore raw

Hi Andrew,

Quoted 34 lines · Andrew Lunn
Quoted 20 lines · Florian Fainelli

In a configuration where multiple CPU ports are declared within the platform configuration, it may be desirable to make sure that a particular CPU port gets used. This is particularly true for Broadcom switch that are fairly flexible to some extent in which port can be the CPU port, yet will be more featureful if port 8 is elected.

net/dsa/dsa2.c +8 -3
-static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
+static struct dsa_port *dsa_tree_find_cpu(struct dsa_switch_tree *dst)
 {
+	struct dsa_switch *ds;
 	struct dsa_port *dp;
+	int err;
 
-	list_for_each_entry(dp, &dst->ports, list)
-		if (dsa_port_is_cpu(dp))
+	list_for_each_entry(dp, &dst->ports, list) {
+		ds = dp->ds;
+		if (!dsa_port_is_cpu(dp))
+			continue;
+

net/dsa/dsa2.c static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst) · line 207

Quoted 10 lines
net/dsa/dsa2.c +6 -0
+		if (!ds->ops->elect_cpu_port)
 			return dp;
 
+		err = ds->ops->elect_cpu_port(ds, dp->index);
+		if (err == 0)
+			return dp;
+	}
+
 	return NULL;
 }

Hi Florian

Quoted 8 lines

I think is_preferred_cpu_port() would be a better name, and maybe a bool?

Also, i don't think we should be returning NULL at the end like this. If the device tree does not have the preferred port as CPU port, we should use dsa_tree_find_cpu() to pick one of the actually offered CPU ports in DT? It sounds like your hardware will still work if any port is used as the CPU port.

It would indeed work, although most likely in a degraded mode, so not a great fit usually.

Quoted 6 lines

And maybe we need a is_valid_cpu_port()? Some of the chipsets only have a subset which can be CPU ports, the hardware is not as flexible. The core can then validate the CPU port really is valid, rather than the driver, e.g. qca8k, validating the CPU port in setup() and returning an error.

Initially I had added a port_validate() function and had it be called from dsa_switch_parse_ports_of() and dsa_switch_parse_ports() such that the driver could check whether the port type (DSA, USER, CPU) was valid and return 0, an error or -EAGAIN if the CPU port was not the preferred one.

Later on, I did introduce is_preferred_cpu_port() returning a bool, but thought this was too long of a name and went for elect_cpu_port which is not really an election process.... Now you know my thought process :)

Let me sleep on it a bit, maybe coming back with the port_validate() approach is the most flexible/capable solution.

Signature · 1 line
Florian
#4 lore raw

PATCH 2/2 net: dsa: b53: Add CPU port election callback

In reply to Florian Fainelli

Add the ability to select a particular CPU port to be chosen when multiple such ports are defined/available in the platform configuration. On all Broadcom switches but 5325 and 5365, port 8 should be selected.

---
 drivers/net/dsa/b53/b53_common.c | 17 +++++++++++++++++
 drivers/net/dsa/b53/b53_priv.h   |  1 +
 drivers/net/dsa/bcm_sf2.c        |  1 +
 3 files changed, 19 insertions(+)
drivers/net/dsa/b53/b53_common.c +17 -0
index baadf622ac55..ce7c22f151a6 100644
@@ -1833,6 +1833,22 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port)
 }
 EXPORT_SYMBOL(b53_get_tag_protocol);
 
+int b53_elect_cpu_port(struct dsa_switch *ds, int port)
+{
+	struct b53_device *dev = ds->priv;
+	int cpu_port = dev->cpu_port;
+
+	if (is5325(dev) || is5365(dev))
+		cpu_port = B53_CPU_PORT_25;
+
+	/* We would prefer to use a different CPU port that this one */
+	if (port != cpu_port)
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL(b53_elect_cpu_port);
+
 int b53_mirror_add(struct dsa_switch *ds, int port,
 		   struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
 {
@@ -1962,6 +1978,7 @@ EXPORT_SYMBOL(b53_set_mac_eee);
 
 static const struct dsa_switch_ops b53_switch_ops = {
 	.get_tag_protocol	= b53_get_tag_protocol,
+	.elect_cpu_port		= b53_elect_cpu_port,
 	.setup			= b53_setup,
 	.get_strings		= b53_get_strings,
 	.get_ethtool_stats	= b53_get_ethtool_stats,
drivers/net/dsa/b53/b53_priv.h +1 -0
index a7dd8acc281b..f12b0fae6743 100644
@@ -354,6 +354,7 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
 int b53_mirror_add(struct dsa_switch *ds, int port,
 		   struct dsa_mall_mirror_tc_entry *mirror, bool ingress);
 enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port);
+int b53_elect_cpu_port(struct dsa_switch *ds, int port);
 void b53_mirror_del(struct dsa_switch *ds, int port,
 		    struct dsa_mall_mirror_tc_entry *mirror);
 int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
drivers/net/dsa/bcm_sf2.c +1 -0
index c068a3b7207b..ab399d7d76b6 100644
@@ -934,6 +934,7 @@ static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port,
 
 static const struct dsa_switch_ops bcm_sf2_ops = {
 	.get_tag_protocol	= b53_get_tag_protocol,
+	.elect_cpu_port		= b53_elect_cpu_port,
 	.setup			= bcm_sf2_sw_setup,
 	.get_strings		= bcm_sf2_sw_get_strings,
 	.get_ethtool_stats	= bcm_sf2_sw_get_ethtool_stats,
Signature · 1 line
2.17.1
maintainer
#5 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Mon, 28 Oct 2019 15:32:34 -0700

Quoted 8 lines

This patch series solves a problem we have with Broadcom switches whereby multiple CPU ports can be defined, and while they should all be possible choices, it may not be desirable to use, say port 5 instead of port 8 because port 8 is hard wired as the management port in the switch logic, or because it simply offers more features.

Add an election callback into the driver to allow the selection of a particular CPU port when multiple are defined.

I sense there will be another spin of this, so marking it changes-requrested in patchwork.