blob: a45009d2bc90149e5199a97c9eff86a8d552f5b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File: mca_drv.c
3 * Purpose: Generic MCA handling layer
4 *
5 * Copyright (C) 2004 FUJITSU LIMITED
6 * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
Keith Owens7f613c72005-09-11 17:22:53 +10007 * Copyright (C) 2005 Silicon Graphics, Inc
8 * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
Russ Andersond2a28ad2006-03-24 09:49:52 -08009 * Copyright (C) 2006 Russ Anderson <rja@sgi.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/types.h>
12#include <linux/init.h>
13#include <linux/sched.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/kallsyms.h>
17#include <linux/smp_lock.h>
18#include <linux/bootmem.h>
19#include <linux/acpi.h>
20#include <linux/timer.h>
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/smp.h>
24#include <linux/workqueue.h>
25#include <linux/mm.h>
26
27#include <asm/delay.h>
28#include <asm/machvec.h>
29#include <asm/page.h>
30#include <asm/ptrace.h>
31#include <asm/system.h>
32#include <asm/sal.h>
33#include <asm/mca.h>
34
35#include <asm/irq.h>
36#include <asm/hw_irq.h>
37
38#include "mca_drv.h"
39
40/* max size of SAL error record (default) */
41static int sal_rec_max = 10000;
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/* from mca_drv_asm.S */
44extern void *mca_handler_bhhook(void);
45
46static DEFINE_SPINLOCK(mca_bh_lock);
47
48typedef enum {
49 MCA_IS_LOCAL = 0,
50 MCA_IS_GLOBAL = 1
51} mca_type_t;
52
53#define MAX_PAGE_ISOLATE 1024
54
55static struct page *page_isolate[MAX_PAGE_ISOLATE];
56static int num_page_isolate = 0;
57
58typedef enum {
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +090059 ISOLATE_NG,
60 ISOLATE_OK,
61 ISOLATE_NONE
Linus Torvalds1da177e2005-04-16 15:20:36 -070062} isolate_status_t;
63
Russ Anderson18997962006-04-27 10:07:08 -050064typedef enum {
65 MCA_NOT_RECOVERED = 0,
66 MCA_RECOVERED = 1
67} recovery_status_t;
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/*
70 * This pool keeps pointers to the section part of SAL error record
71 */
72static struct {
73 slidx_list_t *buffer; /* section pointer list pool */
74 int cur_idx; /* Current index of section pointer list pool */
75 int max_idx; /* Maximum index of section pointer list pool */
76} slidx_pool;
77
Russ Anderson18997962006-04-27 10:07:08 -050078static int
79fatal_mca(const char *fmt, ...)
80{
81 va_list args;
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070082 char buf[256];
Russ Anderson18997962006-04-27 10:07:08 -050083
84 va_start(args, fmt);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070085 vsnprintf(buf, sizeof(buf), fmt, args);
Russ Anderson18997962006-04-27 10:07:08 -050086 va_end(args);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070087 ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
Russ Anderson18997962006-04-27 10:07:08 -050088
89 return MCA_NOT_RECOVERED;
90}
91
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070092static int
93mca_recovered(const char *fmt, ...)
94{
95 va_list args;
96 char buf[256];
97
98 va_start(args, fmt);
99 vsnprintf(buf, sizeof(buf), fmt, args);
100 va_end(args);
101 ia64_mca_printk(KERN_INFO "MCA: %s\n", buf);
102
103 return MCA_RECOVERED;
104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/**
107 * mca_page_isolate - isolate a poisoned page in order not to use it later
108 * @paddr: poisoned memory location
109 *
110 * Return value:
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900111 * one of isolate_status_t, ISOLATE_OK/NG/NONE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
113
114static isolate_status_t
115mca_page_isolate(unsigned long paddr)
116{
117 int i;
118 struct page *p;
119
120 /* whether physical address is valid or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900121 if (!ia64_phys_addr_valid(paddr))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900122 return ISOLATE_NONE;
123
Russ Anderson56f87b82005-11-04 13:57:00 -0600124 if (!pfn_valid(paddr >> PAGE_SHIFT))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900125 return ISOLATE_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* convert physical address to physical page number */
128 p = pfn_to_page(paddr>>PAGE_SHIFT);
129
130 /* check whether a page number have been already registered or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900131 for (i = 0; i < num_page_isolate; i++)
132 if (page_isolate[i] == p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return ISOLATE_OK; /* already listed */
134
135 /* limitation check */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900136 if (num_page_isolate == MAX_PAGE_ISOLATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return ISOLATE_NG;
138
139 /* kick pages having attribute 'SLAB' or 'Reserved' */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900140 if (PageSlab(p) || PageReserved(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return ISOLATE_NG;
142
143 /* add attribute 'Reserved' and register the page */
Russ Andersoncbb92142005-11-04 16:58:28 -0600144 get_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 SetPageReserved(p);
146 page_isolate[num_page_isolate++] = p;
147
148 return ISOLATE_OK;
149}
150
151/**
152 * mca_hanlder_bh - Kill the process which occurred memory read error
153 * @paddr: poisoned address received from MCA Handler
154 */
155
156void
Russ Andersond2a28ad2006-03-24 09:49:52 -0800157mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700159 ia64_mlogbuf_dump();
Russ Andersond2a28ad2006-03-24 09:49:52 -0800160 printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
161 "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
162 raw_smp_processor_id(), current->pid, current->uid,
163 iip, ipsr, paddr, current->comm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 spin_lock(&mca_bh_lock);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900166 switch (mca_page_isolate(paddr)) {
167 case ISOLATE_OK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900169 break;
170 case ISOLATE_NG:
Russ Andersonea0e92a2006-03-07 15:23:25 -0800171 printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900172 break;
173 default:
174 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176 spin_unlock(&mca_bh_lock);
177
178 /* This process is about to be killed itself */
Russ Andersonb1b901c2005-04-06 00:07:00 -0700179 do_exit(SIGKILL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
182/**
183 * mca_make_peidx - Make index of processor error section
184 * @slpi: pointer to record of processor error section
185 * @peidx: pointer to index of processor error section
186 */
187
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900188static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
190{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900191 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 * calculate the start address of
193 * "struct cpuid_info" and "sal_processor_static_info_t".
194 */
195 u64 total_check_num = slpi->valid.num_cache_check
196 + slpi->valid.num_tlb_check
197 + slpi->valid.num_bus_check
198 + slpi->valid.num_reg_file_check
199 + slpi->valid.num_ms_check;
200 u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
201 + sizeof(sal_log_processor_info_t);
202 u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
203
204 peidx_head(peidx) = slpi;
205 peidx_mid(peidx) = (struct sal_cpuid_info *)
206 (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
207 peidx_bottom(peidx) = (sal_processor_static_info_t *)
208 (slpi->valid.psi_static_struct ?
209 ((char*)slpi + head_size + mid_size) : NULL);
210}
211
212/**
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900213 * mca_make_slidx - Make index of SAL error record
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 * @buffer: pointer to SAL error record
215 * @slidx: pointer to index of SAL error record
216 *
217 * Return value:
218 * 1 if record has platform error / 0 if not
219 */
220#define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900221 {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
222 hl->hdr = ptr; \
223 list_add(&hl->list, &(sect)); \
224 slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900226static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227mca_make_slidx(void *buffer, slidx_table_t *slidx)
228{
229 int platform_err = 0;
230 int record_len = ((sal_log_record_header_t*)buffer)->len;
231 u32 ercd_pos;
232 int sects;
233 sal_log_section_hdr_t *sp;
234
235 /*
236 * Initialize index referring current record
237 */
238 INIT_LIST_HEAD(&(slidx->proc_err));
239 INIT_LIST_HEAD(&(slidx->mem_dev_err));
240 INIT_LIST_HEAD(&(slidx->sel_dev_err));
241 INIT_LIST_HEAD(&(slidx->pci_bus_err));
242 INIT_LIST_HEAD(&(slidx->smbios_dev_err));
243 INIT_LIST_HEAD(&(slidx->pci_comp_err));
244 INIT_LIST_HEAD(&(slidx->plat_specific_err));
245 INIT_LIST_HEAD(&(slidx->host_ctlr_err));
246 INIT_LIST_HEAD(&(slidx->plat_bus_err));
247 INIT_LIST_HEAD(&(slidx->unsupported));
248
249 /*
250 * Extract a Record Header
251 */
252 slidx->header = buffer;
253
254 /*
255 * Extract each section records
256 * (arranged from "int ia64_log_platform_info_print()")
257 */
258 for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
259 ercd_pos < record_len; ercd_pos += sp->len, sects++) {
260 sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
261 if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
262 LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900263 } else if (!efi_guidcmp(sp->guid,
264 SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 platform_err = 1;
266 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900267 } else if (!efi_guidcmp(sp->guid,
268 SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 platform_err = 1;
270 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900271 } else if (!efi_guidcmp(sp->guid,
272 SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 platform_err = 1;
274 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900275 } else if (!efi_guidcmp(sp->guid,
276 SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 platform_err = 1;
278 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900279 } else if (!efi_guidcmp(sp->guid,
280 SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 platform_err = 1;
282 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900283 } else if (!efi_guidcmp(sp->guid,
284 SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 platform_err = 1;
286 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900287 } else if (!efi_guidcmp(sp->guid,
288 SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 platform_err = 1;
290 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900291 } else if (!efi_guidcmp(sp->guid,
292 SAL_PLAT_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 platform_err = 1;
294 LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
295 } else {
296 LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
297 }
298 }
299 slidx->n_sections = sects;
300
301 return platform_err;
302}
303
304/**
305 * init_record_index_pools - Initialize pool of lists for SAL record index
306 *
307 * Return value:
308 * 0 on Success / -ENOMEM on Failure
309 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900310static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311init_record_index_pools(void)
312{
313 int i;
314 int rec_max_size; /* Maximum size of SAL error records */
315 int sect_min_size; /* Minimum size of SAL error sections */
316 /* minimum size table of each section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900317 static int sal_log_sect_min_sizes[] = {
318 sizeof(sal_log_processor_info_t)
319 + sizeof(sal_processor_static_info_t),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 sizeof(sal_log_mem_dev_err_info_t),
321 sizeof(sal_log_sel_dev_err_info_t),
322 sizeof(sal_log_pci_bus_err_info_t),
323 sizeof(sal_log_smbios_dev_err_info_t),
324 sizeof(sal_log_pci_comp_err_info_t),
325 sizeof(sal_log_plat_specific_err_info_t),
326 sizeof(sal_log_host_ctlr_err_info_t),
327 sizeof(sal_log_plat_bus_err_info_t),
328 };
329
330 /*
331 * MCA handler cannot allocate new memory on flight,
332 * so we preallocate enough memory to handle a SAL record.
333 *
334 * Initialize a handling set of slidx_pool:
335 * 1. Pick up the max size of SAL error records
336 * 2. Pick up the min size of SAL error sections
337 * 3. Allocate the pool as enough to 2 SAL records
338 * (now we can estimate the maxinum of section in a record.)
339 */
340
341 /* - 1 - */
342 rec_max_size = sal_rec_max;
343
344 /* - 2 - */
345 sect_min_size = sal_log_sect_min_sizes[0];
346 for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
347 if (sect_min_size > sal_log_sect_min_sizes[i])
348 sect_min_size = sal_log_sect_min_sizes[i];
349
350 /* - 3 - */
351 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900352 slidx_pool.buffer = (slidx_list_t *)
353 kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 return slidx_pool.buffer ? 0 : -ENOMEM;
356}
357
358
359/*****************************************************************************
360 * Recovery functions *
361 *****************************************************************************/
362
363/**
364 * is_mca_global - Check whether this MCA is global or not
365 * @peidx: pointer of index of processor error section
366 * @pbci: pointer to pal_bus_check_info_t
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900367 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 *
369 * Return value:
370 * MCA_IS_LOCAL / MCA_IS_GLOBAL
371 */
372
373static mca_type_t
Keith Owens7f613c72005-09-11 17:22:53 +1000374is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
375 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900377 pal_processor_state_info_t *psp =
378 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900380 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 * PAL can request a rendezvous, if the MCA has a global scope.
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900382 * If "rz_always" flag is set, SAL requests MCA rendezvous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 * in spite of global MCA.
384 * Therefore it is local MCA when rendezvous has not been requested.
385 * Failed to rendezvous, the system must be down.
386 */
Keith Owens7f613c72005-09-11 17:22:53 +1000387 switch (sos->rv_rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 case -1: /* SAL rendezvous unsuccessful */
389 return MCA_IS_GLOBAL;
390 case 0: /* SAL rendezvous not required */
391 return MCA_IS_LOCAL;
392 case 1: /* SAL rendezvous successful int */
393 case 2: /* SAL rendezvous successful int with init */
394 default:
395 break;
396 }
397
398 /*
399 * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
400 * it would be a local MCA. (i.e. processor internal error)
401 */
402 if (psp->tc || psp->cc || psp->rc || psp->uc)
403 return MCA_IS_LOCAL;
404
405 /*
406 * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
407 * would be a global MCA. (e.g. a system bus address parity error)
408 */
409 if (!pbci || pbci->ib)
410 return MCA_IS_GLOBAL;
411
412 /*
413 * Bus_Check structure with Bus_Check.eb (external bus error) flag set
414 * could be either a local MCA or a global MCA.
415 *
416 * Referring Bus_Check.bsi:
417 * 0: Unknown/unclassified
418 * 1: BERR#
419 * 2: BINIT#
420 * 3: Hard Fail
421 * (FIXME: Are these SGI specific or generic bsi values?)
422 */
423 if (pbci->eb)
424 switch (pbci->bsi) {
425 case 0:
426 /* e.g. a load from poisoned memory */
427 return MCA_IS_LOCAL;
428 case 1:
429 case 2:
430 case 3:
431 return MCA_IS_GLOBAL;
432 }
433
434 return MCA_IS_GLOBAL;
435}
436
437/**
438 * recover_from_read_error - Try to recover the errors which type are "read"s.
439 * @slidx: pointer of index of SAL error record
440 * @peidx: pointer of index of processor error section
441 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900442 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 *
444 * Return value:
445 * 1 on Success / 0 on Failure
446 */
447
448static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900449recover_from_read_error(slidx_table_t *slidx,
450 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000451 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
453 sal_log_mod_error_info_t *smei;
454 pal_min_state_area_t *pmsa;
455 struct ia64_psr *psr1, *psr2;
456 ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
457
458 /* Is target address valid? */
459 if (!pbci->tv)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700460 return fatal_mca("target address not valid");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 /*
463 * cpu read or memory-mapped io read
464 *
465 * offending process affected process OS MCA do
466 * kernel mode kernel mode down system
467 * kernel mode user mode kill the process
468 * user mode kernel mode down system (*)
469 * user mode user mode kill the process
470 *
471 * (*) You could terminate offending user-mode process
472 * if (pbci->pv && pbci->pl != 0) *and* if you sure
473 * the process not have any locks of kernel.
474 */
475
Hidetoshi Setoa9474642006-02-09 14:42:55 -0800476 /* Is minstate valid? */
477 if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700478 return fatal_mca("minstate not valid");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
Russ Andersond2a28ad2006-03-24 09:49:52 -0800480 psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /*
483 * Check the privilege level of interrupted context.
484 * If it is user-mode, then terminate affected process.
485 */
Russ Andersond2a28ad2006-03-24 09:49:52 -0800486
487 pmsa = sos->pal_min_state;
488 if (psr1->cpl != 0 ||
489 ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 smei = peidx_bus_check(peidx, 0);
491 if (smei->valid.target_identifier) {
492 /*
493 * setup for resume to bottom half of MCA,
494 * "mca_handler_bhhook"
495 */
Russ Andersond2a28ad2006-03-24 09:49:52 -0800496 /* pass to bhhook as argument (gr8, ...) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 pmsa->pmsa_gr[8-1] = smei->target_identifier;
Russ Andersond2a28ad2006-03-24 09:49:52 -0800498 pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
499 pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* set interrupted return address (but no use) */
501 pmsa->pmsa_br0 = pmsa->pmsa_iip;
502 /* change resume address to bottom half */
503 pmsa->pmsa_iip = mca_hdlr_bh->fp;
504 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
505 /* set cpl with kernel mode */
506 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
507 psr2->cpl = 0;
508 psr2->ri = 0;
Russ Andersond2a28ad2006-03-24 09:49:52 -0800509 psr2->bn = 1;
Russ Andersonb1b901c2005-04-06 00:07:00 -0700510 psr2->i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700512 return mca_recovered("user memory corruption. "
513 "kill affected process - recovered.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
515
516 }
517
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700518 return fatal_mca("kernel context not recovered, iip 0x%lx\n",
519 pmsa->pmsa_iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522/**
523 * recover_from_platform_error - Recover from platform error.
524 * @slidx: pointer of index of SAL error record
525 * @peidx: pointer of index of processor error section
526 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900527 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 *
529 * Return value:
530 * 1 on Success / 0 on Failure
531 */
532
533static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900534recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
535 pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000536 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
538 int status = 0;
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900539 pal_processor_state_info_t *psp =
540 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 if (psp->bc && pbci->eb && pbci->bsi == 0) {
543 switch(pbci->type) {
544 case 1: /* partial read */
545 case 3: /* full line(cpu) read */
546 case 9: /* I/O space read */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900547 status = recover_from_read_error(slidx, peidx, pbci,
548 sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 break;
550 case 0: /* unknown */
551 case 2: /* partial write */
552 case 4: /* full line write */
553 case 5: /* implicit or explicit write-back operation */
554 case 6: /* snoop probe */
555 case 7: /* incoming or outgoing ptc.g */
556 case 8: /* write coalescing transactions */
557 case 10: /* I/O space write */
558 case 11: /* inter-processor interrupt message(IPI) */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900559 case 12: /* interrupt acknowledge or
560 external task priority cycle */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 default:
562 break;
563 }
564 }
565
566 return status;
567}
568
569/**
570 * recover_from_processor_error
571 * @platform: whether there are some platform error section or not
572 * @slidx: pointer of index of SAL error record
573 * @peidx: pointer of index of processor error section
574 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900575 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *
577 * Return value:
578 * 1 on Success / 0 on Failure
579 */
580/*
581 * Later we try to recover when below all conditions are satisfied.
582 * 1. Only one processor error section is exist.
583 * 2. BUS_CHECK is exist and the others are not exist.(Except TLB_CHECK)
584 * 3. The entry of BUS_CHECK_INFO is 1.
585 * 4. "External bus error" flag is set and the others are not set.
586 */
587
588static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900589recover_from_processor_error(int platform, slidx_table_t *slidx,
590 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000591 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900593 pal_processor_state_info_t *psp =
594 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900596 /*
Russ Andersona14f25a2005-11-04 13:39:38 -0600597 * Processor recovery status must key off of the PAL recovery
598 * status in the Processor State Parameter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 */
Russ Andersona14f25a2005-11-04 13:39:38 -0600600
601 /*
602 * The machine check is corrected.
603 */
604 if (psp->cm == 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700605 return mca_recovered("machine check is already corrected.");
Russ Andersona14f25a2005-11-04 13:39:38 -0600606
607 /*
608 * The error was not contained. Software must be reset.
609 */
610 if (psp->us || psp->ci == 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700611 return fatal_mca("error not contained");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 /*
Russ Andersone1c48552006-03-03 16:42:26 -0600614 * The cache check and bus check bits have four possible states
615 * cc bc
616 * 0 0 Weird record, not recovered
617 * 1 0 Cache error, not recovered
618 * 0 1 I/O error, attempt recovery
619 * 1 1 Memory error, attempt recovery
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 */
621 if (psp->bc == 0 || pbci == NULL)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700622 return fatal_mca("No bus check");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /*
625 * Sorry, we cannot handle so many.
626 */
627 if (peidx_bus_check_num(peidx) > 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700628 return fatal_mca("Too many bus checks");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 /*
630 * Well, here is only one bus error.
631 */
Russ Anderson18997962006-04-27 10:07:08 -0500632 if (pbci->ib)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700633 return fatal_mca("Internal Bus error");
Russ Anderson18997962006-04-27 10:07:08 -0500634 if (pbci->cc)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700635 return fatal_mca("Cache-cache error");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 if (pbci->eb && pbci->bsi > 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700637 return fatal_mca("External bus check fatal status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 /*
640 * This is a local MCA and estimated as recoverble external bus error.
641 * (e.g. a load from poisoned memory)
642 * This means "there are some platform errors".
643 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900644 if (platform)
Keith Owens7f613c72005-09-11 17:22:53 +1000645 return recover_from_platform_error(slidx, peidx, pbci, sos);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900646 /*
647 * On account of strange SAL error record, we cannot recover.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 */
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700649 return fatal_mca("Strange SAL record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652/**
653 * mca_try_to_recover - Try to recover from MCA
654 * @rec: pointer to a SAL error record
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900655 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 *
657 * Return value:
658 * 1 on Success / 0 on Failure
659 */
660
661static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900662mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
664 int platform_err;
665 int n_proc_err;
666 slidx_table_t slidx;
667 peidx_table_t peidx;
668 pal_bus_check_info_t pbci;
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* Make index of SAL error record */
671 platform_err = mca_make_slidx(rec, &slidx);
672
673 /* Count processor error sections */
674 n_proc_err = slidx_count(&slidx, proc_err);
675
676 /* Now, OS can recover when there is one processor error section */
677 if (n_proc_err > 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700678 return fatal_mca("Too Many Errors");
Russ Anderson18997962006-04-27 10:07:08 -0500679 else if (n_proc_err == 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700680 /* Weird SAL record ... We can't do anything */
681 return fatal_mca("Weird SAL record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 /* Make index of processor error section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900684 mca_make_peidx((sal_log_processor_info_t*)
685 slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 /* Extract Processor BUS_CHECK[0] */
688 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
689
690 /* Check whether MCA is global or not */
Keith Owens7f613c72005-09-11 17:22:53 +1000691 if (is_mca_global(&peidx, &pbci, sos))
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700692 return fatal_mca("global MCA");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 /* Try to recover a processor error */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900695 return recover_from_processor_error(platform_err, &slidx, &peidx,
696 &pbci, sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
699/*
700 * =============================================================================
701 */
702
703int __init mca_external_handler_init(void)
704{
705 if (init_record_index_pools())
706 return -ENOMEM;
707
708 /* register external mca handlers */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900709 if (ia64_reg_MCA_extension(mca_try_to_recover)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
711 kfree(slidx_pool.buffer);
712 return -EFAULT;
713 }
714 return 0;
715}
716
717void __exit mca_external_handler_exit(void)
718{
719 /* unregister external mca handlers */
720 ia64_unreg_MCA_extension();
721 kfree(slidx_pool.buffer);
722}
723
724module_init(mca_external_handler_init);
725module_exit(mca_external_handler_exit);
726
727module_param(sal_rec_max, int, 0644);
728MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
729
730MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
731MODULE_LICENSE("GPL");