PCI Express Advanced Error Reporting Driver
PATCH 4/6 PCI Express Advanced Error Reporting Driver
This patch includes the source code of Root callback-handle component of PCI Express Advanced Error Reporting driver.
Signed-off-by T. Long Nguyen <[email protected]>
--------------------------------------------------------------------
drivers/pci/pcie/aer/aerdrv_rpc_handle.c +96 -0
@@ -0,0 +1,96 @@ +/* +* Copyright (C) 2005 Intel +* Copyright (C) Tom Long Nguyen ([email protected]) +* +*/ +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/kernel.h> + +#include "aerdrv.h" + +static int aer_root_notify (unsigned short requestor_id,union aer_error *error); +static int aer_root_get_header (unsigned short requestor_id, +union aer_error *error,struct header_log_regs *log); + +/* AER callback handle data structure */ +struct pcie_aer_handle aer_root_handle = { + .notify = aer_root_notify, + .get_header = aer_root_get_header, +}; + +/** +* aer_root_notify - process an error being notified by AER Root driver +* @requestor_id: an identification +* @error: pointer to an error data structure +* +* Invoked when AER Root Port itself generates error messages. +**/ +static int aer_root_notify (unsigned short requestor_id,union aer_error *error) +{ +struct pci_dev *pdev =get_root_pci_dev (requestor_id); +int pos, retval = -EINVAL ; +u32 status; +u16 reg16; + +if (error->type ==AER_CORRECTABLE ) { +pci_read_config_dword (pdev, +CORRECTABLE_ERROR_STATUS_REG , &status); +if (status &ERR_CORRECTABLE_ERROR_MASK ) { +pci_write_config_dword (pdev, +CORRECTABLE_ERROR_STATUS_REG , status); + error->source.type =AER_CORRECTABLE ; + error->source.status = status; + retval =0 ; + } + }else { +pci_read_config_dword (pdev, +UNCORRECTABLE_ERROR_STATUS_REG , &status); +if (status &ERR_UNCORRECTABLE_ERROR_MASK ) { +u32 severity; + +pci_read_config_dword (pdev, +UNCORRECTABLE_ERROR_SEVERITY_REG , &severity); +pci_write_config_dword (pdev, +UNCORRECTABLE_ERROR_STATUS_REG , status); +if (status & severity) + error->source.type =AER_FATAL ; +else + error->source.type =AER_NONFATAL ; + error->source.status = status; + retval =0 ; + } + } + +/* Clean up Root device status */ + pos =pci_find_capability (pdev,PCI_CAP_ID_EXP ); +pci_read_config_word (pdev, pos +PCIE_CAP_DEVICE_STATUS_REG_OFF ,®16); +pci_write_config_word (pdev, pos +PCIE_CAP_DEVICE_STATUS_REG_OFF ,reg16); + +return retval; +} + +/** +* aer_root_get_header - provide TLP header +* @requestor_id: an identification +* @error: pointer to a TLP header data structure +* +* Invoked when AER Root Port logs the header of TLP associated with an error. +**/ +static int aer_root_get_header (unsigned short requestor_id, +union aer_error *error,struct header_log_regs *log) +{ +struct pci_dev *pdev =get_root_pci_dev (requestor_id); + +if (error->type ==AER_CORRECTABLE || + !(error->source.status &AER_LOG_TLP_MASKS )) +return AER_UNSUCCESS ; + +pci_read_config_dword (pdev,HEADER_LOG_REG , &log->dw0); +pci_read_config_dword (pdev,HEADER_LOG_REG +4 , &log->dw1); +pci_read_config_dword (pdev,HEADER_LOG_REG +8 , &log->dw2); +pci_read_config_dword (pdev,HEADER_LOG_REG +12 , &log->dw3); + +return AER_SUCCESS ; +} +