From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-1965707-1516287652-2-16808722202650801446 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, ME_NOAUTH 0.01, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org' X-Spam-charsets: plain='utf-8' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: linux-usb-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1516287651; b=mjh3gtODGcdt1KhTedGVt48B4m5LtonnuAfTeVsIhPyTcAV svZUbjF/n+QEaSLOYJ7XGQ/u54zfQortz2+1FdMhHvBkz14XKoqV91Wae6HI4+Be XWiAuXgvyWoC1kKuXZuqQRr3oHy7pAx+Opa1KmV/JbduSpEGGER0uYkyZ/4oJnDh I+SdoKrwFninNpw+zyF/9M9XPtAJCQ7fdGiyFrh7C2DwnEz7s6Z/0XwKhVLHXww5 6XJcQLBgkJUxkijgOyqIrVYpDah9OLNj9pyk9Jze7eyfe/mjJliXuRq6SDLboE6N LYJ4UxYH8o1zmsslvaQlQCqPG+vlbK9ADN/gw1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=subject:to:cc:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding:sender:list-id; s=arctest; t= 1516287651; bh=2FbAlA6GK/aPXlWllkvLxwSzhzhVbzqNex3o9e+AQwI=; b=K 5/fUPoV+6j6WTL9Bc5MJr53hFIxhwf5eWIEPta4LziO3b2svV1elN5k794ukaBPj KmYTLUMC7mBqhu46dO7K6g1wShHQbM8SoRBta1jcXKPpRqTqP9/sD9rwxOR2NrT3 OfYQSOa2mekS2efytTN1En/MRBnzT3E9/exh7fBgflHYAN84Fm4IAYN8/sYXcCXB zOjbw0Wh0fg2LqdZmhHpqXqVI966WNztV0v8hTwV0mJDEBDyHYt96CKdkIbjcgTq eY+ioexsp2QydH2NArLK/rvPFLsxzvWI2DLVk9ou1MR59pXGMBc15diQckQd1/yW AaF4NBgrUbZBpzg8a9Vmw== ARC-Authentication-Results: i=1; mx5.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linux.intel.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-usb-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linux.intel.com header.result=pass header_org.domain=intel.com header_org.result=pass header_is_org_domain=no Authentication-Results: mx5.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linux.intel.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-usb-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linux.intel.com header.result=pass header_org.domain=intel.com header_org.result=pass header_is_org_domain=no Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755503AbeARO7q (ORCPT ); Thu, 18 Jan 2018 09:59:46 -0500 Received: from mga02.intel.com ([134.134.136.20]:2954 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755393AbeARO7m (ORCPT ); Thu, 18 Jan 2018 09:59:42 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,378,1511856000"; d="scan'208";a="11594215" Subject: Re: [PATCH v1 1/1] usb: xhci: do not create and register shared_hcd when USB3.0 is disabled To: Tung Vuong Nguyen Cc: "Thang Q. Nguyen" , Mathias Nyman , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Phong Vo , Loc Ho , patches References: <1513395904-5139-1-git-send-email-tqnguyen@apm.com> From: Mathias Nyman Message-ID: Date: Thu, 18 Jan 2018 17:02:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-usb-owner@vger.kernel.org X-Mailing-List: linux-usb@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On 18.01.2018 09:27, Tung Vuong Nguyen wrote: > On Tue, Jan 16, 2018 at 9:50 PM, Mathias Nyman > wrote: >> >> Hi, Sorry about the delay >> >> >> On 04.01.2018 07:17, Thang Q. Nguyen wrote: >>> >>> Hi, >>> >>> On Sat, Dec 16, 2017 at 10:45 AM, Thang Q. Nguyen wrote: >>>> >>>> From: Tung Nguyen >>>> >>>> Currently, hcd->shared_hcd always creates and registers to the usb-core. >>>> If, for some reasons, USB3 downstream port is disabled, no roothub port for >>>> USB3.0 is found. This causes kernel to display an error: >>>> hub 2-0:1.0: config failed, hub doesn't have any ports! (err -19) >>>> This patch checks, creates and registers shared_hcd if USB3.0 downstream >>>> port is available. >>>> >>>> Signed-off-by: Tung Nguyen >>>> Signed-off-by: Thang Q. Nguyen >>>> --- >>>> drivers/usb/host/xhci-mem.c | 2 +- >>>> drivers/usb/host/xhci-plat.c | 26 +++++++++++---------- >>>> drivers/usb/host/xhci.c | 54 ++++++++++++++++++++++++++++++++------------ >>>> 3 files changed, 54 insertions(+), 28 deletions(-) >>>> >>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c >>>> index 554a8a5..157d1e7 100644 >>>> --- a/drivers/usb/host/xhci-mem.c >>>> +++ b/drivers/usb/host/xhci-mem.c >>>> @@ -1067,7 +1067,7 @@ static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, >>>> struct usb_device *top_dev; >>>> struct usb_hcd *hcd; >>>> >>>> - if (udev->speed >= USB_SPEED_SUPER) >>>> + if (udev->speed >= USB_SPEED_SUPER && xhci->shared_hcd) >>>> hcd = xhci->shared_hcd; >>>> else >>>> hcd = xhci->main_hcd; >>>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c >>>> index 6f03830..e812e3d 100644 >>>> --- a/drivers/usb/host/xhci-plat.c >>>> +++ b/drivers/usb/host/xhci-plat.c >>>> @@ -253,12 +253,6 @@ static int xhci_plat_probe(struct platform_device *pdev) >>>> >>>> xhci->clk = clk; >>>> xhci->main_hcd = hcd; >>>> - xhci->shared_hcd = __usb_create_hcd(driver, sysdev, &pdev->dev, >>>> - dev_name(&pdev->dev), hcd); >>>> - if (!xhci->shared_hcd) { >>>> - ret = -ENOMEM; >>>> - goto disable_clk; >>>> - } >>>> >>>> if (device_property_read_bool(sysdev, "usb2-lpm-disable")) >>>> xhci->quirks |= XHCI_HW_LPM_DISABLE; >>>> @@ -290,12 +284,20 @@ static int xhci_plat_probe(struct platform_device *pdev) >>>> if (ret) >>>> goto disable_usb_phy; >>>> >>>> - if (HCC_MAX_PSA(xhci->hcc_params) >= 4) >>>> - xhci->shared_hcd->can_do_streams = 1; >>>> - >>>> - ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); >>>> - if (ret) >>>> - goto dealloc_usb2_hcd; >>>> + if (xhci->num_usb3_ports > 0) { >>>> + xhci->shared_hcd = __usb_create_hcd(driver, sysdev, &pdev->dev, >>>> + dev_name(&pdev->dev), hcd); >>>> + if (!xhci->shared_hcd) { >>>> + ret = -ENOMEM; >>>> + goto disable_clk; >>>> + } >>>> + if (HCC_MAX_PSA(xhci->hcc_params) >= 4) >>>> + xhci->shared_hcd->can_do_streams = 1; >>>> + >>>> + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); >>>> + if (ret) >>>> + goto dealloc_usb2_hcd; >>>> + } >>>> >>>> device_enable_async_suspend(&pdev->dev); >>>> pm_runtime_put_noidle(&pdev->dev); >>>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c >>>> index 05104bd..4824bf6 100644 >>>> --- a/drivers/usb/host/xhci.c >>>> +++ b/drivers/usb/host/xhci.c >>>> @@ -417,12 +417,14 @@ static void compliance_mode_recovery(struct timer_list *t) >>>> i + 1); >>>> xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, >>>> "Attempting compliance mode recovery"); >>>> - hcd = xhci->shared_hcd; >>>> + if (xhci->shared_hcd) { >>>> + hcd = xhci->shared_hcd; >>>> >>>> - if (hcd->state == HC_STATE_SUSPENDED) >>>> - usb_hcd_resume_root_hub(hcd); >>>> + if (hcd->state == HC_STATE_SUSPENDED) >>>> + usb_hcd_resume_root_hub(hcd); >>>> >>>> - usb_hcd_poll_rh_status(hcd); >>>> + usb_hcd_poll_rh_status(hcd); >>>> + } >>>> } >>>> } >>>> >>>> @@ -611,6 +613,18 @@ int xhci_run(struct usb_hcd *hcd) >>>> if (ret) >>>> xhci_free_command(xhci, command); >>>> } >>>> + /* >>>> + * Execute xhci_start() in case xhci->shared_hcd is not registered. >>>> + * If the xhci->shared_hcd doesn't exist, no one triggers to start >>>> + * the xhci which should be done before exitting run function >>>> + */ >>>> + if (!xhci->shared_hcd) { >>>> + if (xhci_start(xhci)) { >> >> >> This probably won't work as primary hcd was added before shared_hcd was created. >> usb_add_hcd(hcd) calls xhci_run() before xhci->shared_hcd exists, so this will >> cause the xHC to start before the shared_hcd is created or setup. >> >> -Mathias > > Hi Mathias > I ran the test and saw the patch works fine in 2 cases: > xhci->num_usb3_ports = 0 and xhci->num_usb3_ports > 0. > For the case that we don't have the usb 3.0, the standalone > primary_hcd should work without the share_hcd. This case the root hubs > run at speed 480M. > If we have xhci->num_usb3_ports > 0 then we have 2 times to trigger to > start xHC in xhci_run. Once by the primary_hcd and once by share_hcd. > We will have 5000M root hubs and following by 480M root hubs when > triggering by the share_hcd and as properly. > > So the xHC should works when we only have primary_hcd or we have both > primary hcd and share_hcd > > Here is the brief of the scenario for this patch: > + create the primary hcd in xhci-plat > + execute usb_add_hcd(hcd), execute xhci_run and start the xHC (for primary hcd) > + if the xhci->num_usb3_ports > 0 then: > + create the share_hcd structure > + execute usb_add_hcd(share_hcd), execute xhci_run and start > the xHC again (for share_hcd) > + The root hub run at 5000M > else if xhci->num_usb3_ports == 0 then: > + don't create the share_hcd structure > + don't usb_add_hcd(share_hcd) > + the xHC can run with root hub 480M > > Please share your ideas for something should be changed. > original xhci_plat probe: ------------------------- usb_create_hcd(hcd) // USB2 usb_create_hcd(shared) // USB3 xhci->shared_hcd exists now, and hcd->primary is set for the USB3 hcd usb_add_hcd(hcd) // USB2 hcd->driver->start(hcd) // = .xhci_run() if (!usb_hcd_is_primary_hcd(hcd)) // FALSE, this is the primary USB2 else do other setup stuff usb_add_hcd(shared) // USB3 hcd->driver->start(shared) // = .xhci_run() if (!usb_hcd_is_primary_hcd(hcd)) // TRUE, this is the secondary USB3 xhci_run_finished() xhci_start() actually write bit to xHC that starts conrtoller. so xHC HW is not really processing anyting before everything is ready xhci_plat probe after this patch: --------------------------------- usb_create_hcd(hcd) // USB2 usb_add_hcd(hcd) // USB2 hcd->driver->start(hcd) // = .xhci_run() if (!xhci->shared_hcd) // TRUE, shared HCD is not yet created if (xhci_start(xhci)) actually write bit to xHC that starts controller. // <------------ THIS IS THE PROBLEM usb_create_hcd(shared) // USB3 xhci->shared_hcd exists now usb_add_hcd(shared) // USB3 hcd->driver->start(shared) // = .xhci_run() ... So there is a time when xHC HW is processing but the USB3 side in driver is not properly set up yet. -Mathias