aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/access.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2015-06-24 17:05:54 -0400
committerBjorn Helgaas <bhelgaas@google.com>2015-07-14 18:39:32 -0400
commitffb4d602623aef9eb813a35b87b20854c030a2ec (patch)
tree3ea640404450d7799af06383025f652f884ead8b /drivers/pci/access.c
parente7f6c6d02cc3fa7f78153919900561bd1dce02a3 (diff)
PCI: Add pcie_downstream_port() (true for Root and Switch Downstream Ports)
As used in the PCIe spec, "Downstream Port" includes both Root Ports and Switch Downstream Ports. We sometimes checked for PCI_EXP_TYPE_DOWNSTREAM when we should have checked for PCI_EXP_TYPE_ROOT_PORT or PCI_EXP_TYPE_DOWNSTREAM. For a Root Port without a slot, the effect of this was that using pcie_capability_read_word() to read PCI_EXP_SLTSTA returned zero instead of showing the Presence Detect State bit hardwired to one as the PCIe Spec, r3.0, sec 7.8, requires. (This read is completed in software because previous PCIe spec versions didn't require PCI_EXP_SLTSTA to exist at all.) Nothing in the kernel currently depends on this (pciehp only reads PCI_EXP_SLTSTA on ports with slots), so this is a cleanup and not a functional change. Add a pcie_downstream_port() helper function and use it. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/pci/access.c')
-rw-r--r--drivers/pci/access.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index d9b64a175990..5465b005220c 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -531,6 +531,14 @@ static inline int pcie_cap_version(const struct pci_dev *dev)
531 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS; 531 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS;
532} 532}
533 533
534static bool pcie_downstream_port(const struct pci_dev *dev)
535{
536 int type = pci_pcie_type(dev);
537
538 return type == PCI_EXP_TYPE_ROOT_PORT ||
539 type == PCI_EXP_TYPE_DOWNSTREAM;
540}
541
534bool pcie_cap_has_lnkctl(const struct pci_dev *dev) 542bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
535{ 543{
536 int type = pci_pcie_type(dev); 544 int type = pci_pcie_type(dev);
@@ -546,10 +554,7 @@ bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
546 554
547static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev) 555static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev)
548{ 556{
549 int type = pci_pcie_type(dev); 557 return pcie_downstream_port(dev) &&
550
551 return (type == PCI_EXP_TYPE_ROOT_PORT ||
552 type == PCI_EXP_TYPE_DOWNSTREAM) &&
553 pcie_caps_reg(dev) & PCI_EXP_FLAGS_SLOT; 558 pcie_caps_reg(dev) & PCI_EXP_FLAGS_SLOT;
554} 559}
555 560
@@ -628,10 +633,9 @@ int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
628 * State bit in the Slot Status register of Downstream Ports, 633 * State bit in the Slot Status register of Downstream Ports,
629 * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8) 634 * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8)
630 */ 635 */
631 if (pci_is_pcie(dev) && pos == PCI_EXP_SLTSTA && 636 if (pci_is_pcie(dev) && pcie_downstream_port(dev) &&
632 pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) { 637 pos == PCI_EXP_SLTSTA)
633 *val = PCI_EXP_SLTSTA_PDS; 638 *val = PCI_EXP_SLTSTA_PDS;
634 }
635 639
636 return 0; 640 return 0;
637} 641}
@@ -657,10 +661,9 @@ int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val)
657 return ret; 661 return ret;
658 } 662 }
659 663
660 if (pci_is_pcie(dev) && pos == PCI_EXP_SLTCTL && 664 if (pci_is_pcie(dev) && pcie_downstream_port(dev) &&
661 pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) { 665 pos == PCI_EXP_SLTSTA)
662 *val = PCI_EXP_SLTSTA_PDS; 666 *val = PCI_EXP_SLTSTA_PDS;
663 }
664 667
665 return 0; 668 return 0;
666} 669}