/src/qemu/hw/pci/pcie_aer.c
Line | Count | Source |
1 | | /* |
2 | | * pcie_aer.c |
3 | | * |
4 | | * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp> |
5 | | * VA Linux Systems Japan K.K. |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * This program is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License along |
18 | | * with this program; if not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #include "qemu/osdep.h" |
22 | | #include "migration/vmstate.h" |
23 | | #include "hw/pci/pci_bridge.h" |
24 | | #include "hw/pci/pcie.h" |
25 | | #include "hw/pci/msix.h" |
26 | | #include "hw/pci/msi.h" |
27 | | #include "hw/pci/pci_bus.h" |
28 | | #include "hw/pci/pcie_regs.h" |
29 | | #include "pci-internal.h" |
30 | | |
31 | | //#define DEBUG_PCIE |
32 | | #ifdef DEBUG_PCIE |
33 | | # define PCIE_DPRINTF(fmt, ...) \ |
34 | | fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__) |
35 | | #else |
36 | | # define PCIE_DPRINTF(fmt, ...) do {} while (0) |
37 | | #endif |
38 | | #define PCIE_DEV_PRINTF(dev, fmt, ...) \ |
39 | | PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__) |
40 | | |
41 | 0 | #define PCI_ERR_SRC_COR_OFFS 0 |
42 | 0 | #define PCI_ERR_SRC_UNCOR_OFFS 2 |
43 | | |
44 | | /* From 6.2.7 Error Listing and Rules. Table 6-2, 6-3 and 6-4 */ |
45 | | static uint32_t pcie_aer_uncor_default_severity(uint32_t status) |
46 | 0 | { |
47 | 0 | switch (status) { |
48 | 0 | case PCI_ERR_UNC_INTN: |
49 | 0 | case PCI_ERR_UNC_DLP: |
50 | 0 | case PCI_ERR_UNC_SDN: |
51 | 0 | case PCI_ERR_UNC_RX_OVER: |
52 | 0 | case PCI_ERR_UNC_FCP: |
53 | 0 | case PCI_ERR_UNC_MALF_TLP: |
54 | 0 | return PCI_ERR_ROOT_CMD_FATAL_EN; |
55 | 0 | case PCI_ERR_UNC_POISON_TLP: |
56 | 0 | case PCI_ERR_UNC_ECRC: |
57 | 0 | case PCI_ERR_UNC_UNSUP: |
58 | 0 | case PCI_ERR_UNC_COMP_TIME: |
59 | 0 | case PCI_ERR_UNC_COMP_ABORT: |
60 | 0 | case PCI_ERR_UNC_UNX_COMP: |
61 | 0 | case PCI_ERR_UNC_ACSV: |
62 | 0 | case PCI_ERR_UNC_MCBTLP: |
63 | 0 | case PCI_ERR_UNC_ATOP_EBLOCKED: |
64 | 0 | case PCI_ERR_UNC_TLP_PRF_BLOCKED: |
65 | 0 | return PCI_ERR_ROOT_CMD_NONFATAL_EN; |
66 | 0 | default: |
67 | 0 | abort(); |
68 | 0 | break; |
69 | 0 | } |
70 | 0 | return PCI_ERR_ROOT_CMD_FATAL_EN; |
71 | 0 | } |
72 | | |
73 | | static int aer_log_add_err(PCIEAERLog *aer_log, const PCIEAERErr *err) |
74 | 0 | { |
75 | 0 | if (aer_log->log_num == aer_log->log_max) { |
76 | 0 | return -1; |
77 | 0 | } |
78 | 0 | memcpy(&aer_log->log[aer_log->log_num], err, sizeof *err); |
79 | 0 | aer_log->log_num++; |
80 | 0 | return 0; |
81 | 0 | } |
82 | | |
83 | | static void aer_log_del_err(PCIEAERLog *aer_log, PCIEAERErr *err) |
84 | 0 | { |
85 | 0 | assert(aer_log->log_num); |
86 | 0 | *err = aer_log->log[0]; |
87 | 0 | aer_log->log_num--; |
88 | 0 | memmove(&aer_log->log[0], &aer_log->log[1], |
89 | 0 | aer_log->log_num * sizeof *err); |
90 | 0 | } |
91 | | |
92 | | static void aer_log_clear_all_err(PCIEAERLog *aer_log) |
93 | 0 | { |
94 | 0 | aer_log->log_num = 0; |
95 | 0 | } |
96 | | |
97 | | int pcie_aer_init(PCIDevice *dev, uint8_t cap_ver, uint16_t offset, |
98 | | uint16_t size, Error **errp) |
99 | 23 | { |
100 | 23 | pcie_add_capability(dev, PCI_EXT_CAP_ID_ERR, cap_ver, |
101 | 23 | offset, size); |
102 | 23 | dev->exp.aer_cap = offset; |
103 | | |
104 | | /* clip down the value to avoid unreasonable memory usage */ |
105 | 23 | if (dev->exp.aer_log.log_max > PCIE_AER_LOG_MAX_LIMIT) { |
106 | 0 | error_setg(errp, "Invalid aer_log_max %d. The max number of aer log " |
107 | 0 | "is %d", dev->exp.aer_log.log_max, PCIE_AER_LOG_MAX_LIMIT); |
108 | 0 | return -EINVAL; |
109 | 0 | } |
110 | 23 | dev->exp.aer_log.log = g_malloc0(sizeof dev->exp.aer_log.log[0] * |
111 | 23 | dev->exp.aer_log.log_max); |
112 | | |
113 | 23 | pci_set_long(dev->w1cmask + offset + PCI_ERR_UNCOR_STATUS, |
114 | 23 | PCI_ERR_UNC_SUPPORTED); |
115 | | |
116 | 23 | if (dev->cap_present & QEMU_PCIE_ERR_UNC_MASK) { |
117 | 23 | pci_set_long(dev->config + offset + PCI_ERR_UNCOR_MASK, |
118 | 23 | PCI_ERR_UNC_MASK_DEFAULT); |
119 | 23 | pci_set_long(dev->wmask + offset + PCI_ERR_UNCOR_MASK, |
120 | 23 | PCI_ERR_UNC_SUPPORTED); |
121 | 23 | } |
122 | | |
123 | 23 | pci_set_long(dev->config + offset + PCI_ERR_UNCOR_SEVER, |
124 | 23 | PCI_ERR_UNC_SEVERITY_DEFAULT); |
125 | 23 | pci_set_long(dev->wmask + offset + PCI_ERR_UNCOR_SEVER, |
126 | 23 | PCI_ERR_UNC_SUPPORTED); |
127 | | |
128 | 23 | pci_long_test_and_set_mask(dev->w1cmask + offset + PCI_ERR_COR_STATUS, |
129 | 23 | PCI_ERR_COR_SUPPORTED); |
130 | | |
131 | 23 | pci_set_long(dev->config + offset + PCI_ERR_COR_MASK, |
132 | 23 | PCI_ERR_COR_MASK_DEFAULT); |
133 | 23 | pci_set_long(dev->wmask + offset + PCI_ERR_COR_MASK, |
134 | 23 | PCI_ERR_COR_SUPPORTED); |
135 | | |
136 | | /* capabilities and control. multiple header logging is supported */ |
137 | 23 | if (dev->exp.aer_log.log_max > 0) { |
138 | 0 | pci_set_long(dev->config + offset + PCI_ERR_CAP, |
139 | 0 | PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC | |
140 | 0 | PCI_ERR_CAP_MHRC); |
141 | 0 | pci_set_long(dev->wmask + offset + PCI_ERR_CAP, |
142 | 0 | PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE | |
143 | 0 | PCI_ERR_CAP_MHRE); |
144 | 23 | } else { |
145 | 23 | pci_set_long(dev->config + offset + PCI_ERR_CAP, |
146 | 23 | PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC); |
147 | 23 | pci_set_long(dev->wmask + offset + PCI_ERR_CAP, |
148 | 23 | PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE); |
149 | 23 | } |
150 | | |
151 | 23 | switch (pcie_cap_get_type(dev)) { |
152 | 0 | case PCI_EXP_TYPE_ROOT_PORT: |
153 | | /* this case will be set by pcie_aer_root_init() */ |
154 | | /* fallthrough */ |
155 | 0 | case PCI_EXP_TYPE_DOWNSTREAM: |
156 | 0 | case PCI_EXP_TYPE_UPSTREAM: |
157 | 0 | pci_word_test_and_set_mask(dev->wmask + PCI_BRIDGE_CONTROL, |
158 | 0 | PCI_BRIDGE_CTL_SERR); |
159 | 0 | pci_long_test_and_set_mask(dev->w1cmask + PCI_STATUS, |
160 | 0 | PCI_SEC_STATUS_RCV_SYSTEM_ERROR); |
161 | 0 | break; |
162 | 23 | default: |
163 | | /* nothing */ |
164 | 23 | break; |
165 | 23 | } |
166 | 23 | return 0; |
167 | 23 | } |
168 | | |
169 | | void pcie_aer_exit(PCIDevice *dev) |
170 | 0 | { |
171 | 0 | g_free(dev->exp.aer_log.log); |
172 | 0 | } |
173 | | |
174 | | static void pcie_aer_update_uncor_status(PCIDevice *dev) |
175 | 0 | { |
176 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
177 | 0 | PCIEAERLog *aer_log = &dev->exp.aer_log; |
178 | |
|
179 | 0 | uint16_t i; |
180 | 0 | for (i = 0; i < aer_log->log_num; i++) { |
181 | 0 | pci_long_test_and_set_mask(aer_cap + PCI_ERR_UNCOR_STATUS, |
182 | 0 | dev->exp.aer_log.log[i].status); |
183 | 0 | } |
184 | 0 | } |
185 | | |
186 | | /* |
187 | | * return value: |
188 | | * true: error message needs to be sent up |
189 | | * false: error message is masked |
190 | | * |
191 | | * 6.2.6 Error Message Control |
192 | | * Figure 6-3 |
193 | | * all pci express devices part |
194 | | */ |
195 | | static bool |
196 | | pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg) |
197 | 0 | { |
198 | 0 | uint16_t devctl = pci_get_word(dev->config + dev->exp.exp_cap + |
199 | 0 | PCI_EXP_DEVCTL); |
200 | 0 | if (!(pcie_aer_msg_is_uncor(msg) && |
201 | 0 | (pci_get_word(dev->config + PCI_COMMAND) & PCI_COMMAND_SERR)) && |
202 | 0 | !((msg->severity == PCI_ERR_ROOT_CMD_NONFATAL_EN) && |
203 | 0 | (devctl & PCI_EXP_DEVCTL_NFERE)) && |
204 | 0 | !((msg->severity == PCI_ERR_ROOT_CMD_COR_EN) && |
205 | 0 | (devctl & PCI_EXP_DEVCTL_CERE)) && |
206 | 0 | !((msg->severity == PCI_ERR_ROOT_CMD_FATAL_EN) && |
207 | 0 | (devctl & PCI_EXP_DEVCTL_FERE))) { |
208 | 0 | return false; |
209 | 0 | } |
210 | | |
211 | | /* Signaled System Error |
212 | | * |
213 | | * 7.5.1.1 Command register |
214 | | * Bit 8 SERR# Enable |
215 | | * |
216 | | * When Set, this bit enables reporting of Non-fatal and Fatal |
217 | | * errors detected by the Function to the Root Complex. Note that |
218 | | * errors are reported if enabled either through this bit or through |
219 | | * the PCI Express specific bits in the Device Control register (see |
220 | | * Section 7.8.4). |
221 | | */ |
222 | 0 | pci_word_test_and_set_mask(dev->config + PCI_STATUS, |
223 | 0 | PCI_STATUS_SIG_SYSTEM_ERROR); |
224 | |
|
225 | 0 | if (!(msg->severity & |
226 | 0 | pci_get_word(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL))) { |
227 | 0 | return false; |
228 | 0 | } |
229 | | |
230 | | /* send up error message */ |
231 | 0 | return true; |
232 | 0 | } |
233 | | |
234 | | /* |
235 | | * return value: |
236 | | * true: error message is sent up |
237 | | * false: error message is masked |
238 | | * |
239 | | * 6.2.6 Error Message Control |
240 | | * Figure 6-3 |
241 | | * virtual pci bridge part |
242 | | */ |
243 | | static bool pcie_aer_msg_vbridge(PCIDevice *dev, const PCIEAERMsg *msg) |
244 | 0 | { |
245 | 0 | uint16_t bridge_control = pci_get_word(dev->config + PCI_BRIDGE_CONTROL); |
246 | |
|
247 | 0 | if (pcie_aer_msg_is_uncor(msg)) { |
248 | | /* Received System Error */ |
249 | 0 | pci_word_test_and_set_mask(dev->config + PCI_SEC_STATUS, |
250 | 0 | PCI_SEC_STATUS_RCV_SYSTEM_ERROR); |
251 | 0 | } |
252 | |
|
253 | 0 | if (!(bridge_control & PCI_BRIDGE_CTL_SERR)) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | return true; |
257 | 0 | } |
258 | | |
259 | | void pcie_aer_root_set_vector(PCIDevice *dev, unsigned int vector) |
260 | 0 | { |
261 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
262 | 0 | assert(vector < PCI_ERR_ROOT_IRQ_MAX); |
263 | 0 | pci_long_test_and_clear_mask(aer_cap + PCI_ERR_ROOT_STATUS, |
264 | 0 | PCI_ERR_ROOT_IRQ); |
265 | 0 | pci_long_test_and_set_mask(aer_cap + PCI_ERR_ROOT_STATUS, |
266 | 0 | vector << PCI_ERR_ROOT_IRQ_SHIFT); |
267 | 0 | } |
268 | | |
269 | | static unsigned int pcie_aer_root_get_vector(PCIDevice *dev) |
270 | 0 | { |
271 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
272 | 0 | uint32_t root_status = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS); |
273 | 0 | return (root_status & PCI_ERR_ROOT_IRQ) >> PCI_ERR_ROOT_IRQ_SHIFT; |
274 | 0 | } |
275 | | |
276 | | /* Given a status register, get corresponding bits in the command register */ |
277 | | static uint32_t pcie_aer_status_to_cmd(uint32_t status) |
278 | 0 | { |
279 | 0 | uint32_t cmd = 0; |
280 | 0 | if (status & PCI_ERR_ROOT_COR_RCV) { |
281 | 0 | cmd |= PCI_ERR_ROOT_CMD_COR_EN; |
282 | 0 | } |
283 | 0 | if (status & PCI_ERR_ROOT_NONFATAL_RCV) { |
284 | 0 | cmd |= PCI_ERR_ROOT_CMD_NONFATAL_EN; |
285 | 0 | } |
286 | 0 | if (status & PCI_ERR_ROOT_FATAL_RCV) { |
287 | 0 | cmd |= PCI_ERR_ROOT_CMD_FATAL_EN; |
288 | 0 | } |
289 | 0 | return cmd; |
290 | 0 | } |
291 | | |
292 | | static void pcie_aer_root_notify(PCIDevice *dev) |
293 | 0 | { |
294 | 0 | if (msix_enabled(dev)) { |
295 | 0 | msix_notify(dev, pcie_aer_root_get_vector(dev)); |
296 | 0 | } else if (msi_enabled(dev)) { |
297 | 0 | msi_notify(dev, pcie_aer_root_get_vector(dev)); |
298 | 0 | } else if (pci_intx(dev) != -1) { |
299 | 0 | pci_irq_assert(dev); |
300 | 0 | } |
301 | 0 | } |
302 | | |
303 | | /* |
304 | | * 6.2.6 Error Message Control |
305 | | * Figure 6-3 |
306 | | * root port part |
307 | | */ |
308 | | static void pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg) |
309 | 0 | { |
310 | 0 | uint16_t cmd; |
311 | 0 | uint8_t *aer_cap; |
312 | 0 | uint32_t root_cmd; |
313 | 0 | uint32_t root_status, prev_status; |
314 | |
|
315 | 0 | cmd = pci_get_word(dev->config + PCI_COMMAND); |
316 | 0 | aer_cap = dev->config + dev->exp.aer_cap; |
317 | 0 | root_cmd = pci_get_long(aer_cap + PCI_ERR_ROOT_COMMAND); |
318 | 0 | prev_status = root_status = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS); |
319 | |
|
320 | 0 | if (cmd & PCI_COMMAND_SERR) { |
321 | | /* System Error. |
322 | | * |
323 | | * The way to report System Error is platform specific and |
324 | | * it isn't implemented in qemu right now. |
325 | | * So just discard the error for now. |
326 | | * OS which cares of aer would receive errors via |
327 | | * native aer mechanisms, so this wouldn't matter. |
328 | | */ |
329 | 0 | } |
330 | | |
331 | | /* Error Message Received: Root Error Status register */ |
332 | 0 | switch (msg->severity) { |
333 | 0 | case PCI_ERR_ROOT_CMD_COR_EN: |
334 | 0 | if (root_status & PCI_ERR_ROOT_COR_RCV) { |
335 | 0 | root_status |= PCI_ERR_ROOT_MULTI_COR_RCV; |
336 | 0 | } else { |
337 | 0 | pci_set_word(aer_cap + PCI_ERR_ROOT_ERR_SRC + PCI_ERR_SRC_COR_OFFS, |
338 | 0 | msg->source_id); |
339 | 0 | } |
340 | 0 | root_status |= PCI_ERR_ROOT_COR_RCV; |
341 | 0 | break; |
342 | 0 | case PCI_ERR_ROOT_CMD_NONFATAL_EN: |
343 | 0 | root_status |= PCI_ERR_ROOT_NONFATAL_RCV; |
344 | 0 | break; |
345 | 0 | case PCI_ERR_ROOT_CMD_FATAL_EN: |
346 | 0 | if (!(root_status & PCI_ERR_ROOT_UNCOR_RCV)) { |
347 | 0 | root_status |= PCI_ERR_ROOT_FIRST_FATAL; |
348 | 0 | } |
349 | 0 | root_status |= PCI_ERR_ROOT_FATAL_RCV; |
350 | 0 | break; |
351 | 0 | default: |
352 | 0 | abort(); |
353 | 0 | break; |
354 | 0 | } |
355 | 0 | if (pcie_aer_msg_is_uncor(msg)) { |
356 | 0 | if (root_status & PCI_ERR_ROOT_UNCOR_RCV) { |
357 | 0 | root_status |= PCI_ERR_ROOT_MULTI_UNCOR_RCV; |
358 | 0 | } else { |
359 | 0 | pci_set_word(aer_cap + PCI_ERR_ROOT_ERR_SRC + |
360 | 0 | PCI_ERR_SRC_UNCOR_OFFS, msg->source_id); |
361 | 0 | } |
362 | 0 | root_status |= PCI_ERR_ROOT_UNCOR_RCV; |
363 | 0 | } |
364 | 0 | pci_set_long(aer_cap + PCI_ERR_ROOT_STATUS, root_status); |
365 | | |
366 | | /* 6.2.4.1.2 Interrupt Generation */ |
367 | | /* All the above did was set some bits in the status register. |
368 | | * Specifically these that match message severity. |
369 | | * The below code relies on this fact. */ |
370 | 0 | if (!(root_cmd & msg->severity) || |
371 | 0 | (pcie_aer_status_to_cmd(prev_status) & root_cmd)) { |
372 | | /* Condition is not being set or was already true so nothing to do. */ |
373 | 0 | return; |
374 | 0 | } |
375 | | |
376 | 0 | pcie_aer_root_notify(dev); |
377 | 0 | } |
378 | | |
379 | | /* |
380 | | * 6.2.6 Error Message Control Figure 6-3 |
381 | | * |
382 | | * Walk up the bus tree from the device, propagate the error message. |
383 | | */ |
384 | | static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg) |
385 | 0 | { |
386 | 0 | uint8_t type; |
387 | |
|
388 | 0 | while (dev) { |
389 | 0 | if (!pci_is_express(dev)) { |
390 | | /* just ignore it */ |
391 | | /* TODO: Shouldn't we set PCI_STATUS_SIG_SYSTEM_ERROR? |
392 | | * Consider e.g. a PCI bridge above a PCI Express device. */ |
393 | 0 | return; |
394 | 0 | } |
395 | | |
396 | 0 | type = pcie_cap_get_type(dev); |
397 | 0 | if ((type == PCI_EXP_TYPE_ROOT_PORT || |
398 | 0 | type == PCI_EXP_TYPE_UPSTREAM || |
399 | 0 | type == PCI_EXP_TYPE_DOWNSTREAM) && |
400 | 0 | !pcie_aer_msg_vbridge(dev, msg)) { |
401 | 0 | return; |
402 | 0 | } |
403 | 0 | if (!pcie_aer_msg_alldev(dev, msg)) { |
404 | 0 | return; |
405 | 0 | } |
406 | 0 | if (type == PCI_EXP_TYPE_ROOT_PORT) { |
407 | 0 | pcie_aer_msg_root_port(dev, msg); |
408 | | /* Root port can notify system itself, |
409 | | or send the error message to root complex event collector. */ |
410 | | /* |
411 | | * if root port is associated with an event collector, |
412 | | * return the root complex event collector here. |
413 | | * For now root complex event collector isn't supported. |
414 | | */ |
415 | 0 | return; |
416 | 0 | } |
417 | 0 | dev = pci_bridge_get_device(pci_get_bus(dev)); |
418 | 0 | } |
419 | 0 | } |
420 | | |
421 | | static void pcie_aer_update_log(PCIDevice *dev, const PCIEAERErr *err) |
422 | 0 | { |
423 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
424 | 0 | uint8_t first_bit = ctz32(err->status); |
425 | 0 | uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP); |
426 | 0 | int i; |
427 | |
|
428 | 0 | assert(err->status); |
429 | 0 | assert(!(err->status & (err->status - 1))); |
430 | |
|
431 | 0 | errcap &= ~(PCI_ERR_CAP_FEP_MASK | PCI_ERR_CAP_TLP); |
432 | 0 | errcap |= PCI_ERR_CAP_FEP(first_bit); |
433 | |
|
434 | 0 | if (err->flags & PCIE_AER_ERR_HEADER_VALID) { |
435 | 0 | for (i = 0; i < ARRAY_SIZE(err->header); ++i) { |
436 | | /* 7.10.8 Header Log Register */ |
437 | 0 | uint8_t *header_log = |
438 | 0 | aer_cap + PCI_ERR_HEADER_LOG + i * sizeof err->header[0]; |
439 | 0 | stl_be_p(header_log, err->header[i]); |
440 | 0 | } |
441 | 0 | } else { |
442 | 0 | assert(!(err->flags & PCIE_AER_ERR_TLP_PREFIX_PRESENT)); |
443 | 0 | memset(aer_cap + PCI_ERR_HEADER_LOG, 0, PCI_ERR_HEADER_LOG_SIZE); |
444 | 0 | } |
445 | |
|
446 | 0 | if ((err->flags & PCIE_AER_ERR_TLP_PREFIX_PRESENT) && |
447 | 0 | (pci_get_long(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCAP2) & |
448 | 0 | PCI_EXP_DEVCAP2_EETLPP)) { |
449 | 0 | for (i = 0; i < ARRAY_SIZE(err->prefix); ++i) { |
450 | | /* 7.10.12 tlp prefix log register */ |
451 | 0 | uint8_t *prefix_log = |
452 | 0 | aer_cap + PCI_ERR_TLP_PREFIX_LOG + i * sizeof err->prefix[0]; |
453 | 0 | stl_be_p(prefix_log, err->prefix[i]); |
454 | 0 | } |
455 | 0 | errcap |= PCI_ERR_CAP_TLP; |
456 | 0 | } else { |
457 | 0 | memset(aer_cap + PCI_ERR_TLP_PREFIX_LOG, 0, |
458 | 0 | PCI_ERR_TLP_PREFIX_LOG_SIZE); |
459 | 0 | } |
460 | 0 | pci_set_long(aer_cap + PCI_ERR_CAP, errcap); |
461 | 0 | } |
462 | | |
463 | | static void pcie_aer_clear_log(PCIDevice *dev) |
464 | 0 | { |
465 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
466 | |
|
467 | 0 | pci_long_test_and_clear_mask(aer_cap + PCI_ERR_CAP, |
468 | 0 | PCI_ERR_CAP_FEP_MASK | PCI_ERR_CAP_TLP); |
469 | |
|
470 | 0 | memset(aer_cap + PCI_ERR_HEADER_LOG, 0, PCI_ERR_HEADER_LOG_SIZE); |
471 | 0 | memset(aer_cap + PCI_ERR_TLP_PREFIX_LOG, 0, PCI_ERR_TLP_PREFIX_LOG_SIZE); |
472 | 0 | } |
473 | | |
474 | | static void pcie_aer_clear_error(PCIDevice *dev) |
475 | 0 | { |
476 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
477 | 0 | uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP); |
478 | 0 | PCIEAERLog *aer_log = &dev->exp.aer_log; |
479 | 0 | PCIEAERErr err; |
480 | |
|
481 | 0 | if (!(errcap & PCI_ERR_CAP_MHRE) || !aer_log->log_num) { |
482 | 0 | pcie_aer_clear_log(dev); |
483 | 0 | return; |
484 | 0 | } |
485 | | |
486 | | /* |
487 | | * If more errors are queued, set corresponding bits in uncorrectable |
488 | | * error status. |
489 | | * We emulate uncorrectable error status register as W1CS. |
490 | | * So set bit in uncorrectable error status here again for multiple |
491 | | * error recording support. |
492 | | * |
493 | | * 6.2.4.2 Multiple Error Handling(Advanced Error Reporting Capability) |
494 | | */ |
495 | 0 | pcie_aer_update_uncor_status(dev); |
496 | |
|
497 | 0 | aer_log_del_err(aer_log, &err); |
498 | 0 | pcie_aer_update_log(dev, &err); |
499 | 0 | } |
500 | | |
501 | | static int pcie_aer_record_error(PCIDevice *dev, |
502 | | const PCIEAERErr *err) |
503 | 0 | { |
504 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
505 | 0 | uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP); |
506 | 0 | int fep = PCI_ERR_CAP_FEP(errcap); |
507 | |
|
508 | 0 | assert(err->status); |
509 | 0 | assert(!(err->status & (err->status - 1))); |
510 | |
|
511 | 0 | if (errcap & PCI_ERR_CAP_MHRE && |
512 | 0 | (pci_get_long(aer_cap + PCI_ERR_UNCOR_STATUS) & (1U << fep))) { |
513 | | /* Not first error. queue error */ |
514 | 0 | if (aer_log_add_err(&dev->exp.aer_log, err) < 0) { |
515 | | /* overflow */ |
516 | 0 | return -1; |
517 | 0 | } |
518 | 0 | return 0; |
519 | 0 | } |
520 | | |
521 | 0 | pcie_aer_update_log(dev, err); |
522 | 0 | return 0; |
523 | 0 | } |
524 | | |
525 | | typedef struct PCIEAERInject { |
526 | | PCIDevice *dev; |
527 | | uint8_t *aer_cap; |
528 | | const PCIEAERErr *err; |
529 | | uint16_t devctl; |
530 | | uint16_t devsta; |
531 | | uint32_t error_status; |
532 | | bool unsupported_request; |
533 | | bool log_overflow; |
534 | | PCIEAERMsg msg; |
535 | | } PCIEAERInject; |
536 | | |
537 | | static bool pcie_aer_inject_cor_error(PCIEAERInject *inj, |
538 | | uint32_t uncor_status, |
539 | | bool is_advisory_nonfatal) |
540 | 0 | { |
541 | 0 | PCIDevice *dev = inj->dev; |
542 | |
|
543 | 0 | inj->devsta |= PCI_EXP_DEVSTA_CED; |
544 | 0 | if (inj->unsupported_request) { |
545 | 0 | inj->devsta |= PCI_EXP_DEVSTA_URD; |
546 | 0 | } |
547 | 0 | pci_set_word(dev->config + dev->exp.exp_cap + PCI_EXP_DEVSTA, inj->devsta); |
548 | |
|
549 | 0 | if (inj->aer_cap) { |
550 | 0 | uint32_t mask; |
551 | 0 | pci_long_test_and_set_mask(inj->aer_cap + PCI_ERR_COR_STATUS, |
552 | 0 | inj->error_status); |
553 | 0 | mask = pci_get_long(inj->aer_cap + PCI_ERR_COR_MASK); |
554 | 0 | if (mask & inj->error_status) { |
555 | 0 | return false; |
556 | 0 | } |
557 | 0 | if (is_advisory_nonfatal) { |
558 | 0 | uint32_t uncor_mask = |
559 | 0 | pci_get_long(inj->aer_cap + PCI_ERR_UNCOR_MASK); |
560 | 0 | if (!(uncor_mask & uncor_status)) { |
561 | 0 | inj->log_overflow = !!pcie_aer_record_error(dev, inj->err); |
562 | 0 | } |
563 | 0 | pci_long_test_and_set_mask(inj->aer_cap + PCI_ERR_UNCOR_STATUS, |
564 | 0 | uncor_status); |
565 | 0 | } |
566 | 0 | } |
567 | | |
568 | 0 | if (inj->unsupported_request && !(inj->devctl & PCI_EXP_DEVCTL_URRE)) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | if (!(inj->devctl & PCI_EXP_DEVCTL_CERE)) { |
572 | 0 | return false; |
573 | 0 | } |
574 | | |
575 | 0 | inj->msg.severity = PCI_ERR_ROOT_CMD_COR_EN; |
576 | 0 | return true; |
577 | 0 | } |
578 | | |
579 | | static bool pcie_aer_inject_uncor_error(PCIEAERInject *inj, bool is_fatal) |
580 | 0 | { |
581 | 0 | PCIDevice *dev = inj->dev; |
582 | 0 | uint16_t cmd; |
583 | |
|
584 | 0 | if (is_fatal) { |
585 | 0 | inj->devsta |= PCI_EXP_DEVSTA_FED; |
586 | 0 | } else { |
587 | 0 | inj->devsta |= PCI_EXP_DEVSTA_NFED; |
588 | 0 | } |
589 | 0 | if (inj->unsupported_request) { |
590 | 0 | inj->devsta |= PCI_EXP_DEVSTA_URD; |
591 | 0 | } |
592 | 0 | pci_set_word(dev->config + dev->exp.exp_cap + PCI_EXP_DEVSTA, inj->devsta); |
593 | |
|
594 | 0 | if (inj->aer_cap) { |
595 | 0 | uint32_t mask = pci_get_long(inj->aer_cap + PCI_ERR_UNCOR_MASK); |
596 | 0 | if (mask & inj->error_status) { |
597 | 0 | pci_long_test_and_set_mask(inj->aer_cap + PCI_ERR_UNCOR_STATUS, |
598 | 0 | inj->error_status); |
599 | 0 | return false; |
600 | 0 | } |
601 | | |
602 | 0 | inj->log_overflow = !!pcie_aer_record_error(dev, inj->err); |
603 | 0 | pci_long_test_and_set_mask(inj->aer_cap + PCI_ERR_UNCOR_STATUS, |
604 | 0 | inj->error_status); |
605 | 0 | } |
606 | | |
607 | 0 | cmd = pci_get_word(dev->config + PCI_COMMAND); |
608 | 0 | if (inj->unsupported_request && |
609 | 0 | !(inj->devctl & PCI_EXP_DEVCTL_URRE) && !(cmd & PCI_COMMAND_SERR)) { |
610 | 0 | return false; |
611 | 0 | } |
612 | 0 | if (is_fatal) { |
613 | 0 | if (!((cmd & PCI_COMMAND_SERR) || |
614 | 0 | (inj->devctl & PCI_EXP_DEVCTL_FERE))) { |
615 | 0 | return false; |
616 | 0 | } |
617 | 0 | inj->msg.severity = PCI_ERR_ROOT_CMD_FATAL_EN; |
618 | 0 | } else { |
619 | 0 | if (!((cmd & PCI_COMMAND_SERR) || |
620 | 0 | (inj->devctl & PCI_EXP_DEVCTL_NFERE))) { |
621 | 0 | return false; |
622 | 0 | } |
623 | 0 | inj->msg.severity = PCI_ERR_ROOT_CMD_NONFATAL_EN; |
624 | 0 | } |
625 | 0 | return true; |
626 | 0 | } |
627 | | |
628 | | /* |
629 | | * non-Function specific error must be recorded in all functions. |
630 | | * It is the responsibility of the caller of this function. |
631 | | * It is also caller's responsibility to determine which function should |
632 | | * report the error. |
633 | | * |
634 | | * 6.2.4 Error Logging |
635 | | * 6.2.5 Sequence of Device Error Signaling and Logging Operations |
636 | | * Figure 6-2: Flowchart Showing Sequence of Device Error Signaling and Logging |
637 | | * Operations |
638 | | */ |
639 | | int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) |
640 | 0 | { |
641 | 0 | uint8_t *aer_cap = NULL; |
642 | 0 | uint16_t devctl = 0; |
643 | 0 | uint16_t devsta = 0; |
644 | 0 | uint32_t error_status = err->status; |
645 | 0 | PCIEAERInject inj; |
646 | |
|
647 | 0 | if (!pci_is_express(dev)) { |
648 | 0 | return -ENOSYS; |
649 | 0 | } |
650 | | |
651 | 0 | if (err->flags & PCIE_AER_ERR_IS_CORRECTABLE) { |
652 | 0 | error_status &= PCI_ERR_COR_SUPPORTED; |
653 | 0 | } else { |
654 | 0 | error_status &= PCI_ERR_UNC_SUPPORTED; |
655 | 0 | } |
656 | | |
657 | | /* invalid status bit. one and only one bit must be set */ |
658 | 0 | if (!error_status || (error_status & (error_status - 1))) { |
659 | 0 | return -EINVAL; |
660 | 0 | } |
661 | | |
662 | 0 | if (dev->exp.aer_cap) { |
663 | 0 | uint8_t *exp_cap = dev->config + dev->exp.exp_cap; |
664 | 0 | aer_cap = dev->config + dev->exp.aer_cap; |
665 | 0 | devctl = pci_get_long(exp_cap + PCI_EXP_DEVCTL); |
666 | 0 | devsta = pci_get_long(exp_cap + PCI_EXP_DEVSTA); |
667 | 0 | } |
668 | |
|
669 | 0 | inj.dev = dev; |
670 | 0 | inj.aer_cap = aer_cap; |
671 | 0 | inj.err = err; |
672 | 0 | inj.devctl = devctl; |
673 | 0 | inj.devsta = devsta; |
674 | 0 | inj.error_status = error_status; |
675 | 0 | inj.unsupported_request = !(err->flags & PCIE_AER_ERR_IS_CORRECTABLE) && |
676 | 0 | err->status == PCI_ERR_UNC_UNSUP; |
677 | 0 | inj.log_overflow = false; |
678 | |
|
679 | 0 | if (err->flags & PCIE_AER_ERR_IS_CORRECTABLE) { |
680 | 0 | if (!pcie_aer_inject_cor_error(&inj, 0, false)) { |
681 | 0 | return 0; |
682 | 0 | } |
683 | 0 | } else { |
684 | 0 | bool is_fatal = |
685 | 0 | pcie_aer_uncor_default_severity(error_status) == |
686 | 0 | PCI_ERR_ROOT_CMD_FATAL_EN; |
687 | 0 | if (aer_cap) { |
688 | 0 | is_fatal = |
689 | 0 | error_status & pci_get_long(aer_cap + PCI_ERR_UNCOR_SEVER); |
690 | 0 | } |
691 | 0 | if (!is_fatal && (err->flags & PCIE_AER_ERR_MAYBE_ADVISORY)) { |
692 | 0 | inj.error_status = PCI_ERR_COR_ADV_NONFATAL; |
693 | 0 | if (!pcie_aer_inject_cor_error(&inj, error_status, true)) { |
694 | 0 | return 0; |
695 | 0 | } |
696 | 0 | } else { |
697 | 0 | if (!pcie_aer_inject_uncor_error(&inj, is_fatal)) { |
698 | 0 | return 0; |
699 | 0 | } |
700 | 0 | } |
701 | 0 | } |
702 | | |
703 | | /* send up error message */ |
704 | 0 | inj.msg.source_id = err->source_id; |
705 | 0 | pcie_aer_msg(dev, &inj.msg); |
706 | |
|
707 | 0 | if (inj.log_overflow) { |
708 | 0 | PCIEAERErr header_log_overflow = { |
709 | 0 | .status = PCI_ERR_COR_HL_OVERFLOW, |
710 | 0 | .flags = PCIE_AER_ERR_IS_CORRECTABLE, |
711 | 0 | }; |
712 | 0 | int ret = pcie_aer_inject_error(dev, &header_log_overflow); |
713 | 0 | assert(!ret); |
714 | 0 | } |
715 | 0 | return 0; |
716 | 0 | } |
717 | | |
718 | | void pcie_aer_write_config(PCIDevice *dev, |
719 | | uint32_t addr, uint32_t val, int len) |
720 | 0 | { |
721 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
722 | 0 | uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP); |
723 | 0 | uint32_t first_error = 1U << PCI_ERR_CAP_FEP(errcap); |
724 | 0 | uint32_t uncorsta = pci_get_long(aer_cap + PCI_ERR_UNCOR_STATUS); |
725 | | |
726 | | /* uncorrectable error */ |
727 | 0 | if (!(uncorsta & first_error)) { |
728 | | /* the bit that corresponds to the first error is cleared */ |
729 | 0 | pcie_aer_clear_error(dev); |
730 | 0 | } else if (errcap & PCI_ERR_CAP_MHRE) { |
731 | | /* When PCI_ERR_CAP_MHRE is enabled and the first error isn't cleared |
732 | | * nothing should happen. So we have to revert the modification to |
733 | | * the register. |
734 | | */ |
735 | 0 | pcie_aer_update_uncor_status(dev); |
736 | 0 | } else { |
737 | | /* capability & control |
738 | | * PCI_ERR_CAP_MHRE might be cleared, so clear of header log. |
739 | | */ |
740 | 0 | aer_log_clear_all_err(&dev->exp.aer_log); |
741 | 0 | } |
742 | 0 | } |
743 | | |
744 | | void pcie_aer_root_init(PCIDevice *dev) |
745 | 0 | { |
746 | 0 | uint16_t pos = dev->exp.aer_cap; |
747 | |
|
748 | 0 | pci_set_long(dev->wmask + pos + PCI_ERR_ROOT_COMMAND, |
749 | 0 | PCI_ERR_ROOT_CMD_EN_MASK); |
750 | 0 | pci_set_long(dev->w1cmask + pos + PCI_ERR_ROOT_STATUS, |
751 | 0 | PCI_ERR_ROOT_STATUS_REPORT_MASK); |
752 | | /* PCI_ERR_ROOT_IRQ is RO but devices change it using a |
753 | | * device-specific method. |
754 | | */ |
755 | 0 | pci_set_long(dev->cmask + pos + PCI_ERR_ROOT_STATUS, |
756 | 0 | ~PCI_ERR_ROOT_IRQ); |
757 | 0 | } |
758 | | |
759 | | void pcie_aer_root_reset(PCIDevice *dev) |
760 | 0 | { |
761 | 0 | uint8_t* aer_cap = dev->config + dev->exp.aer_cap; |
762 | |
|
763 | 0 | pci_set_long(aer_cap + PCI_ERR_ROOT_COMMAND, 0); |
764 | | |
765 | | /* |
766 | | * Advanced Error Interrupt Message Number in Root Error Status Register |
767 | | * must be updated by chip dependent code because it's chip dependent |
768 | | * which number is used. |
769 | | */ |
770 | 0 | } |
771 | | |
772 | | void pcie_aer_root_write_config(PCIDevice *dev, |
773 | | uint32_t addr, uint32_t val, int len, |
774 | | uint32_t root_cmd_prev) |
775 | 0 | { |
776 | 0 | uint8_t *aer_cap = dev->config + dev->exp.aer_cap; |
777 | 0 | uint32_t root_status = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS); |
778 | 0 | uint32_t enabled_cmd = pcie_aer_status_to_cmd(root_status); |
779 | 0 | uint32_t root_cmd = pci_get_long(aer_cap + PCI_ERR_ROOT_COMMAND); |
780 | | /* 6.2.4.1.2 Interrupt Generation */ |
781 | 0 | if (!msix_enabled(dev) && !msi_enabled(dev)) { |
782 | 0 | if (pci_intx(dev) != -1) { |
783 | 0 | pci_set_irq(dev, !!(root_cmd & enabled_cmd)); |
784 | 0 | } |
785 | 0 | return; |
786 | 0 | } |
787 | | |
788 | 0 | if ((root_cmd_prev & enabled_cmd) || !(root_cmd & enabled_cmd)) { |
789 | | /* Send MSI on transition from false to true. */ |
790 | 0 | return; |
791 | 0 | } |
792 | | |
793 | 0 | pcie_aer_root_notify(dev); |
794 | 0 | } |
795 | | |
796 | | static const VMStateDescription vmstate_pcie_aer_err = { |
797 | | .name = "PCIE_AER_ERROR", |
798 | | .version_id = 1, |
799 | | .minimum_version_id = 1, |
800 | | .fields = (const VMStateField[]) { |
801 | | VMSTATE_UINT32(status, PCIEAERErr), |
802 | | VMSTATE_UINT16(source_id, PCIEAERErr), |
803 | | VMSTATE_UINT16(flags, PCIEAERErr), |
804 | | VMSTATE_UINT32_ARRAY(header, PCIEAERErr, 4), |
805 | | VMSTATE_UINT32_ARRAY(prefix, PCIEAERErr, 4), |
806 | | VMSTATE_END_OF_LIST() |
807 | | } |
808 | | }; |
809 | | |
810 | | static bool pcie_aer_state_log_num_valid(void *opaque, int version_id) |
811 | 0 | { |
812 | 0 | PCIEAERLog *s = opaque; |
813 | |
|
814 | 0 | return s->log_num <= s->log_max; |
815 | 0 | } |
816 | | |
817 | | const VMStateDescription vmstate_pcie_aer_log = { |
818 | | .name = "PCIE_AER_ERROR_LOG", |
819 | | .version_id = 1, |
820 | | .minimum_version_id = 1, |
821 | | .fields = (const VMStateField[]) { |
822 | | VMSTATE_UINT16(log_num, PCIEAERLog), |
823 | | VMSTATE_UINT16_EQUAL(log_max, PCIEAERLog), |
824 | | VMSTATE_VALIDATE("log_num <= log_max", pcie_aer_state_log_num_valid), |
825 | | VMSTATE_STRUCT_VARRAY_POINTER_UINT16(log, PCIEAERLog, log_num, |
826 | | vmstate_pcie_aer_err, PCIEAERErr), |
827 | | VMSTATE_END_OF_LIST() |
828 | | } |
829 | | }; |
830 | | |
831 | | typedef struct PCIEAERErrorName { |
832 | | const char *name; |
833 | | uint32_t val; |
834 | | bool correctable; |
835 | | } PCIEAERErrorName; |
836 | | |
837 | | /* |
838 | | * AER error name -> value conversion table |
839 | | * This naming scheme is same to linux aer-injection tool. |
840 | | */ |
841 | | static const struct PCIEAERErrorName pcie_aer_error_list[] = { |
842 | | { |
843 | | .name = "DLP", |
844 | | .val = PCI_ERR_UNC_DLP, |
845 | | .correctable = false, |
846 | | }, { |
847 | | .name = "SDN", |
848 | | .val = PCI_ERR_UNC_SDN, |
849 | | .correctable = false, |
850 | | }, { |
851 | | .name = "POISON_TLP", |
852 | | .val = PCI_ERR_UNC_POISON_TLP, |
853 | | .correctable = false, |
854 | | }, { |
855 | | .name = "FCP", |
856 | | .val = PCI_ERR_UNC_FCP, |
857 | | .correctable = false, |
858 | | }, { |
859 | | .name = "COMP_TIME", |
860 | | .val = PCI_ERR_UNC_COMP_TIME, |
861 | | .correctable = false, |
862 | | }, { |
863 | | .name = "COMP_ABORT", |
864 | | .val = PCI_ERR_UNC_COMP_ABORT, |
865 | | .correctable = false, |
866 | | }, { |
867 | | .name = "UNX_COMP", |
868 | | .val = PCI_ERR_UNC_UNX_COMP, |
869 | | .correctable = false, |
870 | | }, { |
871 | | .name = "RX_OVER", |
872 | | .val = PCI_ERR_UNC_RX_OVER, |
873 | | .correctable = false, |
874 | | }, { |
875 | | .name = "MALF_TLP", |
876 | | .val = PCI_ERR_UNC_MALF_TLP, |
877 | | .correctable = false, |
878 | | }, { |
879 | | .name = "ECRC", |
880 | | .val = PCI_ERR_UNC_ECRC, |
881 | | .correctable = false, |
882 | | }, { |
883 | | .name = "UNSUP", |
884 | | .val = PCI_ERR_UNC_UNSUP, |
885 | | .correctable = false, |
886 | | }, { |
887 | | .name = "ACSV", |
888 | | .val = PCI_ERR_UNC_ACSV, |
889 | | .correctable = false, |
890 | | }, { |
891 | | .name = "INTN", |
892 | | .val = PCI_ERR_UNC_INTN, |
893 | | .correctable = false, |
894 | | }, { |
895 | | .name = "MCBTLP", |
896 | | .val = PCI_ERR_UNC_MCBTLP, |
897 | | .correctable = false, |
898 | | }, { |
899 | | .name = "ATOP_EBLOCKED", |
900 | | .val = PCI_ERR_UNC_ATOP_EBLOCKED, |
901 | | .correctable = false, |
902 | | }, { |
903 | | .name = "TLP_PRF_BLOCKED", |
904 | | .val = PCI_ERR_UNC_TLP_PRF_BLOCKED, |
905 | | .correctable = false, |
906 | | }, { |
907 | | .name = "RCVR", |
908 | | .val = PCI_ERR_COR_RCVR, |
909 | | .correctable = true, |
910 | | }, { |
911 | | .name = "BAD_TLP", |
912 | | .val = PCI_ERR_COR_BAD_TLP, |
913 | | .correctable = true, |
914 | | }, { |
915 | | .name = "BAD_DLLP", |
916 | | .val = PCI_ERR_COR_BAD_DLLP, |
917 | | .correctable = true, |
918 | | }, { |
919 | | .name = "REP_ROLL", |
920 | | .val = PCI_ERR_COR_REP_ROLL, |
921 | | .correctable = true, |
922 | | }, { |
923 | | .name = "REP_TIMER", |
924 | | .val = PCI_ERR_COR_REP_TIMER, |
925 | | .correctable = true, |
926 | | }, { |
927 | | .name = "ADV_NONFATAL", |
928 | | .val = PCI_ERR_COR_ADV_NONFATAL, |
929 | | .correctable = true, |
930 | | }, { |
931 | | .name = "INTERNAL", |
932 | | .val = PCI_ERR_COR_INTERNAL, |
933 | | .correctable = true, |
934 | | }, { |
935 | | .name = "HL_OVERFLOW", |
936 | | .val = PCI_ERR_COR_HL_OVERFLOW, |
937 | | .correctable = true, |
938 | | }, |
939 | | }; |
940 | | |
941 | | int pcie_aer_parse_error_string(const char *error_name, |
942 | | uint32_t *status, bool *correctable) |
943 | 0 | { |
944 | 0 | int i; |
945 | |
|
946 | 0 | for (i = 0; i < ARRAY_SIZE(pcie_aer_error_list); i++) { |
947 | 0 | const PCIEAERErrorName *e = &pcie_aer_error_list[i]; |
948 | 0 | if (strcmp(error_name, e->name)) { |
949 | 0 | continue; |
950 | 0 | } |
951 | | |
952 | 0 | *status = e->val; |
953 | 0 | *correctable = e->correctable; |
954 | 0 | return 0; |
955 | 0 | } |
956 | 0 | return -EINVAL; |
957 | 0 | } |