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

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