eeh.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /*
  2. * eeh.c
  3. * Copyright IBM Corporation 2001, 2005, 2006
  4. * Copyright Dave Engebretsen & Todd Inglett 2001
  5. * Copyright Linas Vepstas 2005, 2006
  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/init.h>
  25. #include <linux/list.h>
  26. #include <linux/pci.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/rbtree.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/of.h>
  32. #include <linux/atomic.h>
  33. #include <asm/eeh.h>
  34. #include <asm/eeh_event.h>
  35. #include <asm/io.h>
  36. #include <asm/machdep.h>
  37. #include <asm/ppc-pci.h>
  38. #include <asm/rtas.h>
  39. /** Overview:
  40. * EEH, or "Extended Error Handling" is a PCI bridge technology for
  41. * dealing with PCI bus errors that can't be dealt with within the
  42. * usual PCI framework, except by check-stopping the CPU. Systems
  43. * that are designed for high-availability/reliability cannot afford
  44. * to crash due to a "mere" PCI error, thus the need for EEH.
  45. * An EEH-capable bridge operates by converting a detected error
  46. * into a "slot freeze", taking the PCI adapter off-line, making
  47. * the slot behave, from the OS'es point of view, as if the slot
  48. * were "empty": all reads return 0xff's and all writes are silently
  49. * ignored. EEH slot isolation events can be triggered by parity
  50. * errors on the address or data busses (e.g. during posted writes),
  51. * which in turn might be caused by low voltage on the bus, dust,
  52. * vibration, humidity, radioactivity or plain-old failed hardware.
  53. *
  54. * Note, however, that one of the leading causes of EEH slot
  55. * freeze events are buggy device drivers, buggy device microcode,
  56. * or buggy device hardware. This is because any attempt by the
  57. * device to bus-master data to a memory address that is not
  58. * assigned to the device will trigger a slot freeze. (The idea
  59. * is to prevent devices-gone-wild from corrupting system memory).
  60. * Buggy hardware/drivers will have a miserable time co-existing
  61. * with EEH.
  62. *
  63. * Ideally, a PCI device driver, when suspecting that an isolation
  64. * event has occurred (e.g. by reading 0xff's), will then ask EEH
  65. * whether this is the case, and then take appropriate steps to
  66. * reset the PCI slot, the PCI device, and then resume operations.
  67. * However, until that day, the checking is done here, with the
  68. * eeh_check_failure() routine embedded in the MMIO macros. If
  69. * the slot is found to be isolated, an "EEH Event" is synthesized
  70. * and sent out for processing.
  71. */
  72. /* If a device driver keeps reading an MMIO register in an interrupt
  73. * handler after a slot isolation event, it might be broken.
  74. * This sets the threshold for how many read attempts we allow
  75. * before printing an error message.
  76. */
  77. #define EEH_MAX_FAILS 2100000
  78. /* Time to wait for a PCI slot to report status, in milliseconds */
  79. #define PCI_BUS_RESET_WAIT_MSEC (60*1000)
  80. /* RTAS tokens */
  81. static int ibm_set_eeh_option;
  82. static int ibm_set_slot_reset;
  83. static int ibm_read_slot_reset_state;
  84. static int ibm_read_slot_reset_state2;
  85. static int ibm_slot_error_detail;
  86. static int ibm_get_config_addr_info;
  87. static int ibm_get_config_addr_info2;
  88. static int ibm_configure_bridge;
  89. static int ibm_configure_pe;
  90. int eeh_subsystem_enabled;
  91. EXPORT_SYMBOL(eeh_subsystem_enabled);
  92. /* Lock to avoid races due to multiple reports of an error */
  93. static DEFINE_RAW_SPINLOCK(confirm_error_lock);
  94. /* Buffer for reporting slot-error-detail rtas calls. Its here
  95. * in BSS, and not dynamically alloced, so that it ends up in
  96. * RMO where RTAS can access it.
  97. */
  98. static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
  99. static DEFINE_SPINLOCK(slot_errbuf_lock);
  100. static int eeh_error_buf_size;
  101. /* Buffer for reporting pci register dumps. Its here in BSS, and
  102. * not dynamically alloced, so that it ends up in RMO where RTAS
  103. * can access it.
  104. */
  105. #define EEH_PCI_REGS_LOG_LEN 4096
  106. static unsigned char pci_regs_buf[EEH_PCI_REGS_LOG_LEN];
  107. /* System monitoring statistics */
  108. static unsigned long no_device;
  109. static unsigned long no_dn;
  110. static unsigned long no_cfg_addr;
  111. static unsigned long ignored_check;
  112. static unsigned long total_mmio_ffs;
  113. static unsigned long false_positives;
  114. static unsigned long slot_resets;
  115. #define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)
  116. /* --------------------------------------------------------------- */
  117. /* Below lies the EEH event infrastructure */
  118. static void rtas_slot_error_detail(struct pci_dn *pdn, int severity,
  119. char *driver_log, size_t loglen)
  120. {
  121. int config_addr;
  122. unsigned long flags;
  123. int rc;
  124. /* Log the error with the rtas logger */
  125. spin_lock_irqsave(&slot_errbuf_lock, flags);
  126. memset(slot_errbuf, 0, eeh_error_buf_size);
  127. /* Use PE configuration address, if present */
  128. config_addr = pdn->eeh_config_addr;
  129. if (pdn->eeh_pe_config_addr)
  130. config_addr = pdn->eeh_pe_config_addr;
  131. rc = rtas_call(ibm_slot_error_detail,
  132. 8, 1, NULL, config_addr,
  133. BUID_HI(pdn->phb->buid),
  134. BUID_LO(pdn->phb->buid),
  135. virt_to_phys(driver_log), loglen,
  136. virt_to_phys(slot_errbuf),
  137. eeh_error_buf_size,
  138. severity);
  139. if (rc == 0)
  140. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  141. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  142. }
  143. /**
  144. * gather_pci_data - copy assorted PCI config space registers to buff
  145. * @pdn: device to report data for
  146. * @buf: point to buffer in which to log
  147. * @len: amount of room in buffer
  148. *
  149. * This routine captures assorted PCI configuration space data,
  150. * and puts them into a buffer for RTAS error logging.
  151. */
  152. static size_t gather_pci_data(struct pci_dn *pdn, char * buf, size_t len)
  153. {
  154. struct pci_dev *dev = pdn->pcidev;
  155. u32 cfg;
  156. int cap, i;
  157. int n = 0;
  158. n += scnprintf(buf+n, len-n, "%s\n", pdn->node->full_name);
  159. printk(KERN_WARNING "EEH: of node=%s\n", pdn->node->full_name);
  160. rtas_read_config(pdn, PCI_VENDOR_ID, 4, &cfg);
  161. n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
  162. printk(KERN_WARNING "EEH: PCI device/vendor: %08x\n", cfg);
  163. rtas_read_config(pdn, PCI_COMMAND, 4, &cfg);
  164. n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg);
  165. printk(KERN_WARNING "EEH: PCI cmd/status register: %08x\n", cfg);
  166. if (!dev) {
  167. printk(KERN_WARNING "EEH: no PCI device for this of node\n");
  168. return n;
  169. }
  170. /* Gather bridge-specific registers */
  171. if (dev->class >> 16 == PCI_BASE_CLASS_BRIDGE) {
  172. rtas_read_config(pdn, PCI_SEC_STATUS, 2, &cfg);
  173. n += scnprintf(buf+n, len-n, "sec stat:%x\n", cfg);
  174. printk(KERN_WARNING "EEH: Bridge secondary status: %04x\n", cfg);
  175. rtas_read_config(pdn, PCI_BRIDGE_CONTROL, 2, &cfg);
  176. n += scnprintf(buf+n, len-n, "brdg ctl:%x\n", cfg);
  177. printk(KERN_WARNING "EEH: Bridge control: %04x\n", cfg);
  178. }
  179. /* Dump out the PCI-X command and status regs */
  180. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  181. if (cap) {
  182. rtas_read_config(pdn, cap, 4, &cfg);
  183. n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg);
  184. printk(KERN_WARNING "EEH: PCI-X cmd: %08x\n", cfg);
  185. rtas_read_config(pdn, cap+4, 4, &cfg);
  186. n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg);
  187. printk(KERN_WARNING "EEH: PCI-X status: %08x\n", cfg);
  188. }
  189. /* If PCI-E capable, dump PCI-E cap 10, and the AER */
  190. cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
  191. if (cap) {
  192. n += scnprintf(buf+n, len-n, "pci-e cap10:\n");
  193. printk(KERN_WARNING
  194. "EEH: PCI-E capabilities and status follow:\n");
  195. for (i=0; i<=8; i++) {
  196. rtas_read_config(pdn, cap+4*i, 4, &cfg);
  197. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  198. printk(KERN_WARNING "EEH: PCI-E %02x: %08x\n", i, cfg);
  199. }
  200. cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  201. if (cap) {
  202. n += scnprintf(buf+n, len-n, "pci-e AER:\n");
  203. printk(KERN_WARNING
  204. "EEH: PCI-E AER capability register set follows:\n");
  205. for (i=0; i<14; i++) {
  206. rtas_read_config(pdn, cap+4*i, 4, &cfg);
  207. n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
  208. printk(KERN_WARNING "EEH: PCI-E AER %02x: %08x\n", i, cfg);
  209. }
  210. }
  211. }
  212. /* Gather status on devices under the bridge */
  213. if (dev->class >> 16 == PCI_BASE_CLASS_BRIDGE) {
  214. struct device_node *dn;
  215. for_each_child_of_node(pdn->node, dn) {
  216. pdn = PCI_DN(dn);
  217. if (pdn)
  218. n += gather_pci_data(pdn, buf+n, len-n);
  219. }
  220. }
  221. return n;
  222. }
  223. void eeh_slot_error_detail(struct pci_dn *pdn, int severity)
  224. {
  225. size_t loglen = 0;
  226. pci_regs_buf[0] = 0;
  227. rtas_pci_enable(pdn, EEH_THAW_MMIO);
  228. rtas_configure_bridge(pdn);
  229. eeh_restore_bars(pdn);
  230. loglen = gather_pci_data(pdn, pci_regs_buf, EEH_PCI_REGS_LOG_LEN);
  231. rtas_slot_error_detail(pdn, severity, pci_regs_buf, loglen);
  232. }
  233. /**
  234. * read_slot_reset_state - Read the reset state of a device node's slot
  235. * @dn: device node to read
  236. * @rets: array to return results in
  237. */
  238. static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
  239. {
  240. int token, outputs;
  241. int config_addr;
  242. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  243. token = ibm_read_slot_reset_state2;
  244. outputs = 4;
  245. } else {
  246. token = ibm_read_slot_reset_state;
  247. rets[2] = 0; /* fake PE Unavailable info */
  248. outputs = 3;
  249. }
  250. /* Use PE configuration address, if present */
  251. config_addr = pdn->eeh_config_addr;
  252. if (pdn->eeh_pe_config_addr)
  253. config_addr = pdn->eeh_pe_config_addr;
  254. return rtas_call(token, 3, outputs, rets, config_addr,
  255. BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
  256. }
  257. /**
  258. * eeh_wait_for_slot_status - returns error status of slot
  259. * @pdn pci device node
  260. * @max_wait_msecs maximum number to millisecs to wait
  261. *
  262. * Return negative value if a permanent error, else return
  263. * Partition Endpoint (PE) status value.
  264. *
  265. * If @max_wait_msecs is positive, then this routine will
  266. * sleep until a valid status can be obtained, or until
  267. * the max allowed wait time is exceeded, in which case
  268. * a -2 is returned.
  269. */
  270. int
  271. eeh_wait_for_slot_status(struct pci_dn *pdn, int max_wait_msecs)
  272. {
  273. int rc;
  274. int rets[3];
  275. int mwait;
  276. while (1) {
  277. rc = read_slot_reset_state(pdn, rets);
  278. if (rc) return rc;
  279. if (rets[1] == 0) return -1; /* EEH is not supported */
  280. if (rets[0] != 5) return rets[0]; /* return actual status */
  281. if (rets[2] == 0) return -1; /* permanently unavailable */
  282. if (max_wait_msecs <= 0) break;
  283. mwait = rets[2];
  284. if (mwait <= 0) {
  285. printk (KERN_WARNING
  286. "EEH: Firmware returned bad wait value=%d\n", mwait);
  287. mwait = 1000;
  288. } else if (mwait > 300*1000) {
  289. printk (KERN_WARNING
  290. "EEH: Firmware is taking too long, time=%d\n", mwait);
  291. mwait = 300*1000;
  292. }
  293. max_wait_msecs -= mwait;
  294. msleep (mwait);
  295. }
  296. printk(KERN_WARNING "EEH: Timed out waiting for slot status\n");
  297. return -2;
  298. }
  299. /**
  300. * eeh_token_to_phys - convert EEH address token to phys address
  301. * @token i/o token, should be address in the form 0xA....
  302. */
  303. static inline unsigned long eeh_token_to_phys(unsigned long token)
  304. {
  305. pte_t *ptep;
  306. unsigned long pa;
  307. ptep = find_linux_pte(init_mm.pgd, token);
  308. if (!ptep)
  309. return token;
  310. pa = pte_pfn(*ptep) << PAGE_SHIFT;
  311. return pa | (token & (PAGE_SIZE-1));
  312. }
  313. /**
  314. * Return the "partitionable endpoint" (pe) under which this device lies
  315. */
  316. struct device_node * find_device_pe(struct device_node *dn)
  317. {
  318. while ((dn->parent) && PCI_DN(dn->parent) &&
  319. (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
  320. dn = dn->parent;
  321. }
  322. return dn;
  323. }
  324. /** Mark all devices that are children of this device as failed.
  325. * Mark the device driver too, so that it can see the failure
  326. * immediately; this is critical, since some drivers poll
  327. * status registers in interrupts ... If a driver is polling,
  328. * and the slot is frozen, then the driver can deadlock in
  329. * an interrupt context, which is bad.
  330. */
  331. static void __eeh_mark_slot(struct device_node *parent, int mode_flag)
  332. {
  333. struct device_node *dn;
  334. for_each_child_of_node(parent, dn) {
  335. if (PCI_DN(dn)) {
  336. /* Mark the pci device driver too */
  337. struct pci_dev *dev = PCI_DN(dn)->pcidev;
  338. PCI_DN(dn)->eeh_mode |= mode_flag;
  339. if (dev && dev->driver)
  340. dev->error_state = pci_channel_io_frozen;
  341. __eeh_mark_slot(dn, mode_flag);
  342. }
  343. }
  344. }
  345. void eeh_mark_slot (struct device_node *dn, int mode_flag)
  346. {
  347. struct pci_dev *dev;
  348. dn = find_device_pe (dn);
  349. /* Back up one, since config addrs might be shared */
  350. if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
  351. dn = dn->parent;
  352. PCI_DN(dn)->eeh_mode |= mode_flag;
  353. /* Mark the pci device too */
  354. dev = PCI_DN(dn)->pcidev;
  355. if (dev)
  356. dev->error_state = pci_channel_io_frozen;
  357. __eeh_mark_slot(dn, mode_flag);
  358. }
  359. static void __eeh_clear_slot(struct device_node *parent, int mode_flag)
  360. {
  361. struct device_node *dn;
  362. for_each_child_of_node(parent, dn) {
  363. if (PCI_DN(dn)) {
  364. PCI_DN(dn)->eeh_mode &= ~mode_flag;
  365. PCI_DN(dn)->eeh_check_count = 0;
  366. __eeh_clear_slot(dn, mode_flag);
  367. }
  368. }
  369. }
  370. void eeh_clear_slot (struct device_node *dn, int mode_flag)
  371. {
  372. unsigned long flags;
  373. raw_spin_lock_irqsave(&confirm_error_lock, flags);
  374. dn = find_device_pe (dn);
  375. /* Back up one, since config addrs might be shared */
  376. if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
  377. dn = dn->parent;
  378. PCI_DN(dn)->eeh_mode &= ~mode_flag;
  379. PCI_DN(dn)->eeh_check_count = 0;
  380. __eeh_clear_slot(dn, mode_flag);
  381. raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
  382. }
  383. void __eeh_set_pe_freset(struct device_node *parent, unsigned int *freset)
  384. {
  385. struct device_node *dn;
  386. for_each_child_of_node(parent, dn) {
  387. if (PCI_DN(dn)) {
  388. struct pci_dev *dev = PCI_DN(dn)->pcidev;
  389. if (dev && dev->driver)
  390. *freset |= dev->needs_freset;
  391. __eeh_set_pe_freset(dn, freset);
  392. }
  393. }
  394. }
  395. void eeh_set_pe_freset(struct device_node *dn, unsigned int *freset)
  396. {
  397. struct pci_dev *dev;
  398. dn = find_device_pe(dn);
  399. /* Back up one, since config addrs might be shared */
  400. if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
  401. dn = dn->parent;
  402. dev = PCI_DN(dn)->pcidev;
  403. if (dev)
  404. *freset |= dev->needs_freset;
  405. __eeh_set_pe_freset(dn, freset);
  406. }
  407. /**
  408. * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
  409. * @dn device node
  410. * @dev pci device, if known
  411. *
  412. * Check for an EEH failure for the given device node. Call this
  413. * routine if the result of a read was all 0xff's and you want to
  414. * find out if this is due to an EEH slot freeze. This routine
  415. * will query firmware for the EEH status.
  416. *
  417. * Returns 0 if there has not been an EEH error; otherwise returns
  418. * a non-zero value and queues up a slot isolation event notification.
  419. *
  420. * It is safe to call this routine in an interrupt context.
  421. */
  422. int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
  423. {
  424. int ret;
  425. int rets[3];
  426. unsigned long flags;
  427. struct pci_dn *pdn;
  428. int rc = 0;
  429. const char *location;
  430. total_mmio_ffs++;
  431. if (!eeh_subsystem_enabled)
  432. return 0;
  433. if (!dn) {
  434. no_dn++;
  435. return 0;
  436. }
  437. dn = find_device_pe(dn);
  438. pdn = PCI_DN(dn);
  439. /* Access to IO BARs might get this far and still not want checking. */
  440. if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
  441. pdn->eeh_mode & EEH_MODE_NOCHECK) {
  442. ignored_check++;
  443. pr_debug("EEH: Ignored check (%x) for %s %s\n",
  444. pdn->eeh_mode, eeh_pci_name(dev), dn->full_name);
  445. return 0;
  446. }
  447. if (!pdn->eeh_config_addr && !pdn->eeh_pe_config_addr) {
  448. no_cfg_addr++;
  449. return 0;
  450. }
  451. /* If we already have a pending isolation event for this
  452. * slot, we know it's bad already, we don't need to check.
  453. * Do this checking under a lock; as multiple PCI devices
  454. * in one slot might report errors simultaneously, and we
  455. * only want one error recovery routine running.
  456. */
  457. raw_spin_lock_irqsave(&confirm_error_lock, flags);
  458. rc = 1;
  459. if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
  460. pdn->eeh_check_count ++;
  461. if (pdn->eeh_check_count % EEH_MAX_FAILS == 0) {
  462. location = of_get_property(dn, "ibm,loc-code", NULL);
  463. printk (KERN_ERR "EEH: %d reads ignored for recovering device at "
  464. "location=%s driver=%s pci addr=%s\n",
  465. pdn->eeh_check_count, location,
  466. dev->driver->name, eeh_pci_name(dev));
  467. printk (KERN_ERR "EEH: Might be infinite loop in %s driver\n",
  468. dev->driver->name);
  469. dump_stack();
  470. }
  471. goto dn_unlock;
  472. }
  473. /*
  474. * Now test for an EEH failure. This is VERY expensive.
  475. * Note that the eeh_config_addr may be a parent device
  476. * in the case of a device behind a bridge, or it may be
  477. * function zero of a multi-function device.
  478. * In any case they must share a common PHB.
  479. */
  480. ret = read_slot_reset_state(pdn, rets);
  481. /* If the call to firmware failed, punt */
  482. if (ret != 0) {
  483. printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
  484. ret, dn->full_name);
  485. false_positives++;
  486. pdn->eeh_false_positives ++;
  487. rc = 0;
  488. goto dn_unlock;
  489. }
  490. /* Note that config-io to empty slots may fail;
  491. * they are empty when they don't have children. */
  492. if ((rets[0] == 5) && (rets[2] == 0) && (dn->child == NULL)) {
  493. false_positives++;
  494. pdn->eeh_false_positives ++;
  495. rc = 0;
  496. goto dn_unlock;
  497. }
  498. /* If EEH is not supported on this device, punt. */
  499. if (rets[1] != 1) {
  500. printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
  501. ret, dn->full_name);
  502. false_positives++;
  503. pdn->eeh_false_positives ++;
  504. rc = 0;
  505. goto dn_unlock;
  506. }
  507. /* If not the kind of error we know about, punt. */
  508. if (rets[0] != 1 && rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
  509. false_positives++;
  510. pdn->eeh_false_positives ++;
  511. rc = 0;
  512. goto dn_unlock;
  513. }
  514. slot_resets++;
  515. /* Avoid repeated reports of this failure, including problems
  516. * with other functions on this device, and functions under
  517. * bridges. */
  518. eeh_mark_slot (dn, EEH_MODE_ISOLATED);
  519. raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
  520. eeh_send_failure_event (dn, dev);
  521. /* Most EEH events are due to device driver bugs. Having
  522. * a stack trace will help the device-driver authors figure
  523. * out what happened. So print that out. */
  524. dump_stack();
  525. return 1;
  526. dn_unlock:
  527. raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
  528. return rc;
  529. }
  530. EXPORT_SYMBOL_GPL(eeh_dn_check_failure);
  531. /**
  532. * eeh_check_failure - check if all 1's data is due to EEH slot freeze
  533. * @token i/o token, should be address in the form 0xA....
  534. * @val value, should be all 1's (XXX why do we need this arg??)
  535. *
  536. * Check for an EEH failure at the given token address. Call this
  537. * routine if the result of a read was all 0xff's and you want to
  538. * find out if this is due to an EEH slot freeze event. This routine
  539. * will query firmware for the EEH status.
  540. *
  541. * Note this routine is safe to call in an interrupt context.
  542. */
  543. unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
  544. {
  545. unsigned long addr;
  546. struct pci_dev *dev;
  547. struct device_node *dn;
  548. /* Finding the phys addr + pci device; this is pretty quick. */
  549. addr = eeh_token_to_phys((unsigned long __force) token);
  550. dev = pci_get_device_by_addr(addr);
  551. if (!dev) {
  552. no_device++;
  553. return val;
  554. }
  555. dn = pci_device_to_OF_node(dev);
  556. eeh_dn_check_failure (dn, dev);
  557. pci_dev_put(dev);
  558. return val;
  559. }
  560. EXPORT_SYMBOL(eeh_check_failure);
  561. /* ------------------------------------------------------------- */
  562. /* The code below deals with error recovery */
  563. /**
  564. * rtas_pci_enable - enable MMIO or DMA transfers for this slot
  565. * @pdn pci device node
  566. */
  567. int
  568. rtas_pci_enable(struct pci_dn *pdn, int function)
  569. {
  570. int config_addr;
  571. int rc;
  572. /* Use PE configuration address, if present */
  573. config_addr = pdn->eeh_config_addr;
  574. if (pdn->eeh_pe_config_addr)
  575. config_addr = pdn->eeh_pe_config_addr;
  576. rc = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  577. config_addr,
  578. BUID_HI(pdn->phb->buid),
  579. BUID_LO(pdn->phb->buid),
  580. function);
  581. if (rc)
  582. printk(KERN_WARNING "EEH: Unexpected state change %d, err=%d dn=%s\n",
  583. function, rc, pdn->node->full_name);
  584. rc = eeh_wait_for_slot_status (pdn, PCI_BUS_RESET_WAIT_MSEC);
  585. if ((rc == 4) && (function == EEH_THAW_MMIO))
  586. return 0;
  587. return rc;
  588. }
  589. /**
  590. * rtas_pci_slot_reset - raises/lowers the pci #RST line
  591. * @pdn pci device node
  592. * @state: 1/0 to raise/lower the #RST
  593. *
  594. * Clear the EEH-frozen condition on a slot. This routine
  595. * asserts the PCI #RST line if the 'state' argument is '1',
  596. * and drops the #RST line if 'state is '0'. This routine is
  597. * safe to call in an interrupt context.
  598. *
  599. */
  600. static void
  601. rtas_pci_slot_reset(struct pci_dn *pdn, int state)
  602. {
  603. int config_addr;
  604. int rc;
  605. BUG_ON (pdn==NULL);
  606. if (!pdn->phb) {
  607. printk (KERN_WARNING "EEH: in slot reset, device node %s has no phb\n",
  608. pdn->node->full_name);
  609. return;
  610. }
  611. /* Use PE configuration address, if present */
  612. config_addr = pdn->eeh_config_addr;
  613. if (pdn->eeh_pe_config_addr)
  614. config_addr = pdn->eeh_pe_config_addr;
  615. rc = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  616. config_addr,
  617. BUID_HI(pdn->phb->buid),
  618. BUID_LO(pdn->phb->buid),
  619. state);
  620. /* Fundamental-reset not supported on this PE, try hot-reset */
  621. if (rc == -8 && state == 3) {
  622. rc = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  623. config_addr,
  624. BUID_HI(pdn->phb->buid),
  625. BUID_LO(pdn->phb->buid), 1);
  626. if (rc)
  627. printk(KERN_WARNING
  628. "EEH: Unable to reset the failed slot,"
  629. " #RST=%d dn=%s\n",
  630. rc, pdn->node->full_name);
  631. }
  632. }
  633. /**
  634. * pcibios_set_pcie_slot_reset - Set PCI-E reset state
  635. * @dev: pci device struct
  636. * @state: reset state to enter
  637. *
  638. * Return value:
  639. * 0 if success
  640. **/
  641. int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
  642. {
  643. struct device_node *dn = pci_device_to_OF_node(dev);
  644. struct pci_dn *pdn = PCI_DN(dn);
  645. switch (state) {
  646. case pcie_deassert_reset:
  647. rtas_pci_slot_reset(pdn, 0);
  648. break;
  649. case pcie_hot_reset:
  650. rtas_pci_slot_reset(pdn, 1);
  651. break;
  652. case pcie_warm_reset:
  653. rtas_pci_slot_reset(pdn, 3);
  654. break;
  655. default:
  656. return -EINVAL;
  657. };
  658. return 0;
  659. }
  660. /**
  661. * rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
  662. * @pdn: pci device node to be reset.
  663. */
  664. static void __rtas_set_slot_reset(struct pci_dn *pdn)
  665. {
  666. unsigned int freset = 0;
  667. /* Determine type of EEH reset required for
  668. * Partitionable Endpoint, a hot-reset (1)
  669. * or a fundamental reset (3).
  670. * A fundamental reset required by any device under
  671. * Partitionable Endpoint trumps hot-reset.
  672. */
  673. eeh_set_pe_freset(pdn->node, &freset);
  674. if (freset)
  675. rtas_pci_slot_reset(pdn, 3);
  676. else
  677. rtas_pci_slot_reset(pdn, 1);
  678. /* The PCI bus requires that the reset be held high for at least
  679. * a 100 milliseconds. We wait a bit longer 'just in case'. */
  680. #define PCI_BUS_RST_HOLD_TIME_MSEC 250
  681. msleep (PCI_BUS_RST_HOLD_TIME_MSEC);
  682. /* We might get hit with another EEH freeze as soon as the
  683. * pci slot reset line is dropped. Make sure we don't miss
  684. * these, and clear the flag now. */
  685. eeh_clear_slot (pdn->node, EEH_MODE_ISOLATED);
  686. rtas_pci_slot_reset (pdn, 0);
  687. /* After a PCI slot has been reset, the PCI Express spec requires
  688. * a 1.5 second idle time for the bus to stabilize, before starting
  689. * up traffic. */
  690. #define PCI_BUS_SETTLE_TIME_MSEC 1800
  691. msleep (PCI_BUS_SETTLE_TIME_MSEC);
  692. }
  693. int rtas_set_slot_reset(struct pci_dn *pdn)
  694. {
  695. int i, rc;
  696. /* Take three shots at resetting the bus */
  697. for (i=0; i<3; i++) {
  698. __rtas_set_slot_reset(pdn);
  699. rc = eeh_wait_for_slot_status(pdn, PCI_BUS_RESET_WAIT_MSEC);
  700. if (rc == 0)
  701. return 0;
  702. if (rc < 0) {
  703. printk(KERN_ERR "EEH: unrecoverable slot failure %s\n",
  704. pdn->node->full_name);
  705. return -1;
  706. }
  707. printk(KERN_ERR "EEH: bus reset %d failed on slot %s, rc=%d\n",
  708. i+1, pdn->node->full_name, rc);
  709. }
  710. return -1;
  711. }
  712. /* ------------------------------------------------------- */
  713. /** Save and restore of PCI BARs
  714. *
  715. * Although firmware will set up BARs during boot, it doesn't
  716. * set up device BAR's after a device reset, although it will,
  717. * if requested, set up bridge configuration. Thus, we need to
  718. * configure the PCI devices ourselves.
  719. */
  720. /**
  721. * __restore_bars - Restore the Base Address Registers
  722. * @pdn: pci device node
  723. *
  724. * Loads the PCI configuration space base address registers,
  725. * the expansion ROM base address, the latency timer, and etc.
  726. * from the saved values in the device node.
  727. */
  728. static inline void __restore_bars (struct pci_dn *pdn)
  729. {
  730. int i;
  731. u32 cmd;
  732. if (NULL==pdn->phb) return;
  733. for (i=4; i<10; i++) {
  734. rtas_write_config(pdn, i*4, 4, pdn->config_space[i]);
  735. }
  736. /* 12 == Expansion ROM Address */
  737. rtas_write_config(pdn, 12*4, 4, pdn->config_space[12]);
  738. #define BYTE_SWAP(OFF) (8*((OFF)/4)+3-(OFF))
  739. #define SAVED_BYTE(OFF) (((u8 *)(pdn->config_space))[BYTE_SWAP(OFF)])
  740. rtas_write_config (pdn, PCI_CACHE_LINE_SIZE, 1,
  741. SAVED_BYTE(PCI_CACHE_LINE_SIZE));
  742. rtas_write_config (pdn, PCI_LATENCY_TIMER, 1,
  743. SAVED_BYTE(PCI_LATENCY_TIMER));
  744. /* max latency, min grant, interrupt pin and line */
  745. rtas_write_config(pdn, 15*4, 4, pdn->config_space[15]);
  746. /* Restore PERR & SERR bits, some devices require it,
  747. don't touch the other command bits */
  748. rtas_read_config(pdn, PCI_COMMAND, 4, &cmd);
  749. if (pdn->config_space[1] & PCI_COMMAND_PARITY)
  750. cmd |= PCI_COMMAND_PARITY;
  751. else
  752. cmd &= ~PCI_COMMAND_PARITY;
  753. if (pdn->config_space[1] & PCI_COMMAND_SERR)
  754. cmd |= PCI_COMMAND_SERR;
  755. else
  756. cmd &= ~PCI_COMMAND_SERR;
  757. rtas_write_config(pdn, PCI_COMMAND, 4, cmd);
  758. }
  759. /**
  760. * eeh_restore_bars - restore the PCI config space info
  761. *
  762. * This routine performs a recursive walk to the children
  763. * of this device as well.
  764. */
  765. void eeh_restore_bars(struct pci_dn *pdn)
  766. {
  767. struct device_node *dn;
  768. if (!pdn)
  769. return;
  770. if ((pdn->eeh_mode & EEH_MODE_SUPPORTED) && !IS_BRIDGE(pdn->class_code))
  771. __restore_bars (pdn);
  772. for_each_child_of_node(pdn->node, dn)
  773. eeh_restore_bars (PCI_DN(dn));
  774. }
  775. /**
  776. * eeh_save_bars - save device bars
  777. *
  778. * Save the values of the device bars. Unlike the restore
  779. * routine, this routine is *not* recursive. This is because
  780. * PCI devices are added individually; but, for the restore,
  781. * an entire slot is reset at a time.
  782. */
  783. static void eeh_save_bars(struct pci_dn *pdn)
  784. {
  785. int i;
  786. if (!pdn )
  787. return;
  788. for (i = 0; i < 16; i++)
  789. rtas_read_config(pdn, i * 4, 4, &pdn->config_space[i]);
  790. }
  791. void
  792. rtas_configure_bridge(struct pci_dn *pdn)
  793. {
  794. int config_addr;
  795. int rc;
  796. int token;
  797. /* Use PE configuration address, if present */
  798. config_addr = pdn->eeh_config_addr;
  799. if (pdn->eeh_pe_config_addr)
  800. config_addr = pdn->eeh_pe_config_addr;
  801. /* Use new configure-pe function, if supported */
  802. if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE)
  803. token = ibm_configure_pe;
  804. else
  805. token = ibm_configure_bridge;
  806. rc = rtas_call(token, 3, 1, NULL,
  807. config_addr,
  808. BUID_HI(pdn->phb->buid),
  809. BUID_LO(pdn->phb->buid));
  810. if (rc) {
  811. printk (KERN_WARNING "EEH: Unable to configure device bridge (%d) for %s\n",
  812. rc, pdn->node->full_name);
  813. }
  814. }
  815. /* ------------------------------------------------------------- */
  816. /* The code below deals with enabling EEH for devices during the
  817. * early boot sequence. EEH must be enabled before any PCI probing
  818. * can be done.
  819. */
  820. #define EEH_ENABLE 1
  821. struct eeh_early_enable_info {
  822. unsigned int buid_hi;
  823. unsigned int buid_lo;
  824. };
  825. static int get_pe_addr (int config_addr,
  826. struct eeh_early_enable_info *info)
  827. {
  828. unsigned int rets[3];
  829. int ret;
  830. /* Use latest config-addr token on power6 */
  831. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  832. /* Make sure we have a PE in hand */
  833. ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
  834. config_addr, info->buid_hi, info->buid_lo, 1);
  835. if (ret || (rets[0]==0))
  836. return 0;
  837. ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
  838. config_addr, info->buid_hi, info->buid_lo, 0);
  839. if (ret)
  840. return 0;
  841. return rets[0];
  842. }
  843. /* Use older config-addr token on power5 */
  844. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  845. ret = rtas_call (ibm_get_config_addr_info, 4, 2, rets,
  846. config_addr, info->buid_hi, info->buid_lo, 0);
  847. if (ret)
  848. return 0;
  849. return rets[0];
  850. }
  851. return 0;
  852. }
  853. /* Enable eeh for the given device node. */
  854. static void *early_enable_eeh(struct device_node *dn, void *data)
  855. {
  856. unsigned int rets[3];
  857. struct eeh_early_enable_info *info = data;
  858. int ret;
  859. const u32 *class_code = of_get_property(dn, "class-code", NULL);
  860. const u32 *vendor_id = of_get_property(dn, "vendor-id", NULL);
  861. const u32 *device_id = of_get_property(dn, "device-id", NULL);
  862. const u32 *regs;
  863. int enable;
  864. struct pci_dn *pdn = PCI_DN(dn);
  865. pdn->class_code = 0;
  866. pdn->eeh_mode = 0;
  867. pdn->eeh_check_count = 0;
  868. pdn->eeh_freeze_count = 0;
  869. pdn->eeh_false_positives = 0;
  870. if (!of_device_is_available(dn))
  871. return NULL;
  872. /* Ignore bad nodes. */
  873. if (!class_code || !vendor_id || !device_id)
  874. return NULL;
  875. /* There is nothing to check on PCI to ISA bridges */
  876. if (dn->type && !strcmp(dn->type, "isa")) {
  877. pdn->eeh_mode |= EEH_MODE_NOCHECK;
  878. return NULL;
  879. }
  880. pdn->class_code = *class_code;
  881. /* Ok... see if this device supports EEH. Some do, some don't,
  882. * and the only way to find out is to check each and every one. */
  883. regs = of_get_property(dn, "reg", NULL);
  884. if (regs) {
  885. /* First register entry is addr (00BBSS00) */
  886. /* Try to enable eeh */
  887. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  888. regs[0], info->buid_hi, info->buid_lo,
  889. EEH_ENABLE);
  890. enable = 0;
  891. if (ret == 0) {
  892. pdn->eeh_config_addr = regs[0];
  893. /* If the newer, better, ibm,get-config-addr-info is supported,
  894. * then use that instead. */
  895. pdn->eeh_pe_config_addr = get_pe_addr(pdn->eeh_config_addr, info);
  896. /* Some older systems (Power4) allow the
  897. * ibm,set-eeh-option call to succeed even on nodes
  898. * where EEH is not supported. Verify support
  899. * explicitly. */
  900. ret = read_slot_reset_state(pdn, rets);
  901. if ((ret == 0) && (rets[1] == 1))
  902. enable = 1;
  903. }
  904. if (enable) {
  905. eeh_subsystem_enabled = 1;
  906. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  907. pr_debug("EEH: %s: eeh enabled, config=%x pe_config=%x\n",
  908. dn->full_name, pdn->eeh_config_addr,
  909. pdn->eeh_pe_config_addr);
  910. } else {
  911. /* This device doesn't support EEH, but it may have an
  912. * EEH parent, in which case we mark it as supported. */
  913. if (dn->parent && PCI_DN(dn->parent)
  914. && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
  915. /* Parent supports EEH. */
  916. pdn->eeh_mode |= EEH_MODE_SUPPORTED;
  917. pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
  918. return NULL;
  919. }
  920. }
  921. } else {
  922. printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
  923. dn->full_name);
  924. }
  925. eeh_save_bars(pdn);
  926. return NULL;
  927. }
  928. /*
  929. * Initialize EEH by trying to enable it for all of the adapters in the system.
  930. * As a side effect we can determine here if eeh is supported at all.
  931. * Note that we leave EEH on so failed config cycles won't cause a machine
  932. * check. If a user turns off EEH for a particular adapter they are really
  933. * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
  934. * grant access to a slot if EEH isn't enabled, and so we always enable
  935. * EEH for all slots/all devices.
  936. *
  937. * The eeh-force-off option disables EEH checking globally, for all slots.
  938. * Even if force-off is set, the EEH hardware is still enabled, so that
  939. * newer systems can boot.
  940. */
  941. void __init eeh_init(void)
  942. {
  943. struct device_node *phb, *np;
  944. struct eeh_early_enable_info info;
  945. raw_spin_lock_init(&confirm_error_lock);
  946. spin_lock_init(&slot_errbuf_lock);
  947. np = of_find_node_by_path("/rtas");
  948. if (np == NULL)
  949. return;
  950. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  951. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  952. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  953. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  954. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  955. ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
  956. ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
  957. ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
  958. ibm_configure_pe = rtas_token("ibm,configure-pe");
  959. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
  960. return;
  961. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  962. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  963. eeh_error_buf_size = 1024;
  964. }
  965. if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  966. printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
  967. "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  968. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  969. }
  970. /* Enable EEH for all adapters. Note that eeh requires buid's */
  971. for (phb = of_find_node_by_name(NULL, "pci"); phb;
  972. phb = of_find_node_by_name(phb, "pci")) {
  973. unsigned long buid;
  974. buid = get_phb_buid(phb);
  975. if (buid == 0 || PCI_DN(phb) == NULL)
  976. continue;
  977. info.buid_lo = BUID_LO(buid);
  978. info.buid_hi = BUID_HI(buid);
  979. traverse_pci_devices(phb, early_enable_eeh, &info);
  980. }
  981. if (eeh_subsystem_enabled)
  982. printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
  983. else
  984. printk(KERN_WARNING "EEH: No capable adapters found\n");
  985. }
  986. /**
  987. * eeh_add_device_early - enable EEH for the indicated device_node
  988. * @dn: device node for which to set up EEH
  989. *
  990. * This routine must be used to perform EEH initialization for PCI
  991. * devices that were added after system boot (e.g. hotplug, dlpar).
  992. * This routine must be called before any i/o is performed to the
  993. * adapter (inluding any config-space i/o).
  994. * Whether this actually enables EEH or not for this device depends
  995. * on the CEC architecture, type of the device, on earlier boot
  996. * command-line arguments & etc.
  997. */
  998. static void eeh_add_device_early(struct device_node *dn)
  999. {
  1000. struct pci_controller *phb;
  1001. struct eeh_early_enable_info info;
  1002. if (!dn || !PCI_DN(dn))
  1003. return;
  1004. phb = PCI_DN(dn)->phb;
  1005. /* USB Bus children of PCI devices will not have BUID's */
  1006. if (NULL == phb || 0 == phb->buid)
  1007. return;
  1008. info.buid_hi = BUID_HI(phb->buid);
  1009. info.buid_lo = BUID_LO(phb->buid);
  1010. early_enable_eeh(dn, &info);
  1011. }
  1012. void eeh_add_device_tree_early(struct device_node *dn)
  1013. {
  1014. struct device_node *sib;
  1015. for_each_child_of_node(dn, sib)
  1016. eeh_add_device_tree_early(sib);
  1017. eeh_add_device_early(dn);
  1018. }
  1019. EXPORT_SYMBOL_GPL(eeh_add_device_tree_early);
  1020. /**
  1021. * eeh_add_device_late - perform EEH initialization for the indicated pci device
  1022. * @dev: pci device for which to set up EEH
  1023. *
  1024. * This routine must be used to complete EEH initialization for PCI
  1025. * devices that were added after system boot (e.g. hotplug, dlpar).
  1026. */
  1027. static void eeh_add_device_late(struct pci_dev *dev)
  1028. {
  1029. struct device_node *dn;
  1030. struct pci_dn *pdn;
  1031. if (!dev || !eeh_subsystem_enabled)
  1032. return;
  1033. pr_debug("EEH: Adding device %s\n", pci_name(dev));
  1034. dn = pci_device_to_OF_node(dev);
  1035. pdn = PCI_DN(dn);
  1036. if (pdn->pcidev == dev) {
  1037. pr_debug("EEH: Already referenced !\n");
  1038. return;
  1039. }
  1040. WARN_ON(pdn->pcidev);
  1041. pci_dev_get (dev);
  1042. pdn->pcidev = dev;
  1043. pci_addr_cache_insert_device(dev);
  1044. eeh_sysfs_add_device(dev);
  1045. }
  1046. void eeh_add_device_tree_late(struct pci_bus *bus)
  1047. {
  1048. struct pci_dev *dev;
  1049. list_for_each_entry(dev, &bus->devices, bus_list) {
  1050. eeh_add_device_late(dev);
  1051. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  1052. struct pci_bus *subbus = dev->subordinate;
  1053. if (subbus)
  1054. eeh_add_device_tree_late(subbus);
  1055. }
  1056. }
  1057. }
  1058. EXPORT_SYMBOL_GPL(eeh_add_device_tree_late);
  1059. /**
  1060. * eeh_remove_device - undo EEH setup for the indicated pci device
  1061. * @dev: pci device to be removed
  1062. *
  1063. * This routine should be called when a device is removed from
  1064. * a running system (e.g. by hotplug or dlpar). It unregisters
  1065. * the PCI device from the EEH subsystem. I/O errors affecting
  1066. * this device will no longer be detected after this call; thus,
  1067. * i/o errors affecting this slot may leave this device unusable.
  1068. */
  1069. static void eeh_remove_device(struct pci_dev *dev)
  1070. {
  1071. struct device_node *dn;
  1072. if (!dev || !eeh_subsystem_enabled)
  1073. return;
  1074. /* Unregister the device with the EEH/PCI address search system */
  1075. pr_debug("EEH: Removing device %s\n", pci_name(dev));
  1076. dn = pci_device_to_OF_node(dev);
  1077. if (PCI_DN(dn)->pcidev == NULL) {
  1078. pr_debug("EEH: Not referenced !\n");
  1079. return;
  1080. }
  1081. PCI_DN(dn)->pcidev = NULL;
  1082. pci_dev_put (dev);
  1083. pci_addr_cache_remove_device(dev);
  1084. eeh_sysfs_remove_device(dev);
  1085. }
  1086. void eeh_remove_bus_device(struct pci_dev *dev)
  1087. {
  1088. struct pci_bus *bus = dev->subordinate;
  1089. struct pci_dev *child, *tmp;
  1090. eeh_remove_device(dev);
  1091. if (bus && dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  1092. list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
  1093. eeh_remove_bus_device(child);
  1094. }
  1095. }
  1096. EXPORT_SYMBOL_GPL(eeh_remove_bus_device);
  1097. static int proc_eeh_show(struct seq_file *m, void *v)
  1098. {
  1099. if (0 == eeh_subsystem_enabled) {
  1100. seq_printf(m, "EEH Subsystem is globally disabled\n");
  1101. seq_printf(m, "eeh_total_mmio_ffs=%ld\n", total_mmio_ffs);
  1102. } else {
  1103. seq_printf(m, "EEH Subsystem is enabled\n");
  1104. seq_printf(m,
  1105. "no device=%ld\n"
  1106. "no device node=%ld\n"
  1107. "no config address=%ld\n"
  1108. "check not wanted=%ld\n"
  1109. "eeh_total_mmio_ffs=%ld\n"
  1110. "eeh_false_positives=%ld\n"
  1111. "eeh_slot_resets=%ld\n",
  1112. no_device, no_dn, no_cfg_addr,
  1113. ignored_check, total_mmio_ffs,
  1114. false_positives,
  1115. slot_resets);
  1116. }
  1117. return 0;
  1118. }
  1119. static int proc_eeh_open(struct inode *inode, struct file *file)
  1120. {
  1121. return single_open(file, proc_eeh_show, NULL);
  1122. }
  1123. static const struct file_operations proc_eeh_operations = {
  1124. .open = proc_eeh_open,
  1125. .read = seq_read,
  1126. .llseek = seq_lseek,
  1127. .release = single_release,
  1128. };
  1129. static int __init eeh_init_proc(void)
  1130. {
  1131. if (machine_is(pseries))
  1132. proc_create("ppc64/eeh", 0, NULL, &proc_eeh_operations);
  1133. return 0;
  1134. }
  1135. __initcall(eeh_init_proc);