ia64/linux-2.6.18-xen.hg

changeset 734:df84c4c22a0a

PCI-Express AER implemetation: pcie_portdrv error handler.

Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Nov 24 11:02:43 2008 +0000 (2008-11-24)
parents 30524c484bbb
children 5888ffa4b252
files drivers/pci/pcie/portdrv_pci.c
line diff
     1.1 --- a/drivers/pci/pcie/portdrv_pci.c	Mon Nov 24 11:02:14 2008 +0000
     1.2 +++ b/drivers/pci/pcie/portdrv_pci.c	Mon Nov 24 11:02:43 2008 +0000
     1.3 @@ -14,8 +14,10 @@
     1.4  #include <linux/init.h>
     1.5  #include <linux/slab.h>
     1.6  #include <linux/pcieport_if.h>
     1.7 +#include <linux/aer.h>
     1.8  
     1.9  #include "portdrv.h"
    1.10 +#include "aer/aerdrv.h"
    1.11  
    1.12  /*
    1.13   * Version Information
    1.14 @@ -30,6 +32,43 @@ MODULE_LICENSE("GPL");
    1.15  /* global data */
    1.16  static const char device_name[] = "pcieport-driver";
    1.17  
    1.18 +static int pcie_portdrv_save_config(struct pci_dev *dev)
    1.19 +{
    1.20 +	return pci_save_state(dev);
    1.21 +}
    1.22 +
    1.23 +#ifdef CONFIG_PM
    1.24 +static int pcie_portdrv_restore_config(struct pci_dev *dev)
    1.25 +{
    1.26 +	int retval;
    1.27 +
    1.28 +	pci_restore_state(dev);
    1.29 +	retval = pci_enable_device(dev);
    1.30 +	if (retval)
    1.31 +		return retval;
    1.32 +	pci_set_master(dev);
    1.33 +	return 0;
    1.34 +}
    1.35 +
    1.36 +static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state)
    1.37 +{
    1.38 +	int ret = pcie_port_device_suspend(dev, state);
    1.39 +
    1.40 +	if (!ret)
    1.41 +		ret = pcie_portdrv_save_config(dev);
    1.42 +	return ret;
    1.43 +}
    1.44 +
    1.45 +static int pcie_portdrv_resume(struct pci_dev *dev)
    1.46 +{
    1.47 +	pcie_portdrv_restore_config(dev);
    1.48 +	return pcie_port_device_resume(dev);
    1.49 +}
    1.50 +#else
    1.51 +#define pcie_portdrv_suspend NULL
    1.52 +#define pcie_portdrv_resume NULL
    1.53 +#endif
    1.54 +
    1.55  /*
    1.56   * pcie_portdrv_probe - Probe PCI-Express port devices
    1.57   * @dev: PCI-Express port device being probed
    1.58 @@ -61,6 +100,10 @@ static int __devinit pcie_portdrv_probe 
    1.59  		return -ENOMEM;
    1.60  	}
    1.61  
    1.62 +	pcie_portdrv_save_config(dev);
    1.63 +
    1.64 +	pci_enable_pcie_error_reporting(dev);
    1.65 +
    1.66  	return 0;
    1.67  }
    1.68  
    1.69 @@ -70,39 +113,143 @@ static void pcie_portdrv_remove (struct 
    1.70  	kfree(pci_get_drvdata(dev));
    1.71  }
    1.72  
    1.73 -#ifdef CONFIG_PM
    1.74 -static int pcie_portdrv_save_config(struct pci_dev *dev)
    1.75 +static int error_detected_iter(struct device *device, void *data)
    1.76  {
    1.77 -	return pci_save_state(dev);
    1.78 -}
    1.79 +	struct pcie_device *pcie_device;
    1.80 +	struct pcie_port_service_driver *driver;
    1.81 +	struct aer_broadcast_data *result_data;
    1.82 +	pci_ers_result_t status;
    1.83  
    1.84 -static int pcie_portdrv_restore_config(struct pci_dev *dev)
    1.85 -{
    1.86 -	int retval;
    1.87 +	result_data = (struct aer_broadcast_data *) data;
    1.88  
    1.89 -	pci_restore_state(dev);
    1.90 -	retval = pci_enable_device(dev);
    1.91 -	if (retval)
    1.92 -		return retval;
    1.93 -	pci_set_master(dev);
    1.94 +	if (device->bus == &pcie_port_bus_type && device->driver) {
    1.95 +		driver = to_service_driver(device->driver);
    1.96 +		if (!driver ||
    1.97 +			!driver->err_handler ||
    1.98 +			!driver->err_handler->error_detected)
    1.99 +			return 0;
   1.100 +
   1.101 +		pcie_device = to_pcie_device(device);
   1.102 +
   1.103 +		/* Forward error detected message to service drivers */
   1.104 +		status = driver->err_handler->error_detected(
   1.105 +			pcie_device->port,
   1.106 +			result_data->state);
   1.107 +		result_data->result =
   1.108 +			merge_result(result_data->result, status);
   1.109 +	}
   1.110 +
   1.111  	return 0;
   1.112  }
   1.113  
   1.114 -static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
   1.115 +static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
   1.116 +					enum pci_channel_state error)
   1.117  {
   1.118 -	int ret = pcie_port_device_suspend(dev, state);
   1.119 +	struct aer_broadcast_data result_data =
   1.120 +			{error, PCI_ERS_RESULT_CAN_RECOVER};
   1.121  
   1.122 -	if (!ret)
   1.123 -		ret = pcie_portdrv_save_config(dev);
   1.124 -	return ret;
   1.125 +	device_for_each_child(&dev->dev, &result_data, error_detected_iter);
   1.126 +
   1.127 +	return result_data.result;
   1.128  }
   1.129  
   1.130 -static int pcie_portdrv_resume (struct pci_dev *dev)
   1.131 +static int mmio_enabled_iter(struct device *device, void *data)
   1.132  {
   1.133 -	pcie_portdrv_restore_config(dev);
   1.134 -	return pcie_port_device_resume(dev);
   1.135 +	struct pcie_device *pcie_device;
   1.136 +	struct pcie_port_service_driver *driver;
   1.137 +	pci_ers_result_t status, *result;
   1.138 +
   1.139 +	result = (pci_ers_result_t *) data;
   1.140 +
   1.141 +	if (device->bus == &pcie_port_bus_type && device->driver) {
   1.142 +		driver = to_service_driver(device->driver);
   1.143 +		if (driver &&
   1.144 +			driver->err_handler &&
   1.145 +			driver->err_handler->mmio_enabled) {
   1.146 +			pcie_device = to_pcie_device(device);
   1.147 +
   1.148 +			/* Forward error message to service drivers */
   1.149 +			status = driver->err_handler->mmio_enabled(
   1.150 +					pcie_device->port);
   1.151 +			*result = merge_result(*result, status);
   1.152 +		}
   1.153 +	}
   1.154 +
   1.155 +	return 0;
   1.156  }
   1.157 -#endif
   1.158 +
   1.159 +static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
   1.160 +{
   1.161 +	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
   1.162 +
   1.163 +	device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
   1.164 +	return status;
   1.165 +}
   1.166 +
   1.167 +static int slot_reset_iter(struct device *device, void *data)
   1.168 +{
   1.169 +	struct pcie_device *pcie_device;
   1.170 +	struct pcie_port_service_driver *driver;
   1.171 +	pci_ers_result_t status, *result;
   1.172 +
   1.173 +	result = (pci_ers_result_t *) data;
   1.174 +
   1.175 +	if (device->bus == &pcie_port_bus_type && device->driver) {
   1.176 +		driver = to_service_driver(device->driver);
   1.177 +		if (driver &&
   1.178 +			driver->err_handler &&
   1.179 +			driver->err_handler->slot_reset) {
   1.180 +			pcie_device = to_pcie_device(device);
   1.181 +
   1.182 +			/* Forward error message to service drivers */
   1.183 +			status = driver->err_handler->slot_reset(
   1.184 +					pcie_device->port);
   1.185 +			*result = merge_result(*result, status);
   1.186 +		}
   1.187 +	}
   1.188 +
   1.189 +	return 0;
   1.190 +}
   1.191 +
   1.192 +static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
   1.193 +{
   1.194 +	pci_ers_result_t status;
   1.195 +
   1.196 +	/* If fatal, restore cfg space for possible link reset at upstream */
   1.197 +	if (dev->error_state == pci_channel_io_frozen) {
   1.198 +		pcie_portdrv_restore_config(dev);
   1.199 +		pci_enable_pcie_error_reporting(dev);
   1.200 +	}
   1.201 +
   1.202 +	device_for_each_child(&dev->dev, &status, slot_reset_iter);
   1.203 +
   1.204 +	return status;
   1.205 +}
   1.206 +
   1.207 +static int resume_iter(struct device *device, void *data)
   1.208 +{
   1.209 +	struct pcie_device *pcie_device;
   1.210 +	struct pcie_port_service_driver *driver;
   1.211 +
   1.212 +	if (device->bus == &pcie_port_bus_type && device->driver) {
   1.213 +		driver = to_service_driver(device->driver);
   1.214 +		if (driver &&
   1.215 +			driver->err_handler &&
   1.216 +			driver->err_handler->resume) {
   1.217 +			pcie_device = to_pcie_device(device);
   1.218 +
   1.219 +			/* Forward error message to service drivers */
   1.220 +			driver->err_handler->resume(pcie_device->port);
   1.221 +		}
   1.222 +	}
   1.223 +
   1.224 +	return 0;
   1.225 +}
   1.226 +
   1.227 +static void pcie_portdrv_err_resume(struct pci_dev *dev)
   1.228 +{
   1.229 +	device_for_each_child(&dev->dev, NULL, resume_iter);
   1.230 +}
   1.231  
   1.232  /*
   1.233   * LINUX Device Driver Model
   1.234 @@ -114,6 +261,13 @@ static const struct pci_device_id port_p
   1.235  };
   1.236  MODULE_DEVICE_TABLE(pci, port_pci_ids);
   1.237  
   1.238 +static struct pci_error_handlers pcie_portdrv_err_handler = {
   1.239 +		.error_detected = pcie_portdrv_error_detected,
   1.240 +		.mmio_enabled = pcie_portdrv_mmio_enabled,
   1.241 +		.slot_reset = pcie_portdrv_slot_reset,
   1.242 +		.resume = pcie_portdrv_err_resume,
   1.243 +};
   1.244 +
   1.245  static struct pci_driver pcie_portdrv = {
   1.246  	.name		= (char *)device_name,
   1.247  	.id_table	= &port_pci_ids[0],
   1.248 @@ -121,10 +275,10 @@ static struct pci_driver pcie_portdrv = 
   1.249  	.probe		= pcie_portdrv_probe,
   1.250  	.remove		= pcie_portdrv_remove,
   1.251  
   1.252 -#ifdef	CONFIG_PM
   1.253  	.suspend	= pcie_portdrv_suspend,
   1.254  	.resume		= pcie_portdrv_resume,
   1.255 -#endif	/* PM */
   1.256 +
   1.257 +	.err_handler 	= &pcie_portdrv_err_handler,
   1.258  };
   1.259  
   1.260  static int __init pcie_portdrv_init(void)