Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4473851ybz; Tue, 28 Apr 2020 11:54:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIT09zbcFCfUY4kW60ts8ruHBrF/ebJCNUzRDZD/qWHymRVG6RupalYrCHrJ5tf6G5rb+GY X-Received: by 2002:a17:906:130d:: with SMTP id w13mr25490953ejb.253.1588100088419; Tue, 28 Apr 2020 11:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588100088; cv=none; d=google.com; s=arc-20160816; b=WmgTVu3VvX2Tq8R7gr1hWuumg2lcgH56fE+TXFbF2O0+yYku3jRosWu1+L/yHiwmH7 bAbyJulKYmMvHyp78SW3BziC68vcihz/TBEWgF0yOQaVN0trVKdLCJacd9/9hDDosRdE y3VXhIi3qMFYxpHqyD1G5tFrEZ34aLIgIW3aR8akYN0MsxtP1uol4rXKFFWZZjBKBPca nDe6forNxXDca1Gld1mq6KS0o4c4uQrmEqwfTxG5mBZsPPjshhqXgq1ltdMx7SlZ5QEh iftylU7na4DepmrFICfbyka0LIpONK5sKzA0Zz9wgcelj4yDa5HaaouIAfA4d1vwIS1t x4iQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tjiMizbmp6Zhvv/WRKrv2iiJVMEjFTIsyWG788QO5oQ=; b=NCJiZwTcduKevfpOyVC+OM6eUFZ1KvA6UQHxSDtRieaL3DljKWD4X2fbedNnQ5lvoh VA5KmhhqZ0175EBdEMwQ83EkrhCZFgcHz+BpIuoL8bXYpJPnLNXxNG4Y0Wkt/zBfAGLb 2/MMJ/A4cmMiscP3V4FeVJMZaIj4LaByz6y5wBqlG/7ATwNrNsuhybVs46PhY7Q6hm7J W0xMtA0cwOZEcQEVClRI2jYElhhICPxbtJ1Nt2mtgG9McFsdcCln0jJFRRxAMlISzOmx 2nVqB+CbJNs7HlVa92/Nt43Upu9GCLvTbfO/DL3lq15W4vAHLFmMflyh20cQwZ7druPs 9IDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wiN1zUt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si2354189ejb.521.2020.04.28.11.54.24; Tue, 28 Apr 2020 11:54:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wiN1zUt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730796AbgD1SwH (ORCPT + 99 others); Tue, 28 Apr 2020 14:52:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729631AbgD1Sge (ORCPT ); Tue, 28 Apr 2020 14:36:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 025A320575; Tue, 28 Apr 2020 18:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098993; bh=mbsr4pUywiBf3efxDxkiIZhl7JcP3EsZbHgjH0OG9wA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wiN1zUt2A7fFXda2P9cyS+mgleWgn5vf/7Dv7Mt+GIzQrLgkZNCVveXCxW1PX2AIk tvcxrgImrQ7GCETAI6fs0wnkeCzFkDpnyYS5ewRznsExmAn6QbMfQMeQYiTRk8N+HJ aSjWSqGLLpv9+2ElJA0LUawBA9RiUcaP/f4NPlBI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Sasha Levin Subject: [PATCH 5.4 043/168] xhci: Finetune host initiated USB3 rootport link suspend and resume Date: Tue, 28 Apr 2020 20:23:37 +0200 Message-Id: <20200428182237.291490232@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182231.704304409@linuxfoundation.org> References: <20200428182231.704304409@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathias Nyman [ Upstream commit ceca49382ac20e06ce04c21279c7f2868c4ec1d4 ] Depending on the current link state the steps to resume the link to U0 varies. The normal case when a port is suspended (U3) we set the link to U0 and wait for a port event when U3exit completed and port moved to U0. If the port is in U1/U2, then no event is issued, just set link to U0 If port is in Resume or Recovery state then the device has already initiated resume, and this host initiated resume is racing against it. Port event handler for device initiated resume will set link to U0, just wait for the port to reach U0 before returning. Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20200312144517.1593-9-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-hub.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 02f52d4f74df8..a9c87eb8951e8 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1307,20 +1307,34 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, goto error; } + /* + * set link to U0, steps depend on current link state. + * U3: set link to U0 and wait for u3exit completion. + * U1/U2: no PLC complete event, only set link to U0. + * Resume/Recovery: device initiated U0, only wait for + * completion + */ if (link_state == USB_SS_PORT_LS_U0) { - if ((temp & PORT_PLS_MASK) == XDEV_U0) - break; + u32 pls = temp & PORT_PLS_MASK; + bool wait_u0 = false; - if (!((temp & PORT_PLS_MASK) == XDEV_U1 || - (temp & PORT_PLS_MASK) == XDEV_U2 || - (temp & PORT_PLS_MASK) == XDEV_U3)) { - xhci_warn(xhci, "Can only set port %d to U0 from U state\n", - wIndex); - goto error; + /* already in U0 */ + if (pls == XDEV_U0) + break; + if (pls == XDEV_U3 || + pls == XDEV_RESUME || + pls == XDEV_RECOVERY) { + wait_u0 = true; + reinit_completion(&bus_state->u3exit_done[wIndex]); + } + if (pls <= XDEV_U3) /* U1, U2, U3 */ + xhci_set_link_state(xhci, ports[wIndex], + USB_SS_PORT_LS_U0); + if (!wait_u0) { + if (pls > XDEV_U3) + goto error; + break; } - reinit_completion(&bus_state->u3exit_done[wIndex]); - xhci_set_link_state(xhci, ports[wIndex], - USB_SS_PORT_LS_U0); spin_unlock_irqrestore(&xhci->lock, flags); if (!wait_for_completion_timeout(&bus_state->u3exit_done[wIndex], msecs_to_jiffies(100))) -- 2.20.1