Release 4.11 drivers/pci/pcie/aer/aerdrv.c
/*
* drivers/pci/pcie/aer/aerdrv.c
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* This file implements the AER root port service driver. The driver will
* register an irq handler. When root port triggers an AER interrupt, the irq
* handler will collect root port status and schedule a work.
*
* Copyright (C) 2006 Intel Corp.
* Tom Long Nguyen (tom.l.nguyen@intel.com)
* Zhang Yanmin (yanmin.zhang@intel.com)
*
*/
#include <linux/pci.h>
#include <linux/pci-acpi.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/pm.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/pcieport_if.h>
#include <linux/slab.h>
#include "aerdrv.h"
#include "../../pci.h"
static int aer_probe(struct pcie_device *dev);
static void aer_remove(struct pcie_device *dev);
static pci_ers_result_t aer_error_detected(struct pci_dev *dev,
enum pci_channel_state error);
static void aer_error_resume(struct pci_dev *dev);
static pci_ers_result_t aer_root_reset(struct pci_dev *dev);
static const struct pci_error_handlers aer_error_handlers = {
.error_detected = aer_error_detected,
.resume = aer_error_resume,
};
static struct pcie_port_service_driver aerdriver = {
.name = "aer",
.port_type = PCI_EXP_TYPE_ROOT_PORT,
.service = PCIE_PORT_SERVICE_AER,
.probe = aer_probe,
.remove = aer_remove,
.err_handler = &aer_error_handlers,
.reset_link = aer_root_reset,
};
static int pcie_aer_disable;
void pci_no_aer(void)
{
pcie_aer_disable = 1;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Randy Dunlap | 11 | 100.00% | 1 | 100.00% |
Total | 11 | 100.00% | 1 | 100.00% |
bool pci_aer_available(void)
{
return !pcie_aer_disable && pci_msi_enabled();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 14 | 100.00% | 1 | 100.00% |
Total | 14 | 100.00% | 1 | 100.00% |
static int set_device_error_reporting(struct pci_dev *dev, void *data)
{
bool enable = *((bool *)data);
int type = pci_pcie_type(dev);
if ((type == PCI_EXP_TYPE_ROOT_PORT) ||
(type == PCI_EXP_TYPE_UPSTREAM) ||
(type == PCI_EXP_TYPE_DOWNSTREAM)) {
if (enable)
pci_enable_pcie_error_reporting(dev);
else
pci_disable_pcie_error_reporting(dev);
}
if (enable)
pcie_set_ecrc_checking(dev);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hidetoshi Seto | 73 | 86.90% | 1 | 50.00% |
Yijing Wang | 11 | 13.10% | 1 | 50.00% |
Total | 84 | 100.00% | 2 | 100.00% |
/**
* set_downstream_devices_error_reporting - enable/disable the error reporting bits on the root port and its downstream ports.
* @dev: pointer to root port's pci_dev data structure
* @enable: true = enable error reporting, false = disable error reporting.
*/
static void set_downstream_devices_error_reporting(struct pci_dev *dev,
bool enable)
{
set_device_error_reporting(dev, &enable);
if (!dev->subordinate)
return;
pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hidetoshi Seto | 42 | 100.00% | 1 | 100.00% |
Total | 42 | 100.00% | 1 | 100.00% |
/**
* aer_enable_rootport - enable Root Port's interrupts when receiving messages
* @rpc: pointer to a Root Port data structure
*
* Invoked when PCIe bus loads AER service driver.
*/
static void aer_enable_rootport(struct aer_rpc *rpc)
{
struct pci_dev *pdev = rpc->rpd->port;
int aer_pos;
u16 reg16;
u32 reg32;
/* Clear PCIe Capability's Device Status */
pcie_capability_read_word(pdev, PCI_EXP_DEVSTA, ®16);
pcie_capability_write_word(pdev, PCI_EXP_DEVSTA, reg16);
/* Disable system error generation in response to error messages */
pcie_capability_clear_word(pdev, PCI_EXP_RTCTL,
SYSTEM_ERROR_INTR_ON_MESG_MASK);
aer_pos = pdev->aer_cap;
/* Clear error status */
pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, ®32);
pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, ®32);
pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, ®32);
pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
/*
* Enable error reporting for the root port device and downstream port
* devices.
*/
set_downstream_devices_error_reporting(pdev, true);
/* Enable Root Port's interrupt in response to error messages */
pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_COMMAND, ®32);
reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_COMMAND, reg32);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hidetoshi Seto | 168 | 97.11% | 1 | 33.33% |
Jiang Liu | 3 | 1.73% | 1 | 33.33% |
Keith Busch | 2 | 1.16% | 1 | 33.33% |
Total | 173 | 100.00% | 3 | 100.00% |
/**
* aer_disable_rootport - disable Root Port's interrupts when receiving messages
* @rpc: pointer to a Root Port data structure
*
* Invoked when PCIe bus unloads AER service driver.
*/
static void aer_disable_rootport(struct aer_rpc *rpc)
{
struct pci_dev *pdev = rpc->rpd->port;
u32 reg32;
int pos;
/*
* Disable error reporting for the root port device and downstream port
* devices.
*/
set_downstream_devices_error_reporting(pdev, false);
pos = pdev->aer_cap;
/* Disable Root's interrupt in response to error messages */
pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, ®32);
reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, reg32);
/* Clear Root's error status reg */
pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, ®32);
pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hidetoshi Seto | 93 | 97.89% | 1 | 50.00% |
Keith Busch | 2 | 2.11% | 1 | 50.00% |
Total | 95 | 100.00% | 2 | 100.00% |
/**
* aer_irq - Root Port's ISR
* @irq: IRQ assigned to Root Port
* @context: pointer to Root Port data structure
*
* Invoked when Root Port detects AER messages.
*/
irqreturn_t aer_irq(int irq, void *context)
{
unsigned int status, id;
struct pcie_device *pdev = (struct pcie_device *)context;
struct aer_rpc *rpc = get_service_data(pdev);
int next_prod_idx;
unsigned long flags;
int pos;
pos = pdev->port->aer_cap;
/*
* Must lock access to Root Error Status Reg, Root Error ID Reg,
* and Root error producer/consumer index
*/
spin_lock_irqsave(&rpc->e_lock, flags);
/* Read error status */
pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, &status);
if (!(status & (PCI_ERR_ROOT_UNCOR_RCV|PCI_ERR_ROOT_COR_RCV))) {
spin_unlock_irqrestore(&rpc->e_lock, flags);
return IRQ_NONE;
}
/* Read error source and clear error status */
pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_ERR_SRC, &id);
pci_write_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, status);
/* Store error source for later DPC handler */
next_prod_idx = rpc->prod_idx + 1;
if (next_prod_idx == AER_ERROR_SOURCES_MAX)
next_prod_idx = 0;
if (next_prod_idx == rpc->cons_idx) {
/*
* Error Storm Condition - possibly the same error occurred.
* Drop the error.
*/
spin_unlock_irqrestore(&rpc->e_lock, flags);
return IRQ_HANDLED;
}
rpc->e_sources[rpc->prod_idx].status = status;
rpc->e_sources[rpc->prod_idx].id = id;
rpc->prod_idx = next_prod_idx;
spin_unlock_irqrestore(&rpc->e_lock, flags);
/* Invoke DPC handler */
schedule_work(&rpc->dpc_handler);
return IRQ_HANDLED;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 229 | 96.62% | 1 | 25.00% |
Hidetoshi Seto | 6 | 2.53% | 2 | 50.00% |
Keith Busch | 2 | 0.84% | 1 | 25.00% |
Total | 237 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(aer_irq);
/**
* aer_alloc_rpc - allocate Root Port data structure
* @dev: pointer to the pcie_dev data structure
*
* Invoked when Root Port's AER service is loaded.
*/
static struct aer_rpc *aer_alloc_rpc(struct pcie_device *dev)
{
struct aer_rpc *rpc;
rpc = kzalloc(sizeof(struct aer_rpc), GFP_KERNEL);
if (!rpc)
return NULL;
/* Initialize Root lock access, e_lock, to Root Error Status Reg */
spin_lock_init(&rpc->e_lock);
rpc->rpd = dev;
INIT_WORK(&rpc->dpc_handler, aer_isr);
mutex_init(&rpc->rpc_mutex);
/* Use PCIe bus function to store rpc into PCIe device */
set_service_data(dev, rpc);
return rpc;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 71 | 85.54% | 1 | 16.67% |
Hidetoshi Seto | 6 | 7.23% | 2 | 33.33% |
Milind Arun Choudhary | 4 | 4.82% | 1 | 16.67% |
Yoann Padioleau | 1 | 1.20% | 1 | 16.67% |
Stefan Assmann | 1 | 1.20% | 1 | 16.67% |
Total | 83 | 100.00% | 6 | 100.00% |
/**
* aer_remove - clean up resources
* @dev: pointer to the pcie_dev data structure
*
* Invoked when PCI Express bus unloads or AER probe fails.
*/
static void aer_remove(struct pcie_device *dev)
{
struct aer_rpc *rpc = get_service_data(dev);
if (rpc) {
/* If register interrupt service, it must be free. */
if (rpc->isr)
free_irq(dev->irq, dev);
flush_work(&rpc->dpc_handler);
aer_disable_rootport(rpc);
kfree(rpc);
set_service_data(dev, NULL);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 59 | 86.76% | 1 | 33.33% |
Hidetoshi Seto | 6 | 8.82% | 1 | 33.33% |
Sebastian Andrzej Siewior | 3 | 4.41% | 1 | 33.33% |
Total | 68 | 100.00% | 3 | 100.00% |
/**
* aer_probe - initialize resources
* @dev: pointer to the pcie_dev data structure
*
* Invoked when PCI Express bus loads AER service driver.
*/
static int aer_probe(struct pcie_device *dev)
{
int status;
struct aer_rpc *rpc;
struct device *device = &dev->port->dev;
/* Alloc rpc data structure */
rpc = aer_alloc_rpc(dev);
if (!rpc) {
dev_printk(KERN_DEBUG, device, "alloc AER rpc failed\n");
aer_remove(dev);
return -ENOMEM;
}
/* Request IRQ ISR */
status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", dev);
if (status) {
dev_printk(KERN_DEBUG, device, "request AER IRQ %d failed\n",
dev->irq);
aer_remove(dev);
return status;
}
rpc->isr = 1;
aer_enable_rootport(rpc);
dev_info(device, "AER enabled with IRQ %d\n", dev->irq);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 99 | 73.88% | 1 | 16.67% |
Björn Helgaas | 25 | 18.66% | 3 | 50.00% |
Hidetoshi Seto | 9 | 6.72% | 1 | 16.67% |
Thomas Gleixner | 1 | 0.75% | 1 | 16.67% |
Total | 134 | 100.00% | 6 | 100.00% |
/**
* aer_root_reset - reset link on Root Port
* @dev: pointer to Root Port's pci_dev data structure
*
* Invoked by Port Bus driver when performing link reset at Root Port.
*/
static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
{
u32 reg32;
int pos;
pos = dev->aer_cap;
/* Disable Root's interrupt in response to error messages */
pci_read_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, ®32);
reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, reg32);
pci_reset_bridge_secondary_bus(dev);
dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n");
/* Clear Root Error Status */
pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, ®32);
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, reg32);
/* Enable Root Port's interrupt in response to error messages */
pci_read_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, ®32);
reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, reg32);
return PCI_ERS_RESULT_RECOVERED;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 77 | 62.10% | 1 | 20.00% |
Hidetoshi Seto | 40 | 32.26% | 1 | 20.00% |
Björn Helgaas | 4 | 3.23% | 1 | 20.00% |
Keith Busch | 2 | 1.61% | 1 | 20.00% |
Alex Williamson | 1 | 0.81% | 1 | 20.00% |
Total | 124 | 100.00% | 5 | 100.00% |
/**
* aer_error_detected - update severity status
* @dev: pointer to Root Port's pci_dev data structure
* @error: error severity being notified by port bus
*
* Invoked by Port Bus driver during error recovery.
*/
static pci_ers_result_t aer_error_detected(struct pci_dev *dev,
enum pci_channel_state error)
{
/* Root Port has no impact. Always recovers. */
return PCI_ERS_RESULT_CAN_RECOVER;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 19 | 100.00% | 1 | 100.00% |
Total | 19 | 100.00% | 1 | 100.00% |
/**
* aer_error_resume - clean up corresponding error status bits
* @dev: pointer to Root Port's pci_dev data structure
*
* Invoked by Port Bus driver during nonfatal recovery.
*/
static void aer_error_resume(struct pci_dev *dev)
{
int pos;
u32 status, mask;
u16 reg16;
/* Clean up Root device status */
pcie_capability_read_word(dev, PCI_EXP_DEVSTA, ®16);
pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
/* Clean AER Root Error Status */
pos = dev->aer_cap;
pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
if (dev->error_state == pci_channel_io_normal)
status &= ~mask; /* Clear corresponding nonfatal bits */
else
status &= mask; /* Clear corresponding fatal bits */
pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 100 | 96.15% | 1 | 33.33% |
Jiang Liu | 2 | 1.92% | 1 | 33.33% |
Keith Busch | 2 | 1.92% | 1 | 33.33% |
Total | 104 | 100.00% | 3 | 100.00% |
/**
* aer_service_init - register AER root service driver
*
* Invoked when AER root service driver is loaded.
*/
static int __init aer_service_init(void)
{
if (!pci_aer_available() || aer_acpi_firmware_first())
return -ENXIO;
return pcie_port_service_register(&aerdriver);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 15 | 51.72% | 1 | 16.67% |
Andi Kleen | 7 | 24.14% | 1 | 16.67% |
Rafael J. Wysocki | 4 | 13.79% | 2 | 33.33% |
Randy Dunlap | 2 | 6.90% | 1 | 16.67% |
Sam Ravnborg | 1 | 3.45% | 1 | 16.67% |
Total | 29 | 100.00% | 6 | 100.00% |
device_initcall(aer_service_init);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Yanmin Zhang | 807 | 57.77% | 1 | 2.86% |
Hidetoshi Seto | 453 | 32.43% | 7 | 20.00% |
Björn Helgaas | 29 | 2.08% | 3 | 8.57% |
Rafael J. Wysocki | 27 | 1.93% | 4 | 11.43% |
Randy Dunlap | 17 | 1.22% | 1 | 2.86% |
Yijing Wang | 11 | 0.79% | 1 | 2.86% |
Keith Busch | 10 | 0.72% | 1 | 2.86% |
Andi Kleen | 7 | 0.50% | 1 | 2.86% |
Jiang Liu | 5 | 0.36% | 1 | 2.86% |
Huang Ying | 5 | 0.36% | 1 | 2.86% |
Milind Arun Choudhary | 4 | 0.29% | 1 | 2.86% |
Sebastian Andrzej Siewior | 3 | 0.21% | 1 | 2.86% |
Alexey Dobriyan | 3 | 0.21% | 1 | 2.86% |
Tejun Heo | 3 | 0.21% | 1 | 2.86% |
Alexander Chiang | 3 | 0.21% | 1 | 2.86% |
Sam Ravnborg | 2 | 0.14% | 1 | 2.86% |
Alex Williamson | 1 | 0.07% | 1 | 2.86% |
Stephen Hemminger | 1 | 0.07% | 1 | 2.86% |
Cao jin | 1 | 0.07% | 1 | 2.86% |
Yoann Padioleau | 1 | 0.07% | 1 | 2.86% |
Stefan Assmann | 1 | 0.07% | 1 | 2.86% |
Paul Gortmaker | 1 | 0.07% | 1 | 2.86% |
Kenji Kaneshige | 1 | 0.07% | 1 | 2.86% |
Thomas Gleixner | 1 | 0.07% | 1 | 2.86% |
Total | 1397 | 100.00% | 35 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.