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/pci.h>
|
2011-01-07 07:55:09 +08:00
|
|
|
#include <linux/pci-acpi.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2006-07-31 15:21:33 +08:00
|
|
|
#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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
#include "aerdrv.h"
|
2008-06-05 01:39:07 +08:00
|
|
|
#include "../../pci.h"
|
2006-07-31 15:21:33 +08:00
|
|
|
|
2012-11-22 04:35:00 +08:00
|
|
|
static int aer_probe(struct pcie_device *dev);
|
2006-07-31 15:21:33 +08:00
|
|
|
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);
|
|
|
|
|
2012-09-08 00:33:14 +08:00
|
|
|
static const struct pci_error_handlers aer_error_handlers = {
|
2006-07-31 15:21:33 +08:00
|
|
|
.error_detected = aer_error_detected,
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 16:07:29 +08:00
|
|
|
.resume = aer_error_resume,
|
2006-07-31 15:21:33 +08:00
|
|
|
};
|
|
|
|
|
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",
|
2009-11-25 20:06:15 +08:00
|
|
|
.port_type = PCI_EXP_TYPE_ROOT_PORT,
|
2009-01-13 21:46:46 +08:00
|
|
|
.service = PCIE_PORT_SERVICE_AER,
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
.probe = aer_probe,
|
|
|
|
.remove = aer_remove,
|
|
|
|
|
|
|
|
.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)
|
|
|
|
{
|
2016-09-07 05:24:37 +08:00
|
|
|
pcie_aer_disable = 1;
|
2007-10-06 04:17:58 +08:00
|
|
|
}
|
|
|
|
|
2010-08-21 07:50:52 +08:00
|
|
|
bool pci_aer_available(void)
|
|
|
|
{
|
|
|
|
return !pcie_aer_disable && pci_msi_enabled();
|
|
|
|
}
|
|
|
|
|
2010-04-15 12:10:53 +08:00
|
|
|
static int set_device_error_reporting(struct pci_dev *dev, void *data)
|
|
|
|
{
|
|
|
|
bool enable = *((bool *)data);
|
2012-07-24 17:20:03 +08:00
|
|
|
int type = pci_pcie_type(dev);
|
2010-04-15 12:10:53 +08:00
|
|
|
|
2012-07-24 17:20:03 +08:00
|
|
|
if ((type == PCI_EXP_TYPE_ROOT_PORT) ||
|
|
|
|
(type == PCI_EXP_TYPE_UPSTREAM) ||
|
|
|
|
(type == PCI_EXP_TYPE_DOWNSTREAM)) {
|
2010-04-15 12:10:53 +08:00
|
|
|
if (enable)
|
|
|
|
pci_enable_pcie_error_reporting(dev);
|
|
|
|
else
|
|
|
|
pci_disable_pcie_error_reporting(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
pcie_set_ecrc_checking(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2012-07-24 17:20:11 +08:00
|
|
|
int aer_pos;
|
2010-04-15 12:10:53 +08:00
|
|
|
u16 reg16;
|
|
|
|
u32 reg32;
|
|
|
|
|
|
|
|
/* Clear PCIe Capability's Device Status */
|
2012-07-24 17:20:11 +08:00
|
|
|
pcie_capability_read_word(pdev, PCI_EXP_DEVSTA, ®16);
|
|
|
|
pcie_capability_write_word(pdev, PCI_EXP_DEVSTA, reg16);
|
2010-04-15 12:10:53 +08:00
|
|
|
|
|
|
|
/* Disable system error generation in response to error messages */
|
2012-07-24 17:20:11 +08:00
|
|
|
pcie_capability_clear_word(pdev, PCI_EXP_RTCTL,
|
|
|
|
SYSTEM_ERROR_INTR_ON_MESG_MASK);
|
2010-04-15 12:10:53 +08:00
|
|
|
|
2016-09-28 04:23:34 +08:00
|
|
|
aer_pos = pdev->aer_cap;
|
2010-04-15 12:10:53 +08:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2016-09-28 04:23:34 +08:00
|
|
|
pos = pdev->aer_cap;
|
2010-04-15 12:10:53 +08:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2009-04-24 10:45:23 +08:00
|
|
|
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;
|
|
|
|
|
2016-09-28 04:23:34 +08:00
|
|
|
pos = pdev->port->aer_cap;
|
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);
|
2010-04-15 12:18:26 +08:00
|
|
|
if (!(status & (PCI_ERR_ROOT_UNCOR_RCV|PCI_ERR_ROOT_COR_RCV))) {
|
2006-07-31 15:21:33 +08:00
|
|
|
spin_unlock_irqrestore(&rpc->e_lock, flags);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read error source and clear error status */
|
2010-04-15 12:17:33 +08:00
|
|
|
pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_ERR_SRC, &id);
|
2006-07-31 15:21:33 +08:00
|
|
|
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;
|
|
|
|
}
|
2009-04-24 10:45:23 +08:00
|
|
|
EXPORT_SYMBOL_GPL(aer_irq);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 16:07:29 +08:00
|
|
|
static struct aer_rpc *aer_alloc_rpc(struct pcie_device *dev)
|
2006-07-31 15:21:33 +08:00
|
|
|
{
|
|
|
|
struct aer_rpc *rpc;
|
|
|
|
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 16:07:29 +08:00
|
|
|
rpc = kzalloc(sizeof(struct aer_rpc), GFP_KERNEL);
|
|
|
|
if (!rpc)
|
2006-07-31 15:21:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
2010-04-15 12:22:11 +08:00
|
|
|
/* Initialize Root lock access, e_lock, to Root Error Status Reg */
|
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
|
|
|
mutex_init(&rpc->rpc_mutex);
|
|
|
|
|
2009-12-03 19:49:24 +08:00
|
|
|
/* Use PCIe bus function to store rpc into PCIe device */
|
2006-07-31 15:21:33 +08:00
|
|
|
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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2006-07-31 15:21:33 +08:00
|
|
|
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);
|
|
|
|
|
2016-01-26 00:08:00 +08:00
|
|
|
flush_work(&rpc->dpc_handler);
|
2010-04-15 12:10:03 +08:00
|
|
|
aer_disable_rootport(rpc);
|
|
|
|
kfree(rpc);
|
2006-07-31 15:21:33 +08:00
|
|
|
set_service_data(dev, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aer_probe - initialize resources
|
|
|
|
* @dev: pointer to the pcie_dev data structure
|
|
|
|
*
|
|
|
|
* Invoked when PCI Express bus loads AER service driver.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2012-11-22 04:35:00 +08:00
|
|
|
static int aer_probe(struct pcie_device *dev)
|
2006-07-31 15:21:33 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct aer_rpc *rpc;
|
2016-11-22 05:24:25 +08:00
|
|
|
struct device *device = &dev->port->dev;
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/* Alloc rpc data structure */
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 16:07:29 +08:00
|
|
|
rpc = aer_alloc_rpc(dev);
|
|
|
|
if (!rpc) {
|
2016-11-22 05:24:25 +08:00
|
|
|
dev_printk(KERN_DEBUG, device, "alloc AER rpc failed\n");
|
2006-07-31 15:21:33 +08:00
|
|
|
aer_remove(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request IRQ ISR */
|
PCI: pcie, aer: checkpatch style cleanup in pcie/aer/*
Before:
drivers/pci/pcie/aer/aer_inject.c
total: 4 errors, 4 warnings, 473 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 5 errors, 2 warnings, 333 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 1 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 4 errors, 3 warnings, 872 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 12 errors, 11 warnings, 248 lines checked
After:
drivers/pci/pcie/aer/aer_inject.c
total: 0 errors, 0 warnings, 466 lines checked
drivers/pci/pcie/aer/aerdrv.c
total: 0 errors, 0 warnings, 335 lines checked
drivers/pci/pcie/aer/aerdrv.h
total: 0 errors, 0 warnings, 139 lines checked
drivers/pci/pcie/aer/aerdrv_core.c
total: 0 errors, 0 warnings, 869 lines checked
drivers/pci/pcie/aer/aerdrv_errprint.c
total: 0 errors, 10 warnings, 247 lines checked
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Reviewed-by: Andrew Patterson <andrew.patterson@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2009-09-07 16:07:29 +08:00
|
|
|
status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", dev);
|
|
|
|
if (status) {
|
2016-11-22 05:24:25 +08:00
|
|
|
dev_printk(KERN_DEBUG, device, "request AER IRQ %d failed\n",
|
|
|
|
dev->irq);
|
2006-07-31 15:21:33 +08:00
|
|
|
aer_remove(dev);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc->isr = 1;
|
|
|
|
|
|
|
|
aer_enable_rootport(rpc);
|
2016-11-22 05:34:02 +08:00
|
|
|
dev_info(device, "AER enabled with IRQ %d\n", dev->irq);
|
|
|
|
return 0;
|
2006-07-31 15:21:33 +08: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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2006-07-31 15:21:33 +08:00
|
|
|
static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
|
|
|
|
{
|
2010-04-15 12:09:13 +08:00
|
|
|
u32 reg32;
|
2006-07-31 15:21:33 +08:00
|
|
|
int pos;
|
|
|
|
|
2016-09-28 04:23:34 +08:00
|
|
|
pos = dev->aer_cap;
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/* Disable Root's interrupt in response to error messages */
|
2010-04-15 12:09:13 +08:00
|
|
|
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);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
2013-08-09 04:10:20 +08:00
|
|
|
pci_reset_bridge_secondary_bus(dev);
|
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
|
|
|
|
2010-04-15 12:09:13 +08:00
|
|
|
/* 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);
|
|
|
|
|
2006-07-31 15:21:33 +08:00
|
|
|
/* Enable Root Port's interrupt in response to error messages */
|
2010-04-15 12:09:13 +08:00
|
|
|
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);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2006-07-31 15:21:33 +08:00
|
|
|
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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2006-07-31 15:21:33 +08:00
|
|
|
static void aer_error_resume(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
u32 status, mask;
|
|
|
|
u16 reg16;
|
|
|
|
|
|
|
|
/* Clean up Root device status */
|
2012-07-24 17:20:11 +08:00
|
|
|
pcie_capability_read_word(dev, PCI_EXP_DEVSTA, ®16);
|
|
|
|
pcie_capability_write_word(dev, PCI_EXP_DEVSTA, reg16);
|
2006-07-31 15:21:33 +08:00
|
|
|
|
|
|
|
/* Clean AER Root Error Status */
|
2016-09-28 04:23:34 +08:00
|
|
|
pos = dev->aer_cap;
|
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.
|
2010-04-15 12:22:11 +08:00
|
|
|
*/
|
2006-07-31 15:21:33 +08:00
|
|
|
static int __init aer_service_init(void)
|
|
|
|
{
|
2010-09-21 00:50:00 +08:00
|
|
|
if (!pci_aer_available() || aer_acpi_firmware_first())
|
2009-09-17 04:40:22 +08:00
|
|
|
return -ENXIO;
|
2007-02-27 17:22:00 +08:00
|
|
|
return pcie_port_service_register(&aerdriver);
|
2006-07-31 15:21:33 +08:00
|
|
|
}
|
2016-08-25 04:57:46 +08:00
|
|
|
device_initcall(aer_service_init);
|