LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Harini Katakam <harini.katakam@xilinx.com>
To: <nicolas.ferre@microchip.com>, <davem@davemloft.net>,
	<claudiu.beznea@microchip.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<michal.simek@xilinx.com>, <harinikatakamlinux@gmail.com>,
	<harini.katakam@xilinx.com>, Harini Katakam <harinik@xilinx.com>,
	Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>,
	Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
Subject: [PATCH 1/4] net: macb: Check MDIO state before read/write and use timeouts
Date: Wed, 31 Oct 2018 09:10:20 +0530	[thread overview]
Message-ID: <1540957223-30984-2-git-send-email-harini.katakam@xilinx.com> (raw)
In-Reply-To: <1540957223-30984-1-git-send-email-harini.katakam@xilinx.com>

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: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
Signed-off-by: Harini Katakam <harinik@xilinx.com>
---
Changes form RFC:
Cleaned up timeout implementation and moved it to a helper.

 drivers/net/ethernet/cadence/macb_main.c | 44 +++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 0acaef3..b4e26c1 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -318,10 +318,36 @@ static void macb_get_hwaddr(struct macb *bp)
 	eth_hw_addr_random(bp->dev);
 }
 
+static int macb_mdio_wait_for_idle(struct macb *bp)
+{
+	ulong timeout;
+
+	timeout = jiffies + msecs_to_jiffies(1000);
+	/* wait for end of transfer */
+	while (1) {
+		if (MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
+			break;
+
+		if (time_after_eq(jiffies, timeout)) {
+			netdev_err(bp->dev, "wait for end of transfer timed out\n");
+			return -ETIMEDOUT;
+		}
+
+		cpu_relax();
+	}
+
+	return 0;
+}
+
 static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 {
 	struct macb *bp = bus->priv;
 	int value;
+	int err;
+
+	err = macb_mdio_wait_for_idle(bp);
+	if (err < 0)
+		return err;
 
 	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
 			      | MACB_BF(RW, MACB_MAN_READ)
@@ -329,9 +355,9 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 			      | MACB_BF(REGA, regnum)
 			      | MACB_BF(CODE, MACB_MAN_CODE)));
 
-	/* wait for end of transfer */
-	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
-		cpu_relax();
+	err = macb_mdio_wait_for_idle(bp);
+	if (err < 0)
+		return err;
 
 	value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
 
@@ -342,6 +368,12 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 			   u16 value)
 {
 	struct macb *bp = bus->priv;
+	int err;
+
+
+	err = macb_mdio_wait_for_idle(bp);
+	if (err < 0)
+		return err;
 
 	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
 			      | MACB_BF(RW, MACB_MAN_WRITE)
@@ -350,9 +382,9 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 			      | MACB_BF(CODE, MACB_MAN_CODE)
 			      | MACB_BF(DATA, value)));
 
-	/* wait for end of transfer */
-	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
-		cpu_relax();
+	err = macb_mdio_wait_for_idle(bp);
+	if (err < 0)
+		return err;
 
 	return 0;
 }
-- 
2.7.4


  reply	other threads:[~2018-10-31  3:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31  3:40 [PATCH 0/4] Macb power management support for ZynqMP Harini Katakam
2018-10-31  3:40 ` Harini Katakam [this message]
2018-10-31 13:48   ` [PATCH 1/4] net: macb: Check MDIO state before read/write and use timeouts Andrew Lunn
2018-10-31 13:50     ` Harini Katakam
2018-10-31  3:40 ` [PATCH 2/4] net: macb: Support clock management for tsu_clk Harini Katakam
2018-10-31  3:40 ` [PATCH 3/4] net: macb: Add pm runtime support Harini Katakam
2018-10-31 14:54   ` Andrew Lunn
2018-10-31 15:10     ` Harini Katakam
2018-10-31 15:47       ` Andrew Lunn
2018-10-31 15:50         ` Harini Katakam
2018-10-31  3:40 ` [PATCH 4/4] net: macb: Add support for suspend/resume with full power down Harini Katakam
2018-10-31 14:58   ` Andrew Lunn
2018-10-31 15:01     ` Harini Katakam
2018-10-31 16:10   ` Claudiu.Beznea
2018-10-31 16:56     ` Harini Katakam

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=1540957223-30984-2-git-send-email-harini.katakam@xilinx.com \
    --to=harini.katakam@xilinx.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=davem@davemloft.net \
    --cc=harinik@xilinx.com \
    --cc=harinikatakamlinux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=sai.pavan.boddu@xilinx.com \
    --cc=shubhrajyoti.datta@xilinx.com \
    --subject='Re: [PATCH 1/4] 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).