3 * Copyright (C) 2001 Dave Engebretsen & Todd Inglett IBM Corporation
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.
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.
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
20 #include <linux/bootmem.h>
21 #include <linux/init.h>
22 #include <linux/list.h>
24 #include <linux/notifier.h>
25 #include <linux/pci.h>
26 #include <linux/proc_fs.h>
27 #include <linux/rbtree.h>
28 #include <linux/seq_file.h>
29 #include <linux/spinlock.h>
32 #include <asm/machdep.h>
34 #include <asm/atomic.h>
35 #include <asm/systemcfg.h>
41 * EEH, or "Extended Error Handling" is a PCI bridge technology for
42 * dealing with PCI bus errors that can't be dealt with within the
43 * usual PCI framework, except by check-stopping the CPU. Systems
44 * that are designed for high-availability/reliability cannot afford
45 * to crash due to a "mere" PCI error, thus the need for EEH.
46 * An EEH-capable bridge operates by converting a detected error
47 * into a "slot freeze", taking the PCI adapter off-line, making
48 * the slot behave, from the OS'es point of view, as if the slot
49 * were "empty": all reads return 0xff's and all writes are silently
50 * ignored. EEH slot isolation events can be triggered by parity
51 * errors on the address or data busses (e.g. during posted writes),
52 * which in turn might be caused by dust, vibration, humidity,
53 * radioactivity or plain-old failed hardware.
55 * Note, however, that one of the leading causes of EEH slot
56 * freeze events are buggy device drivers, buggy device microcode,
57 * or buggy device hardware. This is because any attempt by the
58 * device to bus-master data to a memory address that is not
59 * assigned to the device will trigger a slot freeze. (The idea
60 * is to prevent devices-gone-wild from corrupting system memory).
61 * Buggy hardware/drivers will have a miserable time co-existing
64 * Ideally, a PCI device driver, when suspecting that an isolation
65 * event has occured (e.g. by reading 0xff's), will then ask EEH
66 * whether this is the case, and then take appropriate steps to
67 * reset the PCI slot, the PCI device, and then resume operations.
68 * However, until that day, the checking is done here, with the
69 * eeh_check_failure() routine embedded in the MMIO macros. If
70 * the slot is found to be isolated, an "EEH Event" is synthesized
71 * and sent out for processing.
74 /** Bus Unit ID macros; get low and hi 32-bits of the 64-bit BUID */
75 #define BUID_HI(buid) ((buid) >> 32)
76 #define BUID_LO(buid) ((buid) & 0xffffffff)
78 /* EEH event workqueue setup. */
79 static DEFINE_SPINLOCK(eeh_eventlist_lock
);
80 LIST_HEAD(eeh_eventlist
);
81 static void eeh_event_handler(void *);
82 DECLARE_WORK(eeh_event_wq
, eeh_event_handler
, NULL
);
84 static struct notifier_block
*eeh_notifier_chain
;
87 * If a device driver keeps reading an MMIO register in an interrupt
88 * handler after a slot isolation event has occurred, we assume it
89 * is broken and panic. This sets the threshold for how many read
90 * attempts we allow before panicking.
92 #define EEH_MAX_FAILS 1000
93 static atomic_t eeh_fail_count
;
96 static int ibm_set_eeh_option
;
97 static int ibm_set_slot_reset
;
98 static int ibm_read_slot_reset_state
;
99 static int ibm_read_slot_reset_state2
;
100 static int ibm_slot_error_detail
;
102 static int eeh_subsystem_enabled
;
104 /* Buffer for reporting slot-error-detail rtas calls */
105 static unsigned char slot_errbuf
[RTAS_ERROR_LOG_MAX
];
106 static DEFINE_SPINLOCK(slot_errbuf_lock
);
107 static int eeh_error_buf_size
;
109 /* System monitoring statistics */
110 static DEFINE_PER_CPU(unsigned long, total_mmio_ffs
);
111 static DEFINE_PER_CPU(unsigned long, false_positives
);
112 static DEFINE_PER_CPU(unsigned long, ignored_failures
);
113 static DEFINE_PER_CPU(unsigned long, slot_resets
);
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.
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.
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).
132 struct pci_io_addr_range
134 struct rb_node rb_node
;
135 unsigned long addr_lo
;
136 unsigned long addr_hi
;
137 struct pci_dev
*pcidev
;
141 static struct pci_io_addr_cache
143 struct rb_root rb_root
;
144 spinlock_t piar_lock
;
145 } pci_io_addr_cache_root
;
147 static inline struct pci_dev
*__pci_get_device_by_addr(unsigned long addr
)
149 struct rb_node
*n
= pci_io_addr_cache_root
.rb_root
.rb_node
;
152 struct pci_io_addr_range
*piar
;
153 piar
= rb_entry(n
, struct pci_io_addr_range
, rb_node
);
155 if (addr
< piar
->addr_lo
) {
158 if (addr
> piar
->addr_hi
) {
161 pci_dev_get(piar
->pcidev
);
171 * pci_get_device_by_addr - Get device, given only address
172 * @addr: mmio (PIO) phys address or i/o port number
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.
180 static struct pci_dev
*pci_get_device_by_addr(unsigned long addr
)
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
);
193 * Handy-dandy debug print routine, does nothing more
194 * than print out the contents of our addr cache.
196 static void pci_addr_cache_print(struct pci_io_addr_cache
*cache
)
201 n
= rb_first(&cache
->rb_root
);
203 struct pci_io_addr_range
*piar
;
204 piar
= rb_entry(n
, struct pci_io_addr_range
, rb_node
);
205 printk(KERN_DEBUG
"PCI: %s addr range %d [%lx-%lx]: %s\n",
206 (piar
->flags
& IORESOURCE_IO
) ? "i/o" : "mem", cnt
,
207 piar
->addr_lo
, piar
->addr_hi
, pci_name(piar
->pcidev
));
214 /* Insert address range into the rb tree. */
215 static struct pci_io_addr_range
*
216 pci_addr_cache_insert(struct pci_dev
*dev
, unsigned long alo
,
217 unsigned long ahi
, unsigned int flags
)
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
;
223 /* Walk tree, find a place to insert into tree */
226 piar
= rb_entry(parent
, struct pci_io_addr_range
, rb_node
);
227 if (alo
< piar
->addr_lo
) {
228 p
= &parent
->rb_left
;
229 } else if (ahi
> piar
->addr_hi
) {
230 p
= &parent
->rb_right
;
232 if (dev
!= piar
->pcidev
||
233 alo
!= piar
->addr_lo
|| ahi
!= piar
->addr_hi
) {
234 printk(KERN_WARNING
"PIAR: overlapping address range\n");
239 piar
= (struct pci_io_addr_range
*)kmalloc(sizeof(struct pci_io_addr_range
), GFP_ATOMIC
);
248 rb_link_node(&piar
->rb_node
, parent
, p
);
249 rb_insert_color(&piar
->rb_node
, &pci_io_addr_cache_root
.rb_root
);
254 static void __pci_addr_cache_insert_device(struct pci_dev
*dev
)
256 struct device_node
*dn
;
261 dn
= pci_device_to_OF_node(dev
);
263 printk(KERN_WARNING
"PCI: no pci dn found for dev=%s\n",
268 /* Skip any devices for which EEH is not enabled. */
270 if (!(pdn
->eeh_mode
& EEH_MODE_SUPPORTED
) ||
271 pdn
->eeh_mode
& EEH_MODE_NOCHECK
) {
273 printk(KERN_INFO
"PCI: skip building address cache for=%s\n",
279 /* The cache holds a reference to the device... */
282 /* Walk resources on this device, poke them into the tree */
283 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
284 unsigned long start
= pci_resource_start(dev
,i
);
285 unsigned long end
= pci_resource_end(dev
,i
);
286 unsigned int flags
= pci_resource_flags(dev
,i
);
288 /* We are interested only bus addresses, not dma or other stuff */
289 if (0 == (flags
& (IORESOURCE_IO
| IORESOURCE_MEM
)))
291 if (start
== 0 || ~start
== 0 || end
== 0 || ~end
== 0)
293 pci_addr_cache_insert(dev
, start
, end
, flags
);
297 /* If there was nothing to add, the cache has no reference... */
303 * pci_addr_cache_insert_device - Add a device to the address cache
304 * @dev: PCI device whose I/O addresses we are interested in.
306 * In order to support the fast lookup of devices based on addresses,
307 * we maintain a cache of devices that can be quickly searched.
308 * This routine adds a device to that cache.
310 void pci_addr_cache_insert_device(struct pci_dev
*dev
)
314 spin_lock_irqsave(&pci_io_addr_cache_root
.piar_lock
, flags
);
315 __pci_addr_cache_insert_device(dev
);
316 spin_unlock_irqrestore(&pci_io_addr_cache_root
.piar_lock
, flags
);
319 static inline void __pci_addr_cache_remove_device(struct pci_dev
*dev
)
325 n
= rb_first(&pci_io_addr_cache_root
.rb_root
);
327 struct pci_io_addr_range
*piar
;
328 piar
= rb_entry(n
, struct pci_io_addr_range
, rb_node
);
330 if (piar
->pcidev
== dev
) {
331 rb_erase(n
, &pci_io_addr_cache_root
.rb_root
);
339 /* The cache no longer holds its reference to this device... */
345 * pci_addr_cache_remove_device - remove pci device from addr cache
346 * @dev: device to remove
348 * Remove a device from the addr-cache tree.
349 * This is potentially expensive, since it will walk
350 * the tree multiple times (once per resource).
351 * But so what; device removal doesn't need to be that fast.
353 void pci_addr_cache_remove_device(struct pci_dev
*dev
)
357 spin_lock_irqsave(&pci_io_addr_cache_root
.piar_lock
, flags
);
358 __pci_addr_cache_remove_device(dev
);
359 spin_unlock_irqrestore(&pci_io_addr_cache_root
.piar_lock
, flags
);
363 * pci_addr_cache_build - Build a cache of I/O addresses
365 * Build a cache of pci i/o addresses. This cache will be used to
366 * find the pci device that corresponds to a given address.
367 * This routine scans all pci busses to build the cache.
368 * Must be run late in boot process, after the pci controllers
369 * have been scaned for devices (after all device resources are known).
371 void __init
pci_addr_cache_build(void)
373 struct pci_dev
*dev
= NULL
;
375 spin_lock_init(&pci_io_addr_cache_root
.piar_lock
);
377 while ((dev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, dev
)) != NULL
) {
378 /* Ignore PCI bridges ( XXX why ??) */
379 if ((dev
->class >> 16) == PCI_BASE_CLASS_BRIDGE
) {
382 pci_addr_cache_insert_device(dev
);
386 /* Verify tree built up above, echo back the list of addrs. */
387 pci_addr_cache_print(&pci_io_addr_cache_root
);
391 /* --------------------------------------------------------------- */
392 /* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
395 * eeh_register_notifier - Register to find out about EEH events.
396 * @nb: notifier block to callback on events
398 int eeh_register_notifier(struct notifier_block
*nb
)
400 return notifier_chain_register(&eeh_notifier_chain
, nb
);
404 * eeh_unregister_notifier - Unregister to an EEH event notifier.
405 * @nb: notifier block to callback on events
407 int eeh_unregister_notifier(struct notifier_block
*nb
)
409 return notifier_chain_unregister(&eeh_notifier_chain
, nb
);
413 * read_slot_reset_state - Read the reset state of a device node's slot
414 * @dn: device node to read
415 * @rets: array to return results in
417 static int read_slot_reset_state(struct device_node
*dn
, int rets
[])
420 struct pci_dn
*pdn
= dn
->data
;
422 if (ibm_read_slot_reset_state2
!= RTAS_UNKNOWN_SERVICE
) {
423 token
= ibm_read_slot_reset_state2
;
426 token
= ibm_read_slot_reset_state
;
430 return rtas_call(token
, 3, outputs
, rets
, pdn
->eeh_config_addr
,
431 BUID_HI(pdn
->phb
->buid
), BUID_LO(pdn
->phb
->buid
));
435 * eeh_panic - call panic() for an eeh event that cannot be handled.
436 * The philosophy of this routine is that it is better to panic and
437 * halt the OS than it is to risk possible data corruption by
438 * oblivious device drivers that don't know better.
440 * @dev pci device that had an eeh event
441 * @reset_state current reset state of the device slot
443 static void eeh_panic(struct pci_dev
*dev
, int reset_state
)
446 * XXX We should create a separate sysctl for this.
448 * Since the panic_on_oops sysctl is used to halt the system
449 * in light of potential corruption, we can use it here.
452 panic("EEH: MMIO failure (%d) on device:%s\n", reset_state
,
455 __get_cpu_var(ignored_failures
)++;
456 printk(KERN_INFO
"EEH: Ignored MMIO failure (%d) on device:%s\n",
457 reset_state
, pci_name(dev
));
462 * eeh_event_handler - dispatch EEH events. The detection of a frozen
463 * slot can occur inside an interrupt, where it can be hard to do
464 * anything about it. The goal of this routine is to pull these
465 * detection events out of the context of the interrupt handler, and
466 * re-dispatch them for processing at a later time in a normal context.
470 static void eeh_event_handler(void *dummy
)
473 struct eeh_event
*event
;
476 spin_lock_irqsave(&eeh_eventlist_lock
, flags
);
478 if (!list_empty(&eeh_eventlist
)) {
479 event
= list_entry(eeh_eventlist
.next
, struct eeh_event
, list
);
480 list_del(&event
->list
);
482 spin_unlock_irqrestore(&eeh_eventlist_lock
, flags
);
486 printk(KERN_INFO
"EEH: MMIO failure (%d), notifiying device "
487 "%s\n", event
->reset_state
,
488 pci_name(event
->dev
));
490 atomic_set(&eeh_fail_count
, 0);
491 notifier_call_chain (&eeh_notifier_chain
,
492 EEH_NOTIFY_FREEZE
, event
);
494 __get_cpu_var(slot_resets
)++;
496 pci_dev_put(event
->dev
);
502 * eeh_token_to_phys - convert EEH address token to phys address
503 * @token i/o token, should be address in the form 0xE....
505 static inline unsigned long eeh_token_to_phys(unsigned long token
)
510 ptep
= find_linux_pte(init_mm
.pgd
, token
);
513 pa
= pte_pfn(*ptep
) << PAGE_SHIFT
;
515 return pa
| (token
& (PAGE_SIZE
-1));
519 * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
521 * @dev pci device, if known
523 * Check for an EEH failure for the given device node. Call this
524 * routine if the result of a read was all 0xff's and you want to
525 * find out if this is due to an EEH slot freeze. This routine
526 * will query firmware for the EEH status.
528 * Returns 0 if there has not been an EEH error; otherwise returns
529 * a non-zero value and queues up a solt isolation event notification.
531 * It is safe to call this routine in an interrupt context.
533 int eeh_dn_check_failure(struct device_node
*dn
, struct pci_dev
*dev
)
539 struct eeh_event
*event
;
542 __get_cpu_var(total_mmio_ffs
)++;
544 if (!eeh_subsystem_enabled
)
551 /* Access to IO BARs might get this far and still not want checking. */
552 if (!pdn
->eeh_capable
|| !(pdn
->eeh_mode
& EEH_MODE_SUPPORTED
) ||
553 pdn
->eeh_mode
& EEH_MODE_NOCHECK
) {
557 if (!pdn
->eeh_config_addr
) {
562 * If we already have a pending isolation event for this
563 * slot, we know it's bad already, we don't need to check...
565 if (pdn
->eeh_mode
& EEH_MODE_ISOLATED
) {
566 atomic_inc(&eeh_fail_count
);
567 if (atomic_read(&eeh_fail_count
) >= EEH_MAX_FAILS
) {
568 /* re-read the slot reset state */
569 if (read_slot_reset_state(dn
, rets
) != 0)
570 rets
[0] = -1; /* reset state unknown */
571 eeh_panic(dev
, rets
[0]);
577 * Now test for an EEH failure. This is VERY expensive.
578 * Note that the eeh_config_addr may be a parent device
579 * in the case of a device behind a bridge, or it may be
580 * function zero of a multi-function device.
581 * In any case they must share a common PHB.
583 ret
= read_slot_reset_state(dn
, rets
);
584 if (!(ret
== 0 && rets
[1] == 1 && (rets
[0] == 2 || rets
[0] == 4))) {
585 __get_cpu_var(false_positives
)++;
589 /* prevent repeated reports of this failure */
590 pdn
->eeh_mode
|= EEH_MODE_ISOLATED
;
592 reset_state
= rets
[0];
594 spin_lock_irqsave(&slot_errbuf_lock
, flags
);
595 memset(slot_errbuf
, 0, eeh_error_buf_size
);
597 rc
= rtas_call(ibm_slot_error_detail
,
598 8, 1, NULL
, pdn
->eeh_config_addr
,
599 BUID_HI(pdn
->phb
->buid
),
600 BUID_LO(pdn
->phb
->buid
), NULL
, 0,
601 virt_to_phys(slot_errbuf
),
603 1 /* Temporary Error */);
606 log_error(slot_errbuf
, ERR_TYPE_RTAS_LOG
, 0);
607 spin_unlock_irqrestore(&slot_errbuf_lock
, flags
);
609 printk(KERN_INFO
"EEH: MMIO failure (%d) on device: %s %s\n",
610 rets
[0], dn
->name
, dn
->full_name
);
611 event
= kmalloc(sizeof(*event
), GFP_ATOMIC
);
613 eeh_panic(dev
, reset_state
);
619 event
->reset_state
= reset_state
;
621 /* We may or may not be called in an interrupt context */
622 spin_lock_irqsave(&eeh_eventlist_lock
, flags
);
623 list_add(&event
->list
, &eeh_eventlist
);
624 spin_unlock_irqrestore(&eeh_eventlist_lock
, flags
);
626 /* Most EEH events are due to device driver bugs. Having
627 * a stack trace will help the device-driver authors figure
628 * out what happened. So print that out. */
630 schedule_work(&eeh_event_wq
);
635 EXPORT_SYMBOL(eeh_dn_check_failure
);
638 * eeh_check_failure - check if all 1's data is due to EEH slot freeze
639 * @token i/o token, should be address in the form 0xA....
640 * @val value, should be all 1's (XXX why do we need this arg??)
642 * Check for an eeh failure at the given token address.
643 * Check for an EEH failure at the given token address. Call this
644 * routine if the result of a read was all 0xff's and you want to
645 * find out if this is due to an EEH slot freeze event. This routine
646 * will query firmware for the EEH status.
648 * Note this routine is safe to call in an interrupt context.
650 unsigned long eeh_check_failure(const volatile void __iomem
*token
, unsigned long val
)
654 struct device_node
*dn
;
656 /* Finding the phys addr + pci device; this is pretty quick. */
657 addr
= eeh_token_to_phys((unsigned long __force
) token
);
658 dev
= pci_get_device_by_addr(addr
);
662 dn
= pci_device_to_OF_node(dev
);
663 eeh_dn_check_failure (dn
, dev
);
669 EXPORT_SYMBOL(eeh_check_failure
);
671 struct eeh_early_enable_info
{
672 unsigned int buid_hi
;
673 unsigned int buid_lo
;
676 /* Enable eeh for the given device node. */
677 static void *early_enable_eeh(struct device_node
*dn
, void *data
)
679 struct eeh_early_enable_info
*info
= data
;
681 char *status
= get_property(dn
, "status", NULL
);
682 u32
*class_code
= (u32
*)get_property(dn
, "class-code", NULL
);
683 u32
*vendor_id
= (u32
*)get_property(dn
, "vendor-id", NULL
);
684 u32
*device_id
= (u32
*)get_property(dn
, "device-id", NULL
);
687 struct pci_dn
*pdn
= dn
->data
;
691 if (status
&& strcmp(status
, "ok") != 0)
692 return NULL
; /* ignore devices with bad status */
694 /* Ignore bad nodes. */
695 if (!class_code
|| !vendor_id
|| !device_id
)
698 /* There is nothing to check on PCI to ISA bridges */
699 if (dn
->type
&& !strcmp(dn
->type
, "isa")) {
700 pdn
->eeh_mode
|= EEH_MODE_NOCHECK
;
705 * Now decide if we are going to "Disable" EEH checking
706 * for this device. We still run with the EEH hardware active,
707 * but we won't be checking for ff's. This means a driver
708 * could return bad data (very bad!), an interrupt handler could
709 * hang waiting on status bits that won't change, etc.
710 * But there are a few cases like display devices that make sense.
712 enable
= 1; /* i.e. we will do checking */
713 if ((*class_code
>> 16) == PCI_BASE_CLASS_DISPLAY
)
717 pdn
->eeh_mode
|= EEH_MODE_NOCHECK
;
719 /* Ok... see if this device supports EEH. Some do, some don't,
720 * and the only way to find out is to check each and every one. */
721 regs
= (u32
*)get_property(dn
, "reg", NULL
);
723 /* First register entry is addr (00BBSS00) */
724 /* Try to enable eeh */
725 ret
= rtas_call(ibm_set_eeh_option
, 4, 1, NULL
,
726 regs
[0], info
->buid_hi
, info
->buid_lo
,
729 eeh_subsystem_enabled
= 1;
730 pdn
->eeh_mode
|= EEH_MODE_SUPPORTED
;
731 pdn
->eeh_config_addr
= regs
[0];
733 printk(KERN_DEBUG
"EEH: %s: eeh enabled\n", dn
->full_name
);
737 /* This device doesn't support EEH, but it may have an
738 * EEH parent, in which case we mark it as supported. */
739 if (dn
->parent
&& dn
->parent
->data
740 && (PCI_DN(dn
->parent
)->eeh_mode
& EEH_MODE_SUPPORTED
)) {
741 /* Parent supports EEH. */
742 pdn
->eeh_mode
|= EEH_MODE_SUPPORTED
;
743 pdn
->eeh_config_addr
= PCI_DN(dn
->parent
)->eeh_config_addr
;
748 printk(KERN_WARNING
"EEH: %s: unable to get reg property.\n",
756 * Initialize EEH by trying to enable it for all of the adapters in the system.
757 * As a side effect we can determine here if eeh is supported at all.
758 * Note that we leave EEH on so failed config cycles won't cause a machine
759 * check. If a user turns off EEH for a particular adapter they are really
760 * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
761 * grant access to a slot if EEH isn't enabled, and so we always enable
762 * EEH for all slots/all devices.
764 * The eeh-force-off option disables EEH checking globally, for all slots.
765 * Even if force-off is set, the EEH hardware is still enabled, so that
766 * newer systems can boot.
768 void __init
eeh_init(void)
770 struct device_node
*phb
, *np
;
771 struct eeh_early_enable_info info
;
773 np
= of_find_node_by_path("/rtas");
777 ibm_set_eeh_option
= rtas_token("ibm,set-eeh-option");
778 ibm_set_slot_reset
= rtas_token("ibm,set-slot-reset");
779 ibm_read_slot_reset_state2
= rtas_token("ibm,read-slot-reset-state2");
780 ibm_read_slot_reset_state
= rtas_token("ibm,read-slot-reset-state");
781 ibm_slot_error_detail
= rtas_token("ibm,slot-error-detail");
783 if (ibm_set_eeh_option
== RTAS_UNKNOWN_SERVICE
)
786 eeh_error_buf_size
= rtas_token("rtas-error-log-max");
787 if (eeh_error_buf_size
== RTAS_UNKNOWN_SERVICE
) {
788 eeh_error_buf_size
= 1024;
790 if (eeh_error_buf_size
> RTAS_ERROR_LOG_MAX
) {
791 printk(KERN_WARNING
"EEH: rtas-error-log-max is bigger than allocated "
792 "buffer ! (%d vs %d)", eeh_error_buf_size
, RTAS_ERROR_LOG_MAX
);
793 eeh_error_buf_size
= RTAS_ERROR_LOG_MAX
;
796 /* Enable EEH for all adapters. Note that eeh requires buid's */
797 for (phb
= of_find_node_by_name(NULL
, "pci"); phb
;
798 phb
= of_find_node_by_name(phb
, "pci")) {
802 buid
= get_phb_buid(phb
);
803 if (buid
== 0 || phb
->data
== NULL
)
807 info
.buid_lo
= BUID_LO(buid
);
808 info
.buid_hi
= BUID_HI(buid
);
809 traverse_pci_devices(phb
, early_enable_eeh
, &info
);
812 if (eeh_subsystem_enabled
)
813 printk(KERN_INFO
"EEH: PCI Enhanced I/O Error Handling Enabled\n");
815 printk(KERN_WARNING
"EEH: No capable adapters found\n");
819 * eeh_add_device_early - enable EEH for the indicated device_node
820 * @dn: device node for which to set up EEH
822 * This routine must be used to perform EEH initialization for PCI
823 * devices that were added after system boot (e.g. hotplug, dlpar).
824 * This routine must be called before any i/o is performed to the
825 * adapter (inluding any config-space i/o).
826 * Whether this actually enables EEH or not for this device depends
827 * on the CEC architecture, type of the device, on earlier boot
828 * command-line arguments & etc.
830 void eeh_add_device_early(struct device_node
*dn
)
832 struct pci_controller
*phb
;
833 struct eeh_early_enable_info info
;
835 if (!dn
|| !dn
->data
)
837 phb
= PCI_DN(dn
)->phb
;
838 if (NULL
== phb
|| 0 == phb
->buid
) {
839 printk(KERN_WARNING
"EEH: Expected buid but found none\n");
843 info
.buid_hi
= BUID_HI(phb
->buid
);
844 info
.buid_lo
= BUID_LO(phb
->buid
);
845 early_enable_eeh(dn
, &info
);
847 EXPORT_SYMBOL(eeh_add_device_early
);
850 * eeh_add_device_late - perform EEH initialization for the indicated pci device
851 * @dev: pci device for which to set up EEH
853 * This routine must be used to complete EEH initialization for PCI
854 * devices that were added after system boot (e.g. hotplug, dlpar).
856 void eeh_add_device_late(struct pci_dev
*dev
)
858 if (!dev
|| !eeh_subsystem_enabled
)
862 printk(KERN_DEBUG
"EEH: adding device %s\n", pci_name(dev
));
865 pci_addr_cache_insert_device (dev
);
867 EXPORT_SYMBOL(eeh_add_device_late
);
870 * eeh_remove_device - undo EEH setup for the indicated pci device
871 * @dev: pci device to be removed
873 * This routine should be when a device is removed from a running
874 * system (e.g. by hotplug or dlpar).
876 void eeh_remove_device(struct pci_dev
*dev
)
878 if (!dev
|| !eeh_subsystem_enabled
)
881 /* Unregister the device with the EEH/PCI address search system */
883 printk(KERN_DEBUG
"EEH: remove device %s\n", pci_name(dev
));
885 pci_addr_cache_remove_device(dev
);
887 EXPORT_SYMBOL(eeh_remove_device
);
889 static int proc_eeh_show(struct seq_file
*m
, void *v
)
892 unsigned long ffs
= 0, positives
= 0, failures
= 0;
893 unsigned long resets
= 0;
896 ffs
+= per_cpu(total_mmio_ffs
, cpu
);
897 positives
+= per_cpu(false_positives
, cpu
);
898 failures
+= per_cpu(ignored_failures
, cpu
);
899 resets
+= per_cpu(slot_resets
, cpu
);
902 if (0 == eeh_subsystem_enabled
) {
903 seq_printf(m
, "EEH Subsystem is globally disabled\n");
904 seq_printf(m
, "eeh_total_mmio_ffs=%ld\n", ffs
);
906 seq_printf(m
, "EEH Subsystem is enabled\n");
907 seq_printf(m
, "eeh_total_mmio_ffs=%ld\n"
908 "eeh_false_positives=%ld\n"
909 "eeh_ignored_failures=%ld\n"
910 "eeh_slot_resets=%ld\n"
911 "eeh_fail_count=%d\n",
912 ffs
, positives
, failures
, resets
,
913 eeh_fail_count
.counter
);
919 static int proc_eeh_open(struct inode
*inode
, struct file
*file
)
921 return single_open(file
, proc_eeh_show
, NULL
);
924 static struct file_operations proc_eeh_operations
= {
925 .open
= proc_eeh_open
,
928 .release
= single_release
,
931 static int __init
eeh_init_proc(void)
933 struct proc_dir_entry
*e
;
935 if (systemcfg
->platform
& PLATFORM_PSERIES
) {
936 e
= create_proc_entry("ppc64/eeh", 0, NULL
);
938 e
->proc_fops
= &proc_eeh_operations
;
943 __initcall(eeh_init_proc
);