xref: /onnv-gate/usr/src/uts/sun4u/os/ecc.c (revision 1338:c2e71173ece3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1338Selowe  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/conf.h>
310Sstevel@tonic-gate #include <sys/ddi.h>
320Sstevel@tonic-gate #include <sys/systm.h>
330Sstevel@tonic-gate #include <sys/sysmacros.h>
340Sstevel@tonic-gate #include <sys/param.h>
350Sstevel@tonic-gate #include <sys/mutex.h>
360Sstevel@tonic-gate #include <sys/kmem.h>
370Sstevel@tonic-gate #include <sys/machparam.h>
380Sstevel@tonic-gate #include <sys/machsystm.h>
390Sstevel@tonic-gate #include <sys/machthread.h>
400Sstevel@tonic-gate #include <sys/cpu.h>
410Sstevel@tonic-gate #include <sys/cpuvar.h>
420Sstevel@tonic-gate #include <vm/page.h>
430Sstevel@tonic-gate #include <vm/hat.h>
440Sstevel@tonic-gate #include <vm/seg.h>
450Sstevel@tonic-gate #include <vm/seg_kmem.h>
460Sstevel@tonic-gate #include <sys/vmsystm.h>
470Sstevel@tonic-gate #include <sys/vmem.h>
480Sstevel@tonic-gate #include <sys/mman.h>
490Sstevel@tonic-gate #include <sys/cmn_err.h>
500Sstevel@tonic-gate #include <sys/time.h>
510Sstevel@tonic-gate #include <sys/async.h>
520Sstevel@tonic-gate #include <sys/spl.h>
530Sstevel@tonic-gate #include <sys/trap.h>
540Sstevel@tonic-gate #include <sys/machtrap.h>
550Sstevel@tonic-gate #include <sys/promif.h>
560Sstevel@tonic-gate #include <sys/prom_plat.h>
570Sstevel@tonic-gate #include <sys/debug.h>
580Sstevel@tonic-gate #include <sys/x_call.h>
590Sstevel@tonic-gate #include <sys/membar.h>
600Sstevel@tonic-gate #include <sys/ivintr.h>
610Sstevel@tonic-gate #include <sys/cred.h>
620Sstevel@tonic-gate #include <sys/cpu_module.h>
630Sstevel@tonic-gate #include <sys/ontrap.h>
640Sstevel@tonic-gate #include <sys/sdt.h>
650Sstevel@tonic-gate #include <sys/errorq.h>
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #define	MAX_CE_FLTS	10
680Sstevel@tonic-gate #define	MAX_ASYNC_FLTS	6
690Sstevel@tonic-gate 
700Sstevel@tonic-gate errorq_t *ue_queue;			/* queue of uncorrectable errors */
710Sstevel@tonic-gate errorq_t *ce_queue;			/* queue of correctable errors */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * ce_verbose_memory - covers CEs in DIMMs
750Sstevel@tonic-gate  * ce_verbose_other - covers "others" (ecache, IO, etc.)
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  * If the value is 0, nothing is logged.
780Sstevel@tonic-gate  * If the value is 1, the error is logged to the log file, but not console.
790Sstevel@tonic-gate  * If the value is 2, the error is logged to the log file and console.
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate int	ce_verbose_memory = 1;
820Sstevel@tonic-gate int	ce_verbose_other = 1;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate int	ce_show_data = 0;
850Sstevel@tonic-gate int	ce_debug = 0;
860Sstevel@tonic-gate int	ue_debug = 0;
870Sstevel@tonic-gate int	reset_debug = 0;
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * Tunables for controlling the handling of asynchronous faults (AFTs). Setting
910Sstevel@tonic-gate  * these to non-default values on a non-DEBUG kernel is NOT supported.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate int	aft_verbose = 0;	/* log AFT messages > 1 to log only */
940Sstevel@tonic-gate int	aft_panic = 0;		/* panic (not reboot) on fatal usermode AFLT */
950Sstevel@tonic-gate int	aft_testfatal = 0;	/* force all AFTs to panic immediately */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate  * Panic_* variables specific to the AFT code.  These are used to record
990Sstevel@tonic-gate  * information that the platform-specific code will need once we panic.
1000Sstevel@tonic-gate  */
1010Sstevel@tonic-gate struct async_flt panic_aflt;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * Defined in bus_func.c but initialised in error_init
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate extern kmutex_t bfd_lock;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * Common bus driver async error logging routine.  This routine can be shared
1100Sstevel@tonic-gate  * by all sun4u CPUs (unlike cpu_async_log_err) because we are assuming that
1110Sstevel@tonic-gate  * if an i/o bus error required a panic, the error interrupt handler will
1120Sstevel@tonic-gate  * enqueue the error and call panic itself.
1130Sstevel@tonic-gate  */
1140Sstevel@tonic-gate void
bus_async_log_err(struct async_flt * aflt)1150Sstevel@tonic-gate bus_async_log_err(struct async_flt *aflt)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	char unum[UNUM_NAMLEN];
1180Sstevel@tonic-gate 	int len;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/*
1210Sstevel@tonic-gate 	 * Call back into the processor specific routine
1220Sstevel@tonic-gate 	 * to check for cpu related errors that may
1230Sstevel@tonic-gate 	 * have resulted in this error. (E.g. copyout trap)
1240Sstevel@tonic-gate 	 */
1250Sstevel@tonic-gate 	if (aflt->flt_in_memory)
1260Sstevel@tonic-gate 		cpu_check_allcpus(aflt);
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	/*
1290Sstevel@tonic-gate 	 * Note that aflt->flt_stat is not the CPU afsr.
1300Sstevel@tonic-gate 	 */
1310Sstevel@tonic-gate 	(void) cpu_get_mem_unum_aflt(AFLT_STAT_INVALID, aflt,
1320Sstevel@tonic-gate 		    unum, UNUM_NAMLEN, &len);
1330Sstevel@tonic-gate 	aflt->flt_func(aflt, unum);
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * ecc_cpu_call called from bus drain functions to run cpu
1380Sstevel@tonic-gate  * specific functions to check other cpus and get the unum.
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate void
ecc_cpu_call(struct async_flt * ecc,char * unum,int err_type)1410Sstevel@tonic-gate ecc_cpu_call(struct async_flt *ecc, char *unum, int err_type)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate 	int len;
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	/*
1460Sstevel@tonic-gate 	 * Call back into the processor
1470Sstevel@tonic-gate 	 * specific routine to check for cpu related errors
1480Sstevel@tonic-gate 	 * that may have resulted in this error.
1490Sstevel@tonic-gate 	 * (E.g. copyout trap)
1500Sstevel@tonic-gate 	 */
1510Sstevel@tonic-gate 	if (ecc->flt_in_memory)
1520Sstevel@tonic-gate 		cpu_check_allcpus(ecc);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	(void) cpu_get_mem_unum(AFLT_STAT_VALID, ecc->flt_synd,
1550Sstevel@tonic-gate 					(uint64_t)-1, ecc->flt_addr,
1560Sstevel@tonic-gate 					ecc->flt_bus_id, ecc->flt_in_memory,
1570Sstevel@tonic-gate 					ecc->flt_status, unum,
1580Sstevel@tonic-gate 					UNUM_NAMLEN, &len);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	if (err_type == ECC_IO_CE)
1610Sstevel@tonic-gate 		cpu_ce_count_unum(ecc, len, unum);
1620Sstevel@tonic-gate }
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate  * Handler to process a fatal error.  This routine can be called from a
1660Sstevel@tonic-gate  * softint, called from trap()'s AST handling, or called from the panic flow.
1670Sstevel@tonic-gate  */
1680Sstevel@tonic-gate /*ARGSUSED*/
1690Sstevel@tonic-gate static void
ue_drain(void * ignored,struct async_flt * aflt,errorq_elem_t * eqep)1700Sstevel@tonic-gate ue_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate 	cpu_ue_log_err(aflt);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * Handler to process a correctable error.  This routine can be called from a
1770Sstevel@tonic-gate  * softint.  We just call the CPU module's logging routine.
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate /*ARGSUSED*/
1800Sstevel@tonic-gate static void
ce_drain(void * ignored,struct async_flt * aflt,errorq_elem_t * eqep)1810Sstevel@tonic-gate ce_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	cpu_ce_log_err(aflt, eqep);
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate  * Scrub a non-fatal correctable ecc error.
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate void
ce_scrub(struct async_flt * aflt)1900Sstevel@tonic-gate ce_scrub(struct async_flt *aflt)
1910Sstevel@tonic-gate {
1920Sstevel@tonic-gate 	if (aflt->flt_in_memory)
1930Sstevel@tonic-gate 		cpu_ce_scrub_mem_err(aflt, B_FALSE);
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate /*
1970Sstevel@tonic-gate  * Allocate error queue sizes based on max_ncpus.  max_ncpus is set just
1980Sstevel@tonic-gate  * after ncpunode has been determined.  ncpus is set in start_other_cpus
1990Sstevel@tonic-gate  * which is called after error_init() but may change dynamically.
2000Sstevel@tonic-gate  */
2010Sstevel@tonic-gate void
error_init(void)2020Sstevel@tonic-gate error_init(void)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate 	char tmp_name[MAXSYSNAME];
205789Sahrens 	pnode_t node;
2060Sstevel@tonic-gate 	size_t size = cpu_aflt_size();
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate 	/*
2090Sstevel@tonic-gate 	 * Initialize the correctable and uncorrectable error queues.
2100Sstevel@tonic-gate 	 */
2110Sstevel@tonic-gate 	ue_queue = errorq_create("ue_queue", (errorq_func_t)ue_drain, NULL,
2120Sstevel@tonic-gate 	    MAX_ASYNC_FLTS * (max_ncpus + 1), size, PIL_2, ERRORQ_VITAL);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	ce_queue = errorq_create("ce_queue", (errorq_func_t)ce_drain, NULL,
2150Sstevel@tonic-gate 	    MAX_CE_FLTS * (max_ncpus + 1), size, PIL_1, 0);
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	if (ue_queue == NULL || ce_queue == NULL)
2180Sstevel@tonic-gate 		panic("failed to create required system error queue");
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	/*
2210Sstevel@tonic-gate 	 * Initialize the busfunc list mutex.  This must be a PIL_15 spin lock
2220Sstevel@tonic-gate 	 * because we will need to acquire it from cpu_async_error().
2230Sstevel@tonic-gate 	 */
2240Sstevel@tonic-gate 	mutex_init(&bfd_lock, NULL, MUTEX_SPIN, (void *)PIL_15);
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	node = prom_rootnode();
2270Sstevel@tonic-gate 	if ((node == OBP_NONODE) || (node == OBP_BADNODE)) {
2280Sstevel@tonic-gate 		cmn_err(CE_CONT, "error_init: node 0x%x\n", (uint_t)node);
2290Sstevel@tonic-gate 		return;
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	if (((size = prom_getproplen(node, "reset-reason")) != -1) &&
2330Sstevel@tonic-gate 	    (size <= MAXSYSNAME) &&
2340Sstevel@tonic-gate 	    (prom_getprop(node, "reset-reason", tmp_name) != -1)) {
2350Sstevel@tonic-gate 		if (reset_debug) {
2360Sstevel@tonic-gate 			cmn_err(CE_CONT, "System booting after %s\n", tmp_name);
2370Sstevel@tonic-gate 		} else if (strncmp(tmp_name, "FATAL", 5) == 0) {
2380Sstevel@tonic-gate 			cmn_err(CE_CONT,
2390Sstevel@tonic-gate 			    "System booting after fatal error %s\n", tmp_name);
2400Sstevel@tonic-gate 		}
2410Sstevel@tonic-gate 	}
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	if (&cpu_error_init) {
2440Sstevel@tonic-gate 		cpu_error_init((MAX_ASYNC_FLTS + MAX_CE_FLTS) *
2450Sstevel@tonic-gate 		    (max_ncpus + 1));
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate /*
250917Selowe  * Flags for ecc_page_zero DTrace probe since ecc_page_zero() is called
251917Selowe  * as a softint handler.
2520Sstevel@tonic-gate  */
2530Sstevel@tonic-gate #define	PAGE_ZERO_SUCCESS	0
2540Sstevel@tonic-gate #define	PAGE_ZERO_FAIL_NOLOCK	1
2550Sstevel@tonic-gate #define	PAGE_ZERO_FAIL_ONTRAP	2
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate void
ecc_page_zero(void * arg)2580Sstevel@tonic-gate ecc_page_zero(void *arg)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate 	uint64_t pa = (uint64_t)arg;
2610Sstevel@tonic-gate 	int ret, success_flag;
262917Selowe 	page_t *pp = page_numtopp_nolock(mmu_btop(pa));
2630Sstevel@tonic-gate 
264917Selowe 	if (page_retire_check(pa, NULL) != 0)
2650Sstevel@tonic-gate 		return;
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	/*
2680Sstevel@tonic-gate 	 * Must hold a lock on the page before calling pagezero()
2690Sstevel@tonic-gate 	 *
2700Sstevel@tonic-gate 	 * This will only fail if someone has or wants an exclusive lock on
2710Sstevel@tonic-gate 	 * the page.  Since it's a retired page, this shouldn't happen.
2720Sstevel@tonic-gate 	 */
273*1338Selowe 	ret = page_lock_es(pp, SE_SHARED, (kmutex_t *)NULL,
274*1338Selowe 	    P_NO_RECLAIM, SE_RETIRED);
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	if (ret > 0) {
2770Sstevel@tonic-gate 		on_trap_data_t otd;
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 		/*
2800Sstevel@tonic-gate 		 * Protect pagezero() from async faults
2810Sstevel@tonic-gate 		 */
2820Sstevel@tonic-gate 		if (!on_trap(&otd, OT_DATA_EC)) {
2830Sstevel@tonic-gate 			pagezero(pp, 0, PAGESIZE);
2840Sstevel@tonic-gate 			success_flag = PAGE_ZERO_SUCCESS;
2850Sstevel@tonic-gate 		} else {
2860Sstevel@tonic-gate 			success_flag = PAGE_ZERO_FAIL_ONTRAP;
2870Sstevel@tonic-gate 		}
2880Sstevel@tonic-gate 		no_trap();
2890Sstevel@tonic-gate 		page_unlock(pp);
2900Sstevel@tonic-gate 	} else {
2910Sstevel@tonic-gate 		success_flag = PAGE_ZERO_FAIL_NOLOCK;
2920Sstevel@tonic-gate 	}
2930Sstevel@tonic-gate 	DTRACE_PROBE2(page_zero_result, int, success_flag, uint64_t, pa);
2940Sstevel@tonic-gate }
295