aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Chan <michael.chan@broadcom.com>2018-03-31 13:54:16 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-31 23:24:20 -0400
commit9899bb59ff08a50aef033b4d388d223adca58a7f (patch)
treedd1a786936532c9cfa82835f08053645a90e412a
parent845adfe40c2a75e67ddae6639fc2b987338b7983 (diff)
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>
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c32
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.h4
2 files changed, 21 insertions, 15 deletions
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 6fcf4dc67d5e..8c8ef6b6ca91 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2317,6 +2317,7 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)
2317 if (rc) 2317 if (rc)
2318 return rc; 2318 return rc;
2319 2319
2320 ring->grp_idx = i;
2320 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; 2321 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2321 mem_size = rxr->rx_agg_bmap_size / 8; 2322 mem_size = rxr->rx_agg_bmap_size / 8;
2322 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); 2323 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
@@ -2389,6 +2390,7 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)
2389 if (rc) 2390 if (rc)
2390 return rc; 2391 return rc;
2391 2392
2393 ring->grp_idx = txr->bnapi->index;
2392 if (bp->tx_push_size) { 2394 if (bp->tx_push_size) {
2393 dma_addr_t mapping; 2395 dma_addr_t mapping;
2394 2396
@@ -2458,6 +2460,7 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp)
2458 rc = bnxt_alloc_ring(bp, ring); 2460 rc = bnxt_alloc_ring(bp, ring);
2459 if (rc) 2461 if (rc)
2460 return rc; 2462 return rc;
2463 ring->map_idx = i;
2461 } 2464 }
2462 return 0; 2465 return 0;
2463} 2466}
@@ -4253,12 +4256,12 @@ static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4253 4256
4254static int hwrm_ring_alloc_send_msg(struct bnxt *bp, 4257static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4255 struct bnxt_ring_struct *ring, 4258 struct bnxt_ring_struct *ring,
4256 u32 ring_type, u32 map_index, 4259 u32 ring_type, u32 map_index)
4257 u32 stats_ctx_id)
4258{ 4260{
4259 int rc = 0, err = 0; 4261 int rc = 0, err = 0;
4260 struct hwrm_ring_alloc_input req = {0}; 4262 struct hwrm_ring_alloc_input req = {0};
4261 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr; 4263 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4264 struct bnxt_ring_grp_info *grp_info;
4262 u16 ring_id; 4265 u16 ring_id;
4263 4266
4264 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1); 4267 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,
4280 case HWRM_RING_ALLOC_TX: 4283 case HWRM_RING_ALLOC_TX:
4281 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX; 4284 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4282 /* Association of transmit ring with completion ring */ 4285 /* Association of transmit ring with completion ring */
4283 req.cmpl_ring_id = 4286 grp_info = &bp->grp_info[ring->grp_idx];
4284 cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id); 4287 req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
4285 req.length = cpu_to_le32(bp->tx_ring_mask + 1); 4288 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);
4287 req.queue_id = cpu_to_le16(ring->queue_id); 4290 req.queue_id = cpu_to_le16(ring->queue_id);
4288 break; 4291 break;
4289 case HWRM_RING_ALLOC_RX: 4292 case HWRM_RING_ALLOC_RX:
@@ -4370,10 +4373,11 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4370 struct bnxt_napi *bnapi = bp->bnapi[i]; 4373 struct bnxt_napi *bnapi = bp->bnapi[i];
4371 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 4374 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4372 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; 4375 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
4376 u32 map_idx = ring->map_idx;
4373 4377
4374 cpr->cp_doorbell = bp->bar1 + i * 0x80; 4378 cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4375 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i, 4379 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4376 INVALID_STATS_CTX_ID); 4380 map_idx);
4377 if (rc) 4381 if (rc)
4378 goto err_out; 4382 goto err_out;
4379 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); 4383 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
@@ -4389,11 +4393,10 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4389 for (i = 0; i < bp->tx_nr_rings; i++) { 4393 for (i = 0; i < bp->tx_nr_rings; i++) {
4390 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; 4394 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
4391 struct bnxt_ring_struct *ring = &txr->tx_ring_struct; 4395 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
4392 u32 map_idx = txr->bnapi->index; 4396 u32 map_idx = i;
4393 u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
4394 4397
4395 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, 4398 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4396 map_idx, fw_stats_ctx); 4399 map_idx);
4397 if (rc) 4400 if (rc)
4398 goto err_out; 4401 goto err_out;
4399 txr->tx_doorbell = bp->bar1 + map_idx * 0x80; 4402 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
@@ -4405,7 +4408,7 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4405 u32 map_idx = rxr->bnapi->index; 4408 u32 map_idx = rxr->bnapi->index;
4406 4409
4407 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, 4410 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4408 map_idx, INVALID_STATS_CTX_ID); 4411 map_idx);
4409 if (rc) 4412 if (rc)
4410 goto err_out; 4413 goto err_out;
4411 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80; 4414 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
@@ -4418,13 +4421,12 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4418 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; 4421 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
4419 struct bnxt_ring_struct *ring = 4422 struct bnxt_ring_struct *ring =
4420 &rxr->rx_agg_ring_struct; 4423 &rxr->rx_agg_ring_struct;
4421 u32 grp_idx = rxr->bnapi->index; 4424 u32 grp_idx = ring->grp_idx;
4422 u32 map_idx = grp_idx + bp->rx_nr_rings; 4425 u32 map_idx = grp_idx + bp->rx_nr_rings;
4423 4426
4424 rc = hwrm_ring_alloc_send_msg(bp, ring, 4427 rc = hwrm_ring_alloc_send_msg(bp, ring,
4425 HWRM_RING_ALLOC_AGG, 4428 HWRM_RING_ALLOC_AGG,
4426 map_idx, 4429 map_idx);
4427 INVALID_STATS_CTX_ID);
4428 if (rc) 4430 if (rc)
4429 goto err_out; 4431 goto err_out;
4430 4432
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 22aa290c94a0..e0cd0cb529c0 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -573,6 +573,10 @@ struct bnxt_ring_struct {
573 void **vmem; 573 void **vmem;
574 574
575 u16 fw_ring_id; /* Ring id filled by Chimp FW */ 575 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 };
576 u8 queue_id; 580 u8 queue_id;
577}; 581};
578 582