Linux USB
 help / color / mirror / Atom feed
* [PATCH v5 0/2] usb: core: Pair ports of different host controllers through their connector
@ 2026-11-18  4:34 Arun Iyengar via B4 Relay
  2026-11-18  4:34 ` [PATCH v5 1/2] usb: core: Pair ports of different hubs " Arun Iyengar via B4 Relay
  2026-11-18  4:34 ` [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer Arun Iyengar via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-18  4:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Mathias Nyman, Chen-Yu Tsai, Rob Herring,
	Arun Iyengar

On the RK3588, the USB 2.0 lines of the USB 3.0 host 2 connector go to
a separate EHCI, so the USB core pairs its SuperSpeed port with the
wrong USB 2.0 port, and a USB 3 device present at boot stays at 480 Mb/s.

Patch 1 pairs the ports through their usb-connector. Patch 2 resets the
USB 2.0 port of such a device once, so that it retries SuperSpeed. The
Orange Pi 5 DT follows separately and needs Chen-Yu Tsai's usb-hcd
binding [1].

Tested on an Orange Pi 5 (7.3-based kernel): a USB 3 disk moved to
5 Gb/s in 3/3 boots, 6/6 xHCI rebinds and 2/2 runtime-suspended resets;
a device that stays at high speed kept its driver and a running read.
Not tested with an external USB 3 hub.

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

[1] https://lore.kernel.org/all/20261014082037.1774672-2-wenst@chromium.org/

---
Changes in v5 (all from Sashiko):
- Patch 1: look up connect_type by the controller port number; don't hold
  back a port without a matching peer; connector_peer is not a bitfield
- Patch 2: reset through usb_reset_device(); keep the device if the
  SuperSpeed port can't be read or is connected; hold its lock until the
  USB 2.0 device is gone
- Link to v4: https://patch.msgid.link/20261115-usb-port-pairing-v4-0-25d3c9adcc21@gmail.com

---
Arun Iyengar (2):
      usb: core: Pair ports of different hubs through their connector
      usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer

 drivers/usb/core/hub.c  | 158 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/hub.h  |   5 ++
 drivers/usb/core/of.c   |  87 ++++++++++++++++++++++++++
 drivers/usb/core/port.c |  70 +++++++++++++++++++--
 include/linux/usb/of.h  |   8 +++
 5 files changed, 323 insertions(+), 5 deletions(-)
---
base-commit: f11fe7603df07fbb9fa02b0d385c1696c87a6dab
change-id: 20261110-usb-port-pairing-af0f66f0ab2e

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v5 1/2] usb: core: Pair ports of different hubs through their connector
  2026-11-18  4:34 [PATCH v5 0/2] usb: core: Pair ports of different host controllers through their connector Arun Iyengar via B4 Relay
@ 2026-11-18  4:34 ` Arun Iyengar via B4 Relay
  2026-11-18  5:13   ` sashiko-bot
  2026-11-18  4:34 ` [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer Arun Iyengar via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-18  4:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Mathias Nyman, Chen-Yu Tsai, Rob Herring,
	Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

On the RK3588, USB 3.0 host 2 is SuperSpeed-only and its connector's
USB 2.0 lines go to a separate EHCI, so pairing by port number gives the
SuperSpeed port a dead USB 2.0 peer.

When ports 0 (USB 2.0) and 1 (SuperSpeed) of a usb-connector graph lead
to different hubs, pair them through the connector. Root hub ports are
found by the controller port number; graphs in the dwc3 numbering don't
match and keep today's pairing. connect_type is looked up the same way,
so such a SuperSpeed port reads "hotplug".

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/usb/core/hub.h  |  2 ++
 drivers/usb/core/of.c   | 87 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/port.c | 70 ++++++++++++++++++++++++++++++++++++---
 include/linux/usb/of.h  |  8 +++++
 4 files changed, 162 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 9ebc5ef54a32..a186c41bdb5e 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;
+	bool connector_peer;
 };
 
 #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(struct usb_device *hub, int p
 }
 EXPORT_SYMBOL_GPL(usb_of_get_connect_type);
 
+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 = of_graph_get_endpoint_by_regs(con, con_port, -1);
+	if (!ep)
+		return NULL;
+
+	remote = 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 = endpoint.port;
+
+	ep = remote;
+	remote = 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 = hub->dev.of_node;
+	struct device_node *ep, *con, *remote, *peer = NULL;
+	u32 remote_port;
+
+	if (!np || !of_graph_is_present(np))
+		return NULL;
+
+	ep = of_graph_get_endpoint_by_regs(np, port, -1);
+	if (!ep)
+		return NULL;
+
+	con = 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 = usb_of_connector_remote(con, superspeed ? 1 : 0, &remote_port);
+	if (!remote)
+		goto out;
+	of_node_put(remote);
+	if (remote != np || remote_port != port)
+		goto out;
+
+	/* Same-node peers are paired by port number */
+	peer = usb_of_connector_remote(con, superspeed ? 0 : 1, peer_port);
+	if (peer && (peer == np || !*peer_port ||
+		     !of_device_is_available(peer))) {
+		of_node_put(peer);
+		peer = 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..da7037bbbf57 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -649,10 +649,44 @@ static int match_location(struct usb_device *peer_hdev, void *p)
 	return 0;
 }
 
+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 usb_port *peer;
+	struct device_node *np;
+	u32 port;
+};
+
+static int match_connector_peer(struct usb_device *peer_hdev, void *p)
+{
+	struct usb_connector_peer *cp = p;
+	struct usb_hub *peer_hub = usb_hub_to_struct_hub(peer_hdev);
+	int port1;
+
+	if (!peer_hub || !peer_hdev->maxchild ||
+	    peer_hdev->dev.of_node != cp->np ||
+	    hub_is_superspeed(peer_hdev) == cp->port_dev->is_superspeed)
+		return 0;
+
+	for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) {
+		if (usb_port_graph_id(peer_hdev, port1) == cp->port) {
+			cp->peer = peer_hub->ports[port1 - 1];
+			break;
+		}
+	}
+	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 +694,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
 	struct usb_device *hdev = hub->hdev;
 	struct usb_device *peer_hdev;
 	struct usb_hub *peer_hub;
+	struct usb_connector_peer cp;
 
 	/*
 	 * If location data is available then we can only peer this port
@@ -671,7 +706,27 @@ static void find_and_link_peer(struct usb_hub *hub, int 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 = usb_of_get_connector_peer(hdev, usb_port_graph_id(hdev, port1),
+					  port_dev->is_superspeed, &cp.port);
+	if (cp.np) {
+		bool found;
+
+		cp.port_dev = port_dev;
+		cp.peer = NULL;
+		found = usb_for_each_dev(&cp, match_connector_peer);
+		of_node_put(cp.np);
+		if (cp.peer)
+			link_peers_report(port_dev, cp.peer);
+		/* Without the peer hub yet, wait for it */
+		if (cp.peer || !found) {
+			port_dev->connector_peer = true;
+			return;
+		}
+	}
+
+	if (!hdev->parent) {
 		struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
 		struct usb_hcd *peer_hcd = hcd->shared_hcd;
 
@@ -703,7 +758,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
 	 * does not have location data
 	 */
 	peer = peer_hub->ports[port1 - 1];
-	if (peer && peer->location == 0)
+	if (peer && peer->location == 0 && !peer->connector_peer)
 		link_peers_report(port_dev, peer);
 }
 
@@ -754,6 +809,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 {
 	struct usb_port *port_dev;
 	struct usb_device *hdev = hub->hdev;
+	u32 graph_id;
 	int retval;
 
 	port_dev = kzalloc_obj(*port_dev);
@@ -766,7 +822,11 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 		return -ENOMEM;
 	}
 
-	port_dev->connect_type = usb_of_get_connect_type(hdev, port1);
+	graph_id = usb_port_graph_id(hdev, port1);
+	port_dev->connect_type = usb_of_get_connect_type(hdev, graph_id);
+	/* dwc3 graphs give the SuperSpeed port port@1 */
+	if (port_dev->connect_type == USB_PORT_NOT_USED && graph_id != port1)
+		port_dev->connect_type = usb_of_get_connect_type(hdev, port1);
 	hub->ports[port1 - 1] = port_dev;
 	port_dev->portnum = port1;
 	set_bit(port1, hub->power_bits);
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 port1);
+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 superspeed,
+			  u32 *peer_port)
+{
+	return NULL;
+}
 static inline bool usb_of_has_combined_node(struct usb_device *udev)
 {
 	return false;

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer
  2026-11-18  4:34 [PATCH v5 0/2] usb: core: Pair ports of different host controllers through their connector Arun Iyengar via B4 Relay
  2026-11-18  4:34 ` [PATCH v5 1/2] usb: core: Pair ports of different hubs " Arun Iyengar via B4 Relay
@ 2026-11-18  4:34 ` Arun Iyengar via B4 Relay
  2026-11-18  4:56   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-18  4:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern
  Cc: linux-usb, linux-kernel, Mathias Nyman, Chen-Yu Tsai, Rob Herring,
	Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

With VBUS always on, a USB 3 device present at boot connects to the EHCI
before the SuperSpeed-only xHCI is up, and stays at 480 Mb/s until a USB
2.0 bus reset.

When such a SuperSpeed root hub starts, reset the USB 2.0 peer port of a
SuperSpeed-capable device (not a hub) once with usb_reset_device(). If
the device appears on the SuperSpeed port within 1 s, the USB 2.0 device
is disconnected; otherwise the reset completes at high speed.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/usb/core/hub.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/hub.h |   3 +
 2 files changed, 161 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 199d3f535a89..65d0728d4330 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);
 
 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);
 
@@ -1346,6 +1348,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
 
 	/* Scan all ports that need attention */
 	kick_hub_wq(hub);
+
+	if (!hdev->parent && hub_is_superspeed(hdev) &&
+	    (type == HUB_INIT2 || type == HUB_INIT3))
+		hub_queue_peer_reset(hub);
  abort:
 	if (type == HUB_INIT2 || type == HUB_INIT3) {
 		/* Allow autosuspend if it was suppressed */
@@ -1419,6 +1425,10 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_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, const 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,116 @@ static void usb_unlock_port(struct usb_port *port_dev)
 	__release(&port_dev->status_lock);
 }
 
+static void hub_reset_peer_child(struct usb_hub *hub, int port1,
+				 struct usb_device *peer_hdev, int peer_port1)
+{
+	struct usb_port *ss_port = hub->ports[port1 - 1];
+	struct usb_port *port_dev;
+	struct usb_hub *peer_hub;
+	struct usb_device *udev;
+	u16 portstatus, portchange;
+
+	/* Keep hub_wq off the SuperSpeed port until the USB 2.0 device is gone */
+	mutex_lock_nested(&ss_port->status_lock, SINGLE_DEPTH_NESTING);
+	usb_lock_device(peer_hdev);
+	if (hub->quiescing)
+		goto out;
+	peer_hub = usb_hub_to_struct_hub(peer_hdev);
+	if (!peer_hub || peer_port1 > peer_hdev->maxchild)
+		goto out;
+
+	port_dev = peer_hub->ports[peer_port1 - 1];
+	udev = port_dev->child;
+	if (!udev || udev->speed != USB_SPEED_HIGH ||
+	    udev->descriptor.bDeviceClass == USB_CLASS_HUB)
+		goto out;
+
+	if (usb_hub_port_status(hub, port1, &portstatus, &portchange) ||
+	    (portstatus & USB_PORT_STAT_CONNECTION))
+		goto out;
+
+	usb_lock_device(udev);
+	if (udev->state != USB_STATE_NOTATTACHED &&
+	    udev->bos && udev->bos->ss_cap) {
+		dev_info(&udev->dev,
+			 "SuperSpeed peer port available, resetting\n");
+		port_dev->ss_retry = ss_port;
+		usb_reset_device(udev);
+		port_dev->ss_retry = NULL;
+	}
+	usb_unlock_device(udev);
+
+	/* As hub_port_connect() would */
+	if (udev->state == USB_STATE_NOTATTACHED) {
+		struct usb_hcd *hcd = bus_to_hcd(peer_hdev->bus);
+
+		if (hcd->usb_phy)
+			usb_phy_notify_disconnect(hcd->usb_phy, udev->speed);
+		usb_disconnect(&port_dev->child);
+	}
+out:
+	usb_unlock_device(peer_hdev);
+	mutex_unlock(&ss_port->status_lock);
+}
+
+static void hub_peer_reset_work(struct work_struct *ws)
+{
+	struct usb_hub *hub = container_of(ws, struct usb_hub, peer_reset_work);
+	struct usb_device *hdev = hub->hdev;
+	int port1;
+
+	for (port1 = 1; ; port1++) {
+		struct usb_device *peer_hdev = NULL;
+		struct usb_port *port_dev;
+		int peer_port1 = 0;
+
+		mutex_lock(&usb_port_peer_mutex);
+		if (port1 > hdev->maxchild || hub->quiescing) {
+			mutex_unlock(&usb_port_peer_mutex);
+			break;
+		}
+		port_dev = hub->ports[port1 - 1];
+		if (port_dev->connector_peer && port_dev->peer) {
+			peer_hdev = to_usb_device(port_dev->peer->dev.parent->parent);
+			peer_port1 = port_dev->peer->portnum;
+			if (peer_hdev->parent ||
+			    peer_hdev->bus->controller == hdev->bus->controller)
+				peer_hdev = 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 = to_usb_interface(hub->intfdev);
+	int port1;
+
+	for (port1 = 1; port1 <= 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
 
 /* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */
@@ -4899,6 +5020,37 @@ static int get_bMaxPacketSize0(struct usb_device *udev,
 
 #define GET_DESCRIPTOR_BUFSIZE	64
 
+/* -ENOTCONN if the device moved to its SuperSpeed peer port */
+static int hub_wait_ss_retry(struct usb_hub *hub, int port1,
+			     struct usb_port *ss_port)
+{
+	struct usb_device *ss_hdev = to_usb_device(ss_port->dev.parent->parent);
+	struct usb_hub *ss_hub = usb_hub_to_struct_hub(ss_hdev);
+	u16 portstatus, portchange;
+	int i;
+
+	for (i = 0; i < 20; i++) {
+		msleep(50);
+		if (!ss_hub ||
+		    usb_hub_port_status(ss_hub, ss_port->portnum, &portstatus,
+					&portchange))
+			return 0;
+		if (portstatus & USB_PORT_STAT_CONNECTION)
+			break;
+	}
+	if (i == 20)
+		return 0;
+
+	/* Else hub_wq resets the port again */
+	for (i = 0; i < 20; i++) {
+		if (usb_hub_port_status(hub, port1, &portstatus, &portchange) ||
+		    !(portstatus & USB_PORT_STAT_CONNECTION))
+			break;
+		msleep(50);
+	}
+	return -ENOTCONN;
+}
+
 /* Reset device, (re)assign address, get device descriptor.
  * Device connection must be stable, no more debouncing needed.
  * Returns device in USB_STATE_ADDRESS, except on error.
@@ -4959,6 +5111,12 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
 		goto fail;
 	/* success, speed is known */
 
+	if (port_dev->ss_retry) {
+		retval = hub_wait_ss_retry(hub, port1, port_dev->ss_retry);
+		if (retval)
+			goto fail;
+	}
+
 	retval = -ENODEV;
 
 	/* Don't allow speed changes at reset, except usb 3.0 to faster */
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index a186c41bdb5e..1213a242fa34 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;
@@ -98,12 +99,14 @@ struct usb_hub {
  * @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.
+ * @ss_retry: SuperSpeed port a device may move to on reset.
  */
 struct usb_port {
 	struct usb_device *child;
 	struct device dev;
 	struct usb_dev_state *port_owner;
 	struct usb_port *peer;
+	struct usb_port *ss_retry;
 	struct typec_connector *connector;
 	struct dev_pm_qos_request *req;
 	enum usb_port_connect_type connect_type;

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer
  2026-11-18  4:34 ` [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer Arun Iyengar via B4 Relay
@ 2026-11-18  4:56   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18  4:56 UTC (permalink / raw)
  To: Arun Iyengar; +Cc: linux-usb

> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> With VBUS always on, a USB 3 device present at boot connects to the EHCI
> before the SuperSpeed-only xHCI is up, and stays at 480 Mb/s until a USB
> 2.0 bus reset.
> 
> When such a SuperSpeed root hub starts, reset the USB 2.0 peer port of a
> SuperSpeed-capable device (not a hub) once with usb_reset_device(). If
> the device appears on the SuperSpeed port within 1 s, the USB 2.0 device
> is disconnected; otherwise the reset completes at high speed.
> 
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-usb-port-pairing-v5-0-5f1a26789270@gmail.com?part=2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 1/2] usb: core: Pair ports of different hubs through their connector
  2026-11-18  4:34 ` [PATCH v5 1/2] usb: core: Pair ports of different hubs " Arun Iyengar via B4 Relay
@ 2026-11-18  5:13   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18  5:13 UTC (permalink / raw)
  To: Arun Iyengar; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: core: broken connector peer lookup in
  usb_of_get_connector_peer()
- [Medium] usb: core: wrong connect_type fallback in
  usb_hub_create_port_device()
--

commit b5e6aabc1813e83de610f267477e491f798833aa
Author: Arun Iyengar <aiyengar1990@gmail.com>

usb: core: Pair ports of different hubs through their connector

This commit pairs USB 2.0 and SuperSpeed ports belonging to different hubs
when they are linked to the same usb-connector node in the Device Tree, and
looks up root hub connect_type using the raw controller port number.

> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index a6ee20d8774e3..df789cef265c4 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(struct usb_device *hub, int p

[ ... ]

> +struct device_node *usb_of_get_connector_peer(struct usb_device *hub, u32 port,
> +					      bool superspeed, u32 *peer_port)
> +{
> +	struct device_node *np = hub->dev.of_node;
> +	struct device_node *ep, *con, *remote, *peer = NULL;
> +	u32 remote_port;
> +
> +	if (!np || !of_graph_is_present(np))
> +		return NULL;
> +
> +	ep = of_graph_get_endpoint_by_regs(np, port, -1);
> +	if (!ep)
> +		return NULL;
> +
> +	con = 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 = usb_of_connector_remote(con, superspeed ? 1 : 0, &remote_port);
> +	if (!remote)
> +		goto out;
> +	of_node_put(remote);
> +	if (remote != np || remote_port != port)
> +		goto out;
> +
> +	/* Same-node peers are paired by port number */
> +	peer = usb_of_connector_remote(con, superspeed ? 0 : 1, peer_port);
> +	if (peer && (peer == np || !*peer_port ||
> +		     !of_device_is_available(peer))) {
> +		of_node_put(peer);
> +		peer = 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 b4452b665f591..da7037bbbf57f 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -649,10 +649,44 @@ static int match_location(struct usb_device *peer_hdev, void *p)
>  	return 0;
>  }
>  
> +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 usb_port *peer;
> +	struct device_node *np;
> +	u32 port;
> +};
> +
> +static int match_connector_peer(struct usb_device *peer_hdev, void *p)
> +{
> +	struct usb_connector_peer *cp = p;
> +	struct usb_hub *peer_hub = usb_hub_to_struct_hub(peer_hdev);
> +	int port1;
> +
> +	if (!peer_hub || !peer_hdev->maxchild ||
> +	    peer_hdev->dev.of_node != cp->np ||
> +	    hub_is_superspeed(peer_hdev) == cp->port_dev->is_superspeed)
> +		return 0;
> +
> +	for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) {
> +		if (usb_port_graph_id(peer_hdev, port1) == cp->port) {
> +			cp->peer = peer_hub->ports[port1 - 1];
> +			break;
> +		}
> +	}
> +	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 +694,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
>  	struct usb_device *hdev = hub->hdev;
>  	struct usb_device *peer_hdev;
>  	struct usb_hub *peer_hub;
> +	struct usb_connector_peer cp;
>  
>  	/*
>  	 * If location data is available then we can only peer this port
> @@ -671,7 +706,27 @@ static void find_and_link_peer(struct usb_hub *hub, int 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 = usb_of_get_connector_peer(hdev, usb_port_graph_id(hdev, port1),
> +					  port_dev->is_superspeed, &cp.port);
> +	if (cp.np) {
> +		bool found;
> +
> +		cp.port_dev = port_dev;
> +		cp.peer = NULL;
> +		found = usb_for_each_dev(&cp, match_connector_peer);
> +		of_node_put(cp.np);
> +		if (cp.peer)
> +			link_peers_report(port_dev, cp.peer);
> +		/* Without the peer hub yet, wait for it */
> +		if (cp.peer || !found) {
> +			port_dev->connector_peer = true;
> +			return;
> +		}
> +	}

[Severity: High]
Can a USB 2.0 hub port end up neither connector-peered nor default-peered when
connector port 1 points to a dwc3 controller using the standard snps,dwc3
binding (port@0 for High-Speed, port@1 for SuperSpeed) or to an intermediate
non-hub node such as a Type-C mux or PHY?

When find_and_link_peer() runs for a USB 2.0 port (superspeed == false),
usb_of_get_connector_peer() inspects connector port 1.  Unlike a lookup from
the SuperSpeed side (where a dwc3 High-Speed endpoint at port@0 is filtered
out by !*peer_port), a dwc3 SuperSpeed endpoint at port@1 (as on
arch/arm64/boot/dts/rockchip/rk3576-lckfb-tspi-3m.dts, where usb_a_3_0 links
usb_hub port@1 to usb_drd1_dwc3 port@1) or a mux/PHY endpoint with reg >= 1
passes the !*peer_port check and is returned as cp.np with cp.port = 1.

In match_connector_peer(), a dwc3 SuperSpeed root hub port has
usb_port_graph_id() == 2 (from xhci_find_raw_port_number()), so it never
matches cp.port == 1, and a non-hub mux/PHY node never matches any usb_device
on usb_bus_type.  Whenever the USB 2.0 hub probes before the SuperSpeed root
hub (or when cp.np is not a hub), found is false, so find_and_link_peer() sets
port_dev->connector_peer = true and returns early, skipping default peering
and preventing the peer from linking later.

[ ... ]

> @@ -766,7 +822,11 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
>  		return -ENOMEM;
>  	}
>  
> -	port_dev->connect_type = usb_of_get_connect_type(hdev, port1);
> +	graph_id = usb_port_graph_id(hdev, port1);
> +	port_dev->connect_type = usb_of_get_connect_type(hdev, graph_id);
> +	/* dwc3 graphs give the SuperSpeed port port@1 */
> +	if (port_dev->connect_type == USB_PORT_NOT_USED && graph_id != port1)
> +		port_dev->connect_type = usb_of_get_connect_type(hdev, port1);

[Severity: Medium]
Does falling back to usb_of_get_connect_type(hdev, port1) misclassify a
SuperSpeed root hub port by matching the USB 2.0 child device or graph
endpoint at raw port 1?

On split-roothub controllers such as xHCI, the USB 2.0 and SuperSpeed root
hubs share hdev->dev.of_node, and child USB device nodes under the controller
use raw controller port numbers (so reg = <1> is High-Speed raw port 1).  For
SuperSpeed root hub port 1 (port1 = 1, graph_id = 2), whenever
usb_of_get_connect_type(hdev, 2) returns USB_PORT_NOT_USED (either because the
DT uses dwc3 port@1 numbering or because SuperSpeed port 2 is unused), calling
usb_of_get_connect_type(hdev, 1) checks usb_of_get_device_node(hdev, 1) and
port@1:

drivers/usb/core/of.c:usb_of_get_connect_type() {
    ...
	child = usb_of_get_device_node(hub, port1);
	if (of_device_is_available(child))
		connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED;
	of_node_put(child);

	return connect_type;
}

For example, on rk3576-lckfb-tspi-3m.dts, usb_drd1_dwc3 has both an onboard
USB 2.0 hub child node hub@1 (reg = <1>) and ports/port@1 for the external
SuperSpeed Type-A connector.  The fallback matches hub@1 and marks the
external SuperSpeed port as USB_PORT_CONNECT_TYPE_HARD_WIRED, causing
set_usb_port_removable() to treat hotplugged SuperSpeed devices as fixed and
usb_dev_authorized() to auto-authorize them under
USB_DEVICE_AUTHORIZE_INTERNAL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-usb-port-pairing-v5-0-5f1a26789270@gmail.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-18  5:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  4:34 [PATCH v5 0/2] usb: core: Pair ports of different host controllers through their connector Arun Iyengar via B4 Relay
2026-11-18  4:34 ` [PATCH v5 1/2] usb: core: Pair ports of different hubs " Arun Iyengar via B4 Relay
2026-11-18  5:13   ` sashiko-bot
2026-11-18  4:34 ` [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer Arun Iyengar via B4 Relay
2026-11-18  4:56   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox