diff mbox

[RFC,net-next,2/2] net: dsa: support SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF

Message ID 1457545368-20647-3-git-send-email-vivien.didelot@savoirfairelinux.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Vivien Didelot March 9, 2016, 5:42 p.m. UTC
Add a new dsa_slave_bridge_if function to handle the
SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF switchdev attribute.

Thus remove the code related to the netdev notifier block.

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

Comments

Andrew Lunn March 9, 2016, 6:32 p.m. UTC | #1
Hi Vivien

> -static bool dsa_slave_dev_check(struct net_device *dev)
> -{
> -	return dev->netdev_ops == &dsa_slave_netdev_ops;
> -}

Where is the equivalent of this happening? Where do we check that the
interface added to the bridge is part of the switch?

> -int dsa_slave_netdevice_event(struct notifier_block *unused,
> -			      unsigned long event, void *ptr)
> -{
> -	struct net_device *dev;
> -	int err = 0;
> -
> -	switch (event) {
> -	case NETDEV_CHANGEUPPER:
> -		dev = netdev_notifier_info_to_dev(ptr);
> -		if (!dsa_slave_dev_check(dev))
> -			goto out;
> -
> -		err = dsa_slave_master_changed(dev);
> -		if (err && err != -EOPNOTSUPP)
> -			netdev_warn(dev, "failed to reflect master change\n");
> -
> -		break;
> -	}
> -
> -out:
> -	return NOTIFY_DONE;
> -}

How about team/bonding? We are not ready to implement it yet with the
Marvell devices, but at some point we probably will. Won't we need the
events then? We need to know when a switch port has been added to a
team?

Or do you think a switchdev object will be added for this case?
Mellanox already have the ability to add switch interfaces to a team,
and then add the team to a bridge. So we need to ensure your solution
works for such stacked systems.

      Andrew
Jiri Pirko March 9, 2016, 7:24 p.m. UTC | #2
Wed, Mar 09, 2016 at 07:32:13PM CET, andrew@lunn.ch wrote:
>Hi Vivien
>
>> -static bool dsa_slave_dev_check(struct net_device *dev)
>> -{
>> -	return dev->netdev_ops == &dsa_slave_netdev_ops;
>> -}
>
>Where is the equivalent of this happening? Where do we check that the
>interface added to the bridge is part of the switch?
>
>> -int dsa_slave_netdevice_event(struct notifier_block *unused,
>> -			      unsigned long event, void *ptr)
>> -{
>> -	struct net_device *dev;
>> -	int err = 0;
>> -
>> -	switch (event) {
>> -	case NETDEV_CHANGEUPPER:
>> -		dev = netdev_notifier_info_to_dev(ptr);
>> -		if (!dsa_slave_dev_check(dev))
>> -			goto out;
>> -
>> -		err = dsa_slave_master_changed(dev);
>> -		if (err && err != -EOPNOTSUPP)
>> -			netdev_warn(dev, "failed to reflect master change\n");
>> -
>> -		break;
>> -	}
>> -
>> -out:
>> -	return NOTIFY_DONE;
>> -}
>
>How about team/bonding? We are not ready to implement it yet with the
>Marvell devices, but at some point we probably will. Won't we need the
>events then? We need to know when a switch port has been added to a
>team?
>
>Or do you think a switchdev object will be added for this case?
>Mellanox already have the ability to add switch interfaces to a team,
>and then add the team to a bridge. So we need to ensure your solution
>works for such stacked systems.

I have to look at this more closer tomorrow, but I'm missing motivation
behind this. Using existing notifiers, drivers can easily monitor what
is going on with their uppers. Why do we need this to be changed?
Vivien Didelot March 9, 2016, 7:32 p.m. UTC | #3
Hi Andrew,

Andrew Lunn <andrew@lunn.ch> writes:

>> -static bool dsa_slave_dev_check(struct net_device *dev)
>> -{
>> -	return dev->netdev_ops == &dsa_slave_netdev_ops;
>> -}
>
> Where is the equivalent of this happening? Where do we check that the
> interface added to the bridge is part of the switch?

Why should we check that? In this RFC, br_if.c tries to set the new
attribute to the net_device, when creating and deleting the net bridge
port. If it supports attr_set and this attribute, then we're good. Or am
I missing something?

>> -int dsa_slave_netdevice_event(struct notifier_block *unused,
>> -			      unsigned long event, void *ptr)
>> -{
>> -	struct net_device *dev;
>> -	int err = 0;
>> -
>> -	switch (event) {
>> -	case NETDEV_CHANGEUPPER:
>> -		dev = netdev_notifier_info_to_dev(ptr);
>> -		if (!dsa_slave_dev_check(dev))
>> -			goto out;
>> -
>> -		err = dsa_slave_master_changed(dev);
>> -		if (err && err != -EOPNOTSUPP)
>> -			netdev_warn(dev, "failed to reflect master change\n");
>> -
>> -		break;
>> -	}
>> -
>> -out:
>> -	return NOTIFY_DONE;
>> -}
>
> How about team/bonding? We are not ready to implement it yet with the
> Marvell devices, but at some point we probably will. Won't we need the
> events then? We need to know when a switch port has been added to a
> team?
>
> Or do you think a switchdev object will be added for this case?
> Mellanox already have the ability to add switch interfaces to a team,
> and then add the team to a bridge. So we need to ensure your solution
> works for such stacked systems.

Indeed these features can be propagated through new switchdev attributes
or objects.

I think it'd be preferable to factorize the switch related operations
into the switchdev API, instead of having every single switchdev user
implement its custom (but similar) listeners and checks for global
netdev events. What do you think?

Best,
Vivien
Andrew Lunn March 9, 2016, 8:07 p.m. UTC | #4
On Wed, Mar 09, 2016 at 02:32:05PM -0500, Vivien Didelot wrote:
> Hi Andrew,
> 
> Andrew Lunn <andrew@lunn.ch> writes:
> 
> >> -static bool dsa_slave_dev_check(struct net_device *dev)
> >> -{
> >> -	return dev->netdev_ops == &dsa_slave_netdev_ops;
> >> -}
> >
> > Where is the equivalent of this happening? Where do we check that the
> > interface added to the bridge is part of the switch?
> 
> Why should we check that? In this RFC, br_if.c tries to set the new
> attribute to the net_device, when creating and deleting the net bridge
> port. If it supports attr_set and this attribute, then we're good. Or am
> I missing something?

One of us is missing something...

What happens if i have two dsa clusters? We probably want to limit the
object to only being passed to the DSA cluster which contains the
port, or once we receive the object, we verify it belongs to the
cluster processing it.

What happens with a team/bind interface is added to the bridge. In the
future we need to know about this, so we can add the trunk in Marvells
terms to the bridge.

> > How about team/bonding? We are not ready to implement it yet with the
> > Marvell devices, but at some point we probably will. Won't we need the
> > events then? We need to know when a switch port has been added to a
> > team?
> >
> > Or do you think a switchdev object will be added for this case?
> > Mellanox already have the ability to add switch interfaces to a team,
> > and then add the team to a bridge. So we need to ensure your solution
> > works for such stacked systems.
> 
> Indeed these features can be propagated through new switchdev attributes
> or objects.
> 
> I think it'd be preferable to factorize the switch related operations
> into the switchdev API, instead of having every single switchdev user
> implement its custom (but similar) listeners and checks for global
> netdev events. What do you think?

Centralizing the code would be good. But DSA is way behind what
Mellanox can do, so you need to look at how your changes fit into
their driver.

During a netdev 1.1 BOF there was a conversation about the stack of
interfaces, teams/bonds, bridges, etc. If the video is available, you
might find it interesting.

      Andrew
Vivien Didelot March 9, 2016, 10:15 p.m. UTC | #5
Hi Jiri,

Jiri Pirko <jiri@resnulli.us> writes:

> Wed, Mar 09, 2016 at 07:32:13PM CET, andrew@lunn.ch wrote:
>>Hi Vivien
>>
>>> -static bool dsa_slave_dev_check(struct net_device *dev)
>>> -{
>>> -	return dev->netdev_ops == &dsa_slave_netdev_ops;
>>> -}
>>
>>Where is the equivalent of this happening? Where do we check that the
>>interface added to the bridge is part of the switch?
>>
>>> -int dsa_slave_netdevice_event(struct notifier_block *unused,
>>> -			      unsigned long event, void *ptr)
>>> -{
>>> -	struct net_device *dev;
>>> -	int err = 0;
>>> -
>>> -	switch (event) {
>>> -	case NETDEV_CHANGEUPPER:
>>> -		dev = netdev_notifier_info_to_dev(ptr);
>>> -		if (!dsa_slave_dev_check(dev))
>>> -			goto out;
>>> -
>>> -		err = dsa_slave_master_changed(dev);
>>> -		if (err && err != -EOPNOTSUPP)
>>> -			netdev_warn(dev, "failed to reflect master change\n");
>>> -
>>> -		break;
>>> -	}
>>> -
>>> -out:
>>> -	return NOTIFY_DONE;
>>> -}
>>
>>How about team/bonding? We are not ready to implement it yet with the
>>Marvell devices, but at some point we probably will. Won't we need the
>>events then? We need to know when a switch port has been added to a
>>team?
>>
>>Or do you think a switchdev object will be added for this case?
>>Mellanox already have the ability to add switch interfaces to a team,
>>and then add the team to a bridge. So we need to ensure your solution
>>works for such stacked systems.
>
> I have to look at this more closer tomorrow, but I'm missing motivation
> behind this. Using existing notifiers, drivers can easily monitor what
> is going on with their uppers. Why do we need this to be changed?

Yes with notifiers, drivers can monitor these changes with the
NETDEV_CHANGEUPPER even. They can also forbid such bridging by returning
NOTIFY_BAD in the NETDEV_PRECHANGEUPPER event if I'm not mistaken.

But looking at DSA slave, Mellanox Spectrum, and Rocker, they all
implement this similar heavy code, while they could support a common
switchdev attribute and reduce boilerplate.

But maybe I'm wrong, what why I sent that as an RFC :-)

Thanks,
Vivien
diff mbox

Patch

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index fa4daba..cfb678b 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -977,10 +977,6 @@  static struct packet_type dsa_pack_type __read_mostly = {
 	.func	= dsa_switch_rcv,
 };
 
-static struct notifier_block dsa_netdevice_nb __read_mostly = {
-	.notifier_call	= dsa_slave_netdevice_event,
-};
-
 #ifdef CONFIG_PM_SLEEP
 static int dsa_suspend(struct device *d)
 {
@@ -1047,8 +1043,6 @@  static int __init dsa_init_module(void)
 {
 	int rc;
 
-	register_netdevice_notifier(&dsa_netdevice_nb);
-
 	rc = platform_driver_register(&dsa_driver);
 	if (rc)
 		return rc;
@@ -1061,7 +1055,6 @@  module_init(dsa_init_module);
 
 static void __exit dsa_cleanup_module(void)
 {
-	unregister_netdevice_notifier(&dsa_netdevice_nb);
 	dev_remove_pack(&dsa_pack_type);
 	platform_driver_unregister(&dsa_driver);
 }
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 1d1a546..34d1951 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -64,8 +64,6 @@  int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
 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);
-int dsa_slave_netdevice_event(struct notifier_block *unused,
-			      unsigned long event, void *ptr);
 
 /* tag_dsa.c */
 extern const struct dsa_device_ops dsa_netdev_ops;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 27bf03d..90ef149 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -305,16 +305,38 @@  static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	return -EOPNOTSUPP;
 }
 
-static int dsa_slave_stp_update(struct net_device *dev, u8 state)
+static int dsa_slave_bridge_if(struct net_device *dev,
+			       const struct switchdev_attr *attr,
+			       struct switchdev_trans *trans)
 {
 	struct dsa_slave_priv *p = netdev_priv(dev);
 	struct dsa_switch *ds = p->parent;
-	int ret = -EOPNOTSUPP;
+	int err;
 
-	if (ds->drv->port_stp_update)
-		ret = ds->drv->port_stp_update(ds, p->port, state);
+	if (switchdev_trans_ph_prepare(trans)) {
+		if (!ds->drv->port_join_bridge || !ds->drv->port_leave_bridge)
+			return -EOPNOTSUPP;
+		return 0;
+	}
 
-	return ret;
+	if (attr->u.join) {
+		err = ds->drv->port_join_bridge(ds, p->port, attr->orig_dev);
+		if (!err)
+			p->bridge_dev = attr->orig_dev;
+	} else {
+		err = ds->drv->port_leave_bridge(ds, p->port);
+
+		/* When a port leaves a bridge, the bridge layer sets its STP
+		 * state to DISABLED. Restore FORWARDING to keep it functional.
+		 */
+		if (ds->drv->port_stp_update)
+			ds->drv->port_stp_update(ds, p->port,
+						 BR_STATE_FORWARDING);
+
+		p->bridge_dev = NULL;
+	}
+
+	return err;
 }
 
 static int dsa_slave_vlan_filtering(struct net_device *dev,
@@ -354,6 +376,9 @@  static int dsa_slave_port_attr_set(struct net_device *dev,
 	case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
 		ret = dsa_slave_vlan_filtering(dev, attr, trans);
 		break;
+	case SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF:
+		ret = dsa_slave_bridge_if(dev, attr, trans);
+		break;
 	default:
 		ret = -EOPNOTSUPP;
 		break;
@@ -439,41 +464,6 @@  static int dsa_slave_port_obj_dump(struct net_device *dev,
 	return err;
 }
 
-static int dsa_slave_bridge_port_join(struct net_device *dev,
-				      struct net_device *br)
-{
-	struct dsa_slave_priv *p = netdev_priv(dev);
-	struct dsa_switch *ds = p->parent;
-	int ret = -EOPNOTSUPP;
-
-	p->bridge_dev = br;
-
-	if (ds->drv->port_join_bridge)
-		ret = ds->drv->port_join_bridge(ds, p->port, br);
-
-	return ret;
-}
-
-static int dsa_slave_bridge_port_leave(struct net_device *dev)
-{
-	struct dsa_slave_priv *p = netdev_priv(dev);
-	struct dsa_switch *ds = p->parent;
-	int ret = -EOPNOTSUPP;
-
-
-	if (ds->drv->port_leave_bridge)
-		ret = ds->drv->port_leave_bridge(ds, p->port);
-
-	p->bridge_dev = NULL;
-
-	/* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer,
-	 * so allow it to be in BR_STATE_FORWARDING to be kept functional
-	 */
-	dsa_slave_stp_update(dev, BR_STATE_FORWARDING);
-
-	return ret;
-}
-
 static int dsa_slave_port_attr_get(struct net_device *dev,
 				   struct switchdev_attr *attr)
 {
@@ -1136,46 +1126,3 @@  void dsa_slave_destroy(struct net_device *slave_dev)
 	unregister_netdev(slave_dev);
 	free_netdev(slave_dev);
 }
-
-static bool dsa_slave_dev_check(struct net_device *dev)
-{
-	return dev->netdev_ops == &dsa_slave_netdev_ops;
-}
-
-static int dsa_slave_master_changed(struct net_device *dev)
-{
-	struct net_device *master = netdev_master_upper_dev_get(dev);
-	struct dsa_slave_priv *p = netdev_priv(dev);
-	int err = 0;
-
-	if (master && master->rtnl_link_ops &&
-	    !strcmp(master->rtnl_link_ops->kind, "bridge"))
-		err = dsa_slave_bridge_port_join(dev, master);
-	else if (dsa_port_is_bridged(p))
-		err = dsa_slave_bridge_port_leave(dev);
-
-	return err;
-}
-
-int dsa_slave_netdevice_event(struct notifier_block *unused,
-			      unsigned long event, void *ptr)
-{
-	struct net_device *dev;
-	int err = 0;
-
-	switch (event) {
-	case NETDEV_CHANGEUPPER:
-		dev = netdev_notifier_info_to_dev(ptr);
-		if (!dsa_slave_dev_check(dev))
-			goto out;
-
-		err = dsa_slave_master_changed(dev);
-		if (err && err != -EOPNOTSUPP)
-			netdev_warn(dev, "failed to reflect master change\n");
-
-		break;
-	}
-
-out:
-	return NOTIFY_DONE;
-}