2 * PCI Error Recovery Driver for RPA-compliant PPC64 platform.
3 * Copyright IBM Corp. 2004 2005
4 * Copyright Linas Vepstas <linas@linas.org> 2004, 2005
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 (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Send comments and feedback to Linas Vepstas <linas@austin.ibm.com>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
31 #include <asm/eeh_event.h>
32 #include <asm/ppc-pci.h>
33 #include <asm/pci-bridge.h>
38 struct list_head edev_list;
42 static int eeh_result_priority(enum pci_ers_result result)
45 case PCI_ERS_RESULT_NONE:
47 case PCI_ERS_RESULT_NO_AER_DRIVER:
49 case PCI_ERS_RESULT_RECOVERED:
51 case PCI_ERS_RESULT_CAN_RECOVER:
53 case PCI_ERS_RESULT_DISCONNECT:
55 case PCI_ERS_RESULT_NEED_RESET:
58 WARN_ONCE(1, "Unknown pci_ers_result value: %d\n", (int)result);
63 const char *pci_ers_result_name(enum pci_ers_result result)
66 case PCI_ERS_RESULT_NONE:
68 case PCI_ERS_RESULT_CAN_RECOVER:
70 case PCI_ERS_RESULT_NEED_RESET:
72 case PCI_ERS_RESULT_DISCONNECT:
74 case PCI_ERS_RESULT_RECOVERED:
76 case PCI_ERS_RESULT_NO_AER_DRIVER:
77 return "no AER driver";
79 WARN_ONCE(1, "Unknown result type: %d\n", (int)result);
84 static __printf(2, 3) void eeh_edev_info(const struct eeh_dev *edev,
95 printk(KERN_INFO "EEH: PE#%x (PCI %s): %pV\n", edev->pe_config_addr,
96 edev->pdev ? dev_name(&edev->pdev->dev) : "none", &vaf);
101 static enum pci_ers_result pci_ers_merge_result(enum pci_ers_result old,
102 enum pci_ers_result new)
104 if (eeh_result_priority(new) > eeh_result_priority(old))
109 static bool eeh_dev_removed(struct eeh_dev *edev)
111 return !edev || (edev->mode & EEH_DEV_REMOVED);
114 static bool eeh_edev_actionable(struct eeh_dev *edev)
116 return (edev->pdev && !eeh_dev_removed(edev) &&
117 !eeh_pe_passed(edev->pe));
121 * eeh_pcid_get - Get the PCI device driver
124 * The function is used to retrieve the PCI device driver for
125 * the indicated PCI device. Besides, we will increase the reference
126 * of the PCI device driver to prevent that being unloaded on
127 * the fly. Otherwise, kernel crash would be seen.
129 static inline struct pci_driver *eeh_pcid_get(struct pci_dev *pdev)
131 if (!pdev || !pdev->driver)
134 if (!try_module_get(pdev->driver->driver.owner))
141 * eeh_pcid_put - Dereference on the PCI device driver
144 * The function is called to do dereference on the PCI device
145 * driver of the indicated PCI device.
147 static inline void eeh_pcid_put(struct pci_dev *pdev)
149 if (!pdev || !pdev->driver)
152 module_put(pdev->driver->driver.owner);
156 * eeh_disable_irq - Disable interrupt for the recovering device
159 * This routine must be called when reporting temporary or permanent
160 * error to the particular PCI device to disable interrupt of that
161 * device. If the device has enabled MSI or MSI-X interrupt, we needn't
162 * do real work because EEH should freeze DMA transfers for those PCI
163 * devices encountering EEH errors, which includes MSI or MSI-X.
165 static void eeh_disable_irq(struct eeh_dev *edev)
167 /* Don't disable MSI and MSI-X interrupts. They are
168 * effectively disabled by the DMA Stopped state
169 * when an EEH error occurs.
171 if (edev->pdev->msi_enabled || edev->pdev->msix_enabled)
174 if (!irq_has_action(edev->pdev->irq))
177 edev->mode |= EEH_DEV_IRQ_DISABLED;
178 disable_irq_nosync(edev->pdev->irq);
182 * eeh_enable_irq - Enable interrupt for the recovering device
185 * This routine must be called to enable interrupt while failed
186 * device could be resumed.
188 static void eeh_enable_irq(struct eeh_dev *edev)
190 if ((edev->mode) & EEH_DEV_IRQ_DISABLED) {
191 edev->mode &= ~EEH_DEV_IRQ_DISABLED;
195 * This is just ass backwards. This maze has
196 * unbalanced irq_enable/disable calls. So instead of
197 * finding the root cause it works around the warning
198 * in the irq_enable code by conditionally calling
201 * That's just wrong.The warning in the core code is
202 * there to tell people to fix their asymmetries in
203 * their own code, not by abusing the core information
206 * I so wish that the assymetry would be the other way
207 * round and a few more irq_disable calls render that
208 * shit unusable forever.
212 if (irqd_irq_disabled(irq_get_irq_data(edev->pdev->irq)))
213 enable_irq(edev->pdev->irq);
217 static void *eeh_dev_save_state(struct eeh_dev *edev, void *userdata)
219 struct pci_dev *pdev;
225 * We cannot access the config space on some adapters.
226 * Otherwise, it will cause fenced PHB. We don't save
227 * the content in their config space and will restore
228 * from the initial config space saved when the EEH
231 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED))
234 pdev = eeh_dev_to_pci_dev(edev);
238 pci_save_state(pdev);
242 static void eeh_set_channel_state(struct eeh_pe *root, enum pci_channel_state s)
245 struct eeh_dev *edev, *tmp;
247 eeh_for_each_pe(root, pe)
248 eeh_pe_for_each_dev(pe, edev, tmp)
249 if (eeh_edev_actionable(edev))
250 edev->pdev->error_state = s;
253 static void eeh_set_irq_state(struct eeh_pe *root, bool enable)
256 struct eeh_dev *edev, *tmp;
258 eeh_for_each_pe(root, pe) {
259 eeh_pe_for_each_dev(pe, edev, tmp) {
260 if (!eeh_edev_actionable(edev))
263 if (!eeh_pcid_get(edev->pdev))
267 eeh_enable_irq(edev);
269 eeh_disable_irq(edev);
271 eeh_pcid_put(edev->pdev);
276 typedef enum pci_ers_result (*eeh_report_fn)(struct eeh_dev *,
277 struct pci_driver *);
278 static void eeh_pe_report_edev(struct eeh_dev *edev, eeh_report_fn fn,
279 enum pci_ers_result *result)
281 struct pci_driver *driver;
282 enum pci_ers_result new_result;
285 eeh_edev_info(edev, "no device");
288 device_lock(&edev->pdev->dev);
289 if (eeh_edev_actionable(edev)) {
290 driver = eeh_pcid_get(edev->pdev);
293 eeh_edev_info(edev, "no driver");
294 else if (!driver->err_handler)
295 eeh_edev_info(edev, "driver not EEH aware");
296 else if (edev->mode & EEH_DEV_NO_HANDLER)
297 eeh_edev_info(edev, "driver bound too late");
299 new_result = fn(edev, driver);
300 eeh_edev_info(edev, "%s driver reports: '%s'",
302 pci_ers_result_name(new_result));
304 *result = pci_ers_merge_result(*result,
308 eeh_pcid_put(edev->pdev);
310 eeh_edev_info(edev, "not actionable (%d,%d,%d)", !!edev->pdev,
311 !eeh_dev_removed(edev), !eeh_pe_passed(edev->pe));
313 device_unlock(&edev->pdev->dev);
316 static void eeh_pe_report(const char *name, struct eeh_pe *root,
317 eeh_report_fn fn, enum pci_ers_result *result)
320 struct eeh_dev *edev, *tmp;
322 pr_info("EEH: Beginning: '%s'\n", name);
323 eeh_for_each_pe(root, pe) eeh_pe_for_each_dev(pe, edev, tmp)
324 eeh_pe_report_edev(edev, fn, result);
326 pr_info("EEH: Finished:'%s' with aggregate recovery state:'%s'\n",
327 name, pci_ers_result_name(*result));
329 pr_info("EEH: Finished:'%s'", name);
333 * eeh_report_error - Report pci error to each device driver
335 * @driver: device's PCI driver
337 * Report an EEH error to each device driver.
339 static enum pci_ers_result eeh_report_error(struct eeh_dev *edev,
340 struct pci_driver *driver)
342 enum pci_ers_result rc;
343 struct pci_dev *dev = edev->pdev;
345 if (!driver->err_handler->error_detected)
346 return PCI_ERS_RESULT_NONE;
348 eeh_edev_info(edev, "Invoking %s->error_detected(IO frozen)",
350 rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
352 edev->in_error = true;
353 pci_uevent_ers(dev, PCI_ERS_RESULT_NONE);
358 * eeh_report_mmio_enabled - Tell drivers that MMIO has been enabled
360 * @driver: device's PCI driver
362 * Tells each device driver that IO ports, MMIO and config space I/O
365 static enum pci_ers_result eeh_report_mmio_enabled(struct eeh_dev *edev,
366 struct pci_driver *driver)
368 if (!driver->err_handler->mmio_enabled)
369 return PCI_ERS_RESULT_NONE;
370 eeh_edev_info(edev, "Invoking %s->mmio_enabled()", driver->name);
371 return driver->err_handler->mmio_enabled(edev->pdev);
375 * eeh_report_reset - Tell device that slot has been reset
377 * @driver: device's PCI driver
379 * This routine must be called while EEH tries to reset particular
380 * PCI device so that the associated PCI device driver could take
381 * some actions, usually to save data the driver needs so that the
382 * driver can work again while the device is recovered.
384 static enum pci_ers_result eeh_report_reset(struct eeh_dev *edev,
385 struct pci_driver *driver)
387 if (!driver->err_handler->slot_reset || !edev->in_error)
388 return PCI_ERS_RESULT_NONE;
389 eeh_edev_info(edev, "Invoking %s->slot_reset()", driver->name);
390 return driver->err_handler->slot_reset(edev->pdev);
393 static void *eeh_dev_restore_state(struct eeh_dev *edev, void *userdata)
395 struct pci_dev *pdev;
401 * The content in the config space isn't saved because
402 * the blocked config space on some adapters. We have
403 * to restore the initial saved config space when the
404 * EEH device is created.
406 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED)) {
407 if (list_is_last(&edev->list, &edev->pe->edevs))
408 eeh_pe_restore_bars(edev->pe);
413 pdev = eeh_dev_to_pci_dev(edev);
417 pci_restore_state(pdev);
422 * eeh_report_resume - Tell device to resume normal operations
424 * @driver: device's PCI driver
426 * This routine must be called to notify the device driver that it
427 * could resume so that the device driver can do some initialization
428 * to make the recovered device work again.
430 static enum pci_ers_result eeh_report_resume(struct eeh_dev *edev,
431 struct pci_driver *driver)
433 if (!driver->err_handler->resume || !edev->in_error)
434 return PCI_ERS_RESULT_NONE;
436 eeh_edev_info(edev, "Invoking %s->resume()", driver->name);
437 driver->err_handler->resume(edev->pdev);
439 pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_RECOVERED);
440 #ifdef CONFIG_PCI_IOV
441 if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
442 eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
444 return PCI_ERS_RESULT_NONE;
448 * eeh_report_failure - Tell device driver that device is dead.
450 * @driver: device's PCI driver
452 * This informs the device driver that the device is permanently
453 * dead, and that no further recovery attempts will be made on it.
455 static enum pci_ers_result eeh_report_failure(struct eeh_dev *edev,
456 struct pci_driver *driver)
458 enum pci_ers_result rc;
460 if (!driver->err_handler->error_detected)
461 return PCI_ERS_RESULT_NONE;
463 eeh_edev_info(edev, "Invoking %s->error_detected(permanent failure)",
465 rc = driver->err_handler->error_detected(edev->pdev,
466 pci_channel_io_perm_failure);
468 pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_DISCONNECT);
472 static void *eeh_add_virt_device(void *data, void *userdata)
474 struct pci_driver *driver;
475 struct eeh_dev *edev = (struct eeh_dev *)data;
476 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
477 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
479 if (!(edev->physfn)) {
480 pr_warn("%s: EEH dev %04x:%02x:%02x.%01x not for VF\n",
481 __func__, pdn->phb->global_number, pdn->busno,
482 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
486 driver = eeh_pcid_get(dev);
488 if (driver->err_handler) {
495 #ifdef CONFIG_PCI_IOV
496 pci_iov_add_virtfn(edev->physfn, pdn->vf_index);
501 static void *eeh_rmv_device(struct eeh_dev *edev, void *userdata)
503 struct pci_driver *driver;
504 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
505 struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
506 int *removed = rmv_data ? &rmv_data->removed : NULL;
509 * Actually, we should remove the PCI bridges as well.
510 * However, that's lots of complexity to do that,
511 * particularly some of devices under the bridge might
512 * support EEH. So we just care about PCI devices for
515 if (!dev || (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE))
519 * We rely on count-based pcibios_release_device() to
520 * detach permanently offlined PEs. Unfortunately, that's
521 * not reliable enough. We might have the permanently
522 * offlined PEs attached, but we needn't take care of
523 * them and their child devices.
525 if (eeh_dev_removed(edev))
529 if (eeh_pe_passed(edev->pe))
531 driver = eeh_pcid_get(dev);
533 if (driver->err_handler &&
534 driver->err_handler->error_detected &&
535 driver->err_handler->slot_reset) {
543 /* Remove it from PCI subsystem */
544 pr_debug("EEH: Removing %s without EEH sensitive driver\n",
546 edev->bus = dev->bus;
547 edev->mode |= EEH_DEV_DISCONNECTED;
552 #ifdef CONFIG_PCI_IOV
553 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
555 pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
559 list_add(&edev->rmv_list, &rmv_data->edev_list);
561 pci_lock_rescan_remove();
562 pci_stop_and_remove_bus_device(dev);
563 pci_unlock_rescan_remove();
569 static void *eeh_pe_detach_dev(struct eeh_pe *pe, void *userdata)
571 struct eeh_dev *edev, *tmp;
573 eeh_pe_for_each_dev(pe, edev, tmp) {
574 if (!(edev->mode & EEH_DEV_DISCONNECTED))
577 edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
578 eeh_rmv_from_parent_pe(edev);
585 * Explicitly clear PE's frozen state for PowerNV where
586 * we have frozen PE until BAR restore is completed. It's
587 * harmless to clear it for pSeries. To be consistent with
588 * PE reset (for 3 times), we try to clear the frozen state
589 * for 3 times as well.
591 static void *__eeh_clear_pe_frozen_state(struct eeh_pe *pe, void *flag)
593 bool clear_sw_state = *(bool *)flag;
596 for (i = 0; rc && i < 3; i++)
597 rc = eeh_unfreeze_pe(pe, clear_sw_state);
599 /* Stop immediately on any errors */
601 pr_warn("%s: Failure %d unfreezing PHB#%x-PE#%x\n",
602 __func__, rc, pe->phb->global_number, pe->addr);
609 static int eeh_clear_pe_frozen_state(struct eeh_pe *pe,
614 rc = eeh_pe_traverse(pe, __eeh_clear_pe_frozen_state, &clear_sw_state);
616 eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
618 return rc ? -EIO : 0;
621 int eeh_pe_reset_and_recover(struct eeh_pe *pe)
625 /* Bail if the PE is being recovered */
626 if (pe->state & EEH_PE_RECOVERING)
629 /* Put the PE into recovery mode */
630 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
633 eeh_pe_dev_traverse(pe, eeh_dev_save_state, NULL);
636 ret = eeh_pe_reset_full(pe);
638 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
642 /* Unfreeze the PE */
643 ret = eeh_clear_pe_frozen_state(pe, true);
645 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
649 /* Restore device state */
650 eeh_pe_dev_traverse(pe, eeh_dev_restore_state, NULL);
652 /* Clear recovery mode */
653 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
659 * eeh_reset_device - Perform actual reset of a pci slot
660 * @driver_eeh_aware: Does the device's driver provide EEH support?
662 * @bus: PCI bus corresponding to the isolcated slot
663 * @rmv_data: Optional, list to record removed devices
665 * This routine must be called to do reset on the indicated PE.
666 * During the reset, udev might be invoked because those affected
667 * PCI devices will be removed and then added.
669 static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,
670 struct eeh_rmv_data *rmv_data,
671 bool driver_eeh_aware)
675 struct eeh_dev *edev;
677 /* pcibios will clear the counter; save the value */
678 cnt = pe->freeze_count;
682 * We don't remove the corresponding PE instances because
683 * we need the information afterwords. The attached EEH
684 * devices are expected to be attached soon when calling
685 * into pci_hp_add_devices().
687 eeh_pe_state_mark(pe, EEH_PE_KEEP);
688 if (driver_eeh_aware || (pe->type & EEH_PE_VF)) {
689 eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
691 pci_lock_rescan_remove();
692 pci_hp_remove_devices(bus);
693 pci_unlock_rescan_remove();
697 * Reset the pci controller. (Asserts RST#; resets config space).
698 * Reconfigure bridges and devices. Don't try to bring the system
699 * up if the reset failed for some reason.
701 * During the reset, it's very dangerous to have uncontrolled PCI
702 * config accesses. So we prefer to block them. However, controlled
703 * PCI config accesses initiated from EEH itself are allowed.
705 rc = eeh_pe_reset_full(pe);
709 pci_lock_rescan_remove();
712 eeh_ops->configure_bridge(pe);
713 eeh_pe_restore_bars(pe);
715 /* Clear frozen state */
716 rc = eeh_clear_pe_frozen_state(pe, false);
718 pci_unlock_rescan_remove();
722 /* Give the system 5 seconds to finish running the user-space
723 * hotplug shutdown scripts, e.g. ifdown for ethernet. Yes,
724 * this is a hack, but if we don't do this, and try to bring
725 * the device up before the scripts have taken it down,
726 * potentially weird things happen.
728 if (!driver_eeh_aware || rmv_data->removed) {
729 pr_info("EEH: Sleep 5s ahead of %s hotplug\n",
730 (driver_eeh_aware ? "partial" : "complete"));
734 * The EEH device is still connected with its parent
735 * PE. We should disconnect it so the binding can be
736 * rebuilt when adding PCI devices.
738 edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
739 eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
740 if (pe->type & EEH_PE_VF) {
741 eeh_add_virt_device(edev, NULL);
743 if (!driver_eeh_aware)
744 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
745 pci_hp_add_devices(bus);
748 eeh_pe_state_clear(pe, EEH_PE_KEEP);
751 pe->freeze_count = cnt;
753 pci_unlock_rescan_remove();
757 /* The longest amount of time to wait for a pci device
758 * to come back on line, in seconds.
760 #define MAX_WAIT_FOR_RECOVERY 300
763 * eeh_handle_normal_event - Handle EEH events on a specific PE
764 * @pe: EEH PE - which should not be used after we return, as it may
765 * have been invalidated.
767 * Attempts to recover the given PE. If recovery fails or the PE has failed
768 * too many times, remove the PE.
770 * While PHB detects address or data parity errors on particular PCI
771 * slot, the associated PE will be frozen. Besides, DMA's occurring
772 * to wild addresses (which usually happen due to bugs in device
773 * drivers or in PCI adapter firmware) can cause EEH error. #SERR,
774 * #PERR or other misc PCI-related errors also can trigger EEH errors.
776 * Recovery process consists of unplugging the device driver (which
777 * generated hotplug events to userspace), then issuing a PCI #RST to
778 * the device, then reconfiguring the PCI config space for all bridges
779 * & devices under this slot, and then finally restarting the device
780 * drivers (which cause a second set of hotplug events to go out to
783 void eeh_handle_normal_event(struct eeh_pe *pe)
786 struct eeh_dev *edev, *tmp;
787 struct eeh_pe *tmp_pe;
789 enum pci_ers_result result = PCI_ERS_RESULT_NONE;
790 struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT(rmv_data.edev_list), 0};
792 bus = eeh_pe_bus_get(pe);
794 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
795 __func__, pe->phb->global_number, pe->addr);
799 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
801 eeh_pe_update_time_stamp(pe);
803 if (pe->freeze_count > eeh_max_freezes) {
804 pr_err("EEH: PHB#%x-PE#%x has failed %d times in the last hour and has been permanently disabled.\n",
805 pe->phb->global_number, pe->addr,
809 pr_warn("EEH: This PCI device has failed %d times in the last hour and will be permanently disabled after %d failures.\n",
810 pe->freeze_count, eeh_max_freezes);
812 eeh_for_each_pe(pe, tmp_pe)
813 eeh_pe_for_each_dev(tmp_pe, edev, tmp)
814 edev->mode &= ~EEH_DEV_NO_HANDLER;
816 /* Walk the various device drivers attached to this slot through
817 * a reset sequence, giving each an opportunity to do what it needs
818 * to accomplish the reset. Each child gets a report of the
819 * status ... if any child can't handle the reset, then the entire
820 * slot is dlpar removed and added.
822 * When the PHB is fenced, we have to issue a reset to recover from
823 * the error. Override the result if necessary to have partially
824 * hotplug for this case.
826 pr_info("EEH: Notify device drivers to shutdown\n");
827 eeh_set_channel_state(pe, pci_channel_io_frozen);
828 eeh_set_irq_state(pe, false);
829 eeh_pe_report("error_detected(IO frozen)", pe, eeh_report_error,
831 if ((pe->type & EEH_PE_PHB) &&
832 result != PCI_ERS_RESULT_NONE &&
833 result != PCI_ERS_RESULT_NEED_RESET)
834 result = PCI_ERS_RESULT_NEED_RESET;
836 /* Get the current PCI slot state. This can take a long time,
837 * sometimes over 300 seconds for certain systems.
839 rc = eeh_ops->wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
840 if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
841 pr_warn("EEH: Permanent failure\n");
845 /* Since rtas may enable MMIO when posting the error log,
846 * don't post the error log until after all dev drivers
847 * have been informed.
849 pr_info("EEH: Collect temporary log\n");
850 eeh_slot_error_detail(pe, EEH_LOG_TEMP);
852 /* If all device drivers were EEH-unaware, then shut
853 * down all of the device drivers, and hope they
854 * go down willingly, without panicing the system.
856 if (result == PCI_ERS_RESULT_NONE) {
857 pr_info("EEH: Reset with hotplug activity\n");
858 rc = eeh_reset_device(pe, bus, NULL, false);
860 pr_warn("%s: Unable to reset, err=%d\n",
866 /* If all devices reported they can proceed, then re-enable MMIO */
867 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
868 pr_info("EEH: Enable I/O for affected devices\n");
869 rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
874 result = PCI_ERS_RESULT_NEED_RESET;
876 pr_info("EEH: Notify device drivers to resume I/O\n");
877 eeh_pe_report("mmio_enabled", pe,
878 eeh_report_mmio_enabled, &result);
882 /* If all devices reported they can proceed, then re-enable DMA */
883 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
884 pr_info("EEH: Enabled DMA for affected devices\n");
885 rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
890 result = PCI_ERS_RESULT_NEED_RESET;
893 * We didn't do PE reset for the case. The PE
894 * is still in frozen state. Clear it before
897 eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
898 result = PCI_ERS_RESULT_RECOVERED;
902 /* If any device has a hard failure, then shut off everything. */
903 if (result == PCI_ERS_RESULT_DISCONNECT) {
904 pr_warn("EEH: Device driver gave up\n");
908 /* If any device called out for a reset, then reset the slot */
909 if (result == PCI_ERS_RESULT_NEED_RESET) {
910 pr_info("EEH: Reset without hotplug activity\n");
911 rc = eeh_reset_device(pe, bus, &rmv_data, true);
913 pr_warn("%s: Cannot reset, err=%d\n",
918 pr_info("EEH: Notify device drivers "
919 "the completion of reset\n");
920 result = PCI_ERS_RESULT_NONE;
921 eeh_set_channel_state(pe, pci_channel_io_normal);
922 eeh_set_irq_state(pe, true);
923 eeh_pe_report("slot_reset", pe, eeh_report_reset, &result);
926 /* All devices should claim they have recovered by now. */
927 if ((result != PCI_ERS_RESULT_RECOVERED) &&
928 (result != PCI_ERS_RESULT_NONE)) {
929 pr_warn("EEH: Not recovered\n");
934 * For those hot removed VFs, we should add back them after PF get
935 * recovered properly.
937 list_for_each_entry_safe(edev, tmp, &rmv_data.edev_list, rmv_list) {
938 eeh_add_virt_device(edev, NULL);
939 list_del(&edev->rmv_list);
942 /* Tell all device drivers that they can resume operations */
943 pr_info("EEH: Notify device driver to resume\n");
944 eeh_set_channel_state(pe, pci_channel_io_normal);
945 eeh_set_irq_state(pe, true);
946 eeh_pe_report("resume", pe, eeh_report_resume, NULL);
947 eeh_for_each_pe(pe, tmp_pe) {
948 eeh_pe_for_each_dev(tmp_pe, edev, tmp) {
949 edev->mode &= ~EEH_DEV_NO_HANDLER;
950 edev->in_error = false;
954 pr_info("EEH: Recovery successful.\n");
959 * About 90% of all real-life EEH failures in the field
960 * are due to poorly seated PCI cards. Only 10% or so are
961 * due to actual, failed cards.
963 pr_err("EEH: Unable to recover from failure from PHB#%x-PE#%x.\n"
964 "Please try reseating or replacing it\n",
965 pe->phb->global_number, pe->addr);
967 eeh_slot_error_detail(pe, EEH_LOG_PERM);
969 /* Notify all devices that they're about to go down. */
970 eeh_set_channel_state(pe, pci_channel_io_perm_failure);
971 eeh_set_irq_state(pe, false);
972 eeh_pe_report("error_detected(permanent failure)", pe,
973 eeh_report_failure, NULL);
975 /* Mark the PE to be removed permanently */
976 eeh_pe_state_mark(pe, EEH_PE_REMOVED);
979 * Shut down the device drivers for good. We mark
980 * all removed devices correctly to avoid access
981 * the their PCI config any more.
983 if (pe->type & EEH_PE_VF) {
984 eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
985 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
987 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
988 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
990 pci_lock_rescan_remove();
991 pci_hp_remove_devices(bus);
992 pci_unlock_rescan_remove();
993 /* The passed PE should no longer be used */
997 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
1001 * eeh_handle_special_event - Handle EEH events without a specific failing PE
1003 * Called when an EEH event is detected but can't be narrowed down to a
1004 * specific PE. Iterates through possible failures and handles them as
1007 void eeh_handle_special_event(void)
1009 struct eeh_pe *pe, *phb_pe, *tmp_pe;
1010 struct eeh_dev *edev, *tmp_edev;
1011 struct pci_bus *bus;
1012 struct pci_controller *hose;
1013 unsigned long flags;
1018 rc = eeh_ops->next_error(&pe);
1021 case EEH_NEXT_ERR_DEAD_IOC:
1022 /* Mark all PHBs in dead state */
1023 eeh_serialize_lock(&flags);
1025 /* Purge all events */
1026 eeh_remove_event(NULL, true);
1028 list_for_each_entry(hose, &hose_list, list_node) {
1029 phb_pe = eeh_phb_pe_get(hose);
1030 if (!phb_pe) continue;
1032 eeh_pe_state_mark(phb_pe, EEH_PE_ISOLATED);
1035 eeh_serialize_unlock(flags);
1038 case EEH_NEXT_ERR_FROZEN_PE:
1039 case EEH_NEXT_ERR_FENCED_PHB:
1040 case EEH_NEXT_ERR_DEAD_PHB:
1041 /* Mark the PE in fenced state */
1042 eeh_serialize_lock(&flags);
1044 /* Purge all events of the PHB */
1045 eeh_remove_event(pe, true);
1047 if (rc == EEH_NEXT_ERR_DEAD_PHB)
1048 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
1050 eeh_pe_state_mark(pe,
1051 EEH_PE_ISOLATED | EEH_PE_RECOVERING);
1053 eeh_serialize_unlock(flags);
1056 case EEH_NEXT_ERR_NONE:
1059 pr_warn("%s: Invalid value %d from next_error()\n",
1065 * For fenced PHB and frozen PE, it's handled as normal
1066 * event. We have to remove the affected PHBs for dead
1069 if (rc == EEH_NEXT_ERR_FROZEN_PE ||
1070 rc == EEH_NEXT_ERR_FENCED_PHB) {
1071 eeh_handle_normal_event(pe);
1073 pci_lock_rescan_remove();
1074 list_for_each_entry(hose, &hose_list, list_node) {
1075 phb_pe = eeh_phb_pe_get(hose);
1077 !(phb_pe->state & EEH_PE_ISOLATED) ||
1078 (phb_pe->state & EEH_PE_RECOVERING))
1081 eeh_for_each_pe(pe, tmp_pe)
1082 eeh_pe_for_each_dev(tmp_pe, edev, tmp_edev)
1083 edev->mode &= ~EEH_DEV_NO_HANDLER;
1085 /* Notify all devices to be down */
1086 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
1087 eeh_set_channel_state(pe, pci_channel_io_perm_failure);
1089 "error_detected(permanent failure)", pe,
1090 eeh_report_failure, NULL);
1091 bus = eeh_pe_bus_get(phb_pe);
1093 pr_err("%s: Cannot find PCI bus for "
1096 pe->phb->global_number,
1100 pci_hp_remove_devices(bus);
1102 pci_unlock_rescan_remove();
1106 * If we have detected dead IOC, we needn't proceed
1107 * any more since all PHBs would have been removed
1109 if (rc == EEH_NEXT_ERR_DEAD_IOC)
1111 } while (rc != EEH_NEXT_ERR_NONE);