xref: /illumos-gate/usr/src/cmd/fm/modules/common/cpumem-retire/cma_main.c (revision fe3e2633be44d2f5361a7bba26abeb80fcc04fbc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <cma.h>
30 
31 #include <strings.h>
32 #include <errno.h>
33 #include <time.h>
34 #include <fm/fmd_api.h>
35 #include <sys/fm/protocol.h>
36 #include <sys/systeminfo.h>
37 #include <sys/utsname.h>
38 
39 #ifdef sun4v
40 #include <sys/fm/ldom.h>
41 
42 static fmd_hdl_t *init_hdl;
43 ldom_hdl_t *cma_lhp;
44 #endif
45 
46 extern const char *fmd_fmri_get_platform();
47 
48 cma_t cma;
49 
50 cma_stats_t cma_stats = {
51 	{ "cpu_flts", FMD_TYPE_UINT64, "cpu faults resolved" },
52 	{ "cpu_repairs", FMD_TYPE_UINT64, "cpu faults repaired" },
53 	{ "cpu_fails", FMD_TYPE_UINT64, "cpu faults unresolveable" },
54 	{ "cpu_blfails", FMD_TYPE_UINT64, "failed cpu blacklists" },
55 	{ "cpu_supp", FMD_TYPE_UINT64, "cpu offlines suppressed" },
56 	{ "cpu_blsupp", FMD_TYPE_UINT64, "cpu blacklists suppressed" },
57 	{ "page_flts", FMD_TYPE_UINT64, "page faults resolved" },
58 	{ "page_repairs", FMD_TYPE_UINT64, "page faults repaired" },
59 	{ "page_fails", FMD_TYPE_UINT64, "page faults unresolveable" },
60 	{ "page_supp", FMD_TYPE_UINT64, "page retires suppressed" },
61 	{ "page_nonent", FMD_TYPE_UINT64, "retires for non-existent fmris" },
62 	{ "bad_flts", FMD_TYPE_UINT64, "invalid fault events received" },
63 	{ "nop_flts", FMD_TYPE_UINT64, "inapplicable fault events received" },
64 	{ "auto_flts", FMD_TYPE_UINT64, "auto-close faults received" }
65 };
66 
67 typedef struct cma_subscriber {
68 	const char *subr_class;
69 	const char *subr_sname;
70 	uint_t subr_svers;
71 	int (*subr_func)(fmd_hdl_t *, nvlist_t *, nvlist_t *, const char *,
72 	    boolean_t);
73 } cma_subscriber_t;
74 
75 static const cma_subscriber_t cma_subrs[] = {
76 #if defined(sun4v)
77 	{ "fault.memory.page", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
78 	    cma_page_retire },
79 	{ "fault.memory.dimm", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
80 	    NULL },
81 	{ "fault.memory.dimm_sb", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
82 	    NULL },
83 	{ "fault.memory.dimm_ck", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
84 	    NULL },
85 	{ "fault.memory.dimm_ue", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
86 	    NULL },
87 	{ "fault.memory.bank", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
88 	    NULL },
89 	{ "fault.memory.datapath", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
90 	    NULL },
91 	{ "fault.memory.link-c", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
92 	    NULL },
93 	{ "fault.memory.link-u", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
94 	    NULL },
95 	{ "fault.memory.link-f", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
96 	    NULL },
97 
98 	/*
99 	 * The following ultraSPARC-T1/T2 faults do NOT retire a cpu thread,
100 	 * and therefore must be intercepted before
101 	 * the default "fault.cpu.*" dispatch to cma_cpu_retire.
102 	 */
103 	{ "fault.cpu.*.l2cachedata", FM_FMRI_SCHEME_CPU,
104 	    FM_CPU_SCHEME_VERSION, NULL },
105 	{ "fault.cpu.*.l2cachetag", FM_FMRI_SCHEME_CPU,
106 	    FM_CPU_SCHEME_VERSION, NULL },
107 	{ "fault.cpu.*.l2cachectl", FM_FMRI_SCHEME_CPU,
108 	    FM_CPU_SCHEME_VERSION, NULL },
109 	{ "fault.cpu.*.l2data-c", FM_FMRI_SCHEME_CPU,
110 	    FM_CPU_SCHEME_VERSION, NULL },
111 	{ "fault.cpu.*.l2data-u", FM_FMRI_SCHEME_CPU,
112 	    FM_CPU_SCHEME_VERSION, NULL },
113 	{ "fault.cpu.*.mau", FM_FMRI_SCHEME_CPU,
114 	    FM_CPU_SCHEME_VERSION, NULL },
115 	{ "fault.cpu.*.lfu-u", FM_FMRI_SCHEME_CPU,
116 	    FM_CPU_SCHEME_VERSION, NULL },
117 	{ "fault.cpu.*.lfu-f", FM_FMRI_SCHEME_CPU,
118 	    FM_CPU_SCHEME_VERSION, NULL },
119 	{ "fault.cpu.*.lfu-p", FM_FMRI_SCHEME_CPU,
120 	    FM_CPU_SCHEME_VERSION, NULL },
121 	{ "fault.cpu.*", FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
122 	    cma_cpu_retire },
123 #elif defined(opl)
124 	{ "fault.memory.page", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
125 	    cma_page_retire },
126 	{ "fault.memory.dimm", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
127 	    NULL },
128 	{ "fault.memory.bank", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
129 	    NULL },
130 	{ "fault.cpu.SPARC64-VI.*", FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
131 	    cma_cpu_retire },
132 	{ "fault.cpu.SPARC64-VII.*", FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
133 	    cma_cpu_retire },
134 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VI.core.se",
135 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
136 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VI.core.se-offlinereq",
137 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
138 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VI.core.ce",
139 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
140 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VI.core.ce-offlinereq",
141 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
142 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VII.core.se",
143 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
144 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VII.core.se-offlinereq",
145 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
146 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VII.core.ce",
147 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
148 	{ "fault.chassis.SPARC-Enterprise.cpu.SPARC64-VII.core.ce-offlinereq",
149 		FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION, cma_cpu_hc_retire },
150 #else /* Generic */
151 	{ "fault.memory.page", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
152 	    cma_page_retire },
153 	{ "fault.memory.page_sb", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
154 	    cma_page_retire },
155 	{ "fault.memory.page_ck", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
156 	    cma_page_retire },
157 	{ "fault.memory.page_ue", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
158 	    cma_page_retire },
159 	{ "fault.memory.generic-x86.page_ce", FM_FMRI_SCHEME_MEM,
160 	    FM_MEM_SCHEME_VERSION, cma_page_retire },
161 	{ "fault.memory.generic-x86.page_ue", FM_FMRI_SCHEME_MEM,
162 	    FM_MEM_SCHEME_VERSION, cma_page_retire },
163 	{ "fault.memory.intel.page_ce", FM_FMRI_SCHEME_MEM,
164 	    FM_MEM_SCHEME_VERSION, cma_page_retire },
165 	{ "fault.memory.intel.page_ue", FM_FMRI_SCHEME_MEM,
166 	    FM_MEM_SCHEME_VERSION, cma_page_retire },
167 	{ "fault.memory.dimm", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
168 	    NULL },
169 	{ "fault.memory.dimm_sb", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
170 	    NULL },
171 	{ "fault.memory.dimm_ck", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
172 	    NULL },
173 	{ "fault.memory.dimm_ue", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
174 	    NULL },
175 	{ "fault.memory.generic-x86.dimm_ce", FM_FMRI_SCHEME_MEM,
176 	    FM_MEM_SCHEME_VERSION, NULL },
177 	{ "fault.memory.generic-x86.dimm_ue", FM_FMRI_SCHEME_MEM,
178 	    FM_MEM_SCHEME_VERSION, NULL },
179 	{ "fault.memory.intel.dimm_ce", FM_FMRI_SCHEME_MEM,
180 	    FM_MEM_SCHEME_VERSION, NULL },
181 	{ "fault.memory.intel.dimm_ue", FM_FMRI_SCHEME_MEM,
182 	    FM_MEM_SCHEME_VERSION, NULL },
183 	{ "fault.memory.intel.fbd.*", FM_FMRI_SCHEME_HC,
184 	    FM_HC_SCHEME_VERSION, NULL },
185 	{ "fault.memory.dimm_testfail", FM_FMRI_SCHEME_MEM,
186 	    FM_MEM_SCHEME_VERSION, NULL },
187 	{ "fault.memory.bank", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
188 	    NULL },
189 	{ "fault.memory.datapath", FM_FMRI_SCHEME_MEM, FM_MEM_SCHEME_VERSION,
190 	    NULL },
191 
192 	/*
193 	 * The following faults do NOT retire a cpu thread,
194 	 * and therefore must be intercepted before
195 	 * the default "fault.cpu.*" dispatch to cma_cpu_retire.
196 	 */
197 	{ "fault.cpu.ultraSPARC-T1.freg", FM_FMRI_SCHEME_CPU,
198 	    FM_CPU_SCHEME_VERSION, NULL },
199 	{ "fault.cpu.ultraSPARC-T1.l2cachedata", FM_FMRI_SCHEME_CPU,
200 	    FM_CPU_SCHEME_VERSION, NULL },
201 	{ "fault.cpu.ultraSPARC-T1.l2cachetag", FM_FMRI_SCHEME_CPU,
202 	    FM_CPU_SCHEME_VERSION, NULL },
203 	{ "fault.cpu.ultraSPARC-T1.l2cachectl", FM_FMRI_SCHEME_CPU,
204 	    FM_CPU_SCHEME_VERSION, NULL },
205 	{ "fault.cpu.ultraSPARC-T1.mau", FM_FMRI_SCHEME_CPU,
206 	    FM_CPU_SCHEME_VERSION, NULL },
207 	{ "fault.cpu.amd.dramchannel", FM_FMRI_SCHEME_HC, FM_HC_SCHEME_VERSION,
208 	    NULL },
209 	{ "fault.cpu.generic-x86.bus_interconnect_memory", FM_FMRI_SCHEME_CPU,
210 	    FM_CPU_SCHEME_VERSION, NULL },
211 	{ "fault.cpu.generic-x86.bus_interconnect_io", FM_FMRI_SCHEME_CPU,
212 	    FM_CPU_SCHEME_VERSION, NULL },
213 	{ "fault.cpu.generic-x86.bus_interconnect", FM_FMRI_SCHEME_CPU,
214 	    FM_CPU_SCHEME_VERSION, NULL },
215 	{ "fault.cpu.intel.bus_interconnect_memory", FM_FMRI_SCHEME_CPU,
216 	    FM_CPU_SCHEME_VERSION, NULL },
217 	{ "fault.cpu.intel.bus_interconnect_io", FM_FMRI_SCHEME_CPU,
218 	    FM_CPU_SCHEME_VERSION, NULL },
219 	{ "fault.cpu.intel.bus_interconnect", FM_FMRI_SCHEME_CPU,
220 	    FM_CPU_SCHEME_VERSION, NULL },
221 	{ "fault.cpu.intel.nb.*", FM_FMRI_SCHEME_HC,
222 	    FM_HC_SCHEME_VERSION, NULL },
223 	{ "fault.cpu.intel.dma", FM_FMRI_SCHEME_HC,
224 	    FM_HC_SCHEME_VERSION, NULL },
225 	{ "fault.cpu.intel.dma", FM_FMRI_SCHEME_CPU,
226 	    FM_CPU_SCHEME_VERSION, NULL },
227 #ifndef sun4v
228 #ifndef opl
229 	{ "fault.cpu.ultraSPARC-IVplus.l2cachedata-line",
230 	    FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
231 	    cma_cache_way_retire },
232 	{ "fault.cpu.ultraSPARC-IVplus.l3cachedata-line",
233 	    FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
234 	    cma_cache_way_retire },
235 	{ "fault.cpu.ultraSPARC-IVplus.l2cachetag-line",
236 	    FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
237 	    cma_cache_way_retire },
238 	{ "fault.cpu.ultraSPARC-IVplus.l3cachetag-line",
239 	    FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
240 	    cma_cache_way_retire },
241 #endif
242 #endif
243 	/*
244 	 * Default "fault.cpu.*" for "mem" scheme ASRU dispatch.
245 	 */
246 	{ "fault.cpu.*", FM_FMRI_SCHEME_CPU, FM_CPU_SCHEME_VERSION,
247 	    cma_cpu_retire },
248 #endif
249 	{ NULL, NULL, 0, NULL }
250 };
251 
252 static const cma_subscriber_t *
253 nvl2subr(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t **asrup)
254 {
255 	const cma_subscriber_t *sp;
256 	nvlist_t *asru;
257 	char *scheme;
258 	uint8_t version;
259 	char *fltclass = "(unknown)";
260 	boolean_t retire;
261 
262 	if (nvlist_lookup_boolean_value(nvl, FM_SUSPECT_RETIRE, &retire) == 0 &&
263 	    retire == 0) {
264 		fmd_hdl_debug(hdl, "cma_recv: retire suppressed");
265 		return (NULL);
266 	}
267 
268 	if (nvlist_lookup_nvlist(nvl, FM_FAULT_ASRU, &asru) != 0 ||
269 	    nvlist_lookup_string(asru, FM_FMRI_SCHEME, &scheme) != 0 ||
270 	    nvlist_lookup_uint8(asru, FM_VERSION, &version) != 0) {
271 		cma_stats.bad_flts.fmds_value.ui64++;
272 		return (NULL);
273 	}
274 
275 	for (sp = cma_subrs; sp->subr_class != NULL; sp++) {
276 		if (fmd_nvl_class_match(hdl, nvl, sp->subr_class) &&
277 		    strcmp(scheme, sp->subr_sname) == 0 &&
278 		    version <= sp->subr_svers) {
279 			*asrup = asru;
280 			return (sp);
281 		}
282 	}
283 
284 	(void) nvlist_lookup_string(nvl, FM_CLASS, &fltclass);
285 	fmd_hdl_error(hdl, "No handling disposition for %s with asru in "
286 	    "scheme \"%s\"\n", fltclass, scheme);
287 	cma_stats.nop_flts.fmds_value.ui64++;
288 	return (NULL);
289 }
290 
291 static void
292 cma_recv_list(fmd_hdl_t *hdl, nvlist_t *nvl, const char *class)
293 {
294 	char *uuid = NULL;
295 	nvlist_t **nva;
296 	uint_t nvc = 0;
297 	uint_t keepopen;
298 	int err = 0;
299 	nvlist_t *asru;
300 	uint32_t index;
301 
302 	err |= nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid);
303 	err |= nvlist_lookup_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST,
304 	    &nva, &nvc);
305 	if (err != 0) {
306 		cma_stats.bad_flts.fmds_value.ui64++;
307 		return;
308 	}
309 
310 	keepopen = nvc;
311 	while (nvc-- != 0 && (strcmp(class, FM_LIST_SUSPECT_CLASS) != 0 ||
312 	    !fmd_case_uuclosed(hdl, uuid))) {
313 		nvlist_t *nvl = *nva++;
314 		const cma_subscriber_t *subr;
315 		int has_fault;
316 
317 		if ((subr = nvl2subr(hdl, nvl, &asru)) == NULL)
318 			continue;
319 
320 		/*
321 		 * A handler returns CMA_RA_SUCCESS to indicate that
322 		 * from this suspects  point-of-view the case may be
323 		 * closed, CMA_RA_FAILURE otherwise.
324 		 * A handler must not close the case itself.
325 		 */
326 		if (subr->subr_func != NULL) {
327 			has_fault = fmd_nvl_fmri_has_fault(hdl, asru,
328 			    FMD_HAS_FAULT_ASRU, NULL);
329 			if (strcmp(class, FM_LIST_SUSPECT_CLASS) == 0) {
330 				if (has_fault == 1)
331 					err = subr->subr_func(hdl, nvl, asru,
332 					    uuid, 0);
333 			} else {
334 				if (has_fault == 0)
335 					err = subr->subr_func(hdl, nvl, asru,
336 					    uuid, 1);
337 			}
338 			if (err == CMA_RA_SUCCESS)
339 				keepopen--;
340 		}
341 	}
342 	/*
343 	 * Do not close the case if we are handling cache faults.
344 	 */
345 	if (nvlist_lookup_uint32(asru, FM_FMRI_CPU_CACHE_INDEX, &index) != 0) {
346 		if (!keepopen && strcmp(class, FM_LIST_SUSPECT_CLASS) == 0) {
347 			fmd_case_uuclose(hdl, uuid);
348 		}
349 	}
350 	if (!keepopen && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0)
351 		fmd_case_uuresolved(hdl, uuid);
352 }
353 
354 static void
355 cma_recv_one(fmd_hdl_t *hdl, nvlist_t *nvl)
356 {
357 	const cma_subscriber_t *subr;
358 	nvlist_t *asru;
359 
360 	if ((subr = nvl2subr(hdl, nvl, &asru)) == NULL)
361 		return;
362 
363 	if (subr->subr_func != NULL) {
364 		if (fmd_nvl_fmri_has_fault(hdl, asru,
365 		    FMD_HAS_FAULT_ASRU, NULL) == 1)
366 			(void) subr->subr_func(hdl, nvl, asru, NULL, 0);
367 	}
368 }
369 
370 /*ARGSUSED*/
371 static void
372 cma_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
373 {
374 	fmd_hdl_debug(hdl, "received %s\n", class);
375 
376 	if (strcmp(class, FM_LIST_SUSPECT_CLASS) == 0 ||
377 	    strcmp(class, FM_LIST_REPAIRED_CLASS) == 0 ||
378 	    strcmp(class, FM_LIST_UPDATED_CLASS) == 0)
379 		cma_recv_list(hdl, nvl, class);
380 	else
381 		cma_recv_one(hdl, nvl);
382 }
383 
384 /*ARGSUSED*/
385 static void
386 cma_timeout(fmd_hdl_t *hdl, id_t id, void *arg)
387 {
388 	if (id == cma.cma_page_timerid)
389 		cma_page_retry(hdl);
390 #ifdef sun4v
391 	/*
392 	 * cpu offline/online needs to be retried on sun4v because
393 	 * ldom request can be asynchronous.
394 	 */
395 	else if (id == cma.cma_cpu_timerid)
396 		cma_cpu_retry(hdl);
397 #endif
398 }
399 
400 #ifdef sun4v
401 static void *
402 cma_init_alloc(size_t size)
403 {
404 	return (fmd_hdl_alloc(init_hdl, size, FMD_SLEEP));
405 }
406 
407 static void
408 cma_init_free(void *addr, size_t size)
409 {
410 	fmd_hdl_free(init_hdl, addr, size);
411 }
412 #endif
413 
414 static const fmd_hdl_ops_t fmd_ops = {
415 	cma_recv,	/* fmdo_recv */
416 	cma_timeout,	/* fmdo_timeout */
417 	NULL,		/* fmdo_close */
418 	NULL,		/* fmdo_stats */
419 	NULL,		/* fmdo_gc */
420 };
421 
422 static const fmd_prop_t fmd_props[] = {
423 	{ "cpu_tries", FMD_TYPE_UINT32, "10" },
424 	{ "cpu_delay", FMD_TYPE_TIME, "1sec" },
425 #ifdef sun4v
426 	{ "cpu_ret_mindelay", FMD_TYPE_TIME, "5sec" },
427 	{ "cpu_ret_maxdelay", FMD_TYPE_TIME, "5min" },
428 #endif /* sun4v */
429 	{ "cpu_offline_enable", FMD_TYPE_BOOL, "true" },
430 	{ "cpu_online_enable", FMD_TYPE_BOOL, "true" },
431 	{ "cpu_forced_offline", FMD_TYPE_BOOL, "true" },
432 #ifdef opl
433 	{ "cpu_blacklist_enable", FMD_TYPE_BOOL, "false" },
434 	{ "cpu_unblacklist_enable", FMD_TYPE_BOOL, "false" },
435 #else
436 	{ "cpu_blacklist_enable", FMD_TYPE_BOOL, "true" },
437 	{ "cpu_unblacklist_enable", FMD_TYPE_BOOL, "true" },
438 #endif /* opl */
439 	{ "page_ret_mindelay", FMD_TYPE_TIME, "1sec" },
440 	{ "page_ret_maxdelay", FMD_TYPE_TIME, "5min" },
441 	{ "page_retire_enable", FMD_TYPE_BOOL, "true" },
442 	{ "page_unretire_enable", FMD_TYPE_BOOL, "true" },
443 	{ NULL, 0, NULL }
444 };
445 
446 static const fmd_hdl_info_t fmd_info = {
447 	"CPU/Memory Retire Agent", CMA_VERSION, &fmd_ops, fmd_props
448 };
449 
450 void
451 _fmd_init(fmd_hdl_t *hdl)
452 {
453 	hrtime_t nsec;
454 #ifdef i386
455 	/*
456 	 * Abort the cpumem-retire module if Solaris is running under the Xen
457 	 * hypervisor.
458 	 */
459 	if (strcmp(fmd_fmri_get_platform(), "i86xpv") == 0)
460 		return;
461 #endif
462 
463 	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
464 		return; /* invalid data in configuration file */
465 
466 	fmd_hdl_subscribe(hdl, "fault.cpu.*");
467 	fmd_hdl_subscribe(hdl, "fault.memory.*");
468 #ifdef opl
469 	fmd_hdl_subscribe(hdl, "fault.chassis.SPARC-Enterprise.cpu.*");
470 #endif
471 
472 	(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, sizeof (cma_stats) /
473 	    sizeof (fmd_stat_t), (fmd_stat_t *)&cma_stats);
474 
475 	cma.cma_cpu_tries = fmd_prop_get_int32(hdl, "cpu_tries");
476 
477 	nsec = fmd_prop_get_int64(hdl, "cpu_delay");
478 	cma.cma_cpu_delay.tv_sec = nsec / NANOSEC;
479 	cma.cma_cpu_delay.tv_nsec = nsec % NANOSEC;
480 
481 	cma.cma_page_mindelay = fmd_prop_get_int64(hdl, "page_ret_mindelay");
482 	cma.cma_page_maxdelay = fmd_prop_get_int64(hdl, "page_ret_maxdelay");
483 
484 #ifdef sun4v
485 	cma.cma_cpu_mindelay = fmd_prop_get_int64(hdl, "cpu_ret_mindelay");
486 	cma.cma_cpu_maxdelay = fmd_prop_get_int64(hdl, "cpu_ret_maxdelay");
487 #endif
488 
489 	cma.cma_cpu_dooffline = fmd_prop_get_int32(hdl, "cpu_offline_enable");
490 	cma.cma_cpu_forcedoffline = fmd_prop_get_int32(hdl,
491 	    "cpu_forced_offline");
492 	cma.cma_cpu_doonline = fmd_prop_get_int32(hdl, "cpu_online_enable");
493 	cma.cma_cpu_doblacklist = fmd_prop_get_int32(hdl,
494 	    "cpu_blacklist_enable");
495 	cma.cma_cpu_dounblacklist = fmd_prop_get_int32(hdl,
496 	    "cpu_unblacklist_enable");
497 	cma.cma_page_doretire = fmd_prop_get_int32(hdl, "page_retire_enable");
498 	cma.cma_page_dounretire = fmd_prop_get_int32(hdl,
499 	    "page_unretire_enable");
500 
501 	if (cma.cma_page_maxdelay < cma.cma_page_mindelay)
502 		fmd_hdl_abort(hdl, "page retirement delays conflict\n");
503 
504 #ifdef sun4v
505 	init_hdl = hdl;
506 	cma_lhp = ldom_init(cma_init_alloc, cma_init_free);
507 #endif
508 }
509 
510 void
511 _fmd_fini(fmd_hdl_t *hdl)
512 {
513 #ifdef sun4v
514 	ldom_fini(cma_lhp);
515 	cma_cpu_fini(hdl);
516 #endif
517 	cma_page_fini(hdl);
518 }
519