Skip to content

Commit b81a90d

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Re-structure ring indexing and mapping.
In order to support dedicated or shared completion rings, the ring indexing and mapping are re-structured as below: 1. bp->grp_info[] array index is 1:1 with bp->bnapi[] array index and completion ring index. 2. rx rings 0 to n will be mapped to completion rings 0 to n. 3. If tx and rx rings share completion rings, then tx rings 0 to m will be mapped to completion rings 0 to m. 4. If tx and rx rings use dedicated completion rings, then tx rings 0 to m will be mapped to completion rings n + 1 to n + m. 5. Each tx or rx ring will use the corresponding completion ring index for doorbell mapping and MSIX mapping. Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3b2b7d9 commit b81a90d

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

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

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
422422
static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
423423
{
424424
struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
425-
int index = bnapi->index;
425+
int index = txr - &bp->tx_ring[0];
426426
struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, index);
427427
u16 cons = txr->tx_cons;
428428
struct pci_dev *pdev = bp->pdev;
@@ -3082,7 +3082,7 @@ static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id)
30823082

30833083
static int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
30843084
{
3085-
int grp_idx = 0;
3085+
unsigned int ring = 0, grp_idx;
30863086
struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
30873087
struct hwrm_vnic_cfg_input req = {0};
30883088

@@ -3093,10 +3093,11 @@ static int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
30933093
req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx);
30943094
req.cos_rule = cpu_to_le16(0xffff);
30953095
if (vnic->flags & BNXT_VNIC_RSS_FLAG)
3096-
grp_idx = 0;
3096+
ring = 0;
30973097
else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
3098-
grp_idx = vnic_id - 1;
3098+
ring = vnic_id - 1;
30993099

3100+
grp_idx = bp->rx_ring[ring].bnapi->index;
31003101
req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
31013102
req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
31023103

@@ -3137,22 +3138,25 @@ static void bnxt_hwrm_vnic_free(struct bnxt *bp)
31373138
bnxt_hwrm_vnic_free_one(bp, i);
31383139
}
31393140

3140-
static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id, u16 start_grp_id,
3141-
u16 end_grp_id)
3141+
static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
3142+
unsigned int start_rx_ring_idx,
3143+
unsigned int nr_rings)
31423144
{
3143-
u32 rc = 0, i, j;
3145+
int rc = 0;
3146+
unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
31443147
struct hwrm_vnic_alloc_input req = {0};
31453148
struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
31463149

31473150
/* map ring groups to this vnic */
3148-
for (i = start_grp_id, j = 0; i < end_grp_id; i++, j++) {
3149-
if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID) {
3151+
for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
3152+
grp_idx = bp->rx_ring[i].bnapi->index;
3153+
if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
31503154
netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
3151-
j, (end_grp_id - start_grp_id));
3155+
j, nr_rings);
31523156
break;
31533157
}
31543158
bp->vnic_info[vnic_id].fw_grp_ids[j] =
3155-
bp->grp_info[i].fw_grp_id;
3159+
bp->grp_info[grp_idx].fw_grp_id;
31563160
}
31573161

31583162
bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx = INVALID_HW_RING_ID;
@@ -3179,20 +3183,22 @@ static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
31793183
struct hwrm_ring_grp_alloc_input req = {0};
31803184
struct hwrm_ring_grp_alloc_output *resp =
31813185
bp->hwrm_cmd_resp_addr;
3186+
unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
31823187

31833188
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
31843189

3185-
req.cr = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
3186-
req.rr = cpu_to_le16(bp->grp_info[i].rx_fw_ring_id);
3187-
req.ar = cpu_to_le16(bp->grp_info[i].agg_fw_ring_id);
3188-
req.sc = cpu_to_le16(bp->grp_info[i].fw_stats_ctx);
3190+
req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
3191+
req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
3192+
req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
3193+
req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
31893194

31903195
rc = _hwrm_send_message(bp, &req, sizeof(req),
31913196
HWRM_CMD_TIMEOUT);
31923197
if (rc)
31933198
break;
31943199

3195-
bp->grp_info[i].fw_grp_id = le32_to_cpu(resp->ring_group_id);
3200+
bp->grp_info[grp_idx].fw_grp_id =
3201+
le32_to_cpu(resp->ring_group_id);
31963202
}
31973203
mutex_unlock(&bp->hwrm_cmd_lock);
31983204
return rc;
@@ -3334,46 +3340,49 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
33343340
for (i = 0; i < bp->tx_nr_rings; i++) {
33353341
struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
33363342
struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
3337-
u16 fw_stats_ctx = bp->grp_info[i].fw_stats_ctx;
3343+
u32 map_idx = txr->bnapi->index;
3344+
u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
33383345

3339-
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, i,
3340-
fw_stats_ctx);
3346+
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
3347+
map_idx, fw_stats_ctx);
33413348
if (rc)
33423349
goto err_out;
3343-
txr->tx_doorbell = bp->bar1 + i * 0x80;
3350+
txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
33443351
}
33453352

33463353
for (i = 0; i < bp->rx_nr_rings; i++) {
33473354
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
33483355
struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
3356+
u32 map_idx = rxr->bnapi->index;
33493357

3350-
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, i,
3351-
INVALID_STATS_CTX_ID);
3358+
rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
3359+
map_idx, INVALID_STATS_CTX_ID);
33523360
if (rc)
33533361
goto err_out;
3354-
rxr->rx_doorbell = bp->bar1 + i * 0x80;
3362+
rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
33553363
writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
3356-
bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id;
3364+
bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
33573365
}
33583366

33593367
if (bp->flags & BNXT_FLAG_AGG_RINGS) {
33603368
for (i = 0; i < bp->rx_nr_rings; i++) {
33613369
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
33623370
struct bnxt_ring_struct *ring =
33633371
&rxr->rx_agg_ring_struct;
3372+
u32 grp_idx = rxr->bnapi->index;
3373+
u32 map_idx = grp_idx + bp->rx_nr_rings;
33643374

33653375
rc = hwrm_ring_alloc_send_msg(bp, ring,
33663376
HWRM_RING_ALLOC_AGG,
3367-
bp->rx_nr_rings + i,
3377+
map_idx,
33683378
INVALID_STATS_CTX_ID);
33693379
if (rc)
33703380
goto err_out;
33713381

3372-
rxr->rx_agg_doorbell =
3373-
bp->bar1 + (bp->rx_nr_rings + i) * 0x80;
3382+
rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
33743383
writel(DB_KEY_RX | rxr->rx_agg_prod,
33753384
rxr->rx_agg_doorbell);
3376-
bp->grp_info[i].agg_fw_ring_id = ring->fw_ring_id;
3385+
bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
33773386
}
33783387
}
33793388
err_out:
@@ -3430,7 +3439,8 @@ static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
34303439
for (i = 0; i < bp->tx_nr_rings; i++) {
34313440
struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
34323441
struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
3433-
u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
3442+
u32 grp_idx = txr->bnapi->index;
3443+
u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
34343444

34353445
if (ring->fw_ring_id != INVALID_HW_RING_ID) {
34363446
hwrm_ring_free_send_msg(bp, ring,
@@ -3444,30 +3454,34 @@ static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
34443454
for (i = 0; i < bp->rx_nr_rings; i++) {
34453455
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
34463456
struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
3447-
u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
3457+
u32 grp_idx = rxr->bnapi->index;
3458+
u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
34483459

34493460
if (ring->fw_ring_id != INVALID_HW_RING_ID) {
34503461
hwrm_ring_free_send_msg(bp, ring,
34513462
RING_FREE_REQ_RING_TYPE_RX,
34523463
close_path ? cmpl_ring_id :
34533464
INVALID_HW_RING_ID);
34543465
ring->fw_ring_id = INVALID_HW_RING_ID;
3455-
bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
3466+
bp->grp_info[grp_idx].rx_fw_ring_id =
3467+
INVALID_HW_RING_ID;
34563468
}
34573469
}
34583470

34593471
for (i = 0; i < bp->rx_nr_rings; i++) {
34603472
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
34613473
struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
3462-
u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
3474+
u32 grp_idx = rxr->bnapi->index;
3475+
u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
34633476

34643477
if (ring->fw_ring_id != INVALID_HW_RING_ID) {
34653478
hwrm_ring_free_send_msg(bp, ring,
34663479
RING_FREE_REQ_RING_TYPE_RX,
34673480
close_path ? cmpl_ring_id :
34683481
INVALID_HW_RING_ID);
34693482
ring->fw_ring_id = INVALID_HW_RING_ID;
3470-
bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
3483+
bp->grp_info[grp_idx].agg_fw_ring_id =
3484+
INVALID_HW_RING_ID;
34713485
}
34723486
}
34733487

@@ -3859,7 +3873,7 @@ static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
38593873
break;
38603874

38613875
bp->vnic_info[vnic_id].flags |= BNXT_VNIC_RFS_FLAG;
3862-
rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, ring_id + 1);
3876+
rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
38633877
if (rc) {
38643878
netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
38653879
vnic_id, rc);
@@ -4165,7 +4179,7 @@ static void bnxt_free_irq(struct bnxt *bp)
41654179

41664180
static int bnxt_request_irq(struct bnxt *bp)
41674181
{
4168-
int i, rc = 0;
4182+
int i, j, rc = 0;
41694183
unsigned long flags = 0;
41704184
#ifdef CONFIG_RFS_ACCEL
41714185
struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap;
@@ -4174,14 +4188,15 @@ static int bnxt_request_irq(struct bnxt *bp)
41744188
if (!(bp->flags & BNXT_FLAG_USING_MSIX))
41754189
flags = IRQF_SHARED;
41764190

4177-
for (i = 0; i < bp->cp_nr_rings; i++) {
4191+
for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
41784192
struct bnxt_irq *irq = &bp->irq_tbl[i];
41794193
#ifdef CONFIG_RFS_ACCEL
4180-
if (rmap && (i < bp->rx_nr_rings)) {
4194+
if (rmap && bp->bnapi[i]->rx_ring) {
41814195
rc = irq_cpu_rmap_add(rmap, irq->vector);
41824196
if (rc)
41834197
netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
4184-
i);
4198+
j);
4199+
j++;
41854200
}
41864201
#endif
41874202
rc = request_irq(irq->vector, irq->handler, flags, irq->name,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ struct bnxt {
918918
int cp_nr_rings;
919919

920920
int num_stat_ctxs;
921+
922+
/* grp_info indexed by completion ring index */
921923
struct bnxt_ring_grp_info *grp_info;
922924
struct bnxt_vnic_info *vnic_info;
923925
int nr_vnics;

0 commit comments

Comments
 (0)