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

Wei Fang posted 1 patch 1 month, 1 week ago
drivers/net/ethernet/freescale/fec_main.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH net] net: fec: correct rx_bytes statistic for the case SHIFT16 is set
Posted by Wei Fang 1 month, 1 week ago
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")
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/fec_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 1edcfaee6819..3222359ac15b 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -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
Re: [PATCH net] net: fec: correct rx_bytes statistic for the case SHIFT16 is set
Posted by Jakub Kicinski 1 month, 1 week ago
On Thu,  6 Nov 2025 10:14:21 +0800 Wei Fang wrote:
>  		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?
Re: [PATCH net] net: fec: correct rx_bytes statistic for the case SHIFT16 is set
Posted by Frank Li 1 month, 1 week ago
On Thu, Nov 06, 2025 at 10:14:21AM +0800, Wei Fang 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")
> Signed-off-by: Wei Fang <wei.fang@nxp.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/net/ethernet/freescale/fec_main.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 1edcfaee6819..3222359ac15b 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -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
>