Skip to contentSkip to conversation

nvme: Use only 32-bit accesses in nvme_writeq/nvme_readq

PATCH New Stefan Agner 2 participants 2 messages Dec 30, 2020 – Jan 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme: Use only 32-bit accesses in nvme_writeq/nvme_readq

There might be hardware configurations where 64-bit data accesses to NVMe registers are not supported properly. This patch removes the readq/writeq so always two 32-bit accesses are used to read/write 64-bit NVMe registers, similarly as it is done in Linux kernel.

This patch fixes operation of NVMe devices on RPi4 Broadcom BCM2711 SoC based board, where the PCIe Root Complex, which is attached to the system through the SCB bridge.

Even though the architecture is 64-bit the PCIe BAR is 32-bit and likely the 64-bit wide register accesses initiated by the CPU are not properly translated to a sequence of 32-bit PCIe accesses. nvme_readq(), for example, always returns same value in upper and lower 32-bits, e.g. 0x3c033fff3c033fff which lead to NVMe devices to fail probing.

This fix is analogous to commit 8e2ab05000ab ("usb: xhci: Use only 32-bit accesses in xhci_writeq/xhci_readq").

Cc Sylwester Nawrocki <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>
Cc Matthias Brugger <[email protected]>

---

Changes in v2:
- Fix subject and message to reflect NVMe change

 drivers/nvme/nvme.h | 8 --------
 1 file changed, 8 deletions(-)
drivers/nvme/nvme.h +0 -8
index 0e8cb221a7..aa4b3bac67 100644
@@ -535,28 +535,20 @@ struct nvme_completion {
  */
 static inline u64 nvme_readq(__le64 volatile *regs)
 {
-#if BITS_PER_LONG == 64
-	return readq(regs);
-#else
 	__u32 *ptr = (__u32 *)regs;
 	u64 val_lo = readl(ptr);
 	u64 val_hi = readl(ptr + 1);
 
 	return val_lo + (val_hi << 32);
-#endif
 }
 
 static inline void nvme_writeq(const u64 val, __le64 volatile *regs)
 {
-#if BITS_PER_LONG == 64
-	writeq(val, regs);
-#else
 	__u32 *ptr = (__u32 *)regs;
 	u32 val_lo = lower_32_bits(val);
 	u32 val_hi = upper_32_bits(val);
 	writel(val_lo, ptr);
 	writel(val_hi, ptr + 1);
-#endif
 }
 
 struct nvme_bar {
Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/1 nvme: Use only 32-bit accesses in nvme_writeq/nvme_readq

Quoted 19 lines · Stefan Agner

There might be hardware configurations where 64-bit data accesses to NVMe registers are not supported properly. This patch removes the readq/writeq so always two 32-bit accesses are used to read/write 64-bit NVMe registers, similarly as it is done in Linux kernel.

This patch fixes operation of NVMe devices on RPi4 Broadcom BCM2711 SoC based board, where the PCIe Root Complex, which is attached to the system through the SCB bridge.

Even though the architecture is 64-bit the PCIe BAR is 32-bit and likely the 64-bit wide register accesses initiated by the CPU are not properly translated to a sequence of 32-bit PCIe accesses. nvme_readq(), for example, always returns same value in upper and lower 32-bits, e.g. 0x3c033fff3c033fff which lead to NVMe devices to fail probing.

This fix is analogous to commit 8e2ab05000ab ("usb: xhci: Use only 32-bit accesses in xhci_writeq/xhci_readq").

Quoted 6 lines
Cc Sylwester Nawrocki <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>
Cc Matthias Brugger <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210105/cab28247/attachment.sig>