Skip to content

Commit d9af497

Browse files
committed
verbs: Add ibv_cmd_alloc/free commands for DMA handle
Add ibv_cmd_alloc/free commands for DMA handle to be used by drivers. Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
1 parent c2ba4c1 commit d9af497

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

libibverbs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rdma_library(ibverbs "${CMAKE_CURRENT_BINARY_DIR}/libibverbs.map"
2929
cmd_cq.c
3030
cmd_device.c
3131
cmd_dm.c
32+
cmd_dmah.c
3233
cmd_fallback.c
3334
cmd_flow.c
3435
cmd_flow_action.c

libibverbs/cmd_dmah.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
2+
/*
3+
* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved
4+
*/
5+
6+
#include <infiniband/cmd_write.h>
7+
8+
int ibv_cmd_alloc_dmah(struct ibv_context *ctx,
9+
struct verbs_dmah *dmah,
10+
struct ibv_dmah_init_attr *attr)
11+
{
12+
DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_DMAH, UVERBS_METHOD_DMAH_ALLOC, 4);
13+
struct ib_uverbs_attr *handle;
14+
int ret;
15+
16+
handle = fill_attr_out_obj(cmdb, UVERBS_ATTR_ALLOC_DMAH_HANDLE);
17+
if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_CPU_ID)
18+
fill_attr_in_uint32(cmdb, UVERBS_ATTR_ALLOC_DMAH_CPU_ID,
19+
attr->cpu_id);
20+
if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_TPH_MEM_TYPE)
21+
fill_attr_in_enum(cmdb, UVERBS_ATTR_ALLOC_DMAH_TPH_MEM_TYPE,
22+
attr->tph_mem_type, NULL, 0);
23+
if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_PH)
24+
fill_attr_in(cmdb, UVERBS_ATTR_ALLOC_DMAH_PH,
25+
&attr->ph, sizeof(attr->ph));
26+
ret = execute_ioctl(ctx, cmdb);
27+
if (ret)
28+
return errno;
29+
30+
dmah->handle = read_attr_obj(UVERBS_ATTR_ALLOC_DMAH_HANDLE, handle);
31+
dmah->dmah.context = ctx;
32+
33+
return 0;
34+
}
35+
36+
int ibv_cmd_free_dmah(struct verbs_dmah *dmah)
37+
{
38+
DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_DMAH, UVERBS_METHOD_DMAH_FREE, 1);
39+
int ret;
40+
41+
fill_attr_in_obj(cmdb, UVERBS_ATTR_FREE_DMA_HANDLE, dmah->handle);
42+
43+
ret = execute_ioctl(dmah->dmah.context, cmdb);
44+
if (verbs_is_destroy_err(&ret))
45+
return ret;
46+
47+
return 0;
48+
}

libibverbs/driver.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ struct verbs_dm {
189189
uint32_t handle;
190190
};
191191

192+
struct verbs_dmah {
193+
struct ibv_dmah dmah;
194+
uint32_t handle;
195+
};
196+
192197
enum {
193198
VERBS_MATCH_SENTINEL = 0,
194199
VERBS_MATCH_PCI = 1,
@@ -707,6 +712,9 @@ int ibv_cmd_alloc_dm(struct ibv_context *ctx,
707712
struct verbs_dm *dm,
708713
struct ibv_command_buffer *link);
709714
int ibv_cmd_free_dm(struct verbs_dm *dm);
715+
int ibv_cmd_alloc_dmah(struct ibv_context *ctx, struct verbs_dmah *st,
716+
struct ibv_dmah_init_attr *attr);
717+
int ibv_cmd_free_dmah(struct verbs_dmah *dmah);
710718
int ibv_cmd_reg_dm_mr(struct ibv_pd *pd, struct verbs_dm *dm,
711719
uint64_t offset, size_t length,
712720
unsigned int access, struct verbs_mr *vmr,

libibverbs/libibverbs.map.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
182182
execute_ioctl;
183183
ibv_cmd_advise_mr;
184184
ibv_cmd_alloc_dm;
185+
ibv_cmd_alloc_dmah;
185186
ibv_cmd_alloc_mw;
186187
ibv_cmd_alloc_pd;
187188
ibv_cmd_attach_mcast;
@@ -214,6 +215,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
214215
ibv_cmd_destroy_wq;
215216
ibv_cmd_detach_mcast;
216217
ibv_cmd_free_dm;
218+
ibv_cmd_free_dmah;
217219
ibv_cmd_get_context;
218220
ibv_cmd_modify_cq;
219221
ibv_cmd_modify_flow_action_esp;

0 commit comments

Comments
 (0)