1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_ENVD_H
28*7c478bd9Sstevel@tonic-gate #define	_ENVD_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <libintl.h>
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
36*7c478bd9Sstevel@tonic-gate extern "C" {
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #define	SENSOR_POLL_INTERVAL 	4			/* in seconds */
40*7c478bd9Sstevel@tonic-gate #define	WARNING_INTERVAL	30			/* in seconds */
41*7c478bd9Sstevel@tonic-gate #define	WARNING_DURATION	28			/* in seconds */
42*7c478bd9Sstevel@tonic-gate #define	SHUTDOWN_INTERVAL	60			/* in seconds */
43*7c478bd9Sstevel@tonic-gate #define	ENV_CONF_FILE		"piclenvd.conf"
44*7c478bd9Sstevel@tonic-gate #define	PM_DEVICE		"/dev/pm"
45*7c478bd9Sstevel@tonic-gate #define	SHUTDOWN_CMD		"/usr/sbin/shutdown -y -g 60 -i 5"
46*7c478bd9Sstevel@tonic-gate #define	ENVMODEL_CONF_FILE	"envmodel.conf"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Macros to fetch 16 and 32 bit data from unaligned address
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate #define	GET_UNALIGN16(addr)	\
52*7c478bd9Sstevel@tonic-gate 	(((*(uint8_t *)addr) << 8) | *((uint8_t *)addr+1))
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #define	GET_UNALIGN32(addr)	\
55*7c478bd9Sstevel@tonic-gate 	(((*(uint8_t *)addr) << 24) | (*((uint8_t *)addr+1) << 16) | \
56*7c478bd9Sstevel@tonic-gate 	((*((uint8_t *)addr+2)) << 8) | (*((uint8_t *)addr+3)))
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * SEEPROM section header layout and location
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate typedef struct {
63*7c478bd9Sstevel@tonic-gate 	uint8_t		header_tag;		/* section header tag */
64*7c478bd9Sstevel@tonic-gate 	uint8_t		header_version[2];	/* header version (msb) */
65*7c478bd9Sstevel@tonic-gate 	uint8_t		header_length;		/* header length */
66*7c478bd9Sstevel@tonic-gate 	uint8_t		header_crc8;		/* crc8 */
67*7c478bd9Sstevel@tonic-gate 	uint8_t		segment_count;		/* total number of segments */
68*7c478bd9Sstevel@tonic-gate } section_layout_t;
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate #define	SECTION_HDR_OFFSET	0x1800
71*7c478bd9Sstevel@tonic-gate #define	SECTION_HDR_TAG		0x08
72*7c478bd9Sstevel@tonic-gate #define	SECTION_HDR_VER		0x0001
73*7c478bd9Sstevel@tonic-gate #define	SECTION_HDR_LENGTH	0x06
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * SEEPROM segment header layout
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate typedef struct {
80*7c478bd9Sstevel@tonic-gate 	uint16_t	name;		/* segment name */
81*7c478bd9Sstevel@tonic-gate 	uint16_t	descriptor[2];	/* descriptor (msb) */
82*7c478bd9Sstevel@tonic-gate 	uint16_t	offset;		/* segment data offset */
83*7c478bd9Sstevel@tonic-gate 	uint16_t	length;		/* segment length */
84*7c478bd9Sstevel@tonic-gate } segment_layout_t;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate #define	ENVSEG_NAME		0x4553	/* environmental segment name */
87*7c478bd9Sstevel@tonic-gate #define	ENVSEG_VERSION		1	/* environmental segment version */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate  * SEEPROM environmental segment header layout
92*7c478bd9Sstevel@tonic-gate  */
93*7c478bd9Sstevel@tonic-gate typedef struct {
94*7c478bd9Sstevel@tonic-gate 	uint16_t	sensor_id[2];	/* unique sensor ID (on this FRU) */
95*7c478bd9Sstevel@tonic-gate 	uint16_t	offset;		/* sensor data record offset */
96*7c478bd9Sstevel@tonic-gate } envseg_sensor_t;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate typedef struct {
99*7c478bd9Sstevel@tonic-gate 	uint8_t		version;	/* envseg version */
100*7c478bd9Sstevel@tonic-gate 	uint8_t		sensor_count;	/* total number of sensor records */
101*7c478bd9Sstevel@tonic-gate 	envseg_sensor_t	sensors[1];	/* sensor table (variable length) */
102*7c478bd9Sstevel@tonic-gate } envseg_layout_t;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * SEEPROM environmental segment sensor data layout
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate #define	MAX_POLICY_ENTRIES	6	/* max # policy data entries */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate typedef struct {
111*7c478bd9Sstevel@tonic-gate 	int8_t		observed;	/* observed (measured) temperature */
112*7c478bd9Sstevel@tonic-gate 	int8_t		expected;	/* expected (correct) temperature */
113*7c478bd9Sstevel@tonic-gate } envseg_map_t;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate typedef struct {
116*7c478bd9Sstevel@tonic-gate 	int8_t		high_power_off;	/* high power off threshold */
117*7c478bd9Sstevel@tonic-gate 	int8_t		high_shutdown;	/* high shutdown threshold */
118*7c478bd9Sstevel@tonic-gate 	int8_t		high_warning;	/* high warning threshold */
119*7c478bd9Sstevel@tonic-gate 	int8_t		low_warning;	/* low warning threshold */
120*7c478bd9Sstevel@tonic-gate 	int8_t		low_shutdown;	/* low shutdown threshold */
121*7c478bd9Sstevel@tonic-gate 	int8_t		low_power_off;	/* low power off threshold */
122*7c478bd9Sstevel@tonic-gate 	int8_t		policy_type;	/* policy type */
123*7c478bd9Sstevel@tonic-gate 	int8_t		policy_entries;	/* #valid entries in policy_data[] */
124*7c478bd9Sstevel@tonic-gate 	int8_t		policy_data[MAX_POLICY_ENTRIES];
125*7c478bd9Sstevel@tonic-gate 	uint16_t	obs2exp_cnt;	/* map entries count */
126*7c478bd9Sstevel@tonic-gate 	envseg_map_t	obs2exp_map[1];	/* variable length map table */
127*7c478bd9Sstevel@tonic-gate } envseg_sensor_data_t;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate /* policy_type */
130*7c478bd9Sstevel@tonic-gate #define	POLICY_TARGET_TEMP	1
131*7c478bd9Sstevel@tonic-gate #define	POLICY_LINEAR		2
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /* linear policy data indices */
134*7c478bd9Sstevel@tonic-gate #define	LOW_NOMINAL_LOC		0	/* linear policy: lower temp index */
135*7c478bd9Sstevel@tonic-gate #define	HIGH_NOMINAL_LOC	1	/* linear policy: higher temp index */
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * FRU envseg list
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate typedef struct fruenvseg {
142*7c478bd9Sstevel@tonic-gate 	struct fruenvseg	*next;		/* next entry */
143*7c478bd9Sstevel@tonic-gate 	char			*fru;		/* FRU SEEPROM path */
144*7c478bd9Sstevel@tonic-gate 	void			*envsegbufp;	/* envseg data buffer */
145*7c478bd9Sstevel@tonic-gate 	int			envseglen;	/* envseg length */
146*7c478bd9Sstevel@tonic-gate } fruenvseg_t;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate /*
150*7c478bd9Sstevel@tonic-gate  * devfs-path and sensor IDs for CPU FRUs
151*7c478bd9Sstevel@tonic-gate  */
152*7c478bd9Sstevel@tonic-gate #define	CPU0_FRU_DEVFS	"/pci@8,700000/ebus@5/i2c@1,30/cpu-fru@0,a0:cpu-fru"
153*7c478bd9Sstevel@tonic-gate #define	CPU1_FRU_DEVFS	"/pci@8,700000/ebus@5/i2c@1,30/cpu-fru@0,a2:cpu-fru"
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #define	CPU_FRU_AMB_SENSOR	1
156*7c478bd9Sstevel@tonic-gate #define	CPU_FRU_DIE_SENSOR	2
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /*
159*7c478bd9Sstevel@tonic-gate  * devfs-path for various fans and their min/max speeds
160*7c478bd9Sstevel@tonic-gate  */
161*7c478bd9Sstevel@tonic-gate #define	ENV_CPU_FAN_DEVFS	\
162*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:2"
163*7c478bd9Sstevel@tonic-gate #define	ENV_SYSTEM_FAN_DEVFS	\
164*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:0"
165*7c478bd9Sstevel@tonic-gate #define	ENV_PSUPPLY_FAN_DEVFS	\
166*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:4"
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /*
169*7c478bd9Sstevel@tonic-gate  * devfs-path for xcalwd watchdog
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate #define	XCALWD_DEVFS	"/devices/pseudo/xcalwd@0:xcalwd"
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate #define	CPU_FAN_SPEED_MIN	12
174*7c478bd9Sstevel@tonic-gate #define	CPU_FAN_SPEED_MAX	63
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate #define	SYSTEM_FAN_SPEED_MIN	12
177*7c478bd9Sstevel@tonic-gate #define	SYSTEM_FAN_SPEED_MAX	63
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate #define	PSUPPLY_FAN_SPEED_MIN	0
180*7c478bd9Sstevel@tonic-gate #define	PSUPPLY_FAN_SPEED_MAX	31
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate /*
184*7c478bd9Sstevel@tonic-gate  * devfs-path for various temperature sensors and CPU platform path
185*7c478bd9Sstevel@tonic-gate  */
186*7c478bd9Sstevel@tonic-gate #define	CPU0_DIE_SENSOR_DEVFS	\
187*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/temperature@0,30:die_temp"
188*7c478bd9Sstevel@tonic-gate #define	CPU0_AMB_SENSOR_DEVFS	\
189*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/temperature@0,30:amb_temp"
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate #define	CPU1_DIE_SENSOR_DEVFS	\
192*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/temperature@0,98:die_temp"
193*7c478bd9Sstevel@tonic-gate #define	CPU1_AMB_SENSOR_DEVFS	\
194*7c478bd9Sstevel@tonic-gate 	"/pci@8,700000/ebus@5/i2c@1,30/temperature@0,98:amb_temp"
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate /*
197*7c478bd9Sstevel@tonic-gate  * Temperature thresholds structure
198*7c478bd9Sstevel@tonic-gate  */
199*7c478bd9Sstevel@tonic-gate typedef int16_t tempr_t;
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate typedef struct {
202*7c478bd9Sstevel@tonic-gate 	tempr_t	low_power_off;		/* low power-off temperature */
203*7c478bd9Sstevel@tonic-gate 	tempr_t	high_power_off;		/* high power-off temperature */
204*7c478bd9Sstevel@tonic-gate 	tempr_t	low_shutdown;		/* low shutdown temperature */
205*7c478bd9Sstevel@tonic-gate 	tempr_t	high_shutdown;		/* high shutdown temperature */
206*7c478bd9Sstevel@tonic-gate 	tempr_t	low_warning;		/* low warning temperature */
207*7c478bd9Sstevel@tonic-gate 	tempr_t	high_warning;		/* high warning temperature */
208*7c478bd9Sstevel@tonic-gate 	tempr_t	min_limit;		/* sensor minimum temperature limit */
209*7c478bd9Sstevel@tonic-gate 	tempr_t	max_limit;		/* sensor maximum temperature limit */
210*7c478bd9Sstevel@tonic-gate 	short	policy_type;		/* temperature policy */
211*7c478bd9Sstevel@tonic-gate 	short	policy_entries;		/* # entries in policy_data */
212*7c478bd9Sstevel@tonic-gate 	tempr_t	policy_data[MAX_POLICY_ENTRIES];
213*7c478bd9Sstevel@tonic-gate } sensor_thresh_t;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate #define	TEMP_IN_SHUTDOWN_RANGE(val, threshp)	\
218*7c478bd9Sstevel@tonic-gate 	((val) > (threshp)->high_shutdown || (val) < (threshp)->low_shutdown)
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate #define	TEMP_IN_WARNING_RANGE(val, threshp)	\
221*7c478bd9Sstevel@tonic-gate 	((val) > (threshp)->high_warning || (val) < (threshp)->low_warning)
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate /*
225*7c478bd9Sstevel@tonic-gate  * MAX1617 sensor min/max temperature limits
226*7c478bd9Sstevel@tonic-gate  */
227*7c478bd9Sstevel@tonic-gate #define	MAX1617_MIN_TEMP	-65
228*7c478bd9Sstevel@tonic-gate #define	MAX1617_MAX_TEMP	127
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate /*
231*7c478bd9Sstevel@tonic-gate  * CPU "die" temperature thresholds
232*7c478bd9Sstevel@tonic-gate  */
233*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_HIGH_POWER_OFF	110
234*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_HIGH_SHUTDOWN	90
235*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_HIGH_WARNING	88
236*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_NORMAL_TARGET	80
237*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_OTHER_TARGET	65
238*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_LOW_WARNING	0
239*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_LOW_SHUTDOWN	-10
240*7c478bd9Sstevel@tonic-gate #define	CPU_DIE_LOW_POWER_OFF	-20
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate /*
243*7c478bd9Sstevel@tonic-gate  * CPU ambient temperature thresholds
244*7c478bd9Sstevel@tonic-gate  */
245*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_HIGH_POWER_OFF	70
246*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_HIGH_SHUTDOWN	60
247*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_HIGH_WARNING	40
248*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_HIGH_NOMINAL	40
249*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_LOW_NOMINAL	25
250*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_LOW_WARNING	0
251*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_LOW_SHUTDOWN	-10
252*7c478bd9Sstevel@tonic-gate #define	CPU_AMB_LOW_POWER_OFF	-20
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate /*
256*7c478bd9Sstevel@tonic-gate  * Fan names
257*7c478bd9Sstevel@tonic-gate  */
258*7c478bd9Sstevel@tonic-gate #define	ENV_SYSTEM_FAN		"system"
259*7c478bd9Sstevel@tonic-gate #define	ENV_CPU_FAN		"cpu"
260*7c478bd9Sstevel@tonic-gate #define	ENV_PSUPPLY_FAN		"power-supply"
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate /*
263*7c478bd9Sstevel@tonic-gate  * Sensor ids & names
264*7c478bd9Sstevel@tonic-gate  */
265*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU0_ID		0
266*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU0_DIE		"cpu0"
267*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU0_AMB		"cpu0-ambient"
268*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU1_ID		1
269*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU1_DIE		"cpu1"
270*7c478bd9Sstevel@tonic-gate #define	SENSOR_CPU1_AMB		"cpu1-ambient"
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate /*
273*7c478bd9Sstevel@tonic-gate  * Temperature correction/map strucutre
274*7c478bd9Sstevel@tonic-gate  */
275*7c478bd9Sstevel@tonic-gate typedef struct {
276*7c478bd9Sstevel@tonic-gate 	tempr_t		observed;		/* observed temperature */
277*7c478bd9Sstevel@tonic-gate 	tempr_t		expected;		/* expected temperature */
278*7c478bd9Sstevel@tonic-gate } tempr_map_t;
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate /*
281*7c478bd9Sstevel@tonic-gate  * Temperature sensor related data structure
282*7c478bd9Sstevel@tonic-gate  */
283*7c478bd9Sstevel@tonic-gate typedef struct sensor_pmdev sensor_pmdev_t;
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate typedef struct env_sensor {
286*7c478bd9Sstevel@tonic-gate 	char		*name;			/* sensor name */
287*7c478bd9Sstevel@tonic-gate 	char		*devfs_path;		/* sensor device devfs path */
288*7c478bd9Sstevel@tonic-gate 	sensor_thresh_t	*temp_thresh;		/* sensor temp threshold */
289*7c478bd9Sstevel@tonic-gate 	char		*fru;			/* FRU seeprom pathname */
290*7c478bd9Sstevel@tonic-gate 	int		fru_sensor;		/* FRU sensor ID */
291*7c478bd9Sstevel@tonic-gate 	int		flags;			/* flags (see below) */
292*7c478bd9Sstevel@tonic-gate 	int		fd;			/* device file descriptor */
293*7c478bd9Sstevel@tonic-gate 	int		error;			/* error flag */
294*7c478bd9Sstevel@tonic-gate 	boolean_t 	present;		/* sensor present */
295*7c478bd9Sstevel@tonic-gate 	tempr_t		cur_temp;		/* current temperature */
296*7c478bd9Sstevel@tonic-gate 	tempr_t		target_temp;		/* target temperature */
297*7c478bd9Sstevel@tonic-gate 	float		avg_temp;		/* average temperature */
298*7c478bd9Sstevel@tonic-gate 	float		prev_avg_temp;		/* prev average temperature */
299*7c478bd9Sstevel@tonic-gate 	time_t		warning_tstamp;		/* last warning time (secs) */
300*7c478bd9Sstevel@tonic-gate 	time_t		shutdown_tstamp;	/* shutdown temp time (secs) */
301*7c478bd9Sstevel@tonic-gate 	boolean_t 	shutdown_initiated;	/* shutdown initated */
302*7c478bd9Sstevel@tonic-gate 	sensor_pmdev_t	*pmdevp;		/* power managed device info */
303*7c478bd9Sstevel@tonic-gate 	float		fan_adjustment_rate;	/* fan adjustment rate */
304*7c478bd9Sstevel@tonic-gate 	uint_t		obs2exp_cnt;		/* # mapping entries */
305*7c478bd9Sstevel@tonic-gate 	tempr_map_t	*obs2exp_map;		/* temperature map entries */
306*7c478bd9Sstevel@tonic-gate 	time_t		warning_start;		/* warning start time (secs) */
307*7c478bd9Sstevel@tonic-gate } env_sensor_t;
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate /*
310*7c478bd9Sstevel@tonic-gate  * Sensor flags
311*7c478bd9Sstevel@tonic-gate  */
312*7c478bd9Sstevel@tonic-gate #define	SFLAG_TARGET_TEMP	0x01		/* track target temperature */
313*7c478bd9Sstevel@tonic-gate #define	SFLAG_CPU_AMB_SENSOR	0x10		/* CPU ambient sensor */
314*7c478bd9Sstevel@tonic-gate #define	SFLAG_CPU_DIE_SENSOR	0x20		/* CPU die snesor */
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate extern	env_sensor_t *sensor_lookup(char *sensor_name);
317*7c478bd9Sstevel@tonic-gate extern	int get_temperature(env_sensor_t *, tempr_t *);
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate /*
320*7c478bd9Sstevel@tonic-gate  * Fan information data structure
321*7c478bd9Sstevel@tonic-gate  */
322*7c478bd9Sstevel@tonic-gate #define	SENSORS_PER_FAN	8		/* max sensors per fan */
323*7c478bd9Sstevel@tonic-gate typedef uint8_t fanspeed_t;
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate typedef struct env_fan {
326*7c478bd9Sstevel@tonic-gate 	char		*name;			/* fan name */
327*7c478bd9Sstevel@tonic-gate 	char		*devfs_path;		/* fan device devfs path */
328*7c478bd9Sstevel@tonic-gate 	fanspeed_t	speed_min;		/* minimum speed */
329*7c478bd9Sstevel@tonic-gate 	fanspeed_t	speed_max;		/* maximum speed */
330*7c478bd9Sstevel@tonic-gate 	int		forced_speed;		/* forced (fixed) speed */
331*7c478bd9Sstevel@tonic-gate 	int		fd;			/* device file descriptor */
332*7c478bd9Sstevel@tonic-gate 	boolean_t	present;		/* fan present */
333*7c478bd9Sstevel@tonic-gate 	float		cur_speed;		/* current fan speed */
334*7c478bd9Sstevel@tonic-gate 	float		prev_speed;		/* previous fan speed */
335*7c478bd9Sstevel@tonic-gate 	int		sensor_cnt;		/* #sensors in sensors[] */
336*7c478bd9Sstevel@tonic-gate 	env_sensor_t	*sensors[SENSORS_PER_FAN]; /* array of sensors */
337*7c478bd9Sstevel@tonic-gate } env_fan_t;
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate /*
340*7c478bd9Sstevel@tonic-gate  * LPM/Table data structures
341*7c478bd9Sstevel@tonic-gate  */
342*7c478bd9Sstevel@tonic-gate #define	LPM_RANGES_PROPERTY	"sunw,lpm-ranges"
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate typedef struct {
345*7c478bd9Sstevel@tonic-gate 	int32_t	x;
346*7c478bd9Sstevel@tonic-gate 	int32_t	y;
347*7c478bd9Sstevel@tonic-gate } point_t;
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate typedef struct {
350*7c478bd9Sstevel@tonic-gate 	int	nentries;
351*7c478bd9Sstevel@tonic-gate 	point_t	*xymap;
352*7c478bd9Sstevel@tonic-gate } table_t;
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate struct lpm_dev {
355*7c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	nodeh;
356*7c478bd9Sstevel@tonic-gate 	table_t		*temp_lpm_tbl;
357*7c478bd9Sstevel@tonic-gate 	struct lpm_dev *next;
358*7c478bd9Sstevel@tonic-gate };
359*7c478bd9Sstevel@tonic-gate typedef struct lpm_dev lpm_dev_t;
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate extern	env_fan_t *fan_lookup(char *fan_name);
362*7c478bd9Sstevel@tonic-gate extern	int get_fan_speed(env_fan_t *, fanspeed_t *);
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate extern int env_debug;
365*7c478bd9Sstevel@tonic-gate extern void envd_log(int pri, const char *fmt, ...);
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate /*
368*7c478bd9Sstevel@tonic-gate  * Various messages
369*7c478bd9Sstevel@tonic-gate  */
370*7c478bd9Sstevel@tonic-gate #define	ENVD_PLUGIN_INIT_FAILED		\
371*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: initialization failed!\n")
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate #define	ENVD_PICL_SETUP_FAILED		\
374*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: PICL setup failed!\n")
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate #define	PM_THREAD_CREATE_FAILED		\
377*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate #define	PM_THREAD_EXITING		\
380*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
381*7c478bd9Sstevel@tonic-gate 
382*7c478bd9Sstevel@tonic-gate #define	ENV_THREAD_CREATE_FAILED	\
383*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: envthr thread creation failed!\n")
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate #define	ENV_SHUTDOWN_MSG		\
386*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
387*7c478bd9Sstevel@tonic-gate 	"limits (%d...%d). Shutting down the system.\n")
388*7c478bd9Sstevel@tonic-gate 
389*7c478bd9Sstevel@tonic-gate #define	ENV_WARNING_MSG			\
390*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
391*7c478bd9Sstevel@tonic-gate 	"operating limits (%d...%d).\n")
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate #define	ENV_WATCHDOG_INIT_FAIL		\
394*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: failed to initialize the watchdog timer " \
395*7c478bd9Sstevel@tonic-gate 	"errno:%d %s\n")
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate #define	ENV_FAN_OPEN_FAIL		\
398*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate #define	ENV_SENSOR_OPEN_FAIL		\
401*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
402*7c478bd9Sstevel@tonic-gate 
403*7c478bd9Sstevel@tonic-gate #define	ENV_SENSOR_ACCESS_FAIL		\
404*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate #define	ENV_SENSOR_ACCESS_OK		\
407*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate #define	ENV_CONF_INT_EXPECTED		\
410*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax or integer " \
411*7c478bd9Sstevel@tonic-gate 	"value outside range for keyword '%s'.\n")
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate #define	ENV_CONF_STRING_EXPECTED	\
414*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Invalid syntax for keyword " \
415*7c478bd9Sstevel@tonic-gate 	"'%s'. Expecting string in double quotes (length < %d).\n")
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate #define	ENV_CONF_UNSUPPORTED_TYPE	\
418*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Unsupported type:%d for " \
419*7c478bd9Sstevel@tonic-gate 	"keyword '%s'.\n")
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate #define	ENV_CONF_UNSUPPORTED_KEYWORD	\
422*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: file:%s line:%d Unsupported keyword '%s'.\n")
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate #define	ENV_FRU_OPEN_FAIL		\
425*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: can't open FRU SEEPROM path:%s errno:%d %s\n")
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate #define	ENV_FRU_BAD_ENVSEG		\
428*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: version mismatch or environmental segment " \
429*7c478bd9Sstevel@tonic-gate 	"header too short in FRU SEEPROM %s\n")
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate #define	ENV_FRU_BAD_SENSOR_ENTRY	\
432*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: discarding bad sensor entry (sensor_id " \
433*7c478bd9Sstevel@tonic-gate 	"%x sensor '%s') in FRU SEEPROM %s\n")
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate #define	ENV_FRU_SENSOR_MAP_NOMEM	\
436*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: out of memory, discarding sensor map for " \
437*7c478bd9Sstevel@tonic-gate 	"sensor_id %x (sensor '%s') in FRU SEEPROM %s\n")
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate #define	ENV_INVALID_PROPERTY_FORMAT	\
440*7c478bd9Sstevel@tonic-gate 	gettext("SUNW_piclenvd: ignoring %s property (invalid format)")
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
443*7c478bd9Sstevel@tonic-gate }
444*7c478bd9Sstevel@tonic-gate #endif
445*7c478bd9Sstevel@tonic-gate 
446*7c478bd9Sstevel@tonic-gate #endif	/* _ENVD_H */
447