]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 | 2 | * Copyright (C) 2001 Dave Engebretsen IBM Corporation |
d9953105 | 3 | * |
1da177e4 LT |
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. | |
d9953105 | 8 | * |
1da177e4 LT |
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. | |
d9953105 | 13 | * |
1da177e4 LT |
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 | |
17 | */ | |
18 | ||
1da177e4 | 19 | #include <linux/sched.h> |
1da177e4 | 20 | #include <linux/interrupt.h> |
1da177e4 | 21 | #include <linux/irq.h> |
90128997 | 22 | #include <linux/of.h> |
55fc0c56 AB |
23 | #include <linux/fs.h> |
24 | #include <linux/reboot.h> | |
1da177e4 | 25 | |
1da177e4 LT |
26 | #include <asm/machdep.h> |
27 | #include <asm/rtas.h> | |
8c4f1f29 | 28 | #include <asm/firmware.h> |
1da177e4 | 29 | |
577830b0 | 30 | #include "pseries.h" |
c902be71 | 31 | |
1da177e4 LT |
32 | static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX]; |
33 | static DEFINE_SPINLOCK(ras_log_buf_lock); | |
34 | ||
d368514c AB |
35 | static char global_mce_data_buf[RTAS_ERROR_LOG_MAX]; |
36 | static DEFINE_PER_CPU(__u64, mce_data_buf); | |
1da177e4 | 37 | |
1da177e4 LT |
38 | static int ras_check_exception_token; |
39 | ||
40 | #define EPOW_SENSOR_TOKEN 9 | |
41 | #define EPOW_SENSOR_INDEX 0 | |
1da177e4 | 42 | |
7d12e780 DH |
43 | static irqreturn_t ras_epow_interrupt(int irq, void *dev_id); |
44 | static irqreturn_t ras_error_interrupt(int irq, void *dev_id); | |
1da177e4 | 45 | |
0ebfff14 | 46 | |
1da177e4 LT |
47 | /* |
48 | * Initialize handlers for the set of interrupts caused by hardware errors | |
49 | * and power system events. | |
50 | */ | |
51 | static int __init init_ras_IRQ(void) | |
52 | { | |
53 | struct device_node *np; | |
54 | ||
1da177e4 LT |
55 | ras_check_exception_token = rtas_token("check-exception"); |
56 | ||
57 | /* Internal Errors */ | |
58 | np = of_find_node_by_path("/event-sources/internal-errors"); | |
59 | if (np != NULL) { | |
32c96f77 MN |
60 | request_event_sources_irqs(np, ras_error_interrupt, |
61 | "RAS_ERROR"); | |
1da177e4 LT |
62 | of_node_put(np); |
63 | } | |
64 | ||
65 | /* EPOW Events */ | |
66 | np = of_find_node_by_path("/event-sources/epow-events"); | |
67 | if (np != NULL) { | |
32c96f77 | 68 | request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW"); |
1da177e4 LT |
69 | of_node_put(np); |
70 | } | |
71 | ||
69ed3324 | 72 | return 0; |
1da177e4 | 73 | } |
8e83e905 | 74 | machine_subsys_initcall(pseries, init_ras_IRQ); |
1da177e4 | 75 | |
55fc0c56 AB |
76 | #define EPOW_SHUTDOWN_NORMAL 1 |
77 | #define EPOW_SHUTDOWN_ON_UPS 2 | |
78 | #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3 | |
79 | #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4 | |
80 | ||
81 | static void handle_system_shutdown(char event_modifier) | |
82 | { | |
83 | switch (event_modifier) { | |
84 | case EPOW_SHUTDOWN_NORMAL: | |
85 | pr_emerg("Firmware initiated power off"); | |
1b7e0cbe | 86 | orderly_poweroff(true); |
55fc0c56 AB |
87 | break; |
88 | ||
89 | case EPOW_SHUTDOWN_ON_UPS: | |
90 | pr_emerg("Loss of power reported by firmware, system is " | |
91 | "running on UPS/battery"); | |
79872e35 AK |
92 | pr_emerg("Check RTAS error log for details"); |
93 | orderly_poweroff(true); | |
55fc0c56 AB |
94 | break; |
95 | ||
96 | case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS: | |
97 | pr_emerg("Loss of system critical functions reported by " | |
98 | "firmware"); | |
99 | pr_emerg("Check RTAS error log for details"); | |
1b7e0cbe | 100 | orderly_poweroff(true); |
55fc0c56 AB |
101 | break; |
102 | ||
103 | case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH: | |
104 | pr_emerg("Ambient temperature too high reported by firmware"); | |
105 | pr_emerg("Check RTAS error log for details"); | |
1b7e0cbe | 106 | orderly_poweroff(true); |
55fc0c56 AB |
107 | break; |
108 | ||
109 | default: | |
110 | pr_err("Unknown power/cooling shutdown event (modifier %d)", | |
111 | event_modifier); | |
112 | } | |
113 | } | |
114 | ||
115 | struct epow_errorlog { | |
116 | unsigned char sensor_value; | |
117 | unsigned char event_modifier; | |
118 | unsigned char extended_modifier; | |
119 | unsigned char reserved; | |
120 | unsigned char platform_reason; | |
121 | }; | |
122 | ||
123 | #define EPOW_RESET 0 | |
124 | #define EPOW_WARN_COOLING 1 | |
125 | #define EPOW_WARN_POWER 2 | |
126 | #define EPOW_SYSTEM_SHUTDOWN 3 | |
127 | #define EPOW_SYSTEM_HALT 4 | |
128 | #define EPOW_MAIN_ENCLOSURE 5 | |
129 | #define EPOW_POWER_OFF 7 | |
130 | ||
e51df2c1 | 131 | static void rtas_parse_epow_errlog(struct rtas_error_log *log) |
55fc0c56 AB |
132 | { |
133 | struct pseries_errorlog *pseries_log; | |
134 | struct epow_errorlog *epow_log; | |
135 | char action_code; | |
136 | char modifier; | |
137 | ||
138 | pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW); | |
139 | if (pseries_log == NULL) | |
140 | return; | |
141 | ||
142 | epow_log = (struct epow_errorlog *)pseries_log->data; | |
143 | action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */ | |
144 | modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */ | |
145 | ||
146 | switch (action_code) { | |
147 | case EPOW_RESET: | |
148 | pr_err("Non critical power or cooling issue cleared"); | |
149 | break; | |
150 | ||
151 | case EPOW_WARN_COOLING: | |
152 | pr_err("Non critical cooling issue reported by firmware"); | |
153 | pr_err("Check RTAS error log for details"); | |
154 | break; | |
155 | ||
156 | case EPOW_WARN_POWER: | |
157 | pr_err("Non critical power issue reported by firmware"); | |
158 | pr_err("Check RTAS error log for details"); | |
159 | break; | |
160 | ||
161 | case EPOW_SYSTEM_SHUTDOWN: | |
162 | handle_system_shutdown(epow_log->event_modifier); | |
163 | break; | |
164 | ||
165 | case EPOW_SYSTEM_HALT: | |
166 | pr_emerg("Firmware initiated power off"); | |
1b7e0cbe | 167 | orderly_poweroff(true); |
55fc0c56 AB |
168 | break; |
169 | ||
170 | case EPOW_MAIN_ENCLOSURE: | |
171 | case EPOW_POWER_OFF: | |
172 | pr_emerg("Critical power/cooling issue reported by firmware"); | |
173 | pr_emerg("Check RTAS error log for details"); | |
174 | pr_emerg("Immediate power off"); | |
175 | emergency_sync(); | |
176 | kernel_power_off(); | |
177 | break; | |
178 | ||
179 | default: | |
180 | pr_err("Unknown power/cooling event (action code %d)", | |
181 | action_code); | |
182 | } | |
183 | } | |
184 | ||
185 | /* Handle environmental and power warning (EPOW) interrupts. */ | |
7d12e780 | 186 | static irqreturn_t ras_epow_interrupt(int irq, void *dev_id) |
1da177e4 | 187 | { |
55fc0c56 AB |
188 | int status; |
189 | int state; | |
1da177e4 LT |
190 | int critical; |
191 | ||
1c2cb594 TH |
192 | status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, |
193 | &state); | |
1da177e4 LT |
194 | |
195 | if (state > 3) | |
55fc0c56 | 196 | critical = 1; /* Time Critical */ |
1da177e4 LT |
197 | else |
198 | critical = 0; | |
199 | ||
200 | spin_lock(&ras_log_buf_lock); | |
201 | ||
202 | status = rtas_call(ras_check_exception_token, 6, 1, NULL, | |
b08e281b | 203 | RTAS_VECTOR_EXTERNAL_INTERRUPT, |
476eb491 | 204 | virq_to_hw(irq), |
6f43747f | 205 | RTAS_EPOW_WARNING, |
1da177e4 LT |
206 | critical, __pa(&ras_log_buf), |
207 | rtas_get_error_log_max()); | |
208 | ||
1da177e4 LT |
209 | log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0); |
210 | ||
55fc0c56 AB |
211 | rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf); |
212 | ||
1da177e4 LT |
213 | spin_unlock(&ras_log_buf_lock); |
214 | return IRQ_HANDLED; | |
215 | } | |
216 | ||
217 | /* | |
218 | * Handle hardware error interrupts. | |
219 | * | |
220 | * RTAS check-exception is called to collect data on the exception. If | |
221 | * the error is deemed recoverable, we log a warning and return. | |
222 | * For nonrecoverable errors, an error is logged and we stop all processing | |
223 | * as quickly as possible in order to prevent propagation of the failure. | |
224 | */ | |
7d12e780 | 225 | static irqreturn_t ras_error_interrupt(int irq, void *dev_id) |
1da177e4 LT |
226 | { |
227 | struct rtas_error_log *rtas_elog; | |
cc8b5263 | 228 | int status; |
1da177e4 LT |
229 | int fatal; |
230 | ||
231 | spin_lock(&ras_log_buf_lock); | |
232 | ||
233 | status = rtas_call(ras_check_exception_token, 6, 1, NULL, | |
b08e281b | 234 | RTAS_VECTOR_EXTERNAL_INTERRUPT, |
476eb491 | 235 | virq_to_hw(irq), |
cc8b5263 | 236 | RTAS_INTERNAL_ERROR, 1 /* Time Critical */, |
1da177e4 LT |
237 | __pa(&ras_log_buf), |
238 | rtas_get_error_log_max()); | |
239 | ||
240 | rtas_elog = (struct rtas_error_log *)ras_log_buf; | |
241 | ||
a08a53ea GK |
242 | if (status == 0 && |
243 | rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC) | |
1da177e4 LT |
244 | fatal = 1; |
245 | else | |
246 | fatal = 0; | |
247 | ||
248 | /* format and print the extended information */ | |
249 | log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal); | |
250 | ||
251 | if (fatal) { | |
cc8b5263 AB |
252 | pr_emerg("Fatal hardware error reported by firmware"); |
253 | pr_emerg("Check RTAS error log for details"); | |
254 | pr_emerg("Immediate power off"); | |
255 | emergency_sync(); | |
256 | kernel_power_off(); | |
1da177e4 | 257 | } else { |
cc8b5263 | 258 | pr_err("Recoverable hardware error reported by firmware"); |
1da177e4 LT |
259 | } |
260 | ||
261 | spin_unlock(&ras_log_buf_lock); | |
262 | return IRQ_HANDLED; | |
263 | } | |
264 | ||
d368514c AB |
265 | /* |
266 | * Some versions of FWNMI place the buffer inside the 4kB page starting at | |
267 | * 0x7000. Other versions place it inside the rtas buffer. We check both. | |
268 | */ | |
269 | #define VALID_FWNMI_BUFFER(A) \ | |
270 | ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \ | |
271 | (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16)))) | |
272 | ||
273 | /* | |
274 | * Get the error information for errors coming through the | |
1da177e4 LT |
275 | * FWNMI vectors. The pt_regs' r3 will be updated to reflect |
276 | * the actual r3 if possible, and a ptr to the error log entry | |
277 | * will be returned if found. | |
278 | * | |
d368514c AB |
279 | * If the RTAS error is not of the extended type, then we put it in a per |
280 | * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf. | |
281 | * | |
282 | * The global_mce_data_buf does not have any locks or protection around it, | |
1da177e4 LT |
283 | * if a second machine check comes in, or a system reset is done |
284 | * before we have logged the error, then we will get corruption in the | |
285 | * error log. This is preferable over holding off on calling | |
286 | * ibm,nmi-interlock which would result in us checkstopping if a | |
287 | * second machine check did come in. | |
288 | */ | |
289 | static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) | |
290 | { | |
1da177e4 | 291 | unsigned long *savep; |
d368514c | 292 | struct rtas_error_log *h, *errhdr = NULL; |
1da177e4 | 293 | |
ee1dd1e3 MS |
294 | /* Mask top two bits */ |
295 | regs->gpr[3] &= ~(0x3UL << 62); | |
296 | ||
d368514c | 297 | if (!VALID_FWNMI_BUFFER(regs->gpr[3])) { |
f0e939ae | 298 | printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]); |
d368514c AB |
299 | return NULL; |
300 | } | |
301 | ||
302 | savep = __va(regs->gpr[3]); | |
303 | regs->gpr[3] = savep[0]; /* restore original r3 */ | |
304 | ||
305 | /* If it isn't an extended log we can use the per cpu 64bit buffer */ | |
306 | h = (struct rtas_error_log *)&savep[1]; | |
a08a53ea | 307 | if (!rtas_error_extended(h)) { |
69111bac CL |
308 | memcpy(this_cpu_ptr(&mce_data_buf), h, sizeof(__u64)); |
309 | errhdr = (struct rtas_error_log *)this_cpu_ptr(&mce_data_buf); | |
1da177e4 | 310 | } else { |
a08a53ea | 311 | int len, error_log_length; |
d368514c | 312 | |
a08a53ea GK |
313 | error_log_length = 8 + rtas_error_extended_log_length(h); |
314 | len = max_t(int, error_log_length, RTAS_ERROR_LOG_MAX); | |
d368514c AB |
315 | memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX); |
316 | memcpy(global_mce_data_buf, h, len); | |
317 | errhdr = (struct rtas_error_log *)global_mce_data_buf; | |
1da177e4 | 318 | } |
d368514c | 319 | |
1da177e4 LT |
320 | return errhdr; |
321 | } | |
322 | ||
323 | /* Call this when done with the data returned by FWNMI_get_errinfo. | |
324 | * It will release the saved data area for other CPUs in the | |
325 | * partition to receive FWNMI errors. | |
326 | */ | |
327 | static void fwnmi_release_errinfo(void) | |
328 | { | |
329 | int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL); | |
330 | if (ret != 0) | |
d368514c | 331 | printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret); |
1da177e4 LT |
332 | } |
333 | ||
c902be71 | 334 | int pSeries_system_reset_exception(struct pt_regs *regs) |
1da177e4 LT |
335 | { |
336 | if (fwnmi_active) { | |
337 | struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs); | |
338 | if (errhdr) { | |
339 | /* XXX Should look at FWNMI information */ | |
340 | } | |
341 | fwnmi_release_errinfo(); | |
342 | } | |
c902be71 | 343 | return 0; /* need to perform reset */ |
1da177e4 LT |
344 | } |
345 | ||
346 | /* | |
347 | * See if we can recover from a machine check exception. | |
348 | * This is only called on power4 (or above) and only via | |
349 | * the Firmware Non-Maskable Interrupts (fwnmi) handler | |
350 | * which provides the error analysis for us. | |
351 | * | |
352 | * Return 1 if corrected (or delivered a signal). | |
353 | * Return 0 if there is nothing we can do. | |
354 | */ | |
d47d1d8a | 355 | static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err) |
1da177e4 | 356 | { |
d47d1d8a | 357 | int recovered = 0; |
a08a53ea | 358 | int disposition = rtas_error_disposition(err); |
1da177e4 | 359 | |
d47d1d8a AB |
360 | if (!(regs->msr & MSR_RI)) { |
361 | /* If MSR_RI isn't set, we cannot recover */ | |
362 | recovered = 0; | |
363 | ||
a08a53ea | 364 | } else if (disposition == RTAS_DISP_FULLY_RECOVERED) { |
1da177e4 | 365 | /* Platform corrected itself */ |
d47d1d8a AB |
366 | recovered = 1; |
367 | ||
a08a53ea | 368 | } else if (disposition == RTAS_DISP_LIMITED_RECOVERY) { |
d47d1d8a AB |
369 | /* Platform corrected itself but could be degraded */ |
370 | printk(KERN_ERR "MCE: limited recovery, system may " | |
371 | "be degraded\n"); | |
372 | recovered = 1; | |
373 | ||
374 | } else if (user_mode(regs) && !is_global_init(current) && | |
a08a53ea | 375 | rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) { |
d47d1d8a AB |
376 | |
377 | /* | |
378 | * If we received a synchronous error when in userspace | |
379 | * kill the task. Firmware may report details of the fail | |
380 | * asynchronously, so we can't rely on the target and type | |
381 | * fields being valid here. | |
382 | */ | |
383 | printk(KERN_ERR "MCE: uncorrectable error, killing task " | |
384 | "%s:%d\n", current->comm, current->pid); | |
385 | ||
386 | _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); | |
387 | recovered = 1; | |
1da177e4 LT |
388 | } |
389 | ||
3f9793e6 | 390 | log_error((char *)err, ERR_TYPE_RTAS_LOG, 0); |
1da177e4 | 391 | |
d47d1d8a | 392 | return recovered; |
1da177e4 LT |
393 | } |
394 | ||
395 | /* | |
396 | * Handle a machine check. | |
397 | * | |
398 | * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi) | |
399 | * should be present. If so the handler which called us tells us if the | |
400 | * error was recovered (never true if RI=0). | |
401 | * | |
402 | * On hardware prior to Power 4 these exceptions were asynchronous which | |
403 | * means we can't tell exactly where it occurred and so we can't recover. | |
404 | */ | |
405 | int pSeries_machine_check_exception(struct pt_regs *regs) | |
406 | { | |
407 | struct rtas_error_log *errp; | |
408 | ||
409 | if (fwnmi_active) { | |
410 | errp = fwnmi_get_errinfo(regs); | |
411 | fwnmi_release_errinfo(); | |
412 | if (errp && recover_mce(regs, errp)) | |
413 | return 1; | |
414 | } | |
415 | ||
416 | return 0; | |
417 | } |