1 From f7fac17ca925faa03fc5eb854c081a24075f8bad Mon Sep 17 00:00:00 2001
2 From: Andrey Smirnov <andrew.smirnov@gmail.com>
3 Date: Wed, 22 May 2019 14:34:01 +0300
4 Subject: xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
6 From: Andrey Smirnov <andrew.smirnov@gmail.com>
8 commit f7fac17ca925faa03fc5eb854c081a24075f8bad upstream.
10 Xhci_handshake() implements the algorithm already captured by
11 readl_poll_timeout_atomic(). Convert the former to use the latter to
14 Turned out this patch also fixes a bug on the AMD Stoneyridge platform
15 where usleep(1) sometimes takes over 10ms.
16 This means a 5 second timeout can easily take over 15 seconds which will
17 trigger the watchdog and reboot the system.
19 [Add info about patch fixing a bug to commit message -Mathias]
20 Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
21 Tested-by: Raul E Rangel <rrangel@chromium.org>
22 Reviewed-by: Raul E Rangel <rrangel@chromium.org>
23 Cc: <stable@vger.kernel.org>
24 Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 drivers/usb/host/xhci.c | 22 ++++++++++------------
29 1 file changed, 10 insertions(+), 12 deletions(-)
31 --- a/drivers/usb/host/xhci.c
32 +++ b/drivers/usb/host/xhci.c
36 #include <linux/pci.h>
37 +#include <linux/iopoll.h>
38 #include <linux/irq.h>
39 #include <linux/log2.h>
40 #include <linux/module.h>
41 @@ -62,7 +63,6 @@ static bool td_on_ring(struct xhci_td *t
45 -/* TODO: copied from ehci-hcd.c - can this be refactored? */
47 * xhci_handshake - spin reading hc until handshake completes or fails
48 * @ptr: address of hc register to be read
49 @@ -79,18 +79,16 @@ static bool td_on_ring(struct xhci_td *t
50 int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
56 - result = readl(ptr);
57 - if (result == ~(u32)0) /* card removed */
66 + ret = readl_poll_timeout_atomic(ptr, result,
67 + (result & mask) == done ||
70 + if (result == U32_MAX) /* card removed */