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
20 * 2001/09/21 : engebret : Created with minimal EPOW and HW exception support.
24 #include <linux/errno.h>
25 #include <linux/threads.h>
26 #include <linux/kernel_stat.h>
27 #include <linux/signal.h>
28 #include <linux/sched.h>
29 #include <linux/ioport.h>
30 #include <linux/interrupt.h>
31 #include <linux/timex.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/irq.h>
35 #include <linux/random.h>
36 #include <linux/sysrq.h>
37 #include <linux/bitops.h>
39 #include <linux/reboot.h>
41 #include <asm/uaccess.h>
42 #include <asm/system.h>
44 #include <asm/pgtable.h>
46 #include <asm/cache.h>
48 #include <asm/ptrace.h>
49 #include <asm/machdep.h>
52 #include <asm/firmware.h>
56 static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
57 static DEFINE_SPINLOCK(ras_log_buf_lock);
59 static char global_mce_data_buf[RTAS_ERROR_LOG_MAX];
60 static DEFINE_PER_CPU(__u64, mce_data_buf);
62 static int ras_check_exception_token;
64 #define EPOW_SENSOR_TOKEN 9
65 #define EPOW_SENSOR_INDEX 0
67 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
68 static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
72 * Initialize handlers for the set of interrupts caused by hardware errors
73 * and power system events.
75 static int __init init_ras_IRQ(void)
77 struct device_node *np;
79 ras_check_exception_token = rtas_token("check-exception");
82 np = of_find_node_by_path("/event-sources/internal-errors");
84 request_event_sources_irqs(np, ras_error_interrupt,
90 np = of_find_node_by_path("/event-sources/epow-events");
92 request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
98 subsys_initcall(init_ras_IRQ);
100 #define EPOW_SHUTDOWN_NORMAL 1
101 #define EPOW_SHUTDOWN_ON_UPS 2
102 #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3
103 #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4
105 static void handle_system_shutdown(char event_modifier)
107 switch (event_modifier) {
108 case EPOW_SHUTDOWN_NORMAL:
109 pr_emerg("Firmware initiated power off");
113 case EPOW_SHUTDOWN_ON_UPS:
114 pr_emerg("Loss of power reported by firmware, system is "
115 "running on UPS/battery");
118 case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
119 pr_emerg("Loss of system critical functions reported by "
121 pr_emerg("Check RTAS error log for details");
125 case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
126 pr_emerg("Ambient temperature too high reported by firmware");
127 pr_emerg("Check RTAS error log for details");
132 pr_err("Unknown power/cooling shutdown event (modifier %d)",
137 struct epow_errorlog {
138 unsigned char sensor_value;
139 unsigned char event_modifier;
140 unsigned char extended_modifier;
141 unsigned char reserved;
142 unsigned char platform_reason;
146 #define EPOW_WARN_COOLING 1
147 #define EPOW_WARN_POWER 2
148 #define EPOW_SYSTEM_SHUTDOWN 3
149 #define EPOW_SYSTEM_HALT 4
150 #define EPOW_MAIN_ENCLOSURE 5
151 #define EPOW_POWER_OFF 7
153 void rtas_parse_epow_errlog(struct rtas_error_log *log)
155 struct pseries_errorlog *pseries_log;
156 struct epow_errorlog *epow_log;
160 pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
161 if (pseries_log == NULL)
164 epow_log = (struct epow_errorlog *)pseries_log->data;
165 action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */
166 modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */
168 switch (action_code) {
170 pr_err("Non critical power or cooling issue cleared");
173 case EPOW_WARN_COOLING:
174 pr_err("Non critical cooling issue reported by firmware");
175 pr_err("Check RTAS error log for details");
178 case EPOW_WARN_POWER:
179 pr_err("Non critical power issue reported by firmware");
180 pr_err("Check RTAS error log for details");
183 case EPOW_SYSTEM_SHUTDOWN:
184 handle_system_shutdown(epow_log->event_modifier);
187 case EPOW_SYSTEM_HALT:
188 pr_emerg("Firmware initiated power off");
192 case EPOW_MAIN_ENCLOSURE:
194 pr_emerg("Critical power/cooling issue reported by firmware");
195 pr_emerg("Check RTAS error log for details");
196 pr_emerg("Immediate power off");
202 pr_err("Unknown power/cooling event (action code %d)",
207 /* Handle environmental and power warning (EPOW) interrupts. */
208 static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
214 status = rtas_get_sensor(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, &state);
217 critical = 1; /* Time Critical */
221 spin_lock(&ras_log_buf_lock);
223 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
224 RTAS_VECTOR_EXTERNAL_INTERRUPT,
227 critical, __pa(&ras_log_buf),
228 rtas_get_error_log_max());
230 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
232 rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
234 spin_unlock(&ras_log_buf_lock);
239 * Handle hardware error interrupts.
241 * RTAS check-exception is called to collect data on the exception. If
242 * the error is deemed recoverable, we log a warning and return.
243 * For nonrecoverable errors, an error is logged and we stop all processing
244 * as quickly as possible in order to prevent propagation of the failure.
246 static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
248 struct rtas_error_log *rtas_elog;
252 spin_lock(&ras_log_buf_lock);
254 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
255 RTAS_VECTOR_EXTERNAL_INTERRUPT,
257 RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
259 rtas_get_error_log_max());
261 rtas_elog = (struct rtas_error_log *)ras_log_buf;
263 if ((status == 0) && (rtas_elog->severity >= RTAS_SEVERITY_ERROR_SYNC))
268 /* format and print the extended information */
269 log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
272 pr_emerg("Fatal hardware error reported by firmware");
273 pr_emerg("Check RTAS error log for details");
274 pr_emerg("Immediate power off");
278 pr_err("Recoverable hardware error reported by firmware");
281 spin_unlock(&ras_log_buf_lock);
286 * Some versions of FWNMI place the buffer inside the 4kB page starting at
287 * 0x7000. Other versions place it inside the rtas buffer. We check both.
289 #define VALID_FWNMI_BUFFER(A) \
290 ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
291 (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
294 * Get the error information for errors coming through the
295 * FWNMI vectors. The pt_regs' r3 will be updated to reflect
296 * the actual r3 if possible, and a ptr to the error log entry
297 * will be returned if found.
299 * If the RTAS error is not of the extended type, then we put it in a per
300 * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf.
302 * The global_mce_data_buf does not have any locks or protection around it,
303 * if a second machine check comes in, or a system reset is done
304 * before we have logged the error, then we will get corruption in the
305 * error log. This is preferable over holding off on calling
306 * ibm,nmi-interlock which would result in us checkstopping if a
307 * second machine check did come in.
309 static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
311 unsigned long *savep;
312 struct rtas_error_log *h, *errhdr = NULL;
314 if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
315 printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
319 savep = __va(regs->gpr[3]);
320 regs->gpr[3] = savep[0]; /* restore original r3 */
322 /* If it isn't an extended log we can use the per cpu 64bit buffer */
323 h = (struct rtas_error_log *)&savep[1];
325 memcpy(&__get_cpu_var(mce_data_buf), h, sizeof(__u64));
326 errhdr = (struct rtas_error_log *)&__get_cpu_var(mce_data_buf);
330 len = max_t(int, 8+h->extended_log_length, RTAS_ERROR_LOG_MAX);
331 memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
332 memcpy(global_mce_data_buf, h, len);
333 errhdr = (struct rtas_error_log *)global_mce_data_buf;
339 /* Call this when done with the data returned by FWNMI_get_errinfo.
340 * It will release the saved data area for other CPUs in the
341 * partition to receive FWNMI errors.
343 static void fwnmi_release_errinfo(void)
345 int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
347 printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
350 int pSeries_system_reset_exception(struct pt_regs *regs)
353 struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
355 /* XXX Should look at FWNMI information */
357 fwnmi_release_errinfo();
359 return 0; /* need to perform reset */
363 * See if we can recover from a machine check exception.
364 * This is only called on power4 (or above) and only via
365 * the Firmware Non-Maskable Interrupts (fwnmi) handler
366 * which provides the error analysis for us.
368 * Return 1 if corrected (or delivered a signal).
369 * Return 0 if there is nothing we can do.
371 static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
375 if (!(regs->msr & MSR_RI)) {
376 /* If MSR_RI isn't set, we cannot recover */
379 } else if (err->disposition == RTAS_DISP_FULLY_RECOVERED) {
380 /* Platform corrected itself */
383 } else if (err->disposition == RTAS_DISP_LIMITED_RECOVERY) {
384 /* Platform corrected itself but could be degraded */
385 printk(KERN_ERR "MCE: limited recovery, system may "
389 } else if (user_mode(regs) && !is_global_init(current) &&
390 err->severity == RTAS_SEVERITY_ERROR_SYNC) {
393 * If we received a synchronous error when in userspace
394 * kill the task. Firmware may report details of the fail
395 * asynchronously, so we can't rely on the target and type
396 * fields being valid here.
398 printk(KERN_ERR "MCE: uncorrectable error, killing task "
399 "%s:%d\n", current->comm, current->pid);
401 _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
405 log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
411 * Handle a machine check.
413 * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
414 * should be present. If so the handler which called us tells us if the
415 * error was recovered (never true if RI=0).
417 * On hardware prior to Power 4 these exceptions were asynchronous which
418 * means we can't tell exactly where it occurred and so we can't recover.
420 int pSeries_machine_check_exception(struct pt_regs *regs)
422 struct rtas_error_log *errp;
425 errp = fwnmi_get_errinfo(regs);
426 fwnmi_release_errinfo();
427 if (errp && recover_mce(regs, errp))