blob: 2293730538645805420f5348eac757d82c6d443b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * eeh.c
Linas Vepstas3c8c90a2007-05-24 03:28:01 +10003 * Copyright IBM Corporation 2001, 2005, 2006
4 * Copyright Dave Engebretsen & Todd Inglett 2001
5 * Copyright Linas Vepstas 2005, 2006
Linas Vepstas69376502005-11-03 18:47:50 -06006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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.
Linas Vepstas69376502005-11-03 18:47:50 -060011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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.
Linas Vepstas69376502005-11-03 18:47:50 -060016 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * 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
Linas Vepstas3c8c90a2007-05-24 03:28:01 +100020 *
21 * Please address comments and feedback to Linas Vepstas <linas@austin.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23
Linas Vepstas6dee3fb2005-11-03 18:50:10 -060024#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/init.h>
26#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#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>
Stephen Rothwellacaa6172007-12-21 15:52:07 +110032#include <linux/of.h>
33
Linas Vepstas69376502005-11-03 18:47:50 -060034#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/eeh.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060036#include <asm/eeh_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/io.h>
38#include <asm/machdep.h>
Stephen Rothwelld3878992005-09-28 02:50:25 +100039#include <asm/ppc-pci.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060040#include <asm/rtas.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/** Overview:
44 * EEH, or "Extended Error Handling" is a PCI bridge technology for
45 * dealing with PCI bus errors that can't be dealt with within the
46 * usual PCI framework, except by check-stopping the CPU. Systems
47 * that are designed for high-availability/reliability cannot afford
48 * to crash due to a "mere" PCI error, thus the need for EEH.
49 * An EEH-capable bridge operates by converting a detected error
50 * into a "slot freeze", taking the PCI adapter off-line, making
51 * the slot behave, from the OS'es point of view, as if the slot
52 * were "empty": all reads return 0xff's and all writes are silently
53 * ignored. EEH slot isolation events can be triggered by parity
54 * errors on the address or data busses (e.g. during posted writes),
Linas Vepstas69376502005-11-03 18:47:50 -060055 * which in turn might be caused by low voltage on the bus, dust,
56 * vibration, humidity, radioactivity or plain-old failed hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * Note, however, that one of the leading causes of EEH slot
59 * freeze events are buggy device drivers, buggy device microcode,
60 * or buggy device hardware. This is because any attempt by the
61 * device to bus-master data to a memory address that is not
62 * assigned to the device will trigger a slot freeze. (The idea
63 * is to prevent devices-gone-wild from corrupting system memory).
64 * Buggy hardware/drivers will have a miserable time co-existing
65 * with EEH.
66 *
67 * Ideally, a PCI device driver, when suspecting that an isolation
Lucas De Marchi25985ed2011-03-30 22:57:33 -030068 * event has occurred (e.g. by reading 0xff's), will then ask EEH
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * whether this is the case, and then take appropriate steps to
70 * reset the PCI slot, the PCI device, and then resume operations.
71 * However, until that day, the checking is done here, with the
72 * eeh_check_failure() routine embedded in the MMIO macros. If
73 * the slot is found to be isolated, an "EEH Event" is synthesized
74 * and sent out for processing.
75 */
76
Linas Vepstas5c1344e2005-11-03 18:49:31 -060077/* If a device driver keeps reading an MMIO register in an interrupt
Mike Masonf36c5222008-07-22 02:40:17 +100078 * handler after a slot isolation event, it might be broken.
79 * This sets the threshold for how many read attempts we allow
80 * before printing an error message.
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 */
Linas Vepstas2fd30be2007-03-19 14:53:22 -050082#define EEH_MAX_FAILS 2100000
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linas Vepstas17213c32007-05-10 02:38:11 +100084/* Time to wait for a PCI slot to report status, in milliseconds */
Linas Vepstas9c547762007-03-19 14:58:07 -050085#define PCI_BUS_RESET_WAIT_MSEC (60*1000)
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/* RTAS tokens */
88static int ibm_set_eeh_option;
89static int ibm_set_slot_reset;
90static int ibm_read_slot_reset_state;
91static int ibm_read_slot_reset_state2;
92static int ibm_slot_error_detail;
Linas Vepstas25e591f2005-11-03 18:53:20 -060093static int ibm_get_config_addr_info;
Linas Vepstas147d6a32007-03-19 14:54:21 -050094static int ibm_get_config_addr_info2;
Linas Vepstas21e464d2005-11-03 18:54:47 -060095static int ibm_configure_bridge;
Richard A. Lary65f47f12011-04-06 12:50:45 +000096static int ibm_configure_pe;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
David Woodhouse1e28a7d2005-11-17 00:44:03 +000098int eeh_subsystem_enabled;
99EXPORT_SYMBOL(eeh_subsystem_enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600101/* Lock to avoid races due to multiple reports of an error */
Thomas Gleixner3d372622010-02-18 02:23:07 +0000102static DEFINE_RAW_SPINLOCK(confirm_error_lock);
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600103
Linas Vepstas17213c32007-05-10 02:38:11 +1000104/* Buffer for reporting slot-error-detail rtas calls. Its here
105 * in BSS, and not dynamically alloced, so that it ends up in
106 * RMO where RTAS can access it.
107 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
109static DEFINE_SPINLOCK(slot_errbuf_lock);
110static int eeh_error_buf_size;
111
Linas Vepstas17213c32007-05-10 02:38:11 +1000112/* Buffer for reporting pci register dumps. Its here in BSS, and
113 * not dynamically alloced, so that it ends up in RMO where RTAS
114 * can access it.
115 */
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000116#define EEH_PCI_REGS_LOG_LEN 4096
117static unsigned char pci_regs_buf[EEH_PCI_REGS_LOG_LEN];
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/* System monitoring statistics */
Linas Vepstas257ffc62005-11-03 18:55:25 -0600120static unsigned long no_device;
121static unsigned long no_dn;
122static unsigned long no_cfg_addr;
123static unsigned long ignored_check;
124static unsigned long total_mmio_ffs;
125static unsigned long false_positives;
Linas Vepstas257ffc62005-11-03 18:55:25 -0600126static unsigned long slot_resets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linas Vepstas7684b402005-11-03 18:55:19 -0600128#define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* --------------------------------------------------------------- */
Linas Vepstas5d5a0932005-11-03 18:53:07 -0600131/* Below lies the EEH event infrastructure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000133static void rtas_slot_error_detail(struct pci_dn *pdn, int severity,
134 char *driver_log, size_t loglen)
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600135{
Linas Vepstasfcb75432005-11-03 18:54:39 -0600136 int config_addr;
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600137 unsigned long flags;
138 int rc;
139
140 /* Log the error with the rtas logger */
141 spin_lock_irqsave(&slot_errbuf_lock, flags);
142 memset(slot_errbuf, 0, eeh_error_buf_size);
143
Linas Vepstasfcb75432005-11-03 18:54:39 -0600144 /* Use PE configuration address, if present */
145 config_addr = pdn->eeh_config_addr;
146 if (pdn->eeh_pe_config_addr)
147 config_addr = pdn->eeh_pe_config_addr;
148
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600149 rc = rtas_call(ibm_slot_error_detail,
Linas Vepstasfcb75432005-11-03 18:54:39 -0600150 8, 1, NULL, config_addr,
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600151 BUID_HI(pdn->phb->buid),
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000152 BUID_LO(pdn->phb->buid),
153 virt_to_phys(driver_log), loglen,
Linas Vepstasdf7242b2005-11-03 18:49:01 -0600154 virt_to_phys(slot_errbuf),
155 eeh_error_buf_size,
156 severity);
157
158 if (rc == 0)
159 log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
160 spin_unlock_irqrestore(&slot_errbuf_lock, flags);
161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/**
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000164 * gather_pci_data - copy assorted PCI config space registers to buff
165 * @pdn: device to report data for
166 * @buf: point to buffer in which to log
167 * @len: amount of room in buffer
168 *
169 * This routine captures assorted PCI configuration space data,
170 * and puts them into a buffer for RTAS error logging.
171 */
172static size_t gather_pci_data(struct pci_dn *pdn, char * buf, size_t len)
173{
Linas Vepstas0b9369f2007-07-27 08:35:40 +1000174 struct pci_dev *dev = pdn->pcidev;
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000175 u32 cfg;
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000176 int cap, i;
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000177 int n = 0;
178
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000179 n += scnprintf(buf+n, len-n, "%s\n", pdn->node->full_name);
180 printk(KERN_WARNING "EEH: of node=%s\n", pdn->node->full_name);
181
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000182 rtas_read_config(pdn, PCI_VENDOR_ID, 4, &cfg);
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000183 n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
184 printk(KERN_WARNING "EEH: PCI device/vendor: %08x\n", cfg);
185
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000186 rtas_read_config(pdn, PCI_COMMAND, 4, &cfg);
187 n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg);
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000188 printk(KERN_WARNING "EEH: PCI cmd/status register: %08x\n", cfg);
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000189
Linas Vepstasb37ceef2007-11-03 07:29:01 +1100190 if (!dev) {
191 printk(KERN_WARNING "EEH: no PCI device for this of node\n");
192 return n;
193 }
194
Linas Vepstas0b9369f2007-07-27 08:35:40 +1000195 /* Gather bridge-specific registers */
196 if (dev->class >> 16 == PCI_BASE_CLASS_BRIDGE) {
197 rtas_read_config(pdn, PCI_SEC_STATUS, 2, &cfg);
198 n += scnprintf(buf+n, len-n, "sec stat:%x\n", cfg);
199 printk(KERN_WARNING "EEH: Bridge secondary status: %04x\n", cfg);
200
201 rtas_read_config(pdn, PCI_BRIDGE_CONTROL, 2, &cfg);
202 n += scnprintf(buf+n, len-n, "brdg ctl:%x\n", cfg);
203 printk(KERN_WARNING "EEH: Bridge control: %04x\n", cfg);
204 }
205
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000206 /* Dump out the PCI-X command and status regs */
Linas Vepstasb37ceef2007-11-03 07:29:01 +1100207 cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000208 if (cap) {
209 rtas_read_config(pdn, cap, 4, &cfg);
210 n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg);
211 printk(KERN_WARNING "EEH: PCI-X cmd: %08x\n", cfg);
212
213 rtas_read_config(pdn, cap+4, 4, &cfg);
214 n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg);
215 printk(KERN_WARNING "EEH: PCI-X status: %08x\n", cfg);
216 }
217
218 /* If PCI-E capable, dump PCI-E cap 10, and the AER */
Linas Vepstasb37ceef2007-11-03 07:29:01 +1100219 cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000220 if (cap) {
221 n += scnprintf(buf+n, len-n, "pci-e cap10:\n");
222 printk(KERN_WARNING
223 "EEH: PCI-E capabilities and status follow:\n");
224
225 for (i=0; i<=8; i++) {
226 rtas_read_config(pdn, cap+4*i, 4, &cfg);
227 n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
228 printk(KERN_WARNING "EEH: PCI-E %02x: %08x\n", i, cfg);
229 }
230
Linas Vepstasb37ceef2007-11-03 07:29:01 +1100231 cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
Linas Vepstasfcf9892b2007-05-09 09:36:21 +1000232 if (cap) {
233 n += scnprintf(buf+n, len-n, "pci-e AER:\n");
234 printk(KERN_WARNING
235 "EEH: PCI-E AER capability register set follows:\n");
236
237 for (i=0; i<14; i++) {
238 rtas_read_config(pdn, cap+4*i, 4, &cfg);
239 n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
240 printk(KERN_WARNING "EEH: PCI-E AER %02x: %08x\n", i, cfg);
241 }
242 }
243 }
Linas Vepstas0b9369f2007-07-27 08:35:40 +1000244
245 /* Gather status on devices under the bridge */
246 if (dev->class >> 16 == PCI_BASE_CLASS_BRIDGE) {
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100247 struct device_node *dn;
248
249 for_each_child_of_node(pdn->node, dn) {
Linas Vepstas0b9369f2007-07-27 08:35:40 +1000250 pdn = PCI_DN(dn);
251 if (pdn)
252 n += gather_pci_data(pdn, buf+n, len-n);
Linas Vepstas0b9369f2007-07-27 08:35:40 +1000253 }
254 }
255
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000256 return n;
257}
258
259void eeh_slot_error_detail(struct pci_dn *pdn, int severity)
260{
261 size_t loglen = 0;
Linas Vepstas17213c32007-05-10 02:38:11 +1000262 pci_regs_buf[0] = 0;
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000263
264 rtas_pci_enable(pdn, EEH_THAW_MMIO);
Richard A. Lary65f47f12011-04-06 12:50:45 +0000265 rtas_configure_bridge(pdn);
266 eeh_restore_bars(pdn);
Linas Vepstasd99bb1d2007-05-09 09:35:32 +1000267 loglen = gather_pci_data(pdn, pci_regs_buf, EEH_PCI_REGS_LOG_LEN);
268
269 rtas_slot_error_detail(pdn, severity, pci_regs_buf, loglen);
270}
271
272/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 * read_slot_reset_state - Read the reset state of a device node's slot
274 * @dn: device node to read
275 * @rets: array to return results in
276 */
Linas Vepstas69376502005-11-03 18:47:50 -0600277static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 int token, outputs;
Linas Vepstasfcb75432005-11-03 18:54:39 -0600280 int config_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
283 token = ibm_read_slot_reset_state2;
284 outputs = 4;
285 } else {
286 token = ibm_read_slot_reset_state;
Linas Vepstas69376502005-11-03 18:47:50 -0600287 rets[2] = 0; /* fake PE Unavailable info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 outputs = 3;
289 }
290
Linas Vepstasfcb75432005-11-03 18:54:39 -0600291 /* Use PE configuration address, if present */
292 config_addr = pdn->eeh_config_addr;
293 if (pdn->eeh_pe_config_addr)
294 config_addr = pdn->eeh_pe_config_addr;
295
296 return rtas_call(token, 3, outputs, rets, config_addr,
Paul Mackerras16353172005-09-06 13:17:54 +1000297 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300/**
Linas Vepstas9c547762007-03-19 14:58:07 -0500301 * eeh_wait_for_slot_status - returns error status of slot
302 * @pdn pci device node
303 * @max_wait_msecs maximum number to millisecs to wait
304 *
305 * Return negative value if a permanent error, else return
306 * Partition Endpoint (PE) status value.
307 *
308 * If @max_wait_msecs is positive, then this routine will
309 * sleep until a valid status can be obtained, or until
310 * the max allowed wait time is exceeded, in which case
311 * a -2 is returned.
312 */
313int
314eeh_wait_for_slot_status(struct pci_dn *pdn, int max_wait_msecs)
315{
316 int rc;
317 int rets[3];
318 int mwait;
319
320 while (1) {
321 rc = read_slot_reset_state(pdn, rets);
322 if (rc) return rc;
323 if (rets[1] == 0) return -1; /* EEH is not supported */
324
325 if (rets[0] != 5) return rets[0]; /* return actual status */
326
327 if (rets[2] == 0) return -1; /* permanently unavailable */
328
Linas Vepstas2c84b402007-11-08 07:03:53 +1100329 if (max_wait_msecs <= 0) break;
Linas Vepstas9c547762007-03-19 14:58:07 -0500330
331 mwait = rets[2];
332 if (mwait <= 0) {
333 printk (KERN_WARNING
334 "EEH: Firmware returned bad wait value=%d\n", mwait);
335 mwait = 1000;
336 } else if (mwait > 300*1000) {
337 printk (KERN_WARNING
338 "EEH: Firmware is taking too long, time=%d\n", mwait);
339 mwait = 300*1000;
340 }
341 max_wait_msecs -= mwait;
342 msleep (mwait);
343 }
344
345 printk(KERN_WARNING "EEH: Timed out waiting for slot status\n");
346 return -2;
347}
348
349/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * eeh_token_to_phys - convert EEH address token to phys address
Linas Vepstas69376502005-11-03 18:47:50 -0600351 * @token i/o token, should be address in the form 0xA....
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 */
353static inline unsigned long eeh_token_to_phys(unsigned long token)
354{
355 pte_t *ptep;
356 unsigned long pa;
357
David Gibson20cee162005-06-21 17:15:31 -0700358 ptep = find_linux_pte(init_mm.pgd, token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (!ptep)
360 return token;
361 pa = pte_pfn(*ptep) << PAGE_SHIFT;
362
363 return pa | (token & (PAGE_SIZE-1));
364}
365
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600366/**
367 * Return the "partitionable endpoint" (pe) under which this device lies
368 */
Linas Vepstas9fb40eb2005-11-03 18:54:29 -0600369struct device_node * find_device_pe(struct device_node *dn)
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600370{
371 while ((dn->parent) && PCI_DN(dn->parent) &&
372 (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
373 dn = dn->parent;
374 }
375 return dn;
376}
377
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100378/** Mark all devices that are children of this device as failed.
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600379 * Mark the device driver too, so that it can see the failure
380 * immediately; this is critical, since some drivers poll
381 * status registers in interrupts ... If a driver is polling,
382 * and the slot is frozen, then the driver can deadlock in
383 * an interrupt context, which is bad.
384 */
385
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100386static void __eeh_mark_slot(struct device_node *parent, int mode_flag)
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600387{
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100388 struct device_node *dn;
389
390 for_each_child_of_node(parent, dn) {
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600391 if (PCI_DN(dn)) {
Linas Vepstas77bd7412005-11-03 18:52:49 -0600392 /* Mark the pci device driver too */
393 struct pci_dev *dev = PCI_DN(dn)->pcidev;
Olof Johanssonea183a92006-01-11 14:02:58 -0600394
395 PCI_DN(dn)->eeh_mode |= mode_flag;
396
Linas Vepstas77bd7412005-11-03 18:52:49 -0600397 if (dev && dev->driver)
398 dev->error_state = pci_channel_io_frozen;
399
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100400 __eeh_mark_slot(dn, mode_flag);
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600401 }
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600402 }
403}
404
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600405void eeh_mark_slot (struct device_node *dn, int mode_flag)
406{
Linas Vepstas022d51b2006-09-25 18:01:42 -0500407 struct pci_dev *dev;
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600408 dn = find_device_pe (dn);
Linas Vepstas3914ac72005-11-03 18:55:01 -0600409
410 /* Back up one, since config addrs might be shared */
Linas Vepstas4980d5e2007-03-19 15:01:31 -0500411 if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
Linas Vepstas3914ac72005-11-03 18:55:01 -0600412 dn = dn->parent;
413
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600414 PCI_DN(dn)->eeh_mode |= mode_flag;
Linas Vepstas022d51b2006-09-25 18:01:42 -0500415
416 /* Mark the pci device too */
417 dev = PCI_DN(dn)->pcidev;
418 if (dev)
419 dev->error_state = pci_channel_io_frozen;
420
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100421 __eeh_mark_slot(dn, mode_flag);
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600422}
423
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100424static void __eeh_clear_slot(struct device_node *parent, int mode_flag)
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600425{
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100426 struct device_node *dn;
427
428 for_each_child_of_node(parent, dn) {
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600429 if (PCI_DN(dn)) {
430 PCI_DN(dn)->eeh_mode &= ~mode_flag;
431 PCI_DN(dn)->eeh_check_count = 0;
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100432 __eeh_clear_slot(dn, mode_flag);
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600433 }
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600434 }
435}
436
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600437void eeh_clear_slot (struct device_node *dn, int mode_flag)
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600438{
439 unsigned long flags;
Thomas Gleixner3d372622010-02-18 02:23:07 +0000440 raw_spin_lock_irqsave(&confirm_error_lock, flags);
Linas Vepstas3914ac72005-11-03 18:55:01 -0600441
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600442 dn = find_device_pe (dn);
Linas Vepstas3914ac72005-11-03 18:55:01 -0600443
444 /* Back up one, since config addrs might be shared */
Linas Vepstas4980d5e2007-03-19 15:01:31 -0500445 if (!pcibios_find_pci_bus(dn) && PCI_DN(dn->parent))
Linas Vepstas3914ac72005-11-03 18:55:01 -0600446 dn = dn->parent;
447
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600448 PCI_DN(dn)->eeh_mode &= ~mode_flag;
449 PCI_DN(dn)->eeh_check_count = 0;
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100450 __eeh_clear_slot(dn, mode_flag);
Thomas Gleixner3d372622010-02-18 02:23:07 +0000451 raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600452}
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454/**
455 * eeh_dn_check_failure - check if all 1's data is due to EEH slot freeze
456 * @dn device node
457 * @dev pci device, if known
458 *
459 * Check for an EEH failure for the given device node. Call this
460 * routine if the result of a read was all 0xff's and you want to
461 * find out if this is due to an EEH slot freeze. This routine
462 * will query firmware for the EEH status.
463 *
464 * Returns 0 if there has not been an EEH error; otherwise returns
Linas Vepstas69376502005-11-03 18:47:50 -0600465 * a non-zero value and queues up a slot isolation event notification.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 *
467 * It is safe to call this routine in an interrupt context.
468 */
469int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
470{
471 int ret;
472 int rets[3];
473 unsigned long flags;
Paul Mackerras16353172005-09-06 13:17:54 +1000474 struct pci_dn *pdn;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600475 int rc = 0;
Mike Masonf36c5222008-07-22 02:40:17 +1000476 const char *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Linas Vepstas257ffc62005-11-03 18:55:25 -0600478 total_mmio_ffs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 if (!eeh_subsystem_enabled)
481 return 0;
482
Linas Vepstas177bc932005-11-03 18:48:52 -0600483 if (!dn) {
Linas Vepstas257ffc62005-11-03 18:55:25 -0600484 no_dn++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 return 0;
Linas Vepstas177bc932005-11-03 18:48:52 -0600486 }
Linas Vepstas307d46e2007-11-16 05:56:23 +1100487 dn = find_device_pe(dn);
Linas Vepstas69376502005-11-03 18:47:50 -0600488 pdn = PCI_DN(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 /* Access to IO BARs might get this far and still not want checking. */
Linas Vepstasf8632c82005-11-03 18:49:45 -0600491 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
Paul Mackerras16353172005-09-06 13:17:54 +1000492 pdn->eeh_mode & EEH_MODE_NOCHECK) {
Linas Vepstas257ffc62005-11-03 18:55:25 -0600493 ignored_check++;
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +0000494 pr_debug("EEH: Ignored check (%x) for %s %s\n",
Breno Leitao8d3d50b2010-02-03 05:56:41 +0000495 pdn->eeh_mode, eeh_pci_name(dev), dn->full_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return 0;
497 }
498
Linas Vepstasfcb75432005-11-03 18:54:39 -0600499 if (!pdn->eeh_config_addr && !pdn->eeh_pe_config_addr) {
Linas Vepstas257ffc62005-11-03 18:55:25 -0600500 no_cfg_addr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return 0;
502 }
503
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600504 /* If we already have a pending isolation event for this
505 * slot, we know it's bad already, we don't need to check.
506 * Do this checking under a lock; as multiple PCI devices
507 * in one slot might report errors simultaneously, and we
508 * only want one error recovery routine running.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 */
Thomas Gleixner3d372622010-02-18 02:23:07 +0000510 raw_spin_lock_irqsave(&confirm_error_lock, flags);
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600511 rc = 1;
Paul Mackerras16353172005-09-06 13:17:54 +1000512 if (pdn->eeh_mode & EEH_MODE_ISOLATED) {
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600513 pdn->eeh_check_count ++;
Mike Masonf36c5222008-07-22 02:40:17 +1000514 if (pdn->eeh_check_count % EEH_MAX_FAILS == 0) {
515 location = of_get_property(dn, "ibm,loc-code", NULL);
516 printk (KERN_ERR "EEH: %d reads ignored for recovering device at "
517 "location=%s driver=%s pci addr=%s\n",
518 pdn->eeh_check_count, location,
Breno Leitao8d3d50b2010-02-03 05:56:41 +0000519 dev->driver->name, eeh_pci_name(dev));
Mike Masonf36c5222008-07-22 02:40:17 +1000520 printk (KERN_ERR "EEH: Might be infinite loop in %s driver\n",
521 dev->driver->name);
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600522 dump_stack();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600524 goto dn_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
526
527 /*
528 * Now test for an EEH failure. This is VERY expensive.
529 * Note that the eeh_config_addr may be a parent device
530 * in the case of a device behind a bridge, or it may be
531 * function zero of a multi-function device.
532 * In any case they must share a common PHB.
533 */
Linas Vepstas69376502005-11-03 18:47:50 -0600534 ret = read_slot_reset_state(pdn, rets);
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600535
536 /* If the call to firmware failed, punt */
537 if (ret != 0) {
538 printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
539 ret, dn->full_name);
Linas Vepstas257ffc62005-11-03 18:55:25 -0600540 false_positives++;
Linas Vepstas858955b2007-05-24 03:20:51 +1000541 pdn->eeh_false_positives ++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600542 rc = 0;
543 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600544 }
545
Linas Vepstas39d16e22007-03-19 14:51:00 -0500546 /* Note that config-io to empty slots may fail;
547 * they are empty when they don't have children. */
Linas Vepstasc9b65a72007-11-16 05:57:27 +1100548 if ((rets[0] == 5) && (rets[2] == 0) && (dn->child == NULL)) {
Linas Vepstas39d16e22007-03-19 14:51:00 -0500549 false_positives++;
Linas Vepstas858955b2007-05-24 03:20:51 +1000550 pdn->eeh_false_positives ++;
Linas Vepstas39d16e22007-03-19 14:51:00 -0500551 rc = 0;
552 goto dn_unlock;
553 }
554
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600555 /* If EEH is not supported on this device, punt. */
556 if (rets[1] != 1) {
557 printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
558 ret, dn->full_name);
Linas Vepstas257ffc62005-11-03 18:55:25 -0600559 false_positives++;
Linas Vepstas858955b2007-05-24 03:20:51 +1000560 pdn->eeh_false_positives ++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600561 rc = 0;
562 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600563 }
564
565 /* If not the kind of error we know about, punt. */
Linas Vepstas90375f52007-03-19 14:56:43 -0500566 if (rets[0] != 1 && rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
Linas Vepstas257ffc62005-11-03 18:55:25 -0600567 false_positives++;
Linas Vepstas858955b2007-05-24 03:20:51 +1000568 pdn->eeh_false_positives ++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600569 rc = 0;
570 goto dn_unlock;
Linas Vepstas76e6faf2005-11-03 18:49:15 -0600571 }
572
Linas Vepstas257ffc62005-11-03 18:55:25 -0600573 slot_resets++;
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600574
575 /* Avoid repeated reports of this failure, including problems
576 * with other functions on this device, and functions under
577 * bridges. */
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600578 eeh_mark_slot (dn, EEH_MODE_ISOLATED);
Thomas Gleixner3d372622010-02-18 02:23:07 +0000579 raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Linas Vepstasd0ab95c2007-03-19 14:59:10 -0500581 eeh_send_failure_event (dn, dev);
Linas Vepstas77bd7412005-11-03 18:52:49 -0600582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 /* Most EEH events are due to device driver bugs. Having
584 * a stack trace will help the device-driver authors figure
585 * out what happened. So print that out. */
Linas Vepstas90375f52007-03-19 14:56:43 -0500586 dump_stack();
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600587 return 1;
588
589dn_unlock:
Thomas Gleixner3d372622010-02-18 02:23:07 +0000590 raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600591 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
593
Linas Vepstasfd761fd2005-11-03 18:49:23 -0600594EXPORT_SYMBOL_GPL(eeh_dn_check_failure);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596/**
597 * eeh_check_failure - check if all 1's data is due to EEH slot freeze
598 * @token i/o token, should be address in the form 0xA....
599 * @val value, should be all 1's (XXX why do we need this arg??)
600 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 * Check for an EEH failure at the given token address. Call this
602 * routine if the result of a read was all 0xff's and you want to
603 * find out if this is due to an EEH slot freeze event. This routine
604 * will query firmware for the EEH status.
605 *
606 * Note this routine is safe to call in an interrupt context.
607 */
608unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
609{
610 unsigned long addr;
611 struct pci_dev *dev;
612 struct device_node *dn;
613
614 /* Finding the phys addr + pci device; this is pretty quick. */
615 addr = eeh_token_to_phys((unsigned long __force) token);
616 dev = pci_get_device_by_addr(addr);
Linas Vepstas177bc932005-11-03 18:48:52 -0600617 if (!dev) {
Linas Vepstas257ffc62005-11-03 18:55:25 -0600618 no_device++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 return val;
Linas Vepstas177bc932005-11-03 18:48:52 -0600620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 dn = pci_device_to_OF_node(dev);
623 eeh_dn_check_failure (dn, dev);
624
625 pci_dev_put(dev);
626 return val;
627}
628
629EXPORT_SYMBOL(eeh_check_failure);
630
Linas Vepstas172ca922005-11-03 18:50:04 -0600631/* ------------------------------------------------------------- */
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600632/* The code below deals with error recovery */
633
Linas Vepstascb5b56242006-09-15 18:56:35 -0500634/**
Linas Vepstas47b5c832006-09-15 18:57:42 -0500635 * rtas_pci_enable - enable MMIO or DMA transfers for this slot
636 * @pdn pci device node
637 */
638
639int
640rtas_pci_enable(struct pci_dn *pdn, int function)
641{
642 int config_addr;
643 int rc;
644
645 /* Use PE configuration address, if present */
646 config_addr = pdn->eeh_config_addr;
647 if (pdn->eeh_pe_config_addr)
648 config_addr = pdn->eeh_pe_config_addr;
649
650 rc = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
651 config_addr,
652 BUID_HI(pdn->phb->buid),
653 BUID_LO(pdn->phb->buid),
654 function);
655
656 if (rc)
Linas Vepstasfa1be472007-03-19 14:59:59 -0500657 printk(KERN_WARNING "EEH: Unexpected state change %d, err=%d dn=%s\n",
Linas Vepstas47b5c832006-09-15 18:57:42 -0500658 function, rc, pdn->node->full_name);
659
Linas Vepstasfa1be472007-03-19 14:59:59 -0500660 rc = eeh_wait_for_slot_status (pdn, PCI_BUS_RESET_WAIT_MSEC);
661 if ((rc == 4) && (function == EEH_THAW_MMIO))
662 return 0;
663
Linas Vepstas47b5c832006-09-15 18:57:42 -0500664 return rc;
665}
666
667/**
Linas Vepstascb5b56242006-09-15 18:56:35 -0500668 * rtas_pci_slot_reset - raises/lowers the pci #RST line
669 * @pdn pci device node
670 * @state: 1/0 to raise/lower the #RST
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600671 *
672 * Clear the EEH-frozen condition on a slot. This routine
673 * asserts the PCI #RST line if the 'state' argument is '1',
674 * and drops the #RST line if 'state is '0'. This routine is
675 * safe to call in an interrupt context.
676 *
677 */
678
679static void
680rtas_pci_slot_reset(struct pci_dn *pdn, int state)
681{
Linas Vepstas25e591f2005-11-03 18:53:20 -0600682 int config_addr;
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600683 int rc;
684
685 BUG_ON (pdn==NULL);
686
687 if (!pdn->phb) {
688 printk (KERN_WARNING "EEH: in slot reset, device node %s has no phb\n",
689 pdn->node->full_name);
690 return;
691 }
692
Linas Vepstas25e591f2005-11-03 18:53:20 -0600693 /* Use PE configuration address, if present */
694 config_addr = pdn->eeh_config_addr;
695 if (pdn->eeh_pe_config_addr)
696 config_addr = pdn->eeh_pe_config_addr;
697
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600698 rc = rtas_call(ibm_set_slot_reset,4,1, NULL,
Linas Vepstas25e591f2005-11-03 18:53:20 -0600699 config_addr,
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600700 BUID_HI(pdn->phb->buid),
701 BUID_LO(pdn->phb->buid),
702 state);
Linas Vepstase1029262006-09-21 18:25:56 -0500703 if (rc)
704 printk (KERN_WARNING "EEH: Unable to reset the failed slot,"
705 " (%d) #RST=%d dn=%s\n",
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600706 rc, state, pdn->node->full_name);
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600707}
708
Linas Vepstascb5b56242006-09-15 18:56:35 -0500709/**
Brian King00c2ae32007-05-08 08:04:05 +1000710 * pcibios_set_pcie_slot_reset - Set PCI-E reset state
711 * @dev: pci device struct
712 * @state: reset state to enter
713 *
714 * Return value:
715 * 0 if success
716 **/
717int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
718{
719 struct device_node *dn = pci_device_to_OF_node(dev);
720 struct pci_dn *pdn = PCI_DN(dn);
721
722 switch (state) {
723 case pcie_deassert_reset:
724 rtas_pci_slot_reset(pdn, 0);
725 break;
726 case pcie_hot_reset:
727 rtas_pci_slot_reset(pdn, 1);
728 break;
729 case pcie_warm_reset:
730 rtas_pci_slot_reset(pdn, 3);
731 break;
732 default:
733 return -EINVAL;
734 };
735
736 return 0;
737}
738
739/**
Linas Vepstascb5b56242006-09-15 18:56:35 -0500740 * rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
741 * @pdn: pci device node to be reset.
Linas Vepstasb6495c02005-11-03 18:54:54 -0600742 *
743 * Return 0 if success, else a non-zero value.
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600744 */
745
Linas Vepstase1029262006-09-21 18:25:56 -0500746static void __rtas_set_slot_reset(struct pci_dn *pdn)
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600747{
Mike Mason6e193142009-07-30 15:42:39 -0700748 struct pci_dev *dev = pdn->pcidev;
749
750 /* Determine type of EEH reset required by device,
751 * default hot reset or fundamental reset
752 */
Anton Blanchardce47c1c2010-05-10 15:38:56 +0000753 if (dev && dev->needs_freset)
Mike Mason6e193142009-07-30 15:42:39 -0700754 rtas_pci_slot_reset(pdn, 3);
755 else
756 rtas_pci_slot_reset(pdn, 1);
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600757
758 /* The PCI bus requires that the reset be held high for at least
759 * a 100 milliseconds. We wait a bit longer 'just in case'. */
760
761#define PCI_BUS_RST_HOLD_TIME_MSEC 250
762 msleep (PCI_BUS_RST_HOLD_TIME_MSEC);
Linas Vepstasd9564ad2005-11-03 18:50:48 -0600763
764 /* We might get hit with another EEH freeze as soon as the
765 * pci slot reset line is dropped. Make sure we don't miss
766 * these, and clear the flag now. */
767 eeh_clear_slot (pdn->node, EEH_MODE_ISOLATED);
768
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600769 rtas_pci_slot_reset (pdn, 0);
770
771 /* After a PCI slot has been reset, the PCI Express spec requires
772 * a 1.5 second idle time for the bus to stabilize, before starting
773 * up traffic. */
774#define PCI_BUS_SETTLE_TIME_MSEC 1800
775 msleep (PCI_BUS_SETTLE_TIME_MSEC);
Linas Vepstase1029262006-09-21 18:25:56 -0500776}
777
778int rtas_set_slot_reset(struct pci_dn *pdn)
779{
780 int i, rc;
781
Linas Vepstas9c547762007-03-19 14:58:07 -0500782 /* Take three shots at resetting the bus */
783 for (i=0; i<3; i++) {
784 __rtas_set_slot_reset(pdn);
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600785
Linas Vepstas9c547762007-03-19 14:58:07 -0500786 rc = eeh_wait_for_slot_status(pdn, PCI_BUS_RESET_WAIT_MSEC);
Linas Vepstasb6495c02005-11-03 18:54:54 -0600787 if (rc == 0)
788 return 0;
Linas Vepstase1029262006-09-21 18:25:56 -0500789
Linas Vepstase1029262006-09-21 18:25:56 -0500790 if (rc < 0) {
Linas Vepstas12588da2007-07-27 08:30:26 +1000791 printk(KERN_ERR "EEH: unrecoverable slot failure %s\n",
792 pdn->node->full_name);
Linas Vepstasb6495c02005-11-03 18:54:54 -0600793 return -1;
Linas Vepstase1029262006-09-21 18:25:56 -0500794 }
Linas Vepstas12588da2007-07-27 08:30:26 +1000795 printk(KERN_ERR "EEH: bus reset %d failed on slot %s, rc=%d\n",
796 i+1, pdn->node->full_name, rc);
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600797 }
Linas Vepstasb6495c02005-11-03 18:54:54 -0600798
Linas Vepstas9c547762007-03-19 14:58:07 -0500799 return -1;
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600800}
801
Linas Vepstas8b553f32005-11-03 18:50:17 -0600802/* ------------------------------------------------------- */
803/** Save and restore of PCI BARs
804 *
805 * Although firmware will set up BARs during boot, it doesn't
806 * set up device BAR's after a device reset, although it will,
807 * if requested, set up bridge configuration. Thus, we need to
808 * configure the PCI devices ourselves.
809 */
810
811/**
812 * __restore_bars - Restore the Base Address Registers
Linas Vepstascb5b56242006-09-15 18:56:35 -0500813 * @pdn: pci device node
814 *
Linas Vepstas8b553f32005-11-03 18:50:17 -0600815 * Loads the PCI configuration space base address registers,
816 * the expansion ROM base address, the latency timer, and etc.
817 * from the saved values in the device node.
818 */
819static inline void __restore_bars (struct pci_dn *pdn)
820{
821 int i;
Mike Masoncde274c2008-07-09 02:04:35 +1000822 u32 cmd;
Linas Vepstas8b553f32005-11-03 18:50:17 -0600823
824 if (NULL==pdn->phb) return;
825 for (i=4; i<10; i++) {
826 rtas_write_config(pdn, i*4, 4, pdn->config_space[i]);
827 }
828
829 /* 12 == Expansion ROM Address */
830 rtas_write_config(pdn, 12*4, 4, pdn->config_space[12]);
831
832#define BYTE_SWAP(OFF) (8*((OFF)/4)+3-(OFF))
833#define SAVED_BYTE(OFF) (((u8 *)(pdn->config_space))[BYTE_SWAP(OFF)])
834
835 rtas_write_config (pdn, PCI_CACHE_LINE_SIZE, 1,
836 SAVED_BYTE(PCI_CACHE_LINE_SIZE));
837
838 rtas_write_config (pdn, PCI_LATENCY_TIMER, 1,
839 SAVED_BYTE(PCI_LATENCY_TIMER));
840
841 /* max latency, min grant, interrupt pin and line */
842 rtas_write_config(pdn, 15*4, 4, pdn->config_space[15]);
Mike Masoncde274c2008-07-09 02:04:35 +1000843
844 /* Restore PERR & SERR bits, some devices require it,
845 don't touch the other command bits */
846 rtas_read_config(pdn, PCI_COMMAND, 4, &cmd);
847 if (pdn->config_space[1] & PCI_COMMAND_PARITY)
848 cmd |= PCI_COMMAND_PARITY;
849 else
850 cmd &= ~PCI_COMMAND_PARITY;
851 if (pdn->config_space[1] & PCI_COMMAND_SERR)
852 cmd |= PCI_COMMAND_SERR;
853 else
854 cmd &= ~PCI_COMMAND_SERR;
855 rtas_write_config(pdn, PCI_COMMAND, 4, cmd);
Linas Vepstas8b553f32005-11-03 18:50:17 -0600856}
857
858/**
859 * eeh_restore_bars - restore the PCI config space info
860 *
861 * This routine performs a recursive walk to the children
862 * of this device as well.
863 */
864void eeh_restore_bars(struct pci_dn *pdn)
865{
866 struct device_node *dn;
867 if (!pdn)
868 return;
869
Linas Vepstas7684b402005-11-03 18:55:19 -0600870 if ((pdn->eeh_mode & EEH_MODE_SUPPORTED) && !IS_BRIDGE(pdn->class_code))
Linas Vepstas8b553f32005-11-03 18:50:17 -0600871 __restore_bars (pdn);
872
Stephen Rothwellacaa6172007-12-21 15:52:07 +1100873 for_each_child_of_node(pdn->node, dn)
Linas Vepstas8b553f32005-11-03 18:50:17 -0600874 eeh_restore_bars (PCI_DN(dn));
Linas Vepstas8b553f32005-11-03 18:50:17 -0600875}
876
877/**
878 * eeh_save_bars - save device bars
879 *
880 * Save the values of the device bars. Unlike the restore
881 * routine, this routine is *not* recursive. This is because
Justin Mattock31116f02011-02-24 20:10:18 +0000882 * PCI devices are added individually; but, for the restore,
Linas Vepstas8b553f32005-11-03 18:50:17 -0600883 * an entire slot is reset at a time.
884 */
Linas Vepstas7684b402005-11-03 18:55:19 -0600885static void eeh_save_bars(struct pci_dn *pdn)
Linas Vepstas8b553f32005-11-03 18:50:17 -0600886{
887 int i;
888
Linas Vepstas7684b402005-11-03 18:55:19 -0600889 if (!pdn )
Linas Vepstas8b553f32005-11-03 18:50:17 -0600890 return;
891
892 for (i = 0; i < 16; i++)
Linas Vepstas7684b402005-11-03 18:55:19 -0600893 rtas_read_config(pdn, i * 4, 4, &pdn->config_space[i]);
Linas Vepstas8b553f32005-11-03 18:50:17 -0600894}
895
896void
897rtas_configure_bridge(struct pci_dn *pdn)
898{
Linas Vepstasfcb75432005-11-03 18:54:39 -0600899 int config_addr;
Linas Vepstas8b553f32005-11-03 18:50:17 -0600900 int rc;
Richard A. Lary65f47f12011-04-06 12:50:45 +0000901 int token;
Linas Vepstas8b553f32005-11-03 18:50:17 -0600902
Linas Vepstasfcb75432005-11-03 18:54:39 -0600903 /* Use PE configuration address, if present */
904 config_addr = pdn->eeh_config_addr;
905 if (pdn->eeh_pe_config_addr)
906 config_addr = pdn->eeh_pe_config_addr;
907
Richard A. Lary65f47f12011-04-06 12:50:45 +0000908 /* Use new configure-pe function, if supported */
909 if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE)
910 token = ibm_configure_pe;
911 else
912 token = ibm_configure_bridge;
913
914 rc = rtas_call(token, 3, 1, NULL,
Linas Vepstasfcb75432005-11-03 18:54:39 -0600915 config_addr,
Linas Vepstas8b553f32005-11-03 18:50:17 -0600916 BUID_HI(pdn->phb->buid),
917 BUID_LO(pdn->phb->buid));
918 if (rc) {
919 printk (KERN_WARNING "EEH: Unable to configure device bridge (%d) for %s\n",
920 rc, pdn->node->full_name);
921 }
922}
923
Linas Vepstas6dee3fb2005-11-03 18:50:10 -0600924/* ------------------------------------------------------------- */
Linas Vepstas172ca922005-11-03 18:50:04 -0600925/* The code below deals with enabling EEH for devices during the
926 * early boot sequence. EEH must be enabled before any PCI probing
927 * can be done.
928 */
929
930#define EEH_ENABLE 1
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932struct eeh_early_enable_info {
933 unsigned int buid_hi;
934 unsigned int buid_lo;
935};
936
Linas Vepstas147d6a32007-03-19 14:54:21 -0500937static int get_pe_addr (int config_addr,
938 struct eeh_early_enable_info *info)
939{
940 unsigned int rets[3];
941 int ret;
942
943 /* Use latest config-addr token on power6 */
944 if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
945 /* Make sure we have a PE in hand */
946 ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
947 config_addr, info->buid_hi, info->buid_lo, 1);
948 if (ret || (rets[0]==0))
949 return 0;
950
951 ret = rtas_call (ibm_get_config_addr_info2, 4, 2, rets,
952 config_addr, info->buid_hi, info->buid_lo, 0);
953 if (ret)
954 return 0;
955 return rets[0];
956 }
957
958 /* Use older config-addr token on power5 */
959 if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
960 ret = rtas_call (ibm_get_config_addr_info, 4, 2, rets,
961 config_addr, info->buid_hi, info->buid_lo, 0);
962 if (ret)
963 return 0;
964 return rets[0];
965 }
966 return 0;
967}
968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969/* Enable eeh for the given device node. */
970static void *early_enable_eeh(struct device_node *dn, void *data)
971{
Linas Vepstas25c4a462007-01-26 14:55:03 -0600972 unsigned int rets[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 struct eeh_early_enable_info *info = data;
974 int ret;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000975 const u32 *class_code = of_get_property(dn, "class-code", NULL);
976 const u32 *vendor_id = of_get_property(dn, "vendor-id", NULL);
977 const u32 *device_id = of_get_property(dn, "device-id", NULL);
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000978 const u32 *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 int enable;
Linas Vepstas69376502005-11-03 18:47:50 -0600980 struct pci_dn *pdn = PCI_DN(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
linas0f175742005-12-01 18:42:32 -0600982 pdn->class_code = 0;
Paul Mackerras16353172005-09-06 13:17:54 +1000983 pdn->eeh_mode = 0;
Linas Vepstas5c1344e2005-11-03 18:49:31 -0600984 pdn->eeh_check_count = 0;
985 pdn->eeh_freeze_count = 0;
Linas Vepstas858955b2007-05-24 03:20:51 +1000986 pdn->eeh_false_positives = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Nathan Lynchc6d4d5a2008-03-14 06:52:10 +1100988 if (!of_device_is_available(dn))
989 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 /* Ignore bad nodes. */
992 if (!class_code || !vendor_id || !device_id)
993 return NULL;
994
995 /* There is nothing to check on PCI to ISA bridges */
996 if (dn->type && !strcmp(dn->type, "isa")) {
Paul Mackerras16353172005-09-06 13:17:54 +1000997 pdn->eeh_mode |= EEH_MODE_NOCHECK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return NULL;
999 }
linas0f175742005-12-01 18:42:32 -06001000 pdn->class_code = *class_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 /* Ok... see if this device supports EEH. Some do, some don't,
1003 * and the only way to find out is to check each and every one. */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001004 regs = of_get_property(dn, "reg", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (regs) {
1006 /* First register entry is addr (00BBSS00) */
1007 /* Try to enable eeh */
1008 ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
Linas Vepstas172ca922005-11-03 18:50:04 -06001009 regs[0], info->buid_hi, info->buid_lo,
1010 EEH_ENABLE);
1011
Linas Vepstas25c4a462007-01-26 14:55:03 -06001012 enable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (ret == 0) {
Paul Mackerras16353172005-09-06 13:17:54 +10001014 pdn->eeh_config_addr = regs[0];
Linas Vepstas25e591f2005-11-03 18:53:20 -06001015
1016 /* If the newer, better, ibm,get-config-addr-info is supported,
1017 * then use that instead. */
Linas Vepstas147d6a32007-03-19 14:54:21 -05001018 pdn->eeh_pe_config_addr = get_pe_addr(pdn->eeh_config_addr, info);
Linas Vepstas25c4a462007-01-26 14:55:03 -06001019
1020 /* Some older systems (Power4) allow the
1021 * ibm,set-eeh-option call to succeed even on nodes
1022 * where EEH is not supported. Verify support
1023 * explicitly. */
1024 ret = read_slot_reset_state(pdn, rets);
1025 if ((ret == 0) && (rets[1] == 1))
1026 enable = 1;
1027 }
1028
1029 if (enable) {
1030 eeh_subsystem_enabled = 1;
1031 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
1032
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001033 pr_debug("EEH: %s: eeh enabled, config=%x pe_config=%x\n",
1034 dn->full_name, pdn->eeh_config_addr,
1035 pdn->eeh_pe_config_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 } else {
1037
1038 /* This device doesn't support EEH, but it may have an
1039 * EEH parent, in which case we mark it as supported. */
Linas Vepstas69376502005-11-03 18:47:50 -06001040 if (dn->parent && PCI_DN(dn->parent)
Paul Mackerras16353172005-09-06 13:17:54 +10001041 && (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 /* Parent supports EEH. */
Paul Mackerras16353172005-09-06 13:17:54 +10001043 pdn->eeh_mode |= EEH_MODE_SUPPORTED;
1044 pdn->eeh_config_addr = PCI_DN(dn->parent)->eeh_config_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 return NULL;
1046 }
1047 }
1048 } else {
1049 printk(KERN_WARNING "EEH: %s: unable to get reg property.\n",
1050 dn->full_name);
1051 }
1052
Linas Vepstas7684b402005-11-03 18:55:19 -06001053 eeh_save_bars(pdn);
Linas Vepstas69376502005-11-03 18:47:50 -06001054 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
1057/*
1058 * Initialize EEH by trying to enable it for all of the adapters in the system.
1059 * As a side effect we can determine here if eeh is supported at all.
1060 * Note that we leave EEH on so failed config cycles won't cause a machine
1061 * check. If a user turns off EEH for a particular adapter they are really
1062 * telling Linux to ignore errors. Some hardware (e.g. POWER5) won't
1063 * grant access to a slot if EEH isn't enabled, and so we always enable
1064 * EEH for all slots/all devices.
1065 *
1066 * The eeh-force-off option disables EEH checking globally, for all slots.
1067 * Even if force-off is set, the EEH hardware is still enabled, so that
1068 * newer systems can boot.
1069 */
1070void __init eeh_init(void)
1071{
1072 struct device_node *phb, *np;
1073 struct eeh_early_enable_info info;
1074
Thomas Gleixner3d372622010-02-18 02:23:07 +00001075 raw_spin_lock_init(&confirm_error_lock);
Linas Vepstasdf7242b2005-11-03 18:49:01 -06001076 spin_lock_init(&slot_errbuf_lock);
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 np = of_find_node_by_path("/rtas");
1079 if (np == NULL)
1080 return;
1081
1082 ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
1083 ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
1084 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
1085 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
1086 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
Linas Vepstas25e591f2005-11-03 18:53:20 -06001087 ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
Linas Vepstas147d6a32007-03-19 14:54:21 -05001088 ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
Linas Vepstas21e464d2005-11-03 18:54:47 -06001089 ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
Richard A. Lary65f47f12011-04-06 12:50:45 +00001090 ibm_configure_pe = rtas_token("ibm,configure-pe");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
1093 return;
1094
1095 eeh_error_buf_size = rtas_token("rtas-error-log-max");
1096 if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
1097 eeh_error_buf_size = 1024;
1098 }
1099 if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
1100 printk(KERN_WARNING "EEH: rtas-error-log-max is bigger than allocated "
1101 "buffer ! (%d vs %d)", eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
1102 eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
1103 }
1104
1105 /* Enable EEH for all adapters. Note that eeh requires buid's */
1106 for (phb = of_find_node_by_name(NULL, "pci"); phb;
1107 phb = of_find_node_by_name(phb, "pci")) {
1108 unsigned long buid;
1109
1110 buid = get_phb_buid(phb);
Linas Vepstas69376502005-11-03 18:47:50 -06001111 if (buid == 0 || PCI_DN(phb) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 continue;
1113
1114 info.buid_lo = BUID_LO(buid);
1115 info.buid_hi = BUID_HI(buid);
1116 traverse_pci_devices(phb, early_enable_eeh, &info);
1117 }
1118
1119 if (eeh_subsystem_enabled)
1120 printk(KERN_INFO "EEH: PCI Enhanced I/O Error Handling Enabled\n");
1121 else
1122 printk(KERN_WARNING "EEH: No capable adapters found\n");
1123}
1124
1125/**
1126 * eeh_add_device_early - enable EEH for the indicated device_node
1127 * @dn: device node for which to set up EEH
1128 *
1129 * This routine must be used to perform EEH initialization for PCI
1130 * devices that were added after system boot (e.g. hotplug, dlpar).
1131 * This routine must be called before any i/o is performed to the
1132 * adapter (inluding any config-space i/o).
1133 * Whether this actually enables EEH or not for this device depends
1134 * on the CEC architecture, type of the device, on earlier boot
1135 * command-line arguments & etc.
1136 */
Nathan Fontenot794e0852006-03-31 12:04:52 -06001137static void eeh_add_device_early(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
1139 struct pci_controller *phb;
1140 struct eeh_early_enable_info info;
1141
Linas Vepstas69376502005-11-03 18:47:50 -06001142 if (!dn || !PCI_DN(dn))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 return;
Paul Mackerras16353172005-09-06 13:17:54 +10001144 phb = PCI_DN(dn)->phb;
Linas Vepstasf751f842005-11-03 18:54:23 -06001145
1146 /* USB Bus children of PCI devices will not have BUID's */
1147 if (NULL == phb || 0 == phb->buid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 info.buid_hi = BUID_HI(phb->buid);
1151 info.buid_lo = BUID_LO(phb->buid);
1152 early_enable_eeh(dn, &info);
1153}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Linas Vepstase2a296e2005-11-03 18:51:31 -06001155void eeh_add_device_tree_early(struct device_node *dn)
1156{
1157 struct device_node *sib;
Stephen Rothwellacaa6172007-12-21 15:52:07 +11001158
1159 for_each_child_of_node(dn, sib)
Linas Vepstase2a296e2005-11-03 18:51:31 -06001160 eeh_add_device_tree_early(sib);
1161 eeh_add_device_early(dn);
1162}
1163EXPORT_SYMBOL_GPL(eeh_add_device_tree_early);
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165/**
1166 * eeh_add_device_late - perform EEH initialization for the indicated pci device
1167 * @dev: pci device for which to set up EEH
1168 *
1169 * This routine must be used to complete EEH initialization for PCI
1170 * devices that were added after system boot (e.g. hotplug, dlpar).
1171 */
Nathan Fontenot794e0852006-03-31 12:04:52 -06001172static void eeh_add_device_late(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001174 struct device_node *dn;
Linas Vepstas8b553f32005-11-03 18:50:17 -06001175 struct pci_dn *pdn;
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 if (!dev || !eeh_subsystem_enabled)
1178 return;
1179
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001180 pr_debug("EEH: Adding device %s\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001182 dn = pci_device_to_OF_node(dev);
Linas Vepstas8b553f32005-11-03 18:50:17 -06001183 pdn = PCI_DN(dn);
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001184 if (pdn->pcidev == dev) {
1185 pr_debug("EEH: Already referenced !\n");
1186 return;
1187 }
1188 WARN_ON(pdn->pcidev);
1189
1190 pci_dev_get (dev);
Linas Vepstas8b553f32005-11-03 18:50:17 -06001191 pdn->pcidev = dev;
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001192
Linas Vepstase1d04c92007-05-24 03:16:46 +10001193 pci_addr_cache_insert_device(dev);
1194 eeh_sysfs_add_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
Nathan Fontenot794e0852006-03-31 12:04:52 -06001196
1197void eeh_add_device_tree_late(struct pci_bus *bus)
1198{
1199 struct pci_dev *dev;
1200
1201 list_for_each_entry(dev, &bus->devices, bus_list) {
1202 eeh_add_device_late(dev);
1203 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
1204 struct pci_bus *subbus = dev->subordinate;
1205 if (subbus)
1206 eeh_add_device_tree_late(subbus);
1207 }
1208 }
1209}
1210EXPORT_SYMBOL_GPL(eeh_add_device_tree_late);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212/**
1213 * eeh_remove_device - undo EEH setup for the indicated pci device
1214 * @dev: pci device to be removed
1215 *
Nathan Fontenot794e0852006-03-31 12:04:52 -06001216 * This routine should be called when a device is removed from
1217 * a running system (e.g. by hotplug or dlpar). It unregisters
1218 * the PCI device from the EEH subsystem. I/O errors affecting
1219 * this device will no longer be detected after this call; thus,
1220 * i/o errors affecting this slot may leave this device unusable.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 */
Nathan Fontenot794e0852006-03-31 12:04:52 -06001222static void eeh_remove_device(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001224 struct device_node *dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 if (!dev || !eeh_subsystem_enabled)
1226 return;
1227
1228 /* Unregister the device with the EEH/PCI address search system */
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001229 pr_debug("EEH: Removing device %s\n", pci_name(dev));
Linas Vepstas56b0fca2005-11-03 18:48:45 -06001230
1231 dn = pci_device_to_OF_node(dev);
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001232 if (PCI_DN(dn)->pcidev == NULL) {
1233 pr_debug("EEH: Not referenced !\n");
1234 return;
Linas Vepstasb055a9e2006-04-06 15:41:41 -05001235 }
Benjamin Herrenschmidt57b066f2008-10-27 19:48:41 +00001236 PCI_DN(dn)->pcidev = NULL;
1237 pci_dev_put (dev);
1238
1239 pci_addr_cache_remove_device(dev);
1240 eeh_sysfs_remove_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Linas Vepstase2a296e2005-11-03 18:51:31 -06001243void eeh_remove_bus_device(struct pci_dev *dev)
1244{
Nathan Fontenot794e0852006-03-31 12:04:52 -06001245 struct pci_bus *bus = dev->subordinate;
1246 struct pci_dev *child, *tmp;
1247
Linas Vepstase2a296e2005-11-03 18:51:31 -06001248 eeh_remove_device(dev);
Nathan Fontenot794e0852006-03-31 12:04:52 -06001249
1250 if (bus && dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
1251 list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
1252 eeh_remove_bus_device(child);
Linas Vepstase2a296e2005-11-03 18:51:31 -06001253 }
1254}
1255EXPORT_SYMBOL_GPL(eeh_remove_bus_device);
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257static int proc_eeh_show(struct seq_file *m, void *v)
1258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 if (0 == eeh_subsystem_enabled) {
1260 seq_printf(m, "EEH Subsystem is globally disabled\n");
Linas Vepstas257ffc62005-11-03 18:55:25 -06001261 seq_printf(m, "eeh_total_mmio_ffs=%ld\n", total_mmio_ffs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 } else {
1263 seq_printf(m, "EEH Subsystem is enabled\n");
Linas Vepstas177bc932005-11-03 18:48:52 -06001264 seq_printf(m,
1265 "no device=%ld\n"
1266 "no device node=%ld\n"
1267 "no config address=%ld\n"
1268 "check not wanted=%ld\n"
1269 "eeh_total_mmio_ffs=%ld\n"
1270 "eeh_false_positives=%ld\n"
Linas Vepstas177bc932005-11-03 18:48:52 -06001271 "eeh_slot_resets=%ld\n",
Linas Vepstas257ffc62005-11-03 18:55:25 -06001272 no_device, no_dn, no_cfg_addr,
1273 ignored_check, total_mmio_ffs,
Linas Vepstas42253a62007-05-24 03:23:38 +10001274 false_positives,
Linas Vepstas257ffc62005-11-03 18:55:25 -06001275 slot_resets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277
1278 return 0;
1279}
1280
1281static int proc_eeh_open(struct inode *inode, struct file *file)
1282{
1283 return single_open(file, proc_eeh_show, NULL);
1284}
1285
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001286static const struct file_operations proc_eeh_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 .open = proc_eeh_open,
1288 .read = seq_read,
1289 .llseek = seq_lseek,
1290 .release = single_release,
1291};
1292
1293static int __init eeh_init_proc(void)
1294{
Denis V. Lunev66747132008-04-29 01:02:26 -07001295 if (machine_is(pseries))
1296 proc_create("ppc64/eeh", 0, NULL, &proc_eeh_operations);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 return 0;
1298}
1299__initcall(eeh_init_proc);