1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <limits.h>
31*0Sstevel@tonic-gate #include <unistd.h>
32*0Sstevel@tonic-gate #include <sys/systeminfo.h>
33*0Sstevel@tonic-gate #include <pthread.h>
34*0Sstevel@tonic-gate #include <syslog.h>
35*0Sstevel@tonic-gate #include <picl.h>
36*0Sstevel@tonic-gate #include <picltree.h>
37*0Sstevel@tonic-gate #include <picldefs.h>
38*0Sstevel@tonic-gate #include <string.h>
39*0Sstevel@tonic-gate #include <libnvpair.h>
40*0Sstevel@tonic-gate #include <libintl.h>
41*0Sstevel@tonic-gate #include <librcm.h>
42*0Sstevel@tonic-gate #include <stropts.h>
43*0Sstevel@tonic-gate #include <smclib.h>
44*0Sstevel@tonic-gate #include <sys/sysevent/dr.h>
45*0Sstevel@tonic-gate #include "piclenvmond.h"
46*0Sstevel@tonic-gate #include "picldr.h"
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate /* local defines */
49*0Sstevel@tonic-gate #define RESET_CPU "/usr/sbin/shutdown -y -g 0 -i6"
50*0Sstevel@tonic-gate #define SHUTDOWN_CPU "/usr/sbin/shutdown -y -g 0 -i0"
51*0Sstevel@tonic-gate #define RCM_ABSTRACT_RESOURCE "SUNW_snowbird/board0/CPU1"
52*0Sstevel@tonic-gate #define CPU_SENSOR_GEO_ADDR 0xe
53*0Sstevel@tonic-gate #define IS_HEALTHY 0x01
54*0Sstevel@tonic-gate #define PICL_NODE_SYSMGMT "sysmgmt"
55*0Sstevel@tonic-gate #define SYSMGMT_PATH PLATFORM_PATH"/pci/pci/isa/sysmgmt"
56*0Sstevel@tonic-gate #define BUF_SIZE 7
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gate /* external functions */
59*0Sstevel@tonic-gate extern picl_errno_t env_create_property(int, int, size_t, char *,
60*0Sstevel@tonic-gate int (*readfn)(ptree_rarg_t *, void *),
61*0Sstevel@tonic-gate int (*writefn)(ptree_warg_t *, const void *),
62*0Sstevel@tonic-gate picl_nodehdl_t, picl_prophdl_t *, void *);
63*0Sstevel@tonic-gate extern picl_errno_t post_dr_req_event(picl_nodehdl_t, char *, uint8_t);
64*0Sstevel@tonic-gate extern picl_errno_t post_dr_ap_state_change_event(picl_nodehdl_t, char *,
65*0Sstevel@tonic-gate uint8_t);
66*0Sstevel@tonic-gate extern boolean_t env_admin_lock_enabled(picl_nodehdl_t);
67*0Sstevel@tonic-gate extern picl_errno_t env_create_temp_sensor_node(picl_nodehdl_t, uint8_t);
68*0Sstevel@tonic-gate extern void env_handle_sensor_event(void *);
69*0Sstevel@tonic-gate extern int env_open_smc();
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate /* external variables */
72*0Sstevel@tonic-gate extern int env_debug;
73*0Sstevel@tonic-gate extern uint8_t cpu_geo_addr;
74*0Sstevel@tonic-gate extern picl_nodehdl_t rooth, platformh, sysmgmth, sensorh;
75*0Sstevel@tonic-gate extern picl_nodehdl_t chassis_nodehdl, cpu_nodehdl, cpu_lnodehdl;
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate /* locals */
78*0Sstevel@tonic-gate static pthread_mutex_t env_dmc_mutex = PTHREAD_MUTEX_INITIALIZER;
79*0Sstevel@tonic-gate static pthread_cond_t env_dmc_cond = PTHREAD_COND_INITIALIZER;
80*0Sstevel@tonic-gate static boolean_t env_reset_cpu = B_FALSE;
81*0Sstevel@tonic-gate static boolean_t env_shutdown_system = B_FALSE;
82*0Sstevel@tonic-gate static env_state_event_t env_chassis_state = FRU_STATE_UNKNOWN;
83*0Sstevel@tonic-gate static char *rcm_abstr_cp2300_name = RCM_ABSTRACT_RESOURCE;
84*0Sstevel@tonic-gate static boolean_t env_got_dmc_msg = B_FALSE;
85*0Sstevel@tonic-gate static long env_dmc_wait_time = 15;
86*0Sstevel@tonic-gate static pthread_t dmc_thr_tid;
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate /*
89*0Sstevel@tonic-gate * issue halt or reboot based on the reset_cpu flag
90*0Sstevel@tonic-gate */
91*0Sstevel@tonic-gate /*ARGSUSED*/
92*0Sstevel@tonic-gate static void
shutdown_cpu(boolean_t force)93*0Sstevel@tonic-gate shutdown_cpu(boolean_t force)
94*0Sstevel@tonic-gate {
95*0Sstevel@tonic-gate if (env_shutdown_system) {
96*0Sstevel@tonic-gate if (env_reset_cpu) {
97*0Sstevel@tonic-gate (void) pclose(popen(RESET_CPU, "w"));
98*0Sstevel@tonic-gate } else {
99*0Sstevel@tonic-gate (void) pclose(popen(SHUTDOWN_CPU, "w"));
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate /*
105*0Sstevel@tonic-gate * inform RCM framework that the remove op is successful
106*0Sstevel@tonic-gate */
107*0Sstevel@tonic-gate static void
confirm_rcm(char * abstr_name,rcm_handle_t * rhandle)108*0Sstevel@tonic-gate confirm_rcm(char *abstr_name, rcm_handle_t *rhandle)
109*0Sstevel@tonic-gate {
110*0Sstevel@tonic-gate rcm_notify_remove(rhandle, abstr_name, 0, NULL);
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate /*
114*0Sstevel@tonic-gate * inform RCM framework that the remove op is failed
115*0Sstevel@tonic-gate */
116*0Sstevel@tonic-gate static void
fail_rcm(char * abstr_name,rcm_handle_t * rhandle)117*0Sstevel@tonic-gate fail_rcm(char *abstr_name, rcm_handle_t *rhandle)
118*0Sstevel@tonic-gate {
119*0Sstevel@tonic-gate (void) rcm_notify_online(rhandle, abstr_name, 0, NULL);
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate /*
123*0Sstevel@tonic-gate * check RCM framework if it is ok to offline a device
124*0Sstevel@tonic-gate */
125*0Sstevel@tonic-gate static int
check_rcm(char * rcm_abstr_cp2300_name,uint_t flags)126*0Sstevel@tonic-gate check_rcm(char *rcm_abstr_cp2300_name, uint_t flags)
127*0Sstevel@tonic-gate {
128*0Sstevel@tonic-gate rcm_info_t *rinfo;
129*0Sstevel@tonic-gate rcm_handle_t *rhandle;
130*0Sstevel@tonic-gate int rv;
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate if (rcm_alloc_handle(NULL, 0, NULL, &rhandle) != RCM_SUCCESS) {
133*0Sstevel@tonic-gate return (RCM_FAILURE);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate rv = rcm_request_offline(rhandle, rcm_abstr_cp2300_name,
137*0Sstevel@tonic-gate flags, &rinfo);
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate if (rv == RCM_FAILURE) {
140*0Sstevel@tonic-gate rcm_free_info(rinfo);
141*0Sstevel@tonic-gate fail_rcm(rcm_abstr_cp2300_name, rhandle);
142*0Sstevel@tonic-gate rcm_free_handle(rhandle);
143*0Sstevel@tonic-gate return (RCM_FAILURE);
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate if (rv == RCM_CONFLICT) {
146*0Sstevel@tonic-gate rcm_free_info(rinfo);
147*0Sstevel@tonic-gate rcm_free_handle(rhandle);
148*0Sstevel@tonic-gate return (RCM_CONFLICT);
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate confirm_rcm(rcm_abstr_cp2300_name, rhandle);
152*0Sstevel@tonic-gate rcm_free_info(rinfo);
153*0Sstevel@tonic-gate rcm_free_handle(rhandle);
154*0Sstevel@tonic-gate return (RCM_SUCCESS);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate /*
158*0Sstevel@tonic-gate * utility routine to send response to an IPMI message
159*0Sstevel@tonic-gate */
160*0Sstevel@tonic-gate static int
send_response2remote_device(uint8_t ipmb_addr,uint8_t cmd,uint8_t reqseq_lun,uint8_t cc)161*0Sstevel@tonic-gate send_response2remote_device(uint8_t ipmb_addr, uint8_t cmd, uint8_t reqseq_lun,
162*0Sstevel@tonic-gate uint8_t cc)
163*0Sstevel@tonic-gate {
164*0Sstevel@tonic-gate int rc = SMC_SUCCESS;
165*0Sstevel@tonic-gate sc_reqmsg_t req_pkt;
166*0Sstevel@tonic-gate sc_rspmsg_t rsp_pkt;
167*0Sstevel@tonic-gate uint8_t data = cc; /* completion code */
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate /* make a call to ctsmc lib */
170*0Sstevel@tonic-gate (void) smc_init_ipmi_msg(&req_pkt, cmd, DEFAULT_FD, 1, &data,
171*0Sstevel@tonic-gate (reqseq_lun >> 2), ipmb_addr, SMC_NETFN_APP_RSP,
172*0Sstevel@tonic-gate (reqseq_lun & 0x03));
173*0Sstevel@tonic-gate rc = smc_send_msg(DEFAULT_FD, &req_pkt, &rsp_pkt,
174*0Sstevel@tonic-gate POLL_TIMEOUT);
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate if (rc != SMC_SUCCESS)
177*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Error in sending response"
178*0Sstevel@tonic-gate " to %x, error = %d"), ipmb_addr, rc);
179*0Sstevel@tonic-gate return (rc);
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate /*
183*0Sstevel@tonic-gate * do all the checks like adminlock check, rcm check and initiate
184*0Sstevel@tonic-gate * shutdown
185*0Sstevel@tonic-gate */
186*0Sstevel@tonic-gate /*ARGSUSED*/
187*0Sstevel@tonic-gate static int
initiate_shutdown(boolean_t force)188*0Sstevel@tonic-gate initiate_shutdown(boolean_t force)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate int rv;
191*0Sstevel@tonic-gate uint_t rcmflags = 0;
192*0Sstevel@tonic-gate struct timespec rqtp, rmtp;
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate if (!env_shutdown_system) {
195*0Sstevel@tonic-gate return (-1);
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate /* check the adminlock prop */
199*0Sstevel@tonic-gate if ((!force) && (env_admin_lock_enabled(cpu_nodehdl))) {
200*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond: "
201*0Sstevel@tonic-gate "CPU in use! Cannot shutdown"));
202*0Sstevel@tonic-gate return (-1);
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate if (force) {
206*0Sstevel@tonic-gate rcmflags = RCM_FORCE;
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate /* check with rcm framework */
210*0Sstevel@tonic-gate rv = check_rcm(rcm_abstr_cp2300_name, rcmflags);
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate if ((rv == RCM_FAILURE) || (rv == RCM_CONFLICT)) {
213*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond: RCM error %d, Cannot"
214*0Sstevel@tonic-gate " shutdown"), rv);
215*0Sstevel@tonic-gate return (-1);
216*0Sstevel@tonic-gate }
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gate /*
219*0Sstevel@tonic-gate * force events on chassis node
220*0Sstevel@tonic-gate */
221*0Sstevel@tonic-gate if (force) {
222*0Sstevel@tonic-gate if (post_dr_req_event(chassis_nodehdl, DR_REQ_OUTGOING_RES,
223*0Sstevel@tonic-gate NO_WAIT) == PICL_SUCCESS) {
224*0Sstevel@tonic-gate /* wait a little for clean up of frutree */
225*0Sstevel@tonic-gate rqtp.tv_sec = 5;
226*0Sstevel@tonic-gate rqtp.tv_nsec = 0;
227*0Sstevel@tonic-gate (void) nanosleep(&rqtp, &rmtp);
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate /*
230*0Sstevel@tonic-gate * If force option is set, do it right here for now
231*0Sstevel@tonic-gate * since there is no way to pass this info via events
232*0Sstevel@tonic-gate * to frutree framework.
233*0Sstevel@tonic-gate */
234*0Sstevel@tonic-gate shutdown_cpu(force);
235*0Sstevel@tonic-gate return (0);
236*0Sstevel@tonic-gate }
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate if (post_dr_req_event(chassis_nodehdl, DR_REQ_OUTGOING_RES, NO_WAIT)
239*0Sstevel@tonic-gate != PICL_SUCCESS) {
240*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:cannot shutdown "
241*0Sstevel@tonic-gate "the host CPU."));
242*0Sstevel@tonic-gate return (-1);
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate return (0);
245*0Sstevel@tonic-gate }
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gate /*
248*0Sstevel@tonic-gate * get the HEALTHY# line state
249*0Sstevel@tonic-gate * Return -1 for Error
250*0Sstevel@tonic-gate * 0 for HEALTHY# down
251*0Sstevel@tonic-gate * 1 for HEALTHY# up
252*0Sstevel@tonic-gate */
253*0Sstevel@tonic-gate static int
env_get_healthy_status()254*0Sstevel@tonic-gate env_get_healthy_status()
255*0Sstevel@tonic-gate {
256*0Sstevel@tonic-gate sc_reqmsg_t req_pkt;
257*0Sstevel@tonic-gate sc_rspmsg_t rsp_pkt;
258*0Sstevel@tonic-gate uint8_t size = 0;
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate /* initialize the request packet */
261*0Sstevel@tonic-gate (void) smc_init_smc_msg(&req_pkt, SMC_GET_EXECUTION_STATE,
262*0Sstevel@tonic-gate DEFAULT_SEQN, size);
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate /* make a call to smc library to send cmd */
265*0Sstevel@tonic-gate if (smc_send_msg(DEFAULT_FD, &req_pkt, &rsp_pkt,
266*0Sstevel@tonic-gate POLL_TIMEOUT) != SMC_SUCCESS) {
267*0Sstevel@tonic-gate return (-1);
268*0Sstevel@tonic-gate }
269*0Sstevel@tonic-gate return (rsp_pkt.data[0] & IS_HEALTHY);
270*0Sstevel@tonic-gate }
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate /*
273*0Sstevel@tonic-gate * initialization
274*0Sstevel@tonic-gate */
275*0Sstevel@tonic-gate picl_errno_t
env_platmod_init()276*0Sstevel@tonic-gate env_platmod_init()
277*0Sstevel@tonic-gate {
278*0Sstevel@tonic-gate picl_errno_t rc = PICL_SUCCESS;
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate if (rooth == 0) {
281*0Sstevel@tonic-gate if (ptree_get_root(&rooth) != PICL_SUCCESS) {
282*0Sstevel@tonic-gate return (rc);
283*0Sstevel@tonic-gate }
284*0Sstevel@tonic-gate }
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gate if (chassis_nodehdl == 0) {
287*0Sstevel@tonic-gate if ((rc = ptree_get_node_by_path(PICL_FRUTREE_CHASSIS,
288*0Sstevel@tonic-gate &chassis_nodehdl)) != PICL_SUCCESS) {
289*0Sstevel@tonic-gate return (rc);
290*0Sstevel@tonic-gate }
291*0Sstevel@tonic-gate }
292*0Sstevel@tonic-gate if (post_dr_req_event(chassis_nodehdl, DR_REQ_INCOMING_RES,
293*0Sstevel@tonic-gate NO_WAIT) != PICL_SUCCESS) {
294*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond: Error in "
295*0Sstevel@tonic-gate "Posting configure event for Chassis node"));
296*0Sstevel@tonic-gate rc = PICL_FAILURE;
297*0Sstevel@tonic-gate }
298*0Sstevel@tonic-gate return (rc);
299*0Sstevel@tonic-gate }
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate /*
302*0Sstevel@tonic-gate * release all the resources
303*0Sstevel@tonic-gate */
304*0Sstevel@tonic-gate void
env_platmod_fini()305*0Sstevel@tonic-gate env_platmod_fini()
306*0Sstevel@tonic-gate {
307*0Sstevel@tonic-gate cpu_geo_addr = 0;
308*0Sstevel@tonic-gate rooth = platformh = sysmgmth = 0;
309*0Sstevel@tonic-gate chassis_nodehdl = cpu_nodehdl = cpu_lnodehdl = 0;
310*0Sstevel@tonic-gate env_chassis_state = FRU_STATE_UNKNOWN;
311*0Sstevel@tonic-gate (void) ptree_delete_node(sensorh);
312*0Sstevel@tonic-gate (void) ptree_destroy_node(sensorh);
313*0Sstevel@tonic-gate }
314*0Sstevel@tonic-gate
315*0Sstevel@tonic-gate /*
316*0Sstevel@tonic-gate * handle chassis state change
317*0Sstevel@tonic-gate */
318*0Sstevel@tonic-gate static void
env_handle_chassis_state_event(char * state)319*0Sstevel@tonic-gate env_handle_chassis_state_event(char *state)
320*0Sstevel@tonic-gate {
321*0Sstevel@tonic-gate if (strcmp(state, PICLEVENTARGVAL_CONFIGURING) == 0) {
322*0Sstevel@tonic-gate env_chassis_state = FRU_STATE_CONFIGURING;
323*0Sstevel@tonic-gate return;
324*0Sstevel@tonic-gate }
325*0Sstevel@tonic-gate
326*0Sstevel@tonic-gate if (strcmp(state, PICLEVENTARGVAL_UNCONFIGURED) == 0) {
327*0Sstevel@tonic-gate if (env_chassis_state == FRU_STATE_CONFIGURING ||
328*0Sstevel@tonic-gate env_chassis_state == FRU_STATE_UNKNOWN) {
329*0Sstevel@tonic-gate /* picl intialization is failed, dont issue shutdown */
330*0Sstevel@tonic-gate env_chassis_state = FRU_STATE_UNCONFIGURED;
331*0Sstevel@tonic-gate return;
332*0Sstevel@tonic-gate }
333*0Sstevel@tonic-gate env_chassis_state = FRU_STATE_UNCONFIGURED;
334*0Sstevel@tonic-gate if (env_reset_cpu) {
335*0Sstevel@tonic-gate (void) pclose(popen(RESET_CPU, "w"));
336*0Sstevel@tonic-gate } else {
337*0Sstevel@tonic-gate (void) pclose(popen(SHUTDOWN_CPU, "w"));
338*0Sstevel@tonic-gate }
339*0Sstevel@tonic-gate return;
340*0Sstevel@tonic-gate }
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate if (strcmp(state, PICLEVENTARGVAL_CONFIGURED) == 0) {
343*0Sstevel@tonic-gate env_chassis_state = FRU_STATE_CONFIGURED;
344*0Sstevel@tonic-gate }
345*0Sstevel@tonic-gate }
346*0Sstevel@tonic-gate
347*0Sstevel@tonic-gate /*
348*0Sstevel@tonic-gate * event handler for watchdog state change event
349*0Sstevel@tonic-gate */
350*0Sstevel@tonic-gate static picl_errno_t
env_handle_watchdog_expiry(picl_nodehdl_t wd_nodehdl)351*0Sstevel@tonic-gate env_handle_watchdog_expiry(picl_nodehdl_t wd_nodehdl)
352*0Sstevel@tonic-gate {
353*0Sstevel@tonic-gate picl_errno_t rc = PICL_SUCCESS;
354*0Sstevel@tonic-gate char class[PICL_CLASSNAMELEN_MAX];
355*0Sstevel@tonic-gate char value[PICL_PROPNAMELEN_MAX];
356*0Sstevel@tonic-gate char cond[BUF_SIZE];
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(wd_nodehdl,
359*0Sstevel@tonic-gate PICL_PROP_CLASSNAME, class,
360*0Sstevel@tonic-gate PICL_CLASSNAMELEN_MAX)) != PICL_SUCCESS) {
361*0Sstevel@tonic-gate return (rc);
362*0Sstevel@tonic-gate }
363*0Sstevel@tonic-gate
364*0Sstevel@tonic-gate /* if the event is not of watchdog-timer, return */
365*0Sstevel@tonic-gate if (strcmp(class, PICL_CLASS_WATCHDOG_TIMER) != 0) {
366*0Sstevel@tonic-gate return (PICL_INVALIDARG);
367*0Sstevel@tonic-gate }
368*0Sstevel@tonic-gate
369*0Sstevel@tonic-gate if ((rc = ptree_get_propval_by_name(wd_nodehdl,
370*0Sstevel@tonic-gate PICL_PROP_WATCHDOG_ACTION, value, sizeof (value))) !=
371*0Sstevel@tonic-gate PICL_SUCCESS) {
372*0Sstevel@tonic-gate return (rc);
373*0Sstevel@tonic-gate }
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gate /* if action is none, dont do anything */
376*0Sstevel@tonic-gate if (strcmp(value, PICL_PROPVAL_WD_ACTION_ALARM) != 0) {
377*0Sstevel@tonic-gate return (PICL_SUCCESS);
378*0Sstevel@tonic-gate }
379*0Sstevel@tonic-gate
380*0Sstevel@tonic-gate (void) strncpy(cond, PICLEVENTARGVAL_FAILED, sizeof (cond));
381*0Sstevel@tonic-gate /* update CPU condition to failed */
382*0Sstevel@tonic-gate if ((rc = ptree_update_propval_by_name(cpu_nodehdl,
383*0Sstevel@tonic-gate PICL_PROP_CONDITION, cond, sizeof (cond))) != PICL_SUCCESS) {
384*0Sstevel@tonic-gate return (rc);
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate /* post dr ap state change event */
388*0Sstevel@tonic-gate rc = post_dr_ap_state_change_event(cpu_nodehdl,
389*0Sstevel@tonic-gate DR_RESERVED_ATTR, NO_COND_TIMEDWAIT);
390*0Sstevel@tonic-gate return (rc);
391*0Sstevel@tonic-gate }
392*0Sstevel@tonic-gate
393*0Sstevel@tonic-gate /*
394*0Sstevel@tonic-gate * rotine that handles all the picl state and condition change events
395*0Sstevel@tonic-gate */
396*0Sstevel@tonic-gate void
env_platmod_handle_event(const char * ename,const void * earg,size_t size)397*0Sstevel@tonic-gate env_platmod_handle_event(const char *ename, const void *earg, size_t size)
398*0Sstevel@tonic-gate {
399*0Sstevel@tonic-gate picl_errno_t rc;
400*0Sstevel@tonic-gate picl_nodehdl_t nodeh = 0;
401*0Sstevel@tonic-gate picl_prophdl_t proph;
402*0Sstevel@tonic-gate nvlist_t *nvlp;
403*0Sstevel@tonic-gate char *value;
404*0Sstevel@tonic-gate boolean_t state_event;
405*0Sstevel@tonic-gate env_state_event_t event;
406*0Sstevel@tonic-gate char result[PICL_PROPNAMELEN_MAX];
407*0Sstevel@tonic-gate uint64_t status_time, cond_time;
408*0Sstevel@tonic-gate char cond[BUF_SIZE];
409*0Sstevel@tonic-gate
410*0Sstevel@tonic-gate if (!ename) {
411*0Sstevel@tonic-gate return;
412*0Sstevel@tonic-gate }
413*0Sstevel@tonic-gate if (strcmp(ename, PICLEVENT_STATE_CHANGE) == 0) {
414*0Sstevel@tonic-gate state_event = B_TRUE;
415*0Sstevel@tonic-gate } else if (strcmp(ename, PICLEVENT_CONDITION_CHANGE) == 0) {
416*0Sstevel@tonic-gate state_event = B_FALSE;
417*0Sstevel@tonic-gate } else {
418*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond: unknown event:%s\n"),
419*0Sstevel@tonic-gate ename);
420*0Sstevel@tonic-gate return;
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gate /* unpack the nvlist and get the information */
424*0Sstevel@tonic-gate if (nvlist_unpack((char *)earg, size, &nvlp, NULL)) {
425*0Sstevel@tonic-gate return;
426*0Sstevel@tonic-gate }
427*0Sstevel@tonic-gate if (nvlist_lookup_uint64(nvlp, PICLEVENTARG_NODEHANDLE, &nodeh) == -1) {
428*0Sstevel@tonic-gate nvlist_free(nvlp);
429*0Sstevel@tonic-gate return;
430*0Sstevel@tonic-gate }
431*0Sstevel@tonic-gate if (nvlist_lookup_string(nvlp, (state_event) ?
432*0Sstevel@tonic-gate PICLEVENTARG_STATE :
433*0Sstevel@tonic-gate PICLEVENTARG_CONDITION, &value) != 0) {
434*0Sstevel@tonic-gate nvlist_free(nvlp);
435*0Sstevel@tonic-gate return;
436*0Sstevel@tonic-gate }
437*0Sstevel@tonic-gate
438*0Sstevel@tonic-gate if (env_debug & PICLEVENTS) {
439*0Sstevel@tonic-gate if (ptree_get_propval_by_name(nodeh, PICL_PROP_NAME,
440*0Sstevel@tonic-gate result, sizeof (result)) != PICL_SUCCESS) {
441*0Sstevel@tonic-gate syslog(LOG_ERR, " SUNW_envmond: error in getting"
442*0Sstevel@tonic-gate " node name");
443*0Sstevel@tonic-gate nvlist_free(nvlp);
444*0Sstevel@tonic-gate return;
445*0Sstevel@tonic-gate }
446*0Sstevel@tonic-gate syslog(LOG_INFO, "SUNW_envmond: %s (%s) on %s",
447*0Sstevel@tonic-gate ename, value, result);
448*0Sstevel@tonic-gate }
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gate if (chassis_nodehdl == 0 && state_event) {
451*0Sstevel@tonic-gate if (ptree_get_propval_by_name(nodeh, PICL_PROP_NAME,
452*0Sstevel@tonic-gate result, sizeof (result)) != PICL_SUCCESS) {
453*0Sstevel@tonic-gate nvlist_free(nvlp);
454*0Sstevel@tonic-gate return;
455*0Sstevel@tonic-gate }
456*0Sstevel@tonic-gate if (strcmp(result, PICL_NODE_CHASSIS) == 0) {
457*0Sstevel@tonic-gate chassis_nodehdl = nodeh;
458*0Sstevel@tonic-gate }
459*0Sstevel@tonic-gate }
460*0Sstevel@tonic-gate
461*0Sstevel@tonic-gate if (nodeh == chassis_nodehdl && state_event) {
462*0Sstevel@tonic-gate env_handle_chassis_state_event(value);
463*0Sstevel@tonic-gate nvlist_free(nvlp);
464*0Sstevel@tonic-gate return;
465*0Sstevel@tonic-gate }
466*0Sstevel@tonic-gate
467*0Sstevel@tonic-gate if (strcmp(PICLEVENTARGVAL_DISCONNECTED, value) == 0) {
468*0Sstevel@tonic-gate event = LOC_STATE_DISCONNECTED;
469*0Sstevel@tonic-gate } else if (strcmp(PICLEVENTARGVAL_CONNECTED, value) == 0) {
470*0Sstevel@tonic-gate event = LOC_STATE_CONNECTED;
471*0Sstevel@tonic-gate } else if (strcmp(PICLEVENTARGVAL_EMPTY, value) == 0) {
472*0Sstevel@tonic-gate event = LOC_STATE_EMPTY;
473*0Sstevel@tonic-gate } else if (strcmp(PICLEVENTARGVAL_CONFIGURED, value) == 0) {
474*0Sstevel@tonic-gate event = FRU_STATE_CONFIGURED;
475*0Sstevel@tonic-gate } else if (strcmp(PICLEVENTARGVAL_UNCONFIGURED, value) == 0) {
476*0Sstevel@tonic-gate event = FRU_STATE_UNCONFIGURED;
477*0Sstevel@tonic-gate } else if (strcmp(PICL_PROPVAL_WD_STATE_EXPIRED, value) == 0) {
478*0Sstevel@tonic-gate /* watchdog expiry event */
479*0Sstevel@tonic-gate if ((rc = env_handle_watchdog_expiry(nodeh)) != PICL_SUCCESS) {
480*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Error in handling"
481*0Sstevel@tonic-gate "watchdog expiry event"));
482*0Sstevel@tonic-gate }
483*0Sstevel@tonic-gate nvlist_free(nvlp);
484*0Sstevel@tonic-gate return;
485*0Sstevel@tonic-gate } else {
486*0Sstevel@tonic-gate nvlist_free(nvlp);
487*0Sstevel@tonic-gate return;
488*0Sstevel@tonic-gate }
489*0Sstevel@tonic-gate
490*0Sstevel@tonic-gate switch (event) {
491*0Sstevel@tonic-gate case LOC_STATE_EMPTY:
492*0Sstevel@tonic-gate break;
493*0Sstevel@tonic-gate
494*0Sstevel@tonic-gate case LOC_STATE_DISCONNECTED:
495*0Sstevel@tonic-gate if (nodeh == cpu_lnodehdl) {
496*0Sstevel@tonic-gate (void) initiate_shutdown(B_FALSE);
497*0Sstevel@tonic-gate }
498*0Sstevel@tonic-gate break;
499*0Sstevel@tonic-gate case LOC_STATE_CONNECTED:
500*0Sstevel@tonic-gate if (nodeh != cpu_lnodehdl) {
501*0Sstevel@tonic-gate break;
502*0Sstevel@tonic-gate }
503*0Sstevel@tonic-gate if (ptree_get_propval_by_name(cpu_lnodehdl,
504*0Sstevel@tonic-gate PICL_PROP_CHILD, &cpu_nodehdl,
505*0Sstevel@tonic-gate sizeof (picl_nodehdl_t)) != PICL_SUCCESS) {
506*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Cannot "
507*0Sstevel@tonic-gate "initialize CPU node handle %llx"), nodeh);
508*0Sstevel@tonic-gate cpu_nodehdl = 0;
509*0Sstevel@tonic-gate }
510*0Sstevel@tonic-gate break;
511*0Sstevel@tonic-gate case FRU_STATE_CONFIGURED:
512*0Sstevel@tonic-gate if (nodeh != cpu_nodehdl) {
513*0Sstevel@tonic-gate break;
514*0Sstevel@tonic-gate }
515*0Sstevel@tonic-gate if (ptree_get_prop_by_name(cpu_nodehdl,
516*0Sstevel@tonic-gate PICL_PROP_STATUS_TIME, &proph) != PICL_SUCCESS) {
517*0Sstevel@tonic-gate status_time = (uint64_t)time(NULL);
518*0Sstevel@tonic-gate (void) env_create_property(PICL_PTYPE_TIMESTAMP,
519*0Sstevel@tonic-gate PICL_READ, sizeof (status_time),
520*0Sstevel@tonic-gate PICL_PROP_STATUS_TIME, NULLREAD,
521*0Sstevel@tonic-gate NULLWRITE, cpu_nodehdl, &proph,
522*0Sstevel@tonic-gate &status_time);
523*0Sstevel@tonic-gate }
524*0Sstevel@tonic-gate if (ptree_get_prop_by_name(cpu_nodehdl,
525*0Sstevel@tonic-gate PICL_PROP_CONDITION_TIME, &proph) != PICL_SUCCESS) {
526*0Sstevel@tonic-gate cond_time = (uint64_t)time(NULL);
527*0Sstevel@tonic-gate (void) env_create_property(PICL_PTYPE_TIMESTAMP,
528*0Sstevel@tonic-gate PICL_READ, sizeof (cond_time),
529*0Sstevel@tonic-gate PICL_PROP_CONDITION_TIME, NULLREAD,
530*0Sstevel@tonic-gate NULLWRITE, cpu_nodehdl, &proph,
531*0Sstevel@tonic-gate &cond_time);
532*0Sstevel@tonic-gate }
533*0Sstevel@tonic-gate env_shutdown_system = B_FALSE;
534*0Sstevel@tonic-gate /* if HEALTHY# is UP update the condition to "ok" */
535*0Sstevel@tonic-gate switch (env_get_healthy_status()) {
536*0Sstevel@tonic-gate case 0:
537*0Sstevel@tonic-gate /* update CPU condition to failed */
538*0Sstevel@tonic-gate (void) strncpy(cond, PICLEVENTARGVAL_FAILED, sizeof (cond));
539*0Sstevel@tonic-gate break;
540*0Sstevel@tonic-gate case 1:
541*0Sstevel@tonic-gate /* update CPU condition to ok */
542*0Sstevel@tonic-gate (void) strncpy(cond, PICLEVENTARGVAL_OK, sizeof (cond));
543*0Sstevel@tonic-gate break;
544*0Sstevel@tonic-gate case -1: /*FALLTHRU*/
545*0Sstevel@tonic-gate default:
546*0Sstevel@tonic-gate /* update the condition to unknown */
547*0Sstevel@tonic-gate (void) strncpy(cond, PICLEVENTARGVAL_UNKNOWN, sizeof (cond));
548*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Error in "
549*0Sstevel@tonic-gate "reading HEALTHY# status"));
550*0Sstevel@tonic-gate }
551*0Sstevel@tonic-gate
552*0Sstevel@tonic-gate if ((rc = ptree_update_propval_by_name(cpu_nodehdl,
553*0Sstevel@tonic-gate PICL_PROP_CONDITION, cond, sizeof (cond))) !=
554*0Sstevel@tonic-gate PICL_SUCCESS) {
555*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Error in "
556*0Sstevel@tonic-gate "updating CPU condition, error = %d"), rc);
557*0Sstevel@tonic-gate }
558*0Sstevel@tonic-gate break;
559*0Sstevel@tonic-gate case FRU_STATE_UNCONFIGURED:
560*0Sstevel@tonic-gate if (env_reset_cpu && nodeh == cpu_nodehdl) {
561*0Sstevel@tonic-gate (void) initiate_shutdown(B_FALSE);
562*0Sstevel@tonic-gate }
563*0Sstevel@tonic-gate break;
564*0Sstevel@tonic-gate default:
565*0Sstevel@tonic-gate break;
566*0Sstevel@tonic-gate } /* end of switch */
567*0Sstevel@tonic-gate nvlist_free(nvlp);
568*0Sstevel@tonic-gate }
569*0Sstevel@tonic-gate
570*0Sstevel@tonic-gate /*
571*0Sstevel@tonic-gate * This thread waits for dmc message to come, as it has to send
572*0Sstevel@tonic-gate * response ACK back to DMC. Otherwise DMC may think that message
573*0Sstevel@tonic-gate * is lost and issues poweroff on a node. So there is a chance for
574*0Sstevel@tonic-gate * CPU to be powered off in the middle of shutdown process. If the
575*0Sstevel@tonic-gate * DMC message didnt come, then process the local shutdown request.
576*0Sstevel@tonic-gate */
577*0Sstevel@tonic-gate /*ARGSUSED*/
578*0Sstevel@tonic-gate static void *
env_wait_for_dmc_msg(void * args)579*0Sstevel@tonic-gate env_wait_for_dmc_msg(void *args)
580*0Sstevel@tonic-gate {
581*0Sstevel@tonic-gate struct timeval ct;
582*0Sstevel@tonic-gate struct timespec to;
583*0Sstevel@tonic-gate
584*0Sstevel@tonic-gate (void) pthread_mutex_lock(&env_dmc_mutex);
585*0Sstevel@tonic-gate if (env_got_dmc_msg == B_TRUE) {
586*0Sstevel@tonic-gate (void) pthread_mutex_unlock(&env_dmc_mutex);
587*0Sstevel@tonic-gate return (NULL);
588*0Sstevel@tonic-gate }
589*0Sstevel@tonic-gate
590*0Sstevel@tonic-gate /*
591*0Sstevel@tonic-gate * wait for specified time to check if dmc sends the
592*0Sstevel@tonic-gate * shutdown request
593*0Sstevel@tonic-gate */
594*0Sstevel@tonic-gate (void) gettimeofday(&ct, NULL);
595*0Sstevel@tonic-gate to.tv_sec = ct.tv_sec + env_dmc_wait_time;
596*0Sstevel@tonic-gate to.tv_nsec = 0;
597*0Sstevel@tonic-gate (void) pthread_cond_timedwait(&env_dmc_cond,
598*0Sstevel@tonic-gate &env_dmc_mutex, &to);
599*0Sstevel@tonic-gate if (env_got_dmc_msg == B_TRUE) {
600*0Sstevel@tonic-gate (void) pthread_mutex_unlock(&env_dmc_mutex);
601*0Sstevel@tonic-gate return (NULL);
602*0Sstevel@tonic-gate }
603*0Sstevel@tonic-gate (void) pthread_mutex_unlock(&env_dmc_mutex);
604*0Sstevel@tonic-gate
605*0Sstevel@tonic-gate env_shutdown_system = B_TRUE;
606*0Sstevel@tonic-gate env_reset_cpu = B_FALSE;
607*0Sstevel@tonic-gate (void) initiate_shutdown(B_FALSE);
608*0Sstevel@tonic-gate return (NULL);
609*0Sstevel@tonic-gate }
610*0Sstevel@tonic-gate
611*0Sstevel@tonic-gate /*
612*0Sstevel@tonic-gate * Handle the Latch open event(shutdown the node)
613*0Sstevel@tonic-gate */
614*0Sstevel@tonic-gate picl_errno_t
env_platmod_handle_latch_open()615*0Sstevel@tonic-gate env_platmod_handle_latch_open()
616*0Sstevel@tonic-gate {
617*0Sstevel@tonic-gate /*
618*0Sstevel@tonic-gate * create a thread to process local event after waiting for DMC CPU
619*0Sstevel@tonic-gate * node state offline message
620*0Sstevel@tonic-gate */
621*0Sstevel@tonic-gate if (pthread_create(&dmc_thr_tid, NULL, &env_wait_for_dmc_msg,
622*0Sstevel@tonic-gate NULL) != 0) {
623*0Sstevel@tonic-gate syslog(LOG_ERR, gettext("SUNW_envmond:Error in creating "
624*0Sstevel@tonic-gate "dmc thread"));
625*0Sstevel@tonic-gate return (PICL_FAILURE);
626*0Sstevel@tonic-gate }
627*0Sstevel@tonic-gate return (PICL_SUCCESS);
628*0Sstevel@tonic-gate }
629*0Sstevel@tonic-gate
630*0Sstevel@tonic-gate /*
631*0Sstevel@tonic-gate * For Sanibel, hotswap initialization is not reqd.
632*0Sstevel@tonic-gate */
633*0Sstevel@tonic-gate picl_errno_t
env_platmod_setup_hotswap()634*0Sstevel@tonic-gate env_platmod_setup_hotswap()
635*0Sstevel@tonic-gate {
636*0Sstevel@tonic-gate return (PICL_SUCCESS);
637*0Sstevel@tonic-gate }
638*0Sstevel@tonic-gate
639*0Sstevel@tonic-gate /*
640*0Sstevel@tonic-gate * For sanibel this supoort is not required
641*0Sstevel@tonic-gate */
642*0Sstevel@tonic-gate picl_errno_t
env_platmod_sp_monitor()643*0Sstevel@tonic-gate env_platmod_sp_monitor()
644*0Sstevel@tonic-gate {
645*0Sstevel@tonic-gate return (PICL_SUCCESS);
646*0Sstevel@tonic-gate }
647*0Sstevel@tonic-gate
648*0Sstevel@tonic-gate /*
649*0Sstevel@tonic-gate * For sanibel this supoort is not required
650*0Sstevel@tonic-gate */
651*0Sstevel@tonic-gate picl_errno_t
env_platmod_create_hotswap_prop()652*0Sstevel@tonic-gate env_platmod_create_hotswap_prop()
653*0Sstevel@tonic-gate {
654*0Sstevel@tonic-gate return (PICL_SUCCESS);
655*0Sstevel@tonic-gate }
656*0Sstevel@tonic-gate
657*0Sstevel@tonic-gate /*
658*0Sstevel@tonic-gate * For sanibel this supoort is not required
659*0Sstevel@tonic-gate */
660*0Sstevel@tonic-gate /*ARGSUSED*/
661*0Sstevel@tonic-gate void
process_platmod_sp_heartbeat(uint8_t data)662*0Sstevel@tonic-gate process_platmod_sp_heartbeat(uint8_t data)
663*0Sstevel@tonic-gate {
664*0Sstevel@tonic-gate }
665*0Sstevel@tonic-gate
666*0Sstevel@tonic-gate /*
667*0Sstevel@tonic-gate * For sanibel this supoort is not required
668*0Sstevel@tonic-gate */
669*0Sstevel@tonic-gate /*ARGSUSED*/
670*0Sstevel@tonic-gate int
process_platmod_async_msg_notif(void * resdatap)671*0Sstevel@tonic-gate process_platmod_async_msg_notif(void *resdatap)
672*0Sstevel@tonic-gate {
673*0Sstevel@tonic-gate return (0);
674*0Sstevel@tonic-gate }
675*0Sstevel@tonic-gate
676*0Sstevel@tonic-gate /*
677*0Sstevel@tonic-gate * For sanibel this supoort is not required
678*0Sstevel@tonic-gate */
679*0Sstevel@tonic-gate /*ARGSUSED*/
680*0Sstevel@tonic-gate int
process_platmod_change_cpci_state(void * res_datap)681*0Sstevel@tonic-gate process_platmod_change_cpci_state(void *res_datap)
682*0Sstevel@tonic-gate {
683*0Sstevel@tonic-gate return (0);
684*0Sstevel@tonic-gate }
685*0Sstevel@tonic-gate
686*0Sstevel@tonic-gate /*
687*0Sstevel@tonic-gate * handle request from service processor for shutdown/online
688*0Sstevel@tonic-gate */
689*0Sstevel@tonic-gate int
process_platmod_change_cpu_node_state(void * res_datap)690*0Sstevel@tonic-gate process_platmod_change_cpu_node_state(void *res_datap)
691*0Sstevel@tonic-gate {
692*0Sstevel@tonic-gate int rc = SMC_SUCCESS;
693*0Sstevel@tonic-gate uint8_t state = BYTE_7(res_datap);
694*0Sstevel@tonic-gate boolean_t force_flag = B_FALSE;
695*0Sstevel@tonic-gate
696*0Sstevel@tonic-gate switch (state & 1) {
697*0Sstevel@tonic-gate case CPU_NODE_STATE_OFFLINE:
698*0Sstevel@tonic-gate (void) pthread_mutex_lock(&env_dmc_mutex);
699*0Sstevel@tonic-gate env_got_dmc_msg = B_TRUE;
700*0Sstevel@tonic-gate (void) pthread_cond_signal(&env_dmc_cond);
701*0Sstevel@tonic-gate (void) pthread_mutex_unlock(&env_dmc_mutex);
702*0Sstevel@tonic-gate env_shutdown_system = B_TRUE;
703*0Sstevel@tonic-gate if ((state >> 2) & 1)
704*0Sstevel@tonic-gate env_reset_cpu = B_TRUE;
705*0Sstevel@tonic-gate if (state >> 1 & 1) { /* force flag set? */
706*0Sstevel@tonic-gate force_flag = B_TRUE;
707*0Sstevel@tonic-gate } else {
708*0Sstevel@tonic-gate force_flag = B_FALSE;
709*0Sstevel@tonic-gate }
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gate if (initiate_shutdown(force_flag) == 0) {
712*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
713*0Sstevel@tonic-gate EVENT_MSG_CHANGE_CPU_NODE_STATE,
714*0Sstevel@tonic-gate BYTE_5(res_datap), 0x0)) != SMC_SUCCESS) {
715*0Sstevel@tonic-gate return (rc);
716*0Sstevel@tonic-gate }
717*0Sstevel@tonic-gate } else {
718*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
719*0Sstevel@tonic-gate EVENT_MSG_CHANGE_CPU_NODE_STATE,
720*0Sstevel@tonic-gate BYTE_5(res_datap), 0xFF)) != SMC_SUCCESS) {
721*0Sstevel@tonic-gate return (rc);
722*0Sstevel@tonic-gate }
723*0Sstevel@tonic-gate env_shutdown_system = B_FALSE;
724*0Sstevel@tonic-gate if ((state >> 2) & 1)
725*0Sstevel@tonic-gate env_reset_cpu = B_FALSE;
726*0Sstevel@tonic-gate }
727*0Sstevel@tonic-gate break;
728*0Sstevel@tonic-gate case CPU_NODE_STATE_ONLINE:
729*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
730*0Sstevel@tonic-gate EVENT_MSG_CHANGE_CPU_NODE_STATE,
731*0Sstevel@tonic-gate BYTE_5(res_datap), 0x0)) != SMC_SUCCESS) {
732*0Sstevel@tonic-gate return (rc);
733*0Sstevel@tonic-gate }
734*0Sstevel@tonic-gate break;
735*0Sstevel@tonic-gate default:
736*0Sstevel@tonic-gate break;
737*0Sstevel@tonic-gate }
738*0Sstevel@tonic-gate return (0);
739*0Sstevel@tonic-gate }
740*0Sstevel@tonic-gate
741*0Sstevel@tonic-gate /*
742*0Sstevel@tonic-gate * Handle change in state of service processor
743*0Sstevel@tonic-gate */
744*0Sstevel@tonic-gate int
process_platmod_sp_state_change_notif(void * res_datap)745*0Sstevel@tonic-gate process_platmod_sp_state_change_notif(void *res_datap)
746*0Sstevel@tonic-gate {
747*0Sstevel@tonic-gate int rc = SMC_SUCCESS;
748*0Sstevel@tonic-gate uint8_t state = BYTE_7(res_datap);
749*0Sstevel@tonic-gate uint8_t rq_addr = BYTE_4(res_datap);
750*0Sstevel@tonic-gate
751*0Sstevel@tonic-gate if (rq_addr != SMC_BMC_ADDR) {
752*0Sstevel@tonic-gate return (PICL_FAILURE);
753*0Sstevel@tonic-gate }
754*0Sstevel@tonic-gate
755*0Sstevel@tonic-gate switch (state) {
756*0Sstevel@tonic-gate case CPU_NODE_STATE_ONLINE:
757*0Sstevel@tonic-gate /* Send ACK to service processor */
758*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
759*0Sstevel@tonic-gate EVENT_MSG_AC_STATE_CHANGE,
760*0Sstevel@tonic-gate BYTE_5(res_datap), 0x0)) != SMC_SUCCESS) {
761*0Sstevel@tonic-gate return (rc);
762*0Sstevel@tonic-gate }
763*0Sstevel@tonic-gate break;
764*0Sstevel@tonic-gate
765*0Sstevel@tonic-gate case CPU_NODE_STATE_OFFLINE:
766*0Sstevel@tonic-gate /* Send ACK to service processor */
767*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
768*0Sstevel@tonic-gate EVENT_MSG_AC_STATE_CHANGE,
769*0Sstevel@tonic-gate BYTE_5(res_datap), 0x0)) != SMC_SUCCESS) {
770*0Sstevel@tonic-gate return (rc);
771*0Sstevel@tonic-gate }
772*0Sstevel@tonic-gate break;
773*0Sstevel@tonic-gate
774*0Sstevel@tonic-gate default:
775*0Sstevel@tonic-gate if ((rc = send_response2remote_device(SMC_BMC_ADDR,
776*0Sstevel@tonic-gate EVENT_MSG_AC_STATE_CHANGE,
777*0Sstevel@tonic-gate BYTE_5(res_datap), 0xFF)) != SMC_SUCCESS) {
778*0Sstevel@tonic-gate return (rc);
779*0Sstevel@tonic-gate }
780*0Sstevel@tonic-gate break;
781*0Sstevel@tonic-gate }
782*0Sstevel@tonic-gate return (0);
783*0Sstevel@tonic-gate }
784*0Sstevel@tonic-gate
785*0Sstevel@tonic-gate /*
786*0Sstevel@tonic-gate * For sanibel this supoort is not required
787*0Sstevel@tonic-gate */
788*0Sstevel@tonic-gate /*ARGSUSED*/
789*0Sstevel@tonic-gate picl_errno_t
env_platmod_handle_bus_if_change(uint8_t data)790*0Sstevel@tonic-gate env_platmod_handle_bus_if_change(uint8_t data)
791*0Sstevel@tonic-gate {
792*0Sstevel@tonic-gate return (PICL_SUCCESS);
793*0Sstevel@tonic-gate }
794*0Sstevel@tonic-gate
795*0Sstevel@tonic-gate /*
796*0Sstevel@tonic-gate * create the temperature sensor nodes
797*0Sstevel@tonic-gate */
798*0Sstevel@tonic-gate picl_errno_t
env_platmod_create_sensors()799*0Sstevel@tonic-gate env_platmod_create_sensors()
800*0Sstevel@tonic-gate {
801*0Sstevel@tonic-gate picl_errno_t rc = PICL_SUCCESS;
802*0Sstevel@tonic-gate
803*0Sstevel@tonic-gate if (rooth == 0) {
804*0Sstevel@tonic-gate if ((rc = ptree_get_root(&rooth)) != PICL_SUCCESS) {
805*0Sstevel@tonic-gate return (rc);
806*0Sstevel@tonic-gate }
807*0Sstevel@tonic-gate }
808*0Sstevel@tonic-gate
809*0Sstevel@tonic-gate if (platformh == 0) {
810*0Sstevel@tonic-gate if ((rc = ptree_get_node_by_path(PLATFORM_PATH,
811*0Sstevel@tonic-gate &platformh)) != PICL_SUCCESS) {
812*0Sstevel@tonic-gate return (rc);
813*0Sstevel@tonic-gate }
814*0Sstevel@tonic-gate }
815*0Sstevel@tonic-gate
816*0Sstevel@tonic-gate if (sysmgmth == 0) {
817*0Sstevel@tonic-gate if ((rc = ptree_get_node_by_path(SYSMGMT_PATH,
818*0Sstevel@tonic-gate &sysmgmth)) != PICL_SUCCESS) {
819*0Sstevel@tonic-gate return (rc);
820*0Sstevel@tonic-gate }
821*0Sstevel@tonic-gate }
822*0Sstevel@tonic-gate
823*0Sstevel@tonic-gate rc = env_create_temp_sensor_node(sysmgmth, CPU_SENSOR_GEO_ADDR);
824*0Sstevel@tonic-gate return (rc);
825*0Sstevel@tonic-gate }
826*0Sstevel@tonic-gate
827*0Sstevel@tonic-gate /*
828*0Sstevel@tonic-gate * handler for sensor event
829*0Sstevel@tonic-gate */
830*0Sstevel@tonic-gate void
env_platmod_handle_sensor_event(void * res_datap)831*0Sstevel@tonic-gate env_platmod_handle_sensor_event(void *res_datap)
832*0Sstevel@tonic-gate {
833*0Sstevel@tonic-gate if (BYTE_4(res_datap) != CPU_SENSOR_GEO_ADDR) {
834*0Sstevel@tonic-gate return;
835*0Sstevel@tonic-gate }
836*0Sstevel@tonic-gate env_handle_sensor_event(res_datap);
837*0Sstevel@tonic-gate }
838