1*5f149bcaScy /*
2*5f149bcaScy  * CDDL HEADER START
3*5f149bcaScy  *
4*5f149bcaScy  * The contents of this file are subject to the terms of the
5*5f149bcaScy  * Common Development and Distribution License (the "License").
6*5f149bcaScy  * You may not use this file except in compliance with the License.
7*5f149bcaScy  *
8*5f149bcaScy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5f149bcaScy  * or http://www.opensolaris.org/os/licensing.
10*5f149bcaScy  * See the License for the specific language governing permissions
11*5f149bcaScy  * and limitations under the License.
12*5f149bcaScy  *
13*5f149bcaScy  * When distributing Covered Code, include this CDDL HEADER in each
14*5f149bcaScy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5f149bcaScy  * If applicable, add the following below this CDDL HEADER, with the
16*5f149bcaScy  * fields enclosed by brackets "[]" replaced with your own identifying
17*5f149bcaScy  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5f149bcaScy  *
19*5f149bcaScy  * CDDL HEADER END
20*5f149bcaScy  */
21*5f149bcaScy 
22*5f149bcaScy /*
23*5f149bcaScy  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*5f149bcaScy  * Use is subject to license terms.
25*5f149bcaScy  */
26*5f149bcaScy 
27*5f149bcaScy #include <cma.h>
28*5f149bcaScy 
29*5f149bcaScy #include <fcntl.h>
30*5f149bcaScy #include <unistd.h>
31*5f149bcaScy #include <strings.h>
32*5f149bcaScy #include <errno.h>
33*5f149bcaScy #include <time.h>
34*5f149bcaScy #include <fm/fmd_api.h>
35*5f149bcaScy #include <sys/fm/protocol.h>
36*5f149bcaScy #include <sys/bl.h>
37*5f149bcaScy #include <sys/processor.h>
38*5f149bcaScy 
39*5f149bcaScy int
cma_cpu_blacklist(fmd_hdl_t * hdl,nvlist_t * nvl,nvlist_t * asru,boolean_t repair)40*5f149bcaScy cma_cpu_blacklist(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t *asru,
41*5f149bcaScy     boolean_t repair)
42*5f149bcaScy {
43*5f149bcaScy 	bl_req_t blr;
44*5f149bcaScy 	nvlist_t *fmri;
45*5f149bcaScy 	char *fmribuf;
46*5f149bcaScy 	size_t fmrisz;
47*5f149bcaScy 	int fd, rc, err;
48*5f149bcaScy 	char *class;
49*5f149bcaScy 
50*5f149bcaScy 	/*
51*5f149bcaScy 	 * Some platforms have special unums for the E$ DIMMs.  If we're dealing
52*5f149bcaScy 	 * with a platform that has these unums, one will have been added to the
53*5f149bcaScy 	 * fault as the resource.  We'll use that for the blacklisting.  If we
54*5f149bcaScy 	 * can't find a resource, we'll fall back to the ASRU.
55*5f149bcaScy 	 */
56*5f149bcaScy 	if (nvlist_lookup_nvlist(nvl, FM_FAULT_RESOURCE, &fmri) != 0)
57*5f149bcaScy 		fmri = asru;
58*5f149bcaScy 
59*5f149bcaScy 	if ((nvlist_lookup_string(nvl, FM_CLASS, &class) != 0) ||
60*5f149bcaScy 	    (class == NULL) || (*class == '\0')) {
61*5f149bcaScy 		fmd_hdl_debug(hdl, "failed to get the fault class name\n");
62*5f149bcaScy 		errno = EINVAL;
63*5f149bcaScy 		return (-1);
64*5f149bcaScy 	}
65*5f149bcaScy 
66*5f149bcaScy 	if ((fd = open("/dev/bl", O_RDONLY)) < 0)
67*5f149bcaScy 		return (-1); /* errno is set for us */
68*5f149bcaScy 
69*5f149bcaScy 	if ((errno = nvlist_size(fmri, &fmrisz, NV_ENCODE_NATIVE)) != 0 ||
70*5f149bcaScy 	    (fmribuf = fmd_hdl_alloc(hdl, fmrisz, FMD_SLEEP)) == NULL) {
71*5f149bcaScy 		(void) close(fd);
72*5f149bcaScy 		return (-1); /* errno is set for us */
73*5f149bcaScy 	}
74*5f149bcaScy 
75*5f149bcaScy 	if ((errno = nvlist_pack(fmri, &fmribuf, &fmrisz,
76*5f149bcaScy 	    NV_ENCODE_NATIVE, 0)) != 0) {
77*5f149bcaScy 		fmd_hdl_free(hdl, fmribuf, fmrisz);
78*5f149bcaScy 		(void) close(fd);
79*5f149bcaScy 		return (-1); /* errno is set for us */
80*5f149bcaScy 	}
81*5f149bcaScy 
82*5f149bcaScy 	blr.bl_fmri = fmribuf;
83*5f149bcaScy 	blr.bl_fmrisz = fmrisz;
84*5f149bcaScy 	blr.bl_class = class;
85*5f149bcaScy 
86*5f149bcaScy 	rc = ioctl(fd, repair ? BLIOC_DELETE : BLIOC_INSERT, &blr);
87*5f149bcaScy 	err = errno;
88*5f149bcaScy 
89*5f149bcaScy 	fmd_hdl_free(hdl, fmribuf, fmrisz);
90*5f149bcaScy 	(void) close(fd);
91*5f149bcaScy 
92*5f149bcaScy 	if (rc < 0 && err != ENOTSUP) {
93*5f149bcaScy 		errno = err;
94*5f149bcaScy 		return (-1);
95*5f149bcaScy 	}
96*5f149bcaScy 
97*5f149bcaScy 	return (0);
98*5f149bcaScy }
99*5f149bcaScy 
100*5f149bcaScy /* ARGSUSED */
101*5f149bcaScy int
cma_cpu_statechange(fmd_hdl_t * hdl,nvlist_t * asru,const char * uuid,int cpustate,boolean_t repair)102*5f149bcaScy cma_cpu_statechange(fmd_hdl_t *hdl, nvlist_t *asru, const char *uuid,
103*5f149bcaScy     int cpustate, boolean_t repair)
104*5f149bcaScy {
105*5f149bcaScy 	int i;
106*5f149bcaScy 	uint_t cpuid;
107*5f149bcaScy 
108*5f149bcaScy 	if (nvlist_lookup_uint32(asru, FM_FMRI_CPU_ID, &cpuid) != 0) {
109*5f149bcaScy 		fmd_hdl_debug(hdl, "missing '%s'\n", FM_FMRI_CPU_ID);
110*5f149bcaScy 		cma_stats.bad_flts.fmds_value.ui64++;
111*5f149bcaScy 		return (CMA_RA_FAILURE);
112*5f149bcaScy 	}
113*5f149bcaScy 
114*5f149bcaScy 	for (i = 0; i < cma.cma_cpu_tries;
115*5f149bcaScy 	    i++, (void) nanosleep(&cma.cma_cpu_delay, NULL)) {
116*5f149bcaScy 		int oldstate;
117*5f149bcaScy 		if ((oldstate = p_online(cpuid, cpustate)) != -1) {
118*5f149bcaScy 			fmd_hdl_debug(hdl, "changed cpu %u state from \"%s\" "
119*5f149bcaScy 			    "to \"%s\"\n", cpuid, p_online_state_fmt(oldstate),
120*5f149bcaScy 			    p_online_state_fmt(cpustate));
121*5f149bcaScy 			if (repair)
122*5f149bcaScy 				cma_stats.cpu_repairs.fmds_value.ui64++;
123*5f149bcaScy 			else
124*5f149bcaScy 				cma_stats.cpu_flts.fmds_value.ui64++;
125*5f149bcaScy 			return (CMA_RA_SUCCESS);
126*5f149bcaScy 		}
127*5f149bcaScy 	}
128*5f149bcaScy 
129*5f149bcaScy 	fmd_hdl_debug(hdl, "failed to changed cpu %u state to \"%s\": %s\n",
130*5f149bcaScy 	    cpuid, p_online_state_fmt(cpustate), strerror(errno));
131*5f149bcaScy 	cma_stats.cpu_fails.fmds_value.ui64++;
132*5f149bcaScy 	return (CMA_RA_FAILURE);
133*5f149bcaScy }
134