eeh.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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/delay.h>
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/pci.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/rbtree.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/spinlock.h>
  27. #include <asm/atomic.h>
  28. #include <asm/eeh.h>
  29. #include <asm/eeh_event.h>
  30. #include <asm/io.h>
  31. #include <asm/machdep.h>
  32. #include <asm/ppc-pci.h>
  33. #include <asm/rtas.h>
  34. #undef DEBUG
  35. /** Overview:
  36. * EEH, or "Extended Error Handling" is a PCI bridge technology for
  37. * dealing with PCI bus errors that can't be dealt with within the
  38. * usual PCI framework, except by check-stopping the CPU. Systems
  39. * that are designed for high-availability/reliability cannot afford
  40. * to crash due to a "mere" PCI error, thus the need for EEH.
  41. * An EEH-capable bridge operates by converting a detected error
  42. * into a "slot freeze", taking the PCI adapter off-line, making
  43. * the slot behave, from the OS'es point of view, as if the slot
  44. * were "empty": all reads return 0xff's and all writes are silently
  45. * ignored. EEH slot isolation events can be triggered by parity
  46. * errors on the address or data busses (e.g. during posted writes),
  47. * which in turn might be caused by low voltage on the bus, dust,
  48. * vibration, humidity, radioactivity or plain-old failed hardware.
  49. *
  50. * Note, however, that one of the leading causes of EEH slot
  51. * freeze events are buggy device drivers, buggy device microcode,
  52. * or buggy device hardware. This is because any attempt by the
  53. * device to bus-master data to a memory address that is not
  54. * assigned to the device will trigger a slot freeze. (The idea
  55. * is to prevent devices-gone-wild from corrupting system memory).
  56. * Buggy hardware/drivers will have a miserable time co-existing
  57. * with EEH.
  58. *
  59. * Ideally, a PCI device driver, when suspecting that an isolation
  60. * event has occured (e.g. by reading 0xff's), will then ask EEH
  61. * whether this is the case, and then take appropriate steps to
  62. * reset the PCI slot, the PCI device, and then resume operations.
  63. * However, until that day, the checking is done here, with the
  64. * eeh_check_failure() routine embedded in the MMIO macros. If
  65. * the slot is found to be isolated, an "EEH Event" is synthesized
  66. * and sent out for processing.
  67. */
  68. /* If a device driver keeps reading an MMIO register in an interrupt
  69. * handler after a slot isolation event has occurred, we assume it
  70. * is broken and panic. This sets the threshold for how many read
  71. * attempts we allow before panicking.
  72. */
  73. #define EEH_MAX_FAILS 2100000
  74. /* Time to wait for a PCI slot to report status, in milliseconds */
  75. #define PCI_BUS_RESET_WAIT_MSEC (60*1000)
  76. /* RTAS tokens */
  77. static int ibm_set_eeh_option;
  78. static int ibm_set_slot_reset;
  79. static int ibm_read_slot_reset_state;
  80. static int ibm_read_slot_reset_state2;
  81. static int ibm_slot_error_detail;
  82. static int ibm_get_config_addr_info;
  83. static int ibm_get_config_addr_info2;
  84. static int ibm_configure_bridge;
  85. int eeh_subsystem_enabled;
  86. EXPORT_SYMBOL(eeh_subsystem_enabled);
  87. /* Lock to avoid races due to multiple reports of an error */
  88. static DEFINE_SPINLOCK(confirm_error_lock);
  89. /* Buffer for reporting slot-error-detail rtas calls. Its here
  90. * in BSS, and not dynamically alloced, so that it ends up in
  91. * RMO where RTAS can access it.
  92. */
  93. static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
  94. static DEFINE_SPINLOCK(slot_errbuf_lock);
  95. static int eeh_error_buf_size;
  96. /* Buffer for reporting pci register dumps. Its here in BSS, and
  97. * not dynamically alloced, so that it ends up in RMO where RTAS
  98. * can access it.
  99. */
  100. #define EEH_PCI_REGS_LOG_LEN 4096
  101. static unsigned char pci_regs_buf[EEH_PCI_REGS_LOG_LEN];
  102. /* System monitoring statistics */
  103. static unsigned long no_device;
  104. static unsigned long no_dn;
  105. static unsigned long no_cfg_addr;
  106. static unsigned long ignored_check;
  107. static unsigned long total_mmio_ffs;
  108. static unsigned long false_positives;
  109. static unsigned long slot_resets;
  110. #define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)
  111. /* --------------------------------------------------------------- */
  112. /* Below lies the EEH event infrastructure */
  113. static void rtas_slot_error_detail(struct pci_dn *pdn, int severity,
  114. char *driver_log, size_t loglen)
  115. {
  116. int config_addr;
  117. unsigned long flags;
  118. int rc;
  119. /* Log the error with the rtas logger */
  120. spin_lock_irqsave(&slot_errbuf_lock, flags);
  121. memset(slot_errbuf, 0, eeh_error_buf_size);
  122. /* Use PE configuration address, if present */
  123. config_addr = pdn->eeh_config_addr;
  124. if (pdn->eeh_pe_config_addr)
  125. config_addr = pdn->eeh_pe_config_addr;
  126. rc = rtas_call(ibm_slot_error_detail,
  127. 8, 1, NULL, config_addr,
  128. BUID_HI(pdn->phb->buid),
  129. BUID_LO(pdn->phb->buid),
  130. virt_to_phys(driver_log), loglen,
  131. virt_to_phys(slot_errbuf),
  132. eeh_error_buf_size,
  133. severity);
  134. if (rc == 0)
  135. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  136. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  137. }
  138. /**
  139. * gather_pci_data - copy assorted PCI config space registers to buff
  140. * @pdn: device to report data for
  141. * @buf: point to buffer in which to log
  142. * @len: amount of room in buffer
  143. *
  144. * This routine captures assorted PCI configuration space data,
  145. * and puts them into a buffer for RTAS error logging.
  146. */
  147. static size_t gather_pci_data(struct pci_dn *pdn, char * buf, size_t len)
  148. {
  149. u32 cfg;
  150. int cap, i;
  151. int n = 0;
  152. n += scnprintf(buf+n, len-n, "%s\n", pdn->node->full_name);
  153. printk(KERN_WARNING "EEH: of node=%s\n", pdn->node->full_name);
  154. rtas_read_config(pdn, PCI_VENDOR_ID, 4, &cfg);
  155. n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
  156. printk(KERN_WARNING "EEH: PCI device/vendor: %08x\n", cfg);
  157. rtas_read_config(pdn, PCI_COMMAND, 4, &cfg);
  158. n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg);
  159. printk(KERN_WARNING "EEH: PCI cmd/status register: %08x\n", cfg);
  160. /* Dump out the PCI-X command and status regs */
  161. cap = pci_find_capability(pdn->pcidev, PCI_CAP_ID_PCIX);
  162. if (cap) {
  163. rtas_read_config(pdn, cap, 4, &cfg);
  164. n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg);
  165. printk(KERN_WARNING "EEH: PCI-X cmd: %08x\n", cfg);
  166. rtas_read_config(pdn, cap+4, 4, &cfg);
  167. n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg);
  168. printk(KERN_WARNING "EEH: PCI-X status: %08x\n", cfg);
  169. }
  170. /* If PCI-E capable, dump PCI-E cap 10, and the AER */
  171. cap = pci_find_capability(pdn->pcidev, PCI_CAP_ID_EXP);
  172. if (cap) {
  173. n += scnprintf(buf+n, len-n, "pci-e cap10:\n");
  174. printk(KERN_WARNING
  175. "EEH: PCI-E capabilities and status follow:\n");
  176. for (i=0; i<=8; i++) {
  177. rtas_read_config(pdn, cap+4*i, 4, &cfg);
  178. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  179. printk(KERN_WARNING "EEH: PCI-E %02x: %08x\n", i, cfg);
  180. }
  181. cap = pci_find_ext_capability(pdn->pcidev,PCI_EXT_CAP_ID_ERR);
  182. if (cap) {
  183. n += scnprintf(buf+n, len-n, "pci-e AER:\n");
  184. printk(KERN_WARNING
  185. "EEH: PCI-E AER capability register set follows:\n");
  186. for (i=0; i<14; i++) {
  187. rtas_read_config(pdn, cap+4*i, 4, &cfg);
  188. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  189. printk(KERN_WARNING "EEH: PCI-E AER %02x: %08x\n", i, cfg);
  190. }
  191. }
  192. }
  193. return n;
  194. }
  195. void eeh_slot_error_detail(struct pci_dn *pdn, int severity)
  196. {
  197. size_t loglen = 0;
  198. pci_regs_buf[0] = 0;
  199. rtas_pci_enable(pdn, EEH_THAW_MMIO);
  200. loglen = gather_pci_data(pdn, pci_regs_buf, EEH_PCI_REGS_LOG_LEN);
  201. rtas_slot_error_detail(pdn, severity, pci_regs_buf, loglen);
  202. }
  203. /**
  204. * read_slot_reset_state - Read the reset state of a device node's slot
  205. * @dn: device node to read
  206. * @rets: array to return results in
  207. */
  208. static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
  209. {
  210. int token, outputs;
  211. int config_addr;
  212. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  213. token = ibm_read_slot_reset_state2;
  214. outputs = 4;
  215. } else {
  216. token = ibm_read_slot_reset_state;
  217. rets[2] = 0; /* fake PE Unavailable info */
  218. outputs = 3;
  219. }
  220. /* Use PE configuration address, if present */
  221. config_addr = pdn->eeh_config_addr;
  222. if (pdn->eeh_pe_config_addr)
  223. config_addr = pdn->eeh_pe_config_addr;
  224. return rtas_call(token, 3, outputs, rets, config_addr,
  225. BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
  226. }
  227. /**
  228. * eeh_wait_for_slot_status - returns error status of slot
  229. * @pdn pci device node
  230. * @max_wait_msecs maximum number to millisecs to wait
  231. *
  232. * Return negative value if a permanent error, else return
  233. * Partition Endpoint (PE) status value.
  234. *
  235. * If @max_wait_msecs is positive, then this routine will
  236. * sleep until a valid status can be obtained, or until
  237. * the max allowed wait time is exceeded, in which case
  238. * a -2 is returned.
  239. */
  240. int
  241. eeh_wait_for_slot_status(struct pci_dn *pdn, int max_wait_msecs)
  242. {
  243. int rc;
  244. int rets[3];
  245. int mwait;
  246. while (1) {
  247. rc = read_slot_reset_state(pdn, rets);
  248. if (rc) return rc;
  249. if (rets[1] == 0) return -1; /* EEH is not supported */
  250. if (rets[0] != 5) return rets[0]; /* return actual status */
  251. if (rets[2] == 0) return -1; /* permanently unavailable */
  252. if (max_wait_msecs <= 0) return -1;
  253. mwait = rets[2];
  254. if (mwait <= 0) {
  255. printk (KERN_WARNING
  256. "EEH: Firmware returned bad wait value=%d\n", mwait);
  257. mwait = 1000;
  258. } else if (mwait > 300*1000) {
  259. printk (KERN_WARNING
  260. "EEH: Firmware is taking too long, time=%d\n", mwait);
  261. mwait = 300*1000;
  262. }
  263. max_wait_msecs -= mwait;
  264. msleep (mwait);
  265. }
  266. printk(KERN_WARNING "EEH: Timed out waiting for slot status\n");
  267. return -2;
  268. }
  269. /**
  270. * eeh_token_to_phys - convert EEH address token to phys address
  271. * @token i/o token, should be address in the form 0xA....
  272. */
  273. static inline unsigned long eeh_token_to_phys(unsigned long token)
  274. {
  275. pte_t *ptep;
  276. unsigned long pa;
  277. ptep = find_linux_pte(init_mm.pgd, token);
  278. if (!ptep)
  279. return token;
  280. pa = pte_pfn(*ptep) << PAGE_SHIFT;
  281. return pa | (token & (PAGE_SIZE-1));
  282. }
  283. /**
  284. * Return the "partitionable endpoint" (pe) under which this device lies
  285. */
  286. struct device_node * find_device_pe(struct device_node *dn)
  287. {
  288. while ((dn->parent) && PCI_DN(dn->parent) &&
  289. (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
  290. dn = dn->parent;
  291. }
  292. return dn;
  293. }
  294. /** Mark all devices that are peers of this device as failed.
  295. * Mark the device driver too, so that it can see the failure
  296. * immediately; this is critical, since some drivers poll
  297. * status registers in interrupts ... If a driver is polling,
  298. * and the slot is frozen, then the driver can deadlock in
  299. * an interrupt context, which is bad.
  300. */
  301. static void __eeh_mark_slot (struct device_node *dn, int mode_flag)
  302. {
  303. while (dn) {
  304. if (PCI_DN(dn)) {
  305. /* Mark the pci device driver too */
  306. struct pci_dev *dev = PCI_DN(dn)->pcidev;
  307. PCI_DN(dn)->eeh_mode |= mode_flag;
  308. if (dev && dev->driver)
  309. dev->error_state = pci_channel_io_frozen;
  310. if (dn->child)
  311. __eeh_mark_slot (dn->child, mode_flag);
  312. }
  313. dn = dn->sibling;
  314. }
  315. }
  316. void eeh_mark_slot (struct device_node *dn, int mode_flag)
  317. {
  318. struct pci_dev *dev;
  319. dn = find_device_pe (dn);
  320. /* Back up one, since config addrs might be shared */
  321. if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
  322. dn = dn->parent;
  323. PCI_DN(dn)->eeh_mode |= mode_flag;
  324. /* Mark the pci device too */
  325. dev = PCI_DN(dn)->pcidev;
  326. if (dev)
  327. dev->error_state = pci_channel_io_frozen;
  328. __eeh_mark_slot (dn->child, mode_flag);
  329. }
  330. static void __eeh_clear_slot (struct device_node *dn, int mode_flag)
  331. {
  332. while (dn) {
  333. if (PCI_DN(dn)) {
  334. PCI_DN(dn)->eeh_mode &= ~mode_flag;
  335. PCI_DN(dn)->eeh_check_count = 0;
  336. if (dn->child)
  337. __eeh_clear_slot (dn->child, mode_flag);
  338. }
  339. dn = dn->sibling;
  340. }
  341. }
  342. void eeh_clear_slot (struct device_node *dn, int mode_flag)
  343. {
  344. unsigned long flags;
  345. spin_lock_irqsave(&confirm_error_lock, flags);
  346. dn = find_device_pe (dn);
  347. /* Back up one, since config addrs might be shared */
  348. if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
  349. dn = dn->parent;
  350. PCI_DN(dn)->eeh_mode &= ~mode_flag;
  351. PCI_DN(dn)->eeh_check_count = 0;
  352. __eeh_clear_slot (dn->child, mode_flag);
  353. spin_unlock_irqrestore(&confirm_error_lock, flags);
  354. }
  355. /**
  356. * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
  357. * @dn device node
  358. * @dev pci device, if known
  359. *
  360. * Check for an EEH failure for the given device node. Call this
  361. * routine if the result of a read was all 0xff's and you want to
  362. * find out if this is due to an EEH slot freeze. This routine
  363. * will query firmware for the EEH status.
  364. *
  365. * Returns 0 if there has not been an EEH error; otherwise returns
  366. * a non-zero value and queues up a slot isolation event notification.
  367. *
  368. * It is safe to call this routine in an interrupt context.
  369. */
  370. int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
  371. {
  372. int ret;
  373. int rets[3];
  374. unsigned long flags;
  375. struct pci_dn *pdn;
  376. int rc = 0;
  377. total_mmio_ffs++;
  378. if (!eeh_subsystem_enabled)
  379. return 0;
  380. if (!dn) {
  381. no_dn++;
  382. return 0;
  383. }
  384. pdn = PCI_DN(dn);
  385. /* Access to IO BARs might get this far and still not want checking. */
  386. if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
  387. pdn->eeh_mode & EEH_MODE_NOCHECK) {
  388. ignored_check++;
  389. #ifdef DEBUG
  390. printk ("EEH:ignored check (%x) for %s %s\n",
  391. pdn->eeh_mode, pci_name (dev), dn->full_name);
  392. #endif
  393. return 0;
  394. }
  395. if (!pdn->eeh_config_addr && !pdn->eeh_pe_config_addr) {
  396. no_cfg_addr++;
  397. return 0;
  398. }
  399. /* If we already have a pending isolation event for this
  400. * slot, we know it's bad already, we don't need to check.
  401. * Do this checking under a lock; as multiple PCI devices
  402. * in one slot might report errors simultaneously, and we
  403. * only want one error recovery routine running.
  404. */
  405. spin_lock_irqsave(&confirm_error_lock, flags);
  406. rc = 1;
  407. if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
  408. pdn->eeh_check_count ++;
  409. if (pdn->eeh_check_count >= EEH_MAX_FAILS) {
  410. printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n",
  411. pdn->eeh_check_count);
  412. dump_stack();
  413. msleep(5000);
  414. /* re-read the slot reset state */
  415. if (read_slot_reset_state(pdn, rets) != 0)
  416. rets[0] = -1; /* reset state unknown */
  417. /* If we are here, then we hit an infinite loop. Stop. */
  418. panic("EEH: MMIO halt (%d) on device:%s\n", rets[0], pci_name(dev));
  419. }
  420. goto dn_unlock;
  421. }
  422. /*
  423. * Now test for an EEH failure. This is VERY expensive.
  424. * Note that the eeh_config_addr may be a parent device
  425. * in the case of a device behind a bridge, or it may be
  426. * function zero of a multi-function device.
  427. * In any case they must share a common PHB.
  428. */
  429. ret = read_slot_reset_state(pdn, rets);
  430. /* If the call to firmware failed, punt */
  431. if (ret != 0) {
  432. printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
  433. ret, dn->full_name);
  434. false_positives++;
  435. pdn->eeh_false_positives ++;
  436. rc = 0;
  437. goto dn_unlock;
  438. }
  439. /* Note that config-io to empty slots may fail;
  440. * they are empty when they don't have children. */
  441. if ((rets[0] == 5) && (dn->child == NULL)) {
  442. false_positives++;
  443. pdn->eeh_false_positives ++;
  444. rc = 0;
  445. goto dn_unlock;
  446. }
  447. /* If EEH is not supported on this device, punt. */
  448. if (rets[1] != 1) {
  449. printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
  450. ret, dn->full_name);
  451. false_positives++;
  452. pdn->eeh_false_positives ++;
  453. rc = 0;
  454. goto dn_unlock;
  455. }
  456. /* If not the kind of error we know about, punt. */
  457. if (rets[0] != 1 && rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
  458. false_positives++;
  459. pdn->eeh_false_positives ++;
  460. rc = 0;
  461. goto dn_unlock;
  462. }
  463. slot_resets++;
  464. /* Avoid repeated reports of this failure, including problems
  465. * with other functions on this device, and functions under
  466. * bridges. */
  467. eeh_mark_slot (dn, EEH_MODE_ISOLATED);
  468. spin_unlock_irqrestore(&confirm_error_lock, flags);
  469. eeh_send_failure_event (dn, dev);
  470. /* Most EEH events are due to device driver bugs. Having
  471. * a stack trace will help the device-driver authors figure
  472. * out what happened. So print that out. */
  473. dump_stack();
  474. return 1;
  475. dn_unlock:
  476. spin_unlock_irqrestore(&confirm_error_lock, flags);
  477. return rc;
  478. }
  479. EXPORT_SYMBOL_GPL(eeh_dn_check_failure);
  480. /**
  481. * eeh_check_failure - check if all 1's data is due to EEH slot freeze
  482. * @token i/o token, should be address in the form 0xA....
  483. * @val value, should be all 1's (XXX why do we need this arg??)
  484. *
  485. * Check for an EEH failure at the given token address. Call this
  486. * routine if the result of a read was all 0xff's and you want to
  487. * find out if this is due to an EEH slot freeze event. This routine
  488. * will query firmware for the EEH status.
  489. *
  490. * Note this routine is safe to call in an interrupt context.
  491. */
  492. unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
  493. {
  494. unsigned long addr;
  495. struct pci_dev *dev;
  496. struct device_node *dn;
  497. /* Finding the phys addr + pci device; this is pretty quick. */
  498. addr = eeh_token_to_phys((unsigned long __force) token);
  499. dev = pci_get_device_by_addr(addr);
  500. if (!dev) {
  501. no_device++;
  502. return val;
  503. }
  504. dn = pci_device_to_OF_node(dev);
  505. eeh_dn_check_failure (dn, dev);
  506. pci_dev_put(dev);
  507. return val;
  508. }
  509. EXPORT_SYMBOL(eeh_check_failure);
  510. /* ------------------------------------------------------------- */
  511. /* The code below deals with error recovery */
  512. /**
  513. * rtas_pci_enable - enable MMIO or DMA transfers for this slot
  514. * @pdn pci device node
  515. */
  516. int
  517. rtas_pci_enable(struct pci_dn *pdn, int function)
  518. {
  519. int config_addr;
  520. int rc;
  521. /* Use PE configuration address, if present */
  522. config_addr = pdn->eeh_config_addr;
  523. if (pdn->eeh_pe_config_addr)
  524. config_addr = pdn->eeh_pe_config_addr;
  525. rc = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  526. config_addr,
  527. BUID_HI(pdn->phb->buid),
  528. BUID_LO(pdn->phb->buid),
  529. function);
  530. if (rc)
  531. printk(KERN_WARNING "EEH: Unexpected state change %d, err=%d dn=%s\n",
  532. function, rc, pdn->node->full_name);
  533. rc = eeh_wait_for_slot_status (pdn, PCI_BUS_RESET_WAIT_MSEC);
  534. if ((rc == 4) && (function == EEH_THAW_MMIO))
  535. return 0;
  536. return rc;
  537. }
  538. /**
  539. * rtas_pci_slot_reset - raises/lowers the pci #RST line
  540. * @pdn pci device node
  541. * @state: 1/0 to raise/lower the #RST
  542. *
  543. * Clear the EEH-frozen condition on a slot. This routine
  544. * asserts the PCI #RST line if the 'state' argument is '1',
  545. * and drops the #RST line if 'state is '0'. This routine is
  546. * safe to call in an interrupt context.
  547. *
  548. */
  549. static void
  550. rtas_pci_slot_reset(struct pci_dn *pdn, int state)
  551. {
  552. int config_addr;
  553. int rc;
  554. BUG_ON (pdn==NULL);
  555. if (!pdn->phb) {
  556. printk (KERN_WARNING "EEH: in slot reset, device node %s has no phb\n",
  557. pdn->node->full_name);
  558. return;
  559. }
  560. /* Use PE configuration address, if present */
  561. config_addr = pdn->eeh_config_addr;
  562. if (pdn->eeh_pe_config_addr)
  563. config_addr = pdn->eeh_pe_config_addr;
  564. rc = rtas_call(ibm_set_slot_reset,4,1, NULL,
  565. config_addr,
  566. BUID_HI(pdn->phb->buid),
  567. BUID_LO(pdn->phb->buid),
  568. state);
  569. if (rc)
  570. printk (KERN_WARNING "EEH: Unable to reset the failed slot,"
  571. " (%d) #RST=%d dn=%s\n",
  572. rc, state, pdn->node->full_name);
  573. }
  574. /**
  575. * pcibios_set_pcie_slot_reset - Set PCI-E reset state
  576. * @dev: pci device struct
  577. * @state: reset state to enter
  578. *
  579. * Return value:
  580. * 0 if success
  581. **/
  582. int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
  583. {
  584. struct device_node *dn = pci_device_to_OF_node(dev);
  585. struct pci_dn *pdn = PCI_DN(dn);
  586. switch (state) {
  587. case pcie_deassert_reset:
  588. rtas_pci_slot_reset(pdn, 0);
  589. break;
  590. case pcie_hot_reset:
  591. rtas_pci_slot_reset(pdn, 1);
  592. break;
  593. case pcie_warm_reset:
  594. rtas_pci_slot_reset(pdn, 3);
  595. break;
  596. default:
  597. return -EINVAL;
  598. };
  599. return 0;
  600. }
  601. /**
  602. * rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
  603. * @pdn: pci device node to be reset.
  604. *
  605. * Return 0 if success, else a non-zero value.
  606. */
  607. static void __rtas_set_slot_reset(struct pci_dn *pdn)
  608. {
  609. rtas_pci_slot_reset (pdn, 1);
  610. /* The PCI bus requires that the reset be held high for at least
  611. * a 100 milliseconds. We wait a bit longer 'just in case'. */
  612. #define PCI_BUS_RST_HOLD_TIME_MSEC 250
  613. msleep (PCI_BUS_RST_HOLD_TIME_MSEC);
  614. /* We might get hit with another EEH freeze as soon as the
  615. * pci slot reset line is dropped. Make sure we don't miss
  616. * these, and clear the flag now. */
  617. eeh_clear_slot (pdn->node, EEH_MODE_ISOLATED);
  618. rtas_pci_slot_reset (pdn, 0);
  619. /* After a PCI slot has been reset, the PCI Express spec requires
  620. * a 1.5 second idle time for the bus to stabilize, before starting
  621. * up traffic. */
  622. #define PCI_BUS_SETTLE_TIME_MSEC 1800
  623. msleep (PCI_BUS_SETTLE_TIME_MSEC);
  624. }
  625. int rtas_set_slot_reset(struct pci_dn *pdn)
  626. {
  627. int i, rc;
  628. /* Take three shots at resetting the bus */
  629. for (i=0; i<3; i++) {
  630. __rtas_set_slot_reset(pdn);
  631. rc = eeh_wait_for_slot_status(pdn, PCI_BUS_RESET_WAIT_MSEC);
  632. if (rc == 0)
  633. return 0;
  634. if (rc < 0) {
  635. printk (KERN_ERR "EEH: unrecoverable slot failure %s\n",
  636. pdn->node->full_name);
  637. return -1;
  638. }
  639. printk (KERN_ERR "EEH: bus reset %d failed on slot %s\n",
  640. i+1, pdn->node->full_name);
  641. }
  642. return -1;
  643. }
  644. /* ------------------------------------------------------- */
  645. /** Save and restore of PCI BARs
  646. *
  647. * Although firmware will set up BARs during boot, it doesn't
  648. * set up device BAR's after a device reset, although it will,
  649. * if requested, set up bridge configuration. Thus, we need to
  650. * configure the PCI devices ourselves.
  651. */
  652. /**
  653. * __restore_bars - Restore the Base Address Registers
  654. * @pdn: pci device node
  655. *
  656. * Loads the PCI configuration space base address registers,
  657. * the expansion ROM base address, the latency timer, and etc.
  658. * from the saved values in the device node.
  659. */
  660. static inline void __restore_bars (struct pci_dn *pdn)
  661. {
  662. int i;
  663. if (NULL==pdn->phb) return;
  664. for (i=4; i<10; i++) {
  665. rtas_write_config(pdn, i*4, 4, pdn->config_space[i]);
  666. }
  667. /* 12 == Expansion ROM Address */
  668. rtas_write_config(pdn, 12*4, 4, pdn->config_space[12]);
  669. #define BYTE_SWAP(OFF) (8*((OFF)/4)+3-(OFF))
  670. #define SAVED_BYTE(OFF) (((u8 *)(pdn->config_space))[BYTE_SWAP(OFF)])
  671. rtas_write_config (pdn, PCI_CACHE_LINE_SIZE, 1,
  672. SAVED_BYTE(PCI_CACHE_LINE_SIZE));
  673. rtas_write_config (pdn, PCI_LATENCY_TIMER, 1,
  674. SAVED_BYTE(PCI_LATENCY_TIMER));
  675. /* max latency, min grant, interrupt pin and line */
  676. rtas_write_config(pdn, 15*4, 4, pdn->config_space[15]);
  677. }
  678. /**
  679. * eeh_restore_bars - restore the PCI config space info
  680. *
  681. * This routine performs a recursive walk to the children
  682. * of this device as well.
  683. */
  684. void eeh_restore_bars(struct pci_dn *pdn)
  685. {
  686. struct device_node *dn;
  687. if (!pdn)
  688. return;
  689. if ((pdn->eeh_mode & EEH_MODE_SUPPORTED) && !IS_BRIDGE(pdn->class_code))
  690. __restore_bars (pdn);
  691. dn = pdn->node->child;
  692. while (dn) {
  693. eeh_restore_bars (PCI_DN(dn));
  694. dn = dn->sibling;
  695. }
  696. }
  697. /**
  698. * eeh_save_bars - save device bars
  699. *
  700. * Save the values of the device bars. Unlike the restore
  701. * routine, this routine is *not* recursive. This is because
  702. * PCI devices are added individuallly; but, for the restore,
  703. * an entire slot is reset at a time.
  704. */
  705. static void eeh_save_bars(struct pci_dn *pdn)
  706. {
  707. int i;
  708. if (!pdn )
  709. return;
  710. for (i = 0; i < 16; i++)
  711. rtas_read_config(pdn, i * 4, 4, &pdn->config_space[i]);
  712. }
  713. void
  714. rtas_configure_bridge(struct pci_dn *pdn)
  715. {
  716. int config_addr;
  717. int rc;
  718. /* Use PE configuration address, if present */
  719. config_addr = pdn->eeh_config_addr;
  720. if (pdn->eeh_pe_config_addr)
  721. config_addr = pdn->eeh_pe_config_addr;
  722. rc = rtas_call(ibm_configure_bridge,3,1, NULL,
  723. config_addr,
  724. BUID_HI(pdn->phb->buid),
  725. BUID_LO(pdn->phb->buid));
  726. if (rc) {
  727. printk (KERN_WARNING "EEH: Unable to configure device bridge (%d) for %s\n",
  728. rc, pdn->node->full_name);
  729. }
  730. }
  731. /* ------------------------------------------------------------- */
  732. /* The code below deals with enabling EEH for devices during the
  733. * early boot sequence. EEH must be enabled before any PCI probing
  734. * can be done.
  735. */
  736. #define EEH_ENABLE 1
  737. struct eeh_early_enable_info {
  738. unsigned int buid_hi;
  739. unsigned int buid_lo;
  740. };
  741. static int get_pe_addr (int config_addr,
  742. struct eeh_early_enable_info *info)
  743. {
  744. unsigned int rets[3];
  745. int ret;
  746. /* Use latest config-addr token on power6 */
  747. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  748. /* Make sure we have a PE in hand */
  749. ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
  750. config_addr, info->buid_hi, info->buid_lo, 1);
  751. if (ret || (rets[0]==0))
  752. return 0;
  753. ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
  754. config_addr, info->buid_hi, info->buid_lo, 0);
  755. if (ret)
  756. return 0;
  757. return rets[0];
  758. }
  759. /* Use older config-addr token on power5 */
  760. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  761. ret = rtas_call (ibm_get_config_addr_info, 4, 2, rets,
  762. config_addr, info->buid_hi, info->buid_lo, 0);
  763. if (ret)
  764. return 0;
  765. return rets[0];
  766. }
  767. return 0;
  768. }
  769. /* Enable eeh for the given device node. */
  770. static void *early_enable_eeh(struct device_node *dn, void *data)
  771. {
  772. unsigned int rets[3];
  773. struct eeh_early_enable_info *info = data;
  774. int ret;
  775. const char *status = of_get_property(dn, "status", NULL);
  776. const u32 *class_code = of_get_property(dn, "class-code", NULL);
  777. const u32 *vendor_id = of_get_property(dn, "vendor-id", NULL);
  778. const u32 *device_id = of_get_property(dn, "device-id", NULL);
  779. const u32 *regs;
  780. int enable;
  781. struct pci_dn *pdn = PCI_DN(dn);
  782. pdn->class_code = 0;
  783. pdn->eeh_mode = 0;
  784. pdn->eeh_check_count = 0;
  785. pdn->eeh_freeze_count = 0;
  786. pdn->eeh_false_positives = 0;
  787. if (status && strcmp(status, "ok") != 0)
  788. return NULL; /* ignore devices with bad status */
  789. /* Ignore bad nodes. */
  790. if (!class_code || !vendor_id || !device_id)
  791. return NULL;
  792. /* There is nothing to check on PCI to ISA bridges */
  793. if (dn->type && !strcmp(dn->type, "isa")) {
  794. pdn->eeh_mode |= EEH_MODE_NOCHECK;
  795. return NULL;
  796. }
  797. pdn->class_code = *class_code;
  798. /*
  799. * Now decide if we are going to "Disable" EEH checking
  800. * for this device. We still run with the EEH hardware active,
  801. * but we won't be checking for ff's. This means a driver
  802. * could return bad data (very bad!), an interrupt handler could
  803. * hang waiting on status bits that won't change, etc.
  804. * But there are a few cases like display devices that make sense.
  805. */
  806. enable = 1; /* i.e. we will do checking */
  807. #if 0
  808. if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
  809. enable = 0;
  810. #endif
  811. if (!enable)
  812. pdn->eeh_mode |= EEH_MODE_NOCHECK;
  813. /* Ok... see if this device supports EEH. Some do, some don't,
  814. * and the only way to find out is to check each and every one. */
  815. regs = of_get_property(dn, "reg", NULL);
  816. if (regs) {
  817. /* First register entry is addr (00BBSS00) */
  818. /* Try to enable eeh */
  819. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  820. regs[0], info->buid_hi, info->buid_lo,
  821. EEH_ENABLE);
  822. enable = 0;
  823. if (ret == 0) {
  824. pdn->eeh_config_addr = regs[0];
  825. /* If the newer, better, ibm,get-config-addr-info is supported,
  826. * then use that instead. */
  827. pdn->eeh_pe_config_addr = get_pe_addr(pdn->eeh_config_addr, info);
  828. /* Some older systems (Power4) allow the
  829. * ibm,set-eeh-option call to succeed even on nodes
  830. * where EEH is not supported. Verify support
  831. * explicitly. */
  832. ret = read_slot_reset_state(pdn, rets);
  833. if ((ret == 0) && (rets[1] == 1))
  834. enable = 1;
  835. }
  836. if (enable) {
  837. eeh_subsystem_enabled = 1;
  838. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  839. #ifdef DEBUG
  840. printk(KERN_DEBUG "EEH: %s: eeh enabled, config=%x pe_config=%x\n",
  841. dn->full_name, pdn->eeh_config_addr, pdn->eeh_pe_config_addr);
  842. #endif
  843. } else {
  844. /* This device doesn't support EEH, but it may have an
  845. * EEH parent, in which case we mark it as supported. */
  846. if (dn->parent && PCI_DN(dn->parent)
  847. && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
  848. /* Parent supports EEH. */
  849. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  850. pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
  851. return NULL;
  852. }
  853. }
  854. } else {
  855. printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
  856. dn->full_name);
  857. }
  858. eeh_save_bars(pdn);
  859. return NULL;
  860. }
  861. /*
  862. * Initialize EEH by trying to enable it for all of the adapters in the system.
  863. * As a side effect we can determine here if eeh is supported at all.
  864. * Note that we leave EEH on so failed config cycles won't cause a machine
  865. * check. If a user turns off EEH for a particular adapter they are really
  866. * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
  867. * grant access to a slot if EEH isn't enabled, and so we always enable
  868. * EEH for all slots/all devices.
  869. *
  870. * The eeh-force-off option disables EEH checking globally, for all slots.
  871. * Even if force-off is set, the EEH hardware is still enabled, so that
  872. * newer systems can boot.
  873. */
  874. void __init eeh_init(void)
  875. {
  876. struct device_node *phb, *np;
  877. struct eeh_early_enable_info info;
  878. spin_lock_init(&confirm_error_lock);
  879. spin_lock_init(&slot_errbuf_lock);
  880. np = of_find_node_by_path("/rtas");
  881. if (np == NULL)
  882. return;
  883. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  884. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  885. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  886. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  887. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  888. ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
  889. ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
  890. ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
  891. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
  892. return;
  893. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  894. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  895. eeh_error_buf_size = 1024;
  896. }
  897. if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  898. printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
  899. "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  900. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  901. }
  902. /* Enable EEH for all adapters. Note that eeh requires buid's */
  903. for (phb = of_find_node_by_name(NULL, "pci"); phb;
  904. phb = of_find_node_by_name(phb, "pci")) {
  905. unsigned long buid;
  906. buid = get_phb_buid(phb);
  907. if (buid == 0 || PCI_DN(phb) == NULL)
  908. continue;
  909. info.buid_lo = BUID_LO(buid);
  910. info.buid_hi = BUID_HI(buid);
  911. traverse_pci_devices(phb, early_enable_eeh, &info);
  912. }
  913. if (eeh_subsystem_enabled)
  914. printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
  915. else
  916. printk(KERN_WARNING "EEH: No capable adapters found\n");
  917. }
  918. /**
  919. * eeh_add_device_early - enable EEH for the indicated device_node
  920. * @dn: device node for which to set up EEH
  921. *
  922. * This routine must be used to perform EEH initialization for PCI
  923. * devices that were added after system boot (e.g. hotplug, dlpar).
  924. * This routine must be called before any i/o is performed to the
  925. * adapter (inluding any config-space i/o).
  926. * Whether this actually enables EEH or not for this device depends
  927. * on the CEC architecture, type of the device, on earlier boot
  928. * command-line arguments & etc.
  929. */
  930. static void eeh_add_device_early(struct device_node *dn)
  931. {
  932. struct pci_controller *phb;
  933. struct eeh_early_enable_info info;
  934. if (!dn || !PCI_DN(dn))
  935. return;
  936. phb = PCI_DN(dn)->phb;
  937. /* USB Bus children of PCI devices will not have BUID's */
  938. if (NULL == phb || 0 == phb->buid)
  939. return;
  940. info.buid_hi = BUID_HI(phb->buid);
  941. info.buid_lo = BUID_LO(phb->buid);
  942. early_enable_eeh(dn, &info);
  943. }
  944. void eeh_add_device_tree_early(struct device_node *dn)
  945. {
  946. struct device_node *sib;
  947. for (sib = dn->child; sib; sib = sib->sibling)
  948. eeh_add_device_tree_early(sib);
  949. eeh_add_device_early(dn);
  950. }
  951. EXPORT_SYMBOL_GPL(eeh_add_device_tree_early);
  952. /**
  953. * eeh_add_device_late - perform EEH initialization for the indicated pci device
  954. * @dev: pci device for which to set up EEH
  955. *
  956. * This routine must be used to complete EEH initialization for PCI
  957. * devices that were added after system boot (e.g. hotplug, dlpar).
  958. */
  959. static void eeh_add_device_late(struct pci_dev *dev)
  960. {
  961. struct device_node *dn;
  962. struct pci_dn *pdn;
  963. if (!dev || !eeh_subsystem_enabled)
  964. return;
  965. #ifdef DEBUG
  966. printk(KERN_DEBUG "EEH: adding device %s\n", pci_name(dev));
  967. #endif
  968. pci_dev_get (dev);
  969. dn = pci_device_to_OF_node(dev);
  970. pdn = PCI_DN(dn);
  971. pdn->pcidev = dev;
  972. pci_addr_cache_insert_device(dev);
  973. eeh_sysfs_add_device(dev);
  974. }
  975. void eeh_add_device_tree_late(struct pci_bus *bus)
  976. {
  977. struct pci_dev *dev;
  978. list_for_each_entry(dev, &bus->devices, bus_list) {
  979. eeh_add_device_late(dev);
  980. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  981. struct pci_bus *subbus = dev->subordinate;
  982. if (subbus)
  983. eeh_add_device_tree_late(subbus);
  984. }
  985. }
  986. }
  987. EXPORT_SYMBOL_GPL(eeh_add_device_tree_late);
  988. /**
  989. * eeh_remove_device - undo EEH setup for the indicated pci device
  990. * @dev: pci device to be removed
  991. *
  992. * This routine should be called when a device is removed from
  993. * a running system (e.g. by hotplug or dlpar). It unregisters
  994. * the PCI device from the EEH subsystem. I/O errors affecting
  995. * this device will no longer be detected after this call; thus,
  996. * i/o errors affecting this slot may leave this device unusable.
  997. */
  998. static void eeh_remove_device(struct pci_dev *dev)
  999. {
  1000. struct device_node *dn;
  1001. if (!dev || !eeh_subsystem_enabled)
  1002. return;
  1003. /* Unregister the device with the EEH/PCI address search system */
  1004. #ifdef DEBUG
  1005. printk(KERN_DEBUG "EEH: remove device %s\n", pci_name(dev));
  1006. #endif
  1007. pci_addr_cache_remove_device(dev);
  1008. eeh_sysfs_remove_device(dev);
  1009. dn = pci_device_to_OF_node(dev);
  1010. if (PCI_DN(dn)->pcidev) {
  1011. PCI_DN(dn)->pcidev = NULL;
  1012. pci_dev_put (dev);
  1013. }
  1014. }
  1015. void eeh_remove_bus_device(struct pci_dev *dev)
  1016. {
  1017. struct pci_bus *bus = dev->subordinate;
  1018. struct pci_dev *child, *tmp;
  1019. eeh_remove_device(dev);
  1020. if (bus && dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  1021. list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
  1022. eeh_remove_bus_device(child);
  1023. }
  1024. }
  1025. EXPORT_SYMBOL_GPL(eeh_remove_bus_device);
  1026. static int proc_eeh_show(struct seq_file *m, void *v)
  1027. {
  1028. if (0 == eeh_subsystem_enabled) {
  1029. seq_printf(m, "EEH Subsystem is globally disabled\n");
  1030. seq_printf(m, "eeh_total_mmio_ffs=%ld\n", total_mmio_ffs);
  1031. } else {
  1032. seq_printf(m, "EEH Subsystem is enabled\n");
  1033. seq_printf(m,
  1034. "no device=%ld\n"
  1035. "no device node=%ld\n"
  1036. "no config address=%ld\n"
  1037. "check not wanted=%ld\n"
  1038. "eeh_total_mmio_ffs=%ld\n"
  1039. "eeh_false_positives=%ld\n"
  1040. "eeh_slot_resets=%ld\n",
  1041. no_device, no_dn, no_cfg_addr,
  1042. ignored_check, total_mmio_ffs,
  1043. false_positives,
  1044. slot_resets);
  1045. }
  1046. return 0;
  1047. }
  1048. static int proc_eeh_open(struct inode *inode, struct file *file)
  1049. {
  1050. return single_open(file, proc_eeh_show, NULL);
  1051. }
  1052. static const struct file_operations proc_eeh_operations = {
  1053. .open = proc_eeh_open,
  1054. .read = seq_read,
  1055. .llseek = seq_lseek,
  1056. .release = single_release,
  1057. };
  1058. static int __init eeh_init_proc(void)
  1059. {
  1060. struct proc_dir_entry *e;
  1061. if (machine_is(pseries)) {
  1062. e = create_proc_entry("ppc64/eeh", 0, NULL);
  1063. if (e)
  1064. e->proc_fops = &proc_eeh_operations;
  1065. }
  1066. return 0;
  1067. }
  1068. __initcall(eeh_init_proc);