eeh.c 36 KB

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