xref: /titanic_41/usr/src/uts/sun4u/lw8/sys/sgenv_impl.h (revision 1816cb7076d3ec8a78ef9ac9f895574e13c43645)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_SGENV_IMPL_H
28 #define	_SYS_SGENV_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * sgenv_impl.h - Serengeti Environmental Driver
38  *
39  * This header file contains the private environmental definitions for
40  * the Serengeti platform. (used only by sgenv driver)
41  *
42  */
43 
44 /* get the public definitions */
45 #include <sys/sgenv.h>
46 
47 /* named field of keyswitch kstat */
48 #define	POSITION_KSTAT_NAME	"position"
49 
50 /* Mailbox message sub-types */
51 #define	SG_GET_ENV_HPU_KEYS	0x4000
52 #define	SG_GET_ENV_CONSTANTS	0x4004
53 #define	SG_GET_ENV_VOLATILES	0x4002
54 #define	SG_GET_ENV_THRESHOLDS	0x4003
55 
56 /*
57  * Max time sgenv waits for mailbox to respond before
58  * it decides to timeout. (measured in seconds)
59  */
60 #define	SGENV_DEFAULT_MAX_MBOX_WAIT_TIME	30
61 
62 #define	SGENV_MAX_SENSORS_PER_KEY	27	/* from design doc (3.1.4) */
63 #define	SGENV_MAX_HPUS_PER_DOMAIN	24
64 #define	SGENV_MAX_HPU_KEYS		(SSM_MAX_INSTANCES * \
65 						SGENV_MAX_HPUS_PER_DOMAIN)
66 #define	SGENV_MAX_SENSORS		(SGENV_MAX_SENSORS_PER_KEY * \
67 						SGENV_MAX_HPU_KEYS)
68 
69 #define	SGENV_NO_NODE_EXISTS		0x0
70 #define	SGENV_NODE_TYPE_DS		0x3FF
71 
72 #define	SGENV_POLL_THREAD	0x1	/* cache update called from kstat */
73 #define	SGENV_INTERRUPT_THREAD	0x2	/* cache update called from softint */
74 
75 #define	BOARD_CACHE		0x1
76 #define	ENV_CACHE		0x2
77 
78 /*
79  * Event Publisher definitions for sysevent.
80  */
81 #define	EP_SGENV	SUNW_KERN_PUB SGENV_DRV_NAME
82 
83 /*
84  * Event definitions
85  */
86 #define	MAX_TAG_ID_STR_LEN		100
87 
88 #define	HPU_ENTRY(value_macro)	{	\
89 	value_macro,	\
90 	value_macro ## _STR,	\
91 	value_macro ## _ID	\
92 }
93 
94 #define	PART_VALUE(value_macro)	{	\
95 	value_macro,	\
96 	value_macro ## _STR	\
97 }
98 
99 #define	TYPE_VALUE(value_macro, scale) {	\
100 	value_macro,	\
101 	value_macro ## _STR,	\
102 	value_macro ## _UNITS,	\
103 	scale	\
104 }
105 
106 typedef struct hpu_value {
107 	unsigned	value;
108 	const char	*name;
109 	const char	*IDstr;
110 
111 } hpu_value_t;
112 
113 typedef struct part_value {
114 	unsigned	value;
115 	const char	*name;
116 } part_value_t;
117 
118 typedef struct type_value {
119 	unsigned	value;
120 	const char	*name;
121 	const char	*units;
122 	uint32_t	scale;
123 
124 } type_value_t;
125 
126 
127 /*
128  * SGENV soft state structure.
129  */
130 typedef struct sgenv_soft_state {
131 	int			instance;	/* instance number */
132 	dev_info_t		*dip;		/* dev_info structure */
133 	kstat_t			*keyswitch_ksp;
134 	kstat_t			*env_info_ksp;
135 	kstat_t			*board_info_ksp;
136 
137 } sgenv_soft_state_t;
138 
139 
140 /*
141  * Environmental Info Structures.
142  */
143 typedef int32_t envresp_key_t;
144 
145 typedef struct envresp_constants {
146 	sensor_id_t	id; /* sd_id */
147 	sensor_data_t	lo; /* sd_lo */
148 	sensor_data_t	hi; /* sd_hi */
149 	/* no padding required, 3x4-bytes in total length */
150 
151 } envresp_constants_t;
152 
153 typedef struct envresp_volatiles {
154 	sensor_status_t	info;	/* sd_infostamp */
155 	sensor_data_t	value;	/* sd_value */
156 	int32_t		_pad;	/* pad to 2x8-bytes */
157 
158 } envresp_volatiles_t;
159 
160 typedef struct envresp_thresholds {
161 	sensor_data_t	lo_warn; /* sd_lo_warn */
162 	sensor_data_t	hi_warn; /* sd_hi_warn */
163 	/* no padding required, 2x4-bytes in total length */
164 
165 } envresp_thresholds_t;
166 
167 
168 /*
169  * functions local to this driver.
170  */
171 static int	sgenv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
172 static int	sgenv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
173 
174 static int	sgenv_add_kstats(sgenv_soft_state_t *softsp);
175 static void	sgenv_remove_kstats(sgenv_soft_state_t *softsp);
176 
177 static int	sgenv_create_cache_update_threads(void);
178 static int	sgenv_remove_cache_update_threads(void);
179 static void	sgenv_indicate_cache_update_needed(int cache);
180 
181 static int	sgenv_keyswitch_kstat_update(kstat_t *ksp, int rw);
182 
183 static void	sgenv_init_env_cache(void);
184 static void	sgenv_update_env_cache(void);
185 static int	sgenv_env_info_kstat_update(kstat_t *ksp, int rw);
186 static int	sgenv_env_info_kstat_snapshot(kstat_t *ksp, void *buf, int rw);
187 static int	sgenv_get_env_info_data(void);
188 static int	sgenv_get_hpu_keys(envresp_key_t *new, int *status);
189 static int	sgenv_get_env_data(envresp_key_t key, int key_posn,
190 					uint16_t flag, int *status);
191 static int	sgenv_handle_env_data_error(int err, int status, int key_posn,
192 					envresp_key_t key, char *str);
193 static void	sgenv_mbox_error_msg(char *str, int err, int status);
194 static void	sgenv_destroy_env_cache(void);
195 static void	sgenv_clear_env_cache_entry(int key_posn);
196 static int	sgenv_create_env_cache_entry(int key_posn);
197 static void	sgenv_set_sensor_status(env_sensor_t *sensor);
198 static void	sgenv_update_env_kstat_size(kstat_t *ksp);
199 
200 static void	sgenv_init_board_cache(void);
201 static void	sgenv_update_board_cache(void);
202 static int	sgenv_board_info_kstat_update(kstat_t *ksp, int rw);
203 static int	sgenv_board_info_kstat_snapshot(kstat_t *ksp,
204 					void *buf, int rw);
205 static int	sgenv_get_board_info_data(void);
206 static void	sgenv_set_valid_node_positions(uint_t *node_present);
207 
208 static int	sgenv_process_threshold_event(env_sensor_t sensor);
209 static void	sgenv_tagid_to_string(sensor_id_t id, char *str);
210 static int	sgenv_add_intr_handlers(void);
211 static int	sgenv_remove_intr_handlers(void);
212 static uint_t	sgenv_keyswitch_handler(char *);
213 static uint_t	sgenv_env_data_handler(char *);
214 static uint_t	sgenv_fan_status_handler(char *);
215 static uint_t	sgenv_dr_event_handler(char *);
216 static uint_t	sgenv_check_sensor_thresholds(void);
217 static const char	*sgenv_get_hpu_id_str(uint_t hpu_type);
218 static const char	*sgenv_get_part_str(uint_t sensor_part);
219 static const char	*sgenv_get_type_str(uint_t sensor_type);
220 
221 
222 /*
223  * Debug stuff
224  */
225 #ifdef DEBUG
226 extern uint_t	sgenv_debug;
227 
228 #define	SGENV_DEBUG_NONE	0x00
229 #define	SGENV_DEBUG_POLL	0x01
230 #define	SGENV_DEBUG_EVENT	0x02
231 #define	SGENV_DEBUG_CACHE	0x04
232 #define	SGENV_DEBUG_MSG		0x08
233 #define	SGENV_DEBUG_THREAD	0x10
234 #define	SGENV_DEBUG_ALL		0xFF
235 
236 #define	DCMN_ERR_S(v, s)	static fn_t (v) = (s)
237 
238 #define	DCMN_ERR	cmn_err
239 #define	DCMN_ERR_EVENT	if (sgenv_debug & SGENV_DEBUG_EVENT)	DCMN_ERR
240 #define	DCMN_ERR_CACHE	if (sgenv_debug & SGENV_DEBUG_CACHE)	DCMN_ERR
241 #define	DCMN_ERR_THREAD	if (sgenv_debug & SGENV_DEBUG_THREAD)	DCMN_ERR
242 
243 #define	SGENV_PRINT_MBOX_MSG(x, str)    \
244 	DCMN_ERR(CE_CONT, "Mbox msg info: %s", str);    \
245 	DCMN_ERR(CE_CONT, "\ttype = 0x%x,", x->msg_type.type);     \
246 	DCMN_ERR(CE_CONT, "\tsub_type = 0x%x\n", x->msg_type.sub_type);    \
247 	DCMN_ERR(CE_CONT, "\tstatus = 0x%x\n", x->msg_status);     \
248 	DCMN_ERR(CE_CONT, "\tlen = %d\n", x->msg_len);   \
249 	DCMN_ERR(CE_CONT, "\tbytes = %d\n", x->msg_bytes);       \
250 	DCMN_ERR(CE_CONT, "\tdata[0] = %d\n", x->msg_data[0]);       \
251 	DCMN_ERR(CE_CONT, "\tdata[1] = %d\n", x->msg_data[1]);
252 
253 #define	SGENV_PRINT_ENV_INFO(x) \
254 	DCMN_ERR(CE_CONT, "Tag=%lx, Val=%d, Lo=%d, LoW=%d, HiW=%d, Hi=%d, " \
255 			"Inf=%llx St=%x PSt=%x",  \
256 		x.sd_id.tag_id, x.sd_value, \
257 		x.sd_lo, x.sd_lo_warn, x.sd_hi_warn, x.sd_hi, x.sd_infostamp, \
258 		SG_GET_SENSOR_STATUS(x.sd_status), \
259 		SG_GET_PREV_SENSOR_STATUS(x.sd_status));
260 
261 #define	SGENV_PRINT_POLL_INFO(x) \
262 		if (sgenv_debug & SGENV_DEBUG_POLL)	SGENV_PRINT_ENV_INFO(x)
263 
264 #else
265 #define	DCMN_ERR_S(v, s)	fn_t (v) = ""
266 
267 #define	_DCMN_ERR		cmn_err
268 #define	DCMN_ERR		if (0) _DCMN_ERR
269 #define	DCMN_ERR_EVENT		if (0) _DCMN_ERR
270 #define	DCMN_ERR_CACHE		if (0) _DCMN_ERR
271 #define	DCMN_ERR_THREAD		if (0) _DCMN_ERR
272 #define	SGENV_PRINT_MBOX_MSG
273 #define	SGENV_PRINT_ENV_INFO
274 #define	SGENV_PRINT_POLL_INFO
275 #endif
276 
277 #ifdef	__cplusplus
278 }
279 #endif
280 
281 #endif	/* _SYS_SGENV_IMPL_H */
282