Skip to content

Commit b685f21

Browse files
committed
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>
1 parent 1b8cbbe commit b685f21

8 files changed

Lines changed: 82 additions & 1 deletion

File tree

debian/ibverbs-providers.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ libmlx5.so.1 ibverbs-providers #MINVER#
3333
MLX5_1.23@MLX5_1.23 40
3434
MLX5_1.24@MLX5_1.24 42
3535
MLX5_1.25@MLX5_1.25 54
36+
MLX5_1.26@MLX5_1.26 62
3637
mlx5dv_init_obj@MLX5_1.0 13
3738
mlx5dv_init_obj@MLX5_1.2 15
3839
mlx5dv_query_device@MLX5_1.0 13
@@ -55,6 +56,7 @@ libmlx5.so.1 ibverbs-providers #MINVER#
5556
mlx5dv_devx_obj_modify@MLX5_1.7 21
5657
mlx5dv_devx_obj_query@MLX5_1.7 21
5758
mlx5dv_devx_query_eqn@MLX5_1.7 21
59+
mlx5dv_devx_uar_export_dmabuf_fd@MLX5_1.26 62
5860
mlx5dv_devx_umem_dereg@MLX5_1.7 21
5961
mlx5dv_devx_umem_reg@MLX5_1.7 21
6062
mlx5dv_open_device@MLX5_1.7 21

providers/mlx5/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (ENABLE_LTTNG AND LTTNGUST_FOUND)
1515
endif()
1616

1717
rdma_shared_provider(mlx5 libmlx5.map
18-
1 1.25.${PACKAGE_VERSION}
18+
1 1.26.${PACKAGE_VERSION}
1919
${TRACE_FILE}
2020
buf.c
2121
cq.c

providers/mlx5/libmlx5.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,8 @@ MLX5_1.25 {
235235
mlx5dv_get_data_direct_sysfs_path;
236236
mlx5dv_reg_dmabuf_mr;
237237
} MLX5_1.24;
238+
239+
MLX5_1.26 {
240+
global:
241+
mlx5dv_devx_uar_export_dmabuf_fd;
242+
} MLX5_1.25;

providers/mlx5/man/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rdma_man_pages(
2323
mlx5dv_devx_qp_modify.3.md
2424
mlx5dv_devx_query_eqn.3.md
2525
mlx5dv_devx_subscribe_devx_event.3.md
26+
mlx5dv_devx_uar_export_dmabuf_fd.3.md
2627
mlx5dv_devx_umem_reg.3.md
2728
mlx5dv_dm_map_op_addr.3.md
2829
mlx5dv_dr_flow.3.md
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
layout: page
3+
title: mlx5dv_devx_uar_export_dmabuf_fd
4+
section: 3
5+
tagline: Verbs
6+
---
7+
8+
# NAME
9+
10+
mlx5dv_devx_uar_export_dmabuf_fd - export dmabuf fd for a given mlx5dv_devx_uar.
11+
12+
# SYNOPSIS
13+
14+
```c
15+
#include <infiniband/mlx5dv.h>
16+
17+
int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *devx_uar);
18+
```
19+
20+
# DESCRIPTION
21+
22+
**mlx5dv_devx_uar_export_dmabuf_fd()** exports a dmabuf fd that is associated with the given
23+
*devx_uar*.
24+
25+
The returned fd can be later used for DMA and RDMA operations associated with it.
26+
27+
Once the usage has been ended, close() should be called while supplying the fd.
28+
29+
This call will release resources that were earlier allocated using the **mlx5dv_devx_uar_export_dmabuf_fd()** API.
30+
31+
# ARGUMENTS
32+
33+
*devx_uar*
34+
: An mlx5dv_devx_uar pointer to export the dmabuf fd for its memory.
35+
36+
# RETURN VALUE
37+
38+
**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.
39+
40+
# SEE ALSO
41+
42+
**ibv_reg_mr_ex**(3)
43+
**ibv_dm_export_dmabuf_fd**(3)
44+
45+
# AUTHOR
46+
47+
Yishai Hadas <yishaih@nvidia.com>

providers/mlx5/mlx5.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ struct mlx5_dv_context_ops {
16371637
size_t length, uint64_t iova, int fd,
16381638
int access, int mlx5_access);
16391639
int (*get_data_direct_sysfs_path)(struct ibv_context *context, char *buf, size_t buf_len);
1640+
int (*devx_uar_export_dmabuf_fd)(struct mlx5dv_devx_uar *dv_devx_uar);
16401641
};
16411642

16421643
struct mlx5_dv_context_ops *mlx5_get_dv_ops(struct ibv_context *context);

providers/mlx5/mlx5dv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,7 @@ struct mlx5dv_devx_uar *mlx5dv_devx_alloc_uar(struct ibv_context *context,
18191819
uint32_t flags);
18201820
void mlx5dv_devx_free_uar(struct mlx5dv_devx_uar *devx_uar);
18211821

1822+
int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *devx_uar);
18221823

18231824
struct mlx5dv_var {
18241825
uint32_t page_id;

providers/mlx5/verbs.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6396,6 +6396,29 @@ void mlx5dv_devx_free_uar(struct mlx5dv_devx_uar *dv_devx_uar)
63966396
dvops->devx_free_uar(dv_devx_uar);
63976397
}
63986398

6399+
static int
6400+
_mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *dv_devx_uar)
6401+
{
6402+
struct mlx5_devx_uar *uar = container_of(dv_devx_uar, struct mlx5_devx_uar,
6403+
dv_devx_uar);
6404+
6405+
return ibv_cmd_export_dmabuf_fd(uar->context, dv_devx_uar->mmap_off);
6406+
}
6407+
6408+
int mlx5dv_devx_uar_export_dmabuf_fd(struct mlx5dv_devx_uar *dv_devx_uar)
6409+
{
6410+
struct mlx5_devx_uar *uar = container_of(dv_devx_uar, struct mlx5_devx_uar,
6411+
dv_devx_uar);
6412+
struct mlx5_dv_context_ops *dvops = mlx5_get_dv_ops(uar->context);
6413+
6414+
if (!dvops || !dvops->devx_uar_export_dmabuf_fd) {
6415+
errno = EOPNOTSUPP;
6416+
return -1;
6417+
}
6418+
6419+
return dvops->devx_uar_export_dmabuf_fd(dv_devx_uar);
6420+
}
6421+
63996422
static int _mlx5dv_devx_query_eqn(struct ibv_context *context,
64006423
uint32_t vector, uint32_t *eqn)
64016424
{
@@ -8161,6 +8184,7 @@ void mlx5_set_dv_ctx_ops(struct mlx5_dv_context_ops *ops)
81618184

81628185
ops->devx_alloc_uar = _mlx5dv_devx_alloc_uar;
81638186
ops->devx_free_uar = _mlx5dv_devx_free_uar;
8187+
ops->devx_uar_export_dmabuf_fd = _mlx5dv_devx_uar_export_dmabuf_fd;
81648188

81658189
ops->devx_umem_reg = _mlx5dv_devx_umem_reg;
81668190
ops->devx_umem_reg_ex = _mlx5dv_devx_umem_reg_ex;

0 commit comments

Comments
 (0)