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