From patchwork Wed Nov 24 23:10:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12638037 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CEF6C433F5 for ; Wed, 24 Nov 2021 23:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345029AbhKXXO7 (ORCPT ); Wed, 24 Nov 2021 18:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243588AbhKXXO7 (ORCPT ); Wed, 24 Nov 2021 18:14:59 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD14C061574 for ; Wed, 24 Nov 2021 15:11:48 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so6247327pjb.2 for ; Wed, 24 Nov 2021 15:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TE1Z/Xi+OjPPDx97RwQJKa7AShoD/XLwj4AePbmASlU=; b=F/XCG8n1Soe5ZK62nwbIDpsjeqSHRKrNr9+ZOSH3olHwakVVyfgjNlwEzZ9dz6pL6D mf1pUbV0feoeL66wRtyKbdbyq+5cju3VW2bfzLX19BlF8BtEHWp1Efup6DZq5c13/yCD Qqz/njkA0f53UNVXVjvIF0C3UH1Y1nMSAGUgQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TE1Z/Xi+OjPPDx97RwQJKa7AShoD/XLwj4AePbmASlU=; b=mo4ZMFauoZS+D1quFbZJIppiPyPi5k/LGqm3EPz+wQhEgYtAlGr0q72xY8FmbBF7Zt cCiaNqtOB9o6VDajm+/KYfeENk/ZYk+TWzfw3bUKDlrlPECIyWcv4wb5n3oMED5PBKOa u6tfLvehZA0Xih9olp0FgLKi3jxV2THkwxN46x1kwlFLFtRCBAtF8+TjSwLuQjl++H+x WHrBRn5CSUaew8XDTjpFbl8zaSfjiFuVtZNdkmSe9kCPq9a9tQwpIkJOAu+B4/MDBSgd YE64pTJD0M33UHk5bsJaKQRCKarMlLOtHn+jbojaDrgcJ6Ucn5rVJJ4wBn3xeEofLbel UpHg== X-Gm-Message-State: AOAM532BlgkjGDgt8Pgr091HizQ7Toak5/PPbV6Uc1yyCgLFHDTIOT4/ P4oxLX0T/1Kj7fetN40g71AehQ== X-Google-Smtp-Source: ABdhPJxVRfQ1dfuT+6moICN/yNXN7KqyJjWOBBOC/GNduuV7aRk56mOyLufWL0e5A6GeRsI3Z4tHEA== X-Received: by 2002:a17:90b:3a89:: with SMTP id om9mr1024253pjb.29.1637795508361; Wed, 24 Nov 2021 15:11:48 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:6bc9:896a:9df2:5d61]) by smtp.gmail.com with ESMTPSA id nn15sm5783296pjb.11.2021.11.24.15.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 15:11:48 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: wonchung@google.com, bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Alan Stern , Bjorn Helgaas , =?utf-8?q?Christian_K=C3=B6nig?= , Chunfeng Yun , Daniel Vetter , Greg Kroah-Hartman , Maarten Lankhorst , Mauro Carvalho Chehab , Rajat Jain , Rikard Falkeborn , Thomas Zimmermann Subject: [PATCH 1/4] usb: typec: Add port registration notifier Date: Wed, 24 Nov 2021 15:10:08 -0800 Message-Id: <20211124231028.696982-2-pmalani@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211124231028.696982-1-pmalani@chromium.org> References: <20211124231028.696982-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Introduce a blocking notifier to be called when a new Type C port gets registered with the connector class framework. Signed-off-by: Prashant Malani --- NOTE: typec_port_registration_register_notify() is a bit long, so please let me know if you have any shorter suggestions for naming this function. drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index aeef453aa658..14b82109b0f5 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -16,6 +16,8 @@ #include "bus.h" #include "class.h" +static BLOCKING_NOTIFIER_HEAD(typec_port_registration_notifier); + static DEFINE_IDA(typec_index_ida); struct class typec_class = { @@ -1979,6 +1981,32 @@ void typec_port_register_altmodes(struct typec_port *port, } EXPORT_SYMBOL_GPL(typec_port_register_altmodes); +/** + * typec_port_registration_register_notify - Register a notifier for Type C port registration. + * @nb: notifier block to signal + * + * This function allows callers to get a notification when a Type C port is registered with + * the connector class. + */ +int typec_port_registration_register_notify(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&typec_port_registration_notifier, nb); +} +EXPORT_SYMBOL_GPL(typec_port_registration_register_notify); + +/** + * typec_port_registration_unregister_notify - Unregister a notifier for Type C port registration. + * @nb: notifier block to unregister + * + * This function allows callers to unregister notifiers which were previously registered using + * typec_port_registration_register_notify(). + */ +int typec_port_registration_unregister_notify(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&typec_port_registration_notifier, nb); +} +EXPORT_SYMBOL_GPL(typec_port_registration_unregister_notify); + /** * typec_register_port - Register a USB Type-C Port * @parent: Parent device @@ -2086,6 +2114,8 @@ struct typec_port *typec_register_port(struct device *parent, if (ret) dev_warn(&port->dev, "failed to create symlinks (%d)\n", ret); + blocking_notifier_call_chain(&typec_port_registration_notifier, 0, port); + return port; } EXPORT_SYMBOL_GPL(typec_register_port); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index e2e44bb1dad8..398317835f24 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -3,6 +3,7 @@ #ifndef __LINUX_USB_TYPEC_H #define __LINUX_USB_TYPEC_H +#include #include /* USB Type-C Specification releases */ @@ -308,6 +309,8 @@ int typec_get_negotiated_svdm_version(struct typec_port *port); #if IS_REACHABLE(CONFIG_TYPEC) int typec_link_port(struct device *port); void typec_unlink_port(struct device *port); +int typec_port_registration_register_notify(struct notifier_block *nb); +int typec_port_registration_unregister_notify(struct notifier_block *nb); #else static inline int typec_link_port(struct device *port) { @@ -315,6 +318,16 @@ static inline int typec_link_port(struct device *port) } static inline void typec_unlink_port(struct device *port) { } + +int typec_port_registration_register_notify(struct notifier_block *nb) +{ + return 0; +} + +int typec_port_registration_unregister_notify(struct notifier_block *nb) +{ + return 0; +} #endif #endif /* __LINUX_USB_TYPEC_H */ From patchwork Wed Nov 24 23:10:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12638039 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4AEAC433EF for ; Wed, 24 Nov 2021 23:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345630AbhKXXQN (ORCPT ); Wed, 24 Nov 2021 18:16:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345677AbhKXXQM (ORCPT ); Wed, 24 Nov 2021 18:16:12 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34238C06173E for ; Wed, 24 Nov 2021 15:13:02 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id h24so3708379pjq.2 for ; Wed, 24 Nov 2021 15:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p9YGerqoefD7Kts4SrR1JKCEyJYREPcX0RCli6jZVLo=; b=P+HEnFYFrSgu9DmzxwoNZej8aaK4wtElTc2pfAd9getl1nTeIDH7k6Ujnf4Qe/lvtB 3VWvSdLA20BLQFeEWByMUDt7OnfYIvwe7dAf2KIIOzns9utPUOUnoI1JIdJ8WjYqs7aL YhgftWcSZG028MVbmLvi98CcwXsDW981ndGJI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p9YGerqoefD7Kts4SrR1JKCEyJYREPcX0RCli6jZVLo=; b=cbCeVV8x7am/YUKs7IE2vT8LANLDl8Qc714pqxUON3qO+edJ7FgIaeFh8lxp8P90Qw hsyk9ktosr+YwXMKcTfM1KlUncZf90JSGdr6FYzYdub+zoCuzDZhVbgWY2S0bW6mXQ9J mNlz59vb2EZsUYw6Tz8SNv/Z8pVivymUYHiuKVMs8B+3j8s3RkXMYP6fumGlyR/MHv+4 yRFaqeLCzcq3De1L3xXcY7jdWJeM8wAfyDc+izudcPEW0rdNxvuiZTnhzt0jn6NfsXHr 1MoyvSddRYqcesIOaMHJunAv1+W4rikGVTDqgazg1H5+/hroUCTQie1jBD7oI9KIg44q v14A== X-Gm-Message-State: AOAM530WIqX3DwCyN3Y7R9MvdHOYFh40T32srYp2NjXwVHnFchD+9poX KOGW6CgH99vuT0WPoXYRDfL+4w== X-Google-Smtp-Source: ABdhPJzFiur+ikn5j3/xC2xNZcWgPnyRI4rHIn/Hp8HKsDF39OSVH7tnd5yZ91o7i2fK+BCHn+VC/Q== X-Received: by 2002:a17:902:d4c2:b0:142:2039:e8e5 with SMTP id o2-20020a170902d4c200b001422039e8e5mr24031027plg.18.1637795581629; Wed, 24 Nov 2021 15:13:01 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:6bc9:896a:9df2:5d61]) by smtp.gmail.com with ESMTPSA id nn15sm5783296pjb.11.2021.11.24.15.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 15:13:01 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: wonchung@google.com, bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Alan Stern , Bjorn Helgaas , Chunfeng Yun , Greg Kroah-Hartman , Maarten Lankhorst , Mauro Carvalho Chehab , Rajat Jain , Rikard Falkeborn , Thomas Zimmermann Subject: [PATCH 2/4] usb: Use notifier to link Type C ports Date: Wed, 24 Nov 2021 15:10:10 -0800 Message-Id: <20211124231028.696982-3-pmalani@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211124231028.696982-1-pmalani@chromium.org> References: <20211124231028.696982-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Instead of using a helper function to register pre-existing USB ports to a new type C port, have each port register a notifier with the Type C connector class, and use that to perform the linking when a new Type C port is registered. This avoid a cyclic dependency from a later change which is needed to link a new USB port to a pre-existing Type C port. Some context on this is in here [1]; in summary, typec_link_ports() introduces a dependency from typec -> usbcore. However, commit 63cd78617350 ("usb: Link the ports to the connectors they are attached to") then introduces a dependency from usbcore -> typec. In order to allow that commit without creating the cyclic dependency, we use a notifier here instead of typec_link_ports(). Since we don't need the helper typec_link_ports() function anymore, remove it and its related functions from port-mapper code. [1]: https://lore.kernel.org/all/20210412213655.3776e15e@canb.auug.org.au/ Cc: Benson Leung Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reported-by: kernel test robot --- drivers/usb/core/hub.h | 3 +++ drivers/usb/core/port.c | 18 +++++++++++++++ drivers/usb/typec/class.c | 5 +--- drivers/usb/typec/class.h | 1 - drivers/usb/typec/port-mapper.c | 41 --------------------------------- 5 files changed, 22 insertions(+), 46 deletions(-) diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 22ea1f4f2d66..d09a8c9c1b4e 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -11,6 +11,7 @@ * move struct usb_hub to this file. */ +#include #include #include #include @@ -89,6 +90,7 @@ struct usb_hub { * @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. + * @typec_nb: notifier called when a Type C port is registered. */ struct usb_port { struct usb_device *child; @@ -105,6 +107,7 @@ struct usb_port { unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1; + struct notifier_block typec_nb; }; #define to_usb_port(_dev) \ diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index dfcca9c876c7..53a64ce76183 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -9,6 +9,7 @@ #include #include +#include #include "hub.h" @@ -528,6 +529,14 @@ static void find_and_link_peer(struct usb_hub *hub, int port1) link_peers_report(port_dev, peer); } +static int usb_port_link_typec_port(struct notifier_block *nb, unsigned long event, void *ptr) +{ + struct usb_port *port_dev = container_of(nb, struct usb_port, typec_nb); + + typec_link_port(&port_dev->dev); + return NOTIFY_OK; +} + int usb_hub_create_port_device(struct usb_hub *hub, int port1) { struct usb_port *port_dev; @@ -577,6 +586,14 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) find_and_link_peer(hub, port1); + /* + * In some cases, the Type C port gets registered later, so + * register a Type C notifier so that we can link the ports + * later too. + */ + port_dev->typec_nb.notifier_call = usb_port_link_typec_port; + typec_port_registration_register_notify(&port_dev->typec_nb); + /* * Enable runtime pm and hold a refernce that hub_configure() * will drop once the PM_QOS_NO_POWER_OFF flag state has been set @@ -616,6 +633,7 @@ void usb_hub_remove_port_device(struct usb_hub *hub, int port1) struct usb_port *port_dev = hub->ports[port1 - 1]; struct usb_port *peer; + typec_port_registration_unregister_notify(&port_dev->typec_nb); peer = port_dev->peer; if (peer) unlink_peers(port_dev, peer); diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 14b82109b0f5..92d03eb65f12 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -2110,10 +2110,7 @@ struct typec_port *typec_register_port(struct device *parent, return ERR_PTR(ret); } - ret = typec_link_ports(port); - if (ret) - dev_warn(&port->dev, "failed to create symlinks (%d)\n", ret); - + /* Used to allow USB ports to register to this Type C port */ blocking_notifier_call_chain(&typec_port_registration_notifier, 0, port); return port; diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index aef03eb7e152..517236935a55 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -79,7 +79,6 @@ extern const struct device_type typec_port_dev_type; extern struct class typec_mux_class; extern struct class typec_class; -int typec_link_ports(struct typec_port *connector); void typec_unlink_ports(struct typec_port *connector); #endif /* __USB_TYPEC_CLASS__ */ diff --git a/drivers/usb/typec/port-mapper.c b/drivers/usb/typec/port-mapper.c index 9b0991bdf391..5597291bd769 100644 --- a/drivers/usb/typec/port-mapper.c +++ b/drivers/usb/typec/port-mapper.c @@ -7,7 +7,6 @@ */ #include -#include #include #include "class.h" @@ -220,46 +219,6 @@ void typec_unlink_port(struct device *port) } EXPORT_SYMBOL_GPL(typec_unlink_port); -static int each_port(struct device *port, void *connector) -{ - struct port_node *node; - int ret; - - node = create_port_node(port); - if (IS_ERR(node)) - return PTR_ERR(node); - - if (!connector_match(connector, node)) { - remove_port_node(node); - return 0; - } - - ret = link_port(to_typec_port(connector), node); - if (ret) { - remove_port_node(node->pld); - return ret; - } - - get_device(connector); - - return 0; -} - -int typec_link_ports(struct typec_port *con) -{ - int ret = 0; - - con->pld = get_pld(&con->dev); - if (!con->pld) - return 0; - - ret = usb_for_each_port(&con->dev, each_port); - if (ret) - typec_unlink_ports(con); - - return ret; -} - void typec_unlink_ports(struct typec_port *con) { struct port_node *node; From patchwork Wed Nov 24 23:10:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12638067 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B025C433F5 for ; Wed, 24 Nov 2021 23:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345679AbhKXXQu (ORCPT ); Wed, 24 Nov 2021 18:16:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343729AbhKXXQu (ORCPT ); Wed, 24 Nov 2021 18:16:50 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04742C061574 for ; Wed, 24 Nov 2021 15:13:40 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso4141619pjb.0 for ; Wed, 24 Nov 2021 15:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=crfmL1J6lNLWpnWCWXe3wcSd/BVJQ67tS3gvAa/yZ9k=; b=CJTj/xgmNxZ3D75A0X2jyMsMkrSTFZj+f+vK9T04i4SSA9SulyowzIs7iwE7ogIPBp wp0IzcRdZyK3t/8nrDqQQC+dLMmfr6N+d8vKjAxLPFkVfMMXoVUObvAxQWzSBk5aGD7e t2/OpKxzd6tQTtFDjO8M2uaTrSmSPaT6j7Pws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=crfmL1J6lNLWpnWCWXe3wcSd/BVJQ67tS3gvAa/yZ9k=; b=6AWrnkZZr2WOHARUpaZ3246snKt4mU7iwS3PuUfGv140jwMJySbLKkPicfpT04ZliG 7+FW/tKzTGQiN3AUGY97nYA/MFHMMmGfJgrjn3Z9v2IwAKh3lCDE3tjhtxa+TecW4ULz S6Tuj8cTdjtRUib6saEhU7i2ejQeoG1d43UNJQY3zowWJFQkJT8Huatk986+EH1xrown T34YGZHRLz2dyg2AHLR82nO/cooMqYdV5aRoNXaPJWPAebephsszBMe7gtm9hwi77Tzm aCzvcBynHWx4tP/MmWSPM9Zr5nyJpN2a9GrDssd0jD1fHzx0NXDmX9X1/2OdnqRSS2BC 31gw== X-Gm-Message-State: AOAM533jSfK0Gfs0HsKhrYX8MLs2OtwQhVCWY7erEEdj94wRdwpiOKwl VHih69YDFyVbInjbyudIZl8A1w== X-Google-Smtp-Source: ABdhPJwlSMYGZvrizyh+vZims2TLlvTVoP1eP2z8MqzlHVbYSDf+4IcIcxbIMzTPxghHMqjLpykWug== X-Received: by 2002:a17:903:10d:b0:142:6343:a48e with SMTP id y13-20020a170903010d00b001426343a48emr23518670plc.29.1637795619570; Wed, 24 Nov 2021 15:13:39 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:6bc9:896a:9df2:5d61]) by smtp.gmail.com with ESMTPSA id nn15sm5783296pjb.11.2021.11.24.15.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 15:13:39 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: wonchung@google.com, bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Greg Kroah-Hartman , Mauro Carvalho Chehab , Bjorn Helgaas , Rajat Jain , Rikard Falkeborn Subject: [PATCH 3/4] usb: Link the ports to the connectors they are attached to Date: Wed, 24 Nov 2021 15:10:12 -0800 Message-Id: <20211124231028.696982-4-pmalani@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211124231028.696982-1-pmalani@chromium.org> References: <20211124231028.696982-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Heikki Krogerus Creating link to the USB Type-C connector for every new port that is added when possible. Originally submitted as commit 63cd78617350 ("usb: Link the ports to the connectors they are attached to") but later reverted in commit 5bdb080f9603 ("Revert "usb: Link the ports to the connectors they are attached to"") due to a cyclic module dependency, which has since been resolved. Signed-off-by: Heikki Krogerus Signed-off-by: Prashant Malani --- Documentation/ABI/testing/sysfs-bus-usb | 9 +++++++++ drivers/usb/core/port.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb index 2ebe5708b4bc..a017cf610d9b 100644 --- a/Documentation/ABI/testing/sysfs-bus-usb +++ b/Documentation/ABI/testing/sysfs-bus-usb @@ -244,6 +244,15 @@ Description: is permitted, "u2" if only u2 is permitted, "u1_u2" if both u1 and u2 are permitted. +What: /sys/bus/usb/devices/.../(hub interface)/portX/connector +Date: April 2021 +Contact: Heikki Krogerus +Description: + Link to the USB Type-C connector when available. This link is + only created when USB Type-C Connector Class is enabled, and + only if the system firmware is capable of describing the + connection between a port and its connector. + What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout Date: May 2013 Contact: Mathias Nyman diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 53a64ce76183..83f5eac6691c 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -585,6 +585,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) } find_and_link_peer(hub, port1); + typec_link_port(&port_dev->dev); /* * In some cases, the Type C port gets registered later, so @@ -637,5 +638,6 @@ void usb_hub_remove_port_device(struct usb_hub *hub, int port1) peer = port_dev->peer; if (peer) unlink_peers(port_dev, peer); + typec_unlink_port(&port_dev->dev); device_unregister(&port_dev->dev); } From patchwork Wed Nov 24 23:10:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12638069 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4E61C433F5 for ; Wed, 24 Nov 2021 23:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345990AbhKXXRO (ORCPT ); Wed, 24 Nov 2021 18:17:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344034AbhKXXRN (ORCPT ); Wed, 24 Nov 2021 18:17:13 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76AA8C06173E for ; Wed, 24 Nov 2021 15:14:03 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id c4so4101983pfj.2 for ; Wed, 24 Nov 2021 15:14:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s+U5SGOWryCFsIXc1FRU37Odr/vxnrrGVzlEIkyDYMM=; b=RkqLqi5X48t2gyoiWTDVOTX0uqmzLpSN1ZxHRwxnjvrU13N+E1TbvrOGpnx+MZ5yZn FgiWfqJBe3s66EQrJewh5mIfREL4qivKJCjo3tKD7yjV+AziYYRVTKIb555MC7NwJxzK fi3cDpi0RWibTKK8DzcbBKDSTHs7YLdh5kCTI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s+U5SGOWryCFsIXc1FRU37Odr/vxnrrGVzlEIkyDYMM=; b=cb3GwU4i2TnZBkeLbG2vZM0jICLU38raLKTrAFI1/tB/QKKtKS1bHmf3MgmWwKuU1W xDbSvVsej7+F62zh8DwXpXPyKK8wG042sMpNM+zP5dK33N4ybRGh8mZ6g37jJXyEydc5 osVnZSdhrVMrE9GMg4wY7A8RH+Pt2askVKUTHTZwlWws3LK9crdugD9c/2AtIwfj3ywb W5+bUlrmZsROha3sT5RjOsRhNm86fUHaNAXaS4ZZ19WtMvcqEEFilyaza6gbqtBw5olJ d0+iOBEfO5BoAcDaoWWyNMI1Yfm+3ARw8atfb53GYRK8be7xx3Y/LHBmt1Y0AVICqDIN q38A== X-Gm-Message-State: AOAM532tsJSU6y0DaPP2Rdlpmldw+zRik5hAf1TiDOM+8QZ0zgAFzhQ3 UzD12AbnrP9Dd+GcgCUrNqofIg== X-Google-Smtp-Source: ABdhPJzhRfP74wbcFqjtZ97Uq9fzfvncJBvUhnd8kKdjYwn68j4g5nYZ6AufpOFut2igocB20dVotQ== X-Received: by 2002:a65:648b:: with SMTP id e11mr12997512pgv.138.1637795643090; Wed, 24 Nov 2021 15:14:03 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:6bc9:896a:9df2:5d61]) by smtp.gmail.com with ESMTPSA id nn15sm5783296pjb.11.2021.11.24.15.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 15:14:02 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: wonchung@google.com, bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Greg Kroah-Hartman , Thomas Zimmermann , Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 4/4] Revert "usb: Iterator for ports" Date: Wed, 24 Nov 2021 15:10:14 -0800 Message-Id: <20211124231028.696982-5-pmalani@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211124231028.696982-1-pmalani@chromium.org> References: <20211124231028.696982-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit b433c4c789d612cf58739a772bbddbd949bafd20. We no longer use typec_link_ports() to link a newly registered Type C port to pre-existing USB ports, so we don't need this iterator anymore. Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- drivers/usb/core/usb.c | 46 ------------------------------------------ include/linux/usb.h | 9 --------- 2 files changed, 55 deletions(-) diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 62368c4ed37a..2ce3667ec6fa 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -398,52 +398,6 @@ int usb_for_each_dev(void *data, int (*fn)(struct usb_device *, void *)) } EXPORT_SYMBOL_GPL(usb_for_each_dev); -struct each_hub_arg { - void *data; - int (*fn)(struct device *, void *); -}; - -static int __each_hub(struct usb_device *hdev, void *data) -{ - struct each_hub_arg *arg = (struct each_hub_arg *)data; - struct usb_hub *hub; - int ret = 0; - int i; - - hub = usb_hub_to_struct_hub(hdev); - if (!hub) - return 0; - - mutex_lock(&usb_port_peer_mutex); - - for (i = 0; i < hdev->maxchild; i++) { - ret = arg->fn(&hub->ports[i]->dev, arg->data); - if (ret) - break; - } - - mutex_unlock(&usb_port_peer_mutex); - - return ret; -} - -/** - * usb_for_each_port - interate over all USB ports in the system - * @data: data pointer that will be handed to the callback function - * @fn: callback function to be called for each USB port - * - * Iterate over all USB ports and call @fn for each, passing it @data. If it - * returns anything other than 0, we break the iteration prematurely and return - * that value. - */ -int usb_for_each_port(void *data, int (*fn)(struct device *, void *)) -{ - struct each_hub_arg arg = {data, fn}; - - return usb_for_each_dev(&arg, __each_hub); -} -EXPORT_SYMBOL_GPL(usb_for_each_port); - /** * usb_release_dev - free a usb device structure when all users of it are finished. * @dev: device that's been disconnected diff --git a/include/linux/usb.h b/include/linux/usb.h index 7ccaa76a9a96..200b7b79acb5 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -875,15 +875,6 @@ extern struct usb_host_interface *usb_find_alt_setting( unsigned int iface_num, unsigned int alt_num); -#if IS_REACHABLE(CONFIG_USB) -int usb_for_each_port(void *data, int (*fn)(struct device *, void *)); -#else -static inline int usb_for_each_port(void *data, int (*fn)(struct device *, void *)) -{ - return 0; -} -#endif - /* port claiming functions */ int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, struct usb_dev_state *owner);