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,
  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(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
  308. return slidx_pool.buffer ? 0 : -ENOMEM;
  309. }
  310. /*****************************************************************************
  311. * Recovery functions *
  312. *****************************************************************************/
  313. /**
  314. * is_mca_global - Check whether this MCA is global or not
  315. * @peidx: pointer of index of processor error section
  316. * @pbci: pointer to pal_bus_check_info_t
  317. * @sos: pointer to hand off struct between SAL and OS
  318. *
  319. * Return value:
  320. * MCA_IS_LOCAL / MCA_IS_GLOBAL
  321. */
  322. static mca_type_t
  323. is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  324. struct ia64_sal_os_state *sos)
  325. {
  326. pal_processor_state_info_t *psp =
  327. (pal_processor_state_info_t*)peidx_psp(peidx);
  328. /*
  329. * PAL can request a rendezvous, if the MCA has a global scope.
  330. * If "rz_always" flag is set, SAL requests MCA rendezvous
  331. * in spite of global MCA.
  332. * Therefore it is local MCA when rendezvous has not been requested.
  333. * Failed to rendezvous, the system must be down.
  334. */
  335. switch (sos->rv_rc) {
  336. case -1: /* SAL rendezvous unsuccessful */
  337. return MCA_IS_GLOBAL;
  338. case 0: /* SAL rendezvous not required */
  339. return MCA_IS_LOCAL;
  340. case 1: /* SAL rendezvous successful int */
  341. case 2: /* SAL rendezvous successful int with init */
  342. default:
  343. break;
  344. }
  345. /*
  346. * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
  347. * it would be a local MCA. (i.e. processor internal error)
  348. */
  349. if (psp->tc || psp->cc || psp->rc || psp->uc)
  350. return MCA_IS_LOCAL;
  351. /*
  352. * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
  353. * would be a global MCA. (e.g. a system bus address parity error)
  354. */
  355. if (!pbci || pbci->ib)
  356. return MCA_IS_GLOBAL;
  357. /*
  358. * Bus_Check structure with Bus_Check.eb (external bus error) flag set
  359. * could be either a local MCA or a global MCA.
  360. *
  361. * Referring Bus_Check.bsi:
  362. * 0: Unknown/unclassified
  363. * 1: BERR#
  364. * 2: BINIT#
  365. * 3: Hard Fail
  366. * (FIXME: Are these SGI specific or generic bsi values?)
  367. */
  368. if (pbci->eb)
  369. switch (pbci->bsi) {
  370. case 0:
  371. /* e.g. a load from poisoned memory */
  372. return MCA_IS_LOCAL;
  373. case 1:
  374. case 2:
  375. case 3:
  376. return MCA_IS_GLOBAL;
  377. }
  378. return MCA_IS_GLOBAL;
  379. }
  380. /**
  381. * get_target_identifier - Get the valid Cache or Bus check target identifier.
  382. * @peidx: pointer of index of processor error section
  383. *
  384. * Return value:
  385. * target address on Success / 0 on Failure
  386. */
  387. static u64
  388. get_target_identifier(peidx_table_t *peidx)
  389. {
  390. u64 target_address = 0;
  391. sal_log_mod_error_info_t *smei;
  392. pal_cache_check_info_t *pcci;
  393. int i, level = 9;
  394. /*
  395. * Look through the cache checks for a valid target identifier
  396. * If more than one valid target identifier, return the one
  397. * with the lowest cache level.
  398. */
  399. for (i = 0; i < peidx_cache_check_num(peidx); i++) {
  400. smei = (sal_log_mod_error_info_t *)peidx_cache_check(peidx, i);
  401. if (smei->valid.target_identifier && smei->target_identifier) {
  402. pcci = (pal_cache_check_info_t *)&(smei->check_info);
  403. if (!target_address || (pcci->level < level)) {
  404. target_address = smei->target_identifier;
  405. level = pcci->level;
  406. continue;
  407. }
  408. }
  409. }
  410. if (target_address)
  411. return target_address;
  412. /*
  413. * Look at the bus check for a valid target identifier
  414. */
  415. smei = peidx_bus_check(peidx, 0);
  416. if (smei && smei->valid.target_identifier)
  417. return smei->target_identifier;
  418. return 0;
  419. }
  420. /**
  421. * recover_from_read_error - Try to recover the errors which type are "read"s.
  422. * @slidx: pointer of index of SAL error record
  423. * @peidx: pointer of index of processor error section
  424. * @pbci: pointer of pal_bus_check_info
  425. * @sos: pointer to hand off struct between SAL and OS
  426. *
  427. * Return value:
  428. * 1 on Success / 0 on Failure
  429. */
  430. static int
  431. recover_from_read_error(slidx_table_t *slidx,
  432. peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  433. struct ia64_sal_os_state *sos)
  434. {
  435. u64 target_identifier;
  436. pal_min_state_area_t *pmsa;
  437. struct ia64_psr *psr1, *psr2;
  438. ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
  439. /* Is target address valid? */
  440. target_identifier = get_target_identifier(peidx);
  441. if (!target_identifier)
  442. return fatal_mca("target address not valid");
  443. /*
  444. * cpu read or memory-mapped io read
  445. *
  446. * offending process affected process OS MCA do
  447. * kernel mode kernel mode down system
  448. * kernel mode user mode kill the process
  449. * user mode kernel mode down system (*)
  450. * user mode user mode kill the process
  451. *
  452. * (*) You could terminate offending user-mode process
  453. * if (pbci->pv && pbci->pl != 0) *and* if you sure
  454. * the process not have any locks of kernel.
  455. */
  456. /* Is minstate valid? */
  457. if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
  458. return fatal_mca("minstate not valid");
  459. psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
  460. psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
  461. /*
  462. * Check the privilege level of interrupted context.
  463. * If it is user-mode, then terminate affected process.
  464. */
  465. pmsa = sos->pal_min_state;
  466. if (psr1->cpl != 0 ||
  467. ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
  468. /*
  469. * setup for resume to bottom half of MCA,
  470. * "mca_handler_bhhook"
  471. */
  472. /* pass to bhhook as argument (gr8, ...) */
  473. pmsa->pmsa_gr[8-1] = target_identifier;
  474. pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
  475. pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
  476. /* set interrupted return address (but no use) */
  477. pmsa->pmsa_br0 = pmsa->pmsa_iip;
  478. /* change resume address to bottom half */
  479. pmsa->pmsa_iip = mca_hdlr_bh->fp;
  480. pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
  481. /* set cpl with kernel mode */
  482. psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
  483. psr2->cpl = 0;
  484. psr2->ri = 0;
  485. psr2->bn = 1;
  486. psr2->i = 0;
  487. return mca_recovered("user memory corruption. "
  488. "kill affected process - recovered.");
  489. }
  490. return fatal_mca("kernel context not recovered, iip 0x%lx\n",
  491. pmsa->pmsa_iip);
  492. }
  493. /**
  494. * recover_from_platform_error - Recover from platform error.
  495. * @slidx: pointer of index of SAL error record
  496. * @peidx: pointer of index of processor error section
  497. * @pbci: pointer of pal_bus_check_info
  498. * @sos: pointer to hand off struct between SAL and OS
  499. *
  500. * Return value:
  501. * 1 on Success / 0 on Failure
  502. */
  503. static int
  504. recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
  505. pal_bus_check_info_t *pbci,
  506. struct ia64_sal_os_state *sos)
  507. {
  508. int status = 0;
  509. pal_processor_state_info_t *psp =
  510. (pal_processor_state_info_t*)peidx_psp(peidx);
  511. if (psp->bc && pbci->eb && pbci->bsi == 0) {
  512. switch(pbci->type) {
  513. case 1: /* partial read */
  514. case 3: /* full line(cpu) read */
  515. case 9: /* I/O space read */
  516. status = recover_from_read_error(slidx, peidx, pbci,
  517. sos);
  518. break;
  519. case 0: /* unknown */
  520. case 2: /* partial write */
  521. case 4: /* full line write */
  522. case 5: /* implicit or explicit write-back operation */
  523. case 6: /* snoop probe */
  524. case 7: /* incoming or outgoing ptc.g */
  525. case 8: /* write coalescing transactions */
  526. case 10: /* I/O space write */
  527. case 11: /* inter-processor interrupt message(IPI) */
  528. case 12: /* interrupt acknowledge or
  529. external task priority cycle */
  530. default:
  531. break;
  532. }
  533. } else if (psp->cc && !psp->bc) { /* Cache error */
  534. status = recover_from_read_error(slidx, peidx, pbci, sos);
  535. }
  536. return status;
  537. }
  538. /*
  539. * recover_from_tlb_check
  540. * @peidx: pointer of index of processor error section
  541. *
  542. * Return value:
  543. * 1 on Success / 0 on Failure
  544. */
  545. static int
  546. recover_from_tlb_check(peidx_table_t *peidx)
  547. {
  548. sal_log_mod_error_info_t *smei;
  549. pal_tlb_check_info_t *ptci;
  550. smei = (sal_log_mod_error_info_t *)peidx_tlb_check(peidx, 0);
  551. ptci = (pal_tlb_check_info_t *)&(smei->check_info);
  552. /*
  553. * Look for signature of a duplicate TLB DTC entry, which is
  554. * a SW bug and always fatal.
  555. */
  556. if (ptci->op == PAL_TLB_CHECK_OP_PURGE
  557. && !(ptci->itr || ptci->dtc || ptci->itc))
  558. return fatal_mca("Duplicate TLB entry");
  559. return mca_recovered("TLB check recovered");
  560. }
  561. /**
  562. * recover_from_processor_error
  563. * @platform: whether there are some platform error section or not
  564. * @slidx: pointer of index of SAL error record
  565. * @peidx: pointer of index of processor error section
  566. * @pbci: pointer of pal_bus_check_info
  567. * @sos: pointer to hand off struct between SAL and OS
  568. *
  569. * Return value:
  570. * 1 on Success / 0 on Failure
  571. */
  572. static int
  573. recover_from_processor_error(int platform, slidx_table_t *slidx,
  574. peidx_table_t *peidx, pal_bus_check_info_t *pbci,
  575. struct ia64_sal_os_state *sos)
  576. {
  577. pal_processor_state_info_t *psp =
  578. (pal_processor_state_info_t*)peidx_psp(peidx);
  579. /*
  580. * Processor recovery status must key off of the PAL recovery
  581. * status in the Processor State Parameter.
  582. */
  583. /*
  584. * The machine check is corrected.
  585. */
  586. if (psp->cm == 1)
  587. return mca_recovered("machine check is already corrected.");
  588. /*
  589. * The error was not contained. Software must be reset.
  590. */
  591. if (psp->us || psp->ci == 0)
  592. return fatal_mca("error not contained");
  593. /*
  594. * Look for recoverable TLB check
  595. */
  596. if (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
  597. return recover_from_tlb_check(peidx);
  598. /*
  599. * The cache check and bus check bits have four possible states
  600. * cc bc
  601. * 1 1 Memory error, attempt recovery
  602. * 1 0 Cache error, attempt recovery
  603. * 0 1 I/O error, attempt recovery
  604. * 0 0 Other error type, not recovered
  605. */
  606. if (psp->cc == 0 && (psp->bc == 0 || pbci == NULL))
  607. return fatal_mca("No cache or bus check");
  608. /*
  609. * Cannot handle more than one bus check.
  610. */
  611. if (peidx_bus_check_num(peidx) > 1)
  612. return fatal_mca("Too many bus checks");
  613. if (pbci->ib)
  614. return fatal_mca("Internal Bus error");
  615. if (pbci->eb && pbci->bsi > 0)
  616. return fatal_mca("External bus check fatal status");
  617. /*
  618. * This is a local MCA and estimated as a recoverable error.
  619. */
  620. if (platform)
  621. return recover_from_platform_error(slidx, peidx, pbci, sos);
  622. /*
  623. * On account of strange SAL error record, we cannot recover.
  624. */
  625. return fatal_mca("Strange SAL record");
  626. }
  627. /**
  628. * mca_try_to_recover - Try to recover from MCA
  629. * @rec: pointer to a SAL error record
  630. * @sos: pointer to hand off struct between SAL and OS
  631. *
  632. * Return value:
  633. * 1 on Success / 0 on Failure
  634. */
  635. static int
  636. mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
  637. {
  638. int platform_err;
  639. int n_proc_err;
  640. slidx_table_t slidx;
  641. peidx_table_t peidx;
  642. pal_bus_check_info_t pbci;
  643. /* Make index of SAL error record */
  644. platform_err = mca_make_slidx(rec, &slidx);
  645. /* Count processor error sections */
  646. n_proc_err = slidx_count(&slidx, proc_err);
  647. /* Now, OS can recover when there is one processor error section */
  648. if (n_proc_err > 1)
  649. return fatal_mca("Too Many Errors");
  650. else if (n_proc_err == 0)
  651. /* Weird SAL record ... We can't do anything */
  652. return fatal_mca("Weird SAL record");
  653. /* Make index of processor error section */
  654. mca_make_peidx((sal_log_processor_info_t*)
  655. slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
  656. /* Extract Processor BUS_CHECK[0] */
  657. *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
  658. /* Check whether MCA is global or not */
  659. if (is_mca_global(&peidx, &pbci, sos))
  660. return fatal_mca("global MCA");
  661. /* Try to recover a processor error */
  662. return recover_from_processor_error(platform_err, &slidx, &peidx,
  663. &pbci, sos);
  664. }
  665. /*
  666. * =============================================================================
  667. */
  668. int __init mca_external_handler_init(void)
  669. {
  670. if (init_record_index_pools())
  671. return -ENOMEM;
  672. /* register external mca handlers */
  673. if (ia64_reg_MCA_extension(mca_try_to_recover)) {
  674. printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
  675. kfree(slidx_pool.buffer);
  676. return -EFAULT;
  677. }
  678. return 0;
  679. }
  680. void __exit mca_external_handler_exit(void)
  681. {
  682. /* unregister external mca handlers */
  683. ia64_unreg_MCA_extension();
  684. kfree(slidx_pool.buffer);
  685. }
  686. module_init(mca_external_handler_init);
  687. module_exit(mca_external_handler_exit);
  688. module_param(sal_rec_max, int, 0644);
  689. MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
  690. MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
  691. MODULE_LICENSE("GPL");