From patchwork Sat Feb 15 00:03:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13975750 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C45EE4C92; Sat, 15 Feb 2025 00:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739577788; cv=none; b=GuKx3AZXYXz1DXaL5jORIiL1dIoSmVx8vr21JVaBAmYNPTFNrlhFqmYcp1hRA4Y7dENTwfiD2R4DbhWRP2RLPn1dsMudZzaUYsiFT6Dbz3bsMT/1qQQw88qrbtaRXEcVIYzdJWmhIY8nq/IfJd2hRyCly9k8UmpnWplPfFvWm2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739577788; c=relaxed/simple; bh=JIoKUIuy1b9eKZinQ1TLFl2oNjJg3VjzFrFTHpXj+AE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e5X4h/VVVFd/AEmPdrnbZJpTm6xYU/NxhUpwHKBX/sn1vxt+iAsFLBDrOSD2o5+FzSNKSDAoGKyuxTFHIO8+Ho3HbLjuf9KIzRfq8c/QhHtyMBj1Ie1Ux66j+nlViDMp9OXsjEePNfJTo7AUkmMT7Vir+/TnONFRw/AJzUwkXGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=En8CkHFw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="En8CkHFw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13C18C4CEE6; Sat, 15 Feb 2025 00:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739577788; bh=JIoKUIuy1b9eKZinQ1TLFl2oNjJg3VjzFrFTHpXj+AE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=En8CkHFwLyWFxCGpUuw40oavsHIn+F+OAzqsWeP/gyfaBPTF6Cift9f5+1sl1DcDi oc94Vv1WAqZpyz7Vb1n5VDVc15usF8HnLW9hwSTwpDo3bSoV+MXzaKPKzlO1ojbuSo YuJGSuoemD/GY3IeJS+NG5NsFMsQPAOXM2ZMCgrbLP+hJfbd7TUAnmSailV4BqWvTP bXcG21F6kKKfd56LJBbyOCrZFCKmHW9x++SQlA997l2Qgxx7q8DGNH3XfnxWBWJoED PgMuTV7/WvBj30miblF5Sp0fAyt3GqJDEBa1o9+x11q/YNPBMZBkxlgr9X6dZh6Q5d +iilWQrbDAWBQ== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Alex Williamson , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , =?utf-8?q?Ilpo_J?= =?utf-8?q?=C3=A4rvinen?= , linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 1/2] PCI: Avoid pointless capability searches Date: Fri, 14 Feb 2025 18:03:00 -0600 Message-Id: <20250215000301.175097-2-helgaas@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250215000301.175097-1-helgaas@kernel.org> References: <20250215000301.175097-1-helgaas@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bjorn Helgaas Many of the save/restore functions in the pci_save_state() and pci_restore_state() paths depend on both a PCI capability of the device and a pci_cap_saved_state structure to hold the configuration data, and they skip the operation if either is missing. Look for the pci_cap_saved_state first so if we don't have one, we can skip searching for the device capability, which requires several slow config space accesses. Remove some error messages if the pci_cap_saved_state is not found so we don't complain about having no saved state for a capability the device doesn't have. We have already warned in pci_allocate_cap_save_buffers() if the capability is present but we were unable to allocate a buffer. Other than the message change, no functional change intended. Signed-off-by: Bjorn Helgaas Reviewed-by: Ilpo Järvinen --- drivers/pci/pci.c | 27 ++++++++++++++------------- drivers/pci/pcie/aspm.c | 15 ++++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 869d204a70a3..503376bf7e75 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1686,10 +1686,8 @@ static int pci_save_pcie_state(struct pci_dev *dev) return 0; save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); - if (!save_state) { - pci_err(dev, "buffer not found in %s\n", __func__); + if (!save_state) return -ENOMEM; - } cap = (u16 *)&save_state->cap.data[0]; pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &cap[i++]); @@ -1742,19 +1740,17 @@ static void pci_restore_pcie_state(struct pci_dev *dev) static int pci_save_pcix_state(struct pci_dev *dev) { - int pos; struct pci_cap_saved_state *save_state; + u8 pos; + + save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); + if (!save_state) + return -ENOMEM; pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); if (!pos) return 0; - save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); - if (!save_state) { - pci_err(dev, "buffer not found in %s\n", __func__); - return -ENOMEM; - } - pci_read_config_word(dev, pos + PCI_X_CMD, (u16 *)save_state->cap.data); @@ -1763,14 +1759,19 @@ static int pci_save_pcix_state(struct pci_dev *dev) static void pci_restore_pcix_state(struct pci_dev *dev) { - int i = 0, pos; struct pci_cap_saved_state *save_state; + u8 pos; + int i = 0; u16 *cap; save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX); - pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); - if (!save_state || !pos) + if (!save_state) return; + + pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); + if (!pos) + return; + cap = (u16 *)&save_state->cap.data[0]; pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index e0bc90597dca..007e4a082e6f 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -35,16 +35,14 @@ void pci_save_ltr_state(struct pci_dev *dev) if (!pci_is_pcie(dev)) return; + save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR); + if (!save_state) + return; + ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); if (!ltr) return; - save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR); - if (!save_state) { - pci_err(dev, "no suspend buffer for LTR; ASPM issues possible after resume\n"); - return; - } - /* Some broken devices only support dword access to LTR */ cap = &save_state->cap.data[0]; pci_read_config_dword(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, cap); @@ -57,8 +55,11 @@ void pci_restore_ltr_state(struct pci_dev *dev) u32 *cap; save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR); + if (!save_state) + return; + ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); - if (!save_state || !ltr) + if (!ltr) return; /* Some broken devices only support dword access to LTR */ From patchwork Sat Feb 15 00:03:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13975751 X-Patchwork-Delegate: bhelgaas@google.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 189C31096F; Sat, 15 Feb 2025 00:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739577791; cv=none; b=G6SWmh5AeGcTMexa6xjzEOOJcCOwbjo8wtjmwYMRneEFfRt8msYLQYM0jog2/5KCddKnaO2hEESTvceBXnd9GLt9Ldt5x9jhR/SM3KrqQnWL1oKEtr6y+wQTpl5NKQz1klGgxRHEgtK5zpxsuxJyvUgEuDQ+ViBH17Ba4kAEM0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739577791; c=relaxed/simple; bh=LZmLoCUg08NiVuotxrtqAjBOOXyj6jZPtonN1xnIy4A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=uAvWmDvab+7X5HoVNSisVU4RQYbJeTKXBE4DIe1fmC7jTf3zJtVJv3hMgekeTyoKsM8p8iP0Awjqc3q3qOwWZ4R5PmxDilw41le9s0RZ+134yCu13koR0oZ5eQUDE6EBsCeO/03e8zQjkjBAF5826zNRL4KPAVtoqsthlnjf3oI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p35LgQoc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p35LgQoc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59C1BC4CED1; Sat, 15 Feb 2025 00:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739577790; bh=LZmLoCUg08NiVuotxrtqAjBOOXyj6jZPtonN1xnIy4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p35LgQocFaddJNP++Q2tfgtWsy/Rgk6APOwPSl9UKUkTfCTLhWekS0zCupTf0Rs1p FlipWpvQNwyUS+6tc0LnJxz6WGcCVNEgRbplqYxI/oyLu6NyuihfcutXwAaGe8AOgz tjAYb5POICChBpxb6YzwLM84muOIkb8OGWpt2YCmn09ZjhMQxm8UJzdFbI8hDGmV0K 5U7k4KQ/BFHo43RSVIpA7jW3J++E6/ZOofCy9gPlgqOi8xKt0SPPX4j2v0dk0QBmMB 1Pom8G2S8dlUywZWRyVmPNJSKRNyBi+EAetVWJEa4Fr0HVA9j3HHj4JZJ+UHwb9QxL Fp9pfx8rUXkuw== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Alex Williamson , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , =?utf-8?q?Ilpo_J?= =?utf-8?q?=C3=A4rvinen?= , linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v2 2/2] PCI: Cache offset of Resizable BAR capability Date: Fri, 14 Feb 2025 18:03:01 -0600 Message-Id: <20250215000301.175097-3-helgaas@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250215000301.175097-1-helgaas@kernel.org> References: <20250215000301.175097-1-helgaas@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bjorn Helgaas Previously most resizable BAR interfaces (pci_rebar_get_possible_sizes(), pci_rebar_set_size(), etc) as well as pci_restore_state() searched config space for a Resizable BAR capability. Most devices don't have such a capability, so this is wasted effort, especially for pci_restore_state(). Search for a Resizable BAR capability once at enumeration-time and cache the offset so we don't have to search every time we need it. No functional change intended. Signed-off-by: Bjorn Helgaas Reviewed-by: Ilpo Järvinen --- drivers/pci/pci.c | 9 +++++++-- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 1 + include/linux/pci.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 503376bf7e75..cf2632080a94 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1872,7 +1872,7 @@ static void pci_restore_rebar_state(struct pci_dev *pdev) unsigned int pos, nbars, i; u32 ctrl; - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); + pos = pdev->rebar_cap; if (!pos) return; @@ -3719,6 +3719,11 @@ void pci_acs_init(struct pci_dev *dev) pci_enable_acs(dev); } +void pci_rebar_init(struct pci_dev *pdev) +{ + pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); +} + /** * pci_rebar_find_pos - find position of resize ctrl reg for BAR * @pdev: PCI device @@ -3733,7 +3738,7 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar) unsigned int pos, nbars, i; u32 ctrl; - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); + pos = pdev->rebar_cap; if (!pos) return -ENOTSUPP; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 01e51db8d285..d7b46ddfd6d2 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -799,6 +799,7 @@ static inline int acpi_get_rc_resources(struct device *dev, const char *hid, } #endif +void pci_rebar_init(struct pci_dev *pdev); int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); static inline u64 pci_rebar_size_to_bytes(int size) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b6536ed599c3..24dd3dcfd223 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2564,6 +2564,7 @@ static void pci_init_capabilities(struct pci_dev *dev) pci_rcec_init(dev); /* Root Complex Event Collector */ pci_doe_init(dev); /* Data Object Exchange */ pci_tph_init(dev); /* TLP Processing Hints */ + pci_rebar_init(dev); /* Resizable BAR */ pcie_report_downtraining(dev); pci_init_reset_methods(dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 47b31ad724fa..9e5bbd996c83 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -353,6 +353,7 @@ struct pci_dev { struct pci_dev *rcec; /* Associated RCEC device */ #endif u32 devcap; /* PCIe Device Capabilities */ + u16 rebar_cap; /* Resizable BAR capability offset */ u8 pcie_cap; /* PCIe capability offset */ u8 msi_cap; /* MSI capability offset */ u8 msix_cap; /* MSI-X capability offset */