Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1741092ybm; Tue, 21 May 2019 20:45:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlOP5Dt5CXrGigv1RP79Y1h3jr8pFI5Aay6fgSE0doWNocnSpN/QxERvvm6faasAga93/y X-Received: by 2002:a17:902:201:: with SMTP id 1mr42782402plc.263.1558496713006; Tue, 21 May 2019 20:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558496712; cv=none; d=google.com; s=arc-20160816; b=bmneaR0Q6n28FBhll+uW3nJREraaYaSTDAB+aZbr7J/TInzDPhyMNAZZityyRokNa8 6qoCTo/DikkoO+KmW2DCGZS03ZBT+ls3RmWVH//i93KA2rBC1EJvBJ/9/n9cijUgD/p0 jM6L+36JpRtvcg3TPwxmH4bDZaL+giVsRbGaMDlNr5iEiknRzzdp9RrFD9sKzdqgWpJP OFfcme+3bc7Z6dzlPsMnxD9hhf6iOQzEgjJsk7GaFEGhyJM5nMzpP3UjZSV93jqdibEi M+pdCwXDmZtISSeAWiyDNEyapQGPgF09s8mCyEB66dVLouX+q6uHqWj2DMTjpjFW/wDW 9/Aw== 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=NPTfaApxYhJLazeTc6j/yypjFDd8f8Hs9lpKwzlxSxg=; b=VAFqniGYkYSKlIFE05ERQW/ckD2HByfgnL09iLgsvA0cf/UwRb3BSqm1c0axtWZlPF ld6DOFiWd8IYVF+YsQTwLMZdV8htzOa6o0xTeql+NDkihPz7I6NzLhyvp2+dy0HHDb6m zQnQYDNEZNWdl56So32MlPONvffs+fOMraIiupPOB9dg077cYdlKRmQPaBKznd7yDy+H pRHpuVMw/uRQkcweG7Hm7gcMnFqXW1BMevllk6e6nLhnTBJnPhwip6/ljS6H0w6WXVez BCtmJG+RUxig/hjZEEWm0HWEX3yPnyo5SSmaBbDCHJnw8jspkN5Lp0iGg6n6JaTpcKDu cpkQ== 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 f5si13505599pgg.19.2019.05.21.20.44.56; Tue, 21 May 2019 20:45:12 -0700 (PDT) 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 S1728370AbfEVDmV (ORCPT + 99 others); Tue, 21 May 2019 23:42:21 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36542 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728162AbfEVDmV (ORCPT ); Tue, 21 May 2019 23:42:21 -0400 Received: from mail-pf1-f200.google.com ([209.85.210.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hTI8w-00045F-Ut for linux-kernel@vger.kernel.org; Wed, 22 May 2019 03:42:19 +0000 Received: by mail-pf1-f200.google.com with SMTP id k22so831957pfg.18 for ; Tue, 21 May 2019 20:42:18 -0700 (PDT) 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=NPTfaApxYhJLazeTc6j/yypjFDd8f8Hs9lpKwzlxSxg=; b=aG3rpC1K5pl29A/j/bBkqAJCllT0ykAMFbcNkOgoWyw6y6fTs+XVay+PluIrPI+7JW M3WrUkHQlbjclo/WiYAHomII+22kaJdFPTaTr6WjJhbV/9G0nScs7UcgfXm8wHit68Dy xQODzQ8nzS91yFFizwnyWNnqOAAPV0JrwonXQOp1/+ydO0x6vDzE1TlmjO2nj9MVWoOT gVKKdmhKvPHkeh2TQFjLgTrT+PvrevjhPqgGurT5nkeeq/WH1pMdeGPUu9aCkg7VosSC 1InG++hgwOcaesff8OcCU5h9AQZdLzOKZPq3hCdi5l6gZEL+8546Exi9j59qDMdwUJKZ 7xKw== X-Gm-Message-State: APjAAAUlRvsmmb0IMO1hHtSW99jA5I6yso2TgxFcXRsYVFWlwJ7ycp6A KNk+O7PIqy6NhgBwRYk4ZNYEzneRfYbDFa6pZZ8xSa7pibTEFbwZyYpkIgkdV8999zdP6/3/BsU K1V/EWaIkSaEe48bh0Q2tys8fQUNkU2fi9NFKVHxG9w== X-Received: by 2002:a63:fd4a:: with SMTP id m10mr86016123pgj.302.1558496537571; Tue, 21 May 2019 20:42:17 -0700 (PDT) X-Received: by 2002:a63:fd4a:: with SMTP id m10mr86016105pgj.302.1558496537321; Tue, 21 May 2019 20:42:17 -0700 (PDT) Received: from [10.101.46.168] (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id s134sm34046394pfc.110.2019.05.21.20.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 20:42:16 -0700 (PDT) Content-Type: text/plain; charset=utf-8; delsp=yes; format=flowed Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: [PATCH] PCI / PM: Don't runtime suspend when device only supports wakeup from D0 From: Kai Heng Feng In-Reply-To: <20190521222300.GG57618@google.com> Date: Wed, 22 May 2019 11:42:14 +0800 Cc: Rafael Wysocki , linux-pci@vger.kernel.org, LKML , Mathias Nyman , linux-usb@vger.kernel.org Content-Transfer-Encoding: 8bit Message-Id: References: <20190521163104.15759-1-kai.heng.feng@canonical.com> <20190521222300.GG57618@google.com> To: Bjorn Helgaas X-Mailer: Apple Mail (2.3445.104.8) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org at 6:23 AM, Bjorn Helgaas wrote: > [+cc Mathias, linux-usb] > > On Wed, May 22, 2019 at 12:31:04AM +0800, Kai-Heng Feng wrote: >> There's an xHC device that doesn't wake when a USB device gets plugged >> to its USB port. The driver's own runtime suspend callback was called, >> PME signaling was enabled, but it stays at PCI D0. > > s/xHC/xHCI/ ? > > This looks like it's fixing a bug? If so, please include a link to > the bug report, and make sure the bug report has "lspci -vv" output > attached to it. Ok, I’ll update this in V2. > >> A PCI device can be runtime suspended to D0 when it supports D0 PME and >> its _S0W reports D0. Theoratically this should work, but as [1] >> specifies, D0 doesn't have wakeup capability. > > s/Theoratically/Theoretically/ Ok. > > What does "runtime suspended to D0" mean? It’s runtime suspended by PCI core, but stays at D0. > Is that different from the regular "device is fully operational" sort of D0? Yes it's different to that. Because of _S0W reports D0 and the device has D0 PME support, so it’s “suspended” to D0: 00:10.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] FCH USB XHCI Controller [1022:7914] (rev 20) (prog-if 30 [XHCI]) Subsystem: Dell FCH USB XHCI Controller [1028:096c] Control: I/O- Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR- If so, what > distinguishes "runtime suspended D0" from "normal fully operational > D0”? The xHC’s own runtime suspend routine is called, but PCI core’s runtime suspend routine decides it should stay at D0. So it’s technically runtime suspended to D0. Kai-Heng > >> To avoid this problematic situation, we should avoid runtime suspend if >> D0 is the only state that can wake up the device. >> >> [1] >> https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/device-working-state-d0 >> >> Signed-off-by: Kai-Heng Feng >> --- >> drivers/pci/pci-driver.c | 5 +++++ >> drivers/pci/pci.c | 2 +- >> include/linux/pci.h | 3 +++ >> 3 files changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c >> index cae630fe6387..15a6310c5d7b 100644 >> --- a/drivers/pci/pci-driver.c >> +++ b/drivers/pci/pci-driver.c >> @@ -1251,6 +1251,11 @@ static int pci_pm_runtime_suspend(struct device >> *dev) >> return 0; >> } >> >> + if (pci_target_state(pci_dev, device_can_wakeup(dev)) == PCI_D0) { >> + dev_dbg(dev, "D0 doesn't have wakeup capability\n"); >> + return -EBUSY; >> + } >> + >> pci_dev->state_saved = false; >> if (pm && pm->runtime_suspend) { >> error = pm->runtime_suspend(dev); >> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c >> index 8abc843b1615..ceee6efbbcfe 100644 >> --- a/drivers/pci/pci.c >> +++ b/drivers/pci/pci.c >> @@ -2294,7 +2294,7 @@ EXPORT_SYMBOL(pci_wake_from_d3); >> * If the platform can't manage @dev, return the deepest state from which it >> * can generate wake events, based on any available PME info. >> */ >> -static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) >> +pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) >> { >> pci_power_t target_state = PCI_D3hot; >> >> diff --git a/include/linux/pci.h b/include/linux/pci.h >> index 4a5a84d7bdd4..91e8dc4d04aa 100644 >> --- a/include/linux/pci.h >> +++ b/include/linux/pci.h >> @@ -1188,6 +1188,7 @@ bool pci_pme_capable(struct pci_dev *dev, >> pci_power_t state); >> void pci_pme_active(struct pci_dev *dev, bool enable); >> int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable); >> int pci_wake_from_d3(struct pci_dev *dev, bool enable); >> +pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup); >> int pci_prepare_to_sleep(struct pci_dev *dev); >> int pci_back_from_sleep(struct pci_dev *dev); >> bool pci_dev_run_wake(struct pci_dev *dev); >> @@ -1672,6 +1673,8 @@ static inline int pci_set_power_state(struct >> pci_dev *dev, pci_power_t state) >> { return 0; } >> static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable) >> { return 0; } >> +pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) >> +{ return PCI_D0; } >> static inline pci_power_t pci_choose_state(struct pci_dev *dev, >> pm_message_t state) >> { return PCI_D0; } >> -- >> 2.17.1