1d9953105SMichael Ellerman /* 2d9953105SMichael Ellerman * Copyright (C) 2001 Dave Engebretsen IBM Corporation 3d9953105SMichael Ellerman * 4d9953105SMichael Ellerman * This program is free software; you can redistribute it and/or modify 5d9953105SMichael Ellerman * it under the terms of the GNU General Public License as published by 6d9953105SMichael Ellerman * the Free Software Foundation; either version 2 of the License, or 7d9953105SMichael Ellerman * (at your option) any later version. 8d9953105SMichael Ellerman * 9d9953105SMichael Ellerman * This program is distributed in the hope that it will be useful, 10d9953105SMichael Ellerman * but WITHOUT ANY WARRANTY; without even the implied warranty of 11d9953105SMichael Ellerman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12d9953105SMichael Ellerman * GNU General Public License for more details. 13d9953105SMichael Ellerman * 14d9953105SMichael Ellerman * You should have received a copy of the GNU General Public License 15d9953105SMichael Ellerman * along with this program; if not, write to the Free Software 16d9953105SMichael Ellerman * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17d9953105SMichael Ellerman */ 18d9953105SMichael Ellerman 19d9953105SMichael Ellerman /* Change Activity: 20d9953105SMichael Ellerman * 2001/09/21 : engebret : Created with minimal EPOW and HW exception support. 21d9953105SMichael Ellerman * End Change Activity 22d9953105SMichael Ellerman */ 23d9953105SMichael Ellerman 24d9953105SMichael Ellerman #include <linux/errno.h> 25d9953105SMichael Ellerman #include <linux/threads.h> 26d9953105SMichael Ellerman #include <linux/kernel_stat.h> 27d9953105SMichael Ellerman #include <linux/signal.h> 28d9953105SMichael Ellerman #include <linux/sched.h> 29d9953105SMichael Ellerman #include <linux/ioport.h> 30d9953105SMichael Ellerman #include <linux/interrupt.h> 31d9953105SMichael Ellerman #include <linux/timex.h> 32d9953105SMichael Ellerman #include <linux/init.h> 33d9953105SMichael Ellerman #include <linux/delay.h> 34d9953105SMichael Ellerman #include <linux/irq.h> 35d9953105SMichael Ellerman #include <linux/random.h> 36d9953105SMichael Ellerman #include <linux/sysrq.h> 37d9953105SMichael Ellerman #include <linux/bitops.h> 3855fc0c56SAnton Blanchard #include <linux/fs.h> 3955fc0c56SAnton Blanchard #include <linux/reboot.h> 40d9953105SMichael Ellerman 41d9953105SMichael Ellerman #include <asm/uaccess.h> 42d9953105SMichael Ellerman #include <asm/system.h> 43d9953105SMichael Ellerman #include <asm/io.h> 44d9953105SMichael Ellerman #include <asm/pgtable.h> 45d9953105SMichael Ellerman #include <asm/irq.h> 46d9953105SMichael Ellerman #include <asm/cache.h> 47d9953105SMichael Ellerman #include <asm/prom.h> 48d9953105SMichael Ellerman #include <asm/ptrace.h> 49d9953105SMichael Ellerman #include <asm/machdep.h> 50d9953105SMichael Ellerman #include <asm/rtas.h> 51dcad47fcSDavid Gibson #include <asm/udbg.h> 528c4f1f29SMichael Ellerman #include <asm/firmware.h> 53d9953105SMichael Ellerman 54577830b0SMichael Ellerman #include "pseries.h" 55c902be71SArnd Bergmann 56d9953105SMichael Ellerman static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX]; 57d9953105SMichael Ellerman static DEFINE_SPINLOCK(ras_log_buf_lock); 58d9953105SMichael Ellerman 59d368514cSAnton Blanchard static char global_mce_data_buf[RTAS_ERROR_LOG_MAX]; 60d368514cSAnton Blanchard static DEFINE_PER_CPU(__u64, mce_data_buf); 61d9953105SMichael Ellerman 62d9953105SMichael Ellerman static int ras_check_exception_token; 63d9953105SMichael Ellerman 64d9953105SMichael Ellerman #define EPOW_SENSOR_TOKEN 9 65d9953105SMichael Ellerman #define EPOW_SENSOR_INDEX 0 66d9953105SMichael Ellerman 677d12e780SDavid Howells static irqreturn_t ras_epow_interrupt(int irq, void *dev_id); 687d12e780SDavid Howells static irqreturn_t ras_error_interrupt(int irq, void *dev_id); 69d9953105SMichael Ellerman 700ebfff14SBenjamin Herrenschmidt 71d9953105SMichael Ellerman /* 72d9953105SMichael Ellerman * Initialize handlers for the set of interrupts caused by hardware errors 73d9953105SMichael Ellerman * and power system events. 74d9953105SMichael Ellerman */ 75d9953105SMichael Ellerman static int __init init_ras_IRQ(void) 76d9953105SMichael Ellerman { 77d9953105SMichael Ellerman struct device_node *np; 78d9953105SMichael Ellerman 79d9953105SMichael Ellerman ras_check_exception_token = rtas_token("check-exception"); 80d9953105SMichael Ellerman 81d9953105SMichael Ellerman /* Internal Errors */ 82d9953105SMichael Ellerman np = of_find_node_by_path("/event-sources/internal-errors"); 83d9953105SMichael Ellerman if (np != NULL) { 8432c96f77SMark Nelson request_event_sources_irqs(np, ras_error_interrupt, 8532c96f77SMark Nelson "RAS_ERROR"); 86d9953105SMichael Ellerman of_node_put(np); 87d9953105SMichael Ellerman } 88d9953105SMichael Ellerman 89d9953105SMichael Ellerman /* EPOW Events */ 90d9953105SMichael Ellerman np = of_find_node_by_path("/event-sources/epow-events"); 91d9953105SMichael Ellerman if (np != NULL) { 9232c96f77SMark Nelson request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW"); 93d9953105SMichael Ellerman of_node_put(np); 94d9953105SMichael Ellerman } 95d9953105SMichael Ellerman 9669ed3324SAnton Blanchard return 0; 97d9953105SMichael Ellerman } 9855fc0c56SAnton Blanchard subsys_initcall(init_ras_IRQ); 99d9953105SMichael Ellerman 10055fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_NORMAL 1 10155fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_ON_UPS 2 10255fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3 10355fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4 10455fc0c56SAnton Blanchard 10555fc0c56SAnton Blanchard static void handle_system_shutdown(char event_modifier) 10655fc0c56SAnton Blanchard { 10755fc0c56SAnton Blanchard switch (event_modifier) { 10855fc0c56SAnton Blanchard case EPOW_SHUTDOWN_NORMAL: 10955fc0c56SAnton Blanchard pr_emerg("Firmware initiated power off"); 11055fc0c56SAnton Blanchard orderly_poweroff(1); 11155fc0c56SAnton Blanchard break; 11255fc0c56SAnton Blanchard 11355fc0c56SAnton Blanchard case EPOW_SHUTDOWN_ON_UPS: 11455fc0c56SAnton Blanchard pr_emerg("Loss of power reported by firmware, system is " 11555fc0c56SAnton Blanchard "running on UPS/battery"); 11655fc0c56SAnton Blanchard break; 11755fc0c56SAnton Blanchard 11855fc0c56SAnton Blanchard case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS: 11955fc0c56SAnton Blanchard pr_emerg("Loss of system critical functions reported by " 12055fc0c56SAnton Blanchard "firmware"); 12155fc0c56SAnton Blanchard pr_emerg("Check RTAS error log for details"); 12255fc0c56SAnton Blanchard orderly_poweroff(1); 12355fc0c56SAnton Blanchard break; 12455fc0c56SAnton Blanchard 12555fc0c56SAnton Blanchard case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH: 12655fc0c56SAnton Blanchard pr_emerg("Ambient temperature too high reported by firmware"); 12755fc0c56SAnton Blanchard pr_emerg("Check RTAS error log for details"); 12855fc0c56SAnton Blanchard orderly_poweroff(1); 12955fc0c56SAnton Blanchard break; 13055fc0c56SAnton Blanchard 13155fc0c56SAnton Blanchard default: 13255fc0c56SAnton Blanchard pr_err("Unknown power/cooling shutdown event (modifier %d)", 13355fc0c56SAnton Blanchard event_modifier); 13455fc0c56SAnton Blanchard } 13555fc0c56SAnton Blanchard } 13655fc0c56SAnton Blanchard 13755fc0c56SAnton Blanchard struct epow_errorlog { 13855fc0c56SAnton Blanchard unsigned char sensor_value; 13955fc0c56SAnton Blanchard unsigned char event_modifier; 14055fc0c56SAnton Blanchard unsigned char extended_modifier; 14155fc0c56SAnton Blanchard unsigned char reserved; 14255fc0c56SAnton Blanchard unsigned char platform_reason; 14355fc0c56SAnton Blanchard }; 14455fc0c56SAnton Blanchard 14555fc0c56SAnton Blanchard #define EPOW_RESET 0 14655fc0c56SAnton Blanchard #define EPOW_WARN_COOLING 1 14755fc0c56SAnton Blanchard #define EPOW_WARN_POWER 2 14855fc0c56SAnton Blanchard #define EPOW_SYSTEM_SHUTDOWN 3 14955fc0c56SAnton Blanchard #define EPOW_SYSTEM_HALT 4 15055fc0c56SAnton Blanchard #define EPOW_MAIN_ENCLOSURE 5 15155fc0c56SAnton Blanchard #define EPOW_POWER_OFF 7 15255fc0c56SAnton Blanchard 15355fc0c56SAnton Blanchard void rtas_parse_epow_errlog(struct rtas_error_log *log) 15455fc0c56SAnton Blanchard { 15555fc0c56SAnton Blanchard struct pseries_errorlog *pseries_log; 15655fc0c56SAnton Blanchard struct epow_errorlog *epow_log; 15755fc0c56SAnton Blanchard char action_code; 15855fc0c56SAnton Blanchard char modifier; 15955fc0c56SAnton Blanchard 16055fc0c56SAnton Blanchard pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW); 16155fc0c56SAnton Blanchard if (pseries_log == NULL) 16255fc0c56SAnton Blanchard return; 16355fc0c56SAnton Blanchard 16455fc0c56SAnton Blanchard epow_log = (struct epow_errorlog *)pseries_log->data; 16555fc0c56SAnton Blanchard action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */ 16655fc0c56SAnton Blanchard modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */ 16755fc0c56SAnton Blanchard 16855fc0c56SAnton Blanchard switch (action_code) { 16955fc0c56SAnton Blanchard case EPOW_RESET: 17055fc0c56SAnton Blanchard pr_err("Non critical power or cooling issue cleared"); 17155fc0c56SAnton Blanchard break; 17255fc0c56SAnton Blanchard 17355fc0c56SAnton Blanchard case EPOW_WARN_COOLING: 17455fc0c56SAnton Blanchard pr_err("Non critical cooling issue reported by firmware"); 17555fc0c56SAnton Blanchard pr_err("Check RTAS error log for details"); 17655fc0c56SAnton Blanchard break; 17755fc0c56SAnton Blanchard 17855fc0c56SAnton Blanchard case EPOW_WARN_POWER: 17955fc0c56SAnton Blanchard pr_err("Non critical power issue reported by firmware"); 18055fc0c56SAnton Blanchard pr_err("Check RTAS error log for details"); 18155fc0c56SAnton Blanchard break; 18255fc0c56SAnton Blanchard 18355fc0c56SAnton Blanchard case EPOW_SYSTEM_SHUTDOWN: 18455fc0c56SAnton Blanchard handle_system_shutdown(epow_log->event_modifier); 18555fc0c56SAnton Blanchard break; 18655fc0c56SAnton Blanchard 18755fc0c56SAnton Blanchard case EPOW_SYSTEM_HALT: 18855fc0c56SAnton Blanchard pr_emerg("Firmware initiated power off"); 18955fc0c56SAnton Blanchard orderly_poweroff(1); 19055fc0c56SAnton Blanchard break; 19155fc0c56SAnton Blanchard 19255fc0c56SAnton Blanchard case EPOW_MAIN_ENCLOSURE: 19355fc0c56SAnton Blanchard case EPOW_POWER_OFF: 19455fc0c56SAnton Blanchard pr_emerg("Critical power/cooling issue reported by firmware"); 19555fc0c56SAnton Blanchard pr_emerg("Check RTAS error log for details"); 19655fc0c56SAnton Blanchard pr_emerg("Immediate power off"); 19755fc0c56SAnton Blanchard emergency_sync(); 19855fc0c56SAnton Blanchard kernel_power_off(); 19955fc0c56SAnton Blanchard break; 20055fc0c56SAnton Blanchard 20155fc0c56SAnton Blanchard default: 20255fc0c56SAnton Blanchard pr_err("Unknown power/cooling event (action code %d)", 20355fc0c56SAnton Blanchard action_code); 20455fc0c56SAnton Blanchard } 20555fc0c56SAnton Blanchard } 20655fc0c56SAnton Blanchard 20755fc0c56SAnton Blanchard /* Handle environmental and power warning (EPOW) interrupts. */ 2087d12e780SDavid Howells static irqreturn_t ras_epow_interrupt(int irq, void *dev_id) 209d9953105SMichael Ellerman { 21055fc0c56SAnton Blanchard int status; 21155fc0c56SAnton Blanchard int state; 212d9953105SMichael Ellerman int critical; 213d9953105SMichael Ellerman 214*587f83e8SAnton Blanchard status = rtas_get_sensor(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, &state); 215d9953105SMichael Ellerman 216d9953105SMichael Ellerman if (state > 3) 217d9953105SMichael Ellerman critical = 1; /* Time Critical */ 218d9953105SMichael Ellerman else 219d9953105SMichael Ellerman critical = 0; 220d9953105SMichael Ellerman 221d9953105SMichael Ellerman spin_lock(&ras_log_buf_lock); 222d9953105SMichael Ellerman 223d9953105SMichael Ellerman status = rtas_call(ras_check_exception_token, 6, 1, NULL, 224b08e281bSMark Nelson RTAS_VECTOR_EXTERNAL_INTERRUPT, 225476eb491SGrant Likely virq_to_hw(irq), 226d9953105SMichael Ellerman RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS, 227d9953105SMichael Ellerman critical, __pa(&ras_log_buf), 228d9953105SMichael Ellerman rtas_get_error_log_max()); 229d9953105SMichael Ellerman 230d9953105SMichael Ellerman log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0); 231d9953105SMichael Ellerman 23255fc0c56SAnton Blanchard rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf); 23355fc0c56SAnton Blanchard 234d9953105SMichael Ellerman spin_unlock(&ras_log_buf_lock); 235d9953105SMichael Ellerman return IRQ_HANDLED; 236d9953105SMichael Ellerman } 237d9953105SMichael Ellerman 238d9953105SMichael Ellerman /* 239d9953105SMichael Ellerman * Handle hardware error interrupts. 240d9953105SMichael Ellerman * 241d9953105SMichael Ellerman * RTAS check-exception is called to collect data on the exception. If 242d9953105SMichael Ellerman * the error is deemed recoverable, we log a warning and return. 243d9953105SMichael Ellerman * For nonrecoverable errors, an error is logged and we stop all processing 244d9953105SMichael Ellerman * as quickly as possible in order to prevent propagation of the failure. 245d9953105SMichael Ellerman */ 2467d12e780SDavid Howells static irqreturn_t ras_error_interrupt(int irq, void *dev_id) 247d9953105SMichael Ellerman { 248d9953105SMichael Ellerman struct rtas_error_log *rtas_elog; 249d9953105SMichael Ellerman int status = 0xdeadbeef; 250d9953105SMichael Ellerman int fatal; 251d9953105SMichael Ellerman 252d9953105SMichael Ellerman spin_lock(&ras_log_buf_lock); 253d9953105SMichael Ellerman 254d9953105SMichael Ellerman status = rtas_call(ras_check_exception_token, 6, 1, NULL, 255b08e281bSMark Nelson RTAS_VECTOR_EXTERNAL_INTERRUPT, 256476eb491SGrant Likely virq_to_hw(irq), 257d9953105SMichael Ellerman RTAS_INTERNAL_ERROR, 1 /*Time Critical */, 258d9953105SMichael Ellerman __pa(&ras_log_buf), 259d9953105SMichael Ellerman rtas_get_error_log_max()); 260d9953105SMichael Ellerman 261d9953105SMichael Ellerman rtas_elog = (struct rtas_error_log *)ras_log_buf; 262d9953105SMichael Ellerman 263d9953105SMichael Ellerman if ((status == 0) && (rtas_elog->severity >= RTAS_SEVERITY_ERROR_SYNC)) 264d9953105SMichael Ellerman fatal = 1; 265d9953105SMichael Ellerman else 266d9953105SMichael Ellerman fatal = 0; 267d9953105SMichael Ellerman 268d9953105SMichael Ellerman /* format and print the extended information */ 269d9953105SMichael Ellerman log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal); 270d9953105SMichael Ellerman 271d9953105SMichael Ellerman if (fatal) { 272d9953105SMichael Ellerman udbg_printf("Fatal HW Error <0x%lx 0x%x>\n", 273d9953105SMichael Ellerman *((unsigned long *)&ras_log_buf), status); 274d9953105SMichael Ellerman printk(KERN_EMERG "Error: Fatal hardware error <0x%lx 0x%x>\n", 275d9953105SMichael Ellerman *((unsigned long *)&ras_log_buf), status); 276d9953105SMichael Ellerman 27736f8a2c4SMichael Ellerman #ifndef DEBUG_RTAS_POWER_OFF 278d9953105SMichael Ellerman /* Don't actually power off when debugging so we can test 279d9953105SMichael Ellerman * without actually failing while injecting errors. 280d9953105SMichael Ellerman * Error data will not be logged to syslog. 281d9953105SMichael Ellerman */ 282d9953105SMichael Ellerman ppc_md.power_off(); 283d9953105SMichael Ellerman #endif 284d9953105SMichael Ellerman } else { 285d9953105SMichael Ellerman udbg_printf("Recoverable HW Error <0x%lx 0x%x>\n", 286d9953105SMichael Ellerman *((unsigned long *)&ras_log_buf), status); 287d9953105SMichael Ellerman printk(KERN_WARNING 288d9953105SMichael Ellerman "Warning: Recoverable hardware error <0x%lx 0x%x>\n", 289d9953105SMichael Ellerman *((unsigned long *)&ras_log_buf), status); 290d9953105SMichael Ellerman } 291d9953105SMichael Ellerman 292d9953105SMichael Ellerman spin_unlock(&ras_log_buf_lock); 293d9953105SMichael Ellerman return IRQ_HANDLED; 294d9953105SMichael Ellerman } 295d9953105SMichael Ellerman 296d368514cSAnton Blanchard /* 297d368514cSAnton Blanchard * Some versions of FWNMI place the buffer inside the 4kB page starting at 298d368514cSAnton Blanchard * 0x7000. Other versions place it inside the rtas buffer. We check both. 299d368514cSAnton Blanchard */ 300d368514cSAnton Blanchard #define VALID_FWNMI_BUFFER(A) \ 301d368514cSAnton Blanchard ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \ 302d368514cSAnton Blanchard (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16)))) 303d368514cSAnton Blanchard 304d368514cSAnton Blanchard /* 305d368514cSAnton Blanchard * Get the error information for errors coming through the 306d9953105SMichael Ellerman * FWNMI vectors. The pt_regs' r3 will be updated to reflect 307d9953105SMichael Ellerman * the actual r3 if possible, and a ptr to the error log entry 308d9953105SMichael Ellerman * will be returned if found. 309d9953105SMichael Ellerman * 310d368514cSAnton Blanchard * If the RTAS error is not of the extended type, then we put it in a per 311d368514cSAnton Blanchard * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf. 312d368514cSAnton Blanchard * 313d368514cSAnton Blanchard * The global_mce_data_buf does not have any locks or protection around it, 314d9953105SMichael Ellerman * if a second machine check comes in, or a system reset is done 315d9953105SMichael Ellerman * before we have logged the error, then we will get corruption in the 316d9953105SMichael Ellerman * error log. This is preferable over holding off on calling 317d9953105SMichael Ellerman * ibm,nmi-interlock which would result in us checkstopping if a 318d9953105SMichael Ellerman * second machine check did come in. 319d9953105SMichael Ellerman */ 320d9953105SMichael Ellerman static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) 321d9953105SMichael Ellerman { 322d9953105SMichael Ellerman unsigned long *savep; 323d368514cSAnton Blanchard struct rtas_error_log *h, *errhdr = NULL; 324d9953105SMichael Ellerman 325d368514cSAnton Blanchard if (!VALID_FWNMI_BUFFER(regs->gpr[3])) { 326f0e939aeSAnton Blanchard printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]); 327d368514cSAnton Blanchard return NULL; 328d9953105SMichael Ellerman } 329d368514cSAnton Blanchard 330d368514cSAnton Blanchard savep = __va(regs->gpr[3]); 331d368514cSAnton Blanchard regs->gpr[3] = savep[0]; /* restore original r3 */ 332d368514cSAnton Blanchard 333d368514cSAnton Blanchard /* If it isn't an extended log we can use the per cpu 64bit buffer */ 334d368514cSAnton Blanchard h = (struct rtas_error_log *)&savep[1]; 335d368514cSAnton Blanchard if (!h->extended) { 336d368514cSAnton Blanchard memcpy(&__get_cpu_var(mce_data_buf), h, sizeof(__u64)); 337d368514cSAnton Blanchard errhdr = (struct rtas_error_log *)&__get_cpu_var(mce_data_buf); 338d368514cSAnton Blanchard } else { 339d368514cSAnton Blanchard int len; 340d368514cSAnton Blanchard 341d368514cSAnton Blanchard len = max_t(int, 8+h->extended_log_length, RTAS_ERROR_LOG_MAX); 342d368514cSAnton Blanchard memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX); 343d368514cSAnton Blanchard memcpy(global_mce_data_buf, h, len); 344d368514cSAnton Blanchard errhdr = (struct rtas_error_log *)global_mce_data_buf; 345d368514cSAnton Blanchard } 346d368514cSAnton Blanchard 347d9953105SMichael Ellerman return errhdr; 348d9953105SMichael Ellerman } 349d9953105SMichael Ellerman 350d9953105SMichael Ellerman /* Call this when done with the data returned by FWNMI_get_errinfo. 351d9953105SMichael Ellerman * It will release the saved data area for other CPUs in the 352d9953105SMichael Ellerman * partition to receive FWNMI errors. 353d9953105SMichael Ellerman */ 354d9953105SMichael Ellerman static void fwnmi_release_errinfo(void) 355d9953105SMichael Ellerman { 356d9953105SMichael Ellerman int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL); 357d9953105SMichael Ellerman if (ret != 0) 358d368514cSAnton Blanchard printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret); 359d9953105SMichael Ellerman } 360d9953105SMichael Ellerman 361c902be71SArnd Bergmann int pSeries_system_reset_exception(struct pt_regs *regs) 362d9953105SMichael Ellerman { 363d9953105SMichael Ellerman if (fwnmi_active) { 364d9953105SMichael Ellerman struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs); 365d9953105SMichael Ellerman if (errhdr) { 366d9953105SMichael Ellerman /* XXX Should look at FWNMI information */ 367d9953105SMichael Ellerman } 368d9953105SMichael Ellerman fwnmi_release_errinfo(); 369d9953105SMichael Ellerman } 370c902be71SArnd Bergmann return 0; /* need to perform reset */ 371d9953105SMichael Ellerman } 372d9953105SMichael Ellerman 373d9953105SMichael Ellerman /* 374d9953105SMichael Ellerman * See if we can recover from a machine check exception. 375d9953105SMichael Ellerman * This is only called on power4 (or above) and only via 376d9953105SMichael Ellerman * the Firmware Non-Maskable Interrupts (fwnmi) handler 377d9953105SMichael Ellerman * which provides the error analysis for us. 378d9953105SMichael Ellerman * 379d9953105SMichael Ellerman * Return 1 if corrected (or delivered a signal). 380d9953105SMichael Ellerman * Return 0 if there is nothing we can do. 381d9953105SMichael Ellerman */ 382d9953105SMichael Ellerman static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err) 383d9953105SMichael Ellerman { 384d47d1d8aSAnton Blanchard int recovered = 0; 385d9953105SMichael Ellerman 386d47d1d8aSAnton Blanchard if (!(regs->msr & MSR_RI)) { 387d47d1d8aSAnton Blanchard /* If MSR_RI isn't set, we cannot recover */ 388d47d1d8aSAnton Blanchard recovered = 0; 389d47d1d8aSAnton Blanchard 390d47d1d8aSAnton Blanchard } else if (err->disposition == RTAS_DISP_FULLY_RECOVERED) { 391d9953105SMichael Ellerman /* Platform corrected itself */ 392d47d1d8aSAnton Blanchard recovered = 1; 393d47d1d8aSAnton Blanchard 394d47d1d8aSAnton Blanchard } else if (err->disposition == RTAS_DISP_LIMITED_RECOVERY) { 395d47d1d8aSAnton Blanchard /* Platform corrected itself but could be degraded */ 396d47d1d8aSAnton Blanchard printk(KERN_ERR "MCE: limited recovery, system may " 397d47d1d8aSAnton Blanchard "be degraded\n"); 398d47d1d8aSAnton Blanchard recovered = 1; 399d47d1d8aSAnton Blanchard 400d47d1d8aSAnton Blanchard } else if (user_mode(regs) && !is_global_init(current) && 401d47d1d8aSAnton Blanchard err->severity == RTAS_SEVERITY_ERROR_SYNC) { 402d47d1d8aSAnton Blanchard 403d47d1d8aSAnton Blanchard /* 404d47d1d8aSAnton Blanchard * If we received a synchronous error when in userspace 405d47d1d8aSAnton Blanchard * kill the task. Firmware may report details of the fail 406d47d1d8aSAnton Blanchard * asynchronously, so we can't rely on the target and type 407d47d1d8aSAnton Blanchard * fields being valid here. 408d47d1d8aSAnton Blanchard */ 409d47d1d8aSAnton Blanchard printk(KERN_ERR "MCE: uncorrectable error, killing task " 410d47d1d8aSAnton Blanchard "%s:%d\n", current->comm, current->pid); 411d47d1d8aSAnton Blanchard 412d47d1d8aSAnton Blanchard _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); 413d47d1d8aSAnton Blanchard recovered = 1; 414d9953105SMichael Ellerman } 415d9953105SMichael Ellerman 4163f9793e6SAnton Blanchard log_error((char *)err, ERR_TYPE_RTAS_LOG, 0); 417d9953105SMichael Ellerman 418d47d1d8aSAnton Blanchard return recovered; 419d9953105SMichael Ellerman } 420d9953105SMichael Ellerman 421d9953105SMichael Ellerman /* 422d9953105SMichael Ellerman * Handle a machine check. 423d9953105SMichael Ellerman * 424d9953105SMichael Ellerman * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi) 425d9953105SMichael Ellerman * should be present. If so the handler which called us tells us if the 426d9953105SMichael Ellerman * error was recovered (never true if RI=0). 427d9953105SMichael Ellerman * 428d9953105SMichael Ellerman * On hardware prior to Power 4 these exceptions were asynchronous which 429d9953105SMichael Ellerman * means we can't tell exactly where it occurred and so we can't recover. 430d9953105SMichael Ellerman */ 431d9953105SMichael Ellerman int pSeries_machine_check_exception(struct pt_regs *regs) 432d9953105SMichael Ellerman { 433d9953105SMichael Ellerman struct rtas_error_log *errp; 434d9953105SMichael Ellerman 435d9953105SMichael Ellerman if (fwnmi_active) { 436d9953105SMichael Ellerman errp = fwnmi_get_errinfo(regs); 437d9953105SMichael Ellerman fwnmi_release_errinfo(); 438d9953105SMichael Ellerman if (errp && recover_mce(regs, errp)) 439d9953105SMichael Ellerman return 1; 440d9953105SMichael Ellerman } 441d9953105SMichael Ellerman 442d9953105SMichael Ellerman return 0; 443d9953105SMichael Ellerman } 444