Path: blob/master/Documentation/PCI/pci-error-recovery.txt
10821 views
1PCI Error Recovery2------------------3February 2, 200645Current document maintainer:6Linas Vepstas <[email protected]>7updated by Richard Lary <[email protected]>8and Mike Mason <[email protected]> on 27-Jul-200991011Many PCI bus controllers are able to detect a variety of hardware12PCI errors on the bus, such as parity errors on the data and address13busses, as well as SERR and PERR errors. Some of the more advanced14chipsets are able to deal with these errors; these include PCI-E chipsets,15and the PCI-host bridges found on IBM Power4, Power5 and Power6-based16pSeries boxes. A typical action taken is to disconnect the affected device,17halting all I/O to it. The goal of a disconnection is to avoid system18corruption; for example, to halt system memory corruption due to DMA's19to "wild" addresses. Typically, a reconnection mechanism is also20offered, so that the affected PCI device(s) are reset and put back21into working condition. The reset phase requires coordination22between the affected device drivers and the PCI controller chip.23This document describes a generic API for notifying device drivers24of a bus disconnection, and then performing error recovery.25This API is currently implemented in the 2.6.16 and later kernels.2627Reporting and recovery is performed in several steps. First, when28a PCI hardware error has resulted in a bus disconnect, that event29is reported as soon as possible to all affected device drivers,30including multiple instances of a device driver on multi-function31cards. This allows device drivers to avoid deadlocking in spinloops,32waiting for some i/o-space register to change, when it never will.33It also gives the drivers a chance to defer incoming I/O as34needed.3536Next, recovery is performed in several stages. Most of the complexity37is forced by the need to handle multi-function devices, that is,38devices that have multiple device drivers associated with them.39In the first stage, each driver is allowed to indicate what type40of reset it desires, the choices being a simple re-enabling of I/O41or requesting a slot reset.4243If any driver requests a slot reset, that is what will be done.4445After a reset and/or a re-enabling of I/O, all drivers are46again notified, so that they may then perform any device setup/config47that may be required. After these have all completed, a final48"resume normal operations" event is sent out.4950The biggest reason for choosing a kernel-based implementation rather51than a user-space implementation was the need to deal with bus52disconnects of PCI devices attached to storage media, and, in particular,53disconnects from devices holding the root file system. If the root54file system is disconnected, a user-space mechanism would have to go55through a large number of contortions to complete recovery. Almost all56of the current Linux file systems are not tolerant of disconnection57from/reconnection to their underlying block device. By contrast,58bus errors are easy to manage in the device driver. Indeed, most59device drivers already handle very similar recovery procedures;60for example, the SCSI-generic layer already provides significant61mechanisms for dealing with SCSI bus errors and SCSI bus resets.626364Detailed Design65---------------66Design and implementation details below, based on a chain of67public email discussions with Ben Herrenschmidt, circa 5 April 2005.6869The error recovery API support is exposed to the driver in the form of70a structure of function pointers pointed to by a new field in struct71pci_driver. A driver that fails to provide the structure is "non-aware",72and the actual recovery steps taken are platform dependent. The73arch/powerpc implementation will simulate a PCI hotplug remove/add.7475This structure has the form:76struct pci_error_handlers77{78int (*error_detected)(struct pci_dev *dev, enum pci_channel_state);79int (*mmio_enabled)(struct pci_dev *dev);80int (*link_reset)(struct pci_dev *dev);81int (*slot_reset)(struct pci_dev *dev);82void (*resume)(struct pci_dev *dev);83};8485The possible channel states are:86enum pci_channel_state {87pci_channel_io_normal, /* I/O channel is in normal state */88pci_channel_io_frozen, /* I/O to channel is blocked */89pci_channel_io_perm_failure, /* PCI card is dead */90};9192Possible return values are:93enum pci_ers_result {94PCI_ERS_RESULT_NONE, /* no result/none/not supported in device driver */95PCI_ERS_RESULT_CAN_RECOVER, /* Device driver can recover without slot reset */96PCI_ERS_RESULT_NEED_RESET, /* Device driver wants slot to be reset. */97PCI_ERS_RESULT_DISCONNECT, /* Device has completely failed, is unrecoverable */98PCI_ERS_RESULT_RECOVERED, /* Device driver is fully recovered and operational */99};100101A driver does not have to implement all of these callbacks; however,102if it implements any, it must implement error_detected(). If a callback103is not implemented, the corresponding feature is considered unsupported.104For example, if mmio_enabled() and resume() aren't there, then it105is assumed that the driver is not doing any direct recovery and requires106a slot reset. If link_reset() is not implemented, the card is assumed to107not care about link resets. Typically a driver will want to know about108a slot_reset().109110The actual steps taken by a platform to recover from a PCI error111event will be platform-dependent, but will follow the general112sequence described below.113114STEP 0: Error Event115-------------------116A PCI bus error is detected by the PCI hardware. On powerpc, the slot117is isolated, in that all I/O is blocked: all reads return 0xffffffff,118all writes are ignored.119120121STEP 1: Notification122--------------------123Platform calls the error_detected() callback on every instance of124every driver affected by the error.125126At this point, the device might not be accessible anymore, depending on127the platform (the slot will be isolated on powerpc). The driver may128already have "noticed" the error because of a failing I/O, but this129is the proper "synchronization point", that is, it gives the driver130a chance to cleanup, waiting for pending stuff (timers, whatever, etc...)131to complete; it can take semaphores, schedule, etc... everything but132touch the device. Within this function and after it returns, the driver133shouldn't do any new IOs. Called in task context. This is sort of a134"quiesce" point. See note about interrupts at the end of this doc.135136All drivers participating in this system must implement this call.137The driver must return one of the following result codes:138- PCI_ERS_RESULT_CAN_RECOVER:139Driver returns this if it thinks it might be able to recover140the HW by just banging IOs or if it wants to be given141a chance to extract some diagnostic information (see142mmio_enable, below).143- PCI_ERS_RESULT_NEED_RESET:144Driver returns this if it can't recover without a145slot reset.146- PCI_ERS_RESULT_DISCONNECT:147Driver returns this if it doesn't want to recover at all.148149The next step taken will depend on the result codes returned by the150drivers.151152If all drivers on the segment/slot return PCI_ERS_RESULT_CAN_RECOVER,153then the platform should re-enable IOs on the slot (or do nothing in154particular, if the platform doesn't isolate slots), and recovery155proceeds to STEP 2 (MMIO Enable).156157If any driver requested a slot reset (by returning PCI_ERS_RESULT_NEED_RESET),158then recovery proceeds to STEP 4 (Slot Reset).159160If the platform is unable to recover the slot, the next step161is STEP 6 (Permanent Failure).162163>>> The current powerpc implementation assumes that a device driver will164>>> *not* schedule or semaphore in this routine; the current powerpc165>>> implementation uses one kernel thread to notify all devices;166>>> thus, if one device sleeps/schedules, all devices are affected.167>>> Doing better requires complex multi-threaded logic in the error168>>> recovery implementation (e.g. waiting for all notification threads169>>> to "join" before proceeding with recovery.) This seems excessively170>>> complex and not worth implementing.171172>>> The current powerpc implementation doesn't much care if the device173>>> attempts I/O at this point, or not. I/O's will fail, returning174>>> a value of 0xff on read, and writes will be dropped. If more than175>>> EEH_MAX_FAILS I/O's are attempted to a frozen adapter, EEH176>>> assumes that the device driver has gone into an infinite loop177>>> and prints an error to syslog. A reboot is then required to178>>> get the device working again.179180STEP 2: MMIO Enabled181-------------------182The platform re-enables MMIO to the device (but typically not the183DMA), and then calls the mmio_enabled() callback on all affected184device drivers.185186This is the "early recovery" call. IOs are allowed again, but DMA is187not, with some restrictions. This is NOT a callback for the driver to188start operations again, only to peek/poke at the device, extract diagnostic189information, if any, and eventually do things like trigger a device local190reset or some such, but not restart operations. This callback is made if191all drivers on a segment agree that they can try to recover and if no automatic192link reset was performed by the HW. If the platform can't just re-enable IOs193without a slot reset or a link reset, it will not call this callback, and194instead will have gone directly to STEP 3 (Link Reset) or STEP 4 (Slot Reset)195196>>> The following is proposed; no platform implements this yet:197>>> Proposal: All I/O's should be done _synchronously_ from within198>>> this callback, errors triggered by them will be returned via199>>> the normal pci_check_whatever() API, no new error_detected()200>>> callback will be issued due to an error happening here. However,201>>> such an error might cause IOs to be re-blocked for the whole202>>> segment, and thus invalidate the recovery that other devices203>>> on the same segment might have done, forcing the whole segment204>>> into one of the next states, that is, link reset or slot reset.205206The driver should return one of the following result codes:207- PCI_ERS_RESULT_RECOVERED208Driver returns this if it thinks the device is fully209functional and thinks it is ready to start210normal driver operations again. There is no211guarantee that the driver will actually be212allowed to proceed, as another driver on the213same segment might have failed and thus triggered a214slot reset on platforms that support it.215216- PCI_ERS_RESULT_NEED_RESET217Driver returns this if it thinks the device is not218recoverable in its current state and it needs a slot219reset to proceed.220221- PCI_ERS_RESULT_DISCONNECT222Same as above. Total failure, no recovery even after223reset driver dead. (To be defined more precisely)224225The next step taken depends on the results returned by the drivers.226If all drivers returned PCI_ERS_RESULT_RECOVERED, then the platform227proceeds to either STEP3 (Link Reset) or to STEP 5 (Resume Operations).228229If any driver returned PCI_ERS_RESULT_NEED_RESET, then the platform230proceeds to STEP 4 (Slot Reset)231232STEP 3: Link Reset233------------------234The platform resets the link, and then calls the link_reset() callback235on all affected device drivers. This is a PCI-Express specific state236and is done whenever a non-fatal error has been detected that can be237"solved" by resetting the link. This call informs the driver of the238reset and the driver should check to see if the device appears to be239in working condition.240241The driver is not supposed to restart normal driver I/O operations242at this point. It should limit itself to "probing" the device to243check its recoverability status. If all is right, then the platform244will call resume() once all drivers have ack'd link_reset().245246Result codes:247(identical to STEP 3 (MMIO Enabled)248249The platform then proceeds to either STEP 4 (Slot Reset) or STEP 5250(Resume Operations).251252>>> The current powerpc implementation does not implement this callback.253254STEP 4: Slot Reset255------------------256257In response to a return value of PCI_ERS_RESULT_NEED_RESET, the258the platform will peform a slot reset on the requesting PCI device(s).259The actual steps taken by a platform to perform a slot reset260will be platform-dependent. Upon completion of slot reset, the261platform will call the device slot_reset() callback.262263Powerpc platforms implement two levels of slot reset:264soft reset(default) and fundamental(optional) reset.265266Powerpc soft reset consists of asserting the adapter #RST line and then267restoring the PCI BAR's and PCI configuration header to a state268that is equivalent to what it would be after a fresh system269power-on followed by power-on BIOS/system firmware initialization.270Soft reset is also known as hot-reset.271272Powerpc fundamental reset is supported by PCI Express cards only273and results in device's state machines, hardware logic, port states and274configuration registers to initialize to their default conditions.275276For most PCI devices, a soft reset will be sufficient for recovery.277Optional fundamental reset is provided to support a limited number278of PCI Express PCI devices for which a soft reset is not sufficient279for recovery.280281If the platform supports PCI hotplug, then the reset might be282performed by toggling the slot electrical power off/on.283284It is important for the platform to restore the PCI config space285to the "fresh poweron" state, rather than the "last state". After286a slot reset, the device driver will almost always use its standard287device initialization routines, and an unusual config space setup288may result in hung devices, kernel panics, or silent data corruption.289290This call gives drivers the chance to re-initialize the hardware291(re-download firmware, etc.). At this point, the driver may assume292that the card is in a fresh state and is fully functional. The slot293is unfrozen and the driver has full access to PCI config space,294memory mapped I/O space and DMA. Interrupts (Legacy, MSI, or MSI-X)295will also be available.296297Drivers should not restart normal I/O processing operations298at this point. If all device drivers report success on this299callback, the platform will call resume() to complete the sequence,300and let the driver restart normal I/O processing.301302A driver can still return a critical failure for this function if303it can't get the device operational after reset. If the platform304previously tried a soft reset, it might now try a hard reset (power305cycle) and then call slot_reset() again. It the device still can't306be recovered, there is nothing more that can be done; the platform307will typically report a "permanent failure" in such a case. The308device will be considered "dead" in this case.309310Drivers for multi-function cards will need to coordinate among311themselves as to which driver instance will perform any "one-shot"312or global device initialization. For example, the Symbios sym53cxx2313driver performs device init only from PCI function 0:314315+ if (PCI_FUNC(pdev->devfn) == 0)316+ sym_reset_scsi_bus(np, 0);317318Result codes:319- PCI_ERS_RESULT_DISCONNECT320Same as above.321322Drivers for PCI Express cards that require a fundamental reset must323set the needs_freset bit in the pci_dev structure in their probe function.324For example, the QLogic qla2xxx driver sets the needs_freset bit for certain325PCI card types:326327+ /* Set EEH reset type to fundamental if required by hba */328+ if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))329+ pdev->needs_freset = 1;330+331332Platform proceeds either to STEP 5 (Resume Operations) or STEP 6 (Permanent333Failure).334335>>> The current powerpc implementation does not try a power-cycle336>>> reset if the driver returned PCI_ERS_RESULT_DISCONNECT.337>>> However, it probably should.338339340STEP 5: Resume Operations341-------------------------342The platform will call the resume() callback on all affected device343drivers if all drivers on the segment have returned344PCI_ERS_RESULT_RECOVERED from one of the 3 previous callbacks.345The goal of this callback is to tell the driver to restart activity,346that everything is back and running. This callback does not return347a result code.348349At this point, if a new error happens, the platform will restart350a new error recovery sequence.351352STEP 6: Permanent Failure353-------------------------354A "permanent failure" has occurred, and the platform cannot recover355the device. The platform will call error_detected() with a356pci_channel_state value of pci_channel_io_perm_failure.357358The device driver should, at this point, assume the worst. It should359cancel all pending I/O, refuse all new I/O, returning -EIO to360higher layers. The device driver should then clean up all of its361memory and remove itself from kernel operations, much as it would362during system shutdown.363364The platform will typically notify the system operator of the365permanent failure in some way. If the device is hotplug-capable,366the operator will probably want to remove and replace the device.367Note, however, not all failures are truly "permanent". Some are368caused by over-heating, some by a poorly seated card. Many369PCI error events are caused by software bugs, e.g. DMA's to370wild addresses or bogus split transactions due to programming371errors. See the discussion in powerpc/eeh-pci-error-recovery.txt372for additional detail on real-life experience of the causes of373software errors.374375376Conclusion; General Remarks377---------------------------378The way the callbacks are called is platform policy. A platform with379no slot reset capability may want to just "ignore" drivers that can't380recover (disconnect them) and try to let other cards on the same segment381recover. Keep in mind that in most real life cases, though, there will382be only one driver per segment.383384Now, a note about interrupts. If you get an interrupt and your385device is dead or has been isolated, there is a problem :)386The current policy is to turn this into a platform policy.387That is, the recovery API only requires that:388389- There is no guarantee that interrupt delivery can proceed from any390device on the segment starting from the error detection and until the391slot_reset callback is called, at which point interrupts are expected392to be fully operational.393394- There is no guarantee that interrupt delivery is stopped, that is,395a driver that gets an interrupt after detecting an error, or that detects396an error within the interrupt handler such that it prevents proper397ack'ing of the interrupt (and thus removal of the source) should just398return IRQ_NOTHANDLED. It's up to the platform to deal with that399condition, typically by masking the IRQ source during the duration of400the error handling. It is expected that the platform "knows" which401interrupts are routed to error-management capable slots and can deal402with temporarily disabling that IRQ number during error processing (this403isn't terribly complex). That means some IRQ latency for other devices404sharing the interrupt, but there is simply no other way. High end405platforms aren't supposed to share interrupts between many devices406anyway :)407408>>> Implementation details for the powerpc platform are discussed in409>>> the file Documentation/powerpc/eeh-pci-error-recovery.txt410411>>> As of this writing, there is a growing list of device drivers with412>>> patches implementing error recovery. Not all of these patches are in413>>> mainline yet. These may be used as "examples":414>>>415>>> drivers/scsi/ipr416>>> drivers/scsi/sym53c8xx_2417>>> drivers/scsi/qla2xxx418>>> drivers/scsi/lpfc419>>> drivers/next/bnx2.c420>>> drivers/next/e100.c421>>> drivers/net/e1000422>>> drivers/net/e1000e423>>> drivers/net/ixgb424>>> drivers/net/ixgbe425>>> drivers/net/cxgb3426>>> drivers/net/s2io.c427>>> drivers/net/qlge428429The End430-------431432433