eeh.c 36 KB

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