Skip to contentSkip to conversation

eUSB2 Double Isochronous IN Bandwidth support

PATCH In review Sakari Ailus 3 participants 18 messages Aug 20, 2025 – Aug 26, 2025

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

v5 cover eUSB2 Double Isochronous IN Bandwidth support

Hi all,

This series enables support for eUSB2 Double Isochronous IN Bandwidth UVC devices specified in 'USB 2.0 Double Isochronous IN Bandwidth' ECN. In short, it adds support for new integrated USB2 webcams that can send twice the data compared to conventional USB2 webcams.

These devices are identified by the device descriptor bcdUSB 0x0220 value. They have an additional eUSB2 Isochronous Endpoint Companion Descriptor, and a zero max packet size in regular isoc endpoint descriptor. Support for parsing that new descriptor was added in commit

c749f058b437 ("USB: core: Add eUSB2 descriptor and parsing in USB core")

This series adds support to UVC, USB core, and xHCI to identify eUSB2 double isoc devices, and allow and set proper max packet, iso frame desc sizes, bytes per interval, and other values in URBs and xHCI endpoint contexts needed to support the double data rates for eUSB2 double isoc devices.

v1 can be found here <URL:https://lore.kernel.org/linux-usb/[email protected]/>.

v2 can be found here <URL:https://lore.kernel.org/linux-usb/[email protected]/>.

v3 can be found here <URL:https://lore.kernel.org/linux-usb/[email protected]/>.

v4 can be found here <URL:https://lore.kernel.org/linux-usb/[email protected]/>.

since v4:

- New patch: use le16_to_cpu() to access endpoint descriptor's wMaxPacketSize field, which is an __le16. This isn't a bugfix as the value was compared to 0.

- New patch: add USB device speed check for eUSB2 isochronous endpoint companion parsing. The check is then removed from sites checking the existence of the companion (through companion's bDescriptorType field, which is non-zero for valid descriptors).

- New patch: do not parse eUSB2 isoc double BW companion descriptor on interrupt or OUT endpoints. It is not supposed to be found there, according to the ECN.

- Rename usb_endpoint_max_isoc_bpi() as usb_endpoint_max_periodic_payload() and move it right after usb_maxpacket().

- Fixed @ep reference in kernel-doc documentation for usb_endpoint_max_periodic_payload().

- In usb_endpoint_max_periodic_payload(), call struct usb_device pointer argument "udev" instead of "dev", to align with naming elsewhere.

- Add support for interrupt endpoints in usb_endpoint_max_periodic_payload(); eUSB2 double isoc BW is still limited to isochronous endpoints though.

- In usb_endpoint_max_periodic_payload(), remove the separate case for USB_SPEED_HIGH as the check is already done in parsing the eUSB isoc double BW companion, which is checked for.

- New patch: use usb_endpoint_max_periodic_payload() in xHCI driver, replacing xhci_get_max_esit_payload().

- Check non-zero bDescriptorType field of ep->eusb2_isoc_ep_comp instead of dwBytesPerInterval value exceeding 3072, where xhci_eusb2_is_isoc_bw_double() was used. This aligns the checks of eUSB2 isochronous double bandwidth support for an endpoint.

- New patch: introduce usb_endpoint_is_hs_isoc_double() to figure out whether an endpoint uses isochronous double bandwidth and use the function in the xHCI driver and the usb core. xhci_eusb2_is_isoc_bw_double() is dropped, as well as the MAX_ISOC_XFER_SIZE_HS macro. usb_endpoint_is_hs_isoc_double() also includes check for bcdUSB == 0x220, to anticipate adding support for eUSB2V2.

- Merge condition for checking eUSB2 isoc double bw support for xHCI/endpoint in xhci_get_endpoint_mult().

- Improve comment regarding maximum packet size bits 12:11 in xhci_get_endpoint_max_burst().

- Aligned subject prefixes with the recent patches to the same files.

since v3:

- Use spaces in aligning macro body for HCC2_EUSB2_DIC() (1st patch).

- Move usb_endpoint_max_isoc_bpi() to drivers/usb/core/usb.c (3rd patch).

since v2:

- Use ep->eusb2_isoc_ep_comp.bDescriptorType to determined whether the eUSB2 isochronous endpoint companion descriptor exists.

- Clean up eUSB2 double isoc bw maxp calculation.

- Drop le16_to_cpu(udev->descriptor.bcdUSB) == 0x220 check from xhci_eusb2_is_isoc_bw_double() -- it's redundant as ep->eusb2_isoc_ep_comp.dwBytesPerInterval will be zero otherwise.

- Add kernel-doc documentation for usb_endpoint_max_isoc_bpi().

- Check the endpoint has IN direction in usb_endpoint_max_isoc_bpi() and usb_submit_urb() as a condition for eUSB2 isoc double bw.

since v1:

- Introduce uvc_endpoint_max_isoc_bpi() to obtain maximum bytes per interval value for an endpoint, in a new patch (3rd). This code has been slightly reworked from the instance in the UVC driver, including support for SuperSpeedPlus Isochronous Endpoint Companion.

- Use usb_endpoint_max_isoc_bpi() in the UVC driver instead of open-coding eUSB2 support there, also drop now-redundant uvc_endpoint_max_bpi().

- Use u32 for maximum bpi and related information in the UVC driver -- the value could be larger than a 16-bit type can hold.

- Assume max in usb_submit_urb() is a natural number as usb_endpoint_maxp() returns only natural numbers (2nd patch).

Rai, Amardeep (3):
usb: core: Add a function to get USB version independent periodic
payload
usb: xhci: Add host support for eUSB2 double isochronous bandwidth
devices
usb: core: support eUSB2 double bandwidth large isoc URB frames

Sakari Ailus (5):
usb: core: Use le16_to_cpu() to read __le16 value in
usb_parse_endpoint()
usb: core: Parse eUSB2 companion descriptors for high speed devices
only
usb: core: eUSB2 companion descriptor is for isoc IN endpoints only
usb: xhci: Use usb_endpoint_max_periodic_payload()
usb: core: Introduce usb_endpoint_is_hs_isoc_double()

Tao Q Tao (1):
media: uvcvideo: eUSB2 double isochronous bandwidth support

 drivers/media/usb/uvc/uvc_driver.c |  4 +-
 drivers/media/usb/uvc/uvc_video.c  | 24 ++-------
 drivers/media/usb/uvc/uvcvideo.h   |  4 +-
 drivers/usb/core/config.c          |  4 +-
 drivers/usb/core/urb.c             | 14 +++--
 drivers/usb/core/usb.c             | 50 ++++++++++++++++++
 drivers/usb/host/xhci-caps.h       |  2 +
 drivers/usb/host/xhci-mem.c        | 85 ++++++++++++++----------------
 drivers/usb/host/xhci-ring.c       |  6 +--
 drivers/usb/host/xhci.c            | 16 +++++-
 drivers/usb/host/xhci.h            |  2 +
 include/linux/usb.h                |  6 +++
 12 files changed, 137 insertions(+), 80 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH v5 1/9 usb: core: Use le16_to_cpu() to read __le16 value in usb_parse_endpoint()

wMaxPacketSize field in struct usb_endpoint_descriptor is an __le16, use le16_to_cpu() to read it.

---
 drivers/usb/core/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/config.c +1 -1
index 42468bbeffd2..cda595b4014f 100644
@@ -507,7 +507,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
 	}
 
 	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
-	if (bcdUSB == 0x0220 && d->wMaxPacketSize == 0 &&
+	if (bcdUSB == 0x0220 && !le16_to_cpu(d->wMaxPacketSize) &&
 	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
 		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
 							endpoint, buffer, size);
Signature · 1 line
2.47.2
Acked-by on v5 1/9
#2 lore raw

Re: [PATCH v5 1/9] usb: core: Use le16_to_cpu() to read __le16 value in usb_parse_endpoint()

Quoted 13 lines · Sakari Ailus

wMaxPacketSize field in struct usb_endpoint_descriptor is an __le16, use le16_to_cpu() to read it.

---
  drivers/usb/core/config.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/config.c +0 -0
index 42468bbeffd2..cda595b4014f 100644

drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 513

Quoted 8 lines
drivers/usb/core/config.c +1 -1
@@ -507,7 +507,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
  	}
 
  	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
-	if (bcdUSB == 0x0220 && d->wMaxPacketSize == 0 &&
+	if (bcdUSB == 0x0220 && !le16_to_cpu(d->wMaxPacketSize) &&
  	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
  		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
  							endpoint, buffer, size);
#3 lore raw

PATCH v5 2/9 usb: core: Parse eUSB2 companion descriptors for high speed devices only

In reply to Sakari Ailus

Check that a device is a high-speed one before proceeding to parse the eUSB2 isochronous endpoint companion descriptors.

---
 drivers/usb/core/config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +2 -1
index cda595b4014f..29fcbd6de482 100644
@@ -507,7 +507,8 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
 	}
 
 	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
-	if (bcdUSB == 0x0220 && !le16_to_cpu(d->wMaxPacketSize) &&
+	if (udev->speed == USB_SPEED_HIGH && bcdUSB == 0x0220 &&
+	    !le16_to_cpu(d->wMaxPacketSize) &&
 	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
 		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
 							endpoint, buffer, size);
Signature · 1 line
2.47.2
Acked-by on v5 2/9
#4 lore raw

Re: [PATCH v5 2/9] usb: core: Parse eUSB2 companion descriptors for high speed devices only

Quoted 13 lines · Sakari Ailus

Check that a device is a high-speed one before proceeding to parse the eUSB2 isochronous endpoint companion descriptors.

---
  drivers/usb/core/config.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +0 -0
index cda595b4014f..29fcbd6de482 100644

drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 514

Quoted 9 lines
drivers/usb/core/config.c +2 -1
@@ -507,7 +507,8 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
  	}
 
  	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
-	if (bcdUSB == 0x0220 && !le16_to_cpu(d->wMaxPacketSize) &&
+	if (udev->speed == USB_SPEED_HIGH && bcdUSB == 0x0220 &&
+	    !le16_to_cpu(d->wMaxPacketSize) &&
  	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
  		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
  							endpoint, buffer, size);
#5 lore raw

PATCH v5 3/9 usb: core: eUSB2 companion descriptor is for isoc IN endpoints only

In reply to Sakari Ailus

The eUSB2 isochronous double bandwidth endpoint descriptor is allowed for the isochronous IN endpoints, according to the ECN. Do not parse these descriptors if they are found in interrupt or OUT endpoints.

---
 drivers/usb/core/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/core/config.c +1 -2
index 29fcbd6de482..baf5bc844b6f 100644
@@ -508,8 +508,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
 
 	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
 	if (udev->speed == USB_SPEED_HIGH && bcdUSB == 0x0220 &&
-	    !le16_to_cpu(d->wMaxPacketSize) &&
-	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
+	    !le16_to_cpu(d->wMaxPacketSize) && usb_endpoint_is_isoc_in(d))
 		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
 							endpoint, buffer, size);
 
Signature · 1 line
2.47.2
Acked-by on v5 3/9
#6 lore raw

Re: [PATCH v5 3/9] usb: core: eUSB2 companion descriptor is for isoc IN endpoints only

Quoted 14 lines · Sakari Ailus

The eUSB2 isochronous double bandwidth endpoint descriptor is allowed for the isochronous IN endpoints, according to the ECN. Do not parse these descriptors if they are found in interrupt or OUT endpoints.

---
  drivers/usb/core/config.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/core/config.c +0 -0
index 29fcbd6de482..baf5bc844b6f 100644

drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 514

Quoted 9 lines
drivers/usb/core/config.c +1 -2
@@ -508,8 +508,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
 
  	/* Parse a possible eUSB2 periodic endpoint companion descriptor */
  	if (udev->speed == USB_SPEED_HIGH && bcdUSB == 0x0220 &&
-	    !le16_to_cpu(d->wMaxPacketSize) &&
-	    (usb_endpoint_xfer_isoc(d) || usb_endpoint_xfer_int(d)))
+	    !le16_to_cpu(d->wMaxPacketSize) && usb_endpoint_is_isoc_in(d))
  		usb_parse_eusb2_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
  							endpoint, buffer, size);
 
#7 lore raw

PATCH v5 4/9 usb: core: Add a function to get USB version independent periodic payload

In reply to Sakari Ailus

From: "Rai, Amardeep" <[email protected]>

Add usb_endpoint_max_periodic_payload() to obtain maximum payload bytes in a service interval for isochronous and interrupt endpoints in a USB version independent way.

---
 drivers/usb/core/usb.c | 29 +++++++++++++++++++++++++++++
 include/linux/usb.h    |  3 +++
 2 files changed, 32 insertions(+)
drivers/usb/core/usb.c +29 -0
index fca7735fc660..ca9ff6ad8e73 100644
@@ -1110,6 +1110,35 @@ void usb_free_noncoherent(struct usb_device *dev, size_t size,
 }
 EXPORT_SYMBOL_GPL(usb_free_noncoherent);
 
+/**
+ * usb_endpoint_max_periodic_payload - Get maximum payload bytes per service
+ *				       interval
+ * @udev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous or interrupt endpoint @ep
+ * can transfer during a service interval, or 0 for other endpoints.
+ */
+u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
+				      const struct usb_host_endpoint *ep)
+{
+	if (!usb_endpoint_xfer_isoc(&ep->desc) &&
+	    !usb_endpoint_xfer_int(&ep->desc))
+		return 0;
+
+	switch (udev->speed) {
+	case USB_SPEED_SUPER_PLUS:
+		if (USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes))
+			return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
+	case USB_SPEED_SUPER:
+		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}
+EXPORT_SYMBOL_GPL(usb_endpoint_max_periodic_payload);
+
 /*
  * Notifications of device and interface registration
  */
include/linux/usb.h +3 -0
index 9d662c6abb4d..e9cf2786d8bd 100644
@@ -2039,6 +2039,9 @@ static inline u16 usb_maxpacket(struct usb_device *udev, int pipe)
 	return usb_endpoint_maxp(&ep->desc);
 }
 
+u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
+				      const struct usb_host_endpoint *ep);
+
 /* translate USB error codes to codes user space understands */
 static inline int usb_translate_errors(int error_code)
 {
Signature · 1 line
2.47.2
#8 lore raw

PATCH v5 5/9 usb: xhci: Use usb_endpoint_max_periodic_payload()

In reply to Sakari Ailus

Use the newly added usb_endpoint_max_periodic_payload() to obtain the maximum number of bytes to transfer during a service interval for isochronous and interrupt endpoints. This will replace the xhci-specific xhci_get_max_esit_payload() which is removed as redundant.

---
 drivers/usb/host/xhci-mem.c | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
drivers/usb/host/xhci-mem.c +1 -31
index 07289333a1e8..d2c04811191f 100644
@@ -1378,36 +1378,6 @@ static u32 xhci_get_endpoint_type(struct usb_host_endpoint *ep)
 	return 0;
 }
 
-/* Return the maximum endpoint service interval time (ESIT) payload.
- * Basically, this is the maxpacket size, multiplied by the burst size
- * and mult size.
- */
-static u32 xhci_get_max_esit_payload(struct usb_device *udev,
-		struct usb_host_endpoint *ep)
-{
-	int max_burst;
-	int max_packet;
-
-	/* Only applies for interrupt or isochronous endpoints */
-	if (usb_endpoint_xfer_control(&ep->desc) ||
-			usb_endpoint_xfer_bulk(&ep->desc))
-		return 0;
-
-	/* SuperSpeedPlus Isoc ep sending over 48k per esit */
-	if ((udev->speed >= USB_SPEED_SUPER_PLUS) &&
-	    USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes))
-		return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval);
-
-	/* SuperSpeed or SuperSpeedPlus Isoc ep with less than 48k per esit */
-	if (udev->speed >= USB_SPEED_SUPER)
-		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
-
-	max_packet = usb_endpoint_maxp(&ep->desc);
-	max_burst = usb_endpoint_maxp_mult(&ep->desc);
-	/* A 0 in max burst means 1 transfer per ESIT */
-	return max_packet * max_burst;
-}
-
 /* Set up an endpoint with one ring segment.  Do not allocate stream rings.
  * Drivers will have to call usb_alloc_streams() to do that.
  */
@@ -1445,7 +1415,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
 	 * have no clue on scatter gather list entry size. For Isoc and Int,
 	 * set it to max available. See xHCI 1.1 spec 4.14.1.1 for details.
 	 */
-	max_esit_payload = xhci_get_max_esit_payload(udev, ep);
+	max_esit_payload = usb_endpoint_max_periodic_payload(udev, ep);
 	interval = xhci_get_endpoint_interval(udev, ep);
 
 	/* Periodic endpoint bInterval limit quirk */
Signature · 1 line
2.47.2
Reviewed-by on v5 5/9
#9 lore raw

Re: [PATCH v5 5/9] usb: xhci: Use usb_endpoint_max_periodic_payload()

Quoted 6 lines · Sakari Ailus

Use the newly added usb_endpoint_max_periodic_payload() to obtain the maximum number of bytes to transfer during a service interval for isochronous and interrupt endpoints. This will replace the xhci-specific xhci_get_max_esit_payload() which is removed as redundant.

#10 lore raw

PATCH v5 6/9 usb: core: Introduce usb_endpoint_is_hs_isoc_double()

In reply to Sakari Ailus

Introduce usb_endpoint_is_hs_isoc_double() tell whether an endpoint conforms to USB 2.0 Isochronous Double IN Bandwidth ECN.

---
 drivers/usb/core/usb.c | 19 +++++++++++++++++++
 include/linux/usb.h    |  3 +++
 2 files changed, 22 insertions(+)
drivers/usb/core/usb.c +19 -0
index ca9ff6ad8e73..939dc4aafb89 100644
@@ -1139,6 +1139,25 @@ u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
 }
 EXPORT_SYMBOL_GPL(usb_endpoint_max_periodic_payload);
 
+/**
+ * usb_endpoint_is_hs_isoc_double - Tell whether an endpoint uses USB 2
+ *                                  Isochronous Double IN Bandwidth
+ * @udev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: true if an endpoint @ep conforms to USB 2 Isochronous Double IN
+ * Bandwidth ECN, false otherwise.
+ */
+bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev,
+				    const struct usb_host_endpoint *ep)
+{
+	return ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		le16_to_cpu(udev->descriptor.bcdUSB) == 0x220 &&
+		usb_endpoint_is_isoc_in(&ep->desc) &&
+		!le16_to_cpu(ep->desc.wMaxPacketSize);
+}
+EXPORT_SYMBOL_GPL(usb_endpoint_is_hs_isoc_double);
+
 /*
  * Notifications of device and interface registration
  */
include/linux/usb.h +3 -0
index e9cf2786d8bd..70ef00c42d22 100644
@@ -2042,6 +2042,9 @@ static inline u16 usb_maxpacket(struct usb_device *udev, int pipe)
 u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
 				      const struct usb_host_endpoint *ep);
 
+bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev,
+				    const struct usb_host_endpoint *ep);
+
 /* translate USB error codes to codes user space understands */
 static inline int usb_translate_errors(int error_code)
 {
Signature · 1 line
2.47.2
Acked-by on v5 6/9
#11 lore raw

Re: [PATCH v5 6/9] usb: core: Introduce usb_endpoint_is_hs_isoc_double()

Quoted 44 lines · Sakari Ailus

Introduce usb_endpoint_is_hs_isoc_double() tell whether an endpoint conforms to USB 2.0 Isochronous Double IN Bandwidth ECN.

---
  drivers/usb/core/usb.c | 19 +++++++++++++++++++
  include/linux/usb.h    |  3 +++
  2 files changed, 22 insertions(+)
drivers/usb/core/usb.c +19 -0
index ca9ff6ad8e73..939dc4aafb89 100644
@@ -1139,6 +1139,25 @@ u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
  }
  EXPORT_SYMBOL_GPL(usb_endpoint_max_periodic_payload);
 
+/**
+ * usb_endpoint_is_hs_isoc_double - Tell whether an endpoint uses USB 2
+ *                                  Isochronous Double IN Bandwidth
+ * @udev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: true if an endpoint @ep conforms to USB 2 Isochronous Double IN
+ * Bandwidth ECN, false otherwise.
+ */
+bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev,
+				    const struct usb_host_endpoint *ep)
+{
+	return ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		le16_to_cpu(udev->descriptor.bcdUSB) == 0x220 &&
+		usb_endpoint_is_isoc_in(&ep->desc) &&
+		!le16_to_cpu(ep->desc.wMaxPacketSize);
+}
+EXPORT_SYMBOL_GPL(usb_endpoint_is_hs_isoc_double);
+
  /*
   * Notifications of device and interface registration
   */
include/linux/usb.h +0 -0
index e9cf2786d8bd..70ef00c42d22 100644

include/linux/usb.h static inline u16 usb_maxpacket(struct usb_device *udev, int pipe) · line 2050

Quoted 9 lines
include/linux/usb.h +3 -0
@@ -2042,6 +2042,9 @@ static inline u16 usb_maxpacket(struct usb_device *udev, int pipe)
  u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
  				      const struct usb_host_endpoint *ep);
 
+bool usb_endpoint_is_hs_isoc_double(struct usb_device *udev,
+				    const struct usb_host_endpoint *ep);
+
  /* translate USB error codes to codes user space understands */
  static inline int usb_translate_errors(int error_code)
  {
#12 lore raw

PATCH v5 7/9 usb: xhci: Add host support for eUSB2 double isochronous bandwidth devices

In reply to Sakari Ailus

From: "Rai, Amardeep" <[email protected]>

Detect eUSB2 double isoc bw capable hosts and devices, and set the proper xhci endpoint context values such as 'Mult', 'Max Burst Size', and 'Max ESIT Payload' to enable the double isochronous bandwidth endpoints.

Intel xHC uses the endpoint context 'Mult' field for eUSB2 isoc endpoints even if hosts supporting Large ESIT Payload Capability should normally ignore the mult field.

---
 drivers/usb/host/xhci-caps.h |  2 ++
 drivers/usb/host/xhci-mem.c  | 53 +++++++++++++++++++++++++++---------
 drivers/usb/host/xhci-ring.c |  6 ++--
 drivers/usb/host/xhci.c      | 16 ++++++++++-
 drivers/usb/host/xhci.h      |  2 ++
 5 files changed, 62 insertions(+), 17 deletions(-)
drivers/usb/host/xhci-caps.h +2 -0
index 4b8ff4815644..89bc83e4f1eb 100644
@@ -89,3 +89,5 @@
 #define HCC2_GSC(p)             ((p) & (1 << 8))
 /* true: HC support Virtualization Based Trusted I/O Capability */
 #define HCC2_VTC(p)             ((p) & (1 << 9))
+/* true: HC support Double BW on a eUSB2 HS ISOC EP */
+#define HCC2_EUSB2_DIC(p)       ((p) & (1 << 11))
drivers/usb/host/xhci-mem.c +40 -13

89 lines not on this page · raw message

drivers/usb/host/xhci-ring.c +3 -3
index ecd757d482c5..ed2fa2c15535 100644
@@ -3545,7 +3545,7 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,
 	if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100))
 		trb_buff_len = 0;
 
-	maxp = usb_endpoint_maxp(&urb->ep->desc);
+	maxp = xhci_usb_endpoint_maxp(urb->dev, urb->ep);
 	total_packet_count = DIV_ROUND_UP(td_total_len, maxp);
 
 	/* Queueing functions don't count the current TRB into transferred */
@@ -3562,7 +3562,7 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len,
 	u32 new_buff_len;
 	size_t len;
 
-	max_pkt = usb_endpoint_maxp(&urb->ep->desc);
+	max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep);
 	unalign = (enqd_len + *trb_buff_len) % max_pkt;
 
 	/* we got lucky, last normal TRB data on segment is packet aligned */
@@ -4133,7 +4133,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
 		addr = start_addr + urb->iso_frame_desc[i].offset;
 		td_len = urb->iso_frame_desc[i].length;
 		td_remain_len = td_len;
-		max_pkt = usb_endpoint_maxp(&urb->ep->desc);
+		max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep);
 		total_pkt_count = DIV_ROUND_UP(td_len, max_pkt);
 
 		/* A zero-length transfer still involves at least one packet. */
drivers/usb/host/xhci.c +15 -1
index 47151ca527bf..e193d4dc414c 100644
@@ -1334,7 +1334,7 @@ static bool xhci_urb_temp_buffer_required(struct usb_hcd *hcd,
 	struct scatterlist *tail_sg;
 
 	tail_sg = urb->sg;
-	max_pkt = usb_endpoint_maxp(&urb->ep->desc);
+	max_pkt = xhci_usb_endpoint_maxp(urb->dev, urb->ep);
 
 	if (!urb->num_sgs)
 		return ret;
@@ -2922,6 +2922,20 @@ int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int
 }
 EXPORT_SYMBOL_GPL(xhci_stop_endpoint_sync);
 
+/*
+ * xhci_usb_endpoint_maxp - get endpoint max packet size
+ * @host_ep: USB host endpoint to be checked
+ *
+ * Returns max packet from the correct descriptor
+ */
+int xhci_usb_endpoint_maxp(struct usb_device *udev,
+			   struct usb_host_endpoint *host_ep)
+{
+	if (usb_endpoint_is_hs_isoc_double(udev, host_ep))
+		return le16_to_cpu(host_ep->eusb2_isoc_ep_comp.wMaxPacketSize);
+	return usb_endpoint_maxp(&host_ep->desc);
+}
+
 /* Issue a configure endpoint command or evaluate context command
  * and wait for it to finish.
  */
drivers/usb/host/xhci.h +2 -0
index a20f4e7cd43a..2721f700c022 100644
@@ -1957,6 +1957,8 @@ void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
 			      struct xhci_interrupter *ir,
 			      bool clear_ehb);
 void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num);
+int xhci_usb_endpoint_maxp(struct usb_device *udev,
+			   struct usb_host_endpoint *host_ep);
 
 /* xHCI roothub code */
 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
Signature · 1 line
2.47.2
#13 lore raw

PATCH v5 8/9 usb: core: support eUSB2 double bandwidth large isoc URB frames

In reply to Sakari Ailus

From: "Rai, Amardeep" <[email protected]>

eUSB2 double isochronous in bandwidth devices support up to 6 transactions per microframe, and thus doubles the total bytes possible to receive per microframe.

Support larger URB isoc frame sizes for eUSB2 double isoc in endpoints.

Also usb_endpoint_maxp() returns a natural number so there's no need to assume it could be < 0.

---
 drivers/usb/core/urb.c | 14 ++++++++++----
 drivers/usb/core/usb.c |  2 ++
 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/usb/core/urb.c +10 -4
index 7a76d5a62db1..ff8df16cca35 100644
@@ -372,6 +372,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 	struct usb_host_endpoint	*ep;
 	int				is_out;
 	unsigned int			allowed;
+	bool				is_eusb2_isoch_double;
 
 	if (!urb || !urb->complete)
 		return -EINVAL;
@@ -434,7 +435,8 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 		return -ENODEV;
 
 	max = usb_endpoint_maxp(&ep->desc);
-	if (max <= 0) {
+	is_eusb2_isoch_double = usb_endpoint_is_hs_isoc_double(dev, ep);
+	if (!max && !is_eusb2_isoch_double) {
 		dev_dbg(&dev->dev,
 			"bogus endpoint ep%d%s in %s (bad maxpacket %d)\n",
 			usb_endpoint_num(&ep->desc), is_out ? "out" : "in",
@@ -467,9 +469,13 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
 			max = le32_to_cpu(isoc_ep_comp->dwBytesPerInterval);
 		}
 
-		/* "high bandwidth" mode, 1-3 packets/uframe? */
-		if (dev->speed == USB_SPEED_HIGH)
-			max *= usb_endpoint_maxp_mult(&ep->desc);
+		/* High speed, 1-3 packets/uframe, max 6 for eUSB2 double bw */
+		if (dev->speed == USB_SPEED_HIGH) {
+			if (is_eusb2_isoch_double)
+				max = le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+			else
+				max *= usb_endpoint_maxp_mult(&ep->desc);
+		}
 
 		if (urb->number_of_packets <= 0)
 			return -EINVAL;
drivers/usb/core/usb.c +2 -0
index 939dc4aafb89..b88b6271cb30 100644
@@ -1134,6 +1134,8 @@ u32 usb_endpoint_max_periodic_payload(struct usb_device *udev,
 	case USB_SPEED_SUPER:
 		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
 	default:
+		if (usb_endpoint_is_hs_isoc_double(udev, ep))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
 		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
 	}
 }
Signature · 1 line
2.47.2
#14 lore raw

PATCH v5 9/9 media: uvcvideo: eUSB2 double isochronous bandwidth support

In reply to Sakari Ailus

From: Tao Q Tao <[email protected]>

Use usb_endpoint_max_esit_payload() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Companion support where larger payloads within a service interval are possible.

---
 drivers/media/usb/uvc/uvc_driver.c |  4 ++--
 drivers/media/usb/uvc/uvc_video.c  | 24 +++---------------------
 drivers/media/usb/uvc/uvcvideo.h   |  4 +---
 3 files changed, 6 insertions(+), 26 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +2 -2
index 775bede0d93d..d06ca79ae2d9 100644
@@ -539,7 +539,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 	unsigned int nformats = 0, nframes = 0, nintervals = 0;
 	unsigned int size, i, n, p;
 	u32 *interval;
-	u16 psize;
+	u32 psize;
 	int ret = -EINVAL;
 
 	if (intf->cur_altsetting->desc.bInterfaceSubClass
@@ -775,7 +775,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
 				streaming->header.bEndpointAddress);
 		if (ep == NULL)
 			continue;
-		psize = uvc_endpoint_max_bpi(dev->udev, ep);
+		psize = usb_endpoint_max_periodic_payload(dev->udev, ep);
 		if (psize > streaming->maxpsize)
 			streaming->maxpsize = psize;
 	}
drivers/media/usb/uvc/uvc_video.c +3 -21
index a5013a7fbca4..1a0cc937de9b 100644
@@ -1869,24 +1869,6 @@ static void uvc_video_stop_transfer(struct uvc_streaming *stream,
 		uvc_free_urb_buffers(stream);
 }
 
-/*
- * Compute the maximum number of bytes per interval for an endpoint.
- */
-u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep)
-{
-	u16 psize;
-
-	switch (dev->speed) {
-	case USB_SPEED_SUPER:
-	case USB_SPEED_SUPER_PLUS:
-		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
-	default:
-		psize = usb_endpoint_maxp(&ep->desc);
-		psize *= usb_endpoint_maxp_mult(&ep->desc);
-		return psize;
-	}
-}
-
 /*
  * Initialize isochronous URBs and allocate transfer buffers. The packet size
  * is given by the endpoint.
@@ -1897,10 +1879,10 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
 	struct urb *urb;
 	struct uvc_urb *uvc_urb;
 	unsigned int npackets, i;
-	u16 psize;
+	u32 psize;
 	u32 size;
 
-	psize = uvc_endpoint_max_bpi(stream->dev->udev, ep);
+	psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep);
 	size = stream->ctrl.dwMaxVideoFrameSize;
 
 	npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
@@ -2043,7 +2025,7 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream,
 				continue;
 
 			/* Check if the bandwidth is high enough. */
-			psize = uvc_endpoint_max_bpi(stream->dev->udev, ep);
+			psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep);
 			if (psize >= bandwidth && psize < best_psize) {
 				altsetting = alts->desc.bAlternateSetting;
 				best_psize = psize;
drivers/media/usb/uvc/uvcvideo.h +1 -3
index 757254fc4fe9..ac19ca721f29 100644
@@ -456,7 +456,7 @@ struct uvc_streaming {
 
 	struct usb_interface *intf;
 	int intfnum;
-	u16 maxpsize;
+	u32 maxpsize;
 
 	struct uvc_streaming_header header;
 	enum v4l2_buf_type type;
@@ -798,8 +798,6 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle);
 /* Utility functions */
 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
 					    u8 epaddr);
-u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep);
-
 /* Quirks support */
 void uvc_video_decode_isight(struct uvc_urb *uvc_urb,
 			     struct uvc_buffer *buf,
Signature · 1 line
2.47.2
Reviewed-by on v5 9/9
#15 lore raw

Re: [PATCH v5 9/9] media: uvcvideo: eUSB2 double isochronous bandwidth support

Hi Sakari

I believe you have missed my previous email.

https://lore.kernel.org/linux-media/CANiDSCsocBBQRPRFAbAovkzauThgN8Qd1u8kjJ_af-83Nd4wvw@mail.gmail.com/

re-posting here

Quoted 9 lines · Sakari Ailus

From: Tao Q Tao <[email protected]>

Use usb_endpoint_max_esit_payload() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Companion support where larger payloads within a service interval are possible.

Quoted 7 lines

nit: I believe the last tag should be: Signed-off-by:

Quoted 105 lines
---
 drivers/media/usb/uvc/uvc_driver.c |  4 ++--
 drivers/media/usb/uvc/uvc_video.c  | 24 +++---------------------
 drivers/media/usb/uvc/uvcvideo.h   |  4 +---
 3 files changed, 6 insertions(+), 26 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +2 -2
index 775bede0d93d..d06ca79ae2d9 100644
@@ -539,7 +539,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
        unsigned int nformats = 0, nframes = 0, nintervals = 0;
        unsigned int size, i, n, p;
        u32 *interval;
-       u16 psize;
+       u32 psize;
        int ret = -EINVAL;
 
        if (intf->cur_altsetting->desc.bInterfaceSubClass
@@ -775,7 +775,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
                                streaming->header.bEndpointAddress);
                if (ep == NULL)
                        continue;
-               psize = uvc_endpoint_max_bpi(dev->udev, ep);
+               psize = usb_endpoint_max_periodic_payload(dev->udev, ep);
                if (psize > streaming->maxpsize)
                        streaming->maxpsize = psize;
        }
drivers/media/usb/uvc/uvc_video.c +3 -21
index a5013a7fbca4..1a0cc937de9b 100644
@@ -1869,24 +1869,6 @@ static void uvc_video_stop_transfer(struct uvc_streaming *stream,
                uvc_free_urb_buffers(stream);
 }
 
-/*
- * Compute the maximum number of bytes per interval for an endpoint.
- */
-u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep)
-{
-       u16 psize;
-
-       switch (dev->speed) {
-       case USB_SPEED_SUPER:
-       case USB_SPEED_SUPER_PLUS:
-               return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
-       default:
-               psize = usb_endpoint_maxp(&ep->desc);
-               psize *= usb_endpoint_maxp_mult(&ep->desc);
-               return psize;
-       }
-}
-
 /*
  * Initialize isochronous URBs and allocate transfer buffers. The packet size
  * is given by the endpoint.
@@ -1897,10 +1879,10 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
        struct urb *urb;
        struct uvc_urb *uvc_urb;
        unsigned int npackets, i;
-       u16 psize;
+       u32 psize;
        u32 size;
 
-       psize = uvc_endpoint_max_bpi(stream->dev->udev, ep);
+       psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep);
        size = stream->ctrl.dwMaxVideoFrameSize;
 
        npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
@@ -2043,7 +2025,7 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream,
                                continue;
 
                        /* Check if the bandwidth is high enough. */
-                       psize = uvc_endpoint_max_bpi(stream->dev->udev, ep);
+                       psize = usb_endpoint_max_periodic_payload(stream->dev->udev, ep);
                        if (psize >= bandwidth && psize < best_psize) {
                                altsetting = alts->desc.bAlternateSetting;
                                best_psize = psize;
drivers/media/usb/uvc/uvcvideo.h +1 -4
index 757254fc4fe9..ac19ca721f29 100644
@@ -456,7 +456,7 @@ struct uvc_streaming {
 
        struct usb_interface *intf;
        int intfnum;
-       u16 maxpsize;
+       u32 maxpsize;
 
        struct uvc_streaming_header header;
        enum v4l2_buf_type type;
@@ -798,8 +798,6 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle);
 /* Utility functions */
 struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
                                            u8 epaddr);
-u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep);
-
 /* Quirks support */
 void uvc_video_decode_isight(struct uvc_urb *uvc_urb,
                             struct uvc_buffer *buf,
--

2.47.2

Signature · 1 line
Ricardo Ribalda
#16 lore raw

Re: [PATCH v5 9/9] media: uvcvideo: eUSB2 double isochronous bandwidth support

Hi Ricardo,

Quoted 12 lines · Ricardo Ribalda

Hi Sakari

I believe you have missed my previous email.

https://lore.kernel.org/linux-media/CANiDSCsocBBQRPRFAbAovkzauThgN8Qd1u8kjJ_af-83Nd4wvw@mail.gmail.com/

re-posting here

Quoted 3 lines · Sakari Ailus

From: Tao Q Tao <[email protected]>

Quoted 8 lines
Quoted 6 lines

Use usb_endpoint_max_esit_payload() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Companion support where larger payloads within a service interval are possible.

Thank you.

Quoted 11 lines
Quoted 7 lines

nit: I believe the last tag should be: Signed-off-by:

Laurent has reviewed the patch, please see <[email protected]>.

Signature · 3 lines
Regards,

Sakari Ailus
Acked-by on the v5 series
#17 lore raw
In reply to Sakari Ailus
Quoted 12 lines · Sakari Ailus

Hi all,

This series enables support for eUSB2 Double Isochronous IN Bandwidth UVC devices specified in 'USB 2.0 Double Isochronous IN Bandwidth' ECN. In short, it adds support for new integrated USB2 webcams that can send twice the data compared to conventional USB2 webcams.

These devices are identified by the device descriptor bcdUSB 0x0220 value. They have an additional eUSB2 Isochronous Endpoint Companion Descriptor, and a zero max packet size in regular isoc endpoint descriptor. Support for parsing that new descriptor was added in commit

Quoted 8 lines

c749f058b437 ("USB: core: Add eUSB2 descriptor and parsing in USB core")

This series adds support to UVC, USB core, and xHCI to identify eUSB2 double isoc devices, and allow and set proper max packet, iso frame desc sizes, bytes per interval, and other values in URBs and xHCI endpoint contexts needed to support the double data rates for eUSB2 double isoc devices.

The v5 of this series looks good to me, and could from my perspective be picked directly to usb-next

Thanks
Mathias