net: stmmac: Use readl_poll_timeout() to simplify the code
Subsystems (4)
v2 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.
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 | 14 ++++++-------- .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.0
PATCH v2 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.
---
v1 -> v2:
- no changed.
.../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +6 -8
@@ -10,6 +10,7 @@*******************************************************************************/ #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/delay.h> #include "common.h" #include "stmmac_ptp.h"
@@ -53,8 +54,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,static int init_systime (void __iomem *ioaddr,u32 sec,u32 nsec) { -int limit;u32 value; +int err;writel (sec, ioaddr +PTP_STSUR );writel (nsec, ioaddr +PTP_STNSUR );
@@ -64,13 +65,10 @@ 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 ) + err =readl_poll_timeout (ioaddr +PTP_TCR , value, + !(value &PTP_TCR_TSINIT ), +10000 ,100000 ); +if (err)return -EBUSY ;return 0 ;
Signature · 1 line
2.25.0
PATCH v2 2/2 net: stmmac: use readl_poll_timeout() function in dwmac4_dma_reset()
In reply to Dejin ZhengThe dwmac4_dma_reset() function use an open coded of readl_poll_timeout(). Replace the open coded handling with the proper function.
---
v1 -> v2:
- no changed.
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +6 -8
@@ -6,6 +6,7 @@*/ #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/delay.h> #include "common.h" #include "dwmac4_dma.h"
@@ -14,19 +15,16 @@int dwmac4_dma_reset (void __iomem *ioaddr) {u32 value =readl (ioaddr +DMA_BUS_MODE ); -int limit; +int err;/* 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 ) + err =readl_poll_timeout (ioaddr +DMA_BUS_MODE , value, + !(value &DMA_BUS_MODE_SFT_RESET ), +10000 ,100000 ); +if (err)return -EBUSY ;return 0 ;
Signature · 1 line
2.25.0
Re: [PATCH net-next v2 1/2] net: stmmac: use readl_poll_timeout() function in init_systime()
In reply to Dejin ZhengQuoted 39 lines · Dejin Zheng
The
init_systime()function use an open coded ofreadl_poll_timeout(). Replace the open coded handling with the proper function.Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- no changed..../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +2
-3@@ -10,6 +10,7 @@*******************************************************************************/ #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/delay.h> #include "common.h" #include "stmmac_ptp.h" @@ -53,8 +54,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,static int init_systime (void __iomem *ioaddr,u32 sec,u32 nsec) { -int limit;u32 value; +int err;writel (sec, ioaddr +PTP_STSUR );writel (nsec, ioaddr +PTP_STNSUR );@@ -64,13 +65,10 @@ 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--) {
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec) · line 72
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +4
-5-if (!(readl (ioaddr +PTP_TCR ) &PTP_TCR_TSINIT )) -break ; -mdelay (10 ); - } -if (limit <0 ) + err =readl_poll_timeout (ioaddr +PTP_TCR , value, + !(value &PTP_TCR_TSINIT ), +10000 ,100000 ); +if (err)return -EBUSY ;
Hi Dejin
It is normal to just return whatever error code readl_poll_timeout() returned.
Andrew
David Miller
maintainerRe: [PATCH net-next v2 1/2] net: stmmac: use readl_poll_timeout() function in init_systime()
From: Andrew Lunn <[email protected]>
Date: Sun, 15 Mar 2020 19:25:04 +0100
Quoted 2 lines
It is normal to just return whatever error code
readl_poll_timeout()returned.
Agreed.
Re: [PATCH net-next v2 1/2] net: stmmac: use readl_poll_timeout() function in init_systime()
In reply to Andrew LunnOn Sun, Mar 15, 2020 at 07:25:04PM +0100, Andrew Lunn wrote:
Hi Andrew and David :
Quoted 53 lines · Dejin Zheng
Quoted 39 lines
The
init_systime()function use an open coded ofreadl_poll_timeout(). Replace the open coded handling with the proper function.Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- no changed..../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +2
-3@@ -10,6 +10,7 @@*******************************************************************************/ #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/delay.h> #include "common.h" #include "stmmac_ptp.h" @@ -53,8 +54,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,static int init_systime (void __iomem *ioaddr,u32 sec,u32 nsec) { -int limit;u32 value; +int err;writel (sec, ioaddr +PTP_STSUR );writel (nsec, ioaddr +PTP_STNSUR );@@ -64,13 +65,10 @@ 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--) {drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec) · line 72
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +4
-5-if (!(readl (ioaddr +PTP_TCR ) &PTP_TCR_TSINIT )) -break ; -mdelay (10 ); - } -if (limit <0 ) + err =readl_poll_timeout (ioaddr +PTP_TCR , value, + !(value &PTP_TCR_TSINIT ), +10000 ,100000 ); +if (err)return -EBUSY ;Hi Dejin
Quoted 4 lines
It is normal to just return whatever error code
readl_poll_timeout()returned.Andrew
You are right. I will modify it. Thanks!
BR,
Dejin