linux/drivers/usb/host
Lachlan Hodges 3d26cd1f3f usb: xhci: use BIT_ULL for CRCR bits to fix incorrect 64bit mask
xhci is unusable on some systems after driver switched to BIT() macro.
Upper 32bits of 64bit CRCR command register are unintentionally cleared.

Seen on a raspberry pi 4B compiled for arm32.
The main symptoms were the following log message:

[    0.549897] raspberrypi-firmware soc:firmware: Attached to firmware from 2021-02-25T12:11:39
[    0.626859] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    0.626889] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 1
[    0.812619] xhci_hcd 0000:01:00.0: hcc params 0x002841eb hci version 0x100 quirks 0x0000200000000890
[    0.813188] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    0.813203] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 2
[    0.813219] xhci_hcd 0000:01:00.0: Host supports USB 3.0 SuperSpeed
[    0.813602] hub 1-0:1.0: USB hub found
[    0.814052] hub 2-0:1.0: USB hub found
[    0.952714] xhci_hcd 0000:01:00.0: ERROR mismatched command completion event

Additionally running lsusb just hangs. Running the same kernel compiled
for aarch64 worked fine. Bisected to the commit in the Fixes line.
Additionally a USB device plugged in to the USB3.0 (or 2.0) did not
enumerate. Once this patch is applied the USB device enumerates properly.

The CRCR register is 64 bits wide - commit abe93f27cd
("xhci: use BIT macro") changed the flag definitions from (1 << n),
a signed int, to BIT(n), an unsigned long. Within
xhci_set_cmd_ring_deq(), the following operation is performed on the
CRCR register:

...
	crcr &= ~CMD_RING_PTR_MASK;
	crcr |= deq_dma;
	crcr &= ~CMD_RING_CYCLE;
	crcr |= xhci->cmd_ring->cycle_state;
...

Previously, ~CMD_RING_CYCLE was ~(int)1, a negative signed value
(0xFFFFFFFE with the sign bit set). Widening a negative signed int to
u64 sign-extends it to 0xFFFFFFFFFFFFFFFE, correctly clearing only bit
0 and preserving the 64-bit pointer written two lines above.

After the change when running on 32 bit kernels, ~CMD_RING_CYCLE is
~(unsigned long)1UL. On a 32-bit host this is an unsigned 32-bit
value (0xFFFFFFFE, no sign bit). Widening an unsigned value to u64
zero-extends it instead (0x00000000FFFFFFFE), so the subsequent AND
silently clears bits 63:32 of crcr, truncating the command ring
pointer that was just written before the value reaches hardware.

To fix, similar to how CMD_RING_PTR_MASK is defined, make sure we
use the BIT_ULL variant when defining the CRCR bits.

[Mathias: use BIT_ULL() for ERST_EHB and EP_CTX_CYCLE_MASK as suggested
by Michal Pecio, also include raspberry case in commit message]

Fixes: abe93f27cd ("xhci: use BIT macro")
Cc: stable <stable@kernel.org>
Assisted-by: Claude:claude-sonnet-5
cc: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Lachlan Hodges <lachlan.hodges@morsemicro.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://patch.msgid.link/20260804083639.2148950-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-08-04 10:54:57 +02:00
..
bcma-hcd.c USB: bcma: Remove unused of_gpio.h 2024-11-04 01:27:52 +01:00
ehci-atmel.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-brcm.c usb: ehci-brcm: fix sleep during atomic 2026-03-30 17:04:13 +02:00
ehci-dbg.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ehci-exynos.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-fsl.c usb: ehci-fsl: Fix use of private data to avoid -Wflex-array-member-not-at-end warning 2025-04-11 16:08:33 +02:00
ehci-fsl.h
ehci-grlib.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-hcd.c USB: HCD: remove logic about which hcd is loaded 2026-01-14 15:59:00 +01:00
ehci-hub.c usb: ehci: add workaround for chipidea PORTSC.PEC bug 2023-08-09 14:16:06 +02:00
ehci-mem.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
ehci-mv.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-npcm7xx.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-omap.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-orion.c usb: ehci-orion: remove optional PHY handling code remnants 2026-03-11 14:59:42 +01:00
ehci-pci.c PCI: Add ASPEED vendor ID to pci_ids.h 2026-01-09 14:21:16 -06:00
ehci-platform.c usb: host: ehci-platform: Call reset assert/deassert on suspend/resume 2025-11-21 15:11:22 +01:00
ehci-ppc-of.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-ps3.c
ehci-q.c USB: Use EHCI control transfer pid macros instead of constant values. 2024-03-26 10:43:35 +01:00
ehci-sched.c usb: free iso schedules on failed submit 2026-07-08 13:30:38 +02:00
ehci-sh.c usb: ehci-hcd: fix call balance of clocks handling routines 2024-12-04 16:25:13 +01:00
ehci-spear.c usb: ehci-spear: fix call balance of sehci clk handling routines 2024-11-16 09:04:06 +01:00
ehci-st.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci-sysfs.c usb: ehci: replace scnprintf() with sysfs_emit() 2025-06-24 15:40:19 +01:00
ehci-timer.c
ehci-xilinx-of.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ehci.h USB: Use EHCI control transfer pid macros instead of constant values. 2024-03-26 10:43:35 +01:00
fhci-dbg.c
fhci-hcd.c usb: fhci: use kzalloc_flex for priv struct 2026-03-18 16:00:34 +01:00
fhci-hub.c
fhci-mem.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
fhci-q.c
fhci-sched.c usb: host: fix typo in the comment 2024-10-04 15:08:37 +02:00
fhci-tds.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fhci.h usb: fhci: use kzalloc_flex for priv struct 2026-03-18 16:00:34 +01:00
fsl-mph-dr-of.c usb: fsl-mph-dr-of: Remove unnecessary NULL check before clk_disable_unprepare() 2025-06-19 12:27:29 +02:00
isp116x-hcd.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
isp116x.h
Kconfig usb: host: add ARCH_AIROHA in XHCI MTK dependency 2026-05-22 11:35:47 +02:00
Makefile usb: xhci-pci: add AMD Promontory 21 PCI glue 2026-05-21 16:48:40 +02:00
max3421-hcd.c usb: host: max3421: Reject hub port requests for non-existent ports 2026-05-22 11:35:18 +02:00
octeon-hcd.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
octeon-hcd.h
ohci-at91.c usb: ohci-at91: Use dynamic device name for OHCI HCD creation 2025-06-19 12:27:33 +02:00
ohci-da8xx.c usb: ohci-da8xx: remove unused platform data 2025-11-21 15:13:56 +01:00
ohci-dbg.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ohci-exynos.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci-hcd.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
ohci-hub.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
ohci-mem.c
ohci-nxp.c usb: ohci-nxp: clean up probe error labels 2025-12-23 15:48:46 +01:00
ohci-omap.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci-pci.c USB: OHCI: Add quirk for LS7A OHCI controller (rev 0x02) 2025-04-11 16:21:20 +02:00
ohci-platform.c USB: OHCI/UHCI: Add soft dependencies on ehci_platform 2026-01-14 16:02:14 +01:00
ohci-ppc-of.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci-ps3.c
ohci-pxa27x.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci-q.c
ohci-s3c2410.c usb: ohci: s3c2410: Drop support for S3C2410 systems 2025-09-06 15:22:51 +02:00
ohci-sa1111.c
ohci-sm501.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci-spear.c usb: ohci-spear: Remove unnecessary NULL check before clk_disable_unprepare() 2025-06-19 12:27:26 +02:00
ohci-st.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
ohci.h usb: Annotate struct urb_priv with __counted_by 2023-10-02 09:48:52 -07:00
oxu210hp-hcd.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
pci-quirks.c USB: pci-quirks: Fix HCCPARAMS register error for LS7A EHCI 2025-02-14 09:18:14 +01:00
pci-quirks.h usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk 2023-10-02 16:19:12 +02:00
r8a66597-hcd.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
r8a66597.h
sl811_cs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sl811-hcd.c usb: sl811-hcd: disable controller wakeup on remove 2026-07-08 13:34:51 +02:00
sl811.h
ssb-hcd.c
uhci-debug.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
uhci-grlib.c usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
uhci-hcd.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
uhci-hcd.h usb: uhci: Add reset control support 2025-10-13 09:11:49 +02:00
uhci-hub.c
uhci-pci.c Merge 6.4-rc4 into usb-next 2023-05-28 15:25:53 +01:00
uhci-platform.c USB: OHCI/UHCI: Add soft dependencies on ehci_platform 2026-01-14 16:02:14 +01:00
uhci-q.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
xen-hcd.c xen/usb: Constify struct hc_driver 2025-10-28 15:35:15 +01:00
xhci-caps.h usb: xhci: Add debugfs support for xHCI Port Link Info (PORTLI) register. 2025-11-21 14:53:01 +01:00
xhci-dbg.c
xhci-dbgcap.c xhci: dbc: support runtime suspend while DbC is in enabled state 2026-06-25 15:10:08 +01:00
xhci-dbgcap.h xhci: dbc: support runtime suspend while DbC is in enabled state 2026-06-25 15:10:08 +01:00
xhci-dbgtty.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
xhci-debugfs.c usb: xhci: Fix debugfs bandwidth reporting 2026-04-02 15:55:36 +02:00
xhci-debugfs.h
xhci-ext-caps.c
xhci-ext-caps.h xhci: Add USB4 tunnel detection for USB3 devices on Intel hosts 2024-09-03 09:54:39 +02:00
xhci-histb.c usb: xhci: change xhci_resume() parameters to explicit the desired info 2025-03-14 09:18:02 +01:00
xhci-hub.c usb: xhci: fix typo in xhci_set_port_power() comment 2026-06-03 19:23:28 +02:00
xhci-mem.c usb: xhci: allocate internal DCBAA mirror dynamically 2026-06-03 19:23:30 +02:00
xhci-mtk-sch.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
xhci-mtk.c usb: xhci-mtk: Use FIELD_MODIFY() 2026-05-21 16:43:04 +02:00
xhci-mtk.h usb: xhci-mtk: correct most kernel-doc problems in xhci-mtk.h 2025-11-21 14:52:37 +01:00
xhci-mvebu.c drivers/usb/host: Fix spelling error 'seperate' -> 'separate' 2026-04-11 12:02:11 +02:00
xhci-mvebu.h usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func 2025-03-14 09:18:02 +01:00
xhci-pci-prom21.c usb: xhci-pci: add AMD Promontory 21 PCI glue 2026-05-21 16:48:40 +02:00
xhci-pci-renesas.c usb: renesas-xhci: Fix External ROM access timeouts 2025-08-13 17:15:59 +02:00
xhci-pci.c usb: xhci-pci: Limit VIA VL805 DMA addressing to 36 bits 2026-07-13 07:10:11 +02:00
xhci-pci.h usb: xhci-pci: add AMD Promontory 21 PCI glue 2026-05-21 16:48:40 +02:00
xhci-plat.c usb: host: xhci-plat: Add .post_resume_quirk for struct xhci_plat_priv 2025-09-17 12:43:17 +02:00
xhci-plat.h usb: host: xhci-plat: Add .post_resume_quirk for struct xhci_plat_priv 2025-09-17 12:43:17 +02:00
xhci-port.h usb: xhci: Add debugfs support for xHCI Port Link Info (PORTLI) register. 2025-11-21 14:53:01 +01:00
xhci-rcar-regs.h usb: host: xhci-rcar: Move R-Car reg definitions 2025-09-17 12:43:16 +02:00
xhci-rcar.c usb: host: xhci-rcar: Split R-Car Gen2 and Gen3 .plat_start() handling 2026-06-03 19:23:37 +02:00
xhci-ring.c usb: xhci: allocate DCBAA based on host controller max slots 2026-06-03 19:23:30 +02:00
xhci-rzg3e-regs.h usb: host: xhci-rcar: Add Renesas RZ/G3E USB3 Host driver support 2025-09-17 12:43:18 +02:00
xhci-rzv2m.c usb: xhci-plat: Don't include xhci.h 2024-04-23 16:25:29 -07:00
xhci-rzv2m.h
xhci-sideband.c xhci: sideband: fix ring sg table pages leak 2026-07-08 13:38:24 +02:00
xhci-tegra.c soc: drivers for 7.2 2026-06-17 11:21:40 -07:00
xhci-trace.c xhci: Move functions to setup msi to xhci-pci 2023-03-23 17:25:22 +01:00
xhci-trace.h usb: xhci: standardize single bit-field macros 2025-11-21 14:53:01 +01:00
xhci.c usb: xhci-pci: Limit VIA VL805 DMA addressing to 36 bits 2026-07-13 07:10:11 +02:00
xhci.h usb: xhci: use BIT_ULL for CRCR bits to fix incorrect 64bit mask 2026-08-04 10:54:57 +02:00