eeh.c 37 KB

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