Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * eeh.c |
| 3 | * Copyright (C) 2001 Dave Engebretsen & Todd Inglett IBM Corporation |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/pci.h> |
| 23 | #include <linux/proc_fs.h> |
| 24 | #include <linux/rbtree.h> |
| 25 | #include <linux/seq_file.h> |
| 26 | #include <linux/spinlock.h> |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 27 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/eeh.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame^] | 29 | #include <asm/eeh_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/io.h> |
| 31 | #include <asm/machdep.h> |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 32 | #include <asm/ppc-pci.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame^] | 33 | #include <asm/rtas.h> |
| 34 | #include <asm/systemcfg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #undef DEBUG |
| 37 | |
| 38 | /** Overview: |
| 39 | * EEH, or "Extended Error Handling" is a PCI bridge technology for |
| 40 | * dealing with PCI bus errors that can't be dealt with within the |
| 41 | * usual PCI framework, except by check-stopping the CPU. Systems |
| 42 | * that are designed for high-availability/reliability cannot afford |
| 43 | * to crash due to a "mere" PCI error, thus the need for EEH. |
| 44 | * An EEH-capable bridge operates by converting a detected error |
| 45 | * into a "slot freeze", taking the PCI adapter off-line, making |
| 46 | * the slot behave, from the OS'es point of view, as if the slot |
| 47 | * were "empty": all reads return 0xff's and all writes are silently |
| 48 | * ignored. EEH slot isolation events can be triggered by parity |
| 49 | * errors on the address or data busses (e.g. during posted writes), |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 50 | * which in turn might be caused by low voltage on the bus, dust, |
| 51 | * vibration, humidity, radioactivity or plain-old failed hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * |
| 53 | * Note, however, that one of the leading causes of EEH slot |
| 54 | * freeze events are buggy device drivers, buggy device microcode, |
| 55 | * or buggy device hardware. This is because any attempt by the |
| 56 | * device to bus-master data to a memory address that is not |
| 57 | * assigned to the device will trigger a slot freeze. (The idea |
| 58 | * is to prevent devices-gone-wild from corrupting system memory). |
| 59 | * Buggy hardware/drivers will have a miserable time co-existing |
| 60 | * with EEH. |
| 61 | * |
| 62 | * Ideally, a PCI device driver, when suspecting that an isolation |
| 63 | * event has occured (e.g. by reading 0xff's), will then ask EEH |
| 64 | * whether this is the case, and then take appropriate steps to |
| 65 | * reset the PCI slot, the PCI device, and then resume operations. |
| 66 | * However, until that day, the checking is done here, with the |
| 67 | * eeh_check_failure() routine embedded in the MMIO macros. If |
| 68 | * the slot is found to be isolated, an "EEH Event" is synthesized |
| 69 | * and sent out for processing. |
| 70 | */ |
| 71 | |
Linas Vepstas | 5c1344e | 2005-11-03 18:49:31 -0600 | [diff] [blame] | 72 | /* If a device driver keeps reading an MMIO register in an interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | * handler after a slot isolation event has occurred, we assume it |
| 74 | * is broken and panic. This sets the threshold for how many read |
| 75 | * attempts we allow before panicking. |
| 76 | */ |
Linas Vepstas | 5c1344e | 2005-11-03 18:49:31 -0600 | [diff] [blame] | 77 | #define EEH_MAX_FAILS 100000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* RTAS tokens */ |
| 80 | static int ibm_set_eeh_option; |
| 81 | static int ibm_set_slot_reset; |
| 82 | static int ibm_read_slot_reset_state; |
| 83 | static int ibm_read_slot_reset_state2; |
| 84 | static int ibm_slot_error_detail; |
| 85 | |
| 86 | static int eeh_subsystem_enabled; |
| 87 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 88 | /* Lock to avoid races due to multiple reports of an error */ |
| 89 | static DEFINE_SPINLOCK(confirm_error_lock); |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Buffer for reporting slot-error-detail rtas calls */ |
| 92 | static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX]; |
| 93 | static DEFINE_SPINLOCK(slot_errbuf_lock); |
| 94 | static int eeh_error_buf_size; |
| 95 | |
| 96 | /* System monitoring statistics */ |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 97 | static DEFINE_PER_CPU(unsigned long, no_device); |
| 98 | static DEFINE_PER_CPU(unsigned long, no_dn); |
| 99 | static DEFINE_PER_CPU(unsigned long, no_cfg_addr); |
| 100 | static DEFINE_PER_CPU(unsigned long, ignored_check); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static DEFINE_PER_CPU(unsigned long, total_mmio_ffs); |
| 102 | static DEFINE_PER_CPU(unsigned long, false_positives); |
| 103 | static DEFINE_PER_CPU(unsigned long, ignored_failures); |
| 104 | static DEFINE_PER_CPU(unsigned long, slot_resets); |
| 105 | |
| 106 | /** |
| 107 | * The pci address cache subsystem. This subsystem places |
| 108 | * PCI device address resources into a red-black tree, sorted |
| 109 | * according to the address range, so that given only an i/o |
| 110 | * address, the corresponding PCI device can be **quickly** |
| 111 | * found. It is safe to perform an address lookup in an interrupt |
| 112 | * context; this ability is an important feature. |
| 113 | * |
| 114 | * Currently, the only customer of this code is the EEH subsystem; |
| 115 | * thus, this code has been somewhat tailored to suit EEH better. |
| 116 | * In particular, the cache does *not* hold the addresses of devices |
| 117 | * for which EEH is not enabled. |
| 118 | * |
| 119 | * (Implementation Note: The RB tree seems to be better/faster |
| 120 | * than any hash algo I could think of for this problem, even |
| 121 | * with the penalty of slow pointer chases for d-cache misses). |
| 122 | */ |
| 123 | struct pci_io_addr_range |
| 124 | { |
| 125 | struct rb_node rb_node; |
| 126 | unsigned long addr_lo; |
| 127 | unsigned long addr_hi; |
| 128 | struct pci_dev *pcidev; |
| 129 | unsigned int flags; |
| 130 | }; |
| 131 | |
| 132 | static struct pci_io_addr_cache |
| 133 | { |
| 134 | struct rb_root rb_root; |
| 135 | spinlock_t piar_lock; |
| 136 | } pci_io_addr_cache_root; |
| 137 | |
| 138 | static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr) |
| 139 | { |
| 140 | struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node; |
| 141 | |
| 142 | while (n) { |
| 143 | struct pci_io_addr_range *piar; |
| 144 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
| 145 | |
| 146 | if (addr < piar->addr_lo) { |
| 147 | n = n->rb_left; |
| 148 | } else { |
| 149 | if (addr > piar->addr_hi) { |
| 150 | n = n->rb_right; |
| 151 | } else { |
| 152 | pci_dev_get(piar->pcidev); |
| 153 | return piar->pcidev; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return NULL; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * pci_get_device_by_addr - Get device, given only address |
| 163 | * @addr: mmio (PIO) phys address or i/o port number |
| 164 | * |
| 165 | * Given an mmio phys address, or a port number, find a pci device |
| 166 | * that implements this address. Be sure to pci_dev_put the device |
| 167 | * when finished. I/O port numbers are assumed to be offset |
| 168 | * from zero (that is, they do *not* have pci_io_addr added in). |
| 169 | * It is safe to call this function within an interrupt. |
| 170 | */ |
| 171 | static struct pci_dev *pci_get_device_by_addr(unsigned long addr) |
| 172 | { |
| 173 | struct pci_dev *dev; |
| 174 | unsigned long flags; |
| 175 | |
| 176 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
| 177 | dev = __pci_get_device_by_addr(addr); |
| 178 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
| 179 | return dev; |
| 180 | } |
| 181 | |
| 182 | #ifdef DEBUG |
| 183 | /* |
| 184 | * Handy-dandy debug print routine, does nothing more |
| 185 | * than print out the contents of our addr cache. |
| 186 | */ |
| 187 | static void pci_addr_cache_print(struct pci_io_addr_cache *cache) |
| 188 | { |
| 189 | struct rb_node *n; |
| 190 | int cnt = 0; |
| 191 | |
| 192 | n = rb_first(&cache->rb_root); |
| 193 | while (n) { |
| 194 | struct pci_io_addr_range *piar; |
| 195 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
Adrian Bunk | 982245f | 2005-07-17 04:22:20 +0200 | [diff] [blame] | 196 | printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt, |
Adrian Bunk | 982245f | 2005-07-17 04:22:20 +0200 | [diff] [blame] | 198 | piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | cnt++; |
| 200 | n = rb_next(n); |
| 201 | } |
| 202 | } |
| 203 | #endif |
| 204 | |
| 205 | /* Insert address range into the rb tree. */ |
| 206 | static struct pci_io_addr_range * |
| 207 | pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo, |
| 208 | unsigned long ahi, unsigned int flags) |
| 209 | { |
| 210 | struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node; |
| 211 | struct rb_node *parent = NULL; |
| 212 | struct pci_io_addr_range *piar; |
| 213 | |
| 214 | /* Walk tree, find a place to insert into tree */ |
| 215 | while (*p) { |
| 216 | parent = *p; |
| 217 | piar = rb_entry(parent, struct pci_io_addr_range, rb_node); |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 218 | if (ahi < piar->addr_lo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | p = &parent->rb_left; |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 220 | } else if (alo > piar->addr_hi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | p = &parent->rb_right; |
| 222 | } else { |
| 223 | if (dev != piar->pcidev || |
| 224 | alo != piar->addr_lo || ahi != piar->addr_hi) { |
| 225 | printk(KERN_WARNING "PIAR: overlapping address range\n"); |
| 226 | } |
| 227 | return piar; |
| 228 | } |
| 229 | } |
| 230 | piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC); |
| 231 | if (!piar) |
| 232 | return NULL; |
| 233 | |
| 234 | piar->addr_lo = alo; |
| 235 | piar->addr_hi = ahi; |
| 236 | piar->pcidev = dev; |
| 237 | piar->flags = flags; |
| 238 | |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 239 | #ifdef DEBUG |
| 240 | printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n", |
| 241 | alo, ahi, pci_name (dev)); |
| 242 | #endif |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | rb_link_node(&piar->rb_node, parent, p); |
| 245 | rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root); |
| 246 | |
| 247 | return piar; |
| 248 | } |
| 249 | |
| 250 | static void __pci_addr_cache_insert_device(struct pci_dev *dev) |
| 251 | { |
| 252 | struct device_node *dn; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 253 | struct pci_dn *pdn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | int i; |
| 255 | int inserted = 0; |
| 256 | |
| 257 | dn = pci_device_to_OF_node(dev); |
| 258 | if (!dn) { |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 259 | printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
| 263 | /* Skip any devices for which EEH is not enabled. */ |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 264 | pdn = PCI_DN(dn); |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 265 | if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) || |
| 266 | pdn->eeh_mode & EEH_MODE_NOCHECK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | #ifdef DEBUG |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 268 | printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n", |
| 269 | pci_name(dev), pdn->node->full_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | #endif |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | /* The cache holds a reference to the device... */ |
| 275 | pci_dev_get(dev); |
| 276 | |
| 277 | /* Walk resources on this device, poke them into the tree */ |
| 278 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 279 | unsigned long start = pci_resource_start(dev,i); |
| 280 | unsigned long end = pci_resource_end(dev,i); |
| 281 | unsigned int flags = pci_resource_flags(dev,i); |
| 282 | |
| 283 | /* We are interested only bus addresses, not dma or other stuff */ |
| 284 | if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM))) |
| 285 | continue; |
| 286 | if (start == 0 || ~start == 0 || end == 0 || ~end == 0) |
| 287 | continue; |
| 288 | pci_addr_cache_insert(dev, start, end, flags); |
| 289 | inserted = 1; |
| 290 | } |
| 291 | |
| 292 | /* If there was nothing to add, the cache has no reference... */ |
| 293 | if (!inserted) |
| 294 | pci_dev_put(dev); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * pci_addr_cache_insert_device - Add a device to the address cache |
| 299 | * @dev: PCI device whose I/O addresses we are interested in. |
| 300 | * |
| 301 | * In order to support the fast lookup of devices based on addresses, |
| 302 | * we maintain a cache of devices that can be quickly searched. |
| 303 | * This routine adds a device to that cache. |
| 304 | */ |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 305 | static void pci_addr_cache_insert_device(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | unsigned long flags; |
| 308 | |
| 309 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
| 310 | __pci_addr_cache_insert_device(dev); |
| 311 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
| 312 | } |
| 313 | |
| 314 | static inline void __pci_addr_cache_remove_device(struct pci_dev *dev) |
| 315 | { |
| 316 | struct rb_node *n; |
| 317 | int removed = 0; |
| 318 | |
| 319 | restart: |
| 320 | n = rb_first(&pci_io_addr_cache_root.rb_root); |
| 321 | while (n) { |
| 322 | struct pci_io_addr_range *piar; |
| 323 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
| 324 | |
| 325 | if (piar->pcidev == dev) { |
| 326 | rb_erase(n, &pci_io_addr_cache_root.rb_root); |
| 327 | removed = 1; |
| 328 | kfree(piar); |
| 329 | goto restart; |
| 330 | } |
| 331 | n = rb_next(n); |
| 332 | } |
| 333 | |
| 334 | /* The cache no longer holds its reference to this device... */ |
| 335 | if (removed) |
| 336 | pci_dev_put(dev); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * pci_addr_cache_remove_device - remove pci device from addr cache |
| 341 | * @dev: device to remove |
| 342 | * |
| 343 | * Remove a device from the addr-cache tree. |
| 344 | * This is potentially expensive, since it will walk |
| 345 | * the tree multiple times (once per resource). |
| 346 | * But so what; device removal doesn't need to be that fast. |
| 347 | */ |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 348 | static void pci_addr_cache_remove_device(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | unsigned long flags; |
| 351 | |
| 352 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
| 353 | __pci_addr_cache_remove_device(dev); |
| 354 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * pci_addr_cache_build - Build a cache of I/O addresses |
| 359 | * |
| 360 | * Build a cache of pci i/o addresses. This cache will be used to |
| 361 | * find the pci device that corresponds to a given address. |
| 362 | * This routine scans all pci busses to build the cache. |
| 363 | * Must be run late in boot process, after the pci controllers |
| 364 | * have been scaned for devices (after all device resources are known). |
| 365 | */ |
| 366 | void __init pci_addr_cache_build(void) |
| 367 | { |
| 368 | struct pci_dev *dev = NULL; |
| 369 | |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 370 | if (!eeh_subsystem_enabled) |
| 371 | return; |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | spin_lock_init(&pci_io_addr_cache_root.piar_lock); |
| 374 | |
| 375 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
| 376 | /* Ignore PCI bridges ( XXX why ??) */ |
| 377 | if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) { |
| 378 | continue; |
| 379 | } |
| 380 | pci_addr_cache_insert_device(dev); |
| 381 | } |
| 382 | |
| 383 | #ifdef DEBUG |
| 384 | /* Verify tree built up above, echo back the list of addrs. */ |
| 385 | pci_addr_cache_print(&pci_io_addr_cache_root); |
| 386 | #endif |
| 387 | } |
| 388 | |
| 389 | /* --------------------------------------------------------------- */ |
| 390 | /* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */ |
| 391 | |
Linas Vepstas | df7242b | 2005-11-03 18:49:01 -0600 | [diff] [blame] | 392 | void eeh_slot_error_detail (struct pci_dn *pdn, int severity) |
| 393 | { |
| 394 | unsigned long flags; |
| 395 | int rc; |
| 396 | |
| 397 | /* Log the error with the rtas logger */ |
| 398 | spin_lock_irqsave(&slot_errbuf_lock, flags); |
| 399 | memset(slot_errbuf, 0, eeh_error_buf_size); |
| 400 | |
| 401 | rc = rtas_call(ibm_slot_error_detail, |
| 402 | 8, 1, NULL, pdn->eeh_config_addr, |
| 403 | BUID_HI(pdn->phb->buid), |
| 404 | BUID_LO(pdn->phb->buid), NULL, 0, |
| 405 | virt_to_phys(slot_errbuf), |
| 406 | eeh_error_buf_size, |
| 407 | severity); |
| 408 | |
| 409 | if (rc == 0) |
| 410 | log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0); |
| 411 | spin_unlock_irqrestore(&slot_errbuf_lock, flags); |
| 412 | } |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | * read_slot_reset_state - Read the reset state of a device node's slot |
| 416 | * @dn: device node to read |
| 417 | * @rets: array to return results in |
| 418 | */ |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 419 | static int read_slot_reset_state(struct pci_dn *pdn, int rets[]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
| 421 | int token, outputs; |
| 422 | |
| 423 | if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) { |
| 424 | token = ibm_read_slot_reset_state2; |
| 425 | outputs = 4; |
| 426 | } else { |
| 427 | token = ibm_read_slot_reset_state; |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 428 | rets[2] = 0; /* fake PE Unavailable info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | outputs = 3; |
| 430 | } |
| 431 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 432 | return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr, |
| 433 | BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * eeh_token_to_phys - convert EEH address token to phys address |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 438 | * @token i/o token, should be address in the form 0xA.... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | */ |
| 440 | static inline unsigned long eeh_token_to_phys(unsigned long token) |
| 441 | { |
| 442 | pte_t *ptep; |
| 443 | unsigned long pa; |
| 444 | |
David Gibson | 20cee16 | 2005-06-21 17:15:31 -0700 | [diff] [blame] | 445 | ptep = find_linux_pte(init_mm.pgd, token); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (!ptep) |
| 447 | return token; |
| 448 | pa = pte_pfn(*ptep) << PAGE_SHIFT; |
| 449 | |
| 450 | return pa | (token & (PAGE_SIZE-1)); |
| 451 | } |
| 452 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 453 | /** |
| 454 | * Return the "partitionable endpoint" (pe) under which this device lies |
| 455 | */ |
| 456 | static struct device_node * find_device_pe(struct device_node *dn) |
| 457 | { |
| 458 | while ((dn->parent) && PCI_DN(dn->parent) && |
| 459 | (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) { |
| 460 | dn = dn->parent; |
| 461 | } |
| 462 | return dn; |
| 463 | } |
| 464 | |
| 465 | /** Mark all devices that are peers of this device as failed. |
| 466 | * Mark the device driver too, so that it can see the failure |
| 467 | * immediately; this is critical, since some drivers poll |
| 468 | * status registers in interrupts ... If a driver is polling, |
| 469 | * and the slot is frozen, then the driver can deadlock in |
| 470 | * an interrupt context, which is bad. |
| 471 | */ |
| 472 | |
| 473 | static inline void __eeh_mark_slot (struct device_node *dn) |
| 474 | { |
| 475 | while (dn) { |
| 476 | PCI_DN(dn)->eeh_mode |= EEH_MODE_ISOLATED; |
| 477 | |
| 478 | if (dn->child) |
| 479 | __eeh_mark_slot (dn->child); |
| 480 | dn = dn->sibling; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | static inline void __eeh_clear_slot (struct device_node *dn) |
| 485 | { |
| 486 | while (dn) { |
| 487 | PCI_DN(dn)->eeh_mode &= ~EEH_MODE_ISOLATED; |
| 488 | if (dn->child) |
| 489 | __eeh_clear_slot (dn->child); |
| 490 | dn = dn->sibling; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static inline void eeh_clear_slot (struct device_node *dn) |
| 495 | { |
| 496 | unsigned long flags; |
| 497 | spin_lock_irqsave(&confirm_error_lock, flags); |
| 498 | __eeh_clear_slot (dn); |
| 499 | spin_unlock_irqrestore(&confirm_error_lock, flags); |
| 500 | } |
| 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | /** |
| 503 | * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze |
| 504 | * @dn device node |
| 505 | * @dev pci device, if known |
| 506 | * |
| 507 | * Check for an EEH failure for the given device node. Call this |
| 508 | * routine if the result of a read was all 0xff's and you want to |
| 509 | * find out if this is due to an EEH slot freeze. This routine |
| 510 | * will query firmware for the EEH status. |
| 511 | * |
| 512 | * Returns 0 if there has not been an EEH error; otherwise returns |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 513 | * a non-zero value and queues up a slot isolation event notification. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | * |
| 515 | * It is safe to call this routine in an interrupt context. |
| 516 | */ |
| 517 | int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev) |
| 518 | { |
| 519 | int ret; |
| 520 | int rets[3]; |
| 521 | unsigned long flags; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 522 | struct pci_dn *pdn; |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 523 | struct device_node *pe_dn; |
| 524 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | __get_cpu_var(total_mmio_ffs)++; |
| 527 | |
| 528 | if (!eeh_subsystem_enabled) |
| 529 | return 0; |
| 530 | |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 531 | if (!dn) { |
| 532 | __get_cpu_var(no_dn)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | return 0; |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 534 | } |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 535 | pdn = PCI_DN(dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | /* Access to IO BARs might get this far and still not want checking. */ |
Linas Vepstas | f8632c8 | 2005-11-03 18:49:45 -0600 | [diff] [blame] | 538 | if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) || |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 539 | pdn->eeh_mode & EEH_MODE_NOCHECK) { |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 540 | __get_cpu_var(ignored_check)++; |
| 541 | #ifdef DEBUG |
Linas Vepstas | f8632c8 | 2005-11-03 18:49:45 -0600 | [diff] [blame] | 542 | printk ("EEH:ignored check (%x) for %s %s\n", |
| 543 | pdn->eeh_mode, pci_name (dev), dn->full_name); |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 544 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 548 | if (!pdn->eeh_config_addr) { |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 549 | __get_cpu_var(no_cfg_addr)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | return 0; |
| 551 | } |
| 552 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 553 | /* If we already have a pending isolation event for this |
| 554 | * slot, we know it's bad already, we don't need to check. |
| 555 | * Do this checking under a lock; as multiple PCI devices |
| 556 | * in one slot might report errors simultaneously, and we |
| 557 | * only want one error recovery routine running. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | */ |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 559 | spin_lock_irqsave(&confirm_error_lock, flags); |
| 560 | rc = 1; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 561 | if (pdn->eeh_mode & EEH_MODE_ISOLATED) { |
Linas Vepstas | 5c1344e | 2005-11-03 18:49:31 -0600 | [diff] [blame] | 562 | pdn->eeh_check_count ++; |
| 563 | if (pdn->eeh_check_count >= EEH_MAX_FAILS) { |
| 564 | printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n", |
| 565 | pdn->eeh_check_count); |
| 566 | dump_stack(); |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* re-read the slot reset state */ |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 569 | if (read_slot_reset_state(pdn, rets) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | rets[0] = -1; /* reset state unknown */ |
Linas Vepstas | 5c1344e | 2005-11-03 18:49:31 -0600 | [diff] [blame] | 571 | |
| 572 | /* If we are here, then we hit an infinite loop. Stop. */ |
| 573 | panic("EEH: MMIO halt (%d) on device:%s\n", rets[0], pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 575 | goto dn_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* |
| 579 | * Now test for an EEH failure. This is VERY expensive. |
| 580 | * Note that the eeh_config_addr may be a parent device |
| 581 | * in the case of a device behind a bridge, or it may be |
| 582 | * function zero of a multi-function device. |
| 583 | * In any case they must share a common PHB. |
| 584 | */ |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 585 | ret = read_slot_reset_state(pdn, rets); |
Linas Vepstas | 76e6faf | 2005-11-03 18:49:15 -0600 | [diff] [blame] | 586 | |
| 587 | /* If the call to firmware failed, punt */ |
| 588 | if (ret != 0) { |
| 589 | printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n", |
| 590 | ret, dn->full_name); |
| 591 | __get_cpu_var(false_positives)++; |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 592 | rc = 0; |
| 593 | goto dn_unlock; |
Linas Vepstas | 76e6faf | 2005-11-03 18:49:15 -0600 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /* If EEH is not supported on this device, punt. */ |
| 597 | if (rets[1] != 1) { |
| 598 | printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n", |
| 599 | ret, dn->full_name); |
| 600 | __get_cpu_var(false_positives)++; |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 601 | rc = 0; |
| 602 | goto dn_unlock; |
Linas Vepstas | 76e6faf | 2005-11-03 18:49:15 -0600 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /* If not the kind of error we know about, punt. */ |
| 606 | if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) { |
| 607 | __get_cpu_var(false_positives)++; |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 608 | rc = 0; |
| 609 | goto dn_unlock; |
Linas Vepstas | 76e6faf | 2005-11-03 18:49:15 -0600 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* Note that config-io to empty slots may fail; |
| 613 | * we recognize empty because they don't have children. */ |
| 614 | if ((rets[0] == 5) && (dn->child == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | __get_cpu_var(false_positives)++; |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 616 | rc = 0; |
| 617 | goto dn_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 620 | __get_cpu_var(slot_resets)++; |
| 621 | |
| 622 | /* Avoid repeated reports of this failure, including problems |
| 623 | * with other functions on this device, and functions under |
| 624 | * bridges. */ |
| 625 | pe_dn = find_device_pe (dn); |
| 626 | __eeh_mark_slot (pe_dn); |
| 627 | spin_unlock_irqrestore(&confirm_error_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame^] | 629 | eeh_send_failure_event (dn, dev, rets[0], rets[2]); |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | /* Most EEH events are due to device driver bugs. Having |
| 632 | * a stack trace will help the device-driver authors figure |
| 633 | * out what happened. So print that out. */ |
Linas Vepstas | 76e6faf | 2005-11-03 18:49:15 -0600 | [diff] [blame] | 634 | if (rets[0] != 5) dump_stack(); |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 635 | return 1; |
| 636 | |
| 637 | dn_unlock: |
| 638 | spin_unlock_irqrestore(&confirm_error_lock, flags); |
| 639 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 642 | EXPORT_SYMBOL_GPL(eeh_dn_check_failure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * eeh_check_failure - check if all 1's data is due to EEH slot freeze |
| 646 | * @token i/o token, should be address in the form 0xA.... |
| 647 | * @val value, should be all 1's (XXX why do we need this arg??) |
| 648 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | * Check for an EEH failure at the given token address. Call this |
| 650 | * routine if the result of a read was all 0xff's and you want to |
| 651 | * find out if this is due to an EEH slot freeze event. This routine |
| 652 | * will query firmware for the EEH status. |
| 653 | * |
| 654 | * Note this routine is safe to call in an interrupt context. |
| 655 | */ |
| 656 | unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val) |
| 657 | { |
| 658 | unsigned long addr; |
| 659 | struct pci_dev *dev; |
| 660 | struct device_node *dn; |
| 661 | |
| 662 | /* Finding the phys addr + pci device; this is pretty quick. */ |
| 663 | addr = eeh_token_to_phys((unsigned long __force) token); |
| 664 | dev = pci_get_device_by_addr(addr); |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 665 | if (!dev) { |
| 666 | __get_cpu_var(no_device)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return val; |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | dn = pci_device_to_OF_node(dev); |
| 671 | eeh_dn_check_failure (dn, dev); |
| 672 | |
| 673 | pci_dev_put(dev); |
| 674 | return val; |
| 675 | } |
| 676 | |
| 677 | EXPORT_SYMBOL(eeh_check_failure); |
| 678 | |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame^] | 679 | /* ------------------------------------------------------------- */ |
| 680 | /* The code below deals with enabling EEH for devices during the |
| 681 | * early boot sequence. EEH must be enabled before any PCI probing |
| 682 | * can be done. |
| 683 | */ |
| 684 | |
| 685 | #define EEH_ENABLE 1 |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | struct eeh_early_enable_info { |
| 688 | unsigned int buid_hi; |
| 689 | unsigned int buid_lo; |
| 690 | }; |
| 691 | |
| 692 | /* Enable eeh for the given device node. */ |
| 693 | static void *early_enable_eeh(struct device_node *dn, void *data) |
| 694 | { |
| 695 | struct eeh_early_enable_info *info = data; |
| 696 | int ret; |
| 697 | char *status = get_property(dn, "status", NULL); |
| 698 | u32 *class_code = (u32 *)get_property(dn, "class-code", NULL); |
| 699 | u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL); |
| 700 | u32 *device_id = (u32 *)get_property(dn, "device-id", NULL); |
| 701 | u32 *regs; |
| 702 | int enable; |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 703 | struct pci_dn *pdn = PCI_DN(dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 705 | pdn->eeh_mode = 0; |
Linas Vepstas | 5c1344e | 2005-11-03 18:49:31 -0600 | [diff] [blame] | 706 | pdn->eeh_check_count = 0; |
| 707 | pdn->eeh_freeze_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | if (status && strcmp(status, "ok") != 0) |
| 710 | return NULL; /* ignore devices with bad status */ |
| 711 | |
| 712 | /* Ignore bad nodes. */ |
| 713 | if (!class_code || !vendor_id || !device_id) |
| 714 | return NULL; |
| 715 | |
| 716 | /* There is nothing to check on PCI to ISA bridges */ |
| 717 | if (dn->type && !strcmp(dn->type, "isa")) { |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 718 | pdn->eeh_mode |= EEH_MODE_NOCHECK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return NULL; |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * Now decide if we are going to "Disable" EEH checking |
| 724 | * for this device. We still run with the EEH hardware active, |
| 725 | * but we won't be checking for ff's. This means a driver |
| 726 | * could return bad data (very bad!), an interrupt handler could |
| 727 | * hang waiting on status bits that won't change, etc. |
| 728 | * But there are a few cases like display devices that make sense. |
| 729 | */ |
| 730 | enable = 1; /* i.e. we will do checking */ |
| 731 | if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY) |
| 732 | enable = 0; |
| 733 | |
| 734 | if (!enable) |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 735 | pdn->eeh_mode |= EEH_MODE_NOCHECK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | /* Ok... see if this device supports EEH. Some do, some don't, |
| 738 | * and the only way to find out is to check each and every one. */ |
| 739 | regs = (u32 *)get_property(dn, "reg", NULL); |
| 740 | if (regs) { |
| 741 | /* First register entry is addr (00BBSS00) */ |
| 742 | /* Try to enable eeh */ |
| 743 | ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL, |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame^] | 744 | regs[0], info->buid_hi, info->buid_lo, |
| 745 | EEH_ENABLE); |
| 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (ret == 0) { |
| 748 | eeh_subsystem_enabled = 1; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 749 | pdn->eeh_mode |= EEH_MODE_SUPPORTED; |
| 750 | pdn->eeh_config_addr = regs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | #ifdef DEBUG |
| 752 | printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name); |
| 753 | #endif |
| 754 | } else { |
| 755 | |
| 756 | /* This device doesn't support EEH, but it may have an |
| 757 | * EEH parent, in which case we mark it as supported. */ |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 758 | if (dn->parent && PCI_DN(dn->parent) |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 759 | && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | /* Parent supports EEH. */ |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 761 | pdn->eeh_mode |= EEH_MODE_SUPPORTED; |
| 762 | pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | return NULL; |
| 764 | } |
| 765 | } |
| 766 | } else { |
| 767 | printk(KERN_WARNING "EEH: %s: unable to get reg property.\n", |
| 768 | dn->full_name); |
| 769 | } |
| 770 | |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 771 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Initialize EEH by trying to enable it for all of the adapters in the system. |
| 776 | * As a side effect we can determine here if eeh is supported at all. |
| 777 | * Note that we leave EEH on so failed config cycles won't cause a machine |
| 778 | * check. If a user turns off EEH for a particular adapter they are really |
| 779 | * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't |
| 780 | * grant access to a slot if EEH isn't enabled, and so we always enable |
| 781 | * EEH for all slots/all devices. |
| 782 | * |
| 783 | * The eeh-force-off option disables EEH checking globally, for all slots. |
| 784 | * Even if force-off is set, the EEH hardware is still enabled, so that |
| 785 | * newer systems can boot. |
| 786 | */ |
| 787 | void __init eeh_init(void) |
| 788 | { |
| 789 | struct device_node *phb, *np; |
| 790 | struct eeh_early_enable_info info; |
| 791 | |
Linas Vepstas | fd761fd | 2005-11-03 18:49:23 -0600 | [diff] [blame] | 792 | spin_lock_init(&confirm_error_lock); |
Linas Vepstas | df7242b | 2005-11-03 18:49:01 -0600 | [diff] [blame] | 793 | spin_lock_init(&slot_errbuf_lock); |
| 794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | np = of_find_node_by_path("/rtas"); |
| 796 | if (np == NULL) |
| 797 | return; |
| 798 | |
| 799 | ibm_set_eeh_option = rtas_token("ibm,set-eeh-option"); |
| 800 | ibm_set_slot_reset = rtas_token("ibm,set-slot-reset"); |
| 801 | ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2"); |
| 802 | ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state"); |
| 803 | ibm_slot_error_detail = rtas_token("ibm,slot-error-detail"); |
| 804 | |
| 805 | if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE) |
| 806 | return; |
| 807 | |
| 808 | eeh_error_buf_size = rtas_token("rtas-error-log-max"); |
| 809 | if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) { |
| 810 | eeh_error_buf_size = 1024; |
| 811 | } |
| 812 | if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) { |
| 813 | printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated " |
| 814 | "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX); |
| 815 | eeh_error_buf_size = RTAS_ERROR_LOG_MAX; |
| 816 | } |
| 817 | |
| 818 | /* Enable EEH for all adapters. Note that eeh requires buid's */ |
| 819 | for (phb = of_find_node_by_name(NULL, "pci"); phb; |
| 820 | phb = of_find_node_by_name(phb, "pci")) { |
| 821 | unsigned long buid; |
| 822 | |
| 823 | buid = get_phb_buid(phb); |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 824 | if (buid == 0 || PCI_DN(phb) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | continue; |
| 826 | |
| 827 | info.buid_lo = BUID_LO(buid); |
| 828 | info.buid_hi = BUID_HI(buid); |
| 829 | traverse_pci_devices(phb, early_enable_eeh, &info); |
| 830 | } |
| 831 | |
| 832 | if (eeh_subsystem_enabled) |
| 833 | printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n"); |
| 834 | else |
| 835 | printk(KERN_WARNING "EEH: No capable adapters found\n"); |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * eeh_add_device_early - enable EEH for the indicated device_node |
| 840 | * @dn: device node for which to set up EEH |
| 841 | * |
| 842 | * This routine must be used to perform EEH initialization for PCI |
| 843 | * devices that were added after system boot (e.g. hotplug, dlpar). |
| 844 | * This routine must be called before any i/o is performed to the |
| 845 | * adapter (inluding any config-space i/o). |
| 846 | * Whether this actually enables EEH or not for this device depends |
| 847 | * on the CEC architecture, type of the device, on earlier boot |
| 848 | * command-line arguments & etc. |
| 849 | */ |
| 850 | void eeh_add_device_early(struct device_node *dn) |
| 851 | { |
| 852 | struct pci_controller *phb; |
| 853 | struct eeh_early_enable_info info; |
| 854 | |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 855 | if (!dn || !PCI_DN(dn)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | return; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 857 | phb = PCI_DN(dn)->phb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | if (NULL == phb || 0 == phb->buid) { |
Linas Vepstas | 6937650 | 2005-11-03 18:47:50 -0600 | [diff] [blame] | 859 | printk(KERN_WARNING "EEH: Expected buid but found none for %s\n", |
| 860 | dn->full_name); |
| 861 | dump_stack(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | return; |
| 863 | } |
| 864 | |
| 865 | info.buid_hi = BUID_HI(phb->buid); |
| 866 | info.buid_lo = BUID_LO(phb->buid); |
| 867 | early_enable_eeh(dn, &info); |
| 868 | } |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 869 | EXPORT_SYMBOL_GPL(eeh_add_device_early); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * eeh_add_device_late - perform EEH initialization for the indicated pci device |
| 873 | * @dev: pci device for which to set up EEH |
| 874 | * |
| 875 | * This routine must be used to complete EEH initialization for PCI |
| 876 | * devices that were added after system boot (e.g. hotplug, dlpar). |
| 877 | */ |
| 878 | void eeh_add_device_late(struct pci_dev *dev) |
| 879 | { |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 880 | struct device_node *dn; |
| 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | if (!dev || !eeh_subsystem_enabled) |
| 883 | return; |
| 884 | |
| 885 | #ifdef DEBUG |
Adrian Bunk | 982245f | 2005-07-17 04:22:20 +0200 | [diff] [blame] | 886 | printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | #endif |
| 888 | |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 889 | pci_dev_get (dev); |
| 890 | dn = pci_device_to_OF_node(dev); |
| 891 | PCI_DN(dn)->pcidev = dev; |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | pci_addr_cache_insert_device (dev); |
| 894 | } |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 895 | EXPORT_SYMBOL_GPL(eeh_add_device_late); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | /** |
| 898 | * eeh_remove_device - undo EEH setup for the indicated pci device |
| 899 | * @dev: pci device to be removed |
| 900 | * |
| 901 | * This routine should be when a device is removed from a running |
| 902 | * system (e.g. by hotplug or dlpar). |
| 903 | */ |
| 904 | void eeh_remove_device(struct pci_dev *dev) |
| 905 | { |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 906 | struct device_node *dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if (!dev || !eeh_subsystem_enabled) |
| 908 | return; |
| 909 | |
| 910 | /* Unregister the device with the EEH/PCI address search system */ |
| 911 | #ifdef DEBUG |
Adrian Bunk | 982245f | 2005-07-17 04:22:20 +0200 | [diff] [blame] | 912 | printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | #endif |
| 914 | pci_addr_cache_remove_device(dev); |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 915 | |
| 916 | dn = pci_device_to_OF_node(dev); |
| 917 | PCI_DN(dn)->pcidev = NULL; |
| 918 | pci_dev_put (dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
Linas Vepstas | 56b0fca | 2005-11-03 18:48:45 -0600 | [diff] [blame] | 920 | EXPORT_SYMBOL_GPL(eeh_remove_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
| 922 | static int proc_eeh_show(struct seq_file *m, void *v) |
| 923 | { |
| 924 | unsigned int cpu; |
| 925 | unsigned long ffs = 0, positives = 0, failures = 0; |
| 926 | unsigned long resets = 0; |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 927 | unsigned long no_dev = 0, no_dn = 0, no_cfg = 0, no_check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | for_each_cpu(cpu) { |
| 930 | ffs += per_cpu(total_mmio_ffs, cpu); |
| 931 | positives += per_cpu(false_positives, cpu); |
| 932 | failures += per_cpu(ignored_failures, cpu); |
| 933 | resets += per_cpu(slot_resets, cpu); |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 934 | no_dev += per_cpu(no_device, cpu); |
| 935 | no_dn += per_cpu(no_dn, cpu); |
| 936 | no_cfg += per_cpu(no_cfg_addr, cpu); |
| 937 | no_check += per_cpu(ignored_check, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | if (0 == eeh_subsystem_enabled) { |
| 941 | seq_printf(m, "EEH Subsystem is globally disabled\n"); |
| 942 | seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs); |
| 943 | } else { |
| 944 | seq_printf(m, "EEH Subsystem is enabled\n"); |
Linas Vepstas | 177bc93 | 2005-11-03 18:48:52 -0600 | [diff] [blame] | 945 | seq_printf(m, |
| 946 | "no device=%ld\n" |
| 947 | "no device node=%ld\n" |
| 948 | "no config address=%ld\n" |
| 949 | "check not wanted=%ld\n" |
| 950 | "eeh_total_mmio_ffs=%ld\n" |
| 951 | "eeh_false_positives=%ld\n" |
| 952 | "eeh_ignored_failures=%ld\n" |
| 953 | "eeh_slot_resets=%ld\n", |
| 954 | no_dev, no_dn, no_cfg, no_check, |
| 955 | ffs, positives, failures, resets); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | static int proc_eeh_open(struct inode *inode, struct file *file) |
| 962 | { |
| 963 | return single_open(file, proc_eeh_show, NULL); |
| 964 | } |
| 965 | |
| 966 | static struct file_operations proc_eeh_operations = { |
| 967 | .open = proc_eeh_open, |
| 968 | .read = seq_read, |
| 969 | .llseek = seq_lseek, |
| 970 | .release = single_release, |
| 971 | }; |
| 972 | |
| 973 | static int __init eeh_init_proc(void) |
| 974 | { |
| 975 | struct proc_dir_entry *e; |
| 976 | |
| 977 | if (systemcfg->platform & PLATFORM_PSERIES) { |
| 978 | e = create_proc_entry("ppc64/eeh", 0, NULL); |
| 979 | if (e) |
| 980 | e->proc_fops = &proc_eeh_operations; |
| 981 | } |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | __initcall(eeh_init_proc); |