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