xref: /illumos-gate/usr/src/cmd/fm/modules/common/cpumem-retire/cma_cpu_arch.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 #include <cma.h>
28 
29 #include <fcntl.h>
30 #include <unistd.h>
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/bl.h>
37 #include <sys/processor.h>
38 
39 int
cma_cpu_blacklist(fmd_hdl_t * hdl,nvlist_t * nvl,nvlist_t * asru,boolean_t repair)40 cma_cpu_blacklist(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t *asru,
41     boolean_t repair)
42 {
43 	bl_req_t blr;
44 	nvlist_t *fmri;
45 	char *fmribuf;
46 	size_t fmrisz;
47 	int fd, rc, err;
48 	char *class;
49 
50 	/*
51 	 * Some platforms have special unums for the E$ DIMMs.  If we're dealing
52 	 * with a platform that has these unums, one will have been added to the
53 	 * fault as the resource.  We'll use that for the blacklisting.  If we
54 	 * can't find a resource, we'll fall back to the ASRU.
55 	 */
56 	if (nvlist_lookup_nvlist(nvl, FM_FAULT_RESOURCE, &fmri) != 0)
57 		fmri = asru;
58 
59 	if ((nvlist_lookup_string(nvl, FM_CLASS, &class) != 0) ||
60 	    (class == NULL) || (*class == '\0')) {
61 		fmd_hdl_debug(hdl, "failed to get the fault class name\n");
62 		errno = EINVAL;
63 		return (-1);
64 	}
65 
66 	if ((fd = open("/dev/bl", O_RDONLY)) < 0)
67 		return (-1); /* errno is set for us */
68 
69 	if ((errno = nvlist_size(fmri, &fmrisz, NV_ENCODE_NATIVE)) != 0 ||
70 	    (fmribuf = fmd_hdl_alloc(hdl, fmrisz, FMD_SLEEP)) == NULL) {
71 		(void) close(fd);
72 		return (-1); /* errno is set for us */
73 	}
74 
75 	if ((errno = nvlist_pack(fmri, &fmribuf, &fmrisz,
76 	    NV_ENCODE_NATIVE, 0)) != 0) {
77 		fmd_hdl_free(hdl, fmribuf, fmrisz);
78 		(void) close(fd);
79 		return (-1); /* errno is set for us */
80 	}
81 
82 	blr.bl_fmri = fmribuf;
83 	blr.bl_fmrisz = fmrisz;
84 	blr.bl_class = class;
85 
86 	rc = ioctl(fd, repair ? BLIOC_DELETE : BLIOC_INSERT, &blr);
87 	err = errno;
88 
89 	fmd_hdl_free(hdl, fmribuf, fmrisz);
90 	(void) close(fd);
91 
92 	if (rc < 0 && err != ENOTSUP) {
93 		errno = err;
94 		return (-1);
95 	}
96 
97 	return (0);
98 }
99 
100 /* ARGSUSED */
101 int
cma_cpu_statechange(fmd_hdl_t * hdl,nvlist_t * asru,const char * uuid,int cpustate,boolean_t repair)102 cma_cpu_statechange(fmd_hdl_t *hdl, nvlist_t *asru, const char *uuid,
103     int cpustate, boolean_t repair)
104 {
105 	int i;
106 	uint_t cpuid;
107 
108 	if (nvlist_lookup_uint32(asru, FM_FMRI_CPU_ID, &cpuid) != 0) {
109 		fmd_hdl_debug(hdl, "missing '%s'\n", FM_FMRI_CPU_ID);
110 		cma_stats.bad_flts.fmds_value.ui64++;
111 		return (CMA_RA_FAILURE);
112 	}
113 
114 	for (i = 0; i < cma.cma_cpu_tries;
115 	    i++, (void) nanosleep(&cma.cma_cpu_delay, NULL)) {
116 		int oldstate;
117 		if ((oldstate = p_online(cpuid, cpustate)) != -1) {
118 			fmd_hdl_debug(hdl, "changed cpu %u state from \"%s\" "
119 			    "to \"%s\"\n", cpuid, p_online_state_fmt(oldstate),
120 			    p_online_state_fmt(cpustate));
121 			if (repair)
122 				cma_stats.cpu_repairs.fmds_value.ui64++;
123 			else
124 				cma_stats.cpu_flts.fmds_value.ui64++;
125 			return (CMA_RA_SUCCESS);
126 		}
127 	}
128 
129 	fmd_hdl_debug(hdl, "failed to changed cpu %u state to \"%s\": %s\n",
130 	    cpuid, p_online_state_fmt(cpustate), strerror(errno));
131 	cma_stats.cpu_fails.fmds_value.ui64++;
132 	return (CMA_RA_FAILURE);
133 }
134