eeh-powernv.c 46 KB

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