xref: /titanic_44/usr/src/cmd/picl/plugins/sun4u/lw2plus/fcal_leds/fcal_leds.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_FCAL_LEDS_H
28 #define	_FCAL_LEDS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <picl.h>
33 #include <picltree.h>
34 #include <picldefs.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Header file for the FC-AL LEDs PICL plugin.
42  * Contains message texts, constant definitions, typedefs for enums and
43  * structs, global data and function templates.
44  */
45 
46 #define	SYSLOG	syslog
47 
48 /*
49  * log message tests
50  */
51 #define	EM_CANT_OPEN	\
52 	gettext("SUNW_fcal_leds: open fail: %s\n")
53 #define	EM_NONALF_TOK	\
54 	gettext("SUNW_fcal_leds: line %d token begins non-alpha\n")
55 #define	EM_LONG_TOK	\
56 	gettext("SUNW_fcal_leds: line %d token too long\n")
57 #define	EM_UNKN_TOK	\
58 	gettext("SUNW_fcal_leds: line %d unknown token\n")
59 #define	EM_INVAL_TOK	\
60 	gettext("SUNW_fcal_leds: line %d invalid token at start of line\n")
61 #define	EM_NOCOLON	\
62 	gettext("SUNW_fcal_leds: line %d leading token not followed by ':'\n")
63 #define	EM_NOVERS	\
64 	gettext("SUNW_fcal_leds: first token not VERSION\n")
65 #define	EM_NUM_TERM	\
66 	gettext("SUNW_fcal_leds: invalid number terminator\n")
67 #define	EM_LOGIC_LVL	\
68 	gettext("SUNW_fcal_leds: logic level specified as neither 0 nor 1\n")
69 #define	EM_NOTPOS	\
70 	gettext("SUNW_fcal_leds: numeric field greater than 0 expected\n")
71 #define	EM_DISK_RANGE	\
72 	gettext("SUNW_fcal_leds: disk number out of range\n")
73 #define	EM_NDISKS_DBL	\
74 	gettext("SUNW_fcal_leds: number of disks defined twice\n")
75 #define	EM_NO_DISKS	\
76 	gettext("SUNW_fcal_leds: no disks defined\n")
77 #define	EM_VER_FRMT	\
78 	gettext("SUNW_fcal_leds: format error in VERSION string\n")
79 #define	EM_WRNGVER	\
80 	gettext("SUNW_fcal_leds: config version %d.%d not supported\n")
81 #define	EM_REL_PATH	\
82 	gettext("SUNW_fcal_leds: path names must be absolute\n")
83 #define	EM_ERRLINE	\
84 	gettext("SUNW_fcal_leds: error on line %d\n")
85 #define	EM_NO_LED_PROP	\
86 	gettext("SUNW_fcal_leds: LED property name missing\n")
87 #define	EM_PROP_TERM	\
88 	gettext("SUNW_fcal_leds: expected comma (',') after property name\n")
89 #define	EM_STR_NOT_SET	\
90 	gettext("SUNW_fcal_leds: %s not defined")
91 #define	EM_I2C_GET_PORT	\
92 	gettext("SUNW_fcal_leds: I2C_GET_PORT: %s\n")
93 #define	EM_DI_INIT_FAIL	\
94 	gettext("SUNW_fcal_leds: di_init failed: %s\n")
95 #define	EM_THREAD_CREATE_FAILED \
96 	gettext("SUNW_fcal_leds: pthread_create() call failed: %s\n")
97 #define	EM_MUTEX_FAIL	\
98 	gettext("SUNW_fcal_leds: pthread_mutex_lock returned: %s\n")
99 #define	EM_CONDWAITFAIL	\
100 	gettext("SUNW_fcal_leds: pthread_cond_wait returned: %s\n")
101 #define	EM_SPURIOUS_FP	\
102 	gettext("SUNW_fcal_leds: deleting spurious PICL fp node\n")
103 #define	EM_NO_FP_NODE \
104 	gettext(	\
105 	    "SUNW_fcal_leds: cannot get PICL disk node for hot plug disk %d\n")
106 #define	EM_POLL_FAIL	\
107 	gettext("SUNW_fcal_leds: poll() returned: %s, no more timed events\n")
108 
109 /*
110  * config file terminal name
111  */
112 #define	FCAL_LEDS_CONF_FILE	"fcal_leds.conf"
113 
114 /*
115  * devinfo hardware properties
116  */
117 #define	HW_PROP_TARGET		"target"
118 #define	HW_PROP_PORT		"port-wwn"
119 
120 /*
121  * PICL node names
122  */
123 #define	FCAL_PICL_DISK_UNIT	"disk-unit"
124 
125 /*
126  * PICL property names
127  */
128 #define	FCAL_PICL_REF		"_"
129 #define	FCAL_PICL_PROP_BUS_ADDR	"bus-addr"
130 #define	FCAL_PICL_PROP_TARGET	"target"
131 #define	FCAL_PICL_LED_REF	FCAL_PICL_REF PICL_CLASS_LED FCAL_PICL_REF
132 #define	FCAL_PICL_BLOCK_REF	FCAL_PICL_REF PICL_CLASS_BLOCK FCAL_PICL_REF
133 
134 /*
135  * String values for led State property
136  */
137 #define	FCAL_PICL_LED_ON	"on"
138 #define	FCAL_PICL_LED_OFF	"off"
139 #define	FCAL_PICL_LED_TEST	"led test"
140 /*
141  * MAX_LEN_LED_STATE is (strlen(FCAL_PICL_LED_TEST) + 1)
142  */
143 #define	MAX_LEN_LED_STATE	9
144 
145 /*
146  * Space for 0123456789ABCDEF,0123456789ABCDEF<nul>
147  */
148 #define	MAX_LEN_UNIT_ADDRESS	34
149 
150 /*
151  * properties per row in Device table
152  */
153 #define	FCAL_DEVTABLE_NCOLS	2
154 
155 /*
156  * number of LEDs per disk
157  */
158 #define	FCAL_LED_CNT	3
159 
160 /*
161  * special values for status when ioctl fails
162  */
163 #define	I2C_IOCTL_FAIL	(-1)
164 #define	I2C_IOCTL_INIT	(-2)
165 #define	MINORS_UNKNOWN	(-1)
166 
167 /*
168  * other status values
169  */
170 #define	NO_MINORS	0
171 #define	HAS_MINORS	1
172 
173 /*
174  * event flags
175  */
176 #define	FCAL_EV_POLL	1
177 #define	FCAL_EV_CONFIG	2
178 
179 /*
180  * default timer values - overridden by .conf file
181  */
182 #define	DFLT_SLOW_POLL	59
183 #define	DFLT_FAST_POLL	2
184 #define	DFLT_RELAX_TIME	300
185 #define	DFLT_TEST_TIME	10
186 
187 typedef enum token {
188 	NO_TOKEN,
189 	TOKEN_ERROR,
190 	FCAL_VERSION,
191 	LED_PROPS_START,	/* next enums are for led properties */
192 	FCAL_REMOK_LED,
193 	FCAL_FAULT_LED,
194 	FCAL_READY_LED,
195 	LED_PROPS_END,		/* no more led properties */
196 	LINE_DEFS,		/* next enums define configuration lines */
197 	FCAL_LEDS_BOARD,
198 	FCAL_STATUS_BOARD,
199 	FCAL_DISK_DRIVER,
200 	FCAL_N_DISKS,
201 	FCAL_ASSERT_PRESENT,
202 	FCAL_ASSERT_FAULT,
203 	FCAL_LED_ON,
204 	FCAL_DISK_PRESENT,
205 	FCAL_DISK_FAULT,
206 	FCAL_LED_ID,
207 	FCAL_SLOW_POLL,
208 	FCAL_FAST_POLL,
209 	FCAL_RELAX_INTERVAL,
210 	FCAL_TEST_INTERVAL,
211 	FCAL_DISK_PARENT,
212 	FCAL_UNIT_PARENT,
213 	FCAL_LED_NODES
214 } token_t;
215 
216 typedef enum led_state_enum {
217 	LED_STATE_OFF,
218 	LED_STATE_ON,
219 	LED_STATE_TEST
220 } led_state_t;
221 
222 typedef char *str;
223 typedef const char *cstr;
224 
225 /*
226  * Note on disk_prev and disk_ready flags.
227  * The following entries are dynamically created arrays:
228  * presence, faults, disk_detected, disk_ready, disk_prev, led_test_end,
229  * disk_port, led_addr.
230  * The disk_prev and disk_ready flags (one per disk) are used as follows:
231  * disk removed (disk_detected = 0), disk_ready[d] = 0, disk_prev[d] = 0
232  * disk present (disk_detected = 1) use this table:
233  * disk_ready[d] | disk_prev[d] | meaning
234  *      0        |      0       | driver not (yet) attached (show green led)
235  *      0        |      1       | driver has been detached (show blue led)
236  *      1        |      0       | driver attached, PICL update needed (green)
237  *      1        |      1       | driver attached, normal running (green)
238  * OK to remove (blue) is only lit for the attached -> detached transition
239  * state 1 0 (PICL update needed) is really transient and is cleared after
240  * calling update_picl.
241  */
242 typedef struct led_dtls {
243 	int		ver_maj;
244 	int		ver_min;
245 	cstr		fcal_leds;	/* path name of leds board */
246 	cstr		fcal_status;	/* path of back-plane status board */
247 	cstr		fcal_driver;	/* name of fcal disk driver */
248 	int		n_disks;	/* number of fcal disks */
249 	int		*presence;	/* presence detection masks */
250 	int		*faults;	/* fault status masks */
251 	int		*disk_detected;	/* working store for detected disks */
252 	int		*disk_ready;	/* working store for disk ready */
253 	int		*disk_prev;	/* previous ready state */
254 	volatile int	*led_test_end;	/* (per disk) ticks to end led test */
255 	boolean_t	*picl_retry;	/* (per disk) retry picl update flag */
256 	uchar_t		**disk_port;	/* for FC-AL this is WWN */
257 	int		assert_presence; /* status value for presence */
258 	int		assert_fault;	/* status value for fault */
259 	int		assert_led_on;	/* level required to light led */
260 	uint_t		*led_addr[FCAL_LED_CNT]; /* 2D array to leds */
261 	led_state_t	*led_state[FCAL_LED_CNT]; /* current states */
262 	boolean_t	led_retry;	/* flag set after led ioctl failure */
263 	volatile boolean_t polling;	/* set to B_FALSE after poll failure */
264 	volatile int	fast_poll_end;	/* fast_poll ticks left */
265 	int		fast_poll;	/* fast_poll interval in seconds */
266 	int		slow_poll_ticks; /* fast polls per slow poll */
267 	int		relax_time_ticks; /* time interval to do fast polling */
268 	int		led_test_time;	/* fast polls in led test interval */
269 	cstr		fcal_disk_parent; /* search string for /platform */
270 	cstr		disk_unit_parent; /* search template for disk-slots */
271 	cstr		disk_led_nodes;	/* search template for disk-leds */
272 } led_dtls_t;
273 
274 typedef int (*actfun_t)(str *p_str, led_dtls_t *dtls);
275 
276 typedef struct lookup {
277 	token_t		tok;
278 	cstr		tok_str;
279 	actfun_t	action;
280 } lookup_t;
281 
282 /*
283  * global data
284  */
285 extern led_dtls_t	*g_led_dtls;
286 extern pthread_cond_t	g_cv;
287 extern pthread_cond_t	g_cv_ack;
288 extern pthread_mutex_t	g_mutex;
289 extern volatile int	g_event_flag;
290 extern volatile boolean_t g_finish_now;
291 extern volatile boolean_t g_leds_thread_ack;
292 extern volatile boolean_t g_poll_thread_ack;
293 
294 /*
295  * function templates
296  */
297 char *mystrerror(int err);
298 void *fcal_leds_thread(void *args);
299 int fc_led_parse(FILE *fp, led_dtls_t **p_dtls);
300 void free_led_dtls(led_dtls_t *dtls);
301 int find_disk_slot(led_dtls_t *dtls, int disk, picl_nodehdl_t *nodeh);
302 void delete_disk_unit(led_dtls_t *dtls, int disk);
303 boolean_t is_led_test(led_dtls_t *dtls);
304 int create_Device_table(picl_prophdl_t *tbl_h, picl_prophdl_t *tableh);
305 void clr_led(int diskNo, token_t led_tok, led_dtls_t *dtls);
306 
307 #ifdef	__cplusplus
308 }
309 #endif
310 
311 #endif	/* _FCAL_LEDS_H */
312