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