From patchwork Tue May 14 21:38:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10943787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C90A392A for ; Tue, 14 May 2019 21:38:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B665F28438 for ; Tue, 14 May 2019 21:38:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAA4A2882E; Tue, 14 May 2019 21:38:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 382C328438 for ; Tue, 14 May 2019 21:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726180AbfENVih (ORCPT ); Tue, 14 May 2019 17:38:37 -0400 Received: from smtprelay-out1.synopsys.com ([198.182.47.102]:33632 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENVih (ORCPT ); Tue, 14 May 2019 17:38:37 -0400 Received: from mailhost.synopsys.com (badc-mailhost2.synopsys.com [10.192.0.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 6A54BC01E2; Tue, 14 May 2019 21:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1557869921; bh=0eOcbEzexVmYzSmQg0FJNp3VqFgjycYdOWrYqkOSdVY=; h=Date:From:Subject:To:CC:From; b=GsqmbmwM8FI3ka4Z5eyVsFNksQYwibmBxGhqZmnaXdtcUxdI2y0SBN27nqHCk23pi jEINNn34thMkSGXEbV+7Y5BLAy09z/FVAqdu88PBBWS85DbegZvEuW39yYPmFAaBit XXzTAT2ugzxWgkprmSUJGe2cCSmOSVaur1GJpVbbk8SDjWCRaSCHkScHOPU8a2kGxH U6Xo5fANhYJLGSDuLSjfi4ETsyqcOt15p9Q6kJA3FUbyywy3DgEMmRZcs+6SBy+gfS OFeWvjlVKMIsuS7jcIM72Edu+TEEbU08oAzIv+ziEW4L9Uor/BuAr3soHbCLtoX9dI MJMET7f//KOHQ== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPS id A18C4A005A; Tue, 14 May 2019 21:38:33 +0000 (UTC) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 14 May 2019 14:38:33 -0700 Received: from te-lab16 (10.13.184.19) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 14 May 2019 14:38:31 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Tue, 14 May 2019 14:38:31 -0700 Date: Tue, 14 May 2019 14:38:31 -0700 Message-ID: From: Thinh Nguyen Subject: [PATCH 1/2] usb: core: hub: Enable/disable U1/U2 in configured state To: Greg Kroah-Hartman , Thinh Nguyen , , Alan Stern , Mathieu Malaterre , "Nicolas Saenz Julienne" , Kai-Heng Feng , Jon Flatley , "Nicolas Boichat" CC: John Youn MIME-Version: 1.0 X-Originating-IP: [10.13.184.19] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP SET_FEATURE(U1/U2_ENABLE) and CLEAR_FEATURE(U1/U2) only apply while the device is in configured state. Add proper check in usb_disable_lpm() and usb_enable_lpm() for enabling/disabling device-initiated U1/U2. Signed-off-by: Thinh Nguyen --- drivers/usb/core/hub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 2f94568ba385..026b652d4f38 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4139,7 +4139,7 @@ int usb_disable_lpm(struct usb_device *udev) if (!udev || !udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable || - udev->state < USB_STATE_DEFAULT) + udev->state < USB_STATE_CONFIGURED) return 0; hcd = bus_to_hcd(udev->bus); @@ -4198,7 +4198,7 @@ void usb_enable_lpm(struct usb_device *udev) if (!udev || !udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable || - udev->state < USB_STATE_DEFAULT) + udev->state < USB_STATE_CONFIGURED) return; udev->lpm_disable_count--; From patchwork Tue May 14 21:38:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10943789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC3A2933 for ; Tue, 14 May 2019 21:38:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB19B28821 for ; Tue, 14 May 2019 21:38:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EF0E28832; Tue, 14 May 2019 21:38:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38BEB28821 for ; Tue, 14 May 2019 21:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbfENVim (ORCPT ); Tue, 14 May 2019 17:38:42 -0400 Received: from dc8-smtprelay2.synopsys.com ([198.182.47.102]:33658 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbfENVim (ORCPT ); Tue, 14 May 2019 17:38:42 -0400 Received: from mailhost.synopsys.com (dc8-mailhost1.synopsys.com [10.13.135.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id ACD25C01E2; Tue, 14 May 2019 21:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1557869926; bh=3Y6CAzzUoINQblswnFSRxSuhjhXjq5RQ36NuSQSgVtw=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=BaawQO3vGjsCaSufuPw/A97hVtYVCt3p1lNkMSNnvoYgL/m+8FgyNibL3zKYfG8gh 1UMbkJ9ui3IHwqL4hN3H2RSvC72dhj6Fxs+PozH6LsQm1hqqsIrE65quoDMHcQSyNS W57P+7pCcShbgC0tDNP9B1hEAJ7izg5FEMU/UNHrJrdUqGJqHHjckOuiFRl3KPFDBw mAUDZftHGq+Gu9aPc/TfdaTEIMCzOdS1/PkKl8n5OEf7Nc3ZfQffjZI+6TvaBlWE0E PmUZy1Sh590P/944IjrwBb8pPv8CneLxq857FWZ2F7snxSxuYvahTuvHx9YhXzfPv7 Tj2VEh6VeyWxw== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPS id 000CEA023B; Tue, 14 May 2019 21:38:39 +0000 (UTC) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 14 May 2019 14:38:39 -0700 Received: from te-lab16 (10.13.184.19) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 14 May 2019 14:38:38 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Tue, 14 May 2019 14:38:38 -0700 Date: Tue, 14 May 2019 14:38:38 -0700 Message-ID: <84e7b407523dbba982e47d7996332866012ab60f.1557869140.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH 2/2] usb: core: hub: Disable hub-initiated U1/U2 To: Greg Kroah-Hartman , Thinh Nguyen , , Alan Stern , Mathieu Malaterre , "Nicolas Saenz Julienne" , Kai-Heng Feng , Jon Flatley , "Nicolas Boichat" CC: John Youn , Anurag Kumar Vulisha MIME-Version: 1.0 X-Originating-IP: [10.13.184.19] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the device rejects the control transfer to enable device-initiated U1/U2 entry, then the device will not initiate U1/U2 transition. To improve the performance, the downstream port should not initate transition to U1/U2 to avoid the delay from the device link command response (no packet can be transmitted while waiting for a response from the device). If the device has some quirks and does not implement U1/U2, it may reject all the link state change requests, and the downstream port may resend and flood the bus with more requests. This will affect the device performance even further. This patch disables the hub-initated U1/U2 if the device-initiated U1/U2 entry fails. Reference: USB 3.2 spec 7.2.4.2.3 Signed-off-by: Thinh Nguyen --- drivers/usb/core/hub.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 026b652d4f38..572e8c26a129 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3999,6 +3999,9 @@ static int usb_set_lpm_timeout(struct usb_device *udev, * control transfers to set the hub timeout or enable device-initiated U1/U2 * will be successful. * + * If the control transfer to enable device-initiated U1/U2 entry fails, then + * hub-initiated U1/U2 will be disabled. + * * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI * driver know about it. If that call fails, it should be harmless, and just * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency. @@ -4053,23 +4056,24 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, * host know that this link state won't be enabled. */ hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); - } else { - /* Only a configured device will accept the Set Feature - * U1/U2_ENABLE - */ - if (udev->actconfig) - usb_set_device_initiated_lpm(udev, state, true); + return; + } - /* As soon as usb_set_lpm_timeout(timeout) returns 0, the - * hub-initiated LPM is enabled. Thus, LPM is enabled no - * matter the result of usb_set_device_initiated_lpm(). - * The only difference is whether device is able to initiate - * LPM. - */ + /* Only a configured device will accept the Set Feature + * U1/U2_ENABLE + */ + if (udev->actconfig && + usb_set_device_initiated_lpm(udev, state, true) == 0) { if (state == USB3_LPM_U1) udev->usb3_lpm_u1_enabled = 1; else if (state == USB3_LPM_U2) udev->usb3_lpm_u2_enabled = 1; + } else { + /* Don't request U1/U2 entry if the device + * cannot transition to U1/U2. + */ + usb_set_lpm_timeout(udev, state, 0); + hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); } }