linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
@ 2019-02-08  1:48 Andrey Smirnov
  2019-04-29 20:05 ` Raul Rangel
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Smirnov @ 2019-02-08  1:48 UTC (permalink / raw)
  To: linux-usb; +Cc: Andrey Smirnov, Mathias Nyman, Greg Kroah-Hartman, linux-kernel

Xhci_handshake() implements the algorithm already captured by
readl_poll_timeout_atomic(). Convert the former to use the latter to
avoid repetition.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---

Changes since [v1]:

    - Replaced readl_poll_timeout() with readl_poll_timeout_atomic()

[v1] https://lore.kernel.org/lkml/20190207000308.7051-1-andrew.smirnov@gmail.com

 drivers/usb/host/xhci.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 005e65922608..51c25a664ca4 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/pci.h>
+#include <linux/iopoll.h>
 #include <linux/irq.h>
 #include <linux/log2.h>
 #include <linux/module.h>
@@ -52,7 +53,6 @@ static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
 	return false;
 }
 
-/* TODO: copied from ehci-hcd.c - can this be refactored? */
 /*
  * xhci_handshake - spin reading hc until handshake completes or fails
  * @ptr: address of hc register to be read
@@ -69,18 +69,16 @@ static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
 int xhci_handshake(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;
 }
 
 /*
-- 
2.20.1


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

* Re: [PATCH v2] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
  2019-02-08  1:48 [PATCH v2] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic() Andrey Smirnov
@ 2019-04-29 20:05 ` Raul Rangel
  2019-05-02 12:17   ` Mathias Nyman
  0 siblings, 1 reply; 3+ messages in thread
From: Raul Rangel @ 2019-04-29 20:05 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: linux-usb, Mathias Nyman, Greg Kroah-Hartman, linux-kernel

On Thu, Feb 07, 2019 at 05:48:16PM -0800, Andrey Smirnov wrote:
> Xhci_handshake() implements the algorithm already captured by
> readl_poll_timeout_atomic(). Convert the former to use the latter to
> avoid repetition.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Tested-by: Raul E Rangel <rrangel@chromium.org>
Reviewed-by: Raul E Rangel <rrangel@chromium.org>

This fixes a bug on the AMD Stoneyridge platform. usleep(1) sometimes
takes over 10ms. This means a 5 second timeout can easily take over 15
seconds which will trigger the watchdog and reboot the system.

Thanks for the patch.

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

* Re: [PATCH v2] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
  2019-04-29 20:05 ` Raul Rangel
@ 2019-05-02 12:17   ` Mathias Nyman
  0 siblings, 0 replies; 3+ messages in thread
From: Mathias Nyman @ 2019-05-02 12:17 UTC (permalink / raw)
  To: Raul Rangel, Andrey Smirnov
  Cc: linux-usb, Mathias Nyman, Greg Kroah-Hartman, linux-kernel

On 29.4.2019 23.05, Raul Rangel wrote:
> On Thu, Feb 07, 2019 at 05:48:16PM -0800, Andrey Smirnov wrote:
>> Xhci_handshake() implements the algorithm already captured by
>> readl_poll_timeout_atomic(). Convert the former to use the latter to
>> avoid repetition.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Tested-by: Raul E Rangel <rrangel@chromium.org>
> Reviewed-by: Raul E Rangel <rrangel@chromium.org>
> 
> This fixes a bug on the AMD Stoneyridge platform. usleep(1) sometimes
> takes over 10ms. This means a 5 second timeout can easily take over 15
> seconds which will trigger the watchdog and reboot the system.
> 
> Thanks for the patch.

Adding to queue

-Mathias


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

end of thread, other threads:[~2019-05-02 12:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-08  1:48 [PATCH v2] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic() Andrey Smirnov
2019-04-29 20:05 ` Raul Rangel
2019-05-02 12:17   ` Mathias Nyman

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).