Skip to content

Commit d1eec61

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Restructure cp_ring_arr in struct bnxt_cp_ring_info
The cp_ring_arr is currently a fixed array of 2 pointers for the TX and RX completion rings. These pointers are allocated during ring initialization. Currntly, we support up to 2 completion rings for each MSIX. In order to support more completion rings, we change this fixed array to a pointer and allocate the required entries during ring initialization. This patch keeps the current scheme of allocating only 2 entries when needed. Later patches will expand and allocate more entries when required. Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7f0a168 commit d1eec61

File tree

3 files changed

+66
-73
lines changed

3 files changed

+66
-73
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,14 +2834,11 @@ static int __bnxt_poll_cqs(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
28342834
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
28352835
int i, work_done = 0;
28362836

2837-
for (i = 0; i < 2; i++) {
2838-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
2837+
for (i = 0; i < cpr->cp_ring_count; i++) {
2838+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[i];
28392839

2840-
if (cpr2) {
2841-
work_done += __bnxt_poll_work(bp, cpr2,
2842-
budget - work_done);
2843-
cpr->has_more_work |= cpr2->has_more_work;
2844-
}
2840+
work_done += __bnxt_poll_work(bp, cpr2, budget - work_done);
2841+
cpr->has_more_work |= cpr2->has_more_work;
28452842
}
28462843
return work_done;
28472844
}
@@ -2852,11 +2849,11 @@ static void __bnxt_poll_cqs_done(struct bnxt *bp, struct bnxt_napi *bnapi,
28522849
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
28532850
int i;
28542851

2855-
for (i = 0; i < 2; i++) {
2856-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
2852+
for (i = 0; i < cpr->cp_ring_count; i++) {
2853+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[i];
28572854
struct bnxt_db_info *db;
28582855

2859-
if (cpr2 && cpr2->had_work_done) {
2856+
if (cpr2->had_work_done) {
28602857
db = &cpr2->cp_db;
28612858
bnxt_writeq(bp, db->db_key64 | dbr_type |
28622859
RING_CMP(cpr2->cp_raw_cons), db->doorbell);
@@ -2915,7 +2912,7 @@ static int bnxt_poll_p5(struct napi_struct *napi, int budget)
29152912
if (budget && work_done >= budget && idx == BNXT_RX_HDL)
29162913
break;
29172914

2918-
cpr2 = cpr->cp_ring_arr[idx];
2915+
cpr2 = &cpr->cp_ring_arr[idx];
29192916
work_done += __bnxt_poll_work(bp, cpr2,
29202917
budget - work_done);
29212918
cpr->has_more_work |= cpr2->has_more_work;
@@ -2930,8 +2927,8 @@ static int bnxt_poll_p5(struct napi_struct *napi, int budget)
29302927
BNXT_DB_NQ_P5(&cpr->cp_db, raw_cons);
29312928
}
29322929
poll_done:
2933-
cpr_rx = cpr->cp_ring_arr[BNXT_RX_HDL];
2934-
if (cpr_rx && (bp->flags & BNXT_FLAG_DIM)) {
2930+
cpr_rx = &cpr->cp_ring_arr[BNXT_RX_HDL];
2931+
if (cpr_rx->bnapi && (bp->flags & BNXT_FLAG_DIM)) {
29352932
struct dim_sample dim_sample = {};
29362933

29372934
dim_update_sample(cpr->event_ctr,
@@ -3541,36 +3538,33 @@ static void bnxt_free_cp_rings(struct bnxt *bp)
35413538

35423539
bnxt_free_ring(bp, &ring->ring_mem);
35433540

3544-
for (j = 0; j < 2; j++) {
3545-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
3541+
if (!cpr->cp_ring_arr)
3542+
continue;
35463543

3547-
if (cpr2) {
3548-
ring = &cpr2->cp_ring_struct;
3549-
bnxt_free_ring(bp, &ring->ring_mem);
3550-
bnxt_free_cp_arrays(cpr2);
3551-
kfree(cpr2);
3552-
cpr->cp_ring_arr[j] = NULL;
3553-
}
3544+
for (j = 0; j < cpr->cp_ring_count; j++) {
3545+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[j];
3546+
3547+
ring = &cpr2->cp_ring_struct;
3548+
bnxt_free_ring(bp, &ring->ring_mem);
3549+
bnxt_free_cp_arrays(cpr2);
35543550
}
3551+
kfree(cpr->cp_ring_arr);
3552+
cpr->cp_ring_arr = NULL;
3553+
cpr->cp_ring_count = 0;
35553554
}
35563555
}
35573556

3558-
static struct bnxt_cp_ring_info *bnxt_alloc_cp_sub_ring(struct bnxt *bp)
3557+
static int bnxt_alloc_cp_sub_ring(struct bnxt *bp,
3558+
struct bnxt_cp_ring_info *cpr)
35593559
{
35603560
struct bnxt_ring_mem_info *rmem;
35613561
struct bnxt_ring_struct *ring;
3562-
struct bnxt_cp_ring_info *cpr;
35633562
int rc;
35643563

3565-
cpr = kzalloc(sizeof(*cpr), GFP_KERNEL);
3566-
if (!cpr)
3567-
return NULL;
3568-
35693564
rc = bnxt_alloc_cp_arrays(cpr, bp->cp_nr_pages);
35703565
if (rc) {
35713566
bnxt_free_cp_arrays(cpr);
3572-
kfree(cpr);
3573-
return NULL;
3567+
return -ENOMEM;
35743568
}
35753569
ring = &cpr->cp_ring_struct;
35763570
rmem = &ring->ring_mem;
@@ -3583,10 +3577,8 @@ static struct bnxt_cp_ring_info *bnxt_alloc_cp_sub_ring(struct bnxt *bp)
35833577
if (rc) {
35843578
bnxt_free_ring(bp, rmem);
35853579
bnxt_free_cp_arrays(cpr);
3586-
kfree(cpr);
3587-
cpr = NULL;
35883580
}
3589-
return cpr;
3581+
return rc;
35903582
}
35913583

35923584
static int bnxt_alloc_cp_rings(struct bnxt *bp)
@@ -3598,7 +3590,7 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp)
35983590
ulp_base_vec = bnxt_get_ulp_msix_base(bp);
35993591
for (i = 0; i < bp->cp_nr_rings; i++) {
36003592
struct bnxt_napi *bnapi = bp->bnapi[i];
3601-
struct bnxt_cp_ring_info *cpr;
3593+
struct bnxt_cp_ring_info *cpr, *cpr2;
36023594
struct bnxt_ring_struct *ring;
36033595

36043596
if (!bnapi)
@@ -3620,23 +3612,27 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp)
36203612
if (!(bp->flags & BNXT_FLAG_CHIP_P5))
36213613
continue;
36223614

3623-
if (i < bp->rx_nr_rings) {
3624-
struct bnxt_cp_ring_info *cpr2 =
3625-
bnxt_alloc_cp_sub_ring(bp);
3615+
cpr->cp_ring_count = 2;
3616+
cpr->cp_ring_arr = kcalloc(cpr->cp_ring_count, sizeof(*cpr),
3617+
GFP_KERNEL);
3618+
if (!cpr->cp_ring_arr) {
3619+
cpr->cp_ring_count = 0;
3620+
return -ENOMEM;
3621+
}
36263622

3627-
cpr->cp_ring_arr[BNXT_RX_HDL] = cpr2;
3628-
if (!cpr2)
3629-
return -ENOMEM;
3623+
if (i < bp->rx_nr_rings) {
3624+
cpr2 = &cpr->cp_ring_arr[BNXT_RX_HDL];
3625+
rc = bnxt_alloc_cp_sub_ring(bp, cpr2);
3626+
if (rc)
3627+
return rc;
36303628
cpr2->bnapi = bnapi;
36313629
}
36323630
if ((sh && i < bp->tx_nr_rings) ||
36333631
(!sh && i >= bp->rx_nr_rings)) {
3634-
struct bnxt_cp_ring_info *cpr2 =
3635-
bnxt_alloc_cp_sub_ring(bp);
3636-
3637-
cpr->cp_ring_arr[BNXT_TX_HDL] = cpr2;
3638-
if (!cpr2)
3639-
return -ENOMEM;
3632+
cpr2 = &cpr->cp_ring_arr[BNXT_TX_HDL];
3633+
rc = bnxt_alloc_cp_sub_ring(bp, cpr2);
3634+
if (rc)
3635+
return rc;
36403636
cpr2->bnapi = bnapi;
36413637
}
36423638
}
@@ -3822,11 +3818,10 @@ static void bnxt_init_cp_rings(struct bnxt *bp)
38223818
ring->fw_ring_id = INVALID_HW_RING_ID;
38233819
cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
38243820
cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
3825-
for (j = 0; j < 2; j++) {
3826-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
3827-
3828-
if (!cpr2)
3829-
continue;
3821+
if (!cpr->cp_ring_arr)
3822+
continue;
3823+
for (j = 0; j < cpr->cp_ring_count; j++) {
3824+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[j];
38303825

38313826
ring = &cpr2->cp_ring_struct;
38323827
ring->fw_ring_id = INVALID_HW_RING_ID;
@@ -5251,7 +5246,7 @@ static u16 bnxt_cp_ring_for_rx(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
52515246
struct bnxt_napi *bnapi = rxr->bnapi;
52525247
struct bnxt_cp_ring_info *cpr;
52535248

5254-
cpr = bnapi->cp_ring.cp_ring_arr[BNXT_RX_HDL];
5249+
cpr = &bnapi->cp_ring.cp_ring_arr[BNXT_RX_HDL];
52555250
return cpr->cp_ring_struct.fw_ring_id;
52565251
} else {
52575252
return bnxt_cp_ring_from_grp(bp, &rxr->rx_ring_struct);
@@ -5264,7 +5259,7 @@ static u16 bnxt_cp_ring_for_tx(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
52645259
struct bnxt_napi *bnapi = txr->bnapi;
52655260
struct bnxt_cp_ring_info *cpr;
52665261

5267-
cpr = bnapi->cp_ring.cp_ring_arr[BNXT_TX_HDL];
5262+
cpr = &bnapi->cp_ring.cp_ring_arr[BNXT_TX_HDL];
52685263
return cpr->cp_ring_struct.fw_ring_id;
52695264
} else {
52705265
return bnxt_cp_ring_from_grp(bp, &txr->tx_ring_struct);
@@ -6032,7 +6027,7 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
60326027
u32 type2 = HWRM_RING_ALLOC_CMPL;
60336028

60346029
cpr = &bnapi->cp_ring;
6035-
cpr2 = cpr->cp_ring_arr[BNXT_TX_HDL];
6030+
cpr2 = &cpr->cp_ring_arr[BNXT_TX_HDL];
60366031
ring = &cpr2->cp_ring_struct;
60376032
ring->handle = BNXT_TX_HDL;
60386033
map_idx = bnapi->index;
@@ -6071,7 +6066,7 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
60716066
u32 type2 = HWRM_RING_ALLOC_CMPL;
60726067
struct bnxt_cp_ring_info *cpr2;
60736068

6074-
cpr2 = cpr->cp_ring_arr[BNXT_RX_HDL];
6069+
cpr2 = &cpr->cp_ring_arr[BNXT_RX_HDL];
60756070
ring = &cpr2->cp_ring_struct;
60766071
ring->handle = BNXT_RX_HDL;
60776072
rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx);
@@ -6218,18 +6213,16 @@ static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
62186213
struct bnxt_ring_struct *ring;
62196214
int j;
62206215

6221-
for (j = 0; j < 2; j++) {
6222-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
6223-
6224-
if (cpr2) {
6225-
ring = &cpr2->cp_ring_struct;
6226-
if (ring->fw_ring_id == INVALID_HW_RING_ID)
6227-
continue;
6228-
hwrm_ring_free_send_msg(bp, ring,
6229-
RING_FREE_REQ_RING_TYPE_L2_CMPL,
6230-
INVALID_HW_RING_ID);
6231-
ring->fw_ring_id = INVALID_HW_RING_ID;
6232-
}
6216+
for (j = 0; j < cpr->cp_ring_count && cpr->cp_ring_arr; j++) {
6217+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[j];
6218+
6219+
ring = &cpr2->cp_ring_struct;
6220+
if (ring->fw_ring_id == INVALID_HW_RING_ID)
6221+
continue;
6222+
hwrm_ring_free_send_msg(bp, ring,
6223+
RING_FREE_REQ_RING_TYPE_L2_CMPL,
6224+
INVALID_HW_RING_ID);
6225+
ring->fw_ring_id = INVALID_HW_RING_ID;
62336226
}
62346227
ring = &cpr->cp_ring_struct;
62356228
if (ring->fw_ring_id != INVALID_HW_RING_ID) {
@@ -12005,12 +11998,11 @@ static void bnxt_chk_missed_irq(struct bnxt *bp)
1200511998
continue;
1200611999

1200712000
cpr = &bnapi->cp_ring;
12008-
for (j = 0; j < 2; j++) {
12009-
struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
12001+
for (j = 0; j < cpr->cp_ring_count; j++) {
12002+
struct bnxt_cp_ring_info *cpr2 = &cpr->cp_ring_arr[j];
1201012003
u32 val[2];
1201112004

12012-
if (!cpr2 || cpr2->has_more_work ||
12013-
!bnxt_has_work(bp, cpr2))
12005+
if (cpr2->has_more_work || !bnxt_has_work(bp, cpr2))
1201412006
continue;
1201512007

1201612008
if (cpr2->cp_raw_cons != cpr2->last_cp_raw_cons) {

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,8 @@ struct bnxt_cp_ring_info {
10191019

10201020
struct bnxt_ring_struct cp_ring_struct;
10211021

1022-
struct bnxt_cp_ring_info *cp_ring_arr[2];
1022+
int cp_ring_count;
1023+
struct bnxt_cp_ring_info *cp_ring_arr;
10231024
#define BNXT_RX_HDL 0
10241025
#define BNXT_TX_HDL 1
10251026
};

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3941,7 +3941,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
39413941

39423942
cpr = &rxr->bnapi->cp_ring;
39433943
if (bp->flags & BNXT_FLAG_CHIP_P5)
3944-
cpr = cpr->cp_ring_arr[BNXT_RX_HDL];
3944+
cpr = &cpr->cp_ring_arr[BNXT_RX_HDL];
39453945
pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
39463946
skb = netdev_alloc_skb(bp->dev, pkt_size);
39473947
if (!skb)

0 commit comments

Comments
 (0)