public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable"
@ 2014-11-06  2:50 Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 1/3] usb: xhci: Revert " Lu Baolu
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Lu Baolu @ 2014-11-06  2:50 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Lu Baolu

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.

Changes in v4:
	- Refine xhci_disable_port_wake_on_bits().
	- Add "Acked-by: Alan Stern"

Changes in v3:
	- Need to consider run-time suspend as well.
	- Change "wake-up capable" to "allowed to do wakeup"
	    in both comments and patch description.
	- Add "Suggested-by: Alan Stern"

Changes in v2:
	- Should not be a quirk.
	- Should be applied to all xhci controllers.

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  |  2 +-
 drivers/usb/host/xhci-plat.c | 10 +++++++++-
 drivers/usb/host/xhci.c      | 42 +++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/host/xhci.h      |  4 ++--
 5 files changed, 54 insertions(+), 9 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 1/3] usb: xhci: Revert "xhci: clear root port wake on bits if controller isn't wake-up capable"
  2014-11-06  2:50 [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu Baolu
@ 2014-11-06  2:50 ` Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe Lu Baolu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2014-11-06  2:50 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Lu Baolu

This reverts commit ff8cbf250b448aac35589f6075082c3fcad8a8fe.

Commit ff8cbf250b448aac35589f6075082c3fcad8a8fe triggers the bug logged at

https://bugzilla.kernel.org/show_bug.cgi?id=85701

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reported-by: Dmitry Nezhevenko <dion@inhex.net>
---
 drivers/usb/host/xhci-hub.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 696160d..388cfd8 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -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;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe
  2014-11-06  2:50 [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 1/3] usb: xhci: Revert " Lu Baolu
@ 2014-11-06  2:50 ` Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 3/3] usb: xhci: fix comment for PORT_DEV_REMOVE Lu Baolu
  2014-11-14  3:14 ` [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu, Baolu
  3 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2014-11-06  2:50 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Lu Baolu

xhci: clear root port wake on bits if controller isn't allowed to do wakeup

When system is being suspended, if host device is not allowed to do wakeup,
xhci_suspend() needs to clear all root port wake on bits. Otherwise, some
platforms may generate spurious wakeup, even if PCI PME# is disabled.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
---
 drivers/usb/host/xhci-pci.c  |  2 +-
 drivers/usb/host/xhci-plat.c | 10 +++++++++-
 drivers/usb/host/xhci.c      | 42 +++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/host/xhci.h      |  2 +-
 4 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 280dde9..d3fa3c2 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -291,7 +291,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 	if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
 		pdev->no_d3cold = true;
 
-	return xhci_suspend(xhci);
+	return xhci_suspend(xhci, do_wakeup);
 }
 
 static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 3d78b0c..646300c 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -204,7 +204,15 @@ static int xhci_plat_suspend(struct device *dev)
 	struct usb_hcd	*hcd = dev_get_drvdata(dev);
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 
-	return xhci_suspend(xhci);
+	/*
+	 * xhci_suspend() needs `do_wakeup` to know whether host is allowed
+	 * to do wakeup during suspend. Since xhci_plat_suspend is currently
+	 * only designed for system suspend, device_may_wakeup() is enough
+	 * to dertermine whether host is allowed to do wakeup. Need to
+	 * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
+	 * also applies to runtime suspend.
+	 */
+	return xhci_suspend(xhci, device_may_wakeup(dev));
 }
 
 static int xhci_plat_resume(struct device *dev)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2a5d45b..b832841 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -35,6 +35,8 @@
 #define DRIVER_AUTHOR "Sarah Sharp"
 #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
 
+#define	PORT_WAKE_BITS	(PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
+
 /* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
 static int link_quirk;
 module_param(link_quirk, int, S_IRUGO | S_IWUSR);
@@ -851,13 +853,47 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
 	xhci_set_cmd_ring_deq(xhci);
 }
 
+static void xhci_disable_port_wake_on_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]);
+		t1 = xhci_port_state_to_neutral(t1);
+		t2 = t1 & ~PORT_WAKE_BITS;
+		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]);
+		t1 = xhci_port_state_to_neutral(t1);
+		t2 = t1 & ~PORT_WAKE_BITS;
+		if (t1 != t2)
+			writel(t2, port_array[port_index]);
+	}
+
+	spin_unlock_irqrestore(&xhci->lock, flags);
+}
+
 /*
  * Stop HC (not bus-specific)
  *
  * This is called when the machine transition into S3/S4 mode.
  *
  */
-int xhci_suspend(struct xhci_hcd *xhci)
+int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
 {
 	int			rc = 0;
 	unsigned int		delay = XHCI_MAX_HALT_USEC;
@@ -868,6 +904,10 @@ int xhci_suspend(struct xhci_hcd *xhci)
 			xhci->shared_hcd->state != HC_STATE_SUSPENDED)
 		return -EINVAL;
 
+	/* Clear root port wake on bits if wakeup not allowed. */
+	if (!do_wakeup)
+		xhci_disable_port_wake_on_bits(xhci);
+
 	/* Don't poll the roothubs on bus suspend. */
 	xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
 	clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index df76d64..d745715 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1746,7 +1746,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
 void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *));
 
 #ifdef	CONFIG_PM
-int xhci_suspend(struct xhci_hcd *xhci);
+int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
 int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
 #else
 #define	xhci_suspend	NULL
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 3/3] usb: xhci: fix comment for PORT_DEV_REMOVE
  2014-11-06  2:50 [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 1/3] usb: xhci: Revert " Lu Baolu
  2014-11-06  2:50 ` [PATCH v4 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe Lu Baolu
@ 2014-11-06  2:50 ` Lu Baolu
  2014-11-14  3:14 ` [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu, Baolu
  3 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2014-11-06  2:50 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Lu Baolu

According to xHCI specification, PORT_DEV_REMOVE(bit 30) in PORTSC
true means "Device is non-removable".

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reported-by: Juro Bystricky <jurobystricky@hotmail.com>
---
 drivers/usb/host/xhci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d745715..ab36bbb 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -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)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable"
  2014-11-06  2:50 [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu Baolu
                   ` (2 preceding siblings ...)
  2014-11-06  2:50 ` [PATCH v4 3/3] usb: xhci: fix comment for PORT_DEV_REMOVE Lu Baolu
@ 2014-11-14  3:14 ` Lu, Baolu
  2014-11-14  8:51   ` Mathias Nyman
  3 siblings, 1 reply; 6+ messages in thread
From: Lu, Baolu @ 2014-11-14  3:14 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Alan Stern; +Cc: linux-usb, linux-kernel

Hi Mathias,

This patch series has been acked by Alan Stern. There seems no further 
comments from others. Can you please pull in it?

Thanks,
-baolu

On 2014年11月06日 10:50, Lu Baolu wrote:
> 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.
>
> Changes in v4:
> 	- Refine xhci_disable_port_wake_on_bits().
> 	- Add "Acked-by: Alan Stern"
>
> Changes in v3:
> 	- Need to consider run-time suspend as well.
> 	- Change "wake-up capable" to "allowed to do wakeup"
> 	    in both comments and patch description.
> 	- Add "Suggested-by: Alan Stern"
>
> Changes in v2:
> 	- Should not be a quirk.
> 	- Should be applied to all xhci controllers.
>
> 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  |  2 +-
>   drivers/usb/host/xhci-plat.c | 10 +++++++++-
>   drivers/usb/host/xhci.c      | 42 +++++++++++++++++++++++++++++++++++++++++-
>   drivers/usb/host/xhci.h      |  4 ++--
>   5 files changed, 54 insertions(+), 9 deletions(-)
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable"
  2014-11-14  3:14 ` [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu, Baolu
@ 2014-11-14  8:51   ` Mathias Nyman
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2014-11-14  8:51 UTC (permalink / raw)
  To: Lu, Baolu, Mathias Nyman, Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel

On 14.11.2014 05:14, Lu, Baolu wrote:
> Hi Mathias,
> 
> This patch series has been acked by Alan Stern. There seems no further comments from others. Can you please pull in it?
> 
> Thanks,
> -baolu
> 

Ah, yes, thanks for reminding, I'll pull them in and send them forward.

-Mathias


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-14  8:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-06  2:50 [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu Baolu
2014-11-06  2:50 ` [PATCH v4 1/3] usb: xhci: Revert " Lu Baolu
2014-11-06  2:50 ` [PATCH v4 2/3] usb: xhci: This reworks ff8cbf250b448aac35589f6075082c3fcad8a8fe Lu Baolu
2014-11-06  2:50 ` [PATCH v4 3/3] usb: xhci: fix comment for PORT_DEV_REMOVE Lu Baolu
2014-11-14  3:14 ` [PATCH v4 0/3] Rework "xhci: clear root port wake on bits if controller isn't wake-up capable" Lu, Baolu
2014-11-14  8:51   ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox