Message ID | 20230411213323.1362300-1-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:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2869965vqo; Tue, 11 Apr 2023 14:36:59 -0700 (PDT) X-Google-Smtp-Source: AKy350bm1NzzHRtZ9a50fpzuP0GItKCrQ25+pYeLIsuc0olxRHRSlY+fd8E3TDKofcnZx6NuLHoV X-Received: by 2002:a17:90b:3885:b0:244:a3b8:ea9f with SMTP id mu5-20020a17090b388500b00244a3b8ea9fmr19088804pjb.25.1681249019077; Tue, 11 Apr 2023 14:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681249019; cv=none; d=google.com; s=arc-20160816; b=RBFudut2BjVu4A/PQbDKB/pe4G2LmBasDiiKg7q15qiMN63U/jUPveB7CwqvDPdIvv iZExlUaOg0VoCGEdOApJq+RdXD0UAOyRjsPHmeNqHJZbgoKIWZaca8rLk6tI+GlRykIw fk+l3eadlK9L8tKxl2PxwpNK5QPg5EeGRc/jpZINDjLHqTHLEtXu2PDNmDRzNwlAU+WP vYR97xG+TtXcnUeAXobEHJX7ODDkkws1RlQFiK0OqnBv0EcfeA0KAYoEikv41meLA9YM SuNUe1tiwSFOf2KxhEjXnwEebGa9dCvHMJLR9+tJc56KLuH6M0iulOyb/nL6B+Ugp8YO dKFg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=ZI3Dq54SpvSwrA/+JOMXyDE8ZHEBHcnwXt7x4N7Doe8=; b=pP8LdjYY4Nw2aIe27oVSSvv/9BGF7uIxkx+fCmo6h0QDcNpW7UtmpbmDPJx3Fv6K36 CNBiy7U4frNWlkVrRIJ4+fWyTX4/2bQ2K7HcFjySjIM5oEMWgXvedCNg1vdDl8/+3I+v KyePVD6ekuqrqd+MnLbNhRLhSg90vzBUvg1B/f3lIEytVePx25aDedXdBqhvz7L3i+Ap JQdVtjVxmC4Qb/1oGd9Fkeh3AGJxii9CUBfo+w/RWWbohpiUTYtvkBU3y0q+A4kXA8Ie 9NVvYHCmzvgYLAFtTBeIMNTprUoxxFaqFrwp2VNUtdP39qSrATdp0+J1GIWfoZFOiYEE jUIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C9flPaXt; 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 u59-20020a17090a51c100b00244af8c2956si94456pjh.126.2023.04.11.14.36.47; Tue, 11 Apr 2023 14:36:59 -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=@intel.com header.s=Intel header.b=C9flPaXt; 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 S229451AbjDKVda (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 11 Apr 2023 17:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjDKVd2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Apr 2023 17:33:28 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569F64C2E; Tue, 11 Apr 2023 14:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681248807; x=1712784807; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Qbs/+BT7zaXH0NFJ1Etj/EqbkrZR4YTOBmmPKWBUP3c=; b=C9flPaXtToLgleIzt/nALNSQMxpPFms9FFn3H/OlU78I271HbjrSO+eE /E4wOs2ACux9mLwYbRfll6YAL4eD/+r/NnNBSszsQzH1iRJZc62Tg4FK0 R/qimeQ8f3KkHv0EY6sC02DcL7jZehQLNpsQ8Gux7K3ylJvLL6u6Q3C55 T3orG6WsElcHXK8MzI43xs26SAynf1et39KDzY//qw6uQTN4Avcrx6KcE VgkKz4ZipXNBEJOQEKjVWh8Mn7GF9QucCKn+pVIuR8nzCBiyMMQEJ6vm7 q9sGUeUPCEXlbqFwAs2D1KaigJPX5GZlcAZ7BPmfPrU/Dc1Vsh8qofEWL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10677"; a="408880800" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="408880800" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2023 14:33:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10677"; a="753285746" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="753285746" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 11 Apr 2023 14:33:26 -0700 Received: from debox1-desk4.lan (unknown [10.209.9.147]) by linux.intel.com (Postfix) with ESMTP id A8F65580AFF; Tue, 11 Apr 2023 14:33:25 -0700 (PDT) From: "David E. Box" <david.e.box@linux.intel.com> To: david.e.box@linux.intel.com, ville.syrjala@linux.intel.com, 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, michael.a.bottini@intel.com, rafael@kernel.org Cc: me@adhityamohan.in, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Subject: [PATCH V2] PCI: Move VMD ASPM/LTR fix to PCI quirk Date: Tue, 11 Apr 2023 14:33:23 -0700 Message-Id: <20230411213323.1362300-1-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 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, RCVD_IN_MSPIKE_H2,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?1762917371534999115?= X-GMAIL-MSGID: =?utf-8?q?1762917371534999115?= |
Series |
[V2] PCI: Move VMD ASPM/LTR fix to PCI quirk
|
|
Commit Message
David E. Box
April 11, 2023, 9:33 p.m. UTC
In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and
LTR") the VMD driver calls pci_enabled_link_state as a callback from
pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep
warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using
DECLARE_PCI_FIXUP_FINAL.
Fixes: f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR")
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---
V2 - Instead of adding a lock flag argument to pci_enabled_link_state, move
the fix to quirks.c
drivers/pci/controller/vmd.c | 55 +--------------------------
drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 54 deletions(-)
Comments
On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > LTR") the VMD driver calls pci_enabled_link_state as a callback from > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using > DECLARE_PCI_FIXUP_FINAL. s/pci_enabled_link_state/pci_enable_link_state/ Add "()" after pci_enable_link_state() and pci_bus_walk() to make it obvious they're functions. > ... > +++ b/drivers/pci/quirks.c > @@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); > #endif > + > +#ifdef CONFIG_VMD > +/* > + * Enable ASPM on the PCIE root ports under VMD 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. s/PCIE/PCIe/ to match spec usage. > + */ > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ It would be nice to know how this value was derived. But I know we had this hard-coded value before, so it's not new with this patch. > +static void quirk_intel_vmd(struct pci_dev *pdev) I think this quirk could possibly stay in drivers/pci/controller/vmd.c, couldn't it? It has a lot of VMD-specific knowledge that it would nice to contain in vmd.c. > +{ > + struct pci_dev *parent; > + u16 ltr = VMD_DEVICE_LTR; I don't think "ltr" is an improvement over using "VMD_DEVICE_LTR" below. > + u32 ltr_reg; > + int pos; > + > + /* Check in VMD domain */ > + if (pci_domain_nr(pdev->bus) < 0x10000) > + return; If in vmd.c, maybe could identify devices under a VMD by checking pdev->bus->ops as vmd_acpi_find_companion() does? > + /* Get Root Port */ > + parent = pci_upstream_bridge(pdev); > + if (!parent || parent->vendor != PCI_VENDOR_ID_INTEL) > + return; > + > + /* Get VMD Host Bridge */ > + parent = to_pci_dev(parent->dev.parent); > + if (!parent) > + return; > + > + /* Get RAID controller */ > + parent = to_pci_dev(parent->dev.parent); > + if (!parent) > + return; > + > + switch (parent->device) { > + case 0x467f: > + case 0x4c3d: > + case 0xa77f: > + case 0x7d0b: > + case 0xad0b: > + case 0x9a0b: > + break; > + default: > + return; > + } > + > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); Seems like you would want to set LTR *before* enabling the link states? > + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > + if (!pos) > + return; > + > + /* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ > + 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; > + > + /* > + * Set the LTR 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. This comment suggests that the LTR value is platform-dependent, which is what I would expect, but the code and the hard-coded VMD_DEVICE_LTR value don't have any platform dependencies. Again, nothing new in *this* patch; that's true in the current tree, too. > + ltr_reg = (ltr << 16) | ltr; > + pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg); > + pci_info(pdev, "LTR set by VMD PCI quick\n"); s/quick/quirk/ > + > +} > +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, > + PCI_CLASS_STORAGE_EXPRESS, 0, quirk_intel_vmd); > +#endif > -- > 2.34.1 >
Hi Bjorn, On Thu, 2023-06-08 at 15:52 -0500, Bjorn Helgaas wrote: > On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > > LTR") the VMD driver calls pci_enabled_link_state as a callback from > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using > > DECLARE_PCI_FIXUP_FINAL. > > s/pci_enabled_link_state/pci_enable_link_state/ > > Add "()" after pci_enable_link_state() and pci_bus_walk() to make it > obvious they're functions. > > > ... > > +++ b/drivers/pci/quirks.c > > @@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, > > dpc_log_size); > > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); > > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); > > #endif > > + > > +#ifdef CONFIG_VMD > > +/* > > + * Enable ASPM on the PCIE root ports under VMD 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. > > s/PCIE/PCIe/ to match spec usage. > > > + */ > > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ > > It would be nice to know how this value was derived. But I know we > had this hard-coded value before, so it's not new with this patch. Do you mean to show the multiplier that determines that value or to say why this particular number was chosen? For the latter, it the largest that could be set (given the multipier options) that will allow the SoC to get to it's lowest power state. And it's the same so far on all the SoCs covered by the VMD driver. > > > +static void quirk_intel_vmd(struct pci_dev *pdev) > > I think this quirk could possibly stay in > drivers/pci/controller/vmd.c, couldn't it? It has a lot of > VMD-specific knowledge that it would nice to contain in vmd.c. I may have misunderstood your comment on V1 then. But you suggested that this would be typically done as PCI_FIXUP so that the PCI core could call it and we could avoid the locking issue that was seen while walking the bus in vmd.c. https://lore.kernel.org/lkml/ab9bf3032ed46fc0586e089edc5aac6e71b331d8.camel@linux.intel.com/T/#m09dc05ef56b8d9f104f91594f582251b6088d24d > > > +{ > > + struct pci_dev *parent; > > + u16 ltr = VMD_DEVICE_LTR; > > I don't think "ltr" is an improvement over using "VMD_DEVICE_LTR" > below. > > > + u32 ltr_reg; > > + int pos; > > + > > + /* Check in VMD domain */ > > + if (pci_domain_nr(pdev->bus) < 0x10000) > > + return; > > If in vmd.c, maybe could identify devices under a VMD by checking > pdev->bus->ops as vmd_acpi_find_companion() does? > > > + /* Get Root Port */ > > + parent = pci_upstream_bridge(pdev); > > + if (!parent || parent->vendor != PCI_VENDOR_ID_INTEL) > > + return; > > + > > + /* Get VMD Host Bridge */ > > + parent = to_pci_dev(parent->dev.parent); > > + if (!parent) > > + return; > > + > > + /* Get RAID controller */ > > + parent = to_pci_dev(parent->dev.parent); > > + if (!parent) > > + return; > > + > > + switch (parent->device) { > > + case 0x467f: > > + case 0x4c3d: > > + case 0xa77f: > > + case 0x7d0b: > > + case 0xad0b: > > + case 0x9a0b: > > + break; > > + default: > > + return; > > + } > > + > > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > > Seems like you would want to set LTR *before* enabling the link > states? Yes that would be better. We'll still want to check if the LTR is set first though because if it is then we don't need to do either. David > > > + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > > + if (!pos) > > + return; > > + > > + /* Skip if the max snoop LTR is non-zero, indicating BIOS has set it > > */ > > + 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; > > + > > + /* > > + * Set the LTR 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. > > This comment suggests that the LTR value is platform-dependent, which > is what I would expect, but the code and the hard-coded VMD_DEVICE_LTR > value don't have any platform dependencies. Again, nothing new in > *this* patch; that's true in the current tree, too. > > > + ltr_reg = (ltr << 16) | ltr; > > + pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_reg); > > + pci_info(pdev, "LTR set by VMD PCI quick\n"); > > s/quick/quirk/ > > > + > > +} > > +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, > > + PCI_CLASS_STORAGE_EXPRESS, 0, > > quirk_intel_vmd); > > +#endif > > -- > > 2.34.1 > >
On Fri, Jun 09, 2023 at 03:09:26PM -0700, David E. Box wrote: > Hi Bjorn, > > On Thu, 2023-06-08 at 15:52 -0500, Bjorn Helgaas wrote: > > On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > > > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > > > LTR") the VMD driver calls pci_enabled_link_state as a callback from > > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > > > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using > > > DECLARE_PCI_FIXUP_FINAL. > > > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ > > > > It would be nice to know how this value was derived. But I know we > > had this hard-coded value before, so it's not new with this patch. > > Do you mean to show the multiplier that determines that value or to > say why this particular number was chosen? For the latter, it the > largest that could be set (given the multipier options) that will > allow the SoC to get to it's lowest power state. And it's the same > so far on all the SoCs covered by the VMD driver. Oh, sorry, I meant "why this number was chosen". PCIe r6.0, sec 7.8.2, says this capability allows software to provide "platform latency information," so I assume this is somehow dependent on platform, but I really don't understand the details of how LTR works, and we didn't have an explanation before, so this was just a "if you happen to know, it might be useful here" comment. > > > +static void quirk_intel_vmd(struct pci_dev *pdev) > > > > I think this quirk could possibly stay in > > drivers/pci/controller/vmd.c, couldn't it? It has a lot of > > VMD-specific knowledge that it would nice to contain in vmd.c. > > I may have misunderstood your comment on V1 then. But you suggested > that this would be typically done as PCI_FIXUP so that the PCI core > could call it and we could avoid the locking issue that was seen > while walking the bus in vmd.c. Right, I think it makes sense to be a DECLARE_PCI_FIXUP_CLASS_FINAL(), but I was thinking that it could be implemented in vmd.c and still be called by the PCI core. But now I'm uncertain since vmd.c can be compiled as a module, and I'm not sure how that could work, since pci_fixup_device() calls things in the __start_pci_fixups_final[] table, and I don't see how loading a module would insert the fixup entry into that table. So maybe it needs to be in quirks.c after all. I think my only remaining questions here are about how to identify devices below VMD and the order of enabling ASPM states vs setting LTR. Bjorn
On Fri, 2023-06-09 at 17:46 -0500, Bjorn Helgaas wrote: > On Fri, Jun 09, 2023 at 03:09:26PM -0700, David E. Box wrote: > > Hi Bjorn, > > > > On Thu, 2023-06-08 at 15:52 -0500, Bjorn Helgaas wrote: > > > On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > > > > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > > > > LTR") the VMD driver calls pci_enabled_link_state as a callback from > > > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a > > > > lockdep > > > > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c > > > > using > > > > DECLARE_PCI_FIXUP_FINAL. > > > > > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ > > > > > > It would be nice to know how this value was derived. But I know we > > > had this hard-coded value before, so it's not new with this patch. > > > > Do you mean to show the multiplier that determines that value or to > > say why this particular number was chosen? For the latter, it the > > largest that could be set (given the multipier options) that will > > allow the SoC to get to it's lowest power state. And it's the same > > so far on all the SoCs covered by the VMD driver. > > Oh, sorry, I meant "why this number was chosen". PCIe r6.0, sec > 7.8.2, says this capability allows software to provide "platform > latency information," so I assume this is somehow dependent on > platform, but I really don't understand the details of how LTR works, > and we didn't have an explanation before, so this was just a "if you > happen to know, it might be useful here" comment. Sure. > > > > > +static void quirk_intel_vmd(struct pci_dev *pdev) > > > > > > I think this quirk could possibly stay in > > > drivers/pci/controller/vmd.c, couldn't it? It has a lot of > > > VMD-specific knowledge that it would nice to contain in vmd.c. > > > > I may have misunderstood your comment on V1 then. But you suggested > > that this would be typically done as PCI_FIXUP so that the PCI core > > could call it and we could avoid the locking issue that was seen > > while walking the bus in vmd.c. > > Right, I think it makes sense to be a DECLARE_PCI_FIXUP_CLASS_FINAL(), > but I was thinking that it could be implemented in vmd.c and still be > called by the PCI core. > > But now I'm uncertain since vmd.c can be compiled as a module, and I'm > not sure how that could work, since pci_fixup_device() calls things in > the __start_pci_fixups_final[] table, and I don't see how loading a > module would insert the fixup entry into that table. > > So maybe it needs to be in quirks.c after all. Okay. > > I think my only remaining questions here are about how to identify > devices below VMD and the order of enabling ASPM states vs setting > LTR. Agree on setting the LTR first. I'll also look at other ways to identify devices below VMD. David
On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > LTR") the VMD driver calls pci_enabled_link_state as a callback from > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using > DECLARE_PCI_FIXUP_FINAL. What happened to this patch? We're still carrying a local fix for this in drm-tip... > > Fixes: f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") > Suggested-by: Bjorn Helgaas <bhelgaas@google.com> > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > --- > > V2 - Instead of adding a lock flag argument to pci_enabled_link_state, move > the fix to quirks.c > > drivers/pci/controller/vmd.c | 55 +-------------------------- > drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 73 insertions(+), 54 deletions(-) > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > index 990630ec57c6..47fa3e5f2dc5 100644 > --- a/drivers/pci/controller/vmd.c > +++ b/drivers/pci/controller/vmd.c > @@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ > - > #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ > VMD_FEAT_HAS_BUS_RESTRICTIONS | \ > - VMD_FEAT_OFFSET_FIRST_VECTOR | \ > - VMD_FEAT_BIOS_PM_QUIRK) > + VMD_FEAT_OFFSET_FIRST_VECTOR) > > static DEFINE_IDA(vmd_instance_ida); > > @@ -724,46 +713,6 @@ 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; > @@ -936,8 +885,6 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) > > 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 > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c > index 44cab813bf95..2d86623f96e3 100644 > --- a/drivers/pci/quirks.c > +++ b/drivers/pci/quirks.c > @@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); > #endif > + > +#ifdef CONFIG_VMD > +/* > + * Enable ASPM on the PCIE root ports under VMD 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. > + */ > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ > +static void quirk_intel_vmd(struct pci_dev *pdev) > +{ > + struct pci_dev *parent; > + u16 ltr = VMD_DEVICE_LTR; > + u32 ltr_reg; > + int pos; > + > + /* Check in VMD domain */ > + if (pci_domain_nr(pdev->bus) < 0x10000) > + return; > + > + /* Get Root Port */ > + parent = pci_upstream_bridge(pdev); > + if (!parent || parent->vendor != PCI_VENDOR_ID_INTEL) > + return; > + > + /* Get VMD Host Bridge */ > + parent = to_pci_dev(parent->dev.parent); > + if (!parent) > + return; > + > + /* Get RAID controller */ > + parent = to_pci_dev(parent->dev.parent); > + if (!parent) > + return; > + > + switch (parent->device) { > + case 0x467f: > + case 0x4c3d: > + case 0xa77f: > + case 0x7d0b: > + case 0xad0b: > + case 0x9a0b: > + break; > + default: > + return; > + } > + > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > + > + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > + if (!pos) > + return; > + > + /* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ > + 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; > + > + /* > + * Set the LTR 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, "LTR set by VMD PCI quick\n"); > + > +} > +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, > + PCI_CLASS_STORAGE_EXPRESS, 0, quirk_intel_vmd); > +#endif > -- > 2.34.1
On Tue, 24 Oct 2023, Ville Syrjälä wrote: > On Tue, Apr 11, 2023 at 02:33:23PM -0700, David E. Box wrote: > > In commit f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and > > LTR") the VMD driver calls pci_enabled_link_state as a callback from > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > > warning. Instead of doing the pci_bus_walk, move the fix to quirks.c using > > DECLARE_PCI_FIXUP_FINAL. > > What happened to this patch? We're still carrying a local fix > for this in drm-tip... > > > > > Fixes: f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") > > Suggested-by: Bjorn Helgaas <bhelgaas@google.com> > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > --- > > > > V2 - Instead of adding a lock flag argument to pci_enabled_link_state, move > > the fix to quirks.c > > > > drivers/pci/controller/vmd.c | 55 +-------------------------- > > drivers/pci/quirks.c | 72 ++++++++++++++++++++++++++++++++++++ > > 2 files changed, 73 insertions(+), 54 deletions(-) > > > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > > index 990630ec57c6..47fa3e5f2dc5 100644 > > --- a/drivers/pci/controller/vmd.c > > +++ b/drivers/pci/controller/vmd.c > > @@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ > > - > > #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ > > VMD_FEAT_HAS_BUS_RESTRICTIONS | \ > > - VMD_FEAT_OFFSET_FIRST_VECTOR | \ > > - VMD_FEAT_BIOS_PM_QUIRK) > > + VMD_FEAT_OFFSET_FIRST_VECTOR) > > > > static DEFINE_IDA(vmd_instance_ida); > > > > @@ -724,46 +713,6 @@ 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; > > @@ -936,8 +885,6 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) > > > > 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 > > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c > > index 44cab813bf95..2d86623f96e3 100644 > > --- a/drivers/pci/quirks.c > > +++ b/drivers/pci/quirks.c > > @@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); > > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); > > DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); > > #endif > > + > > +#ifdef CONFIG_VMD > > +/* > > + * Enable ASPM on the PCIE root ports under VMD 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. > > + */ > > +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ This should be defined using FIELD_PREP()s. It is better to construct both snoop and nosnoop registers here and not do the shift below at all. There are new defines for the nosnoop reg in pci/field-get branch for the nosnoop reg fields.
diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 990630ec57c6..47fa3e5f2dc5 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -66,22 +66,11 @@ 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_BIOS_PM_QUIRK_LTR 0x1003 /* 3145728 ns */ - #define VMD_FEATS_CLIENT (VMD_FEAT_HAS_MEMBAR_SHADOW_VSCAP | \ VMD_FEAT_HAS_BUS_RESTRICTIONS | \ - VMD_FEAT_OFFSET_FIRST_VECTOR | \ - VMD_FEAT_BIOS_PM_QUIRK) + VMD_FEAT_OFFSET_FIRST_VECTOR) static DEFINE_IDA(vmd_instance_ida); @@ -724,46 +713,6 @@ 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; @@ -936,8 +885,6 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) 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 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 44cab813bf95..2d86623f96e3 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -6023,3 +6023,75 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size); DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size); #endif + +#ifdef CONFIG_VMD +/* + * Enable ASPM on the PCIE root ports under VMD 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. + */ +#define VMD_DEVICE_LTR 0x1003 /* 3145728 ns */ +static void quirk_intel_vmd(struct pci_dev *pdev) +{ + struct pci_dev *parent; + u16 ltr = VMD_DEVICE_LTR; + u32 ltr_reg; + int pos; + + /* Check in VMD domain */ + if (pci_domain_nr(pdev->bus) < 0x10000) + return; + + /* Get Root Port */ + parent = pci_upstream_bridge(pdev); + if (!parent || parent->vendor != PCI_VENDOR_ID_INTEL) + return; + + /* Get VMD Host Bridge */ + parent = to_pci_dev(parent->dev.parent); + if (!parent) + return; + + /* Get RAID controller */ + parent = to_pci_dev(parent->dev.parent); + if (!parent) + return; + + switch (parent->device) { + case 0x467f: + case 0x4c3d: + case 0xa77f: + case 0x7d0b: + case 0xad0b: + case 0x9a0b: + break; + default: + return; + } + + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); + + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); + if (!pos) + return; + + /* Skip if the max snoop LTR is non-zero, indicating BIOS has set it */ + 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; + + /* + * Set the LTR 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, "LTR set by VMD PCI quick\n"); + +} +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, + PCI_CLASS_STORAGE_EXPRESS, 0, quirk_intel_vmd); +#endif