pcie_error.c revision 70025d765b044c6d8594bb965a2247a61e991a99
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 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/sysmacros.h>
#include <sys/pcie_impl.h>
#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 */
/* PCI-Express AER Root Control Register */
/* PCI-Express Root Error Command Register */
/*
* 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
*/
/*
* 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 SERR only (in RCR and command reg)
* default value = 1 (disable SERR bits)
* 0 (enable SERR handling)
*
* pcie_aer_disable_flag : disable AER only
* default value = 1 (disable AER bits)
* 0 (enable AER handling)
*
* 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
*/
/*
* PCI-Express error initialization.
*/
int
{
/*
* flag to turn this off
*/
return (DDI_SUCCESS);
return (DDI_FAILURE);
/* Determine the configuration header type */
PCIE_ERROR_DBG("%s: header_type=%x\n",
/* Setup the device's command register */
if (pcie_serr_disable_flag) {
/* shouldn't happen; just in case */
if (command_reg & PCI_COMM_SERR_ENABLE)
}
/*
* If the device has a bus control register then program it
* based on the settings in the command register.
*/
if (pcie_command_default & PCI_COMM_SERR_ENABLE) {
else
}
}
/* Look for PCIe capability */
}
/*
* Clear any pending errors
*/
/* No PCIe; just return */
if (cap_ptr == PCI_CAP_NEXT_PTR_NULL)
goto cleanup;
/*
*/
/*
* Enable PCI-Express Baseline Error Handling
*
* NOTE: Unsupported Request related errors are not enabled
* If these are enabled; then as SERR is already set the
* Programs that scan PCI configuration space can easily
* generate URs as they scan entire BDFs..
*/
PCIE_ERROR_DBG("%s: device control=0x%x->0x%x\n",
/*
* Enable PCI-Express Advanced Error Handling if Exists
*/
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL)
goto cleanup;
goto cleanup;
/* Enable Uncorrectable errors */
/* Enable Correctable errors */
/*
* Enable Secondary Uncorrectable errors if this is a bridge
*/
if (!(dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI))
goto cleanup;
/*
* Enable secondary bus errors
*/
PCIE_ERROR_DBG("%s: AER SUCE=0x%x->0x%x\n",
return (DDI_SUCCESS);
}
static void
{
if (!pcie_serr_disable_flag) {
PCIE_ERROR_DBG("%s: PCIe Root Control Register=0x%x->0x%x\n",
}
/* Root Error Command Register */
if (!pcie_aer_disable_flag)
PCIE_ERROR_DBG("%s: PCIe AER RootError Command Register=0x%x->0x%x\n",
}
/*
* PCI-Express CK8-04 child device de-initialization.
* This function disables generic pci-express interrupts and error handling.
*/
void
{
return;
return;
/* Determine the configuration header type */
/* Clear the device's command register (SERR and PARITY detect) */
/*
* If the device has a bus control register then clear
* SERR, Master Abort and Parity detect
*/
if ((pcie_command_default & PCI_COMM_SERR_ENABLE) ||
}
if (cap_ptr == PCI_CAP_NEXT_PTR_NULL) {
return;
}
/* Disable PCI-Express Baseline Error Handling */
/*
*/
if (aer_ptr == PCIE_EXT_CAP_NEXT_PTR_NULL) {
return;
}
/* Disable AER bits */
if (!pcie_aer_disable_flag)
/* Disable Uncorrectable errors */
if (!pcie_aer_disable_flag)
/* Disable Correctable errors */
if (!pcie_aer_disable_flag)
/* Disable Secondary Uncorrectable errors if this is a bridge */
if (!pcie_aer_disable_flag) {
if (!(dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)) {
return;
}
/* Disable secondary bus errors */
}
}
static void
{
if (!pcie_serr_disable_flag) {
}
/* Root Error Command Register */
if (!pcie_aer_disable_flag)
}
/*
* Clear any pending errors
*/
static void
{
/* 1. clear the Advanced PCIe Errors */
if (aer_ptr != PCIE_EXT_CAP_NEXT_PTR_NULL) {
if (dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI) {
}
}
/* 2. clear the PCIe Errors */
/* 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);
while (caps_ptr != PCI_CAP_NEXT_PTR_NULL) {
if (caps_ptr < PCI_CAP_PTR_OFF)
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 != cap_id)) {
}
if (hdr_cap_id == cap_id)
return (PCIE_EXT_CAP_NEXT_PTR_NULL);
}
#ifdef DEBUG
static void
pcie_error_dbg(char *fmt, ...)
{
if (!pcie_error_debug_flags)
return;
}
#endif /* DEBUG */