Skip to contentSkip to conversation

net: fec: correct rx_bytes statistic for the case SHIFT16 is set

PATCH Applied Wei Fang 4 participants 5 messages Nov 6, 2025 – Nov 10, 2025

Subsystems (4)
lore
Share & tools
lore

Wei Fang

author maintainer
#0 lore raw

PATCH 1/1 net: fec: correct rx_bytes statistic for the case SHIFT16 is set

Two additional bytes in front of each frame received into the RX FIFO if SHIFT16 is set, so we need to subtract the extra two bytes from pkt_len to correct the statistic of rx_bytes.

Fixes 3ac72b7b63d5 ("net: fec: align IP header in hardware")
---
 drivers/net/ethernet/freescale/fec_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +2 -0
index 1edcfaee6819..3222359ac15b 100644
@@ -1835,6 +1835,8 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 		ndev->stats.rx_packets++;
 		pkt_len = fec16_to_cpu(bdp->cbd_datlen);
 		ndev->stats.rx_bytes += pkt_len;
+		if (fep->quirks & FEC_QUIRK_HAS_RACC)
+			ndev->stats.rx_bytes -= 2;
 
 		index = fec_enet_get_bd_index(bdp, &rxq->bd);
 		page = rxq->rx_skb_info[index].page;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Wei Fang

Two additional bytes in front of each frame received into the RX FIFO if SHIFT16 is set, so we need to subtract the extra two bytes from pkt_len to correct the statistic of rx_bytes.

Fixes 3ac72b7b63d5 ("net: fec: align IP header in hardware")
Quoted 20 lines
---
 drivers/net/ethernet/freescale/fec_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +2 -1
index 1edcfaee6819..3222359ac15b 100644
@@ -1835,6 +1835,8 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)
 		ndev->stats.rx_packets++;
 		pkt_len = fec16_to_cpu(bdp->cbd_datlen);
 		ndev->stats.rx_bytes += pkt_len;
+		if (fep->quirks & FEC_QUIRK_HAS_RACC)
+			ndev->stats.rx_bytes -= 2;
 
 		index = fec_enet_get_bd_index(bdp, &rxq->bd);
 		page = rxq->rx_skb_info[index].page;
--

2.34.1

maintainer
#2 lore raw
In reply to Wei Fang

drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) · line 1839

Quoted 3 lines · On Thu, 6 Nov 2025 10:14:21 +0800 Wei Fang wrote:
drivers/net/ethernet/freescale/fec_main.c +2 -0
 		ndev->stats.rx_bytes += pkt_len;
+		if (fep->quirks & FEC_QUIRK_HAS_RACC)
+			ndev->stats.rx_bytes -= 2;

Orthogonal to this patch, but why not:

	ndev->stats.rx_bytes += pkt_len - sub_len;

? Is this driver intentionally counting FCS as bytes?

author maintainer
#3 lore raw
Quoted 10 lines

Subject: Re: [PATCH net] net: fec: correct rx_bytes statistic for the case SHIFT16 is set

drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) · line 1839

Quoted 3 lines · On Thu, 6 Nov 2025 10:14:21 +0800 Wei Fang wrote:
drivers/net/ethernet/freescale/fec_main.c +2 -0
 		ndev->stats.rx_bytes += pkt_len;
+		if (fep->quirks & FEC_QUIRK_HAS_RACC)
+			ndev->stats.rx_bytes -= 2;

Orthogonal to this patch, but why not:

Quoted 3 lines
	ndev->stats.rx_bytes += pkt_len - sub_len;

? Is this driver intentionally counting FCS as bytes?

Yes, the FEC hardware does not remove the FCS from the frame, so the frame received by the driver contains the FCS and will be included in the statistics.

#4 lore raw
In reply to Wei Fang
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 6 Nov 2025 10:14:21 +0800 you wrote:

Two additional bytes in front of each frame received into the RX FIFO if SHIFT16 is set, so we need to subtract the extra two bytes from pkt_len to correct the statistic of rx_bytes.

Fixes 3ac72b7b63d5 ("net: fec: align IP header in hardware")

[...]

Here is the summary with links:
- [net] net: fec: correct rx_bytes statistic for the case SHIFT16 is set

    https://git.kernel.org/netdev/net/c/ad17e7e92a7c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html