Skip to content

Commit 484d802

Browse files
ffainellidavem330
authored andcommitted
net: systemport: Rewrite __bcm_sysport_tx_reclaim()
There is no need for complex checking between the last consumed index and current consumed index, a simple subtraction will do. This also eliminates the possibility of a permanent transmit queue stall under the following conditions: - one CPU bursts ring->size worth of traffic (up to 256 buffers), to the point where we run out of free descriptors, so we stop the transmit queue at the end of bcm_sysport_xmit() - because of our locking, we have the transmit process disable interrupts which means we can be blocking the TX reclamation process - when TX reclamation finally runs, we will be computing the difference between ring->c_index (last consumed index by SW) and what the HW reports through its register - this register is masked with (ring->size - 1) = 0xff, which will lead to stripping the upper bits of the index (register is 16-bits wide) - we will be computing last_tx_cn as 0, which means there is no work to be done, and we never wake-up the transmit queue, leaving it permanently disabled A practical example is e.g: ring->c_index aka last_c_index = 12, we pushed 256 entries, HW consumer index = 268, we mask it with 0xff = 12, so last_tx_cn == 0, nothing happens. Fixes: 80105be ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC driver") Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2cc683e commit 484d802

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

drivers/net/ethernet/broadcom/bcmsysport.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,12 @@ static void bcm_sysport_tx_reclaim_one(struct bcm_sysport_tx_ring *ring,
855855
static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
856856
struct bcm_sysport_tx_ring *ring)
857857
{
858-
unsigned int c_index, last_c_index, last_tx_cn, num_tx_cbs;
859858
unsigned int pkts_compl = 0, bytes_compl = 0;
860859
struct net_device *ndev = priv->netdev;
860+
unsigned int txbds_processed = 0;
861861
struct bcm_sysport_cb *cb;
862+
unsigned int txbds_ready;
863+
unsigned int c_index;
862864
u32 hw_ind;
863865

864866
/* Clear status before servicing to reduce spurious interrupts */
@@ -871,29 +873,23 @@ static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
871873
/* Compute how many descriptors have been processed since last call */
872874
hw_ind = tdma_readl(priv, TDMA_DESC_RING_PROD_CONS_INDEX(ring->index));
873875
c_index = (hw_ind >> RING_CONS_INDEX_SHIFT) & RING_CONS_INDEX_MASK;
874-
ring->p_index = (hw_ind & RING_PROD_INDEX_MASK);
875-
876-
last_c_index = ring->c_index;
877-
num_tx_cbs = ring->size;
878-
879-
c_index &= (num_tx_cbs - 1);
880-
881-
if (c_index >= last_c_index)
882-
last_tx_cn = c_index - last_c_index;
883-
else
884-
last_tx_cn = num_tx_cbs - last_c_index + c_index;
876+
txbds_ready = (c_index - ring->c_index) & RING_CONS_INDEX_MASK;
885877

886878
netif_dbg(priv, tx_done, ndev,
887-
"ring=%d c_index=%d last_tx_cn=%d last_c_index=%d\n",
888-
ring->index, c_index, last_tx_cn, last_c_index);
879+
"ring=%d old_c_index=%u c_index=%u txbds_ready=%u\n",
880+
ring->index, ring->c_index, c_index, txbds_ready);
889881

890-
while (last_tx_cn-- > 0) {
891-
cb = ring->cbs + last_c_index;
882+
while (txbds_processed < txbds_ready) {
883+
cb = &ring->cbs[ring->clean_index];
892884
bcm_sysport_tx_reclaim_one(ring, cb, &bytes_compl, &pkts_compl);
893885

894886
ring->desc_count++;
895-
last_c_index++;
896-
last_c_index &= (num_tx_cbs - 1);
887+
txbds_processed++;
888+
889+
if (likely(ring->clean_index < ring->size - 1))
890+
ring->clean_index++;
891+
else
892+
ring->clean_index = 0;
897893
}
898894

899895
u64_stats_update_begin(&priv->syncp);
@@ -1394,6 +1390,7 @@ static int bcm_sysport_init_tx_ring(struct bcm_sysport_priv *priv,
13941390
netif_tx_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64);
13951391
ring->index = index;
13961392
ring->size = size;
1393+
ring->clean_index = 0;
13971394
ring->alloc_size = ring->size;
13981395
ring->desc_cpu = p;
13991396
ring->desc_count = ring->size;

drivers/net/ethernet/broadcom/bcmsysport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ struct bcm_sysport_tx_ring {
706706
unsigned int desc_count; /* Number of descriptors */
707707
unsigned int curr_desc; /* Current descriptor */
708708
unsigned int c_index; /* Last consumer index */
709-
unsigned int p_index; /* Current producer index */
709+
unsigned int clean_index; /* Current clean index */
710710
struct bcm_sysport_cb *cbs; /* Transmit control blocks */
711711
struct dma_desc *desc_cpu; /* CPU view of the descriptor */
712712
struct bcm_sysport_priv *priv; /* private context backpointer */

0 commit comments

Comments
 (0)