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