summaryrefslogtreecommitdiff
path: root/usr/src/uts/sun4u/os/ecc.c
blob: 4c85b7b0b0e4a6c1022e51aa2271110c5f557299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/systm.h>
#include <sys/sysmacros.h>
#include <sys/param.h>
#include <sys/mutex.h>
#include <sys/kmem.h>
#include <sys/machparam.h>
#include <sys/machsystm.h>
#include <sys/machthread.h>
#include <sys/cpu.h>
#include <sys/cpuvar.h>
#include <vm/page.h>
#include <vm/hat.h>
#include <vm/seg.h>
#include <vm/seg_kmem.h>
#include <sys/vmsystm.h>
#include <sys/vmem.h>
#include <sys/mman.h>
#include <sys/cmn_err.h>
#include <sys/time.h>
#include <sys/async.h>
#include <sys/spl.h>
#include <sys/trap.h>
#include <sys/machtrap.h>
#include <sys/promif.h>
#include <sys/prom_plat.h>
#include <sys/debug.h>
#include <sys/x_call.h>
#include <sys/membar.h>
#include <sys/ivintr.h>
#include <sys/cred.h>
#include <sys/cpu_module.h>
#include <sys/ontrap.h>
#include <sys/sdt.h>
#include <sys/errorq.h>

#define	MAX_CE_FLTS	10
#define	MAX_ASYNC_FLTS	6

errorq_t *ue_queue;			/* queue of uncorrectable errors */
errorq_t *ce_queue;			/* queue of correctable errors */

/*
 * ce_verbose_memory - covers CEs in DIMMs
 * ce_verbose_other - covers "others" (ecache, IO, etc.)
 *
 * If the value is 0, nothing is logged.
 * If the value is 1, the error is logged to the log file, but not console.
 * If the value is 2, the error is logged to the log file and console.
 */
int	ce_verbose_memory = 1;
int	ce_verbose_other = 1;

int	ce_show_data = 0;
int	ce_debug = 0;
int	ue_debug = 0;
int	reset_debug = 0;

/*
 * Tunables for controlling the handling of asynchronous faults (AFTs). Setting
 * these to non-default values on a non-DEBUG kernel is NOT supported.
 */
int	aft_verbose = 0;	/* log AFT messages > 1 to log only */
int	aft_panic = 0;		/* panic (not reboot) on fatal usermode AFLT */
int	aft_testfatal = 0;	/* force all AFTs to panic immediately */

/*
 * Panic_* variables specific to the AFT code.  These are used to record
 * information that the platform-specific code will need once we panic.
 */
struct async_flt panic_aflt;

/*
 * Defined in bus_func.c but initialised in error_init
 */
extern kmutex_t bfd_lock;

/*
 * Common bus driver async error logging routine.  This routine can be shared
 * by all sun4u CPUs (unlike cpu_async_log_err) because we are assuming that
 * if an i/o bus error required a panic, the error interrupt handler will
 * enqueue the error and call panic itself.
 */
void
bus_async_log_err(struct async_flt *aflt)
{
	char unum[UNUM_NAMLEN];
	int len;

	/*
	 * Call back into the processor specific routine
	 * to check for cpu related errors that may
	 * have resulted in this error. (E.g. copyout trap)
	 */
	if (aflt->flt_in_memory)
		cpu_check_allcpus(aflt);

	/*
	 * Note that aflt->flt_stat is not the CPU afsr.
	 */
	(void) cpu_get_mem_unum_aflt(AFLT_STAT_INVALID, aflt,
		    unum, UNUM_NAMLEN, &len);
	aflt->flt_func(aflt, unum);
}

/*
 * ecc_cpu_call called from bus drain functions to run cpu
 * specific functions to check other cpus and get the unum.
 */
void
ecc_cpu_call(struct async_flt *ecc, char *unum, int err_type)
{
	int len;

	/*
	 * Call back into the processor
	 * specific routine to check for cpu related errors
	 * that may have resulted in this error.
	 * (E.g. copyout trap)
	 */
	if (ecc->flt_in_memory)
		cpu_check_allcpus(ecc);

	(void) cpu_get_mem_unum(AFLT_STAT_VALID, ecc->flt_synd,
					(uint64_t)-1, ecc->flt_addr,
					ecc->flt_bus_id, ecc->flt_in_memory,
					ecc->flt_status, unum,
					UNUM_NAMLEN, &len);

	if (err_type == ECC_IO_CE)
		cpu_ce_count_unum(ecc, len, unum);
}

/*
 * Handler to process a fatal error.  This routine can be called from a
 * softint, called from trap()'s AST handling, or called from the panic flow.
 */
/*ARGSUSED*/
static void
ue_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
{
	cpu_ue_log_err(aflt);
}

/*
 * Handler to process a correctable error.  This routine can be called from a
 * softint.  We just call the CPU module's logging routine.
 */
/*ARGSUSED*/
static void
ce_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep)
{
	cpu_ce_log_err(aflt, eqep);
}

/*
 * Scrub a non-fatal correctable ecc error.
 */
void
ce_scrub(struct async_flt *aflt)
{
	if (aflt->flt_in_memory)
		cpu_ce_scrub_mem_err(aflt, B_FALSE);
}

/*
 * Allocate error queue sizes based on max_ncpus.  max_ncpus is set just
 * after ncpunode has been determined.  ncpus is set in start_other_cpus
 * which is called after error_init() but may change dynamically.
 */
void
error_init(void)
{
	char tmp_name[MAXSYSNAME];
	pnode_t node;
	size_t size = cpu_aflt_size();

	/*
	 * Initialize the correctable and uncorrectable error queues.
	 */
	ue_queue = errorq_create("ue_queue", (errorq_func_t)ue_drain, NULL,
	    MAX_ASYNC_FLTS * (max_ncpus + 1), size, PIL_2, ERRORQ_VITAL);

	ce_queue = errorq_create("ce_queue", (errorq_func_t)ce_drain, NULL,
	    MAX_CE_FLTS * (max_ncpus + 1), size, PIL_1, 0);

	if (ue_queue == NULL || ce_queue == NULL)
		panic("failed to create required system error queue");

	/*
	 * Initialize the busfunc list mutex.  This must be a PIL_15 spin lock
	 * because we will need to acquire it from cpu_async_error().
	 */
	mutex_init(&bfd_lock, NULL, MUTEX_SPIN, (void *)PIL_15);

	node = prom_rootnode();
	if ((node == OBP_NONODE) || (node == OBP_BADNODE)) {
		cmn_err(CE_CONT, "error_init: node 0x%x\n", (uint_t)node);
		return;
	}

	if (((size = prom_getproplen(node, "reset-reason")) != -1) &&
	    (size <= MAXSYSNAME) &&
	    (prom_getprop(node, "reset-reason", tmp_name) != -1)) {
		if (reset_debug) {
			cmn_err(CE_CONT, "System booting after %s\n", tmp_name);
		} else if (strncmp(tmp_name, "FATAL", 5) == 0) {
			cmn_err(CE_CONT,
			    "System booting after fatal error %s\n", tmp_name);
		}
	}

	if (&cpu_error_init) {
		cpu_error_init((MAX_ASYNC_FLTS + MAX_CE_FLTS) *
		    (max_ncpus + 1));
	}
}

/*
 * Flags for ecc_page_zero DTrace probe since ecc_page_zero() is called
 * as a softint handler.
 */
#define	PAGE_ZERO_SUCCESS	0
#define	PAGE_ZERO_FAIL_NOLOCK	1
#define	PAGE_ZERO_FAIL_ONTRAP	2

void
ecc_page_zero(void *arg)
{
	uint64_t pa = (uint64_t)arg;
	int ret, success_flag;
	page_t *pp = page_numtopp_nolock(mmu_btop(pa));

	if (page_retire_check(pa, NULL) != 0)
		return;

	/*
	 * Must hold a lock on the page before calling pagezero()
	 *
	 * This will only fail if someone has or wants an exclusive lock on
	 * the page.  Since it's a retired page, this shouldn't happen.
	 */
	ret = page_lock_es(pp, SE_SHARED, (kmutex_t *)NULL,
	    P_NO_RECLAIM, SE_RETIRED);

	if (ret > 0) {
		on_trap_data_t otd;

		/*
		 * Protect pagezero() from async faults
		 */
		if (!on_trap(&otd, OT_DATA_EC)) {
			pagezero(pp, 0, PAGESIZE);
			success_flag = PAGE_ZERO_SUCCESS;
		} else {
			success_flag = PAGE_ZERO_FAIL_ONTRAP;
		}
		no_trap();
		page_unlock(pp);
	} else {
		success_flag = PAGE_ZERO_FAIL_NOLOCK;
	}
	DTRACE_PROBE2(page_zero_result, int, success_flag, uint64_t, pa);
}