25 #include <linux/sched.h>
27 #include <linux/list.h>
28 #include <linux/pci.h>
30 #include <linux/rbtree.h>
33 #include <linux/export.h>
40 #include <asm/machdep.h>
84 #define EEH_MAX_FAILS 2100000
87 #define PCI_BUS_RESET_WAIT_MSEC (60*1000)
116 #define EEH_PCI_REGS_LOG_LEN 4096
136 #define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)
147 static size_t eeh_gather_pci_data(
struct eeh_dev *edev,
char *
buf,
size_t len)
150 struct pci_dev *
dev = eeh_dev_to_pci_dev(edev);
159 n +=
scnprintf(buf+n, len-n,
"dev/vend:%08x\n", cfg);
163 n +=
scnprintf(buf+n, len-n,
"cmd/stat:%x\n", cfg);
174 n +=
scnprintf(buf+n, len-n,
"sec stat:%x\n", cfg);
178 n +=
scnprintf(buf+n, len-n,
"brdg ctl:%x\n", cfg);
185 eeh_ops->read_config(dn, cap, 4, &cfg);
186 n +=
scnprintf(buf+n, len-n,
"pcix-cmd:%x\n", cfg);
189 eeh_ops->read_config(dn, cap+4, 4, &cfg);
190 n +=
scnprintf(buf+n, len-n,
"pcix-stat:%x\n", cfg);
197 n +=
scnprintf(buf+n, len-n,
"pci-e cap10:\n");
199 "EEH: PCI-E capabilities and status follow:\n");
201 for (i=0; i<=8; i++) {
202 eeh_ops->read_config(dn, cap+4*i, 4, &cfg);
203 n +=
scnprintf(buf+n, len-n,
"%02x:%x\n", 4*i, cfg);
209 n +=
scnprintf(buf+n, len-n,
"pci-e AER:\n");
211 "EEH: PCI-E AER capability register set follows:\n");
213 for (i=0; i<14; i++) {
214 eeh_ops->read_config(dn, cap+4*i, 4, &cfg);
215 n +=
scnprintf(buf+n, len-n,
"%02x:%x\n", 4*i, cfg);
237 struct eeh_dev *edev;
244 eeh_pe_for_each_dev(pe, edev) {
245 loglen += eeh_gather_pci_data(edev, pci_regs_buf,
249 eeh_ops->get_log(pe, severity, pci_regs_buf, loglen);
259 static inline unsigned long eeh_token_to_phys(
unsigned long token)
264 ptep = find_linux_pte(
init_mm.pgd, token);
305 dn = eeh_dev_to_of_node(edev);
306 dev = eeh_dev_to_pci_dev(edev);
312 pr_debug(
"EEH: Ignored check for %s %s\n",
317 if (!pe->addr && !pe->config_addr) {
330 if (pe->state & EEH_PE_ISOLATED) {
335 "location=%s driver=%s pci addr=%s\n",
336 pe->check_count, location,
337 eeh_driver_name(dev), eeh_pci_name(dev));
339 eeh_driver_name(dev));
361 (ret == EEH_STATE_NOT_SUPPORT) ||
362 (ret & (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE)) ==
363 (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE)) {
365 pe->false_positives++;
385 WARN(1,
"EEH: failure detected\n");
410 struct eeh_dev *edev;
413 addr = eeh_token_to_phys((
unsigned long __force) token);
441 rc =
eeh_ops->set_option(pe,
function);
443 pr_warning(
"%s: Unexpected state change %d on PHB#%d-PE#%x, err=%d\n",
444 __func__,
function, pe->phb->global_number, pe->addr, rc);
447 if (rc > 0 && (rc & EEH_STATE_MMIO_ENABLED) &&
448 (
function == EEH_OPT_THAW_MMIO))
464 struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
465 struct eeh_pe *pe = edev->pe;
468 pr_err(
"%s: No PE found on PCI device %s\n",
469 __func__, pci_name(dev));
475 eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
478 eeh_ops->reset(pe, EEH_RESET_HOT);
481 eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
500 static void *eeh_set_dev_freset(
void *
data,
void *
flag)
503 unsigned int *freset = (
unsigned int *)flag;
504 struct eeh_dev *edev = (
struct eeh_dev *)data;
506 dev = eeh_dev_to_pci_dev(edev);
519 static void eeh_reset_pe_once(
struct eeh_pe *pe)
521 unsigned int freset = 0;
532 eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
534 eeh_ops->reset(pe, EEH_RESET_HOT);
539 #define PCI_BUS_RST_HOLD_TIME_MSEC 250
540 msleep(PCI_BUS_RST_HOLD_TIME_MSEC);
548 eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
554 #define PCI_BUS_SETTLE_TIME_MSEC 1800
555 msleep(PCI_BUS_SETTLE_TIME_MSEC);
571 for (i=0; i<3; i++) {
572 eeh_reset_pe_once(pe);
575 if (rc == (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE))
579 pr_err(
"%s: Unrecoverable slot failure on PHB#%d-PE#%x",
580 __func__, pe->phb->global_number, pe->addr);
583 pr_err(
"EEH: bus reset %d failed on PHB#%d-PE#%x, rc=%d\n",
584 i+1, pe->phb->global_number, pe->addr, rc);
606 dn = eeh_dev_to_of_node(edev);
608 for (i = 0; i < 16; i++)
609 eeh_ops->read_config(dn, i * 4, 4, &edev->config_space[i]);
623 pr_warning(
"%s: Invalid EEH ops name for %p\n",
629 pr_warning(
"%s: EEH ops of platform %s already existing (%s)\n",
630 __func__,
eeh_ops->name, ops->name);
648 if (!name || !
strlen(name)) {
677 static int __init eeh_init(
void)
685 pr_warning(
"%s: Platform EEH operation not found\n",
688 }
else if ((ret =
eeh_ops->init())) {
689 pr_warning(
"%s: Failed to call platform init function (%d)\n",
697 if (eeh_probe_mode_devtree()) {
699 &hose_list, list_node) {
706 pr_info(
"EEH: PCI Enhanced I/O Error Handling Enabled\n");
708 pr_warning(
"EEH: No capable adapters found\n");
731 if (!of_node_to_eeh_dev(dn))
733 phb = of_node_to_eeh_dev(dn)->phb;
736 if (
NULL == phb || 0 == phb->buid)
757 eeh_add_device_early(dn);
768 static void eeh_add_device_late(
struct pci_dev *dev)
771 struct eeh_dev *edev;
776 pr_debug(
"EEH: Adding device %s\n", pci_name(dev));
778 dn = pci_device_to_OF_node(dev);
779 edev = of_node_to_eeh_dev(dn);
780 if (edev->pdev == dev) {
781 pr_debug(
"EEH: Already referenced !\n");
788 dev->
dev.archdata.edev = edev;
807 eeh_add_device_late(dev);
828 static void eeh_remove_device(
struct pci_dev *dev,
int purge_pe)
830 struct eeh_dev *edev;
834 edev = pci_dev_to_eeh_dev(dev);
837 pr_debug(
"EEH: Removing device %s\n", pci_name(dev));
839 if (!edev || !edev->pdev) {
840 pr_debug(
"EEH: Not referenced !\n");
866 eeh_remove_device(dev, purge_pe);
875 static int proc_eeh_show(
struct seq_file *
m,
void *
v)
878 seq_printf(m,
"EEH Subsystem is globally disabled\n");
884 "no device node=%llu\n"
885 "no config address=%llu\n"
886 "check not wanted=%llu\n"
887 "eeh_total_mmio_ffs=%llu\n"
888 "eeh_false_positives=%llu\n"
889 "eeh_slot_resets=%llu\n",
908 .open = proc_eeh_open,
914 static int __init eeh_init_proc(
void)
916 if (machine_is(pseries))
917 proc_create(
"powerpc/eeh", 0,
NULL, &proc_eeh_operations);