]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/xhci-convert-xhci_handshake-to-use-readl_poll_timeout_atomic.patch
Linux 4.19.49
[thirdparty/kernel/stable-queue.git] / queue-4.14 / xhci-convert-xhci_handshake-to-use-readl_poll_timeout_atomic.patch
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()
5
6 From: Andrey Smirnov <andrew.smirnov@gmail.com>
7
8 commit f7fac17ca925faa03fc5eb854c081a24075f8bad upstream.
9
10 Xhci_handshake() implements the algorithm already captured by
11 readl_poll_timeout_atomic(). Convert the former to use the latter to
12 avoid repetition.
13
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.
18
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>
26
27 ---
28 drivers/usb/host/xhci.c | 22 ++++++++++------------
29 1 file changed, 10 insertions(+), 12 deletions(-)
30
31 --- a/drivers/usb/host/xhci.c
32 +++ b/drivers/usb/host/xhci.c
33 @@ -21,6 +21,7 @@
34 */
35
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
42 return false;
43 }
44
45 -/* TODO: copied from ehci-hcd.c - can this be refactored? */
46 /*
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)
51 {
52 u32 result;
53 + int ret;
54
55 - do {
56 - result = readl(ptr);
57 - if (result == ~(u32)0) /* card removed */
58 - return -ENODEV;
59 - result &= mask;
60 - if (result == done)
61 - return 0;
62 - udelay(1);
63 - usec--;
64 - } while (usec > 0);
65 - return -ETIMEDOUT;
66 + ret = readl_poll_timeout_atomic(ptr, result,
67 + (result & mask) == done ||
68 + result == U32_MAX,
69 + 1, usec);
70 + if (result == U32_MAX) /* card removed */
71 + return -ENODEV;
72 +
73 + return ret;
74 }
75
76 /*