From nobody Mon Nov 23 10:29:55 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794733039; b=C4tXj9AcmfCpOYx/BRYbtVBWdggMgsvn/lgOE3OQytg+yL/QccEyDnpt7wKOrsbLkbPk Gk4cRdV4a2YUMV6J2Mtf8fFqjjLBHFUwfOlTckuBffjcuMzAWmxQTeczwqCGzEX7fMf9Y OxaROFDhieuaImVIhRUpMJixSOeeaCL6yQ0jIS7s9pRV6H1vY1TgmMYBLNZ8ZVkgbQ46f e4QBiq5UbEK90Z1mN+ZJXI/6njSi2cdC9tK7sbE4RhJUFq1LSLLMAjz1ExgYkdm3auaqJ we97awjNl4IoMAAMFU0cKQ/+KT2aCAJiMw1LxKnTtv6EyuQOYCem66nAZnbsgIjFe6Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733039; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=vf4xcpWzTEDi7Kl+k/wVBVZLSyYTkfmAof1kH53cuD4=; b=vGTpJHB8wgygG2TUJwu8xYgkl7Y5ij7xB9QkGLQuubcqheT4qbNVdfHb5Ea2gPlkjwWt 0j4KQwGAM1XKD4+9I5NHsakeg8OZJ6GQScjpg6KOlAOwJOSHDvp3SOv5tNWzcJQ7DZnqn Zfh4iPsmoBhAGtHXnnC/alzpOGiDi8ybS14Cw820DN6VwUBAo9vrJpbW+JH0Nwthbr5qc Qhvdu0JSD2WS0P1EAWTgKjxLGbF1DxkrgsRrjBYXOBuqJ5mSPYVDXCzRqxRXhOQbBN2VK 8KPPVCz6zW/q2dm9PFAcoKVGYz9BM4CZE8i6jID+01FXJOabRXd1JlxVZgT/DfDzzJQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X9QRjZqf; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4185606A31A; Sun, 15 Nov 2026 08:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X9QRjZqf Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1794733039; b=nt++MabnP8O66frM8HnTq62Anxt+HiRNkA/NxFDL5yVfIemk4XeDxTccMHeA78wyc7F4 wSyFDiiWAzyNSHhcJ+CvPqTaj1mGfmyhgJaljBxVZw6d6QGBhEd1r37M5wK6bjcgpgBAK WFn+Gc1tImLgb/9ErUObK9z5mlxjnMO86NThT0vdyJEVRzPvXLnaIaEn3qe7LXMsuSH51 SDDZHZUy5Y/rjOtOIfSRFdZFYJU62dF0N8D8AtSGPWcEhvOyWZXqYGm5J6XwyQHnvduIC kmoM3AEorYrM0VxllgyW0xgXso57KjBXLW47TOFfqokCsVfR2vFExfVfkq+jVuRO5KA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1794733039; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=vf4xcpWzTEDi7Kl+k/wVBVZLSyYTkfmAof1kH53cuD4=; b=Y1vHsMM0s9aFBcLhwg8kS6toODIfI3V+Qnso4CCMcMysmBNO/rNlvIujpsp7GCBYr98E 6r/qdFXfRzFVTuUYqBafrgbH+F+ElG5fens1sOfxBu4+Y+kJ8l0lYTa4ZoJdBv3N5qIJ/ yS5XzKwymYpBVVhX2mHUNXh4aAqB7ddEk61DBIvEtEvt34p6LfqFa+QKQqZQkLcoPyr0o oda9/Tzo0WzVtSuCf4BzCtrFrscQe66FJ5m560veY3p6e28AG87aF5qM6hqAac8+v/eL0 9SCoEqiBKxh1t+E6nK0Bmj6rgHm1xLtbB9ZRdNMtEXoPJMVsYgmseM94D6LgCQg2x0Q== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C15081F000C5; Sun, 15 Nov 2026 08:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794733039; bh=vf4xcpWzTEDi7Kl+k/wVBVZLSyYTkfmAof1kH53cuD4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=X9QRjZqfo5GDMIDU49ukQyqiU5pnLmA0r8JE8Lvr5ne+M0lpKTrRJDVXODKkB0NMV go/ZgP4516pCIBso3NJFi1IVaa1ZdBbWvBt5t5pnV+jO2rmi+wBzRw7cF/no6DkrGp tBzRViJVs7cJg3vroSNPt2GVDlrn0bOCx3Pkx3OZDIVesL3ikvMRG7Y28cZZ4/pFcd RqJGMYP1cfnGd4SalysB6hTsjUTwFjRjTFlzN2tluxyTq3lyZ/k41fcW8LTZaD6yIA eUoRRzz87UtcCy5/cSSqJ3bJiW5hSaeFTQLVHSA3l8Hy0001O3lWdro9uxrdt78cG6 BDIVj6Ar4vnog== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 368C64A014; Sun, 15 Nov 2026 08:57:18 +0000 (UTC) From: Arun Iyengar via B4 Relay Date: Sun, 15 Nov 2026 08:57:18 +0000 Subject: [PATCH v4 1/2] usb: core: Pair ports of different hubs through their connector X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261115-usb-port-pairing-v4-1-25d3c9adcc21@gmail.com> References: <20261115-usb-port-pairing-v4-0-25d3c9adcc21@gmail.com> In-Reply-To: <20261115-usb-port-pairing-v4-0-25d3c9adcc21@gmail.com> To: Greg Kroah-Hartman , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Mathias Nyman , Chen-Yu Tsai , Rob Herring , Arun Iyengar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794733037; l=8613; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=qBMyWAfJQ3+ED0TgGFatKYoCLnVtQqhP00eQLWRu7hM=; b=KDnkeeOljdEAJt+29QD5BYBLo0OC47n5NkDjfqoOWK+QMmi3mcv18djEm6qxB4L5mQW8IKTcB fJTbvw4eawlB1JGW9ri4zvyU4oUR21kdMam5HZSRC31ZDVHjt/a7h41 X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 X-Original-From: Arun Iyengar Reply-To: aiyengar1990@gmail.com Content-Transfer-Encoding: quoted-printable From: Arun Iyengar The USB core pairs the USB 2.0 and SuperSpeed ports of a connector by port number within one xHCI, or by ACPI location. On the RK3588, USB 3.0 host 2 is SuperSpeed-only and the connector's USB 2.0 lines go to a separate EHCI, so the SuperSpeed port gets a dead USB 2.0 peer. When graph ports 0 (USB 2.0) and 1 (SuperSpeed) of a usb-connector lead to different hubs or host controllers, pair the two ports through the connector and mark them hotplug. Root hub ports are found by the controller's port number, as in ACPI; a controller graph in the dwc3 numbering (port@0 HS, port@1 SS) does not match and keeps today's pairing. Signed-off-by: Arun Iyengar --- drivers/usb/core/hub.h | 2 ++ drivers/usb/core/of.c | 87 +++++++++++++++++++++++++++++++++++++++++++++= ++++ drivers/usb/core/port.c | 62 ++++++++++++++++++++++++++++++++--- include/linux/usb/of.h | 8 +++++ 4 files changed, 155 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 9ebc5ef54a32..ab80164b4b46 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -97,6 +97,7 @@ struct usb_hub { * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted. * @early_stop: whether port initialization will be stopped earlier. * @ignore_event: whether events of the port are ignored. + * @connector_peer: peer found through a connector. */ struct usb_port { struct usb_device *child; @@ -118,6 +119,7 @@ struct usb_port { unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1; + unsigned int connector_peer:1; }; =20 #define to_usb_port(_dev) \ diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c index a6ee20d8774e..df789cef265c 100644 --- a/drivers/usb/core/of.c +++ b/drivers/usb/core/of.c @@ -145,6 +145,93 @@ enum usb_port_connect_type usb_of_get_connect_type(str= uct usb_device *hub, int p } EXPORT_SYMBOL_GPL(usb_of_get_connect_type); =20 +static bool usb_of_is_connector(const struct device_node *np) +{ + return of_device_is_compatible(np, "usb-a-connector") || + of_device_is_compatible(np, "usb-b-connector") || + of_device_is_compatible(np, "usb-c-connector"); +} + +static struct device_node *usb_of_connector_remote(struct device_node *con, + u32 con_port, u32 *port) +{ + struct device_node *ep, *remote; + struct of_endpoint endpoint; + + ep =3D of_graph_get_endpoint_by_regs(con, con_port, -1); + if (!ep) + return NULL; + + remote =3D of_graph_get_remote_endpoint(ep); + of_node_put(ep); + if (!remote) + return NULL; + + if (of_graph_parse_endpoint(remote, &endpoint)) { + of_node_put(remote); + return NULL; + } + *port =3D endpoint.port; + + ep =3D remote; + remote =3D of_graph_get_port_parent(ep); + of_node_put(ep); + + return remote; +} + +/** + * usb_of_get_connector_peer() - find a port's peer through its connector + * @hub: hub to which the port belongs + * @port: graph port of the port + * @superspeed: whether @hub is a SuperSpeed hub + * @peer_port: returns the graph port of the peer + * + * Return: the node with the peer port, with a reference, if the other half + * of @port's connector leads to a different node. NULL otherwise. + */ +struct device_node *usb_of_get_connector_peer(struct usb_device *hub, u32 = port, + bool superspeed, u32 *peer_port) +{ + struct device_node *np =3D hub->dev.of_node; + struct device_node *ep, *con, *remote, *peer =3D NULL; + u32 remote_port; + + if (!np || !of_graph_is_present(np)) + return NULL; + + ep =3D of_graph_get_endpoint_by_regs(np, port, -1); + if (!ep) + return NULL; + + con =3D of_graph_get_remote_port_parent(ep); + of_node_put(ep); + if (!con) + return NULL; + + if (!usb_of_is_connector(con) || !of_device_is_available(con)) + goto out; + + remote =3D usb_of_connector_remote(con, superspeed ? 1 : 0, &remote_port); + if (!remote) + goto out; + of_node_put(remote); + if (remote !=3D np || remote_port !=3D port) + goto out; + + /* Same-node peers are paired by port number */ + peer =3D usb_of_connector_remote(con, superspeed ? 0 : 1, peer_port); + if (peer && (peer =3D=3D np || !*peer_port || + !of_device_is_available(peer))) { + of_node_put(peer); + peer =3D NULL; + } +out: + of_node_put(con); + return peer; +} +EXPORT_SYMBOL_GPL(usb_of_get_connector_peer); + /** * usb_of_get_interface_node() - get a USB interface node * @udev: USB device of interface diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index b4452b665f59..5b2041d891ec 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -649,10 +649,49 @@ static int match_location(struct usb_device *peer_hde= v, void *p) return 0; } =20 +static u32 usb_port_graph_id(struct usb_device *hdev, int port1) +{ + if (hdev->parent) + return port1; + return usb_hcd_find_raw_port_number(bus_to_hcd(hdev->bus), port1); +} + +struct usb_connector_peer { + struct usb_port *port_dev; + struct device_node *np; + u32 port; +}; + +static int match_connector_peer(struct usb_device *peer_hdev, void *p) +{ + struct usb_connector_peer *cp =3D p; + struct usb_hub *peer_hub =3D usb_hub_to_struct_hub(peer_hdev); + struct usb_port *peer; + int port1; + + if (!peer_hub || peer_hdev->dev.of_node !=3D cp->np || + hub_is_superspeed(peer_hdev) =3D=3D cp->port_dev->is_superspeed) + return 0; + + for (port1 =3D 1; port1 <=3D peer_hdev->maxchild; port1++) { + if (usb_port_graph_id(peer_hdev, port1) =3D=3D cp->port) + break; + } + if (port1 > peer_hdev->maxchild) + return 0; + + peer =3D peer_hub->ports[port1 - 1]; + if (!peer) + return 0; + + link_peers_report(cp->port_dev, peer); + return 1; +} + /* * Find the peer port either via explicit platform firmware "location" - * data, the peer hcd for root hubs, or the upstream peer relationship - * for all other hubs. + * data, a DT connector, the peer hcd for root hubs, or the upstream peer + * relationship for all other hubs. */ static void find_and_link_peer(struct usb_hub *hub, int port1) { @@ -660,6 +699,7 @@ static void find_and_link_peer(struct usb_hub *hub, int= port1) struct usb_device *hdev =3D hub->hdev; struct usb_device *peer_hdev; struct usb_hub *peer_hub; + struct usb_connector_peer cp; =20 /* * If location data is available then we can only peer this port @@ -671,7 +711,21 @@ static void find_and_link_peer(struct usb_hub *hub, in= t port1) /* we link the peer in match_location() if found */ usb_for_each_dev(port_dev, match_location); return; - } else if (!hdev->parent) { + } + + cp.np =3D usb_of_get_connector_peer(hdev, usb_port_graph_id(hdev, port1), + port_dev->is_superspeed, &cp.port); + if (cp.np) { + cp.port_dev =3D port_dev; + port_dev->connector_peer =3D 1; + /* usb_of_get_connect_type() misses graph ports */ + port_dev->connect_type =3D USB_PORT_CONNECT_TYPE_HOT_PLUG; + usb_for_each_dev(&cp, match_connector_peer); + of_node_put(cp.np); + return; + } + + if (!hdev->parent) { struct usb_hcd *hcd =3D bus_to_hcd(hdev->bus); struct usb_hcd *peer_hcd =3D hcd->shared_hcd; =20 @@ -703,7 +757,7 @@ static void find_and_link_peer(struct usb_hub *hub, int= port1) * does not have location data */ peer =3D peer_hub->ports[port1 - 1]; - if (peer && peer->location =3D=3D 0) + if (peer && peer->location =3D=3D 0 && !peer->connector_peer) link_peers_report(port_dev, peer); } =20 diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index de42f14bd280..4be581bd2758 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -20,6 +20,8 @@ int of_usb_update_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps); enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub,= int port1); struct device_node *usb_of_get_device_node(struct usb_device *hub, int por= t1); +struct device_node *usb_of_get_connector_peer(struct usb_device *hub, u32 = port, + bool superspeed, u32 *peer_port); bool usb_of_has_combined_node(struct usb_device *udev); struct device_node *usb_of_get_interface_node(struct usb_device *udev, u8 config, u8 ifnum); @@ -49,6 +51,12 @@ usb_of_get_device_node(struct usb_device *hub, int port1) { return NULL; } +static inline struct device_node * +usb_of_get_connector_peer(struct usb_device *hub, u32 port, bool superspee= d, + u32 *peer_port) +{ + return NULL; +} static inline bool usb_of_has_combined_node(struct usb_device *udev) { return false; --=20 2.55.0 From nobody Mon Nov 23 10:29:55 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794733040; b=OYLcGG6IfaMnKQTJD/LAzHwBLRZssRVf2LzvXuFjxzOSFkR0fVol4oi0+ub8GZXK+T6a DTESEufOEuLczBO91T1B25fDdv/DemoJmqhSaV5cbC1gMQCMocUWkwZY93ogSWanwFBuY 0xcH6J/Eujy/0dt3dxbIxFJFN45aiiyCVYPzwBRps+rKu+2mr4DBkdulF2KLiZk9r/s8P UCyVnDB6JXgCh7nb8IrBScBzbWrrmDxO2+S1Qa6+Q/7gUo0VJQK4OmRp7GyqYZ8wg/y8k je/VSovUFanmFA/dT2pKVseX9Wne3E4ukhMwK6XNw3z341GXo1o94ZMm4Wowa7pGztw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733040; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=wuj5a0ng1fyQ56Dzg1UQEUsDJ1P3qdW9sd8CLjmp3ww=; b=HujVuVTiO+kyjicN89kL/bUrPM9TNRSXCAiQcSJri6KTRnNIEW1LgqCC10B+7UCy93t3 rWQMnPOaL5AHaJIyZnOT62nfQg6JyQ0dwH7q9U99qXq8awSwcf0TuZKwhLyuHppy16DBB Rlw925X4ZeIS4RPQGw44HBFqZ/2XIAlaQMo8uAp2AqjrxJzusgjqA4juSN1Gw0bDsHbZP ZgVk8l82Jj3CPt4HBHIT2inIQZjXCwyIPHRRCSEV2RnP99AsoUkACBzjS3i/gqyv1FLe+ PP7trpTnlaSdp4pRo2PB1mi8PWC31Hwuu3Em0VRLYsdmfh3ijJfCa4P1U24WD6Gl8mA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RTCL0kQb; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05CD4606A32D; Sun, 15 Nov 2026 08:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RTCL0kQb Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1794733039; b=pil5w4FXNExhAzVcZYNIQFWjrdcdpXejaKYoeV855f8TWgPOK1MkwVmQAASEn3ZmHoBn 7+wMN77l/hO0GNkUbMSSDZUkpu0/hLkZU4e0PXi4OGgH849uHsOJgZgQKQjChO+/BFc6G vwhzKeSnlB94glSkPWEgKQN3AssSlMPUEa02SvEP4gULazlPr2Iuv03HRY5geAUofvn/8 I76woTEztYv2iy2jM/PnD1G+rR0BNRTdzu47m9DURIM16V+deUc0Yw1J+vJVwxrlOjFbe G9j0h0G7+1jdNeze51klrC8MJo0d6f0z1SQ1ZecviAe0jr/kCRiKBToXddAoOPOb+KA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1794733039; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=wuj5a0ng1fyQ56Dzg1UQEUsDJ1P3qdW9sd8CLjmp3ww=; b=dOA/Ul9P2VwobmKBzfu5IXJVxx3X1o87hsB6EXinhir755qyvp7Gk46QgKiYuQCEbLQT 7yTnUMXPfgkU6T4TNL8DVRpu1ds/OH/oA68XMSNtsh+AD5tYEDrXxg99KUJCzG1ahHDuN iaM5IlW7UbRwQJFd7FpwejdRrq44KeKikoeTeVE4/S6HANTeRnbFVcbjzhTsKj1mWsSJQ aFHGGXtz4Po9fvZ6YtlbAJTOqSOsswrLyZZx2FBAwp14lSu2v139gDgHXAziyAdEgytBs 1B5m8iMYyc8DSb+xabZha7G2VOJXZIIq8sDw0Hzx8oosbXnoTLQ4Q4ce9ocnutIaKjw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C24861F000C6; Sun, 15 Nov 2026 08:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794733039; bh=wuj5a0ng1fyQ56Dzg1UQEUsDJ1P3qdW9sd8CLjmp3ww=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=RTCL0kQbkZdYnyc5hI2fd78UYU670LIehX/dkOC3yZn+stljohEznX2Sw/Q2AhkPV uDw5kw2oMNvcTrVq7CHnhCe2Egyh4aMikpBYv5SElUHgleypYMWkumi1EBH57ademx nxhXBnAQopureHL3q50GU6rPfS+E3zLa57OMc2K7pvhBfjVi+3uaJOhWqsqbOPXeWG xd6NCrbvjLDszziMqd+TjRRqA3xPt/HJFIYhVu2RN1ke8pBDrOGa6+XUKNCHosLql8 d9xLrEmaUls/yZL14HbRVf47PR1pix6ftuke1P9PBlf9JMpOals28a5AwmMP0fOCD2 eQ8dgm+JOr/XA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 4BB5D4A019; Sun, 15 Nov 2026 08:57:18 +0000 (UTC) From: Arun Iyengar via B4 Relay Date: Sun, 15 Nov 2026 08:57:19 +0000 Subject: [PATCH v4 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261115-usb-port-pairing-v4-2-25d3c9adcc21@gmail.com> References: <20261115-usb-port-pairing-v4-0-25d3c9adcc21@gmail.com> In-Reply-To: <20261115-usb-port-pairing-v4-0-25d3c9adcc21@gmail.com> To: Greg Kroah-Hartman , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Mathias Nyman , Chen-Yu Tsai , Rob Herring , Arun Iyengar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794733037; l=7016; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=x/pl7VUYVHlXCr7FPF6ufBBZfBXL4EZGgC4W7auwWNo=; b=PzNmA+xnt1Q6ecY32F8qyFfy/5dLFatcPOUs2XnNFLyRCSEmuQfpsiA/C2L+CidGXFmlvcdTt a/71/2xw7EXBM+ijrPd9c/Cp9NQlBXmXLgx2hpbnlTQCawCYQRSqmUp X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 X-Original-From: Arun Iyengar Reply-To: aiyengar1990@gmail.com Content-Transfer-Encoding: quoted-printable From: Arun Iyengar A SuperSpeed device that finds no SuperSpeed link at power-up connects at high speed and retries SuperSpeed only after a VBUS cycle or a USB 2.0 bus reset. With VBUS always on and the connector's halves on different host controllers (Orange Pi 5 USB 3 Type-A port), a device present at boot reaches the EHCI before the SuperSpeed-only xHCI is up and stays at 480 Mb/s. When such a SuperSpeed root hub starts, reset the USB 2.0 peer port of a SuperSpeed-capable device once; hubs are skipped. A device that appears on the SuperSpeed port within 1 s is disconnected from the USB 2.0 port. One that stays at high speed is restored with usb_reset_device() and keeps its drivers bound (they don't see the first reset). Signed-off-by: Arun Iyengar --- drivers/usb/core/hub.c | 132 +++++++++++++++++++++++++++++++++++++++++++++= ++++ drivers/usb/core/hub.h | 1 + 2 files changed, 133 insertions(+) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 199d3f535a89..b56ee90e55f0 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -144,6 +144,8 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); =20 static int usb_reset_and_verify_device(struct usb_device *udev); static int hub_port_disable(struct usb_hub *hub, int port1, int set_state); +static void hub_queue_peer_reset(struct usb_hub *hub); +static void hub_peer_reset_work(struct work_struct *ws); static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, u16 portstatus); =20 @@ -1346,6 +1348,10 @@ static void hub_activate(struct usb_hub *hub, enum h= ub_activation_type type) =20 /* Scan all ports that need attention */ kick_hub_wq(hub); + + if (!hdev->parent && hub_is_superspeed(hdev) && + (type =3D=3D HUB_INIT2 || type =3D=3D HUB_INIT3)) + hub_queue_peer_reset(hub); abort: if (type =3D=3D HUB_INIT2 || type =3D=3D HUB_INIT3) { /* Allow autosuspend if it was suppressed */ @@ -1419,6 +1425,10 @@ static void hub_quiesce(struct usb_hub *hub, enum hu= b_quiescing_type type) /* Stop hub_wq and related activity */ timer_delete_sync(&hub->irq_urb_retry); flush_delayed_work(&hub->post_resume_work); + if (cancel_work_sync(&hub->peer_reset_work)) { + usb_autopm_put_interface_no_suspend(to_usb_interface(hub->intfdev)); + hub_put(hub); + } usb_kill_urb(hub->urb); if (hub->has_indicators) cancel_delayed_work_sync(&hub->leds); @@ -1978,6 +1988,7 @@ static int hub_probe(struct usb_interface *intf, cons= t struct usb_device_id *id) INIT_DELAYED_WORK(&hub->leds, led_work); INIT_DELAYED_WORK(&hub->init_work, NULL); INIT_DELAYED_WORK(&hub->post_resume_work, hub_post_resume); + INIT_WORK(&hub->peer_reset_work, hub_peer_reset_work); INIT_WORK(&hub->events, hub_event); INIT_LIST_HEAD(&hub->onboard_devs); spin_lock_init(&hub->irq_urb_lock); @@ -3278,6 +3289,127 @@ static void usb_unlock_port(struct usb_port *port_d= ev) __release(&port_dev->status_lock); } =20 +static void hub_reset_peer_child(struct usb_hub *hub, int port1, + struct usb_device *peer_hdev, int peer_port1) +{ + struct usb_hub *peer_hub; + struct usb_device *udev; + + usb_lock_device(peer_hdev); + if (hub->quiescing) + goto out; + peer_hub =3D usb_hub_to_struct_hub(peer_hdev); + if (!peer_hub || peer_port1 > peer_hdev->maxchild) + goto out; + + udev =3D peer_hub->ports[peer_port1 - 1]->child; + if (!udev || udev->speed !=3D USB_SPEED_HIGH) + goto out; + + if (udev->descriptor.bDeviceClass =3D=3D USB_CLASS_HUB) + goto out; + + usb_lock_device(udev); + if (udev->state !=3D USB_STATE_NOTATTACHED && + udev->bos && udev->bos->ss_cap && + usb_autoresume_device(udev) =3D=3D 0) { + struct usb_port *port_dev =3D peer_hub->ports[peer_port1 - 1]; + u16 portstatus, portchange; + int i, ret; + + dev_info(&udev->dev, + "SuperSpeed peer port available, resetting\n"); + /* A second reset hands the EHCI port to its companion */ + usb_lock_port(port_dev); + ret =3D hub_port_reset(peer_hub, peer_port1, NULL, + HUB_ROOT_RESET_TIME, false); + for (i =3D 0; !ret && i < 20; i++) { + msleep(50); + ret =3D hub->quiescing ? -ENODEV : + usb_hub_port_status(hub, port1, &portstatus, + &portchange); + if (!ret && (portstatus & USB_PORT_STAT_CONNECTION)) + ret =3D -ENOTCONN; + } + if (ret) + hub_port_logical_disconnect(peer_hub, peer_port1); + /* Else hub_wq resets the port again */ + for (i =3D 0; ret =3D=3D -ENOTCONN && i < 20; i++) { + if (usb_hub_port_status(peer_hub, peer_port1, &portstatus, + &portchange) || + !(portstatus & USB_PORT_STAT_CONNECTION)) + break; + msleep(50); + } + usb_unlock_port(port_dev); + + if (!ret) + usb_reset_device(udev); + usb_autosuspend_device(udev); + } + usb_unlock_device(udev); +out: + usb_unlock_device(peer_hdev); +} + +static void hub_peer_reset_work(struct work_struct *ws) +{ + struct usb_hub *hub =3D container_of(ws, struct usb_hub, peer_reset_work); + struct usb_device *hdev =3D hub->hdev; + int port1; + + for (port1 =3D 1; ; port1++) { + struct usb_device *peer_hdev =3D NULL; + struct usb_port *port_dev; + int peer_port1 =3D 0; + + mutex_lock(&usb_port_peer_mutex); + if (port1 > hdev->maxchild || hub->quiescing) { + mutex_unlock(&usb_port_peer_mutex); + break; + } + port_dev =3D hub->ports[port1 - 1]; + if (port_dev->connector_peer && port_dev->peer) { + peer_hdev =3D to_usb_device(port_dev->peer->dev.parent->parent); + peer_port1 =3D port_dev->peer->portnum; + if (peer_hdev->parent || + peer_hdev->bus->controller =3D=3D hdev->bus->controller) + peer_hdev =3D NULL; + else + usb_get_dev(peer_hdev); + } + mutex_unlock(&usb_port_peer_mutex); + + if (peer_hdev) { + hub_reset_peer_child(hub, port1, peer_hdev, peer_port1); + usb_put_dev(peer_hdev); + } + } + + usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); + hub_put(hub); +} + +static void hub_queue_peer_reset(struct usb_hub *hub) +{ + struct usb_interface *intf =3D to_usb_interface(hub->intfdev); + int port1; + + for (port1 =3D 1; port1 <=3D hub->hdev->maxchild; port1++) { + if (hub->ports[port1 - 1]->connector_peer) + break; + } + if (port1 > hub->hdev->maxchild) + return; + + usb_autopm_get_interface_no_resume(intf); + hub_get(hub); + if (!queue_work(hub_wq, &hub->peer_reset_work)) { + usb_autopm_put_interface_async(intf); + hub_put(hub); + } +} + #ifdef CONFIG_PM =20 /* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */ diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index ab80164b4b46..f6387b99c708 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -71,6 +71,7 @@ struct usb_hub { struct delayed_work leds; struct delayed_work init_work; struct delayed_work post_resume_work; + struct work_struct peer_reset_work; struct work_struct events; spinlock_t irq_urb_lock; struct timer_list irq_urb_retry; --=20 2.55.0