Skip to content

Commit 2521106

Browse files
matnymangregkh
authored andcommitted
usb: hub: Don't try to recover devices lost during warm reset.
Hub driver warm-resets ports in SS.Inactive or Compliance mode to recover a possible connected device. The port reset code correctly detects if a connection is lost during reset, but hub driver port_event() fails to take this into account in some cases. port_event() ends up using stale values and assumes there is a connected device, and will try all means to recover it, including power-cycling the port. Details: This case was triggered when xHC host was suspended with DbC (Debug Capability) enabled and connected. DbC turns one xHC port into a simple usb debug device, allowing debugging a system with an A-to-A USB debug cable. xhci DbC code disables DbC when xHC is system suspended to D3, and enables it back during resume. We essentially end up with two hosts connected to each other during suspend, and, for a short while during resume, until DbC is enabled back. The suspended xHC host notices some activity on the roothub port, but can't train the link due to being suspended, so xHC hardware sets a CAS (Cold Attach Status) flag for this port to inform xhci host driver that the port needs to be warm reset once xHC resumes. CAS is xHCI specific, and not part of USB specification, so xhci driver tells usb core that the port has a connection and link is in compliance mode. Recovery from complinace mode is similar to CAS recovery. xhci CAS driver support that fakes a compliance mode connection was added in commit 8bea2bd ("usb: Add support for root hub port status CAS") Once xHCI resumes and DbC is enabled back, all activity on the xHC roothub host side port disappears. The hub driver will anyway think port has a connection and link is in compliance mode, and hub driver will try to recover it. The port power-cycle during recovery seems to cause issues to the active DbC connection. Fix this by clearing connect_change flag if hub_port_reset() returns -ENOTCONN, thus avoiding the whole unnecessary port recovery and initialization attempt. Cc: [email protected] Fixes: 8bea2bd ("usb: Add support for root hub port status CAS") Tested-by: Łukasz Bartosik <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Acked-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fdfa018 commit 2521106

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/usb/core/hub.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,6 +5751,7 @@ static void port_event(struct usb_hub *hub, int port1)
57515751
struct usb_device *hdev = hub->hdev;
57525752
u16 portstatus, portchange;
57535753
int i = 0;
5754+
int err;
57545755

57555756
connect_change = test_bit(port1, hub->change_bits);
57565757
clear_bit(port1, hub->event_bits);
@@ -5847,8 +5848,11 @@ static void port_event(struct usb_hub *hub, int port1)
58475848
} else if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION)
58485849
|| udev->state == USB_STATE_NOTATTACHED) {
58495850
dev_dbg(&port_dev->dev, "do warm reset, port only\n");
5850-
if (hub_port_reset(hub, port1, NULL,
5851-
HUB_BH_RESET_TIME, true) < 0)
5851+
err = hub_port_reset(hub, port1, NULL,
5852+
HUB_BH_RESET_TIME, true);
5853+
if (!udev && err == -ENOTCONN)
5854+
connect_change = 0;
5855+
else if (err < 0)
58525856
hub_port_disable(hub, port1, 1);
58535857
} else {
58545858
dev_dbg(&port_dev->dev, "do warm reset, full device\n");

0 commit comments

Comments
 (0)