* [PATCH 0/3] xhci features for usb-next
@ 2025-07-17 7:31 Mathias Nyman
2025-07-17 7:31 ` [PATCH 1/3] usb: xhci: Avoid showing errors during surprise removal Mathias Nyman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-07-17 7:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few small xhci changes for usb-next that have been sitting in the list.
The "avg_trb_len = 8" patch is not marked for stable as it only helps a
company with their custom virtual xHC hardware development.
They have a stricter interpretation of an ambiguous part of the xHCI spec.
I don't object to their interpretation, but other existing xHC hardware seem
to work with either way, so skipping the stable flag for now.
Thanks
Mathias
Jay Chen (1):
usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command
Mario Limonciello (2):
usb: xhci: Avoid showing errors during surprise removal
usb: xhci: Avoid showing warnings for dying controller
drivers/usb/host/xhci-mem.c | 2 ++
drivers/usb/host/xhci-ring.c | 7 +++++--
drivers/usb/host/xhci.c | 6 ++++--
3 files changed, 11 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] usb: xhci: Avoid showing errors during surprise removal
2025-07-17 7:31 [PATCH 0/3] xhci features for usb-next Mathias Nyman
@ 2025-07-17 7:31 ` Mathias Nyman
2025-07-17 7:31 ` [PATCH 2/3] usb: xhci: Avoid showing warnings for dying controller Mathias Nyman
2025-07-17 7:31 ` [PATCH 3/3] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command Mathias Nyman
2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-07-17 7:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mario Limonciello, Mathias Nyman
From: Mario Limonciello <mario.limonciello@amd.com>
When a USB4 dock is unplugged from a system it won't respond to ring
events. The PCI core handles the surprise removal event and notifies
all PCI drivers. The XHCI PCI driver sets a flag that the device is
being removed as well.
When that flag is set don't show messages in the cleanup path for
marking the controller dead.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-ring.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 94c9c9271658..2b7415dd4170 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1376,12 +1376,15 @@ static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci,
*/
void xhci_hc_died(struct xhci_hcd *xhci)
{
+ bool notify;
int i, j;
if (xhci->xhc_state & XHCI_STATE_DYING)
return;
- xhci_err(xhci, "xHCI host controller not responding, assume dead\n");
+ notify = !(xhci->xhc_state & XHCI_STATE_REMOVING);
+ if (notify)
+ xhci_err(xhci, "xHCI host controller not responding, assume dead\n");
xhci->xhc_state |= XHCI_STATE_DYING;
xhci_cleanup_command_queue(xhci);
@@ -1395,7 +1398,7 @@ void xhci_hc_died(struct xhci_hcd *xhci)
}
/* inform usb core hc died if PCI remove isn't already handling it */
- if (!(xhci->xhc_state & XHCI_STATE_REMOVING))
+ if (notify)
usb_hc_died(xhci_to_hcd(xhci));
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] usb: xhci: Avoid showing warnings for dying controller
2025-07-17 7:31 [PATCH 0/3] xhci features for usb-next Mathias Nyman
2025-07-17 7:31 ` [PATCH 1/3] usb: xhci: Avoid showing errors during surprise removal Mathias Nyman
@ 2025-07-17 7:31 ` Mathias Nyman
2025-07-17 7:31 ` [PATCH 3/3] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command Mathias Nyman
2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-07-17 7:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mario Limonciello, Mathias Nyman
From: Mario Limonciello <mario.limonciello@amd.com>
When a USB4 dock is unplugged from a system it won't respond to ring
events. The PCI core handles the surprise removal event and notifies
all PCI drivers. The XHCI PCI driver sets a flag that the device is
being removed, and when the device stops responding a flag is also
added to indicate it's dying.
When that flag is set don't bother to show warnings about a missing
controller.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 8a819e853288..47151ca527bf 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -121,7 +121,8 @@ int xhci_halt(struct xhci_hcd *xhci)
ret = xhci_handshake(&xhci->op_regs->status,
STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
if (ret) {
- xhci_warn(xhci, "Host halt failed, %d\n", ret);
+ if (!(xhci->xhc_state & XHCI_STATE_DYING))
+ xhci_warn(xhci, "Host halt failed, %d\n", ret);
return ret;
}
@@ -180,7 +181,8 @@ int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us)
state = readl(&xhci->op_regs->status);
if (state == ~(u32)0) {
- xhci_warn(xhci, "Host not accessible, reset failed.\n");
+ if (!(xhci->xhc_state & XHCI_STATE_DYING))
+ xhci_warn(xhci, "Host not accessible, reset failed.\n");
return -ENODEV;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command
2025-07-17 7:31 [PATCH 0/3] xhci features for usb-next Mathias Nyman
2025-07-17 7:31 ` [PATCH 1/3] usb: xhci: Avoid showing errors during surprise removal Mathias Nyman
2025-07-17 7:31 ` [PATCH 2/3] usb: xhci: Avoid showing warnings for dying controller Mathias Nyman
@ 2025-07-17 7:31 ` Mathias Nyman
2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-07-17 7:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Jay Chen, Mathias Nyman
From: Jay Chen <shawn2000100@gmail.com>
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>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
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 6680afa4f596..07289333a1e8 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1195,6 +1195,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.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-17 7:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 7:31 [PATCH 0/3] xhci features for usb-next Mathias Nyman
2025-07-17 7:31 ` [PATCH 1/3] usb: xhci: Avoid showing errors during surprise removal Mathias Nyman
2025-07-17 7:31 ` [PATCH 2/3] usb: xhci: Avoid showing warnings for dying controller Mathias Nyman
2025-07-17 7:31 ` [PATCH 3/3] usb: xhci: Set avg_trb_len = 8 for EP0 during Address Device Command 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).