Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp702308imu; Mon, 5 Nov 2018 07:32:39 -0800 (PST) X-Google-Smtp-Source: AJdET5d09ffke2bcu7fFoF37yHYoR6fLRrUgdYIYYKTweSdYzAsdbyC044d3kVvQKwTFFnCEoJnq X-Received: by 2002:a17:902:1122:: with SMTP id d31-v6mr22728834pla.259.1541431959125; Mon, 05 Nov 2018 07:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541431959; cv=none; d=google.com; s=arc-20160816; b=Q0s69hfmv24CVHOWt/0bHqzsG6KTStzpuqKU4KtLwXxrFMw4dHeG6ObMPnCfx/kCkK ddfZJ/kcm5NMQTnmEmvfxyDrpQnRPBxL9PCkR+AA/CgziIeQyQWqxZEowgoWX5894G+s 7p2qp76sM7BjMl4Jz6T4Og/zFz67Oo4nx4UFs/BhZBqwqoOltsC3P6r7I28wFZI5vgUQ A9Y6ohK2VrQ41nKDm5vbhNytucbHljqROqgdMN13TdCFv5uRSwDEtGVZ77SL22maS0lF 1dBvrHhuPIrYJOR8a3R7otimJCf7pBcS0mDxpNEpeWh+tDD3jDfMlu+miiRZURxALXcQ NTNQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=hUSqw1fnApvD1u79GJvrW6M3CYLNXcwh3ZBvlic0O+8=; b=Nrd/E9zYcLUgxfvRr7S+XzvAe1bOIfYpoG/z/iEnHFVAWoubYqEysqQmr2J20mv4dX bxgg40Wm8uhMI40qrojZxFkunVCeHSVi4Ugg7RCrKPjOhrPd9mU7x8NprLLVlPZd2OGG A5M0NvXjS+CuuLIdV7ljm53SKvkUaGfOQ8W8WKmNK3ktrvKToGziG/mf6WWZynXMITCc nAUImQYEPMtIfg4XaaiTEwUkuL4x2f1ORVMj9p0kzkTbUMsq1aH3bMs1yxlWcslTjSGd y8Z+tA3AQog2CyBcaOXSsC/8xDY2FjADqGK7X3S1xX1KIWsXawhSTrRMg765+IrDc+h5 cLxg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m187-v6si11418250pfm.159.2018.11.05.07.32.24; Mon, 05 Nov 2018 07:32: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730087AbeKFAwH (ORCPT + 99 others); Mon, 5 Nov 2018 19:52:07 -0500 Received: from mga06.intel.com ([134.134.136.31]:6649 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729960AbeKFAwH (ORCPT ); Mon, 5 Nov 2018 19:52:07 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 07:31:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,468,1534834800"; d="scan'208";a="84112992" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.164]) ([10.237.72.164]) by fmsmga008.fm.intel.com with ESMTP; 05 Nov 2018 07:31:48 -0800 Subject: Re: USB-C device hotplug issue To: Alan Stern , Dennis Wassenberg Cc: Mathias Nyman , Greg Kroah-Hartman , Ravi Chandra Sadineni , Kuppuswamy Sathyanarayanan , Bin Liu , Maxim Moseychuk , Mike Looijmans , Dominik Bozek , USB list , Kernel development list References: From: Mathias Nyman Message-ID: Date: Mon, 5 Nov 2018 17:35:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26.10.2018 17:07, Alan Stern wrote: > On Fri, 26 Oct 2018, Dennis Wassenberg wrote: > >>>> --- a/drivers/usb/core/hub.c >>>> +++ b/drivers/usb/core/hub.c >>>> @@ -2815,7 +2815,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1, >>>> USB_PORT_FEAT_C_BH_PORT_RESET); >>>> usb_clear_port_feature(hub->hdev, port1, >>>> USB_PORT_FEAT_C_PORT_LINK_STATE); >>>> - usb_clear_port_feature(hub->hdev, port1, >>>> + >>>> + if (!warm) >>>> + usb_clear_port_feature(hub->hdev, port1, >>>> USB_PORT_FEAT_C_CONNECTION); >>>> >>>> /* >>> >>> The key fact is that connection events can get lost if they happen to >>> occur during a port reset. >> Yes. >>> >>> I'm not entirely certain of the logic here, but it looks like the >>> correct test to add should be "if (udev != NULL)", not "if (!warm)". >>> Perhaps Mathias can confirm this Sorry about the late response, got distracted while performing git archeology. "if (udev != NULL)" would seem more reasonable. Logs show that clearing the FEAT_C_CONNECTION was originally added after a hot reset failed, and before issuing a warm reset to a SS.Inactive link. (see 10d674a USB: When hot reset for USB3 fails, try warm reset.) Apparently all the change flags needed to be cleared for some specific host + device combination before issuing a warm reset for the enumeration to work properly. The change to always clear FEAT_C_CONNECTION for USB3 was done later in patch: a24a607 USB: Rip out recursive call on warm port reset. Motivation was: "In hub_port_finish_reset, unconditionally clear the connect status change (CSC) bit for USB 3.0 hubs when the port reset is done. If we had to issue multiple warm resets for a device, that bit may have been set if the device went into SS.Inactive and then was successfully warm reset." >> I don't know if clearing the USB_PORT_FEAT_C_CONNECTION bit is >> correct in case of a non warm reset. In my case I always observed a >> warm reset because of the link state change. >> Thats why I checked the warm variable to not change the behavoir for >> cases a didn't checked for the first shot. > > (The syntax of that last sentence is pretty mangled; I can't understand > it.) > > Think of it this way: > > If a device was not attached before the reset, we don't want > to clear the connect-change status because then we wouldn't > recognize a device that was plugged in during the reset. > > If a device was attached before the reset, we don't want any > connect-change status which might be provoked by the reset to > last, because we don't want the core to think that the device > was unplugged and replugged when all that happened was a reset. > > So the important criterion is whether or not a device was attached to > the port when the reset started. It's something of a coincidence that > you only observe warm resets when there's nothing attached. > >> During the first run of usb_hub_reset the udev is NULL because in >> this situation the device is not attached logically. >> >> [ 112.889810] usb 4-1-port1: XXX: port_event: portstatus: 0x2c0, portchange: 0x40! >> [ 113.201192] usb 4-1-port1: XXX: hub_port_reset: udev: (nil)! >> [ 113.201198] usb 4-1-port1: XXX: hub_port_reset (not clearing USB_PORT_FEAT_C_CONNECTION): 0x203, portchange: 0x1! >> [ 113.253612] usb 4-1-port1: XXX: port_event: portstatus: 0x203, portchange: 0x1! >> [ 113.377208] usb 4-1-port1: XXX: hub_port_reset: udev: ffff88046b302800! >> [ 113.377214] usb 4-1-port1: XXX: hub_port_reset (not clearing USB_PORT_FEAT_C_CONNECTION): 0x203, portchange: 0x0! >> [ 113.429478] usb 4-1.1: new SuperSpeed USB device number 7 using xhci_hcd >> [ 113.442370] usb 4-1.1: New USB device found, idVendor=0781, idProduct=5596 >> [ 113.442376] usb 4-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 >> [ 113.442381] usb 4-1.1: Product: Ultra T C >> [ 113.442385] usb 4-1.1: Manufacturer: SanDisk >> [ 113.442388] usb 4-1.1: SerialNumber: 4C530001131013121031 >> >> Or maybe we can skip clearing the USB_PORT_FEAT_C_CONNECTION bit in >> case of hub_port_reset completely without any other check? > > See above. Checking for udev sounds reasonable to me. Not sure if we should worry about the specific host+device combo that needed flags cleared before warm reset. See patch: 10d674a USB: When hot reset for USB3 fails, try warm reset. https://marc.info/?l=linux-usb&m=131603549603799&w=2 -Mathias