Skip to contentSkip to conversation

net: stmmac: Use readl_poll_timeout() to simplify the code

PATCH In review Dejin Zheng 2 participants 4 messages Mar 16, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover net: stmmac: Use readl_poll_timeout() to simplify the code

This patch sets just for replace the open-coded loop to the readl_poll_timeout() helper macro for simplify the code in stmmac driver.

v2 -> v3:
- return whatever error code by readl_poll_timeout() returned.
v1 -> v2:
- no changed. I am a newbie and sent this patch a month ago (February 6th). So far, I have not received any comments or suggestion. I think it may be lost somewhere in the world, so resend it.

Dejin Zheng (2):
net: stmmac: use readl_poll_timeout() function in init_systime()
net: stmmac: use readl_poll_timeout() function in dwmac4_dma_reset()

 drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c  | 15 ++++-----------
 .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 15 ++++-----------
 2 files changed, 8 insertions(+), 22 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH v3 1/2 net: stmmac: use readl_poll_timeout() function in init_systime()

The init_systime() function use an open coded of readl_poll_timeout(). Replace the open coded handling with the proper function.

---
v2 -> v3:
- return whatever error code by readl_poll_timeout() returned.
v1 -> v2:
- no changed.

 .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +4 -11
index 020159622559..fcf080243a0f 100644
@@ -10,6 +10,7 @@
 *******************************************************************************/
 
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/delay.h>
 #include "common.h"
 #include "stmmac_ptp.h"
@@ -53,7 +54,6 @@ static void config_sub_second_increment(void __iomem *ioaddr,
 
 static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
 {
-	int limit;
 	u32 value;
 
 	writel(sec, ioaddr + PTP_STSUR);
@@ -64,16 +64,9 @@ static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
 	writel(value, ioaddr + PTP_TCR);
 
 	/* wait for present system time initialize to complete */
-	limit = 10;
-	while (limit--) {
-		if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSINIT))
-			break;
-		mdelay(10);
-	}
-	if (limit < 0)
-		return -EBUSY;
-
-	return 0;
+	return readl_poll_timeout(ioaddr + PTP_TCR, value,
+				 !(value & PTP_TCR_TSINIT),
+				 10000, 100000);
 }
 
 static int config_addend(void __iomem *ioaddr, u32 addend)
Signature · 1 line
2.25.0
#2 lore raw

PATCH v3 2/2 net: stmmac: use readl_poll_timeout() function in dwmac4_dma_reset()

In reply to Dejin Zheng

The dwmac4_dma_reset() function use an open coded of readl_poll_timeout(). Replace the open coded handling with the proper function.

---
v2 -> v3:
- return whatever error code by readl_poll_timeout() returned.
v1 -> v2:
- no changed.

 drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +4 -11
index 9becca280074..6e30d7eb4983 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/delay.h>
 #include "common.h"
 #include "dwmac4_dma.h"
@@ -14,22 +15,14 @@
 int dwmac4_dma_reset(void __iomem *ioaddr)
 {
 	u32 value = readl(ioaddr + DMA_BUS_MODE);
-	int limit;
 
 	/* DMA SW reset */
 	value |= DMA_BUS_MODE_SFT_RESET;
 	writel(value, ioaddr + DMA_BUS_MODE);
-	limit = 10;
-	while (limit--) {
-		if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
-			break;
-		mdelay(10);
-	}
-
-	if (limit < 0)
-		return -EBUSY;
 
-	return 0;
+	return readl_poll_timeout(ioaddr + DMA_BUS_MODE, value,
+				 !(value & DMA_BUS_MODE_SFT_RESET),
+				 10000, 100000);
 }
 
 void dwmac4_set_rx_tail_ptr(void __iomem *ioaddr, u32 tail_ptr, u32 chan)
Signature · 1 line
2.25.0
maintainer
#3 lore raw
In reply to Dejin Zheng

From: Dejin Zheng <[email protected]>
Date: Mon, 16 Mar 2020 10:32:52 +0800

Quoted 11 lines

This patch sets just for replace the open-coded loop to the readl_poll_timeout() helper macro for simplify the code in stmmac driver.

v2 -> v3:
- return whatever error code by readl_poll_timeout() returned.
v1 -> v2:
- no changed. I am a newbie and sent this patch a month ago (February 6th). So far, I have not received any comments or suggestion. I think it may be lost somewhere in the world, so resend it.

Looks good, series applied, thank you.