Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1256704imu; Fri, 7 Dec 2018 17:50:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vq54kkwR/wPYwkoWMDtkrPhcx0ZfR87bZ3VhM4M+ekP8L38Eo84K0ZYuE8DTB4xN/26awq X-Received: by 2002:a63:4e41:: with SMTP id o1mr3990247pgl.282.1544233839167; Fri, 07 Dec 2018 17:50:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544233839; cv=none; d=google.com; s=arc-20160816; b=kypSN0Qrj0KqfTVMe1oDtDfnxAzIRTdTXTpymJpS/hbAQ+7A/vwDOHVi5ek9/dfDSf 2bBnGKlbhgDZHJkqUMG7iTBy3Ob8IoWJZnA+kyVsAVg6UhYNiwdqH+vkv2/pD0Y7CLP0 M/Bza0UnuOlLjL/izaDc7PDwriTwk7CrZBtzVZL/cJgnE7ezFE9MWLp3iziUkhvxvZ7G sKjhpsbcVhPl1YdhaE+fr3CoSp910Yzlf0YTWD1azV6zu7pKSyr2FD3WIn6mRjRpkJBH 4nJqvad/V7m5198G3RLbHKNOxLb5AyGVkMtvh/DCuCP/whCPWpEJNILtNrbey5vr15HL 59/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sFhVeAi7iY+UOG3wtwxTXo49ZgqvorZCSv35bV1qeMY=; b=gRRPJmp0bbsG50PB3duefD7k3Etcb1cy8SFivQnB73Tzhb+O+PGFZ/0YsP3YoB26CO G5dVi7pGhRqwySBkmJ410T+VPPFC8VVxwiMd06ouEensOTqC29Kqu5ZMLu3tPAAt8a8a FRUKDFbCmIOuPLjW47FoI6TKLgfd66KxDsTpfRerG0F6b8Tz3y/F0/2cnCcAIfd+pC8+ 8aodA1Ntpsm7ve2ioa5VOf9naCgY5ajGU7KIbE0Ooc3WC3SsYTRWE6jkR6VpcZN/4sVq zN4R6EG1Klel3x6GLytIYhEpRHfFcrCydl8tap0nSbf6H4CNMDgdgIMtCOJfCCdBjRoo JXzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UMS4cpoS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si4023658pgb.254.2018.12.07.17.49.45; Fri, 07 Dec 2018 17:50:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UMS4cpoS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbeLHBrw (ORCPT + 99 others); Fri, 7 Dec 2018 20:47:52 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:44112 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726110AbeLHBrw (ORCPT ); Fri, 7 Dec 2018 20:47:52 -0500 Received: by mail-qt1-f196.google.com with SMTP id n32so6599961qte.11 for ; Fri, 07 Dec 2018 17:47:51 -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=sFhVeAi7iY+UOG3wtwxTXo49ZgqvorZCSv35bV1qeMY=; b=UMS4cpoST60G6mrh0UTfrRs2NNM3+eLo3gRw1q0JybRTuhidGtYuZJumI9YpCUWYcm aEN2kyN8MHucC4EHOcMNkaNEUj5h4TBh6wS4hNTaAm/18uPO+BEXxma1szPcslcy5P4k IE7HyoDHFl5qniIKRS9rcXvUtXSmihvWJdCC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sFhVeAi7iY+UOG3wtwxTXo49ZgqvorZCSv35bV1qeMY=; b=OPvuRGP3kaW2xi3A00AbVpMHFxNKhyAATACq1LaT7zQ2Y2VYdtznkKI+VA7w5UvL7i n0haoD+FyOYpY2uEKl/0mdaqiLz6l44DYW5ywa8+rKXHaPJe1j1J8C4M+jxwUsOil812 f6ZVBr8pxgez3cM0Vmupj/2GrTEiG3pK9OgIjxRdo7+BmHfUiFyfTXcpL+hu51N8lClA GWWOKeHz69CBP0V9BZgNCIzKQ1/yp1McCywiSkg6ImZ9MV+FKdKjLTfd1D6DzRu3KeO7 mLeGpXOvnlA6VBIsejEp1tkJVdA2r4mXUBsRbGX1et5Yau9kUAaySAOaYvD/29TdCrTQ X0Ug== X-Gm-Message-State: AA+aEWbQSMIBk/jjEfsq10kL2HdjZXRRa525LFkY7IZxsbcXVkLSA+vI AWgcpovJo1LV2DgK4Nt6J8S6+2JUXe5BQQ== X-Received: by 2002:ac8:254c:: with SMTP id 12mr4071312qtn.88.1544233670635; Fri, 07 Dec 2018 17:47:50 -0800 (PST) Received: from kdgwill07.nyc.corp.google.com ([2620:0:1003:510:59af:10e9:2d49:6b0a]) by smtp.googlemail.com with ESMTPSA id 94sm5604597qks.8.2018.12.07.17.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 17:47:50 -0800 (PST) From: Kyle Williams X-Google-Original-From: Kyle Williams To: linux-kernel@vger.kernel.org Cc: kdgwill@chromium.org, Greg Kroah-Hartman , Alan Stern , Mathias Nyman , Nicolas Boichat , Jon Flatley , Felipe Balbi , linux-usb@vger.kernel.org Subject: [PATCH v3 1/2] USB: quirks: Check device interface LPM capability Date: Fri, 7 Dec 2018 20:47:21 -0500 Message-Id: <20181208014724.951-2-kdgwill@google.com> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog In-Reply-To: <20181208014724.951-1-kdgwill@google.com> References: <20181205093902.GA18633@kroah.com> <20181208014724.951-1-kdgwill@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kyle Williams Description: enable the ability to disable LPM for all devices matched by interface information Signed-off-by: Kyle Williams --- drivers/usb/core/hub.c | 87 +++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 0f9381b69a3b..8f366ec4d21b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -365,6 +365,51 @@ static void usb_set_lpm_parameters(struct usb_device *udev) usb_set_lpm_sel(udev, &udev->u2_params); } +/* + * There are reports of USB 3.0 devices that say they support USB 2.0 Link PM + * when they're plugged into a USB 2.0 port, but they don't work when LPM is + * enabled. + * + * Only enable USB 2.0 Link PM if the port is internal (hardwired), or the + * device says it supports the new USB 2.0 Link PM errata by setting the BESL + * support bit in the BOS descriptor. + */ +static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) +{ + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); + int connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; + + if (!udev->usb2_hw_lpm_capable || !udev->bos) + return; + + if (hub) + connect_type = hub->ports[udev->portnum - 1]->connect_type; + + if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) + || connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { + udev->usb2_hw_lpm_allowed = 1; + usb_set_usb2_hardware_lpm(udev, 1); + } +} + +void usb_update_device_lpm(struct usb_hcd *hcd, struct usb_device *udev) +{ + int retval; + + if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { + retval = usb_get_bos_descriptor(udev); + if (!retval) { + udev->lpm_capable = usb_device_supports_lpm(udev); + usb_set_lpm_parameters(udev); + } + } + + /* notify HCD that we have a device connected and addressed */ + if (hcd->driver->update_device) + hcd->driver->update_device(hcd, udev); + hub_set_initial_usb2_lpm_policy(udev); +} + /* USB 2.0 spec Section 11.24.4.5 */ static int get_hub_descriptor(struct usb_device *hdev, struct usb_hub_descriptor *desc) @@ -2295,7 +2340,6 @@ static int usb_enumerate_device_otg(struct usb_device *udev) return err; } - /** * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal) * @udev: newly addressed device (in ADDRESS state) @@ -2351,6 +2395,8 @@ static int usb_enumerate_device(struct usb_device *udev) usb_detect_interface_quirks(udev); + usb_update_device_lpm(hcd, udev); + return 0; } @@ -4402,33 +4448,6 @@ static int hub_set_address(struct usb_device *udev, int devnum) return retval; } -/* - * There are reports of USB 3.0 devices that say they support USB 2.0 Link PM - * when they're plugged into a USB 2.0 port, but they don't work when LPM is - * enabled. - * - * Only enable USB 2.0 Link PM if the port is internal (hardwired), or the - * device says it supports the new USB 2.0 Link PM errata by setting the BESL - * support bit in the BOS descriptor. - */ -static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) -{ - struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); - int connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; - - if (!udev->usb2_hw_lpm_capable || !udev->bos) - return; - - if (hub) - connect_type = hub->ports[udev->portnum - 1]->connect_type; - - if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || - connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { - udev->usb2_hw_lpm_allowed = 1; - usb_set_usb2_hardware_lpm(udev, 1); - } -} - static int hub_enable_device(struct usb_device *udev) { struct usb_hcd *hcd = bus_to_hcd(udev->bus); @@ -4779,19 +4798,9 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, usb_detect_quirks(udev); - if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { - retval = usb_get_bos_descriptor(udev); - if (!retval) { - udev->lpm_capable = usb_device_supports_lpm(udev); - usb_set_lpm_parameters(udev); - } - } + usb_update_device_lpm(hcd, udev); retval = 0; - /* notify HCD that we have a device connected and addressed */ - if (hcd->driver->update_device) - hcd->driver->update_device(hcd, udev); - hub_set_initial_usb2_lpm_policy(udev); fail: if (retval) { hub_port_disable(hub, port1, 0); -- 2.20.0.rc2.403.gdbc3b29805-goog