]> git.droids-corp.org - dpdk.git/commitdiff
common/mlx5: glue device and PD import
authorMichael Baum <michaelba@nvidia.com>
Thu, 24 Feb 2022 23:25:07 +0000 (01:25 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 25 Feb 2022 16:33:31 +0000 (17:33 +0100)
Add support for rdma-core API to import device.
The API gets ibv_context file descriptor and returns an ibv_context
pointer that is associated with the given file descriptor.
Add also support for rdma-core API to import PD.
The API gets ibv_context and PD handle and returns a protection domain
(PD) that is associated with the given handle in the given context.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/common/mlx5/linux/meson.build
drivers/common/mlx5/linux/mlx5_glue.c
drivers/common/mlx5/linux/mlx5_glue.h

index 4c7b53b9bd26989b7cacec8716f73cd0d0164c99..ed48245c679ef9a5c2a9fe0e5db4c2fe73b3b6d8 100644 (file)
@@ -202,6 +202,8 @@ has_sym_args = [
             'mlx5dv_dr_domain_allow_duplicate_rules' ],
         [ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
             'ibv_reg_mr_iova' ],
+        [ 'HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR', 'infiniband/verbs.h',
+            'ibv_import_device' ],
 ]
 config = configuration_data()
 foreach arg:has_sym_args
index bc6622053fcec771c3d27ba18f843359a3cc7eaf..450dd6a06a14d7312d4fead3555701f6b723c3ed 100644 (file)
@@ -34,6 +34,32 @@ mlx5_glue_dealloc_pd(struct ibv_pd *pd)
        return ibv_dealloc_pd(pd);
 }
 
+static struct ibv_pd *
+mlx5_glue_import_pd(struct ibv_context *context, uint32_t pd_handle)
+{
+#ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
+       return ibv_import_pd(context, pd_handle);
+#else
+       (void)context;
+       (void)pd_handle;
+       errno = ENOTSUP;
+       return NULL;
+#endif
+}
+
+static int
+mlx5_glue_unimport_pd(struct ibv_pd *pd)
+{
+#ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
+       ibv_unimport_pd(pd);
+       return 0;
+#else
+       (void)pd;
+       errno = ENOTSUP;
+       return -errno;
+#endif
+}
+
 static struct ibv_device **
 mlx5_glue_get_device_list(int *num_devices)
 {
@@ -52,6 +78,18 @@ mlx5_glue_open_device(struct ibv_device *device)
        return ibv_open_device(device);
 }
 
+static struct ibv_context *
+mlx5_glue_import_device(int cmd_fd)
+{
+#ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
+       return ibv_import_device(cmd_fd);
+#else
+       (void)cmd_fd;
+       errno = ENOTSUP;
+       return NULL;
+#endif
+}
+
 static int
 mlx5_glue_close_device(struct ibv_context *context)
 {
@@ -1402,9 +1440,12 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
        .fork_init = mlx5_glue_fork_init,
        .alloc_pd = mlx5_glue_alloc_pd,
        .dealloc_pd = mlx5_glue_dealloc_pd,
+       .import_pd = mlx5_glue_import_pd,
+       .unimport_pd = mlx5_glue_unimport_pd,
        .get_device_list = mlx5_glue_get_device_list,
        .free_device_list = mlx5_glue_free_device_list,
        .open_device = mlx5_glue_open_device,
+       .import_device = mlx5_glue_import_device,
        .close_device = mlx5_glue_close_device,
        .query_device = mlx5_glue_query_device,
        .query_device_ex = mlx5_glue_query_device_ex,
index 4e6d31f263e82e42dca9b3027a65734831c16f72..c4903a6dce3fdd52e4176cb8948ca261c562d8da 100644 (file)
@@ -151,9 +151,13 @@ struct mlx5_glue {
        int (*fork_init)(void);
        struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
        int (*dealloc_pd)(struct ibv_pd *pd);
+       struct ibv_pd *(*import_pd)(struct ibv_context *context,
+                                   uint32_t pd_handle);
+       int (*unimport_pd)(struct ibv_pd *pd);
        struct ibv_device **(*get_device_list)(int *num_devices);
        void (*free_device_list)(struct ibv_device **list);
        struct ibv_context *(*open_device)(struct ibv_device *device);
+       struct ibv_context *(*import_device)(int cmd_fd);
        int (*close_device)(struct ibv_context *context);
        int (*query_device)(struct ibv_context *context,
                            struct ibv_device_attr *device_attr);