Re: [PATCH v3] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command

Mathias Nyman
2025-05-19T13:14:37Z

On 16.5.2025 6.39, Jay Chen wrote:
> According to the xHCI 1.2 spec (Section 6.2.3, p.454), the Average
> TRB Length (avg_trb_len) for control endpoints should be set to 8.

Maybe add here "But section 4.8.2 "Endpoint Context Initialization"
states that all fields of an Input Endpoint Context data structure
(including the Reserved fields) shall be initialized to 0
> > Currently, during the Address Device Command, EP0's avg_trb_len remains 0,
> which may cause some xHCI hardware to reject the Input Context, resulting
> in device enumeration failures. In extreme cases, using a zero avg_trb_len
> in calculations may lead to division-by-zero errors and unexpected system
> crashes.

Would be good to specify here which exact hardware requires avg_trb_len to be
set before the 'Address Device Command'. This way we can later create a
quirk for it in case it turns out other existing controllers can't handle it.

So far it seems other hosts can handle it well, and quirks may not be needed
at all. Thanks to Michał for testing.

Thanks
Mathias

>
> This patch sets avg_trb_len to 8 for EP0 in
> xhci_setup_addressable_virt_dev(), ensuring compliance with the spec
> and improving compatibility across various host controller implementations.

I'd skip the 'compliance with spec..' part as spec is a bit unclear on this
issue.

Thanks
Mathias