From patchwork Wed Jan 30 12:38:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan-Marek Glogowski X-Patchwork-Id: 10788505 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 A682C91E for ; Wed, 30 Jan 2019 12:38:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90E0A2DFE2 for ; Wed, 30 Jan 2019 12:38:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81F812E96A; Wed, 30 Jan 2019 12:38:33 +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.9 required=2.0 tests=BAYES_00,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 9A1CB2DFE2 for ; Wed, 30 Jan 2019 12:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbfA3Mic (ORCPT ); Wed, 30 Jan 2019 07:38:32 -0500 Received: from ironboyv.h-da.de ([141.100.10.230]:55839 "EHLO ironboyv.h-da.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfA3Mib (ORCPT ); Wed, 30 Jan 2019 07:38:31 -0500 IronPort-SDR: n7cu34BkujRDBC5X0we+Si81AtHpoUTdSQnR91XFs8s6fPKb9fDK35u74SjqNVz78HT3Qi3ZI7 Pa3+BK1p0T7B8HlCbA4dyqjpzh0uustvUAGsospG9LgKbORWp1nTSDFRefO0K9wrRSoEm6Bnn/ rWdk3/1Sgi6WnbtZT471cJBe//ojCe9B8MKOsaFyKjMc2l1jVVj1IdiOPO/Gpyxj+th702zj7V wzAuzF0jC8zjNDhfYBy7nGTW0YILNt8ku8MEBJpQ4i36K/Qfij91/BnTWVinwyScKOKluau+xU NCw= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2EPAADhmVFc/2soZI1jGwEBAQEDAQEBBwMBAQGBUQYBAQELAYIDgTggEieMHYxFAQEBAQEHmUIUgWc5hECDCSI0CQ0BAwEBAgEBAgICaSiGSyiBKYMigXURrCIaAooch3+EQRd4gQeBEIRUAYMoA4V0AotvlmkJgRuRGRaKNBkDh2ODLZl7OYFWTSQUgyeCJwwLjh8+M4EfjESCTAEB X-IPAS-Result: A2EPAADhmVFc/2soZI1jGwEBAQEDAQEBBwMBAQGBUQYBAQELAYIDgTggEieMHYxFAQEBAQEHmUIUgWc5hECDCSI0CQ0BAwEBAgEBAgICaSiGSyiBKYMigXURrCIaAooch3+EQRd4gQeBEIRUAYMoA4V0AotvlmkJgRuRGRaKNBkDh2ODLZl7OYFWTSQUgyeCJwwLjh8+M4EfjESCTAEB Received: from unknown (HELO mail.fbihome.de) ([141.100.40.107]) by ironboyv.h-da.de with ESMTP; 30 Jan 2019 13:38:31 +0100 Received: from kvm-sbuild2.tvc.muenchen.de. (unknown [194.113.41.246]) by mail.fbihome.de (Postfix) with ESMTPSA id 87B8D42226; Wed, 30 Jan 2019 13:37:30 +0100 (CET) From: Jan-Marek Glogowski To: linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Alan Stern , Mathias Nyman , Kai-Heng Feng , Nicolas Boichat , Nicolas Saenz Julienne , Jon Flatley , Oliver Neukum Subject: [PATCH v3] usb: warm-reset ports on hub resume, if requested Date: Wed, 30 Jan 2019 13:38:25 +0100 Message-Id: <1548851905-1570-1-git-send-email-glogow@fbihome.de> X-Mailer: git-send-email 2.1.4 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 On plug-in of my USB-C device, its USB_SS_PORT_LS_SS_INACTIVE link state bit is set. Greping all the kernel for this bit shows that the port status requests a warm-reset this way. This just happens, if its the only device on that hub and the hub resumes, so we don't call port_event, which would otherwise warm-reset ports. The device works ok without this patch, if there is already any other device connected to the hub. Signed-off-by: Jan-Marek Glogowski --- The original thread is "USB-C storage device not detected on USB 3.1 Gen 2 host when plugged in after boot". A different patch, suggested by Mathias Nyman, didn't work for me. This patch was just rebased on usb-next, but not re-tested. Original tests are based on 5.0-rc. v1: This always warm-resets the ports in hub_activate, independent of the "enum hub_activation_type". Just had a single device to test. v2: I had the idea about the working device, if there is already a device connected to the hub and that a resume only on "type == HUB_RESUME" should be sufficient. This still works for me, but I didn't follow all the hub_activate callers everywhere and I'm definitly still missing a lot of knowledge about USB stuff. There is also HUB_RESET_RESUME with a slightly different code path. I don't know how to trigger this. v3: code unchanged to v2. --- drivers/usb/core/hub.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index bb0830c..33d4821 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -108,6 +108,16 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); static void hub_release(struct kref *kref); static int usb_reset_and_verify_device(struct usb_device *udev); static int hub_port_disable(struct usb_hub *hub, int port1, int set_state); +static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, + u16 portstatus); +static int hub_port_reset(struct usb_hub *hub, int port1, + struct usb_device *udev, unsigned int delay, bool warm); + +#define HUB_ROOT_RESET_TIME 60 /* times are in msec */ +#define HUB_SHORT_RESET_TIME 10 +#define HUB_BH_RESET_TIME 50 +#define HUB_LONG_RESET_TIME 200 +#define HUB_RESET_TIMEOUT 800 static inline char *portspeed(struct usb_hub *hub, int portstatus) { @@ -1147,6 +1157,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) USB_SS_PORT_LS_POLLING)) need_debounce_delay = true; + if (type == HUB_RESUME && + hub_port_warm_reset_required(hub, port1, portstatus)) + hub_port_reset(hub, port1, udev, + HUB_BH_RESET_TIME, true); + /* Clear status-change flags; we'll debounce later */ if (portchange & USB_PORT_STAT_C_CONNECTION) { need_debounce_delay = true; @@ -2684,12 +2699,6 @@ static unsigned hub_is_wusb(struct usb_hub *hub) #define SET_CONFIG_TRIES (2 * (use_both_schemes + 1)) #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 -#define HUB_BH_RESET_TIME 50 -#define HUB_LONG_RESET_TIME 200 -#define HUB_RESET_TIMEOUT 800 - /* * "New scheme" enumeration causes an extra state transition to be * exposed to an xhci host and causes USB3 devices to receive control