Skip to content

Commit f850396

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Refactor and simplify coalescing code.
The mapping of the ethtool coalescing parameters to hardware parameters is now done in bnxt_hwrm_set_coal_params(). The same function can handle both RX and TX settings. The code is now more clear. Some adjustments have been made to get better hardware settings. The coal_frames setting is now accurately set in hardware. The max_timer is set to coal_ticks value. Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 18775aa commit f850396

File tree

1 file changed

+35
-46
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+35
-46
lines changed

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

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,68 +4537,57 @@ static int bnxt_hwrm_check_tx_rings(struct bnxt *bp, int tx_rings)
45374537
return 0;
45384538
}
45394539

4540-
static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs,
4541-
u32 buf_tmrs, u16 flags,
4540+
static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
45424541
struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
45434542
{
4543+
u16 val, tmr, max, flags;
4544+
4545+
max = hw_coal->bufs_per_record * 128;
4546+
if (hw_coal->budget)
4547+
max = hw_coal->bufs_per_record * hw_coal->budget;
4548+
4549+
val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
4550+
req->num_cmpl_aggr_int = cpu_to_le16(val);
4551+
req->num_cmpl_dma_aggr = cpu_to_le16(val);
4552+
4553+
val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, max);
4554+
req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
4555+
4556+
tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4557+
tmr = max_t(u16, tmr, 1);
4558+
req->int_lat_tmr_max = cpu_to_le16(tmr);
4559+
4560+
/* min timer set to 1/2 of interrupt timer */
4561+
val = tmr / 2;
4562+
req->int_lat_tmr_min = cpu_to_le16(val);
4563+
4564+
/* buf timer set to 1/4 of interrupt timer */
4565+
val = max_t(u16, tmr / 4, 1);
4566+
req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
4567+
4568+
tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4569+
tmr = max_t(u16, tmr, 1);
4570+
req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
4571+
4572+
flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4573+
if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
4574+
flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
45444575
req->flags = cpu_to_le16(flags);
4545-
req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs);
4546-
req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16);
4547-
req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs);
4548-
req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16);
4549-
/* Minimum time between 2 interrupts set to buf_tmr x 2 */
4550-
req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2);
4551-
req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4);
4552-
req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4);
45534576
}
45544577

45554578
int bnxt_hwrm_set_coal(struct bnxt *bp)
45564579
{
45574580
int i, rc = 0;
45584581
struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
45594582
req_tx = {0}, *req;
4560-
u16 max_buf, max_buf_irq;
4561-
u16 buf_tmr, buf_tmr_irq;
4562-
u32 flags;
45634583

45644584
bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
45654585
HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
45664586
bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
45674587
HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
45684588

4569-
/* Each rx completion (2 records) should be DMAed immediately.
4570-
* DMA 1/4 of the completion buffers at a time.
4571-
*/
4572-
max_buf = min_t(u16, bp->rx_coal.coal_bufs / 4, 2);
4573-
/* max_buf must not be zero */
4574-
max_buf = clamp_t(u16, max_buf, 1, 63);
4575-
max_buf_irq = clamp_t(u16, bp->rx_coal.coal_bufs_irq, 1, 63);
4576-
buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal.coal_ticks);
4577-
/* buf timer set to 1/4 of interrupt timer */
4578-
buf_tmr = max_t(u16, buf_tmr / 4, 1);
4579-
buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal.coal_ticks_irq);
4580-
buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4581-
4582-
flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4583-
4584-
if (bp->rx_coal.coal_ticks < bp->rx_coal.idle_thresh)
4585-
flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
4586-
4587-
bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4588-
buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
4589-
4590-
/* max_buf must not be zero */
4591-
max_buf = clamp_t(u16, bp->tx_coal.coal_bufs, 1, 63);
4592-
max_buf_irq = clamp_t(u16, bp->tx_coal.coal_bufs_irq, 1, 63);
4593-
buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal.coal_ticks);
4594-
/* buf timer set to 1/4 of interrupt timer */
4595-
buf_tmr = max_t(u16, buf_tmr / 4, 1);
4596-
buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal.coal_ticks_irq);
4597-
buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4598-
4599-
flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4600-
bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4601-
buf_tmr_irq << 16 | buf_tmr, flags, &req_tx);
4589+
bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
4590+
bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
46024591

46034592
mutex_lock(&bp->hwrm_cmd_lock);
46044593
for (i = 0; i < bp->cp_nr_rings; i++) {

0 commit comments

Comments
 (0)