Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 ==================
0004 PCI Error Recovery
0005 ==================
0006 
0007 
0008 :Authors: - Linas Vepstas <linasvepstas@gmail.com>
0009           - Richard Lary <rlary@us.ibm.com>
0010           - Mike Mason <mmlnx@us.ibm.com>
0011 
0012 
0013 Many PCI bus controllers are able to detect a variety of hardware
0014 PCI errors on the bus, such as parity errors on the data and address
0015 buses, as well as SERR and PERR errors.  Some of the more advanced
0016 chipsets are able to deal with these errors; these include PCI-E chipsets,
0017 and the PCI-host bridges found on IBM Power4, Power5 and Power6-based
0018 pSeries boxes. A typical action taken is to disconnect the affected device,
0019 halting all I/O to it.  The goal of a disconnection is to avoid system
0020 corruption; for example, to halt system memory corruption due to DMA's
0021 to "wild" addresses. Typically, a reconnection mechanism is also
0022 offered, so that the affected PCI device(s) are reset and put back
0023 into working condition. The reset phase requires coordination
0024 between the affected device drivers and the PCI controller chip.
0025 This document describes a generic API for notifying device drivers
0026 of a bus disconnection, and then performing error recovery.
0027 This API is currently implemented in the 2.6.16 and later kernels.
0028 
0029 Reporting and recovery is performed in several steps. First, when
0030 a PCI hardware error has resulted in a bus disconnect, that event
0031 is reported as soon as possible to all affected device drivers,
0032 including multiple instances of a device driver on multi-function
0033 cards. This allows device drivers to avoid deadlocking in spinloops,
0034 waiting for some i/o-space register to change, when it never will.
0035 It also gives the drivers a chance to defer incoming I/O as
0036 needed.
0037 
0038 Next, recovery is performed in several stages. Most of the complexity
0039 is forced by the need to handle multi-function devices, that is,
0040 devices that have multiple device drivers associated with them.
0041 In the first stage, each driver is allowed to indicate what type
0042 of reset it desires, the choices being a simple re-enabling of I/O
0043 or requesting a slot reset.
0044 
0045 If any driver requests a slot reset, that is what will be done.
0046 
0047 After a reset and/or a re-enabling of I/O, all drivers are
0048 again notified, so that they may then perform any device setup/config
0049 that may be required.  After these have all completed, a final
0050 "resume normal operations" event is sent out.
0051 
0052 The biggest reason for choosing a kernel-based implementation rather
0053 than a user-space implementation was the need to deal with bus
0054 disconnects of PCI devices attached to storage media, and, in particular,
0055 disconnects from devices holding the root file system.  If the root
0056 file system is disconnected, a user-space mechanism would have to go
0057 through a large number of contortions to complete recovery. Almost all
0058 of the current Linux file systems are not tolerant of disconnection
0059 from/reconnection to their underlying block device. By contrast,
0060 bus errors are easy to manage in the device driver. Indeed, most
0061 device drivers already handle very similar recovery procedures;
0062 for example, the SCSI-generic layer already provides significant
0063 mechanisms for dealing with SCSI bus errors and SCSI bus resets.
0064 
0065 
0066 Detailed Design
0067 ===============
0068 
0069 Design and implementation details below, based on a chain of
0070 public email discussions with Ben Herrenschmidt, circa 5 April 2005.
0071 
0072 The error recovery API support is exposed to the driver in the form of
0073 a structure of function pointers pointed to by a new field in struct
0074 pci_driver. A driver that fails to provide the structure is "non-aware",
0075 and the actual recovery steps taken are platform dependent.  The
0076 arch/powerpc implementation will simulate a PCI hotplug remove/add.
0077 
0078 This structure has the form::
0079 
0080         struct pci_error_handlers
0081         {
0082                 int (*error_detected)(struct pci_dev *dev, pci_channel_state_t);
0083                 int (*mmio_enabled)(struct pci_dev *dev);
0084                 int (*slot_reset)(struct pci_dev *dev);
0085                 void (*resume)(struct pci_dev *dev);
0086         };
0087 
0088 The possible channel states are::
0089 
0090         typedef enum {
0091                 pci_channel_io_normal,  /* I/O channel is in normal state */
0092                 pci_channel_io_frozen,  /* I/O to channel is blocked */
0093                 pci_channel_io_perm_failure, /* PCI card is dead */
0094         } pci_channel_state_t;
0095 
0096 Possible return values are::
0097 
0098         enum pci_ers_result {
0099                 PCI_ERS_RESULT_NONE,        /* no result/none/not supported in device driver */
0100                 PCI_ERS_RESULT_CAN_RECOVER, /* Device driver can recover without slot reset */
0101                 PCI_ERS_RESULT_NEED_RESET,  /* Device driver wants slot to be reset. */
0102                 PCI_ERS_RESULT_DISCONNECT,  /* Device has completely failed, is unrecoverable */
0103                 PCI_ERS_RESULT_RECOVERED,   /* Device driver is fully recovered and operational */
0104         };
0105 
0106 A driver does not have to implement all of these callbacks; however,
0107 if it implements any, it must implement error_detected(). If a callback
0108 is not implemented, the corresponding feature is considered unsupported.
0109 For example, if mmio_enabled() and resume() aren't there, then it
0110 is assumed that the driver is not doing any direct recovery and requires
0111 a slot reset.  Typically a driver will want to know about
0112 a slot_reset().
0113 
0114 The actual steps taken by a platform to recover from a PCI error
0115 event will be platform-dependent, but will follow the general
0116 sequence described below.
0117 
0118 STEP 0: Error Event
0119 -------------------
0120 A PCI bus error is detected by the PCI hardware.  On powerpc, the slot
0121 is isolated, in that all I/O is blocked: all reads return 0xffffffff,
0122 all writes are ignored.
0123 
0124 
0125 STEP 1: Notification
0126 --------------------
0127 Platform calls the error_detected() callback on every instance of
0128 every driver affected by the error.
0129 
0130 At this point, the device might not be accessible anymore, depending on
0131 the platform (the slot will be isolated on powerpc). The driver may
0132 already have "noticed" the error because of a failing I/O, but this
0133 is the proper "synchronization point", that is, it gives the driver
0134 a chance to cleanup, waiting for pending stuff (timers, whatever, etc...)
0135 to complete; it can take semaphores, schedule, etc... everything but
0136 touch the device. Within this function and after it returns, the driver
0137 shouldn't do any new IOs. Called in task context. This is sort of a
0138 "quiesce" point. See note about interrupts at the end of this doc.
0139 
0140 All drivers participating in this system must implement this call.
0141 The driver must return one of the following result codes:
0142 
0143   - PCI_ERS_RESULT_CAN_RECOVER
0144       Driver returns this if it thinks it might be able to recover
0145       the HW by just banging IOs or if it wants to be given
0146       a chance to extract some diagnostic information (see
0147       mmio_enable, below).
0148   - PCI_ERS_RESULT_NEED_RESET
0149       Driver returns this if it can't recover without a
0150       slot reset.
0151   - PCI_ERS_RESULT_DISCONNECT
0152       Driver returns this if it doesn't want to recover at all.
0153 
0154 The next step taken will depend on the result codes returned by the
0155 drivers.
0156 
0157 If all drivers on the segment/slot return PCI_ERS_RESULT_CAN_RECOVER,
0158 then the platform should re-enable IOs on the slot (or do nothing in
0159 particular, if the platform doesn't isolate slots), and recovery
0160 proceeds to STEP 2 (MMIO Enable).
0161 
0162 If any driver requested a slot reset (by returning PCI_ERS_RESULT_NEED_RESET),
0163 then recovery proceeds to STEP 4 (Slot Reset).
0164 
0165 If the platform is unable to recover the slot, the next step
0166 is STEP 6 (Permanent Failure).
0167 
0168 .. note::
0169 
0170    The current powerpc implementation assumes that a device driver will
0171    *not* schedule or semaphore in this routine; the current powerpc
0172    implementation uses one kernel thread to notify all devices;
0173    thus, if one device sleeps/schedules, all devices are affected.
0174    Doing better requires complex multi-threaded logic in the error
0175    recovery implementation (e.g. waiting for all notification threads
0176    to "join" before proceeding with recovery.)  This seems excessively
0177    complex and not worth implementing.
0178 
0179    The current powerpc implementation doesn't much care if the device
0180    attempts I/O at this point, or not.  I/O's will fail, returning
0181    a value of 0xff on read, and writes will be dropped. If more than
0182    EEH_MAX_FAILS I/O's are attempted to a frozen adapter, EEH
0183    assumes that the device driver has gone into an infinite loop
0184    and prints an error to syslog.  A reboot is then required to
0185    get the device working again.
0186 
0187 STEP 2: MMIO Enabled
0188 --------------------
0189 The platform re-enables MMIO to the device (but typically not the
0190 DMA), and then calls the mmio_enabled() callback on all affected
0191 device drivers.
0192 
0193 This is the "early recovery" call. IOs are allowed again, but DMA is
0194 not, with some restrictions. This is NOT a callback for the driver to
0195 start operations again, only to peek/poke at the device, extract diagnostic
0196 information, if any, and eventually do things like trigger a device local
0197 reset or some such, but not restart operations. This callback is made if
0198 all drivers on a segment agree that they can try to recover and if no automatic
0199 link reset was performed by the HW. If the platform can't just re-enable IOs
0200 without a slot reset or a link reset, it will not call this callback, and
0201 instead will have gone directly to STEP 3 (Link Reset) or STEP 4 (Slot Reset)
0202 
0203 .. note::
0204 
0205    The following is proposed; no platform implements this yet:
0206    Proposal: All I/O's should be done _synchronously_ from within
0207    this callback, errors triggered by them will be returned via
0208    the normal pci_check_whatever() API, no new error_detected()
0209    callback will be issued due to an error happening here. However,
0210    such an error might cause IOs to be re-blocked for the whole
0211    segment, and thus invalidate the recovery that other devices
0212    on the same segment might have done, forcing the whole segment
0213    into one of the next states, that is, link reset or slot reset.
0214 
0215 The driver should return one of the following result codes:
0216   - PCI_ERS_RESULT_RECOVERED
0217       Driver returns this if it thinks the device is fully
0218       functional and thinks it is ready to start
0219       normal driver operations again. There is no
0220       guarantee that the driver will actually be
0221       allowed to proceed, as another driver on the
0222       same segment might have failed and thus triggered a
0223       slot reset on platforms that support it.
0224 
0225   - PCI_ERS_RESULT_NEED_RESET
0226       Driver returns this if it thinks the device is not
0227       recoverable in its current state and it needs a slot
0228       reset to proceed.
0229 
0230   - PCI_ERS_RESULT_DISCONNECT
0231       Same as above. Total failure, no recovery even after
0232       reset driver dead. (To be defined more precisely)
0233 
0234 The next step taken depends on the results returned by the drivers.
0235 If all drivers returned PCI_ERS_RESULT_RECOVERED, then the platform
0236 proceeds to either STEP3 (Link Reset) or to STEP 5 (Resume Operations).
0237 
0238 If any driver returned PCI_ERS_RESULT_NEED_RESET, then the platform
0239 proceeds to STEP 4 (Slot Reset)
0240 
0241 STEP 3: Link Reset
0242 ------------------
0243 The platform resets the link.  This is a PCI-Express specific step
0244 and is done whenever a fatal error has been detected that can be
0245 "solved" by resetting the link.
0246 
0247 STEP 4: Slot Reset
0248 ------------------
0249 
0250 In response to a return value of PCI_ERS_RESULT_NEED_RESET, the
0251 platform will perform a slot reset on the requesting PCI device(s).
0252 The actual steps taken by a platform to perform a slot reset
0253 will be platform-dependent. Upon completion of slot reset, the
0254 platform will call the device slot_reset() callback.
0255 
0256 Powerpc platforms implement two levels of slot reset:
0257 soft reset(default) and fundamental(optional) reset.
0258 
0259 Powerpc soft reset consists of asserting the adapter #RST line and then
0260 restoring the PCI BAR's and PCI configuration header to a state
0261 that is equivalent to what it would be after a fresh system
0262 power-on followed by power-on BIOS/system firmware initialization.
0263 Soft reset is also known as hot-reset.
0264 
0265 Powerpc fundamental reset is supported by PCI Express cards only
0266 and results in device's state machines, hardware logic, port states and
0267 configuration registers to initialize to their default conditions.
0268 
0269 For most PCI devices, a soft reset will be sufficient for recovery.
0270 Optional fundamental reset is provided to support a limited number
0271 of PCI Express devices for which a soft reset is not sufficient
0272 for recovery.
0273 
0274 If the platform supports PCI hotplug, then the reset might be
0275 performed by toggling the slot electrical power off/on.
0276 
0277 It is important for the platform to restore the PCI config space
0278 to the "fresh poweron" state, rather than the "last state". After
0279 a slot reset, the device driver will almost always use its standard
0280 device initialization routines, and an unusual config space setup
0281 may result in hung devices, kernel panics, or silent data corruption.
0282 
0283 This call gives drivers the chance to re-initialize the hardware
0284 (re-download firmware, etc.).  At this point, the driver may assume
0285 that the card is in a fresh state and is fully functional. The slot
0286 is unfrozen and the driver has full access to PCI config space,
0287 memory mapped I/O space and DMA. Interrupts (Legacy, MSI, or MSI-X)
0288 will also be available.
0289 
0290 Drivers should not restart normal I/O processing operations
0291 at this point.  If all device drivers report success on this
0292 callback, the platform will call resume() to complete the sequence,
0293 and let the driver restart normal I/O processing.
0294 
0295 A driver can still return a critical failure for this function if
0296 it can't get the device operational after reset.  If the platform
0297 previously tried a soft reset, it might now try a hard reset (power
0298 cycle) and then call slot_reset() again.  If the device still can't
0299 be recovered, there is nothing more that can be done;  the platform
0300 will typically report a "permanent failure" in such a case.  The
0301 device will be considered "dead" in this case.
0302 
0303 Drivers for multi-function cards will need to coordinate among
0304 themselves as to which driver instance will perform any "one-shot"
0305 or global device initialization. For example, the Symbios sym53cxx2
0306 driver performs device init only from PCI function 0::
0307 
0308         +       if (PCI_FUNC(pdev->devfn) == 0)
0309         +               sym_reset_scsi_bus(np, 0);
0310 
0311 Result codes:
0312         - PCI_ERS_RESULT_DISCONNECT
0313           Same as above.
0314 
0315 Drivers for PCI Express cards that require a fundamental reset must
0316 set the needs_freset bit in the pci_dev structure in their probe function.
0317 For example, the QLogic qla2xxx driver sets the needs_freset bit for certain
0318 PCI card types::
0319 
0320         +       /* Set EEH reset type to fundamental if required by hba  */
0321         +       if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
0322         +               pdev->needs_freset = 1;
0323         +
0324 
0325 Platform proceeds either to STEP 5 (Resume Operations) or STEP 6 (Permanent
0326 Failure).
0327 
0328 .. note::
0329 
0330    The current powerpc implementation does not try a power-cycle
0331    reset if the driver returned PCI_ERS_RESULT_DISCONNECT.
0332    However, it probably should.
0333 
0334 
0335 STEP 5: Resume Operations
0336 -------------------------
0337 The platform will call the resume() callback on all affected device
0338 drivers if all drivers on the segment have returned
0339 PCI_ERS_RESULT_RECOVERED from one of the 3 previous callbacks.
0340 The goal of this callback is to tell the driver to restart activity,
0341 that everything is back and running. This callback does not return
0342 a result code.
0343 
0344 At this point, if a new error happens, the platform will restart
0345 a new error recovery sequence.
0346 
0347 STEP 6: Permanent Failure
0348 -------------------------
0349 A "permanent failure" has occurred, and the platform cannot recover
0350 the device.  The platform will call error_detected() with a
0351 pci_channel_state_t value of pci_channel_io_perm_failure.
0352 
0353 The device driver should, at this point, assume the worst. It should
0354 cancel all pending I/O, refuse all new I/O, returning -EIO to
0355 higher layers. The device driver should then clean up all of its
0356 memory and remove itself from kernel operations, much as it would
0357 during system shutdown.
0358 
0359 The platform will typically notify the system operator of the
0360 permanent failure in some way.  If the device is hotplug-capable,
0361 the operator will probably want to remove and replace the device.
0362 Note, however, not all failures are truly "permanent". Some are
0363 caused by over-heating, some by a poorly seated card. Many
0364 PCI error events are caused by software bugs, e.g. DMA's to
0365 wild addresses or bogus split transactions due to programming
0366 errors. See the discussion in powerpc/eeh-pci-error-recovery.txt
0367 for additional detail on real-life experience of the causes of
0368 software errors.
0369 
0370 
0371 Conclusion; General Remarks
0372 ---------------------------
0373 The way the callbacks are called is platform policy. A platform with
0374 no slot reset capability may want to just "ignore" drivers that can't
0375 recover (disconnect them) and try to let other cards on the same segment
0376 recover. Keep in mind that in most real life cases, though, there will
0377 be only one driver per segment.
0378 
0379 Now, a note about interrupts. If you get an interrupt and your
0380 device is dead or has been isolated, there is a problem :)
0381 The current policy is to turn this into a platform policy.
0382 That is, the recovery API only requires that:
0383 
0384  - There is no guarantee that interrupt delivery can proceed from any
0385    device on the segment starting from the error detection and until the
0386    slot_reset callback is called, at which point interrupts are expected
0387    to be fully operational.
0388 
0389  - There is no guarantee that interrupt delivery is stopped, that is,
0390    a driver that gets an interrupt after detecting an error, or that detects
0391    an error within the interrupt handler such that it prevents proper
0392    ack'ing of the interrupt (and thus removal of the source) should just
0393    return IRQ_NOTHANDLED. It's up to the platform to deal with that
0394    condition, typically by masking the IRQ source during the duration of
0395    the error handling. It is expected that the platform "knows" which
0396    interrupts are routed to error-management capable slots and can deal
0397    with temporarily disabling that IRQ number during error processing (this
0398    isn't terribly complex). That means some IRQ latency for other devices
0399    sharing the interrupt, but there is simply no other way. High end
0400    platforms aren't supposed to share interrupts between many devices
0401    anyway :)
0402 
0403 .. note::
0404 
0405    Implementation details for the powerpc platform are discussed in
0406    the file Documentation/powerpc/eeh-pci-error-recovery.rst
0407 
0408    As of this writing, there is a growing list of device drivers with
0409    patches implementing error recovery. Not all of these patches are in
0410    mainline yet. These may be used as "examples":
0411 
0412    - drivers/scsi/ipr
0413    - drivers/scsi/sym53c8xx_2
0414    - drivers/scsi/qla2xxx
0415    - drivers/scsi/lpfc
0416    - drivers/next/bnx2.c
0417    - drivers/next/e100.c
0418    - drivers/net/e1000
0419    - drivers/net/e1000e
0420    - drivers/net/ixgb
0421    - drivers/net/ixgbe
0422    - drivers/net/cxgb3
0423    - drivers/net/s2io.c
0424 
0425 The End
0426 -------