17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55eb92cf2Sdhain  * Common Development and Distribution License (the "License").
65eb92cf2Sdhain  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
228a88157cSvb  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Daktari platform platform specific environment monitoring policies
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #include	<poll.h>
307c478bd9Sstevel@tonic-gate #include	<syslog.h>
317c478bd9Sstevel@tonic-gate #include	<unistd.h>
327c478bd9Sstevel@tonic-gate #include	<stdio.h>
337c478bd9Sstevel@tonic-gate #include	<stdlib.h>
347c478bd9Sstevel@tonic-gate #include	<errno.h>
357c478bd9Sstevel@tonic-gate #include	<fcntl.h>
367c478bd9Sstevel@tonic-gate #include	<strings.h>
377c478bd9Sstevel@tonic-gate #include	<libintl.h>
387c478bd9Sstevel@tonic-gate #include	<sys/types.h>
397c478bd9Sstevel@tonic-gate #include	<sys/param.h>
407c478bd9Sstevel@tonic-gate #include	<config_admin.h>
417c478bd9Sstevel@tonic-gate #include	<libdevice.h>
427c478bd9Sstevel@tonic-gate #include	<picl.h>
437c478bd9Sstevel@tonic-gate #include	<picltree.h>
447c478bd9Sstevel@tonic-gate #include	<psvc_objects.h>
457c478bd9Sstevel@tonic-gate #include	<sys/i2c/clients/i2c_client.h>
467c478bd9Sstevel@tonic-gate #include	<sys/daktari.h>
477c478bd9Sstevel@tonic-gate #include	<sys/hpc3130_events.h>
487c478bd9Sstevel@tonic-gate #include	<assert.h>
49298b7f4cSjfrank #include	<limits.h>
50298b7f4cSjfrank #include	<sys/systeminfo.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* resides in libcfgadm */
557c478bd9Sstevel@tonic-gate extern cfga_err_t config_change_state(cfga_cmd_t, int, char *const *,
567c478bd9Sstevel@tonic-gate 	const char *, struct cfga_confirm *, struct cfga_msg *, char **,
577c478bd9Sstevel@tonic-gate 	cfga_flags_t);
587c478bd9Sstevel@tonic-gate /* Local Routine */
597c478bd9Sstevel@tonic-gate static int32_t update_gen_fault_led(psvc_opaque_t, char *);
607c478bd9Sstevel@tonic-gate static void shutdown_routine(void);
617c478bd9Sstevel@tonic-gate static int32_t update_thresholds(psvc_opaque_t hdlp, char *id, int offset);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #ifdef DEBUG
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static int dak_policy_debug = 0;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	D1SYS_ERR(ARGS) if (dak_policy_debug & 0x1) syslog ARGS;
697c478bd9Sstevel@tonic-gate #define	D2SYS_ERR(ARGS) if (dak_policy_debug & 0x2) syslog ARGS;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #else
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	D1SYS_ERR(ARGS)
747c478bd9Sstevel@tonic-gate #define	D2SYS_ERR(ARGS)
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	I2C_PATH	"/devices/pci@9,700000/ebus@1/i2c@1,30"
79159cf8a6Swesolows #define	I2C_NODE	I2C_PATH ":devctl"
80159cf8a6Swesolows #define	PCF8574		I2C_PATH "/ioexp@0,%x:pcf8574"
81159cf8a6Swesolows #define	PCF8591		I2C_PATH "/adio@0,%x:port_0"
82159cf8a6Swesolows #define	FRU		I2C_PATH "/fru@0,%x:fru"
83159cf8a6Swesolows #define	HPC3130_DEV	I2C_PATH "/hotplug-controller@0,%2x:port_%1x"
847c478bd9Sstevel@tonic-gate #define	GEN_FAULT_LED	"FSP_GEN_FAULT_LED"
857c478bd9Sstevel@tonic-gate #define	EMPTY_STRING	"EMPTY"
867c478bd9Sstevel@tonic-gate #define	DEVICE_FAILURE_MSG	gettext("WARNING: Device %s failure detected")
877c478bd9Sstevel@tonic-gate #define	DEVICE_INSERTED_MSG	gettext("Device %s inserted")
887c478bd9Sstevel@tonic-gate #define	DEVICE_REMOVED_MSG	gettext("Device %s removed")
897c478bd9Sstevel@tonic-gate #define	PS_UNPLUGGED_MSG	gettext("Device %s unplugged")
907c478bd9Sstevel@tonic-gate #define	PS_PLUGGED_MSG		gettext("Device %s Plugged in")
917c478bd9Sstevel@tonic-gate #define	DEVICE_OK_MSG		gettext("Device %s OK")
927c478bd9Sstevel@tonic-gate #define	SET_LED_FAILED_MSG		\
937c478bd9Sstevel@tonic-gate 	gettext("Failed to set LED state, id = %s, errno = %d\n")
947c478bd9Sstevel@tonic-gate #define	GET_PRESENCE_FAILED_MSG		\
957c478bd9Sstevel@tonic-gate 	gettext("Failed to get presence attribute, id = %s, errno = %d\n")
967c478bd9Sstevel@tonic-gate #define	GET_SENSOR_FAILED_MSG		\
977c478bd9Sstevel@tonic-gate 	gettext("Failed to get sensor value, id = %s, errno = %d\n")
987c478bd9Sstevel@tonic-gate #define	ADD_PS_MSG			\
99*338c2f03SToomas Soome     gettext("WARNING: Only 1 Power Supply in system. ADD a 2nd Power Supply.\n")
1007c478bd9Sstevel@tonic-gate #define	REMOVE_LOAD_MSG			\
1017c478bd9Sstevel@tonic-gate 	gettext("WARNING: Power Supply at 95%% current. Remove some load.\n")
1027c478bd9Sstevel@tonic-gate #define	PS_OVER_CURRENT_MSG		\
1037c478bd9Sstevel@tonic-gate 	gettext("WARNING: Power Supply overcurrent detected\n")
1048a88157cSvb #define	PS_UNDER_CURRENT_MSG		\
1058a88157cSvb 	gettext("WARNING: PS%d Undercurrent on one or more DC lines\n")
1067c478bd9Sstevel@tonic-gate #define	DEVICE_UNKNOWN_MSG	gettext("Unknown device %s instance %d\n")
1077c478bd9Sstevel@tonic-gate #define	DEVICE_HANDLE_FAIL_MSG		\
1087c478bd9Sstevel@tonic-gate 	gettext("Failed to get device handle for %s, errno = %d\n")
1097c478bd9Sstevel@tonic-gate #define	DEVTREE_NODE_CREATE_FAILED	\
1107c478bd9Sstevel@tonic-gate 	gettext("psvc PICL plugin: Failed to create node for %s, errno = %d")
1117c478bd9Sstevel@tonic-gate #define	DEVTREE_NODE_DELETE_FAILED	\
1127c478bd9Sstevel@tonic-gate 	gettext("psvc PICL plugin: Failed to delete node for %s, errno = %d")
1137c478bd9Sstevel@tonic-gate #define	DISK_FAULT_MSG		gettext("%s: Error Reported\n")
1147c478bd9Sstevel@tonic-gate #define	DISK_OK_MSG		gettext("%s: Error Cleared\n")
1157c478bd9Sstevel@tonic-gate #define	SET_FANSPEED_FAILED_MSG		\
1167c478bd9Sstevel@tonic-gate 	gettext("Failed to set fan speed, id = %s, errno = %d\n")
1177c478bd9Sstevel@tonic-gate #define	GET_ATTR_FRU_FAILED_MSG	gettext("Failed psvc_get_attr for FRU info\n")
1187c478bd9Sstevel@tonic-gate #define	NO_FRU_INFO_MSG			\
1197c478bd9Sstevel@tonic-gate 	gettext("No FRU Information for %s using default module card\n")
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	DAKTARI_MAX_PS	3
1227c478bd9Sstevel@tonic-gate #define	DAK_MAX_PS_I_SENSORS 4
1237c478bd9Sstevel@tonic-gate #define	DAK_MAX_DISKS	12
1247c478bd9Sstevel@tonic-gate #define	DAK_MAX_CPU_MOD	4
1257c478bd9Sstevel@tonic-gate #define	DAK_MAX_FAULT_SENSORS 3
1267c478bd9Sstevel@tonic-gate #define	DAK_MAX_FANS 10
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate static int co_ps = 0;
1297c478bd9Sstevel@tonic-gate static char *shutdown_string = "shutdown -y -g 60 -i 5 \"OVERTEMP condition\"";
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate typedef struct i2c_hp {
1327c478bd9Sstevel@tonic-gate 	int32_t		addr[2];
1337c478bd9Sstevel@tonic-gate 	char		name[256];
1347c478bd9Sstevel@tonic-gate 	char		compatible[256];
1357c478bd9Sstevel@tonic-gate } i2c_hp_t;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate typedef struct seg_desc {
1387c478bd9Sstevel@tonic-gate 	int32_t segdesc;
1397c478bd9Sstevel@tonic-gate 	int16_t segoffset;
1407c478bd9Sstevel@tonic-gate 	int16_t seglength;
1417c478bd9Sstevel@tonic-gate } seg_desc_t;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate static int32_t threshold_names[] = {
1447c478bd9Sstevel@tonic-gate 	PSVC_HW_LO_SHUT_ATTR,
1457c478bd9Sstevel@tonic-gate 	PSVC_LO_SHUT_ATTR,
1467c478bd9Sstevel@tonic-gate 	PSVC_LO_WARN_ATTR,
1477c478bd9Sstevel@tonic-gate 	PSVC_NOT_USED,			/* LOW MODE which is not used */
1487c478bd9Sstevel@tonic-gate 	PSVC_OPTIMAL_TEMP_ATTR,
1497c478bd9Sstevel@tonic-gate 	PSVC_HI_WARN_ATTR,
1507c478bd9Sstevel@tonic-gate 	PSVC_HI_SHUT_ATTR,
1517c478bd9Sstevel@tonic-gate 	PSVC_HW_HI_SHUT_ATTR
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
154298b7f4cSjfrank /*
155298b7f4cSjfrank  * The I2C bus is noisy, and the state may be incorrectly reported as
156298b7f4cSjfrank  * having changed.  When the state changes, we attempt to confirm by
157298b7f4cSjfrank  * retrying.  If any retries indicate that the state has not changed, we
158298b7f4cSjfrank  * assume the state change(s) were incorrect and the state has not changed.
159298b7f4cSjfrank  * The following variables are used to store the tuneable values read in
160298b7f4cSjfrank  * from the optional i2cparam.conf file for this shared object library.
161298b7f4cSjfrank  */
162298b7f4cSjfrank static int n_retry_pshp_status = PSVC_NUM_OF_RETRIES;
163298b7f4cSjfrank static int retry_sleep_pshp_status = 1;
164298b7f4cSjfrank static int n_read_overcurrent = PSVC_THRESHOLD_COUNTER;
1658a88157cSvb static int n_read_undercurrent = PSVC_THRESHOLD_COUNTER;
166298b7f4cSjfrank static int n_retry_devicefail = PSVC_NUM_OF_RETRIES;
167298b7f4cSjfrank static int retry_sleep_devicefail = 1;
168298b7f4cSjfrank static int n_read_fanfault = PSVC_THRESHOLD_COUNTER;
169298b7f4cSjfrank static int n_retry_pshp = PSVC_NUM_OF_RETRIES;
170298b7f4cSjfrank static int retry_sleep_pshp = 1;
171298b7f4cSjfrank static int n_retry_diskfault = PSVC_NUM_OF_RETRIES;
172298b7f4cSjfrank static int retry_sleep_diskfault = 1;
173298b7f4cSjfrank static int n_retry_temp_shutdown = PSVC_NUM_OF_RETRIES;
174298b7f4cSjfrank static int retry_sleep_temp_shutdown = 1;
175298b7f4cSjfrank 
176298b7f4cSjfrank typedef struct {
177298b7f4cSjfrank 	int *pvar;
178298b7f4cSjfrank 	char *texttag;
179298b7f4cSjfrank } i2c_noise_param_t;
180298b7f4cSjfrank 
181298b7f4cSjfrank static i2c_noise_param_t i2cparams[] = {
182298b7f4cSjfrank 	&n_retry_pshp_status, "n_retry_pshp_status",
183298b7f4cSjfrank 	&retry_sleep_pshp_status, "retry_sleep_pshp_status",
184298b7f4cSjfrank 	&n_read_overcurrent, "n_read_overcurrent",
1858a88157cSvb 	&n_read_undercurrent, "n_read_undercurrent",
186298b7f4cSjfrank 	&n_retry_devicefail, "n_retry_devicefail",
187298b7f4cSjfrank 	&retry_sleep_devicefail, "retry_sleep_devicefail",
188298b7f4cSjfrank 	&n_read_fanfault, "n_read_fanfault",
189298b7f4cSjfrank 	&n_retry_pshp, "n_retry_pshp",
190298b7f4cSjfrank 	&retry_sleep_pshp, "retry_sleep_pshp",
191298b7f4cSjfrank 	&n_retry_diskfault, "n_retry_diskfault",
192298b7f4cSjfrank 	&retry_sleep_diskfault, "retry_sleep_diskfault",
193298b7f4cSjfrank 	&n_retry_temp_shutdown, "n_retry_temp_shutdown",
194298b7f4cSjfrank 	&retry_sleep_temp_shutdown, "retry_sleep_temp_shutdown",
195298b7f4cSjfrank 	NULL, NULL
196298b7f4cSjfrank };
197298b7f4cSjfrank 
198298b7f4cSjfrank #pragma init(i2cparams_load)
199298b7f4cSjfrank 
200298b7f4cSjfrank static void
i2cparams_debug(i2c_noise_param_t * pi2cparams,char * platform,int usingDefaults)201298b7f4cSjfrank i2cparams_debug(i2c_noise_param_t *pi2cparams, char *platform,
202*338c2f03SToomas Soome     int usingDefaults)
203298b7f4cSjfrank {
204298b7f4cSjfrank 	char s[128];
205298b7f4cSjfrank 	i2c_noise_param_t *p;
206298b7f4cSjfrank 
207298b7f4cSjfrank 	if (!usingDefaults) {
208298b7f4cSjfrank 		(void) snprintf(s, sizeof (s),
209298b7f4cSjfrank 		    "# Values from /usr/platform/%s/lib/i2cparam.conf\n",
210298b7f4cSjfrank 		    platform);
211298b7f4cSjfrank 		syslog(LOG_WARNING, "%s", s);
212298b7f4cSjfrank 	} else {
213298b7f4cSjfrank 		/* no file - we're using the defaults */
214298b7f4cSjfrank 		(void) snprintf(s, sizeof (s),
215298b7f4cSjfrank "# No /usr/platform/%s/lib/i2cparam.conf file, using defaults\n",
216298b7f4cSjfrank 		    platform);
217298b7f4cSjfrank 	}
218298b7f4cSjfrank 	(void) fputs(s, stdout);
219298b7f4cSjfrank 	p = pi2cparams;
220298b7f4cSjfrank 	while (p->pvar != NULL) {
221298b7f4cSjfrank 		(void) snprintf(s, sizeof (s), "%s %d\n", p->texttag,
222298b7f4cSjfrank 		    *(p->pvar));
223298b7f4cSjfrank 		if (!usingDefaults)
224298b7f4cSjfrank 			syslog(LOG_WARNING, "%s", s);
225298b7f4cSjfrank 		(void) fputs(s, stdout);
226298b7f4cSjfrank 		p++;
227298b7f4cSjfrank 	}
228298b7f4cSjfrank }
229298b7f4cSjfrank 
230298b7f4cSjfrank static void
i2cparams_load(void)231298b7f4cSjfrank i2cparams_load(void)
232298b7f4cSjfrank {
233298b7f4cSjfrank 	FILE *fp;
234298b7f4cSjfrank 	char filename[PATH_MAX];
235298b7f4cSjfrank 	char platform[64];
236298b7f4cSjfrank 	char s[128];
237298b7f4cSjfrank 	char var[128];
238298b7f4cSjfrank 	int val;
239298b7f4cSjfrank 	i2c_noise_param_t *p;
240298b7f4cSjfrank 
241298b7f4cSjfrank 	if (sysinfo(SI_PLATFORM, platform, sizeof (platform)) == -1) {
242298b7f4cSjfrank 		syslog(LOG_ERR, "sysinfo error %s\n", strerror(errno));
243298b7f4cSjfrank 		return;
244298b7f4cSjfrank 	}
245298b7f4cSjfrank 	(void) snprintf(filename, sizeof (filename),
246298b7f4cSjfrank 	    "/usr/platform/%s/lib/i2cparam.conf", platform);
247298b7f4cSjfrank 	/* read thru the i2cparam.conf file and set variables */
248298b7f4cSjfrank 	if ((fp = fopen(filename, "r")) != NULL) {
249298b7f4cSjfrank 		while (fgets(s, sizeof (s), fp) != NULL) {
250298b7f4cSjfrank 			if (s[0] == '#') /* skip comment lines */
251298b7f4cSjfrank 				continue;
252298b7f4cSjfrank 			/* try to find a string match and get the value */
253298b7f4cSjfrank 			if (sscanf(s, "%127s %d", var, &val) != 2)
254298b7f4cSjfrank 				continue;
255298b7f4cSjfrank 			if (val < 1)
256298b7f4cSjfrank 				val = 1;  /* clamp min value */
257298b7f4cSjfrank 			p = &(i2cparams[0]);
258298b7f4cSjfrank 			while (p->pvar != NULL) {
259298b7f4cSjfrank 				if (strncmp(p->texttag, var, sizeof (var)) ==
260298b7f4cSjfrank 				    0) {
261298b7f4cSjfrank 					*(p->pvar) = val;
262298b7f4cSjfrank 					break;
263298b7f4cSjfrank 				}
264298b7f4cSjfrank 				p++;
265298b7f4cSjfrank 			}
266298b7f4cSjfrank 		}
267298b7f4cSjfrank 		(void) fclose(fp);
268298b7f4cSjfrank 	}
269298b7f4cSjfrank 	/* output the values of the parameters */
270298b7f4cSjfrank 	i2cparams_debug(&(i2cparams[0]), platform, ((fp == NULL)? 1 : 0));
271298b7f4cSjfrank }
272298b7f4cSjfrank 
2737c478bd9Sstevel@tonic-gate int32_t
psvc_MB_update_thresholds_0(psvc_opaque_t hdlp,char * id,int offset)2747c478bd9Sstevel@tonic-gate psvc_MB_update_thresholds_0(psvc_opaque_t hdlp, char *id, int offset)
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate 	int IO_offset = 0xd;
2777c478bd9Sstevel@tonic-gate 	int32_t err;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	err = update_thresholds(hdlp, id, IO_offset);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	return (err);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate int32_t
psvc_IO_update_thresholds_0(psvc_opaque_t hdlp,char * id,int offset)2857c478bd9Sstevel@tonic-gate psvc_IO_update_thresholds_0(psvc_opaque_t hdlp, char *id, int offset)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate 	int IO_offset = 0x8;
2887c478bd9Sstevel@tonic-gate 	int32_t err;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	err = update_thresholds(hdlp, id, IO_offset);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	return (err);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate int32_t
psvc_DBP_update_thresholds_0(psvc_opaque_t hdlp,char * id,int offset)2967c478bd9Sstevel@tonic-gate psvc_DBP_update_thresholds_0(psvc_opaque_t hdlp, char *id, int offset)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	int IO_offset = 0x7;
2997c478bd9Sstevel@tonic-gate 	int32_t err;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	err = update_thresholds(hdlp, id, IO_offset);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	return (err);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate  * used to determine if a change of state occured. valid when states
3087c478bd9Sstevel@tonic-gate  * are strings.
3097c478bd9Sstevel@tonic-gate  */
3107c478bd9Sstevel@tonic-gate static int8_t
change_of_state_str(char * state1,char * check1,char * state2,char * check2)3117c478bd9Sstevel@tonic-gate change_of_state_str(char *state1, char *check1, char *state2, char *check2)
3127c478bd9Sstevel@tonic-gate {
3137c478bd9Sstevel@tonic-gate 	int change = 0;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	if ((strcmp(state1, check1) == 0) && (strcmp(state2, check2) != 0))
3167c478bd9Sstevel@tonic-gate 		change = 1;
3177c478bd9Sstevel@tonic-gate 	if ((strcmp(state1, check1) != 0) && (strcmp(state2, check2) == 0))
3187c478bd9Sstevel@tonic-gate 		change = 1;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	return (change);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * Update thresholds tries to read the temperature thresholds from the FRU
3257c478bd9Sstevel@tonic-gate  * SEEproms and then updates the thresholds in the object by overriding the
3267c478bd9Sstevel@tonic-gate  * hardcoded thresholds.  For Daktari it is an Error if the FRU does not
3277c478bd9Sstevel@tonic-gate  * contain the segment that had the temperature thresholds.
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate static int32_t
update_thresholds(psvc_opaque_t hdlp,char * id,int offset)3307c478bd9Sstevel@tonic-gate update_thresholds(psvc_opaque_t hdlp, char *id, int offset)
3317c478bd9Sstevel@tonic-gate {
3327c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
3337c478bd9Sstevel@tonic-gate 	fru_info_t fru_data;
3347c478bd9Sstevel@tonic-gate 	char *fru, seg_name[2];
3357c478bd9Sstevel@tonic-gate 	int8_t seg_count, temp_array[8];
3367c478bd9Sstevel@tonic-gate 	int32_t match_count, i, j, seg_desc_start = 0x1806, temp_address;
3377c478bd9Sstevel@tonic-gate 	int32_t seg_found, temp;
3387c478bd9Sstevel@tonic-gate 	boolean_t present;
3397c478bd9Sstevel@tonic-gate 	seg_desc_t segment;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
3427c478bd9Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (present != PSVC_PRESENT))
3437c478bd9Sstevel@tonic-gate 		return (status);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &match_count,
3467c478bd9Sstevel@tonic-gate 	    PSVC_FRU);
3477c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
3487c478bd9Sstevel@tonic-gate 		return (status);
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	for (i = 0; i < match_count; i++) {
3517c478bd9Sstevel@tonic-gate 		seg_found = 0;
3527c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
3537c478bd9Sstevel@tonic-gate 		    &fru, PSVC_FRU, i);
3547c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
3557c478bd9Sstevel@tonic-gate 			return (status);
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 		fru_data.buf_start = 0x1805;
3587c478bd9Sstevel@tonic-gate 		fru_data.buf = (char *)&seg_count;
3597c478bd9Sstevel@tonic-gate 		fru_data.read_size = 1;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
3627c478bd9Sstevel@tonic-gate 		    &fru_data);
3637c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS) {
3647c478bd9Sstevel@tonic-gate 			return (status);
3657c478bd9Sstevel@tonic-gate 		}
3667c478bd9Sstevel@tonic-gate 		for (j = 0; (j < seg_count) && (!seg_found); j++) {
3677c478bd9Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
3687c478bd9Sstevel@tonic-gate 			fru_data.buf = seg_name;
3697c478bd9Sstevel@tonic-gate 			fru_data.read_size = 2;
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
3727c478bd9Sstevel@tonic-gate 			    &fru_data);
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + 2;
3757c478bd9Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
3767c478bd9Sstevel@tonic-gate 			fru_data.buf = (char *)&segment;
3777c478bd9Sstevel@tonic-gate 			fru_data.read_size = sizeof (seg_desc_t);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
3807c478bd9Sstevel@tonic-gate 			    &fru_data);
3817c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
3827c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
3837c478bd9Sstevel@tonic-gate 				    "Failed psvc_get_attr for FRU info\n");
3847c478bd9Sstevel@tonic-gate 				return (status);
3857c478bd9Sstevel@tonic-gate 			}
3867c478bd9Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + sizeof (seg_desc_t);
3877c478bd9Sstevel@tonic-gate 			if (memcmp(seg_name, "SC", 2) == 0)
3887c478bd9Sstevel@tonic-gate 				seg_found = 1;
3897c478bd9Sstevel@tonic-gate 		}
3907c478bd9Sstevel@tonic-gate 		if (seg_found) {
3917c478bd9Sstevel@tonic-gate 			temp_address = segment.segoffset + offset;
3927c478bd9Sstevel@tonic-gate 			fru_data.buf_start = temp_address;
3937c478bd9Sstevel@tonic-gate 			fru_data.buf = (char *)&temp_array;
3947c478bd9Sstevel@tonic-gate 			fru_data.read_size = sizeof (temp_array);
3957c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
3967c478bd9Sstevel@tonic-gate 			    &fru_data);
3977c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
3987c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
3997c478bd9Sstevel@tonic-gate 				    "Failed psvc_get_attr for FRU info\n");
4007c478bd9Sstevel@tonic-gate 				return (status);
4017c478bd9Sstevel@tonic-gate 			} else {
4027c478bd9Sstevel@tonic-gate 				for (j = 0; j < sizeof (temp_array); j++) {
4037c478bd9Sstevel@tonic-gate 					if (threshold_names[j] ==
4047c478bd9Sstevel@tonic-gate 					    PSVC_NOT_USED)
4057c478bd9Sstevel@tonic-gate 						continue;
4067c478bd9Sstevel@tonic-gate 					temp = temp_array[j];
4077c478bd9Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, id,
4087c478bd9Sstevel@tonic-gate 					    threshold_names[j], &temp);
4097c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS) {
4107c478bd9Sstevel@tonic-gate 						return (status);
4117c478bd9Sstevel@tonic-gate 					}
4127c478bd9Sstevel@tonic-gate 				}
4137c478bd9Sstevel@tonic-gate 			}
4147c478bd9Sstevel@tonic-gate 		} else {
4157c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, "No FRU Information for %s"
4167c478bd9Sstevel@tonic-gate 			    " using default temperatures\n", id);
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 	return (status);
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate int32_t
psvc_fan_init_speed_0(psvc_opaque_t hdlp,char * id)4237c478bd9Sstevel@tonic-gate psvc_fan_init_speed_0(psvc_opaque_t hdlp, char *id)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
4267c478bd9Sstevel@tonic-gate 	boolean_t present;
4277c478bd9Sstevel@tonic-gate 	char *control_id;
4287c478bd9Sstevel@tonic-gate 	int32_t init_speed = 0;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
4317c478bd9Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (present != PSVC_PRESENT))
4327c478bd9Sstevel@tonic-gate 		return (status);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR, &control_id,
4355eb92cf2Sdhain 	    PSVC_FAN_DRIVE_CONTROL, 0);
4367c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
4377c478bd9Sstevel@tonic-gate 		return (status);
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, control_id, PSVC_CONTROL_VALUE_ATTR,
4407c478bd9Sstevel@tonic-gate 	    &init_speed);
4417c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
4427c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, SET_FANSPEED_FAILED_MSG, control_id, errno);
4437c478bd9Sstevel@tonic-gate 		return (status);
4447c478bd9Sstevel@tonic-gate 	}
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	return (status);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate int32_t
psvc_update_setpoint_0(psvc_opaque_t hdlp,char * id)4507c478bd9Sstevel@tonic-gate psvc_update_setpoint_0(psvc_opaque_t hdlp, char *id)
4517c478bd9Sstevel@tonic-gate {
4527c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
4537c478bd9Sstevel@tonic-gate 	char *temp_sensor;
4547c478bd9Sstevel@tonic-gate 	int32_t match_count, i, temp;
4557c478bd9Sstevel@tonic-gate 	int16_t lowest_temp = 500;
4567c478bd9Sstevel@tonic-gate 	boolean_t present;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
4597c478bd9Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (present != PSVC_PRESENT))
4607c478bd9Sstevel@tonic-gate 		return (status);
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &match_count,
4637c478bd9Sstevel@tonic-gate 	    PSVC_DEV_TEMP_SENSOR);
4647c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
4657c478bd9Sstevel@tonic-gate 		return (status);
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	for (i = 0; i < match_count; i++) {
4687c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
4697c478bd9Sstevel@tonic-gate 		    &temp_sensor, PSVC_DEV_TEMP_SENSOR, i);
4707c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
4717c478bd9Sstevel@tonic-gate 			return (status);
4727c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, temp_sensor,
4737c478bd9Sstevel@tonic-gate 		    PSVC_OPTIMAL_TEMP_ATTR, &temp);
4747c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS) {
4757c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, "Failed to get Optimal temp for %s\n",
4767c478bd9Sstevel@tonic-gate 			    temp_sensor);
4777c478bd9Sstevel@tonic-gate 			return (status);
4787c478bd9Sstevel@tonic-gate 		}
4797c478bd9Sstevel@tonic-gate 		if (temp < lowest_temp)
4807c478bd9Sstevel@tonic-gate 			lowest_temp = temp;
4817c478bd9Sstevel@tonic-gate 	}
4827c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_SETPOINT_ATTR, &lowest_temp);
4837c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
4847c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "Failed to change setpoint for %s\n", id);
4857c478bd9Sstevel@tonic-gate 		return (status);
4867c478bd9Sstevel@tonic-gate 	}
4877c478bd9Sstevel@tonic-gate 	return (status);
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate int32_t
psvc_remove_missing_nodes_0(psvc_opaque_t hdlp,char * id)4917c478bd9Sstevel@tonic-gate psvc_remove_missing_nodes_0(psvc_opaque_t hdlp, char *id)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
4947c478bd9Sstevel@tonic-gate 	char state[32];
4957c478bd9Sstevel@tonic-gate 	char *physical_dev;
4967c478bd9Sstevel@tonic-gate 	int32_t i, device_count;
4977c478bd9Sstevel@tonic-gate 	char parent_path[256];
4987c478bd9Sstevel@tonic-gate 	picl_nodehdl_t child_node;
4997c478bd9Sstevel@tonic-gate 	boolean_t present;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR,
5027c478bd9Sstevel@tonic-gate 	    &device_count, PSVC_PHYSICAL_DEVICE);
5037c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
5047c478bd9Sstevel@tonic-gate 		return (status);
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	for (i = 0; i < device_count; i++) {
5077c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
5087c478bd9Sstevel@tonic-gate 		    &physical_dev, PSVC_PHYSICAL_DEVICE, i);
5097c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
5107c478bd9Sstevel@tonic-gate 			return (status);
5117c478bd9Sstevel@tonic-gate 		if (strncmp(physical_dev, "LTC1427", 7) == 0)
5127c478bd9Sstevel@tonic-gate 			continue;
5137c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, physical_dev,
5147c478bd9Sstevel@tonic-gate 		    PSVC_PROBE_RESULT_ATTR, state);
5157c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
5167c478bd9Sstevel@tonic-gate 			continue;
5177c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, physical_dev, PSVC_PRESENCE_ATTR,
5187c478bd9Sstevel@tonic-gate 		    &present);
5197c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
5207c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, GET_PRESENCE_FAILED_MSG, physical_dev,
5217c478bd9Sstevel@tonic-gate 			    errno);
5227c478bd9Sstevel@tonic-gate 			return (status);
5237c478bd9Sstevel@tonic-gate 		}
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 		if ((strcmp(state, PSVC_ERROR) == 0) &&
5267c478bd9Sstevel@tonic-gate 		    (present == PSVC_PRESENT)) {
5277c478bd9Sstevel@tonic-gate 			/* convert name to node, and parent path */
5287c478bd9Sstevel@tonic-gate 			psvcplugin_lookup(physical_dev, parent_path,
5297c478bd9Sstevel@tonic-gate 			    &child_node);
5307c478bd9Sstevel@tonic-gate 			/* Device removed */
5317c478bd9Sstevel@tonic-gate 			ptree_delete_node(child_node);
5327c478bd9Sstevel@tonic-gate 		}
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 	return (status);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate int32_t
psvc_check_ps_hotplug_status_0(psvc_opaque_t hdlp,char * id)5387c478bd9Sstevel@tonic-gate psvc_check_ps_hotplug_status_0(psvc_opaque_t hdlp, char *id)
5397c478bd9Sstevel@tonic-gate {
5407c478bd9Sstevel@tonic-gate 	char		fail_valid_switch_id[PICL_PROPNAMELEN_MAX];
5417c478bd9Sstevel@tonic-gate 	int32_t		status = PSVC_SUCCESS;
5427c478bd9Sstevel@tonic-gate 	char		valid_switch_state[32];
5437c478bd9Sstevel@tonic-gate 	char		state[32], fault[32];
5447c478bd9Sstevel@tonic-gate 	int32_t		led_count, j;
5457c478bd9Sstevel@tonic-gate 	char		*led_id;
5467c478bd9Sstevel@tonic-gate 	char		led_state[32];
5477c478bd9Sstevel@tonic-gate 	boolean_t	present;
5487c478bd9Sstevel@tonic-gate 	static int8_t	hotplug_failed_count = 0;
5495eb92cf2Sdhain 	static int	unplugged_ps = 0;
550298b7f4cSjfrank 	int	retry;
5515eb92cf2Sdhain 	char		*unplugged_id;
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
5547c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
5557c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, GET_PRESENCE_FAILED_MSG, id, errno);
5567c478bd9Sstevel@tonic-gate 		return (status);
5577c478bd9Sstevel@tonic-gate 	}
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	if (present == PSVC_ABSENT) {
5607c478bd9Sstevel@tonic-gate 		errno = ENODEV;
5617c478bd9Sstevel@tonic-gate 		return (PSVC_FAILURE);
5627c478bd9Sstevel@tonic-gate 	}
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	snprintf(fail_valid_switch_id, sizeof (fail_valid_switch_id), "%s%s",
5657c478bd9Sstevel@tonic-gate 	    id, "_SENSOR_VALID_SWITCH");
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 	retry = 0;
5687c478bd9Sstevel@tonic-gate 	do {
5697c478bd9Sstevel@tonic-gate 		if (retry)
570298b7f4cSjfrank 			(void) sleep(retry_sleep_pshp_status);
5717c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, fail_valid_switch_id,
5727c478bd9Sstevel@tonic-gate 		    PSVC_STATE_ATTR, valid_switch_state);
5737c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
5747c478bd9Sstevel@tonic-gate 			if (hotplug_failed_count == 0) {
5757c478bd9Sstevel@tonic-gate 				/*
5767c478bd9Sstevel@tonic-gate 				 * First time the get_attr call failed
5777c478bd9Sstevel@tonic-gate 				 * set count so that if we fail again
5787c478bd9Sstevel@tonic-gate 				 * we will know
5797c478bd9Sstevel@tonic-gate 				 */
5807c478bd9Sstevel@tonic-gate 				hotplug_failed_count = 1;
5817c478bd9Sstevel@tonic-gate 				/*
5827c478bd9Sstevel@tonic-gate 				 * We probably failed because the power
5837c478bd9Sstevel@tonic-gate 				 * supply was just insterted or removed
5847c478bd9Sstevel@tonic-gate 				 * before the get_attr call. We then
5857c478bd9Sstevel@tonic-gate 				 * return from this policy successfully
5867c478bd9Sstevel@tonic-gate 				 * knowing it will be run again shortly
5877c478bd9Sstevel@tonic-gate 				 * with the right PS state.
5887c478bd9Sstevel@tonic-gate 				 */
5897c478bd9Sstevel@tonic-gate 				return (PSVC_SUCCESS);
5907c478bd9Sstevel@tonic-gate 			} else {
5917c478bd9Sstevel@tonic-gate 				/*
5927c478bd9Sstevel@tonic-gate 				 * We have failed before and so this
5937c478bd9Sstevel@tonic-gate 				 * we will consider a hardware problem
5947c478bd9Sstevel@tonic-gate 				 * and it should be reported
5957c478bd9Sstevel@tonic-gate 				 */
5967c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR,
5977c478bd9Sstevel@tonic-gate 				    "Failed getting %s State: ",
5987c478bd9Sstevel@tonic-gate 				    "ps_hotplug_status_0\n",
5997c478bd9Sstevel@tonic-gate 				    fail_valid_switch_id);
6007c478bd9Sstevel@tonic-gate 				return (status);
6017c478bd9Sstevel@tonic-gate 			}
6027c478bd9Sstevel@tonic-gate 		}
6037c478bd9Sstevel@tonic-gate 		/*
6047c478bd9Sstevel@tonic-gate 		 * Because we have successfully gotten a value from
6057c478bd9Sstevel@tonic-gate 		 * the i2c device on the PS we will set the
6067c478bd9Sstevel@tonic-gate 		 * failed_count to 0
6077c478bd9Sstevel@tonic-gate 		 */
6087c478bd9Sstevel@tonic-gate 		hotplug_failed_count = 0;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, state);
6117c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
6127c478bd9Sstevel@tonic-gate 			return (status);
6137c478bd9Sstevel@tonic-gate 		retry++;
6147c478bd9Sstevel@tonic-gate 		/*
6157c478bd9Sstevel@tonic-gate 		 * check to see if we need to retry. the conditions are:
6167c478bd9Sstevel@tonic-gate 		 *
6177c478bd9Sstevel@tonic-gate 		 * valid_switch_state	state			retry
6187c478bd9Sstevel@tonic-gate 		 * --------------------------------------------------
6197c478bd9Sstevel@tonic-gate 		 *	PSVC_OFF	!PSVC_HOTPLUGGED	yes
6207c478bd9Sstevel@tonic-gate 		 *	PSVC_ON		PSVC_HOTPLUGGED		yes
6217c478bd9Sstevel@tonic-gate 		 *	PSVC_OFF	PSVC_HOTPLUGGED		no
6227c478bd9Sstevel@tonic-gate 		 *	PSVC_ON		!PSVC_HOTPLUGGED	no
6237c478bd9Sstevel@tonic-gate 		 */
624298b7f4cSjfrank 	} while ((retry < n_retry_pshp_status) &&
6257c478bd9Sstevel@tonic-gate 	    change_of_state_str(valid_switch_state, PSVC_OFF,
6267c478bd9Sstevel@tonic-gate 	    state, PSVC_HOTPLUGGED));
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	if ((strcmp(valid_switch_state, PSVC_OFF) == 0) &&
6295eb92cf2Sdhain 	    (strcmp(state, PSVC_HOTPLUGGED) != 0)) {
6307c478bd9Sstevel@tonic-gate 		strcpy(state, PSVC_HOTPLUGGED);
6317c478bd9Sstevel@tonic-gate 		strcpy(fault, PSVC_NO_FAULT);
6327c478bd9Sstevel@tonic-gate 		strcpy(led_state, PSVC_LED_OFF);
6337c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
6345eb92cf2Sdhain 		    state);
6357c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
6367c478bd9Sstevel@tonic-gate 			return (status);
6377c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR,
6385eb92cf2Sdhain 		    &led_count, PSVC_DEV_FAULT_LED);
6397c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
6407c478bd9Sstevel@tonic-gate 			return (status);
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 		for (j = 0; j < led_count; j++) {
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
6455eb92cf2Sdhain 			    &led_id, PSVC_DEV_FAULT_LED, j);
6467c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6477c478bd9Sstevel@tonic-gate 				return (status);
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, led_id,
6505eb92cf2Sdhain 			    PSVC_LED_STATE_ATTR, led_state);
6517c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
6527c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, SET_LED_FAILED_MSG, led_id,
6537c478bd9Sstevel@tonic-gate 				    errno);
6547c478bd9Sstevel@tonic-gate 				return (status);
6557c478bd9Sstevel@tonic-gate 			}
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 		}
6585eb92cf2Sdhain 		strcpy(led_state, PSVC_LED_ON);
6595eb92cf2Sdhain 		status = psvc_set_attr(hdlp, "FSP_POWER_FAULT_LED",
6605eb92cf2Sdhain 		    PSVC_LED_STATE_ATTR, led_state);
6615eb92cf2Sdhain 		if (status != PSVC_SUCCESS) {
6625eb92cf2Sdhain 			syslog(LOG_ERR, SET_LED_FAILED_MSG, led_id, errno);
6635eb92cf2Sdhain 			return (status);
6645eb92cf2Sdhain 		}
6655eb92cf2Sdhain 		unplugged_id = id + 2;
6665eb92cf2Sdhain 		unplugged_ps = unplugged_ps | (1 << (int)strtol(unplugged_id,
6675eb92cf2Sdhain 		    (char **)NULL, 10));
6685eb92cf2Sdhain 		status = update_gen_fault_led(hdlp, GEN_FAULT_LED);
6697c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, PS_UNPLUGGED_MSG, id);
6707c478bd9Sstevel@tonic-gate 		return (status);
6717c478bd9Sstevel@tonic-gate 	}
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	if ((strcmp(valid_switch_state, PSVC_ON) == 0) &&
6745eb92cf2Sdhain 	    (strcmp(state, PSVC_HOTPLUGGED) == 0)) {
6757c478bd9Sstevel@tonic-gate 		strcpy(state, PSVC_OK);
6767c478bd9Sstevel@tonic-gate 		strcpy(fault, PSVC_NO_FAULT);
6777c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
6787c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
6797c478bd9Sstevel@tonic-gate 			return (status);
6805eb92cf2Sdhain 		unplugged_id = id + 2;
6815eb92cf2Sdhain 		unplugged_ps = unplugged_ps ^ (1 << (int)strtol(unplugged_id,
6825eb92cf2Sdhain 		    (char **)NULL, 10));
6835eb92cf2Sdhain 		if (unplugged_ps == 0) {
6845eb92cf2Sdhain 			strcpy(led_state, PSVC_LED_OFF);
6855eb92cf2Sdhain 			status = psvc_set_attr(hdlp, "FSP_POWER_FAULT_LED",
6865eb92cf2Sdhain 			    PSVC_LED_STATE_ATTR, led_state);
6875eb92cf2Sdhain 			if (status != PSVC_SUCCESS) {
6885eb92cf2Sdhain 				syslog(LOG_ERR, SET_LED_FAILED_MSG, led_id,
6895eb92cf2Sdhain 				    errno);
6905eb92cf2Sdhain 				return (status);
6915eb92cf2Sdhain 			}
6925eb92cf2Sdhain 			status = update_gen_fault_led(hdlp, GEN_FAULT_LED);
6935eb92cf2Sdhain 		}
6947c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, PS_PLUGGED_MSG, id);
6957c478bd9Sstevel@tonic-gate 	}
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 	return (status);
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate int32_t
psvc_ps_overcurrent_check_policy_0(psvc_opaque_t hdlp,char * system)7017c478bd9Sstevel@tonic-gate psvc_ps_overcurrent_check_policy_0(psvc_opaque_t hdlp, char *system)
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
7047c478bd9Sstevel@tonic-gate 	boolean_t present;
7057c478bd9Sstevel@tonic-gate 	static char *sensor_id[DAKTARI_MAX_PS][DAK_MAX_PS_I_SENSORS];
706360e6f5eSmathue 	static char *power_supply_id[DAKTARI_MAX_PS] = {NULL};
7077c478bd9Sstevel@tonic-gate 	int32_t i, j;
7087c478bd9Sstevel@tonic-gate 	int32_t amps, oc_flag = 0, ps_present = 0;
7097c478bd9Sstevel@tonic-gate 	static int32_t hi_warn[DAKTARI_MAX_PS][DAK_MAX_PS_I_SENSORS];
7107c478bd9Sstevel@tonic-gate 	char state[32];
7117c478bd9Sstevel@tonic-gate 	static int8_t overcurrent_failed_check = 0;
712298b7f4cSjfrank 	static int threshold_counter = 0;
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	if (power_supply_id[0] == NULL) {
7157c478bd9Sstevel@tonic-gate 		for (i = 0; i < DAKTARI_MAX_PS; i++) {
7167c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, system,
7177c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &(power_supply_id[i]),
7187c478bd9Sstevel@tonic-gate 			    PSVC_PS, i);
7197c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
7207c478bd9Sstevel@tonic-gate 				return (status);
7217c478bd9Sstevel@tonic-gate 			for (j = 0; j < DAK_MAX_PS_I_SENSORS; ++j) {
7227c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp,
7237c478bd9Sstevel@tonic-gate 				    power_supply_id[i], PSVC_ASSOC_ID_ATTR,
7247c478bd9Sstevel@tonic-gate 				    &(sensor_id[i][j]), PSVC_PS_I_SENSOR, j);
7257c478bd9Sstevel@tonic-gate 				if (status != PSVC_SUCCESS)
7267c478bd9Sstevel@tonic-gate 					return (status);
7277c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, sensor_id[i][j],
7287c478bd9Sstevel@tonic-gate 				    PSVC_HI_WARN_ATTR, &(hi_warn[i][j]));
7297c478bd9Sstevel@tonic-gate 				if (status != PSVC_SUCCESS)
7307c478bd9Sstevel@tonic-gate 					return (status);
7317c478bd9Sstevel@tonic-gate 			}
7327c478bd9Sstevel@tonic-gate 		}
7337c478bd9Sstevel@tonic-gate 	}
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 	for (i = 0; i < DAKTARI_MAX_PS; i++) {
7367c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, power_supply_id[i],
7375eb92cf2Sdhain 		    PSVC_PRESENCE_ATTR, &present);
7387c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
7397c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, GET_PRESENCE_FAILED_MSG,
7405eb92cf2Sdhain 			    power_supply_id[i], errno);
7417c478bd9Sstevel@tonic-gate 			return (status);
7427c478bd9Sstevel@tonic-gate 		}
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		if (present == PSVC_ABSENT) {
7457c478bd9Sstevel@tonic-gate 			continue;
7467c478bd9Sstevel@tonic-gate 		}
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 		status = psvc_check_ps_hotplug_status_0(hdlp,
7497c478bd9Sstevel@tonic-gate 		    power_supply_id[i]);
7507c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
7517c478bd9Sstevel@tonic-gate 			return (status);
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, power_supply_id[i],
7547c478bd9Sstevel@tonic-gate 		    PSVC_STATE_ATTR, state);
7557c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
7567c478bd9Sstevel@tonic-gate 			return (status);
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 		if (strcmp(state, PSVC_HOTPLUGGED) == 0) {
7597c478bd9Sstevel@tonic-gate 			continue;
7607c478bd9Sstevel@tonic-gate 		} else {
7617c478bd9Sstevel@tonic-gate 			ps_present++;
7627c478bd9Sstevel@tonic-gate 		}
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 		for (j = 0; j < DAK_MAX_PS_I_SENSORS; ++j) {
7657c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, sensor_id[i][j],
7665eb92cf2Sdhain 			    PSVC_SENSOR_VALUE_ATTR, &amps);
7677c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
7687c478bd9Sstevel@tonic-gate 				if (overcurrent_failed_check == 0) {
7697c478bd9Sstevel@tonic-gate 					/*
7707c478bd9Sstevel@tonic-gate 					 * First time the get_attr call
7717c478bd9Sstevel@tonic-gate 					 * failed  set count so that if we
7727c478bd9Sstevel@tonic-gate 					 * fail again we will know
7737c478bd9Sstevel@tonic-gate 					 */
7747c478bd9Sstevel@tonic-gate 					overcurrent_failed_check = 1;
7757c478bd9Sstevel@tonic-gate 					/*
7767c478bd9Sstevel@tonic-gate 					 * We probably failed because the power
7777c478bd9Sstevel@tonic-gate 					 * supply was just insterted or removed
7787c478bd9Sstevel@tonic-gate 					 * before the get_attr call. We then
7797c478bd9Sstevel@tonic-gate 					 * return from this policy successfully
7807c478bd9Sstevel@tonic-gate 					 * knowing it will be run again shortly
7817c478bd9Sstevel@tonic-gate 					 * with the right PS state.
7827c478bd9Sstevel@tonic-gate 					 */
7837c478bd9Sstevel@tonic-gate 					return (PSVC_SUCCESS);
7847c478bd9Sstevel@tonic-gate 				} else {
7857c478bd9Sstevel@tonic-gate 					/*
7867c478bd9Sstevel@tonic-gate 					 * We have failed before and so this we
7877c478bd9Sstevel@tonic-gate 					 * will consider a hardware problem and
7887c478bd9Sstevel@tonic-gate 					 * it should be reported.
7897c478bd9Sstevel@tonic-gate 					 */
7907c478bd9Sstevel@tonic-gate 					syslog(LOG_ERR,
7917c478bd9Sstevel@tonic-gate 					    "Failed getting %s sensor value",
7927c478bd9Sstevel@tonic-gate 					    sensor_id[i][j]);
7937c478bd9Sstevel@tonic-gate 					return (status);
7947c478bd9Sstevel@tonic-gate 				}
7957c478bd9Sstevel@tonic-gate 			}
7967c478bd9Sstevel@tonic-gate 			/*
7977c478bd9Sstevel@tonic-gate 			 * Because we have successfully gotten a value from the
7987c478bd9Sstevel@tonic-gate 			 * i2c device on the PS we will set the failed_count
7997c478bd9Sstevel@tonic-gate 			 * to 0.
8007c478bd9Sstevel@tonic-gate 			 */
8017c478bd9Sstevel@tonic-gate 			overcurrent_failed_check = 0;
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 			if (amps >= hi_warn[i][j]) {
8047c478bd9Sstevel@tonic-gate 				oc_flag = 1;
8057c478bd9Sstevel@tonic-gate 			}
8067c478bd9Sstevel@tonic-gate 		}
8077c478bd9Sstevel@tonic-gate 	}
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate 	if (oc_flag) {
8107c478bd9Sstevel@tonic-gate 		/*
8117c478bd9Sstevel@tonic-gate 		 * Because we observed an overcurrent
8127c478bd9Sstevel@tonic-gate 		 * condition, we increment threshold_counter.
8137c478bd9Sstevel@tonic-gate 		 * Once threshold_counter reaches the value
814298b7f4cSjfrank 		 * of n_read_overcurrent we log the event.
8157c478bd9Sstevel@tonic-gate 		 */
8167c478bd9Sstevel@tonic-gate 		threshold_counter++;
817298b7f4cSjfrank 		if (threshold_counter == n_read_overcurrent) {
8187c478bd9Sstevel@tonic-gate 			threshold_counter = 0;
8197c478bd9Sstevel@tonic-gate 			if (ps_present == 1) {
8207c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, PS_OVER_CURRENT_MSG);
8217c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, ADD_PS_MSG);
8227c478bd9Sstevel@tonic-gate 			} else {
8237c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, PS_OVER_CURRENT_MSG);
8247c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, REMOVE_LOAD_MSG);
8257c478bd9Sstevel@tonic-gate 			}
8267c478bd9Sstevel@tonic-gate 		}
8277c478bd9Sstevel@tonic-gate 	} else {
8287c478bd9Sstevel@tonic-gate 		threshold_counter = 0;
8297c478bd9Sstevel@tonic-gate 	}
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
8327c478bd9Sstevel@tonic-gate }
8337c478bd9Sstevel@tonic-gate 
8348a88157cSvb int32_t
psvc_ps_undercurrent_check(psvc_opaque_t hdlp,char * id,int32_t * uc_flag)8358a88157cSvb psvc_ps_undercurrent_check(psvc_opaque_t hdlp, char *id, int32_t *uc_flag)
8368a88157cSvb {
8378a88157cSvb 	int32_t status = PSVC_SUCCESS;
8388a88157cSvb 	boolean_t present;
8398a88157cSvb 	static char *sensor_id[DAK_MAX_PS_I_SENSORS];
8408a88157cSvb 	int32_t j;
8418a88157cSvb 	int32_t amps;
8428a88157cSvb 	static int32_t lo_warn[DAK_MAX_PS_I_SENSORS];
8438a88157cSvb 	static int8_t undercurrent_failed_check = 0;
8448a88157cSvb 
8458a88157cSvb 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
8468a88157cSvb 	if (status == PSVC_FAILURE) {
8478a88157cSvb 		syslog(LOG_ERR, GET_PRESENCE_FAILED_MSG, id, errno);
8488a88157cSvb 		return (status);
8498a88157cSvb 	}
8508a88157cSvb 
8518a88157cSvb 	if (present == PSVC_ABSENT) {
8528a88157cSvb 		errno = ENODEV;
8538a88157cSvb 		return (PSVC_FAILURE);
8548a88157cSvb 	}
8558a88157cSvb 
8568a88157cSvb 	for (j = 0; j < DAK_MAX_PS_I_SENSORS; ++j) {
8578a88157cSvb 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
8588a88157cSvb 		    &(sensor_id[j]), PSVC_PS_I_SENSOR, j);
8598a88157cSvb 		if (status != PSVC_SUCCESS)
8608a88157cSvb 			return (status);
8618a88157cSvb 		status = psvc_get_attr(hdlp, sensor_id[j],
8628a88157cSvb 		    PSVC_LO_WARN_ATTR, &(lo_warn[j]));
8638a88157cSvb 		if (status != PSVC_SUCCESS)
8648a88157cSvb 			return (status);
8658a88157cSvb 	}
8668a88157cSvb 
8678a88157cSvb 	*uc_flag = 0;
8688a88157cSvb 	for (j = 0; j < DAK_MAX_PS_I_SENSORS; ++j) {
8698a88157cSvb 		status = psvc_get_attr(hdlp, sensor_id[j],
8708a88157cSvb 		    PSVC_SENSOR_VALUE_ATTR, &amps);
8718a88157cSvb 		if (status != PSVC_SUCCESS) {
8728a88157cSvb 			if (undercurrent_failed_check == 0) {
8738a88157cSvb 				/*
8748a88157cSvb 				 * First time the get_attr call
8758a88157cSvb 				 * failed  set count so that if we
8768a88157cSvb 				 * fail again we will know.
8778a88157cSvb 				 */
8788a88157cSvb 				undercurrent_failed_check = 1;
8798a88157cSvb 				/*
8808a88157cSvb 				 * We probably failed because the power
8818a88157cSvb 				 * supply was just inserted or removed
8828a88157cSvb 				 * before the get_attr call. We then
8838a88157cSvb 				 * return from this policy successfully
8848a88157cSvb 				 * knowing it will be run again shortly
8858a88157cSvb 				 * with the right PS state.
8868a88157cSvb 				 */
8878a88157cSvb 				return (PSVC_SUCCESS);
8888a88157cSvb 			} else {
8898a88157cSvb 				/*
8908a88157cSvb 				 * Repeated failures are logged.
8918a88157cSvb 				 */
8928a88157cSvb 				syslog(LOG_ERR,
8938a88157cSvb 				    "Failed getting %s sensor value",
8948a88157cSvb 				    sensor_id[j]);
8958a88157cSvb 				return (status);
8968a88157cSvb 			}
8978a88157cSvb 		}
8988a88157cSvb 		/*
8998a88157cSvb 		 * Because we have successfully gotten a value from the
9008a88157cSvb 		 * i2c device on the PS we will set the failed_count
9018a88157cSvb 		 * to 0.
9028a88157cSvb 		 */
9038a88157cSvb 		undercurrent_failed_check = 0;
9048a88157cSvb 
9058a88157cSvb 		if (amps <= lo_warn[j]) {
9068a88157cSvb 			*uc_flag = 1;
9078a88157cSvb 			return (PSVC_SUCCESS);
9088a88157cSvb 		}
9098a88157cSvb 	}
9108a88157cSvb 
9118a88157cSvb 	return (PSVC_SUCCESS);
9128a88157cSvb }
9138a88157cSvb 
9147c478bd9Sstevel@tonic-gate int32_t
psvc_ps_device_fail_notifier_policy_0(psvc_opaque_t hdlp,char * system)9157c478bd9Sstevel@tonic-gate psvc_ps_device_fail_notifier_policy_0(psvc_opaque_t hdlp, char *system)
9167c478bd9Sstevel@tonic-gate {
917360e6f5eSmathue 	static char *ps_id[DAKTARI_MAX_PS] = {NULL};
9187c478bd9Sstevel@tonic-gate 	static char *sensor_id[DAKTARI_MAX_PS][DAK_MAX_FAULT_SENSORS];
9197c478bd9Sstevel@tonic-gate 	char *led_id = "FSP_POWER_FAULT_LED";
9208a88157cSvb 	int i, j, uc_flag;
9217c478bd9Sstevel@tonic-gate 	char state[32], fault[32], previous_state[32], past_state[32];
9227c478bd9Sstevel@tonic-gate 	char led_state[32];
9237c478bd9Sstevel@tonic-gate 	char bad_sensors[DAK_MAX_FAULT_SENSORS][256];
9248a88157cSvb 	static int threshold_counter[DAKTARI_MAX_PS];
9257c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
9267c478bd9Sstevel@tonic-gate 	boolean_t present;
9277c478bd9Sstevel@tonic-gate 	int fail_state;
9287c478bd9Sstevel@tonic-gate 	static int8_t device_fail_failed_check = 0;
929298b7f4cSjfrank 	int retry, should_retry;
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate 	if (ps_id[0] == NULL) {
9327c478bd9Sstevel@tonic-gate 		for (i = 0; i < DAKTARI_MAX_PS; i++) {
9337c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, system,
9347c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &(ps_id[i]), PSVC_PS, i);
9357c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
9367c478bd9Sstevel@tonic-gate 				return (status);
9377c478bd9Sstevel@tonic-gate 			for (j = 0; j < DAK_MAX_FAULT_SENSORS; j++) {
9387c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, ps_id[i],
9397c478bd9Sstevel@tonic-gate 				    PSVC_ASSOC_ID_ATTR, &(sensor_id[i][j]),
9407c478bd9Sstevel@tonic-gate 				    PSVC_DEV_FAULT_SENSOR, j);
9417c478bd9Sstevel@tonic-gate 				if (status != PSVC_SUCCESS)
9427c478bd9Sstevel@tonic-gate 					return (status);
9437c478bd9Sstevel@tonic-gate 			}
9447c478bd9Sstevel@tonic-gate 		}
9457c478bd9Sstevel@tonic-gate 	}
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 	for (i = 0; i < DAKTARI_MAX_PS; i++) {
9487c478bd9Sstevel@tonic-gate 		fail_state = 0;
9497c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, ps_id[i], PSVC_PRESENCE_ATTR,
9507c478bd9Sstevel@tonic-gate 		    &present);
9517c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
9527c478bd9Sstevel@tonic-gate 			return (status);
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 		if (present == PSVC_ABSENT) {
9557c478bd9Sstevel@tonic-gate 			errno = ENODEV;
9567c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
9577c478bd9Sstevel@tonic-gate 		}
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 		status = psvc_check_ps_hotplug_status_0(hdlp, ps_id[i]);
9607c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
9617c478bd9Sstevel@tonic-gate 			return (status);
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, ps_id[i], PSVC_STATE_ATTR,
9647c478bd9Sstevel@tonic-gate 		    past_state);
9657c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
9667c478bd9Sstevel@tonic-gate 			return (status);
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 		if (strcmp(past_state, PSVC_HOTPLUGGED) == 0) {
9697c478bd9Sstevel@tonic-gate 			return (PICL_SUCCESS);
9707c478bd9Sstevel@tonic-gate 		}
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 		retry = 0;
9737c478bd9Sstevel@tonic-gate 		do {
9747c478bd9Sstevel@tonic-gate 			if (retry)
975298b7f4cSjfrank 				(void) sleep(retry_sleep_devicefail);
9767c478bd9Sstevel@tonic-gate 			fail_state = 0;
9777c478bd9Sstevel@tonic-gate 			should_retry = 0;
9787c478bd9Sstevel@tonic-gate 			for (j = 0; j < DAK_MAX_FAULT_SENSORS; ++j) {
9797c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, sensor_id[i][j],
9807c478bd9Sstevel@tonic-gate 				    PSVC_SWITCH_STATE_ATTR, state);
9817c478bd9Sstevel@tonic-gate 				if (status != PSVC_SUCCESS) {
9827c478bd9Sstevel@tonic-gate 					if (device_fail_failed_check == 0) {
9837c478bd9Sstevel@tonic-gate 						/*
9847c478bd9Sstevel@tonic-gate 						 * First time the get_attr call
9857c478bd9Sstevel@tonic-gate 						 * failed  set count so that
9867c478bd9Sstevel@tonic-gate 						 * if we fail again we will know
9877c478bd9Sstevel@tonic-gate 						 */
9887c478bd9Sstevel@tonic-gate 						device_fail_failed_check = 1;
9897c478bd9Sstevel@tonic-gate 						/*
9907c478bd9Sstevel@tonic-gate 						 * We probably failed because
9917c478bd9Sstevel@tonic-gate 						 * the power supply was just
9927c478bd9Sstevel@tonic-gate 						 * insterted or removed before
9937c478bd9Sstevel@tonic-gate 						 * the get_attr call. We then
9947c478bd9Sstevel@tonic-gate 						 * return from this policy
9957c478bd9Sstevel@tonic-gate 						 * successfully knowing it will
9967c478bd9Sstevel@tonic-gate 						 * be run again shortly
9977c478bd9Sstevel@tonic-gate 						 * with the right PS state.
9987c478bd9Sstevel@tonic-gate 						 */
9997c478bd9Sstevel@tonic-gate 						return (PSVC_SUCCESS);
10007c478bd9Sstevel@tonic-gate 					} else {
10017c478bd9Sstevel@tonic-gate 						/*
10027c478bd9Sstevel@tonic-gate 						 * We have failed before and
10037c478bd9Sstevel@tonic-gate 						 * so this we will consider a
10047c478bd9Sstevel@tonic-gate 						 * hardware problem and
10057c478bd9Sstevel@tonic-gate 						 * it should be reported.
10067c478bd9Sstevel@tonic-gate 						 */
10077c478bd9Sstevel@tonic-gate 						syslog(LOG_ERR, "Failed in "
10087c478bd9Sstevel@tonic-gate 						    "getting sensor state for "
10097c478bd9Sstevel@tonic-gate 						    "%s\n", sensor_id[i][j]);
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 						return (status);
10127c478bd9Sstevel@tonic-gate 					}
10137c478bd9Sstevel@tonic-gate 				}
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 				/*
10167c478bd9Sstevel@tonic-gate 				 * Because we have successfully gotten
10177c478bd9Sstevel@tonic-gate 				 * a value from the i2c device on the
10187c478bd9Sstevel@tonic-gate 				 * PS we will set the failed_count to 0.
10197c478bd9Sstevel@tonic-gate 				 */
10207c478bd9Sstevel@tonic-gate 				device_fail_failed_check = 0;
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 				/*
10237c478bd9Sstevel@tonic-gate 				 * If we find that the sensor is on we
10247c478bd9Sstevel@tonic-gate 				 * fill in the name of the sensor in
10257c478bd9Sstevel@tonic-gate 				 * the bad_sensor array. If the sensor
10267c478bd9Sstevel@tonic-gate 				 * is off we use EMPTY_STRING as a check
10277c478bd9Sstevel@tonic-gate 				 * later on as to when NOT to print out
10287c478bd9Sstevel@tonic-gate 				 * what is in bad_sensor[].
10297c478bd9Sstevel@tonic-gate 				 */
10307c478bd9Sstevel@tonic-gate 				if (strcmp(state, PSVC_SWITCH_ON) == 0) {
10317c478bd9Sstevel@tonic-gate 					fail_state++;
10327c478bd9Sstevel@tonic-gate 					strlcpy(bad_sensors[j], sensor_id[i][j],
10337c478bd9Sstevel@tonic-gate 					    sizeof (bad_sensors[j]));
10347c478bd9Sstevel@tonic-gate 				} else {
10357c478bd9Sstevel@tonic-gate 					strcpy(bad_sensors[j], EMPTY_STRING);
10367c478bd9Sstevel@tonic-gate 				}
10377c478bd9Sstevel@tonic-gate 			}
10387c478bd9Sstevel@tonic-gate 			retry++;
10397c478bd9Sstevel@tonic-gate 			/*
10407c478bd9Sstevel@tonic-gate 			 * check to see if we need to retry. the conditions are:
10417c478bd9Sstevel@tonic-gate 			 *
10427c478bd9Sstevel@tonic-gate 			 * fail_state		past_state		retry
10437c478bd9Sstevel@tonic-gate 			 * --------------------------------------------------
10447c478bd9Sstevel@tonic-gate 			 *	+		PSVC_OK			yes
10457c478bd9Sstevel@tonic-gate 			 *	0		PSVC_ERROR		yes
10467c478bd9Sstevel@tonic-gate 			 *	+		PSVC_ERROR		no
10477c478bd9Sstevel@tonic-gate 			 *	0		PSVC_OK			no
10487c478bd9Sstevel@tonic-gate 			 */
10497c478bd9Sstevel@tonic-gate 			if ((fail_state > 0) &&
10507c478bd9Sstevel@tonic-gate 			    (strcmp(past_state, PSVC_OK) == 0)) {
10517c478bd9Sstevel@tonic-gate 				should_retry = 1;
10527c478bd9Sstevel@tonic-gate 			} else if ((fail_state == 0) &&
10537c478bd9Sstevel@tonic-gate 			    (strcmp(past_state, PSVC_ERROR) == 0)) {
10547c478bd9Sstevel@tonic-gate 				should_retry = 1;
10557c478bd9Sstevel@tonic-gate 			}
1056298b7f4cSjfrank 		} while ((retry < n_retry_devicefail) && should_retry);
10577c478bd9Sstevel@tonic-gate 
10588a88157cSvb 		/* Under current check */
10598a88157cSvb 		status = psvc_ps_undercurrent_check(hdlp, ps_id[i], &uc_flag);
10608a88157cSvb 
10618a88157cSvb 		if (status != PSVC_FAILURE) {
10628a88157cSvb 			if (uc_flag) {
10638a88157cSvb 				/*
10648a88157cSvb 				 * Because we observed an undercurrent
10658a88157cSvb 				 * condition, we increment threshold counter.
10668a88157cSvb 				 * Once threshold counter reaches the value
10678a88157cSvb 				 * of n_read_undercurrent we log the event.
10688a88157cSvb 				 */
10698a88157cSvb 				threshold_counter[i]++;
10708a88157cSvb 				if (threshold_counter[i] >=
10718a88157cSvb 				    n_read_undercurrent) {
10728a88157cSvb 					fail_state++;
10738a88157cSvb 					syslog(LOG_ERR, PS_UNDER_CURRENT_MSG,
10748a88157cSvb 					    i);
10758a88157cSvb 				}
10768a88157cSvb 			} else {
10778a88157cSvb 				threshold_counter[i] = 0;
10788a88157cSvb 			}
10798a88157cSvb 		}
10808a88157cSvb 
10817c478bd9Sstevel@tonic-gate 		if (fail_state != 0) {
10827c478bd9Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
10837c478bd9Sstevel@tonic-gate 			strcpy(fault, PSVC_GEN_FAULT);
10847c478bd9Sstevel@tonic-gate 		} else {
10857c478bd9Sstevel@tonic-gate 			strcpy(state, PSVC_OK);
10867c478bd9Sstevel@tonic-gate 			strcpy(fault, PSVC_NO_FAULT);
10877c478bd9Sstevel@tonic-gate 		}
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, ps_id[i], PSVC_STATE_ATTR, state);
10907c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
10917c478bd9Sstevel@tonic-gate 			return (status);
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, ps_id[i], PSVC_FAULTID_ATTR,
10947c478bd9Sstevel@tonic-gate 		    fault);
10957c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
10967c478bd9Sstevel@tonic-gate 			return (status);
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, ps_id[i], PSVC_PREV_STATE_ATTR,
10997c478bd9Sstevel@tonic-gate 		    previous_state);
11007c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11017c478bd9Sstevel@tonic-gate 			return (status);
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 		if (strcmp(state, previous_state) != 0) {
11047c478bd9Sstevel@tonic-gate 			char dev_label[32];
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 			psvc_get_attr(hdlp, ps_id[i], PSVC_LABEL_ATTR,
11077c478bd9Sstevel@tonic-gate 			    dev_label);
11087c478bd9Sstevel@tonic-gate 
11097c478bd9Sstevel@tonic-gate 			if (strcmp(state, PSVC_ERROR) == 0) {
11107c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DEVICE_FAILURE_MSG, dev_label);
11117c478bd9Sstevel@tonic-gate 				for (j = 0; j < DAK_MAX_FAULT_SENSORS; ++j) {
11127c478bd9Sstevel@tonic-gate 					if (strcmp(bad_sensors[j],
11135eb92cf2Sdhain 					    EMPTY_STRING) != 0)
11147c478bd9Sstevel@tonic-gate 						syslog(LOG_ERR, "%s\n",
11157c478bd9Sstevel@tonic-gate 						    bad_sensors[j]);
11167c478bd9Sstevel@tonic-gate 				}
11177c478bd9Sstevel@tonic-gate 				strcpy(led_state, PSVC_LED_ON);
11187c478bd9Sstevel@tonic-gate 			} else {
11197c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DEVICE_OK_MSG, dev_label);
11207c478bd9Sstevel@tonic-gate 				strcpy(led_state, PSVC_LED_OFF);
11217c478bd9Sstevel@tonic-gate 			}
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, led_id,
11247c478bd9Sstevel@tonic-gate 			    PSVC_LED_STATE_ATTR, led_state);
11257c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
11267c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, SET_LED_FAILED_MSG, led_id,
11277c478bd9Sstevel@tonic-gate 				    errno);
11287c478bd9Sstevel@tonic-gate 				return (status);
11297c478bd9Sstevel@tonic-gate 			}
11307c478bd9Sstevel@tonic-gate 		}
11317c478bd9Sstevel@tonic-gate 	}
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
11347c478bd9Sstevel@tonic-gate }
11357c478bd9Sstevel@tonic-gate 
11367c478bd9Sstevel@tonic-gate int32_t
psvc_ps_check_and_disable_dr_policy_0(psvc_opaque_t hdlp,char * id)11377c478bd9Sstevel@tonic-gate psvc_ps_check_and_disable_dr_policy_0(psvc_opaque_t hdlp, char *id)
11387c478bd9Sstevel@tonic-gate {
11397c478bd9Sstevel@tonic-gate 	char		state[32];
1140360e6f5eSmathue 	static char	*name[DAKTARI_MAX_PS] = {NULL};
11417c478bd9Sstevel@tonic-gate 	int		ps_cnt = 0;
11427c478bd9Sstevel@tonic-gate 	int		i, j;
11437c478bd9Sstevel@tonic-gate 	int		dr_conf;
11447c478bd9Sstevel@tonic-gate 	int		fd, rv;
11457c478bd9Sstevel@tonic-gate 	boolean_t	present;
11467c478bd9Sstevel@tonic-gate 	char		dev_path[sizeof (HPC3130_DEV)+8];
11477c478bd9Sstevel@tonic-gate 	unsigned char	controller_names[HPC3130_CONTROLLERS] =
11487c478bd9Sstevel@tonic-gate 		{ 0xe2, 0xe6, 0xe8, 0xec };
11497c478bd9Sstevel@tonic-gate 
11507c478bd9Sstevel@tonic-gate 	if (name[0] == NULL) {
11517c478bd9Sstevel@tonic-gate 		for (i = 0; i < DAKTARI_MAX_PS; i++) {
11527c478bd9Sstevel@tonic-gate 			rv = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
11537c478bd9Sstevel@tonic-gate 			    &(name[i]), PSVC_PS, i);
11547c478bd9Sstevel@tonic-gate 			if (rv != PSVC_SUCCESS)
11557c478bd9Sstevel@tonic-gate 				return (rv);
11567c478bd9Sstevel@tonic-gate 		}
11577c478bd9Sstevel@tonic-gate 	}
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	/*
11607c478bd9Sstevel@tonic-gate 	 * Go through the power supplies to make sure they're present
11617c478bd9Sstevel@tonic-gate 	 * and OK.
11627c478bd9Sstevel@tonic-gate 	 */
11637c478bd9Sstevel@tonic-gate 	ps_cnt = DAKTARI_MAX_PS;
11647c478bd9Sstevel@tonic-gate 	for (i = 0; i < DAKTARI_MAX_PS; i++) {
11657c478bd9Sstevel@tonic-gate 		rv = psvc_get_attr(hdlp, name[i], PSVC_PRESENCE_ATTR,
11667c478bd9Sstevel@tonic-gate 		    &present);
11677c478bd9Sstevel@tonic-gate 		if (rv != PSVC_SUCCESS)
11687c478bd9Sstevel@tonic-gate 			return (rv);
11697c478bd9Sstevel@tonic-gate 
11707c478bd9Sstevel@tonic-gate 		if (present != PSVC_PRESENT) {
11717c478bd9Sstevel@tonic-gate 			ps_cnt--;
11727c478bd9Sstevel@tonic-gate 			continue;
11737c478bd9Sstevel@tonic-gate 		} else {
11747c478bd9Sstevel@tonic-gate 			rv = psvc_get_attr(hdlp, name[i], PSVC_STATE_ATTR,
11755eb92cf2Sdhain 			    state);
11767c478bd9Sstevel@tonic-gate 			if (rv != PSVC_SUCCESS)
11777c478bd9Sstevel@tonic-gate 				return (rv);
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 			if (strcmp(state, PSVC_OK))
11807c478bd9Sstevel@tonic-gate 				ps_cnt--;
11817c478bd9Sstevel@tonic-gate 		}
11827c478bd9Sstevel@tonic-gate 	}
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	/*
11857c478bd9Sstevel@tonic-gate 	 * No change in DR configuration is needed if the new power supply
11867c478bd9Sstevel@tonic-gate 	 * count equals the current count.
11877c478bd9Sstevel@tonic-gate 	 */
11887c478bd9Sstevel@tonic-gate 	if (ps_cnt == co_ps)
11897c478bd9Sstevel@tonic-gate 		return (PSVC_SUCCESS);
11907c478bd9Sstevel@tonic-gate 
11917c478bd9Sstevel@tonic-gate 	/*
11927c478bd9Sstevel@tonic-gate 	 * Disable DR when hotplugged down to 1 power supply; enable DR when
11937c478bd9Sstevel@tonic-gate 	 * hotplugged up from 1 supply.
11947c478bd9Sstevel@tonic-gate 	 */
11957c478bd9Sstevel@tonic-gate 	assert(ps_cnt);
11967c478bd9Sstevel@tonic-gate 	if ((co_ps == 0 || co_ps > 1) && ps_cnt != 1) {
11977c478bd9Sstevel@tonic-gate 		co_ps = ps_cnt;
11987c478bd9Sstevel@tonic-gate 		return (PSVC_SUCCESS);
11997c478bd9Sstevel@tonic-gate 	}
12007c478bd9Sstevel@tonic-gate 	dr_conf = (ps_cnt == 1 ? HPC3130_DR_DISABLE : HPC3130_DR_ENABLE);
12017c478bd9Sstevel@tonic-gate 	co_ps = ps_cnt;
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate 	for (i = 0; i < HPC3130_CONTROLLERS; i++) {
12047c478bd9Sstevel@tonic-gate 		for (j = 0; j < HPC3130_SLOTS; j++) {
12057c478bd9Sstevel@tonic-gate 			(void) snprintf(dev_path, sizeof (dev_path),
12067c478bd9Sstevel@tonic-gate 			    HPC3130_DEV, controller_names[i], j);
12077c478bd9Sstevel@tonic-gate 			fd = open(dev_path, O_RDWR);
12087c478bd9Sstevel@tonic-gate 			if (fd == -1)
12097c478bd9Sstevel@tonic-gate 				return (PSVC_FAILURE);
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate 			rv = ioctl(fd, HPC3130_CONF_DR, &dr_conf);
12127c478bd9Sstevel@tonic-gate 			close(fd);
12137c478bd9Sstevel@tonic-gate 			if (rv == -1)
12147c478bd9Sstevel@tonic-gate 				return (PSVC_FAILURE);
12157c478bd9Sstevel@tonic-gate 		}
12167c478bd9Sstevel@tonic-gate 	}
12177c478bd9Sstevel@tonic-gate 
12187c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate 
12217c478bd9Sstevel@tonic-gate int32_t
psvc_fan_blast_shutoff_policy_0(psvc_opaque_t hdlp,char * id)12227c478bd9Sstevel@tonic-gate psvc_fan_blast_shutoff_policy_0(psvc_opaque_t hdlp, char *id)
12237c478bd9Sstevel@tonic-gate {
12247c478bd9Sstevel@tonic-gate 	char		switch_status[32];
12257c478bd9Sstevel@tonic-gate 	int32_t		status = PSVC_SUCCESS;
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_SWITCH_STATE_ATTR, switch_status);
12287c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
12297c478bd9Sstevel@tonic-gate 		return (status);
12307c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_SWITCH_STATE_ATTR,
12315eb92cf2Sdhain 	    PSVC_SWITCH_OFF);
12327c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
12337c478bd9Sstevel@tonic-gate 		return (status);
12347c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_SWITCH_STATE_ATTR,
12355eb92cf2Sdhain 	    PSVC_SWITCH_ON);
12367c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
12377c478bd9Sstevel@tonic-gate 		return (status);
12387c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_SWITCH_STATE_ATTR,
12395eb92cf2Sdhain 	    PSVC_SWITCH_OFF);
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	return (status);
12427c478bd9Sstevel@tonic-gate }
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate int32_t
psvc_fan_fault_check_policy_0(psvc_opaque_t hdlp,char * system)12457c478bd9Sstevel@tonic-gate psvc_fan_fault_check_policy_0(psvc_opaque_t hdlp, char *system)
12467c478bd9Sstevel@tonic-gate {
1247360e6f5eSmathue 	static char *fan_id[DAK_MAX_FANS] = {NULL};
12487c478bd9Sstevel@tonic-gate 	boolean_t enabled;
12497c478bd9Sstevel@tonic-gate 	int32_t speed;
12507c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
12517c478bd9Sstevel@tonic-gate 	int r;
1252298b7f4cSjfrank 	static int threshold_counter = 0;
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate 	if (fan_id[0] == NULL) {
12557c478bd9Sstevel@tonic-gate 		for (r = 0; r < DAK_MAX_FANS; r++) {
12567c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, system,
12577c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &(fan_id[r]), PSVC_FAN, r);
12587c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
12597c478bd9Sstevel@tonic-gate 				return (status);
12607c478bd9Sstevel@tonic-gate 		}
12617c478bd9Sstevel@tonic-gate 	}
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 	for (r = 0; r < DAK_MAX_FANS; r++) {
12647c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, fan_id[r], PSVC_ENABLE_ATTR,
12657c478bd9Sstevel@tonic-gate 		    &enabled);
12667c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
12677c478bd9Sstevel@tonic-gate 			return (status);
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate 		if (enabled == PSVC_ENABLED) {
12707c478bd9Sstevel@tonic-gate 			uint64_t features;
12717c478bd9Sstevel@tonic-gate 			char *switch_id;
12727c478bd9Sstevel@tonic-gate 			char switch_state[32], fan_state[32];
12737c478bd9Sstevel@tonic-gate 			int fan_count, fans;
12747c478bd9Sstevel@tonic-gate 			char *other_fan_id;
12757c478bd9Sstevel@tonic-gate 			char fstate[32], ffault[32];
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@tonic-gate 			/*
12787c478bd9Sstevel@tonic-gate 			 * If any other fan on the fan tray has an ERROR state,
12797c478bd9Sstevel@tonic-gate 			 * mark this fan bad and return
12807c478bd9Sstevel@tonic-gate 			 */
12817c478bd9Sstevel@tonic-gate 			psvc_get_attr(hdlp, fan_id[r], PSVC_ASSOC_MATCHES_ATTR,
12827c478bd9Sstevel@tonic-gate 			    &fan_count, PSVC_FAN_TRAY_FANS);
12837c478bd9Sstevel@tonic-gate 			for (fans = 0; fans < fan_count; ++fans) {
12847c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, fan_id[r],
12857c478bd9Sstevel@tonic-gate 				    PSVC_ASSOC_ID_ATTR, &other_fan_id,
12867c478bd9Sstevel@tonic-gate 				    PSVC_FAN_TRAY_FANS, fans);
12877c478bd9Sstevel@tonic-gate 				if (status == PSVC_FAILURE)
12887c478bd9Sstevel@tonic-gate 					return (status);
12897c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, other_fan_id,
12907c478bd9Sstevel@tonic-gate 				    PSVC_STATE_ATTR, fan_state);
12917c478bd9Sstevel@tonic-gate 				if (status != PSVC_SUCCESS)
12927c478bd9Sstevel@tonic-gate 					return (status);
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate 				if (strcmp(fan_state, PSVC_ERROR) == 0) {
12957c478bd9Sstevel@tonic-gate 					strlcpy(ffault, PSVC_GEN_FAULT,
12967c478bd9Sstevel@tonic-gate 					    sizeof (ffault));
12977c478bd9Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, fan_id[r],
12987c478bd9Sstevel@tonic-gate 					    PSVC_FAULTID_ATTR, ffault);
12997c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS)
13007c478bd9Sstevel@tonic-gate 						return (status);
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 					strlcpy(fstate, PSVC_ERROR,
13037c478bd9Sstevel@tonic-gate 					    sizeof (fstate));
13047c478bd9Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, fan_id[r],
13057c478bd9Sstevel@tonic-gate 					    PSVC_STATE_ATTR, fstate);
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 					return (status);
13087c478bd9Sstevel@tonic-gate 				}
13097c478bd9Sstevel@tonic-gate 			}
13107c478bd9Sstevel@tonic-gate 
13117c478bd9Sstevel@tonic-gate 			/*
13127c478bd9Sstevel@tonic-gate 			 * Select tachometer for IO or CPU primary/secondary
13137c478bd9Sstevel@tonic-gate 			 * fans.
13147c478bd9Sstevel@tonic-gate 			 */
13157c478bd9Sstevel@tonic-gate 			pthread_mutex_lock(&fan_mutex);
13167c478bd9Sstevel@tonic-gate 
13177c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fan_id[r],
13187c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &switch_id,
13197c478bd9Sstevel@tonic-gate 			    PSVC_FAN_PRIM_SEC_SELECTOR, 0);
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 			if (status != PSVC_FAILURE) {
13227c478bd9Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, fan_id[r],
13237c478bd9Sstevel@tonic-gate 				    PSVC_FEATURES_ATTR,	&features);
13247c478bd9Sstevel@tonic-gate 				if (status == PSVC_FAILURE) {
13257c478bd9Sstevel@tonic-gate 					pthread_mutex_unlock(&fan_mutex);
13267c478bd9Sstevel@tonic-gate 					return (status);
13277c478bd9Sstevel@tonic-gate 				}
13287c478bd9Sstevel@tonic-gate 
13297c478bd9Sstevel@tonic-gate 				if (features & PSVC_DEV_PRIMARY)
13307c478bd9Sstevel@tonic-gate 					strlcpy(switch_state, PSVC_SWITCH_ON,
13317c478bd9Sstevel@tonic-gate 					    sizeof (switch_state));
13327c478bd9Sstevel@tonic-gate 				else
13337c478bd9Sstevel@tonic-gate 					strlcpy(switch_state, PSVC_SWITCH_OFF,
13347c478bd9Sstevel@tonic-gate 					    sizeof (switch_state));
13357c478bd9Sstevel@tonic-gate 				status = psvc_set_attr(hdlp, switch_id,
13367c478bd9Sstevel@tonic-gate 				    PSVC_SWITCH_STATE_ATTR, switch_state);
13377c478bd9Sstevel@tonic-gate 				if (status == PSVC_FAILURE) {
13387c478bd9Sstevel@tonic-gate 					pthread_mutex_unlock(&fan_mutex);
13397c478bd9Sstevel@tonic-gate 					return (status);
13407c478bd9Sstevel@tonic-gate 				}
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 				/* allow time for speed to be determined */
13437c478bd9Sstevel@tonic-gate 				(void) poll(NULL, 0, 250);
13447c478bd9Sstevel@tonic-gate 			}
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fan_id[r],
13477c478bd9Sstevel@tonic-gate 			    PSVC_SENSOR_VALUE_ATTR, &speed);
13487c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
13497c478bd9Sstevel@tonic-gate 				pthread_mutex_unlock(&fan_mutex);
13507c478bd9Sstevel@tonic-gate 				return (status);
13517c478bd9Sstevel@tonic-gate 			}
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate 			pthread_mutex_unlock(&fan_mutex);
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 			if (speed == 0) {
13567c478bd9Sstevel@tonic-gate 				threshold_counter++;
13577c478bd9Sstevel@tonic-gate 				if (threshold_counter ==
1358298b7f4cSjfrank 				    n_read_fanfault) {
13597c478bd9Sstevel@tonic-gate 					int32_t i;
13607c478bd9Sstevel@tonic-gate 					int32_t led_count;
13617c478bd9Sstevel@tonic-gate 					char led_state[32];
13627c478bd9Sstevel@tonic-gate 					char *led_id;
13637c478bd9Sstevel@tonic-gate 					char *slot_id;
13647c478bd9Sstevel@tonic-gate 					char label[32];
13657c478bd9Sstevel@tonic-gate 					char state[32], fault[32];
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate 					threshold_counter = 0;
13687c478bd9Sstevel@tonic-gate 					strlcpy(fault, PSVC_GEN_FAULT,
13697c478bd9Sstevel@tonic-gate 					    sizeof (fault));
13707c478bd9Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, fan_id[r],
13717c478bd9Sstevel@tonic-gate 					    PSVC_FAULTID_ATTR, fault);
13727c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS)
13737c478bd9Sstevel@tonic-gate 						return (status);
13747c478bd9Sstevel@tonic-gate 
13757c478bd9Sstevel@tonic-gate 					strlcpy(state, PSVC_ERROR,
13767c478bd9Sstevel@tonic-gate 					    sizeof (state));
13777c478bd9Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, fan_id[r],
13787c478bd9Sstevel@tonic-gate 					    PSVC_STATE_ATTR, state);
13797c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS)
13807c478bd9Sstevel@tonic-gate 						return (status);
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate 					status = psvc_get_attr(hdlp, fan_id[r],
13837c478bd9Sstevel@tonic-gate 					    PSVC_LABEL_ATTR, label);
13847c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS)
13857c478bd9Sstevel@tonic-gate 						return (status);
13867c478bd9Sstevel@tonic-gate 
13877c478bd9Sstevel@tonic-gate 					syslog(LOG_ERR, DEVICE_FAILURE_MSG,
13887c478bd9Sstevel@tonic-gate 					    label);
13897c478bd9Sstevel@tonic-gate 
13907c478bd9Sstevel@tonic-gate 					/* turn on fault LEDs */
13917c478bd9Sstevel@tonic-gate 					psvc_get_attr(hdlp, fan_id[r],
13927c478bd9Sstevel@tonic-gate 					    PSVC_ASSOC_MATCHES_ATTR, &led_count,
13937c478bd9Sstevel@tonic-gate 					    PSVC_DEV_FAULT_LED);
13947c478bd9Sstevel@tonic-gate 					strlcpy(led_state, PSVC_LED_ON,
13957c478bd9Sstevel@tonic-gate 					    sizeof (led_state));
13967c478bd9Sstevel@tonic-gate 					for (i = 0; i < led_count; ++i) {
13977c478bd9Sstevel@tonic-gate 						status = psvc_get_attr(hdlp,
13987c478bd9Sstevel@tonic-gate 						    fan_id[r],
13997c478bd9Sstevel@tonic-gate 						    PSVC_ASSOC_ID_ATTR, &led_id,
14007c478bd9Sstevel@tonic-gate 						    PSVC_DEV_FAULT_LED, i);
14017c478bd9Sstevel@tonic-gate 						if (status == PSVC_FAILURE)
14027c478bd9Sstevel@tonic-gate 							return (status);
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 						status = psvc_set_attr(hdlp,
14057c478bd9Sstevel@tonic-gate 						    led_id, PSVC_LED_STATE_ATTR,
14067c478bd9Sstevel@tonic-gate 						    led_state);
14077c478bd9Sstevel@tonic-gate 						if (status == PSVC_FAILURE)
14087c478bd9Sstevel@tonic-gate 							return (status);
14097c478bd9Sstevel@tonic-gate 					}
14107c478bd9Sstevel@tonic-gate 
14117c478bd9Sstevel@tonic-gate 					/* turn on OK to remove LEDs */
14127c478bd9Sstevel@tonic-gate 
14137c478bd9Sstevel@tonic-gate 					status = psvc_get_attr(hdlp, fan_id[r],
14147c478bd9Sstevel@tonic-gate 					    PSVC_ASSOC_ID_ATTR, &slot_id,
14157c478bd9Sstevel@tonic-gate 					    PSVC_PARENT, 0);
14167c478bd9Sstevel@tonic-gate 					if (status != PSVC_SUCCESS)
14177c478bd9Sstevel@tonic-gate 						return (status);
14187c478bd9Sstevel@tonic-gate 
14197c478bd9Sstevel@tonic-gate 					psvc_get_attr(hdlp, slot_id,
14207c478bd9Sstevel@tonic-gate 					    PSVC_ASSOC_MATCHES_ATTR, &led_count,
14217c478bd9Sstevel@tonic-gate 					    PSVC_SLOT_REMOVE_LED);
14227c478bd9Sstevel@tonic-gate 					strlcpy(led_state, PSVC_LED_ON,
14237c478bd9Sstevel@tonic-gate 					    sizeof (led_state));
14247c478bd9Sstevel@tonic-gate 					for (i = 0; i < led_count; ++i) {
14257c478bd9Sstevel@tonic-gate 						status = psvc_get_attr(hdlp,
14267c478bd9Sstevel@tonic-gate 						    slot_id,
14277c478bd9Sstevel@tonic-gate 						    PSVC_ASSOC_ID_ATTR, &led_id,
14287c478bd9Sstevel@tonic-gate 						    PSVC_SLOT_REMOVE_LED, i);
14297c478bd9Sstevel@tonic-gate 						if (status == PSVC_FAILURE)
14307c478bd9Sstevel@tonic-gate 							return (status);
14317c478bd9Sstevel@tonic-gate 
14327c478bd9Sstevel@tonic-gate 						status = psvc_set_attr(hdlp,
14337c478bd9Sstevel@tonic-gate 						    led_id, PSVC_LED_STATE_ATTR,
14347c478bd9Sstevel@tonic-gate 						    led_state);
14357c478bd9Sstevel@tonic-gate 						if (status == PSVC_FAILURE)
14367c478bd9Sstevel@tonic-gate 							return (status);
14377c478bd9Sstevel@tonic-gate 					}
14387c478bd9Sstevel@tonic-gate 				}
14397c478bd9Sstevel@tonic-gate 			}
14407c478bd9Sstevel@tonic-gate 		}
14417c478bd9Sstevel@tonic-gate 	}
14427c478bd9Sstevel@tonic-gate 
14437c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
14447c478bd9Sstevel@tonic-gate }
14457c478bd9Sstevel@tonic-gate 
14467c478bd9Sstevel@tonic-gate /*
14477c478bd9Sstevel@tonic-gate  * This routine takes in the PSVC handle pointer, the PS name, and the
14487c478bd9Sstevel@tonic-gate  * instance number (0, 1, or 2). It simply make a psvc_get call to get the
14497c478bd9Sstevel@tonic-gate  * presence of each of the children under the PS. This call will set the
14507c478bd9Sstevel@tonic-gate  * presence state of the child device if it was not there when the system
14517c478bd9Sstevel@tonic-gate  * was booted.
14527c478bd9Sstevel@tonic-gate  */
14537c478bd9Sstevel@tonic-gate static int
handle_ps_hotplug_children_presence(psvc_opaque_t hdlp,char * id)14547c478bd9Sstevel@tonic-gate handle_ps_hotplug_children_presence(psvc_opaque_t hdlp, char *id)
14557c478bd9Sstevel@tonic-gate {
14567c478bd9Sstevel@tonic-gate 	char *sensor_id;
14577c478bd9Sstevel@tonic-gate 	char fail_valid_switch_id[PICL_PROPNAMELEN_MAX];
14587c478bd9Sstevel@tonic-gate 	int32_t	status = PSVC_SUCCESS;
14597c478bd9Sstevel@tonic-gate 	boolean_t presence;
14607c478bd9Sstevel@tonic-gate 	int j;
14617c478bd9Sstevel@tonic-gate 
14627c478bd9Sstevel@tonic-gate 	/* Get the Sensor Valid Switch presence */
14637c478bd9Sstevel@tonic-gate 	snprintf(fail_valid_switch_id, sizeof (fail_valid_switch_id), "%s%s",
14647c478bd9Sstevel@tonic-gate 	    id, "_SENSOR_VALID_SWITCH");
14657c478bd9Sstevel@tonic-gate 
14667c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, fail_valid_switch_id, PSVC_PRESENCE_ATTR,
14677c478bd9Sstevel@tonic-gate 	    &presence);
14687c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
14697c478bd9Sstevel@tonic-gate 		return (status);
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate 	/* Go through each PS's fault sensors */
14727c478bd9Sstevel@tonic-gate 	for (j = 0; j < DAK_MAX_FAULT_SENSORS; j++) {
14737c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
14747c478bd9Sstevel@tonic-gate 		    &(sensor_id), PSVC_DEV_FAULT_SENSOR, j);
14757c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
14767c478bd9Sstevel@tonic-gate 			return (status);
14777c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id, PSVC_PRESENCE_ATTR,
14787c478bd9Sstevel@tonic-gate 		    &presence);
14797c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
14807c478bd9Sstevel@tonic-gate 			return (status);
14817c478bd9Sstevel@tonic-gate 	}
14827c478bd9Sstevel@tonic-gate 
14837c478bd9Sstevel@tonic-gate 	/* Go through each PS's current sensors */
14847c478bd9Sstevel@tonic-gate 	for (j = 0; j < DAK_MAX_PS_I_SENSORS; ++j) {
14857c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
14867c478bd9Sstevel@tonic-gate 		    &(sensor_id), PSVC_PS_I_SENSOR, j);
14877c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
14887c478bd9Sstevel@tonic-gate 			return (status);
14897c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id, PSVC_PRESENCE_ATTR,
14907c478bd9Sstevel@tonic-gate 		    &presence);
14917c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
14927c478bd9Sstevel@tonic-gate 			return (status);
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate 	}
14957c478bd9Sstevel@tonic-gate 
14967c478bd9Sstevel@tonic-gate 	/* Go through each PS's onboard i2c hardware */
14977c478bd9Sstevel@tonic-gate 	for (j = 0; j < 3; j++) {
14987c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
14997c478bd9Sstevel@tonic-gate 		    &(sensor_id), PSVC_PHYSICAL_DEVICE, j);
15007c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
15017c478bd9Sstevel@tonic-gate 			return (status);
15027c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id, PSVC_PRESENCE_ATTR,
15037c478bd9Sstevel@tonic-gate 		    &presence);
15047c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
15057c478bd9Sstevel@tonic-gate 			return (status);
15067c478bd9Sstevel@tonic-gate 	}
15077c478bd9Sstevel@tonic-gate 
15087c478bd9Sstevel@tonic-gate 	return (status);
15097c478bd9Sstevel@tonic-gate }
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate static i2c_hp_t devices[3][3] = {
15127c478bd9Sstevel@tonic-gate {{{0, 0x90}, "adio", "i2c-pcf8591"}, {{0, 0x70}, "ioexp", "i2c-pcf8574"},
15137c478bd9Sstevel@tonic-gate 	{{0, 0xa0}, "fru", "i2c-at24c64"}},
15147c478bd9Sstevel@tonic-gate {{{0, 0x92}, "adio", "i2c-pcf8591"}, {{0, 0x72}, "ioexp", "i2c-pcf8574"},
15157c478bd9Sstevel@tonic-gate 	{{0, 0xa2}, "fru", "i2c-at24c64"}},
15167c478bd9Sstevel@tonic-gate {{{0, 0x94}, "adio", "i2c-pcf8591"}, {{0, 0x74}, "ioexp", "i2c-pcf8574"},
15177c478bd9Sstevel@tonic-gate 	{{0, 0xa4}, "fru", "i2c-at24c64"}},
15187c478bd9Sstevel@tonic-gate };
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate int32_t
psvc_ps_hotplug_policy_0(psvc_opaque_t hdlp,char * id)15217c478bd9Sstevel@tonic-gate psvc_ps_hotplug_policy_0(psvc_opaque_t hdlp, char *id)
15227c478bd9Sstevel@tonic-gate {
15237c478bd9Sstevel@tonic-gate 	boolean_t presence, previous_presence;
15247c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
15257c478bd9Sstevel@tonic-gate 	char label[32], state[32], fault[32];
15267c478bd9Sstevel@tonic-gate 	int32_t ps_instance, led_count;
15277c478bd9Sstevel@tonic-gate 	char *switch_id, *led_id;
15287c478bd9Sstevel@tonic-gate 	int i;
15297c478bd9Sstevel@tonic-gate 	picl_nodehdl_t parent_node;
15307c478bd9Sstevel@tonic-gate 	char parent_path[256], ps_path[256];
15317c478bd9Sstevel@tonic-gate 	picl_nodehdl_t child_node;
15327c478bd9Sstevel@tonic-gate 	devctl_hdl_t bus_handle, dev_handle;
15337c478bd9Sstevel@tonic-gate 	devctl_ddef_t ddef_hdl;
15347c478bd9Sstevel@tonic-gate 	char pcf8574_devpath[256], pcf8591_devpath[256], fru_devpath[256];
1535298b7f4cSjfrank 	int retry;
15367c478bd9Sstevel@tonic-gate 
15377c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR,
15385eb92cf2Sdhain 	    &previous_presence);
15397c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
15407c478bd9Sstevel@tonic-gate 		return (status);
15417c478bd9Sstevel@tonic-gate 
15427c478bd9Sstevel@tonic-gate 	retry = 0;
15437c478bd9Sstevel@tonic-gate 	do {
15447c478bd9Sstevel@tonic-gate 		if (retry)
1545298b7f4cSjfrank 			(void) sleep(retry_sleep_pshp);
15467c478bd9Sstevel@tonic-gate 
15477c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &presence);
15487c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
15497c478bd9Sstevel@tonic-gate 			return (status);
15507c478bd9Sstevel@tonic-gate 		retry++;
1551298b7f4cSjfrank 	} while ((retry < n_retry_pshp) &&
15527c478bd9Sstevel@tonic-gate 	    (presence != previous_presence));
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate 	if (presence == previous_presence) {
15557c478bd9Sstevel@tonic-gate 		/* No change */
15567c478bd9Sstevel@tonic-gate 		return (status);
15577c478bd9Sstevel@tonic-gate 	}
15587c478bd9Sstevel@tonic-gate 
15597c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, label);
15607c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
15617c478bd9Sstevel@tonic-gate 		return (status);
15627c478bd9Sstevel@tonic-gate 
15637c478bd9Sstevel@tonic-gate 	/* convert name to node, and parent path */
15647c478bd9Sstevel@tonic-gate 	psvcplugin_lookup(id, parent_path, &child_node);
15657c478bd9Sstevel@tonic-gate 
15667c478bd9Sstevel@tonic-gate 	if (presence == PSVC_PRESENT) {
15677c478bd9Sstevel@tonic-gate 		/*
15687c478bd9Sstevel@tonic-gate 		 * Run this code if Power Supply was just added into the
15697c478bd9Sstevel@tonic-gate 		 * System.  This code toggles hotplug switch and adds the
15707c478bd9Sstevel@tonic-gate 		 * PS and it's children to the picl tree. We then goto adding
15717c478bd9Sstevel@tonic-gate 		 * device drivers at bottom of the routine.
15727c478bd9Sstevel@tonic-gate 		 */
15737c478bd9Sstevel@tonic-gate 		int32_t switch_count;
15747c478bd9Sstevel@tonic-gate 		char state[32], fault[32];
15757c478bd9Sstevel@tonic-gate 		char switch_state[32];
15767c478bd9Sstevel@tonic-gate 
15777c478bd9Sstevel@tonic-gate 		/* may detect presence before all connections are made */
15787c478bd9Sstevel@tonic-gate 		(void) poll(NULL, 0, 500);
15797c478bd9Sstevel@tonic-gate 
15807c478bd9Sstevel@tonic-gate 		/* Device added */
15817c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, DEVICE_INSERTED_MSG, label);
15827c478bd9Sstevel@tonic-gate 
15837c478bd9Sstevel@tonic-gate 		strcpy(state, PSVC_OK);
15847c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
15857c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
15867c478bd9Sstevel@tonic-gate 			return (status);
15877c478bd9Sstevel@tonic-gate 
15887c478bd9Sstevel@tonic-gate 		strcpy(fault, PSVC_NO_FAULT);
15897c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR, fault);
15907c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
15917c478bd9Sstevel@tonic-gate 			return (status);
15927c478bd9Sstevel@tonic-gate 
15937c478bd9Sstevel@tonic-gate 		/* Enable i2c bus */
15947c478bd9Sstevel@tonic-gate 		psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR,
15955eb92cf2Sdhain 		    &switch_count, PSVC_HOTPLUG_ENABLE_SWITCH);
15967c478bd9Sstevel@tonic-gate 		for (i = 0; i < switch_count; ++i) {
15977c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
15985eb92cf2Sdhain 			    &switch_id, PSVC_HOTPLUG_ENABLE_SWITCH, i);
15997c478bd9Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
16007c478bd9Sstevel@tonic-gate 				return (status);
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate 			strcpy(switch_state, PSVC_SWITCH_OFF);
16037c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, switch_id,
16045eb92cf2Sdhain 			    PSVC_SWITCH_STATE_ATTR, switch_state);
16057c478bd9Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
16067c478bd9Sstevel@tonic-gate 				return (status);
16077c478bd9Sstevel@tonic-gate 
16087c478bd9Sstevel@tonic-gate 			strcpy(switch_state, PSVC_SWITCH_ON);
16097c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, switch_id,
16105eb92cf2Sdhain 			    PSVC_SWITCH_STATE_ATTR, switch_state);
16117c478bd9Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
16127c478bd9Sstevel@tonic-gate 				return (status);
16137c478bd9Sstevel@tonic-gate 		}
16147c478bd9Sstevel@tonic-gate 		ptree_get_node_by_path(parent_path, &parent_node);
16157c478bd9Sstevel@tonic-gate 		ptree_add_node(parent_node, child_node);
16167c478bd9Sstevel@tonic-gate 		snprintf(ps_path, sizeof (ps_path), "%s/%s", parent_path, id);
16177c478bd9Sstevel@tonic-gate 		psvcplugin_add_children(ps_path);
16187c478bd9Sstevel@tonic-gate 	} else {
16197c478bd9Sstevel@tonic-gate 		/*
16207c478bd9Sstevel@tonic-gate 		 * Run this code if PS was just removed from the system. We
16217c478bd9Sstevel@tonic-gate 		 * delete the device from the picl tree and then shut off
16227c478bd9Sstevel@tonic-gate 		 * all fault lights associated with the PS.  We also set the
16237c478bd9Sstevel@tonic-gate 		 * device state to PSVC_REMOVED so that if we hit overcurrent
16247c478bd9Sstevel@tonic-gate 		 * or fault checking code we can do a psvc call to see that
16257c478bd9Sstevel@tonic-gate 		 * the device has not offically been added into the system.
16267c478bd9Sstevel@tonic-gate 		 * We then will drop to code lower in the routine to remove
16277c478bd9Sstevel@tonic-gate 		 * the device drivers for this PS.
16287c478bd9Sstevel@tonic-gate 		 */
16297c478bd9Sstevel@tonic-gate 
16307c478bd9Sstevel@tonic-gate 		/* Device removed */
16317c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, DEVICE_REMOVED_MSG, label);
16327c478bd9Sstevel@tonic-gate 		ptree_delete_node(child_node);
16337c478bd9Sstevel@tonic-gate 		psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &led_count,
16345eb92cf2Sdhain 		    PSVC_DEV_FAULT_LED);
16357c478bd9Sstevel@tonic-gate 
16367c478bd9Sstevel@tonic-gate 		for (i = 0; i < led_count; i++) {
16377c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
16385eb92cf2Sdhain 			    &led_id, PSVC_DEV_FAULT_LED, i);
16397c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
16407c478bd9Sstevel@tonic-gate 				return (status);
16417c478bd9Sstevel@tonic-gate 			}
16427c478bd9Sstevel@tonic-gate 
16437c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, led_id,
16447c478bd9Sstevel@tonic-gate 			    PSVC_LED_STATE_ATTR, PSVC_OFF);
16457c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
16467c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, SET_LED_FAILED_MSG, led_id,
16475eb92cf2Sdhain 				    errno);
16487c478bd9Sstevel@tonic-gate 				return (status);
16497c478bd9Sstevel@tonic-gate 			}
16507c478bd9Sstevel@tonic-gate 
16517c478bd9Sstevel@tonic-gate 		}
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate 		strcpy(state, PSVC_OK);
16547c478bd9Sstevel@tonic-gate 		strcpy(fault, PSVC_NO_FAULT);
16557c478bd9Sstevel@tonic-gate 
16567c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
16577c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
16587c478bd9Sstevel@tonic-gate 			return (status);
16597c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR, fault);
16607c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
16617c478bd9Sstevel@tonic-gate 			return (status);
16627c478bd9Sstevel@tonic-gate 	}
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR, &presence);
16657c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
16667c478bd9Sstevel@tonic-gate 		return (status);
16677c478bd9Sstevel@tonic-gate 
16687c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_INSTANCE_ATTR, &ps_instance);
16697c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
16707c478bd9Sstevel@tonic-gate 		return (status);
16717c478bd9Sstevel@tonic-gate 
16727c478bd9Sstevel@tonic-gate 	if (presence != PSVC_PRESENT) {
16737c478bd9Sstevel@tonic-gate 		/*
16747c478bd9Sstevel@tonic-gate 		 * This is the additional code needed to remove the PS from
16757c478bd9Sstevel@tonic-gate 		 * the system.  It removes the device drivers from the
16767c478bd9Sstevel@tonic-gate 		 * device tree.
16777c478bd9Sstevel@tonic-gate 		 */
16787c478bd9Sstevel@tonic-gate 		snprintf(pcf8574_devpath, sizeof (pcf8574_devpath), PCF8574,
16795eb92cf2Sdhain 		    devices[ps_instance][1].addr[1]);
16807c478bd9Sstevel@tonic-gate 		snprintf(pcf8591_devpath, sizeof (pcf8591_devpath), PCF8591,
16815eb92cf2Sdhain 		    devices[ps_instance][0].addr[1]);
16827c478bd9Sstevel@tonic-gate 		snprintf(fru_devpath, sizeof (fru_devpath), FRU,
16835eb92cf2Sdhain 		    devices[ps_instance][2].addr[1]);
16847c478bd9Sstevel@tonic-gate 
16857c478bd9Sstevel@tonic-gate 		dev_handle = devctl_device_acquire(pcf8591_devpath, 0);
16867c478bd9Sstevel@tonic-gate 		if (dev_handle == NULL) {
16877c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
16885eb92cf2Sdhain 			    pcf8591_devpath, errno);
16897c478bd9Sstevel@tonic-gate 			devctl_release(dev_handle);
16907c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
16917c478bd9Sstevel@tonic-gate 		} else if ((devctl_device_remove(dev_handle)) &&
16925eb92cf2Sdhain 		    (errno != ENXIO)) {
16937c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DEVTREE_NODE_DELETE_FAILED,
16945eb92cf2Sdhain 				    pcf8591_devpath, errno);
16957c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
16967c478bd9Sstevel@tonic-gate 				return (PSVC_FAILURE);
16977c478bd9Sstevel@tonic-gate 			} else {
16987c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
16997c478bd9Sstevel@tonic-gate 				status = PSVC_SUCCESS;
17007c478bd9Sstevel@tonic-gate 			}
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 		dev_handle = devctl_device_acquire(pcf8574_devpath, 0);
17037c478bd9Sstevel@tonic-gate 		if (dev_handle == NULL) {
17047c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
17055eb92cf2Sdhain 			    pcf8574_devpath, errno);
17067c478bd9Sstevel@tonic-gate 			devctl_release(dev_handle);
17077c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17087c478bd9Sstevel@tonic-gate 		} else if ((devctl_device_remove(dev_handle)) &&
17095eb92cf2Sdhain 		    (errno != ENXIO)) {
17107c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DEVTREE_NODE_DELETE_FAILED,
17115eb92cf2Sdhain 				    pcf8574_devpath, errno);
17127c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
17137c478bd9Sstevel@tonic-gate 				return (PSVC_FAILURE);
17147c478bd9Sstevel@tonic-gate 			} else {
17157c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
17167c478bd9Sstevel@tonic-gate 				status = PSVC_SUCCESS;
17177c478bd9Sstevel@tonic-gate 			}
17187c478bd9Sstevel@tonic-gate 
17197c478bd9Sstevel@tonic-gate 		dev_handle = devctl_device_acquire(fru_devpath, 0);
17207c478bd9Sstevel@tonic-gate 		if (dev_handle == NULL) {
17217c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
17225eb92cf2Sdhain 			    fru_devpath, errno);
17237c478bd9Sstevel@tonic-gate 			devctl_release(dev_handle);
17247c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17257c478bd9Sstevel@tonic-gate 		} else if ((devctl_device_remove(dev_handle)) &&
17265eb92cf2Sdhain 		    (errno != ENXIO)) {
17277c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DEVTREE_NODE_DELETE_FAILED,
17285eb92cf2Sdhain 				    fru_devpath, errno);
17297c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
17307c478bd9Sstevel@tonic-gate 				return (PSVC_FAILURE);
17317c478bd9Sstevel@tonic-gate 			} else {
17327c478bd9Sstevel@tonic-gate 				devctl_release(dev_handle);
17337c478bd9Sstevel@tonic-gate 				status = PSVC_SUCCESS;
17347c478bd9Sstevel@tonic-gate 			}
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate 		return (status);
17377c478bd9Sstevel@tonic-gate 	}
17387c478bd9Sstevel@tonic-gate 
17397c478bd9Sstevel@tonic-gate 	/*
17407c478bd9Sstevel@tonic-gate 	 * This code is to update the presences of power supply child
17417c478bd9Sstevel@tonic-gate 	 * devices in the event that picld was started without a power
17427c478bd9Sstevel@tonic-gate 	 * supply present.  This call makes the devices available
17437c478bd9Sstevel@tonic-gate 	 * after that initial insertion.
17447c478bd9Sstevel@tonic-gate 	 */
17457c478bd9Sstevel@tonic-gate 	status = handle_ps_hotplug_children_presence(hdlp, id);
17467c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
17477c478bd9Sstevel@tonic-gate 		return (status);
17487c478bd9Sstevel@tonic-gate 	}
17497c478bd9Sstevel@tonic-gate 
17507c478bd9Sstevel@tonic-gate 	/*
17517c478bd9Sstevel@tonic-gate 	 * We fall through to here if the device has been inserted.
17527c478bd9Sstevel@tonic-gate 	 * Add the devinfo tree node entry for the seeprom and attach
17537c478bd9Sstevel@tonic-gate 	 * the i2c seeprom driver
17547c478bd9Sstevel@tonic-gate 	 */
17557c478bd9Sstevel@tonic-gate 
17567c478bd9Sstevel@tonic-gate 	bus_handle = devctl_bus_acquire(I2C_NODE, 0);
17577c478bd9Sstevel@tonic-gate 	if (bus_handle == NULL) {
17587c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG, I2C_NODE, errno);
17597c478bd9Sstevel@tonic-gate 		return (PSVC_FAILURE);
17607c478bd9Sstevel@tonic-gate 	}
17617c478bd9Sstevel@tonic-gate 	/* Create the deivce nodes for all 3 i2c parts on the PS */
17627c478bd9Sstevel@tonic-gate 	for (i = 0; i < 3; i++) {
17637c478bd9Sstevel@tonic-gate 		ddef_hdl = devctl_ddef_alloc(devices[ps_instance][i].name, 0);
17647c478bd9Sstevel@tonic-gate 		if (ddef_hdl == NULL) {
17657c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
17665eb92cf2Sdhain 			    devices[ps_instance][i].name, errno);
17677c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17687c478bd9Sstevel@tonic-gate 		}
17697c478bd9Sstevel@tonic-gate 		status = devctl_ddef_string(ddef_hdl, "compatible",
17705eb92cf2Sdhain 		    devices[ps_instance][i].compatible);
17717c478bd9Sstevel@tonic-gate 		if (status == -1) {
17727c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
17735eb92cf2Sdhain 			    devices[ps_instance][i].name, errno);
17747c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17757c478bd9Sstevel@tonic-gate 		}
17767c478bd9Sstevel@tonic-gate 		status = devctl_ddef_int_array(ddef_hdl, "reg", 2,
17775eb92cf2Sdhain 		    devices[ps_instance][i].addr);
17787c478bd9Sstevel@tonic-gate 		if (status == -1) {
17797c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_HANDLE_FAIL_MSG,
17805eb92cf2Sdhain 			    devices[ps_instance][i].name, errno);
17817c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17827c478bd9Sstevel@tonic-gate 		}
17837c478bd9Sstevel@tonic-gate 		if (devctl_bus_dev_create(bus_handle, ddef_hdl, 0,
17845eb92cf2Sdhain 		    &dev_handle)) {
17857c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, DEVTREE_NODE_CREATE_FAILED,
17865eb92cf2Sdhain 			    devices[ps_instance][i].name, errno);
17877c478bd9Sstevel@tonic-gate 			return (PSVC_FAILURE);
17887c478bd9Sstevel@tonic-gate 		} else
17897c478bd9Sstevel@tonic-gate 			devctl_release(dev_handle);
17907c478bd9Sstevel@tonic-gate 		devctl_ddef_free(ddef_hdl);
17917c478bd9Sstevel@tonic-gate 	}
17927c478bd9Sstevel@tonic-gate 	devctl_release(bus_handle);
17937c478bd9Sstevel@tonic-gate 
17947c478bd9Sstevel@tonic-gate 	return (status);
17957c478bd9Sstevel@tonic-gate }
17967c478bd9Sstevel@tonic-gate 
17977c478bd9Sstevel@tonic-gate static void
shutdown_routine()17987c478bd9Sstevel@tonic-gate shutdown_routine()
17997c478bd9Sstevel@tonic-gate {
18007c478bd9Sstevel@tonic-gate 	static boolean_t shutdown_flag = 0;
18017c478bd9Sstevel@tonic-gate 
18027c478bd9Sstevel@tonic-gate 	if (!(shutdown_flag)) {
18037c478bd9Sstevel@tonic-gate 		system(shutdown_string);
18047c478bd9Sstevel@tonic-gate 		shutdown_flag = 1;
18057c478bd9Sstevel@tonic-gate 	}
18067c478bd9Sstevel@tonic-gate }
18077c478bd9Sstevel@tonic-gate 
18087c478bd9Sstevel@tonic-gate /*
18097c478bd9Sstevel@tonic-gate  * This policy checks temperature sensors to see if the fault attribute
18107c478bd9Sstevel@tonic-gate  * is set to either High or Low Shutdown. If so then it shuts the system
18117c478bd9Sstevel@tonic-gate  * down with a 1 minute warning period
18127c478bd9Sstevel@tonic-gate  */
18137c478bd9Sstevel@tonic-gate int32_t
psvc_shutdown_policy(psvc_opaque_t hdlp,char * id)18147c478bd9Sstevel@tonic-gate psvc_shutdown_policy(psvc_opaque_t hdlp, char *id)
18157c478bd9Sstevel@tonic-gate {
18167c478bd9Sstevel@tonic-gate 	int32_t	status;
18177c478bd9Sstevel@tonic-gate 	char	fault[32] = {0};
18187c478bd9Sstevel@tonic-gate 	boolean_t	pr;
1819298b7f4cSjfrank 	int	retry;
18207c478bd9Sstevel@tonic-gate 
18217c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &pr);
18227c478bd9Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (pr != PSVC_PRESENT)) {
18237c478bd9Sstevel@tonic-gate 		return (status);
18247c478bd9Sstevel@tonic-gate 	}
18257c478bd9Sstevel@tonic-gate 
1826298b7f4cSjfrank 	retry = 0;
1827298b7f4cSjfrank 	do {
1828298b7f4cSjfrank 		if (retry)
1829298b7f4cSjfrank 			(void) sleep(retry_sleep_temp_shutdown);
1830298b7f4cSjfrank 		status = psvc_get_attr(hdlp, id, PSVC_FAULTID_ATTR, fault);
1831298b7f4cSjfrank 		if (status != PSVC_SUCCESS)
1832298b7f4cSjfrank 			return (status);
1833298b7f4cSjfrank 		retry++;
1834298b7f4cSjfrank 	} while (((strcmp(fault, PSVC_TEMP_LO_SHUT) == 0) ||
1835298b7f4cSjfrank 	    (strcmp(fault, PSVC_TEMP_HI_SHUT) == 0)) &&
18365eb92cf2Sdhain 	    (retry < n_retry_temp_shutdown));
18377c478bd9Sstevel@tonic-gate 	if ((strcmp(fault, PSVC_TEMP_LO_SHUT) == 0) ||
18387c478bd9Sstevel@tonic-gate 	    (strcmp(fault, PSVC_TEMP_HI_SHUT) == 0)) {
18397c478bd9Sstevel@tonic-gate 		shutdown_routine();
18407c478bd9Sstevel@tonic-gate 	}
18417c478bd9Sstevel@tonic-gate 
18427c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
18437c478bd9Sstevel@tonic-gate }
18447c478bd9Sstevel@tonic-gate 
18457c478bd9Sstevel@tonic-gate int32_t
psvc_check_disk_fault_policy_0(psvc_opaque_t hdlp,char * id)18467c478bd9Sstevel@tonic-gate psvc_check_disk_fault_policy_0(psvc_opaque_t hdlp, char *id)
18477c478bd9Sstevel@tonic-gate {
18487c478bd9Sstevel@tonic-gate 	int32_t		status = PSVC_SUCCESS;
18497c478bd9Sstevel@tonic-gate 	int32_t		i;
1850*338c2f03SToomas Soome 	char		prev_state[32], led_state[32];
18517c478bd9Sstevel@tonic-gate 	char		disk_fault[32], disk_state[32];
1852360e6f5eSmathue 	static char	*disk_id[DAK_MAX_DISKS] = {NULL};
1853360e6f5eSmathue 	static char	*led_id[DAK_MAX_DISKS] = {NULL};
1854360e6f5eSmathue 	static char	*parent_id[DAK_MAX_DISKS] = {NULL};
18557c478bd9Sstevel@tonic-gate 	boolean_t	present;
1856298b7f4cSjfrank 	int		retry;
18577c478bd9Sstevel@tonic-gate 
18587c478bd9Sstevel@tonic-gate 	/*
18597c478bd9Sstevel@tonic-gate 	 * Check which disk faulted, now get the disks.
18607c478bd9Sstevel@tonic-gate 	 * We are now going to get disk, disk parent,
18617c478bd9Sstevel@tonic-gate 	 * parent's leds, and check to see if parent's leds are on
18627c478bd9Sstevel@tonic-gate 	 */
18637c478bd9Sstevel@tonic-gate 
18647c478bd9Sstevel@tonic-gate 	if (disk_id[0] == NULL) {
18657c478bd9Sstevel@tonic-gate 		for (i = 0; i < DAK_MAX_DISKS; i++) {
18667c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
18677c478bd9Sstevel@tonic-gate 			    &(disk_id[i]), PSVC_DISK, i);
18687c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
18697c478bd9Sstevel@tonic-gate 				return (status);
18707c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, disk_id[i],
18717c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &(parent_id[i]),
18727c478bd9Sstevel@tonic-gate 			    PSVC_PARENT, 0);
18737c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
18747c478bd9Sstevel@tonic-gate 				return (status);
18757c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, parent_id[i],
18767c478bd9Sstevel@tonic-gate 			    PSVC_ASSOC_ID_ATTR, &(led_id[i]),
18777c478bd9Sstevel@tonic-gate 			    PSVC_SLOT_FAULT_LED, 0);
18787c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
18797c478bd9Sstevel@tonic-gate 				return (status);
18807c478bd9Sstevel@tonic-gate 
18817c478bd9Sstevel@tonic-gate 		}
18827c478bd9Sstevel@tonic-gate 	}
18837c478bd9Sstevel@tonic-gate 
18847c478bd9Sstevel@tonic-gate 	for (i = 0; i < DAK_MAX_DISKS; i++) {
18857c478bd9Sstevel@tonic-gate 		prev_state[0] = 0;
18867c478bd9Sstevel@tonic-gate 
18877c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, disk_id[i], PSVC_PRESENCE_ATTR,
18885eb92cf2Sdhain 		    &present);
18897c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
18907c478bd9Sstevel@tonic-gate 			return (status);
18917c478bd9Sstevel@tonic-gate 
18927c478bd9Sstevel@tonic-gate 		if (present == PSVC_ABSENT)
18937c478bd9Sstevel@tonic-gate 			continue;
18947c478bd9Sstevel@tonic-gate 
18957c478bd9Sstevel@tonic-gate 		/*
18967c478bd9Sstevel@tonic-gate 		 * Check if whether or not the led is on.
18977c478bd9Sstevel@tonic-gate 		 * If so, then this disk has a problem and
18987c478bd9Sstevel@tonic-gate 		 * set its fault and error states to bad.
18997c478bd9Sstevel@tonic-gate 		 * If not, then set fault and error states to good.
19007c478bd9Sstevel@tonic-gate 		 * If the disk underwent a change in state, then
19017c478bd9Sstevel@tonic-gate 		 * print out what state it's now in.
19027c478bd9Sstevel@tonic-gate 		 */
19037c478bd9Sstevel@tonic-gate 
19047c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, disk_id[i], PSVC_STATE_ATTR,
19057c478bd9Sstevel@tonic-gate 		    prev_state);
19067c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19077c478bd9Sstevel@tonic-gate 			return (status);
19087c478bd9Sstevel@tonic-gate 
19097c478bd9Sstevel@tonic-gate 		retry = 0;
19107c478bd9Sstevel@tonic-gate 		do {
19117c478bd9Sstevel@tonic-gate 			if (retry)
1912298b7f4cSjfrank 				(void) sleep(retry_sleep_diskfault);
19137c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, led_id[i], PSVC_STATE_ATTR,
19147c478bd9Sstevel@tonic-gate 			    led_state);
19157c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
19167c478bd9Sstevel@tonic-gate 				return (status);
19177c478bd9Sstevel@tonic-gate 			retry++;
19187c478bd9Sstevel@tonic-gate 			/*
19197c478bd9Sstevel@tonic-gate 			 * check to see if we need to retry. the conditions are:
19207c478bd9Sstevel@tonic-gate 			 *
19217c478bd9Sstevel@tonic-gate 			 * prev_state		led_state		retry
19227c478bd9Sstevel@tonic-gate 			 * --------------------------------------------------
19237c478bd9Sstevel@tonic-gate 			 * PSVC_ERROR		PSVC_LED_ON		yes
19247c478bd9Sstevel@tonic-gate 			 * PSVC_OK		PSVC_LED_OFF		yes
19257c478bd9Sstevel@tonic-gate 			 * PSVC_ERROR		PSVC_LED_OFF		no
19267c478bd9Sstevel@tonic-gate 			 * PSVC_OK		PSVC_LED_ON		no
19277c478bd9Sstevel@tonic-gate 			 */
1928298b7f4cSjfrank 		} while ((retry < n_retry_diskfault) &&
19297c478bd9Sstevel@tonic-gate 		    change_of_state_str(prev_state, PSVC_OK,
19307c478bd9Sstevel@tonic-gate 		    led_state, PSVC_LED_ON));
19317c478bd9Sstevel@tonic-gate 
19327c478bd9Sstevel@tonic-gate 		/*
19337c478bd9Sstevel@tonic-gate 		 * Set the disk's state and fault id according to
19347c478bd9Sstevel@tonic-gate 		 * what we found the disk fault sensor (disk_slot_fault_led)
19357c478bd9Sstevel@tonic-gate 		 * to be.
19367c478bd9Sstevel@tonic-gate 		 */
19377c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_LED_ON) == 0) {
19387c478bd9Sstevel@tonic-gate 			strcpy(disk_fault, PSVC_GEN_FAULT);
19397c478bd9Sstevel@tonic-gate 			strcpy(disk_state, PSVC_ERROR);
19407c478bd9Sstevel@tonic-gate 		} else {
19417c478bd9Sstevel@tonic-gate 			strcpy(disk_fault, PSVC_NO_FAULT);
19427c478bd9Sstevel@tonic-gate 			strcpy(disk_state, PSVC_OK);
19437c478bd9Sstevel@tonic-gate 		}
19447c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, disk_id[i], PSVC_STATE_ATTR,
19455eb92cf2Sdhain 		    disk_state);
19467c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19477c478bd9Sstevel@tonic-gate 			return (status);
19487c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, disk_id[i], PSVC_FAULTID_ATTR,
19495eb92cf2Sdhain 		    disk_fault);
19507c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19517c478bd9Sstevel@tonic-gate 			return (status);
19527c478bd9Sstevel@tonic-gate 		/*
19537c478bd9Sstevel@tonic-gate 		 * Check disk states.  If they differ, then print out
19547c478bd9Sstevel@tonic-gate 		 * the current state of the disk
19557c478bd9Sstevel@tonic-gate 		 */
19567c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, disk_id[i], PSVC_PREV_STATE_ATTR,
19575eb92cf2Sdhain 		    prev_state);
19587c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19597c478bd9Sstevel@tonic-gate 			return (status);
19607c478bd9Sstevel@tonic-gate 
19617c478bd9Sstevel@tonic-gate 		if (strcmp(disk_state, prev_state) != 0) {
19627c478bd9Sstevel@tonic-gate 			if (strcmp(disk_state, PSVC_ERROR) == 0) {
19637c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DISK_FAULT_MSG, disk_id[i]);
19647c478bd9Sstevel@tonic-gate 			} else {
19657c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, DISK_OK_MSG, disk_id[i]);
19667c478bd9Sstevel@tonic-gate 			}
19677c478bd9Sstevel@tonic-gate 		}
19687c478bd9Sstevel@tonic-gate 	}
19697c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
19707c478bd9Sstevel@tonic-gate }
19717c478bd9Sstevel@tonic-gate 
19727c478bd9Sstevel@tonic-gate int32_t
psvc_update_FSP_fault_led_policy_0(psvc_opaque_t hdlp,char * id)19737c478bd9Sstevel@tonic-gate psvc_update_FSP_fault_led_policy_0(psvc_opaque_t hdlp, char *id)
19747c478bd9Sstevel@tonic-gate {
19757c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
19767c478bd9Sstevel@tonic-gate 	int32_t i;
19777c478bd9Sstevel@tonic-gate 	int32_t dev_count, fault_state = 0;
19787c478bd9Sstevel@tonic-gate 	char	*dev_id;
19797c478bd9Sstevel@tonic-gate 	char	dev_state[32], led_state[32];
19807c478bd9Sstevel@tonic-gate 	boolean_t	present;
19817c478bd9Sstevel@tonic-gate 
19827c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &dev_count,
19835eb92cf2Sdhain 	    PSVC_DEV_FAULT_SENSOR);
19847c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
19857c478bd9Sstevel@tonic-gate 		return (status);
19867c478bd9Sstevel@tonic-gate 
19877c478bd9Sstevel@tonic-gate 	fault_state = 0;
19887c478bd9Sstevel@tonic-gate 
19897c478bd9Sstevel@tonic-gate 	for (i = 0; i < dev_count; i++) {
19907c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
19915eb92cf2Sdhain 		    &dev_id, PSVC_DEV_FAULT_SENSOR, i);
19927c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19937c478bd9Sstevel@tonic-gate 			return (status);
19947c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, dev_id, PSVC_PRESENCE_ATTR,
19955eb92cf2Sdhain 		    &present);
19967c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
19977c478bd9Sstevel@tonic-gate 			return (status);
19987c478bd9Sstevel@tonic-gate 
19997c478bd9Sstevel@tonic-gate 		if (present == PSVC_ABSENT)
20007c478bd9Sstevel@tonic-gate 			continue;
20017c478bd9Sstevel@tonic-gate 
20027c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, dev_id, PSVC_STATE_ATTR,
20035eb92cf2Sdhain 		    dev_state);
20047c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20057c478bd9Sstevel@tonic-gate 			return (status);
20067c478bd9Sstevel@tonic-gate 
20077c478bd9Sstevel@tonic-gate 		if (strcmp(dev_state, PSVC_ERROR) == 0) {
20087c478bd9Sstevel@tonic-gate 			fault_state = 1;
20097c478bd9Sstevel@tonic-gate 		}
20107c478bd9Sstevel@tonic-gate 	}
20117c478bd9Sstevel@tonic-gate 	if (fault_state == 1) {
20127c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, led_state);
20137c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20147c478bd9Sstevel@tonic-gate 			return (status);
20157c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_OFF) == 0) {
20167c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
20177c478bd9Sstevel@tonic-gate 			    PSVC_ON);
20187c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
20197c478bd9Sstevel@tonic-gate 				return (status);
20207c478bd9Sstevel@tonic-gate 		}
20217c478bd9Sstevel@tonic-gate 	} else {
20227c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, led_state);
20237c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20247c478bd9Sstevel@tonic-gate 			return (status);
20257c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_ON) == 0) {
20267c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
20277c478bd9Sstevel@tonic-gate 			    PSVC_OFF);
20287c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
20297c478bd9Sstevel@tonic-gate 				return (status);
20307c478bd9Sstevel@tonic-gate 		}
20317c478bd9Sstevel@tonic-gate 	}
20327c478bd9Sstevel@tonic-gate 	status = update_gen_fault_led(hdlp, GEN_FAULT_LED);
20337c478bd9Sstevel@tonic-gate 
20347c478bd9Sstevel@tonic-gate 	return (status);
20357c478bd9Sstevel@tonic-gate }
20367c478bd9Sstevel@tonic-gate 
20377c478bd9Sstevel@tonic-gate int32_t
update_gen_fault_led(psvc_opaque_t hdlp,char * id)20387c478bd9Sstevel@tonic-gate update_gen_fault_led(psvc_opaque_t hdlp, char *id)
20397c478bd9Sstevel@tonic-gate {
20407c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
20417c478bd9Sstevel@tonic-gate 	int32_t i;
20427c478bd9Sstevel@tonic-gate 	int32_t led_count, fault_state;
20437c478bd9Sstevel@tonic-gate 	char	*led_id;
20447c478bd9Sstevel@tonic-gate 	char	led_state[32];
20457c478bd9Sstevel@tonic-gate 
20467c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &led_count,
20475eb92cf2Sdhain 	    PSVC_DEV_FAULT_SENSOR);
20487c478bd9Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
20497c478bd9Sstevel@tonic-gate 		return (status);
20507c478bd9Sstevel@tonic-gate 
20517c478bd9Sstevel@tonic-gate 	fault_state = 0;
20527c478bd9Sstevel@tonic-gate 
20537c478bd9Sstevel@tonic-gate 	for (i = 0; i < led_count; i++) {
20547c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
20555eb92cf2Sdhain 		    &led_id, PSVC_DEV_FAULT_SENSOR, i);
20567c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20577c478bd9Sstevel@tonic-gate 			return (status);
20587c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, led_id, PSVC_STATE_ATTR,
20595eb92cf2Sdhain 		    led_state);
20607c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20617c478bd9Sstevel@tonic-gate 			return (status);
20627c478bd9Sstevel@tonic-gate 
20637c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_ON) == 0) {
20647c478bd9Sstevel@tonic-gate 			fault_state = 1;
20657c478bd9Sstevel@tonic-gate 		}
20667c478bd9Sstevel@tonic-gate 	}
20677c478bd9Sstevel@tonic-gate 
20687c478bd9Sstevel@tonic-gate 	if (fault_state == 1) {
20697c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, led_state);
20707c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20717c478bd9Sstevel@tonic-gate 			return (status);
20727c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_OFF) == 0) {
20737c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
20747c478bd9Sstevel@tonic-gate 			    PSVC_ON);
20757c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
20767c478bd9Sstevel@tonic-gate 				return (status);
20777c478bd9Sstevel@tonic-gate 		}
20787c478bd9Sstevel@tonic-gate 	} else {
20797c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, led_state);
20807c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
20817c478bd9Sstevel@tonic-gate 			return (status);
20827c478bd9Sstevel@tonic-gate 		if (strcmp(led_state, PSVC_ON) == 0) {
20837c478bd9Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
20847c478bd9Sstevel@tonic-gate 			    PSVC_OFF);
20857c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
20867c478bd9Sstevel@tonic-gate 				return (status);
20877c478bd9Sstevel@tonic-gate 		}
20887c478bd9Sstevel@tonic-gate 	}
20897c478bd9Sstevel@tonic-gate 
20907c478bd9Sstevel@tonic-gate 	return (status);
20917c478bd9Sstevel@tonic-gate }
20927c478bd9Sstevel@tonic-gate 
20937c478bd9Sstevel@tonic-gate 
20947c478bd9Sstevel@tonic-gate /*
20957c478bd9Sstevel@tonic-gate  * This function detects whether the module present in the dakatari's
20967c478bd9Sstevel@tonic-gate  * CPU slot is a CPU module or a Zulu (XVR-4000).
20977c478bd9Sstevel@tonic-gate  * Based on this detection it also sets the appropriate temperature sensors
20987c478bd9Sstevel@tonic-gate  * to HOTPLUGGED, so that it works properly with check_temp() function
20997c478bd9Sstevel@tonic-gate  */
21007c478bd9Sstevel@tonic-gate #define	MAX_MODULE_SIZE		20
21017c478bd9Sstevel@tonic-gate #define	MAX_TEMP_SENSOR_SIZE	30
21027c478bd9Sstevel@tonic-gate 
21037c478bd9Sstevel@tonic-gate int32_t
psvc_update_cpu_module_card_node_0(psvc_opaque_t hdlp,char * id)21047c478bd9Sstevel@tonic-gate psvc_update_cpu_module_card_node_0(psvc_opaque_t hdlp, char *id)
21057c478bd9Sstevel@tonic-gate {
21067c478bd9Sstevel@tonic-gate 	int32_t	set_temp_sensor_properties(psvc_opaque_t, char *);
21077c478bd9Sstevel@tonic-gate 	int32_t	remove_module_node(psvc_opaque_t, char *);
21087c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
21097c478bd9Sstevel@tonic-gate 	fru_info_t fru_data;
21107c478bd9Sstevel@tonic-gate 	char *fru, seg_name[2];
21117c478bd9Sstevel@tonic-gate 	int8_t seg_count, module_card;
21127c478bd9Sstevel@tonic-gate 	int32_t match_count, i, j, seg_desc_start = 0x1806, module_address;
21137c478bd9Sstevel@tonic-gate 	int32_t seg_found;
21147c478bd9Sstevel@tonic-gate 	boolean_t present;
21157c478bd9Sstevel@tonic-gate 	seg_desc_t segment;
21167c478bd9Sstevel@tonic-gate 	char other_module_id[MAX_MODULE_SIZE];
21177c478bd9Sstevel@tonic-gate 	char cpu_temp_sensor1[MAX_TEMP_SENSOR_SIZE];
21187c478bd9Sstevel@tonic-gate 	char cpu_temp_sensor2[MAX_TEMP_SENSOR_SIZE];
21197c478bd9Sstevel@tonic-gate 	char zulu_temp_sensor1[MAX_TEMP_SENSOR_SIZE];
21207c478bd9Sstevel@tonic-gate 	char zulu_temp_sensor2[MAX_TEMP_SENSOR_SIZE];
21217c478bd9Sstevel@tonic-gate 	int offset = 0x7;
21227c478bd9Sstevel@tonic-gate 
21237c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
21247c478bd9Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (present != PSVC_PRESENT)) {
21257c478bd9Sstevel@tonic-gate 		return (status);
21267c478bd9Sstevel@tonic-gate 	}
21277c478bd9Sstevel@tonic-gate 
21287c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &match_count,
21297c478bd9Sstevel@tonic-gate 	    PSVC_FRU);
21307c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
21317c478bd9Sstevel@tonic-gate 		return (status);
21327c478bd9Sstevel@tonic-gate 	}
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 	for (i = 0; i < match_count; i++) {
21357c478bd9Sstevel@tonic-gate 		seg_found = 0;
21367c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR, &fru,
21377c478bd9Sstevel@tonic-gate 		    PSVC_FRU, i);
21387c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
21397c478bd9Sstevel@tonic-gate 			return (status);
21407c478bd9Sstevel@tonic-gate 
21417c478bd9Sstevel@tonic-gate 		fru_data.buf_start = 0x1805;
21427c478bd9Sstevel@tonic-gate 		fru_data.buf = (char *)&seg_count;
21437c478bd9Sstevel@tonic-gate 		fru_data.read_size = 1;
21447c478bd9Sstevel@tonic-gate 
21457c478bd9Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
21467c478bd9Sstevel@tonic-gate 		    &fru_data);
21477c478bd9Sstevel@tonic-gate 		if (status != PSVC_SUCCESS) {
21487c478bd9Sstevel@tonic-gate 			return (status);
21497c478bd9Sstevel@tonic-gate 		}
21507c478bd9Sstevel@tonic-gate 
21517c478bd9Sstevel@tonic-gate 		for (j = 0; (j < seg_count) && (!seg_found); j++) {
21527c478bd9Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
21537c478bd9Sstevel@tonic-gate 			fru_data.buf = seg_name;
21547c478bd9Sstevel@tonic-gate 			fru_data.read_size = 2;
21557c478bd9Sstevel@tonic-gate 
21567c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
21577c478bd9Sstevel@tonic-gate 			    &fru_data);
21587c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
21597c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, GET_ATTR_FRU_FAILED_MSG);
21607c478bd9Sstevel@tonic-gate 				return (status);
21617c478bd9Sstevel@tonic-gate 			}
21627c478bd9Sstevel@tonic-gate 
21637c478bd9Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + 2;
21647c478bd9Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
21657c478bd9Sstevel@tonic-gate 			fru_data.buf = (char *)&segment;
21667c478bd9Sstevel@tonic-gate 			fru_data.read_size = sizeof (seg_desc_t);
21677c478bd9Sstevel@tonic-gate 
21687c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
21697c478bd9Sstevel@tonic-gate 			    &fru_data);
21707c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
21717c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, GET_ATTR_FRU_FAILED_MSG);
21727c478bd9Sstevel@tonic-gate 				return (status);
21737c478bd9Sstevel@tonic-gate 			}
21747c478bd9Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + sizeof (seg_desc_t);
21757c478bd9Sstevel@tonic-gate 			if (memcmp(seg_name, "SC", 2) == 0)
21767c478bd9Sstevel@tonic-gate 				seg_found = 1;
21777c478bd9Sstevel@tonic-gate 		}
21787c478bd9Sstevel@tonic-gate 
21797c478bd9Sstevel@tonic-gate 		if (seg_found) {
21807c478bd9Sstevel@tonic-gate 			module_address = segment.segoffset + offset;
21817c478bd9Sstevel@tonic-gate 			fru_data.buf_start = module_address;
21827c478bd9Sstevel@tonic-gate 			fru_data.buf = (char *)&module_card;
21837c478bd9Sstevel@tonic-gate 			fru_data.read_size = 1;
21847c478bd9Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
21857c478bd9Sstevel@tonic-gate 			    &fru_data);
21867c478bd9Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
21877c478bd9Sstevel@tonic-gate 				syslog(LOG_ERR, GET_ATTR_FRU_FAILED_MSG);
21887c478bd9Sstevel@tonic-gate 				return (status);
21897c478bd9Sstevel@tonic-gate 			}
21907c478bd9Sstevel@tonic-gate 		} else {
21917c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, NO_FRU_INFO_MSG, id);
21927c478bd9Sstevel@tonic-gate 		}
21937c478bd9Sstevel@tonic-gate 	}
21947c478bd9Sstevel@tonic-gate 
21957c478bd9Sstevel@tonic-gate 	if (strcmp(id, "ZULU_1_3_MOD_CARD") == 0) {
21967c478bd9Sstevel@tonic-gate 		strlcpy(other_module_id, "CPU_1_3_MOD_CARD", MAX_MODULE_SIZE);
21977c478bd9Sstevel@tonic-gate 
21987c478bd9Sstevel@tonic-gate 		strlcpy(cpu_temp_sensor1, "CPU1_DIE_TEMPERATURE_SENSOR",
21997c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22007c478bd9Sstevel@tonic-gate 		strlcpy(cpu_temp_sensor2, "CPU3_DIE_TEMPERATURE_SENSOR",
22017c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22027c478bd9Sstevel@tonic-gate 
22037c478bd9Sstevel@tonic-gate 		strlcpy(zulu_temp_sensor1, "ZULU1_DIE_TEMPERATURE_SENSOR",
22047c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22057c478bd9Sstevel@tonic-gate 		strlcpy(zulu_temp_sensor2, "ZULU3_DIE_TEMPERATURE_SENSOR",
22067c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22077c478bd9Sstevel@tonic-gate 	}
22087c478bd9Sstevel@tonic-gate 
22097c478bd9Sstevel@tonic-gate 	if (strcmp(id, "ZULU_4_6_MOD_CARD") == 0) {
22107c478bd9Sstevel@tonic-gate 		strlcpy(other_module_id, "CPU_4_6_MOD_CARD", MAX_MODULE_SIZE);
22117c478bd9Sstevel@tonic-gate 
22127c478bd9Sstevel@tonic-gate 		strlcpy(cpu_temp_sensor1, "CPU4_DIE_TEMPERATURE_SENSOR",
22137c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22147c478bd9Sstevel@tonic-gate 		strlcpy(cpu_temp_sensor2, "CPU6_DIE_TEMPERATURE_SENSOR",
22157c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22167c478bd9Sstevel@tonic-gate 
22177c478bd9Sstevel@tonic-gate 		strlcpy(zulu_temp_sensor1, "ZULU4_DIE_TEMPERATURE_SENSOR",
22187c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22197c478bd9Sstevel@tonic-gate 		strlcpy(zulu_temp_sensor2, "ZULU6_DIE_TEMPERATURE_SENSOR",
22207c478bd9Sstevel@tonic-gate 		    MAX_TEMP_SENSOR_SIZE);
22217c478bd9Sstevel@tonic-gate 	}
22227c478bd9Sstevel@tonic-gate 
22237c478bd9Sstevel@tonic-gate 
22247c478bd9Sstevel@tonic-gate 	/*
22257c478bd9Sstevel@tonic-gate 	 * If the module in the CPU slot is a Zulu (XVR-4000), then
22267c478bd9Sstevel@tonic-gate 	 * location 0x1EB0 in its FRUid prom has a value 0xFB.
22277c478bd9Sstevel@tonic-gate 	 * If Zulu (XVR-4000) is detected, delete the CPU node, otherwise
22287c478bd9Sstevel@tonic-gate 	 * delete the Zulu node. Also set the temperature sensor value to
22297c478bd9Sstevel@tonic-gate 	 * HOTPLUGGED for absent temperature sensors.
22307c478bd9Sstevel@tonic-gate 	 */
22317c478bd9Sstevel@tonic-gate 	if ((module_card & 0xff) == 0xfb) {
22327c478bd9Sstevel@tonic-gate 		status = set_temp_sensor_properties(hdlp, cpu_temp_sensor1);
22337c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22347c478bd9Sstevel@tonic-gate 			return (status);
22357c478bd9Sstevel@tonic-gate 		}
22367c478bd9Sstevel@tonic-gate 
22377c478bd9Sstevel@tonic-gate 		status = set_temp_sensor_properties(hdlp, cpu_temp_sensor2);
22387c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22397c478bd9Sstevel@tonic-gate 			return (status);
22407c478bd9Sstevel@tonic-gate 		}
22417c478bd9Sstevel@tonic-gate 
22427c478bd9Sstevel@tonic-gate 		/*
22437c478bd9Sstevel@tonic-gate 		 * Remove CPU node
22447c478bd9Sstevel@tonic-gate 		 */
22457c478bd9Sstevel@tonic-gate 		status = remove_module_node(hdlp, other_module_id);
22467c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22477c478bd9Sstevel@tonic-gate 			return (status);
22487c478bd9Sstevel@tonic-gate 		}
22497c478bd9Sstevel@tonic-gate 	} else {
22507c478bd9Sstevel@tonic-gate 		status = set_temp_sensor_properties(hdlp, zulu_temp_sensor1);
22517c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22527c478bd9Sstevel@tonic-gate 			return (status);
22537c478bd9Sstevel@tonic-gate 		}
22547c478bd9Sstevel@tonic-gate 		status = set_temp_sensor_properties(hdlp, zulu_temp_sensor2);
22557c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22567c478bd9Sstevel@tonic-gate 			return (status);
22577c478bd9Sstevel@tonic-gate 		}
22587c478bd9Sstevel@tonic-gate 
22597c478bd9Sstevel@tonic-gate 		/*
22607c478bd9Sstevel@tonic-gate 		 * Remove Zulu (XVR-4000) node
22617c478bd9Sstevel@tonic-gate 		 */
22627c478bd9Sstevel@tonic-gate 		status = remove_module_node(hdlp, id);
22637c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
22647c478bd9Sstevel@tonic-gate 			return (status);
22657c478bd9Sstevel@tonic-gate 		}
22667c478bd9Sstevel@tonic-gate 	}
22677c478bd9Sstevel@tonic-gate 
22687c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
22697c478bd9Sstevel@tonic-gate }
22707c478bd9Sstevel@tonic-gate 
22717c478bd9Sstevel@tonic-gate 
22727c478bd9Sstevel@tonic-gate /*
22737c478bd9Sstevel@tonic-gate  * Remove the CPU slot's module node
22747c478bd9Sstevel@tonic-gate  */
22757c478bd9Sstevel@tonic-gate int32_t
remove_module_node(psvc_opaque_t hdlp,char * id)22767c478bd9Sstevel@tonic-gate remove_module_node(psvc_opaque_t hdlp, char *id)
22777c478bd9Sstevel@tonic-gate {
22787c478bd9Sstevel@tonic-gate 	char parent_path[256];
22797c478bd9Sstevel@tonic-gate 	picl_nodehdl_t child_node;
22807c478bd9Sstevel@tonic-gate 
22817c478bd9Sstevel@tonic-gate 	/* convert name to node, and parent path */
22827c478bd9Sstevel@tonic-gate 	psvcplugin_lookup(id, parent_path, &child_node);
22837c478bd9Sstevel@tonic-gate 	/* Device removed */
22847c478bd9Sstevel@tonic-gate 	ptree_delete_node(child_node);
22857c478bd9Sstevel@tonic-gate 
22867c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
22877c478bd9Sstevel@tonic-gate }
22887c478bd9Sstevel@tonic-gate 
22897c478bd9Sstevel@tonic-gate 
22907c478bd9Sstevel@tonic-gate /*
22917c478bd9Sstevel@tonic-gate  * Set absent temperature sensor values to HOTPLUGGED
22927c478bd9Sstevel@tonic-gate  */
22937c478bd9Sstevel@tonic-gate int32_t
set_temp_sensor_properties(psvc_opaque_t hdlp,char * id)22947c478bd9Sstevel@tonic-gate set_temp_sensor_properties(psvc_opaque_t hdlp, char *id)
22957c478bd9Sstevel@tonic-gate {
22967c478bd9Sstevel@tonic-gate 	char state[32];
22977c478bd9Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
22987c478bd9Sstevel@tonic-gate 
22997c478bd9Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, state);
23007c478bd9Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
23017c478bd9Sstevel@tonic-gate 		return (status);
23027c478bd9Sstevel@tonic-gate 	}
23037c478bd9Sstevel@tonic-gate 
23047c478bd9Sstevel@tonic-gate 	if (strcmp(state, PSVC_HOTPLUGGED) != 0) {
23057c478bd9Sstevel@tonic-gate 		strcpy(state, PSVC_HOTPLUGGED);
23067c478bd9Sstevel@tonic-gate 
23077c478bd9Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
23087c478bd9Sstevel@tonic-gate 		if (status == PSVC_FAILURE) {
23097c478bd9Sstevel@tonic-gate 			return (status);
23107c478bd9Sstevel@tonic-gate 		}
23117c478bd9Sstevel@tonic-gate 	}
23127c478bd9Sstevel@tonic-gate 
23137c478bd9Sstevel@tonic-gate 	return (PSVC_SUCCESS);
23147c478bd9Sstevel@tonic-gate }
2315