Skip to contentSkip to conversation

eUSB2 Double Isochronous IN Bandwidth support

PATCH Superseded Sakari Ailus 5 participants 14 messages Aug 7, 2025 – Aug 12, 2025

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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]/>.

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):
xhci: Add host support for eUSB2 double isochronous bandwidth devices
USB: core: support eUSB2 double bandwidth large isoc URB frames
USB: Add a function to obtain USB version independent maximum bpi
value

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/urb.c             | 17 +++++++--
 drivers/usb/host/xhci-caps.h       |  2 +
 drivers/usb/host/xhci-mem.c        | 60 ++++++++++++++++++++++++------
 drivers/usb/host/xhci-ring.c       |  6 +--
 drivers/usb/host/xhci.c            | 16 +++++++-
 drivers/usb/host/xhci.h            | 19 ++++++++++
 include/linux/usb.h                | 31 +++++++++++++++
 10 files changed, 137 insertions(+), 46 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v3 1/4 xhci: Add host support for eUSB2 double isochronous bandwidth devices

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  | 60 ++++++++++++++++++++++++++++--------
 drivers/usb/host/xhci-ring.c |  6 ++--
 drivers/usb/host/xhci.c      | 16 +++++++++-
 drivers/usb/host/xhci.h      | 19 ++++++++++++
 5 files changed, 87 insertions(+), 16 deletions(-)
drivers/usb/host/xhci-caps.h +2 -0
index 4b8ff4815644..723a56052439 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 +48 -12

103 lines not on this page · raw message

drivers/usb/host/xhci-ring.c +3 -3
index 94c9c9271658..9abc5bc4e1c0 100644
@@ -3542,7 +3542,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 */
@@ -3559,7 +3559,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 */
@@ -4130,7 +4130,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 8a819e853288..1ea7d2fb5876 100644
@@ -1332,7 +1332,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;
@@ -2920,6 +2920,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 (xhci_eusb2_is_isoc_bw_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 +19 -0
index a20f4e7cd43a..9657a4deb87b 100644
@@ -1736,6 +1736,23 @@ static inline bool xhci_has_one_roothub(struct xhci_hcd *xhci)
 	       (!xhci->usb2_rhub.num_ports || !xhci->usb3_rhub.num_ports);
 }
 
+/*
+ * USB 2.0 specification, chapter 5.6.4 Isochronous Transfer Bus Access
+ * Constraint. A high speed endpoint can move up to 3072 bytes per microframe
+ * (or 192Mb/s).
+ */
+#define MAX_ISOC_XFER_SIZE_HS  3072
+
+static inline bool xhci_eusb2_is_isoc_bw_double(struct usb_device *udev,
+						struct usb_host_endpoint *ep)
+{
+	return udev->speed == USB_SPEED_HIGH &&
+		usb_endpoint_is_isoc_in(&ep->desc) &&
+		le16_to_cpu(ep->desc.wMaxPacketSize) == 0 &&
+		le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval) >
+		MAX_ISOC_XFER_SIZE_HS;
+}
+
 #define xhci_dbg(xhci, fmt, args...) \
 	dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
 #define xhci_err(xhci, fmt, args...) \
@@ -1957,6 +1974,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.39.5
maintainer
#2 lore raw

Re: [PATCH v3 1/4] xhci: Add host support for eUSB2 double isochronous bandwidth devices

Quoted 31 lines · 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  | 60 ++++++++++++++++++++++++++++--------
 drivers/usb/host/xhci-ring.c |  6 ++--
 drivers/usb/host/xhci.c      | 16 +++++++++-
 drivers/usb/host/xhci.h      | 19 ++++++++++++
 5 files changed, 87 insertions(+), 16 deletions(-)
drivers/usb/host/xhci-caps.h +0 -0
index 4b8ff4815644..723a56052439 100644

drivers/usb/host/xhci-caps.h line 93

Quoted 5 lines
drivers/usb/host/xhci-caps.h +2 -0
@@ -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))

Why tabs when the ones above it were not using tabs?

#3 lore raw

Re: [PATCH v3 1/4] xhci: Add host support for eUSB2 double isochronous bandwidth devices

Hi Greg,

Quoted 27 lines · Greg KH
Quoted 26 lines · 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  | 60 ++++++++++++++++++++++++++++--------
 drivers/usb/host/xhci-ring.c |  6 ++--
 drivers/usb/host/xhci.c      | 16 +++++++++-
 drivers/usb/host/xhci.h      | 19 ++++++++++++
 5 files changed, 87 insertions(+), 16 deletions(-)
Quoted 12 lines

drivers/usb/host/xhci-caps.h line 93

Quoted 10 lines
drivers/usb/host/xhci-caps.h +2 -0
index 4b8ff4815644..723a56052439 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))

Why tabs when the ones above it were not using tabs?

I'll use spaces for v4 so the macro bodies are aligned.

These macros should be cleaned up but that's for another set I think.

Signature · 3 lines
Regards,

Sakari Ailus
#4 lore raw

PATCH v3 2/4 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 | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/usb/core/urb.c +13 -4
index 7a76d5a62db1..6f8f3d751854 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,11 @@ 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 = dev->speed == USB_SPEED_HIGH &&
+				usb_endpoint_is_isoc_in(&ep->desc) &&
+				ep->eusb2_isoc_ep_comp.bDescriptorType &&
+				le16_to_cpu(ep->desc.wMaxPacketSize) == 0;
+	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 +472,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;
Signature · 1 line
2.39.5
Acked-by on v3 2/4
#5 lore raw

Re: [PATCH v3 2/4] USB: core: support eUSB2 double bandwidth large isoc URB frames

Quoted 11 lines · 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.

Quoted 6 lines

---

Quoted 48 lines
 drivers/usb/core/urb.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/usb/core/urb.c +13 -4
index 7a76d5a62db1..6f8f3d751854 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,11 @@ 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 = dev->speed == USB_SPEED_HIGH &&
+				usb_endpoint_is_isoc_in(&ep->desc) &&
+				ep->eusb2_isoc_ep_comp.bDescriptorType &&
+				le16_to_cpu(ep->desc.wMaxPacketSize) == 0;
+	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 +472,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;
Signature · 1 line
2.39.5
#6 lore raw

PATCH v3 3/4 USB: Add a function to obtain USB version independent maximum bpi value

In reply to Sakari Ailus

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

Add usb_endpoint_max_isoc_bpi() to obtain maximum bytes per interval for isochronous endpoints in a USB version independent way.

---
 include/linux/usb.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
include/linux/usb.h +31 -0
index 535ac37198a1..da0f51dfe15f 100644
@@ -2049,6 +2049,37 @@ static inline int usb_translate_errors(int error_code)
 	}
 }
 
+/**
+ * usb_endpoint_max_isoc_bpi - Get maximum isochronous transfer bytes per interval
+ * @dev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous endpoint @endpoint can
+ * transfer in during a service interval, or 0 for non-isochronous endpoints.
+ */
+static inline u32 usb_endpoint_max_isoc_bpi(struct usb_device *dev,
+					    const struct usb_host_endpoint *ep)
+{
+	if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_ISOC)
+		return 0;
+
+	switch (dev->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);
+	case USB_SPEED_HIGH:
+		if (ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		    !usb_endpoint_maxp(&ep->desc) && usb_endpoint_dir_in(&ep->desc))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}
+
 /* Events from the usb core */
 #define USB_DEVICE_ADD		0x0001
 #define USB_DEVICE_REMOVE	0x0002
Signature · 1 line
2.39.5
#7 lore raw

Re: [PATCH v3 3/4] USB: Add a function to obtain USB version independent maximum bpi value

Quoted 4 lines · Sakari Ailus

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

Add usb_endpoint_max_isoc_bpi() to obtain maximum bytes per interval for isochronous endpoints in a USB version independent way.

Is "bpi" really a commonly recognized acronym? Offhand, I wouldn't guess that it stands for "bytes per interval". Can you come up with a more explicit name?

Quoted 37 lines
---
 include/linux/usb.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
include/linux/usb.h +20 -0
index 535ac37198a1..da0f51dfe15f 100644
@@ -2049,6 +2049,37 @@ static inline int usb_translate_errors(int error_code)
 	}
 }
 
+/**
+ * usb_endpoint_max_isoc_bpi - Get maximum isochronous transfer bytes per interval
+ * @dev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous endpoint @endpoint can
+ * transfer in during a service interval, or 0 for non-isochronous endpoints.
+ */
+static inline u32 usb_endpoint_max_isoc_bpi(struct usb_device *dev,
+					    const struct usb_host_endpoint *ep)
+{
+	if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_ISOC)
+		return 0;
+
+	switch (dev->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:

include/linux/usb.h static inline int usb_translate_errors(int error_code) · line 2081

Quoted 10 lines
include/linux/usb.h +10 -0
+		return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
+	case USB_SPEED_HIGH:
+		if (ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		    !usb_endpoint_maxp(&ep->desc) && usb_endpoint_dir_in(&ep->desc))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}

This function is complicated enough that it probably should not be an inline routine. Not unless it's used in only one place (in which case why define it in a .h file?).

Alan Stern

#8 lore raw

Re: [PATCH v3 3/4] USB: Add a function to obtain USB version independent maximum bpi value

Hi Alan,

Thanks for the review.

Quoted 9 lines · Alan Stern
Quoted 4 lines · Sakari Ailus

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

Add usb_endpoint_max_isoc_bpi() to obtain maximum bytes per interval for isochronous endpoints in a USB version independent way.

Is "bpi" really a commonly recognized acronym? Offhand, I wouldn't guess that it stands for "bytes per interval". Can you come up with a more explicit name?

There's not a single canonical name for this as the information is derived from different sources depending on the USB version. But yes, that's the abbreviation. I used it because "bytes_per_interval" would be quite long. "bpi" has also been used by the UVC driver (see the 4th patch).

Quoted 44 lines
Quoted 44 lines
---
 include/linux/usb.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
include/linux/usb.h +26 -0
index 535ac37198a1..da0f51dfe15f 100644
@@ -2049,6 +2049,37 @@ static inline int usb_translate_errors(int error_code)
 	}
 }
 
+/**
+ * usb_endpoint_max_isoc_bpi - Get maximum isochronous transfer bytes per interval
+ * @dev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous endpoint @endpoint can
+ * transfer in during a service interval, or 0 for non-isochronous endpoints.
+ */
+static inline u32 usb_endpoint_max_isoc_bpi(struct usb_device *dev,
+					    const struct usb_host_endpoint *ep)
+{
+	if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_ISOC)
+		return 0;
+
+	switch (dev->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);
+	case USB_SPEED_HIGH:
+		if (ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		    !usb_endpoint_maxp(&ep->desc) && usb_endpoint_dir_in(&ep->desc))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
Quoted 8 lines

include/linux/usb.h static inline int usb_translate_errors(int error_code) · line 2081

Quoted 4 lines
include/linux/usb.h +4 -0
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}

This function is complicated enough that it probably should not be an inline routine. Not unless it's used in only one place (in which case why define it in a .h file?).

The single user currently (and probably will be for some time at least) is the UVC driver but this code is better located in the USB tree. I'd keep it this way until we have more users, unless Mathias can suggest where the function should be located.

Signature · 3 lines
Kind regards,

Sakari Ailus
#9 lore raw

Re: [PATCH v3 3/4] USB: Add a function to obtain USB version independent maximum bpi value

Quoted 36 lines · Sakari Ailus
Quoted 27 lines
Quoted 27 lines
include/linux/usb.h +26 -0
+/**
+ * usb_endpoint_max_isoc_bpi - Get maximum isochronous transfer bytes per interval
+ * @dev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous endpoint @endpoint can
+ * transfer in during a service interval, or 0 for non-isochronous endpoints.
+ */
+static inline u32 usb_endpoint_max_isoc_bpi(struct usb_device *dev,
+					    const struct usb_host_endpoint *ep)
+{
+	if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_ISOC)
+		return 0;
+
+	switch (dev->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);
+	case USB_SPEED_HIGH:
+		if (ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		    !usb_endpoint_maxp(&ep->desc) && usb_endpoint_dir_in(&ep->desc))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
Quoted 8 lines

include/linux/usb.h static inline int usb_translate_errors(int error_code) · line 2081

Quoted 4 lines
include/linux/usb.h +4 -0
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}

This function is complicated enough that it probably should not be an inline routine. Not unless it's used in only one place (in which case why define it in a .h file?).

Quoted 4 lines

The single user currently (and probably will be for some time at least) is the UVC driver but this code is better located in the USB tree. I'd keep it this way until we have more users, unless Mathias can suggest where the function should be located.

Okay. But in the meantime, how about putting just a declaration for this function in include/linux/usb.h and putting the actual (non-inline) definition in drivers/usb/core/usb.c, or in drivers/usb/common/common.c if you think the function would be used in gadget-side drivers as well as host-side drivers?

Alan Stern

#10 lore raw

Re: [PATCH v3 3/4] USB: Add a function to obtain USB version independent maximum bpi value

Hi Alan,

Quoted 42 lines · Alan Stern
Quoted 36 lines · Sakari Ailus
Quoted 27 lines
Quoted 27 lines
include/linux/usb.h +26 -0
+/**
+ * usb_endpoint_max_isoc_bpi - Get maximum isochronous transfer bytes per interval
+ * @dev: The USB device
+ * @ep: The endpoint
+ *
+ * Returns: the maximum number of bytes isochronous endpoint @endpoint can
+ * transfer in during a service interval, or 0 for non-isochronous endpoints.
+ */
+static inline u32 usb_endpoint_max_isoc_bpi(struct usb_device *dev,
+					    const struct usb_host_endpoint *ep)
+{
+	if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_ISOC)
+		return 0;
+
+	switch (dev->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);
+	case USB_SPEED_HIGH:
+		if (ep->eusb2_isoc_ep_comp.bDescriptorType &&
+		    !usb_endpoint_maxp(&ep->desc) && usb_endpoint_dir_in(&ep->desc))
+			return le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval);
+		fallthrough;
Quoted 8 lines

include/linux/usb.h static inline int usb_translate_errors(int error_code) · line 2081

Quoted 4 lines
include/linux/usb.h +4 -0
+	default:
+		return usb_endpoint_maxp(&ep->desc) * usb_endpoint_maxp_mult(&ep->desc);
+	}
+}

This function is complicated enough that it probably should not be an inline routine. Not unless it's used in only one place (in which case why define it in a .h file?).

Quoted 4 lines

The single user currently (and probably will be for some time at least) is the UVC driver but this code is better located in the USB tree. I'd keep it this way until we have more users, unless Mathias can suggest where the function should be located.

Quoted 5 lines

Okay. But in the meantime, how about putting just a declaration for this function in include/linux/usb.h and putting the actual (non-inline) definition in drivers/usb/core/usb.c, or in drivers/usb/common/common.c if you think the function would be used in gadget-side drivers as well as host-side drivers?

I'll move it to usb.c in v4.

Signature · 3 lines
Regards,

Sakari Ailus
#11 lore raw

PATCH v3 4/4 media: uvcvideo: eUSB2 double isochronous bandwidth support

In reply to Sakari Ailus

From: Tao Q Tao <[email protected]>

Use usb_endpoint_max_isoc_bpi() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Compaion support where larger bpi values 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 da24a655ab68..fde0bc95622c 100644
@@ -536,7 +536,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
@@ -772,7 +772,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_isoc_bpi(dev->udev, ep);
 		if (psize > streaming->maxpsize)
 			streaming->maxpsize = psize;
 	}
drivers/media/usb/uvc/uvc_video.c +3 -21
index a75af314e46b..335b1c4eff9b 100644
@@ -1860,24 +1860,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.
@@ -1888,10 +1870,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_isoc_bpi(stream->dev->udev, ep);
 	size = stream->ctrl.dwMaxVideoFrameSize;
 
 	npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
@@ -2034,7 +2016,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_isoc_bpi(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 b9f8eb62ba1d..a77ba76e033a 100644
@@ -450,7 +450,7 @@ struct uvc_streaming {
 
 	struct usb_interface *intf;
 	int intfnum;
-	u16 maxpsize;
+	u32 maxpsize;
 
 	struct uvc_streaming_header header;
 	enum v4l2_buf_type type;
@@ -818,8 +818,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.39.5
Reviewed-by on v3 4/4
#12 lore raw

Re: [PATCH v3 4/4] media: uvcvideo: eUSB2 double isochronous bandwidth support

Quoted 8 lines · Sakari Ailus

From: Tao Q Tao <[email protected]>

Use usb_endpoint_max_isoc_bpi() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Compaion support where larger bpi values are possible.

Quoted 8 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 da24a655ab68..fde0bc95622c 100644
@@ -536,7 +536,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
@@ -772,7 +772,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_isoc_bpi(dev->udev, ep);
                if (psize > streaming->maxpsize)
                        streaming->maxpsize = psize;
        }
drivers/media/usb/uvc/uvc_video.c +3 -21
index a75af314e46b..335b1c4eff9b 100644
@@ -1860,24 +1860,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.
@@ -1888,10 +1870,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_isoc_bpi(stream->dev->udev, ep);
        size = stream->ctrl.dwMaxVideoFrameSize;
 
        npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
@@ -2034,7 +2016,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_isoc_bpi(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 b9f8eb62ba1d..a77ba76e033a 100644
@@ -450,7 +450,7 @@ struct uvc_streaming {
 
        struct usb_interface *intf;
        int intfnum;
-       u16 maxpsize;
+       u32 maxpsize;
 
        struct uvc_streaming_header header;
        enum v4l2_buf_type type;
@@ -818,8 +818,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.39.5

Signature · 1 line
Ricardo Ribalda
maintainer
#13 lore raw

Re: [PATCH v3 4/4] media: uvcvideo: eUSB2 double isochronous bandwidth support

Quoted 20 lines · Ricardo Ribalda
Quoted 7 lines · Sakari Ailus

From: Tao Q Tao <[email protected]>

Use usb_endpoint_max_isoc_bpi() from the USB framework to find the maximum bytes per interval for the endpoint. Consequently this adds eUSB2 isochronous mode and SuperSpeedPlus Isochronous Endpoint Compaion support where larger bpi values are possible.

Quoted 8 lines
Quoted 1 line

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

Related discussion on the workflow mailing list:
https://lore.kernel.org/workflows/[email protected]/T/#t

To answer a question Sakari asked off-list, I'm fine with this patch being merged through the linux-usb tree.

Quoted 101 lines
Quoted 101 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 da24a655ab68..fde0bc95622c 100644
@@ -536,7 +536,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
@@ -772,7 +772,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_isoc_bpi(dev->udev, ep);
                if (psize > streaming->maxpsize)
                        streaming->maxpsize = psize;
        }
drivers/media/usb/uvc/uvc_video.c +3 -21
index a75af314e46b..335b1c4eff9b 100644
@@ -1860,24 +1860,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.
@@ -1888,10 +1870,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_isoc_bpi(stream->dev->udev, ep);
        size = stream->ctrl.dwMaxVideoFrameSize;
 
        npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags);
@@ -2034,7 +2016,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_isoc_bpi(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 b9f8eb62ba1d..a77ba76e033a 100644
@@ -450,7 +450,7 @@ struct uvc_streaming {
 
        struct usb_interface *intf;
        int intfnum;
-       u16 maxpsize;
+       u32 maxpsize;
 
        struct uvc_streaming_header header;
        enum v4l2_buf_type type;
@@ -818,8 +818,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 · 3 lines
Regards,

Laurent Pinchart