Skip to content

Commit e337dd5

Browse files
yishaihjgunthorpe
authored andcommitted
IB/mlx5: Register DEVX with mlx5_core to get async events
Register DEVX with with mlx5_core to get async events. This will enable to dispatch the applicable events to its consumers in down stream patches. Signed-off-by: Yishai Hadas <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 2afc5e1 commit e337dd5

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

drivers/infiniband/hw/mlx5/devx.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,36 @@ static int devx_umem_cleanup(struct ib_uobject *uobject,
16631663
return 0;
16641664
}
16651665

1666+
static int devx_event_notifier(struct notifier_block *nb,
1667+
unsigned long event_type, void *data)
1668+
{
1669+
return NOTIFY_DONE;
1670+
}
1671+
1672+
void mlx5_ib_devx_init_event_table(struct mlx5_ib_dev *dev)
1673+
{
1674+
struct mlx5_devx_event_table *table = &dev->devx_event_table;
1675+
1676+
xa_init(&table->event_xa);
1677+
mutex_init(&table->event_xa_lock);
1678+
MLX5_NB_INIT(&table->devx_nb, devx_event_notifier, NOTIFY_ANY);
1679+
mlx5_eq_notifier_register(dev->mdev, &table->devx_nb);
1680+
}
1681+
1682+
void mlx5_ib_devx_cleanup_event_table(struct mlx5_ib_dev *dev)
1683+
{
1684+
struct mlx5_devx_event_table *table = &dev->devx_event_table;
1685+
void *entry;
1686+
unsigned long id;
1687+
1688+
mlx5_eq_notifier_unregister(dev->mdev, &table->devx_nb);
1689+
1690+
xa_for_each(&table->event_xa, id, entry)
1691+
kfree(entry);
1692+
1693+
xa_destroy(&table->event_xa);
1694+
}
1695+
16661696
static ssize_t devx_async_cmd_event_read(struct file *filp, char __user *buf,
16671697
size_t count, loff_t *pos)
16681698
{

drivers/infiniband/hw/mlx5/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6630,15 +6630,19 @@ static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev)
66306630
int uid;
66316631

66326632
uid = mlx5_ib_devx_create(dev, false);
6633-
if (uid > 0)
6633+
if (uid > 0) {
66346634
dev->devx_whitelist_uid = uid;
6635+
mlx5_ib_devx_init_event_table(dev);
6636+
}
66356637

66366638
return 0;
66376639
}
66386640
static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev)
66396641
{
6640-
if (dev->devx_whitelist_uid)
6642+
if (dev->devx_whitelist_uid) {
6643+
mlx5_ib_devx_cleanup_event_table(dev);
66416644
mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid);
6645+
}
66426646
}
66436647

66446648
void __mlx5_ib_remove(struct mlx5_ib_dev *dev,

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,13 @@ struct mlx5_ib_pf_eq {
936936
mempool_t *pool;
937937
};
938938

939+
struct mlx5_devx_event_table {
940+
struct mlx5_nb devx_nb;
941+
/* serialize updating the event_xa */
942+
struct mutex event_xa_lock;
943+
struct xarray event_xa;
944+
};
945+
939946
struct mlx5_ib_dev {
940947
struct ib_device ib_dev;
941948
struct mlx5_core_dev *mdev;
@@ -985,6 +992,7 @@ struct mlx5_ib_dev {
985992
u16 devx_whitelist_uid;
986993
struct mlx5_srq_table srq_table;
987994
struct mlx5_async_ctx async_ctx;
995+
struct mlx5_devx_event_table devx_event_table;
988996
};
989997

990998
static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
@@ -1324,6 +1332,8 @@ void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *dev,
13241332
#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
13251333
int mlx5_ib_devx_create(struct mlx5_ib_dev *dev, bool is_user);
13261334
void mlx5_ib_devx_destroy(struct mlx5_ib_dev *dev, u16 uid);
1335+
void mlx5_ib_devx_init_event_table(struct mlx5_ib_dev *dev);
1336+
void mlx5_ib_devx_cleanup_event_table(struct mlx5_ib_dev *dev);
13271337
const struct uverbs_object_tree_def *mlx5_ib_get_devx_tree(void);
13281338
extern const struct uapi_definition mlx5_ib_devx_defs[];
13291339
extern const struct uapi_definition mlx5_ib_flow_defs[];
@@ -1341,6 +1351,8 @@ static inline int
13411351
mlx5_ib_devx_create(struct mlx5_ib_dev *dev,
13421352
bool is_user) { return -EOPNOTSUPP; }
13431353
static inline void mlx5_ib_devx_destroy(struct mlx5_ib_dev *dev, u16 uid) {}
1354+
static inline void mlx5_ib_devx_init_event_table(struct mlx5_ib_dev *dev) {}
1355+
static inline void mlx5_ib_devx_cleanup_event_table(struct mlx5_ib_dev *dev) {}
13441356
static inline bool mlx5_ib_devx_is_flow_dest(void *obj, int *dest_id,
13451357
int *dest_type)
13461358
{

0 commit comments

Comments
 (0)