eeh.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  1. /*
  2. * Copyright IBM Corporation 2001, 2005, 2006
  3. * Copyright Dave Engebretsen & Todd Inglett 2001
  4. * Copyright Linas Vepstas 2005, 2006
  5. * Copyright 2001-2012 IBM Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * Please address comments and feedback to Linas Vepstas <linas@austin.ibm.com>
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/sched.h>
  25. #include <linux/init.h>
  26. #include <linux/list.h>
  27. #include <linux/pci.h>
  28. #include <linux/iommu.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/rbtree.h>
  31. #include <linux/reboot.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/export.h>
  35. #include <linux/of.h>
  36. #include <linux/atomic.h>
  37. #include <asm/debugfs.h>
  38. #include <asm/eeh.h>
  39. #include <asm/eeh_event.h>
  40. #include <asm/io.h>
  41. #include <asm/iommu.h>
  42. #include <asm/machdep.h>
  43. #include <asm/ppc-pci.h>
  44. #include <asm/rtas.h>
  45. #include <asm/pte-walk.h>
  46. /** Overview:
  47. * EEH, or "Enhanced Error Handling" is a PCI bridge technology for
  48. * dealing with PCI bus errors that can't be dealt with within the
  49. * usual PCI framework, except by check-stopping the CPU. Systems
  50. * that are designed for high-availability/reliability cannot afford
  51. * to crash due to a "mere" PCI error, thus the need for EEH.
  52. * An EEH-capable bridge operates by converting a detected error
  53. * into a "slot freeze", taking the PCI adapter off-line, making
  54. * the slot behave, from the OS'es point of view, as if the slot
  55. * were "empty": all reads return 0xff's and all writes are silently
  56. * ignored. EEH slot isolation events can be triggered by parity
  57. * errors on the address or data busses (e.g. during posted writes),
  58. * which in turn might be caused by low voltage on the bus, dust,
  59. * vibration, humidity, radioactivity or plain-old failed hardware.
  60. *
  61. * Note, however, that one of the leading causes of EEH slot
  62. * freeze events are buggy device drivers, buggy device microcode,
  63. * or buggy device hardware. This is because any attempt by the
  64. * device to bus-master data to a memory address that is not
  65. * assigned to the device will trigger a slot freeze. (The idea
  66. * is to prevent devices-gone-wild from corrupting system memory).
  67. * Buggy hardware/drivers will have a miserable time co-existing
  68. * with EEH.
  69. *
  70. * Ideally, a PCI device driver, when suspecting that an isolation
  71. * event has occurred (e.g. by reading 0xff's), will then ask EEH
  72. * whether this is the case, and then take appropriate steps to
  73. * reset the PCI slot, the PCI device, and then resume operations.
  74. * However, until that day, the checking is done here, with the
  75. * eeh_check_failure() routine embedded in the MMIO macros. If
  76. * the slot is found to be isolated, an "EEH Event" is synthesized
  77. * and sent out for processing.
  78. */
  79. /* If a device driver keeps reading an MMIO register in an interrupt
  80. * handler after a slot isolation event, it might be broken.
  81. * This sets the threshold for how many read attempts we allow
  82. * before printing an error message.
  83. */
  84. #define EEH_MAX_FAILS 2100000
  85. /* Time to wait for a PCI slot to report status, in milliseconds */
  86. #define PCI_BUS_RESET_WAIT_MSEC (5*60*1000)
  87. /*
  88. * EEH probe mode support, which is part of the flags,
  89. * is to support multiple platforms for EEH. Some platforms
  90. * like pSeries do PCI emunation based on device tree.
  91. * However, other platforms like powernv probe PCI devices
  92. * from hardware. The flag is used to distinguish that.
  93. * In addition, struct eeh_ops::probe would be invoked for
  94. * particular OF node or PCI device so that the corresponding
  95. * PE would be created there.
  96. */
  97. int eeh_subsystem_flags;
  98. EXPORT_SYMBOL(eeh_subsystem_flags);
  99. /*
  100. * EEH allowed maximal frozen times. If one particular PE's
  101. * frozen count in last hour exceeds this limit, the PE will
  102. * be forced to be offline permanently.
  103. */
  104. int eeh_max_freezes = 5;
  105. /* Platform dependent EEH operations */
  106. struct eeh_ops *eeh_ops = NULL;
  107. /* Lock to avoid races due to multiple reports of an error */
  108. DEFINE_RAW_SPINLOCK(confirm_error_lock);
  109. EXPORT_SYMBOL_GPL(confirm_error_lock);
  110. /* Lock to protect passed flags */
  111. static DEFINE_MUTEX(eeh_dev_mutex);
  112. /* Buffer for reporting pci register dumps. Its here in BSS, and
  113. * not dynamically alloced, so that it ends up in RMO where RTAS
  114. * can access it.
  115. */
  116. #define EEH_PCI_REGS_LOG_LEN 8192
  117. static unsigned char pci_regs_buf[EEH_PCI_REGS_LOG_LEN];
  118. /*
  119. * The struct is used to maintain the EEH global statistic
  120. * information. Besides, the EEH global statistics will be
  121. * exported to user space through procfs
  122. */
  123. struct eeh_stats {
  124. u64 no_device; /* PCI device not found */
  125. u64 no_dn; /* OF node not found */
  126. u64 no_cfg_addr; /* Config address not found */
  127. u64 ignored_check; /* EEH check skipped */
  128. u64 total_mmio_ffs; /* Total EEH checks */
  129. u64 false_positives; /* Unnecessary EEH checks */
  130. u64 slot_resets; /* PE reset */
  131. };
  132. static struct eeh_stats eeh_stats;
  133. static int __init eeh_setup(char *str)
  134. {
  135. if (!strcmp(str, "off"))
  136. eeh_add_flag(EEH_FORCE_DISABLED);
  137. else if (!strcmp(str, "early_log"))
  138. eeh_add_flag(EEH_EARLY_DUMP_LOG);
  139. return 1;
  140. }
  141. __setup("eeh=", eeh_setup);
  142. /*
  143. * This routine captures assorted PCI configuration space data
  144. * for the indicated PCI device, and puts them into a buffer
  145. * for RTAS error logging.
  146. */
  147. static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
  148. {
  149. struct pci_dn *pdn = eeh_dev_to_pdn(edev);
  150. u32 cfg;
  151. int cap, i;
  152. int n = 0, l = 0;
  153. char buffer[128];
  154. if (!pdn) {
  155. pr_warn("EEH: Note: No error log for absent device.\n");
  156. return 0;
  157. }
  158. n += scnprintf(buf+n, len-n, "%04x:%02x:%02x.%01x\n",
  159. pdn->phb->global_number, pdn->busno,
  160. PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
  161. pr_warn("EEH: of node=%04x:%02x:%02x.%01x\n",
  162. pdn->phb->global_number, pdn->busno,
  163. PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
  164. eeh_ops->read_config(pdn, PCI_VENDOR_ID, 4, &cfg);
  165. n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
  166. pr_warn("EEH: PCI device/vendor: %08x\n", cfg);
  167. eeh_ops->read_config(pdn, PCI_COMMAND, 4, &cfg);
  168. n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg);
  169. pr_warn("EEH: PCI cmd/status register: %08x\n", cfg);
  170. /* Gather bridge-specific registers */
  171. if (edev->mode & EEH_DEV_BRIDGE) {
  172. eeh_ops->read_config(pdn, PCI_SEC_STATUS, 2, &cfg);
  173. n += scnprintf(buf+n, len-n, "sec stat:%x\n", cfg);
  174. pr_warn("EEH: Bridge secondary status: %04x\n", cfg);
  175. eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &cfg);
  176. n += scnprintf(buf+n, len-n, "brdg ctl:%x\n", cfg);
  177. pr_warn("EEH: Bridge control: %04x\n", cfg);
  178. }
  179. /* Dump out the PCI-X command and status regs */
  180. cap = edev->pcix_cap;
  181. if (cap) {
  182. eeh_ops->read_config(pdn, cap, 4, &cfg);
  183. n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg);
  184. pr_warn("EEH: PCI-X cmd: %08x\n", cfg);
  185. eeh_ops->read_config(pdn, cap+4, 4, &cfg);
  186. n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg);
  187. pr_warn("EEH: PCI-X status: %08x\n", cfg);
  188. }
  189. /* If PCI-E capable, dump PCI-E cap 10 */
  190. cap = edev->pcie_cap;
  191. if (cap) {
  192. n += scnprintf(buf+n, len-n, "pci-e cap10:\n");
  193. pr_warn("EEH: PCI-E capabilities and status follow:\n");
  194. for (i=0; i<=8; i++) {
  195. eeh_ops->read_config(pdn, cap+4*i, 4, &cfg);
  196. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  197. if ((i % 4) == 0) {
  198. if (i != 0)
  199. pr_warn("%s\n", buffer);
  200. l = scnprintf(buffer, sizeof(buffer),
  201. "EEH: PCI-E %02x: %08x ",
  202. 4*i, cfg);
  203. } else {
  204. l += scnprintf(buffer+l, sizeof(buffer)-l,
  205. "%08x ", cfg);
  206. }
  207. }
  208. pr_warn("%s\n", buffer);
  209. }
  210. /* If AER capable, dump it */
  211. cap = edev->aer_cap;
  212. if (cap) {
  213. n += scnprintf(buf+n, len-n, "pci-e AER:\n");
  214. pr_warn("EEH: PCI-E AER capability register set follows:\n");
  215. for (i=0; i<=13; i++) {
  216. eeh_ops->read_config(pdn, cap+4*i, 4, &cfg);
  217. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  218. if ((i % 4) == 0) {
  219. if (i != 0)
  220. pr_warn("%s\n", buffer);
  221. l = scnprintf(buffer, sizeof(buffer),
  222. "EEH: PCI-E AER %02x: %08x ",
  223. 4*i, cfg);
  224. } else {
  225. l += scnprintf(buffer+l, sizeof(buffer)-l,
  226. "%08x ", cfg);
  227. }
  228. }
  229. pr_warn("%s\n", buffer);
  230. }
  231. return n;
  232. }
  233. static void *eeh_dump_pe_log(struct eeh_pe *pe, void *flag)
  234. {
  235. struct eeh_dev *edev, *tmp;
  236. size_t *plen = flag;
  237. eeh_pe_for_each_dev(pe, edev, tmp)
  238. *plen += eeh_dump_dev_log(edev, pci_regs_buf + *plen,
  239. EEH_PCI_REGS_LOG_LEN - *plen);
  240. return NULL;
  241. }
  242. /**
  243. * eeh_slot_error_detail - Generate combined log including driver log and error log
  244. * @pe: EEH PE
  245. * @severity: temporary or permanent error log
  246. *
  247. * This routine should be called to generate the combined log, which
  248. * is comprised of driver log and error log. The driver log is figured
  249. * out from the config space of the corresponding PCI device, while
  250. * the error log is fetched through platform dependent function call.
  251. */
  252. void eeh_slot_error_detail(struct eeh_pe *pe, int severity)
  253. {
  254. size_t loglen = 0;
  255. /*
  256. * When the PHB is fenced or dead, it's pointless to collect
  257. * the data from PCI config space because it should return
  258. * 0xFF's. For ER, we still retrieve the data from the PCI
  259. * config space.
  260. *
  261. * For pHyp, we have to enable IO for log retrieval. Otherwise,
  262. * 0xFF's is always returned from PCI config space.
  263. *
  264. * When the @severity is EEH_LOG_PERM, the PE is going to be
  265. * removed. Prior to that, the drivers for devices included in
  266. * the PE will be closed. The drivers rely on working IO path
  267. * to bring the devices to quiet state. Otherwise, PCI traffic
  268. * from those devices after they are removed is like to cause
  269. * another unexpected EEH error.
  270. */
  271. if (!(pe->type & EEH_PE_PHB)) {
  272. if (eeh_has_flag(EEH_ENABLE_IO_FOR_LOG) ||
  273. severity == EEH_LOG_PERM)
  274. eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
  275. /*
  276. * The config space of some PCI devices can't be accessed
  277. * when their PEs are in frozen state. Otherwise, fenced
  278. * PHB might be seen. Those PEs are identified with flag
  279. * EEH_PE_CFG_RESTRICTED, indicating EEH_PE_CFG_BLOCKED
  280. * is set automatically when the PE is put to EEH_PE_ISOLATED.
  281. *
  282. * Restoring BARs possibly triggers PCI config access in
  283. * (OPAL) firmware and then causes fenced PHB. If the
  284. * PCI config is blocked with flag EEH_PE_CFG_BLOCKED, it's
  285. * pointless to restore BARs and dump config space.
  286. */
  287. eeh_ops->configure_bridge(pe);
  288. if (!(pe->state & EEH_PE_CFG_BLOCKED)) {
  289. eeh_pe_restore_bars(pe);
  290. pci_regs_buf[0] = 0;
  291. eeh_pe_traverse(pe, eeh_dump_pe_log, &loglen);
  292. }
  293. }
  294. eeh_ops->get_log(pe, severity, pci_regs_buf, loglen);
  295. }
  296. /**
  297. * eeh_token_to_phys - Convert EEH address token to phys address
  298. * @token: I/O token, should be address in the form 0xA....
  299. *
  300. * This routine should be called to convert virtual I/O address
  301. * to physical one.
  302. */
  303. static inline unsigned long eeh_token_to_phys(unsigned long token)
  304. {
  305. pte_t *ptep;
  306. unsigned long pa;
  307. int hugepage_shift;
  308. /*
  309. * We won't find hugepages here(this is iomem). Hence we are not
  310. * worried about _PAGE_SPLITTING/collapse. Also we will not hit
  311. * page table free, because of init_mm.
  312. */
  313. ptep = find_init_mm_pte(token, &hugepage_shift);
  314. if (!ptep)
  315. return token;
  316. pa = pte_pfn(*ptep);
  317. /* On radix we can do hugepage mappings for io, so handle that */
  318. if (hugepage_shift) {
  319. pa <<= hugepage_shift;
  320. pa |= token & ((1ul << hugepage_shift) - 1);
  321. } else {
  322. pa <<= PAGE_SHIFT;
  323. pa |= token & (PAGE_SIZE - 1);
  324. }
  325. return pa;
  326. }
  327. /*
  328. * On PowerNV platform, we might already have fenced PHB there.
  329. * For that case, it's meaningless to recover frozen PE. Intead,
  330. * We have to handle fenced PHB firstly.
  331. */
  332. static int eeh_phb_check_failure(struct eeh_pe *pe)
  333. {
  334. struct eeh_pe *phb_pe;
  335. unsigned long flags;
  336. int ret;
  337. if (!eeh_has_flag(EEH_PROBE_MODE_DEV))
  338. return -EPERM;
  339. /* Find the PHB PE */
  340. phb_pe = eeh_phb_pe_get(pe->phb);
  341. if (!phb_pe) {
  342. pr_warn("%s Can't find PE for PHB#%x\n",
  343. __func__, pe->phb->global_number);
  344. return -EEXIST;
  345. }
  346. /* If the PHB has been in problematic state */
  347. eeh_serialize_lock(&flags);
  348. if (phb_pe->state & EEH_PE_ISOLATED) {
  349. ret = 0;
  350. goto out;
  351. }
  352. /* Check PHB state */
  353. ret = eeh_ops->get_state(phb_pe, NULL);
  354. if ((ret < 0) ||
  355. (ret == EEH_STATE_NOT_SUPPORT) || eeh_state_active(ret)) {
  356. ret = 0;
  357. goto out;
  358. }
  359. /* Isolate the PHB and send event */
  360. eeh_pe_state_mark(phb_pe, EEH_PE_ISOLATED);
  361. eeh_serialize_unlock(flags);
  362. pr_err("EEH: PHB#%x failure detected, location: %s\n",
  363. phb_pe->phb->global_number, eeh_pe_loc_get(phb_pe));
  364. dump_stack();
  365. eeh_send_failure_event(phb_pe);
  366. return 1;
  367. out:
  368. eeh_serialize_unlock(flags);
  369. return ret;
  370. }
  371. /**
  372. * eeh_dev_check_failure - Check if all 1's data is due to EEH slot freeze
  373. * @edev: eeh device
  374. *
  375. * Check for an EEH failure for the given device node. Call this
  376. * routine if the result of a read was all 0xff's and you want to
  377. * find out if this is due to an EEH slot freeze. This routine
  378. * will query firmware for the EEH status.
  379. *
  380. * Returns 0 if there has not been an EEH error; otherwise returns
  381. * a non-zero value and queues up a slot isolation event notification.
  382. *
  383. * It is safe to call this routine in an interrupt context.
  384. */
  385. int eeh_dev_check_failure(struct eeh_dev *edev)
  386. {
  387. int ret;
  388. unsigned long flags;
  389. struct device_node *dn;
  390. struct pci_dev *dev;
  391. struct eeh_pe *pe, *parent_pe, *phb_pe;
  392. int rc = 0;
  393. const char *location = NULL;
  394. eeh_stats.total_mmio_ffs++;
  395. if (!eeh_enabled())
  396. return 0;
  397. if (!edev) {
  398. eeh_stats.no_dn++;
  399. return 0;
  400. }
  401. dev = eeh_dev_to_pci_dev(edev);
  402. pe = eeh_dev_to_pe(edev);
  403. /* Access to IO BARs might get this far and still not want checking. */
  404. if (!pe) {
  405. eeh_stats.ignored_check++;
  406. pr_debug("EEH: Ignored check for %s\n",
  407. eeh_pci_name(dev));
  408. return 0;
  409. }
  410. if (!pe->addr && !pe->config_addr) {
  411. eeh_stats.no_cfg_addr++;
  412. return 0;
  413. }
  414. /*
  415. * On PowerNV platform, we might already have fenced PHB
  416. * there and we need take care of that firstly.
  417. */
  418. ret = eeh_phb_check_failure(pe);
  419. if (ret > 0)
  420. return ret;
  421. /*
  422. * If the PE isn't owned by us, we shouldn't check the
  423. * state. Instead, let the owner handle it if the PE has
  424. * been frozen.
  425. */
  426. if (eeh_pe_passed(pe))
  427. return 0;
  428. /* If we already have a pending isolation event for this
  429. * slot, we know it's bad already, we don't need to check.
  430. * Do this checking under a lock; as multiple PCI devices
  431. * in one slot might report errors simultaneously, and we
  432. * only want one error recovery routine running.
  433. */
  434. eeh_serialize_lock(&flags);
  435. rc = 1;
  436. if (pe->state & EEH_PE_ISOLATED) {
  437. pe->check_count++;
  438. if (pe->check_count % EEH_MAX_FAILS == 0) {
  439. dn = pci_device_to_OF_node(dev);
  440. if (dn)
  441. location = of_get_property(dn, "ibm,loc-code",
  442. NULL);
  443. printk(KERN_ERR "EEH: %d reads ignored for recovering device at "
  444. "location=%s driver=%s pci addr=%s\n",
  445. pe->check_count,
  446. location ? location : "unknown",
  447. eeh_driver_name(dev), eeh_pci_name(dev));
  448. printk(KERN_ERR "EEH: Might be infinite loop in %s driver\n",
  449. eeh_driver_name(dev));
  450. dump_stack();
  451. }
  452. goto dn_unlock;
  453. }
  454. /*
  455. * Now test for an EEH failure. This is VERY expensive.
  456. * Note that the eeh_config_addr may be a parent device
  457. * in the case of a device behind a bridge, or it may be
  458. * function zero of a multi-function device.
  459. * In any case they must share a common PHB.
  460. */
  461. ret = eeh_ops->get_state(pe, NULL);
  462. /* Note that config-io to empty slots may fail;
  463. * they are empty when they don't have children.
  464. * We will punt with the following conditions: Failure to get
  465. * PE's state, EEH not support and Permanently unavailable
  466. * state, PE is in good state.
  467. */
  468. if ((ret < 0) ||
  469. (ret == EEH_STATE_NOT_SUPPORT) || eeh_state_active(ret)) {
  470. eeh_stats.false_positives++;
  471. pe->false_positives++;
  472. rc = 0;
  473. goto dn_unlock;
  474. }
  475. /*
  476. * It should be corner case that the parent PE has been
  477. * put into frozen state as well. We should take care
  478. * that at first.
  479. */
  480. parent_pe = pe->parent;
  481. while (parent_pe) {
  482. /* Hit the ceiling ? */
  483. if (parent_pe->type & EEH_PE_PHB)
  484. break;
  485. /* Frozen parent PE ? */
  486. ret = eeh_ops->get_state(parent_pe, NULL);
  487. if (ret > 0 && !eeh_state_active(ret)) {
  488. pe = parent_pe;
  489. pr_err("EEH: Failure of PHB#%x-PE#%x will be handled at parent PHB#%x-PE#%x.\n",
  490. pe->phb->global_number, pe->addr,
  491. pe->phb->global_number, parent_pe->addr);
  492. }
  493. /* Next parent level */
  494. parent_pe = parent_pe->parent;
  495. }
  496. eeh_stats.slot_resets++;
  497. /* Avoid repeated reports of this failure, including problems
  498. * with other functions on this device, and functions under
  499. * bridges.
  500. */
  501. eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
  502. eeh_serialize_unlock(flags);
  503. /* Most EEH events are due to device driver bugs. Having
  504. * a stack trace will help the device-driver authors figure
  505. * out what happened. So print that out.
  506. */
  507. phb_pe = eeh_phb_pe_get(pe->phb);
  508. pr_err("EEH: Frozen PHB#%x-PE#%x detected\n",
  509. pe->phb->global_number, pe->addr);
  510. pr_err("EEH: PE location: %s, PHB location: %s\n",
  511. eeh_pe_loc_get(pe), eeh_pe_loc_get(phb_pe));
  512. dump_stack();
  513. eeh_send_failure_event(pe);
  514. return 1;
  515. dn_unlock:
  516. eeh_serialize_unlock(flags);
  517. return rc;
  518. }
  519. EXPORT_SYMBOL_GPL(eeh_dev_check_failure);
  520. /**
  521. * eeh_check_failure - Check if all 1's data is due to EEH slot freeze
  522. * @token: I/O address
  523. *
  524. * Check for an EEH failure at the given I/O address. Call this
  525. * routine if the result of a read was all 0xff's and you want to
  526. * find out if this is due to an EEH slot freeze event. This routine
  527. * will query firmware for the EEH status.
  528. *
  529. * Note this routine is safe to call in an interrupt context.
  530. */
  531. int eeh_check_failure(const volatile void __iomem *token)
  532. {
  533. unsigned long addr;
  534. struct eeh_dev *edev;
  535. /* Finding the phys addr + pci device; this is pretty quick. */
  536. addr = eeh_token_to_phys((unsigned long __force) token);
  537. edev = eeh_addr_cache_get_dev(addr);
  538. if (!edev) {
  539. eeh_stats.no_device++;
  540. return 0;
  541. }
  542. return eeh_dev_check_failure(edev);
  543. }
  544. EXPORT_SYMBOL(eeh_check_failure);
  545. /**
  546. * eeh_pci_enable - Enable MMIO or DMA transfers for this slot
  547. * @pe: EEH PE
  548. *
  549. * This routine should be called to reenable frozen MMIO or DMA
  550. * so that it would work correctly again. It's useful while doing
  551. * recovery or log collection on the indicated device.
  552. */
  553. int eeh_pci_enable(struct eeh_pe *pe, int function)
  554. {
  555. int active_flag, rc;
  556. /*
  557. * pHyp doesn't allow to enable IO or DMA on unfrozen PE.
  558. * Also, it's pointless to enable them on unfrozen PE. So
  559. * we have to check before enabling IO or DMA.
  560. */
  561. switch (function) {
  562. case EEH_OPT_THAW_MMIO:
  563. active_flag = EEH_STATE_MMIO_ACTIVE | EEH_STATE_MMIO_ENABLED;
  564. break;
  565. case EEH_OPT_THAW_DMA:
  566. active_flag = EEH_STATE_DMA_ACTIVE;
  567. break;
  568. case EEH_OPT_DISABLE:
  569. case EEH_OPT_ENABLE:
  570. case EEH_OPT_FREEZE_PE:
  571. active_flag = 0;
  572. break;
  573. default:
  574. pr_warn("%s: Invalid function %d\n",
  575. __func__, function);
  576. return -EINVAL;
  577. }
  578. /*
  579. * Check if IO or DMA has been enabled before
  580. * enabling them.
  581. */
  582. if (active_flag) {
  583. rc = eeh_ops->get_state(pe, NULL);
  584. if (rc < 0)
  585. return rc;
  586. /* Needn't enable it at all */
  587. if (rc == EEH_STATE_NOT_SUPPORT)
  588. return 0;
  589. /* It's already enabled */
  590. if (rc & active_flag)
  591. return 0;
  592. }
  593. /* Issue the request */
  594. rc = eeh_ops->set_option(pe, function);
  595. if (rc)
  596. pr_warn("%s: Unexpected state change %d on "
  597. "PHB#%x-PE#%x, err=%d\n",
  598. __func__, function, pe->phb->global_number,
  599. pe->addr, rc);
  600. /* Check if the request is finished successfully */
  601. if (active_flag) {
  602. rc = eeh_ops->wait_state(pe, PCI_BUS_RESET_WAIT_MSEC);
  603. if (rc < 0)
  604. return rc;
  605. if (rc & active_flag)
  606. return 0;
  607. return -EIO;
  608. }
  609. return rc;
  610. }
  611. static void *eeh_disable_and_save_dev_state(struct eeh_dev *edev,
  612. void *userdata)
  613. {
  614. struct pci_dev *pdev = eeh_dev_to_pci_dev(edev);
  615. struct pci_dev *dev = userdata;
  616. /*
  617. * The caller should have disabled and saved the
  618. * state for the specified device
  619. */
  620. if (!pdev || pdev == dev)
  621. return NULL;
  622. /* Ensure we have D0 power state */
  623. pci_set_power_state(pdev, PCI_D0);
  624. /* Save device state */
  625. pci_save_state(pdev);
  626. /*
  627. * Disable device to avoid any DMA traffic and
  628. * interrupt from the device
  629. */
  630. pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
  631. return NULL;
  632. }
  633. static void *eeh_restore_dev_state(struct eeh_dev *edev, void *userdata)
  634. {
  635. struct pci_dn *pdn = eeh_dev_to_pdn(edev);
  636. struct pci_dev *pdev = eeh_dev_to_pci_dev(edev);
  637. struct pci_dev *dev = userdata;
  638. if (!pdev)
  639. return NULL;
  640. /* Apply customization from firmware */
  641. if (pdn && eeh_ops->restore_config)
  642. eeh_ops->restore_config(pdn);
  643. /* The caller should restore state for the specified device */
  644. if (pdev != dev)
  645. pci_restore_state(pdev);
  646. return NULL;
  647. }
  648. int eeh_restore_vf_config(struct pci_dn *pdn)
  649. {
  650. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  651. u32 devctl, cmd, cap2, aer_capctl;
  652. int old_mps;
  653. if (edev->pcie_cap) {
  654. /* Restore MPS */
  655. old_mps = (ffs(pdn->mps) - 8) << 5;
  656. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  657. 2, &devctl);
  658. devctl &= ~PCI_EXP_DEVCTL_PAYLOAD;
  659. devctl |= old_mps;
  660. eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  661. 2, devctl);
  662. /* Disable Completion Timeout if possible */
  663. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCAP2,
  664. 4, &cap2);
  665. if (cap2 & PCI_EXP_DEVCAP2_COMP_TMOUT_DIS) {
  666. eeh_ops->read_config(pdn,
  667. edev->pcie_cap + PCI_EXP_DEVCTL2,
  668. 4, &cap2);
  669. cap2 |= PCI_EXP_DEVCTL2_COMP_TMOUT_DIS;
  670. eeh_ops->write_config(pdn,
  671. edev->pcie_cap + PCI_EXP_DEVCTL2,
  672. 4, cap2);
  673. }
  674. }
  675. /* Enable SERR and parity checking */
  676. eeh_ops->read_config(pdn, PCI_COMMAND, 2, &cmd);
  677. cmd |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  678. eeh_ops->write_config(pdn, PCI_COMMAND, 2, cmd);
  679. /* Enable report various errors */
  680. if (edev->pcie_cap) {
  681. eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  682. 2, &devctl);
  683. devctl &= ~PCI_EXP_DEVCTL_CERE;
  684. devctl |= (PCI_EXP_DEVCTL_NFERE |
  685. PCI_EXP_DEVCTL_FERE |
  686. PCI_EXP_DEVCTL_URRE);
  687. eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
  688. 2, devctl);
  689. }
  690. /* Enable ECRC generation and check */
  691. if (edev->pcie_cap && edev->aer_cap) {
  692. eeh_ops->read_config(pdn, edev->aer_cap + PCI_ERR_CAP,
  693. 4, &aer_capctl);
  694. aer_capctl |= (PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
  695. eeh_ops->write_config(pdn, edev->aer_cap + PCI_ERR_CAP,
  696. 4, aer_capctl);
  697. }
  698. return 0;
  699. }
  700. /**
  701. * pcibios_set_pcie_reset_state - Set PCI-E reset state
  702. * @dev: pci device struct
  703. * @state: reset state to enter
  704. *
  705. * Return value:
  706. * 0 if success
  707. */
  708. int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
  709. {
  710. struct eeh_dev *edev = pci_dev_to_eeh_dev(dev);
  711. struct eeh_pe *pe = eeh_dev_to_pe(edev);
  712. if (!pe) {
  713. pr_err("%s: No PE found on PCI device %s\n",
  714. __func__, pci_name(dev));
  715. return -EINVAL;
  716. }
  717. switch (state) {
  718. case pcie_deassert_reset:
  719. eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
  720. eeh_unfreeze_pe(pe, false);
  721. if (!(pe->type & EEH_PE_VF))
  722. eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED);
  723. eeh_pe_dev_traverse(pe, eeh_restore_dev_state, dev);
  724. eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
  725. break;
  726. case pcie_hot_reset:
  727. eeh_pe_state_mark_with_cfg(pe, EEH_PE_ISOLATED);
  728. eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
  729. eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
  730. if (!(pe->type & EEH_PE_VF))
  731. eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
  732. eeh_ops->reset(pe, EEH_RESET_HOT);
  733. break;
  734. case pcie_warm_reset:
  735. eeh_pe_state_mark_with_cfg(pe, EEH_PE_ISOLATED);
  736. eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
  737. eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
  738. if (!(pe->type & EEH_PE_VF))
  739. eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
  740. eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
  741. break;
  742. default:
  743. eeh_pe_state_clear(pe, EEH_PE_ISOLATED | EEH_PE_CFG_BLOCKED);
  744. return -EINVAL;
  745. };
  746. return 0;
  747. }
  748. /**
  749. * eeh_set_pe_freset - Check the required reset for the indicated device
  750. * @data: EEH device
  751. * @flag: return value
  752. *
  753. * Each device might have its preferred reset type: fundamental or
  754. * hot reset. The routine is used to collected the information for
  755. * the indicated device and its children so that the bunch of the
  756. * devices could be reset properly.
  757. */
  758. static void *eeh_set_dev_freset(struct eeh_dev *edev, void *flag)
  759. {
  760. struct pci_dev *dev;
  761. unsigned int *freset = (unsigned int *)flag;
  762. dev = eeh_dev_to_pci_dev(edev);
  763. if (dev)
  764. *freset |= dev->needs_freset;
  765. return NULL;
  766. }
  767. /**
  768. * eeh_pe_reset_full - Complete a full reset process on the indicated PE
  769. * @pe: EEH PE
  770. *
  771. * This function executes a full reset procedure on a PE, including setting
  772. * the appropriate flags, performing a fundamental or hot reset, and then
  773. * deactivating the reset status. It is designed to be used within the EEH
  774. * subsystem, as opposed to eeh_pe_reset which is exported to drivers and
  775. * only performs a single operation at a time.
  776. *
  777. * This function will attempt to reset a PE three times before failing.
  778. */
  779. int eeh_pe_reset_full(struct eeh_pe *pe)
  780. {
  781. int reset_state = (EEH_PE_RESET | EEH_PE_CFG_BLOCKED);
  782. int type = EEH_RESET_HOT;
  783. unsigned int freset = 0;
  784. int i, state, ret;
  785. /*
  786. * Determine the type of reset to perform - hot or fundamental.
  787. * Hot reset is the default operation, unless any device under the
  788. * PE requires a fundamental reset.
  789. */
  790. eeh_pe_dev_traverse(pe, eeh_set_dev_freset, &freset);
  791. if (freset)
  792. type = EEH_RESET_FUNDAMENTAL;
  793. /* Mark the PE as in reset state and block config space accesses */
  794. eeh_pe_state_mark(pe, reset_state);
  795. /* Make three attempts at resetting the bus */
  796. for (i = 0; i < 3; i++) {
  797. ret = eeh_pe_reset(pe, type);
  798. if (ret)
  799. break;
  800. ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE);
  801. if (ret)
  802. break;
  803. /* Wait until the PE is in a functioning state */
  804. state = eeh_ops->wait_state(pe, PCI_BUS_RESET_WAIT_MSEC);
  805. if (eeh_state_active(state))
  806. break;
  807. if (state < 0) {
  808. pr_warn("%s: Unrecoverable slot failure on PHB#%x-PE#%x",
  809. __func__, pe->phb->global_number, pe->addr);
  810. ret = -ENOTRECOVERABLE;
  811. break;
  812. }
  813. /* Set error in case this is our last attempt */
  814. ret = -EIO;
  815. pr_warn("%s: Failure %d resetting PHB#%x-PE#%x\n (%d)\n",
  816. __func__, state, pe->phb->global_number, pe->addr, (i + 1));
  817. }
  818. eeh_pe_state_clear(pe, reset_state);
  819. return ret;
  820. }
  821. /**
  822. * eeh_save_bars - Save device bars
  823. * @edev: PCI device associated EEH device
  824. *
  825. * Save the values of the device bars. Unlike the restore
  826. * routine, this routine is *not* recursive. This is because
  827. * PCI devices are added individually; but, for the restore,
  828. * an entire slot is reset at a time.
  829. */
  830. void eeh_save_bars(struct eeh_dev *edev)
  831. {
  832. struct pci_dn *pdn;
  833. int i;
  834. pdn = eeh_dev_to_pdn(edev);
  835. if (!pdn)
  836. return;
  837. for (i = 0; i < 16; i++)
  838. eeh_ops->read_config(pdn, i * 4, 4, &edev->config_space[i]);
  839. /*
  840. * For PCI bridges including root port, we need enable bus
  841. * master explicitly. Otherwise, it can't fetch IODA table
  842. * entries correctly. So we cache the bit in advance so that
  843. * we can restore it after reset, either PHB range or PE range.
  844. */
  845. if (edev->mode & EEH_DEV_BRIDGE)
  846. edev->config_space[1] |= PCI_COMMAND_MASTER;
  847. }
  848. /**
  849. * eeh_ops_register - Register platform dependent EEH operations
  850. * @ops: platform dependent EEH operations
  851. *
  852. * Register the platform dependent EEH operation callback
  853. * functions. The platform should call this function before
  854. * any other EEH operations.
  855. */
  856. int __init eeh_ops_register(struct eeh_ops *ops)
  857. {
  858. if (!ops->name) {
  859. pr_warn("%s: Invalid EEH ops name for %p\n",
  860. __func__, ops);
  861. return -EINVAL;
  862. }
  863. if (eeh_ops && eeh_ops != ops) {
  864. pr_warn("%s: EEH ops of platform %s already existing (%s)\n",
  865. __func__, eeh_ops->name, ops->name);
  866. return -EEXIST;
  867. }
  868. eeh_ops = ops;
  869. return 0;
  870. }
  871. /**
  872. * eeh_ops_unregister - Unreigster platform dependent EEH operations
  873. * @name: name of EEH platform operations
  874. *
  875. * Unregister the platform dependent EEH operation callback
  876. * functions.
  877. */
  878. int __exit eeh_ops_unregister(const char *name)
  879. {
  880. if (!name || !strlen(name)) {
  881. pr_warn("%s: Invalid EEH ops name\n",
  882. __func__);
  883. return -EINVAL;
  884. }
  885. if (eeh_ops && !strcmp(eeh_ops->name, name)) {
  886. eeh_ops = NULL;
  887. return 0;
  888. }
  889. return -EEXIST;
  890. }
  891. static int eeh_reboot_notifier(struct notifier_block *nb,
  892. unsigned long action, void *unused)
  893. {
  894. eeh_clear_flag(EEH_ENABLED);
  895. return NOTIFY_DONE;
  896. }
  897. static struct notifier_block eeh_reboot_nb = {
  898. .notifier_call = eeh_reboot_notifier,
  899. };
  900. void eeh_probe_devices(void)
  901. {
  902. struct pci_controller *hose, *tmp;
  903. struct pci_dn *pdn;
  904. /* Enable EEH for all adapters */
  905. list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
  906. pdn = hose->pci_data;
  907. traverse_pci_dn(pdn, eeh_ops->probe, NULL);
  908. }
  909. }
  910. /**
  911. * eeh_init - EEH initialization
  912. *
  913. * Initialize EEH by trying to enable it for all of the adapters in the system.
  914. * As a side effect we can determine here if eeh is supported at all.
  915. * Note that we leave EEH on so failed config cycles won't cause a machine
  916. * check. If a user turns off EEH for a particular adapter they are really
  917. * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
  918. * grant access to a slot if EEH isn't enabled, and so we always enable
  919. * EEH for all slots/all devices.
  920. *
  921. * The eeh-force-off option disables EEH checking globally, for all slots.
  922. * Even if force-off is set, the EEH hardware is still enabled, so that
  923. * newer systems can boot.
  924. */
  925. static int eeh_init(void)
  926. {
  927. struct pci_controller *hose, *tmp;
  928. int ret = 0;
  929. /* Register reboot notifier */
  930. ret = register_reboot_notifier(&eeh_reboot_nb);
  931. if (ret) {
  932. pr_warn("%s: Failed to register notifier (%d)\n",
  933. __func__, ret);
  934. return ret;
  935. }
  936. /* call platform initialization function */
  937. if (!eeh_ops) {
  938. pr_warn("%s: Platform EEH operation not found\n",
  939. __func__);
  940. return -EEXIST;
  941. } else if ((ret = eeh_ops->init()))
  942. return ret;
  943. /* Initialize PHB PEs */
  944. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  945. eeh_dev_phb_init_dynamic(hose);
  946. /* Initialize EEH event */
  947. ret = eeh_event_init();
  948. if (ret)
  949. return ret;
  950. eeh_probe_devices();
  951. if (eeh_enabled())
  952. pr_info("EEH: PCI Enhanced I/O Error Handling Enabled\n");
  953. else if (!eeh_has_flag(EEH_POSTPONED_PROBE))
  954. pr_info("EEH: No capable adapters found\n");
  955. return ret;
  956. }
  957. core_initcall_sync(eeh_init);
  958. /**
  959. * eeh_add_device_early - Enable EEH for the indicated device node
  960. * @pdn: PCI device node for which to set up EEH
  961. *
  962. * This routine must be used to perform EEH initialization for PCI
  963. * devices that were added after system boot (e.g. hotplug, dlpar).
  964. * This routine must be called before any i/o is performed to the
  965. * adapter (inluding any config-space i/o).
  966. * Whether this actually enables EEH or not for this device depends
  967. * on the CEC architecture, type of the device, on earlier boot
  968. * command-line arguments & etc.
  969. */
  970. void eeh_add_device_early(struct pci_dn *pdn)
  971. {
  972. struct pci_controller *phb = pdn ? pdn->phb : NULL;
  973. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  974. if (!edev)
  975. return;
  976. if (!eeh_has_flag(EEH_PROBE_MODE_DEVTREE))
  977. return;
  978. /* USB Bus children of PCI devices will not have BUID's */
  979. if (NULL == phb ||
  980. (eeh_has_flag(EEH_PROBE_MODE_DEVTREE) && 0 == phb->buid))
  981. return;
  982. eeh_ops->probe(pdn, NULL);
  983. }
  984. /**
  985. * eeh_add_device_tree_early - Enable EEH for the indicated device
  986. * @pdn: PCI device node
  987. *
  988. * This routine must be used to perform EEH initialization for the
  989. * indicated PCI device that was added after system boot (e.g.
  990. * hotplug, dlpar).
  991. */
  992. void eeh_add_device_tree_early(struct pci_dn *pdn)
  993. {
  994. struct pci_dn *n;
  995. if (!pdn)
  996. return;
  997. list_for_each_entry(n, &pdn->child_list, list)
  998. eeh_add_device_tree_early(n);
  999. eeh_add_device_early(pdn);
  1000. }
  1001. EXPORT_SYMBOL_GPL(eeh_add_device_tree_early);
  1002. /**
  1003. * eeh_add_device_late - Perform EEH initialization for the indicated pci device
  1004. * @dev: pci device for which to set up EEH
  1005. *
  1006. * This routine must be used to complete EEH initialization for PCI
  1007. * devices that were added after system boot (e.g. hotplug, dlpar).
  1008. */
  1009. void eeh_add_device_late(struct pci_dev *dev)
  1010. {
  1011. struct pci_dn *pdn;
  1012. struct eeh_dev *edev;
  1013. if (!dev || !eeh_enabled())
  1014. return;
  1015. pr_debug("EEH: Adding device %s\n", pci_name(dev));
  1016. pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
  1017. edev = pdn_to_eeh_dev(pdn);
  1018. if (edev->pdev == dev) {
  1019. pr_debug("EEH: Already referenced !\n");
  1020. return;
  1021. }
  1022. /*
  1023. * The EEH cache might not be removed correctly because of
  1024. * unbalanced kref to the device during unplug time, which
  1025. * relies on pcibios_release_device(). So we have to remove
  1026. * that here explicitly.
  1027. */
  1028. if (edev->pdev) {
  1029. eeh_rmv_from_parent_pe(edev);
  1030. eeh_addr_cache_rmv_dev(edev->pdev);
  1031. eeh_sysfs_remove_device(edev->pdev);
  1032. edev->mode &= ~EEH_DEV_SYSFS;
  1033. /*
  1034. * We definitely should have the PCI device removed
  1035. * though it wasn't correctly. So we needn't call
  1036. * into error handler afterwards.
  1037. */
  1038. edev->mode |= EEH_DEV_NO_HANDLER;
  1039. edev->pdev = NULL;
  1040. dev->dev.archdata.edev = NULL;
  1041. }
  1042. if (eeh_has_flag(EEH_PROBE_MODE_DEV))
  1043. eeh_ops->probe(pdn, NULL);
  1044. edev->pdev = dev;
  1045. dev->dev.archdata.edev = edev;
  1046. eeh_addr_cache_insert_dev(dev);
  1047. }
  1048. /**
  1049. * eeh_add_device_tree_late - Perform EEH initialization for the indicated PCI bus
  1050. * @bus: PCI bus
  1051. *
  1052. * This routine must be used to perform EEH initialization for PCI
  1053. * devices which are attached to the indicated PCI bus. The PCI bus
  1054. * is added after system boot through hotplug or dlpar.
  1055. */
  1056. void eeh_add_device_tree_late(struct pci_bus *bus)
  1057. {
  1058. struct pci_dev *dev;
  1059. list_for_each_entry(dev, &bus->devices, bus_list) {
  1060. eeh_add_device_late(dev);
  1061. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  1062. struct pci_bus *subbus = dev->subordinate;
  1063. if (subbus)
  1064. eeh_add_device_tree_late(subbus);
  1065. }
  1066. }
  1067. }
  1068. EXPORT_SYMBOL_GPL(eeh_add_device_tree_late);
  1069. /**
  1070. * eeh_add_sysfs_files - Add EEH sysfs files for the indicated PCI bus
  1071. * @bus: PCI bus
  1072. *
  1073. * This routine must be used to add EEH sysfs files for PCI
  1074. * devices which are attached to the indicated PCI bus. The PCI bus
  1075. * is added after system boot through hotplug or dlpar.
  1076. */
  1077. void eeh_add_sysfs_files(struct pci_bus *bus)
  1078. {
  1079. struct pci_dev *dev;
  1080. list_for_each_entry(dev, &bus->devices, bus_list) {
  1081. eeh_sysfs_add_device(dev);
  1082. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  1083. struct pci_bus *subbus = dev->subordinate;
  1084. if (subbus)
  1085. eeh_add_sysfs_files(subbus);
  1086. }
  1087. }
  1088. }
  1089. EXPORT_SYMBOL_GPL(eeh_add_sysfs_files);
  1090. /**
  1091. * eeh_remove_device - Undo EEH setup for the indicated pci device
  1092. * @dev: pci device to be removed
  1093. *
  1094. * This routine should be called when a device is removed from
  1095. * a running system (e.g. by hotplug or dlpar). It unregisters
  1096. * the PCI device from the EEH subsystem. I/O errors affecting
  1097. * this device will no longer be detected after this call; thus,
  1098. * i/o errors affecting this slot may leave this device unusable.
  1099. */
  1100. void eeh_remove_device(struct pci_dev *dev)
  1101. {
  1102. struct eeh_dev *edev;
  1103. if (!dev || !eeh_enabled())
  1104. return;
  1105. edev = pci_dev_to_eeh_dev(dev);
  1106. /* Unregister the device with the EEH/PCI address search system */
  1107. pr_debug("EEH: Removing device %s\n", pci_name(dev));
  1108. if (!edev || !edev->pdev || !edev->pe) {
  1109. pr_debug("EEH: Not referenced !\n");
  1110. return;
  1111. }
  1112. /*
  1113. * During the hotplug for EEH error recovery, we need the EEH
  1114. * device attached to the parent PE in order for BAR restore
  1115. * a bit later. So we keep it for BAR restore and remove it
  1116. * from the parent PE during the BAR resotre.
  1117. */
  1118. edev->pdev = NULL;
  1119. /*
  1120. * The flag "in_error" is used to trace EEH devices for VFs
  1121. * in error state or not. It's set in eeh_report_error(). If
  1122. * it's not set, eeh_report_{reset,resume}() won't be called
  1123. * for the VF EEH device.
  1124. */
  1125. edev->in_error = false;
  1126. dev->dev.archdata.edev = NULL;
  1127. if (!(edev->pe->state & EEH_PE_KEEP))
  1128. eeh_rmv_from_parent_pe(edev);
  1129. else
  1130. edev->mode |= EEH_DEV_DISCONNECTED;
  1131. /*
  1132. * We're removing from the PCI subsystem, that means
  1133. * the PCI device driver can't support EEH or not
  1134. * well. So we rely on hotplug completely to do recovery
  1135. * for the specific PCI device.
  1136. */
  1137. edev->mode |= EEH_DEV_NO_HANDLER;
  1138. eeh_addr_cache_rmv_dev(dev);
  1139. eeh_sysfs_remove_device(dev);
  1140. edev->mode &= ~EEH_DEV_SYSFS;
  1141. }
  1142. int eeh_unfreeze_pe(struct eeh_pe *pe, bool sw_state)
  1143. {
  1144. int ret;
  1145. ret = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
  1146. if (ret) {
  1147. pr_warn("%s: Failure %d enabling IO on PHB#%x-PE#%x\n",
  1148. __func__, ret, pe->phb->global_number, pe->addr);
  1149. return ret;
  1150. }
  1151. ret = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
  1152. if (ret) {
  1153. pr_warn("%s: Failure %d enabling DMA on PHB#%x-PE#%x\n",
  1154. __func__, ret, pe->phb->global_number, pe->addr);
  1155. return ret;
  1156. }
  1157. /* Clear software isolated state */
  1158. if (sw_state && (pe->state & EEH_PE_ISOLATED))
  1159. eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
  1160. return ret;
  1161. }
  1162. static struct pci_device_id eeh_reset_ids[] = {
  1163. { PCI_DEVICE(0x19a2, 0x0710) }, /* Emulex, BE */
  1164. { PCI_DEVICE(0x10df, 0xe220) }, /* Emulex, Lancer */
  1165. { PCI_DEVICE(0x14e4, 0x1657) }, /* Broadcom BCM5719 */
  1166. { 0 }
  1167. };
  1168. static int eeh_pe_change_owner(struct eeh_pe *pe)
  1169. {
  1170. struct eeh_dev *edev, *tmp;
  1171. struct pci_dev *pdev;
  1172. struct pci_device_id *id;
  1173. int ret;
  1174. /* Check PE state */
  1175. ret = eeh_ops->get_state(pe, NULL);
  1176. if (ret < 0 || ret == EEH_STATE_NOT_SUPPORT)
  1177. return 0;
  1178. /* Unfrozen PE, nothing to do */
  1179. if (eeh_state_active(ret))
  1180. return 0;
  1181. /* Frozen PE, check if it needs PE level reset */
  1182. eeh_pe_for_each_dev(pe, edev, tmp) {
  1183. pdev = eeh_dev_to_pci_dev(edev);
  1184. if (!pdev)
  1185. continue;
  1186. for (id = &eeh_reset_ids[0]; id->vendor != 0; id++) {
  1187. if (id->vendor != PCI_ANY_ID &&
  1188. id->vendor != pdev->vendor)
  1189. continue;
  1190. if (id->device != PCI_ANY_ID &&
  1191. id->device != pdev->device)
  1192. continue;
  1193. if (id->subvendor != PCI_ANY_ID &&
  1194. id->subvendor != pdev->subsystem_vendor)
  1195. continue;
  1196. if (id->subdevice != PCI_ANY_ID &&
  1197. id->subdevice != pdev->subsystem_device)
  1198. continue;
  1199. return eeh_pe_reset_and_recover(pe);
  1200. }
  1201. }
  1202. return eeh_unfreeze_pe(pe, true);
  1203. }
  1204. /**
  1205. * eeh_dev_open - Increase count of pass through devices for PE
  1206. * @pdev: PCI device
  1207. *
  1208. * Increase count of passed through devices for the indicated
  1209. * PE. In the result, the EEH errors detected on the PE won't be
  1210. * reported. The PE owner will be responsible for detection
  1211. * and recovery.
  1212. */
  1213. int eeh_dev_open(struct pci_dev *pdev)
  1214. {
  1215. struct eeh_dev *edev;
  1216. int ret = -ENODEV;
  1217. mutex_lock(&eeh_dev_mutex);
  1218. /* No PCI device ? */
  1219. if (!pdev)
  1220. goto out;
  1221. /* No EEH device or PE ? */
  1222. edev = pci_dev_to_eeh_dev(pdev);
  1223. if (!edev || !edev->pe)
  1224. goto out;
  1225. /*
  1226. * The PE might have been put into frozen state, but we
  1227. * didn't detect that yet. The passed through PCI devices
  1228. * in frozen PE won't work properly. Clear the frozen state
  1229. * in advance.
  1230. */
  1231. ret = eeh_pe_change_owner(edev->pe);
  1232. if (ret)
  1233. goto out;
  1234. /* Increase PE's pass through count */
  1235. atomic_inc(&edev->pe->pass_dev_cnt);
  1236. mutex_unlock(&eeh_dev_mutex);
  1237. return 0;
  1238. out:
  1239. mutex_unlock(&eeh_dev_mutex);
  1240. return ret;
  1241. }
  1242. EXPORT_SYMBOL_GPL(eeh_dev_open);
  1243. /**
  1244. * eeh_dev_release - Decrease count of pass through devices for PE
  1245. * @pdev: PCI device
  1246. *
  1247. * Decrease count of pass through devices for the indicated PE. If
  1248. * there is no passed through device in PE, the EEH errors detected
  1249. * on the PE will be reported and handled as usual.
  1250. */
  1251. void eeh_dev_release(struct pci_dev *pdev)
  1252. {
  1253. struct eeh_dev *edev;
  1254. mutex_lock(&eeh_dev_mutex);
  1255. /* No PCI device ? */
  1256. if (!pdev)
  1257. goto out;
  1258. /* No EEH device ? */
  1259. edev = pci_dev_to_eeh_dev(pdev);
  1260. if (!edev || !edev->pe || !eeh_pe_passed(edev->pe))
  1261. goto out;
  1262. /* Decrease PE's pass through count */
  1263. WARN_ON(atomic_dec_if_positive(&edev->pe->pass_dev_cnt) < 0);
  1264. eeh_pe_change_owner(edev->pe);
  1265. out:
  1266. mutex_unlock(&eeh_dev_mutex);
  1267. }
  1268. EXPORT_SYMBOL(eeh_dev_release);
  1269. #ifdef CONFIG_IOMMU_API
  1270. static int dev_has_iommu_table(struct device *dev, void *data)
  1271. {
  1272. struct pci_dev *pdev = to_pci_dev(dev);
  1273. struct pci_dev **ppdev = data;
  1274. if (!dev)
  1275. return 0;
  1276. if (dev->iommu_group) {
  1277. *ppdev = pdev;
  1278. return 1;
  1279. }
  1280. return 0;
  1281. }
  1282. /**
  1283. * eeh_iommu_group_to_pe - Convert IOMMU group to EEH PE
  1284. * @group: IOMMU group
  1285. *
  1286. * The routine is called to convert IOMMU group to EEH PE.
  1287. */
  1288. struct eeh_pe *eeh_iommu_group_to_pe(struct iommu_group *group)
  1289. {
  1290. struct pci_dev *pdev = NULL;
  1291. struct eeh_dev *edev;
  1292. int ret;
  1293. /* No IOMMU group ? */
  1294. if (!group)
  1295. return NULL;
  1296. ret = iommu_group_for_each_dev(group, &pdev, dev_has_iommu_table);
  1297. if (!ret || !pdev)
  1298. return NULL;
  1299. /* No EEH device or PE ? */
  1300. edev = pci_dev_to_eeh_dev(pdev);
  1301. if (!edev || !edev->pe)
  1302. return NULL;
  1303. return edev->pe;
  1304. }
  1305. EXPORT_SYMBOL_GPL(eeh_iommu_group_to_pe);
  1306. #endif /* CONFIG_IOMMU_API */
  1307. /**
  1308. * eeh_pe_set_option - Set options for the indicated PE
  1309. * @pe: EEH PE
  1310. * @option: requested option
  1311. *
  1312. * The routine is called to enable or disable EEH functionality
  1313. * on the indicated PE, to enable IO or DMA for the frozen PE.
  1314. */
  1315. int eeh_pe_set_option(struct eeh_pe *pe, int option)
  1316. {
  1317. int ret = 0;
  1318. /* Invalid PE ? */
  1319. if (!pe)
  1320. return -ENODEV;
  1321. /*
  1322. * EEH functionality could possibly be disabled, just
  1323. * return error for the case. And the EEH functinality
  1324. * isn't expected to be disabled on one specific PE.
  1325. */
  1326. switch (option) {
  1327. case EEH_OPT_ENABLE:
  1328. if (eeh_enabled()) {
  1329. ret = eeh_pe_change_owner(pe);
  1330. break;
  1331. }
  1332. ret = -EIO;
  1333. break;
  1334. case EEH_OPT_DISABLE:
  1335. break;
  1336. case EEH_OPT_THAW_MMIO:
  1337. case EEH_OPT_THAW_DMA:
  1338. case EEH_OPT_FREEZE_PE:
  1339. if (!eeh_ops || !eeh_ops->set_option) {
  1340. ret = -ENOENT;
  1341. break;
  1342. }
  1343. ret = eeh_pci_enable(pe, option);
  1344. break;
  1345. default:
  1346. pr_debug("%s: Option %d out of range (%d, %d)\n",
  1347. __func__, option, EEH_OPT_DISABLE, EEH_OPT_THAW_DMA);
  1348. ret = -EINVAL;
  1349. }
  1350. return ret;
  1351. }
  1352. EXPORT_SYMBOL_GPL(eeh_pe_set_option);
  1353. /**
  1354. * eeh_pe_get_state - Retrieve PE's state
  1355. * @pe: EEH PE
  1356. *
  1357. * Retrieve the PE's state, which includes 3 aspects: enabled
  1358. * DMA, enabled IO and asserted reset.
  1359. */
  1360. int eeh_pe_get_state(struct eeh_pe *pe)
  1361. {
  1362. int result, ret = 0;
  1363. bool rst_active, dma_en, mmio_en;
  1364. /* Existing PE ? */
  1365. if (!pe)
  1366. return -ENODEV;
  1367. if (!eeh_ops || !eeh_ops->get_state)
  1368. return -ENOENT;
  1369. /*
  1370. * If the parent PE is owned by the host kernel and is undergoing
  1371. * error recovery, we should return the PE state as temporarily
  1372. * unavailable so that the error recovery on the guest is suspended
  1373. * until the recovery completes on the host.
  1374. */
  1375. if (pe->parent &&
  1376. !(pe->state & EEH_PE_REMOVED) &&
  1377. (pe->parent->state & (EEH_PE_ISOLATED | EEH_PE_RECOVERING)))
  1378. return EEH_PE_STATE_UNAVAIL;
  1379. result = eeh_ops->get_state(pe, NULL);
  1380. rst_active = !!(result & EEH_STATE_RESET_ACTIVE);
  1381. dma_en = !!(result & EEH_STATE_DMA_ENABLED);
  1382. mmio_en = !!(result & EEH_STATE_MMIO_ENABLED);
  1383. if (rst_active)
  1384. ret = EEH_PE_STATE_RESET;
  1385. else if (dma_en && mmio_en)
  1386. ret = EEH_PE_STATE_NORMAL;
  1387. else if (!dma_en && !mmio_en)
  1388. ret = EEH_PE_STATE_STOPPED_IO_DMA;
  1389. else if (!dma_en && mmio_en)
  1390. ret = EEH_PE_STATE_STOPPED_DMA;
  1391. else
  1392. ret = EEH_PE_STATE_UNAVAIL;
  1393. return ret;
  1394. }
  1395. EXPORT_SYMBOL_GPL(eeh_pe_get_state);
  1396. static int eeh_pe_reenable_devices(struct eeh_pe *pe)
  1397. {
  1398. struct eeh_dev *edev, *tmp;
  1399. struct pci_dev *pdev;
  1400. int ret = 0;
  1401. /* Restore config space */
  1402. eeh_pe_restore_bars(pe);
  1403. /*
  1404. * Reenable PCI devices as the devices passed
  1405. * through are always enabled before the reset.
  1406. */
  1407. eeh_pe_for_each_dev(pe, edev, tmp) {
  1408. pdev = eeh_dev_to_pci_dev(edev);
  1409. if (!pdev)
  1410. continue;
  1411. ret = pci_reenable_device(pdev);
  1412. if (ret) {
  1413. pr_warn("%s: Failure %d reenabling %s\n",
  1414. __func__, ret, pci_name(pdev));
  1415. return ret;
  1416. }
  1417. }
  1418. /* The PE is still in frozen state */
  1419. return eeh_unfreeze_pe(pe, true);
  1420. }
  1421. /**
  1422. * eeh_pe_reset - Issue PE reset according to specified type
  1423. * @pe: EEH PE
  1424. * @option: reset type
  1425. *
  1426. * The routine is called to reset the specified PE with the
  1427. * indicated type, either fundamental reset or hot reset.
  1428. * PE reset is the most important part for error recovery.
  1429. */
  1430. int eeh_pe_reset(struct eeh_pe *pe, int option)
  1431. {
  1432. int ret = 0;
  1433. /* Invalid PE ? */
  1434. if (!pe)
  1435. return -ENODEV;
  1436. if (!eeh_ops || !eeh_ops->set_option || !eeh_ops->reset)
  1437. return -ENOENT;
  1438. switch (option) {
  1439. case EEH_RESET_DEACTIVATE:
  1440. ret = eeh_ops->reset(pe, option);
  1441. eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED);
  1442. if (ret)
  1443. break;
  1444. ret = eeh_pe_reenable_devices(pe);
  1445. break;
  1446. case EEH_RESET_HOT:
  1447. case EEH_RESET_FUNDAMENTAL:
  1448. /*
  1449. * Proactively freeze the PE to drop all MMIO access
  1450. * during reset, which should be banned as it's always
  1451. * cause recursive EEH error.
  1452. */
  1453. eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
  1454. eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
  1455. ret = eeh_ops->reset(pe, option);
  1456. break;
  1457. default:
  1458. pr_debug("%s: Unsupported option %d\n",
  1459. __func__, option);
  1460. ret = -EINVAL;
  1461. }
  1462. return ret;
  1463. }
  1464. EXPORT_SYMBOL_GPL(eeh_pe_reset);
  1465. /**
  1466. * eeh_pe_configure - Configure PCI bridges after PE reset
  1467. * @pe: EEH PE
  1468. *
  1469. * The routine is called to restore the PCI config space for
  1470. * those PCI devices, especially PCI bridges affected by PE
  1471. * reset issued previously.
  1472. */
  1473. int eeh_pe_configure(struct eeh_pe *pe)
  1474. {
  1475. int ret = 0;
  1476. /* Invalid PE ? */
  1477. if (!pe)
  1478. return -ENODEV;
  1479. return ret;
  1480. }
  1481. EXPORT_SYMBOL_GPL(eeh_pe_configure);
  1482. /**
  1483. * eeh_pe_inject_err - Injecting the specified PCI error to the indicated PE
  1484. * @pe: the indicated PE
  1485. * @type: error type
  1486. * @function: error function
  1487. * @addr: address
  1488. * @mask: address mask
  1489. *
  1490. * The routine is called to inject the specified PCI error, which
  1491. * is determined by @type and @function, to the indicated PE for
  1492. * testing purpose.
  1493. */
  1494. int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
  1495. unsigned long addr, unsigned long mask)
  1496. {
  1497. /* Invalid PE ? */
  1498. if (!pe)
  1499. return -ENODEV;
  1500. /* Unsupported operation ? */
  1501. if (!eeh_ops || !eeh_ops->err_inject)
  1502. return -ENOENT;
  1503. /* Check on PCI error type */
  1504. if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64)
  1505. return -EINVAL;
  1506. /* Check on PCI error function */
  1507. if (func < EEH_ERR_FUNC_MIN || func > EEH_ERR_FUNC_MAX)
  1508. return -EINVAL;
  1509. return eeh_ops->err_inject(pe, type, func, addr, mask);
  1510. }
  1511. EXPORT_SYMBOL_GPL(eeh_pe_inject_err);
  1512. static int proc_eeh_show(struct seq_file *m, void *v)
  1513. {
  1514. if (!eeh_enabled()) {
  1515. seq_printf(m, "EEH Subsystem is globally disabled\n");
  1516. seq_printf(m, "eeh_total_mmio_ffs=%llu\n", eeh_stats.total_mmio_ffs);
  1517. } else {
  1518. seq_printf(m, "EEH Subsystem is enabled\n");
  1519. seq_printf(m,
  1520. "no device=%llu\n"
  1521. "no device node=%llu\n"
  1522. "no config address=%llu\n"
  1523. "check not wanted=%llu\n"
  1524. "eeh_total_mmio_ffs=%llu\n"
  1525. "eeh_false_positives=%llu\n"
  1526. "eeh_slot_resets=%llu\n",
  1527. eeh_stats.no_device,
  1528. eeh_stats.no_dn,
  1529. eeh_stats.no_cfg_addr,
  1530. eeh_stats.ignored_check,
  1531. eeh_stats.total_mmio_ffs,
  1532. eeh_stats.false_positives,
  1533. eeh_stats.slot_resets);
  1534. }
  1535. return 0;
  1536. }
  1537. #ifdef CONFIG_DEBUG_FS
  1538. static int eeh_enable_dbgfs_set(void *data, u64 val)
  1539. {
  1540. if (val)
  1541. eeh_clear_flag(EEH_FORCE_DISABLED);
  1542. else
  1543. eeh_add_flag(EEH_FORCE_DISABLED);
  1544. return 0;
  1545. }
  1546. static int eeh_enable_dbgfs_get(void *data, u64 *val)
  1547. {
  1548. if (eeh_enabled())
  1549. *val = 0x1ul;
  1550. else
  1551. *val = 0x0ul;
  1552. return 0;
  1553. }
  1554. static int eeh_freeze_dbgfs_set(void *data, u64 val)
  1555. {
  1556. eeh_max_freezes = val;
  1557. return 0;
  1558. }
  1559. static int eeh_freeze_dbgfs_get(void *data, u64 *val)
  1560. {
  1561. *val = eeh_max_freezes;
  1562. return 0;
  1563. }
  1564. DEFINE_SIMPLE_ATTRIBUTE(eeh_enable_dbgfs_ops, eeh_enable_dbgfs_get,
  1565. eeh_enable_dbgfs_set, "0x%llx\n");
  1566. DEFINE_SIMPLE_ATTRIBUTE(eeh_freeze_dbgfs_ops, eeh_freeze_dbgfs_get,
  1567. eeh_freeze_dbgfs_set, "0x%llx\n");
  1568. #endif
  1569. static int __init eeh_init_proc(void)
  1570. {
  1571. if (machine_is(pseries) || machine_is(powernv)) {
  1572. proc_create_single("powerpc/eeh", 0, NULL, proc_eeh_show);
  1573. #ifdef CONFIG_DEBUG_FS
  1574. debugfs_create_file("eeh_enable", 0600,
  1575. powerpc_debugfs_root, NULL,
  1576. &eeh_enable_dbgfs_ops);
  1577. debugfs_create_file("eeh_max_freezes", 0600,
  1578. powerpc_debugfs_root, NULL,
  1579. &eeh_freeze_dbgfs_ops);
  1580. #endif
  1581. }
  1582. return 0;
  1583. }
  1584. __initcall(eeh_init_proc);