From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796352803; b=eAnBKXwnl1+oF5ohyyiVhXSoaqNJNZpdSlpTXFp7aZF4da+uN1QY0r2vet43gzPv7aqW BIfDFP96e+QJwefLwcsbPpqVou8tvivV1rXPI9GnqzPIX0kYMJY1rx3jgVeewFWtFBMyJ CjgXbBhkrRCfAilTfZXHvIc2i6PNVkJiU4acryOcmXk3qYg+Lt9wrvYCr8trXYEHsUJ1A qqc9DfN+k9FKJdsdt5klFiMBIoIDJ7ZeUnRJqCDfpOJl4H7r6/OoVLrPjge/SAWkn9Fnx jG4ZRcvzxEdzBEW0M3f6c/jVzUQdC1v+2FKPegg0+bBMhhjzAODIdi/zunb/ZRbuxhQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352803; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=upsAGdeRIdlytDiqjhutVt085a0g05r19ra2Vsq7hcg=; b=1J3VGEx5GXYvpEVbWnVqDiCgYvIcz52tDL09skDX1XkSxzfgtH+J1ICpcV658M2AF+A7 gOM+YW+kq/2X1Gx8rIQ+zi1WzsV02JCifvXnU+6CYEgYU1ahiFmPlCDvht6cnVKJUU+Wr xPkHnXKRfaHhiKIrZMh1jEETSq3x7TJVE70QPQKUK5YgGh4QTfB51PMVk12vJN69AwRHq 7z22E/RM8mxMs+eGNaAFit1E3aGBE4Gqi+2fThnd6iQ/B7I/KHvSAr861SUOJL25JybXT fVHwmDcbOU1JVIoPlPp57ApcJe/dfPmjvOtElkHL6jfK38Giv0BJvny1ZU1AwqPfNaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b="INIu3/mm"; arc=none smtp.remote-ip=209.85.214.171 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9CF1606A32C for ; Fri, 4 Dec 2026 02:53:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A9CF1606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=INIu3/mm Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f02ee04378so5221755ad.1 for ; Thu, 03 Dec 2026 18:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796352802; x=1796957602; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=upsAGdeRIdlytDiqjhutVt085a0g05r19ra2Vsq7hcg=; b=INIu3/mmNQA3kG20eKJMY+HwZjxKARhpZhn23CJRvz0eiV9I92m/v5SWCILurMD33M tlgpkMvG4/NZ98JfwBDYaGf+Se3ldrTK+e/XWFnVdBAZhKjOfKe1vBK0/LK5ZAA0MojS m2b72JLf8V+n/bIh4nozKwko7ezhrbcuwafJU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796352802; x=1796957602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=upsAGdeRIdlytDiqjhutVt085a0g05r19ra2Vsq7hcg=; b=cGdbtueZX72IEk5OWTuy980xhCwlQMjgjAzxTYb/nB8z6k6KxowEg/f0MSxjPi4Ncl g2JLpWX8zd1c7uk3DbsRn5FRhTheEurxy8eken+5Q2TwX7TKVg2qbIDOQr5aa6EhoN99 kEwFP91vMQSjNp+pwXZ/35ExbrBdZewTefnviJXNq2HxxNbI4KTPIcZ1/UmOxQHhGLuz 3FENrtERat9GcjVqafETJnXCa7WbB/gXBf25yKCcQmu2LdugBMlQbZgOpJ+3FOQ3uZLn sM00Qwxup6LTZMH3BpVxLUfOdZ7U5H5TeZfhhSE00N3yPJfNyD32SpLIQb6pxnxTL+Dx GS7A== X-Forwarded-Encrypted: i=1; AL+hErElb2gUL45XEM9iBz4KTrWvzJK/LvVSqZTEYmpXNWnIyBIckx23EHSrSDdlIztUNKlXNU5g0Yik4ZvJ@vger.kernel.org X-Gm-Message-State: APuU4Z+BUXC3MpdjFOeBM03VZl+lZgem0jwCG4pVg8PNghg75L/S52cL +7nDT5ESiy1RFq4tuAofuLvCWb3CHUskkxuQf7K9r5Glh3S60uxxFGLHyG/qbrnrFeTd2CUtjDm D0QXF3S/a X-Gm-Gg: AZFdTZdoj/Q4gFCfFBMg3ByoVgtkwWjvLip5BQ+FmXb9nHPzCIGBJsffePZfQsWwc19 ZSgIbcav/gUf/MkuN/ZUL48TtpudPhi/8kZN71aWWlOOZf9vGwkvqRm4RGqlo0voZs286hqLJTL qaJTOwBSFgH7JYY80soxnO2CToPmRAnoy/rLB73Fpk2jclTavMaabkj+4Zx0Eu24Gy79gFVSp1z cZynw4zmXSq+5IJglXboFIsqnr+JJQLIdIT6LjCIa2A4/aw+xN30KR2dkFgNRpL8TkwDbSZq9Jy foMNNJ8lAkdtTYkw9Y7Snm0WN4eT4z7ODAFvC67qwyk6+ip83ZdASDu4RyuD8KY1OvLXQN5oM4z zRvaKjVyOQs8YMN4uPxQAmG9snGZAAIAS3sndHkGVTsWyH7P0Om7CFltI4oFI7IWiZ+o1Mh50h3 +s3hVvLQrHyK3QxuVsfZRaMuaZy9T7qeEJtMrB6/Hfh1ZxWgnYKSbhzJA0H91qdQW4IHx4D5LdN buc45+j4NLeCSeK/8jS1JvLvveB7PcM+jDLjBdlRHOdG5XYdW59c0oIl/V4V4hfWrlNUaDH3ios dZAH9fXEQBvSSe2D8Px5wAFjUZ53cEZWkrY2sVMogl/Ue/eQYTWb9ygN1rc= X-Received: by 2002:a17:902:e5c2:b0:2f0:3e44:4761 with SMTP id d9443c01a7336-2f1ba225c80mr5092525ad.54.1796352801982; Thu, 03 Dec 2026 18:53:21 -0800 (PST) Received: from localhost ([2a00:79e0:203d:7:baaf:2341:c22:c17a]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2f1b78fab9fsm3187635ad.15.2026.12.03.18.53.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 18:53:21 -0800 (PST) From: Chen-Yu Tsai To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Chen-Yu Tsai , Alan Stern , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Matthias Kaehlcke , Stephen Boyd , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Johan Hovold , Mathias Nyman , Neil Armstrong , Bjorn Andersson , stable@vger.kernel.org Subject: [PATCH 2/4] usb: of: Use raw port numbers for root hub OF lookups Date: Fri, 4 Dec 2026 10:52:40 +0800 Message-ID: <20261204025243.807657-3-wenst@chromium.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261204025243.807657-1-wenst@chromium.org> References: <20261204025243.807657-1-wenst@chromium.org> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 7739376eb1ed ("USB: of: clean up device-node helper") reworked usb_of_get_device_node() such that it takes the USB hub object and a one-based port number. One could look at it and think that the port number should be the logical port number found on the hub. This is not the case on root hubs of xHCI host controllers. An xHCI controller has two root hubs, a primary (HS) root hub and a secondary (SS) root hub, sharing a single HCD device tree node, with the HS and SS downstream ports split among them and either protocol block able to come first in the controller's raw port numbering. Both downstream DT child nodes (reg = ) and 1-based OF graph ports (port@N) are indexed by the controller's raw port number rather than the logical port number on a root hub. Previously only usb_alloc_dev() resolved the raw port number with usb_hcd_find_raw_port_number() before calling usb_of_get_device_node(). Neither usb_of_get_device_node() nor the OF graph lookup in usb_of_get_connect_type() remapped root hub port numbers. For example, on controllers where SS raw ports precede HS raw ports, an OF graph lookup for HS port 1 would look for raw port 1 (an SS port); if only the HS data lines are wired up, usb_of_get_connect_type() would incorrectly return USB_PORT_NOT_USED instead of USB_PORT_CONNECT_TYPE_HOT_PLUG. Add a usb_of_find_raw_port() helper that remaps root hub port numbers via usb_hcd_find_raw_port_number(), and use it in both usb_of_get_device_node() (after an early NULL check on hub->dev.of_node to skip the lookup on non-DT root hubs) and the OF graph lookup in usb_of_get_connect_type(), so that all callers align with the stated API contract: - usb_alloc_dev() continues to match downstream USB devices as before. - usb_of_get_connect_type() now uses raw port numbers for both OF graph connections and hard-wired child nodes on root hubs. - onboard_dev_create_pdevs() now looks up hard-wired child nodes on root hubs using raw port numbers instead of the unmapped hub port index, fixing lookups when the two differ (such as USB 2.0 ports whose raw port number exceeds the root hub's maxchild). - usbport_trig_port_observed() in ledtrig-usbport now matches each root hub port against its corresponding raw port node rather than matching port 1 of both HS and SS root hubs to reg = <1>. Also tweak usb_of_get_device_node()'s and usb_of_get_connect_type()'s kernel-doc comments to make it clear that hub port numbers are mapped to raw port numbers. The missing raw-port remapping for OF graph lookups in usb_of_get_connect_type() was flagged during a review of the M.2 E-key USB support series by an AI coding agent (Antigravity). Fixes: 4f04c210d031 ("usb: core: read USB ports from DT in the usbport LED trigger driver") Fixes: 82e82130a78b ("usb: core: Set connect_type of ports based on DT node") Fixes: 8bc063641ceb ("usb: misc: Add onboard_usb_hub driver") Cc: Signed-off-by: Chen-Yu Tsai --- drivers/usb/core/of.c | 42 ++++++++++++++++++++++++++++++------------ drivers/usb/core/usb.c | 8 +------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c index a040fae5710b..47e5428fc8d4 100644 --- a/drivers/usb/core/of.c +++ b/drivers/usb/core/of.c @@ -9,15 +9,25 @@ #include #include +#include +#include #include +static int usb_of_find_raw_port(struct usb_device *hub, int port1) +{ + if (!hub->parent) + return usb_hcd_find_raw_port_number(bus_to_hcd(hub->bus), port1); + + return port1; +} + /** * usb_of_get_device_node() - get a USB device node * @hub: hub to which device is connected - * @port1: one-based index of port + * @port1: one-based index of hub port * * Look up the node of a USB device given its parent hub device and one-based - * port number. + * hub port number. * * Return: A pointer to the node with incremented refcount if found, or * %NULL otherwise. @@ -25,13 +35,19 @@ struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1) { struct device_node *node; + int raw_port; u32 reg; + if (!hub->dev.of_node) + return NULL; + + raw_port = usb_of_find_raw_port(hub, port1); + for_each_child_of_node(hub->dev.of_node, node) { if (of_property_read_u32(node, "reg", ®)) continue; - if (reg == port1) + if (reg == raw_port) return node; } @@ -109,16 +125,16 @@ static bool usb_of_has_graph(struct device_node *np) /** * usb_of_get_connect_type() - get a USB hub's port connect_type * @hub: hub to which port is for @port1 - * @port1: one-based index of port + * @port1: one-based index of hub port * * Get the connect_type of @port1 based on the device node for @hub. If the - * port is described in a valid 1-based OF graph, the connect_type is - * "hotplug". OF graphs containing port@0 or an unnumbered "port" node are - * ignored. If the @hub has a child device with a 'reg' property equal to - * @port1 the connect_type is "hard-wired". If there isn't a valid 1-based OF - * graph or any child node with a 'reg' property then the connect_type is - * "unknown". Otherwise, the port is considered "unused" because it isn't - * described at all. + * port's raw port number is described in a valid 1-based OF graph, the + * connect_type is "hotplug". OF graphs containing port@0 or an unnumbered + * "port" node are ignored. If the @hub has a child device with a 'reg' + * property matching the port's raw port number, the connect_type is + * "hard-wired". If there isn't a valid 1-based OF graph or any child node + * with a 'reg' property then the connect_type is "unknown". Otherwise, the + * port is considered "unused" because it isn't described at all. * * Return: A connect_type for @port1 based on the device node for @hub. */ @@ -141,7 +157,9 @@ enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int p * usb-a-connector compatible node, in the OF graph. */ if (has_graph) { - ep = of_graph_get_endpoint_by_regs(np, port1, -1); + int raw_port = usb_of_find_raw_port(hub, port1); + + ep = of_graph_get_endpoint_by_regs(np, raw_port, -1); if (ep) { remote_np = of_graph_get_remote_port_parent(ep); of_node_put(ep); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 2559a180fdee..5f775130ebf6 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -646,7 +646,6 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, { struct usb_device *dev; struct usb_hcd *usb_hcd = bus_to_hcd(bus); - unsigned raw_port = port1; dev = kzalloc_obj(*dev); if (!dev) @@ -725,12 +724,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->dev.parent = &parent->dev; dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); - if (!parent->parent) { - /* device under root hub's port */ - raw_port = usb_hcd_find_raw_port_number(usb_hcd, - port1); - } - dev->dev.of_node = usb_of_get_device_node(parent, raw_port); + dev->dev.of_node = usb_of_get_device_node(parent, port1); /* hub driver sets up TT records */ } -- 2.56.1.915.g69d5ec7298-goog