eeh-ioda.c 24 KB

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