From patchwork Wed May 23 02:16:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 10420033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A09EA60224 for ; Wed, 23 May 2018 02:17:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E7B12904F for ; Wed, 23 May 2018 02:17:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 820D62905C; Wed, 23 May 2018 02:17: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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 EB54B2904F for ; Wed, 23 May 2018 02:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753717AbeEWCR1 (ORCPT ); Tue, 22 May 2018 22:17:27 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:41315 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753165AbeEWCR0 (ORCPT ); Tue, 22 May 2018 22:17:26 -0400 Received: by mail-pf0-f194.google.com with SMTP id v63-v6so9675520pfk.8 for ; Tue, 22 May 2018 19:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=pJtRnaElwSNW1L/gpRGgdje1rQ6IQjHi6a6o2iFaQnY=; b=e09gF/tlQ0tGZj0vEAtCDNqHo2eD8id5ZaqhFb0dJFi5QCpeetQiAfJaazN96tfw/9 mHhN6/3+Qurfv6hB69ZpRNxoMMBVVSZxPUR9hU1p4V+woVHuEm8YqUerrfwODe0o6/S1 wX8FoOnBm2mxlRmRv4/cLHI97b0rQ6Eqk/ixA= 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; bh=pJtRnaElwSNW1L/gpRGgdje1rQ6IQjHi6a6o2iFaQnY=; b=qWdwXVkz2b9lF8fNhRh4wOlm30fKwQqTQWhRv5Vh+QXeCZdEk54FAGFu25AG66V/fI O8mvAY904b6ig0iAd0YQAgu4D/QaOqJulNgkFeYIcqTbEzlgoCl0Dx+il1y0tLmu2Aw9 1YGhC5Q60r+X1nAe+HPWeZP/2wBtj9a1hL3JOshq2MLyDpLIaU0GYngof73WvbK3tRoc Pmn/1bfQiy1M+UssRVSheogSIh+feKFGa0Z9KTR50O4D9dVSaY0cNxLmLx1TDxUY5t0X unS2eR6KI8D3XRCLW8UzA/vSXzZtQ6HKp5MGV15EsgKWozyIMME7vyfpN4O5MQzkaAft 56Kg== X-Gm-Message-State: ALKqPwfkIhFwP7pUefOiiuZ0oNvB+rqRalHp6TV4BrsVJTPGasa7tE52 bmceisAxLb+6hGm9RUBCPyASHw4Fx+g= X-Google-Smtp-Source: AB8JxZoJtM7Qj5moVofDPveGuyqLKksQnhJt9l2+X1aC4rtNNRR4odZfmX9BapiUGI0RFfaYqm8XHA== X-Received: by 2002:a65:5b4d:: with SMTP id y13-v6mr762721pgr.152.1527041845485; Tue, 22 May 2018 19:17:25 -0700 (PDT) Received: from drinkcat.tpe.corp.google.com ([2401:fa00:1:b:9ba:cd16:d555:bacf]) by smtp.gmail.com with ESMTPSA id r130-v6sm4648671pgr.87.2018.05.22.19.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 19:17:24 -0700 (PDT) From: Nicolas Boichat To: linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Alan Stern , Mathias Nyman , Felipe Balbi , Eugene Korenevsky , Peter Chen , Daniel Drake , Joe Perches , Nicolas Boichat , Johan Hovold , Richard Leitner , linux-kernel@vger.kernel.org, groeck@chromium.org Subject: [PATCH] usb: hub: Per-port setting to use old enumeration scheme Date: Wed, 23 May 2018 10:16:56 +0800 Message-Id: <20180523021656.122455-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog 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 The "old" enumeration scheme is considerably faster (it takes ~294ms instead of ~439ms to get the descriptor). It is currently only possible to use the old scheme globally (/sys/module/usbcore/parameters/old_scheme_first), which is not desirable as the new scheme was introduced to increase compatibility with more devices. However, in our case, we care about time-to-active for a specific USB device (which we make the firmware for), on a specific port (that is pogo-pin based: not a standard USB port). This new sysfs option makes it possible to use the old scheme on a single port only. Signed-off-by: Nicolas Boichat Acked-by: Alan Stern --- There are other "quirks" that we could add to reduce further enumeration time (e.g. reduce USB debounce time, reduce TRSTRCY to 10ms instead of 50ms as used currently), but the logic is quite similar, so it'd be good to have this reviewed first. drivers/usb/core/hub.c | 13 +++++++++---- drivers/usb/core/hub.h | 1 + drivers/usb/core/port.c | 23 +++++++++++++++++++++++ include/linux/usb.h | 7 +++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index c2d993d3816f0..f900f66a62856 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2636,7 +2636,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub) #define SET_ADDRESS_TRIES 2 #define GET_DESCRIPTOR_TRIES 2 #define SET_CONFIG_TRIES (2 * (use_both_schemes + 1)) -#define USE_NEW_SCHEME(i) ((i) / 2 == (int)old_scheme_first) +#define USE_NEW_SCHEME(i, scheme) ((i) / 2 == (int)scheme) #define HUB_ROOT_RESET_TIME 60 /* times are in msec */ #define HUB_SHORT_RESET_TIME 10 @@ -2651,12 +2651,16 @@ static unsigned hub_is_wusb(struct usb_hub *hub) * enumeration failures, so disable this enumeration scheme for USB3 * devices. */ -static bool use_new_scheme(struct usb_device *udev, int retry) +static bool use_new_scheme(struct usb_device *udev, int retry, + struct usb_port *port_dev) { + int old_scheme_first_port = + port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME; + if (udev->speed >= USB_SPEED_SUPER) return false; - return USE_NEW_SCHEME(retry); + return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first); } /* Is a USB 3.0 port in the Inactive or Compliance Mode state? @@ -4392,6 +4396,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, { struct usb_device *hdev = hub->hdev; struct usb_hcd *hcd = bus_to_hcd(hdev->bus); + struct usb_port *port_dev = hub->ports[port1 - 1]; int retries, operations, retval, i; unsigned delay = HUB_SHORT_RESET_TIME; enum usb_device_speed oldspeed = udev->speed; @@ -4513,7 +4518,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) { bool did_new_scheme = false; - if (use_new_scheme(udev, retry_counter)) { + if (use_new_scheme(udev, retry_counter, port_dev)) { struct usb_device_descriptor *buf; int r = 0; diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 4dc769ee9c740..4accfb63f7dcb 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -98,6 +98,7 @@ struct usb_port { struct mutex status_lock; u32 over_current_count; u8 portnum; + u32 quirks; unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1; diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 6979bde87d310..4a21431953953 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -50,6 +50,28 @@ static ssize_t over_current_count_show(struct device *dev, } static DEVICE_ATTR_RO(over_current_count); +static ssize_t quirks_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct usb_port *port_dev = to_usb_port(dev); + + return sprintf(buf, "%08x\n", port_dev->quirks); +} + +static ssize_t quirks_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct usb_port *port_dev = to_usb_port(dev); + u32 value; + + if (kstrtou32(buf, 16, &value)) + return -EINVAL; + + port_dev->quirks = value; + return count; +} +static DEVICE_ATTR_RW(quirks); + static ssize_t usb3_lpm_permit_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -118,6 +140,7 @@ static DEVICE_ATTR_RW(usb3_lpm_permit); static struct attribute *port_dev_attrs[] = { &dev_attr_connect_type.attr, + &dev_attr_quirks.attr, &dev_attr_over_current_count.attr, NULL, }; diff --git a/include/linux/usb.h b/include/linux/usb.h index beffceec49158..2ade17992ed66 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -489,6 +489,13 @@ enum usb_port_connect_type { USB_PORT_NOT_USED, }; +/* + * USB port quirks. + */ + +/* For the given port, prefer the old (faster) enumeration scheme. */ +#define USB_PORT_QUIRK_OLD_SCHEME BIT(0) + /* * USB 2.0 Link Power Management (LPM) parameters. */