net: stmmac: selftests: Check multiple MMC counters

The MMC counters report MAC statistics. Multiple counters can be
enabled when the IP is integrated, however there's no way to know
exactly which ones. Un-implemented counters seem to report 0.

It was found that on StarFive JH7110 and Amlogic SM1, the counter that's
used by the selftest (mmc_tx_framecount_g) isn't implemented, triggering
an MMC selftest failure.

Both the above SoCs seem to implement mmc_rx_framecount_gb, let's use
this counter as well for MMC counter validation.

Note that this doesn't guarantee that we won't encounter the same issue
again if another IP implements yet another set of counters that don't
include that new one.

If the game of whack-a-mole with implemented counters becomes too hard to
maintain, we may simply consider removing the MMC selftest entirely.

Fixes: 091810dbde ("net: stmmac: Introduce selftests support")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20260826140500.616466-2-maxime.chevallier@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Maxime Chevallier
2026-08-26 16:04:53 +02:00
committed by Jakub Kicinski
parent e2a6641e3b
commit d29b399150

View File

@@ -395,11 +395,17 @@ static int stmmac_test_mmc(struct stmmac_priv *priv)
stmmac_mmc_read(priv, priv->mmcaddr, &final);
/*
* The number of MMC counters available depends on HW configuration
* so we just use this one to validate the feature. I hope there is
* not a version without this counter.
* The number of MMC counters available depends on HW configuration,
* and there doesn't seem to be a way to enumerate the implemented
* counters.
*
* Let's check a hand-picked set of counters, knowing that :
* - Starfive JH7110 doesn't implement mmc_tx_framecount_g
* - Amlogic SM1 doesn't implement any mmc_tx_*
*
*/
if (final.mmc_tx_framecount_g <= initial.mmc_tx_framecount_g)
if (final.mmc_tx_framecount_g <= initial.mmc_tx_framecount_g &&
final.mmc_rx_framecount_gb <= initial.mmc_rx_framecount_gb)
return -EINVAL;
return 0;