Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: Add tunnel_mode parameter to usb device structure

Add 'tunnel_mode' enum to usb device structure to describe if a USB3
link is tunneled over USB4, or connected directly using native USB2/USB3
protocols.

Tunneled devices depend on USB4 NHI host to maintain the tunnel.
Knowledge about tunneled devices is important to ensure correct
suspend and resume order between USB4 hosts and tunneled devices.
i.e. make sure tunnel is up before the USB device using it resumes.

USB hosts such as xHCI may have vendor specific ways to detect tunneled
connections. This 'tunnel_mode' parameter can be set by USB3 host driver
during hcd->driver->update_device(hcd, udev) callback.

tunnel_mode can be set to:
USB_LINK_UNKNOWN = 0
USB_LINK_NATIVE
USB_LINK_TUNNELED

USB_LINK_UNKNOWN is used in case host is not capable of detecting
tunneled links.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20240830152630.3943215-3-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Nyman and committed by
Greg Kroah-Hartman
f46a6e16 948ce83f

+24 -8
+9 -4
drivers/usb/host/xhci-hub.c
··· 763 763 * 764 764 * A USB3 device must be connected to the port to detect the tunnel. 765 765 * 766 - * Return: true if USB3 connection is tunneled over USB4 766 + * Return: link tunnel mode enum, USB_LINK_UNKNOWN if host is incapable of 767 + * detecting USB3 over USB4 tunnels. USB_LINK_NATIVE or USB_LINK_TUNNELED 768 + * otherwise. 767 769 */ 768 - bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port) 770 + enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, 771 + struct xhci_port *port) 769 772 { 770 773 void __iomem *base; 771 774 u32 offset; ··· 780 777 offset = XHCI_INTEL_SPR_ESS_PORT_OFFSET + port->hcd_portnum * 0x20; 781 778 782 779 if (readl(base + offset) & XHCI_INTEL_SPR_TUNEN) 783 - return true; 780 + return USB_LINK_TUNNELED; 781 + else 782 + return USB_LINK_NATIVE; 784 783 } 785 784 786 - return false; 785 + return USB_LINK_UNKNOWN; 787 786 } 788 787 789 788 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
+5 -2
drivers/usb/host/xhci.c
··· 4529 4529 if (hcd->speed >= HCD_USB3 && !udev->parent->parent) { 4530 4530 port = xhci->usb3_rhub.ports[udev->portnum - 1]; 4531 4531 4532 - if (xhci_port_is_tunneled(xhci, port)) 4532 + udev->tunnel_mode = xhci_port_is_tunneled(xhci, port); 4533 + if (udev->tunnel_mode == USB_LINK_UNKNOWN) 4534 + dev_dbg(&udev->dev, "link tunnel state unknown\n"); 4535 + else if (udev->tunnel_mode == USB_LINK_TUNNELED) 4533 4536 dev_dbg(&udev->dev, "tunneled over USB4 link\n"); 4534 - else 4537 + else if (udev->tunnel_mode == USB_LINK_NATIVE) 4535 4538 dev_dbg(&udev->dev, "native USB 3.x link\n"); 4536 4539 return 0; 4537 4540 }
+2 -2
drivers/usb/host/xhci.h
··· 1929 1929 int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); 1930 1930 int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1); 1931 1931 struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd); 1932 - bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port); 1933 - 1932 + enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, 1933 + struct xhci_port *port); 1934 1934 void xhci_hc_died(struct xhci_hcd *xhci); 1935 1935 1936 1936 #ifdef CONFIG_PM
+8
include/linux/usb.h
··· 495 495 496 496 struct usb_tt; 497 497 498 + enum usb_link_tunnel_mode { 499 + USB_LINK_UNKNOWN = 0, 500 + USB_LINK_NATIVE, 501 + USB_LINK_TUNNELED, 502 + }; 503 + 498 504 enum usb_port_connect_type { 499 505 USB_PORT_CONNECT_TYPE_UNKNOWN = 0, 500 506 USB_PORT_CONNECT_TYPE_HOT_PLUG, ··· 611 605 * WUSB devices are not, until we authorize them from user space. 612 606 * FIXME -- complete doc 613 607 * @authenticated: Crypto authentication passed 608 + * @tunnel_mode: Connection native or tunneled over USB4 614 609 * @lpm_capable: device supports LPM 615 610 * @lpm_devinit_allow: Allow USB3 device initiated LPM, exit latency is in range 616 611 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM ··· 721 714 unsigned do_remote_wakeup:1; 722 715 unsigned reset_resume:1; 723 716 unsigned port_is_suspended:1; 717 + enum usb_link_tunnel_mode tunnel_mode; 724 718 725 719 int slot_id; 726 720 struct usb2_lpm_parameters l1_params;