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
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.
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]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
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"
51 * ADC Sample of ADM in Khz, currently 11.2 KHz
53 #define ADCSAMPLE 11250
56 * Taco Platform Details
63 * ADM1031 Hardware Monitor IDs
64 * Used as index into arrays
68 #define CPU_HWM_DEVFS \
69 "/devices/pci@1e,600000/isa@7/i2c@0,320/hardware-monitor@0,5c:control"
75 * Taco sensor IDs as used in FRUID segment
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
83 * Taco fan IDs used in FRUID segment
85 #define SYSTEM_FAN_ID 0
90 * devfs-path for various fans and their min/max speeds
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"
97 #define FAN_RANGE_DEFAULT 4
98 #define CPU_FAN_SPEED_MIN 14
99 #define CPU_FAN_SPEED_MAX 100
101 #define SYSTEM_OUT_FAN_SPEED_MIN 14
102 #define SYSTEM_OUT_FAN_SPEED_MAX 100
104 #define SYSTEM_INTAKE_FAN_SPEED_MIN 14
105 #define SYSTEM_INTAKE_FAN_SPEED_MAX 100
110 * devfs-path for various temperature sensors and CPU platform path
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"
122 typedef int16_t tempr_t
;
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"
136 #define SENSOR_CPU_DIE "cpu"
137 #define SENSOR_SYS_IN "sys-in"
138 #define SENSOR_INT_AMB "int-amb"
140 /* Bit Map of ADM 1031 Status 1/2 Registers */
150 /* ADM Stat 1/2 Mask */
157 * ES segment related structures
159 typedef struct id_off
{
164 typedef struct fan_ctl_pair
{
169 typedef struct Correction_Pair
{
174 #define ES_SENSOR_POLICY_LEN 8
175 #define ES_CORRECTION_PAIRS 12
177 typedef struct sensor_ctrl_blk
{
178 uchar_t high_power_off
;
179 uchar_t high_shutdown
;
180 uchar_t high_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
];
190 #define ES_FAN_CTL_PAIRS 4
192 typedef struct fan_ctrl_blk
{
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
];
206 #define TEMP_IN_WARNING_RANGE(val, sensorp) \
207 ((val) > (sensorp)->es_ptr->high_warning || \
208 (val) < (char)((sensorp)->es_ptr->low_warning))
210 #define TEMP_IN_SHUTDOWN_RANGE(val, sensorp) \
211 ((val) > (sensorp)->es_ptr->high_shutdown || \
212 (val) < (char)((sensorp)->es_ptr->low_shutdown))
215 * Macros to fetch 16 and 32 bit data from unaligned address
217 #define GET_UNALIGN16(addr) \
218 (((*(uint8_t *)addr) << 8) | *((uint8_t *)addr + 1))
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)))
225 * SEEPROM section header layout and location
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 */
235 #define SECTION_HDR_OFFSET 0x1800
236 #define SECTION_HDR_TAG 0x08
237 #define SECTION_HDR_VER 0x0001
238 #define SECTION_HDR_LENGTH 0x06
241 * SEEPROM segment header layout
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 */
250 #define ENVSEG_NAME 0x4553 /* environmental segment name */
251 #define ENVSEG_VERSION 2 /* environmental segment version */
253 #define SENSOR_WARN 1
257 * SEEPROM environmental segment header layout
260 uint16_t sensor_id
[2]; /* unique sensor ID (on this FRU) */
261 uint16_t offset
; /* sensor data record offset */
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) */
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 */
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"
284 * Table data structures
297 * Temperature sensor related data structure
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
;
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 */
317 extern env_sensor_t
*sensor_lookup(char *sensor_name
);
318 extern int get_temperature(env_sensor_t
*, tempr_t
*);
321 * Fan information data structure
323 typedef int fanspeed_t
;
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
;
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 */
345 typedef struct env_tuneable
{
349 int (*rfunc
)(ptree_rarg_t
*, void *);
350 int (*wfunc
)(ptree_warg_t
*, const void *);
352 picl_prophdl_t proph
;
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
);
359 extern int env_debug
;
360 extern void envd_log(int pri
, const char *fmt
, ...);
365 #define ENVD_PLUGIN_INIT_FAILED \
366 gettext("SUNW_piclenvd: initialization failed!\n")
368 #define ENVD_PICL_SETUP_FAILED \
369 gettext("SUNW_piclenvd: PICL setup failed!\n")
371 #define PM_THREAD_CREATE_FAILED \
372 gettext("SUNW_piclenvd: pmthr thread creation failed!\n")
374 #define PM_THREAD_EXITING \
375 gettext("SUNW_piclenvd: pmthr exiting! errno:%d %s\n")
377 #define ENVTHR_THREAD_CREATE_FAILED \
378 gettext("SUNW_piclenvd: envthr thread creation failed!\n")
380 #define ENV_SHUTDOWN_MSG \
381 gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
382 "limits (%d...%d). Shutting down the system.\n")
384 #define ENV_WARNING_MSG \
385 gettext("SUNW_piclenvd: '%s' sensor temperature %d outside safe " \
386 "operating limits (%d...%d).\n")
388 #define ENV_FAN_OPEN_FAIL \
389 gettext("SUNW_piclenvd: can't open '%s' fan path:%s errno:%d %s\n")
391 #define ENV_SENSOR_OPEN_FAIL \
392 gettext("SUNW_piclenvd: can't open '%s' sensor path:%s errno:%d %s\n")
394 #define ENV_SENSOR_ACCESS_FAIL \
395 gettext("SUNW_piclenvd: can't access '%s' sensor errno:%d %s\n")
397 #define ENV_SENSOR_ACCESS_OK \
398 gettext("SUNW_piclenvd: '%s' sensor is accessible now.\n")
400 #define ENV_FRU_OPEN_FAIL \
401 gettext("SUNW_piclenvd: can't open FRU SEEPROM path:%s errno:%d %s\n")
403 #define ENV_FRU_BAD_ENVSEG \
404 gettext("SUNW_piclenvd: version mismatch or environmental segment " \
405 "header too short in FRU SEEPROM %s\n")
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")
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")
415 #define ENV_ADM_OPEN_FAIL \
416 gettext("SUNW_piclenvd: can't open hwm path:%s errno:%d %s\n")
418 #define ENV_ADM_MANUAL_MODE \
419 gettext("SUNW_piclenvd: Cannot change the ADM Chip to Manual mode")
421 #define ENV_ADM_AUTO_MODE \
422 gettext("SUNW_piclenvd: Cannot change the ADM Chip to Auto mode")
424 #define ENV_FAN_FAULT \
425 gettext("SUNW_piclenvd: ADM %s, Fan %s Fault")