Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp523763pxb; Thu, 26 Aug 2021 08:21:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym1k0FRNod+JrDSo+dTjgOM3vpYd02qY1mpcnZtWlGdHcAGnKrjQiR5C/vFYS8aOF1YTEM X-Received: by 2002:a17:906:4a8e:: with SMTP id x14mr4898647eju.389.1629991290193; Thu, 26 Aug 2021 08:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629991290; cv=none; d=google.com; s=arc-20160816; b=jTTSke4vhHIXIisI1ZUuLIe+2qe0vHUJmpfbHfcB17vdicg0Y4ke4c44m3T3CsUC3V 7csMEJ8wEA7eEjHifp+CE0A8wF6K4xWqu532dm5dMXq4YHadnvIXme4AjO7RlgYAHs/y axYjUqiD+r7PJyLBtQ/uobpWhB4UbGcZk09iO0L1hh48nmp3b48OnclxLeFmce3bhvAU hILNsqD18FV0yxdt0kPh8dZSL1U3qhMPsProyryD6LS0+30SuAnRSywyQ+X3rTdLa9Qn aAH627z+k/AmMh74U6YRcIOXE0NDUE5mzi8yiM0Gp23YjJbs/fQcpNSBJ2E8ByaXfjLE bxzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=7QqxKoBssWgK4ESt8Yez37IY+Gq1Qh3nuyCDuUe6Gys=; b=MtsL3IwCm+YxLz8//NG+aqzq3ExDvGADrhokhtdlF06vnwJsHW6KrIb12oUrfz2zXO WP0a7lXDdU21j6nr9FJaawHvHEmk54iCl1TOf64i305prYgUN3deV+keqkyNZZIf3Fwk Txg22lPYvUoHWoAQ+Q+1lnTvxZ8Ebh82FAASo8QJabdzZMAORAOgYmTAluytLTUMPLaM r+5lrzold1BU0CPEfAmKOunXcNjXltw6m6w3Bl7MS+vFukv622ATJPQ8/afvoucFv8uU 0qH39ufAHNZZrofwZykRBX9Fw2SXafqSejNphd2Vr/jPHco0cE+MgYlsrvGvHFpGqDhB nQ9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si3537870ejy.739.2021.08.26.08.20.32; Thu, 26 Aug 2021 08:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242886AbhHZPRR (ORCPT + 99 others); Thu, 26 Aug 2021 11:17:17 -0400 Received: from netrider.rowland.org ([192.131.102.5]:44115 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S232291AbhHZPRQ (ORCPT ); Thu, 26 Aug 2021 11:17:16 -0400 Received: (qmail 230172 invoked by uid 1000); 26 Aug 2021 11:16:23 -0400 Date: Thu, 26 Aug 2021 11:16:23 -0400 From: Alan Stern To: Kishon Vijay Abraham I Cc: Greg Kroah-Hartman , Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chris.chiu@canonical.com, lokeshvutla@ti.com Subject: Re: [PATCH v2 2/3] usb: core: hcd: Add support for deferring roothub registration Message-ID: <20210826151623.GA228824@rowland.harvard.edu> References: <20210826111426.751-1-kishon@ti.com> <20210826111426.751-3-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210826111426.751-3-kishon@ti.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021 at 04:44:25PM +0530, Kishon Vijay Abraham I wrote: > It has been observed with certain PCIe USB cards (like Inateck connected > to AM64 EVM or J7200 EVM) that as soon as the primary roothub is > registered, port status change is handled even before xHC is running > leading to cold plug USB devices not detected. For such cases, registering > both the root hubs along with the second HCD is required. Add support for > deferring roothub registration in usb_add_hcd(), so that both primary and > secondary roothubs are registered along with the second HCD. > > Signed-off-by: Kishon Vijay Abraham I > Suggested-by: Mathias Nyman > Tested-by: Chris Chiu > --- I should have noticed this problem before... > drivers/usb/core/hcd.c | 27 ++++++++++++++++++++++----- > include/linux/usb/hcd.h | 2 ++ > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > index 00d35fe1fef0..64fdfc6692c2 100644 > --- a/drivers/usb/core/hcd.c > +++ b/drivers/usb/core/hcd.c > @@ -2795,6 +2795,7 @@ int usb_add_hcd(struct usb_hcd *hcd, > { > int retval; > struct usb_device *rhdev; > + struct usb_hcd *shared_hcd; > > if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { > hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); > @@ -2955,18 +2956,34 @@ int usb_add_hcd(struct usb_hcd *hcd, > goto err_hcd_driver_start; > } > > + /* starting here, usbcore will pay attention to the shared HCD roothub */ > + shared_hcd = hcd->shared_hcd; > + if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) { > + retval = register_root_hub(shared_hcd); > + if (retval != 0) > + goto err_register_shared_root_hub; > + > + if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) > + usb_hcd_poll_rh_status(shared_hcd); > + } > + > /* starting here, usbcore will pay attention to this root hub */ > - retval = register_root_hub(hcd); > - if (retval != 0) > - goto err_register_root_hub; > + if (!HCD_DEFER_RH_REGISTER(hcd)) { > + retval = register_root_hub(hcd); > + if (retval != 0) > + goto err_register_root_hub; > > - if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) > - usb_hcd_poll_rh_status(hcd); > + if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) > + usb_hcd_poll_rh_status(hcd); > + } > > return retval; > > err_register_root_hub: > usb_stop_hcd(hcd); > +err_register_shared_root_hub: > + if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) > + usb_stop_hcd(shared_hcd); This was added in the wrong place. It needs to come before the usb_stop_hcd(hcd) call, because usb_start_hcd(hcd) was run before we failed to register the shared hcd's root hub. Furthermore, I don't think we need to stop the shared hcd at all. At this point, the usb_add_hcd() call for the shared hcd has already returned successfully. The usb_stop_hcd(shared_hcd) callback will be made automatically when the shared hcd is unregistered later on, after this function returns an error. Come to think of it, don't we also need to modify the usb_disconnect(&rhdev) call in usb_remove_hcd() to handle the case where the root hub wasn't registered in the first place because it was deferred? At the very least, we should test the hcd's rh_registered flag before trying to unregister the root hub. Alan Stern > err_hcd_driver_start: > if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) > free_irq(irqnum, hcd); > diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h > index 548a028f2dab..2c1fc9212cf2 100644 > --- a/include/linux/usb/hcd.h > +++ b/include/linux/usb/hcd.h > @@ -124,6 +124,7 @@ struct usb_hcd { > #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ > #define HCD_FLAG_DEAD 6 /* controller has died? */ > #define HCD_FLAG_INTF_AUTHORIZED 7 /* authorize interfaces? */ > +#define HCD_FLAG_DEFER_RH_REGISTER 8 /* Defer roothub registration */ > > /* The flags can be tested using these macros; they are likely to > * be slightly faster than test_bit(). > @@ -134,6 +135,7 @@ struct usb_hcd { > #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) > #define HCD_RH_RUNNING(hcd) ((hcd)->flags & (1U << HCD_FLAG_RH_RUNNING)) > #define HCD_DEAD(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEAD)) > +#define HCD_DEFER_RH_REGISTER(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEFER_RH_REGISTER)) > > /* > * Specifies if interfaces are authorized by default > -- > 2.17.1 >