eeh_driver.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * PCI Error Recovery Driver for RPA-compliant PPC64 platform.
  3. * Copyright IBM Corp. 2004 2005
  4. * Copyright Linas Vepstas <linas@linas.org> 2004, 2005
  5. *
  6. * All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  16. * NON INFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. * Send comments and feedback to Linas Vepstas <linas@austin.ibm.com>
  24. */
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/module.h>
  29. #include <linux/pci.h>
  30. #include <asm/eeh.h>
  31. #include <asm/eeh_event.h>
  32. #include <asm/ppc-pci.h>
  33. #include <asm/pci-bridge.h>
  34. #include <asm/prom.h>
  35. #include <asm/rtas.h>
  36. /**
  37. * eeh_pcid_name - Retrieve name of PCI device driver
  38. * @pdev: PCI device
  39. *
  40. * This routine is used to retrieve the name of PCI device driver
  41. * if that's valid.
  42. */
  43. static inline const char *eeh_pcid_name(struct pci_dev *pdev)
  44. {
  45. if (pdev && pdev->dev.driver)
  46. return pdev->dev.driver->name;
  47. return "";
  48. }
  49. /**
  50. * eeh_pcid_get - Get the PCI device driver
  51. * @pdev: PCI device
  52. *
  53. * The function is used to retrieve the PCI device driver for
  54. * the indicated PCI device. Besides, we will increase the reference
  55. * of the PCI device driver to prevent that being unloaded on
  56. * the fly. Otherwise, kernel crash would be seen.
  57. */
  58. static inline struct pci_driver *eeh_pcid_get(struct pci_dev *pdev)
  59. {
  60. if (!pdev || !pdev->driver)
  61. return NULL;
  62. if (!try_module_get(pdev->driver->driver.owner))
  63. return NULL;
  64. return pdev->driver;
  65. }
  66. /**
  67. * eeh_pcid_put - Dereference on the PCI device driver
  68. * @pdev: PCI device
  69. *
  70. * The function is called to do dereference on the PCI device
  71. * driver of the indicated PCI device.
  72. */
  73. static inline void eeh_pcid_put(struct pci_dev *pdev)
  74. {
  75. if (!pdev || !pdev->driver)
  76. return;
  77. module_put(pdev->driver->driver.owner);
  78. }
  79. #if 0
  80. static void print_device_node_tree(struct pci_dn *pdn, int dent)
  81. {
  82. int i;
  83. struct device_node *pc;
  84. if (!pdn)
  85. return;
  86. for (i = 0; i < dent; i++)
  87. printk(" ");
  88. printk("dn=%s mode=%x \tcfg_addr=%x pe_addr=%x \tfull=%s\n",
  89. pdn->node->name, pdn->eeh_mode, pdn->eeh_config_addr,
  90. pdn->eeh_pe_config_addr, pdn->node->full_name);
  91. dent += 3;
  92. pc = pdn->node->child;
  93. while (pc) {
  94. print_device_node_tree(PCI_DN(pc), dent);
  95. pc = pc->sibling;
  96. }
  97. }
  98. #endif
  99. /**
  100. * eeh_disable_irq - Disable interrupt for the recovering device
  101. * @dev: PCI device
  102. *
  103. * This routine must be called when reporting temporary or permanent
  104. * error to the particular PCI device to disable interrupt of that
  105. * device. If the device has enabled MSI or MSI-X interrupt, we needn't
  106. * do real work because EEH should freeze DMA transfers for those PCI
  107. * devices encountering EEH errors, which includes MSI or MSI-X.
  108. */
  109. static void eeh_disable_irq(struct pci_dev *dev)
  110. {
  111. struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
  112. /* Don't disable MSI and MSI-X interrupts. They are
  113. * effectively disabled by the DMA Stopped state
  114. * when an EEH error occurs.
  115. */
  116. if (dev->msi_enabled || dev->msix_enabled)
  117. return;
  118. if (!irq_has_action(dev->irq))
  119. return;
  120. edev->mode |= EEH_DEV_IRQ_DISABLED;
  121. disable_irq_nosync(dev->irq);
  122. }
  123. /**
  124. * eeh_enable_irq - Enable interrupt for the recovering device
  125. * @dev: PCI device
  126. *
  127. * This routine must be called to enable interrupt while failed
  128. * device could be resumed.
  129. */
  130. static void eeh_enable_irq(struct pci_dev *dev)
  131. {
  132. struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
  133. if ((edev->mode) & EEH_DEV_IRQ_DISABLED) {
  134. edev->mode &= ~EEH_DEV_IRQ_DISABLED;
  135. /*
  136. * FIXME !!!!!
  137. *
  138. * This is just ass backwards. This maze has
  139. * unbalanced irq_enable/disable calls. So instead of
  140. * finding the root cause it works around the warning
  141. * in the irq_enable code by conditionally calling
  142. * into it.
  143. *
  144. * That's just wrong.The warning in the core code is
  145. * there to tell people to fix their assymetries in
  146. * their own code, not by abusing the core information
  147. * to avoid it.
  148. *
  149. * I so wish that the assymetry would be the other way
  150. * round and a few more irq_disable calls render that
  151. * shit unusable forever.
  152. *
  153. * tglx
  154. */
  155. if (irqd_irq_disabled(irq_get_irq_data(dev->irq)))
  156. enable_irq(dev->irq);
  157. }
  158. }
  159. /**
  160. * eeh_report_error - Report pci error to each device driver
  161. * @data: eeh device
  162. * @userdata: return value
  163. *
  164. * Report an EEH error to each device driver, collect up and
  165. * merge the device driver responses. Cumulative response
  166. * passed back in "userdata".
  167. */
  168. static void *eeh_report_error(void *data, void *userdata)
  169. {
  170. struct eeh_dev *edev = (struct eeh_dev *)data;
  171. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  172. enum pci_ers_result rc, *res = userdata;
  173. struct pci_driver *driver;
  174. /* We might not have the associated PCI device,
  175. * then we should continue for next one.
  176. */
  177. if (!dev) return NULL;
  178. dev->error_state = pci_channel_io_frozen;
  179. driver = eeh_pcid_get(dev);
  180. if (!driver) return NULL;
  181. eeh_disable_irq(dev);
  182. if (!driver->err_handler ||
  183. !driver->err_handler->error_detected) {
  184. eeh_pcid_put(dev);
  185. return NULL;
  186. }
  187. rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
  188. /* A driver that needs a reset trumps all others */
  189. if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  190. if (*res == PCI_ERS_RESULT_NONE) *res = rc;
  191. eeh_pcid_put(dev);
  192. return NULL;
  193. }
  194. /**
  195. * eeh_report_mmio_enabled - Tell drivers that MMIO has been enabled
  196. * @data: eeh device
  197. * @userdata: return value
  198. *
  199. * Tells each device driver that IO ports, MMIO and config space I/O
  200. * are now enabled. Collects up and merges the device driver responses.
  201. * Cumulative response passed back in "userdata".
  202. */
  203. static void *eeh_report_mmio_enabled(void *data, void *userdata)
  204. {
  205. struct eeh_dev *edev = (struct eeh_dev *)data;
  206. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  207. enum pci_ers_result rc, *res = userdata;
  208. struct pci_driver *driver;
  209. driver = eeh_pcid_get(dev);
  210. if (!driver) return NULL;
  211. if (!driver->err_handler ||
  212. !driver->err_handler->mmio_enabled ||
  213. (edev->mode & EEH_DEV_NO_HANDLER)) {
  214. eeh_pcid_put(dev);
  215. return NULL;
  216. }
  217. rc = driver->err_handler->mmio_enabled(dev);
  218. /* A driver that needs a reset trumps all others */
  219. if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  220. if (*res == PCI_ERS_RESULT_NONE) *res = rc;
  221. eeh_pcid_put(dev);
  222. return NULL;
  223. }
  224. /**
  225. * eeh_report_reset - Tell device that slot has been reset
  226. * @data: eeh device
  227. * @userdata: return value
  228. *
  229. * This routine must be called while EEH tries to reset particular
  230. * PCI device so that the associated PCI device driver could take
  231. * some actions, usually to save data the driver needs so that the
  232. * driver can work again while the device is recovered.
  233. */
  234. static void *eeh_report_reset(void *data, void *userdata)
  235. {
  236. struct eeh_dev *edev = (struct eeh_dev *)data;
  237. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  238. enum pci_ers_result rc, *res = userdata;
  239. struct pci_driver *driver;
  240. if (!dev) return NULL;
  241. dev->error_state = pci_channel_io_normal;
  242. driver = eeh_pcid_get(dev);
  243. if (!driver) return NULL;
  244. eeh_enable_irq(dev);
  245. if (!driver->err_handler ||
  246. !driver->err_handler->slot_reset ||
  247. (edev->mode & EEH_DEV_NO_HANDLER)) {
  248. eeh_pcid_put(dev);
  249. return NULL;
  250. }
  251. rc = driver->err_handler->slot_reset(dev);
  252. if ((*res == PCI_ERS_RESULT_NONE) ||
  253. (*res == PCI_ERS_RESULT_RECOVERED)) *res = rc;
  254. if (*res == PCI_ERS_RESULT_DISCONNECT &&
  255. rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  256. eeh_pcid_put(dev);
  257. return NULL;
  258. }
  259. /**
  260. * eeh_report_resume - Tell device to resume normal operations
  261. * @data: eeh device
  262. * @userdata: return value
  263. *
  264. * This routine must be called to notify the device driver that it
  265. * could resume so that the device driver can do some initialization
  266. * to make the recovered device work again.
  267. */
  268. static void *eeh_report_resume(void *data, void *userdata)
  269. {
  270. struct eeh_dev *edev = (struct eeh_dev *)data;
  271. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  272. struct pci_driver *driver;
  273. if (!dev) return NULL;
  274. dev->error_state = pci_channel_io_normal;
  275. driver = eeh_pcid_get(dev);
  276. if (!driver) return NULL;
  277. eeh_enable_irq(dev);
  278. if (!driver->err_handler ||
  279. !driver->err_handler->resume ||
  280. (edev->mode & EEH_DEV_NO_HANDLER)) {
  281. edev->mode &= ~EEH_DEV_NO_HANDLER;
  282. eeh_pcid_put(dev);
  283. return NULL;
  284. }
  285. driver->err_handler->resume(dev);
  286. eeh_pcid_put(dev);
  287. return NULL;
  288. }
  289. /**
  290. * eeh_report_failure - Tell device driver that device is dead.
  291. * @data: eeh device
  292. * @userdata: return value
  293. *
  294. * This informs the device driver that the device is permanently
  295. * dead, and that no further recovery attempts will be made on it.
  296. */
  297. static void *eeh_report_failure(void *data, void *userdata)
  298. {
  299. struct eeh_dev *edev = (struct eeh_dev *)data;
  300. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  301. struct pci_driver *driver;
  302. if (!dev) return NULL;
  303. dev->error_state = pci_channel_io_perm_failure;
  304. driver = eeh_pcid_get(dev);
  305. if (!driver) return NULL;
  306. eeh_disable_irq(dev);
  307. if (!driver->err_handler ||
  308. !driver->err_handler->error_detected) {
  309. eeh_pcid_put(dev);
  310. return NULL;
  311. }
  312. driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
  313. eeh_pcid_put(dev);
  314. return NULL;
  315. }
  316. static void *eeh_rmv_device(void *data, void *userdata)
  317. {
  318. struct pci_driver *driver;
  319. struct eeh_dev *edev = (struct eeh_dev *)data;
  320. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  321. int *removed = (int *)userdata;
  322. /*
  323. * Actually, we should remove the PCI bridges as well.
  324. * However, that's lots of complexity to do that,
  325. * particularly some of devices under the bridge might
  326. * support EEH. So we just care about PCI devices for
  327. * simplicity here.
  328. */
  329. if (!dev || (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE))
  330. return NULL;
  331. driver = eeh_pcid_get(dev);
  332. if (driver) {
  333. eeh_pcid_put(dev);
  334. if (driver->err_handler)
  335. return NULL;
  336. }
  337. /* Remove it from PCI subsystem */
  338. pr_debug("EEH: Removing %s without EEH sensitive driver\n",
  339. pci_name(dev));
  340. edev->bus = dev->bus;
  341. edev->mode |= EEH_DEV_DISCONNECTED;
  342. (*removed)++;
  343. pci_lock_rescan_remove();
  344. pci_stop_and_remove_bus_device(dev);
  345. pci_unlock_rescan_remove();
  346. return NULL;
  347. }
  348. static void *eeh_pe_detach_dev(void *data, void *userdata)
  349. {
  350. struct eeh_pe *pe = (struct eeh_pe *)data;
  351. struct eeh_dev *edev, *tmp;
  352. eeh_pe_for_each_dev(pe, edev, tmp) {
  353. if (!(edev->mode & EEH_DEV_DISCONNECTED))
  354. continue;
  355. edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
  356. eeh_rmv_from_parent_pe(edev);
  357. }
  358. return NULL;
  359. }
  360. /**
  361. * eeh_reset_device - Perform actual reset of a pci slot
  362. * @pe: EEH PE
  363. * @bus: PCI bus corresponding to the isolcated slot
  364. *
  365. * This routine must be called to do reset on the indicated PE.
  366. * During the reset, udev might be invoked because those affected
  367. * PCI devices will be removed and then added.
  368. */
  369. static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
  370. {
  371. struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
  372. struct timeval tstamp;
  373. int cnt, rc, removed = 0;
  374. /* pcibios will clear the counter; save the value */
  375. cnt = pe->freeze_count;
  376. tstamp = pe->tstamp;
  377. /*
  378. * We don't remove the corresponding PE instances because
  379. * we need the information afterwords. The attached EEH
  380. * devices are expected to be attached soon when calling
  381. * into pcibios_add_pci_devices().
  382. */
  383. eeh_pe_state_mark(pe, EEH_PE_KEEP);
  384. if (bus) {
  385. pci_lock_rescan_remove();
  386. pcibios_remove_pci_devices(bus);
  387. pci_unlock_rescan_remove();
  388. } else if (frozen_bus) {
  389. eeh_pe_dev_traverse(pe, eeh_rmv_device, &removed);
  390. }
  391. /* Reset the pci controller. (Asserts RST#; resets config space).
  392. * Reconfigure bridges and devices. Don't try to bring the system
  393. * up if the reset failed for some reason.
  394. */
  395. rc = eeh_reset_pe(pe);
  396. if (rc)
  397. return rc;
  398. pci_lock_rescan_remove();
  399. /* Restore PE */
  400. eeh_ops->configure_bridge(pe);
  401. eeh_pe_restore_bars(pe);
  402. /* Give the system 5 seconds to finish running the user-space
  403. * hotplug shutdown scripts, e.g. ifdown for ethernet. Yes,
  404. * this is a hack, but if we don't do this, and try to bring
  405. * the device up before the scripts have taken it down,
  406. * potentially weird things happen.
  407. */
  408. if (bus) {
  409. pr_info("EEH: Sleep 5s ahead of complete hotplug\n");
  410. ssleep(5);
  411. /*
  412. * The EEH device is still connected with its parent
  413. * PE. We should disconnect it so the binding can be
  414. * rebuilt when adding PCI devices.
  415. */
  416. eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
  417. pcibios_add_pci_devices(bus);
  418. } else if (frozen_bus && removed) {
  419. pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
  420. ssleep(5);
  421. eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
  422. pcibios_add_pci_devices(frozen_bus);
  423. }
  424. eeh_pe_state_clear(pe, EEH_PE_KEEP);
  425. pe->tstamp = tstamp;
  426. pe->freeze_count = cnt;
  427. pci_unlock_rescan_remove();
  428. return 0;
  429. }
  430. /* The longest amount of time to wait for a pci device
  431. * to come back on line, in seconds.
  432. */
  433. #define MAX_WAIT_FOR_RECOVERY 300
  434. static void eeh_handle_normal_event(struct eeh_pe *pe)
  435. {
  436. struct pci_bus *frozen_bus;
  437. int rc = 0;
  438. enum pci_ers_result result = PCI_ERS_RESULT_NONE;
  439. frozen_bus = eeh_pe_bus_get(pe);
  440. if (!frozen_bus) {
  441. pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n",
  442. __func__, pe->phb->global_number, pe->addr);
  443. return;
  444. }
  445. eeh_pe_update_time_stamp(pe);
  446. pe->freeze_count++;
  447. if (pe->freeze_count > EEH_MAX_ALLOWED_FREEZES)
  448. goto excess_failures;
  449. pr_warning("EEH: This PCI device has failed %d times in the last hour\n",
  450. pe->freeze_count);
  451. /* Walk the various device drivers attached to this slot through
  452. * a reset sequence, giving each an opportunity to do what it needs
  453. * to accomplish the reset. Each child gets a report of the
  454. * status ... if any child can't handle the reset, then the entire
  455. * slot is dlpar removed and added.
  456. */
  457. pr_info("EEH: Notify device drivers to shutdown\n");
  458. eeh_pe_dev_traverse(pe, eeh_report_error, &result);
  459. /* Get the current PCI slot state. This can take a long time,
  460. * sometimes over 3 seconds for certain systems.
  461. */
  462. rc = eeh_ops->wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
  463. if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
  464. pr_warning("EEH: Permanent failure\n");
  465. goto hard_fail;
  466. }
  467. /* Since rtas may enable MMIO when posting the error log,
  468. * don't post the error log until after all dev drivers
  469. * have been informed.
  470. */
  471. pr_info("EEH: Collect temporary log\n");
  472. eeh_slot_error_detail(pe, EEH_LOG_TEMP);
  473. /* If all device drivers were EEH-unaware, then shut
  474. * down all of the device drivers, and hope they
  475. * go down willingly, without panicing the system.
  476. */
  477. if (result == PCI_ERS_RESULT_NONE) {
  478. pr_info("EEH: Reset with hotplug activity\n");
  479. rc = eeh_reset_device(pe, frozen_bus);
  480. if (rc) {
  481. pr_warning("%s: Unable to reset, err=%d\n",
  482. __func__, rc);
  483. goto hard_fail;
  484. }
  485. }
  486. /* If all devices reported they can proceed, then re-enable MMIO */
  487. if (result == PCI_ERS_RESULT_CAN_RECOVER) {
  488. pr_info("EEH: Enable I/O for affected devices\n");
  489. rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
  490. if (rc < 0)
  491. goto hard_fail;
  492. if (rc) {
  493. result = PCI_ERS_RESULT_NEED_RESET;
  494. } else {
  495. pr_info("EEH: Notify device drivers to resume I/O\n");
  496. result = PCI_ERS_RESULT_NONE;
  497. eeh_pe_dev_traverse(pe, eeh_report_mmio_enabled, &result);
  498. }
  499. }
  500. /* If all devices reported they can proceed, then re-enable DMA */
  501. if (result == PCI_ERS_RESULT_CAN_RECOVER) {
  502. pr_info("EEH: Enabled DMA for affected devices\n");
  503. rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
  504. if (rc < 0)
  505. goto hard_fail;
  506. if (rc)
  507. result = PCI_ERS_RESULT_NEED_RESET;
  508. else
  509. result = PCI_ERS_RESULT_RECOVERED;
  510. }
  511. /* If any device has a hard failure, then shut off everything. */
  512. if (result == PCI_ERS_RESULT_DISCONNECT) {
  513. pr_warning("EEH: Device driver gave up\n");
  514. goto hard_fail;
  515. }
  516. /* If any device called out for a reset, then reset the slot */
  517. if (result == PCI_ERS_RESULT_NEED_RESET) {
  518. pr_info("EEH: Reset without hotplug activity\n");
  519. rc = eeh_reset_device(pe, NULL);
  520. if (rc) {
  521. pr_warning("%s: Cannot reset, err=%d\n",
  522. __func__, rc);
  523. goto hard_fail;
  524. }
  525. pr_info("EEH: Notify device drivers "
  526. "the completion of reset\n");
  527. result = PCI_ERS_RESULT_NONE;
  528. eeh_pe_dev_traverse(pe, eeh_report_reset, &result);
  529. }
  530. /* All devices should claim they have recovered by now. */
  531. if ((result != PCI_ERS_RESULT_RECOVERED) &&
  532. (result != PCI_ERS_RESULT_NONE)) {
  533. pr_warning("EEH: Not recovered\n");
  534. goto hard_fail;
  535. }
  536. /* Tell all device drivers that they can resume operations */
  537. pr_info("EEH: Notify device driver to resume\n");
  538. eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
  539. return;
  540. excess_failures:
  541. /*
  542. * About 90% of all real-life EEH failures in the field
  543. * are due to poorly seated PCI cards. Only 10% or so are
  544. * due to actual, failed cards.
  545. */
  546. pr_err("EEH: PHB#%d-PE#%x has failed %d times in the\n"
  547. "last hour and has been permanently disabled.\n"
  548. "Please try reseating or replacing it.\n",
  549. pe->phb->global_number, pe->addr,
  550. pe->freeze_count);
  551. goto perm_error;
  552. hard_fail:
  553. pr_err("EEH: Unable to recover from failure from PHB#%d-PE#%x.\n"
  554. "Please try reseating or replacing it\n",
  555. pe->phb->global_number, pe->addr);
  556. perm_error:
  557. eeh_slot_error_detail(pe, EEH_LOG_PERM);
  558. /* Notify all devices that they're about to go down. */
  559. eeh_pe_dev_traverse(pe, eeh_report_failure, NULL);
  560. /* Shut down the device drivers for good. */
  561. if (frozen_bus) {
  562. pci_lock_rescan_remove();
  563. pcibios_remove_pci_devices(frozen_bus);
  564. pci_unlock_rescan_remove();
  565. }
  566. }
  567. static void eeh_handle_special_event(void)
  568. {
  569. struct eeh_pe *pe, *phb_pe;
  570. struct pci_bus *bus;
  571. struct pci_controller *hose;
  572. unsigned long flags;
  573. int rc;
  574. do {
  575. rc = eeh_ops->next_error(&pe);
  576. switch (rc) {
  577. case EEH_NEXT_ERR_DEAD_IOC:
  578. /* Mark all PHBs in dead state */
  579. eeh_serialize_lock(&flags);
  580. /* Purge all events */
  581. eeh_remove_event(NULL);
  582. list_for_each_entry(hose, &hose_list, list_node) {
  583. phb_pe = eeh_phb_pe_get(hose);
  584. if (!phb_pe) continue;
  585. eeh_pe_state_mark(phb_pe,
  586. EEH_PE_ISOLATED | EEH_PE_PHB_DEAD);
  587. }
  588. eeh_serialize_unlock(flags);
  589. break;
  590. case EEH_NEXT_ERR_FROZEN_PE:
  591. case EEH_NEXT_ERR_FENCED_PHB:
  592. case EEH_NEXT_ERR_DEAD_PHB:
  593. /* Mark the PE in fenced state */
  594. eeh_serialize_lock(&flags);
  595. /* Purge all events of the PHB */
  596. eeh_remove_event(pe);
  597. if (rc == EEH_NEXT_ERR_DEAD_PHB)
  598. eeh_pe_state_mark(pe,
  599. EEH_PE_ISOLATED | EEH_PE_PHB_DEAD);
  600. else
  601. eeh_pe_state_mark(pe,
  602. EEH_PE_ISOLATED | EEH_PE_RECOVERING);
  603. eeh_serialize_unlock(flags);
  604. break;
  605. case EEH_NEXT_ERR_NONE:
  606. return;
  607. default:
  608. pr_warn("%s: Invalid value %d from next_error()\n",
  609. __func__, rc);
  610. return;
  611. }
  612. /*
  613. * For fenced PHB and frozen PE, it's handled as normal
  614. * event. We have to remove the affected PHBs for dead
  615. * PHB and IOC
  616. */
  617. if (rc == EEH_NEXT_ERR_FROZEN_PE ||
  618. rc == EEH_NEXT_ERR_FENCED_PHB) {
  619. eeh_handle_normal_event(pe);
  620. } else {
  621. pci_lock_rescan_remove();
  622. list_for_each_entry(hose, &hose_list, list_node) {
  623. phb_pe = eeh_phb_pe_get(hose);
  624. if (!phb_pe ||
  625. !(phb_pe->state & EEH_PE_PHB_DEAD))
  626. continue;
  627. /* Notify all devices to be down */
  628. bus = eeh_pe_bus_get(phb_pe);
  629. eeh_pe_dev_traverse(pe,
  630. eeh_report_failure, NULL);
  631. pcibios_remove_pci_devices(bus);
  632. }
  633. pci_unlock_rescan_remove();
  634. }
  635. /*
  636. * If we have detected dead IOC, we needn't proceed
  637. * any more since all PHBs would have been removed
  638. */
  639. if (rc == EEH_NEXT_ERR_DEAD_IOC)
  640. break;
  641. } while (rc != EEH_NEXT_ERR_NONE);
  642. }
  643. /**
  644. * eeh_handle_event - Reset a PCI device after hard lockup.
  645. * @pe: EEH PE
  646. *
  647. * While PHB detects address or data parity errors on particular PCI
  648. * slot, the associated PE will be frozen. Besides, DMA's occurring
  649. * to wild addresses (which usually happen due to bugs in device
  650. * drivers or in PCI adapter firmware) can cause EEH error. #SERR,
  651. * #PERR or other misc PCI-related errors also can trigger EEH errors.
  652. *
  653. * Recovery process consists of unplugging the device driver (which
  654. * generated hotplug events to userspace), then issuing a PCI #RST to
  655. * the device, then reconfiguring the PCI config space for all bridges
  656. * & devices under this slot, and then finally restarting the device
  657. * drivers (which cause a second set of hotplug events to go out to
  658. * userspace).
  659. */
  660. void eeh_handle_event(struct eeh_pe *pe)
  661. {
  662. if (pe)
  663. eeh_handle_normal_event(pe);
  664. else
  665. eeh_handle_special_event();
  666. }