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