Skip to contentSkip to conversation

usb: host: xhci: wait CNR when doing xhci resume

PATCH Superseded Rick Tseng 2 participants 2 messages Sep 6, 2019 – Sep 12, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Rick Tseng

author
#0 lore raw

PATCH v2 1/1 usb: host: xhci: wait CNR when doing xhci resume

NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.

---
 drivers/usb/host/xhci.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/host/xhci.c +9 -0
index 03d1e55..6c7102c 100644
@@ -1108,6 +1108,15 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
 		hibernated = true;
 
 	if (!hibernated) {
+		/* Some xHC would lose power during suspend, so wait for
+		 * controller ready from resume as xHC init.
+		 */
+		if (xhci_handshake(&xhci->op_regs->status,
+				   STS_CNR, 0, 10 * 1000 * 1000)) {
+			xhci_warn(xhci, "WARN: xHC timeout for CNR clear\n");
+			spin_unlock_irq(&xhci->lock);
+			return -ETIMEDOUT;
+		}
 		/* step 1: restore register */
 		xhci_restore_registers(xhci);
 		/* step 2: initialize command ring buffer */
Signature · 1 line
2.1.4
#1 lore raw
Quoted 15 lines · Rick Tseng

NVIDIA 3.1 xHCI card would lose power when moving power state into D3Cold. Thus we need to wait CNR bit to clear when xhci resmue as xhci init.

---
  drivers/usb/host/xhci.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/usb/host/xhci.c +0 -0
index 03d1e55..6c7102c 100644
@@ -1108,6 +1108,15 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
  		hibernated = true;
 

drivers/usb/host/xhci.c int xhci_resume(struct xhci_hcd *xhci, bool hibernated) · line 1119

Quoted 10 lines
drivers/usb/host/xhci.c +9 -0
  	if (!hibernated) {
+		/* Some xHC would lose power during suspend, so wait for
+		 * controller ready from resume as xHC init.
+		 */
+		if (xhci_handshake(&xhci->op_regs->status,
+				   STS_CNR, 0, 10 * 1000 * 1000)) {
+			xhci_warn(xhci, "WARN: xHC timeout for CNR clear\n");
+			spin_unlock_irq(&xhci->lock);
+			return -ETIMEDOUT;
+		}

xhci_handshake() can return -ENODEV in case controller is not reachable (still in PCI D3). Would be better to just show and return what xhci_handshake() returns.
I know there are places where the existing code doesn't do this, but it would be better to add it for new code

ret = xhci_handshake(CNR bit clear)

if (ret) {
	xhci_warn(xhci, "Controller not ready at resume %d\n", ret);
	unlock()
	return ret
}

-Mathias