eeh.c 35 KB

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