From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9861DC79F83 for ; Fri, 4 Sep 2026 08:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KKk9MsFCuRaE3YN06XOCWIV3dU/ufhZe2dVPkS7i8qI=; b=b8hwHjJo5Jj+zjZILaNv13Du3R egXxeRX7OxlrMm4Cq9y23HDPRMO/hADFOPqQ/MPlUrIEc5laSxqFSmPrJ8nphTK7fYcMCzpwjxeF3 wgJd7E+rJ3yTYO8zQ7J70QNHrP6C2qJm1vi7E/iie/cBE5ZX3ZWTTWnjxGKkFfDe05DPpy29+f1+F CqeTzg7fbGX0UzRhL2FN0vrJihM+56fu/u/pLk/z2fNsUhheWSKRdyrdmvVIwoLx5+OHvpE/UKO0K 4SI8aTgIuLwVcBxDX2DhjiSMhvbJjdMZlWwnO7Fx9pjNUfDPAlRDGORvgaUlTMhgwS3gvvboTFplA ITdusB7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x2PWk-00000001QAD-28ns; Fri, 04 Sep 2026 08:44:02 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x2PWf-00000001Q7e-34Lv for linux-mediatek@lists.infradead.org; Fri, 04 Sep 2026 08:44:01 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-398a4dcf289so875951a91.2 for ; Fri, 04 Sep 2026 01:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1788511437; x=1789116237; darn=lists.infradead.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=KKk9MsFCuRaE3YN06XOCWIV3dU/ufhZe2dVPkS7i8qI=; b=PHN3jL3qXyz9rtmTMSgI6t9y7WQNDoQ2aEx4cCJh5RUJLSfwYkNb6/CjPhBvnzlX9d LA3WRzK6WPADMGBVnTYG/7g+Z6zvEgKhpMTZ/Kjl6EwCT5B1Fi57Gvt4TO6ovVB3uBN0 sH+5LWGZdy5DZNsDb9Voyves8eKUJA+la9wJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788511437; x=1789116237; 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=KKk9MsFCuRaE3YN06XOCWIV3dU/ufhZe2dVPkS7i8qI=; b=e6j5XYZyTNG2AiZwNEXbrLdBOvpHxZFGLcEVwQ1VDLhGRkcL3BSbtpIgp1wia+qGpr M52TnL1p0Kd6+ZCx26xOWTqDwSW6f1JVEDAXQxWqwuEql427KakBK2fY8IpigHLUhIH8 8e3BlwJIG3GwWfgQsFyTQi1LJYfr5pt1E+u/RBVl5hOpPr72vo8LlXxLT+8D8E1hOS/+ siEYcTe/wCqZc6r9wsyJnLldiODDkOsfI6ghiTucM4iEAhtvZfY7R8SeJnQ5QUDgy1Gp zXCFJNN+EBzrniNhTAgNwE4glCyBEek7D2JwuRgCqsmySYjLSiH4//N8D/86f1oFW2lh KbzA== X-Forwarded-Encrypted: i=1; AKwUvBygX7Z42firnyR1rxg0Mb1/NMCQZn5DrQ9DhGWWZ1mNSuoFLndZK3uDMIy/YRrtkj2l5A9pweTXfo0wHpZqTA==@lists.infradead.org X-Gm-Message-State: AFuF++m+ctCuQKYdvCgfGqTUmKWjBNDJxYewRkIfNl2PP+DW4/xmAPhh JdDqNdGRC5tZceA1JrOYdGr4Ki9zUCoQfZ5txCqsWSqY1SDtYpawrWFjA+3sd83FDw== X-Gm-Gg: AYBFou01aYmJ4EXd0As5DnHqTz2O/SEcWcRyplhwscXByMMIG3WUfJm9pztTZARHYrV x4S4Atet6PEIRgyIMPevJnrhGeIs+oujzzBaWn8MHYqQgudo2Klor+butt6d1XbXDY0YGt67JCO z+/BVgEiG/ETrnR3NaSKXKtohuy6w9uHeNapJzq8I6rJgIzIx800B5yrRGMMUKM3Nn1p6vJY0QL rmIvGyzRcTwDPPn7y+65QvW6OE4mxoofHilFQgxVJ4G9/vql2vzHOBEaVLxsFGdj3PtZOKmBaon PHbrC8KneUc09p+RcBz3v2MUvLSTnV5sCHXo6nbhqKjkVNcjO1MynsrbFspBQ3AKNRKa5AGIbCa Cz6/kYPYqnnFADWedqCLf+ihVcKP0Gk77WIXKNhEozlgb6vnjaNn0DH+776KzUk1PhfkJmMOgpO x7jSFp/enH76S0fGeynsQU51oN0tdM1P9wn7gakJr33exBLr71mkSs9Yh+eFYYsppzKGsYqJkvG jLoxxWsx6V20pPn+f2kx9cDVqxBPNkRIxdkowPE/qRp X-Received: by 2002:a17:90a:d004:b0:398:c9be:cca8 with SMTP id 98e67ed59e1d1-39b2609f363mr7918987a91.2.1788511436740; Fri, 04 Sep 2026 01:43:56 -0700 (PDT) Received: from wenst-7875.tpe.corp.google.com ([2a00:79e0:201d:8:343:bf21:3095:9c5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b260fdf9asm3343538a91.9.2026.09.04.01.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 01:43:56 -0700 (PDT) From: Chen-Yu Tsai To: Bartosz Golaszewski , Greg Kroah-Hartman , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Danilo Krummrich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: Wei Deng , Konrad Dybcio , Chen-Yu Tsai , linux-acpi@vger.kernel.org, driver-core@lists.linux.dev, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam , Alan Stern , Bartosz Golaszewski Subject: [PATCH v8 07/16] usb: core: Move struct usb_port and related APIs to port.h Date: Fri, 4 Sep 2026 16:41:46 +0800 Message-ID: <20260904084158.1341550-8-wenst@chromium.org> X-Mailer: git-send-email 2.55.0.979.g7e5102b832-goog In-Reply-To: <20260904084158.1341550-1-wenst@chromium.org> References: <20260904084158.1341550-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260904_014357_785889_3AC30CDB X-CRM114-Status: GOOD ( 25.28 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org |struct usb_port| and its matching container_of() macro should live in its own port.h, matching the split we have for .c files. Move them as described. Also move usb_port_is_power_on(), since in the next change its |struct usb_hub *| parameter will be changed to |struct usb_port *|, and becomes a non-static function that only references |struct usb_port|. port.h is only included from hub.h, as a subsequent patch will directly use fields from |struct usb_port| in a static inline helper in hub.h. The USB internal headers don't have header guards to help with this. Also drop 'extern' from the header declaration of usb_port_is_power_on(). This is not needed in modern C. Suggested-by: Andy Shevchenko Reviewed-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko Signed-off-by: Chen-Yu Tsai --- Changes since v4: - Dropped 'extern' (Andy) Changes since v3: - New patch (Andy) --- drivers/usb/core/hub.c | 16 ---------- drivers/usb/core/hub.h | 48 ++--------------------------- drivers/usb/core/port.c | 16 ++++++++++ drivers/usb/core/port.h | 68 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 62 deletions(-) create mode 100644 drivers/usb/core/port.h diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index c19c9912c740..7f58d753d77a 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3243,22 +3243,6 @@ static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) return port_dev->ignore_event; } -/* Check if a port is power on */ -int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) -{ - int ret = 0; - - if (hub_is_superspeed(hub->hdev)) { - if (portstatus & USB_SS_PORT_STAT_POWER) - ret = 1; - } else { - if (portstatus & USB_PORT_STAT_POWER) - ret = 1; - } - - return ret; -} - static void usb_lock_port(struct usb_port *port_dev) __acquires(&port_dev->status_lock) { diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 9ebc5ef54a32..de524c6da9fc 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -15,7 +15,9 @@ #include #include #include + #include "usb.h" +#include "port.h" struct usb_hub { struct device *intfdev; /* the "interface" device */ @@ -78,51 +80,6 @@ struct usb_hub { struct list_head onboard_devs; }; -/** - * struct usb port - kernel's representation of a usb port - * @child: usb device attached to the port - * @dev: generic device interface - * @port_owner: port's owner - * @peer: related usb2 and usb3 ports (share the same connector) - * @connector: USB Type-C connector - * @req: default pm qos request for hubs without port power control - * @connect_type: port's connect type - * @state: device state of the usb device attached to the port - * @state_kn: kernfs_node of the sysfs attribute that accesses @state - * @location: opaque representation of platform connector location - * @status_lock: synchronize port_event() vs usb_port_{suspend|resume} - * @portnum: port index num based one - * @is_superspeed cache super-speed status - * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted. - * @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. - */ -struct usb_port { - struct usb_device *child; - struct device dev; - struct usb_dev_state *port_owner; - struct usb_port *peer; - struct typec_connector *connector; - struct dev_pm_qos_request *req; - enum usb_port_connect_type connect_type; - enum usb_device_state state; - struct kernfs_node *state_kn; - usb_port_location_t location; - struct mutex status_lock; - u32 over_current_count; - u8 portnum; - u32 quirks; - unsigned int early_stop:1; - unsigned int ignore_event:1; - unsigned int is_superspeed:1; - unsigned int usb3_lpm_u1_permit:1; - unsigned int usb3_lpm_u2_permit:1; -}; - -#define to_usb_port(_dev) \ - container_of(_dev, struct usb_port, dev) - extern int usb_hub_create_port_device(struct usb_hub *hub, int port1); extern void usb_hub_remove_port_device(struct usb_hub *hub, @@ -138,7 +95,6 @@ extern int usb_clear_port_feature(struct usb_device *hdev, int port1, int feature); extern int usb_hub_port_status(struct usb_hub *hub, int port1, u16 *status, u16 *change); -extern int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus); static inline bool hub_is_port_power_switchable(struct usb_hub *hub) { diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index c0a51d9b06a6..b2e953f137f8 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -22,6 +22,22 @@ static int usb_port_block_power_off; static const struct attribute_group *port_dev_group[]; +/* Check if a port is power on */ +int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) +{ + int ret = 0; + + if (hub_is_superspeed(hub->hdev)) { + if (portstatus & USB_SS_PORT_STAT_POWER) + ret = 1; + } else { + if (portstatus & USB_PORT_STAT_POWER) + ret = 1; + } + + return ret; +} + static bool usb_port_allow_power_off(struct usb_device *hdev, struct usb_hub *hub, struct usb_port *port_dev) diff --git a/drivers/usb/core/port.h b/drivers/usb/core/port.h new file mode 100644 index 000000000000..00f7500af336 --- /dev/null +++ b/drivers/usb/core/port.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * usb hub driver head file + * + * Copyright (C) 1999 Linus Torvalds + * Copyright (C) 1999 Johannes Erdfelt + * Copyright (C) 1999 Gregory P. Smith + * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au) + * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com) + * + * move struct usb_port to this file. + */ + +#include +#include +#include +#include + +#include + +/** + * struct usb port - kernel's representation of a usb port + * @child: usb device attached to the port + * @dev: generic device interface + * @port_owner: port's owner + * @peer: related usb2 and usb3 ports (share the same connector) + * @connector: USB Type-C connector + * @req: default pm qos request for hubs without port power control + * @connect_type: port's connect type + * @state: device state of the usb device attached to the port + * @state_kn: kernfs_node of the sysfs attribute that accesses @state + * @location: opaque representation of platform connector location + * @status_lock: synchronize port_event() vs usb_port_{suspend|resume} + * @portnum: port index num based one + * @is_superspeed cache super-speed status + * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted. + * @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. + */ +struct usb_port { + struct usb_device *child; + struct device dev; + struct usb_dev_state *port_owner; + struct usb_port *peer; + struct typec_connector *connector; + struct dev_pm_qos_request *req; + enum usb_port_connect_type connect_type; + enum usb_device_state state; + struct kernfs_node *state_kn; + usb_port_location_t location; + struct mutex status_lock; + u32 over_current_count; + u8 portnum; + u32 quirks; + unsigned int early_stop:1; + unsigned int ignore_event:1; + unsigned int is_superspeed:1; + unsigned int usb3_lpm_u1_permit:1; + unsigned int usb3_lpm_u2_permit:1; +}; + +#define to_usb_port(_dev) \ + container_of(_dev, struct usb_port, dev) + +struct usb_hub; + +int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus); -- 2.55.0.979.g7e5102b832-goog