⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aerdrv_core.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * drivers/pci/pcie/aer/aerdrv_core.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 core part of PCI-Express AER. When an pci-express * error is delivered, an error message will be collected and printed to * console, then, an error recovery procedure will be executed by following * the pci error recovery rules. * * 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/suspend.h>#include <linux/delay.h>#include "aerdrv.h"static int forceload;module_param(forceload, bool, 0);#define PCI_CFG_SPACE_SIZE	(0x100)int pci_find_aer_capability(struct pci_dev *dev){	int pos;	u32 reg32 = 0;	/* Check if it's a pci-express device */	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);	if (!pos)		return 0;	/* Check if it supports pci-express AER */	pos = PCI_CFG_SPACE_SIZE;	while (pos) {		if (pci_read_config_dword(dev, pos, &reg32))			return 0;		/* some broken boards return ~0 */		if (reg32 == 0xffffffff)			return 0;		if (PCI_EXT_CAP_ID(reg32) == PCI_EXT_CAP_ID_ERR)			break;		pos = reg32 >> 20;	}	return pos;}int pci_enable_pcie_error_reporting(struct pci_dev *dev){	u16 reg16 = 0;	int pos;	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);	if (!pos)		return -EIO;	pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);	reg16 = reg16 |		PCI_EXP_DEVCTL_CERE |		PCI_EXP_DEVCTL_NFERE |		PCI_EXP_DEVCTL_FERE |		PCI_EXP_DEVCTL_URRE;	pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,			reg16);	return 0;}int pci_disable_pcie_error_reporting(struct pci_dev *dev){	u16 reg16 = 0;	int pos;	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);	if (!pos)		return -EIO;	pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);	reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |			PCI_EXP_DEVCTL_NFERE |			PCI_EXP_DEVCTL_FERE |			PCI_EXP_DEVCTL_URRE);	pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,			reg16);	return 0;}int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev){	int pos;	u32 status, mask;	pos = pci_find_aer_capability(dev);	if (!pos)		return -EIO;	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);	return 0;}int pci_cleanup_aer_correct_error_status(struct pci_dev *dev){	int pos;	u32 status;	pos = pci_find_aer_capability(dev);	if (!pos)		return -EIO;	pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);	pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status);	return 0;}static int find_device_iter(struct device *device, void *data){	struct pci_dev *dev;	u16 id = *(unsigned long *)data;	u8 secondary, subordinate, d_bus = id >> 8;	if (device->bus == &pci_bus_type) {		dev = to_pci_dev(device);		if (id == ((dev->bus->number << 8) | dev->devfn)) {			/*			 * Device ID match			 */			*(unsigned long*)data = (unsigned long)device;			return 1;		}		/*		 * If device is P2P, check if it is an upstream?		 */		if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {			pci_read_config_byte(dev, PCI_SECONDARY_BUS,				&secondary);			pci_read_config_byte(dev, PCI_SUBORDINATE_BUS,				&subordinate);			if (d_bus >= secondary && d_bus <= subordinate) {				*(unsigned long*)data = (unsigned long)device;				return 1;			}		}	}	return 0;}/** * find_source_device - search through device hierarchy for source device * @parent: pointer to Root Port pci_dev data structure * @id: device ID of agent who sends an error message to this Root Port * * Invoked when error is detected at the Root Port. */static struct device* find_source_device(struct pci_dev *parent, u16 id){	struct pci_dev *dev = parent;	struct device *device;	unsigned long device_addr;	int status;	/* Is Root Port an agent that sends error message? */	if (id == ((dev->bus->number << 8) | dev->devfn))		return &dev->dev;	do {		device_addr = id; 		if ((status = device_for_each_child(&dev->dev,			&device_addr, find_device_iter))) {			device = (struct device*)device_addr;			dev = to_pci_dev(device);			if (id == ((dev->bus->number << 8) | dev->devfn))				return device;		} 	}while (status);	return NULL;}static void report_error_detected(struct pci_dev *dev, void *data){	pci_ers_result_t vote;	struct pci_error_handlers *err_handler;	struct aer_broadcast_data *result_data;	result_data = (struct aer_broadcast_data *) data;	dev->error_state = result_data->state;	if (!dev->driver ||		!dev->driver->err_handler ||		!dev->driver->err_handler->error_detected) {		if (result_data->state == pci_channel_io_frozen &&			!(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) {			/*			 * In case of fatal recovery, if one of down-			 * stream device has no driver. We might be			 * unable to recover because a later insmod			 * of a driver for this device is unaware of			 * its hw state.			 */			printk(KERN_DEBUG "Device ID[%s] has %s\n",					dev->dev.bus_id, (dev->driver) ?					"no AER-aware driver" : "no driver");		}		return;	}	err_handler = dev->driver->err_handler;	vote = err_handler->error_detected(dev, result_data->state);	result_data->result = merge_result(result_data->result, vote);	return;}static void report_mmio_enabled(struct pci_dev *dev, void *data){	pci_ers_result_t vote;	struct pci_error_handlers *err_handler;	struct aer_broadcast_data *result_data;	result_data = (struct aer_broadcast_data *) data;	if (!dev->driver ||		!dev->driver->err_handler ||		!dev->driver->err_handler->mmio_enabled)		return;	err_handler = dev->driver->err_handler;	vote = err_handler->mmio_enabled(dev);	result_data->result = merge_result(result_data->result, vote);	return;}static void report_slot_reset(struct pci_dev *dev, void *data){	pci_ers_result_t vote;	struct pci_error_handlers *err_handler;	struct aer_broadcast_data *result_data;	result_data = (struct aer_broadcast_data *) data;	if (!dev->driver ||		!dev->driver->err_handler ||		!dev->driver->err_handler->slot_reset)		return;	err_handler = dev->driver->err_handler;	vote = err_handler->slot_reset(dev);	result_data->result = merge_result(result_data->result, vote);	return;}static void report_resume(struct pci_dev *dev, void *data){	struct pci_error_handlers *err_handler;	dev->error_state = pci_channel_io_normal;	if (!dev->driver ||		!dev->driver->err_handler ||		!dev->driver->err_handler->slot_reset)		return;	err_handler = dev->driver->err_handler;	err_handler->resume(dev);	return;}/** * broadcast_error_message - handle message broadcast to downstream drivers * @dev: pointer to from where in a hierarchy message is broadcasted down * @state: error state * @error_mesg: message to print * @cb: callback to be broadcasted * * Invoked during error recovery process. Once being invoked, the content * of error severity will be broadcasted to all downstream drivers in a * hierarchy in question. */static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,	enum pci_channel_state state,	char *error_mesg,	void (*cb)(struct pci_dev *, void *)){	struct aer_broadcast_data result_data;	printk(KERN_DEBUG "Broadcast %s message\n", error_mesg);	result_data.state = state;	if (cb == report_error_detected)		result_data.result = PCI_ERS_RESULT_CAN_RECOVER;	else		result_data.result = PCI_ERS_RESULT_RECOVERED;	if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {		/*		 * If the error is reported by a bridge, we think this error		 * is related to the downstream link of the bridge, so we		 * do error recovery on all subordinates of the bridge instead		 * of the bridge and clear the error status of the bridge.		 */		if (cb == report_error_detected)			dev->error_state = state;		pci_walk_bus(dev->subordinate, cb, &result_data);		if (cb == report_resume) {			pci_cleanup_aer_uncorrect_error_status(dev);			dev->error_state = pci_channel_io_normal;		}	}	else {		/*		 * If the error is reported by an end point, we think this		 * error is related to the upstream link of the end point.		 */		pci_walk_bus(dev->bus, cb, &result_data);	}	return result_data.result;}struct find_aer_service_data {	struct pcie_port_service_driver *aer_driver;	int is_downstream;};static int find_aer_service_iter(struct device *device, void *data){	struct device_driver *driver;	struct pcie_port_service_driver *service_driver;	struct pcie_device *pcie_dev;	struct find_aer_service_data *result;	result = (struct find_aer_service_data *) data;	if (device->bus == &pcie_port_bus_type) {		pcie_dev = to_pcie_device(device);		if (pcie_dev->id.port_type == PCIE_SW_DOWNSTREAM_PORT)			result->is_downstream = 1;		driver = device->driver;		if (driver) {			service_driver = to_service_driver(driver);			if (service_driver->id_table->service_type ==					PCIE_PORT_SERVICE_AER) {				result->aer_driver = service_driver;				return 1;			}		}	}	return 0;}static void find_aer_service(struct pci_dev *dev,		struct find_aer_service_data *data){	int retval;	retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);}static pci_ers_result_t reset_link(struct pcie_device *aerdev,		struct pci_dev *dev){	struct pci_dev *udev;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -