]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xhci: fix stale flag preventig URBs after link state error is cleared
authorMathias Nyman <mathias.nyman@linux.intel.com>
Fri, 7 Nov 2025 16:28:16 +0000 (18:28 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 9 Nov 2025 01:54:44 +0000 (10:54 +0900)
A usb device caught behind a link in ss.Inactive error state needs to
be reset to recover. A VDEV_PORT_ERROR flag is used to track this state,
preventing new transfers from being queued until error is cleared.

This flag may be left uncleared if link goes to error state between two
resets, and print the following message:

"xhci_hcd 0000:00:14.0: Can't queue urb, port error, link inactive"

Fix setting and clearing the flag.

The flag is cleared after hub driver has successfully reset the device
when hcd->reset_device is called. xhci-hcd issues an internal "reset
device" command in this callback, and clear all flags once the command
completes successfully.

This command may complete with a context state error if slot was recently
reset and is already in the defauilt state. This is treated as a success
but flag was left uncleared.

The link state field is also unreliable if port is currently in reset,
so don't set the flag in active reset cases.
Also clear the flag immediately when link is no longer in ss.Inactive
state and port event handler detects a completed reset.

This issue was discovered while debugging kernel bugzilla issue 220491.
It is likely one small part of the problem, causing some of the failures,
but root cause remains unknown

Link: https://bugzilla.kernel.org/show_bug.cgi?id=220491
Fixes: b8c3b718087b ("usb: xhci: Don't try to recover an endpoint if port is in error state.")
Cc: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://patch.msgid.link/20251107162819.1362579-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c
drivers/usb/host/xhci.c

index 8e209aa33ea75796629dae81a8aa6267ba54f76f..5bdcf9ab2b99d7153b0157072f83b854431e37c6 100644 (file)
@@ -1985,6 +1985,7 @@ static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci)
 
 static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
 {
+       struct xhci_virt_device *vdev = NULL;
        struct usb_hcd *hcd;
        u32 port_id;
        u32 portsc, cmd_reg;
@@ -2016,6 +2017,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
                goto cleanup;
        }
 
+       if (port->slot_id)
+               vdev = xhci->devs[port->slot_id];
+
        /* We might get interrupts after shared_hcd is removed */
        if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) {
                xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n");
@@ -2038,10 +2042,11 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
                usb_hcd_resume_root_hub(hcd);
        }
 
-       if (hcd->speed >= HCD_USB3 &&
-           (portsc & PORT_PLS_MASK) == XDEV_INACTIVE) {
-               if (port->slot_id && xhci->devs[port->slot_id])
-                       xhci->devs[port->slot_id]->flags |= VDEV_PORT_ERROR;
+       if (vdev && (portsc & PORT_PLS_MASK) == XDEV_INACTIVE) {
+               if (!(portsc & PORT_RESET))
+                       vdev->flags |= VDEV_PORT_ERROR;
+       } else if (vdev && portsc & PORT_RC) {
+               vdev->flags &= ~VDEV_PORT_ERROR;
        }
 
        if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
@@ -2099,7 +2104,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
                 * so the roothub behavior is consistent with external
                 * USB 3.0 hub behavior.
                 */
-               if (port->slot_id && xhci->devs[port->slot_id])
+               if (vdev)
                        xhci_ring_device(xhci, port->slot_id);
                if (bus_state->port_remote_wakeup & (1 << hcd_portnum)) {
                        xhci_test_and_clear_bit(xhci, port, PORT_PLC);
index 0cb45b95e4f5fed0dee9e2e6bef110f51d94e236..a148a128012638ee4d907366f6378c2de0995c55 100644 (file)
@@ -4007,6 +4007,7 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,
                                xhci_get_slot_state(xhci, virt_dev->out_ctx));
                xhci_dbg(xhci, "Not freeing device rings.\n");
                /* Don't treat this as an error.  May change my mind later. */
+               virt_dev->flags = 0;
                ret = 0;
                goto command_cleanup;
        case COMP_SUCCESS: