lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250110144828.4943-6-gerhard@engleder-embedded.com>
Date: Fri, 10 Jan 2025 15:48:28 +0100
From: Gerhard Engleder <gerhard@...leder-embedded.com>
To: andrew@...n.ch,
	hkallweit1@...il.com,
	linux@...linux.org.uk,
	davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	pabeni@...hat.com
Cc: netdev@...r.kernel.org,
	Gerhard Engleder <gerhard@...leder-embedded.com>
Subject: [PATCH net-next v2 5/5] tsnep: Add PHY loopback selftests

Add loopback selftests on PHY level. This enables quick testing of
loopback functionality to ensure working loopback for testing.

Signed-off-by: Gerhard Engleder <gerhard@...leder-embedded.com>
---
 .../net/ethernet/engleder/tsnep_selftests.c   | 102 ++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/drivers/net/ethernet/engleder/tsnep_selftests.c b/drivers/net/ethernet/engleder/tsnep_selftests.c
index 8a9145f93147..0a3f92ac35cd 100644
--- a/drivers/net/ethernet/engleder/tsnep_selftests.c
+++ b/drivers/net/ethernet/engleder/tsnep_selftests.c
@@ -10,6 +10,7 @@ enum tsnep_test {
 	TSNEP_TEST_TAPRIO,
 	TSNEP_TEST_TAPRIO_CHANGE,
 	TSNEP_TEST_TAPRIO_EXTENSION,
+	TSNEP_TEST_PHY_LOOPBACK,
 };
 
 static const char tsnep_test_strings[][ETH_GSTRING_LEN] = {
@@ -17,6 +18,7 @@ static const char tsnep_test_strings[][ETH_GSTRING_LEN] = {
 	"TAPRIO                (offline)",
 	"TAPRIO change         (offline)",
 	"TAPRIO extension      (offline)",
+	"PHY loopback          (offline)",
 };
 
 #define TSNEP_TEST_COUNT (sizeof(tsnep_test_strings) / ETH_GSTRING_LEN)
@@ -754,6 +756,98 @@ static bool tsnep_test_taprio_extension(struct tsnep_adapter *adapter)
 	return false;
 }
 
+static bool loopback(struct tsnep_adapter *adapter, int speed)
+{
+	struct phy_device *phydev = adapter->phydev;
+	int retval;
+
+	retval = phy_loopback(phydev, true, speed);
+	if (retval || !phydev->loopback_enabled || !phydev->link || phydev->speed != speed)
+		return false;
+	retval = phy_loopback(phydev, false, 0);
+	if (retval || phydev->loopback_enabled)
+		return false;
+
+	return true;
+}
+
+static bool set_speed(struct tsnep_adapter *adapter, int speed)
+{
+	struct ethtool_link_ksettings cmd;
+	int retval;
+
+	retval = tsnep_ethtool_ops.get_link_ksettings(adapter->netdev, &cmd);
+	if (retval)
+		return false;
+
+	if (speed) {
+		cmd.base.speed = speed;
+		cmd.base.duplex = DUPLEX_FULL;
+		cmd.base.autoneg = AUTONEG_DISABLE;
+	} else {
+		cmd.base.autoneg = AUTONEG_ENABLE;
+	}
+
+	retval = tsnep_ethtool_ops.set_link_ksettings(adapter->netdev, &cmd);
+	if (retval)
+		return false;
+
+	return true;
+}
+
+static bool tsnep_test_phy_loopback(struct tsnep_adapter *adapter)
+{
+	/* 1000Mbps loopback */
+	if (!loopback(adapter, 1000))
+		goto failed;
+
+	/* 100Mbps loopback */
+	if (!loopback(adapter, 100))
+		goto failed;
+
+	/* 1000Mbps loopback after autonegotiation */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 1000))
+		goto failed;
+
+	/* 100Mbps loopback after autonegotiation */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 100))
+		goto failed;
+
+	/* 1000Mbps loopback after 100Mbps fixed speed */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 1000))
+		goto failed;
+
+	/* 100Mbps loopback after 100Mbps fixed speed */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 100))
+		goto failed;
+
+	/* 1000Mbps loopback after 1000Mbps fixed speed */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 1000))
+		goto failed;
+
+	/* 100Mbps loopback after 1000Mbps fixed speed */
+	if (!set_speed(adapter, 0))
+		goto failed;
+	if (!loopback(adapter, 100))
+		goto failed;
+
+	return true;
+
+failed:
+	phy_loopback(adapter->phydev, false, 0);
+	return false;
+}
+
 int tsnep_ethtool_get_test_count(void)
 {
 	return TSNEP_TEST_COUNT;
@@ -777,6 +871,7 @@ void tsnep_ethtool_self_test(struct net_device *netdev,
 		data[TSNEP_TEST_TAPRIO] = 0;
 		data[TSNEP_TEST_TAPRIO_CHANGE] = 0;
 		data[TSNEP_TEST_TAPRIO_EXTENSION] = 0;
+		data[TSNEP_TEST_PHY_LOOPBACK] = 0;
 
 		return;
 	}
@@ -808,4 +903,11 @@ void tsnep_ethtool_self_test(struct net_device *netdev,
 		eth_test->flags |= ETH_TEST_FL_FAILED;
 		data[TSNEP_TEST_TAPRIO_EXTENSION] = 1;
 	}
+
+	if (tsnep_test_phy_loopback(adapter)) {
+		data[TSNEP_TEST_PHY_LOOPBACK] = 0;
+	} else {
+		eth_test->flags |= ETH_TEST_FL_FAILED;
+		data[TSNEP_TEST_PHY_LOOPBACK] = 1;
+	}
 }
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ