[PATCH v5 1/5] PCI: Consistently report presence of PCIe link registers

From: Maciej W. Rozycki
Date: Sat Sep 17 2022 - 08:03:28 EST


Consistently with commit c8b303d0206b ("PCI: Remove PCIe Capability
version checks") only consider the PCI Express capability's Link Control
2, etc. registers present if the Link Control register is.

Before said commit with PCI Express capability versions higher than one
all link registers used to be considered present, however starting from
said commit Link Control, etc. original registers are only considered
present in devices with links, but Link Control 2, etc. registers
continue being considered always present even though likewise they are
only present in devices with links.

Fix the inconsistency then.

Signed-off-by: Maciej W. Rozycki <macro@xxxxxxxxxxx>
---
New change in v5.
---
drivers/pci/access.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

linux-pcie-cap-has-lnkctl2.diff
Index: linux-macro/drivers/pci/access.c
===================================================================
--- linux-macro.orig/drivers/pci/access.c
+++ linux-macro/drivers/pci/access.c
@@ -350,6 +350,11 @@ bool pcie_cap_has_lnkctl(const struct pc
type == PCI_EXP_TYPE_PCIE_BRIDGE;
}

+static inline bool pcie_cap_has_lnkctl2(const struct pci_dev *dev)
+{
+ return pcie_cap_has_lnkctl(dev) && pcie_cap_version(dev) > 1;
+}
+
static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev)
{
return pcie_downstream_port(dev) &&
@@ -390,10 +395,11 @@ static bool pcie_capability_reg_implemen
return pcie_cap_has_rtctl(dev);
case PCI_EXP_DEVCAP2:
case PCI_EXP_DEVCTL2:
+ return pcie_cap_version(dev) > 1;
case PCI_EXP_LNKCAP2:
case PCI_EXP_LNKCTL2:
case PCI_EXP_LNKSTA2:
- return pcie_cap_version(dev) > 1;
+ return pcie_cap_has_lnkctl2(dev);
default:
return false;
}