30 #include <linux/export.h>
32 #include <linux/list.h>
34 #include <linux/pci.h>
36 #include <linux/rbtree.h>
37 #include <linux/sched.h>
44 #include <asm/machdep.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;
64 static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
66 static int eeh_error_buf_size;
73 static int pseries_eeh_init(
void)
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");
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",
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;
133 eeh_probe_mode_set(EEH_PROBE_MODE_DEVTREE);
149 struct eeh_dev *edev;
157 edev = of_node_to_eeh_dev(dn);
167 if (!class_code || !vendor_id || !device_id)
173 edev->class_code = *class_code;
179 pr_warning(
"%s: OF node property %s::reg not found\n",
185 memset(&pe, 0,
sizeof(
struct eeh_pe));
187 pe.config_addr = regs[0];
190 ret =
eeh_ops->set_option(&pe, EEH_OPT_ENABLE);
192 edev->config_addr = regs[0];
194 edev->pe_config_addr =
eeh_ops->get_pe_addr(&pe);
195 pe.addr = edev->pe_config_addr;
202 if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
209 pr_debug(
"%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n",
210 __func__, dn->
full_name, pe.phb->global_number,
211 pe.addr, pe.config_addr);
212 }
else if (dn->
parent && of_node_to_eeh_dev(dn->
parent) &&
213 (of_node_to_eeh_dev(dn->
parent))->pe) {
217 edev->config_addr = of_node_to_eeh_dev(dn->
parent)->config_addr;
218 edev->pe_config_addr = of_node_to_eeh_dev(dn->
parent)->pe_config_addr;
238 static int pseries_eeh_set_option(
struct eeh_pe *pe,
int option)
250 case EEH_OPT_DISABLE:
252 case EEH_OPT_THAW_MMIO:
253 case EEH_OPT_THAW_DMA:
254 config_addr = pe->config_addr;
256 config_addr = pe->addr;
260 pr_err(
"%s: Invalid option %d\n",
266 config_addr, BUID_HI(pe->phb->buid),
267 BUID_LO(pe->phb->buid), option);
285 static int pseries_eeh_get_pe_addr(
struct eeh_pe *pe)
290 if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
296 ret =
rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
297 pe->config_addr, BUID_HI(pe->phb->buid),
298 BUID_LO(pe->phb->buid), 1);
299 if (ret || (rets[0] == 0))
303 ret =
rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
304 pe->config_addr, BUID_HI(pe->phb->buid),
305 BUID_LO(pe->phb->buid), 0);
307 pr_warning(
"%s: Failed to get address for PHB#%d-PE#%x\n",
308 __func__, pe->phb->global_number, pe->config_addr);
315 if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
316 ret =
rtas_call(ibm_get_config_addr_info, 4, 2, rets,
317 pe->config_addr, BUID_HI(pe->phb->buid),
318 BUID_LO(pe->phb->buid), 0);
320 pr_warning(
"%s: Failed to get address for PHB#%d-PE#%x\n",
321 __func__, pe->phb->global_number, pe->config_addr);
344 static int pseries_eeh_get_state(
struct eeh_pe *pe,
int *
state)
352 config_addr = pe->config_addr;
354 config_addr = pe->addr;
356 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
357 ret =
rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
358 config_addr, BUID_HI(pe->phb->buid),
359 BUID_LO(pe->phb->buid));
360 }
else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
363 ret =
rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
364 config_addr, BUID_HI(pe->phb->buid),
365 BUID_LO(pe->phb->buid));
367 return EEH_STATE_NOT_SUPPORT;
378 result &= ~EEH_STATE_RESET_ACTIVE;
379 result |= EEH_STATE_MMIO_ACTIVE;
380 result |= EEH_STATE_DMA_ACTIVE;
383 result |= EEH_STATE_RESET_ACTIVE;
384 result |= EEH_STATE_MMIO_ACTIVE;
385 result |= EEH_STATE_DMA_ACTIVE;
388 result &= ~EEH_STATE_RESET_ACTIVE;
389 result &= ~EEH_STATE_MMIO_ACTIVE;
390 result &= ~EEH_STATE_DMA_ACTIVE;
393 result &= ~EEH_STATE_RESET_ACTIVE;
394 result &= ~EEH_STATE_MMIO_ACTIVE;
395 result &= ~EEH_STATE_DMA_ACTIVE;
396 result |= EEH_STATE_MMIO_ENABLED;
400 if (state) *state = rets[2];
401 result = EEH_STATE_UNAVAILABLE;
403 result = EEH_STATE_NOT_SUPPORT;
406 result = EEH_STATE_NOT_SUPPORT;
409 result = EEH_STATE_NOT_SUPPORT;
422 static int pseries_eeh_reset(
struct eeh_pe *pe,
int option)
428 config_addr = pe->config_addr;
430 config_addr = pe->addr;
434 config_addr, BUID_HI(pe->phb->buid),
435 BUID_LO(pe->phb->buid), option);
438 if (option == EEH_RESET_FUNDAMENTAL &&
441 config_addr, BUID_HI(pe->phb->buid),
442 BUID_LO(pe->phb->buid), EEH_RESET_HOT);
456 static int pseries_eeh_wait_state(
struct eeh_pe *pe,
int max_wait)
469 #define EEH_STATE_MIN_WAIT_TIME (1000)
470 #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
473 ret = pseries_eeh_get_state(pe, &mwait);
480 if (ret != EEH_STATE_UNAVAILABLE)
484 pr_warning(
"%s: Timeout when getting PE's state (%d)\n",
486 return EEH_STATE_NOT_SUPPORT;
490 pr_warning(
"%s: Firmware returned bad wait value %d\n",
493 }
else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
494 pr_warning(
"%s: Firmware returned too long wait value %d\n",
503 return EEH_STATE_NOT_SUPPORT;
517 static int pseries_eeh_get_log(
struct eeh_pe *pe,
int severity,
char *drv_log,
unsigned long len)
524 memset(slot_errbuf, 0, eeh_error_buf_size);
527 config_addr = pe->config_addr;
529 config_addr = pe->addr;
531 ret =
rtas_call(ibm_slot_error_detail, 8, 1,
NULL, config_addr,
532 BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid),
537 log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
538 spin_unlock_irqrestore(&slot_errbuf_lock, flags);
551 static int pseries_eeh_configure_bridge(
struct eeh_pe *pe)
557 config_addr = pe->config_addr;
559 config_addr = pe->addr;
562 if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) {
564 config_addr, BUID_HI(pe->phb->buid),
565 BUID_LO(pe->phb->buid));
566 }
else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) {
568 config_addr, BUID_HI(pe->phb->buid),
569 BUID_LO(pe->phb->buid));
575 pr_warning(
"%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n",
576 __func__, pe->phb->global_number, pe->addr, ret);
617 static struct eeh_ops pseries_eeh_ops = {
619 .init = pseries_eeh_init,
620 .of_probe = pseries_eeh_of_probe,
622 .set_option = pseries_eeh_set_option,
623 .get_pe_addr = pseries_eeh_get_pe_addr,
624 .get_state = pseries_eeh_get_state,
625 .reset = pseries_eeh_reset,
626 .wait_state = pseries_eeh_wait_state,
627 .get_log = pseries_eeh_get_log,
628 .configure_bridge = pseries_eeh_configure_bridge,
629 .read_config = pseries_eeh_read_config,
630 .write_config = pseries_eeh_write_config
639 static int __init eeh_pseries_init(
void)
643 if (!machine_is(pseries))
648 pr_info(
"EEH: pSeries platform initialized\n");
650 pr_info(
"EEH: pSeries platform initialization failure (%d)\n",