pcie_error.c revision 14a66e5a5df38a62990b14d0672ff8f6f55caa09
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Library file that has code for PCIe error handling
*/
#include <sys/sysmacros.h>
#include <sys/pci_impl.h>
#include <sys/pcie_impl.h>
extern uint32_t pcie_expected_ue_mask;
#ifdef DEBUG
#define PCIE_ERROR_DBG pcie_error_dbg
static void pcie_error_dbg(char *fmt, ...);
#else /* DEBUG */
#define PCIE_ERROR_DBG 0 &&
#endif /* DEBUG */
/* Variables to control error settings */
/* Device Command Register */
PCI_COMM_ME | \
PCI_COMM_MAE | \
/* PCI-Express Device Control Register */
#define PCIE_DEVCTL_ERR_ALL \
/* PCI-Express Root Control Register */
#define PCIE_ROOTCTL_SYS_ERR_ALL \
/* PCI-Express AER Root Error Command Register */
#define PCIE_AER_RE_CMD_ERR_ALL \
/*
* PCI-Express related masks (AER only)
* Can be defined to mask off certain types of AER errors
* By default all are set to 0; as no errors are masked
*/
uint32_t pcie_aer_ce_mask = 0;
/*
* PCI-Express related severity (AER only)
* Used to set the severity levels of errors detected by devices on the PCI
* Express fabric, which in turn results in either a fatal or nonfatal error
* message to the root complex. A set bit (1) indictates a fatal error, an
* unset one is nonfatal. For more information refer to the PCI Express Base
* default values are set below:
*/
/*
* By default, error handling is enabled
* Enable error handling flags. There are two flags
* pcie_error_disable_flag : disable AER, Baseline error handling, SERR
* default value = 0 (do not disable error handling)
* 1 (disable all error handling)
*
* pcie_serr_disable_flag : disable all error reporting via SERR for
* : PCIE root ports in the absence of AER
* default value = 0 (disable SERR)
* 1 (enable SERR)
*
* pcie_aer_disable_flag : disable AER only (simulates absent AER)
* default value = 0 (enable AER handling)
* 1 (disable AER bits)
*
* NOTE: pci_serr_disable_flag is a subset of pcie_error_disable_flag
* If pcie_error_disable_flag is set; then pcie_serr_disable_flag is ignored
* Above is also true for pcie_aer_disable_flag
*/
/*
* Function prototypes
*/
boolean_t *);
/*
* bridge interrupt handling
*/
/*
* the values for pcie_bridge_msi_flag must be ordered as follows
*
* PCIE_BRIDGE_INTR_DISABLE = disable all interrupts
* PCIE_BRIDGE_MSI_DISABLE = only use fixed interrupts
* PCIE_BRIDGE_MSI_ENABLE = use MSI for supported chipsets if hardware enabled
* PCIE_BRIDGE_MSI_ENABLE_ON = enable hardware MSI for supported chipsets
* PCIE_BRIDGE_MSI_ENABLE_ALL = use MSI for all chipsets
*/
#define PCIE_BRIDGE_INTR_DISABLE -1
#define PCIE_BRIDGE_MSI_DISABLE 0
#define PCIE_BRIDGE_MSI_ENABLE 1
#define PCIE_BRIDGE_MSI_ENABLE_ON 2
#define PCIE_BRIDGE_MSI_ENABLE_ALL 3
/* enable MSI for switches and other non-root-complex bridges */
int pcie_bridge_msi_nonrc_flag = 0;
/* enable bridge to interrupt when it recieves a PME message */
int pcie_bridge_enable_pme = 0;
/*
* modload support
*/
&mod_miscops, /* Type of module */
"PCI Express Error Support %I%"
};
struct modlinkage modlinkage = {
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini()
{
return (mod_remove(&modlinkage));
}
int
{
}
/*
* PCI-Express error initialization.
*/
/*
* Enable generic pci-express interrupts and error handling.
*/
int
{
/*
* flag to turn this off
*/
return (DDI_SUCCESS);
/* Determine the configuration header type */
PCIE_ERROR_DBG("%s: header_type=%x\n",
/* Look for PCIe capability */
if (aer_ptr != PCIE_EXT_CAP_NEXT_PTR_NULL)
"pcie-aer-pointer", aer_ptr);
}
/* Setup the device's command register */
/*
* when to disable SERR:
* - AER present (any PCIE device) to allow finer grained control
* - root port without AER and pcie_serr_disable_flag is set
*/
if (aer_ptr != PCIE_EXT_CAP_NEXT_PTR_NULL ||
/* Check io and mem ranges for empty bridges */
if (empty_io_range == B_TRUE) {
command_reg &= ~PCI_COMM_IO;
PCIE_ERROR_DBG("%s: No I/O range found\n",
}
if (empty_mem_range == B_TRUE) {
command_reg &= ~PCI_COMM_MAE;
PCIE_ERROR_DBG("%s: No Mem range found\n",
}
/*
* For PCI bridges:
* If the device has a bus control register then program it
* based on the settings in the command register.
*
* For PCIE bridges:
* Always enable PERR detection and SERR foward, unless:
* - root port without AER and pcie_serr_disable_flag is set
*/
if (cap_ptr != PCI_CAP_NEXT_PTR_NULL) {
if (dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT &&
bcr &= ~(PCI_BCNF_BCNTRL_PARITY_ENABLE |
} else {
}
} else {
if (command_reg & PCI_COMM_SERR_ENABLE)
}
/* Always clear Master Abort Mode bit */
}
/*
* Clear any pending errors
*/
/* No PCIe; just return */
if (cap_ptr == PCI_CAP_NEXT_PTR_NULL)
return (DDI_SUCCESS);
/*
* Enable PCI-Express Baseline Error Handling
*/
/*
* Disable UR for any non-RBER enabled leaf PCIe device,
* bridge or switch devices.
*/
if ((dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV ||
if (dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) {
/*
* without AER, disable UR for all child devices by
* changing the default ue mask (for AER devices) and the
* default device control value (for non-AER device).
*/
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL) {
}
}
PCIE_ERROR_DBG("%s: device control=0x%x\n",
/*
* Enable PCI-Express Advanced Error Handling if Exists
*/
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL)
return (DDI_SUCCESS);
if (dev_type == PCIE_PCIECAP_DEV_TYPE_UP ||
/* Set Uncorrectable error severity */
PCIE_ERROR_DBG("%s: AER UCE severity=0x%x->0x%x\n",
aer_ptr + PCIE_AER_UCE_SERV));
/* Enable Uncorrectable errors */
/* Enable Correctable errors */
/*
* Enable Secondary Uncorrectable errors if this is a bridge
*/
if (!(dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI))
return (DDI_SUCCESS);
/* Set Secondary Uncorrectable error severity */
PCIE_ERROR_DBG("%s: AER SUCE severity=0x%x->0x%x\n",
/*
* Enable secondary bus errors
*/
PCIE_ERROR_DBG("%s: AER SUCE mask=0x%x->0x%x\n",
return (DDI_SUCCESS);
}
static void
{
0xf0) << 8);
/*
* Assuming that a zero based io_range[0] implies an
* invalid I/O range. Likewise for mem_range[0].
*/
if (val == 0)
*empty_io_range = B_TRUE;
0xfff0) << 16);
if (val == 0)
}
}
/* ARGSUSED */
static void
{
/*
* if AER is present or pcie_serr_disable_flag is set,
* then disable SERR; otherwise allow it in the root control reg
*/
PCIE_ERROR_DBG("%s: PCIe Root Control Register=0x%x->0x%x\n",
/* Root Error Command Register */
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL)
return;
/* enable interrupt generation */
PCIE_ERROR_DBG("%s: PCIe AER Root Error Command "
/* Also enable ECRC checking */
if (rc_ctl & PCIE_AER_CTL_ECRC_GEN_CAP)
}
/*
* Disable generic pci-express interrupts and error handling.
*/
void
{
return;
/* Determine the configuration header type */
/*
* If the device has a bus control register then clear
* SERR, Master Abort and Parity detect
*/
if (cap_ptr != PCI_CAP_NEXT_PTR_NULL) {
bcr &= ~(PCI_BCNF_BCNTRL_PARITY_ENABLE |
} else {
if (command_reg & PCI_COMM_SERR_ENABLE)
}
}
/* Clear the device's command register */
if (cap_ptr == PCI_CAP_NEXT_PTR_NULL)
return;
/* Disable PCI-Express Baseline Error Handling */
"pcie-aer-pointer", PCIE_EXT_CAP_NEXT_PTR_NULL);
if (dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT)
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL)
return;
/* Disable AER bits */
/* Disable Uncorrectable errors */
/* Disable Correctable errors */
/* Disable Secondary Uncorrectable errors if this is a bridge */
if (!(dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI))
return;
}
static void
{
/* Root Error Command Register */
if (aer_ptr != PCIE_EXT_CAP_NEXT_PTR_NULL) {
/* Disable ECRC checking */
if (rc_ctl & PCIE_AER_CTL_ECRC_GEN_CAP)
}
}
/*
* Clear any pending errors
*/
static void
{
/* 1. clear the Advanced PCIe Errors */
}
/* 2. clear the PCIe Errors */
if (cap_ptr) {
}
/* 3. clear the Legacy PCI Errors */
if (dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI) {
}
}
/*
* Helper Function to traverse the pci-express config space looking
* for the pci-express capability id pointer.
*/
static uint16_t
{
/*
* Check if capabilities list is supported. If not then it is a PCI
* device.
*/
return (PCI_CAP_NEXT_PTR_NULL);
break;
} else if (cap == 0xff)
return (PCI_CAP_NEXT_PTR_NULL);
}
return (caps_ptr);
}
/*
* Helper Function to traverse the pci-express extended config space looking
* for the pci-express capability id pointer.
*/
static uint16_t
{
while ((hdr_next_ptr != PCIE_EXT_CAP_NEXT_PTR_NULL) &&
(hdr_cap_id != PCIE_EXT_CAP_ID_AER)) {
}
if (hdr_cap_id == PCIE_EXT_CAP_ID_AER)
return (PCIE_EXT_CAP_NEXT_PTR_NULL);
}
/*
* Determine interrupt type support for this bridge and configure bridge
* to support the returned interrupt type, if any configuration is required
*/
int
{
int itype;
/*
* General interrupt type support
*/
return (DDI_FAILURE);
return (DDI_FAILURE);
if (itype & DDI_INTR_TYPE_MSI) {
/*
* Allow MSIs for root ports and non-root-ports if their
* corresponding flags are set
*/
if ((port_type == PCIE_PCIECAP_DEV_TYPE_ROOT &&
pcie_bridge_msi_nonrc_flag > 0)) {
} else
}
if (itype == DDI_INTR_TYPE_FIXED)
goto DONE;
/*
* Non-root-complex bridge interrupt type support:
* Assume that nothing special needs to be done
*/
if (port_type != PCIE_PCIECAP_DEV_TYPE_ROOT)
goto DONE;
/*
* Chipset interrupt type support:
* MSIs need further evaluation because it turns out that even if
* the bridge reports MSI capability, there can be chipset specific
* settings that control how interrupts will be delivered for certain
* interrupt sources.
*/
/*
* Intel 5000 series
*/
goto DONE;
}
/*
* Intel 7300
*/
pexctrl |=
pexctrl);
pexctrl3);
/* paranoia: verify */
}
if ((pexctrl &
goto DONE;
}
/*
* Allow MSI for Nvidia chipsets except for:
* CK804 or IO4 (same devids as CK804) with rev below A3
*/
goto DONE;
}
goto DONE;
}
DONE:
if (port_type == PCIE_PCIECAP_DEV_TYPE_ROOT &&
return (DDI_SUCCESS);
}
/*
* Note: only valid on root ports
*/
void
{
}
void
{
}
void
{
return;
if (pcie_loc == 0)
return;
}
/*
* re-initialize bridge after a resume
*/
int
{
int ret = DDI_SUCCESS;
PCIE_ERROR_DBG("%s%d: intr type reinitialization failed\n",
ret = DDI_FAILURE;
goto OUT;
}
OUT:
return (ret);
}
/*
* Initialize interrupts; returns:
* - DDI_SUCCESS on success
* - DDI_ENOTSUP if interrupts are not supported for this bridge
* - DDI_FAILURE if interrupts are supported but failed initialization
*/
int
{
int aer_loc;
int pcie_loc;
int inband_hpc;
int port_type;
int *isrc_tab;
int retry = 0;
if (pcie_bridge_msi_flag == PCIE_BRIDGE_INTR_DISABLE) {
}
/*
* Get cap locations and other relevant PCIE info
*/
DDI_PROP_DONTPASS, "pcie-capid-pointer", 0);
DDI_PROP_DONTPASS, "pcie-aer-pointer", 0);
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/*
* We only support fixed and MSI interrupts on bridges that are
* hotpluggable or root ports with AER
*/
if ((port_type != PCIE_PCIECAP_DEV_TYPE_ROOT &&
inband_hpc != INBAND_HPC_PCIE) ||
return (DDI_ENOTSUP);
return (DDI_FAILURE);
}
if (itype == DDI_INTR_TYPE_FIXED) {
PCIE_ERROR_DBG("%s%d: invalid IPIN for fixed intr\n",
return (DDI_FAILURE);
}
}
/*
* Get the max number of intrs requested and allocate handler
* table for that amount
*/
PCIE_ERROR_DBG("%s%d: ddi_intr_get_nintrs() "
return (DDI_FAILURE);
}
/*
* If the bridge wants more than one (MSI), but we cannot allocate
* exactly that much, we fall back to using only one. If we cannot
* get any MSI then we fall back to using fixed intrs. However,
* for Nvidia bridges, if we cannot get the exact requested amount
* of MSIs, we must use fixed intrs due to some chipset limitations
* (MCP55 errata and potentially other NV chipsets).
*/
PCIE_ERROR_DBG("%s%d: retrying allocation for NVIDIA "
retry = 1;
goto RETRY;
} else {
PCIE_ERROR_DBG("%s%d: retrying allocation with "
}
}
PCIE_ERROR_DBG("%s%d: retrying allocation with "
retry = 1;
goto RETRY;
}
if (rv != DDI_SUCCESS) {
PCIE_ERROR_DBG("%s%d: could not allocate interrupts\n",
goto FAIL;
}
PCIE_ERROR_DBG("%s%d: bridge supports %d intrs; allocated %d "
/*
* There are 3 possible interrupt sources we recognize:
* - hotplug (PCIE cap)
* - power (PCIE cap; root port)
* - error (AER cap; root port)
* Note that error interrupts only apply to root ports with AER.
* Non-root port devices with or without AER will report errors by
* sending error messages to the root port which will interrupt on
* their behalf. We report this to FMA who determines which
* device originated the error by checking the error logs in the
* root port AER cap. FMA can then check the originating device's
* error status registers and invoke its driver's error handler if
* registered.
*/
/*
* hotplug and PME interrupts
* both share the same vector
*/
if (pcie_loc != 0) {
inum = 0;
if (itype == DDI_INTR_TYPE_MSI) {
pcie_loc + PCIE_PCIECAP);
if (inum == 0xffff) {
PCIE_ERROR_DBG("%s%d: invalid PCIE cap "
goto FAIL;
}
PCIE_ERROR_DBG("%s%d: MSI number %d in "
"PCIE cap > max allocated\n",
goto FAIL;
}
}
if (inband_hpc == INBAND_HPC_PCIE) {
PCIE_ERROR_DBG("%s%d: HP intr on inum %d\n",
}
/*
* PME interrupts should always remained disabled and
* only enabled after we add our interrupt handler, if we
* decide to support it. PMEs pending while it is disabled
* will trigger an interrupt when enabled.
*
* Note that PMEs could be delivered either through ACPI or
* directly via the bridge interrupt on some platforms, so
* a method of determining which mode to use is required
* before supporting PCIE PME in general, much like
* determining PCIE hotplug mode (native vs acpi).
*/
if (port_type == PCIE_PCIECAP_DEV_TYPE_ROOT) {
if (pcie_bridge_enable_pme) {
PCIE_ERROR_DBG("%s%d: PME intr on inum %d\n",
}
}
}
/*
* error reporting interrupts
*/
if (aer_loc != 0 &&
inum = 0;
if (itype == DDI_INTR_TYPE_MSI) {
if (inum == 0xffffffff) {
PCIE_ERROR_DBG("%s%d: invalid "
"root error status register in AER cap\n",
goto FAIL;
}
PCIE_ERROR_DBG("%s%d: MSI number %d in "
"AER cap > max allocated\n",
goto FAIL;
}
}
PCIE_ERROR_DBG("%s%d: AER intr on inum %d\n",
}
/*
* Add handler using second arg to identify which interrupt
*/
for (i = 0; i < igot; i++) {
if (rv != DDI_SUCCESS) {
PCIE_ERROR_DBG("%s%d: ddi_intr_add_handler() "
break;
}
PCIE_ERROR_DBG("%s%d: isrc_tab[%d] = 0x%x\n",
}
if (rv != DDI_SUCCESS) {
while (--i >= 0)
goto FAIL;
}
/*
* Get interrupt priority and initialize mutex
*/
DDI_SUCCESS) {
PCIE_ERROR_DBG("%s%d: ddi_intr_get_pri() failed\n",
goto FAIL;
}
/*
* Enable interrupts
*/
PCIE_ERROR_DBG("%s%d: ddi_intr_get_cap() failed\n",
goto FAIL;
}
if (icap & DDI_INTR_FLAG_BLOCK) {
DDI_SUCCESS) {
PCIE_ERROR_DBG("%s%d: ddi_intr_block_enable() failed\n",
goto FAIL;
}
} else {
for (i = 0; i < igot; i++) {
DDI_SUCCESS) {
PCIE_ERROR_DBG("%s%d: ddi_intr_enable() "
goto FAIL;
}
}
}
/*
* Post interrupt enabled work; enable interrupt sources
* - PME; see NOTE above regarding PMEs
*/
if (pcie_bridge_enable_pme && pcie_loc != 0 &&
}
return (DDI_SUCCESS);
/*NOTREACHED*/
FAIL:
return (DDI_FAILURE);
}
void
{
int x;
return;
if ((flags & PCIE_BRIDGE_INTR_INIT_ENABLE) &&
(flags & PCIE_BRIDGE_INTR_INIT_BLOCK)) {
}
if (flags & PCIE_BRIDGE_INTR_INIT_MUTEX)
for (x = 0; x < count; x++) {
if (flags & PCIE_BRIDGE_INTR_INIT_ALLOC)
}
}
int
{
int pcie_loc;
DDI_PROP_DONTPASS, "pcie-capid-pointer", 0);
return (1);
}
return (0);
}
#ifdef DEBUG
static void
pcie_error_dbg(char *fmt, ...)
{
if (!pcie_error_debug_flags)
return;
}
#endif /* DEBUG */