eeh-ioda.c 24 KB

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