@@ -91,6 +91,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = {
.alloc_pd = mlx5_alloc_pd,
.async_event = mlx5_async_event,
.dealloc_pd = mlx5_free_pd,
+ .import_mr = mlx5_import_mr,
.import_pd = mlx5_import_pd,
.reg_mr = mlx5_reg_mr,
.rereg_mr = mlx5_rereg_mr,
@@ -816,6 +816,8 @@ int mlx5_query_port(struct ibv_context *context, uint8_t port,
struct ibv_pd *mlx5_alloc_pd(struct ibv_context *context);
int mlx5_free_pd(struct ibv_pd *pd);
+struct ibv_mr *mlx5_import_mr(struct ibv_context *context, uint32_t fd,
+ uint32_t handle);
struct ibv_pd *mlx5_import_pd(struct ibv_context *context, uint32_t fd,
uint32_t handle);
@@ -178,6 +178,32 @@ struct ibv_pd *mlx5_alloc_pd(struct ibv_context *context)
return &pd->ibv_pd;
}
+struct ibv_mr *mlx5_import_mr(struct ibv_context *context, uint32_t fd,
+ uint32_t handle)
+{
+ struct ibv_import_mr cmd = {
+ .handle = handle,
+ .type = UVERBS_OBJECT_MR,
+ .fd = fd,
+ };
+ struct ib_uverbs_import_fr_fd_resp resp = {0};
+ struct mlx5_mr *mr;
+ int ret;
+
+ mr = calloc(1, sizeof(*mr));
+ if (!mr)
+ return NULL;
+
+ ret = ibv_cmd_import_mr(context, &mr->vmr, &cmd, sizeof(cmd), &resp,
+ sizeof(resp));
+ if (ret) {
+ free(mr);
+ return NULL;
+ }
+
+ return &mr->vmr.ibv_mr;
+}
+
struct ibv_pd *mlx5_import_pd(struct ibv_context *context, uint32_t fd,
uint32_t handle)
{