Skip to content

Commit 30b8713

Browse files
Kalesh APrleon
authored andcommitted
RDMA/bnxt_re: Refactor NQ allocation
Move NQ related data structures from rdev to a new structure named "struct bnxt_re_nq_record" by keeping a pointer to in the rdev structure. Allocate the memory for it dynamically. This change is needed for subsequent patches in the series. Also, removed the nq_task variable from rdev structure as it is redundant and no longer used. This change would help to reduce the size of the driver private structure as well. Reviewed-by: Chandramohan Akula <[email protected]> Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 65ecee1 commit 30b8713

File tree

3 files changed

+60
-33
lines changed

3 files changed

+60
-33
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ struct bnxt_re_pacing {
155155
#define BNXT_RE_GRC_FIFO_REG_BASE 0x2000
156156

157157
#define BNXT_RE_MIN_MSIX 2
158+
#define BNXT_RE_MAX_MSIX BNXT_MAX_ROCE_MSIX
159+
struct bnxt_re_nq_record {
160+
struct bnxt_qplib_nq nq[BNXT_RE_MAX_MSIX];
161+
int num_msix;
162+
};
158163

159164
#define MAX_CQ_HASH_BITS (16)
160165
#define MAX_SRQ_HASH_BITS (16)
@@ -183,21 +188,17 @@ struct bnxt_re_dev {
183188
unsigned int version, major, minor;
184189
struct bnxt_qplib_chip_ctx *chip_ctx;
185190
struct bnxt_en_dev *en_dev;
186-
int num_msix;
187191

188192
int id;
189193

190194
struct delayed_work worker;
191195
u8 cur_prio_map;
192196

193-
/* FP Notification Queue (CQ & SRQ) */
194-
struct tasklet_struct nq_task;
195-
196197
/* RCFW Channel */
197198
struct bnxt_qplib_rcfw rcfw;
198199

199-
/* NQ */
200-
struct bnxt_qplib_nq nq[BNXT_MAX_ROCE_MSIX];
200+
/* NQ record */
201+
struct bnxt_re_nq_record *nqr;
201202

202203
/* Device Resources */
203204
struct bnxt_qplib_dev_attr dev_attr;

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,8 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq,
18721872
srq->qplib_srq.wqe_size = bnxt_re_get_rwqe_size(dev_attr->max_srq_sges);
18731873
srq->qplib_srq.threshold = srq_init_attr->attr.srq_limit;
18741874
srq->srq_limit = srq_init_attr->attr.srq_limit;
1875-
srq->qplib_srq.eventq_hw_ring_id = rdev->nq[0].ring_id;
1876-
nq = &rdev->nq[0];
1875+
srq->qplib_srq.eventq_hw_ring_id = rdev->nqr->nq[0].ring_id;
1876+
nq = &rdev->nqr->nq[0];
18771877

18781878
if (udata) {
18791879
rc = bnxt_re_init_user_srq(rdev, pd, srq, udata);
@@ -3122,7 +3122,7 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
31223122
* used for getting the NQ index.
31233123
*/
31243124
nq_alloc_cnt = atomic_inc_return(&rdev->nq_alloc_cnt);
3125-
nq = &rdev->nq[nq_alloc_cnt % (rdev->num_msix - 1)];
3125+
nq = &rdev->nqr->nq[nq_alloc_cnt % (rdev->nqr->num_msix - 1)];
31263126
cq->qplib_cq.max_wqe = entries;
31273127
cq->qplib_cq.cnq_hw_ring_id = nq->ring_id;
31283128
cq->qplib_cq.nq = nq;

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ static void bnxt_re_stop_irq(void *handle)
326326
rdev = en_info->rdev;
327327
rcfw = &rdev->rcfw;
328328

329-
for (indx = BNXT_RE_NQ_IDX; indx < rdev->num_msix; indx++) {
330-
nq = &rdev->nq[indx - 1];
329+
for (indx = BNXT_RE_NQ_IDX; indx < rdev->nqr->num_msix; indx++) {
330+
nq = &rdev->nqr->nq[indx - 1];
331331
bnxt_qplib_nq_stop_irq(nq, false);
332332
}
333333

@@ -362,7 +362,7 @@ static void bnxt_re_start_irq(void *handle, struct bnxt_msix_entry *ent)
362362
/* Vectors may change after restart, so update with new vectors
363363
* in device sctructure.
364364
*/
365-
for (indx = 0; indx < rdev->num_msix; indx++)
365+
for (indx = 0; indx < rdev->nqr->num_msix; indx++)
366366
rdev->en_dev->msix_entries[indx].vector = ent[indx].vector;
367367

368368
rc = bnxt_qplib_rcfw_start_irq(rcfw, msix_ent[BNXT_RE_AEQ_IDX].vector,
@@ -371,8 +371,8 @@ static void bnxt_re_start_irq(void *handle, struct bnxt_msix_entry *ent)
371371
ibdev_warn(&rdev->ibdev, "Failed to reinit CREQ\n");
372372
return;
373373
}
374-
for (indx = BNXT_RE_NQ_IDX ; indx < rdev->num_msix; indx++) {
375-
nq = &rdev->nq[indx - 1];
374+
for (indx = BNXT_RE_NQ_IDX ; indx < rdev->nqr->num_msix; indx++) {
375+
nq = &rdev->nqr->nq[indx - 1];
376376
rc = bnxt_qplib_nq_start_irq(nq, indx - 1,
377377
msix_ent[indx].vector, false);
378378
if (rc) {
@@ -1206,7 +1206,7 @@ static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)
12061206

12071207
addrconf_addr_eui48((u8 *)&ibdev->node_guid, rdev->netdev->dev_addr);
12081208

1209-
ibdev->num_comp_vectors = rdev->num_msix - 1;
1209+
ibdev->num_comp_vectors = rdev->nqr->num_msix - 1;
12101210
ibdev->dev.parent = &rdev->en_dev->pdev->dev;
12111211
ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY;
12121212

@@ -1551,8 +1551,8 @@ static void bnxt_re_cleanup_res(struct bnxt_re_dev *rdev)
15511551
{
15521552
int i;
15531553

1554-
for (i = 1; i < rdev->num_msix; i++)
1555-
bnxt_qplib_disable_nq(&rdev->nq[i - 1]);
1554+
for (i = 1; i < rdev->nqr->num_msix; i++)
1555+
bnxt_qplib_disable_nq(&rdev->nqr->nq[i - 1]);
15561556

15571557
if (rdev->qplib_res.rcfw)
15581558
bnxt_qplib_cleanup_res(&rdev->qplib_res);
@@ -1566,9 +1566,9 @@ static int bnxt_re_init_res(struct bnxt_re_dev *rdev)
15661566

15671567
bnxt_qplib_init_res(&rdev->qplib_res);
15681568

1569-
for (i = 1; i < rdev->num_msix ; i++) {
1569+
for (i = 1; i < rdev->nqr->num_msix ; i++) {
15701570
db_offt = rdev->en_dev->msix_entries[i].db_offset;
1571-
rc = bnxt_qplib_enable_nq(rdev->en_dev->pdev, &rdev->nq[i - 1],
1571+
rc = bnxt_qplib_enable_nq(rdev->en_dev->pdev, &rdev->nqr->nq[i - 1],
15721572
i - 1, rdev->en_dev->msix_entries[i].vector,
15731573
db_offt, &bnxt_re_cqn_handler,
15741574
&bnxt_re_srqn_handler);
@@ -1582,20 +1582,22 @@ static int bnxt_re_init_res(struct bnxt_re_dev *rdev)
15821582
return 0;
15831583
fail:
15841584
for (i = num_vec_enabled; i >= 0; i--)
1585-
bnxt_qplib_disable_nq(&rdev->nq[i]);
1585+
bnxt_qplib_disable_nq(&rdev->nqr->nq[i]);
15861586
return rc;
15871587
}
15881588

15891589
static void bnxt_re_free_nq_res(struct bnxt_re_dev *rdev)
15901590
{
1591+
struct bnxt_qplib_nq *nq;
15911592
u8 type;
15921593
int i;
15931594

1594-
for (i = 0; i < rdev->num_msix - 1; i++) {
1595+
for (i = 0; i < rdev->nqr->num_msix - 1; i++) {
15951596
type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1596-
bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id, type);
1597-
bnxt_qplib_free_nq(&rdev->nq[i]);
1598-
rdev->nq[i].res = NULL;
1597+
nq = &rdev->nqr->nq[i];
1598+
bnxt_re_net_ring_free(rdev, nq->ring_id, type);
1599+
bnxt_qplib_free_nq(nq);
1600+
nq->res = NULL;
15991601
}
16001602
}
16011603

@@ -1637,20 +1639,20 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
16371639
if (rc)
16381640
goto dealloc_res;
16391641

1640-
for (i = 0; i < rdev->num_msix - 1; i++) {
1642+
for (i = 0; i < rdev->nqr->num_msix - 1; i++) {
16411643
struct bnxt_qplib_nq *nq;
16421644

1643-
nq = &rdev->nq[i];
1645+
nq = &rdev->nqr->nq[i];
16441646
nq->hwq.max_elements = BNXT_QPLIB_NQE_MAX_CNT;
1645-
rc = bnxt_qplib_alloc_nq(&rdev->qplib_res, &rdev->nq[i]);
1647+
rc = bnxt_qplib_alloc_nq(&rdev->qplib_res, nq);
16461648
if (rc) {
16471649
ibdev_err(&rdev->ibdev, "Alloc Failed NQ%d rc:%#x",
16481650
i, rc);
16491651
goto free_nq;
16501652
}
16511653
type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
16521654
rattr.dma_arr = nq->hwq.pbl[PBL_LVL_0].pg_map_arr;
1653-
rattr.pages = nq->hwq.pbl[rdev->nq[i].hwq.level].pg_count;
1655+
rattr.pages = nq->hwq.pbl[rdev->nqr->nq[i].hwq.level].pg_count;
16541656
rattr.type = type;
16551657
rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
16561658
rattr.depth = BNXT_QPLIB_NQE_MAX_CNT - 1;
@@ -1660,7 +1662,7 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
16601662
ibdev_err(&rdev->ibdev,
16611663
"Failed to allocate NQ fw id with rc = 0x%x",
16621664
rc);
1663-
bnxt_qplib_free_nq(&rdev->nq[i]);
1665+
bnxt_qplib_free_nq(nq);
16641666
goto free_nq;
16651667
}
16661668
num_vec_created++;
@@ -1669,8 +1671,8 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev)
16691671
free_nq:
16701672
for (i = num_vec_created - 1; i >= 0; i--) {
16711673
type = bnxt_qplib_get_ring_type(rdev->chip_ctx);
1672-
bnxt_re_net_ring_free(rdev, rdev->nq[i].ring_id, type);
1673-
bnxt_qplib_free_nq(&rdev->nq[i]);
1674+
bnxt_re_net_ring_free(rdev, rdev->nqr->nq[i].ring_id, type);
1675+
bnxt_qplib_free_nq(&rdev->nqr->nq[i]);
16741676
}
16751677
bnxt_qplib_dealloc_dpi(&rdev->qplib_res,
16761678
&rdev->dpi_privileged);
@@ -1865,6 +1867,21 @@ static int bnxt_re_ib_init(struct bnxt_re_dev *rdev)
18651867
return rc;
18661868
}
18671869

1870+
static int bnxt_re_alloc_nqr_mem(struct bnxt_re_dev *rdev)
1871+
{
1872+
rdev->nqr = kzalloc(sizeof(*rdev->nqr), GFP_KERNEL);
1873+
if (!rdev->nqr)
1874+
return -ENOMEM;
1875+
1876+
return 0;
1877+
}
1878+
1879+
static void bnxt_re_free_nqr_mem(struct bnxt_re_dev *rdev)
1880+
{
1881+
kfree(rdev->nqr);
1882+
rdev->nqr = NULL;
1883+
}
1884+
18681885
static void bnxt_re_dev_uninit(struct bnxt_re_dev *rdev, u8 op_type)
18691886
{
18701887
u8 type;
@@ -1894,11 +1911,12 @@ static void bnxt_re_dev_uninit(struct bnxt_re_dev *rdev, u8 op_type)
18941911
bnxt_qplib_free_rcfw_channel(&rdev->rcfw);
18951912
}
18961913

1897-
rdev->num_msix = 0;
1914+
rdev->nqr->num_msix = 0;
18981915

18991916
if (rdev->pacing.dbr_pacing)
19001917
bnxt_re_deinitialize_dbr_pacing(rdev);
19011918

1919+
bnxt_re_free_nqr_mem(rdev);
19021920
bnxt_re_destroy_chip_ctx(rdev);
19031921
if (op_type == BNXT_RE_COMPLETE_REMOVE) {
19041922
if (test_and_clear_bit(BNXT_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
@@ -1946,7 +1964,6 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)
19461964
}
19471965
ibdev_dbg(&rdev->ibdev, "Got %d MSI-X vectors\n",
19481966
rdev->en_dev->ulp_tbl->msix_requested);
1949-
rdev->num_msix = rdev->en_dev->ulp_tbl->msix_requested;
19501967

19511968
rc = bnxt_re_setup_chip_ctx(rdev);
19521969
if (rc) {
@@ -1956,6 +1973,15 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)
19561973
return -EINVAL;
19571974
}
19581975

1976+
rc = bnxt_re_alloc_nqr_mem(rdev);
1977+
if (rc) {
1978+
bnxt_re_destroy_chip_ctx(rdev);
1979+
bnxt_unregister_dev(rdev->en_dev);
1980+
clear_bit(BNXT_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
1981+
return rc;
1982+
}
1983+
rdev->nqr->num_msix = rdev->en_dev->ulp_tbl->msix_requested;
1984+
19591985
/* Check whether VF or PF */
19601986
bnxt_re_get_sriov_func_type(rdev);
19611987

0 commit comments

Comments
 (0)