]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mlxsw: spectrum: Move netdevice NB to struct mlxsw_sp
authorPetr Machata <petrm@mellanox.com>
Mon, 16 Oct 2017 14:26:35 +0000 (16:26 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Oct 2017 20:30:32 +0000 (21:30 +0100)
So far, all netdevice notifications that the driver cared about were
related to its own ports, and mlxsw_sp could be retrieved from the
netdevice's private data. For IP-in-IP offloading however, the driver
cares about events on foreign netdevices, and getting at mlxsw_sp or
router data structures from the handler is inconvenient.

Therefore move the netdevice notifier blocks from global scope to struct
mlxsw_sp to allow retrieval from the notifier block pointer itself.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h

index 321988ac57ccb21a29633982f4d1560e470cbc15..83f9c2564f61799711ddd92a99713ed2d93300ae 100644 (file)
@@ -3667,6 +3667,9 @@ static int mlxsw_sp_basic_trap_groups_set(struct mlxsw_core *mlxsw_core)
        return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
 }
 
+static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
+                                   unsigned long event, void *ptr);
+
 static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
                         const struct mlxsw_bus_info *mlxsw_bus_info)
 {
@@ -3736,6 +3739,16 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
                goto err_router_init;
        }
 
+       /* Initialize netdevice notifier after router is initialized, so that
+        * the event handler can use router structures.
+        */
+       mlxsw_sp->netdevice_nb.notifier_call = mlxsw_sp_netdevice_event;
+       err = register_netdevice_notifier(&mlxsw_sp->netdevice_nb);
+       if (err) {
+               dev_err(mlxsw_sp->bus_info->dev, "Failed to register netdev notifier\n");
+               goto err_netdev_notifier;
+       }
+
        err = mlxsw_sp_span_init(mlxsw_sp);
        if (err) {
                dev_err(mlxsw_sp->bus_info->dev, "Failed to init span system\n");
@@ -3769,6 +3782,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
 err_acl_init:
        mlxsw_sp_span_fini(mlxsw_sp);
 err_span_init:
+       unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
+err_netdev_notifier:
        mlxsw_sp_router_fini(mlxsw_sp);
 err_router_init:
        mlxsw_sp_afa_fini(mlxsw_sp);
@@ -3795,6 +3810,7 @@ static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
        mlxsw_sp_dpipe_fini(mlxsw_sp);
        mlxsw_sp_acl_fini(mlxsw_sp);
        mlxsw_sp_span_fini(mlxsw_sp);
+       unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
        mlxsw_sp_router_fini(mlxsw_sp);
        mlxsw_sp_afa_fini(mlxsw_sp);
        mlxsw_sp_counter_pool_fini(mlxsw_sp);
@@ -4501,10 +4517,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
        return notifier_from_errno(err);
 }
 
-static struct notifier_block mlxsw_sp_netdevice_nb __read_mostly = {
-       .notifier_call = mlxsw_sp_netdevice_event,
-};
-
 static struct notifier_block mlxsw_sp_inetaddr_nb __read_mostly = {
        .notifier_call = mlxsw_sp_inetaddr_event,
        .priority = 10, /* Must be called before FIB notifier block */
@@ -4532,7 +4544,6 @@ static int __init mlxsw_sp_module_init(void)
 {
        int err;
 
-       register_netdevice_notifier(&mlxsw_sp_netdevice_nb);
        register_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
        register_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
        register_netevent_notifier(&mlxsw_sp_router_netevent_nb);
@@ -4553,7 +4564,6 @@ static int __init mlxsw_sp_module_init(void)
        unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb);
        unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
        unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
-       unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb);
        return err;
 }
 
@@ -4564,7 +4574,6 @@ static void __exit mlxsw_sp_module_exit(void)
        unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb);
        unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
        unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
-       unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb);
 }
 
 module_init(mlxsw_sp_module_init);
index 8e45183dc9bbbb5d02e823f01a8d30f081f9d473..e1a0157c0b94fcf20ba7c7e9681bc8d4c04121b1 100644 (file)
@@ -161,6 +161,7 @@ struct mlxsw_sp {
        struct {
                DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE);
        } kvdl;
+       struct notifier_block netdevice_nb;
 
        struct mlxsw_sp_counter_pool *counter_pool;
        struct {