Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pci/pcie/aer/aerdrv_core.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 core part of PCI-Express AER. When an pci-express |
| 9 | * error is delivered, an error message will be collected and printed to |
| 10 | * console, then, an error recovery procedure will be executed by following |
| 11 | * the pci error recovery rules. |
| 12 | * |
| 13 | * Copyright (C) 2006 Intel Corp. |
| 14 | * Tom Long Nguyen (tom.l.nguyen@intel.com) |
| 15 | * Zhang Yanmin (yanmin.zhang@intel.com) |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/pm.h> |
| 24 | #include <linux/suspend.h> |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include "aerdrv.h" |
| 27 | |
| 28 | static int forceload; |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 29 | static int nosourceid; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 30 | module_param(forceload, bool, 0); |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 31 | module_param(nosourceid, bool, 0); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 32 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 33 | int pci_enable_pcie_error_reporting(struct pci_dev *dev) |
| 34 | { |
| 35 | u16 reg16 = 0; |
| 36 | int pos; |
| 37 | |
Yu Zhao | 270c66b | 2008-10-19 20:35:20 +0800 | [diff] [blame] | 38 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 39 | if (!pos) |
| 40 | return -EIO; |
| 41 | |
Yu Zhao | 270c66b | 2008-10-19 20:35:20 +0800 | [diff] [blame] | 42 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 43 | if (!pos) |
| 44 | return -EIO; |
| 45 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 46 | pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, ®16); |
| 47 | reg16 = reg16 | |
| 48 | PCI_EXP_DEVCTL_CERE | |
| 49 | PCI_EXP_DEVCTL_NFERE | |
| 50 | PCI_EXP_DEVCTL_FERE | |
| 51 | PCI_EXP_DEVCTL_URRE; |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 52 | pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16); |
| 53 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 54 | return 0; |
| 55 | } |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 56 | EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 57 | |
| 58 | int pci_disable_pcie_error_reporting(struct pci_dev *dev) |
| 59 | { |
| 60 | u16 reg16 = 0; |
| 61 | int pos; |
| 62 | |
| 63 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
| 64 | if (!pos) |
| 65 | return -EIO; |
| 66 | |
| 67 | pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, ®16); |
| 68 | reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE | |
| 69 | PCI_EXP_DEVCTL_NFERE | |
| 70 | PCI_EXP_DEVCTL_FERE | |
| 71 | PCI_EXP_DEVCTL_URRE); |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 72 | pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16); |
| 73 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 74 | return 0; |
| 75 | } |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 76 | EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 77 | |
| 78 | int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev) |
| 79 | { |
| 80 | int pos; |
| 81 | u32 status, mask; |
| 82 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 83 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 84 | if (!pos) |
| 85 | return -EIO; |
| 86 | |
| 87 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status); |
| 88 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask); |
| 89 | if (dev->error_state == pci_channel_io_normal) |
| 90 | status &= ~mask; /* Clear corresponding nonfatal bits */ |
| 91 | else |
| 92 | status &= mask; /* Clear corresponding fatal bits */ |
| 93 | pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status); |
| 94 | |
| 95 | return 0; |
| 96 | } |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 97 | EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 98 | |
Adrian Bunk | 21c6847 | 2008-02-04 23:50:11 -0800 | [diff] [blame] | 99 | #if 0 |
Stephen Hemminger | f0dce41 | 2007-06-06 11:50:34 +0800 | [diff] [blame] | 100 | int pci_cleanup_aer_correct_error_status(struct pci_dev *dev) |
| 101 | { |
| 102 | int pos; |
| 103 | u32 status; |
| 104 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 105 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Stephen Hemminger | f0dce41 | 2007-06-06 11:50:34 +0800 | [diff] [blame] | 106 | if (!pos) |
| 107 | return -EIO; |
| 108 | |
| 109 | pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status); |
| 110 | pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status); |
| 111 | |
| 112 | return 0; |
| 113 | } |
Adrian Bunk | 21c6847 | 2008-02-04 23:50:11 -0800 | [diff] [blame] | 114 | #endif /* 0 */ |
Stephen Hemminger | f0dce41 | 2007-06-06 11:50:34 +0800 | [diff] [blame] | 115 | |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 116 | static int set_device_error_reporting(struct pci_dev *dev, void *data) |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 117 | { |
| 118 | bool enable = *((bool *)data); |
| 119 | |
Andrew Patterson | 43c1640 | 2009-04-22 16:52:09 -0600 | [diff] [blame] | 120 | if (dev->pcie_type == PCIE_RC_PORT || |
| 121 | dev->pcie_type == PCIE_SW_UPSTREAM_PORT || |
| 122 | dev->pcie_type == PCIE_SW_DOWNSTREAM_PORT) { |
| 123 | if (enable) |
| 124 | pci_enable_pcie_error_reporting(dev); |
| 125 | else |
| 126 | pci_disable_pcie_error_reporting(dev); |
| 127 | } |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 128 | |
| 129 | if (enable) |
Andrew Patterson | 43c1640 | 2009-04-22 16:52:09 -0600 | [diff] [blame] | 130 | pcie_set_ecrc_checking(dev); |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 131 | |
| 132 | return 0; |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * set_downstream_devices_error_reporting - enable/disable the error reporting bits on the root port and its downstream ports. |
| 137 | * @dev: pointer to root port's pci_dev data structure |
| 138 | * @enable: true = enable error reporting, false = disable error reporting. |
| 139 | */ |
| 140 | static void set_downstream_devices_error_reporting(struct pci_dev *dev, |
| 141 | bool enable) |
| 142 | { |
| 143 | set_device_error_reporting(dev, &enable); |
Alex Chiang | cb4cb4a | 2009-03-05 19:28:40 -0700 | [diff] [blame] | 144 | |
| 145 | if (!dev->subordinate) |
| 146 | return; |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 147 | pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable); |
| 148 | } |
| 149 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 150 | static inline int compare_device_id(struct pci_dev *dev, |
| 151 | struct aer_err_info *e_info) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 152 | { |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 153 | if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) { |
| 154 | /* |
| 155 | * Device ID match |
| 156 | */ |
| 157 | return 1; |
| 158 | } |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 159 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 163 | static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev) |
| 164 | { |
| 165 | if (e_info->error_dev_num < AER_MAX_MULTI_ERR_DEVICES) { |
| 166 | e_info->dev[e_info->error_dev_num] = dev; |
| 167 | e_info->error_dev_num++; |
| 168 | return 1; |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 169 | } |
| 170 | |
| 171 | return 0; |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 175 | #define PCI_BUS(x) (((x) >> 8) & 0xff) |
| 176 | |
| 177 | static int find_device_iter(struct pci_dev *dev, void *data) |
| 178 | { |
| 179 | int pos; |
| 180 | u32 status; |
| 181 | u32 mask; |
| 182 | u16 reg16; |
| 183 | int result; |
| 184 | struct aer_err_info *e_info = (struct aer_err_info *)data; |
| 185 | |
| 186 | /* |
| 187 | * When bus id is equal to 0, it might be a bad id |
| 188 | * reported by root port. |
| 189 | */ |
| 190 | if (!nosourceid && (PCI_BUS(e_info->id) != 0)) { |
| 191 | result = compare_device_id(dev, e_info); |
| 192 | if (result) |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 193 | add_error_device(e_info, dev); |
| 194 | |
| 195 | /* |
| 196 | * If there is no multiple error, we stop |
| 197 | * or continue based on the id comparing. |
| 198 | */ |
| 199 | if (!(e_info->flags & AER_MULTI_ERROR_VALID_FLAG)) |
| 200 | return result; |
| 201 | |
| 202 | /* |
| 203 | * If there are multiple errors and id does match, |
| 204 | * We need continue to search other devices under |
| 205 | * the root port. Return 0 means that. |
| 206 | */ |
| 207 | if (result) |
| 208 | return 0; |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 212 | * When either |
| 213 | * 1) nosourceid==y; |
| 214 | * 2) bus id is equal to 0. Some ports might lose the bus |
| 215 | * id of error source id; |
| 216 | * 3) There are multiple errors and prior id comparing fails; |
| 217 | * We check AER status registers to find the initial reporter. |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 218 | */ |
| 219 | if (atomic_read(&dev->enable_cnt) == 0) |
| 220 | return 0; |
| 221 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
| 222 | if (!pos) |
| 223 | return 0; |
| 224 | /* Check if AER is enabled */ |
| 225 | pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, ®16); |
| 226 | if (!(reg16 & ( |
| 227 | PCI_EXP_DEVCTL_CERE | |
| 228 | PCI_EXP_DEVCTL_NFERE | |
| 229 | PCI_EXP_DEVCTL_FERE | |
| 230 | PCI_EXP_DEVCTL_URRE))) |
| 231 | return 0; |
| 232 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
| 233 | if (!pos) |
| 234 | return 0; |
| 235 | |
| 236 | status = 0; |
| 237 | mask = 0; |
| 238 | if (e_info->severity == AER_CORRECTABLE) { |
| 239 | pci_read_config_dword(dev, |
| 240 | pos + PCI_ERR_COR_STATUS, |
| 241 | &status); |
| 242 | pci_read_config_dword(dev, |
| 243 | pos + PCI_ERR_COR_MASK, |
| 244 | &mask); |
| 245 | if (status & ERR_CORRECTABLE_ERROR_MASK & ~mask) { |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 246 | add_error_device(e_info, dev); |
| 247 | goto added; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 248 | } |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 249 | } else { |
| 250 | pci_read_config_dword(dev, |
| 251 | pos + PCI_ERR_UNCOR_STATUS, |
| 252 | &status); |
| 253 | pci_read_config_dword(dev, |
| 254 | pos + PCI_ERR_UNCOR_MASK, |
| 255 | &mask); |
| 256 | if (status & ERR_UNCORRECTABLE_ERROR_MASK & ~mask) { |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 257 | add_error_device(e_info, dev); |
| 258 | goto added; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | return 0; |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 263 | |
| 264 | added: |
| 265 | if (e_info->flags & AER_MULTI_ERROR_VALID_FLAG) |
| 266 | return 0; |
| 267 | else |
| 268 | return 1; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * find_source_device - search through device hierarchy for source device |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 273 | * @parent: pointer to Root Port pci_dev data structure |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 274 | * @err_info: including detailed error information such like id |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 275 | * |
| 276 | * Invoked when error is detected at the Root Port. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 277 | */ |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 278 | static void find_source_device(struct pci_dev *parent, |
| 279 | struct aer_err_info *e_info) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 280 | { |
| 281 | struct pci_dev *dev = parent; |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 282 | int result; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 283 | |
| 284 | /* Is Root Port an agent that sends error message? */ |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 285 | result = find_device_iter(dev, e_info); |
| 286 | if (result) |
| 287 | return; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 288 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 289 | pci_walk_bus(parent->subordinate, find_device_iter, e_info); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 292 | static int report_error_detected(struct pci_dev *dev, void *data) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 293 | { |
| 294 | pci_ers_result_t vote; |
| 295 | struct pci_error_handlers *err_handler; |
| 296 | struct aer_broadcast_data *result_data; |
| 297 | result_data = (struct aer_broadcast_data *) data; |
| 298 | |
| 299 | dev->error_state = result_data->state; |
| 300 | |
| 301 | if (!dev->driver || |
| 302 | !dev->driver->err_handler || |
| 303 | !dev->driver->err_handler->error_detected) { |
| 304 | if (result_data->state == pci_channel_io_frozen && |
| 305 | !(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) { |
| 306 | /* |
| 307 | * In case of fatal recovery, if one of down- |
| 308 | * stream device has no driver. We might be |
| 309 | * unable to recover because a later insmod |
| 310 | * of a driver for this device is unaware of |
| 311 | * its hw state. |
| 312 | */ |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 313 | dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n", |
| 314 | dev->driver ? |
| 315 | "no AER-aware driver" : "no driver"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 316 | } |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 317 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | err_handler = dev->driver->err_handler; |
| 321 | vote = err_handler->error_detected(dev, result_data->state); |
| 322 | result_data->result = merge_result(result_data->result, vote); |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 323 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 324 | } |
| 325 | |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 326 | static int report_mmio_enabled(struct pci_dev *dev, void *data) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 327 | { |
| 328 | pci_ers_result_t vote; |
| 329 | struct pci_error_handlers *err_handler; |
| 330 | struct aer_broadcast_data *result_data; |
| 331 | result_data = (struct aer_broadcast_data *) data; |
| 332 | |
| 333 | if (!dev->driver || |
| 334 | !dev->driver->err_handler || |
| 335 | !dev->driver->err_handler->mmio_enabled) |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 336 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 337 | |
| 338 | err_handler = dev->driver->err_handler; |
| 339 | vote = err_handler->mmio_enabled(dev); |
| 340 | result_data->result = merge_result(result_data->result, vote); |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 341 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 342 | } |
| 343 | |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 344 | static int report_slot_reset(struct pci_dev *dev, void *data) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 345 | { |
| 346 | pci_ers_result_t vote; |
| 347 | struct pci_error_handlers *err_handler; |
| 348 | struct aer_broadcast_data *result_data; |
| 349 | result_data = (struct aer_broadcast_data *) data; |
| 350 | |
| 351 | if (!dev->driver || |
| 352 | !dev->driver->err_handler || |
| 353 | !dev->driver->err_handler->slot_reset) |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 354 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 355 | |
| 356 | err_handler = dev->driver->err_handler; |
| 357 | vote = err_handler->slot_reset(dev); |
| 358 | result_data->result = merge_result(result_data->result, vote); |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 359 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 360 | } |
| 361 | |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 362 | static int report_resume(struct pci_dev *dev, void *data) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 363 | { |
| 364 | struct pci_error_handlers *err_handler; |
| 365 | |
| 366 | dev->error_state = pci_channel_io_normal; |
| 367 | |
| 368 | if (!dev->driver || |
| 369 | !dev->driver->err_handler || |
Hidetoshi Seto | b0b801d | 2008-12-01 16:31:06 +0900 | [diff] [blame] | 370 | !dev->driver->err_handler->resume) |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 371 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 372 | |
| 373 | err_handler = dev->driver->err_handler; |
| 374 | err_handler->resume(dev); |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 375 | return 0; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
| 379 | * broadcast_error_message - handle message broadcast to downstream drivers |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 380 | * @dev: pointer to from where in a hierarchy message is broadcasted down |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 381 | * @state: error state |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 382 | * @error_mesg: message to print |
| 383 | * @cb: callback to be broadcasted |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 384 | * |
| 385 | * Invoked during error recovery process. Once being invoked, the content |
| 386 | * of error severity will be broadcasted to all downstream drivers in a |
| 387 | * hierarchy in question. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 388 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 389 | static pci_ers_result_t broadcast_error_message(struct pci_dev *dev, |
| 390 | enum pci_channel_state state, |
| 391 | char *error_mesg, |
Zhang, Yanmin | 70298c6 | 2009-06-16 13:34:38 +0800 | [diff] [blame] | 392 | int (*cb)(struct pci_dev *, void *)) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 393 | { |
| 394 | struct aer_broadcast_data result_data; |
| 395 | |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 396 | dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 397 | result_data.state = state; |
| 398 | if (cb == report_error_detected) |
| 399 | result_data.result = PCI_ERS_RESULT_CAN_RECOVER; |
| 400 | else |
| 401 | result_data.result = PCI_ERS_RESULT_RECOVERED; |
| 402 | |
| 403 | if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) { |
| 404 | /* |
| 405 | * If the error is reported by a bridge, we think this error |
| 406 | * is related to the downstream link of the bridge, so we |
| 407 | * do error recovery on all subordinates of the bridge instead |
| 408 | * of the bridge and clear the error status of the bridge. |
| 409 | */ |
| 410 | if (cb == report_error_detected) |
| 411 | dev->error_state = state; |
| 412 | pci_walk_bus(dev->subordinate, cb, &result_data); |
| 413 | if (cb == report_resume) { |
| 414 | pci_cleanup_aer_uncorrect_error_status(dev); |
| 415 | dev->error_state = pci_channel_io_normal; |
| 416 | } |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 417 | } else { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 418 | /* |
| 419 | * If the error is reported by an end point, we think this |
| 420 | * error is related to the upstream link of the end point. |
| 421 | */ |
| 422 | pci_walk_bus(dev->bus, cb, &result_data); |
| 423 | } |
| 424 | |
| 425 | return result_data.result; |
| 426 | } |
| 427 | |
| 428 | struct find_aer_service_data { |
| 429 | struct pcie_port_service_driver *aer_driver; |
| 430 | int is_downstream; |
| 431 | }; |
| 432 | |
| 433 | static int find_aer_service_iter(struct device *device, void *data) |
| 434 | { |
| 435 | struct device_driver *driver; |
| 436 | struct pcie_port_service_driver *service_driver; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 437 | struct find_aer_service_data *result; |
| 438 | |
| 439 | result = (struct find_aer_service_data *) data; |
| 440 | |
| 441 | if (device->bus == &pcie_port_bus_type) { |
Rafael J. Wysocki | 2210636 | 2009-01-13 14:46:46 +0100 | [diff] [blame] | 442 | struct pcie_port_data *port_data; |
| 443 | |
| 444 | port_data = pci_get_drvdata(to_pcie_device(device)->port); |
| 445 | if (port_data->port_type == PCIE_SW_DOWNSTREAM_PORT) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 446 | result->is_downstream = 1; |
| 447 | |
| 448 | driver = device->driver; |
| 449 | if (driver) { |
| 450 | service_driver = to_service_driver(driver); |
Rafael J. Wysocki | 2210636 | 2009-01-13 14:46:46 +0100 | [diff] [blame] | 451 | if (service_driver->service == PCIE_PORT_SERVICE_AER) { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 452 | result->aer_driver = service_driver; |
| 453 | return 1; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static void find_aer_service(struct pci_dev *dev, |
| 462 | struct find_aer_service_data *data) |
| 463 | { |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 464 | int retval; |
| 465 | retval = device_for_each_child(&dev->dev, data, find_aer_service_iter); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static pci_ers_result_t reset_link(struct pcie_device *aerdev, |
| 469 | struct pci_dev *dev) |
| 470 | { |
| 471 | struct pci_dev *udev; |
| 472 | pci_ers_result_t status; |
| 473 | struct find_aer_service_data data; |
| 474 | |
| 475 | if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) |
| 476 | udev = dev; |
| 477 | else |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 478 | udev = dev->bus->self; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 479 | |
| 480 | data.is_downstream = 0; |
| 481 | data.aer_driver = NULL; |
| 482 | find_aer_service(udev, &data); |
| 483 | |
| 484 | /* |
| 485 | * Use the aer driver of the error agent firstly. |
| 486 | * If it hasn't the aer driver, use the root port's |
| 487 | */ |
| 488 | if (!data.aer_driver || !data.aer_driver->reset_link) { |
| 489 | if (data.is_downstream && |
| 490 | aerdev->device.driver && |
| 491 | to_service_driver(aerdev->device.driver)->reset_link) { |
| 492 | data.aer_driver = |
| 493 | to_service_driver(aerdev->device.driver); |
| 494 | } else { |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 495 | dev_printk(KERN_DEBUG, &dev->dev, "no link-reset " |
| 496 | "support\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 497 | return PCI_ERS_RESULT_DISCONNECT; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | status = data.aer_driver->reset_link(udev); |
| 502 | if (status != PCI_ERS_RESULT_RECOVERED) { |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 503 | dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream " |
| 504 | "device %s failed\n", pci_name(udev)); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 505 | return PCI_ERS_RESULT_DISCONNECT; |
| 506 | } |
| 507 | |
| 508 | return status; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * do_recovery - handle nonfatal/fatal error recovery process |
| 513 | * @aerdev: pointer to a pcie_device data structure of root port |
| 514 | * @dev: pointer to a pci_dev data structure of agent detecting an error |
| 515 | * @severity: error severity type |
| 516 | * |
| 517 | * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast |
| 518 | * error detected message to all downstream drivers within a hierarchy in |
| 519 | * question and return the returned code. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 520 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 521 | static pci_ers_result_t do_recovery(struct pcie_device *aerdev, |
| 522 | struct pci_dev *dev, |
| 523 | int severity) |
| 524 | { |
| 525 | pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED; |
| 526 | enum pci_channel_state state; |
| 527 | |
| 528 | if (severity == AER_FATAL) |
| 529 | state = pci_channel_io_frozen; |
| 530 | else |
| 531 | state = pci_channel_io_normal; |
| 532 | |
| 533 | status = broadcast_error_message(dev, |
| 534 | state, |
| 535 | "error_detected", |
| 536 | report_error_detected); |
| 537 | |
| 538 | if (severity == AER_FATAL) { |
| 539 | result = reset_link(aerdev, dev); |
| 540 | if (result != PCI_ERS_RESULT_RECOVERED) { |
| 541 | /* TODO: Should panic here? */ |
| 542 | return result; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | if (status == PCI_ERS_RESULT_CAN_RECOVER) |
| 547 | status = broadcast_error_message(dev, |
| 548 | state, |
| 549 | "mmio_enabled", |
| 550 | report_mmio_enabled); |
| 551 | |
| 552 | if (status == PCI_ERS_RESULT_NEED_RESET) { |
| 553 | /* |
| 554 | * TODO: Should call platform-specific |
| 555 | * functions to reset slot before calling |
| 556 | * drivers' slot_reset callbacks? |
| 557 | */ |
| 558 | status = broadcast_error_message(dev, |
| 559 | state, |
| 560 | "slot_reset", |
| 561 | report_slot_reset); |
| 562 | } |
| 563 | |
| 564 | if (status == PCI_ERS_RESULT_RECOVERED) |
| 565 | broadcast_error_message(dev, |
| 566 | state, |
| 567 | "resume", |
| 568 | report_resume); |
| 569 | |
| 570 | return status; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * handle_error_source - handle logging error into an event log |
| 575 | * @aerdev: pointer to pcie_device data structure of the root port |
| 576 | * @dev: pointer to pci_dev data structure of error source device |
| 577 | * @info: comprehensive error information |
| 578 | * |
| 579 | * Invoked when an error being detected by Root Port. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 580 | */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 581 | static void handle_error_source(struct pcie_device *aerdev, |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 582 | struct pci_dev *dev, |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 583 | struct aer_err_info *info) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 584 | { |
| 585 | pci_ers_result_t status = 0; |
| 586 | int pos; |
| 587 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 588 | if (info->severity == AER_CORRECTABLE) { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 589 | /* |
| 590 | * Correctable error does not need software intevention. |
| 591 | * No need to go through error recovery process. |
| 592 | */ |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 593 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 594 | if (pos) |
| 595 | pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 596 | info->status); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 597 | } else { |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 598 | status = do_recovery(aerdev, dev, info->severity); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 599 | if (status == PCI_ERS_RESULT_RECOVERED) { |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 600 | dev_printk(KERN_DEBUG, &dev->dev, "AER driver " |
| 601 | "successfully recovered\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 602 | } else { |
| 603 | /* TODO: Should kernel panic here? */ |
Bjorn Helgaas | 531f254 | 2008-06-13 10:52:12 -0600 | [diff] [blame] | 604 | dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't " |
| 605 | "recover\n"); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * aer_enable_rootport - enable Root Port's interrupts when receiving messages |
| 612 | * @rpc: pointer to a Root Port data structure |
| 613 | * |
| 614 | * Invoked when PCIE bus loads AER service driver. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 615 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 616 | void aer_enable_rootport(struct aer_rpc *rpc) |
| 617 | { |
| 618 | struct pci_dev *pdev = rpc->rpd->port; |
| 619 | int pos, aer_pos; |
| 620 | u16 reg16; |
| 621 | u32 reg32; |
| 622 | |
| 623 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 624 | /* Clear PCIE Capability's Device Status */ |
| 625 | pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, ®16); |
| 626 | pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16); |
| 627 | |
| 628 | /* Disable system error generation in response to error messages */ |
| 629 | pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, ®16); |
| 630 | reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK); |
| 631 | pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16); |
| 632 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 633 | aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 634 | /* Clear error status */ |
| 635 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, ®32); |
| 636 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32); |
| 637 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, ®32); |
| 638 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32); |
| 639 | pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, ®32); |
| 640 | pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32); |
| 641 | |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 642 | /* |
| 643 | * Enable error reporting for the root port device and downstream port |
| 644 | * devices. |
| 645 | */ |
| 646 | set_downstream_devices_error_reporting(pdev, true); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 647 | |
| 648 | /* Enable Root Port's interrupt in response to error messages */ |
| 649 | pci_write_config_dword(pdev, |
| 650 | aer_pos + PCI_ERR_ROOT_COMMAND, |
| 651 | ROOT_PORT_INTR_ON_MESG_MASK); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * disable_root_aer - disable Root Port's interrupts when receiving messages |
| 656 | * @rpc: pointer to a Root Port data structure |
| 657 | * |
| 658 | * Invoked when PCIE bus unloads AER service driver. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 659 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 660 | static void disable_root_aer(struct aer_rpc *rpc) |
| 661 | { |
| 662 | struct pci_dev *pdev = rpc->rpd->port; |
| 663 | u32 reg32; |
| 664 | int pos; |
| 665 | |
Andrew Patterson | 1f9f13c | 2009-02-20 16:04:59 -0700 | [diff] [blame] | 666 | /* |
| 667 | * Disable error reporting for the root port device and downstream port |
| 668 | * devices. |
| 669 | */ |
| 670 | set_downstream_devices_error_reporting(pdev, false); |
| 671 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 672 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 673 | /* Disable Root's interrupt in response to error messages */ |
| 674 | pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0); |
| 675 | |
| 676 | /* Clear Root's error status reg */ |
| 677 | pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, ®32); |
| 678 | pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32); |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * get_e_source - retrieve an error source |
| 683 | * @rpc: pointer to the root port which holds an error |
| 684 | * |
| 685 | * Invoked by DPC handler to consume an error. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 686 | */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame^] | 687 | static struct aer_err_source *get_e_source(struct aer_rpc *rpc) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 688 | { |
| 689 | struct aer_err_source *e_source; |
| 690 | unsigned long flags; |
| 691 | |
| 692 | /* Lock access to Root error producer/consumer index */ |
| 693 | spin_lock_irqsave(&rpc->e_lock, flags); |
| 694 | if (rpc->prod_idx == rpc->cons_idx) { |
| 695 | spin_unlock_irqrestore(&rpc->e_lock, flags); |
| 696 | return NULL; |
| 697 | } |
| 698 | e_source = &rpc->e_sources[rpc->cons_idx]; |
| 699 | rpc->cons_idx++; |
| 700 | if (rpc->cons_idx == AER_ERROR_SOURCES_MAX) |
| 701 | rpc->cons_idx = 0; |
| 702 | spin_unlock_irqrestore(&rpc->e_lock, flags); |
| 703 | |
| 704 | return e_source; |
| 705 | } |
| 706 | |
| 707 | static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info) |
| 708 | { |
| 709 | int pos; |
| 710 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 711 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 712 | |
| 713 | /* The device might not support AER */ |
| 714 | if (!pos) |
| 715 | return AER_SUCCESS; |
| 716 | |
| 717 | if (info->severity == AER_CORRECTABLE) { |
| 718 | pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, |
| 719 | &info->status); |
| 720 | if (!(info->status & ERR_CORRECTABLE_ERROR_MASK)) |
| 721 | return AER_UNSUCCESS; |
| 722 | } else if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE || |
| 723 | info->severity == AER_NONFATAL) { |
| 724 | |
| 725 | /* Link is still healthy for IO reads */ |
| 726 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, |
| 727 | &info->status); |
| 728 | if (!(info->status & ERR_UNCORRECTABLE_ERROR_MASK)) |
| 729 | return AER_UNSUCCESS; |
| 730 | |
| 731 | if (info->status & AER_LOG_TLP_MASKS) { |
| 732 | info->flags |= AER_TLP_HEADER_VALID_FLAG; |
| 733 | pci_read_config_dword(dev, |
| 734 | pos + PCI_ERR_HEADER_LOG, &info->tlp.dw0); |
| 735 | pci_read_config_dword(dev, |
| 736 | pos + PCI_ERR_HEADER_LOG + 4, &info->tlp.dw1); |
| 737 | pci_read_config_dword(dev, |
| 738 | pos + PCI_ERR_HEADER_LOG + 8, &info->tlp.dw2); |
| 739 | pci_read_config_dword(dev, |
| 740 | pos + PCI_ERR_HEADER_LOG + 12, &info->tlp.dw3); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | return AER_SUCCESS; |
| 745 | } |
| 746 | |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 747 | static inline void aer_process_err_devices(struct pcie_device *p_device, |
| 748 | struct aer_err_info *e_info) |
| 749 | { |
| 750 | int i; |
| 751 | |
| 752 | if (!e_info->dev[0]) { |
| 753 | dev_printk(KERN_DEBUG, &p_device->port->dev, |
| 754 | "can't find device of ID%04x\n", |
| 755 | e_info->id); |
| 756 | } |
| 757 | |
| 758 | for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { |
| 759 | if (get_device_error_info(e_info->dev[i], e_info) == |
| 760 | AER_SUCCESS) { |
| 761 | aer_print_error(e_info->dev[i], e_info); |
| 762 | handle_error_source(p_device, |
| 763 | e_info->dev[i], |
| 764 | e_info); |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 769 | /** |
| 770 | * aer_isr_one_error - consume an error detected by root port |
| 771 | * @p_device: pointer to error root port service device |
| 772 | * @e_src: pointer to an error source |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 773 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 774 | static void aer_isr_one_error(struct pcie_device *p_device, |
| 775 | struct aer_err_source *e_src) |
| 776 | { |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 777 | struct aer_err_info *e_info; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 778 | int i; |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 779 | |
| 780 | /* struct aer_err_info might be big, so we allocate it with slab */ |
| 781 | e_info = kmalloc(sizeof(struct aer_err_info), GFP_KERNEL); |
| 782 | if (e_info == NULL) { |
| 783 | dev_printk(KERN_DEBUG, &p_device->port->dev, |
| 784 | "Can't allocate mem when processing AER errors\n"); |
| 785 | return; |
| 786 | } |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 787 | |
| 788 | /* |
| 789 | * There is a possibility that both correctable error and |
| 790 | * uncorrectable error being logged. Report correctable error first. |
| 791 | */ |
| 792 | for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) { |
| 793 | if (i > 4) |
| 794 | break; |
| 795 | if (!(e_src->status & i)) |
| 796 | continue; |
| 797 | |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 798 | memset(e_info, 0, sizeof(struct aer_err_info)); |
| 799 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 800 | /* Init comprehensive error information */ |
| 801 | if (i & PCI_ERR_ROOT_COR_RCV) { |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 802 | e_info->id = ERR_COR_ID(e_src->id); |
| 803 | e_info->severity = AER_CORRECTABLE; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 804 | } else { |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 805 | e_info->id = ERR_UNCOR_ID(e_src->id); |
| 806 | e_info->severity = ((e_src->status >> 6) & 1); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 807 | } |
| 808 | if (e_src->status & |
| 809 | (PCI_ERR_ROOT_MULTI_COR_RCV | |
| 810 | PCI_ERR_ROOT_MULTI_UNCOR_RCV)) |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 811 | e_info->flags |= AER_MULTI_ERROR_VALID_FLAG; |
| 812 | |
| 813 | find_source_device(p_device->port, e_info); |
Zhang, Yanmin | 3d5505c | 2009-06-16 13:35:16 +0800 | [diff] [blame] | 814 | aer_process_err_devices(p_device, e_info); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 815 | } |
Zhang, Yanmin | 28eb27c | 2009-06-16 13:35:11 +0800 | [diff] [blame] | 816 | |
| 817 | kfree(e_info); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * aer_isr - consume errors detected by root port |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 822 | * @work: definition of this work item |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 823 | * |
| 824 | * Invoked, as DPC, when root port records new detected error |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 825 | */ |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 826 | void aer_isr(struct work_struct *work) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 827 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 828 | struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler); |
| 829 | struct pcie_device *p_device = rpc->rpd; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 830 | struct aer_err_source *e_src; |
| 831 | |
| 832 | mutex_lock(&rpc->rpc_mutex); |
| 833 | e_src = get_e_source(rpc); |
| 834 | while (e_src) { |
| 835 | aer_isr_one_error(p_device, e_src); |
| 836 | e_src = get_e_source(rpc); |
| 837 | } |
| 838 | mutex_unlock(&rpc->rpc_mutex); |
| 839 | |
| 840 | wake_up(&rpc->wait_release); |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * aer_delete_rootport - disable root port aer and delete service data |
| 845 | * @rpc: pointer to a root port device being deleted |
| 846 | * |
| 847 | * Invoked when AER service unloaded on a specific Root Port |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 848 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 849 | void aer_delete_rootport(struct aer_rpc *rpc) |
| 850 | { |
| 851 | /* Disable root port AER itself */ |
| 852 | disable_root_aer(rpc); |
| 853 | |
| 854 | kfree(rpc); |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * aer_init - provide AER initialization |
| 859 | * @dev: pointer to AER pcie device |
| 860 | * |
| 861 | * Invoked when AER service driver is loaded. |
Randy Dunlap | d885c6b | 2007-11-28 09:04:23 -0800 | [diff] [blame] | 862 | */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 863 | int aer_init(struct pcie_device *dev) |
| 864 | { |
Zhang, Yanmin | 8d29bfb | 2007-06-06 11:44:16 +0800 | [diff] [blame] | 865 | if (aer_osc_setup(dev) && !forceload) |
| 866 | return -ENXIO; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 867 | |
| 868 | return AER_SUCCESS; |
| 869 | } |