All of lore.kernel.org
 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 4/4] RDMA/bnxt_re: Allow user library to request STATIC WQE mode per-QP
Date: Sun, 29 Nov 2026 15:21:05 -0800	[thread overview]
Message-ID: <20261129232105.358484-5-selvin.xavier@broadcom.com> (raw)
In-Reply-To: <20261129232105.358484-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.

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 | 92 ++++++++++++++++++------
 include/uapi/rdma/bnxt_re-abi.h          |  9 +++
 2 files changed, 80 insertions(+), 21 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
index 7d26d94ae8ea..cd4064682574 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
@@ -1168,6 +1168,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;
@@ -1179,13 +1180,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)
+		psn_nume = ureq->sq_slots;
 	else
 		psn_nume = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
 			   sizeof(struct bnxt_qplib_sge);
@@ -1371,8 +1374,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;
@@ -1383,7 +1386,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 ?
@@ -1603,16 +1607,23 @@ 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;
+			if (!sq->max_wqe || sq->max_wqe > dev_attr->max_qp_wqes)
+				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) {
@@ -1704,7 +1715,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));
@@ -1731,6 +1742,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;
@@ -1748,15 +1760,52 @@ 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)) {
+		if (ureq->rsvd0)
+			return -EINVAL;
+		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;
+			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))
 		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 power-of-two number of static
+			 * WQEs, since the SQ depth is used as an index mask.
+			 */
+			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 ||
+			    !is_power_of_2(ureq->sq_slots / slots_per_wqe))
+				return -EINVAL;
+		}
 	}
 	qplqp->dev_cap_flags = dev_attr->dev_cap_flags;
 	qplqp->cctx = rdev->chip_ctx;
@@ -1960,7 +2009,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 856a1b3036e9..719799ecd0e6 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-29 18:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 23:21 [PATCH for-next 0/4] RDMA/bnxt_re: CQ and QP updates for app allocated queues Selvin Xavier
2026-11-29 18:21 ` sashiko-bot
2026-11-29 23:21 ` [PATCH for-next 1/4] RDMA/bnxt_re: Disable CQ overflow detection on P7 adapters based on FW support Selvin Xavier
2026-11-29 23:21 ` [PATCH for-next 2/4] RDMA/bnxt_re: Set CQ coalescing max buffers to 1 for CQs with depth 1 Selvin Xavier
2026-11-29 23:21 ` [PATCH for-next 3/4] RDMA/bnxt_re: Simplify PSN size and QP HWQ setup paths Selvin Xavier
2026-11-29 23:21 ` Selvin Xavier [this message]
2026-11-29 18:21   ` [PATCH for-next 4/4] RDMA/bnxt_re: Allow user library to request STATIC WQE mode per-QP sashiko-bot
2026-11-30  7:35     ` Selvin Xavier

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=20261129232105.358484-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.