xref: /titanic_41/usr/src/cmd/fm/modules/sun4u/datapath-retire/cda_cpu.c (revision d00f0155af9a9a671eb08a0dc30f5ea0a379c36c)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 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 <cda.h>
30 
31 #include <fcntl.h>
32 #include <unistd.h>
33 #include <strings.h>
34 #include <errno.h>
35 #include <time.h>
36 #include <fm/fmd_api.h>
37 #include <sys/fm/protocol.h>
38 #include <sys/processor.h>
39 
40 static void
cda_cpu_offline(fmd_hdl_t * hdl,uint_t cpuid,int cpustate)41 cda_cpu_offline(fmd_hdl_t *hdl, uint_t cpuid, int cpustate)
42 {
43 	int i;
44 
45 	for (i = 0; i < cda.cda_cpu_tries;
46 	    i++, (void) nanosleep(&cda.cda_cpu_delay, NULL)) {
47 		if (p_online(cpuid, cpustate) != -1) {
48 			fmd_hdl_debug(hdl, "offlined cpu %u\n", cpuid);
49 			cda_stats.dp_offs.fmds_value.ui64++;
50 			return;
51 		}
52 	}
53 
54 	fmd_hdl_debug(hdl, "failed to offline %u: %s\n", cpuid,
55 	    strerror(errno));
56 	cda_stats.dp_fails.fmds_value.ui64++;
57 }
58 
59 /*ARGSUSED*/
60 void
cda_dp_retire(fmd_hdl_t * hdl,nvlist_t * nvl,nvlist_t * asru,const char * uuid)61 cda_dp_retire(fmd_hdl_t *hdl, nvlist_t *nvl, nvlist_t *asru, const char *uuid)
62 {
63 	int ii;
64 	uint_t cpuid;
65 	uint_t hc_nprs;
66 	nvlist_t **hc_prs;
67 	char *id;
68 
69 	/* Get the hc-list of elements in FMRI, and the size of the list */
70 	if (nvlist_lookup_nvlist_array(asru, FM_FMRI_HC_LIST, &hc_prs,
71 	    &hc_nprs) != 0) {
72 		fmd_hdl_debug(hdl, "failed to get '%s' from dp fault\n",
73 			FM_FMRI_HC_LIST);
74 		return;
75 	}
76 
77 	/* walk hc-list and offline each CPU present */
78 	for (ii = 0; ii < hc_nprs; ii++) {
79 		int cpustate = P_FAULTED;
80 
81 		if (nvlist_lookup_string(hc_prs[ii], FM_FMRI_HC_ID, &id) != 0) {
82 			fmd_hdl_debug(hdl, "dp fault missing '%s'\n",
83 			FM_FMRI_HC_ID);
84 			cda_stats.bad_flts.fmds_value.ui64++;
85 			return;
86 		}
87 
88 		cpuid = atoi(id);
89 		if (!cda.cda_cpu_dooffline) {
90 			fmd_hdl_debug(hdl, "dp suppressed offline of "
91 				"CPU %u\n", cpuid);
92 			cda_stats.dp_supp.fmds_value.ui64++;
93 			continue;
94 		}
95 
96 		if (cda.cda_cpu_forcedoffline)
97 			cpustate |= P_FORCED;
98 
99 		cda_cpu_offline(hdl, cpuid, cpustate);
100 	}
101 }
102