Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3718669ybl; Mon, 13 Jan 2020 01:11:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxCHCb7yuXXVtfx/zNrfu8RmYJQTb9cHMWRjBcavT6L/T3Krfmw/98IKLG844cDbgFB/ID+ X-Received: by 2002:aca:4dd6:: with SMTP id a205mr11425558oib.43.1578906681990; Mon, 13 Jan 2020 01:11:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578906681; cv=none; d=google.com; s=arc-20160816; b=WlxYLTp9utbsjo81v/FtwPP1Y+031g7BIhfg0He36ZIBKrMTysRtQN6io9bXh5eyFa MLupZAqwRESkRnXT95ytqDA7meffMbjedvxJ4gOg4ZkcLmM885m0Oouxx7/PWi3buYRd GSzFgHudehUqW+3TTu9zxJr9H8LVLITt/TKbAdf7zZGO+gayGY5WVwyO875j/0WxyEDW oAcqs9RxhlfaegfRDKURp9Q0wAON3yKKe43r3F6yLu1udRcrejyU0RGcbPrFioijgdG+ wulL1eOUW044oFCzCzaecL/xKeSb01JWyu+B0gG5bNkhchARZn67j3uUcoMJAUHUoaFk qeOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=mEdQLRNNr60Uq1X2SB+y192Ftk0ynyhp3ZNDXSiOKAQ=; b=vDvcIqhUZQ3wwSY9BKaFnRyf1EEZKkliG/pF3LqWvgg8XAyTGJjgbcd4Omm1VVUsn2 fI7YHDp4jSnRIoCtDnKdSBVzx1codfb4CEU+kMCbZ2NLVY8ZWsQoNOHaOeJksww6yJhJ GKyx7octVMRBdSajfEjkMPkP9hw4v3iwwxf2NaTynb+Njj64AUlH3GtsYjUF9qjQt2Iy gpxRU4EgDOkeQnGo5Ef7gn/ZrcGuehCDAm+b+gzYE3JAIZbWChRSVuzqlFCr0IMPGNHt BcapLQUlIKNagkGDDgM7gJ/Mk37m5qpSSPJ6GJgMNcRMXb24PW8SzTa8c8qg+8G5M/GV vPtw== 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 u16si6675677otg.325.2020.01.13.01.11.10; Mon, 13 Jan 2020 01:11:21 -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 S1726435AbgAMJKS (ORCPT + 99 others); Mon, 13 Jan 2020 04:10:18 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34768 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgAMJKR (ORCPT ); Mon, 13 Jan 2020 04:10:17 -0500 Received: from mail-oi1-f200.google.com ([209.85.167.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iqvji-0000pc-LQ for linux-kernel@vger.kernel.org; Mon, 13 Jan 2020 09:10:14 +0000 Received: by mail-oi1-f200.google.com with SMTP id u125so2880433oia.20 for ; Mon, 13 Jan 2020 01:10:14 -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:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mEdQLRNNr60Uq1X2SB+y192Ftk0ynyhp3ZNDXSiOKAQ=; b=ZDuUtxXP8lCfFmmKbHgRHfnbN1ufYkqKPzLomRLXV3ddQ4mcuLFIWqAfgSmTY/x8UF +fk+Dl9PF3Uh52mfnv8uUiBHrQWWJFLVZeh671dAlwSZP4l+Q0aMHW80FdnJZVMt3p2e OSuWdDG7Otlx9GCzBeaiCaxzR0zD+b8JQaeEHUGYTlpxU9Aihiq6J6uDDp6+gGvZDLs5 Y/kgJ7dKaHwfLl3+wPTdlkFmTthPigr1HUjlYQvKxTrdJLa4W9ThcDdEa+pozOjdWNJc cl/1q28bju4LsXKhKDHGf0OgDko74N+hX2CUr6RFBOBhxCSqTdcOqRSneawc/VarsO3c ms8w== X-Gm-Message-State: APjAAAVKywk5wTEZbGO4GXxgIbNC+HDDDN4qW2qipNCKkNO3USe518hB 9Tl8JnVDkQ2Egi9OWADpu1/a3qnEKGyfZOK1NEDJo9s6K7wXy2X0Ev9TTHLtIqrLOFUgPs2xovU ubaiU5TIdhzufgGnm3k8CElXBH/v7pqhFG69sjik1qQRqVXV1gQIqAnlAkQ== X-Received: by 2002:a05:6830:2116:: with SMTP id i22mr12892759otc.0.1578906613629; Mon, 13 Jan 2020 01:10:13 -0800 (PST) X-Received: by 2002:a05:6830:2116:: with SMTP id i22mr12892740otc.0.1578906613363; Mon, 13 Jan 2020 01:10:13 -0800 (PST) MIME-Version: 1.0 References: <20200103084008.3579-1-kai.heng.feng@canonical.com> <607e395f-21ce-3c9f-eff7-2fa6aaa74595@linux.intel.com> In-Reply-To: <607e395f-21ce-3c9f-eff7-2fa6aaa74595@linux.intel.com> From: Kai-Heng Feng Date: Mon, 13 Jan 2020 17:10:02 +0800 Message-ID: Subject: Re: [PATCH 1/3] xhci: Ensure link state is U3 after setting USB_SS_PORT_LS_U3 To: Mathias Nyman Cc: Mathias Nyman , Greg Kroah-Hartman , Alan Stern , AceLan Kao , USB list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 10, 2020 at 5:33 PM Mathias Nyman wrote: > > On 3.1.2020 10.40, Kai-Heng Feng wrote: > > The xHCI spec doesn't specify the upper bound of U3 transition time. For > > some devices 20ms is not enough, so we need to make sure the link state > > is in U3 before further actions. > > Looking at the USB 3.2 spec (7.2.4.2 Link Power management and Flow) it seems > most timers related to U3 entry are a lot less than a millisecond (4-16us) > If port is in U1/U2, Ux_EXIT_TIMER is 6ms which seems to be the longest timeout. > > If we anyway are polling for the U3 state we could shorten the initial 20ms sleep > down to 10ms. I think many devices, especially if they are already in U0 > could manage this. Ok. > > are > > > I've tried to use U3 Entry Capability by setting U3 Entry Enable in > > config register, however the port change event for U3 transition > > interrupts the system suspend process. > > > > For now let's use the less ideal method by polling PLS. > > > > Signed-off-by: Kai-Heng Feng > > --- > > drivers/usb/host/xhci-hub.c | 13 +++++++++++-- > > 1 file changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c > > index 7a3a29e5e9d2..2b2e9d004dbf 100644 > > --- a/drivers/usb/host/xhci-hub.c > > +++ b/drivers/usb/host/xhci-hub.c > > @@ -1228,6 +1228,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, > > break; > > case USB_PORT_FEAT_LINK_STATE: > > temp = readl(ports[wIndex]->addr); > > + xhci_dbg(xhci, "before setting link state, actual port %d-%d status = 0x%0x\n", hcd->self.busnum, wIndex + 1, temp); > > xhci_set_link_state() already shows similar debugging, Ok, will remove it. > > > /* Disable port */ > > if (link_state == USB_SS_PORT_LS_SS_DISABLED) { > > xhci_dbg(xhci, "Disable port %d\n", wIndex); > > @@ -1316,9 +1317,17 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, > > msleep(20); /* wait device to enter */ > > spin_lock_irqsave(&xhci->lock, flags); > > > > - temp = readl(ports[wIndex]->addr); > > - if (link_state == USB_SS_PORT_LS_U3) > > + if (link_state == USB_SS_PORT_LS_U3) { > > + retval = xhci_handshake(ports[wIndex]->addr, PORT_PLS_MASK, XDEV_U3, 80 * 1000); > > + if (retval) > > + xhci_dbg(xhci, "polling XDEV_U3 on port %d-%d timeout\n", hcd->self.busnum, wIndex + 1); > > In worst case we are busylooping for 80ms here, keeping the cpu busy. > It should be ok to sleep here, so how about just reading the register > every 10ms max 10 times, sleeping in between. Ok. Is the polling safe outside of spin_lock_irqsave()? Kai-Heng > > -Mathias