The import MR verb take care of importing the generic part of the MR object and then triggers provider's specific callback to take care of provider's specific attributes. Add implementation of mlx4 related MR attributes. Signed-off-by: Yuval Shaia <yuval.shaia@xxxxxxxxxx> Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> Signed-off-by: Shamir Rabinovitch <srabinov7@xxxxxxxxx> --- providers/mlx4/mlx4.c | 1 + providers/mlx4/mlx4.h | 2 ++ providers/mlx4/verbs.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c index 62ea5539..40935ca0 100644 --- a/providers/mlx4/mlx4.c +++ b/providers/mlx4/mlx4.c @@ -86,6 +86,7 @@ static const struct verbs_context_ops mlx4_ctx_ops = { .query_port = mlx4_query_port, .alloc_pd = mlx4_alloc_pd, .dealloc_pd = mlx4_free_pd, + .import_mr = mlx4_import_mr, .import_pd = mlx4_import_pd, .reg_mr = mlx4_reg_mr, .rereg_mr = mlx4_rereg_mr, diff --git a/providers/mlx4/mlx4.h b/providers/mlx4/mlx4.h index 0f6e6ecf..fc06317c 100644 --- a/providers/mlx4/mlx4.h +++ b/providers/mlx4/mlx4.h @@ -316,6 +316,8 @@ int mlx4_query_rt_values(struct ibv_context *context, struct ibv_values_ex *values); struct ibv_pd *mlx4_alloc_pd(struct ibv_context *context); int mlx4_free_pd(struct ibv_pd *pd); +struct ibv_mr *mlx4_import_mr(struct ibv_context *context, uint32_t fd, + uint32_t handle); struct ibv_pd *mlx4_import_pd(struct ibv_context *context, uint32_t fd, uint32_t handle); struct ibv_xrcd *mlx4_open_xrcd(struct ibv_context *context, diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index fd8d396f..ab1efa67 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -239,6 +239,32 @@ int mlx4_free_pd(struct ibv_pd *pd) return 0; } +struct ibv_mr *mlx4_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; + struct verbs_mr *vmr; + int ret; + + vmr = calloc(1, sizeof(*vmr)); + if (!vmr) + return NULL; + + ret = ibv_cmd_import_mr(context, vmr, &cmd, sizeof(cmd), &resp, + sizeof(resp)); + if (ret) { + free(vmr); + return NULL; + } + + return &vmr->ibv_mr; +} + struct ibv_pd *mlx4_import_pd(struct ibv_context *context, uint32_t fd, uint32_t handle) { -- 2.20.1