eeh.c 36 KB

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