* [PATCH v5] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command
@ 2025-05-21 11:40 Jay Chen
2025-06-21 13:21 ` Jay Chen
0 siblings, 1 reply; 3+ messages in thread
From: Jay Chen @ 2025-05-21 11:40 UTC (permalink / raw)
To: mathias.nyman, gregkh; +Cc: linux-usb, linux-kernel, jay.chen, Jay Chen
There is a subtle contradiction between sections of the xHCI 1.2 spec
regarding the initialization of Input Endpoint Context fields. Section
4.8.2 ("Endpoint Context Initialization") states that all fields should
be initialized to 0. However, Section 6.2.3 ("Endpoint Context", p.453)
specifies that the Average TRB Length (avg_trb_len) field shall be
greater than 0, and explicitly notes (p.454): "Software shall set
Average TRB Length to '8' for control endpoints."
Strictly setting all fields to 0 during initialization conflicts with
the specific recommendation for control endpoints. In practice, setting
avg_trb_len = 0 is not meaningful for the hardware/firmware, as the
value is used for bandwidth calculation.
Motivation: Our company is developing a custom Virtual xHC hardware
platform that strictly follows the xHCI spec and its recommendations.
During validation, we observed that enumeration fails and a parameter
error (TRB Completion Code = 5) is reported if avg_trb_len for EP0 is
not set to 8 as recommended by Section 6.2.3. This demonstrates the
importance of assigning a meaningful, non-zero value to avg_trb_len,
even in virtualized or emulated environments.
This patch explicitly sets avg_trb_len to 8 for EP0 in
xhci_setup_addressable_virt_dev(), as recommended in Section 6.2.3, to
prevent potential issues with xHCI host controllers that enforce the
spec strictly.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=220033
Signed-off-by: Jay Chen <shawn2000100@gmail.com>
---
Change log:
v5:
- Move changelog to below the '---' line as required by kernel patch format.
v4:
- Clarify relevant spec sections and document their conflict.
- Remove language about "ensuring compliance with the spec" per reviewer suggestion.
- Update assignment to use '=' instead of '|='.
v3:
- Corrected author name in commit metadata and added changelog.
v2:
- Fixed malformed patch formatting issue.
---
drivers/usb/host/xhci-mem.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d698095fc88d..26d0ab37bd5b 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -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() */
--
2.43.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v5] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command
2025-05-21 11:40 [PATCH v5] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command Jay Chen
@ 2025-06-21 13:21 ` Jay Chen
2025-06-25 13:28 ` Mathias Nyman
0 siblings, 1 reply; 3+ messages in thread
From: Jay Chen @ 2025-06-21 13:21 UTC (permalink / raw)
To: shawn2000100; +Cc: gregkh, jay.chen, linux-kernel, linux-usb, mathias.nyman
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 68 bytes --]
Hi Greg, maintainers,
friendly bump — anyone any thoughts?
Thx.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v5] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command
2025-06-21 13:21 ` Jay Chen
@ 2025-06-25 13:28 ` Mathias Nyman
0 siblings, 0 replies; 3+ messages in thread
From: Mathias Nyman @ 2025-06-25 13:28 UTC (permalink / raw)
To: Jay Chen; +Cc: gregkh, jay.chen, linux-kernel, linux-usb, mathias.nyman
On 21.6.2025 16.21, Jay Chen wrote:
> Hi Greg, maintainers,
>
> friendly bump — anyone any thoughts?
>
Added to queue
Thanks
-Mathias
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-25 13:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-21 11:40 [PATCH v5] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command Jay Chen
2025-06-21 13:21 ` Jay Chen
2025-06-25 13:28 ` Mathias Nyman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).