Skip to contentSkip to conversation

xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()

PATCH In review Andrey Smirnov 3 participants 3 messages Feb 8, 2019 – May 2, 2019

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

PATCH v2 1/1 xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()

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

---

Changes since [v1]:

- Replaced readl_poll_timeout() with readl_poll_timeout_atomic()

[v1] https://lore.kernel.org/lkml/[email protected]

 drivers/usb/host/xhci.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/usb/host/xhci.c +10 -12
index 005e65922608..51c25a664ca4 100644
@@ -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;
 }
 
 /*
Tested-by Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Andrey Smirnov

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

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.

#2 lore raw
Quoted 6 lines · Raul Rangel
Quoted 5 lines · Andrey Smirnov

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

Quoted 8 lines

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