Skip to content

Commit 9899bb5

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Improve ring allocation logic.
Currently, the driver code makes some assumptions about the group index and the map index of rings. This makes the code more difficult to understand and less flexible. Improve it by adding the grp_idx and map_idx fields explicitly to the bnxt_ring_struct as a union. The grp_idx is initialized for each tx ring and rx agg ring during init. time. We do the same for the map_idx for each cmpl ring. The grp_idx ties the tx ring to the ring group. The map_idx is the doorbell index of the ring. With this new infrastructure, we can change the ring index mapping scheme easily in the future. Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 845adfe commit 9899bb5

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,7 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)
23172317
if (rc)
23182318
return rc;
23192319

2320+
ring->grp_idx = i;
23202321
rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
23212322
mem_size = rxr->rx_agg_bmap_size / 8;
23222323
rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
@@ -2389,6 +2390,7 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)
23892390
if (rc)
23902391
return rc;
23912392

2393+
ring->grp_idx = txr->bnapi->index;
23922394
if (bp->tx_push_size) {
23932395
dma_addr_t mapping;
23942396

@@ -2458,6 +2460,7 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp)
24582460
rc = bnxt_alloc_ring(bp, ring);
24592461
if (rc)
24602462
return rc;
2463+
ring->map_idx = i;
24612464
}
24622465
return 0;
24632466
}
@@ -4253,12 +4256,12 @@ static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
42534256

42544257
static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
42554258
struct bnxt_ring_struct *ring,
4256-
u32 ring_type, u32 map_index,
4257-
u32 stats_ctx_id)
4259+
u32 ring_type, u32 map_index)
42584260
{
42594261
int rc = 0, err = 0;
42604262
struct hwrm_ring_alloc_input req = {0};
42614263
struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4264+
struct bnxt_ring_grp_info *grp_info;
42624265
u16 ring_id;
42634266

42644267
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
@@ -4280,10 +4283,10 @@ static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
42804283
case HWRM_RING_ALLOC_TX:
42814284
req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
42824285
/* Association of transmit ring with completion ring */
4283-
req.cmpl_ring_id =
4284-
cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id);
4286+
grp_info = &bp->grp_info[ring->grp_idx];
4287+
req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
42854288
req.length = cpu_to_le32(bp->tx_ring_mask + 1);
4286-
req.stat_ctx_id = cpu_to_le32(stats_ctx_id);
4289+
req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
42874290
req.queue_id = cpu_to_le16(ring->queue_id);
42884291
break;
42894292
case HWRM_RING_ALLOC_RX:
@@ -4370,10 +4373,11 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
43704373
struct bnxt_napi *bnapi = bp->bnapi[i];
43714374
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
43724375
struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4376+
u32 map_idx = ring->map_idx;
43734377

4374-
cpr->cp_doorbell = bp->bar1 + i * 0x80;
4375-
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
4376-
INVALID_STATS_CTX_ID);
4378+
cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4379+
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4380+
map_idx);
43774381
if (rc)
43784382
goto err_out;
43794383
BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
@@ -4389,11 +4393,10 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
43894393
for (i = 0; i < bp->tx_nr_rings; i++) {
43904394
struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
43914395
struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4392-
u32 map_idx = txr->bnapi->index;
4393-
u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
4396+
u32 map_idx = i;
43944397

43954398
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4396-
map_idx, fw_stats_ctx);
4399+
map_idx);
43974400
if (rc)
43984401
goto err_out;
43994402
txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
@@ -4405,7 +4408,7 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
44054408
u32 map_idx = rxr->bnapi->index;
44064409

44074410
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4408-
map_idx, INVALID_STATS_CTX_ID);
4411+
map_idx);
44094412
if (rc)
44104413
goto err_out;
44114414
rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
@@ -4418,13 +4421,12 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
44184421
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
44194422
struct bnxt_ring_struct *ring =
44204423
&rxr->rx_agg_ring_struct;
4421-
u32 grp_idx = rxr->bnapi->index;
4424+
u32 grp_idx = ring->grp_idx;
44224425
u32 map_idx = grp_idx + bp->rx_nr_rings;
44234426

44244427
rc = hwrm_ring_alloc_send_msg(bp, ring,
44254428
HWRM_RING_ALLOC_AGG,
4426-
map_idx,
4427-
INVALID_STATS_CTX_ID);
4429+
map_idx);
44284430
if (rc)
44294431
goto err_out;
44304432

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ struct bnxt_ring_struct {
573573
void **vmem;
574574

575575
u16 fw_ring_id; /* Ring id filled by Chimp FW */
576+
union {
577+
u16 grp_idx;
578+
u16 map_idx; /* Used by cmpl rings */
579+
};
576580
u8 queue_id;
577581
};
578582

0 commit comments

Comments
 (0)