[PATCH net 3/3] net/mlx5e: Account for netdev stats in ndo_get_stats64

Tariq Toukan posted 3 patches 1 week, 6 days ago
[PATCH net 3/3] net/mlx5e: Account for netdev stats in ndo_get_stats64
Posted by Tariq Toukan 1 week, 6 days ago
From: Gal Pressman <gal@nvidia.com>

The driver's ndo_get_stats64 callback is only reporting mlx5 counters,
without accounting for the netdev stats, causing errors from the network
stack to be invisible in statistics.

Add netdev_stats_to_stats64() call to first populate the counters, then
add mlx5 counters on top, ensuring both are accounted for (where
appropriate).

Fixes: f62b8bb8f2d3 ("net/mlx5: Extend mlx5_core to support ConnectX-4 Ethernet functionality")
Signed-off-by: Gal Pressman <gal@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index f83359f7fdea..4b2963bbe7ff 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -4052,6 +4052,8 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
 		mlx5e_queue_update_stats(priv);
 	}
 
+	netdev_stats_to_stats64(stats, &dev->stats);
+
 	if (mlx5e_is_uplink_rep(priv)) {
 		struct mlx5e_vport_stats *vstats = &priv->stats.vport;
 
@@ -4068,21 +4070,21 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
 		mlx5e_fold_sw_stats64(priv, stats);
 	}
 
-	stats->rx_missed_errors = priv->stats.qcnt.rx_out_of_buffer;
-	stats->rx_dropped = PPORT_2863_GET(pstats, if_in_discards);
+	stats->rx_missed_errors += priv->stats.qcnt.rx_out_of_buffer;
+	stats->rx_dropped += PPORT_2863_GET(pstats, if_in_discards);
 
-	stats->rx_length_errors =
+	stats->rx_length_errors +=
 		PPORT_802_3_GET(pstats, a_in_range_length_errors) +
 		PPORT_802_3_GET(pstats, a_out_of_range_length_field) +
 		PPORT_802_3_GET(pstats, a_frame_too_long_errors) +
 		VNIC_ENV_GET(&priv->stats.vnic, eth_wqe_too_small);
-	stats->rx_crc_errors =
+	stats->rx_crc_errors +=
 		PPORT_802_3_GET(pstats, a_frame_check_sequence_errors);
-	stats->rx_frame_errors = PPORT_802_3_GET(pstats, a_alignment_errors);
-	stats->tx_aborted_errors = PPORT_2863_GET(pstats, if_out_discards);
-	stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
-			   stats->rx_frame_errors;
-	stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors;
+	stats->rx_frame_errors += PPORT_802_3_GET(pstats, a_alignment_errors);
+	stats->tx_aborted_errors += PPORT_2863_GET(pstats, if_out_discards);
+	stats->rx_errors += stats->rx_length_errors + stats->rx_crc_errors +
+			    stats->rx_frame_errors;
+	stats->tx_errors += stats->tx_aborted_errors + stats->tx_carrier_errors;
 }
 
 static void mlx5e_nic_set_rx_mode(struct mlx5e_priv *priv)
-- 
2.40.1
Re: [PATCH net 3/3] net/mlx5e: Account for netdev stats in ndo_get_stats64
Posted by Jakub Kicinski 1 week, 4 days ago
On Mon, 26 Jan 2026 09:14:55 +0200 Tariq Toukan wrote:
> The driver's ndo_get_stats64 callback is only reporting mlx5 counters,
> without accounting for the netdev stats, causing errors from the network
> stack to be invisible in statistics.

I cooked up a patch to fix this generically in the core... but I can't
actually find any "errors from the network stack" that are accounted
to dev->stats. Could you be more specific about the issues you were
seeing?
Re: [PATCH net 3/3] net/mlx5e: Account for netdev stats in ndo_get_stats64
Posted by Gal Pressman 1 week, 4 days ago
On 28/01/2026 5:52, Jakub Kicinski wrote:
> On Mon, 26 Jan 2026 09:14:55 +0200 Tariq Toukan wrote:
>> The driver's ndo_get_stats64 callback is only reporting mlx5 counters,
>> without accounting for the netdev stats, causing errors from the network
>> stack to be invisible in statistics.
> 
> I cooked up a patch to fix this generically in the core... but I can't
> actually find any "errors from the network stack" that are accounted
> to dev->stats. Could you be more specific about the issues you were
> seeing?

My original motivation was identifying packet drops in the GRE stack,
specifically in gre_rcv() after an error in gre_parse_header() (in my
case, due to a checksum error).
Currently, these packets are silently dropped. I have additional patches
that increment the rx_dropped/rx_crc_errors counters in that path, which
exposed the issue, but they haven't been submitted yet.

However, you are right that it's hard to find existing dev->stats
increments, the use case this currently fixes is an error in
__bpf_redirect_neigh_v4()/__bpf_redirect_neigh_v6().