xhci features for usb-next
Subsystems (3)
cover xhci features for usb-next
Hi Greg
A set of xhci features for usb-next.
Turning on LPM support for a couple controllers, and finishing USB3 root port suspend and resume requests based on actual port link states transitions instead of waiting for some default time.
-Mathias
JC Kuo (1):
usb: host: xhci-tegra: Tegra186/Tegra194 LPM
Kai-Heng Feng (2):
xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3
xhci: Wait until link state trainsits to U0 after setting
USB_SS_PORT_LS_U0
Mathias Nyman (4):
xhci: bail out early if driver can't accress host in resume
xhci: Add a separate debug message for split transaction errors.
xhci: Show host status when watchdog triggers and host is assumed
dead.
xhci: Finetune host initiated USB3 rootport link suspend and resume
Mika Westerberg (1):
xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI
Nicolas Saenz Julienne (1):
usb: xhci: Enable LPM for VIA LABS VL805
drivers/usb/host/xhci-hub.c | 61 +++++++++++++++++++++++++++++------ drivers/usb/host/xhci-mem.c | 1 + drivers/usb/host/xhci-pci.c | 7 +++- drivers/usb/host/xhci-ring.c | 9 ++++++ drivers/usb/host/xhci-tegra.c | 7 ++++ drivers/usb/host/xhci.c | 4 ++- drivers/usb/host/xhci.h | 30 +++++++++++++++++ 7 files changed, 107 insertions(+), 12 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/9 xhci: bail out early if driver can't accress host in resume
Bail out early if the xHC host needs to be reset at resume but driver can't access xHC PCI registers.
If xhci driver already fails to reset the controller then there is no point in attempting to free, re-initialize, re-allocate and re-start the host. If failure to access the host is detected later, failing the resume, xhci interrupts will be double freed when remove is called.
--- drivers/usb/host/xhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/host/xhci.c +3 -1
@@ -1157,8 +1157,10 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)xhci_dbg (xhci,"Stop HCD\n" );xhci_halt (xhci);xhci_zero_64b_regs (xhci); -xhci_reset (xhci); + retval =xhci_reset (xhci);spin_unlock_irq (&xhci->lock); +if (retval) +return retval;xhci_cleanup_msix (xhci);xhci_dbg (xhci,"// Disabling event ring interrupts\n" );
Signature · 1 line
2.17.1
PATCH 2/9 xhci: Add a separate debug message for split transaction errors.
In reply to Mathias NymanDon't show the same error message for transaction errors and split transaction errors. It's very confusing while debugging.
Transaction errors are often due to electrical interference. Split transaction errors are about xHC not being able to schedule start and complete split transactions needed to address low- and full-speed devices behind high-speed hubs.
--- drivers/usb/host/xhci-ring.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/host/xhci-ring.c +4 -0
@@ -2413,6 +2413,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, status = -EPIPE ;break ;case COMP_SPLIT_TRANSACTION_ERROR : +xhci_dbg (xhci,"Split transaction error for slot %u ep %u\n" , + slot_id, ep_index); + status = -EPROTO ; +break ;case COMP_USB_TRANSACTION_ERROR :xhci_dbg (xhci,"Transfer error for slot %u ep %u on endpoint\n" , slot_id, ep_index);
Signature · 1 line
2.17.1
PATCH 3/9 xhci: Show host status when watchdog triggers and host is assumed dead.
In reply to Mathias NymanAdditional debugging to show xHC USBSTS register when stop endpoint command watchdog triggers and host is assumed dead.
useful to know the current status before the controller is stopped by the xhci driver and everything is released and freed.
--- drivers/usb/host/xhci-ring.c | 4 ++++ drivers/usb/host/xhci.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
drivers/usb/host/xhci-ring.c +4 -0
@@ -955,6 +955,7 @@ void xhci_stop_endpoint_command_watchdog(struct timer_list *t)struct xhci_virt_ep *ep =from_timer (ep, t, stop_cmd_timer);struct xhci_hcd *xhci = ep->xhci;unsigned long flags; +u32 usbsts;spin_lock_irqsave (&xhci->lock, flags);
@@ -965,8 +966,11 @@ void xhci_stop_endpoint_command_watchdog(struct timer_list *t)xhci_dbg (xhci,"Stop EP timer raced with cmd completion, exit" );return ; } + usbsts =readl (&xhci->op_regs->status);xhci_warn (xhci,"xHCI host not responding to stop endpoint command.\n" ); +xhci_warn (xhci,"USBSTS:%s\n" ,xhci_decode_usbsts (usbsts)); + ep->ep_state &= ~EP_STOP_CMD_PENDING ;xhci_halt (xhci);
drivers/usb/host/xhci.h +29 -0
@@ -2589,6 +2589,35 @@ static inline const char *xhci_decode_portsc(u32 portsc)return str; } +static inline const char *xhci_decode_usbsts (u32 usbsts) +{ +static char str[256 ]; +int ret =0 ; + +if (usbsts == ~(u32 )0 ) +return " 0xffffffff" ; +if (usbsts &STS_HALT ) + ret +=sprintf (str + ret," HCHalted" ); +if (usbsts &STS_FATAL ) + ret +=sprintf (str + ret," HSE" ); +if (usbsts &STS_EINT ) + ret +=sprintf (str + ret," EINT" ); +if (usbsts &STS_PORT ) + ret +=sprintf (str + ret," PCD" ); +if (usbsts &STS_SAVE ) + ret +=sprintf (str + ret," SSS" ); +if (usbsts &STS_RESTORE ) + ret +=sprintf (str + ret," RSS" ); +if (usbsts &STS_SRE ) + ret +=sprintf (str + ret," SRE" ); +if (usbsts &STS_CNR ) + ret +=sprintf (str + ret," CNR" ); +if (usbsts &STS_HCE ) + ret +=sprintf (str + ret," HCE" ); + +return str; +} +static inline const char *xhci_decode_doorbell (u32 slot,u32 doorbell) {static char str[256 ];
Signature · 1 line
2.17.1
PATCH 4/9 usb: xhci: Enable LPM for VIA LABS VL805
In reply to Mathias NymanFrom: Nicolas Saenz Julienne <[email protected]>
This PCIe controller chip is used on the Raspberry Pi 4 and multiple adapter cards. There is no publicly available documentation for the chip, yet both the downstream RPi4 kernel and the controller cards support/advertise LPM support.
--- drivers/usb/host/xhci-pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/host/xhci-pci.c +3 -0
@@ -243,6 +243,9 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device == 0x3432) xhci->quirks |=XHCI_BROKEN_STREAMS ; +if (pdev->vendor ==PCI_VENDOR_ID_VIA && pdev->device ==0x3483 ) + xhci->quirks |=XHCI_LPM_SUPPORT ; +if (pdev->vendor ==PCI_VENDOR_ID_ASMEDIA && pdev->device ==0x1042 ) xhci->quirks |=XHCI_BROKEN_STREAMS ;
Signature · 1 line
2.17.1
PATCH 5/9 usb: host: xhci-tegra: Tegra186/Tegra194 LPM
In reply to Mathias NymanFrom: JC Kuo <[email protected]>
Tegra186 and Tegra194 xHC supports USB 3.0 LPM. This commit enables XHCI_LPM_SUPPORT quirk for Tegra186 and Tegra194.
--- drivers/usb/host/xhci-tegra.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/usb/host/xhci-tegra.c +7 -0
@@ -203,6 +203,7 @@ struct tegra_xusb_soc {bool scale_ss_clock;bool has_ipfs; +bool lpm_support; };struct tegra_xusb_context {
@@ -1779,6 +1780,7 @@ static const struct tegra_xusb_soc tegra186_soc = { .data_out = 0xec, .owner = 0xf0, }, + .lpm_support = true, }; static const char * const tegra194_supply_names[] = {
@@ -1808,6 +1810,7 @@ static const struct tegra_xusb_soc tegra194_soc = { .data_out = 0x70, .owner = 0x74, }, + .lpm_support = true, };MODULE_FIRMWARE ("nvidia/tegra194/xusb.bin" );
@@ -1832,7 +1835,11 @@ static struct platform_driver tegra_xusb_driver = {static void tegra_xhci_quirks (struct device *dev,struct xhci_hcd *xhci) { +struct tegra_xusb *tegra =dev_get_drvdata (dev); + xhci->quirks |=XHCI_PLAT ; +if (tegra && tegra->soc->lpm_support) + xhci->quirks |=XHCI_LPM_SUPPORT ; }static int tegra_xhci_setup (struct usb_hcd *hcd)
Signature · 1 line
2.17.1
PATCH 6/9 xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3
In reply to Mathias NymanFrom: Kai-Heng Feng <[email protected]>
The xHCI spec doesn't specify the upper bound of U3 transition time. For some devices 20ms is not enough, so we need to make sure the link state is in U3 before further actions.
I've tried to use U3 Entry Capability by setting U3 Entry Enable in config register, however the port change event for U3 transition interrupts the system suspend process.
For now let's use the less ideal method by polling PLS.
--- drivers/usb/host/xhci-hub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-hub.c +10 -1
@@ -1322,7 +1322,16 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,xhci_set_link_state (xhci, ports[wIndex], link_state);spin_unlock_irqrestore (&xhci->lock, flags); -msleep (20 );/* wait device to enter */ +if (link_state ==USB_SS_PORT_LS_U3 ) { +int retries =16 ; + +while (retries--) { +usleep_range (4000 ,8000 ); + temp =readl (ports[wIndex]->addr); +if ((temp &PORT_PLS_MASK ) ==XDEV_U3 ) +break ; + } + }spin_lock_irqsave (&xhci->lock, flags); temp =readl (ports[wIndex]->addr);
Signature · 1 line
2.17.1
PATCH 7/9 xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0
In reply to Mathias NymanFrom: Kai-Heng Feng <[email protected]>
Like U3 case, xHCI spec doesn't specify the upper bound of U0 transition time. The 20ms is not enough for some devices.
Intead of polling PLS or PLC, we can facilitate the port change event to know that the link transits to U0 is completed.
While at it, also separate U0 and U3 case to make the code cleaner.
--- drivers/usb/host/xhci-hub.c | 44 +++++++++++++++++++++++++----------- drivers/usb/host/xhci-mem.c | 1 + drivers/usb/host/xhci-ring.c | 1 + drivers/usb/host/xhci.h | 1 + 4 files changed, 34 insertions(+), 13 deletions(-)
drivers/usb/host/xhci-hub.c +31 -13
@@ -1306,7 +1306,33 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, wIndex, link_state); goto error; } + +if (link_state ==USB_SS_PORT_LS_U0 ) { +if ((temp &PORT_PLS_MASK ) ==XDEV_U0 ) +break ; + +if (!((temp &PORT_PLS_MASK ) ==XDEV_U1 || + (temp &PORT_PLS_MASK ) ==XDEV_U2 || + (temp &PORT_PLS_MASK ) ==XDEV_U3 )) { +xhci_warn (xhci,"Can only set port %d to U0 from U state\n" , + wIndex); + goto error; + } +reinit_completion (&bus_state->u3exit_done[wIndex]); +xhci_set_link_state (xhci, ports[wIndex], +USB_SS_PORT_LS_U0 ); +spin_unlock_irqrestore (&xhci->lock, flags); +if (!wait_for_completion_timeout (&bus_state->u3exit_done[wIndex], +msecs_to_jiffies (100 ))) +xhci_dbg (xhci,"missing U0 port change event for port %d\n" , + wIndex); +spin_lock_irqsave (&xhci->lock, flags); + temp =readl (ports[wIndex]->addr); +break ; + } +if (link_state ==USB_SS_PORT_LS_U3 ) { +int retries =16 ; slot_id =xhci_find_slot_id_by_port (hcd, xhci, wIndex +1 );if (slot_id) {
@@ -1317,26 +1343,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,xhci_stop_device (xhci, slot_id,1 );spin_lock_irqsave (&xhci->lock, flags); } - } - -xhci_set_link_state (xhci, ports[wIndex], link_state); - -spin_unlock_irqrestore (&xhci->lock, flags); -if (link_state ==USB_SS_PORT_LS_U3 ) { -int retries =16 ; - +xhci_set_link_state (xhci, ports[wIndex],USB_SS_PORT_LS_U3 ); +spin_unlock_irqrestore (&xhci->lock, flags);while (retries--) {usleep_range (4000 ,8000 ); temp =readl (ports[wIndex]->addr);if ((temp &PORT_PLS_MASK ) ==XDEV_U3 )break ; } - } -spin_lock_irqsave (&xhci->lock, flags); - - temp =readl (ports[wIndex]->addr); -if (link_state ==USB_SS_PORT_LS_U3 ) +spin_lock_irqsave (&xhci->lock, flags); + temp =readl (ports[wIndex]->addr); bus_state->suspended_ports |=1 << wIndex; + }break ;case USB_PORT_FEAT_POWER :/*
drivers/usb/host/xhci-mem.c +1 -0
@@ -2552,6 +2552,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) xhci->usb3_rhub.bus_state.resume_done[i] =0 ;/* Only the USB 2.0 completions will ever be used. */ init_completion (&xhci->usb2_rhub.bus_state.rexit_done[i]); +init_completion (&xhci->usb3_rhub.bus_state.u3exit_done[i]); }if (scratchpad_alloc (xhci, flags))
drivers/usb/host/xhci-ring.c +1 -0
@@ -1681,6 +1681,7 @@ static void handle_port_status(struct xhci_hcd *xhci, (portsc & PORT_PLS_MASK) == XDEV_U1 || (portsc & PORT_PLS_MASK) == XDEV_U2)) {xhci_dbg (xhci,"resume SS port %d finished\n" , port_id); +complete (&bus_state->u3exit_done[hcd_portnum]);/* We've just brought the device into U0/1/2 through either the * Resume state after a device remote wakeup, or through the * U3Exit state after a host-initiated resume. If it's a device
drivers/usb/host/xhci.h +1 -0
@@ -1694,6 +1694,7 @@ struct xhci_bus_state {/* Which ports are waiting on RExit to U0 transition. */ unsigned long rexit_ports;struct completion rexit_done[USB_MAXCHILDREN ]; +struct completion u3exit_done[USB_MAXCHILDREN ]; };
Signature · 1 line
2.17.1
PATCH 8/9 xhci: Finetune host initiated USB3 rootport link suspend and resume
In reply to Mathias NymanDepending on the current link state the steps to resume the link to U0 varies. The normal case when a port is suspended (U3) we set the link to U0 and wait for a port event when U3exit completed and port moved to U0.
If the port is in U1/U2, then no event is issued, just set link to U0
If port is in Resume or Recovery state then the device has already initiated resume, and this host initiated resume is racing against it. Port event handler for device initiated resume will set link to U0, just wait for the port to reach U0 before returning.
--- drivers/usb/host/xhci-hub.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
drivers/usb/host/xhci-hub.c +25 -11
@@ -1307,20 +1307,34 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, goto error; } +/* +* set link to U0, steps depend on current link state. +* U3: set link to U0 and wait for u3exit completion. +* U1/U2: no PLC complete event, only set link to U0. +* Resume/Recovery: device initiated U0, only wait for +* completion +*/ if (link_state ==USB_SS_PORT_LS_U0 ) { -if ((temp &PORT_PLS_MASK ) ==XDEV_U0 ) -break ; +u32 pls = temp &PORT_PLS_MASK ; +bool wait_u0 = false; -if (!((temp &PORT_PLS_MASK ) ==XDEV_U1 || - (temp &PORT_PLS_MASK ) ==XDEV_U2 || - (temp &PORT_PLS_MASK ) ==XDEV_U3 )) { -xhci_warn (xhci,"Can only set port %d to U0 from U state\n" , - wIndex); - goto error; +/* already in U0 */ +if (pls ==XDEV_U0 ) +break ; +if (pls ==XDEV_U3 || + pls ==XDEV_RESUME || + pls ==XDEV_RECOVERY ) { + wait_u0 = true; +reinit_completion (&bus_state->u3exit_done[wIndex]); + } +if (pls <=XDEV_U3 )/* U1, U2, U3 */ +xhci_set_link_state (xhci, ports[wIndex], +USB_SS_PORT_LS_U0 ); +if (!wait_u0) { +if (pls >XDEV_U3 ) + goto error; +break ; } -reinit_completion (&bus_state->u3exit_done[wIndex]); -xhci_set_link_state (xhci, ports[wIndex], -USB_SS_PORT_LS_U0 );spin_unlock_irqrestore (&xhci->lock, flags);if (!wait_for_completion_timeout (&bus_state->u3exit_done[wIndex],msecs_to_jiffies (100 )))
Signature · 1 line
2.17.1
PATCH 9/9 xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI
In reply to Mathias NymanFrom: Mika Westerberg <[email protected]>
In the same way as Intel Ice Lake TCSS (Type-C Subsystem) the Tiger Lake TCSS xHCI needs to be runtime suspended whenever possible to allow the TCSS hardware block to enter D3cold and thus save energy.
--- drivers/usb/host/xhci-pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-pci.c +3 -1
@@ -50,6 +50,7 @@#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI 0x15f0#define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13#define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af +#define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13#define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9#define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
@@ -216,7 +217,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device ==PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI || pdev->device ==PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI || pdev->device ==PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI || - pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI)) + pdev->device ==PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI || + pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI)) xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
Signature · 1 line
2.17.1