Netdev List
 help / color / mirror / Atom feed
* [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side
@ 2026-11-23 20:14 Maxime Chevallier (Netdev Foundation)
  0 siblings, 0 replies; only message in thread
From: Maxime Chevallier (Netdev Foundation) @ 2026-11-23 20:14 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet,
	Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King,
	Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao,
	matttbe
  Cc: Maxime Chevallier (Netdev Foundation), thomas.petazzoni, netdev,
	linux-kernel, linux-kselftest

The logic used to detect if the kselftest remote we're interacting with
is directly connected to us uses link renegotiation to flap the link,
that way we know if there's a switch between the remote and the DUT.

However the current logic is racy. It triggers a link renegotiation,
wait for the link to come back up locally, and looks on the remote if
the link flap counter changed.

It's possible that this entire cycle happens locally before the peer
reports the link flap, in which case it reports that we're not directly
connected to the peer when we actually are.

Solve that by reversing the logic : Trigger a link renegotiation on the
peer, and check if we see the link flap locally. The current
wait_for_aneg() already waits for a full "up - down - up" cycle, so
it doens't really matter which side of the link flaps first here.

This was found in the stmmac CI setup, between an Intel I350-T4 card and
an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at
random, due to the link flap occuring either on the host or the remote
first.

Fixes: 8f897f26ef34 ("selftests: drv-net: pause: Validate the pause autonegotiation with a partner")
Signed-off-by: Maxime Chevallier (Netdev Foundation) <maxime.chevallier@bootlin.com>
---
 .../testing/selftests/drivers/net/hw/pause.py | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py
index ca4a55e59c30..31518b7ec53b 100755
--- a/tools/testing/selftests/drivers/net/hw/pause.py
+++ b/tools/testing/selftests/drivers/net/hw/pause.py
@@ -90,8 +90,8 @@ def controllable_lp(cfg):
     For low level ethtool tests, we need to have the remote directly connected
     to the local host (i.e. not through a switch).
 
-    This is tested by taking triggering a link renegotiation and checking the
-    carrier_changes counter on the partner.
+    This is tested by triggering a link renegotiation on the remote and
+    checking that the local link flaps.
 
     :returns: True if the remote is our link partner
     """
@@ -99,17 +99,17 @@ def controllable_lp(cfg):
     if controllable is not None:
         return controllable
 
-    before = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes",
-                     host=cfg.remote).stdout)
-
-    ret, _ = ethtool_ret(f"-r {cfg.ifname}", is_get=False)
+    ret, _ = ethtool_ret(f"-r {cfg.remote_ifname}", is_get=False,
+                         host=cfg.remote)
     if ret != 0:
-        raise KsftSkipEx(f"ethtool -r {cfg.ifname} failed: {errno.errorcode.get(ret, ret)}")
+        raise KsftSkipEx(f"ethtool -r {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}")
 
-    wait_for_aneg(cfg, link_drop=True)
+    try:
+        wait_for_aneg(cfg, link_drop=True)
+        cfg.lp_controllable = True
+    except TimeoutError:
+        cfg.lp_controllable = False
 
-    cfg.lp_controllable = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes",
-                                  host=cfg.remote).stdout) > before
     return cfg.lp_controllable
 
 def require_controllable_lp(cfg):
-- 
2.56.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 20:14 [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side Maxime Chevallier (Netdev Foundation)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox