eeh-powernv.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. /*
  2. * The file intends to implement the platform dependent EEH operations on
  3. * powernv platform. Actually, the powernv was created in order to fully
  4. * hypervisor support.
  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/atomic.h>
  14. #include <linux/debugfs.h>
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/list.h>
  20. #include <linux/msi.h>
  21. #include <linux/of.h>
  22. #include <linux/pci.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/rbtree.h>
  25. #include <linux/sched.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/spinlock.h>
  28. #include <asm/eeh.h>
  29. #include <asm/eeh_event.h>
  30. #include <asm/firmware.h>
  31. #include <asm/io.h>
  32. #include <asm/iommu.h>
  33. #include <asm/machdep.h>
  34. #include <asm/msi_bitmap.h>
  35. #include <asm/opal.h>
  36. #include <asm/ppc-pci.h>
  37. #include <asm/pnv-pci.h>
  38. #include "powernv.h"
  39. #include "pci.h"
  40. static int eeh_event_irq = -EINVAL;
  41. void pnv_pcibios_bus_add_device(struct pci_dev *pdev)
  42. {
  43. struct pci_dn *pdn = pci_get_pdn(pdev);
  44. if (!pdev->is_virtfn)
  45. return;
  46. /*
  47. * The following operations will fail if VF's sysfs files
  48. * aren't created or its resources aren't finalized.
  49. */
  50. eeh_add_device_early(pdn);
  51. eeh_add_device_late(pdev);
  52. eeh_sysfs_add_device(pdev);
  53. }
  54. static int pnv_eeh_init(void)
  55. {
  56. struct pci_controller *hose;
  57. struct pnv_phb *phb;
  58. int max_diag_size = PNV_PCI_DIAG_BUF_SIZE;
  59. if (!firmware_has_feature(FW_FEATURE_OPAL)) {
  60. pr_warn("%s: OPAL is required !\n",
  61. __func__);
  62. return -EINVAL;
  63. }
  64. /* Set probe mode */
  65. eeh_add_flag(EEH_PROBE_MODE_DEV);
  66. /*
  67. * P7IOC blocks PCI config access to frozen PE, but PHB3
  68. * doesn't do that. So we have to selectively enable I/O
  69. * prior to collecting error log.
  70. */
  71. list_for_each_entry(hose, &hose_list, list_node) {
  72. phb = hose->private_data;
  73. if (phb->model == PNV_PHB_MODEL_P7IOC)
  74. eeh_add_flag(EEH_ENABLE_IO_FOR_LOG);
  75. if (phb->diag_data_size > max_diag_size)
  76. max_diag_size = phb->diag_data_size;
  77. /*
  78. * PE#0 should be regarded as valid by EEH core
  79. * if it's not the reserved one. Currently, we
  80. * have the reserved PE#255 and PE#127 for PHB3
  81. * and P7IOC separately. So we should regard
  82. * PE#0 as valid for PHB3 and P7IOC.
  83. */
  84. if (phb->ioda.reserved_pe_idx != 0)
  85. eeh_add_flag(EEH_VALID_PE_ZERO);
  86. break;
  87. }
  88. eeh_set_pe_aux_size(max_diag_size);
  89. ppc_md.pcibios_bus_add_device = pnv_pcibios_bus_add_device;
  90. return 0;
  91. }
  92. static irqreturn_t pnv_eeh_event(int irq, void *data)
  93. {
  94. /*
  95. * We simply send a special EEH event if EEH has been
  96. * enabled. We don't care about EEH events until we've
  97. * finished processing the outstanding ones. Event processing
  98. * gets unmasked in next_error() if EEH is enabled.
  99. */
  100. disable_irq_nosync(irq);
  101. if (eeh_enabled())
  102. eeh_send_failure_event(NULL);
  103. return IRQ_HANDLED;
  104. }
  105. #ifdef CONFIG_DEBUG_FS
  106. static ssize_t pnv_eeh_ei_write(struct file *filp,
  107. const char __user *user_buf,
  108. size_t count, loff_t *ppos)
  109. {
  110. struct pci_controller *hose = filp->private_data;
  111. struct eeh_pe *pe;
  112. int pe_no, type, func;
  113. unsigned long addr, mask;
  114. char buf[50];
  115. int ret;
  116. if (!eeh_ops || !eeh_ops->err_inject)
  117. return -ENXIO;
  118. /* Copy over argument buffer */
  119. ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
  120. if (!ret)
  121. return -EFAULT;
  122. /* Retrieve parameters */
  123. ret = sscanf(buf, "%x:%x:%x:%lx:%lx",
  124. &pe_no, &type, &func, &addr, &mask);
  125. if (ret != 5)
  126. return -EINVAL;
  127. /* Retrieve PE */
  128. pe = eeh_pe_get(hose, pe_no, 0);
  129. if (!pe)
  130. return -ENODEV;
  131. /* Do error injection */
  132. ret = eeh_ops->err_inject(pe, type, func, addr, mask);
  133. return ret < 0 ? ret : count;
  134. }
  135. static const struct file_operations pnv_eeh_ei_fops = {
  136. .open = simple_open,
  137. .llseek = no_llseek,
  138. .write = pnv_eeh_ei_write,
  139. };
  140. static int pnv_eeh_dbgfs_set(void *data, int offset, u64 val)
  141. {
  142. struct pci_controller *hose = data;
  143. struct pnv_phb *phb = hose->private_data;
  144. out_be64(phb->regs + offset, val);
  145. return 0;
  146. }
  147. static int pnv_eeh_dbgfs_get(void *data, int offset, u64 *val)
  148. {
  149. struct pci_controller *hose = data;
  150. struct pnv_phb *phb = hose->private_data;
  151. *val = in_be64(phb->regs + offset);
  152. return 0;
  153. }
  154. #define PNV_EEH_DBGFS_ENTRY(name, reg) \
  155. static int pnv_eeh_dbgfs_set_##name(void *data, u64 val) \
  156. { \
  157. return pnv_eeh_dbgfs_set(data, reg, val); \
  158. } \
  159. \
  160. static int pnv_eeh_dbgfs_get_##name(void *data, u64 *val) \
  161. { \
  162. return pnv_eeh_dbgfs_get(data, reg, val); \
  163. } \
  164. \
  165. DEFINE_SIMPLE_ATTRIBUTE(pnv_eeh_dbgfs_ops_##name, \
  166. pnv_eeh_dbgfs_get_##name, \
  167. pnv_eeh_dbgfs_set_##name, \
  168. "0x%llx\n")
  169. PNV_EEH_DBGFS_ENTRY(outb, 0xD10);
  170. PNV_EEH_DBGFS_ENTRY(inbA, 0xD90);
  171. PNV_EEH_DBGFS_ENTRY(inbB, 0xE10);
  172. #endif /* CONFIG_DEBUG_FS */
  173. /**
  174. * pnv_eeh_post_init - EEH platform dependent post initialization
  175. *
  176. * EEH platform dependent post initialization on powernv. When
  177. * the function is called, the EEH PEs and devices should have
  178. * been built. If the I/O cache staff has been built, EEH is
  179. * ready to supply service.
  180. */
  181. int pnv_eeh_post_init(void)
  182. {
  183. struct pci_controller *hose;
  184. struct pnv_phb *phb;
  185. int ret = 0;
  186. /* Probe devices & build address cache */
  187. eeh_probe_devices();
  188. eeh_addr_cache_build();
  189. if (eeh_has_flag(EEH_POSTPONED_PROBE)) {
  190. eeh_clear_flag(EEH_POSTPONED_PROBE);
  191. if (eeh_enabled())
  192. pr_info("EEH: PCI Enhanced I/O Error Handling Enabled\n");
  193. else
  194. pr_info("EEH: No capable adapters found\n");
  195. }
  196. /* Register OPAL event notifier */
  197. eeh_event_irq = opal_event_request(ilog2(OPAL_EVENT_PCI_ERROR));
  198. if (eeh_event_irq < 0) {
  199. pr_err("%s: Can't register OPAL event interrupt (%d)\n",
  200. __func__, eeh_event_irq);
  201. return eeh_event_irq;
  202. }
  203. ret = request_irq(eeh_event_irq, pnv_eeh_event,
  204. IRQ_TYPE_LEVEL_HIGH, "opal-eeh", NULL);
  205. if (ret < 0) {
  206. irq_dispose_mapping(eeh_event_irq);
  207. pr_err("%s: Can't request OPAL event interrupt (%d)\n",
  208. __func__, eeh_event_irq);
  209. return ret;
  210. }
  211. if (!eeh_enabled())
  212. disable_irq(eeh_event_irq);
  213. list_for_each_entry(hose, &hose_list, list_node) {
  214. phb = hose->private_data;
  215. /*
  216. * If EEH is enabled, we're going to rely on that.
  217. * Otherwise, we restore to conventional mechanism
  218. * to clear frozen PE during PCI config access.
  219. */
  220. if (eeh_enabled())
  221. phb->flags |= PNV_PHB_FLAG_EEH;
  222. else
  223. phb->flags &= ~PNV_PHB_FLAG_EEH;
  224. /* Create debugfs entries */
  225. #ifdef CONFIG_DEBUG_FS
  226. if (phb->has_dbgfs || !phb->dbgfs)
  227. continue;
  228. phb->has_dbgfs = 1;
  229. debugfs_create_file("err_injct", 0200,
  230. phb->dbgfs, hose,
  231. &pnv_eeh_ei_fops);
  232. debugfs_create_file("err_injct_outbound", 0600,
  233. phb->dbgfs, hose,
  234. &pnv_eeh_dbgfs_ops_outb);
  235. debugfs_create_file("err_injct_inboundA", 0600,
  236. phb->dbgfs, hose,
  237. &pnv_eeh_dbgfs_ops_inbA);
  238. debugfs_create_file("err_injct_inboundB", 0600,
  239. phb->dbgfs, hose,
  240. &pnv_eeh_dbgfs_ops_inbB);
  241. #endif /* CONFIG_DEBUG_FS */
  242. }
  243. return ret;
  244. }
  245. static int pnv_eeh_find_cap(struct pci_dn *pdn, int cap)
  246. {
  247. int pos = PCI_CAPABILITY_LIST;
  248. int cnt = 48; /* Maximal number of capabilities */
  249. u32 status, id;
  250. if (!pdn)
  251. return 0;
  252. /* Check if the device supports capabilities */
  253. pnv_pci_cfg_read(pdn, PCI_STATUS, 2, &status);
  254. if (!(status & PCI_STATUS_CAP_LIST))
  255. return 0;
  256. while (cnt--) {
  257. pnv_pci_cfg_read(pdn, pos, 1, &pos);
  258. if (pos < 0x40)
  259. break;
  260. pos &= ~3;
  261. pnv_pci_cfg_read(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
  262. if (id == 0xff)
  263. break;
  264. /* Found */
  265. if (id == cap)
  266. return pos;
  267. /* Next one */
  268. pos += PCI_CAP_LIST_NEXT;
  269. }
  270. return 0;
  271. }
  272. static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
  273. {
  274. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  275. u32 header;
  276. int pos = 256, ttl = (4096 - 256) / 8;
  277. if (!edev || !edev->pcie_cap)
  278. return 0;
  279. if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  280. return 0;
  281. else if (!header)
  282. return 0;
  283. while (ttl-- > 0) {
  284. if (PCI_EXT_CAP_ID(header) == cap && pos)
  285. return pos;
  286. pos = PCI_EXT_CAP_NEXT(header);
  287. if (pos < 256)
  288. break;
  289. if (pnv_pci_cfg_read(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  290. break;
  291. }
  292. return 0;
  293. }
  294. /**
  295. * pnv_eeh_probe - Do probe on PCI device
  296. * @pdn: PCI device node
  297. * @data: unused
  298. *
  299. * When EEH module is installed during system boot, all PCI devices
  300. * are checked one by one to see if it supports EEH. The function
  301. * is introduced for the purpose. By default, EEH has been enabled
  302. * on all PCI devices. That's to say, we only need do necessary
  303. * initialization on the corresponding eeh device and create PE
  304. * accordingly.
  305. *
  306. * It's notable that's unsafe to retrieve the EEH device through
  307. * the corresponding PCI device. During the PCI device hotplug, which
  308. * was possiblly triggered by EEH core, the binding between EEH device
  309. * and the PCI device isn't built yet.
  310. */
  311. static void *pnv_eeh_probe(struct pci_dn *pdn, void *data)
  312. {
  313. struct pci_controller *hose = pdn->phb;
  314. struct pnv_phb *phb = hose->private_data;
  315. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  316. uint32_t pcie_flags;
  317. int ret;
  318. int config_addr = (pdn->busno << 8) | (pdn->devfn);
  319. /*
  320. * When probing the root bridge, which doesn't have any
  321. * subordinate PCI devices. We don't have OF node for
  322. * the root bridge. So it's not reasonable to continue
  323. * the probing.
  324. */
  325. if (!edev || edev->pe)
  326. return NULL;
  327. /* Skip for PCI-ISA bridge */
  328. if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)
  329. return NULL;
  330. /* Skip if we haven't probed yet */
  331. if (phb->ioda.pe_rmap[config_addr] == IODA_INVALID_PE) {
  332. eeh_add_flag(EEH_POSTPONED_PROBE);
  333. return NULL;
  334. }
  335. /* Initialize eeh device */
  336. edev->class_code = pdn->class_code;
  337. edev->mode &= 0xFFFFFF00;
  338. edev->pcix_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
  339. edev->pcie_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
  340. edev->af_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_AF);
  341. edev->aer_cap = pnv_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
  342. if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
  343. edev->mode |= EEH_DEV_BRIDGE;
  344. if (edev->pcie_cap) {
  345. pnv_pci_cfg_read(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
  346. 2, &pcie_flags);
  347. pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
  348. if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
  349. edev->mode |= EEH_DEV_ROOT_PORT;
  350. else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
  351. edev->mode |= EEH_DEV_DS_PORT;
  352. }
  353. }
  354. edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
  355. /* Create PE */
  356. ret = eeh_add_to_parent_pe(edev);
  357. if (ret) {
  358. pr_warn("%s: Can't add PCI dev %04x:%02x:%02x.%01x to parent PE (%x)\n",
  359. __func__, hose->global_number, pdn->busno,
  360. PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn), ret);
  361. return NULL;
  362. }
  363. /*
  364. * If the PE contains any one of following adapters, the
  365. * PCI config space can't be accessed when dumping EEH log.
  366. * Otherwise, we will run into fenced PHB caused by shortage
  367. * of outbound credits in the adapter. The PCI config access
  368. * should be blocked until PE reset. MMIO access is dropped
  369. * by hardware certainly. In order to drop PCI config requests,
  370. * one more flag (EEH_PE_CFG_RESTRICTED) is introduced, which
  371. * will be checked in the backend for PE state retrival. If
  372. * the PE becomes frozen for the first time and the flag has
  373. * been set for the PE, we will set EEH_PE_CFG_BLOCKED for
  374. * that PE to block its config space.
  375. *
  376. * Broadcom BCM5718 2-ports NICs (14e4:1656)
  377. * Broadcom Austin 4-ports NICs (14e4:1657)
  378. * Broadcom Shiner 4-ports 1G NICs (14e4:168a)
  379. * Broadcom Shiner 2-ports 10G NICs (14e4:168e)
  380. */
  381. if ((pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
  382. pdn->device_id == 0x1656) ||
  383. (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
  384. pdn->device_id == 0x1657) ||
  385. (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
  386. pdn->device_id == 0x168a) ||
  387. (pdn->vendor_id == PCI_VENDOR_ID_BROADCOM &&
  388. pdn->device_id == 0x168e))
  389. edev->pe->state |= EEH_PE_CFG_RESTRICTED;
  390. /*
  391. * Cache the PE primary bus, which can't be fetched when
  392. * full hotplug is in progress. In that case, all child
  393. * PCI devices of the PE are expected to be removed prior
  394. * to PE reset.
  395. */
  396. if (!(edev->pe->state & EEH_PE_PRI_BUS)) {
  397. edev->pe->bus = pci_find_bus(hose->global_number,
  398. pdn->busno);
  399. if (edev->pe->bus)
  400. edev->pe->state |= EEH_PE_PRI_BUS;
  401. }
  402. /*
  403. * Enable EEH explicitly so that we will do EEH check
  404. * while accessing I/O stuff
  405. */
  406. eeh_add_flag(EEH_ENABLED);
  407. /* Save memory bars */
  408. eeh_save_bars(edev);
  409. return NULL;
  410. }
  411. /**
  412. * pnv_eeh_set_option - Initialize EEH or MMIO/DMA reenable
  413. * @pe: EEH PE
  414. * @option: operation to be issued
  415. *
  416. * The function is used to control the EEH functionality globally.
  417. * Currently, following options are support according to PAPR:
  418. * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
  419. */
  420. static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
  421. {
  422. struct pci_controller *hose = pe->phb;
  423. struct pnv_phb *phb = hose->private_data;
  424. bool freeze_pe = false;
  425. int opt;
  426. s64 rc;
  427. switch (option) {
  428. case EEH_OPT_DISABLE:
  429. return -EPERM;
  430. case EEH_OPT_ENABLE:
  431. return 0;
  432. case EEH_OPT_THAW_MMIO:
  433. opt = OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO;
  434. break;
  435. case EEH_OPT_THAW_DMA:
  436. opt = OPAL_EEH_ACTION_CLEAR_FREEZE_DMA;
  437. break;
  438. case EEH_OPT_FREEZE_PE:
  439. freeze_pe = true;
  440. opt = OPAL_EEH_ACTION_SET_FREEZE_ALL;
  441. break;
  442. default:
  443. pr_warn("%s: Invalid option %d\n", __func__, option);
  444. return -EINVAL;
  445. }
  446. /* Freeze master and slave PEs if PHB supports compound PEs */
  447. if (freeze_pe) {
  448. if (phb->freeze_pe) {
  449. phb->freeze_pe(phb, pe->addr);
  450. return 0;
  451. }
  452. rc = opal_pci_eeh_freeze_set(phb->opal_id, pe->addr, opt);
  453. if (rc != OPAL_SUCCESS) {
  454. pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",
  455. __func__, rc, phb->hose->global_number,
  456. pe->addr);
  457. return -EIO;
  458. }
  459. return 0;
  460. }
  461. /* Unfreeze master and slave PEs if PHB supports */
  462. if (phb->unfreeze_pe)
  463. return phb->unfreeze_pe(phb, pe->addr, opt);
  464. rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe->addr, opt);
  465. if (rc != OPAL_SUCCESS) {
  466. pr_warn("%s: Failure %lld enable %d for PHB#%x-PE#%x\n",
  467. __func__, rc, option, phb->hose->global_number,
  468. pe->addr);
  469. return -EIO;
  470. }
  471. return 0;
  472. }
  473. /**
  474. * pnv_eeh_get_pe_addr - Retrieve PE address
  475. * @pe: EEH PE
  476. *
  477. * Retrieve the PE address according to the given tranditional
  478. * PCI BDF (Bus/Device/Function) address.
  479. */
  480. static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
  481. {
  482. return pe->addr;
  483. }
  484. static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
  485. {
  486. struct pnv_phb *phb = pe->phb->private_data;
  487. s64 rc;
  488. rc = opal_pci_get_phb_diag_data2(phb->opal_id, pe->data,
  489. phb->diag_data_size);
  490. if (rc != OPAL_SUCCESS)
  491. pr_warn("%s: Failure %lld getting PHB#%x diag-data\n",
  492. __func__, rc, pe->phb->global_number);
  493. }
  494. static int pnv_eeh_get_phb_state(struct eeh_pe *pe)
  495. {
  496. struct pnv_phb *phb = pe->phb->private_data;
  497. u8 fstate = 0;
  498. __be16 pcierr = 0;
  499. s64 rc;
  500. int result = 0;
  501. rc = opal_pci_eeh_freeze_status(phb->opal_id,
  502. pe->addr,
  503. &fstate,
  504. &pcierr,
  505. NULL);
  506. if (rc != OPAL_SUCCESS) {
  507. pr_warn("%s: Failure %lld getting PHB#%x state\n",
  508. __func__, rc, phb->hose->global_number);
  509. return EEH_STATE_NOT_SUPPORT;
  510. }
  511. /*
  512. * Check PHB state. If the PHB is frozen for the
  513. * first time, to dump the PHB diag-data.
  514. */
  515. if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
  516. result = (EEH_STATE_MMIO_ACTIVE |
  517. EEH_STATE_DMA_ACTIVE |
  518. EEH_STATE_MMIO_ENABLED |
  519. EEH_STATE_DMA_ENABLED);
  520. } else if (!(pe->state & EEH_PE_ISOLATED)) {
  521. eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
  522. pnv_eeh_get_phb_diag(pe);
  523. if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
  524. pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
  525. }
  526. return result;
  527. }
  528. static int pnv_eeh_get_pe_state(struct eeh_pe *pe)
  529. {
  530. struct pnv_phb *phb = pe->phb->private_data;
  531. u8 fstate = 0;
  532. __be16 pcierr = 0;
  533. s64 rc;
  534. int result;
  535. /*
  536. * We don't clobber hardware frozen state until PE
  537. * reset is completed. In order to keep EEH core
  538. * moving forward, we have to return operational
  539. * state during PE reset.
  540. */
  541. if (pe->state & EEH_PE_RESET) {
  542. result = (EEH_STATE_MMIO_ACTIVE |
  543. EEH_STATE_DMA_ACTIVE |
  544. EEH_STATE_MMIO_ENABLED |
  545. EEH_STATE_DMA_ENABLED);
  546. return result;
  547. }
  548. /*
  549. * Fetch PE state from hardware. If the PHB
  550. * supports compound PE, let it handle that.
  551. */
  552. if (phb->get_pe_state) {
  553. fstate = phb->get_pe_state(phb, pe->addr);
  554. } else {
  555. rc = opal_pci_eeh_freeze_status(phb->opal_id,
  556. pe->addr,
  557. &fstate,
  558. &pcierr,
  559. NULL);
  560. if (rc != OPAL_SUCCESS) {
  561. pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
  562. __func__, rc, phb->hose->global_number,
  563. pe->addr);
  564. return EEH_STATE_NOT_SUPPORT;
  565. }
  566. }
  567. /* Figure out state */
  568. switch (fstate) {
  569. case OPAL_EEH_STOPPED_NOT_FROZEN:
  570. result = (EEH_STATE_MMIO_ACTIVE |
  571. EEH_STATE_DMA_ACTIVE |
  572. EEH_STATE_MMIO_ENABLED |
  573. EEH_STATE_DMA_ENABLED);
  574. break;
  575. case OPAL_EEH_STOPPED_MMIO_FREEZE:
  576. result = (EEH_STATE_DMA_ACTIVE |
  577. EEH_STATE_DMA_ENABLED);
  578. break;
  579. case OPAL_EEH_STOPPED_DMA_FREEZE:
  580. result = (EEH_STATE_MMIO_ACTIVE |
  581. EEH_STATE_MMIO_ENABLED);
  582. break;
  583. case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
  584. result = 0;
  585. break;
  586. case OPAL_EEH_STOPPED_RESET:
  587. result = EEH_STATE_RESET_ACTIVE;
  588. break;
  589. case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
  590. result = EEH_STATE_UNAVAILABLE;
  591. break;
  592. case OPAL_EEH_STOPPED_PERM_UNAVAIL:
  593. result = EEH_STATE_NOT_SUPPORT;
  594. break;
  595. default:
  596. result = EEH_STATE_NOT_SUPPORT;
  597. pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
  598. __func__, phb->hose->global_number,
  599. pe->addr, fstate);
  600. }
  601. /*
  602. * If PHB supports compound PE, to freeze all
  603. * slave PEs for consistency.
  604. *
  605. * If the PE is switching to frozen state for the
  606. * first time, to dump the PHB diag-data.
  607. */
  608. if (!(result & EEH_STATE_NOT_SUPPORT) &&
  609. !(result & EEH_STATE_UNAVAILABLE) &&
  610. !(result & EEH_STATE_MMIO_ACTIVE) &&
  611. !(result & EEH_STATE_DMA_ACTIVE) &&
  612. !(pe->state & EEH_PE_ISOLATED)) {
  613. if (phb->freeze_pe)
  614. phb->freeze_pe(phb, pe->addr);
  615. eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
  616. pnv_eeh_get_phb_diag(pe);
  617. if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
  618. pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
  619. }
  620. return result;
  621. }
  622. /**
  623. * pnv_eeh_get_state - Retrieve PE state
  624. * @pe: EEH PE
  625. * @delay: delay while PE state is temporarily unavailable
  626. *
  627. * Retrieve the state of the specified PE. For IODA-compitable
  628. * platform, it should be retrieved from IODA table. Therefore,
  629. * we prefer passing down to hardware implementation to handle
  630. * it.
  631. */
  632. static int pnv_eeh_get_state(struct eeh_pe *pe, int *delay)
  633. {
  634. int ret;
  635. if (pe->type & EEH_PE_PHB)
  636. ret = pnv_eeh_get_phb_state(pe);
  637. else
  638. ret = pnv_eeh_get_pe_state(pe);
  639. if (!delay)
  640. return ret;
  641. /*
  642. * If the PE state is temporarily unavailable,
  643. * to inform the EEH core delay for default
  644. * period (1 second)
  645. */
  646. *delay = 0;
  647. if (ret & EEH_STATE_UNAVAILABLE)
  648. *delay = 1000;
  649. return ret;
  650. }
  651. static s64 pnv_eeh_poll(unsigned long id)
  652. {
  653. s64 rc = OPAL_HARDWARE;
  654. while (1) {
  655. rc = opal_pci_poll(id);
  656. if (rc <= 0)
  657. break;
  658. if (system_state < SYSTEM_RUNNING)
  659. udelay(1000 * rc);
  660. else
  661. msleep(rc);
  662. }
  663. return rc;
  664. }
  665. int pnv_eeh_phb_reset(struct pci_controller *hose, int option)
  666. {
  667. struct pnv_phb *phb = hose->private_data;
  668. s64 rc = OPAL_HARDWARE;
  669. pr_debug("%s: Reset PHB#%x, option=%d\n",
  670. __func__, hose->global_number, option);
  671. /* Issue PHB complete reset request */
  672. if (option == EEH_RESET_FUNDAMENTAL ||
  673. option == EEH_RESET_HOT)
  674. rc = opal_pci_reset(phb->opal_id,
  675. OPAL_RESET_PHB_COMPLETE,
  676. OPAL_ASSERT_RESET);
  677. else if (option == EEH_RESET_DEACTIVATE)
  678. rc = opal_pci_reset(phb->opal_id,
  679. OPAL_RESET_PHB_COMPLETE,
  680. OPAL_DEASSERT_RESET);
  681. if (rc < 0)
  682. goto out;
  683. /*
  684. * Poll state of the PHB until the request is done
  685. * successfully. The PHB reset is usually PHB complete
  686. * reset followed by hot reset on root bus. So we also
  687. * need the PCI bus settlement delay.
  688. */
  689. if (rc > 0)
  690. rc = pnv_eeh_poll(phb->opal_id);
  691. if (option == EEH_RESET_DEACTIVATE) {
  692. if (system_state < SYSTEM_RUNNING)
  693. udelay(1000 * EEH_PE_RST_SETTLE_TIME);
  694. else
  695. msleep(EEH_PE_RST_SETTLE_TIME);
  696. }
  697. out:
  698. if (rc != OPAL_SUCCESS)
  699. return -EIO;
  700. return 0;
  701. }
  702. static int pnv_eeh_root_reset(struct pci_controller *hose, int option)
  703. {
  704. struct pnv_phb *phb = hose->private_data;
  705. s64 rc = OPAL_HARDWARE;
  706. pr_debug("%s: Reset PHB#%x, option=%d\n",
  707. __func__, hose->global_number, option);
  708. /*
  709. * During the reset deassert time, we needn't care
  710. * the reset scope because the firmware does nothing
  711. * for fundamental or hot reset during deassert phase.
  712. */
  713. if (option == EEH_RESET_FUNDAMENTAL)
  714. rc = opal_pci_reset(phb->opal_id,
  715. OPAL_RESET_PCI_FUNDAMENTAL,
  716. OPAL_ASSERT_RESET);
  717. else if (option == EEH_RESET_HOT)
  718. rc = opal_pci_reset(phb->opal_id,
  719. OPAL_RESET_PCI_HOT,
  720. OPAL_ASSERT_RESET);
  721. else if (option == EEH_RESET_DEACTIVATE)
  722. rc = opal_pci_reset(phb->opal_id,
  723. OPAL_RESET_PCI_HOT,
  724. OPAL_DEASSERT_RESET);
  725. if (rc < 0)
  726. goto out;
  727. /* Poll state of the PHB until the request is done */
  728. if (rc > 0)
  729. rc = pnv_eeh_poll(phb->opal_id);
  730. if (option == EEH_RESET_DEACTIVATE)
  731. msleep(EEH_PE_RST_SETTLE_TIME);
  732. out:
  733. if (rc != OPAL_SUCCESS)
  734. return -EIO;
  735. return 0;
  736. }
  737. static int __pnv_eeh_bridge_reset(struct pci_dev *dev, int option)
  738. {
  739. struct pci_dn *pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
  740. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  741. int aer = edev ? edev->aer_cap : 0;
  742. u32 ctrl;
  743. pr_debug("%s: Reset PCI bus %04x:%02x with option %d\n",
  744. __func__, pci_domain_nr(dev->bus),
  745. dev->bus->number, option);
  746. switch (option) {
  747. case EEH_RESET_FUNDAMENTAL:
  748. case EEH_RESET_HOT:
  749. /* Don't report linkDown event */
  750. if (aer) {
  751. eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
  752. 4, &ctrl);
  753. ctrl |= PCI_ERR_UNC_SURPDN;
  754. eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
  755. 4, ctrl);
  756. }
  757. eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
  758. ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
  759. eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
  760. msleep(EEH_PE_RST_HOLD_TIME);
  761. break;
  762. case EEH_RESET_DEACTIVATE:
  763. eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &ctrl);
  764. ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  765. eeh_ops->write_config(pdn, PCI_BRIDGE_CONTROL, 2, ctrl);
  766. msleep(EEH_PE_RST_SETTLE_TIME);
  767. /* Continue reporting linkDown event */
  768. if (aer) {
  769. eeh_ops->read_config(pdn, aer + PCI_ERR_UNCOR_MASK,
  770. 4, &ctrl);
  771. ctrl &= ~PCI_ERR_UNC_SURPDN;
  772. eeh_ops->write_config(pdn, aer + PCI_ERR_UNCOR_MASK,
  773. 4, ctrl);
  774. }
  775. break;
  776. }
  777. return 0;
  778. }
  779. static int pnv_eeh_bridge_reset(struct pci_dev *pdev, int option)
  780. {
  781. struct pci_controller *hose = pci_bus_to_host(pdev->bus);
  782. struct pnv_phb *phb = hose->private_data;
  783. struct device_node *dn = pci_device_to_OF_node(pdev);
  784. uint64_t id = PCI_SLOT_ID(phb->opal_id,
  785. (pdev->bus->number << 8) | pdev->devfn);
  786. uint8_t scope;
  787. int64_t rc;
  788. /* Hot reset to the bus if firmware cannot handle */
  789. if (!dn || !of_get_property(dn, "ibm,reset-by-firmware", NULL))
  790. return __pnv_eeh_bridge_reset(pdev, option);
  791. switch (option) {
  792. case EEH_RESET_FUNDAMENTAL:
  793. scope = OPAL_RESET_PCI_FUNDAMENTAL;
  794. break;
  795. case EEH_RESET_HOT:
  796. scope = OPAL_RESET_PCI_HOT;
  797. break;
  798. case EEH_RESET_DEACTIVATE:
  799. return 0;
  800. default:
  801. dev_dbg(&pdev->dev, "%s: Unsupported reset %d\n",
  802. __func__, option);
  803. return -EINVAL;
  804. }
  805. rc = opal_pci_reset(id, scope, OPAL_ASSERT_RESET);
  806. if (rc <= OPAL_SUCCESS)
  807. goto out;
  808. rc = pnv_eeh_poll(id);
  809. out:
  810. return (rc == OPAL_SUCCESS) ? 0 : -EIO;
  811. }
  812. void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
  813. {
  814. struct pci_controller *hose;
  815. if (pci_is_root_bus(dev->bus)) {
  816. hose = pci_bus_to_host(dev->bus);
  817. pnv_eeh_root_reset(hose, EEH_RESET_HOT);
  818. pnv_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
  819. } else {
  820. pnv_eeh_bridge_reset(dev, EEH_RESET_HOT);
  821. pnv_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
  822. }
  823. }
  824. static void pnv_eeh_wait_for_pending(struct pci_dn *pdn, const char *type,
  825. int pos, u16 mask)
  826. {
  827. int i, status = 0;
  828. /* Wait for Transaction Pending bit to be cleared */
  829. for (i = 0; i < 4; i++) {
  830. eeh_ops->read_config(pdn, pos, 2, &status);
  831. if (!(status & mask))
  832. return;
  833. msleep((1 << i) * 100);
  834. }
  835. pr_warn("%s: Pending transaction while issuing %sFLR to %04x:%02x:%02x.%01x\n",
  836. __func__, type,
  837. pdn->phb->global_number, pdn->busno,
  838. PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
  839. }
  840. static int pnv_eeh_do_flr(struct pci_dn *pdn, int option)
  841. {
  842. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  843. u32 reg = 0;
  844. if (WARN_ON(!edev->pcie_cap))
  845. return -ENOTTY;
  846. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCAP, 4, &reg);
  847. if (!(reg & PCI_EXP_DEVCAP_FLR))
  848. return -ENOTTY;
  849. switch (option) {
  850. case EEH_RESET_HOT:
  851. case EEH_RESET_FUNDAMENTAL:
  852. pnv_eeh_wait_for_pending(pdn, "",
  853. edev->pcie_cap + PCI_EXP_DEVSTA,
  854. PCI_EXP_DEVSTA_TRPND);
  855. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  856. 4, &reg);
  857. reg |= PCI_EXP_DEVCTL_BCR_FLR;
  858. eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  859. 4, reg);
  860. msleep(EEH_PE_RST_HOLD_TIME);
  861. break;
  862. case EEH_RESET_DEACTIVATE:
  863. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  864. 4, &reg);
  865. reg &= ~PCI_EXP_DEVCTL_BCR_FLR;
  866. eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  867. 4, reg);
  868. msleep(EEH_PE_RST_SETTLE_TIME);
  869. break;
  870. }
  871. return 0;
  872. }
  873. static int pnv_eeh_do_af_flr(struct pci_dn *pdn, int option)
  874. {
  875. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  876. u32 cap = 0;
  877. if (WARN_ON(!edev->af_cap))
  878. return -ENOTTY;
  879. eeh_ops->read_config(pdn, edev->af_cap + PCI_AF_CAP, 1, &cap);
  880. if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
  881. return -ENOTTY;
  882. switch (option) {
  883. case EEH_RESET_HOT:
  884. case EEH_RESET_FUNDAMENTAL:
  885. /*
  886. * Wait for Transaction Pending bit to clear. A word-aligned
  887. * test is used, so we use the conrol offset rather than status
  888. * and shift the test bit to match.
  889. */
  890. pnv_eeh_wait_for_pending(pdn, "AF",
  891. edev->af_cap + PCI_AF_CTRL,
  892. PCI_AF_STATUS_TP << 8);
  893. eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL,
  894. 1, PCI_AF_CTRL_FLR);
  895. msleep(EEH_PE_RST_HOLD_TIME);
  896. break;
  897. case EEH_RESET_DEACTIVATE:
  898. eeh_ops->write_config(pdn, edev->af_cap + PCI_AF_CTRL, 1, 0);
  899. msleep(EEH_PE_RST_SETTLE_TIME);
  900. break;
  901. }
  902. return 0;
  903. }
  904. static int pnv_eeh_reset_vf_pe(struct eeh_pe *pe, int option)
  905. {
  906. struct eeh_dev *edev;
  907. struct pci_dn *pdn;
  908. int ret;
  909. /* The VF PE should have only one child device */
  910. edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, list);
  911. pdn = eeh_dev_to_pdn(edev);
  912. if (!pdn)
  913. return -ENXIO;
  914. ret = pnv_eeh_do_flr(pdn, option);
  915. if (!ret)
  916. return ret;
  917. return pnv_eeh_do_af_flr(pdn, option);
  918. }
  919. /**
  920. * pnv_eeh_reset - Reset the specified PE
  921. * @pe: EEH PE
  922. * @option: reset option
  923. *
  924. * Do reset on the indicated PE. For PCI bus sensitive PE,
  925. * we need to reset the parent p2p bridge. The PHB has to
  926. * be reinitialized if the p2p bridge is root bridge. For
  927. * PCI device sensitive PE, we will try to reset the device
  928. * through FLR. For now, we don't have OPAL APIs to do HARD
  929. * reset yet, so all reset would be SOFT (HOT) reset.
  930. */
  931. static int pnv_eeh_reset(struct eeh_pe *pe, int option)
  932. {
  933. struct pci_controller *hose = pe->phb;
  934. struct pnv_phb *phb;
  935. struct pci_bus *bus;
  936. int64_t rc;
  937. /*
  938. * For PHB reset, we always have complete reset. For those PEs whose
  939. * primary bus derived from root complex (root bus) or root port
  940. * (usually bus#1), we apply hot or fundamental reset on the root port.
  941. * For other PEs, we always have hot reset on the PE primary bus.
  942. *
  943. * Here, we have different design to pHyp, which always clear the
  944. * frozen state during PE reset. However, the good idea here from
  945. * benh is to keep frozen state before we get PE reset done completely
  946. * (until BAR restore). With the frozen state, HW drops illegal IO
  947. * or MMIO access, which can incur recrusive frozen PE during PE
  948. * reset. The side effect is that EEH core has to clear the frozen
  949. * state explicitly after BAR restore.
  950. */
  951. if (pe->type & EEH_PE_PHB)
  952. return pnv_eeh_phb_reset(hose, option);
  953. /*
  954. * The frozen PE might be caused by PAPR error injection
  955. * registers, which are expected to be cleared after hitting
  956. * frozen PE as stated in the hardware spec. Unfortunately,
  957. * that's not true on P7IOC. So we have to clear it manually
  958. * to avoid recursive EEH errors during recovery.
  959. */
  960. phb = hose->private_data;
  961. if (phb->model == PNV_PHB_MODEL_P7IOC &&
  962. (option == EEH_RESET_HOT ||
  963. option == EEH_RESET_FUNDAMENTAL)) {
  964. rc = opal_pci_reset(phb->opal_id,
  965. OPAL_RESET_PHB_ERROR,
  966. OPAL_ASSERT_RESET);
  967. if (rc != OPAL_SUCCESS) {
  968. pr_warn("%s: Failure %lld clearing error injection registers\n",
  969. __func__, rc);
  970. return -EIO;
  971. }
  972. }
  973. if (pe->type & EEH_PE_VF)
  974. return pnv_eeh_reset_vf_pe(pe, option);
  975. bus = eeh_pe_bus_get(pe);
  976. if (!bus) {
  977. pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
  978. __func__, pe->phb->global_number, pe->addr);
  979. return -EIO;
  980. }
  981. /*
  982. * If dealing with the root bus (or the bus underneath the
  983. * root port), we reset the bus underneath the root port.
  984. *
  985. * The cxl driver depends on this behaviour for bi-modal card
  986. * switching.
  987. */
  988. if (pci_is_root_bus(bus) ||
  989. pci_is_root_bus(bus->parent))
  990. return pnv_eeh_root_reset(hose, option);
  991. return pnv_eeh_bridge_reset(bus->self, option);
  992. }
  993. /**
  994. * pnv_eeh_wait_state - Wait for PE state
  995. * @pe: EEH PE
  996. * @max_wait: maximal period in millisecond
  997. *
  998. * Wait for the state of associated PE. It might take some time
  999. * to retrieve the PE's state.
  1000. */
  1001. static int pnv_eeh_wait_state(struct eeh_pe *pe, int max_wait)
  1002. {
  1003. int ret;
  1004. int mwait;
  1005. while (1) {
  1006. ret = pnv_eeh_get_state(pe, &mwait);
  1007. /*
  1008. * If the PE's state is temporarily unavailable,
  1009. * we have to wait for the specified time. Otherwise,
  1010. * the PE's state will be returned immediately.
  1011. */
  1012. if (ret != EEH_STATE_UNAVAILABLE)
  1013. return ret;
  1014. if (max_wait <= 0) {
  1015. pr_warn("%s: Timeout getting PE#%x's state (%d)\n",
  1016. __func__, pe->addr, max_wait);
  1017. return EEH_STATE_NOT_SUPPORT;
  1018. }
  1019. max_wait -= mwait;
  1020. msleep(mwait);
  1021. }
  1022. return EEH_STATE_NOT_SUPPORT;
  1023. }
  1024. /**
  1025. * pnv_eeh_get_log - Retrieve error log
  1026. * @pe: EEH PE
  1027. * @severity: temporary or permanent error log
  1028. * @drv_log: driver log to be combined with retrieved error log
  1029. * @len: length of driver log
  1030. *
  1031. * Retrieve the temporary or permanent error from the PE.
  1032. */
  1033. static int pnv_eeh_get_log(struct eeh_pe *pe, int severity,
  1034. char *drv_log, unsigned long len)
  1035. {
  1036. if (!eeh_has_flag(EEH_EARLY_DUMP_LOG))
  1037. pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
  1038. return 0;
  1039. }
  1040. /**
  1041. * pnv_eeh_configure_bridge - Configure PCI bridges in the indicated PE
  1042. * @pe: EEH PE
  1043. *
  1044. * The function will be called to reconfigure the bridges included
  1045. * in the specified PE so that the mulfunctional PE would be recovered
  1046. * again.
  1047. */
  1048. static int pnv_eeh_configure_bridge(struct eeh_pe *pe)
  1049. {
  1050. return 0;
  1051. }
  1052. /**
  1053. * pnv_pe_err_inject - Inject specified error to the indicated PE
  1054. * @pe: the indicated PE
  1055. * @type: error type
  1056. * @func: specific error type
  1057. * @addr: address
  1058. * @mask: address mask
  1059. *
  1060. * The routine is called to inject specified error, which is
  1061. * determined by @type and @func, to the indicated PE for
  1062. * testing purpose.
  1063. */
  1064. static int pnv_eeh_err_inject(struct eeh_pe *pe, int type, int func,
  1065. unsigned long addr, unsigned long mask)
  1066. {
  1067. struct pci_controller *hose = pe->phb;
  1068. struct pnv_phb *phb = hose->private_data;
  1069. s64 rc;
  1070. if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
  1071. type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
  1072. pr_warn("%s: Invalid error type %d\n",
  1073. __func__, type);
  1074. return -ERANGE;
  1075. }
  1076. if (func < OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR ||
  1077. func > OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET) {
  1078. pr_warn("%s: Invalid error function %d\n",
  1079. __func__, func);
  1080. return -ERANGE;
  1081. }
  1082. /* Firmware supports error injection ? */
  1083. if (!opal_check_token(OPAL_PCI_ERR_INJECT)) {
  1084. pr_warn("%s: Firmware doesn't support error injection\n",
  1085. __func__);
  1086. return -ENXIO;
  1087. }
  1088. /* Do error injection */
  1089. rc = opal_pci_err_inject(phb->opal_id, pe->addr,
  1090. type, func, addr, mask);
  1091. if (rc != OPAL_SUCCESS) {
  1092. pr_warn("%s: Failure %lld injecting error "
  1093. "%d-%d to PHB#%x-PE#%x\n",
  1094. __func__, rc, type, func,
  1095. hose->global_number, pe->addr);
  1096. return -EIO;
  1097. }
  1098. return 0;
  1099. }
  1100. static inline bool pnv_eeh_cfg_blocked(struct pci_dn *pdn)
  1101. {
  1102. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  1103. if (!edev || !edev->pe)
  1104. return false;
  1105. /*
  1106. * We will issue FLR or AF FLR to all VFs, which are contained
  1107. * in VF PE. It relies on the EEH PCI config accessors. So we
  1108. * can't block them during the window.
  1109. */
  1110. if (edev->physfn && (edev->pe->state & EEH_PE_RESET))
  1111. return false;
  1112. if (edev->pe->state & EEH_PE_CFG_BLOCKED)
  1113. return true;
  1114. return false;
  1115. }
  1116. static int pnv_eeh_read_config(struct pci_dn *pdn,
  1117. int where, int size, u32 *val)
  1118. {
  1119. if (!pdn)
  1120. return PCIBIOS_DEVICE_NOT_FOUND;
  1121. if (pnv_eeh_cfg_blocked(pdn)) {
  1122. *val = 0xFFFFFFFF;
  1123. return PCIBIOS_SET_FAILED;
  1124. }
  1125. return pnv_pci_cfg_read(pdn, where, size, val);
  1126. }
  1127. static int pnv_eeh_write_config(struct pci_dn *pdn,
  1128. int where, int size, u32 val)
  1129. {
  1130. if (!pdn)
  1131. return PCIBIOS_DEVICE_NOT_FOUND;
  1132. if (pnv_eeh_cfg_blocked(pdn))
  1133. return PCIBIOS_SET_FAILED;
  1134. return pnv_pci_cfg_write(pdn, where, size, val);
  1135. }
  1136. static void pnv_eeh_dump_hub_diag_common(struct OpalIoP7IOCErrorData *data)
  1137. {
  1138. /* GEM */
  1139. if (data->gemXfir || data->gemRfir ||
  1140. data->gemRirqfir || data->gemMask || data->gemRwof)
  1141. pr_info(" GEM: %016llx %016llx %016llx %016llx %016llx\n",
  1142. be64_to_cpu(data->gemXfir),
  1143. be64_to_cpu(data->gemRfir),
  1144. be64_to_cpu(data->gemRirqfir),
  1145. be64_to_cpu(data->gemMask),
  1146. be64_to_cpu(data->gemRwof));
  1147. /* LEM */
  1148. if (data->lemFir || data->lemErrMask ||
  1149. data->lemAction0 || data->lemAction1 || data->lemWof)
  1150. pr_info(" LEM: %016llx %016llx %016llx %016llx %016llx\n",
  1151. be64_to_cpu(data->lemFir),
  1152. be64_to_cpu(data->lemErrMask),
  1153. be64_to_cpu(data->lemAction0),
  1154. be64_to_cpu(data->lemAction1),
  1155. be64_to_cpu(data->lemWof));
  1156. }
  1157. static void pnv_eeh_get_and_dump_hub_diag(struct pci_controller *hose)
  1158. {
  1159. struct pnv_phb *phb = hose->private_data;
  1160. struct OpalIoP7IOCErrorData *data =
  1161. (struct OpalIoP7IOCErrorData*)phb->diag_data;
  1162. long rc;
  1163. rc = opal_pci_get_hub_diag_data(phb->hub_id, data, sizeof(*data));
  1164. if (rc != OPAL_SUCCESS) {
  1165. pr_warn("%s: Failed to get HUB#%llx diag-data (%ld)\n",
  1166. __func__, phb->hub_id, rc);
  1167. return;
  1168. }
  1169. switch (be16_to_cpu(data->type)) {
  1170. case OPAL_P7IOC_DIAG_TYPE_RGC:
  1171. pr_info("P7IOC diag-data for RGC\n\n");
  1172. pnv_eeh_dump_hub_diag_common(data);
  1173. if (data->rgc.rgcStatus || data->rgc.rgcLdcp)
  1174. pr_info(" RGC: %016llx %016llx\n",
  1175. be64_to_cpu(data->rgc.rgcStatus),
  1176. be64_to_cpu(data->rgc.rgcLdcp));
  1177. break;
  1178. case OPAL_P7IOC_DIAG_TYPE_BI:
  1179. pr_info("P7IOC diag-data for BI %s\n\n",
  1180. data->bi.biDownbound ? "Downbound" : "Upbound");
  1181. pnv_eeh_dump_hub_diag_common(data);
  1182. if (data->bi.biLdcp0 || data->bi.biLdcp1 ||
  1183. data->bi.biLdcp2 || data->bi.biFenceStatus)
  1184. pr_info(" BI: %016llx %016llx %016llx %016llx\n",
  1185. be64_to_cpu(data->bi.biLdcp0),
  1186. be64_to_cpu(data->bi.biLdcp1),
  1187. be64_to_cpu(data->bi.biLdcp2),
  1188. be64_to_cpu(data->bi.biFenceStatus));
  1189. break;
  1190. case OPAL_P7IOC_DIAG_TYPE_CI:
  1191. pr_info("P7IOC diag-data for CI Port %d\n\n",
  1192. data->ci.ciPort);
  1193. pnv_eeh_dump_hub_diag_common(data);
  1194. if (data->ci.ciPortStatus || data->ci.ciPortLdcp)
  1195. pr_info(" CI: %016llx %016llx\n",
  1196. be64_to_cpu(data->ci.ciPortStatus),
  1197. be64_to_cpu(data->ci.ciPortLdcp));
  1198. break;
  1199. case OPAL_P7IOC_DIAG_TYPE_MISC:
  1200. pr_info("P7IOC diag-data for MISC\n\n");
  1201. pnv_eeh_dump_hub_diag_common(data);
  1202. break;
  1203. case OPAL_P7IOC_DIAG_TYPE_I2C:
  1204. pr_info("P7IOC diag-data for I2C\n\n");
  1205. pnv_eeh_dump_hub_diag_common(data);
  1206. break;
  1207. default:
  1208. pr_warn("%s: Invalid type of HUB#%llx diag-data (%d)\n",
  1209. __func__, phb->hub_id, data->type);
  1210. }
  1211. }
  1212. static int pnv_eeh_get_pe(struct pci_controller *hose,
  1213. u16 pe_no, struct eeh_pe **pe)
  1214. {
  1215. struct pnv_phb *phb = hose->private_data;
  1216. struct pnv_ioda_pe *pnv_pe;
  1217. struct eeh_pe *dev_pe;
  1218. /*
  1219. * If PHB supports compound PE, to fetch
  1220. * the master PE because slave PE is invisible
  1221. * to EEH core.
  1222. */
  1223. pnv_pe = &phb->ioda.pe_array[pe_no];
  1224. if (pnv_pe->flags & PNV_IODA_PE_SLAVE) {
  1225. pnv_pe = pnv_pe->master;
  1226. WARN_ON(!pnv_pe ||
  1227. !(pnv_pe->flags & PNV_IODA_PE_MASTER));
  1228. pe_no = pnv_pe->pe_number;
  1229. }
  1230. /* Find the PE according to PE# */
  1231. dev_pe = eeh_pe_get(hose, pe_no, 0);
  1232. if (!dev_pe)
  1233. return -EEXIST;
  1234. /* Freeze the (compound) PE */
  1235. *pe = dev_pe;
  1236. if (!(dev_pe->state & EEH_PE_ISOLATED))
  1237. phb->freeze_pe(phb, pe_no);
  1238. /*
  1239. * At this point, we're sure the (compound) PE should
  1240. * have been frozen. However, we still need poke until
  1241. * hitting the frozen PE on top level.
  1242. */
  1243. dev_pe = dev_pe->parent;
  1244. while (dev_pe && !(dev_pe->type & EEH_PE_PHB)) {
  1245. int ret;
  1246. ret = eeh_ops->get_state(dev_pe, NULL);
  1247. if (ret <= 0 || eeh_state_active(ret)) {
  1248. dev_pe = dev_pe->parent;
  1249. continue;
  1250. }
  1251. /* Frozen parent PE */
  1252. *pe = dev_pe;
  1253. if (!(dev_pe->state & EEH_PE_ISOLATED))
  1254. phb->freeze_pe(phb, dev_pe->addr);
  1255. /* Next one */
  1256. dev_pe = dev_pe->parent;
  1257. }
  1258. return 0;
  1259. }
  1260. /**
  1261. * pnv_eeh_next_error - Retrieve next EEH error to handle
  1262. * @pe: Affected PE
  1263. *
  1264. * The function is expected to be called by EEH core while it gets
  1265. * special EEH event (without binding PE). The function calls to
  1266. * OPAL APIs for next error to handle. The informational error is
  1267. * handled internally by platform. However, the dead IOC, dead PHB,
  1268. * fenced PHB and frozen PE should be handled by EEH core eventually.
  1269. */
  1270. static int pnv_eeh_next_error(struct eeh_pe **pe)
  1271. {
  1272. struct pci_controller *hose;
  1273. struct pnv_phb *phb;
  1274. struct eeh_pe *phb_pe, *parent_pe;
  1275. __be64 frozen_pe_no;
  1276. __be16 err_type, severity;
  1277. long rc;
  1278. int state, ret = EEH_NEXT_ERR_NONE;
  1279. /*
  1280. * While running here, it's safe to purge the event queue. The
  1281. * event should still be masked.
  1282. */
  1283. eeh_remove_event(NULL, false);
  1284. list_for_each_entry(hose, &hose_list, list_node) {
  1285. /*
  1286. * If the subordinate PCI buses of the PHB has been
  1287. * removed or is exactly under error recovery, we
  1288. * needn't take care of it any more.
  1289. */
  1290. phb = hose->private_data;
  1291. phb_pe = eeh_phb_pe_get(hose);
  1292. if (!phb_pe || (phb_pe->state & EEH_PE_ISOLATED))
  1293. continue;
  1294. rc = opal_pci_next_error(phb->opal_id,
  1295. &frozen_pe_no, &err_type, &severity);
  1296. if (rc != OPAL_SUCCESS) {
  1297. pr_devel("%s: Invalid return value on "
  1298. "PHB#%x (0x%lx) from opal_pci_next_error",
  1299. __func__, hose->global_number, rc);
  1300. continue;
  1301. }
  1302. /* If the PHB doesn't have error, stop processing */
  1303. if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR ||
  1304. be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) {
  1305. pr_devel("%s: No error found on PHB#%x\n",
  1306. __func__, hose->global_number);
  1307. continue;
  1308. }
  1309. /*
  1310. * Processing the error. We're expecting the error with
  1311. * highest priority reported upon multiple errors on the
  1312. * specific PHB.
  1313. */
  1314. pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n",
  1315. __func__, be16_to_cpu(err_type),
  1316. be16_to_cpu(severity), be64_to_cpu(frozen_pe_no),
  1317. hose->global_number);
  1318. switch (be16_to_cpu(err_type)) {
  1319. case OPAL_EEH_IOC_ERROR:
  1320. if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) {
  1321. pr_err("EEH: dead IOC detected\n");
  1322. ret = EEH_NEXT_ERR_DEAD_IOC;
  1323. } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
  1324. pr_info("EEH: IOC informative error "
  1325. "detected\n");
  1326. pnv_eeh_get_and_dump_hub_diag(hose);
  1327. ret = EEH_NEXT_ERR_NONE;
  1328. }
  1329. break;
  1330. case OPAL_EEH_PHB_ERROR:
  1331. if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) {
  1332. *pe = phb_pe;
  1333. pr_err("EEH: dead PHB#%x detected, "
  1334. "location: %s\n",
  1335. hose->global_number,
  1336. eeh_pe_loc_get(phb_pe));
  1337. ret = EEH_NEXT_ERR_DEAD_PHB;
  1338. } else if (be16_to_cpu(severity) ==
  1339. OPAL_EEH_SEV_PHB_FENCED) {
  1340. *pe = phb_pe;
  1341. pr_err("EEH: Fenced PHB#%x detected, "
  1342. "location: %s\n",
  1343. hose->global_number,
  1344. eeh_pe_loc_get(phb_pe));
  1345. ret = EEH_NEXT_ERR_FENCED_PHB;
  1346. } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
  1347. pr_info("EEH: PHB#%x informative error "
  1348. "detected, location: %s\n",
  1349. hose->global_number,
  1350. eeh_pe_loc_get(phb_pe));
  1351. pnv_eeh_get_phb_diag(phb_pe);
  1352. pnv_pci_dump_phb_diag_data(hose, phb_pe->data);
  1353. ret = EEH_NEXT_ERR_NONE;
  1354. }
  1355. break;
  1356. case OPAL_EEH_PE_ERROR:
  1357. /*
  1358. * If we can't find the corresponding PE, we
  1359. * just try to unfreeze.
  1360. */
  1361. if (pnv_eeh_get_pe(hose,
  1362. be64_to_cpu(frozen_pe_no), pe)) {
  1363. pr_info("EEH: Clear non-existing PHB#%x-PE#%llx\n",
  1364. hose->global_number, be64_to_cpu(frozen_pe_no));
  1365. pr_info("EEH: PHB location: %s\n",
  1366. eeh_pe_loc_get(phb_pe));
  1367. /* Dump PHB diag-data */
  1368. rc = opal_pci_get_phb_diag_data2(phb->opal_id,
  1369. phb->diag_data, phb->diag_data_size);
  1370. if (rc == OPAL_SUCCESS)
  1371. pnv_pci_dump_phb_diag_data(hose,
  1372. phb->diag_data);
  1373. /* Try best to clear it */
  1374. opal_pci_eeh_freeze_clear(phb->opal_id,
  1375. be64_to_cpu(frozen_pe_no),
  1376. OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
  1377. ret = EEH_NEXT_ERR_NONE;
  1378. } else if ((*pe)->state & EEH_PE_ISOLATED ||
  1379. eeh_pe_passed(*pe)) {
  1380. ret = EEH_NEXT_ERR_NONE;
  1381. } else {
  1382. pr_err("EEH: Frozen PE#%x "
  1383. "on PHB#%x detected\n",
  1384. (*pe)->addr,
  1385. (*pe)->phb->global_number);
  1386. pr_err("EEH: PE location: %s, "
  1387. "PHB location: %s\n",
  1388. eeh_pe_loc_get(*pe),
  1389. eeh_pe_loc_get(phb_pe));
  1390. ret = EEH_NEXT_ERR_FROZEN_PE;
  1391. }
  1392. break;
  1393. default:
  1394. pr_warn("%s: Unexpected error type %d\n",
  1395. __func__, be16_to_cpu(err_type));
  1396. }
  1397. /*
  1398. * EEH core will try recover from fenced PHB or
  1399. * frozen PE. In the time for frozen PE, EEH core
  1400. * enable IO path for that before collecting logs,
  1401. * but it ruins the site. So we have to dump the
  1402. * log in advance here.
  1403. */
  1404. if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
  1405. ret == EEH_NEXT_ERR_FENCED_PHB) &&
  1406. !((*pe)->state & EEH_PE_ISOLATED)) {
  1407. eeh_pe_state_mark(*pe, EEH_PE_ISOLATED);
  1408. pnv_eeh_get_phb_diag(*pe);
  1409. if (eeh_has_flag(EEH_EARLY_DUMP_LOG))
  1410. pnv_pci_dump_phb_diag_data((*pe)->phb,
  1411. (*pe)->data);
  1412. }
  1413. /*
  1414. * We probably have the frozen parent PE out there and
  1415. * we need have to handle frozen parent PE firstly.
  1416. */
  1417. if (ret == EEH_NEXT_ERR_FROZEN_PE) {
  1418. parent_pe = (*pe)->parent;
  1419. while (parent_pe) {
  1420. /* Hit the ceiling ? */
  1421. if (parent_pe->type & EEH_PE_PHB)
  1422. break;
  1423. /* Frozen parent PE ? */
  1424. state = eeh_ops->get_state(parent_pe, NULL);
  1425. if (state > 0 && !eeh_state_active(state))
  1426. *pe = parent_pe;
  1427. /* Next parent level */
  1428. parent_pe = parent_pe->parent;
  1429. }
  1430. /* We possibly migrate to another PE */
  1431. eeh_pe_state_mark(*pe, EEH_PE_ISOLATED);
  1432. }
  1433. /*
  1434. * If we have no errors on the specific PHB or only
  1435. * informative error there, we continue poking it.
  1436. * Otherwise, we need actions to be taken by upper
  1437. * layer.
  1438. */
  1439. if (ret > EEH_NEXT_ERR_INF)
  1440. break;
  1441. }
  1442. /* Unmask the event */
  1443. if (ret == EEH_NEXT_ERR_NONE && eeh_enabled())
  1444. enable_irq(eeh_event_irq);
  1445. return ret;
  1446. }
  1447. static int pnv_eeh_restore_config(struct pci_dn *pdn)
  1448. {
  1449. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  1450. struct pnv_phb *phb;
  1451. s64 ret = 0;
  1452. int config_addr = (pdn->busno << 8) | (pdn->devfn);
  1453. if (!edev)
  1454. return -EEXIST;
  1455. /*
  1456. * We have to restore the PCI config space after reset since the
  1457. * firmware can't see SRIOV VFs.
  1458. *
  1459. * FIXME: The MPS, error routing rules, timeout setting are worthy
  1460. * to be exported by firmware in extendible way.
  1461. */
  1462. if (edev->physfn) {
  1463. ret = eeh_restore_vf_config(pdn);
  1464. } else {
  1465. phb = pdn->phb->private_data;
  1466. ret = opal_pci_reinit(phb->opal_id,
  1467. OPAL_REINIT_PCI_DEV, config_addr);
  1468. }
  1469. if (ret) {
  1470. pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
  1471. __func__, config_addr, ret);
  1472. return -EIO;
  1473. }
  1474. return ret;
  1475. }
  1476. static struct eeh_ops pnv_eeh_ops = {
  1477. .name = "powernv",
  1478. .init = pnv_eeh_init,
  1479. .probe = pnv_eeh_probe,
  1480. .set_option = pnv_eeh_set_option,
  1481. .get_pe_addr = pnv_eeh_get_pe_addr,
  1482. .get_state = pnv_eeh_get_state,
  1483. .reset = pnv_eeh_reset,
  1484. .wait_state = pnv_eeh_wait_state,
  1485. .get_log = pnv_eeh_get_log,
  1486. .configure_bridge = pnv_eeh_configure_bridge,
  1487. .err_inject = pnv_eeh_err_inject,
  1488. .read_config = pnv_eeh_read_config,
  1489. .write_config = pnv_eeh_write_config,
  1490. .next_error = pnv_eeh_next_error,
  1491. .restore_config = pnv_eeh_restore_config,
  1492. .notify_resume = NULL
  1493. };
  1494. #ifdef CONFIG_PCI_IOV
  1495. static void pnv_pci_fixup_vf_mps(struct pci_dev *pdev)
  1496. {
  1497. struct pci_dn *pdn = pci_get_pdn(pdev);
  1498. int parent_mps;
  1499. if (!pdev->is_virtfn)
  1500. return;
  1501. /* Synchronize MPS for VF and PF */
  1502. parent_mps = pcie_get_mps(pdev->physfn);
  1503. if ((128 << pdev->pcie_mpss) >= parent_mps)
  1504. pcie_set_mps(pdev, parent_mps);
  1505. pdn->mps = pcie_get_mps(pdev);
  1506. }
  1507. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_pci_fixup_vf_mps);
  1508. #endif /* CONFIG_PCI_IOV */
  1509. /**
  1510. * eeh_powernv_init - Register platform dependent EEH operations
  1511. *
  1512. * EEH initialization on powernv platform. This function should be
  1513. * called before any EEH related functions.
  1514. */
  1515. static int __init eeh_powernv_init(void)
  1516. {
  1517. int ret = -EINVAL;
  1518. ret = eeh_ops_register(&pnv_eeh_ops);
  1519. if (!ret)
  1520. pr_info("EEH: PowerNV platform initialized\n");
  1521. else
  1522. pr_info("EEH: Failed to initialize PowerNV platform (%d)\n", ret);
  1523. return ret;
  1524. }
  1525. machine_early_initcall(powernv, eeh_powernv_init);