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