bnxt_en: Reorganize the coalescing parameters.
authorMichael Chan <michael.chan@broadcom.com>
Thu, 26 Oct 2017 15:51:27 +0000 (11:51 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 27 Oct 2017 15:02:45 +0000 (00:02 +0900)
The current IRQ coalescing logic is a little messy.  The ethtool
parameters are mapped to hardware parameters in a way that is difficult
to understand.  The first step is to better organize the parameters
by adding the new structure bnxt_coal.  The structure is used by both
the RX and TX sets of coalescing parameters.

Adjust the default coal_ticks to 14 us and 28 us for RX and TX.

Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

index 285863ba51a32825690c32c2e068bac6cbe68a2b..52fff1605172a63ce328f3f21c7340c1d0232052 100644 (file)
@@ -4569,34 +4569,31 @@ int bnxt_hwrm_set_coal(struct bnxt *bp)
        /* Each rx completion (2 records) should be DMAed immediately.
         * DMA 1/4 of the completion buffers at a time.
         */
-       max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2);
+       max_buf = min_t(u16, bp->rx_coal.coal_bufs / 4, 2);
        /* max_buf must not be zero */
        max_buf = clamp_t(u16, max_buf, 1, 63);
-       max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63);
-       buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks);
+       max_buf_irq = clamp_t(u16, bp->rx_coal.coal_bufs_irq, 1, 63);
+       buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal.coal_ticks);
        /* buf timer set to 1/4 of interrupt timer */
        buf_tmr = max_t(u16, buf_tmr / 4, 1);
-       buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq);
+       buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal.coal_ticks_irq);
        buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
 
        flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
 
-       /* RING_IDLE generates more IRQs for lower latency.  Enable it only
-        * if coal_ticks is less than 25 us.
-        */
-       if (bp->rx_coal_ticks < 25)
+       if (bp->rx_coal.coal_ticks < bp->rx_coal.idle_thresh)
                flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
 
        bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
                                  buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
 
        /* max_buf must not be zero */
-       max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63);
-       max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63);
-       buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks);
+       max_buf = clamp_t(u16, bp->tx_coal.coal_bufs, 1, 63);
+       max_buf_irq = clamp_t(u16, bp->tx_coal.coal_bufs_irq, 1, 63);
+       buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal.coal_ticks);
        /* buf timer set to 1/4 of interrupt timer */
        buf_tmr = max_t(u16, buf_tmr / 4, 1);
-       buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq);
+       buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal.coal_ticks_irq);
        buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
 
        flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
@@ -7146,6 +7143,32 @@ static void bnxt_cleanup_pci(struct bnxt *bp)
        pci_disable_device(bp->pdev);
 }
 
+static void bnxt_init_dflt_coal(struct bnxt *bp)
+{
+       struct bnxt_coal *coal;
+
+       /* Tick values in micro seconds.
+        * 1 coal_buf x bufs_per_record = 1 completion record.
+        */
+       coal = &bp->rx_coal;
+       coal->coal_ticks = 14;
+       coal->coal_bufs = 30;
+       coal->coal_ticks_irq = 1;
+       coal->coal_bufs_irq = 2;
+       coal->idle_thresh = 25;
+       coal->bufs_per_record = 2;
+       coal->budget = 64;              /* NAPI budget */
+
+       coal = &bp->tx_coal;
+       coal->coal_ticks = 28;
+       coal->coal_bufs = 30;
+       coal->coal_ticks_irq = 2;
+       coal->coal_bufs_irq = 2;
+       coal->bufs_per_record = 1;
+
+       bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
+}
+
 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
 {
        int rc;
@@ -7214,18 +7237,7 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
        bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
        bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
 
-       /* tick values in micro seconds */
-       bp->rx_coal_ticks = 12;
-       bp->rx_coal_bufs = 30;
-       bp->rx_coal_ticks_irq = 1;
-       bp->rx_coal_bufs_irq = 2;
-
-       bp->tx_coal_ticks = 25;
-       bp->tx_coal_bufs = 30;
-       bp->tx_coal_ticks_irq = 2;
-       bp->tx_coal_bufs_irq = 2;
-
-       bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
+       bnxt_init_dflt_coal(bp);
 
        setup_timer(&bp->timer, bnxt_timer, (unsigned long)bp);
        bp->current_interval = BNXT_TIMER_INTERVAL;
index 5f1fce4a724db9b5941e7c4f0dde7aa67e8dea1c..2188f1606209dd614e5b6ecd10e6d1abce838d95 100644 (file)
@@ -944,6 +944,17 @@ struct bnxt_test_info {
 #define BNXT_CAG_REG_LEGACY_INT_STATUS 0x4014
 #define BNXT_CAG_REG_BASE              0x300000
 
+struct bnxt_coal {
+       u16                     coal_ticks;
+       u16                     coal_ticks_irq;
+       u16                     coal_bufs;
+       u16                     coal_bufs_irq;
+                       /* RING_IDLE enabled when coal ticks < idle_thresh  */
+       u16                     idle_thresh;
+       u8                      bufs_per_record;
+       u8                      budget;
+};
+
 struct bnxt_tc_info {
        bool                            enabled;
 
@@ -1235,14 +1246,8 @@ struct bnxt {
        u8                      port_count;
        u16                     br_mode;
 
-       u16                     rx_coal_ticks;
-       u16                     rx_coal_ticks_irq;
-       u16                     rx_coal_bufs;
-       u16                     rx_coal_bufs_irq;
-       u16                     tx_coal_ticks;
-       u16                     tx_coal_ticks_irq;
-       u16                     tx_coal_bufs;
-       u16                     tx_coal_bufs_irq;
+       struct bnxt_coal        rx_coal;
+       struct bnxt_coal        tx_coal;
 
 #define BNXT_USEC_TO_COAL_TIMER(x)     ((x) * 25 / 2)
 
index fc32df7f979f71ff9777c86e59314f4754f903cb..5cd1a501c62b03412bf8410024c17f6e44044eb9 100644 (file)
@@ -44,19 +44,24 @@ static int bnxt_get_coalesce(struct net_device *dev,
                             struct ethtool_coalesce *coal)
 {
        struct bnxt *bp = netdev_priv(dev);
+       struct bnxt_coal *hw_coal;
+       u16 mult;
 
        memset(coal, 0, sizeof(*coal));
 
-       coal->rx_coalesce_usecs = bp->rx_coal_ticks;
-       /* 2 completion records per rx packet */
-       coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2;
-       coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq;
-       coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2;
+       hw_coal = &bp->rx_coal;
+       mult = hw_coal->bufs_per_record;
+       coal->rx_coalesce_usecs = hw_coal->coal_ticks;
+       coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult;
+       coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
+       coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
 
-       coal->tx_coalesce_usecs = bp->tx_coal_ticks;
-       coal->tx_max_coalesced_frames = bp->tx_coal_bufs;
-       coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq;
-       coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq;
+       hw_coal = &bp->tx_coal;
+       mult = hw_coal->bufs_per_record;
+       coal->tx_coalesce_usecs = hw_coal->coal_ticks;
+       coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult;
+       coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
+       coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
 
        coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
 
@@ -68,18 +73,23 @@ static int bnxt_set_coalesce(struct net_device *dev,
 {
        struct bnxt *bp = netdev_priv(dev);
        bool update_stats = false;
+       struct bnxt_coal *hw_coal;
        int rc = 0;
-
-       bp->rx_coal_ticks = coal->rx_coalesce_usecs;
-       /* 2 completion records per rx packet */
-       bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2;
-       bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq;
-       bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2;
-
-       bp->tx_coal_ticks = coal->tx_coalesce_usecs;
-       bp->tx_coal_bufs = coal->tx_max_coalesced_frames;
-       bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq;
-       bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq;
+       u16 mult;
+
+       hw_coal = &bp->rx_coal;
+       mult = hw_coal->bufs_per_record;
+       hw_coal->coal_ticks = coal->rx_coalesce_usecs;
+       hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult;
+       hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq;
+       hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult;
+
+       hw_coal = &bp->rx_coal;
+       mult = hw_coal->bufs_per_record;
+       hw_coal->coal_ticks = coal->tx_coalesce_usecs;
+       hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult;
+       hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq;
+       hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult;
 
        if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
                u32 stats_ticks = coal->stats_block_coalesce_usecs;