eeh.c 37 KB

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