mca_drv.c 21 KB

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