Repository navigation
fix(usb/ehci): correct the USBCMD and PORTSC bit definitions - #105
Merged
FengHeting merged 3 commits intoOct 20, 2026
Merged
Conversation
Two groups of EHCI register bits did not match EHCI 1.0 (sections 2.3.1
and 2.3.9) or Linux's include/linux/usb/ehci_def.h:
USBCMD ASE bit 2 -> bit 5 (bits 3:2 are Frame List Size)
PSE bit 3 -> bit 4
PORTSC CSC bit 17 -> bit 1 (bits 19:16 are Port Test Control)
PED bit 1 -> bit 2
PEC bit 18 -> bit 3
Together they kept every EHCI device from enumerating:
- After the port reset, ehci_port_reset() tested "PED" but read CSC,
which the worker had already cleared, so a high-speed device looked
not enabled and the port was handed to the companion (-ENODEV).
- With that fixed, "ASE" landed in the Frame List Size field, which
QEMU rejects ("attempt to set frame list size"), so the async
schedule never started and the first SET_ADDRESS timed out
(-ETIMEDOUT).
Tested in QEMU (q35, usb-ehci + usb-storage): before, "usb-ehci: Port
0 enumeration failed: -19" and no /dev/sda; with only the PORTSC fix,
-110; with both, /dev/sda appears.
Signed-off-by: JiTianYu391 <smallcuteshb@outlook.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rainy101112
previously approved these changes
Oct 18, 2026
EHCI_CMD_ASYNC was defined at USBCMD bit 8, but bits 9:8 are the park mode count and the park enable is bit 11. Replace it with the park count field and EHCI_CMD_PARK. EHCI_PORT_PTC_SHIFT pointed at bits 6:3 instead of the port test control field at bits 19:16, so it overlapped PEC, OCA, OCC and FPR. The QH endpoint-capability block defined C at bits 1:0 and RL at bits 7:4. Neither field exists there: C is the control endpoint flag at bit 27 (already covered by EHCI_QH_CONTROL) and RL is the NAK counter reload at bits 31:28. Drop the bogus pair and give RL its real field. EHCI_HCS_NCC and EHCI_HCS_NPCC were named the wrong way round: bits 11:8 are N_PCC and bits 15:12 are N_CC. None of the corrected macros had users, so no generated code changes. Signed-off-by: MicroFish <2609948707@qq.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
clang-format lines up the USBCMD macros with the longer park count field added by the previous change. Signed-off-by: MicroFish <2609948707@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
include/drivers/usb/host/ehci/ehci.h里两组寄存器位与 EHCI 1.0 规范(2.3.1 / 2.3.9)以及 Linuxinclude/linux/usb/ehci_def.h不一致,导致 EHCI 上的任何设备都无法枚举。故障链
ehci_port_reset()检查"PED",实际读到的是 CSC(已被 worker 清掉),于是把高速设备误判为"未使能",置 PO 交给伴随控制器 →Port 0 enumeration failed: -19。hcd-ehci.c: attempt to set frame list size),异步调度从未启动,第一个 SET_ADDRESS 超时 →-110。两处缺一不可。只改头文件,
ehci.c无改动。测试(QEMU q35,
usb-ehci+usb-storage)enumeration failed: -19,无/dev/sdaenumeration failed: -110enumeration failed: -19/dev/sda出现QEMU trace(修复前):内核写
USBCMD = 0x5,QEMU 记录为0x1,ASE 被丢弃。备注
EHCI_PORT_PTC_*的位置也不对,但没有任何代码使用,为保持改动最小未动。CONFIG_VIRTIO_GPU:当前 develop 的virtgpu_vq.c有static ratelimit重定义编译错误,与本 PR 无关。🤖 Generated with Claude Code