Skip to contentSkip to conversation

xhci: Handle missing USB2 resume events on Etron hosts

PATCH New Kuangyi Chiang 2 participants 2 messages Nov 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xhci: Handle missing USB2 resume events on Etron hosts

On Etron xHCs, a USB2 remote wakeup may also move other suspended USB2 ports into the resume state without generating individual Port Status Change Events.

The issue can be reproduced as follows:

1. Disable autosuspend for the USB2 root hub by setting its power/control to "on".
2. Connect two USB2 hubs to the Etron xHC.
3. Wait for both USB2 hubs to autosuspend.
4. Connect a mouse to one of the USB2 hubs.
5. Connect another mouse to the other hub. The second mouse does not work.

The affected USB2 ports may remain in the resume state, preventing newly connected devices from enumerating. Reconnecting an affected hub or mouse does not help. Reloading the xHCI driver restores normal operation.

When handling a USB2 resume event on an Etron xHC, check whether other USB2 ports are also in the resume state and track them so normal resume handling can complete.

Before the patch, the root hub status bitmap reported only port 2 (evt 0004), leaving port 1 in the resume state.

[ 4928.200011] xhci_hcd 0000:02:00.0: Port change event, 5-2, id 2, portsc: 0x400fe3
[ 4928.200087] xhci_hcd 0000:02:00.0: port resume event for port 2
[ 4928.200095] xhci_hcd 0000:02:00.0: resume HS port 2
[ 4928.241196] hub 5-0:1.0: state 7 ports 4 chg 0000 evt 0004
[ 4928.369244] usb usb5-port2: resume, status 0

After the patch, the bitmap includes both ports (evt 0006), allowing port 1 to complete the normal resume process.

[ 6277.946923] xhci_hcd 0000:02:00.0: Port change event, 5-2, id 2, portsc: 0x400fe3
[ 6277.946998] xhci_hcd 0000:02:00.0: port resume event for port 2
[ 6277.947005] xhci_hcd 0000:02:00.0: resume HS port 2
[ 6277.947013] xhci_hcd 0000:02:00.0: HS port 1 in resume without event, portsc: 0xfe3
[ 6277.987265] hub 5-0:1.0: state 7 ports 4 chg 0000 evt 0006
[ 6278.010733] usb usb5-port1: resume, status 0
[ 6278.145273] usb usb5-port2: resume, status 0

Tested on Etron EJ168 (1b6f:7023) and EJ188 (1b6f:7052) with root hub autosuspend disabled.

---
Changes in v2:
- Update the reproduction steps and logs in the commit message.
The issue can be reproduced with root hub autosuspend disabled,
as reported by Michal Pecio.
- No code changes.
- Link to v1: https://lore.kernel.org/all/[email protected]/

 drivers/usb/host/xhci-ring.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/usb/host/xhci-ring.c +35 -0
index fffd901..c640952 100644
@@ -1997,6 +1997,39 @@ static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci)
 	} while (!(pll_lock_check & 0x1) && --retry_count);
 }
 
+/*
+ * Etron xHCs may resume other suspended USB2 ports without generating
+ * individual Port Status Change Events. Track those ports so the normal
+ * USB2 resume handling can finish.
+ */
+static void xhci_handle_etron_usb2_resume(struct xhci_hcd *xhci)
+{
+	struct xhci_hub *rhub = &xhci->usb2_rhub;
+	struct xhci_bus_state *bus_state = &rhub->bus_state;
+	struct xhci_port *port;
+	unsigned int i;
+	u32 portsc;
+
+	for (i = 0; i < rhub->num_ports; i++) {
+		if (test_bit(i, &bus_state->resuming_ports))
+			continue;
+
+		port = rhub->ports[i];
+		portsc = xhci_portsc_readl(port);
+		if ((portsc & PORT_RESET) || !(portsc & PORT_PE))
+			continue;
+
+		if ((portsc & PORT_PLS_MASK) == XDEV_RESUME) {
+			xhci_dbg(xhci, "HS port %d in resume without event, portsc: 0x%x\n",
+				 port->hw_portnum + 1, portsc);
+			port->resume_timestamp = jiffies +
+				msecs_to_jiffies(USB_RESUME_TIMEOUT);
+			set_bit(i, &bus_state->resuming_ports);
+			usb_hcd_start_port_resume(&rhub->hcd->self, i);
+		}
+	}
+}
+
 static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
 {
 	struct xhci_virt_device *vdev = NULL;
@@ -2103,6 +2136,8 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
 			mod_timer(&hcd->rh_timer,
 				  port->resume_timestamp);
 			usb_hcd_start_port_resume(&hcd->self, hcd_portnum);
+			if (xhci->quirks & XHCI_ETRON_HOST)
+				xhci_handle_etron_usb2_resume(xhci);
 			bogus_port_status = true;
 		}
 	}
Signature · 1 line
2.25.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

On Etron xHCs, a USB2 remote wakeup may also move other suspended USB2 ports into the resume state without generating individual Port Status Change Events.

The issue can be reproduced as follows:

1. Disable autosuspend for the USB2 root hub by setting its power/control to "on".
2. Connect two USB2 hubs to the Etron xHC.
3. Wait for both USB2 hubs to autosuspend.
4. Connect a mouse to one of the USB2 hubs.
5. Connect another mouse to the other hub. The second mouse does not work.

Quoted 7 lines

The affected USB2 ports may remain in the resume state, preventing [ ... ]

Tested on Etron EJ168 (1b6f:7023) and EJ188 (1b6f:7052) with root hub autosuspend disabled.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1