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