Commit 9d5e6a70 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'bnxt-tx-napi-disabling-resiliency-improvements'

Jakub Kicinski says:

====================
bnxt: Tx NAPI disabling resiliency improvements

A lockdep warning was triggered by netpoll because napi poll
was taking the xmit lock. Fix that and a couple more issues
noticed while reading the code.
====================

Link: https://lore.kernel.org/r/20210812214242.578039-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents f8e6dfc6 fb9f7190
...@@ -72,7 +72,8 @@ ...@@ -72,7 +72,8 @@
#include "bnxt_debugfs.h" #include "bnxt_debugfs.h"
#define BNXT_TX_TIMEOUT (5 * HZ) #define BNXT_TX_TIMEOUT (5 * HZ)
#define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW) #define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \
NETIF_MSG_TX_ERR)
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Broadcom BCM573xx network driver"); MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
...@@ -365,6 +366,33 @@ static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb) ...@@ -365,6 +366,33 @@ static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
return md_dst->u.port_info.port_id; return md_dst->u.port_info.port_id;
} }
static void bnxt_txr_db_kick(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
u16 prod)
{
bnxt_db_write(bp, &txr->tx_db, prod);
txr->kick_pending = 0;
}
static bool bnxt_txr_netif_try_stop_queue(struct bnxt *bp,
struct bnxt_tx_ring_info *txr,
struct netdev_queue *txq)
{
netif_tx_stop_queue(txq);
/* netif_tx_stop_queue() must be done before checking
* tx index in bnxt_tx_avail() below, because in
* bnxt_tx_int(), we update tx index before checking for
* netif_tx_queue_stopped().
*/
smp_mb();
if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh) {
netif_tx_wake_queue(txq);
return false;
}
return true;
}
static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct bnxt *bp = netdev_priv(dev); struct bnxt *bp = netdev_priv(dev);
...@@ -384,6 +412,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -384,6 +412,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
i = skb_get_queue_mapping(skb); i = skb_get_queue_mapping(skb);
if (unlikely(i >= bp->tx_nr_rings)) { if (unlikely(i >= bp->tx_nr_rings)) {
dev_kfree_skb_any(skb); dev_kfree_skb_any(skb);
atomic_long_inc(&dev->tx_dropped);
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
...@@ -393,8 +422,12 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -393,8 +422,12 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
free_size = bnxt_tx_avail(bp, txr); free_size = bnxt_tx_avail(bp, txr);
if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) { if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
netif_tx_stop_queue(txq); /* We must have raced with NAPI cleanup */
return NETDEV_TX_BUSY; if (net_ratelimit() && txr->kick_pending)
netif_warn(bp, tx_err, dev,
"bnxt: ring busy w/ flush pending!\n");
if (bnxt_txr_netif_try_stop_queue(bp, txr, txq))
return NETDEV_TX_BUSY;
} }
length = skb->len; length = skb->len;
...@@ -517,21 +550,16 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -517,21 +550,16 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
normal_tx: normal_tx:
if (length < BNXT_MIN_PKT_SIZE) { if (length < BNXT_MIN_PKT_SIZE) {
pad = BNXT_MIN_PKT_SIZE - length; pad = BNXT_MIN_PKT_SIZE - length;
if (skb_pad(skb, pad)) { if (skb_pad(skb, pad))
/* SKB already freed. */ /* SKB already freed. */
tx_buf->skb = NULL; goto tx_kick_pending;
return NETDEV_TX_OK;
}
length = BNXT_MIN_PKT_SIZE; length = BNXT_MIN_PKT_SIZE;
} }
mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE); mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(&pdev->dev, mapping))) { if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
dev_kfree_skb_any(skb); goto tx_free;
tx_buf->skb = NULL;
return NETDEV_TX_OK;
}
dma_unmap_addr_set(tx_buf, mapping, mapping); dma_unmap_addr_set(tx_buf, mapping, mapping);
flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD | flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
...@@ -618,24 +646,17 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -618,24 +646,17 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
txr->tx_prod = prod; txr->tx_prod = prod;
if (!netdev_xmit_more() || netif_xmit_stopped(txq)) if (!netdev_xmit_more() || netif_xmit_stopped(txq))
bnxt_db_write(bp, &txr->tx_db, prod); bnxt_txr_db_kick(bp, txr, prod);
else
txr->kick_pending = 1;
tx_done: tx_done:
if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) { if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
if (netdev_xmit_more() && !tx_buf->is_push) if (netdev_xmit_more() && !tx_buf->is_push)
bnxt_db_write(bp, &txr->tx_db, prod); bnxt_txr_db_kick(bp, txr, prod);
netif_tx_stop_queue(txq);
/* netif_tx_stop_queue() must be done before checking bnxt_txr_netif_try_stop_queue(bp, txr, txq);
* tx index in bnxt_tx_avail() below, because in
* bnxt_tx_int(), we update tx index before checking for
* netif_tx_queue_stopped().
*/
smp_mb();
if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
netif_tx_wake_queue(txq);
} }
return NETDEV_TX_OK; return NETDEV_TX_OK;
...@@ -648,7 +669,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -648,7 +669,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
/* start back at beginning and unmap skb */ /* start back at beginning and unmap skb */
prod = txr->tx_prod; prod = txr->tx_prod;
tx_buf = &txr->tx_buf_ring[prod]; tx_buf = &txr->tx_buf_ring[prod];
tx_buf->skb = NULL;
dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
skb_headlen(skb), PCI_DMA_TODEVICE); skb_headlen(skb), PCI_DMA_TODEVICE);
prod = NEXT_TX(prod); prod = NEXT_TX(prod);
...@@ -662,7 +682,13 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -662,7 +682,13 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
PCI_DMA_TODEVICE); PCI_DMA_TODEVICE);
} }
tx_free:
dev_kfree_skb_any(skb); dev_kfree_skb_any(skb);
tx_kick_pending:
if (txr->kick_pending)
bnxt_txr_db_kick(bp, txr, txr->tx_prod);
txr->tx_buf_ring[txr->tx_prod].skb = NULL;
atomic_long_inc(&dev->tx_dropped);
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
...@@ -732,14 +758,9 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) ...@@ -732,14 +758,9 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
smp_mb(); smp_mb();
if (unlikely(netif_tx_queue_stopped(txq)) && if (unlikely(netif_tx_queue_stopped(txq)) &&
(bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) { bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
__netif_tx_lock(txq, smp_processor_id()); READ_ONCE(txr->dev_state) != BNXT_DEV_STATE_CLOSING)
if (netif_tx_queue_stopped(txq) && netif_tx_wake_queue(txq);
bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
txr->dev_state != BNXT_DEV_STATE_CLOSING)
netif_tx_wake_queue(txq);
__netif_tx_unlock(txq);
}
} }
static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping, static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
...@@ -9128,10 +9149,9 @@ static void bnxt_disable_napi(struct bnxt *bp) ...@@ -9128,10 +9149,9 @@ static void bnxt_disable_napi(struct bnxt *bp)
for (i = 0; i < bp->cp_nr_rings; i++) { for (i = 0; i < bp->cp_nr_rings; i++) {
struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
napi_disable(&bp->bnapi[i]->napi);
if (bp->bnapi[i]->rx_ring) if (bp->bnapi[i]->rx_ring)
cancel_work_sync(&cpr->dim.work); cancel_work_sync(&cpr->dim.work);
napi_disable(&bp->bnapi[i]->napi);
} }
} }
...@@ -9165,9 +9185,11 @@ void bnxt_tx_disable(struct bnxt *bp) ...@@ -9165,9 +9185,11 @@ void bnxt_tx_disable(struct bnxt *bp)
if (bp->tx_ring) { if (bp->tx_ring) {
for (i = 0; i < bp->tx_nr_rings; i++) { for (i = 0; i < bp->tx_nr_rings; i++) {
txr = &bp->tx_ring[i]; txr = &bp->tx_ring[i];
txr->dev_state = BNXT_DEV_STATE_CLOSING; WRITE_ONCE(txr->dev_state, BNXT_DEV_STATE_CLOSING);
} }
} }
/* Make sure napi polls see @dev_state change */
synchronize_net();
/* Drop carrier first to prevent TX timeout */ /* Drop carrier first to prevent TX timeout */
netif_carrier_off(bp->dev); netif_carrier_off(bp->dev);
/* Stop all TX queues */ /* Stop all TX queues */
...@@ -9181,8 +9203,10 @@ void bnxt_tx_enable(struct bnxt *bp) ...@@ -9181,8 +9203,10 @@ void bnxt_tx_enable(struct bnxt *bp)
for (i = 0; i < bp->tx_nr_rings; i++) { for (i = 0; i < bp->tx_nr_rings; i++) {
txr = &bp->tx_ring[i]; txr = &bp->tx_ring[i];
txr->dev_state = 0; WRITE_ONCE(txr->dev_state, 0);
} }
/* Make sure napi polls see @dev_state change */
synchronize_net();
netif_tx_wake_all_queues(bp->dev); netif_tx_wake_all_queues(bp->dev);
if (bp->link_info.link_up) if (bp->link_info.link_up)
netif_carrier_on(bp->dev); netif_carrier_on(bp->dev);
......
...@@ -786,6 +786,7 @@ struct bnxt_tx_ring_info { ...@@ -786,6 +786,7 @@ struct bnxt_tx_ring_info {
u16 tx_prod; u16 tx_prod;
u16 tx_cons; u16 tx_cons;
u16 txq_index; u16 txq_index;
u8 kick_pending;
struct bnxt_db_info tx_db; struct bnxt_db_info tx_db;
struct tx_bd *tx_desc_ring[MAX_TX_PAGES]; struct tx_bd *tx_desc_ring[MAX_TX_PAGES];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment