]> Git Repo - linux.git/commitdiff
xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
authorAndrey Smirnov <[email protected]>
Wed, 22 May 2019 11:34:01 +0000 (14:34 +0300)
committerGreg Kroah-Hartman <[email protected]>
Wed, 22 May 2019 12:25:37 +0000 (14:25 +0200)
Xhci_handshake() implements the algorithm already captured by
readl_poll_timeout_atomic(). Convert the former to use the latter to
avoid repetition.

Turned out this patch also fixes a bug on the AMD Stoneyridge platform
where 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.

[Add info about patch fixing a bug to commit message -Mathias]
Signed-off-by: Andrey Smirnov <[email protected]>
Tested-by: Raul E Rangel <[email protected]>
Reviewed-by: Raul E Rangel <[email protected]>
Cc: <[email protected]>
Signed-off-by: Mathias Nyman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
drivers/usb/host/xhci.c

index 048a675bbc5271fa49461d1eafe2a01d8b3dc518..20db378a60123ccae997948408385b64c8410b1b 100644 (file)
@@ -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;
 }
 
 /*
This page took 0.05839 seconds and 4 git commands to generate.