xref: /openbmc/linux/arch/powerpc/platforms/pseries/ras.c (revision b4af279a7cba5cc1f665485e8ecdf272f1ba0cc5)
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 #include <linux/sched.h>
20d9953105SMichael Ellerman #include <linux/interrupt.h>
21d9953105SMichael Ellerman #include <linux/irq.h>
2290128997SAnton Blanchard #include <linux/of.h>
2355fc0c56SAnton Blanchard #include <linux/fs.h>
2455fc0c56SAnton Blanchard #include <linux/reboot.h>
25d9953105SMichael Ellerman 
26d9953105SMichael Ellerman #include <asm/machdep.h>
27d9953105SMichael Ellerman #include <asm/rtas.h>
288c4f1f29SMichael Ellerman #include <asm/firmware.h>
29d9953105SMichael Ellerman 
30577830b0SMichael Ellerman #include "pseries.h"
31c902be71SArnd Bergmann 
32d9953105SMichael Ellerman static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
33d9953105SMichael Ellerman static DEFINE_SPINLOCK(ras_log_buf_lock);
34d9953105SMichael Ellerman 
35d368514cSAnton Blanchard static char global_mce_data_buf[RTAS_ERROR_LOG_MAX];
36d368514cSAnton Blanchard static DEFINE_PER_CPU(__u64, mce_data_buf);
37d9953105SMichael Ellerman 
38d9953105SMichael Ellerman static int ras_check_exception_token;
39d9953105SMichael Ellerman 
40d9953105SMichael Ellerman #define EPOW_SENSOR_TOKEN	9
41d9953105SMichael Ellerman #define EPOW_SENSOR_INDEX	0
42d9953105SMichael Ellerman 
43*b4af279aSVipin K Parashar /* EPOW events counter variable */
44*b4af279aSVipin K Parashar static int num_epow_events;
45*b4af279aSVipin K Parashar 
467d12e780SDavid Howells static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
477d12e780SDavid Howells static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
48d9953105SMichael Ellerman 
490ebfff14SBenjamin Herrenschmidt 
50d9953105SMichael Ellerman /*
51d9953105SMichael Ellerman  * Initialize handlers for the set of interrupts caused by hardware errors
52d9953105SMichael Ellerman  * and power system events.
53d9953105SMichael Ellerman  */
54d9953105SMichael Ellerman static int __init init_ras_IRQ(void)
55d9953105SMichael Ellerman {
56d9953105SMichael Ellerman 	struct device_node *np;
57d9953105SMichael Ellerman 
58d9953105SMichael Ellerman 	ras_check_exception_token = rtas_token("check-exception");
59d9953105SMichael Ellerman 
60d9953105SMichael Ellerman 	/* Internal Errors */
61d9953105SMichael Ellerman 	np = of_find_node_by_path("/event-sources/internal-errors");
62d9953105SMichael Ellerman 	if (np != NULL) {
6332c96f77SMark Nelson 		request_event_sources_irqs(np, ras_error_interrupt,
6432c96f77SMark Nelson 					   "RAS_ERROR");
65d9953105SMichael Ellerman 		of_node_put(np);
66d9953105SMichael Ellerman 	}
67d9953105SMichael Ellerman 
68d9953105SMichael Ellerman 	/* EPOW Events */
69d9953105SMichael Ellerman 	np = of_find_node_by_path("/event-sources/epow-events");
70d9953105SMichael Ellerman 	if (np != NULL) {
7132c96f77SMark Nelson 		request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
72d9953105SMichael Ellerman 		of_node_put(np);
73d9953105SMichael Ellerman 	}
74d9953105SMichael Ellerman 
7569ed3324SAnton Blanchard 	return 0;
76d9953105SMichael Ellerman }
778e83e905SMichael Ellerman machine_subsys_initcall(pseries, init_ras_IRQ);
78d9953105SMichael Ellerman 
7955fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_NORMAL				1
8055fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_ON_UPS				2
8155fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS	3
8255fc0c56SAnton Blanchard #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH	4
8355fc0c56SAnton Blanchard 
8455fc0c56SAnton Blanchard static void handle_system_shutdown(char event_modifier)
8555fc0c56SAnton Blanchard {
8655fc0c56SAnton Blanchard 	switch (event_modifier) {
8755fc0c56SAnton Blanchard 	case EPOW_SHUTDOWN_NORMAL:
88*b4af279aSVipin K Parashar 		pr_emerg("Power off requested\n");
891b7e0cbeSliguang 		orderly_poweroff(true);
9055fc0c56SAnton Blanchard 		break;
9155fc0c56SAnton Blanchard 
9255fc0c56SAnton Blanchard 	case EPOW_SHUTDOWN_ON_UPS:
93*b4af279aSVipin K Parashar 		pr_emerg("Loss of system power detected. System is running on"
94*b4af279aSVipin K Parashar 			 " UPS/battery. Check RTAS error log for details\n");
9579872e35SAnshuman Khandual 		orderly_poweroff(true);
9655fc0c56SAnton Blanchard 		break;
9755fc0c56SAnton Blanchard 
9855fc0c56SAnton Blanchard 	case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
99*b4af279aSVipin K Parashar 		pr_emerg("Loss of system critical functions detected. Check"
100*b4af279aSVipin K Parashar 			 " RTAS error log for details\n");
1011b7e0cbeSliguang 		orderly_poweroff(true);
10255fc0c56SAnton Blanchard 		break;
10355fc0c56SAnton Blanchard 
10455fc0c56SAnton Blanchard 	case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
105*b4af279aSVipin K Parashar 		pr_emerg("High ambient temperature detected. Check RTAS"
106*b4af279aSVipin K Parashar 			 " error log for details\n");
1071b7e0cbeSliguang 		orderly_poweroff(true);
10855fc0c56SAnton Blanchard 		break;
10955fc0c56SAnton Blanchard 
11055fc0c56SAnton Blanchard 	default:
111*b4af279aSVipin K Parashar 		pr_err("Unknown power/cooling shutdown event (modifier = %d)\n",
11255fc0c56SAnton Blanchard 			event_modifier);
11355fc0c56SAnton Blanchard 	}
11455fc0c56SAnton Blanchard }
11555fc0c56SAnton Blanchard 
11655fc0c56SAnton Blanchard struct epow_errorlog {
11755fc0c56SAnton Blanchard 	unsigned char sensor_value;
11855fc0c56SAnton Blanchard 	unsigned char event_modifier;
11955fc0c56SAnton Blanchard 	unsigned char extended_modifier;
12055fc0c56SAnton Blanchard 	unsigned char reserved;
12155fc0c56SAnton Blanchard 	unsigned char platform_reason;
12255fc0c56SAnton Blanchard };
12355fc0c56SAnton Blanchard 
12455fc0c56SAnton Blanchard #define EPOW_RESET			0
12555fc0c56SAnton Blanchard #define EPOW_WARN_COOLING		1
12655fc0c56SAnton Blanchard #define EPOW_WARN_POWER			2
12755fc0c56SAnton Blanchard #define EPOW_SYSTEM_SHUTDOWN		3
12855fc0c56SAnton Blanchard #define EPOW_SYSTEM_HALT		4
12955fc0c56SAnton Blanchard #define EPOW_MAIN_ENCLOSURE		5
13055fc0c56SAnton Blanchard #define EPOW_POWER_OFF			7
13155fc0c56SAnton Blanchard 
132e51df2c1SAnton Blanchard static void rtas_parse_epow_errlog(struct rtas_error_log *log)
13355fc0c56SAnton Blanchard {
13455fc0c56SAnton Blanchard 	struct pseries_errorlog *pseries_log;
13555fc0c56SAnton Blanchard 	struct epow_errorlog *epow_log;
13655fc0c56SAnton Blanchard 	char action_code;
13755fc0c56SAnton Blanchard 	char modifier;
13855fc0c56SAnton Blanchard 
13955fc0c56SAnton Blanchard 	pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
14055fc0c56SAnton Blanchard 	if (pseries_log == NULL)
14155fc0c56SAnton Blanchard 		return;
14255fc0c56SAnton Blanchard 
14355fc0c56SAnton Blanchard 	epow_log = (struct epow_errorlog *)pseries_log->data;
14455fc0c56SAnton Blanchard 	action_code = epow_log->sensor_value & 0xF;	/* bottom 4 bits */
14555fc0c56SAnton Blanchard 	modifier = epow_log->event_modifier & 0xF;	/* bottom 4 bits */
14655fc0c56SAnton Blanchard 
14755fc0c56SAnton Blanchard 	switch (action_code) {
14855fc0c56SAnton Blanchard 	case EPOW_RESET:
149*b4af279aSVipin K Parashar 		if (num_epow_events) {
150*b4af279aSVipin K Parashar 			pr_info("Non critical power/cooling issue cleared\n");
151*b4af279aSVipin K Parashar 			num_epow_events--;
152*b4af279aSVipin K Parashar 		}
15355fc0c56SAnton Blanchard 		break;
15455fc0c56SAnton Blanchard 
15555fc0c56SAnton Blanchard 	case EPOW_WARN_COOLING:
156*b4af279aSVipin K Parashar 		pr_info("Non-critical cooling issue detected. Check RTAS error"
157*b4af279aSVipin K Parashar 			" log for details\n");
15855fc0c56SAnton Blanchard 		break;
15955fc0c56SAnton Blanchard 
16055fc0c56SAnton Blanchard 	case EPOW_WARN_POWER:
161*b4af279aSVipin K Parashar 		pr_info("Non-critical power issue detected. Check RTAS error"
162*b4af279aSVipin K Parashar 			" log for details\n");
16355fc0c56SAnton Blanchard 		break;
16455fc0c56SAnton Blanchard 
16555fc0c56SAnton Blanchard 	case EPOW_SYSTEM_SHUTDOWN:
16655fc0c56SAnton Blanchard 		handle_system_shutdown(epow_log->event_modifier);
16755fc0c56SAnton Blanchard 		break;
16855fc0c56SAnton Blanchard 
16955fc0c56SAnton Blanchard 	case EPOW_SYSTEM_HALT:
170*b4af279aSVipin K Parashar 		pr_emerg("Critical power/cooling issue detected. Check RTAS"
171*b4af279aSVipin K Parashar 			 " error log for details. Powering off.\n");
1721b7e0cbeSliguang 		orderly_poweroff(true);
17355fc0c56SAnton Blanchard 		break;
17455fc0c56SAnton Blanchard 
17555fc0c56SAnton Blanchard 	case EPOW_MAIN_ENCLOSURE:
17655fc0c56SAnton Blanchard 	case EPOW_POWER_OFF:
177*b4af279aSVipin K Parashar 		pr_emerg("System about to lose power. Check RTAS error log "
178*b4af279aSVipin K Parashar 			 " for details. Powering off immediately.\n");
17955fc0c56SAnton Blanchard 		emergency_sync();
18055fc0c56SAnton Blanchard 		kernel_power_off();
18155fc0c56SAnton Blanchard 		break;
18255fc0c56SAnton Blanchard 
18355fc0c56SAnton Blanchard 	default:
184*b4af279aSVipin K Parashar 		pr_err("Unknown power/cooling event (action code  = %d)\n",
18555fc0c56SAnton Blanchard 			action_code);
18655fc0c56SAnton Blanchard 	}
187*b4af279aSVipin K Parashar 
188*b4af279aSVipin K Parashar 	/* Increment epow events counter variable */
189*b4af279aSVipin K Parashar 	if (action_code != EPOW_RESET)
190*b4af279aSVipin K Parashar 		num_epow_events++;
19155fc0c56SAnton Blanchard }
19255fc0c56SAnton Blanchard 
19355fc0c56SAnton Blanchard /* Handle environmental and power warning (EPOW) interrupts. */
1947d12e780SDavid Howells static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
195d9953105SMichael Ellerman {
19655fc0c56SAnton Blanchard 	int status;
19755fc0c56SAnton Blanchard 	int state;
198d9953105SMichael Ellerman 	int critical;
199d9953105SMichael Ellerman 
2001c2cb594SThomas Huth 	status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
2011c2cb594SThomas Huth 				      &state);
202d9953105SMichael Ellerman 
203d9953105SMichael Ellerman 	if (state > 3)
204d9953105SMichael Ellerman 		critical = 1;		/* Time Critical */
205d9953105SMichael Ellerman 	else
206d9953105SMichael Ellerman 		critical = 0;
207d9953105SMichael Ellerman 
208d9953105SMichael Ellerman 	spin_lock(&ras_log_buf_lock);
209d9953105SMichael Ellerman 
210d9953105SMichael Ellerman 	status = rtas_call(ras_check_exception_token, 6, 1, NULL,
211b08e281bSMark Nelson 			   RTAS_VECTOR_EXTERNAL_INTERRUPT,
212476eb491SGrant Likely 			   virq_to_hw(irq),
2136f43747fSAnton Blanchard 			   RTAS_EPOW_WARNING,
214d9953105SMichael Ellerman 			   critical, __pa(&ras_log_buf),
215d9953105SMichael Ellerman 				rtas_get_error_log_max());
216d9953105SMichael Ellerman 
217d9953105SMichael Ellerman 	log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
218d9953105SMichael Ellerman 
21955fc0c56SAnton Blanchard 	rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
22055fc0c56SAnton Blanchard 
221d9953105SMichael Ellerman 	spin_unlock(&ras_log_buf_lock);
222d9953105SMichael Ellerman 	return IRQ_HANDLED;
223d9953105SMichael Ellerman }
224d9953105SMichael Ellerman 
225d9953105SMichael Ellerman /*
226d9953105SMichael Ellerman  * Handle hardware error interrupts.
227d9953105SMichael Ellerman  *
228d9953105SMichael Ellerman  * RTAS check-exception is called to collect data on the exception.  If
229d9953105SMichael Ellerman  * the error is deemed recoverable, we log a warning and return.
230d9953105SMichael Ellerman  * For nonrecoverable errors, an error is logged and we stop all processing
231d9953105SMichael Ellerman  * as quickly as possible in order to prevent propagation of the failure.
232d9953105SMichael Ellerman  */
2337d12e780SDavid Howells static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
234d9953105SMichael Ellerman {
235d9953105SMichael Ellerman 	struct rtas_error_log *rtas_elog;
236cc8b5263SAnton Blanchard 	int status;
237d9953105SMichael Ellerman 	int fatal;
238d9953105SMichael Ellerman 
239d9953105SMichael Ellerman 	spin_lock(&ras_log_buf_lock);
240d9953105SMichael Ellerman 
241d9953105SMichael Ellerman 	status = rtas_call(ras_check_exception_token, 6, 1, NULL,
242b08e281bSMark Nelson 			   RTAS_VECTOR_EXTERNAL_INTERRUPT,
243476eb491SGrant Likely 			   virq_to_hw(irq),
244d9953105SMichael Ellerman 			   RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
245d9953105SMichael Ellerman 			   __pa(&ras_log_buf),
246d9953105SMichael Ellerman 				rtas_get_error_log_max());
247d9953105SMichael Ellerman 
248d9953105SMichael Ellerman 	rtas_elog = (struct rtas_error_log *)ras_log_buf;
249d9953105SMichael Ellerman 
250a08a53eaSGreg Kurz 	if (status == 0 &&
251a08a53eaSGreg Kurz 	    rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC)
252d9953105SMichael Ellerman 		fatal = 1;
253d9953105SMichael Ellerman 	else
254d9953105SMichael Ellerman 		fatal = 0;
255d9953105SMichael Ellerman 
256d9953105SMichael Ellerman 	/* format and print the extended information */
257d9953105SMichael Ellerman 	log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
258d9953105SMichael Ellerman 
259d9953105SMichael Ellerman 	if (fatal) {
260*b4af279aSVipin K Parashar 		pr_emerg("Fatal hardware error detected. Check RTAS error"
261*b4af279aSVipin K Parashar 			 " log for details. Powering off immediately\n");
262cc8b5263SAnton Blanchard 		emergency_sync();
263cc8b5263SAnton Blanchard 		kernel_power_off();
264d9953105SMichael Ellerman 	} else {
265*b4af279aSVipin K Parashar 		pr_err("Recoverable hardware error detected\n");
266d9953105SMichael Ellerman 	}
267d9953105SMichael Ellerman 
268d9953105SMichael Ellerman 	spin_unlock(&ras_log_buf_lock);
269d9953105SMichael Ellerman 	return IRQ_HANDLED;
270d9953105SMichael Ellerman }
271d9953105SMichael Ellerman 
272d368514cSAnton Blanchard /*
273d368514cSAnton Blanchard  * Some versions of FWNMI place the buffer inside the 4kB page starting at
274d368514cSAnton Blanchard  * 0x7000. Other versions place it inside the rtas buffer. We check both.
275d368514cSAnton Blanchard  */
276d368514cSAnton Blanchard #define VALID_FWNMI_BUFFER(A) \
277d368514cSAnton Blanchard 	((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
278d368514cSAnton Blanchard 	(((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
279d368514cSAnton Blanchard 
280d368514cSAnton Blanchard /*
281d368514cSAnton Blanchard  * Get the error information for errors coming through the
282d9953105SMichael Ellerman  * FWNMI vectors.  The pt_regs' r3 will be updated to reflect
283d9953105SMichael Ellerman  * the actual r3 if possible, and a ptr to the error log entry
284d9953105SMichael Ellerman  * will be returned if found.
285d9953105SMichael Ellerman  *
286d368514cSAnton Blanchard  * If the RTAS error is not of the extended type, then we put it in a per
287d368514cSAnton Blanchard  * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf.
288d368514cSAnton Blanchard  *
289d368514cSAnton Blanchard  * The global_mce_data_buf does not have any locks or protection around it,
290d9953105SMichael Ellerman  * if a second machine check comes in, or a system reset is done
291d9953105SMichael Ellerman  * before we have logged the error, then we will get corruption in the
292d9953105SMichael Ellerman  * error log.  This is preferable over holding off on calling
293d9953105SMichael Ellerman  * ibm,nmi-interlock which would result in us checkstopping if a
294d9953105SMichael Ellerman  * second machine check did come in.
295d9953105SMichael Ellerman  */
296d9953105SMichael Ellerman static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
297d9953105SMichael Ellerman {
298d9953105SMichael Ellerman 	unsigned long *savep;
299d368514cSAnton Blanchard 	struct rtas_error_log *h, *errhdr = NULL;
300d9953105SMichael Ellerman 
301ee1dd1e3SMahesh Salgaonkar 	/* Mask top two bits */
302ee1dd1e3SMahesh Salgaonkar 	regs->gpr[3] &= ~(0x3UL << 62);
303ee1dd1e3SMahesh Salgaonkar 
304d368514cSAnton Blanchard 	if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
305f0e939aeSAnton Blanchard 		printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
306d368514cSAnton Blanchard 		return NULL;
307d9953105SMichael Ellerman 	}
308d368514cSAnton Blanchard 
309d368514cSAnton Blanchard 	savep = __va(regs->gpr[3]);
310d368514cSAnton Blanchard 	regs->gpr[3] = savep[0];	/* restore original r3 */
311d368514cSAnton Blanchard 
312d368514cSAnton Blanchard 	/* If it isn't an extended log we can use the per cpu 64bit buffer */
313d368514cSAnton Blanchard 	h = (struct rtas_error_log *)&savep[1];
314a08a53eaSGreg Kurz 	if (!rtas_error_extended(h)) {
31569111bacSChristoph Lameter 		memcpy(this_cpu_ptr(&mce_data_buf), h, sizeof(__u64));
31669111bacSChristoph Lameter 		errhdr = (struct rtas_error_log *)this_cpu_ptr(&mce_data_buf);
317d368514cSAnton Blanchard 	} else {
318a08a53eaSGreg Kurz 		int len, error_log_length;
319d368514cSAnton Blanchard 
320a08a53eaSGreg Kurz 		error_log_length = 8 + rtas_error_extended_log_length(h);
321a08a53eaSGreg Kurz 		len = max_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
322d368514cSAnton Blanchard 		memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
323d368514cSAnton Blanchard 		memcpy(global_mce_data_buf, h, len);
324d368514cSAnton Blanchard 		errhdr = (struct rtas_error_log *)global_mce_data_buf;
325d368514cSAnton Blanchard 	}
326d368514cSAnton Blanchard 
327d9953105SMichael Ellerman 	return errhdr;
328d9953105SMichael Ellerman }
329d9953105SMichael Ellerman 
330d9953105SMichael Ellerman /* Call this when done with the data returned by FWNMI_get_errinfo.
331d9953105SMichael Ellerman  * It will release the saved data area for other CPUs in the
332d9953105SMichael Ellerman  * partition to receive FWNMI errors.
333d9953105SMichael Ellerman  */
334d9953105SMichael Ellerman static void fwnmi_release_errinfo(void)
335d9953105SMichael Ellerman {
336d9953105SMichael Ellerman 	int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
337d9953105SMichael Ellerman 	if (ret != 0)
338d368514cSAnton Blanchard 		printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
339d9953105SMichael Ellerman }
340d9953105SMichael Ellerman 
341c902be71SArnd Bergmann int pSeries_system_reset_exception(struct pt_regs *regs)
342d9953105SMichael Ellerman {
343d9953105SMichael Ellerman 	if (fwnmi_active) {
344d9953105SMichael Ellerman 		struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
345d9953105SMichael Ellerman 		if (errhdr) {
346d9953105SMichael Ellerman 			/* XXX Should look at FWNMI information */
347d9953105SMichael Ellerman 		}
348d9953105SMichael Ellerman 		fwnmi_release_errinfo();
349d9953105SMichael Ellerman 	}
350c902be71SArnd Bergmann 	return 0; /* need to perform reset */
351d9953105SMichael Ellerman }
352d9953105SMichael Ellerman 
353d9953105SMichael Ellerman /*
354d9953105SMichael Ellerman  * See if we can recover from a machine check exception.
355d9953105SMichael Ellerman  * This is only called on power4 (or above) and only via
356d9953105SMichael Ellerman  * the Firmware Non-Maskable Interrupts (fwnmi) handler
357d9953105SMichael Ellerman  * which provides the error analysis for us.
358d9953105SMichael Ellerman  *
359d9953105SMichael Ellerman  * Return 1 if corrected (or delivered a signal).
360d9953105SMichael Ellerman  * Return 0 if there is nothing we can do.
361d9953105SMichael Ellerman  */
362d9953105SMichael Ellerman static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
363d9953105SMichael Ellerman {
364d47d1d8aSAnton Blanchard 	int recovered = 0;
365a08a53eaSGreg Kurz 	int disposition = rtas_error_disposition(err);
366d9953105SMichael Ellerman 
367d47d1d8aSAnton Blanchard 	if (!(regs->msr & MSR_RI)) {
368d47d1d8aSAnton Blanchard 		/* If MSR_RI isn't set, we cannot recover */
369d47d1d8aSAnton Blanchard 		recovered = 0;
370d47d1d8aSAnton Blanchard 
371a08a53eaSGreg Kurz 	} else if (disposition == RTAS_DISP_FULLY_RECOVERED) {
372d9953105SMichael Ellerman 		/* Platform corrected itself */
373d47d1d8aSAnton Blanchard 		recovered = 1;
374d47d1d8aSAnton Blanchard 
375a08a53eaSGreg Kurz 	} else if (disposition == RTAS_DISP_LIMITED_RECOVERY) {
376d47d1d8aSAnton Blanchard 		/* Platform corrected itself but could be degraded */
377d47d1d8aSAnton Blanchard 		printk(KERN_ERR "MCE: limited recovery, system may "
378d47d1d8aSAnton Blanchard 		       "be degraded\n");
379d47d1d8aSAnton Blanchard 		recovered = 1;
380d47d1d8aSAnton Blanchard 
381d47d1d8aSAnton Blanchard 	} else if (user_mode(regs) && !is_global_init(current) &&
382a08a53eaSGreg Kurz 		   rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) {
383d47d1d8aSAnton Blanchard 
384d47d1d8aSAnton Blanchard 		/*
385d47d1d8aSAnton Blanchard 		 * If we received a synchronous error when in userspace
386d47d1d8aSAnton Blanchard 		 * kill the task. Firmware may report details of the fail
387d47d1d8aSAnton Blanchard 		 * asynchronously, so we can't rely on the target and type
388d47d1d8aSAnton Blanchard 		 * fields being valid here.
389d47d1d8aSAnton Blanchard 		 */
390d47d1d8aSAnton Blanchard 		printk(KERN_ERR "MCE: uncorrectable error, killing task "
391d47d1d8aSAnton Blanchard 		       "%s:%d\n", current->comm, current->pid);
392d47d1d8aSAnton Blanchard 
393d47d1d8aSAnton Blanchard 		_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
394d47d1d8aSAnton Blanchard 		recovered = 1;
395d9953105SMichael Ellerman 	}
396d9953105SMichael Ellerman 
3973f9793e6SAnton Blanchard 	log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
398d9953105SMichael Ellerman 
399d47d1d8aSAnton Blanchard 	return recovered;
400d9953105SMichael Ellerman }
401d9953105SMichael Ellerman 
402d9953105SMichael Ellerman /*
403d9953105SMichael Ellerman  * Handle a machine check.
404d9953105SMichael Ellerman  *
405d9953105SMichael Ellerman  * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
406d9953105SMichael Ellerman  * should be present.  If so the handler which called us tells us if the
407d9953105SMichael Ellerman  * error was recovered (never true if RI=0).
408d9953105SMichael Ellerman  *
409d9953105SMichael Ellerman  * On hardware prior to Power 4 these exceptions were asynchronous which
410d9953105SMichael Ellerman  * means we can't tell exactly where it occurred and so we can't recover.
411d9953105SMichael Ellerman  */
412d9953105SMichael Ellerman int pSeries_machine_check_exception(struct pt_regs *regs)
413d9953105SMichael Ellerman {
414d9953105SMichael Ellerman 	struct rtas_error_log *errp;
415d9953105SMichael Ellerman 
416d9953105SMichael Ellerman 	if (fwnmi_active) {
417d9953105SMichael Ellerman 		errp = fwnmi_get_errinfo(regs);
418d9953105SMichael Ellerman 		fwnmi_release_errinfo();
419d9953105SMichael Ellerman 		if (errp && recover_mce(regs, errp))
420d9953105SMichael Ellerman 			return 1;
421d9953105SMichael Ellerman 	}
422d9953105SMichael Ellerman 
423d9953105SMichael Ellerman 	return 0;
424d9953105SMichael Ellerman }
425