]> git.hungrycats.org Git - linux/commitdiff
net: stmmac: selftests: Check multiple MMC counters
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Wed, 26 Aug 2026 14:04:53 +0000 (16:04 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 Sep 2026 11:36:15 +0000 (13:36 +0200)
[ Upstream commit d29b399150b07796dfa81d8778d4804c08c2a41d ]

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: 091810dbded9 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c

index df64889aa4ea3c6450f695c6e0f4a276b3f4b5e3..f83bb0d33e44322eb085a82c7b5c248d58a512f0 100644 (file)
@@ -415,11 +415,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;