xref: /onnv-gate/usr/src/cmd/picl/plugins/sun4u/grover/envd/envd.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_ENVD_H
28*0Sstevel@tonic-gate #define	_ENVD_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <libintl.h>
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #ifdef	__cplusplus
36*0Sstevel@tonic-gate extern "C" {
37*0Sstevel@tonic-gate #endif
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #define	SENSOR_POLL_INTERVAL 	4			/* in seconds */
40*0Sstevel@tonic-gate #define	WARNING_INTERVAL	30			/* in seconds */
41*0Sstevel@tonic-gate #define	SHUTDOWN_INTERVAL	20			/* in seconds */
42*0Sstevel@tonic-gate #define	ENV_CONF_FILE		"piclenvd.conf"
43*0Sstevel@tonic-gate #define	ENVMODEL_CONF_FILE	"envmodel.conf"
44*0Sstevel@tonic-gate #define	PM_DEVICE		"/dev/pm"
45*0Sstevel@tonic-gate #define	SHUTDOWN_CMD		"/usr/sbin/shutdown -y -g 60 -i 5"
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate  * devfs-path for various fans and their min/max speeds
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate #define	ENV_CPU_FAN_DEVFS	\
51*0Sstevel@tonic-gate 	"/pci@1f,0/pmu@3/fan-control@0,c8:cpu_fan"
52*0Sstevel@tonic-gate #define	ENV_SYSTEM_FAN_DEVFS	\
53*0Sstevel@tonic-gate 	"/pci@1f,0/pmu@3/fan-control@0,c8:sys_fan"
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate #define	SYSTEM_FAN_SPEED_MIN	0
56*0Sstevel@tonic-gate #define	SYSTEM_FAN_SPEED_MAX	100
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * devfs-path for various temperature sensors and CPU platform path
61*0Sstevel@tonic-gate  */
62*0Sstevel@tonic-gate #define	CPU_DIE_SENSOR_DEVFS	\
63*0Sstevel@tonic-gate 	"/pci@1f,0/pmu@3/i2c@0,0/temperature@30:die_temp"
64*0Sstevel@tonic-gate #define	CPU_AMB_SENSOR_DEVFS	\
65*0Sstevel@tonic-gate 	"/pci@1f,0/pmu@3/i2c@0,0/temperature@30:amb_temp"
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate  * Temperature thresholds structure
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate typedef int16_t tempr_t;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate typedef struct {
73*0Sstevel@tonic-gate 	tempr_t	low_power_off;		/* low power-off temperature */
74*0Sstevel@tonic-gate 	tempr_t	high_power_off;		/* high power-off temperature */
75*0Sstevel@tonic-gate 	tempr_t	low_shutdown;		/* low shutdown temperature */
76*0Sstevel@tonic-gate 	tempr_t	high_shutdown;		/* high shutdown temperature */
77*0Sstevel@tonic-gate 	tempr_t	low_warning;		/* low warning temperature */
78*0Sstevel@tonic-gate 	tempr_t	high_warning;		/* high warning temperature */
79*0Sstevel@tonic-gate 	tempr_t	target_temp;		/* target temperature */
80*0Sstevel@tonic-gate } sensor_thresh_t;
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate #define	TEMP_IN_SHUTDOWN_RANGE(val, threshp)	\
83*0Sstevel@tonic-gate 	((val) > (threshp)->high_shutdown || (val) < (threshp)->low_shutdown)
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate #define	TEMP_IN_WARNING_RANGE(val, threshp)	\
86*0Sstevel@tonic-gate 	((val) > (threshp)->high_warning || (val) < (threshp)->low_warning)
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * CPU "die" temperature thresholds
91*0Sstevel@tonic-gate  */
92*0Sstevel@tonic-gate #define	CPU_DIE_HIGH_POWER_OFF	125
93*0Sstevel@tonic-gate #define	CPU_DIE_HIGH_SHUTDOWN	90
94*0Sstevel@tonic-gate #define	CPU_DIE_HIGH_WARNING	85
95*0Sstevel@tonic-gate #define	CPU_DIE_TARGET_TEMP	80
96*0Sstevel@tonic-gate #define	CPU_DIE_LOW_WARNING	0
97*0Sstevel@tonic-gate #define	CPU_DIE_LOW_SHUTDOWN	-10
98*0Sstevel@tonic-gate #define	CPU_DIE_LOW_POWER_OFF	-20
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate /*
101*0Sstevel@tonic-gate  * CPU ambient temperature thresholds
102*0Sstevel@tonic-gate  */
103*0Sstevel@tonic-gate #define	CPU_AMB_HIGH_POWER_OFF	70
104*0Sstevel@tonic-gate #define	CPU_AMB_HIGH_SHUTDOWN	60
105*0Sstevel@tonic-gate #define	CPU_AMB_HIGH_WARNING	40
106*0Sstevel@tonic-gate #define	CPU_AMB_TARGET_TEMP	32
107*0Sstevel@tonic-gate #define	CPU_AMB_LOW_WARNING	0
108*0Sstevel@tonic-gate #define	CPU_AMB_LOW_SHUTDOWN	-10
109*0Sstevel@tonic-gate #define	CPU_AMB_LOW_POWER_OFF	-20
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate /*
113*0Sstevel@tonic-gate  * Fan names
114*0Sstevel@tonic-gate  */
115*0Sstevel@tonic-gate #define	ENV_SYSTEM_FAN		"system"
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate /*
118*0Sstevel@tonic-gate  * Sensor names
119*0Sstevel@tonic-gate  */
120*0Sstevel@tonic-gate #define	SENSOR_CPU_DIE		"cpu"
121*0Sstevel@tonic-gate #define	SENSOR_CPU_AMB		"cpu-ambient"
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate /*
124*0Sstevel@tonic-gate  * Temperature sensor related data structure
125*0Sstevel@tonic-gate  */
126*0Sstevel@tonic-gate typedef struct env_sensor {
127*0Sstevel@tonic-gate 	char		*name;			/* sensor name */
128*0Sstevel@tonic-gate 	char		*devfs_path;		/* sensor device devfs path */
129*0Sstevel@tonic-gate 	sensor_thresh_t	*temp_thresh;		/* sensor temp threshold */
130*0Sstevel@tonic-gate 	int		fd;			/* device file descriptor */
131*0Sstevel@tonic-gate 	int		error;			/* error flag */
132*0Sstevel@tonic-gate 	boolean_t 	present;		/* sensor present */
133*0Sstevel@tonic-gate 	tempr_t		cur_temp;		/* current temperature */
134*0Sstevel@tonic-gate 	time_t		warning_tstamp;		/* last warning time in secs */
135*0Sstevel@tonic-gate 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
136*0Sstevel@tonic-gate 	boolean_t 	shutdown_initiated;	/* shutdown initated */
137*0Sstevel@tonic-gate } env_sensor_t;
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate extern	env_sensor_t *sensor_lookup(char *sensor_name);
140*0Sstevel@tonic-gate extern	int get_temperature(env_sensor_t *, tempr_t *);
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate /*
143*0Sstevel@tonic-gate  * Fan information data structure
144*0Sstevel@tonic-gate  */
145*0Sstevel@tonic-gate typedef uint8_t fanspeed_t;
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate typedef struct env_fan {
148*0Sstevel@tonic-gate 	char		*name;			/* fan name */
149*0Sstevel@tonic-gate 	char		*devfs_path;		/* fan device devfs path */
150*0Sstevel@tonic-gate 	fanspeed_t	speed_min;		/* minimum speed */
151*0Sstevel@tonic-gate 	fanspeed_t	speed_max;		/* maximum speed */
152*0Sstevel@tonic-gate 	int		fd;			/* device file descriptor */
153*0Sstevel@tonic-gate 	boolean_t	present;		/* fan present */
154*0Sstevel@tonic-gate 	fanspeed_t	cur_speed;		/* current fan speed */
155*0Sstevel@tonic-gate 	fanspeed_t	prev_speed;		/* previous fan speed */
156*0Sstevel@tonic-gate } env_fan_t;
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate extern	env_fan_t *fan_lookup(char *fan_name);
160*0Sstevel@tonic-gate extern	int get_fan_speed(env_fan_t *, fanspeed_t *);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate extern int env_debug;
163*0Sstevel@tonic-gate extern void envd_log(int pri, const char *fmt, ...);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate /*
166*0Sstevel@tonic-gate  * Various messages
167*0Sstevel@tonic-gate  */
168*0Sstevel@tonic-gate #define	ENVD_PLUGIN_INIT_FAILED		\
169*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: initialization failed!\n")
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate #define	ENVD_PICL_SETUP_FAILED		\
172*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: PICL setup failed!\n")
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate #define	PM_THREAD_CREATE_FAILED		\
175*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate #define	PM_THREAD_EXITING		\
178*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate #define	ENV_THREAD_CREATE_FAILED	\
181*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: envthr thread creation failed!\n")
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate #define	ENV_SHUTDOWN_MSG		\
184*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
185*0Sstevel@tonic-gate 	"limits (%d...%d). Shutting down the system.\n")
186*0Sstevel@tonic-gate 
187*0Sstevel@tonic-gate #define	ENV_WARNING_MSG			\
188*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
189*0Sstevel@tonic-gate 	"operating limits (%d...%d).\n")
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate #define	ENV_FAN_OPEN_FAIL		\
192*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate #define	ENV_SENSOR_OPEN_FAIL		\
195*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate #define	ENV_SENSOR_ACCESS_FAIL		\
198*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate #define	ENV_SENSOR_ACCESS_OK		\
201*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate #define	ENV_CONF_INT_EXPECTED		\
204*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax or integer " \
205*0Sstevel@tonic-gate 	"value outside range for keyword '%s'.\n")
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate #define	ENV_CONF_STRING_EXPECTED	\
208*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax for keyword " \
209*0Sstevel@tonic-gate 	"'%s'. Expecting string in double quotes (length < %d).\n")
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate #define	ENV_CONF_UNSUPPORTED_TYPE	\
212*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Unsupported type:%d for " \
213*0Sstevel@tonic-gate 	"keyword '%s'.\n")
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate #define	ENV_CONF_UNSUPPORTED_KEYWORD	\
216*0Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Unsupported keyword '%s'.\n")
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate #ifdef	__cplusplus
219*0Sstevel@tonic-gate }
220*0Sstevel@tonic-gate #endif
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate #endif	/* _ENVD_H */
223