Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6767798rwn; Tue, 13 Sep 2022 08:46:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR71PmKn5MmKr8smjqdkLTAoEpor+HkqwSZVfW8tijwilVjwv3PXzsa6jLSS3e+RsFxQRdcs X-Received: by 2002:a17:907:6e1c:b0:73d:7806:3c5e with SMTP id sd28-20020a1709076e1c00b0073d78063c5emr23301612ejc.36.1663083963346; Tue, 13 Sep 2022 08:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663083963; cv=none; d=google.com; s=arc-20160816; b=N1hOsuxwdVQ5p033yZp1FV9o3DDvuE1VTbBNjb95XoGC1L3kuRz/BwxijlSDiAHwV9 FNUo+S3bvLa4c/Cr8KRxy/JFkjCPuUBWY1Jnb1C5F6f9ka2ieDcmkA1ZSsQ/XMjQu3bC lue1Ca/5GHDe+eC6BmzkfOZxkGaPG42llO5YKnPSecNNhwi8tbWAe1/Xcv2e+116xnA/ 3RMTab10tzlEu0hFpVqdi4eQE/bpXTRurNARtXHDrhQsCqLdR4p3p5MULk8i6rWHKoH7 n+3Rehz6XJBvACpeXU/k1F9/MInJ+S19R2ZqFlvD/lxZc7/u25pJmD+kAtRDzF6z2jMO 0EQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tqzMmagYON5bESGYjpmC/OHMoXOT8Aap0C0GnpRCdY8=; b=QFoztcGsr3wsJB28HQwyARHE7g9stEmMaurElbhuNPumpss0uZd4Yahf3pgjOVwSFj CJn6qq5OEFlmIY5jTiUWqDx69wHIUB7iQf4jZSgWB00SEea3Oxy7OVEoU+e4KKNesl+Z P69JIDx4ttaXSslXuXpyRWtYwuU/YloSn2naCADQifAni0UYOdpRBn3FmuynFPHhXciI ilQaJ2yjBpW1X0GlmFHeBECrNHEvSAHP7mdOp4KHiqX58EuA1wGidPrzB8Fxfak+bnQp ZJg8F7QdWC7jr9Ks7qTq37+u/cVh+Nm0FF5fdWrcL72/V9L1m7tW824pofiPYvyrwHwX l7FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mg86VHa4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t25-20020a056402241900b0044ea553d7cdsi9470413eda.105.2022.09.13.08.45.28; Tue, 13 Sep 2022 08:46:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mg86VHa4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235714AbiIMPRl (ORCPT + 99 others); Tue, 13 Sep 2022 11:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235705AbiIMPQn (ORCPT ); Tue, 13 Sep 2022 11:16:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C145D1A3BB; Tue, 13 Sep 2022 07:34:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 71D8B614E5; Tue, 13 Sep 2022 14:32:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 864ADC433B5; Tue, 13 Sep 2022 14:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079543; bh=CuFPnUVGuG9hBco8DptOgD2OQllpbhmCOy7iqqU/xjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mg86VHa4PMxj1/YBxuMCtp7KY4ooDJoyrdvU6sm7So1XmMgZqkDbNZdLr3O7vWbPP PgKc2xJ58Fj9FNxuGDj5yz7wDA4TUAlyEjS5HcJ0caEFIwld+yTSwUpg9PZWI7SVaL 2PQVWmFzmxuP1cXZTfZtGl74bwck3p79tXgtwQ24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 4.19 32/79] xhci: Add grace period after xHC start to prevent premature runtime suspend. Date: Tue, 13 Sep 2022 16:06:50 +0200 Message-Id: <20220913140350.455005240@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140348.835121645@linuxfoundation.org> References: <20220913140348.835121645@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathias Nyman commit 33e321586e37b642ad10594b9ef25a613555cd08 upstream. After xHC controller is started, either in probe or resume, it can take a while before any of the connected usb devices are visible to the roothub due to link training. It's possible xhci driver loads, sees no acivity and suspends the host before the USB device is visible. In one testcase with a hotplugged xHC controller the host finally detected the connected USB device and generated a wake 500ms after host initial start. If hosts didn't suspend the device duringe training it probablty wouldn't take up to 500ms to detect it, but looking at specs reveal USB3 link training has a couple long timeout values, such as 120ms RxDetectQuietTimeout, and 360ms PollingLFPSTimeout. So Add a 500ms grace period that keeps polling the roothub for 500ms after start, preventing runtime suspend until USB devices are detected. Cc: stable@vger.kernel.org Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220825150840.132216-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-hub.c | 11 +++++++++++ drivers/usb/host/xhci.c | 4 +++- drivers/usb/host/xhci.h | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1464,6 +1464,17 @@ int xhci_hub_status_data(struct usb_hcd status = bus_state->resuming_ports; + /* + * SS devices are only visible to roothub after link training completes. + * Keep polling roothubs for a grace period after xHC start + */ + if (xhci->run_graceperiod) { + if (time_before(jiffies, xhci->run_graceperiod)) + status = 1; + else + xhci->run_graceperiod = 0; + } + mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC | PORT_CEC; /* For each port, did anything change? If so, set that bit in buf. */ --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -149,9 +149,11 @@ int xhci_start(struct xhci_hcd *xhci) xhci_err(xhci, "Host took too long to start, " "waited %u microseconds.\n", XHCI_MAX_HALT_USEC); - if (!ret) + if (!ret) { /* clear state flags. Including dying, halted or removing */ xhci->xhc_state = 0; + xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); + } return ret; } --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1811,7 +1811,7 @@ struct xhci_hcd { /* Host controller watchdog timer structures */ unsigned int xhc_state; - + unsigned long run_graceperiod; u32 command; struct s3_save s3; /* Host controller is dying - not responding to commands. "I'm not dead yet!"