Skip to content

Commit 66d0675

Browse files
Petri Gyntherdavem330
authored andcommitted
net: bcmgenet: simplify __bcmgenet_tx_reclaim()
1. Use c_index and ring->c_index to determine how many TxCBs/TxBDs are ready for cleanup - c_index = the current value of TDMA_CONS_INDEX - TDMA_CONS_INDEX is HW-incremented and auto-wraparound (0x0-0xFFFF) - ring->c_index = __bcmgenet_tx_reclaim() cleaned up to this point on the previous invocation 2. Add bcmgenet_tx_ring->clean_ptr - index of the next TxCB to be cleaned - incremented as TxCBs/TxBDs are processed - value always in range [ring->cb_ptr, ring->end_ptr] 3. Fix incrementing of dev->stats.tx_packets - should be incremented only when tx_cb_ptr->skb != NULL These changes simplify __bcmgenet_tx_reclaim(). Furthermore, Tx ring size can now be any value. With the old code, Tx ring size had to be a power-of-2: num_tx_bds = ring->size; c_index &= (num_tx_bds - 1); last_c_index &= (num_tx_bds - 1); Signed-off-by: Petri Gynther <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f93eb4b commit 66d0675

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -978,39 +978,32 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
978978
struct bcmgenet_tx_ring *ring)
979979
{
980980
struct bcmgenet_priv *priv = netdev_priv(dev);
981-
int last_tx_cn, last_c_index, num_tx_bds;
982981
struct enet_cb *tx_cb_ptr;
983982
struct netdev_queue *txq;
984983
unsigned int pkts_compl = 0;
985-
unsigned int bds_compl;
986984
unsigned int c_index;
985+
unsigned int txbds_ready;
986+
unsigned int txbds_processed = 0;
987987

988988
/* Compute how many buffers are transmitted since last xmit call */
989989
c_index = bcmgenet_tdma_ring_readl(priv, ring->index, TDMA_CONS_INDEX);
990-
txq = netdev_get_tx_queue(dev, ring->queue);
991-
992-
last_c_index = ring->c_index;
993-
num_tx_bds = ring->size;
994-
995-
c_index &= (num_tx_bds - 1);
990+
c_index &= DMA_C_INDEX_MASK;
996991

997-
if (c_index >= last_c_index)
998-
last_tx_cn = c_index - last_c_index;
992+
if (likely(c_index >= ring->c_index))
993+
txbds_ready = c_index - ring->c_index;
999994
else
1000-
last_tx_cn = num_tx_bds - last_c_index + c_index;
995+
txbds_ready = (DMA_C_INDEX_MASK + 1) - ring->c_index + c_index;
1001996

1002997
netif_dbg(priv, tx_done, dev,
1003-
"%s ring=%d index=%d last_tx_cn=%d last_index=%d\n",
1004-
__func__, ring->index,
1005-
c_index, last_tx_cn, last_c_index);
998+
"%s ring=%d old_c_index=%u c_index=%u txbds_ready=%u\n",
999+
__func__, ring->index, ring->c_index, c_index, txbds_ready);
10061000

10071001
/* Reclaim transmitted buffers */
1008-
while (last_tx_cn-- > 0) {
1009-
tx_cb_ptr = ring->cbs + last_c_index;
1010-
bds_compl = 0;
1002+
while (txbds_processed < txbds_ready) {
1003+
tx_cb_ptr = &priv->tx_cbs[ring->clean_ptr];
10111004
if (tx_cb_ptr->skb) {
10121005
pkts_compl++;
1013-
bds_compl = skb_shinfo(tx_cb_ptr->skb)->nr_frags + 1;
1006+
dev->stats.tx_packets++;
10141007
dev->stats.tx_bytes += tx_cb_ptr->skb->len;
10151008
dma_unmap_single(&dev->dev,
10161009
dma_unmap_addr(tx_cb_ptr, dma_addr),
@@ -1026,20 +1019,23 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
10261019
DMA_TO_DEVICE);
10271020
dma_unmap_addr_set(tx_cb_ptr, dma_addr, 0);
10281021
}
1029-
dev->stats.tx_packets++;
1030-
ring->free_bds += bds_compl;
10311022

1032-
last_c_index++;
1033-
last_c_index &= (num_tx_bds - 1);
1023+
txbds_processed++;
1024+
if (likely(ring->clean_ptr < ring->end_ptr))
1025+
ring->clean_ptr++;
1026+
else
1027+
ring->clean_ptr = ring->cb_ptr;
10341028
}
10351029

1030+
ring->free_bds += txbds_processed;
1031+
ring->c_index = (ring->c_index + txbds_processed) & DMA_C_INDEX_MASK;
1032+
10361033
if (ring->free_bds > (MAX_SKB_FRAGS + 1)) {
1034+
txq = netdev_get_tx_queue(dev, ring->queue);
10371035
if (netif_tx_queue_stopped(txq))
10381036
netif_tx_wake_queue(txq);
10391037
}
10401038

1041-
ring->c_index = c_index;
1042-
10431039
return pkts_compl;
10441040
}
10451041

@@ -1734,6 +1730,7 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
17341730
}
17351731
ring->cbs = priv->tx_cbs + start_ptr;
17361732
ring->size = size;
1733+
ring->clean_ptr = start_ptr;
17371734
ring->c_index = 0;
17381735
ring->free_bds = size;
17391736
ring->write_ptr = start_ptr;

drivers/net/ethernet/broadcom/genet/bcmgenet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ struct bcmgenet_tx_ring {
525525
unsigned int queue; /* queue index */
526526
struct enet_cb *cbs; /* tx ring buffer control block*/
527527
unsigned int size; /* size of each tx ring */
528+
unsigned int clean_ptr; /* Tx ring clean pointer */
528529
unsigned int c_index; /* last consumer index of each ring*/
529530
unsigned int free_bds; /* # of free bds for each ring */
530531
unsigned int write_ptr; /* Tx ring write pointer SW copy */

0 commit comments

Comments
 (0)