Skip to content

Commit 5a6caa2

Browse files
Sean AndersonPaolo Abeni
authored andcommitted
net: xilinx: axienet: Fix packet counting
axienet_free_tx_chain returns the number of DMA descriptors it's handled. However, axienet_tx_poll treats the return as the number of packets. When scatter-gather SKBs are enabled, a single packet may use multiple DMA descriptors, which causes incorrect packet counts. Fix this by explicitly keepting track of the number of packets processed as separate from the DMA descriptors. Budget does not affect the number of Tx completions we can process for NAPI, so we use the ring size as the limit instead of budget. As we no longer return the number of descriptors processed to axienet_tx_poll, we now update tx_bd_ci in axienet_free_tx_chain. Fixes: 8a3b7a2 ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") Signed-off-by: Sean Anderson <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent ba0da2d commit 5a6caa2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/net/ethernet/xilinx/xilinx_axienet_main.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,15 @@ static int axienet_device_reset(struct net_device *ndev)
736736
*
737737
* Would either be called after a successful transmit operation, or after
738738
* there was an error when setting up the chain.
739-
* Returns the number of descriptors handled.
739+
* Returns the number of packets handled.
740740
*/
741741
static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
742742
int nr_bds, bool force, u32 *sizep, int budget)
743743
{
744744
struct axidma_bd *cur_p;
745745
unsigned int status;
746+
int i, packets = 0;
746747
dma_addr_t phys;
747-
int i;
748748

749749
for (i = 0; i < nr_bds; i++) {
750750
cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num];
@@ -763,8 +763,10 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
763763
(cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK),
764764
DMA_TO_DEVICE);
765765

766-
if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK))
766+
if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) {
767767
napi_consume_skb(cur_p->skb, budget);
768+
packets++;
769+
}
768770

769771
cur_p->app0 = 0;
770772
cur_p->app1 = 0;
@@ -780,7 +782,13 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
780782
*sizep += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
781783
}
782784

783-
return i;
785+
if (!force) {
786+
lp->tx_bd_ci += i;
787+
if (lp->tx_bd_ci >= lp->tx_bd_num)
788+
lp->tx_bd_ci %= lp->tx_bd_num;
789+
}
790+
791+
return packets;
784792
}
785793

786794
/**
@@ -953,13 +961,10 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
953961
u32 size = 0;
954962
int packets;
955963

956-
packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget);
964+
packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, lp->tx_bd_num, false,
965+
&size, budget);
957966

958967
if (packets) {
959-
lp->tx_bd_ci += packets;
960-
if (lp->tx_bd_ci >= lp->tx_bd_num)
961-
lp->tx_bd_ci %= lp->tx_bd_num;
962-
963968
u64_stats_update_begin(&lp->tx_stat_sync);
964969
u64_stats_add(&lp->tx_packets, packets);
965970
u64_stats_add(&lp->tx_bytes, size);

0 commit comments

Comments
 (0)