All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] xhci features for usb-next
@ 2020-03-12 14:45 Mathias Nyman
  2020-03-12 14:45 ` [PATCH 1/9] xhci: bail out early if driver can't accress host in resume Mathias Nyman
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

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(-)

-- 
2.17.1


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

* [PATCH 1/9] xhci: bail out early if driver can't accress host in resume
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 2/9] xhci: Add a separate debug message for split transaction errors Mathias Nyman
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

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.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index dbac0fa9748d..fe38275363e0 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -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");
-- 
2.17.1


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

* [PATCH 2/9] xhci: Add a separate debug message for split transaction errors.
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
  2020-03-12 14:45 ` [PATCH 1/9] xhci: bail out early if driver can't accress host in resume Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 3/9] xhci: Show host status when watchdog triggers and host is assumed dead Mathias Nyman
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Don'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.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index d23f7408c81f..efcddc0c0991 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -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);
-- 
2.17.1


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

* [PATCH 3/9] xhci: Show host status when watchdog triggers and host is assumed dead.
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
  2020-03-12 14:45 ` [PATCH 1/9] xhci: bail out early if driver can't accress host in resume Mathias Nyman
  2020-03-12 14:45 ` [PATCH 2/9] xhci: Add a separate debug message for split transaction errors Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 4/9] usb: xhci: Enable LPM for VIA LABS VL805 Mathias Nyman
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Additional 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.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c |  4 ++++
 drivers/usb/host/xhci.h      | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index efcddc0c0991..ba512b25901a 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -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);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 3ecee10fdcdc..d74f1be26a58 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -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];
-- 
2.17.1


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

* [PATCH 4/9] usb: xhci: Enable LPM for VIA LABS VL805
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (2 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 3/9] xhci: Show host status when watchdog triggers and host is assumed dead Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 5/9] usb: host: xhci-tegra: Tegra186/Tegra194 LPM Mathias Nyman
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Nicolas Saenz Julienne, Mathias Nyman

From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

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.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 5e9b537df631..09786fbed996 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -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;
-- 
2.17.1


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

* [PATCH 5/9] usb: host: xhci-tegra: Tegra186/Tegra194 LPM
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (3 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 4/9] usb: xhci: Enable LPM for VIA LABS VL805 Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 6/9] xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3 Mathias Nyman
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, JC Kuo, Mathias Nyman

From: JC Kuo <jckuo@nvidia.com>

Tegra186 and Tegra194 xHC supports USB 3.0 LPM. This commit enables
XHCI_LPM_SUPPORT quirk for Tegra186 and Tegra194.

Signed-off-by: JC Kuo <jckuo@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-tegra.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 8163aefc6c6b..a6e36b3c968f 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -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)
-- 
2.17.1


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

* [PATCH 6/9] xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (4 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 5/9] usb: host: xhci-tegra: Tegra186/Tegra194 LPM Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 7/9] xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0 Mathias Nyman
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Kai-Heng Feng, Mathias Nyman

From: Kai-Heng Feng <kai.heng.feng@canonical.com>

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.

[use usleep_range(), and shorten the delay time while polling -Mathias]
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index af92b2576fe9..712cd44f05ac 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -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);
-- 
2.17.1


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

* [PATCH 7/9] xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (5 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 6/9] xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3 Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 8/9] xhci: Finetune host initiated USB3 rootport link suspend and resume Mathias Nyman
  2020-03-12 14:45 ` [PATCH 9/9] xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI Mathias Nyman
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Kai-Heng Feng, Mathias Nyman

From: Kai-Heng Feng <kai.heng.feng@canonical.com>

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.

[variable rename to u3exit, and skip completion for usb2 ports -Mathias ]
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 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(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 712cd44f05ac..02f52d4f74df 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -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:
 			/*
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 884c601bfa15..9764122c9cdf 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -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))
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index ba512b25901a..a78787bb5133 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -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
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d74f1be26a58..fbf26b20c1e1 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -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];
 };
 
 
-- 
2.17.1


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

* [PATCH 8/9] xhci: Finetune host initiated USB3 rootport link suspend and resume
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (6 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 7/9] xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0 Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  2020-03-12 14:45 ` [PATCH 9/9] xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI Mathias Nyman
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Depending 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.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 02f52d4f74df..a9c87eb8951e 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -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)))
-- 
2.17.1


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

* [PATCH 9/9] xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI
  2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
                   ` (7 preceding siblings ...)
  2020-03-12 14:45 ` [PATCH 8/9] xhci: Finetune host initiated USB3 rootport link suspend and resume Mathias Nyman
@ 2020-03-12 14:45 ` Mathias Nyman
  8 siblings, 0 replies; 10+ messages in thread
From: Mathias Nyman @ 2020-03-12 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mika Westerberg, Mathias Nyman

From: Mika Westerberg <mika.westerberg@linux.intel.com>

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.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 09786fbed996..c37b736d93f9 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -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 &&
-- 
2.17.1


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

end of thread, other threads:[~2020-03-12 14:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 14:45 [PATCH 0/9] xhci features for usb-next Mathias Nyman
2020-03-12 14:45 ` [PATCH 1/9] xhci: bail out early if driver can't accress host in resume Mathias Nyman
2020-03-12 14:45 ` [PATCH 2/9] xhci: Add a separate debug message for split transaction errors Mathias Nyman
2020-03-12 14:45 ` [PATCH 3/9] xhci: Show host status when watchdog triggers and host is assumed dead Mathias Nyman
2020-03-12 14:45 ` [PATCH 4/9] usb: xhci: Enable LPM for VIA LABS VL805 Mathias Nyman
2020-03-12 14:45 ` [PATCH 5/9] usb: host: xhci-tegra: Tegra186/Tegra194 LPM Mathias Nyman
2020-03-12 14:45 ` [PATCH 6/9] xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3 Mathias Nyman
2020-03-12 14:45 ` [PATCH 7/9] xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0 Mathias Nyman
2020-03-12 14:45 ` [PATCH 8/9] xhci: Finetune host initiated USB3 rootport link suspend and resume Mathias Nyman
2020-03-12 14:45 ` [PATCH 9/9] xhci-pci: Allow host runtime PM as default for Intel Tiger Lake xHCI Mathias Nyman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.