@@ -90,6 +90,7 @@ enum ib_uverbs_write_cmds {
IB_USER_VERBS_CMD_OPEN_QP,
IB_USER_VERBS_CMD_IMPORT_FROM_FD,
IB_USER_VERBS_CMD_IMPORT_PD = IB_USER_VERBS_CMD_IMPORT_FROM_FD,
+ IB_USER_VERBS_CMD_IMPORT_MR = IB_USER_VERBS_CMD_IMPORT_FROM_FD,
};
enum {
@@ -1309,9 +1310,18 @@ struct ib_uverbs_import_pd {
__u8 reserved[6];
};
+struct ib_uverbs_import_mr {
+ __aligned_u64 response;
+ __u32 fd;
+ __u32 handle;
+ __u16 type;
+ __u8 reserved[6];
+};
+
struct ib_uverbs_import_fr_fd_resp {
union {
struct ib_uverbs_alloc_pd_resp alloc_pd;
+ struct ib_uverbs_reg_mr_resp reg_mr;
} u;
};
@@ -382,6 +382,27 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
return 0;
}
+int ibv_cmd_import_mr(struct ibv_context *context, struct verbs_mr *vmr,
+ struct ibv_import_mr *cmd, size_t cmd_size,
+ struct ib_uverbs_import_fr_fd_resp *resp,
+ size_t resp_size)
+{
+ int ret;
+
+ ret = execute_cmd_write(context, IB_USER_VERBS_CMD_IMPORT_MR, cmd,
+ cmd_size, resp, resp_size);
+ if (ret)
+ return ret;
+
+ vmr->ibv_mr.handle = resp->u.reg_mr.mr_handle;
+ vmr->ibv_mr.lkey = resp->u.reg_mr.lkey;
+ vmr->ibv_mr.rkey = resp->u.reg_mr.rkey;
+ vmr->ibv_mr.context = context;
+ vmr->mr_type = IBV_MR_TYPE_MR;
+
+ return 0;
+}
+
int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr,
size_t length, uint64_t hca_va, int access,
struct ibv_pd *pd, struct ibv_rereg_mr *cmd,
@@ -317,6 +317,8 @@ struct verbs_context_ops {
uint16_t lid);
int (*free_dm)(struct ibv_dm *dm);
int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);
+ struct ibv_mr *(*import_mr)(struct ibv_context *context, uint32_t fd,
+ uint32_t handle);
struct ibv_pd *(*import_pd)(struct ibv_context *context, uint32_t fd,
uint32_t handle);
int (*modify_cq)(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr);
@@ -479,6 +481,10 @@ int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr,
size_t cmd_sz, struct ib_uverbs_rereg_mr_resp *resp,
size_t resp_sz);
int ibv_cmd_dereg_mr(struct verbs_mr *vmr);
+int ibv_cmd_import_mr(struct ibv_context *context, struct verbs_mr *vmr,
+ struct ibv_import_mr *cmd, size_t cmd_size,
+ struct ib_uverbs_import_fr_fd_resp *resp,
+ size_t resp_size);
int ibv_cmd_advise_mr(struct ibv_pd *pd,
enum ibv_advise_mr_advice advice,
uint32_t flags,
@@ -282,6 +282,13 @@ static int get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
return ENOSYS;
}
+static struct ibv_mr *import_mr(struct ibv_context *context, uint32_t fd,
+ uint32_t handle)
+{
+ errno = ENOSYS;
+ return NULL;
+}
+
static struct ibv_pd *import_pd(struct ibv_context *context, uint32_t fd,
uint32_t handle)
{
@@ -494,6 +501,7 @@ const struct verbs_context_ops verbs_dummy_ops = {
detach_mcast,
free_dm,
get_srq_num,
+ import_mr,
import_pd,
modify_cq,
modify_flow_action_esp,
@@ -636,6 +644,7 @@ void verbs_set_ops(struct verbs_context *vctx,
SET_PRIV_OP(ctx, rereg_mr);
SET_PRIV_OP(ctx, resize_cq);
SET_OP(vctx, import_pd);
+ SET_OP(vctx, import_mr);
#undef SET_OP
#undef SET_OP2
@@ -208,6 +208,7 @@ DECLARE_CMDX(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ, ibv_req_notify_cq, ib_uverbs_req_n
DECLARE_CMD(IB_USER_VERBS_CMD_REREG_MR, ibv_rereg_mr, ib_uverbs_rereg_mr);
DECLARE_CMD(IB_USER_VERBS_CMD_RESIZE_CQ, ibv_resize_cq, ib_uverbs_resize_cq);
DECLARE_CMDX(IB_USER_VERBS_CMD_IMPORT_PD, ibv_import_pd, ib_uverbs_import_pd, ib_uverbs_import_fr_fd_resp);
+DECLARE_CMDX(IB_USER_VERBS_CMD_IMPORT_MR, ibv_import_mr, ib_uverbs_import_mr, ib_uverbs_import_fr_fd_resp);
DECLARE_CMD_EX(IB_USER_VERBS_EX_CMD_CREATE_CQ, ibv_create_cq_ex, ib_uverbs_ex_create_cq);
DECLARE_CMD_EX(IB_USER_VERBS_EX_CMD_CREATE_FLOW, ibv_create_flow, ib_uverbs_create_flow);
DECLARE_CMD_EX(IB_USER_VERBS_EX_CMD_CREATE_QP, ibv_create_qp_ex, ib_uverbs_ex_create_qp);
@@ -160,6 +160,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
ibv_cmd_detach_mcast;
ibv_cmd_free_dm;
ibv_cmd_get_context;
+ ibv_cmd_import_mr;
ibv_cmd_import_pd;
ibv_cmd_modify_flow_action_esp;
ibv_cmd_modify_qp;
@@ -2015,6 +2015,8 @@ struct ibv_values_ex {
struct verbs_context {
/* "grows up" - new fields go here */
+ struct ibv_mr *(*import_mr)(struct ibv_context *context, uint32_t fd,
+ uint32_t handle);
struct ibv_pd *(*import_pd)(struct ibv_context *context, uint32_t fd,
uint32_t handle);
int (*query_port)(struct ibv_context *context, uint8_t port_num,
@@ -3298,6 +3300,24 @@ static inline struct ibv_pd *ibv_import_pd(struct ibv_context *context,
return pd;
}
+static inline struct ibv_mr *ibv_import_mr(struct ibv_context *context,
+ uint32_t fd, uint32_t handle)
+{
+ struct verbs_context *vctx = verbs_get_ctx_op(context, import_mr);
+ struct ibv_mr *mr;
+
+ if (!vctx) {
+ errno = ENOSYS;
+ return NULL;
+ }
+
+ mr = vctx->import_mr(context, fd, handle);
+ if (mr)
+ mr->context = context;
+
+ return mr;
+}
+
#ifdef __cplusplus
}
#endif