blob: 0c52c2de92e02b43d6dbee63c98878c77bb76bfa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * eeh.c
3 * Copyright (C) 2001 Dave Engebretsen & Todd Inglett IBM Corporation
Linas Vepstas69376502005-11-03 18:47:50 -06004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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 Vepstas69376502005-11-03 18:47:50 -06009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 Vepstas69376502005-11-03 18:47:50 -060014 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * 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 Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/notifier.h>
23#include <linux/pci.h>
24#include <linux/proc_fs.h>
25#include <linux/rbtree.h>
26#include <linux/seq_file.h>
27#include <linux/spinlock.h>
Linas Vepstas69376502005-11-03 18:47:50 -060028#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/eeh.h>
30#include <asm/io.h>
31#include <asm/machdep.h>
32#include <asm/rtas.h>
33#include <asm/atomic.h>
34#include <asm/systemcfg.h>
Stephen Rothwelld3878992005-09-28 02:50:25 +100035#include <asm/ppc-pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#undef DEBUG
38
39/** Overview:
40 * EEH, or "Extended Error Handling" is a PCI bridge technology for
41 * dealing with PCI bus errors that can't be dealt with within the
42 * usual PCI framework, except by check-stopping the CPU. Systems
43 * that are designed for high-availability/reliability cannot afford
44 * to crash due to a "mere" PCI error, thus the need for EEH.
45 * An EEH-capable bridge operates by converting a detected error
46 * into a "slot freeze", taking the PCI adapter off-line, making
47 * the slot behave, from the OS'es point of view, as if the slot
48 * were "empty": all reads return 0xff's and all writes are silently
49 * ignored. EEH slot isolation events can be triggered by parity
50 * errors on the address or data busses (e.g. during posted writes),
Linas Vepstas69376502005-11-03 18:47:50 -060051 * which in turn might be caused by low voltage on the bus, dust,
52 * vibration, humidity, radioactivity or plain-old failed hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
54 * Note, however, that one of the leading causes of EEH slot
55 * freeze events are buggy device drivers, buggy device microcode,
56 * or buggy device hardware. This is because any attempt by the
57 * device to bus-master data to a memory address that is not
58 * assigned to the device will trigger a slot freeze. (The idea
59 * is to prevent devices-gone-wild from corrupting system memory).
60 * Buggy hardware/drivers will have a miserable time co-existing
61 * with EEH.
62 *
63 * Ideally, a PCI device driver, when suspecting that an isolation
64 * event has occured (e.g. by reading 0xff's), will then ask EEH
65 * whether this is the case, and then take appropriate steps to
66 * reset the PCI slot, the PCI device, and then resume operations.
67 * However, until that day, the checking is done here, with the
68 * eeh_check_failure() routine embedded in the MMIO macros. If
69 * the slot is found to be isolated, an "EEH Event" is synthesized
70 * and sent out for processing.
71 */
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* EEH event workqueue setup. */
74static DEFINE_SPINLOCK(eeh_eventlist_lock);
75LIST_HEAD(eeh_eventlist);
76static void eeh_event_handler(void *);
77DECLARE_WORK(eeh_event_wq, eeh_event_handler, NULL);
78
79static struct notifier_block *eeh_notifier_chain;
80
Linas Vepstas5c1344e2005-11-03 18:49:31 -060081/* If a device driver keeps reading an MMIO register in an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * handler after a slot isolation event has occurred, we assume it
83 * is broken and panic. This sets the threshold for how many read
84 * attempts we allow before panicking.
85 */
Linas Vepstas5c1344e2005-11-03 18:49:31 -060086#define EEH_MAX_FAILS 100000
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/* RTAS tokens */
89static int ibm_set_eeh_option;
90static int ibm_set_slot_reset;
91static int ibm_read_slot_reset_state;
92static int ibm_read_slot_reset_state2;
93static int ibm_slot_error_detail;
94
95static int eeh_subsystem_enabled;
96
Linas Vepstasfd761fd2005-11-03 18:49:23 -060097/* Lock to avoid races due to multiple reports of an error */
98static DEFINE_SPINLOCK(confirm_error_lock);
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* Buffer for reporting slot-error-detail rtas calls */
101static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
102static DEFINE_SPINLOCK(slot_errbuf_lock);
103static int eeh_error_buf_size;
104
105/* System monitoring statistics */
Linas Vepstas177bc932005-11-03 18:48:52 -0600106static DEFINE_PER_CPU(unsigned long, no_device);
107static DEFINE_PER_CPU(unsigned long, no_dn);
108static DEFINE_PER_CPU(unsigned long, no_cfg_addr);
109static DEFINE_PER_CPU(unsigned long, ignored_check);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static DEFINE_PER_CPU(unsigned long, total_mmio_ffs);
111static DEFINE_PER_CPU(unsigned long, false_positives);
112static DEFINE_PER_CPU(unsigned long, ignored_failures);
113static DEFINE_PER_CPU(unsigned long, slot_resets);
114
115/**
116 * The pci address cache subsystem. This subsystem places
117 * PCI device address resources into a red-black tree, sorted
118 * according to the address range, so that given only an i/o
119 * address, the corresponding PCI device can be **quickly**
120 * found. It is safe to perform an address lookup in an interrupt
121 * context; this ability is an important feature.
122 *
123 * Currently, the only customer of this code is the EEH subsystem;
124 * thus, this code has been somewhat tailored to suit EEH better.
125 * In particular, the cache does *not* hold the addresses of devices
126 * for which EEH is not enabled.
127 *
128 * (Implementation Note: The RB tree seems to be better/faster
129 * than any hash algo I could think of for this problem, even
130 * with the penalty of slow pointer chases for d-cache misses).
131 */
132struct pci_io_addr_range
133{
134 struct rb_node rb_node;
135 unsigned long addr_lo;
136 unsigned long addr_hi;
137 struct pci_dev *pcidev;
138 unsigned int flags;
139};
140
141static struct pci_io_addr_cache
142{
143 struct rb_root rb_root;
144 spinlock_t piar_lock;
145} pci_io_addr_cache_root;
146
147static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)
148{
149 struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
150
151 while (n) {
152 struct pci_io_addr_range *piar;
153 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
154
155 if (addr < piar->addr_lo) {
156 n = n->rb_left;
157 } else {
158 if (addr > piar->addr_hi) {
159 n = n->rb_right;
160 } else {
161 pci_dev_get(piar->pcidev);
162 return piar->pcidev;
163 }
164 }
165 }
166
167 return NULL;
168}
169
170/**
171 * pci_get_device_by_addr - Get device, given only address
172 * @addr: mmio (PIO) phys address or i/o port number
173 *
174 * Given an mmio phys address, or a port number, find a pci device
175 * that implements this address. Be sure to pci_dev_put the device
176 * when finished. I/O port numbers are assumed to be offset
177 * from zero (that is, they do *not* have pci_io_addr added in).
178 * It is safe to call this function within an interrupt.
179 */
180static struct pci_dev *pci_get_device_by_addr(unsigned long addr)
181{
182 struct pci_dev *dev;
183 unsigned long flags;
184
185 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
186 dev = __pci_get_device_by_addr(addr);
187 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
188 return dev;
189}
190
191#ifdef DEBUG
192/*
193 * Handy-dandy debug print routine, does nothing more
194 * than print out the contents of our addr cache.
195 */
196static void pci_addr_cache_print(struct pci_io_addr_cache *cache)
197{
198 struct rb_node *n;
199 int cnt = 0;
200
201 n = rb_first(&cache->rb_root);
202 while (n) {
203 struct pci_io_addr_range *piar;
204 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
Adrian Bunk982245f2005-07-17 04:22:20 +0200205 printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
Adrian Bunk982245f2005-07-17 04:22:20 +0200207 piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 cnt++;
209 n = rb_next(n);
210 }
211}
212#endif
213
214/* Insert address range into the rb tree. */
215static struct pci_io_addr_range *
216pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,
217 unsigned long ahi, unsigned int flags)
218{
219 struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
220 struct rb_node *parent = NULL;
221 struct pci_io_addr_range *piar;
222
223 /* Walk tree, find a place to insert into tree */
224 while (*p) {
225 parent = *p;
226 piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600227 if (ahi < piar->addr_lo) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 p = &parent->rb_left;
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600229 } else if (alo > piar->addr_hi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 p = &parent->rb_right;
231 } else {
232 if (dev != piar->pcidev ||
233 alo != piar->addr_lo || ahi != piar->addr_hi) {
234 printk(KERN_WARNING "PIAR: overlapping address range\n");
235 }
236 return piar;
237 }
238 }
239 piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
240 if (!piar)
241 return NULL;
242
243 piar->addr_lo = alo;
244 piar->addr_hi = ahi;
245 piar->pcidev = dev;
246 piar->flags = flags;
247
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600248#ifdef DEBUG
249 printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",
250 alo, ahi, pci_name (dev));
251#endif
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 rb_link_node(&piar->rb_node, parent, p);
254 rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
255
256 return piar;
257}
258
259static void __pci_addr_cache_insert_device(struct pci_dev *dev)
260{
261 struct device_node *dn;
Paul Mackerras16353172005-09-06 13:17:54 +1000262 struct pci_dn *pdn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 int i;
264 int inserted = 0;
265
266 dn = pci_device_to_OF_node(dev);
267 if (!dn) {
Linas Vepstas69376502005-11-03 18:47:50 -0600268 printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return;
270 }
271
272 /* Skip any devices for which EEH is not enabled. */
Linas Vepstas69376502005-11-03 18:47:50 -0600273 pdn = PCI_DN(dn);
Paul Mackerras16353172005-09-06 13:17:54 +1000274 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
275 pdn->eeh_mode & EEH_MODE_NOCHECK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#ifdef DEBUG
Linas Vepstas69376502005-11-03 18:47:50 -0600277 printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",
278 pci_name(dev), pdn->node->full_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#endif
280 return;
281 }
282
283 /* The cache holds a reference to the device... */
284 pci_dev_get(dev);
285
286 /* Walk resources on this device, poke them into the tree */
287 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
288 unsigned long start = pci_resource_start(dev,i);
289 unsigned long end = pci_resource_end(dev,i);
290 unsigned int flags = pci_resource_flags(dev,i);
291
292 /* We are interested only bus addresses, not dma or other stuff */
293 if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
294 continue;
295 if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
296 continue;
297 pci_addr_cache_insert(dev, start, end, flags);
298 inserted = 1;
299 }
300
301 /* If there was nothing to add, the cache has no reference... */
302 if (!inserted)
303 pci_dev_put(dev);
304}
305
306/**
307 * pci_addr_cache_insert_device - Add a device to the address cache
308 * @dev: PCI device whose I/O addresses we are interested in.
309 *
310 * In order to support the fast lookup of devices based on addresses,
311 * we maintain a cache of devices that can be quickly searched.
312 * This routine adds a device to that cache.
313 */
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600314static void pci_addr_cache_insert_device(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 unsigned long flags;
317
318 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
319 __pci_addr_cache_insert_device(dev);
320 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
321}
322
323static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
324{
325 struct rb_node *n;
326 int removed = 0;
327
328restart:
329 n = rb_first(&pci_io_addr_cache_root.rb_root);
330 while (n) {
331 struct pci_io_addr_range *piar;
332 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
333
334 if (piar->pcidev == dev) {
335 rb_erase(n, &pci_io_addr_cache_root.rb_root);
336 removed = 1;
337 kfree(piar);
338 goto restart;
339 }
340 n = rb_next(n);
341 }
342
343 /* The cache no longer holds its reference to this device... */
344 if (removed)
345 pci_dev_put(dev);
346}
347
348/**
349 * pci_addr_cache_remove_device - remove pci device from addr cache
350 * @dev: device to remove
351 *
352 * Remove a device from the addr-cache tree.
353 * This is potentially expensive, since it will walk
354 * the tree multiple times (once per resource).
355 * But so what; device removal doesn't need to be that fast.
356 */
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600357static void pci_addr_cache_remove_device(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
359 unsigned long flags;
360
361 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
362 __pci_addr_cache_remove_device(dev);
363 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
364}
365
366/**
367 * pci_addr_cache_build - Build a cache of I/O addresses
368 *
369 * Build a cache of pci i/o addresses. This cache will be used to
370 * find the pci device that corresponds to a given address.
371 * This routine scans all pci busses to build the cache.
372 * Must be run late in boot process, after the pci controllers
373 * have been scaned for devices (after all device resources are known).
374 */
375void __init pci_addr_cache_build(void)
376{
377 struct pci_dev *dev = NULL;
378
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600379 if (!eeh_subsystem_enabled)
380 return;
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 spin_lock_init(&pci_io_addr_cache_root.piar_lock);
383
384 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
385 /* Ignore PCI bridges ( XXX why ??) */
386 if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
387 continue;
388 }
389 pci_addr_cache_insert_device(dev);
390 }
391
392#ifdef DEBUG
393 /* Verify tree built up above, echo back the list of addrs. */
394 pci_addr_cache_print(&pci_io_addr_cache_root);
395#endif
396}
397
398/* --------------------------------------------------------------- */
399/* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
400
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600401void eeh_slot_error_detail (struct pci_dn *pdn, int severity)
402{
403 unsigned long flags;
404 int rc;
405
406 /* Log the error with the rtas logger */
407 spin_lock_irqsave(&slot_errbuf_lock, flags);
408 memset(slot_errbuf, 0, eeh_error_buf_size);
409
410 rc = rtas_call(ibm_slot_error_detail,
411 8, 1, NULL, pdn->eeh_config_addr,
412 BUID_HI(pdn->phb->buid),
413 BUID_LO(pdn->phb->buid), NULL, 0,
414 virt_to_phys(slot_errbuf),
415 eeh_error_buf_size,
416 severity);
417
418 if (rc == 0)
419 log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
420 spin_unlock_irqrestore(&slot_errbuf_lock, flags);
421}
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/**
424 * eeh_register_notifier - Register to find out about EEH events.
425 * @nb: notifier block to callback on events
426 */
427int eeh_register_notifier(struct notifier_block *nb)
428{
429 return notifier_chain_register(&eeh_notifier_chain, nb);
430}
431
432/**
433 * eeh_unregister_notifier - Unregister to an EEH event notifier.
434 * @nb: notifier block to callback on events
435 */
436int eeh_unregister_notifier(struct notifier_block *nb)
437{
438 return notifier_chain_unregister(&eeh_notifier_chain, nb);
439}
440
441/**
442 * read_slot_reset_state - Read the reset state of a device node's slot
443 * @dn: device node to read
444 * @rets: array to return results in
445 */
Linas Vepstas69376502005-11-03 18:47:50 -0600446static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
448 int token, outputs;
449
450 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
451 token = ibm_read_slot_reset_state2;
452 outputs = 4;
453 } else {
454 token = ibm_read_slot_reset_state;
Linas Vepstas69376502005-11-03 18:47:50 -0600455 rets[2] = 0; /* fake PE Unavailable info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 outputs = 3;
457 }
458
Paul Mackerras16353172005-09-06 13:17:54 +1000459 return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr,
460 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463/**
464 * eeh_panic - call panic() for an eeh event that cannot be handled.
465 * The philosophy of this routine is that it is better to panic and
466 * halt the OS than it is to risk possible data corruption by
467 * oblivious device drivers that don't know better.
468 *
469 * @dev pci device that had an eeh event
470 * @reset_state current reset state of the device slot
471 */
472static void eeh_panic(struct pci_dev *dev, int reset_state)
473{
474 /*
475 * XXX We should create a separate sysctl for this.
476 *
477 * Since the panic_on_oops sysctl is used to halt the system
478 * in light of potential corruption, we can use it here.
479 */
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600480 if (panic_on_oops) {
481 struct device_node *dn = pci_device_to_OF_node(dev);
482 eeh_slot_error_detail (PCI_DN(dn), 2 /* Permanent Error */);
Adrian Bunk982245f2005-07-17 04:22:20 +0200483 panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
484 pci_name(dev));
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 else {
487 __get_cpu_var(ignored_failures)++;
Adrian Bunk982245f2005-07-17 04:22:20 +0200488 printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
489 reset_state, pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491}
492
493/**
494 * eeh_event_handler - dispatch EEH events. The detection of a frozen
495 * slot can occur inside an interrupt, where it can be hard to do
496 * anything about it. The goal of this routine is to pull these
497 * detection events out of the context of the interrupt handler, and
498 * re-dispatch them for processing at a later time in a normal context.
499 *
500 * @dummy - unused
501 */
502static void eeh_event_handler(void *dummy)
503{
504 unsigned long flags;
505 struct eeh_event *event;
506
507 while (1) {
508 spin_lock_irqsave(&eeh_eventlist_lock, flags);
509 event = NULL;
510 if (!list_empty(&eeh_eventlist)) {
511 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
512 list_del(&event->list);
513 }
514 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
515 if (event == NULL)
516 break;
517
518 printk(KERN_INFO "EEH: MMIO failure (%d), notifiying device "
Adrian Bunk982245f2005-07-17 04:22:20 +0200519 "%s\n", event->reset_state,
520 pci_name(event->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 notifier_call_chain (&eeh_notifier_chain,
523 EEH_NOTIFY_FREEZE, event);
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 pci_dev_put(event->dev);
526 kfree(event);
527 }
528}
529
530/**
531 * eeh_token_to_phys - convert EEH address token to phys address
Linas Vepstas69376502005-11-03 18:47:50 -0600532 * @token i/o token, should be address in the form 0xA....
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 */
534static inline unsigned long eeh_token_to_phys(unsigned long token)
535{
536 pte_t *ptep;
537 unsigned long pa;
538
David Gibson20cee162005-06-21 17:15:31 -0700539 ptep = find_linux_pte(init_mm.pgd, token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (!ptep)
541 return token;
542 pa = pte_pfn(*ptep) << PAGE_SHIFT;
543
544 return pa | (token & (PAGE_SIZE-1));
545}
546
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600547/**
548 * Return the "partitionable endpoint" (pe) under which this device lies
549 */
550static struct device_node * find_device_pe(struct device_node *dn)
551{
552 while ((dn->parent) && PCI_DN(dn->parent) &&
553 (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
554 dn = dn->parent;
555 }
556 return dn;
557}
558
559/** Mark all devices that are peers of this device as failed.
560 * Mark the device driver too, so that it can see the failure
561 * immediately; this is critical, since some drivers poll
562 * status registers in interrupts ... If a driver is polling,
563 * and the slot is frozen, then the driver can deadlock in
564 * an interrupt context, which is bad.
565 */
566
567static inline void __eeh_mark_slot (struct device_node *dn)
568{
569 while (dn) {
570 PCI_DN(dn)->eeh_mode |= EEH_MODE_ISOLATED;
571
572 if (dn->child)
573 __eeh_mark_slot (dn->child);
574 dn = dn->sibling;
575 }
576}
577
578static inline void __eeh_clear_slot (struct device_node *dn)
579{
580 while (dn) {
581 PCI_DN(dn)->eeh_mode &= ~EEH_MODE_ISOLATED;
582 if (dn->child)
583 __eeh_clear_slot (dn->child);
584 dn = dn->sibling;
585 }
586}
587
588static inline void eeh_clear_slot (struct device_node *dn)
589{
590 unsigned long flags;
591 spin_lock_irqsave(&confirm_error_lock, flags);
592 __eeh_clear_slot (dn);
593 spin_unlock_irqrestore(&confirm_error_lock, flags);
594}
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596/**
597 * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
598 * @dn device node
599 * @dev pci device, if known
600 *
601 * Check for an EEH failure for the given device node. Call this
602 * routine if the result of a read was all 0xff's and you want to
603 * find out if this is due to an EEH slot freeze. This routine
604 * will query firmware for the EEH status.
605 *
606 * Returns 0 if there has not been an EEH error; otherwise returns
Linas Vepstas69376502005-11-03 18:47:50 -0600607 * a non-zero value and queues up a slot isolation event notification.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 *
609 * It is safe to call this routine in an interrupt context.
610 */
611int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
612{
613 int ret;
614 int rets[3];
615 unsigned long flags;
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600616 int reset_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 struct eeh_event *event;
Paul Mackerras16353172005-09-06 13:17:54 +1000618 struct pci_dn *pdn;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600619 struct device_node *pe_dn;
620 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 __get_cpu_var(total_mmio_ffs)++;
623
624 if (!eeh_subsystem_enabled)
625 return 0;
626
Linas Vepstas177bc932005-11-03 18:48:52 -0600627 if (!dn) {
628 __get_cpu_var(no_dn)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return 0;
Linas Vepstas177bc932005-11-03 18:48:52 -0600630 }
Linas Vepstas69376502005-11-03 18:47:50 -0600631 pdn = PCI_DN(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /* Access to IO BARs might get this far and still not want checking. */
Paul Mackerras16353172005-09-06 13:17:54 +1000634 if (!pdn->eeh_capable || !(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
635 pdn->eeh_mode & EEH_MODE_NOCHECK) {
Linas Vepstas177bc932005-11-03 18:48:52 -0600636 __get_cpu_var(ignored_check)++;
637#ifdef DEBUG
638 printk ("EEH:ignored check for %s %s\n", pci_name (dev), dn->full_name);
639#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return 0;
641 }
642
Paul Mackerras16353172005-09-06 13:17:54 +1000643 if (!pdn->eeh_config_addr) {
Linas Vepstas177bc932005-11-03 18:48:52 -0600644 __get_cpu_var(no_cfg_addr)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return 0;
646 }
647
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600648 /* If we already have a pending isolation event for this
649 * slot, we know it's bad already, we don't need to check.
650 * Do this checking under a lock; as multiple PCI devices
651 * in one slot might report errors simultaneously, and we
652 * only want one error recovery routine running.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 */
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600654 spin_lock_irqsave(&confirm_error_lock, flags);
655 rc = 1;
Paul Mackerras16353172005-09-06 13:17:54 +1000656 if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600657 pdn->eeh_check_count ++;
658 if (pdn->eeh_check_count >= EEH_MAX_FAILS) {
659 printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n",
660 pdn->eeh_check_count);
661 dump_stack();
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /* re-read the slot reset state */
Linas Vepstas69376502005-11-03 18:47:50 -0600664 if (read_slot_reset_state(pdn, rets) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 rets[0] = -1; /* reset state unknown */
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600666
667 /* If we are here, then we hit an infinite loop. Stop. */
668 panic("EEH: MMIO halt (%d) on device:%s\n", rets[0], pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600670 goto dn_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 /*
674 * Now test for an EEH failure. This is VERY expensive.
675 * Note that the eeh_config_addr may be a parent device
676 * in the case of a device behind a bridge, or it may be
677 * function zero of a multi-function device.
678 * In any case they must share a common PHB.
679 */
Linas Vepstas69376502005-11-03 18:47:50 -0600680 ret = read_slot_reset_state(pdn, rets);
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600681
682 /* If the call to firmware failed, punt */
683 if (ret != 0) {
684 printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
685 ret, dn->full_name);
686 __get_cpu_var(false_positives)++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600687 rc = 0;
688 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600689 }
690
691 /* If EEH is not supported on this device, punt. */
692 if (rets[1] != 1) {
693 printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
694 ret, dn->full_name);
695 __get_cpu_var(false_positives)++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600696 rc = 0;
697 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600698 }
699
700 /* If not the kind of error we know about, punt. */
701 if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
702 __get_cpu_var(false_positives)++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600703 rc = 0;
704 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600705 }
706
707 /* Note that config-io to empty slots may fail;
708 * we recognize empty because they don't have children. */
709 if ((rets[0] == 5) && (dn->child == NULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 __get_cpu_var(false_positives)++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600711 rc = 0;
712 goto dn_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600715 __get_cpu_var(slot_resets)++;
716
717 /* Avoid repeated reports of this failure, including problems
718 * with other functions on this device, and functions under
719 * bridges. */
720 pe_dn = find_device_pe (dn);
721 __eeh_mark_slot (pe_dn);
722 spin_unlock_irqrestore(&confirm_error_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 reset_state = rets[0];
725
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600726 eeh_slot_error_detail (pdn, 1 /* Temporary Error */);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 printk(KERN_INFO "EEH: MMIO failure (%d) on device: %s %s\n",
729 rets[0], dn->name, dn->full_name);
730 event = kmalloc(sizeof(*event), GFP_ATOMIC);
731 if (event == NULL) {
732 eeh_panic(dev, reset_state);
733 return 1;
734 }
735
736 event->dev = dev;
737 event->dn = dn;
738 event->reset_state = reset_state;
739
740 /* We may or may not be called in an interrupt context */
741 spin_lock_irqsave(&eeh_eventlist_lock, flags);
742 list_add(&event->list, &eeh_eventlist);
743 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
744
745 /* Most EEH events are due to device driver bugs. Having
746 * a stack trace will help the device-driver authors figure
747 * out what happened. So print that out. */
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600748 if (rets[0] != 5) dump_stack();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 schedule_work(&eeh_event_wq);
750
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600751 return 1;
752
753dn_unlock:
754 spin_unlock_irqrestore(&confirm_error_lock, flags);
755 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756}
757
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600758EXPORT_SYMBOL_GPL(eeh_dn_check_failure);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760/**
761 * eeh_check_failure - check if all 1's data is due to EEH slot freeze
762 * @token i/o token, should be address in the form 0xA....
763 * @val value, should be all 1's (XXX why do we need this arg??)
764 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 * Check for an EEH failure at the given token address. Call this
766 * routine if the result of a read was all 0xff's and you want to
767 * find out if this is due to an EEH slot freeze event. This routine
768 * will query firmware for the EEH status.
769 *
770 * Note this routine is safe to call in an interrupt context.
771 */
772unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
773{
774 unsigned long addr;
775 struct pci_dev *dev;
776 struct device_node *dn;
777
778 /* Finding the phys addr + pci device; this is pretty quick. */
779 addr = eeh_token_to_phys((unsigned long __force) token);
780 dev = pci_get_device_by_addr(addr);
Linas Vepstas177bc932005-11-03 18:48:52 -0600781 if (!dev) {
782 __get_cpu_var(no_device)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return val;
Linas Vepstas177bc932005-11-03 18:48:52 -0600784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 dn = pci_device_to_OF_node(dev);
787 eeh_dn_check_failure (dn, dev);
788
789 pci_dev_put(dev);
790 return val;
791}
792
793EXPORT_SYMBOL(eeh_check_failure);
794
795struct eeh_early_enable_info {
796 unsigned int buid_hi;
797 unsigned int buid_lo;
798};
799
800/* Enable eeh for the given device node. */
801static void *early_enable_eeh(struct device_node *dn, void *data)
802{
803 struct eeh_early_enable_info *info = data;
804 int ret;
805 char *status = get_property(dn, "status", NULL);
806 u32 *class_code = (u32 *)get_property(dn, "class-code", NULL);
807 u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL);
808 u32 *device_id = (u32 *)get_property(dn, "device-id", NULL);
809 u32 *regs;
810 int enable;
Linas Vepstas69376502005-11-03 18:47:50 -0600811 struct pci_dn *pdn = PCI_DN(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Paul Mackerras16353172005-09-06 13:17:54 +1000813 pdn->eeh_mode = 0;
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600814 pdn->eeh_check_count = 0;
815 pdn->eeh_freeze_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 if (status && strcmp(status, "ok") != 0)
818 return NULL; /* ignore devices with bad status */
819
820 /* Ignore bad nodes. */
821 if (!class_code || !vendor_id || !device_id)
822 return NULL;
823
824 /* There is nothing to check on PCI to ISA bridges */
825 if (dn->type && !strcmp(dn->type, "isa")) {
Paul Mackerras16353172005-09-06 13:17:54 +1000826 pdn->eeh_mode |= EEH_MODE_NOCHECK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return NULL;
828 }
829
830 /*
831 * Now decide if we are going to "Disable" EEH checking
832 * for this device. We still run with the EEH hardware active,
833 * but we won't be checking for ff's. This means a driver
834 * could return bad data (very bad!), an interrupt handler could
835 * hang waiting on status bits that won't change, etc.
836 * But there are a few cases like display devices that make sense.
837 */
838 enable = 1; /* i.e. we will do checking */
839 if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
840 enable = 0;
841
842 if (!enable)
Paul Mackerras16353172005-09-06 13:17:54 +1000843 pdn->eeh_mode |= EEH_MODE_NOCHECK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 /* Ok... see if this device supports EEH. Some do, some don't,
846 * and the only way to find out is to check each and every one. */
847 regs = (u32 *)get_property(dn, "reg", NULL);
848 if (regs) {
849 /* First register entry is addr (00BBSS00) */
850 /* Try to enable eeh */
851 ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
852 regs[0], info->buid_hi, info->buid_lo,
853 EEH_ENABLE);
854 if (ret == 0) {
855 eeh_subsystem_enabled = 1;
Paul Mackerras16353172005-09-06 13:17:54 +1000856 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
857 pdn->eeh_config_addr = regs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858#ifdef DEBUG
859 printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);
860#endif
861 } else {
862
863 /* This device doesn't support EEH, but it may have an
864 * EEH parent, in which case we mark it as supported. */
Linas Vepstas69376502005-11-03 18:47:50 -0600865 if (dn->parent && PCI_DN(dn->parent)
Paul Mackerras16353172005-09-06 13:17:54 +1000866 && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 /* Parent supports EEH. */
Paul Mackerras16353172005-09-06 13:17:54 +1000868 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
869 pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 return NULL;
871 }
872 }
873 } else {
874 printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
875 dn->full_name);
876 }
877
Linas Vepstas69376502005-11-03 18:47:50 -0600878 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879}
880
881/*
882 * Initialize EEH by trying to enable it for all of the adapters in the system.
883 * As a side effect we can determine here if eeh is supported at all.
884 * Note that we leave EEH on so failed config cycles won't cause a machine
885 * check. If a user turns off EEH for a particular adapter they are really
886 * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
887 * grant access to a slot if EEH isn't enabled, and so we always enable
888 * EEH for all slots/all devices.
889 *
890 * The eeh-force-off option disables EEH checking globally, for all slots.
891 * Even if force-off is set, the EEH hardware is still enabled, so that
892 * newer systems can boot.
893 */
894void __init eeh_init(void)
895{
896 struct device_node *phb, *np;
897 struct eeh_early_enable_info info;
898
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600899 spin_lock_init(&confirm_error_lock);
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600900 spin_lock_init(&slot_errbuf_lock);
901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 np = of_find_node_by_path("/rtas");
903 if (np == NULL)
904 return;
905
906 ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
907 ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
908 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
909 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
910 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
911
912 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
913 return;
914
915 eeh_error_buf_size = rtas_token("rtas-error-log-max");
916 if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
917 eeh_error_buf_size = 1024;
918 }
919 if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
920 printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
921 "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
922 eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
923 }
924
925 /* Enable EEH for all adapters. Note that eeh requires buid's */
926 for (phb = of_find_node_by_name(NULL, "pci"); phb;
927 phb = of_find_node_by_name(phb, "pci")) {
928 unsigned long buid;
929
930 buid = get_phb_buid(phb);
Linas Vepstas69376502005-11-03 18:47:50 -0600931 if (buid == 0 || PCI_DN(phb) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 continue;
933
934 info.buid_lo = BUID_LO(buid);
935 info.buid_hi = BUID_HI(buid);
936 traverse_pci_devices(phb, early_enable_eeh, &info);
937 }
938
939 if (eeh_subsystem_enabled)
940 printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
941 else
942 printk(KERN_WARNING "EEH: No capable adapters found\n");
943}
944
945/**
946 * eeh_add_device_early - enable EEH for the indicated device_node
947 * @dn: device node for which to set up EEH
948 *
949 * This routine must be used to perform EEH initialization for PCI
950 * devices that were added after system boot (e.g. hotplug, dlpar).
951 * This routine must be called before any i/o is performed to the
952 * adapter (inluding any config-space i/o).
953 * Whether this actually enables EEH or not for this device depends
954 * on the CEC architecture, type of the device, on earlier boot
955 * command-line arguments & etc.
956 */
957void eeh_add_device_early(struct device_node *dn)
958{
959 struct pci_controller *phb;
960 struct eeh_early_enable_info info;
961
Linas Vepstas69376502005-11-03 18:47:50 -0600962 if (!dn || !PCI_DN(dn))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return;
Paul Mackerras16353172005-09-06 13:17:54 +1000964 phb = PCI_DN(dn)->phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 if (NULL == phb || 0 == phb->buid) {
Linas Vepstas69376502005-11-03 18:47:50 -0600966 printk(KERN_WARNING "EEH: Expected buid but found none for %s\n",
967 dn->full_name);
968 dump_stack();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return;
970 }
971
972 info.buid_hi = BUID_HI(phb->buid);
973 info.buid_lo = BUID_LO(phb->buid);
974 early_enable_eeh(dn, &info);
975}
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600976EXPORT_SYMBOL_GPL(eeh_add_device_early);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978/**
979 * eeh_add_device_late - perform EEH initialization for the indicated pci device
980 * @dev: pci device for which to set up EEH
981 *
982 * This routine must be used to complete EEH initialization for PCI
983 * devices that were added after system boot (e.g. hotplug, dlpar).
984 */
985void eeh_add_device_late(struct pci_dev *dev)
986{
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600987 struct device_node *dn;
988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (!dev || !eeh_subsystem_enabled)
990 return;
991
992#ifdef DEBUG
Adrian Bunk982245f2005-07-17 04:22:20 +0200993 printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994#endif
995
Linas Vepstas56b0fca2005-11-03 18:48:45 -0600996 pci_dev_get (dev);
997 dn = pci_device_to_OF_node(dev);
998 PCI_DN(dn)->pcidev = dev;
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 pci_addr_cache_insert_device (dev);
1001}
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001002EXPORT_SYMBOL_GPL(eeh_add_device_late);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004/**
1005 * eeh_remove_device - undo EEH setup for the indicated pci device
1006 * @dev: pci device to be removed
1007 *
1008 * This routine should be when a device is removed from a running
1009 * system (e.g. by hotplug or dlpar).
1010 */
1011void eeh_remove_device(struct pci_dev *dev)
1012{
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001013 struct device_node *dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (!dev || !eeh_subsystem_enabled)
1015 return;
1016
1017 /* Unregister the device with the EEH/PCI address search system */
1018#ifdef DEBUG
Adrian Bunk982245f2005-07-17 04:22:20 +02001019 printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020#endif
1021 pci_addr_cache_remove_device(dev);
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001022
1023 dn = pci_device_to_OF_node(dev);
1024 PCI_DN(dn)->pcidev = NULL;
1025 pci_dev_put (dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001027EXPORT_SYMBOL_GPL(eeh_remove_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029static int proc_eeh_show(struct seq_file *m, void *v)
1030{
1031 unsigned int cpu;
1032 unsigned long ffs = 0, positives = 0, failures = 0;
1033 unsigned long resets = 0;
Linas Vepstas177bc932005-11-03 18:48:52 -06001034 unsigned long no_dev = 0, no_dn = 0, no_cfg = 0, no_check = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 for_each_cpu(cpu) {
1037 ffs += per_cpu(total_mmio_ffs, cpu);
1038 positives += per_cpu(false_positives, cpu);
1039 failures += per_cpu(ignored_failures, cpu);
1040 resets += per_cpu(slot_resets, cpu);
Linas Vepstas177bc932005-11-03 18:48:52 -06001041 no_dev += per_cpu(no_device, cpu);
1042 no_dn += per_cpu(no_dn, cpu);
1043 no_cfg += per_cpu(no_cfg_addr, cpu);
1044 no_check += per_cpu(ignored_check, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046
1047 if (0 == eeh_subsystem_enabled) {
1048 seq_printf(m, "EEH Subsystem is globally disabled\n");
1049 seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);
1050 } else {
1051 seq_printf(m, "EEH Subsystem is enabled\n");
Linas Vepstas177bc932005-11-03 18:48:52 -06001052 seq_printf(m,
1053 "no device=%ld\n"
1054 "no device node=%ld\n"
1055 "no config address=%ld\n"
1056 "check not wanted=%ld\n"
1057 "eeh_total_mmio_ffs=%ld\n"
1058 "eeh_false_positives=%ld\n"
1059 "eeh_ignored_failures=%ld\n"
1060 "eeh_slot_resets=%ld\n",
1061 no_dev, no_dn, no_cfg, no_check,
1062 ffs, positives, failures, resets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064
1065 return 0;
1066}
1067
1068static int proc_eeh_open(struct inode *inode, struct file *file)
1069{
1070 return single_open(file, proc_eeh_show, NULL);
1071}
1072
1073static struct file_operations proc_eeh_operations = {
1074 .open = proc_eeh_open,
1075 .read = seq_read,
1076 .llseek = seq_lseek,
1077 .release = single_release,
1078};
1079
1080static int __init eeh_init_proc(void)
1081{
1082 struct proc_dir_entry *e;
1083
1084 if (systemcfg->platform & PLATFORM_PSERIES) {
1085 e = create_proc_entry("ppc64/eeh", 0, NULL);
1086 if (e)
1087 e->proc_fops = &proc_eeh_operations;
1088 }
1089
1090 return 0;
1091}
1092__initcall(eeh_init_proc);