blob: ca6666b51ccb6d2a9f79cf8244b5f172a91a92e0 [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 */
11#include <linux/config.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/sched.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/kallsyms.h>
18#include <linux/smp_lock.h>
19#include <linux/bootmem.h>
20#include <linux/acpi.h>
21#include <linux/timer.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/smp.h>
25#include <linux/workqueue.h>
26#include <linux/mm.h>
27
28#include <asm/delay.h>
29#include <asm/machvec.h>
30#include <asm/page.h>
31#include <asm/ptrace.h>
32#include <asm/system.h>
33#include <asm/sal.h>
34#include <asm/mca.h>
35
36#include <asm/irq.h>
37#include <asm/hw_irq.h>
38
39#include "mca_drv.h"
40
41/* max size of SAL error record (default) */
42static int sal_rec_max = 10000;
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/* from mca_drv_asm.S */
45extern void *mca_handler_bhhook(void);
46
47static DEFINE_SPINLOCK(mca_bh_lock);
48
49typedef enum {
50 MCA_IS_LOCAL = 0,
51 MCA_IS_GLOBAL = 1
52} mca_type_t;
53
54#define MAX_PAGE_ISOLATE 1024
55
56static struct page *page_isolate[MAX_PAGE_ISOLATE];
57static int num_page_isolate = 0;
58
59typedef enum {
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +090060 ISOLATE_NG,
61 ISOLATE_OK,
62 ISOLATE_NONE
Linus Torvalds1da177e2005-04-16 15:20:36 -070063} isolate_status_t;
64
Russ Anderson18997962006-04-27 10:07:08 -050065typedef enum {
66 MCA_NOT_RECOVERED = 0,
67 MCA_RECOVERED = 1
68} recovery_status_t;
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
71 * This pool keeps pointers to the section part of SAL error record
72 */
73static struct {
74 slidx_list_t *buffer; /* section pointer list pool */
75 int cur_idx; /* Current index of section pointer list pool */
76 int max_idx; /* Maximum index of section pointer list pool */
77} slidx_pool;
78
Russ Anderson18997962006-04-27 10:07:08 -050079static int
80fatal_mca(const char *fmt, ...)
81{
82 va_list args;
83
84 va_start(args, fmt);
85 vprintk(fmt, args);
86 va_end(args);
87
88 return MCA_NOT_RECOVERED;
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/**
92 * mca_page_isolate - isolate a poisoned page in order not to use it later
93 * @paddr: poisoned memory location
94 *
95 * Return value:
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +090096 * one of isolate_status_t, ISOLATE_OK/NG/NONE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 */
98
99static isolate_status_t
100mca_page_isolate(unsigned long paddr)
101{
102 int i;
103 struct page *p;
104
105 /* whether physical address is valid or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900106 if (!ia64_phys_addr_valid(paddr))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900107 return ISOLATE_NONE;
108
Russ Anderson56f87b82005-11-04 13:57:00 -0600109 if (!pfn_valid(paddr >> PAGE_SHIFT))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900110 return ISOLATE_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 /* convert physical address to physical page number */
113 p = pfn_to_page(paddr>>PAGE_SHIFT);
114
115 /* check whether a page number have been already registered or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900116 for (i = 0; i < num_page_isolate; i++)
117 if (page_isolate[i] == p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return ISOLATE_OK; /* already listed */
119
120 /* limitation check */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900121 if (num_page_isolate == MAX_PAGE_ISOLATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return ISOLATE_NG;
123
124 /* kick pages having attribute 'SLAB' or 'Reserved' */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900125 if (PageSlab(p) || PageReserved(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return ISOLATE_NG;
127
128 /* add attribute 'Reserved' and register the page */
Russ Andersoncbb92142005-11-04 16:58:28 -0600129 get_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 SetPageReserved(p);
131 page_isolate[num_page_isolate++] = p;
132
133 return ISOLATE_OK;
134}
135
136/**
137 * mca_hanlder_bh - Kill the process which occurred memory read error
138 * @paddr: poisoned address received from MCA Handler
139 */
140
141void
Russ Andersond2a28ad2006-03-24 09:49:52 -0800142mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Russ Andersond2a28ad2006-03-24 09:49:52 -0800144 printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
145 "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
146 raw_smp_processor_id(), current->pid, current->uid,
147 iip, ipsr, paddr, current->comm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 spin_lock(&mca_bh_lock);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900150 switch (mca_page_isolate(paddr)) {
151 case ISOLATE_OK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900153 break;
154 case ISOLATE_NG:
Russ Andersonea0e92a2006-03-07 15:23:25 -0800155 printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900156 break;
157 default:
158 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160 spin_unlock(&mca_bh_lock);
161
162 /* This process is about to be killed itself */
Russ Andersonb1b901c2005-04-06 00:07:00 -0700163 do_exit(SIGKILL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
166/**
167 * mca_make_peidx - Make index of processor error section
168 * @slpi: pointer to record of processor error section
169 * @peidx: pointer to index of processor error section
170 */
171
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900172static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
174{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900175 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 * calculate the start address of
177 * "struct cpuid_info" and "sal_processor_static_info_t".
178 */
179 u64 total_check_num = slpi->valid.num_cache_check
180 + slpi->valid.num_tlb_check
181 + slpi->valid.num_bus_check
182 + slpi->valid.num_reg_file_check
183 + slpi->valid.num_ms_check;
184 u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
185 + sizeof(sal_log_processor_info_t);
186 u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
187
188 peidx_head(peidx) = slpi;
189 peidx_mid(peidx) = (struct sal_cpuid_info *)
190 (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
191 peidx_bottom(peidx) = (sal_processor_static_info_t *)
192 (slpi->valid.psi_static_struct ?
193 ((char*)slpi + head_size + mid_size) : NULL);
194}
195
196/**
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900197 * mca_make_slidx - Make index of SAL error record
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 * @buffer: pointer to SAL error record
199 * @slidx: pointer to index of SAL error record
200 *
201 * Return value:
202 * 1 if record has platform error / 0 if not
203 */
204#define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900205 {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
206 hl->hdr = ptr; \
207 list_add(&hl->list, &(sect)); \
208 slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900210static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211mca_make_slidx(void *buffer, slidx_table_t *slidx)
212{
213 int platform_err = 0;
214 int record_len = ((sal_log_record_header_t*)buffer)->len;
215 u32 ercd_pos;
216 int sects;
217 sal_log_section_hdr_t *sp;
218
219 /*
220 * Initialize index referring current record
221 */
222 INIT_LIST_HEAD(&(slidx->proc_err));
223 INIT_LIST_HEAD(&(slidx->mem_dev_err));
224 INIT_LIST_HEAD(&(slidx->sel_dev_err));
225 INIT_LIST_HEAD(&(slidx->pci_bus_err));
226 INIT_LIST_HEAD(&(slidx->smbios_dev_err));
227 INIT_LIST_HEAD(&(slidx->pci_comp_err));
228 INIT_LIST_HEAD(&(slidx->plat_specific_err));
229 INIT_LIST_HEAD(&(slidx->host_ctlr_err));
230 INIT_LIST_HEAD(&(slidx->plat_bus_err));
231 INIT_LIST_HEAD(&(slidx->unsupported));
232
233 /*
234 * Extract a Record Header
235 */
236 slidx->header = buffer;
237
238 /*
239 * Extract each section records
240 * (arranged from "int ia64_log_platform_info_print()")
241 */
242 for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
243 ercd_pos < record_len; ercd_pos += sp->len, sects++) {
244 sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
245 if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
246 LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900247 } else if (!efi_guidcmp(sp->guid,
248 SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 platform_err = 1;
250 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900251 } else if (!efi_guidcmp(sp->guid,
252 SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 platform_err = 1;
254 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900255 } else if (!efi_guidcmp(sp->guid,
256 SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 platform_err = 1;
258 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900259 } else if (!efi_guidcmp(sp->guid,
260 SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 platform_err = 1;
262 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900263 } else if (!efi_guidcmp(sp->guid,
264 SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 platform_err = 1;
266 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900267 } else if (!efi_guidcmp(sp->guid,
268 SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 platform_err = 1;
270 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900271 } else if (!efi_guidcmp(sp->guid,
272 SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 platform_err = 1;
274 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900275 } else if (!efi_guidcmp(sp->guid,
276 SAL_PLAT_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 platform_err = 1;
278 LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
279 } else {
280 LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
281 }
282 }
283 slidx->n_sections = sects;
284
285 return platform_err;
286}
287
288/**
289 * init_record_index_pools - Initialize pool of lists for SAL record index
290 *
291 * Return value:
292 * 0 on Success / -ENOMEM on Failure
293 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900294static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295init_record_index_pools(void)
296{
297 int i;
298 int rec_max_size; /* Maximum size of SAL error records */
299 int sect_min_size; /* Minimum size of SAL error sections */
300 /* minimum size table of each section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900301 static int sal_log_sect_min_sizes[] = {
302 sizeof(sal_log_processor_info_t)
303 + sizeof(sal_processor_static_info_t),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 sizeof(sal_log_mem_dev_err_info_t),
305 sizeof(sal_log_sel_dev_err_info_t),
306 sizeof(sal_log_pci_bus_err_info_t),
307 sizeof(sal_log_smbios_dev_err_info_t),
308 sizeof(sal_log_pci_comp_err_info_t),
309 sizeof(sal_log_plat_specific_err_info_t),
310 sizeof(sal_log_host_ctlr_err_info_t),
311 sizeof(sal_log_plat_bus_err_info_t),
312 };
313
314 /*
315 * MCA handler cannot allocate new memory on flight,
316 * so we preallocate enough memory to handle a SAL record.
317 *
318 * Initialize a handling set of slidx_pool:
319 * 1. Pick up the max size of SAL error records
320 * 2. Pick up the min size of SAL error sections
321 * 3. Allocate the pool as enough to 2 SAL records
322 * (now we can estimate the maxinum of section in a record.)
323 */
324
325 /* - 1 - */
326 rec_max_size = sal_rec_max;
327
328 /* - 2 - */
329 sect_min_size = sal_log_sect_min_sizes[0];
330 for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
331 if (sect_min_size > sal_log_sect_min_sizes[i])
332 sect_min_size = sal_log_sect_min_sizes[i];
333
334 /* - 3 - */
335 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900336 slidx_pool.buffer = (slidx_list_t *)
337 kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return slidx_pool.buffer ? 0 : -ENOMEM;
340}
341
342
343/*****************************************************************************
344 * Recovery functions *
345 *****************************************************************************/
346
347/**
348 * is_mca_global - Check whether this MCA is global or not
349 * @peidx: pointer of index of processor error section
350 * @pbci: pointer to pal_bus_check_info_t
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900351 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 *
353 * Return value:
354 * MCA_IS_LOCAL / MCA_IS_GLOBAL
355 */
356
357static mca_type_t
Keith Owens7f613c72005-09-11 17:22:53 +1000358is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
359 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900361 pal_processor_state_info_t *psp =
362 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900364 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 * PAL can request a rendezvous, if the MCA has a global scope.
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900366 * If "rz_always" flag is set, SAL requests MCA rendezvous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 * in spite of global MCA.
368 * Therefore it is local MCA when rendezvous has not been requested.
369 * Failed to rendezvous, the system must be down.
370 */
Keith Owens7f613c72005-09-11 17:22:53 +1000371 switch (sos->rv_rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 case -1: /* SAL rendezvous unsuccessful */
373 return MCA_IS_GLOBAL;
374 case 0: /* SAL rendezvous not required */
375 return MCA_IS_LOCAL;
376 case 1: /* SAL rendezvous successful int */
377 case 2: /* SAL rendezvous successful int with init */
378 default:
379 break;
380 }
381
382 /*
383 * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
384 * it would be a local MCA. (i.e. processor internal error)
385 */
386 if (psp->tc || psp->cc || psp->rc || psp->uc)
387 return MCA_IS_LOCAL;
388
389 /*
390 * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
391 * would be a global MCA. (e.g. a system bus address parity error)
392 */
393 if (!pbci || pbci->ib)
394 return MCA_IS_GLOBAL;
395
396 /*
397 * Bus_Check structure with Bus_Check.eb (external bus error) flag set
398 * could be either a local MCA or a global MCA.
399 *
400 * Referring Bus_Check.bsi:
401 * 0: Unknown/unclassified
402 * 1: BERR#
403 * 2: BINIT#
404 * 3: Hard Fail
405 * (FIXME: Are these SGI specific or generic bsi values?)
406 */
407 if (pbci->eb)
408 switch (pbci->bsi) {
409 case 0:
410 /* e.g. a load from poisoned memory */
411 return MCA_IS_LOCAL;
412 case 1:
413 case 2:
414 case 3:
415 return MCA_IS_GLOBAL;
416 }
417
418 return MCA_IS_GLOBAL;
419}
420
421/**
422 * recover_from_read_error - Try to recover the errors which type are "read"s.
423 * @slidx: pointer of index of SAL error record
424 * @peidx: pointer of index of processor error section
425 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900426 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 *
428 * Return value:
429 * 1 on Success / 0 on Failure
430 */
431
432static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900433recover_from_read_error(slidx_table_t *slidx,
434 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000435 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
437 sal_log_mod_error_info_t *smei;
438 pal_min_state_area_t *pmsa;
439 struct ia64_psr *psr1, *psr2;
440 ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
441
442 /* Is target address valid? */
443 if (!pbci->tv)
Russ Anderson18997962006-04-27 10:07:08 -0500444 return fatal_mca(KERN_ALERT "MCA: target address not valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /*
447 * cpu read or memory-mapped io read
448 *
449 * offending process affected process OS MCA do
450 * kernel mode kernel mode down system
451 * kernel mode user mode kill the process
452 * user mode kernel mode down system (*)
453 * user mode user mode kill the process
454 *
455 * (*) You could terminate offending user-mode process
456 * if (pbci->pv && pbci->pl != 0) *and* if you sure
457 * the process not have any locks of kernel.
458 */
459
Hidetoshi Setoa9474642006-02-09 14:42:55 -0800460 /* Is minstate valid? */
461 if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
Russ Anderson18997962006-04-27 10:07:08 -0500462 return fatal_mca(KERN_ALERT "MCA: minstate not valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
Russ Andersond2a28ad2006-03-24 09:49:52 -0800464 psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 /*
467 * Check the privilege level of interrupted context.
468 * If it is user-mode, then terminate affected process.
469 */
Russ Andersond2a28ad2006-03-24 09:49:52 -0800470
471 pmsa = sos->pal_min_state;
472 if (psr1->cpl != 0 ||
473 ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 smei = peidx_bus_check(peidx, 0);
475 if (smei->valid.target_identifier) {
476 /*
477 * setup for resume to bottom half of MCA,
478 * "mca_handler_bhhook"
479 */
Russ Andersond2a28ad2006-03-24 09:49:52 -0800480 /* pass to bhhook as argument (gr8, ...) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 pmsa->pmsa_gr[8-1] = smei->target_identifier;
Russ Andersond2a28ad2006-03-24 09:49:52 -0800482 pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
483 pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* set interrupted return address (but no use) */
485 pmsa->pmsa_br0 = pmsa->pmsa_iip;
486 /* change resume address to bottom half */
487 pmsa->pmsa_iip = mca_hdlr_bh->fp;
488 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
489 /* set cpl with kernel mode */
490 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
491 psr2->cpl = 0;
492 psr2->ri = 0;
Russ Andersond2a28ad2006-03-24 09:49:52 -0800493 psr2->bn = 1;
Russ Andersonb1b901c2005-04-06 00:07:00 -0700494 psr2->i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Russ Anderson18997962006-04-27 10:07:08 -0500496 return MCA_RECOVERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
499 }
500
Russ Anderson18997962006-04-27 10:07:08 -0500501 return fatal_mca(KERN_ALERT "MCA: kernel context not recovered,"
502 " iip 0x%lx\n", pmsa->pmsa_iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505/**
506 * recover_from_platform_error - Recover from platform error.
507 * @slidx: pointer of index of SAL error record
508 * @peidx: pointer of index of processor error section
509 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900510 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 *
512 * Return value:
513 * 1 on Success / 0 on Failure
514 */
515
516static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900517recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
518 pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000519 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
521 int status = 0;
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900522 pal_processor_state_info_t *psp =
523 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 if (psp->bc && pbci->eb && pbci->bsi == 0) {
526 switch(pbci->type) {
527 case 1: /* partial read */
528 case 3: /* full line(cpu) read */
529 case 9: /* I/O space read */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900530 status = recover_from_read_error(slidx, peidx, pbci,
531 sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533 case 0: /* unknown */
534 case 2: /* partial write */
535 case 4: /* full line write */
536 case 5: /* implicit or explicit write-back operation */
537 case 6: /* snoop probe */
538 case 7: /* incoming or outgoing ptc.g */
539 case 8: /* write coalescing transactions */
540 case 10: /* I/O space write */
541 case 11: /* inter-processor interrupt message(IPI) */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900542 case 12: /* interrupt acknowledge or
543 external task priority cycle */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 default:
545 break;
546 }
547 }
548
549 return status;
550}
551
552/**
553 * recover_from_processor_error
554 * @platform: whether there are some platform error section or not
555 * @slidx: pointer of index of SAL error record
556 * @peidx: pointer of index of processor error section
557 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900558 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 *
560 * Return value:
561 * 1 on Success / 0 on Failure
562 */
563/*
564 * Later we try to recover when below all conditions are satisfied.
565 * 1. Only one processor error section is exist.
566 * 2. BUS_CHECK is exist and the others are not exist.(Except TLB_CHECK)
567 * 3. The entry of BUS_CHECK_INFO is 1.
568 * 4. "External bus error" flag is set and the others are not set.
569 */
570
571static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900572recover_from_processor_error(int platform, slidx_table_t *slidx,
573 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000574 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900576 pal_processor_state_info_t *psp =
577 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900579 /*
Russ Andersona14f25a2005-11-04 13:39:38 -0600580 * Processor recovery status must key off of the PAL recovery
581 * status in the Processor State Parameter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 */
Russ Andersona14f25a2005-11-04 13:39:38 -0600583
584 /*
585 * The machine check is corrected.
586 */
587 if (psp->cm == 1)
Russ Anderson18997962006-04-27 10:07:08 -0500588 return MCA_RECOVERED;
Russ Andersona14f25a2005-11-04 13:39:38 -0600589
590 /*
591 * The error was not contained. Software must be reset.
592 */
593 if (psp->us || psp->ci == 0)
Russ Anderson18997962006-04-27 10:07:08 -0500594 return fatal_mca(KERN_ALERT "MCA: error not contained\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 /*
Russ Andersone1c48552006-03-03 16:42:26 -0600597 * The cache check and bus check bits have four possible states
598 * cc bc
599 * 0 0 Weird record, not recovered
600 * 1 0 Cache error, not recovered
601 * 0 1 I/O error, attempt recovery
602 * 1 1 Memory error, attempt recovery
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 */
604 if (psp->bc == 0 || pbci == NULL)
Russ Anderson18997962006-04-27 10:07:08 -0500605 return fatal_mca(KERN_ALERT "MCA: No bus check\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /*
608 * Sorry, we cannot handle so many.
609 */
610 if (peidx_bus_check_num(peidx) > 1)
Russ Anderson18997962006-04-27 10:07:08 -0500611 return fatal_mca(KERN_ALERT "MCA: Too many bus checks\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /*
613 * Well, here is only one bus error.
614 */
Russ Anderson18997962006-04-27 10:07:08 -0500615 if (pbci->ib)
616 return fatal_mca(KERN_ALERT "MCA: Internal Bus error\n");
617 if (pbci->cc)
618 return fatal_mca(KERN_ALERT "MCA: Cache-cache error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (pbci->eb && pbci->bsi > 0)
Russ Anderson18997962006-04-27 10:07:08 -0500620 return fatal_mca(KERN_ALERT "MCA: External bus check fatal status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /*
623 * This is a local MCA and estimated as recoverble external bus error.
624 * (e.g. a load from poisoned memory)
625 * This means "there are some platform errors".
626 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900627 if (platform)
Keith Owens7f613c72005-09-11 17:22:53 +1000628 return recover_from_platform_error(slidx, peidx, pbci, sos);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900629 /*
630 * On account of strange SAL error record, we cannot recover.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 */
Russ Anderson18997962006-04-27 10:07:08 -0500632 return fatal_mca(KERN_ALERT "MCA: Strange SAL record\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
635/**
636 * mca_try_to_recover - Try to recover from MCA
637 * @rec: pointer to a SAL error record
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900638 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 *
640 * Return value:
641 * 1 on Success / 0 on Failure
642 */
643
644static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900645mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
647 int platform_err;
648 int n_proc_err;
649 slidx_table_t slidx;
650 peidx_table_t peidx;
651 pal_bus_check_info_t pbci;
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* Make index of SAL error record */
654 platform_err = mca_make_slidx(rec, &slidx);
655
656 /* Count processor error sections */
657 n_proc_err = slidx_count(&slidx, proc_err);
658
659 /* Now, OS can recover when there is one processor error section */
660 if (n_proc_err > 1)
Russ Anderson18997962006-04-27 10:07:08 -0500661 return fatal_mca(KERN_ALERT "MCA: Too Many Errors\n");
662 else if (n_proc_err == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /* Weird SAL record ... We need not to recover */
Russ Anderson18997962006-04-27 10:07:08 -0500664 return fatal_mca(KERN_ALERT "MCA: Weird SAL record\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 /* Make index of processor error section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900667 mca_make_peidx((sal_log_processor_info_t*)
668 slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 /* Extract Processor BUS_CHECK[0] */
671 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
672
673 /* Check whether MCA is global or not */
Keith Owens7f613c72005-09-11 17:22:53 +1000674 if (is_mca_global(&peidx, &pbci, sos))
Russ Anderson18997962006-04-27 10:07:08 -0500675 return fatal_mca(KERN_ALERT "MCA: global MCA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 /* Try to recover a processor error */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900678 return recover_from_processor_error(platform_err, &slidx, &peidx,
679 &pbci, sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682/*
683 * =============================================================================
684 */
685
686int __init mca_external_handler_init(void)
687{
688 if (init_record_index_pools())
689 return -ENOMEM;
690
691 /* register external mca handlers */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900692 if (ia64_reg_MCA_extension(mca_try_to_recover)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
694 kfree(slidx_pool.buffer);
695 return -EFAULT;
696 }
697 return 0;
698}
699
700void __exit mca_external_handler_exit(void)
701{
702 /* unregister external mca handlers */
703 ia64_unreg_MCA_extension();
704 kfree(slidx_pool.buffer);
705}
706
707module_init(mca_external_handler_init);
708module_exit(mca_external_handler_exit);
709
710module_param(sal_rec_max, int, 0644);
711MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
712
713MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
714MODULE_LICENSE("GPL");