eeh.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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. struct pci_dn *pdn;
  231. int i;
  232. int inserted = 0;
  233. dn = pci_device_to_OF_node(dev);
  234. if (!dn) {
  235. printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n",
  236. pci_name(dev));
  237. return;
  238. }
  239. /* Skip any devices for which EEH is not enabled. */
  240. pdn = dn->data;
  241. if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
  242. pdn->eeh_mode & EEH_MODE_NOCHECK) {
  243. #ifdef DEBUG
  244. printk(KERN_INFO "PCI: skip building address cache for=%s\n",
  245. pci_name(dev));
  246. #endif
  247. return;
  248. }
  249. /* The cache holds a reference to the device... */
  250. pci_dev_get(dev);
  251. /* Walk resources on this device, poke them into the tree */
  252. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  253. unsigned long start = pci_resource_start(dev,i);
  254. unsigned long end = pci_resource_end(dev,i);
  255. unsigned int flags = pci_resource_flags(dev,i);
  256. /* We are interested only bus addresses, not dma or other stuff */
  257. if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
  258. continue;
  259. if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
  260. continue;
  261. pci_addr_cache_insert(dev, start, end, flags);
  262. inserted = 1;
  263. }
  264. /* If there was nothing to add, the cache has no reference... */
  265. if (!inserted)
  266. pci_dev_put(dev);
  267. }
  268. /**
  269. * pci_addr_cache_insert_device - Add a device to the address cache
  270. * @dev: PCI device whose I/O addresses we are interested in.
  271. *
  272. * In order to support the fast lookup of devices based on addresses,
  273. * we maintain a cache of devices that can be quickly searched.
  274. * This routine adds a device to that cache.
  275. */
  276. void pci_addr_cache_insert_device(struct pci_dev *dev)
  277. {
  278. unsigned long flags;
  279. spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
  280. __pci_addr_cache_insert_device(dev);
  281. spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
  282. }
  283. static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
  284. {
  285. struct rb_node *n;
  286. int removed = 0;
  287. restart:
  288. n = rb_first(&pci_io_addr_cache_root.rb_root);
  289. while (n) {
  290. struct pci_io_addr_range *piar;
  291. piar = rb_entry(n, struct pci_io_addr_range, rb_node);
  292. if (piar->pcidev == dev) {
  293. rb_erase(n, &pci_io_addr_cache_root.rb_root);
  294. removed = 1;
  295. kfree(piar);
  296. goto restart;
  297. }
  298. n = rb_next(n);
  299. }
  300. /* The cache no longer holds its reference to this device... */
  301. if (removed)
  302. pci_dev_put(dev);
  303. }
  304. /**
  305. * pci_addr_cache_remove_device - remove pci device from addr cache
  306. * @dev: device to remove
  307. *
  308. * Remove a device from the addr-cache tree.
  309. * This is potentially expensive, since it will walk
  310. * the tree multiple times (once per resource).
  311. * But so what; device removal doesn't need to be that fast.
  312. */
  313. void pci_addr_cache_remove_device(struct pci_dev *dev)
  314. {
  315. unsigned long flags;
  316. spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
  317. __pci_addr_cache_remove_device(dev);
  318. spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
  319. }
  320. /**
  321. * pci_addr_cache_build - Build a cache of I/O addresses
  322. *
  323. * Build a cache of pci i/o addresses. This cache will be used to
  324. * find the pci device that corresponds to a given address.
  325. * This routine scans all pci busses to build the cache.
  326. * Must be run late in boot process, after the pci controllers
  327. * have been scaned for devices (after all device resources are known).
  328. */
  329. void __init pci_addr_cache_build(void)
  330. {
  331. struct pci_dev *dev = NULL;
  332. spin_lock_init(&pci_io_addr_cache_root.piar_lock);
  333. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  334. /* Ignore PCI bridges ( XXX why ??) */
  335. if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
  336. continue;
  337. }
  338. pci_addr_cache_insert_device(dev);
  339. }
  340. #ifdef DEBUG
  341. /* Verify tree built up above, echo back the list of addrs. */
  342. pci_addr_cache_print(&pci_io_addr_cache_root);
  343. #endif
  344. }
  345. /* --------------------------------------------------------------- */
  346. /* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
  347. /**
  348. * eeh_register_notifier - Register to find out about EEH events.
  349. * @nb: notifier block to callback on events
  350. */
  351. int eeh_register_notifier(struct notifier_block *nb)
  352. {
  353. return notifier_chain_register(&eeh_notifier_chain, nb);
  354. }
  355. /**
  356. * eeh_unregister_notifier - Unregister to an EEH event notifier.
  357. * @nb: notifier block to callback on events
  358. */
  359. int eeh_unregister_notifier(struct notifier_block *nb)
  360. {
  361. return notifier_chain_unregister(&eeh_notifier_chain, nb);
  362. }
  363. /**
  364. * read_slot_reset_state - Read the reset state of a device node's slot
  365. * @dn: device node to read
  366. * @rets: array to return results in
  367. */
  368. static int read_slot_reset_state(struct device_node *dn, int rets[])
  369. {
  370. int token, outputs;
  371. struct pci_dn *pdn = dn->data;
  372. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  373. token = ibm_read_slot_reset_state2;
  374. outputs = 4;
  375. } else {
  376. token = ibm_read_slot_reset_state;
  377. outputs = 3;
  378. }
  379. return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr,
  380. BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
  381. }
  382. /**
  383. * eeh_panic - call panic() for an eeh event that cannot be handled.
  384. * The philosophy of this routine is that it is better to panic and
  385. * halt the OS than it is to risk possible data corruption by
  386. * oblivious device drivers that don't know better.
  387. *
  388. * @dev pci device that had an eeh event
  389. * @reset_state current reset state of the device slot
  390. */
  391. static void eeh_panic(struct pci_dev *dev, int reset_state)
  392. {
  393. /*
  394. * XXX We should create a separate sysctl for this.
  395. *
  396. * Since the panic_on_oops sysctl is used to halt the system
  397. * in light of potential corruption, we can use it here.
  398. */
  399. if (panic_on_oops)
  400. panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
  401. pci_name(dev));
  402. else {
  403. __get_cpu_var(ignored_failures)++;
  404. printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
  405. reset_state, pci_name(dev));
  406. }
  407. }
  408. /**
  409. * eeh_event_handler - dispatch EEH events. The detection of a frozen
  410. * slot can occur inside an interrupt, where it can be hard to do
  411. * anything about it. The goal of this routine is to pull these
  412. * detection events out of the context of the interrupt handler, and
  413. * re-dispatch them for processing at a later time in a normal context.
  414. *
  415. * @dummy - unused
  416. */
  417. static void eeh_event_handler(void *dummy)
  418. {
  419. unsigned long flags;
  420. struct eeh_event *event;
  421. while (1) {
  422. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  423. event = NULL;
  424. if (!list_empty(&eeh_eventlist)) {
  425. event = list_entry(eeh_eventlist.next, struct eeh_event, list);
  426. list_del(&event->list);
  427. }
  428. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  429. if (event == NULL)
  430. break;
  431. printk(KERN_INFO "EEH: MMIO failure (%d), notifiying device "
  432. "%s\n", event->reset_state,
  433. pci_name(event->dev));
  434. atomic_set(&eeh_fail_count, 0);
  435. notifier_call_chain (&eeh_notifier_chain,
  436. EEH_NOTIFY_FREEZE, event);
  437. __get_cpu_var(slot_resets)++;
  438. pci_dev_put(event->dev);
  439. kfree(event);
  440. }
  441. }
  442. /**
  443. * eeh_token_to_phys - convert EEH address token to phys address
  444. * @token i/o token, should be address in the form 0xE....
  445. */
  446. static inline unsigned long eeh_token_to_phys(unsigned long token)
  447. {
  448. pte_t *ptep;
  449. unsigned long pa;
  450. ptep = find_linux_pte(init_mm.pgd, token);
  451. if (!ptep)
  452. return token;
  453. pa = pte_pfn(*ptep) << PAGE_SHIFT;
  454. return pa | (token & (PAGE_SIZE-1));
  455. }
  456. /**
  457. * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
  458. * @dn device node
  459. * @dev pci device, if known
  460. *
  461. * Check for an EEH failure for the given device node. Call this
  462. * routine if the result of a read was all 0xff's and you want to
  463. * find out if this is due to an EEH slot freeze. This routine
  464. * will query firmware for the EEH status.
  465. *
  466. * Returns 0 if there has not been an EEH error; otherwise returns
  467. * a non-zero value and queues up a solt isolation event notification.
  468. *
  469. * It is safe to call this routine in an interrupt context.
  470. */
  471. int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
  472. {
  473. int ret;
  474. int rets[3];
  475. unsigned long flags;
  476. int rc, reset_state;
  477. struct eeh_event *event;
  478. struct pci_dn *pdn;
  479. __get_cpu_var(total_mmio_ffs)++;
  480. if (!eeh_subsystem_enabled)
  481. return 0;
  482. if (!dn)
  483. return 0;
  484. pdn = dn->data;
  485. /* Access to IO BARs might get this far and still not want checking. */
  486. if (!pdn->eeh_capable || !(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
  487. pdn->eeh_mode & EEH_MODE_NOCHECK) {
  488. return 0;
  489. }
  490. if (!pdn->eeh_config_addr) {
  491. return 0;
  492. }
  493. /*
  494. * If we already have a pending isolation event for this
  495. * slot, we know it's bad already, we don't need to check...
  496. */
  497. if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
  498. atomic_inc(&eeh_fail_count);
  499. if (atomic_read(&eeh_fail_count) >= EEH_MAX_FAILS) {
  500. /* re-read the slot reset state */
  501. if (read_slot_reset_state(dn, rets) != 0)
  502. rets[0] = -1; /* reset state unknown */
  503. eeh_panic(dev, rets[0]);
  504. }
  505. return 0;
  506. }
  507. /*
  508. * Now test for an EEH failure. This is VERY expensive.
  509. * Note that the eeh_config_addr may be a parent device
  510. * in the case of a device behind a bridge, or it may be
  511. * function zero of a multi-function device.
  512. * In any case they must share a common PHB.
  513. */
  514. ret = read_slot_reset_state(dn, rets);
  515. if (!(ret == 0 && rets[1] == 1 && (rets[0] == 2 || rets[0] == 4))) {
  516. __get_cpu_var(false_positives)++;
  517. return 0;
  518. }
  519. /* prevent repeated reports of this failure */
  520. pdn->eeh_mode |= EEH_MODE_ISOLATED;
  521. reset_state = rets[0];
  522. spin_lock_irqsave(&slot_errbuf_lock, flags);
  523. memset(slot_errbuf, 0, eeh_error_buf_size);
  524. rc = rtas_call(ibm_slot_error_detail,
  525. 8, 1, NULL, pdn->eeh_config_addr,
  526. BUID_HI(pdn->phb->buid),
  527. BUID_LO(pdn->phb->buid), NULL, 0,
  528. virt_to_phys(slot_errbuf),
  529. eeh_error_buf_size,
  530. 1 /* Temporary Error */);
  531. if (rc == 0)
  532. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  533. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  534. printk(KERN_INFO "EEH: MMIO failure (%d) on device: %s %s\n",
  535. rets[0], dn->name, dn->full_name);
  536. event = kmalloc(sizeof(*event), GFP_ATOMIC);
  537. if (event == NULL) {
  538. eeh_panic(dev, reset_state);
  539. return 1;
  540. }
  541. event->dev = dev;
  542. event->dn = dn;
  543. event->reset_state = reset_state;
  544. /* We may or may not be called in an interrupt context */
  545. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  546. list_add(&event->list, &eeh_eventlist);
  547. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  548. /* Most EEH events are due to device driver bugs. Having
  549. * a stack trace will help the device-driver authors figure
  550. * out what happened. So print that out. */
  551. dump_stack();
  552. schedule_work(&eeh_event_wq);
  553. return 0;
  554. }
  555. EXPORT_SYMBOL(eeh_dn_check_failure);
  556. /**
  557. * eeh_check_failure - check if all 1's data is due to EEH slot freeze
  558. * @token i/o token, should be address in the form 0xA....
  559. * @val value, should be all 1's (XXX why do we need this arg??)
  560. *
  561. * Check for an eeh failure at the given token address.
  562. * Check for an EEH failure at the given token address. Call this
  563. * routine if the result of a read was all 0xff's and you want to
  564. * find out if this is due to an EEH slot freeze event. This routine
  565. * will query firmware for the EEH status.
  566. *
  567. * Note this routine is safe to call in an interrupt context.
  568. */
  569. unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
  570. {
  571. unsigned long addr;
  572. struct pci_dev *dev;
  573. struct device_node *dn;
  574. /* Finding the phys addr + pci device; this is pretty quick. */
  575. addr = eeh_token_to_phys((unsigned long __force) token);
  576. dev = pci_get_device_by_addr(addr);
  577. if (!dev)
  578. return val;
  579. dn = pci_device_to_OF_node(dev);
  580. eeh_dn_check_failure (dn, dev);
  581. pci_dev_put(dev);
  582. return val;
  583. }
  584. EXPORT_SYMBOL(eeh_check_failure);
  585. struct eeh_early_enable_info {
  586. unsigned int buid_hi;
  587. unsigned int buid_lo;
  588. };
  589. /* Enable eeh for the given device node. */
  590. static void *early_enable_eeh(struct device_node *dn, void *data)
  591. {
  592. struct eeh_early_enable_info *info = data;
  593. int ret;
  594. char *status = get_property(dn, "status", NULL);
  595. u32 *class_code = (u32 *)get_property(dn, "class-code", NULL);
  596. u32 *vendor_id = (u32 *)get_property(dn, "vendor-id", NULL);
  597. u32 *device_id = (u32 *)get_property(dn, "device-id", NULL);
  598. u32 *regs;
  599. int enable;
  600. struct pci_dn *pdn = dn->data;
  601. pdn->eeh_mode = 0;
  602. if (status && strcmp(status, "ok") != 0)
  603. return NULL; /* ignore devices with bad status */
  604. /* Ignore bad nodes. */
  605. if (!class_code || !vendor_id || !device_id)
  606. return NULL;
  607. /* There is nothing to check on PCI to ISA bridges */
  608. if (dn->type && !strcmp(dn->type, "isa")) {
  609. pdn->eeh_mode |= EEH_MODE_NOCHECK;
  610. return NULL;
  611. }
  612. /*
  613. * Now decide if we are going to "Disable" EEH checking
  614. * for this device. We still run with the EEH hardware active,
  615. * but we won't be checking for ff's. This means a driver
  616. * could return bad data (very bad!), an interrupt handler could
  617. * hang waiting on status bits that won't change, etc.
  618. * But there are a few cases like display devices that make sense.
  619. */
  620. enable = 1; /* i.e. we will do checking */
  621. if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
  622. enable = 0;
  623. if (!enable)
  624. pdn->eeh_mode |= EEH_MODE_NOCHECK;
  625. /* Ok... see if this device supports EEH. Some do, some don't,
  626. * and the only way to find out is to check each and every one. */
  627. regs = (u32 *)get_property(dn, "reg", NULL);
  628. if (regs) {
  629. /* First register entry is addr (00BBSS00) */
  630. /* Try to enable eeh */
  631. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  632. regs[0], info->buid_hi, info->buid_lo,
  633. EEH_ENABLE);
  634. if (ret == 0) {
  635. eeh_subsystem_enabled = 1;
  636. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  637. pdn->eeh_config_addr = regs[0];
  638. #ifdef DEBUG
  639. printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);
  640. #endif
  641. } else {
  642. /* This device doesn't support EEH, but it may have an
  643. * EEH parent, in which case we mark it as supported. */
  644. if (dn->parent && dn->parent->data
  645. && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
  646. /* Parent supports EEH. */
  647. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  648. pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
  649. return NULL;
  650. }
  651. }
  652. } else {
  653. printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
  654. dn->full_name);
  655. }
  656. return NULL;
  657. }
  658. /*
  659. * Initialize EEH by trying to enable it for all of the adapters in the system.
  660. * As a side effect we can determine here if eeh is supported at all.
  661. * Note that we leave EEH on so failed config cycles won't cause a machine
  662. * check. If a user turns off EEH for a particular adapter they are really
  663. * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
  664. * grant access to a slot if EEH isn't enabled, and so we always enable
  665. * EEH for all slots/all devices.
  666. *
  667. * The eeh-force-off option disables EEH checking globally, for all slots.
  668. * Even if force-off is set, the EEH hardware is still enabled, so that
  669. * newer systems can boot.
  670. */
  671. void __init eeh_init(void)
  672. {
  673. struct device_node *phb, *np;
  674. struct eeh_early_enable_info info;
  675. np = of_find_node_by_path("/rtas");
  676. if (np == NULL)
  677. return;
  678. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  679. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  680. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  681. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  682. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  683. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
  684. return;
  685. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  686. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  687. eeh_error_buf_size = 1024;
  688. }
  689. if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  690. printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
  691. "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  692. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  693. }
  694. /* Enable EEH for all adapters. Note that eeh requires buid's */
  695. for (phb = of_find_node_by_name(NULL, "pci"); phb;
  696. phb = of_find_node_by_name(phb, "pci")) {
  697. unsigned long buid;
  698. struct pci_dn *pci;
  699. buid = get_phb_buid(phb);
  700. if (buid == 0 || phb->data == NULL)
  701. continue;
  702. pci = phb->data;
  703. info.buid_lo = BUID_LO(buid);
  704. info.buid_hi = BUID_HI(buid);
  705. traverse_pci_devices(phb, early_enable_eeh, &info);
  706. }
  707. if (eeh_subsystem_enabled)
  708. printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
  709. else
  710. printk(KERN_WARNING "EEH: No capable adapters found\n");
  711. }
  712. /**
  713. * eeh_add_device_early - enable EEH for the indicated device_node
  714. * @dn: device node for which to set up EEH
  715. *
  716. * This routine must be used to perform EEH initialization for PCI
  717. * devices that were added after system boot (e.g. hotplug, dlpar).
  718. * This routine must be called before any i/o is performed to the
  719. * adapter (inluding any config-space i/o).
  720. * Whether this actually enables EEH or not for this device depends
  721. * on the CEC architecture, type of the device, on earlier boot
  722. * command-line arguments & etc.
  723. */
  724. void eeh_add_device_early(struct device_node *dn)
  725. {
  726. struct pci_controller *phb;
  727. struct eeh_early_enable_info info;
  728. if (!dn || !dn->data)
  729. return;
  730. phb = PCI_DN(dn)->phb;
  731. if (NULL == phb || 0 == phb->buid) {
  732. printk(KERN_WARNING "EEH: Expected buid but found none\n");
  733. return;
  734. }
  735. info.buid_hi = BUID_HI(phb->buid);
  736. info.buid_lo = BUID_LO(phb->buid);
  737. early_enable_eeh(dn, &info);
  738. }
  739. EXPORT_SYMBOL(eeh_add_device_early);
  740. /**
  741. * eeh_add_device_late - perform EEH initialization for the indicated pci device
  742. * @dev: pci device for which to set up EEH
  743. *
  744. * This routine must be used to complete EEH initialization for PCI
  745. * devices that were added after system boot (e.g. hotplug, dlpar).
  746. */
  747. void eeh_add_device_late(struct pci_dev *dev)
  748. {
  749. if (!dev || !eeh_subsystem_enabled)
  750. return;
  751. #ifdef DEBUG
  752. printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev));
  753. #endif
  754. pci_addr_cache_insert_device (dev);
  755. }
  756. EXPORT_SYMBOL(eeh_add_device_late);
  757. /**
  758. * eeh_remove_device - undo EEH setup for the indicated pci device
  759. * @dev: pci device to be removed
  760. *
  761. * This routine should be when a device is removed from a running
  762. * system (e.g. by hotplug or dlpar).
  763. */
  764. void eeh_remove_device(struct pci_dev *dev)
  765. {
  766. if (!dev || !eeh_subsystem_enabled)
  767. return;
  768. /* Unregister the device with the EEH/PCI address search system */
  769. #ifdef DEBUG
  770. printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev));
  771. #endif
  772. pci_addr_cache_remove_device(dev);
  773. }
  774. EXPORT_SYMBOL(eeh_remove_device);
  775. static int proc_eeh_show(struct seq_file *m, void *v)
  776. {
  777. unsigned int cpu;
  778. unsigned long ffs = 0, positives = 0, failures = 0;
  779. unsigned long resets = 0;
  780. for_each_cpu(cpu) {
  781. ffs += per_cpu(total_mmio_ffs, cpu);
  782. positives += per_cpu(false_positives, cpu);
  783. failures += per_cpu(ignored_failures, cpu);
  784. resets += per_cpu(slot_resets, cpu);
  785. }
  786. if (0 == eeh_subsystem_enabled) {
  787. seq_printf(m, "EEH Subsystem is globally disabled\n");
  788. seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);
  789. } else {
  790. seq_printf(m, "EEH Subsystem is enabled\n");
  791. seq_printf(m, "eeh_total_mmio_ffs=%ld\n"
  792. "eeh_false_positives=%ld\n"
  793. "eeh_ignored_failures=%ld\n"
  794. "eeh_slot_resets=%ld\n"
  795. "eeh_fail_count=%d\n",
  796. ffs, positives, failures, resets,
  797. eeh_fail_count.counter);
  798. }
  799. return 0;
  800. }
  801. static int proc_eeh_open(struct inode *inode, struct file *file)
  802. {
  803. return single_open(file, proc_eeh_show, NULL);
  804. }
  805. static struct file_operations proc_eeh_operations = {
  806. .open = proc_eeh_open,
  807. .read = seq_read,
  808. .llseek = seq_lseek,
  809. .release = single_release,
  810. };
  811. static int __init eeh_init_proc(void)
  812. {
  813. struct proc_dir_entry *e;
  814. if (systemcfg->platform & PLATFORM_PSERIES) {
  815. e = create_proc_entry("ppc64/eeh", 0, NULL);
  816. if (e)
  817. e->proc_fops = &proc_eeh_operations;
  818. }
  819. return 0;
  820. }
  821. __initcall(eeh_init_proc);