Skip to contentSkip to conversation

mlxsw: spectrum_ethtool: expose per-PG rx_discards

PATCH Applied Keno Fischer 3 participants 4 messages May 18 – May 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxsw: spectrum_ethtool: expose per-PG rx_discards

PPCNT group 0x10 (per-priority counters) carries an rx_discards field at offset 0x78. These counters aggregate up into if_in_discards, but don't show up anywhere else. Since there are many things that aggregate into if_in_discards, having these counters helps distinguish what caused those discards (in my case they were caused by headroom buffer overruns due to inappropriately configured buffer sizes).

Of note, from emperical testing, these counter are per-"priority group" (PG) not per-"switch priority". It's a bit confusing, because the rest of these counter are per-"switch priority" and the header file calls these "Per Priority Group Counters". However, that should be read as "(Per Priority) Group Counters", not "Per (Priority Group) Counters".

I attempted to distinguish this in the counter naming by calling these rx_discards_pg_N rather than rx_discards_prio_N (which is the naming scheme of the other counters in this PPCNT group).

I will also note that the mlx5 driver (which already has this counter) uses the schme rx_prioN_discards (and same for the other counters in this group). However, I was unable to determine whether the mlx5 counters behave the same as the mlxsw counters with respect to PG mapping. An attempt to remap to a different PG there did not change which counter incremented, but the mlx5 configuration code is quite different, so it's possible the remapping needs to be done differently.

Assisted-by Claude:claude-opus-4-7
---
 drivers/net/ethernet/mellanox/mlxsw/reg.h              | 8 ++++++++
 drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c | 4 ++++
 2 files changed, 12 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/reg.h +8 -0
index 3bb89045eaf5..01fcbd1c8d01 100644
@@ -5651,6 +5651,14 @@ MLXSW_ITEM64(reg, ppcnt, tx_pause_duration,
 MLXSW_ITEM64(reg, ppcnt, tx_pause_transition,
 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
 
+/* reg_ppcnt_rx_discards
+ * Per-PG (ingress priority group) drop count.
+ * index slot is the PG, switch priority.
+ * Access: RO
+ */
+MLXSW_ITEM64(reg, ppcnt, rx_discards,
+	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x78, 0, 64);
+
 /* Ethernet Per Traffic Class Counters */
 
 /* reg_ppcnt_tc_transmit_queue
drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c +4 -0
index 0a8fb9c842d3..7f78b1ef61cc 100644
@@ -542,6 +542,10 @@ static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_prio_stats[] = {
 		.str = "tx_pause_duration_prio",
 		.getter = mlxsw_reg_ppcnt_tx_pause_duration_get,
 	},
+	{
+		.str = "rx_discards_pg",
+		.getter = mlxsw_reg_ppcnt_rx_discards_get,
+	},
 };
 
 #define MLXSW_SP_PORT_HW_PRIO_STATS_LEN ARRAY_SIZE(mlxsw_sp_port_hw_prio_stats)
Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Keno Fischer

PPCNT group 0x10 (per-priority counters) carries an rx_discards field at offset 0x78. These counters aggregate up into if_in_discards, but don't show up anywhere else. Since there are many things that aggregate into if_in_discards, having these counters helps distinguish what caused those discards (in my case they were caused by headroom buffer overruns due to inappropriately configured buffer sizes).

Quoted 5 lines

Of note, from emperical testing, these counter are per-"priority group" (PG) not per-"switch priority". It's a bit confusing, because the rest of these counter are per-"switch priority" and the header file calls these "Per Priority Group Counters". However, that should be read as "(Per Priority) Group Counters", not "Per (Priority Group) Counters".

I think it's (Per-Priority Group) Counters. As in group of counters that are per priority. Similarly there's the "Ethernet Discard Counter Group Counters". These names come from the HW manual.

Quoted 12 lines

I attempted to distinguish this in the counter naming by calling these rx_discards_pg_N rather than rx_discards_prio_N (which is the naming scheme of the other counters in this PPCNT group).

I will also note that the mlx5 driver (which already has this counter) uses the schme rx_prioN_discards (and same for the other counters in this group). However, I was unable to determine whether the mlx5 counters behave the same as the mlxsw counters with respect to PG mapping. An attempt to remap to a different PG there did not change which counter incremented, but the mlx5 configuration code is quite different, so it's possible the remapping needs to be done differently.

Quoted 2 lines
Assisted-by Claude:claude-opus-4-7

LGTM, thanks!

#2 lore raw
Quoted 11 lines · Petr Machata
Quoted 6 lines · Keno Fischer

Of note, from emperical testing, these counter are per-"priority group" (PG) not per-"switch priority". It's a bit confusing, because the rest of these counter are per-"switch priority" and the header file calls these "Per Priority Group Counters". However, that should be read as "(Per Priority) Group Counters", not "Per (Priority Group) Counters".

I think it's (Per-Priority Group) Counters. As in group of counters that are per priority. Similarly there's the "Ethernet Discard Counter Group Counters". These names come from the HW manual.

Yes, that's what I meant, sorry if that wasn't clear.
I meant to make the distinction that this comment
is correct for all other counters (even if marginally misleading), but not quite this one, since it is Per-Priority-Group, not Per-Priority (i.e. if you
map 3:2, you will get the prio_3 counters,
but the rx_discards_pg2 counters).
I think we're on the same page, just spelling it out for the record.

Quoted 2 lines

LGTM, thanks!

Thanks!

#3 lore raw
In reply to Keno Fischer
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Mon, 18 May 2026 01:31:31 -0400 you wrote:

PPCNT group 0x10 (per-priority counters) carries an rx_discards field at offset 0x78. These counters aggregate up into if_in_discards, but don't show up anywhere else. Since there are many things that aggregate into if_in_discards, having these counters helps distinguish what caused those discards (in my case they were caused by headroom buffer overruns due to inappropriately configured buffer sizes).

[...]

Here is the summary with links:
- [net-next] mlxsw: spectrum_ethtool: expose per-PG rx_discards

    https://git.kernel.org/netdev/net-next/c/a2b5e31b668f

You are awesome, thank you!

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