Skip to content

Commit c30f5d0

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum: Move netdevice NB to struct mlxsw_sp
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>
1 parent 36c0a9d commit c30f5d0

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,9 @@ static int mlxsw_sp_basic_trap_groups_set(struct mlxsw_core *mlxsw_core)
36673667
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
36683668
}
36693669

3670+
static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
3671+
unsigned long event, void *ptr);
3672+
36703673
static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
36713674
const struct mlxsw_bus_info *mlxsw_bus_info)
36723675
{
@@ -3736,6 +3739,16 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
37363739
goto err_router_init;
37373740
}
37383741

3742+
/* Initialize netdevice notifier after router is initialized, so that
3743+
* the event handler can use router structures.
3744+
*/
3745+
mlxsw_sp->netdevice_nb.notifier_call = mlxsw_sp_netdevice_event;
3746+
err = register_netdevice_notifier(&mlxsw_sp->netdevice_nb);
3747+
if (err) {
3748+
dev_err(mlxsw_sp->bus_info->dev, "Failed to register netdev notifier\n");
3749+
goto err_netdev_notifier;
3750+
}
3751+
37393752
err = mlxsw_sp_span_init(mlxsw_sp);
37403753
if (err) {
37413754
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,
37693782
err_acl_init:
37703783
mlxsw_sp_span_fini(mlxsw_sp);
37713784
err_span_init:
3785+
unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
3786+
err_netdev_notifier:
37723787
mlxsw_sp_router_fini(mlxsw_sp);
37733788
err_router_init:
37743789
mlxsw_sp_afa_fini(mlxsw_sp);
@@ -3795,6 +3810,7 @@ static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
37953810
mlxsw_sp_dpipe_fini(mlxsw_sp);
37963811
mlxsw_sp_acl_fini(mlxsw_sp);
37973812
mlxsw_sp_span_fini(mlxsw_sp);
3813+
unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
37983814
mlxsw_sp_router_fini(mlxsw_sp);
37993815
mlxsw_sp_afa_fini(mlxsw_sp);
38003816
mlxsw_sp_counter_pool_fini(mlxsw_sp);
@@ -4501,10 +4517,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
45014517
return notifier_from_errno(err);
45024518
}
45034519

4504-
static struct notifier_block mlxsw_sp_netdevice_nb __read_mostly = {
4505-
.notifier_call = mlxsw_sp_netdevice_event,
4506-
};
4507-
45084520
static struct notifier_block mlxsw_sp_inetaddr_nb __read_mostly = {
45094521
.notifier_call = mlxsw_sp_inetaddr_event,
45104522
.priority = 10, /* Must be called before FIB notifier block */
@@ -4532,7 +4544,6 @@ static int __init mlxsw_sp_module_init(void)
45324544
{
45334545
int err;
45344546

4535-
register_netdevice_notifier(&mlxsw_sp_netdevice_nb);
45364547
register_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
45374548
register_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
45384549
register_netevent_notifier(&mlxsw_sp_router_netevent_nb);
@@ -4553,7 +4564,6 @@ static int __init mlxsw_sp_module_init(void)
45534564
unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb);
45544565
unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
45554566
unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
4556-
unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb);
45574567
return err;
45584568
}
45594569

@@ -4564,7 +4574,6 @@ static void __exit mlxsw_sp_module_exit(void)
45644574
unregister_netevent_notifier(&mlxsw_sp_router_netevent_nb);
45654575
unregister_inet6addr_notifier(&mlxsw_sp_inet6addr_nb);
45664576
unregister_inetaddr_notifier(&mlxsw_sp_inetaddr_nb);
4567-
unregister_netdevice_notifier(&mlxsw_sp_netdevice_nb);
45684577
}
45694578

45704579
module_init(mlxsw_sp_module_init);

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct mlxsw_sp {
161161
struct {
162162
DECLARE_BITMAP(usage, MLXSW_SP_KVD_LINEAR_SIZE);
163163
} kvdl;
164+
struct notifier_block netdevice_nb;
164165

165166
struct mlxsw_sp_counter_pool *counter_pool;
166167
struct {

0 commit comments

Comments
 (0)