Rework "xhci: clear root port wake on bits if controller isn't wake-up capable"
Subsystems (2)
cover Rework "xhci: clear root port wake on bits if controller isn't wake-up capable"
This serie of patch reworks commit ff8cbf250b448aac35589f6075082c3fcad8a8fe. This has been discussed at http://www.spinics.net/lists/linux-usb/msg114986.html
It also includes a patch to fix a comment in drivers/usb/host/xhci.h.
Lu Baolu (3):
usb: xhci: Revert "xhci: clear root port wake on bits if controller
isn't wake-up capable"
usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe
usb: xhci: fix comment for PORT_DEV_REMOVE
drivers/usb/host/xhci-hub.c | 5 +---- drivers/usb/host/xhci-pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 8 +++++++- 3 files changed, 50 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 usb: xhci: Revert "xhci: clear root port wake on bits if controller isn't wake-up capable"
This reverts commit ff8cbf250b448aac35589f6075082c3fcad8a8fe.
Commit ff8cbf250b448aac35589f6075082c3fcad8a8fe triggers the bug logged at
https://bugzilla.kernel.org/show_bug.cgi?id=85701
--- drivers/usb/host/xhci-hub.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/usb/host/xhci-hub.c +1 -4
@@ -22,7 +22,6 @@#include <linux/slab.h> -#include <linux/device.h> #include <asm/unaligned.h> #include "xhci.h"
@@ -1149,9 +1148,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)* including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME * is enabled, so also enable remote wake here. */ -if (hcd->self.root_hub->do_remote_wakeup - &&device_may_wakeup (hcd->self.controller)) { - +if (hcd->self.root_hub->do_remote_wakeup) {if (t1 &PORT_CONNECT ) { t2 |=PORT_WKOC_E |PORT_WKDISC_E ; t2 &= ~PORT_WKCONN_E ;
Signature · 1 line
1.9.1
PATCH 2/3 usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe
In reply to Lu Baoluxhci: clear root port wake on bits if controller isn't wake-up capable
When xHCI PCI host is suspended, if do_wakeup is false in xhci_pci_suspend, xhci_pci_suspend needs to clear all root port wake on bits. Otherwise some Intel platforms may get a spurious wakeup, even if PCI PME# is disabled.
--- drivers/usb/host/xhci-pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 6 ++++++ 2 files changed, 48 insertions(+)
drivers/usb/host/xhci-pci.c +42 -0
@@ -27,6 +27,8 @@#include "xhci.h" #include "xhci-trace.h" +#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) +/* Device for a quirk */ #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
@@ -126,6 +128,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)*/ xhci->quirks |=XHCI_SPURIOUS_REBOOT ; xhci->quirks |=XHCI_AVOID_BEI ; + xhci->quirks |=XHCI_DISABLE_PORT_WOB ; } if (pdev->vendor == PCI_VENDOR_ID_INTEL && (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||
@@ -279,6 +282,42 @@ static void xhci_pci_remove(struct pci_dev *dev) }#ifdef CONFIG_PM +static void xhci_disable_port_wake_bits (struct xhci_hcd *xhci) +{ +int port_index; +__le32 __iomem **port_array; +unsigned long flags; +u32 t1, t2; + +spin_lock_irqsave (&xhci->lock, flags); + +/* disble usb3 ports Wake bits*/ + port_index = xhci->num_usb3_ports; + port_array = xhci->usb3_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +/* disble usb2 ports Wake bits*/ + port_index = xhci->num_usb2_ports; + port_array = xhci->usb2_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +spin_unlock_irqrestore (&xhci->lock, flags); +} +static int xhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);
@@ -291,6 +330,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)if (xhci->quirks &XHCI_COMP_MODE_QUIRK ) pdev->no_d3cold = true; +if (xhci->quirks &XHCI_DISABLE_PORT_WOB && !do_wakeup) +xhci_disable_port_wake_bits (xhci); +return xhci_suspend (xhci); }
drivers/usb/host/xhci.h +6 -0
@@ -1560,6 +1560,12 @@ struct xhci_hcd {#define XHCI_SPURIOUS_WAKEUP (1 << 18)/* For controllers with a broken beyond repair streams implementation */ #define XHCI_BROKEN_STREAMS (1 << 19) +/* +* Some Intel platforms may get a spurious wakeup after entering system +* suspend with PCI PME# disabled. Software can workaround this by dis- +* abling the wake on bits of all root ports. +*/ +#define XHCI_DISABLE_PORT_WOB (1 << 20)unsigned int num_active_eps;unsigned int limit_active_eps;/* There are two roothubs to keep track of bus suspend info for */
Signature · 1 line
1.9.1
Re: [PATCH 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe
Quoted 77 lines · Lu Baolu
xhci: clear root port wake on bits if controller isn't wake-up capable
When xHCI PCI host is suspended, if
do_wakeupis false inxhci_pci_suspend,xhci_pci_suspendneeds to clear all root port wake on bits. Otherwise some Intel platforms may get a spurious wakeup, even if PCI PME# is disabled.Signed-off-by Lu Baolu <[email protected]>--- drivers/usb/host/xhci-pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 6 ++++++ 2 files changed, 48 insertions(+)drivers/usb/host/xhci-pci.c +39
-0@@ -27,6 +27,8 @@#include "xhci.h" #include "xhci-trace.h" +#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) +/* Device for a quirk */ #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000@@ -126,6 +128,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)*/ xhci->quirks |=XHCI_SPURIOUS_REBOOT ; xhci->quirks |=XHCI_AVOID_BEI ; + xhci->quirks |=XHCI_DISABLE_PORT_WOB ; } if (pdev->vendor == PCI_VENDOR_ID_INTEL && (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||@@ -279,6 +282,42 @@ static void xhci_pci_remove(struct pci_dev *dev) }#ifdef CONFIG_PM +static void xhci_disable_port_wake_bits (struct xhci_hcd *xhci) +{ +int port_index; +__le32 __iomem **port_array; +unsigned long flags; +u32 t1, t2; + +spin_lock_irqsave (&xhci->lock, flags); + +/* disble usb3 ports Wake bits*/ + port_index = xhci->num_usb3_ports; + port_array = xhci->usb3_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +/* disble usb2 ports Wake bits*/ + port_index = xhci->num_usb2_ports; + port_array = xhci->usb2_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +spin_unlock_irqrestore (&xhci->lock, flags); +} +static int xhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);
drivers/usb/host/xhci-pci.c static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) · line 337
Quoted 8 lines
drivers/usb/host/xhci-pci.c +3
-0@@ -291,6 +330,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)if (xhci->quirks &XHCI_COMP_MODE_QUIRK ) pdev->no_d3cold = true; +if (xhci->quirks &XHCI_DISABLE_PORT_WOB && !do_wakeup) +xhci_disable_port_wake_bits (xhci); +return xhci_suspend (xhci); }
There are two things wrong here. First, this should not be a quirk. The Wake-On bits should be disabled whenever they aren't needed, on every controller.
Second, this code (or something like it) belongs in xhci.c or xhci-hub.c, not xhci-pci.c. This is because it should apply to all xHCI controllers, not just the PCI-based ones.
(In fact, instead of disabling the Wake-On bits when the controller is suspended and do_wakeup is 0, it probably would be better to leave them disabled normally and then _enable_ them if do_wakeup is 1.)
Alan Stern
Re: [PATCH 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe
Quoted 91 lines · Alan Stern
Quoted 77 lines · Lu Baolu
xhci: clear root port wake on bits if controller isn't wake-up capable
When xHCI PCI host is suspended, if
do_wakeupis false inxhci_pci_suspend,xhci_pci_suspendneeds to clear all root port wake on bits. Otherwise some Intel platforms may get a spurious wakeup, even if PCI PME# is disabled.Signed-off-by Lu Baolu <[email protected]>--- drivers/usb/host/xhci-pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 6 ++++++ 2 files changed, 48 insertions(+)drivers/usb/host/xhci-pci.c +39
-0@@ -27,6 +27,8 @@#include "xhci.h" #include "xhci-trace.h" +#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) +/* Device for a quirk */ #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000@@ -126,6 +128,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)*/ xhci->quirks |=XHCI_SPURIOUS_REBOOT ; xhci->quirks |=XHCI_AVOID_BEI ; + xhci->quirks |=XHCI_DISABLE_PORT_WOB ; } if (pdev->vendor == PCI_VENDOR_ID_INTEL && (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||@@ -279,6 +282,42 @@ static void xhci_pci_remove(struct pci_dev *dev) }#ifdef CONFIG_PM +static void xhci_disable_port_wake_bits (struct xhci_hcd *xhci) +{ +int port_index; +__le32 __iomem **port_array; +unsigned long flags; +u32 t1, t2; + +spin_lock_irqsave (&xhci->lock, flags); + +/* disble usb3 ports Wake bits*/ + port_index = xhci->num_usb3_ports; + port_array = xhci->usb3_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +/* disble usb2 ports Wake bits*/ + port_index = xhci->num_usb2_ports; + port_array = xhci->usb2_ports; +while (port_index--) { + t1 =readl (port_array[port_index]); + t2 =xhci_port_state_to_neutral (t1); + t2 &= ~PORT_WAKE_BITS ; + t1 =xhci_port_state_to_neutral (t1); +if (t1 != t2) +writel (t2, port_array[port_index]); + } + +spin_unlock_irqrestore (&xhci->lock, flags); +} +static int xhci_pci_suspend (struct usb_hcd *hcd,bool do_wakeup) {struct xhci_hcd *xhci =hcd_to_xhci (hcd);drivers/usb/host/xhci-pci.c static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) · line 337
Quoted 8 lines
drivers/usb/host/xhci-pci.c +3
-0@@ -291,6 +330,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)if (xhci->quirks &XHCI_COMP_MODE_QUIRK ) pdev->no_d3cold = true; +if (xhci->quirks &XHCI_DISABLE_PORT_WOB && !do_wakeup) +xhci_disable_port_wake_bits (xhci); +return xhci_suspend (xhci); }There are two things wrong here. First, this should not be a quirk. The Wake-On bits should be disabled whenever they aren't needed, on every controller.
Quoted 3 lines
Second, this code (or something like it) belongs in
xhci.corxhci-hub.c, notxhci-pci.c. This is because it should apply to all xHCI controllers, not just the PCI-based ones.
Hi Alan,
I agree with you. I will resubmit my patches.
BR,
baolu
Quoted 7 lines
(In fact, instead of disabling the Wake-On bits when the controller is suspended and
do_wakeupis 0, it probably would be better to leave them disabled normally and then _enable_ them ifdo_wakeupis 1.)Alan Stern
PATCH 3/3 usb: xhci: fix comment for PORT_DEV_REMOVE
In reply to Lu BaoluAccording to xHCI specification, PORT_DEV_REMOVE(bit 30) in PORTSC true means "Device is non-removable".
--- drivers/usb/host/xhci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci.h +1 -1
@@ -358,7 +358,7 @@ struct xhci_op_regs {/* wake on over-current (enable) */ #define PORT_WKOC_E (1 << 27)/* bits 28:29 reserved */ -/* true: device is removable - for USB 3.0 roothub emulation */ +/* true: device is non-removable - for USB 3.0 roothub emulation */ #define PORT_DEV_REMOVE (1 << 30)/* Initiate a warm port reset - complete when PORT_WRC is '1' */ #define PORT_WR (1 << 31)
Signature · 1 line
1.9.1