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