diff mbox series

[v2,net-next,3/3] net: mscc: ocelot: issue a warning if stats are incorrectly ordered

Message ID 20221119231406.3167852-4-colin.foster@in-advantage.com (mailing list archive)
State Accepted
Commit 877e7b7c3b12d78f0488b767ed10ec21166ee422
Delegated to: Netdev Maintainers
Headers show
Series cleanup ocelot_stats exposure | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: kuba@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 0 this patch: 0
netdev/checkpatch warning WARNING: Co-developed-by and Signed-off-by: name/email do not match
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Colin Foster Nov. 19, 2022, 11:14 p.m. UTC
Ocelot uses regmap_bulk_read() operations to efficiently read stats
registers. Currently the implementation relies on the stats layout to be
ordered to be most efficient.

Issue a warning if any future implementations happen to break this pattern.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Co-developed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---

v1->v2
    * New patch, picked up from previous mailings

---
 drivers/net/ethernet/mscc/ocelot_stats.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Vladimir Oltean Nov. 21, 2022, 4:51 p.m. UTC | #1
On Sat, Nov 19, 2022 at 03:14:06PM -0800, Colin Foster wrote:
> Ocelot uses regmap_bulk_read() operations to efficiently read stats
> registers. Currently the implementation relies on the stats layout to be
> ordered to be most efficient.
> 
> Issue a warning if any future implementations happen to break this pattern.
> 
> Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
> Co-developed-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Assertion holds even with my MAC Merge patch set that's in preparation,
so things are good.

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c
index 68e9f450c468..1478c3b21af1 100644
--- a/drivers/net/ethernet/mscc/ocelot_stats.c
+++ b/drivers/net/ethernet/mscc/ocelot_stats.c
@@ -602,7 +602,7 @@  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);
@@ -619,6 +619,12 @@  static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
 			if (!region)
 				return -ENOMEM;
 
+			/* 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);