2 * The file intends to implement the platform dependent EEH operations on pseries.
3 * Actually, the pseries platform is built based on RTAS heavily. That means the
4 * pseries platform dependent EEH operations will be built on RTAS calls. The functions
5 * are devired from arch/powerpc/platforms/pseries/eeh.c and necessary cleanup has
8 * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2011.
9 * Copyright IBM Corporation 2001, 2005, 2006
10 * Copyright Dave Engebretsen & Todd Inglett 2001
11 * Copyright Linas Vepstas 2005, 2006
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/atomic.h>
29 #include <linux/delay.h>
30 #include <linux/export.h>
31 #include <linux/init.h>
32 #include <linux/list.h>
34 #include <linux/pci.h>
35 #include <linux/proc_fs.h>
36 #include <linux/rbtree.h>
37 #include <linux/sched.h>
38 #include <linux/seq_file.h>
39 #include <linux/spinlock.h>
42 #include <asm/eeh_event.h>
44 #include <asm/machdep.h>
45 #include <asm/ppc-pci.h>
49 static int ibm_set_eeh_option;
50 static int ibm_set_slot_reset;
51 static int ibm_read_slot_reset_state;
52 static int ibm_read_slot_reset_state2;
53 static int ibm_slot_error_detail;
54 static int ibm_get_config_addr_info;
55 static int ibm_get_config_addr_info2;
56 static int ibm_configure_bridge;
57 static int ibm_configure_pe;
60 * Buffer for reporting slot-error-detail rtas calls. Its here
61 * in BSS, and not dynamically alloced, so that it ends up in
62 * RMO where RTAS can access it.
64 static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
65 static DEFINE_SPINLOCK(slot_errbuf_lock);
66 static int eeh_error_buf_size;
69 * pseries_eeh_init - EEH platform dependent initialization
71 * EEH platform dependent initialization on pseries.
73 static int pseries_eeh_init(void)
75 /* figure out EEH RTAS function call tokens */
76 ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
77 ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
78 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
79 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
80 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
81 ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
82 ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
83 ibm_configure_pe = rtas_token("ibm,configure-pe");
84 ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
86 /* necessary sanity check */
87 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE) {
88 pr_warning("%s: RTAS service <ibm,set-eeh-option> invalid\n",
91 } else if (ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE) {
92 pr_warning("%s: RTAS service <ibm, set-slot-reset> invalid\n",
95 } else if (ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE &&
96 ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) {
97 pr_warning("%s: RTAS service <ibm,read-slot-reset-state2> and "
98 "<ibm,read-slot-reset-state> invalid\n",
101 } else if (ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE) {
102 pr_warning("%s: RTAS service <ibm,slot-error-detail> invalid\n",
105 } else if (ibm_get_config_addr_info2 == RTAS_UNKNOWN_SERVICE &&
106 ibm_get_config_addr_info == RTAS_UNKNOWN_SERVICE) {
107 pr_warning("%s: RTAS service <ibm,get-config-addr-info2> and "
108 "<ibm,get-config-addr-info> invalid\n",
111 } else if (ibm_configure_pe == RTAS_UNKNOWN_SERVICE &&
112 ibm_configure_bridge == RTAS_UNKNOWN_SERVICE) {
113 pr_warning("%s: RTAS service <ibm,configure-pe> and "
114 "<ibm,configure-bridge> invalid\n",
119 /* Initialize error log lock and size */
120 spin_lock_init(&slot_errbuf_lock);
121 eeh_error_buf_size = rtas_token("rtas-error-log-max");
122 if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
123 pr_warning("%s: unknown EEH error log size\n",
125 eeh_error_buf_size = 1024;
126 } else if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
127 pr_warning("%s: EEH error log size %d exceeds the maximal %d\n",
128 __func__, eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
129 eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
136 * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
138 * @option: operation to be issued
140 * The function is used to control the EEH functionality globally.
141 * Currently, following options are support according to PAPR:
142 * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
144 static int pseries_eeh_set_option(struct device_node *dn, int option)
147 struct eeh_dev *edev;
151 edev = of_node_to_eeh_dev(dn);
154 * When we're enabling or disabling EEH functioality on
155 * the particular PE, the PE config address is possibly
156 * unavailable. Therefore, we have to figure it out from
160 case EEH_OPT_DISABLE:
162 reg = of_get_property(dn, "reg", NULL);
163 config_addr = reg[0];
166 case EEH_OPT_THAW_MMIO:
167 case EEH_OPT_THAW_DMA:
168 config_addr = edev->config_addr;
169 if (edev->pe_config_addr)
170 config_addr = edev->pe_config_addr;
174 pr_err("%s: Invalid option %d\n",
179 ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
180 config_addr, BUID_HI(edev->phb->buid),
181 BUID_LO(edev->phb->buid), option);
187 * pseries_eeh_get_pe_addr - Retrieve PE address
190 * Retrieve the assocated PE address. Actually, there're 2 RTAS
191 * function calls dedicated for the purpose. We need implement
192 * it through the new function and then the old one. Besides,
193 * you should make sure the config address is figured out from
194 * FDT node before calling the function.
196 * It's notable that zero'ed return value means invalid PE config
199 static int pseries_eeh_get_pe_addr(struct device_node *dn)
201 struct eeh_dev *edev;
205 edev = of_node_to_eeh_dev(dn);
207 if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
209 * First of all, we need to make sure there has one PE
210 * associated with the device. Otherwise, PE address is
213 ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
214 edev->config_addr, BUID_HI(edev->phb->buid),
215 BUID_LO(edev->phb->buid), 1);
216 if (ret || (rets[0] == 0))
219 /* Retrieve the associated PE config address */
220 ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
221 edev->config_addr, BUID_HI(edev->phb->buid),
222 BUID_LO(edev->phb->buid), 0);
224 pr_warning("%s: Failed to get PE address for %s\n",
225 __func__, dn->full_name);
232 if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
233 ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
234 edev->config_addr, BUID_HI(edev->phb->buid),
235 BUID_LO(edev->phb->buid), 0);
237 pr_warning("%s: Failed to get PE address for %s\n",
238 __func__, dn->full_name);
249 * pseries_eeh_get_state - Retrieve PE state
250 * @dn: PE associated device node
251 * @state: return value
253 * Retrieve the state of the specified PE. On RTAS compliant
254 * pseries platform, there already has one dedicated RTAS function
255 * for the purpose. It's notable that the associated PE config address
256 * might be ready when calling the function. Therefore, endeavour to
257 * use the PE config address if possible. Further more, there're 2
258 * RTAS calls for the purpose, we need to try the new one and back
259 * to the old one if the new one couldn't work properly.
261 static int pseries_eeh_get_state(struct device_node *dn, int *state)
263 struct eeh_dev *edev;
269 /* Figure out PE config address if possible */
270 edev = of_node_to_eeh_dev(dn);
271 config_addr = edev->config_addr;
272 if (edev->pe_config_addr)
273 config_addr = edev->pe_config_addr;
275 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
276 ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
277 config_addr, BUID_HI(edev->phb->buid),
278 BUID_LO(edev->phb->buid));
279 } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
280 /* Fake PE unavailable info */
282 ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
283 config_addr, BUID_HI(edev->phb->buid),
284 BUID_LO(edev->phb->buid));
286 return EEH_STATE_NOT_SUPPORT;
292 /* Parse the result out */
297 result &= ~EEH_STATE_RESET_ACTIVE;
298 result |= EEH_STATE_MMIO_ACTIVE;
299 result |= EEH_STATE_DMA_ACTIVE;
302 result |= EEH_STATE_RESET_ACTIVE;
303 result |= EEH_STATE_MMIO_ACTIVE;
304 result |= EEH_STATE_DMA_ACTIVE;
307 result &= ~EEH_STATE_RESET_ACTIVE;
308 result &= ~EEH_STATE_MMIO_ACTIVE;
309 result &= ~EEH_STATE_DMA_ACTIVE;
312 result &= ~EEH_STATE_RESET_ACTIVE;
313 result &= ~EEH_STATE_MMIO_ACTIVE;
314 result &= ~EEH_STATE_DMA_ACTIVE;
315 result |= EEH_STATE_MMIO_ENABLED;
319 if (state) *state = rets[2];
320 result = EEH_STATE_UNAVAILABLE;
322 result = EEH_STATE_NOT_SUPPORT;
325 result = EEH_STATE_NOT_SUPPORT;
328 result = EEH_STATE_NOT_SUPPORT;
335 * pseries_eeh_reset - Reset the specified PE
336 * @dn: PE associated device node
337 * @option: reset option
339 * Reset the specified PE
341 static int pseries_eeh_reset(struct device_node *dn, int option)
343 struct eeh_dev *edev;
347 /* Figure out PE address */
348 edev = of_node_to_eeh_dev(dn);
349 config_addr = edev->config_addr;
350 if (edev->pe_config_addr)
351 config_addr = edev->pe_config_addr;
353 /* Reset PE through RTAS call */
354 ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
355 config_addr, BUID_HI(edev->phb->buid),
356 BUID_LO(edev->phb->buid), option);
358 /* If fundamental-reset not supported, try hot-reset */
359 if (option == EEH_RESET_FUNDAMENTAL &&
361 ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
362 config_addr, BUID_HI(edev->phb->buid),
363 BUID_LO(edev->phb->buid), EEH_RESET_HOT);
370 * pseries_eeh_wait_state - Wait for PE state
371 * @dn: PE associated device node
372 * @max_wait: maximal period in microsecond
374 * Wait for the state of associated PE. It might take some time
375 * to retrieve the PE's state.
377 static int pseries_eeh_wait_state(struct device_node *dn, int max_wait)
383 * According to PAPR, the state of PE might be temporarily
384 * unavailable. Under the circumstance, we have to wait
385 * for indicated time determined by firmware. The maximal
386 * wait time is 5 minutes, which is acquired from the original
387 * EEH implementation. Also, the original implementation
388 * also defined the minimal wait time as 1 second.
390 #define EEH_STATE_MIN_WAIT_TIME (1000)
391 #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
394 ret = pseries_eeh_get_state(dn, &mwait);
397 * If the PE's state is temporarily unavailable,
398 * we have to wait for the specified time. Otherwise,
399 * the PE's state will be returned immediately.
401 if (ret != EEH_STATE_UNAVAILABLE)
405 pr_warning("%s: Timeout when getting PE's state (%d)\n",
407 return EEH_STATE_NOT_SUPPORT;
411 pr_warning("%s: Firmware returned bad wait value %d\n",
413 mwait = EEH_STATE_MIN_WAIT_TIME;
414 } else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
415 pr_warning("%s: Firmware returned too long wait value %d\n",
417 mwait = EEH_STATE_MAX_WAIT_TIME;
424 return EEH_STATE_NOT_SUPPORT;
428 * pseries_eeh_get_log - Retrieve error log
430 * @severity: temporary or permanent error log
431 * @drv_log: driver log to be combined with retrieved error log
432 * @len: length of driver log
434 * Retrieve the temporary or permanent error from the PE.
435 * Actually, the error will be retrieved through the dedicated
438 static int pseries_eeh_get_log(struct device_node *dn, int severity, char *drv_log, unsigned long len)
440 struct eeh_dev *edev;
445 edev = of_node_to_eeh_dev(dn);
446 spin_lock_irqsave(&slot_errbuf_lock, flags);
447 memset(slot_errbuf, 0, eeh_error_buf_size);
449 /* Figure out the PE address */
450 config_addr = edev->config_addr;
451 if (edev->pe_config_addr)
452 config_addr = edev->pe_config_addr;
454 ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, config_addr,
455 BUID_HI(edev->phb->buid), BUID_LO(edev->phb->buid),
456 virt_to_phys(drv_log), len,
457 virt_to_phys(slot_errbuf), eeh_error_buf_size,
460 log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
461 spin_unlock_irqrestore(&slot_errbuf_lock, flags);
467 * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE
468 * @dn: PE associated device node
470 * The function will be called to reconfigure the bridges included
471 * in the specified PE so that the mulfunctional PE would be recovered
474 static int pseries_eeh_configure_bridge(struct device_node *dn)
476 struct eeh_dev *edev;
480 /* Figure out the PE address */
481 edev = of_node_to_eeh_dev(dn);
482 config_addr = edev->config_addr;
483 if (edev->pe_config_addr)
484 config_addr = edev->pe_config_addr;
486 /* Use new configure-pe function, if supported */
487 if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) {
488 ret = rtas_call(ibm_configure_pe, 3, 1, NULL,
489 config_addr, BUID_HI(edev->phb->buid),
490 BUID_LO(edev->phb->buid));
491 } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) {
492 ret = rtas_call(ibm_configure_bridge, 3, 1, NULL,
493 config_addr, BUID_HI(edev->phb->buid),
494 BUID_LO(edev->phb->buid));
500 pr_warning("%s: Unable to configure bridge %d for %s\n",
501 __func__, ret, dn->full_name);
506 static struct eeh_ops pseries_eeh_ops = {
508 .init = pseries_eeh_init,
509 .set_option = pseries_eeh_set_option,
510 .get_pe_addr = pseries_eeh_get_pe_addr,
511 .get_state = pseries_eeh_get_state,
512 .reset = pseries_eeh_reset,
513 .wait_state = pseries_eeh_wait_state,
514 .get_log = pseries_eeh_get_log,
515 .configure_bridge = pseries_eeh_configure_bridge
519 * eeh_pseries_init - Register platform dependent EEH operations
521 * EEH initialization on pseries platform. This function should be
522 * called before any EEH related functions.
524 int __init eeh_pseries_init(void)
526 return eeh_ops_register(&pseries_eeh_ops);