eeh.c 36 KB

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