* [PATCH] xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 0:03 ` Andrey Smirnov
0 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-02-07 0:03 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(). 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
---
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..1b5306001340 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(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] 8+ messages in thread
* xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 0:03 ` Andrey Smirnov
0 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-02-07 0:03 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(). 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
---
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..1b5306001340 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(ptr, result,
+ (result & mask) == done ||
+ result == U32_MAX,
+ 1, usec);
+ if (result == U32_MAX) /* card removed */
+ return -ENODEV;
+
+ return ret;
}
/*
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 8:32 ` Mathias Nyman
0 siblings, 0 replies; 8+ messages in thread
From: Mathias Nyman @ 2019-02-07 8:32 UTC (permalink / raw)
To: Andrey Smirnov, linux-usb; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On 07.02.2019 02:03, Andrey Smirnov wrote:
> Xhci_handshake() implements the algorithm already captured by
> readl_poll_timeout(). Convert the former to use the latter to avoid
> repetition.
readl_poll_timeout() doesn't really work here as it might sleep.
iopoll.h:
/**
* readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
*
...
* Returns 0 on success and -ETIMEDOUT upon a timeout. In either
* case, the last read value at @addr is stored in @val. Must not
* be called from atomic context if sleep_us or timeout_us are used.
-Mathias
^ permalink raw reply [flat|nested] 8+ messages in thread
* xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 8:32 ` Mathias Nyman
0 siblings, 0 replies; 8+ messages in thread
From: Mathias Nyman @ 2019-02-07 8:32 UTC (permalink / raw)
To: Andrey Smirnov, linux-usb; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On 07.02.2019 02:03, Andrey Smirnov wrote:
> Xhci_handshake() implements the algorithm already captured by
> readl_poll_timeout(). Convert the former to use the latter to avoid
> repetition.
readl_poll_timeout() doesn't really work here as it might sleep.
iopoll.h:
/**
* readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
*
...
* Returns 0 on success and -ETIMEDOUT upon a timeout. In either
* case, the last read value at @addr is stored in @val. Must not
* be called from atomic context if sleep_us or timeout_us are used.
-Mathias
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 8:45 ` Felipe Balbi
0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2019-02-07 8:45 UTC (permalink / raw)
To: Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]
Hi,
Mathias Nyman <mathias.nyman@linux.intel.com> writes:
> On 07.02.2019 02:03, Andrey Smirnov wrote:
>> Xhci_handshake() implements the algorithm already captured by
>> readl_poll_timeout(). Convert the former to use the latter to avoid
>> repetition.
>
> readl_poll_timeout() doesn't really work here as it might sleep.
>
> iopoll.h:
>
> /**
> * readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
> *
> ...
> * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
> * case, the last read value at @addr is stored in @val. Must not
> * be called from atomic context if sleep_us or timeout_us are used.
readl_poll_timeout_atomic()?
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 8:45 ` Felipe Balbi
0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2019-02-07 8:45 UTC (permalink / raw)
To: Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
Hi,
Mathias Nyman <mathias.nyman@linux.intel.com> writes:
> On 07.02.2019 02:03, Andrey Smirnov wrote:
>> Xhci_handshake() implements the algorithm already captured by
>> readl_poll_timeout(). Convert the former to use the latter to avoid
>> repetition.
>
> readl_poll_timeout() doesn't really work here as it might sleep.
>
> iopoll.h:
>
> /**
> * readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
> *
> ...
> * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
> * case, the last read value at @addr is stored in @val. Must not
> * be called from atomic context if sleep_us or timeout_us are used.
readl_poll_timeout_atomic()?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 21:03 ` Andrey Smirnov
0 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-02-07 21:03 UTC (permalink / raw)
To: Mathias Nyman; +Cc: linux-usb, Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On Thu, Feb 7, 2019 at 12:27 AM Mathias Nyman
<mathias.nyman@linux.intel.com> wrote:
>
> On 07.02.2019 02:03, Andrey Smirnov wrote:
> > Xhci_handshake() implements the algorithm already captured by
> > readl_poll_timeout(). Convert the former to use the latter to avoid
> > repetition.
>
> readl_poll_timeout() doesn't really work here as it might sleep.
>
> iopoll.h:
>
> /**
> * readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
> *
> ...
> * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
> * case, the last read value at @addr is stored in @val. Must not
> * be called from atomic context if sleep_us or timeout_us are used.
>
> -Mathias
Shoot, missed this part. Will change to readl_poll_timeout_atomic() in v2.
Thanks,
Andrey Smirnov
^ permalink raw reply [flat|nested] 8+ messages in thread
* xhci: Convert xhci_handshake() to use readl_poll_timeout()
@ 2019-02-07 21:03 ` Andrey Smirnov
0 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2019-02-07 21:03 UTC (permalink / raw)
To: Mathias Nyman; +Cc: linux-usb, Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On Thu, Feb 7, 2019 at 12:27 AM Mathias Nyman
<mathias.nyman@linux.intel.com> wrote:
>
> On 07.02.2019 02:03, Andrey Smirnov wrote:
> > Xhci_handshake() implements the algorithm already captured by
> > readl_poll_timeout(). Convert the former to use the latter to avoid
> > repetition.
>
> readl_poll_timeout() doesn't really work here as it might sleep.
>
> iopoll.h:
>
> /**
> * readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
> *
> ...
> * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
> * case, the last read value at @addr is stored in @val. Must not
> * be called from atomic context if sleep_us or timeout_us are used.
>
> -Mathias
Shoot, missed this part. Will change to readl_poll_timeout_atomic() in v2.
Thanks,
Andrey Smirnov
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-02-07 21:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 0:03 [PATCH] xhci: Convert xhci_handshake() to use readl_poll_timeout() Andrey Smirnov
2019-02-07 0:03 ` Andrey Smirnov
2019-02-07 8:32 ` [PATCH] " Mathias Nyman
2019-02-07 8:32 ` Mathias Nyman
2019-02-07 8:45 ` [PATCH] " Felipe Balbi
2019-02-07 8:45 ` Felipe Balbi
2019-02-07 21:03 ` [PATCH] " Andrey Smirnov
2019-02-07 21:03 ` Andrey Smirnov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.