2 * The file intends to implement the platform dependent EEH operations on
3 * powernv platform. Actually, the powernv was created in order to fully
6 * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2013.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/atomic.h>
15 #include <linux/debugfs.h>
16 #include <linux/delay.h>
17 #include <linux/export.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/list.h>
21 #include <linux/msi.h>
23 #include <linux/pci.h>
24 #include <linux/proc_fs.h>
25 #include <linux/rbtree.h>
26 #include <linux/sched.h>
27 #include <linux/seq_file.h>
28 #include <linux/spinlock.h>
31 #include <asm/eeh_event.h>
32 #include <asm/firmware.h>
34 #include <asm/iommu.h>
35 #include <asm/machdep.h>
36 #include <asm/msi_bitmap.h>
38 #include <asm/ppc-pci.h>
39 #include <asm/pnv-pci.h>
44 static int eeh_event_irq = -EINVAL;
46 void pnv_pcibios_bus_add_device(struct pci_dev *pdev)
48 struct pci_dn *pdn = pci_get_pdn(pdev);
54 * The following operations will fail if VF's sysfs files
55 * aren't created or its resources aren't finalized.
57 eeh_add_device_early(pdn);
58 eeh_add_device_late(pdev);
59 eeh_sysfs_add_device(pdev);
62 static int pnv_eeh_init(void)
64 struct pci_controller *hose;
66 int max_diag_size = PNV_PCI_DIAG_BUF_SIZE;
68 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
69 pr_warn("%s: OPAL is required !\n",
75 eeh_add_flag(EEH_PROBE_MODE_DEV);
78 * P7IOC blocks PCI config access to frozen PE, but PHB3
79 * doesn't do that. So we have to selectively enable I/O
80 * prior to collecting error log.
82 list_for_each_entry(hose, &hose_list, list_node) {
83 phb = hose->private_data;
85 if (phb->model == PNV_PHB_MODEL_P7IOC)
86 eeh_add_flag(EEH_ENABLE_IO_FOR_LOG);
88 if (phb->diag_data_size > max_diag_size)
89 max_diag_size = phb->diag_data_size;
92 * PE#0 should be regarded as valid by EEH core
93 * if it's not the reserved one. Currently, we
94 * have the reserved PE#255 and PE#127 for PHB3
95 * and P7IOC separately. So we should regard
96 * PE#0 as valid for PHB3 and P7IOC.
98 if (phb->ioda.reserved_pe_idx != 0)
99 eeh_add_flag(EEH_VALID_PE_ZERO);
104 eeh_set_pe_aux_size(max_diag_size);
105 ppc_md.pcibios_bus_add_device = pnv_pcibios_bus_add_device;
110 static irqreturn_t pnv_eeh_event(int irq, void *data)
113 * We simply send a special EEH event if EEH has been
114 * enabled. We don't care about EEH events until we've
115 * finished processing the outstanding ones. Event processing
116 * gets unmasked in next_error() if EEH is enabled.
118 disable_irq_nosync(irq);
121 eeh_send_failure_event(NULL);
126 #ifdef CONFIG_DEBUG_FS
127 static ssize_t pnv_eeh_ei_write(struct file *filp,
128 const char __user *user_buf,
129 size_t count, loff_t *ppos)
131 struct pci_controller *hose = filp->private_data;
133 int pe_no, type, func;
134 unsigned long addr, mask;
138 if (!eeh_ops || !eeh_ops->err_inject)
141 /* Copy over argument buffer */
142 ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
146 /* Retrieve parameters */
147 ret = sscanf(buf, "%x:%x:%x:%lx:%lx",
148 &pe_no, &type, &func, &addr, &mask);
153 pe = eeh_pe_get(hose, pe_no, 0);
157 /* Do error injection */
158 ret = eeh_ops->err_inject(pe, type, func, addr, mask);
159 return ret < 0 ? ret : count;
162 static const struct file_operations pnv_eeh_ei_fops = {
165 .write = pnv_eeh_ei_write,
168 static int pnv_eeh_dbgfs_set(void *data, int offset, u64 val)
170 struct pci_controller *hose = data;
171 struct pnv_phb *phb = hose->private_data;
173 out_be64(phb->regs + offset, val);
177 static int pnv_eeh_dbgfs_get(void *data, int offset, u64 *val)
179 struct pci_controller *hose = data;
180 struct pnv_phb *phb = hose->private_data;
182 *val = in_be64(phb->regs + offset);
186 #define PNV_EEH_DBGFS_ENTRY(name, reg) \
187 static int pnv_eeh_dbgfs_set_##name(void *data, u64 val) \
189 return pnv_eeh_dbgfs_set(data, reg, val); \
192 static int pnv_eeh_dbgfs_get_##name(void *data, u64 *val) \
194 return pnv_eeh_dbgfs_get(data, reg, val); \
197 DEFINE_SIMPLE_ATTRIBUTE(pnv_eeh_dbgfs_ops_##name, \
198 pnv_eeh_dbgfs_get_##name, \
199 pnv_eeh_dbgfs_set_##name, \
202 PNV_EEH_DBGFS_ENTRY(outb, 0xD10);
203 PNV_EEH_DBGFS_ENTRY(inbA, 0xD90);
204 PNV_EEH_DBGFS_ENTRY(inbB, 0xE10);
206 #endif /* CONFIG_DEBUG_FS */
209 * pnv_eeh_post_init - EEH platform dependent post initialization
211 * EEH platform dependent post initialization on powernv. When
212 * the function is called, the EEH PEs and devices should have
213 * been built. If the I/O cache staff has been built, EEH is
214 * ready to supply service.
216 int pnv_eeh_post_init(void)
218 struct pci_controller *hose;
222 /* Probe devices & build address cache */
224 eeh_addr_cache_build();
226 /* Register OPAL event notifier */
227 eeh_event_irq = opal_event_request(ilog2(OPAL_EVENT_PCI_ERROR));
228 if (eeh_event_irq < 0) {
229 pr_err("%s: Can't register OPAL event interrupt (%d)\n",
230 __func__, eeh_event_irq);
231 return eeh_event_irq;
234 ret = request_irq(eeh_event_irq, pnv_eeh_event,
235 IRQ_TYPE_LEVEL_HIGH, "opal-eeh", NULL);
237 irq_dispose_mapping(eeh_event_irq);
238 pr_err("%s: Can't request OPAL event interrupt (%d)\n",
239 __func__, eeh_event_irq);
244 disable_irq(eeh_event_irq);
246 list_for_each_entry(hose, &hose_list, list_node) {
247 phb = hose->private_data;
250 * If EEH is enabled, we're going to rely on that.
251 * Otherwise, we restore to conventional mechanism
252 * to clear frozen PE during PCI config access.
255 phb->flags |= PNV_PHB_FLAG_EEH;
257 phb->flags &= ~PNV_PHB_FLAG_EEH;
259 /* Create debugfs entries */
260 #ifdef CONFIG_DEBUG_FS
261 if (phb->has_dbgfs || !phb->dbgfs)
265 debugfs_create_file("err_injct", 0200,
269 debugfs_create_file("err_injct_outbound", 0600,
271 &pnv_eeh_dbgfs_ops_outb);
272 debugfs_create_file("err_injct_inboundA", 0600,
274 &pnv_eeh_dbgfs_ops_inbA);
275 debugfs_create_file("err_injct_inboundB", 0600,
277 &pnv_eeh_dbgfs_ops_inbB);
278 #endif /* CONFIG_DEBUG_FS */
284 static int pnv_eeh_find_cap(struct pci_dn *pdn, int cap)
286 int pos = PCI_CAPABILITY_LIST;
287 int cnt = 48; /* Maximal number of capabilities */
293 /* Check if the device supports capabilities */
294 pnv_pci_cfg_read(pdn, PCI_STATUS, 2, &status);
295 if (!(status & PCI_STATUS_CAP_LIST))
299 pnv_pci_cfg_read(pdn, pos, 1, &pos);
304 pnv_pci_cfg_read(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
313 pos += PCI_CAP_LIST_NEXT;
319 static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
321 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
323 int pos = 256, ttl = (4096 - 256) / 8;
325 if (!edev || !edev->pcie_cap)
327 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
333 if (PCI_EXT_CAP_ID(header) == cap && pos)
336 pos = PCI_EXT_CAP_NEXT(header);
340 if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
348 * pnv_eeh_probe - Do probe on PCI device
349 * @pdn: PCI device node
352 * When EEH module is installed during system boot, all PCI devices
353 * are checked one by one to see if it supports EEH. The function
354 * is introduced for the purpose. By default, EEH has been enabled
355 * on all PCI devices. That's to say, we only need do necessary
356 * initialization on the corresponding eeh device and create PE
359 * It's notable that's unsafe to retrieve the EEH device through
360 * the corresponding PCI device. During the PCI device hotplug, which
361 * was possiblly triggered by EEH core, the binding between EEH device
362 * and the PCI device isn't built yet.
364 static void *pnv_eeh_probe(struct pci_dn *pdn, void *data)
366 struct pci_controller *hose = pdn->phb;
367 struct pnv_phb *phb = hose->private_data;
368 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
371 int config_addr = (pdn->busno << 8) | (pdn->devfn);
374 * When probing the root bridge, which doesn't have any
375 * subordinate PCI devices. We don't have OF node for
376 * the root bridge. So it's not reasonable to continue
379 if (!edev || edev->pe)
382 /* Skip for PCI-ISA bridge */
383 if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)
386 /* Initialize eeh device */
387 edev->class_code = pdn->class_code;
388 edev->mode &= 0xFFFFFF00;
389 edev->pcix_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
390 edev->pcie_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
391 edev->af_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_AF);
392 edev->aer_cap = pnv_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
393 if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
394 edev->mode |= EEH_DEV_BRIDGE;
395 if (edev->pcie_cap) {
396 pnv_pci_cfg_read(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
398 pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
399 if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
400 edev->mode |= EEH_DEV_ROOT_PORT;
401 else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
402 edev->mode |= EEH_DEV_DS_PORT;
406 edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
409 ret = eeh_add_to_parent_pe(edev);
411 pr_warn("%s: Can't add PCI dev %04x:%02x:%02x.%01x to parent PE (%x)\n",
412 __func__, hose->global_number, pdn->busno,
413 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn), ret);
418 * If the PE contains any one of following adapters, the
419 * PCI config space can't be accessed when dumping EEH log.
420 * Otherwise, we will run into fenced PHB caused by shortage
421 * of outbound credits in the adapter. The PCI config access
422 * should be blocked until PE reset. MMIO access is dropped
423 * by hardware certainly. In order to drop PCI config requests,
424 * one more flag (EEH_PE_CFG_RESTRICTED) is introduced, which
425 * will be checked in the backend for PE state retrival. If
426 * the PE becomes frozen for the first time and the flag has
427 * been set for the PE, we will set EEH_PE_CFG_BLOCKED for
428 * that PE to block its config space.
430 * Broadcom BCM5718 2-ports NICs (14e4:1656)
431 * Broadcom Austin 4-ports NICs (14e4:1657)
432 * Broadcom Shiner 4-ports 1G NICs (14e4:168a)
433 * Broadcom Shiner 2-ports 10G NICs (14e4:168e)
435 if ((pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
436 pdn->device_id == 0x1656) ||
437 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
438 pdn->device_id == 0x1657) ||
439 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
440 pdn->device_id == 0x168a) ||
441 (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
442 pdn->device_id == 0x168e))
443 edev->pe->state |= EEH_PE_CFG_RESTRICTED;
446 * Cache the PE primary bus, which can't be fetched when
447 * full hotplug is in progress. In that case, all child
448 * PCI devices of the PE are expected to be removed prior
451 if (!(edev->pe->state & EEH_PE_PRI_BUS)) {
452 edev->pe->bus = pci_find_bus(hose->global_number,
455 edev->pe->state |= EEH_PE_PRI_BUS;
459 * Enable EEH explicitly so that we will do EEH check
460 * while accessing I/O stuff
462 eeh_add_flag(EEH_ENABLED);
464 /* Save memory bars */
471 * pnv_eeh_set_option - Initialize EEH or MMIO/DMA reenable
473 * @option: operation to be issued
475 * The function is used to control the EEH functionality globally.
476 * Currently, following options are support according to PAPR:
477 * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
479 static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
481 struct pci_controller *hose = pe->phb;
482 struct pnv_phb *phb = hose->private_data;
483 bool freeze_pe = false;
488 case EEH_OPT_DISABLE:
492 case EEH_OPT_THAW_MMIO:
493 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO;
495 case EEH_OPT_THAW_DMA:
496 opt = OPAL_EEH_ACTION_CLEAR_FREEZE_DMA;
498 case EEH_OPT_FREEZE_PE:
500 opt = OPAL_EEH_ACTION_SET_FREEZE_ALL;
503 pr_warn("%s: Invalid option %d\n", __func__, option);
507 /* Freeze master and slave PEs if PHB supports compound PEs */
509 if (phb->freeze_pe) {
510 phb->freeze_pe(phb, pe->addr);
514 rc = opal_pci_eeh_freeze_set(phb->opal_id, pe->addr, opt);
515 if (rc != OPAL_SUCCESS) {
516 pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",
517 __func__, rc, phb->hose->global_number,
525 /* Unfreeze master and slave PEs if PHB supports */
526 if (phb->unfreeze_pe)
527 return phb->unfreeze_pe(phb, pe->addr, opt);
529 rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe->addr, opt);
530 if (rc != OPAL_SUCCESS) {
531 pr_warn("%s: Failure %lld enable %d for PHB#%x-PE#%x\n",
532 __func__, rc, option, phb->hose->global_number,
541 * pnv_eeh_get_pe_addr - Retrieve PE address
544 * Retrieve the PE address according to the given tranditional
545 * PCI BDF (Bus/Device/Function) address.
547 static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
552 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
554 struct pnv_phb *phb = pe->phb->private_data;
557 rc = opal_pci_get_phb_diag_data2(phb->opal_id, pe->data,
558 phb->diag_data_size);
559 if (rc != OPAL_SUCCESS)
560 pr_warn("%s: Failure %lld getting PHB#%x diag-data\n",
561 __func__, rc, pe->phb->global_number);
564 static int pnv_eeh_get_phb_state(struct eeh_pe *pe)
566 struct pnv_phb *phb = pe->phb->private_data;
572 rc = opal_pci_eeh_freeze_status(phb->opal_id,
577 if (rc != OPAL_SUCCESS) {
578 pr_warn("%s: Failure %lld getting PHB#%x state\n",
579 __func__, rc, phb->hose->global_number);
580 return EEH_STATE_NOT_SUPPORT;
584 * Check PHB state. If the PHB is frozen for the
585 * first time, to dump the PHB diag-data.
587 if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
588 result = (EEH_STATE_MMIO_ACTIVE |
589 EEH_STATE_DMA_ACTIVE |
590 EEH_STATE_MMIO_ENABLED |
591 EEH_STATE_DMA_ENABLED);
592 } else if (!(pe->state & EEH_PE_ISOLATED)) {
593 eeh_pe_mark_isolated(pe);
594 pnv_eeh_get_phb_diag(pe);
596 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
597 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
603 static int pnv_eeh_get_pe_state(struct eeh_pe *pe)
605 struct pnv_phb *phb = pe->phb->private_data;
612 * We don't clobber hardware frozen state until PE
613 * reset is completed. In order to keep EEH core
614 * moving forward, we have to return operational
615 * state during PE reset.
617 if (pe->state & EEH_PE_RESET) {
618 result = (EEH_STATE_MMIO_ACTIVE |
619 EEH_STATE_DMA_ACTIVE |
620 EEH_STATE_MMIO_ENABLED |
621 EEH_STATE_DMA_ENABLED);
626 * Fetch PE state from hardware. If the PHB
627 * supports compound PE, let it handle that.
629 if (phb->get_pe_state) {
630 fstate = phb->get_pe_state(phb, pe->addr);
632 rc = opal_pci_eeh_freeze_status(phb->opal_id,
637 if (rc != OPAL_SUCCESS) {
638 pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
639 __func__, rc, phb->hose->global_number,
641 return EEH_STATE_NOT_SUPPORT;
645 /* Figure out state */
647 case OPAL_EEH_STOPPED_NOT_FROZEN:
648 result = (EEH_STATE_MMIO_ACTIVE |
649 EEH_STATE_DMA_ACTIVE |
650 EEH_STATE_MMIO_ENABLED |
651 EEH_STATE_DMA_ENABLED);
653 case OPAL_EEH_STOPPED_MMIO_FREEZE:
654 result = (EEH_STATE_DMA_ACTIVE |
655 EEH_STATE_DMA_ENABLED);
657 case OPAL_EEH_STOPPED_DMA_FREEZE:
658 result = (EEH_STATE_MMIO_ACTIVE |
659 EEH_STATE_MMIO_ENABLED);
661 case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
664 case OPAL_EEH_STOPPED_RESET:
665 result = EEH_STATE_RESET_ACTIVE;
667 case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
668 result = EEH_STATE_UNAVAILABLE;
670 case OPAL_EEH_STOPPED_PERM_UNAVAIL:
671 result = EEH_STATE_NOT_SUPPORT;
674 result = EEH_STATE_NOT_SUPPORT;
675 pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
676 __func__, phb->hose->global_number,
681 * If PHB supports compound PE, to freeze all
682 * slave PEs for consistency.
684 * If the PE is switching to frozen state for the
685 * first time, to dump the PHB diag-data.
687 if (!(result & EEH_STATE_NOT_SUPPORT) &&
688 !(result & EEH_STATE_UNAVAILABLE) &&
689 !(result & EEH_STATE_MMIO_ACTIVE) &&
690 !(result & EEH_STATE_DMA_ACTIVE) &&
691 !(pe->state & EEH_PE_ISOLATED)) {
693 phb->freeze_pe(phb, pe->addr);
695 eeh_pe_mark_isolated(pe);
696 pnv_eeh_get_phb_diag(pe);
698 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
699 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
706 * pnv_eeh_get_state - Retrieve PE state
708 * @delay: delay while PE state is temporarily unavailable
710 * Retrieve the state of the specified PE. For IODA-compitable
711 * platform, it should be retrieved from IODA table. Therefore,
712 * we prefer passing down to hardware implementation to handle
715 static int pnv_eeh_get_state(struct eeh_pe *pe, int *delay)
719 if (pe->type & EEH_PE_PHB)
720 ret = pnv_eeh_get_phb_state(pe);
722 ret = pnv_eeh_get_pe_state(pe);
728 * If the PE state is temporarily unavailable,
729 * to inform the EEH core delay for default
733 if (ret & EEH_STATE_UNAVAILABLE)
739 static s64 pnv_eeh_poll(unsigned long id)
741 s64 rc = OPAL_HARDWARE;
744 rc = opal_pci_poll(id);
748 if (system_state < SYSTEM_RUNNING)
757 int pnv_eeh_phb_reset(struct pci_controller *hose, int option)
759 struct pnv_phb *phb = hose->private_data;
760 s64 rc = OPAL_HARDWARE;
762 pr_debug("%s: Reset PHB#%x, option=%d\n",
763 __func__, hose->global_number, option);
765 /* Issue PHB complete reset request */
766 if (option == EEH_RESET_FUNDAMENTAL ||
767 option == EEH_RESET_HOT)
768 rc = opal_pci_reset(phb->opal_id,
769 OPAL_RESET_PHB_COMPLETE,
771 else if (option == EEH_RESET_DEACTIVATE)
772 rc = opal_pci_reset(phb->opal_id,
773 OPAL_RESET_PHB_COMPLETE,
774 OPAL_DEASSERT_RESET);
779 * Poll state of the PHB until the request is done
780 * successfully. The PHB reset is usually PHB complete
781 * reset followed by hot reset on root bus. So we also
782 * need the PCI bus settlement delay.
785 rc = pnv_eeh_poll(phb->opal_id);
786 if (option == EEH_RESET_DEACTIVATE) {
787 if (system_state < SYSTEM_RUNNING)
788 udelay(1000 * EEH_PE_RST_SETTLE_TIME);
790 msleep(EEH_PE_RST_SETTLE_TIME);
793 if (rc != OPAL_SUCCESS)
799 static int pnv_eeh_root_reset(struct pci_controller *hose, int option)
801 struct pnv_phb *phb = hose->private_data;
802 s64 rc = OPAL_HARDWARE;
804 pr_debug("%s: Reset PHB#%x, option=%d\n",
805 __func__, hose->global_number, option);
808 * During the reset deassert time, we needn't care
809 * the reset scope because the firmware does nothing
810 * for fundamental or hot reset during deassert phase.
812 if (option == EEH_RESET_FUNDAMENTAL)
813 rc = opal_pci_reset(phb->opal_id,
814 OPAL_RESET_PCI_FUNDAMENTAL,
816 else if (option == EEH_RESET_HOT)
817 rc = opal_pci_reset(phb->opal_id,
820 else if (option == EEH_RESET_DEACTIVATE)
821 rc = opal_pci_reset(phb->opal_id,
823 OPAL_DEASSERT_RESET);
827 /* Poll state of the PHB until the request is done */
829 rc = pnv_eeh_poll(phb->opal_id);
830 if (option == EEH_RESET_DEACTIVATE)
831 msleep(EEH_PE_RST_SETTLE_TIME);
833 if (rc != OPAL_SUCCESS)
839 static int __pnv_eeh_bridge_reset(struct pci_dev *dev, int option)
841 struct pci_dn *pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
842 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
843 int aer = edev ? edev->aer_cap : 0;
846 pr_debug("%s: Reset PCI bus %04x:%02x with option %d\n",
847 __func__, pci_domain_nr(dev->bus),
848 dev->bus->number, option);
851 case EEH_RESET_FUNDAMENTAL:
853 /* Don't report linkDown event */
855 eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
857 ctrl |= PCI_ERR_UNC_SURPDN;
858 eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
862 eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
863 ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
864 eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
866 msleep(EEH_PE_RST_HOLD_TIME);
868 case EEH_RESET_DEACTIVATE:
869 eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
870 ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
871 eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
873 msleep(EEH_PE_RST_SETTLE_TIME);
875 /* Continue reporting linkDown event */
877 eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
879 ctrl &= ~PCI_ERR_UNC_SURPDN;
880 eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
890 static int pnv_eeh_bridge_reset(struct pci_dev *pdev, int option)
892 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
893 struct pnv_phb *phb = hose->private_data;
894 struct device_node *dn = pci_device_to_OF_node(pdev);
895 uint64_t id = PCI_SLOT_ID(phb->opal_id,
896 (pdev->bus->number << 8) | pdev->devfn);
900 /* Hot reset to the bus if firmware cannot handle */
901 if (!dn || !of_get_property(dn, "ibm,reset-by-firmware", NULL))
902 return __pnv_eeh_bridge_reset(pdev, option);
905 case EEH_RESET_FUNDAMENTAL:
906 scope = OPAL_RESET_PCI_FUNDAMENTAL;
909 scope = OPAL_RESET_PCI_HOT;
911 case EEH_RESET_DEACTIVATE:
914 dev_dbg(&pdev->dev, "%s: Unsupported reset %d\n",
919 rc = opal_pci_reset(id, scope, OPAL_ASSERT_RESET);
920 if (rc <= OPAL_SUCCESS)
923 rc = pnv_eeh_poll(id);
925 return (rc == OPAL_SUCCESS) ? 0 : -EIO;
928 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
930 struct pci_controller *hose;
932 if (pci_is_root_bus(dev->bus)) {
933 hose = pci_bus_to_host(dev->bus);
934 pnv_eeh_root_reset(hose, EEH_RESET_HOT);
935 pnv_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
937 pnv_eeh_bridge_reset(dev, EEH_RESET_HOT);
938 pnv_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
942 static void pnv_eeh_wait_for_pending(struct pci_dn *pdn, const char *type,
947 /* Wait for Transaction Pending bit to be cleared */
948 for (i = 0; i < 4; i++) {
949 eeh_ops->read_config(pdn, pos, 2, &status);
950 if (!(status & mask))
953 msleep((1 << i) * 100);
956 pr_warn("%s: Pending transaction while issuing %sFLR to %04x:%02x:%02x.%01x\n",
958 pdn->phb->global_number, pdn->busno,
959 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
962 static int pnv_eeh_do_flr(struct pci_dn *pdn, int option)
964 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
967 if (WARN_ON(!edev->pcie_cap))
970 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCAP, 4, ®);
971 if (!(reg & PCI_EXP_DEVCAP_FLR))
976 case EEH_RESET_FUNDAMENTAL:
977 pnv_eeh_wait_for_pending(pdn, "",
978 edev->pcie_cap + PCI_EXP_DEVSTA,
979 PCI_EXP_DEVSTA_TRPND);
980 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
982 reg |= PCI_EXP_DEVCTL_BCR_FLR;
983 eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
985 msleep(EEH_PE_RST_HOLD_TIME);
987 case EEH_RESET_DEACTIVATE:
988 eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
990 reg &= ~PCI_EXP_DEVCTL_BCR_FLR;
991 eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
993 msleep(EEH_PE_RST_SETTLE_TIME);
1000 static int pnv_eeh_do_af_flr(struct pci_dn *pdn, int option)
1002 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1005 if (WARN_ON(!edev->af_cap))
1008 eeh_ops->read_config(pdn, edev->af_cap + PCI_AF_CAP, 1, &cap);
1009 if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
1014 case EEH_RESET_FUNDAMENTAL:
1016 * Wait for Transaction Pending bit to clear. A word-aligned
1017 * test is used, so we use the conrol offset rather than status
1018 * and shift the test bit to match.
1020 pnv_eeh_wait_for_pending(pdn, "AF",
1021 edev->af_cap + PCI_AF_CTRL,
1022 PCI_AF_STATUS_TP << 8);
1023 eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL,
1024 1, PCI_AF_CTRL_FLR);
1025 msleep(EEH_PE_RST_HOLD_TIME);
1027 case EEH_RESET_DEACTIVATE:
1028 eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL, 1, 0);
1029 msleep(EEH_PE_RST_SETTLE_TIME);
1036 static int pnv_eeh_reset_vf_pe(struct eeh_pe *pe, int option)
1038 struct eeh_dev *edev;
1042 /* The VF PE should have only one child device */
1043 edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, entry);
1044 pdn = eeh_dev_to_pdn(edev);
1048 ret = pnv_eeh_do_flr(pdn, option);
1052 return pnv_eeh_do_af_flr(pdn, option);
1056 * pnv_eeh_reset - Reset the specified PE
1058 * @option: reset option
1060 * Do reset on the indicated PE. For PCI bus sensitive PE,
1061 * we need to reset the parent p2p bridge. The PHB has to
1062 * be reinitialized if the p2p bridge is root bridge. For
1063 * PCI device sensitive PE, we will try to reset the device
1064 * through FLR. For now, we don't have OPAL APIs to do HARD
1065 * reset yet, so all reset would be SOFT (HOT) reset.
1067 static int pnv_eeh_reset(struct eeh_pe *pe, int option)
1069 struct pci_controller *hose = pe->phb;
1070 struct pnv_phb *phb;
1071 struct pci_bus *bus;
1075 * For PHB reset, we always have complete reset. For those PEs whose
1076 * primary bus derived from root complex (root bus) or root port
1077 * (usually bus#1), we apply hot or fundamental reset on the root port.
1078 * For other PEs, we always have hot reset on the PE primary bus.
1080 * Here, we have different design to pHyp, which always clear the
1081 * frozen state during PE reset. However, the good idea here from
1082 * benh is to keep frozen state before we get PE reset done completely
1083 * (until BAR restore). With the frozen state, HW drops illegal IO
1084 * or MMIO access, which can incur recrusive frozen PE during PE
1085 * reset. The side effect is that EEH core has to clear the frozen
1086 * state explicitly after BAR restore.
1088 if (pe->type & EEH_PE_PHB)
1089 return pnv_eeh_phb_reset(hose, option);
1092 * The frozen PE might be caused by PAPR error injection
1093 * registers, which are expected to be cleared after hitting
1094 * frozen PE as stated in the hardware spec. Unfortunately,
1095 * that's not true on P7IOC. So we have to clear it manually
1096 * to avoid recursive EEH errors during recovery.
1098 phb = hose->private_data;
1099 if (phb->model == PNV_PHB_MODEL_P7IOC &&
1100 (option == EEH_RESET_HOT ||
1101 option == EEH_RESET_FUNDAMENTAL)) {
1102 rc = opal_pci_reset(phb->opal_id,
1103 OPAL_RESET_PHB_ERROR,
1105 if (rc != OPAL_SUCCESS) {
1106 pr_warn("%s: Failure %lld clearing error injection registers\n",
1112 if (pe->type & EEH_PE_VF)
1113 return pnv_eeh_reset_vf_pe(pe, option);
1115 bus = eeh_pe_bus_get(pe);
1117 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
1118 __func__, pe->phb->global_number, pe->addr);
1123 * If dealing with the root bus (or the bus underneath the
1124 * root port), we reset the bus underneath the root port.
1126 * The cxl driver depends on this behaviour for bi-modal card
1129 if (pci_is_root_bus(bus) ||
1130 pci_is_root_bus(bus->parent))
1131 return pnv_eeh_root_reset(hose, option);
1133 return pnv_eeh_bridge_reset(bus->self, option);
1137 * pnv_eeh_get_log - Retrieve error log
1139 * @severity: temporary or permanent error log
1140 * @drv_log: driver log to be combined with retrieved error log
1141 * @len: length of driver log
1143 * Retrieve the temporary or permanent error from the PE.
1145 static int pnv_eeh_get_log(struct eeh_pe *pe, int severity,
1146 char *drv_log, unsigned long len)
1148 if (!eeh_has_flag(EEH_EARLY_DUMP_LOG))
1149 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
1155 * pnv_eeh_configure_bridge - Configure PCI bridges in the indicated PE
1158 * The function will be called to reconfigure the bridges included
1159 * in the specified PE so that the mulfunctional PE would be recovered
1162 static int pnv_eeh_configure_bridge(struct eeh_pe *pe)
1168 * pnv_pe_err_inject - Inject specified error to the indicated PE
1169 * @pe: the indicated PE
1171 * @func: specific error type
1173 * @mask: address mask
1175 * The routine is called to inject specified error, which is
1176 * determined by @type and @func, to the indicated PE for
1179 static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
1180 unsigned long addr, unsigned long mask)
1182 struct pci_controller *hose = pe->phb;
1183 struct pnv_phb *phb = hose->private_data;
1186 if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
1187 type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
1188 pr_warn("%s: Invalid error type %d\n",
1193 if (func < OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR ||
1194 func > OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET) {
1195 pr_warn("%s: Invalid error function %d\n",
1200 /* Firmware supports error injection ? */
1201 if (!opal_check_token(OPAL_PCI_ERR_INJECT)) {
1202 pr_warn("%s: Firmware doesn't support error injection\n",
1207 /* Do error injection */
1208 rc = opal_pci_err_inject(phb->opal_id, pe->addr,
1209 type, func, addr, mask);
1210 if (rc != OPAL_SUCCESS) {
1211 pr_warn("%s: Failure %lld injecting error "
1212 "%d-%d to PHB#%x-PE#%x\n",
1213 __func__, rc, type, func,
1214 hose->global_number, pe->addr);
1221 static inline bool pnv_eeh_cfg_blocked(struct pci_dn *pdn)
1223 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1225 if (!edev || !edev->pe)
1229 * We will issue FLR or AF FLR to all VFs, which are contained
1230 * in VF PE. It relies on the EEH PCI config accessors. So we
1231 * can't block them during the window.
1233 if (edev->physfn && (edev->pe->state & EEH_PE_RESET))
1236 if (edev->pe->state & EEH_PE_CFG_BLOCKED)
1242 static int pnv_eeh_read_config(struct pci_dn *pdn,
1243 int where, int size, u32 *val)
1246 return PCIBIOS_DEVICE_NOT_FOUND;
1248 if (pnv_eeh_cfg_blocked(pdn)) {
1250 return PCIBIOS_SET_FAILED;
1253 return pnv_pci_cfg_read(pdn, where, size, val);
1256 static int pnv_eeh_write_config(struct pci_dn *pdn,
1257 int where, int size, u32 val)
1260 return PCIBIOS_DEVICE_NOT_FOUND;
1262 if (pnv_eeh_cfg_blocked(pdn))
1263 return PCIBIOS_SET_FAILED;
1265 return pnv_pci_cfg_write(pdn, where, size, val);
1268 static void pnv_eeh_dump_hub_diag_common(struct OpalIoP7IOCErrorData *data)
1271 if (data->gemXfir || data->gemRfir ||
1272 data->gemRirqfir || data->gemMask || data->gemRwof)
1273 pr_info(" GEM: %016llx %016llx %016llx %016llx %016llx\n",
1274 be64_to_cpu(data->gemXfir),
1275 be64_to_cpu(data->gemRfir),
1276 be64_to_cpu(data->gemRirqfir),
1277 be64_to_cpu(data->gemMask),
1278 be64_to_cpu(data->gemRwof));
1281 if (data->lemFir || data->lemErrMask ||
1282 data->lemAction0 || data->lemAction1 || data->lemWof)
1283 pr_info(" LEM: %016llx %016llx %016llx %016llx %016llx\n",
1284 be64_to_cpu(data->lemFir),
1285 be64_to_cpu(data->lemErrMask),
1286 be64_to_cpu(data->lemAction0),
1287 be64_to_cpu(data->lemAction1),
1288 be64_to_cpu(data->lemWof));
1291 static void pnv_eeh_get_and_dump_hub_diag(struct pci_controller *hose)
1293 struct pnv_phb *phb = hose->private_data;
1294 struct OpalIoP7IOCErrorData *data =
1295 (struct OpalIoP7IOCErrorData*)phb->diag_data;
1298 rc = opal_pci_get_hub_diag_data(phb->hub_id, data, sizeof(*data));
1299 if (rc != OPAL_SUCCESS) {
1300 pr_warn("%s: Failed to get HUB#%llx diag-data (%ld)\n",
1301 __func__, phb->hub_id, rc);
1305 switch (be16_to_cpu(data->type)) {
1306 case OPAL_P7IOC_DIAG_TYPE_RGC:
1307 pr_info("P7IOC diag-data for RGC\n\n");
1308 pnv_eeh_dump_hub_diag_common(data);
1309 if (data->rgc.rgcStatus || data->rgc.rgcLdcp)
1310 pr_info(" RGC: %016llx %016llx\n",
1311 be64_to_cpu(data->rgc.rgcStatus),
1312 be64_to_cpu(data->rgc.rgcLdcp));
1314 case OPAL_P7IOC_DIAG_TYPE_BI:
1315 pr_info("P7IOC diag-data for BI %s\n\n",
1316 data->bi.biDownbound ? "Downbound" : "Upbound");
1317 pnv_eeh_dump_hub_diag_common(data);
1318 if (data->bi.biLdcp0 || data->bi.biLdcp1 ||
1319 data->bi.biLdcp2 || data->bi.biFenceStatus)
1320 pr_info(" BI: %016llx %016llx %016llx %016llx\n",
1321 be64_to_cpu(data->bi.biLdcp0),
1322 be64_to_cpu(data->bi.biLdcp1),
1323 be64_to_cpu(data->bi.biLdcp2),
1324 be64_to_cpu(data->bi.biFenceStatus));
1326 case OPAL_P7IOC_DIAG_TYPE_CI:
1327 pr_info("P7IOC diag-data for CI Port %d\n\n",
1329 pnv_eeh_dump_hub_diag_common(data);
1330 if (data->ci.ciPortStatus || data->ci.ciPortLdcp)
1331 pr_info(" CI: %016llx %016llx\n",
1332 be64_to_cpu(data->ci.ciPortStatus),
1333 be64_to_cpu(data->ci.ciPortLdcp));
1335 case OPAL_P7IOC_DIAG_TYPE_MISC:
1336 pr_info("P7IOC diag-data for MISC\n\n");
1337 pnv_eeh_dump_hub_diag_common(data);
1339 case OPAL_P7IOC_DIAG_TYPE_I2C:
1340 pr_info("P7IOC diag-data for I2C\n\n");
1341 pnv_eeh_dump_hub_diag_common(data);
1344 pr_warn("%s: Invalid type of HUB#%llx diag-data (%d)\n",
1345 __func__, phb->hub_id, data->type);
1349 static int pnv_eeh_get_pe(struct pci_controller *hose,
1350 u16 pe_no, struct eeh_pe **pe)
1352 struct pnv_phb *phb = hose->private_data;
1353 struct pnv_ioda_pe *pnv_pe;
1354 struct eeh_pe *dev_pe;
1357 * If PHB supports compound PE, to fetch
1358 * the master PE because slave PE is invisible
1361 pnv_pe = &phb->ioda.pe_array[pe_no];
1362 if (pnv_pe->flags & PNV_IODA_PE_SLAVE) {
1363 pnv_pe = pnv_pe->master;
1365 !(pnv_pe->flags & PNV_IODA_PE_MASTER));
1366 pe_no = pnv_pe->pe_number;
1369 /* Find the PE according to PE# */
1370 dev_pe = eeh_pe_get(hose, pe_no, 0);
1374 /* Freeze the (compound) PE */
1376 if (!(dev_pe->state & EEH_PE_ISOLATED))
1377 phb->freeze_pe(phb, pe_no);
1380 * At this point, we're sure the (compound) PE should
1381 * have been frozen. However, we still need poke until
1382 * hitting the frozen PE on top level.
1384 dev_pe = dev_pe->parent;
1385 while (dev_pe && !(dev_pe->type & EEH_PE_PHB)) {
1387 ret = eeh_ops->get_state(dev_pe, NULL);
1388 if (ret <= 0 || eeh_state_active(ret)) {
1389 dev_pe = dev_pe->parent;
1393 /* Frozen parent PE */
1395 if (!(dev_pe->state & EEH_PE_ISOLATED))
1396 phb->freeze_pe(phb, dev_pe->addr);
1399 dev_pe = dev_pe->parent;
1406 * pnv_eeh_next_error - Retrieve next EEH error to handle
1409 * The function is expected to be called by EEH core while it gets
1410 * special EEH event (without binding PE). The function calls to
1411 * OPAL APIs for next error to handle. The informational error is
1412 * handled internally by platform. However, the dead IOC, dead PHB,
1413 * fenced PHB and frozen PE should be handled by EEH core eventually.
1415 static int pnv_eeh_next_error(struct eeh_pe **pe)
1417 struct pci_controller *hose;
1418 struct pnv_phb *phb;
1419 struct eeh_pe *phb_pe, *parent_pe;
1420 __be64 frozen_pe_no;
1421 __be16 err_type, severity;
1423 int state, ret = EEH_NEXT_ERR_NONE;
1426 * While running here, it's safe to purge the event queue. The
1427 * event should still be masked.
1429 eeh_remove_event(NULL, false);
1431 list_for_each_entry(hose, &hose_list, list_node) {
1433 * If the subordinate PCI buses of the PHB has been
1434 * removed or is exactly under error recovery, we
1435 * needn't take care of it any more.
1437 phb = hose->private_data;
1438 phb_pe = eeh_phb_pe_get(hose);
1439 if (!phb_pe || (phb_pe->state & EEH_PE_ISOLATED))
1442 rc = opal_pci_next_error(phb->opal_id,
1443 &frozen_pe_no, &err_type, &severity);
1444 if (rc != OPAL_SUCCESS) {
1445 pr_devel("%s: Invalid return value on "
1446 "PHB#%x (0x%lx) from opal_pci_next_error",
1447 __func__, hose->global_number, rc);
1451 /* If the PHB doesn't have error, stop processing */
1452 if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR ||
1453 be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) {
1454 pr_devel("%s: No error found on PHB#%x\n",
1455 __func__, hose->global_number);
1460 * Processing the error. We're expecting the error with
1461 * highest priority reported upon multiple errors on the
1464 pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n",
1465 __func__, be16_to_cpu(err_type),
1466 be16_to_cpu(severity), be64_to_cpu(frozen_pe_no),
1467 hose->global_number);
1468 switch (be16_to_cpu(err_type)) {
1469 case OPAL_EEH_IOC_ERROR:
1470 if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) {
1471 pr_err("EEH: dead IOC detected\n");
1472 ret = EEH_NEXT_ERR_DEAD_IOC;
1473 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1474 pr_info("EEH: IOC informative error "
1476 pnv_eeh_get_and_dump_hub_diag(hose);
1477 ret = EEH_NEXT_ERR_NONE;
1481 case OPAL_EEH_PHB_ERROR:
1482 if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) {
1484 pr_err("EEH: dead PHB#%x detected, "
1486 hose->global_number,
1487 eeh_pe_loc_get(phb_pe));
1488 ret = EEH_NEXT_ERR_DEAD_PHB;
1489 } else if (be16_to_cpu(severity) ==
1490 OPAL_EEH_SEV_PHB_FENCED) {
1492 pr_err("EEH: Fenced PHB#%x detected, "
1494 hose->global_number,
1495 eeh_pe_loc_get(phb_pe));
1496 ret = EEH_NEXT_ERR_FENCED_PHB;
1497 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1498 pr_info("EEH: PHB#%x informative error "
1499 "detected, location: %s\n",
1500 hose->global_number,
1501 eeh_pe_loc_get(phb_pe));
1502 pnv_eeh_get_phb_diag(phb_pe);
1503 pnv_pci_dump_phb_diag_data(hose, phb_pe->data);
1504 ret = EEH_NEXT_ERR_NONE;
1508 case OPAL_EEH_PE_ERROR:
1510 * If we can't find the corresponding PE, we
1511 * just try to unfreeze.
1513 if (pnv_eeh_get_pe(hose,
1514 be64_to_cpu(frozen_pe_no), pe)) {
1515 pr_info("EEH: Clear non-existing PHB#%x-PE#%llx\n",
1516 hose->global_number, be64_to_cpu(frozen_pe_no));
1517 pr_info("EEH: PHB location: %s\n",
1518 eeh_pe_loc_get(phb_pe));
1520 /* Dump PHB diag-data */
1521 rc = opal_pci_get_phb_diag_data2(phb->opal_id,
1522 phb->diag_data, phb->diag_data_size);
1523 if (rc == OPAL_SUCCESS)
1524 pnv_pci_dump_phb_diag_data(hose,
1527 /* Try best to clear it */
1528 opal_pci_eeh_freeze_clear(phb->opal_id,
1529 be64_to_cpu(frozen_pe_no),
1530 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
1531 ret = EEH_NEXT_ERR_NONE;
1532 } else if ((*pe)->state & EEH_PE_ISOLATED ||
1533 eeh_pe_passed(*pe)) {
1534 ret = EEH_NEXT_ERR_NONE;
1536 pr_err("EEH: Frozen PE#%x "
1537 "on PHB#%x detected\n",
1539 (*pe)->phb->global_number);
1540 pr_err("EEH: PE location: %s, "
1541 "PHB location: %s\n",
1542 eeh_pe_loc_get(*pe),
1543 eeh_pe_loc_get(phb_pe));
1544 ret = EEH_NEXT_ERR_FROZEN_PE;
1549 pr_warn("%s: Unexpected error type %d\n",
1550 __func__, be16_to_cpu(err_type));
1554 * EEH core will try recover from fenced PHB or
1555 * frozen PE. In the time for frozen PE, EEH core
1556 * enable IO path for that before collecting logs,
1557 * but it ruins the site. So we have to dump the
1558 * log in advance here.
1560 if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
1561 ret == EEH_NEXT_ERR_FENCED_PHB) &&
1562 !((*pe)->state & EEH_PE_ISOLATED)) {
1563 eeh_pe_mark_isolated(*pe);
1564 pnv_eeh_get_phb_diag(*pe);
1566 if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
1567 pnv_pci_dump_phb_diag_data((*pe)->phb,
1572 * We probably have the frozen parent PE out there and
1573 * we need have to handle frozen parent PE firstly.
1575 if (ret == EEH_NEXT_ERR_FROZEN_PE) {
1576 parent_pe = (*pe)->parent;
1578 /* Hit the ceiling ? */
1579 if (parent_pe->type & EEH_PE_PHB)
1582 /* Frozen parent PE ? */
1583 state = eeh_ops->get_state(parent_pe, NULL);
1584 if (state > 0 && !eeh_state_active(state))
1587 /* Next parent level */
1588 parent_pe = parent_pe->parent;
1591 /* We possibly migrate to another PE */
1592 eeh_pe_mark_isolated(*pe);
1596 * If we have no errors on the specific PHB or only
1597 * informative error there, we continue poking it.
1598 * Otherwise, we need actions to be taken by upper
1601 if (ret > EEH_NEXT_ERR_INF)
1605 /* Unmask the event */
1606 if (ret == EEH_NEXT_ERR_NONE && eeh_enabled())
1607 enable_irq(eeh_event_irq);
1612 static int pnv_eeh_restore_config(struct pci_dn *pdn)
1614 struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
1615 struct pnv_phb *phb;
1617 int config_addr = (pdn->busno << 8) | (pdn->devfn);
1623 * We have to restore the PCI config space after reset since the
1624 * firmware can't see SRIOV VFs.
1626 * FIXME: The MPS, error routing rules, timeout setting are worthy
1627 * to be exported by firmware in extendible way.
1630 ret = eeh_restore_vf_config(pdn);
1632 phb = pdn->phb->private_data;
1633 ret = opal_pci_reinit(phb->opal_id,
1634 OPAL_REINIT_PCI_DEV, config_addr);
1638 pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
1639 __func__, config_addr, ret);
1646 static struct eeh_ops pnv_eeh_ops = {
1648 .init = pnv_eeh_init,
1649 .probe = pnv_eeh_probe,
1650 .set_option = pnv_eeh_set_option,
1651 .get_pe_addr = pnv_eeh_get_pe_addr,
1652 .get_state = pnv_eeh_get_state,
1653 .reset = pnv_eeh_reset,
1654 .get_log = pnv_eeh_get_log,
1655 .configure_bridge = pnv_eeh_configure_bridge,
1656 .err_inject = pnv_eeh_err_inject,
1657 .read_config = pnv_eeh_read_config,
1658 .write_config = pnv_eeh_write_config,
1659 .next_error = pnv_eeh_next_error,
1660 .restore_config = pnv_eeh_restore_config,
1661 .notify_resume = NULL
1664 #ifdef CONFIG_PCI_IOV
1665 static void pnv_pci_fixup_vf_mps(struct pci_dev *pdev)
1667 struct pci_dn *pdn = pci_get_pdn(pdev);
1670 if (!pdev->is_virtfn)
1673 /* Synchronize MPS for VF and PF */
1674 parent_mps = pcie_get_mps(pdev->physfn);
1675 if ((128 << pdev->pcie_mpss) >= parent_mps)
1676 pcie_set_mps(pdev, parent_mps);
1677 pdn->mps = pcie_get_mps(pdev);
1679 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_pci_fixup_vf_mps);
1680 #endif /* CONFIG_PCI_IOV */
1683 * eeh_powernv_init - Register platform dependent EEH operations
1685 * EEH initialization on powernv platform. This function should be
1686 * called before any EEH related functions.
1688 static int __init eeh_powernv_init(void)
1692 ret = eeh_ops_register(&pnv_eeh_ops);
1694 pr_info("EEH: PowerNV platform initialized\n");
1696 pr_info("EEH: Failed to initialize PowerNV platform (%d)\n", ret);
1700 machine_early_initcall(powernv, eeh_powernv_init);