Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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) | |
7f613c7d KO |
7 | * Copyright (C) 2005 Silicon Graphics, Inc |
8 | * Copyright (C) 2005 Keith Owens <kaos@sgi.com> | |
1da177e4 LT |
9 | */ |
10 | #include <linux/config.h> | |
11 | #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) */ | |
41 | static int sal_rec_max = 10000; | |
42 | ||
1da177e4 LT |
43 | /* from mca_drv_asm.S */ |
44 | extern void *mca_handler_bhhook(void); | |
45 | ||
46 | static DEFINE_SPINLOCK(mca_bh_lock); | |
47 | ||
48 | typedef enum { | |
49 | MCA_IS_LOCAL = 0, | |
50 | MCA_IS_GLOBAL = 1 | |
51 | } mca_type_t; | |
52 | ||
53 | #define MAX_PAGE_ISOLATE 1024 | |
54 | ||
55 | static struct page *page_isolate[MAX_PAGE_ISOLATE]; | |
56 | static int num_page_isolate = 0; | |
57 | ||
58 | typedef enum { | |
4881e2cd HS |
59 | ISOLATE_NG, |
60 | ISOLATE_OK, | |
61 | ISOLATE_NONE | |
1da177e4 LT |
62 | } isolate_status_t; |
63 | ||
64 | /* | |
65 | * This pool keeps pointers to the section part of SAL error record | |
66 | */ | |
67 | static struct { | |
68 | slidx_list_t *buffer; /* section pointer list pool */ | |
69 | int cur_idx; /* Current index of section pointer list pool */ | |
70 | int max_idx; /* Maximum index of section pointer list pool */ | |
71 | } slidx_pool; | |
72 | ||
73 | /** | |
74 | * mca_page_isolate - isolate a poisoned page in order not to use it later | |
75 | * @paddr: poisoned memory location | |
76 | * | |
77 | * Return value: | |
4881e2cd | 78 | * one of isolate_status_t, ISOLATE_OK/NG/NONE. |
1da177e4 LT |
79 | */ |
80 | ||
81 | static isolate_status_t | |
82 | mca_page_isolate(unsigned long paddr) | |
83 | { | |
84 | int i; | |
85 | struct page *p; | |
86 | ||
87 | /* whether physical address is valid or not */ | |
20305e59 | 88 | if (!ia64_phys_addr_valid(paddr)) |
4881e2cd HS |
89 | return ISOLATE_NONE; |
90 | ||
56f87b82 | 91 | if (!pfn_valid(paddr >> PAGE_SHIFT)) |
4881e2cd | 92 | return ISOLATE_NONE; |
1da177e4 LT |
93 | |
94 | /* convert physical address to physical page number */ | |
95 | p = pfn_to_page(paddr>>PAGE_SHIFT); | |
96 | ||
97 | /* check whether a page number have been already registered or not */ | |
20305e59 HS |
98 | for (i = 0; i < num_page_isolate; i++) |
99 | if (page_isolate[i] == p) | |
1da177e4 LT |
100 | return ISOLATE_OK; /* already listed */ |
101 | ||
102 | /* limitation check */ | |
20305e59 | 103 | if (num_page_isolate == MAX_PAGE_ISOLATE) |
1da177e4 LT |
104 | return ISOLATE_NG; |
105 | ||
106 | /* kick pages having attribute 'SLAB' or 'Reserved' */ | |
20305e59 | 107 | if (PageSlab(p) || PageReserved(p)) |
1da177e4 LT |
108 | return ISOLATE_NG; |
109 | ||
110 | /* add attribute 'Reserved' and register the page */ | |
cbb92144 | 111 | get_page(p); |
1da177e4 LT |
112 | SetPageReserved(p); |
113 | page_isolate[num_page_isolate++] = p; | |
114 | ||
115 | return ISOLATE_OK; | |
116 | } | |
117 | ||
118 | /** | |
119 | * mca_hanlder_bh - Kill the process which occurred memory read error | |
120 | * @paddr: poisoned address received from MCA Handler | |
121 | */ | |
122 | ||
123 | void | |
124 | mca_handler_bh(unsigned long paddr) | |
125 | { | |
126 | printk(KERN_DEBUG "OS_MCA: process [pid: %d](%s) encounters MCA.\n", | |
127 | current->pid, current->comm); | |
128 | ||
129 | spin_lock(&mca_bh_lock); | |
4881e2cd HS |
130 | switch (mca_page_isolate(paddr)) { |
131 | case ISOLATE_OK: | |
1da177e4 | 132 | printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr); |
4881e2cd HS |
133 | break; |
134 | case ISOLATE_NG: | |
1da177e4 | 135 | printk(KERN_DEBUG "Page isolation: ( %lx ) failure.\n", paddr); |
4881e2cd HS |
136 | break; |
137 | default: | |
138 | break; | |
1da177e4 LT |
139 | } |
140 | spin_unlock(&mca_bh_lock); | |
141 | ||
142 | /* This process is about to be killed itself */ | |
b1b901c2 | 143 | do_exit(SIGKILL); |
1da177e4 LT |
144 | } |
145 | ||
146 | /** | |
147 | * mca_make_peidx - Make index of processor error section | |
148 | * @slpi: pointer to record of processor error section | |
149 | * @peidx: pointer to index of processor error section | |
150 | */ | |
151 | ||
20305e59 | 152 | static void |
1da177e4 LT |
153 | mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx) |
154 | { | |
20305e59 | 155 | /* |
1da177e4 LT |
156 | * calculate the start address of |
157 | * "struct cpuid_info" and "sal_processor_static_info_t". | |
158 | */ | |
159 | u64 total_check_num = slpi->valid.num_cache_check | |
160 | + slpi->valid.num_tlb_check | |
161 | + slpi->valid.num_bus_check | |
162 | + slpi->valid.num_reg_file_check | |
163 | + slpi->valid.num_ms_check; | |
164 | u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num | |
165 | + sizeof(sal_log_processor_info_t); | |
166 | u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info); | |
167 | ||
168 | peidx_head(peidx) = slpi; | |
169 | peidx_mid(peidx) = (struct sal_cpuid_info *) | |
170 | (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL); | |
171 | peidx_bottom(peidx) = (sal_processor_static_info_t *) | |
172 | (slpi->valid.psi_static_struct ? | |
173 | ((char*)slpi + head_size + mid_size) : NULL); | |
174 | } | |
175 | ||
176 | /** | |
20305e59 | 177 | * mca_make_slidx - Make index of SAL error record |
1da177e4 LT |
178 | * @buffer: pointer to SAL error record |
179 | * @slidx: pointer to index of SAL error record | |
180 | * | |
181 | * Return value: | |
182 | * 1 if record has platform error / 0 if not | |
183 | */ | |
184 | #define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \ | |
20305e59 HS |
185 | {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \ |
186 | hl->hdr = ptr; \ | |
187 | list_add(&hl->list, &(sect)); \ | |
188 | slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; } | |
1da177e4 | 189 | |
20305e59 | 190 | static int |
1da177e4 LT |
191 | mca_make_slidx(void *buffer, slidx_table_t *slidx) |
192 | { | |
193 | int platform_err = 0; | |
194 | int record_len = ((sal_log_record_header_t*)buffer)->len; | |
195 | u32 ercd_pos; | |
196 | int sects; | |
197 | sal_log_section_hdr_t *sp; | |
198 | ||
199 | /* | |
200 | * Initialize index referring current record | |
201 | */ | |
202 | INIT_LIST_HEAD(&(slidx->proc_err)); | |
203 | INIT_LIST_HEAD(&(slidx->mem_dev_err)); | |
204 | INIT_LIST_HEAD(&(slidx->sel_dev_err)); | |
205 | INIT_LIST_HEAD(&(slidx->pci_bus_err)); | |
206 | INIT_LIST_HEAD(&(slidx->smbios_dev_err)); | |
207 | INIT_LIST_HEAD(&(slidx->pci_comp_err)); | |
208 | INIT_LIST_HEAD(&(slidx->plat_specific_err)); | |
209 | INIT_LIST_HEAD(&(slidx->host_ctlr_err)); | |
210 | INIT_LIST_HEAD(&(slidx->plat_bus_err)); | |
211 | INIT_LIST_HEAD(&(slidx->unsupported)); | |
212 | ||
213 | /* | |
214 | * Extract a Record Header | |
215 | */ | |
216 | slidx->header = buffer; | |
217 | ||
218 | /* | |
219 | * Extract each section records | |
220 | * (arranged from "int ia64_log_platform_info_print()") | |
221 | */ | |
222 | for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0; | |
223 | ercd_pos < record_len; ercd_pos += sp->len, sects++) { | |
224 | sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos); | |
225 | if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) { | |
226 | LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp); | |
20305e59 HS |
227 | } else if (!efi_guidcmp(sp->guid, |
228 | SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) { | |
1da177e4 LT |
229 | platform_err = 1; |
230 | LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp); | |
20305e59 HS |
231 | } else if (!efi_guidcmp(sp->guid, |
232 | SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) { | |
1da177e4 LT |
233 | platform_err = 1; |
234 | LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp); | |
20305e59 HS |
235 | } else if (!efi_guidcmp(sp->guid, |
236 | SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) { | |
1da177e4 LT |
237 | platform_err = 1; |
238 | LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp); | |
20305e59 HS |
239 | } else if (!efi_guidcmp(sp->guid, |
240 | SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) { | |
1da177e4 LT |
241 | platform_err = 1; |
242 | LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp); | |
20305e59 HS |
243 | } else if (!efi_guidcmp(sp->guid, |
244 | SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) { | |
1da177e4 LT |
245 | platform_err = 1; |
246 | LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp); | |
20305e59 HS |
247 | } else if (!efi_guidcmp(sp->guid, |
248 | SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) { | |
1da177e4 LT |
249 | platform_err = 1; |
250 | LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp); | |
20305e59 HS |
251 | } else if (!efi_guidcmp(sp->guid, |
252 | SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) { | |
1da177e4 LT |
253 | platform_err = 1; |
254 | LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp); | |
20305e59 HS |
255 | } else if (!efi_guidcmp(sp->guid, |
256 | SAL_PLAT_BUS_ERR_SECT_GUID)) { | |
1da177e4 LT |
257 | platform_err = 1; |
258 | LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp); | |
259 | } else { | |
260 | LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp); | |
261 | } | |
262 | } | |
263 | slidx->n_sections = sects; | |
264 | ||
265 | return platform_err; | |
266 | } | |
267 | ||
268 | /** | |
269 | * init_record_index_pools - Initialize pool of lists for SAL record index | |
270 | * | |
271 | * Return value: | |
272 | * 0 on Success / -ENOMEM on Failure | |
273 | */ | |
20305e59 | 274 | static int |
1da177e4 LT |
275 | init_record_index_pools(void) |
276 | { | |
277 | int i; | |
278 | int rec_max_size; /* Maximum size of SAL error records */ | |
279 | int sect_min_size; /* Minimum size of SAL error sections */ | |
280 | /* minimum size table of each section */ | |
20305e59 HS |
281 | static int sal_log_sect_min_sizes[] = { |
282 | sizeof(sal_log_processor_info_t) | |
283 | + sizeof(sal_processor_static_info_t), | |
1da177e4 LT |
284 | sizeof(sal_log_mem_dev_err_info_t), |
285 | sizeof(sal_log_sel_dev_err_info_t), | |
286 | sizeof(sal_log_pci_bus_err_info_t), | |
287 | sizeof(sal_log_smbios_dev_err_info_t), | |
288 | sizeof(sal_log_pci_comp_err_info_t), | |
289 | sizeof(sal_log_plat_specific_err_info_t), | |
290 | sizeof(sal_log_host_ctlr_err_info_t), | |
291 | sizeof(sal_log_plat_bus_err_info_t), | |
292 | }; | |
293 | ||
294 | /* | |
295 | * MCA handler cannot allocate new memory on flight, | |
296 | * so we preallocate enough memory to handle a SAL record. | |
297 | * | |
298 | * Initialize a handling set of slidx_pool: | |
299 | * 1. Pick up the max size of SAL error records | |
300 | * 2. Pick up the min size of SAL error sections | |
301 | * 3. Allocate the pool as enough to 2 SAL records | |
302 | * (now we can estimate the maxinum of section in a record.) | |
303 | */ | |
304 | ||
305 | /* - 1 - */ | |
306 | rec_max_size = sal_rec_max; | |
307 | ||
308 | /* - 2 - */ | |
309 | sect_min_size = sal_log_sect_min_sizes[0]; | |
310 | for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++) | |
311 | if (sect_min_size > sal_log_sect_min_sizes[i]) | |
312 | sect_min_size = sal_log_sect_min_sizes[i]; | |
313 | ||
314 | /* - 3 - */ | |
315 | slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1; | |
20305e59 HS |
316 | slidx_pool.buffer = (slidx_list_t *) |
317 | kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL); | |
1da177e4 LT |
318 | |
319 | return slidx_pool.buffer ? 0 : -ENOMEM; | |
320 | } | |
321 | ||
322 | ||
323 | /***************************************************************************** | |
324 | * Recovery functions * | |
325 | *****************************************************************************/ | |
326 | ||
327 | /** | |
328 | * is_mca_global - Check whether this MCA is global or not | |
329 | * @peidx: pointer of index of processor error section | |
330 | * @pbci: pointer to pal_bus_check_info_t | |
20305e59 | 331 | * @sos: pointer to hand off struct between SAL and OS |
1da177e4 LT |
332 | * |
333 | * Return value: | |
334 | * MCA_IS_LOCAL / MCA_IS_GLOBAL | |
335 | */ | |
336 | ||
337 | static mca_type_t | |
7f613c7d KO |
338 | is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci, |
339 | struct ia64_sal_os_state *sos) | |
1da177e4 | 340 | { |
20305e59 HS |
341 | pal_processor_state_info_t *psp = |
342 | (pal_processor_state_info_t*)peidx_psp(peidx); | |
1da177e4 | 343 | |
20305e59 | 344 | /* |
1da177e4 | 345 | * PAL can request a rendezvous, if the MCA has a global scope. |
20305e59 | 346 | * If "rz_always" flag is set, SAL requests MCA rendezvous |
1da177e4 LT |
347 | * in spite of global MCA. |
348 | * Therefore it is local MCA when rendezvous has not been requested. | |
349 | * Failed to rendezvous, the system must be down. | |
350 | */ | |
7f613c7d | 351 | switch (sos->rv_rc) { |
1da177e4 LT |
352 | case -1: /* SAL rendezvous unsuccessful */ |
353 | return MCA_IS_GLOBAL; | |
354 | case 0: /* SAL rendezvous not required */ | |
355 | return MCA_IS_LOCAL; | |
356 | case 1: /* SAL rendezvous successful int */ | |
357 | case 2: /* SAL rendezvous successful int with init */ | |
358 | default: | |
359 | break; | |
360 | } | |
361 | ||
362 | /* | |
363 | * If One or more Cache/TLB/Reg_File/Uarch_Check is here, | |
364 | * it would be a local MCA. (i.e. processor internal error) | |
365 | */ | |
366 | if (psp->tc || psp->cc || psp->rc || psp->uc) | |
367 | return MCA_IS_LOCAL; | |
368 | ||
369 | /* | |
370 | * Bus_Check structure with Bus_Check.ib (internal bus error) flag set | |
371 | * would be a global MCA. (e.g. a system bus address parity error) | |
372 | */ | |
373 | if (!pbci || pbci->ib) | |
374 | return MCA_IS_GLOBAL; | |
375 | ||
376 | /* | |
377 | * Bus_Check structure with Bus_Check.eb (external bus error) flag set | |
378 | * could be either a local MCA or a global MCA. | |
379 | * | |
380 | * Referring Bus_Check.bsi: | |
381 | * 0: Unknown/unclassified | |
382 | * 1: BERR# | |
383 | * 2: BINIT# | |
384 | * 3: Hard Fail | |
385 | * (FIXME: Are these SGI specific or generic bsi values?) | |
386 | */ | |
387 | if (pbci->eb) | |
388 | switch (pbci->bsi) { | |
389 | case 0: | |
390 | /* e.g. a load from poisoned memory */ | |
391 | return MCA_IS_LOCAL; | |
392 | case 1: | |
393 | case 2: | |
394 | case 3: | |
395 | return MCA_IS_GLOBAL; | |
396 | } | |
397 | ||
398 | return MCA_IS_GLOBAL; | |
399 | } | |
400 | ||
401 | /** | |
402 | * recover_from_read_error - Try to recover the errors which type are "read"s. | |
403 | * @slidx: pointer of index of SAL error record | |
404 | * @peidx: pointer of index of processor error section | |
405 | * @pbci: pointer of pal_bus_check_info | |
20305e59 | 406 | * @sos: pointer to hand off struct between SAL and OS |
1da177e4 LT |
407 | * |
408 | * Return value: | |
409 | * 1 on Success / 0 on Failure | |
410 | */ | |
411 | ||
412 | static int | |
20305e59 HS |
413 | recover_from_read_error(slidx_table_t *slidx, |
414 | peidx_table_t *peidx, pal_bus_check_info_t *pbci, | |
7f613c7d | 415 | struct ia64_sal_os_state *sos) |
1da177e4 LT |
416 | { |
417 | sal_log_mod_error_info_t *smei; | |
418 | pal_min_state_area_t *pmsa; | |
419 | struct ia64_psr *psr1, *psr2; | |
420 | ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook; | |
421 | ||
422 | /* Is target address valid? */ | |
423 | if (!pbci->tv) | |
424 | return 0; | |
425 | ||
426 | /* | |
427 | * cpu read or memory-mapped io read | |
428 | * | |
429 | * offending process affected process OS MCA do | |
430 | * kernel mode kernel mode down system | |
431 | * kernel mode user mode kill the process | |
432 | * user mode kernel mode down system (*) | |
433 | * user mode user mode kill the process | |
434 | * | |
435 | * (*) You could terminate offending user-mode process | |
436 | * if (pbci->pv && pbci->pl != 0) *and* if you sure | |
437 | * the process not have any locks of kernel. | |
438 | */ | |
439 | ||
a9474646 HS |
440 | /* Is minstate valid? */ |
441 | if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate)) | |
442 | return 0; | |
1da177e4 LT |
443 | psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr); |
444 | ||
445 | /* | |
446 | * Check the privilege level of interrupted context. | |
447 | * If it is user-mode, then terminate affected process. | |
448 | */ | |
449 | if (psr1->cpl != 0) { | |
450 | smei = peidx_bus_check(peidx, 0); | |
451 | if (smei->valid.target_identifier) { | |
452 | /* | |
453 | * setup for resume to bottom half of MCA, | |
454 | * "mca_handler_bhhook" | |
455 | */ | |
7f613c7d | 456 | pmsa = sos->pal_min_state; |
1da177e4 LT |
457 | /* pass to bhhook as 1st argument (gr8) */ |
458 | pmsa->pmsa_gr[8-1] = smei->target_identifier; | |
459 | /* set interrupted return address (but no use) */ | |
460 | pmsa->pmsa_br0 = pmsa->pmsa_iip; | |
461 | /* change resume address to bottom half */ | |
462 | pmsa->pmsa_iip = mca_hdlr_bh->fp; | |
463 | pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp; | |
464 | /* set cpl with kernel mode */ | |
465 | psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr; | |
466 | psr2->cpl = 0; | |
467 | psr2->ri = 0; | |
b1b901c2 | 468 | psr2->i = 0; |
1da177e4 LT |
469 | |
470 | return 1; | |
471 | } | |
472 | ||
473 | } | |
474 | ||
475 | return 0; | |
476 | } | |
477 | ||
478 | /** | |
479 | * recover_from_platform_error - Recover from platform error. | |
480 | * @slidx: pointer of index of SAL error record | |
481 | * @peidx: pointer of index of processor error section | |
482 | * @pbci: pointer of pal_bus_check_info | |
20305e59 | 483 | * @sos: pointer to hand off struct between SAL and OS |
1da177e4 LT |
484 | * |
485 | * Return value: | |
486 | * 1 on Success / 0 on Failure | |
487 | */ | |
488 | ||
489 | static int | |
20305e59 HS |
490 | recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, |
491 | pal_bus_check_info_t *pbci, | |
7f613c7d | 492 | struct ia64_sal_os_state *sos) |
1da177e4 LT |
493 | { |
494 | int status = 0; | |
20305e59 HS |
495 | pal_processor_state_info_t *psp = |
496 | (pal_processor_state_info_t*)peidx_psp(peidx); | |
1da177e4 LT |
497 | |
498 | if (psp->bc && pbci->eb && pbci->bsi == 0) { | |
499 | switch(pbci->type) { | |
500 | case 1: /* partial read */ | |
501 | case 3: /* full line(cpu) read */ | |
502 | case 9: /* I/O space read */ | |
20305e59 HS |
503 | status = recover_from_read_error(slidx, peidx, pbci, |
504 | sos); | |
1da177e4 LT |
505 | break; |
506 | case 0: /* unknown */ | |
507 | case 2: /* partial write */ | |
508 | case 4: /* full line write */ | |
509 | case 5: /* implicit or explicit write-back operation */ | |
510 | case 6: /* snoop probe */ | |
511 | case 7: /* incoming or outgoing ptc.g */ | |
512 | case 8: /* write coalescing transactions */ | |
513 | case 10: /* I/O space write */ | |
514 | case 11: /* inter-processor interrupt message(IPI) */ | |
20305e59 HS |
515 | case 12: /* interrupt acknowledge or |
516 | external task priority cycle */ | |
1da177e4 LT |
517 | default: |
518 | break; | |
519 | } | |
520 | } | |
521 | ||
522 | return status; | |
523 | } | |
524 | ||
525 | /** | |
526 | * recover_from_processor_error | |
527 | * @platform: whether there are some platform error section or not | |
528 | * @slidx: pointer of index of SAL error record | |
529 | * @peidx: pointer of index of processor error section | |
530 | * @pbci: pointer of pal_bus_check_info | |
20305e59 | 531 | * @sos: pointer to hand off struct between SAL and OS |
1da177e4 LT |
532 | * |
533 | * Return value: | |
534 | * 1 on Success / 0 on Failure | |
535 | */ | |
536 | /* | |
537 | * Later we try to recover when below all conditions are satisfied. | |
538 | * 1. Only one processor error section is exist. | |
539 | * 2. BUS_CHECK is exist and the others are not exist.(Except TLB_CHECK) | |
540 | * 3. The entry of BUS_CHECK_INFO is 1. | |
541 | * 4. "External bus error" flag is set and the others are not set. | |
542 | */ | |
543 | ||
544 | static int | |
20305e59 HS |
545 | recover_from_processor_error(int platform, slidx_table_t *slidx, |
546 | peidx_table_t *peidx, pal_bus_check_info_t *pbci, | |
7f613c7d | 547 | struct ia64_sal_os_state *sos) |
1da177e4 | 548 | { |
20305e59 HS |
549 | pal_processor_state_info_t *psp = |
550 | (pal_processor_state_info_t*)peidx_psp(peidx); | |
1da177e4 | 551 | |
20305e59 | 552 | /* |
a14f25a0 RA |
553 | * Processor recovery status must key off of the PAL recovery |
554 | * status in the Processor State Parameter. | |
1da177e4 | 555 | */ |
a14f25a0 RA |
556 | |
557 | /* | |
558 | * The machine check is corrected. | |
559 | */ | |
560 | if (psp->cm == 1) | |
561 | return 1; | |
562 | ||
563 | /* | |
564 | * The error was not contained. Software must be reset. | |
565 | */ | |
566 | if (psp->us || psp->ci == 0) | |
1da177e4 LT |
567 | return 0; |
568 | ||
569 | /* | |
570 | * If there is no bus error, record is weird but we need not to recover. | |
571 | */ | |
572 | if (psp->bc == 0 || pbci == NULL) | |
573 | return 1; | |
574 | ||
575 | /* | |
576 | * Sorry, we cannot handle so many. | |
577 | */ | |
578 | if (peidx_bus_check_num(peidx) > 1) | |
579 | return 0; | |
580 | /* | |
581 | * Well, here is only one bus error. | |
582 | */ | |
583 | if (pbci->ib || pbci->cc) | |
584 | return 0; | |
585 | if (pbci->eb && pbci->bsi > 0) | |
586 | return 0; | |
1da177e4 LT |
587 | |
588 | /* | |
589 | * This is a local MCA and estimated as recoverble external bus error. | |
590 | * (e.g. a load from poisoned memory) | |
591 | * This means "there are some platform errors". | |
592 | */ | |
20305e59 | 593 | if (platform) |
7f613c7d | 594 | return recover_from_platform_error(slidx, peidx, pbci, sos); |
20305e59 HS |
595 | /* |
596 | * On account of strange SAL error record, we cannot recover. | |
1da177e4 LT |
597 | */ |
598 | return 0; | |
599 | } | |
600 | ||
601 | /** | |
602 | * mca_try_to_recover - Try to recover from MCA | |
603 | * @rec: pointer to a SAL error record | |
20305e59 | 604 | * @sos: pointer to hand off struct between SAL and OS |
1da177e4 LT |
605 | * |
606 | * Return value: | |
607 | * 1 on Success / 0 on Failure | |
608 | */ | |
609 | ||
610 | static int | |
20305e59 | 611 | mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos) |
1da177e4 LT |
612 | { |
613 | int platform_err; | |
614 | int n_proc_err; | |
615 | slidx_table_t slidx; | |
616 | peidx_table_t peidx; | |
617 | pal_bus_check_info_t pbci; | |
618 | ||
1da177e4 LT |
619 | /* Make index of SAL error record */ |
620 | platform_err = mca_make_slidx(rec, &slidx); | |
621 | ||
622 | /* Count processor error sections */ | |
623 | n_proc_err = slidx_count(&slidx, proc_err); | |
624 | ||
625 | /* Now, OS can recover when there is one processor error section */ | |
626 | if (n_proc_err > 1) | |
627 | return 0; | |
628 | else if (n_proc_err == 0) { | |
629 | /* Weird SAL record ... We need not to recover */ | |
630 | ||
631 | return 1; | |
632 | } | |
633 | ||
634 | /* Make index of processor error section */ | |
20305e59 HS |
635 | mca_make_peidx((sal_log_processor_info_t*) |
636 | slidx_first_entry(&slidx.proc_err)->hdr, &peidx); | |
1da177e4 LT |
637 | |
638 | /* Extract Processor BUS_CHECK[0] */ | |
639 | *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0); | |
640 | ||
641 | /* Check whether MCA is global or not */ | |
7f613c7d | 642 | if (is_mca_global(&peidx, &pbci, sos)) |
1da177e4 LT |
643 | return 0; |
644 | ||
645 | /* Try to recover a processor error */ | |
20305e59 HS |
646 | return recover_from_processor_error(platform_err, &slidx, &peidx, |
647 | &pbci, sos); | |
1da177e4 LT |
648 | } |
649 | ||
650 | /* | |
651 | * ============================================================================= | |
652 | */ | |
653 | ||
654 | int __init mca_external_handler_init(void) | |
655 | { | |
656 | if (init_record_index_pools()) | |
657 | return -ENOMEM; | |
658 | ||
659 | /* register external mca handlers */ | |
20305e59 | 660 | if (ia64_reg_MCA_extension(mca_try_to_recover)) { |
1da177e4 LT |
661 | printk(KERN_ERR "ia64_reg_MCA_extension failed.\n"); |
662 | kfree(slidx_pool.buffer); | |
663 | return -EFAULT; | |
664 | } | |
665 | return 0; | |
666 | } | |
667 | ||
668 | void __exit mca_external_handler_exit(void) | |
669 | { | |
670 | /* unregister external mca handlers */ | |
671 | ia64_unreg_MCA_extension(); | |
672 | kfree(slidx_pool.buffer); | |
673 | } | |
674 | ||
675 | module_init(mca_external_handler_init); | |
676 | module_exit(mca_external_handler_exit); | |
677 | ||
678 | module_param(sal_rec_max, int, 0644); | |
679 | MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record"); | |
680 | ||
681 | MODULE_DESCRIPTION("ia64 platform dependent mca handler driver"); | |
682 | MODULE_LICENSE("GPL"); |