Skip to contentSkip to conversation

usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command

PATCH Superseded jay.chen 2 participants 3 messages May 14, 2025 – May 16, 2025

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

jay.chen

author
#0 lore raw

PATCH 1/1 usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command

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.

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.

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.

---
 drivers/usb/host/xhci-mem.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-mem.c +2 -0
index d698095fc88d..fed9e9d1990c 100644
@@ -1166,6 +1166,8 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
 	ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma |
 				   dev->eps[0].ring->cycle_state);
 
+	ep0_ctx->tx_info |= cpu_to_le32(EP_AVG_TRB_LENGTH(8));
+
 	trace_xhci_setup_addressable_virt_device(dev);
 
 	/* Steps 7 and 8 were done in xhci_alloc_virt_device() */
Signature · 1 line
2.43.5
maintainer
#1 lore raw
Quoted 9 lines · jay.chen

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.

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.

Quoted 6 lines

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.

Please use your name, not your email alias.

And as you are now using a gmail account, please set the "From:" line at the top of the patch properly as is documented. Please work with others at your company that know how to do all of this if you have questions.

Also, this is a v2 patch, so always document what changed to warrant a new version.

thanks,

greg k-h

author
#2 lore raw

Hi Greg,

I got it, thank you so much for the effort!

I already patched a newer version

Quoted 30 lines · Greg KH
Quoted 9 lines · jay.chen

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.

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.

Quoted 6 lines

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.

Please use your name, not your email alias.

And as you are now using a gmail account, please set the "From:" line at the top of the patch properly as is documented. Please work with others at your company that know how to do all of this if you have questions.

Also, this is a v2 patch, so always document what changed to warrant a new version.

thanks,

greg k-h