Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Selvin Xavier <selvin.xavier@broadcom.com>
To: leon@kernel.org, jgg@ziepe.ca
Cc: linux-rdma@vger.kernel.org, andrew.gospodarek@broadcom.com,
	kalesh-anakkur.purayil@broadcom.com,
	Abhishek Mohapatra <abhishek.mohapatra@broadcom.com>,
	Kashyap Desai <kashyap.desai@broadcom.com>,
	Selvin Xavier <selvin.xavier@broadcom.com>
Subject: [PATCH for-next v2 4/4] RDMA/bnxt_re: Allow user library to request STATIC WQE mode per-QP
Date: Mon, 30 Nov 2026 06:53:44 -0800	[thread overview]
Message-ID: <20261130145344.322857-5-selvin.xavier@broadcom.com> (raw)
In-Reply-To: <20261130145344.322857-1-selvin.xavier@broadcom.com>

From: Abhishek Mohapatra <abhishek.mohapatra@broadcom.com>

Allow the provider library to explicitly request STATIC WQE mode at
creation through a new wqe_mode field in the create-QP request,
gated by a comp_mask flag. This lets applications that create QP
directly to use fixed-size WQEs. The SQ is sized from the application
provided slot count and PSN/MSN sizing follows the
selected mode.

STATIC mode is rejected if the device reports fewer SGEs than the
fixed STATIC WQE size. On non-P5/P7 chips the 128 WQEs reserved for HW
are kept. In variable WQE mode, sq_slots must be a multiple of 256.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Abhishek Mohapatra <abhishek.mohapatra@broadcom.com>
Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
---
 drivers/infiniband/hw/bnxt_re/ib_verbs.c | 122 +++++++++++++++++------
 include/uapi/rdma/bnxt_re-abi.h          |   9 ++
 2 files changed, 102 insertions(+), 29 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
index 92d8995b5895..ac7db219bfc1 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
@@ -1163,6 +1163,7 @@ static int bnxt_re_get_psn_bytes(struct bnxt_re_dev *rdev,
 				 struct bnxt_re_qp_req *ureq,
 				 bool fixed_que_attr)
 {
+	bool is_static = qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC;
 	bool msn_tbl = rdev->dev_attr &&
 		       _is_host_msn_table(rdev->dev_attr->dev_cap_flags2);
 	int psn_sz, psn_nume;
@@ -1174,13 +1175,15 @@ static int bnxt_re_get_psn_bytes(struct bnxt_re_dev *rdev,
 					sizeof(struct sq_psn_search_ext) :
 					sizeof(struct sq_psn_search);
 
-	if (fixed_que_attr)
+	/* Fixed-attribute variable-WQE QPs get the PSN count from userspace */
+	if (fixed_que_attr && !is_static)
 		return ureq->sq_npsn * psn_sz;
 
-	if (cntx && bnxt_re_is_var_size_supported(rdev, cntx))
-		psn_nume = ureq->sq_slots;
-	else if (qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
+	/* STATIC mode matches msn_tbl_sz in bnxt_re_qp_calculate_msn_psn_size() */
+	if (is_static)
 		psn_nume = qplib_qp->sq.max_wqe;
+	else if (cntx && bnxt_re_is_var_size_supported(rdev, cntx))
+		psn_nume = ureq->sq_slots;
 	else
 		psn_nume = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
 			   sizeof(struct bnxt_qplib_sge);
@@ -1366,8 +1369,8 @@ static void bnxt_re_set_hwq_pg_sz_lvl(struct bnxt_qplib_hwq *hwq, u8 pg_sz_sft,
 static int bnxt_re_setup_qp_hwqs(struct bnxt_re_qp *qp, bool fixed_que_attr)
 {
 	struct bnxt_qplib_res *res = &qp->rdev->qplib_res;
-	struct bnxt_qplib_hwq_attr hwq_attr = {};
 	struct bnxt_qplib_qp *qplib_qp = &qp->qplib_qp;
+	struct bnxt_qplib_hwq_attr hwq_attr = {};
 	struct bnxt_qplib_q *sq = &qplib_qp->sq;
 	struct bnxt_qplib_q *rq = &qplib_qp->rq;
 	u8 wqe_mode = qplib_qp->wqe_mode;
@@ -1378,7 +1381,8 @@ static int bnxt_re_setup_qp_hwqs(struct bnxt_re_qp *qp, bool fixed_que_attr)
 	hwq_attr.stride = bnxt_qplib_get_stride();
 	hwq_attr.aux_stride = qplib_qp->psn_sz;
 	hwq_attr.type = HWQ_TYPE_QUEUE;
-	if (!fixed_que_attr) {
+	/* STATIC mode (also for fixed-attribute QPs) is sized from max_wqe */
+	if (!fixed_que_attr || wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) {
 		hwq_attr.depth = bnxt_qplib_get_depth(sq, wqe_mode, true);
 		if (qplib_qp->psn_sz)
 			hwq_attr.aux_depth = qplib_qp->is_host_msn_tbl ?
@@ -1509,6 +1513,7 @@ static int bnxt_re_init_rq_attr(struct bnxt_re_qp *qp,
 	struct bnxt_qplib_qp *qplqp;
 	struct bnxt_re_dev *rdev;
 	struct bnxt_qplib_q *rq;
+	u32 max_sge;
 
 	rdev = qp->rdev;
 	qplqp = &qp->qplib_qp;
@@ -1522,12 +1527,16 @@ static int bnxt_re_init_rq_attr(struct bnxt_re_qp *qp,
 		qplqp->srq = &srq->qplib_srq;
 		rq->max_wqe = 0;
 	} else {
-		rq->max_sge = init_attr->cap.max_recv_sge;
-		if (rq->max_sge > dev_attr->max_qp_sges)
-			rq->max_sge = dev_attr->max_qp_sges;
+		/* Explicitly requested STATIC mode WQEs are fixed at
+		 * BNXT_STATIC_MAX_SGE SGEs. Legacy QPs keep their geometry.
+		 */
+		max_sge = dev_attr->max_qp_sges;
+		if (fixed_que_attr && qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
+			max_sge = min_t(u32, max_sge, BNXT_STATIC_MAX_SGE);
+		rq->max_sge = min_t(u32, init_attr->cap.max_recv_sge, max_sge);
 		init_attr->cap.max_recv_sge = rq->max_sge;
 		rq->wqe_size = bnxt_re_setup_rwqe_size(qplqp, rq->max_sge,
-						       dev_attr->max_qp_sges);
+						       max_sge);
 		if (!fixed_que_attr) {
 			/* Allocate 1 more than what's provided so posting max doesn't
 			 * mean empty.
@@ -1576,6 +1585,7 @@ static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
 	struct bnxt_re_dev *rdev;
 	struct bnxt_qplib_q *sq;
 	int diff = 0;
+	u32 max_sge;
 	int rc;
 
 	rdev = qp->rdev;
@@ -1589,8 +1599,11 @@ static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
 		sq->max_sw_wqe = ureq->sq_slots;
 		sq->wqe_size = sizeof(struct sq_sge);
 	} else {
-		if (sq->max_sge > dev_attr->max_qp_sges) {
-			sq->max_sge = dev_attr->max_qp_sges;
+		max_sge = dev_attr->max_qp_sges;
+		if (fixed_que_attr && qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
+			max_sge = min_t(u32, max_sge, BNXT_STATIC_MAX_SGE);
+		if (sq->max_sge > max_sge) {
+			sq->max_sge = max_sge;
 			init_attr->cap.max_send_sge = sq->max_sge;
 		}
 
@@ -1598,17 +1611,24 @@ static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
 		if (rc)
 			return rc;
 
-		/* Allocate 128 + 1 more than what's provided */
-		if (qplqp->wqe_mode != BNXT_QPLIB_WQE_MODE_VARIABLE)
-			diff = BNXT_QPLIB_RESERVED_QP_WRS;
-		sq->max_wqe = bnxt_re_init_depth(
-			init_attr->cap.max_send_wr + diff + 1,
-			dev_attr->max_qp_wqes + diff + 1, uctx);
-		if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE)
-			sq->max_sw_wqe = bnxt_qplib_get_depth(sq, qplqp->wqe_mode, true);
-		else
+		if (uctx && fixed_que_attr) {
+			sq->max_wqe = ((u64)ureq->sq_slots * bnxt_qplib_get_stride()) /
+				       sq->wqe_size;
+			/* Bound the depth by the device limit */
+			if (!sq->max_wqe || sq->max_wqe > dev_attr->max_qp_wqes + 1)
+				return -EINVAL;
 			sq->max_sw_wqe = sq->max_wqe;
-
+		} else {
+			/* Allocate 128 + 1 more than what's provided */
+			if (qplqp->wqe_mode != BNXT_QPLIB_WQE_MODE_VARIABLE)
+				diff = BNXT_QPLIB_RESERVED_QP_WRS;
+			sq->max_wqe = bnxt_re_init_depth(init_attr->cap.max_send_wr + diff + 1,
+							 dev_attr->max_qp_wqes + diff + 1, uctx);
+			if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE)
+				sq->max_sw_wqe = bnxt_qplib_get_depth(sq, qplqp->wqe_mode, true);
+			else
+				sq->max_sw_wqe = sq->max_wqe;
+		}
 	}
 	if (!fixed_que_attr) {
 		sq->q_full_delta = diff + 1;
@@ -1618,6 +1638,12 @@ static int bnxt_re_init_sq_attr(struct bnxt_re_qp *qp,
 		 * unexpected Queue full condition
 		 */
 		qplqp->sq.q_full_delta -= 1;
+	} else if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC &&
+		   !bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx)) {
+		/* Legacy chips need 128 WQEs reserved for HW (8916) */
+		if (sq->max_wqe <= BNXT_QPLIB_RESERVED_QP_WRS)
+			return -EINVAL;
+		sq->q_full_delta = BNXT_QPLIB_RESERVED_QP_WRS;
 	} else {
 		sq->q_full_delta = 0;
 	}
@@ -1699,7 +1725,7 @@ static void bnxt_re_qp_calculate_msn_psn_size(struct bnxt_re_qp *qp,
 
 	/* Update msn tbl size */
 	if (qplib_qp->is_host_msn_tbl && qplib_qp->psn_sz) {
-		if (!fixed_que_attr) {
+		if (!fixed_que_attr || wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) {
 			if (wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC)
 				qplib_qp->msn_tbl_sz =
 					roundup_pow_of_two(bnxt_qplib_set_sq_size(sq, wqe_mode));
@@ -1726,6 +1752,7 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
 	struct bnxt_qplib_qp *qplqp;
 	struct bnxt_re_dev *rdev;
 	struct bnxt_re_cq *cq;
+	bool static_req = false;
 	int rc = 0, qptype;
 
 	rdev = qp->rdev;
@@ -1743,15 +1770,51 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
 		return qptype;
 	qplqp->type = (u8)qptype;
 	qplqp->wqe_mode = bnxt_re_is_var_size_supported(rdev, uctx);
+
+	if (uctx && (ureq->comp_mask & BNXT_RE_QP_REQ_MASK_WQE_MODE)) {
+		switch (ureq->wqe_mode) {
+		case BNXT_RE_QP_REQ_WQE_MODE_DEFAULT:
+			break;
+		case BNXT_RE_QP_REQ_WQE_MODE_VARIABLE:
+			if (!bnxt_re_is_var_size_supported(rdev, uctx))
+				return -EOPNOTSUPP;
+			qplqp->wqe_mode = BNXT_QPLIB_WQE_MODE_VARIABLE;
+			break;
+		case BNXT_RE_QP_REQ_WQE_MODE_STATIC:
+			if (!fixed_que_attr)
+				return -EINVAL;
+			/* STATIC WQEs always use BNXT_STATIC_MAX_SGE SGEs */
+			if (dev_attr->max_qp_sges < BNXT_STATIC_MAX_SGE)
+				return -EOPNOTSUPP;
+			qplqp->wqe_mode = BNXT_QPLIB_WQE_MODE_STATIC;
+			static_req = true;
+			break;
+		default:
+			return -EINVAL;
+		}
+	}
 	if (uctx && qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE &&
-	    (!ureq->sq_slots || ureq->sq_slots > BNXT_RE_MAX_SQ_SLOTS))
+	    (!ureq->sq_slots || ureq->sq_slots > BNXT_RE_MAX_SQ_SLOTS ||
+	     !IS_ALIGNED(ureq->sq_slots, BNXT_VAR_MAX_SLOT_ALIGN)))
 		return -EINVAL;
 	if (fixed_que_attr) {
-		if (qplqp->wqe_mode != BNXT_QPLIB_WQE_MODE_VARIABLE)
+		if (qplqp->wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE) {
+			if (!ureq->sq_npsn ||
+			    ureq->sq_npsn > roundup_pow_of_two(ureq->sq_slots / 2))
+				return -EINVAL;
+		} else if (!static_req) {
+			/* STATIC must be requested explicitly, not implied */
 			return -EOPNOTSUPP;
-		if (!ureq->sq_npsn ||
-		    ureq->sq_npsn > roundup_pow_of_two(ureq->sq_slots / 2))
-			return -EINVAL;
+		} else {
+			/* sq_slots must hold a whole number of static WQEs */
+			u32 slots_per_wqe = bnxt_re_get_swqe_size(BNXT_STATIC_MAX_SGE) /
+					    bnxt_qplib_get_stride();
+
+			if (!ureq->sq_slots ||
+			    ureq->sq_slots > BNXT_RE_MAX_SQ_SLOTS ||
+			    ureq->sq_slots % slots_per_wqe)
+				return -EINVAL;
+		}
 	}
 	qplqp->dev_cap_flags = dev_attr->dev_cap_flags;
 	qplqp->cctx = rdev->chip_ctx;
@@ -1955,7 +2018,8 @@ int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,
 	uctx = rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx);
 	if (udata) {
 		rc = ib_copy_validate_udata_in_cm(udata, ureq, qp_handle,
-						  BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR);
+						  BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR |
+						  BNXT_RE_QP_REQ_MASK_WQE_MODE);
 		if (rc)
 			return rc;
 
diff --git a/include/uapi/rdma/bnxt_re-abi.h b/include/uapi/rdma/bnxt_re-abi.h
index 15ed2a51f8f1..79d458ed3af5 100644
--- a/include/uapi/rdma/bnxt_re-abi.h
+++ b/include/uapi/rdma/bnxt_re-abi.h
@@ -128,6 +128,13 @@ struct bnxt_re_resize_cq_req {
 
 enum bnxt_re_qp_mask {
 	BNXT_RE_QP_REQ_MASK_FIXED_QUE_ATTR = 0x1,
+	BNXT_RE_QP_REQ_MASK_WQE_MODE = 0x2,
+};
+
+enum bnxt_re_qp_req_wqe_mode {
+	BNXT_RE_QP_REQ_WQE_MODE_DEFAULT = 0x0,
+	BNXT_RE_QP_REQ_WQE_MODE_VARIABLE = 0x1,
+	BNXT_RE_QP_REQ_WQE_MODE_STATIC = 0x2,
 };
 
 struct bnxt_re_qp_req {
@@ -137,6 +144,8 @@ struct bnxt_re_qp_req {
 	__aligned_u64 comp_mask;
 	__u32 sq_slots;
 	__u32 sq_npsn;
+	__u32 wqe_mode;
+	__u32 rsvd0;
 };
 
 enum bnxt_re_create_qp_attrs {
-- 
2.39.3


      parent reply	other threads:[~2026-11-30  9:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:53 [PATCH for-next v2 0/4] RDMA/bnxt_re: CQ and QP updates for app allocated queues Selvin Xavier
2026-11-30 14:53 ` [PATCH for-next v2 1/4] RDMA/bnxt_re: Disable CQ overflow detection on P7 adapters based on FW support Selvin Xavier
2026-11-30 14:53 ` [PATCH for-next v2 2/4] RDMA/bnxt_re: Set CQ coalescing max buffers to 1 for CQs with depth 1 Selvin Xavier
2026-11-30 14:53 ` [PATCH for-next v2 3/4] RDMA/bnxt_re: Simplify PSN size and QP HWQ setup paths Selvin Xavier
2026-11-30 14:53 ` Selvin Xavier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130145344.322857-5-selvin.xavier@broadcom.com \
    --to=selvin.xavier@broadcom.com \
    --cc=abhishek.mohapatra@broadcom.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=jgg@ziepe.ca \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox