Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'pci/errors'

- Add PCI_ERROR_RESPONSE and related definitions for signaling and checking
for transaction errors on PCI (Naveen Naidu)

- Fabricate PCI_ERROR_RESPONSE data (~0) in config read wrappers, instead
of in host controller drivers, when transactions fail on PCI (Naveen
Naidu)

- Use PCI_POSSIBLE_ERROR() to check for possible failure of config reads
(Naveen Naidu)

* pci/errors:
PCI: xgene: Use PCI_ERROR_RESPONSE to identify config read errors
PCI: hv: Use PCI_ERROR_RESPONSE to identify config read errors
PCI: keystone: Use PCI_ERROR_RESPONSE to identify config read errors
PCI: Use PCI_ERROR_RESPONSE to identify config read errors
PCI: cpqphp: Use PCI_POSSIBLE_ERROR() to check config reads
PCI/PME: Use PCI_POSSIBLE_ERROR() to check config reads
PCI/DPC: Use PCI_POSSIBLE_ERROR() to check config reads
PCI: pciehp: Use PCI_POSSIBLE_ERROR() to check config reads
PCI: vmd: Use PCI_POSSIBLE_ERROR() to check config reads
PCI/ERR: Use PCI_POSSIBLE_ERROR() to check config reads
PCI: rockchip-host: Drop error data fabrication when config read fails
PCI: rcar-host: Drop error data fabrication when config read fails
PCI: altera: Drop error data fabrication when config read fails
PCI: mvebu: Drop error data fabrication when config read fails
PCI: aardvark: Drop error data fabrication when config read fails
PCI: kirin: Drop error data fabrication when config read fails
PCI: histb: Drop error data fabrication when config read fails
PCI: exynos: Drop error data fabrication when config read fails
PCI: mediatek: Drop error data fabrication when config read fails
PCI: iproc: Drop error data fabrication when config read fails
PCI: thunder: Drop error data fabrication when config read fails
PCI: Drop error data fabrication when config read fails
PCI: Use PCI_SET_ERROR_RESPONSE() for disconnected devices
PCI: Set error response data when config read fails
PCI: Add PCI_ERROR_RESPONSE and related definitions

+88 -120
+19 -17
drivers/pci/access.c
··· 42 42 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \ 43 43 pci_lock_config(flags); \ 44 44 res = bus->ops->read(bus, devfn, pos, len, &data); \ 45 - *value = (type)data; \ 45 + if (res) \ 46 + PCI_SET_ERROR_RESPONSE(value); \ 47 + else \ 48 + *value = (type)data; \ 46 49 pci_unlock_config(flags); \ 47 50 return res; \ 48 51 } ··· 83 80 void __iomem *addr; 84 81 85 82 addr = bus->ops->map_bus(bus, devfn, where); 86 - if (!addr) { 87 - *val = ~0; 83 + if (!addr) 88 84 return PCIBIOS_DEVICE_NOT_FOUND; 89 - } 90 85 91 86 if (size == 1) 92 87 *val = readb(addr); ··· 123 122 void __iomem *addr; 124 123 125 124 addr = bus->ops->map_bus(bus, devfn, where & ~0x3); 126 - if (!addr) { 127 - *val = ~0; 125 + if (!addr) 128 126 return PCIBIOS_DEVICE_NOT_FOUND; 129 - } 130 127 131 128 *val = readl(addr); 132 129 ··· 227 228 ret = dev->bus->ops->read(dev->bus, dev->devfn, \ 228 229 pos, sizeof(type), &data); \ 229 230 raw_spin_unlock_irq(&pci_lock); \ 230 - *val = (type)data; \ 231 + if (ret) \ 232 + PCI_SET_ERROR_RESPONSE(val); \ 233 + else \ 234 + *val = (type)data; \ 231 235 return pcibios_err_to_errno(ret); \ 232 236 } \ 233 237 EXPORT_SYMBOL_GPL(pci_user_read_config_##size); ··· 412 410 if (pcie_capability_reg_implemented(dev, pos)) { 413 411 ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val); 414 412 /* 415 - * Reset *val to 0 if pci_read_config_word() fails, it may 416 - * have been written as 0xFFFF if hardware error happens 417 - * during pci_read_config_word(). 413 + * Reset *val to 0 if pci_read_config_word() fails; it may 414 + * have been written as 0xFFFF (PCI_ERROR_RESPONSE) if the 415 + * config read failed on PCI. 418 416 */ 419 417 if (ret) 420 418 *val = 0; ··· 447 445 if (pcie_capability_reg_implemented(dev, pos)) { 448 446 ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val); 449 447 /* 450 - * Reset *val to 0 if pci_read_config_dword() fails, it may 451 - * have been written as 0xFFFFFFFF if hardware error happens 452 - * during pci_read_config_dword(). 448 + * Reset *val to 0 if pci_read_config_dword() fails; it may 449 + * have been written as 0xFFFFFFFF (PCI_ERROR_RESPONSE) if 450 + * the config read failed on PCI. 453 451 */ 454 452 if (ret) 455 453 *val = 0; ··· 525 523 int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val) 526 524 { 527 525 if (pci_dev_is_disconnected(dev)) { 528 - *val = ~0; 526 + PCI_SET_ERROR_RESPONSE(val); 529 527 return PCIBIOS_DEVICE_NOT_FOUND; 530 528 } 531 529 return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val); ··· 535 533 int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val) 536 534 { 537 535 if (pci_dev_is_disconnected(dev)) { 538 - *val = ~0; 536 + PCI_SET_ERROR_RESPONSE(val); 539 537 return PCIBIOS_DEVICE_NOT_FOUND; 540 538 } 541 539 return pci_bus_read_config_word(dev->bus, dev->devfn, where, val); ··· 546 544 u32 *val) 547 545 { 548 546 if (pci_dev_is_disconnected(dev)) { 549 - *val = ~0; 547 + PCI_SET_ERROR_RESPONSE(val); 550 548 return PCIBIOS_DEVICE_NOT_FOUND; 551 549 } 552 550 return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
+1 -3
drivers/pci/controller/dwc/pci-exynos.c
··· 216 216 { 217 217 struct dw_pcie *pci = to_dw_pcie_from_pp(bus->sysdata); 218 218 219 - if (PCI_SLOT(devfn)) { 220 - *val = ~0; 219 + if (PCI_SLOT(devfn)) 221 220 return PCIBIOS_DEVICE_NOT_FOUND; 222 - } 223 221 224 222 *val = dw_pcie_read_dbi(pci, where, size); 225 223 return PCIBIOS_SUCCESSFUL;
+3 -3
drivers/pci/controller/dwc/pci-keystone.c
··· 747 747 748 748 #ifdef CONFIG_ARM 749 749 /* 750 - * When a PCI device does not exist during config cycles, keystone host gets a 751 - * bus error instead of returning 0xffffffff. This handler always returns 0 752 - * for this kind of faults. 750 + * When a PCI device does not exist during config cycles, keystone host 751 + * gets a bus error instead of returning 0xffffffff (PCI_ERROR_RESPONSE). 752 + * This handler always returns 0 for this kind of fault. 753 753 */ 754 754 static int ks_pcie_fault(unsigned long addr, unsigned int fsr, 755 755 struct pt_regs *regs)
+1 -3
drivers/pci/controller/dwc/pcie-histb.c
··· 127 127 { 128 128 struct dw_pcie *pci = to_dw_pcie_from_pp(bus->sysdata); 129 129 130 - if (PCI_SLOT(devfn)) { 131 - *val = ~0; 130 + if (PCI_SLOT(devfn)) 132 131 return PCIBIOS_DEVICE_NOT_FOUND; 133 - } 134 132 135 133 *val = dw_pcie_read_dbi(pci, where, size); 136 134 return PCIBIOS_SUCCESSFUL;
+1 -3
drivers/pci/controller/dwc/pcie-kirin.c
··· 530 530 { 531 531 struct dw_pcie *pci = to_dw_pcie_from_pp(bus->sysdata); 532 532 533 - if (PCI_SLOT(devfn)) { 534 - *val = ~0; 533 + if (PCI_SLOT(devfn)) 535 534 return PCIBIOS_DEVICE_NOT_FOUND; 536 - } 537 535 538 536 *val = dw_pcie_read_dbi(pci, where, size); 539 537 return PCIBIOS_SUCCESSFUL;
+1 -3
drivers/pci/controller/pci-aardvark.c
··· 1037 1037 u32 reg; 1038 1038 int ret; 1039 1039 1040 - if (!advk_pcie_valid_device(pcie, bus, devfn)) { 1041 - *val = 0xffffffff; 1040 + if (!advk_pcie_valid_device(pcie, bus, devfn)) 1042 1041 return PCIBIOS_DEVICE_NOT_FOUND; 1043 - } 1044 1042 1045 1043 if (pci_is_root_bus(bus)) 1046 1044 return pci_bridge_emul_conf_read(&pcie->bridge, where,
+1 -1
drivers/pci/controller/pci-hyperv.c
··· 2030 2030 * If the memory enable bit is already set, Hyper-V silently ignores 2031 2031 * the below BAR updates, and the related PCI device driver can not 2032 2032 * work, because reading from the device register(s) always returns 2033 - * 0xFFFFFFFF. 2033 + * 0xFFFFFFFF (PCI_ERROR_RESPONSE). 2034 2034 */ 2035 2035 list_for_each_entry(hpdev, &hbus->children, list_entry) { 2036 2036 _hv_pcifront_read_config(hpdev, PCI_COMMAND, 2, &command);
+2 -6
drivers/pci/controller/pci-mvebu.c
··· 814 814 int ret; 815 815 816 816 port = mvebu_pcie_find_port(pcie, bus, devfn); 817 - if (!port) { 818 - *val = 0xffffffff; 817 + if (!port) 819 818 return PCIBIOS_DEVICE_NOT_FOUND; 820 - } 821 819 822 820 /* Access the emulated PCI-to-PCI bridge */ 823 821 if (bus->number == 0) 824 822 return pci_bridge_emul_conf_read(&port->bridge, where, 825 823 size, val); 826 824 827 - if (!mvebu_pcie_link_up(port)) { 828 - *val = 0xffffffff; 825 + if (!mvebu_pcie_link_up(port)) 829 826 return PCIBIOS_DEVICE_NOT_FOUND; 830 - } 831 827 832 828 /* Access the real PCIe interface */ 833 829 ret = mvebu_pcie_hw_rd_conf(port, bus, devfn,
+16 -30
drivers/pci/controller/pci-thunder-ecam.c
··· 41 41 } 42 42 if (where_a == 0x4) { 43 43 addr = bus->ops->map_bus(bus, devfn, bar); /* BAR 0 */ 44 - if (!addr) { 45 - *val = ~0; 44 + if (!addr) 46 45 return PCIBIOS_DEVICE_NOT_FOUND; 47 - } 46 + 48 47 v = readl(addr); 49 48 v &= ~0xf; 50 49 v |= 2; /* EA entry-1. Base-L */ ··· 55 56 u32 barl_rb; 56 57 57 58 addr = bus->ops->map_bus(bus, devfn, bar); /* BAR 0 */ 58 - if (!addr) { 59 - *val = ~0; 59 + if (!addr) 60 60 return PCIBIOS_DEVICE_NOT_FOUND; 61 - } 61 + 62 62 barl_orig = readl(addr + 0); 63 63 writel(0xffffffff, addr + 0); 64 64 barl_rb = readl(addr + 0); ··· 70 72 } 71 73 if (where_a == 0xc) { 72 74 addr = bus->ops->map_bus(bus, devfn, bar + 4); /* BAR 1 */ 73 - if (!addr) { 74 - *val = ~0; 75 + if (!addr) 75 76 return PCIBIOS_DEVICE_NOT_FOUND; 76 - } 77 + 77 78 v = readl(addr); /* EA entry-3. Base-H */ 78 79 set_val(v, where, size, val); 79 80 return PCIBIOS_SUCCESSFUL; ··· 101 104 } 102 105 103 106 addr = bus->ops->map_bus(bus, devfn, where_a); 104 - if (!addr) { 105 - *val = ~0; 107 + if (!addr) 106 108 return PCIBIOS_DEVICE_NOT_FOUND; 107 - } 108 109 109 110 v = readl(addr); 110 111 ··· 130 135 int where_a = where & ~3; 131 136 132 137 addr = bus->ops->map_bus(bus, devfn, 0xc); 133 - if (!addr) { 134 - *val = ~0; 138 + if (!addr) 135 139 return PCIBIOS_DEVICE_NOT_FOUND; 136 - } 137 140 138 141 v = readl(addr); 139 142 ··· 139 146 cfg_type = (v >> 16) & 0x7f; 140 147 141 148 addr = bus->ops->map_bus(bus, devfn, 8); 142 - if (!addr) { 143 - *val = ~0; 149 + if (!addr) 144 150 return PCIBIOS_DEVICE_NOT_FOUND; 145 - } 146 151 147 152 class_rev = readl(addr); 148 153 if (class_rev == 0xffffffff) ··· 167 176 } 168 177 169 178 addr = bus->ops->map_bus(bus, devfn, 0); 170 - if (!addr) { 171 - *val = ~0; 179 + if (!addr) 172 180 return PCIBIOS_DEVICE_NOT_FOUND; 173 - } 174 181 175 182 vendor_device = readl(addr); 176 183 if (vendor_device == 0xffffffff) ··· 185 196 bool is_tns = (vendor_device == 0xa01f177d); 186 197 187 198 addr = bus->ops->map_bus(bus, devfn, 0x70); 188 - if (!addr) { 189 - *val = ~0; 199 + if (!addr) 190 200 return PCIBIOS_DEVICE_NOT_FOUND; 191 - } 201 + 192 202 /* E_CAP */ 193 203 v = readl(addr); 194 204 has_msix = (v & 0xff00) != 0; ··· 199 211 } 200 212 if (where_a == 0xb0) { 201 213 addr = bus->ops->map_bus(bus, devfn, where_a); 202 - if (!addr) { 203 - *val = ~0; 214 + if (!addr) 204 215 return PCIBIOS_DEVICE_NOT_FOUND; 205 - } 216 + 206 217 v = readl(addr); 207 218 if (v & 0xff00) 208 219 pr_err("Bad MSIX cap header: %08x\n", v); ··· 255 268 256 269 if (where_a == 0x70) { 257 270 addr = bus->ops->map_bus(bus, devfn, where_a); 258 - if (!addr) { 259 - *val = ~0; 271 + if (!addr) 260 272 return PCIBIOS_DEVICE_NOT_FOUND; 261 - } 273 + 262 274 v = readl(addr); 263 275 if (v & 0xff00) 264 276 pr_err("Bad PCIe cap header: %08x\n", v);
+1 -3
drivers/pci/controller/pci-thunder-pem.c
··· 41 41 struct pci_config_window *cfg = bus->sysdata; 42 42 struct thunder_pem_pci *pem_pci = (struct thunder_pem_pci *)cfg->priv; 43 43 44 - if (devfn != 0 || where >= 2048) { 45 - *val = ~0; 44 + if (devfn != 0 || where >= 2048) 46 45 return PCIBIOS_DEVICE_NOT_FOUND; 47 - } 48 46 49 47 /* 50 48 * 32-bit accesses only. Write the address to the low order
+5 -5
drivers/pci/controller/pci-xgene.c
··· 171 171 return PCIBIOS_DEVICE_NOT_FOUND; 172 172 173 173 /* 174 - * The v1 controller has a bug in its Configuration Request 175 - * Retry Status (CRS) logic: when CRS Software Visibility is 176 - * enabled and we read the Vendor and Device ID of a non-existent 177 - * device, the controller fabricates return data of 0xFFFF0001 178 - * ("device exists but is not ready") instead of 0xFFFFFFFF 174 + * The v1 controller has a bug in its Configuration Request Retry 175 + * Status (CRS) logic: when CRS Software Visibility is enabled and 176 + * we read the Vendor and Device ID of a non-existent device, the 177 + * controller fabricates return data of 0xFFFF0001 ("device exists 178 + * but is not ready") instead of 0xFFFFFFFF (PCI_ERROR_RESPONSE) 179 179 * ("device does not exist"). This causes the PCI core to retry 180 180 * the read until it times out. Avoid this by not claiming to 181 181 * support CRS SV.
+1 -3
drivers/pci/controller/pcie-altera.c
··· 510 510 if (altera_pcie_hide_rc_bar(bus, devfn, where)) 511 511 return PCIBIOS_BAD_REGISTER_NUMBER; 512 512 513 - if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) { 514 - *value = 0xffffffff; 513 + if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) 515 514 return PCIBIOS_DEVICE_NOT_FOUND; 516 - } 517 515 518 516 return _altera_pcie_cfg_read(pcie, bus->number, devfn, where, size, 519 517 value);
+1 -3
drivers/pci/controller/pcie-iproc.c
··· 659 659 void __iomem *addr; 660 660 661 661 addr = iproc_pcie_map_cfg_bus(pcie, 0, devfn, where & ~0x3); 662 - if (!addr) { 663 - *val = ~0; 662 + if (!addr) 664 663 return PCIBIOS_DEVICE_NOT_FOUND; 665 - } 666 664 667 665 *val = readl(addr); 668 666
+2 -9
drivers/pci/controller/pcie-mediatek.c
··· 365 365 { 366 366 struct mtk_pcie_port *port; 367 367 u32 bn = bus->number; 368 - int ret; 369 368 370 369 port = mtk_pcie_find_port(bus, devfn); 371 - if (!port) { 372 - *val = ~0; 370 + if (!port) 373 371 return PCIBIOS_DEVICE_NOT_FOUND; 374 - } 375 372 376 - ret = mtk_pcie_hw_rd_cfg(port, bn, devfn, where, size, val); 377 - if (ret) 378 - *val = ~0; 379 - 380 - return ret; 373 + return mtk_pcie_hw_rd_cfg(port, bn, devfn, where, size, val); 381 374 } 382 375 383 376 static int mtk_pcie_config_write(struct pci_bus *bus, unsigned int devfn,
+1 -3
drivers/pci/controller/pcie-rcar-host.c
··· 159 159 160 160 ret = rcar_pcie_config_access(host, RCAR_PCI_ACCESS_READ, 161 161 bus, devfn, where, val); 162 - if (ret != PCIBIOS_SUCCESSFUL) { 163 - *val = 0xffffffff; 162 + if (ret != PCIBIOS_SUCCESSFUL) 164 163 return ret; 165 - } 166 164 167 165 if (size == 1) 168 166 *val = (*val >> (BITS_PER_BYTE * (where & 3))) & 0xff;
+1 -3
drivers/pci/controller/pcie-rockchip-host.c
··· 221 221 { 222 222 struct rockchip_pcie *rockchip = bus->sysdata; 223 223 224 - if (!rockchip_pcie_valid_device(rockchip, bus, PCI_SLOT(devfn))) { 225 - *val = 0xffffffff; 224 + if (!rockchip_pcie_valid_device(rockchip, bus, PCI_SLOT(devfn))) 226 225 return PCIBIOS_DEVICE_NOT_FOUND; 227 - } 228 226 229 227 if (pci_is_root_bus(bus)) 230 228 return rockchip_pcie_rd_own_conf(rockchip, where, size, val);
+1 -1
drivers/pci/controller/vmd.c
··· 575 575 int ret; 576 576 577 577 ret = pci_read_config_dword(dev, PCI_REG_VMLOCK, &vmlock); 578 - if (ret || vmlock == ~0) 578 + if (ret || PCI_POSSIBLE_ERROR(vmlock)) 579 579 return -ENODEV; 580 580 581 581 if (MB2_SHADOW_EN(vmlock)) {
+2 -2
drivers/pci/hotplug/cpqphp_ctrl.c
··· 2273 2273 while ((function < max_functions) && (!stop_it)) { 2274 2274 pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID); 2275 2275 2276 - if (ID == 0xFFFFFFFF) { 2276 + if (PCI_POSSIBLE_ERROR(ID)) { 2277 2277 function++; 2278 2278 } else { 2279 2279 /* Setup slot structure. */ ··· 2517 2517 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0), 0x00, &ID); 2518 2518 pci_bus->number = func->bus; 2519 2519 2520 - if (ID != 0xFFFFFFFF) { /* device present */ 2520 + if (!PCI_POSSIBLE_ERROR(ID)) { /* device present */ 2521 2521 /* Setup slot structure. */ 2522 2522 new_slot = cpqhp_slot_create(hold_bus_node->base); 2523 2523
+5 -5
drivers/pci/hotplug/pciehp_hpc.c
··· 89 89 90 90 do { 91 91 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); 92 - if (slot_status == (u16) ~0) { 92 + if (PCI_POSSIBLE_ERROR(slot_status)) { 93 93 ctrl_info(ctrl, "%s: no response from device\n", 94 94 __func__); 95 95 return 0; ··· 165 165 pcie_wait_cmd(ctrl); 166 166 167 167 pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); 168 - if (slot_ctrl == (u16) ~0) { 168 + if (PCI_POSSIBLE_ERROR(slot_ctrl)) { 169 169 ctrl_info(ctrl, "%s: no response from device\n", __func__); 170 170 goto out; 171 171 } ··· 236 236 int ret; 237 237 238 238 ret = pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); 239 - if (ret == PCIBIOS_DEVICE_NOT_FOUND || lnk_status == (u16)~0) 239 + if (ret == PCIBIOS_DEVICE_NOT_FOUND || PCI_POSSIBLE_ERROR(lnk_status)) 240 240 return -ENODEV; 241 241 242 242 ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); ··· 443 443 int ret; 444 444 445 445 ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); 446 - if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)~0) 446 + if (ret == PCIBIOS_DEVICE_NOT_FOUND || PCI_POSSIBLE_ERROR(slot_status)) 447 447 return -ENODEV; 448 448 449 449 return !!(slot_status & PCI_EXP_SLTSTA_PDS); ··· 621 621 622 622 read_status: 623 623 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &status); 624 - if (status == (u16) ~0) { 624 + if (PCI_POSSIBLE_ERROR(status)) { 625 625 ctrl_info(ctrl, "%s: no response from device\n", __func__); 626 626 if (parent) 627 627 pm_runtime_put(parent);
+5 -5
drivers/pci/pci.c
··· 1115 1115 return -EIO; 1116 1116 1117 1117 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 1118 - if (pmcsr == (u16) ~0) { 1118 + if (PCI_POSSIBLE_ERROR(pmcsr)) { 1119 1119 pci_err(dev, "can't change power state from %s to %s (config space inaccessible)\n", 1120 1120 pci_power_name(dev->current_state), 1121 1121 pci_power_name(state)); ··· 1271 1271 * After reset, the device should not silently discard config 1272 1272 * requests, but it may still indicate that it needs more time by 1273 1273 * responding to them with CRS completions. The Root Port will 1274 - * generally synthesize ~0 data to complete the read (except when 1275 - * CRS SV is enabled and the read was for the Vendor ID; in that 1276 - * case it synthesizes 0x0001 data). 1274 + * generally synthesize ~0 (PCI_ERROR_RESPONSE) data to complete 1275 + * the read (except when CRS SV is enabled and the read was for the 1276 + * Vendor ID; in that case it synthesizes 0x0001 data). 1277 1277 * 1278 1278 * Wait for the device to return a non-CRS completion. Read the 1279 1279 * Command register instead of Vendor ID so we don't have to 1280 1280 * contend with the CRS SV value. 1281 1281 */ 1282 1282 pci_read_config_dword(dev, PCI_COMMAND, &id); 1283 - while (id == ~0) { 1283 + while (PCI_POSSIBLE_ERROR(id)) { 1284 1284 if (delay > timeout) { 1285 1285 pci_warn(dev, "not ready %dms after %s; giving up\n", 1286 1286 delay - 1, reset_type);
+2 -2
drivers/pci/pcie/dpc.c
··· 79 79 u16 status; 80 80 81 81 pci_read_config_word(pdev, pdev->dpc_cap + PCI_EXP_DPC_STATUS, &status); 82 - if ((status != 0xffff) && (status & PCI_EXP_DPC_STATUS_TRIGGER)) 82 + if ((!PCI_POSSIBLE_ERROR(status)) && (status & PCI_EXP_DPC_STATUS_TRIGGER)) 83 83 return false; 84 84 85 85 if (test_bit(PCI_DPC_RECOVERING, &pdev->priv_flags)) ··· 312 312 313 313 pci_read_config_word(pdev, cap + PCI_EXP_DPC_STATUS, &status); 314 314 315 - if (!(status & PCI_EXP_DPC_STATUS_INTERRUPT) || status == (u16)(~0)) 315 + if (!(status & PCI_EXP_DPC_STATUS_INTERRUPT) || PCI_POSSIBLE_ERROR(status)) 316 316 return IRQ_NONE; 317 317 318 318 pci_write_config_word(pdev, cap + PCI_EXP_DPC_STATUS,
+2 -2
drivers/pci/pcie/pme.c
··· 224 224 break; 225 225 226 226 pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); 227 - if (rtsta == (u32) ~0) 227 + if (PCI_POSSIBLE_ERROR(rtsta)) 228 228 break; 229 229 230 230 if (rtsta & PCI_EXP_RTSTA_PME) { ··· 274 274 spin_lock_irqsave(&data->lock, flags); 275 275 pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); 276 276 277 - if (rtsta == (u32) ~0 || !(rtsta & PCI_EXP_RTSTA_PME)) { 277 + if (PCI_POSSIBLE_ERROR(rtsta) || !(rtsta & PCI_EXP_RTSTA_PME)) { 278 278 spin_unlock_irqrestore(&data->lock, flags); 279 279 return IRQ_NONE; 280 280 }
+5 -5
drivers/pci/probe.c
··· 206 206 * memory BAR or a ROM, bit 0 must be clear; if it's an io BAR, bit 207 207 * 1 must be clear. 208 208 */ 209 - if (sz == 0xffffffff) 209 + if (PCI_POSSIBLE_ERROR(sz)) 210 210 sz = 0; 211 211 212 212 /* 213 213 * I don't know how l can have all bits set. Copied from old code. 214 214 * Maybe it fixes a bug on some ancient platform. 215 215 */ 216 - if (l == 0xffffffff) 216 + if (PCI_POSSIBLE_ERROR(l)) 217 217 l = 0; 218 218 219 219 if (type == pci_bar_unknown) { ··· 1675 1675 1676 1676 if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL) 1677 1677 return PCI_CFG_SPACE_SIZE; 1678 - if (status == 0xffffffff || pci_ext_cfg_is_aliased(dev)) 1678 + if (PCI_POSSIBLE_ERROR(status) || pci_ext_cfg_is_aliased(dev)) 1679 1679 return PCI_CFG_SPACE_SIZE; 1680 1680 1681 1681 return PCI_CFG_SPACE_EXP_SIZE; ··· 2363 2363 if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l)) 2364 2364 return false; 2365 2365 2366 - /* Some broken boards return 0 or ~0 if a slot is empty: */ 2367 - if (*l == 0xffffffff || *l == 0x00000000 || 2366 + /* Some broken boards return 0 or ~0 (PCI_ERROR_RESPONSE) if a slot is empty: */ 2367 + if (PCI_POSSIBLE_ERROR(*l) || *l == 0x00000000 || 2368 2368 *l == 0x0000ffff || *l == 0xffff0000) 2369 2369 return false; 2370 2370
+9
include/linux/pci.h
··· 155 155 #define PCI_NUM_INTX 4 156 156 157 157 /* 158 + * Reading from a device that doesn't respond typically returns ~0. A 159 + * successful read from a device may also return ~0, so you need additional 160 + * information to reliably identify errors. 161 + */ 162 + #define PCI_ERROR_RESPONSE (~0ULL) 163 + #define PCI_SET_ERROR_RESPONSE(val) (*(val) = ((typeof(*(val))) PCI_ERROR_RESPONSE)) 164 + #define PCI_POSSIBLE_ERROR(val) ((val) == ((typeof(val)) PCI_ERROR_RESPONSE)) 165 + 166 + /* 158 167 * pci_power_t values must match the bits in the Capabilities PME_Support 159 168 * and Control/Status PowerState fields in the Power Management capability. 160 169 */