xref: /illumos-gate/usr/src/cmd/picl/plugins/sun4u/chicago/envd/envd.h (revision 16ade92d9ce9c9ab33a25f7a2fdd00b581b6efda)
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 2005 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <libintl.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Chicago Platform Details
41  */
42 #define	MAX_SENSORS		8
43 #define	MAX_FANS		6
44 
45 /*
46  * Fan names and ids
47  */
48 #define	ENV_SYSTEM_FAN0		"system-fan0"
49 #define	ENV_SYSTEM_FAN1		"system-fan1"
50 #define	ENV_SYSTEM_FAN2		"system-fan2"
51 #define	ENV_SYSTEM_FAN3		"system-fan3"
52 #define	ENV_SYSTEM_FAN4		"system-fan4"
53 
54 #define	SYSTEM_FAN0_ID		0
55 #define	SYSTEM_FAN1_ID		1
56 #define	SYSTEM_FAN2_ID		2
57 #define	SYSTEM_FAN3_ID		3
58 #define	SYSTEM_FAN4_ID		4
59 
60 #define	CPU0_FAN_ID		SYSTEM_FAN0_ID
61 #define	CPU1_FAN_ID		SYSTEM_FAN1_ID
62 
63 /*
64  * Sensor names and ids
65  */
66 #define	SENSOR_CPU0		"cpu0"
67 #define	SENSOR_CPU1		"cpu1"
68 #define	SENSOR_MB		"MotherBoard"
69 #define	SENSOR_ADT7462		"ADT7462"
70 #define	SENSOR_LM95221		"LM95221"
71 #define	SENSOR_FIRE		"FireASIC"
72 #define	SENSOR_LSI1064		"LSI1064"
73 #define	SENSOR_FRONT_PANEL	"Front_panel"
74 
75 #define	CPU0_SENSOR_ID		0
76 #define	CPU1_SENSOR_ID		1
77 #define	ADT7462_SENSOR_ID	2
78 #define	MB_SENSOR_ID		3
79 #define	LM95221_SENSOR_ID	4
80 #define	FIRE_SENSOR_ID		5
81 #define	LSI1064_SENSOR_ID	6
82 #define	FRONT_PANEL_SENSOR_ID	7
83 
84 /*
85  * Hard disk sensor names and ids
86  */
87 #define	ENV_DISK0		"hard-disk0"
88 #define	ENV_DISK1		"hard-disk1"
89 #define	ENV_DISK2		"hard-disk2"
90 #define	ENV_DISK3		"hard-disk3"
91 
92 #define	DISK0_ID		0
93 #define	DISK1_ID		1
94 #define	DISK2_ID		2
95 #define	DISK3_ID		3
96 
97 /*
98  * Thresholds and other constants
99  */
100 #define	DISK_SCAN_INTERVAL		10
101 #define	DISK_HIGH_WARN_TEMPERATURE	55
102 #define	DISK_LOW_WARN_TEMPERATURE	5
103 #define	DISK_HIGH_SHUTDOWN_TEMPERATURE	60
104 #define	DISK_LOW_SHUTDOWN_TEMPERATURE	0
105 #define	DISK_INVALID_TEMP		0xFFFF
106 #define	LSI1064_VENDOR_ID		0x1000
107 #define	LSI1064_DEVICE_ID		0x50
108 #define	FAN_SCAN_INTERVAL		10
109 #define	SENSOR_SCAN_INTERVAL		2
110 #define	SENSOR_WARNING_DURATION		4
111 #define	SENSOR_WARNING_INTERVAL		30
112 #define	DISK_WARNING_INTERVAL		30
113 #define	DISK_WARNING_DURATION		20
114 #define	SENSOR_SHUTDOWN_INTERVAL	60
115 #define	DISK_SHUTDOWN_INTERVAL		30
116 #define	ENV_CONF_FILE			"envmodel.conf"
117 #define	TUNABLE_CONF_FILE		"piclenvd.conf"
118 #define	PM_DEVICE			"/dev/pm"
119 #define	SHUTDOWN_CMD			"/usr/sbin/shutdown -y -g 60 -i 5"
120 #define	PICL_PLUGINS_NODE		"plugins"
121 #define	PICL_ENVIRONMENTAL_NODE		"environmental"
122 
123 #define	MAX_RETRIES_FOR_FAN_FAULT	10
124 #define	MAX_FAN_RETRIES			14
125 #define	MAX_SENSOR_RETRIES		14
126 
127 #define	TACH_TO_RPM(tach)		(90000 * 60)/tach
128 
129 #define	DISK0_PHYSPATH	\
130 	"/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@0,0"
131 
132 #define	DISK1_PHYSPATH	\
133 	"/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@1,0"
134 
135 #define	DISK2_PHYSPATH  \
136 	"/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@2,0"
137 
138 #define	DISK3_PHYSPATH  \
139 	"/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@3,0"
140 
141 #define	ENV_DISK0_DEVFS	\
142 "/devices/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@0,0:a,raw"
143 
144 #define	ENV_DISK1_DEVFS	\
145 "/devices/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@1,0:a,raw"
146 
147 #define	ENV_DISK2_DEVFS \
148 "/devices/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@2,0:a,raw"
149 
150 #define	ENV_DISK3_DEVFS \
151 "/devices/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@3,0:a,raw"
152 
153 #define	DISK0_NODE_PATH	\
154 "name:/platform/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@0,0"
155 
156 #define	DISK1_NODE_PATH	\
157 "name:/platform/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@1,0"
158 
159 #define	DISK2_NODE_PATH \
160 "name:/platform/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@2,0"
161 
162 #define	DISK3_NODE_PATH \
163 "name:/platform/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1/sd@3,0"
164 
165 #define	SCSI_CONTROLLER_NODE_PATH	\
166 	"name:/platform/pci@1e,600000/pci@0/pci@a/pci@0/LSILogic,sas@1"
167 
168 /* CPU Path Names */
169 #define	CPU0_PATH		"_class:/jbus/cpu?ID=0"
170 #define	CPU1_PATH		"_class:/jbus/cpu?ID=1"
171 
172 #define	ENV_MONITOR_DEVFS	"/devices/ebus@1f,464000/env-monitor@3,0"
173 
174 
175 /*
176  * devfs-path for various fans and their min/max speeds
177  */
178 #define	ENV_SYSTEM_FAN0_DEVFS	\
179 	"/devices/ebus@1f,464000/env-monitor@3,0:fan_0"
180 #define	ENV_SYSTEM_FAN1_DEVFS	\
181 	"/devices/ebus@1f,464000/env-monitor@3,0:fan_1"
182 #define	ENV_SYSTEM_FAN2_DEVFS	\
183 	"/devices/ebus@1f,464000/env-monitor@3,0:fan_2"
184 #define	ENV_SYSTEM_FAN3_DEVFS	\
185 	"/devices/ebus@1f,464000/env-monitor@3,0:fan_3"
186 #define	ENV_SYSTEM_FAN4_DEVFS	\
187 	"/devices/ebus@1f,464000/env-monitor@3,0:fan_4"
188 
189 /* MIN and MAX SPEED are in RPM units */
190 
191 #define	CPU_FAN_SPEED_MIN	250
192 #define	CPU_FAN_SPEED_MAX	5000
193 
194 #define	SYSTEM_FAN_SPEED_MIN	250
195 #define	SYSTEM_FAN_SPEED_MAX	5000
196 
197 /*
198  * devfs-path for various temperature sensors and CPU platform path
199  */
200 #define	SENSOR_CPU0_DEVFS	\
201 	"/devices/ebus@1f,464000/env-monitor@3,0:cpu_0"
202 #define	SENSOR_CPU1_DEVFS	\
203 	"/devices/ebus@1f,464000/env-monitor@3,0:cpu_1"
204 #define	SENSOR_MB_DEVFS	\
205 	"/devices/ebus@1f,464000/env-monitor@3,0:mb"
206 #define	SENSOR_ADT7462_DEVFS	\
207 	"/devices/ebus@1f,464000/env-monitor@3,0:adt7462"
208 #define	SENSOR_LM95221_DEVFS	\
209 	"/devices/ebus@1f,464000/env-monitor@3,0:lm95221"
210 #define	SENSOR_FIRE_DEVFS	\
211 	"/devices/ebus@1f,464000/env-monitor@3,0:fire"
212 #define	SENSOR_LSI1064_DEVFS	\
213 	"/devices/ebus@1f,464000/env-monitor@3,0:lsi1064"
214 #define	SENSOR_FRONT_PANEL_DEVFS	\
215 	"/devices/ebus@1f,464000/env-monitor@3,0:front_panel"
216 
217 /*
218  * Temperature type
219  */
220 typedef int16_t tempr_t;
221 
222 #define	SENSOR_TEMP_IN_WARNING_RANGE(val, sensorp) \
223 	((val) > (sensorp)->high_warning || \
224 	(val) < (char)((sensorp)->low_warning))
225 
226 #define	SENSOR_TEMP_IN_SHUTDOWN_RANGE(val, sensorp) \
227 	((val) > (sensorp)->high_shutdown || \
228 	(val) < (char)((sensorp)->low_shutdown))
229 
230 #define	DISK_TEMP_IN_WARNING_RANGE(val, diskp) \
231 	((val) > (diskp)->high_warning || \
232 	(val) < (char)((diskp)->low_warning))
233 
234 #define	DISK_TEMP_IN_SHUTDOWN_RANGE(val, diskp) \
235 	((val) > (diskp)->high_shutdown || \
236 	(val) < (char)((diskp)->low_shutdown))
237 
238 #define	SENSOR_WARN		1
239 #define	SENSOR_OK		0
240 
241 #define	FAN_FAILED		1
242 #define	FAN_OK			0
243 
244 #define	CPU0_HIGH_SHUTDOWN		100
245 #define	CPU0_LOW_SHUTDOWN		0
246 #define	CPU0_HIGH_WARNING		95
247 #define	CPU0_LOW_WARNING		5
248 #define	CPU0_HIGH_POWER_OFF		105
249 #define	CPU0_LOW_POWER_OFF		-5
250 
251 #define	CPU1_HIGH_SHUTDOWN		100
252 #define	CPU1_LOW_SHUTDOWN		0
253 #define	CPU1_HIGH_WARNING		95
254 #define	CPU1_LOW_WARNING		5
255 #define	CPU1_HIGH_POWER_OFF		105
256 #define	CPU1_LOW_POWER_OFF		-5
257 
258 #define	ADT7462_HIGH_SHUTDOWN		75
259 #define	ADT7462_LOW_SHUTDOWN		0
260 #define	ADT7462_HIGH_WARNING		70
261 #define	ADT7462_LOW_WARNING		5
262 #define	ADT7462_HIGH_POWER_OFF		80
263 #define	ADT7462_LOW_POWER_OFF		-5
264 
265 #define	MB_HIGH_SHUTDOWN		75
266 #define	MB_LOW_SHUTDOWN			0
267 #define	MB_HIGH_WARNING			70
268 #define	MB_LOW_WARNING			5
269 #define	MB_HIGH_POWER_OFF		80
270 #define	MB_LOW_POWER_OFF		-5
271 
272 #define	LM95221_HIGH_SHUTDOWN		75
273 #define	LM95221_LOW_SHUTDOWN		0
274 #define	LM95221_HIGH_WARNING		70
275 #define	LM95221_LOW_WARNING		5
276 #define	LM95221_HIGH_POWER_OFF		80
277 #define	LM95221_LOW_POWER_OFF		-5
278 
279 #define	FIRE_HIGH_SHUTDOWN		100
280 #define	FIRE_LOW_SHUTDOWN		0
281 #define	FIRE_HIGH_WARNING		95
282 #define	FIRE_LOW_WARNING		5
283 #define	FIRE_HIGH_POWER_OFF		105
284 #define	FIRE_LOW_POWER_OFF		-5
285 
286 #define	LSI1064_HIGH_SHUTDOWN		100
287 #define	LSI1064_LOW_SHUTDOWN		0
288 #define	LSI1064_HIGH_WARNING		95
289 #define	LSI1064_LOW_WARNING		5
290 #define	LSI1064_HIGH_POWER_OFF		105
291 #define	LSI1064_LOW_POWER_OFF		-5
292 
293 #define	FRONT_PANEL_HIGH_SHUTDOWN	70
294 #define	FRONT_PANEL_LOW_SHUTDOWN	0
295 #define	FRONT_PANEL_HIGH_WARNING	60
296 #define	FRONT_PANEL_LOW_WARNING		5
297 #define	FRONT_PANEL_HIGH_POWER_OFF	75
298 #define	FRONT_PANEL_LOW_POWER_OFF	-5
299 /*
300  * Temperature sensor related data structure
301  */
302 typedef struct env_sensor {
303 	char		*name;			/* sensor name */
304 	char		*devfs_path;		/* sensor device devfs path */
305 	int		id;
306 	int		fd;			/* device file descriptor */
307 	char  		high_shutdown;
308 	char  		high_warning;
309 	char  		low_warning;
310 	char  		low_shutdown;
311 	char  		low_power_off;
312 	char  		high_power_off;
313 	int		error;			/* error flag */
314 	boolean_t 	present;		/* sensor present */
315 	tempr_t		cur_temp;		/* current temperature */
316 	time_t		warning_start;		/* warning start time (secs) */
317 	time_t		warning_tstamp;		/* last warning time (secs) */
318 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
319 	boolean_t 	shutdown_initiated;	/* shutdown initated */
320 } env_sensor_t;
321 
322 extern	env_sensor_t *sensor_lookup(char *sensor_name);
323 extern	int get_temperature(env_sensor_t *, tempr_t *);
324 
325 typedef struct env_disk {
326 	char		*name;			/* disk name */
327 	char		*devfs_path;	/* disk device devfs path */
328 	char		*physpath;	/* used to be probe for IDLW TIME */
329 	char		*nodepath;	/* used to detect presence of disk */
330 	uchar_t		id;
331 	int		fd;		/* device file descriptor */
332 	boolean_t	present;	/* disk present */
333 	boolean_t	tpage_supported;	/* Temperature page */
334 	int		current_temp;
335 	int		ref_temp;
336 	int		reliability_temp;
337 	uchar_t  	high_shutdown;
338 	uchar_t  	high_warning;
339 	uchar_t  	low_warning;
340 	uchar_t  	low_shutdown;
341 	time_t		warning_start;		/* warning start time (secs) */
342 	time_t		warning_tstamp;		/* last warning time (secs) */
343 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
344 	boolean_t 	shutdown_initiated;	/* shutdown initated */
345 } env_disk_t;
346 
347 extern	env_disk_t *disk_lookup(char *disk_name);
348 extern	int disk_temperature(env_disk_t *, tempr_t *);
349 
350 /*
351  * Fan information data structure
352  */
353 typedef int fanspeed_t;
354 
355 typedef struct env_fan {
356 	char		*name;			/* fan name */
357 	char		*devfs_path;	/* fan device devfs path */
358 	uchar_t		id;
359 	fanspeed_t	speed_min;		/* minimum speed */
360 	fanspeed_t	speed_max;		/* maximum speed */
361 	int		forced_speed;		/* forced (fixed) speed */
362 	int		fd;			/* device file descriptor */
363 	boolean_t	present;		/* fan present */
364 	int		last_status;		/* Fan status */
365 	uint8_t		cspeed;			/* Current speed (tach) */
366 	uint8_t		lspeed;			/* Last speed (tach) */
367 } env_fan_t;
368 
369 /*
370  * Tuneables
371  */
372 typedef struct env_tuneable {
373 	char		*name;
374 	char		type;
375 	void		*value;
376 	int		(*rfunc)(ptree_rarg_t *, void *);
377 	int		(*wfunc)(ptree_warg_t *, const void *);
378 	int		nbytes;
379 	picl_prophdl_t proph;
380 } env_tuneable_t;
381 
382 extern	env_fan_t *fan_lookup(char *fan_name);
383 extern	int get_fan_speed(env_fan_t *, fanspeed_t *);
384 extern	int set_fan_speed(env_fan_t *, fanspeed_t);
385 
386 extern int env_debug;
387 extern void envd_log(int pri, const char *fmt, ...);
388 
389 /*
390  * Various messages
391  */
392 #define	ENVD_PLUGIN_INIT_FAILED		\
393 	gettext("SUNW_piclenvd: initialization failed!\n")
394 
395 #define	ENVD_PICL_SETUP_FAILED		\
396 	gettext("SUNW_piclenvd: PICL setup failed!\n")
397 
398 #define	PM_THREAD_CREATE_FAILED		\
399 	gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
400 
401 #define	PM_THREAD_EXITING		\
402 	gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
403 
404 #define	DISK_TEMP_THREAD_EXITING		\
405 	gettext("SUNW_piclenvd: Disk temp thread exiting."	\
406 	" Disk temperature will not be monitored. errno:%d %s\n")
407 
408 #define	ENVTHR_THREAD_CREATE_FAILED	\
409 	gettext("SUNW_piclenvd: envthr thread creation failed!\n")
410 
411 #define	ENV_SHUTDOWN_MSG		\
412 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
413 	"limits (%d...%d). Shutting down the system.\n")
414 
415 #define	ENV_WARNING_MSG			\
416 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
417 	"operating limits (%d...%d).\n")
418 
419 #define	ENV_FAN_OPEN_FAIL		\
420 	gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
421 
422 #define	ENV_SENSOR_OPEN_FAIL		\
423 	gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
424 
425 #define	ENV_SENSOR_ACCESS_FAIL		\
426 	gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
427 
428 #define	ENV_SENSOR_ACCESS_OK		\
429 	gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
430 
431 #define	ENV_FAN_FAILURE_WARNING_MSG		\
432 	gettext("SUNW_piclenvd: %s has Failed.\n"	\
433 	"(rpm = %s status = %s)\n")
434 
435 #define	ENV_FAN_OK_MSG		\
436 	gettext("SUNW_piclenvd: %s is OKAY.\n")
437 
438 
439 #ifdef	__cplusplus
440 }
441 #endif
442 
443 #endif	/* _ENVD_H */
444