mlx5: Introduce mlx5dv_devx_uar_export_dmabuf_fd() This API exports a dmabuf fd that is associated with a given mlx5dv_devx_uar. Upon success the returned fd can be used for DMA and RDMA operations associated with it. Once the usage has been ended, close() should be called while supplying the fd. This call will release the resources that were earlier allocated using the mlx5dv_devx_uar_export_dmabuf_fd() API. A detailed man page was added as well. Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols index 256d80f..e280809 100644 --- a/debian/ibverbs-providers.symbols +++ b/debian/ibverbs-providers.symbols
@@ -33,6 +33,7 @@ MLX5_1.23@MLX5_1.23 40 MLX5_1.24@MLX5_1.24 42 MLX5_1.25@MLX5_1.25 54 + MLX5_1.26@MLX5_1.26 62 mlx5dv_init_obj@MLX5_1.0 13 mlx5dv_init_obj@MLX5_1.2 15 mlx5dv_query_device@MLX5_1.0 13 @@ -55,6 +56,7 @@ mlx5dv_devx_obj_modify@MLX5_1.7 21 mlx5dv_devx_obj_query@MLX5_1.7 21 mlx5dv_devx_query_eqn@MLX5_1.7 21 + mlx5dv_devx_uar_export_dmabuf_fd@MLX5_1.26 62 mlx5dv_devx_umem_dereg@MLX5_1.7 21 mlx5dv_devx_umem_reg@MLX5_1.7 21 mlx5dv_open_device@MLX5_1.7 21
diff --git a/providers/mlx5/CMakeLists.txt b/providers/mlx5/CMakeLists.txt index 4a438d9..95d5985 100644 --- a/providers/mlx5/CMakeLists.txt +++ b/providers/mlx5/CMakeLists.txt
@@ -15,7 +15,7 @@ endif() rdma_shared_provider(mlx5 libmlx5.map - 1 1.25.${PACKAGE_VERSION} + 1 1.26.${PACKAGE_VERSION} ${TRACE_FILE} buf.c cq.c
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map index b2a852a..6e965a9 100644 --- a/providers/mlx5/libmlx5.map +++ b/providers/mlx5/libmlx5.map
@@ -235,3 +235,8 @@ mlx5dv_get_data_direct_sysfs_path; mlx5dv_reg_dmabuf_mr; } MLX5_1.24; + +MLX5_1.26 { + global: + mlx5dv_devx_uar_export_dmabuf_fd; +} MLX5_1.25;
diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt index 16f1d47..b0f6308 100644 --- a/providers/mlx5/man/CMakeLists.txt +++ b/providers/mlx5/man/CMakeLists.txt
@@ -23,6 +23,7 @@ mlx5dv_devx_qp_modify.3.md mlx5dv_devx_query_eqn.3.md mlx5dv_devx_subscribe_devx_event.3.md + mlx5dv_devx_uar_export_dmabuf_fd.3.md mlx5dv_devx_umem_reg.3.md mlx5dv_dm_map_op_addr.3.md mlx5dv_dr_flow.3.md
diff --git a/providers/mlx5/man/mlx5dv_devx_uar_export_dmabuf_fd.3.md b/providers/mlx5/man/mlx5dv_devx_uar_export_dmabuf_fd.3.md new file mode 100644 index 0000000..5f5dc4d --- /dev/null +++ b/providers/mlx5/man/mlx5dv_devx_uar_export_dmabuf_fd.3.md
@@ -0,0 +1,47 @@ +--- +layout: page +title: mlx5dv_devx_uar_export_dmabuf_fd +section: 3 +tagline: Verbs +--- + +# NAME + +mlx5dv_devx_uar_export_dmabuf_fd - export dmabuf fd for a given mlx5dv_devx_uar. + +# SYNOPSIS + +```c +#include <infiniband/mlx5dv.h> + +int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *devx_uar); +``` + +# DESCRIPTION + +**mlx5dv_devx_uar_export_dmabuf_fd()** exports a dmabuf fd that is associated with the given +*devx_uar*. + +The returned fd can be later used for DMA and RDMA operations associated with it. + +Once the usage has been ended, close() should be called while supplying the fd. + +This call will release resources that were earlier allocated using the **mlx5dv_devx_uar_export_dmabuf_fd()** API. + +# ARGUMENTS + +*devx_uar* +: An mlx5dv_devx_uar pointer to export the dmabuf fd for its memory. + +# RETURN VALUE + +**mlx5dv_devx_uar_export_dmabuf_fd()** returns an fd number >= 0 upon success, or -1 if the request fails and errno set to the error. + +# SEE ALSO + +**ibv_reg_mr_ex**(3) +**ibv_dm_export_dmabuf_fd**(3) + +# AUTHOR + +Yishai Hadas <yishaih@nvidia.com>
diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h index d3744dd..349801d 100644 --- a/providers/mlx5/mlx5.h +++ b/providers/mlx5/mlx5.h
@@ -1637,6 +1637,7 @@ size_t length, uint64_t iova, int fd, int access, int mlx5_access); int (*get_data_direct_sysfs_path)(struct ibv_context *context, char *buf, size_t buf_len); + int (*devx_uar_export_dmabuf_fd)(struct mlx5dv_devx_uar *dv_devx_uar); }; struct mlx5_dv_context_ops *mlx5_get_dv_ops(struct ibv_context *context);
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h index a249401..5fe8bf7 100644 --- a/providers/mlx5/mlx5dv.h +++ b/providers/mlx5/mlx5dv.h
@@ -1819,6 +1819,7 @@ uint32_t flags); void mlx5dv_devx_free_uar(struct mlx5dv_devx_uar *devx_uar); +int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *devx_uar); struct mlx5dv_var { uint32_t page_id;
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 0b3f1dc..8f90446 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c
@@ -6396,6 +6396,29 @@ dvops->devx_free_uar(dv_devx_uar); } +static int +_mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *dv_devx_uar) +{ + struct mlx5_devx_uar *uar = container_of(dv_devx_uar, struct mlx5_devx_uar, + dv_devx_uar); + + return ibv_cmd_export_dmabuf_fd(uar->context, dv_devx_uar->mmap_off); +} + +int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *dv_devx_uar) +{ + struct mlx5_devx_uar *uar = container_of(dv_devx_uar, struct mlx5_devx_uar, + dv_devx_uar); + struct mlx5_dv_context_ops *dvops = mlx5_get_dv_ops(uar->context); + + if (!dvops || !dvops->devx_uar_export_dmabuf_fd) { + errno = EOPNOTSUPP; + return -1; + } + + return dvops->devx_uar_export_dmabuf_fd(dv_devx_uar); +} + static int _mlx5dv_devx_query_eqn(struct ibv_context *context, uint32_t vector, uint32_t *eqn) { @@ -8161,6 +8184,7 @@ ops->devx_alloc_uar = _mlx5dv_devx_alloc_uar; ops->devx_free_uar = _mlx5dv_devx_free_uar; + ops->devx_uar_export_dmabuf_fd = _mlx5dv_devx_uar_export_dmabuf_fd; ops->devx_umem_reg = _mlx5dv_devx_umem_reg; ops->devx_umem_reg_ex = _mlx5dv_devx_umem_reg_ex;