usb: dwc3: ulpi: Replace CPU-based busyloop with Protocol-based one
authorSerge Semin <Sergey.Semin@baikalelectronics.ru>
Thu, 10 Dec 2020 08:50:07 +0000 (11:50 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 28 Dec 2020 14:55:41 +0000 (15:55 +0100)
commitfca3f138105727c3a22edda32d02f91ce1bf11c9
tree311040e5ebd7221484ad2f0d0f4aa839da1cd3e8
parentce722da66d3e9384aa2de9d33d584ee154e5e157
usb: dwc3: ulpi: Replace CPU-based busyloop with Protocol-based one

Originally the procedure of the ULPI transaction finish detection has been
developed as a simple busy-loop with just decrementing counter and no
delays. It's wrong since on different systems the loop will take a
different time to complete. So if the system bus and CPU are fast enough
to overtake the ULPI bus and the companion PHY reaction, then we'll get to
take a false timeout error. Fix this by converting the busy-loop procedure
to take the standard bus speed, address value and the registers access
mode into account for the busy-loop delay calculation.

Here is the way the fix works. It's known that the ULPI bus is clocked
with 60MHz signal. In accordance with [1] the ULPI bus protocol is created
so to spend 5 and 6 clock periods for immediate register write and read
operations respectively, and 6 and 7 clock periods - for the extended
register writes and reads. Based on that we can easily pre-calculate the
time which will be needed for the controller to perform a requested IO
operation. Note we'll still preserve the attempts counter in case if the
DWC USB3 controller has got some internals delays.

[1] UTMI+ Low Pin Interface (ULPI) Specification, Revision 1.1,
    October 20, 2004, pp. 30 - 36.

Fixes: 88bc9d194ff6 ("usb: dwc3: add ULPI interface support")
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Link: https://lore.kernel.org/r/20201210085008.13264-3-Sergey.Semin@baikalelectronics.ru
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/ulpi.c