Skip to content

Commit 0918472

Browse files
yhuang-inteljbarnes993
authored andcommitted
PCI: PCIe AER: add aer_recover_queue
In addition to native PCIe AER, now APEI (ACPI Platform Error Interface) GHES (Generic Hardware Error Source) can be used to report PCIe AER errors too. To add support to APEI GHES PCIe AER recovery, aer_recover_queue is added to export the recovery function in native PCIe AER driver. Recoverable PCIe AER errors are reported via NMI in APEI GHES. Then APEI GHES uses irq_work to delay the error processing into an IRQ handler. But PCIe AER recovery can be very time-consuming, so aer_recover_queue, which can be used in IRQ handler, delays the real recovery action into the process context, that is, work queue. Signed-off-by: Huang Ying <ying.huang@intel.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 0aba496 commit 0918472

3 files changed

Lines changed: 74 additions & 8 deletions

File tree

‎drivers/pci/pcie/aer/aerdrv_core.c‎

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/suspend.h>
2525
#include <linux/delay.h>
2626
#include <linux/slab.h>
27+
#include <linux/kfifo.h>
2728
#include "aerdrv.h"
2829

2930
static int forceload;
@@ -445,8 +446,7 @@ static struct pcie_port_service_driver *find_aer_service(struct pci_dev *dev)
445446
return drv;
446447
}
447448

448-
static pci_ers_result_t reset_link(struct pcie_device *aerdev,
449-
struct pci_dev *dev)
449+
static pci_ers_result_t reset_link(struct pci_dev *dev)
450450
{
451451
struct pci_dev *udev;
452452
pci_ers_result_t status;
@@ -486,16 +486,14 @@ static pci_ers_result_t reset_link(struct pcie_device *aerdev,
486486

487487
/**
488488
* do_recovery - handle nonfatal/fatal error recovery process
489-
* @aerdev: pointer to a pcie_device data structure of root port
490489
* @dev: pointer to a pci_dev data structure of agent detecting an error
491490
* @severity: error severity type
492491
*
493492
* Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
494493
* error detected message to all downstream drivers within a hierarchy in
495494
* question and return the returned code.
496495
*/
497-
static void do_recovery(struct pcie_device *aerdev, struct pci_dev *dev,
498-
int severity)
496+
static void do_recovery(struct pci_dev *dev, int severity)
499497
{
500498
pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
501499
enum pci_channel_state state;
@@ -511,7 +509,7 @@ static void do_recovery(struct pcie_device *aerdev, struct pci_dev *dev,
511509
report_error_detected);
512510

513511
if (severity == AER_FATAL) {
514-
result = reset_link(aerdev, dev);
512+
result = reset_link(dev);
515513
if (result != PCI_ERS_RESULT_RECOVERED)
516514
goto failed;
517515
}
@@ -576,9 +574,73 @@ static void handle_error_source(struct pcie_device *aerdev,
576574
pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
577575
info->status);
578576
} else
579-
do_recovery(aerdev, dev, info->severity);
577+
do_recovery(dev, info->severity);
580578
}
581579

580+
#ifdef CONFIG_ACPI_APEI_PCIEAER
581+
static void aer_recover_work_func(struct work_struct *work);
582+
583+
#define AER_RECOVER_RING_ORDER 4
584+
#define AER_RECOVER_RING_SIZE (1 << AER_RECOVER_RING_ORDER)
585+
586+
struct aer_recover_entry
587+
{
588+
u8 bus;
589+
u8 devfn;
590+
u16 domain;
591+
int severity;
592+
};
593+
594+
static DEFINE_KFIFO(aer_recover_ring, struct aer_recover_entry,
595+
AER_RECOVER_RING_SIZE);
596+
/*
597+
* Mutual exclusion for writers of aer_recover_ring, reader side don't
598+
* need lock, because there is only one reader and lock is not needed
599+
* between reader and writer.
600+
*/
601+
static DEFINE_SPINLOCK(aer_recover_ring_lock);
602+
static DECLARE_WORK(aer_recover_work, aer_recover_work_func);
603+
604+
void aer_recover_queue(int domain, unsigned int bus, unsigned int devfn,
605+
int severity)
606+
{
607+
unsigned long flags;
608+
struct aer_recover_entry entry = {
609+
.bus = bus,
610+
.devfn = devfn,
611+
.domain = domain,
612+
.severity = severity,
613+
};
614+
615+
spin_lock_irqsave(&aer_recover_ring_lock, flags);
616+
if (kfifo_put(&aer_recover_ring, &entry))
617+
schedule_work(&aer_recover_work);
618+
else
619+
pr_err("AER recover: Buffer overflow when recovering AER for %04x:%02x:%02x:%x\n",
620+
domain, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
621+
spin_unlock_irqrestore(&aer_recover_ring_lock, flags);
622+
}
623+
EXPORT_SYMBOL_GPL(aer_recover_queue);
624+
625+
static void aer_recover_work_func(struct work_struct *work)
626+
{
627+
struct aer_recover_entry entry;
628+
struct pci_dev *pdev;
629+
630+
while (kfifo_get(&aer_recover_ring, &entry)) {
631+
pdev = pci_get_domain_bus_and_slot(entry.domain, entry.bus,
632+
entry.devfn);
633+
if (!pdev) {
634+
pr_err("AER recover: Can not find pci_dev for %04x:%02x:%02x:%x\n",
635+
entry.domain, entry.bus,
636+
PCI_SLOT(entry.devfn), PCI_FUNC(entry.devfn));
637+
continue;
638+
}
639+
do_recovery(pdev, entry.severity);
640+
}
641+
}
642+
#endif
643+
582644
/**
583645
* get_device_error_info - read error status from dev and store it to info
584646
* @dev: pointer to the device expected to have a error record

‎drivers/pci/pcie/aer/aerdrv_errprint.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
204204
}
205205

206206
#ifdef CONFIG_ACPI_APEI_PCIEAER
207-
static int cper_severity_to_aer(int cper_severity)
207+
int cper_severity_to_aer(int cper_severity)
208208
{
209209
switch (cper_severity) {
210210
case CPER_SEV_RECOVERABLE:
@@ -215,6 +215,7 @@ static int cper_severity_to_aer(int cper_severity)
215215
return AER_CORRECTABLE;
216216
}
217217
}
218+
EXPORT_SYMBOL_GPL(cper_severity_to_aer);
218219

219220
void cper_print_aer(const char *prefix, int cper_severity,
220221
struct aer_capability_regs *aer)

‎include/linux/aer.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
5151

5252
extern void cper_print_aer(const char *prefix, int cper_severity,
5353
struct aer_capability_regs *aer);
54+
extern int cper_severity_to_aer(int cper_severity);
55+
extern void aer_recover_queue(int domain, unsigned int bus, unsigned int devfn,
56+
int severity);
5457
#endif //_AER_H_
5558

0 commit comments

Comments
 (0)