eeh-ioda.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /*
  2. * The file intends to implement the functions needed by EEH, which is
  3. * built on IODA compliant chip. Actually, lots of functions related
  4. * to EEH would be built based on the OPAL APIs.
  5. *
  6. * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2013.
  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
  11. * (at your option) any later version.
  12. */
  13. #include <linux/bootmem.h>
  14. #include <linux/debugfs.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/kernel.h>
  20. #include <linux/msi.h>
  21. #include <linux/notifier.h>
  22. #include <linux/pci.h>
  23. #include <linux/string.h>
  24. #include <asm/eeh.h>
  25. #include <asm/eeh_event.h>
  26. #include <asm/io.h>
  27. #include <asm/iommu.h>
  28. #include <asm/msi_bitmap.h>
  29. #include <asm/opal.h>
  30. #include <asm/pci-bridge.h>
  31. #include <asm/ppc-pci.h>
  32. #include <asm/tce.h>
  33. #include "powernv.h"
  34. #include "pci.h"
  35. /* Debugging option */
  36. #ifdef IODA_EEH_DBG_ON
  37. #define IODA_EEH_DBG(args...) pr_info(args)
  38. #else
  39. #define IODA_EEH_DBG(args...)
  40. #endif
  41. static char *hub_diag = NULL;
  42. static int ioda_eeh_nb_init = 0;
  43. static int ioda_eeh_event(struct notifier_block *nb,
  44. unsigned long events, void *change)
  45. {
  46. uint64_t changed_evts = (uint64_t)change;
  47. /* We simply send special EEH event */
  48. if ((changed_evts & OPAL_EVENT_PCI_ERROR) &&
  49. (events & OPAL_EVENT_PCI_ERROR))
  50. eeh_send_failure_event(NULL);
  51. return 0;
  52. }
  53. static struct notifier_block ioda_eeh_nb = {
  54. .notifier_call = ioda_eeh_event,
  55. .next = NULL,
  56. .priority = 0
  57. };
  58. #ifdef CONFIG_DEBUG_FS
  59. static int ioda_eeh_dbgfs_set(void *data, u64 val)
  60. {
  61. struct pci_controller *hose = data;
  62. struct pnv_phb *phb = hose->private_data;
  63. out_be64(phb->regs + 0xD10, val);
  64. return 0;
  65. }
  66. static int ioda_eeh_dbgfs_get(void *data, u64 *val)
  67. {
  68. struct pci_controller *hose = data;
  69. struct pnv_phb *phb = hose->private_data;
  70. *val = in_be64(phb->regs + 0xD10);
  71. return 0;
  72. }
  73. DEFINE_SIMPLE_ATTRIBUTE(ioda_eeh_dbgfs_ops, ioda_eeh_dbgfs_get,
  74. ioda_eeh_dbgfs_set, "0x%llx\n");
  75. #endif /* CONFIG_DEBUG_FS */
  76. /**
  77. * ioda_eeh_post_init - Chip dependent post initialization
  78. * @hose: PCI controller
  79. *
  80. * The function will be called after eeh PEs and devices
  81. * have been built. That means the EEH is ready to supply
  82. * service with I/O cache.
  83. */
  84. static int ioda_eeh_post_init(struct pci_controller *hose)
  85. {
  86. struct pnv_phb *phb = hose->private_data;
  87. int ret;
  88. /* Register OPAL event notifier */
  89. if (!ioda_eeh_nb_init) {
  90. ret = opal_notifier_register(&ioda_eeh_nb);
  91. if (ret) {
  92. pr_err("%s: Can't register OPAL event notifier (%d)\n",
  93. __func__, ret);
  94. return ret;
  95. }
  96. ioda_eeh_nb_init = 1;
  97. }
  98. /* FIXME: Enable it for PHB3 later */
  99. if (phb->type == PNV_PHB_IODA1) {
  100. if (!hub_diag) {
  101. hub_diag = (char *)__get_free_page(GFP_KERNEL |
  102. __GFP_ZERO);
  103. if (!hub_diag) {
  104. pr_err("%s: Out of memory !\n",
  105. __func__);
  106. return -ENOMEM;
  107. }
  108. }
  109. #ifdef CONFIG_DEBUG_FS
  110. if (phb->dbgfs)
  111. debugfs_create_file("err_injct", 0600,
  112. phb->dbgfs, hose,
  113. &ioda_eeh_dbgfs_ops);
  114. #endif
  115. phb->eeh_state |= PNV_EEH_STATE_ENABLED;
  116. }
  117. return 0;
  118. }
  119. /**
  120. * ioda_eeh_set_option - Set EEH operation or I/O setting
  121. * @pe: EEH PE
  122. * @option: options
  123. *
  124. * Enable or disable EEH option for the indicated PE. The
  125. * function also can be used to enable I/O or DMA for the
  126. * PE.
  127. */
  128. static int ioda_eeh_set_option(struct eeh_pe *pe, int option)
  129. {
  130. s64 ret;
  131. u32 pe_no;
  132. struct pci_controller *hose = pe->phb;
  133. struct pnv_phb *phb = hose->private_data;
  134. /* Check on PE number */
  135. if (pe->addr < 0 || pe->addr >= phb->ioda.total_pe) {
  136. pr_err("%s: PE address %x out of range [0, %x] "
  137. "on PHB#%x\n",
  138. __func__, pe->addr, phb->ioda.total_pe,
  139. hose->global_number);
  140. return -EINVAL;
  141. }
  142. pe_no = pe->addr;
  143. switch (option) {
  144. case EEH_OPT_DISABLE:
  145. ret = -EEXIST;
  146. break;
  147. case EEH_OPT_ENABLE:
  148. ret = 0;
  149. break;
  150. case EEH_OPT_THAW_MMIO:
  151. ret = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no,
  152. OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO);
  153. if (ret) {
  154. pr_warning("%s: Failed to enable MMIO for "
  155. "PHB#%x-PE#%x, err=%lld\n",
  156. __func__, hose->global_number, pe_no, ret);
  157. return -EIO;
  158. }
  159. break;
  160. case EEH_OPT_THAW_DMA:
  161. ret = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no,
  162. OPAL_EEH_ACTION_CLEAR_FREEZE_DMA);
  163. if (ret) {
  164. pr_warning("%s: Failed to enable DMA for "
  165. "PHB#%x-PE#%x, err=%lld\n",
  166. __func__, hose->global_number, pe_no, ret);
  167. return -EIO;
  168. }
  169. break;
  170. default:
  171. pr_warning("%s: Invalid option %d\n", __func__, option);
  172. return -EINVAL;
  173. }
  174. return ret;
  175. }
  176. /**
  177. * ioda_eeh_get_state - Retrieve the state of PE
  178. * @pe: EEH PE
  179. *
  180. * The PE's state should be retrieved from the PEEV, PEST
  181. * IODA tables. Since the OPAL has exported the function
  182. * to do it, it'd better to use that.
  183. */
  184. static int ioda_eeh_get_state(struct eeh_pe *pe)
  185. {
  186. s64 ret = 0;
  187. u8 fstate;
  188. u16 pcierr;
  189. u32 pe_no;
  190. int result;
  191. struct pci_controller *hose = pe->phb;
  192. struct pnv_phb *phb = hose->private_data;
  193. /*
  194. * Sanity check on PE address. The PHB PE address should
  195. * be zero.
  196. */
  197. if (pe->addr < 0 || pe->addr >= phb->ioda.total_pe) {
  198. pr_err("%s: PE address %x out of range [0, %x] "
  199. "on PHB#%x\n",
  200. __func__, pe->addr, phb->ioda.total_pe,
  201. hose->global_number);
  202. return EEH_STATE_NOT_SUPPORT;
  203. }
  204. /* Retrieve PE status through OPAL */
  205. pe_no = pe->addr;
  206. ret = opal_pci_eeh_freeze_status(phb->opal_id, pe_no,
  207. &fstate, &pcierr, NULL);
  208. if (ret) {
  209. pr_err("%s: Failed to get EEH status on "
  210. "PHB#%x-PE#%x\n, err=%lld\n",
  211. __func__, hose->global_number, pe_no, ret);
  212. return EEH_STATE_NOT_SUPPORT;
  213. }
  214. /* Check PHB status */
  215. if (pe->type & EEH_PE_PHB) {
  216. result = 0;
  217. result &= ~EEH_STATE_RESET_ACTIVE;
  218. if (pcierr != OPAL_EEH_PHB_ERROR) {
  219. result |= EEH_STATE_MMIO_ACTIVE;
  220. result |= EEH_STATE_DMA_ACTIVE;
  221. result |= EEH_STATE_MMIO_ENABLED;
  222. result |= EEH_STATE_DMA_ENABLED;
  223. }
  224. return result;
  225. }
  226. /* Parse result out */
  227. result = 0;
  228. switch (fstate) {
  229. case OPAL_EEH_STOPPED_NOT_FROZEN:
  230. result &= ~EEH_STATE_RESET_ACTIVE;
  231. result |= EEH_STATE_MMIO_ACTIVE;
  232. result |= EEH_STATE_DMA_ACTIVE;
  233. result |= EEH_STATE_MMIO_ENABLED;
  234. result |= EEH_STATE_DMA_ENABLED;
  235. break;
  236. case OPAL_EEH_STOPPED_MMIO_FREEZE:
  237. result &= ~EEH_STATE_RESET_ACTIVE;
  238. result |= EEH_STATE_DMA_ACTIVE;
  239. result |= EEH_STATE_DMA_ENABLED;
  240. break;
  241. case OPAL_EEH_STOPPED_DMA_FREEZE:
  242. result &= ~EEH_STATE_RESET_ACTIVE;
  243. result |= EEH_STATE_MMIO_ACTIVE;
  244. result |= EEH_STATE_MMIO_ENABLED;
  245. break;
  246. case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
  247. result &= ~EEH_STATE_RESET_ACTIVE;
  248. break;
  249. case OPAL_EEH_STOPPED_RESET:
  250. result |= EEH_STATE_RESET_ACTIVE;
  251. break;
  252. case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
  253. result |= EEH_STATE_UNAVAILABLE;
  254. break;
  255. case OPAL_EEH_STOPPED_PERM_UNAVAIL:
  256. result |= EEH_STATE_NOT_SUPPORT;
  257. break;
  258. default:
  259. pr_warning("%s: Unexpected EEH status 0x%x "
  260. "on PHB#%x-PE#%x\n",
  261. __func__, fstate, hose->global_number, pe_no);
  262. }
  263. return result;
  264. }
  265. static int ioda_eeh_pe_clear(struct eeh_pe *pe)
  266. {
  267. struct pci_controller *hose;
  268. struct pnv_phb *phb;
  269. u32 pe_no;
  270. u8 fstate;
  271. u16 pcierr;
  272. s64 ret;
  273. pe_no = pe->addr;
  274. hose = pe->phb;
  275. phb = pe->phb->private_data;
  276. /* Clear the EEH error on the PE */
  277. ret = opal_pci_eeh_freeze_clear(phb->opal_id,
  278. pe_no, OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
  279. if (ret) {
  280. pr_err("%s: Failed to clear EEH error for "
  281. "PHB#%x-PE#%x, err=%lld\n",
  282. __func__, hose->global_number, pe_no, ret);
  283. return -EIO;
  284. }
  285. /*
  286. * Read the PE state back and verify that the frozen
  287. * state has been removed.
  288. */
  289. ret = opal_pci_eeh_freeze_status(phb->opal_id, pe_no,
  290. &fstate, &pcierr, NULL);
  291. if (ret) {
  292. pr_err("%s: Failed to get EEH status on "
  293. "PHB#%x-PE#%x\n, err=%lld\n",
  294. __func__, hose->global_number, pe_no, ret);
  295. return -EIO;
  296. }
  297. if (fstate != OPAL_EEH_STOPPED_NOT_FROZEN) {
  298. pr_err("%s: Frozen state not cleared on "
  299. "PHB#%x-PE#%x, sts=%x\n",
  300. __func__, hose->global_number, pe_no, fstate);
  301. return -EIO;
  302. }
  303. return 0;
  304. }
  305. static s64 ioda_eeh_phb_poll(struct pnv_phb *phb)
  306. {
  307. s64 rc = OPAL_HARDWARE;
  308. while (1) {
  309. rc = opal_pci_poll(phb->opal_id);
  310. if (rc <= 0)
  311. break;
  312. msleep(rc);
  313. }
  314. return rc;
  315. }
  316. static int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
  317. {
  318. struct pnv_phb *phb = hose->private_data;
  319. s64 rc = OPAL_HARDWARE;
  320. pr_debug("%s: Reset PHB#%x, option=%d\n",
  321. __func__, hose->global_number, option);
  322. /* Issue PHB complete reset request */
  323. if (option == EEH_RESET_FUNDAMENTAL ||
  324. option == EEH_RESET_HOT)
  325. rc = opal_pci_reset(phb->opal_id,
  326. OPAL_PHB_COMPLETE,
  327. OPAL_ASSERT_RESET);
  328. else if (option == EEH_RESET_DEACTIVATE)
  329. rc = opal_pci_reset(phb->opal_id,
  330. OPAL_PHB_COMPLETE,
  331. OPAL_DEASSERT_RESET);
  332. if (rc < 0)
  333. goto out;
  334. /*
  335. * Poll state of the PHB until the request is done
  336. * successfully.
  337. */
  338. rc = ioda_eeh_phb_poll(phb);
  339. out:
  340. if (rc != OPAL_SUCCESS)
  341. return -EIO;
  342. return 0;
  343. }
  344. static int ioda_eeh_root_reset(struct pci_controller *hose, int option)
  345. {
  346. struct pnv_phb *phb = hose->private_data;
  347. s64 rc = OPAL_SUCCESS;
  348. pr_debug("%s: Reset PHB#%x, option=%d\n",
  349. __func__, hose->global_number, option);
  350. /*
  351. * During the reset deassert time, we needn't care
  352. * the reset scope because the firmware does nothing
  353. * for fundamental or hot reset during deassert phase.
  354. */
  355. if (option == EEH_RESET_FUNDAMENTAL)
  356. rc = opal_pci_reset(phb->opal_id,
  357. OPAL_PCI_FUNDAMENTAL_RESET,
  358. OPAL_ASSERT_RESET);
  359. else if (option == EEH_RESET_HOT)
  360. rc = opal_pci_reset(phb->opal_id,
  361. OPAL_PCI_HOT_RESET,
  362. OPAL_ASSERT_RESET);
  363. else if (option == EEH_RESET_DEACTIVATE)
  364. rc = opal_pci_reset(phb->opal_id,
  365. OPAL_PCI_HOT_RESET,
  366. OPAL_DEASSERT_RESET);
  367. if (rc < 0)
  368. goto out;
  369. /* Poll state of the PHB until the request is done */
  370. rc = ioda_eeh_phb_poll(phb);
  371. out:
  372. if (rc != OPAL_SUCCESS)
  373. return -EIO;
  374. return 0;
  375. }
  376. static int ioda_eeh_bridge_reset(struct pci_controller *hose,
  377. struct pci_dev *dev, int option)
  378. {
  379. u16 ctrl;
  380. pr_debug("%s: Reset device %04x:%02x:%02x.%01x with option %d\n",
  381. __func__, hose->global_number, dev->bus->number,
  382. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), option);
  383. switch (option) {
  384. case EEH_RESET_FUNDAMENTAL:
  385. case EEH_RESET_HOT:
  386. pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &ctrl);
  387. ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
  388. pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
  389. break;
  390. case EEH_RESET_DEACTIVATE:
  391. pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &ctrl);
  392. ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  393. pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
  394. break;
  395. }
  396. return 0;
  397. }
  398. /**
  399. * ioda_eeh_reset - Reset the indicated PE
  400. * @pe: EEH PE
  401. * @option: reset option
  402. *
  403. * Do reset on the indicated PE. For PCI bus sensitive PE,
  404. * we need to reset the parent p2p bridge. The PHB has to
  405. * be reinitialized if the p2p bridge is root bridge. For
  406. * PCI device sensitive PE, we will try to reset the device
  407. * through FLR. For now, we don't have OPAL APIs to do HARD
  408. * reset yet, so all reset would be SOFT (HOT) reset.
  409. */
  410. static int ioda_eeh_reset(struct eeh_pe *pe, int option)
  411. {
  412. struct pci_controller *hose = pe->phb;
  413. struct eeh_dev *edev;
  414. struct pci_dev *dev;
  415. int ret;
  416. /*
  417. * Anyway, we have to clear the problematic state for the
  418. * corresponding PE. However, we needn't do it if the PE
  419. * is PHB associated. That means the PHB is having fatal
  420. * errors and it needs reset. Further more, the AIB interface
  421. * isn't reliable any more.
  422. */
  423. if (!(pe->type & EEH_PE_PHB) &&
  424. (option == EEH_RESET_HOT ||
  425. option == EEH_RESET_FUNDAMENTAL)) {
  426. ret = ioda_eeh_pe_clear(pe);
  427. if (ret)
  428. return -EIO;
  429. }
  430. /*
  431. * The rules applied to reset, either fundamental or hot reset:
  432. *
  433. * We always reset the direct upstream bridge of the PE. If the
  434. * direct upstream bridge isn't root bridge, we always take hot
  435. * reset no matter what option (fundamental or hot) is. Otherwise,
  436. * we should do the reset according to the required option.
  437. */
  438. if (pe->type & EEH_PE_PHB) {
  439. ret = ioda_eeh_phb_reset(hose, option);
  440. } else {
  441. if (pe->type & EEH_PE_DEVICE) {
  442. /*
  443. * If it's device PE, we didn't refer to the parent
  444. * PCI bus yet. So we have to figure it out indirectly.
  445. */
  446. edev = list_first_entry(&pe->edevs,
  447. struct eeh_dev, list);
  448. dev = eeh_dev_to_pci_dev(edev);
  449. dev = dev->bus->self;
  450. } else {
  451. /*
  452. * If it's bus PE, the parent PCI bus is already there
  453. * and just pick it up.
  454. */
  455. dev = pe->bus->self;
  456. }
  457. /*
  458. * Do reset based on the fact that the direct upstream bridge
  459. * is root bridge (port) or not.
  460. */
  461. if (dev->bus->number == 0)
  462. ret = ioda_eeh_root_reset(hose, option);
  463. else
  464. ret = ioda_eeh_bridge_reset(hose, dev, option);
  465. }
  466. return ret;
  467. }
  468. /**
  469. * ioda_eeh_get_log - Retrieve error log
  470. * @pe: EEH PE
  471. * @severity: Severity level of the log
  472. * @drv_log: buffer to store the log
  473. * @len: space of the log buffer
  474. *
  475. * The function is used to retrieve error log from P7IOC.
  476. */
  477. static int ioda_eeh_get_log(struct eeh_pe *pe, int severity,
  478. char *drv_log, unsigned long len)
  479. {
  480. s64 ret;
  481. unsigned long flags;
  482. struct pci_controller *hose = pe->phb;
  483. struct pnv_phb *phb = hose->private_data;
  484. spin_lock_irqsave(&phb->lock, flags);
  485. ret = opal_pci_get_phb_diag_data2(phb->opal_id,
  486. phb->diag.blob, PNV_PCI_DIAG_BUF_SIZE);
  487. if (ret) {
  488. spin_unlock_irqrestore(&phb->lock, flags);
  489. pr_warning("%s: Failed to get log for PHB#%x-PE#%x\n",
  490. __func__, hose->global_number, pe->addr);
  491. return -EIO;
  492. }
  493. /*
  494. * FIXME: We probably need log the error in somewhere.
  495. * Lets make it up in future.
  496. */
  497. /* pr_info("%s", phb->diag.blob); */
  498. spin_unlock_irqrestore(&phb->lock, flags);
  499. return 0;
  500. }
  501. /**
  502. * ioda_eeh_configure_bridge - Configure the PCI bridges for the indicated PE
  503. * @pe: EEH PE
  504. *
  505. * For particular PE, it might have included PCI bridges. In order
  506. * to make the PE work properly, those PCI bridges should be configured
  507. * correctly. However, we need do nothing on P7IOC since the reset
  508. * function will do everything that should be covered by the function.
  509. */
  510. static int ioda_eeh_configure_bridge(struct eeh_pe *pe)
  511. {
  512. return 0;
  513. }
  514. static void ioda_eeh_hub_diag_common(struct OpalIoP7IOCErrorData *data)
  515. {
  516. /* GEM */
  517. pr_info(" GEM XFIR: %016llx\n", data->gemXfir);
  518. pr_info(" GEM RFIR: %016llx\n", data->gemRfir);
  519. pr_info(" GEM RIRQFIR: %016llx\n", data->gemRirqfir);
  520. pr_info(" GEM Mask: %016llx\n", data->gemMask);
  521. pr_info(" GEM RWOF: %016llx\n", data->gemRwof);
  522. /* LEM */
  523. pr_info(" LEM FIR: %016llx\n", data->lemFir);
  524. pr_info(" LEM Error Mask: %016llx\n", data->lemErrMask);
  525. pr_info(" LEM Action 0: %016llx\n", data->lemAction0);
  526. pr_info(" LEM Action 1: %016llx\n", data->lemAction1);
  527. pr_info(" LEM WOF: %016llx\n", data->lemWof);
  528. }
  529. static void ioda_eeh_hub_diag(struct pci_controller *hose)
  530. {
  531. struct pnv_phb *phb = hose->private_data;
  532. struct OpalIoP7IOCErrorData *data;
  533. long rc;
  534. data = (struct OpalIoP7IOCErrorData *)ioda_eeh_hub_diag;
  535. rc = opal_pci_get_hub_diag_data(phb->hub_id, data, PAGE_SIZE);
  536. if (rc != OPAL_SUCCESS) {
  537. pr_warning("%s: Failed to get HUB#%llx diag-data (%ld)\n",
  538. __func__, phb->hub_id, rc);
  539. return;
  540. }
  541. switch (data->type) {
  542. case OPAL_P7IOC_DIAG_TYPE_RGC:
  543. pr_info("P7IOC diag-data for RGC\n\n");
  544. ioda_eeh_hub_diag_common(data);
  545. pr_info(" RGC Status: %016llx\n", data->rgc.rgcStatus);
  546. pr_info(" RGC LDCP: %016llx\n", data->rgc.rgcLdcp);
  547. break;
  548. case OPAL_P7IOC_DIAG_TYPE_BI:
  549. pr_info("P7IOC diag-data for BI %s\n\n",
  550. data->bi.biDownbound ? "Downbound" : "Upbound");
  551. ioda_eeh_hub_diag_common(data);
  552. pr_info(" BI LDCP 0: %016llx\n", data->bi.biLdcp0);
  553. pr_info(" BI LDCP 1: %016llx\n", data->bi.biLdcp1);
  554. pr_info(" BI LDCP 2: %016llx\n", data->bi.biLdcp2);
  555. pr_info(" BI Fence Status: %016llx\n", data->bi.biFenceStatus);
  556. break;
  557. case OPAL_P7IOC_DIAG_TYPE_CI:
  558. pr_info("P7IOC diag-data for CI Port %d\\nn",
  559. data->ci.ciPort);
  560. ioda_eeh_hub_diag_common(data);
  561. pr_info(" CI Port Status: %016llx\n", data->ci.ciPortStatus);
  562. pr_info(" CI Port LDCP: %016llx\n", data->ci.ciPortLdcp);
  563. break;
  564. case OPAL_P7IOC_DIAG_TYPE_MISC:
  565. pr_info("P7IOC diag-data for MISC\n\n");
  566. ioda_eeh_hub_diag_common(data);
  567. break;
  568. case OPAL_P7IOC_DIAG_TYPE_I2C:
  569. pr_info("P7IOC diag-data for I2C\n\n");
  570. ioda_eeh_hub_diag_common(data);
  571. break;
  572. default:
  573. pr_warning("%s: Invalid type of HUB#%llx diag-data (%d)\n",
  574. __func__, phb->hub_id, data->type);
  575. }
  576. }
  577. static void ioda_eeh_p7ioc_phb_diag(struct pci_controller *hose,
  578. struct OpalIoPhbErrorCommon *common)
  579. {
  580. struct OpalIoP7IOCPhbErrorData *data;
  581. int i;
  582. data = (struct OpalIoP7IOCPhbErrorData *)common;
  583. pr_info("P7IOC PHB#%x Diag-data (Version: %d)\n\n",
  584. hose->global_number, common->version);
  585. pr_info(" brdgCtl: %08x\n", data->brdgCtl);
  586. pr_info(" portStatusReg: %08x\n", data->portStatusReg);
  587. pr_info(" rootCmplxStatus: %08x\n", data->rootCmplxStatus);
  588. pr_info(" busAgentStatus: %08x\n", data->busAgentStatus);
  589. pr_info(" deviceStatus: %08x\n", data->deviceStatus);
  590. pr_info(" slotStatus: %08x\n", data->slotStatus);
  591. pr_info(" linkStatus: %08x\n", data->linkStatus);
  592. pr_info(" devCmdStatus: %08x\n", data->devCmdStatus);
  593. pr_info(" devSecStatus: %08x\n", data->devSecStatus);
  594. pr_info(" rootErrorStatus: %08x\n", data->rootErrorStatus);
  595. pr_info(" uncorrErrorStatus: %08x\n", data->uncorrErrorStatus);
  596. pr_info(" corrErrorStatus: %08x\n", data->corrErrorStatus);
  597. pr_info(" tlpHdr1: %08x\n", data->tlpHdr1);
  598. pr_info(" tlpHdr2: %08x\n", data->tlpHdr2);
  599. pr_info(" tlpHdr3: %08x\n", data->tlpHdr3);
  600. pr_info(" tlpHdr4: %08x\n", data->tlpHdr4);
  601. pr_info(" sourceId: %08x\n", data->sourceId);
  602. pr_info(" errorClass: %016llx\n", data->errorClass);
  603. pr_info(" correlator: %016llx\n", data->correlator);
  604. pr_info(" p7iocPlssr: %016llx\n", data->p7iocPlssr);
  605. pr_info(" p7iocCsr: %016llx\n", data->p7iocCsr);
  606. pr_info(" lemFir: %016llx\n", data->lemFir);
  607. pr_info(" lemErrorMask: %016llx\n", data->lemErrorMask);
  608. pr_info(" lemWOF: %016llx\n", data->lemWOF);
  609. pr_info(" phbErrorStatus: %016llx\n", data->phbErrorStatus);
  610. pr_info(" phbFirstErrorStatus: %016llx\n", data->phbFirstErrorStatus);
  611. pr_info(" phbErrorLog0: %016llx\n", data->phbErrorLog0);
  612. pr_info(" phbErrorLog1: %016llx\n", data->phbErrorLog1);
  613. pr_info(" mmioErrorStatus: %016llx\n", data->mmioErrorStatus);
  614. pr_info(" mmioFirstErrorStatus: %016llx\n", data->mmioFirstErrorStatus);
  615. pr_info(" mmioErrorLog0: %016llx\n", data->mmioErrorLog0);
  616. pr_info(" mmioErrorLog1: %016llx\n", data->mmioErrorLog1);
  617. pr_info(" dma0ErrorStatus: %016llx\n", data->dma0ErrorStatus);
  618. pr_info(" dma0FirstErrorStatus: %016llx\n", data->dma0FirstErrorStatus);
  619. pr_info(" dma0ErrorLog0: %016llx\n", data->dma0ErrorLog0);
  620. pr_info(" dma0ErrorLog1: %016llx\n", data->dma0ErrorLog1);
  621. pr_info(" dma1ErrorStatus: %016llx\n", data->dma1ErrorStatus);
  622. pr_info(" dma1FirstErrorStatus: %016llx\n", data->dma1FirstErrorStatus);
  623. pr_info(" dma1ErrorLog0: %016llx\n", data->dma1ErrorLog0);
  624. pr_info(" dma1ErrorLog1: %016llx\n", data->dma1ErrorLog1);
  625. for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) {
  626. if ((data->pestA[i] >> 63) == 0 &&
  627. (data->pestB[i] >> 63) == 0)
  628. continue;
  629. pr_info(" PE[%3d] PESTA: %016llx\n", i, data->pestA[i]);
  630. pr_info(" PESTB: %016llx\n", data->pestB[i]);
  631. }
  632. }
  633. static void ioda_eeh_phb_diag(struct pci_controller *hose)
  634. {
  635. struct pnv_phb *phb = hose->private_data;
  636. struct OpalIoPhbErrorCommon *common;
  637. long rc;
  638. common = (struct OpalIoPhbErrorCommon *)phb->diag.blob;
  639. rc = opal_pci_get_phb_diag_data2(phb->opal_id, common, PAGE_SIZE);
  640. if (rc != OPAL_SUCCESS) {
  641. pr_warning("%s: Failed to get diag-data for PHB#%x (%ld)\n",
  642. __func__, hose->global_number, rc);
  643. return;
  644. }
  645. switch (common->ioType) {
  646. case OPAL_PHB_ERROR_DATA_TYPE_P7IOC:
  647. ioda_eeh_p7ioc_phb_diag(hose, common);
  648. break;
  649. default:
  650. pr_warning("%s: Unrecognized I/O chip %d\n",
  651. __func__, common->ioType);
  652. }
  653. }
  654. static int ioda_eeh_get_phb_pe(struct pci_controller *hose,
  655. struct eeh_pe **pe)
  656. {
  657. struct eeh_pe *phb_pe;
  658. phb_pe = eeh_phb_pe_get(hose);
  659. if (!phb_pe) {
  660. pr_warning("%s Can't find PE for PHB#%d\n",
  661. __func__, hose->global_number);
  662. return -EEXIST;
  663. }
  664. *pe = phb_pe;
  665. return 0;
  666. }
  667. static int ioda_eeh_get_pe(struct pci_controller *hose,
  668. u16 pe_no, struct eeh_pe **pe)
  669. {
  670. struct eeh_pe *phb_pe, *dev_pe;
  671. struct eeh_dev dev;
  672. /* Find the PHB PE */
  673. if (ioda_eeh_get_phb_pe(hose, &phb_pe))
  674. return -EEXIST;
  675. /* Find the PE according to PE# */
  676. memset(&dev, 0, sizeof(struct eeh_dev));
  677. dev.phb = hose;
  678. dev.pe_config_addr = pe_no;
  679. dev_pe = eeh_pe_get(&dev);
  680. if (!dev_pe) {
  681. pr_warning("%s: Can't find PE for PHB#%x - PE#%x\n",
  682. __func__, hose->global_number, pe_no);
  683. return -EEXIST;
  684. }
  685. *pe = dev_pe;
  686. return 0;
  687. }
  688. /**
  689. * ioda_eeh_next_error - Retrieve next error for EEH core to handle
  690. * @pe: The affected PE
  691. *
  692. * The function is expected to be called by EEH core while it gets
  693. * special EEH event (without binding PE). The function calls to
  694. * OPAL APIs for next error to handle. The informational error is
  695. * handled internally by platform. However, the dead IOC, dead PHB,
  696. * fenced PHB and frozen PE should be handled by EEH core eventually.
  697. */
  698. static int ioda_eeh_next_error(struct eeh_pe **pe)
  699. {
  700. struct pci_controller *hose, *tmp;
  701. struct pnv_phb *phb;
  702. u64 frozen_pe_no;
  703. u16 err_type, severity;
  704. long rc;
  705. int ret = 1;
  706. /*
  707. * While running here, it's safe to purge the event queue.
  708. * And we should keep the cached OPAL notifier event sychronized
  709. * between the kernel and firmware.
  710. */
  711. eeh_remove_event(NULL);
  712. opal_notifier_update_evt(OPAL_EVENT_PCI_ERROR, 0x0ul);
  713. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  714. /*
  715. * If the subordinate PCI buses of the PHB has been
  716. * removed, we needn't take care of it any more.
  717. */
  718. phb = hose->private_data;
  719. if (phb->eeh_state & PNV_EEH_STATE_REMOVED)
  720. continue;
  721. rc = opal_pci_next_error(phb->opal_id,
  722. &frozen_pe_no, &err_type, &severity);
  723. /* If OPAL API returns error, we needn't proceed */
  724. if (rc != OPAL_SUCCESS) {
  725. IODA_EEH_DBG("%s: Invalid return value on "
  726. "PHB#%x (0x%lx) from opal_pci_next_error",
  727. __func__, hose->global_number, rc);
  728. continue;
  729. }
  730. /* If the PHB doesn't have error, stop processing */
  731. if (err_type == OPAL_EEH_NO_ERROR ||
  732. severity == OPAL_EEH_SEV_NO_ERROR) {
  733. IODA_EEH_DBG("%s: No error found on PHB#%x\n",
  734. __func__, hose->global_number);
  735. continue;
  736. }
  737. /*
  738. * Processing the error. We're expecting the error with
  739. * highest priority reported upon multiple errors on the
  740. * specific PHB.
  741. */
  742. IODA_EEH_DBG("%s: Error (%d, %d, %d) on PHB#%x\n",
  743. err_type, severity, pe_no, hose->global_number);
  744. switch (err_type) {
  745. case OPAL_EEH_IOC_ERROR:
  746. if (severity == OPAL_EEH_SEV_IOC_DEAD) {
  747. list_for_each_entry_safe(hose, tmp,
  748. &hose_list, list_node) {
  749. phb = hose->private_data;
  750. phb->eeh_state |= PNV_EEH_STATE_REMOVED;
  751. }
  752. pr_err("EEH: dead IOC detected\n");
  753. ret = 4;
  754. goto out;
  755. } else if (severity == OPAL_EEH_SEV_INF) {
  756. pr_info("EEH: IOC informative error "
  757. "detected\n");
  758. ioda_eeh_hub_diag(hose);
  759. }
  760. break;
  761. case OPAL_EEH_PHB_ERROR:
  762. if (severity == OPAL_EEH_SEV_PHB_DEAD) {
  763. if (ioda_eeh_get_phb_pe(hose, pe))
  764. break;
  765. pr_err("EEH: dead PHB#%x detected\n",
  766. hose->global_number);
  767. phb->eeh_state |= PNV_EEH_STATE_REMOVED;
  768. ret = 3;
  769. goto out;
  770. } else if (severity == OPAL_EEH_SEV_PHB_FENCED) {
  771. if (ioda_eeh_get_phb_pe(hose, pe))
  772. break;
  773. pr_err("EEH: fenced PHB#%x detected\n",
  774. hose->global_number);
  775. ret = 2;
  776. goto out;
  777. } else if (severity == OPAL_EEH_SEV_INF) {
  778. pr_info("EEH: PHB#%x informative error "
  779. "detected\n",
  780. hose->global_number);
  781. ioda_eeh_phb_diag(hose);
  782. }
  783. break;
  784. case OPAL_EEH_PE_ERROR:
  785. if (ioda_eeh_get_pe(hose, frozen_pe_no, pe))
  786. break;
  787. pr_err("EEH: Frozen PE#%x on PHB#%x detected\n",
  788. (*pe)->addr, (*pe)->phb->global_number);
  789. ret = 1;
  790. goto out;
  791. }
  792. }
  793. ret = 0;
  794. out:
  795. return ret;
  796. }
  797. struct pnv_eeh_ops ioda_eeh_ops = {
  798. .post_init = ioda_eeh_post_init,
  799. .set_option = ioda_eeh_set_option,
  800. .get_state = ioda_eeh_get_state,
  801. .reset = ioda_eeh_reset,
  802. .get_log = ioda_eeh_get_log,
  803. .configure_bridge = ioda_eeh_configure_bridge,
  804. .next_error = ioda_eeh_next_error
  805. };