From: Ladislav Michl <oss-lists@triops.cz>
To: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: linux-usb@vger.kernel.org, Sneeker Yeh <sneeker.yeh@gmail.com>
Subject: Re: xHCI host dies on device unplug
Date: Wed, 21 Dec 2022 13:05:50 +0100 [thread overview]
Message-ID: <Y6L2nnXpkkAJVLgh@lenoch> (raw)
In-Reply-To: <Y6Lbxhc/98QA6dMU@lenoch>
On Wed, Dec 21, 2022 at 11:11:19AM +0100, Ladislav Michl wrote:
> On Wed, Dec 21, 2022 at 11:58:42AM +0200, Mathias Nyman wrote:
> > Looked at that same series and turned patch 1/5 into a standalone quick hack that applies on 6.1
> >
> > Untested, does it work for you?
>
> Applied on the top of you stop_endpoint_fixes, 6.1.0. is a base tree:
> [ 24.800835] xhci-hcd xhci-hcd.0.auto: Delay clearing port-1 CSC
> [ 24.806788] usb 1-1: USB disconnect, device number 2
> [ 28.148451] ieee80211 phy0: rt2x00usb_vendor_request: Error - Vendor Request 0x07 failed for offset 0x101c with error -19
> [ 29.828466] xhci-hcd xhci-hcd.0.auto: xHCI host not responding to stop endpoint command
> [ 29.856656] xhci-hcd xhci-hcd.0.auto: xHCI host controller not responding, assume dead
> [ 29.864804] xhci-hcd xhci-hcd.0.auto: HC died; cleaning up
> [ 29.949460] xhci-hcd xhci-hcd.0.auto: Late clearing port-1 CSC, portsc 0x202a0
>
> What about checking whenever anything is still connected on command timeout
> and considering device autosuspended instead of killing it?
Just completed test run, it is working, but I'd consider it insane at least...
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index b07d3740f554..d7b7faaac647 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1580,6 +1580,21 @@ static bool xhci_pending_command_completion(struct xhci_hcd *xhci)
return false;
}
+static bool xhci_is_anything_connected(struct xhci_hcd *xhci)
+{
+ struct usb_hcd *hcd = xhci_to_hcd(xhci);
+ struct xhci_hub *rhub = xhci_get_rhub(hcd);
+ struct xhci_port **ports = rhub->ports;
+ int i, max_ports = rhub->num_ports;
+
+ max_ports = rhub->num_ports;
+ for (i = 0; i < max_ports; i++)
+ if (PORT_CONNECT & readl(ports[i]->addr))
+ return true;
+
+ return false;
+}
+
void xhci_handle_command_timeout(struct work_struct *work)
{
struct xhci_hcd *xhci;
@@ -1587,7 +1602,6 @@ void xhci_handle_command_timeout(struct work_struct *work)
char str[XHCI_MSG_MAX];
u64 hw_ring_state;
u32 cmd_field3;
- u32 usbsts;
xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer);
@@ -1602,9 +1616,9 @@ void xhci_handle_command_timeout(struct work_struct *work)
return;
}
- cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]);
- usbsts = readl(&xhci->op_regs->status);
- xhci_dbg(xhci, "Command timeout, USBSTS:%s\n", xhci_decode_usbsts(str, usbsts));
+ xhci_dbg(xhci, "Command timeout, USBSTS:%s, USBCMD: %08x\n",
+ xhci_decode_usbsts(str, readl(&xhci->op_regs->status)),
+ readl(&xhci->op_regs->command));
/* Did hw complete the command but event handler was blocked? */
if (xhci_pending_interrupt(xhci) > 0 &&
@@ -1616,10 +1630,16 @@ void xhci_handle_command_timeout(struct work_struct *work)
return;
}
+ cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]);
/* Bail out and tear down xhci if a stop endpoint command failed */
if (TRB_FIELD_TO_TYPE(cmd_field3) == TRB_STOP_RING) {
struct xhci_virt_ep *ep;
+ if (!(xhci_is_anything_connected(xhci))) {
+ xhci_info(xhci, "xHCI autosuspended?\n");
+ goto time_out_completed;
+ }
+
xhci_warn(xhci, "xHCI host not responding to stop endpoint command\n");
ep = xhci_get_virt_ep(xhci, TRB_TO_SLOT_ID(cmd_field3),
next prev parent reply other threads:[~2022-12-21 12:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 21:27 xHCI host dies on device unplug Ladislav Michl
2022-12-06 13:17 ` Ladislav Michl
2022-12-15 16:12 ` Ladislav Michl
2022-12-16 10:13 ` Mathias Nyman
2022-12-16 21:32 ` Ladislav Michl
2022-12-19 12:25 ` Mathias Nyman
2022-12-19 18:31 ` Ladislav Michl
2022-12-19 21:45 ` Ladislav Michl
2022-12-20 7:58 ` Ladislav Michl
2022-12-21 9:46 ` Mathias Nyman
2022-12-21 7:14 ` Ladislav Michl
2022-12-21 9:58 ` Mathias Nyman
2022-12-21 10:11 ` Ladislav Michl
2022-12-21 12:05 ` Ladislav Michl [this message]
2022-12-21 12:12 ` Mathias Nyman
2022-12-21 12:21 ` Ladislav Michl
2022-12-19 7:11 ` Ladislav Michl
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=Y6L2nnXpkkAJVLgh@lenoch \
--to=oss-lists@triops.cz \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=sneeker.yeh@gmail.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;
as well as URLs for NNTP newsgroup(s).