Message ID | 20221119021411.1383248-5-david.e.box@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp523284wrr; Fri, 18 Nov 2022 18:34:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4VQet7okpPa3Zg8oxbXprAw6ezdrdyGp9/qqPNQ2azQ1/0ZTHn60QVPUkaoGdUn0Jw+nb5 X-Received: by 2002:a63:e509:0:b0:474:4380:cca6 with SMTP id r9-20020a63e509000000b004744380cca6mr9089392pgh.229.1668825259716; Fri, 18 Nov 2022 18:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668825259; cv=none; d=google.com; s=arc-20160816; b=sL2p9T0Kj9Vzuvq+1jCvAZ2DaidbfWnhK/WLKPhDAUxM9ukTPC3sB6lwPnMnQcPrD+ c3lFZzMfOCt+qME7udsKCuBJvtizsU07zPD03FGVP/C+berU+QFQvM92Oebd7mfNLy7U cLW2NhFavQXrjvslQy+8+xwKIWg3dx80ma0WRtF1+A1eLHugQUZ7EJXfga/GEiOrqu0c c0SH8Rqc6ry0/EpwYHz+Ssxw2Pm2jlJI47BYNyFstYUq/mpDOY7MmpWXBSRG75/teEah 1zacGTfn5J9Bayft1Ch2azt5Qg+6sbcO7jKl6J1AndRsqRDEHkfhPA7jUWT0y4153Net L8sA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AN3y3/lf9jUBuRSm5dowTkXFBWVvdiwZbUDUB15fGtk=; b=KfrsRiG+csX/1LRjFx1PAv4ABL7iq8UDJJ9diC23SFJjufmXoIqvqVfw8ktze3J7xq hUMkx2dGfI7mGSFaW2iCX8oKuJOrDZ0LKW0PiZc2hBosl9bCQCwx2qUzkV2OHCCewM1+ l1ovmjfRcEuH8jjvnperJV3nHgQSXiR5+FWUH+ppUAgfyVaht5khLenGudaAaILphvwY uo9wHY6cO1DDijuT2gAbD3LKpKLLbIhSbATr0VJGhc8e6JDJ0eGG+adpl/16RwhJsBz3 jocuGifysrC72HnX0OMhoZommOdJz+lv8SpdBZdOB9CmLlDBS3EgV6w1Z88YUYyoTGlP Pxlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AUGT0i2y; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t141-20020a635f93000000b004622caf9ac4si5462427pgb.805.2022.11.18.18.34.07; Fri, 18 Nov 2022 18:34:19 -0800 (PST) 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=@intel.com header.s=Intel header.b=AUGT0i2y; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236003AbiKSC0a (ORCPT <rfc822;kkmonlee@gmail.com> + 99 others); Fri, 18 Nov 2022 21:26:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235936AbiKSCYo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 18 Nov 2022 21:24:44 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD560C7599; Fri, 18 Nov 2022 18:15:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668824144; x=1700360144; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oeZu/jIyN1c5IQFJ1A7HgOl4IY4Uaxs22ZTpXdLDbgo=; b=AUGT0i2yZw3gwHddRNbW4qrRHXd9gduysswN87KvFC+yYbrxAmoqCyMs O9e7xJ2tVDYLK+1ZZDmEXw/Y02Xob8v7XPA/qSLgMZkLY5F7++PXhReiK YUicgPQ+Qmg0RtrYP7WO4TcYyBGieJ5B29/wnff5qJrZzTE6MVFsK4pHW V+WBoH7pOdKfkSFT+w6Ga5fqIFlHVKuqLmuEgqMaqjR92GbbtqHRUl/ig 4f4K8d8uji0HNFHrvlg/3gQ9DCPXwj4S23zjMY2RMG/t44a1KP9K1+qRj BH9oROqx32jRXTP3rObyY38WB2sQIzRkKK99T2aYEmSC89v68v68bRkcF w==; X-IronPort-AV: E=McAfee;i="6500,9779,10535"; a="315100484" X-IronPort-AV: E=Sophos;i="5.96,175,1665471600"; d="scan'208";a="315100484" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2022 18:14:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10535"; a="618225634" X-IronPort-AV: E=Sophos;i="5.96,175,1665471600"; d="scan'208";a="618225634" Received: from linux.intel.com ([10.54.29.200]) by orsmga006.jf.intel.com with ESMTP; 18 Nov 2022 18:14:12 -0800 Received: from debox1-desk4.lan (unknown [10.252.138.169]) by linux.intel.com (Postfix) with ESMTP id AB668580DFA; Fri, 18 Nov 2022 18:14:12 -0800 (PST) From: "David E. Box" <david.e.box@linux.intel.com> To: nirmal.patel@linux.intel.com, jonathan.derrick@linux.dev, lorenzo.pieralisi@arm.com, hch@infradead.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, david.e.box@linux.intel.com, michael.a.bottini@intel.com, rafael@kernel.org, me@adhityamohan.in Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V8 RESEND 4/4] PCI: vmd: Add quirk to configure PCIe ASPM and LTR Date: Fri, 18 Nov 2022 18:14:11 -0800 Message-Id: <20221119021411.1383248-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221119021411.1383248-1-david.e.box@linux.intel.com> References: <20221119021411.1383248-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749890115483337854?= X-GMAIL-MSGID: =?utf-8?q?1749890115483337854?= |
Series |
PCI: vmd: Enable PCIe ASPM and LTR on select
|
|
Commit Message
David E. Box
Nov. 19, 2022, 2:14 a.m. UTC
PCIe ports reserved for VMD use are not visible to BIOS and therefore not configured to enable PCIe ASPM or LTR values (which BIOS will configure if they are not set). Lack of this programming results in high power consumption on laptops as reported in bugzilla. For affected products use pci_enable_link_state to set the allowed link states for devices on the root ports. Also set the LTR value to the maximum value needed for the SoC. This is a workaround for products from Rocket Lake through Alder Lake. Raptor Lake, the latest product at this time, has already implemented LTR configuring in BIOS. Future products will move ASPM configuration back to BIOS as well. As this solution is intended for laptops, support is not added for hotplug or for devices downstream of a switch on the root port. Link: https://bugzilla.kernel.org/show_bug.cgi?id=212355 Link: https://bugzilla.kernel.org/show_bug.cgi?id=215063 Link: https://bugzilla.kernel.org/show_bug.cgi?id=213717 Signed-off-by: Michael Bottini <michael.a.bottini@linux.intel.com> Signed-off-by: David E. Box <david.e.box@linux.intel.com> Reviewed-by: Jon Derrick <jonathan.derrick@linux.dev> Reviewed-by: Nirmal Patel <nirmal.patel@linux.intel.com> --- V8 - Removed struct vmd_device_data patch. Instead use #define for the LTR value which is the same across all products needing the quirk. V7 - No change V6 - Set ASPM first before setting LTR. This is needed because some devices may only have LTR set by BIOS and not ASPM - Skip setting the LTR if the current LTR in non-zero. V5 - Provide the LTR value as driver data. - Use DWORD for the config space write to avoid PCI WORD access bug. - Set ASPM links firsts, enabling all link states, before setting a default LTR if the capability is present - Add kernel message that VMD is setting the device LTR. V4 - Refactor vmd_enable_apsm() to exit early, making the lines shorter and more readable. Suggested by Christoph. V3 - No changes V2 - Use return status to print pci_info message if ASPM cannot be enabled. - Add missing static declaration, caught by lkp@intel.com drivers/pci/controller/vmd.c | 64 ++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-)
Comments
HI, On 11/18/22 6:14 PM, David E. Box wrote: > PCIe ports reserved for VMD use are not visible to BIOS and therefore not > configured to enable PCIe ASPM or LTR values (which BIOS will configure if > they are not set). Lack of this programming results in high power > consumption on laptops as reported in bugzilla. For affected products use > pci_enable_link_state to set the allowed link states for devices on the > root ports. Also set the LTR value to the maximum value needed for the SoC. > > This is a workaround for products from Rocket Lake through Alder Lake. > Raptor Lake, the latest product at this time, has already implemented LTR > configuring in BIOS. Future products will move ASPM configuration back to > BIOS as well. As this solution is intended for laptops, support is not > added for hotplug or for devices downstream of a switch on the root port. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=212355 > Link: https://bugzilla.kernel.org/show_bug.cgi?id=215063 > Link: https://bugzilla.kernel.org/show_bug.cgi?id=213717 > > Signed-off-by: Michael Bottini <michael.a.bottini@linux.intel.com> > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > Reviewed-by: Jon Derrick <jonathan.derrick@linux.dev> > Reviewed-by: Nirmal Patel <nirmal.patel@linux.intel.com> > --- > V8 > - Removed struct vmd_device_data patch. Instead use #define for the LTR > value which is the same across all products needing the quirk. > V7 > - No change > V6 > - Set ASPM first before setting LTR. This is needed because some > devices may only have LTR set by BIOS and not ASPM > - Skip setting the LTR if the current LTR in non-zero. > V5 > - Provide the LTR value as driver data. > - Use DWORD for the config space write to avoid PCI WORD access bug. > - Set ASPM links firsts, enabling all link states, before setting a > default LTR if the capability is present > - Add kernel message that VMD is setting the device LTR. > V4 > - Refactor vmd_enable_apsm() to exit early, making the lines shorter > and more readable. Suggested by Christoph. > V3 > - No changes > V2 > - Use return status to print pci_info message if ASPM cannot be enabled. > - Add missing static declaration, caught by lkp@intel.com > > drivers/pci/controller/vmd.c | 64 ++++++++++++++++++++++++++++++++---- > 1 file changed, 58 insertions(+), 6 deletions(-) > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > index 86f3085db014..cba57e3091f6 100644 > --- a/drivers/pci/controller/vmd.c > +++ b/drivers/pci/controller/vmd.c > @@ -66,12 +66,22 @@ enum vmd_features { > * interrupt handling. > */ > VMD_FEAT_CAN_BYPASS_MSI_REMAP = (1 << 4), > + > + /* > + * Enable ASPM on the PCIE root ports and set the default LTR of the > + * storage devices on platforms where these values are not configured by > + * BIOS. This is needed for laptops, which require these settings for > + * proper power management of the SoC. > + */ > + VMD_FEAT_BIOS_PM_QUIRK = (1 << 5), > }; > > #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ > VMD_FEAT_HAS_BUS_RESTRICTIONS | \ > VMD_FEAT_OFFSET_FIRST_VECTOR) > > +#define VMD_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ > + > static DEFINE_IDA(vmd_instance_ida); > > /* > @@ -713,6 +723,46 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, > vmd_bridge->native_dpc = root_bridge->native_dpc; > } > > +/* > + * Enable ASPM and LTR settings on devices that aren't configured by BIOS. > + */ > +static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) > +{ > + unsigned long features = *(unsigned long *)userdata; > + u16 ltr = VMD_BIOS_PM_QUIRK_LTR; > + u32 ltr_reg; > + int pos; > + > + if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > + return 0; > + > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > + > + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > + if (!pos) > + return 0; > + > + /* > + * Skip if the max snoop LTR is non-zero, indicating BIOS has set it > + * so the LTR quirk is not needed. > + */ > + pci_read_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, <r_reg); > + if (!!(ltr_reg & (PCI_LTR_VALUE_MASK | PCI_LTR_SCALE_MASK))) > + return 0; > + > + /* > + * Set the default values to the maximum required by the platform to > + * allow the deepest power management savings. Write as a DWORD where > + * the lower word is the max snoop latency and the upper word is the > + * max non-snoop latency. > + */ > + ltr_reg = (ltr << 16) | ltr; > + pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg); > + pci_info(pdev, "VMD: Default LTR value set by driver\n"); > + > + return 0; > +} > + > static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) > { > struct pci_sysdata *sd = &vmd->sysdata; > @@ -867,6 +917,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) > pci_reset_bus(child->self); > pci_assign_unassigned_bus_resources(vmd->bus); > > + pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); > + > /* > * VMD root buses are virtual and don't return true on pci_is_pcie() > * and will fail pcie_bus_configure_settings() early. It can instead be > @@ -1005,17 +1057,17 @@ static const struct pci_device_id vmd_ids[] = { > VMD_FEAT_HAS_BUS_RESTRICTIONS | > VMD_FEAT_CAN_BYPASS_MSI_REMAP,}, > {PCI_VDEVICE(INTEL, 0x467f), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > {PCI_VDEVICE(INTEL, 0x4c3d), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > {PCI_VDEVICE(INTEL, 0xa77f), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > {PCI_VDEVICE(INTEL, 0x7d0b), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > {PCI_VDEVICE(INTEL, 0xad0b), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_VMD_9A0B), > - .driver_data = VMD_FEATS_CLIENT,}, > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, Why not add VMD_FEAT_BIOS_PM_QUIRK part of VMD_FEATS_CLIENT? > {0,} > }; > MODULE_DEVICE_TABLE(pci, vmd_ids);
On Fri, 2022-11-18 at 21:50 -0800, Sathyanarayanan Kuppuswamy wrote: > HI, > > On 11/18/22 6:14 PM, David E. Box wrote: > > PCIe ports reserved for VMD use are not visible to BIOS and therefore not > > configured to enable PCIe ASPM or LTR values (which BIOS will configure if > > they are not set). Lack of this programming results in high power > > consumption on laptops as reported in bugzilla. For affected products use > > pci_enable_link_state to set the allowed link states for devices on the > > root ports. Also set the LTR value to the maximum value needed for the SoC. > > > > This is a workaround for products from Rocket Lake through Alder Lake. > > Raptor Lake, the latest product at this time, has already implemented LTR > > configuring in BIOS. Future products will move ASPM configuration back to > > BIOS as well. As this solution is intended for laptops, support is not > > added for hotplug or for devices downstream of a switch on the root port. > > > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=212355 > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=215063 > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=213717 > > > > Signed-off-by: Michael Bottini <michael.a.bottini@linux.intel.com> > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > Reviewed-by: Jon Derrick <jonathan.derrick@linux.dev> > > Reviewed-by: Nirmal Patel <nirmal.patel@linux.intel.com> > > --- > > V8 > > - Removed struct vmd_device_data patch. Instead use #define for the LTR > > value which is the same across all products needing the quirk. > > V7 > > - No change > > V6 > > - Set ASPM first before setting LTR. This is needed because some > > devices may only have LTR set by BIOS and not ASPM > > - Skip setting the LTR if the current LTR in non-zero. > > V5 > > - Provide the LTR value as driver data. > > - Use DWORD for the config space write to avoid PCI WORD access bug. > > - Set ASPM links firsts, enabling all link states, before setting a > > default LTR if the capability is present > > - Add kernel message that VMD is setting the device LTR. > > V4 > > - Refactor vmd_enable_apsm() to exit early, making the lines shorter > > and more readable. Suggested by Christoph. > > V3 > > - No changes > > V2 > > - Use return status to print pci_info message if ASPM cannot be enabled. > > - Add missing static declaration, caught by lkp@intel.com > > > > drivers/pci/controller/vmd.c | 64 ++++++++++++++++++++++++++++++++---- > > 1 file changed, 58 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > > index 86f3085db014..cba57e3091f6 100644 > > --- a/drivers/pci/controller/vmd.c > > +++ b/drivers/pci/controller/vmd.c > > @@ -66,12 +66,22 @@ enum vmd_features { > > * interrupt handling. > > */ > > VMD_FEAT_CAN_BYPASS_MSI_REMAP = (1 << 4), > > + > > + /* > > + * Enable ASPM on the PCIE root ports and set the default LTR of the > > + * storage devices on platforms where these values are not > > configured by > > + * BIOS. This is needed for laptops, which require these settings > > for > > + * proper power management of the SoC. > > + */ > > + VMD_FEAT_BIOS_PM_QUIRK = (1 << 5), > > }; > > > > #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ > > VMD_FEAT_HAS_BUS_RESTRICTIONS | \ > > VMD_FEAT_OFFSET_FIRST_VECTOR) > > > > +#define VMD_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ > > + > > static DEFINE_IDA(vmd_instance_ida); > > > > /* > > @@ -713,6 +723,46 @@ static void vmd_copy_host_bridge_flags(struct > > pci_host_bridge *root_bridge, > > vmd_bridge->native_dpc = root_bridge->native_dpc; > > } > > > > +/* > > + * Enable ASPM and LTR settings on devices that aren't configured by BIOS. > > + */ > > +static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) > > +{ > > + unsigned long features = *(unsigned long *)userdata; > > + u16 ltr = VMD_BIOS_PM_QUIRK_LTR; > > + u32 ltr_reg; > > + int pos; > > + > > + if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > > + return 0; > > + > > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > > + > > + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > > + if (!pos) > > + return 0; > > + > > + /* > > + * Skip if the max snoop LTR is non-zero, indicating BIOS has set it > > + * so the LTR quirk is not needed. > > + */ > > + pci_read_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, <r_reg); > > + if (!!(ltr_reg & (PCI_LTR_VALUE_MASK | PCI_LTR_SCALE_MASK))) > > + return 0; > > + > > + /* > > + * Set the default values to the maximum required by the platform to > > + * allow the deepest power management savings. Write as a DWORD > > where > > + * the lower word is the max snoop latency and the upper word is the > > + * max non-snoop latency. > > + */ > > + ltr_reg = (ltr << 16) | ltr; > > + pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg); > > + pci_info(pdev, "VMD: Default LTR value set by driver\n"); > > + > > + return 0; > > +} > > + > > static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) > > { > > struct pci_sysdata *sd = &vmd->sysdata; > > @@ -867,6 +917,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, > > unsigned long features) > > pci_reset_bus(child->self); > > pci_assign_unassigned_bus_resources(vmd->bus); > > > > + pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); > > + > > /* > > * VMD root buses are virtual and don't return true on pci_is_pcie() > > * and will fail pcie_bus_configure_settings() early. It can instead > > be > > @@ -1005,17 +1057,17 @@ static const struct pci_device_id vmd_ids[] = { > > VMD_FEAT_HAS_BUS_RESTRICTIONS | > > VMD_FEAT_CAN_BYPASS_MSI_REMAP,}, > > {PCI_VDEVICE(INTEL, 0x467f), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > {PCI_VDEVICE(INTEL, 0x4c3d), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > {PCI_VDEVICE(INTEL, 0xa77f), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > {PCI_VDEVICE(INTEL, 0x7d0b), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > {PCI_VDEVICE(INTEL, 0xad0b), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_VMD_9A0B), > > - .driver_data = VMD_FEATS_CLIENT,}, > > + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, > > Why not add VMD_FEAT_BIOS_PM_QUIRK part of VMD_FEATS_CLIENT? Because our VMD team is in the middle of removing the need for the current on next gen. David > > > {0,} > > }; > > MODULE_DEVICE_TABLE(pci, vmd_ids); >
On 11/20/22 7:30 PM, David E. Box wrote: >>> + >>> static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) >>> { >>> struct pci_sysdata *sd = &vmd->sysdata; >>> @@ -867,6 +917,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, >>> unsigned long features) >>> pci_reset_bus(child->self); >>> pci_assign_unassigned_bus_resources(vmd->bus); >>> >>> + pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); >>> + >>> /* >>> * VMD root buses are virtual and don't return true on pci_is_pcie() >>> * and will fail pcie_bus_configure_settings() early. It can instead >>> be >>> @@ -1005,17 +1057,17 @@ static const struct pci_device_id vmd_ids[] = { >>> VMD_FEAT_HAS_BUS_RESTRICTIONS | >>> VMD_FEAT_CAN_BYPASS_MSI_REMAP,}, >>> {PCI_VDEVICE(INTEL, 0x467f), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >>> {PCI_VDEVICE(INTEL, 0x4c3d), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >>> {PCI_VDEVICE(INTEL, 0xa77f), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >>> {PCI_VDEVICE(INTEL, 0x7d0b), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >>> {PCI_VDEVICE(INTEL, 0xad0b), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >>> {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_VMD_9A0B), >>> - .driver_data = VMD_FEATS_CLIENT,}, >>> + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, >> Why not add VMD_FEAT_BIOS_PM_QUIRK part of VMD_FEATS_CLIENT? > Because our VMD team is in the middle of removing the need for the current on > next gen. You mean you may not need this quirk support from next gen? It looks like you are adding this quirk to all occurances of VMD_FEATS_CLIENT. So I am still not clear why we can't add it directly to that macro?
diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 86f3085db014..cba57e3091f6 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -66,12 +66,22 @@ enum vmd_features { * interrupt handling. */ VMD_FEAT_CAN_BYPASS_MSI_REMAP = (1 << 4), + + /* + * Enable ASPM on the PCIE root ports and set the default LTR of the + * storage devices on platforms where these values are not configured by + * BIOS. This is needed for laptops, which require these settings for + * proper power management of the SoC. + */ + VMD_FEAT_BIOS_PM_QUIRK = (1 << 5), }; #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ VMD_FEAT_HAS_BUS_RESTRICTIONS | \ VMD_FEAT_OFFSET_FIRST_VECTOR) +#define VMD_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ + static DEFINE_IDA(vmd_instance_ida); /* @@ -713,6 +723,46 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, vmd_bridge->native_dpc = root_bridge->native_dpc; } +/* + * Enable ASPM and LTR settings on devices that aren't configured by BIOS. + */ +static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) +{ + unsigned long features = *(unsigned long *)userdata; + u16 ltr = VMD_BIOS_PM_QUIRK_LTR; + u32 ltr_reg; + int pos; + + if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) + return 0; + + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); + + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); + if (!pos) + return 0; + + /* + * Skip if the max snoop LTR is non-zero, indicating BIOS has set it + * so the LTR quirk is not needed. + */ + pci_read_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, <r_reg); + if (!!(ltr_reg & (PCI_LTR_VALUE_MASK | PCI_LTR_SCALE_MASK))) + return 0; + + /* + * Set the default values to the maximum required by the platform to + * allow the deepest power management savings. Write as a DWORD where + * the lower word is the max snoop latency and the upper word is the + * max non-snoop latency. + */ + ltr_reg = (ltr << 16) | ltr; + pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg); + pci_info(pdev, "VMD: Default LTR value set by driver\n"); + + return 0; +} + static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) { struct pci_sysdata *sd = &vmd->sysdata; @@ -867,6 +917,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) pci_reset_bus(child->self); pci_assign_unassigned_bus_resources(vmd->bus); + pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); + /* * VMD root buses are virtual and don't return true on pci_is_pcie() * and will fail pcie_bus_configure_settings() early. It can instead be @@ -1005,17 +1057,17 @@ static const struct pci_device_id vmd_ids[] = { VMD_FEAT_HAS_BUS_RESTRICTIONS | VMD_FEAT_CAN_BYPASS_MSI_REMAP,}, {PCI_VDEVICE(INTEL, 0x467f), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {PCI_VDEVICE(INTEL, 0x4c3d), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {PCI_VDEVICE(INTEL, 0xa77f), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {PCI_VDEVICE(INTEL, 0x7d0b), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {PCI_VDEVICE(INTEL, 0xad0b), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_VMD_9A0B), - .driver_data = VMD_FEATS_CLIENT,}, + .driver_data = VMD_FEATS_CLIENT | VMD_FEAT_BIOS_PM_QUIRK,}, {0,} }; MODULE_DEVICE_TABLE(pci, vmd_ids);