Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2026056imm; Sun, 27 May 2018 23:33:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqcpNyc8lF5qNbMX7zmh1SyJ2E3VQANyBlBKDwJ1mVOc8not8I9oNqpG3tYArGfrsBKoLX/ X-Received: by 2002:a17:902:b08f:: with SMTP id p15-v6mr12163799plr.36.1527489224704; Sun, 27 May 2018 23:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527489224; cv=none; d=google.com; s=arc-20160816; b=xjZZ4ifVk+PHCiqnlHZndQm0WWTOT2w7xfp2WKNPxpXlnK0v7qZCgYm0y5JCXjgPdv n2t+PEgGw+OzBC3CPp9DkAH51F2FM3/x0UnVi59wkcrYiIma7a7MVMwwV6Sf0AmqNURV U148RAHEGULdyz/DYrp5dju2v6Lw1/qU57Md5un8I6cay5D1Tp+rUqPyfdR3DcUw2hYY oV/CIjZdNmXjvrRArpdSOszdy247QZMGdcx/orm92Snla7Z7fFyeE5NxtR9Ol4Wlw1bV +FDq1Uma9LSI1EWcHeNhgUGEtqe+uhs4a9Sh05xoiDOWI+mEqURXCz3rt/ukul8Ei3KT AoWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=oCKoxcoys5U4s+10yUMCd4wM1xS5rCNwihYiCYLvijE=; b=sLOljehnMAkFMkQsK6GF+mURrMTfrAzoYsodeq7UoM+Q3o+5Lcb7RcQGgBnVoGsJQB QpGYoCDwTUb0lT88y/myw7qSh3r5qKT7yC7H9G3090r/CxdXaFdWrDi8x8NFs+Vj7y5G t/0Kxhj1vk//UtxNo1jEMs1M7el6vik+Onp/CJkdCTmlEodxl+QJ0am880WNArjcPfC5 wh0ZC/O5mDokauMr05XU7qy5jvZbqUJiijGRb6KaxyZps/81RrSlRKjtTVWt0jrF3e5x /03BH+YWsZrKWRhQpBi5lHo/WRYxFYmQKEKqN4u4jYE+ZmGy1J4QiCLTgV1eMf8ZZs5l aWww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AFNDjdY4; 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 f11-v6si11083297plt.9.2018.05.27.23.33.27; Sun, 27 May 2018 23:33:44 -0700 (PDT) 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=AFNDjdY4; 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 S1753418AbeE1GdH (ORCPT + 99 others); Mon, 28 May 2018 02:33:07 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35296 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751085AbeE1GdE (ORCPT ); Mon, 28 May 2018 02:33:04 -0400 Received: by mail-pl0-f67.google.com with SMTP id i5-v6so6630929plt.2 for ; Sun, 27 May 2018 23:33:03 -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=oCKoxcoys5U4s+10yUMCd4wM1xS5rCNwihYiCYLvijE=; b=AFNDjdY42IFbFP2H/zMjVE1xA84HIveS8yAxQ5ngXsTCpktB1LKS56bOBRQwXI+0Im 4RG39Iv3PAvUkXSHOCHMMVSIZAibWDvkUw68aRew25WVnGSCttZOOm9yNbOa5VYbgL5s WPSg+zlindwcoMahCu0qptMmkrEm5jezUjqD8= 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=oCKoxcoys5U4s+10yUMCd4wM1xS5rCNwihYiCYLvijE=; b=rsPPJ0IJHHbW0JdF7tvRsj9f8XIqaPNgr2/xj9ZDMUP8d1h1Qcx6I35IiPJOm3J7bD 7vRshkuFmoVJC/br/WhrqG8HPCdGMEEKtu0nJHJfAynz0EIEcg4Lpp8pOk3QCMjcIvb9 crHNfskHCCCNWAJsypm0oNWepK9jUMsuKF2pUCwiK9zTI6eXUHR5aIp1pbY5GvxzpZgE ttLjIFhdya6CDhUM6CQF/bbcxpnM2n8/LON9qZrS7gRyM/4908vYsjDDyg4hauDUmrx8 NbsGVCVcwCw5YM1fypoYrZL1KNGbrfqUn+YUc/COKgYub09qmeZvBWBAFnh5pW2/L74i ayDQ== X-Gm-Message-State: ALKqPwdOYhQmwDS6G6Pie3wXUcUNretDpEcA9PRXvzPw7lzyCiqX1R1O vrzNIgGY6MOlb4g8OvKuzi1rvyzZzog= X-Received: by 2002:a17:902:4081:: with SMTP id c1-v6mr12342802pld.60.1527489183398; Sun, 27 May 2018 23:33:03 -0700 (PDT) Received: from drinkcat.tpe.corp.google.com ([2401:fa00:1:b:9ba:cd16:d555:bacf]) by smtp.gmail.com with ESMTPSA id y2-v6sm36431247pgp.92.2018.05.27.23.33.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 23:33:02 -0700 (PDT) From: Nicolas Boichat To: Greg Kroah-Hartman Cc: Alan Stern , Mathias Nyman , Felipe Balbi , Eugene Korenevsky , Peter Chen , Daniel Drake , Joe Perches , Nicolas Boichat , Johan Hovold , Richard Leitner , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, groeck@chromium.org Subject: [PATCHv2 1/2] usb: hub: Per-port setting to use old enumeration scheme Date: Mon, 28 May 2018 14:32:18 +0800 Message-Id: <20180528063219.234757-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "old" enumeration scheme is considerably faster (it takes ~244ms instead of ~356ms 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 --- Changes since v1: - Added documentation in Documentation/ABI - Updated timing in commit message to account for recent improvement in USB core (74072bae88fb3b) Documentation/ABI/testing/sysfs-bus-usb | 18 ++++++++++++++++++ drivers/usb/core/hub.c | 13 +++++++++---- drivers/usb/core/hub.h | 1 + drivers/usb/core/port.c | 23 +++++++++++++++++++++++ include/linux/usb.h | 7 +++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb index c6e9b30f05b13..a31a66d62cbba 100644 --- a/Documentation/ABI/testing/sysfs-bus-usb +++ b/Documentation/ABI/testing/sysfs-bus-usb @@ -189,6 +189,24 @@ Description: The file will read "hotplug", "wired" and "not used" if the information is available, and "unknown" otherwise. +What: /sys/bus/usb/devices/.../(hub interface)/portX/quirks +Date: May 2018 +Contact: Nicolas Boichat +Description: + In some cases, we care about time-to-active for devices + connected on a specific port (e.g. non-standard USB port like + pogo pins), where the device to be connected is known in + advance, and behaves well according to the specification. + This attribute is a bit-field that controls the behavior of + a specific port: + - Bit 0 of this field selects the "old" enumeration scheme, + as it is considerably faster (it only causes one USB reset + instead of 2). + The old enumeration scheme can also be selected globally + using /sys/module/usbcore/parameters/old_scheme_first, but + it is often not desirable as the new scheme was introduced to + increase compatibility with more devices. + What: /sys/bus/usb/devices/.../(hub interface)/portX/over_current_count Date: February 2018 Contact: Richard Leitner 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. */ -- 2.17.0.921.gf22659ad46-goog