Commit 5a6caa2c authored by Sean Anderson's avatar Sean Anderson Committed by Paolo Abeni

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: 8a3b7a25 ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")
Signed-off-by: default avatarSean Anderson <sean.anderson@linux.dev>
Link: https://patch.msgid.link/20240913145156.2283067-1-sean.anderson@linux.devSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent ba0da2dc
...@@ -736,15 +736,15 @@ static int axienet_device_reset(struct net_device *ndev) ...@@ -736,15 +736,15 @@ static int axienet_device_reset(struct net_device *ndev)
* *
* Would either be called after a successful transmit operation, or after * Would either be called after a successful transmit operation, or after
* there was an error when setting up the chain. * there was an error when setting up the chain.
* Returns the number of descriptors handled. * Returns the number of packets handled.
*/ */
static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
int nr_bds, bool force, u32 *sizep, int budget) int nr_bds, bool force, u32 *sizep, int budget)
{ {
struct axidma_bd *cur_p; struct axidma_bd *cur_p;
unsigned int status; unsigned int status;
int i, packets = 0;
dma_addr_t phys; dma_addr_t phys;
int i;
for (i = 0; i < nr_bds; i++) { for (i = 0; i < nr_bds; i++) {
cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num]; 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, ...@@ -763,8 +763,10 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
(cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK), (cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK),
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) {
napi_consume_skb(cur_p->skb, budget); napi_consume_skb(cur_p->skb, budget);
packets++;
}
cur_p->app0 = 0; cur_p->app0 = 0;
cur_p->app1 = 0; cur_p->app1 = 0;
...@@ -780,7 +782,13 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, ...@@ -780,7 +782,13 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd,
*sizep += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; *sizep += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
} }
return i; if (!force) {
lp->tx_bd_ci += i;
if (lp->tx_bd_ci >= lp->tx_bd_num)
lp->tx_bd_ci %= lp->tx_bd_num;
}
return packets;
} }
/** /**
...@@ -953,13 +961,10 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget) ...@@ -953,13 +961,10 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
u32 size = 0; u32 size = 0;
int packets; int packets;
packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget); packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, lp->tx_bd_num, false,
&size, budget);
if (packets) { if (packets) {
lp->tx_bd_ci += packets;
if (lp->tx_bd_ci >= lp->tx_bd_num)
lp->tx_bd_ci %= lp->tx_bd_num;
u64_stats_update_begin(&lp->tx_stat_sync); u64_stats_update_begin(&lp->tx_stat_sync);
u64_stats_add(&lp->tx_packets, packets); u64_stats_add(&lp->tx_packets, packets);
u64_stats_add(&lp->tx_bytes, size); u64_stats_add(&lp->tx_bytes, size);
......
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