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.