init from v2.6.32.60
[mach-moxart.git] / drivers / pci / pcie / aer / aerdrv_core.c
blob72fa87c095d8c6752232e070c70dd96f74ed9111
1 /*
2 * drivers/pci/pcie/aer/aerdrv_core.c
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.
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.
13 * Copyright (C) 2006 Intel Corp.
14 * Tom Long Nguyen (tom.l.nguyen@intel.com)
15 * Zhang Yanmin (yanmin.zhang@intel.com)
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"
28 static int forceload;
29 static int nosourceid;
30 module_param(forceload, bool, 0);
31 module_param(nosourceid, bool, 0);
33 int pci_enable_pcie_error_reporting(struct pci_dev *dev)
35 u16 reg16 = 0;
36 int pos;
38 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
39 if (!pos)
40 return -EIO;
42 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
43 if (!pos)
44 return -EIO;
46 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
47 reg16 = reg16 |
48 PCI_EXP_DEVCTL_CERE |
49 PCI_EXP_DEVCTL_NFERE |
50 PCI_EXP_DEVCTL_FERE |
51 PCI_EXP_DEVCTL_URRE;
52 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16);
54 return 0;
56 EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting);
58 int pci_disable_pcie_error_reporting(struct pci_dev *dev)
60 u16 reg16 = 0;
61 int pos;
63 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
64 if (!pos)
65 return -EIO;
67 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
68 reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |
69 PCI_EXP_DEVCTL_NFERE |
70 PCI_EXP_DEVCTL_FERE |
71 PCI_EXP_DEVCTL_URRE);
72 pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16);
74 return 0;
76 EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
78 int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
80 int pos;
81 u32 status;
83 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
84 if (!pos)
85 return -EIO;
87 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
88 if (status)
89 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
91 return 0;
93 EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);
95 #if 0
96 int pci_cleanup_aer_correct_error_status(struct pci_dev *dev)
98 int pos;
99 u32 status;
101 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
102 if (!pos)
103 return -EIO;
105 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
106 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status);
108 return 0;
110 #endif /* 0 */
112 static int set_device_error_reporting(struct pci_dev *dev, void *data)
114 bool enable = *((bool *)data);
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);
125 if (enable)
126 pcie_set_ecrc_checking(dev);
128 return 0;
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.
136 static void set_downstream_devices_error_reporting(struct pci_dev *dev,
137 bool enable)
139 set_device_error_reporting(dev, &enable);
141 if (!dev->subordinate)
142 return;
143 pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
146 static inline int compare_device_id(struct pci_dev *dev,
147 struct aer_err_info *e_info)
149 if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) {
151 * Device ID match
153 return 1;
156 return 0;
159 static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev)
161 if (e_info->error_dev_num < AER_MAX_MULTI_ERR_DEVICES) {
162 e_info->dev[e_info->error_dev_num] = dev;
163 e_info->error_dev_num++;
164 return 1;
167 return 0;
171 #define PCI_BUS(x) (((x) >> 8) & 0xff)
173 static int find_device_iter(struct pci_dev *dev, void *data)
175 int pos;
176 u32 status;
177 u32 mask;
178 u16 reg16;
179 int result;
180 struct aer_err_info *e_info = (struct aer_err_info *)data;
183 * When bus id is equal to 0, it might be a bad id
184 * reported by root port.
186 if (!nosourceid && (PCI_BUS(e_info->id) != 0)) {
187 result = compare_device_id(dev, e_info);
188 if (result)
189 add_error_device(e_info, dev);
192 * If there is no multiple error, we stop
193 * or continue based on the id comparing.
195 if (!e_info->multi_error_valid)
196 return result;
199 * If there are multiple errors and id does match,
200 * We need continue to search other devices under
201 * the root port. Return 0 means that.
203 if (result)
204 return 0;
208 * When either
209 * 1) nosourceid==y;
210 * 2) bus id is equal to 0. Some ports might lose the bus
211 * id of error source id;
212 * 3) There are multiple errors and prior id comparing fails;
213 * We check AER status registers to find the initial reporter.
215 if (atomic_read(&dev->enable_cnt) == 0)
216 return 0;
217 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
218 if (!pos)
219 return 0;
220 /* Check if AER is enabled */
221 pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
222 if (!(reg16 & (
223 PCI_EXP_DEVCTL_CERE |
224 PCI_EXP_DEVCTL_NFERE |
225 PCI_EXP_DEVCTL_FERE |
226 PCI_EXP_DEVCTL_URRE)))
227 return 0;
228 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
229 if (!pos)
230 return 0;
232 status = 0;
233 mask = 0;
234 if (e_info->severity == AER_CORRECTABLE) {
235 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
236 pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &mask);
237 if (status & ~mask) {
238 add_error_device(e_info, dev);
239 goto added;
241 } else {
242 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
243 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
244 if (status & ~mask) {
245 add_error_device(e_info, dev);
246 goto added;
250 return 0;
252 added:
253 if (e_info->multi_error_valid)
254 return 0;
255 else
256 return 1;
260 * find_source_device - search through device hierarchy for source device
261 * @parent: pointer to Root Port pci_dev data structure
262 * @err_info: including detailed error information such like id
264 * Invoked when error is detected at the Root Port.
266 static void find_source_device(struct pci_dev *parent,
267 struct aer_err_info *e_info)
269 struct pci_dev *dev = parent;
270 int result;
272 /* Is Root Port an agent that sends error message? */
273 result = find_device_iter(dev, e_info);
274 if (result)
275 return;
277 pci_walk_bus(parent->subordinate, find_device_iter, e_info);
280 static int report_error_detected(struct pci_dev *dev, void *data)
282 pci_ers_result_t vote;
283 struct pci_error_handlers *err_handler;
284 struct aer_broadcast_data *result_data;
285 result_data = (struct aer_broadcast_data *) data;
287 dev->error_state = result_data->state;
289 if (!dev->driver ||
290 !dev->driver->err_handler ||
291 !dev->driver->err_handler->error_detected) {
292 if (result_data->state == pci_channel_io_frozen &&
293 !(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) {
295 * In case of fatal recovery, if one of down-
296 * stream device has no driver. We might be
297 * unable to recover because a later insmod
298 * of a driver for this device is unaware of
299 * its hw state.
301 dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n",
302 dev->driver ?
303 "no AER-aware driver" : "no driver");
305 return 0;
308 err_handler = dev->driver->err_handler;
309 vote = err_handler->error_detected(dev, result_data->state);
310 result_data->result = merge_result(result_data->result, vote);
311 return 0;
314 static int report_mmio_enabled(struct pci_dev *dev, void *data)
316 pci_ers_result_t vote;
317 struct pci_error_handlers *err_handler;
318 struct aer_broadcast_data *result_data;
319 result_data = (struct aer_broadcast_data *) data;
321 if (!dev->driver ||
322 !dev->driver->err_handler ||
323 !dev->driver->err_handler->mmio_enabled)
324 return 0;
326 err_handler = dev->driver->err_handler;
327 vote = err_handler->mmio_enabled(dev);
328 result_data->result = merge_result(result_data->result, vote);
329 return 0;
332 static int report_slot_reset(struct pci_dev *dev, void *data)
334 pci_ers_result_t vote;
335 struct pci_error_handlers *err_handler;
336 struct aer_broadcast_data *result_data;
337 result_data = (struct aer_broadcast_data *) data;
339 if (!dev->driver ||
340 !dev->driver->err_handler ||
341 !dev->driver->err_handler->slot_reset)
342 return 0;
344 err_handler = dev->driver->err_handler;
345 vote = err_handler->slot_reset(dev);
346 result_data->result = merge_result(result_data->result, vote);
347 return 0;
350 static int report_resume(struct pci_dev *dev, void *data)
352 struct pci_error_handlers *err_handler;
354 dev->error_state = pci_channel_io_normal;
356 if (!dev->driver ||
357 !dev->driver->err_handler ||
358 !dev->driver->err_handler->resume)
359 return 0;
361 err_handler = dev->driver->err_handler;
362 err_handler->resume(dev);
363 return 0;
367 * broadcast_error_message - handle message broadcast to downstream drivers
368 * @dev: pointer to from where in a hierarchy message is broadcasted down
369 * @state: error state
370 * @error_mesg: message to print
371 * @cb: callback to be broadcasted
373 * Invoked during error recovery process. Once being invoked, the content
374 * of error severity will be broadcasted to all downstream drivers in a
375 * hierarchy in question.
377 static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
378 enum pci_channel_state state,
379 char *error_mesg,
380 int (*cb)(struct pci_dev *, void *))
382 struct aer_broadcast_data result_data;
384 dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg);
385 result_data.state = state;
386 if (cb == report_error_detected)
387 result_data.result = PCI_ERS_RESULT_CAN_RECOVER;
388 else
389 result_data.result = PCI_ERS_RESULT_RECOVERED;
391 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
393 * If the error is reported by a bridge, we think this error
394 * is related to the downstream link of the bridge, so we
395 * do error recovery on all subordinates of the bridge instead
396 * of the bridge and clear the error status of the bridge.
398 if (cb == report_error_detected)
399 dev->error_state = state;
400 pci_walk_bus(dev->subordinate, cb, &result_data);
401 if (cb == report_resume) {
402 pci_cleanup_aer_uncorrect_error_status(dev);
403 dev->error_state = pci_channel_io_normal;
405 } else {
407 * If the error is reported by an end point, we think this
408 * error is related to the upstream link of the end point.
410 pci_walk_bus(dev->bus, cb, &result_data);
413 return result_data.result;
416 struct find_aer_service_data {
417 struct pcie_port_service_driver *aer_driver;
418 int is_downstream;
421 static int find_aer_service_iter(struct device *device, void *data)
423 struct device_driver *driver;
424 struct pcie_port_service_driver *service_driver;
425 struct find_aer_service_data *result;
427 result = (struct find_aer_service_data *) data;
429 if (device->bus == &pcie_port_bus_type) {
430 struct pcie_port_data *port_data;
432 port_data = pci_get_drvdata(to_pcie_device(device)->port);
433 if (port_data->port_type == PCIE_SW_DOWNSTREAM_PORT)
434 result->is_downstream = 1;
436 driver = device->driver;
437 if (driver) {
438 service_driver = to_service_driver(driver);
439 if (service_driver->service == PCIE_PORT_SERVICE_AER) {
440 result->aer_driver = service_driver;
441 return 1;
446 return 0;
449 static void find_aer_service(struct pci_dev *dev,
450 struct find_aer_service_data *data)
452 int retval;
453 retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);
456 static pci_ers_result_t reset_link(struct pcie_device *aerdev,
457 struct pci_dev *dev)
459 struct pci_dev *udev;
460 pci_ers_result_t status;
461 struct find_aer_service_data data;
463 if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)
464 udev = dev;
465 else
466 udev = dev->bus->self;
468 data.is_downstream = 0;
469 data.aer_driver = NULL;
470 find_aer_service(udev, &data);
473 * Use the aer driver of the error agent firstly.
474 * If it hasn't the aer driver, use the root port's
476 if (!data.aer_driver || !data.aer_driver->reset_link) {
477 if (data.is_downstream &&
478 aerdev->device.driver &&
479 to_service_driver(aerdev->device.driver)->reset_link) {
480 data.aer_driver =
481 to_service_driver(aerdev->device.driver);
482 } else {
483 dev_printk(KERN_DEBUG, &dev->dev, "no link-reset "
484 "support\n");
485 return PCI_ERS_RESULT_DISCONNECT;
489 status = data.aer_driver->reset_link(udev);
490 if (status != PCI_ERS_RESULT_RECOVERED) {
491 dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream "
492 "device %s failed\n", pci_name(udev));
493 return PCI_ERS_RESULT_DISCONNECT;
496 return status;
500 * do_recovery - handle nonfatal/fatal error recovery process
501 * @aerdev: pointer to a pcie_device data structure of root port
502 * @dev: pointer to a pci_dev data structure of agent detecting an error
503 * @severity: error severity type
505 * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
506 * error detected message to all downstream drivers within a hierarchy in
507 * question and return the returned code.
509 static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
510 struct pci_dev *dev,
511 int severity)
513 pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
514 enum pci_channel_state state;
516 if (severity == AER_FATAL)
517 state = pci_channel_io_frozen;
518 else
519 state = pci_channel_io_normal;
521 status = broadcast_error_message(dev,
522 state,
523 "error_detected",
524 report_error_detected);
526 if (severity == AER_FATAL) {
527 result = reset_link(aerdev, dev);
528 if (result != PCI_ERS_RESULT_RECOVERED) {
529 /* TODO: Should panic here? */
530 return result;
534 if (status == PCI_ERS_RESULT_CAN_RECOVER)
535 status = broadcast_error_message(dev,
536 state,
537 "mmio_enabled",
538 report_mmio_enabled);
540 if (status == PCI_ERS_RESULT_NEED_RESET) {
542 * TODO: Should call platform-specific
543 * functions to reset slot before calling
544 * drivers' slot_reset callbacks?
546 status = broadcast_error_message(dev,
547 state,
548 "slot_reset",
549 report_slot_reset);
552 if (status == PCI_ERS_RESULT_RECOVERED)
553 broadcast_error_message(dev,
554 state,
555 "resume",
556 report_resume);
558 return status;
562 * handle_error_source - handle logging error into an event log
563 * @aerdev: pointer to pcie_device data structure of the root port
564 * @dev: pointer to pci_dev data structure of error source device
565 * @info: comprehensive error information
567 * Invoked when an error being detected by Root Port.
569 static void handle_error_source(struct pcie_device *aerdev,
570 struct pci_dev *dev,
571 struct aer_err_info *info)
573 pci_ers_result_t status = 0;
574 int pos;
576 if (info->severity == AER_CORRECTABLE) {
578 * Correctable error does not need software intevention.
579 * No need to go through error recovery process.
581 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
582 if (pos)
583 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
584 info->status);
585 } else {
586 status = do_recovery(aerdev, dev, info->severity);
587 if (status == PCI_ERS_RESULT_RECOVERED) {
588 dev_printk(KERN_DEBUG, &dev->dev, "AER driver "
589 "successfully recovered\n");
590 } else {
591 /* TODO: Should kernel panic here? */
592 dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't "
593 "recover\n");
599 * aer_enable_rootport - enable Root Port's interrupts when receiving messages
600 * @rpc: pointer to a Root Port data structure
602 * Invoked when PCIE bus loads AER service driver.
604 void aer_enable_rootport(struct aer_rpc *rpc)
606 struct pci_dev *pdev = rpc->rpd->port;
607 int pos, aer_pos;
608 u16 reg16;
609 u32 reg32;
611 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
612 /* Clear PCIE Capability's Device Status */
613 pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16);
614 pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16);
616 /* Disable system error generation in response to error messages */
617 pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16);
618 reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK);
619 pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
621 aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
622 /* Clear error status */
623 pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, &reg32);
624 pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
625 pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32);
626 pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
627 pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32);
628 pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
631 * Enable error reporting for the root port device and downstream port
632 * devices.
634 set_downstream_devices_error_reporting(pdev, true);
636 /* Enable Root Port's interrupt in response to error messages */
637 pci_write_config_dword(pdev,
638 aer_pos + PCI_ERR_ROOT_COMMAND,
639 ROOT_PORT_INTR_ON_MESG_MASK);
643 * disable_root_aer - disable Root Port's interrupts when receiving messages
644 * @rpc: pointer to a Root Port data structure
646 * Invoked when PCIE bus unloads AER service driver.
648 static void disable_root_aer(struct aer_rpc *rpc)
650 struct pci_dev *pdev = rpc->rpd->port;
651 u32 reg32;
652 int pos;
655 * Disable error reporting for the root port device and downstream port
656 * devices.
658 set_downstream_devices_error_reporting(pdev, false);
660 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
661 /* Disable Root's interrupt in response to error messages */
662 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0);
664 /* Clear Root's error status reg */
665 pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, &reg32);
666 pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
670 * get_e_source - retrieve an error source
671 * @rpc: pointer to the root port which holds an error
673 * Invoked by DPC handler to consume an error.
675 static struct aer_err_source *get_e_source(struct aer_rpc *rpc)
677 struct aer_err_source *e_source;
678 unsigned long flags;
680 /* Lock access to Root error producer/consumer index */
681 spin_lock_irqsave(&rpc->e_lock, flags);
682 if (rpc->prod_idx == rpc->cons_idx) {
683 spin_unlock_irqrestore(&rpc->e_lock, flags);
684 return NULL;
686 e_source = &rpc->e_sources[rpc->cons_idx];
687 rpc->cons_idx++;
688 if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
689 rpc->cons_idx = 0;
690 spin_unlock_irqrestore(&rpc->e_lock, flags);
692 return e_source;
696 * get_device_error_info - read error status from dev and store it to info
697 * @dev: pointer to the device expected to have a error record
698 * @info: pointer to structure to store the error record
700 * Return 1 on success, 0 on error.
702 static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
704 int pos, temp;
706 info->status = 0;
707 info->tlp_header_valid = 0;
709 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
711 /* The device might not support AER */
712 if (!pos)
713 return 1;
715 if (info->severity == AER_CORRECTABLE) {
716 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS,
717 &info->status);
718 pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK,
719 &info->mask);
720 if (!(info->status & ~info->mask))
721 return 0;
722 } else if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE ||
723 info->severity == AER_NONFATAL) {
725 /* Link is still healthy for IO reads */
726 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
727 &info->status);
728 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK,
729 &info->mask);
730 if (!(info->status & ~info->mask))
731 return 0;
733 /* Get First Error Pointer */
734 pci_read_config_dword(dev, pos + PCI_ERR_CAP, &temp);
735 info->first_error = PCI_ERR_CAP_FEP(temp);
737 if (info->status & AER_LOG_TLP_MASKS) {
738 info->tlp_header_valid = 1;
739 pci_read_config_dword(dev,
740 pos + PCI_ERR_HEADER_LOG, &info->tlp.dw0);
741 pci_read_config_dword(dev,
742 pos + PCI_ERR_HEADER_LOG + 4, &info->tlp.dw1);
743 pci_read_config_dword(dev,
744 pos + PCI_ERR_HEADER_LOG + 8, &info->tlp.dw2);
745 pci_read_config_dword(dev,
746 pos + PCI_ERR_HEADER_LOG + 12, &info->tlp.dw3);
750 return 1;
753 static inline void aer_process_err_devices(struct pcie_device *p_device,
754 struct aer_err_info *e_info)
756 int i;
758 if (!e_info->dev[0]) {
759 dev_printk(KERN_DEBUG, &p_device->port->dev,
760 "can't find device of ID%04x\n",
761 e_info->id);
764 /* Report all before handle them, not to lost records by reset etc. */
765 for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
766 if (get_device_error_info(e_info->dev[i], e_info))
767 aer_print_error(e_info->dev[i], e_info);
769 for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
770 if (get_device_error_info(e_info->dev[i], e_info))
771 handle_error_source(p_device, e_info->dev[i], e_info);
776 * aer_isr_one_error - consume an error detected by root port
777 * @p_device: pointer to error root port service device
778 * @e_src: pointer to an error source
780 static void aer_isr_one_error(struct pcie_device *p_device,
781 struct aer_err_source *e_src)
783 struct aer_err_info *e_info;
784 int i;
786 /* struct aer_err_info might be big, so we allocate it with slab */
787 e_info = kmalloc(sizeof(struct aer_err_info), GFP_KERNEL);
788 if (e_info == NULL) {
789 dev_printk(KERN_DEBUG, &p_device->port->dev,
790 "Can't allocate mem when processing AER errors\n");
791 return;
795 * There is a possibility that both correctable error and
796 * uncorrectable error being logged. Report correctable error first.
798 for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) {
799 if (i > 4)
800 break;
801 if (!(e_src->status & i))
802 continue;
804 memset(e_info, 0, sizeof(struct aer_err_info));
806 /* Init comprehensive error information */
807 if (i & PCI_ERR_ROOT_COR_RCV) {
808 e_info->id = ERR_COR_ID(e_src->id);
809 e_info->severity = AER_CORRECTABLE;
810 } else {
811 e_info->id = ERR_UNCOR_ID(e_src->id);
812 e_info->severity = ((e_src->status >> 6) & 1);
814 if (e_src->status &
815 (PCI_ERR_ROOT_MULTI_COR_RCV |
816 PCI_ERR_ROOT_MULTI_UNCOR_RCV))
817 e_info->multi_error_valid = 1;
819 aer_print_port_info(p_device->port, e_info);
821 find_source_device(p_device->port, e_info);
822 aer_process_err_devices(p_device, e_info);
825 kfree(e_info);
829 * aer_isr - consume errors detected by root port
830 * @work: definition of this work item
832 * Invoked, as DPC, when root port records new detected error
834 void aer_isr(struct work_struct *work)
836 struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler);
837 struct pcie_device *p_device = rpc->rpd;
838 struct aer_err_source *e_src;
840 mutex_lock(&rpc->rpc_mutex);
841 e_src = get_e_source(rpc);
842 while (e_src) {
843 aer_isr_one_error(p_device, e_src);
844 e_src = get_e_source(rpc);
846 mutex_unlock(&rpc->rpc_mutex);
848 wake_up(&rpc->wait_release);
852 * aer_delete_rootport - disable root port aer and delete service data
853 * @rpc: pointer to a root port device being deleted
855 * Invoked when AER service unloaded on a specific Root Port
857 void aer_delete_rootport(struct aer_rpc *rpc)
859 /* Disable root port AER itself */
860 disable_root_aer(rpc);
862 kfree(rpc);
866 * aer_init - provide AER initialization
867 * @dev: pointer to AER pcie device
869 * Invoked when AER service driver is loaded.
871 int aer_init(struct pcie_device *dev)
873 if (aer_osc_setup(dev) && !forceload)
874 return -ENXIO;
876 return 0;