Lines Matching +full:cfg +full:- +full:space
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright 2001-2012 IBM Corporation.
32 #include <asm/ppc-pci.h>
34 #include <asm/pte-walk.h>
40 * usual PCI framework, except by check-stopping the CPU. Systems
41 * that are designed for high-availability/reliability cannot afford
43 * An EEH-capable bridge operates by converting a detected error
44 * into a "slot freeze", taking the PCI adapter off-line, making
50 * vibration, humidity, radioactivity or plain-old failed hardware.
55 * device to bus-master data to a memory address that is not
57 * is to prevent devices-gone-wild from corrupting system memory).
58 * Buggy hardware/drivers will have a miserable time co-existing
128 * exported to user space through procfs
164 * This routine captures assorted PCI configuration space data
170 u32 cfg; in eeh_dump_dev_log() local
175 n += scnprintf(buf+n, len-n, "%04x:%02x:%02x.%01x\n", in eeh_dump_dev_log()
176 edev->pe->phb->global_number, edev->bdfn >> 8, in eeh_dump_dev_log()
177 PCI_SLOT(edev->bdfn), PCI_FUNC(edev->bdfn)); in eeh_dump_dev_log()
179 edev->pe->phb->global_number, edev->bdfn >> 8, in eeh_dump_dev_log()
180 PCI_SLOT(edev->bdfn), PCI_FUNC(edev->bdfn)); in eeh_dump_dev_log()
182 eeh_ops->read_config(edev, PCI_VENDOR_ID, 4, &cfg); in eeh_dump_dev_log()
183 n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg); in eeh_dump_dev_log()
184 pr_warn("EEH: PCI device/vendor: %08x\n", cfg); in eeh_dump_dev_log()
186 eeh_ops->read_config(edev, PCI_COMMAND, 4, &cfg); in eeh_dump_dev_log()
187 n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg); in eeh_dump_dev_log()
188 pr_warn("EEH: PCI cmd/status register: %08x\n", cfg); in eeh_dump_dev_log()
190 /* Gather bridge-specific registers */ in eeh_dump_dev_log()
191 if (edev->mode & EEH_DEV_BRIDGE) { in eeh_dump_dev_log()
192 eeh_ops->read_config(edev, PCI_SEC_STATUS, 2, &cfg); in eeh_dump_dev_log()
193 n += scnprintf(buf+n, len-n, "sec stat:%x\n", cfg); in eeh_dump_dev_log()
194 pr_warn("EEH: Bridge secondary status: %04x\n", cfg); in eeh_dump_dev_log()
196 eeh_ops->read_config(edev, PCI_BRIDGE_CONTROL, 2, &cfg); in eeh_dump_dev_log()
197 n += scnprintf(buf+n, len-n, "brdg ctl:%x\n", cfg); in eeh_dump_dev_log()
198 pr_warn("EEH: Bridge control: %04x\n", cfg); in eeh_dump_dev_log()
201 /* Dump out the PCI-X command and status regs */ in eeh_dump_dev_log()
202 cap = edev->pcix_cap; in eeh_dump_dev_log()
204 eeh_ops->read_config(edev, cap, 4, &cfg); in eeh_dump_dev_log()
205 n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg); in eeh_dump_dev_log()
206 pr_warn("EEH: PCI-X cmd: %08x\n", cfg); in eeh_dump_dev_log()
208 eeh_ops->read_config(edev, cap+4, 4, &cfg); in eeh_dump_dev_log()
209 n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg); in eeh_dump_dev_log()
210 pr_warn("EEH: PCI-X status: %08x\n", cfg); in eeh_dump_dev_log()
213 /* If PCI-E capable, dump PCI-E cap 10 */ in eeh_dump_dev_log()
214 cap = edev->pcie_cap; in eeh_dump_dev_log()
216 n += scnprintf(buf+n, len-n, "pci-e cap10:\n"); in eeh_dump_dev_log()
217 pr_warn("EEH: PCI-E capabilities and status follow:\n"); in eeh_dump_dev_log()
220 eeh_ops->read_config(edev, cap+4*i, 4, &cfg); in eeh_dump_dev_log()
221 n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg); in eeh_dump_dev_log()
228 "EEH: PCI-E %02x: %08x ", in eeh_dump_dev_log()
229 4*i, cfg); in eeh_dump_dev_log()
231 l += scnprintf(buffer+l, sizeof(buffer)-l, in eeh_dump_dev_log()
232 "%08x ", cfg); in eeh_dump_dev_log()
241 cap = edev->aer_cap; in eeh_dump_dev_log()
243 n += scnprintf(buf+n, len-n, "pci-e AER:\n"); in eeh_dump_dev_log()
244 pr_warn("EEH: PCI-E AER capability register set follows:\n"); in eeh_dump_dev_log()
247 eeh_ops->read_config(edev, cap+4*i, 4, &cfg); in eeh_dump_dev_log()
248 n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg); in eeh_dump_dev_log()
255 "EEH: PCI-E AER %02x: %08x ", in eeh_dump_dev_log()
256 4*i, cfg); in eeh_dump_dev_log()
258 l += scnprintf(buffer+l, sizeof(buffer)-l, in eeh_dump_dev_log()
259 "%08x ", cfg); in eeh_dump_dev_log()
276 EEH_PCI_REGS_LOG_LEN - *plen); in eeh_dump_pe_log()
282 * eeh_slot_error_detail - Generate combined log including driver log and error log
288 * out from the config space of the corresponding PCI device, while
297 * the data from PCI config space because it should return in eeh_slot_error_detail()
299 * config space. in eeh_slot_error_detail()
302 * 0xFF's is always returned from PCI config space. in eeh_slot_error_detail()
311 if (!(pe->type & EEH_PE_PHB)) { in eeh_slot_error_detail()
317 * The config space of some PCI devices can't be accessed in eeh_slot_error_detail()
326 * pointless to restore BARs and dump config space. in eeh_slot_error_detail()
328 eeh_ops->configure_bridge(pe); in eeh_slot_error_detail()
329 if (!(pe->state & EEH_PE_CFG_BLOCKED)) { in eeh_slot_error_detail()
337 eeh_ops->get_log(pe, severity, pci_regs_buf, loglen); in eeh_slot_error_detail()
341 * eeh_token_to_phys - Convert EEH address token to phys address
364 return -EPERM; in eeh_phb_check_failure()
367 phb_pe = eeh_phb_pe_get(pe->phb); in eeh_phb_check_failure()
370 __func__, pe->phb->global_number); in eeh_phb_check_failure()
371 return -EEXIST; in eeh_phb_check_failure()
376 if (phb_pe->state & EEH_PE_ISOLATED) { in eeh_phb_check_failure()
382 ret = eeh_ops->get_state(phb_pe, NULL); in eeh_phb_check_failure()
394 phb_pe->phb->global_number, eeh_pe_loc_get(phb_pe)); in eeh_phb_check_failure()
405 return dev_driver_string(&pdev->dev); in eeh_driver_name()
411 * eeh_dev_check_failure - Check if all 1's data is due to EEH slot freeze
420 * a non-zero value and queues up a slot isolation event notification.
477 if (pe->state & EEH_PE_ISOLATED) { in eeh_dev_check_failure()
478 pe->check_count++; in eeh_dev_check_failure()
479 if (pe->check_count == EEH_MAX_FAILS) { in eeh_dev_check_failure()
482 location = of_get_property(dn, "ibm,loc-code", in eeh_dev_check_failure()
485 pe->check_count, in eeh_dev_check_failure()
499 * function zero of a multi-function device. in eeh_dev_check_failure()
502 ret = eeh_ops->get_state(pe, NULL); in eeh_dev_check_failure()
504 /* Note that config-io to empty slots may fail; in eeh_dev_check_failure()
513 pe->false_positives++; in eeh_dev_check_failure()
523 parent_pe = pe->parent; in eeh_dev_check_failure()
526 if (parent_pe->type & EEH_PE_PHB) in eeh_dev_check_failure()
530 ret = eeh_ops->get_state(parent_pe, NULL); in eeh_dev_check_failure()
533 pr_err("EEH: Failure of PHB#%x-PE#%x will be handled at parent PHB#%x-PE#%x.\n", in eeh_dev_check_failure()
534 pe->phb->global_number, pe->addr, in eeh_dev_check_failure()
535 pe->phb->global_number, parent_pe->addr); in eeh_dev_check_failure()
539 parent_pe = parent_pe->parent; in eeh_dev_check_failure()
552 * a stack trace will help the device-driver authors figure in eeh_dev_check_failure()
555 pr_debug("EEH: %s: Frozen PHB#%x-PE#%x detected\n", in eeh_dev_check_failure()
556 __func__, pe->phb->global_number, pe->addr); in eeh_dev_check_failure()
569 * eeh_check_failure - Check if all 1's data is due to EEH slot freeze
598 * eeh_pci_enable - Enable MMIO or DMA transfers for this slot
630 return -EINVAL; in eeh_pci_enable()
638 rc = eeh_ops->get_state(pe, NULL); in eeh_pci_enable()
653 rc = eeh_ops->set_option(pe, function); in eeh_pci_enable()
656 "PHB#%x-PE#%x, err=%d\n", in eeh_pci_enable()
657 __func__, function, pe->phb->global_number, in eeh_pci_enable()
658 pe->addr, rc); in eeh_pci_enable()
669 return -EIO; in eeh_pci_enable()
710 if (eeh_ops->restore_config) in eeh_restore_dev_state()
711 eeh_ops->restore_config(edev); in eeh_restore_dev_state()
719 * pcibios_set_pcie_reset_state - Set PCI-E reset state
734 return -EINVAL; in pcibios_set_pcie_reset_state()
739 eeh_ops->reset(pe, EEH_RESET_DEACTIVATE); in pcibios_set_pcie_reset_state()
741 if (!(pe->type & EEH_PE_VF)) in pcibios_set_pcie_reset_state()
749 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE); in pcibios_set_pcie_reset_state()
751 if (!(pe->type & EEH_PE_VF)) in pcibios_set_pcie_reset_state()
753 eeh_ops->reset(pe, EEH_RESET_HOT); in pcibios_set_pcie_reset_state()
758 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE); in pcibios_set_pcie_reset_state()
760 if (!(pe->type & EEH_PE_VF)) in pcibios_set_pcie_reset_state()
762 eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL); in pcibios_set_pcie_reset_state()
766 return -EINVAL; in pcibios_set_pcie_reset_state()
773 * eeh_set_dev_freset - Check the required reset for the indicated device
789 *freset |= dev->needs_freset; in eeh_set_dev_freset()
799 state = eeh_ops->get_state(pe, NULL); in eeh_pe_refreeze_passed()
802 pr_info("EEH: Passed-through PE PHB#%x-PE#%x was thawed by reset, re-freezing for safety.\n", in eeh_pe_refreeze_passed()
803 pe->phb->global_number, pe->addr); in eeh_pe_refreeze_passed()
811 * eeh_pe_reset_full - Complete a full reset process on the indicated PE
813 * @include_passed: include passed-through devices?
831 * Determine the type of reset to perform - hot or fundamental. in eeh_pe_reset_full()
840 /* Mark the PE as in reset state and block config space accesses */ in eeh_pe_reset_full()
850 ret = -EIO; in eeh_pe_reset_full()
851 pr_warn("EEH: Failure %d resetting PHB#%x-PE#%x (attempt %d)\n\n", in eeh_pe_reset_full()
852 state, pe->phb->global_number, pe->addr, i + 1); in eeh_pe_reset_full()
856 pr_warn("EEH: PHB#%x-PE#%x: Successful reset (attempt %d)\n", in eeh_pe_reset_full()
857 pe->phb->global_number, pe->addr, i + 1); in eeh_pe_reset_full()
862 pr_warn("EEH: Unrecoverable slot failure on PHB#%x-PE#%x", in eeh_pe_reset_full()
863 pe->phb->global_number, pe->addr); in eeh_pe_reset_full()
864 ret = -ENOTRECOVERABLE; in eeh_pe_reset_full()
870 pr_warn("EEH: PHB#%x-PE#%x: Slot inactive after reset: 0x%x (attempt %d)\n", in eeh_pe_reset_full()
871 pe->phb->global_number, pe->addr, state, i + 1); in eeh_pe_reset_full()
875 * (potentially) passed through to a guest, re-freeze them: in eeh_pe_reset_full()
885 * eeh_save_bars - Save device bars
901 eeh_ops->read_config(edev, i * 4, 4, &edev->config_space[i]); in eeh_save_bars()
909 if (edev->mode & EEH_DEV_BRIDGE) in eeh_save_bars()
910 edev->config_space[1] |= PCI_COMMAND_MASTER; in eeh_save_bars()
949 * eeh_init - System wide EEH initialization
961 return -EEXIST; in eeh_init()
963 return -ENOENT; in eeh_init()
992 * eeh_probe_device() - Perform EEH initialization for the indicated pci device
1013 edev = eeh_ops->probe(dev); in eeh_probe_device()
1028 if (edev->pdev && edev->pdev != dev) { in eeh_probe_device()
1030 eeh_addr_cache_rmv_dev(edev->pdev); in eeh_probe_device()
1031 eeh_sysfs_remove_device(edev->pdev); in eeh_probe_device()
1038 edev->mode |= EEH_DEV_NO_HANDLER; in eeh_probe_device()
1042 edev->pdev = dev; in eeh_probe_device()
1043 dev->dev.archdata.edev = edev; in eeh_probe_device()
1049 * eeh_remove_device - Undo EEH setup for the indicated pci device
1067 dev_dbg(&dev->dev, "EEH: Removing device\n"); in eeh_remove_device()
1069 if (!edev || !edev->pdev || !edev->pe) { in eeh_remove_device()
1070 dev_dbg(&dev->dev, "EEH: Device not referenced!\n"); in eeh_remove_device()
1080 edev->pdev = NULL; in eeh_remove_device()
1086 if (edev->mode & EEH_DEV_SYSFS) in eeh_remove_device()
1095 edev->mode |= EEH_DEV_NO_HANDLER; in eeh_remove_device()
1105 edev->in_error = false; in eeh_remove_device()
1106 dev->dev.archdata.edev = NULL; in eeh_remove_device()
1107 if (!(edev->pe->state & EEH_PE_KEEP)) in eeh_remove_device()
1110 edev->mode |= EEH_DEV_DISCONNECTED; in eeh_remove_device()
1119 pr_warn("%s: Failure %d enabling IO on PHB#%x-PE#%x\n", in eeh_unfreeze_pe()
1120 __func__, ret, pe->phb->global_number, pe->addr); in eeh_unfreeze_pe()
1126 pr_warn("%s: Failure %d enabling DMA on PHB#%x-PE#%x\n", in eeh_unfreeze_pe()
1127 __func__, ret, pe->phb->global_number, pe->addr); in eeh_unfreeze_pe()
1150 ret = eeh_ops->get_state(pe, NULL); in eeh_pe_change_owner()
1164 for (id = &eeh_reset_ids[0]; id->vendor != 0; id++) { in eeh_pe_change_owner()
1165 if (id->vendor != PCI_ANY_ID && in eeh_pe_change_owner()
1166 id->vendor != pdev->vendor) in eeh_pe_change_owner()
1168 if (id->device != PCI_ANY_ID && in eeh_pe_change_owner()
1169 id->device != pdev->device) in eeh_pe_change_owner()
1171 if (id->subvendor != PCI_ANY_ID && in eeh_pe_change_owner()
1172 id->subvendor != pdev->subsystem_vendor) in eeh_pe_change_owner()
1174 if (id->subdevice != PCI_ANY_ID && in eeh_pe_change_owner()
1175 id->subdevice != pdev->subsystem_device) in eeh_pe_change_owner()
1189 * eeh_dev_open - Increase count of pass through devices for PE
1200 int ret = -ENODEV; in eeh_dev_open()
1210 if (!edev || !edev->pe) in eeh_dev_open()
1219 ret = eeh_pe_change_owner(edev->pe); in eeh_dev_open()
1224 atomic_inc(&edev->pe->pass_dev_cnt); in eeh_dev_open()
1235 * eeh_dev_release - Decrease count of pass through devices for PE
1254 if (!edev || !edev->pe || !eeh_pe_passed(edev->pe)) in eeh_dev_release()
1258 WARN_ON(atomic_dec_if_positive(&edev->pe->pass_dev_cnt) < 0); in eeh_dev_release()
1259 eeh_pe_change_owner(edev->pe); in eeh_dev_release()
1284 * eeh_iommu_group_to_pe - Convert IOMMU group to EEH PE
1305 if (!edev || !edev->pe) in eeh_iommu_group_to_pe()
1308 return edev->pe; in eeh_iommu_group_to_pe()
1315 * eeh_pe_set_option - Set options for the indicated PE
1328 return -ENODEV; in eeh_pe_set_option()
1341 ret = -EIO; in eeh_pe_set_option()
1348 if (!eeh_ops || !eeh_ops->set_option) { in eeh_pe_set_option()
1349 ret = -ENOENT; in eeh_pe_set_option()
1358 ret = -EINVAL; in eeh_pe_set_option()
1366 * eeh_pe_get_state - Retrieve PE's state
1379 return -ENODEV; in eeh_pe_get_state()
1381 if (!eeh_ops || !eeh_ops->get_state) in eeh_pe_get_state()
1382 return -ENOENT; in eeh_pe_get_state()
1390 if (pe->parent && in eeh_pe_get_state()
1391 !(pe->state & EEH_PE_REMOVED) && in eeh_pe_get_state()
1392 (pe->parent->state & (EEH_PE_ISOLATED | EEH_PE_RECOVERING))) in eeh_pe_get_state()
1395 result = eeh_ops->get_state(pe, NULL); in eeh_pe_get_state()
1444 pr_info("EEH: Note: Leaving passthrough PHB#%x-PE#%x frozen.\n", in eeh_pe_reenable_devices()
1445 pe->phb->global_number, pe->addr); in eeh_pe_reenable_devices()
1453 * eeh_pe_reset - Issue PE reset according to specified type
1456 * @include_passed: include passed-through devices?
1468 return -ENODEV; in eeh_pe_reset()
1470 if (!eeh_ops || !eeh_ops->set_option || !eeh_ops->reset) in eeh_pe_reset()
1471 return -ENOENT; in eeh_pe_reset()
1475 ret = eeh_ops->reset(pe, option); in eeh_pe_reset()
1489 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE); in eeh_pe_reset()
1492 ret = eeh_ops->reset(pe, option); in eeh_pe_reset()
1497 ret = -EINVAL; in eeh_pe_reset()
1505 * eeh_pe_configure - Configure PCI bridges after PE reset
1508 * The routine is called to restore the PCI config space for
1518 return -ENODEV; in eeh_pe_configure()
1525 * eeh_pe_inject_err - Injecting the specified PCI error to the indicated PE
1541 return -ENODEV; in eeh_pe_inject_err()
1544 if (!eeh_ops || !eeh_ops->err_inject) in eeh_pe_inject_err()
1545 return -ENOENT; in eeh_pe_inject_err()
1549 return -EINVAL; in eeh_pe_inject_err()
1553 return -EINVAL; in eeh_pe_inject_err()
1555 return eeh_ops->err_inject(pe, type, func, addr, mask); in eeh_pe_inject_err()
1601 ret = simple_write_to_buffer(buf, sizeof(buf)-1, ppos, user_buf, count); in eeh_debug_lookup_pdev()
1603 return ERR_PTR(-EFAULT); in eeh_debug_lookup_pdev()
1608 return ERR_PTR(-EINVAL); in eeh_debug_lookup_pdev()
1613 return ERR_PTR(-ENODEV); in eeh_debug_lookup_pdev()
1652 return -EFAULT; in eeh_force_recover_write()
1667 return -EINVAL; in eeh_force_recover_write()
1671 return -ENODEV; in eeh_force_recover_write()
1676 return -ENODEV; in eeh_force_recover_write()
1683 * non-isolated PE) in eeh_force_recover_write()
1703 usage, sizeof(usage) - 1); in eeh_debugfs_dev_usage()
1722 return -ENODEV; in eeh_dev_check_write()
1750 struct resource *r = &pdev->resource[i]; in eeh_debugfs_break_device()
1752 if (!r->flags || !r->start) in eeh_debugfs_break_device()
1754 if (r->flags & IORESOURCE_IO) in eeh_debugfs_break_device()
1756 if (r->flags & IORESOURCE_UNSET) in eeh_debugfs_break_device()
1765 return -ENXIO; in eeh_debugfs_break_device()
1770 if (pdev->is_virtfn) { in eeh_debugfs_break_device()
1772 return -ENXIO; in eeh_debugfs_break_device()
1775 * VFs don't have a per-function COMMAND register, so the best in eeh_debugfs_break_device()
1776 * we can do is clear the Memory Space Enable bit in the PF's in eeh_debugfs_break_device()
1780 * work for a passed-through VF) and it has the potential side in eeh_debugfs_break_device()
1784 pdev = pdev->physfn; in eeh_debugfs_break_device()
1786 return -ENXIO; /* passed through VFs have no PF */ in eeh_debugfs_break_device()
1800 * 1. Disable Memory space. in eeh_debugfs_break_device()
1810 * 3. Turn Memory space back on. This is more important for VFs in eeh_debugfs_break_device()
1812 * the COMMAND register is reset as a part of re-initialising in eeh_debugfs_break_device()
1819 mapped = ioremap(bar->start, PAGE_SIZE); in eeh_debugfs_break_device()
1822 return -ENXIO; in eeh_debugfs_break_device()
1876 * .slot_reset() so it can re-initialise the device after a reset. in eeh_dev_can_recover()
1882 * .mmio_enabled() is mostly there as a work-around for devices which in eeh_dev_can_recover()
1883 * take forever to re-init after a hot reset. Implementing that is in eeh_dev_can_recover()
1888 drv->err_handler && in eeh_dev_can_recover()
1889 drv->err_handler->error_detected && in eeh_dev_can_recover()
1890 drv->err_handler->slot_reset) { in eeh_dev_can_recover()
1893 ret = -EOPNOTSUPP; in eeh_dev_can_recover()