mca_drv.c 21 KB

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