linux-sunxi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write
@ 2022-09-06  7:56 qianfanguijin
  2022-09-06  7:56 ` [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done qianfanguijin
  2022-09-06 19:52 ` [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write Jernej Škrabec
  0 siblings, 2 replies; 3+ messages in thread
From: qianfanguijin @ 2022-09-06  7:56 UTC (permalink / raw)
  To: linux-sunxi, linux-kernel
  Cc: Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux-arm-kernel,
	Evgeny Boger, qianfan Zhao

From: qianfan Zhao <qianfanguijin@163.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@163.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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done
  2022-09-06  7:56 [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write qianfanguijin
@ 2022-09-06  7:56 ` qianfanguijin
  2022-09-06 19:52 ` [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write Jernej Škrabec
  1 sibling, 0 replies; 3+ messages in thread
From: qianfanguijin @ 2022-09-06  7:56 UTC (permalink / raw)
  To: linux-sunxi, linux-kernel
  Cc: Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux-arm-kernel,
	Evgeny Boger, qianfan Zhao

From: qianfan Zhao <qianfanguijin@163.com>

Data maybe written to the B register if the B register is reading
immediately after 'sun4i_mdio_write' write a value to A register.

Wait write done and fix it.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
---
 drivers/net/mdio/mdio-sun4i.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mdio/mdio-sun4i.c b/drivers/net/mdio/mdio-sun4i.c
index 168e2a375535..72ac142f2edf 100644
--- a/drivers/net/mdio/mdio-sun4i.c
+++ b/drivers/net/mdio/mdio-sun4i.c
@@ -79,7 +79,10 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	/* and write data */
 	writel(value, data->membase + EMAC_MAC_MWTD_REG);
 
-	return 0;
+	/* Wait write complete */
+	return read_poll_timeout(readl, tmp, (tmp & 1) == 0,
+				 20, 10000, false,
+				 data->membase + EMAC_MAC_MIND_REG);
 }
 
 static int sun4i_mdio_probe(struct platform_device *pdev)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write
  2022-09-06  7:56 [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write qianfanguijin
  2022-09-06  7:56 ` [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done qianfanguijin
@ 2022-09-06 19:52 ` Jernej Škrabec
  1 sibling, 0 replies; 3+ messages in thread
From: Jernej Škrabec @ 2022-09-06 19:52 UTC (permalink / raw)
  To: linux-sunxi, linux-kernel, qianfanguijin
  Cc: Maxime Ripard, Chen-Yu Tsai, linux-arm-kernel, Evgeny Boger,
	qianfan Zhao

Dne torek, 06. september 2022 ob 09:56:15 CEST je qianfanguijin@163.com 
napisal(a):
> From: qianfan Zhao <qianfanguijin@163.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@163.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);

You should use readl_poll_timeout() instead, as instructed by documentation. 
Additionally, are you sure about both delay parameters? They are both much 
smaller than in original code.

Same comments apply to patch 2.

Best regards,
Jernej

> +	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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-06 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06  7:56 [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write qianfanguijin
2022-09-06  7:56 ` [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done qianfanguijin
2022-09-06 19:52 ` [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write Jernej Škrabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).