19 #include <linux/module.h>
20 #include <linux/pci.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
26 #include <linux/slab.h>
30 static bool forceload;
31 static bool nosourceid;
35 #define PCI_EXP_AER_FLAGS (PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | \
36 PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE)
40 if (pcie_aer_get_firmware_first(dev))
52 if (pcie_aer_get_firmware_first(dev))
92 #define PCI_BUS(x) (((x) >> 8) & 0xff)
109 if (!nosourceid && (
PCI_BUS(e_info->
id) != 0)) {
111 if (e_info->
id == ((dev->
bus->number << 8) | dev->
devfn))
153 static int find_device_iter(
struct pci_dev *dev,
void *
data)
157 if (is_error_source(dev, e_info)) {
159 if (add_error_device(e_info, dev)) {
184 static bool find_source_device(
struct pci_dev *parent,
194 result = find_device_iter(dev, e_info);
202 "can't find device of ID%04x\n",
209 static int report_error_detected(
struct pci_dev *dev,
void *data)
216 device_lock(&dev->
dev);
220 !dev->
driver->err_handler ||
221 !dev->
driver->err_handler->error_detected) {
233 "no AER-aware driver" :
"no driver");
238 err_handler = dev->
driver->err_handler;
240 result_data->
result = merge_result(result_data->
result, vote);
242 device_unlock(&dev->
dev);
246 static int report_mmio_enabled(
struct pci_dev *dev,
void *data)
253 device_lock(&dev->
dev);
255 !dev->
driver->err_handler ||
256 !dev->
driver->err_handler->mmio_enabled)
259 err_handler = dev->
driver->err_handler;
261 result_data->
result = merge_result(result_data->
result, vote);
263 device_unlock(&dev->
dev);
267 static int report_slot_reset(
struct pci_dev *dev,
void *data)
274 device_lock(&dev->
dev);
276 !dev->
driver->err_handler ||
277 !dev->
driver->err_handler->slot_reset)
280 err_handler = dev->
driver->err_handler;
282 result_data->
result = merge_result(result_data->
result, vote);
284 device_unlock(&dev->
dev);
288 static int report_resume(
struct pci_dev *dev,
void *data)
292 device_lock(&dev->
dev);
296 !dev->
driver->err_handler ||
297 !dev->
driver->err_handler->resume)
300 err_handler = dev->
driver->err_handler;
303 device_unlock(&dev->
dev);
325 dev_printk(
KERN_DEBUG, &dev->
dev,
"broadcast %s message\n", error_mesg);
327 if (
cb == report_error_detected)
339 if (
cb == report_error_detected)
342 if (
cb == report_resume) {
354 return result_data.
result;
400 "Downstream Port link has been reset\n");
404 static int find_aer_service_iter(
struct device *
device,
void *data)
413 *drv = service_driver;
441 udev = dev->
bus->self;
445 driver = find_aer_service(udev);
450 status = default_downstream_reset_link(udev);
453 "no link-reset support at upstream device %s\n",
460 "link reset at upstream device %s failed\n",
477 static void do_recovery(
struct pci_dev *dev,
int severity)
487 status = broadcast_error_message(dev,
490 report_error_detected);
499 status = broadcast_error_message(dev,
502 report_mmio_enabled);
510 status = broadcast_error_message(dev,
519 broadcast_error_message(dev,
524 dev_info(&dev->
dev,
"AER: Device recovery successful\n");
529 dev_info(&dev->
dev,
"AER: Device recovery failed\n");
540 static void handle_error_source(
struct pcie_device *aerdev,
559 #ifdef CONFIG_ACPI_APEI_PCIEAER
562 #define AER_RECOVER_RING_ORDER 4
563 #define AER_RECOVER_RING_SIZE (1 << AER_RECOVER_RING_ORDER)
565 struct aer_recover_entry
573 static DEFINE_KFIFO(aer_recover_ring,
struct aer_recover_entry,
574 AER_RECOVER_RING_SIZE);
581 static DECLARE_WORK(aer_recover_work, aer_recover_work_func);
587 struct aer_recover_entry
entry = {
591 .severity = severity,
595 if (
kfifo_put(&aer_recover_ring, &entry))
598 pr_err(
"AER recover: Buffer overflow when recovering AER for %04x:%02x:%02x:%x\n",
600 spin_unlock_irqrestore(&aer_recover_ring_lock, flags);
606 struct aer_recover_entry entry;
609 while (
kfifo_get(&aer_recover_ring, &entry)) {
613 pr_err(
"AER recover: Can not find pci_dev for %04x:%02x:%02x:%x\n",
614 entry.domain, entry.bus,
618 do_recovery(pdev, entry.severity);
665 pci_read_config_dword(dev, pos +
PCI_ERR_CAP, &temp);
670 pci_read_config_dword(dev,
672 pci_read_config_dword(dev,
674 pci_read_config_dword(dev,
676 pci_read_config_dword(dev,
684 static inline void aer_process_err_devices(
struct pcie_device *p_device,
691 if (get_device_error_info(e_info->
dev[i], e_info))
695 if (get_device_error_info(e_info->
dev[i], e_info))
696 handle_error_source(p_device, e_info->
dev[i], e_info);
705 static void aer_isr_one_error(
struct pcie_device *p_device,
714 "Can't allocate mem when processing AER errors\n");
733 if (find_source_device(p_device->
port, e_info))
734 aer_process_err_devices(p_device, e_info);
752 if (find_source_device(p_device->
port, e_info))
753 aer_process_err_devices(p_device, e_info);
775 spin_unlock_irqrestore(&rpc->
e_lock, flags);
783 spin_unlock_irqrestore(&rpc->
e_lock, flags);
801 while (get_e_source(rpc, &e_src))
802 aer_isr_one_error(p_device, &e_src);
818 "aerdrv forceload requested.\n");
819 pcie_aer_force_firmware_first(dev->
port, 0);