20 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
27 #include <linux/stddef.h>
31 static bool aer_mask_override;
78 unsigned int bus,
unsigned int devfn,
81 INIT_LIST_HEAD(&err->
list);
95 if (domain == err->
domain &&
109 return __find_aer_error((
u16)domain, dev->
bus->number, dev->
devfn);
118 if (bus_ops->
bus == bus)
130 if (list_empty(&pci_bus_ops_list))
137 spin_unlock_irqrestore(&inject_lock, flags);
141 static u32 *find_pci_config_dword(
struct aer_error *err,
int where,
184 static int pci_read_aer(
struct pci_bus *bus,
unsigned int devfn,
int where,
194 if (size !=
sizeof(
u32))
199 err = __find_aer_error((
u16)domain, bus->
number, devfn);
203 sim = find_pci_config_dword(err, where,
NULL);
206 spin_unlock_irqrestore(&inject_lock, flags);
210 ops = __find_pci_bus_ops(bus);
211 spin_unlock_irqrestore(&inject_lock, flags);
212 return ops->
read(bus, devfn, where, size, val);
226 if (size !=
sizeof(
u32))
231 err = __find_aer_error((
u16)domain, bus->
number, devfn);
235 sim = find_pci_config_dword(err, where, &rw1cs);
241 spin_unlock_irqrestore(&inject_lock, flags);
245 ops = __find_pci_bus_ops(bus);
246 spin_unlock_irqrestore(&inject_lock, flags);
247 return ops->
write(bus, devfn, where, size, val);
250 static struct pci_ops pci_ops_aer = {
251 .read = pci_read_aer,
255 static void pci_bus_ops_init(
struct pci_bus_ops *bus_ops,
259 INIT_LIST_HEAD(&bus_ops->
list);
264 static int pci_bus_set_aer_ops(
struct pci_bus *bus)
275 if (ops == &pci_ops_aer)
277 pci_bus_ops_init(bus_ops, bus, ops);
278 list_add(&bus_ops->
list, &pci_bus_ops_list);
281 spin_unlock_irqrestore(&inject_lock, flags);
289 if (!pci_is_pcie(dev))
295 dev = dev->
bus->self;
328 int pos_cap_err, rp_pos_cap_err;
329 u32 sever, cor_mask, uncor_mask, cor_mask_orig = 0, uncor_mask_orig = 0;
335 rpdev = pcie_find_root_port(dev);
352 if (!rp_pos_cap_err) {
368 if (aer_mask_override) {
369 cor_mask_orig = cor_mask;
374 uncor_mask_orig = uncor_mask;
382 err = __find_aer_error_by_dev(dev);
386 aer_error_init(err, einj->
domain, einj->
bus, devfn,
388 list_add(&err->
list, &einjected);
402 spin_unlock_irqrestore(&inject_lock, flags);
410 spin_unlock_irqrestore(&inject_lock, flags);
414 rperr = __find_aer_error_by_dev(rpdev);
421 list_add(&rperr->
list, &einjected);
444 spin_unlock_irqrestore(&inject_lock, flags);
446 if (aer_mask_override) {
453 ret = pci_bus_set_aer_ops(dev->
bus);
456 ret = pci_bus_set_aer_ops(rpdev->
bus);
460 if (find_aer_device(rpdev, &edev)) {
461 if (!get_service_data(edev)) {
477 static ssize_t aer_inject_write(
struct file *filp,
const char __user *ubuf,
478 size_t usize, loff_t *off)
486 usize >
sizeof(einj))
489 memset(&einj, 0,
sizeof(einj));
493 ret = aer_inject(&einj);
494 return ret ? ret : usize;
498 .write = aer_inject_write,
503 static struct miscdevice aer_inject_device = {
505 .name =
"aer_inject",
506 .fops = &aer_inject_fops,
509 static int __init aer_inject_init(
void)
514 static void __exit aer_inject_exit(
void)
522 while ((bus_ops = pci_bus_ops_pop())) {
532 spin_unlock_irqrestore(&inject_lock, flags);