[PATCH v4 net 1/8] net: enetc: consistently track dropped frames in enetc_xdp_xmit()

From: vladimir . oltean

Date: Thu Oct 15 2026 - 07:03:06 EST


2 distinct classes of problems:
(a) the following events from enetc_xdp_xmit() will result in the frames
being silently dropped without any counter tracking that action:
- failures in enetc_xdp_frame_to_xdp_tx_swbd(),
- frames split across too many buffers
- frames enqueued while the interface is down
Similar to how enetc_xdp_tx() increments xdp_tx_drops, let's reuse
this ethtool counter for the above cases too.
(b) enetc_xdp_tx() failures increment xdp_tx_drops by 1, but that is not
necessarily correct. Wei Fang points out that on .ndo_xdp_xmit()
failure, bq_xmit_all() drops all remaining frames from the batch,
not just the current one. So we should in any case increment the
xdp_tx_drops counter by the remainder, not just by 1.

A limitation that remains is that the xdp_tx_drops ethtool statistics
counter (already) tracks XDP_TX and XDP_REDIRECT drops in the same
value. We should distinguish between these at some point, but that is an
ABI change and is out of scope for a bug fix.

Fixes: 9d2b68cc108d ("net: enetc: add support for XDP_REDIRECT")
Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
---
v3->v4:
- make sure the ENETC_TX_DOWN case also increments the xdp_tx_drops
counter
- reword the commit message to enumerate the cases of silently dropped
frames
v2->v3:
- patch is new; replaces:
https://lore.kernel.org/netdev/20260406204122.167237-2-vladimir.oltean@xxxxxxx/
---
drivers/net/ethernet/freescale/enetc/enetc.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index e91ba77a1532..103335f3d418 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1811,15 +1811,18 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
struct enetc_bdr *tx_ring;
int xdp_tx_bd_cnt, i, k;
int xdp_tx_frm_cnt = 0;
+ int err = 0;
+
+ tx_ring = priv->xdp_tx_ring[smp_processor_id()];

if (unlikely(test_bit(ENETC_TX_DOWN, &priv->flags) ||
- !netif_carrier_ok(ndev)))
- return -ENETDOWN;
+ !netif_carrier_ok(ndev))) {
+ err = -ENETDOWN;
+ goto out;
+ }

enetc_lock_mdio();

- tx_ring = priv->xdp_tx_ring[smp_processor_id()];
-
prefetchw(ENETC_TXBD(*tx_ring, tx_ring->next_to_use));

for (k = 0; k < num_frames; k++) {
@@ -1840,7 +1843,6 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
for (i = 0; i < xdp_tx_bd_cnt; i++)
enetc_unmap_tx_buff(tx_ring,
&xdp_redirect_arr[i]);
- tx_ring->stats.xdp_tx_drops++;
break;
}

@@ -1850,11 +1852,13 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
if (unlikely((flags & XDP_XMIT_FLUSH) || k != xdp_tx_frm_cnt))
enetc_update_tx_ring_tail(tx_ring);

- tx_ring->stats.xdp_tx += xdp_tx_frm_cnt;
-
enetc_unlock_mdio();

- return xdp_tx_frm_cnt;
+out:
+ tx_ring->stats.xdp_tx += xdp_tx_frm_cnt;
+ tx_ring->stats.xdp_tx_drops += num_frames - xdp_tx_frm_cnt;
+
+ return err ?: xdp_tx_frm_cnt;
}
EXPORT_SYMBOL_GPL(enetc_xdp_xmit);

--
2.43.0