Page MenuHomeFreeBSD

xhci: Refactor xhci_setup_generic code
ClosedPublic

Authored by aokblast on May 20 2026, 4:13 PM.
Tags
None
Referenced Files
F166316278: D57130.id178214.diff
Wed, Aug 12, 8:55 PM
F166306187: D57130.id178214.diff
Wed, Aug 12, 7:20 PM
Unknown Object (File)
Wed, Aug 12, 5:40 PM
Unknown Object (File)
Wed, Aug 12, 12:38 AM
Unknown Object (File)
Tue, Aug 11, 8:58 PM
Unknown Object (File)
Mon, Aug 10, 10:26 AM
Unknown Object (File)
Mon, Aug 10, 10:26 AM
Unknown Object (File)
Mon, Aug 10, 10:26 AM
Subscribers

Details

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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

  • xhci: Refactor xhci_generic_setup code
  • AI fixed
  • AI fix: 2

@adrian If you don't have any concern, I will merge this patch tomorrow.

  • AI fixed
  • AI fix: 2
  • fixup! xhci: Refactor xhci_generic_setup code
This revision was not accepted when it landed; it landed in state Needs Review.Sat, Jul 25, 1:50 AM
This revision was automatically updated to reflect the committed changes.