mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/4] net: designware: refactor wait loop to own function
Date: Thu, 29 Nov 2018 12:39:29 +0100	[thread overview]
Message-ID: <20181129113931.5045-2-s.trumtrar@pengutronix.de> (raw)
In-Reply-To: <20181129113931.5045-1-s.trumtrar@pengutronix.de>

The polling of the MII_BUSY bit is used three times. Instead of having the same
code in all three locations, move it to an inline function.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/net/designware.c | 45 ++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 49ddaa20d8be..410658d67b39 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -41,18 +41,11 @@
 #define HALF_DUPLEX		1
 #define FULL_DUPLEX		2
 
-
-static int dwc_ether_mii_read(struct mii_bus *dev, int addr, int reg)
+static inline int dwc_wait_mii_idle(struct mii_bus *dev)
 {
 	struct dw_eth_dev *priv = dev->priv;
 	struct eth_mac_regs *mac_p = priv->mac_regs_p;
 	u64 start;
-	u32 miiaddr;
-
-	miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
-		  ((reg << MIIREGSHIFT) & MII_REGMSK);
-
-	writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
 
 	start = get_time_ns();
 	while (readl(&mac_p->miiaddr) & MII_BUSY) {
@@ -61,6 +54,30 @@ static int dwc_ether_mii_read(struct mii_bus *dev, int addr, int reg)
 			return -EIO;
 		}
 	}
+
+	return 0;
+}
+
+static int dwc_ether_mii_read(struct mii_bus *dev, int addr, int reg)
+{
+	struct dw_eth_dev *priv = dev->priv;
+	struct eth_mac_regs *mac_p = priv->mac_regs_p;
+	u32 miiaddr;
+	int ret;
+
+	miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
+		  ((reg << MIIREGSHIFT) & MII_REGMSK);
+
+	ret = dwc_wait_mii_idle(dev);
+	if (ret)
+		return ret;
+
+	writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
+
+	ret = dwc_wait_mii_idle(dev);
+	if (ret)
+		return ret;
+
 	return readl(&mac_p->miidata) & 0xffff;
 }
 
@@ -68,8 +85,8 @@ static int dwc_ether_mii_write(struct mii_bus *dev, int addr, int reg, u16 val)
 {
 	struct dw_eth_dev *priv = dev->priv;
 	struct eth_mac_regs *mac_p = priv->mac_regs_p;
-	u64 start;
 	u32 miiaddr;
+	int ret;
 
 	writel(val, &mac_p->miidata);
 	miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
@@ -77,13 +94,9 @@ static int dwc_ether_mii_write(struct mii_bus *dev, int addr, int reg, u16 val)
 
 	writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
 
-	start = get_time_ns();
-	while (readl(&mac_p->miiaddr) & MII_BUSY) {
-		if (is_timeout(start, 10 * MSECOND)) {
-			dev_err(&priv->netdev.dev, "MDIO timeout\n");
-			return -EIO;
-		}
-	}
+	ret = dwc_wait_mii_idle(dev);
+	if (ret)
+		return ret;
 
 	/* Needed as a fix for ST-Phy */
 	dwc_ether_mii_read(dev, addr, reg);
-- 
2.19.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-11-29 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 11:39 [PATCH 1/4] net: designware: socfpga: return error value Steffen Trumtrar
2018-11-29 11:39 ` Steffen Trumtrar [this message]
2018-11-29 11:39 ` [PATCH 3/4] net: designware: reorder execution of write and busy check Steffen Trumtrar
2018-11-29 11:39 ` [PATCH 4/4] net: designware: return error value in mii_write Steffen Trumtrar
2018-11-30  9:15   ` Sascha Hauer

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=20181129113931.5045-2-s.trumtrar@pengutronix.de \
    --to=s.trumtrar@pengutronix.de \
    --cc=barebox@lists.infradead.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