Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp630009ybm; Wed, 22 May 2019 08:57:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwL0FkaUe+OOhhimWB2UC34wEgagw3XFX6d9mx36bFzgAH0M5nMKRp44bZDyL72SX0/MsVb X-Received: by 2002:aa7:8d50:: with SMTP id s16mr35040794pfe.96.1558540667105; Wed, 22 May 2019 08:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558540667; cv=none; d=google.com; s=arc-20160816; b=jtx7wsZyWrdGGTqcXZRRRsv44tYBbx2vGsEW8fOZeZV1OF+9bTVdVBu7HPQp4pSC9Z ui1WU43UmEBQPYJA+7Q7YhiKWqCNDu4RaY1tO0OH2eqK2CkigNn1/ro6ltXDbGnaseTc 5E7UkmVQpkaDiSXR/RoH0ocjCqCbZ31YWUdDR8xyu/ETeyRjb5pegO/t5E7deT2KlPOn IY+2MTrhwQ4Etv4JcAVITWd7ECvgci8JWQvAJ05uoi+QAClFsZ3RUNybVjI+UpRn9l8i q5Iy970Fzxmd3EUwJsgI7qWLipnCbkwIzVPqlw98YlkJMMhu/KicKhtN7KikLGXFAOYz qIfQ== 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=Gny7zpyg4/tKr9ea5waidyxUOOMNEMCWZX6A3ecAUbs=; b=O1xIYLSHgqdSwPU0ciUuuDl0EWF/UFJh5cF7rtIm6WMXqEiDCg3xiRWtX8wuzeusqM aARQFtJoyNa2XBzgTBGonQa0pe4SgqVvFoXq4B2ghTtxEq9klqu8aJZFDvignB0nbMq+ 7Uj7i6/F/Yw1qwnLzLbLg+urzHoNp0LTJBWA0vKXehjGYvsEGG7GqgsrikSSNQgvIXZs D20oQ4O8aB/n1FP6odzyEXxGWwho9JIDWXl1GbhHq16gLU9/FSH/XECQ7qQ6UyaLwTGd QgpHe4yweev43QVO3CYueaP4wUmOHmpo0EJwcZ4hncN94tN6bOjqbi8RpaIPADONCFCq LHxQ== 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 w207si28665701pff.69.2019.05.22.08.57.31; Wed, 22 May 2019 08:57:47 -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 S1729767AbfEVPq2 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 22 May 2019 11:46:28 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54953 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729638AbfEVPq1 (ORCPT ); Wed, 22 May 2019 11:46:27 -0400 Received: from mail-pl1-f197.google.com ([209.85.214.197]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hTTRh-00048F-FE for linux-kernel@vger.kernel.org; Wed, 22 May 2019 15:46:25 +0000 Received: by mail-pl1-f197.google.com with SMTP id h12so1580360pll.20 for ; Wed, 22 May 2019 08:46:25 -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=CNOZQ1DIO+Q7gA/QrNVP/yBFpd3UL1O9kI3xP9DfOhM=; b=Tbi6nQljRxaQ0hmwmcmGB1wSEKbvSX89UJHu7zrzYx8foYwB9oX78eCPwYo4LdPtET CRgWwaLmNev3tn0hTyrc74W86rYWmtAQHL+U1yAABF31JI45nUCIkhPbgvxOZHW5UxiW +DtSGPO+ymEicOFXJCsEeMMVgX6KDJ+TfBSq2lqF7KFzS7uUQLKRtCnWr9UfFnNQw3el Xj9Jn5Iz84v7jh9LNmUYCuuBsHWbK56SVKM6jxU3eUWXCWKWDshRtcP6qyLiw8WIsNdP 3//bGb1x4RltTOt7pQ05dnJqblgMyk635TaGD2T39uXIO0SgK4usvEdmnu7udS6DAtXW TjJA== X-Gm-Message-State: APjAAAXPpVrv9V0Zq4I2SRixGRCbGDB10rNpZZ/l8F5JbM/aElI3yhGI p92KM4VVWCQDuZ0nRzDX32QH45TcgfX2nW53pnhllNA1thu7NOqNyUqGHEUqlK1CYnaCooLikMG ffZPlb7TtawNhPAlZ7+NUPIJS6Nrp8pppPJA+0M4GFw== X-Received: by 2002:aa7:9159:: with SMTP id 25mr65759196pfi.64.1558539984186; Wed, 22 May 2019 08:46:24 -0700 (PDT) X-Received: by 2002:aa7:9159:: with SMTP id 25mr65759173pfi.64.1558539983851; Wed, 22 May 2019 08:46:23 -0700 (PDT) Received: from [192.168.1.220] (220-133-187-190.HINET-IP.hinet.net. [220.133.187.190]) by smtp.gmail.com with ESMTPSA id s134sm37011467pfc.110.2019.05.22.08.46.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 08:46:23 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH] PCI / PM: Don't runtime suspend when device only supports wakeup from D0 From: Kai Heng Feng In-Reply-To: <20190522134854.GA79339@google.com> Date: Wed, 22 May 2019 23:46:25 +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> <20190522134854.GA79339@google.com> To: Bjorn Helgaas X-Mailer: Apple Mail (2.3445.104.11) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On May 22, 2019, at 9:48 PM, Bjorn Helgaas wrote: > > On Wed, May 22, 2019 at 11:42:14AM +0800, Kai Heng Feng wrote: >> at 6:23 AM, Bjorn Helgaas wrote: >>> 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. >>> >>> 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. > > I see your bug report (https://bugzilla.kernel.org/show_bug.cgi?id=203673) > but it doesn't say anything about what this looks like to a user. > Presumably somebody complained about something not working. The bug > report should include that information about what isn't working. > Ideally, a user experiencing a problem should be able to google for > the symptoms and find the bug report. Sorry about that. I’ve added a comment to describe the symptom. > >>>> 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. >>> >>> What does "runtime suspended to D0" mean? > > If I understand correctly, Linux normally clears PME-Enable while > devices are in D0, but sets PME-Enable if a device is "runtime > suspended to D0”. Yes, this is what happens here. > > I'm not sure I'd describe that as "suspended", since the power > management state is exactly D0 and the only difference is that a PME > interrupt is enabled. It sounds to me like the xHCI controller is > basically using PME as a hotplug interrupt to say "something happened > on my secondary (USB) interface". But that's more a question for > Rafael. Runtime suspend routines are called successfully, so I think it’s still logically suspended. > > And I guess this patch basically means we wouldn't call the driver's > suspend callback if we're merely going to stay at D0, so the driver > would have no idea anything happened. That might match > Documentation/power/pci.txt better, because it suggests that the > suspend callback is related to putting a device in a low-power state, > and D0 is not a low-power state. Yes, the patch is to let the device stay at D0 and don’t run driver’s own runtime suspend routine. I guess I’ll just proceed to send a V2 with updated commit message? Kai-Heng > > Maybe we should also update Documentation/power/pci.txt to say "PCI > devices ... can be programmed to generate PMEs while in any state > (D0-D3)" instead of "a low-power state (D1-D3)”. > > Anyway, this is all Rafael's area, so I'll defer to him. > >>>> 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 >> >>