usb: ehci: Fix accessors for big-endian platforms and descriptors
Subsystems (2)
PATCH 1/1 usb: ehci: Fix accessors for big-endian platforms and descriptors
Commit 9000eddbae0d ("drivers/usb/ehci: Use platform-specific accessors") broke USB 2.0 on big-endian platforms because for them writel/readl() does automatic conversion of BE data to LE.
Proper implementation requires to use "raw" variant of these accessors which read/write data without messing with endianess.
While at it replace cpu_to_be32() to be32_to_cpu() in readl() to keep sane semantics.
--- drivers/usb/host/ehci.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/ehci.h +4 -4
@@ -101,11 +101,11 @@ struct usb_linux_config_descriptor { } __attribute__ ((packed));#if definedCONFIG_EHCI_DESC_BIG_ENDIAN -#define ehci_readl (x) cpu_to_be32(readl(x)) -#define ehci_writel (a, b) writel(cpu_to_be32(b), a) +#define ehci_readl (x) be32_to_cpu(__raw_readl(x)) +#define ehci_writel (a, b) __raw_writel(cpu_to_be32(b), a)#else -#define ehci_readl (x) cpu_to_le32(readl(x)) -#define ehci_writel (a, b) writel(cpu_to_le32(b), a) +#define ehci_readl (x) readl(x) +#define ehci_writel (a, b) writel(b, a)#endif #if definedCONFIG_EHCI_MMIO_BIG_ENDIAN
Signature · 1 line
2.7.5
Marek Vasut
AppliedPATCH 1/1 usb: ehci: Fix accessors for big-endian platforms and descriptors
Quoted 7 lines · Alexey Brodkin
Commit
9000eddbae0d("drivers/usb/ehci: Use platform-specific accessors") broke USB 2.0 on big-endian platforms because for them writel/readl() does automatic conversion of BE data to LE.Proper implementation requires to use "raw" variant of these accessors which read/write data without messing with endianess.
Quoted 6 lines
While at it replace
cpu_to_be32()tobe32_to_cpu()inreadl()to keep sane semantics.Signed-off-by Alexey Brodkin <[email protected]>Cc Marek Vasut <[email protected]>Reported-by Vladimir Boroda <[email protected]>
Applied, thanks !
Quoted 25 lines
--- drivers/usb/host/ehci.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/usb/host/ehci.h +4
-4@@ -101,11 +101,11 @@ struct usb_linux_config_descriptor { } __attribute__ ((packed));#if definedCONFIG_EHCI_DESC_BIG_ENDIAN -#define ehci_readl (x) cpu_to_be32(readl(x)) -#define ehci_writel (a, b) writel(cpu_to_be32(b), a) +#define ehci_readl (x) be32_to_cpu(__raw_readl(x)) +#define ehci_writel (a, b) __raw_writel(cpu_to_be32(b), a)#else -#define ehci_readl (x) cpu_to_le32(readl(x)) -#define ehci_writel (a, b) writel(cpu_to_le32(b), a) +#define ehci_readl (x) readl(x) +#define ehci_writel (a, b) writel(b, a)#endif #if definedCONFIG_EHCI_MMIO_BIG_ENDIAN
Signature · 2 lines
Best regards, Marek Vasut