1*7532SSean.Ye@Sun.COM /*
2*7532SSean.Ye@Sun.COM * CDDL HEADER START
3*7532SSean.Ye@Sun.COM *
4*7532SSean.Ye@Sun.COM * The contents of this file are subject to the terms of the
5*7532SSean.Ye@Sun.COM * Common Development and Distribution License (the "License").
6*7532SSean.Ye@Sun.COM * You may not use this file except in compliance with the License.
7*7532SSean.Ye@Sun.COM *
8*7532SSean.Ye@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7532SSean.Ye@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*7532SSean.Ye@Sun.COM * See the License for the specific language governing permissions
11*7532SSean.Ye@Sun.COM * and limitations under the License.
12*7532SSean.Ye@Sun.COM *
13*7532SSean.Ye@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*7532SSean.Ye@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7532SSean.Ye@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*7532SSean.Ye@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*7532SSean.Ye@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*7532SSean.Ye@Sun.COM *
19*7532SSean.Ye@Sun.COM * CDDL HEADER END
20*7532SSean.Ye@Sun.COM */
21*7532SSean.Ye@Sun.COM
22*7532SSean.Ye@Sun.COM /*
23*7532SSean.Ye@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*7532SSean.Ye@Sun.COM * Use is subject to license terms.
25*7532SSean.Ye@Sun.COM */
26*7532SSean.Ye@Sun.COM
27*7532SSean.Ye@Sun.COM #include <stdlib.h>
28*7532SSean.Ye@Sun.COM #include <errno.h>
29*7532SSean.Ye@Sun.COM #include <sys/types.h>
30*7532SSean.Ye@Sun.COM #include <libnvpair.h>
31*7532SSean.Ye@Sun.COM #include <sys/fcntl.h>
32*7532SSean.Ye@Sun.COM #include <sys/devfm.h>
33*7532SSean.Ye@Sun.COM #include <fmd_agent_impl.h>
34*7532SSean.Ye@Sun.COM
35*7532SSean.Ye@Sun.COM static int
cleanup_set_errno(fmd_agent_hdl_t * hdl,nvlist_t * innvl,nvlist_t * outnvl,int err)36*7532SSean.Ye@Sun.COM cleanup_set_errno(fmd_agent_hdl_t *hdl, nvlist_t *innvl, nvlist_t *outnvl,
37*7532SSean.Ye@Sun.COM int err)
38*7532SSean.Ye@Sun.COM {
39*7532SSean.Ye@Sun.COM if (innvl != NULL)
40*7532SSean.Ye@Sun.COM nvlist_free(innvl);
41*7532SSean.Ye@Sun.COM if (outnvl != NULL)
42*7532SSean.Ye@Sun.COM nvlist_free(outnvl);
43*7532SSean.Ye@Sun.COM return (fmd_agent_seterrno(hdl, err));
44*7532SSean.Ye@Sun.COM }
45*7532SSean.Ye@Sun.COM
46*7532SSean.Ye@Sun.COM static int
fmd_agent_physcpu_info_v1(fmd_agent_hdl_t * hdl,nvlist_t *** cpusp,uint_t * ncpup)47*7532SSean.Ye@Sun.COM fmd_agent_physcpu_info_v1(fmd_agent_hdl_t *hdl, nvlist_t ***cpusp,
48*7532SSean.Ye@Sun.COM uint_t *ncpup)
49*7532SSean.Ye@Sun.COM {
50*7532SSean.Ye@Sun.COM int err;
51*7532SSean.Ye@Sun.COM nvlist_t *nvl, **nvl_array, **cpus;
52*7532SSean.Ye@Sun.COM uint_t i, n;
53*7532SSean.Ye@Sun.COM
54*7532SSean.Ye@Sun.COM if ((err = fmd_agent_nvl_ioctl(hdl, FM_IOC_PHYSCPU_INFO, 1,
55*7532SSean.Ye@Sun.COM NULL, &nvl)) != 0)
56*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, NULL, NULL, err));
57*7532SSean.Ye@Sun.COM if ((err = nvlist_lookup_nvlist_array(nvl, FM_PHYSCPU_INFO_CPUS,
58*7532SSean.Ye@Sun.COM &cpus, &n)) != 0)
59*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, NULL, nvl, err));
60*7532SSean.Ye@Sun.COM
61*7532SSean.Ye@Sun.COM if ((nvl_array = umem_alloc(sizeof (nvlist_t *) * n, UMEM_DEFAULT))
62*7532SSean.Ye@Sun.COM == NULL)
63*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, NULL, nvl, errno));
64*7532SSean.Ye@Sun.COM for (i = 0; i < n; i++) {
65*7532SSean.Ye@Sun.COM if ((err = nvlist_dup(cpus[i], nvl_array + i, 0)) != 0) {
66*7532SSean.Ye@Sun.COM while (i > 0)
67*7532SSean.Ye@Sun.COM nvlist_free(nvl_array[--i]);
68*7532SSean.Ye@Sun.COM umem_free(nvl_array, sizeof (nvlist_t *) * n);
69*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, NULL, nvl, err));
70*7532SSean.Ye@Sun.COM }
71*7532SSean.Ye@Sun.COM }
72*7532SSean.Ye@Sun.COM
73*7532SSean.Ye@Sun.COM nvlist_free(nvl);
74*7532SSean.Ye@Sun.COM *cpusp = nvl_array;
75*7532SSean.Ye@Sun.COM *ncpup = n;
76*7532SSean.Ye@Sun.COM return (0);
77*7532SSean.Ye@Sun.COM }
78*7532SSean.Ye@Sun.COM
79*7532SSean.Ye@Sun.COM int
fmd_agent_physcpu_info(fmd_agent_hdl_t * hdl,nvlist_t *** cpusp,uint_t * ncpu)80*7532SSean.Ye@Sun.COM fmd_agent_physcpu_info(fmd_agent_hdl_t *hdl, nvlist_t ***cpusp, uint_t *ncpu)
81*7532SSean.Ye@Sun.COM {
82*7532SSean.Ye@Sun.COM uint32_t ver;
83*7532SSean.Ye@Sun.COM
84*7532SSean.Ye@Sun.COM if (fmd_agent_version(hdl, FM_CPU_INFO_VERSION, &ver) == -1)
85*7532SSean.Ye@Sun.COM return (fmd_agent_seterrno(hdl, errno));
86*7532SSean.Ye@Sun.COM
87*7532SSean.Ye@Sun.COM switch (ver) {
88*7532SSean.Ye@Sun.COM case 1:
89*7532SSean.Ye@Sun.COM return (fmd_agent_physcpu_info_v1(hdl, cpusp, ncpu));
90*7532SSean.Ye@Sun.COM
91*7532SSean.Ye@Sun.COM default:
92*7532SSean.Ye@Sun.COM return (fmd_agent_seterrno(hdl, ENOTSUP));
93*7532SSean.Ye@Sun.COM }
94*7532SSean.Ye@Sun.COM }
95*7532SSean.Ye@Sun.COM
96*7532SSean.Ye@Sun.COM static int
fmd_agent_cpuop_v1(fmd_agent_hdl_t * hdl,int cmd,int chipid,int coreid,int strandid,int * old_status)97*7532SSean.Ye@Sun.COM fmd_agent_cpuop_v1(fmd_agent_hdl_t *hdl, int cmd, int chipid, int coreid,
98*7532SSean.Ye@Sun.COM int strandid, int *old_status)
99*7532SSean.Ye@Sun.COM {
100*7532SSean.Ye@Sun.COM int err;
101*7532SSean.Ye@Sun.COM nvlist_t *nvl = NULL, *outnvl = NULL;
102*7532SSean.Ye@Sun.COM int32_t status;
103*7532SSean.Ye@Sun.COM
104*7532SSean.Ye@Sun.COM if ((err = nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) != 0 ||
105*7532SSean.Ye@Sun.COM (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_CHIP_ID, chipid)) != 0 ||
106*7532SSean.Ye@Sun.COM (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_CORE_ID, coreid)) != 0 ||
107*7532SSean.Ye@Sun.COM (err = nvlist_add_int32(nvl, FM_CPU_RETIRE_STRAND_ID, strandid))
108*7532SSean.Ye@Sun.COM != 0 || (err = fmd_agent_nvl_ioctl(hdl, cmd, 1, nvl, &outnvl)) != 0)
109*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, nvl, NULL, err));
110*7532SSean.Ye@Sun.COM
111*7532SSean.Ye@Sun.COM nvlist_free(nvl);
112*7532SSean.Ye@Sun.COM if (outnvl != NULL) {
113*7532SSean.Ye@Sun.COM if (old_status != NULL) {
114*7532SSean.Ye@Sun.COM (void) nvlist_lookup_int32(outnvl,
115*7532SSean.Ye@Sun.COM FM_CPU_RETIRE_OLDSTATUS, &status);
116*7532SSean.Ye@Sun.COM *old_status = status;
117*7532SSean.Ye@Sun.COM }
118*7532SSean.Ye@Sun.COM nvlist_free(outnvl);
119*7532SSean.Ye@Sun.COM }
120*7532SSean.Ye@Sun.COM
121*7532SSean.Ye@Sun.COM return (0);
122*7532SSean.Ye@Sun.COM }
123*7532SSean.Ye@Sun.COM
124*7532SSean.Ye@Sun.COM static int
fmd_agent_cpuop(fmd_agent_hdl_t * hdl,int cmd,int chipid,int coreid,int strandid,int * old_status)125*7532SSean.Ye@Sun.COM fmd_agent_cpuop(fmd_agent_hdl_t *hdl, int cmd, int chipid, int coreid,
126*7532SSean.Ye@Sun.COM int strandid, int *old_status)
127*7532SSean.Ye@Sun.COM {
128*7532SSean.Ye@Sun.COM uint32_t ver;
129*7532SSean.Ye@Sun.COM
130*7532SSean.Ye@Sun.COM if (fmd_agent_version(hdl, FM_CPU_OP_VERSION, &ver) == -1)
131*7532SSean.Ye@Sun.COM return (cleanup_set_errno(hdl, NULL, NULL, errno));
132*7532SSean.Ye@Sun.COM
133*7532SSean.Ye@Sun.COM switch (ver) {
134*7532SSean.Ye@Sun.COM case 1:
135*7532SSean.Ye@Sun.COM return (fmd_agent_cpuop_v1(hdl, cmd, chipid, coreid, strandid,
136*7532SSean.Ye@Sun.COM old_status));
137*7532SSean.Ye@Sun.COM
138*7532SSean.Ye@Sun.COM default:
139*7532SSean.Ye@Sun.COM return (fmd_agent_seterrno(hdl, ENOTSUP));
140*7532SSean.Ye@Sun.COM }
141*7532SSean.Ye@Sun.COM }
142*7532SSean.Ye@Sun.COM
143*7532SSean.Ye@Sun.COM int
fmd_agent_cpu_retire(fmd_agent_hdl_t * hdl,int chipid,int coreid,int strandid)144*7532SSean.Ye@Sun.COM fmd_agent_cpu_retire(fmd_agent_hdl_t *hdl, int chipid, int coreid, int strandid)
145*7532SSean.Ye@Sun.COM {
146*7532SSean.Ye@Sun.COM int ret;
147*7532SSean.Ye@Sun.COM
148*7532SSean.Ye@Sun.COM ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_RETIRE, chipid, coreid, strandid,
149*7532SSean.Ye@Sun.COM NULL);
150*7532SSean.Ye@Sun.COM
151*7532SSean.Ye@Sun.COM return (ret == 0 ? FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
152*7532SSean.Ye@Sun.COM }
153*7532SSean.Ye@Sun.COM
154*7532SSean.Ye@Sun.COM int
fmd_agent_cpu_isretired(fmd_agent_hdl_t * hdl,int chipid,int coreid,int strandid)155*7532SSean.Ye@Sun.COM fmd_agent_cpu_isretired(fmd_agent_hdl_t *hdl, int chipid, int coreid,
156*7532SSean.Ye@Sun.COM int strandid)
157*7532SSean.Ye@Sun.COM {
158*7532SSean.Ye@Sun.COM int ret, status;
159*7532SSean.Ye@Sun.COM
160*7532SSean.Ye@Sun.COM ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_STATUS, chipid, coreid, strandid,
161*7532SSean.Ye@Sun.COM &status);
162*7532SSean.Ye@Sun.COM
163*7532SSean.Ye@Sun.COM return (ret == 0 && status != P_ONLINE ?
164*7532SSean.Ye@Sun.COM FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
165*7532SSean.Ye@Sun.COM }
166*7532SSean.Ye@Sun.COM
167*7532SSean.Ye@Sun.COM int
fmd_agent_cpu_unretire(fmd_agent_hdl_t * hdl,int chipid,int coreid,int strandid)168*7532SSean.Ye@Sun.COM fmd_agent_cpu_unretire(fmd_agent_hdl_t *hdl, int chipid, int coreid,
169*7532SSean.Ye@Sun.COM int strandid)
170*7532SSean.Ye@Sun.COM {
171*7532SSean.Ye@Sun.COM int ret;
172*7532SSean.Ye@Sun.COM
173*7532SSean.Ye@Sun.COM ret = fmd_agent_cpuop(hdl, FM_IOC_CPU_UNRETIRE, chipid, coreid,
174*7532SSean.Ye@Sun.COM strandid, NULL);
175*7532SSean.Ye@Sun.COM
176*7532SSean.Ye@Sun.COM return (ret == 0 ? FMD_AGENT_RETIRE_DONE : FMD_AGENT_RETIRE_FAIL);
177*7532SSean.Ye@Sun.COM }
178