aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2012-08-23 20:31:58 -0400
committerBjorn Helgaas <bhelgaas@google.com>2012-08-23 20:31:58 -0400
commite1c171b86baaccab983ded5dfa1663c0981d2520 (patch)
tree648ad71d7bd2838678f66d055fcaae654b5e4ddc
parent0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff)
parent479e0d485eaab452cf248cd1a9520015023b35b2 (diff)
Merge branch 'pci/jiang-pcie-cap' into next
* pci/jiang-pcie-cap: (40 commits) rtl8192e: Use PCI Express Capability accessors et131x: Use PCI Express Capability accessors rapdio/tsi721: Use PCI Express Capability accessors drm/radeon: Use PCI Express Capability accessors [SCSI] qla4xxx: Use PCI Express Capability accessors [SCSI] qla4xxx: Use PCI Express Capability accessors IB/qib: Use PCI Express Capability accessors IB/mthca: Use PCI Express Capability accessors rtlwifi: Use PCI Express Capability accessors iwlwifi: Use PCI Express Capability accessors iwlegacy: Use PCI Express Capability accessors ath9k: Use PCI Express Capability accessors atl1c: Use PCI Express Capability accessors cxgb4: Use PCI Express Capability accessors cxgb3: Use PCI Express Capability accessors myri10ge: Use PCI Express Capability accessors niu: Use PCI Express Capability accessors mlx4: Use PCI Express Capability accessors vxge: Use PCI Express Capability accessors igb: Use PCI Express Capability accessors ...
-rw-r--r--arch/arm/mach-tegra/pcie.c12
-rw-r--r--arch/mips/pci/pci-octeon.c15
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c2
-rw-r--r--arch/tile/kernel/pci.c26
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_reset.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_pcie.c38
-rw-r--r--drivers/iommu/intel-iommu.c6
-rw-r--r--drivers/net/ethernet/atheros/atl1c/atl1c_main.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c25
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c50
-rw-r--r--drivers/net/ethernet/chelsio/cxgb3/t3_hw.c22
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c10
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c6
-rw-r--r--drivers/net/ethernet/intel/e1000e/netdev.c27
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c12
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/reset.c8
-rw-r--r--drivers/net/ethernet/myricom/myri10ge/myri10ge.c31
-rw-r--r--drivers/net/ethernet/neterion/vxge/vxge-config.c4
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c2
-rw-r--r--drivers/net/ethernet/realtek/r8169.c44
-rw-r--r--drivers/net/ethernet/sun/niu.c19
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c21
-rw-r--r--drivers/net/wireless/iwlegacy/common.h4
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c7
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c8
-rw-r--r--drivers/pci/access.c202
-rw-r--r--drivers/pci/hotplug/pciehp_acpi.c6
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c12
-rw-r--r--drivers/pci/hotplug/pcihp_slot.c20
-rw-r--r--drivers/pci/iov.c6
-rw-r--r--drivers/pci/pci.c316
-rw-r--r--drivers/pci/pcie/aer/aer_inject.c2
-rw-r--r--drivers/pci/pcie/aer/aerdrv.c24
-rw-r--r--drivers/pci/pcie/aer/aerdrv_acpi.c2
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c53
-rw-r--r--drivers/pci/pcie/aspm.c119
-rw-r--r--drivers/pci/pcie/pme.c29
-rw-r--r--drivers/pci/pcie/portdrv_bus.c2
-rw-r--r--drivers/pci/pcie/portdrv_core.c19
-rw-r--r--drivers/pci/pcie/portdrv_pci.c17
-rw-r--r--drivers/pci/probe.c28
-rw-r--r--drivers/pci/quirks.c31
-rw-r--r--drivers/pci/search.c2
-rw-r--r--drivers/rapidio/devices/tsi721.c19
-rw-r--r--drivers/scsi/qla2xxx/qla_nx.c8
-rw-r--r--drivers/scsi/qla4xxx/ql4_nx.c4
-rw-r--r--drivers/staging/et131x/et131x.c19
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_pci.c8
-rw-r--r--include/linux/pci.h44
-rw-r--r--include/linux/pci_regs.h1
52 files changed, 591 insertions, 823 deletions
diff --git a/arch/arm/mach-tegra/pcie.c b/arch/arm/mach-tegra/pcie.c
index d3ad5150d660..c25a2a4f2e3d 100644
--- a/arch/arm/mach-tegra/pcie.c
+++ b/arch/arm/mach-tegra/pcie.c
@@ -367,17 +367,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf1, tegra_pcie_fixup_class);
367/* Tegra PCIE requires relaxed ordering */ 367/* Tegra PCIE requires relaxed ordering */
368static void __devinit tegra_pcie_relax_enable(struct pci_dev *dev) 368static void __devinit tegra_pcie_relax_enable(struct pci_dev *dev)
369{ 369{
370 u16 val16; 370 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
371 int pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
372
373 if (pos <= 0) {
374 dev_err(&dev->dev, "skipping relaxed ordering fixup\n");
375 return;
376 }
377
378 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &val16);
379 val16 |= PCI_EXP_DEVCTL_RELAX_EN;
380 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, val16);
381} 371}
382DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, tegra_pcie_relax_enable); 372DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, tegra_pcie_relax_enable);
383 373
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index 52a1ba70b3b6..c5dfb2c87d44 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -117,16 +117,11 @@ int pcibios_plat_dev_init(struct pci_dev *dev)
117 } 117 }
118 118
119 /* Enable the PCIe normal error reporting */ 119 /* Enable the PCIe normal error reporting */
120 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 120 config = PCI_EXP_DEVCTL_CERE; /* Correctable Error Reporting */
121 if (pos) { 121 config |= PCI_EXP_DEVCTL_NFERE; /* Non-Fatal Error Reporting */
122 /* Update Device Control */ 122 config |= PCI_EXP_DEVCTL_FERE; /* Fatal Error Reporting */
123 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config); 123 config |= PCI_EXP_DEVCTL_URRE; /* Unsupported Request */
124 config |= PCI_EXP_DEVCTL_CERE; /* Correctable Error Reporting */ 124 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, config);
125 config |= PCI_EXP_DEVCTL_NFERE; /* Non-Fatal Error Reporting */
126 config |= PCI_EXP_DEVCTL_FERE; /* Fatal Error Reporting */
127 config |= PCI_EXP_DEVCTL_URRE; /* Unsupported Request */
128 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
129 }
130 125
131 /* Find the Advanced Error Reporting capability */ 126 /* Find the Advanced Error Reporting capability */
132 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 127 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 9cda6a1ad0cf..b46e1dadc882 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -855,7 +855,7 @@ static void __devinit pnv_ioda_setup_PEs(struct pci_bus *bus)
855 if (pe == NULL) 855 if (pe == NULL)
856 continue; 856 continue;
857 /* Leaving the PCIe domain ... single PE# */ 857 /* Leaving the PCIe domain ... single PE# */
858 if (dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) 858 if (pci_pcie_type(dev) == PCI_EXP_TYPE_PCI_BRIDGE)
859 pnv_ioda_setup_bus_PE(dev, pe); 859 pnv_ioda_setup_bus_PE(dev, pe);
860 else if (dev->subordinate) 860 else if (dev->subordinate)
861 pnv_ioda_setup_PEs(dev->subordinate); 861 pnv_ioda_setup_PEs(dev->subordinate);
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
index 33c10864d2f7..d2292be6fb90 100644
--- a/arch/tile/kernel/pci.c
+++ b/arch/tile/kernel/pci.c
@@ -246,16 +246,13 @@ static void __devinit fixup_read_and_payload_sizes(void)
246 246
247 /* Scan for the smallest maximum payload size. */ 247 /* Scan for the smallest maximum payload size. */
248 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 248 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
249 int pcie_caps_offset;
250 u32 devcap; 249 u32 devcap;
251 int max_payload; 250 int max_payload;
252 251
253 pcie_caps_offset = pci_find_capability(dev, PCI_CAP_ID_EXP); 252 if (!pci_is_pcie(dev))
254 if (pcie_caps_offset == 0)
255 continue; 253 continue;
256 254
257 pci_read_config_dword(dev, pcie_caps_offset + PCI_EXP_DEVCAP, 255 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &devcap);
258 &devcap);
259 max_payload = devcap & PCI_EXP_DEVCAP_PAYLOAD; 256 max_payload = devcap & PCI_EXP_DEVCAP_PAYLOAD;
260 if (max_payload < smallest_max_payload) 257 if (max_payload < smallest_max_payload)
261 smallest_max_payload = max_payload; 258 smallest_max_payload = max_payload;
@@ -263,21 +260,10 @@ static void __devinit fixup_read_and_payload_sizes(void)
263 260
264 /* Now, set the max_payload_size for all devices to that value. */ 261 /* Now, set the max_payload_size for all devices to that value. */
265 new_values = (max_read_size << 12) | (smallest_max_payload << 5); 262 new_values = (max_read_size << 12) | (smallest_max_payload << 5);
266 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 263 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
267 int pcie_caps_offset; 264 pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
268 u16 devctl; 265 PCI_EXP_DEVCTL_PAYLOAD | PCI_EXP_DEVCTL_READRQ,
269 266 new_values);
270 pcie_caps_offset = pci_find_capability(dev, PCI_CAP_ID_EXP);
271 if (pcie_caps_offset == 0)
272 continue;
273
274 pci_read_config_word(dev, pcie_caps_offset + PCI_EXP_DEVCTL,
275 &devctl);
276 devctl &= ~(PCI_EXP_DEVCTL_PAYLOAD | PCI_EXP_DEVCTL_READRQ);
277 devctl |= new_values;
278 pci_write_config_word(dev, pcie_caps_offset + PCI_EXP_DEVCTL,
279 devctl);
280 }
281} 267}
282 268
283 269
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index e585a3b947eb..b106c56c9af1 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -77,13 +77,9 @@ void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
77void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev) 77void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
78{ 78{
79 u16 ctl, v; 79 u16 ctl, v;
80 int cap, err; 80 int err;
81 81
82 cap = pci_pcie_cap(rdev->pdev); 82 err = pcie_capability_read_word(rdev->pdev, PCI_EXP_DEVCTL, &ctl);
83 if (!cap)
84 return;
85
86 err = pci_read_config_word(rdev->pdev, cap + PCI_EXP_DEVCTL, &ctl);
87 if (err) 83 if (err)
88 return; 84 return;
89 85
@@ -95,7 +91,7 @@ void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
95 if ((v == 0) || (v == 6) || (v == 7)) { 91 if ((v == 0) || (v == 6) || (v == 7)) {
96 ctl &= ~PCI_EXP_DEVCTL_READRQ; 92 ctl &= ~PCI_EXP_DEVCTL_READRQ;
97 ctl |= (2 << 12); 93 ctl |= (2 << 12);
98 pci_write_config_word(rdev->pdev, cap + PCI_EXP_DEVCTL, ctl); 94 pcie_capability_write_word(rdev->pdev, PCI_EXP_DEVCTL, ctl);
99 } 95 }
100} 96}
101 97
diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c
index 4fa3534ec233..74c6a9426047 100644
--- a/drivers/infiniband/hw/mthca/mthca_reset.c
+++ b/drivers/infiniband/hw/mthca/mthca_reset.c
@@ -241,16 +241,16 @@ good:
241 241
242 if (hca_pcie_cap) { 242 if (hca_pcie_cap) {
243 devctl = hca_header[(hca_pcie_cap + PCI_EXP_DEVCTL) / 4]; 243 devctl = hca_header[(hca_pcie_cap + PCI_EXP_DEVCTL) / 4];
244 if (pci_write_config_word(mdev->pdev, hca_pcie_cap + PCI_EXP_DEVCTL, 244 if (pcie_capability_write_word(mdev->pdev, PCI_EXP_DEVCTL,
245 devctl)) { 245 devctl)) {
246 err = -ENODEV; 246 err = -ENODEV;
247 mthca_err(mdev, "Couldn't restore HCA PCI Express " 247 mthca_err(mdev, "Couldn't restore HCA PCI Express "
248 "Device Control register, aborting.\n"); 248 "Device Control register, aborting.\n");
249 goto out; 249 goto out;
250 } 250 }
251 linkctl = hca_header[(hca_pcie_cap + PCI_EXP_LNKCTL) / 4]; 251 linkctl = hca_header[(hca_pcie_cap + PCI_EXP_LNKCTL) / 4];
252 if (pci_write_config_word(mdev->pdev, hca_pcie_cap + PCI_EXP_LNKCTL, 252 if (pcie_capability_write_word(mdev->pdev, PCI_EXP_LNKCTL,
253 linkctl)) { 253 linkctl)) {
254 err = -ENODEV; 254 err = -ENODEV;
255 mthca_err(mdev, "Couldn't restore HCA PCI Express " 255 mthca_err(mdev, "Couldn't restore HCA PCI Express "
256 "Link control register, aborting.\n"); 256 "Link control register, aborting.\n");
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c
index 062c301ebf53..900137173210 100644
--- a/drivers/infiniband/hw/qib/qib_pcie.c
+++ b/drivers/infiniband/hw/qib/qib_pcie.c
@@ -273,10 +273,9 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent,
273 struct qib_msix_entry *entry) 273 struct qib_msix_entry *entry)
274{ 274{
275 u16 linkstat, speed; 275 u16 linkstat, speed;
276 int pos = 0, pose, ret = 1; 276 int pos = 0, ret = 1;
277 277
278 pose = pci_pcie_cap(dd->pcidev); 278 if (!pci_is_pcie(dd->pcidev)) {
279 if (!pose) {
280 qib_dev_err(dd, "Can't find PCI Express capability!\n"); 279 qib_dev_err(dd, "Can't find PCI Express capability!\n");
281 /* set up something... */ 280 /* set up something... */
282 dd->lbus_width = 1; 281 dd->lbus_width = 1;
@@ -298,7 +297,7 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent,
298 if (!pos) 297 if (!pos)
299 qib_enable_intx(dd->pcidev); 298 qib_enable_intx(dd->pcidev);
300 299
301 pci_read_config_word(dd->pcidev, pose + PCI_EXP_LNKSTA, &linkstat); 300 pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKSTA, &linkstat);
302 /* 301 /*
303 * speed is bits 0-3, linkwidth is bits 4-8 302 * speed is bits 0-3, linkwidth is bits 4-8
304 * no defines for them in headers 303 * no defines for them in headers
@@ -516,7 +515,6 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
516{ 515{
517 int r; 516 int r;
518 struct pci_dev *parent; 517 struct pci_dev *parent;
519 int ppos;
520 u16 devid; 518 u16 devid;
521 u32 mask, bits, val; 519 u32 mask, bits, val;
522 520
@@ -529,8 +527,7 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
529 qib_devinfo(dd->pcidev, "Parent not root\n"); 527 qib_devinfo(dd->pcidev, "Parent not root\n");
530 return 1; 528 return 1;
531 } 529 }
532 ppos = pci_pcie_cap(parent); 530 if (!pci_is_pcie(parent))
533 if (!ppos)
534 return 1; 531 return 1;
535 if (parent->vendor != 0x8086) 532 if (parent->vendor != 0x8086)
536 return 1; 533 return 1;
@@ -587,7 +584,6 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
587{ 584{
588 int ret = 1; /* Assume the worst */ 585 int ret = 1; /* Assume the worst */
589 struct pci_dev *parent; 586 struct pci_dev *parent;
590 int ppos, epos;
591 u16 pcaps, pctl, ecaps, ectl; 587 u16 pcaps, pctl, ecaps, ectl;
592 int rc_sup, ep_sup; 588 int rc_sup, ep_sup;
593 int rc_cur, ep_cur; 589 int rc_cur, ep_cur;
@@ -598,19 +594,15 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
598 qib_devinfo(dd->pcidev, "Parent not root\n"); 594 qib_devinfo(dd->pcidev, "Parent not root\n");
599 goto bail; 595 goto bail;
600 } 596 }
601 ppos = pci_pcie_cap(parent); 597
602 if (ppos) { 598 if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev))
603 pci_read_config_word(parent, ppos + PCI_EXP_DEVCAP, &pcaps);
604 pci_read_config_word(parent, ppos + PCI_EXP_DEVCTL, &pctl);
605 } else
606 goto bail; 599 goto bail;
600 pcie_capability_read_word(parent, PCI_EXP_DEVCAP, &pcaps);
601 pcie_capability_read_word(parent, PCI_EXP_DEVCTL, &pctl);
607 /* Find out supported and configured values for endpoint (us) */ 602 /* Find out supported and configured values for endpoint (us) */
608 epos = pci_pcie_cap(dd->pcidev); 603 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCAP, &ecaps);
609 if (epos) { 604 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl);
610 pci_read_config_word(dd->pcidev, epos + PCI_EXP_DEVCAP, &ecaps); 605
611 pci_read_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, &ectl);
612 } else
613 goto bail;
614 ret = 0; 606 ret = 0;
615 /* Find max payload supported by root, endpoint */ 607 /* Find max payload supported by root, endpoint */
616 rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD); 608 rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD);
@@ -629,14 +621,14 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
629 rc_cur = rc_sup; 621 rc_cur = rc_sup;
630 pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) | 622 pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) |
631 val2fld(rc_cur, PCI_EXP_DEVCTL_PAYLOAD); 623 val2fld(rc_cur, PCI_EXP_DEVCTL_PAYLOAD);
632 pci_write_config_word(parent, ppos + PCI_EXP_DEVCTL, pctl); 624 pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl);
633 } 625 }
634 /* If less than (allowed, supported), bump endpoint payload */ 626 /* If less than (allowed, supported), bump endpoint payload */
635 if (rc_sup > ep_cur) { 627 if (rc_sup > ep_cur) {
636 ep_cur = rc_sup; 628 ep_cur = rc_sup;
637 ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) | 629 ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) |
638 val2fld(ep_cur, PCI_EXP_DEVCTL_PAYLOAD); 630 val2fld(ep_cur, PCI_EXP_DEVCTL_PAYLOAD);
639 pci_write_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, ectl); 631 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl);
640 } 632 }
641 633
642 /* 634 /*
@@ -654,13 +646,13 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
654 rc_cur = rc_sup; 646 rc_cur = rc_sup;
655 pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) | 647 pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) |
656 val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ); 648 val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ);
657 pci_write_config_word(parent, ppos + PCI_EXP_DEVCTL, pctl); 649 pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl);
658 } 650 }
659 if (rc_sup > ep_cur) { 651 if (rc_sup > ep_cur) {
660 ep_cur = rc_sup; 652 ep_cur = rc_sup;
661 ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) | 653 ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) |
662 val2fld(ep_cur, PCI_EXP_DEVCTL_READRQ); 654 val2fld(ep_cur, PCI_EXP_DEVCTL_READRQ);
663 pci_write_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, ectl); 655 pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl);
664 } 656 }
665bail: 657bail:
666 return ret; 658 return ret;
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 7469b5346643..8b5075d6dd5a 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2350,7 +2350,7 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup)
2350 return 0; 2350 return 0;
2351 if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI) 2351 if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI)
2352 return 0; 2352 return 0;
2353 } else if (pdev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) 2353 } else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE)
2354 return 0; 2354 return 0;
2355 2355
2356 /* 2356 /*
@@ -3545,10 +3545,10 @@ found:
3545 struct pci_dev *bridge = bus->self; 3545 struct pci_dev *bridge = bus->self;
3546 3546
3547 if (!bridge || !pci_is_pcie(bridge) || 3547 if (!bridge || !pci_is_pcie(bridge) ||
3548 bridge->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) 3548 pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE)
3549 return 0; 3549 return 0;
3550 3550
3551 if (bridge->pcie_type == PCI_EXP_TYPE_ROOT_PORT) { 3551 if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT) {
3552 for (i = 0; i < atsru->devices_cnt; i++) 3552 for (i = 0; i < atsru->devices_cnt; i++)
3553 if (atsru->devices[i] == bridge) 3553 if (atsru->devices[i] == bridge)
3554 return 1; 3554 return 1;
diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
index 1bf5bbfe778e..8892e2b64498 100644
--- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
+++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
@@ -149,7 +149,7 @@ static void atl1c_reset_pcie(struct atl1c_hw *hw, u32 flag)
149 data &= ~(PCI_ERR_UNC_DLP | PCI_ERR_UNC_FCP); 149 data &= ~(PCI_ERR_UNC_DLP | PCI_ERR_UNC_FCP);
150 pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, data); 150 pci_write_config_dword(pdev, pos + PCI_ERR_UNCOR_SEVER, data);
151 /* clear error status */ 151 /* clear error status */
152 pci_write_config_word(pdev, pci_pcie_cap(pdev) + PCI_EXP_DEVSTA, 152 pcie_capability_write_word(pdev, PCI_EXP_DEVSTA,
153 PCI_EXP_DEVSTA_NFED | 153 PCI_EXP_DEVSTA_NFED |
154 PCI_EXP_DEVSTA_FED | 154 PCI_EXP_DEVSTA_FED |
155 PCI_EXP_DEVSTA_CED | 155 PCI_EXP_DEVSTA_CED |
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index dd451c3dd83d..281cf3f7bc20 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -1162,14 +1162,9 @@ static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
1162 1162
1163static u8 bnx2x_is_pcie_pending(struct pci_dev *dev) 1163static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1164{ 1164{
1165 int pos;
1166 u16 status; 1165 u16 status;
1167 1166
1168 pos = pci_pcie_cap(dev); 1167 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
1169 if (!pos)
1170 return false;
1171
1172 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1173 return status & PCI_EXP_DEVSTA_TRPND; 1168 return status & PCI_EXP_DEVSTA_TRPND;
1174} 1169}
1175 1170
@@ -6149,8 +6144,7 @@ static void bnx2x_init_pxp(struct bnx2x *bp)
6149 u16 devctl; 6144 u16 devctl;
6150 int r_order, w_order; 6145 int r_order, w_order;
6151 6146
6152 pci_read_config_word(bp->pdev, 6147 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
6153 pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
6154 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); 6148 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6155 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); 6149 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6156 if (bp->mrrs == -1) 6150 if (bp->mrrs == -1)
@@ -9386,15 +9380,10 @@ static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
9386 9380
9387static bool __devinit bnx2x_can_flr(struct bnx2x *bp) 9381static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
9388{ 9382{
9389 int pos;
9390 u32 cap; 9383 u32 cap;
9391 struct pci_dev *dev = bp->pdev; 9384 struct pci_dev *dev = bp->pdev;
9392 9385
9393 pos = pci_pcie_cap(dev); 9386 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap);
9394 if (!pos)
9395 return false;
9396
9397 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
9398 if (!(cap & PCI_EXP_DEVCAP_FLR)) 9387 if (!(cap & PCI_EXP_DEVCAP_FLR))
9399 return false; 9388 return false;
9400 9389
@@ -9403,7 +9392,7 @@ static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
9403 9392
9404static int __devinit bnx2x_do_flr(struct bnx2x *bp) 9393static int __devinit bnx2x_do_flr(struct bnx2x *bp)
9405{ 9394{
9406 int i, pos; 9395 int i;
9407 u16 status; 9396 u16 status;
9408 struct pci_dev *dev = bp->pdev; 9397 struct pci_dev *dev = bp->pdev;
9409 9398
@@ -9411,16 +9400,12 @@ static int __devinit bnx2x_do_flr(struct bnx2x *bp)
9411 if (bnx2x_can_flr(bp)) 9400 if (bnx2x_can_flr(bp))
9412 return -ENOTTY; 9401 return -ENOTTY;
9413 9402
9414 pos = pci_pcie_cap(dev);
9415 if (!pos)
9416 return -ENOTTY;
9417
9418 /* Wait for Transaction Pending bit clean */ 9403 /* Wait for Transaction Pending bit clean */
9419 for (i = 0; i < 4; i++) { 9404 for (i = 0; i < 4; i++) {
9420 if (i) 9405 if (i)
9421 msleep((1 << (i - 1)) * 100); 9406 msleep((1 << (i - 1)) * 100);
9422 9407
9423 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); 9408 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
9424 if (!(status & PCI_EXP_DEVSTA_TRPND)) 9409 if (!(status & PCI_EXP_DEVSTA_TRPND))
9425 goto clear; 9410 goto clear;
9426 } 9411 }
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index bf906c51d82a..8325fd8d4e5b 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -3653,17 +3653,9 @@ static int tg3_power_down_prepare(struct tg3 *tp)
3653 tg3_enable_register_access(tp); 3653 tg3_enable_register_access(tp);
3654 3654
3655 /* Restore the CLKREQ setting. */ 3655 /* Restore the CLKREQ setting. */
3656 if (tg3_flag(tp, CLKREQ_BUG)) { 3656 if (tg3_flag(tp, CLKREQ_BUG))
3657 u16 lnkctl; 3657 pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL,
3658 3658 PCI_EXP_LNKCTL_CLKREQ_EN);
3659 pci_read_config_word(tp->pdev,
3660 pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL,
3661 &lnkctl);
3662 lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN;
3663 pci_write_config_word(tp->pdev,
3664 pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL,
3665 lnkctl);
3666 }
3667 3659
3668 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); 3660 misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
3669 tw32(TG3PCI_MISC_HOST_CTRL, 3661 tw32(TG3PCI_MISC_HOST_CTRL,
@@ -4434,20 +4426,13 @@ relink:
4434 4426
4435 /* Prevent send BD corruption. */ 4427 /* Prevent send BD corruption. */
4436 if (tg3_flag(tp, CLKREQ_BUG)) { 4428 if (tg3_flag(tp, CLKREQ_BUG)) {
4437 u16 oldlnkctl, newlnkctl;
4438
4439 pci_read_config_word(tp->pdev,
4440 pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL,
4441 &oldlnkctl);
4442 if (tp->link_config.active_speed == SPEED_100 || 4429 if (tp->link_config.active_speed == SPEED_100 ||
4443 tp->link_config.active_speed == SPEED_10) 4430 tp->link_config.active_speed == SPEED_10)
4444 newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; 4431 pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL,
4432 PCI_EXP_LNKCTL_CLKREQ_EN);
4445 else 4433 else
4446 newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; 4434 pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL,
4447 if (newlnkctl != oldlnkctl) 4435 PCI_EXP_LNKCTL_CLKREQ_EN);
4448 pci_write_config_word(tp->pdev,
4449 pci_pcie_cap(tp->pdev) +
4450 PCI_EXP_LNKCTL, newlnkctl);
4451 } 4436 }
4452 4437
4453 if (current_link_up != netif_carrier_ok(tp->dev)) { 4438 if (current_link_up != netif_carrier_ok(tp->dev)) {
@@ -8054,7 +8039,7 @@ static int tg3_chip_reset(struct tg3 *tp)
8054 8039
8055 udelay(120); 8040 udelay(120);
8056 8041
8057 if (tg3_flag(tp, PCI_EXPRESS) && pci_pcie_cap(tp->pdev)) { 8042 if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) {
8058 u16 val16; 8043 u16 val16;
8059 8044
8060 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { 8045 if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) {
@@ -8071,24 +8056,17 @@ static int tg3_chip_reset(struct tg3 *tp)
8071 } 8056 }
8072 8057
8073 /* Clear the "no snoop" and "relaxed ordering" bits. */ 8058 /* Clear the "no snoop" and "relaxed ordering" bits. */
8074 pci_read_config_word(tp->pdev, 8059 val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN;
8075 pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL,
8076 &val16);
8077 val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN |
8078 PCI_EXP_DEVCTL_NOSNOOP_EN);
8079 /* 8060 /*
8080 * Older PCIe devices only support the 128 byte 8061 * Older PCIe devices only support the 128 byte
8081 * MPS setting. Enforce the restriction. 8062 * MPS setting. Enforce the restriction.
8082 */ 8063 */
8083 if (!tg3_flag(tp, CPMU_PRESENT)) 8064 if (!tg3_flag(tp, CPMU_PRESENT))
8084 val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; 8065 val16 |= PCI_EXP_DEVCTL_PAYLOAD;
8085 pci_write_config_word(tp->pdev, 8066 pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16);
8086 pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL,
8087 val16);
8088 8067
8089 /* Clear error status */ 8068 /* Clear error status */
8090 pci_write_config_word(tp->pdev, 8069 pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA,
8091 pci_pcie_cap(tp->pdev) + PCI_EXP_DEVSTA,
8092 PCI_EXP_DEVSTA_CED | 8070 PCI_EXP_DEVSTA_CED |
8093 PCI_EXP_DEVSTA_NFED | 8071 PCI_EXP_DEVSTA_NFED |
8094 PCI_EXP_DEVSTA_FED | 8072 PCI_EXP_DEVSTA_FED |
@@ -14565,9 +14543,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
14565 14543
14566 tg3_flag_set(tp, PCI_EXPRESS); 14544 tg3_flag_set(tp, PCI_EXPRESS);
14567 14545
14568 pci_read_config_word(tp->pdev, 14546 pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl);
14569 pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL,
14570 &lnkctl);
14571 if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { 14547 if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) {
14572 if (GET_ASIC_REV(tp->pci_chip_rev_id) == 14548 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
14573 ASIC_REV_5906) { 14549 ASIC_REV_5906) {
diff --git a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
index bff8a3cdd3df..aef45d3113ba 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
@@ -3289,22 +3289,18 @@ static void config_pcie(struct adapter *adap)
3289 unsigned int log2_width, pldsize; 3289 unsigned int log2_width, pldsize;
3290 unsigned int fst_trn_rx, fst_trn_tx, acklat, rpllmt; 3290 unsigned int fst_trn_rx, fst_trn_tx, acklat, rpllmt;
3291 3291
3292 pci_read_config_word(adap->pdev, 3292 pcie_capability_read_word(adap->pdev, PCI_EXP_DEVCTL, &val);
3293 adap->pdev->pcie_cap + PCI_EXP_DEVCTL,
3294 &val);
3295 pldsize = (val & PCI_EXP_DEVCTL_PAYLOAD) >> 5; 3293 pldsize = (val & PCI_EXP_DEVCTL_PAYLOAD) >> 5;
3296 3294
3297 pci_read_config_word(adap->pdev, 0x2, &devid); 3295 pci_read_config_word(adap->pdev, 0x2, &devid);
3298 if (devid == 0x37) { 3296 if (devid == 0x37) {
3299 pci_write_config_word(adap->pdev, 3297 pcie_capability_write_word(adap->pdev, PCI_EXP_DEVCTL,
3300 adap->pdev->pcie_cap + PCI_EXP_DEVCTL, 3298 val & ~PCI_EXP_DEVCTL_READRQ &
3301 val & ~PCI_EXP_DEVCTL_READRQ & 3299 ~PCI_EXP_DEVCTL_PAYLOAD);
3302 ~PCI_EXP_DEVCTL_PAYLOAD);
3303 pldsize = 0; 3300 pldsize = 0;
3304 } 3301 }
3305 3302
3306 pci_read_config_word(adap->pdev, adap->pdev->pcie_cap + PCI_EXP_LNKCTL, 3303 pcie_capability_read_word(adap->pdev, PCI_EXP_LNKCTL, &val);
3307 &val);
3308 3304
3309 fst_trn_tx = G_NUMFSTTRNSEQ(t3_read_reg(adap, A_PCIE_PEX_CTRL0)); 3305 fst_trn_tx = G_NUMFSTTRNSEQ(t3_read_reg(adap, A_PCIE_PEX_CTRL0));
3310 fst_trn_rx = adap->params.rev == 0 ? fst_trn_tx : 3306 fst_trn_rx = adap->params.rev == 0 ? fst_trn_tx :
@@ -3425,15 +3421,13 @@ out_err:
3425static void get_pci_mode(struct adapter *adapter, struct pci_params *p) 3421static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
3426{ 3422{
3427 static unsigned short speed_map[] = { 33, 66, 100, 133 }; 3423 static unsigned short speed_map[] = { 33, 66, 100, 133 };
3428 u32 pci_mode, pcie_cap; 3424 u32 pci_mode;
3429 3425
3430 pcie_cap = pci_pcie_cap(adapter->pdev); 3426 if (pci_is_pcie(adapter->pdev)) {
3431 if (pcie_cap) {
3432 u16 val; 3427 u16 val;
3433 3428
3434 p->variant = PCI_VARIANT_PCIE; 3429 p->variant = PCI_VARIANT_PCIE;
3435 pci_read_config_word(adapter->pdev, pcie_cap + PCI_EXP_LNKSTA, 3430 pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
3436 &val);
3437 p->width = (val >> 4) & 0x3f; 3431 p->width = (val >> 4) & 0x3f;
3438 return; 3432 return;
3439 } 3433 }
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 5ed49af23d6a..4a20821511e7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -3694,15 +3694,7 @@ static void __devinit print_port_info(const struct net_device *dev)
3694 3694
3695static void __devinit enable_pcie_relaxed_ordering(struct pci_dev *dev) 3695static void __devinit enable_pcie_relaxed_ordering(struct pci_dev *dev)
3696{ 3696{
3697 u16 v; 3697 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
3698 int pos;
3699
3700 pos = pci_pcie_cap(dev);
3701 if (pos > 0) {
3702 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &v);
3703 v |= PCI_EXP_DEVCTL_RELAX_EN;
3704 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, v);
3705 }
3706} 3698}
3707 3699
3708/* 3700/*
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index fa947dfa4c30..af1601323173 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -2741,11 +2741,9 @@ static void __devinit get_pci_mode(struct adapter *adapter,
2741 struct pci_params *p) 2741 struct pci_params *p)
2742{ 2742{
2743 u16 val; 2743 u16 val;
2744 u32 pcie_cap = pci_pcie_cap(adapter->pdev);
2745 2744
2746 if (pcie_cap) { 2745 if (pci_is_pcie(adapter->pdev)) {
2747 pci_read_config_word(adapter->pdev, pcie_cap + PCI_EXP_LNKSTA, 2746 pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
2748 &val);
2749 p->speed = val & PCI_EXP_LNKSTA_CLS; 2747 p->speed = val & PCI_EXP_LNKSTA_CLS;
2750 p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4; 2748 p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
2751 } 2749 }
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 95b245310f17..9f474b2cc819 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -5570,16 +5570,15 @@ static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5570 */ 5570 */
5571 if (adapter->flags & FLAG_IS_QUAD_PORT) { 5571 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5572 struct pci_dev *us_dev = pdev->bus->self; 5572 struct pci_dev *us_dev = pdev->bus->self;
5573 int pos = pci_pcie_cap(us_dev);
5574 u16 devctl; 5573 u16 devctl;
5575 5574
5576 pci_read_config_word(us_dev, pos + PCI_EXP_DEVCTL, &devctl); 5575 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
5577 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, 5576 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
5578 (devctl & ~PCI_EXP_DEVCTL_CERE)); 5577 (devctl & ~PCI_EXP_DEVCTL_CERE));
5579 5578
5580 e1000_power_off(pdev, sleep, wake); 5579 e1000_power_off(pdev, sleep, wake);
5581 5580
5582 pci_write_config_word(us_dev, pos + PCI_EXP_DEVCTL, devctl); 5581 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
5583 } else { 5582 } else {
5584 e1000_power_off(pdev, sleep, wake); 5583 e1000_power_off(pdev, sleep, wake);
5585 } 5584 }
@@ -5593,25 +5592,15 @@ static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5593#else 5592#else
5594static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state) 5593static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5595{ 5594{
5596 int pos;
5597 u16 reg16;
5598
5599 /* 5595 /*
5600 * Both device and parent should have the same ASPM setting. 5596 * Both device and parent should have the same ASPM setting.
5601 * Disable ASPM in downstream component first and then upstream. 5597 * Disable ASPM in downstream component first and then upstream.
5602 */ 5598 */
5603 pos = pci_pcie_cap(pdev); 5599 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, state);
5604 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
5605 reg16 &= ~state;
5606 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
5607
5608 if (!pdev->bus->self)
5609 return;
5610 5600
5611 pos = pci_pcie_cap(pdev->bus->self); 5601 if (pdev->bus->self)
5612 pci_read_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, &reg16); 5602 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
5613 reg16 &= ~state; 5603 state);
5614 pci_write_config_word(pdev->bus->self, pos + PCI_EXP_LNKCTL, reg16);
5615} 5604}
5616#endif 5605#endif
5617static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state) 5606static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index b7c2d5050572..9a379d9c07fa 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -6539,28 +6539,20 @@ static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6539s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) 6539s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6540{ 6540{
6541 struct igb_adapter *adapter = hw->back; 6541 struct igb_adapter *adapter = hw->back;
6542 u16 cap_offset;
6543 6542
6544 cap_offset = adapter->pdev->pcie_cap; 6543 if (pcie_capability_read_word(adapter->pdev, reg, value))
6545 if (!cap_offset)
6546 return -E1000_ERR_CONFIG; 6544 return -E1000_ERR_CONFIG;
6547 6545
6548 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
6549
6550 return 0; 6546 return 0;
6551} 6547}
6552 6548
6553s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) 6549s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6554{ 6550{
6555 struct igb_adapter *adapter = hw->back; 6551 struct igb_adapter *adapter = hw->back;
6556 u16 cap_offset;
6557 6552
6558 cap_offset = adapter->pdev->pcie_cap; 6553 if (pcie_capability_write_word(adapter->pdev, reg, *value))
6559 if (!cap_offset)
6560 return -E1000_ERR_CONFIG; 6554 return -E1000_ERR_CONFIG;
6561 6555
6562 pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
6563
6564 return 0; 6556 return 0;
6565} 6557}
6566 6558
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 4326f74f7137..976570d4c939 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7527,7 +7527,7 @@ static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7527 goto skip_bad_vf_detection; 7527 goto skip_bad_vf_detection;
7528 7528
7529 bdev = pdev->bus->self; 7529 bdev = pdev->bus->self;
7530 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT)) 7530 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
7531 bdev = bdev->bus->self; 7531 bdev = bdev->bus->self;
7532 7532
7533 if (!bdev) 7533 if (!bdev)
diff --git a/drivers/net/ethernet/mellanox/mlx4/reset.c b/drivers/net/ethernet/mellanox/mlx4/reset.c
index 11e7c1cb99bf..dd1b5093d8b1 100644
--- a/drivers/net/ethernet/mellanox/mlx4/reset.c
+++ b/drivers/net/ethernet/mellanox/mlx4/reset.c
@@ -141,16 +141,16 @@ int mlx4_reset(struct mlx4_dev *dev)
141 /* Now restore the PCI headers */ 141 /* Now restore the PCI headers */
142 if (pcie_cap) { 142 if (pcie_cap) {
143 devctl = hca_header[(pcie_cap + PCI_EXP_DEVCTL) / 4]; 143 devctl = hca_header[(pcie_cap + PCI_EXP_DEVCTL) / 4];
144 if (pci_write_config_word(dev->pdev, pcie_cap + PCI_EXP_DEVCTL, 144 if (pcie_capability_write_word(dev->pdev, PCI_EXP_DEVCTL,
145 devctl)) { 145 devctl)) {
146 err = -ENODEV; 146 err = -ENODEV;
147 mlx4_err(dev, "Couldn't restore HCA PCI Express " 147 mlx4_err(dev, "Couldn't restore HCA PCI Express "
148 "Device Control register, aborting.\n"); 148 "Device Control register, aborting.\n");
149 goto out; 149 goto out;
150 } 150 }
151 linkctl = hca_header[(pcie_cap + PCI_EXP_LNKCTL) / 4]; 151 linkctl = hca_header[(pcie_cap + PCI_EXP_LNKCTL) / 4];
152 if (pci_write_config_word(dev->pdev, pcie_cap + PCI_EXP_LNKCTL, 152 if (pcie_capability_write_word(dev->pdev, PCI_EXP_LNKCTL,
153 linkctl)) { 153 linkctl)) {
154 err = -ENODEV; 154 err = -ENODEV;
155 mlx4_err(dev, "Couldn't restore HCA PCI Express " 155 mlx4_err(dev, "Couldn't restore HCA PCI Express "
156 "Link control register, aborting.\n"); 156 "Link control register, aborting.\n");
diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
index fa85cf1353fd..83516e3369c9 100644
--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
@@ -1078,22 +1078,16 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
1078#ifdef CONFIG_MYRI10GE_DCA 1078#ifdef CONFIG_MYRI10GE_DCA
1079static int myri10ge_toggle_relaxed(struct pci_dev *pdev, int on) 1079static int myri10ge_toggle_relaxed(struct pci_dev *pdev, int on)
1080{ 1080{
1081 int ret, cap, err; 1081 int ret;
1082 u16 ctl; 1082 u16 ctl;
1083 1083
1084 cap = pci_pcie_cap(pdev); 1084 pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &ctl);
1085 if (!cap)
1086 return 0;
1087
1088 err = pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
1089 if (err)
1090 return 0;
1091 1085
1092 ret = (ctl & PCI_EXP_DEVCTL_RELAX_EN) >> 4; 1086 ret = (ctl & PCI_EXP_DEVCTL_RELAX_EN) >> 4;
1093 if (ret != on) { 1087 if (ret != on) {
1094 ctl &= ~PCI_EXP_DEVCTL_RELAX_EN; 1088 ctl &= ~PCI_EXP_DEVCTL_RELAX_EN;
1095 ctl |= (on << 4); 1089 ctl |= (on << 4);
1096 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); 1090 pcie_capability_write_word(pdev, PCI_EXP_DEVCTL, ctl);
1097 } 1091 }
1098 return ret; 1092 return ret;
1099} 1093}
@@ -3192,18 +3186,13 @@ static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
3192 struct device *dev = &mgp->pdev->dev; 3186 struct device *dev = &mgp->pdev->dev;
3193 int cap; 3187 int cap;
3194 unsigned err_cap; 3188 unsigned err_cap;
3195 u16 val;
3196 u8 ext_type;
3197 int ret; 3189 int ret;
3198 3190
3199 if (!myri10ge_ecrc_enable || !bridge) 3191 if (!myri10ge_ecrc_enable || !bridge)
3200 return; 3192 return;
3201 3193
3202 /* check that the bridge is a root port */ 3194 /* check that the bridge is a root port */
3203 cap = pci_pcie_cap(bridge); 3195 if (pci_pcie_type(bridge) != PCI_EXP_TYPE_ROOT_PORT) {
3204 pci_read_config_word(bridge, cap + PCI_CAP_FLAGS, &val);
3205 ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4;
3206 if (ext_type != PCI_EXP_TYPE_ROOT_PORT) {
3207 if (myri10ge_ecrc_enable > 1) { 3196 if (myri10ge_ecrc_enable > 1) {
3208 struct pci_dev *prev_bridge, *old_bridge = bridge; 3197 struct pci_dev *prev_bridge, *old_bridge = bridge;
3209 3198
@@ -3218,11 +3207,8 @@ static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
3218 " to force ECRC\n"); 3207 " to force ECRC\n");
3219 return; 3208 return;
3220 } 3209 }
3221 cap = pci_pcie_cap(bridge); 3210 } while (pci_pcie_type(bridge) !=
3222 pci_read_config_word(bridge, 3211 PCI_EXP_TYPE_ROOT_PORT);
3223 cap + PCI_CAP_FLAGS, &val);
3224 ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4;
3225 } while (ext_type != PCI_EXP_TYPE_ROOT_PORT);
3226 3212
3227 dev_info(dev, 3213 dev_info(dev,
3228 "Forcing ECRC on non-root port %s" 3214 "Forcing ECRC on non-root port %s"
@@ -3335,11 +3321,10 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
3335 int overridden = 0; 3321 int overridden = 0;
3336 3322
3337 if (myri10ge_force_firmware == 0) { 3323 if (myri10ge_force_firmware == 0) {
3338 int link_width, exp_cap; 3324 int link_width;
3339 u16 lnk; 3325 u16 lnk;
3340 3326
3341 exp_cap = pci_pcie_cap(mgp->pdev); 3327 pcie_capability_read_word(mgp->pdev, PCI_EXP_LNKSTA, &lnk);
3342 pci_read_config_word(mgp->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk);
3343 link_width = (lnk >> 4) & 0x3f; 3328 link_width = (lnk >> 4) & 0x3f;
3344 3329
3345 /* Check to see if Link is less than 8 or if the 3330 /* Check to see if Link is less than 8 or if the
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
index 32d06824fe3e..c2e420a84d22 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
@@ -757,7 +757,7 @@ __vxge_hw_verify_pci_e_info(struct __vxge_hw_device *hldev)
757 u16 lnk; 757 u16 lnk;
758 758
759 /* Get the negotiated link width and speed from PCI config space */ 759 /* Get the negotiated link width and speed from PCI config space */
760 pci_read_config_word(dev, dev->pcie_cap + PCI_EXP_LNKSTA, &lnk); 760 pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
761 761
762 if ((lnk & PCI_EXP_LNKSTA_CLS) != 1) 762 if ((lnk & PCI_EXP_LNKSTA_CLS) != 1)
763 return VXGE_HW_ERR_INVALID_PCI_INFO; 763 return VXGE_HW_ERR_INVALID_PCI_INFO;
@@ -1982,7 +1982,7 @@ u16 vxge_hw_device_link_width_get(struct __vxge_hw_device *hldev)
1982 struct pci_dev *dev = hldev->pdev; 1982 struct pci_dev *dev = hldev->pdev;
1983 u16 lnk; 1983 u16 lnk;
1984 1984
1985 pci_read_config_word(dev, dev->pcie_cap + PCI_EXP_LNKSTA, &lnk); 1985 pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
1986 return (lnk & VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH) >> 4; 1986 return (lnk & VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH) >> 4;
1987} 1987}
1988 1988
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index 342b3a79bd0f..01d6141cedd9 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -1382,7 +1382,7 @@ static void netxen_mask_aer_correctable(struct netxen_adapter *adapter)
1382 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP) 1382 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1383 return; 1383 return;
1384 1384
1385 if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT) 1385 if (pci_pcie_type(root) != PCI_EXP_TYPE_ROOT_PORT)
1386 return; 1386 return;
1387 1387
1388 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR); 1388 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR);
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index b47d5b35024e..a7cc56007b33 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -833,15 +833,8 @@ static void rtl_unlock_work(struct rtl8169_private *tp)
833 833
834static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) 834static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
835{ 835{
836 int cap = pci_pcie_cap(pdev); 836 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
837 837 PCI_EXP_DEVCTL_READRQ, force);
838 if (cap) {
839 u16 ctl;
840
841 pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
842 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force;
843 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl);
844 }
845} 838}
846 839
847struct rtl_cond { 840struct rtl_cond {
@@ -4739,28 +4732,14 @@ static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e,
4739 4732
4740static void rtl_disable_clock_request(struct pci_dev *pdev) 4733static void rtl_disable_clock_request(struct pci_dev *pdev)
4741{ 4734{
4742 int cap = pci_pcie_cap(pdev); 4735 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL,
4743 4736 PCI_EXP_LNKCTL_CLKREQ_EN);
4744 if (cap) {
4745 u16 ctl;
4746
4747 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
4748 ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
4749 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
4750 }
4751} 4737}
4752 4738
4753static void rtl_enable_clock_request(struct pci_dev *pdev) 4739static void rtl_enable_clock_request(struct pci_dev *pdev)
4754{ 4740{
4755 int cap = pci_pcie_cap(pdev); 4741 pcie_capability_set_word(pdev, PCI_EXP_LNKCTL,
4756 4742 PCI_EXP_LNKCTL_CLKREQ_EN);
4757 if (cap) {
4758 u16 ctl;
4759
4760 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
4761 ctl |= PCI_EXP_LNKCTL_CLKREQ_EN;
4762 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
4763 }
4764} 4743}
4765 4744
4766#define R8168_CPCMD_QUIRK_MASK (\ 4745#define R8168_CPCMD_QUIRK_MASK (\
@@ -5405,14 +5384,9 @@ static void rtl_hw_start_8101(struct net_device *dev)
5405 tp->event_slow &= ~RxFIFOOver; 5384 tp->event_slow &= ~RxFIFOOver;
5406 5385
5407 if (tp->mac_version == RTL_GIGA_MAC_VER_13 || 5386 if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
5408 tp->mac_version == RTL_GIGA_MAC_VER_16) { 5387 tp->mac_version == RTL_GIGA_MAC_VER_16)
5409 int cap = pci_pcie_cap(pdev); 5388 pcie_capability_set_word(pdev, PCI_EXP_DEVCTL,
5410 5389 PCI_EXP_DEVCTL_NOSNOOP_EN);
5411 if (cap) {
5412 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL,
5413 PCI_EXP_DEVCTL_NOSNOOP_EN);
5414 }
5415 }
5416 5390
5417 RTL_W8(Cfg9346, Cfg9346_Unlock); 5391 RTL_W8(Cfg9346, Cfg9346_Unlock);
5418 5392
diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index c2a0fe393267..3208dca66758 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -9762,9 +9762,8 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
9762 union niu_parent_id parent_id; 9762 union niu_parent_id parent_id;
9763 struct net_device *dev; 9763 struct net_device *dev;
9764 struct niu *np; 9764 struct niu *np;
9765 int err, pos; 9765 int err;
9766 u64 dma_mask; 9766 u64 dma_mask;
9767 u16 val16;
9768 9767
9769 niu_driver_version(); 9768 niu_driver_version();
9770 9769
@@ -9787,8 +9786,7 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
9787 goto err_out_disable_pdev; 9786 goto err_out_disable_pdev;
9788 } 9787 }
9789 9788
9790 pos = pci_pcie_cap(pdev); 9789 if (!pci_is_pcie(pdev)) {
9791 if (pos <= 0) {
9792 dev_err(&pdev->dev, "Cannot find PCI Express capability, aborting\n"); 9790 dev_err(&pdev->dev, "Cannot find PCI Express capability, aborting\n");
9793 goto err_out_free_res; 9791 goto err_out_free_res;
9794 } 9792 }
@@ -9813,14 +9811,11 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
9813 goto err_out_free_dev; 9811 goto err_out_free_dev;
9814 } 9812 }
9815 9813
9816 pci_read_config_word(pdev, pos + PCI_EXP_DEVCTL, &val16); 9814 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
9817 val16 &= ~PCI_EXP_DEVCTL_NOSNOOP_EN; 9815 PCI_EXP_DEVCTL_NOSNOOP_EN,
9818 val16 |= (PCI_EXP_DEVCTL_CERE | 9816 PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE |
9819 PCI_EXP_DEVCTL_NFERE | 9817 PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE |
9820 PCI_EXP_DEVCTL_FERE | 9818 PCI_EXP_DEVCTL_RELAX_EN);
9821 PCI_EXP_DEVCTL_URRE |
9822 PCI_EXP_DEVCTL_RELAX_EN);
9823 pci_write_config_word(pdev, pos + PCI_EXP_DEVCTL, val16);
9824 9819
9825 dma_mask = DMA_BIT_MASK(44); 9820 dma_mask = DMA_BIT_MASK(44);
9826 err = pci_set_dma_mask(pdev, dma_mask); 9821 err = pci_set_dma_mask(pdev, dma_mask);
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index 87b89d55e637..f7fe104df372 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -112,41 +112,32 @@ static void ath_pci_aspm_init(struct ath_common *common)
112 struct ath_hw *ah = sc->sc_ah; 112 struct ath_hw *ah = sc->sc_ah;
113 struct pci_dev *pdev = to_pci_dev(sc->dev); 113 struct pci_dev *pdev = to_pci_dev(sc->dev);
114 struct pci_dev *parent; 114 struct pci_dev *parent;
115 int pos; 115 u16 aspm;
116 u8 aspm;
117 116
118 if (!ah->is_pciexpress) 117 if (!ah->is_pciexpress)
119 return; 118 return;
120 119
121 pos = pci_pcie_cap(pdev);
122 if (!pos)
123 return;
124
125 parent = pdev->bus->self; 120 parent = pdev->bus->self;
126 if (!parent) 121 if (!parent)
127 return; 122 return;
128 123
129 if (ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) { 124 if (ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) {
130 /* Bluetooth coexistance requires disabling ASPM. */ 125 /* Bluetooth coexistance requires disabling ASPM. */
131 pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &aspm); 126 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL,
132 aspm &= ~(PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); 127 PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
133 pci_write_config_byte(pdev, pos + PCI_EXP_LNKCTL, aspm);
134 128
135 /* 129 /*
136 * Both upstream and downstream PCIe components should 130 * Both upstream and downstream PCIe components should
137 * have the same ASPM settings. 131 * have the same ASPM settings.
138 */ 132 */
139 pos = pci_pcie_cap(parent); 133 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
140 pci_read_config_byte(parent, pos + PCI_EXP_LNKCTL, &aspm); 134 PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
141 aspm &= ~(PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
142 pci_write_config_byte(parent, pos + PCI_EXP_LNKCTL, aspm);
143 135
144 ath_info(common, "Disabling ASPM since BTCOEX is enabled\n"); 136 ath_info(common, "Disabling ASPM since BTCOEX is enabled\n");
145 return; 137 return;
146 } 138 }
147 139
148 pos = pci_pcie_cap(parent); 140 pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
149 pci_read_config_byte(parent, pos + PCI_EXP_LNKCTL, &aspm);
150 if (aspm & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1)) { 141 if (aspm & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1)) {
151 ah->aspm_enabled = true; 142 ah->aspm_enabled = true;
152 /* Initialize PCIe PM and SERDES registers. */ 143 /* Initialize PCIe PM and SERDES registers. */
diff --git a/drivers/net/wireless/iwlegacy/common.h b/drivers/net/wireless/iwlegacy/common.h
index 5f5017767b99..724682669060 100644
--- a/drivers/net/wireless/iwlegacy/common.h
+++ b/drivers/net/wireless/iwlegacy/common.h
@@ -1832,10 +1832,8 @@ int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd);
1832static inline u16 1832static inline u16
1833il_pcie_link_ctl(struct il_priv *il) 1833il_pcie_link_ctl(struct il_priv *il)
1834{ 1834{
1835 int pos;
1836 u16 pci_lnk_ctl; 1835 u16 pci_lnk_ctl;
1837 pos = pci_pcie_cap(il->pci_dev); 1836 pcie_capability_read_word(il->pci_dev, PCI_EXP_LNKCTL, &pci_lnk_ctl);
1838 pci_read_config_word(il->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
1839 return pci_lnk_ctl; 1837 return pci_lnk_ctl;
1840} 1838}
1841 1839
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 939c2f78df58..26bdbe3ff7cf 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -675,13 +675,10 @@ static void iwl_set_pwr_vmain(struct iwl_trans *trans)
675static u16 iwl_pciexp_link_ctrl(struct iwl_trans *trans) 675static u16 iwl_pciexp_link_ctrl(struct iwl_trans *trans)
676{ 676{
677 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 677 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
678 int pos;
679 u16 pci_lnk_ctl; 678 u16 pci_lnk_ctl;
680 679
681 struct pci_dev *pci_dev = trans_pcie->pci_dev; 680 pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_LNKCTL,
682 681 &pci_lnk_ctl);
683 pos = pci_pcie_cap(pci_dev);
684 pci_read_config_word(pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
685 return pci_lnk_ctl; 682 return pci_lnk_ctl;
686} 683}
687 684
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 80f75d3ba84a..5983631a1b1a 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -372,13 +372,11 @@ static void rtl_pci_parse_configuration(struct pci_dev *pdev,
372 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 372 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
373 373
374 u8 tmp; 374 u8 tmp;
375 int pos; 375 u16 linkctrl_reg;
376 u8 linkctrl_reg;
377 376
378 /*Link Control Register */ 377 /*Link Control Register */
379 pos = pci_pcie_cap(pdev); 378 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &linkctrl_reg);
380 pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &linkctrl_reg); 379 pcipriv->ndis_adapter.linkctrl_reg = (u8)linkctrl_reg;
381 pcipriv->ndis_adapter.linkctrl_reg = linkctrl_reg;
382 380
383 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Link Control Register =%x\n", 381 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Link Control Register =%x\n",
384 pcipriv->ndis_adapter.linkctrl_reg); 382 pcipriv->ndis_adapter.linkctrl_reg);
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index ba91a7e17519..3af0478c057b 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -469,3 +469,205 @@ void pci_cfg_access_unlock(struct pci_dev *dev)
469 raw_spin_unlock_irqrestore(&pci_lock, flags); 469 raw_spin_unlock_irqrestore(&pci_lock, flags);
470} 470}
471EXPORT_SYMBOL_GPL(pci_cfg_access_unlock); 471EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
472
473static inline int pcie_cap_version(const struct pci_dev *dev)
474{
475 return dev->pcie_flags_reg & PCI_EXP_FLAGS_VERS;
476}
477
478static inline bool pcie_cap_has_devctl(const struct pci_dev *dev)
479{
480 return true;
481}
482
483static inline bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
484{
485 int type = pci_pcie_type(dev);
486
487 return pcie_cap_version(dev) > 1 ||
488 type == PCI_EXP_TYPE_ROOT_PORT ||
489 type == PCI_EXP_TYPE_ENDPOINT ||
490 type == PCI_EXP_TYPE_LEG_END;
491}
492
493static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev)
494{
495 int type = pci_pcie_type(dev);
496
497 return pcie_cap_version(dev) > 1 ||
498 type == PCI_EXP_TYPE_ROOT_PORT ||
499 (type == PCI_EXP_TYPE_DOWNSTREAM &&
500 dev->pcie_flags_reg & PCI_EXP_FLAGS_SLOT);
501}
502
503static inline bool pcie_cap_has_rtctl(const struct pci_dev *dev)
504{
505 int type = pci_pcie_type(dev);
506
507 return pcie_cap_version(dev) > 1 ||
508 type == PCI_EXP_TYPE_ROOT_PORT ||
509 type == PCI_EXP_TYPE_RC_EC;
510}
511
512static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos)
513{
514 if (!pci_is_pcie(dev))
515 return false;
516
517 switch (pos) {
518 case PCI_EXP_FLAGS_TYPE:
519 return true;
520 case PCI_EXP_DEVCAP:
521 case PCI_EXP_DEVCTL:
522 case PCI_EXP_DEVSTA:
523 return pcie_cap_has_devctl(dev);
524 case PCI_EXP_LNKCAP:
525 case PCI_EXP_LNKCTL:
526 case PCI_EXP_LNKSTA:
527 return pcie_cap_has_lnkctl(dev);
528 case PCI_EXP_SLTCAP:
529 case PCI_EXP_SLTCTL:
530 case PCI_EXP_SLTSTA:
531 return pcie_cap_has_sltctl(dev);
532 case PCI_EXP_RTCTL:
533 case PCI_EXP_RTCAP:
534 case PCI_EXP_RTSTA:
535 return pcie_cap_has_rtctl(dev);
536 case PCI_EXP_DEVCAP2:
537 case PCI_EXP_DEVCTL2:
538 case PCI_EXP_LNKCAP2:
539 case PCI_EXP_LNKCTL2:
540 case PCI_EXP_LNKSTA2:
541 return pcie_cap_version(dev) > 1;
542 default:
543 return false;
544 }
545}
546
547/*
548 * Note that these accessor functions are only for the "PCI Express
549 * Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the
550 * other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.)
551 */
552int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
553{
554 int ret;
555
556 *val = 0;
557 if (pos & 1)
558 return -EINVAL;
559
560 if (pcie_capability_reg_implemented(dev, pos)) {
561 ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val);
562 /*
563 * Reset *val to 0 if pci_read_config_word() fails, it may
564 * have been written as 0xFFFF if hardware error happens
565 * during pci_read_config_word().
566 */
567 if (ret)
568 *val = 0;
569 return ret;
570 }
571
572 /*
573 * For Functions that do not implement the Slot Capabilities,
574 * Slot Status, and Slot Control registers, these spaces must
575 * be hardwired to 0b, with the exception of the Presence Detect
576 * State bit in the Slot Status register of Downstream Ports,
577 * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8)
578 */
579 if (pci_is_pcie(dev) && pos == PCI_EXP_SLTSTA &&
580 pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) {
581 *val = PCI_EXP_SLTSTA_PDS;
582 }
583
584 return 0;
585}
586EXPORT_SYMBOL(pcie_capability_read_word);
587
588int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val)
589{
590 int ret;
591
592 *val = 0;
593 if (pos & 3)
594 return -EINVAL;
595
596 if (pcie_capability_reg_implemented(dev, pos)) {
597 ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val);
598 /*
599 * Reset *val to 0 if pci_read_config_dword() fails, it may
600 * have been written as 0xFFFFFFFF if hardware error happens
601 * during pci_read_config_dword().
602 */
603 if (ret)
604 *val = 0;
605 return ret;
606 }
607
608 if (pci_is_pcie(dev) && pos == PCI_EXP_SLTCTL &&
609 pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) {
610 *val = PCI_EXP_SLTSTA_PDS;
611 }
612
613 return 0;
614}
615EXPORT_SYMBOL(pcie_capability_read_dword);
616
617int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val)
618{
619 if (pos & 1)
620 return -EINVAL;
621
622 if (!pcie_capability_reg_implemented(dev, pos))
623 return 0;
624
625 return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
626}
627EXPORT_SYMBOL(pcie_capability_write_word);
628
629int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val)
630{
631 if (pos & 3)
632 return -EINVAL;
633
634 if (!pcie_capability_reg_implemented(dev, pos))
635 return 0;
636
637 return pci_write_config_dword(dev, pci_pcie_cap(dev) + pos, val);
638}
639EXPORT_SYMBOL(pcie_capability_write_dword);
640
641int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
642 u16 clear, u16 set)
643{
644 int ret;
645 u16 val;
646
647 ret = pcie_capability_read_word(dev, pos, &val);
648 if (!ret) {
649 val &= ~clear;
650 val |= set;
651 ret = pcie_capability_write_word(dev, pos, val);
652 }
653
654 return ret;
655}
656EXPORT_SYMBOL(pcie_capability_clear_and_set_word);
657
658int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
659 u32 clear, u32 set)
660{
661 int ret;
662 u32 val;
663
664 ret = pcie_capability_read_dword(dev, pos, &val);
665 if (!ret) {
666 val &= ~clear;
667 val |= set;
668 ret = pcie_capability_write_dword(dev, pos, val);
669 }
670
671 return ret;
672}
673EXPORT_SYMBOL(pcie_capability_clear_and_set_dword);
diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
index 376d70d17176..24d709b7388c 100644
--- a/drivers/pci/hotplug/pciehp_acpi.c
+++ b/drivers/pci/hotplug/pciehp_acpi.c
@@ -81,16 +81,12 @@ static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots);
81/* Dummy driver for dumplicate name detection */ 81/* Dummy driver for dumplicate name detection */
82static int __init dummy_probe(struct pcie_device *dev) 82static int __init dummy_probe(struct pcie_device *dev)
83{ 83{
84 int pos;
85 u32 slot_cap; 84 u32 slot_cap;
86 acpi_handle handle; 85 acpi_handle handle;
87 struct dummy_slot *slot, *tmp; 86 struct dummy_slot *slot, *tmp;
88 struct pci_dev *pdev = dev->port; 87 struct pci_dev *pdev = dev->port;
89 88
90 pos = pci_pcie_cap(pdev); 89 pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &slot_cap);
91 if (!pos)
92 return -ENODEV;
93 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
94 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 90 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
95 if (!slot) 91 if (!slot)
96 return -ENOMEM; 92 return -ENOMEM;
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 302451e8289d..13b2eaf7ba43 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -44,25 +44,25 @@
44static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value) 44static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
45{ 45{
46 struct pci_dev *dev = ctrl->pcie->port; 46 struct pci_dev *dev = ctrl->pcie->port;
47 return pci_read_config_word(dev, pci_pcie_cap(dev) + reg, value); 47 return pcie_capability_read_word(dev, reg, value);
48} 48}
49 49
50static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value) 50static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value)
51{ 51{
52 struct pci_dev *dev = ctrl->pcie->port; 52 struct pci_dev *dev = ctrl->pcie->port;
53 return pci_read_config_dword(dev, pci_pcie_cap(dev) + reg, value); 53 return pcie_capability_read_dword(dev, reg, value);
54} 54}
55 55
56static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value) 56static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value)
57{ 57{
58 struct pci_dev *dev = ctrl->pcie->port; 58 struct pci_dev *dev = ctrl->pcie->port;
59 return pci_write_config_word(dev, pci_pcie_cap(dev) + reg, value); 59 return pcie_capability_write_word(dev, reg, value);
60} 60}
61 61
62static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value) 62static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
63{ 63{
64 struct pci_dev *dev = ctrl->pcie->port; 64 struct pci_dev *dev = ctrl->pcie->port;
65 return pci_write_config_dword(dev, pci_pcie_cap(dev) + reg, value); 65 return pcie_capability_write_dword(dev, reg, value);
66} 66}
67 67
68/* Power Control Command */ 68/* Power Control Command */
@@ -855,10 +855,6 @@ struct controller *pcie_init(struct pcie_device *dev)
855 goto abort; 855 goto abort;
856 } 856 }
857 ctrl->pcie = dev; 857 ctrl->pcie = dev;
858 if (!pci_pcie_cap(pdev)) {
859 ctrl_err(ctrl, "Cannot find PCI Express capability\n");
860 goto abort_ctrl;
861 }
862 if (pciehp_readl(ctrl, PCI_EXP_SLTCAP, &slot_cap)) { 858 if (pciehp_readl(ctrl, PCI_EXP_SLTCAP, &slot_cap)) {
863 ctrl_err(ctrl, "Cannot read SLOTCAP register\n"); 859 ctrl_err(ctrl, "Cannot read SLOTCAP register\n");
864 goto abort_ctrl; 860 goto abort_ctrl;
diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c
index 8c05a18c9770..fec2d5b75440 100644
--- a/drivers/pci/hotplug/pcihp_slot.c
+++ b/drivers/pci/hotplug/pcihp_slot.c
@@ -96,17 +96,11 @@ static void program_hpp_type1(struct pci_dev *dev, struct hpp_type1 *hpp)
96static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) 96static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
97{ 97{
98 int pos; 98 int pos;
99 u16 reg16;
100 u32 reg32; 99 u32 reg32;
101 100
102 if (!hpp) 101 if (!hpp)
103 return; 102 return;
104 103
105 /* Find PCI Express capability */
106 pos = pci_pcie_cap(dev);
107 if (!pos)
108 return;
109
110 if (hpp->revision > 1) { 104 if (hpp->revision > 1) {
111 dev_warn(&dev->dev, "PCIe settings rev %d not supported\n", 105 dev_warn(&dev->dev, "PCIe settings rev %d not supported\n",
112 hpp->revision); 106 hpp->revision);
@@ -114,17 +108,13 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
114 } 108 }
115 109
116 /* Initialize Device Control Register */ 110 /* Initialize Device Control Register */
117 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16); 111 pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
118 reg16 = (reg16 & hpp->pci_exp_devctl_and) | hpp->pci_exp_devctl_or; 112 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or);
119 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16);
120 113
121 /* Initialize Link Control Register */ 114 /* Initialize Link Control Register */
122 if (dev->subordinate) { 115 if (dev->subordinate)
123 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &reg16); 116 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL,
124 reg16 = (reg16 & hpp->pci_exp_lnkctl_and) 117 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or);
125 | hpp->pci_exp_lnkctl_or;
126 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, reg16);
127 }
128 118
129 /* Find Advanced Error Reporting Enhanced Capability */ 119 /* Find Advanced Error Reporting Enhanced Capability */
130 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 120 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 74bbaf82638d..aeccc911abb8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -433,8 +433,8 @@ static int sriov_init(struct pci_dev *dev, int pos)
433 struct resource *res; 433 struct resource *res;
434 struct pci_dev *pdev; 434 struct pci_dev *pdev;
435 435
436 if (dev->pcie_type != PCI_EXP_TYPE_RC_END && 436 if (pci_pcie_type(dev) != PCI_EXP_TYPE_RC_END &&
437 dev->pcie_type != PCI_EXP_TYPE_ENDPOINT) 437 pci_pcie_type(dev) != PCI_EXP_TYPE_ENDPOINT)
438 return -ENODEV; 438 return -ENODEV;
439 439
440 pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &ctrl); 440 pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &ctrl);
@@ -503,7 +503,7 @@ found:
503 iov->self = dev; 503 iov->self = dev;
504 pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap); 504 pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
505 pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link); 505 pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
506 if (dev->pcie_type == PCI_EXP_TYPE_RC_END) 506 if (pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END)
507 iov->link = PCI_DEVFN(PCI_SLOT(dev->devfn), iov->link); 507 iov->link = PCI_DEVFN(PCI_SLOT(dev->devfn), iov->link);
508 508
509 if (pdev) 509 if (pdev)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index f3ea977a5b1b..fac08f508d09 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -254,38 +254,6 @@ int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
254} 254}
255 255
256/** 256/**
257 * pci_pcie_cap2 - query for devices' PCI_CAP_ID_EXP v2 capability structure
258 * @dev: PCI device to check
259 *
260 * Like pci_pcie_cap() but also checks that the PCIe capability version is
261 * >= 2. Note that v1 capability structures could be sparse in that not
262 * all register fields were required. v2 requires the entire structure to
263 * be present size wise, while still allowing for non-implemented registers
264 * to exist but they must be hardwired to 0.
265 *
266 * Due to the differences in the versions of capability structures, one
267 * must be careful not to try and access non-existant registers that may
268 * exist in early versions - v1 - of Express devices.
269 *
270 * Returns the offset of the PCIe capability structure as long as the
271 * capability version is >= 2; otherwise 0 is returned.
272 */
273static int pci_pcie_cap2(struct pci_dev *dev)
274{
275 u16 flags;
276 int pos;
277
278 pos = pci_pcie_cap(dev);
279 if (pos) {
280 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
281 if ((flags & PCI_EXP_FLAGS_VERS) < 2)
282 pos = 0;
283 }
284
285 return pos;
286}
287
288/**
289 * pci_find_ext_capability - Find an extended capability 257 * pci_find_ext_capability - Find an extended capability
290 * @dev: PCI device to query 258 * @dev: PCI device to query
291 * @cap: capability code 259 * @cap: capability code
@@ -854,21 +822,6 @@ EXPORT_SYMBOL(pci_choose_state);
854 822
855#define PCI_EXP_SAVE_REGS 7 823#define PCI_EXP_SAVE_REGS 7
856 824
857#define pcie_cap_has_devctl(type, flags) 1
858#define pcie_cap_has_lnkctl(type, flags) \
859 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
860 (type == PCI_EXP_TYPE_ROOT_PORT || \
861 type == PCI_EXP_TYPE_ENDPOINT || \
862 type == PCI_EXP_TYPE_LEG_END))
863#define pcie_cap_has_sltctl(type, flags) \
864 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
865 ((type == PCI_EXP_TYPE_ROOT_PORT) || \
866 (type == PCI_EXP_TYPE_DOWNSTREAM && \
867 (flags & PCI_EXP_FLAGS_SLOT))))
868#define pcie_cap_has_rtctl(type, flags) \
869 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
870 (type == PCI_EXP_TYPE_ROOT_PORT || \
871 type == PCI_EXP_TYPE_RC_EC))
872 825
873static struct pci_cap_saved_state *pci_find_saved_cap( 826static struct pci_cap_saved_state *pci_find_saved_cap(
874 struct pci_dev *pci_dev, char cap) 827 struct pci_dev *pci_dev, char cap)
@@ -885,13 +838,11 @@ static struct pci_cap_saved_state *pci_find_saved_cap(
885 838
886static int pci_save_pcie_state(struct pci_dev *dev) 839static int pci_save_pcie_state(struct pci_dev *dev)
887{ 840{
888 int pos, i = 0; 841 int i = 0;
889 struct pci_cap_saved_state *save_state; 842 struct pci_cap_saved_state *save_state;
890 u16 *cap; 843 u16 *cap;
891 u16 flags;
892 844
893 pos = pci_pcie_cap(dev); 845 if (!pci_is_pcie(dev))
894 if (!pos)
895 return 0; 846 return 0;
896 847
897 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 848 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
@@ -899,60 +850,37 @@ static int pci_save_pcie_state(struct pci_dev *dev)
899 dev_err(&dev->dev, "buffer not found in %s\n", __func__); 850 dev_err(&dev->dev, "buffer not found in %s\n", __func__);
900 return -ENOMEM; 851 return -ENOMEM;
901 } 852 }
902 cap = (u16 *)&save_state->cap.data[0];
903
904 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
905 853
906 if (pcie_cap_has_devctl(dev->pcie_type, flags)) 854 cap = (u16 *)&save_state->cap.data[0];
907 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]); 855 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &cap[i++]);
908 if (pcie_cap_has_lnkctl(dev->pcie_type, flags)) 856 pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &cap[i++]);
909 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]); 857 pcie_capability_read_word(dev, PCI_EXP_SLTCTL, &cap[i++]);
910 if (pcie_cap_has_sltctl(dev->pcie_type, flags)) 858 pcie_capability_read_word(dev, PCI_EXP_RTCTL, &cap[i++]);
911 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); 859 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &cap[i++]);
912 if (pcie_cap_has_rtctl(dev->pcie_type, flags)) 860 pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &cap[i++]);
913 pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); 861 pcie_capability_read_word(dev, PCI_EXP_SLTCTL2, &cap[i++]);
914
915 pos = pci_pcie_cap2(dev);
916 if (!pos)
917 return 0;
918 862
919 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &cap[i++]);
920 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL2, &cap[i++]);
921 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL2, &cap[i++]);
922 return 0; 863 return 0;
923} 864}
924 865
925static void pci_restore_pcie_state(struct pci_dev *dev) 866static void pci_restore_pcie_state(struct pci_dev *dev)
926{ 867{
927 int i = 0, pos; 868 int i = 0;
928 struct pci_cap_saved_state *save_state; 869 struct pci_cap_saved_state *save_state;
929 u16 *cap; 870 u16 *cap;
930 u16 flags;
931 871
932 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 872 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
933 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 873 if (!save_state)
934 if (!save_state || pos <= 0)
935 return;
936 cap = (u16 *)&save_state->cap.data[0];
937
938 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
939
940 if (pcie_cap_has_devctl(dev->pcie_type, flags))
941 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
942 if (pcie_cap_has_lnkctl(dev->pcie_type, flags))
943 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
944 if (pcie_cap_has_sltctl(dev->pcie_type, flags))
945 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
946 if (pcie_cap_has_rtctl(dev->pcie_type, flags))
947 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
948
949 pos = pci_pcie_cap2(dev);
950 if (!pos)
951 return; 874 return;
952 875
953 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); 876 cap = (u16 *)&save_state->cap.data[0];
954 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); 877 pcie_capability_write_word(dev, PCI_EXP_DEVCTL, cap[i++]);
955 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); 878 pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++]);
879 pcie_capability_write_word(dev, PCI_EXP_SLTCTL, cap[i++]);
880 pcie_capability_write_word(dev, PCI_EXP_RTCTL, cap[i++]);
881 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, cap[i++]);
882 pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, cap[i++]);
883 pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
956} 884}
957 885
958 886
@@ -2066,35 +1994,24 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
2066 */ 1994 */
2067void pci_enable_ari(struct pci_dev *dev) 1995void pci_enable_ari(struct pci_dev *dev)
2068{ 1996{
2069 int pos;
2070 u32 cap; 1997 u32 cap;
2071 u16 ctrl;
2072 struct pci_dev *bridge; 1998 struct pci_dev *bridge;
2073 1999
2074 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) 2000 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn)
2075 return; 2001 return;
2076 2002
2077 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 2003 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI))
2078 if (!pos)
2079 return; 2004 return;
2080 2005
2081 bridge = dev->bus->self; 2006 bridge = dev->bus->self;
2082 if (!bridge) 2007 if (!bridge)
2083 return; 2008 return;
2084 2009
2085 /* ARI is a PCIe cap v2 feature */ 2010 pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
2086 pos = pci_pcie_cap2(bridge);
2087 if (!pos)
2088 return;
2089
2090 pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap);
2091 if (!(cap & PCI_EXP_DEVCAP2_ARI)) 2011 if (!(cap & PCI_EXP_DEVCAP2_ARI))
2092 return; 2012 return;
2093 2013
2094 pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl); 2014 pcie_capability_set_word(bridge, PCI_EXP_DEVCTL2, PCI_EXP_DEVCTL2_ARI);
2095 ctrl |= PCI_EXP_DEVCTL2_ARI;
2096 pci_write_config_word(bridge, pos + PCI_EXP_DEVCTL2, ctrl);
2097
2098 bridge->ari_enabled = 1; 2015 bridge->ari_enabled = 1;
2099} 2016}
2100 2017
@@ -2109,20 +2026,14 @@ void pci_enable_ari(struct pci_dev *dev)
2109 */ 2026 */
2110void pci_enable_ido(struct pci_dev *dev, unsigned long type) 2027void pci_enable_ido(struct pci_dev *dev, unsigned long type)
2111{ 2028{
2112 int pos; 2029 u16 ctrl = 0;
2113 u16 ctrl;
2114 2030
2115 /* ID-based Ordering is a PCIe cap v2 feature */
2116 pos = pci_pcie_cap2(dev);
2117 if (!pos)
2118 return;
2119
2120 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2121 if (type & PCI_EXP_IDO_REQUEST) 2031 if (type & PCI_EXP_IDO_REQUEST)
2122 ctrl |= PCI_EXP_IDO_REQ_EN; 2032 ctrl |= PCI_EXP_IDO_REQ_EN;
2123 if (type & PCI_EXP_IDO_COMPLETION) 2033 if (type & PCI_EXP_IDO_COMPLETION)
2124 ctrl |= PCI_EXP_IDO_CMP_EN; 2034 ctrl |= PCI_EXP_IDO_CMP_EN;
2125 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2035 if (ctrl)
2036 pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, ctrl);
2126} 2037}
2127EXPORT_SYMBOL(pci_enable_ido); 2038EXPORT_SYMBOL(pci_enable_ido);
2128 2039
@@ -2133,20 +2044,14 @@ EXPORT_SYMBOL(pci_enable_ido);
2133 */ 2044 */
2134void pci_disable_ido(struct pci_dev *dev, unsigned long type) 2045void pci_disable_ido(struct pci_dev *dev, unsigned long type)
2135{ 2046{
2136 int pos; 2047 u16 ctrl = 0;
2137 u16 ctrl;
2138 2048
2139 /* ID-based Ordering is a PCIe cap v2 feature */
2140 pos = pci_pcie_cap2(dev);
2141 if (!pos)
2142 return;
2143
2144 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2145 if (type & PCI_EXP_IDO_REQUEST) 2049 if (type & PCI_EXP_IDO_REQUEST)
2146 ctrl &= ~PCI_EXP_IDO_REQ_EN; 2050 ctrl |= PCI_EXP_IDO_REQ_EN;
2147 if (type & PCI_EXP_IDO_COMPLETION) 2051 if (type & PCI_EXP_IDO_COMPLETION)
2148 ctrl &= ~PCI_EXP_IDO_CMP_EN; 2052 ctrl |= PCI_EXP_IDO_CMP_EN;
2149 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2053 if (ctrl)
2054 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, ctrl);
2150} 2055}
2151EXPORT_SYMBOL(pci_disable_ido); 2056EXPORT_SYMBOL(pci_disable_ido);
2152 2057
@@ -2171,17 +2076,11 @@ EXPORT_SYMBOL(pci_disable_ido);
2171 */ 2076 */
2172int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) 2077int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2173{ 2078{
2174 int pos;
2175 u32 cap; 2079 u32 cap;
2176 u16 ctrl; 2080 u16 ctrl;
2177 int ret; 2081 int ret;
2178 2082
2179 /* OBFF is a PCIe cap v2 feature */ 2083 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
2180 pos = pci_pcie_cap2(dev);
2181 if (!pos)
2182 return -ENOTSUPP;
2183
2184 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
2185 if (!(cap & PCI_EXP_OBFF_MASK)) 2084 if (!(cap & PCI_EXP_OBFF_MASK))
2186 return -ENOTSUPP; /* no OBFF support at all */ 2085 return -ENOTSUPP; /* no OBFF support at all */
2187 2086
@@ -2192,7 +2091,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2192 return ret; 2091 return ret;
2193 } 2092 }
2194 2093
2195 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2094 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &ctrl);
2196 if (cap & PCI_EXP_OBFF_WAKE) 2095 if (cap & PCI_EXP_OBFF_WAKE)
2197 ctrl |= PCI_EXP_OBFF_WAKE_EN; 2096 ctrl |= PCI_EXP_OBFF_WAKE_EN;
2198 else { 2097 else {
@@ -2210,7 +2109,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2210 return -ENOTSUPP; 2109 return -ENOTSUPP;
2211 } 2110 }
2212 } 2111 }
2213 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2112 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, ctrl);
2214 2113
2215 return 0; 2114 return 0;
2216} 2115}
@@ -2224,17 +2123,7 @@ EXPORT_SYMBOL(pci_enable_obff);
2224 */ 2123 */
2225void pci_disable_obff(struct pci_dev *dev) 2124void pci_disable_obff(struct pci_dev *dev)
2226{ 2125{
2227 int pos; 2126 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_OBFF_WAKE_EN);
2228 u16 ctrl;
2229
2230 /* OBFF is a PCIe cap v2 feature */
2231 pos = pci_pcie_cap2(dev);
2232 if (!pos)
2233 return;
2234
2235 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2236 ctrl &= ~PCI_EXP_OBFF_WAKE_EN;
2237 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
2238} 2127}
2239EXPORT_SYMBOL(pci_disable_obff); 2128EXPORT_SYMBOL(pci_disable_obff);
2240 2129
@@ -2247,15 +2136,9 @@ EXPORT_SYMBOL(pci_disable_obff);
2247 */ 2136 */
2248static bool pci_ltr_supported(struct pci_dev *dev) 2137static bool pci_ltr_supported(struct pci_dev *dev)
2249{ 2138{
2250 int pos;
2251 u32 cap; 2139 u32 cap;
2252 2140
2253 /* LTR is a PCIe cap v2 feature */ 2141 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
2254 pos = pci_pcie_cap2(dev);
2255 if (!pos)
2256 return false;
2257
2258 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
2259 2142
2260 return cap & PCI_EXP_DEVCAP2_LTR; 2143 return cap & PCI_EXP_DEVCAP2_LTR;
2261} 2144}
@@ -2272,22 +2155,15 @@ static bool pci_ltr_supported(struct pci_dev *dev)
2272 */ 2155 */
2273int pci_enable_ltr(struct pci_dev *dev) 2156int pci_enable_ltr(struct pci_dev *dev)
2274{ 2157{
2275 int pos;
2276 u16 ctrl;
2277 int ret; 2158 int ret;
2278 2159
2279 if (!pci_ltr_supported(dev))
2280 return -ENOTSUPP;
2281
2282 /* LTR is a PCIe cap v2 feature */
2283 pos = pci_pcie_cap2(dev);
2284 if (!pos)
2285 return -ENOTSUPP;
2286
2287 /* Only primary function can enable/disable LTR */ 2160 /* Only primary function can enable/disable LTR */
2288 if (PCI_FUNC(dev->devfn) != 0) 2161 if (PCI_FUNC(dev->devfn) != 0)
2289 return -EINVAL; 2162 return -EINVAL;
2290 2163
2164 if (!pci_ltr_supported(dev))
2165 return -ENOTSUPP;
2166
2291 /* Enable upstream ports first */ 2167 /* Enable upstream ports first */
2292 if (dev->bus->self) { 2168 if (dev->bus->self) {
2293 ret = pci_enable_ltr(dev->bus->self); 2169 ret = pci_enable_ltr(dev->bus->self);
@@ -2295,11 +2171,7 @@ int pci_enable_ltr(struct pci_dev *dev)
2295 return ret; 2171 return ret;
2296 } 2172 }
2297 2173
2298 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2174 return pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_LTR_EN);
2299 ctrl |= PCI_EXP_LTR_EN;
2300 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
2301
2302 return 0;
2303} 2175}
2304EXPORT_SYMBOL(pci_enable_ltr); 2176EXPORT_SYMBOL(pci_enable_ltr);
2305 2177
@@ -2309,24 +2181,14 @@ EXPORT_SYMBOL(pci_enable_ltr);
2309 */ 2181 */
2310void pci_disable_ltr(struct pci_dev *dev) 2182void pci_disable_ltr(struct pci_dev *dev)
2311{ 2183{
2312 int pos;
2313 u16 ctrl;
2314
2315 if (!pci_ltr_supported(dev))
2316 return;
2317
2318 /* LTR is a PCIe cap v2 feature */
2319 pos = pci_pcie_cap2(dev);
2320 if (!pos)
2321 return;
2322
2323 /* Only primary function can enable/disable LTR */ 2184 /* Only primary function can enable/disable LTR */
2324 if (PCI_FUNC(dev->devfn) != 0) 2185 if (PCI_FUNC(dev->devfn) != 0)
2325 return; 2186 return;
2326 2187
2327 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2188 if (!pci_ltr_supported(dev))
2328 ctrl &= ~PCI_EXP_LTR_EN; 2189 return;
2329 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2190
2191 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_LTR_EN);
2330} 2192}
2331EXPORT_SYMBOL(pci_disable_ltr); 2193EXPORT_SYMBOL(pci_disable_ltr);
2332 2194
@@ -2409,9 +2271,6 @@ void pci_enable_acs(struct pci_dev *dev)
2409 if (!pci_acs_enable) 2271 if (!pci_acs_enable)
2410 return; 2272 return;
2411 2273
2412 if (!pci_is_pcie(dev))
2413 return;
2414
2415 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); 2274 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
2416 if (!pos) 2275 if (!pos)
2417 return; 2276 return;
@@ -2459,8 +2318,8 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
2459 acs_flags &= (PCI_ACS_RR | PCI_ACS_CR | 2318 acs_flags &= (PCI_ACS_RR | PCI_ACS_CR |
2460 PCI_ACS_EC | PCI_ACS_DT); 2319 PCI_ACS_EC | PCI_ACS_DT);
2461 2320
2462 if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM || 2321 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM ||
2463 pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT || 2322 pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||
2464 pdev->multifunction) { 2323 pdev->multifunction) {
2465 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS); 2324 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
2466 if (!pos) 2325 if (!pos)
@@ -3176,15 +3035,10 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary);
3176static int pcie_flr(struct pci_dev *dev, int probe) 3035static int pcie_flr(struct pci_dev *dev, int probe)
3177{ 3036{
3178 int i; 3037 int i;
3179 int pos;
3180 u32 cap; 3038 u32 cap;
3181 u16 status, control; 3039 u16 status;
3182
3183 pos = pci_pcie_cap(dev);
3184 if (!pos)
3185 return -ENOTTY;
3186 3040
3187 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap); 3041 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap);
3188 if (!(cap & PCI_EXP_DEVCAP_FLR)) 3042 if (!(cap & PCI_EXP_DEVCAP_FLR))
3189 return -ENOTTY; 3043 return -ENOTTY;
3190 3044
@@ -3196,7 +3050,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3196 if (i) 3050 if (i)
3197 msleep((1 << (i - 1)) * 100); 3051 msleep((1 << (i - 1)) * 100);
3198 3052
3199 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); 3053 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
3200 if (!(status & PCI_EXP_DEVSTA_TRPND)) 3054 if (!(status & PCI_EXP_DEVSTA_TRPND))
3201 goto clear; 3055 goto clear;
3202 } 3056 }
@@ -3205,9 +3059,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3205 "proceeding with reset anyway\n"); 3059 "proceeding with reset anyway\n");
3206 3060
3207clear: 3061clear:
3208 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &control); 3062 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3209 control |= PCI_EXP_DEVCTL_BCR_FLR;
3210 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, control);
3211 3063
3212 msleep(100); 3064 msleep(100);
3213 3065
@@ -3575,18 +3427,11 @@ EXPORT_SYMBOL(pcix_set_mmrbc);
3575 */ 3427 */
3576int pcie_get_readrq(struct pci_dev *dev) 3428int pcie_get_readrq(struct pci_dev *dev)
3577{ 3429{
3578 int ret, cap;
3579 u16 ctl; 3430 u16 ctl;
3580 3431
3581 cap = pci_pcie_cap(dev); 3432 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
3582 if (!cap)
3583 return -EINVAL;
3584
3585 ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3586 if (!ret)
3587 ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
3588 3433
3589 return ret; 3434 return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
3590} 3435}
3591EXPORT_SYMBOL(pcie_get_readrq); 3436EXPORT_SYMBOL(pcie_get_readrq);
3592 3437
@@ -3600,19 +3445,11 @@ EXPORT_SYMBOL(pcie_get_readrq);
3600 */ 3445 */
3601int pcie_set_readrq(struct pci_dev *dev, int rq) 3446int pcie_set_readrq(struct pci_dev *dev, int rq)
3602{ 3447{
3603 int cap, err = -EINVAL; 3448 u16 v;
3604 u16 ctl, v;
3605 3449
3606 if (rq < 128 || rq > 4096 || !is_power_of_2(rq)) 3450 if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
3607 goto out; 3451 return -EINVAL;
3608
3609 cap = pci_pcie_cap(dev);
3610 if (!cap)
3611 goto out;
3612 3452
3613 err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3614 if (err)
3615 goto out;
3616 /* 3453 /*
3617 * If using the "performance" PCIe config, we clamp the 3454 * If using the "performance" PCIe config, we clamp the
3618 * read rq size to the max packet size to prevent the 3455 * read rq size to the max packet size to prevent the
@@ -3630,14 +3467,8 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
3630 3467
3631 v = (ffs(rq) - 8) << 12; 3468 v = (ffs(rq) - 8) << 12;
3632 3469
3633 if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) { 3470 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3634 ctl &= ~PCI_EXP_DEVCTL_READRQ; 3471 PCI_EXP_DEVCTL_READRQ, v);
3635 ctl |= v;
3636 err = pci_write_config_word(dev, cap + PCI_EXP_DEVCTL, ctl);
3637 }
3638
3639out:
3640 return err;
3641} 3472}
3642EXPORT_SYMBOL(pcie_set_readrq); 3473EXPORT_SYMBOL(pcie_set_readrq);
3643 3474
@@ -3650,18 +3481,11 @@ EXPORT_SYMBOL(pcie_set_readrq);
3650 */ 3481 */
3651int pcie_get_mps(struct pci_dev *dev) 3482int pcie_get_mps(struct pci_dev *dev)
3652{ 3483{
3653 int ret, cap;
3654 u16 ctl; 3484 u16 ctl;
3655 3485
3656 cap = pci_pcie_cap(dev); 3486 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
3657 if (!cap)
3658 return -EINVAL;
3659
3660 ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3661 if (!ret)
3662 ret = 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3663 3487
3664 return ret; 3488 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3665} 3489}
3666 3490
3667/** 3491/**
@@ -3674,32 +3498,18 @@ int pcie_get_mps(struct pci_dev *dev)
3674 */ 3498 */
3675int pcie_set_mps(struct pci_dev *dev, int mps) 3499int pcie_set_mps(struct pci_dev *dev, int mps)
3676{ 3500{
3677 int cap, err = -EINVAL; 3501 u16 v;
3678 u16 ctl, v;
3679 3502
3680 if (mps < 128 || mps > 4096 || !is_power_of_2(mps)) 3503 if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
3681 goto out; 3504 return -EINVAL;
3682 3505
3683 v = ffs(mps) - 8; 3506 v = ffs(mps) - 8;
3684 if (v > dev->pcie_mpss) 3507 if (v > dev->pcie_mpss)
3685 goto out; 3508 return -EINVAL;
3686 v <<= 5; 3509 v <<= 5;
3687 3510
3688 cap = pci_pcie_cap(dev); 3511 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3689 if (!cap) 3512 PCI_EXP_DEVCTL_PAYLOAD, v);
3690 goto out;
3691
3692 err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3693 if (err)
3694 goto out;
3695
3696 if ((ctl & PCI_EXP_DEVCTL_PAYLOAD) != v) {
3697 ctl &= ~PCI_EXP_DEVCTL_PAYLOAD;
3698 ctl |= v;
3699 err = pci_write_config_word(dev, cap + PCI_EXP_DEVCTL, ctl);
3700 }
3701out:
3702 return err;
3703} 3513}
3704 3514
3705/** 3515/**
diff --git a/drivers/pci/pcie/aer/aer_inject.c b/drivers/pci/pcie/aer/aer_inject.c
index 52229863e9fe..4e24cb8a94ae 100644
--- a/drivers/pci/pcie/aer/aer_inject.c
+++ b/drivers/pci/pcie/aer/aer_inject.c
@@ -288,7 +288,7 @@ static struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
288 while (1) { 288 while (1) {
289 if (!pci_is_pcie(dev)) 289 if (!pci_is_pcie(dev))
290 break; 290 break;
291 if (dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) 291 if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
292 return dev; 292 return dev;
293 if (!dev->bus->self) 293 if (!dev->bus->self)
294 break; 294 break;
diff --git a/drivers/pci/pcie/aer/aerdrv.c b/drivers/pci/pcie/aer/aerdrv.c
index 58ad7917553c..c78778fc0cba 100644
--- a/drivers/pci/pcie/aer/aerdrv.c
+++ b/drivers/pci/pcie/aer/aerdrv.c
@@ -81,10 +81,11 @@ bool pci_aer_available(void)
81static int set_device_error_reporting(struct pci_dev *dev, void *data) 81static int set_device_error_reporting(struct pci_dev *dev, void *data)
82{ 82{
83 bool enable = *((bool *)data); 83 bool enable = *((bool *)data);
84 int type = pci_pcie_type(dev);
84 85
85 if ((dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) || 86 if ((type == PCI_EXP_TYPE_ROOT_PORT) ||
86 (dev->pcie_type == PCI_EXP_TYPE_UPSTREAM) || 87 (type == PCI_EXP_TYPE_UPSTREAM) ||
87 (dev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)) { 88 (type == PCI_EXP_TYPE_DOWNSTREAM)) {
88 if (enable) 89 if (enable)
89 pci_enable_pcie_error_reporting(dev); 90 pci_enable_pcie_error_reporting(dev);
90 else 91 else
@@ -121,19 +122,17 @@ static void set_downstream_devices_error_reporting(struct pci_dev *dev,
121static void aer_enable_rootport(struct aer_rpc *rpc) 122static void aer_enable_rootport(struct aer_rpc *rpc)
122{ 123{
123 struct pci_dev *pdev = rpc->rpd->port; 124 struct pci_dev *pdev = rpc->rpd->port;
124 int pos, aer_pos; 125 int aer_pos;
125 u16 reg16; 126 u16 reg16;
126 u32 reg32; 127 u32 reg32;
127 128
128 pos = pci_pcie_cap(pdev);
129 /* Clear PCIe Capability's Device Status */ 129 /* Clear PCIe Capability's Device Status */
130 pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16); 130 pcie_capability_read_word(pdev, PCI_EXP_DEVSTA, &reg16);
131 pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16); 131 pcie_capability_write_word(pdev, PCI_EXP_DEVSTA, reg16);
132 132
133 /* Disable system error generation in response to error messages */ 133 /* Disable system error generation in response to error messages */
134 pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16); 134 pcie_capability_clear_word(pdev, PCI_EXP_RTCTL,
135 reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK); 135 SYSTEM_ERROR_INTR_ON_MESG_MASK);
136 pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
137 136
138 aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); 137 aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
139 /* Clear error status */ 138 /* Clear error status */
@@ -395,9 +394,8 @@ static void aer_error_resume(struct pci_dev *dev)
395 u16 reg16; 394 u16 reg16;
396 395
397 /* Clean up Root device status */ 396 /* Clean up Root device status */
398 pos = pci_pcie_cap(dev); 397 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &reg16);
399 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &reg16); 398 pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
400 pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, reg16);
401 399
402 /* Clean AER Root Error Status */ 400 /* Clean AER Root Error Status */
403 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 401 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
diff --git a/drivers/pci/pcie/aer/aerdrv_acpi.c b/drivers/pci/pcie/aer/aerdrv_acpi.c
index 124f20ff11b2..5194a7d41730 100644
--- a/drivers/pci/pcie/aer/aerdrv_acpi.c
+++ b/drivers/pci/pcie/aer/aerdrv_acpi.c
@@ -60,7 +60,7 @@ static int aer_hest_parse(struct acpi_hest_header *hest_hdr, void *data)
60 p = (struct acpi_hest_aer_common *)(hest_hdr + 1); 60 p = (struct acpi_hest_aer_common *)(hest_hdr + 1);
61 if (p->flags & ACPI_HEST_GLOBAL) { 61 if (p->flags & ACPI_HEST_GLOBAL) {
62 if ((pci_is_pcie(info->pci_dev) && 62 if ((pci_is_pcie(info->pci_dev) &&
63 info->pci_dev->pcie_type == pcie_type) || bridge) 63 pci_pcie_type(info->pci_dev) == pcie_type) || bridge)
64 ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST); 64 ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
65 } else 65 } else
66 if (hest_match_pci(p, info->pci_dev)) 66 if (hest_match_pci(p, info->pci_dev))
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index 0ca053538146..cefc0ddcacf6 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -32,53 +32,28 @@ static bool nosourceid;
32module_param(forceload, bool, 0); 32module_param(forceload, bool, 0);
33module_param(nosourceid, bool, 0); 33module_param(nosourceid, bool, 0);
34 34
35#define PCI_EXP_AER_FLAGS (PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | \
36 PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE)
37
35int pci_enable_pcie_error_reporting(struct pci_dev *dev) 38int pci_enable_pcie_error_reporting(struct pci_dev *dev)
36{ 39{
37 u16 reg16 = 0;
38 int pos;
39
40 if (pcie_aer_get_firmware_first(dev)) 40 if (pcie_aer_get_firmware_first(dev))
41 return -EIO; 41 return -EIO;
42 42
43 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 43 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR))
44 if (!pos)
45 return -EIO;
46
47 pos = pci_pcie_cap(dev);
48 if (!pos)
49 return -EIO; 44 return -EIO;
50 45
51 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16); 46 return pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_AER_FLAGS);
52 reg16 |= (PCI_EXP_DEVCTL_CERE |
53 PCI_EXP_DEVCTL_NFERE |
54 PCI_EXP_DEVCTL_FERE |
55 PCI_EXP_DEVCTL_URRE);
56 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16);
57
58 return 0;
59} 47}
60EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting); 48EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting);
61 49
62int pci_disable_pcie_error_reporting(struct pci_dev *dev) 50int pci_disable_pcie_error_reporting(struct pci_dev *dev)
63{ 51{
64 u16 reg16 = 0;
65 int pos;
66
67 if (pcie_aer_get_firmware_first(dev)) 52 if (pcie_aer_get_firmware_first(dev))
68 return -EIO; 53 return -EIO;
69 54
70 pos = pci_pcie_cap(dev); 55 return pcie_capability_clear_word(dev, PCI_EXP_DEVCTL,
71 if (!pos) 56 PCI_EXP_AER_FLAGS);
72 return -EIO;
73
74 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16);
75 reg16 &= ~(PCI_EXP_DEVCTL_CERE |
76 PCI_EXP_DEVCTL_NFERE |
77 PCI_EXP_DEVCTL_FERE |
78 PCI_EXP_DEVCTL_URRE);
79 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16);
80
81 return 0;
82} 57}
83EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting); 58EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
84 59
@@ -151,18 +126,12 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
151 */ 126 */
152 if (atomic_read(&dev->enable_cnt) == 0) 127 if (atomic_read(&dev->enable_cnt) == 0)
153 return false; 128 return false;
154 pos = pci_pcie_cap(dev);
155 if (!pos)
156 return false;
157 129
158 /* Check if AER is enabled */ 130 /* Check if AER is enabled */
159 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16); 131 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &reg16);
160 if (!(reg16 & ( 132 if (!(reg16 & PCI_EXP_AER_FLAGS))
161 PCI_EXP_DEVCTL_CERE |
162 PCI_EXP_DEVCTL_NFERE |
163 PCI_EXP_DEVCTL_FERE |
164 PCI_EXP_DEVCTL_URRE)))
165 return false; 133 return false;
134
166 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 135 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
167 if (!pos) 136 if (!pos)
168 return false; 137 return false;
@@ -465,7 +434,7 @@ static pci_ers_result_t reset_link(struct pci_dev *dev)
465 434
466 if (driver && driver->reset_link) { 435 if (driver && driver->reset_link) {
467 status = driver->reset_link(udev); 436 status = driver->reset_link(udev);
468 } else if (udev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) { 437 } else if (pci_pcie_type(udev) == PCI_EXP_TYPE_DOWNSTREAM) {
469 status = default_downstream_reset_link(udev); 438 status = default_downstream_reset_link(udev);
470 } else { 439 } else {
471 dev_printk(KERN_DEBUG, &dev->dev, 440 dev_printk(KERN_DEBUG, &dev->dev,
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index b500840a143b..213753b283a6 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -125,21 +125,16 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)
125 125
126static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) 126static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
127{ 127{
128 int pos;
129 u16 reg16;
130 struct pci_dev *child; 128 struct pci_dev *child;
131 struct pci_bus *linkbus = link->pdev->subordinate; 129 struct pci_bus *linkbus = link->pdev->subordinate;
132 130
133 list_for_each_entry(child, &linkbus->devices, bus_list) { 131 list_for_each_entry(child, &linkbus->devices, bus_list) {
134 pos = pci_pcie_cap(child);
135 if (!pos)
136 return;
137 pci_read_config_word(child, pos + PCI_EXP_LNKCTL, &reg16);
138 if (enable) 132 if (enable)
139 reg16 |= PCI_EXP_LNKCTL_CLKREQ_EN; 133 pcie_capability_set_word(child, PCI_EXP_LNKCTL,
134 PCI_EXP_LNKCTL_CLKREQ_EN);
140 else 135 else
141 reg16 &= ~PCI_EXP_LNKCTL_CLKREQ_EN; 136 pcie_capability_clear_word(child, PCI_EXP_LNKCTL,
142 pci_write_config_word(child, pos + PCI_EXP_LNKCTL, reg16); 137 PCI_EXP_LNKCTL_CLKREQ_EN);
143 } 138 }
144 link->clkpm_enabled = !!enable; 139 link->clkpm_enabled = !!enable;
145} 140}
@@ -157,7 +152,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
157 152
158static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) 153static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
159{ 154{
160 int pos, capable = 1, enabled = 1; 155 int capable = 1, enabled = 1;
161 u32 reg32; 156 u32 reg32;
162 u16 reg16; 157 u16 reg16;
163 struct pci_dev *child; 158 struct pci_dev *child;
@@ -165,16 +160,13 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
165 160
166 /* All functions should have the same cap and state, take the worst */ 161 /* All functions should have the same cap and state, take the worst */
167 list_for_each_entry(child, &linkbus->devices, bus_list) { 162 list_for_each_entry(child, &linkbus->devices, bus_list) {
168 pos = pci_pcie_cap(child); 163 pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &reg32);
169 if (!pos)
170 return;
171 pci_read_config_dword(child, pos + PCI_EXP_LNKCAP, &reg32);
172 if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { 164 if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
173 capable = 0; 165 capable = 0;
174 enabled = 0; 166 enabled = 0;
175 break; 167 break;
176 } 168 }
177 pci_read_config_word(child, pos + PCI_EXP_LNKCTL, &reg16); 169 pcie_capability_read_word(child, PCI_EXP_LNKCTL, &reg16);
178 if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) 170 if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN))
179 enabled = 0; 171 enabled = 0;
180 } 172 }
@@ -190,7 +182,7 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
190 */ 182 */
191static void pcie_aspm_configure_common_clock(struct pcie_link_state *link) 183static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
192{ 184{
193 int ppos, cpos, same_clock = 1; 185 int same_clock = 1;
194 u16 reg16, parent_reg, child_reg[8]; 186 u16 reg16, parent_reg, child_reg[8];
195 unsigned long start_jiffies; 187 unsigned long start_jiffies;
196 struct pci_dev *child, *parent = link->pdev; 188 struct pci_dev *child, *parent = link->pdev;
@@ -203,46 +195,43 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
203 BUG_ON(!pci_is_pcie(child)); 195 BUG_ON(!pci_is_pcie(child));
204 196
205 /* Check downstream component if bit Slot Clock Configuration is 1 */ 197 /* Check downstream component if bit Slot Clock Configuration is 1 */
206 cpos = pci_pcie_cap(child); 198 pcie_capability_read_word(child, PCI_EXP_LNKSTA, &reg16);
207 pci_read_config_word(child, cpos + PCI_EXP_LNKSTA, &reg16);
208 if (!(reg16 & PCI_EXP_LNKSTA_SLC)) 199 if (!(reg16 & PCI_EXP_LNKSTA_SLC))
209 same_clock = 0; 200 same_clock = 0;
210 201
211 /* Check upstream component if bit Slot Clock Configuration is 1 */ 202 /* Check upstream component if bit Slot Clock Configuration is 1 */
212 ppos = pci_pcie_cap(parent); 203 pcie_capability_read_word(parent, PCI_EXP_LNKSTA, &reg16);
213 pci_read_config_word(parent, ppos + PCI_EXP_LNKSTA, &reg16);
214 if (!(reg16 & PCI_EXP_LNKSTA_SLC)) 204 if (!(reg16 & PCI_EXP_LNKSTA_SLC))
215 same_clock = 0; 205 same_clock = 0;
216 206
217 /* Configure downstream component, all functions */ 207 /* Configure downstream component, all functions */
218 list_for_each_entry(child, &linkbus->devices, bus_list) { 208 list_for_each_entry(child, &linkbus->devices, bus_list) {
219 cpos = pci_pcie_cap(child); 209 pcie_capability_read_word(child, PCI_EXP_LNKCTL, &reg16);
220 pci_read_config_word(child, cpos + PCI_EXP_LNKCTL, &reg16);
221 child_reg[PCI_FUNC(child->devfn)] = reg16; 210 child_reg[PCI_FUNC(child->devfn)] = reg16;
222 if (same_clock) 211 if (same_clock)
223 reg16 |= PCI_EXP_LNKCTL_CCC; 212 reg16 |= PCI_EXP_LNKCTL_CCC;
224 else 213 else
225 reg16 &= ~PCI_EXP_LNKCTL_CCC; 214 reg16 &= ~PCI_EXP_LNKCTL_CCC;
226 pci_write_config_word(child, cpos + PCI_EXP_LNKCTL, reg16); 215 pcie_capability_write_word(child, PCI_EXP_LNKCTL, reg16);
227 } 216 }
228 217
229 /* Configure upstream component */ 218 /* Configure upstream component */
230 pci_read_config_word(parent, ppos + PCI_EXP_LNKCTL, &reg16); 219 pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &reg16);
231 parent_reg = reg16; 220 parent_reg = reg16;
232 if (same_clock) 221 if (same_clock)
233 reg16 |= PCI_EXP_LNKCTL_CCC; 222 reg16 |= PCI_EXP_LNKCTL_CCC;
234 else 223 else
235 reg16 &= ~PCI_EXP_LNKCTL_CCC; 224 reg16 &= ~PCI_EXP_LNKCTL_CCC;
236 pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16); 225 pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16);
237 226
238 /* Retrain link */ 227 /* Retrain link */
239 reg16 |= PCI_EXP_LNKCTL_RL; 228 reg16 |= PCI_EXP_LNKCTL_RL;
240 pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16); 229 pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16);
241 230
242 /* Wait for link training end. Break out after waiting for timeout */ 231 /* Wait for link training end. Break out after waiting for timeout */
243 start_jiffies = jiffies; 232 start_jiffies = jiffies;
244 for (;;) { 233 for (;;) {
245 pci_read_config_word(parent, ppos + PCI_EXP_LNKSTA, &reg16); 234 pcie_capability_read_word(parent, PCI_EXP_LNKSTA, &reg16);
246 if (!(reg16 & PCI_EXP_LNKSTA_LT)) 235 if (!(reg16 & PCI_EXP_LNKSTA_LT))
247 break; 236 break;
248 if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) 237 if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT))
@@ -255,12 +244,10 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
255 /* Training failed. Restore common clock configurations */ 244 /* Training failed. Restore common clock configurations */
256 dev_printk(KERN_ERR, &parent->dev, 245 dev_printk(KERN_ERR, &parent->dev,
257 "ASPM: Could not configure common clock\n"); 246 "ASPM: Could not configure common clock\n");
258 list_for_each_entry(child, &linkbus->devices, bus_list) { 247 list_for_each_entry(child, &linkbus->devices, bus_list)
259 cpos = pci_pcie_cap(child); 248 pcie_capability_write_word(child, PCI_EXP_LNKCTL,
260 pci_write_config_word(child, cpos + PCI_EXP_LNKCTL, 249 child_reg[PCI_FUNC(child->devfn)]);
261 child_reg[PCI_FUNC(child->devfn)]); 250 pcie_capability_write_word(parent, PCI_EXP_LNKCTL, parent_reg);
262 }
263 pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg);
264} 251}
265 252
266/* Convert L0s latency encoding to ns */ 253/* Convert L0s latency encoding to ns */
@@ -305,16 +292,14 @@ struct aspm_register_info {
305static void pcie_get_aspm_reg(struct pci_dev *pdev, 292static void pcie_get_aspm_reg(struct pci_dev *pdev,
306 struct aspm_register_info *info) 293 struct aspm_register_info *info)
307{ 294{
308 int pos;
309 u16 reg16; 295 u16 reg16;
310 u32 reg32; 296 u32 reg32;
311 297
312 pos = pci_pcie_cap(pdev); 298 pcie_capability_read_dword(pdev, PCI_EXP_LNKCAP, &reg32);
313 pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, &reg32);
314 info->support = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10; 299 info->support = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10;
315 info->latency_encoding_l0s = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12; 300 info->latency_encoding_l0s = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12;
316 info->latency_encoding_l1 = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15; 301 info->latency_encoding_l1 = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15;
317 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16); 302 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &reg16);
318 info->enabled = reg16 & PCI_EXP_LNKCTL_ASPMC; 303 info->enabled = reg16 & PCI_EXP_LNKCTL_ASPMC;
319} 304}
320 305
@@ -412,7 +397,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
412 * do ASPM for now. 397 * do ASPM for now.
413 */ 398 */
414 list_for_each_entry(child, &linkbus->devices, bus_list) { 399 list_for_each_entry(child, &linkbus->devices, bus_list) {
415 if (child->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) { 400 if (pci_pcie_type(child) == PCI_EXP_TYPE_PCI_BRIDGE) {
416 link->aspm_disable = ASPM_STATE_ALL; 401 link->aspm_disable = ASPM_STATE_ALL;
417 break; 402 break;
418 } 403 }
@@ -420,17 +405,15 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
420 405
421 /* Get and check endpoint acceptable latencies */ 406 /* Get and check endpoint acceptable latencies */
422 list_for_each_entry(child, &linkbus->devices, bus_list) { 407 list_for_each_entry(child, &linkbus->devices, bus_list) {
423 int pos;
424 u32 reg32, encoding; 408 u32 reg32, encoding;
425 struct aspm_latency *acceptable = 409 struct aspm_latency *acceptable =
426 &link->acceptable[PCI_FUNC(child->devfn)]; 410 &link->acceptable[PCI_FUNC(child->devfn)];
427 411
428 if (child->pcie_type != PCI_EXP_TYPE_ENDPOINT && 412 if (pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT &&
429 child->pcie_type != PCI_EXP_TYPE_LEG_END) 413 pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END)
430 continue; 414 continue;
431 415
432 pos = pci_pcie_cap(child); 416 pcie_capability_read_dword(child, PCI_EXP_DEVCAP, &reg32);
433 pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32);
434 /* Calculate endpoint L0s acceptable latency */ 417 /* Calculate endpoint L0s acceptable latency */
435 encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; 418 encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
436 acceptable->l0s = calc_l0s_acceptable(encoding); 419 acceptable->l0s = calc_l0s_acceptable(encoding);
@@ -444,13 +427,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
444 427
445static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val) 428static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val)
446{ 429{
447 u16 reg16; 430 pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL, 0x3, val);
448 int pos = pci_pcie_cap(pdev);
449
450 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
451 reg16 &= ~0x3;
452 reg16 |= val;
453 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
454} 431}
455 432
456static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state) 433static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state)
@@ -505,7 +482,6 @@ static void free_link_state(struct pcie_link_state *link)
505static int pcie_aspm_sanity_check(struct pci_dev *pdev) 482static int pcie_aspm_sanity_check(struct pci_dev *pdev)
506{ 483{
507 struct pci_dev *child; 484 struct pci_dev *child;
508 int pos;
509 u32 reg32; 485 u32 reg32;
510 486
511 /* 487 /*
@@ -513,8 +489,7 @@ static int pcie_aspm_sanity_check(struct pci_dev *pdev)
513 * very strange. Disable ASPM for the whole slot 489 * very strange. Disable ASPM for the whole slot
514 */ 490 */
515 list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { 491 list_for_each_entry(child, &pdev->subordinate->devices, bus_list) {
516 pos = pci_pcie_cap(child); 492 if (!pci_is_pcie(child))
517 if (!pos)
518 return -EINVAL; 493 return -EINVAL;
519 494
520 /* 495 /*
@@ -530,7 +505,7 @@ static int pcie_aspm_sanity_check(struct pci_dev *pdev)
530 * Disable ASPM for pre-1.1 PCIe device, we follow MS to use 505 * Disable ASPM for pre-1.1 PCIe device, we follow MS to use
531 * RBER bit to determine if a function is 1.1 version device 506 * RBER bit to determine if a function is 1.1 version device
532 */ 507 */
533 pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32); 508 pcie_capability_read_dword(child, PCI_EXP_DEVCAP, &reg32);
534 if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) { 509 if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) {
535 dev_printk(KERN_INFO, &child->dev, "disabling ASPM" 510 dev_printk(KERN_INFO, &child->dev, "disabling ASPM"
536 " on pre-1.1 PCIe device. You can enable it" 511 " on pre-1.1 PCIe device. You can enable it"
@@ -552,7 +527,7 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
552 INIT_LIST_HEAD(&link->children); 527 INIT_LIST_HEAD(&link->children);
553 INIT_LIST_HEAD(&link->link); 528 INIT_LIST_HEAD(&link->link);
554 link->pdev = pdev; 529 link->pdev = pdev;
555 if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) { 530 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM) {
556 struct pcie_link_state *parent; 531 struct pcie_link_state *parent;
557 parent = pdev->bus->parent->self->link_state; 532 parent = pdev->bus->parent->self->link_state;
558 if (!parent) { 533 if (!parent) {
@@ -585,12 +560,12 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
585 560
586 if (!pci_is_pcie(pdev) || pdev->link_state) 561 if (!pci_is_pcie(pdev) || pdev->link_state)
587 return; 562 return;
588 if (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && 563 if (pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT &&
589 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) 564 pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
590 return; 565 return;
591 566
592 /* VIA has a strange chipset, root port is under a bridge */ 567 /* VIA has a strange chipset, root port is under a bridge */
593 if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT && 568 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT &&
594 pdev->bus->self) 569 pdev->bus->self)
595 return; 570 return;
596 571
@@ -647,8 +622,8 @@ static void pcie_update_aspm_capable(struct pcie_link_state *root)
647 if (link->root != root) 622 if (link->root != root)
648 continue; 623 continue;
649 list_for_each_entry(child, &linkbus->devices, bus_list) { 624 list_for_each_entry(child, &linkbus->devices, bus_list) {
650 if ((child->pcie_type != PCI_EXP_TYPE_ENDPOINT) && 625 if ((pci_pcie_type(child) != PCI_EXP_TYPE_ENDPOINT) &&
651 (child->pcie_type != PCI_EXP_TYPE_LEG_END)) 626 (pci_pcie_type(child) != PCI_EXP_TYPE_LEG_END))
652 continue; 627 continue;
653 pcie_aspm_check_latency(child); 628 pcie_aspm_check_latency(child);
654 } 629 }
@@ -663,8 +638,8 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
663 638
664 if (!pci_is_pcie(pdev) || !parent || !parent->link_state) 639 if (!pci_is_pcie(pdev) || !parent || !parent->link_state)
665 return; 640 return;
666 if ((parent->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && 641 if ((pci_pcie_type(parent) != PCI_EXP_TYPE_ROOT_PORT) &&
667 (parent->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)) 642 (pci_pcie_type(parent) != PCI_EXP_TYPE_DOWNSTREAM))
668 return; 643 return;
669 644
670 down_read(&pci_bus_sem); 645 down_read(&pci_bus_sem);
@@ -704,8 +679,8 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev)
704 679
705 if (aspm_disabled || !pci_is_pcie(pdev) || !link) 680 if (aspm_disabled || !pci_is_pcie(pdev) || !link)
706 return; 681 return;
707 if ((pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && 682 if ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
708 (pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)) 683 (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM))
709 return; 684 return;
710 /* 685 /*
711 * Devices changed PM state, we should recheck if latency 686 * Devices changed PM state, we should recheck if latency
@@ -729,8 +704,8 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev)
729 if (aspm_policy != POLICY_POWERSAVE) 704 if (aspm_policy != POLICY_POWERSAVE)
730 return; 705 return;
731 706
732 if ((pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && 707 if ((pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT) &&
733 (pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)) 708 (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM))
734 return; 709 return;
735 710
736 down_read(&pci_bus_sem); 711 down_read(&pci_bus_sem);
@@ -757,8 +732,8 @@ static void __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem,
757 if (!pci_is_pcie(pdev)) 732 if (!pci_is_pcie(pdev))
758 return; 733 return;
759 734
760 if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT || 735 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||
761 pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) 736 pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM)
762 parent = pdev; 737 parent = pdev;
763 if (!parent || !parent->link_state) 738 if (!parent || !parent->link_state)
764 return; 739 return;
@@ -933,8 +908,8 @@ void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
933 struct pcie_link_state *link_state = pdev->link_state; 908 struct pcie_link_state *link_state = pdev->link_state;
934 909
935 if (!pci_is_pcie(pdev) || 910 if (!pci_is_pcie(pdev) ||
936 (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && 911 (pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT &&
937 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) 912 pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
938 return; 913 return;
939 914
940 if (link_state->aspm_support) 915 if (link_state->aspm_support)
@@ -950,8 +925,8 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev)
950 struct pcie_link_state *link_state = pdev->link_state; 925 struct pcie_link_state *link_state = pdev->link_state;
951 926
952 if (!pci_is_pcie(pdev) || 927 if (!pci_is_pcie(pdev) ||
953 (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && 928 (pci_pcie_type(pdev) != PCI_EXP_TYPE_ROOT_PORT &&
954 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) 929 pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
955 return; 930 return;
956 931
957 if (link_state->aspm_support) 932 if (link_state->aspm_support)
diff --git a/drivers/pci/pcie/pme.c b/drivers/pci/pcie/pme.c
index 001f1b78f39c..9ca0dc9ffd84 100644
--- a/drivers/pci/pcie/pme.c
+++ b/drivers/pci/pcie/pme.c
@@ -57,17 +57,12 @@ struct pcie_pme_service_data {
57 */ 57 */
58void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable) 58void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable)
59{ 59{
60 int rtctl_pos;
61 u16 rtctl;
62
63 rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
64
65 pci_read_config_word(dev, rtctl_pos, &rtctl);
66 if (enable) 60 if (enable)
67 rtctl |= PCI_EXP_RTCTL_PMEIE; 61 pcie_capability_set_word(dev, PCI_EXP_RTCTL,
62 PCI_EXP_RTCTL_PMEIE);
68 else 63 else
69 rtctl &= ~PCI_EXP_RTCTL_PMEIE; 64 pcie_capability_clear_word(dev, PCI_EXP_RTCTL,
70 pci_write_config_word(dev, rtctl_pos, rtctl); 65 PCI_EXP_RTCTL_PMEIE);
71} 66}
72 67
73/** 68/**
@@ -120,7 +115,7 @@ static bool pcie_pme_from_pci_bridge(struct pci_bus *bus, u8 devfn)
120 if (!dev) 115 if (!dev)
121 return false; 116 return false;
122 117
123 if (pci_is_pcie(dev) && dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) { 118 if (pci_is_pcie(dev) && pci_pcie_type(dev) == PCI_EXP_TYPE_PCI_BRIDGE) {
124 down_read(&pci_bus_sem); 119 down_read(&pci_bus_sem);
125 if (pcie_pme_walk_bus(bus)) 120 if (pcie_pme_walk_bus(bus))
126 found = true; 121 found = true;
@@ -226,18 +221,15 @@ static void pcie_pme_work_fn(struct work_struct *work)
226 struct pcie_pme_service_data *data = 221 struct pcie_pme_service_data *data =
227 container_of(work, struct pcie_pme_service_data, work); 222 container_of(work, struct pcie_pme_service_data, work);
228 struct pci_dev *port = data->srv->port; 223 struct pci_dev *port = data->srv->port;
229 int rtsta_pos;
230 u32 rtsta; 224 u32 rtsta;
231 225
232 rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
233
234 spin_lock_irq(&data->lock); 226 spin_lock_irq(&data->lock);
235 227
236 for (;;) { 228 for (;;) {
237 if (data->noirq) 229 if (data->noirq)
238 break; 230 break;
239 231
240 pci_read_config_dword(port, rtsta_pos, &rtsta); 232 pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta);
241 if (rtsta & PCI_EXP_RTSTA_PME) { 233 if (rtsta & PCI_EXP_RTSTA_PME) {
242 /* 234 /*
243 * Clear PME status of the port. If there are other 235 * Clear PME status of the port. If there are other
@@ -276,17 +268,14 @@ static irqreturn_t pcie_pme_irq(int irq, void *context)
276{ 268{
277 struct pci_dev *port; 269 struct pci_dev *port;
278 struct pcie_pme_service_data *data; 270 struct pcie_pme_service_data *data;
279 int rtsta_pos;
280 u32 rtsta; 271 u32 rtsta;
281 unsigned long flags; 272 unsigned long flags;
282 273
283 port = ((struct pcie_device *)context)->port; 274 port = ((struct pcie_device *)context)->port;
284 data = get_service_data((struct pcie_device *)context); 275 data = get_service_data((struct pcie_device *)context);
285 276
286 rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
287
288 spin_lock_irqsave(&data->lock, flags); 277 spin_lock_irqsave(&data->lock, flags);
289 pci_read_config_dword(port, rtsta_pos, &rtsta); 278 pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta);
290 279
291 if (!(rtsta & PCI_EXP_RTSTA_PME)) { 280 if (!(rtsta & PCI_EXP_RTSTA_PME)) {
292 spin_unlock_irqrestore(&data->lock, flags); 281 spin_unlock_irqrestore(&data->lock, flags);
@@ -335,13 +324,13 @@ static void pcie_pme_mark_devices(struct pci_dev *port)
335 struct pci_dev *dev; 324 struct pci_dev *dev;
336 325
337 /* Check if this is a root port event collector. */ 326 /* Check if this is a root port event collector. */
338 if (port->pcie_type != PCI_EXP_TYPE_RC_EC || !bus) 327 if (pci_pcie_type(port) != PCI_EXP_TYPE_RC_EC || !bus)
339 return; 328 return;
340 329
341 down_read(&pci_bus_sem); 330 down_read(&pci_bus_sem);
342 list_for_each_entry(dev, &bus->devices, bus_list) 331 list_for_each_entry(dev, &bus->devices, bus_list)
343 if (pci_is_pcie(dev) 332 if (pci_is_pcie(dev)
344 && dev->pcie_type == PCI_EXP_TYPE_RC_END) 333 && pci_pcie_type(dev) == PCI_EXP_TYPE_RC_END)
345 pcie_pme_set_native(dev, NULL); 334 pcie_pme_set_native(dev, NULL);
346 up_read(&pci_bus_sem); 335 up_read(&pci_bus_sem);
347 } 336 }
diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c
index 18bf90f748f6..67be55a7f260 100644
--- a/drivers/pci/pcie/portdrv_bus.c
+++ b/drivers/pci/pcie/portdrv_bus.c
@@ -38,7 +38,7 @@ static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
38 return 0; 38 return 0;
39 39
40 if ((driver->port_type != PCIE_ANY_PORT) && 40 if ((driver->port_type != PCIE_ANY_PORT) &&
41 (driver->port_type != pciedev->port->pcie_type)) 41 (driver->port_type != pci_pcie_type(pciedev->port)))
42 return 0; 42 return 0;
43 43
44 return 1; 44 return 1;
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 75915b30ad19..aede99171e90 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -246,8 +246,7 @@ static void cleanup_service_irqs(struct pci_dev *dev)
246 */ 246 */
247static int get_port_device_capability(struct pci_dev *dev) 247static int get_port_device_capability(struct pci_dev *dev)
248{ 248{
249 int services = 0, pos; 249 int services = 0;
250 u16 reg16;
251 u32 reg32; 250 u32 reg32;
252 int cap_mask = 0; 251 int cap_mask = 0;
253 int err; 252 int err;
@@ -265,11 +264,9 @@ static int get_port_device_capability(struct pci_dev *dev)
265 return 0; 264 return 0;
266 } 265 }
267 266
268 pos = pci_pcie_cap(dev);
269 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &reg16);
270 /* Hot-Plug Capable */ 267 /* Hot-Plug Capable */
271 if ((cap_mask & PCIE_PORT_SERVICE_HP) && (reg16 & PCI_EXP_FLAGS_SLOT)) { 268 if (cap_mask & PCIE_PORT_SERVICE_HP) {
272 pci_read_config_dword(dev, pos + PCI_EXP_SLTCAP, &reg32); 269 pcie_capability_read_dword(dev, PCI_EXP_SLTCAP, &reg32);
273 if (reg32 & PCI_EXP_SLTCAP_HPC) { 270 if (reg32 & PCI_EXP_SLTCAP_HPC) {
274 services |= PCIE_PORT_SERVICE_HP; 271 services |= PCIE_PORT_SERVICE_HP;
275 /* 272 /*
@@ -277,10 +274,8 @@ static int get_port_device_capability(struct pci_dev *dev)
277 * enabled by the BIOS and the hot-plug service driver 274 * enabled by the BIOS and the hot-plug service driver
278 * is not loaded. 275 * is not loaded.
279 */ 276 */
280 pos += PCI_EXP_SLTCTL; 277 pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
281 pci_read_config_word(dev, pos, &reg16); 278 PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
282 reg16 &= ~(PCI_EXP_SLTCTL_CCIE | PCI_EXP_SLTCTL_HPIE);
283 pci_write_config_word(dev, pos, reg16);
284 } 279 }
285 } 280 }
286 /* AER capable */ 281 /* AER capable */
@@ -298,7 +293,7 @@ static int get_port_device_capability(struct pci_dev *dev)
298 services |= PCIE_PORT_SERVICE_VC; 293 services |= PCIE_PORT_SERVICE_VC;
299 /* Root ports are capable of generating PME too */ 294 /* Root ports are capable of generating PME too */
300 if ((cap_mask & PCIE_PORT_SERVICE_PME) 295 if ((cap_mask & PCIE_PORT_SERVICE_PME)
301 && dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) { 296 && pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) {
302 services |= PCIE_PORT_SERVICE_PME; 297 services |= PCIE_PORT_SERVICE_PME;
303 /* 298 /*
304 * Disable PME interrupt on this port in case it's been enabled 299 * Disable PME interrupt on this port in case it's been enabled
@@ -336,7 +331,7 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
336 device->release = release_pcie_device; /* callback to free pcie dev */ 331 device->release = release_pcie_device; /* callback to free pcie dev */
337 dev_set_name(device, "%s:pcie%02x", 332 dev_set_name(device, "%s:pcie%02x",
338 pci_name(pdev), 333 pci_name(pdev),
339 get_descriptor_id(pdev->pcie_type, service)); 334 get_descriptor_id(pci_pcie_type(pdev), service));
340 device->parent = &pdev->dev; 335 device->parent = &pdev->dev;
341 device_enable_async_suspend(device); 336 device_enable_async_suspend(device);
342 337
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 3a7eefcb270a..2360330e48f1 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -64,14 +64,7 @@ __setup("pcie_ports=", pcie_port_setup);
64 */ 64 */
65void pcie_clear_root_pme_status(struct pci_dev *dev) 65void pcie_clear_root_pme_status(struct pci_dev *dev)
66{ 66{
67 int rtsta_pos; 67 pcie_capability_set_dword(dev, PCI_EXP_RTSTA, PCI_EXP_RTSTA_PME);
68 u32 rtsta;
69
70 rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
71
72 pci_read_config_dword(dev, rtsta_pos, &rtsta);
73 rtsta |= PCI_EXP_RTSTA_PME;
74 pci_write_config_dword(dev, rtsta_pos, rtsta);
75} 68}
76 69
77static int pcie_portdrv_restore_config(struct pci_dev *dev) 70static int pcie_portdrv_restore_config(struct pci_dev *dev)
@@ -95,7 +88,7 @@ static int pcie_port_resume_noirq(struct device *dev)
95 * which breaks ACPI-based runtime wakeup on PCI Express, so clear those 88 * which breaks ACPI-based runtime wakeup on PCI Express, so clear those
96 * bits now just in case (shouldn't hurt). 89 * bits now just in case (shouldn't hurt).
97 */ 90 */
98 if(pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) 91 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT)
99 pcie_clear_root_pme_status(pdev); 92 pcie_clear_root_pme_status(pdev);
100 return 0; 93 return 0;
101} 94}
@@ -186,9 +179,9 @@ static int __devinit pcie_portdrv_probe(struct pci_dev *dev,
186 int status; 179 int status;
187 180
188 if (!pci_is_pcie(dev) || 181 if (!pci_is_pcie(dev) ||
189 ((dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && 182 ((pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT) &&
190 (dev->pcie_type != PCI_EXP_TYPE_UPSTREAM) && 183 (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM) &&
191 (dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM))) 184 (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM)))
192 return -ENODEV; 185 return -ENODEV;
193 186
194 if (!dev->irq && dev->pin) { 187 if (!dev->irq && dev->pin) {
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6c143b4497ca..d8f513bdf95c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -603,10 +603,10 @@ static void pci_set_bus_speed(struct pci_bus *bus)
603 u32 linkcap; 603 u32 linkcap;
604 u16 linksta; 604 u16 linksta;
605 605
606 pci_read_config_dword(bridge, pos + PCI_EXP_LNKCAP, &linkcap); 606 pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap);
607 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf]; 607 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf];
608 608
609 pci_read_config_word(bridge, pos + PCI_EXP_LNKSTA, &linksta); 609 pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta);
610 pcie_update_link_speed(bus, linksta); 610 pcie_update_link_speed(bus, linksta);
611 } 611 }
612} 612}
@@ -929,24 +929,16 @@ void set_pcie_port_type(struct pci_dev *pdev)
929 pdev->is_pcie = 1; 929 pdev->is_pcie = 1;
930 pdev->pcie_cap = pos; 930 pdev->pcie_cap = pos;
931 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16); 931 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
932 pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4; 932 pdev->pcie_flags_reg = reg16;
933 pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16); 933 pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16);
934 pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; 934 pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD;
935} 935}
936 936
937void set_pcie_hotplug_bridge(struct pci_dev *pdev) 937void set_pcie_hotplug_bridge(struct pci_dev *pdev)
938{ 938{
939 int pos;
940 u16 reg16;
941 u32 reg32; 939 u32 reg32;
942 940
943 pos = pci_pcie_cap(pdev); 941 pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &reg32);
944 if (!pos)
945 return;
946 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
947 if (!(reg16 & PCI_EXP_FLAGS_SLOT))
948 return;
949 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &reg32);
950 if (reg32 & PCI_EXP_SLTCAP_HPC) 942 if (reg32 & PCI_EXP_SLTCAP_HPC)
951 pdev->is_hotplug_bridge = 1; 943 pdev->is_hotplug_bridge = 1;
952} 944}
@@ -1160,8 +1152,7 @@ int pci_cfg_space_size(struct pci_dev *dev)
1160 if (class == PCI_CLASS_BRIDGE_HOST) 1152 if (class == PCI_CLASS_BRIDGE_HOST)
1161 return pci_cfg_space_size_ext(dev); 1153 return pci_cfg_space_size_ext(dev);
1162 1154
1163 pos = pci_pcie_cap(dev); 1155 if (!pci_is_pcie(dev)) {
1164 if (!pos) {
1165 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); 1156 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
1166 if (!pos) 1157 if (!pos)
1167 goto fail; 1158 goto fail;
@@ -1383,9 +1374,9 @@ static int only_one_child(struct pci_bus *bus)
1383 1374
1384 if (!parent || !pci_is_pcie(parent)) 1375 if (!parent || !pci_is_pcie(parent))
1385 return 0; 1376 return 0;
1386 if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT) 1377 if (pci_pcie_type(parent) == PCI_EXP_TYPE_ROOT_PORT)
1387 return 1; 1378 return 1;
1388 if (parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM && 1379 if (pci_pcie_type(parent) == PCI_EXP_TYPE_DOWNSTREAM &&
1389 !pci_has_flag(PCI_SCAN_ALL_PCIE_DEVS)) 1380 !pci_has_flag(PCI_SCAN_ALL_PCIE_DEVS))
1390 return 1; 1381 return 1;
1391 return 0; 1382 return 0;
@@ -1462,7 +1453,7 @@ static int pcie_find_smpss(struct pci_dev *dev, void *data)
1462 */ 1453 */
1463 if (dev->is_hotplug_bridge && (!list_is_singular(&dev->bus->devices) || 1454 if (dev->is_hotplug_bridge && (!list_is_singular(&dev->bus->devices) ||
1464 (dev->bus->self && 1455 (dev->bus->self &&
1465 dev->bus->self->pcie_type != PCI_EXP_TYPE_ROOT_PORT))) 1456 pci_pcie_type(dev->bus->self) != PCI_EXP_TYPE_ROOT_PORT)))
1466 *smpss = 0; 1457 *smpss = 0;
1467 1458
1468 if (*smpss > dev->pcie_mpss) 1459 if (*smpss > dev->pcie_mpss)
@@ -1478,7 +1469,8 @@ static void pcie_write_mps(struct pci_dev *dev, int mps)
1478 if (pcie_bus_config == PCIE_BUS_PERFORMANCE) { 1469 if (pcie_bus_config == PCIE_BUS_PERFORMANCE) {
1479 mps = 128 << dev->pcie_mpss; 1470 mps = 128 << dev->pcie_mpss;
1480 1471
1481 if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && dev->bus->self) 1472 if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT &&
1473 dev->bus->self)
1482 /* For "Performance", the assumption is made that 1474 /* For "Performance", the assumption is made that
1483 * downstream communication will never be larger than 1475 * downstream communication will never be larger than
1484 * the MRRS. So, the MPS only needs to be configured 1476 * the MRRS. So, the MPS only needs to be configured
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 51553179e967..7a451ff56ecc 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3081,17 +3081,36 @@ static int reset_intel_generic_dev(struct pci_dev *dev, int probe)
3081 3081
3082static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) 3082static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)
3083{ 3083{
3084 int pos; 3084 int i;
3085 u16 status;
3085 3086
3086 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 3087 /*
3087 if (!pos) 3088 * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf
3088 return -ENOTTY; 3089 *
3090 * The 82599 supports FLR on VFs, but FLR support is reported only
3091 * in the PF DEVCAP (sec 9.3.10.4), not in the VF DEVCAP (sec 9.5).
3092 * Therefore, we can't use pcie_flr(), which checks the VF DEVCAP.
3093 */
3089 3094
3090 if (probe) 3095 if (probe)
3091 return 0; 3096 return 0;
3092 3097
3093 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, 3098 /* Wait for Transaction Pending bit clean */
3094 PCI_EXP_DEVCTL_BCR_FLR); 3099 for (i = 0; i < 4; i++) {
3100 if (i)
3101 msleep((1 << (i - 1)) * 100);
3102
3103 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
3104 if (!(status & PCI_EXP_DEVSTA_TRPND))
3105 goto clear;
3106 }
3107
3108 dev_err(&dev->dev, "transaction is not cleared; "
3109 "proceeding with reset anyway\n");
3110
3111clear:
3112 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3113
3095 msleep(100); 3114 msleep(100);
3096 3115
3097 return 0; 3116 return 0;
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 993d4a0a2469..621b162ceb69 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -41,7 +41,7 @@ pci_find_upstream_pcie_bridge(struct pci_dev *pdev)
41 continue; 41 continue;
42 } 42 }
43 /* PCI device should connect to a PCIe bridge */ 43 /* PCI device should connect to a PCIe bridge */
44 if (pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE) { 44 if (pci_pcie_type(pdev) != PCI_EXP_TYPE_PCI_BRIDGE) {
45 /* Busted hardware? */ 45 /* Busted hardware? */
46 WARN_ON_ONCE(1); 46 WARN_ON_ONCE(1);
47 return NULL; 47 return NULL;
diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
index 722246cf20ab..fc22b93e0924 100644
--- a/drivers/rapidio/devices/tsi721.c
+++ b/drivers/rapidio/devices/tsi721.c
@@ -2212,9 +2212,8 @@ static int __devinit tsi721_probe(struct pci_dev *pdev,
2212 const struct pci_device_id *id) 2212 const struct pci_device_id *id)
2213{ 2213{
2214 struct tsi721_device *priv; 2214 struct tsi721_device *priv;
2215 int i, cap; 2215 int i;
2216 int err; 2216 int err;
2217 u32 regval;
2218 2217
2219 priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL); 2218 priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL);
2220 if (priv == NULL) { 2219 if (priv == NULL) {
@@ -2320,20 +2319,16 @@ static int __devinit tsi721_probe(struct pci_dev *pdev,
2320 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n"); 2319 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2321 } 2320 }
2322 2321
2323 cap = pci_pcie_cap(pdev); 2322 BUG_ON(!pci_is_pcie(pdev));
2324 BUG_ON(cap == 0);
2325 2323
2326 /* Clear "no snoop" and "relaxed ordering" bits, use default MRRS. */ 2324 /* Clear "no snoop" and "relaxed ordering" bits, use default MRRS. */
2327 pci_read_config_dword(pdev, cap + PCI_EXP_DEVCTL, &regval); 2325 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
2328 regval &= ~(PCI_EXP_DEVCTL_READRQ | PCI_EXP_DEVCTL_RELAX_EN | 2326 PCI_EXP_DEVCTL_READRQ | PCI_EXP_DEVCTL_RELAX_EN |
2329 PCI_EXP_DEVCTL_NOSNOOP_EN); 2327 PCI_EXP_DEVCTL_NOSNOOP_EN,
2330 regval |= 0x2 << MAX_READ_REQUEST_SZ_SHIFT; 2328 0x2 << MAX_READ_REQUEST_SZ_SHIFT);
2331 pci_write_config_dword(pdev, cap + PCI_EXP_DEVCTL, regval);
2332 2329
2333 /* Adjust PCIe completion timeout. */ 2330 /* Adjust PCIe completion timeout. */
2334 pci_read_config_dword(pdev, cap + PCI_EXP_DEVCTL2, &regval); 2331 pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL2, 0xf, 0x2);
2335 regval &= ~(0x0f);
2336 pci_write_config_dword(pdev, cap + PCI_EXP_DEVCTL2, regval | 0x2);
2337 2332
2338 /* 2333 /*
2339 * FIXUP: correct offsets of MSI-X tables in the MSI-X Capability Block 2334 * FIXUP: correct offsets of MSI-X tables in the MSI-X Capability Block
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index 9ce3a8f8754f..7cfdf2bd8edb 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -1615,13 +1615,11 @@ qla82xx_get_fw_offs(struct qla_hw_data *ha)
1615char * 1615char *
1616qla82xx_pci_info_str(struct scsi_qla_host *vha, char *str) 1616qla82xx_pci_info_str(struct scsi_qla_host *vha, char *str)
1617{ 1617{
1618 int pcie_reg;
1619 struct qla_hw_data *ha = vha->hw; 1618 struct qla_hw_data *ha = vha->hw;
1620 char lwstr[6]; 1619 char lwstr[6];
1621 uint16_t lnk; 1620 uint16_t lnk;
1622 1621
1623 pcie_reg = pci_pcie_cap(ha->pdev); 1622 pcie_capability_read_word(ha->pdev, PCI_EXP_LNKSTA, &lnk);
1624 pci_read_config_word(ha->pdev, pcie_reg + PCI_EXP_LNKSTA, &lnk);
1625 ha->link_width = (lnk >> 4) & 0x3f; 1623 ha->link_width = (lnk >> 4) & 0x3f;
1626 1624
1627 strcpy(str, "PCIe ("); 1625 strcpy(str, "PCIe (");
@@ -2497,7 +2495,6 @@ fw_load_failed:
2497int 2495int
2498qla82xx_start_firmware(scsi_qla_host_t *vha) 2496qla82xx_start_firmware(scsi_qla_host_t *vha)
2499{ 2497{
2500 int pcie_cap;
2501 uint16_t lnk; 2498 uint16_t lnk;
2502 struct qla_hw_data *ha = vha->hw; 2499 struct qla_hw_data *ha = vha->hw;
2503 2500
@@ -2528,8 +2525,7 @@ qla82xx_start_firmware(scsi_qla_host_t *vha)
2528 } 2525 }
2529 2526
2530 /* Negotiated Link width */ 2527 /* Negotiated Link width */
2531 pcie_cap = pci_pcie_cap(ha->pdev); 2528 pcie_capability_read_word(ha->pdev, PCI_EXP_LNKSTA, &lnk);
2532 pci_read_config_word(ha->pdev, pcie_cap + PCI_EXP_LNKSTA, &lnk);
2533 ha->link_width = (lnk >> 4) & 0x3f; 2529 ha->link_width = (lnk >> 4) & 0x3f;
2534 2530
2535 /* Synchronize with Receive peg */ 2531 /* Synchronize with Receive peg */
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index 939d7261c37a..807bf76f1b6a 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -1566,7 +1566,6 @@ qla4_8xxx_set_qsnt_ready(struct scsi_qla_host *ha)
1566static int 1566static int
1567qla4_8xxx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start) 1567qla4_8xxx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start)
1568{ 1568{
1569 int pcie_cap;
1570 uint16_t lnk; 1569 uint16_t lnk;
1571 1570
1572 /* scrub dma mask expansion register */ 1571 /* scrub dma mask expansion register */
@@ -1590,8 +1589,7 @@ qla4_8xxx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start)
1590 } 1589 }
1591 1590
1592 /* Negotiated Link width */ 1591 /* Negotiated Link width */
1593 pcie_cap = pci_pcie_cap(ha->pdev); 1592 pcie_capability_read_word(ha->pdev, PCI_EXP_LNKSTA, &lnk);
1594 pci_read_config_word(ha->pdev, pcie_cap + PCI_EXP_LNKSTA, &lnk);
1595 ha->link_width = (lnk >> 4) & 0x3f; 1593 ha->link_width = (lnk >> 4) & 0x3f;
1596 1594
1597 /* Synchronize with Receive peg */ 1595 /* Synchronize with Receive peg */
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 029725c89e58..49553f88c7b3 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -3995,16 +3995,14 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter)
3995static int et131x_pci_init(struct et131x_adapter *adapter, 3995static int et131x_pci_init(struct et131x_adapter *adapter,
3996 struct pci_dev *pdev) 3996 struct pci_dev *pdev)
3997{ 3997{
3998 int cap = pci_pcie_cap(pdev);
3999 u16 max_payload; 3998 u16 max_payload;
4000 u16 ctl;
4001 int i, rc; 3999 int i, rc;
4002 4000
4003 rc = et131x_init_eeprom(adapter); 4001 rc = et131x_init_eeprom(adapter);
4004 if (rc < 0) 4002 if (rc < 0)
4005 goto out; 4003 goto out;
4006 4004
4007 if (!cap) { 4005 if (!pci_is_pcie(pdev)) {
4008 dev_err(&pdev->dev, "Missing PCIe capabilities\n"); 4006 dev_err(&pdev->dev, "Missing PCIe capabilities\n");
4009 goto err_out; 4007 goto err_out;
4010 } 4008 }
@@ -4012,7 +4010,7 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
4012 /* Let's set up the PORT LOGIC Register. First we need to know what 4010 /* Let's set up the PORT LOGIC Register. First we need to know what
4013 * the max_payload_size is 4011 * the max_payload_size is
4014 */ 4012 */
4015 if (pci_read_config_word(pdev, cap + PCI_EXP_DEVCAP, &max_payload)) { 4013 if (pcie_capability_read_word(pdev, PCI_EXP_DEVCAP, &max_payload)) {
4016 dev_err(&pdev->dev, 4014 dev_err(&pdev->dev,
4017 "Could not read PCI config space for Max Payload Size\n"); 4015 "Could not read PCI config space for Max Payload Size\n");
4018 goto err_out; 4016 goto err_out;
@@ -4049,17 +4047,10 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
4049 } 4047 }
4050 4048
4051 /* Change the max read size to 2k */ 4049 /* Change the max read size to 2k */
4052 if (pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl)) { 4050 if (pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL,
4051 PCI_EXP_DEVCTL_READRQ, 0x4 << 12)) {
4053 dev_err(&pdev->dev, 4052 dev_err(&pdev->dev,
4054 "Could not read PCI config space for Max read size\n"); 4053 "Couldn't change PCI config space for Max read size\n");
4055 goto err_out;
4056 }
4057
4058 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | (0x04 << 12);
4059
4060 if (pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl)) {
4061 dev_err(&pdev->dev,
4062 "Could not write PCI config space for Max read size\n");
4063 goto err_out; 4054 goto err_out;
4064 } 4055 }
4065 4056
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
index ddadcc3e4e7c..5abbee37cdca 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
@@ -31,12 +31,10 @@ static void rtl8192_parse_pci_configuration(struct pci_dev *pdev,
31 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 31 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
32 32
33 u8 tmp; 33 u8 tmp;
34 int pos; 34 u16 LinkCtrlReg;
35 u8 LinkCtrlReg;
36 35
37 pos = pci_find_capability(priv->pdev, PCI_CAP_ID_EXP); 36 pcie_capability_read_word(priv->pdev, PCI_EXP_LNKCTL, &LinkCtrlReg);
38 pci_read_config_byte(priv->pdev, pos + PCI_EXP_LNKCTL, &LinkCtrlReg); 37 priv->NdisAdapter.LinkCtrlReg = (u8)LinkCtrlReg;
39 priv->NdisAdapter.LinkCtrlReg = LinkCtrlReg;
40 38
41 RT_TRACE(COMP_INIT, "Link Control Register =%x\n", 39 RT_TRACE(COMP_INIT, "Link Control Register =%x\n",
42 priv->NdisAdapter.LinkCtrlReg); 40 priv->NdisAdapter.LinkCtrlReg);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 5faa8310eec9..b8667e0548e0 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -254,10 +254,10 @@ struct pci_dev {
254 u8 revision; /* PCI revision, low byte of class word */ 254 u8 revision; /* PCI revision, low byte of class word */
255 u8 hdr_type; /* PCI header type (`multi' flag masked out) */ 255 u8 hdr_type; /* PCI header type (`multi' flag masked out) */
256 u8 pcie_cap; /* PCI-E capability offset */ 256 u8 pcie_cap; /* PCI-E capability offset */
257 u8 pcie_type:4; /* PCI-E device/port type */
258 u8 pcie_mpss:3; /* PCI-E Max Payload Size Supported */ 257 u8 pcie_mpss:3; /* PCI-E Max Payload Size Supported */
259 u8 rom_base_reg; /* which config register controls the ROM */ 258 u8 rom_base_reg; /* which config register controls the ROM */
260 u8 pin; /* which interrupt pin this device uses */ 259 u8 pin; /* which interrupt pin this device uses */
260 u16 pcie_flags_reg; /* cached PCI-E Capabilities Register */
261 261
262 struct pci_driver *driver; /* which driver has allocated this device */ 262 struct pci_driver *driver; /* which driver has allocated this device */
263 u64 dma_mask; /* Mask of the bits of bus address this 263 u64 dma_mask; /* Mask of the bits of bus address this
@@ -816,6 +816,39 @@ static inline int pci_write_config_dword(const struct pci_dev *dev, int where,
816 return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val); 816 return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
817} 817}
818 818
819int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
820int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val);
821int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
822int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val);
823int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
824 u16 clear, u16 set);
825int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
826 u32 clear, u32 set);
827
828static inline int pcie_capability_set_word(struct pci_dev *dev, int pos,
829 u16 set)
830{
831 return pcie_capability_clear_and_set_word(dev, pos, 0, set);
832}
833
834static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos,
835 u32 set)
836{
837 return pcie_capability_clear_and_set_dword(dev, pos, 0, set);
838}
839
840static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
841 u16 clear)
842{
843 return pcie_capability_clear_and_set_word(dev, pos, clear, 0);
844}
845
846static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
847 u32 clear)
848{
849 return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
850}
851
819/* user-space driven config access */ 852/* user-space driven config access */
820int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 853int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
821int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val); 854int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
@@ -1650,6 +1683,15 @@ static inline bool pci_is_pcie(struct pci_dev *dev)
1650 return !!pci_pcie_cap(dev); 1683 return !!pci_pcie_cap(dev);
1651} 1684}
1652 1685
1686/**
1687 * pci_pcie_type - get the PCIe device/port type
1688 * @dev: PCI device
1689 */
1690static inline int pci_pcie_type(const struct pci_dev *dev)
1691{
1692 return (dev->pcie_flags_reg & PCI_EXP_FLAGS_TYPE) >> 4;
1693}
1694
1653void pci_request_acs(void); 1695void pci_request_acs(void);
1654bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags); 1696bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
1655bool pci_acs_path_enabled(struct pci_dev *start, 1697bool pci_acs_path_enabled(struct pci_dev *start,
diff --git a/include/linux/pci_regs.h b/include/linux/pci_regs.h
index 7fb75b143755..3958f70f3202 100644
--- a/include/linux/pci_regs.h
+++ b/include/linux/pci_regs.h
@@ -549,6 +549,7 @@
549#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x04 /* Current Link Speed 8.0GT/s */ 549#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x04 /* Current Link Speed 8.0GT/s */
550#define PCI_EXP_LNKCAP2_CROSSLINK 0x100 /* Crosslink supported */ 550#define PCI_EXP_LNKCAP2_CROSSLINK 0x100 /* Crosslink supported */
551#define PCI_EXP_LNKCTL2 48 /* Link Control 2 */ 551#define PCI_EXP_LNKCTL2 48 /* Link Control 2 */
552#define PCI_EXP_LNKSTA2 50 /* Link Status 2 */
552#define PCI_EXP_SLTCTL2 56 /* Slot Control 2 */ 553#define PCI_EXP_SLTCTL2 56 /* Slot Control 2 */
553 554
554/* Extended Capabilities (PCI-X 2.0 and Express) */ 555/* Extended Capabilities (PCI-X 2.0 and Express) */