Skip to contentSkip to conversation

net: dsa: Implement ndo_get_phys_port_name()

PATCH In review Florian Fainelli 5 participants 12 messages Jan 10, 2017 – Jan 11, 2017

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

cover net: dsa: Implement ndo_get_phys_port_name()

Hi all,

This patch series implements ndo_get_phys_port_name() so we can revert ndo_get_phys_id() which was (ab)used in the DSA layer.

Thanks

Florian Fainelli (2):
net: dsa: Implement ndo_get_phys_port_name() Revert "net: dsa: Implement ndo_get_phys_port_id"

 net/dsa/slave.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/2 net: dsa: Implement ndo_get_phys_port_name()

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

---
 net/dsa/slave.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
net/dsa/slave.c +10 -0
index 5cd5b8137c08..fed3fbd403cb 100644
@@ -990,6 +990,15 @@ static int dsa_slave_get_phys_port_id(struct net_device *dev,
 
 	ppid->id_len = sizeof(p->port);
 	memcpy(ppid->id, &p->port, ppid->id_len);
+}
+
+static int dsa_slave_get_phys_port_name(struct net_device *dev,
+					char *name, size_t len)
+{
+	struct dsa_slave_priv *p = netdev_priv(dev);
+
+	if (snprintf(name, len, "p%d", p->port) >= len)
+		return -EINVAL;
 
 	return 0;
 }
@@ -1042,6 +1051,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
 	.ndo_bridge_setlink	= switchdev_port_bridge_setlink,
 	.ndo_bridge_dellink	= switchdev_port_bridge_dellink,
 	.ndo_get_phys_port_id	= dsa_slave_get_phys_port_id,
+	.ndo_get_phys_port_name	= dsa_slave_get_phys_port_name,
 };
 
 static const struct switchdev_ops dsa_slave_switchdev_ops = {
Signature · 1 line
2.9.3
#8 lore raw

PATCH 2/2 Revert "net: dsa: Implement ndo_get_phys_port_id"

In reply to Florian Fainelli

This reverts commit 3a543ef479868e36c95935de320608a7e41466ca ("net: dsa:
Implement ndo_get_phys_port_id") since it misuses the purpose of ndo_get_phys_port_id(). We have ndo_get_phys_port_name() to do the correct thing for us now.

---
 net/dsa/slave.c | 10 ----------
 1 file changed, 10 deletions(-)
net/dsa/slave.c +0 -10
index fed3fbd403cb..0cdcaf526987 100644
@@ -983,15 +983,6 @@ static void dsa_slave_poll_controller(struct net_device *dev)
 }
 #endif
 
-static int dsa_slave_get_phys_port_id(struct net_device *dev,
-				      struct netdev_phys_item_id *ppid)
-{
-	struct dsa_slave_priv *p = netdev_priv(dev);
-
-	ppid->id_len = sizeof(p->port);
-	memcpy(ppid->id, &p->port, ppid->id_len);
-}
-
 static int dsa_slave_get_phys_port_name(struct net_device *dev,
 					char *name, size_t len)
 {
@@ -1050,7 +1041,6 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
 	.ndo_bridge_getlink	= switchdev_port_bridge_getlink,
 	.ndo_bridge_setlink	= switchdev_port_bridge_setlink,
 	.ndo_bridge_dellink	= switchdev_port_bridge_dellink,
-	.ndo_get_phys_port_id	= dsa_slave_get_phys_port_id,
 	.ndo_get_phys_port_name	= dsa_slave_get_phys_port_name,
 };
 
Signature · 1 line
2.9.3
Reviewed-by on v1 2/2
#9 lore raw

Re: [PATCH net-next 2/2] Revert "net: dsa: Implement ndo_get_phys_port_id"

In reply to Florian Fainelli

Hi Florian,

Quoted 6 lines · Florian Fainelli

This reverts commit 3a543ef479868e36c95935de320608a7e41466ca ("net: dsa:
Implement ndo_get_phys_port_id") since it misuses the purpose of ndo_get_phys_port_id(). We have ndo_get_phys_port_name() to do the correct thing for us now.

Thanks,

Vivien

maintainer
#3 lore raw
In reply to Florian Fainelli
Quoted 2 lines · Florian Fainelli

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

At what level does this need to be unique?

We can have multiple switches within one switch cluster. p->port will be unique within one switch, but can be repeated in a cluster.

We can also have multiple clusters, and again p->port will be re-used.

Andrew

#4 lore raw
Quoted 5 lines · Andrew Lunn
Quoted 2 lines · Florian Fainelli

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

At what level does this need to be unique?

This needs to be unique to the switch I would say, ndo_get_phys_switch_id would return the physical number of the switch device in the tree/cluster, so that number plus the port name should be an unique differentiator that is good enough for e.g: a persistent naming rule?

Quoted 5 lines

We can have multiple switches within one switch cluster. p->port will be unique within one switch, but can be repeated in a cluster.

We can also have multiple clusters, and again p->port will be re-used.

Signature · 1 line
Florian
#6 lore raw
In reply to Andrew Lunn

Hi Andrew,

Quoted 5 lines · Andrew Lunn
Quoted 2 lines · Florian Fainelli

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

At what level does this need to be unique?

The port name must be unique at the switch Linux device level.

Thanks,

Vivien

#5 lore raw
In reply to Florian Fainelli
Quoted 8 lines · Tue, Jan 10, 2017 at 09:58:53PM CET, [email protected] wrote:
Quoted 5 lines · Andrew Lunn
Quoted 2 lines · Florian Fainelli

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

At what level does this need to be unique?

This needs to be unique to the switch I would say,

Yes.

Quoted 4 lines

ndo_get_phys_switch_id would return the physical number of the switch device in the tree/cluster, so that number plus the port name should be an unique differentiator that is good enough for e.g: a persistent naming rule?

Yes.

Quoted 10 lines
Quoted 6 lines

We can have multiple switches within one switch cluster. p->port will be unique within one switch, but can be repeated in a cluster.

We can also have multiple clusters, and again p->port will be re-used.

Signature · 1 line
Florian
Reviewed-by on v1 1/2
#7 lore raw
In reply to Florian Fainelli
Quoted 4 lines · Tue, Jan 10, 2017 at 09:32:36PM CET, [email protected] wrote:

Return the physical port number of a DSA created network device using ndo_get_phys_port_name().

Quoted 35 lines

---
net/dsa/slave.c | 10 ++++++++++

1 file changed, 10 insertions(+)
net/dsa/slave.c +10 -0
index 5cd5b8137c08..fed3fbd403cb 100644
@@ -990,6 +990,15 @@ static int dsa_slave_get_phys_port_id(struct net_device *dev,
 
 	ppid->id_len = sizeof(p->port);
 	memcpy(ppid->id, &p->port, ppid->id_len);
+}
+
+static int dsa_slave_get_phys_port_name(struct net_device *dev,
+					char *name, size_t len)
+{
+	struct dsa_slave_priv *p = netdev_priv(dev);
+
+	if (snprintf(name, len, "p%d", p->port) >= len)
+		return -EINVAL;
 
 	return 0;
 }
@@ -1042,6 +1051,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
 	.ndo_bridge_setlink	= switchdev_port_bridge_setlink,
 	.ndo_bridge_dellink	= switchdev_port_bridge_dellink,
 	.ndo_get_phys_port_id	= dsa_slave_get_phys_port_id,
+	.ndo_get_phys_port_name	= dsa_slave_get_phys_port_name,
 };
 
 static const struct switchdev_ops dsa_slave_switchdev_ops = {
Signature · 1 line
2.9.3
Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH net-next 2/2] Revert "net: dsa: Implement ndo_get_phys_port_id"

In reply to Florian Fainelli
Quoted 6 lines · Tue, Jan 10, 2017 at 09:32:37PM CET, [email protected] wrote:

This reverts commit 3a543ef479868e36c95935de320608a7e41466ca ("net: dsa:
Implement ndo_get_phys_port_id") since it misuses the purpose of ndo_get_phys_port_id(). We have ndo_get_phys_port_name() to do the correct thing for us now.

Quoted 35 lines

---
net/dsa/slave.c | 10 ----------

1 file changed, 10 deletions(-)
net/dsa/slave.c +0 -10
index fed3fbd403cb..0cdcaf526987 100644
@@ -983,15 +983,6 @@ static void dsa_slave_poll_controller(struct net_device *dev)
 }
 #endif
 
-static int dsa_slave_get_phys_port_id(struct net_device *dev,
-				      struct netdev_phys_item_id *ppid)
-{
-	struct dsa_slave_priv *p = netdev_priv(dev);
-
-	ppid->id_len = sizeof(p->port);
-	memcpy(ppid->id, &p->port, ppid->id_len);
-}
-
 static int dsa_slave_get_phys_port_name(struct net_device *dev,
 					char *name, size_t len)
 {
@@ -1050,7 +1041,6 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
 	.ndo_bridge_getlink	= switchdev_port_bridge_getlink,
 	.ndo_bridge_setlink	= switchdev_port_bridge_setlink,
 	.ndo_bridge_dellink	= switchdev_port_bridge_dellink,
-	.ndo_get_phys_port_id	= dsa_slave_get_phys_port_id,
 	.ndo_get_phys_port_name	= dsa_slave_get_phys_port_name,
 };
 
Signature · 1 line
2.9.3
maintainer
#11 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Tue, 10 Jan 2017 12:32:35 -0800

Quoted 2 lines

This patch series implements ndo_get_phys_port_name() so we can revert ndo_get_phys_id() which was (ab)used in the DSA layer.

Series applied, thanks Florian.