xref: /onnv-gate/usr/src/uts/sun4u/os/ecc.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/conf.h>
31*0Sstevel@tonic-gate #include <sys/ddi.h>
32*0Sstevel@tonic-gate #include <sys/systm.h>
33*0Sstevel@tonic-gate #include <sys/sysmacros.h>
34*0Sstevel@tonic-gate #include <sys/param.h>
35*0Sstevel@tonic-gate #include <sys/mutex.h>
36*0Sstevel@tonic-gate #include <sys/kmem.h>
37*0Sstevel@tonic-gate #include <sys/machparam.h>
38*0Sstevel@tonic-gate #include <sys/machsystm.h>
39*0Sstevel@tonic-gate #include <sys/machthread.h>
40*0Sstevel@tonic-gate #include <sys/cpu.h>
41*0Sstevel@tonic-gate #include <sys/cpuvar.h>
42*0Sstevel@tonic-gate #include <vm/page.h>
43*0Sstevel@tonic-gate #include <vm/hat.h>
44*0Sstevel@tonic-gate #include <vm/seg.h>
45*0Sstevel@tonic-gate #include <vm/seg_kmem.h>
46*0Sstevel@tonic-gate #include <sys/vmsystm.h>
47*0Sstevel@tonic-gate #include <sys/vmem.h>
48*0Sstevel@tonic-gate #include <sys/mman.h>
49*0Sstevel@tonic-gate #include <sys/cmn_err.h>
50*0Sstevel@tonic-gate #include <sys/time.h>
51*0Sstevel@tonic-gate #include <sys/async.h>
52*0Sstevel@tonic-gate #include <sys/spl.h>
53*0Sstevel@tonic-gate #include <sys/trap.h>
54*0Sstevel@tonic-gate #include <sys/machtrap.h>
55*0Sstevel@tonic-gate #include <sys/promif.h>
56*0Sstevel@tonic-gate #include <sys/prom_plat.h>
57*0Sstevel@tonic-gate #include <sys/debug.h>
58*0Sstevel@tonic-gate #include <sys/x_call.h>
59*0Sstevel@tonic-gate #include <sys/membar.h>
60*0Sstevel@tonic-gate #include <sys/ivintr.h>
61*0Sstevel@tonic-gate #include <sys/cred.h>
62*0Sstevel@tonic-gate #include <sys/cpu_module.h>
63*0Sstevel@tonic-gate #include <sys/ontrap.h>
64*0Sstevel@tonic-gate #include <sys/sdt.h>
65*0Sstevel@tonic-gate #include <sys/errorq.h>
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate #define	MAX_CE_FLTS	10
68*0Sstevel@tonic-gate #define	MAX_ASYNC_FLTS	6
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate errorq_t *ue_queue;			/* queue of uncorrectable errors */
71*0Sstevel@tonic-gate errorq_t *ce_queue;			/* queue of correctable errors */
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate  * ce_verbose_memory - covers CEs in DIMMs
75*0Sstevel@tonic-gate  * ce_verbose_other - covers "others" (ecache, IO, etc.)
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  * If the value is 0, nothing is logged.
78*0Sstevel@tonic-gate  * If the value is 1, the error is logged to the log file, but not console.
79*0Sstevel@tonic-gate  * If the value is 2, the error is logged to the log file and console.
80*0Sstevel@tonic-gate  */
81*0Sstevel@tonic-gate int	ce_verbose_memory = 1;
82*0Sstevel@tonic-gate int	ce_verbose_other = 1;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate int	ce_show_data = 0;
85*0Sstevel@tonic-gate int	ce_debug = 0;
86*0Sstevel@tonic-gate int	ue_debug = 0;
87*0Sstevel@tonic-gate int	reset_debug = 0;
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * Tunables for controlling the handling of asynchronous faults (AFTs). Setting
91*0Sstevel@tonic-gate  * these to non-default values on a non-DEBUG kernel is NOT supported.
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate int	aft_verbose = 0;	/* log AFT messages > 1 to log only */
94*0Sstevel@tonic-gate int	aft_panic = 0;		/* panic (not reboot) on fatal usermode AFLT */
95*0Sstevel@tonic-gate int	aft_testfatal = 0;	/* force all AFTs to panic immediately */
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate /*
98*0Sstevel@tonic-gate  * Panic_* variables specific to the AFT code.  These are used to record
99*0Sstevel@tonic-gate  * information that the platform-specific code will need once we panic.
100*0Sstevel@tonic-gate  */
101*0Sstevel@tonic-gate struct async_flt panic_aflt;
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate /*
104*0Sstevel@tonic-gate  * Defined in bus_func.c but initialised in error_init
105*0Sstevel@tonic-gate  */
106*0Sstevel@tonic-gate extern kmutex_t bfd_lock;
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate  * Common bus driver async error logging routine.  This routine can be shared
110*0Sstevel@tonic-gate  * by all sun4u CPUs (unlike cpu_async_log_err) because we are assuming that
111*0Sstevel@tonic-gate  * if an i/o bus error required a panic, the error interrupt handler will
112*0Sstevel@tonic-gate  * enqueue the error and call panic itself.
113*0Sstevel@tonic-gate  */
114*0Sstevel@tonic-gate void
115*0Sstevel@tonic-gate bus_async_log_err(struct async_flt *aflt)
116*0Sstevel@tonic-gate {
117*0Sstevel@tonic-gate 	char unum[UNUM_NAMLEN];
118*0Sstevel@tonic-gate 	int len;
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 	/*
121*0Sstevel@tonic-gate 	 * Call back into the processor specific routine
122*0Sstevel@tonic-gate 	 * to check for cpu related errors that may
123*0Sstevel@tonic-gate 	 * have resulted in this error. (E.g. copyout trap)
124*0Sstevel@tonic-gate 	 */
125*0Sstevel@tonic-gate 	if (aflt->flt_in_memory)
126*0Sstevel@tonic-gate 		cpu_check_allcpus(aflt);
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 	/*
129*0Sstevel@tonic-gate 	 * Note that aflt->flt_stat is not the CPU afsr.
130*0Sstevel@tonic-gate 	 */
131*0Sstevel@tonic-gate 	(void) cpu_get_mem_unum_aflt(AFLT_STAT_INVALID, aflt,
132*0Sstevel@tonic-gate 		    unum, UNUM_NAMLEN, &len);
133*0Sstevel@tonic-gate 	aflt->flt_func(aflt, unum);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /*
137*0Sstevel@tonic-gate  * ecc_cpu_call called from bus drain functions to run cpu
138*0Sstevel@tonic-gate  * specific functions to check other cpus and get the unum.
139*0Sstevel@tonic-gate  */
140*0Sstevel@tonic-gate void
141*0Sstevel@tonic-gate ecc_cpu_call(struct async_flt *ecc, char *unum, int err_type)
142*0Sstevel@tonic-gate {
143*0Sstevel@tonic-gate 	int len;
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 	/*
146*0Sstevel@tonic-gate 	 * Call back into the processor
147*0Sstevel@tonic-gate 	 * specific routine to check for cpu related errors
148*0Sstevel@tonic-gate 	 * that may have resulted in this error.
149*0Sstevel@tonic-gate 	 * (E.g. copyout trap)
150*0Sstevel@tonic-gate 	 */
151*0Sstevel@tonic-gate 	if (ecc->flt_in_memory)
152*0Sstevel@tonic-gate 		cpu_check_allcpus(ecc);
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 	(void) cpu_get_mem_unum(AFLT_STAT_VALID, ecc->flt_synd,
155*0Sstevel@tonic-gate 					(uint64_t)-1, ecc->flt_addr,
156*0Sstevel@tonic-gate 					ecc->flt_bus_id, ecc->flt_in_memory,
157*0Sstevel@tonic-gate 					ecc->flt_status, unum,
158*0Sstevel@tonic-gate 					UNUM_NAMLEN, &len);
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	if (err_type == ECC_IO_CE)
161*0Sstevel@tonic-gate 		cpu_ce_count_unum(ecc, len, unum);
162*0Sstevel@tonic-gate }
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate /*
165*0Sstevel@tonic-gate  * Handler to process a fatal error.  This routine can be called from a
166*0Sstevel@tonic-gate  * softint, called from trap()'s AST handling, or called from the panic flow.
167*0Sstevel@tonic-gate  */
168*0Sstevel@tonic-gate /*ARGSUSED*/
169*0Sstevel@tonic-gate static void
170*0Sstevel@tonic-gate ue_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
171*0Sstevel@tonic-gate {
172*0Sstevel@tonic-gate 	cpu_ue_log_err(aflt);
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate  * Handler to process a correctable error.  This routine can be called from a
177*0Sstevel@tonic-gate  * softint.  We just call the CPU module's logging routine.
178*0Sstevel@tonic-gate  */
179*0Sstevel@tonic-gate /*ARGSUSED*/
180*0Sstevel@tonic-gate static void
181*0Sstevel@tonic-gate ce_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
182*0Sstevel@tonic-gate {
183*0Sstevel@tonic-gate 	cpu_ce_log_err(aflt, eqep);
184*0Sstevel@tonic-gate }
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate /*
187*0Sstevel@tonic-gate  * Scrub a non-fatal correctable ecc error.
188*0Sstevel@tonic-gate  */
189*0Sstevel@tonic-gate void
190*0Sstevel@tonic-gate ce_scrub(struct async_flt *aflt)
191*0Sstevel@tonic-gate {
192*0Sstevel@tonic-gate 	if (aflt->flt_in_memory)
193*0Sstevel@tonic-gate 		cpu_ce_scrub_mem_err(aflt, B_FALSE);
194*0Sstevel@tonic-gate }
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate /*
197*0Sstevel@tonic-gate  * Allocate error queue sizes based on max_ncpus.  max_ncpus is set just
198*0Sstevel@tonic-gate  * after ncpunode has been determined.  ncpus is set in start_other_cpus
199*0Sstevel@tonic-gate  * which is called after error_init() but may change dynamically.
200*0Sstevel@tonic-gate  */
201*0Sstevel@tonic-gate void
202*0Sstevel@tonic-gate error_init(void)
203*0Sstevel@tonic-gate {
204*0Sstevel@tonic-gate 	char tmp_name[MAXSYSNAME];
205*0Sstevel@tonic-gate 	dnode_t node;
206*0Sstevel@tonic-gate 	size_t size = cpu_aflt_size();
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 	/*
209*0Sstevel@tonic-gate 	 * Initialize the correctable and uncorrectable error queues.
210*0Sstevel@tonic-gate 	 */
211*0Sstevel@tonic-gate 	ue_queue = errorq_create("ue_queue", (errorq_func_t)ue_drain, NULL,
212*0Sstevel@tonic-gate 	    MAX_ASYNC_FLTS * (max_ncpus + 1), size, PIL_2, ERRORQ_VITAL);
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 	ce_queue = errorq_create("ce_queue", (errorq_func_t)ce_drain, NULL,
215*0Sstevel@tonic-gate 	    MAX_CE_FLTS * (max_ncpus + 1), size, PIL_1, 0);
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 	if (ue_queue == NULL || ce_queue == NULL)
218*0Sstevel@tonic-gate 		panic("failed to create required system error queue");
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 	/*
221*0Sstevel@tonic-gate 	 * Initialize the busfunc list mutex.  This must be a PIL_15 spin lock
222*0Sstevel@tonic-gate 	 * because we will need to acquire it from cpu_async_error().
223*0Sstevel@tonic-gate 	 */
224*0Sstevel@tonic-gate 	mutex_init(&bfd_lock, NULL, MUTEX_SPIN, (void *)PIL_15);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	node = prom_rootnode();
227*0Sstevel@tonic-gate 	if ((node == OBP_NONODE) || (node == OBP_BADNODE)) {
228*0Sstevel@tonic-gate 		cmn_err(CE_CONT, "error_init: node 0x%x\n", (uint_t)node);
229*0Sstevel@tonic-gate 		return;
230*0Sstevel@tonic-gate 	}
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate 	if (((size = prom_getproplen(node, "reset-reason")) != -1) &&
233*0Sstevel@tonic-gate 	    (size <= MAXSYSNAME) &&
234*0Sstevel@tonic-gate 	    (prom_getprop(node, "reset-reason", tmp_name) != -1)) {
235*0Sstevel@tonic-gate 		if (reset_debug) {
236*0Sstevel@tonic-gate 			cmn_err(CE_CONT, "System booting after %s\n", tmp_name);
237*0Sstevel@tonic-gate 		} else if (strncmp(tmp_name, "FATAL", 5) == 0) {
238*0Sstevel@tonic-gate 			cmn_err(CE_CONT,
239*0Sstevel@tonic-gate 			    "System booting after fatal error %s\n", tmp_name);
240*0Sstevel@tonic-gate 		}
241*0Sstevel@tonic-gate 	}
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	if (&cpu_error_init) {
244*0Sstevel@tonic-gate 		cpu_error_init((MAX_ASYNC_FLTS + MAX_CE_FLTS) *
245*0Sstevel@tonic-gate 		    (max_ncpus + 1));
246*0Sstevel@tonic-gate 	}
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate /*
250*0Sstevel@tonic-gate  * Success flags for ecc_page_zero
251*0Sstevel@tonic-gate  */
252*0Sstevel@tonic-gate #define	PAGE_ZERO_SUCCESS	0
253*0Sstevel@tonic-gate #define	PAGE_ZERO_FAIL_NOLOCK	1
254*0Sstevel@tonic-gate #define	PAGE_ZERO_FAIL_ONTRAP	2
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate /*
257*0Sstevel@tonic-gate  * arg is a physical address - zero out the page that contains it
258*0Sstevel@tonic-gate  */
259*0Sstevel@tonic-gate void
260*0Sstevel@tonic-gate ecc_page_zero(void *arg)
261*0Sstevel@tonic-gate {
262*0Sstevel@tonic-gate 	uint64_t pa = (uint64_t)arg;
263*0Sstevel@tonic-gate 	page_t *pp = page_numtopp_nolock((pfn_t)(pa >> MMU_PAGESHIFT));
264*0Sstevel@tonic-gate 	int ret, success_flag;
265*0Sstevel@tonic-gate 
266*0Sstevel@tonic-gate 	if (pp == NULL || !page_isretired(pp))
267*0Sstevel@tonic-gate 		return;
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 	/*
270*0Sstevel@tonic-gate 	 * Must hold a lock on the page before calling pagezero()
271*0Sstevel@tonic-gate 	 *
272*0Sstevel@tonic-gate 	 * This will only fail if someone has or wants an exclusive lock on
273*0Sstevel@tonic-gate 	 * the page.  Since it's a retired page, this shouldn't happen.
274*0Sstevel@tonic-gate 	 */
275*0Sstevel@tonic-gate 	ret = page_lock(pp, SE_SHARED, (kmutex_t *)NULL, P_NO_RECLAIM);
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 	if (ret > 0) {
278*0Sstevel@tonic-gate 		on_trap_data_t otd;
279*0Sstevel@tonic-gate 
280*0Sstevel@tonic-gate 		/*
281*0Sstevel@tonic-gate 		 * Protect pagezero() from async faults
282*0Sstevel@tonic-gate 		 */
283*0Sstevel@tonic-gate 		if (!on_trap(&otd, OT_DATA_EC)) {
284*0Sstevel@tonic-gate 			pagezero(pp, 0, PAGESIZE);
285*0Sstevel@tonic-gate 			success_flag = PAGE_ZERO_SUCCESS;
286*0Sstevel@tonic-gate 		} else {
287*0Sstevel@tonic-gate 			success_flag = PAGE_ZERO_FAIL_ONTRAP;
288*0Sstevel@tonic-gate 		}
289*0Sstevel@tonic-gate 		no_trap();
290*0Sstevel@tonic-gate 		page_unlock(pp);
291*0Sstevel@tonic-gate 	} else {
292*0Sstevel@tonic-gate 		success_flag = PAGE_ZERO_FAIL_NOLOCK;
293*0Sstevel@tonic-gate 	}
294*0Sstevel@tonic-gate 	DTRACE_PROBE2(page_zero_result, int, success_flag, uint64_t, pa);
295*0Sstevel@tonic-gate }
296