Message ID | 20230914092724.1469813-1-mathias.nyman@linux.intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | d7cdfc319b2bcf6899ab0a05eec0958bc802a9a1 |
Headers | show |
Series | [RFT] xhci: track port suspend state correctly in unsuccessful resume cases | expand |
Hi Mathias, On 9/14/2023 2:27 AM, Mathias Nyman wrote: > xhci-hub.c tracks suspended ports in a suspended_port bitfield. > This is checked when responding to a Get_Status(PORT) request to see if a > port in running U0 state was recently resumed, and adds the required > USB_PORT_STAT_C_SUSPEND change bit in those cases. > > The suspended_port bit was left uncleared if a device is disconnected > during suspend. The bit remained set even when a new device was connected > and enumerated. The set bit resulted in a incorrect Get_Status(PORT) > response with a bogus USB_PORT_STAT_C_SUSPEND change > bit set once the new device reached U0 link state. > > USB_PORT_STAT_C_SUSPEND change bit is only used for USB2 ports, but > xhci-hub keeps track of both USB2 and USB3 suspended ports. > Thanks for looking at this change. Tested it on my environment and it looks good to me: //Disconnect while bus is suspended (before get status) msm-dwc3 a600000.ssusb: DWC3 exited from low power mode xhci_resume: usb3 suspended_ports = 0, bus_suspended = 0 xhci_resume: usb2 suspended_ports = 1, bus_suspended = 0 usb 1-1: USB disconnect, device number 2 msm-dwc3 a600000.ssusb: could not transition HS PHY to L2 msm-dwc3 a600000.ssusb: DWC3 in low power mode //Plug in after disconnect msm-dwc3 a600000.ssusb: DWC3 exited from low power mode xhci_resume: usb3 suspended_ports = 0, bus_suspended = 0 xhci_resume: usb2 suspended_ports = 0, bus_suspended = 0 usb 1-1: new full-speed USB device number 3 using xhci-hcd ... msm-dwc3 a600000.ssusb: could not transition HS PHY to L2 msm-dwc3 a600000.ssusb: DWC3 in low power mode //Remote wakeup msm-dwc3 a600000.ssusb: DWC3 exited from low power mode xhci_resume: usb3 suspended_ports = 0, bus_suspended = 0 xhci_resume: usb2 suspended_ports = 1, bus_suspended = 0 plantronics 0003:047F:C025.0002: intr, xhci-hcd.2.auto-1/input3, status -2 msm-dwc3 a600000.ssusb: could not transition HS PHY to L2 msm-dwc3 a600000.ssusb: DWC3 in low power mode Will update my change ([1]) to include testing for the suspended_ports for if a device is connected (and suspended) while running xhci_resume() Thanks Wesley Cheng [1] https://lore.kernel.org/linux-usb/20230901001518.25403-1-quic_wcheng@quicinc.com/
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 0054d02239e2..0df5d807a77e 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1062,19 +1062,19 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status, *status |= USB_PORT_STAT_C_CONFIG_ERROR << 16; /* USB3 specific wPortStatus bits */ - if (portsc & PORT_POWER) { + if (portsc & PORT_POWER) *status |= USB_SS_PORT_STAT_POWER; - /* link state handling */ - if (link_state == XDEV_U0) - bus_state->suspended_ports &= ~(1 << portnum); - } - /* remote wake resume signaling complete */ - if (bus_state->port_remote_wakeup & (1 << portnum) && + /* no longer suspended or resuming */ + if (link_state != XDEV_U3 && link_state != XDEV_RESUME && link_state != XDEV_RECOVERY) { - bus_state->port_remote_wakeup &= ~(1 << portnum); - usb_hcd_end_port_resume(&hcd->self, portnum); + /* remote wake resume signaling complete */ + if (bus_state->port_remote_wakeup & (1 << portnum)) { + bus_state->port_remote_wakeup &= ~(1 << portnum); + usb_hcd_end_port_resume(&hcd->self, portnum); + } + bus_state->suspended_ports &= ~(1 << portnum); } xhci_hub_report_usb3_link_state(xhci, status, portsc); @@ -1131,6 +1131,7 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status, usb_hcd_end_port_resume(&port->rhub->hcd->self, portnum); } port->rexit_active = 0; + bus_state->suspended_ports &= ~(1 << portnum); } }
xhci-hub.c tracks suspended ports in a suspended_port bitfield. This is checked when responding to a Get_Status(PORT) request to see if a port in running U0 state was recently resumed, and adds the required USB_PORT_STAT_C_SUSPEND change bit in those cases. The suspended_port bit was left uncleared if a device is disconnected during suspend. The bit remained set even when a new device was connected and enumerated. The set bit resulted in a incorrect Get_Status(PORT) response with a bogus USB_PORT_STAT_C_SUSPEND change bit set once the new device reached U0 link state. USB_PORT_STAT_C_SUSPEND change bit is only used for USB2 ports, but xhci-hub keeps track of both USB2 and USB3 suspended ports. Reported-by: Wesley Cheng <quic_wcheng@quicinc.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> --- drivers/usb/host/xhci-hub.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)