mca_drv.c 20 KB

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