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-next>] [day] [month] [year] [list]
Message-Id: <20220825082238.11056-1-aminuddin.jamaluddin@intel.com>
Date:   Thu, 25 Aug 2022 16:22:37 +0800
From:   Aminuddin Jamaluddin <aminuddin.jamaluddin@...el.com>
To:     Andrew Lunn <andrew@...n.ch>,
        Heiner Kallweit <hkallweit1@...il.com>,
        Russell King <linux@...linux.org.uk>,
        "David S . Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Mohammad Athari Bin Ismail <mohammad.athari.ismail@...el.com>
Cc:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        stable@...r.kernel.org, tee.min.tan@...el.com,
        muhammad.husaini.zulkifli@...el.com, aminuddin.jamaluddin@...el.com
Subject: [PATCH net 1/1] net: phy: marvell: add link status check before enabling phy loopback

Add link status checking in m88e1510_loopback() for 1Gbps link speed
and delay for 100ms after phy loopback bit is set before send packet.
This is needed to ensure the stability and consistency when running
the phy loopback test.

Fixes: 020a45aff119 ("net: phy: marvell: add Marvell specific PHY loopback")
Cc: <stable@...r.kernel.org> # 5.15.x
Signed-off-by: Muhammad Husaini Zulkifli <muhammad.husaini.zulkifli@...el.com>
Signed-off-by: Aminuddin Jamaluddin <aminuddin.jamaluddin@...el.com>
---
 drivers/net/phy/marvell.c | 22 ++++++++++++++++------
 include/linux/phy.h       |  3 +++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index a714150f5e8c..17403acf780d 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1992,6 +1992,7 @@ static int m88e1510_loopback(struct phy_device *phydev, bool enable)
 
 	if (enable) {
 		u16 bmcr_ctl, mscr2_ctl = 0;
+		int val = 0;
 
 		bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
 
@@ -2015,14 +2016,23 @@ static int m88e1510_loopback(struct phy_device *phydev, bool enable)
 		if (err < 0)
 			return err;
 
-		/* FIXME: Based on trial and error test, it seem 1G need to have
-		 * delay between soft reset and loopback enablement.
-		 */
-		if (phydev->speed == SPEED_1000)
-			msleep(1000);
+		if (phydev->speed == SPEED_1000) {
+			err = phy_read_poll_timeout(phydev, MII_BMSR, val, val & BMSR_LSTATUS,
+						    PHY_LOOP_BACK_SLEEP,
+						    PHY_LOOP_BACK_TIMEOUT, true);
+			if (err)
+				return err;
+		}
 
-		return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
+		err =  phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
 				  BMCR_LOOPBACK);
+		if (!err) {
+			/* It takes some time for PHY device to switch
+			 * into/out-of loopback mode.
+			 */
+			msleep(100);
+		}
+		return err;
 	} else {
 		err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0);
 		if (err < 0)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 87638c55d844..b4da968da8e6 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -276,6 +276,9 @@ static inline const char *phy_modes(phy_interface_t interface)
 #define PHY_INIT_TIMEOUT	100000
 #define PHY_FORCE_TIMEOUT	10
 
+#define PHY_LOOP_BACK_SLEEP	1000000
+#define PHY_LOOP_BACK_TIMEOUT	8000000
+
 #define PHY_MAX_ADDR	32
 
 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ