pcieaer-howto.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. The PCI Express Advanced Error Reporting Driver Guide HOWTO
  2. T. Long Nguyen <tom.l.nguyen@intel.com>
  3. Yanmin Zhang <yanmin.zhang@intel.com>
  4. 07/29/2006
  5. 1. Overview
  6. 1.1 About this guide
  7. This guide describes the basics of the PCI Express Advanced Error
  8. Reporting (AER) driver and provides information on how to use it, as
  9. well as how to enable the drivers of endpoint devices to conform with
  10. PCI Express AER driver.
  11. 1.2 Copyright (C) Intel Corporation 2006.
  12. 1.3 What is the PCI Express AER Driver?
  13. PCI Express error signaling can occur on the PCI Express link itself
  14. or on behalf of transactions initiated on the link. PCI Express
  15. defines two error reporting paradigms: the baseline capability and
  16. the Advanced Error Reporting capability. The baseline capability is
  17. required of all PCI Express components providing a minimum defined
  18. set of error reporting requirements. Advanced Error Reporting
  19. capability is implemented with a PCI Express advanced error reporting
  20. extended capability structure providing more robust error reporting.
  21. The PCI Express AER driver provides the infrastructure to support PCI
  22. Express Advanced Error Reporting capability. The PCI Express AER
  23. driver provides three basic functions:
  24. - Gathers the comprehensive error information if errors occurred.
  25. - Reports error to the users.
  26. - Performs error recovery actions.
  27. AER driver only attaches root ports which support PCI-Express AER
  28. capability.
  29. 2. User Guide
  30. 2.1 Include the PCI Express AER Root Driver into the Linux Kernel
  31. The PCI Express AER Root driver is a Root Port service driver attached
  32. to the PCI Express Port Bus driver. If a user wants to use it, the driver
  33. has to be compiled. Option CONFIG_PCIEAER supports this capability. It
  34. depends on CONFIG_PCIEPORTBUS, so pls. set CONFIG_PCIEPORTBUS=y and
  35. CONFIG_PCIEAER = y.
  36. 2.2 Load PCI Express AER Root Driver
  37. Some systems have AER support in firmware. Enabling Linux AER support at
  38. the same time the firmware handles AER may result in unpredictable
  39. behavior. Therefore, Linux does not handle AER events unless the firmware
  40. grants AER control to the OS via the ACPI _OSC method. See the PCI FW 3.0
  41. Specification for details regarding _OSC usage.
  42. 2.3 AER error output
  43. When a PCIe AER error is captured, an error message will be output to
  44. console. If it's a correctable error, it is output as a warning.
  45. Otherwise, it is printed as an error. So users could choose different
  46. log level to filter out correctable error messages.
  47. Below shows an example:
  48. 0000:50:00.0: PCIe Bus Error: severity=Uncorrected (Fatal), type=Transaction Layer, id=0500(Requester ID)
  49. 0000:50:00.0: device [8086:0329] error status/mask=00100000/00000000
  50. 0000:50:00.0: [20] Unsupported Request (First)
  51. 0000:50:00.0: TLP Header: 04000001 00200a03 05010000 00050100
  52. In the example, 'Requester ID' means the ID of the device who sends
  53. the error message to root port. Pls. refer to pci express specs for
  54. other fields.
  55. 3. Developer Guide
  56. To enable AER aware support requires a software driver to configure
  57. the AER capability structure within its device and to provide callbacks.
  58. To support AER better, developers need understand how AER does work
  59. firstly.
  60. PCI Express errors are classified into two types: correctable errors
  61. and uncorrectable errors. This classification is based on the impacts
  62. of those errors, which may result in degraded performance or function
  63. failure.
  64. Correctable errors pose no impacts on the functionality of the
  65. interface. The PCI Express protocol can recover without any software
  66. intervention or any loss of data. These errors are detected and
  67. corrected by hardware. Unlike correctable errors, uncorrectable
  68. errors impact functionality of the interface. Uncorrectable errors
  69. can cause a particular transaction or a particular PCI Express link
  70. to be unreliable. Depending on those error conditions, uncorrectable
  71. errors are further classified into non-fatal errors and fatal errors.
  72. Non-fatal errors cause the particular transaction to be unreliable,
  73. but the PCI Express link itself is fully functional. Fatal errors, on
  74. the other hand, cause the link to be unreliable.
  75. When AER is enabled, a PCI Express device will automatically send an
  76. error message to the PCIe root port above it when the device captures
  77. an error. The Root Port, upon receiving an error reporting message,
  78. internally processes and logs the error message in its PCI Express
  79. capability structure. Error information being logged includes storing
  80. the error reporting agent's requestor ID into the Error Source
  81. Identification Registers and setting the error bits of the Root Error
  82. Status Register accordingly. If AER error reporting is enabled in Root
  83. Error Command Register, the Root Port generates an interrupt if an
  84. error is detected.
  85. Note that the errors as described above are related to the PCI Express
  86. hierarchy and links. These errors do not include any device specific
  87. errors because device specific errors will still get sent directly to
  88. the device driver.
  89. 3.1 Configure the AER capability structure
  90. AER aware drivers of PCI Express component need change the device
  91. control registers to enable AER. They also could change AER registers,
  92. including mask and severity registers. Helper function
  93. pci_enable_pcie_error_reporting could be used to enable AER. See
  94. section 3.3.
  95. 3.2. Provide callbacks
  96. 3.2.1 callback reset_link to reset pci express link
  97. This callback is used to reset the pci express physical link when a
  98. fatal error happens. The root port aer service driver provides a
  99. default reset_link function, but different upstream ports might
  100. have different specifications to reset pci express link, so all
  101. upstream ports should provide their own reset_link functions.
  102. In struct pcie_port_service_driver, a new pointer, reset_link, is
  103. added.
  104. pci_ers_result_t (*reset_link) (struct pci_dev *dev);
  105. Section 3.2.2.2 provides more detailed info on when to call
  106. reset_link.
  107. 3.2.2 PCI error-recovery callbacks
  108. The PCI Express AER Root driver uses error callbacks to coordinate
  109. with downstream device drivers associated with a hierarchy in question
  110. when performing error recovery actions.
  111. Data struct pci_driver has a pointer, err_handler, to point to
  112. pci_error_handlers who consists of a couple of callback function
  113. pointers. AER driver follows the rules defined in
  114. pci-error-recovery.txt except pci express specific parts (e.g.
  115. reset_link). Pls. refer to pci-error-recovery.txt for detailed
  116. definitions of the callbacks.
  117. Below sections specify when to call the error callback functions.
  118. 3.2.2.1 Correctable errors
  119. Correctable errors pose no impacts on the functionality of
  120. the interface. The PCI Express protocol can recover without any
  121. software intervention or any loss of data. These errors do not
  122. require any recovery actions. The AER driver clears the device's
  123. correctable error status register accordingly and logs these errors.
  124. 3.2.2.2 Non-correctable (non-fatal and fatal) errors
  125. If an error message indicates a non-fatal error, performing link reset
  126. at upstream is not required. The AER driver calls error_detected(dev,
  127. pci_channel_io_normal) to all drivers associated within a hierarchy in
  128. question. for example,
  129. EndPoint<==>DownstreamPort B<==>UpstreamPort A<==>RootPort.
  130. If Upstream port A captures an AER error, the hierarchy consists of
  131. Downstream port B and EndPoint.
  132. A driver may return PCI_ERS_RESULT_CAN_RECOVER,
  133. PCI_ERS_RESULT_DISCONNECT, or PCI_ERS_RESULT_NEED_RESET, depending on
  134. whether it can recover or the AER driver calls mmio_enabled as next.
  135. If an error message indicates a fatal error, kernel will broadcast
  136. error_detected(dev, pci_channel_io_frozen) to all drivers within
  137. a hierarchy in question. Then, performing link reset at upstream is
  138. necessary. As different kinds of devices might use different approaches
  139. to reset link, AER port service driver is required to provide the
  140. function to reset link. Firstly, kernel looks for if the upstream
  141. component has an aer driver. If it has, kernel uses the reset_link
  142. callback of the aer driver. If the upstream component has no aer driver
  143. and the port is downstream port, we will perform a hot reset as the
  144. default by setting the Secondary Bus Reset bit of the Bridge Control
  145. register associated with the downstream port. As for upstream ports,
  146. they should provide their own aer service drivers with reset_link
  147. function. If error_detected returns PCI_ERS_RESULT_CAN_RECOVER and
  148. reset_link returns PCI_ERS_RESULT_RECOVERED, the error handling goes
  149. to mmio_enabled.
  150. 3.3 helper functions
  151. 3.3.1 int pci_enable_pcie_error_reporting(struct pci_dev *dev);
  152. pci_enable_pcie_error_reporting enables the device to send error
  153. messages to root port when an error is detected. Note that devices
  154. don't enable the error reporting by default, so device drivers need
  155. call this function to enable it.
  156. 3.3.2 int pci_disable_pcie_error_reporting(struct pci_dev *dev);
  157. pci_disable_pcie_error_reporting disables the device to send error
  158. messages to root port when an error is detected.
  159. 3.3.3 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev);
  160. pci_cleanup_aer_uncorrect_error_status cleanups the uncorrectable
  161. error status register.
  162. 3.4 Frequent Asked Questions
  163. Q: What happens if a PCI Express device driver does not provide an
  164. error recovery handler (pci_driver->err_handler is equal to NULL)?
  165. A: The devices attached with the driver won't be recovered. If the
  166. error is fatal, kernel will print out warning messages. Please refer
  167. to section 3 for more information.
  168. Q: What happens if an upstream port service driver does not provide
  169. callback reset_link?
  170. A: Fatal error recovery will fail if the errors are reported by the
  171. upstream ports who are attached by the service driver.
  172. Q: How does this infrastructure deal with driver that is not PCI
  173. Express aware?
  174. A: This infrastructure calls the error callback functions of the
  175. driver when an error happens. But if the driver is not aware of
  176. PCI Express, the device might not report its own errors to root
  177. port.
  178. Q: What modifications will that driver need to make it compatible
  179. with the PCI Express AER Root driver?
  180. A: It could call the helper functions to enable AER in devices and
  181. cleanup uncorrectable status register. Pls. refer to section 3.3.
  182. 4. Software error injection
  183. Debugging PCIe AER error recovery code is quite difficult because it
  184. is hard to trigger real hardware errors. Software based error
  185. injection can be used to fake various kinds of PCIe errors.
  186. First you should enable PCIe AER software error injection in kernel
  187. configuration, that is, following item should be in your .config.
  188. CONFIG_PCIEAER_INJECT=y or CONFIG_PCIEAER_INJECT=m
  189. After reboot with new kernel or insert the module, a device file named
  190. /dev/aer_inject should be created.
  191. Then, you need a user space tool named aer-inject, which can be gotten
  192. from:
  193. http://www.kernel.org/pub/linux/utils/pci/aer-inject/
  194. More information about aer-inject can be found in the document comes
  195. with its source code.