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;
43 * eeh_pcid_name - Retrieve name of PCI device driver
46 * This routine is used to retrieve the name of PCI device driver
49 static inline const char *eeh_pcid_name(struct pci_dev *pdev)
51 if (pdev && pdev->dev.driver)
52 return pdev->dev.driver->name;
57 * eeh_pcid_get - Get the PCI device driver
60 * The function is used to retrieve the PCI device driver for
61 * the indicated PCI device. Besides, we will increase the reference
62 * of the PCI device driver to prevent that being unloaded on
63 * the fly. Otherwise, kernel crash would be seen.
65 static inline struct pci_driver *eeh_pcid_get(struct pci_dev *pdev)
67 if (!pdev || !pdev->driver)
70 if (!try_module_get(pdev->driver->driver.owner))
77 * eeh_pcid_put - Dereference on the PCI device driver
80 * The function is called to do dereference on the PCI device
81 * driver of the indicated PCI device.
83 static inline void eeh_pcid_put(struct pci_dev *pdev)
85 if (!pdev || !pdev->driver)
88 module_put(pdev->driver->driver.owner);
92 * eeh_disable_irq - Disable interrupt for the recovering device
95 * This routine must be called when reporting temporary or permanent
96 * error to the particular PCI device to disable interrupt of that
97 * device. If the device has enabled MSI or MSI-X interrupt, we needn't
98 * do real work because EEH should freeze DMA transfers for those PCI
99 * devices encountering EEH errors, which includes MSI or MSI-X.
101 static void eeh_disable_irq(struct pci_dev *dev)
103 struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
105 /* Don't disable MSI and MSI-X interrupts. They are
106 * effectively disabled by the DMA Stopped state
107 * when an EEH error occurs.
109 if (dev->msi_enabled || dev->msix_enabled)
112 if (!irq_has_action(dev->irq))
115 edev->mode |= EEH_DEV_IRQ_DISABLED;
116 disable_irq_nosync(dev->irq);
120 * eeh_enable_irq - Enable interrupt for the recovering device
123 * This routine must be called to enable interrupt while failed
124 * device could be resumed.
126 static void eeh_enable_irq(struct pci_dev *dev)
128 struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
130 if ((edev->mode) & EEH_DEV_IRQ_DISABLED) {
131 edev->mode &= ~EEH_DEV_IRQ_DISABLED;
135 * This is just ass backwards. This maze has
136 * unbalanced irq_enable/disable calls. So instead of
137 * finding the root cause it works around the warning
138 * in the irq_enable code by conditionally calling
141 * That's just wrong.The warning in the core code is
142 * there to tell people to fix their asymmetries in
143 * their own code, not by abusing the core information
146 * I so wish that the assymetry would be the other way
147 * round and a few more irq_disable calls render that
148 * shit unusable forever.
152 if (irqd_irq_disabled(irq_get_irq_data(dev->irq)))
153 enable_irq(dev->irq);
157 static bool eeh_dev_removed(struct eeh_dev *edev)
159 /* EEH device removed ? */
160 if (!edev || (edev->mode & EEH_DEV_REMOVED))
166 static void *eeh_dev_save_state(void *data, void *userdata)
168 struct eeh_dev *edev = data;
169 struct pci_dev *pdev;
175 * We cannot access the config space on some adapters.
176 * Otherwise, it will cause fenced PHB. We don't save
177 * the content in their config space and will restore
178 * from the initial config space saved when the EEH
181 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED))
184 pdev = eeh_dev_to_pci_dev(edev);
188 pci_save_state(pdev);
193 * eeh_report_error - Report pci error to each device driver
195 * @userdata: return value
197 * Report an EEH error to each device driver, collect up and
198 * merge the device driver responses. Cumulative response
199 * passed back in "userdata".
201 static void *eeh_report_error(void *data, void *userdata)
203 struct eeh_dev *edev = (struct eeh_dev *)data;
204 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
205 enum pci_ers_result rc, *res = userdata;
206 struct pci_driver *driver;
208 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
210 dev->error_state = pci_channel_io_frozen;
212 driver = eeh_pcid_get(dev);
213 if (!driver) return NULL;
215 eeh_disable_irq(dev);
217 if (!driver->err_handler ||
218 !driver->err_handler->error_detected) {
223 rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
225 /* A driver that needs a reset trumps all others */
226 if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
227 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
229 edev->in_error = true;
231 pci_uevent_ers(dev, PCI_ERS_RESULT_NONE);
236 * eeh_report_mmio_enabled - Tell drivers that MMIO has been enabled
238 * @userdata: return value
240 * Tells each device driver that IO ports, MMIO and config space I/O
241 * are now enabled. Collects up and merges the device driver responses.
242 * Cumulative response passed back in "userdata".
244 static void *eeh_report_mmio_enabled(void *data, void *userdata)
246 struct eeh_dev *edev = (struct eeh_dev *)data;
247 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
248 enum pci_ers_result rc, *res = userdata;
249 struct pci_driver *driver;
251 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
254 driver = eeh_pcid_get(dev);
255 if (!driver) return NULL;
257 if (!driver->err_handler ||
258 !driver->err_handler->mmio_enabled ||
259 (edev->mode & EEH_DEV_NO_HANDLER)) {
264 rc = driver->err_handler->mmio_enabled(dev);
266 /* A driver that needs a reset trumps all others */
267 if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
268 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
275 * eeh_report_reset - Tell device that slot has been reset
277 * @userdata: return value
279 * This routine must be called while EEH tries to reset particular
280 * PCI device so that the associated PCI device driver could take
281 * some actions, usually to save data the driver needs so that the
282 * driver can work again while the device is recovered.
284 static void *eeh_report_reset(void *data, void *userdata)
286 struct eeh_dev *edev = (struct eeh_dev *)data;
287 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
288 enum pci_ers_result rc, *res = userdata;
289 struct pci_driver *driver;
291 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
293 dev->error_state = pci_channel_io_normal;
295 driver = eeh_pcid_get(dev);
296 if (!driver) return NULL;
300 if (!driver->err_handler ||
301 !driver->err_handler->slot_reset ||
302 (edev->mode & EEH_DEV_NO_HANDLER) ||
308 rc = driver->err_handler->slot_reset(dev);
309 if ((*res == PCI_ERS_RESULT_NONE) ||
310 (*res == PCI_ERS_RESULT_RECOVERED)) *res = rc;
311 if (*res == PCI_ERS_RESULT_DISCONNECT &&
312 rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
318 static void *eeh_dev_restore_state(void *data, void *userdata)
320 struct eeh_dev *edev = data;
321 struct pci_dev *pdev;
327 * The content in the config space isn't saved because
328 * the blocked config space on some adapters. We have
329 * to restore the initial saved config space when the
330 * EEH device is created.
332 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED)) {
333 if (list_is_last(&edev->list, &edev->pe->edevs))
334 eeh_pe_restore_bars(edev->pe);
339 pdev = eeh_dev_to_pci_dev(edev);
343 pci_restore_state(pdev);
348 * eeh_report_resume - Tell device to resume normal operations
350 * @userdata: return value
352 * This routine must be called to notify the device driver that it
353 * could resume so that the device driver can do some initialization
354 * to make the recovered device work again.
356 static void *eeh_report_resume(void *data, void *userdata)
358 struct eeh_dev *edev = (struct eeh_dev *)data;
359 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
361 struct pci_driver *driver;
363 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
365 dev->error_state = pci_channel_io_normal;
367 driver = eeh_pcid_get(dev);
368 if (!driver) return NULL;
370 was_in_error = edev->in_error;
371 edev->in_error = false;
374 if (!driver->err_handler ||
375 !driver->err_handler->resume ||
376 (edev->mode & EEH_DEV_NO_HANDLER) || !was_in_error) {
377 edev->mode &= ~EEH_DEV_NO_HANDLER;
382 driver->err_handler->resume(dev);
385 pci_uevent_ers(dev, PCI_ERS_RESULT_RECOVERED);
386 #ifdef CONFIG_PCI_IOV
387 if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
388 eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
394 * eeh_report_failure - Tell device driver that device is dead.
396 * @userdata: return value
398 * This informs the device driver that the device is permanently
399 * dead, and that no further recovery attempts will be made on it.
401 static void *eeh_report_failure(void *data, void *userdata)
403 struct eeh_dev *edev = (struct eeh_dev *)data;
404 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
405 struct pci_driver *driver;
407 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
409 dev->error_state = pci_channel_io_perm_failure;
411 driver = eeh_pcid_get(dev);
412 if (!driver) return NULL;
414 eeh_disable_irq(dev);
416 if (!driver->err_handler ||
417 !driver->err_handler->error_detected) {
422 driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
425 pci_uevent_ers(dev, PCI_ERS_RESULT_DISCONNECT);
429 static void *eeh_add_virt_device(void *data, void *userdata)
431 struct pci_driver *driver;
432 struct eeh_dev *edev = (struct eeh_dev *)data;
433 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
434 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
436 if (!(edev->physfn)) {
437 pr_warn("%s: EEH dev %04x:%02x:%02x.%01x not for VF\n",
438 __func__, pdn->phb->global_number, pdn->busno,
439 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
443 driver = eeh_pcid_get(dev);
446 if (driver->err_handler)
450 #ifdef CONFIG_PCI_IOV
451 pci_iov_add_virtfn(edev->physfn, pdn->vf_index);
456 static void *eeh_rmv_device(void *data, void *userdata)
458 struct pci_driver *driver;
459 struct eeh_dev *edev = (struct eeh_dev *)data;
460 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
461 struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
462 int *removed = rmv_data ? &rmv_data->removed : NULL;
465 * Actually, we should remove the PCI bridges as well.
466 * However, that's lots of complexity to do that,
467 * particularly some of devices under the bridge might
468 * support EEH. So we just care about PCI devices for
471 if (!dev || (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE))
475 * We rely on count-based pcibios_release_device() to
476 * detach permanently offlined PEs. Unfortunately, that's
477 * not reliable enough. We might have the permanently
478 * offlined PEs attached, but we needn't take care of
479 * them and their child devices.
481 if (eeh_dev_removed(edev))
484 driver = eeh_pcid_get(dev);
488 eeh_pe_passed(edev->pe))
491 driver->err_handler &&
492 driver->err_handler->error_detected &&
493 driver->err_handler->slot_reset)
497 /* Remove it from PCI subsystem */
498 pr_debug("EEH: Removing %s without EEH sensitive driver\n",
500 edev->bus = dev->bus;
501 edev->mode |= EEH_DEV_DISCONNECTED;
506 #ifdef CONFIG_PCI_IOV
507 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
509 pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
513 * We have to set the VF PE number to invalid one, which is
514 * required to plug the VF successfully.
516 pdn->pe_number = IODA_INVALID_PE;
519 list_add(&edev->rmv_list, &rmv_data->edev_list);
521 pci_lock_rescan_remove();
522 pci_stop_and_remove_bus_device(dev);
523 pci_unlock_rescan_remove();
529 static void *eeh_pe_detach_dev(void *data, void *userdata)
531 struct eeh_pe *pe = (struct eeh_pe *)data;
532 struct eeh_dev *edev, *tmp;
534 eeh_pe_for_each_dev(pe, edev, tmp) {
535 if (!(edev->mode & EEH_DEV_DISCONNECTED))
538 edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
539 eeh_rmv_from_parent_pe(edev);
546 * Explicitly clear PE's frozen state for PowerNV where
547 * we have frozen PE until BAR restore is completed. It's
548 * harmless to clear it for pSeries. To be consistent with
549 * PE reset (for 3 times), we try to clear the frozen state
550 * for 3 times as well.
552 static void *__eeh_clear_pe_frozen_state(void *data, void *flag)
554 struct eeh_pe *pe = (struct eeh_pe *)data;
555 bool clear_sw_state = *(bool *)flag;
558 for (i = 0; rc && i < 3; i++)
559 rc = eeh_unfreeze_pe(pe, clear_sw_state);
561 /* Stop immediately on any errors */
563 pr_warn("%s: Failure %d unfreezing PHB#%x-PE#%x\n",
564 __func__, rc, pe->phb->global_number, pe->addr);
571 static int eeh_clear_pe_frozen_state(struct eeh_pe *pe,
576 rc = eeh_pe_traverse(pe, __eeh_clear_pe_frozen_state, &clear_sw_state);
578 eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
580 return rc ? -EIO : 0;
583 int eeh_pe_reset_and_recover(struct eeh_pe *pe)
587 /* Bail if the PE is being recovered */
588 if (pe->state & EEH_PE_RECOVERING)
591 /* Put the PE into recovery mode */
592 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
595 eeh_pe_dev_traverse(pe, eeh_dev_save_state, NULL);
598 ret = eeh_pe_reset_full(pe);
600 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
604 /* Unfreeze the PE */
605 ret = eeh_clear_pe_frozen_state(pe, true);
607 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
611 /* Restore device state */
612 eeh_pe_dev_traverse(pe, eeh_dev_restore_state, NULL);
614 /* Clear recovery mode */
615 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
621 * eeh_reset_device - Perform actual reset of a pci slot
623 * @bus: PCI bus corresponding to the isolcated slot
625 * This routine must be called to do reset on the indicated PE.
626 * During the reset, udev might be invoked because those affected
627 * PCI devices will be removed and then added.
629 static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,
630 struct eeh_rmv_data *rmv_data)
632 struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
635 struct eeh_dev *edev;
637 /* pcibios will clear the counter; save the value */
638 cnt = pe->freeze_count;
642 * We don't remove the corresponding PE instances because
643 * we need the information afterwords. The attached EEH
644 * devices are expected to be attached soon when calling
645 * into pci_hp_add_devices().
647 eeh_pe_state_mark(pe, EEH_PE_KEEP);
649 if (pe->type & EEH_PE_VF) {
650 eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
652 pci_lock_rescan_remove();
653 pci_hp_remove_devices(bus);
654 pci_unlock_rescan_remove();
656 } else if (frozen_bus) {
657 eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
661 * Reset the pci controller. (Asserts RST#; resets config space).
662 * Reconfigure bridges and devices. Don't try to bring the system
663 * up if the reset failed for some reason.
665 * During the reset, it's very dangerous to have uncontrolled PCI
666 * config accesses. So we prefer to block them. However, controlled
667 * PCI config accesses initiated from EEH itself are allowed.
669 rc = eeh_pe_reset_full(pe);
673 pci_lock_rescan_remove();
676 eeh_ops->configure_bridge(pe);
677 eeh_pe_restore_bars(pe);
679 /* Clear frozen state */
680 rc = eeh_clear_pe_frozen_state(pe, false);
682 pci_unlock_rescan_remove();
686 /* Give the system 5 seconds to finish running the user-space
687 * hotplug shutdown scripts, e.g. ifdown for ethernet. Yes,
688 * this is a hack, but if we don't do this, and try to bring
689 * the device up before the scripts have taken it down,
690 * potentially weird things happen.
693 pr_info("EEH: Sleep 5s ahead of complete hotplug\n");
697 * The EEH device is still connected with its parent
698 * PE. We should disconnect it so the binding can be
699 * rebuilt when adding PCI devices.
701 edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
702 eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
703 if (pe->type & EEH_PE_VF) {
704 eeh_add_virt_device(edev, NULL);
706 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
707 pci_hp_add_devices(bus);
709 } else if (frozen_bus && rmv_data->removed) {
710 pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
713 edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
714 eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
715 if (pe->type & EEH_PE_VF)
716 eeh_add_virt_device(edev, NULL);
718 pci_hp_add_devices(frozen_bus);
720 eeh_pe_state_clear(pe, EEH_PE_KEEP);
723 pe->freeze_count = cnt;
725 pci_unlock_rescan_remove();
729 /* The longest amount of time to wait for a pci device
730 * to come back on line, in seconds.
732 #define MAX_WAIT_FOR_RECOVERY 300
735 * eeh_handle_normal_event - Handle EEH events on a specific PE
738 * Attempts to recover the given PE. If recovery fails or the PE has failed
739 * too many times, remove the PE.
741 * Returns true if @pe should no longer be used, else false.
743 static bool eeh_handle_normal_event(struct eeh_pe *pe)
745 struct pci_bus *frozen_bus;
746 struct eeh_dev *edev, *tmp;
748 enum pci_ers_result result = PCI_ERS_RESULT_NONE;
749 struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT(rmv_data.edev_list), 0};
751 frozen_bus = eeh_pe_bus_get(pe);
753 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
754 __func__, pe->phb->global_number, pe->addr);
758 eeh_pe_update_time_stamp(pe);
760 if (pe->freeze_count > eeh_max_freezes) {
761 pr_err("EEH: PHB#%x-PE#%x has failed %d times in the\n"
762 "last hour and has been permanently disabled.\n",
763 pe->phb->global_number, pe->addr,
767 pr_warn("EEH: This PCI device has failed %d times in the last hour\n",
770 /* Walk the various device drivers attached to this slot through
771 * a reset sequence, giving each an opportunity to do what it needs
772 * to accomplish the reset. Each child gets a report of the
773 * status ... if any child can't handle the reset, then the entire
774 * slot is dlpar removed and added.
776 * When the PHB is fenced, we have to issue a reset to recover from
777 * the error. Override the result if necessary to have partially
778 * hotplug for this case.
780 pr_info("EEH: Notify device drivers to shutdown\n");
781 eeh_pe_dev_traverse(pe, eeh_report_error, &result);
782 if ((pe->type & EEH_PE_PHB) &&
783 result != PCI_ERS_RESULT_NONE &&
784 result != PCI_ERS_RESULT_NEED_RESET)
785 result = PCI_ERS_RESULT_NEED_RESET;
787 /* Get the current PCI slot state. This can take a long time,
788 * sometimes over 300 seconds for certain systems.
790 rc = eeh_ops->wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
791 if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
792 pr_warn("EEH: Permanent failure\n");
796 /* Since rtas may enable MMIO when posting the error log,
797 * don't post the error log until after all dev drivers
798 * have been informed.
800 pr_info("EEH: Collect temporary log\n");
801 eeh_slot_error_detail(pe, EEH_LOG_TEMP);
803 /* If all device drivers were EEH-unaware, then shut
804 * down all of the device drivers, and hope they
805 * go down willingly, without panicing the system.
807 if (result == PCI_ERS_RESULT_NONE) {
808 pr_info("EEH: Reset with hotplug activity\n");
809 rc = eeh_reset_device(pe, frozen_bus, NULL);
811 pr_warn("%s: Unable to reset, err=%d\n",
817 /* If all devices reported they can proceed, then re-enable MMIO */
818 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
819 pr_info("EEH: Enable I/O for affected devices\n");
820 rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
825 result = PCI_ERS_RESULT_NEED_RESET;
827 pr_info("EEH: Notify device drivers to resume I/O\n");
828 eeh_pe_dev_traverse(pe, eeh_report_mmio_enabled, &result);
832 /* If all devices reported they can proceed, then re-enable DMA */
833 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
834 pr_info("EEH: Enabled DMA for affected devices\n");
835 rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
840 result = PCI_ERS_RESULT_NEED_RESET;
843 * We didn't do PE reset for the case. The PE
844 * is still in frozen state. Clear it before
847 eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
848 result = PCI_ERS_RESULT_RECOVERED;
852 /* If any device has a hard failure, then shut off everything. */
853 if (result == PCI_ERS_RESULT_DISCONNECT) {
854 pr_warn("EEH: Device driver gave up\n");
858 /* If any device called out for a reset, then reset the slot */
859 if (result == PCI_ERS_RESULT_NEED_RESET) {
860 pr_info("EEH: Reset without hotplug activity\n");
861 rc = eeh_reset_device(pe, NULL, &rmv_data);
863 pr_warn("%s: Cannot reset, err=%d\n",
868 pr_info("EEH: Notify device drivers "
869 "the completion of reset\n");
870 result = PCI_ERS_RESULT_NONE;
871 eeh_pe_dev_traverse(pe, eeh_report_reset, &result);
874 /* All devices should claim they have recovered by now. */
875 if ((result != PCI_ERS_RESULT_RECOVERED) &&
876 (result != PCI_ERS_RESULT_NONE)) {
877 pr_warn("EEH: Not recovered\n");
882 * For those hot removed VFs, we should add back them after PF get
883 * recovered properly.
885 list_for_each_entry_safe(edev, tmp, &rmv_data.edev_list, rmv_list) {
886 eeh_add_virt_device(edev, NULL);
887 list_del(&edev->rmv_list);
890 /* Tell all device drivers that they can resume operations */
891 pr_info("EEH: Notify device driver to resume\n");
892 eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
898 * About 90% of all real-life EEH failures in the field
899 * are due to poorly seated PCI cards. Only 10% or so are
900 * due to actual, failed cards.
902 pr_err("EEH: Unable to recover from failure from PHB#%x-PE#%x.\n"
903 "Please try reseating or replacing it\n",
904 pe->phb->global_number, pe->addr);
906 eeh_slot_error_detail(pe, EEH_LOG_PERM);
908 /* Notify all devices that they're about to go down. */
909 eeh_pe_dev_traverse(pe, eeh_report_failure, NULL);
911 /* Mark the PE to be removed permanently */
912 eeh_pe_state_mark(pe, EEH_PE_REMOVED);
915 * Shut down the device drivers for good. We mark
916 * all removed devices correctly to avoid access
917 * the their PCI config any more.
920 if (pe->type & EEH_PE_VF) {
921 eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
922 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
924 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
925 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
927 pci_lock_rescan_remove();
928 pci_hp_remove_devices(frozen_bus);
929 pci_unlock_rescan_remove();
931 /* The passed PE should no longer be used */
939 * eeh_handle_special_event - Handle EEH events without a specific failing PE
941 * Called when an EEH event is detected but can't be narrowed down to a
942 * specific PE. Iterates through possible failures and handles them as
945 static void eeh_handle_special_event(void)
947 struct eeh_pe *pe, *phb_pe;
949 struct pci_controller *hose;
955 rc = eeh_ops->next_error(&pe);
958 case EEH_NEXT_ERR_DEAD_IOC:
959 /* Mark all PHBs in dead state */
960 eeh_serialize_lock(&flags);
962 /* Purge all events */
963 eeh_remove_event(NULL, true);
965 list_for_each_entry(hose, &hose_list, list_node) {
966 phb_pe = eeh_phb_pe_get(hose);
967 if (!phb_pe) continue;
969 eeh_pe_state_mark(phb_pe, EEH_PE_ISOLATED);
972 eeh_serialize_unlock(flags);
975 case EEH_NEXT_ERR_FROZEN_PE:
976 case EEH_NEXT_ERR_FENCED_PHB:
977 case EEH_NEXT_ERR_DEAD_PHB:
978 /* Mark the PE in fenced state */
979 eeh_serialize_lock(&flags);
981 /* Purge all events of the PHB */
982 eeh_remove_event(pe, true);
984 if (rc == EEH_NEXT_ERR_DEAD_PHB)
985 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
987 eeh_pe_state_mark(pe,
988 EEH_PE_ISOLATED | EEH_PE_RECOVERING);
990 eeh_serialize_unlock(flags);
993 case EEH_NEXT_ERR_NONE:
996 pr_warn("%s: Invalid value %d from next_error()\n",
1002 * For fenced PHB and frozen PE, it's handled as normal
1003 * event. We have to remove the affected PHBs for dead
1006 if (rc == EEH_NEXT_ERR_FROZEN_PE ||
1007 rc == EEH_NEXT_ERR_FENCED_PHB) {
1009 * eeh_handle_normal_event() can make the PE stale if it
1010 * determines that the PE cannot possibly be recovered.
1011 * Don't modify the PE state if that's the case.
1013 if (eeh_handle_normal_event(pe))
1016 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
1018 pci_lock_rescan_remove();
1019 list_for_each_entry(hose, &hose_list, list_node) {
1020 phb_pe = eeh_phb_pe_get(hose);
1022 !(phb_pe->state & EEH_PE_ISOLATED) ||
1023 (phb_pe->state & EEH_PE_RECOVERING))
1026 /* Notify all devices to be down */
1027 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
1028 eeh_pe_dev_traverse(pe,
1029 eeh_report_failure, NULL);
1030 bus = eeh_pe_bus_get(phb_pe);
1032 pr_err("%s: Cannot find PCI bus for "
1035 pe->phb->global_number,
1039 pci_hp_remove_devices(bus);
1041 pci_unlock_rescan_remove();
1045 * If we have detected dead IOC, we needn't proceed
1046 * any more since all PHBs would have been removed
1048 if (rc == EEH_NEXT_ERR_DEAD_IOC)
1050 } while (rc != EEH_NEXT_ERR_NONE);
1054 * eeh_handle_event - Reset a PCI device after hard lockup.
1057 * While PHB detects address or data parity errors on particular PCI
1058 * slot, the associated PE will be frozen. Besides, DMA's occurring
1059 * to wild addresses (which usually happen due to bugs in device
1060 * drivers or in PCI adapter firmware) can cause EEH error. #SERR,
1061 * #PERR or other misc PCI-related errors also can trigger EEH errors.
1063 * Recovery process consists of unplugging the device driver (which
1064 * generated hotplug events to userspace), then issuing a PCI #RST to
1065 * the device, then reconfiguring the PCI config space for all bridges
1066 * & devices under this slot, and then finally restarting the device
1067 * drivers (which cause a second set of hotplug events to go out to
1070 void eeh_handle_event(struct eeh_pe *pe)
1073 eeh_handle_normal_event(pe);
1075 eeh_handle_special_event();