]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/pci/pcie/aer/aerdrv_core.c
Merge commit 'v2.6.29' into timers/core
[mirror_ubuntu-jammy-kernel.git] / drivers / pci / pcie / aer / aerdrv_core.c
1 /*
2 * drivers/pci/pcie/aer/aerdrv_core.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * This file implements the core part of PCI-Express AER. When an pci-express
9 * error is delivered, an error message will be collected and printed to
10 * console, then, an error recovery procedure will be executed by following
11 * the pci error recovery rules.
12 *
13 * Copyright (C) 2006 Intel Corp.
14 * Tom Long Nguyen (tom.l.nguyen@intel.com)
15 * Zhang Yanmin (yanmin.zhang@intel.com)
16 *
17 */
18
19 #include <linux/module.h>
20 #include <linux/pci.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/pm.h>
24 #include <linux/suspend.h>
25 #include <linux/delay.h>
26 #include "aerdrv.h"
27
28 static int forceload;
29 module_param(forceload, bool, 0);
30
31 int pci_enable_pcie_error_reporting(struct pci_dev *dev)
32 {
33 u16 reg16 = 0;
34 int pos;
35
36 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
37 if (!pos)
38 return -EIO;
39
40 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
41 if (!pos)
42 return -EIO;
43
44 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
45 reg16 = reg16 |
46 PCI_EXP_DEVCTL_CERE |
47 PCI_EXP_DEVCTL_NFERE |
48 PCI_EXP_DEVCTL_FERE |
49 PCI_EXP_DEVCTL_URRE;
50 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
51 reg16);
52 return 0;
53 }
54
55 int pci_disable_pcie_error_reporting(struct pci_dev *dev)
56 {
57 u16 reg16 = 0;
58 int pos;
59
60 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
61 if (!pos)
62 return -EIO;
63
64 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
65 reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |
66 PCI_EXP_DEVCTL_NFERE |
67 PCI_EXP_DEVCTL_FERE |
68 PCI_EXP_DEVCTL_URRE);
69 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
70 reg16);
71 return 0;
72 }
73
74 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
75 {
76 int pos;
77 u32 status, mask;
78
79 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
80 if (!pos)
81 return -EIO;
82
83 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
84 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
85 if (dev->error_state == pci_channel_io_normal)
86 status &= ~mask; /* Clear corresponding nonfatal bits */
87 else
88 status &= mask; /* Clear corresponding fatal bits */
89 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
90
91 return 0;
92 }
93
94 #if 0
95 int pci_cleanup_aer_correct_error_status(struct pci_dev *dev)
96 {
97 int pos;
98 u32 status;
99
100 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
101 if (!pos)
102 return -EIO;
103
104 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
105 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status);
106
107 return 0;
108 }
109 #endif /* 0 */
110
111
112 static void set_device_error_reporting(struct pci_dev *dev, void *data)
113 {
114 bool enable = *((bool *)data);
115
116 if (dev->pcie_type != PCIE_RC_PORT &&
117 dev->pcie_type != PCIE_SW_UPSTREAM_PORT &&
118 dev->pcie_type != PCIE_SW_DOWNSTREAM_PORT)
119 return;
120
121 if (enable)
122 pci_enable_pcie_error_reporting(dev);
123 else
124 pci_disable_pcie_error_reporting(dev);
125 }
126
127 /**
128 * set_downstream_devices_error_reporting - enable/disable the error reporting bits on the root port and its downstream ports.
129 * @dev: pointer to root port's pci_dev data structure
130 * @enable: true = enable error reporting, false = disable error reporting.
131 */
132 static void set_downstream_devices_error_reporting(struct pci_dev *dev,
133 bool enable)
134 {
135 set_device_error_reporting(dev, &enable);
136
137 if (!dev->subordinate)
138 return;
139 pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
140 }
141
142 static int find_device_iter(struct device *device, void *data)
143 {
144 struct pci_dev *dev;
145 u16 id = *(unsigned long *)data;
146 u8 secondary, subordinate, d_bus = id >> 8;
147
148 if (device->bus == &pci_bus_type) {
149 dev = to_pci_dev(device);
150 if (id == ((dev->bus->number << 8) | dev->devfn)) {
151 /*
152 * Device ID match
153 */
154 *(unsigned long*)data = (unsigned long)device;
155 return 1;
156 }
157
158 /*
159 * If device is P2P, check if it is an upstream?
160 */
161 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
162 pci_read_config_byte(dev, PCI_SECONDARY_BUS,
163 &secondary);
164 pci_read_config_byte(dev, PCI_SUBORDINATE_BUS,
165 &subordinate);
166 if (d_bus >= secondary && d_bus <= subordinate) {
167 *(unsigned long*)data = (unsigned long)device;
168 return 1;
169 }
170 }
171 }
172
173 return 0;
174 }
175
176 /**
177 * find_source_device - search through device hierarchy for source device
178 * @parent: pointer to Root Port pci_dev data structure
179 * @id: device ID of agent who sends an error message to this Root Port
180 *
181 * Invoked when error is detected at the Root Port.
182 */
183 static struct device* find_source_device(struct pci_dev *parent, u16 id)
184 {
185 struct pci_dev *dev = parent;
186 struct device *device;
187 unsigned long device_addr;
188 int status;
189
190 /* Is Root Port an agent that sends error message? */
191 if (id == ((dev->bus->number << 8) | dev->devfn))
192 return &dev->dev;
193
194 do {
195 device_addr = id;
196 if ((status = device_for_each_child(&dev->dev,
197 &device_addr, find_device_iter))) {
198 device = (struct device*)device_addr;
199 dev = to_pci_dev(device);
200 if (id == ((dev->bus->number << 8) | dev->devfn))
201 return device;
202 }
203 }while (status);
204
205 return NULL;
206 }
207
208 static void report_error_detected(struct pci_dev *dev, void *data)
209 {
210 pci_ers_result_t vote;
211 struct pci_error_handlers *err_handler;
212 struct aer_broadcast_data *result_data;
213 result_data = (struct aer_broadcast_data *) data;
214
215 dev->error_state = result_data->state;
216
217 if (!dev->driver ||
218 !dev->driver->err_handler ||
219 !dev->driver->err_handler->error_detected) {
220 if (result_data->state == pci_channel_io_frozen &&
221 !(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) {
222 /*
223 * In case of fatal recovery, if one of down-
224 * stream device has no driver. We might be
225 * unable to recover because a later insmod
226 * of a driver for this device is unaware of
227 * its hw state.
228 */
229 dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n",
230 dev->driver ?
231 "no AER-aware driver" : "no driver");
232 }
233 return;
234 }
235
236 err_handler = dev->driver->err_handler;
237 vote = err_handler->error_detected(dev, result_data->state);
238 result_data->result = merge_result(result_data->result, vote);
239 return;
240 }
241
242 static void report_mmio_enabled(struct pci_dev *dev, void *data)
243 {
244 pci_ers_result_t vote;
245 struct pci_error_handlers *err_handler;
246 struct aer_broadcast_data *result_data;
247 result_data = (struct aer_broadcast_data *) data;
248
249 if (!dev->driver ||
250 !dev->driver->err_handler ||
251 !dev->driver->err_handler->mmio_enabled)
252 return;
253
254 err_handler = dev->driver->err_handler;
255 vote = err_handler->mmio_enabled(dev);
256 result_data->result = merge_result(result_data->result, vote);
257 return;
258 }
259
260 static void report_slot_reset(struct pci_dev *dev, void *data)
261 {
262 pci_ers_result_t vote;
263 struct pci_error_handlers *err_handler;
264 struct aer_broadcast_data *result_data;
265 result_data = (struct aer_broadcast_data *) data;
266
267 if (!dev->driver ||
268 !dev->driver->err_handler ||
269 !dev->driver->err_handler->slot_reset)
270 return;
271
272 err_handler = dev->driver->err_handler;
273 vote = err_handler->slot_reset(dev);
274 result_data->result = merge_result(result_data->result, vote);
275 return;
276 }
277
278 static void report_resume(struct pci_dev *dev, void *data)
279 {
280 struct pci_error_handlers *err_handler;
281
282 dev->error_state = pci_channel_io_normal;
283
284 if (!dev->driver ||
285 !dev->driver->err_handler ||
286 !dev->driver->err_handler->resume)
287 return;
288
289 err_handler = dev->driver->err_handler;
290 err_handler->resume(dev);
291 return;
292 }
293
294 /**
295 * broadcast_error_message - handle message broadcast to downstream drivers
296 * @dev: pointer to from where in a hierarchy message is broadcasted down
297 * @state: error state
298 * @error_mesg: message to print
299 * @cb: callback to be broadcasted
300 *
301 * Invoked during error recovery process. Once being invoked, the content
302 * of error severity will be broadcasted to all downstream drivers in a
303 * hierarchy in question.
304 */
305 static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
306 enum pci_channel_state state,
307 char *error_mesg,
308 void (*cb)(struct pci_dev *, void *))
309 {
310 struct aer_broadcast_data result_data;
311
312 dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg);
313 result_data.state = state;
314 if (cb == report_error_detected)
315 result_data.result = PCI_ERS_RESULT_CAN_RECOVER;
316 else
317 result_data.result = PCI_ERS_RESULT_RECOVERED;
318
319 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
320 /*
321 * If the error is reported by a bridge, we think this error
322 * is related to the downstream link of the bridge, so we
323 * do error recovery on all subordinates of the bridge instead
324 * of the bridge and clear the error status of the bridge.
325 */
326 if (cb == report_error_detected)
327 dev->error_state = state;
328 pci_walk_bus(dev->subordinate, cb, &result_data);
329 if (cb == report_resume) {
330 pci_cleanup_aer_uncorrect_error_status(dev);
331 dev->error_state = pci_channel_io_normal;
332 }
333 }
334 else {
335 /*
336 * If the error is reported by an end point, we think this
337 * error is related to the upstream link of the end point.
338 */
339 pci_walk_bus(dev->bus, cb, &result_data);
340 }
341
342 return result_data.result;
343 }
344
345 struct find_aer_service_data {
346 struct pcie_port_service_driver *aer_driver;
347 int is_downstream;
348 };
349
350 static int find_aer_service_iter(struct device *device, void *data)
351 {
352 struct device_driver *driver;
353 struct pcie_port_service_driver *service_driver;
354 struct pcie_device *pcie_dev;
355 struct find_aer_service_data *result;
356
357 result = (struct find_aer_service_data *) data;
358
359 if (device->bus == &pcie_port_bus_type) {
360 pcie_dev = to_pcie_device(device);
361 if (pcie_dev->id.port_type == PCIE_SW_DOWNSTREAM_PORT)
362 result->is_downstream = 1;
363
364 driver = device->driver;
365 if (driver) {
366 service_driver = to_service_driver(driver);
367 if (service_driver->id_table->service_type ==
368 PCIE_PORT_SERVICE_AER) {
369 result->aer_driver = service_driver;
370 return 1;
371 }
372 }
373 }
374
375 return 0;
376 }
377
378 static void find_aer_service(struct pci_dev *dev,
379 struct find_aer_service_data *data)
380 {
381 int retval;
382 retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);
383 }
384
385 static pci_ers_result_t reset_link(struct pcie_device *aerdev,
386 struct pci_dev *dev)
387 {
388 struct pci_dev *udev;
389 pci_ers_result_t status;
390 struct find_aer_service_data data;
391
392 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)
393 udev = dev;
394 else
395 udev= dev->bus->self;
396
397 data.is_downstream = 0;
398 data.aer_driver = NULL;
399 find_aer_service(udev, &data);
400
401 /*
402 * Use the aer driver of the error agent firstly.
403 * If it hasn't the aer driver, use the root port's
404 */
405 if (!data.aer_driver || !data.aer_driver->reset_link) {
406 if (data.is_downstream &&
407 aerdev->device.driver &&
408 to_service_driver(aerdev->device.driver)->reset_link) {
409 data.aer_driver =
410 to_service_driver(aerdev->device.driver);
411 } else {
412 dev_printk(KERN_DEBUG, &dev->dev, "no link-reset "
413 "support\n");
414 return PCI_ERS_RESULT_DISCONNECT;
415 }
416 }
417
418 status = data.aer_driver->reset_link(udev);
419 if (status != PCI_ERS_RESULT_RECOVERED) {
420 dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream "
421 "device %s failed\n", pci_name(udev));
422 return PCI_ERS_RESULT_DISCONNECT;
423 }
424
425 return status;
426 }
427
428 /**
429 * do_recovery - handle nonfatal/fatal error recovery process
430 * @aerdev: pointer to a pcie_device data structure of root port
431 * @dev: pointer to a pci_dev data structure of agent detecting an error
432 * @severity: error severity type
433 *
434 * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
435 * error detected message to all downstream drivers within a hierarchy in
436 * question and return the returned code.
437 */
438 static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
439 struct pci_dev *dev,
440 int severity)
441 {
442 pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
443 enum pci_channel_state state;
444
445 if (severity == AER_FATAL)
446 state = pci_channel_io_frozen;
447 else
448 state = pci_channel_io_normal;
449
450 status = broadcast_error_message(dev,
451 state,
452 "error_detected",
453 report_error_detected);
454
455 if (severity == AER_FATAL) {
456 result = reset_link(aerdev, dev);
457 if (result != PCI_ERS_RESULT_RECOVERED) {
458 /* TODO: Should panic here? */
459 return result;
460 }
461 }
462
463 if (status == PCI_ERS_RESULT_CAN_RECOVER)
464 status = broadcast_error_message(dev,
465 state,
466 "mmio_enabled",
467 report_mmio_enabled);
468
469 if (status == PCI_ERS_RESULT_NEED_RESET) {
470 /*
471 * TODO: Should call platform-specific
472 * functions to reset slot before calling
473 * drivers' slot_reset callbacks?
474 */
475 status = broadcast_error_message(dev,
476 state,
477 "slot_reset",
478 report_slot_reset);
479 }
480
481 if (status == PCI_ERS_RESULT_RECOVERED)
482 broadcast_error_message(dev,
483 state,
484 "resume",
485 report_resume);
486
487 return status;
488 }
489
490 /**
491 * handle_error_source - handle logging error into an event log
492 * @aerdev: pointer to pcie_device data structure of the root port
493 * @dev: pointer to pci_dev data structure of error source device
494 * @info: comprehensive error information
495 *
496 * Invoked when an error being detected by Root Port.
497 */
498 static void handle_error_source(struct pcie_device * aerdev,
499 struct pci_dev *dev,
500 struct aer_err_info info)
501 {
502 pci_ers_result_t status = 0;
503 int pos;
504
505 if (info.severity == AER_CORRECTABLE) {
506 /*
507 * Correctable error does not need software intevention.
508 * No need to go through error recovery process.
509 */
510 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
511 if (pos)
512 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
513 info.status);
514 } else {
515 status = do_recovery(aerdev, dev, info.severity);
516 if (status == PCI_ERS_RESULT_RECOVERED) {
517 dev_printk(KERN_DEBUG, &dev->dev, "AER driver "
518 "successfully recovered\n");
519 } else {
520 /* TODO: Should kernel panic here? */
521 dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't "
522 "recover\n");
523 }
524 }
525 }
526
527 /**
528 * aer_enable_rootport - enable Root Port's interrupts when receiving messages
529 * @rpc: pointer to a Root Port data structure
530 *
531 * Invoked when PCIE bus loads AER service driver.
532 */
533 void aer_enable_rootport(struct aer_rpc *rpc)
534 {
535 struct pci_dev *pdev = rpc->rpd->port;
536 int pos, aer_pos;
537 u16 reg16;
538 u32 reg32;
539
540 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
541 /* Clear PCIE Capability's Device Status */
542 pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16);
543 pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16);
544
545 /* Disable system error generation in response to error messages */
546 pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16);
547 reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK);
548 pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
549
550 aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
551 /* Clear error status */
552 pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, &reg32);
553 pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
554 pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32);
555 pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
556 pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32);
557 pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
558
559 /*
560 * Enable error reporting for the root port device and downstream port
561 * devices.
562 */
563 set_downstream_devices_error_reporting(pdev, true);
564
565 /* Enable Root Port's interrupt in response to error messages */
566 pci_write_config_dword(pdev,
567 aer_pos + PCI_ERR_ROOT_COMMAND,
568 ROOT_PORT_INTR_ON_MESG_MASK);
569 }
570
571 /**
572 * disable_root_aer - disable Root Port's interrupts when receiving messages
573 * @rpc: pointer to a Root Port data structure
574 *
575 * Invoked when PCIE bus unloads AER service driver.
576 */
577 static void disable_root_aer(struct aer_rpc *rpc)
578 {
579 struct pci_dev *pdev = rpc->rpd->port;
580 u32 reg32;
581 int pos;
582
583 /*
584 * Disable error reporting for the root port device and downstream port
585 * devices.
586 */
587 set_downstream_devices_error_reporting(pdev, false);
588
589 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
590 /* Disable Root's interrupt in response to error messages */
591 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0);
592
593 /* Clear Root's error status reg */
594 pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, &reg32);
595 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
596 }
597
598 /**
599 * get_e_source - retrieve an error source
600 * @rpc: pointer to the root port which holds an error
601 *
602 * Invoked by DPC handler to consume an error.
603 */
604 static struct aer_err_source* get_e_source(struct aer_rpc *rpc)
605 {
606 struct aer_err_source *e_source;
607 unsigned long flags;
608
609 /* Lock access to Root error producer/consumer index */
610 spin_lock_irqsave(&rpc->e_lock, flags);
611 if (rpc->prod_idx == rpc->cons_idx) {
612 spin_unlock_irqrestore(&rpc->e_lock, flags);
613 return NULL;
614 }
615 e_source = &rpc->e_sources[rpc->cons_idx];
616 rpc->cons_idx++;
617 if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
618 rpc->cons_idx = 0;
619 spin_unlock_irqrestore(&rpc->e_lock, flags);
620
621 return e_source;
622 }
623
624 static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
625 {
626 int pos;
627
628 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
629
630 /* The device might not support AER */
631 if (!pos)
632 return AER_SUCCESS;
633
634 if (info->severity == AER_CORRECTABLE) {
635 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS,
636 &info->status);
637 if (!(info->status & ERR_CORRECTABLE_ERROR_MASK))
638 return AER_UNSUCCESS;
639 } else if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE ||
640 info->severity == AER_NONFATAL) {
641
642 /* Link is still healthy for IO reads */
643 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
644 &info->status);
645 if (!(info->status & ERR_UNCORRECTABLE_ERROR_MASK))
646 return AER_UNSUCCESS;
647
648 if (info->status & AER_LOG_TLP_MASKS) {
649 info->flags |= AER_TLP_HEADER_VALID_FLAG;
650 pci_read_config_dword(dev,
651 pos + PCI_ERR_HEADER_LOG, &info->tlp.dw0);
652 pci_read_config_dword(dev,
653 pos + PCI_ERR_HEADER_LOG + 4, &info->tlp.dw1);
654 pci_read_config_dword(dev,
655 pos + PCI_ERR_HEADER_LOG + 8, &info->tlp.dw2);
656 pci_read_config_dword(dev,
657 pos + PCI_ERR_HEADER_LOG + 12, &info->tlp.dw3);
658 }
659 }
660
661 return AER_SUCCESS;
662 }
663
664 /**
665 * aer_isr_one_error - consume an error detected by root port
666 * @p_device: pointer to error root port service device
667 * @e_src: pointer to an error source
668 */
669 static void aer_isr_one_error(struct pcie_device *p_device,
670 struct aer_err_source *e_src)
671 {
672 struct device *s_device;
673 struct aer_err_info e_info = {0, 0, 0,};
674 int i;
675 u16 id;
676
677 /*
678 * There is a possibility that both correctable error and
679 * uncorrectable error being logged. Report correctable error first.
680 */
681 for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) {
682 if (i > 4)
683 break;
684 if (!(e_src->status & i))
685 continue;
686
687 /* Init comprehensive error information */
688 if (i & PCI_ERR_ROOT_COR_RCV) {
689 id = ERR_COR_ID(e_src->id);
690 e_info.severity = AER_CORRECTABLE;
691 } else {
692 id = ERR_UNCOR_ID(e_src->id);
693 e_info.severity = ((e_src->status >> 6) & 1);
694 }
695 if (e_src->status &
696 (PCI_ERR_ROOT_MULTI_COR_RCV |
697 PCI_ERR_ROOT_MULTI_UNCOR_RCV))
698 e_info.flags |= AER_MULTI_ERROR_VALID_FLAG;
699 if (!(s_device = find_source_device(p_device->port, id))) {
700 printk(KERN_DEBUG "%s->can't find device of ID%04x\n",
701 __func__, id);
702 continue;
703 }
704 if (get_device_error_info(to_pci_dev(s_device), &e_info) ==
705 AER_SUCCESS) {
706 aer_print_error(to_pci_dev(s_device), &e_info);
707 handle_error_source(p_device,
708 to_pci_dev(s_device),
709 e_info);
710 }
711 }
712 }
713
714 /**
715 * aer_isr - consume errors detected by root port
716 * @work: definition of this work item
717 *
718 * Invoked, as DPC, when root port records new detected error
719 */
720 void aer_isr(struct work_struct *work)
721 {
722 struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler);
723 struct pcie_device *p_device = rpc->rpd;
724 struct aer_err_source *e_src;
725
726 mutex_lock(&rpc->rpc_mutex);
727 e_src = get_e_source(rpc);
728 while (e_src) {
729 aer_isr_one_error(p_device, e_src);
730 e_src = get_e_source(rpc);
731 }
732 mutex_unlock(&rpc->rpc_mutex);
733
734 wake_up(&rpc->wait_release);
735 }
736
737 /**
738 * aer_delete_rootport - disable root port aer and delete service data
739 * @rpc: pointer to a root port device being deleted
740 *
741 * Invoked when AER service unloaded on a specific Root Port
742 */
743 void aer_delete_rootport(struct aer_rpc *rpc)
744 {
745 /* Disable root port AER itself */
746 disable_root_aer(rpc);
747
748 kfree(rpc);
749 }
750
751 /**
752 * aer_init - provide AER initialization
753 * @dev: pointer to AER pcie device
754 *
755 * Invoked when AER service driver is loaded.
756 */
757 int aer_init(struct pcie_device *dev)
758 {
759 if (aer_osc_setup(dev) && !forceload)
760 return -ENXIO;
761
762 return AER_SUCCESS;
763 }
764
765 EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting);
766 EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
767 EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);
768