PCI: add pci_pcie_cap2() check for PCIe feature capabilities >= v2
authorMyron Stowe <myron.stowe@redhat.com>
Fri, 1 Jun 2012 21:16:37 +0000 (15:16 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 12 Jun 2012 02:41:23 +0000 (20:41 -0600)
commitc463b8cb9350cf1230cefe467a1cf279140a5437
tree396a615ecee1763411ba5c5f61b13315aab0a219
parentcb97ae3485955401d637bd269b0d24d3cd3fd3ec
PCI: add pci_pcie_cap2() check for PCIe feature capabilities >= v2

This patch resolves potential issues when accessing PCI Express
Capability structures.  The makeup of the capability varies
substantially between v1 and v2:

    Version 1 of the PCI Express Capability (defined by PCI Express
    1.0 and 1.1 base) neither requires the endpoint to implement the
    entire PCIe capability structure nor specifies default values of
    registers that are not implemented by the device.

    Version 2 of the PCI Express Capability (defined by PCIe 1.1
    Capability Structure Expansion ECN, PCIe 2.0, 2.1, and 3.0) added
    additional registers to the structure and requires all registers
    to be either implemented or hardwired to 0.

Due to the differences in the capability structures, code dealing with
capability features must be careful not to access the additional
registers introduced with v2 unless the device is specifically known to
be a v2 capable device.  Otherwise, attempts to access non-existant
registers will occur.  This is a subtle issue that is hard to track down
when it occurs (and it has - see commit 864d296cf94).

To try and help mitigate such occurrences, this patch introduces
pci_pcie_cap2() which is similar to pci_pcie_cap() but also checks
that the PCIe capability version is >= 2.  pci_pcie_cap2() should be
used for qualifying PCIe capability features introduced after v1.

Suggested by Don Dutile.

Acked-by: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Myron Stowe <myron.stowe@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci.c
include/linux/pci_regs.h