Skip to content

EHCI driver: USB keyboards and mice on Intel 6-series and older chipsets (fixes #113) - #115

Merged
v3nn7 merged 1 commit into
mainfrom
v3nn7/sweet-archimedes-d75mf2
Nov 10, 2026
Merged

v3nn7 merged 1 commit into
mainfrom
v3nn7/sweet-archimedes-d75mf2

Conversation

@v3nn7

@v3nn7 v3nn7 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

What does this change?

Fixes #113: on an ASUS P8Z68-V LX (Intel Z68, i5-2500K) the USB mouse did not work, and the keyboard stopped working once it was plugged in again.

Root cause. Intel chipsets up to the 6 series have no xHCI: their USB ports belong to EHCI controllers, and OSyx only drove xHCI. The keyboard worked only through the firmware's emulation of a PS/2 keyboard, which does not survive plugging in again. The firmware emulates no mouse, so there was none.

Fix: an EHCI driver (kernel/src/drivers/ehci.rs):

  • takes each controller from the firmware at boot (USBLEGSUP handoff, USB SMIs off), before the PS/2 driver starts
  • control transfers on the asynchronous schedule; HID interrupt endpoints on the periodic schedule, polled every frame
  • root ports and hubs, including Intel's rate matching hub behind each root port: low and full-speed keyboards and mice behind it get split transactions through its transaction translator; the hub's status change endpoint reports plugging
  • plugging and unplugging at root and hub ports, keyboard LEDs
  • usb.ehci=off on the kernel command line leaves the controllers to the firmware, as before

Register layouts, queue heads, qTDs and split masks are in osyx-usb (drivers/usb/src/ehci.rs) with host tests. The HID setup (boot keyboards, mice, tablets) moves out of the xHCI driver into kernel/src/drivers/usbhid.rs, shared by both drivers. pci::Address::write8 was added for the firmware semaphore byte.

How was it tested?

  • cargo test -p osyx-usb: 50 passed (5 new EHCI tests)
  • cargo clippy on osyx-usb (-D warnings) and the kernel: no findings in the new code
  • QEMU (q35, OVMF, TCG), live ISO from scripts/build-linux.sh:
    • usb-ehci with usb-kbd + usb-tablet as the only input devices: typing and clicking work; QMP device_del / device_add of both, then typing opens Files
    • ich9-usb-ehci1 beside qemu-xhci: devices on both controllers work
    • qemu-xhci keyboard replug after the HID refactor: works
    • usb.ehci=off: controllers left to the firmware

Limitations or screenshots

  • Not tested on real hardware. QEMU's HID devices are high-speed on EHCI and its usb-hub is full-speed, so the split transactions Intel's rate matching hub needs (the reporter's case) are covered only by host tests of the queue head encoding. A run on the reporter's machine is needed.
  • EHCI configures HID devices and hubs only; USB sticks on EHCI ports are logged and left alone.
  • No UHCI/OHCI: low and full-speed devices on older chipsets with companion controllers (ICH9/ICH10) still do not work.
  • Interrupt endpoints are polled every 1 ms regardless of bInterval.

Labels

Labels: bug, drivers, kernel


Generated by Claude Code

… and older)

Fixes #113. On an ASUS P8Z68-V LX (Intel Z68) USB mice did not work and a
keyboard stopped working after it was plugged in again. Intel chipsets up
to the 6 series have no xHCI: their USB ports belong to EHCI controllers,
which OSyx did not drive. The keyboard only worked through the firmware's
emulation of a PS/2 keyboard, which does not survive plugging, and there
was no mouse at all.

The new driver (kernel/src/drivers/ehci.rs) takes each EHCI controller
from the firmware at boot (USBLEGSUP handoff, USB SMIs off), before the
PS/2 driver starts, and runs it in its own thread:

- control transfers on the asynchronous schedule, unlinked with the async
  advance doorbell before their memory is reused
- HID interrupt endpoints on the periodic schedule, polled every frame
- root ports and hubs, including Intel's rate matching hub behind each root
  port: low and full-speed keyboards and mice behind it get split
  transactions through its transaction translator; a hub's status change
  endpoint reports plugging, so control traffic only happens then
- plugging and unplugging at root ports and hub ports
- keyboard LEDs

Register layouts, queue heads, qTDs and split masks are in osyx-usb
(drivers/usb/src/ehci.rs) with host tests. The HID setup (boot keyboards,
mice, tablets) moves from the xHCI driver to drivers/usbhid.rs and is
shared by both drivers. `usb.ehci=off` on the kernel command line leaves
the controllers to the firmware, as before.

Checked in QEMU with usb-ehci and ich9-usb-ehci1 (alone and beside
qemu-xhci): keyboard and tablet work, and work again after QMP
device_del/device_add. The xHCI keyboard also works after the same replug.
QEMU cannot model split transactions behind a high-speed hub, so the path
Intel's rate matching hub needs has host tests only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K22juFHFi5Lsqrq5dG
@v3nn7 v3nn7 added bug Something isn't working kernel Area: kernel drivers Area: drivers labels Nov 10, 2026 — with Claude
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing v3nn7/sweet-archimedes-d75mf2 (1b1665e) with main (5453738)

Open in CodSpeed

@v3nn7
v3nn7 marked this pull request as ready for review November 10, 2026 10:55
@v3nn7
v3nn7 merged commit 7745b7a into main Nov 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working drivers Area: drivers kernel Area: kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Mouse problem – The mouse is not working.

2 participants