2006-07-31 15:21:33 +08:00
|
|
|
/*
|
|
|
|
* 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/module.h>
|
|
|
|
#include <linux/pci.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 "aerdrv.h"
|
2008-06-05 01:39:07 +08:00
|
|
|
#include "../../pci.h"
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION "v1.0"
|
|
|
|
#define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
|
|
|
|
#define DRIVER_DESC "Root Port Advanced Error Reporting Driver"
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-01-13 21:44:19 +08:00
|
|
|
static int __devinit aer_probe (struct pcie_device *dev);
|
2006-07-31 15:21:33 +08:00
|
|
|
static void aer_remove(struct pcie_device *dev);
|
|
|
|
static int aer_suspend(struct pcie_device *dev, pm_message_t state)
|
|
|
|
{return 0;}
|
|
|
|
static int aer_resume(struct pcie_device *dev) {return 0;}
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI Express bus's AER Root service driver data structure
|
|
|
|
*/
|
|
|
|
static struct pcie_port_service_id aer_id[] = {
|
|
|
|
{
|
|
|
|
.vendor = PCI_ANY_ID,
|
|
|
|
.device = PCI_ANY_ID,
|
|
|
|
.port_type = PCIE_RC_PORT,
|
|
|
|
.service_type = PCIE_PORT_SERVICE_AER,
|
|
|
|
},
|
|
|
|
{ /* end: all zeroes */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_error_handlers aer_error_handlers = {
|
|
|
|
.error_detected = aer_error_detected,
|
|
|
|
.resume = aer_error_resume,
|
|
|
|
};
|
|
|
|
|
2007-02-27 17:22:00 +08:00
|
|
|
static struct pcie_port_service_driver aerdriver = {
|
2006-07-31 15:21:33 +08:00
|
|
|
.name = "aer",
|
|
|
|
.id_table = &aer_id[0],
|
|
|
|
|
|
|
|
.probe = aer_probe,
|
|
|
|
.remove = aer_remove,
|
|
|
|
|
|
|
|
.suspend = aer_suspend,
|
|
|
|
.resume = aer_resume,
|
|
|
|
|
|
|
|
.err_handler = &aer_error_handlers,
|
|
|
|
|
|
|
|
.reset_link = aer_root_reset,
|
|
|
|
};
|
|
|
|
|
2007-10-06 04:17:58 +08:00
|
|
|
static int pcie_aer_disable;
|
|
|
|
|
|
|
|
void pci_no_aer(void)
|
|
|
|
{
|
|
|
|
pcie_aer_disable = 1; /* has priority over 'forceload' */
|
|
|
|
}
|
|
|
|
|
2006-07-31 15:21:33 +08: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.
|
|
|
|
**/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t aer_irq(int irq, void *context)
|
2006-07-31 15:21:33 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2008-10-19 08:33:19 +08:00
|
|
|
pos = pci_find_ext_capability(pdev->port, PCI_EXT_CAP_ID_ERR);
|
2006-07-31 15:21:33 +08:00
|
|
|
/*
|
|
|
|
* 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 & ROOT_ERR_STATUS_MASKS)) {
|
|
|
|
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_COR_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 16:49:03 +08:00
|
|
|
if (!(rpc = kzalloc(sizeof(struct aer_rpc),
|
2006-07-31 15:21:33 +08:00
|
|
|
GFP_KERNEL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize Root lock access, e_lock, to Root Error Status Reg,
|
|
|
|
* Root Error ID Reg, and Root error producer/consumer index.
|
|
|
|
*/
|
2007-07-10 02:55:54 +08:00
|
|
|
spin_lock_init(&rpc->e_lock);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
rpc->rpd = dev;
|
2006-11-22 22:55:48 +08:00
|
|
|
INIT_WORK(&rpc->dpc_handler, aer_isr);
|
2006-07-31 15:21:33 +08:00
|
|
|
rpc->prod_idx = rpc->cons_idx = 0;
|
|
|
|
mutex_init(&rpc->rpc_mutex);
|
|
|
|
init_waitqueue_head(&rpc->wait_release);
|
|
|
|
|
|
|
|
/* Use PCIE bus function to store rpc into PCIE device */
|
|
|
|
set_service_data(dev, rpc);
|
|
|
|
|
|
|
|
return rpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
wait_event(rpc->wait_release, rpc->prod_idx == rpc->cons_idx);
|
|
|
|
|
|
|
|
aer_delete_rootport(rpc);
|
|
|
|
set_service_data(dev, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aer_probe - initialize resources
|
|
|
|
* @dev: pointer to the pcie_dev data structure
|
|
|
|
* @id: pointer to the service id data structure
|
|
|
|
*
|
|
|
|
* Invoked when PCI Express bus loads AER service driver.
|
|
|
|
**/
|
2009-01-13 21:44:19 +08:00
|
|
|
static int __devinit aer_probe (struct pcie_device *dev)
|
2006-07-31 15:21:33 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct aer_rpc *rpc;
|
|
|
|
struct device *device = &dev->device;
|
|
|
|
|
|
|
|
/* Init */
|
|
|
|
if ((status = aer_init(dev)))
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* Alloc rpc data structure */
|
|
|
|
if (!(rpc = aer_alloc_rpc(dev))) {
|
2008-06-14 00:52:12 +08:00
|
|
|
dev_printk(KERN_DEBUG, device, "alloc rpc failed\n");
|
2006-07-31 15:21:33 +08:00
|
|
|
aer_remove(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request IRQ ISR */
|
2007-02-14 16:33:16 +08:00
|
|
|
if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv",
|
2006-07-31 15:21:33 +08:00
|
|
|
dev))) {
|
2008-06-14 00:52:12 +08:00
|
|
|
dev_printk(KERN_DEBUG, device, "request IRQ failed\n");
|
2006-07-31 15:21:33 +08:00
|
|
|
aer_remove(dev);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc->isr = 1;
|
|
|
|
|
|
|
|
aer_enable_rootport(rpc);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
u16 p2p_ctrl;
|
|
|
|
u32 status;
|
|
|
|
int pos;
|
|
|
|
|
2008-10-19 08:33:19 +08:00
|
|
|
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/* Disable Root's interrupt in response to error messages */
|
|
|
|
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, 0);
|
|
|
|
|
|
|
|
/* Assert Secondary Bus Reset */
|
|
|
|
pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &p2p_ctrl);
|
|
|
|
p2p_ctrl |= PCI_CB_BRIDGE_CTL_CB_RESET;
|
|
|
|
pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
|
|
|
|
|
|
|
|
/* De-assert Secondary Bus Reset */
|
|
|
|
p2p_ctrl &= ~PCI_CB_BRIDGE_CTL_CB_RESET;
|
|
|
|
pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System software must wait for at least 100ms from the end
|
|
|
|
* of a reset of one or more device before it is permitted
|
|
|
|
* to issue Configuration Requests to those devices.
|
|
|
|
*/
|
|
|
|
msleep(200);
|
2008-06-14 00:52:12 +08:00
|
|
|
dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n");
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/* Enable Root Port's interrupt in response to error messages */
|
|
|
|
pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status);
|
|
|
|
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, status);
|
|
|
|
pci_write_config_dword(dev,
|
|
|
|
pos + PCI_ERR_ROOT_COMMAND,
|
|
|
|
ROOT_PORT_INTR_ON_MESG_MASK);
|
|
|
|
|
|
|
|
return PCI_ERS_RESULT_RECOVERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 */
|
|
|
|
pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
|
|
|
|
pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, ®16);
|
|
|
|
pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, reg16);
|
|
|
|
|
|
|
|
/* Clean AER Root Error Status */
|
2008-10-19 08:33:19 +08:00
|
|
|
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
|
2006-07-31 15:21:33 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aer_service_init - register AER root service driver
|
|
|
|
*
|
|
|
|
* Invoked when AER root service driver is loaded.
|
|
|
|
**/
|
|
|
|
static int __init aer_service_init(void)
|
|
|
|
{
|
2007-10-06 04:17:58 +08:00
|
|
|
if (pcie_aer_disable)
|
|
|
|
return -ENXIO;
|
2007-02-27 17:22:00 +08:00
|
|
|
return pcie_port_service_register(&aerdriver);
|
2006-07-31 15:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aer_service_exit - unregister AER root service driver
|
|
|
|
*
|
|
|
|
* Invoked when AER root service driver is unloaded.
|
|
|
|
**/
|
|
|
|
static void __exit aer_service_exit(void)
|
|
|
|
{
|
2007-02-27 17:22:00 +08:00
|
|
|
pcie_port_service_unregister(&aerdriver);
|
2006-07-31 15:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(aer_service_init);
|
|
|
|
module_exit(aer_service_exit);
|