LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Claudiu Beznea <Claudiu.Beznea@microchip.com>
To: <harinikatakamlinux@gmail.com>, <nicolas.ferre@atmel.com>,
<davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<harinik@xilinx.com>, <michals@xilinx.com>, <appanad@xilinx.com>,
Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Subject: Re: [RFC PATCH 1/5] net: macb: Check MDIO state before read/write and use timeouts
Date: Thu, 3 May 2018 13:08:43 +0300 [thread overview]
Message-ID: <81b5b276-e59c-79d8-1616-79ff0e9c5f17@microchip.com> (raw)
In-Reply-To: <1521726700-22634-2-git-send-email-harinikatakamlinux@gmail.com>
On 22.03.2018 15:51, harinikatakamlinux@gmail.com wrote:
> From: Harini Katakam <harinik@xilinx.com>
>
> Replace the while loop in MDIO read/write functions with a timeout.
> In addition, add a check for MDIO bus busy before initiating a new
> operation as well to make sure there is no ongoing MDIO operation.
>
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> Signed-off-by: Harini Katakam <harinik@xilinx.com>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 54 ++++++++++++++++++++++++++++++--
> 1 file changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index d09bd43..f4030c1 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -321,6 +321,21 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
> {
> struct macb *bp = bus->priv;
> int value;
> + ulong timeout;
> +
> + timeout = jiffies + msecs_to_jiffies(1000);
> + /* wait for end of transfer */
> + do {
> + if (MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + break;
> +
> + cpu_relax();
> + } while (!time_after_eq(jiffies, timeout));
> +
> + if (time_after_eq(jiffies, timeout)) {
> + netdev_err(bp->dev, "wait for end of transfer timed out\n");
> + return -ETIMEDOUT;
> + }
Wouldn't be cleaner to keep it in this way:
while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR))) {
if (time_after_eq(jiffies, timeout) {
netdev_err(bp->dev, "wait for end of transfer timed out\n");
return -ETIMEDOUT;
}
cpu_relax();
}
>
> macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
> | MACB_BF(RW, MACB_MAN_READ)
> @@ -328,9 +343,19 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
> | MACB_BF(REGA, regnum)
> | MACB_BF(CODE, MACB_MAN_CODE)));
>
> + timeout = jiffies + msecs_to_jiffies(1000);
> /* wait for end of transfer */
> - while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + do {
> + if (MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + break;
> +
> cpu_relax();
> + } while (!time_after_eq(jiffies, timeout));
> +
> + if (time_after_eq(jiffies, timeout)) {
> + netdev_err(bp->dev, "wait for end of transfer timed out\n");
> + return -ETIMEDOUT;
> + }
>
> value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
>
> @@ -341,6 +366,21 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
> u16 value)
> {
> struct macb *bp = bus->priv;
> + ulong timeout;
> +
> + timeout = jiffies + msecs_to_jiffies(1000);
> + /* wait for end of transfer */
> + do {
> + if (MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + break;
> +
> + cpu_relax();
> + } while (!time_after_eq(jiffies, timeout));
> +
> + if (time_after_eq(jiffies, timeout)) {
> + netdev_err(bp->dev, "wait for end of transfer timed out\n");
> + return -ETIMEDOUT;
> + }
>
> macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
> | MACB_BF(RW, MACB_MAN_WRITE)
> @@ -349,9 +389,19 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
> | MACB_BF(CODE, MACB_MAN_CODE)
> | MACB_BF(DATA, value)));
>
> + timeout = jiffies + msecs_to_jiffies(1000);
> /* wait for end of transfer */
> - while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + do {
> + if (MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> + break;
> +
> cpu_relax();
> + } while (!time_after_eq(jiffies, timeout));
> +
> + if (time_after_eq(jiffies, timeout)) {
> + netdev_err(bp->dev, "wait for end of transfer timed out\n");
> + return -ETIMEDOUT;
> + }
>
> return 0;
> }
>
next prev parent reply other threads:[~2018-05-03 10:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 13:51 [RFC PATCH 0/5] Macb power management support for ZynqMP harinikatakamlinux
2018-03-22 13:51 ` [RFC PATCH 1/5] net: macb: Check MDIO state before read/write and use timeouts harinikatakamlinux
2018-03-22 14:47 ` Andrew Lunn
2018-05-03 10:08 ` Claudiu Beznea [this message]
2018-05-03 10:58 ` Harini Katakam
2018-03-22 13:51 ` [RFC PATCH 2/5] net: macb: Support clock management for tsu_clk harinikatakamlinux
2018-03-22 13:51 ` [RFC PATCH 3/5] net: macb: Add pm runtime support harinikatakamlinux
2018-05-03 10:09 ` Claudiu Beznea
2018-05-03 11:13 ` Harini Katakam
2018-05-03 12:59 ` Claudiu Beznea
2018-03-22 13:51 ` [RFC PATCH 4/5] net: macb: Add support for suspend/resume with full power down harinikatakamlinux
2018-05-03 10:09 ` Claudiu Beznea
2018-05-03 11:20 ` Harini Katakam
2018-05-03 12:23 ` Claudiu Beznea
2018-03-22 13:51 ` [RFC PATCH 5/5] net: macb: Add WOL support with ARP harinikatakamlinux
2018-05-04 12:17 ` Claudiu Beznea
2018-05-10 10:37 ` Harini Katakam
2018-05-15 8:39 ` Claudiu Beznea
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=81b5b276-e59c-79d8-1616-79ff0e9c5f17@microchip.com \
--to=claudiu.beznea@microchip.com \
--cc=appanad@xilinx.com \
--cc=davem@davemloft.net \
--cc=harinik@xilinx.com \
--cc=harinikatakamlinux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michals@xilinx.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@atmel.com \
--cc=shubhrajyoti.datta@xilinx.com \
--subject='Re: [RFC PATCH 1/5] net: macb: Check MDIO state before read/write and use timeouts' \
/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
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).