eeh-ioda.c 29 KB

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