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: <20220906075616.21347-1-qianfanguijin@163.com>
Date:   Tue,  6 Sep 2022 15:56:15 +0800
From:   qianfanguijin@....com
To:     linux-sunxi@...ts.linux.dev, linux-kernel@...r.kernel.org
Cc:     Maxime Ripard <mripard@...nel.org>, Chen-Yu Tsai <wens@...e.org>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        linux-arm-kernel@...ts.infradead.org,
        Evgeny Boger <boger@...enboard.com>,
        qianfan Zhao <qianfanguijin@....com>
Subject: [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write

From: qianfan Zhao <qianfanguijin@....com>

msleep(1) on my board takes about 30ms, and it is too long to accept.
Use read_poll_timeout to speedup.

Signed-off-by: qianfan Zhao <qianfanguijin@....com>
---
 drivers/net/mdio/mdio-sun4i.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/drivers/net/mdio/mdio-sun4i.c b/drivers/net/mdio/mdio-sun4i.c
index f798de3276dc..168e2a375535 100644
--- a/drivers/net/mdio/mdio-sun4i.c
+++ b/drivers/net/mdio/mdio-sun4i.c
@@ -26,8 +26,6 @@
 #define EMAC_MAC_MIND_REG	(0x10)
 #define EMAC_MAC_SSRR_REG	(0x14)
 
-#define MDIO_TIMEOUT		(msecs_to_jiffies(100))
-
 struct sun4i_mdio_data {
 	void __iomem		*membase;
 	struct regulator	*regulator;
@@ -36,8 +34,7 @@ struct sun4i_mdio_data {
 static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 {
 	struct sun4i_mdio_data *data = bus->priv;
-	unsigned long timeout_jiffies;
-	int value;
+	int ret, tmp, value;
 
 	/* issue the phy address and reg */
 	writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
@@ -45,12 +42,11 @@ static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 	writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
 
 	/* Wait read complete */
-	timeout_jiffies = jiffies + MDIO_TIMEOUT;
-	while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
-		if (time_is_before_jiffies(timeout_jiffies))
-			return -ETIMEDOUT;
-		msleep(1);
-	}
+	ret = read_poll_timeout(readl, tmp, (tmp & 1) == 0,
+				20, 10000, false,
+				data->membase + EMAC_MAC_MIND_REG);
+	if (ret < 0)
+		return ret;
 
 	/* push down the phy io line */
 	writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
@@ -64,7 +60,7 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 			    u16 value)
 {
 	struct sun4i_mdio_data *data = bus->priv;
-	unsigned long timeout_jiffies;
+	int ret, tmp;
 
 	/* issue the phy address and reg */
 	writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
@@ -72,12 +68,11 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
 
 	/* Wait read complete */
-	timeout_jiffies = jiffies + MDIO_TIMEOUT;
-	while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
-		if (time_is_before_jiffies(timeout_jiffies))
-			return -ETIMEDOUT;
-		msleep(1);
-	}
+	ret = read_poll_timeout(readl, tmp, (tmp & 1) == 0,
+				20, 10000, false,
+				data->membase + EMAC_MAC_MIND_REG);
+	if (ret < 0)
+		return ret;
 
 	/* push down the phy io line */
 	writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ