eeh.c 48 KB

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