eeh.c 36 KB

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