xref: /illumos-gate/usr/src/cmd/picl/plugins/sun4u/taco/envd/envd.h (revision 8b80e8cb6855118d46f605e91b5ed4ce83417395)
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 2003 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	SENSORPOLL_INTERVAL	4
40 #define	INTERRUPTPOLL_INTERVAL	2
41 #define	WARNING_INTERVAL	30
42 #define	SHUTDOWN_INTERVAL	60
43 #define	ENV_CONF_FILE		"envmodel.conf"
44 #define	TUNABLE_CONF_FILE	"piclenvd.conf"
45 #define	PM_DEVICE		"/dev/pm"
46 #define	SHUTDOWN_CMD		"/usr/sbin/shutdown -y -g 60 -i 5"
47 #define	PICL_PLUGINS_NODE	"plugins"
48 #define	PICL_ENVIRONMENTAL_NODE	"environmental"
49 
50 /*
51  * ADC Sample of ADM in Khz, currently 11.2 KHz
52  */
53 #define	ADCSAMPLE		11250
54 
55 /*
56  * Taco Platform Details
57  */
58 #define	MAX_SENSORS	3
59 #define	MAX_FANS	2
60 #define	MAX_HWMS	1
61 
62 /*
63  * ADM1031 Hardware Monitor IDs
64  * Used as index into arrays
65  */
66 #define	CPU_HWM_ID	0
67 
68 #define	CPU_HWM_DEVFS	\
69 	"/devices/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:control"
70 
71 #define	HWM_FAN1	0
72 #define	HWM_FAN2	1
73 
74 /*
75  * Taco sensor IDs as used in FRUID segment
76  */
77 #define	SYS_IN_SENSOR_ID	0
78 #define	CPU_SENSOR_ID		1
79 #define	INT_AMB_SENSOR_ID	2
80 #define	MAX_SENSOR_ID		2
81 
82 /*
83  * Taco fan IDs used in FRUID segment
84  */
85 #define	SYSTEM_FAN_ID		0
86 #define	CPU_FAN_ID		1
87 #define	MAX_FAN_ID		1
88 
89 /*
90  * devfs-path for various fans and their min/max speeds
91  */
92 #define	ENV_CPU_FAN_DEVFS	\
93 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:fan_2"
94 #define	ENV_SYSTEM_FAN_DEVFS	\
95 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:fan_1"
96 
97 #define	FAN_RANGE_DEFAULT	4
98 #define	CPU_FAN_SPEED_MIN	14
99 #define	CPU_FAN_SPEED_MAX	100
100 
101 #define	SYSTEM_OUT_FAN_SPEED_MIN	14
102 #define	SYSTEM_OUT_FAN_SPEED_MAX	100
103 
104 #define	SYSTEM_INTAKE_FAN_SPEED_MIN	14
105 #define	SYSTEM_INTAKE_FAN_SPEED_MAX	100
106 
107 
108 
109 /*
110  * devfs-path for various temperature sensors and CPU platform path
111  */
112 #define	SENSOR_CPU_DIE_DEVFS	\
113 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:remote_2"
114 #define	SENSOR_SYS_IN_DEVFS	\
115 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:remote_1"
116 #define	SENSOR_INT_AMB_DEVFS	\
117 	"/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:local"
118 
119 /*
120  * Temperature type
121  */
122 typedef int16_t tempr_t;
123 
124 
125 /*
126  * Fan names
127  */
128 #define	ENV_SYSTEM_INTAKE_FAN	"intake-fan"
129 #define	ENV_SYSTEM_OUT_FAN	"outtake-fan"
130 #define	ENV_CPU_FAN		"cpu-fan"
131 #define	ENV_SYSTEM_IN_OUT_FANS	"intake-outtake-fans"
132 
133 /*
134  * Sensor names
135  */
136 #define	SENSOR_CPU_DIE		"cpu"
137 #define	SENSOR_SYS_IN		"sys-in"
138 #define	SENSOR_INT_AMB		"int-amb"
139 
140 /* Bit Map of ADM 1031 Status 1/2 Registers */
141 enum adm1031 {
142 	FANFAULT = 0x2,
143 	REMOTEHIGH = 0x4,
144 	REMOTELOW = 0x8,
145 	REMOTETHERN = 0x10,
146 	LHIGH = 0x40,
147 	LLOW  = 0x80
148 } adm1031_t;
149 
150 /* ADM Stat 1/2 Mask */
151 enum adm1031Mask {
152 	STAT1MASK = 0xdc,
153 	STAT2MASK = 0x1c
154 } adm1031Mask_t;
155 
156 /*
157  * ES segment related structures
158  */
159 typedef struct id_off {
160 	uint_t id;
161 	ushort_t offset;
162 } id_off_t;
163 
164 typedef struct fan_ctl_pair {
165 	uchar_t tMin;
166 	uchar_t tRange;
167 } fan_ctl_pair_t;
168 
169 typedef struct Correction_Pair {
170 	uchar_t measured;
171 	uchar_t corrected;
172 } Correction_Pair_t;
173 
174 #define	ES_SENSOR_POLICY_LEN	8
175 #define	ES_CORRECTION_PAIRS	12
176 
177 typedef struct sensor_ctrl_blk {
178 	uchar_t  high_power_off;
179 	uchar_t  high_shutdown;
180 	uchar_t  high_warning;
181 	uchar_t  low_warning;
182 	uchar_t  low_shutdown;
183 	uchar_t  low_power_off;
184 	uchar_t  sensorPolicy[ES_SENSOR_POLICY_LEN];
185 	ushort_t correctionEntries;
186 	Correction_Pair_t correctionPair[ES_CORRECTION_PAIRS];
187 } sensor_ctrl_blk_t;
188 
189 
190 #define	ES_FAN_CTL_PAIRS	4
191 
192 typedef struct fan_ctrl_blk {
193 	uchar_t  tSpinUp;
194 	uchar_t  minFanSpeed;
195 	ushort_t setPoint;
196 	ushort_t loopGain;
197 	ushort_t loopBias;
198 	ushort_t hysteresis;
199 	ushort_t fanViabTestInt;
200 	ushort_t fanViabTestThresh;
201 	ushort_t grossFanThresh;
202 	uchar_t no_ctl_pairs;
203 	fan_ctl_pair_t fan_ctl_pairs[ES_FAN_CTL_PAIRS];
204 } fan_ctrl_blk_t;
205 
206 #define	TEMP_IN_WARNING_RANGE(val, sensorp) \
207 	((val) > (sensorp)->es_ptr->high_warning || \
208 		(val) < (char)((sensorp)->es_ptr->low_warning))
209 
210 #define	TEMP_IN_SHUTDOWN_RANGE(val, sensorp) \
211 	((val) > (sensorp)->es_ptr->high_shutdown || \
212 		(val) < (char)((sensorp)->es_ptr->low_shutdown))
213 
214 /*
215  * Macros to fetch 16 and 32 bit data from unaligned address
216  */
217 #define	GET_UNALIGN16(addr)	\
218 	(((*(uint8_t *)addr) << 8) | *((uint8_t *)addr + 1))
219 
220 #define	GET_UNALIGN32(addr)	\
221 	(((*(uint8_t *)addr) << 24) | (*((uint8_t *)addr + 1) << 16) | \
222 	((*((uint8_t *)addr + 2)) << 8) | (*((uint8_t *)addr + 3)))
223 
224 /*
225  * SEEPROM section header layout and location
226  */
227 typedef struct {
228 	uint8_t		header_tag;		/* section header tag */
229 	uint8_t		header_version[2];	/* header version (msb) */
230 	uint8_t		header_length;		/* header length */
231 	uint8_t		header_crc8;		/* crc8 */
232 	uint8_t		segment_count;		/* total number of segments */
233 } section_layout_t;
234 
235 #define	SECTION_HDR_OFFSET	0x1800
236 #define	SECTION_HDR_TAG		0x08
237 #define	SECTION_HDR_VER		0x0001
238 #define	SECTION_HDR_LENGTH	0x06
239 
240 /*
241  * SEEPROM segment header layout
242  */
243 typedef struct {
244 	uint16_t	name;		/* segment name */
245 	uint16_t	descriptor[2];	/* descriptor (msb) */
246 	uint16_t	offset;		/* segment data offset */
247 	uint16_t	length;		/* segment length */
248 } segment_layout_t;
249 
250 #define	ENVSEG_NAME		0x4553	/* environmental segment name */
251 #define	ENVSEG_VERSION		2	/* environmental segment version */
252 
253 #define	SENSOR_WARN		1
254 #define	SENSOR_OK		0
255 
256 /*
257  * SEEPROM environmental segment header layout
258  */
259 typedef struct {
260 	uint16_t	sensor_id[2];	/* unique sensor ID (on this FRU) */
261 	uint16_t	offset;		/* sensor data record offset */
262 } envseg_sensor_t;
263 
264 typedef struct {
265 	uint8_t		version;	/* envseg version */
266 	uint8_t		sensor_count;	/* total number of sensor records */
267 	envseg_sensor_t	sensors[1];	/* sensor table (variable length) */
268 } envseg_layout_t;
269 
270 /*
271  * FRU envseg list
272  */
273 typedef struct fruenvseg {
274 	struct fruenvseg	*next;		/* next entry */
275 	char			*fru;		/* FRU SEEPROM path */
276 	void			*envsegbufp;	/* envseg data buffer */
277 	int			envseglen;	/* envseg length */
278 } fruenvseg_t;
279 
280 #define	I2C_DEVFS	"/devices/pci@1e,600000/isa@7/i2c@0,320"
281 #define	MBFRU_DEV	"/motherboard-fru-prom@0,a8:motherboard-fru-prom"
282 #define	FRU_SEEPROM_NAME	"motherboard-fru-prom"
283 /*
284  * Table data structures
285  */
286 typedef struct {
287 	int32_t	x;
288 	int32_t	y;
289 } point_t;
290 
291 typedef struct {
292 	int	nentries;
293 	point_t	*xymap;
294 } table_t;
295 
296 /*
297  * Temperature sensor related data structure
298  */
299 typedef struct env_sensor {
300 	char		*name;			/* sensor name */
301 	char		*devfs_path;		/* sensor device devfs path */
302 	sensor_ctrl_blk_t *es_ptr;
303 	uchar_t		id;
304 	int		hwm_id;
305 	void		*fanp;
306 	int		fd;			/* device file descriptor */
307 	int		error;			/* error flag */
308 	boolean_t 	present;		/* sensor present */
309 	tempr_t		cur_temp;		/* current temperature */
310 	time_t		warning_tstamp;		/* last warning time (secs) */
311 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
312 	boolean_t 	shutdown_initiated;	/* shutdown initated */
313 	table_t		*crtbl;			/* Correction table */
314 	tempr_t		tmin;
315 } env_sensor_t;
316 
317 extern	env_sensor_t *sensor_lookup(char *sensor_name);
318 extern	int get_temperature(env_sensor_t *, tempr_t *);
319 
320 /*
321  * Fan information data structure
322  */
323 typedef int fanspeed_t;
324 
325 typedef struct env_fan {
326 	char		*name;			/* fan name */
327 	char		*devfs_path;		/* fan device devfs path */
328 	fan_ctrl_blk_t	*es_ptr;
329 	uchar_t		id;
330 	fanspeed_t	speed_min;		/* minimum speed */
331 	fanspeed_t	speed_max;		/* maximum speed */
332 	int		forced_speed;		/* forced (fixed) speed */
333 	int		fd;			/* device file descriptor */
334 	boolean_t	present;		/* fan present */
335 	int		speedrange;		/* speed range N */
336 	int		fanstat;		/* Fan status */
337 	uint8_t		cspeed;			/* Current speed (tach) */
338 	uint8_t		lspeed;			/* Last speed (tach) */
339 	int		conccnt;		/* Concurrent tach count */
340 } env_fan_t;
341 
342 /*
343  * Tuneables
344  */
345 typedef struct env_tuneable {
346 	char		*name;
347 	char		type;
348 	void		*value;
349 	int		(*rfunc)(ptree_rarg_t *, void *);
350 	int		(*wfunc)(ptree_warg_t *, const void *);
351 	int		nbytes;
352 	picl_prophdl_t proph;
353 } env_tuneable_t;
354 
355 extern	env_fan_t *fan_lookup(char *fan_name);
356 extern	int get_fan_speed(env_fan_t *, fanspeed_t *);
357 extern	int set_fan_speed(env_fan_t *, fanspeed_t);
358 
359 extern int env_debug;
360 extern void envd_log(int pri, const char *fmt, ...);
361 
362 /*
363  * Various messages
364  */
365 #define	ENVD_PLUGIN_INIT_FAILED		\
366 	gettext("SUNW_piclenvd: initialization failed!\n")
367 
368 #define	ENVD_PICL_SETUP_FAILED		\
369 	gettext("SUNW_piclenvd: PICL setup failed!\n")
370 
371 #define	PM_THREAD_CREATE_FAILED		\
372 	gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
373 
374 #define	PM_THREAD_EXITING		\
375 	gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
376 
377 #define	ENVTHR_THREAD_CREATE_FAILED		\
378 	gettext("SUNW_piclenvd: envthr thread creation failed!\n")
379 
380 #define	ENV_SHUTDOWN_MSG		\
381 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
382 	"limits (%d...%d). Shutting down the system.\n")
383 
384 #define	ENV_WARNING_MSG			\
385 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
386 	"operating limits (%d...%d).\n")
387 
388 #define	ENV_FAN_OPEN_FAIL		\
389 	gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
390 
391 #define	ENV_SENSOR_OPEN_FAIL		\
392 	gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
393 
394 #define	ENV_SENSOR_ACCESS_FAIL		\
395 	gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
396 
397 #define	ENV_SENSOR_ACCESS_OK		\
398 	gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
399 
400 #define	ENV_FRU_OPEN_FAIL		\
401 	gettext("SUNW_piclenvd: can't open FRU SEEPROM path:%s errno:%d %s\n")
402 
403 #define	ENV_FRU_BAD_ENVSEG		\
404 	gettext("SUNW_piclenvd: version mismatch or environmental segment " \
405 	"header too short in FRU SEEPROM %s\n")
406 
407 #define	ENV_FRU_BAD_SENSOR_ENTRY	\
408 	gettext("SUNW_piclenvd: discarding bad sensor entry (sensor_id " \
409 	"%x sensor '%s') in FRU SEEPROM %s\n")
410 
411 #define	ENV_FRU_SENSOR_MAP_NOMEM	\
412 	gettext("SUNW_piclenvd: out of memory, discarding sensor map for " \
413 	"sensor_id %x (sensor '%s') in FRU SEEPROM %s\n")
414 
415 #define	ENV_ADM_OPEN_FAIL		\
416 	gettext("SUNW_piclenvd: can't open hwm path:%s errno:%d %s\n")
417 
418 #define	ENV_ADM_MANUAL_MODE \
419 	gettext("SUNW_piclenvd: Cannot change the ADM Chip to Manual mode")
420 
421 #define	ENV_ADM_AUTO_MODE \
422 	gettext("SUNW_piclenvd: Cannot change the ADM Chip to Auto mode")
423 
424 #define	ENV_FAN_FAULT \
425 	gettext("SUNW_piclenvd: ADM %s, Fan %s Fault")
426 #ifdef	__cplusplus
427 }
428 #endif
429 
430 #endif	/* _ENVD_H */
431