diff options
| author | Rai, Amardeep <amardeep.rai@intel.com> | 2025-08-20 17:38:22 +0300 | 
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-09-06 16:25:05 +0300 | 
| commit | 0c670dc882d31f0423f18899c0e594547b55b76d (patch) | |
| tree | 9fcd59edb4a607bbe3100b7c240853fbff55395c | |
| parent | d6725169a9bbcb5bd1dd14b2891b874614c59f52 (diff) | |
| download | linux-0c670dc882d31f0423f18899c0e594547b55b76d.tar.xz | |
usb: xhci: Add host support for eUSB2 double isochronous bandwidth devices
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.
Signed-off-by: Rai, Amardeep <amardeep.rai@intel.com>
Co-developed-by: Kannappan R <r.kannappan@intel.com>
Signed-off-by: Kannappan R <r.kannappan@intel.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Co-developed-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Co-developed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250820143824.551777-8-sakari.ailus@linux.intel.com
| -rw-r--r-- | drivers/usb/host/xhci-caps.h | 2 | ||||
| -rw-r--r-- | drivers/usb/host/xhci-mem.c | 53 | ||||
| -rw-r--r-- | drivers/usb/host/xhci-ring.c | 6 | ||||
| -rw-r--r-- | drivers/usb/host/xhci.c | 16 | ||||
| -rw-r--r-- | drivers/usb/host/xhci.h | 2 | 
5 files changed, 62 insertions, 17 deletions
diff --git a/drivers/usb/host/xhci-caps.h b/drivers/usb/host/xhci-caps.h index 4b8ff4815644..89bc83e4f1eb 100644 --- a/drivers/usb/host/xhci-caps.h +++ b/drivers/usb/host/xhci-caps.h @@ -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)) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d2c04811191f..78ddcc6761ac 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1330,18 +1330,33 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,  	return interval;  } -/* The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps. +/* + * xHCs without LEC use the "Mult" field in the endpoint context for SuperSpeed + * isoc eps, and High speed isoc eps that support bandwidth doubling. Standard   * High speed endpoint descriptors can define "the number of additional   * transaction opportunities per microframe", but that goes in the Max Burst   * endpoint context field.   */ -static u32 xhci_get_endpoint_mult(struct usb_device *udev, -		struct usb_host_endpoint *ep) +static u32 xhci_get_endpoint_mult(struct xhci_hcd *xhci, +				  struct usb_device *udev, +				  struct usb_host_endpoint *ep)  { -	if (udev->speed < USB_SPEED_SUPER || -			!usb_endpoint_xfer_isoc(&ep->desc)) -		return 0; -	return ep->ss_ep_comp.bmAttributes; +	bool lec; + +	/* xHCI 1.1 with LEC set does not use mult field, except intel eUSB2 */ +	lec = xhci->hci_version > 0x100 && HCC2_LEC(xhci->hcc_params2); + +	/* eUSB2 double isoc bw devices are the only USB2 devices using mult */ +	if (usb_endpoint_is_hs_isoc_double(udev, ep) && +	    (!lec || xhci->quirks & XHCI_INTEL_HOST)) +		return 1; + +	/* SuperSpeed isoc transfers on hosts without LEC uses mult field */ +	if (udev->speed >= USB_SPEED_SUPER && +	    usb_endpoint_xfer_isoc(&ep->desc) && !lec) +		return ep->ss_ep_comp.bmAttributes; + +	return 0;  }  static u32 xhci_get_endpoint_max_burst(struct usb_device *udev, @@ -1353,8 +1368,16 @@ static u32 xhci_get_endpoint_max_burst(struct usb_device *udev,  	if (udev->speed == USB_SPEED_HIGH &&  	    (usb_endpoint_xfer_isoc(&ep->desc) || -	     usb_endpoint_xfer_int(&ep->desc))) +	     usb_endpoint_xfer_int(&ep->desc))) { +		/* +		 * USB 2 Isochronous Double IN Bandwidth ECN uses fixed burst +		 * size and max packets bits 12:11 are invalid. +		 */ +		if (usb_endpoint_is_hs_isoc_double(udev, ep)) +			return 2; +  		return usb_endpoint_maxp_mult(&ep->desc) - 1; +	}  	return 0;  } @@ -1409,6 +1432,13 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,  	ring_type = usb_endpoint_type(&ep->desc); +	/* Ensure host supports double isoc bandwidth for eUSB2 devices */ +	if (usb_endpoint_is_hs_isoc_double(udev, ep) && +	    !HCC2_EUSB2_DIC(xhci->hcc_params2))	{ +		dev_dbg(&udev->dev, "Double Isoc Bandwidth not supported by xhci\n"); +		return -EINVAL; +	} +  	/*  	 * Get values to fill the endpoint context, mostly from ep descriptor.  	 * The average TRB buffer lengt for bulk endpoints is unclear as we @@ -1432,8 +1462,8 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,  		}  	} -	mult = xhci_get_endpoint_mult(udev, ep); -	max_packet = usb_endpoint_maxp(&ep->desc); +	mult = xhci_get_endpoint_mult(xhci, udev, ep); +	max_packet = xhci_usb_endpoint_maxp(udev, ep);  	max_burst = xhci_get_endpoint_max_burst(udev, ep);  	avg_trb_len = max_esit_payload; @@ -1454,9 +1484,6 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,  	/* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */  	if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100)  		avg_trb_len = 8; -	/* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */ -	if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) -		mult = 0;  	/* Set up the endpoint ring */  	virt_dev->eps[ep_index].new_ring = diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index ecd757d482c5..ed2fa2c15535 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -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. */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 47151ca527bf..e193d4dc414c 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -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 @@ out:  }  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.   */ diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index a20f4e7cd43a..2721f700c022 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -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,  | 
