103831d35Sstevel /* 203831d35Sstevel * CDDL HEADER START 303831d35Sstevel * 403831d35Sstevel * The contents of this file are subject to the terms of the 503831d35Sstevel * Common Development and Distribution License (the "License"). 603831d35Sstevel * You may not use this file except in compliance with the License. 703831d35Sstevel * 803831d35Sstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 903831d35Sstevel * or http://www.opensolaris.org/os/licensing. 1003831d35Sstevel * See the License for the specific language governing permissions 1103831d35Sstevel * and limitations under the License. 1203831d35Sstevel * 1303831d35Sstevel * When distributing Covered Code, include this CDDL HEADER in each 1403831d35Sstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1503831d35Sstevel * If applicable, add the following below this CDDL HEADER, with the 1603831d35Sstevel * fields enclosed by brackets "[]" replaced with your own identifying 1703831d35Sstevel * information: Portions Copyright [yyyy] [name of copyright owner] 1803831d35Sstevel * 1903831d35Sstevel * CDDL HEADER END 2003831d35Sstevel */ 2103831d35Sstevel 2203831d35Sstevel /* 23*a5df24e1Sarutz * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2403831d35Sstevel * Use is subject to license terms. 2503831d35Sstevel */ 2603831d35Sstevel 2703831d35Sstevel #ifndef _SYS_SGENV_IMPL_H 2803831d35Sstevel #define _SYS_SGENV_IMPL_H 2903831d35Sstevel 3003831d35Sstevel #pragma ident "%Z%%M% %I% %E% SMI" 3103831d35Sstevel 3203831d35Sstevel #ifdef __cplusplus 3303831d35Sstevel extern "C" { 3403831d35Sstevel #endif 3503831d35Sstevel 3603831d35Sstevel /* 3703831d35Sstevel * sgenv_impl.h - Serengeti Environmental Driver 3803831d35Sstevel * 3903831d35Sstevel * This header file contains the private environmental definitions for 4003831d35Sstevel * the Serengeti platform. (used only by sgenv driver) 4103831d35Sstevel * 4203831d35Sstevel */ 4303831d35Sstevel 4403831d35Sstevel /* get the public definitions */ 4503831d35Sstevel #include <sys/sgenv.h> 4603831d35Sstevel 4703831d35Sstevel /* named field of keyswitch kstat */ 4803831d35Sstevel #define POSITION_KSTAT_NAME "position" 4903831d35Sstevel 5003831d35Sstevel /* Mailbox message sub-types */ 5103831d35Sstevel #define SG_GET_ENV_HPU_KEYS 0x4000 5203831d35Sstevel #define SG_GET_ENV_CONSTANTS 0x4004 5303831d35Sstevel #define SG_GET_ENV_VOLATILES 0x4002 5403831d35Sstevel #define SG_GET_ENV_THRESHOLDS 0x4003 5503831d35Sstevel 5603831d35Sstevel /* 5703831d35Sstevel * Max time sgenv waits for mailbox to respond before 5803831d35Sstevel * it decides to timeout. (measured in seconds) 5903831d35Sstevel */ 6003831d35Sstevel #define SGENV_DEFAULT_MAX_MBOX_WAIT_TIME 30 6103831d35Sstevel 6203831d35Sstevel #define SGENV_MAX_SENSORS_PER_KEY 27 /* from design doc (3.1.4) */ 6303831d35Sstevel #define SGENV_MAX_HPUS_PER_DOMAIN 24 6403831d35Sstevel #define SGENV_MAX_HPU_KEYS (SSM_MAX_INSTANCES * \ 6503831d35Sstevel SGENV_MAX_HPUS_PER_DOMAIN) 6603831d35Sstevel #define SGENV_MAX_SENSORS (SGENV_MAX_SENSORS_PER_KEY * \ 6703831d35Sstevel SGENV_MAX_HPU_KEYS) 6803831d35Sstevel 6903831d35Sstevel #define SGENV_NO_NODE_EXISTS 0x0 7003831d35Sstevel #define SGENV_NODE_TYPE_DS 0x3FF 7103831d35Sstevel 7203831d35Sstevel #define SGENV_POLL_THREAD 0x1 /* cache update called from kstat */ 7303831d35Sstevel #define SGENV_INTERRUPT_THREAD 0x2 /* cache update called from softint */ 7403831d35Sstevel 7503831d35Sstevel #define BOARD_CACHE 0x1 7603831d35Sstevel #define ENV_CACHE 0x2 7703831d35Sstevel 7803831d35Sstevel /* 7903831d35Sstevel * Event Publisher definitions for sysevent. 8003831d35Sstevel */ 8103831d35Sstevel #define EP_SGENV SUNW_KERN_PUB SGENV_DRV_NAME 8203831d35Sstevel 8303831d35Sstevel /* 8403831d35Sstevel * Event definitions 8503831d35Sstevel */ 8603831d35Sstevel #define MAX_TAG_ID_STR_LEN 100 8703831d35Sstevel 8803831d35Sstevel #define HPU_ENTRY(value_macro) { \ 8903831d35Sstevel value_macro, \ 9003831d35Sstevel value_macro ## _STR, \ 9103831d35Sstevel value_macro ## _ID \ 9203831d35Sstevel } 9303831d35Sstevel 9403831d35Sstevel #define PART_VALUE(value_macro) { \ 9503831d35Sstevel value_macro, \ 9603831d35Sstevel value_macro ## _STR \ 9703831d35Sstevel } 9803831d35Sstevel 9903831d35Sstevel #define TYPE_VALUE(value_macro, scale) { \ 10003831d35Sstevel value_macro, \ 10103831d35Sstevel value_macro ## _STR, \ 10203831d35Sstevel value_macro ## _UNITS, \ 10303831d35Sstevel scale \ 10403831d35Sstevel } 10503831d35Sstevel 10603831d35Sstevel typedef struct hpu_value { 10703831d35Sstevel unsigned value; 10803831d35Sstevel const char *name; 10903831d35Sstevel const char *IDstr; 11003831d35Sstevel 11103831d35Sstevel } hpu_value_t; 11203831d35Sstevel 11303831d35Sstevel typedef struct part_value { 11403831d35Sstevel unsigned value; 11503831d35Sstevel const char *name; 11603831d35Sstevel } part_value_t; 11703831d35Sstevel 11803831d35Sstevel typedef struct type_value { 11903831d35Sstevel unsigned value; 12003831d35Sstevel const char *name; 12103831d35Sstevel const char *units; 12203831d35Sstevel uint32_t scale; 12303831d35Sstevel 12403831d35Sstevel } type_value_t; 12503831d35Sstevel 12603831d35Sstevel 12703831d35Sstevel /* 12803831d35Sstevel * SGENV soft state structure. 12903831d35Sstevel */ 13003831d35Sstevel typedef struct sgenv_soft_state { 13103831d35Sstevel int instance; /* instance number */ 13203831d35Sstevel dev_info_t *dip; /* dev_info structure */ 13303831d35Sstevel kstat_t *keyswitch_ksp; 13403831d35Sstevel kstat_t *env_info_ksp; 13503831d35Sstevel kstat_t *board_info_ksp; 13603831d35Sstevel 13703831d35Sstevel } sgenv_soft_state_t; 13803831d35Sstevel 13903831d35Sstevel 14003831d35Sstevel /* 14103831d35Sstevel * Environmental Info Structures. 14203831d35Sstevel */ 14303831d35Sstevel typedef int32_t envresp_key_t; 14403831d35Sstevel 14503831d35Sstevel typedef struct envresp_constants { 14603831d35Sstevel sensor_id_t id; /* sd_id */ 14703831d35Sstevel sensor_data_t lo; /* sd_lo */ 14803831d35Sstevel sensor_data_t hi; /* sd_hi */ 14903831d35Sstevel /* no padding required, 3x4-bytes in total length */ 15003831d35Sstevel 15103831d35Sstevel } envresp_constants_t; 15203831d35Sstevel 15303831d35Sstevel typedef struct envresp_volatiles { 15403831d35Sstevel sensor_status_t info; /* sd_infostamp */ 15503831d35Sstevel sensor_data_t value; /* sd_value */ 15603831d35Sstevel int32_t _pad; /* pad to 2x8-bytes */ 15703831d35Sstevel 15803831d35Sstevel } envresp_volatiles_t; 15903831d35Sstevel 16003831d35Sstevel typedef struct envresp_thresholds { 16103831d35Sstevel sensor_data_t lo_warn; /* sd_lo_warn */ 16203831d35Sstevel sensor_data_t hi_warn; /* sd_hi_warn */ 16303831d35Sstevel /* no padding required, 2x4-bytes in total length */ 16403831d35Sstevel 16503831d35Sstevel } envresp_thresholds_t; 16603831d35Sstevel 16703831d35Sstevel 16803831d35Sstevel /* 16903831d35Sstevel * functions local to this driver. 17003831d35Sstevel */ 17103831d35Sstevel static int sgenv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 17203831d35Sstevel static int sgenv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 17303831d35Sstevel 17403831d35Sstevel static int sgenv_add_kstats(sgenv_soft_state_t *softsp); 17503831d35Sstevel static void sgenv_remove_kstats(sgenv_soft_state_t *softsp); 17603831d35Sstevel 17703831d35Sstevel static int sgenv_create_cache_update_threads(void); 17803831d35Sstevel static int sgenv_remove_cache_update_threads(void); 17903831d35Sstevel static void sgenv_indicate_cache_update_needed(int cache); 18003831d35Sstevel 18103831d35Sstevel static int sgenv_keyswitch_kstat_update(kstat_t *ksp, int rw); 18203831d35Sstevel 18303831d35Sstevel static void sgenv_init_env_cache(void); 18403831d35Sstevel static void sgenv_update_env_cache(void); 18503831d35Sstevel static int sgenv_env_info_kstat_update(kstat_t *ksp, int rw); 18603831d35Sstevel static int sgenv_env_info_kstat_snapshot(kstat_t *ksp, void *buf, int rw); 18703831d35Sstevel static int sgenv_get_env_info_data(void); 18803831d35Sstevel static int sgenv_get_hpu_keys(envresp_key_t *new, int *status); 18903831d35Sstevel static int sgenv_get_env_data(envresp_key_t key, int key_posn, 19003831d35Sstevel uint16_t flag, int *status); 19103831d35Sstevel static int sgenv_handle_env_data_error(int err, int status, int key_posn, 19203831d35Sstevel envresp_key_t key, char *str); 19303831d35Sstevel static void sgenv_mbox_error_msg(char *str, int err, int status); 19403831d35Sstevel static void sgenv_destroy_env_cache(void); 19503831d35Sstevel static void sgenv_clear_env_cache_entry(int key_posn); 19603831d35Sstevel static int sgenv_create_env_cache_entry(int key_posn); 19703831d35Sstevel static void sgenv_set_sensor_status(env_sensor_t *sensor); 19803831d35Sstevel static void sgenv_update_env_kstat_size(kstat_t *ksp); 19903831d35Sstevel 20003831d35Sstevel static void sgenv_init_board_cache(void); 20103831d35Sstevel static void sgenv_update_board_cache(void); 20203831d35Sstevel static int sgenv_board_info_kstat_update(kstat_t *ksp, int rw); 20303831d35Sstevel static int sgenv_board_info_kstat_snapshot(kstat_t *ksp, 20403831d35Sstevel void *buf, int rw); 20503831d35Sstevel static int sgenv_get_board_info_data(void); 20603831d35Sstevel static void sgenv_set_valid_node_positions(uint_t *node_present); 20703831d35Sstevel 20803831d35Sstevel static int sgenv_process_threshold_event(env_sensor_t sensor); 20903831d35Sstevel static void sgenv_tagid_to_string(sensor_id_t id, char *str); 21003831d35Sstevel static int sgenv_add_intr_handlers(void); 21103831d35Sstevel static int sgenv_remove_intr_handlers(void); 21203831d35Sstevel static uint_t sgenv_keyswitch_handler(char *); 21303831d35Sstevel static uint_t sgenv_env_data_handler(char *); 21403831d35Sstevel static uint_t sgenv_fan_status_handler(char *); 21503831d35Sstevel static uint_t sgenv_dr_event_handler(char *); 21603831d35Sstevel static uint_t sgenv_check_sensor_thresholds(void); 21703831d35Sstevel static const char *sgenv_get_hpu_id_str(uint_t hpu_type); 21803831d35Sstevel static const char *sgenv_get_part_str(uint_t sensor_part); 21903831d35Sstevel static const char *sgenv_get_type_str(uint_t sensor_type); 22003831d35Sstevel 22103831d35Sstevel 22203831d35Sstevel /* 22303831d35Sstevel * Debug stuff 22403831d35Sstevel */ 22503831d35Sstevel #ifdef DEBUG 22603831d35Sstevel extern uint_t sgenv_debug; 22703831d35Sstevel 22803831d35Sstevel #define SGENV_DEBUG_NONE 0x00 22903831d35Sstevel #define SGENV_DEBUG_POLL 0x01 23003831d35Sstevel #define SGENV_DEBUG_EVENT 0x02 23103831d35Sstevel #define SGENV_DEBUG_CACHE 0x04 23203831d35Sstevel #define SGENV_DEBUG_MSG 0x08 23303831d35Sstevel #define SGENV_DEBUG_THREAD 0x10 23403831d35Sstevel #define SGENV_DEBUG_ALL 0xFF 23503831d35Sstevel 236*a5df24e1Sarutz #define DCMN_ERR_S(v, s) static fn_t (v) = (s) 237*a5df24e1Sarutz 23803831d35Sstevel #define DCMN_ERR cmn_err 23903831d35Sstevel #define DCMN_ERR_EVENT if (sgenv_debug & SGENV_DEBUG_EVENT) DCMN_ERR 24003831d35Sstevel #define DCMN_ERR_CACHE if (sgenv_debug & SGENV_DEBUG_CACHE) DCMN_ERR 24103831d35Sstevel #define DCMN_ERR_THREAD if (sgenv_debug & SGENV_DEBUG_THREAD) DCMN_ERR 24203831d35Sstevel 24303831d35Sstevel #define SGENV_PRINT_MBOX_MSG(x, str) \ 24403831d35Sstevel DCMN_ERR(CE_CONT, "Mbox msg info: %s", str); \ 24503831d35Sstevel DCMN_ERR(CE_CONT, "\ttype = 0x%x,", x->msg_type.type); \ 24603831d35Sstevel DCMN_ERR(CE_CONT, "\tsub_type = 0x%x\n", x->msg_type.sub_type); \ 24703831d35Sstevel DCMN_ERR(CE_CONT, "\tstatus = 0x%x\n", x->msg_status); \ 24803831d35Sstevel DCMN_ERR(CE_CONT, "\tlen = %d\n", x->msg_len); \ 24903831d35Sstevel DCMN_ERR(CE_CONT, "\tbytes = %d\n", x->msg_bytes); \ 25003831d35Sstevel DCMN_ERR(CE_CONT, "\tdata[0] = %d\n", x->msg_data[0]); \ 25103831d35Sstevel DCMN_ERR(CE_CONT, "\tdata[1] = %d\n", x->msg_data[1]); 25203831d35Sstevel 25303831d35Sstevel #define SGENV_PRINT_ENV_INFO(x) \ 25403831d35Sstevel DCMN_ERR(CE_CONT, "Tag=%lx, Val=%d, Lo=%d, LoW=%d, HiW=%d, Hi=%d, " \ 25503831d35Sstevel "Inf=%llx St=%x PSt=%x", \ 25603831d35Sstevel x.sd_id.tag_id, x.sd_value, \ 25703831d35Sstevel x.sd_lo, x.sd_lo_warn, x.sd_hi_warn, x.sd_hi, x.sd_infostamp, \ 25803831d35Sstevel SG_GET_SENSOR_STATUS(x.sd_status), \ 25903831d35Sstevel SG_GET_PREV_SENSOR_STATUS(x.sd_status)); 26003831d35Sstevel 26103831d35Sstevel #define SGENV_PRINT_POLL_INFO(x) \ 26203831d35Sstevel if (sgenv_debug & SGENV_DEBUG_POLL) SGENV_PRINT_ENV_INFO(x) 26303831d35Sstevel 26403831d35Sstevel #else 265*a5df24e1Sarutz #define DCMN_ERR_S(v, s) fn_t (v) = "" 266*a5df24e1Sarutz 267*a5df24e1Sarutz #define _DCMN_ERR cmn_err 268*a5df24e1Sarutz #define DCMN_ERR if (0) _DCMN_ERR 269*a5df24e1Sarutz #define DCMN_ERR_EVENT if (0) _DCMN_ERR 270*a5df24e1Sarutz #define DCMN_ERR_CACHE if (0) _DCMN_ERR 271*a5df24e1Sarutz #define DCMN_ERR_THREAD if (0) _DCMN_ERR 27203831d35Sstevel #define SGENV_PRINT_MBOX_MSG 27303831d35Sstevel #define SGENV_PRINT_ENV_INFO 27403831d35Sstevel #define SGENV_PRINT_POLL_INFO 27503831d35Sstevel #endif 27603831d35Sstevel 27703831d35Sstevel #ifdef __cplusplus 27803831d35Sstevel } 27903831d35Sstevel #endif 28003831d35Sstevel 28103831d35Sstevel #endif /* _SYS_SGENV_IMPL_H */ 282