Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6598146ybf; Fri, 6 Mar 2020 00:39:37 -0800 (PST) X-Google-Smtp-Source: ADFU+vuIfnTkIP2pqXonN9MkedkV+M3uSAWtmHv7p9MQC6od8ZduHAo/w1tLls5RBsGd9bzBUdZV X-Received: by 2002:a9d:75d7:: with SMTP id c23mr1474763otl.73.1583483977698; Fri, 06 Mar 2020 00:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583483977; cv=none; d=google.com; s=arc-20160816; b=t0Tegy8jbHi6Wa4mrUZ/ocWxCF67j/a6mBE6kCV6sRPBBucG/GMtX/sn2pDZpwa65I o6u+vvHMMkSuU6bRQ11wzBWbAVarmk7TrwKbQpTd5t5/ned6QCD2a8XQGMsvXoKDndLP LKAALN4Pdn43hAogS2db98mPJ8YIzCLG99eq28LS4649W/DUnARDb3DnI8J2vIkjK8cl HqvZCmQFq1CnzIIs//GGQJbWZfadgia0uudAzsTOX/4aYertP2P5kS3UAPY4VUeGca3W tXtNwgga2rEp484Fk0x1T0M9E+gvY+5ucYRoqlwRzoDsvFUeTTcCB89MXxxZ2KmYB5/W 6W9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=mz68RAVZwk2GAytm9sZM2plTjuy76cNfGXFKZoV1UBI=; b=Az/yCiVm3BEpld5v/Bo3Wd1lmfP/h1H2wnCCq4pgVSVP0VJukNtBBg/ax1eMsd7IQH 8q7fo/IvOid859YJDpMT/ldu1Ohi1P1q8DQ07sGQGBzncSJ0IHaX9S3sAFtpNuF/GfMI R2Yakv/amBHi0+UGxT0X5kp1C8qO8TyOSQzQZ/Xyyry7tYl5GMeDBwskxHXhYRBE0zlO Idzoo6PiD5ImH2FswlkqgBHkMLsUKsN4Q65KufcTiOcPRXiUgzGCkc/f7T452yN3e4ej SpXCxRETBRQoQBtE4Re4KwtUGn7EkIqPBdyMdIMqfBG5AC93mB6DZTczaI3jXtgZpNnc WPdg== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w22si914222oih.103.2020.03.06.00.39.25; Fri, 06 Mar 2020 00:39:37 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725941AbgCFIi4 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 6 Mar 2020 03:38:56 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:46607 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbgCFIi4 (ORCPT ); Fri, 6 Mar 2020 03:38:56 -0500 Received: from mail-pl1-f200.google.com ([209.85.214.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jA8VR-0002Ab-Fg for linux-kernel@vger.kernel.org; Fri, 06 Mar 2020 08:38:53 +0000 Received: by mail-pl1-f200.google.com with SMTP id b10so1049416pls.0 for ; Fri, 06 Mar 2020 00:38:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ex8IIRiePP84oKL/gqanENhA2v8Yo70JDYAq5VI/5vc=; b=DXQtI5CUJtUpd85YvoRf4tcV8eRaxQd2LatN1y948w9kx9N25bU3aPrZ/p+l1zmPin GLn40JAviQdMy8OwKB7O+72NzG3VcdcbnWmLfKOeyBRbVYqcTfTnxxfNIxr+yIugvV1j ezaHdwdRvvkZanE8Be3fOs3pTHkA8sNVMYCXyz7qGa4YTbNrT1119Tx1zX/6dY/XLMaU BnHCYWhusYBF/+3RXywqDNwJ8i9LvOrWiXINn8JUk6JHvSpW4scmmgt63bbjJA8pJqvL /zuC+XXVXfoDKMEMQtWu8CLlag5Gl4HWVIyj4nTH8d3vUBSEeiiYDx0cNLXHeMLhfg+l XZTQ== X-Gm-Message-State: ANhLgQ3FsBr1BhZfrcWEPRG6wQUvClwiMhrJnsA23oxf9Tg3mQL5vb6t HHA3NflEorlru/OI5JA3nSZoMa49b3SQmyhkQIYxtnLAO/EAaCpIHkofLmlxonD8wimAMc9iZwP T0Qf7Oa/jRlsD0ZPyMrdkqOBbN5qvYURUdVwjcDsXuQ== X-Received: by 2002:a17:90b:1a8b:: with SMTP id ng11mr2490787pjb.194.1583483931713; Fri, 06 Mar 2020 00:38:51 -0800 (PST) X-Received: by 2002:a17:90b:1a8b:: with SMTP id ng11mr2490760pjb.194.1583483931244; Fri, 06 Mar 2020 00:38:51 -0800 (PST) Received: from [192.168.1.208] (220-133-187-190.HINET-IP.hinet.net. [220.133.187.190]) by smtp.gmail.com with ESMTPSA id b71sm23302152pfb.156.2020.03.06.00.38.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2020 00:38:50 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH] usb: core: Set port link to RxDetect if port is not enabled after resume From: Kai-Heng Feng In-Reply-To: Date: Fri, 6 Mar 2020 16:38:47 +0800 Cc: gregkh@linuxfoundation.org, mathias.nyman@intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: To: Alan Stern X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Mar 6, 2020, at 03:02, Alan Stern wrote: > > On Thu, 5 Mar 2020, Kai-Heng Feng wrote: > >> On Dell TB16, Realtek USB ethernet (r8152) connects to an SMSC hub which >> then connects to ASMedia xHCI's root hub: >> >> /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M >> |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 5000M >> |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M >> >> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub >> Bus 004 Device 002: ID 0424:5537 Standard Microsystems Corp. USB5537B >> Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter >> >> The port is disabled after resume: >> xhci_hcd 0000:3f:00.0: Get port status 4-1 read: 0x280, return 0x280 >> >> According to xHCI 4.19.1.2.1, we should set link to RxDetect to transit >> it from disabled state to disconnected state, which allows the port to >> be set to U0 and completes the resume process. >> >> Signed-off-by: Kai-Heng Feng >> --- >> >> P.S. This is and differnt (and should be more correct) approach to solve >> https://lore.kernel.org/lkml/20191129174115.31683-1-kai.heng.feng@canonical.com/ >> >> drivers/usb/core/hub.c | 14 +++++++++++++- >> 1 file changed, 13 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c >> index 54cd8ef795ec..352e33c84d6a 100644 >> --- a/drivers/usb/core/hub.c >> +++ b/drivers/usb/core/hub.c >> @@ -3537,12 +3537,24 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) >> >> /* Skip the initial Clear-Suspend step for a remote wakeup */ >> status = hub_port_status(hub, port1, &portstatus, &portchange); >> - if (status == 0 && !port_is_suspended(hub, portstatus)) { >> + if (status == 0 && !port_is_suspended(hub, portstatus) >> + && (portstatus & USB_PORT_STAT_ENABLE)) { > > This doesn't look right. We want to skip the step the clears the > port's suspend feature whenever the feature is already clear, > regardless of whether the port is enabled. > > Besides, isn't this new test racy? Suppose the port was enabled when > we called hub_port_status above, but it got disabled in the nanoseconds > since then? > >> if (portchange & USB_PORT_STAT_C_SUSPEND) >> pm_wakeup_event(&udev->dev, 0); >> goto SuspendCleared; >> } >> >> + /* xHCI 4.19.1.2.1 */ >> + if (hub_is_superspeed(hub->hdev)) { >> + if (!(portstatus & USB_PORT_STAT_ENABLE)) >> + status = hub_set_port_link_state(hub, port1, >> + USB_SS_PORT_LS_RX_DETECT); >> + >> + if (status) >> + dev_dbg(&port_dev->dev, >> + "can't set to RxDetect, status %d\n", status); >> + } >> + > > So maybe this part belongs later in the routine. Or maybe it shouldn't > be in the hub driver at all -- since it is xHCI-specific, shouldn't it > go into the xhci-hcd driver? Ok, I'll put this change into xhci instead. It should also avoid the race you mentioned above. Kai-Heng > > Alan Stern > >> /* see 7.1.7.7; affects power usage, but not budgeting */ >> if (hub_is_superspeed(hub->hdev)) >> status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0);