mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] net: designware: socfpga: return error value
@ 2018-11-29 11:39 Steffen Trumtrar
  2018-11-29 11:39 ` [PATCH 2/4] net: designware: refactor wait loop to own function Steffen Trumtrar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2018-11-29 11:39 UTC (permalink / raw)
  To: Barebox List

Instead of silently dropping the return value of socfpga_dwc_set_phy_mode,
use it as the return value of the function, instead.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/net/designware_socfpga.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/designware_socfpga.c b/drivers/net/designware_socfpga.c
index cb88882d66a0..ff4b6a565559 100644
--- a/drivers/net/designware_socfpga.c
+++ b/drivers/net/designware_socfpga.c
@@ -158,9 +158,7 @@ static int socfpga_dwc_ether_probe(struct device_d *dev)
 	if (ret)
 		return ret;
 
-	socfpga_dwc_set_phy_mode(dwc_dev);
-
-	return 0;
+	return socfpga_dwc_set_phy_mode(dwc_dev);
 }
 
 static struct dw_eth_drvdata socfpga_stmmac_drvdata = {
-- 
2.19.2


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

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

* [PATCH 2/4] net: designware: refactor wait loop to own function
  2018-11-29 11:39 [PATCH 1/4] net: designware: socfpga: return error value Steffen Trumtrar
@ 2018-11-29 11:39 ` Steffen Trumtrar
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2018-11-29 11:39 UTC (permalink / raw)
  To: Barebox List

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

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

* [PATCH 3/4] net: designware: reorder execution of write and busy check
  2018-11-29 11:39 [PATCH 1/4] net: designware: socfpga: return error value Steffen Trumtrar
  2018-11-29 11:39 ` [PATCH 2/4] net: designware: refactor wait loop to own function Steffen Trumtrar
@ 2018-11-29 11:39 ` Steffen Trumtrar
  2018-11-29 11:39 ` [PATCH 4/4] net: designware: return error value in mii_write Steffen Trumtrar
  2 siblings, 0 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2018-11-29 11:39 UTC (permalink / raw)
  To: Barebox List

Instead of first writing to the MII register and then checking if the
MII operation is finished. Check if there is an ongoing operation and
then write to the MII register.

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

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 410658d67b39..104258e21c51 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -92,12 +92,12 @@ static int dwc_ether_mii_write(struct mii_bus *dev, int addr, int reg, u16 val)
 	miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
 		  ((reg << MIIREGSHIFT) & MII_REGMSK) | MII_WRITE;
 
-	writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
-
 	ret = dwc_wait_mii_idle(dev);
 	if (ret)
 		return ret;
 
+	writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
+
 	/* Needed as a fix for ST-Phy */
 	dwc_ether_mii_read(dev, addr, reg);
 	return 0;
-- 
2.19.2


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

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

* [PATCH 4/4] net: designware: return error value in mii_write
  2018-11-29 11:39 [PATCH 1/4] net: designware: socfpga: return error value Steffen Trumtrar
  2018-11-29 11:39 ` [PATCH 2/4] net: designware: refactor wait loop to own function Steffen Trumtrar
  2018-11-29 11:39 ` [PATCH 3/4] net: designware: reorder execution of write and busy check Steffen Trumtrar
@ 2018-11-29 11:39 ` Steffen Trumtrar
  2018-11-30  9:15   ` Sascha Hauer
  2 siblings, 1 reply; 5+ messages in thread
From: Steffen Trumtrar @ 2018-11-29 11:39 UTC (permalink / raw)
  To: Barebox List

Do not drop the error value and use it as a return value instead.

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

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 104258e21c51..cb7c4a13719c 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -99,8 +99,7 @@ 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);
 
 	/* Needed as a fix for ST-Phy */
-	dwc_ether_mii_read(dev, addr, reg);
-	return 0;
+	return dwc_ether_mii_read(dev, addr, reg);
 }
 
 
-- 
2.19.2


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

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

* Re: [PATCH 4/4] net: designware: return error value in mii_write
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2018-11-30  9:15 UTC (permalink / raw)
  To: Steffen Trumtrar; +Cc: Barebox List

On Thu, Nov 29, 2018 at 12:39:31PM +0100, Steffen Trumtrar wrote:
> Do not drop the error value and use it as a return value instead.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
>  drivers/net/designware.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/designware.c b/drivers/net/designware.c
> index 104258e21c51..cb7c4a13719c 100644
> --- a/drivers/net/designware.c
> +++ b/drivers/net/designware.c
> @@ -99,8 +99,7 @@ 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);
>  
>  	/* Needed as a fix for ST-Phy */
> -	dwc_ether_mii_read(dev, addr, reg);
> -	return 0;
> +	return dwc_ether_mii_read(dev, addr, reg);

dwc_ether_mii_read() normally returns the register value on success,
returning this from dwc_ether_mii_write() looks wrong.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2018-11-30  9:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29 11:39 [PATCH 1/4] net: designware: socfpga: return error value Steffen Trumtrar
2018-11-29 11:39 ` [PATCH 2/4] net: designware: refactor wait loop to own function Steffen Trumtrar
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox