2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-19 02:34:01 +08:00

xhci: Fix repeated xhci wake after suspend due to uncleared internal wake state

If port terminations are detected in suspend, but link never reaches U0
then xHCI may have an internal uncleared wake state that will cause an
immediate wake after suspend.

This wake state is normally cleared when driver clears the PORT_CSC bit,
which is set after a device is enabled and in U0.

Write 1 to clear PORT_CSC for ports that don't have anything connected
when suspending. This makes sure any pending internal wake states in
xHCI are cleared.

Cc: stable@vger.kernel.org
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20210311115353.2137560-5-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Mathias Nyman 2021-03-11 13:53:53 +02:00 committed by Greg Kroah-Hartman
parent b71c669ad8
commit d26c00e727

View File

@ -883,44 +883,42 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
xhci_set_cmd_ring_deq(xhci); xhci_set_cmd_ring_deq(xhci);
} }
static void xhci_disable_port_wake_on_bits(struct xhci_hcd *xhci) /*
* Disable port wake bits if do_wakeup is not set.
*
* Also clear a possible internal port wake state left hanging for ports that
* detected termination but never successfully enumerated (trained to 0U).
* Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
* at enumeration clears this wake, force one here as well for unconnected ports
*/
static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci,
struct xhci_hub *rhub,
bool do_wakeup)
{ {
struct xhci_port **ports;
int port_index;
unsigned long flags; unsigned long flags;
u32 t1, t2, portsc; u32 t1, t2, portsc;
int i;
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
/* disable usb3 ports Wake bits */ for (i = 0; i < rhub->num_ports; i++) {
port_index = xhci->usb3_rhub.num_ports; portsc = readl(rhub->ports[i]->addr);
ports = xhci->usb3_rhub.ports; t1 = xhci_port_state_to_neutral(portsc);
while (port_index--) { t2 = t1;
t1 = readl(ports[port_index]->addr);
portsc = t1; /* clear wake bits if do_wake is not set */
t1 = xhci_port_state_to_neutral(t1); if (!do_wakeup)
t2 = t1 & ~PORT_WAKE_BITS; t2 &= ~PORT_WAKE_BITS;
if (t1 != t2) {
writel(t2, ports[port_index]->addr); /* Don't touch csc bit if connected or connect change is set */
xhci_dbg(xhci, "disable wake bits port %d-%d, portsc: 0x%x, write: 0x%x\n", if (!(portsc & (PORT_CSC | PORT_CONNECT)))
xhci->usb3_rhub.hcd->self.busnum, t2 |= PORT_CSC;
port_index + 1, portsc, t2);
}
}
/* disable usb2 ports Wake bits */
port_index = xhci->usb2_rhub.num_ports;
ports = xhci->usb2_rhub.ports;
while (port_index--) {
t1 = readl(ports[port_index]->addr);
portsc = t1;
t1 = xhci_port_state_to_neutral(t1);
t2 = t1 & ~PORT_WAKE_BITS;
if (t1 != t2) { if (t1 != t2) {
writel(t2, ports[port_index]->addr); writel(t2, rhub->ports[i]->addr);
xhci_dbg(xhci, "disable wake bits port %d-%d, portsc: 0x%x, write: 0x%x\n", xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n",
xhci->usb2_rhub.hcd->self.busnum, rhub->hcd->self.busnum, i + 1, portsc, t2);
port_index + 1, portsc, t2);
} }
} }
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
@ -983,8 +981,8 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
return -EINVAL; return -EINVAL;
/* Clear root port wake on bits if wakeup not allowed. */ /* Clear root port wake on bits if wakeup not allowed. */
if (!do_wakeup) xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup);
xhci_disable_port_wake_on_bits(xhci); xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup);
if (!HCD_HW_ACCESSIBLE(hcd)) if (!HCD_HW_ACCESSIBLE(hcd))
return 0; return 0;