diff mbox series

[RFC,6/9] usb: xhci: Allow accessing 64-bit registers with DWORD accesses only

Message ID 20200421165059.19394-7-s.nawrocki@samsung.com
State New
Headers show
Series USB host support for Raspberry Pi 4 board | expand

Commit Message

This patch adds a Kconfig option which allows accessing 64-bit xHCI
IO registers only with 2 double word accesses rather than using
a single quad word access. There might be HW configurations where
single quad word access doesn't work, even though the CPU is 64-bit.
That seems to be the case on rpi4 board with Broadcom BCM2711 SoC,
where the VL805 USB xHCI hub is connected to the PCIe controller
behind the SCB bridge.

Signed-off-by: Sylwester Nawrocki <s.nawrocki at samsung.com>
---
So far I couldn't come up with anything better to make the xHCI host
controller working on the rpi4 board. For some reason dereferencing
a 64-bit pointer to access 64-bit registers doesn't work there,
might be a limitation of the PCIe bridge behind the SCB. In Linux
always 2 double word accesses are used.
---
 drivers/usb/host/Kconfig | 7 +++++++
 include/usb/xhci.h       | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Bin Meng April 22, 2020, 6 a.m. UTC | #1
Hi Sylwester,

On Wed, Apr 22, 2020 at 12:51 AM Sylwester Nawrocki
<s.nawrocki at samsung.com> wrote:
>
> This patch adds a Kconfig option which allows accessing 64-bit xHCI
> IO registers only with 2 double word accesses rather than using
> a single quad word access. There might be HW configurations where
> single quad word access doesn't work, even though the CPU is 64-bit.
> That seems to be the case on rpi4 board with Broadcom BCM2711 SoC,
> where the VL805 USB xHCI hub is connected to the PCIe controller
> behind the SCB bridge.
>
> Signed-off-by: Sylwester Nawrocki <s.nawrocki at samsung.com>
> ---
> So far I couldn't come up with anything better to make the xHCI host
> controller working on the rpi4 board. For some reason dereferencing
> a 64-bit pointer to access 64-bit registers doesn't work there,
> might be a limitation of the PCIe bridge behind the SCB. In Linux
> always 2 double word accesses are used.

If Linux always uses 2 double word accesses, let's simply do the same
in U-Boot by removing the readq/writeq.

> ---
>  drivers/usb/host/Kconfig | 7 +++++++
>  include/usb/xhci.h       | 4 ++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
>

Regards,
Bin
Nicolas Saenz Julienne April 22, 2020, 8:58 a.m. UTC | #2
On Tue, 2020-04-21 at 18:50 +0200, Sylwester Nawrocki wrote:
> This patch adds a Kconfig option which allows accessing 64-bit xHCI
> IO registers only with 2 double word accesses rather than using
> a single quad word access. There might be HW configurations where
> single quad word access doesn't work, even though the CPU is 64-bit.
> That seems to be the case on rpi4 board with Broadcom BCM2711 SoC,
> where the VL805 USB xHCI hub is connected to the PCIe controller
> behind the SCB bridge.
> 
> Signed-off-by: Sylwester Nawrocki <s.nawrocki at samsung.com>
> ---
> So far I couldn't come up with anything better to make the xHCI host
> controller working on the rpi4 board. For some reason dereferencing
> a 64-bit pointer to access 64-bit registers doesn't work there,
> might be a limitation of the PCIe bridge behind the SCB. In Linux
> always 2 double word accesses are used.

Out of curiosity, what are the benefits of using 64bit accesses anyway? I'm
under the impression that 64 bit accesses are not used that much in xHCI
anyway. We could simply default Linux's behavior and save some maintenance
burden.

Regards,
Nicolas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200422/f6d926d7/attachment.sig>
Hi Bin,

On 22.04.2020 08:00, Bin Meng wrote:
> On Wed, Apr 22, 2020 at 12:51 AM Sylwester Nawrocki
> <s.nawrocki at samsung.com> wrote:
[...]
>> So far I couldn't come up with anything better to make the xHCI host
>> controller working on the rpi4 board. For some reason dereferencing
>> a 64-bit pointer to access 64-bit registers doesn't work there,
>> might be a limitation of the PCIe bridge behind the SCB. In Linux
>> always 2 double word accesses are used.
> 
> If Linux always uses 2 double word accesses, let's simply do the same
> in U-Boot by removing the readq/writeq.

Thanks for your review. That sounds good to me, I will do it that way
in next iteration.

--
Regards, 
Sylwester
diff mbox series

Patch

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 0987ff2..3990b8a 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -15,6 +15,13 @@  config USB_XHCI_HCD
 
 if USB_XHCI_HCD
 
+config XHCI_64BIT_DWORD_ACCESS_ONLY
+	bool "Access xHCI 64-bit registers with double word accesses only"
+	help
+	  Choose this option if your hardware does not support quad word accesses
+	  for registers with 64-bit address pointers.
+	  If unsure, say Y.
+
 config USB_XHCI_DWC3
 	bool "DesignWare USB3 DRD Core Support"
 	help
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 6017504..459e76b 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -1111,7 +1111,7 @@  static inline void xhci_writel(uint32_t volatile *regs, const unsigned int val)
  */
 static inline u64 xhci_readq(__le64 volatile *regs)
 {
-#if BITS_PER_LONG == 64
+#if BITS_PER_LONG == 64 && !defined(CONFIG_XHCI_64BIT_DWORD_ACCESS_ONLY)
 	return readq(regs);
 #else
 	__u32 *ptr = (__u32 *)regs;
@@ -1123,7 +1123,7 @@  static inline u64 xhci_readq(__le64 volatile *regs)
 
 static inline void xhci_writeq(__le64 volatile *regs, const u64 val)
 {
-#if BITS_PER_LONG == 64
+#if BITS_PER_LONG == 64 && !defined(CONFIG_XHCI_64BIT_DWORD_ACCESS_ONLY)
 	writeq(val, regs);
 #else
 	__u32 *ptr = (__u32 *)regs;