aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt32
-rw-r--r--arch/arm/mach-tegra/pcie.c12
-rw-r--r--arch/frv/mb93090-mb00/pci-vdk.c4
-rw-r--r--arch/mips/pci/pci-octeon.c15
-rw-r--r--arch/powerpc/include/asm/machdep.h3
-rw-r--r--arch/powerpc/kernel/pci-common.c20
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c41
-rw-r--r--arch/tile/kernel/pci.c26
-rw-r--r--drivers/char/agp/sgi-agp.c5
-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/parisc/dino.c10
-rw-r--r--drivers/parisc/lba_pci.c7
-rw-r--r--drivers/pci/access.c202
-rw-r--r--drivers/pci/hotplug/Kconfig24
-rw-r--r--drivers/pci/hotplug/Makefile3
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c46
-rw-r--r--drivers/pci/hotplug/fakephp.c164
-rw-r--r--drivers/pci/hotplug/pciehp_acpi.c6
-rw-r--r--drivers/pci/hotplug/pciehp_core.c28
-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.c356
-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.c34
-rw-r--r--drivers/pci/pcie/portdrv_pci.c17
-rw-r--r--drivers/pci/probe.c28
-rw-r--r--drivers/pci/proc.c19
-rw-r--r--drivers/pci/quirks.c31
-rw-r--r--drivers/pci/remove.c131
-rw-r--r--drivers/pci/rom.c59
-rw-r--r--drivers/pci/search.c63
-rw-r--r--drivers/pci/setup-bus.c81
-rw-r--r--drivers/pcmcia/cardbus.c15
-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.h51
-rw-r--r--include/linux/pci_regs.h7
69 files changed, 841 insertions, 1392 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index afaff312bf41..529e8323ca82 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -253,38 +253,6 @@ Who: Dave Jones <davej@redhat.com>, Matthew Garrett <mjg@redhat.com>
253 253
254----------------------------- 254-----------------------------
255 255
256What: fakephp and associated sysfs files in /sys/bus/pci/slots/
257When: 2011
258Why: In 2.6.27, the semantics of /sys/bus/pci/slots was redefined to
259 represent a machine's physical PCI slots. The change in semantics
260 had userspace implications, as the hotplug core no longer allowed
261 drivers to create multiple sysfs files per physical slot (required
262 for multi-function devices, e.g.). fakephp was seen as a developer's
263 tool only, and its interface changed. Too late, we learned that
264 there were some users of the fakephp interface.
265
266 In 2.6.30, the original fakephp interface was restored. At the same
267 time, the PCI core gained the ability that fakephp provided, namely
268 function-level hot-remove and hot-add.
269
270 Since the PCI core now provides the same functionality, exposed in:
271
272 /sys/bus/pci/rescan
273 /sys/bus/pci/devices/.../remove
274 /sys/bus/pci/devices/.../rescan
275
276 there is no functional reason to maintain fakephp as well.
277
278 We will keep the existing module so that 'modprobe fakephp' will
279 present the old /sys/bus/pci/slots/... interface for compatibility,
280 but users are urged to migrate their applications to the API above.
281
282 After a reasonable transition period, we will remove the legacy
283 fakephp interface.
284Who: Alex Chiang <achiang@hp.com>
285
286---------------------------
287
288What: CONFIG_RFKILL_INPUT 256What: CONFIG_RFKILL_INPUT
289When: 2.6.33 257When: 2.6.33
290Why: Should be implemented in userspace, policy daemon. 258Why: Should be implemented in userspace, policy daemon.
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/frv/mb93090-mb00/pci-vdk.c b/arch/frv/mb93090-mb00/pci-vdk.c
index d04ed14bbf0c..71e9bcf58105 100644
--- a/arch/frv/mb93090-mb00/pci-vdk.c
+++ b/arch/frv/mb93090-mb00/pci-vdk.c
@@ -330,10 +330,8 @@ void __init pcibios_fixup_bus(struct pci_bus *bus)
330 pci_read_bridge_bases(bus); 330 pci_read_bridge_bases(bus);
331 331
332 if (bus->number == 0) { 332 if (bus->number == 0) {
333 struct list_head *ln;
334 struct pci_dev *dev; 333 struct pci_dev *dev;
335 for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) { 334 list_for_each_entry(dev, &bus->devices, bus_list) {
336 dev = pci_dev_b(ln);
337 if (dev->devfn == 0) { 335 if (dev->devfn == 0) {
338 dev->resource[0].start = 0; 336 dev->resource[0].start = 0;
339 dev->resource[0].end = 0; 337 dev->resource[0].end = 0;
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/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h
index 42ce570812c1..f7706d722b39 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -214,6 +214,9 @@ struct machdep_calls {
214 /* Called after scan and before resource survey */ 214 /* Called after scan and before resource survey */
215 void (*pcibios_fixup_phb)(struct pci_controller *hose); 215 void (*pcibios_fixup_phb)(struct pci_controller *hose);
216 216
217 /* Called during PCI resource reassignment */
218 resource_size_t (*pcibios_window_alignment)(struct pci_bus *, unsigned long type);
219
217 /* Called to shutdown machine specific hardware not already controlled 220 /* Called to shutdown machine specific hardware not already controlled
218 * by other drivers. 221 * by other drivers.
219 */ 222 */
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 2aa04f29e1de..43fea543d686 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -99,6 +99,26 @@ void pcibios_free_controller(struct pci_controller *phb)
99 kfree(phb); 99 kfree(phb);
100} 100}
101 101
102/*
103 * The function is used to return the minimal alignment
104 * for memory or I/O windows of the associated P2P bridge.
105 * By default, 4KiB alignment for I/O windows and 1MiB for
106 * memory windows.
107 */
108resource_size_t pcibios_window_alignment(struct pci_bus *bus,
109 unsigned long type)
110{
111 if (ppc_md.pcibios_window_alignment)
112 return ppc_md.pcibios_window_alignment(bus, type);
113
114 /*
115 * PCI core will figure out the default
116 * alignment: 4KiB for I/O and 1MiB for
117 * memory window.
118 */
119 return 1;
120}
121
102static resource_size_t pcibios_io_size(const struct pci_controller *hose) 122static resource_size_t pcibios_io_size(const struct pci_controller *hose)
103{ 123{
104#ifdef CONFIG_PPC64 124#ifdef CONFIG_PPC64
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 9cda6a1ad0cf..0e7eccc0f88d 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);
@@ -1139,6 +1139,44 @@ static void __devinit pnv_pci_ioda_fixup_phb(struct pci_controller *hose)
1139 } 1139 }
1140} 1140}
1141 1141
1142/*
1143 * Returns the alignment for I/O or memory windows for P2P
1144 * bridges. That actually depends on how PEs are segmented.
1145 * For now, we return I/O or M32 segment size for PE sensitive
1146 * P2P bridges. Otherwise, the default values (4KiB for I/O,
1147 * 1MiB for memory) will be returned.
1148 *
1149 * The current PCI bus might be put into one PE, which was
1150 * create against the parent PCI bridge. For that case, we
1151 * needn't enlarge the alignment so that we can save some
1152 * resources.
1153 */
1154static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
1155 unsigned long type)
1156{
1157 struct pci_dev *bridge;
1158 struct pci_controller *hose = pci_bus_to_host(bus);
1159 struct pnv_phb *phb = hose->private_data;
1160 int num_pci_bridges = 0;
1161
1162 bridge = bus->self;
1163 while (bridge) {
1164 if (pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE) {
1165 num_pci_bridges++;
1166 if (num_pci_bridges >= 2)
1167 return 1;
1168 }
1169
1170 bridge = bridge->bus->self;
1171 }
1172
1173 /* We need support prefetchable memory window later */
1174 if (type & IORESOURCE_MEM)
1175 return phb->ioda.m32_segsize;
1176
1177 return phb->ioda.io_segsize;
1178}
1179
1142/* Prevent enabling devices for which we couldn't properly 1180/* Prevent enabling devices for which we couldn't properly
1143 * assign a PE 1181 * assign a PE
1144 */ 1182 */
@@ -1306,6 +1344,7 @@ void __init pnv_pci_init_ioda1_phb(struct device_node *np)
1306 */ 1344 */
1307 ppc_md.pcibios_fixup_phb = pnv_pci_ioda_fixup_phb; 1345 ppc_md.pcibios_fixup_phb = pnv_pci_ioda_fixup_phb;
1308 ppc_md.pcibios_enable_device_hook = pnv_pci_enable_device_hook; 1346 ppc_md.pcibios_enable_device_hook = pnv_pci_enable_device_hook;
1347 ppc_md.pcibios_window_alignment = pnv_pci_window_alignment;
1309 pci_add_flags(PCI_PROBE_ONLY | PCI_REASSIGN_ALL_RSRC); 1348 pci_add_flags(PCI_PROBE_ONLY | PCI_REASSIGN_ALL_RSRC);
1310 1349
1311 /* Reset IODA tables to a clean state */ 1350 /* Reset IODA tables to a clean state */
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/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 192000377737..3a5af2f9b015 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -289,12 +289,11 @@ static int __devinit agp_sgi_init(void)
289 289
290 j = 0; 290 j = 0;
291 list_for_each_entry(info, &tioca_list, ca_list) { 291 list_for_each_entry(info, &tioca_list, ca_list) {
292 struct list_head *tmp;
293 if (list_empty(info->ca_devices)) 292 if (list_empty(info->ca_devices))
294 continue; 293 continue;
295 list_for_each(tmp, info->ca_devices) { 294 list_for_each_entry(pdev, info->ca_devices, bus_list) {
296 u8 cap_ptr; 295 u8 cap_ptr;
297 pdev = pci_dev_b(tmp); 296
298 if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8)) 297 if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
299 continue; 298 continue;
300 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); 299 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
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 8fd03a8c7354..c574ec7c85e6 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 64c8c2eb05b5..55a2e3795055 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 81e377408a4e..3de20c83c722 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 5639b5c85c54..388d32213937 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 05bdbbbf145c..933985420acb 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 1c650ecae88d..26a2ba2f8986 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 25270648517b..083ca330a336 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 ade4d81a3177..ee61819d6088 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 0fa18ae07de5..fdc5ca0f7b64 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/parisc/dino.c b/drivers/parisc/dino.c
index ffddc4f64268..fb6a1fe21b93 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -477,14 +477,12 @@ dino_card_setup(struct pci_bus *bus, void __iomem *base_addr)
477 if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB, 477 if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB,
478 F_EXTEND(0xf0000000UL) | _8MB, 478 F_EXTEND(0xf0000000UL) | _8MB,
479 F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) { 479 F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) {
480 struct list_head *ln, *tmp_ln; 480 struct pci_dev *dev, *tmp;
481 481
482 printk(KERN_ERR "Dino: cannot attach bus %s\n", 482 printk(KERN_ERR "Dino: cannot attach bus %s\n",
483 dev_name(bus->bridge)); 483 dev_name(bus->bridge));
484 /* kill the bus, we can't do anything with it */ 484 /* kill the bus, we can't do anything with it */
485 list_for_each_safe(ln, tmp_ln, &bus->devices) { 485 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
486 struct pci_dev *dev = pci_dev_b(ln);
487
488 list_del(&dev->bus_list); 486 list_del(&dev->bus_list);
489 } 487 }
490 488
@@ -549,7 +547,6 @@ dino_card_fixup(struct pci_dev *dev)
549static void __init 547static void __init
550dino_fixup_bus(struct pci_bus *bus) 548dino_fixup_bus(struct pci_bus *bus)
551{ 549{
552 struct list_head *ln;
553 struct pci_dev *dev; 550 struct pci_dev *dev;
554 struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge)); 551 struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
555 552
@@ -596,8 +593,7 @@ dino_fixup_bus(struct pci_bus *bus)
596 } 593 }
597 594
598 595
599 list_for_each(ln, &bus->devices) { 596 list_for_each_entry(dev, &bus->devices, bus_list) {
600 dev = pci_dev_b(ln);
601 if (is_card_dino(&dino_dev->hba.dev->id)) 597 if (is_card_dino(&dino_dev->hba.dev->id))
602 dino_card_fixup(dev); 598 dino_card_fixup(dev);
603 599
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 4f9cf2456f4e..fdd63a6a62d6 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -629,7 +629,7 @@ truncate_pat_collision(struct resource *root, struct resource *new)
629static void 629static void
630lba_fixup_bus(struct pci_bus *bus) 630lba_fixup_bus(struct pci_bus *bus)
631{ 631{
632 struct list_head *ln; 632 struct pci_dev *dev;
633#ifdef FBB_SUPPORT 633#ifdef FBB_SUPPORT
634 u16 status; 634 u16 status;
635#endif 635#endif
@@ -710,9 +710,8 @@ lba_fixup_bus(struct pci_bus *bus)
710 710
711 } 711 }
712 712
713 list_for_each(ln, &bus->devices) { 713 list_for_each_entry(dev, &bus->devices, bus_list) {
714 int i; 714 int i;
715 struct pci_dev *dev = pci_dev_b(ln);
716 715
717 DBG("lba_fixup_bus() %s\n", pci_name(dev)); 716 DBG("lba_fixup_bus() %s\n", pci_name(dev));
718 717
@@ -770,7 +769,7 @@ lba_fixup_bus(struct pci_bus *bus)
770 } 769 }
771 770
772 /* Lastly enable FBB/PERR/SERR on all devices too */ 771 /* Lastly enable FBB/PERR/SERR on all devices too */
773 list_for_each(ln, &bus->devices) { 772 list_for_each_entry(dev, &bus->devices, bus_list) {
774 (void) pci_read_config_word(dev, PCI_COMMAND, &status); 773 (void) pci_read_config_word(dev, PCI_COMMAND, &status);
775 status |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR | fbb_enable; 774 status |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR | fbb_enable;
776 (void) pci_write_config_word(dev, PCI_COMMAND, status); 775 (void) pci_write_config_word(dev, PCI_COMMAND, status);
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/Kconfig b/drivers/pci/hotplug/Kconfig
index 66f29bc00be4..b0e46dede1a9 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -17,28 +17,6 @@ menuconfig HOTPLUG_PCI
17 17
18if HOTPLUG_PCI 18if HOTPLUG_PCI
19 19
20config HOTPLUG_PCI_FAKE
21 tristate "Fake PCI Hotplug driver"
22 help
23 Say Y here if you want to use the fake PCI hotplug driver. It can
24 be used to simulate PCI hotplug events if even if your system is
25 not PCI hotplug capable.
26
27 This driver will "emulate" removing PCI devices from the system.
28 If the "power" file is written to with "0" then the specified PCI
29 device will be completely removed from the kernel.
30
31 WARNING, this does NOT turn off the power to the PCI device.
32 This is a "logical" removal, not a physical or electrical
33 removal.
34
35 Use this module at your own risk. You have been warned!
36
37 To compile this driver as a module, choose M here: the
38 module will be called fakephp.
39
40 When in doubt, say N.
41
42config HOTPLUG_PCI_COMPAQ 20config HOTPLUG_PCI_COMPAQ
43 tristate "Compaq PCI Hotplug driver" 21 tristate "Compaq PCI Hotplug driver"
44 depends on X86 && PCI_BIOS 22 depends on X86 && PCI_BIOS
@@ -143,7 +121,7 @@ config HOTPLUG_PCI_SHPC
143 121
144config HOTPLUG_PCI_RPA 122config HOTPLUG_PCI_RPA
145 tristate "RPA PCI Hotplug driver" 123 tristate "RPA PCI Hotplug driver"
146 depends on PPC_PSERIES && EEH && !HOTPLUG_PCI_FAKE 124 depends on PPC_PSERIES && EEH
147 help 125 help
148 Say Y here if you have a RPA system that supports PCI Hotplug. 126 Say Y here if you have a RPA system that supports PCI Hotplug.
149 127
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 6cd9f3c9887d..c459cd4e39c2 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -23,9 +23,6 @@ obj-$(CONFIG_HOTPLUG_PCI_ACPI) += acpiphp.o
23 23
24obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM) += acpiphp_ibm.o 24obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM) += acpiphp_ibm.o
25 25
26# Link this last so it doesn't claim devices that have a real hotplug driver
27obj-$(CONFIG_HOTPLUG_PCI_FAKE) += fakephp.o
28
29pci_hotplug-objs := pci_hotplug_core.o pcihp_slot.o 26pci_hotplug-objs := pci_hotplug_core.o pcihp_slot.o
30 27
31ifdef CONFIG_HOTPLUG_PCI_CPCI 28ifdef CONFIG_HOTPLUG_PCI_CPCI
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index ad6fd6695495..7be4ca5e1f4c 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -869,17 +869,6 @@ static int __ref enable_device(struct acpiphp_slot *slot)
869 return retval; 869 return retval;
870} 870}
871 871
872static void disable_bridges(struct pci_bus *bus)
873{
874 struct pci_dev *dev;
875 list_for_each_entry(dev, &bus->devices, bus_list) {
876 if (dev->subordinate) {
877 disable_bridges(dev->subordinate);
878 pci_disable_device(dev);
879 }
880 }
881}
882
883/* return first device in slot, acquiring a reference on it */ 872/* return first device in slot, acquiring a reference on it */
884static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot) 873static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
885{ 874{
@@ -931,12 +920,7 @@ static int disable_device(struct acpiphp_slot *slot)
931 * here. 920 * here.
932 */ 921 */
933 while ((pdev = dev_in_slot(slot))) { 922 while ((pdev = dev_in_slot(slot))) {
934 pci_stop_bus_device(pdev); 923 pci_stop_and_remove_bus_device(pdev);
935 if (pdev->subordinate) {
936 disable_bridges(pdev->subordinate);
937 pci_disable_device(pdev);
938 }
939 __pci_remove_bus_device(pdev);
940 pci_dev_put(pdev); 924 pci_dev_put(pdev);
941 } 925 }
942 926
@@ -1477,34 +1461,6 @@ int __init acpiphp_get_num_slots(void)
1477} 1461}
1478 1462
1479 1463
1480#if 0
1481/**
1482 * acpiphp_for_each_slot - call function for each slot
1483 * @fn: callback function
1484 * @data: context to be passed to callback function
1485 */
1486static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1487{
1488 struct list_head *node;
1489 struct acpiphp_bridge *bridge;
1490 struct acpiphp_slot *slot;
1491 int retval = 0;
1492
1493 list_for_each (node, &bridge_list) {
1494 bridge = (struct acpiphp_bridge *)node;
1495 for (slot = bridge->slots; slot; slot = slot->next) {
1496 retval = fn(slot, data);
1497 if (!retval)
1498 goto err_exit;
1499 }
1500 }
1501
1502 err_exit:
1503 return retval;
1504}
1505#endif
1506
1507
1508/** 1464/**
1509 * acpiphp_enable_slot - power on slot 1465 * acpiphp_enable_slot - power on slot
1510 * @slot: ACPI PHP slot 1466 * @slot: ACPI PHP slot
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
deleted file mode 100644
index a019c9a712be..000000000000
--- a/drivers/pci/hotplug/fakephp.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/* Works like the fakephp driver used to, except a little better.
2 *
3 * - It's possible to remove devices with subordinate busses.
4 * - New PCI devices that appear via any method, not just a fakephp triggered
5 * rescan, will be noticed.
6 * - Devices that are removed via any method, not just a fakephp triggered
7 * removal, will also be noticed.
8 *
9 * Uses nothing from the pci-hotplug subsystem.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/types.h>
16#include <linux/list.h>
17#include <linux/kobject.h>
18#include <linux/sysfs.h>
19#include <linux/init.h>
20#include <linux/pci.h>
21#include <linux/device.h>
22#include <linux/slab.h>
23#include "../pci.h"
24
25struct legacy_slot {
26 struct kobject kobj;
27 struct pci_dev *dev;
28 struct list_head list;
29};
30
31static LIST_HEAD(legacy_list);
32
33static ssize_t legacy_show(struct kobject *kobj, struct attribute *attr,
34 char *buf)
35{
36 struct legacy_slot *slot = container_of(kobj, typeof(*slot), kobj);
37 strcpy(buf, "1\n");
38 return 2;
39}
40
41static void remove_callback(void *data)
42{
43 pci_stop_and_remove_bus_device((struct pci_dev *)data);
44}
45
46static ssize_t legacy_store(struct kobject *kobj, struct attribute *attr,
47 const char *buf, size_t len)
48{
49 struct legacy_slot *slot = container_of(kobj, typeof(*slot), kobj);
50 unsigned long val;
51
52 if (strict_strtoul(buf, 0, &val) < 0)
53 return -EINVAL;
54
55 if (val)
56 pci_rescan_bus(slot->dev->bus);
57 else
58 sysfs_schedule_callback(&slot->dev->dev.kobj, remove_callback,
59 slot->dev, THIS_MODULE);
60 return len;
61}
62
63static struct attribute *legacy_attrs[] = {
64 &(struct attribute){ .name = "power", .mode = 0644 },
65 NULL,
66};
67
68static void legacy_release(struct kobject *kobj)
69{
70 struct legacy_slot *slot = container_of(kobj, typeof(*slot), kobj);
71
72 pci_dev_put(slot->dev);
73 kfree(slot);
74}
75
76static struct kobj_type legacy_ktype = {
77 .sysfs_ops = &(const struct sysfs_ops){
78 .store = legacy_store, .show = legacy_show
79 },
80 .release = &legacy_release,
81 .default_attrs = legacy_attrs,
82};
83
84static int legacy_add_slot(struct pci_dev *pdev)
85{
86 struct legacy_slot *slot = kzalloc(sizeof(*slot), GFP_KERNEL);
87
88 if (!slot)
89 return -ENOMEM;
90
91 if (kobject_init_and_add(&slot->kobj, &legacy_ktype,
92 &pci_slots_kset->kobj, "%s",
93 dev_name(&pdev->dev))) {
94 dev_warn(&pdev->dev, "Failed to created legacy fake slot\n");
95 return -EINVAL;
96 }
97 slot->dev = pci_dev_get(pdev);
98
99 list_add(&slot->list, &legacy_list);
100
101 return 0;
102}
103
104static int legacy_notify(struct notifier_block *nb,
105 unsigned long action, void *data)
106{
107 struct pci_dev *pdev = to_pci_dev(data);
108
109 if (action == BUS_NOTIFY_ADD_DEVICE) {
110 legacy_add_slot(pdev);
111 } else if (action == BUS_NOTIFY_DEL_DEVICE) {
112 struct legacy_slot *slot;
113
114 list_for_each_entry(slot, &legacy_list, list)
115 if (slot->dev == pdev)
116 goto found;
117
118 dev_warn(&pdev->dev, "Missing legacy fake slot?");
119 return -ENODEV;
120found:
121 kobject_del(&slot->kobj);
122 list_del(&slot->list);
123 kobject_put(&slot->kobj);
124 }
125
126 return 0;
127}
128
129static struct notifier_block legacy_notifier = {
130 .notifier_call = legacy_notify
131};
132
133static int __init init_legacy(void)
134{
135 struct pci_dev *pdev = NULL;
136
137 /* Add existing devices */
138 for_each_pci_dev(pdev)
139 legacy_add_slot(pdev);
140
141 /* Be alerted of any new ones */
142 bus_register_notifier(&pci_bus_type, &legacy_notifier);
143 return 0;
144}
145module_init(init_legacy);
146
147static void __exit remove_legacy(void)
148{
149 struct legacy_slot *slot, *tmp;
150
151 bus_unregister_notifier(&pci_bus_type, &legacy_notifier);
152
153 list_for_each_entry_safe(slot, tmp, &legacy_list, list) {
154 list_del(&slot->list);
155 kobject_del(&slot->kobj);
156 kobject_put(&slot->kobj);
157 }
158}
159module_exit(remove_legacy);
160
161
162MODULE_AUTHOR("Trent Piepho <xyzzy@speakeasy.org>");
163MODULE_DESCRIPTION("Legacy version of the fakephp interface");
164MODULE_LICENSE("GPL");
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_core.c b/drivers/pci/hotplug/pciehp_core.c
index 365c6b96c642..916bf4f53aba 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -300,24 +300,24 @@ static int pciehp_suspend (struct pcie_device *dev)
300 300
301static int pciehp_resume (struct pcie_device *dev) 301static int pciehp_resume (struct pcie_device *dev)
302{ 302{
303 struct controller *ctrl;
304 struct slot *slot;
305 u8 status;
306
303 dev_info(&dev->device, "%s ENTRY\n", __func__); 307 dev_info(&dev->device, "%s ENTRY\n", __func__);
304 if (pciehp_force) { 308 ctrl = get_service_data(dev);
305 struct controller *ctrl = get_service_data(dev);
306 struct slot *slot;
307 u8 status;
308 309
309 /* reinitialize the chipset's event detection logic */ 310 /* reinitialize the chipset's event detection logic */
310 pcie_enable_notification(ctrl); 311 pcie_enable_notification(ctrl);
311 312
312 slot = ctrl->slot; 313 slot = ctrl->slot;
313 314
314 /* Check if slot is occupied */ 315 /* Check if slot is occupied */
315 pciehp_get_adapter_status(slot, &status); 316 pciehp_get_adapter_status(slot, &status);
316 if (status) 317 if (status)
317 pciehp_enable_slot(slot); 318 pciehp_enable_slot(slot);
318 else 319 else
319 pciehp_disable_slot(slot); 320 pciehp_disable_slot(slot);
320 }
321 return 0; 321 return 0;
322} 322}
323#endif /* PM */ 323#endif /* PM */
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..5ba60dd71faa 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -254,52 +254,17 @@ 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 257 * pci_find_next_ext_capability - Find an extended capability
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
290 * @dev: PCI device to query 258 * @dev: PCI device to query
259 * @start: address at which to start looking (0 to start at beginning of list)
291 * @cap: capability code 260 * @cap: capability code
292 * 261 *
293 * Returns the address of the requested extended capability structure 262 * Returns the address of the next matching extended capability structure
294 * within the device's PCI configuration space or 0 if the device does 263 * within the device's PCI configuration space or 0 if the device does
295 * not support it. Possible values for @cap: 264 * not support it. Some capabilities can occur several times, e.g., the
296 * 265 * vendor-specific capability, and this provides a way to find them all.
297 * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
298 * %PCI_EXT_CAP_ID_VC Virtual Channel
299 * %PCI_EXT_CAP_ID_DSN Device Serial Number
300 * %PCI_EXT_CAP_ID_PWR Power Budgeting
301 */ 266 */
302int pci_find_ext_capability(struct pci_dev *dev, int cap) 267int pci_find_next_ext_capability(struct pci_dev *dev, int start, int cap)
303{ 268{
304 u32 header; 269 u32 header;
305 int ttl; 270 int ttl;
@@ -311,6 +276,9 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
311 if (dev->cfg_size <= PCI_CFG_SPACE_SIZE) 276 if (dev->cfg_size <= PCI_CFG_SPACE_SIZE)
312 return 0; 277 return 0;
313 278
279 if (start)
280 pos = start;
281
314 if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL) 282 if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
315 return 0; 283 return 0;
316 284
@@ -322,7 +290,7 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
322 return 0; 290 return 0;
323 291
324 while (ttl-- > 0) { 292 while (ttl-- > 0) {
325 if (PCI_EXT_CAP_ID(header) == cap) 293 if (PCI_EXT_CAP_ID(header) == cap && pos != start)
326 return pos; 294 return pos;
327 295
328 pos = PCI_EXT_CAP_NEXT(header); 296 pos = PCI_EXT_CAP_NEXT(header);
@@ -335,6 +303,26 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
335 303
336 return 0; 304 return 0;
337} 305}
306EXPORT_SYMBOL_GPL(pci_find_next_ext_capability);
307
308/**
309 * pci_find_ext_capability - Find an extended capability
310 * @dev: PCI device to query
311 * @cap: capability code
312 *
313 * Returns the address of the requested extended capability structure
314 * within the device's PCI configuration space or 0 if the device does
315 * not support it. Possible values for @cap:
316 *
317 * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
318 * %PCI_EXT_CAP_ID_VC Virtual Channel
319 * %PCI_EXT_CAP_ID_DSN Device Serial Number
320 * %PCI_EXT_CAP_ID_PWR Power Budgeting
321 */
322int pci_find_ext_capability(struct pci_dev *dev, int cap)
323{
324 return pci_find_next_ext_capability(dev, 0, cap);
325}
338EXPORT_SYMBOL_GPL(pci_find_ext_capability); 326EXPORT_SYMBOL_GPL(pci_find_ext_capability);
339 327
340static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap) 328static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
@@ -854,21 +842,6 @@ EXPORT_SYMBOL(pci_choose_state);
854 842
855#define PCI_EXP_SAVE_REGS 7 843#define PCI_EXP_SAVE_REGS 7
856 844
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 845
873static struct pci_cap_saved_state *pci_find_saved_cap( 846static struct pci_cap_saved_state *pci_find_saved_cap(
874 struct pci_dev *pci_dev, char cap) 847 struct pci_dev *pci_dev, char cap)
@@ -885,13 +858,11 @@ static struct pci_cap_saved_state *pci_find_saved_cap(
885 858
886static int pci_save_pcie_state(struct pci_dev *dev) 859static int pci_save_pcie_state(struct pci_dev *dev)
887{ 860{
888 int pos, i = 0; 861 int i = 0;
889 struct pci_cap_saved_state *save_state; 862 struct pci_cap_saved_state *save_state;
890 u16 *cap; 863 u16 *cap;
891 u16 flags;
892 864
893 pos = pci_pcie_cap(dev); 865 if (!pci_is_pcie(dev))
894 if (!pos)
895 return 0; 866 return 0;
896 867
897 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 868 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
@@ -899,60 +870,37 @@ static int pci_save_pcie_state(struct pci_dev *dev)
899 dev_err(&dev->dev, "buffer not found in %s\n", __func__); 870 dev_err(&dev->dev, "buffer not found in %s\n", __func__);
900 return -ENOMEM; 871 return -ENOMEM;
901 } 872 }
902 cap = (u16 *)&save_state->cap.data[0];
903
904 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
905 873
906 if (pcie_cap_has_devctl(dev->pcie_type, flags)) 874 cap = (u16 *)&save_state->cap.data[0];
907 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]); 875 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &cap[i++]);
908 if (pcie_cap_has_lnkctl(dev->pcie_type, flags)) 876 pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &cap[i++]);
909 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]); 877 pcie_capability_read_word(dev, PCI_EXP_SLTCTL, &cap[i++]);
910 if (pcie_cap_has_sltctl(dev->pcie_type, flags)) 878 pcie_capability_read_word(dev, PCI_EXP_RTCTL, &cap[i++]);
911 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); 879 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &cap[i++]);
912 if (pcie_cap_has_rtctl(dev->pcie_type, flags)) 880 pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &cap[i++]);
913 pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); 881 pcie_capability_read_word(dev, PCI_EXP_SLTCTL2, &cap[i++]);
914
915 pos = pci_pcie_cap2(dev);
916 if (!pos)
917 return 0;
918 882
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; 883 return 0;
923} 884}
924 885
925static void pci_restore_pcie_state(struct pci_dev *dev) 886static void pci_restore_pcie_state(struct pci_dev *dev)
926{ 887{
927 int i = 0, pos; 888 int i = 0;
928 struct pci_cap_saved_state *save_state; 889 struct pci_cap_saved_state *save_state;
929 u16 *cap; 890 u16 *cap;
930 u16 flags;
931 891
932 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 892 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
933 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 893 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; 894 return;
952 895
953 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); 896 cap = (u16 *)&save_state->cap.data[0];
954 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); 897 pcie_capability_write_word(dev, PCI_EXP_DEVCTL, cap[i++]);
955 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); 898 pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++]);
899 pcie_capability_write_word(dev, PCI_EXP_SLTCTL, cap[i++]);
900 pcie_capability_write_word(dev, PCI_EXP_RTCTL, cap[i++]);
901 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, cap[i++]);
902 pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, cap[i++]);
903 pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
956} 904}
957 905
958 906
@@ -2066,35 +2014,24 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
2066 */ 2014 */
2067void pci_enable_ari(struct pci_dev *dev) 2015void pci_enable_ari(struct pci_dev *dev)
2068{ 2016{
2069 int pos;
2070 u32 cap; 2017 u32 cap;
2071 u16 ctrl;
2072 struct pci_dev *bridge; 2018 struct pci_dev *bridge;
2073 2019
2074 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) 2020 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn)
2075 return; 2021 return;
2076 2022
2077 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 2023 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI))
2078 if (!pos)
2079 return; 2024 return;
2080 2025
2081 bridge = dev->bus->self; 2026 bridge = dev->bus->self;
2082 if (!bridge) 2027 if (!bridge)
2083 return; 2028 return;
2084 2029
2085 /* ARI is a PCIe cap v2 feature */ 2030 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)) 2031 if (!(cap & PCI_EXP_DEVCAP2_ARI))
2092 return; 2032 return;
2093 2033
2094 pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl); 2034 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; 2035 bridge->ari_enabled = 1;
2099} 2036}
2100 2037
@@ -2109,20 +2046,14 @@ void pci_enable_ari(struct pci_dev *dev)
2109 */ 2046 */
2110void pci_enable_ido(struct pci_dev *dev, unsigned long type) 2047void pci_enable_ido(struct pci_dev *dev, unsigned long type)
2111{ 2048{
2112 int pos; 2049 u16 ctrl = 0;
2113 u16 ctrl;
2114 2050
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) 2051 if (type & PCI_EXP_IDO_REQUEST)
2122 ctrl |= PCI_EXP_IDO_REQ_EN; 2052 ctrl |= PCI_EXP_IDO_REQ_EN;
2123 if (type & PCI_EXP_IDO_COMPLETION) 2053 if (type & PCI_EXP_IDO_COMPLETION)
2124 ctrl |= PCI_EXP_IDO_CMP_EN; 2054 ctrl |= PCI_EXP_IDO_CMP_EN;
2125 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2055 if (ctrl)
2056 pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, ctrl);
2126} 2057}
2127EXPORT_SYMBOL(pci_enable_ido); 2058EXPORT_SYMBOL(pci_enable_ido);
2128 2059
@@ -2133,20 +2064,14 @@ EXPORT_SYMBOL(pci_enable_ido);
2133 */ 2064 */
2134void pci_disable_ido(struct pci_dev *dev, unsigned long type) 2065void pci_disable_ido(struct pci_dev *dev, unsigned long type)
2135{ 2066{
2136 int pos; 2067 u16 ctrl = 0;
2137 u16 ctrl;
2138 2068
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) 2069 if (type & PCI_EXP_IDO_REQUEST)
2146 ctrl &= ~PCI_EXP_IDO_REQ_EN; 2070 ctrl |= PCI_EXP_IDO_REQ_EN;
2147 if (type & PCI_EXP_IDO_COMPLETION) 2071 if (type & PCI_EXP_IDO_COMPLETION)
2148 ctrl &= ~PCI_EXP_IDO_CMP_EN; 2072 ctrl |= PCI_EXP_IDO_CMP_EN;
2149 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2073 if (ctrl)
2074 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, ctrl);
2150} 2075}
2151EXPORT_SYMBOL(pci_disable_ido); 2076EXPORT_SYMBOL(pci_disable_ido);
2152 2077
@@ -2171,17 +2096,11 @@ EXPORT_SYMBOL(pci_disable_ido);
2171 */ 2096 */
2172int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) 2097int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2173{ 2098{
2174 int pos;
2175 u32 cap; 2099 u32 cap;
2176 u16 ctrl; 2100 u16 ctrl;
2177 int ret; 2101 int ret;
2178 2102
2179 /* OBFF is a PCIe cap v2 feature */ 2103 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)) 2104 if (!(cap & PCI_EXP_OBFF_MASK))
2186 return -ENOTSUPP; /* no OBFF support at all */ 2105 return -ENOTSUPP; /* no OBFF support at all */
2187 2106
@@ -2192,7 +2111,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2192 return ret; 2111 return ret;
2193 } 2112 }
2194 2113
2195 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2114 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &ctrl);
2196 if (cap & PCI_EXP_OBFF_WAKE) 2115 if (cap & PCI_EXP_OBFF_WAKE)
2197 ctrl |= PCI_EXP_OBFF_WAKE_EN; 2116 ctrl |= PCI_EXP_OBFF_WAKE_EN;
2198 else { 2117 else {
@@ -2210,7 +2129,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2210 return -ENOTSUPP; 2129 return -ENOTSUPP;
2211 } 2130 }
2212 } 2131 }
2213 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2132 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, ctrl);
2214 2133
2215 return 0; 2134 return 0;
2216} 2135}
@@ -2224,17 +2143,7 @@ EXPORT_SYMBOL(pci_enable_obff);
2224 */ 2143 */
2225void pci_disable_obff(struct pci_dev *dev) 2144void pci_disable_obff(struct pci_dev *dev)
2226{ 2145{
2227 int pos; 2146 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} 2147}
2239EXPORT_SYMBOL(pci_disable_obff); 2148EXPORT_SYMBOL(pci_disable_obff);
2240 2149
@@ -2247,15 +2156,9 @@ EXPORT_SYMBOL(pci_disable_obff);
2247 */ 2156 */
2248static bool pci_ltr_supported(struct pci_dev *dev) 2157static bool pci_ltr_supported(struct pci_dev *dev)
2249{ 2158{
2250 int pos;
2251 u32 cap; 2159 u32 cap;
2252 2160
2253 /* LTR is a PCIe cap v2 feature */ 2161 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 2162
2260 return cap & PCI_EXP_DEVCAP2_LTR; 2163 return cap & PCI_EXP_DEVCAP2_LTR;
2261} 2164}
@@ -2272,22 +2175,15 @@ static bool pci_ltr_supported(struct pci_dev *dev)
2272 */ 2175 */
2273int pci_enable_ltr(struct pci_dev *dev) 2176int pci_enable_ltr(struct pci_dev *dev)
2274{ 2177{
2275 int pos;
2276 u16 ctrl;
2277 int ret; 2178 int ret;
2278 2179
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 */ 2180 /* Only primary function can enable/disable LTR */
2288 if (PCI_FUNC(dev->devfn) != 0) 2181 if (PCI_FUNC(dev->devfn) != 0)
2289 return -EINVAL; 2182 return -EINVAL;
2290 2183
2184 if (!pci_ltr_supported(dev))
2185 return -ENOTSUPP;
2186
2291 /* Enable upstream ports first */ 2187 /* Enable upstream ports first */
2292 if (dev->bus->self) { 2188 if (dev->bus->self) {
2293 ret = pci_enable_ltr(dev->bus->self); 2189 ret = pci_enable_ltr(dev->bus->self);
@@ -2295,11 +2191,7 @@ int pci_enable_ltr(struct pci_dev *dev)
2295 return ret; 2191 return ret;
2296 } 2192 }
2297 2193
2298 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2194 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} 2195}
2304EXPORT_SYMBOL(pci_enable_ltr); 2196EXPORT_SYMBOL(pci_enable_ltr);
2305 2197
@@ -2309,24 +2201,14 @@ EXPORT_SYMBOL(pci_enable_ltr);
2309 */ 2201 */
2310void pci_disable_ltr(struct pci_dev *dev) 2202void pci_disable_ltr(struct pci_dev *dev)
2311{ 2203{
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 */ 2204 /* Only primary function can enable/disable LTR */
2324 if (PCI_FUNC(dev->devfn) != 0) 2205 if (PCI_FUNC(dev->devfn) != 0)
2325 return; 2206 return;
2326 2207
2327 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2208 if (!pci_ltr_supported(dev))
2328 ctrl &= ~PCI_EXP_LTR_EN; 2209 return;
2329 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2210
2211 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_LTR_EN);
2330} 2212}
2331EXPORT_SYMBOL(pci_disable_ltr); 2213EXPORT_SYMBOL(pci_disable_ltr);
2332 2214
@@ -2409,9 +2291,6 @@ void pci_enable_acs(struct pci_dev *dev)
2409 if (!pci_acs_enable) 2291 if (!pci_acs_enable)
2410 return; 2292 return;
2411 2293
2412 if (!pci_is_pcie(dev))
2413 return;
2414
2415 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); 2294 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
2416 if (!pos) 2295 if (!pos)
2417 return; 2296 return;
@@ -2459,8 +2338,8 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
2459 acs_flags &= (PCI_ACS_RR | PCI_ACS_CR | 2338 acs_flags &= (PCI_ACS_RR | PCI_ACS_CR |
2460 PCI_ACS_EC | PCI_ACS_DT); 2339 PCI_ACS_EC | PCI_ACS_DT);
2461 2340
2462 if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM || 2341 if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM ||
2463 pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT || 2342 pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||
2464 pdev->multifunction) { 2343 pdev->multifunction) {
2465 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS); 2344 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
2466 if (!pos) 2345 if (!pos)
@@ -3176,15 +3055,10 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary);
3176static int pcie_flr(struct pci_dev *dev, int probe) 3055static int pcie_flr(struct pci_dev *dev, int probe)
3177{ 3056{
3178 int i; 3057 int i;
3179 int pos;
3180 u32 cap; 3058 u32 cap;
3181 u16 status, control; 3059 u16 status;
3182
3183 pos = pci_pcie_cap(dev);
3184 if (!pos)
3185 return -ENOTTY;
3186 3060
3187 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap); 3061 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap);
3188 if (!(cap & PCI_EXP_DEVCAP_FLR)) 3062 if (!(cap & PCI_EXP_DEVCAP_FLR))
3189 return -ENOTTY; 3063 return -ENOTTY;
3190 3064
@@ -3196,7 +3070,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3196 if (i) 3070 if (i)
3197 msleep((1 << (i - 1)) * 100); 3071 msleep((1 << (i - 1)) * 100);
3198 3072
3199 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); 3073 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
3200 if (!(status & PCI_EXP_DEVSTA_TRPND)) 3074 if (!(status & PCI_EXP_DEVSTA_TRPND))
3201 goto clear; 3075 goto clear;
3202 } 3076 }
@@ -3205,9 +3079,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3205 "proceeding with reset anyway\n"); 3079 "proceeding with reset anyway\n");
3206 3080
3207clear: 3081clear:
3208 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &control); 3082 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 3083
3212 msleep(100); 3084 msleep(100);
3213 3085
@@ -3575,18 +3447,11 @@ EXPORT_SYMBOL(pcix_set_mmrbc);
3575 */ 3447 */
3576int pcie_get_readrq(struct pci_dev *dev) 3448int pcie_get_readrq(struct pci_dev *dev)
3577{ 3449{
3578 int ret, cap;
3579 u16 ctl; 3450 u16 ctl;
3580 3451
3581 cap = pci_pcie_cap(dev); 3452 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 3453
3589 return ret; 3454 return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
3590} 3455}
3591EXPORT_SYMBOL(pcie_get_readrq); 3456EXPORT_SYMBOL(pcie_get_readrq);
3592 3457
@@ -3600,19 +3465,11 @@ EXPORT_SYMBOL(pcie_get_readrq);
3600 */ 3465 */
3601int pcie_set_readrq(struct pci_dev *dev, int rq) 3466int pcie_set_readrq(struct pci_dev *dev, int rq)
3602{ 3467{
3603 int cap, err = -EINVAL; 3468 u16 v;
3604 u16 ctl, v;
3605 3469
3606 if (rq < 128 || rq > 4096 || !is_power_of_2(rq)) 3470 if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
3607 goto out; 3471 return -EINVAL;
3608
3609 cap = pci_pcie_cap(dev);
3610 if (!cap)
3611 goto out;
3612 3472
3613 err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3614 if (err)
3615 goto out;
3616 /* 3473 /*
3617 * If using the "performance" PCIe config, we clamp the 3474 * If using the "performance" PCIe config, we clamp the
3618 * read rq size to the max packet size to prevent the 3475 * read rq size to the max packet size to prevent the
@@ -3630,14 +3487,8 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
3630 3487
3631 v = (ffs(rq) - 8) << 12; 3488 v = (ffs(rq) - 8) << 12;
3632 3489
3633 if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) { 3490 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3634 ctl &= ~PCI_EXP_DEVCTL_READRQ; 3491 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} 3492}
3642EXPORT_SYMBOL(pcie_set_readrq); 3493EXPORT_SYMBOL(pcie_set_readrq);
3643 3494
@@ -3650,18 +3501,11 @@ EXPORT_SYMBOL(pcie_set_readrq);
3650 */ 3501 */
3651int pcie_get_mps(struct pci_dev *dev) 3502int pcie_get_mps(struct pci_dev *dev)
3652{ 3503{
3653 int ret, cap;
3654 u16 ctl; 3504 u16 ctl;
3655 3505
3656 cap = pci_pcie_cap(dev); 3506 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 3507
3664 return ret; 3508 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3665} 3509}
3666 3510
3667/** 3511/**
@@ -3674,32 +3518,18 @@ int pcie_get_mps(struct pci_dev *dev)
3674 */ 3518 */
3675int pcie_set_mps(struct pci_dev *dev, int mps) 3519int pcie_set_mps(struct pci_dev *dev, int mps)
3676{ 3520{
3677 int cap, err = -EINVAL; 3521 u16 v;
3678 u16 ctl, v;
3679 3522
3680 if (mps < 128 || mps > 4096 || !is_power_of_2(mps)) 3523 if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
3681 goto out; 3524 return -EINVAL;
3682 3525
3683 v = ffs(mps) - 8; 3526 v = ffs(mps) - 8;
3684 if (v > dev->pcie_mpss) 3527 if (v > dev->pcie_mpss)
3685 goto out; 3528 return -EINVAL;
3686 v <<= 5; 3529 v <<= 5;
3687 3530
3688 cap = pci_pcie_cap(dev); 3531 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3689 if (!cap) 3532 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} 3533}
3704 3534
3705/** 3535/**
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 7131644e3ae6..030cf12d5468 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 dc901771d34b..cd46d74ec806 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..d03a7a39b2d8 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -200,10 +200,13 @@ static int init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
200{ 200{
201 int i, irq = -1; 201 int i, irq = -1;
202 202
203 /* We have to use INTx if MSI cannot be used for PCIe PME or pciehp. */ 203 /*
204 * If MSI cannot be used for PCIe PME or hotplug, we have to use
205 * INTx or other interrupts, e.g. system shared interrupt.
206 */
204 if (((mask & PCIE_PORT_SERVICE_PME) && pcie_pme_no_msi()) || 207 if (((mask & PCIE_PORT_SERVICE_PME) && pcie_pme_no_msi()) ||
205 ((mask & PCIE_PORT_SERVICE_HP) && pciehp_no_msi())) { 208 ((mask & PCIE_PORT_SERVICE_HP) && pciehp_no_msi())) {
206 if (dev->pin) 209 if (dev->irq)
207 irq = dev->irq; 210 irq = dev->irq;
208 goto no_msi; 211 goto no_msi;
209 } 212 }
@@ -212,8 +215,12 @@ static int init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
212 if (!pcie_port_enable_msix(dev, irqs, mask)) 215 if (!pcie_port_enable_msix(dev, irqs, mask))
213 return 0; 216 return 0;
214 217
215 /* We're not going to use MSI-X, so try MSI and fall back to INTx */ 218 /*
216 if (!pci_enable_msi(dev) || dev->pin) 219 * We're not going to use MSI-X, so try MSI and fall back to INTx.
220 * If neither MSI/MSI-X nor INTx available, try other interrupt. On
221 * some platforms, root port doesn't support MSI/MSI-X/INTx in RC mode.
222 */
223 if (!pci_enable_msi(dev) || dev->irq)
217 irq = dev->irq; 224 irq = dev->irq;
218 225
219 no_msi: 226 no_msi:
@@ -246,8 +253,7 @@ static void cleanup_service_irqs(struct pci_dev *dev)
246 */ 253 */
247static int get_port_device_capability(struct pci_dev *dev) 254static int get_port_device_capability(struct pci_dev *dev)
248{ 255{
249 int services = 0, pos; 256 int services = 0;
250 u16 reg16;
251 u32 reg32; 257 u32 reg32;
252 int cap_mask = 0; 258 int cap_mask = 0;
253 int err; 259 int err;
@@ -265,11 +271,9 @@ static int get_port_device_capability(struct pci_dev *dev)
265 return 0; 271 return 0;
266 } 272 }
267 273
268 pos = pci_pcie_cap(dev);
269 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &reg16);
270 /* Hot-Plug Capable */ 274 /* Hot-Plug Capable */
271 if ((cap_mask & PCIE_PORT_SERVICE_HP) && (reg16 & PCI_EXP_FLAGS_SLOT)) { 275 if (cap_mask & PCIE_PORT_SERVICE_HP) {
272 pci_read_config_dword(dev, pos + PCI_EXP_SLTCAP, &reg32); 276 pcie_capability_read_dword(dev, PCI_EXP_SLTCAP, &reg32);
273 if (reg32 & PCI_EXP_SLTCAP_HPC) { 277 if (reg32 & PCI_EXP_SLTCAP_HPC) {
274 services |= PCIE_PORT_SERVICE_HP; 278 services |= PCIE_PORT_SERVICE_HP;
275 /* 279 /*
@@ -277,10 +281,8 @@ static int get_port_device_capability(struct pci_dev *dev)
277 * enabled by the BIOS and the hot-plug service driver 281 * enabled by the BIOS and the hot-plug service driver
278 * is not loaded. 282 * is not loaded.
279 */ 283 */
280 pos += PCI_EXP_SLTCTL; 284 pcie_capability_clear_word(dev, PCI_EXP_SLTCTL,
281 pci_read_config_word(dev, pos, &reg16); 285 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 } 286 }
285 } 287 }
286 /* AER capable */ 288 /* AER capable */
@@ -298,7 +300,7 @@ static int get_port_device_capability(struct pci_dev *dev)
298 services |= PCIE_PORT_SERVICE_VC; 300 services |= PCIE_PORT_SERVICE_VC;
299 /* Root ports are capable of generating PME too */ 301 /* Root ports are capable of generating PME too */
300 if ((cap_mask & PCIE_PORT_SERVICE_PME) 302 if ((cap_mask & PCIE_PORT_SERVICE_PME)
301 && dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) { 303 && pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) {
302 services |= PCIE_PORT_SERVICE_PME; 304 services |= PCIE_PORT_SERVICE_PME;
303 /* 305 /*
304 * Disable PME interrupt on this port in case it's been enabled 306 * Disable PME interrupt on this port in case it's been enabled
@@ -336,7 +338,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 */ 338 device->release = release_pcie_device; /* callback to free pcie dev */
337 dev_set_name(device, "%s:pcie%02x", 339 dev_set_name(device, "%s:pcie%02x",
338 pci_name(pdev), 340 pci_name(pdev),
339 get_descriptor_id(pdev->pcie_type, service)); 341 get_descriptor_id(pci_pcie_type(pdev), service));
340 device->parent = &pdev->dev; 342 device->parent = &pdev->dev;
341 device_enable_async_suspend(device); 343 device_enable_async_suspend(device);
342 344
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 943443510089..ca10911ee0df 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/proc.c b/drivers/pci/proc.c
index 27911b55c2a5..eb907a8faf2a 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -434,25 +434,6 @@ int pci_proc_detach_device(struct pci_dev *dev)
434 return 0; 434 return 0;
435} 435}
436 436
437#if 0
438int pci_proc_attach_bus(struct pci_bus* bus)
439{
440 struct proc_dir_entry *de = bus->procdir;
441
442 if (!proc_initialized)
443 return -EACCES;
444
445 if (!de) {
446 char name[16];
447 sprintf(name, "%02x", bus->number);
448 de = bus->procdir = proc_mkdir(name, proc_bus_pci_dir);
449 if (!de)
450 return -ENOMEM;
451 }
452 return 0;
453}
454#endif /* 0 */
455
456int pci_proc_detach_bus(struct pci_bus* bus) 437int pci_proc_detach_bus(struct pci_bus* bus)
457{ 438{
458 struct proc_dir_entry *de = bus->procdir; 439 struct proc_dir_entry *de = bus->procdir;
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/remove.c b/drivers/pci/remove.c
index 04a4861b4749..4f9ca9162895 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -32,53 +32,30 @@ static void pci_stop_dev(struct pci_dev *dev)
32 32
33static void pci_destroy_dev(struct pci_dev *dev) 33static void pci_destroy_dev(struct pci_dev *dev)
34{ 34{
35 /* Remove the device from the device lists, and prevent any further
36 * list accesses from this device */
37 down_write(&pci_bus_sem); 35 down_write(&pci_bus_sem);
38 list_del(&dev->bus_list); 36 list_del(&dev->bus_list);
39 dev->bus_list.next = dev->bus_list.prev = NULL;
40 up_write(&pci_bus_sem); 37 up_write(&pci_bus_sem);
41 38
42 pci_free_resources(dev); 39 pci_free_resources(dev);
43 pci_dev_put(dev); 40 pci_dev_put(dev);
44} 41}
45 42
46/** 43void pci_remove_bus(struct pci_bus *bus)
47 * pci_remove_device_safe - remove an unused hotplug device
48 * @dev: the device to remove
49 *
50 * Delete the device structure from the device lists and
51 * notify userspace (/sbin/hotplug), but only if the device
52 * in question is not being used by a driver.
53 * Returns 0 on success.
54 */
55#if 0
56int pci_remove_device_safe(struct pci_dev *dev)
57{ 44{
58 if (pci_dev_driver(dev)) 45 pci_proc_detach_bus(bus);
59 return -EBUSY;
60 pci_destroy_dev(dev);
61 return 0;
62}
63#endif /* 0 */
64
65void pci_remove_bus(struct pci_bus *pci_bus)
66{
67 pci_proc_detach_bus(pci_bus);
68 46
69 down_write(&pci_bus_sem); 47 down_write(&pci_bus_sem);
70 list_del(&pci_bus->node); 48 list_del(&bus->node);
71 pci_bus_release_busn_res(pci_bus); 49 pci_bus_release_busn_res(bus);
72 up_write(&pci_bus_sem); 50 up_write(&pci_bus_sem);
73 if (!pci_bus->is_added) 51 if (!bus->is_added)
74 return; 52 return;
75 53
76 pci_remove_legacy_files(pci_bus); 54 pci_remove_legacy_files(bus);
77 device_unregister(&pci_bus->dev); 55 device_unregister(&bus->dev);
78} 56}
79EXPORT_SYMBOL(pci_remove_bus); 57EXPORT_SYMBOL(pci_remove_bus);
80 58
81static void __pci_remove_behind_bridge(struct pci_dev *dev);
82/** 59/**
83 * pci_stop_and_remove_bus_device - remove a PCI device and any children 60 * pci_stop_and_remove_bus_device - remove a PCI device and any children
84 * @dev: the device to remove 61 * @dev: the device to remove
@@ -91,93 +68,27 @@ static void __pci_remove_behind_bridge(struct pci_dev *dev);
91 * device lists, remove the /proc entry, and notify userspace 68 * device lists, remove the /proc entry, and notify userspace
92 * (/sbin/hotplug). 69 * (/sbin/hotplug).
93 */ 70 */
94void __pci_remove_bus_device(struct pci_dev *dev)
95{
96 if (dev->subordinate) {
97 struct pci_bus *b = dev->subordinate;
98
99 __pci_remove_behind_bridge(dev);
100 pci_remove_bus(b);
101 dev->subordinate = NULL;
102 }
103
104 pci_destroy_dev(dev);
105}
106EXPORT_SYMBOL(__pci_remove_bus_device);
107
108void pci_stop_and_remove_bus_device(struct pci_dev *dev) 71void pci_stop_and_remove_bus_device(struct pci_dev *dev)
109{ 72{
110 pci_stop_bus_device(dev); 73 struct pci_bus *bus = dev->subordinate;
111 __pci_remove_bus_device(dev); 74 struct pci_dev *child, *tmp;
112}
113
114static void __pci_remove_behind_bridge(struct pci_dev *dev)
115{
116 struct list_head *l, *n;
117
118 if (dev->subordinate)
119 list_for_each_safe(l, n, &dev->subordinate->devices)
120 __pci_remove_bus_device(pci_dev_b(l));
121}
122
123static void pci_stop_behind_bridge(struct pci_dev *dev)
124{
125 struct list_head *l, *n;
126
127 if (dev->subordinate)
128 list_for_each_safe(l, n, &dev->subordinate->devices)
129 pci_stop_bus_device(pci_dev_b(l));
130}
131
132/**
133 * pci_stop_and_remove_behind_bridge - stop and remove all devices behind
134 * a PCI bridge
135 * @dev: PCI bridge device
136 *
137 * Remove all devices on the bus, except for the parent bridge.
138 * This also removes any child buses, and any devices they may
139 * contain in a depth-first manner.
140 */
141void pci_stop_and_remove_behind_bridge(struct pci_dev *dev)
142{
143 pci_stop_behind_bridge(dev);
144 __pci_remove_behind_bridge(dev);
145}
146
147static void pci_stop_bus_devices(struct pci_bus *bus)
148{
149 struct list_head *l, *n;
150 75
151 /* 76 /*
152 * VFs could be removed by pci_stop_and_remove_bus_device() in the 77 * Removing an SR-IOV PF device removes all the associated VFs,
153 * pci_stop_bus_devices() code path for PF. 78 * which will update the bus->devices list and confuse the
154 * aka, bus->devices get updated in the process. 79 * iterator. Therefore, iterate in reverse so we remove the VFs
155 * but VFs are inserted after PFs when SRIOV is enabled for PF, 80 * first, then the PF.
156 * We can iterate the list backwards to get prev valid PF instead
157 * of removed VF.
158 */ 81 */
159 list_for_each_prev_safe(l, n, &bus->devices) { 82 if (bus) {
160 struct pci_dev *dev = pci_dev_b(l); 83 list_for_each_entry_safe_reverse(child, tmp,
161 pci_stop_bus_device(dev); 84 &bus->devices, bus_list)
162 } 85 pci_stop_and_remove_bus_device(child);
163}
164 86
165/** 87 pci_remove_bus(bus);
166 * pci_stop_bus_device - stop a PCI device and any children 88 dev->subordinate = NULL;
167 * @dev: the device to stop 89 }
168 *
169 * Stop a PCI device (detach the driver, remove from the global list
170 * and so on). This also stop any subordinate buses and children in a
171 * depth-first manner.
172 */
173void pci_stop_bus_device(struct pci_dev *dev)
174{
175 if (dev->subordinate)
176 pci_stop_bus_devices(dev->subordinate);
177 90
178 pci_stop_dev(dev); 91 pci_stop_dev(dev);
92 pci_destroy_dev(dev);
179} 93}
180
181EXPORT_SYMBOL(pci_stop_and_remove_bus_device); 94EXPORT_SYMBOL(pci_stop_and_remove_bus_device);
182EXPORT_SYMBOL(pci_stop_and_remove_behind_bridge);
183EXPORT_SYMBOL_GPL(pci_stop_bus_device);
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index 48ebdb237f3f..0b3037ab8b93 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -167,44 +167,6 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
167 return rom; 167 return rom;
168} 168}
169 169
170#if 0
171/**
172 * pci_map_rom_copy - map a PCI ROM to kernel space, create a copy
173 * @pdev: pointer to pci device struct
174 * @size: pointer to receive size of pci window over ROM
175 *
176 * Return: kernel virtual pointer to image of ROM
177 *
178 * Map a PCI ROM into kernel space. If ROM is boot video ROM,
179 * the shadow BIOS copy will be returned instead of the
180 * actual ROM.
181 */
182void __iomem *pci_map_rom_copy(struct pci_dev *pdev, size_t *size)
183{
184 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
185 void __iomem *rom;
186
187 rom = pci_map_rom(pdev, size);
188 if (!rom)
189 return NULL;
190
191 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_SHADOW |
192 IORESOURCE_ROM_BIOS_COPY))
193 return rom;
194
195 res->start = (unsigned long)kmalloc(*size, GFP_KERNEL);
196 if (!res->start)
197 return rom;
198
199 res->end = res->start + *size;
200 memcpy_fromio((void*)(unsigned long)res->start, rom, *size);
201 pci_unmap_rom(pdev, rom);
202 res->flags |= IORESOURCE_ROM_COPY;
203
204 return (void __iomem *)(unsigned long)res->start;
205}
206#endif /* 0 */
207
208/** 170/**
209 * pci_unmap_rom - unmap the ROM from kernel space 171 * pci_unmap_rom - unmap the ROM from kernel space
210 * @pdev: pointer to pci device struct 172 * @pdev: pointer to pci device struct
@@ -226,27 +188,6 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom)
226 pci_disable_rom(pdev); 188 pci_disable_rom(pdev);
227} 189}
228 190
229#if 0
230/**
231 * pci_remove_rom - disable the ROM and remove its sysfs attribute
232 * @pdev: pointer to pci device struct
233 *
234 * Remove the rom file in sysfs and disable ROM decoding.
235 */
236void pci_remove_rom(struct pci_dev *pdev)
237{
238 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
239
240 if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
241 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
242 if (!(res->flags & (IORESOURCE_ROM_ENABLE |
243 IORESOURCE_ROM_SHADOW |
244 IORESOURCE_ROM_BIOS_COPY |
245 IORESOURCE_ROM_COPY)))
246 pci_disable_rom(pdev);
247}
248#endif /* 0 */
249
250/** 191/**
251 * pci_cleanup_rom - free the ROM copy created by pci_map_rom_copy 192 * pci_cleanup_rom - free the ROM copy created by pci_map_rom_copy
252 * @pdev: pointer to pci device struct 193 * @pdev: pointer to pci device struct
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 993d4a0a2469..bf969ba58e59 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;
@@ -130,16 +130,14 @@ pci_find_next_bus(const struct pci_bus *from)
130 * decrement the reference count by calling pci_dev_put(). 130 * decrement the reference count by calling pci_dev_put().
131 * If no device is found, %NULL is returned. 131 * If no device is found, %NULL is returned.
132 */ 132 */
133struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn) 133struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn)
134{ 134{
135 struct list_head *tmp;
136 struct pci_dev *dev; 135 struct pci_dev *dev;
137 136
138 WARN_ON(in_interrupt()); 137 WARN_ON(in_interrupt());
139 down_read(&pci_bus_sem); 138 down_read(&pci_bus_sem);
140 139
141 list_for_each(tmp, &bus->devices) { 140 list_for_each_entry(dev, &bus->devices, bus_list) {
142 dev = pci_dev_b(tmp);
143 if (dev->devfn == devfn) 141 if (dev->devfn == devfn)
144 goto out; 142 goto out;
145 } 143 }
@@ -245,30 +243,14 @@ struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
245 unsigned int ss_vendor, unsigned int ss_device, 243 unsigned int ss_vendor, unsigned int ss_device,
246 struct pci_dev *from) 244 struct pci_dev *from)
247{ 245{
248 struct pci_dev *pdev; 246 struct pci_device_id id = {
249 struct pci_device_id *id; 247 .vendor = vendor,
250 248 .device = device,
251 /* 249 .subvendor = ss_vendor,
252 * pci_find_subsys() can be called on the ide_setup() path, 250 .subdevice = ss_device,
253 * super-early in boot. But the down_read() will enable local 251 };
254 * interrupts, which can cause some machines to crash. So here we 252
255 * detect and flag that situation and bail out early. 253 return pci_get_dev_by_id(&id, from);
256 */
257 if (unlikely(no_pci_devices()))
258 return NULL;
259
260 id = kzalloc(sizeof(*id), GFP_KERNEL);
261 if (!id)
262 return NULL;
263 id->vendor = vendor;
264 id->device = device;
265 id->subvendor = ss_vendor;
266 id->subdevice = ss_device;
267
268 pdev = pci_get_dev_by_id(id, from);
269 kfree(id);
270
271 return pdev;
272} 254}
273 255
274/** 256/**
@@ -307,19 +289,16 @@ pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
307 */ 289 */
308struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from) 290struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
309{ 291{
310 struct pci_dev *dev; 292 struct pci_device_id id = {
311 struct pci_device_id *id; 293 .vendor = PCI_ANY_ID,
312 294 .device = PCI_ANY_ID,
313 id = kzalloc(sizeof(*id), GFP_KERNEL); 295 .subvendor = PCI_ANY_ID,
314 if (!id) 296 .subdevice = PCI_ANY_ID,
315 return NULL; 297 .class_mask = PCI_ANY_ID,
316 id->vendor = id->device = id->subvendor = id->subdevice = PCI_ANY_ID; 298 .class = class,
317 id->class_mask = PCI_ANY_ID; 299 };
318 id->class = class; 300
319 301 return pci_get_dev_by_id(&id, from);
320 dev = pci_get_dev_by_id(id, from);
321 kfree(id);
322 return dev;
323} 302}
324 303
325/** 304/**
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index fb506137aaee..1e808ca338f8 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -697,6 +697,38 @@ static resource_size_t calculate_memsize(resource_size_t size,
697 return size; 697 return size;
698} 698}
699 699
700resource_size_t __weak pcibios_window_alignment(struct pci_bus *bus,
701 unsigned long type)
702{
703 return 1;
704}
705
706#define PCI_P2P_DEFAULT_MEM_ALIGN 0x100000 /* 1MiB */
707#define PCI_P2P_DEFAULT_IO_ALIGN 0x1000 /* 4KiB */
708#define PCI_P2P_DEFAULT_IO_ALIGN_1K 0x400 /* 1KiB */
709
710static resource_size_t window_alignment(struct pci_bus *bus,
711 unsigned long type)
712{
713 resource_size_t align = 1, arch_align;
714
715 if (type & IORESOURCE_MEM)
716 align = PCI_P2P_DEFAULT_MEM_ALIGN;
717 else if (type & IORESOURCE_IO) {
718 /*
719 * Per spec, I/O windows are 4K-aligned, but some
720 * bridges have an extension to support 1K alignment.
721 */
722 if (bus->self->io_window_1k)
723 align = PCI_P2P_DEFAULT_IO_ALIGN_1K;
724 else
725 align = PCI_P2P_DEFAULT_IO_ALIGN;
726 }
727
728 arch_align = pcibios_window_alignment(bus, type);
729 return max(align, arch_align);
730}
731
700/** 732/**
701 * pbus_size_io() - size the io window of a given bus 733 * pbus_size_io() - size the io window of a given bus
702 * 734 *
@@ -717,17 +749,12 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
717 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 749 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
718 unsigned long size = 0, size0 = 0, size1 = 0; 750 unsigned long size = 0, size0 = 0, size1 = 0;
719 resource_size_t children_add_size = 0; 751 resource_size_t children_add_size = 0;
720 resource_size_t min_align = 4096, align; 752 resource_size_t min_align, io_align, align;
721 753
722 if (!b_res) 754 if (!b_res)
723 return; 755 return;
724 756
725 /* 757 io_align = min_align = window_alignment(bus, IORESOURCE_IO);
726 * Per spec, I/O windows are 4K-aligned, but some bridges have an
727 * extension to support 1K alignment.
728 */
729 if (bus->self->io_window_1k)
730 min_align = 1024;
731 list_for_each_entry(dev, &bus->devices, bus_list) { 758 list_for_each_entry(dev, &bus->devices, bus_list) {
732 int i; 759 int i;
733 760
@@ -754,8 +781,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
754 } 781 }
755 } 782 }
756 783
757 if (min_align > 4096) 784 if (min_align > io_align)
758 min_align = 4096; 785 min_align = io_align;
759 786
760 size0 = calculate_iosize(size, min_size, size1, 787 size0 = calculate_iosize(size, min_size, size1,
761 resource_size(b_res), min_align); 788 resource_size(b_res), min_align);
@@ -785,6 +812,28 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
785 } 812 }
786} 813}
787 814
815static inline resource_size_t calculate_mem_align(resource_size_t *aligns,
816 int max_order)
817{
818 resource_size_t align = 0;
819 resource_size_t min_align = 0;
820 int order;
821
822 for (order = 0; order <= max_order; order++) {
823 resource_size_t align1 = 1;
824
825 align1 <<= (order + 20);
826
827 if (!align)
828 min_align = align1;
829 else if (ALIGN(align + min_align, min_align) < align1)
830 min_align = align1 >> 1;
831 align += aligns[order];
832 }
833
834 return min_align;
835}
836
788/** 837/**
789 * pbus_size_mem() - size the memory window of a given bus 838 * pbus_size_mem() - size the memory window of a given bus
790 * 839 *
@@ -864,19 +913,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
864 children_add_size += get_res_add_size(realloc_head, r); 913 children_add_size += get_res_add_size(realloc_head, r);
865 } 914 }
866 } 915 }
867 align = 0;
868 min_align = 0;
869 for (order = 0; order <= max_order; order++) {
870 resource_size_t align1 = 1;
871 916
872 align1 <<= (order + 20); 917 min_align = calculate_mem_align(aligns, max_order);
873 918 min_align = max(min_align, window_alignment(bus, b_res->flags & mask));
874 if (!align)
875 min_align = align1;
876 else if (ALIGN(align + min_align, min_align) < align1)
877 min_align = align1 >> 1;
878 align += aligns[order];
879 }
880 size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); 919 size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
881 if (children_add_size > add_size) 920 if (children_add_size > add_size)
882 add_size = children_add_size; 921 add_size = children_add_size;
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 24caeaf50529..9d3ac998fc1f 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -105,8 +105,17 @@ int __ref cb_alloc(struct pcmcia_socket *s)
105 */ 105 */
106void cb_free(struct pcmcia_socket *s) 106void cb_free(struct pcmcia_socket *s)
107{ 107{
108 struct pci_dev *bridge = s->cb_dev; 108 struct pci_dev *bridge, *dev, *tmp;
109 struct pci_bus *bus;
109 110
110 if (bridge) 111 bridge = s->cb_dev;
111 pci_stop_and_remove_behind_bridge(bridge); 112 if (!bridge)
113 return;
114
115 bus = bridge->subordinate;
116 if (!bus)
117 return;
118
119 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
120 pci_stop_and_remove_bus_device(dev);
112} 121}
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 f0f2b80e5e7f..f3b074eb117c 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
@@ -369,7 +369,6 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
369 369
370extern struct pci_dev *alloc_pci_dev(void); 370extern struct pci_dev *alloc_pci_dev(void);
371 371
372#define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list)
373#define to_pci_dev(n) container_of(n, struct pci_dev, dev) 372#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
374#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) 373#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
375 374
@@ -734,9 +733,7 @@ u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
734extern struct pci_dev *pci_dev_get(struct pci_dev *dev); 733extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
735extern void pci_dev_put(struct pci_dev *dev); 734extern void pci_dev_put(struct pci_dev *dev);
736extern void pci_remove_bus(struct pci_bus *b); 735extern void pci_remove_bus(struct pci_bus *b);
737extern void __pci_remove_bus_device(struct pci_dev *dev);
738extern void pci_stop_and_remove_bus_device(struct pci_dev *dev); 736extern void pci_stop_and_remove_bus_device(struct pci_dev *dev);
739extern void pci_stop_bus_device(struct pci_dev *dev);
740void pci_setup_cardbus(struct pci_bus *bus); 737void pci_setup_cardbus(struct pci_bus *bus);
741extern void pci_sort_breadthfirst(void); 738extern void pci_sort_breadthfirst(void);
742#define dev_is_pci(d) ((d)->bus == &pci_bus_type) 739#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
@@ -755,6 +752,7 @@ enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev);
755int pci_find_capability(struct pci_dev *dev, int cap); 752int pci_find_capability(struct pci_dev *dev, int cap);
756int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap); 753int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
757int pci_find_ext_capability(struct pci_dev *dev, int cap); 754int pci_find_ext_capability(struct pci_dev *dev, int cap);
755int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
758int pci_find_ht_capability(struct pci_dev *dev, int ht_cap); 756int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
759int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap); 757int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
760struct pci_bus *pci_find_next_bus(const struct pci_bus *from); 758struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
@@ -816,6 +814,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); 814 return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
817} 815}
818 816
817int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
818int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val);
819int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
820int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val);
821int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
822 u16 clear, u16 set);
823int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
824 u32 clear, u32 set);
825
826static inline int pcie_capability_set_word(struct pci_dev *dev, int pos,
827 u16 set)
828{
829 return pcie_capability_clear_and_set_word(dev, pos, 0, set);
830}
831
832static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos,
833 u32 set)
834{
835 return pcie_capability_clear_and_set_dword(dev, pos, 0, set);
836}
837
838static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
839 u16 clear)
840{
841 return pcie_capability_clear_and_set_word(dev, pos, clear, 0);
842}
843
844static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
845 u32 clear)
846{
847 return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
848}
849
819/* user-space driven config access */ 850/* user-space driven config access */
820int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 851int 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); 852int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
@@ -1013,7 +1044,6 @@ void pci_unregister_driver(struct pci_driver *dev);
1013 module_driver(__pci_driver, pci_register_driver, \ 1044 module_driver(__pci_driver, pci_register_driver, \
1014 pci_unregister_driver) 1045 pci_unregister_driver)
1015 1046
1016void pci_stop_and_remove_behind_bridge(struct pci_dev *dev);
1017struct pci_driver *pci_dev_driver(const struct pci_dev *dev); 1047struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
1018int pci_add_dynid(struct pci_driver *drv, 1048int pci_add_dynid(struct pci_driver *drv,
1019 unsigned int vendor, unsigned int device, 1049 unsigned int vendor, unsigned int device,
@@ -1031,6 +1061,8 @@ int pci_cfg_space_size_ext(struct pci_dev *dev);
1031int pci_cfg_space_size(struct pci_dev *dev); 1061int pci_cfg_space_size(struct pci_dev *dev);
1032unsigned char pci_bus_max_busnr(struct pci_bus *bus); 1062unsigned char pci_bus_max_busnr(struct pci_bus *bus);
1033void pci_setup_bridge(struct pci_bus *bus); 1063void pci_setup_bridge(struct pci_bus *bus);
1064resource_size_t pcibios_window_alignment(struct pci_bus *bus,
1065 unsigned long type);
1034 1066
1035#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0) 1067#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
1036#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1) 1068#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
@@ -1650,6 +1682,15 @@ static inline bool pci_is_pcie(struct pci_dev *dev)
1650 return !!pci_pcie_cap(dev); 1682 return !!pci_pcie_cap(dev);
1651} 1683}
1652 1684
1685/**
1686 * pci_pcie_type - get the PCIe device/port type
1687 * @dev: PCI device
1688 */
1689static inline int pci_pcie_type(const struct pci_dev *dev)
1690{
1691 return (dev->pcie_flags_reg & PCI_EXP_FLAGS_TYPE) >> 4;
1692}
1693
1653void pci_request_acs(void); 1694void pci_request_acs(void);
1654bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags); 1695bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
1655bool pci_acs_path_enabled(struct pci_dev *start, 1696bool pci_acs_path_enabled(struct pci_dev *start,
diff --git a/include/linux/pci_regs.h b/include/linux/pci_regs.h
index 7fb75b143755..20ae747ddf34 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) */
@@ -677,6 +678,12 @@
677#define PCI_PWR_CAP_BUDGET(x) ((x) & 1) /* Included in system budget */ 678#define PCI_PWR_CAP_BUDGET(x) ((x) & 1) /* Included in system budget */
678#define PCI_EXT_CAP_PWR_SIZEOF 16 679#define PCI_EXT_CAP_PWR_SIZEOF 16
679 680
681/* Vendor-Specific (VSEC, PCI_EXT_CAP_ID_VNDR) */
682#define PCI_VNDR_HEADER 4 /* Vendor-Specific Header */
683#define PCI_VNDR_HEADER_ID(x) ((x) & 0xffff)
684#define PCI_VNDR_HEADER_REV(x) (((x) >> 16) & 0xf)
685#define PCI_VNDR_HEADER_LEN(x) (((x) >> 20) & 0xfff)
686
680/* 687/*
681 * Hypertransport sub capability types 688 * Hypertransport sub capability types
682 * 689 *