xref: /onnv-gate/usr/src/uts/sun4u/lw8/sys/sgenv_impl.h (revision 1979:654adad2e33c)
11708Sstevel /*
21708Sstevel  * CDDL HEADER START
31708Sstevel  *
41708Sstevel  * The contents of this file are subject to the terms of the
51708Sstevel  * Common Development and Distribution License (the "License").
61708Sstevel  * You may not use this file except in compliance with the License.
71708Sstevel  *
81708Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91708Sstevel  * or http://www.opensolaris.org/os/licensing.
101708Sstevel  * See the License for the specific language governing permissions
111708Sstevel  * and limitations under the License.
121708Sstevel  *
131708Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
141708Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151708Sstevel  * If applicable, add the following below this CDDL HEADER, with the
161708Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
171708Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
181708Sstevel  *
191708Sstevel  * CDDL HEADER END
201708Sstevel  */
211708Sstevel 
221708Sstevel /*
23*1979Sarutz  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
241708Sstevel  * Use is subject to license terms.
251708Sstevel  */
261708Sstevel 
271708Sstevel #ifndef _SYS_SGENV_IMPL_H
281708Sstevel #define	_SYS_SGENV_IMPL_H
291708Sstevel 
301708Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
311708Sstevel 
321708Sstevel #ifdef	__cplusplus
331708Sstevel extern "C" {
341708Sstevel #endif
351708Sstevel 
361708Sstevel /*
371708Sstevel  * sgenv_impl.h - Serengeti Environmental Driver
381708Sstevel  *
391708Sstevel  * This header file contains the private environmental definitions for
401708Sstevel  * the Serengeti platform. (used only by sgenv driver)
411708Sstevel  *
421708Sstevel  */
431708Sstevel 
441708Sstevel /* get the public definitions */
451708Sstevel #include <sys/sgenv.h>
461708Sstevel 
471708Sstevel /* named field of keyswitch kstat */
481708Sstevel #define	POSITION_KSTAT_NAME	"position"
491708Sstevel 
501708Sstevel /* Mailbox message sub-types */
511708Sstevel #define	SG_GET_ENV_HPU_KEYS	0x4000
521708Sstevel #define	SG_GET_ENV_CONSTANTS	0x4004
531708Sstevel #define	SG_GET_ENV_VOLATILES	0x4002
541708Sstevel #define	SG_GET_ENV_THRESHOLDS	0x4003
551708Sstevel 
561708Sstevel /*
571708Sstevel  * Max time sgenv waits for mailbox to respond before
581708Sstevel  * it decides to timeout. (measured in seconds)
591708Sstevel  */
601708Sstevel #define	SGENV_DEFAULT_MAX_MBOX_WAIT_TIME	30
611708Sstevel 
621708Sstevel #define	SGENV_MAX_SENSORS_PER_KEY	27	/* from design doc (3.1.4) */
631708Sstevel #define	SGENV_MAX_HPUS_PER_DOMAIN	24
641708Sstevel #define	SGENV_MAX_HPU_KEYS		(SSM_MAX_INSTANCES * \
651708Sstevel 						SGENV_MAX_HPUS_PER_DOMAIN)
661708Sstevel #define	SGENV_MAX_SENSORS		(SGENV_MAX_SENSORS_PER_KEY * \
671708Sstevel 						SGENV_MAX_HPU_KEYS)
681708Sstevel 
691708Sstevel #define	SGENV_NO_NODE_EXISTS		0x0
701708Sstevel #define	SGENV_NODE_TYPE_DS		0x3FF
711708Sstevel 
721708Sstevel #define	SGENV_POLL_THREAD	0x1	/* cache update called from kstat */
731708Sstevel #define	SGENV_INTERRUPT_THREAD	0x2	/* cache update called from softint */
741708Sstevel 
751708Sstevel #define	BOARD_CACHE		0x1
761708Sstevel #define	ENV_CACHE		0x2
771708Sstevel 
781708Sstevel /*
791708Sstevel  * Event Publisher definitions for sysevent.
801708Sstevel  */
811708Sstevel #define	EP_SGENV	SUNW_KERN_PUB SGENV_DRV_NAME
821708Sstevel 
831708Sstevel /*
841708Sstevel  * Event definitions
851708Sstevel  */
861708Sstevel #define	MAX_TAG_ID_STR_LEN		100
871708Sstevel 
881708Sstevel #define	HPU_ENTRY(value_macro)	{	\
891708Sstevel 	value_macro,	\
901708Sstevel 	value_macro ## _STR,	\
911708Sstevel 	value_macro ## _ID	\
921708Sstevel }
931708Sstevel 
941708Sstevel #define	PART_VALUE(value_macro)	{	\
951708Sstevel 	value_macro,	\
961708Sstevel 	value_macro ## _STR	\
971708Sstevel }
981708Sstevel 
991708Sstevel #define	TYPE_VALUE(value_macro, scale) {	\
1001708Sstevel 	value_macro,	\
1011708Sstevel 	value_macro ## _STR,	\
1021708Sstevel 	value_macro ## _UNITS,	\
1031708Sstevel 	scale	\
1041708Sstevel }
1051708Sstevel 
1061708Sstevel typedef struct hpu_value {
1071708Sstevel 	unsigned	value;
1081708Sstevel 	const char	*name;
1091708Sstevel 	const char	*IDstr;
1101708Sstevel 
1111708Sstevel } hpu_value_t;
1121708Sstevel 
1131708Sstevel typedef struct part_value {
1141708Sstevel 	unsigned	value;
1151708Sstevel 	const char	*name;
1161708Sstevel } part_value_t;
1171708Sstevel 
1181708Sstevel typedef struct type_value {
1191708Sstevel 	unsigned	value;
1201708Sstevel 	const char	*name;
1211708Sstevel 	const char	*units;
1221708Sstevel 	uint32_t	scale;
1231708Sstevel 
1241708Sstevel } type_value_t;
1251708Sstevel 
1261708Sstevel 
1271708Sstevel /*
1281708Sstevel  * SGENV soft state structure.
1291708Sstevel  */
1301708Sstevel typedef struct sgenv_soft_state {
1311708Sstevel 	int			instance;	/* instance number */
1321708Sstevel 	dev_info_t		*dip;		/* dev_info structure */
1331708Sstevel 	kstat_t			*keyswitch_ksp;
1341708Sstevel 	kstat_t			*env_info_ksp;
1351708Sstevel 	kstat_t			*board_info_ksp;
1361708Sstevel 
1371708Sstevel } sgenv_soft_state_t;
1381708Sstevel 
1391708Sstevel 
1401708Sstevel /*
1411708Sstevel  * Environmental Info Structures.
1421708Sstevel  */
1431708Sstevel typedef int32_t envresp_key_t;
1441708Sstevel 
1451708Sstevel typedef struct envresp_constants {
1461708Sstevel 	sensor_id_t	id; /* sd_id */
1471708Sstevel 	sensor_data_t	lo; /* sd_lo */
1481708Sstevel 	sensor_data_t	hi; /* sd_hi */
1491708Sstevel 	/* no padding required, 3x4-bytes in total length */
1501708Sstevel 
1511708Sstevel } envresp_constants_t;
1521708Sstevel 
1531708Sstevel typedef struct envresp_volatiles {
1541708Sstevel 	sensor_status_t	info;	/* sd_infostamp */
1551708Sstevel 	sensor_data_t	value;	/* sd_value */
1561708Sstevel 	int32_t		_pad;	/* pad to 2x8-bytes */
1571708Sstevel 
1581708Sstevel } envresp_volatiles_t;
1591708Sstevel 
1601708Sstevel typedef struct envresp_thresholds {
1611708Sstevel 	sensor_data_t	lo_warn; /* sd_lo_warn */
1621708Sstevel 	sensor_data_t	hi_warn; /* sd_hi_warn */
1631708Sstevel 	/* no padding required, 2x4-bytes in total length */
1641708Sstevel 
1651708Sstevel } envresp_thresholds_t;
1661708Sstevel 
1671708Sstevel 
1681708Sstevel /*
1691708Sstevel  * functions local to this driver.
1701708Sstevel  */
1711708Sstevel static int	sgenv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
1721708Sstevel static int	sgenv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
1731708Sstevel 
1741708Sstevel static int	sgenv_add_kstats(sgenv_soft_state_t *softsp);
1751708Sstevel static void	sgenv_remove_kstats(sgenv_soft_state_t *softsp);
1761708Sstevel 
1771708Sstevel static int	sgenv_create_cache_update_threads(void);
1781708Sstevel static int	sgenv_remove_cache_update_threads(void);
1791708Sstevel static void	sgenv_indicate_cache_update_needed(int cache);
1801708Sstevel 
1811708Sstevel static int	sgenv_keyswitch_kstat_update(kstat_t *ksp, int rw);
1821708Sstevel 
1831708Sstevel static void	sgenv_init_env_cache(void);
1841708Sstevel static void	sgenv_update_env_cache(void);
1851708Sstevel static int	sgenv_env_info_kstat_update(kstat_t *ksp, int rw);
1861708Sstevel static int	sgenv_env_info_kstat_snapshot(kstat_t *ksp, void *buf, int rw);
1871708Sstevel static int	sgenv_get_env_info_data(void);
1881708Sstevel static int	sgenv_get_hpu_keys(envresp_key_t *new, int *status);
1891708Sstevel static int	sgenv_get_env_data(envresp_key_t key, int key_posn,
1901708Sstevel 					uint16_t flag, int *status);
1911708Sstevel static int	sgenv_handle_env_data_error(int err, int status, int key_posn,
1921708Sstevel 					envresp_key_t key, char *str);
1931708Sstevel static void	sgenv_mbox_error_msg(char *str, int err, int status);
1941708Sstevel static void	sgenv_destroy_env_cache(void);
1951708Sstevel static void	sgenv_clear_env_cache_entry(int key_posn);
1961708Sstevel static int	sgenv_create_env_cache_entry(int key_posn);
1971708Sstevel static void	sgenv_set_sensor_status(env_sensor_t *sensor);
1981708Sstevel static void	sgenv_update_env_kstat_size(kstat_t *ksp);
1991708Sstevel 
2001708Sstevel static void	sgenv_init_board_cache(void);
2011708Sstevel static void	sgenv_update_board_cache(void);
2021708Sstevel static int	sgenv_board_info_kstat_update(kstat_t *ksp, int rw);
2031708Sstevel static int	sgenv_board_info_kstat_snapshot(kstat_t *ksp,
2041708Sstevel 					void *buf, int rw);
2051708Sstevel static int	sgenv_get_board_info_data(void);
2061708Sstevel static void	sgenv_set_valid_node_positions(uint_t *node_present);
2071708Sstevel 
2081708Sstevel static int	sgenv_process_threshold_event(env_sensor_t sensor);
2091708Sstevel static void	sgenv_tagid_to_string(sensor_id_t id, char *str);
2101708Sstevel static int	sgenv_add_intr_handlers(void);
2111708Sstevel static int	sgenv_remove_intr_handlers(void);
2121708Sstevel static uint_t	sgenv_keyswitch_handler(char *);
2131708Sstevel static uint_t	sgenv_env_data_handler(char *);
2141708Sstevel static uint_t	sgenv_fan_status_handler(char *);
2151708Sstevel static uint_t	sgenv_dr_event_handler(char *);
2161708Sstevel static uint_t	sgenv_check_sensor_thresholds(void);
2171708Sstevel static const char	*sgenv_get_hpu_id_str(uint_t hpu_type);
2181708Sstevel static const char	*sgenv_get_part_str(uint_t sensor_part);
2191708Sstevel static const char	*sgenv_get_type_str(uint_t sensor_type);
2201708Sstevel 
2211708Sstevel 
2221708Sstevel /*
2231708Sstevel  * Debug stuff
2241708Sstevel  */
2251708Sstevel #ifdef DEBUG
2261708Sstevel extern uint_t	sgenv_debug;
2271708Sstevel 
2281708Sstevel #define	SGENV_DEBUG_NONE	0x00
2291708Sstevel #define	SGENV_DEBUG_POLL	0x01
2301708Sstevel #define	SGENV_DEBUG_EVENT	0x02
2311708Sstevel #define	SGENV_DEBUG_CACHE	0x04
2321708Sstevel #define	SGENV_DEBUG_MSG		0x08
2331708Sstevel #define	SGENV_DEBUG_THREAD	0x10
2341708Sstevel #define	SGENV_DEBUG_ALL		0xFF
2351708Sstevel 
236*1979Sarutz #define	DCMN_ERR_S(v, s)	static fn_t (v) = (s)
237*1979Sarutz 
2381708Sstevel #define	DCMN_ERR	cmn_err
2391708Sstevel #define	DCMN_ERR_EVENT	if (sgenv_debug & SGENV_DEBUG_EVENT)	DCMN_ERR
2401708Sstevel #define	DCMN_ERR_CACHE	if (sgenv_debug & SGENV_DEBUG_CACHE)	DCMN_ERR
2411708Sstevel #define	DCMN_ERR_THREAD	if (sgenv_debug & SGENV_DEBUG_THREAD)	DCMN_ERR
2421708Sstevel 
2431708Sstevel #define	SGENV_PRINT_MBOX_MSG(x, str)    \
2441708Sstevel 	DCMN_ERR(CE_CONT, "Mbox msg info: %s", str);    \
2451708Sstevel 	DCMN_ERR(CE_CONT, "\ttype = 0x%x,", x->msg_type.type);     \
2461708Sstevel 	DCMN_ERR(CE_CONT, "\tsub_type = 0x%x\n", x->msg_type.sub_type);    \
2471708Sstevel 	DCMN_ERR(CE_CONT, "\tstatus = 0x%x\n", x->msg_status);     \
2481708Sstevel 	DCMN_ERR(CE_CONT, "\tlen = %d\n", x->msg_len);   \
2491708Sstevel 	DCMN_ERR(CE_CONT, "\tbytes = %d\n", x->msg_bytes);       \
2501708Sstevel 	DCMN_ERR(CE_CONT, "\tdata[0] = %d\n", x->msg_data[0]);       \
2511708Sstevel 	DCMN_ERR(CE_CONT, "\tdata[1] = %d\n", x->msg_data[1]);
2521708Sstevel 
2531708Sstevel #define	SGENV_PRINT_ENV_INFO(x) \
2541708Sstevel 	DCMN_ERR(CE_CONT, "Tag=%lx, Val=%d, Lo=%d, LoW=%d, HiW=%d, Hi=%d, " \
2551708Sstevel 			"Inf=%llx St=%x PSt=%x",  \
2561708Sstevel 		x.sd_id.tag_id, x.sd_value, \
2571708Sstevel 		x.sd_lo, x.sd_lo_warn, x.sd_hi_warn, x.sd_hi, x.sd_infostamp, \
2581708Sstevel 		SG_GET_SENSOR_STATUS(x.sd_status), \
2591708Sstevel 		SG_GET_PREV_SENSOR_STATUS(x.sd_status));
2601708Sstevel 
2611708Sstevel #define	SGENV_PRINT_POLL_INFO(x) \
2621708Sstevel 		if (sgenv_debug & SGENV_DEBUG_POLL)	SGENV_PRINT_ENV_INFO(x)
2631708Sstevel 
2641708Sstevel #else
265*1979Sarutz #define	DCMN_ERR_S(v, s)	fn_t (v) = ""
266*1979Sarutz 
267*1979Sarutz #define	_DCMN_ERR		cmn_err
268*1979Sarutz #define	DCMN_ERR		if (0) _DCMN_ERR
269*1979Sarutz #define	DCMN_ERR_EVENT		if (0) _DCMN_ERR
270*1979Sarutz #define	DCMN_ERR_CACHE		if (0) _DCMN_ERR
271*1979Sarutz #define	DCMN_ERR_THREAD		if (0) _DCMN_ERR
2721708Sstevel #define	SGENV_PRINT_MBOX_MSG
2731708Sstevel #define	SGENV_PRINT_ENV_INFO
2741708Sstevel #define	SGENV_PRINT_POLL_INFO
2751708Sstevel #endif
2761708Sstevel 
2771708Sstevel #ifdef	__cplusplus
2781708Sstevel }
2791708Sstevel #endif
2801708Sstevel 
2811708Sstevel #endif	/* _SYS_SGENV_IMPL_H */
282