Blame SOURCES/0102-bnxt_re-lib-Enable-Broadcom-s-57500-RoCE-adapter.patch

81ae37
From 7089c4caf0e2ffa37d6a663b9fc7d05624841bf0 Mon Sep 17 00:00:00 2001
81ae37
From: Devesh Sharma <devesh.sharma@broadcom.com>
81ae37
Date: Sun, 13 Jan 2019 14:36:13 -0500
81ae37
Subject: [PATCH rdma-core 2/2] bnxt_re/lib: Enable Broadcom's 57500 RoCE
81ae37
 adapter
81ae37
81ae37
This is to add Broadcom's 57500 series of adapters support
81ae37
to RoCE from libbnxt_re. Listing below the significant changes
81ae37
done as part of the patch.
81ae37
81ae37
 - Added the pci-id of the basic gen-p5 chip.
81ae37
 - Adjust psn search memory allocation to suite new search
81ae37
   psn structure.
81ae37
 - Added chip context structure to select the appropriate
81ae37
   execution flow in data-path and control path.
81ae37
 - Fill psn search area as per new or older chip execution
81ae37
   flow.
81ae37
 - removed duplicate declaration of BNXT_RE_ABI_VERSION macro
81ae37
81ae37
Signed-off-by: Devesh Sharma <devesh.sharma@broadcom.com>
81ae37
---
81ae37
 providers/bnxt_re/bnxt_re-abi.h | 10 +++++--
81ae37
 providers/bnxt_re/main.c        | 14 +++++++++
81ae37
 providers/bnxt_re/main.h        | 15 +++++++++-
81ae37
 providers/bnxt_re/verbs.c       | 50 +++++++++++++++++++++++----------
81ae37
 4 files changed, 71 insertions(+), 18 deletions(-)
81ae37
81ae37
diff --git a/providers/bnxt_re/bnxt_re-abi.h b/providers/bnxt_re/bnxt_re-abi.h
81ae37
index 65d048d3..c6998e85 100644
81ae37
--- a/providers/bnxt_re/bnxt_re-abi.h
81ae37
+++ b/providers/bnxt_re/bnxt_re-abi.h
81ae37
@@ -43,8 +43,6 @@
81ae37
 #include <rdma/bnxt_re-abi.h>
81ae37
 #include <kernel-abi/bnxt_re-abi.h>
81ae37
 
81ae37
-#define BNXT_RE_ABI_VERSION 1
81ae37
-
81ae37
 #define BNXT_RE_FULL_FLAG_DELTA        0x80
81ae37
 
81ae37
 DECLARE_DRV_CMD(ubnxt_re_pd, IB_USER_VERBS_CMD_ALLOC_PD,
81ae37
@@ -246,6 +244,14 @@ struct bnxt_re_psns {
81ae37
 	__le32 flg_npsn;
81ae37
 };
81ae37
 
81ae37
+struct bnxt_re_psns_ext {
81ae37
+	__u32 opc_spsn;
81ae37
+	__u32 flg_npsn;
81ae37
+	__u16 st_slot_idx;
81ae37
+	__u16 rsvd0;
81ae37
+	__u32 rsvd1;
81ae37
+};
81ae37
+
81ae37
 struct bnxt_re_sge {
81ae37
 	__le64 pa;
81ae37
 	__le32 lkey;
81ae37
diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c
81ae37
index 1cd4d880..d171748e 100644
81ae37
--- a/providers/bnxt_re/main.c
81ae37
+++ b/providers/bnxt_re/main.c
81ae37
@@ -74,6 +74,7 @@ static const struct verbs_match_ent cna_table[] = {
81ae37
 	CNA(BROADCOM, 0x16EF),  /* BCM57416 NPAR */
81ae37
 	CNA(BROADCOM, 0x16F0),  /* BCM58730 */
81ae37
 	CNA(BROADCOM, 0x16F1),  /* BCM57452 */
81ae37
+	CNA(BROADCOM, 0x1750),	/* BCM57500 */
81ae37
 	CNA(BROADCOM, 0xD800),  /* BCM880xx VF */
81ae37
 	CNA(BROADCOM, 0xD802),  /* BCM58802 */
81ae37
 	CNA(BROADCOM, 0xD804),   /* BCM8804 SR */
81ae37
@@ -108,6 +109,11 @@ static const struct verbs_context_ops bnxt_re_cntx_ops = {
81ae37
 	.destroy_ah    = bnxt_re_destroy_ah
81ae37
 };
81ae37
 
81ae37
+bool bnxt_re_is_chip_gen_p5(struct bnxt_re_chip_ctx *cctx)
81ae37
+{
81ae37
+	return cctx->chip_num == CHIP_NUM_57500;
81ae37
+}
81ae37
+
81ae37
 /* Context Init functions */
81ae37
 static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
81ae37
 						   int cmd_fd,
81ae37
@@ -133,6 +139,14 @@ static struct verbs_context *bnxt_re_alloc_context(struct ibv_device *vdev,
81ae37
 	dev->pg_size = resp.pg_size;
81ae37
 	dev->cqe_size = resp.cqe_sz;
81ae37
 	dev->max_cq_depth = resp.max_cqd;
81ae37
+	if (resp.comp_mask & BNXT_RE_UCNTX_CMASK_HAVE_CCTX) {
81ae37
+		cntx->cctx.chip_num = resp.chip_id0 & 0xFFFF;
81ae37
+		cntx->cctx.chip_rev = (resp.chip_id0 >>
81ae37
+				       BNXT_RE_CHIP_ID0_CHIP_REV_SFT) & 0xFF;
81ae37
+		cntx->cctx.chip_metal = (resp.chip_id0 >>
81ae37
+					 BNXT_RE_CHIP_ID0_CHIP_MET_SFT) &
81ae37
+					 0xFF;
81ae37
+	}
81ae37
 	pthread_spin_init(&cntx->fqlock, PTHREAD_PROCESS_PRIVATE);
81ae37
 	/* mmap shared page. */
81ae37
 	cntx->shpg = mmap(NULL, dev->pg_size, PROT_READ | PROT_WRITE,
81ae37
diff --git a/providers/bnxt_re/main.h b/providers/bnxt_re/main.h
81ae37
index 0b5c749f..be573496 100644
81ae37
--- a/providers/bnxt_re/main.h
81ae37
+++ b/providers/bnxt_re/main.h
81ae37
@@ -54,7 +54,14 @@
81ae37
 
81ae37
 #define DEV	"bnxt_re : "
81ae37
 
81ae37
-#define BNXT_RE_UD_QP_HW_STALL 0x400000
81ae37
+#define BNXT_RE_UD_QP_HW_STALL	0x400000
81ae37
+
81ae37
+#define CHIP_NUM_57500		0x1750
81ae37
+struct bnxt_re_chip_ctx {
81ae37
+	__u16 chip_num;
81ae37
+	__u8 chip_rev;
81ae37
+	__u8 chip_metal;
81ae37
+};
81ae37
 
81ae37
 struct bnxt_re_dpi {
81ae37
 	__u32 dpindx;
81ae37
@@ -81,6 +88,7 @@ struct bnxt_re_cq {
81ae37
 };
81ae37
 
81ae37
 struct bnxt_re_wrid {
81ae37
+	struct bnxt_re_psns_ext *psns_ext;
81ae37
 	struct bnxt_re_psns *psns;
81ae37
 	uint64_t wrid;
81ae37
 	uint32_t bytes;
81ae37
@@ -111,6 +119,7 @@ struct bnxt_re_srq {
81ae37
 
81ae37
 struct bnxt_re_qp {
81ae37
 	struct ibv_qp ibvqp;
81ae37
+	struct bnxt_re_chip_ctx *cctx;
81ae37
 	struct bnxt_re_queue *sqq;
81ae37
 	struct bnxt_re_wrid *swrid;
81ae37
 	struct bnxt_re_queue *rqq;
81ae37
@@ -155,6 +164,7 @@ struct bnxt_re_context {
81ae37
 	struct verbs_context ibvctx;
81ae37
 	uint32_t dev_id;
81ae37
 	uint32_t max_qp;
81ae37
+	struct bnxt_re_chip_ctx cctx;
81ae37
 	uint32_t max_srq;
81ae37
 	struct bnxt_re_dpi udpi;
81ae37
 	void *shpg;
81ae37
@@ -162,6 +172,9 @@ struct bnxt_re_context {
81ae37
 	pthread_spinlock_t fqlock;
81ae37
 };
81ae37
 
81ae37
+/* Chip context related functions */
81ae37
+bool bnxt_re_is_chip_gen_p5(struct bnxt_re_chip_ctx *cctx);
81ae37
+
81ae37
 /* DB ring functions used internally*/
81ae37
 void bnxt_re_ring_rq_db(struct bnxt_re_qp *qp);
81ae37
 void bnxt_re_ring_sq_db(struct bnxt_re_qp *qp);
81ae37
diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c
81ae37
index 7786d247..bec382b3 100644
81ae37
--- a/providers/bnxt_re/verbs.c
81ae37
+++ b/providers/bnxt_re/verbs.c
81ae37
@@ -844,9 +844,11 @@ static void bnxt_re_free_queues(struct bnxt_re_qp *qp)
81ae37
 static int bnxt_re_alloc_queues(struct bnxt_re_qp *qp,
81ae37
 				struct ibv_qp_init_attr *attr,
81ae37
 				uint32_t pg_size) {
81ae37
+	struct bnxt_re_psns_ext *psns_ext;
81ae37
 	struct bnxt_re_queue *que;
81ae37
 	struct bnxt_re_psns *psns;
81ae37
 	uint32_t psn_depth;
81ae37
+	uint32_t psn_size;
81ae37
 	int ret, indx;
81ae37
 
81ae37
 	que = qp->sqq;
81ae37
@@ -857,11 +859,12 @@ static int bnxt_re_alloc_queues(struct bnxt_re_qp *qp,
81ae37
 	que->diff = que->depth - attr->cap.max_send_wr;
81ae37
 
81ae37
 	/* psn_depth extra entries of size que->stride */
81ae37
-	psn_depth = (que->depth * sizeof(struct bnxt_re_psns)) /
81ae37
-		     que->stride;
81ae37
-	if ((que->depth * sizeof(struct bnxt_re_psns)) % que->stride)
81ae37
+	psn_size = bnxt_re_is_chip_gen_p5(qp->cctx) ?
81ae37
+					sizeof(struct bnxt_re_psns_ext) :
81ae37
+					sizeof(struct bnxt_re_psns);
81ae37
+	psn_depth = (que->depth * psn_size) / que->stride;
81ae37
+	if ((que->depth * psn_size) % que->stride)
81ae37
 		psn_depth++;
81ae37
-
81ae37
 	que->depth += psn_depth;
81ae37
 	/* PSN-search memory is allocated without checking for
81ae37
 	 * QP-Type. Kenrel driver do not map this memory if it
81ae37
@@ -875,6 +878,7 @@ static int bnxt_re_alloc_queues(struct bnxt_re_qp *qp,
81ae37
 	que->depth -= psn_depth;
81ae37
 	/* start of spsn space sizeof(struct bnxt_re_psns) each. */
81ae37
 	psns = (que->va + que->stride * que->depth);
81ae37
+	psns_ext = (struct bnxt_re_psns_ext *)psns;
81ae37
 	pthread_spin_init(&que->qlock, PTHREAD_PROCESS_PRIVATE);
81ae37
 	qp->swrid = calloc(que->depth, sizeof(struct bnxt_re_wrid));
81ae37
 	if (!qp->swrid) {
81ae37
@@ -884,6 +888,13 @@ static int bnxt_re_alloc_queues(struct bnxt_re_qp *qp,
81ae37
 
81ae37
 	for (indx = 0 ; indx < que->depth; indx++, psns++)
81ae37
 		qp->swrid[indx].psns = psns;
81ae37
+	if (bnxt_re_is_chip_gen_p5(qp->cctx)) {
81ae37
+		for (indx = 0 ; indx < que->depth; indx++, psns_ext++) {
81ae37
+			qp->swrid[indx].psns_ext = psns_ext;
81ae37
+			qp->swrid[indx].psns = (struct bnxt_re_psns *)psns_ext;
81ae37
+		}
81ae37
+	}
81ae37
+
81ae37
 	qp->cap.max_swr = que->depth;
81ae37
 
81ae37
 	if (qp->rqq) {
81ae37
@@ -931,6 +942,7 @@ struct ibv_qp *bnxt_re_create_qp(struct ibv_pd *ibvpd,
81ae37
 	if (bnxt_re_alloc_queue_ptr(qp, attr))
81ae37
 		goto fail;
81ae37
 	/* alloc queues */
81ae37
+	qp->cctx = &cntx->cctx;
81ae37
 	if (bnxt_re_alloc_queues(qp, attr, dev->pg_size))
81ae37
 		goto failq;
81ae37
 	/* Fill ibv_cmd */
81ae37
@@ -1094,26 +1106,36 @@ static int bnxt_re_build_sge(struct bnxt_re_sge *sge, struct ibv_sge *sg_list,
81ae37
 	return length;
81ae37
 }
81ae37
 
81ae37
-static void bnxt_re_fill_psns(struct bnxt_re_qp *qp, struct bnxt_re_psns *psns,
81ae37
+static void bnxt_re_fill_psns(struct bnxt_re_qp *qp, struct bnxt_re_wrid *wrid,
81ae37
 			      uint8_t opcode, uint32_t len)
81ae37
 {
81ae37
-	uint32_t pkt_cnt = 0, nxt_psn;
81ae37
+	uint32_t opc_spsn = 0, flg_npsn = 0;
81ae37
+	struct bnxt_re_psns_ext *psns_ext;
81ae37
+	uint32_t pkt_cnt = 0, nxt_psn = 0;
81ae37
+	struct bnxt_re_psns *psns;
81ae37
+
81ae37
+	psns = wrid->psns;
81ae37
+	psns_ext = wrid->psns_ext;
81ae37
 
81ae37
-	memset(psns, 0, sizeof(*psns));
81ae37
 	if (qp->qptyp == IBV_QPT_RC) {
81ae37
-		psns->opc_spsn = htole32(qp->sq_psn & BNXT_RE_PSNS_SPSN_MASK);
81ae37
+		opc_spsn = qp->sq_psn & BNXT_RE_PSNS_SPSN_MASK;
81ae37
 		pkt_cnt = (len / qp->mtu);
81ae37
 		if (len % qp->mtu)
81ae37
 			pkt_cnt++;
81ae37
 		if (len == 0)
81ae37
 			pkt_cnt = 1;
81ae37
 		nxt_psn = ((qp->sq_psn + pkt_cnt) & BNXT_RE_PSNS_NPSN_MASK);
81ae37
-		psns->flg_npsn = htole32(nxt_psn);
81ae37
+		flg_npsn = nxt_psn;
81ae37
 		qp->sq_psn = nxt_psn;
81ae37
 	}
81ae37
 	opcode = bnxt_re_ibv_wr_to_wc_opcd(opcode);
81ae37
-	psns->opc_spsn |= htole32(((opcode & BNXT_RE_PSNS_OPCD_MASK) <<
81ae37
-				    BNXT_RE_PSNS_OPCD_SHIFT));
81ae37
+	opc_spsn |= (((uint32_t)opcode & BNXT_RE_PSNS_OPCD_MASK) <<
81ae37
+		      BNXT_RE_PSNS_OPCD_SHIFT);
81ae37
+	memset(psns, 0, sizeof(*psns));
81ae37
+	psns->opc_spsn = htole32(opc_spsn);
81ae37
+	psns->flg_npsn = htole32(flg_npsn);
81ae37
+	if (bnxt_re_is_chip_gen_p5(qp->cctx))
81ae37
+		psns_ext->st_slot_idx = 0;
81ae37
 }
81ae37
 
81ae37
 static void bnxt_re_fill_wrid(struct bnxt_re_wrid *wrid, struct ibv_send_wr *wr,
81ae37
@@ -1235,10 +1257,9 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
81ae37
 {
81ae37
 	struct bnxt_re_qp *qp = to_bnxt_re_qp(ibvqp);
81ae37
 	struct bnxt_re_queue *sq = qp->sqq;
81ae37
-	struct bnxt_re_bsqe *hdr;
81ae37
 	struct bnxt_re_wrid *wrid;
81ae37
-	struct bnxt_re_psns *psns;
81ae37
 	uint8_t is_inline = false;
81ae37
+	struct bnxt_re_bsqe *hdr;
81ae37
 	int ret = 0, bytes = 0;
81ae37
 	bool ring_db = false;
81ae37
 	void *sqe;
81ae37
@@ -1268,7 +1289,6 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
81ae37
 
81ae37
 		sqe = (void *)(sq->va + (sq->tail * sq->stride));
81ae37
 		wrid = &qp->swrid[sq->tail];
81ae37
-		psns = wrid->psns;
81ae37
 
81ae37
 		memset(sqe, 0, bnxt_re_get_sqe_sz());
81ae37
 		hdr = sqe;
81ae37
@@ -1318,7 +1338,7 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr,
81ae37
 		}
81ae37
 
81ae37
 		bnxt_re_fill_wrid(wrid, wr, bytes, qp->cap.sqsig);
81ae37
-		bnxt_re_fill_psns(qp, psns, wr->opcode, bytes);
81ae37
+		bnxt_re_fill_psns(qp, wrid, wr->opcode, bytes);
81ae37
 		bnxt_re_incr_tail(sq);
81ae37
 		qp->wqe_cnt++;
81ae37
 		wr = wr->next;
81ae37
-- 
81ae37
2.20.1
81ae37