xref: /illumos-gate/usr/src/cmd/picl/plugins/sun4u/enchilada/envd/envd.h (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
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 2004 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 #define	DISK_SCAN_INTERVAL	10
40 #define	DISK_HIGH_WARN_TEMPERATURE	55
41 #define	DISK_LOW_WARN_TEMPERATURE	5
42 #define	DISK_HIGH_SHUTDOWN_TEMPERATURE	60
43 #define	DISK_LOW_SHUTDOWN_TEMPERATURE	0
44 #define	DISK_INVALID_TEMP	0xFFFF
45 #define	LSI1030_VENDOR_ID	0x1000
46 #define	LSI1030_DEVICE_ID	0x30
47 #define	SENSORPOLL_INTERVAL	4
48 #define	INTERRUPTPOLL_INTERVAL	2
49 #define	WARNING_INTERVAL	30
50 #define	DISK_WARNING_INTERVAL	30
51 #define	DISK_WARNING_DURATION	20
52 #define	SHUTDOWN_INTERVAL	60
53 #define	DISK_SHUTDOWN_INTERVAL	30
54 #define	ENV_CONF_FILE		"envmodel.conf"
55 #define	TUNABLE_CONF_FILE	"piclenvd.conf"
56 #define	PM_DEVICE		"/dev/pm"
57 #define	SHUTDOWN_CMD		"/usr/sbin/shutdown -y -g 60 -i 5"
58 #define	PICL_PLUGINS_NODE	"plugins"
59 #define	PICL_ENVIRONMENTAL_NODE	"environmental"
60 
61 /*
62  * ADC Sample of ADM in Khz, currently 11.2 KHz
63  */
64 #define	ADCSAMPLE		11250
65 
66 /*
67  * Enchilada Platform Details
68  */
69 #define	MAX_SENSORS	6
70 #define	MAX_FANS	4
71 #define	MAX_HWMS	2
72 
73 /*
74  * ADM1031 Hardware Monitor IDs
75  * Used as index into arrays
76  */
77 #define	CPU_HWM_ID	0
78 #define	SYS_HWM_ID	1
79 
80 #define	CPU_HWM_DEVFS	\
81 	"/devices/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:control"
82 #define	SYS_HWM_DEVFS	\
83 	"/devices/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:control"
84 
85 #define	DISK0_PHYSPATH	\
86 	"/pci@1d,700000/scsi@4/sd@0,0"
87 
88 #define	DISK1_PHYSPATH	\
89 	"/pci@1d,700000/scsi@4/sd@1,0"
90 
91 #define	ENV_DISK0_DEVFS	\
92 	"/devices/pci@1d,700000/scsi@4/sd@0,0:a,raw"
93 
94 #define	ENV_DISK1_DEVFS	\
95 	"/devices/pci@1d,700000/scsi@4/sd@1,0:a,raw"
96 
97 #define	DISK0_NODE_PATH	\
98 	"name:/platform/pci@1d,700000/scsi@4/sd@0,0"
99 
100 #define	DISK1_NODE_PATH	\
101 	"name:/platform/pci@1d,700000/scsi@4/sd@1,0"
102 
103 
104 #define	SCSI_CONTROLLER_NODE_PATH	\
105 	"name:/platform/pci@1d,700000/scsi@4"
106 
107 #define	HWM_FAN1	0
108 #define	HWM_FAN2	1
109 
110 /*
111  * Enchilada sensor IDs as used in FRUID segment
112  */
113 #define	CPU0_SENSOR_ID		0
114 #define	CPU1_SENSOR_ID		1
115 #define	INT_AMB0_SENSOR_ID	5
116 #define	SYS_OUT_SENSOR_ID	3
117 #define	INT_AMB1_SENSOR_ID	4
118 #define	SYS_IN_SENSOR_ID	2
119 #define	MAX_SENSOR_ID		5
120 
121 /*
122  * Enchilada fan IDs used in FRUID segment
123  */
124 #define	CPU0_FAN_ID		0
125 #define	CPU1_FAN_ID		1
126 #define	SYSTEM_OUT_FAN_ID	2
127 #define	SYSTEM_INTAKE_FAN_ID	3
128 #define	DIMM_FAN_ID		4
129 
130 #define	DISK0_ID		0
131 #define	DISK1_ID		1
132 
133 
134 /* CPU Path Names */
135 #define	CPU0_PATH		"_class:/jbus/cpu?ID=0"
136 #define	CPU1_PATH		"_class:/jbus/cpu?ID=1"
137 
138 /* DIMM Fan controller path Name */
139 #define	DIMM_FAN_CONTROLLER_PATH	\
140 	"name:/platform/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,52"
141 /*
142  * devfs-path for various fans and their min/max speeds
143  */
144 #define	ENV_CPU0_FAN_DEVFS	\
145 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:fan_1"
146 #define	ENV_CPU1_FAN_DEVFS	\
147 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:fan_2"
148 #define	ENV_SYSTEM_INTAKE_FAN_DEVFS	\
149 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:fan_1"
150 #define	ENV_SYSTEM_OUT_FAN_DEVFS	\
151 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:fan_2"
152 #define	ENV_DIMM_FAN_DEVFS	\
153 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,52:fan_1"
154 
155 #define	FAN_RANGE_DEFAULT	4
156 #define	CPU_FAN_SPEED_MIN	14
157 #define	CPU_FAN_SPEED_MAX	100
158 
159 #define	SYSTEM_OUT_FAN_SPEED_MIN	14
160 #define	SYSTEM_OUT_FAN_SPEED_MAX	100
161 
162 #define	SYSTEM_INTAKE_FAN_SPEED_MIN	14
163 #define	SYSTEM_INTAKE_FAN_SPEED_MAX	100
164 
165 
166 /*
167  * devfs-path for various temperature sensors and CPU platform path
168  */
169 #define	SENSOR_CPU0_DIE_DEVFS	\
170 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:remote_1"
171 #define	SENSOR_CPU1_DIE_DEVFS	\
172 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:remote_2"
173 #define	SENSOR_INT_AMB_0_DEVFS	\
174 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,58:local"
175 
176 #define	SENSOR_SYS_IN_DEVFS	\
177 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:remote_1"
178 #define	SENSOR_SYS_OUT_DEVFS	\
179 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:remote_2"
180 #define	SENSOR_INT_AMB_1_DEVFS	\
181 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:local"
182 
183 /*
184  * Temperature type
185  */
186 typedef int16_t tempr_t;
187 
188 
189 /*
190  * Fan names
191  */
192 #define	ENV_SYSTEM_OUT_FAN	"outtake-fan"
193 #define	ENV_CPU0_FAN		"cpu0-fan"
194 #define	ENV_SYSTEM_INTAKE_FAN	"intake-fan"
195 #define	ENV_CPU1_FAN		"cpu1-fan"
196 #define	ENV_DIMM_FAN		"dimm-fan"
197 
198 #define	ENV_DISK0		"hard-disk0"
199 #define	ENV_DISK1		"hard-disk1"
200 /*
201  * Sensor names
202  */
203 #define	SENSOR_CPU0_DIE		"cpu0"
204 #define	SENSOR_CPU1_DIE		"cpu1"
205 #define	SENSOR_INT_AMB_0	"int-amb0"
206 #define	SENSOR_SYS_IN		"sys-in"
207 #define	SENSOR_SYS_OUT		"sys-out"
208 #define	SENSOR_INT_AMB_1	"int-amb1"
209 
210 /* Bit Map of ADM 1031 Status 1/2 Registers */
211 enum adm1031 {
212 	FANFAULT = 0x2,
213 	REMOTEHIGH = 0x4,
214 	REMOTELOW = 0x8,
215 	REMOTETHERN = 0x10,
216 	LHIGH = 0x40,
217 	LLOW  = 0x80
218 } adm1031_t;
219 
220 /* ADM Stat 1/2 Mask */
221 enum adm1031Mask {
222 	STAT1MASK = 0xdc,
223 	STAT2MASK = 0x1c
224 } adm1031Mask_t;
225 
226 /*
227  * ES segment related structures
228  */
229 typedef struct id_off {
230 	uint_t id;
231 	ushort_t offset;
232 } id_off_t;
233 
234 typedef struct fan_ctl_pair {
235 	uchar_t tMin;
236 	uchar_t tRange;
237 } fan_ctl_pair_t;
238 
239 typedef struct Correction_Pair {
240 	uchar_t measured;
241 	uchar_t corrected;
242 } Correction_Pair_t;
243 
244 #define	ES_SENSOR_POLICY_LEN	8
245 #define	ES_CORRECTION_PAIRS	12
246 
247 typedef struct sensor_ctrl_blk {
248 	uchar_t  high_power_off;
249 	uchar_t  high_shutdown;
250 	uchar_t  high_warning;
251 	uchar_t  low_warning;
252 	uchar_t  low_shutdown;
253 	uchar_t  low_power_off;
254 	uchar_t  sensorPolicy[ES_SENSOR_POLICY_LEN];
255 	ushort_t correctionEntries;
256 	Correction_Pair_t correctionPair[ES_CORRECTION_PAIRS];
257 } sensor_ctrl_blk_t;
258 
259 
260 #define	ES_FAN_CTL_PAIRS	4
261 
262 typedef struct fan_ctrl_blk {
263 	uchar_t  tSpinUp;
264 	uchar_t  minFanSpeed;
265 	ushort_t setPoint;
266 	ushort_t loopGain;
267 	ushort_t loopBias;
268 	ushort_t hysteresis;
269 	ushort_t fanViabTestInt;
270 	ushort_t fanViabTestThresh;
271 	ushort_t grossFanThresh;
272 	uchar_t no_ctl_pairs;
273 	fan_ctl_pair_t fan_ctl_pairs[ES_FAN_CTL_PAIRS];
274 } fan_ctrl_blk_t;
275 
276 #define	TEMP_IN_WARNING_RANGE(val, sensorp) \
277 	((val) > (sensorp)->es_ptr->high_warning || \
278 	(val) < (char)((sensorp)->es_ptr->low_warning))
279 
280 #define	TEMP_IN_SHUTDOWN_RANGE(val, sensorp) \
281 	((val) > (sensorp)->es_ptr->high_shutdown || \
282 	(val) < (char)((sensorp)->es_ptr->low_shutdown))
283 
284 #define	DISK_TEMP_IN_WARNING_RANGE(val, diskp) \
285 	((val) > (diskp)->high_warning || \
286 	(val) < (char)((diskp)->low_warning))
287 
288 #define	DISK_TEMP_IN_SHUTDOWN_RANGE(val, diskp) \
289 	((val) > (diskp)->high_shutdown || \
290 	(val) < (char)((diskp)->low_shutdown))
291 
292 /*
293  * Macros to fetch 16 and 32 bit data from unaligned address
294  */
295 #define	GET_UNALIGN16(addr)	\
296 	(((*(uint8_t *)addr) << 8) | *((uint8_t *)addr + 1))
297 
298 #define	GET_UNALIGN32(addr)	\
299 	(((*(uint8_t *)addr) << 24) | (*((uint8_t *)addr + 1) << 16) | \
300 	((*((uint8_t *)addr + 2)) << 8) | (*((uint8_t *)addr + 3)))
301 
302 
303 /*
304  * SEEPROM section header layout and location
305  */
306 typedef struct {
307 	uint8_t		header_tag;		/* section header tag */
308 	uint8_t		header_version[2];	/* header version (msb) */
309 	uint8_t		header_length;		/* header length */
310 	uint8_t		header_crc8;		/* crc8 */
311 	uint8_t		segment_count;		/* total number of segments */
312 } section_layout_t;
313 
314 #define	SECTION_HDR_OFFSET	0x1800
315 #define	SECTION_HDR_TAG		0x08
316 #define	SECTION_HDR_VER		0x0001
317 #define	SECTION_HDR_LENGTH	0x06
318 
319 /*
320  * SEEPROM segment header layout
321  */
322 typedef struct {
323 	uint16_t	name;		/* segment name */
324 	uint16_t	descriptor[2];	/* descriptor (msb) */
325 	uint16_t	offset;		/* segment data offset */
326 	uint16_t	length;		/* segment length */
327 } segment_layout_t;
328 
329 #define	ENVSEG_NAME		0x4553	/* environmental segment name */
330 #define	ENVSEG_VERSION		2	/* environmental segment version */
331 
332 #define	SENSOR_WARN		1
333 #define	SENSOR_OK		0
334 
335 /*
336  * SEEPROM environmental segment header layout
337  */
338 typedef struct {
339 	uint16_t	sensor_id[2];	/* unique sensor ID (on this FRU) */
340 	uint16_t	offset;		/* sensor data record offset */
341 } envseg_sensor_t;
342 
343 typedef struct {
344 	uint8_t		version;	/* envseg version */
345 	uint8_t		sensor_count;	/* total number of sensor records */
346 	envseg_sensor_t	sensors[1];	/* sensor table (variable length) */
347 } envseg_layout_t;
348 
349 /*
350  * FRU envseg list
351  */
352 typedef struct fruenvseg {
353 	struct fruenvseg	*next;		/* next entry */
354 	char			*fru;		/* FRU SEEPROM path */
355 	void			*envsegbufp;	/* envseg data buffer */
356 	int			envseglen;	/* envseg length */
357 } fruenvseg_t;
358 
359 #define	I2C_DEVFS	"/devices/pci@1e,600000/isa@7/i2c@0,320"
360 #define	MBFRU_DEV	"/motherboard-fru-prom@0,a2:motherboard-fru-prom"
361 #define	FRU_SEEPROM_NAME	"motherboard-fru-prom"
362 
363 /*
364  * Table data structures
365  */
366 
367 typedef struct {
368 	int32_t	x;
369 	int32_t	y;
370 } point_t;
371 
372 typedef struct {
373 	int	nentries;
374 	point_t	*xymap;
375 } table_t;
376 
377 /*
378  * Temperature sensor related data structure
379  */
380 typedef struct env_sensor {
381 	char		*name;			/* sensor name */
382 	char		*devfs_path;		/* sensor device devfs path */
383 	sensor_ctrl_blk_t	*es_ptr;
384 	int		id;
385 	int		hwm_id;
386 	void		*fanp;
387 	int		fd;			/* device file descriptor */
388 	int		error;			/* error flag */
389 	boolean_t 	present;		/* sensor present */
390 	tempr_t		cur_temp;		/* current temperature */
391 	time_t		warning_tstamp;		/* last warning time (secs) */
392 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
393 	boolean_t 	shutdown_initiated;	/* shutdown initated */
394 	table_t		*crtbl;			/* Correction Table */
395 	tempr_t		tmin;
396 } env_sensor_t;
397 
398 extern	env_sensor_t *sensor_lookup(char *sensor_name);
399 extern	int get_temperature(env_sensor_t *, tempr_t *);
400 
401 typedef struct env_disk {
402 	char		*name;			/* disk name */
403 	char		*devfs_path;	/* disk device devfs path */
404 	char		*physpath;	/* used to be probe for IDLW TIME */
405 	char		*nodepath;	/* used to detect presence of disk */
406 	uchar_t		id;
407 	int		fd;		/* device file descriptor */
408 	boolean_t	present;	/* disk present */
409 	boolean_t	tpage_supported;	/* Temperature page */
410 	int		current_temp;
411 	int		ref_temp;
412 	int		reliability_temp;
413 	uchar_t  	high_shutdown;
414 	uchar_t  	high_warning;
415 	uchar_t  	low_warning;
416 	uchar_t  	low_shutdown;
417 	time_t		warning_start;		/* warning start time (secs) */
418 	time_t		warning_tstamp;		/* last warning time (secs) */
419 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
420 	boolean_t 	shutdown_initiated;	/* shutdown initated */
421 } env_disk_t;
422 
423 extern	env_disk_t *disk_lookup(char *disk_name);
424 extern	int disk_temperature(env_disk_t *, tempr_t *);
425 
426 /*
427  * Fan information data structure
428  */
429 typedef int fanspeed_t;
430 
431 typedef struct env_fan {
432 	char		*name;			/* fan name */
433 	char		*devfs_path;	/* fan device devfs path */
434 	fan_ctrl_blk_t	*es_ptr;
435 	uchar_t		id;
436 	fanspeed_t	speed_min;		/* minimum speed */
437 	fanspeed_t	speed_max;		/* maximum speed */
438 	int		forced_speed;		/* forced (fixed) speed */
439 	int		fd;			/* device file descriptor */
440 	boolean_t	present;		/* fan present */
441 	int		speedrange;		/* speed range N */
442 	int		fanstat;		/* Fan status */
443 	uint8_t		cspeed;			/* Current speed (tach) */
444 	uint8_t		lspeed;			/* Last speed (tach) */
445 	int		conccnt;		/* Concurrent tach count */
446 } env_fan_t;
447 
448 /*
449  * Tuneables
450  */
451 typedef struct env_tuneable {
452 	char		*name;
453 	char		type;
454 	void		*value;
455 	int		(*rfunc)(ptree_rarg_t *, void *);
456 	int		(*wfunc)(ptree_warg_t *, const void *);
457 	int		nbytes;
458 	picl_prophdl_t proph;
459 } env_tuneable_t;
460 
461 extern	env_fan_t *fan_lookup(char *fan_name);
462 extern	int get_fan_speed(env_fan_t *, fanspeed_t *);
463 extern	int set_fan_speed(env_fan_t *, fanspeed_t);
464 
465 extern int env_debug;
466 extern void envd_log(int pri, const char *fmt, ...);
467 
468 /*
469  * Various messages
470  */
471 #define	ENVD_PLUGIN_INIT_FAILED		\
472 	gettext("SUNW_piclenvd: initialization failed!\n")
473 
474 #define	ENVD_PICL_SETUP_FAILED		\
475 	gettext("SUNW_piclenvd: PICL setup failed!\n")
476 
477 #define	PM_THREAD_CREATE_FAILED		\
478 	gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
479 
480 #define	PM_THREAD_EXITING		\
481 	gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
482 
483 #define	DISK_TEMP_THREAD_EXITING		\
484 	gettext("SUNW_piclenvd: Disk temp thread exiting."	\
485 	" Disk temperature will not be monitored. errno:%d %s\n")
486 
487 #define	ENVTHR_THREAD_CREATE_FAILED	\
488 	gettext("SUNW_piclenvd: envthr thread creation failed!\n")
489 
490 #define	ENV_SHUTDOWN_MSG		\
491 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
492 	"limits (%d...%d). Shutting down the system.\n")
493 
494 #define	ENV_DIMM_FAN_FAILURE_SHUTDOWN_MSG		\
495 	gettext("SUNW_piclenvd: %s has Failed.\n"	\
496 	"(rpm = %s status = %s command = %s debug = %s).\n" \
497 	"Shutting down the system to protect the memory modules.\n")
498 
499 #define	ENV_WARNING_MSG			\
500 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
501 	"operating limits (%d...%d).\n")
502 
503 #define	ENV_FAN_OPEN_FAIL		\
504 	gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
505 
506 #define	ENV_SENSOR_OPEN_FAIL		\
507 	gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
508 
509 #define	ENV_SENSOR_ACCESS_FAIL		\
510 	gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
511 
512 #define	ENV_SENSOR_ACCESS_OK		\
513 	gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
514 
515 #define	ENV_FRU_OPEN_FAIL		\
516 	gettext("SUNW_piclenvd: can't open FRU SEEPROM path:%s errno:%d %s\n")
517 
518 #define	ENV_FRU_BAD_ENVSEG		\
519 	gettext("SUNW_piclenvd: version mismatch or environmental segment " \
520 	"header too short in FRU SEEPROM %s\n")
521 
522 #define	ENV_FRU_BAD_SENSOR_ENTRY	\
523 	gettext("SUNW_piclenvd: discarding bad sensor entry (sensor_id " \
524 	"%x sensor '%s') in FRU SEEPROM %s\n")
525 
526 #define	ENV_FRU_SENSOR_MAP_NOMEM	\
527 	gettext("SUNW_piclenvd: out of memory, discarding sensor map for " \
528 	"sensor_id %x (sensor '%s') in FRU SEEPROM %s\n")
529 
530 #define	ENV_ADM_OPEN_FAIL		\
531 	gettext("SUNW_piclenvd: can't open hwm path:%s errno:%d %s\n")
532 
533 #define	ENV_ADM_MANUAL_MODE \
534 	gettext("SUNW_piclenvd: Cannot change the ADM Chip to Manual mode")
535 
536 #define	ENV_ADM_AUTO_MODE \
537 	gettext("SUNW_piclenvd: Cannot change the ADM Chip to Auto mode")
538 
539 #define	ENV_FAN_FAULT \
540 	gettext("SUNW_piclenvd: ADM %s, Fan %s Fault")
541 
542 #ifdef	__cplusplus
543 }
544 #endif
545 
546 #endif	/* _ENVD_H */
547