Skip to contentSkip to conversation

xhci: Check all endpoints for LPM timeout

PATCH In review Jan Schmidt 3 participants 7 messages Sep 12, 2019 – Sep 18, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xhci: Check all endpoints for LPM timeout

If an endpoint is encountered that returns USB3_LPM_DEVICE_INITIATED, keep checking further endpoints, as there might be periodic endpoints later that return USB3_LPM_DISABLED due to shorter service intervals.

Without this, the code can set too high a maximum-exit-latency and prevent the use of multiple USB3 cameras that should be able to work.

---
 drivers/usb/host/xhci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/xhci.c +4 -4
index 03d1e552769b..1986b88661fc 100644
@@ -4673,12 +4673,12 @@ static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
 	alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
 		desc, state, timeout);
 
-	/* If we found we can't enable hub-initiated LPM, or
+	/* If we found we can't enable hub-initiated LPM, and
 	 * the U1 or U2 exit latency was too high to allow
-	 * device-initiated LPM as well, just stop searching.
+	 * device-initiated LPM as well, then we will disable LPM
+	 * for this device, so stop searching any further.
 	 */
-	if (alt_timeout == USB3_LPM_DISABLED ||
-			alt_timeout == USB3_LPM_DEVICE_INITIATED) {
+	if (alt_timeout == USB3_LPM_DISABLED) {
 		*timeout = alt_timeout;
 		return -E2BIG;
 	}
Signature · 1 line
2.21.0
#1 lore raw
Quoted 9 lines · Jan Schmidt

If an endpoint is encountered that returns USB3_LPM_DEVICE_INITIATED, keep checking further endpoints, as there might be periodic endpoints later that return USB3_LPM_DISABLED due to shorter service intervals.

Without this, the code can set too high a maximum-exit-latency and prevent the use of multiple USB3 cameras that should be able to work.

This fixes the capture from multiple Oculus Sensors, as described in the "Not enough bandwidth with Magewell XI100DUSB-HDMI" thread:

https://lore.kernel.org/linux-usb/CA+gwMce-h9LPCv1hhfEcRz_2w9mEQLOjy42dcjvPxTeawSU5kQ@mail.gmail.com/

regards
Philipp

#2 lore raw
In reply to Jan Schmidt
Quoted 25 lines · Jan Schmidt

If an endpoint is encountered that returns USB3_LPM_DEVICE_INITIATED, keep checking further endpoints, as there might be periodic endpoints later that return USB3_LPM_DISABLED due to shorter service intervals.

Without this, the code can set too high a maximum-exit-latency and prevent the use of multiple USB3 cameras that should be able to work.

---
  drivers/usb/host/xhci.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/xhci.c +1 -1
index 03d1e552769b..1986b88661fc 100644
@@ -4673,12 +4673,12 @@ static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
  	alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
  		desc, state, timeout);
 
-	/* If we found we can't enable hub-initiated LPM, or
+	/* If we found we can't enable hub-initiated LPM, and
  	 * the U1 or U2 exit latency was too high to allow

drivers/usb/host/xhci.c static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, · line 4684

Quoted 10 lines
drivers/usb/host/xhci.c +3 -3
-	 * device-initiated LPM as well, just stop searching.
+	 * device-initiated LPM as well, then we will disable LPM
+	 * for this device, so stop searching any further.
  	 */
-	if (alt_timeout == USB3_LPM_DISABLED ||
-			alt_timeout == USB3_LPM_DEVICE_INITIATED) {
+	if (alt_timeout == USB3_LPM_DISABLED) {
  		*timeout = alt_timeout;
  		return -E2BIG;
  	}

Thanks, nice catch. Adding to queue.

While looking at this I see we have a similar issue if driver has "disable_hub_initiated_lpm" flag set.

xhci_get_timeout_no_hub_lpm() might return USB3_LPM_DEVICE_INITIATED before we check if periodic endpoints would require disabling LPM completely.

xhci_calculate_lpm_timeout()
...

    for (i = 0; i < config->desc.bNumInterfaces; i++) {
        ...
        if (intf->dev.driver) {
            ...
            if (driver && driver->disable_hub_initiated_lpm) {
                return xhci_get_timeout_no_hub_lpm(udev, state);

I'll write a patch for that

-Mathias

#3 lore raw
Quoted 32 lines · Mathias Nyman
Quoted 31 lines · Jan Schmidt

If an endpoint is encountered that returns USB3_LPM_DEVICE_INITIATED, keep
checking further endpoints, as there might be periodic endpoints later that return USB3_LPM_DISABLED due to shorter service intervals.

Without this, the code can set too high a maximum-exit-latency and prevent the use of multiple USB3 cameras that should be able to work.

---
  drivers/usb/host/xhci.c | 8 ++++----

  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/host/xhci.c +0 -0
index 03d1e552769b..1986b88661fc 100644
@@ -4673,12 +4673,12 @@ static int
 xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
       alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci,
 udev,
           desc, state, timeout);

  -    /* If we found we can't enable hub-initiated LPM, or +    /* If we found we can't enable hub-initiated LPM, and
       * the U1 or U2 exit latency was too high to allow -     * device-initiated LPM as well, just stop searching. +     * device-initiated LPM as well, then we will disable LPM +     * for this device, so stop searching any further. */
-    if (alt_timeout == USB3_LPM_DISABLED ||

Quoted 8 lines
Quoted 6 lines

-            alt_timeout == USB3_LPM_DEVICE_INITIATED) { +    if (alt_timeout == USB3_LPM_DISABLED) { *timeout = alt_timeout;
          return -E2BIG;
      }

Thanks, nice catch. Adding to queue.

Great news for the Oculus Rift support we're working on :)

Quoted 6 lines

While looking at this I see we have a similar issue if driver has "disable_hub_initiated_lpm" flag set.

xhci_get_timeout_no_hub_lpm() might return USB3_LPM_DEVICE_INITIATED before we check if periodic endpoints would require disabling LPM completely.

Indeed - sorry, I didn't even think to look past the immediate issue.

Quoted 10 lines

xhci_calculate_lpm_timeout()
...
    for (i = 0; i < config->desc.bNumInterfaces; i++) {
        ...
        if (intf->dev.driver) {
            ...
            if (driver && driver->disable_hub_initiated_lpm) { return xhci_get_timeout_no_hub_lpm(udev, state);

I'll write a patch for that

I'll be happy to test by hard-coding the flag.

- Jan.

Quoted 2 lines

-Mathias

Signature · 1 line
Jan Schmidt, Centricular Ltd - https://centricular.com/
#4 lore raw

PATCH 1/1 xhci: Prevent device initiated U1/U2 link pm if exit latency is too long

If host/hub initiated link pm is prevented by a driver flag we still must ensure that periodic endpoints have longer service intervals than link pm exit latency before allowing device initiated link pm.

Fix this by continue walking and checking endpoint service interval if xhci_get_timeout_no_hub_lpm() returns anything else than USB3_LPM_DISABLED

While at it fix the split line error message

---
 drivers/usb/host/xhci.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/host/xhci.c +6 -4
index 447c29bbad48..8892dfbb2af7 100644
@@ -4809,10 +4809,12 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
 		if (intf->dev.driver) {
 			driver = to_usb_driver(intf->dev.driver);
 			if (driver && driver->disable_hub_initiated_lpm) {
-				dev_dbg(&udev->dev, "Hub-initiated %s disabled "
-						"at request of driver %s\n",
-						state_name, driver->name);
-				return xhci_get_timeout_no_hub_lpm(udev, state);
+				dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n",
+					state_name, driver->name);
+				timeout = xhci_get_timeout_no_hub_lpm(udev,
+								      state);
+				if (timeout == USB3_LPM_DISABLED)
+					return timeout;
 			}
 		}
 
Signature · 1 line
2.7.4
author Tested-by on v1 1/1
#5 lore raw

Re: [RFT PATCH] xhci: Prevent device initiated U1/U2 link pm if exit latency is too long

Quoted 10 lines · Mathias Nyman

If host/hub initiated link pm is prevented by a driver flag we still must ensure that periodic endpoints have longer service intervals than link pm exit latency before allowing device initiated link pm.

Fix this by continue walking and checking endpoint service interval if xhci_get_timeout_no_hub_lpm() returns anything else than USB3_LPM_DISABLED

While at it fix the split line error message

I tested by forcing the driver->disable_hub_initiated_lpm check and confirm a) Other USB devices still work as I expect them to b) without this patch, I'm back to only 1 working Oculus Rift Sensor. With it, I can capture 3 simultaneously.

- Jan

Quoted 26 lines
---
 drivers/usb/host/xhci.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/host/xhci.c +6 -4
index 447c29bbad48..8892dfbb2af7 100644
@@ -4809,10 +4809,12 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
 		if (intf->dev.driver) {
 			driver = to_usb_driver(intf->dev.driver);
 			if (driver && driver->disable_hub_initiated_lpm) {
-				dev_dbg(&udev->dev, "Hub-initiated %s disabled "
-						"at request of driver %s\n",
-						state_name, driver->name);
-				return xhci_get_timeout_no_hub_lpm(udev, state);
+				dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n",
+					state_name, driver->name);
+				timeout = xhci_get_timeout_no_hub_lpm(udev,
+								      state);
+				if (timeout == USB3_LPM_DISABLED)
+					return timeout;
 			}
 		}
 
Signature · 1 line
Jan Schmidt, Centricular Ltd - https://centricular.com/
#6 lore raw

Re: [RFT PATCH] xhci: Prevent device initiated U1/U2 link pm if exit latency is too long

Quoted 12 lines · Jan Schmidt
Quoted 9 lines · Mathias Nyman

If host/hub initiated link pm is prevented by a driver flag we still must ensure that periodic endpoints have longer service intervals than link pm exit latency before allowing device initiated link pm.

Fix this by continue walking and checking endpoint service interval if xhci_get_timeout_no_hub_lpm() returns anything else than USB3_LPM_DISABLED

While at it fix the split line error message

Quoted 9 lines
Quoted 1 line

I tested by forcing the driver->disable_hub_initiated_lpm check and confirm a) Other USB devices still work as I expect them to b) without this patch, I'm back to only 1 working Oculus Rift Sensor. With it, I can capture 3 simultaneously.

Great, thanks, I'll queue up that patch as well with your Tested-by tag

-Mathias