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 for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230314093648.44510-1-lxu@maxlinear.com>
Date:   Tue, 14 Mar 2023 17:36:48 +0800
From:   Xu Liang <lxu@...linear.com>
To:     <andrew@...n.ch>, <hkallweit1@...il.com>, <netdev@...r.kernel.org>,
        <davem@...emloft.net>, <kuba@...nel.org>
CC:     <linux@...linux.org.uk>, <hmehrtens@...linear.com>,
        <tmohren@...linear.com>, <rtanwar@...linear.com>,
        <mohammad.athari.ismail@...el.com>, <edumazet@...gle.com>,
        <michael@...le.cc>, <pabeni@...hat.com>,
        Xu Liang <lxu@...linear.com>
Subject: [PATCH net-next v4] net: phy: mxl-gpy: enhance delay time required by loopback disable function

GPY2xx devices need 3 seconds to fully switch out of loopback mode
before it can safely re-enter loopback mode. Implement timeout mechanism
to guarantee 3 seconds waited before re-enter loopback mode.

Signed-off-by: Xu Liang <lxu@...linear.com>
---
v2 changes:
 Update comments.

v3 changes:
 Submit for net-next.

v4 changes:
 Implement timeout mechanism as re-enter loopback mode is quite rare use case.
 The delay is not required to resume normal function.

 drivers/net/phy/mxl-gpy.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c
index e5972b4ef6e8..7316d6ba0cb5 100644
--- a/drivers/net/phy/mxl-gpy.c
+++ b/drivers/net/phy/mxl-gpy.c
@@ -107,6 +107,14 @@ struct gpy_priv {
 
 	u8 fw_major;
 	u8 fw_minor;
+
+	/* It takes 3 seconds to fully switch out of loopback mode before
+	 * it can safely re-enter loopback mode. Record the time when
+	 * loopback is disabled. Check and wait if necessary before loopback
+	 * is enabled.
+	 */
+	bool lb_dis_chk;
+	u64 lb_dis_to;
 };
 
 static const struct {
@@ -769,18 +777,34 @@ static void gpy_get_wol(struct phy_device *phydev,
 
 static int gpy_loopback(struct phy_device *phydev, bool enable)
 {
+	struct gpy_priv *priv = phydev->priv;
+	u16 set = 0;
 	int ret;
 
-	ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
-			 enable ? BMCR_LOOPBACK : 0);
-	if (!ret) {
-		/* It takes some time for PHY device to switch
-		 * into/out-of loopback mode.
+	if (enable) {
+		/* wait until 3 seconds from last disable */
+		if (priv->lb_dis_chk && time_is_after_jiffies64(priv->lb_dis_to))
+			msleep(jiffies64_to_msecs(priv->lb_dis_to - get_jiffies_64()));
+
+		priv->lb_dis_chk = false;
+		set = BMCR_LOOPBACK;
+	}
+
+	ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, set);
+	if (ret)
+		return ret;
+
+	if (enable) {
+		/* It takes some time for PHY device to switch into
+		 * loopback mode.
 		 */
 		msleep(100);
+	} else {
+		priv->lb_dis_chk = true;
+		priv->lb_dis_to = get_jiffies_64() + HZ * 3;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int gpy115_loopback(struct phy_device *phydev, bool enable)
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ