From: Dongdong Liu <liudongdong3@huawei.com>
To: <helgaas@kernel.org>, <hch@infradead.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH V2 1/5] PCI: Use cached Device Capabilities 2 Register
Date: Tue, 11 May 2021 23:09:00 +0800 [thread overview]
Message-ID: <1620745744-91316-2-git-send-email-liudongdong3@huawei.com> (raw)
In-Reply-To: <1620745744-91316-1-git-send-email-liudongdong3@huawei.com>
It will make sense to store the devcap2 value in the pci_dev structure
instead of reading Device Capabilities 2 Register multiple times.
So we add pci_init_devcap2() to get the value of devcap2, then use
cached devcap2 in the needed place.
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 +---
drivers/pci/pci.c | 8 +++-----
drivers/pci/probe.c | 18 ++++++++++++------
include/linux/pci.h | 1 +
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 6264bc6..704d7c0 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -6303,7 +6303,6 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
struct pci_dev *pbridge;
struct port_info *pi;
char name[IFNAMSIZ];
- u32 devcap2;
u16 flags;
/* If we want to instantiate Virtual Functions, then our
@@ -6313,10 +6312,9 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
*/
pbridge = pdev->bus->self;
pcie_capability_read_word(pbridge, PCI_EXP_FLAGS, &flags);
- pcie_capability_read_dword(pbridge, PCI_EXP_DEVCAP2, &devcap2);
if ((flags & PCI_EXP_FLAGS_VERS) < 2 ||
- !(devcap2 & PCI_EXP_DEVCAP2_ARI)) {
+ !(pbridge->devcap2 & PCI_EXP_DEVCAP2_ARI)) {
/* Our parent bridge does not support ARI so issue a
* warning and skip instantiating the VFs. They
* won't be reachable.
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b717680..ed219d7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3690,7 +3690,7 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
{
struct pci_bus *bus = dev->bus;
struct pci_dev *bridge;
- u32 cap, ctl2;
+ u32 ctl2;
if (!pci_is_pcie(dev))
return -EINVAL;
@@ -3714,19 +3714,17 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
while (bus->parent) {
bridge = bus->self;
- pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
-
switch (pci_pcie_type(bridge)) {
/* Ensure switch ports support AtomicOp routing */
case PCI_EXP_TYPE_UPSTREAM:
case PCI_EXP_TYPE_DOWNSTREAM:
- if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
+ if (!(bridge->devcap2 & PCI_EXP_DEVCAP2_ATOMIC_ROUTE))
return -EINVAL;
break;
/* Ensure root port supports all the sizes we care about */
case PCI_EXP_TYPE_ROOT_PORT:
- if ((cap & cap_mask) != cap_mask)
+ if ((bridge->devcap2 & cap_mask) != cap_mask)
return -EINVAL;
break;
}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 3a62d09..e66bc14 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2098,7 +2098,7 @@ static void pci_configure_ltr(struct pci_dev *dev)
#ifdef CONFIG_PCIEASPM
struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
struct pci_dev *bridge;
- u32 cap, ctl;
+ u32 ctl;
if (!pci_is_pcie(dev))
return;
@@ -2106,8 +2106,7 @@ static void pci_configure_ltr(struct pci_dev *dev)
/* Read L1 PM substate capabilities */
dev->l1ss = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_L1SS);
- pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
- if (!(cap & PCI_EXP_DEVCAP2_LTR))
+ if (!(dev->devcap2 & PCI_EXP_DEVCAP2_LTR))
return;
pcie_capability_read_dword(dev, PCI_EXP_DEVCTL2, &ctl);
@@ -2147,13 +2146,11 @@ static void pci_configure_eetlp_prefix(struct pci_dev *dev)
#ifdef CONFIG_PCI_PASID
struct pci_dev *bridge;
int pcie_type;
- u32 cap;
if (!pci_is_pcie(dev))
return;
- pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
- if (!(cap & PCI_EXP_DEVCAP2_EE_PREFIX))
+ if (!(dev->devcap2 & PCI_EXP_DEVCAP2_EE_PREFIX))
return;
pcie_type = pci_pcie_type(dev);
@@ -2381,6 +2378,14 @@ void pcie_report_downtraining(struct pci_dev *dev)
__pcie_print_link_status(dev, false);
}
+static void pci_init_devcap2(struct pci_dev *dev)
+{
+ if (!pci_is_pcie(dev))
+ return;
+
+ pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &dev->devcap2);
+}
+
static void pci_init_capabilities(struct pci_dev *dev)
{
pci_ea_init(dev); /* Enhanced Allocation */
@@ -2457,6 +2462,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
{
int ret;
+ pci_init_devcap2(dev);
pci_configure_device(dev);
device_initialize(&dev->dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c20211e..3244b0b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -340,6 +340,7 @@ struct pci_dev {
u8 rom_base_reg; /* Config register controlling ROM */
u8 pin; /* Interrupt pin this device uses */
u16 pcie_flags_reg; /* Cached PCIe Capabilities Register */
+ u32 devcap2; /* Cached Device Capabilities 2 Register */
unsigned long *dma_alias_mask;/* Mask of enabled devfn aliases */
struct pci_driver *driver; /* Driver bound to this device */
--
2.7.4
next prev parent reply other threads:[~2021-05-11 15:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 15:08 [PATCH V2 0/5] PCI: Enable 10-Bit tag support for PCIe devices Dongdong Liu
2021-05-11 15:09 ` Dongdong Liu [this message]
2021-05-11 15:26 ` [PATCH V2 1/5] PCI: Use cached Device Capabilities 2 Register Christoph Hellwig
2021-05-12 7:29 ` Dongdong Liu
2021-05-11 15:09 ` [PATCH V2 2/5] PCI: Add 10-Bit Tag register definitions Dongdong Liu
2021-05-11 15:09 ` [PATCH V2 3/5] PCI: Enable 10-Bit tag support for PCIe Endpoint devices Dongdong Liu
2021-05-11 15:09 ` [PATCH V2 4/5] PCI/IOV: Enable 10-Bit tag support for PCIe VF devices Dongdong Liu
-- strict thread matches above, loose matches on Subject: below --
2021-05-11 13:59 [PATCH V2 0/5] PCI: Enable 10-Bit tag support for PCIe devices Dongdong Liu
2021-05-11 13:59 ` [PATCH V2 1/5] PCI: Use cached Device Capabilities 2 Register Dongdong Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1620745744-91316-2-git-send-email-liudongdong3@huawei.com \
--to=liudongdong3@huawei.com \
--cc=hch@infradead.org \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox