eeh-ioda.c 23 KB

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