Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pci/pcie/aer/aerdrv.c |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * This file implements the AER root port service driver. The driver will |
| 9 | * register an irq handler. When root port triggers an AER interrupt, the irq |
| 10 | * handler will collect root port status and schedule a work. |
| 11 | * |
| 12 | * Copyright (C) 2006 Intel Corp. |
| 13 | * Tom Long Nguyen (tom.l.nguyen@intel.com) |
| 14 | * Zhang Yanmin (yanmin.zhang@intel.com) |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/pci.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 20 | #include <linux/sched.h> |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/pm.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/pcieport_if.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 29 | |
| 30 | #include "aerdrv.h" |
Alex Chiang | 5d9526d | 2008-06-04 11:39:07 -0600 | [diff] [blame] | 31 | #include "../../pci.h" |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Version Information |
| 35 | */ |
| 36 | #define DRIVER_VERSION "v1.0" |
| 37 | #define DRIVER_AUTHOR "tom.l.nguyen@intel.com" |
| 38 | #define DRIVER_DESC "Root Port Advanced Error Reporting Driver" |
| 39 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 40 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 43 | static int __devinit aer_probe(struct pcie_device *dev); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 44 | static void aer_remove(struct pcie_device *dev); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 45 | static pci_ers_result_t aer_error_detected(struct pci_dev *dev, |
| 46 | enum pci_channel_state error); |
| 47 | static void aer_error_resume(struct pci_dev *dev); |
| 48 | static pci_ers_result_t aer_root_reset(struct pci_dev *dev); |
| 49 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 50 | static struct pci_error_handlers aer_error_handlers = { |
| 51 | .error_detected = aer_error_detected, |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 52 | .resume = aer_error_resume, |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 53 | }; |
| 54 | |
Sam Ravnborg | c1996c2 | 2007-02-27 10:22:00 +0100 | [diff] [blame] | 55 | static struct pcie_port_service_driver aerdriver = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 56 | .name = "aer", |
Kenji Kaneshige | 694f88e | 2009-11-25 21:06:15 +0900 | [diff] [blame] | 57 | .port_type = PCI_EXP_TYPE_ROOT_PORT, |
Rafael J. Wysocki | 2210636 | 2009-01-13 14:46:46 +0100 | [diff] [blame] | 58 | .service = PCIE_PORT_SERVICE_AER, |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 59 | |
| 60 | .probe = aer_probe, |
| 61 | .remove = aer_remove, |
| 62 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 63 | .err_handler = &aer_error_handlers, |
| 64 | |
| 65 | .reset_link = aer_root_reset, |
| 66 | }; |
| 67 | |
Randy Dunlap | 7f78576 | 2007-10-05 13:17:58 -0700 | [diff] [blame] | 68 | static int pcie_aer_disable; |
| 69 | |
| 70 | void pci_no_aer(void) |
| 71 | { |
| 72 | pcie_aer_disable = 1; /* has priority over 'forceload' */ |
| 73 | } |
| 74 | |
Hidetoshi Seto | 843f469 | 2010-04-15 13:10:53 +0900 | [diff] [blame] | 75 | static int set_device_error_reporting(struct pci_dev *dev, void *data) |
| 76 | { |
| 77 | bool enable = *((bool *)data); |
| 78 | |
| 79 | if ((dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) || |
| 80 | (dev->pcie_type == PCI_EXP_TYPE_UPSTREAM) || |
| 81 | (dev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)) { |
| 82 | if (enable) |
| 83 | pci_enable_pcie_error_reporting(dev); |
| 84 | else |
| 85 | pci_disable_pcie_error_reporting(dev); |
| 86 | } |
| 87 | |
| 88 | if (enable) |
| 89 | pcie_set_ecrc_checking(dev); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * set_downstream_devices_error_reporting - enable/disable the error reporting bits on the root port and its downstream ports. |
| 96 | * @dev: pointer to root port's pci_dev data structure |
| 97 | * @enable: true = enable error reporting, false = disable error reporting. |
| 98 | */ |
| 99 | static void set_downstream_devices_error_reporting(struct pci_dev *dev, |
| 100 | bool enable) |
| 101 | { |
| 102 | set_device_error_reporting(dev, &enable); |
| 103 | |
| 104 | if (!dev->subordinate) |
| 105 | return; |
| 106 | pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * aer_enable_rootport - enable Root Port's interrupts when receiving messages |
| 111 | * @rpc: pointer to a Root Port data structure |
| 112 | * |
| 113 | * Invoked when PCIe bus loads AER service driver. |
| 114 | */ |
| 115 | static void aer_enable_rootport(struct aer_rpc *rpc) |
| 116 | { |
| 117 | struct pci_dev *pdev = rpc->rpd->port; |
| 118 | int pos, aer_pos; |
| 119 | u16 reg16; |
| 120 | u32 reg32; |
| 121 | |
| 122 | pos = pci_pcie_cap(pdev); |
| 123 | /* Clear PCIe Capability's Device Status */ |
| 124 | pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, ®16); |
| 125 | pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16); |
| 126 | |
| 127 | /* Disable system error generation in response to error messages */ |
| 128 | pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, ®16); |
| 129 | reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK); |
| 130 | pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16); |
| 131 | |
| 132 | aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); |
| 133 | /* Clear error status */ |
| 134 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, ®32); |
| 135 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32); |
| 136 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, ®32); |
| 137 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32); |
| 138 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, ®32); |
| 139 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32); |
| 140 | |
| 141 | /* |
| 142 | * Enable error reporting for the root port device and downstream port |
| 143 | * devices. |
| 144 | */ |
| 145 | set_downstream_devices_error_reporting(pdev, true); |
| 146 | |
| 147 | /* Enable Root Port's interrupt in response to error messages */ |
| 148 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_COMMAND, ®32); |
| 149 | reg32 |= ROOT_PORT_INTR_ON_MESG_MASK; |
| 150 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_COMMAND, reg32); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * aer_disable_rootport - disable Root Port's interrupts when receiving messages |
| 155 | * @rpc: pointer to a Root Port data structure |
| 156 | * |
| 157 | * Invoked when PCIe bus unloads AER service driver. |
| 158 | */ |
| 159 | static void aer_disable_rootport(struct aer_rpc *rpc) |
| 160 | { |
| 161 | struct pci_dev *pdev = rpc->rpd->port; |
| 162 | u32 reg32; |
| 163 | int pos; |
| 164 | |
| 165 | /* |
| 166 | * Disable error reporting for the root port device and downstream port |
| 167 | * devices. |
| 168 | */ |
| 169 | set_downstream_devices_error_reporting(pdev, false); |
| 170 | |
| 171 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); |
| 172 | /* Disable Root's interrupt in response to error messages */ |
| 173 | pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, ®32); |
| 174 | reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK; |
| 175 | pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, reg32); |
| 176 | |
| 177 | /* Clear Root's error status reg */ |
| 178 | pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, ®32); |
| 179 | pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32); |
| 180 | } |
| 181 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 182 | /** |
| 183 | * aer_irq - Root Port's ISR |
| 184 | * @irq: IRQ assigned to Root Port |
| 185 | * @context: pointer to Root Port data structure |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 186 | * |
| 187 | * Invoked when Root Port detects AER messages. |
| 188 | **/ |
Huang Ying | 634deb0 | 2009-04-24 10:45:23 +0800 | [diff] [blame] | 189 | irqreturn_t aer_irq(int irq, void *context) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 190 | { |
| 191 | unsigned int status, id; |
| 192 | struct pcie_device *pdev = (struct pcie_device *)context; |
| 193 | struct aer_rpc *rpc = get_service_data(pdev); |
| 194 | int next_prod_idx; |
| 195 | unsigned long flags; |
| 196 | int pos; |
| 197 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 198 | pos = pci_find_ext_capability(pdev->port, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 199 | /* |
| 200 | * Must lock access to Root Error Status Reg, Root Error ID Reg, |
| 201 | * and Root error producer/consumer index |
| 202 | */ |
| 203 | spin_lock_irqsave(&rpc->e_lock, flags); |
| 204 | |
| 205 | /* Read error status */ |
| 206 | pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, &status); |
Hidetoshi Seto | e167bfc | 2010-04-15 13:18:26 +0900 | [diff] [blame^] | 207 | if (!(status & (PCI_ERR_ROOT_UNCOR_RCV|PCI_ERR_ROOT_COR_RCV))) { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 208 | spin_unlock_irqrestore(&rpc->e_lock, flags); |
| 209 | return IRQ_NONE; |
| 210 | } |
| 211 | |
| 212 | /* Read error source and clear error status */ |
Hidetoshi Seto | f647a44 | 2010-04-15 13:17:33 +0900 | [diff] [blame] | 213 | pci_read_config_dword(pdev->port, pos + PCI_ERR_ROOT_ERR_SRC, &id); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 214 | pci_write_config_dword(pdev->port, pos + PCI_ERR_ROOT_STATUS, status); |
| 215 | |
| 216 | /* Store error source for later DPC handler */ |
| 217 | next_prod_idx = rpc->prod_idx + 1; |
| 218 | if (next_prod_idx == AER_ERROR_SOURCES_MAX) |
| 219 | next_prod_idx = 0; |
| 220 | if (next_prod_idx == rpc->cons_idx) { |
| 221 | /* |
| 222 | * Error Storm Condition - possibly the same error occurred. |
| 223 | * Drop the error. |
| 224 | */ |
| 225 | spin_unlock_irqrestore(&rpc->e_lock, flags); |
| 226 | return IRQ_HANDLED; |
| 227 | } |
| 228 | rpc->e_sources[rpc->prod_idx].status = status; |
| 229 | rpc->e_sources[rpc->prod_idx].id = id; |
| 230 | rpc->prod_idx = next_prod_idx; |
| 231 | spin_unlock_irqrestore(&rpc->e_lock, flags); |
| 232 | |
| 233 | /* Invoke DPC handler */ |
| 234 | schedule_work(&rpc->dpc_handler); |
| 235 | |
| 236 | return IRQ_HANDLED; |
| 237 | } |
Huang Ying | 634deb0 | 2009-04-24 10:45:23 +0800 | [diff] [blame] | 238 | EXPORT_SYMBOL_GPL(aer_irq); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * aer_alloc_rpc - allocate Root Port data structure |
| 242 | * @dev: pointer to the pcie_dev data structure |
| 243 | * |
| 244 | * Invoked when Root Port's AER service is loaded. |
| 245 | **/ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 246 | static struct aer_rpc *aer_alloc_rpc(struct pcie_device *dev) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 247 | { |
| 248 | struct aer_rpc *rpc; |
| 249 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 250 | rpc = kzalloc(sizeof(struct aer_rpc), GFP_KERNEL); |
| 251 | if (!rpc) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 252 | return NULL; |
| 253 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 254 | /* |
| 255 | * Initialize Root lock access, e_lock, to Root Error Status Reg, |
| 256 | * Root Error ID Reg, and Root error producer/consumer index. |
| 257 | */ |
Milind Arun Choudhary | f5609d7 | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 258 | spin_lock_init(&rpc->e_lock); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 259 | |
| 260 | rpc->rpd = dev; |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 261 | INIT_WORK(&rpc->dpc_handler, aer_isr); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 262 | rpc->prod_idx = rpc->cons_idx = 0; |
| 263 | mutex_init(&rpc->rpc_mutex); |
| 264 | init_waitqueue_head(&rpc->wait_release); |
| 265 | |
Stefan Assmann | 45e829e | 2009-12-03 06:49:24 -0500 | [diff] [blame] | 266 | /* Use PCIe bus function to store rpc into PCIe device */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 267 | set_service_data(dev, rpc); |
| 268 | |
| 269 | return rpc; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * aer_remove - clean up resources |
| 274 | * @dev: pointer to the pcie_dev data structure |
| 275 | * |
| 276 | * Invoked when PCI Express bus unloads or AER probe fails. |
| 277 | **/ |
| 278 | static void aer_remove(struct pcie_device *dev) |
| 279 | { |
| 280 | struct aer_rpc *rpc = get_service_data(dev); |
| 281 | |
| 282 | if (rpc) { |
| 283 | /* If register interrupt service, it must be free. */ |
| 284 | if (rpc->isr) |
| 285 | free_irq(dev->irq, dev); |
| 286 | |
| 287 | wait_event(rpc->wait_release, rpc->prod_idx == rpc->cons_idx); |
| 288 | |
Hidetoshi Seto | 460d298 | 2010-04-15 13:10:03 +0900 | [diff] [blame] | 289 | aer_disable_rootport(rpc); |
| 290 | kfree(rpc); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 291 | set_service_data(dev, NULL); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * aer_probe - initialize resources |
| 297 | * @dev: pointer to the pcie_dev data structure |
| 298 | * @id: pointer to the service id data structure |
| 299 | * |
| 300 | * Invoked when PCI Express bus loads AER service driver. |
| 301 | **/ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 302 | static int __devinit aer_probe(struct pcie_device *dev) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 303 | { |
| 304 | int status; |
| 305 | struct aer_rpc *rpc; |
| 306 | struct device *device = &dev->device; |
| 307 | |
| 308 | /* Init */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 309 | status = aer_init(dev); |
| 310 | if (status) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 311 | return status; |
| 312 | |
| 313 | /* Alloc rpc data structure */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 314 | rpc = aer_alloc_rpc(dev); |
| 315 | if (!rpc) { |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 316 | dev_printk(KERN_DEBUG, device, "alloc rpc failed\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 317 | aer_remove(dev); |
| 318 | return -ENOMEM; |
| 319 | } |
| 320 | |
| 321 | /* Request IRQ ISR */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 322 | status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", dev); |
| 323 | if (status) { |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 324 | dev_printk(KERN_DEBUG, device, "request IRQ failed\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 325 | aer_remove(dev); |
| 326 | return status; |
| 327 | } |
| 328 | |
| 329 | rpc->isr = 1; |
| 330 | |
| 331 | aer_enable_rootport(rpc); |
| 332 | |
| 333 | return status; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * aer_root_reset - reset link on Root Port |
| 338 | * @dev: pointer to Root Port's pci_dev data structure |
| 339 | * |
| 340 | * Invoked by Port Bus driver when performing link reset at Root Port. |
| 341 | **/ |
| 342 | static pci_ers_result_t aer_root_reset(struct pci_dev *dev) |
| 343 | { |
| 344 | u16 p2p_ctrl; |
Hidetoshi Seto | c6d34ed | 2010-04-15 13:09:13 +0900 | [diff] [blame] | 345 | u32 reg32; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 346 | int pos; |
| 347 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 348 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 349 | |
| 350 | /* Disable Root's interrupt in response to error messages */ |
Hidetoshi Seto | c6d34ed | 2010-04-15 13:09:13 +0900 | [diff] [blame] | 351 | pci_read_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, ®32); |
| 352 | reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK; |
| 353 | pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, reg32); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 354 | |
| 355 | /* Assert Secondary Bus Reset */ |
| 356 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &p2p_ctrl); |
Alexander Duyck | 4352aa5 | 2010-03-25 13:03:30 -0700 | [diff] [blame] | 357 | p2p_ctrl |= PCI_BRIDGE_CTL_BUS_RESET; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 358 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl); |
| 359 | |
Alexander Duyck | 4352aa5 | 2010-03-25 13:03:30 -0700 | [diff] [blame] | 360 | /* |
| 361 | * we should send hot reset message for 2ms to allow it time to |
| 362 | * propogate to all downstream ports |
| 363 | */ |
| 364 | msleep(2); |
| 365 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 366 | /* De-assert Secondary Bus Reset */ |
Alexander Duyck | 4352aa5 | 2010-03-25 13:03:30 -0700 | [diff] [blame] | 367 | p2p_ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 368 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl); |
| 369 | |
| 370 | /* |
| 371 | * System software must wait for at least 100ms from the end |
| 372 | * of a reset of one or more device before it is permitted |
| 373 | * to issue Configuration Requests to those devices. |
| 374 | */ |
| 375 | msleep(200); |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 376 | dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 377 | |
Hidetoshi Seto | c6d34ed | 2010-04-15 13:09:13 +0900 | [diff] [blame] | 378 | /* Clear Root Error Status */ |
| 379 | pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, ®32); |
| 380 | pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, reg32); |
| 381 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 382 | /* Enable Root Port's interrupt in response to error messages */ |
Hidetoshi Seto | c6d34ed | 2010-04-15 13:09:13 +0900 | [diff] [blame] | 383 | pci_read_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, ®32); |
| 384 | reg32 |= ROOT_PORT_INTR_ON_MESG_MASK; |
| 385 | pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND, reg32); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 386 | |
| 387 | return PCI_ERS_RESULT_RECOVERED; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * aer_error_detected - update severity status |
| 392 | * @dev: pointer to Root Port's pci_dev data structure |
| 393 | * @error: error severity being notified by port bus |
| 394 | * |
| 395 | * Invoked by Port Bus driver during error recovery. |
| 396 | **/ |
| 397 | static pci_ers_result_t aer_error_detected(struct pci_dev *dev, |
| 398 | enum pci_channel_state error) |
| 399 | { |
| 400 | /* Root Port has no impact. Always recovers. */ |
| 401 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * aer_error_resume - clean up corresponding error status bits |
| 406 | * @dev: pointer to Root Port's pci_dev data structure |
| 407 | * |
| 408 | * Invoked by Port Bus driver during nonfatal recovery. |
| 409 | **/ |
| 410 | static void aer_error_resume(struct pci_dev *dev) |
| 411 | { |
| 412 | int pos; |
| 413 | u32 status, mask; |
| 414 | u16 reg16; |
| 415 | |
| 416 | /* Clean up Root device status */ |
Kenji Kaneshige | 39a5306 | 2009-11-11 14:31:38 +0900 | [diff] [blame] | 417 | pos = pci_pcie_cap(dev); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 418 | pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, ®16); |
| 419 | pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, reg16); |
| 420 | |
| 421 | /* Clean AER Root Error Status */ |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 422 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 423 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status); |
| 424 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask); |
| 425 | if (dev->error_state == pci_channel_io_normal) |
| 426 | status &= ~mask; /* Clear corresponding nonfatal bits */ |
| 427 | else |
| 428 | status &= mask; /* Clear corresponding fatal bits */ |
| 429 | pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * aer_service_init - register AER root service driver |
| 434 | * |
| 435 | * Invoked when AER root service driver is loaded. |
| 436 | **/ |
| 437 | static int __init aer_service_init(void) |
| 438 | { |
Randy Dunlap | 7f78576 | 2007-10-05 13:17:58 -0700 | [diff] [blame] | 439 | if (pcie_aer_disable) |
| 440 | return -ENXIO; |
Andi Kleen | 3e77a3f | 2009-09-16 22:40:22 +0200 | [diff] [blame] | 441 | if (!pci_msi_enabled()) |
| 442 | return -ENXIO; |
Sam Ravnborg | c1996c2 | 2007-02-27 10:22:00 +0100 | [diff] [blame] | 443 | return pcie_port_service_register(&aerdriver); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * aer_service_exit - unregister AER root service driver |
| 448 | * |
| 449 | * Invoked when AER root service driver is unloaded. |
| 450 | **/ |
| 451 | static void __exit aer_service_exit(void) |
| 452 | { |
Sam Ravnborg | c1996c2 | 2007-02-27 10:22:00 +0100 | [diff] [blame] | 453 | pcie_port_service_unregister(&aerdriver); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | module_init(aer_service_init); |
| 457 | module_exit(aer_service_exit); |