ia64/linux-2.6.18-xen.hg

view drivers/pci/pcie/portdrv_pci.c @ 781:83b71f4b5cb2

Fix !CONFIG_PM compilation problem

Signed-off-by: Espen Skoglund <espen.skoglund@netronome.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 20 13:28:35 2009 +0000 (2009-01-20)
parents df84c4c22a0a
children
line source
1 /*
2 * File: portdrv_pci.c
3 * Purpose: PCI Express Port Bus Driver
4 *
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/pm.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/pcieport_if.h>
17 #include <linux/aer.h>
19 #include "portdrv.h"
20 #include "aer/aerdrv.h"
22 /*
23 * Version Information
24 */
25 #define DRIVER_VERSION "v1.0"
26 #define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
27 #define DRIVER_DESC "PCIE Port Bus Driver"
28 MODULE_AUTHOR(DRIVER_AUTHOR);
29 MODULE_DESCRIPTION(DRIVER_DESC);
30 MODULE_LICENSE("GPL");
32 /* global data */
33 static const char device_name[] = "pcieport-driver";
35 static int pcie_portdrv_save_config(struct pci_dev *dev)
36 {
37 return pci_save_state(dev);
38 }
40 static int pcie_portdrv_restore_config(struct pci_dev *dev)
41 {
42 int retval;
44 pci_restore_state(dev);
45 retval = pci_enable_device(dev);
46 if (retval)
47 return retval;
48 pci_set_master(dev);
49 return 0;
50 }
52 #ifdef CONFIG_PM
53 static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state)
54 {
55 int ret = pcie_port_device_suspend(dev, state);
57 if (!ret)
58 ret = pcie_portdrv_save_config(dev);
59 return ret;
60 }
62 static int pcie_portdrv_resume(struct pci_dev *dev)
63 {
64 pcie_portdrv_restore_config(dev);
65 return pcie_port_device_resume(dev);
66 }
67 #else
68 #define pcie_portdrv_suspend NULL
69 #define pcie_portdrv_resume NULL
70 #endif
72 /*
73 * pcie_portdrv_probe - Probe PCI-Express port devices
74 * @dev: PCI-Express port device being probed
75 *
76 * If detected invokes the pcie_port_device_register() method for
77 * this port device.
78 *
79 */
80 static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
81 const struct pci_device_id *id )
82 {
83 int status;
85 status = pcie_port_device_probe(dev);
86 if (status)
87 return status;
89 if (pci_enable_device(dev) < 0)
90 return -ENODEV;
92 pci_set_master(dev);
93 if (!dev->irq) {
94 printk(KERN_WARNING
95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
96 __FUNCTION__, dev->device, dev->vendor);
97 }
98 if (pcie_port_device_register(dev)) {
99 pci_disable_device(dev);
100 return -ENOMEM;
101 }
103 pcie_portdrv_save_config(dev);
105 pci_enable_pcie_error_reporting(dev);
107 return 0;
108 }
110 static void pcie_portdrv_remove (struct pci_dev *dev)
111 {
112 pcie_port_device_remove(dev);
113 kfree(pci_get_drvdata(dev));
114 }
116 static int error_detected_iter(struct device *device, void *data)
117 {
118 struct pcie_device *pcie_device;
119 struct pcie_port_service_driver *driver;
120 struct aer_broadcast_data *result_data;
121 pci_ers_result_t status;
123 result_data = (struct aer_broadcast_data *) data;
125 if (device->bus == &pcie_port_bus_type && device->driver) {
126 driver = to_service_driver(device->driver);
127 if (!driver ||
128 !driver->err_handler ||
129 !driver->err_handler->error_detected)
130 return 0;
132 pcie_device = to_pcie_device(device);
134 /* Forward error detected message to service drivers */
135 status = driver->err_handler->error_detected(
136 pcie_device->port,
137 result_data->state);
138 result_data->result =
139 merge_result(result_data->result, status);
140 }
142 return 0;
143 }
145 static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
146 enum pci_channel_state error)
147 {
148 struct aer_broadcast_data result_data =
149 {error, PCI_ERS_RESULT_CAN_RECOVER};
151 device_for_each_child(&dev->dev, &result_data, error_detected_iter);
153 return result_data.result;
154 }
156 static int mmio_enabled_iter(struct device *device, void *data)
157 {
158 struct pcie_device *pcie_device;
159 struct pcie_port_service_driver *driver;
160 pci_ers_result_t status, *result;
162 result = (pci_ers_result_t *) data;
164 if (device->bus == &pcie_port_bus_type && device->driver) {
165 driver = to_service_driver(device->driver);
166 if (driver &&
167 driver->err_handler &&
168 driver->err_handler->mmio_enabled) {
169 pcie_device = to_pcie_device(device);
171 /* Forward error message to service drivers */
172 status = driver->err_handler->mmio_enabled(
173 pcie_device->port);
174 *result = merge_result(*result, status);
175 }
176 }
178 return 0;
179 }
181 static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
182 {
183 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
185 device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
186 return status;
187 }
189 static int slot_reset_iter(struct device *device, void *data)
190 {
191 struct pcie_device *pcie_device;
192 struct pcie_port_service_driver *driver;
193 pci_ers_result_t status, *result;
195 result = (pci_ers_result_t *) data;
197 if (device->bus == &pcie_port_bus_type && device->driver) {
198 driver = to_service_driver(device->driver);
199 if (driver &&
200 driver->err_handler &&
201 driver->err_handler->slot_reset) {
202 pcie_device = to_pcie_device(device);
204 /* Forward error message to service drivers */
205 status = driver->err_handler->slot_reset(
206 pcie_device->port);
207 *result = merge_result(*result, status);
208 }
209 }
211 return 0;
212 }
214 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
215 {
216 pci_ers_result_t status;
218 /* If fatal, restore cfg space for possible link reset at upstream */
219 if (dev->error_state == pci_channel_io_frozen) {
220 pcie_portdrv_restore_config(dev);
221 pci_enable_pcie_error_reporting(dev);
222 }
224 device_for_each_child(&dev->dev, &status, slot_reset_iter);
226 return status;
227 }
229 static int resume_iter(struct device *device, void *data)
230 {
231 struct pcie_device *pcie_device;
232 struct pcie_port_service_driver *driver;
234 if (device->bus == &pcie_port_bus_type && device->driver) {
235 driver = to_service_driver(device->driver);
236 if (driver &&
237 driver->err_handler &&
238 driver->err_handler->resume) {
239 pcie_device = to_pcie_device(device);
241 /* Forward error message to service drivers */
242 driver->err_handler->resume(pcie_device->port);
243 }
244 }
246 return 0;
247 }
249 static void pcie_portdrv_err_resume(struct pci_dev *dev)
250 {
251 device_for_each_child(&dev->dev, NULL, resume_iter);
252 }
254 /*
255 * LINUX Device Driver Model
256 */
257 static const struct pci_device_id port_pci_ids[] = { {
258 /* handle any PCI-Express port */
259 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
260 }, { /* end: all zeroes */ }
261 };
262 MODULE_DEVICE_TABLE(pci, port_pci_ids);
264 static struct pci_error_handlers pcie_portdrv_err_handler = {
265 .error_detected = pcie_portdrv_error_detected,
266 .mmio_enabled = pcie_portdrv_mmio_enabled,
267 .slot_reset = pcie_portdrv_slot_reset,
268 .resume = pcie_portdrv_err_resume,
269 };
271 static struct pci_driver pcie_portdrv = {
272 .name = (char *)device_name,
273 .id_table = &port_pci_ids[0],
275 .probe = pcie_portdrv_probe,
276 .remove = pcie_portdrv_remove,
278 .suspend = pcie_portdrv_suspend,
279 .resume = pcie_portdrv_resume,
281 .err_handler = &pcie_portdrv_err_handler,
282 };
284 static int __init pcie_portdrv_init(void)
285 {
286 int retval = 0;
288 pcie_port_bus_register();
289 retval = pci_register_driver(&pcie_portdrv);
290 if (retval)
291 pcie_port_bus_unregister();
292 return retval;
293 }
295 static void __exit pcie_portdrv_exit(void)
296 {
297 pci_unregister_driver(&pcie_portdrv);
298 pcie_port_bus_unregister();
299 }
301 module_init(pcie_portdrv_init);
302 module_exit(pcie_portdrv_exit);