eeh.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. #include <linux/bootmem.h>
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/mm.h>
  23. #include <linux/notifier.h>
  24. #include <linux/pci.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/rbtree.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/spinlock.h>
  29. #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>
  35. #include "pci.h"
  36. #undef DEBUG
  37. /** Overview:
  38. * EEH, or "Extended Error Handling" is a PCI bridge technology for
  39. * dealing with PCI bus errors that can't be dealt with within the
  40. * usual PCI framework, except by check-stopping the CPU. Systems
  41. * that are designed for high-availability/reliability cannot afford
  42. * to crash due to a "mere" PCI error, thus the need for EEH.
  43. * An EEH-capable bridge operates by converting a detected error
  44. * into a "slot freeze", taking the PCI adapter off-line, making
  45. * the slot behave, from the OS'es point of view, as if the slot
  46. * were "empty": all reads return 0xff's and all writes are silently
  47. * ignored. EEH slot isolation events can be triggered by parity
  48. * errors on the address or data busses (e.g. during posted writes),
  49. * which in turn might be caused by dust, vibration, humidity,
  50. * radioactivity or plain-old failed hardware.
  51. *
  52. * Note, however, that one of the leading causes of EEH slot
  53. * freeze events are buggy device drivers, buggy device microcode,
  54. * or buggy device hardware. This is because any attempt by the
  55. * device to bus-master data to a memory address that is not
  56. * assigned to the device will trigger a slot freeze. (The idea
  57. * is to prevent devices-gone-wild from corrupting system memory).
  58. * Buggy hardware/drivers will have a miserable time co-existing
  59. * with EEH.
  60. *
  61. * Ideally, a PCI device driver, when suspecting that an isolation
  62. * event has occured (e.g. by reading 0xff's), will then ask EEH
  63. * whether this is the case, and then take appropriate steps to
  64. * reset the PCI slot, the PCI device, and then resume operations.
  65. * However, until that day, the checking is done here, with the
  66. * eeh_check_failure() routine embedded in the MMIO macros. If
  67. * the slot is found to be isolated, an "EEH Event" is synthesized
  68. * and sent out for processing.
  69. */
  70. /** Bus Unit ID macros; get low and hi 32-bits of the 64-bit BUID */
  71. #define BUID_HI(buid) ((buid) >> 32)
  72. #define BUID_LO(buid) ((buid) & 0xffffffff)
  73. /* EEH event workqueue setup. */
  74. static DEFINE_SPINLOCK(eeh_eventlist_lock);
  75. LIST_HEAD(eeh_eventlist);
  76. static void eeh_event_handler(void *);
  77. DECLARE_WORK(eeh_event_wq, eeh_event_handler, NULL);
  78. static struct notifier_block *eeh_notifier_chain;
  79. /*
  80. * If a device driver keeps reading an MMIO register in an interrupt
  81. * handler after a slot isolation event has occurred, we assume it
  82. * is broken and panic. This sets the threshold for how many read
  83. * attempts we allow before panicking.
  84. */
  85. #define EEH_MAX_FAILS 1000
  86. static atomic_t eeh_fail_count;
  87. /* RTAS tokens */
  88. static int ibm_set_eeh_option;
  89. static int ibm_set_slot_reset;
  90. static int ibm_read_slot_reset_state;
  91. static int ibm_read_slot_reset_state2;
  92. static int ibm_slot_error_detail;
  93. static int eeh_subsystem_enabled;
  94. /* Buffer for reporting slot-error-detail rtas calls */
  95. static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
  96. static DEFINE_SPINLOCK(slot_errbuf_lock);
  97. static int eeh_error_buf_size;
  98. /* System monitoring statistics */
  99. static DEFINE_PER_CPU(unsigned long, total_mmio_ffs);
  100. static DEFINE_PER_CPU(unsigned long, false_positives);
  101. static DEFINE_PER_CPU(unsigned long, ignored_failures);
  102. static DEFINE_PER_CPU(unsigned long, slot_resets);
  103. /**
  104. * The pci address cache subsystem. This subsystem places
  105. * PCI device address resources into a red-black tree, sorted
  106. * according to the address range, so that given only an i/o
  107. * address, the corresponding PCI device can be **quickly**
  108. * found. It is safe to perform an address lookup in an interrupt
  109. * context; this ability is an important feature.
  110. *
  111. * Currently, the only customer of this code is the EEH subsystem;
  112. * thus, this code has been somewhat tailored to suit EEH better.
  113. * In particular, the cache does *not* hold the addresses of devices
  114. * for which EEH is not enabled.
  115. *
  116. * (Implementation Note: The RB tree seems to be better/faster
  117. * than any hash algo I could think of for this problem, even
  118. * with the penalty of slow pointer chases for d-cache misses).
  119. */
  120. struct pci_io_addr_range
  121. {
  122. struct rb_node rb_node;
  123. unsigned long addr_lo;
  124. unsigned long addr_hi;
  125. struct pci_dev *pcidev;
  126. unsigned int flags;
  127. };
  128. static struct pci_io_addr_cache
  129. {
  130. struct rb_root rb_root;
  131. spinlock_t piar_lock;
  132. } pci_io_addr_cache_root;
  133. static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)
  134. {
  135. struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
  136. while (n) {
  137. struct pci_io_addr_range *piar;
  138. piar = rb_entry(n, struct pci_io_addr_range, rb_node);
  139. if (addr < piar->addr_lo) {
  140. n = n->rb_left;
  141. } else {
  142. if (addr > piar->addr_hi) {
  143. n = n->rb_right;
  144. } else {
  145. pci_dev_get(piar->pcidev);
  146. return piar->pcidev;
  147. }
  148. }
  149. }
  150. return NULL;
  151. }
  152. /**
  153. * pci_get_device_by_addr - Get device, given only address
  154. * @addr: mmio (PIO) phys address or i/o port number
  155. *
  156. * Given an mmio phys address, or a port number, find a pci device
  157. * that implements this address. Be sure to pci_dev_put the device
  158. * when finished. I/O port numbers are assumed to be offset
  159. * from zero (that is, they do *not* have pci_io_addr added in).
  160. * It is safe to call this function within an interrupt.
  161. */
  162. static struct pci_dev *pci_get_device_by_addr(unsigned long addr)
  163. {
  164. struct pci_dev *dev;
  165. unsigned long flags;
  166. spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
  167. dev = __pci_get_device_by_addr(addr);
  168. spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
  169. return dev;
  170. }
  171. #ifdef DEBUG
  172. /*
  173. * Handy-dandy debug print routine, does nothing more
  174. * than print out the contents of our addr cache.
  175. */
  176. static void pci_addr_cache_print(struct pci_io_addr_cache *cache)
  177. {
  178. struct rb_node *n;
  179. int cnt = 0;
  180. n = rb_first(&cache->rb_root);
  181. while (n) {
  182. struct pci_io_addr_range *piar;
  183. piar = rb_entry(n, struct pci_io_addr_range, rb_node);
  184. printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",
  185. (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
  186. piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));
  187. cnt++;
  188. n = rb_next(n);
  189. }
  190. }
  191. #endif
  192. /* Insert address range into the rb tree. */
  193. static struct pci_io_addr_range *
  194. pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,
  195. unsigned long ahi, unsigned int flags)
  196. {
  197. struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
  198. struct rb_node *parent = NULL;
  199. struct pci_io_addr_range *piar;
  200. /* Walk tree, find a place to insert into tree */
  201. while (*p) {
  202. parent = *p;
  203. piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
  204. if (alo < piar->addr_lo) {
  205. p = &parent->rb_left;
  206. } else if (ahi > piar->addr_hi) {
  207. p = &parent->rb_right;
  208. } else {
  209. if (dev != piar->pcidev ||
  210. alo != piar->addr_lo || ahi != piar->addr_hi) {
  211. printk(KERN_WARNING "PIAR: overlapping address range\n");
  212. }
  213. return piar;
  214. }
  215. }
  216. piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
  217. if (!piar)
  218. return NULL;
  219. piar->addr_lo = alo;
  220. piar->addr_hi = ahi;
  221. piar->pcidev = dev;
  222. piar->flags = flags;
  223. rb_link_node(&piar->rb_node, parent, p);
  224. rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
  225. return piar;
  226. }
  227. static void __pci_addr_cache_insert_device(struct pci_dev *dev)
  228. {
  229. struct device_node *dn;
  230. int i;
  231. int inserted = 0;
  232. dn = pci_device_to_OF_node(dev);
  233. if (!dn) {
  234. printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n",
  235. pci_name(dev));
  236. return;
  237. }
  238. /* Skip any devices for which EEH is not enabled. */
  239. if (!(dn->eeh_mode & EEH_MODE_SUPPORTED) ||
  240. dn->eeh_mode & EEH_MODE_NOCHECK) {
  241. #ifdef DEBUG
  242. printk(KERN_INFO "PCI: skip building address cache for=%s\n",
  243. pci_name(dev));
  244. #endif
  245. return;
  246. }
  247. /* The cache holds a reference to the device... */
  248. pci_dev_get(dev);
  249. /* Walk resources on this device, poke them into the tree */
  250. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  251. unsigned long start = pci_resource_start(dev,i);
  252. unsigned long end = pci_resource_end(dev,i);
  253. unsigned int flags = pci_resource_flags(dev,i);
  254. /* We are interested only bus addresses, not dma or other stuff */
  255. if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
  256. continue;
  257. if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
  258. continue;
  259. pci_addr_cache_insert(dev, start, end, flags);
  260. inserted = 1;
  261. }
  262. /* If there was nothing to add, the cache has no reference... */
  263. if (!inserted)
  264. pci_dev_put(dev);
  265. }
  266. /**
  267. * pci_addr_cache_insert_device - Add a device to the address cache
  268. * @dev: PCI device whose I/O addresses we are interested in.
  269. *
  270. * In order to support the fast lookup of devices based on addresses,
  271. * we maintain a cache of devices that can be quickly searched.
  272. * This routine adds a device to that cache.
  273. */
  274. void pci_addr_cache_insert_device(struct pci_dev *dev)
  275. {
  276. unsigned long flags;
  277. spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
  278. __pci_addr_cache_insert_device(dev);
  279. spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
  280. }
  281. static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
  282. {
  283. struct rb_node *n;
  284. int removed = 0;
  285. restart:
  286. n = rb_first(&pci_io_addr_cache_root.rb_root);
  287. while (n) {
  288. struct pci_io_addr_range *piar;
  289. piar = rb_entry(n, struct pci_io_addr_range, rb_node);
  290. if (piar->pcidev == dev) {
  291. rb_erase(n, &pci_io_addr_cache_root.rb_root);
  292. removed = 1;
  293. kfree(piar);
  294. goto restart;
  295. }
  296. n = rb_next(n);
  297. }
  298. /* The cache no longer holds its reference to this device... */
  299. if (removed)
  300. pci_dev_put(dev);
  301. }
  302. /**
  303. * pci_addr_cache_remove_device - remove pci device from addr cache
  304. * @dev: device to remove
  305. *
  306. * Remove a device from the addr-cache tree.
  307. * This is potentially expensive, since it will walk
  308. * the tree multiple times (once per resource).
  309. * But so what; device removal doesn't need to be that fast.
  310. */
  311. void pci_addr_cache_remove_device(struct pci_dev *dev)
  312. {
  313. unsigned long flags;
  314. spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
  315. __pci_addr_cache_remove_device(dev);
  316. spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
  317. }
  318. /**
  319. * pci_addr_cache_build - Build a cache of I/O addresses
  320. *
  321. * Build a cache of pci i/o addresses. This cache will be used to
  322. * find the pci device that corresponds to a given address.
  323. * This routine scans all pci busses to build the cache.
  324. * Must be run late in boot process, after the pci controllers
  325. * have been scaned for devices (after all device resources are known).
  326. */
  327. void __init pci_addr_cache_build(void)
  328. {
  329. struct pci_dev *dev = NULL;
  330. spin_lock_init(&pci_io_addr_cache_root.piar_lock);
  331. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  332. /* Ignore PCI bridges ( XXX why ??) */
  333. if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
  334. continue;
  335. }
  336. pci_addr_cache_insert_device(dev);
  337. }
  338. #ifdef DEBUG
  339. /* Verify tree built up above, echo back the list of addrs. */
  340. pci_addr_cache_print(&pci_io_addr_cache_root);
  341. #endif
  342. }
  343. /* --------------------------------------------------------------- */
  344. /* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
  345. /**
  346. * eeh_register_notifier - Register to find out about EEH events.
  347. * @nb: notifier block to callback on events
  348. */
  349. int eeh_register_notifier(struct notifier_block *nb)
  350. {
  351. return notifier_chain_register(&eeh_notifier_chain, nb);
  352. }
  353. /**
  354. * eeh_unregister_notifier - Unregister to an EEH event notifier.
  355. * @nb: notifier block to callback on events
  356. */
  357. int eeh_unregister_notifier(struct notifier_block *nb)
  358. {
  359. return notifier_chain_unregister(&eeh_notifier_chain, nb);
  360. }
  361. /**
  362. * read_slot_reset_state - Read the reset state of a device node's slot
  363. * @dn: device node to read
  364. * @rets: array to return results in
  365. */
  366. static int read_slot_reset_state(struct device_node *dn, int rets[])
  367. {
  368. int token, outputs;
  369. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  370. token = ibm_read_slot_reset_state2;
  371. outputs = 4;
  372. } else {
  373. token = ibm_read_slot_reset_state;
  374. outputs = 3;
  375. }
  376. return rtas_call(token, 3, outputs, rets, dn->eeh_config_addr,
  377. BUID_HI(dn->phb->buid), BUID_LO(dn->phb->buid));
  378. }
  379. /**
  380. * eeh_panic - call panic() for an eeh event that cannot be handled.
  381. * The philosophy of this routine is that it is better to panic and
  382. * halt the OS than it is to risk possible data corruption by
  383. * oblivious device drivers that don't know better.
  384. *
  385. * @dev pci device that had an eeh event
  386. * @reset_state current reset state of the device slot
  387. */
  388. static void eeh_panic(struct pci_dev *dev, int reset_state)
  389. {
  390. /*
  391. * XXX We should create a separate sysctl for this.
  392. *
  393. * Since the panic_on_oops sysctl is used to halt the system
  394. * in light of potential corruption, we can use it here.
  395. */
  396. if (panic_on_oops)
  397. panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
  398. pci_name(dev));
  399. else {
  400. __get_cpu_var(ignored_failures)++;
  401. printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
  402. reset_state, pci_name(dev));
  403. }
  404. }
  405. /**
  406. * eeh_event_handler - dispatch EEH events. The detection of a frozen
  407. * slot can occur inside an interrupt, where it can be hard to do
  408. * anything about it. The goal of this routine is to pull these
  409. * detection events out of the context of the interrupt handler, and
  410. * re-dispatch them for processing at a later time in a normal context.
  411. *
  412. * @dummy - unused
  413. */
  414. static void eeh_event_handler(void *dummy)
  415. {
  416. unsigned long flags;
  417. struct eeh_event *event;
  418. while (1) {
  419. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  420. event = NULL;
  421. if (!list_empty(&eeh_eventlist)) {
  422. event = list_entry(eeh_eventlist.next, struct eeh_event, list);
  423. list_del(&event->list);
  424. }
  425. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  426. if (event == NULL)
  427. break;
  428. printk(KERN_INFO "EEH: MMIO failure (%d), notifiying device "
  429. "%s\n", event->reset_state,
  430. pci_name(event->dev));
  431. atomic_set(&eeh_fail_count, 0);
  432. notifier_call_chain (&eeh_notifier_chain,
  433. EEH_NOTIFY_FREEZE, event);
  434. __get_cpu_var(slot_resets)++;
  435. pci_dev_put(event->dev);
  436. kfree(event);
  437. }
  438. }
  439. /**
  440. * eeh_token_to_phys - convert EEH address token to phys address
  441. * @token i/o token, should be address in the form 0xE....
  442. */
  443. static inline unsigned long eeh_token_to_phys(unsigned long token)
  444. {
  445. pte_t *ptep;
  446. unsigned long pa;
  447. ptep = find_linux_pte(init_mm.pgd, token);
  448. if (!ptep)
  449. return token;
  450. pa = pte_pfn(*ptep) << PAGE_SHIFT;
  451. return pa | (token & (PAGE_SIZE-1));
  452. }
  453. /**
  454. * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
  455. * @dn device node
  456. * @dev pci device, if known
  457. *
  458. * Check for an EEH failure for the given device node. Call this
  459. * routine if the result of a read was all 0xff's and you want to
  460. * find out if this is due to an EEH slot freeze. This routine
  461. * will query firmware for the EEH status.
  462. *
  463. * Returns 0 if there has not been an EEH error; otherwise returns
  464. * a non-zero value and queues up a solt isolation event notification.
  465. *
  466. * It is safe to call this routine in an interrupt context.
  467. */
  468. int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
  469. {
  470. int ret;
  471. int rets[3];
  472. unsigned long flags;
  473. int rc, reset_state;
  474. struct eeh_event *event;
  475. __get_cpu_var(total_mmio_ffs)++;
  476. if (!eeh_subsystem_enabled)
  477. return 0;
  478. if (!dn)
  479. return 0;
  480. /* Access to IO BARs might get this far and still not want checking. */
  481. if (!(dn->eeh_mode & EEH_MODE_SUPPORTED) ||
  482. dn->eeh_mode & EEH_MODE_NOCHECK) {
  483. return 0;
  484. }
  485. if (!dn->eeh_config_addr) {
  486. return 0;
  487. }
  488. /*
  489. * If we already have a pending isolation event for this
  490. * slot, we know it's bad already, we don't need to check...
  491. */
  492. if (dn->eeh_mode & EEH_MODE_ISOLATED) {
  493. atomic_inc(&eeh_fail_count);
  494. if (atomic_read(&eeh_fail_count) >= EEH_MAX_FAILS) {
  495. /* re-read the slot reset state */
  496. if (read_slot_reset_state(dn, rets) != 0)
  497. rets[0] = -1; /* reset state unknown */
  498. eeh_panic(dev, rets[0]);
  499. }
  500. return 0;
  501. }
  502. /*
  503. * Now test for an EEH failure. This is VERY expensive.
  504. * Note that the eeh_config_addr may be a parent device
  505. * in the case of a device behind a bridge, or it may be
  506. * function zero of a multi-function device.
  507. * In any case they must share a common PHB.
  508. */
  509. ret = read_slot_reset_state(dn, rets);
  510. if (!(ret == 0 && rets[1] == 1 && (rets[0] == 2 || rets[0] == 4))) {
  511. __get_cpu_var(false_positives)++;
  512. return 0;
  513. }
  514. /* prevent repeated reports of this failure */
  515. dn->eeh_mode |= EEH_MODE_ISOLATED;
  516. reset_state = rets[0];
  517. spin_lock_irqsave(&slot_errbuf_lock, flags);
  518. memset(slot_errbuf, 0, eeh_error_buf_size);
  519. rc = rtas_call(ibm_slot_error_detail,
  520. 8, 1, NULL, dn->eeh_config_addr,
  521. BUID_HI(dn->phb->buid),
  522. BUID_LO(dn->phb->buid), NULL, 0,
  523. virt_to_phys(slot_errbuf),
  524. eeh_error_buf_size,
  525. 1 /* Temporary Error */);
  526. if (rc == 0)
  527. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  528. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  529. printk(KERN_INFO "EEH: MMIO failure (%d) on device: %s %s\n",
  530. rets[0], dn->name, dn->full_name);
  531. event = kmalloc(sizeof(*event), GFP_ATOMIC);
  532. if (event == NULL) {
  533. eeh_panic(dev, reset_state);
  534. return 1;
  535. }
  536. event->dev = dev;
  537. event->dn = dn;
  538. event->reset_state = reset_state;
  539. /* We may or may not be called in an interrupt context */
  540. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  541. list_add(&event->list, &eeh_eventlist);
  542. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  543. /* Most EEH events are due to device driver bugs. Having
  544. * a stack trace will help the device-driver authors figure
  545. * out what happened. So print that out. */
  546. dump_stack();
  547. schedule_work(&eeh_event_wq);
  548. return 0;
  549. }
  550. EXPORT_SYMBOL(eeh_dn_check_failure);
  551. /**
  552. * eeh_check_failure - check if all 1's data is due to EEH slot freeze
  553. * @token i/o token, should be address in the form 0xA....
  554. * @val value, should be all 1's (XXX why do we need this arg??)
  555. *
  556. * Check for an eeh failure at the given token address.
  557. * Check for an EEH failure at the given token address. Call this
  558. * routine if the result of a read was all 0xff's and you want to
  559. * find out if this is due to an EEH slot freeze event. This routine
  560. * will query firmware for the EEH status.
  561. *
  562. * Note this routine is safe to call in an interrupt context.
  563. */
  564. unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
  565. {
  566. unsigned long addr;
  567. struct pci_dev *dev;
  568. struct device_node *dn;
  569. /* Finding the phys addr + pci device; this is pretty quick. */
  570. addr = eeh_token_to_phys((unsigned long __force) token);
  571. dev = pci_get_device_by_addr(addr);
  572. if (!dev)
  573. return val;
  574. dn = pci_device_to_OF_node(dev);
  575. eeh_dn_check_failure (dn, dev);
  576. pci_dev_put(dev);
  577. return val;
  578. }
  579. EXPORT_SYMBOL(eeh_check_failure);
  580. struct eeh_early_enable_info {
  581. unsigned int buid_hi;
  582. unsigned int buid_lo;
  583. };
  584. /* Enable eeh for the given device node. */
  585. static void *early_enable_eeh(struct device_node *dn, void *data)
  586. {
  587. struct eeh_early_enable_info *info = data;
  588. int ret;
  589. char *status = get_property(dn, "status", NULL);
  590. u32 *class_code = (u32 *)get_property(dn, "class-code", NULL);
  591. u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL);
  592. u32 *device_id = (u32 *)get_property(dn, "device-id", NULL);
  593. u32 *regs;
  594. int enable;
  595. dn->eeh_mode = 0;
  596. if (status && strcmp(status, "ok") != 0)
  597. return NULL; /* ignore devices with bad status */
  598. /* Ignore bad nodes. */
  599. if (!class_code || !vendor_id || !device_id)
  600. return NULL;
  601. /* There is nothing to check on PCI to ISA bridges */
  602. if (dn->type && !strcmp(dn->type, "isa")) {
  603. dn->eeh_mode |= EEH_MODE_NOCHECK;
  604. return NULL;
  605. }
  606. /*
  607. * Now decide if we are going to "Disable" EEH checking
  608. * for this device. We still run with the EEH hardware active,
  609. * but we won't be checking for ff's. This means a driver
  610. * could return bad data (very bad!), an interrupt handler could
  611. * hang waiting on status bits that won't change, etc.
  612. * But there are a few cases like display devices that make sense.
  613. */
  614. enable = 1; /* i.e. we will do checking */
  615. if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
  616. enable = 0;
  617. if (!enable)
  618. dn->eeh_mode |= EEH_MODE_NOCHECK;
  619. /* Ok... see if this device supports EEH. Some do, some don't,
  620. * and the only way to find out is to check each and every one. */
  621. regs = (u32 *)get_property(dn, "reg", NULL);
  622. if (regs) {
  623. /* First register entry is addr (00BBSS00) */
  624. /* Try to enable eeh */
  625. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  626. regs[0], info->buid_hi, info->buid_lo,
  627. EEH_ENABLE);
  628. if (ret == 0) {
  629. eeh_subsystem_enabled = 1;
  630. dn->eeh_mode |= EEH_MODE_SUPPORTED;
  631. dn->eeh_config_addr = regs[0];
  632. #ifdef DEBUG
  633. printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);
  634. #endif
  635. } else {
  636. /* This device doesn't support EEH, but it may have an
  637. * EEH parent, in which case we mark it as supported. */
  638. if (dn->parent && (dn->parent->eeh_mode & EEH_MODE_SUPPORTED)) {
  639. /* Parent supports EEH. */
  640. dn->eeh_mode |= EEH_MODE_SUPPORTED;
  641. dn->eeh_config_addr = dn->parent->eeh_config_addr;
  642. return NULL;
  643. }
  644. }
  645. } else {
  646. printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
  647. dn->full_name);
  648. }
  649. return NULL;
  650. }
  651. /*
  652. * Initialize EEH by trying to enable it for all of the adapters in the system.
  653. * As a side effect we can determine here if eeh is supported at all.
  654. * Note that we leave EEH on so failed config cycles won't cause a machine
  655. * check. If a user turns off EEH for a particular adapter they are really
  656. * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
  657. * grant access to a slot if EEH isn't enabled, and so we always enable
  658. * EEH for all slots/all devices.
  659. *
  660. * The eeh-force-off option disables EEH checking globally, for all slots.
  661. * Even if force-off is set, the EEH hardware is still enabled, so that
  662. * newer systems can boot.
  663. */
  664. void __init eeh_init(void)
  665. {
  666. struct device_node *phb, *np;
  667. struct eeh_early_enable_info info;
  668. np = of_find_node_by_path("/rtas");
  669. if (np == NULL)
  670. return;
  671. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  672. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  673. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  674. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  675. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  676. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
  677. return;
  678. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  679. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  680. eeh_error_buf_size = 1024;
  681. }
  682. if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  683. printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
  684. "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  685. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  686. }
  687. /* Enable EEH for all adapters. Note that eeh requires buid's */
  688. for (phb = of_find_node_by_name(NULL, "pci"); phb;
  689. phb = of_find_node_by_name(phb, "pci")) {
  690. unsigned long buid;
  691. buid = get_phb_buid(phb);
  692. if (buid == 0)
  693. continue;
  694. info.buid_lo = BUID_LO(buid);
  695. info.buid_hi = BUID_HI(buid);
  696. traverse_pci_devices(phb, early_enable_eeh, &info);
  697. }
  698. if (eeh_subsystem_enabled)
  699. printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
  700. else
  701. printk(KERN_WARNING "EEH: No capable adapters found\n");
  702. }
  703. /**
  704. * eeh_add_device_early - enable EEH for the indicated device_node
  705. * @dn: device node for which to set up EEH
  706. *
  707. * This routine must be used to perform EEH initialization for PCI
  708. * devices that were added after system boot (e.g. hotplug, dlpar).
  709. * This routine must be called before any i/o is performed to the
  710. * adapter (inluding any config-space i/o).
  711. * Whether this actually enables EEH or not for this device depends
  712. * on the CEC architecture, type of the device, on earlier boot
  713. * command-line arguments & etc.
  714. */
  715. void eeh_add_device_early(struct device_node *dn)
  716. {
  717. struct pci_controller *phb;
  718. struct eeh_early_enable_info info;
  719. if (!dn)
  720. return;
  721. phb = dn->phb;
  722. if (NULL == phb || 0 == phb->buid) {
  723. printk(KERN_WARNING "EEH: Expected buid but found none\n");
  724. return;
  725. }
  726. info.buid_hi = BUID_HI(phb->buid);
  727. info.buid_lo = BUID_LO(phb->buid);
  728. early_enable_eeh(dn, &info);
  729. }
  730. EXPORT_SYMBOL(eeh_add_device_early);
  731. /**
  732. * eeh_add_device_late - perform EEH initialization for the indicated pci device
  733. * @dev: pci device for which to set up EEH
  734. *
  735. * This routine must be used to complete EEH initialization for PCI
  736. * devices that were added after system boot (e.g. hotplug, dlpar).
  737. */
  738. void eeh_add_device_late(struct pci_dev *dev)
  739. {
  740. if (!dev || !eeh_subsystem_enabled)
  741. return;
  742. #ifdef DEBUG
  743. printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev));
  744. #endif
  745. pci_addr_cache_insert_device (dev);
  746. }
  747. EXPORT_SYMBOL(eeh_add_device_late);
  748. /**
  749. * eeh_remove_device - undo EEH setup for the indicated pci device
  750. * @dev: pci device to be removed
  751. *
  752. * This routine should be when a device is removed from a running
  753. * system (e.g. by hotplug or dlpar).
  754. */
  755. void eeh_remove_device(struct pci_dev *dev)
  756. {
  757. if (!dev || !eeh_subsystem_enabled)
  758. return;
  759. /* Unregister the device with the EEH/PCI address search system */
  760. #ifdef DEBUG
  761. printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev));
  762. #endif
  763. pci_addr_cache_remove_device(dev);
  764. }
  765. EXPORT_SYMBOL(eeh_remove_device);
  766. static int proc_eeh_show(struct seq_file *m, void *v)
  767. {
  768. unsigned int cpu;
  769. unsigned long ffs = 0, positives = 0, failures = 0;
  770. unsigned long resets = 0;
  771. for_each_cpu(cpu) {
  772. ffs += per_cpu(total_mmio_ffs, cpu);
  773. positives += per_cpu(false_positives, cpu);
  774. failures += per_cpu(ignored_failures, cpu);
  775. resets += per_cpu(slot_resets, cpu);
  776. }
  777. if (0 == eeh_subsystem_enabled) {
  778. seq_printf(m, "EEH Subsystem is globally disabled\n");
  779. seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);
  780. } else {
  781. seq_printf(m, "EEH Subsystem is enabled\n");
  782. seq_printf(m, "eeh_total_mmio_ffs=%ld\n"
  783. "eeh_false_positives=%ld\n"
  784. "eeh_ignored_failures=%ld\n"
  785. "eeh_slot_resets=%ld\n"
  786. "eeh_fail_count=%d\n",
  787. ffs, positives, failures, resets,
  788. eeh_fail_count.counter);
  789. }
  790. return 0;
  791. }
  792. static int proc_eeh_open(struct inode *inode, struct file *file)
  793. {
  794. return single_open(file, proc_eeh_show, NULL);
  795. }
  796. static struct file_operations proc_eeh_operations = {
  797. .open = proc_eeh_open,
  798. .read = seq_read,
  799. .llseek = seq_lseek,
  800. .release = single_release,
  801. };
  802. static int __init eeh_init_proc(void)
  803. {
  804. struct proc_dir_entry *e;
  805. if (systemcfg->platform & PLATFORM_PSERIES) {
  806. e = create_proc_entry("ppc64/eeh", 0, NULL);
  807. if (e)
  808. e->proc_fops = &proc_eeh_operations;
  809. }
  810. return 0;
  811. }
  812. __initcall(eeh_init_proc);