1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PowerNV Platform dependent EEH operations
5 * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2013.
8 #include <linux/atomic.h>
9 #include <linux/debugfs.h>
10 #include <linux/delay.h>
11 #include <linux/export.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/irqdomain.h>
15 #include <linux/list.h>
16 #include <linux/msi.h>
18 #include <linux/pci.h>
19 #include <linux/proc_fs.h>
20 #include <linux/rbtree.h>
21 #include <linux/sched.h>
22 #include <linux/seq_file.h>
23 #include <linux/spinlock.h>
26 #include <asm/eeh_event.h>
27 #include <asm/firmware.h>
29 #include <asm/iommu.h>
30 #include <asm/machdep.h>
31 #include <asm/msi_bitmap.h>
33 #include <asm/ppc-pci.h>
34 #include <asm/pnv-pci.h>
38 #include "../../../../drivers/pci/pci.h"
40 static int eeh_event_irq = -EINVAL;
42 static void pnv_pcibios_bus_add_device(struct pci_dev *pdev)
44 dev_dbg(&pdev->dev, "EEH: Setting up device\n");
45 eeh_probe_device(pdev);
48 static irqreturn_t pnv_eeh_event(int irq, void *data)
51 * We simply send a special EEH event if EEH has been
52 * enabled. We don't care about EEH events until we've
53 * finished processing the outstanding ones. Event processing
54 * gets unmasked in next_error() if EEH is enabled.
56 disable_irq_nosync(irq);
59 eeh_send_failure_event(NULL);
64 #ifdef CONFIG_DEBUG_FS
65 static ssize_t pnv_eeh_ei_write(struct file *filp,
66 const char __user *user_buf,
67 size_t count, loff_t *ppos)
69 struct pci_controller *hose = filp->private_data;
71 int pe_no, type, func;
72 unsigned long addr, mask;
76 if (!eeh_ops || !eeh_ops->err_inject)
79 /* Copy over argument buffer */
80 ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
84 /* Retrieve parameters */
85 ret = sscanf(buf, "%x:%x:%x:%lx:%lx",
86 &pe_no, &type, &func, &addr, &mask);
91 pe = eeh_pe_get(hose, pe_no);
95 /* Do error injection */
96 ret = eeh_ops->err_inject(pe, type, func, addr, mask);
97 return ret < 0 ? ret : count;
100 static const struct file_operations pnv_eeh_ei_fops = {
103 .write = pnv_eeh_ei_write,
106 static int pnv_eeh_dbgfs_set(void *data, int offset, u64 val)
108 struct pci_controller *hose = data;
109 struct pnv_phb *phb = hose->private_data;
111 out_be64(phb->regs + offset, val);
115 static int pnv_eeh_dbgfs_get(void *data, int offset, u64 *val)
117 struct pci_controller *hose = data;
118 struct pnv_phb *phb = hose->private_data;
120 *val = in_be64(phb->regs + offset);
124 #define PNV_EEH_DBGFS_ENTRY(name, reg) \
125 static int pnv_eeh_dbgfs_set_##name(void *data, u64 val) \
127 return pnv_eeh_dbgfs_set(data, reg, val); \
130 static int pnv_eeh_dbgfs_get_##name(void *data, u64 *val) \
132 return pnv_eeh_dbgfs_get(data, reg, val); \
135 DEFINE_SIMPLE_ATTRIBUTE(pnv_eeh_dbgfs_ops_##name, \
136 pnv_eeh_dbgfs_get_##name, \
137 pnv_eeh_dbgfs_set_##name, \
140 PNV_EEH_DBGFS_ENTRY(outb, 0xD10);
141 PNV_EEH_DBGFS_ENTRY(inbA, 0xD90);
142 PNV_EEH_DBGFS_ENTRY(inbB, 0xE10);
144 #endif /* CONFIG_DEBUG_FS */
146 static void pnv_eeh_enable_phbs(void)
148 struct pci_controller *hose;
151 list_for_each_entry(hose, &hose_list, list_node) {
152 phb = hose->private_data;
154 * If EEH is enabled, we're going to rely on that.
155 * Otherwise, we restore to conventional mechanism
156 * to clear frozen PE during PCI config access.
159 phb->flags |= PNV_PHB_FLAG_EEH;
161 phb->flags &= ~PNV_PHB_FLAG_EEH;
166 * pnv_eeh_post_init - EEH platform dependent post initialization
168 * EEH platform dependent post initialization on powernv. When
169 * the function is called, the EEH PEs and devices should have
170 * been built. If the I/O cache staff has been built, EEH is
171 * ready to supply service.
173 int pnv_eeh_post_init(void)
175 struct pci_controller *hose;
181 /* Register OPAL event notifier */
182 eeh_event_irq = opal_event_request(ilog2(OPAL_EVENT_PCI_ERROR));
183 if (eeh_event_irq < 0) {
184 pr_err("%s: Can't register OPAL event interrupt (%d)\n",
185 __func__, eeh_event_irq);
186 return eeh_event_irq;
189 ret = request_irq(eeh_event_irq, pnv_eeh_event,
190 IRQ_TYPE_LEVEL_HIGH, "opal-eeh", NULL);
192 irq_dispose_mapping(eeh_event_irq);
193 pr_err("%s: Can't request OPAL event interrupt (%d)\n",
194 __func__, eeh_event_irq);
199 disable_irq(eeh_event_irq);
201 pnv_eeh_enable_phbs();
203 list_for_each_entry(hose, &hose_list, list_node) {
204 phb = hose->private_data;
206 /* Create debugfs entries */
207 #ifdef CONFIG_DEBUG_FS
208 if (phb->has_dbgfs || !phb->dbgfs)
212 debugfs_create_file("err_injct", 0200,
216 debugfs_create_file("err_injct_outbound", 0600,
218 &pnv_eeh_dbgfs_ops_outb);
219 debugfs_create_file("err_injct_inboundA", 0600,
221 &pnv_eeh_dbgfs_ops_inbA);
222 debugfs_create_file("err_injct_inboundB", 0600,
224 &pnv_eeh_dbgfs_ops_inbB);
225 #endif /* CONFIG_DEBUG_FS */
231 static int pnv_eeh_find_cap(struct pci_dn *pdn, int cap)
233 int pos = PCI_CAPABILITY_LIST;
234 int cnt = 48; /* Maximal number of capabilities */
240 /* Check if the device supports capabilities */
241 pnv_pci_cfg_read(pdn, PCI_STATUS, 2, &status);
242 if (!(status & PCI_STATUS_CAP_LIST))
246 pnv_pci_cfg_read(pdn, pos, 1, &pos);
251 pnv_pci_cfg_read(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
260 pos += PCI_CAP_LIST_NEXT;
266 static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
268 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
270 int pos = 256, ttl = (4096 - 256) / 8;
272 if (!edev || !edev->pcie_cap)
274 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
280 if (PCI_EXT_CAP_ID(header) == cap && pos)
283 pos = PCI_EXT_CAP_NEXT(header);
287 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
294 static struct eeh_pe *pnv_eeh_get_upstream_pe(struct pci_dev *pdev)
296 struct pci_controller *hose = pdev->bus->sysdata;
297 struct pnv_phb *phb = hose->private_data;
298 struct pci_dev *parent = pdev->bus->self;
300 #ifdef CONFIG_PCI_IOV
301 /* for VFs we use the PF's PE as the upstream PE */
303 parent = pdev->physfn;
306 /* otherwise use the PE of our parent bridge */
308 struct pnv_ioda_pe *ioda_pe = pnv_ioda_get_pe(parent);
310 return eeh_pe_get(phb->hose, ioda_pe->pe_number);
317 * pnv_eeh_probe - Do probe on PCI device
318 * @pdev: pci_dev to probe
320 * Create, or find the existing, eeh_dev for this pci_dev.
322 static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
324 struct pci_dn *pdn = pci_get_pdn(pdev);
325 struct pci_controller *hose = pdn->phb;
326 struct pnv_phb *phb = hose->private_data;
327 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
328 struct eeh_pe *upstream_pe;
331 int config_addr = (pdn->busno << 8) | (pdn->devfn);
334 * When probing the root bridge, which doesn't have any
335 * subordinate PCI devices. We don't have OF node for
336 * the root bridge. So it's not reasonable to continue
339 if (!edev || edev->pe)
342 /* already configured? */
344 pr_debug("%s: found existing edev for %04x:%02x:%02x.%01x\n",
345 __func__, hose->global_number, config_addr >> 8,
346 PCI_SLOT(config_addr), PCI_FUNC(config_addr));
350 /* Skip for PCI-ISA bridge */
351 if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
354 eeh_edev_dbg(edev, "Probing device\n");
356 /* Initialize eeh device */
357 edev->mode &= 0xFFFFFF00;
358 edev->pcix_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
359 edev->pcie_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
360 edev->af_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_AF);
361 edev->aer_cap = pnv_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
362 if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
363 edev->mode |= EEH_DEV_BRIDGE;
364 if (edev->pcie_cap) {
365 pnv_pci_cfg_read(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
367 pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
368 if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
369 edev->mode |= EEH_DEV_ROOT_PORT;
370 else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
371 edev->mode |= EEH_DEV_DS_PORT;
375 edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
377 upstream_pe = pnv_eeh_get_upstream_pe(pdev);
380 ret = eeh_pe_tree_insert(edev, upstream_pe);
382 eeh_edev_warn(edev, "Failed to add device to PE (code %d)\n", ret);
387 * If the PE contains any one of following adapters, the
388 * PCI config space can't be accessed when dumping EEH log.
389 * Otherwise, we will run into fenced PHB caused by shortage
390 * of outbound credits in the adapter. The PCI config access
391 * should be blocked until PE reset. MMIO access is dropped
392 * by hardware certainly. In order to drop PCI config requests,
393 * one more flag (EEH_PE_CFG_RESTRICTED) is introduced, which
394 * will be checked in the backend for PE state retrieval. If
395 * the PE becomes frozen for the first time and the flag has
396 * been set for the PE, we will set EEH_PE_CFG_BLOCKED for
397 * that PE to block its config space.
399 * Broadcom BCM5718 2-ports NICs (14e4:1656)
400 * Broadcom Austin 4-ports NICs (14e4:1657)
401 * Broadcom Shiner 4-ports 1G NICs (14e4:168a)
402 * Broadcom Shiner 2-ports 10G NICs (14e4:168e)
404 if ((pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
405 pdn->device_id == 0x1656) ||
406 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
407 pdn->device_id == 0x1657) ||
408 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
409 pdn->device_id == 0x168a) ||
410 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
411 pdn->device_id == 0x168e))
412 edev->pe->state |= EEH_PE_CFG_RESTRICTED;
415 * Cache the PE primary bus, which can't be fetched when
416 * full hotplug is in progress. In that case, all child
417 * PCI devices of the PE are expected to be removed prior
420 if (!(edev->pe->state & EEH_PE_PRI_BUS)) {
421 edev->pe->bus = pci_find_bus(hose->global_number,
424 edev->pe->state |= EEH_PE_PRI_BUS;
428 * Enable EEH explicitly so that we will do EEH check
429 * while accessing I/O stuff
431 if (!eeh_has_flag(EEH_ENABLED)) {
432 enable_irq(eeh_event_irq);
433 pnv_eeh_enable_phbs();
434 eeh_add_flag(EEH_ENABLED);
437 /* Save memory bars */
440 eeh_edev_dbg(edev, "EEH enabled on device\n");
446 * pnv_eeh_set_option - Initialize EEH or MMIO/DMA reenable
448 * @option: operation to be issued
450 * The function is used to control the EEH functionality globally.
451 * Currently, following options are support according to PAPR:
452 * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
454 static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
456 struct pci_controller *hose = pe->phb;
457 struct pnv_phb *phb = hose->private_data;
458 bool freeze_pe = false;
463 case EEH_OPT_DISABLE:
467 case EEH_OPT_THAW_MMIO:
468 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO;
470 case EEH_OPT_THAW_DMA:
471 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_DMA;
473 case EEH_OPT_FREEZE_PE:
475 opt = OPAL_EEH_ACTION_SET_FREEZE_ALL;
478 pr_warn("%s: Invalid option %d\n", __func__, option);
482 /* Freeze master and slave PEs if PHB supports compound PEs */
484 if (phb->freeze_pe) {
485 phb->freeze_pe(phb, pe->addr);
489 rc = opal_pci_eeh_freeze_set(phb->opal_id, pe->addr, opt);
490 if (rc != OPAL_SUCCESS) {
491 pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",
492 __func__, rc, phb->hose->global_number,
500 /* Unfreeze master and slave PEs if PHB supports */
501 if (phb->unfreeze_pe)
502 return phb->unfreeze_pe(phb, pe->addr, opt);
504 rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe->addr, opt);
505 if (rc != OPAL_SUCCESS) {
506 pr_warn("%s: Failure %lld enable %d for PHB#%x-PE#%x\n",
507 __func__, rc, option, phb->hose->global_number,
515 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
517 struct pnv_phb *phb = pe->phb->private_data;
520 rc = opal_pci_get_phb_diag_data2(phb->opal_id, pe->data,
521 phb->diag_data_size);
522 if (rc != OPAL_SUCCESS)
523 pr_warn("%s: Failure %lld getting PHB#%x diag-data\n",
524 __func__, rc, pe->phb->global_number);
527 static int pnv_eeh_get_phb_state(struct eeh_pe *pe)
529 struct pnv_phb *phb = pe->phb->private_data;
535 rc = opal_pci_eeh_freeze_status(phb->opal_id,
540 if (rc != OPAL_SUCCESS) {
541 pr_warn("%s: Failure %lld getting PHB#%x state\n",
542 __func__, rc, phb->hose->global_number);
543 return EEH_STATE_NOT_SUPPORT;
547 * Check PHB state. If the PHB is frozen for the
548 * first time, to dump the PHB diag-data.
550 if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
551 result = (EEH_STATE_MMIO_ACTIVE |
552 EEH_STATE_DMA_ACTIVE |
553 EEH_STATE_MMIO_ENABLED |
554 EEH_STATE_DMA_ENABLED);
555 } else if (!(pe->state & EEH_PE_ISOLATED)) {
556 eeh_pe_mark_isolated(pe);
557 pnv_eeh_get_phb_diag(pe);
559 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
560 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
566 static int pnv_eeh_get_pe_state(struct eeh_pe *pe)
568 struct pnv_phb *phb = pe->phb->private_data;
575 * We don't clobber hardware frozen state until PE
576 * reset is completed. In order to keep EEH core
577 * moving forward, we have to return operational
578 * state during PE reset.
580 if (pe->state & EEH_PE_RESET) {
581 result = (EEH_STATE_MMIO_ACTIVE |
582 EEH_STATE_DMA_ACTIVE |
583 EEH_STATE_MMIO_ENABLED |
584 EEH_STATE_DMA_ENABLED);
589 * Fetch PE state from hardware. If the PHB
590 * supports compound PE, let it handle that.
592 if (phb->get_pe_state) {
593 fstate = phb->get_pe_state(phb, pe->addr);
595 rc = opal_pci_eeh_freeze_status(phb->opal_id,
600 if (rc != OPAL_SUCCESS) {
601 pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
602 __func__, rc, phb->hose->global_number,
604 return EEH_STATE_NOT_SUPPORT;
608 /* Figure out state */
610 case OPAL_EEH_STOPPED_NOT_FROZEN:
611 result = (EEH_STATE_MMIO_ACTIVE |
612 EEH_STATE_DMA_ACTIVE |
613 EEH_STATE_MMIO_ENABLED |
614 EEH_STATE_DMA_ENABLED);
616 case OPAL_EEH_STOPPED_MMIO_FREEZE:
617 result = (EEH_STATE_DMA_ACTIVE |
618 EEH_STATE_DMA_ENABLED);
620 case OPAL_EEH_STOPPED_DMA_FREEZE:
621 result = (EEH_STATE_MMIO_ACTIVE |
622 EEH_STATE_MMIO_ENABLED);
624 case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
627 case OPAL_EEH_STOPPED_RESET:
628 result = EEH_STATE_RESET_ACTIVE;
630 case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
631 result = EEH_STATE_UNAVAILABLE;
633 case OPAL_EEH_STOPPED_PERM_UNAVAIL:
634 result = EEH_STATE_NOT_SUPPORT;
637 result = EEH_STATE_NOT_SUPPORT;
638 pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
639 __func__, phb->hose->global_number,
644 * If PHB supports compound PE, to freeze all
645 * slave PEs for consistency.
647 * If the PE is switching to frozen state for the
648 * first time, to dump the PHB diag-data.
650 if (!(result & EEH_STATE_NOT_SUPPORT) &&
651 !(result & EEH_STATE_UNAVAILABLE) &&
652 !(result & EEH_STATE_MMIO_ACTIVE) &&
653 !(result & EEH_STATE_DMA_ACTIVE) &&
654 !(pe->state & EEH_PE_ISOLATED)) {
656 phb->freeze_pe(phb, pe->addr);
658 eeh_pe_mark_isolated(pe);
659 pnv_eeh_get_phb_diag(pe);
661 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
662 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
669 * pnv_eeh_get_state - Retrieve PE state
671 * @delay: delay while PE state is temporarily unavailable
673 * Retrieve the state of the specified PE. For IODA-compitable
674 * platform, it should be retrieved from IODA table. Therefore,
675 * we prefer passing down to hardware implementation to handle
678 static int pnv_eeh_get_state(struct eeh_pe *pe, int *delay)
682 if (pe->type & EEH_PE_PHB)
683 ret = pnv_eeh_get_phb_state(pe);
685 ret = pnv_eeh_get_pe_state(pe);
691 * If the PE state is temporarily unavailable,
692 * to inform the EEH core delay for default
696 if (ret & EEH_STATE_UNAVAILABLE)
702 static s64 pnv_eeh_poll(unsigned long id)
704 s64 rc = OPAL_HARDWARE;
707 rc = opal_pci_poll(id);
711 if (system_state < SYSTEM_RUNNING)
720 int pnv_eeh_phb_reset(struct pci_controller *hose, int option)
722 struct pnv_phb *phb = hose->private_data;
723 s64 rc = OPAL_HARDWARE;
725 pr_debug("%s: Reset PHB#%x, option=%d\n",
726 __func__, hose->global_number, option);
728 /* Issue PHB complete reset request */
729 if (option == EEH_RESET_FUNDAMENTAL ||
730 option == EEH_RESET_HOT)
731 rc = opal_pci_reset(phb->opal_id,
732 OPAL_RESET_PHB_COMPLETE,
734 else if (option == EEH_RESET_DEACTIVATE)
735 rc = opal_pci_reset(phb->opal_id,
736 OPAL_RESET_PHB_COMPLETE,
737 OPAL_DEASSERT_RESET);
742 * Poll state of the PHB until the request is done
743 * successfully. The PHB reset is usually PHB complete
744 * reset followed by hot reset on root bus. So we also
745 * need the PCI bus settlement delay.
748 rc = pnv_eeh_poll(phb->opal_id);
749 if (option == EEH_RESET_DEACTIVATE) {
750 if (system_state < SYSTEM_RUNNING)
751 udelay(1000 * EEH_PE_RST_SETTLE_TIME);
753 msleep(EEH_PE_RST_SETTLE_TIME);
756 if (rc != OPAL_SUCCESS)
762 static int pnv_eeh_root_reset(struct pci_controller *hose, int option)
764 struct pnv_phb *phb = hose->private_data;
765 s64 rc = OPAL_HARDWARE;
767 pr_debug("%s: Reset PHB#%x, option=%d\n",
768 __func__, hose->global_number, option);
771 * During the reset deassert time, we needn't care
772 * the reset scope because the firmware does nothing
773 * for fundamental or hot reset during deassert phase.
775 if (option == EEH_RESET_FUNDAMENTAL)
776 rc = opal_pci_reset(phb->opal_id,
777 OPAL_RESET_PCI_FUNDAMENTAL,
779 else if (option == EEH_RESET_HOT)
780 rc = opal_pci_reset(phb->opal_id,
783 else if (option == EEH_RESET_DEACTIVATE)
784 rc = opal_pci_reset(phb->opal_id,
786 OPAL_DEASSERT_RESET);
790 /* Poll state of the PHB until the request is done */
792 rc = pnv_eeh_poll(phb->opal_id);
793 if (option == EEH_RESET_DEACTIVATE)
794 msleep(EEH_PE_RST_SETTLE_TIME);
796 if (rc != OPAL_SUCCESS)
802 static int __pnv_eeh_bridge_reset(struct pci_dev *dev, int option)
804 struct pci_dn *pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
805 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
806 int aer = edev ? edev->aer_cap : 0;
809 pr_debug("%s: Secondary Reset PCI bus %04x:%02x with option %d\n",
810 __func__, pci_domain_nr(dev->bus),
811 dev->bus->number, option);
814 case EEH_RESET_FUNDAMENTAL:
816 /* Don't report linkDown event */
818 eeh_ops->read_config(edev, aer + PCI_ERR_UNCOR_MASK,
820 ctrl |= PCI_ERR_UNC_SURPDN;
821 eeh_ops->write_config(edev, aer + PCI_ERR_UNCOR_MASK,
825 eeh_ops->read_config(edev, PCI_BRIDGE_CONTROL, 2, &ctrl);
826 ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
827 eeh_ops->write_config(edev, PCI_BRIDGE_CONTROL, 2, ctrl);
829 msleep(EEH_PE_RST_HOLD_TIME);
831 case EEH_RESET_DEACTIVATE:
832 eeh_ops->read_config(edev, PCI_BRIDGE_CONTROL, 2, &ctrl);
833 ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
834 eeh_ops->write_config(edev, PCI_BRIDGE_CONTROL, 2, ctrl);
836 msleep(EEH_PE_RST_SETTLE_TIME);
838 /* Continue reporting linkDown event */
840 eeh_ops->read_config(edev, aer + PCI_ERR_UNCOR_MASK,
842 ctrl &= ~PCI_ERR_UNC_SURPDN;
843 eeh_ops->write_config(edev, aer + PCI_ERR_UNCOR_MASK,
853 static int pnv_eeh_bridge_reset(struct pci_dev *pdev, int option)
855 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
856 struct pnv_phb *phb = hose->private_data;
857 struct device_node *dn = pci_device_to_OF_node(pdev);
858 uint64_t id = PCI_SLOT_ID(phb->opal_id, pci_dev_id(pdev));
862 /* Hot reset to the bus if firmware cannot handle */
863 if (!dn || !of_get_property(dn, "ibm,reset-by-firmware", NULL))
864 return __pnv_eeh_bridge_reset(pdev, option);
866 pr_debug("%s: FW reset PCI bus %04x:%02x with option %d\n",
867 __func__, pci_domain_nr(pdev->bus),
868 pdev->bus->number, option);
871 case EEH_RESET_FUNDAMENTAL:
872 scope = OPAL_RESET_PCI_FUNDAMENTAL;
875 scope = OPAL_RESET_PCI_HOT;
877 case EEH_RESET_DEACTIVATE:
880 dev_dbg(&pdev->dev, "%s: Unsupported reset %d\n",
885 rc = opal_pci_reset(id, scope, OPAL_ASSERT_RESET);
886 if (rc <= OPAL_SUCCESS)
889 rc = pnv_eeh_poll(id);
891 return (rc == OPAL_SUCCESS) ? 0 : -EIO;
894 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
896 struct pci_controller *hose;
898 if (pci_is_root_bus(dev->bus)) {
899 hose = pci_bus_to_host(dev->bus);
900 pnv_eeh_root_reset(hose, EEH_RESET_HOT);
901 pnv_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
903 pnv_eeh_bridge_reset(dev, EEH_RESET_HOT);
904 pnv_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
908 static void pnv_eeh_wait_for_pending(struct pci_dn *pdn, const char *type,
911 struct eeh_dev *edev = pdn->edev;
914 /* Wait for Transaction Pending bit to be cleared */
915 for (i = 0; i < 4; i++) {
916 eeh_ops->read_config(edev, pos, 2, &status);
917 if (!(status & mask))
920 msleep((1 << i) * 100);
923 pr_warn("%s: Pending transaction while issuing %sFLR to %04x:%02x:%02x.%01x\n",
925 pdn->phb->global_number, pdn->busno,
926 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
929 static int pnv_eeh_do_flr(struct pci_dn *pdn, int option)
931 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
934 if (WARN_ON(!edev->pcie_cap))
937 eeh_ops->read_config(edev, edev->pcie_cap + PCI_EXP_DEVCAP, 4, ®);
938 if (!(reg & PCI_EXP_DEVCAP_FLR))
943 case EEH_RESET_FUNDAMENTAL:
944 pnv_eeh_wait_for_pending(pdn, "",
945 edev->pcie_cap + PCI_EXP_DEVSTA,
946 PCI_EXP_DEVSTA_TRPND);
947 eeh_ops->read_config(edev, edev->pcie_cap + PCI_EXP_DEVCTL,
949 reg |= PCI_EXP_DEVCTL_BCR_FLR;
950 eeh_ops->write_config(edev, edev->pcie_cap + PCI_EXP_DEVCTL,
952 msleep(EEH_PE_RST_HOLD_TIME);
954 case EEH_RESET_DEACTIVATE:
955 eeh_ops->read_config(edev, edev->pcie_cap + PCI_EXP_DEVCTL,
957 reg &= ~PCI_EXP_DEVCTL_BCR_FLR;
958 eeh_ops->write_config(edev, edev->pcie_cap + PCI_EXP_DEVCTL,
960 msleep(EEH_PE_RST_SETTLE_TIME);
967 static int pnv_eeh_do_af_flr(struct pci_dn *pdn, int option)
969 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
972 if (WARN_ON(!edev->af_cap))
975 eeh_ops->read_config(edev, edev->af_cap + PCI_AF_CAP, 1, &cap);
976 if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
981 case EEH_RESET_FUNDAMENTAL:
983 * Wait for Transaction Pending bit to clear. A word-aligned
984 * test is used, so we use the control offset rather than status
985 * and shift the test bit to match.
987 pnv_eeh_wait_for_pending(pdn, "AF",
988 edev->af_cap + PCI_AF_CTRL,
989 PCI_AF_STATUS_TP << 8);
990 eeh_ops->write_config(edev, edev->af_cap + PCI_AF_CTRL,
992 msleep(EEH_PE_RST_HOLD_TIME);
994 case EEH_RESET_DEACTIVATE:
995 eeh_ops->write_config(edev, edev->af_cap + PCI_AF_CTRL, 1, 0);
996 msleep(EEH_PE_RST_SETTLE_TIME);
1003 static int pnv_eeh_reset_vf_pe(struct eeh_pe *pe, int option)
1005 struct eeh_dev *edev;
1009 /* The VF PE should have only one child device */
1010 edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, entry);
1011 pdn = eeh_dev_to_pdn(edev);
1015 ret = pnv_eeh_do_flr(pdn, option);
1019 return pnv_eeh_do_af_flr(pdn, option);
1023 * pnv_eeh_reset - Reset the specified PE
1025 * @option: reset option
1027 * Do reset on the indicated PE. For PCI bus sensitive PE,
1028 * we need to reset the parent p2p bridge. The PHB has to
1029 * be reinitialized if the p2p bridge is root bridge. For
1030 * PCI device sensitive PE, we will try to reset the device
1031 * through FLR. For now, we don't have OPAL APIs to do HARD
1032 * reset yet, so all reset would be SOFT (HOT) reset.
1034 static int pnv_eeh_reset(struct eeh_pe *pe, int option)
1036 struct pci_controller *hose = pe->phb;
1037 struct pnv_phb *phb;
1038 struct pci_bus *bus;
1042 * For PHB reset, we always have complete reset. For those PEs whose
1043 * primary bus derived from root complex (root bus) or root port
1044 * (usually bus#1), we apply hot or fundamental reset on the root port.
1045 * For other PEs, we always have hot reset on the PE primary bus.
1047 * Here, we have different design to pHyp, which always clear the
1048 * frozen state during PE reset. However, the good idea here from
1049 * benh is to keep frozen state before we get PE reset done completely
1050 * (until BAR restore). With the frozen state, HW drops illegal IO
1051 * or MMIO access, which can incur recursive frozen PE during PE
1052 * reset. The side effect is that EEH core has to clear the frozen
1053 * state explicitly after BAR restore.
1055 if (pe->type & EEH_PE_PHB)
1056 return pnv_eeh_phb_reset(hose, option);
1059 * The frozen PE might be caused by PAPR error injection
1060 * registers, which are expected to be cleared after hitting
1061 * frozen PE as stated in the hardware spec. Unfortunately,
1062 * that's not true on P7IOC. So we have to clear it manually
1063 * to avoid recursive EEH errors during recovery.
1065 phb = hose->private_data;
1066 if (phb->model == PNV_PHB_MODEL_P7IOC &&
1067 (option == EEH_RESET_HOT ||
1068 option == EEH_RESET_FUNDAMENTAL)) {
1069 rc = opal_pci_reset(phb->opal_id,
1070 OPAL_RESET_PHB_ERROR,
1072 if (rc != OPAL_SUCCESS) {
1073 pr_warn("%s: Failure %lld clearing error injection registers\n",
1079 if (pe->type & EEH_PE_VF)
1080 return pnv_eeh_reset_vf_pe(pe, option);
1082 bus = eeh_pe_bus_get(pe);
1084 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
1085 __func__, pe->phb->global_number, pe->addr);
1089 if (pci_is_root_bus(bus))
1090 return pnv_eeh_root_reset(hose, option);
1093 * For hot resets try use the generic PCI error recovery reset
1094 * functions. These correctly handles the case where the secondary
1095 * bus is behind a hotplug slot and it will use the slot provided
1096 * reset methods to prevent spurious hotplug events during the reset.
1098 * Fundamental resets need to be handled internally to EEH since the
1099 * PCI core doesn't really have a concept of a fundamental reset,
1100 * mainly because there's no standard way to generate one. Only a
1101 * few devices require an FRESET so it should be fine.
1103 if (option != EEH_RESET_FUNDAMENTAL) {
1105 * NB: Skiboot and pnv_eeh_bridge_reset() also no-op the
1106 * de-assert step. It's like the OPAL reset API was
1107 * poorly designed or something...
1109 if (option == EEH_RESET_DEACTIVATE)
1112 rc = pci_bus_error_reset(bus->self);
1117 /* otherwise, use the generic bridge reset. this might call into FW */
1118 if (pci_is_root_bus(bus->parent))
1119 return pnv_eeh_root_reset(hose, option);
1120 return pnv_eeh_bridge_reset(bus->self, option);
1124 * pnv_eeh_get_log - Retrieve error log
1126 * @severity: temporary or permanent error log
1127 * @drv_log: driver log to be combined with retrieved error log
1128 * @len: length of driver log
1130 * Retrieve the temporary or permanent error from the PE.
1132 static int pnv_eeh_get_log(struct eeh_pe *pe, int severity,
1133 char *drv_log, unsigned long len)
1135 if (!eeh_has_flag(EEH_EARLY_DUMP_LOG))
1136 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
1142 * pnv_eeh_configure_bridge - Configure PCI bridges in the indicated PE
1145 * The function will be called to reconfigure the bridges included
1146 * in the specified PE so that the mulfunctional PE would be recovered
1149 static int pnv_eeh_configure_bridge(struct eeh_pe *pe)
1155 * pnv_pe_err_inject - Inject specified error to the indicated PE
1156 * @pe: the indicated PE
1158 * @func: specific error type
1160 * @mask: address mask
1162 * The routine is called to inject specified error, which is
1163 * determined by @type and @func, to the indicated PE for
1166 static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
1167 unsigned long addr, unsigned long mask)
1169 struct pci_controller *hose = pe->phb;
1170 struct pnv_phb *phb = hose->private_data;
1173 if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
1174 type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
1175 pr_warn("%s: Invalid error type %d\n",
1180 if (func < OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR ||
1181 func > OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET) {
1182 pr_warn("%s: Invalid error function %d\n",
1187 /* Firmware supports error injection ? */
1188 if (!opal_check_token(OPAL_PCI_ERR_INJECT)) {
1189 pr_warn("%s: Firmware doesn't support error injection\n",
1194 /* Do error injection */
1195 rc = opal_pci_err_inject(phb->opal_id, pe->addr,
1196 type, func, addr, mask);
1197 if (rc != OPAL_SUCCESS) {
1198 pr_warn("%s: Failure %lld injecting error "
1199 "%d-%d to PHB#%x-PE#%x\n",
1200 __func__, rc, type, func,
1201 hose->global_number, pe->addr);
1208 static inline bool pnv_eeh_cfg_blocked(struct pci_dn *pdn)
1210 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1212 if (!edev || !edev->pe)
1216 * We will issue FLR or AF FLR to all VFs, which are contained
1217 * in VF PE. It relies on the EEH PCI config accessors. So we
1218 * can't block them during the window.
1220 if (edev->physfn && (edev->pe->state & EEH_PE_RESET))
1223 if (edev->pe->state & EEH_PE_CFG_BLOCKED)
1229 static int pnv_eeh_read_config(struct eeh_dev *edev,
1230 int where, int size, u32 *val)
1232 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
1235 return PCIBIOS_DEVICE_NOT_FOUND;
1237 if (pnv_eeh_cfg_blocked(pdn)) {
1239 return PCIBIOS_SET_FAILED;
1242 return pnv_pci_cfg_read(pdn, where, size, val);
1245 static int pnv_eeh_write_config(struct eeh_dev *edev,
1246 int where, int size, u32 val)
1248 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
1251 return PCIBIOS_DEVICE_NOT_FOUND;
1253 if (pnv_eeh_cfg_blocked(pdn))
1254 return PCIBIOS_SET_FAILED;
1256 return pnv_pci_cfg_write(pdn, where, size, val);
1259 static void pnv_eeh_dump_hub_diag_common(struct OpalIoP7IOCErrorData *data)
1262 if (data->gemXfir || data->gemRfir ||
1263 data->gemRirqfir || data->gemMask || data->gemRwof)
1264 pr_info(" GEM: %016llx %016llx %016llx %016llx %016llx\n",
1265 be64_to_cpu(data->gemXfir),
1266 be64_to_cpu(data->gemRfir),
1267 be64_to_cpu(data->gemRirqfir),
1268 be64_to_cpu(data->gemMask),
1269 be64_to_cpu(data->gemRwof));
1272 if (data->lemFir || data->lemErrMask ||
1273 data->lemAction0 || data->lemAction1 || data->lemWof)
1274 pr_info(" LEM: %016llx %016llx %016llx %016llx %016llx\n",
1275 be64_to_cpu(data->lemFir),
1276 be64_to_cpu(data->lemErrMask),
1277 be64_to_cpu(data->lemAction0),
1278 be64_to_cpu(data->lemAction1),
1279 be64_to_cpu(data->lemWof));
1282 static void pnv_eeh_get_and_dump_hub_diag(struct pci_controller *hose)
1284 struct pnv_phb *phb = hose->private_data;
1285 struct OpalIoP7IOCErrorData *data =
1286 (struct OpalIoP7IOCErrorData*)phb->diag_data;
1289 rc = opal_pci_get_hub_diag_data(phb->hub_id, data, sizeof(*data));
1290 if (rc != OPAL_SUCCESS) {
1291 pr_warn("%s: Failed to get HUB#%llx diag-data (%ld)\n",
1292 __func__, phb->hub_id, rc);
1296 switch (be16_to_cpu(data->type)) {
1297 case OPAL_P7IOC_DIAG_TYPE_RGC:
1298 pr_info("P7IOC diag-data for RGC\n\n");
1299 pnv_eeh_dump_hub_diag_common(data);
1300 if (data->rgc.rgcStatus || data->rgc.rgcLdcp)
1301 pr_info(" RGC: %016llx %016llx\n",
1302 be64_to_cpu(data->rgc.rgcStatus),
1303 be64_to_cpu(data->rgc.rgcLdcp));
1305 case OPAL_P7IOC_DIAG_TYPE_BI:
1306 pr_info("P7IOC diag-data for BI %s\n\n",
1307 data->bi.biDownbound ? "Downbound" : "Upbound");
1308 pnv_eeh_dump_hub_diag_common(data);
1309 if (data->bi.biLdcp0 || data->bi.biLdcp1 ||
1310 data->bi.biLdcp2 || data->bi.biFenceStatus)
1311 pr_info(" BI: %016llx %016llx %016llx %016llx\n",
1312 be64_to_cpu(data->bi.biLdcp0),
1313 be64_to_cpu(data->bi.biLdcp1),
1314 be64_to_cpu(data->bi.biLdcp2),
1315 be64_to_cpu(data->bi.biFenceStatus));
1317 case OPAL_P7IOC_DIAG_TYPE_CI:
1318 pr_info("P7IOC diag-data for CI Port %d\n\n",
1320 pnv_eeh_dump_hub_diag_common(data);
1321 if (data->ci.ciPortStatus || data->ci.ciPortLdcp)
1322 pr_info(" CI: %016llx %016llx\n",
1323 be64_to_cpu(data->ci.ciPortStatus),
1324 be64_to_cpu(data->ci.ciPortLdcp));
1326 case OPAL_P7IOC_DIAG_TYPE_MISC:
1327 pr_info("P7IOC diag-data for MISC\n\n");
1328 pnv_eeh_dump_hub_diag_common(data);
1330 case OPAL_P7IOC_DIAG_TYPE_I2C:
1331 pr_info("P7IOC diag-data for I2C\n\n");
1332 pnv_eeh_dump_hub_diag_common(data);
1335 pr_warn("%s: Invalid type of HUB#%llx diag-data (%d)\n",
1336 __func__, phb->hub_id, data->type);
1340 static int pnv_eeh_get_pe(struct pci_controller *hose,
1341 u16 pe_no, struct eeh_pe **pe)
1343 struct pnv_phb *phb = hose->private_data;
1344 struct pnv_ioda_pe *pnv_pe;
1345 struct eeh_pe *dev_pe;
1348 * If PHB supports compound PE, to fetch
1349 * the master PE because slave PE is invisible
1352 pnv_pe = &phb->ioda.pe_array[pe_no];
1353 if (pnv_pe->flags & PNV_IODA_PE_SLAVE) {
1354 pnv_pe = pnv_pe->master;
1356 !(pnv_pe->flags & PNV_IODA_PE_MASTER));
1357 pe_no = pnv_pe->pe_number;
1360 /* Find the PE according to PE# */
1361 dev_pe = eeh_pe_get(hose, pe_no);
1365 /* Freeze the (compound) PE */
1367 if (!(dev_pe->state & EEH_PE_ISOLATED))
1368 phb->freeze_pe(phb, pe_no);
1371 * At this point, we're sure the (compound) PE should
1372 * have been frozen. However, we still need poke until
1373 * hitting the frozen PE on top level.
1375 dev_pe = dev_pe->parent;
1376 while (dev_pe && !(dev_pe->type & EEH_PE_PHB)) {
1378 ret = eeh_ops->get_state(dev_pe, NULL);
1379 if (ret <= 0 || eeh_state_active(ret)) {
1380 dev_pe = dev_pe->parent;
1384 /* Frozen parent PE */
1386 if (!(dev_pe->state & EEH_PE_ISOLATED))
1387 phb->freeze_pe(phb, dev_pe->addr);
1390 dev_pe = dev_pe->parent;
1397 * pnv_eeh_next_error - Retrieve next EEH error to handle
1400 * The function is expected to be called by EEH core while it gets
1401 * special EEH event (without binding PE). The function calls to
1402 * OPAL APIs for next error to handle. The informational error is
1403 * handled internally by platform. However, the dead IOC, dead PHB,
1404 * fenced PHB and frozen PE should be handled by EEH core eventually.
1406 static int pnv_eeh_next_error(struct eeh_pe **pe)
1408 struct pci_controller *hose;
1409 struct pnv_phb *phb;
1410 struct eeh_pe *phb_pe, *parent_pe;
1411 __be64 frozen_pe_no;
1412 __be16 err_type, severity;
1414 int state, ret = EEH_NEXT_ERR_NONE;
1417 * While running here, it's safe to purge the event queue. The
1418 * event should still be masked.
1420 eeh_remove_event(NULL, false);
1422 list_for_each_entry(hose, &hose_list, list_node) {
1424 * If the subordinate PCI buses of the PHB has been
1425 * removed or is exactly under error recovery, we
1426 * needn't take care of it any more.
1428 phb = hose->private_data;
1429 phb_pe = eeh_phb_pe_get(hose);
1430 if (!phb_pe || (phb_pe->state & EEH_PE_ISOLATED))
1433 rc = opal_pci_next_error(phb->opal_id,
1434 &frozen_pe_no, &err_type, &severity);
1435 if (rc != OPAL_SUCCESS) {
1436 pr_devel("%s: Invalid return value on "
1437 "PHB#%x (0x%lx) from opal_pci_next_error",
1438 __func__, hose->global_number, rc);
1442 /* If the PHB doesn't have error, stop processing */
1443 if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR ||
1444 be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) {
1445 pr_devel("%s: No error found on PHB#%x\n",
1446 __func__, hose->global_number);
1451 * Processing the error. We're expecting the error with
1452 * highest priority reported upon multiple errors on the
1455 pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n",
1456 __func__, be16_to_cpu(err_type),
1457 be16_to_cpu(severity), be64_to_cpu(frozen_pe_no),
1458 hose->global_number);
1459 switch (be16_to_cpu(err_type)) {
1460 case OPAL_EEH_IOC_ERROR:
1461 if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) {
1462 pr_err("EEH: dead IOC detected\n");
1463 ret = EEH_NEXT_ERR_DEAD_IOC;
1464 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1465 pr_info("EEH: IOC informative error "
1467 pnv_eeh_get_and_dump_hub_diag(hose);
1468 ret = EEH_NEXT_ERR_NONE;
1472 case OPAL_EEH_PHB_ERROR:
1473 if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) {
1475 pr_err("EEH: dead PHB#%x detected, "
1477 hose->global_number,
1478 eeh_pe_loc_get(phb_pe));
1479 ret = EEH_NEXT_ERR_DEAD_PHB;
1480 } else if (be16_to_cpu(severity) ==
1481 OPAL_EEH_SEV_PHB_FENCED) {
1483 pr_err("EEH: Fenced PHB#%x detected, "
1485 hose->global_number,
1486 eeh_pe_loc_get(phb_pe));
1487 ret = EEH_NEXT_ERR_FENCED_PHB;
1488 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1489 pr_info("EEH: PHB#%x informative error "
1490 "detected, location: %s\n",
1491 hose->global_number,
1492 eeh_pe_loc_get(phb_pe));
1493 pnv_eeh_get_phb_diag(phb_pe);
1494 pnv_pci_dump_phb_diag_data(hose, phb_pe->data);
1495 ret = EEH_NEXT_ERR_NONE;
1499 case OPAL_EEH_PE_ERROR:
1501 * If we can't find the corresponding PE, we
1502 * just try to unfreeze.
1504 if (pnv_eeh_get_pe(hose,
1505 be64_to_cpu(frozen_pe_no), pe)) {
1506 pr_info("EEH: Clear non-existing PHB#%x-PE#%llx\n",
1507 hose->global_number, be64_to_cpu(frozen_pe_no));
1508 pr_info("EEH: PHB location: %s\n",
1509 eeh_pe_loc_get(phb_pe));
1511 /* Dump PHB diag-data */
1512 rc = opal_pci_get_phb_diag_data2(phb->opal_id,
1513 phb->diag_data, phb->diag_data_size);
1514 if (rc == OPAL_SUCCESS)
1515 pnv_pci_dump_phb_diag_data(hose,
1518 /* Try best to clear it */
1519 opal_pci_eeh_freeze_clear(phb->opal_id,
1520 be64_to_cpu(frozen_pe_no),
1521 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
1522 ret = EEH_NEXT_ERR_NONE;
1523 } else if ((*pe)->state & EEH_PE_ISOLATED ||
1524 eeh_pe_passed(*pe)) {
1525 ret = EEH_NEXT_ERR_NONE;
1527 pr_err("EEH: Frozen PE#%x "
1528 "on PHB#%x detected\n",
1530 (*pe)->phb->global_number);
1531 pr_err("EEH: PE location: %s, "
1532 "PHB location: %s\n",
1533 eeh_pe_loc_get(*pe),
1534 eeh_pe_loc_get(phb_pe));
1535 ret = EEH_NEXT_ERR_FROZEN_PE;
1540 pr_warn("%s: Unexpected error type %d\n",
1541 __func__, be16_to_cpu(err_type));
1545 * EEH core will try recover from fenced PHB or
1546 * frozen PE. In the time for frozen PE, EEH core
1547 * enable IO path for that before collecting logs,
1548 * but it ruins the site. So we have to dump the
1549 * log in advance here.
1551 if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
1552 ret == EEH_NEXT_ERR_FENCED_PHB) &&
1553 !((*pe)->state & EEH_PE_ISOLATED)) {
1554 eeh_pe_mark_isolated(*pe);
1555 pnv_eeh_get_phb_diag(*pe);
1557 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
1558 pnv_pci_dump_phb_diag_data((*pe)->phb,
1563 * We probably have the frozen parent PE out there and
1564 * we need have to handle frozen parent PE firstly.
1566 if (ret == EEH_NEXT_ERR_FROZEN_PE) {
1567 parent_pe = (*pe)->parent;
1569 /* Hit the ceiling ? */
1570 if (parent_pe->type & EEH_PE_PHB)
1573 /* Frozen parent PE ? */
1574 state = eeh_ops->get_state(parent_pe, NULL);
1575 if (state > 0 && !eeh_state_active(state))
1578 /* Next parent level */
1579 parent_pe = parent_pe->parent;
1582 /* We possibly migrate to another PE */
1583 eeh_pe_mark_isolated(*pe);
1587 * If we have no errors on the specific PHB or only
1588 * informative error there, we continue poking it.
1589 * Otherwise, we need actions to be taken by upper
1592 if (ret > EEH_NEXT_ERR_INF)
1596 /* Unmask the event */
1597 if (ret == EEH_NEXT_ERR_NONE && eeh_enabled())
1598 enable_irq(eeh_event_irq);
1603 static int pnv_eeh_restore_config(struct eeh_dev *edev)
1605 struct pnv_phb *phb;
1614 phb = edev->controller->private_data;
1615 ret = opal_pci_reinit(phb->opal_id,
1616 OPAL_REINIT_PCI_DEV, edev->bdfn);
1619 pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
1620 __func__, edev->bdfn, ret);
1627 static struct eeh_ops pnv_eeh_ops = {
1629 .probe = pnv_eeh_probe,
1630 .set_option = pnv_eeh_set_option,
1631 .get_state = pnv_eeh_get_state,
1632 .reset = pnv_eeh_reset,
1633 .get_log = pnv_eeh_get_log,
1634 .configure_bridge = pnv_eeh_configure_bridge,
1635 .err_inject = pnv_eeh_err_inject,
1636 .read_config = pnv_eeh_read_config,
1637 .write_config = pnv_eeh_write_config,
1638 .next_error = pnv_eeh_next_error,
1639 .restore_config = pnv_eeh_restore_config,
1640 .notify_resume = NULL
1644 * eeh_powernv_init - Register platform dependent EEH operations
1646 * EEH initialization on powernv platform. This function should be
1647 * called before any EEH related functions.
1649 static int __init eeh_powernv_init(void)
1651 int max_diag_size = PNV_PCI_DIAG_BUF_SIZE;
1652 struct pci_controller *hose;
1653 struct pnv_phb *phb;
1656 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
1657 pr_warn("%s: OPAL is required !\n", __func__);
1661 /* Set probe mode */
1662 eeh_add_flag(EEH_PROBE_MODE_DEV);
1665 * P7IOC blocks PCI config access to frozen PE, but PHB3
1666 * doesn't do that. So we have to selectively enable I/O
1667 * prior to collecting error log.
1669 list_for_each_entry(hose, &hose_list, list_node) {
1670 phb = hose->private_data;
1672 if (phb->model == PNV_PHB_MODEL_P7IOC)
1673 eeh_add_flag(EEH_ENABLE_IO_FOR_LOG);
1675 if (phb->diag_data_size > max_diag_size)
1676 max_diag_size = phb->diag_data_size;
1682 * eeh_init() allocates the eeh_pe and its aux data buf so the
1683 * size needs to be set before calling eeh_init().
1685 eeh_set_pe_aux_size(max_diag_size);
1686 ppc_md.pcibios_bus_add_device = pnv_pcibios_bus_add_device;
1688 ret = eeh_init(&pnv_eeh_ops);
1690 pr_info("EEH: PowerNV platform initialized\n");
1692 pr_info("EEH: Failed to initialize PowerNV platform (%d)\n", ret);
1696 machine_arch_initcall(powernv, eeh_powernv_init);