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 3/4] RDMA/bnxt_re: Simplify PSN size and QP HWQ setup paths
Date: Sun, 29 Nov 2026 15:21:04 -0800	[thread overview]
Message-ID: <20261129232105.358484-4-selvin.xavier@broadcom.com> (raw)
In-Reply-To: <20261129232105.358484-1-selvin.xavier@broadcom.com>

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

Factor out the SQ/RQ page size and level encoding into a helper,
flatten the RQ allocation in bnxt_re_setup_qp_hwqs(), fix the error
path to not free the RQ HWQ when an SRQ is used, and simplify
bnxt_re_get_psn_bytes(). No functional change intended.

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 | 96 ++++++++++++------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
index ac15372376a2..7d26d94ae8ea 100644
--- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c
+++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c
@@ -1168,28 +1168,30 @@ static int bnxt_re_get_psn_bytes(struct bnxt_re_dev *rdev,
 				 struct bnxt_re_qp_req *ureq,
 				 bool fixed_que_attr)
 {
+	bool msn_tbl = rdev->dev_attr &&
+		       _is_host_msn_table(rdev->dev_attr->dev_cap_flags2);
 	int psn_sz, psn_nume;
 
-	if (rdev->dev_attr &&
-	    _is_host_msn_table(rdev->dev_attr->dev_cap_flags2))
+	if (msn_tbl)
 		psn_sz = sizeof(struct sq_msn_search);
 	else
 		psn_sz = bnxt_qplib_is_chip_gen_p5_p7(rdev->chip_ctx) ?
 					sizeof(struct sq_psn_search_ext) :
 					sizeof(struct sq_psn_search);
-	if (!fixed_que_attr) {
-		if (cntx && bnxt_re_is_var_size_supported(rdev, cntx)) {
-			psn_nume = ureq->sq_slots;
-		} else {
-			psn_nume = (qplib_qp->wqe_mode == BNXT_QPLIB_WQE_MODE_STATIC) ?
-			qplib_qp->sq.max_wqe : ((qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
-				 sizeof(struct bnxt_qplib_sge));
-		}
-		if (_is_host_msn_table(rdev->qplib_res.dattr->dev_cap_flags2))
-			psn_nume = roundup_pow_of_two(psn_nume);
-	} else {
-		psn_nume = ureq->sq_npsn;
-	}
+
+	if (fixed_que_attr)
+		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)
+		psn_nume = qplib_qp->sq.max_wqe;
+	else
+		psn_nume = (qplib_qp->sq.max_wqe * qplib_qp->sq.wqe_size) /
+			   sizeof(struct bnxt_qplib_sge);
+
+	if (msn_tbl)
+		psn_nume = roundup_pow_of_two(psn_nume);
 
 	return psn_nume * psn_sz;
 }
@@ -1359,61 +1361,58 @@ static int bnxt_re_qp_alloc_init_xrrq(struct bnxt_re_qp *qp)
 	return rc;
 }
 
+static void bnxt_re_set_hwq_pg_sz_lvl(struct bnxt_qplib_hwq *hwq, u8 pg_sz_sft,
+				      u8 lvl_mask, u8 lvl_sft)
+{
+	hwq->pg_sz_lvl = (bnxt_qplib_base_pg_size(hwq) << pg_sz_sft) |
+			 ((hwq->level & lvl_mask) << lvl_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_qp *qplib_qp = &qp->qplib_qp;
 	struct bnxt_qplib_hwq_attr hwq_attr = {};
+	struct bnxt_qplib_qp *qplib_qp = &qp->qplib_qp;
 	struct bnxt_qplib_q *sq = &qplib_qp->sq;
 	struct bnxt_qplib_q *rq = &qplib_qp->rq;
 	u8 wqe_mode = qplib_qp->wqe_mode;
-	u8 pg_sz_lvl;
 	int rc;
 
 	hwq_attr.res = res;
 	hwq_attr.sginfo = &sq->sg_info;
 	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) {
 		hwq_attr.depth = bnxt_qplib_get_depth(sq, wqe_mode, true);
-		hwq_attr.aux_depth = (qplib_qp->psn_sz) ?
-				bnxt_qplib_set_sq_size(sq, wqe_mode) : 0;
-		if (qplib_qp->is_host_msn_tbl && qplib_qp->psn_sz)
-			hwq_attr.aux_depth = qplib_qp->msn_tbl_sz;
+		if (qplib_qp->psn_sz)
+			hwq_attr.aux_depth = qplib_qp->is_host_msn_tbl ?
+				qplib_qp->msn_tbl_sz :
+				bnxt_qplib_set_sq_size(sq, wqe_mode);
 	} else {
 		hwq_attr.depth = sq->max_wqe;
 		hwq_attr.aux_depth = qplib_qp->msn_tbl_sz;
 	}
-	hwq_attr.type = HWQ_TYPE_QUEUE;
 	rc = bnxt_qplib_alloc_init_hwq(&sq->hwq, &hwq_attr);
 	if (rc)
 		return rc;
+	bnxt_re_set_hwq_pg_sz_lvl(&sq->hwq, CMDQ_CREATE_QP_SQ_PG_SIZE_SFT,
+				  CMDQ_CREATE_QP_SQ_LVL_MASK,
+				  CMDQ_CREATE_QP_SQ_LVL_SFT);
+
+	if (!qplib_qp->srq) {
+		hwq_attr.sginfo = &rq->sg_info;
+		hwq_attr.depth = bnxt_qplib_get_depth(rq, wqe_mode, false);
+		hwq_attr.aux_stride = 0;
+		hwq_attr.aux_depth = 0;
+		rc = bnxt_qplib_alloc_init_hwq(&rq->hwq, &hwq_attr);
+		if (rc)
+			goto free_sq_hwq;
+		bnxt_re_set_hwq_pg_sz_lvl(&rq->hwq, CMDQ_CREATE_QP_RQ_PG_SIZE_SFT,
+					  CMDQ_CREATE_QP_RQ_LVL_MASK,
+					  CMDQ_CREATE_QP_RQ_LVL_SFT);
+	}
 
-	pg_sz_lvl = bnxt_qplib_base_pg_size(&sq->hwq) << CMDQ_CREATE_QP_SQ_PG_SIZE_SFT;
-	pg_sz_lvl |= ((sq->hwq.level & CMDQ_CREATE_QP_SQ_LVL_MASK) <<
-		      CMDQ_CREATE_QP_SQ_LVL_SFT);
-	sq->hwq.pg_sz_lvl = pg_sz_lvl;
-
-	if (qplib_qp->srq)
-		goto done;
-
-	hwq_attr.res = res;
-	hwq_attr.sginfo = &rq->sg_info;
-	hwq_attr.stride = bnxt_qplib_get_stride();
-	hwq_attr.depth = bnxt_qplib_get_depth(rq, qplib_qp->wqe_mode, false);
-	hwq_attr.aux_stride = 0;
-	hwq_attr.aux_depth = 0;
-	hwq_attr.type = HWQ_TYPE_QUEUE;
-	rc = bnxt_qplib_alloc_init_hwq(&rq->hwq, &hwq_attr);
-	if (rc)
-		goto free_sq_hwq;
-	pg_sz_lvl = bnxt_qplib_base_pg_size(&rq->hwq) <<
-		CMDQ_CREATE_QP_RQ_PG_SIZE_SFT;
-	pg_sz_lvl |= ((rq->hwq.level & CMDQ_CREATE_QP_RQ_LVL_MASK) <<
-		      CMDQ_CREATE_QP_RQ_LVL_SFT);
-	rq->hwq.pg_sz_lvl = pg_sz_lvl;
-
-done:
 	if (qplib_qp->psn_sz) {
 		rc = bnxt_re_qp_alloc_init_xrrq(qp);
 		if (rc)
@@ -1422,7 +1421,8 @@ static int bnxt_re_setup_qp_hwqs(struct bnxt_re_qp *qp, bool fixed_que_attr)
 
 	return 0;
 free_rq_hwq:
-	bnxt_qplib_free_hwq(res, &rq->hwq);
+	if (!qplib_qp->srq)
+		bnxt_qplib_free_hwq(res, &rq->hwq);
 free_sq_hwq:
 	bnxt_qplib_free_hwq(res, &sq->hwq);
 	return rc;
-- 
2.39.3


  parent reply	other threads:[~2026-11-29 18:00 UTC|newest]

Thread overview: 5+ 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 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 ` Selvin Xavier [this message]
2026-11-29 23:21 ` [PATCH for-next 4/4] RDMA/bnxt_re: Allow user library to request STATIC WQE mode per-QP 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-4-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