* [PATCH net-next 0/2] Add ICSSG firmware stats related to HSR @ 2026-05-12 6:06 MD Danish Anwar 2026-05-12 6:06 ` [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE MD Danish Anwar 2026-05-12 6:06 ` [PATCH net-next 2/2] net: ti: icssg: Add HSR and LRE PA statistics MD Danish Anwar 0 siblings, 2 replies; 7+ messages in thread From: MD Danish Anwar @ 2026-05-12 6:06 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, MD Danish Anwar, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, David Carlier, Kevin Hao, Vadim Fedorenko Cc: netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra This series has two pacthes, Patch 1/2 Updates Stats counter to use ARRAY_SIZE instead of hardcoded length. Patch 2/2 Adds new stats related to HSR / PRP maintained by ICSSG firmware. MD Danish Anwar (2): net: ti: icssg: Derive stats array lengths from ARRAY_SIZE net: ti: icssg: Add HSR and LRE PA statistics .../device_drivers/ethernet/ti/icssg_prueth.rst | 10 ++++++++++ drivers/net/ethernet/ti/icssg/icssg_common.c | 7 +++++-- drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- drivers/net/ethernet/ti/icssg/icssg_stats.h | 17 ++++++++++++++++- .../net/ethernet/ti/icssg/icssg_switch_map.h | 10 ++++++++++ 5 files changed, 42 insertions(+), 5 deletions(-) base-commit: 63751099502d10f0aa6bb35273e56c5800cc4e3a -- 2.34.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE 2026-05-12 6:06 [PATCH net-next 0/2] Add ICSSG firmware stats related to HSR MD Danish Anwar @ 2026-05-12 6:06 ` MD Danish Anwar 2026-05-12 7:58 ` David CARLIER 2026-05-12 6:06 ` [PATCH net-next 2/2] net: ti: icssg: Add HSR and LRE PA statistics MD Danish Anwar 1 sibling, 1 reply; 7+ messages in thread From: MD Danish Anwar @ 2026-05-12 6:06 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, MD Danish Anwar, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, David Carlier, Kevin Hao, Vadim Fedorenko Cc: netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Replace the manually maintained ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS constants with ARRAY_SIZE() expressions derived directly from the corresponding stat descriptor arrays, so that adding new entries to icssg_all_miig_stats[] or icssg_all_pa_stats[] no longer requires a separate update to a numeric constant. To make this self-contained, break the circular include dependency between icssg_stats.h and icssg_prueth.h: - icssg_stats.h previously included icssg_prueth.h (transitively pulling in icssg_switch_map.h and ETH_GSTRING_LEN). Replace that with direct includes of <linux/ethtool.h>, <linux/kernel.h> and "icssg_switch_map.h". - icssg_prueth.h now includes icssg_stats.h, giving it access to the ARRAY_SIZE-based ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS before they are used in the prueth_emac struct and ICSSG_NUM_STATS. Signed-off-by: MD Danish Anwar <danishanwar@ti.com> --- drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- drivers/net/ethernet/ti/icssg/icssg_stats.h | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h index df93d15c5b78..e2ccecb0a0dd 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h @@ -43,6 +43,7 @@ #include "icssg_config.h" #include "icss_iep.h" +#include "icssg_stats.h" #include "icssg_switch_map.h" #define PRUETH_MAX_MTU (2000 - ETH_HLEN - ETH_FCS_LEN) @@ -57,8 +58,6 @@ #define ICSSG_MAX_RFLOWS 8 /* per slice */ -#define ICSSG_NUM_PA_STATS 32 -#define ICSSG_NUM_MIIG_STATS 60 /* Number of ICSSG related stats */ #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS) #define ICSSG_NUM_STANDARD_STATS 31 diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h index 5ec0b38e0c67..b854eb587c1e 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h @@ -8,10 +8,15 @@ #ifndef __NET_TI_ICSSG_STATS_H #define __NET_TI_ICSSG_STATS_H -#include "icssg_prueth.h" +#include <linux/ethtool.h> +#include <linux/kernel.h> +#include "icssg_switch_map.h" #define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */ +#define ICSSG_NUM_MIIG_STATS ARRAY_SIZE(icssg_all_miig_stats) +#define ICSSG_NUM_PA_STATS ARRAY_SIZE(icssg_all_pa_stats) + struct miig_stats_regs { /* Rx */ u32 rx_packets; -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE 2026-05-12 6:06 ` [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE MD Danish Anwar @ 2026-05-12 7:58 ` David CARLIER 2026-05-12 9:40 ` MD Danish Anwar 0 siblings, 1 reply; 7+ messages in thread From: David CARLIER @ 2026-05-12 7:58 UTC (permalink / raw) To: MD Danish Anwar Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, Kevin Hao, Vadim Fedorenko, netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Hi MD, On Tue, 12 May 2026 at 07:06, MD Danish Anwar <danishanwar@ti.com> wrote: > > Replace the manually maintained ICSSG_NUM_MIIG_STATS and > ICSSG_NUM_PA_STATS constants with ARRAY_SIZE() expressions derived > directly from the corresponding stat descriptor arrays, so that adding > new entries to icssg_all_miig_stats[] or icssg_all_pa_stats[] no longer > requires a separate update to a numeric constant. > > To make this self-contained, break the circular include dependency > between icssg_stats.h and icssg_prueth.h: > > - icssg_stats.h previously included icssg_prueth.h (transitively > pulling in icssg_switch_map.h and ETH_GSTRING_LEN). Replace that > with direct includes of <linux/ethtool.h>, <linux/kernel.h> and > "icssg_switch_map.h". > > - icssg_prueth.h now includes icssg_stats.h, giving it access to > the ARRAY_SIZE-based ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS > before they are used in the prueth_emac struct and ICSSG_NUM_STATS. > > Signed-off-by: MD Danish Anwar <danishanwar@ti.com> > --- > drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- > drivers/net/ethernet/ti/icssg/icssg_stats.h | 7 ++++++- > 2 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h > index df93d15c5b78..e2ccecb0a0dd 100644 > --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h > +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h > @@ -43,6 +43,7 @@ > > #include "icssg_config.h" > #include "icss_iep.h" > +#include "icssg_stats.h" > #include "icssg_switch_map.h" > > #define PRUETH_MAX_MTU (2000 - ETH_HLEN - ETH_FCS_LEN) > @@ -57,8 +58,6 @@ > > #define ICSSG_MAX_RFLOWS 8 /* per slice */ > > -#define ICSSG_NUM_PA_STATS 32 > -#define ICSSG_NUM_MIIG_STATS 60 > /* Number of ICSSG related stats */ > #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS) > #define ICSSG_NUM_STANDARD_STATS 31 > diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h > index 5ec0b38e0c67..b854eb587c1e 100644 > --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h > +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h > @@ -8,10 +8,15 @@ > #ifndef __NET_TI_ICSSG_STATS_H > #define __NET_TI_ICSSG_STATS_H > > -#include "icssg_prueth.h" > +#include <linux/ethtool.h> > +#include <linux/kernel.h> > +#include "icssg_switch_map.h" > > #define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */ > > +#define ICSSG_NUM_MIIG_STATS ARRAY_SIZE(icssg_all_miig_stats) > +#define ICSSG_NUM_PA_STATS ARRAY_SIZE(icssg_all_pa_stats) > + > struct miig_stats_regs { > /* Rx */ > u32 rx_packets; > -- > 2.34.1 > One thing that caught my eye: icssg_all_miig_stats[] and icssg_all_pa_stats[] are 'static const' arrays in icssg_stats.h with ETH_GSTRING_LEN name buffers per entry. Right now only icssg_stats.c and icssg_ethtool.c pull them in. After this patch icssg_prueth.h includes icssg_stats.h, so every .c in the driver (classifier, common, config, mii_cfg, queues, switchdev, ...) ends up with its own static-const copy of both tables. Would a static_assert() work for what you're after? Something like: static const struct icssg_miig_stats icssg_all_miig_stats[] = { ... }; static_assert(ARRAY_SIZE(icssg_all_miig_stats) == ICSSG_NUM_MIIG_STATS); next to each array, keeping the numeric #defines as-is. Then 2/2 fails to build the moment a new entry is added without bumping the count, which is the case you're guarding against — without touching the include graph. What do you think ? Cheers. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE 2026-05-12 7:58 ` David CARLIER @ 2026-05-12 9:40 ` MD Danish Anwar 2026-05-12 10:03 ` David CARLIER 0 siblings, 1 reply; 7+ messages in thread From: MD Danish Anwar @ 2026-05-12 9:40 UTC (permalink / raw) To: David CARLIER Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, Kevin Hao, Vadim Fedorenko, netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Hi David, On 12/05/26 1:28 pm, David CARLIER wrote: > Hi MD, > > On Tue, 12 May 2026 at 07:06, MD Danish Anwar <danishanwar@ti.com> wrote: >> >> Replace the manually maintained ICSSG_NUM_MIIG_STATS and >> ICSSG_NUM_PA_STATS constants with ARRAY_SIZE() expressions derived >> directly from the corresponding stat descriptor arrays, so that adding >> new entries to icssg_all_miig_stats[] or icssg_all_pa_stats[] no longer >> requires a separate update to a numeric constant. >> >> To make this self-contained, break the circular include dependency >> between icssg_stats.h and icssg_prueth.h: >> >> - icssg_stats.h previously included icssg_prueth.h (transitively >> pulling in icssg_switch_map.h and ETH_GSTRING_LEN). Replace that >> with direct includes of <linux/ethtool.h>, <linux/kernel.h> and >> "icssg_switch_map.h". >> >> - icssg_prueth.h now includes icssg_stats.h, giving it access to >> the ARRAY_SIZE-based ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS >> before they are used in the prueth_emac struct and ICSSG_NUM_STATS. >> >> Signed-off-by: MD Danish Anwar <danishanwar@ti.com> >> --- >> drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- >> drivers/net/ethernet/ti/icssg/icssg_stats.h | 7 ++++++- >> 2 files changed, 7 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h >> index df93d15c5b78..e2ccecb0a0dd 100644 >> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h >> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h >> @@ -43,6 +43,7 @@ >> >> #include "icssg_config.h" >> #include "icss_iep.h" >> +#include "icssg_stats.h" >> #include "icssg_switch_map.h" >> >> #define PRUETH_MAX_MTU (2000 - ETH_HLEN - ETH_FCS_LEN) >> @@ -57,8 +58,6 @@ >> >> #define ICSSG_MAX_RFLOWS 8 /* per slice */ >> >> -#define ICSSG_NUM_PA_STATS 32 >> -#define ICSSG_NUM_MIIG_STATS 60 >> /* Number of ICSSG related stats */ >> #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS) >> #define ICSSG_NUM_STANDARD_STATS 31 >> diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h >> index 5ec0b38e0c67..b854eb587c1e 100644 >> --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h >> +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h >> @@ -8,10 +8,15 @@ >> #ifndef __NET_TI_ICSSG_STATS_H >> #define __NET_TI_ICSSG_STATS_H >> >> -#include "icssg_prueth.h" >> +#include <linux/ethtool.h> >> +#include <linux/kernel.h> >> +#include "icssg_switch_map.h" >> >> #define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */ >> >> +#define ICSSG_NUM_MIIG_STATS ARRAY_SIZE(icssg_all_miig_stats) >> +#define ICSSG_NUM_PA_STATS ARRAY_SIZE(icssg_all_pa_stats) >> + >> struct miig_stats_regs { >> /* Rx */ >> u32 rx_packets; >> -- >> 2.34.1 >> > > One thing that caught my eye: icssg_all_miig_stats[] and > icssg_all_pa_stats[] are 'static const' arrays in icssg_stats.h with > ETH_GSTRING_LEN name buffers per entry. Right now only icssg_stats.c > and icssg_ethtool.c pull them in. After this patch icssg_prueth.h > includes icssg_stats.h, so every .c in the driver (classifier, > common, config, mii_cfg, queues, switchdev, ...) ends up with its own > static-const copy of both tables. > > Would a static_assert() work for what you're after? Something like: > While adding more stats manually, The ARRAY_SIZE() approach was explicitly requested by maintainer [1]: This patch is a direct response to that feedback. static_assert() would still require updating the numeric constant on every array change. The goal here is to eliminate the need of manually incrementing stats count whenever new stats are added Your concern about multiple copies of table is noted and valid. Could you advise on the preferred way to reconcile these two requirements? I am happy to restructure if there is an approach that satisfies both. [1] https://lore.kernel.org/all/20260112181436.4s5ceywwembn674r@skbuf/#:~:text=Can%27t%20this%20be%20expressed%20as%20ARRAY_SIZE(icssg_all_pa_stats)%3F%20It%20is%20very%0Afragile%20to%20have%20to%20count%20and%20update%20this%20manually. > static const struct icssg_miig_stats icssg_all_miig_stats[] = { > ... > }; > static_assert(ARRAY_SIZE(icssg_all_miig_stats) == ICSSG_NUM_MIIG_STATS); > > next to each array, keeping the numeric #defines as-is. Then 2/2 fails > to build the moment a new entry is added without bumping the count, > which is the case you're guarding against — without touching the > include graph. > > What do you think ? > > Cheers. -- Thanks and Regards, Danish ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE 2026-05-12 9:40 ` MD Danish Anwar @ 2026-05-12 10:03 ` David CARLIER 2026-05-13 6:29 ` MD Danish Anwar 0 siblings, 1 reply; 7+ messages in thread From: David CARLIER @ 2026-05-12 10:03 UTC (permalink / raw) To: MD Danish Anwar Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, Kevin Hao, Vadim Fedorenko, netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Hi Danish, On Tue, 12 May 2026 at 10:40, MD Danish Anwar <danishanwar@ti.com> wrote: > > Hi David, > > On 12/05/26 1:28 pm, David CARLIER wrote: > > Hi MD, > > > > On Tue, 12 May 2026 at 07:06, MD Danish Anwar <danishanwar@ti.com> wrote: > >> > >> Replace the manually maintained ICSSG_NUM_MIIG_STATS and > >> ICSSG_NUM_PA_STATS constants with ARRAY_SIZE() expressions derived > >> directly from the corresponding stat descriptor arrays, so that adding > >> new entries to icssg_all_miig_stats[] or icssg_all_pa_stats[] no longer > >> requires a separate update to a numeric constant. > >> > >> To make this self-contained, break the circular include dependency > >> between icssg_stats.h and icssg_prueth.h: > >> > >> - icssg_stats.h previously included icssg_prueth.h (transitively > >> pulling in icssg_switch_map.h and ETH_GSTRING_LEN). Replace that > >> with direct includes of <linux/ethtool.h>, <linux/kernel.h> and > >> "icssg_switch_map.h". > >> > >> - icssg_prueth.h now includes icssg_stats.h, giving it access to > >> the ARRAY_SIZE-based ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS > >> before they are used in the prueth_emac struct and ICSSG_NUM_STATS. > >> > >> Signed-off-by: MD Danish Anwar <danishanwar@ti.com> > >> --- > >> drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- > >> drivers/net/ethernet/ti/icssg/icssg_stats.h | 7 ++++++- > >> 2 files changed, 7 insertions(+), 3 deletions(-) > >> > >> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h > >> index df93d15c5b78..e2ccecb0a0dd 100644 > >> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h > >> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h > >> @@ -43,6 +43,7 @@ > >> > >> #include "icssg_config.h" > >> #include "icss_iep.h" > >> +#include "icssg_stats.h" > >> #include "icssg_switch_map.h" > >> > >> #define PRUETH_MAX_MTU (2000 - ETH_HLEN - ETH_FCS_LEN) > >> @@ -57,8 +58,6 @@ > >> > >> #define ICSSG_MAX_RFLOWS 8 /* per slice */ > >> > >> -#define ICSSG_NUM_PA_STATS 32 > >> -#define ICSSG_NUM_MIIG_STATS 60 > >> /* Number of ICSSG related stats */ > >> #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS) > >> #define ICSSG_NUM_STANDARD_STATS 31 > >> diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h > >> index 5ec0b38e0c67..b854eb587c1e 100644 > >> --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h > >> +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h > >> @@ -8,10 +8,15 @@ > >> #ifndef __NET_TI_ICSSG_STATS_H > >> #define __NET_TI_ICSSG_STATS_H > >> > >> -#include "icssg_prueth.h" > >> +#include <linux/ethtool.h> > >> +#include <linux/kernel.h> > >> +#include "icssg_switch_map.h" > >> > >> #define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */ > >> > >> +#define ICSSG_NUM_MIIG_STATS ARRAY_SIZE(icssg_all_miig_stats) > >> +#define ICSSG_NUM_PA_STATS ARRAY_SIZE(icssg_all_pa_stats) > >> + > >> struct miig_stats_regs { > >> /* Rx */ > >> u32 rx_packets; > >> -- > >> 2.34.1 > >> > > > > One thing that caught my eye: icssg_all_miig_stats[] and > > icssg_all_pa_stats[] are 'static const' arrays in icssg_stats.h with > > ETH_GSTRING_LEN name buffers per entry. Right now only icssg_stats.c > > and icssg_ethtool.c pull them in. After this patch icssg_prueth.h > > includes icssg_stats.h, so every .c in the driver (classifier, > > common, config, mii_cfg, queues, switchdev, ...) ends up with its own > > static-const copy of both tables. > > > > Would a static_assert() work for what you're after? Something like: > > > > While adding more stats manually, The ARRAY_SIZE() approach was > explicitly requested by maintainer [1]: > > This patch is a direct response to that feedback. static_assert() would > still require updating the numeric constant on every array change. The > goal here is to eliminate the need of manually incrementing stats count > whenever new stats are added > > Your concern about multiple copies of table is noted and valid. Could > you advise on the preferred way to reconcile these two requirements? I > am happy to restructure if there is an approach that satisfies both. > > [1] > https://lore.kernel.org/all/20260112181436.4s5ceywwembn674r@skbuf/#:~:text=Can%27t%20this%20be%20expressed%20as%20ARRAY_SIZE(icssg_all_pa_stats)%3F%20It%20is%20very%0Afragile%20to%20have%20to%20count%20and%20update%20this%20manually. > > > > static const struct icssg_miig_stats icssg_all_miig_stats[] = { > > ... > > }; > > static_assert(ARRAY_SIZE(icssg_all_miig_stats) == ICSSG_NUM_MIIG_STATS); > > > > next to each array, keeping the numeric #defines as-is. Then 2/2 fails > > to build the moment a new entry is added without bumping the count, > > which is the case you're guarding against — without touching the > > include graph. > > > > What do you think ? > > > > Cheers. > > -- > Thanks and Regards, > Danish > Thanks for digging up the context — fair point, I'd missed Vladimir's earlier ask. Reading it again though, what he calls fragile is the silent miscount, not the keystroke of typing a number. A static_assert turns "forgot to bump" into a build error, which I think gets you there. What about moving the two arrays into icssg_stats.c, declaring them extern in the header, and dropping a static_assert next to each definition? Numeric #defines stay where they are, icssg_prueth.h doesn't need to know about icssg_stats.h, and the tables live in one TU instead of every .o in the driver. If the count and the array disagree, you get a compile error on the spot. Probably worth keeping Vladimir on Cc for v2 in case he had something else in mind. Cheers, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE 2026-05-12 10:03 ` David CARLIER @ 2026-05-13 6:29 ` MD Danish Anwar 0 siblings, 0 replies; 7+ messages in thread From: MD Danish Anwar @ 2026-05-13 6:29 UTC (permalink / raw) To: David CARLIER Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, Kevin Hao, Vadim Fedorenko, netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Hi David On 12/05/26 3:33 pm, David CARLIER wrote: > Hi Danish, > > > On Tue, 12 May 2026 at 10:40, MD Danish Anwar <danishanwar@ti.com> wrote: >> >> Hi David, >> >> On 12/05/26 1:28 pm, David CARLIER wrote: >>> Hi MD, >>> >>> On Tue, 12 May 2026 at 07:06, MD Danish Anwar <danishanwar@ti.com> wrote: >>>> >>>> Replace the manually maintained ICSSG_NUM_MIIG_STATS and >>>> ICSSG_NUM_PA_STATS constants with ARRAY_SIZE() expressions derived >>>> directly from the corresponding stat descriptor arrays, so that adding >>>> new entries to icssg_all_miig_stats[] or icssg_all_pa_stats[] no longer >>>> requires a separate update to a numeric constant. >>>> >>>> To make this self-contained, break the circular include dependency >>>> between icssg_stats.h and icssg_prueth.h: >>>> >>>> - icssg_stats.h previously included icssg_prueth.h (transitively >>>> pulling in icssg_switch_map.h and ETH_GSTRING_LEN). Replace that >>>> with direct includes of <linux/ethtool.h>, <linux/kernel.h> and >>>> "icssg_switch_map.h". >>>> >>>> - icssg_prueth.h now includes icssg_stats.h, giving it access to >>>> the ARRAY_SIZE-based ICSSG_NUM_MIIG_STATS and ICSSG_NUM_PA_STATS >>>> before they are used in the prueth_emac struct and ICSSG_NUM_STATS. >>>> >>>> Signed-off-by: MD Danish Anwar <danishanwar@ti.com> >>>> --- >>>> drivers/net/ethernet/ti/icssg/icssg_prueth.h | 3 +-- >>>> drivers/net/ethernet/ti/icssg/icssg_stats.h | 7 ++++++- >>>> 2 files changed, 7 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h >>>> index df93d15c5b78..e2ccecb0a0dd 100644 >>>> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h >>>> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h >>>> @@ -43,6 +43,7 @@ >>>> >>>> #include "icssg_config.h" >>>> #include "icss_iep.h" >>>> +#include "icssg_stats.h" >>>> #include "icssg_switch_map.h" >>>> >>>> #define PRUETH_MAX_MTU (2000 - ETH_HLEN - ETH_FCS_LEN) >>>> @@ -57,8 +58,6 @@ >>>> >>>> #define ICSSG_MAX_RFLOWS 8 /* per slice */ >>>> >>>> -#define ICSSG_NUM_PA_STATS 32 >>>> -#define ICSSG_NUM_MIIG_STATS 60 >>>> /* Number of ICSSG related stats */ >>>> #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS) >>>> #define ICSSG_NUM_STANDARD_STATS 31 >>>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h >>>> index 5ec0b38e0c67..b854eb587c1e 100644 >>>> --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h >>>> +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h >>>> @@ -8,10 +8,15 @@ >>>> #ifndef __NET_TI_ICSSG_STATS_H >>>> #define __NET_TI_ICSSG_STATS_H >>>> >>>> -#include "icssg_prueth.h" >>>> +#include <linux/ethtool.h> >>>> +#include <linux/kernel.h> >>>> +#include "icssg_switch_map.h" >>>> >>>> #define STATS_TIME_LIMIT_1G_MS 25000 /* 25 seconds @ 1G */ >>>> >>>> +#define ICSSG_NUM_MIIG_STATS ARRAY_SIZE(icssg_all_miig_stats) >>>> +#define ICSSG_NUM_PA_STATS ARRAY_SIZE(icssg_all_pa_stats) >>>> + >>>> struct miig_stats_regs { >>>> /* Rx */ >>>> u32 rx_packets; >>>> -- >>>> 2.34.1 >>>> >>> >>> One thing that caught my eye: icssg_all_miig_stats[] and >>> icssg_all_pa_stats[] are 'static const' arrays in icssg_stats.h with >>> ETH_GSTRING_LEN name buffers per entry. Right now only icssg_stats.c >>> and icssg_ethtool.c pull them in. After this patch icssg_prueth.h >>> includes icssg_stats.h, so every .c in the driver (classifier, >>> common, config, mii_cfg, queues, switchdev, ...) ends up with its own >>> static-const copy of both tables. >>> >>> Would a static_assert() work for what you're after? Something like: >>> >> >> While adding more stats manually, The ARRAY_SIZE() approach was >> explicitly requested by maintainer [1]: >> >> This patch is a direct response to that feedback. static_assert() would >> still require updating the numeric constant on every array change. The >> goal here is to eliminate the need of manually incrementing stats count >> whenever new stats are added >> >> Your concern about multiple copies of table is noted and valid. Could >> you advise on the preferred way to reconcile these two requirements? I >> am happy to restructure if there is an approach that satisfies both. >> >> [1] >> https://lore.kernel.org/all/20260112181436.4s5ceywwembn674r@skbuf/#:~:text=Can%27t%20this%20be%20expressed%20as%20ARRAY_SIZE(icssg_all_pa_stats)%3F%20It%20is%20very%0Afragile%20to%20have%20to%20count%20and%20update%20this%20manually. >> >> >>> static const struct icssg_miig_stats icssg_all_miig_stats[] = { >>> ... >>> }; >>> static_assert(ARRAY_SIZE(icssg_all_miig_stats) == ICSSG_NUM_MIIG_STATS); >>> >>> next to each array, keeping the numeric #defines as-is. Then 2/2 fails >>> to build the moment a new entry is added without bumping the count, >>> which is the case you're guarding against — without touching the >>> include graph. >>> >>> What do you think ? >>> >>> Cheers. >> >> -- >> Thanks and Regards, >> Danish >> > > > Thanks for digging up the context — fair point, I'd missed Vladimir's > earlier ask. Reading it again though, what he calls fragile is the > silent miscount, not the keystroke of typing a number. A static_assert > turns "forgot to bump" into a build error, which I think gets you > there. > Thank you for the suggestion. I think your previous suggestion fits better. I believe keeping the arrays in icssg_stats.h is preferable to moving them to icssg_stats.c. Here is my reasoning: Your binary-bloat concern was about icssg_prueth.h including icssg_stats.h, which would drag the static const tables into every .c that includes icssg_prueth.h (~11 translation units). That concern is valid, but it is specific to the include direction of the previous patch. If we simply revert to the original include graph — icssg_stats.h includes icssg_prueth.h, not the other way around — only the two files that have always included icssg_stats.h directly (icssg_stats.c and icssg_ethtool.c) get a copy of the arrays. No regression in binary size compared to the baseline. > What about moving the two arrays into icssg_stats.c, declaring them > extern in the header, and dropping a static_assert next to each > definition? Numeric #defines stay where they are, icssg_prueth.h > doesn't need to know about icssg_stats.h, and the tables live in one > TU instead of every .o in the driver. If the count and the array > disagree, you get a compile error on the spot. > Moving the arrays to icssg_stats.c (approach #2) adds extern declarations, splits the definition from the static_assert, and is a larger restructuring for the same safety guarantee. Keeping the arrays in the header with a static_assert immediately after each one is a 2-line diff and leaves the code easy to read in one place. Please let me know if this sounds okay to you. I will send out a v2 soon if this approach is fine with you. > Probably worth keeping Vladimir on Cc for v2 in case he had something > else in mind. > I will CC Vladimir in v2. -- Thanks and Regards, Danish ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next 2/2] net: ti: icssg: Add HSR and LRE PA statistics 2026-05-12 6:06 [PATCH net-next 0/2] Add ICSSG firmware stats related to HSR MD Danish Anwar 2026-05-12 6:06 ` [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE MD Danish Anwar @ 2026-05-12 6:06 ` MD Danish Anwar 1 sibling, 0 replies; 7+ messages in thread From: MD Danish Anwar @ 2026-05-12 6:06 UTC (permalink / raw) To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet, Shuah Khan, MD Danish Anwar, Roger Quadros, Andrew Lunn, Jacob Keller, Meghana Malladi, David Carlier, Kevin Hao, Vadim Fedorenko Cc: netdev, linux-doc, linux-kernel, linux-arm-kernel, Vignesh Raghavendra Add new firmware PA statistics counters for HSR and LRE to the ethtool statistics exposed by the ICSSG driver. New statistics added: - FW_HSR_FWD_CHECK_FAIL_DROP: Packets dropped on the HSR forwarding path - FW_HSR_HE_CHECK_FAIL_DROP: Packets dropped on the HSR host egress path - FW_HSR_SKIP_HOST_DUP_DISCARD_FRAMES: Frames with duplicate discard skipped - FW_LRE_CNT_UNIQUE/DUPLICATE/MULTIPLE_RX: LRE duplicate detetcion counters - FW_LRE_CNT_RX/TX: LRE per-port frame counters - FW_LRE_CNT_OWN_RX: Own HSR tagged frames received - FW_LRE_CNT_ERRWRONGLAN: Frames with wrong LAN identifier (PRP) Document the new HSR/LRE statistics in icssg_prueth.rst. Signed-off-by: MD Danish Anwar <danishanwar@ti.com> --- .../device_drivers/ethernet/ti/icssg_prueth.rst | 10 ++++++++++ drivers/net/ethernet/ti/icssg/icssg_common.c | 7 +++++-- drivers/net/ethernet/ti/icssg/icssg_stats.h | 10 ++++++++++ drivers/net/ethernet/ti/icssg/icssg_switch_map.h | 10 ++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/device_drivers/ethernet/ti/icssg_prueth.rst b/Documentation/networking/device_drivers/ethernet/ti/icssg_prueth.rst index da21ddf431bb..b0bda7327b2a 100644 --- a/Documentation/networking/device_drivers/ethernet/ti/icssg_prueth.rst +++ b/Documentation/networking/device_drivers/ethernet/ti/icssg_prueth.rst @@ -54,3 +54,13 @@ These statistics are as follows, - ``FW_HOST_TX_PKT_CNT``: Number of valid packets copied by RTU0 to Tx queues - ``FW_HOST_EGRESS_Q_PRE_OVERFLOW``: Host Egress Q (Pre-emptible) Overflow Counter - ``FW_HOST_EGRESS_Q_EXP_OVERFLOW``: Host Egress Q (Pre-emptible) Overflow Counter + - ``FW_HSR_FWD_CHECK_FAIL_DROP``: Packets dropped on the HSR forwarding path due to failed checks + - ``FW_HSR_HE_CHECK_FAIL_DROP``: Packets dropped on the host egress path due to failed checks + - ``FW_HSR_SKIP_HOST_DUP_DISCARD_FRAMES``: Frames for which the host duplicate discard check was skipped + - ``FW_LRE_CNT_UNIQUE_RX``: Number of frames received with no duplicate detected + - ``FW_LRE_CNT_DUPLICATE_RX``: Number of frames received for which exactly one duplicate was detected + - ``FW_LRE_CNT_MULTIPLE_RX``: Number of frames received for which more than one duplicate was detected + - ``FW_LRE_CNT_RX``: Number of HSR/PRP tagged frames received + - ``FW_LRE_CNT_TX``: Number of HSR/PRP tagged frames sent + - ``FW_LRE_CNT_OWN_RX``: Number of HSR/PRP tagged frames received whose source MAC matches the node's own address + - ``FW_LRE_CNT_ERRWRONGLAN``: Number of frames received with a wrong LAN identifier, PRP only diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c index a28a608f9bf4..e7a51a9eee24 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_common.c +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c @@ -1633,7 +1633,8 @@ void icssg_ndo_get_stats64(struct net_device *ndev, emac_get_stat_by_name(emac, "FW_RX_EOF_SHORT_FRMERR") + emac_get_stat_by_name(emac, "FW_RX_B0_DROP_EARLY_EOF") + emac_get_stat_by_name(emac, "FW_RX_EXP_FRAG_Q_DROP") + - emac_get_stat_by_name(emac, "FW_RX_FIFO_OVERRUN"); + emac_get_stat_by_name(emac, "FW_RX_FIFO_OVERRUN") + + emac_get_stat_by_name(emac, "FW_LRE_CNT_ERRWRONGLAN"); stats->rx_dropped = ndev->stats.rx_dropped + emac_get_stat_by_name(emac, "FW_DROPPED_PKT") + emac_get_stat_by_name(emac, "FW_INF_PORT_DISABLED") + @@ -1643,7 +1644,9 @@ void icssg_ndo_get_stats64(struct net_device *ndev, emac_get_stat_by_name(emac, "FW_INF_DROP_TAGGED") + emac_get_stat_by_name(emac, "FW_INF_DROP_PRIOTAGGED") + emac_get_stat_by_name(emac, "FW_INF_DROP_NOTAG") + - emac_get_stat_by_name(emac, "FW_INF_DROP_NOTMEMBER"); + emac_get_stat_by_name(emac, "FW_INF_DROP_NOTMEMBER") + + emac_get_stat_by_name(emac, "FW_HSR_FWD_CHECK_FAIL_DROP") + + emac_get_stat_by_name(emac, "FW_HSR_HE_CHECK_FAIL_DROP"); stats->tx_errors = ndev->stats.tx_errors; stats->tx_dropped = ndev->stats.tx_dropped + emac_get_stat_by_name(emac, "FW_RTU_PKT_DROP") + diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h index b854eb587c1e..af3fcecac403 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_stats.h +++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h @@ -204,6 +204,16 @@ static const struct icssg_pa_stats icssg_all_pa_stats[] = { ICSSG_PA_STATS(FW_HOST_TX_PKT_CNT), ICSSG_PA_STATS(FW_HOST_EGRESS_Q_PRE_OVERFLOW), ICSSG_PA_STATS(FW_HOST_EGRESS_Q_EXP_OVERFLOW), + ICSSG_PA_STATS(FW_HSR_FWD_CHECK_FAIL_DROP), + ICSSG_PA_STATS(FW_HSR_HE_CHECK_FAIL_DROP), + ICSSG_PA_STATS(FW_HSR_SKIP_HOST_DUP_DISCARD_FRAMES), + ICSSG_PA_STATS(FW_LRE_CNT_UNIQUE_RX), + ICSSG_PA_STATS(FW_LRE_CNT_DUPLICATE_RX), + ICSSG_PA_STATS(FW_LRE_CNT_MULTIPLE_RX), + ICSSG_PA_STATS(FW_LRE_CNT_RX), + ICSSG_PA_STATS(FW_LRE_CNT_TX), + ICSSG_PA_STATS(FW_LRE_CNT_OWN_RX), + ICSSG_PA_STATS(FW_LRE_CNT_ERRWRONGLAN), }; #endif /* __NET_TI_ICSSG_STATS_H */ diff --git a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h index 7e053b8af3ec..bd2d54dd7f45 100644 --- a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h +++ b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h @@ -266,5 +266,15 @@ #define FW_HOST_TX_PKT_CNT 0x0250 #define FW_HOST_EGRESS_Q_PRE_OVERFLOW 0x0258 #define FW_HOST_EGRESS_Q_EXP_OVERFLOW 0x0260 +#define FW_HSR_FWD_CHECK_FAIL_DROP 0x0500 +#define FW_HSR_HE_CHECK_FAIL_DROP 0x0508 +#define FW_HSR_SKIP_HOST_DUP_DISCARD_FRAMES 0x0510 +#define FW_LRE_CNT_UNIQUE_RX 0x0518 +#define FW_LRE_CNT_DUPLICATE_RX 0x0520 +#define FW_LRE_CNT_MULTIPLE_RX 0x0528 +#define FW_LRE_CNT_RX 0x0530 +#define FW_LRE_CNT_TX 0x0538 +#define FW_LRE_CNT_OWN_RX 0x0540 +#define FW_LRE_CNT_ERRWRONGLAN 0x0548 #endif /* __NET_TI_ICSSG_SWITCH_MAP_H */ -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-05-13 6:29 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-05-12 6:06 [PATCH net-next 0/2] Add ICSSG firmware stats related to HSR MD Danish Anwar 2026-05-12 6:06 ` [PATCH net-next 1/2] net: ti: icssg: Derive stats array lengths from ARRAY_SIZE MD Danish Anwar 2026-05-12 7:58 ` David CARLIER 2026-05-12 9:40 ` MD Danish Anwar 2026-05-12 10:03 ` David CARLIER 2026-05-13 6:29 ` MD Danish Anwar 2026-05-12 6:06 ` [PATCH net-next 2/2] net: ti: icssg: Add HSR and LRE PA statistics MD Danish Anwar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox