netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/7] net: dsa: add port parsing functions
@ 2017-10-27 19:55 Vivien Didelot
  2017-10-27 19:55 ` [PATCH net-next 1/7] net: dsa: get ports within parsing code Vivien Didelot
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

This patchset adds port parsing functions called early in the new
bindings parsing stage, which regroup all the fetching of static data
available at the port level, including the port's type, name and CPU
master interface.

This simplifies the rest of the code which does not need to dig into
device tree or platform data again in order to check a port's type or
name.

Vivien Didelot (7):
  net: dsa: get ports within parsing code
  net: dsa: add port parse functions
  net: dsa: get port type at parse time
  net: dsa: check master device before put
  net: dsa: get master device at port parsing time
  net: dsa: get port name at parse time
  net: dsa: remove name arg from slave create

 net/dsa/dsa2.c     | 163 +++++++++++++++++++++++++++++------------------------
 net/dsa/dsa_priv.h |   2 +-
 net/dsa/legacy.c   |   3 +-
 net/dsa/slave.c    |   3 +-
 4 files changed, 95 insertions(+), 76 deletions(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH net-next 1/7] net: dsa: get ports within parsing code
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:37   ` Florian Fainelli
  2017-10-27 19:55 ` [PATCH net-next 2/7] net: dsa: add port parse functions Vivien Didelot
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

There is no point into hiding the -EINVAL error code in ERR_PTR from a
dsa_get_ports function, simply get the "ports" node directly from within
the dsa_parse_ports_dn function.

This also has the effect to make the pdata and device tree handling code
symmetrical inside _dsa_register_switch.

At the same time, rename dsa_parse_ports_dn to dsa_parse_ports_of
because _of is a more common suffix for device tree parsing functions.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index ec58654a71cd..26d2ff013eb1 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -589,11 +589,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
 	return 0;
 }
 
-static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
+static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
 {
-	struct device_node *port;
-	int err;
+	struct device_node *ports, *port;
 	u32 reg;
+	int err;
+
+	ports = of_get_child_by_name(dn, "ports");
+	if (!ports) {
+		dev_err(ds->dev, "no ports child node found\n");
+		return -EINVAL;
+	}
 
 	for_each_available_child_of_node(ports, port) {
 		err = of_property_read_u32(port, "reg", &reg);
@@ -664,26 +670,11 @@ static int dsa_parse_member(struct dsa_chip_data *pd, u32 *tree, u32 *index)
 	return 0;
 }
 
-static struct device_node *dsa_get_ports(struct dsa_switch *ds,
-					 struct device_node *np)
-{
-	struct device_node *ports;
-
-	ports = of_get_child_by_name(np, "ports");
-	if (!ports) {
-		dev_err(ds->dev, "no ports child node found\n");
-		return ERR_PTR(-EINVAL);
-	}
-
-	return ports;
-}
-
 static int _dsa_register_switch(struct dsa_switch *ds)
 {
 	struct dsa_chip_data *pdata = ds->dev->platform_data;
 	struct device_node *np = ds->dev->of_node;
 	struct dsa_switch_tree *dst;
-	struct device_node *ports;
 	u32 tree, index;
 	int i, err;
 
@@ -692,11 +683,7 @@ static int _dsa_register_switch(struct dsa_switch *ds)
 		if (err)
 			return err;
 
-		ports = dsa_get_ports(ds, np);
-		if (IS_ERR(ports))
-			return PTR_ERR(ports);
-
-		err = dsa_parse_ports_dn(ports, ds);
+		err = dsa_parse_ports_of(np, ds);
 		if (err)
 			return err;
 	} else {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 2/7] net: dsa: add port parse functions
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
  2017-10-27 19:55 ` [PATCH net-next 1/7] net: dsa: get ports within parsing code Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:37   ` Florian Fainelli
  2017-10-27 19:55 ` [PATCH net-next 3/7] net: dsa: get port type at parse time Vivien Didelot
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

Add symmetrical DSA port parsing functions for pdata and device tree,
used to parse and validate a given port node or platform data.

They don't do much for the moment but will be extended later on to
assign a port type and get device references.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 26d2ff013eb1..9b75d19d57cb 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -589,9 +589,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
 	return 0;
 }
 
+static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
+{
+	dp->dn = dn;
+
+	return 0;
+}
+
 static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
 {
 	struct device_node *ports, *port;
+	struct dsa_port *dp;
 	u32 reg;
 	int err;
 
@@ -609,22 +617,45 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
 		if (reg >= ds->num_ports)
 			return -EINVAL;
 
-		ds->ports[reg].dn = port;
+		dp = &ds->ports[reg];
+
+		err = dsa_port_parse_of(dp, port);
+		if (err)
+			return err;
 	}
 
 	return 0;
 }
 
+static int dsa_port_parse(struct dsa_port *dp, const char *name,
+			  struct device *dev)
+{
+	dp->name = name;
+
+	return 0;
+}
+
 static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
 {
 	bool valid_name_found = false;
+	struct dsa_port *dp;
+	struct device *dev;
+	const char *name;
 	unsigned int i;
+	int err;
 
 	for (i = 0; i < DSA_MAX_PORTS; i++) {
-		if (!cd->port_names[i])
+		name = cd->port_names[i];
+		dev = cd->netdev[i];
+		dp = &ds->ports[i];
+
+		if (!name)
 			continue;
 
-		ds->ports[i].name = cd->port_names[i];
+		err = dsa_port_parse(dp, name, dev);
+		if (err)
+			return err;
+
 		valid_name_found = true;
 	}
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 3/7] net: dsa: get port type at parse time
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
  2017-10-27 19:55 ` [PATCH net-next 1/7] net: dsa: get ports within parsing code Vivien Didelot
  2017-10-27 19:55 ` [PATCH net-next 2/7] net: dsa: add port parse functions Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:39   ` Florian Fainelli
  2017-10-27 19:55 ` [PATCH net-next 4/7] net: dsa: check master device before put Vivien Didelot
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

Assign a port's type at parsed time instead of waiting for the tree to
be completed.

Because this is now done earlier, we can use the port's type in
dsa_port_is_* helpers instead of digging again in topology description.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 9b75d19d57cb..960219d2f862 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -87,23 +87,17 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
  */
 static bool dsa_port_is_valid(struct dsa_port *port)
 {
-	return !!(port->dn || port->name);
+	return port->type != DSA_PORT_TYPE_UNUSED;
 }
 
 static bool dsa_port_is_dsa(struct dsa_port *port)
 {
-	if (port->name && !strcmp(port->name, "dsa"))
-		return true;
-	else
-		return !!of_parse_phandle(port->dn, "link", 0);
+	return port->type == DSA_PORT_TYPE_DSA;
 }
 
 static bool dsa_port_is_cpu(struct dsa_port *port)
 {
-	if (port->name && !strcmp(port->name, "cpu"))
-		return true;
-	else
-		return !!of_parse_phandle(port->dn, "ethernet", 0);
+	return port->type == DSA_PORT_TYPE_CPU;
 }
 
 static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
@@ -183,8 +177,6 @@ static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
 		err = dsa_port_complete(dst, ds, port, index);
 		if (err != 0)
 			return err;
-
-		port->type = DSA_PORT_TYPE_DSA;
 	}
 
 	return 0;
@@ -499,8 +491,6 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
 		dst->cpu_dp->master = ethernet_dev;
 	}
 
-	port->type = DSA_PORT_TYPE_CPU;
-
 	tag_protocol = ds->ops->get_tag_protocol(ds);
 	tag_ops = dsa_resolve_tag_protocol(tag_protocol);
 	if (IS_ERR(tag_ops)) {
@@ -533,8 +523,6 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
 			err = dsa_cpu_parse(port, index, dst, ds);
 			if (err)
 				return err;
-		} else {
-			port->type = DSA_PORT_TYPE_USER;
 		}
 
 	}
@@ -591,6 +579,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
 
 static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 {
+	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
+	struct device_node *link = of_parse_phandle(dn, "link", 0);
+
+	if (ethernet) {
+		dp->type = DSA_PORT_TYPE_CPU;
+	} else if (link) {
+		dp->type = DSA_PORT_TYPE_DSA;
+	} else {
+		dp->type = DSA_PORT_TYPE_USER;
+	}
+
 	dp->dn = dn;
 
 	return 0;
@@ -630,6 +629,14 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
 static int dsa_port_parse(struct dsa_port *dp, const char *name,
 			  struct device *dev)
 {
+	if (!strcmp(name, "cpu")) {
+		dp->type = DSA_PORT_TYPE_CPU;
+	} else if (!strcmp(name, "dsa")) {
+		dp->type = DSA_PORT_TYPE_DSA;
+	} else {
+		dp->type = DSA_PORT_TYPE_USER;
+	}
+
 	dp->name = name;
 
 	return 0;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 4/7] net: dsa: check master device before put
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
                   ` (2 preceding siblings ...)
  2017-10-27 19:55 ` [PATCH net-next 3/7] net: dsa: get port type at parse time Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-27 19:55 ` [PATCH net-next 5/7] net: dsa: get master device at port parsing time Vivien Didelot
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

In the case of pdata, the dsa_cpu_parse function calls dev_put() before
making sure it isn't NULL. Fix this.

Fixes: 71e0bbde0d88 ("net: dsa: Add support for platform data")
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/dsa/dsa2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 960219d2f862..5b9dea81d617 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -478,14 +478,15 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
 		if (!ethernet)
 			return -EINVAL;
 		ethernet_dev = of_find_net_device_by_node(ethernet);
+		if (!ethernet_dev)
+			return -EPROBE_DEFER;
 	} else {
 		ethernet_dev = dsa_dev_to_net_device(ds->cd->netdev[index]);
+		if (!ethernet_dev)
+			return -EPROBE_DEFER;
 		dev_put(ethernet_dev);
 	}
 
-	if (!ethernet_dev)
-		return -EPROBE_DEFER;
-
 	if (!dst->cpu_dp) {
 		dst->cpu_dp = port;
 		dst->cpu_dp->master = ethernet_dev;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 5/7] net: dsa: get master device at port parsing time
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
                   ` (3 preceding siblings ...)
  2017-10-27 19:55 ` [PATCH net-next 4/7] net: dsa: check master device before put Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:41   ` Florian Fainelli
  2017-10-27 19:55 ` [PATCH net-next 6/7] net: dsa: get port name at parse time Vivien Didelot
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

Fetching the master device can be done directly when a port is parsed
from device tree or pdata, instead of waiting until dsa_dst_parse.

Now that -EPROBE_DEFER is returned before we add the switch to the tree,
there is no need to check for this error after dsa_dst_parse.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c | 44 ++++++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 5b9dea81d617..be43e06caf7e 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -470,27 +470,9 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
 {
 	const struct dsa_device_ops *tag_ops;
 	enum dsa_tag_protocol tag_protocol;
-	struct net_device *ethernet_dev;
-	struct device_node *ethernet;
 
-	if (port->dn) {
-		ethernet = of_parse_phandle(port->dn, "ethernet", 0);
-		if (!ethernet)
-			return -EINVAL;
-		ethernet_dev = of_find_net_device_by_node(ethernet);
-		if (!ethernet_dev)
-			return -EPROBE_DEFER;
-	} else {
-		ethernet_dev = dsa_dev_to_net_device(ds->cd->netdev[index]);
-		if (!ethernet_dev)
-			return -EPROBE_DEFER;
-		dev_put(ethernet_dev);
-	}
-
-	if (!dst->cpu_dp) {
+	if (!dst->cpu_dp)
 		dst->cpu_dp = port;
-		dst->cpu_dp->master = ethernet_dev;
-	}
 
 	tag_protocol = ds->ops->get_tag_protocol(ds);
 	tag_ops = dsa_resolve_tag_protocol(tag_protocol);
@@ -584,7 +566,14 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 	struct device_node *link = of_parse_phandle(dn, "link", 0);
 
 	if (ethernet) {
+		struct net_device *master;
+
+		master = of_find_net_device_by_node(ethernet);
+		if (!master)
+			return -EPROBE_DEFER;
+
 		dp->type = DSA_PORT_TYPE_CPU;
+		dp->master = master;
 	} else if (link) {
 		dp->type = DSA_PORT_TYPE_DSA;
 	} else {
@@ -631,7 +620,16 @@ static int dsa_port_parse(struct dsa_port *dp, const char *name,
 			  struct device *dev)
 {
 	if (!strcmp(name, "cpu")) {
+		struct net_device *master;
+
+		master = dsa_dev_to_net_device(dev);
+		if (!master)
+			return -EPROBE_DEFER;
+
+		dev_put(master);
+
 		dp->type = DSA_PORT_TYPE_CPU;
+		dp->master = master;
 	} else if (!strcmp(name, "dsa")) {
 		dp->type = DSA_PORT_TYPE_DSA;
 	} else {
@@ -773,14 +771,8 @@ static int _dsa_register_switch(struct dsa_switch *ds)
 	}
 
 	err = dsa_dst_parse(dst);
-	if (err) {
-		if (err == -EPROBE_DEFER) {
-			dsa_dst_del_ds(dst, ds, ds->index);
-			return err;
-		}
-
+	if (err)
 		goto out_del_dst;
-	}
 
 	err = dsa_dst_apply(dst);
 	if (err) {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 6/7] net: dsa: get port name at parse time
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
                   ` (4 preceding siblings ...)
  2017-10-27 19:55 ` [PATCH net-next 5/7] net: dsa: get master device at port parsing time Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:44   ` Florian Fainelli
  2017-10-27 19:55 ` [PATCH net-next 7/7] net: dsa: remove name arg from slave create Vivien Didelot
  2017-11-01  2:48 ` [PATCH net-next 0/7] net: dsa: add port parsing functions David Miller
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

Get the optional "label" property and assign a default one directly at
parse time instead of doing it when creating the slave.

For legacy, simply assign the port name stored in cd->port_names.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c   | 10 +++++-----
 net/dsa/legacy.c |  1 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index be43e06caf7e..f32fc0cd1bfe 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -260,11 +260,6 @@ static int dsa_user_port_apply(struct dsa_port *port)
 	const char *name = port->name;
 	int err;
 
-	if (port->dn)
-		name = of_get_property(port->dn, "label", NULL);
-	if (!name)
-		name = "eth%d";
-
 	err = dsa_slave_create(port, name);
 	if (err) {
 		dev_warn(ds->dev, "Failed to create slave %d: %d\n",
@@ -564,6 +559,7 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 {
 	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
 	struct device_node *link = of_parse_phandle(dn, "link", 0);
+	const char *name = of_get_property(dn, "label", NULL);
 
 	if (ethernet) {
 		struct net_device *master;
@@ -577,7 +573,11 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 	} else if (link) {
 		dp->type = DSA_PORT_TYPE_DSA;
 	} else {
+		if (!name)
+			name = "eth%d";
+
 		dp->type = DSA_PORT_TYPE_USER;
+		dp->name = name;
 	}
 
 	dp->dn = dn;
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index 93e1b116ef83..3b50a5da0401 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -115,6 +115,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
 		name = cd->port_names[i];
 		if (name == NULL)
 			continue;
+		dp->name = name;
 
 		if (!strcmp(name, "cpu")) {
 			if (dst->cpu_dp) {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 7/7] net: dsa: remove name arg from slave create
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
                   ` (5 preceding siblings ...)
  2017-10-27 19:55 ` [PATCH net-next 6/7] net: dsa: get port name at parse time Vivien Didelot
@ 2017-10-27 19:55 ` Vivien Didelot
  2017-10-30 18:44   ` Florian Fainelli
  2017-11-01  2:48 ` [PATCH net-next 0/7] net: dsa: add port parsing functions David Miller
  7 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-27 19:55 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, kernel, David S. Miller, Florian Fainelli,
	Andrew Lunn, Vivien Didelot

Now that slave dsa_port always have their name set, there is no need to
pass it to dsa_slave_create() anymore. Remove this argument.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 net/dsa/dsa2.c     | 3 +--
 net/dsa/dsa_priv.h | 2 +-
 net/dsa/legacy.c   | 2 +-
 net/dsa/slave.c    | 3 ++-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index f32fc0cd1bfe..bf4a39b93fb9 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -257,10 +257,9 @@ static void dsa_cpu_port_unapply(struct dsa_port *port)
 static int dsa_user_port_apply(struct dsa_port *port)
 {
 	struct dsa_switch *ds = port->ds;
-	const char *name = port->name;
 	int err;
 
-	err = dsa_slave_create(port, name);
+	err = dsa_slave_create(port);
 	if (err) {
 		dev_warn(ds->dev, "Failed to create slave %d: %d\n",
 			 port->index, err);
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 1e9914062d0b..6d775a137082 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -162,7 +162,7 @@ int dsa_port_vlan_del(struct dsa_port *dp,
 /* slave.c */
 extern const struct dsa_device_ops notag_netdev_ops;
 void dsa_slave_mii_bus_init(struct dsa_switch *ds);
-int dsa_slave_create(struct dsa_port *port, const char *name);
+int dsa_slave_create(struct dsa_port *dp);
 void dsa_slave_destroy(struct net_device *slave_dev);
 int dsa_slave_suspend(struct net_device *slave_dev);
 int dsa_slave_resume(struct net_device *slave_dev);
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index 3b50a5da0401..1b5405ff02d5 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -197,7 +197,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
 		if (dsa_is_user_port(ds, i))
 			continue;
 
-		ret = dsa_slave_create(&ds->ports[i], cd->port_names[i]);
+		ret = dsa_slave_create(&ds->ports[i]);
 		if (ret < 0)
 			netdev_err(master, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
 				   index, i, cd->port_names[i], ret);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 808e205227c3..48b954a76b0d 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1142,11 +1142,12 @@ static void dsa_slave_notify(struct net_device *dev, unsigned long val)
 	call_dsa_notifiers(val, dev, &rinfo.info);
 }
 
-int dsa_slave_create(struct dsa_port *port, const char *name)
+int dsa_slave_create(struct dsa_port *port)
 {
 	struct dsa_port *cpu_dp = port->cpu_dp;
 	struct net_device *master = cpu_dp->master;
 	struct dsa_switch *ds = port->ds;
+	const char *name = port->name;
 	struct net_device *slave_dev;
 	struct dsa_slave_priv *p;
 	int ret;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/7] net: dsa: get ports within parsing code
  2017-10-27 19:55 ` [PATCH net-next 1/7] net: dsa: get ports within parsing code Vivien Didelot
@ 2017-10-30 18:37   ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:37 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> There is no point into hiding the -EINVAL error code in ERR_PTR from a
> dsa_get_ports function, simply get the "ports" node directly from within
> the dsa_parse_ports_dn function.
> 
> This also has the effect to make the pdata and device tree handling code
> symmetrical inside _dsa_register_switch.
> 
> At the same time, rename dsa_parse_ports_dn to dsa_parse_ports_of
> because _of is a more common suffix for device tree parsing functions.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 2/7] net: dsa: add port parse functions
  2017-10-27 19:55 ` [PATCH net-next 2/7] net: dsa: add port parse functions Vivien Didelot
@ 2017-10-30 18:37   ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:37 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> Add symmetrical DSA port parsing functions for pdata and device tree,
> used to parse and validate a given port node or platform data.
> 
> They don't do much for the moment but will be extended later on to
> assign a port type and get device references.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 3/7] net: dsa: get port type at parse time
  2017-10-27 19:55 ` [PATCH net-next 3/7] net: dsa: get port type at parse time Vivien Didelot
@ 2017-10-30 18:39   ` Florian Fainelli
  2017-10-30 18:46     ` Vivien Didelot
  0 siblings, 1 reply; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:39 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> Assign a port's type at parsed time instead of waiting for the tree to
> be completed.
> 
> Because this is now done earlier, we can use the port's type in
> dsa_port_is_* helpers instead of digging again in topology description.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

One nit below:


>  static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
>  {
> +	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
> +	struct device_node *link = of_parse_phandle(dn, "link", 0);
> +
> +	if (ethernet) {
> +		dp->type = DSA_PORT_TYPE_CPU;
> +	} else if (link) {
> +		dp->type = DSA_PORT_TYPE_DSA;
> +	} else {
> +		dp->type = DSA_PORT_TYPE_USER;
> +	}
> +

The curly braces are probably not necessary since all of these are
single line statements.

>  	dp->dn = dn;
>  
>  	return 0;
> @@ -630,6 +629,14 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
>  static int dsa_port_parse(struct dsa_port *dp, const char *name,
>  			  struct device *dev)
>  {
> +	if (!strcmp(name, "cpu")) {
> +		dp->type = DSA_PORT_TYPE_CPU;
> +	} else if (!strcmp(name, "dsa")) {
> +		dp->type = DSA_PORT_TYPE_DSA;
> +	} else {
> +		dp->type = DSA_PORT_TYPE_USER;
> +	}

Likewise.
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 5/7] net: dsa: get master device at port parsing time
  2017-10-27 19:55 ` [PATCH net-next 5/7] net: dsa: get master device at port parsing time Vivien Didelot
@ 2017-10-30 18:41   ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:41 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> Fetching the master device can be done directly when a port is parsed
> from device tree or pdata, instead of waiting until dsa_dst_parse.
> 
> Now that -EPROBE_DEFER is returned before we add the switch to the tree,
> there is no need to check for this error after dsa_dst_parse.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 6/7] net: dsa: get port name at parse time
  2017-10-27 19:55 ` [PATCH net-next 6/7] net: dsa: get port name at parse time Vivien Didelot
@ 2017-10-30 18:44   ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:44 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> Get the optional "label" property and assign a default one directly at
> parse time instead of doing it when creating the slave.
> 
> For legacy, simply assign the port name stored in cd->port_names.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 7/7] net: dsa: remove name arg from slave create
  2017-10-27 19:55 ` [PATCH net-next 7/7] net: dsa: remove name arg from slave create Vivien Didelot
@ 2017-10-30 18:44   ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:44 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/27/2017 12:55 PM, Vivien Didelot wrote:
> Now that slave dsa_port always have their name set, there is no need to
> pass it to dsa_slave_create() anymore. Remove this argument.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 3/7] net: dsa: get port type at parse time
  2017-10-30 18:39   ` Florian Fainelli
@ 2017-10-30 18:46     ` Vivien Didelot
  2017-10-30 18:46       ` Florian Fainelli
  0 siblings, 1 reply; 17+ messages in thread
From: Vivien Didelot @ 2017-10-30 18:46 UTC (permalink / raw)
  To: Florian Fainelli, netdev
  Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

Hi Florian,

Florian Fainelli <f.fainelli@gmail.com> writes:

> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
>
> One nit below:
>
>>  static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
>>  {
>> +	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
>> +	struct device_node *link = of_parse_phandle(dn, "link", 0);
>> +
>> +	if (ethernet) {
>> +		dp->type = DSA_PORT_TYPE_CPU;
>> +	} else if (link) {
>> +		dp->type = DSA_PORT_TYPE_DSA;
>> +	} else {
>> +		dp->type = DSA_PORT_TYPE_USER;
>> +	}
>> +
>
> The curly braces are probably not necessary since all of these are
> single line statements.

I didn't mention it in the commit message because it was obvious that
the next patches will extend these condition arms.


Thanks,

        Vivien

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 3/7] net: dsa: get port type at parse time
  2017-10-30 18:46     ` Vivien Didelot
@ 2017-10-30 18:46       ` Florian Fainelli
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2017-10-30 18:46 UTC (permalink / raw)
  To: Vivien Didelot, netdev; +Cc: linux-kernel, kernel, David S. Miller, Andrew Lunn

On 10/30/2017 11:46 AM, Vivien Didelot wrote:
> Hi Florian,
> 
> Florian Fainelli <f.fainelli@gmail.com> writes:
> 
>> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
>>
>> One nit below:
>>
>>>  static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
>>>  {
>>> +	struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
>>> +	struct device_node *link = of_parse_phandle(dn, "link", 0);
>>> +
>>> +	if (ethernet) {
>>> +		dp->type = DSA_PORT_TYPE_CPU;
>>> +	} else if (link) {
>>> +		dp->type = DSA_PORT_TYPE_DSA;
>>> +	} else {
>>> +		dp->type = DSA_PORT_TYPE_USER;
>>> +	}
>>> +
>>
>> The curly braces are probably not necessary since all of these are
>> single line statements.
> 
> I didn't mention it in the commit message because it was obvious that
> the next patches will extend these condition arms.

Fair enough then ;)
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 0/7] net: dsa: add port parsing functions
  2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
                   ` (6 preceding siblings ...)
  2017-10-27 19:55 ` [PATCH net-next 7/7] net: dsa: remove name arg from slave create Vivien Didelot
@ 2017-11-01  2:48 ` David Miller
  7 siblings, 0 replies; 17+ messages in thread
From: David Miller @ 2017-11-01  2:48 UTC (permalink / raw)
  To: vivien.didelot; +Cc: netdev, linux-kernel, kernel, f.fainelli, andrew

From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Date: Fri, 27 Oct 2017 15:55:12 -0400

> This patchset adds port parsing functions called early in the new
> bindings parsing stage, which regroup all the fetching of static data
> available at the port level, including the port's type, name and CPU
> master interface.
> 
> This simplifies the rest of the code which does not need to dig into
> device tree or platform data again in order to check a port's type or
> name.

Series applied, thanks Vivien.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-11-01  2:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27 19:55 [PATCH net-next 0/7] net: dsa: add port parsing functions Vivien Didelot
2017-10-27 19:55 ` [PATCH net-next 1/7] net: dsa: get ports within parsing code Vivien Didelot
2017-10-30 18:37   ` Florian Fainelli
2017-10-27 19:55 ` [PATCH net-next 2/7] net: dsa: add port parse functions Vivien Didelot
2017-10-30 18:37   ` Florian Fainelli
2017-10-27 19:55 ` [PATCH net-next 3/7] net: dsa: get port type at parse time Vivien Didelot
2017-10-30 18:39   ` Florian Fainelli
2017-10-30 18:46     ` Vivien Didelot
2017-10-30 18:46       ` Florian Fainelli
2017-10-27 19:55 ` [PATCH net-next 4/7] net: dsa: check master device before put Vivien Didelot
2017-10-27 19:55 ` [PATCH net-next 5/7] net: dsa: get master device at port parsing time Vivien Didelot
2017-10-30 18:41   ` Florian Fainelli
2017-10-27 19:55 ` [PATCH net-next 6/7] net: dsa: get port name at parse time Vivien Didelot
2017-10-30 18:44   ` Florian Fainelli
2017-10-27 19:55 ` [PATCH net-next 7/7] net: dsa: remove name arg from slave create Vivien Didelot
2017-10-30 18:44   ` Florian Fainelli
2017-11-01  2:48 ` [PATCH net-next 0/7] net: dsa: add port parsing functions David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).