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/list.h>
15 #include <linux/msi.h>
17 #include <linux/pci.h>
18 #include <linux/proc_fs.h>
19 #include <linux/rbtree.h>
20 #include <linux/sched.h>
21 #include <linux/seq_file.h>
22 #include <linux/spinlock.h>
25 #include <asm/eeh_event.h>
26 #include <asm/firmware.h>
28 #include <asm/iommu.h>
29 #include <asm/machdep.h>
30 #include <asm/msi_bitmap.h>
32 #include <asm/ppc-pci.h>
33 #include <asm/pnv-pci.h>
38 static int eeh_event_irq = -EINVAL;
40 void pnv_pcibios_bus_add_device(struct pci_dev *pdev)
42 struct pci_dn *pdn = pci_get_pdn(pdev);
48 * The following operations will fail if VF's sysfs files
49 * aren't created or its resources aren't finalized.
51 eeh_add_device_early(pdn);
52 eeh_add_device_late(pdev);
53 eeh_sysfs_add_device(pdev);
56 static int pnv_eeh_init(void)
58 struct pci_controller *hose;
60 int max_diag_size = PNV_PCI_DIAG_BUF_SIZE;
62 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
63 pr_warn("%s: OPAL is required !\n",
69 eeh_add_flag(EEH_PROBE_MODE_DEV);
72 * P7IOC blocks PCI config access to frozen PE, but PHB3
73 * doesn't do that. So we have to selectively enable I/O
74 * prior to collecting error log.
76 list_for_each_entry(hose, &hose_list, list_node) {
77 phb = hose->private_data;
79 if (phb->model == PNV_PHB_MODEL_P7IOC)
80 eeh_add_flag(EEH_ENABLE_IO_FOR_LOG);
82 if (phb->diag_data_size > max_diag_size)
83 max_diag_size = phb->diag_data_size;
86 * PE#0 should be regarded as valid by EEH core
87 * if it's not the reserved one. Currently, we
88 * have the reserved PE#255 and PE#127 for PHB3
89 * and P7IOC separately. So we should regard
90 * PE#0 as valid for PHB3 and P7IOC.
92 if (phb->ioda.reserved_pe_idx != 0)
93 eeh_add_flag(EEH_VALID_PE_ZERO);
98 eeh_set_pe_aux_size(max_diag_size);
99 ppc_md.pcibios_bus_add_device = pnv_pcibios_bus_add_device;
104 static irqreturn_t pnv_eeh_event(int irq, void *data)
107 * We simply send a special EEH event if EEH has been
108 * enabled. We don't care about EEH events until we've
109 * finished processing the outstanding ones. Event processing
110 * gets unmasked in next_error() if EEH is enabled.
112 disable_irq_nosync(irq);
115 eeh_send_failure_event(NULL);
120 #ifdef CONFIG_DEBUG_FS
121 static ssize_t pnv_eeh_ei_write(struct file *filp,
122 const char __user *user_buf,
123 size_t count, loff_t *ppos)
125 struct pci_controller *hose = filp->private_data;
127 int pe_no, type, func;
128 unsigned long addr, mask;
132 if (!eeh_ops || !eeh_ops->err_inject)
135 /* Copy over argument buffer */
136 ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
140 /* Retrieve parameters */
141 ret = sscanf(buf, "%x:%x:%x:%lx:%lx",
142 &pe_no, &type, &func, &addr, &mask);
147 pe = eeh_pe_get(hose, pe_no, 0);
151 /* Do error injection */
152 ret = eeh_ops->err_inject(pe, type, func, addr, mask);
153 return ret < 0 ? ret : count;
156 static const struct file_operations pnv_eeh_ei_fops = {
159 .write = pnv_eeh_ei_write,
162 static int pnv_eeh_dbgfs_set(void *data, int offset, u64 val)
164 struct pci_controller *hose = data;
165 struct pnv_phb *phb = hose->private_data;
167 out_be64(phb->regs + offset, val);
171 static int pnv_eeh_dbgfs_get(void *data, int offset, u64 *val)
173 struct pci_controller *hose = data;
174 struct pnv_phb *phb = hose->private_data;
176 *val = in_be64(phb->regs + offset);
180 #define PNV_EEH_DBGFS_ENTRY(name, reg) \
181 static int pnv_eeh_dbgfs_set_##name(void *data, u64 val) \
183 return pnv_eeh_dbgfs_set(data, reg, val); \
186 static int pnv_eeh_dbgfs_get_##name(void *data, u64 *val) \
188 return pnv_eeh_dbgfs_get(data, reg, val); \
191 DEFINE_SIMPLE_ATTRIBUTE(pnv_eeh_dbgfs_ops_##name, \
192 pnv_eeh_dbgfs_get_##name, \
193 pnv_eeh_dbgfs_set_##name, \
196 PNV_EEH_DBGFS_ENTRY(outb, 0xD10);
197 PNV_EEH_DBGFS_ENTRY(inbA, 0xD90);
198 PNV_EEH_DBGFS_ENTRY(inbB, 0xE10);
200 #endif /* CONFIG_DEBUG_FS */
203 * pnv_eeh_post_init - EEH platform dependent post initialization
205 * EEH platform dependent post initialization on powernv. When
206 * the function is called, the EEH PEs and devices should have
207 * been built. If the I/O cache staff has been built, EEH is
208 * ready to supply service.
210 int pnv_eeh_post_init(void)
212 struct pci_controller *hose;
216 /* Probe devices & build address cache */
218 eeh_addr_cache_build();
220 /* Register OPAL event notifier */
221 eeh_event_irq = opal_event_request(ilog2(OPAL_EVENT_PCI_ERROR));
222 if (eeh_event_irq < 0) {
223 pr_err("%s: Can't register OPAL event interrupt (%d)\n",
224 __func__, eeh_event_irq);
225 return eeh_event_irq;
228 ret = request_irq(eeh_event_irq, pnv_eeh_event,
229 IRQ_TYPE_LEVEL_HIGH, "opal-eeh", NULL);
231 irq_dispose_mapping(eeh_event_irq);
232 pr_err("%s: Can't request OPAL event interrupt (%d)\n",
233 __func__, eeh_event_irq);
238 disable_irq(eeh_event_irq);
240 list_for_each_entry(hose, &hose_list, list_node) {
241 phb = hose->private_data;
244 * If EEH is enabled, we're going to rely on that.
245 * Otherwise, we restore to conventional mechanism
246 * to clear frozen PE during PCI config access.
249 phb->flags |= PNV_PHB_FLAG_EEH;
251 phb->flags &= ~PNV_PHB_FLAG_EEH;
253 /* Create debugfs entries */
254 #ifdef CONFIG_DEBUG_FS
255 if (phb->has_dbgfs || !phb->dbgfs)
259 debugfs_create_file("err_injct", 0200,
263 debugfs_create_file("err_injct_outbound", 0600,
265 &pnv_eeh_dbgfs_ops_outb);
266 debugfs_create_file("err_injct_inboundA", 0600,
268 &pnv_eeh_dbgfs_ops_inbA);
269 debugfs_create_file("err_injct_inboundB", 0600,
271 &pnv_eeh_dbgfs_ops_inbB);
272 #endif /* CONFIG_DEBUG_FS */
278 static int pnv_eeh_find_cap(struct pci_dn *pdn, int cap)
280 int pos = PCI_CAPABILITY_LIST;
281 int cnt = 48; /* Maximal number of capabilities */
287 /* Check if the device supports capabilities */
288 pnv_pci_cfg_read(pdn, PCI_STATUS, 2, &status);
289 if (!(status & PCI_STATUS_CAP_LIST))
293 pnv_pci_cfg_read(pdn, pos, 1, &pos);
298 pnv_pci_cfg_read(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
307 pos += PCI_CAP_LIST_NEXT;
313 static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
315 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
317 int pos = 256, ttl = (4096 - 256) / 8;
319 if (!edev || !edev->pcie_cap)
321 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
327 if (PCI_EXT_CAP_ID(header) == cap && pos)
330 pos = PCI_EXT_CAP_NEXT(header);
334 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
342 * pnv_eeh_probe - Do probe on PCI device
343 * @pdn: PCI device node
346 * When EEH module is installed during system boot, all PCI devices
347 * are checked one by one to see if it supports EEH. The function
348 * is introduced for the purpose. By default, EEH has been enabled
349 * on all PCI devices. That's to say, we only need do necessary
350 * initialization on the corresponding eeh device and create PE
353 * It's notable that's unsafe to retrieve the EEH device through
354 * the corresponding PCI device. During the PCI device hotplug, which
355 * was possiblly triggered by EEH core, the binding between EEH device
356 * and the PCI device isn't built yet.
358 static void *pnv_eeh_probe(struct pci_dn *pdn, void *data)
360 struct pci_controller *hose = pdn->phb;
361 struct pnv_phb *phb = hose->private_data;
362 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
365 int config_addr = (pdn->busno << 8) | (pdn->devfn);
368 * When probing the root bridge, which doesn't have any
369 * subordinate PCI devices. We don't have OF node for
370 * the root bridge. So it's not reasonable to continue
373 if (!edev || edev->pe)
376 /* Skip for PCI-ISA bridge */
377 if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)
380 /* Initialize eeh device */
381 edev->class_code = pdn->class_code;
382 edev->mode &= 0xFFFFFF00;
383 edev->pcix_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
384 edev->pcie_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
385 edev->af_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_AF);
386 edev->aer_cap = pnv_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
387 if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
388 edev->mode |= EEH_DEV_BRIDGE;
389 if (edev->pcie_cap) {
390 pnv_pci_cfg_read(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
392 pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
393 if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
394 edev->mode |= EEH_DEV_ROOT_PORT;
395 else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
396 edev->mode |= EEH_DEV_DS_PORT;
400 edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
403 ret = eeh_add_to_parent_pe(edev);
405 pr_warn("%s: Can't add PCI dev %04x:%02x:%02x.%01x to parent PE (%x)\n",
406 __func__, hose->global_number, pdn->busno,
407 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn), ret);
412 * If the PE contains any one of following adapters, the
413 * PCI config space can't be accessed when dumping EEH log.
414 * Otherwise, we will run into fenced PHB caused by shortage
415 * of outbound credits in the adapter. The PCI config access
416 * should be blocked until PE reset. MMIO access is dropped
417 * by hardware certainly. In order to drop PCI config requests,
418 * one more flag (EEH_PE_CFG_RESTRICTED) is introduced, which
419 * will be checked in the backend for PE state retrival. If
420 * the PE becomes frozen for the first time and the flag has
421 * been set for the PE, we will set EEH_PE_CFG_BLOCKED for
422 * that PE to block its config space.
424 * Broadcom BCM5718 2-ports NICs (14e4:1656)
425 * Broadcom Austin 4-ports NICs (14e4:1657)
426 * Broadcom Shiner 4-ports 1G NICs (14e4:168a)
427 * Broadcom Shiner 2-ports 10G NICs (14e4:168e)
429 if ((pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
430 pdn->device_id == 0x1656) ||
431 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
432 pdn->device_id == 0x1657) ||
433 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
434 pdn->device_id == 0x168a) ||
435 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
436 pdn->device_id == 0x168e))
437 edev->pe->state |= EEH_PE_CFG_RESTRICTED;
440 * Cache the PE primary bus, which can't be fetched when
441 * full hotplug is in progress. In that case, all child
442 * PCI devices of the PE are expected to be removed prior
445 if (!(edev->pe->state & EEH_PE_PRI_BUS)) {
446 edev->pe->bus = pci_find_bus(hose->global_number,
449 edev->pe->state |= EEH_PE_PRI_BUS;
453 * Enable EEH explicitly so that we will do EEH check
454 * while accessing I/O stuff
456 eeh_add_flag(EEH_ENABLED);
458 /* Save memory bars */
465 * pnv_eeh_set_option - Initialize EEH or MMIO/DMA reenable
467 * @option: operation to be issued
469 * The function is used to control the EEH functionality globally.
470 * Currently, following options are support according to PAPR:
471 * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
473 static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
475 struct pci_controller *hose = pe->phb;
476 struct pnv_phb *phb = hose->private_data;
477 bool freeze_pe = false;
482 case EEH_OPT_DISABLE:
486 case EEH_OPT_THAW_MMIO:
487 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO;
489 case EEH_OPT_THAW_DMA:
490 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_DMA;
492 case EEH_OPT_FREEZE_PE:
494 opt = OPAL_EEH_ACTION_SET_FREEZE_ALL;
497 pr_warn("%s: Invalid option %d\n", __func__, option);
501 /* Freeze master and slave PEs if PHB supports compound PEs */
503 if (phb->freeze_pe) {
504 phb->freeze_pe(phb, pe->addr);
508 rc = opal_pci_eeh_freeze_set(phb->opal_id, pe->addr, opt);
509 if (rc != OPAL_SUCCESS) {
510 pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",
511 __func__, rc, phb->hose->global_number,
519 /* Unfreeze master and slave PEs if PHB supports */
520 if (phb->unfreeze_pe)
521 return phb->unfreeze_pe(phb, pe->addr, opt);
523 rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe->addr, opt);
524 if (rc != OPAL_SUCCESS) {
525 pr_warn("%s: Failure %lld enable %d for PHB#%x-PE#%x\n",
526 __func__, rc, option, phb->hose->global_number,
535 * pnv_eeh_get_pe_addr - Retrieve PE address
538 * Retrieve the PE address according to the given tranditional
539 * PCI BDF (Bus/Device/Function) address.
541 static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
546 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
548 struct pnv_phb *phb = pe->phb->private_data;
551 rc = opal_pci_get_phb_diag_data2(phb->opal_id, pe->data,
552 phb->diag_data_size);
553 if (rc != OPAL_SUCCESS)
554 pr_warn("%s: Failure %lld getting PHB#%x diag-data\n",
555 __func__, rc, pe->phb->global_number);
558 static int pnv_eeh_get_phb_state(struct eeh_pe *pe)
560 struct pnv_phb *phb = pe->phb->private_data;
566 rc = opal_pci_eeh_freeze_status(phb->opal_id,
571 if (rc != OPAL_SUCCESS) {
572 pr_warn("%s: Failure %lld getting PHB#%x state\n",
573 __func__, rc, phb->hose->global_number);
574 return EEH_STATE_NOT_SUPPORT;
578 * Check PHB state. If the PHB is frozen for the
579 * first time, to dump the PHB diag-data.
581 if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
582 result = (EEH_STATE_MMIO_ACTIVE |
583 EEH_STATE_DMA_ACTIVE |
584 EEH_STATE_MMIO_ENABLED |
585 EEH_STATE_DMA_ENABLED);
586 } else if (!(pe->state & EEH_PE_ISOLATED)) {
587 eeh_pe_mark_isolated(pe);
588 pnv_eeh_get_phb_diag(pe);
590 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
591 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
597 static int pnv_eeh_get_pe_state(struct eeh_pe *pe)
599 struct pnv_phb *phb = pe->phb->private_data;
606 * We don't clobber hardware frozen state until PE
607 * reset is completed. In order to keep EEH core
608 * moving forward, we have to return operational
609 * state during PE reset.
611 if (pe->state & EEH_PE_RESET) {
612 result = (EEH_STATE_MMIO_ACTIVE |
613 EEH_STATE_DMA_ACTIVE |
614 EEH_STATE_MMIO_ENABLED |
615 EEH_STATE_DMA_ENABLED);
620 * Fetch PE state from hardware. If the PHB
621 * supports compound PE, let it handle that.
623 if (phb->get_pe_state) {
624 fstate = phb->get_pe_state(phb, pe->addr);
626 rc = opal_pci_eeh_freeze_status(phb->opal_id,
631 if (rc != OPAL_SUCCESS) {
632 pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
633 __func__, rc, phb->hose->global_number,
635 return EEH_STATE_NOT_SUPPORT;
639 /* Figure out state */
641 case OPAL_EEH_STOPPED_NOT_FROZEN:
642 result = (EEH_STATE_MMIO_ACTIVE |
643 EEH_STATE_DMA_ACTIVE |
644 EEH_STATE_MMIO_ENABLED |
645 EEH_STATE_DMA_ENABLED);
647 case OPAL_EEH_STOPPED_MMIO_FREEZE:
648 result = (EEH_STATE_DMA_ACTIVE |
649 EEH_STATE_DMA_ENABLED);
651 case OPAL_EEH_STOPPED_DMA_FREEZE:
652 result = (EEH_STATE_MMIO_ACTIVE |
653 EEH_STATE_MMIO_ENABLED);
655 case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
658 case OPAL_EEH_STOPPED_RESET:
659 result = EEH_STATE_RESET_ACTIVE;
661 case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
662 result = EEH_STATE_UNAVAILABLE;
664 case OPAL_EEH_STOPPED_PERM_UNAVAIL:
665 result = EEH_STATE_NOT_SUPPORT;
668 result = EEH_STATE_NOT_SUPPORT;
669 pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
670 __func__, phb->hose->global_number,
675 * If PHB supports compound PE, to freeze all
676 * slave PEs for consistency.
678 * If the PE is switching to frozen state for the
679 * first time, to dump the PHB diag-data.
681 if (!(result & EEH_STATE_NOT_SUPPORT) &&
682 !(result & EEH_STATE_UNAVAILABLE) &&
683 !(result & EEH_STATE_MMIO_ACTIVE) &&
684 !(result & EEH_STATE_DMA_ACTIVE) &&
685 !(pe->state & EEH_PE_ISOLATED)) {
687 phb->freeze_pe(phb, pe->addr);
689 eeh_pe_mark_isolated(pe);
690 pnv_eeh_get_phb_diag(pe);
692 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
693 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
700 * pnv_eeh_get_state - Retrieve PE state
702 * @delay: delay while PE state is temporarily unavailable
704 * Retrieve the state of the specified PE. For IODA-compitable
705 * platform, it should be retrieved from IODA table. Therefore,
706 * we prefer passing down to hardware implementation to handle
709 static int pnv_eeh_get_state(struct eeh_pe *pe, int *delay)
713 if (pe->type & EEH_PE_PHB)
714 ret = pnv_eeh_get_phb_state(pe);
716 ret = pnv_eeh_get_pe_state(pe);
722 * If the PE state is temporarily unavailable,
723 * to inform the EEH core delay for default
727 if (ret & EEH_STATE_UNAVAILABLE)
733 static s64 pnv_eeh_poll(unsigned long id)
735 s64 rc = OPAL_HARDWARE;
738 rc = opal_pci_poll(id);
742 if (system_state < SYSTEM_RUNNING)
751 int pnv_eeh_phb_reset(struct pci_controller *hose, int option)
753 struct pnv_phb *phb = hose->private_data;
754 s64 rc = OPAL_HARDWARE;
756 pr_debug("%s: Reset PHB#%x, option=%d\n",
757 __func__, hose->global_number, option);
759 /* Issue PHB complete reset request */
760 if (option == EEH_RESET_FUNDAMENTAL ||
761 option == EEH_RESET_HOT)
762 rc = opal_pci_reset(phb->opal_id,
763 OPAL_RESET_PHB_COMPLETE,
765 else if (option == EEH_RESET_DEACTIVATE)
766 rc = opal_pci_reset(phb->opal_id,
767 OPAL_RESET_PHB_COMPLETE,
768 OPAL_DEASSERT_RESET);
773 * Poll state of the PHB until the request is done
774 * successfully. The PHB reset is usually PHB complete
775 * reset followed by hot reset on root bus. So we also
776 * need the PCI bus settlement delay.
779 rc = pnv_eeh_poll(phb->opal_id);
780 if (option == EEH_RESET_DEACTIVATE) {
781 if (system_state < SYSTEM_RUNNING)
782 udelay(1000 * EEH_PE_RST_SETTLE_TIME);
784 msleep(EEH_PE_RST_SETTLE_TIME);
787 if (rc != OPAL_SUCCESS)
793 static int pnv_eeh_root_reset(struct pci_controller *hose, int option)
795 struct pnv_phb *phb = hose->private_data;
796 s64 rc = OPAL_HARDWARE;
798 pr_debug("%s: Reset PHB#%x, option=%d\n",
799 __func__, hose->global_number, option);
802 * During the reset deassert time, we needn't care
803 * the reset scope because the firmware does nothing
804 * for fundamental or hot reset during deassert phase.
806 if (option == EEH_RESET_FUNDAMENTAL)
807 rc = opal_pci_reset(phb->opal_id,
808 OPAL_RESET_PCI_FUNDAMENTAL,
810 else if (option == EEH_RESET_HOT)
811 rc = opal_pci_reset(phb->opal_id,
814 else if (option == EEH_RESET_DEACTIVATE)
815 rc = opal_pci_reset(phb->opal_id,
817 OPAL_DEASSERT_RESET);
821 /* Poll state of the PHB until the request is done */
823 rc = pnv_eeh_poll(phb->opal_id);
824 if (option == EEH_RESET_DEACTIVATE)
825 msleep(EEH_PE_RST_SETTLE_TIME);
827 if (rc != OPAL_SUCCESS)
833 static int __pnv_eeh_bridge_reset(struct pci_dev *dev, int option)
835 struct pci_dn *pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
836 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
837 int aer = edev ? edev->aer_cap : 0;
840 pr_debug("%s: Reset PCI bus %04x:%02x with option %d\n",
841 __func__, pci_domain_nr(dev->bus),
842 dev->bus->number, option);
845 case EEH_RESET_FUNDAMENTAL:
847 /* Don't report linkDown event */
849 eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
851 ctrl |= PCI_ERR_UNC_SURPDN;
852 eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
856 eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
857 ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
858 eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
860 msleep(EEH_PE_RST_HOLD_TIME);
862 case EEH_RESET_DEACTIVATE:
863 eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
864 ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
865 eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
867 msleep(EEH_PE_RST_SETTLE_TIME);
869 /* Continue reporting linkDown event */
871 eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
873 ctrl &= ~PCI_ERR_UNC_SURPDN;
874 eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
884 static int pnv_eeh_bridge_reset(struct pci_dev *pdev, int option)
886 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
887 struct pnv_phb *phb = hose->private_data;
888 struct device_node *dn = pci_device_to_OF_node(pdev);
889 uint64_t id = PCI_SLOT_ID(phb->opal_id,
890 (pdev->bus->number << 8) | pdev->devfn);
894 /* Hot reset to the bus if firmware cannot handle */
895 if (!dn || !of_get_property(dn, "ibm,reset-by-firmware", NULL))
896 return __pnv_eeh_bridge_reset(pdev, option);
899 case EEH_RESET_FUNDAMENTAL:
900 scope = OPAL_RESET_PCI_FUNDAMENTAL;
903 scope = OPAL_RESET_PCI_HOT;
905 case EEH_RESET_DEACTIVATE:
908 dev_dbg(&pdev->dev, "%s: Unsupported reset %d\n",
913 rc = opal_pci_reset(id, scope, OPAL_ASSERT_RESET);
914 if (rc <= OPAL_SUCCESS)
917 rc = pnv_eeh_poll(id);
919 return (rc == OPAL_SUCCESS) ? 0 : -EIO;
922 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
924 struct pci_controller *hose;
926 if (pci_is_root_bus(dev->bus)) {
927 hose = pci_bus_to_host(dev->bus);
928 pnv_eeh_root_reset(hose, EEH_RESET_HOT);
929 pnv_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
931 pnv_eeh_bridge_reset(dev, EEH_RESET_HOT);
932 pnv_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
936 static void pnv_eeh_wait_for_pending(struct pci_dn *pdn, const char *type,
941 /* Wait for Transaction Pending bit to be cleared */
942 for (i = 0; i < 4; i++) {
943 eeh_ops->read_config(pdn, pos, 2, &status);
944 if (!(status & mask))
947 msleep((1 << i) * 100);
950 pr_warn("%s: Pending transaction while issuing %sFLR to %04x:%02x:%02x.%01x\n",
952 pdn->phb->global_number, pdn->busno,
953 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
956 static int pnv_eeh_do_flr(struct pci_dn *pdn, int option)
958 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
961 if (WARN_ON(!edev->pcie_cap))
964 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCAP, 4, ®);
965 if (!(reg & PCI_EXP_DEVCAP_FLR))
970 case EEH_RESET_FUNDAMENTAL:
971 pnv_eeh_wait_for_pending(pdn, "",
972 edev->pcie_cap + PCI_EXP_DEVSTA,
973 PCI_EXP_DEVSTA_TRPND);
974 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
976 reg |= PCI_EXP_DEVCTL_BCR_FLR;
977 eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
979 msleep(EEH_PE_RST_HOLD_TIME);
981 case EEH_RESET_DEACTIVATE:
982 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
984 reg &= ~PCI_EXP_DEVCTL_BCR_FLR;
985 eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
987 msleep(EEH_PE_RST_SETTLE_TIME);
994 static int pnv_eeh_do_af_flr(struct pci_dn *pdn, int option)
996 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
999 if (WARN_ON(!edev->af_cap))
1002 eeh_ops->read_config(pdn, edev->af_cap + PCI_AF_CAP, 1, &cap);
1003 if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
1008 case EEH_RESET_FUNDAMENTAL:
1010 * Wait for Transaction Pending bit to clear. A word-aligned
1011 * test is used, so we use the conrol offset rather than status
1012 * and shift the test bit to match.
1014 pnv_eeh_wait_for_pending(pdn, "AF",
1015 edev->af_cap + PCI_AF_CTRL,
1016 PCI_AF_STATUS_TP << 8);
1017 eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL,
1018 1, PCI_AF_CTRL_FLR);
1019 msleep(EEH_PE_RST_HOLD_TIME);
1021 case EEH_RESET_DEACTIVATE:
1022 eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL, 1, 0);
1023 msleep(EEH_PE_RST_SETTLE_TIME);
1030 static int pnv_eeh_reset_vf_pe(struct eeh_pe *pe, int option)
1032 struct eeh_dev *edev;
1036 /* The VF PE should have only one child device */
1037 edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, entry);
1038 pdn = eeh_dev_to_pdn(edev);
1042 ret = pnv_eeh_do_flr(pdn, option);
1046 return pnv_eeh_do_af_flr(pdn, option);
1050 * pnv_eeh_reset - Reset the specified PE
1052 * @option: reset option
1054 * Do reset on the indicated PE. For PCI bus sensitive PE,
1055 * we need to reset the parent p2p bridge. The PHB has to
1056 * be reinitialized if the p2p bridge is root bridge. For
1057 * PCI device sensitive PE, we will try to reset the device
1058 * through FLR. For now, we don't have OPAL APIs to do HARD
1059 * reset yet, so all reset would be SOFT (HOT) reset.
1061 static int pnv_eeh_reset(struct eeh_pe *pe, int option)
1063 struct pci_controller *hose = pe->phb;
1064 struct pnv_phb *phb;
1065 struct pci_bus *bus;
1069 * For PHB reset, we always have complete reset. For those PEs whose
1070 * primary bus derived from root complex (root bus) or root port
1071 * (usually bus#1), we apply hot or fundamental reset on the root port.
1072 * For other PEs, we always have hot reset on the PE primary bus.
1074 * Here, we have different design to pHyp, which always clear the
1075 * frozen state during PE reset. However, the good idea here from
1076 * benh is to keep frozen state before we get PE reset done completely
1077 * (until BAR restore). With the frozen state, HW drops illegal IO
1078 * or MMIO access, which can incur recrusive frozen PE during PE
1079 * reset. The side effect is that EEH core has to clear the frozen
1080 * state explicitly after BAR restore.
1082 if (pe->type & EEH_PE_PHB)
1083 return pnv_eeh_phb_reset(hose, option);
1086 * The frozen PE might be caused by PAPR error injection
1087 * registers, which are expected to be cleared after hitting
1088 * frozen PE as stated in the hardware spec. Unfortunately,
1089 * that's not true on P7IOC. So we have to clear it manually
1090 * to avoid recursive EEH errors during recovery.
1092 phb = hose->private_data;
1093 if (phb->model == PNV_PHB_MODEL_P7IOC &&
1094 (option == EEH_RESET_HOT ||
1095 option == EEH_RESET_FUNDAMENTAL)) {
1096 rc = opal_pci_reset(phb->opal_id,
1097 OPAL_RESET_PHB_ERROR,
1099 if (rc != OPAL_SUCCESS) {
1100 pr_warn("%s: Failure %lld clearing error injection registers\n",
1106 if (pe->type & EEH_PE_VF)
1107 return pnv_eeh_reset_vf_pe(pe, option);
1109 bus = eeh_pe_bus_get(pe);
1111 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
1112 __func__, pe->phb->global_number, pe->addr);
1117 * If dealing with the root bus (or the bus underneath the
1118 * root port), we reset the bus underneath the root port.
1120 * The cxl driver depends on this behaviour for bi-modal card
1123 if (pci_is_root_bus(bus) ||
1124 pci_is_root_bus(bus->parent))
1125 return pnv_eeh_root_reset(hose, option);
1127 return pnv_eeh_bridge_reset(bus->self, option);
1131 * pnv_eeh_get_log - Retrieve error log
1133 * @severity: temporary or permanent error log
1134 * @drv_log: driver log to be combined with retrieved error log
1135 * @len: length of driver log
1137 * Retrieve the temporary or permanent error from the PE.
1139 static int pnv_eeh_get_log(struct eeh_pe *pe, int severity,
1140 char *drv_log, unsigned long len)
1142 if (!eeh_has_flag(EEH_EARLY_DUMP_LOG))
1143 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
1149 * pnv_eeh_configure_bridge - Configure PCI bridges in the indicated PE
1152 * The function will be called to reconfigure the bridges included
1153 * in the specified PE so that the mulfunctional PE would be recovered
1156 static int pnv_eeh_configure_bridge(struct eeh_pe *pe)
1162 * pnv_pe_err_inject - Inject specified error to the indicated PE
1163 * @pe: the indicated PE
1165 * @func: specific error type
1167 * @mask: address mask
1169 * The routine is called to inject specified error, which is
1170 * determined by @type and @func, to the indicated PE for
1173 static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
1174 unsigned long addr, unsigned long mask)
1176 struct pci_controller *hose = pe->phb;
1177 struct pnv_phb *phb = hose->private_data;
1180 if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
1181 type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
1182 pr_warn("%s: Invalid error type %d\n",
1187 if (func < OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR ||
1188 func > OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET) {
1189 pr_warn("%s: Invalid error function %d\n",
1194 /* Firmware supports error injection ? */
1195 if (!opal_check_token(OPAL_PCI_ERR_INJECT)) {
1196 pr_warn("%s: Firmware doesn't support error injection\n",
1201 /* Do error injection */
1202 rc = opal_pci_err_inject(phb->opal_id, pe->addr,
1203 type, func, addr, mask);
1204 if (rc != OPAL_SUCCESS) {
1205 pr_warn("%s: Failure %lld injecting error "
1206 "%d-%d to PHB#%x-PE#%x\n",
1207 __func__, rc, type, func,
1208 hose->global_number, pe->addr);
1215 static inline bool pnv_eeh_cfg_blocked(struct pci_dn *pdn)
1217 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1219 if (!edev || !edev->pe)
1223 * We will issue FLR or AF FLR to all VFs, which are contained
1224 * in VF PE. It relies on the EEH PCI config accessors. So we
1225 * can't block them during the window.
1227 if (edev->physfn && (edev->pe->state & EEH_PE_RESET))
1230 if (edev->pe->state & EEH_PE_CFG_BLOCKED)
1236 static int pnv_eeh_read_config(struct pci_dn *pdn,
1237 int where, int size, u32 *val)
1240 return PCIBIOS_DEVICE_NOT_FOUND;
1242 if (pnv_eeh_cfg_blocked(pdn)) {
1244 return PCIBIOS_SET_FAILED;
1247 return pnv_pci_cfg_read(pdn, where, size, val);
1250 static int pnv_eeh_write_config(struct pci_dn *pdn,
1251 int where, int size, u32 val)
1254 return PCIBIOS_DEVICE_NOT_FOUND;
1256 if (pnv_eeh_cfg_blocked(pdn))
1257 return PCIBIOS_SET_FAILED;
1259 return pnv_pci_cfg_write(pdn, where, size, val);
1262 static void pnv_eeh_dump_hub_diag_common(struct OpalIoP7IOCErrorData *data)
1265 if (data->gemXfir || data->gemRfir ||
1266 data->gemRirqfir || data->gemMask || data->gemRwof)
1267 pr_info(" GEM: %016llx %016llx %016llx %016llx %016llx\n",
1268 be64_to_cpu(data->gemXfir),
1269 be64_to_cpu(data->gemRfir),
1270 be64_to_cpu(data->gemRirqfir),
1271 be64_to_cpu(data->gemMask),
1272 be64_to_cpu(data->gemRwof));
1275 if (data->lemFir || data->lemErrMask ||
1276 data->lemAction0 || data->lemAction1 || data->lemWof)
1277 pr_info(" LEM: %016llx %016llx %016llx %016llx %016llx\n",
1278 be64_to_cpu(data->lemFir),
1279 be64_to_cpu(data->lemErrMask),
1280 be64_to_cpu(data->lemAction0),
1281 be64_to_cpu(data->lemAction1),
1282 be64_to_cpu(data->lemWof));
1285 static void pnv_eeh_get_and_dump_hub_diag(struct pci_controller *hose)
1287 struct pnv_phb *phb = hose->private_data;
1288 struct OpalIoP7IOCErrorData *data =
1289 (struct OpalIoP7IOCErrorData*)phb->diag_data;
1292 rc = opal_pci_get_hub_diag_data(phb->hub_id, data, sizeof(*data));
1293 if (rc != OPAL_SUCCESS) {
1294 pr_warn("%s: Failed to get HUB#%llx diag-data (%ld)\n",
1295 __func__, phb->hub_id, rc);
1299 switch (be16_to_cpu(data->type)) {
1300 case OPAL_P7IOC_DIAG_TYPE_RGC:
1301 pr_info("P7IOC diag-data for RGC\n\n");
1302 pnv_eeh_dump_hub_diag_common(data);
1303 if (data->rgc.rgcStatus || data->rgc.rgcLdcp)
1304 pr_info(" RGC: %016llx %016llx\n",
1305 be64_to_cpu(data->rgc.rgcStatus),
1306 be64_to_cpu(data->rgc.rgcLdcp));
1308 case OPAL_P7IOC_DIAG_TYPE_BI:
1309 pr_info("P7IOC diag-data for BI %s\n\n",
1310 data->bi.biDownbound ? "Downbound" : "Upbound");
1311 pnv_eeh_dump_hub_diag_common(data);
1312 if (data->bi.biLdcp0 || data->bi.biLdcp1 ||
1313 data->bi.biLdcp2 || data->bi.biFenceStatus)
1314 pr_info(" BI: %016llx %016llx %016llx %016llx\n",
1315 be64_to_cpu(data->bi.biLdcp0),
1316 be64_to_cpu(data->bi.biLdcp1),
1317 be64_to_cpu(data->bi.biLdcp2),
1318 be64_to_cpu(data->bi.biFenceStatus));
1320 case OPAL_P7IOC_DIAG_TYPE_CI:
1321 pr_info("P7IOC diag-data for CI Port %d\n\n",
1323 pnv_eeh_dump_hub_diag_common(data);
1324 if (data->ci.ciPortStatus || data->ci.ciPortLdcp)
1325 pr_info(" CI: %016llx %016llx\n",
1326 be64_to_cpu(data->ci.ciPortStatus),
1327 be64_to_cpu(data->ci.ciPortLdcp));
1329 case OPAL_P7IOC_DIAG_TYPE_MISC:
1330 pr_info("P7IOC diag-data for MISC\n\n");
1331 pnv_eeh_dump_hub_diag_common(data);
1333 case OPAL_P7IOC_DIAG_TYPE_I2C:
1334 pr_info("P7IOC diag-data for I2C\n\n");
1335 pnv_eeh_dump_hub_diag_common(data);
1338 pr_warn("%s: Invalid type of HUB#%llx diag-data (%d)\n",
1339 __func__, phb->hub_id, data->type);
1343 static int pnv_eeh_get_pe(struct pci_controller *hose,
1344 u16 pe_no, struct eeh_pe **pe)
1346 struct pnv_phb *phb = hose->private_data;
1347 struct pnv_ioda_pe *pnv_pe;
1348 struct eeh_pe *dev_pe;
1351 * If PHB supports compound PE, to fetch
1352 * the master PE because slave PE is invisible
1355 pnv_pe = &phb->ioda.pe_array[pe_no];
1356 if (pnv_pe->flags & PNV_IODA_PE_SLAVE) {
1357 pnv_pe = pnv_pe->master;
1359 !(pnv_pe->flags & PNV_IODA_PE_MASTER));
1360 pe_no = pnv_pe->pe_number;
1363 /* Find the PE according to PE# */
1364 dev_pe = eeh_pe_get(hose, pe_no, 0);
1368 /* Freeze the (compound) PE */
1370 if (!(dev_pe->state & EEH_PE_ISOLATED))
1371 phb->freeze_pe(phb, pe_no);
1374 * At this point, we're sure the (compound) PE should
1375 * have been frozen. However, we still need poke until
1376 * hitting the frozen PE on top level.
1378 dev_pe = dev_pe->parent;
1379 while (dev_pe && !(dev_pe->type & EEH_PE_PHB)) {
1381 ret = eeh_ops->get_state(dev_pe, NULL);
1382 if (ret <= 0 || eeh_state_active(ret)) {
1383 dev_pe = dev_pe->parent;
1387 /* Frozen parent PE */
1389 if (!(dev_pe->state & EEH_PE_ISOLATED))
1390 phb->freeze_pe(phb, dev_pe->addr);
1393 dev_pe = dev_pe->parent;
1400 * pnv_eeh_next_error - Retrieve next EEH error to handle
1403 * The function is expected to be called by EEH core while it gets
1404 * special EEH event (without binding PE). The function calls to
1405 * OPAL APIs for next error to handle. The informational error is
1406 * handled internally by platform. However, the dead IOC, dead PHB,
1407 * fenced PHB and frozen PE should be handled by EEH core eventually.
1409 static int pnv_eeh_next_error(struct eeh_pe **pe)
1411 struct pci_controller *hose;
1412 struct pnv_phb *phb;
1413 struct eeh_pe *phb_pe, *parent_pe;
1414 __be64 frozen_pe_no;
1415 __be16 err_type, severity;
1417 int state, ret = EEH_NEXT_ERR_NONE;
1420 * While running here, it's safe to purge the event queue. The
1421 * event should still be masked.
1423 eeh_remove_event(NULL, false);
1425 list_for_each_entry(hose, &hose_list, list_node) {
1427 * If the subordinate PCI buses of the PHB has been
1428 * removed or is exactly under error recovery, we
1429 * needn't take care of it any more.
1431 phb = hose->private_data;
1432 phb_pe = eeh_phb_pe_get(hose);
1433 if (!phb_pe || (phb_pe->state & EEH_PE_ISOLATED))
1436 rc = opal_pci_next_error(phb->opal_id,
1437 &frozen_pe_no, &err_type, &severity);
1438 if (rc != OPAL_SUCCESS) {
1439 pr_devel("%s: Invalid return value on "
1440 "PHB#%x (0x%lx) from opal_pci_next_error",
1441 __func__, hose->global_number, rc);
1445 /* If the PHB doesn't have error, stop processing */
1446 if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR ||
1447 be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) {
1448 pr_devel("%s: No error found on PHB#%x\n",
1449 __func__, hose->global_number);
1454 * Processing the error. We're expecting the error with
1455 * highest priority reported upon multiple errors on the
1458 pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n",
1459 __func__, be16_to_cpu(err_type),
1460 be16_to_cpu(severity), be64_to_cpu(frozen_pe_no),
1461 hose->global_number);
1462 switch (be16_to_cpu(err_type)) {
1463 case OPAL_EEH_IOC_ERROR:
1464 if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) {
1465 pr_err("EEH: dead IOC detected\n");
1466 ret = EEH_NEXT_ERR_DEAD_IOC;
1467 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1468 pr_info("EEH: IOC informative error "
1470 pnv_eeh_get_and_dump_hub_diag(hose);
1471 ret = EEH_NEXT_ERR_NONE;
1475 case OPAL_EEH_PHB_ERROR:
1476 if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) {
1478 pr_err("EEH: dead PHB#%x detected, "
1480 hose->global_number,
1481 eeh_pe_loc_get(phb_pe));
1482 ret = EEH_NEXT_ERR_DEAD_PHB;
1483 } else if (be16_to_cpu(severity) ==
1484 OPAL_EEH_SEV_PHB_FENCED) {
1486 pr_err("EEH: Fenced PHB#%x detected, "
1488 hose->global_number,
1489 eeh_pe_loc_get(phb_pe));
1490 ret = EEH_NEXT_ERR_FENCED_PHB;
1491 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1492 pr_info("EEH: PHB#%x informative error "
1493 "detected, location: %s\n",
1494 hose->global_number,
1495 eeh_pe_loc_get(phb_pe));
1496 pnv_eeh_get_phb_diag(phb_pe);
1497 pnv_pci_dump_phb_diag_data(hose, phb_pe->data);
1498 ret = EEH_NEXT_ERR_NONE;
1502 case OPAL_EEH_PE_ERROR:
1504 * If we can't find the corresponding PE, we
1505 * just try to unfreeze.
1507 if (pnv_eeh_get_pe(hose,
1508 be64_to_cpu(frozen_pe_no), pe)) {
1509 pr_info("EEH: Clear non-existing PHB#%x-PE#%llx\n",
1510 hose->global_number, be64_to_cpu(frozen_pe_no));
1511 pr_info("EEH: PHB location: %s\n",
1512 eeh_pe_loc_get(phb_pe));
1514 /* Dump PHB diag-data */
1515 rc = opal_pci_get_phb_diag_data2(phb->opal_id,
1516 phb->diag_data, phb->diag_data_size);
1517 if (rc == OPAL_SUCCESS)
1518 pnv_pci_dump_phb_diag_data(hose,
1521 /* Try best to clear it */
1522 opal_pci_eeh_freeze_clear(phb->opal_id,
1523 be64_to_cpu(frozen_pe_no),
1524 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
1525 ret = EEH_NEXT_ERR_NONE;
1526 } else if ((*pe)->state & EEH_PE_ISOLATED ||
1527 eeh_pe_passed(*pe)) {
1528 ret = EEH_NEXT_ERR_NONE;
1530 pr_err("EEH: Frozen PE#%x "
1531 "on PHB#%x detected\n",
1533 (*pe)->phb->global_number);
1534 pr_err("EEH: PE location: %s, "
1535 "PHB location: %s\n",
1536 eeh_pe_loc_get(*pe),
1537 eeh_pe_loc_get(phb_pe));
1538 ret = EEH_NEXT_ERR_FROZEN_PE;
1543 pr_warn("%s: Unexpected error type %d\n",
1544 __func__, be16_to_cpu(err_type));
1548 * EEH core will try recover from fenced PHB or
1549 * frozen PE. In the time for frozen PE, EEH core
1550 * enable IO path for that before collecting logs,
1551 * but it ruins the site. So we have to dump the
1552 * log in advance here.
1554 if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
1555 ret == EEH_NEXT_ERR_FENCED_PHB) &&
1556 !((*pe)->state & EEH_PE_ISOLATED)) {
1557 eeh_pe_mark_isolated(*pe);
1558 pnv_eeh_get_phb_diag(*pe);
1560 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
1561 pnv_pci_dump_phb_diag_data((*pe)->phb,
1566 * We probably have the frozen parent PE out there and
1567 * we need have to handle frozen parent PE firstly.
1569 if (ret == EEH_NEXT_ERR_FROZEN_PE) {
1570 parent_pe = (*pe)->parent;
1572 /* Hit the ceiling ? */
1573 if (parent_pe->type & EEH_PE_PHB)
1576 /* Frozen parent PE ? */
1577 state = eeh_ops->get_state(parent_pe, NULL);
1578 if (state > 0 && !eeh_state_active(state))
1581 /* Next parent level */
1582 parent_pe = parent_pe->parent;
1585 /* We possibly migrate to another PE */
1586 eeh_pe_mark_isolated(*pe);
1590 * If we have no errors on the specific PHB or only
1591 * informative error there, we continue poking it.
1592 * Otherwise, we need actions to be taken by upper
1595 if (ret > EEH_NEXT_ERR_INF)
1599 /* Unmask the event */
1600 if (ret == EEH_NEXT_ERR_NONE && eeh_enabled())
1601 enable_irq(eeh_event_irq);
1606 static int pnv_eeh_restore_config(struct pci_dn *pdn)
1608 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1609 struct pnv_phb *phb;
1611 int config_addr = (pdn->busno << 8) | (pdn->devfn);
1617 * We have to restore the PCI config space after reset since the
1618 * firmware can't see SRIOV VFs.
1620 * FIXME: The MPS, error routing rules, timeout setting are worthy
1621 * to be exported by firmware in extendible way.
1624 ret = eeh_restore_vf_config(pdn);
1626 phb = pdn->phb->private_data;
1627 ret = opal_pci_reinit(phb->opal_id,
1628 OPAL_REINIT_PCI_DEV, config_addr);
1632 pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
1633 __func__, config_addr, ret);
1640 static struct eeh_ops pnv_eeh_ops = {
1642 .init = pnv_eeh_init,
1643 .probe = pnv_eeh_probe,
1644 .set_option = pnv_eeh_set_option,
1645 .get_pe_addr = pnv_eeh_get_pe_addr,
1646 .get_state = pnv_eeh_get_state,
1647 .reset = pnv_eeh_reset,
1648 .get_log = pnv_eeh_get_log,
1649 .configure_bridge = pnv_eeh_configure_bridge,
1650 .err_inject = pnv_eeh_err_inject,
1651 .read_config = pnv_eeh_read_config,
1652 .write_config = pnv_eeh_write_config,
1653 .next_error = pnv_eeh_next_error,
1654 .restore_config = pnv_eeh_restore_config,
1655 .notify_resume = NULL
1658 #ifdef CONFIG_PCI_IOV
1659 static void pnv_pci_fixup_vf_mps(struct pci_dev *pdev)
1661 struct pci_dn *pdn = pci_get_pdn(pdev);
1664 if (!pdev->is_virtfn)
1667 /* Synchronize MPS for VF and PF */
1668 parent_mps = pcie_get_mps(pdev->physfn);
1669 if ((128 << pdev->pcie_mpss) >= parent_mps)
1670 pcie_set_mps(pdev, parent_mps);
1671 pdn->mps = pcie_get_mps(pdev);
1673 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_pci_fixup_vf_mps);
1674 #endif /* CONFIG_PCI_IOV */
1677 * eeh_powernv_init - Register platform dependent EEH operations
1679 * EEH initialization on powernv platform. This function should be
1680 * called before any EEH related functions.
1682 static int __init eeh_powernv_init(void)
1686 ret = eeh_ops_register(&pnv_eeh_ops);
1688 pr_info("EEH: PowerNV platform initialized\n");
1690 pr_info("EEH: Failed to initialize PowerNV platform (%d)\n", ret);
1694 machine_early_initcall(powernv, eeh_powernv_init);