* [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic()
@ 2020-09-10 8:21 Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 02/11] usb: early: ehci-dbgp: " Chunfeng Yun
` (10 more replies)
0 siblings, 11 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Gustavo A. R. Silva, Douglas Anderson, Saurav Girepunje,
Lee Jones, Daniel Thompson, Mathias Nyman, Jann Horn, Ben Dooks,
Chunfeng Yun, Arnd Bergmann, Sumit Garg, Chuhong Yuan,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Felipe Balbi,
Mathias Nyman, Jason Yan, linux-usb, linux-kernel,
Eric W. Biederman, Lu Baolu
Use readl_poll_timeout_atomic() to simplify code
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/early/xhci-dbc.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index c050776..be4ecba 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -14,6 +14,7 @@
#include <linux/pci_ids.h>
#include <linux/memblock.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <asm/pci-direct.h>
#include <asm/fixmap.h>
#include <linux/bcd.h>
@@ -135,16 +136,9 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done, int wait, int delay)
{
u32 result;
- do {
- result = readl(ptr);
- result &= mask;
- if (result == done)
- return 0;
- udelay(delay);
- wait -= delay;
- } while (wait > 0);
-
- return -ETIMEDOUT;
+ return readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done),
+ delay, wait);
}
static void __init xdbc_bios_handoff(void)
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 02/11] usb: early: ehci-dbgp: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 03/11] usb: pci-quirks: " Chunfeng Yun
` (9 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Petr Mladek, Lee Jones, Ben Dooks,
linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/early/ehci-dbgp.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index b075dbf..45b42d8 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -15,6 +15,7 @@
#include <linux/console.h>
#include <linux/errno.h>
#include <linux/init.h>
+#include <linux/iopoll.h>
#include <linux/pci_regs.h>
#include <linux/pci_ids.h>
#include <linux/usb/ch9.h>
@@ -161,17 +162,11 @@ static inline u32 dbgp_pid_read_update(u32 x, u32 tok)
static int dbgp_wait_until_complete(void)
{
u32 ctrl;
- int loop = DBGP_TIMEOUT;
-
- do {
- ctrl = readl(&ehci_debug->control);
- /* Stop when the transaction is finished */
- if (ctrl & DBGP_DONE)
- break;
- udelay(1);
- } while (--loop > 0);
+ int ret;
- if (!loop)
+ ret = readl_poll_timeout_atomic(&ehci_debug->control, ctrl,
+ (ctrl & DBGP_DONE), 1, DBGP_TIMEOUT);
+ if (ret)
return -DBGP_TIMEOUT;
/*
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 03/11] usb: pci-quirks: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 02/11] usb: early: ehci-dbgp: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 04/11] usb: xhci-rcar: " Chunfeng Yun
` (8 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, linux-kernel,
Jann Horn, Chuhong Yuan, Douglas Anderson, Gustavo A. R. Silva,
Saurav Girepunje, Chunfeng Yun, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/host/pci-quirks.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index b8961c0..8920566 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -16,6 +16,7 @@
#include <linux/export.h>
#include <linux/acpi.h>
#include <linux/dmi.h>
+#include <linux/iopoll.h>
#include <soc/bcm2835/raspberrypi-firmware.h>
@@ -1012,15 +1013,9 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
{
u32 result;
- do {
- result = readl(ptr);
- result &= mask;
- if (result == done)
- return 0;
- udelay(delay_usec);
- wait_usec -= delay_usec;
- } while (wait_usec > 0);
- return -ETIMEDOUT;
+ return readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done),
+ delay_usec, wait_usec);
}
/*
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 02/11] usb: early: ehci-dbgp: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 03/11] usb: pci-quirks: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 12:56 ` Yoshihiro Shimoda
2020-09-10 13:12 ` Daniel Thompson
2020-09-10 8:21 ` [PATCH RESEND v3 05/11] usb: oxu210hp-hcd: " Chunfeng Yun
` (7 subsequent siblings)
10 siblings, 2 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Gustavo A. R. Silva, Douglas Anderson, Saurav Girepunje,
Lee Jones, Daniel Thompson, Mathias Nyman, Jann Horn, Ben Dooks,
Chunfeng Yun, Arnd Bergmann, Sumit Garg, Chuhong Yuan,
linux-mediatek, Matthias Brugger, linux-arm-kernel, Felipe Balbi,
Mathias Nyman, Jason Yan, Yoshihiro Shimoda, linux-usb,
linux-kernel, Eric W. Biederman
Use readl_poll_timeout_atomic() to simplify code
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
1 file changed, 12 insertions(+), 31 deletions(-)
diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index c1025d3..74f836f 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -6,6 +6,7 @@
*/
#include <linux/firmware.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
@@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
void __iomem *regs = hcd->regs;
struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
const struct firmware *fw;
- int retval, index, j, time;
- int timeout = 10000;
+ int retval, index, j;
u32 data, val, temp;
u32 quirks = 0;
const struct soc_device_attribute *attr;
@@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
writel(temp, regs + RCAR_USB3_DL_CTRL);
- for (time = 0; time < timeout; time++) {
- val = readl(regs + RCAR_USB3_DL_CTRL);
- if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
- break;
- udelay(1);
- }
- if (time == timeout) {
- retval = -ETIMEDOUT;
+ retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
+ val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
+ 1, 10000);
+ if (retval < 0)
break;
- }
}
temp = readl(regs + RCAR_USB3_DL_CTRL);
temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
writel(temp, regs + RCAR_USB3_DL_CTRL);
- for (time = 0; time < timeout; time++) {
- val = readl(regs + RCAR_USB3_DL_CTRL);
- if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
- retval = 0;
- break;
- }
- udelay(1);
- }
- if (time == timeout)
- retval = -ETIMEDOUT;
+ retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
+ val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
release_firmware(fw);
@@ -200,18 +187,12 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
{
- int timeout = 1000;
+ int retval;
u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
- while (timeout > 0) {
- val = readl(hcd->regs + RCAR_USB3_AXH_STA);
- if ((val & mask) == mask)
- return true;
- udelay(1);
- timeout--;
- }
-
- return false;
+ retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
+ val, ((val & mask) == mask), 1, 1000);
+ return !!retval;
}
/* This function needs to initialize a "phy" of usb before */
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 05/11] usb: oxu210hp-hcd: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (2 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 04/11] usb: xhci-rcar: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 06/11] usb: fotg210-hcd: " Chunfeng Yun
` (6 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/host/oxu210hp-hcd.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index cfa7dd2..27dbbe1 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -24,6 +24,7 @@
#include <linux/moduleparam.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <asm/irq.h>
#include <asm/unaligned.h>
@@ -748,18 +749,16 @@ static int handshake(struct oxu_hcd *oxu, void __iomem *ptr,
u32 mask, u32 done, int usec)
{
u32 result;
+ int ret;
- do {
- result = readl(ptr);
- if (result == ~(u32)0) /* card removed */
- return -ENODEV;
- result &= mask;
- if (result == done)
- return 0;
- udelay(1);
- usec--;
- } while (usec > 0);
- return -ETIMEDOUT;
+ ret = readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done ||
+ result == U32_MAX),
+ 1, usec);
+ if (result == U32_MAX) /* card removed */
+ return -ENODEV;
+
+ return ret;
}
/* Force HC to halt state from unknown (EHCI spec section 2.3) */
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 06/11] usb: fotg210-hcd: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (3 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 05/11] usb: oxu210hp-hcd: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 07/11] usb: isp1760-hcd: " Chunfeng Yun
` (5 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/host/fotg210-hcd.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index 194df82..1d94fcf 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -32,6 +32,7 @@
#include <linux/uaccess.h>
#include <linux/platform_device.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/clk.h>
#include <asm/byteorder.h>
@@ -883,18 +884,15 @@ static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
u32 mask, u32 done, int usec)
{
u32 result;
+ int ret;
- do {
- result = fotg210_readl(fotg210, ptr);
- if (result == ~(u32)0) /* card removed */
- return -ENODEV;
- result &= mask;
- if (result == done)
- return 0;
- udelay(1);
- usec--;
- } while (usec > 0);
- return -ETIMEDOUT;
+ ret = readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done ||
+ result == U32_MAX), 1, usec);
+ if (result == U32_MAX) /* card removed */
+ return -ENODEV;
+
+ return ret;
}
/* Force HC to halt state from unknown (EHCI spec section 2.3).
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 07/11] usb: isp1760-hcd: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (4 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 06/11] usb: fotg210-hcd: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 08/11] usb: phy-ulpi-viewport: " Chunfeng Yun
` (4 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/isp1760/isp1760-hcd.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c
index dd74ab7a..33ae656 100644
--- a/drivers/usb/isp1760/isp1760-hcd.c
+++ b/drivers/usb/isp1760/isp1760-hcd.c
@@ -22,6 +22,7 @@
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/mm.h>
#include <linux/timer.h>
#include <asm/unaligned.h>
@@ -380,18 +381,15 @@ static int handshake(struct usb_hcd *hcd, u32 reg,
u32 mask, u32 done, int usec)
{
u32 result;
+ int ret;
+
+ ret = readl_poll_timeout_atomic(hcd->regs + reg, result,
+ ((result & mask) == done ||
+ result == U32_MAX), 1, usec);
+ if (result == U32_MAX)
+ return -ENODEV;
- do {
- result = reg_read32(hcd->regs, reg);
- if (result == ~0)
- return -ENODEV;
- result &= mask;
- if (result == done)
- return 0;
- udelay(1);
- usec--;
- } while (usec > 0);
- return -ETIMEDOUT;
+ return ret;
}
/* reset a non-running (STS_HALT == 1) controller */
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 08/11] usb: phy-ulpi-viewport: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (5 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 07/11] usb: isp1760-hcd: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 09/11] usb: phy: phy-mv-usb: " Chunfeng Yun
` (3 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2~v3: no changes
---
drivers/usb/phy/phy-ulpi-viewport.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/phy/phy-ulpi-viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c
index 7a14e0e..0f61e32 100644
--- a/drivers/usb/phy/phy-ulpi-viewport.c
+++ b/drivers/usb/phy/phy-ulpi-viewport.c
@@ -7,6 +7,7 @@
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/usb/otg.h>
#include <linux/usb/ulpi.h>
@@ -20,16 +21,9 @@
static int ulpi_viewport_wait(void __iomem *view, u32 mask)
{
- unsigned long usec = 2000;
+ u32 val;
- while (usec--) {
- if (!(readl(view) & mask))
- return 0;
-
- udelay(1);
- }
-
- return -ETIMEDOUT;
+ return readl_poll_timeout_atomic(view, val, !(val & mask), 1, 2000);
}
static int ulpi_viewport_read(struct usb_phy *otg, u32 reg)
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 09/11] usb: phy: phy-mv-usb: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (6 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 08/11] usb: phy-ulpi-viewport: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 10/11] usb: udc: net2280: " Chunfeng Yun
` (2 subsequent siblings)
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v3: re-align argument of log suggested by Sergei
v2: udelay 10us instead of 20us according to kerneldoc
---
drivers/usb/phy/phy-mv-usb.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c
index ce767ec..576d925 100644
--- a/drivers/usb/phy/phy-mv-usb.c
+++ b/drivers/usb/phy/phy-mv-usb.c
@@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/proc_fs.h>
@@ -135,8 +136,8 @@ static int mv_otg_set_timer(struct mv_otg *mvotg, unsigned int id,
static int mv_otg_reset(struct mv_otg *mvotg)
{
- unsigned int loops;
u32 tmp;
+ int ret;
/* Stop the controller */
tmp = readl(&mvotg->op_regs->usbcmd);
@@ -146,15 +147,12 @@ static int mv_otg_reset(struct mv_otg *mvotg)
/* Reset the controller to get default values */
writel(USBCMD_CTRL_RESET, &mvotg->op_regs->usbcmd);
- loops = 500;
- while (readl(&mvotg->op_regs->usbcmd) & USBCMD_CTRL_RESET) {
- if (loops == 0) {
- dev_err(&mvotg->pdev->dev,
- "Wait for RESET completed TIMEOUT\n");
- return -ETIMEDOUT;
- }
- loops--;
- udelay(20);
+ ret = readl_poll_timeout_atomic(&mvotg->op_regs->usbcmd, tmp,
+ (tmp & USBCMD_CTRL_RESET), 10, 10000);
+ if (ret < 0) {
+ dev_err(&mvotg->pdev->dev,
+ "Wait for RESET completed TIMEOUT\n");
+ return ret;
}
writel(0x0, &mvotg->op_regs->usbintr);
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 10/11] usb: udc: net2280: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (7 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 09/11] usb: phy: phy-mv-usb: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 11/11] iopoll: update kerneldoc of read_poll_timeout_atomic() Chunfeng Yun
2020-09-10 10:49 ` [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Jann Horn
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Alan Stern, Lee Jones, Ben Dooks,
linux-arm-kernel
Use readl_poll_timeout_atomic() to simplify code
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
---
v3: no changes
v2: add Acked-by Alan
---
drivers/usb/gadget/udc/net2280.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 7530bd9..f1a21f4 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -52,6 +52,7 @@
#include <linux/usb/gadget.h>
#include <linux/prefetch.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <asm/byteorder.h>
#include <asm/irq.h>
@@ -360,18 +361,16 @@ static inline void enable_pciirqenb(struct net2280_ep *ep)
static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec)
{
u32 result;
+ int ret;
- do {
- result = readl(ptr);
- if (result == ~(u32)0) /* "device unplugged" */
- return -ENODEV;
- result &= mask;
- if (result == done)
- return 0;
- udelay(1);
- usec--;
- } while (usec > 0);
- return -ETIMEDOUT;
+ ret = readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done ||
+ result == U32_MAX),
+ 1, usec);
+ if (result == U32_MAX) /* device unplugged */
+ return -ENODEV;
+
+ return ret;
}
static const struct usb_ep_ops net2280_ep_ops;
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH RESEND v3 11/11] iopoll: update kerneldoc of read_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (8 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 10/11] usb: udc: net2280: " Chunfeng Yun
@ 2020-09-10 8:21 ` Chunfeng Yun
2020-09-10 10:49 ` [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Jann Horn
10 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-10 8:21 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Arnd Bergmann,
Mathias Nyman, Sumit Garg, linux-kernel, Jann Horn, Chuhong Yuan,
Douglas Anderson, Gustavo A. R. Silva, Saurav Girepunje,
Chunfeng Yun, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Alan Stern, Lee Jones, Ben Dooks,
linux-arm-kernel
Arguments description of read_poll_timeout_atomic() is out of date,
update it.
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v3: fix typo in commit message suggested by Sergei
v2: new patch, suggested by Alan
---
include/linux/iopoll.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index bc89ac6..2c8860e 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -60,8 +60,7 @@
/**
* read_poll_timeout_atomic - Periodically poll an address until a condition is
* met or a timeout occurs
- * @op: accessor function (takes @addr as its only argument)
- * @addr: Address to poll
+ * @op: accessor function (takes @args as its arguments)
* @val: Variable to read the value into
* @cond: Break condition (usually involving @val)
* @delay_us: Time to udelay between reads in us (0 tight-loops). Should
@@ -69,6 +68,7 @@
* Documentation/timers/timers-howto.rst).
* @timeout_us: Timeout in us, 0 means never timeout
* @delay_before_read: if it is true, delay @delay_us before read.
+ * @args: arguments for @op poll
*
* Returns 0 on success and -ETIMEDOUT upon a timeout. In either
* case, the last read value at @args is stored in @val.
--
1.9.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
` (9 preceding siblings ...)
2020-09-10 8:21 ` [PATCH RESEND v3 11/11] iopoll: update kerneldoc of read_poll_timeout_atomic() Chunfeng Yun
@ 2020-09-10 10:49 ` Jann Horn
10 siblings, 0 replies; 24+ messages in thread
From: Jann Horn @ 2020-09-10 10:49 UTC (permalink / raw)
To: Chunfeng Yun
Cc: Linux ARM, Felipe Balbi, Daniel Thompson, linux-usb,
Mathias Nyman, Arnd Bergmann, Mathias Nyman, Sumit Garg,
Greg Kroah-Hartman, Jason Yan, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Ben Dooks, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, kernel list,
Lu Baolu
On Thu, Sep 10, 2020 at 10:24 AM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
> Use readl_poll_timeout_atomic() to simplify code
>
> Cc: Lu Baolu <baolu.lu@linux.intel.com>
> Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: Jann Horn <jannh@google.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 ` [PATCH RESEND v3 04/11] usb: xhci-rcar: " Chunfeng Yun
@ 2020-09-10 12:56 ` Yoshihiro Shimoda
2020-09-11 2:21 ` Chunfeng Yun
2020-09-10 13:12 ` Daniel Thompson
1 sibling, 1 reply; 24+ messages in thread
From: Yoshihiro Shimoda @ 2020-09-10 12:56 UTC (permalink / raw)
To: Chunfeng Yun, Greg Kroah-Hartman
Cc: Felipe Balbi, Daniel Thompson, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, linux-kernel,
Jann Horn, Chuhong Yuan, Douglas Anderson, Gustavo A. R. Silva,
Saurav Girepunje, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-arm-kernel
Hi Chunfeng,
Thank you for the patch!
> From: Chunfeng Yun, Sent: Thursday, September 10, 2020 5:22 PM
>
> Use readl_poll_timeout_atomic() to simplify code
>
> Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
> v2~v3: no changes
> ---
> drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> 1 file changed, 12 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> index c1025d3..74f836f 100644
> --- a/drivers/usb/host/xhci-rcar.c
> +++ b/drivers/usb/host/xhci-rcar.c
> @@ -6,6 +6,7 @@
> */
>
> #include <linux/firmware.h>
> +#include <linux/iopoll.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/of.h>
> @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> void __iomem *regs = hcd->regs;
> struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> const struct firmware *fw;
> - int retval, index, j, time;
> - int timeout = 10000;
> + int retval, index, j;
> u32 data, val, temp;
> u32 quirks = 0;
> const struct soc_device_attribute *attr;
> @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> writel(temp, regs + RCAR_USB3_DL_CTRL);
>
> - for (time = 0; time < timeout; time++) {
> - val = readl(regs + RCAR_USB3_DL_CTRL);
> - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> - break;
> - udelay(1);
> - }
> - if (time == timeout) {
> - retval = -ETIMEDOUT;
> + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> + 1, 10000);
> + if (retval < 0)
> break;
> - }
> }
>
> temp = readl(regs + RCAR_USB3_DL_CTRL);
> temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> writel(temp, regs + RCAR_USB3_DL_CTRL);
>
> - for (time = 0; time < timeout; time++) {
> - val = readl(regs + RCAR_USB3_DL_CTRL);
> - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> - retval = 0;
> - break;
> - }
> - udelay(1);
> - }
> - if (time == timeout)
> - retval = -ETIMEDOUT;
> + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
Some parentheses are not needed like below:
retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000);
> release_firmware(fw);
>
> @@ -200,18 +187,12 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
>
> static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
> {
> - int timeout = 1000;
> + int retval;
> u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
>
> - while (timeout > 0) {
> - val = readl(hcd->regs + RCAR_USB3_AXH_STA);
> - if ((val & mask) == mask)
> - return true;
> - udelay(1);
> - timeout--;
> - }
> -
> - return false;
> + retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
> + val, ((val & mask) == mask), 1, 1000);
Likewise above:
retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
val, (val & mask) == mask, 1, 1000);
> + return !!retval;
This breaks the code. If I changed this to "return retval < 0 ? false : true;",
it works again.
Best regards,
Yoshihiro Shimoda
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-10 8:21 ` [PATCH RESEND v3 04/11] usb: xhci-rcar: " Chunfeng Yun
2020-09-10 12:56 ` Yoshihiro Shimoda
@ 2020-09-10 13:12 ` Daniel Thompson
2020-09-11 2:33 ` Chunfeng Yun
1 sibling, 1 reply; 24+ messages in thread
From: Daniel Thompson @ 2020-09-10 13:12 UTC (permalink / raw)
To: Chunfeng Yun
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Yoshihiro Shimoda, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> Use readl_poll_timeout_atomic() to simplify code
>
> Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
> v2~v3: no changes
> ---
> drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> 1 file changed, 12 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> index c1025d3..74f836f 100644
> --- a/drivers/usb/host/xhci-rcar.c
> +++ b/drivers/usb/host/xhci-rcar.c
> @@ -6,6 +6,7 @@
> */
>
> #include <linux/firmware.h>
> +#include <linux/iopoll.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/of.h>
> @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> void __iomem *regs = hcd->regs;
> struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> const struct firmware *fw;
> - int retval, index, j, time;
> - int timeout = 10000;
> + int retval, index, j;
> u32 data, val, temp;
> u32 quirks = 0;
> const struct soc_device_attribute *attr;
> @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> writel(temp, regs + RCAR_USB3_DL_CTRL);
>
> - for (time = 0; time < timeout; time++) {
> - val = readl(regs + RCAR_USB3_DL_CTRL);
> - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> - break;
> - udelay(1);
> - }
> - if (time == timeout) {
> - retval = -ETIMEDOUT;
> + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> + 1, 10000);
> + if (retval < 0)
> break;
> - }
> }
>
> temp = readl(regs + RCAR_USB3_DL_CTRL);
> temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> writel(temp, regs + RCAR_USB3_DL_CTRL);
>
> - for (time = 0; time < timeout; time++) {
> - val = readl(regs + RCAR_USB3_DL_CTRL);
> - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> - retval = 0;
> - break;
> - }
> - udelay(1);
> - }
> - if (time == timeout)
> - retval = -ETIMEDOUT;
> + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
Directly assigning to retval at this point will clobber a previous
-ETIMEDOUT error.
In other words if there is a timeout waiting for FW_SET_DATA0, but not for
DW_SUCCESS, then we will return the wrong return value.
Daniel.
>
> release_firmware(fw);
>
> @@ -200,18 +187,12 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
>
> static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
> {
> - int timeout = 1000;
> + int retval;
> u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
>
> - while (timeout > 0) {
> - val = readl(hcd->regs + RCAR_USB3_AXH_STA);
> - if ((val & mask) == mask)
> - return true;
> - udelay(1);
> - timeout--;
> - }
> -
> - return false;
> + retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
> + val, ((val & mask) == mask), 1, 1000);
> + return !!retval;
This function returns a bool so !! is either wrong or redundant... I
think in this case it is wrong and should be a single ! .
Daniel.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-10 12:56 ` Yoshihiro Shimoda
@ 2020-09-11 2:21 ` Chunfeng Yun
0 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-11 2:21 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: linux-arm-kernel, Felipe Balbi, Daniel Thompson, linux-usb,
Mathias Nyman, Arnd Bergmann, Mathias Nyman, Sumit Garg,
Greg Kroah-Hartman, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Thu, 2020-09-10 at 12:56 +0000, Yoshihiro Shimoda wrote:
> Hi Chunfeng,
>
> Thank you for the patch!
>
> > From: Chunfeng Yun, Sent: Thursday, September 10, 2020 5:22 PM
> >
> > Use readl_poll_timeout_atomic() to simplify code
> >
> > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> > v2~v3: no changes
> > ---
> > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > 1 file changed, 12 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > index c1025d3..74f836f 100644
> > --- a/drivers/usb/host/xhci-rcar.c
> > +++ b/drivers/usb/host/xhci-rcar.c
> > @@ -6,6 +6,7 @@
> > */
> >
> > #include <linux/firmware.h>
> > +#include <linux/iopoll.h>
> > #include <linux/module.h>
> > #include <linux/platform_device.h>
> > #include <linux/of.h>
> > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > void __iomem *regs = hcd->regs;
> > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > const struct firmware *fw;
> > - int retval, index, j, time;
> > - int timeout = 10000;
> > + int retval, index, j;
> > u32 data, val, temp;
> > u32 quirks = 0;
> > const struct soc_device_attribute *attr;
> > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > writel(temp, regs + RCAR_USB3_DL_CTRL);
> >
> > - for (time = 0; time < timeout; time++) {
> > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > - break;
> > - udelay(1);
> > - }
> > - if (time == timeout) {
> > - retval = -ETIMEDOUT;
> > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > + 1, 10000);
> > + if (retval < 0)
> > break;
> > - }
> > }
> >
> > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > writel(temp, regs + RCAR_USB3_DL_CTRL);
> >
> > - for (time = 0; time < timeout; time++) {
> > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > - retval = 0;
> > - break;
> > - }
> > - udelay(1);
> > - }
> > - if (time == timeout)
> > - retval = -ETIMEDOUT;
> > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
>
> Some parentheses are not needed like below:
>
> retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000);
>
Ok, will modify it
>
> > release_firmware(fw);
> >
> > @@ -200,18 +187,12 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> >
> > static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
> > {
> > - int timeout = 1000;
> > + int retval;
> > u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
> >
> > - while (timeout > 0) {
> > - val = readl(hcd->regs + RCAR_USB3_AXH_STA);
> > - if ((val & mask) == mask)
> > - return true;
> > - udelay(1);
> > - timeout--;
> > - }
> > -
> > - return false;
> > + retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
> > + val, ((val & mask) == mask), 1, 1000);
>
> Likewise above:
> retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
> val, (val & mask) == mask, 1, 1000);
>
> > + return !!retval;
>
> This breaks the code. If I changed this to "return retval < 0 ? false : true;",
> it works again.
Oops, my bad, will fix it
Thanks a lot
>
> Best regards,
> Yoshihiro Shimoda
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-10 13:12 ` Daniel Thompson
@ 2020-09-11 2:33 ` Chunfeng Yun
2020-09-11 3:13 ` Yoshihiro Shimoda
2020-09-11 8:34 ` Daniel Thompson
0 siblings, 2 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-11 2:33 UTC (permalink / raw)
To: Daniel Thompson, Yoshihiro Shimoda
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Yoshihiro Shimoda, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > Use readl_poll_timeout_atomic() to simplify code
> >
> > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> > v2~v3: no changes
> > ---
> > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > 1 file changed, 12 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > index c1025d3..74f836f 100644
> > --- a/drivers/usb/host/xhci-rcar.c
> > +++ b/drivers/usb/host/xhci-rcar.c
> > @@ -6,6 +6,7 @@
> > */
> >
> > #include <linux/firmware.h>
> > +#include <linux/iopoll.h>
> > #include <linux/module.h>
> > #include <linux/platform_device.h>
> > #include <linux/of.h>
> > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > void __iomem *regs = hcd->regs;
> > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > const struct firmware *fw;
> > - int retval, index, j, time;
> > - int timeout = 10000;
> > + int retval, index, j;
> > u32 data, val, temp;
> > u32 quirks = 0;
> > const struct soc_device_attribute *attr;
> > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > writel(temp, regs + RCAR_USB3_DL_CTRL);
> >
> > - for (time = 0; time < timeout; time++) {
> > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > - break;
> > - udelay(1);
> > - }
> > - if (time == timeout) {
> > - retval = -ETIMEDOUT;
> > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > + 1, 10000);
> > + if (retval < 0)
> > break;
> > - }
> > }
> >
> > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > writel(temp, regs + RCAR_USB3_DL_CTRL);
> >
> > - for (time = 0; time < timeout; time++) {
> > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > - retval = 0;
> > - break;
> > - }
> > - udelay(1);
> > - }
> > - if (time == timeout)
> > - retval = -ETIMEDOUT;
> > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
>
> Directly assigning to retval at this point will clobber a previous
> -ETIMEDOUT error.
>
> In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> DW_SUCCESS, then we will return the wrong return value.
Yes, agree with you, but seems I keep its original logic unchanged.
Hi Yoshihiro,
What do think about Daniel's suggestion? should I fix it up?
>
>
> Daniel.
>
>
> >
> > release_firmware(fw);
> >
> > @@ -200,18 +187,12 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> >
> > static bool xhci_rcar_wait_for_pll_active(struct usb_hcd *hcd)
> > {
> > - int timeout = 1000;
> > + int retval;
> > u32 val, mask = RCAR_USB3_AXH_STA_PLL_ACTIVE_MASK;
> >
> > - while (timeout > 0) {
> > - val = readl(hcd->regs + RCAR_USB3_AXH_STA);
> > - if ((val & mask) == mask)
> > - return true;
> > - udelay(1);
> > - timeout--;
> > - }
> > -
> > - return false;
> > + retval = readl_poll_timeout_atomic(hcd->regs + RCAR_USB3_AXH_STA,
> > + val, ((val & mask) == mask), 1, 1000);
> > + return !!retval;
>
> This function returns a bool so !! is either wrong or redundant... I
> think in this case it is wrong and should be a single ! .
Yes, will fix it
Thanks a lot
>
>
> Daniel.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 2:33 ` Chunfeng Yun
@ 2020-09-11 3:13 ` Yoshihiro Shimoda
2020-09-11 4:12 ` Chunfeng Yun
2020-09-11 8:34 ` Daniel Thompson
1 sibling, 1 reply; 24+ messages in thread
From: Yoshihiro Shimoda @ 2020-09-11 3:13 UTC (permalink / raw)
To: Chunfeng Yun, Daniel Thompson
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Jann Horn, Chuhong Yuan, Douglas Anderson, Gustavo A. R. Silva,
Saurav Girepunje, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-kernel
Hi Daniel, Chunfeng,
> From: Chunfeng Yun, Sent: Friday, September 11, 2020 11:33 AM
>
> On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > Use readl_poll_timeout_atomic() to simplify code
> > >
> > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > ---
> > > v2~v3: no changes
> > > ---
> > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > >
> > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > index c1025d3..74f836f 100644
> > > --- a/drivers/usb/host/xhci-rcar.c
> > > +++ b/drivers/usb/host/xhci-rcar.c
> > > @@ -6,6 +6,7 @@
> > > */
> > >
> > > #include <linux/firmware.h>
> > > +#include <linux/iopoll.h>
> > > #include <linux/module.h>
> > > #include <linux/platform_device.h>
> > > #include <linux/of.h>
> > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > void __iomem *regs = hcd->regs;
> > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > const struct firmware *fw;
> > > - int retval, index, j, time;
> > > - int timeout = 10000;
> > > + int retval, index, j;
> > > u32 data, val, temp;
> > > u32 quirks = 0;
> > > const struct soc_device_attribute *attr;
> > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > >
> > > - for (time = 0; time < timeout; time++) {
> > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > - break;
> > > - udelay(1);
> > > - }
> > > - if (time == timeout) {
> > > - retval = -ETIMEDOUT;
> > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > + 1, 10000);
> > > + if (retval < 0)
> > > break;
> > > - }
> > > }
> > >
> > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > >
> > > - for (time = 0; time < timeout; time++) {
> > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > - retval = 0;
> > > - break;
> > > - }
> > > - udelay(1);
> > > - }
> > > - if (time == timeout)
> > > - retval = -ETIMEDOUT;
> > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> >
> > Directly assigning to retval at this point will clobber a previous
> > -ETIMEDOUT error.
> >
> > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > DW_SUCCESS, then we will return the wrong return value.
Thank you for your comment! I didn't realized this.
> Yes, agree with you, but seems I keep its original logic unchanged.
> Hi Yoshihiro,
>
> What do think about Daniel's suggestion? should I fix it up?
I think you should fix it up like below:
if (readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000) < 0)
retval = -ETIMEOUT; /* Overwrite retval if timeout occurred */
Otherwise, the xhci_rcar_download_firmware() cannot return -ETIMEDOUT if
timeout happened on the previous poll [1].
[1]
+ retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
+ val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
+ 1, 10000);
Best regards,
Yoshihiro Shimoda
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 3:13 ` Yoshihiro Shimoda
@ 2020-09-11 4:12 ` Chunfeng Yun
2020-09-11 4:57 ` Yoshihiro Shimoda
0 siblings, 1 reply; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-11 4:12 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: linux-arm-kernel, Felipe Balbi, Daniel Thompson, linux-usb,
Mathias Nyman, Arnd Bergmann, Mathias Nyman, Sumit Garg,
Greg Kroah-Hartman, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Fri, 2020-09-11 at 03:13 +0000, Yoshihiro Shimoda wrote:
> Hi Daniel, Chunfeng,
>
> > From: Chunfeng Yun, Sent: Friday, September 11, 2020 11:33 AM
> >
> > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > Use readl_poll_timeout_atomic() to simplify code
> > > >
> > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > ---
> > > > v2~v3: no changes
> > > > ---
> > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > >
> > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > index c1025d3..74f836f 100644
> > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > @@ -6,6 +6,7 @@
> > > > */
> > > >
> > > > #include <linux/firmware.h>
> > > > +#include <linux/iopoll.h>
> > > > #include <linux/module.h>
> > > > #include <linux/platform_device.h>
> > > > #include <linux/of.h>
> > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > void __iomem *regs = hcd->regs;
> > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > const struct firmware *fw;
> > > > - int retval, index, j, time;
> > > > - int timeout = 10000;
> > > > + int retval, index, j;
> > > > u32 data, val, temp;
> > > > u32 quirks = 0;
> > > > const struct soc_device_attribute *attr;
> > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > >
> > > > - for (time = 0; time < timeout; time++) {
> > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > - break;
> > > > - udelay(1);
> > > > - }
> > > > - if (time == timeout) {
> > > > - retval = -ETIMEDOUT;
> > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > + 1, 10000);
> > > > + if (retval < 0)
How about free firmware and return error number here ? instead of break
> > > > break;
> > > > - }
> > > > }
> > > >
> > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > >
> > > > - for (time = 0; time < timeout; time++) {
> > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > - retval = 0;
> > > > - break;
> > > > - }
> > > > - udelay(1);
> > > > - }
> > > > - if (time == timeout)
> > > > - retval = -ETIMEDOUT;
> > > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> > >
> > > Directly assigning to retval at this point will clobber a previous
> > > -ETIMEDOUT error.
> > >
> > > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > > DW_SUCCESS, then we will return the wrong return value.
>
> Thank you for your comment! I didn't realized this.
>
> > Yes, agree with you, but seems I keep its original logic unchanged.
> > Hi Yoshihiro,
> >
> > What do think about Daniel's suggestion? should I fix it up?
>
> I think you should fix it up like below:
>
> if (readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000) < 0)
> retval = -ETIMEOUT; /* Overwrite retval if timeout occurred */
readl_poll_timeout_atomic() only return -ETIMEOUT error number, so this
likes what I did, doesn't fix it.
>
> Otherwise, the xhci_rcar_download_firmware() cannot return -ETIMEDOUT if
> timeout happened on the previous poll [1].
>
> [1]
> + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> + 1, 10000);
>
> Best regards,
> Yoshihiro Shimoda
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 4:12 ` Chunfeng Yun
@ 2020-09-11 4:57 ` Yoshihiro Shimoda
2020-09-11 11:46 ` Chunfeng Yun
0 siblings, 1 reply; 24+ messages in thread
From: Yoshihiro Shimoda @ 2020-09-11 4:57 UTC (permalink / raw)
To: Chunfeng Yun
Cc: linux-arm-kernel, Felipe Balbi, Daniel Thompson, linux-usb,
Mathias Nyman, Arnd Bergmann, Mathias Nyman, Sumit Garg,
Greg Kroah-Hartman, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
Hi Chunfeng,
> From: Chunfeng Yun, Sent: Friday, September 11, 2020 1:13 PM
>
> On Fri, 2020-09-11 at 03:13 +0000, Yoshihiro Shimoda wrote:
> > Hi Daniel, Chunfeng,
> >
> > > From: Chunfeng Yun, Sent: Friday, September 11, 2020 11:33 AM
> > >
> > > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > > Use readl_poll_timeout_atomic() to simplify code
> > > > >
> > > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > > ---
> > > > > v2~v3: no changes
> > > > > ---
> > > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > > >
> > > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > > index c1025d3..74f836f 100644
> > > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > > @@ -6,6 +6,7 @@
> > > > > */
> > > > >
> > > > > #include <linux/firmware.h>
> > > > > +#include <linux/iopoll.h>
> > > > > #include <linux/module.h>
> > > > > #include <linux/platform_device.h>
> > > > > #include <linux/of.h>
> > > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > void __iomem *regs = hcd->regs;
> > > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > > const struct firmware *fw;
> > > > > - int retval, index, j, time;
> > > > > - int timeout = 10000;
> > > > > + int retval, index, j;
> > > > > u32 data, val, temp;
> > > > > u32 quirks = 0;
> > > > > const struct soc_device_attribute *attr;
> > > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > >
> > > > > - for (time = 0; time < timeout; time++) {
> > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > > - break;
> > > > > - udelay(1);
> > > > > - }
> > > > > - if (time == timeout) {
> > > > > - retval = -ETIMEDOUT;
> > > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > > + 1, 10000);
> > > > > + if (retval < 0)
> How about free firmware and return error number here ? instead of break
I think clearing CTRL_ENABLE code below is needed.
And, I think this patch should not change a lot of things...
> > > > > break;
> > > > > - }
> > > > > }
> > > > >
> > > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > >
> > > > > - for (time = 0; time < timeout; time++) {
> > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > > - retval = 0;
> > > > > - break;
> > > > > - }
> > > > > - udelay(1);
> > > > > - }
> > > > > - if (time == timeout)
> > > > > - retval = -ETIMEDOUT;
> > > > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> > > >
> > > > Directly assigning to retval at this point will clobber a previous
> > > > -ETIMEDOUT error.
> > > >
> > > > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > > > DW_SUCCESS, then we will return the wrong return value.
> >
> > Thank you for your comment! I didn't realized this.
> >
> > > Yes, agree with you, but seems I keep its original logic unchanged.
> > > Hi Yoshihiro,
> > >
> > > What do think about Daniel's suggestion? should I fix it up?
> >
> > I think you should fix it up like below:
> >
> > if (readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000) < 0)
> > retval = -ETIMEOUT; /* Overwrite retval if timeout occurred */
>
> readl_poll_timeout_atomic() only return -ETIMEOUT error number, so this
> likes what I did, doesn't fix it.
readl_poll_timeout_atomic() returns 0 if timeout doesn't happen.
So, when my suggestion code runs, the retval is not overwritten if
the readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL...) returns 0.
Best regards,
Yoshihiro Shimoda
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 2:33 ` Chunfeng Yun
2020-09-11 3:13 ` Yoshihiro Shimoda
@ 2020-09-11 8:34 ` Daniel Thompson
2020-09-11 9:27 ` Chunfeng Yun
1 sibling, 1 reply; 24+ messages in thread
From: Daniel Thompson @ 2020-09-11 8:34 UTC (permalink / raw)
To: Chunfeng Yun
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Yoshihiro Shimoda, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Fri, Sep 11, 2020 at 10:33:21AM +0800, Chunfeng Yun wrote:
> On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > Use readl_poll_timeout_atomic() to simplify code
> > >
> > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > ---
> > > v2~v3: no changes
> > > ---
> > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > >
> > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > index c1025d3..74f836f 100644
> > > --- a/drivers/usb/host/xhci-rcar.c
> > > +++ b/drivers/usb/host/xhci-rcar.c
> > > @@ -6,6 +6,7 @@
> > > */
> > >
> > > #include <linux/firmware.h>
> > > +#include <linux/iopoll.h>
> > > #include <linux/module.h>
> > > #include <linux/platform_device.h>
> > > #include <linux/of.h>
> > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > void __iomem *regs = hcd->regs;
> > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > const struct firmware *fw;
> > > - int retval, index, j, time;
> > > - int timeout = 10000;
> > > + int retval, index, j;
> > > u32 data, val, temp;
> > > u32 quirks = 0;
> > > const struct soc_device_attribute *attr;
> > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > >
> > > - for (time = 0; time < timeout; time++) {
> > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > - break;
> > > - udelay(1);
> > > - }
> > > - if (time == timeout) {
> > > - retval = -ETIMEDOUT;
> > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > + 1, 10000);
> > > + if (retval < 0)
> > > break;
> > > - }
> > > }
> > >
> > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > >
> > > - for (time = 0; time < timeout; time++) {
> > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > - retval = 0;
> > > - break;
> > > - }
> > > - udelay(1);
> > > - }
> > > - if (time == timeout)
> > > - retval = -ETIMEDOUT;
> > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> >
> > Directly assigning to retval at this point will clobber a previous
> > -ETIMEDOUT error.
> >
> > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > DW_SUCCESS, then we will return the wrong return value.
>
> Yes, agree with you, but seems I keep its original logic unchanged.
I disagree.
Your patch does not preserve the original logic. Your patch explicitly
sets retval to zero if the second loop succeeds. The original code does
not do this. As a result there is a change of return code for one of the
error paths.
Daniel.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 8:34 ` Daniel Thompson
@ 2020-09-11 9:27 ` Chunfeng Yun
2020-09-11 9:48 ` Daniel Thompson
0 siblings, 1 reply; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-11 9:27 UTC (permalink / raw)
To: Daniel Thompson
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Yoshihiro Shimoda, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Fri, 2020-09-11 at 09:34 +0100, Daniel Thompson wrote:
> On Fri, Sep 11, 2020 at 10:33:21AM +0800, Chunfeng Yun wrote:
> > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > Use readl_poll_timeout_atomic() to simplify code
> > > >
> > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > ---
> > > > v2~v3: no changes
> > > > ---
> > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > >
> > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > index c1025d3..74f836f 100644
> > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > @@ -6,6 +6,7 @@
> > > > */
> > > >
> > > > #include <linux/firmware.h>
> > > > +#include <linux/iopoll.h>
> > > > #include <linux/module.h>
> > > > #include <linux/platform_device.h>
> > > > #include <linux/of.h>
> > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > void __iomem *regs = hcd->regs;
> > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > const struct firmware *fw;
> > > > - int retval, index, j, time;
> > > > - int timeout = 10000;
> > > > + int retval, index, j;
> > > > u32 data, val, temp;
> > > > u32 quirks = 0;
> > > > const struct soc_device_attribute *attr;
> > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > >
> > > > - for (time = 0; time < timeout; time++) {
> > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > - break;
> > > > - udelay(1);
> > > > - }
> > > > - if (time == timeout) {
> > > > - retval = -ETIMEDOUT;
> > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > + 1, 10000);
> > > > + if (retval < 0)
> > > > break;
> > > > - }
> > > > }
> > > >
> > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > >
> > > > - for (time = 0; time < timeout; time++) {
> > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > - retval = 0;
Here will set it 0 too
> > > > - break;
> > > > - }
> > > > - udelay(1);
> > > > - }
> > > > - if (time == timeout)
> > > > - retval = -ETIMEDOUT;
> > > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> > >
> > > Directly assigning to retval at this point will clobber a previous
> > > -ETIMEDOUT error.
> > >
> > > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > > DW_SUCCESS, then we will return the wrong return value.
> >
> > Yes, agree with you, but seems I keep its original logic unchanged.
>
> I disagree.
>
> Your patch does not preserve the original logic. Your patch explicitly
> sets retval to zero if the second loop succeeds. The original code does
> not do this. As a result there is a change of return code for one of the
> error paths.
>
>
> Daniel.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 9:27 ` Chunfeng Yun
@ 2020-09-11 9:48 ` Daniel Thompson
2020-09-11 9:58 ` Yoshihiro Shimoda
0 siblings, 1 reply; 24+ messages in thread
From: Daniel Thompson @ 2020-09-11 9:48 UTC (permalink / raw)
To: Chunfeng Yun
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Yoshihiro Shimoda, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Fri, Sep 11, 2020 at 05:27:22PM +0800, Chunfeng Yun wrote:
> On Fri, 2020-09-11 at 09:34 +0100, Daniel Thompson wrote:
> > On Fri, Sep 11, 2020 at 10:33:21AM +0800, Chunfeng Yun wrote:
> > > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > > Use readl_poll_timeout_atomic() to simplify code
> > > > >
> > > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > > ---
> > > > > v2~v3: no changes
> > > > > ---
> > > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > > >
> > > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > > index c1025d3..74f836f 100644
> > > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > > @@ -6,6 +6,7 @@
> > > > > */
> > > > >
> > > > > #include <linux/firmware.h>
> > > > > +#include <linux/iopoll.h>
> > > > > #include <linux/module.h>
> > > > > #include <linux/platform_device.h>
> > > > > #include <linux/of.h>
> > > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > void __iomem *regs = hcd->regs;
> > > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > > const struct firmware *fw;
> > > > > - int retval, index, j, time;
> > > > > - int timeout = 10000;
> > > > > + int retval, index, j;
> > > > > u32 data, val, temp;
> > > > > u32 quirks = 0;
> > > > > const struct soc_device_attribute *attr;
> > > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > >
> > > > > - for (time = 0; time < timeout; time++) {
> > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > > - break;
> > > > > - udelay(1);
> > > > > - }
> > > > > - if (time == timeout) {
> > > > > - retval = -ETIMEDOUT;
> > > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > > + 1, 10000);
> > > > > + if (retval < 0)
> > > > > break;
> > > > > - }
> > > > > }
> > > > >
> > > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > >
> > > > > - for (time = 0; time < timeout; time++) {
> > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > > - retval = 0;
> Here will set it 0 too
Doh...
Thanks.
Daniel.
>
> > > > > - break;
> > > > > - }
> > > > > - udelay(1);
> > > > > - }
> > > > > - if (time == timeout)
> > > > > - retval = -ETIMEDOUT;
> > > > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> > > >
> > > > Directly assigning to retval at this point will clobber a previous
> > > > -ETIMEDOUT error.
> > > >
> > > > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > > > DW_SUCCESS, then we will return the wrong return value.
> > >
> > > Yes, agree with you, but seems I keep its original logic unchanged.
> >
> > I disagree.
> >
> > Your patch does not preserve the original logic. Your patch explicitly
> > sets retval to zero if the second loop succeeds. The original code does
> > not do this. As a result there is a change of return code for one of the
> > error paths.
> >
> >
> > Daniel.
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 9:48 ` Daniel Thompson
@ 2020-09-11 9:58 ` Yoshihiro Shimoda
0 siblings, 0 replies; 24+ messages in thread
From: Yoshihiro Shimoda @ 2020-09-11 9:58 UTC (permalink / raw)
To: Daniel Thompson, Chunfeng Yun
Cc: linux-arm-kernel, Felipe Balbi, linux-usb, Mathias Nyman,
Arnd Bergmann, Mathias Nyman, Sumit Garg, Greg Kroah-Hartman,
Jann Horn, Chuhong Yuan, Douglas Anderson, Gustavo A. R. Silva,
Saurav Girepunje, Jason Yan, linux-mediatek, Eric W. Biederman,
Matthias Brugger, Lee Jones, Ben Dooks, linux-kernel
Hi Chunfeng,
> From: Daniel Thompson, Sent: Friday, September 11, 2020 6:49 PM
>
> On Fri, Sep 11, 2020 at 05:27:22PM +0800, Chunfeng Yun wrote:
> > On Fri, 2020-09-11 at 09:34 +0100, Daniel Thompson wrote:
> > > On Fri, Sep 11, 2020 at 10:33:21AM +0800, Chunfeng Yun wrote:
> > > > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > > > Use readl_poll_timeout_atomic() to simplify code
> > > > > >
> > > > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > > > ---
> > > > > > v2~v3: no changes
> > > > > > ---
> > > > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > > > index c1025d3..74f836f 100644
> > > > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > > > @@ -6,6 +6,7 @@
> > > > > > */
> > > > > >
> > > > > > #include <linux/firmware.h>
> > > > > > +#include <linux/iopoll.h>
> > > > > > #include <linux/module.h>
> > > > > > #include <linux/platform_device.h>
> > > > > > #include <linux/of.h>
> > > > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > > void __iomem *regs = hcd->regs;
> > > > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > > > const struct firmware *fw;
> > > > > > - int retval, index, j, time;
> > > > > > - int timeout = 10000;
> > > > > > + int retval, index, j;
> > > > > > u32 data, val, temp;
> > > > > > u32 quirks = 0;
> > > > > > const struct soc_device_attribute *attr;
> > > > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > > >
> > > > > > - for (time = 0; time < timeout; time++) {
> > > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > > > - break;
> > > > > > - udelay(1);
> > > > > > - }
> > > > > > - if (time == timeout) {
> > > > > > - retval = -ETIMEDOUT;
> > > > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > > > + 1, 10000);
> > > > > > + if (retval < 0)
> > > > > > break;
> > > > > > - }
> > > > > > }
> > > > > >
> > > > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > > >
> > > > > > - for (time = 0; time < timeout; time++) {
> > > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > > > - retval = 0;
> > Here will set it 0 too
>
> Doh...
>
> Thanks.
Ah, now I also understood your patch was logically unchanged.
Thanks!
Best regards,
Yoshihiro Shimoda
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH RESEND v3 04/11] usb: xhci-rcar: convert to readl_poll_timeout_atomic()
2020-09-11 4:57 ` Yoshihiro Shimoda
@ 2020-09-11 11:46 ` Chunfeng Yun
0 siblings, 0 replies; 24+ messages in thread
From: Chunfeng Yun @ 2020-09-11 11:46 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: linux-arm-kernel, Felipe Balbi, Daniel Thompson, linux-usb,
Mathias Nyman, Arnd Bergmann, Mathias Nyman, Sumit Garg,
Greg Kroah-Hartman, Jann Horn, Chuhong Yuan, Douglas Anderson,
Gustavo A. R. Silva, Saurav Girepunje, Jason Yan, linux-mediatek,
Eric W. Biederman, Matthias Brugger, Lee Jones, Ben Dooks,
linux-kernel
On Fri, 2020-09-11 at 04:57 +0000, Yoshihiro Shimoda wrote:
> Hi Chunfeng,
>
> > From: Chunfeng Yun, Sent: Friday, September 11, 2020 1:13 PM
> >
> > On Fri, 2020-09-11 at 03:13 +0000, Yoshihiro Shimoda wrote:
> > > Hi Daniel, Chunfeng,
> > >
> > > > From: Chunfeng Yun, Sent: Friday, September 11, 2020 11:33 AM
> > > >
> > > > On Thu, 2020-09-10 at 14:12 +0100, Daniel Thompson wrote:
> > > > > On Thu, Sep 10, 2020 at 04:21:45PM +0800, Chunfeng Yun wrote:
> > > > > > Use readl_poll_timeout_atomic() to simplify code
> > > > > >
> > > > > > Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
> > > > > > Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > > > > ---
> > > > > > v2~v3: no changes
> > > > > > ---
> > > > > > drivers/usb/host/xhci-rcar.c | 43 ++++++++++++-------------------------------
> > > > > > 1 file changed, 12 insertions(+), 31 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> > > > > > index c1025d3..74f836f 100644
> > > > > > --- a/drivers/usb/host/xhci-rcar.c
> > > > > > +++ b/drivers/usb/host/xhci-rcar.c
> > > > > > @@ -6,6 +6,7 @@
> > > > > > */
> > > > > >
> > > > > > #include <linux/firmware.h>
> > > > > > +#include <linux/iopoll.h>
> > > > > > #include <linux/module.h>
> > > > > > #include <linux/platform_device.h>
> > > > > > #include <linux/of.h>
> > > > > > @@ -127,8 +128,7 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > > void __iomem *regs = hcd->regs;
> > > > > > struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
> > > > > > const struct firmware *fw;
> > > > > > - int retval, index, j, time;
> > > > > > - int timeout = 10000;
> > > > > > + int retval, index, j;
> > > > > > u32 data, val, temp;
> > > > > > u32 quirks = 0;
> > > > > > const struct soc_device_attribute *attr;
> > > > > > @@ -166,32 +166,19 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
> > > > > > temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
> > > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > > >
> > > > > > - for (time = 0; time < timeout; time++) {
> > > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > - if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
> > > > > > - break;
> > > > > > - udelay(1);
> > > > > > - }
> > > > > > - if (time == timeout) {
> > > > > > - retval = -ETIMEDOUT;
> > > > > > + retval = readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > > > > + val, !(val & RCAR_USB3_DL_CTRL_FW_SET_DATA0),
> > > > > > + 1, 10000);
> > > > > > + if (retval < 0)
> > How about free firmware and return error number here ? instead of break
>
> I think clearing CTRL_ENABLE code below is needed.
> And, I think this patch should not change a lot of things...
Ok, thanks
>
> > > > > > break;
> > > > > > - }
> > > > > > }
> > > > > >
> > > > > > temp = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
> > > > > > writel(temp, regs + RCAR_USB3_DL_CTRL);
> > > > > >
> > > > > > - for (time = 0; time < timeout; time++) {
> > > > > > - val = readl(regs + RCAR_USB3_DL_CTRL);
> > > > > > - if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
> > > > > > - retval = 0;
> > > > > > - break;
> > > > > > - }
> > > > > > - udelay(1);
> > > > > > - }
> > > > > > - if (time == timeout)
> > > > > > - retval = -ETIMEDOUT;
> > > > > > + retval = readl_poll_timeout_atomic((regs + RCAR_USB3_DL_CTRL),
> > > > > > + val, (val & RCAR_USB3_DL_CTRL_FW_SUCCESS), 1, 10000);
> > > > >
> > > > > Directly assigning to retval at this point will clobber a previous
> > > > > -ETIMEDOUT error.
> > > > >
> > > > > In other words if there is a timeout waiting for FW_SET_DATA0, but not for
> > > > > DW_SUCCESS, then we will return the wrong return value.
> > >
> > > Thank you for your comment! I didn't realized this.
> > >
> > > > Yes, agree with you, but seems I keep its original logic unchanged.
> > > > Hi Yoshihiro,
> > > >
> > > > What do think about Daniel's suggestion? should I fix it up?
> > >
> > > I think you should fix it up like below:
> > >
> > > if (readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL,
> > > val, val & RCAR_USB3_DL_CTRL_FW_SUCCESS, 1, 10000) < 0)
> > > retval = -ETIMEOUT; /* Overwrite retval if timeout occurred */
> >
> > readl_poll_timeout_atomic() only return -ETIMEOUT error number, so this
> > likes what I did, doesn't fix it.
>
> readl_poll_timeout_atomic() returns 0 if timeout doesn't happen.
> So, when my suggestion code runs, the retval is not overwritten if
> the readl_poll_timeout_atomic(regs + RCAR_USB3_DL_CTRL...) returns 0.
>
> Best regards,
> Yoshihiro Shimoda
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2020-09-11 11:50 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10 8:21 [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 02/11] usb: early: ehci-dbgp: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 03/11] usb: pci-quirks: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 04/11] usb: xhci-rcar: " Chunfeng Yun
2020-09-10 12:56 ` Yoshihiro Shimoda
2020-09-11 2:21 ` Chunfeng Yun
2020-09-10 13:12 ` Daniel Thompson
2020-09-11 2:33 ` Chunfeng Yun
2020-09-11 3:13 ` Yoshihiro Shimoda
2020-09-11 4:12 ` Chunfeng Yun
2020-09-11 4:57 ` Yoshihiro Shimoda
2020-09-11 11:46 ` Chunfeng Yun
2020-09-11 8:34 ` Daniel Thompson
2020-09-11 9:27 ` Chunfeng Yun
2020-09-11 9:48 ` Daniel Thompson
2020-09-11 9:58 ` Yoshihiro Shimoda
2020-09-10 8:21 ` [PATCH RESEND v3 05/11] usb: oxu210hp-hcd: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 06/11] usb: fotg210-hcd: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 07/11] usb: isp1760-hcd: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 08/11] usb: phy-ulpi-viewport: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 09/11] usb: phy: phy-mv-usb: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 10/11] usb: udc: net2280: " Chunfeng Yun
2020-09-10 8:21 ` [PATCH RESEND v3 11/11] iopoll: update kerneldoc of read_poll_timeout_atomic() Chunfeng Yun
2020-09-10 10:49 ` [PATCH RESEND v3 01/11] usb: early: convert to readl_poll_timeout_atomic() Jann Horn
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).