Skip to content

Commit df097a2

Browse files
author
Saeed Mahameed
committed
IB/mlx5: Use the new mlx5 core notifier API
Remove the deprecated mlx5_interface->event mlx5_ib callback and use new mlx5 notifier API to subscribe for mlx5 events. For native mlx5_ib devices profiles pf_profile/nic_rep_profile register the notifier callback mlx5_ib_handle_event which treats the notifier context as mlx5_ib_dev. For vport repesentors, don't register any notifier, same as before, they didn't receive any mlx5 events. For slave port (mlx5_ib_multiport_info) register a different notifier callback mlx5_ib_event_slave_port, which knows that the event is coming for mlx5_ib_multiport_info and prepares the event job accordingly. Before this on the event handler work we had to ask mlx5_core if this is a slave port mlx5_core_is_mp_slave(work->dev), now it is not needed anymore. mlx5_ib_multiport_info notifier registration is done on mlx5_ib_bind_slave_port and de-registration is done on mlx5_ib_unbind_slave_port. Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 58d180b commit df097a2

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ static char mlx5_version[] =
8282

8383
struct mlx5_ib_event_work {
8484
struct work_struct work;
85-
struct mlx5_core_dev *dev;
86-
void *context;
85+
union {
86+
struct mlx5_ib_dev *dev;
87+
struct mlx5_ib_multiport_info *mpi;
88+
};
89+
bool is_slave;
8790
enum mlx5_dev_event event;
88-
unsigned long param;
91+
void *param;
8992
};
9093

9194
enum {
@@ -4240,14 +4243,14 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
42404243
struct mlx5_ib_dev *ibdev;
42414244
struct ib_event ibev;
42424245
bool fatal = false;
4243-
u8 port = (u8)work->param;
4246+
u8 port = (u8)(unsigned long)work->param;
42444247

4245-
if (mlx5_core_is_mp_slave(work->dev)) {
4246-
ibdev = mlx5_ib_get_ibdev_from_mpi(work->context);
4248+
if (work->is_slave) {
4249+
ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi);
42474250
if (!ibdev)
42484251
goto out;
42494252
} else {
4250-
ibdev = work->context;
4253+
ibdev = work->dev;
42514254
}
42524255

42534256
switch (work->event) {
@@ -4256,7 +4259,6 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
42564259
mlx5_ib_handle_internal_error(ibdev);
42574260
fatal = true;
42584261
break;
4259-
42604262
case MLX5_DEV_EVENT_PORT_UP:
42614263
case MLX5_DEV_EVENT_PORT_DOWN:
42624264
case MLX5_DEV_EVENT_PORT_INITIALIZED:
@@ -4311,22 +4313,43 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
43114313
kfree(work);
43124314
}
43134315

4314-
static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
4315-
enum mlx5_dev_event event, unsigned long param)
4316+
static int mlx5_ib_event(struct notifier_block *nb,
4317+
unsigned long event, void *param)
43164318
{
43174319
struct mlx5_ib_event_work *work;
43184320

43194321
work = kmalloc(sizeof(*work), GFP_ATOMIC);
43204322
if (!work)
4321-
return;
4323+
return NOTIFY_DONE;
43224324

43234325
INIT_WORK(&work->work, mlx5_ib_handle_event);
4324-
work->dev = dev;
4326+
work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events);
4327+
work->is_slave = false;
43254328
work->param = param;
4326-
work->context = context;
43274329
work->event = event;
43284330

43294331
queue_work(mlx5_ib_event_wq, &work->work);
4332+
4333+
return NOTIFY_OK;
4334+
}
4335+
4336+
static int mlx5_ib_event_slave_port(struct notifier_block *nb,
4337+
unsigned long event, void *param)
4338+
{
4339+
struct mlx5_ib_event_work *work;
4340+
4341+
work = kmalloc(sizeof(*work), GFP_ATOMIC);
4342+
if (!work)
4343+
return NOTIFY_DONE;
4344+
4345+
INIT_WORK(&work->work, mlx5_ib_handle_event);
4346+
work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events);
4347+
work->is_slave = true;
4348+
work->param = param;
4349+
work->event = event;
4350+
queue_work(mlx5_ib_event_wq, &work->work);
4351+
4352+
return NOTIFY_OK;
43304353
}
43314354

43324355
static int set_has_smi_cap(struct mlx5_ib_dev *dev)
@@ -5357,6 +5380,11 @@ static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev,
53575380
spin_unlock(&port->mp.mpi_lock);
53585381
return;
53595382
}
5383+
5384+
if (mpi->mdev_events.notifier_call)
5385+
mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events);
5386+
mpi->mdev_events.notifier_call = NULL;
5387+
53605388
mpi->ibdev = NULL;
53615389

53625390
spin_unlock(&port->mp.mpi_lock);
@@ -5412,6 +5440,7 @@ static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev,
54125440

54135441
ibdev->port[port_num].mp.mpi = mpi;
54145442
mpi->ibdev = ibdev;
5443+
mpi->mdev_events.notifier_call = NULL;
54155444
spin_unlock(&ibdev->port[port_num].mp.mpi_lock);
54165445

54175446
err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev);
@@ -5429,6 +5458,9 @@ static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev,
54295458
goto unbind;
54305459
}
54315460

5461+
mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port;
5462+
mlx5_notifier_register(mpi->mdev, &mpi->mdev_events);
5463+
54325464
err = mlx5_ib_init_cong_debugfs(ibdev, port_num);
54335465
if (err)
54345466
goto unbind;
@@ -6163,6 +6195,18 @@ static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev)
61636195
mlx5_ib_unregister_vport_reps(dev);
61646196
}
61656197

6198+
static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev)
6199+
{
6200+
dev->mdev_events.notifier_call = mlx5_ib_event;
6201+
mlx5_notifier_register(dev->mdev, &dev->mdev_events);
6202+
return 0;
6203+
}
6204+
6205+
static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev)
6206+
{
6207+
mlx5_notifier_unregister(dev->mdev, &dev->mdev_events);
6208+
}
6209+
61666210
void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
61676211
const struct mlx5_ib_profile *profile,
61686212
int stage)
@@ -6228,6 +6272,9 @@ static const struct mlx5_ib_profile pf_profile = {
62286272
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
62296273
mlx5_ib_stage_dev_res_init,
62306274
mlx5_ib_stage_dev_res_cleanup),
6275+
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER,
6276+
mlx5_ib_stage_dev_notifier_init,
6277+
mlx5_ib_stage_dev_notifier_cleanup),
62316278
STAGE_CREATE(MLX5_IB_STAGE_ODP,
62326279
mlx5_ib_stage_odp_init,
62336280
mlx5_ib_stage_odp_cleanup),
@@ -6279,6 +6326,9 @@ static const struct mlx5_ib_profile nic_rep_profile = {
62796326
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
62806327
mlx5_ib_stage_dev_res_init,
62816328
mlx5_ib_stage_dev_res_cleanup),
6329+
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER,
6330+
mlx5_ib_stage_dev_notifier_init,
6331+
mlx5_ib_stage_dev_notifier_cleanup),
62826332
STAGE_CREATE(MLX5_IB_STAGE_COUNTERS,
62836333
mlx5_ib_stage_counters_init,
62846334
mlx5_ib_stage_counters_cleanup),
@@ -6399,7 +6449,6 @@ static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
63996449
static struct mlx5_interface mlx5_ib_interface = {
64006450
.add = mlx5_ib_add,
64016451
.remove = mlx5_ib_remove,
6402-
.event = mlx5_ib_event,
64036452
.protocol = MLX5_INTERFACE_PROTOCOL_IB,
64046453
};
64056454

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ enum mlx5_ib_stages {
775775
MLX5_IB_STAGE_NON_DEFAULT_CB,
776776
MLX5_IB_STAGE_ROCE,
777777
MLX5_IB_STAGE_DEVICE_RESOURCES,
778+
MLX5_IB_STAGE_DEVICE_NOTIFIER,
778779
MLX5_IB_STAGE_ODP,
779780
MLX5_IB_STAGE_COUNTERS,
780781
MLX5_IB_STAGE_CONG_DEBUGFS,
@@ -806,6 +807,7 @@ struct mlx5_ib_multiport_info {
806807
struct list_head list;
807808
struct mlx5_ib_dev *ibdev;
808809
struct mlx5_core_dev *mdev;
810+
struct notifier_block mdev_events;
809811
struct completion unref_comp;
810812
u64 sys_image_guid;
811813
u32 mdev_refcnt;
@@ -893,6 +895,7 @@ struct mlx5_ib_dev {
893895
struct ib_device ib_dev;
894896
const struct uverbs_object_tree_def *driver_trees[7];
895897
struct mlx5_core_dev *mdev;
898+
struct notifier_block mdev_events;
896899
struct mlx5_roce roce[MLX5_MAX_PORTS];
897900
int num_ports;
898901
/* serialize update of capability mask

0 commit comments

Comments
 (0)