From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <linux-usb@vger.kernel.org>
Cc: raoxu@uniontech.com, michal.pecio@gmail.com,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [RFT PATCH 2/3] xhci: prevent endpoint recovery after roothub disconnect
Date: Mon, 29 Jun 2026 15:30:30 +0300 [thread overview]
Message-ID: <20260629123031.142133-3-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20260629123031.142133-1-mathias.nyman@linux.intel.com>
Prevent transfer retry and endpoint recovery if the device or its parent
disconnected from the roothub. Just like link error case.
There is a suspicion some xHC controllers may stop processing endpoint
related commands after the last USB device disconnects from the host.
Disconnect often causes transaction errors, xhci driver tries to (soft)
reset and restart the endpoint to recover it.
Hub driver again will cancel all pending URBs once disconnect is detected,
stopping the endpoint right after (soft) reset restarted it.
xHC controller sometimes fail to complete the stop endpoint command,
leading to driver timing out, and tearing down xhci
Prevent extra endpoint (soft) reset after xhci driver is aware of the
parent roothub port disconnect.
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-ring.c | 12 ++++++++----
drivers/usb/host/xhci.h | 1 +
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 020e924c1ced..5e9efd3aa629 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -986,14 +986,16 @@ static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
struct xhci_td *td,
enum xhci_ep_reset_type reset_type)
{
+ struct xhci_port *rhub_port = ep->vdev->rhub_port;
unsigned int slot_id = ep->vdev->slot_id;
int err;
/*
- * Avoid resetting endpoint if link is inactive. Can cause host hang.
- * Device will be reset soon to recover the link so don't do anything
+ * Avoid resetting endpoint if link is inactive or device disonnected.
+ * Can cause host hang.
+ * Device will be reset to recover an inactive link, so don't do anything
*/
- if (ep->vdev->rhub_port->link_inactive)
+ if (rhub_port->link_inactive || !rhub_port->connected)
return -ENODEV;
/* add td to cancelled list and let reset ep handler take care of it */
@@ -2053,8 +2055,10 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
* Tag broken links to avoid retries while hub driver sorts it out.
* Link status is not relible while port is in reset.
*/
- if (!(portsc & PORT_RESET))
+ if (!(portsc & PORT_RESET)) {
port->link_inactive = (pls == XDEV_INACTIVE);
+ port->connected = !!(portsc & PORT_CONNECT);
+ }
if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
xhci_dbg(xhci, "port resume event for port %d\n", port_id);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 717a7fd60a76..fd5533bdb261 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1471,6 +1471,7 @@ struct xhci_port {
struct xhci_hub *rhub;
struct xhci_port_cap *port_cap;
unsigned int link_inactive:1;
+ unsigned int connected:1;
unsigned int lpm_incapable:1;
unsigned long resume_timestamp;
bool rexit_active;
--
2.43.0
next prev parent reply other threads:[~2026-06-29 12:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 12:30 [RFT PATCH 0/3] xhci: avoid futile stop endpoint command and host teardown Mathias Nyman
2026-06-29 12:30 ` [RFT PATCH 1/3] xhci: include all root port children in recovery prevention on link error Mathias Nyman
2026-06-29 12:30 ` Mathias Nyman [this message]
2026-06-29 12:30 ` [RFT PATCH 3/3] xhci: avoid xHC endpoint changes after disconnect or " Mathias Nyman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260629123031.142133-3-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=michal.pecio@gmail.com \
--cc=raoxu@uniontech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox