Skip to content

Commit b08fe04

Browse files
Devesh Sharmajgunthorpe
authored andcommitted
RDMA/bnxt_re: Refactor net ring allocation function
Introducing a new attribute structure to reduce the long list of arguments passed in bnxt_re_net_ring_alloc() function. The caller of bnxt_re_net_ring_alloc should fill in the list of attributes in bnxt_re_ring_attr structure and then pass the pointer to the function. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Naresh Kumar PBS <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Signed-off-by: Devesh Sharma <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 0c4dcd6 commit b08fe04

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@
8989

9090
#define BNXT_RE_DEFAULT_ACK_DELAY 16
9191

92+
struct bnxt_re_ring_attr {
93+
dma_addr_t *dma_arr;
94+
int pages;
95+
int type;
96+
u32 depth;
97+
u32 lrid; /* Logical ring id */
98+
u8 mode;
99+
};
100+
92101
struct bnxt_re_work {
93102
struct work_struct work;
94103
unsigned long event;

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ static int bnxt_re_net_ring_free(struct bnxt_re_dev *rdev,
427427
return rc;
428428
}
429429

430-
static int bnxt_re_net_ring_alloc(struct bnxt_re_dev *rdev, dma_addr_t *dma_arr,
431-
int pages, int type, u32 ring_mask,
432-
u32 map_index, u16 *fw_ring_id)
430+
static int bnxt_re_net_ring_alloc(struct bnxt_re_dev *rdev,
431+
struct bnxt_re_ring_attr *ring_attr,
432+
u16 *fw_ring_id)
433433
{
434434
struct bnxt_en_dev *en_dev = rdev->en_dev;
435435
struct hwrm_ring_alloc_input req = {0};
@@ -443,18 +443,18 @@ static int bnxt_re_net_ring_alloc(struct bnxt_re_dev *rdev, dma_addr_t *dma_arr,
443443
memset(&fw_msg, 0, sizeof(fw_msg));
444444
bnxt_re_init_hwrm_hdr(rdev, (void *)&req, HWRM_RING_ALLOC, -1, -1);
445445
req.enables = 0;
446-
req.page_tbl_addr = cpu_to_le64(dma_arr[0]);
447-
if (pages > 1) {
446+
req.page_tbl_addr = cpu_to_le64(ring_attr->dma_arr[0]);
447+
if (ring_attr->pages > 1) {
448448
/* Page size is in log2 units */
449449
req.page_size = BNXT_PAGE_SHIFT;
450450
req.page_tbl_depth = 1;
451451
}
452452
req.fbo = 0;
453453
/* Association of ring index with doorbell index and MSIX number */
454-
req.logical_id = cpu_to_le16(map_index);
455-
req.length = cpu_to_le32(ring_mask + 1);
456-
req.ring_type = type;
457-
req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
454+
req.logical_id = cpu_to_le16(ring_attr->lrid);
455+
req.length = cpu_to_le32(ring_attr->depth + 1);
456+
req.ring_type = ring_attr->type;
457+
req.int_mode = ring_attr->mode;
458458
bnxt_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
459459
sizeof(resp), DFLT_HWRM_CMD_TIMEOUT);
460460
rc = en_dev->en_ops->bnxt_send_fw_msg(en_dev, BNXT_ROCE_ULP, &fw_msg);
@@ -1006,10 +1006,10 @@ static void bnxt_re_free_res(struct bnxt_re_dev *rdev)
10061006

10071007
static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
10081008
{
1009+
struct bnxt_re_ring_attr rattr = {};
1010+
struct bnxt_qplib_ctx *qplib_ctx;
10091011
int num_vec_created = 0;
1010-
dma_addr_t *pg_map;
10111012
int rc = 0, i;
1012-
int pages;
10131013
u8 type;
10141014

10151015
/* Configure and allocate resources for qplib */
@@ -1030,23 +1030,27 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
10301030
if (rc)
10311031
goto dealloc_res;
10321032

1033+
qplib_ctx = &rdev->qplib_ctx;
10331034
for (i = 0; i < rdev->num_msix - 1; i++) {
1034-
rdev->nq[i].res = &rdev->qplib_res;
1035-
rdev->nq[i].hwq.max_elements = BNXT_RE_MAX_CQ_COUNT +
1036-
BNXT_RE_MAX_SRQC_COUNT + 2;
1035+
struct bnxt_qplib_nq *nq;
1036+
1037+
nq = &rdev->nq[i];
1038+
nq->hwq.max_elements = (qplib_ctx->cq_count +
1039+
qplib_ctx->srqc_count + 2);
10371040
rc = bnxt_qplib_alloc_nq(&rdev->qplib_res, &rdev->nq[i]);
10381041
if (rc) {
10391042
dev_err(rdev_to_dev(rdev), "Alloc Failed NQ%d rc:%#x",
10401043
i, rc);
10411044
goto free_nq;
10421045
}
10431046
type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1044-
pg_map = rdev->nq[i].hwq.pbl[PBL_LVL_0].pg_map_arr;
1045-
pages = rdev->nq[i].hwq.pbl[rdev->nq[i].hwq.level].pg_count;
1046-
rc = bnxt_re_net_ring_alloc(rdev, pg_map, pages, type,
1047-
BNXT_QPLIB_NQE_MAX_CNT - 1,
1048-
rdev->msix_entries[i + 1].ring_idx,
1049-
&rdev->nq[i].ring_id);
1047+
rattr.dma_arr = nq->hwq.pbl[PBL_LVL_0].pg_map_arr;
1048+
rattr.pages = nq->hwq.pbl[rdev->nq[i].hwq.level].pg_count;
1049+
rattr.type = type;
1050+
rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
1051+
rattr.depth = BNXT_QPLIB_NQE_MAX_CNT - 1;
1052+
rattr.lrid = rdev->msix_entries[i + 1].ring_idx;
1053+
rc = bnxt_re_net_ring_alloc(rdev, &rattr, &nq->ring_id);
10501054
if (rc) {
10511055
dev_err(rdev_to_dev(rdev),
10521056
"Failed to allocate NQ fw id with rc = 0x%x",
@@ -1371,10 +1375,10 @@ static void bnxt_re_worker(struct work_struct *work)
13711375

13721376
static int bnxt_re_ib_reg(struct bnxt_re_dev *rdev)
13731377
{
1374-
dma_addr_t *pg_map;
1375-
u32 db_offt, ridx;
1376-
int pages, vid;
1378+
struct bnxt_re_ring_attr rattr;
1379+
u32 db_offt;
13771380
bool locked;
1381+
int vid;
13781382
u8 type;
13791383
int rc;
13801384

@@ -1383,6 +1387,7 @@ static int bnxt_re_ib_reg(struct bnxt_re_dev *rdev)
13831387
locked = true;
13841388

13851389
/* Registered a new RoCE device instance to netdev */
1390+
memset(&rattr, 0, sizeof(rattr));
13861391
rc = bnxt_re_register_netdev(rdev);
13871392
if (rc) {
13881393
rtnl_unlock();
@@ -1422,12 +1427,13 @@ static int bnxt_re_ib_reg(struct bnxt_re_dev *rdev)
14221427
}
14231428

14241429
type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1425-
pg_map = rdev->rcfw.creq.pbl[PBL_LVL_0].pg_map_arr;
1426-
pages = rdev->rcfw.creq.pbl[rdev->rcfw.creq.level].pg_count;
1427-
ridx = rdev->msix_entries[BNXT_RE_AEQ_IDX].ring_idx;
1428-
rc = bnxt_re_net_ring_alloc(rdev, pg_map, pages, type,
1429-
BNXT_QPLIB_CREQE_MAX_CNT - 1,
1430-
ridx, &rdev->rcfw.creq_ring_id);
1430+
rattr.dma_arr = rdev->rcfw.creq.pbl[PBL_LVL_0].pg_map_arr;
1431+
rattr.pages = rdev->rcfw.creq.pbl[rdev->rcfw.creq.level].pg_count;
1432+
rattr.type = type;
1433+
rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
1434+
rattr.depth = BNXT_QPLIB_CREQE_MAX_CNT - 1;
1435+
rattr.lrid = rdev->msix_entries[BNXT_RE_AEQ_IDX].ring_idx;
1436+
rc = bnxt_re_net_ring_alloc(rdev, &rattr, &rdev->rcfw.creq_ring_id);
14311437
if (rc) {
14321438
pr_err("Failed to allocate CREQ: %#x\n", rc);
14331439
goto free_rcfw;

0 commit comments

Comments
 (0)