diff mbox series

[net-next,2/4] net: dsa: mv88e6xxx: Give each hw stat an ID

Message ID 20231201125812.1052078-3-tobias@waldekranz.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: mv88e6xxx: Add "eth-mac" and "rmon" counter group support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers warning 2 maintainers not CCed: pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch fail ERROR: Macros with complex values should be enclosed in parentheses
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tobias Waldekranz Dec. 1, 2023, 12:58 p.m. UTC
With the upcoming standard counter group support, we are no longer
reading out the whole set of counters, but rather mapping a subset to
the requested group.

Therefore, create an enum with an ID for each stat, such that
mv88e6xxx_hw_stats[] can be subscripted with a human-readable ID
corresponding to the counter's name.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 140 +++++++++++++++++--------------
 1 file changed, 77 insertions(+), 63 deletions(-)

Comments

Vladimir Oltean Dec. 4, 2023, 4:20 p.m. UTC | #1
On Fri, Dec 01, 2023 at 01:58:10PM +0100, Tobias Waldekranz wrote:
> +#define MV88E6XXX_HW_STAT_MAPPER(_fn)				   \
> +	_fn(in_good_octets,		8, 0x00, STATS_TYPE_BANK0) \
> +	_fn(in_bad_octets,		4, 0x02, STATS_TYPE_BANK0) \
> +	_fn(in_unicast,			4, 0x04, STATS_TYPE_BANK0) \
> +	_fn(in_broadcasts,		4, 0x06, STATS_TYPE_BANK0) \
> +	_fn(in_multicasts,		4, 0x07, STATS_TYPE_BANK0) \
> +	_fn(in_pause,			4, 0x16, STATS_TYPE_BANK0) \
> +	_fn(in_undersize,		4, 0x18, STATS_TYPE_BANK0) \
> +	_fn(in_fragments,		4, 0x19, STATS_TYPE_BANK0) \
> +	_fn(in_oversize,		4, 0x1a, STATS_TYPE_BANK0) \
> +	_fn(in_jabber,			4, 0x1b, STATS_TYPE_BANK0) \
> +	_fn(in_rx_error,		4, 0x1c, STATS_TYPE_BANK0) \
> +	_fn(in_fcs_error,		4, 0x1d, STATS_TYPE_BANK0) \
> +	_fn(out_octets,			8, 0x0e, STATS_TYPE_BANK0) \
> +	_fn(out_unicast,		4, 0x10, STATS_TYPE_BANK0) \
> +	_fn(out_broadcasts,		4, 0x13, STATS_TYPE_BANK0) \
> +	_fn(out_multicasts,		4, 0x12, STATS_TYPE_BANK0) \
> +	_fn(out_pause,			4, 0x15, STATS_TYPE_BANK0) \
> +	_fn(excessive,			4, 0x11, STATS_TYPE_BANK0) \
> +	_fn(collisions,			4, 0x1e, STATS_TYPE_BANK0) \
> +	_fn(deferred,			4, 0x05, STATS_TYPE_BANK0) \
> +	_fn(single,			4, 0x14, STATS_TYPE_BANK0) \
> +	_fn(multiple,			4, 0x17, STATS_TYPE_BANK0) \
> +	_fn(out_fcs_error,		4, 0x03, STATS_TYPE_BANK0) \
> +	_fn(late,			4, 0x1f, STATS_TYPE_BANK0) \
> +	_fn(hist_64bytes,		4, 0x08, STATS_TYPE_BANK0) \
> +	_fn(hist_65_127bytes,		4, 0x09, STATS_TYPE_BANK0) \
> +	_fn(hist_128_255bytes,		4, 0x0a, STATS_TYPE_BANK0) \
> +	_fn(hist_256_511bytes,		4, 0x0b, STATS_TYPE_BANK0) \
> +	_fn(hist_512_1023bytes,		4, 0x0c, STATS_TYPE_BANK0) \
> +	_fn(hist_1024_max_bytes,	4, 0x0d, STATS_TYPE_BANK0) \
> +	_fn(sw_in_discards,		4, 0x10, STATS_TYPE_PORT)  \
> +	_fn(sw_in_filtered,		2, 0x12, STATS_TYPE_PORT)  \
> +	_fn(sw_out_filtered,		2, 0x13, STATS_TYPE_PORT)  \
> +	_fn(in_discards,		4, 0x00, STATS_TYPE_BANK1) \
> +	_fn(in_filtered,		4, 0x01, STATS_TYPE_BANK1) \
> +	_fn(in_accepted,		4, 0x02, STATS_TYPE_BANK1) \
> +	_fn(in_bad_accepted,		4, 0x03, STATS_TYPE_BANK1) \
> +	_fn(in_good_avb_class_a,	4, 0x04, STATS_TYPE_BANK1) \
> +	_fn(in_good_avb_class_b,	4, 0x05, STATS_TYPE_BANK1) \
> +	_fn(in_bad_avb_class_a,		4, 0x06, STATS_TYPE_BANK1) \
> +	_fn(in_bad_avb_class_b,		4, 0x07, STATS_TYPE_BANK1) \
> +	_fn(tcam_counter_0,		4, 0x08, STATS_TYPE_BANK1) \
> +	_fn(tcam_counter_1,		4, 0x09, STATS_TYPE_BANK1) \
> +	_fn(tcam_counter_2,		4, 0x0a, STATS_TYPE_BANK1) \
> +	_fn(tcam_counter_3,		4, 0x0b, STATS_TYPE_BANK1) \
> +	_fn(in_da_unknown,		4, 0x0e, STATS_TYPE_BANK1) \
> +	_fn(in_management,		4, 0x0f, STATS_TYPE_BANK1) \
> +	_fn(out_queue_0,		4, 0x10, STATS_TYPE_BANK1) \
> +	_fn(out_queue_1,		4, 0x11, STATS_TYPE_BANK1) \
> +	_fn(out_queue_2,		4, 0x12, STATS_TYPE_BANK1) \
> +	_fn(out_queue_3,		4, 0x13, STATS_TYPE_BANK1) \
> +	_fn(out_queue_4,		4, 0x14, STATS_TYPE_BANK1) \
> +	_fn(out_queue_5,		4, 0x15, STATS_TYPE_BANK1) \
> +	_fn(out_queue_6,		4, 0x16, STATS_TYPE_BANK1) \
> +	_fn(out_queue_7,		4, 0x17, STATS_TYPE_BANK1) \
> +	_fn(out_cut_through,		4, 0x18, STATS_TYPE_BANK1) \
> +	_fn(out_octets_a,		4, 0x1a, STATS_TYPE_BANK1) \
> +	_fn(out_octets_b,		4, 0x1b, STATS_TYPE_BANK1) \
> +	_fn(out_management,		4, 0x1f, STATS_TYPE_BANK1) \
> +	/*  */
> +
> +#define MV88E6XXX_HW_STAT_ENTRY(_string, _size, _reg, _type) \
> +	{ #_string, _size, _reg, _type },

I think it would look better to take the comma out of this macro and put
it into its callers, so that enums and arrays have the natural separators
between elements.

> +static const struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
> +	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENTRY)
> +};
> +
> +#define MV88E6XXX_HW_STAT_ENUM(_string, _size, _reg, _type) \
> +	MV88E6XXX_HW_STAT_ID_ ## _string,
> +enum mv88e6xxx_hw_stat_id {
> +	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENUM)
> +
> +	MV88E6XXX_HW_STAT_ID_MAX
>  };
diff mbox series

Patch

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index ffd81174bda3..71c60f229a2f 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -937,66 +937,80 @@  static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
 	return chip->info->ops->stats_snapshot(chip, port);
 }
 
-static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
-	{ "in_good_octets",		8, 0x00, STATS_TYPE_BANK0, },
-	{ "in_bad_octets",		4, 0x02, STATS_TYPE_BANK0, },
-	{ "in_unicast",			4, 0x04, STATS_TYPE_BANK0, },
-	{ "in_broadcasts",		4, 0x06, STATS_TYPE_BANK0, },
-	{ "in_multicasts",		4, 0x07, STATS_TYPE_BANK0, },
-	{ "in_pause",			4, 0x16, STATS_TYPE_BANK0, },
-	{ "in_undersize",		4, 0x18, STATS_TYPE_BANK0, },
-	{ "in_fragments",		4, 0x19, STATS_TYPE_BANK0, },
-	{ "in_oversize",		4, 0x1a, STATS_TYPE_BANK0, },
-	{ "in_jabber",			4, 0x1b, STATS_TYPE_BANK0, },
-	{ "in_rx_error",		4, 0x1c, STATS_TYPE_BANK0, },
-	{ "in_fcs_error",		4, 0x1d, STATS_TYPE_BANK0, },
-	{ "out_octets",			8, 0x0e, STATS_TYPE_BANK0, },
-	{ "out_unicast",		4, 0x10, STATS_TYPE_BANK0, },
-	{ "out_broadcasts",		4, 0x13, STATS_TYPE_BANK0, },
-	{ "out_multicasts",		4, 0x12, STATS_TYPE_BANK0, },
-	{ "out_pause",			4, 0x15, STATS_TYPE_BANK0, },
-	{ "excessive",			4, 0x11, STATS_TYPE_BANK0, },
-	{ "collisions",			4, 0x1e, STATS_TYPE_BANK0, },
-	{ "deferred",			4, 0x05, STATS_TYPE_BANK0, },
-	{ "single",			4, 0x14, STATS_TYPE_BANK0, },
-	{ "multiple",			4, 0x17, STATS_TYPE_BANK0, },
-	{ "out_fcs_error",		4, 0x03, STATS_TYPE_BANK0, },
-	{ "late",			4, 0x1f, STATS_TYPE_BANK0, },
-	{ "hist_64bytes",		4, 0x08, STATS_TYPE_BANK0, },
-	{ "hist_65_127bytes",		4, 0x09, STATS_TYPE_BANK0, },
-	{ "hist_128_255bytes",		4, 0x0a, STATS_TYPE_BANK0, },
-	{ "hist_256_511bytes",		4, 0x0b, STATS_TYPE_BANK0, },
-	{ "hist_512_1023bytes",		4, 0x0c, STATS_TYPE_BANK0, },
-	{ "hist_1024_max_bytes",	4, 0x0d, STATS_TYPE_BANK0, },
-	{ "sw_in_discards",		4, 0x10, STATS_TYPE_PORT, },
-	{ "sw_in_filtered",		2, 0x12, STATS_TYPE_PORT, },
-	{ "sw_out_filtered",		2, 0x13, STATS_TYPE_PORT, },
-	{ "in_discards",		4, 0x00, STATS_TYPE_BANK1, },
-	{ "in_filtered",		4, 0x01, STATS_TYPE_BANK1, },
-	{ "in_accepted",		4, 0x02, STATS_TYPE_BANK1, },
-	{ "in_bad_accepted",		4, 0x03, STATS_TYPE_BANK1, },
-	{ "in_good_avb_class_a",	4, 0x04, STATS_TYPE_BANK1, },
-	{ "in_good_avb_class_b",	4, 0x05, STATS_TYPE_BANK1, },
-	{ "in_bad_avb_class_a",		4, 0x06, STATS_TYPE_BANK1, },
-	{ "in_bad_avb_class_b",		4, 0x07, STATS_TYPE_BANK1, },
-	{ "tcam_counter_0",		4, 0x08, STATS_TYPE_BANK1, },
-	{ "tcam_counter_1",		4, 0x09, STATS_TYPE_BANK1, },
-	{ "tcam_counter_2",		4, 0x0a, STATS_TYPE_BANK1, },
-	{ "tcam_counter_3",		4, 0x0b, STATS_TYPE_BANK1, },
-	{ "in_da_unknown",		4, 0x0e, STATS_TYPE_BANK1, },
-	{ "in_management",		4, 0x0f, STATS_TYPE_BANK1, },
-	{ "out_queue_0",		4, 0x10, STATS_TYPE_BANK1, },
-	{ "out_queue_1",		4, 0x11, STATS_TYPE_BANK1, },
-	{ "out_queue_2",		4, 0x12, STATS_TYPE_BANK1, },
-	{ "out_queue_3",		4, 0x13, STATS_TYPE_BANK1, },
-	{ "out_queue_4",		4, 0x14, STATS_TYPE_BANK1, },
-	{ "out_queue_5",		4, 0x15, STATS_TYPE_BANK1, },
-	{ "out_queue_6",		4, 0x16, STATS_TYPE_BANK1, },
-	{ "out_queue_7",		4, 0x17, STATS_TYPE_BANK1, },
-	{ "out_cut_through",		4, 0x18, STATS_TYPE_BANK1, },
-	{ "out_octets_a",		4, 0x1a, STATS_TYPE_BANK1, },
-	{ "out_octets_b",		4, 0x1b, STATS_TYPE_BANK1, },
-	{ "out_management",		4, 0x1f, STATS_TYPE_BANK1, },
+#define MV88E6XXX_HW_STAT_MAPPER(_fn)				   \
+	_fn(in_good_octets,		8, 0x00, STATS_TYPE_BANK0) \
+	_fn(in_bad_octets,		4, 0x02, STATS_TYPE_BANK0) \
+	_fn(in_unicast,			4, 0x04, STATS_TYPE_BANK0) \
+	_fn(in_broadcasts,		4, 0x06, STATS_TYPE_BANK0) \
+	_fn(in_multicasts,		4, 0x07, STATS_TYPE_BANK0) \
+	_fn(in_pause,			4, 0x16, STATS_TYPE_BANK0) \
+	_fn(in_undersize,		4, 0x18, STATS_TYPE_BANK0) \
+	_fn(in_fragments,		4, 0x19, STATS_TYPE_BANK0) \
+	_fn(in_oversize,		4, 0x1a, STATS_TYPE_BANK0) \
+	_fn(in_jabber,			4, 0x1b, STATS_TYPE_BANK0) \
+	_fn(in_rx_error,		4, 0x1c, STATS_TYPE_BANK0) \
+	_fn(in_fcs_error,		4, 0x1d, STATS_TYPE_BANK0) \
+	_fn(out_octets,			8, 0x0e, STATS_TYPE_BANK0) \
+	_fn(out_unicast,		4, 0x10, STATS_TYPE_BANK0) \
+	_fn(out_broadcasts,		4, 0x13, STATS_TYPE_BANK0) \
+	_fn(out_multicasts,		4, 0x12, STATS_TYPE_BANK0) \
+	_fn(out_pause,			4, 0x15, STATS_TYPE_BANK0) \
+	_fn(excessive,			4, 0x11, STATS_TYPE_BANK0) \
+	_fn(collisions,			4, 0x1e, STATS_TYPE_BANK0) \
+	_fn(deferred,			4, 0x05, STATS_TYPE_BANK0) \
+	_fn(single,			4, 0x14, STATS_TYPE_BANK0) \
+	_fn(multiple,			4, 0x17, STATS_TYPE_BANK0) \
+	_fn(out_fcs_error,		4, 0x03, STATS_TYPE_BANK0) \
+	_fn(late,			4, 0x1f, STATS_TYPE_BANK0) \
+	_fn(hist_64bytes,		4, 0x08, STATS_TYPE_BANK0) \
+	_fn(hist_65_127bytes,		4, 0x09, STATS_TYPE_BANK0) \
+	_fn(hist_128_255bytes,		4, 0x0a, STATS_TYPE_BANK0) \
+	_fn(hist_256_511bytes,		4, 0x0b, STATS_TYPE_BANK0) \
+	_fn(hist_512_1023bytes,		4, 0x0c, STATS_TYPE_BANK0) \
+	_fn(hist_1024_max_bytes,	4, 0x0d, STATS_TYPE_BANK0) \
+	_fn(sw_in_discards,		4, 0x10, STATS_TYPE_PORT)  \
+	_fn(sw_in_filtered,		2, 0x12, STATS_TYPE_PORT)  \
+	_fn(sw_out_filtered,		2, 0x13, STATS_TYPE_PORT)  \
+	_fn(in_discards,		4, 0x00, STATS_TYPE_BANK1) \
+	_fn(in_filtered,		4, 0x01, STATS_TYPE_BANK1) \
+	_fn(in_accepted,		4, 0x02, STATS_TYPE_BANK1) \
+	_fn(in_bad_accepted,		4, 0x03, STATS_TYPE_BANK1) \
+	_fn(in_good_avb_class_a,	4, 0x04, STATS_TYPE_BANK1) \
+	_fn(in_good_avb_class_b,	4, 0x05, STATS_TYPE_BANK1) \
+	_fn(in_bad_avb_class_a,		4, 0x06, STATS_TYPE_BANK1) \
+	_fn(in_bad_avb_class_b,		4, 0x07, STATS_TYPE_BANK1) \
+	_fn(tcam_counter_0,		4, 0x08, STATS_TYPE_BANK1) \
+	_fn(tcam_counter_1,		4, 0x09, STATS_TYPE_BANK1) \
+	_fn(tcam_counter_2,		4, 0x0a, STATS_TYPE_BANK1) \
+	_fn(tcam_counter_3,		4, 0x0b, STATS_TYPE_BANK1) \
+	_fn(in_da_unknown,		4, 0x0e, STATS_TYPE_BANK1) \
+	_fn(in_management,		4, 0x0f, STATS_TYPE_BANK1) \
+	_fn(out_queue_0,		4, 0x10, STATS_TYPE_BANK1) \
+	_fn(out_queue_1,		4, 0x11, STATS_TYPE_BANK1) \
+	_fn(out_queue_2,		4, 0x12, STATS_TYPE_BANK1) \
+	_fn(out_queue_3,		4, 0x13, STATS_TYPE_BANK1) \
+	_fn(out_queue_4,		4, 0x14, STATS_TYPE_BANK1) \
+	_fn(out_queue_5,		4, 0x15, STATS_TYPE_BANK1) \
+	_fn(out_queue_6,		4, 0x16, STATS_TYPE_BANK1) \
+	_fn(out_queue_7,		4, 0x17, STATS_TYPE_BANK1) \
+	_fn(out_cut_through,		4, 0x18, STATS_TYPE_BANK1) \
+	_fn(out_octets_a,		4, 0x1a, STATS_TYPE_BANK1) \
+	_fn(out_octets_b,		4, 0x1b, STATS_TYPE_BANK1) \
+	_fn(out_management,		4, 0x1f, STATS_TYPE_BANK1) \
+	/*  */
+
+#define MV88E6XXX_HW_STAT_ENTRY(_string, _size, _reg, _type) \
+	{ #_string, _size, _reg, _type },
+static const struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
+	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENTRY)
+};
+
+#define MV88E6XXX_HW_STAT_ENUM(_string, _size, _reg, _type) \
+	MV88E6XXX_HW_STAT_ID_ ## _string,
+enum mv88e6xxx_hw_stat_id {
+	MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENUM)
+
+	MV88E6XXX_HW_STAT_ID_MAX
 };
 
 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
@@ -1043,7 +1057,7 @@  static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
 static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
 				       uint8_t *data, int types)
 {
-	struct mv88e6xxx_hw_stat *stat;
+	const struct mv88e6xxx_hw_stat *stat;
 	int i, j;
 
 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
@@ -1124,7 +1138,7 @@  static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
 					  int types)
 {
-	struct mv88e6xxx_hw_stat *stat;
+	const struct mv88e6xxx_hw_stat *stat;
 	int i, j;
 
 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
@@ -1251,7 +1265,7 @@  static int mv88e6xxx_stats_get_stat(struct mv88e6xxx_chip *chip, int port,
 static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
 				     uint64_t *data)
 {
-	struct mv88e6xxx_hw_stat *stat;
+	const struct mv88e6xxx_hw_stat *stat;
 	int i, j;
 
 	for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {