2 * Copyright (C) 2001 Dave Engebretsen IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/sched.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
24 #include <linux/reboot.h>
26 #include <asm/machdep.h>
28 #include <asm/firmware.h>
32 static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
33 static DEFINE_SPINLOCK(ras_log_buf_lock);
35 static char global_mce_data_buf[RTAS_ERROR_LOG_MAX];
36 static DEFINE_PER_CPU(__u64, mce_data_buf);
38 static int ras_check_exception_token;
40 #define EPOW_SENSOR_TOKEN 9
41 #define EPOW_SENSOR_INDEX 0
43 /* EPOW events counter variable */
44 static int num_epow_events;
46 static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id);
47 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
48 static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
52 * Initialize handlers for the set of interrupts caused by hardware errors
53 * and power system events.
55 static int __init init_ras_IRQ(void)
57 struct device_node *np;
59 ras_check_exception_token = rtas_token("check-exception");
62 np = of_find_node_by_path("/event-sources/internal-errors");
64 request_event_sources_irqs(np, ras_error_interrupt,
70 np = of_find_node_by_path("/event-sources/hot-plug-events");
72 if (dlpar_workqueue_init() == 0)
73 request_event_sources_irqs(np, ras_hotplug_interrupt,
79 np = of_find_node_by_path("/event-sources/epow-events");
81 request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
87 machine_subsys_initcall(pseries, init_ras_IRQ);
89 #define EPOW_SHUTDOWN_NORMAL 1
90 #define EPOW_SHUTDOWN_ON_UPS 2
91 #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3
92 #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4
94 static void handle_system_shutdown(char event_modifier)
96 switch (event_modifier) {
97 case EPOW_SHUTDOWN_NORMAL:
98 pr_emerg("Power off requested\n");
99 orderly_poweroff(true);
102 case EPOW_SHUTDOWN_ON_UPS:
103 pr_emerg("Loss of system power detected. System is running on"
104 " UPS/battery. Check RTAS error log for details\n");
105 orderly_poweroff(true);
108 case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
109 pr_emerg("Loss of system critical functions detected. Check"
110 " RTAS error log for details\n");
111 orderly_poweroff(true);
114 case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
115 pr_emerg("High ambient temperature detected. Check RTAS"
116 " error log for details\n");
117 orderly_poweroff(true);
121 pr_err("Unknown power/cooling shutdown event (modifier = %d)\n",
126 struct epow_errorlog {
127 unsigned char sensor_value;
128 unsigned char event_modifier;
129 unsigned char extended_modifier;
130 unsigned char reserved;
131 unsigned char platform_reason;
135 #define EPOW_WARN_COOLING 1
136 #define EPOW_WARN_POWER 2
137 #define EPOW_SYSTEM_SHUTDOWN 3
138 #define EPOW_SYSTEM_HALT 4
139 #define EPOW_MAIN_ENCLOSURE 5
140 #define EPOW_POWER_OFF 7
142 static void rtas_parse_epow_errlog(struct rtas_error_log *log)
144 struct pseries_errorlog *pseries_log;
145 struct epow_errorlog *epow_log;
149 pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
150 if (pseries_log == NULL)
153 epow_log = (struct epow_errorlog *)pseries_log->data;
154 action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */
155 modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */
157 switch (action_code) {
159 if (num_epow_events) {
160 pr_info("Non critical power/cooling issue cleared\n");
165 case EPOW_WARN_COOLING:
166 pr_info("Non-critical cooling issue detected. Check RTAS error"
167 " log for details\n");
170 case EPOW_WARN_POWER:
171 pr_info("Non-critical power issue detected. Check RTAS error"
172 " log for details\n");
175 case EPOW_SYSTEM_SHUTDOWN:
176 handle_system_shutdown(epow_log->event_modifier);
179 case EPOW_SYSTEM_HALT:
180 pr_emerg("Critical power/cooling issue detected. Check RTAS"
181 " error log for details. Powering off.\n");
182 orderly_poweroff(true);
185 case EPOW_MAIN_ENCLOSURE:
187 pr_emerg("System about to lose power. Check RTAS error log "
188 " for details. Powering off immediately.\n");
194 pr_err("Unknown power/cooling event (action code = %d)\n",
198 /* Increment epow events counter variable */
199 if (action_code != EPOW_RESET)
203 static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id)
205 struct pseries_errorlog *pseries_log;
206 struct pseries_hp_errorlog *hp_elog;
208 spin_lock(&ras_log_buf_lock);
210 rtas_call(ras_check_exception_token, 6, 1, NULL,
211 RTAS_VECTOR_EXTERNAL_INTERRUPT, virq_to_hw(irq),
212 RTAS_HOTPLUG_EVENTS, 0, __pa(&ras_log_buf),
213 rtas_get_error_log_max());
215 pseries_log = get_pseries_errorlog((struct rtas_error_log *)ras_log_buf,
216 PSERIES_ELOG_SECT_ID_HOTPLUG);
217 hp_elog = (struct pseries_hp_errorlog *)pseries_log->data;
220 * Since PCI hotplug is not currently supported on pseries, put PCI
221 * hotplug events on the ras_log_buf to be handled by rtas_errd.
223 if (hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_MEM ||
224 hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_CPU)
225 queue_hotplug_event(hp_elog, NULL, NULL);
227 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
229 spin_unlock(&ras_log_buf_lock);
233 /* Handle environmental and power warning (EPOW) interrupts. */
234 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
240 status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
244 critical = 1; /* Time Critical */
248 spin_lock(&ras_log_buf_lock);
250 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
251 RTAS_VECTOR_EXTERNAL_INTERRUPT,
254 critical, __pa(&ras_log_buf),
255 rtas_get_error_log_max());
257 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
259 rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
261 spin_unlock(&ras_log_buf_lock);
266 * Handle hardware error interrupts.
268 * RTAS check-exception is called to collect data on the exception. If
269 * the error is deemed recoverable, we log a warning and return.
270 * For nonrecoverable errors, an error is logged and we stop all processing
271 * as quickly as possible in order to prevent propagation of the failure.
273 static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
275 struct rtas_error_log *rtas_elog;
279 spin_lock(&ras_log_buf_lock);
281 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
282 RTAS_VECTOR_EXTERNAL_INTERRUPT,
284 RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
286 rtas_get_error_log_max());
288 rtas_elog = (struct rtas_error_log *)ras_log_buf;
291 rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC)
296 /* format and print the extended information */
297 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
300 pr_emerg("Fatal hardware error detected. Check RTAS error"
301 " log for details. Powering off immediately\n");
305 pr_err("Recoverable hardware error detected\n");
308 spin_unlock(&ras_log_buf_lock);
313 * Some versions of FWNMI place the buffer inside the 4kB page starting at
314 * 0x7000. Other versions place it inside the rtas buffer. We check both.
316 #define VALID_FWNMI_BUFFER(A) \
317 ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
318 (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
321 * Get the error information for errors coming through the
322 * FWNMI vectors. The pt_regs' r3 will be updated to reflect
323 * the actual r3 if possible, and a ptr to the error log entry
324 * will be returned if found.
326 * If the RTAS error is not of the extended type, then we put it in a per
327 * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf.
329 * The global_mce_data_buf does not have any locks or protection around it,
330 * if a second machine check comes in, or a system reset is done
331 * before we have logged the error, then we will get corruption in the
332 * error log. This is preferable over holding off on calling
333 * ibm,nmi-interlock which would result in us checkstopping if a
334 * second machine check did come in.
336 static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
338 unsigned long *savep;
339 struct rtas_error_log *h, *errhdr = NULL;
341 /* Mask top two bits */
342 regs->gpr[3] &= ~(0x3UL << 62);
344 if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
345 printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
349 savep = __va(regs->gpr[3]);
350 regs->gpr[3] = savep[0]; /* restore original r3 */
352 /* If it isn't an extended log we can use the per cpu 64bit buffer */
353 h = (struct rtas_error_log *)&savep[1];
354 if (!rtas_error_extended(h)) {
355 memcpy(this_cpu_ptr(&mce_data_buf), h, sizeof(__u64));
356 errhdr = (struct rtas_error_log *)this_cpu_ptr(&mce_data_buf);
358 int len, error_log_length;
360 error_log_length = 8 + rtas_error_extended_log_length(h);
361 len = max_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
362 memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
363 memcpy(global_mce_data_buf, h, len);
364 errhdr = (struct rtas_error_log *)global_mce_data_buf;
370 /* Call this when done with the data returned by FWNMI_get_errinfo.
371 * It will release the saved data area for other CPUs in the
372 * partition to receive FWNMI errors.
374 static void fwnmi_release_errinfo(void)
376 int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
378 printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
381 int pSeries_system_reset_exception(struct pt_regs *regs)
383 #ifdef __LITTLE_ENDIAN__
385 * Some firmware byteswaps SRR registers and gives incorrect SRR1. Try
386 * to detect the bad SRR1 pattern here. Flip the NIP back to correct
387 * endian for reporting purposes. Unfortunately the MSR can't be fixed,
388 * so clear it. It will be missing MSR_RI so we won't try to recover.
390 if ((be64_to_cpu(regs->msr) &
391 (MSR_LE|MSR_RI|MSR_DR|MSR_IR|MSR_ME|MSR_PR|
392 MSR_ILE|MSR_HV|MSR_SF)) == (MSR_DR|MSR_SF)) {
393 regs->nip = be64_to_cpu((__be64)regs->nip);
399 struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
401 /* XXX Should look at FWNMI information */
403 fwnmi_release_errinfo();
406 if (smp_handle_nmi_ipi(regs))
409 return 0; /* need to perform reset */
413 * See if we can recover from a machine check exception.
414 * This is only called on power4 (or above) and only via
415 * the Firmware Non-Maskable Interrupts (fwnmi) handler
416 * which provides the error analysis for us.
418 * Return 1 if corrected (or delivered a signal).
419 * Return 0 if there is nothing we can do.
421 static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
424 int disposition = rtas_error_disposition(err);
426 if (!(regs->msr & MSR_RI)) {
427 /* If MSR_RI isn't set, we cannot recover */
430 } else if (disposition == RTAS_DISP_FULLY_RECOVERED) {
431 /* Platform corrected itself */
434 } else if (disposition == RTAS_DISP_LIMITED_RECOVERY) {
435 /* Platform corrected itself but could be degraded */
436 printk(KERN_ERR "MCE: limited recovery, system may "
440 } else if (user_mode(regs) && !is_global_init(current) &&
441 rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) {
444 * If we received a synchronous error when in userspace
445 * kill the task. Firmware may report details of the fail
446 * asynchronously, so we can't rely on the target and type
447 * fields being valid here.
449 printk(KERN_ERR "MCE: uncorrectable error, killing task "
450 "%s:%d\n", current->comm, current->pid);
452 _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
456 log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
462 * Handle a machine check.
464 * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
465 * should be present. If so the handler which called us tells us if the
466 * error was recovered (never true if RI=0).
468 * On hardware prior to Power 4 these exceptions were asynchronous which
469 * means we can't tell exactly where it occurred and so we can't recover.
471 int pSeries_machine_check_exception(struct pt_regs *regs)
473 struct rtas_error_log *errp;
476 errp = fwnmi_get_errinfo(regs);
477 fwnmi_release_errinfo();
478 if (errp && recover_mce(regs, errp))