eeh.c 36 KB

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