Commit 339e79df authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge branch 'cleanup-ocelot_stats-exposure'

Colin Foster says:

====================
cleanup ocelot_stats exposure

The ocelot_stats structures became redundant across all users. Replace
this redundancy with a static const struct. After doing this, several
definitions inside include/soc/mscc/ocelot.h no longer needed to be
shared. Patch 2 removes them.

Checkpatch throws an error for a complicated macro not in parentheses. I
understand the reason for OCELOT_COMMON_STATS was to allow expansion, but
interestingly this patch set is essentially reverting the ability for
expansion. I'm keeping the macro in this set, but am open to remove it,
since it doesn't _actually_ provide any immediate benefits anymore.
====================

Link: https://lore.kernel.org/r/20221119231406.3167852-1-colin.foster@in-advantage.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 837a3d66 877e7b7c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1363,7 +1363,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
		return -ENOMEM;

	ocelot->map		= felix->info->map;
	ocelot->stats_layout	= felix->info->stats_layout;
	ocelot->num_mact_rows	= felix->info->num_mact_rows;
	ocelot->vcap		= felix->info->vcap;
	ocelot->vcap_pol.base	= felix->info->vcap_pol_base;
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ struct felix_info {
	const struct ocelot_ops		*ops;
	const u32			*port_modes;
	int				num_mact_rows;
	const struct ocelot_stat_layout	*stats_layout;
	int				num_ports;
	int				num_tx_queues;
	struct vcap_props		*vcap;
+0 −5
Original line number Diff line number Diff line
@@ -565,10 +565,6 @@ static const struct reg_field vsc9959_regfields[REGFIELD_MAX] = {
	[SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 7, 4),
};

static const struct ocelot_stat_layout vsc9959_stats_layout[OCELOT_NUM_STATS] = {
	OCELOT_COMMON_STATS,
};

static const struct vcap_field vsc9959_vcap_es0_keys[] = {
	[VCAP_ES0_EGR_PORT]			= {  0,  3},
	[VCAP_ES0_IGR_PORT]			= {  3,  3},
@@ -2546,7 +2542,6 @@ static const struct felix_info felix_info_vsc9959 = {
	.regfields		= vsc9959_regfields,
	.map			= vsc9959_regmap,
	.ops			= &vsc9959_ops,
	.stats_layout		= vsc9959_stats_layout,
	.vcap			= vsc9959_vcap_props,
	.vcap_pol_base		= VSC9959_VCAP_POLICER_BASE,
	.vcap_pol_max		= VSC9959_VCAP_POLICER_MAX,
+0 −5
Original line number Diff line number Diff line
@@ -543,10 +543,6 @@ static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
	[SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 11, 4),
};

static const struct ocelot_stat_layout vsc9953_stats_layout[OCELOT_NUM_STATS] = {
	OCELOT_COMMON_STATS,
};

static const struct vcap_field vsc9953_vcap_es0_keys[] = {
	[VCAP_ES0_EGR_PORT]			= {  0,  4},
	[VCAP_ES0_IGR_PORT]			= {  4,  4},
@@ -970,7 +966,6 @@ static const struct felix_info seville_info_vsc9953 = {
	.regfields		= vsc9953_regfields,
	.map			= vsc9953_regmap,
	.ops			= &vsc9953_ops,
	.stats_layout		= vsc9953_stats_layout,
	.vcap			= vsc9953_vcap_props,
	.vcap_pol_base		= VSC9953_VCAP_POLICER_BASE,
	.vcap_pol_max		= VSC9953_VCAP_POLICER_MAX,
+235 −9
Original line number Diff line number Diff line
@@ -9,6 +9,225 @@
#include <linux/workqueue.h>
#include "ocelot.h"

enum ocelot_stat {
	OCELOT_STAT_RX_OCTETS,
	OCELOT_STAT_RX_UNICAST,
	OCELOT_STAT_RX_MULTICAST,
	OCELOT_STAT_RX_BROADCAST,
	OCELOT_STAT_RX_SHORTS,
	OCELOT_STAT_RX_FRAGMENTS,
	OCELOT_STAT_RX_JABBERS,
	OCELOT_STAT_RX_CRC_ALIGN_ERRS,
	OCELOT_STAT_RX_SYM_ERRS,
	OCELOT_STAT_RX_64,
	OCELOT_STAT_RX_65_127,
	OCELOT_STAT_RX_128_255,
	OCELOT_STAT_RX_256_511,
	OCELOT_STAT_RX_512_1023,
	OCELOT_STAT_RX_1024_1526,
	OCELOT_STAT_RX_1527_MAX,
	OCELOT_STAT_RX_PAUSE,
	OCELOT_STAT_RX_CONTROL,
	OCELOT_STAT_RX_LONGS,
	OCELOT_STAT_RX_CLASSIFIED_DROPS,
	OCELOT_STAT_RX_RED_PRIO_0,
	OCELOT_STAT_RX_RED_PRIO_1,
	OCELOT_STAT_RX_RED_PRIO_2,
	OCELOT_STAT_RX_RED_PRIO_3,
	OCELOT_STAT_RX_RED_PRIO_4,
	OCELOT_STAT_RX_RED_PRIO_5,
	OCELOT_STAT_RX_RED_PRIO_6,
	OCELOT_STAT_RX_RED_PRIO_7,
	OCELOT_STAT_RX_YELLOW_PRIO_0,
	OCELOT_STAT_RX_YELLOW_PRIO_1,
	OCELOT_STAT_RX_YELLOW_PRIO_2,
	OCELOT_STAT_RX_YELLOW_PRIO_3,
	OCELOT_STAT_RX_YELLOW_PRIO_4,
	OCELOT_STAT_RX_YELLOW_PRIO_5,
	OCELOT_STAT_RX_YELLOW_PRIO_6,
	OCELOT_STAT_RX_YELLOW_PRIO_7,
	OCELOT_STAT_RX_GREEN_PRIO_0,
	OCELOT_STAT_RX_GREEN_PRIO_1,
	OCELOT_STAT_RX_GREEN_PRIO_2,
	OCELOT_STAT_RX_GREEN_PRIO_3,
	OCELOT_STAT_RX_GREEN_PRIO_4,
	OCELOT_STAT_RX_GREEN_PRIO_5,
	OCELOT_STAT_RX_GREEN_PRIO_6,
	OCELOT_STAT_RX_GREEN_PRIO_7,
	OCELOT_STAT_TX_OCTETS,
	OCELOT_STAT_TX_UNICAST,
	OCELOT_STAT_TX_MULTICAST,
	OCELOT_STAT_TX_BROADCAST,
	OCELOT_STAT_TX_COLLISION,
	OCELOT_STAT_TX_DROPS,
	OCELOT_STAT_TX_PAUSE,
	OCELOT_STAT_TX_64,
	OCELOT_STAT_TX_65_127,
	OCELOT_STAT_TX_128_255,
	OCELOT_STAT_TX_256_511,
	OCELOT_STAT_TX_512_1023,
	OCELOT_STAT_TX_1024_1526,
	OCELOT_STAT_TX_1527_MAX,
	OCELOT_STAT_TX_YELLOW_PRIO_0,
	OCELOT_STAT_TX_YELLOW_PRIO_1,
	OCELOT_STAT_TX_YELLOW_PRIO_2,
	OCELOT_STAT_TX_YELLOW_PRIO_3,
	OCELOT_STAT_TX_YELLOW_PRIO_4,
	OCELOT_STAT_TX_YELLOW_PRIO_5,
	OCELOT_STAT_TX_YELLOW_PRIO_6,
	OCELOT_STAT_TX_YELLOW_PRIO_7,
	OCELOT_STAT_TX_GREEN_PRIO_0,
	OCELOT_STAT_TX_GREEN_PRIO_1,
	OCELOT_STAT_TX_GREEN_PRIO_2,
	OCELOT_STAT_TX_GREEN_PRIO_3,
	OCELOT_STAT_TX_GREEN_PRIO_4,
	OCELOT_STAT_TX_GREEN_PRIO_5,
	OCELOT_STAT_TX_GREEN_PRIO_6,
	OCELOT_STAT_TX_GREEN_PRIO_7,
	OCELOT_STAT_TX_AGED,
	OCELOT_STAT_DROP_LOCAL,
	OCELOT_STAT_DROP_TAIL,
	OCELOT_STAT_DROP_YELLOW_PRIO_0,
	OCELOT_STAT_DROP_YELLOW_PRIO_1,
	OCELOT_STAT_DROP_YELLOW_PRIO_2,
	OCELOT_STAT_DROP_YELLOW_PRIO_3,
	OCELOT_STAT_DROP_YELLOW_PRIO_4,
	OCELOT_STAT_DROP_YELLOW_PRIO_5,
	OCELOT_STAT_DROP_YELLOW_PRIO_6,
	OCELOT_STAT_DROP_YELLOW_PRIO_7,
	OCELOT_STAT_DROP_GREEN_PRIO_0,
	OCELOT_STAT_DROP_GREEN_PRIO_1,
	OCELOT_STAT_DROP_GREEN_PRIO_2,
	OCELOT_STAT_DROP_GREEN_PRIO_3,
	OCELOT_STAT_DROP_GREEN_PRIO_4,
	OCELOT_STAT_DROP_GREEN_PRIO_5,
	OCELOT_STAT_DROP_GREEN_PRIO_6,
	OCELOT_STAT_DROP_GREEN_PRIO_7,
	OCELOT_NUM_STATS,
};

struct ocelot_stat_layout {
	u32 reg;
	char name[ETH_GSTRING_LEN];
};

/* 32-bit counter checked for wraparound by ocelot_port_update_stats()
 * and copied to ocelot->stats.
 */
#define OCELOT_STAT(kind) \
	[OCELOT_STAT_ ## kind] = { .reg = SYS_COUNT_ ## kind }
/* Same as above, except also exported to ethtool -S. Standard counters should
 * only be exposed to more specific interfaces rather than by their string name.
 */
#define OCELOT_STAT_ETHTOOL(kind, ethtool_name) \
	[OCELOT_STAT_ ## kind] = { .reg = SYS_COUNT_ ## kind, .name = ethtool_name }

#define OCELOT_COMMON_STATS \
	OCELOT_STAT_ETHTOOL(RX_OCTETS, "rx_octets"), \
	OCELOT_STAT_ETHTOOL(RX_UNICAST, "rx_unicast"), \
	OCELOT_STAT_ETHTOOL(RX_MULTICAST, "rx_multicast"), \
	OCELOT_STAT_ETHTOOL(RX_BROADCAST, "rx_broadcast"), \
	OCELOT_STAT_ETHTOOL(RX_SHORTS, "rx_shorts"), \
	OCELOT_STAT_ETHTOOL(RX_FRAGMENTS, "rx_fragments"), \
	OCELOT_STAT_ETHTOOL(RX_JABBERS, "rx_jabbers"), \
	OCELOT_STAT_ETHTOOL(RX_CRC_ALIGN_ERRS, "rx_crc_align_errs"), \
	OCELOT_STAT_ETHTOOL(RX_SYM_ERRS, "rx_sym_errs"), \
	OCELOT_STAT_ETHTOOL(RX_64, "rx_frames_below_65_octets"), \
	OCELOT_STAT_ETHTOOL(RX_65_127, "rx_frames_65_to_127_octets"), \
	OCELOT_STAT_ETHTOOL(RX_128_255, "rx_frames_128_to_255_octets"), \
	OCELOT_STAT_ETHTOOL(RX_256_511, "rx_frames_256_to_511_octets"), \
	OCELOT_STAT_ETHTOOL(RX_512_1023, "rx_frames_512_to_1023_octets"), \
	OCELOT_STAT_ETHTOOL(RX_1024_1526, "rx_frames_1024_to_1526_octets"), \
	OCELOT_STAT_ETHTOOL(RX_1527_MAX, "rx_frames_over_1526_octets"), \
	OCELOT_STAT_ETHTOOL(RX_PAUSE, "rx_pause"), \
	OCELOT_STAT_ETHTOOL(RX_CONTROL, "rx_control"), \
	OCELOT_STAT_ETHTOOL(RX_LONGS, "rx_longs"), \
	OCELOT_STAT_ETHTOOL(RX_CLASSIFIED_DROPS, "rx_classified_drops"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_0, "rx_red_prio_0"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_1, "rx_red_prio_1"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_2, "rx_red_prio_2"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_3, "rx_red_prio_3"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_4, "rx_red_prio_4"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_5, "rx_red_prio_5"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_6, "rx_red_prio_6"), \
	OCELOT_STAT_ETHTOOL(RX_RED_PRIO_7, "rx_red_prio_7"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_0, "rx_yellow_prio_0"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_1, "rx_yellow_prio_1"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_2, "rx_yellow_prio_2"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_3, "rx_yellow_prio_3"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_4, "rx_yellow_prio_4"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_5, "rx_yellow_prio_5"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_6, "rx_yellow_prio_6"), \
	OCELOT_STAT_ETHTOOL(RX_YELLOW_PRIO_7, "rx_yellow_prio_7"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_0, "rx_green_prio_0"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_1, "rx_green_prio_1"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_2, "rx_green_prio_2"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_3, "rx_green_prio_3"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_4, "rx_green_prio_4"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_5, "rx_green_prio_5"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_6, "rx_green_prio_6"), \
	OCELOT_STAT_ETHTOOL(RX_GREEN_PRIO_7, "rx_green_prio_7"), \
	OCELOT_STAT_ETHTOOL(TX_OCTETS, "tx_octets"), \
	OCELOT_STAT_ETHTOOL(TX_UNICAST, "tx_unicast"), \
	OCELOT_STAT_ETHTOOL(TX_MULTICAST, "tx_multicast"), \
	OCELOT_STAT_ETHTOOL(TX_BROADCAST, "tx_broadcast"), \
	OCELOT_STAT_ETHTOOL(TX_COLLISION, "tx_collision"), \
	OCELOT_STAT_ETHTOOL(TX_DROPS, "tx_drops"), \
	OCELOT_STAT_ETHTOOL(TX_PAUSE, "tx_pause"), \
	OCELOT_STAT_ETHTOOL(TX_64, "tx_frames_below_65_octets"), \
	OCELOT_STAT_ETHTOOL(TX_65_127, "tx_frames_65_to_127_octets"), \
	OCELOT_STAT_ETHTOOL(TX_128_255, "tx_frames_128_255_octets"), \
	OCELOT_STAT_ETHTOOL(TX_256_511, "tx_frames_256_511_octets"), \
	OCELOT_STAT_ETHTOOL(TX_512_1023, "tx_frames_512_1023_octets"), \
	OCELOT_STAT_ETHTOOL(TX_1024_1526, "tx_frames_1024_1526_octets"), \
	OCELOT_STAT_ETHTOOL(TX_1527_MAX, "tx_frames_over_1526_octets"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_0, "tx_yellow_prio_0"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_1, "tx_yellow_prio_1"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_2, "tx_yellow_prio_2"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_3, "tx_yellow_prio_3"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_4, "tx_yellow_prio_4"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_5, "tx_yellow_prio_5"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_6, "tx_yellow_prio_6"), \
	OCELOT_STAT_ETHTOOL(TX_YELLOW_PRIO_7, "tx_yellow_prio_7"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_0, "tx_green_prio_0"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_1, "tx_green_prio_1"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_2, "tx_green_prio_2"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_3, "tx_green_prio_3"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_4, "tx_green_prio_4"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_5, "tx_green_prio_5"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_6, "tx_green_prio_6"), \
	OCELOT_STAT_ETHTOOL(TX_GREEN_PRIO_7, "tx_green_prio_7"), \
	OCELOT_STAT_ETHTOOL(TX_AGED, "tx_aged"), \
	OCELOT_STAT_ETHTOOL(DROP_LOCAL, "drop_local"), \
	OCELOT_STAT_ETHTOOL(DROP_TAIL, "drop_tail"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_0, "drop_yellow_prio_0"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_1, "drop_yellow_prio_1"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_2, "drop_yellow_prio_2"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_3, "drop_yellow_prio_3"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_4, "drop_yellow_prio_4"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_5, "drop_yellow_prio_5"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_6, "drop_yellow_prio_6"), \
	OCELOT_STAT_ETHTOOL(DROP_YELLOW_PRIO_7, "drop_yellow_prio_7"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_0, "drop_green_prio_0"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_1, "drop_green_prio_1"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_2, "drop_green_prio_2"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_3, "drop_green_prio_3"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_4, "drop_green_prio_4"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_5, "drop_green_prio_5"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_6, "drop_green_prio_6"), \
	OCELOT_STAT_ETHTOOL(DROP_GREEN_PRIO_7, "drop_green_prio_7")

struct ocelot_stats_region {
	struct list_head node;
	u32 base;
	int count;
	u32 *buf;
};

static const struct ocelot_stat_layout ocelot_stats_layout[OCELOT_NUM_STATS] = {
	OCELOT_COMMON_STATS,
};

/* Read the counters from hardware and keep them in region->buf.
 * Caller must hold &ocelot->stat_view_lock.
 */
@@ -93,10 +312,10 @@ void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
		return;

	for (i = 0; i < OCELOT_NUM_STATS; i++) {
		if (ocelot->stats_layout[i].name[0] == '\0')
		if (ocelot_stats_layout[i].name[0] == '\0')
			continue;

		memcpy(data + i * ETH_GSTRING_LEN, ocelot->stats_layout[i].name,
		memcpy(data + i * ETH_GSTRING_LEN, ocelot_stats_layout[i].name,
		       ETH_GSTRING_LEN);
	}
}
@@ -137,7 +356,7 @@ int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
		return -EOPNOTSUPP;

	for (i = 0; i < OCELOT_NUM_STATS; i++)
		if (ocelot->stats_layout[i].name[0] != '\0')
		if (ocelot_stats_layout[i].name[0] != '\0')
			num_stats++;

	return num_stats;
@@ -154,7 +373,7 @@ static void ocelot_port_ethtool_stats_cb(struct ocelot *ocelot, int port,
	for (i = 0; i < OCELOT_NUM_STATS; i++) {
		int index = port * OCELOT_NUM_STATS + i;

		if (ocelot->stats_layout[i].name[0] == '\0')
		if (ocelot_stats_layout[i].name[0] == '\0')
			continue;

		*data++ = ocelot->stats[index];
@@ -383,16 +602,16 @@ EXPORT_SYMBOL(ocelot_port_get_stats64);
static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
{
	struct ocelot_stats_region *region = NULL;
	unsigned int last;
	unsigned int last = 0;
	int i;

	INIT_LIST_HEAD(&ocelot->stats_regions);

	for (i = 0; i < OCELOT_NUM_STATS; i++) {
		if (!ocelot->stats_layout[i].reg)
		if (!ocelot_stats_layout[i].reg)
			continue;

		if (region && ocelot->stats_layout[i].reg == last + 4) {
		if (region && ocelot_stats_layout[i].reg == last + 4) {
			region->count++;
		} else {
			region = devm_kzalloc(ocelot->dev, sizeof(*region),
@@ -400,12 +619,18 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
			if (!region)
				return -ENOMEM;

			region->base = ocelot->stats_layout[i].reg;
			/* enum ocelot_stat must be kept sorted in the same
			 * order as ocelot_stats_layout[i].reg in order to have
			 * efficient bulking
			 */
			WARN_ON(last >= ocelot_stats_layout[i].reg);

			region->base = ocelot_stats_layout[i].reg;
			region->count = 1;
			list_add_tail(&region->node, &ocelot->stats_regions);
		}

		last = ocelot->stats_layout[i].reg;
		last = ocelot_stats_layout[i].reg;
	}

	list_for_each_entry(region, &ocelot->stats_regions, node) {
@@ -456,3 +681,4 @@ void ocelot_stats_deinit(struct ocelot *ocelot)
	cancel_delayed_work(&ocelot->stats_work);
	destroy_workqueue(ocelot->stats_queue);
}
Loading