Following patches will change the way of distributing port object
changes from a switchdev operation to a switchdev notifier. The
switchdev code currently recursively descends through layers of lower
devices, eventually calling the op on a front-panel port device. The
notifier will instead be sent referencing the bridge port device, which
may be a stacking device that's one of front-panel ports uppers, or a
completely unrelated device.

DSA currently doesn't support any other uppers than bridge.
SWITCHDEV_OBJ_ID_HOST_MDB and _PORT_MDB objects are always notified on
the bridge port device. Thus the only case that a stacked device could
be validly referenced by port object notifications are bridge
notifications for VLAN objects added to the bridge itself. But the
driver explicitly rejects such notifications in dsa_port_vlan_add(). It
is therefore safe to assume that the only interesting case is that the
notification is on a front-panel port netdevice. Therefore keep the
filtering by dsa_slave_dev_check() in place.

To handle SWITCHDEV_PORT_OBJ_ADD and _DEL, subscribe to the blocking
notifier chain. Dispatch to rocker_port_obj_add() resp. _del() to
maintain the behavior that the switchdev operation based code currently
has.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Acked-by: Jiri Pirko <j...@mellanox.com>
---
 net/dsa/slave.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 7d0c19e7edcf..d00a0b6d4ce0 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1557,6 +1557,44 @@ static int dsa_slave_switchdev_event(struct 
notifier_block *unused,
        return NOTIFY_BAD;
 }
 
+static int
+dsa_slave_switchdev_port_obj_event(unsigned long event,
+                       struct net_device *netdev,
+                       struct switchdev_notifier_port_obj_info *port_obj_info)
+{
+       int err = -EOPNOTSUPP;
+
+       switch (event) {
+       case SWITCHDEV_PORT_OBJ_ADD:
+               err = dsa_slave_port_obj_add(netdev, port_obj_info->obj,
+                                            port_obj_info->trans);
+               break;
+       case SWITCHDEV_PORT_OBJ_DEL:
+               err = dsa_slave_port_obj_del(netdev, port_obj_info->obj);
+               break;
+       }
+
+       port_obj_info->handled = true;
+       return notifier_from_errno(err);
+}
+
+static int dsa_slave_switchdev_blocking_event(struct notifier_block *unused,
+                                             unsigned long event, void *ptr)
+{
+       struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
+
+       if (!dsa_slave_dev_check(dev))
+               return NOTIFY_DONE;
+
+       switch (event) {
+       case SWITCHDEV_PORT_OBJ_ADD: /* fall through */
+       case SWITCHDEV_PORT_OBJ_DEL:
+               return dsa_slave_switchdev_port_obj_event(event, dev, ptr);
+       }
+
+       return NOTIFY_DONE;
+}
+
 static struct notifier_block dsa_slave_nb __read_mostly = {
        .notifier_call  = dsa_slave_netdevice_event,
 };
@@ -1565,8 +1603,13 @@ static struct notifier_block 
dsa_slave_switchdev_notifier = {
        .notifier_call = dsa_slave_switchdev_event,
 };
 
+static struct notifier_block dsa_slave_switchdev_blocking_notifier = {
+       .notifier_call = dsa_slave_switchdev_blocking_event,
+};
+
 int dsa_slave_register_notifier(void)
 {
+       struct notifier_block *nb;
        int err;
 
        err = register_netdevice_notifier(&dsa_slave_nb);
@@ -1577,8 +1620,15 @@ int dsa_slave_register_notifier(void)
        if (err)
                goto err_switchdev_nb;
 
+       nb = &dsa_slave_switchdev_blocking_notifier;
+       err = register_switchdev_blocking_notifier(nb);
+       if (err)
+               goto err_switchdev_blocking_nb;
+
        return 0;
 
+err_switchdev_blocking_nb:
+       unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
 err_switchdev_nb:
        unregister_netdevice_notifier(&dsa_slave_nb);
        return err;
@@ -1586,8 +1636,14 @@ int dsa_slave_register_notifier(void)
 
 void dsa_slave_unregister_notifier(void)
 {
+       struct notifier_block *nb;
        int err;
 
+       nb = &dsa_slave_switchdev_blocking_notifier;
+       err = unregister_switchdev_blocking_notifier(nb);
+       if (err)
+               pr_err("DSA: failed to unregister switchdev blocking notifier 
(%d)\n", err);
+
        err = unregister_switchdev_notifier(&dsa_slave_switchdev_notifier);
        if (err)
                pr_err("DSA: failed to unregister switchdev notifier (%d)\n", 
err);
-- 
2.4.11

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to