Page MenuHomeFreeBSD

xhci: Refactor xhci_setup_generic code
Needs ReviewPublic

Authored by aokblast on May 20 2026, 4:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jun 11, 3:42 AM
Unknown Object (File)
Sat, Jun 6, 2:38 PM
Unknown Object (File)
Tue, Jun 2, 8:52 AM
Unknown Object (File)
Sun, May 31, 11:59 PM
Unknown Object (File)
Sun, May 31, 1:27 PM
Unknown Object (File)
Fri, May 29, 11:48 PM
Unknown Object (File)
Fri, May 29, 8:50 PM
Unknown Object (File)
Fri, May 29, 8:42 PM
Subscribers

Details

Reviewers
adrian
Group Reviewers
USB
Summary

Our USB TRB buildup subroutines were previously difficult to follow. In
setup_generic_chain_sub(), the routine filled TRB packets based on the
characteristics passed by the caller and the current state (for example,
whether the TRB was the last in the TD).

However, most TRB types (except Normal TRBs) cannot be shared across TDs.
To simplify the logic, refactor xhci_setup_generic() so that TRBs are
constructed according to their transfer type, with dedicated helper
functions for each TRB type.

Note: this patch series was partially refactored with AI assistance.
Originally, I implemented the control, bulk, and interrupt transfer paths
myself. Later, while reviewing the existing code from hps@, I found the
transfer management logic difficult to follow — not the xHCI specification
itself, but the TD chaining and flag handling logic (for example, how TDs
are chained together, what each flag represents, and when flags should be
cleared).

I (my first time) used Claude to help analyze the existing implementation and draft the
isochronous transfer buildup functions, as well as the restructuring needed
for xhci_setup_generic() to use the new helpers.

Afterward, I reviewed the entire implementation against the xHCI
specification to verify correctness. I also tested the changes with several
devices, and everything appears to work properly. Finally, I cleaned up and
refined the AI-generated code further to improve readability and overall
code quality.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 73303
Build 70186: arc lint + arc unit