aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/pseries
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms/pseries')
-rw-r--r--arch/powerpc/platforms/pseries/Makefile2
-rw-r--r--arch/powerpc/platforms/pseries/eeh.c1212
-rw-r--r--arch/powerpc/platforms/pseries/eeh_event.c155
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c3
-rw-r--r--arch/powerpc/platforms/pseries/pci.c3
-rw-r--r--arch/powerpc/platforms/pseries/reconfig.c2
-rw-r--r--arch/powerpc/platforms/pseries/rtasd.c8
-rw-r--r--arch/powerpc/platforms/pseries/scanlog.c235
-rw-r--r--arch/powerpc/platforms/pseries/setup.c8
-rw-r--r--arch/powerpc/platforms/pseries/smp.c5
-rw-r--r--arch/powerpc/platforms/pseries/xics.c7
11 files changed, 1623 insertions, 17 deletions
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index b9938fece781..e7ca5b1f591e 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -3,3 +3,5 @@ obj-y := pci.o lpar.o hvCall.o nvram.o reconfig.o \
3obj-$(CONFIG_SMP) += smp.o 3obj-$(CONFIG_SMP) += smp.o
4obj-$(CONFIG_IBMVIO) += vio.o 4obj-$(CONFIG_IBMVIO) += vio.o
5obj-$(CONFIG_XICS) += xics.o 5obj-$(CONFIG_XICS) += xics.o
6obj-$(CONFIG_SCANLOG) += scanlog.o
7obj-$(CONFIG_EEH) += eeh.o eeh_event.o
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
new file mode 100644
index 000000000000..79de2310e70b
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -0,0 +1,1212 @@
1/*
2 * eeh.c
3 * Copyright (C) 2001 Dave Engebretsen & Todd Inglett IBM Corporation
4 *
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.
9 *
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.
14 *
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
20#include <linux/delay.h>
21#include <linux/init.h>
22#include <linux/list.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>
28#include <asm/atomic.h>
29#include <asm/eeh.h>
30#include <asm/eeh_event.h>
31#include <asm/io.h>
32#include <asm/machdep.h>
33#include <asm/ppc-pci.h>
34#include <asm/rtas.h>
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),
50 * which in turn might be caused by low voltage on the bus, dust,
51 * vibration, humidity, radioactivity or plain-old failed hardware.
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
72/* If a device driver keeps reading an MMIO register in an interrupt
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 */
77#define EEH_MAX_FAILS 100000
78
79/* Misc forward declaraions */
80static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn);
81
82/* RTAS tokens */
83static int ibm_set_eeh_option;
84static int ibm_set_slot_reset;
85static int ibm_read_slot_reset_state;
86static int ibm_read_slot_reset_state2;
87static int ibm_slot_error_detail;
88
89static int eeh_subsystem_enabled;
90
91/* Lock to avoid races due to multiple reports of an error */
92static DEFINE_SPINLOCK(confirm_error_lock);
93
94/* Buffer for reporting slot-error-detail rtas calls */
95static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
96static DEFINE_SPINLOCK(slot_errbuf_lock);
97static int eeh_error_buf_size;
98
99/* System monitoring statistics */
100static DEFINE_PER_CPU(unsigned long, no_device);
101static DEFINE_PER_CPU(unsigned long, no_dn);
102static DEFINE_PER_CPU(unsigned long, no_cfg_addr);
103static DEFINE_PER_CPU(unsigned long, ignored_check);
104static DEFINE_PER_CPU(unsigned long, total_mmio_ffs);
105static DEFINE_PER_CPU(unsigned long, false_positives);
106static DEFINE_PER_CPU(unsigned long, ignored_failures);
107static DEFINE_PER_CPU(unsigned long, slot_resets);
108
109/**
110 * The pci address cache subsystem. This subsystem places
111 * PCI device address resources into a red-black tree, sorted
112 * according to the address range, so that given only an i/o
113 * address, the corresponding PCI device can be **quickly**
114 * found. It is safe to perform an address lookup in an interrupt
115 * context; this ability is an important feature.
116 *
117 * Currently, the only customer of this code is the EEH subsystem;
118 * thus, this code has been somewhat tailored to suit EEH better.
119 * In particular, the cache does *not* hold the addresses of devices
120 * for which EEH is not enabled.
121 *
122 * (Implementation Note: The RB tree seems to be better/faster
123 * than any hash algo I could think of for this problem, even
124 * with the penalty of slow pointer chases for d-cache misses).
125 */
126struct pci_io_addr_range
127{
128 struct rb_node rb_node;
129 unsigned long addr_lo;
130 unsigned long addr_hi;
131 struct pci_dev *pcidev;
132 unsigned int flags;
133};
134
135static struct pci_io_addr_cache
136{
137 struct rb_root rb_root;
138 spinlock_t piar_lock;
139} pci_io_addr_cache_root;
140
141static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)
142{
143 struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
144
145 while (n) {
146 struct pci_io_addr_range *piar;
147 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
148
149 if (addr < piar->addr_lo) {
150 n = n->rb_left;
151 } else {
152 if (addr > piar->addr_hi) {
153 n = n->rb_right;
154 } else {
155 pci_dev_get(piar->pcidev);
156 return piar->pcidev;
157 }
158 }
159 }
160
161 return NULL;
162}
163
164/**
165 * pci_get_device_by_addr - Get device, given only address
166 * @addr: mmio (PIO) phys address or i/o port number
167 *
168 * Given an mmio phys address, or a port number, find a pci device
169 * that implements this address. Be sure to pci_dev_put the device
170 * when finished. I/O port numbers are assumed to be offset
171 * from zero (that is, they do *not* have pci_io_addr added in).
172 * It is safe to call this function within an interrupt.
173 */
174static struct pci_dev *pci_get_device_by_addr(unsigned long addr)
175{
176 struct pci_dev *dev;
177 unsigned long flags;
178
179 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
180 dev = __pci_get_device_by_addr(addr);
181 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
182 return dev;
183}
184
185#ifdef DEBUG
186/*
187 * Handy-dandy debug print routine, does nothing more
188 * than print out the contents of our addr cache.
189 */
190static void pci_addr_cache_print(struct pci_io_addr_cache *cache)
191{
192 struct rb_node *n;
193 int cnt = 0;
194
195 n = rb_first(&cache->rb_root);
196 while (n) {
197 struct pci_io_addr_range *piar;
198 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
199 printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",
200 (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
201 piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));
202 cnt++;
203 n = rb_next(n);
204 }
205}
206#endif
207
208/* Insert address range into the rb tree. */
209static struct pci_io_addr_range *
210pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,
211 unsigned long ahi, unsigned int flags)
212{
213 struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
214 struct rb_node *parent = NULL;
215 struct pci_io_addr_range *piar;
216
217 /* Walk tree, find a place to insert into tree */
218 while (*p) {
219 parent = *p;
220 piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
221 if (ahi < piar->addr_lo) {
222 p = &parent->rb_left;
223 } else if (alo > piar->addr_hi) {
224 p = &parent->rb_right;
225 } else {
226 if (dev != piar->pcidev ||
227 alo != piar->addr_lo || ahi != piar->addr_hi) {
228 printk(KERN_WARNING "PIAR: overlapping address range\n");
229 }
230 return piar;
231 }
232 }
233 piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
234 if (!piar)
235 return NULL;
236
237 piar->addr_lo = alo;
238 piar->addr_hi = ahi;
239 piar->pcidev = dev;
240 piar->flags = flags;
241
242#ifdef DEBUG
243 printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",
244 alo, ahi, pci_name (dev));
245#endif
246
247 rb_link_node(&piar->rb_node, parent, p);
248 rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
249
250 return piar;
251}
252
253static void __pci_addr_cache_insert_device(struct pci_dev *dev)
254{
255 struct device_node *dn;
256 struct pci_dn *pdn;
257 int i;
258 int inserted = 0;
259
260 dn = pci_device_to_OF_node(dev);
261 if (!dn) {
262 printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));
263 return;
264 }
265
266 /* Skip any devices for which EEH is not enabled. */
267 pdn = PCI_DN(dn);
268 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
269 pdn->eeh_mode & EEH_MODE_NOCHECK) {
270#ifdef DEBUG
271 printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",
272 pci_name(dev), pdn->node->full_name);
273#endif
274 return;
275 }
276
277 /* The cache holds a reference to the device... */
278 pci_dev_get(dev);
279
280 /* Walk resources on this device, poke them into the tree */
281 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
282 unsigned long start = pci_resource_start(dev,i);
283 unsigned long end = pci_resource_end(dev,i);
284 unsigned int flags = pci_resource_flags(dev,i);
285
286 /* We are interested only bus addresses, not dma or other stuff */
287 if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
288 continue;
289 if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
290 continue;
291 pci_addr_cache_insert(dev, start, end, flags);
292 inserted = 1;
293 }
294
295 /* If there was nothing to add, the cache has no reference... */
296 if (!inserted)
297 pci_dev_put(dev);
298}
299
300/**
301 * pci_addr_cache_insert_device - Add a device to the address cache
302 * @dev: PCI device whose I/O addresses we are interested in.
303 *
304 * In order to support the fast lookup of devices based on addresses,
305 * we maintain a cache of devices that can be quickly searched.
306 * This routine adds a device to that cache.
307 */
308static void pci_addr_cache_insert_device(struct pci_dev *dev)
309{
310 unsigned long flags;
311
312 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
313 __pci_addr_cache_insert_device(dev);
314 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
315}
316
317static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
318{
319 struct rb_node *n;
320 int removed = 0;
321
322restart:
323 n = rb_first(&pci_io_addr_cache_root.rb_root);
324 while (n) {
325 struct pci_io_addr_range *piar;
326 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
327
328 if (piar->pcidev == dev) {
329 rb_erase(n, &pci_io_addr_cache_root.rb_root);
330 removed = 1;
331 kfree(piar);
332 goto restart;
333 }
334 n = rb_next(n);
335 }
336
337 /* The cache no longer holds its reference to this device... */
338 if (removed)
339 pci_dev_put(dev);
340}
341
342/**
343 * pci_addr_cache_remove_device - remove pci device from addr cache
344 * @dev: device to remove
345 *
346 * Remove a device from the addr-cache tree.
347 * This is potentially expensive, since it will walk
348 * the tree multiple times (once per resource).
349 * But so what; device removal doesn't need to be that fast.
350 */
351static void pci_addr_cache_remove_device(struct pci_dev *dev)
352{
353 unsigned long flags;
354
355 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
356 __pci_addr_cache_remove_device(dev);
357 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
358}
359
360/**
361 * pci_addr_cache_build - Build a cache of I/O addresses
362 *
363 * Build a cache of pci i/o addresses. This cache will be used to
364 * find the pci device that corresponds to a given address.
365 * This routine scans all pci busses to build the cache.
366 * Must be run late in boot process, after the pci controllers
367 * have been scaned for devices (after all device resources are known).
368 */
369void __init pci_addr_cache_build(void)
370{
371 struct device_node *dn;
372 struct pci_dev *dev = NULL;
373
374 if (!eeh_subsystem_enabled)
375 return;
376
377 spin_lock_init(&pci_io_addr_cache_root.piar_lock);
378
379 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
380 /* Ignore PCI bridges ( XXX why ??) */
381 if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
382 continue;
383 }
384 pci_addr_cache_insert_device(dev);
385
386 /* Save the BAR's; firmware doesn't restore these after EEH reset */
387 dn = pci_device_to_OF_node(dev);
388 eeh_save_bars(dev, PCI_DN(dn));
389 }
390
391#ifdef DEBUG
392 /* Verify tree built up above, echo back the list of addrs. */
393 pci_addr_cache_print(&pci_io_addr_cache_root);
394#endif
395}
396
397/* --------------------------------------------------------------- */
398/* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
399
400void eeh_slot_error_detail (struct pci_dn *pdn, int severity)
401{
402 unsigned long flags;
403 int rc;
404
405 /* Log the error with the rtas logger */
406 spin_lock_irqsave(&slot_errbuf_lock, flags);
407 memset(slot_errbuf, 0, eeh_error_buf_size);
408
409 rc = rtas_call(ibm_slot_error_detail,
410 8, 1, NULL, pdn->eeh_config_addr,
411 BUID_HI(pdn->phb->buid),
412 BUID_LO(pdn->phb->buid), NULL, 0,
413 virt_to_phys(slot_errbuf),
414 eeh_error_buf_size,
415 severity);
416
417 if (rc == 0)
418 log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
419 spin_unlock_irqrestore(&slot_errbuf_lock, flags);
420}
421
422/**
423 * read_slot_reset_state - Read the reset state of a device node's slot
424 * @dn: device node to read
425 * @rets: array to return results in
426 */
427static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
428{
429 int token, outputs;
430
431 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
432 token = ibm_read_slot_reset_state2;
433 outputs = 4;
434 } else {
435 token = ibm_read_slot_reset_state;
436 rets[2] = 0; /* fake PE Unavailable info */
437 outputs = 3;
438 }
439
440 return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr,
441 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
442}
443
444/**
445 * eeh_token_to_phys - convert EEH address token to phys address
446 * @token i/o token, should be address in the form 0xA....
447 */
448static inline unsigned long eeh_token_to_phys(unsigned long token)
449{
450 pte_t *ptep;
451 unsigned long pa;
452
453 ptep = find_linux_pte(init_mm.pgd, token);
454 if (!ptep)
455 return token;
456 pa = pte_pfn(*ptep) << PAGE_SHIFT;
457
458 return pa | (token & (PAGE_SIZE-1));
459}
460
461/**
462 * Return the "partitionable endpoint" (pe) under which this device lies
463 */
464static struct device_node * find_device_pe(struct device_node *dn)
465{
466 while ((dn->parent) && PCI_DN(dn->parent) &&
467 (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
468 dn = dn->parent;
469 }
470 return dn;
471}
472
473/** Mark all devices that are peers of this device as failed.
474 * Mark the device driver too, so that it can see the failure
475 * immediately; this is critical, since some drivers poll
476 * status registers in interrupts ... If a driver is polling,
477 * and the slot is frozen, then the driver can deadlock in
478 * an interrupt context, which is bad.
479 */
480
481static void __eeh_mark_slot (struct device_node *dn, int mode_flag)
482{
483 while (dn) {
484 if (PCI_DN(dn)) {
485 PCI_DN(dn)->eeh_mode |= mode_flag;
486
487 if (dn->child)
488 __eeh_mark_slot (dn->child, mode_flag);
489 }
490 dn = dn->sibling;
491 }
492}
493
494void eeh_mark_slot (struct device_node *dn, int mode_flag)
495{
496 dn = find_device_pe (dn);
497 PCI_DN(dn)->eeh_mode |= mode_flag;
498 __eeh_mark_slot (dn->child, mode_flag);
499}
500
501static void __eeh_clear_slot (struct device_node *dn, int mode_flag)
502{
503 while (dn) {
504 if (PCI_DN(dn)) {
505 PCI_DN(dn)->eeh_mode &= ~mode_flag;
506 PCI_DN(dn)->eeh_check_count = 0;
507 if (dn->child)
508 __eeh_clear_slot (dn->child, mode_flag);
509 }
510 dn = dn->sibling;
511 }
512}
513
514void eeh_clear_slot (struct device_node *dn, int mode_flag)
515{
516 unsigned long flags;
517 spin_lock_irqsave(&confirm_error_lock, flags);
518 dn = find_device_pe (dn);
519 PCI_DN(dn)->eeh_mode &= ~mode_flag;
520 PCI_DN(dn)->eeh_check_count = 0;
521 __eeh_clear_slot (dn->child, mode_flag);
522 spin_unlock_irqrestore(&confirm_error_lock, flags);
523}
524
525/**
526 * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
527 * @dn device node
528 * @dev pci device, if known
529 *
530 * Check for an EEH failure for the given device node. Call this
531 * routine if the result of a read was all 0xff's and you want to
532 * find out if this is due to an EEH slot freeze. This routine
533 * will query firmware for the EEH status.
534 *
535 * Returns 0 if there has not been an EEH error; otherwise returns
536 * a non-zero value and queues up a slot isolation event notification.
537 *
538 * It is safe to call this routine in an interrupt context.
539 */
540int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
541{
542 int ret;
543 int rets[3];
544 unsigned long flags;
545 struct pci_dn *pdn;
546 int rc = 0;
547
548 __get_cpu_var(total_mmio_ffs)++;
549
550 if (!eeh_subsystem_enabled)
551 return 0;
552
553 if (!dn) {
554 __get_cpu_var(no_dn)++;
555 return 0;
556 }
557 pdn = PCI_DN(dn);
558
559 /* Access to IO BARs might get this far and still not want checking. */
560 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
561 pdn->eeh_mode & EEH_MODE_NOCHECK) {
562 __get_cpu_var(ignored_check)++;
563#ifdef DEBUG
564 printk ("EEH:ignored check (%x) for %s %s\n",
565 pdn->eeh_mode, pci_name (dev), dn->full_name);
566#endif
567 return 0;
568 }
569
570 if (!pdn->eeh_config_addr) {
571 __get_cpu_var(no_cfg_addr)++;
572 return 0;
573 }
574
575 /* If we already have a pending isolation event for this
576 * slot, we know it's bad already, we don't need to check.
577 * Do this checking under a lock; as multiple PCI devices
578 * in one slot might report errors simultaneously, and we
579 * only want one error recovery routine running.
580 */
581 spin_lock_irqsave(&confirm_error_lock, flags);
582 rc = 1;
583 if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
584 pdn->eeh_check_count ++;
585 if (pdn->eeh_check_count >= EEH_MAX_FAILS) {
586 printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n",
587 pdn->eeh_check_count);
588 dump_stack();
589
590 /* re-read the slot reset state */
591 if (read_slot_reset_state(pdn, rets) != 0)
592 rets[0] = -1; /* reset state unknown */
593
594 /* If we are here, then we hit an infinite loop. Stop. */
595 panic("EEH: MMIO halt (%d) on device:%s\n", rets[0], pci_name(dev));
596 }
597 goto dn_unlock;
598 }
599
600 /*
601 * Now test for an EEH failure. This is VERY expensive.
602 * Note that the eeh_config_addr may be a parent device
603 * in the case of a device behind a bridge, or it may be
604 * function zero of a multi-function device.
605 * In any case they must share a common PHB.
606 */
607 ret = read_slot_reset_state(pdn, rets);
608
609 /* If the call to firmware failed, punt */
610 if (ret != 0) {
611 printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
612 ret, dn->full_name);
613 __get_cpu_var(false_positives)++;
614 rc = 0;
615 goto dn_unlock;
616 }
617
618 /* If EEH is not supported on this device, punt. */
619 if (rets[1] != 1) {
620 printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
621 ret, dn->full_name);
622 __get_cpu_var(false_positives)++;
623 rc = 0;
624 goto dn_unlock;
625 }
626
627 /* If not the kind of error we know about, punt. */
628 if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
629 __get_cpu_var(false_positives)++;
630 rc = 0;
631 goto dn_unlock;
632 }
633
634 /* Note that config-io to empty slots may fail;
635 * we recognize empty because they don't have children. */
636 if ((rets[0] == 5) && (dn->child == NULL)) {
637 __get_cpu_var(false_positives)++;
638 rc = 0;
639 goto dn_unlock;
640 }
641
642 __get_cpu_var(slot_resets)++;
643
644 /* Avoid repeated reports of this failure, including problems
645 * with other functions on this device, and functions under
646 * bridges. */
647 eeh_mark_slot (dn, EEH_MODE_ISOLATED);
648 spin_unlock_irqrestore(&confirm_error_lock, flags);
649
650 eeh_send_failure_event (dn, dev, rets[0], rets[2]);
651
652 /* Most EEH events are due to device driver bugs. Having
653 * a stack trace will help the device-driver authors figure
654 * out what happened. So print that out. */
655 if (rets[0] != 5) dump_stack();
656 return 1;
657
658dn_unlock:
659 spin_unlock_irqrestore(&confirm_error_lock, flags);
660 return rc;
661}
662
663EXPORT_SYMBOL_GPL(eeh_dn_check_failure);
664
665/**
666 * eeh_check_failure - check if all 1's data is due to EEH slot freeze
667 * @token i/o token, should be address in the form 0xA....
668 * @val value, should be all 1's (XXX why do we need this arg??)
669 *
670 * Check for an EEH failure at the given token address. Call this
671 * routine if the result of a read was all 0xff's and you want to
672 * find out if this is due to an EEH slot freeze event. This routine
673 * will query firmware for the EEH status.
674 *
675 * Note this routine is safe to call in an interrupt context.
676 */
677unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
678{
679 unsigned long addr;
680 struct pci_dev *dev;
681 struct device_node *dn;
682
683 /* Finding the phys addr + pci device; this is pretty quick. */
684 addr = eeh_token_to_phys((unsigned long __force) token);
685 dev = pci_get_device_by_addr(addr);
686 if (!dev) {
687 __get_cpu_var(no_device)++;
688 return val;
689 }
690
691 dn = pci_device_to_OF_node(dev);
692 eeh_dn_check_failure (dn, dev);
693
694 pci_dev_put(dev);
695 return val;
696}
697
698EXPORT_SYMBOL(eeh_check_failure);
699
700/* ------------------------------------------------------------- */
701/* The code below deals with error recovery */
702
703/** Return negative value if a permanent error, else return
704 * a number of milliseconds to wait until the PCI slot is
705 * ready to be used.
706 */
707static int
708eeh_slot_availability(struct pci_dn *pdn)
709{
710 int rc;
711 int rets[3];
712
713 rc = read_slot_reset_state(pdn, rets);
714
715 if (rc) return rc;
716
717 if (rets[1] == 0) return -1; /* EEH is not supported */
718 if (rets[0] == 0) return 0; /* Oll Korrect */
719 if (rets[0] == 5) {
720 if (rets[2] == 0) return -1; /* permanently unavailable */
721 return rets[2]; /* number of millisecs to wait */
722 }
723 return -1;
724}
725
726/** rtas_pci_slot_reset raises/lowers the pci #RST line
727 * state: 1/0 to raise/lower the #RST
728 *
729 * Clear the EEH-frozen condition on a slot. This routine
730 * asserts the PCI #RST line if the 'state' argument is '1',
731 * and drops the #RST line if 'state is '0'. This routine is
732 * safe to call in an interrupt context.
733 *
734 */
735
736static void
737rtas_pci_slot_reset(struct pci_dn *pdn, int state)
738{
739 int rc;
740
741 BUG_ON (pdn==NULL);
742
743 if (!pdn->phb) {
744 printk (KERN_WARNING "EEH: in slot reset, device node %s has no phb\n",
745 pdn->node->full_name);
746 return;
747 }
748
749 rc = rtas_call(ibm_set_slot_reset,4,1, NULL,
750 pdn->eeh_config_addr,
751 BUID_HI(pdn->phb->buid),
752 BUID_LO(pdn->phb->buid),
753 state);
754 if (rc) {
755 printk (KERN_WARNING "EEH: Unable to reset the failed slot, (%d) #RST=%d dn=%s\n",
756 rc, state, pdn->node->full_name);
757 return;
758 }
759}
760
761/** rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
762 * dn -- device node to be reset.
763 */
764
765void
766rtas_set_slot_reset(struct pci_dn *pdn)
767{
768 int i, rc;
769
770 rtas_pci_slot_reset (pdn, 1);
771
772 /* The PCI bus requires that the reset be held high for at least
773 * a 100 milliseconds. We wait a bit longer 'just in case'. */
774
775#define PCI_BUS_RST_HOLD_TIME_MSEC 250
776 msleep (PCI_BUS_RST_HOLD_TIME_MSEC);
777
778 /* We might get hit with another EEH freeze as soon as the
779 * pci slot reset line is dropped. Make sure we don't miss
780 * these, and clear the flag now. */
781 eeh_clear_slot (pdn->node, EEH_MODE_ISOLATED);
782
783 rtas_pci_slot_reset (pdn, 0);
784
785 /* After a PCI slot has been reset, the PCI Express spec requires
786 * a 1.5 second idle time for the bus to stabilize, before starting
787 * up traffic. */
788#define PCI_BUS_SETTLE_TIME_MSEC 1800
789 msleep (PCI_BUS_SETTLE_TIME_MSEC);
790
791 /* Now double check with the firmware to make sure the device is
792 * ready to be used; if not, wait for recovery. */
793 for (i=0; i<10; i++) {
794 rc = eeh_slot_availability (pdn);
795 if (rc <= 0) break;
796
797 msleep (rc+100);
798 }
799}
800
801/* ------------------------------------------------------- */
802/** Save and restore of PCI BARs
803 *
804 * Although firmware will set up BARs during boot, it doesn't
805 * set up device BAR's after a device reset, although it will,
806 * if requested, set up bridge configuration. Thus, we need to
807 * configure the PCI devices ourselves.
808 */
809
810/**
811 * __restore_bars - Restore the Base Address Registers
812 * Loads the PCI configuration space base address registers,
813 * the expansion ROM base address, the latency timer, and etc.
814 * from the saved values in the device node.
815 */
816static inline void __restore_bars (struct pci_dn *pdn)
817{
818 int i;
819
820 if (NULL==pdn->phb) return;
821 for (i=4; i<10; i++) {
822 rtas_write_config(pdn, i*4, 4, pdn->config_space[i]);
823 }
824
825 /* 12 == Expansion ROM Address */
826 rtas_write_config(pdn, 12*4, 4, pdn->config_space[12]);
827
828#define BYTE_SWAP(OFF) (8*((OFF)/4)+3-(OFF))
829#define SAVED_BYTE(OFF) (((u8 *)(pdn->config_space))[BYTE_SWAP(OFF)])
830
831 rtas_write_config (pdn, PCI_CACHE_LINE_SIZE, 1,
832 SAVED_BYTE(PCI_CACHE_LINE_SIZE));
833
834 rtas_write_config (pdn, PCI_LATENCY_TIMER, 1,
835 SAVED_BYTE(PCI_LATENCY_TIMER));
836
837 /* max latency, min grant, interrupt pin and line */
838 rtas_write_config(pdn, 15*4, 4, pdn->config_space[15]);
839}
840
841/**
842 * eeh_restore_bars - restore the PCI config space info
843 *
844 * This routine performs a recursive walk to the children
845 * of this device as well.
846 */
847void eeh_restore_bars(struct pci_dn *pdn)
848{
849 struct device_node *dn;
850 if (!pdn)
851 return;
852
853 if (! pdn->eeh_is_bridge)
854 __restore_bars (pdn);
855
856 dn = pdn->node->child;
857 while (dn) {
858 eeh_restore_bars (PCI_DN(dn));
859 dn = dn->sibling;
860 }
861}
862
863/**
864 * eeh_save_bars - save device bars
865 *
866 * Save the values of the device bars. Unlike the restore
867 * routine, this routine is *not* recursive. This is because
868 * PCI devices are added individuallly; but, for the restore,
869 * an entire slot is reset at a time.
870 */
871static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn)
872{
873 int i;
874
875 if (!pdev || !pdn )
876 return;
877
878 for (i = 0; i < 16; i++)
879 pci_read_config_dword(pdev, i * 4, &pdn->config_space[i]);
880
881 if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
882 pdn->eeh_is_bridge = 1;
883}
884
885void
886rtas_configure_bridge(struct pci_dn *pdn)
887{
888 int token = rtas_token ("ibm,configure-bridge");
889 int rc;
890
891 if (token == RTAS_UNKNOWN_SERVICE)
892 return;
893 rc = rtas_call(token,3,1, NULL,
894 pdn->eeh_config_addr,
895 BUID_HI(pdn->phb->buid),
896 BUID_LO(pdn->phb->buid));
897 if (rc) {
898 printk (KERN_WARNING "EEH: Unable to configure device bridge (%d) for %s\n",
899 rc, pdn->node->full_name);
900 }
901}
902
903/* ------------------------------------------------------------- */
904/* The code below deals with enabling EEH for devices during the
905 * early boot sequence. EEH must be enabled before any PCI probing
906 * can be done.
907 */
908
909#define EEH_ENABLE 1
910
911struct eeh_early_enable_info {
912 unsigned int buid_hi;
913 unsigned int buid_lo;
914};
915
916/* Enable eeh for the given device node. */
917static void *early_enable_eeh(struct device_node *dn, void *data)
918{
919 struct eeh_early_enable_info *info = data;
920 int ret;
921 char *status = get_property(dn, "status", NULL);
922 u32 *class_code = (u32 *)get_property(dn, "class-code", NULL);
923 u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL);
924 u32 *device_id = (u32 *)get_property(dn, "device-id", NULL);
925 u32 *regs;
926 int enable;
927 struct pci_dn *pdn = PCI_DN(dn);
928
929 pdn->eeh_mode = 0;
930 pdn->eeh_check_count = 0;
931 pdn->eeh_freeze_count = 0;
932
933 if (status && strcmp(status, "ok") != 0)
934 return NULL; /* ignore devices with bad status */
935
936 /* Ignore bad nodes. */
937 if (!class_code || !vendor_id || !device_id)
938 return NULL;
939
940 /* There is nothing to check on PCI to ISA bridges */
941 if (dn->type && !strcmp(dn->type, "isa")) {
942 pdn->eeh_mode |= EEH_MODE_NOCHECK;
943 return NULL;
944 }
945
946 /*
947 * Now decide if we are going to "Disable" EEH checking
948 * for this device. We still run with the EEH hardware active,
949 * but we won't be checking for ff's. This means a driver
950 * could return bad data (very bad!), an interrupt handler could
951 * hang waiting on status bits that won't change, etc.
952 * But there are a few cases like display devices that make sense.
953 */
954 enable = 1; /* i.e. we will do checking */
955 if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
956 enable = 0;
957
958 if (!enable)
959 pdn->eeh_mode |= EEH_MODE_NOCHECK;
960
961 /* Ok... see if this device supports EEH. Some do, some don't,
962 * and the only way to find out is to check each and every one. */
963 regs = (u32 *)get_property(dn, "reg", NULL);
964 if (regs) {
965 /* First register entry is addr (00BBSS00) */
966 /* Try to enable eeh */
967 ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
968 regs[0], info->buid_hi, info->buid_lo,
969 EEH_ENABLE);
970
971 if (ret == 0) {
972 eeh_subsystem_enabled = 1;
973 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
974 pdn->eeh_config_addr = regs[0];
975#ifdef DEBUG
976 printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);
977#endif
978 } else {
979
980 /* This device doesn't support EEH, but it may have an
981 * EEH parent, in which case we mark it as supported. */
982 if (dn->parent && PCI_DN(dn->parent)
983 && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
984 /* Parent supports EEH. */
985 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
986 pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
987 return NULL;
988 }
989 }
990 } else {
991 printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
992 dn->full_name);
993 }
994
995 return NULL;
996}
997
998/*
999 * Initialize EEH by trying to enable it for all of the adapters in the system.
1000 * As a side effect we can determine here if eeh is supported at all.
1001 * Note that we leave EEH on so failed config cycles won't cause a machine
1002 * check. If a user turns off EEH for a particular adapter they are really
1003 * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
1004 * grant access to a slot if EEH isn't enabled, and so we always enable
1005 * EEH for all slots/all devices.
1006 *
1007 * The eeh-force-off option disables EEH checking globally, for all slots.
1008 * Even if force-off is set, the EEH hardware is still enabled, so that
1009 * newer systems can boot.
1010 */
1011void __init eeh_init(void)
1012{
1013 struct device_node *phb, *np;
1014 struct eeh_early_enable_info info;
1015
1016 spin_lock_init(&confirm_error_lock);
1017 spin_lock_init(&slot_errbuf_lock);
1018
1019 np = of_find_node_by_path("/rtas");
1020 if (np == NULL)
1021 return;
1022
1023 ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
1024 ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
1025 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
1026 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
1027 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
1028
1029 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
1030 return;
1031
1032 eeh_error_buf_size = rtas_token("rtas-error-log-max");
1033 if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
1034 eeh_error_buf_size = 1024;
1035 }
1036 if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
1037 printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
1038 "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
1039 eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
1040 }
1041
1042 /* Enable EEH for all adapters. Note that eeh requires buid's */
1043 for (phb = of_find_node_by_name(NULL, "pci"); phb;
1044 phb = of_find_node_by_name(phb, "pci")) {
1045 unsigned long buid;
1046
1047 buid = get_phb_buid(phb);
1048 if (buid == 0 || PCI_DN(phb) == NULL)
1049 continue;
1050
1051 info.buid_lo = BUID_LO(buid);
1052 info.buid_hi = BUID_HI(buid);
1053 traverse_pci_devices(phb, early_enable_eeh, &info);
1054 }
1055
1056 if (eeh_subsystem_enabled)
1057 printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
1058 else
1059 printk(KERN_WARNING "EEH: No capable adapters found\n");
1060}
1061
1062/**
1063 * eeh_add_device_early - enable EEH for the indicated device_node
1064 * @dn: device node for which to set up EEH
1065 *
1066 * This routine must be used to perform EEH initialization for PCI
1067 * devices that were added after system boot (e.g. hotplug, dlpar).
1068 * This routine must be called before any i/o is performed to the
1069 * adapter (inluding any config-space i/o).
1070 * Whether this actually enables EEH or not for this device depends
1071 * on the CEC architecture, type of the device, on earlier boot
1072 * command-line arguments & etc.
1073 */
1074void eeh_add_device_early(struct device_node *dn)
1075{
1076 struct pci_controller *phb;
1077 struct eeh_early_enable_info info;
1078
1079 if (!dn || !PCI_DN(dn))
1080 return;
1081 phb = PCI_DN(dn)->phb;
1082 if (NULL == phb || 0 == phb->buid) {
1083 printk(KERN_WARNING "EEH: Expected buid but found none for %s\n",
1084 dn->full_name);
1085 dump_stack();
1086 return;
1087 }
1088
1089 info.buid_hi = BUID_HI(phb->buid);
1090 info.buid_lo = BUID_LO(phb->buid);
1091 early_enable_eeh(dn, &info);
1092}
1093EXPORT_SYMBOL_GPL(eeh_add_device_early);
1094
1095/**
1096 * eeh_add_device_late - perform EEH initialization for the indicated pci device
1097 * @dev: pci device for which to set up EEH
1098 *
1099 * This routine must be used to complete EEH initialization for PCI
1100 * devices that were added after system boot (e.g. hotplug, dlpar).
1101 */
1102void eeh_add_device_late(struct pci_dev *dev)
1103{
1104 struct device_node *dn;
1105 struct pci_dn *pdn;
1106
1107 if (!dev || !eeh_subsystem_enabled)
1108 return;
1109
1110#ifdef DEBUG
1111 printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev));
1112#endif
1113
1114 pci_dev_get (dev);
1115 dn = pci_device_to_OF_node(dev);
1116 pdn = PCI_DN(dn);
1117 pdn->pcidev = dev;
1118
1119 pci_addr_cache_insert_device (dev);
1120 eeh_save_bars(dev, pdn);
1121}
1122EXPORT_SYMBOL_GPL(eeh_add_device_late);
1123
1124/**
1125 * eeh_remove_device - undo EEH setup for the indicated pci device
1126 * @dev: pci device to be removed
1127 *
1128 * This routine should be when a device is removed from a running
1129 * system (e.g. by hotplug or dlpar).
1130 */
1131void eeh_remove_device(struct pci_dev *dev)
1132{
1133 struct device_node *dn;
1134 if (!dev || !eeh_subsystem_enabled)
1135 return;
1136
1137 /* Unregister the device with the EEH/PCI address search system */
1138#ifdef DEBUG
1139 printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev));
1140#endif
1141 pci_addr_cache_remove_device(dev);
1142
1143 dn = pci_device_to_OF_node(dev);
1144 PCI_DN(dn)->pcidev = NULL;
1145 pci_dev_put (dev);
1146}
1147EXPORT_SYMBOL_GPL(eeh_remove_device);
1148
1149static int proc_eeh_show(struct seq_file *m, void *v)
1150{
1151 unsigned int cpu;
1152 unsigned long ffs = 0, positives = 0, failures = 0;
1153 unsigned long resets = 0;
1154 unsigned long no_dev = 0, no_dn = 0, no_cfg = 0, no_check = 0;
1155
1156 for_each_cpu(cpu) {
1157 ffs += per_cpu(total_mmio_ffs, cpu);
1158 positives += per_cpu(false_positives, cpu);
1159 failures += per_cpu(ignored_failures, cpu);
1160 resets += per_cpu(slot_resets, cpu);
1161 no_dev += per_cpu(no_device, cpu);
1162 no_dn += per_cpu(no_dn, cpu);
1163 no_cfg += per_cpu(no_cfg_addr, cpu);
1164 no_check += per_cpu(ignored_check, cpu);
1165 }
1166
1167 if (0 == eeh_subsystem_enabled) {
1168 seq_printf(m, "EEH Subsystem is globally disabled\n");
1169 seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);
1170 } else {
1171 seq_printf(m, "EEH Subsystem is enabled\n");
1172 seq_printf(m,
1173 "no device=%ld\n"
1174 "no device node=%ld\n"
1175 "no config address=%ld\n"
1176 "check not wanted=%ld\n"
1177 "eeh_total_mmio_ffs=%ld\n"
1178 "eeh_false_positives=%ld\n"
1179 "eeh_ignored_failures=%ld\n"
1180 "eeh_slot_resets=%ld\n",
1181 no_dev, no_dn, no_cfg, no_check,
1182 ffs, positives, failures, resets);
1183 }
1184
1185 return 0;
1186}
1187
1188static int proc_eeh_open(struct inode *inode, struct file *file)
1189{
1190 return single_open(file, proc_eeh_show, NULL);
1191}
1192
1193static struct file_operations proc_eeh_operations = {
1194 .open = proc_eeh_open,
1195 .read = seq_read,
1196 .llseek = seq_lseek,
1197 .release = single_release,
1198};
1199
1200static int __init eeh_init_proc(void)
1201{
1202 struct proc_dir_entry *e;
1203
1204 if (platform_is_pseries()) {
1205 e = create_proc_entry("ppc64/eeh", 0, NULL);
1206 if (e)
1207 e->proc_fops = &proc_eeh_operations;
1208 }
1209
1210 return 0;
1211}
1212__initcall(eeh_init_proc);
diff --git a/arch/powerpc/platforms/pseries/eeh_event.c b/arch/powerpc/platforms/pseries/eeh_event.c
new file mode 100644
index 000000000000..92497333c2b6
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/eeh_event.c
@@ -0,0 +1,155 @@
1/*
2 * eeh_event.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
19 */
20
21#include <linux/list.h>
22#include <linux/pci.h>
23#include <asm/eeh_event.h>
24
25/** Overview:
26 * EEH error states may be detected within exception handlers;
27 * however, the recovery processing needs to occur asynchronously
28 * in a normal kernel context and not an interrupt context.
29 * This pair of routines creates an event and queues it onto a
30 * work-queue, where a worker thread can drive recovery.
31 */
32
33/* EEH event workqueue setup. */
34static spinlock_t eeh_eventlist_lock = SPIN_LOCK_UNLOCKED;
35LIST_HEAD(eeh_eventlist);
36static void eeh_thread_launcher(void *);
37DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);
38
39/**
40 * eeh_panic - call panic() for an eeh event that cannot be handled.
41 * The philosophy of this routine is that it is better to panic and
42 * halt the OS than it is to risk possible data corruption by
43 * oblivious device drivers that don't know better.
44 *
45 * @dev pci device that had an eeh event
46 * @reset_state current reset state of the device slot
47 */
48static void eeh_panic(struct pci_dev *dev, int reset_state)
49{
50 /*
51 * Since the panic_on_oops sysctl is used to halt the system
52 * in light of potential corruption, we can use it here.
53 */
54 if (panic_on_oops) {
55 panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
56 pci_name(dev));
57 }
58 else {
59 printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
60 reset_state, pci_name(dev));
61 }
62}
63
64/**
65 * eeh_event_handler - dispatch EEH events. The detection of a frozen
66 * slot can occur inside an interrupt, where it can be hard to do
67 * anything about it. The goal of this routine is to pull these
68 * detection events out of the context of the interrupt handler, and
69 * re-dispatch them for processing at a later time in a normal context.
70 *
71 * @dummy - unused
72 */
73static int eeh_event_handler(void * dummy)
74{
75 unsigned long flags;
76 struct eeh_event *event;
77
78 daemonize ("eehd");
79
80 while (1) {
81 set_current_state(TASK_INTERRUPTIBLE);
82
83 spin_lock_irqsave(&eeh_eventlist_lock, flags);
84 event = NULL;
85 if (!list_empty(&eeh_eventlist)) {
86 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
87 list_del(&event->list);
88 }
89 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
90 if (event == NULL)
91 break;
92
93 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
94 pci_name(event->dev));
95
96 eeh_panic (event->dev, event->state);
97
98 kfree(event);
99 }
100
101 return 0;
102}
103
104/**
105 * eeh_thread_launcher
106 *
107 * @dummy - unused
108 */
109static void eeh_thread_launcher(void *dummy)
110{
111 if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
112 printk(KERN_ERR "Failed to start EEH daemon\n");
113}
114
115/**
116 * eeh_send_failure_event - generate a PCI error event
117 * @dev pci device
118 *
119 * This routine can be called within an interrupt context;
120 * the actual event will be delivered in a normal context
121 * (from a workqueue).
122 */
123int eeh_send_failure_event (struct device_node *dn,
124 struct pci_dev *dev,
125 int state,
126 int time_unavail)
127{
128 unsigned long flags;
129 struct eeh_event *event;
130
131 event = kmalloc(sizeof(*event), GFP_ATOMIC);
132 if (event == NULL) {
133 printk (KERN_ERR "EEH: out of memory, event not handled\n");
134 return 1;
135 }
136
137 if (dev)
138 pci_dev_get(dev);
139
140 event->dn = dn;
141 event->dev = dev;
142 event->state = state;
143 event->time_unavail = time_unavail;
144
145 /* We may or may not be called in an interrupt context */
146 spin_lock_irqsave(&eeh_eventlist_lock, flags);
147 list_add(&event->list, &eeh_eventlist);
148 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
149
150 schedule_work(&eeh_event_wq);
151
152 return 0;
153}
154
155/********************** END OF FILE ******************************/
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index fcc50bfd43fd..97ba5214417f 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -42,7 +42,6 @@
42#include <asm/machdep.h> 42#include <asm/machdep.h>
43#include <asm/abs_addr.h> 43#include <asm/abs_addr.h>
44#include <asm/pSeries_reconfig.h> 44#include <asm/pSeries_reconfig.h>
45#include <asm/systemcfg.h>
46#include <asm/firmware.h> 45#include <asm/firmware.h>
47#include <asm/tce.h> 46#include <asm/tce.h>
48#include <asm/ppc-pci.h> 47#include <asm/ppc-pci.h>
@@ -582,7 +581,7 @@ void iommu_init_early_pSeries(void)
582 return; 581 return;
583 } 582 }
584 583
585 if (systemcfg->platform & PLATFORM_LPAR) { 584 if (platform_is_lpar()) {
586 if (firmware_has_feature(FW_FEATURE_MULTITCE)) { 585 if (firmware_has_feature(FW_FEATURE_MULTITCE)) {
587 ppc_md.tce_build = tce_buildmulti_pSeriesLP; 586 ppc_md.tce_build = tce_buildmulti_pSeriesLP;
588 ppc_md.tce_free = tce_freemulti_pSeriesLP; 587 ppc_md.tce_free = tce_freemulti_pSeriesLP;
diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/pseries/pci.c
index c198656a3bb5..999a9620b5ce 100644
--- a/arch/powerpc/platforms/pseries/pci.c
+++ b/arch/powerpc/platforms/pseries/pci.c
@@ -107,7 +107,6 @@ static void __init pSeries_request_regions(void)
107 107
108void __init pSeries_final_fixup(void) 108void __init pSeries_final_fixup(void)
109{ 109{
110 phbs_remap_io();
111 pSeries_request_regions(); 110 pSeries_request_regions();
112 111
113 pci_addr_cache_build(); 112 pci_addr_cache_build();
@@ -123,7 +122,7 @@ static void fixup_winbond_82c105(struct pci_dev* dev)
123 int i; 122 int i;
124 unsigned int reg; 123 unsigned int reg;
125 124
126 if (!(systemcfg->platform & PLATFORM_PSERIES)) 125 if (!platform_is_pseries())
127 return; 126 return;
128 127
129 printk("Using INTC for W82c105 IDE controller.\n"); 128 printk("Using INTC for W82c105 IDE controller.\n");
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index d7d400339458..d8864164dbe8 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -408,7 +408,7 @@ static int proc_ppc64_create_ofdt(void)
408{ 408{
409 struct proc_dir_entry *ent; 409 struct proc_dir_entry *ent;
410 410
411 if (!(systemcfg->platform & PLATFORM_PSERIES)) 411 if (!platform_is_pseries())
412 return 0; 412 return 0;
413 413
414 ent = create_proc_entry("ppc64/ofdt", S_IWUSR, NULL); 414 ent = create_proc_entry("ppc64/ofdt", S_IWUSR, NULL);
diff --git a/arch/powerpc/platforms/pseries/rtasd.c b/arch/powerpc/platforms/pseries/rtasd.c
index e26b0420b6dd..00cf331a1dc4 100644
--- a/arch/powerpc/platforms/pseries/rtasd.c
+++ b/arch/powerpc/platforms/pseries/rtasd.c
@@ -482,10 +482,12 @@ static int __init rtas_init(void)
482{ 482{
483 struct proc_dir_entry *entry; 483 struct proc_dir_entry *entry;
484 484
485 /* No RTAS, only warn if we are on a pSeries box */ 485 if (!platform_is_pseries())
486 return 0;
487
488 /* No RTAS */
486 if (rtas_token("event-scan") == RTAS_UNKNOWN_SERVICE) { 489 if (rtas_token("event-scan") == RTAS_UNKNOWN_SERVICE) {
487 if (systemcfg->platform & PLATFORM_PSERIES) 490 printk(KERN_INFO "rtasd: no event-scan on system\n");
488 printk(KERN_INFO "rtasd: no event-scan on system\n");
489 return 1; 491 return 1;
490 } 492 }
491 493
diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
new file mode 100644
index 000000000000..2edc947f7c44
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/scanlog.c
@@ -0,0 +1,235 @@
1/*
2 * c 2001 PPC 64 Team, IBM Corp
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * scan-log-data driver for PPC64 Todd Inglett <tinglett@vnet.ibm.com>
10 *
11 * When ppc64 hardware fails the service processor dumps internal state
12 * of the system. After a reboot the operating system can access a dump
13 * of this data using this driver. A dump exists if the device-tree
14 * /chosen/ibm,scan-log-data property exists.
15 *
16 * This driver exports /proc/ppc64/scan-log-dump which can be read.
17 * The driver supports only sequential reads.
18 *
19 * The driver looks at a write to the driver for the single word "reset".
20 * If given, the driver will reset the scanlog so the platform can free it.
21 */
22
23#include <linux/module.h>
24#include <linux/types.h>
25#include <linux/errno.h>
26#include <linux/proc_fs.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <asm/uaccess.h>
30#include <asm/rtas.h>
31#include <asm/prom.h>
32
33#define MODULE_VERS "1.0"
34#define MODULE_NAME "scanlog"
35
36/* Status returns from ibm,scan-log-dump */
37#define SCANLOG_COMPLETE 0
38#define SCANLOG_HWERROR -1
39#define SCANLOG_CONTINUE 1
40
41#define DEBUG(A...) do { if (scanlog_debug) printk(KERN_ERR "scanlog: " A); } while (0)
42
43static int scanlog_debug;
44static unsigned int ibm_scan_log_dump; /* RTAS token */
45static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
46
47static ssize_t scanlog_read(struct file *file, char __user *buf,
48 size_t count, loff_t *ppos)
49{
50 struct inode * inode = file->f_dentry->d_inode;
51 struct proc_dir_entry *dp;
52 unsigned int *data;
53 int status;
54 unsigned long len, off;
55 unsigned int wait_time;
56
57 dp = PDE(inode);
58 data = (unsigned int *)dp->data;
59
60 if (!data) {
61 printk(KERN_ERR "scanlog: read failed no data\n");
62 return -EIO;
63 }
64
65 if (count > RTAS_DATA_BUF_SIZE)
66 count = RTAS_DATA_BUF_SIZE;
67
68 if (count < 1024) {
69 /* This is the min supported by this RTAS call. Rather
70 * than do all the buffering we insist the user code handle
71 * larger reads. As long as cp works... :)
72 */
73 printk(KERN_ERR "scanlog: cannot perform a small read (%ld)\n", count);
74 return -EINVAL;
75 }
76
77 if (!access_ok(VERIFY_WRITE, buf, count))
78 return -EFAULT;
79
80 for (;;) {
81 wait_time = 500; /* default wait if no data */
82 spin_lock(&rtas_data_buf_lock);
83 memcpy(rtas_data_buf, data, RTAS_DATA_BUF_SIZE);
84 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL,
85 (u32) __pa(rtas_data_buf), (u32) count);
86 memcpy(data, rtas_data_buf, RTAS_DATA_BUF_SIZE);
87 spin_unlock(&rtas_data_buf_lock);
88
89 DEBUG("status=%d, data[0]=%x, data[1]=%x, data[2]=%x\n",
90 status, data[0], data[1], data[2]);
91 switch (status) {
92 case SCANLOG_COMPLETE:
93 DEBUG("hit eof\n");
94 return 0;
95 case SCANLOG_HWERROR:
96 DEBUG("hardware error reading scan log data\n");
97 return -EIO;
98 case SCANLOG_CONTINUE:
99 /* We may or may not have data yet */
100 len = data[1];
101 off = data[2];
102 if (len > 0) {
103 if (copy_to_user(buf, ((char *)data)+off, len))
104 return -EFAULT;
105 return len;
106 }
107 /* Break to sleep default time */
108 break;
109 default:
110 if (status > 9900 && status <= 9905) {
111 wait_time = rtas_extended_busy_delay_time(status);
112 } else {
113 printk(KERN_ERR "scanlog: unknown error from rtas: %d\n", status);
114 return -EIO;
115 }
116 }
117 /* Apparently no data yet. Wait and try again. */
118 msleep_interruptible(wait_time);
119 }
120 /*NOTREACHED*/
121}
122
123static ssize_t scanlog_write(struct file * file, const char __user * buf,
124 size_t count, loff_t *ppos)
125{
126 char stkbuf[20];
127 int status;
128
129 if (count > 19) count = 19;
130 if (copy_from_user (stkbuf, buf, count)) {
131 return -EFAULT;
132 }
133 stkbuf[count] = 0;
134
135 if (buf) {
136 if (strncmp(stkbuf, "reset", 5) == 0) {
137 DEBUG("reset scanlog\n");
138 status = rtas_call(ibm_scan_log_dump, 2, 1, NULL, 0, 0);
139 DEBUG("rtas returns %d\n", status);
140 } else if (strncmp(stkbuf, "debugon", 7) == 0) {
141 printk(KERN_ERR "scanlog: debug on\n");
142 scanlog_debug = 1;
143 } else if (strncmp(stkbuf, "debugoff", 8) == 0) {
144 printk(KERN_ERR "scanlog: debug off\n");
145 scanlog_debug = 0;
146 }
147 }
148 return count;
149}
150
151static int scanlog_open(struct inode * inode, struct file * file)
152{
153 struct proc_dir_entry *dp = PDE(inode);
154 unsigned int *data = (unsigned int *)dp->data;
155
156 if (!data) {
157 printk(KERN_ERR "scanlog: open failed no data\n");
158 return -EIO;
159 }
160
161 if (data[0] != 0) {
162 /* This imperfect test stops a second copy of the
163 * data (or a reset while data is being copied)
164 */
165 return -EBUSY;
166 }
167
168 data[0] = 0; /* re-init so we restart the scan */
169
170 return 0;
171}
172
173static int scanlog_release(struct inode * inode, struct file * file)
174{
175 struct proc_dir_entry *dp = PDE(inode);
176 unsigned int *data = (unsigned int *)dp->data;
177
178 if (!data) {
179 printk(KERN_ERR "scanlog: release failed no data\n");
180 return -EIO;
181 }
182 data[0] = 0;
183
184 return 0;
185}
186
187struct file_operations scanlog_fops = {
188 .owner = THIS_MODULE,
189 .read = scanlog_read,
190 .write = scanlog_write,
191 .open = scanlog_open,
192 .release = scanlog_release,
193};
194
195int __init scanlog_init(void)
196{
197 struct proc_dir_entry *ent;
198
199 ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
200 if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE) {
201 printk(KERN_ERR "scan-log-dump not implemented on this system\n");
202 return -EIO;
203 }
204
205 ent = create_proc_entry("ppc64/rtas/scan-log-dump", S_IRUSR, NULL);
206 if (ent) {
207 ent->proc_fops = &scanlog_fops;
208 /* Ideally we could allocate a buffer < 4G */
209 ent->data = kmalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
210 if (!ent->data) {
211 printk(KERN_ERR "Failed to allocate a buffer\n");
212 remove_proc_entry("scan-log-dump", ent->parent);
213 return -ENOMEM;
214 }
215 ((unsigned int *)ent->data)[0] = 0;
216 } else {
217 printk(KERN_ERR "Failed to create ppc64/scan-log-dump proc entry\n");
218 return -EIO;
219 }
220 proc_ppc64_scan_log_dump = ent;
221
222 return 0;
223}
224
225void __exit scanlog_cleanup(void)
226{
227 if (proc_ppc64_scan_log_dump) {
228 kfree(proc_ppc64_scan_log_dump->data);
229 remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
230 }
231}
232
233module_init(scanlog_init);
234module_exit(scanlog_cleanup);
235MODULE_LICENSE("GPL");
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index a093a0d4dd69..e94247c28d42 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -249,7 +249,7 @@ static void __init pSeries_setup_arch(void)
249 ppc_md.idle_loop = default_idle; 249 ppc_md.idle_loop = default_idle;
250 } 250 }
251 251
252 if (systemcfg->platform & PLATFORM_LPAR) 252 if (platform_is_lpar())
253 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs; 253 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
254 else 254 else
255 ppc_md.enable_pmcs = power4_enable_pmcs; 255 ppc_md.enable_pmcs = power4_enable_pmcs;
@@ -378,7 +378,7 @@ static void __init pSeries_init_early(void)
378 378
379 fw_feature_init(); 379 fw_feature_init();
380 380
381 if (systemcfg->platform & PLATFORM_LPAR) 381 if (platform_is_lpar())
382 hpte_init_lpar(); 382 hpte_init_lpar();
383 else { 383 else {
384 hpte_init_native(); 384 hpte_init_native();
@@ -388,7 +388,7 @@ static void __init pSeries_init_early(void)
388 388
389 generic_find_legacy_serial_ports(&physport, &default_speed); 389 generic_find_legacy_serial_ports(&physport, &default_speed);
390 390
391 if (systemcfg->platform & PLATFORM_LPAR) 391 if (platform_is_lpar())
392 find_udbg_vterm(); 392 find_udbg_vterm();
393 else if (physport) { 393 else if (physport) {
394 /* Map the uart for udbg. */ 394 /* Map the uart for udbg. */
@@ -592,7 +592,7 @@ static void pseries_shared_idle(void)
592 592
593static int pSeries_pci_probe_mode(struct pci_bus *bus) 593static int pSeries_pci_probe_mode(struct pci_bus *bus)
594{ 594{
595 if (systemcfg->platform & PLATFORM_LPAR) 595 if (platform_is_lpar())
596 return PCI_PROBE_DEVTREE; 596 return PCI_PROBE_DEVTREE;
597 return PCI_PROBE_NORMAL; 597 return PCI_PROBE_NORMAL;
598} 598}
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 7a243e8ccd7e..3ba794ca3288 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -46,6 +46,7 @@
46#include <asm/rtas.h> 46#include <asm/rtas.h>
47#include <asm/pSeries_reconfig.h> 47#include <asm/pSeries_reconfig.h>
48#include <asm/mpic.h> 48#include <asm/mpic.h>
49#include <asm/systemcfg.h>
49 50
50#include "plpar_wrappers.h" 51#include "plpar_wrappers.h"
51 52
@@ -96,7 +97,7 @@ int pSeries_cpu_disable(void)
96 int cpu = smp_processor_id(); 97 int cpu = smp_processor_id();
97 98
98 cpu_clear(cpu, cpu_online_map); 99 cpu_clear(cpu, cpu_online_map);
99 systemcfg->processorCount--; 100 _systemcfg->processorCount--;
100 101
101 /*fix boot_cpuid here*/ 102 /*fix boot_cpuid here*/
102 if (cpu == boot_cpuid) 103 if (cpu == boot_cpuid)
@@ -441,7 +442,7 @@ void __init smp_init_pSeries(void)
441 smp_ops->cpu_die = pSeries_cpu_die; 442 smp_ops->cpu_die = pSeries_cpu_die;
442 443
443 /* Processors can be added/removed only on LPAR */ 444 /* Processors can be added/removed only on LPAR */
444 if (systemcfg->platform == PLATFORM_PSERIES_LPAR) 445 if (platform_is_lpar())
445 pSeries_reconfig_notifier_register(&pSeries_smp_nb); 446 pSeries_reconfig_notifier_register(&pSeries_smp_nb);
446#endif 447#endif
447 448
diff --git a/arch/powerpc/platforms/pseries/xics.c b/arch/powerpc/platforms/pseries/xics.c
index c72c86f05cb6..72ac18067ece 100644
--- a/arch/powerpc/platforms/pseries/xics.c
+++ b/arch/powerpc/platforms/pseries/xics.c
@@ -545,7 +545,9 @@ nextnode:
545 of_node_put(np); 545 of_node_put(np);
546 } 546 }
547 547
548 if (systemcfg->platform == PLATFORM_PSERIES) { 548 if (platform_is_lpar())
549 ops = &pSeriesLP_ops;
550 else {
549#ifdef CONFIG_SMP 551#ifdef CONFIG_SMP
550 for_each_cpu(i) { 552 for_each_cpu(i) {
551 int hard_id; 553 int hard_id;
@@ -561,12 +563,11 @@ nextnode:
561#else 563#else
562 xics_per_cpu[0] = ioremap(intr_base, intr_size); 564 xics_per_cpu[0] = ioremap(intr_base, intr_size);
563#endif /* CONFIG_SMP */ 565#endif /* CONFIG_SMP */
564 } else if (systemcfg->platform == PLATFORM_PSERIES_LPAR) {
565 ops = &pSeriesLP_ops;
566 } 566 }
567 567
568 xics_8259_pic.enable = i8259_pic.enable; 568 xics_8259_pic.enable = i8259_pic.enable;
569 xics_8259_pic.disable = i8259_pic.disable; 569 xics_8259_pic.disable = i8259_pic.disable;
570 xics_8259_pic.end = i8259_pic.end;
570 for (i = 0; i < 16; ++i) 571 for (i = 0; i < 16; ++i)
571 get_irq_desc(i)->handler = &xics_8259_pic; 572 get_irq_desc(i)->handler = &xics_8259_pic;
572 for (; i < NR_IRQS; ++i) 573 for (; i < NR_IRQS; ++i)