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