linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	qianfanguijin@163.com
Cc: Maxime Ripard <mripard@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	linux-arm-kernel@lists.infradead.org,
	Evgeny Boger <boger@wirenboard.com>,
	qianfan Zhao <qianfanguijin@163.com>
Subject: Re: [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write
Date: Tue, 06 Sep 2022 21:52:24 +0200	[thread overview]
Message-ID: <4737709.GXAFRqVoOG@kista> (raw)
In-Reply-To: <20220906075616.21347-1-qianfanguijin@163.com>

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



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      parent reply	other threads:[~2022-09-06 19:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4737709.GXAFRqVoOG@kista \
    --to=jernej.skrabec@gmail.com \
    --cc=boger@wirenboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=qianfanguijin@163.com \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).