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