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