Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp561670pxu; Wed, 7 Oct 2020 09:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgtHOBoUwgBvVbOeCKIXKa9s4bhh/KF11nfej/14ljvAmQrKeOg/uIlBnVASJrD7tp3o/4 X-Received: by 2002:aa7:dac4:: with SMTP id x4mr4455310eds.165.1602089741181; Wed, 07 Oct 2020 09:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602089741; cv=none; d=google.com; s=arc-20160816; b=Rui2rqLBZhdkEpo6D6W9uKL7s1DAcjN9+3sg+JNiW7dbdSgCCuc8u6VB/TsRM7Vf// Y0U+BP0Hg90LNLa24FxJf0v18BD7Cpiw7UkqpMhA8x9mH/JSVD0wQWhKu9nDz27oOjmX cDOkCPcZr95B0bapyaCPHwIfKCGNzFFat40UE4h4iFmYxPDC5kmMez8zUyVv5o5XrWj7 uUxs6FfWILL5LC3wwC6Fn6bVCjaUQzo8wgTYjjIvcU70GYbeQNe70FzuUVyAkX85lRAI jnr37/+HwpQQrqrs7ZT79VGAKrFlcIZZ7iUW/gQ+a5UtmaPYGLEYE/IPdzGicQQKuQ1z TFiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=0A+i/MnG7ofk1/uow7Ro700CbvukkHEpDKrbjreJTRc=; b=OHDJOihraVRhLviUjYrSvdkTPD+kkhURuo6mQe/6jIoxp2TjBmmFEO330Dobe+E935 n0YZqNQqfpHf5BOpO8rMnSLeNr8gq9Wyt38yYEQvv+O/IxjQFqyMaOf+QWMJngn9ZVqy GGdbdkfg7Cs2IhWgE3J0nNvw/XvoK276XV8CG2bzXqRnPch7N3kVAEZQScEHRGerXJCS Tp76+y/Ha5d1GXZSppNF9+MRzwnFim4oTrfuFkNo+tZ3NbWrkFAC5C6tz3uK9QGeyFl0 X6cDPSIeR0ZXa1nlbeEuNqWALDxB1xlQQX/mGvocfkZE+El9lHLq+XyR37nAcfVbd96x bnaw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si1882896ejy.388.2020.10.07.09.55.17; Wed, 07 Oct 2020 09:55:41 -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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728117AbgJGQx3 (ORCPT + 99 others); Wed, 7 Oct 2020 12:53:29 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:41754 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728046AbgJGQx3 (ORCPT ); Wed, 7 Oct 2020 12:53:29 -0400 Received: by mail-ot1-f66.google.com with SMTP id q21so2852483ota.8; Wed, 07 Oct 2020 09:53:28 -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:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0A+i/MnG7ofk1/uow7Ro700CbvukkHEpDKrbjreJTRc=; b=QHWWg0b8jTnc9x1ukbEWEcd0ak2+6OsQiKET89hEQni5yX3hKHdkuCd1H1+3ioUcN0 Gz9l9V20p+SUR5wmncysfoYoQf+hk97iyCkrIWNKF5AAROVfnfONOetp2fOXi7wk9/79 4hdHY44nh1zMyYjRxmAML99por+CTqQBmrEXoxVC5Nic1rrDoHwTqgQ3iuEjQ8FqPAl7 Y2oheFDKDkxso5hHHIAl1mgpbwl9kolslEF+hOEe8VZv0RjS9Kfp8SShALFMsCdvuqEO eaeOywcnKwNJxzSabcISDKifqQUImggOYDQZCaTEwa8UcsiIjPhHA8UkNfVQ8A7fDuof 4uxQ== X-Gm-Message-State: AOAM530ppGilp+870PRVH/jZOrNkl6g1zQXnxhJPldqgAB3Nevdm2hYn A+B4XTGbdbS0t92MU2JWFLEOXeT2GZXupXKcTKKxuLW/ X-Received: by 2002:a9d:3626:: with SMTP id w35mr2533946otb.206.1602089607809; Wed, 07 Oct 2020 09:53:27 -0700 (PDT) MIME-Version: 1.0 References: <20201007164851.1218-1-david.e.box@linux.intel.com> In-Reply-To: <20201007164851.1218-1-david.e.box@linux.intel.com> From: "Rafael J. Wysocki" Date: Wed, 7 Oct 2020 18:53:16 +0200 Message-ID: Subject: Re: [PATCH] PCI: Disable PTM during suspend on Intel PCI bridges To: "David E. Box" Cc: Bjorn Helgaas , Len Brown , "Rafael J. Wysocki" , Linux PCI , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 7, 2020 at 6:49 PM David E. Box wrote: > > On Intel Platform Controller Hubs (PCH) since Cannon Lake, the Precision > Time Measurement (PTM) capability can prevent PCIe root ports from power > gating during suspend-to-idle, causing increased power consumption on > systems that suspend using Low Power S0 Idle [1]. The issue is yet to be > root caused but believed to be coming from a race condition in the suspend > flow as the incidence rate varies for different platforms on Linux but the > issue does not occur at all in other operating systems. For now, disable > the feature on suspend on all Intel root ports and enable again on resume. IMV it should also be noted that there is no particular reason why PTM would need to be enabled while the whole system is suspended. At least it doesn't seem to be particularly useful in that state. > Link: https://www.uefi.org/sites/default/files/resources/Intel_ACPI_Low_Power_S0_Idle.pdf > Bug: https://bugzilla.kernel.org/show_bug.cgi?id=209361 > Tested-by: Len Brown > Signed-off-by: David E. Box > --- > drivers/pci/quirks.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c > index bdf9b52567e0..e82b1f60c7a1 100644 > --- a/drivers/pci/quirks.c > +++ b/drivers/pci/quirks.c > @@ -5632,3 +5632,60 @@ static void apex_pci_fixup_class(struct pci_dev *pdev) > } > DECLARE_PCI_FIXUP_CLASS_HEADER(0x1ac1, 0x089a, > PCI_CLASS_NOT_DEFINED, 8, apex_pci_fixup_class); > + > +#ifdef CONFIG_PCIE_PTM > +/* > + * On Intel Platform Controller Hubs (PCH) since Cannon Lake, the Precision > + * Time Measurement (PTM) capability can prevent the PCIe root port from > + * power gating during suspend-to-idle, causing increased power consumption. > + * So disable the feature on suspend on all Intel root ports and enable > + * again on resume. > + */ > +static void quirk_intel_ptm_disable_suspend(struct pci_dev *dev) > +{ > + int pos; > + u32 ctrl; > + > + if (!(dev->ptm_enabled && dev->ptm_root)) > + return; > + > + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PTM); > + if (!pos) > + return; > + > + pci_dbg(dev, "quirk: disabling PTM\n"); > + > + dev->ptm_enabled = 0; > + dev->ptm_root = 0; > + > + pci_read_config_dword(dev, pos + PCI_PTM_CTRL, &ctrl); > + ctrl &= ~(PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT); > + pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl); > +} > + > +static void quirk_intel_ptm_enable_resume(struct pci_dev *dev) > +{ > + int pos; > + u32 ctrl; > + > + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_PTM); > + if (!pos) > + return; > + > + pci_dbg(dev, "quirk: re-enabling PTM\n"); > + > + pci_read_config_dword(dev, pos + PCI_PTM_CTRL, &ctrl); > + ctrl |= PCI_PTM_CTRL_ENABLE | PCI_PTM_CTRL_ROOT; > + pci_write_config_dword(dev, pos + PCI_PTM_CTRL, ctrl); > + > + dev->ptm_enabled = 1; > + dev->ptm_root = 1; > +} > + > +DECLARE_PCI_FIXUP_CLASS_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, > + PCI_CLASS_BRIDGE_PCI, 8, > + quirk_intel_ptm_disable_suspend) > +DECLARE_PCI_FIXUP_CLASS_RESUME(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, > + PCI_CLASS_BRIDGE_PCI, 8, > + quirk_intel_ptm_enable_resume) > +#endif > -- > 2.20.1 >