Commit 69139244 authored by Amey Narkhede's avatar Amey Narkhede Committed by Bjorn Helgaas

PCI: Cache PCIe Device Capabilities register

Add a new member called devcap in struct pci_dev for caching the PCIe
Device Capabilities register to avoid reading PCI_EXP_DEVCAP multiple
times.

Refactor pcie_has_flr() to use cached device capabilities.

Link: https://lore.kernel.org/r/20210817180500.1253-2-ameynarkhede03@gmail.comSigned-off-by: default avatarAmey Narkhede <ameynarkhede03@gmail.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarRaphael Norwitz <raphael.norwitz@nutanix.com>
parent e73f0f0e
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <asm/dma.h> #include <asm/dma.h>
#include <linux/aer.h> #include <linux/aer.h>
#include <linux/bitfield.h>
#include "pci.h" #include "pci.h"
DEFINE_MUTEX(pci_slot_mutex); DEFINE_MUTEX(pci_slot_mutex);
...@@ -4630,13 +4631,10 @@ EXPORT_SYMBOL(pci_wait_for_pending_transaction); ...@@ -4630,13 +4631,10 @@ EXPORT_SYMBOL(pci_wait_for_pending_transaction);
*/ */
bool pcie_has_flr(struct pci_dev *dev) bool pcie_has_flr(struct pci_dev *dev)
{ {
u32 cap;
if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET)
return false; return false;
pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap); return FIELD_GET(PCI_EXP_DEVCAP_FLR, dev->devcap) == 1;
return cap & PCI_EXP_DEVCAP_FLR;
} }
EXPORT_SYMBOL_GPL(pcie_has_flr); EXPORT_SYMBOL_GPL(pcie_has_flr);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/hypervisor.h> #include <linux/hypervisor.h>
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/bitfield.h>
#include "pci.h" #include "pci.h"
#define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */
...@@ -1498,8 +1499,8 @@ void set_pcie_port_type(struct pci_dev *pdev) ...@@ -1498,8 +1499,8 @@ void set_pcie_port_type(struct pci_dev *pdev)
pdev->pcie_cap = pos; pdev->pcie_cap = pos;
pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16); pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
pdev->pcie_flags_reg = reg16; pdev->pcie_flags_reg = reg16;
pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16); pci_read_config_dword(pdev, pos + PCI_EXP_DEVCAP, &pdev->devcap);
pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; pdev->pcie_mpss = FIELD_GET(PCI_EXP_DEVCAP_PAYLOAD, pdev->devcap);
parent = pci_upstream_bridge(pdev); parent = pci_upstream_bridge(pdev);
if (!parent) if (!parent)
......
...@@ -333,6 +333,7 @@ struct pci_dev { ...@@ -333,6 +333,7 @@ struct pci_dev {
struct rcec_ea *rcec_ea; /* RCEC cached endpoint association */ struct rcec_ea *rcec_ea; /* RCEC cached endpoint association */
struct pci_dev *rcec; /* Associated RCEC device */ struct pci_dev *rcec; /* Associated RCEC device */
#endif #endif
u32 devcap; /* PCIe Device Capabilities */
u8 pcie_cap; /* PCIe capability offset */ u8 pcie_cap; /* PCIe capability offset */
u8 msi_cap; /* MSI capability offset */ u8 msi_cap; /* MSI capability offset */
u8 msix_cap; /* MSI-X capability offset */ u8 msix_cap; /* MSI-X capability offset */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment