diff mbox series

[v2,4/7] usb: xhci: Workaround undercalculated BW for fullspeed BI

Message ID ed5ddb78abd157ef2bb9317545b9fec63c6a5b66.1618014279.git.Thinh.Nguyen@synopsys.com
State New
Headers show
Series usb: Set quirks for xhci/dwc3 host mode | expand

Commit Message

Thinh Nguyen April 10, 2021, 12:47 a.m. UTC
DWC_usb31 host version 1.90a and prior undercalculates the bandwidth
available for interrupt endpoints. The controller will return bandwidth
error on config endpoint commands if there are already 6 or more
fullspeed interrupt endpoints with bInterval of 4 (or 4ms) associated
with a single fullspeed bus instance (BI).

To workaround this, configure and use the endpoint at a shorter
interrupt interval. Lower the ep_ctx interval from 5 to 4 (or 2ms)
for interrupt endpoints of the fullspeed BI. Note: we have not observed
functional impact to the fullspeed devices by lowering the interrupt
service interval (at least for a few devices that we tested).

To simplify the workaround, let's just check and apply the workaround if
the endpoint is a fullspeed interrupt endpoint with interval of 4ms and
if the top parent device is also operating in fullspeed (i.e. associated
with fullspeed BI).

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
Changes in v2:
- None

Note:
Checkpatch will give a warning below for getting top_dev:
	WARNING: suspect code indent for conditional statements

Since this logic is done everywhere else in the driver, I'm keeping it
consistent here.

 drivers/usb/host/xhci-mem.c     | 23 +++++++++++++++++++++++
 include/linux/usb/xhci-quirks.h |  1 +
 2 files changed, 24 insertions(+)

Comments

Mathias Nyman April 28, 2021, 11:57 a.m. UTC | #1
On 10.4.2021 3.47, Thinh Nguyen wrote:
> DWC_usb31 host version 1.90a and prior undercalculates the bandwidth

> available for interrupt endpoints. The controller will return bandwidth

> error on config endpoint commands if there are already 6 or more

> fullspeed interrupt endpoints with bInterval of 4 (or 4ms) associated

> with a single fullspeed bus instance (BI).

> 

> To workaround this, configure and use the endpoint at a shorter

> interrupt interval. Lower the ep_ctx interval from 5 to 4 (or 2ms)

> for interrupt endpoints of the fullspeed BI. Note: we have not observed

> functional impact to the fullspeed devices by lowering the interrupt

> service interval (at least for a few devices that we tested).

> 

> To simplify the workaround, let's just check and apply the workaround if

> the endpoint is a fullspeed interrupt endpoint with interval of 4ms and

> if the top parent device is also operating in fullspeed (i.e. associated

> with fullspeed BI).

> 

> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

> ---

> Changes in v2:

> - None

> 

> Note:

> Checkpatch will give a warning below for getting top_dev:

> 	WARNING: suspect code indent for conditional statements

> 

> Since this logic is done everywhere else in the driver, I'm keeping it

> consistent here.

> 

>  drivers/usb/host/xhci-mem.c     | 23 +++++++++++++++++++++++

>  include/linux/usb/xhci-quirks.h |  1 +

>  2 files changed, 24 insertions(+)

> 

> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c

> index 1053b43008e4..e01d0ddb012a 100644

> --- a/drivers/usb/host/xhci-mem.c

> +++ b/drivers/usb/host/xhci-mem.c

> @@ -1463,6 +1463,29 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,

>  		}

>  	}

>  

> +	/*

> +	 * Check for undercalculated bandwidth quirk for interrupt endpoints

> +	 * associated with fullspeed BI.

> +	 */

> +	if ((xhci->quirks & XHCI_LIMIT_FS_BI_INTR_EP) &&

> +	    usb_endpoint_xfer_int(&ep->desc) &&

> +	    udev->speed == USB_SPEED_FULL &&

> +	    interval == 5) {

> +		struct usb_device *top_dev;

> +

> +		for (top_dev = udev;

> +		     top_dev->parent && top_dev->parent->parent;

> +		     top_dev = top_dev->parent)

> +			/* Found device below root hub */;

> +

> +		/*

> +		 * If the top device is operating at fullspeed, then the

> +		 * controller is using fullspeed BI for this device.

> +		 */

> +		if (top_dev->speed == USB_SPEED_FULL)

> +			interval = 4;

> +	}

> +



If we write a new xhci-snps driver then adjusting the interval could be done in the
.add_endpoint override, after calling xhci_add_endpoint()

If not then something like this should work.
Maybe turn it into a separate function for readability.

xhci_tune_interval_quirk(xhci, udev, ep, &interval)

-Mathias
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1053b43008e4..e01d0ddb012a 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1463,6 +1463,29 @@  int xhci_endpoint_init(struct xhci_hcd *xhci,
 		}
 	}
 
+	/*
+	 * Check for undercalculated bandwidth quirk for interrupt endpoints
+	 * associated with fullspeed BI.
+	 */
+	if ((xhci->quirks & XHCI_LIMIT_FS_BI_INTR_EP) &&
+	    usb_endpoint_xfer_int(&ep->desc) &&
+	    udev->speed == USB_SPEED_FULL &&
+	    interval == 5) {
+		struct usb_device *top_dev;
+
+		for (top_dev = udev;
+		     top_dev->parent && top_dev->parent->parent;
+		     top_dev = top_dev->parent)
+			/* Found device below root hub */;
+
+		/*
+		 * If the top device is operating at fullspeed, then the
+		 * controller is using fullspeed BI for this device.
+		 */
+		if (top_dev->speed == USB_SPEED_FULL)
+			interval = 4;
+	}
+
 	mult = xhci_get_endpoint_mult(udev, ep);
 	max_packet = usb_endpoint_maxp(&ep->desc);
 	max_burst = xhci_get_endpoint_max_burst(udev, ep);
diff --git a/include/linux/usb/xhci-quirks.h b/include/linux/usb/xhci-quirks.h
index 65bb62d3d31d..5bedf5a25f7a 100644
--- a/include/linux/usb/xhci-quirks.h
+++ b/include/linux/usb/xhci-quirks.h
@@ -59,5 +59,6 @@ 
 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK	BIT_ULL(39)
 #define XHCI_NO_SOFT_RETRY		BIT_ULL(40)
 #define XHCI_ISOC_BLOCKED_DISCONNECT	BIT_ULL(41)
+#define XHCI_LIMIT_FS_BI_INTR_EP	BIT_ULL(42)
 
 #endif /* __LINUX_USB_XHCI_QUIRKS_H */