staging: fsl-dpaa2: ethsw: Handle SWITCHDEV_PORT_OBJ_ADD/_DEL
authorPetr Machata <petrm@mellanox.com>
Thu, 22 Nov 2018 23:29:30 +0000 (23:29 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 24 Nov 2018 02:02:24 +0000 (18:02 -0800)
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.

ethsw currently doesn't support any uppers other 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 port_vlans_add(). It is
therefore safe to assume that the only interesting case is that the
notification is on a front-panel port netdevice.

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

Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/staging/fsl-dpaa2/ethsw/ethsw.c

index e379b0fa936f092c659a98fdbb982be082cfc69e..83e1d92dc7f3440fedcbd51fd0c6b0334f10328d 100644 (file)
@@ -1088,10 +1088,51 @@ err_addr_alloc:
        return NOTIFY_BAD;
 }
 
+static int
+ethsw_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 = swdev_port_obj_add(netdev, port_obj_info->obj,
+                                        port_obj_info->trans);
+               break;
+       case SWITCHDEV_PORT_OBJ_DEL:
+               err = swdev_port_obj_del(netdev, port_obj_info->obj);
+               break;
+       }
+
+       port_obj_info->handled = true;
+       return notifier_from_errno(err);
+}
+
+static int port_switchdev_blocking_event(struct notifier_block *unused,
+                                        unsigned long event, void *ptr)
+{
+       struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
+
+       if (!ethsw_port_dev_check(dev))
+               return NOTIFY_DONE;
+
+       switch (event) {
+       case SWITCHDEV_PORT_OBJ_ADD: /* fall through */
+       case SWITCHDEV_PORT_OBJ_DEL:
+               return ethsw_switchdev_port_obj_event(event, dev, ptr);
+       }
+
+       return NOTIFY_DONE;
+}
+
 static struct notifier_block port_switchdev_nb = {
        .notifier_call = port_switchdev_event,
 };
 
+static struct notifier_block port_switchdev_blocking_nb = {
+       .notifier_call = port_switchdev_blocking_event,
+};
+
 static int ethsw_register_notifier(struct device *dev)
 {
        int err;
@@ -1108,8 +1149,16 @@ static int ethsw_register_notifier(struct device *dev)
                goto err_switchdev_nb;
        }
 
+       err = register_switchdev_blocking_notifier(&port_switchdev_blocking_nb);
+       if (err) {
+               dev_err(dev, "Failed to register switchdev blocking notifier\n");
+               goto err_switchdev_blocking_nb;
+       }
+
        return 0;
 
+err_switchdev_blocking_nb:
+       unregister_switchdev_notifier(&port_switchdev_nb);
 err_switchdev_nb:
        unregister_netdevice_notifier(&port_nb);
        return err;
@@ -1296,8 +1345,15 @@ static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port)
 
 static void ethsw_unregister_notifier(struct device *dev)
 {
+       struct notifier_block *nb;
        int err;
 
+       nb = &port_switchdev_blocking_nb;
+       err = unregister_switchdev_blocking_notifier(nb);
+       if (err)
+               dev_err(dev,
+                       "Failed to unregister switchdev blocking notifier (%d)\n", err);
+
        err = unregister_switchdev_notifier(&port_switchdev_nb);
        if (err)
                dev_err(dev,