mca_drv.c 20 KB

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