Skip to content

Commit c7743ea

Browse files
author
Yishai Hadas
committed
verbs: Add ibv_cmd_reg_mr_ex() to be used by drivers
Add ibv_cmd_reg_mr_ex() to be used by drivers which implement the ibv_reg_mr_ex() verb. Signed-off-by: Yishai Hadas <[email protected]>
1 parent 3aa84ae commit c7743ea

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

libibverbs/cmd_mr.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,82 @@ int ibv_cmd_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
156156
vmr->mr_type = IBV_MR_TYPE_DMABUF_MR;
157157
return 0;
158158
}
159+
160+
int ibv_cmd_reg_mr_ex(struct ibv_pd *pd, struct verbs_mr *vmr,
161+
struct ibv_reg_mr_in *in)
162+
{
163+
DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_MR,
164+
UVERBS_METHOD_REG_MR, 11);
165+
bool fd_based = (in->comp_mask & IBV_REG_MR_MASK_FD);
166+
struct ib_uverbs_attr *handle;
167+
uint64_t length = in->length;
168+
uint32_t lkey, rkey;
169+
int ret;
170+
171+
if (fd_based) {
172+
if (!(in->comp_mask & IBV_REG_MR_MASK_FD_OFFSET) ||
173+
(in->comp_mask & IBV_REG_MR_MASK_ADDR)) {
174+
errno = EINVAL;
175+
return EINVAL;
176+
}
177+
fill_attr_in_uint64(cmdb, UVERBS_ATTR_REG_MR_FD_OFFSET, in->fd_offset);
178+
fill_attr_in_fd(cmdb, UVERBS_ATTR_REG_MR_FD,
179+
in->fd);
180+
} else {
181+
if ((in->comp_mask & IBV_REG_MR_MASK_FD_OFFSET) ||
182+
!(in->comp_mask & IBV_REG_MR_MASK_ADDR)) {
183+
errno = EINVAL;
184+
return EINVAL;
185+
}
186+
187+
fill_attr_in_uint64(cmdb, UVERBS_ATTR_REG_MR_ADDR, (uintptr_t)in->addr);
188+
if (in->access & IBV_ACCESS_ON_DEMAND) {
189+
if (in->length == SIZE_MAX && in->addr) {
190+
errno = EINVAL;
191+
return EINVAL;
192+
}
193+
if (in->length == SIZE_MAX)
194+
length = UINT64_MAX;
195+
}
196+
}
197+
198+
if (in->comp_mask & IBV_REG_MR_MASK_IOVA) {
199+
fill_attr_in_uint64(cmdb, UVERBS_ATTR_REG_MR_IOVA, in->iova);
200+
} else {
201+
if (!fd_based) {
202+
fill_attr_in_uint64(cmdb, UVERBS_ATTR_REG_MR_IOVA,
203+
(uintptr_t)in->addr);
204+
} else {
205+
/* iova is a must from kernel point of view */
206+
errno = EINVAL;
207+
return EINVAL;
208+
}
209+
}
210+
211+
handle = fill_attr_out_obj(cmdb, UVERBS_ATTR_REG_MR_HANDLE);
212+
fill_attr_out_ptr(cmdb, UVERBS_ATTR_REG_MR_RESP_LKEY, &lkey);
213+
fill_attr_out_ptr(cmdb, UVERBS_ATTR_REG_MR_RESP_RKEY, &rkey);
214+
fill_attr_in_obj(cmdb, UVERBS_ATTR_REG_MR_PD_HANDLE, pd->handle);
215+
fill_attr_in_uint64(cmdb, UVERBS_ATTR_REG_MR_LENGTH, length);
216+
fill_attr_in_uint32(cmdb, UVERBS_ATTR_REG_MR_ACCESS_FLAGS, in->access);
217+
218+
if (in->comp_mask & IBV_REG_MR_MASK_DMAH)
219+
fill_attr_in_obj(cmdb, UVERBS_ATTR_REG_MR_DMA_HANDLE,
220+
verbs_get_dmah(in->dmah)->handle);
221+
222+
ret = execute_ioctl(pd->context, cmdb);
223+
if (ret)
224+
return errno;
225+
226+
vmr->ibv_mr.handle = read_attr_obj(UVERBS_ATTR_REG_MR_HANDLE,
227+
handle);
228+
vmr->ibv_mr.context = pd->context;
229+
vmr->ibv_mr.lkey = lkey;
230+
vmr->ibv_mr.rkey = rkey;
231+
if (fd_based)
232+
vmr->mr_type = IBV_MR_TYPE_DMABUF_MR;
233+
else
234+
vmr->mr_type = IBV_MR_TYPE_MR;
235+
236+
return 0;
237+
}

libibverbs/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ int ibv_cmd_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
573573
uint64_t iova, int fd, int access,
574574
struct verbs_mr *vmr,
575575
struct ibv_command_buffer *driver);
576+
int ibv_cmd_reg_mr_ex(struct ibv_pd *pd, struct verbs_mr *vmr,
577+
struct ibv_reg_mr_in *in);
576578
int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type,
577579
struct ibv_mw *mw, struct ibv_alloc_mw *cmd,
578580
size_t cmd_size,

0 commit comments

Comments
 (0)