[PATCH v1 net-next 0/1] net: ethernet: ocelot: remove num_stats initializer requirement

From: Colin Foster
Date: Fri Apr 29 2022 - 17:31:04 EST


The ocelot_stats_layout structure array is common with other chips,
specifically the VSC7512. It can only be controlled externally (SPI,
PCIe...)

During the VSC7512 / Felix driver development, it was noticed that
this array can be shared with the Ocelot driver. As with other arrays
shared between the VSC7514 and VSC7512, it makes sense to define them in
drivers/net/ethernet/mscc/vsc7514_regs.c, while declaring them in
include/soc/mscc/vsc7514_regs.h

The thing that makes the stats_layout unique is that it is not accessed
indirectly by way of a shared enumeration index, but instead is looped
over. As such, the num_stats parameter has been used as the loop bounds.

Since the array size isn't necessarily fixed-length, the size has to be
determined. This was done locally in the C file with ARRAY_SIZE, but
that isn't possible if the array is declared via:
extern const struct ocelot_stat_layout ocelot_stats_layout[];

Instead, determine the size by the elemenets of the structure itself.
This way stats can be added / removed as needed (though they rarely
should) without the requirement of dragging a size variable around.

I don't have felix / seville / vsc7514 hardware to test, so I'd
appreciate if someone could give it a test. I've verified functionality
on my in-development kernel, but wouldn't mind feedback from the
existing users who have had the misfortune of having to find my mistakes
when it was too late.

Colin Foster (1):
net: ethernet: ocelot: remove the need for num_stats initializer

drivers/net/dsa/ocelot/felix.c | 1 -
drivers/net/dsa/ocelot/felix.h | 1 -
drivers/net/dsa/ocelot/felix_vsc9959.c | 2 +-
drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +-
drivers/net/ethernet/mscc/ocelot.c | 5 +++++
drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 +-
include/soc/mscc/ocelot.h | 10 ++++++++++
7 files changed, 18 insertions(+), 5 deletions(-)

--
2.25.1