From 9eaaab5333d6e6c53d9732f2f2cbed446a4338d9 Mon Sep 17 00:00:00 2001 From: Davide Rossetti Date: Tue, 17 Jan 2017 08:17:28 -0800 Subject: [PATCH] when creating CQ dbrec, route to peer creation and registration functions fixes #5 --- src/mlx5.h | 2 ++ src/verbs.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/mlx5.h b/src/mlx5.h index 4d1a8cd..dce7a1c 100644 --- a/src/mlx5.h +++ b/src/mlx5.h @@ -637,6 +637,8 @@ struct mlx5_cq { struct mlx5_buf peer_buf; struct mlx5_peek_entry **peer_peek_table; struct mlx5_peek_entry *peer_peek_free; + struct ibv_exp_peer_buf *peer_dbrec_buf; + uint64_t peer_dbrec_id; }; struct mlx5_srq { diff --git a/src/verbs.c b/src/verbs.c index 485d176..37f3e47 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -820,12 +820,37 @@ static struct ibv_cq *create_cq(struct ibv_context *context, goto err_buf; } - cq->dbrec = mlx5_alloc_dbrec(mctx); + if (cq->peer_enabled && cq->peer_ctx->buf_alloc) { + struct ibv_exp_peer_buf_alloc_attr attr; + + attr.length = mctx->cache_line_size; + attr.peer_id = cq->peer_ctx->peer_id; + attr.dir = IBV_EXP_PEER_DIRECTION_FROM_PEER | + IBV_EXP_PEER_DIRECTION_TO_HCA; + attr.alignment = mctx->cache_line_size; + cq->peer_dbrec_buf = cq->peer_ctx->buf_alloc(&attr); + if (cq->peer_dbrec_buf) + cq->dbrec = cq->peer_dbrec_buf->addr; + } + if (!cq->dbrec) + cq->dbrec = mlx5_alloc_dbrec(mctx); if (!cq->dbrec) { mlx5_dbg(fp, MLX5_DBG_CQ, "\n"); goto err_peer_buf; } + if (cq->peer_enabled && cq->peer_ctx->register_va) { + cq->peer_dbrec_id = + cq->peer_ctx->register_va((void*)cq->dbrec, + mctx->cache_line_size, + cq->peer_ctx->peer_id, + cq->peer_dbrec_buf); + if (!cq->peer_dbrec_id) { + mlx5_dbg(fp, MLX5_DBG_QP, "\n"); + goto err_peer_buf; + } + } + cq->dbrec[MLX5_CQ_SET_CI] = 0; cq->dbrec[MLX5_CQ_ARM_DB] = 0; cq->arm_sn = 0; @@ -903,8 +928,14 @@ static struct ibv_cq *create_cq(struct ibv_context *context, mlx5_free_db(mctx, cq->dbrec); err_peer_buf: - if (cq->peer_enabled) + if (cq->peer_enabled) { mlx5_free_actual_buf(mctx, &cq->peer_buf); + if (cq->peer_dbrec_buf) { + if (cq->peer_dbrec_id) + cq->peer_ctx->unregister_va(cq->peer_dbrec_id, cq->peer_ctx->peer_id); + cq->peer_ctx->buf_release(cq->peer_dbrec_buf); + } + } err_buf: mlx5_free_actual_buf(mctx, &cq->buf_a); @@ -1027,8 +1058,15 @@ int mlx5_destroy_cq(struct ibv_cq *ibcq) mlx5_free_db(ctx, cq->dbrec); mlx5_free_actual_buf(ctx, cq->active_buf); - if (cq->peer_enabled) + if (cq->peer_enabled) { mlx5_free_actual_buf(ctx, &cq->peer_buf); + if (cq->peer_dbrec_buf) { + if (cq->peer_dbrec_id) + cq->peer_ctx->unregister_va(cq->peer_dbrec_id, cq->peer_ctx->peer_id); + cq->peer_ctx->buf_release(cq->peer_dbrec_buf); + } + } + free(cq); return 0;