cregit-Linux how code gets into the kernel

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

PersonTokensPropCommitsCommitProp
Randy Dunlap11100.00%1100.00%
Total11100.00%1100.00%


bool pci_aer_available(void) { return !pcie_aer_disable && pci_msi_enabled(); }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki14100.00%1100.00%
Total14100.00%1100.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

PersonTokensPropCommitsCommitProp
Hidetoshi Seto7386.90%150.00%
Yijing Wang1113.10%150.00%
Total84100.00%2100.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

PersonTokensPropCommitsCommitProp
Hidetoshi Seto42100.00%1100.00%
Total42100.00%1100.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, &reg16); 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, &reg32); pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32); pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32); pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32); pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32); 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, &reg32); reg32 |= ROOT_PORT_INTR_ON_MESG_MASK; pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_COMMAND, reg32); }

Contributors

PersonTokensPropCommitsCommitProp
Hidetoshi Seto16897.11%133.33%
Jiang Liu31.73%133.33%
Keith Busch21.16%133.33%
Total173100.00%3100.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, &reg32); 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, &reg32); pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32); }

Contributors

PersonTokensPropCommitsCommitProp
Hidetoshi Seto9397.89%150.00%
Keith Busch22.11%150.00%
Total95100.00%2100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang22996.62%125.00%
Hidetoshi Seto62.53%250.00%
Keith Busch20.84%125.00%
Total237100.00%4100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang7185.54%116.67%
Hidetoshi Seto67.23%233.33%
Milind Arun Choudhary44.82%116.67%
Yoann Padioleau11.20%116.67%
Stefan Assmann11.20%116.67%
Total83100.00%6100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang5986.76%133.33%
Hidetoshi Seto68.82%133.33%
Sebastian Andrzej Siewior34.41%133.33%
Total68100.00%3100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang9973.88%116.67%
Björn Helgaas2518.66%350.00%
Hidetoshi Seto96.72%116.67%
Thomas Gleixner10.75%116.67%
Total134100.00%6100.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, &reg32); 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, &reg32); 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, &reg32); reg32 |= ROOT_PORT_INTR_ON_MESG_MASK; pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, reg32); return PCI_ERS_RESULT_RECOVERED; }

Contributors

PersonTokensPropCommitsCommitProp
Yanmin Zhang7762.10%120.00%
Hidetoshi Seto4032.26%120.00%
Björn Helgaas43.23%120.00%
Keith Busch21.61%120.00%
Alex Williamson10.81%120.00%
Total124100.00%5100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang19100.00%1100.00%
Total19100.00%1100.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, &reg16); 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

PersonTokensPropCommitsCommitProp
Yanmin Zhang10096.15%133.33%
Jiang Liu21.92%133.33%
Keith Busch21.92%133.33%
Total104100.00%3100.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

PersonTokensPropCommitsCommitProp
Yanmin Zhang1551.72%116.67%
Andi Kleen724.14%116.67%
Rafael J. Wysocki413.79%233.33%
Randy Dunlap26.90%116.67%
Sam Ravnborg13.45%116.67%
Total29100.00%6100.00%

device_initcall(aer_service_init);

Overall Contributors

PersonTokensPropCommitsCommitProp
Yanmin Zhang80757.77%12.86%
Hidetoshi Seto45332.43%720.00%
Björn Helgaas292.08%38.57%
Rafael J. Wysocki271.93%411.43%
Randy Dunlap171.22%12.86%
Yijing Wang110.79%12.86%
Keith Busch100.72%12.86%
Andi Kleen70.50%12.86%
Jiang Liu50.36%12.86%
Huang Ying50.36%12.86%
Milind Arun Choudhary40.29%12.86%
Sebastian Andrzej Siewior30.21%12.86%
Alexey Dobriyan30.21%12.86%
Tejun Heo30.21%12.86%
Alexander Chiang30.21%12.86%
Sam Ravnborg20.14%12.86%
Alex Williamson10.07%12.86%
Stephen Hemminger10.07%12.86%
Cao jin10.07%12.86%
Yoann Padioleau10.07%12.86%
Stefan Assmann10.07%12.86%
Paul Gortmaker10.07%12.86%
Kenji Kaneshige10.07%12.86%
Thomas Gleixner10.07%12.86%
Total1397100.00%35100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.