git: 112ca55eefe8 - main - libmlx5: Extend mlx5dv_get_qp() to return UAR mapping info
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 16 Sep 2026 14:12:37 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=112ca55eefe8462c86f7507bff52ae4eb6488c71
commit 112ca55eefe8462c86f7507bff52ae4eb6488c71
Author: Vag Singh <vag.singh@oneconvergence.com>
AuthorDate: 2025-08-12 01:30:33 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-09-16 14:12:06 +0000
libmlx5: Extend mlx5dv_get_qp() to return UAR mapping info
[PATCH 02/31] FreeBSD OFED support for DPDK MLX5 PMD
Extend mlx5dv_get_qp() to return UAR mapping info. This can allow a
process to share its doorbell access with secondary process by re-mmap
the UAR address on the device and make it accessible as a user space
address.
Differential revision: https://reviews.freebsd.org/D32176
MFC after: 1 month
---
contrib/ofed/libmlx5/mlx5.c | 27 +++++++++++++++++++++------
contrib/ofed/libmlx5/mlx5.h | 1 +
contrib/ofed/libmlx5/mlx5dv.h | 5 +++++
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/contrib/ofed/libmlx5/mlx5.c b/contrib/ofed/libmlx5/mlx5.c
index 6fe6cf594c3b..56abaa965a6c 100644
--- a/contrib/ofed/libmlx5/mlx5.c
+++ b/contrib/ofed/libmlx5/mlx5.c
@@ -667,8 +667,8 @@ static int mlx5dv_get_qp(struct ibv_qp *qp_in,
struct mlx5dv_qp *qp_out)
{
struct mlx5_qp *mqp = to_mqp(qp_in);
+ uint64_t mask_out = 0;
- qp_out->comp_mask = 0;
qp_out->dbrec = mqp->db;
if (mqp->sq_buf_size)
@@ -683,13 +683,20 @@ static int mlx5dv_get_qp(struct ibv_qp *qp_in,
qp_out->rq.wqe_cnt = mqp->rq.wqe_cnt;
qp_out->rq.stride = 1 << mqp->rq.wqe_shift;
- qp_out->bf.reg = mqp->bf->reg;
+ qp_out->bf.reg = mqp->bf->reg;
+
+ if (qp_out->comp_mask & MLX5DV_QP_MASK_UAR_MMAP_OFFSET) {
+ qp_out->uar_mmap_offset = mqp->bf->uar_mmap_offset;
+ mask_out |= MLX5DV_QP_MASK_UAR_MMAP_OFFSET;
+ }
if (mqp->bf->uuarn > 0)
qp_out->bf.size = mqp->bf->buf_size;
else
qp_out->bf.size = 0;
+ qp_out->comp_mask = mask_out;
+
return 0;
}
@@ -774,6 +781,15 @@ static void adjust_uar_info(struct mlx5_device *mdev,
context->num_uars_per_page = resp.num_uars_per_page;
}
+static off_t get_uar_mmap_offset(int idx, int page_size)
+{
+ off_t offset = 0;
+
+ set_command(MLX5_MMAP_GET_REGULAR_PAGES_CMD, &offset);
+ set_index(idx, &offset);
+ return offset * page_size;
+}
+
static int mlx5_init_context(struct verbs_device *vdev,
struct ibv_context *ctx, int cmd_fd)
{
@@ -889,11 +905,9 @@ static int mlx5_init_context(struct verbs_device *vdev,
num_sys_page_map = context->tot_uuars / (context->num_uars_per_page * MLX5_NUM_NON_FP_BFREGS_PER_UAR);
for (i = 0; i < num_sys_page_map; ++i) {
- offset = 0;
- set_command(MLX5_MMAP_GET_REGULAR_PAGES_CMD, &offset);
- set_index(i, &offset);
+ offset = get_uar_mmap_offset(i, page_size);
context->uar[i] = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED,
- cmd_fd, page_size * offset);
+ cmd_fd, offset);
if (context->uar[i] == MAP_FAILED) {
context->uar[i] = NULL;
goto err_db_list_mutex;
@@ -913,6 +927,7 @@ static int mlx5_init_context(struct verbs_device *vdev,
if (bfi)
context->bfs[bfi].buf_size = context->bf_reg_size / 2;
context->bfs[bfi].uuarn = bfi;
+ context->bfs[bfi].uar_mmap_offset = get_uar_mmap_offset(i, page_size);
}
}
}
diff --git a/contrib/ofed/libmlx5/mlx5.h b/contrib/ofed/libmlx5/mlx5.h
index 456b9ba6db21..74c6685a1e73 100644
--- a/contrib/ofed/libmlx5/mlx5.h
+++ b/contrib/ofed/libmlx5/mlx5.h
@@ -386,6 +386,7 @@ struct mlx5_bf {
unsigned offset;
unsigned buf_size;
unsigned uuarn;
+ off_t uar_mmap_offset;
};
struct mlx5_mr {
diff --git a/contrib/ofed/libmlx5/mlx5dv.h b/contrib/ofed/libmlx5/mlx5dv.h
index 5cd0b0d95161..52d8803fb3ab 100644
--- a/contrib/ofed/libmlx5/mlx5dv.h
+++ b/contrib/ofed/libmlx5/mlx5dv.h
@@ -106,6 +106,10 @@ struct ibv_cq_ex *mlx5dv_create_cq(struct ibv_context *context,
int mlx5dv_query_device(struct ibv_context *ctx_in,
struct mlx5dv_context *attrs_out);
+enum mlx5dv_qp_comp_mask {
+ MLX5DV_QP_MASK_UAR_MMAP_OFFSET = 1 << 0,
+};
+
struct mlx5dv_qp {
uint32_t *dbrec;
struct {
@@ -123,6 +127,7 @@ struct mlx5dv_qp {
uint32_t size;
} bf;
uint64_t comp_mask;
+ off_t uar_mmap_offset;
};
struct mlx5dv_cq {