Skip to content

Commit 89bab83

Browse files
Sean Andersongregkh
authored andcommitted
net: xilinx: axienet: Fix packet counting
[ Upstream commit 5a6caa2 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent bcce139 commit 89bab83

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
@@ -652,15 +652,15 @@ static int axienet_device_reset(struct net_device *ndev)
652652
*
653653
* Would either be called after a successful transmit operation, or after
654654
* there was an error when setting up the chain.
655-
* Returns the number of descriptors handled.
655+
* Returns the number of packets handled.
656656
*/
657657
static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
658658
int nr_bds, bool force, u32 *sizep, int budget)
659659
{
660660
struct axidma_bd *cur_p;
661661
unsigned int status;
662+
int i, packets = 0;
662663
dma_addr_t phys;
663-
int i;
664664

665665
for (i = 0; i < nr_bds; i++) {
666666
cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num];
@@ -679,8 +679,10 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
679679
(cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK),
680680
DMA_TO_DEVICE);
681681

682-
if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK))
682+
if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) {
683683
napi_consume_skb(cur_p->skb, budget);
684+
packets++;
685+
}
684686

685687
cur_p->app0 = 0;
686688
cur_p->app1 = 0;
@@ -696,7 +698,13 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
696698
*sizep += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
697699
}
698700

699-
return i;
701+
if (!force) {
702+
lp->tx_bd_ci += i;
703+
if (lp->tx_bd_ci >= lp->tx_bd_num)
704+
lp->tx_bd_ci %= lp->tx_bd_num;
705+
}
706+
707+
return packets;
700708
}
701709

702710
/**
@@ -747,13 +755,10 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
747755
u32 size = 0;
748756
int packets;
749757

750-
packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget);
758+
packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, lp->tx_bd_num, false,
759+
&size, budget);
751760

752761
if (packets) {
753-
lp->tx_bd_ci += packets;
754-
if (lp->tx_bd_ci >= lp->tx_bd_num)
755-
lp->tx_bd_ci %= lp->tx_bd_num;
756-
757762
u64_stats_update_begin(&lp->tx_stat_sync);
758763
u64_stats_add(&lp->tx_packets, packets);
759764
u64_stats_add(&lp->tx_bytes, size);

0 commit comments

Comments
 (0)