eeh_driver.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. static bool eeh_dev_removed(struct eeh_dev *edev)
  160. {
  161. /* EEH device removed ? */
  162. if (!edev || (edev->mode & EEH_DEV_REMOVED))
  163. return true;
  164. return false;
  165. }
  166. /**
  167. * eeh_report_error - Report pci error to each device driver
  168. * @data: eeh device
  169. * @userdata: return value
  170. *
  171. * Report an EEH error to each device driver, collect up and
  172. * merge the device driver responses. Cumulative response
  173. * passed back in "userdata".
  174. */
  175. static void *eeh_report_error(void *data, void *userdata)
  176. {
  177. struct eeh_dev *edev = (struct eeh_dev *)data;
  178. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  179. enum pci_ers_result rc, *res = userdata;
  180. struct pci_driver *driver;
  181. if (!dev || eeh_dev_removed(edev))
  182. return NULL;
  183. dev->error_state = pci_channel_io_frozen;
  184. driver = eeh_pcid_get(dev);
  185. if (!driver) return NULL;
  186. eeh_disable_irq(dev);
  187. if (!driver->err_handler ||
  188. !driver->err_handler->error_detected) {
  189. eeh_pcid_put(dev);
  190. return NULL;
  191. }
  192. rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
  193. /* A driver that needs a reset trumps all others */
  194. if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  195. if (*res == PCI_ERS_RESULT_NONE) *res = rc;
  196. eeh_pcid_put(dev);
  197. return NULL;
  198. }
  199. /**
  200. * eeh_report_mmio_enabled - Tell drivers that MMIO has been enabled
  201. * @data: eeh device
  202. * @userdata: return value
  203. *
  204. * Tells each device driver that IO ports, MMIO and config space I/O
  205. * are now enabled. Collects up and merges the device driver responses.
  206. * Cumulative response passed back in "userdata".
  207. */
  208. static void *eeh_report_mmio_enabled(void *data, void *userdata)
  209. {
  210. struct eeh_dev *edev = (struct eeh_dev *)data;
  211. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  212. enum pci_ers_result rc, *res = userdata;
  213. struct pci_driver *driver;
  214. if (!dev || eeh_dev_removed(edev))
  215. return NULL;
  216. driver = eeh_pcid_get(dev);
  217. if (!driver) return NULL;
  218. if (!driver->err_handler ||
  219. !driver->err_handler->mmio_enabled ||
  220. (edev->mode & EEH_DEV_NO_HANDLER)) {
  221. eeh_pcid_put(dev);
  222. return NULL;
  223. }
  224. rc = driver->err_handler->mmio_enabled(dev);
  225. /* A driver that needs a reset trumps all others */
  226. if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  227. if (*res == PCI_ERS_RESULT_NONE) *res = rc;
  228. eeh_pcid_put(dev);
  229. return NULL;
  230. }
  231. /**
  232. * eeh_report_reset - Tell device that slot has been reset
  233. * @data: eeh device
  234. * @userdata: return value
  235. *
  236. * This routine must be called while EEH tries to reset particular
  237. * PCI device so that the associated PCI device driver could take
  238. * some actions, usually to save data the driver needs so that the
  239. * driver can work again while the device is recovered.
  240. */
  241. static void *eeh_report_reset(void *data, void *userdata)
  242. {
  243. struct eeh_dev *edev = (struct eeh_dev *)data;
  244. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  245. enum pci_ers_result rc, *res = userdata;
  246. struct pci_driver *driver;
  247. if (!dev || eeh_dev_removed(edev))
  248. return NULL;
  249. dev->error_state = pci_channel_io_normal;
  250. driver = eeh_pcid_get(dev);
  251. if (!driver) return NULL;
  252. eeh_enable_irq(dev);
  253. if (!driver->err_handler ||
  254. !driver->err_handler->slot_reset ||
  255. (edev->mode & EEH_DEV_NO_HANDLER)) {
  256. eeh_pcid_put(dev);
  257. return NULL;
  258. }
  259. rc = driver->err_handler->slot_reset(dev);
  260. if ((*res == PCI_ERS_RESULT_NONE) ||
  261. (*res == PCI_ERS_RESULT_RECOVERED)) *res = rc;
  262. if (*res == PCI_ERS_RESULT_DISCONNECT &&
  263. rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  264. eeh_pcid_put(dev);
  265. return NULL;
  266. }
  267. /**
  268. * eeh_report_resume - Tell device to resume normal operations
  269. * @data: eeh device
  270. * @userdata: return value
  271. *
  272. * This routine must be called to notify the device driver that it
  273. * could resume so that the device driver can do some initialization
  274. * to make the recovered device work again.
  275. */
  276. static void *eeh_report_resume(void *data, void *userdata)
  277. {
  278. struct eeh_dev *edev = (struct eeh_dev *)data;
  279. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  280. struct pci_driver *driver;
  281. if (!dev || eeh_dev_removed(edev))
  282. return NULL;
  283. dev->error_state = pci_channel_io_normal;
  284. driver = eeh_pcid_get(dev);
  285. if (!driver) return NULL;
  286. eeh_enable_irq(dev);
  287. if (!driver->err_handler ||
  288. !driver->err_handler->resume ||
  289. (edev->mode & EEH_DEV_NO_HANDLER)) {
  290. edev->mode &= ~EEH_DEV_NO_HANDLER;
  291. eeh_pcid_put(dev);
  292. return NULL;
  293. }
  294. driver->err_handler->resume(dev);
  295. eeh_pcid_put(dev);
  296. return NULL;
  297. }
  298. /**
  299. * eeh_report_failure - Tell device driver that device is dead.
  300. * @data: eeh device
  301. * @userdata: return value
  302. *
  303. * This informs the device driver that the device is permanently
  304. * dead, and that no further recovery attempts will be made on it.
  305. */
  306. static void *eeh_report_failure(void *data, void *userdata)
  307. {
  308. struct eeh_dev *edev = (struct eeh_dev *)data;
  309. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  310. struct pci_driver *driver;
  311. if (!dev || eeh_dev_removed(edev))
  312. return NULL;
  313. dev->error_state = pci_channel_io_perm_failure;
  314. driver = eeh_pcid_get(dev);
  315. if (!driver) return NULL;
  316. eeh_disable_irq(dev);
  317. if (!driver->err_handler ||
  318. !driver->err_handler->error_detected) {
  319. eeh_pcid_put(dev);
  320. return NULL;
  321. }
  322. driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
  323. eeh_pcid_put(dev);
  324. return NULL;
  325. }
  326. static void *eeh_rmv_device(void *data, void *userdata)
  327. {
  328. struct pci_driver *driver;
  329. struct eeh_dev *edev = (struct eeh_dev *)data;
  330. struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
  331. int *removed = (int *)userdata;
  332. /*
  333. * Actually, we should remove the PCI bridges as well.
  334. * However, that's lots of complexity to do that,
  335. * particularly some of devices under the bridge might
  336. * support EEH. So we just care about PCI devices for
  337. * simplicity here.
  338. */
  339. if (!dev || (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE))
  340. return NULL;
  341. /*
  342. * We rely on count-based pcibios_release_device() to
  343. * detach permanently offlined PEs. Unfortunately, that's
  344. * not reliable enough. We might have the permanently
  345. * offlined PEs attached, but we needn't take care of
  346. * them and their child devices.
  347. */
  348. if (eeh_dev_removed(edev))
  349. return NULL;
  350. driver = eeh_pcid_get(dev);
  351. if (driver) {
  352. eeh_pcid_put(dev);
  353. if (driver->err_handler)
  354. return NULL;
  355. }
  356. /* Remove it from PCI subsystem */
  357. pr_debug("EEH: Removing %s without EEH sensitive driver\n",
  358. pci_name(dev));
  359. edev->bus = dev->bus;
  360. edev->mode |= EEH_DEV_DISCONNECTED;
  361. (*removed)++;
  362. pci_lock_rescan_remove();
  363. pci_stop_and_remove_bus_device(dev);
  364. pci_unlock_rescan_remove();
  365. return NULL;
  366. }
  367. static void *eeh_pe_detach_dev(void *data, void *userdata)
  368. {
  369. struct eeh_pe *pe = (struct eeh_pe *)data;
  370. struct eeh_dev *edev, *tmp;
  371. eeh_pe_for_each_dev(pe, edev, tmp) {
  372. if (!(edev->mode & EEH_DEV_DISCONNECTED))
  373. continue;
  374. edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
  375. eeh_rmv_from_parent_pe(edev);
  376. }
  377. return NULL;
  378. }
  379. /*
  380. * Explicitly clear PE's frozen state for PowerNV where
  381. * we have frozen PE until BAR restore is completed. It's
  382. * harmless to clear it for pSeries. To be consistent with
  383. * PE reset (for 3 times), we try to clear the frozen state
  384. * for 3 times as well.
  385. */
  386. static void *__eeh_clear_pe_frozen_state(void *data, void *flag)
  387. {
  388. struct eeh_pe *pe = (struct eeh_pe *)data;
  389. int i, rc;
  390. for (i = 0; i < 3; i++) {
  391. rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
  392. if (rc)
  393. continue;
  394. rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
  395. if (!rc)
  396. break;
  397. }
  398. /* The PE has been isolated, clear it */
  399. if (rc) {
  400. pr_warn("%s: Can't clear frozen PHB#%x-PE#%x (%d)\n",
  401. __func__, pe->phb->global_number, pe->addr, rc);
  402. return (void *)pe;
  403. }
  404. return NULL;
  405. }
  406. static int eeh_clear_pe_frozen_state(struct eeh_pe *pe)
  407. {
  408. void *rc;
  409. rc = eeh_pe_traverse(pe, __eeh_clear_pe_frozen_state, NULL);
  410. if (!rc)
  411. eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
  412. return rc ? -EIO : 0;
  413. }
  414. /**
  415. * eeh_reset_device - Perform actual reset of a pci slot
  416. * @pe: EEH PE
  417. * @bus: PCI bus corresponding to the isolcated slot
  418. *
  419. * This routine must be called to do reset on the indicated PE.
  420. * During the reset, udev might be invoked because those affected
  421. * PCI devices will be removed and then added.
  422. */
  423. static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
  424. {
  425. struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
  426. struct timeval tstamp;
  427. int cnt, rc, removed = 0;
  428. /* pcibios will clear the counter; save the value */
  429. cnt = pe->freeze_count;
  430. tstamp = pe->tstamp;
  431. /*
  432. * We don't remove the corresponding PE instances because
  433. * we need the information afterwords. The attached EEH
  434. * devices are expected to be attached soon when calling
  435. * into pcibios_add_pci_devices().
  436. */
  437. eeh_pe_state_mark(pe, EEH_PE_KEEP);
  438. if (bus) {
  439. pci_lock_rescan_remove();
  440. pcibios_remove_pci_devices(bus);
  441. pci_unlock_rescan_remove();
  442. } else if (frozen_bus) {
  443. eeh_pe_dev_traverse(pe, eeh_rmv_device, &removed);
  444. }
  445. /*
  446. * Reset the pci controller. (Asserts RST#; resets config space).
  447. * Reconfigure bridges and devices. Don't try to bring the system
  448. * up if the reset failed for some reason.
  449. *
  450. * During the reset, it's very dangerous to have uncontrolled PCI
  451. * config accesses. So we prefer to block them. However, controlled
  452. * PCI config accesses initiated from EEH itself are allowed.
  453. */
  454. eeh_pe_state_mark(pe, EEH_PE_RESET);
  455. rc = eeh_reset_pe(pe);
  456. if (rc) {
  457. eeh_pe_state_clear(pe, EEH_PE_RESET);
  458. return rc;
  459. }
  460. pci_lock_rescan_remove();
  461. /* Restore PE */
  462. eeh_ops->configure_bridge(pe);
  463. eeh_pe_restore_bars(pe);
  464. eeh_pe_state_clear(pe, EEH_PE_RESET);
  465. /* Clear frozen state */
  466. rc = eeh_clear_pe_frozen_state(pe);
  467. if (rc)
  468. return rc;
  469. /* Give the system 5 seconds to finish running the user-space
  470. * hotplug shutdown scripts, e.g. ifdown for ethernet. Yes,
  471. * this is a hack, but if we don't do this, and try to bring
  472. * the device up before the scripts have taken it down,
  473. * potentially weird things happen.
  474. */
  475. if (bus) {
  476. pr_info("EEH: Sleep 5s ahead of complete hotplug\n");
  477. ssleep(5);
  478. /*
  479. * The EEH device is still connected with its parent
  480. * PE. We should disconnect it so the binding can be
  481. * rebuilt when adding PCI devices.
  482. */
  483. eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
  484. pcibios_add_pci_devices(bus);
  485. } else if (frozen_bus && removed) {
  486. pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
  487. ssleep(5);
  488. eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
  489. pcibios_add_pci_devices(frozen_bus);
  490. }
  491. eeh_pe_state_clear(pe, EEH_PE_KEEP);
  492. pe->tstamp = tstamp;
  493. pe->freeze_count = cnt;
  494. pci_unlock_rescan_remove();
  495. return 0;
  496. }
  497. /* The longest amount of time to wait for a pci device
  498. * to come back on line, in seconds.
  499. */
  500. #define MAX_WAIT_FOR_RECOVERY 300
  501. static void eeh_handle_normal_event(struct eeh_pe *pe)
  502. {
  503. struct pci_bus *frozen_bus;
  504. int rc = 0;
  505. enum pci_ers_result result = PCI_ERS_RESULT_NONE;
  506. frozen_bus = eeh_pe_bus_get(pe);
  507. if (!frozen_bus) {
  508. pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n",
  509. __func__, pe->phb->global_number, pe->addr);
  510. return;
  511. }
  512. eeh_pe_update_time_stamp(pe);
  513. pe->freeze_count++;
  514. if (pe->freeze_count > EEH_MAX_ALLOWED_FREEZES)
  515. goto excess_failures;
  516. pr_warning("EEH: This PCI device has failed %d times in the last hour\n",
  517. pe->freeze_count);
  518. /* Walk the various device drivers attached to this slot through
  519. * a reset sequence, giving each an opportunity to do what it needs
  520. * to accomplish the reset. Each child gets a report of the
  521. * status ... if any child can't handle the reset, then the entire
  522. * slot is dlpar removed and added.
  523. */
  524. pr_info("EEH: Notify device drivers to shutdown\n");
  525. eeh_pe_dev_traverse(pe, eeh_report_error, &result);
  526. /* Get the current PCI slot state. This can take a long time,
  527. * sometimes over 3 seconds for certain systems.
  528. */
  529. rc = eeh_ops->wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
  530. if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
  531. pr_warning("EEH: Permanent failure\n");
  532. goto hard_fail;
  533. }
  534. /* Since rtas may enable MMIO when posting the error log,
  535. * don't post the error log until after all dev drivers
  536. * have been informed.
  537. */
  538. pr_info("EEH: Collect temporary log\n");
  539. eeh_slot_error_detail(pe, EEH_LOG_TEMP);
  540. /* If all device drivers were EEH-unaware, then shut
  541. * down all of the device drivers, and hope they
  542. * go down willingly, without panicing the system.
  543. */
  544. if (result == PCI_ERS_RESULT_NONE) {
  545. pr_info("EEH: Reset with hotplug activity\n");
  546. rc = eeh_reset_device(pe, frozen_bus);
  547. if (rc) {
  548. pr_warning("%s: Unable to reset, err=%d\n",
  549. __func__, rc);
  550. goto hard_fail;
  551. }
  552. }
  553. /* If all devices reported they can proceed, then re-enable MMIO */
  554. if (result == PCI_ERS_RESULT_CAN_RECOVER) {
  555. pr_info("EEH: Enable I/O for affected devices\n");
  556. rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
  557. if (rc < 0)
  558. goto hard_fail;
  559. if (rc) {
  560. result = PCI_ERS_RESULT_NEED_RESET;
  561. } else {
  562. pr_info("EEH: Notify device drivers to resume I/O\n");
  563. eeh_pe_dev_traverse(pe, eeh_report_mmio_enabled, &result);
  564. }
  565. }
  566. /* If all devices reported they can proceed, then re-enable DMA */
  567. if (result == PCI_ERS_RESULT_CAN_RECOVER) {
  568. pr_info("EEH: Enabled DMA for affected devices\n");
  569. rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
  570. if (rc < 0)
  571. goto hard_fail;
  572. if (rc) {
  573. result = PCI_ERS_RESULT_NEED_RESET;
  574. } else {
  575. /*
  576. * We didn't do PE reset for the case. The PE
  577. * is still in frozen state. Clear it before
  578. * resuming the PE.
  579. */
  580. eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
  581. result = PCI_ERS_RESULT_RECOVERED;
  582. }
  583. }
  584. /* If any device has a hard failure, then shut off everything. */
  585. if (result == PCI_ERS_RESULT_DISCONNECT) {
  586. pr_warning("EEH: Device driver gave up\n");
  587. goto hard_fail;
  588. }
  589. /* If any device called out for a reset, then reset the slot */
  590. if (result == PCI_ERS_RESULT_NEED_RESET) {
  591. pr_info("EEH: Reset without hotplug activity\n");
  592. rc = eeh_reset_device(pe, NULL);
  593. if (rc) {
  594. pr_warning("%s: Cannot reset, err=%d\n",
  595. __func__, rc);
  596. goto hard_fail;
  597. }
  598. pr_info("EEH: Notify device drivers "
  599. "the completion of reset\n");
  600. result = PCI_ERS_RESULT_NONE;
  601. eeh_pe_dev_traverse(pe, eeh_report_reset, &result);
  602. }
  603. /* All devices should claim they have recovered by now. */
  604. if ((result != PCI_ERS_RESULT_RECOVERED) &&
  605. (result != PCI_ERS_RESULT_NONE)) {
  606. pr_warning("EEH: Not recovered\n");
  607. goto hard_fail;
  608. }
  609. /* Tell all device drivers that they can resume operations */
  610. pr_info("EEH: Notify device driver to resume\n");
  611. eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
  612. return;
  613. excess_failures:
  614. /*
  615. * About 90% of all real-life EEH failures in the field
  616. * are due to poorly seated PCI cards. Only 10% or so are
  617. * due to actual, failed cards.
  618. */
  619. pr_err("EEH: PHB#%d-PE#%x has failed %d times in the\n"
  620. "last hour and has been permanently disabled.\n"
  621. "Please try reseating or replacing it.\n",
  622. pe->phb->global_number, pe->addr,
  623. pe->freeze_count);
  624. goto perm_error;
  625. hard_fail:
  626. pr_err("EEH: Unable to recover from failure from PHB#%d-PE#%x.\n"
  627. "Please try reseating or replacing it\n",
  628. pe->phb->global_number, pe->addr);
  629. perm_error:
  630. eeh_slot_error_detail(pe, EEH_LOG_PERM);
  631. /* Notify all devices that they're about to go down. */
  632. eeh_pe_dev_traverse(pe, eeh_report_failure, NULL);
  633. /* Mark the PE to be removed permanently */
  634. pe->freeze_count = EEH_MAX_ALLOWED_FREEZES + 1;
  635. /*
  636. * Shut down the device drivers for good. We mark
  637. * all removed devices correctly to avoid access
  638. * the their PCI config any more.
  639. */
  640. if (frozen_bus) {
  641. eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
  642. pci_lock_rescan_remove();
  643. pcibios_remove_pci_devices(frozen_bus);
  644. pci_unlock_rescan_remove();
  645. }
  646. }
  647. static void eeh_handle_special_event(void)
  648. {
  649. struct eeh_pe *pe, *phb_pe;
  650. struct pci_bus *bus;
  651. struct pci_controller *hose;
  652. unsigned long flags;
  653. int rc;
  654. do {
  655. rc = eeh_ops->next_error(&pe);
  656. switch (rc) {
  657. case EEH_NEXT_ERR_DEAD_IOC:
  658. /* Mark all PHBs in dead state */
  659. eeh_serialize_lock(&flags);
  660. /* Purge all events */
  661. eeh_remove_event(NULL, true);
  662. list_for_each_entry(hose, &hose_list, list_node) {
  663. phb_pe = eeh_phb_pe_get(hose);
  664. if (!phb_pe) continue;
  665. eeh_pe_state_mark(phb_pe, EEH_PE_ISOLATED);
  666. }
  667. eeh_serialize_unlock(flags);
  668. break;
  669. case EEH_NEXT_ERR_FROZEN_PE:
  670. case EEH_NEXT_ERR_FENCED_PHB:
  671. case EEH_NEXT_ERR_DEAD_PHB:
  672. /* Mark the PE in fenced state */
  673. eeh_serialize_lock(&flags);
  674. /* Purge all events of the PHB */
  675. eeh_remove_event(pe, true);
  676. if (rc == EEH_NEXT_ERR_DEAD_PHB)
  677. eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
  678. else
  679. eeh_pe_state_mark(pe,
  680. EEH_PE_ISOLATED | EEH_PE_RECOVERING);
  681. eeh_serialize_unlock(flags);
  682. break;
  683. case EEH_NEXT_ERR_NONE:
  684. return;
  685. default:
  686. pr_warn("%s: Invalid value %d from next_error()\n",
  687. __func__, rc);
  688. return;
  689. }
  690. /*
  691. * For fenced PHB and frozen PE, it's handled as normal
  692. * event. We have to remove the affected PHBs for dead
  693. * PHB and IOC
  694. */
  695. if (rc == EEH_NEXT_ERR_FROZEN_PE ||
  696. rc == EEH_NEXT_ERR_FENCED_PHB) {
  697. eeh_handle_normal_event(pe);
  698. eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
  699. } else {
  700. pci_lock_rescan_remove();
  701. list_for_each_entry(hose, &hose_list, list_node) {
  702. phb_pe = eeh_phb_pe_get(hose);
  703. if (!phb_pe ||
  704. !(phb_pe->state & EEH_PE_ISOLATED) ||
  705. (phb_pe->state & EEH_PE_RECOVERING))
  706. continue;
  707. /* Notify all devices to be down */
  708. bus = eeh_pe_bus_get(phb_pe);
  709. eeh_pe_dev_traverse(pe,
  710. eeh_report_failure, NULL);
  711. pcibios_remove_pci_devices(bus);
  712. }
  713. pci_unlock_rescan_remove();
  714. }
  715. /*
  716. * If we have detected dead IOC, we needn't proceed
  717. * any more since all PHBs would have been removed
  718. */
  719. if (rc == EEH_NEXT_ERR_DEAD_IOC)
  720. break;
  721. } while (rc != EEH_NEXT_ERR_NONE);
  722. }
  723. /**
  724. * eeh_handle_event - Reset a PCI device after hard lockup.
  725. * @pe: EEH PE
  726. *
  727. * While PHB detects address or data parity errors on particular PCI
  728. * slot, the associated PE will be frozen. Besides, DMA's occurring
  729. * to wild addresses (which usually happen due to bugs in device
  730. * drivers or in PCI adapter firmware) can cause EEH error. #SERR,
  731. * #PERR or other misc PCI-related errors also can trigger EEH errors.
  732. *
  733. * Recovery process consists of unplugging the device driver (which
  734. * generated hotplug events to userspace), then issuing a PCI #RST to
  735. * the device, then reconfiguring the PCI config space for all bridges
  736. * & devices under this slot, and then finally restarting the device
  737. * drivers (which cause a second set of hotplug events to go out to
  738. * userspace).
  739. */
  740. void eeh_handle_event(struct eeh_pe *pe)
  741. {
  742. if (pe)
  743. eeh_handle_normal_event(pe);
  744. else
  745. eeh_handle_special_event();
  746. }