xref: /onnv-gate/usr/src/cmd/picl/plugins/sun4u/psvc/psvcpolicy/psvcpolicy.c (revision 6398:d95e5b6874fa)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6398Sanbui  * Common Development and Distribution License (the "License").
6*6398Sanbui  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
20*6398Sanbui  *
21*6398Sanbui  *
22*6398Sanbui  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
24*6398Sanbui  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * This file contains routines to support the Platform Services Plugin
310Sstevel@tonic-gate  * These routines implement the platform independent environment monitoring
320Sstevel@tonic-gate  * and control policies that may be invoked by a daemon thread within
330Sstevel@tonic-gate  * the plugin
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <syslog.h>
370Sstevel@tonic-gate #include <unistd.h>
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <stdlib.h>
400Sstevel@tonic-gate #include <libintl.h>
410Sstevel@tonic-gate #include <errno.h>
420Sstevel@tonic-gate #include <fcntl.h>
430Sstevel@tonic-gate #include <strings.h>
440Sstevel@tonic-gate #include <libintl.h>
450Sstevel@tonic-gate #include <sys/types.h>
46958Sjfrank #include <string.h>
47958Sjfrank #include <limits.h>
480Sstevel@tonic-gate #include <picl.h>
490Sstevel@tonic-gate #include <picltree.h>
500Sstevel@tonic-gate #include <sys/types.h>
510Sstevel@tonic-gate #include <string.h>
520Sstevel@tonic-gate #include <psvc_objects.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #define	LOWTEMP_CRITICAL_MSG		\
550Sstevel@tonic-gate 	gettext("CRITICAL : LOW TEMPERATURE DETECTED %d, %s")
560Sstevel@tonic-gate #define	LOWTEMP_WARNING_MSG		\
570Sstevel@tonic-gate 	gettext("WARNING : LOW TEMPERATURE DETECTED %d, %s")
580Sstevel@tonic-gate #define	HIGHTEMP_CRITICAL_MSG		\
590Sstevel@tonic-gate 	gettext("CRITICAL : HIGH TEMPERATURE DETECTED %d, %s")
600Sstevel@tonic-gate #define	HIGHTEMP_WARNING_MSG		\
610Sstevel@tonic-gate 	gettext("WARNING : HIGH TEMPERATURE DETECTED %d, %s")
620Sstevel@tonic-gate #define	DEVICE_INSERTED_MSG	gettext("Device %s inserted")
630Sstevel@tonic-gate #define	DEVICE_REMOVED_MSG	gettext("Device %s removed")
640Sstevel@tonic-gate #define	DEVICE_FAILURE_MSG		\
650Sstevel@tonic-gate 	gettext("CRITICAL: Device %s failure detected by sensor %s\n")
660Sstevel@tonic-gate #define	DEVICE_OK_MSG	gettext("Device %s OK")
670Sstevel@tonic-gate #define	SECONDARY_FAN_FAIL_MSG	gettext("Secondary fan failure, device %s")
680Sstevel@tonic-gate #define	KEYSWITCH_POS_READ_FAILED_MSG	\
690Sstevel@tonic-gate 	gettext("Keyswitch position could not be determined")
700Sstevel@tonic-gate #define	KEYSWITCH_POS_CHANGED_MSG gettext("Keyswitch position changed to %s")
710Sstevel@tonic-gate #define	GET_PRESENCE_FAILED_MSG		\
720Sstevel@tonic-gate 	gettext("Failed to get presence attribute, id = %s, errno = %d\n")
730Sstevel@tonic-gate #define	GET_SENSOR_FAILED_MSG		\
740Sstevel@tonic-gate 	gettext("Failed to get sensor value, id = %s, errno = %d\n")
750Sstevel@tonic-gate #define	PS_OVER_CURRENT_MSG		\
760Sstevel@tonic-gate 	gettext("WARNING: Power Supply overcurrent detected for %s\n")
770Sstevel@tonic-gate #define	SET_LED_FAILED_MSG		\
780Sstevel@tonic-gate 	gettext("Failed to set LED state, id = %s, errno = %d\n")
790Sstevel@tonic-gate #define	SET_FANSPEED_FAILED_MSG		\
800Sstevel@tonic-gate 	gettext("Failed to set fan speed, id = %s, errno = %d\n")
810Sstevel@tonic-gate #define	FAN_MISSING_MSG			\
820Sstevel@tonic-gate 	gettext("WARNING: Fan missing, id = %s\n")
830Sstevel@tonic-gate #define	TEMP_SENSOR_FAULT		\
840Sstevel@tonic-gate 	gettext("WARNING: Temperature Sensor %s returning faulty temp\n")
850Sstevel@tonic-gate #define	TEMP_OFFSET	17
860Sstevel@tonic-gate 
870Sstevel@tonic-gate static char *shutdown_string = "shutdown -y -g 60 -i 5 \"OVERTEMP condition\"";
880Sstevel@tonic-gate 
890Sstevel@tonic-gate static int cpus_online = 0;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate typedef struct seg_desc {
920Sstevel@tonic-gate 	int32_t segdesc;
930Sstevel@tonic-gate 	int16_t segoffset;
940Sstevel@tonic-gate 	int16_t seglength;
950Sstevel@tonic-gate } seg_desc_t;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate static int32_t threshold_names[] = {
980Sstevel@tonic-gate 	PSVC_HW_LO_SHUT_ATTR,
990Sstevel@tonic-gate 	PSVC_LO_SHUT_ATTR,
1000Sstevel@tonic-gate 	PSVC_LO_WARN_ATTR,
1010Sstevel@tonic-gate 	PSVC_NOT_USED,			/* LOW MODE which is not used */
1020Sstevel@tonic-gate 	PSVC_OPTIMAL_TEMP_ATTR,
1030Sstevel@tonic-gate 	PSVC_HI_WARN_ATTR,
1040Sstevel@tonic-gate 	PSVC_HI_SHUT_ATTR,
1050Sstevel@tonic-gate 	PSVC_HW_HI_SHUT_ATTR
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate 
108958Sjfrank /*
109958Sjfrank  * The I2C bus is noisy, and the state may be incorrectly reported as
110958Sjfrank  * having changed.  When the state changes, we attempt to confirm by
111958Sjfrank  * retrying.  If any retries indicate that the state has not changed, we
112958Sjfrank  * assume the state change(s) were incorrect and the state has not changed.
113958Sjfrank  * The following variables are used to store the tuneable values read in
114958Sjfrank  * from the optional i2cparam.conf file for this shared object library.
115958Sjfrank  */
116958Sjfrank static int n_read_temp = PSVC_THRESHOLD_COUNTER;
117958Sjfrank static int n_retry_keyswitch = PSVC_NUM_OF_RETRIES;
118958Sjfrank static int retry_sleep_keyswitch = 1;
119958Sjfrank static int n_retry_hotplug = PSVC_NUM_OF_RETRIES;
120958Sjfrank static int retry_sleep_hotplug = 1;
121958Sjfrank static int n_retry_fan_hotplug = PSVC_NUM_OF_RETRIES;
122958Sjfrank static int retry_sleep_fan_hotplug = 1;
123958Sjfrank static int n_retry_fan_present = PSVC_NUM_OF_RETRIES;
124958Sjfrank static int retry_sleep_fan_present = 1;
125958Sjfrank 
126958Sjfrank typedef struct {
127958Sjfrank 	int *pvar;
128958Sjfrank 	char *texttag;
129958Sjfrank } i2c_noise_param_t;
130958Sjfrank 
131958Sjfrank static i2c_noise_param_t i2cparams_sun4u[] = {
132958Sjfrank 	&n_read_temp, "n_read_temp",
133958Sjfrank 	&n_retry_keyswitch, "n_retry_keyswitch",
134958Sjfrank 	&retry_sleep_keyswitch, "retry_sleep_keyswitch",
135958Sjfrank 	&n_retry_hotplug, "n_retry_hotplug",
136958Sjfrank 	&retry_sleep_hotplug, "retry_sleep_hotplug",
137958Sjfrank 	&n_retry_fan_hotplug, "n_retry_fan_hotplug",
138958Sjfrank 	&retry_sleep_fan_hotplug, "retry_sleep_fan_hotplug",
139958Sjfrank 	&n_retry_fan_present, "n_retry_fan_present",
140958Sjfrank 	&retry_sleep_fan_present, "retry_sleep_fan_present",
141958Sjfrank 	NULL, NULL
142958Sjfrank };
143958Sjfrank 
144958Sjfrank #pragma init(i2cparams_sun4u_load)
145958Sjfrank 
146958Sjfrank static void
i2cparams_sun4u_debug(i2c_noise_param_t * pi2cparams,int usingDefaults)147958Sjfrank i2cparams_sun4u_debug(i2c_noise_param_t *pi2cparams, int usingDefaults)
148958Sjfrank {
149958Sjfrank 	char s[128];
150958Sjfrank 	i2c_noise_param_t *p;
151958Sjfrank 
152958Sjfrank 	if (!usingDefaults) {
153958Sjfrank 		(void) strncpy(s,
154958Sjfrank 		    "# Values from /usr/platform/sun4u/lib/i2cparam.conf\n",
155958Sjfrank 			sizeof (s) - 1);
156958Sjfrank 		syslog(LOG_WARNING, "%s", s);
157958Sjfrank 	} else {
158958Sjfrank 		/* no file - we're using the defaults */
159958Sjfrank 		(void) strncpy(s,
160958Sjfrank "# No /usr/platform/sun4u/lib/i2cparam.conf file, using defaults\n",
161958Sjfrank 			sizeof (s) - 1);
162958Sjfrank 	}
163958Sjfrank 	(void) fputs(s, stdout);
164958Sjfrank 	p = pi2cparams;
165958Sjfrank 	while (p->pvar != NULL) {
166958Sjfrank 		(void) snprintf(s, sizeof (s), "%s %d\n", p->texttag,
167958Sjfrank 		    *(p->pvar));
168958Sjfrank 		if (!usingDefaults)
169958Sjfrank 			syslog(LOG_WARNING, "%s", s);
170958Sjfrank 		(void) fputs(s, stdout);
171958Sjfrank 		p++;
172958Sjfrank 	}
173958Sjfrank }
174958Sjfrank 
175958Sjfrank static void
i2cparams_sun4u_load(void)176958Sjfrank i2cparams_sun4u_load(void)
177958Sjfrank {
178958Sjfrank 	FILE *fp;
179958Sjfrank 	char *filename = "/usr/platform/sun4u/lib/i2cparam.conf";
180958Sjfrank 	char s[128];
181958Sjfrank 	char var[128];
182958Sjfrank 	int val;
183958Sjfrank 	i2c_noise_param_t *p;
184958Sjfrank 
185958Sjfrank 	/* read thru the i2cparam.conf file and set variables */
186958Sjfrank 	if ((fp = fopen(filename, "r")) != NULL) {
187958Sjfrank 		while (fgets(s, sizeof (s), fp) != NULL) {
188958Sjfrank 			if (s[0] == '#') /* skip comment lines */
189958Sjfrank 				continue;
190958Sjfrank 			/* try to find a string match and get the value */
191958Sjfrank 			if (sscanf(s, "%127s %d", var, &val) != 2)
192958Sjfrank 				continue;
193958Sjfrank 			if (val < 1)
194958Sjfrank 				val = 1;  /* clamp min value */
195958Sjfrank 			p = &(i2cparams_sun4u[0]);
196958Sjfrank 			while (p->pvar != NULL) {
197958Sjfrank 				if (strncmp(p->texttag, var, sizeof (var)) ==
198958Sjfrank 				    0) {
199958Sjfrank 					*(p->pvar) = val;
200958Sjfrank 					break;
201958Sjfrank 				}
202958Sjfrank 				p++;
203958Sjfrank 			}
204958Sjfrank 		}
205958Sjfrank 		(void) fclose(fp);
206958Sjfrank 	}
207958Sjfrank 	/* output the values of the parameters */
208958Sjfrank 	i2cparams_sun4u_debug(&(i2cparams_sun4u[0]), ((fp == NULL)? 1 : 0));
209958Sjfrank }
210958Sjfrank 
211958Sjfrank 
2120Sstevel@tonic-gate int32_t
psvc_update_thresholds_0(psvc_opaque_t hdlp,char * id)2130Sstevel@tonic-gate psvc_update_thresholds_0(psvc_opaque_t hdlp, char *id)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
2160Sstevel@tonic-gate 	fru_info_t fru_data;
2170Sstevel@tonic-gate 	char *fru, seg_name[2];
2180Sstevel@tonic-gate 	int8_t seg_count, temp_array[8];
2190Sstevel@tonic-gate 	int32_t match_count, i, j, seg_desc_start = 0x1806, temp_address;
2200Sstevel@tonic-gate 	int32_t seg_found, temp;
2210Sstevel@tonic-gate 	boolean_t present;
2220Sstevel@tonic-gate 	seg_desc_t segment;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
2250Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (present != PSVC_PRESENT))
2260Sstevel@tonic-gate 		return (status);
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &match_count,
2290Sstevel@tonic-gate 	    PSVC_FRU);
2300Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
2310Sstevel@tonic-gate 		return (status);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	for (i = 0; i < match_count; i++) {
2340Sstevel@tonic-gate 		seg_found = 0;
2350Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
2360Sstevel@tonic-gate 		    &fru, PSVC_FRU, i);
2370Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
2380Sstevel@tonic-gate 			return (status);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 		fru_data.buf_start = 0x1805;
2410Sstevel@tonic-gate 		fru_data.buf = (char *)&seg_count;
2420Sstevel@tonic-gate 		fru_data.read_size = 1;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
2450Sstevel@tonic-gate 		    &fru_data);
2460Sstevel@tonic-gate 		if (status != PSVC_SUCCESS) {
2470Sstevel@tonic-gate 			return (status);
2480Sstevel@tonic-gate 		}
2490Sstevel@tonic-gate 		for (j = 0; (j < seg_count) && (!seg_found); j++) {
2500Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
2510Sstevel@tonic-gate 			fru_data.buf = seg_name;
2520Sstevel@tonic-gate 			fru_data.read_size = 2;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
2550Sstevel@tonic-gate 			    &fru_data);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + 2;
2580Sstevel@tonic-gate 			fru_data.buf_start = seg_desc_start;
2590Sstevel@tonic-gate 			fru_data.buf = (char *)&segment;
2600Sstevel@tonic-gate 			fru_data.read_size = sizeof (seg_desc_t);
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
2630Sstevel@tonic-gate 			    &fru_data);
2640Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
2650Sstevel@tonic-gate 				syslog(LOG_ERR,
2660Sstevel@tonic-gate 				    "Failed psvc_get_attr for FRU info\n");
2670Sstevel@tonic-gate 				return (status);
2680Sstevel@tonic-gate 			}
2690Sstevel@tonic-gate 			seg_desc_start = seg_desc_start + sizeof (seg_desc_t);
2700Sstevel@tonic-gate 			if (memcmp(seg_name, "SC", 2) == 0)
2710Sstevel@tonic-gate 				seg_found = 1;
2720Sstevel@tonic-gate 		}
2730Sstevel@tonic-gate 		if (seg_found) {
2740Sstevel@tonic-gate 			temp_address = segment.segoffset + TEMP_OFFSET;
2750Sstevel@tonic-gate 			fru_data.buf_start = temp_address;
2760Sstevel@tonic-gate 			fru_data.buf = (char *)&temp_array;
2770Sstevel@tonic-gate 			fru_data.read_size = sizeof (temp_array);
2780Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, fru, PSVC_FRU_INFO_ATTR,
2790Sstevel@tonic-gate 			    &fru_data);
2800Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
2810Sstevel@tonic-gate 				syslog(LOG_ERR,
2820Sstevel@tonic-gate 				    "Failed psvc_get_attr for FRU info\n");
2830Sstevel@tonic-gate 				return (status);
2840Sstevel@tonic-gate 			} else {
2850Sstevel@tonic-gate 				for (j = 0; j < sizeof (temp_array); j++) {
2860Sstevel@tonic-gate 					if (threshold_names[j] == PSVC_NOT_USED)
2870Sstevel@tonic-gate 						continue;
2880Sstevel@tonic-gate 					temp = temp_array[j];
2890Sstevel@tonic-gate 					status = psvc_set_attr(hdlp, id,
2900Sstevel@tonic-gate 					    threshold_names[j], &temp);
2910Sstevel@tonic-gate 					if (status != PSVC_SUCCESS) {
2920Sstevel@tonic-gate 						return (status);
2930Sstevel@tonic-gate 					}
2940Sstevel@tonic-gate 				}
2950Sstevel@tonic-gate 			}
2960Sstevel@tonic-gate 		} else {
2970Sstevel@tonic-gate 			syslog(LOG_ERR, "No FRU Information for %s"
2980Sstevel@tonic-gate 			    " using default temperatures\n", id);
2990Sstevel@tonic-gate 		}
3000Sstevel@tonic-gate 	}
3010Sstevel@tonic-gate 	return (status);
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate #define	MAX_TEMP_SENSORS	256
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate static int32_t
check_temp(psvc_opaque_t hdlp,char * id,int32_t silent)3070Sstevel@tonic-gate check_temp(psvc_opaque_t hdlp, char *id, int32_t silent)
3080Sstevel@tonic-gate {
3090Sstevel@tonic-gate 	int32_t		lo_warn, hi_warn, lo_shut, hi_shut;
3100Sstevel@tonic-gate 	uint64_t	features;
3110Sstevel@tonic-gate 	int32_t		temp;
3120Sstevel@tonic-gate 	char		previous_state[32];
3130Sstevel@tonic-gate 	char		led_state[32];
3140Sstevel@tonic-gate 	char		state[32];
3150Sstevel@tonic-gate 	char		fault[32];
3160Sstevel@tonic-gate 	char		label[32];
3170Sstevel@tonic-gate 	boolean_t	pr;
3180Sstevel@tonic-gate 	int32_t		status = PSVC_SUCCESS;
3190Sstevel@tonic-gate 	int8_t		fail = 0;
320958Sjfrank 	static int	threshold_low_shut[MAX_TEMP_SENSORS] = {0};
321958Sjfrank 	static int	threshold_high_shut[MAX_TEMP_SENSORS] = {0};
322958Sjfrank 	static int	threshold_low_warn[MAX_TEMP_SENSORS] = {0};
323958Sjfrank 	static int	threshold_high_warn[MAX_TEMP_SENSORS] = {0};
3240Sstevel@tonic-gate 	int32_t		instance;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_INSTANCE_ATTR, &instance);
3270Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3280Sstevel@tonic-gate 		return (status);
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &pr);
3310Sstevel@tonic-gate 	if ((status != PSVC_SUCCESS) || (pr != PSVC_PRESENT)) {
3320Sstevel@tonic-gate 		return (status);
3330Sstevel@tonic-gate 	}
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, state);
3360Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
3370Sstevel@tonic-gate 		return (status);
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	if ((strcmp(state, PSVC_HOTPLUGGED) == 0)) {
3400Sstevel@tonic-gate 		return (PSVC_SUCCESS);
3410Sstevel@tonic-gate 	}
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_FEATURES_ATTR, &features);
3440Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3450Sstevel@tonic-gate 		return (status);
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_LO_WARN_ATTR, &lo_warn);
3480Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3490Sstevel@tonic-gate 		return (status);
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_LO_SHUT_ATTR, &lo_shut);
3520Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3530Sstevel@tonic-gate 		return (status);
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_HI_WARN_ATTR, &hi_warn);
3560Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3570Sstevel@tonic-gate 		return (status);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_HI_SHUT_ATTR, &hi_shut);
3600Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3610Sstevel@tonic-gate 		return (status);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_SENSOR_VALUE_ATTR, &temp);
3640Sstevel@tonic-gate 	if (status != PSVC_SUCCESS) {
3650Sstevel@tonic-gate 		return (status);
3660Sstevel@tonic-gate 	}
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	/*
3690Sstevel@tonic-gate 	 * The following code is to check to see if the temp sensor is
3700Sstevel@tonic-gate 	 * returning a faulty reading due to it either being bad or the
3710Sstevel@tonic-gate 	 * CPU being powered off for some reason. Is so we will alert the user
3720Sstevel@tonic-gate 	 * and just label the sensor bad but not the WHOLE CPU module.
3730Sstevel@tonic-gate 	 */
3740Sstevel@tonic-gate 	if ((temp == 127) && (strcmp(state, PSVC_ERROR) != 0)) {
3750Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, PSVC_ERROR);
3760Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
3770Sstevel@tonic-gate 			return (status);
3780Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR,
3790Sstevel@tonic-gate 		    PSVC_GEN_FAULT);
3800Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
3810Sstevel@tonic-gate 			return (status);
3820Sstevel@tonic-gate 		syslog(LOG_ERR, TEMP_SENSOR_FAULT, id);
3830Sstevel@tonic-gate 		return (status);
3840Sstevel@tonic-gate 	}
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, label);
3870Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
3880Sstevel@tonic-gate 		return (status);
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	/*
3910Sstevel@tonic-gate 	 * if any of the four temperature states (lo_shut, lo_warn,
3920Sstevel@tonic-gate 	 * hi_shut, hi_warn) is detected we will not take an action
393958Sjfrank 	 * until the number of similar back-to-back readings equals
394958Sjfrank 	 * 'n_read_temp' (default is PSVC_THRESHOLD_COUNTER).
3950Sstevel@tonic-gate 	 */
3960Sstevel@tonic-gate 	if ((features & PSVC_LOW_SHUT) && temp < lo_shut) {
3970Sstevel@tonic-gate 		/*
3980Sstevel@tonic-gate 		 * once we are in one state, clear all the
3990Sstevel@tonic-gate 		 * counters for the other three states since
4000Sstevel@tonic-gate 		 * back-to-back readings of these other three
4010Sstevel@tonic-gate 		 * states could not happen anymore.
4020Sstevel@tonic-gate 		 */
4030Sstevel@tonic-gate 		threshold_low_warn[instance] = 0;
4040Sstevel@tonic-gate 		threshold_high_shut[instance] = 0;
4050Sstevel@tonic-gate 		threshold_high_warn[instance] = 0;
4060Sstevel@tonic-gate 		threshold_low_shut[instance]++;
407958Sjfrank 		if (threshold_low_shut[instance] == n_read_temp) {
4080Sstevel@tonic-gate 			threshold_low_shut[instance] = 0;
4090Sstevel@tonic-gate 			fail = 1;
4100Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
4110Sstevel@tonic-gate 			strcpy(fault, PSVC_TEMP_LO_SHUT);
4120Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_ON);
4130Sstevel@tonic-gate 			if (silent == 0)
4140Sstevel@tonic-gate 				syslog(LOG_ERR, LOWTEMP_CRITICAL_MSG,
4150Sstevel@tonic-gate 				    temp, label);
4160Sstevel@tonic-gate 		} else { /* Threshold for showing error not reached */
4170Sstevel@tonic-gate 			return (PSVC_SUCCESS);
4180Sstevel@tonic-gate 		}
4190Sstevel@tonic-gate 	} else if ((features & PSVC_LOW_WARN) && temp < lo_warn) {
4200Sstevel@tonic-gate 		threshold_low_shut[instance] = 0;
4210Sstevel@tonic-gate 		threshold_high_shut[instance] = 0;
4220Sstevel@tonic-gate 		threshold_high_warn[instance] = 0;
4230Sstevel@tonic-gate 		threshold_low_warn[instance]++;
424958Sjfrank 		if (threshold_low_warn[instance] == n_read_temp) {
4250Sstevel@tonic-gate 			threshold_low_warn[instance] = 0;
4260Sstevel@tonic-gate 			fail = 1;
4270Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
4280Sstevel@tonic-gate 			strcpy(fault, PSVC_TEMP_LO_WARN);
4290Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_ON);
4300Sstevel@tonic-gate 			if (silent == 0)
4310Sstevel@tonic-gate 				syslog(LOG_ERR, LOWTEMP_WARNING_MSG,
4320Sstevel@tonic-gate 				    temp, label);
4330Sstevel@tonic-gate 		} else { /* Threshold for showing error not reached */
4340Sstevel@tonic-gate 			return (PSVC_SUCCESS);
4350Sstevel@tonic-gate 		}
4360Sstevel@tonic-gate 	} else if ((features & PSVC_HIGH_SHUT) && temp > hi_shut) {
4370Sstevel@tonic-gate 		threshold_low_warn[instance] = 0;
4380Sstevel@tonic-gate 		threshold_low_shut[instance] = 0;
4390Sstevel@tonic-gate 		threshold_high_warn[instance] = 0;
4400Sstevel@tonic-gate 		threshold_high_shut[instance]++;
441958Sjfrank 		if (threshold_high_shut[instance] == n_read_temp) {
4420Sstevel@tonic-gate 			threshold_high_shut[instance] = 0;
4430Sstevel@tonic-gate 			fail = 1;
4440Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
4450Sstevel@tonic-gate 			strcpy(fault, PSVC_TEMP_HI_SHUT);
4460Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_ON);
4470Sstevel@tonic-gate 			if (silent == 0)
4480Sstevel@tonic-gate 				syslog(LOG_ERR, HIGHTEMP_CRITICAL_MSG,
4490Sstevel@tonic-gate 				    temp, label);
4500Sstevel@tonic-gate 		} else { /* Threshold for showing error not reached */
4510Sstevel@tonic-gate 			return (PSVC_SUCCESS);
4520Sstevel@tonic-gate 		}
4530Sstevel@tonic-gate 	} else if ((features & PSVC_HIGH_WARN) && temp > hi_warn) {
4540Sstevel@tonic-gate 		threshold_low_warn[instance] = 0;
4550Sstevel@tonic-gate 		threshold_low_shut[instance] = 0;
4560Sstevel@tonic-gate 		threshold_high_shut[instance] = 0;
4570Sstevel@tonic-gate 		threshold_high_warn[instance]++;
458958Sjfrank 		if (threshold_high_warn[instance] == n_read_temp) {
4590Sstevel@tonic-gate 			threshold_high_warn[instance] = 0;
4600Sstevel@tonic-gate 			fail = 1;
4610Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
4620Sstevel@tonic-gate 			strcpy(fault, PSVC_TEMP_HI_WARN);
4630Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_ON);
4640Sstevel@tonic-gate 			if (silent == 0)
4650Sstevel@tonic-gate 				syslog(LOG_ERR, HIGHTEMP_WARNING_MSG,
4660Sstevel@tonic-gate 				    temp, label);
4670Sstevel@tonic-gate 		} else { /* Threshold for showing error not reached */
4680Sstevel@tonic-gate 			return (PSVC_SUCCESS);
4690Sstevel@tonic-gate 		}
4700Sstevel@tonic-gate 	}
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	/*
4730Sstevel@tonic-gate 	 * If we reached this point then that means that we are either
474958Sjfrank 	 * okay, or we have showed error n_read_temp times.
4750Sstevel@tonic-gate 	 */
4760Sstevel@tonic-gate 	if (fail != 1) {
4770Sstevel@tonic-gate 		/* within limits */
4780Sstevel@tonic-gate 		strcpy(state, PSVC_OK);
4790Sstevel@tonic-gate 		strcpy(fault, PSVC_NO_FAULT);
4800Sstevel@tonic-gate 		strcpy(led_state, PSVC_LED_OFF);
4810Sstevel@tonic-gate 	}
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
4840Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
4850Sstevel@tonic-gate 		return (status);
4860Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR, fault);
4870Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
4880Sstevel@tonic-gate 		return (status);
4890Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PREV_STATE_ATTR,
4900Sstevel@tonic-gate 		previous_state);
4910Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
4920Sstevel@tonic-gate 		return (status);
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 	if (strcmp(previous_state, state) != 0) {
4950Sstevel@tonic-gate 		char *led_id;
4960Sstevel@tonic-gate 		int32_t led_count;
4970Sstevel@tonic-gate 		int32_t i;
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 		/* change state of fault LEDs */
5000Sstevel@tonic-gate 		psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &led_count,
5010Sstevel@tonic-gate 			PSVC_TS_OVERTEMP_LED);
5020Sstevel@tonic-gate 		for (i = 0; i < led_count; ++i) {
5030Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id,
5040Sstevel@tonic-gate 				PSVC_ASSOC_ID_ATTR, &led_id,
5050Sstevel@tonic-gate 				PSVC_TS_OVERTEMP_LED, i);
5060Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
5070Sstevel@tonic-gate 				return (status);
5080Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, led_id,
5090Sstevel@tonic-gate 				PSVC_LED_STATE_ATTR, led_state);
5100Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
5110Sstevel@tonic-gate 				return (status);
5120Sstevel@tonic-gate 		}
5130Sstevel@tonic-gate 	}
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	return (PSVC_SUCCESS);
5160Sstevel@tonic-gate }
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate int32_t
psvc_check_temperature_policy_0(psvc_opaque_t hdlp,char * id)5190Sstevel@tonic-gate psvc_check_temperature_policy_0(psvc_opaque_t hdlp, char *id)
5200Sstevel@tonic-gate {
5210Sstevel@tonic-gate 	return (check_temp(hdlp, id, 0));
5220Sstevel@tonic-gate }
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate int32_t
psvc_check_temperature_silent_policy_0(psvc_opaque_t hdlp,char * id)5250Sstevel@tonic-gate psvc_check_temperature_silent_policy_0(psvc_opaque_t hdlp, char *id)
5260Sstevel@tonic-gate {
5270Sstevel@tonic-gate 	return (check_temp(hdlp, id, 1));
5280Sstevel@tonic-gate }
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate int32_t
psvc_fan_enable_disable_policy_0(psvc_opaque_t hdlp,char * id)5310Sstevel@tonic-gate psvc_fan_enable_disable_policy_0(psvc_opaque_t hdlp, char *id)
5320Sstevel@tonic-gate {
5330Sstevel@tonic-gate 	char state[32], previous_state[32];
5340Sstevel@tonic-gate 	char *backup_fan;
5350Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
5360Sstevel@tonic-gate 	uint64_t features;
5370Sstevel@tonic-gate 	char label[32];
5380Sstevel@tonic-gate 	boolean_t presence;
5390Sstevel@tonic-gate 	boolean_t enable;
540958Sjfrank 	int retry;
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_FEATURES_ATTR, &features);
5430Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
5440Sstevel@tonic-gate 		return (status);
5450Sstevel@tonic-gate 
546958Sjfrank 	retry = 0;
547958Sjfrank 	do {
548958Sjfrank 		if (retry)
549958Sjfrank 			(void) sleep(retry_sleep_fan_present);
550958Sjfrank 
551958Sjfrank 		status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &presence);
552958Sjfrank 		if (status != PSVC_SUCCESS)
553958Sjfrank 			return (status);
554958Sjfrank 		retry++;
555958Sjfrank 	} while ((retry < n_retry_fan_present) && (presence == PSVC_ABSENT));
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	if (presence == PSVC_ABSENT) {
5580Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, label);
5590Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
5600Sstevel@tonic-gate 			return (status);
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ENABLE_ATTR, &enable);
5630Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
5640Sstevel@tonic-gate 			return (status);
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 		if (features & PSVC_DEV_PRIMARY) {
5670Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
5680Sstevel@tonic-gate 				&backup_fan, PSVC_ALTERNATE, 0);
5690Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
5700Sstevel@tonic-gate 				return (status);
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate 			enable = PSVC_DISABLED;
5730Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_ENABLE_ATTR,
5740Sstevel@tonic-gate 				&enable);
5750Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
5760Sstevel@tonic-gate 				return (status);
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate 			enable = PSVC_ENABLED;
5790Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, backup_fan,
5800Sstevel@tonic-gate 				PSVC_ENABLE_ATTR, &enable);
5810Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
5820Sstevel@tonic-gate 				return (status);
5830Sstevel@tonic-gate 		} else {
5840Sstevel@tonic-gate 			enable = PSVC_DISABLED;
5850Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_ENABLE_ATTR,
5860Sstevel@tonic-gate 				&enable);
5870Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
5880Sstevel@tonic-gate 				return (status);
5890Sstevel@tonic-gate 		}
5900Sstevel@tonic-gate 		return (PSVC_SUCCESS);
5910Sstevel@tonic-gate 	}
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	/* device was present */
5940Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR, state);
5950Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
5960Sstevel@tonic-gate 		return (status);
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PREV_STATE_ATTR, previous_state);
5990Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
6000Sstevel@tonic-gate 		return (status);
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate 	if (features & PSVC_DEV_PRIMARY) {
6030Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
6040Sstevel@tonic-gate 			&backup_fan, PSVC_ALTERNATE, 0);
6050Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
6060Sstevel@tonic-gate 			return (status);
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate 		if (strcmp(state, PSVC_OK) == 0) {
6090Sstevel@tonic-gate 			enable = PSVC_ENABLED;
6100Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_ENABLE_ATTR,
6110Sstevel@tonic-gate 				&enable);
6120Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6130Sstevel@tonic-gate 				return (status);
6140Sstevel@tonic-gate 
6150Sstevel@tonic-gate 			enable = PSVC_DISABLED;
6160Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, backup_fan,
6170Sstevel@tonic-gate 				PSVC_ENABLE_ATTR, &enable);
6180Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6190Sstevel@tonic-gate 				return (status);
6200Sstevel@tonic-gate 		}
6210Sstevel@tonic-gate 		if ((strcmp(state, PSVC_ERROR) == 0) &&
6220Sstevel@tonic-gate 			(strcmp(previous_state, PSVC_ERROR) != 0)) {
6230Sstevel@tonic-gate 			enable = PSVC_DISABLED;
6240Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_ENABLE_ATTR,
6250Sstevel@tonic-gate 				&enable);
6260Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6270Sstevel@tonic-gate 				return (status);
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 			enable = PSVC_ENABLED;
6300Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, backup_fan,
6310Sstevel@tonic-gate 				PSVC_ENABLE_ATTR, &enable);
6320Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6330Sstevel@tonic-gate 				return (status);
6340Sstevel@tonic-gate 		}
6350Sstevel@tonic-gate 	} else {
6360Sstevel@tonic-gate 		if ((strcmp(state, PSVC_ERROR) == 0) &&
6370Sstevel@tonic-gate 			(strcmp(previous_state, PSVC_ERROR) != 0)) {
6380Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR,
6390Sstevel@tonic-gate 				label);
6400Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
6410Sstevel@tonic-gate 				return (status);
6420Sstevel@tonic-gate 			syslog(LOG_ERR, SECONDARY_FAN_FAIL_MSG, label);
6430Sstevel@tonic-gate 		}
6440Sstevel@tonic-gate 	}
6450Sstevel@tonic-gate 	return (status);
6460Sstevel@tonic-gate }
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate /*
6490Sstevel@tonic-gate  * psvc_switch_fan_onoff_policy_0
6500Sstevel@tonic-gate  * Turn a fan on if it is enabled, turn it off if it is disabled.
6510Sstevel@tonic-gate  */
6520Sstevel@tonic-gate int32_t
psvc_switch_fan_onoff_policy_0(psvc_opaque_t hdlp,char * id)6530Sstevel@tonic-gate psvc_switch_fan_onoff_policy_0(psvc_opaque_t hdlp, char *id)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate 	boolean_t enable;
6560Sstevel@tonic-gate 	char *switchid;
6570Sstevel@tonic-gate 	char state[32];
6580Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ENABLE_ATTR, &enable);
6610Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
6620Sstevel@tonic-gate 		return (status);
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR, &switchid,
6650Sstevel@tonic-gate 		PSVC_FAN_ONOFF_SENSOR, 0);
6660Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
6670Sstevel@tonic-gate 		return (status);
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate 	if (enable == PSVC_DISABLED) {
6700Sstevel@tonic-gate 		strcpy(state, PSVC_SWITCH_OFF);
6710Sstevel@tonic-gate 	} else {
6720Sstevel@tonic-gate 		strcpy(state, PSVC_SWITCH_ON);
6730Sstevel@tonic-gate 	}
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, switchid, PSVC_SWITCH_STATE_ATTR, state);
6760Sstevel@tonic-gate 	return (status);
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate static int32_t
check_cpu_temp_fault(psvc_opaque_t hdlp,char * cpu,int32_t cpu_count)6800Sstevel@tonic-gate check_cpu_temp_fault(psvc_opaque_t hdlp, char *cpu, int32_t cpu_count)
6810Sstevel@tonic-gate {
6820Sstevel@tonic-gate 	char *sensorid;
6830Sstevel@tonic-gate 	int32_t sensor_count;
6840Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
6850Sstevel@tonic-gate 	int32_t i;
6860Sstevel@tonic-gate 	uint64_t features;
6870Sstevel@tonic-gate 	char fault[32];
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, cpu, PSVC_FEATURES_ATTR, &features);
6900Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
6910Sstevel@tonic-gate 		return (status);
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate 	psvc_get_attr(hdlp, cpu, PSVC_ASSOC_MATCHES_ATTR, &sensor_count,
6940Sstevel@tonic-gate 		PSVC_DEV_TEMP_SENSOR);
6950Sstevel@tonic-gate 	for (i = 0; i < sensor_count; ++i) {
6960Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, cpu, PSVC_ASSOC_ID_ATTR,
6970Sstevel@tonic-gate 			&sensorid, PSVC_DEV_TEMP_SENSOR, i);
6980Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
6990Sstevel@tonic-gate 			return (status);
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensorid, PSVC_FAULTID_ATTR,
7020Sstevel@tonic-gate 			fault);
7030Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
7040Sstevel@tonic-gate 			return (status);
7050Sstevel@tonic-gate 
7060Sstevel@tonic-gate 		if ((strcmp(fault, PSVC_TEMP_HI_SHUT) == 0) ||
7070Sstevel@tonic-gate 			(strcmp(fault, PSVC_TEMP_LO_SHUT) == 0)) {
7080Sstevel@tonic-gate 			if (cpu_count == 1 || cpus_online == 1 ||
7090Sstevel@tonic-gate 			    !(features & PSVC_DEV_HOTPLUG)) {
7100Sstevel@tonic-gate 				system(shutdown_string);
7110Sstevel@tonic-gate 			} else {
7120Sstevel@tonic-gate 				/* FIX offline cpu */
7130Sstevel@tonic-gate 				--cpus_online;
7140Sstevel@tonic-gate 			}
7150Sstevel@tonic-gate 		}
7160Sstevel@tonic-gate 	}
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate 	return (status);
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate int32_t
psvc_shutdown_policy_0(psvc_opaque_t hdlp,char * id)7220Sstevel@tonic-gate psvc_shutdown_policy_0(psvc_opaque_t hdlp, char *id)
7230Sstevel@tonic-gate {
7240Sstevel@tonic-gate 	int32_t cpu_count;
7250Sstevel@tonic-gate 	char *cpuid;
7260Sstevel@tonic-gate 	int32_t i;
7270Sstevel@tonic-gate 	boolean_t present;
7280Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 	if (cpus_online == 0) {
7310Sstevel@tonic-gate 		/* obviously, zero isn't correct, count present cpu's */
7320Sstevel@tonic-gate 		psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &cpu_count,
7330Sstevel@tonic-gate 			PSVC_CPU);
7340Sstevel@tonic-gate 		for (i = 0; i < cpu_count; ++i) {
7350Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
7360Sstevel@tonic-gate 				&cpuid, PSVC_CPU, i);
7370Sstevel@tonic-gate 			if (status == PSVC_FAILURE)
7380Sstevel@tonic-gate 				return (status);
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, cpuid,
7410Sstevel@tonic-gate 				PSVC_PRESENCE_ATTR, &present);
7420Sstevel@tonic-gate 			if (status == PSVC_FAILURE && present == PSVC_PRESENT)
7430Sstevel@tonic-gate 				return (status);
7440Sstevel@tonic-gate 			if (present == PSVC_PRESENT)
7450Sstevel@tonic-gate 				++cpus_online;
7460Sstevel@tonic-gate 		}
7470Sstevel@tonic-gate 	}
7480Sstevel@tonic-gate 	psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &cpu_count,
7490Sstevel@tonic-gate 		PSVC_CPU);
7500Sstevel@tonic-gate 	for (i = 0; i < cpu_count; ++i) {
7510Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR, &cpuid,
7520Sstevel@tonic-gate 			PSVC_CPU, i);
7530Sstevel@tonic-gate 		if (status == PSVC_FAILURE)
7540Sstevel@tonic-gate 			return (status);
7550Sstevel@tonic-gate 		status = check_cpu_temp_fault(hdlp, cpuid, cpu_count);
7560Sstevel@tonic-gate 		if (status == PSVC_FAILURE && errno != ENODEV)
7570Sstevel@tonic-gate 			return (status);
7580Sstevel@tonic-gate 	}
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 	return (PSVC_SUCCESS);
7610Sstevel@tonic-gate }
7620Sstevel@tonic-gate 
7630Sstevel@tonic-gate /*
7640Sstevel@tonic-gate  * psvc_keyswitch_position_policy_0
7650Sstevel@tonic-gate  * Checks the state of the keyswitch sensors.
7660Sstevel@tonic-gate  * If a keyswitch position sensor's state is on, the position
7670Sstevel@tonic-gate  * of the key is written to syslog.  If none of the sensors
7680Sstevel@tonic-gate  * are on (keyswitch is not at one of the detents), a message is sent
7690Sstevel@tonic-gate  * to syslog stating that the position is unknown.
7700Sstevel@tonic-gate  */
7710Sstevel@tonic-gate int32_t
psvc_keyswitch_position_policy_0(psvc_opaque_t hdlp,char * id)7720Sstevel@tonic-gate psvc_keyswitch_position_policy_0(psvc_opaque_t hdlp, char *id)
7730Sstevel@tonic-gate {
7740Sstevel@tonic-gate 	char position[32];
7750Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
7760Sstevel@tonic-gate 	static int error_reported = 0;
7770Sstevel@tonic-gate 	static char local_previous_position[32];
7780Sstevel@tonic-gate 	static int32_t first_time = 1;
779958Sjfrank 	int retry;
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate 	if (first_time) {
7820Sstevel@tonic-gate 		first_time = 0;
7830Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_STATE_ATTR,
7840Sstevel@tonic-gate 		    local_previous_position);
7850Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
7860Sstevel@tonic-gate 			return (status);
7870Sstevel@tonic-gate 	}
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 	retry = 0;
7900Sstevel@tonic-gate 	do {
7910Sstevel@tonic-gate 		if (retry)
792958Sjfrank 			(void) sleep(retry_sleep_keyswitch);
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_SWITCH_STATE_ATTR,
7950Sstevel@tonic-gate 		    position);
7960Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
7970Sstevel@tonic-gate 			return (status);
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 		if (strcmp(position, PSVC_ERROR) == 0) {
8000Sstevel@tonic-gate 			if ((errno == EINVAL) && (!(error_reported))) {
8010Sstevel@tonic-gate 				syslog(LOG_ERR,
8020Sstevel@tonic-gate 				    KEYSWITCH_POS_READ_FAILED_MSG);
8030Sstevel@tonic-gate 				error_reported = 1;
8040Sstevel@tonic-gate 				return (PSVC_SUCCESS);
8050Sstevel@tonic-gate 			}
8060Sstevel@tonic-gate 		}
8070Sstevel@tonic-gate 		retry++;
808958Sjfrank 	} while ((retry < n_retry_keyswitch) &&
8090Sstevel@tonic-gate 	    (strcmp(position, local_previous_position) != 0));
8100Sstevel@tonic-gate 
8110Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, position);
8120Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
8130Sstevel@tonic-gate 		return (status);
8140Sstevel@tonic-gate 
8150Sstevel@tonic-gate 	if (strcmp(position, local_previous_position) != 0) {
8160Sstevel@tonic-gate 		error_reported = 0;
8170Sstevel@tonic-gate 		strcpy(local_previous_position, position);
8180Sstevel@tonic-gate 		syslog(LOG_ERR, KEYSWITCH_POS_CHANGED_MSG, position);
8190Sstevel@tonic-gate 	}
8200Sstevel@tonic-gate 
8210Sstevel@tonic-gate 	return (status);
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate int32_t
psvc_hotplug_notifier_policy_0(psvc_opaque_t hdlp,char * id)8250Sstevel@tonic-gate psvc_hotplug_notifier_policy_0(psvc_opaque_t hdlp, char *id)
8260Sstevel@tonic-gate {
8270Sstevel@tonic-gate 	boolean_t presence, previous_presence;
8280Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
8290Sstevel@tonic-gate 	char label[32];
830958Sjfrank 	int retry;
8310Sstevel@tonic-gate 
8320Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR,
8330Sstevel@tonic-gate 		&previous_presence);
8340Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
8350Sstevel@tonic-gate 		return (status);
836958Sjfrank 
8370Sstevel@tonic-gate 	retry = 0;
8380Sstevel@tonic-gate 	do {
8390Sstevel@tonic-gate 		if (retry)
840958Sjfrank 			(void) sleep(retry_sleep_hotplug);
8410Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &presence);
8420Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
8430Sstevel@tonic-gate 			return (status);
8440Sstevel@tonic-gate 		retry++;
845958Sjfrank 	} while ((retry < n_retry_hotplug) &&
8460Sstevel@tonic-gate 	    (presence != previous_presence));
8470Sstevel@tonic-gate 
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate 	if (presence != previous_presence) {
8500Sstevel@tonic-gate 		char parent_path[256];
8510Sstevel@tonic-gate 		picl_nodehdl_t child_node;
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, label);
8540Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
8550Sstevel@tonic-gate 			return (status);
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate 		/* return parent path and node for an object */
8580Sstevel@tonic-gate 		psvcplugin_lookup(id, parent_path, &child_node);
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 		if (presence == PSVC_PRESENT) {
8610Sstevel@tonic-gate 			char state[32], fault[32];
8620Sstevel@tonic-gate 			picl_nodehdl_t parent_node;
8630Sstevel@tonic-gate 
8640Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_INSERTED_MSG, label);
8650Sstevel@tonic-gate 			strcpy(state, PSVC_OK);
8660Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
8670Sstevel@tonic-gate 				state);
8680Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
8690Sstevel@tonic-gate 				return (status);
8700Sstevel@tonic-gate 			strcpy(fault, PSVC_NO_FAULT);
8710Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR,
8720Sstevel@tonic-gate 				fault);
8730Sstevel@tonic-gate 			if (status != PSVC_SUCCESS) {
8740Sstevel@tonic-gate 				return (status);
8750Sstevel@tonic-gate 			}
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate 			status = ptree_get_node_by_path(parent_path,
8780Sstevel@tonic-gate 				&parent_node);
8790Sstevel@tonic-gate 			if (status != 0)
8800Sstevel@tonic-gate 				return (PSVC_FAILURE);
8810Sstevel@tonic-gate 			status = ptree_add_node(parent_node, child_node);
8820Sstevel@tonic-gate 			if (status != 0)
8830Sstevel@tonic-gate 				return (PSVC_FAILURE);
8840Sstevel@tonic-gate 		} else {
8850Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_REMOVED_MSG, label);
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 			ptree_delete_node(child_node);
8880Sstevel@tonic-gate 
8890Sstevel@tonic-gate 		}
8900Sstevel@tonic-gate 	}
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR, &presence);
8930Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
8940Sstevel@tonic-gate 		return (status);
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate 	return (status);
8970Sstevel@tonic-gate }
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate int32_t
psvc_fan_hotplug_policy_0(psvc_opaque_t hdlp,char * id)9000Sstevel@tonic-gate psvc_fan_hotplug_policy_0(psvc_opaque_t hdlp, char *id)
9010Sstevel@tonic-gate {
9020Sstevel@tonic-gate 	boolean_t presence, previous_presence;
9030Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
9040Sstevel@tonic-gate 	char label[32];
905958Sjfrank 	int retry;
9060Sstevel@tonic-gate 
9070Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR,
9080Sstevel@tonic-gate 		&previous_presence);
9090Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
9100Sstevel@tonic-gate 		return (status);
9110Sstevel@tonic-gate 
9120Sstevel@tonic-gate 	retry = 0;
9130Sstevel@tonic-gate 	do {
9140Sstevel@tonic-gate 		if (retry)
915958Sjfrank 			(void) sleep(retry_sleep_fan_hotplug);
9160Sstevel@tonic-gate 
9170Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &presence);
9180Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
9190Sstevel@tonic-gate 			return (status);
9200Sstevel@tonic-gate 		retry++;
921958Sjfrank 	} while ((retry < n_retry_fan_hotplug) &&
9220Sstevel@tonic-gate 	    (presence != previous_presence));
9230Sstevel@tonic-gate 
9240Sstevel@tonic-gate 
9250Sstevel@tonic-gate 	if (presence != previous_presence) {
9260Sstevel@tonic-gate 		char parent_path[256];
9270Sstevel@tonic-gate 		picl_nodehdl_t child_node;
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, label);
9300Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
9310Sstevel@tonic-gate 			return (status);
9320Sstevel@tonic-gate 
9330Sstevel@tonic-gate 		/* return parent path and node for an object */
9340Sstevel@tonic-gate 		psvcplugin_lookup(id, parent_path, &child_node);
9350Sstevel@tonic-gate 
9360Sstevel@tonic-gate 		if (presence == PSVC_PRESENT) {
9370Sstevel@tonic-gate 			char state[32], fault[32];
9380Sstevel@tonic-gate 			char *slot_id;
9390Sstevel@tonic-gate 			char *led_id;
9400Sstevel@tonic-gate 			int32_t i, led_count;
9410Sstevel@tonic-gate 			char led_state[32];
9420Sstevel@tonic-gate 			picl_nodehdl_t parent_node;
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_INSERTED_MSG, label);
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate 			strcpy(state, PSVC_OK);
9470Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR,
9480Sstevel@tonic-gate 				state);
9490Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
9500Sstevel@tonic-gate 				return (status);
9510Sstevel@tonic-gate 			strcpy(fault, PSVC_NO_FAULT);
9520Sstevel@tonic-gate 			status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR,
9530Sstevel@tonic-gate 				fault);
9540Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
9550Sstevel@tonic-gate 				return (status);
9560Sstevel@tonic-gate 
9570Sstevel@tonic-gate 			/* turn off fault LEDs */
9580Sstevel@tonic-gate 			psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR,
9590Sstevel@tonic-gate 				&led_count, PSVC_DEV_FAULT_LED);
9600Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_OFF);
9610Sstevel@tonic-gate 			for (i = 0; i < led_count; ++i) {
9620Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, id,
9630Sstevel@tonic-gate 					PSVC_ASSOC_ID_ATTR, &led_id,
9640Sstevel@tonic-gate 					PSVC_DEV_FAULT_LED, i);
9650Sstevel@tonic-gate 				if (status == PSVC_FAILURE)
9660Sstevel@tonic-gate 					return (status);
9670Sstevel@tonic-gate 				status = psvc_set_attr(hdlp, led_id,
9680Sstevel@tonic-gate 					PSVC_LED_STATE_ATTR, led_state);
9690Sstevel@tonic-gate 				if (status == PSVC_FAILURE)
9700Sstevel@tonic-gate 					return (status);
9710Sstevel@tonic-gate 			}
9720Sstevel@tonic-gate 
9730Sstevel@tonic-gate 			/* turn off OK to remove LEDs */
9740Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
9750Sstevel@tonic-gate 				&slot_id, PSVC_PARENT, 0);
9760Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
9770Sstevel@tonic-gate 				return (status);
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate 			psvc_get_attr(hdlp, slot_id, PSVC_ASSOC_MATCHES_ATTR,
9800Sstevel@tonic-gate 				&led_count, PSVC_SLOT_REMOVE_LED);
9810Sstevel@tonic-gate 			strcpy(led_state, PSVC_LED_OFF);
9820Sstevel@tonic-gate 			for (i = 0; i < led_count; ++i) {
9830Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, slot_id,
9840Sstevel@tonic-gate 					PSVC_ASSOC_ID_ATTR, &led_id,
9850Sstevel@tonic-gate 					PSVC_SLOT_REMOVE_LED, i);
9860Sstevel@tonic-gate 				if (status == PSVC_FAILURE)
9870Sstevel@tonic-gate 					return (status);
9880Sstevel@tonic-gate 
9890Sstevel@tonic-gate 				status = psvc_set_attr(hdlp, led_id,
9900Sstevel@tonic-gate 					PSVC_LED_STATE_ATTR, led_state);
9910Sstevel@tonic-gate 				if (status == PSVC_FAILURE)
9920Sstevel@tonic-gate 					return (status);
9930Sstevel@tonic-gate 			}
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate 			ptree_get_node_by_path(parent_path, &parent_node);
9960Sstevel@tonic-gate 			ptree_add_node(parent_node, child_node);
9970Sstevel@tonic-gate 		} else {
9980Sstevel@tonic-gate 			syslog(LOG_ERR, DEVICE_REMOVED_MSG, label);
9990Sstevel@tonic-gate 			ptree_delete_node(child_node);
10000Sstevel@tonic-gate 		}
10010Sstevel@tonic-gate 	}
10020Sstevel@tonic-gate 
10030Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_PREV_PRESENCE_ATTR, &presence);
10040Sstevel@tonic-gate 	if (status != PSVC_SUCCESS)
10050Sstevel@tonic-gate 		return (status);
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate 	return (status);
10080Sstevel@tonic-gate }
10090Sstevel@tonic-gate 
10100Sstevel@tonic-gate int32_t
psvc_init_led_policy_0(psvc_opaque_t hdlp,char * id)10110Sstevel@tonic-gate psvc_init_led_policy_0(psvc_opaque_t hdlp, char *id)
10120Sstevel@tonic-gate {
10130Sstevel@tonic-gate 	int32_t status;
10140Sstevel@tonic-gate 
10150Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_LED_STATE_ATTR, PSVC_LED_OFF);
10160Sstevel@tonic-gate 	return (status);
10170Sstevel@tonic-gate }
10180Sstevel@tonic-gate 
10190Sstevel@tonic-gate int32_t
psvc_init_state_policy_0(psvc_opaque_t hdlp,char * id)10200Sstevel@tonic-gate psvc_init_state_policy_0(psvc_opaque_t hdlp, char *id)
10210Sstevel@tonic-gate {
10220Sstevel@tonic-gate 	int32_t status;
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, PSVC_OK);
10250Sstevel@tonic-gate 	status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR, PSVC_NO_FAULT);
10260Sstevel@tonic-gate 	return (status);
10270Sstevel@tonic-gate }
10280Sstevel@tonic-gate 
10290Sstevel@tonic-gate int32_t
psvc_ps_overcurrent_check_policy_0(psvc_opaque_t hdlp,char * power_supply_id)10300Sstevel@tonic-gate psvc_ps_overcurrent_check_policy_0(psvc_opaque_t hdlp, char *power_supply_id)
10310Sstevel@tonic-gate {
10320Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
10330Sstevel@tonic-gate 	boolean_t present;
10340Sstevel@tonic-gate 	char *sensor_id;
10350Sstevel@tonic-gate 	int32_t sensor_count;
10360Sstevel@tonic-gate 	int32_t i;
10370Sstevel@tonic-gate 	int32_t amps, hi_warn;
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, power_supply_id, PSVC_PRESENCE_ATTR,
10400Sstevel@tonic-gate 		&present);
10410Sstevel@tonic-gate 	if (status == PSVC_FAILURE) {
10420Sstevel@tonic-gate 		syslog(LOG_ERR, GET_PRESENCE_FAILED_MSG, power_supply_id,
10430Sstevel@tonic-gate 			errno);
10440Sstevel@tonic-gate 		return (status);
10450Sstevel@tonic-gate 	}
10460Sstevel@tonic-gate 
10470Sstevel@tonic-gate 	if (present == PSVC_ABSENT) {
10480Sstevel@tonic-gate 		errno = ENODEV;
10490Sstevel@tonic-gate 		return (PSVC_FAILURE);
10500Sstevel@tonic-gate 	}
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 	psvc_get_attr(hdlp, power_supply_id, PSVC_ASSOC_MATCHES_ATTR,
10530Sstevel@tonic-gate 		&sensor_count, PSVC_PS_I_SENSOR);
10540Sstevel@tonic-gate 	for (i = 0; i < sensor_count; ++i) {
10550Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, power_supply_id,
10560Sstevel@tonic-gate 			PSVC_ASSOC_ID_ATTR, &sensor_id, PSVC_PS_I_SENSOR, i);
10570Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
10580Sstevel@tonic-gate 			return (status);
10590Sstevel@tonic-gate 
10600Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id, PSVC_HI_WARN_ATTR,
10610Sstevel@tonic-gate 			&hi_warn);
10620Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
10630Sstevel@tonic-gate 			return (status);
10640Sstevel@tonic-gate 
10650Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id,
10660Sstevel@tonic-gate 			PSVC_SENSOR_VALUE_ATTR, &amps);
10670Sstevel@tonic-gate 		if (status != PSVC_SUCCESS) {
10680Sstevel@tonic-gate 			syslog(LOG_ERR, GET_SENSOR_FAILED_MSG, sensor_id,
10690Sstevel@tonic-gate 				errno);
10700Sstevel@tonic-gate 			return (status);
10710Sstevel@tonic-gate 		}
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate 		if (amps >= hi_warn) {
10740Sstevel@tonic-gate 			char label[32];
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate 			status = psvc_get_attr(hdlp, power_supply_id,
10770Sstevel@tonic-gate 				PSVC_LABEL_ATTR, &label);
10780Sstevel@tonic-gate 			if (status != PSVC_SUCCESS)
10790Sstevel@tonic-gate 				return (status);
10800Sstevel@tonic-gate 
10810Sstevel@tonic-gate 			syslog(LOG_ERR, PS_OVER_CURRENT_MSG, label);
10820Sstevel@tonic-gate 		}
10830Sstevel@tonic-gate 	}
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate 	return (PSVC_SUCCESS);
10860Sstevel@tonic-gate 
10870Sstevel@tonic-gate }
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate int32_t
psvc_device_fail_notifier_policy_0(psvc_opaque_t hdlp,char * id)10900Sstevel@tonic-gate psvc_device_fail_notifier_policy_0(psvc_opaque_t hdlp, char *id)
10910Sstevel@tonic-gate {
10920Sstevel@tonic-gate 	int32_t led_count, sensor_count;
10930Sstevel@tonic-gate 	char *led_id, *sensor_id;
10940Sstevel@tonic-gate 	int i;
10950Sstevel@tonic-gate 	char state[32], fault[32], previous_state[32];
10960Sstevel@tonic-gate 	char led_state[32];
10970Sstevel@tonic-gate 	int32_t status = PSVC_SUCCESS;
10980Sstevel@tonic-gate 	boolean_t present;
10990Sstevel@tonic-gate 
11000Sstevel@tonic-gate 	status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &present);
11010Sstevel@tonic-gate 	if (status == PSVC_FAILURE)
11020Sstevel@tonic-gate 		return (status);
11030Sstevel@tonic-gate 
11040Sstevel@tonic-gate 	if (present == PSVC_ABSENT) {
11050Sstevel@tonic-gate 		errno = ENODEV;
11060Sstevel@tonic-gate 		return (PSVC_FAILURE);
11070Sstevel@tonic-gate 	}
11080Sstevel@tonic-gate 
11090Sstevel@tonic-gate 	psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR, &sensor_count,
11100Sstevel@tonic-gate 		PSVC_DEV_FAULT_SENSOR);
11110Sstevel@tonic-gate 	for (i = 0; i < sensor_count; ++i) {
11120Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_ASSOC_ID_ATTR,
11130Sstevel@tonic-gate 			&sensor_id, PSVC_DEV_FAULT_SENSOR, i);
11140Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11150Sstevel@tonic-gate 			return (status);
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, sensor_id,
11180Sstevel@tonic-gate 			PSVC_SWITCH_STATE_ATTR, state);
11190Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11200Sstevel@tonic-gate 			return (status);
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate 		if (strcmp(state, PSVC_SWITCH_ON) == 0) {
11230Sstevel@tonic-gate 			strcpy(state, PSVC_ERROR);
11240Sstevel@tonic-gate 			strcpy(fault, PSVC_GEN_FAULT);
11250Sstevel@tonic-gate 		} else {
11260Sstevel@tonic-gate 			strcpy(state, PSVC_OK);
11270Sstevel@tonic-gate 			strcpy(fault, PSVC_NO_FAULT);
11280Sstevel@tonic-gate 		}
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_STATE_ATTR, state);
11310Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11320Sstevel@tonic-gate 			return (status);
11330Sstevel@tonic-gate 		status = psvc_set_attr(hdlp, id, PSVC_FAULTID_ATTR, fault);
11340Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11350Sstevel@tonic-gate 			return (status);
11360Sstevel@tonic-gate 		status = psvc_get_attr(hdlp, id, PSVC_PREV_STATE_ATTR,
11370Sstevel@tonic-gate 			previous_state);
11380Sstevel@tonic-gate 		if (status != PSVC_SUCCESS)
11390Sstevel@tonic-gate 			return (status);
11400Sstevel@tonic-gate 
11410Sstevel@tonic-gate 		if (strcmp(state, previous_state) != 0) {
11420Sstevel@tonic-gate 			char sensor_label[32];
11430Sstevel@tonic-gate 			char dev_label[32];
11440Sstevel@tonic-gate 			int32_t j;
11450Sstevel@tonic-gate 
11460Sstevel@tonic-gate 			psvc_get_attr(hdlp, id, PSVC_LABEL_ATTR, dev_label);
11470Sstevel@tonic-gate 			psvc_get_attr(hdlp, sensor_id, PSVC_LABEL_ATTR,
11480Sstevel@tonic-gate 				sensor_label);
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 			if (strcmp(state, PSVC_ERROR) == 0) {
11510Sstevel@tonic-gate 				syslog(LOG_ERR, DEVICE_FAILURE_MSG, dev_label,
11520Sstevel@tonic-gate 					sensor_label);
11530Sstevel@tonic-gate 				strcpy(led_state, PSVC_LED_ON);
11540Sstevel@tonic-gate 			} else {
11550Sstevel@tonic-gate 				syslog(LOG_ERR, DEVICE_OK_MSG, dev_label);
11560Sstevel@tonic-gate 				strcpy(led_state, PSVC_LED_OFF);
11570Sstevel@tonic-gate 			}
11580Sstevel@tonic-gate 
11590Sstevel@tonic-gate 			psvc_get_attr(hdlp, id, PSVC_ASSOC_MATCHES_ATTR,
11600Sstevel@tonic-gate 				&led_count, PSVC_DEV_FAULT_LED);
11610Sstevel@tonic-gate 			for (j = 0; j < led_count; j++) {
11620Sstevel@tonic-gate 				status = psvc_get_attr(hdlp, id,
11630Sstevel@tonic-gate 					PSVC_ASSOC_ID_ATTR, &led_id,
11640Sstevel@tonic-gate 					PSVC_DEV_FAULT_LED, j);
11650Sstevel@tonic-gate 				if (status != PSVC_SUCCESS)
11660Sstevel@tonic-gate 					return (status);
11670Sstevel@tonic-gate 				status = psvc_set_attr(hdlp, led_id,
11680Sstevel@tonic-gate 					PSVC_LED_STATE_ATTR, led_state);
11690Sstevel@tonic-gate 				if (status != PSVC_SUCCESS) {
11700Sstevel@tonic-gate 					syslog(LOG_ERR, SET_LED_FAILED_MSG,
11710Sstevel@tonic-gate 						led_id, errno);
11720Sstevel@tonic-gate 					return (status);
11730Sstevel@tonic-gate 				}
11740Sstevel@tonic-gate 			}
11750Sstevel@tonic-gate 		}
11760Sstevel@tonic-gate 	}
11770Sstevel@tonic-gate 
11780Sstevel@tonic-gate 	return (PSVC_SUCCESS);
11790Sstevel@tonic-gate }
11800Sstevel@tonic-gate 
11810Sstevel@tonic-gate static float
get_filtered_error(float * last_errors,int current_error)11820Sstevel@tonic-gate get_filtered_error(float *last_errors, int current_error)
11830Sstevel@tonic-gate {
11840Sstevel@tonic-gate 	float error;
11850Sstevel@tonic-gate 	float adder;
11860Sstevel@tonic-gate 	int i = 0;
11870Sstevel@tonic-gate 
11880Sstevel@tonic-gate 	adder = last_errors[0];
11890Sstevel@tonic-gate 	for (i = 1; i < PSVC_MAXERRORS; i++) {
11900Sstevel@tonic-gate 		adder = adder + last_errors[i];
11910Sstevel@tonic-gate 	}
11920Sstevel@tonic-gate 	adder = adder + current_error;
11930Sstevel@tonic-gate 	error = adder/(PSVC_MAXERRORS+1);
11940Sstevel@tonic-gate 
11950Sstevel@tonic-gate 	return (error);
11960Sstevel@tonic-gate }
11970Sstevel@tonic-gate 
11980Sstevel@tonic-gate static int32_t
change_cpu_fans(psvc_opaque_t hdlp,char * fan_id,int32_t fan_speed)11990Sstevel@tonic-gate change_cpu_fans(psvc_opaque_t hdlp, char *fan_id, int32_t fan_speed)
12000Sstevel@tonic-gate {
12010Sstevel@tonic-gate 	int err = PSVC_SUCCESS;
12020Sstevel@tonic-gate 	int i;
12030Sstevel@tonic-gate 	int32_t control_count;
12040Sstevel@tonic-gate 	char *control_id;
12050Sstevel@tonic-gate 	int32_t old_fan_speed;
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 	psvc_get_attr(hdlp, fan_id, PSVC_ASSOC_MATCHES_ATTR, &control_count,
12080Sstevel@tonic-gate 		PSVC_FAN_DRIVE_CONTROL);
12090Sstevel@tonic-gate 	if (control_count == 0)
12100Sstevel@tonic-gate 		return (PSVC_SUCCESS);
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_ASSOC_ID_ATTR, &control_id,
12130Sstevel@tonic-gate 		PSVC_FAN_DRIVE_CONTROL, 0);
12140Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
12150Sstevel@tonic-gate 		return (err);
12160Sstevel@tonic-gate 
12170Sstevel@tonic-gate 	/*
12180Sstevel@tonic-gate 	 * this call will return PSVC_FAILURE on the first pass,
12190Sstevel@tonic-gate 	 * because no value has been set.
12200Sstevel@tonic-gate 	 */
12210Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, control_id, PSVC_CONTROL_VALUE_ATTR,
12220Sstevel@tonic-gate 		&old_fan_speed);
12230Sstevel@tonic-gate 	if (err == PSVC_SUCCESS && old_fan_speed == fan_speed)
12240Sstevel@tonic-gate 		return (PSVC_SUCCESS);
12250Sstevel@tonic-gate 
12260Sstevel@tonic-gate 	for (i = 0; i < control_count; i++) {
12270Sstevel@tonic-gate 		err = psvc_get_attr(hdlp, fan_id, PSVC_ASSOC_ID_ATTR,
12280Sstevel@tonic-gate 			&control_id, PSVC_FAN_DRIVE_CONTROL, i);
12290Sstevel@tonic-gate 		if (err != PSVC_SUCCESS)
12300Sstevel@tonic-gate 			return (err);
12310Sstevel@tonic-gate 
12320Sstevel@tonic-gate 		err = psvc_set_attr(hdlp, control_id, PSVC_CONTROL_VALUE_ATTR,
12330Sstevel@tonic-gate 			&fan_speed);
12340Sstevel@tonic-gate 		if (err == PSVC_FAILURE) {
12350Sstevel@tonic-gate 			syslog(LOG_ERR, SET_FANSPEED_FAILED_MSG, control_id,
12360Sstevel@tonic-gate 				errno);
12370Sstevel@tonic-gate 			return (err);
12380Sstevel@tonic-gate 		}
12390Sstevel@tonic-gate 	}
12400Sstevel@tonic-gate 	return (err);
12410Sstevel@tonic-gate }
12420Sstevel@tonic-gate 
12430Sstevel@tonic-gate static int32_t
device_temp_check(psvc_opaque_t hdlp,char * fan_id,int32_t * hot_device)12440Sstevel@tonic-gate device_temp_check(psvc_opaque_t hdlp, char *fan_id, int32_t *hot_device)
12450Sstevel@tonic-gate {
12460Sstevel@tonic-gate 	int i;
12470Sstevel@tonic-gate 	int32_t err = PSVC_SUCCESS;
12480Sstevel@tonic-gate 	char *sensor_id;
12490Sstevel@tonic-gate 	int32_t sensor_count;
12500Sstevel@tonic-gate 	int32_t temp;
12510Sstevel@tonic-gate 
12520Sstevel@tonic-gate 	*hot_device = 0;
12530Sstevel@tonic-gate 
12540Sstevel@tonic-gate 	psvc_get_attr(hdlp, fan_id, PSVC_ASSOC_MATCHES_ATTR, &sensor_count,
12550Sstevel@tonic-gate 		PSVC_DEV_TEMP_SENSOR);
12560Sstevel@tonic-gate 	for (i = 0; i < sensor_count; i++) {
12570Sstevel@tonic-gate 		err = psvc_get_attr(hdlp, fan_id, PSVC_ASSOC_ID_ATTR,
12580Sstevel@tonic-gate 			&sensor_id, PSVC_DEV_TEMP_SENSOR, i);
12590Sstevel@tonic-gate 		if (err == PSVC_FAILURE)
12600Sstevel@tonic-gate 			return (err);
12610Sstevel@tonic-gate 		err = psvc_get_attr(hdlp, sensor_id, PSVC_SENSOR_VALUE_ATTR,
12620Sstevel@tonic-gate 			&temp);
12630Sstevel@tonic-gate 		if (err == PSVC_FAILURE) {
12640Sstevel@tonic-gate 			if (errno == ENODEV) {
12650Sstevel@tonic-gate 				temp = 0;
12660Sstevel@tonic-gate 			} else {
1267*6398Sanbui 				syslog(LOG_ERR, GET_SENSOR_FAILED_MSG,
1268*6398Sanbui 				    sensor_id, errno);
12690Sstevel@tonic-gate 				return (err);
12700Sstevel@tonic-gate 			}
12710Sstevel@tonic-gate 		}
12720Sstevel@tonic-gate 
12730Sstevel@tonic-gate 		if (*hot_device < temp)
12740Sstevel@tonic-gate 			*hot_device = temp;
12750Sstevel@tonic-gate 	}
12760Sstevel@tonic-gate 	return (PSVC_SUCCESS);
12770Sstevel@tonic-gate }
12780Sstevel@tonic-gate 
12790Sstevel@tonic-gate int32_t
psvc_fan_control_policy_0(psvc_opaque_t hdlp,char * fan_id)12800Sstevel@tonic-gate psvc_fan_control_policy_0(psvc_opaque_t hdlp, char *fan_id)
12810Sstevel@tonic-gate {
12820Sstevel@tonic-gate 	boolean_t is_enabled;
12830Sstevel@tonic-gate 	int32_t err = PSVC_SUCCESS;
12840Sstevel@tonic-gate 	int16_t setpoint, hysteresis, loopgain, loopbias;
12850Sstevel@tonic-gate 	int current_error;		/* Holds current error */
12860Sstevel@tonic-gate 					/* Signal before signaling */
12870Sstevel@tonic-gate 	float filtered_error;		/* Holds the filtered error signal */
12880Sstevel@tonic-gate 	int ampout;			/* output of loop amplifier */
12890Sstevel@tonic-gate 	int hot_device;
12900Sstevel@tonic-gate 
12910Sstevel@tonic-gate 	int16_t error_number;
12920Sstevel@tonic-gate 	float last_errors[PSVC_MAXERRORS];	/* Holds the filtered error */
12930Sstevel@tonic-gate 						/* from the last n iterations */
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 	psvc_get_attr(hdlp, fan_id, PSVC_ENABLE_ATTR, &is_enabled);
12960Sstevel@tonic-gate 	if (is_enabled == PSVC_DISABLED)
12970Sstevel@tonic-gate 		return (PSVC_SUCCESS);
12980Sstevel@tonic-gate 
12990Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_SETPOINT_ATTR, &setpoint);
13000Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13010Sstevel@tonic-gate 		return (err);
13020Sstevel@tonic-gate 
13030Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_HYSTERESIS_ATTR,
13040Sstevel@tonic-gate 		&hysteresis);
13050Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13060Sstevel@tonic-gate 		return (err);
13070Sstevel@tonic-gate 
13080Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_LOOPGAIN_ATTR, &loopgain);
13090Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13100Sstevel@tonic-gate 		return (err);
13110Sstevel@tonic-gate 
13120Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_LOOPBIAS_ATTR, &loopbias);
13130Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13140Sstevel@tonic-gate 		return (err);
13150Sstevel@tonic-gate 
13160Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_TEMP_DIFFERENTIAL_ATTR,
13170Sstevel@tonic-gate 		last_errors);
13180Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13190Sstevel@tonic-gate 		return (err);
13200Sstevel@tonic-gate 
13210Sstevel@tonic-gate 	err = psvc_get_attr(hdlp, fan_id, PSVC_TEMP_DIFFERENTIAL_INDEX_ATTR,
13220Sstevel@tonic-gate 		&error_number);
13230Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13240Sstevel@tonic-gate 		return (err);
13250Sstevel@tonic-gate 
13260Sstevel@tonic-gate 	err = device_temp_check(hdlp, fan_id, &hot_device);
13270Sstevel@tonic-gate 	if (err != PSVC_SUCCESS) {
13280Sstevel@tonic-gate 		printf("psvc_fan_control failure in device_temp_check\n");
13290Sstevel@tonic-gate 		return (err);
13300Sstevel@tonic-gate 	}
13310Sstevel@tonic-gate 	current_error = setpoint - hot_device;
13320Sstevel@tonic-gate 	filtered_error = get_filtered_error(last_errors, current_error);
13330Sstevel@tonic-gate 	if (filtered_error <= 0 || filtered_error > hysteresis) {
13340Sstevel@tonic-gate 		ampout = (int)((filtered_error * loopgain) + loopbias);
13350Sstevel@tonic-gate 		if (ampout < 0)
13360Sstevel@tonic-gate 			ampout = 0;
13370Sstevel@tonic-gate 		if (ampout > 1023)
13380Sstevel@tonic-gate 			ampout = 1023;
13390Sstevel@tonic-gate 		err = change_cpu_fans(hdlp, fan_id, ampout);
13400Sstevel@tonic-gate 		if (err != PSVC_SUCCESS)
13410Sstevel@tonic-gate 			return (err);
13420Sstevel@tonic-gate 	}
13430Sstevel@tonic-gate 	last_errors[error_number++] = current_error;
13440Sstevel@tonic-gate 	if (error_number == PSVC_MAXERRORS)
13450Sstevel@tonic-gate 		error_number = 0;
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate 	err = psvc_set_attr(hdlp, fan_id, PSVC_TEMP_DIFFERENTIAL_ATTR,
13480Sstevel@tonic-gate 		last_errors);
13490Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13500Sstevel@tonic-gate 		return (err);
13510Sstevel@tonic-gate 
13520Sstevel@tonic-gate 	err = psvc_set_attr(hdlp, fan_id, PSVC_TEMP_DIFFERENTIAL_INDEX_ATTR,
13530Sstevel@tonic-gate 		&error_number);
13540Sstevel@tonic-gate 	if (err != PSVC_SUCCESS)
13550Sstevel@tonic-gate 		return (err);
13560Sstevel@tonic-gate 
13570Sstevel@tonic-gate 	return (PSVC_SUCCESS);
13580Sstevel@tonic-gate }
13590Sstevel@tonic-gate 
13600Sstevel@tonic-gate int32_t
psvc_fan_present_policy_0(psvc_opaque_t hdlp,char * id)13610Sstevel@tonic-gate psvc_fan_present_policy_0(psvc_opaque_t hdlp, char *id)
13620Sstevel@tonic-gate {
13630Sstevel@tonic-gate 	int32_t		status = PSVC_SUCCESS;
13640Sstevel@tonic-gate 	boolean_t	presence;
13650Sstevel@tonic-gate 	int fd;
13660Sstevel@tonic-gate 	FILE *fp;
1367958Sjfrank 	int retry;
13680Sstevel@tonic-gate 
1369958Sjfrank 	retry = 0;
1370958Sjfrank 	do {
1371958Sjfrank 		if (retry)
1372958Sjfrank 			(void) sleep(retry_sleep_fan_present);
1373958Sjfrank 
1374958Sjfrank 		status = psvc_get_attr(hdlp, id, PSVC_PRESENCE_ATTR, &presence);
1375958Sjfrank 		if (status != PSVC_SUCCESS)
1376958Sjfrank 			return (status);
1377958Sjfrank 		retry++;
1378958Sjfrank 	} while ((retry < n_retry_fan_present) && (presence == PSVC_ABSENT));
13790Sstevel@tonic-gate 
13800Sstevel@tonic-gate 	if (presence == PSVC_ABSENT) {
13810Sstevel@tonic-gate 		/*
13820Sstevel@tonic-gate 		 * We make this open, write, close, call because picld
13830Sstevel@tonic-gate 		 * starts in rcS.d while print services does not start
13840Sstevel@tonic-gate 		 * until later (either rc2.d or rc3.d)
13850Sstevel@tonic-gate 		 */
13860Sstevel@tonic-gate 		fd = open("/dev/console", O_WRONLY | O_NOCTTY);
13870Sstevel@tonic-gate 		if (fd != -1) {
13880Sstevel@tonic-gate 			fp = fdopen(fd, "w+");
13890Sstevel@tonic-gate 			if (fp != NULL) {
13900Sstevel@tonic-gate 				fprintf(fp, FAN_MISSING_MSG, id);
13910Sstevel@tonic-gate 				fclose(fp);
13920Sstevel@tonic-gate 			}
13930Sstevel@tonic-gate 			close(fd);
13940Sstevel@tonic-gate 		}
13950Sstevel@tonic-gate 		syslog(LOG_ERR, FAN_MISSING_MSG, id);
13960Sstevel@tonic-gate 	}
13970Sstevel@tonic-gate 	return (status);
13980Sstevel@tonic-gate }
1399