xref: /titanic_50/usr/src/uts/common/sys/bscv_impl.h (revision 142c9f13e148d687426ed2d4e8bd93717eeaebbc)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_BSCV_IMPL_H
27 #define	_SYS_BSCV_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Implementation private header file for bscv driver.
33  */
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/lom_priv.h>
40 
41 
42 /*
43  * Local #defines
44  */
45 
46 #define	BSCV_SUCCESS	DDI_SUCCESS
47 #define	BSCV_FAILURE	DDI_FAILURE
48 
49 /*
50  * The following are used as progress indicators in bscv_attach()
51  */
52 
53 #define	BSCV_LOCKS		0x01
54 #define	BSCV_MAPPED_REGS	0x02
55 #define	BSCV_NODES		0x04
56 #define	BSCV_THREAD		0x08
57 #define	BSCV_HOSTNAME_DONE	0x10
58 #define	BSCV_WDOG_CFG		0x20
59 #define	BSCV_SIG_SENT		0x40
60 
61 /*
62  * macros to encode device minors and provide mapping to device instances.
63  * The following is designed to get around the problem of a 32-bit app not
64  * supporting a 32-bit minor number on an LP64 model system.
65  */
66 
67 #ifdef NBITSMINOR
68 #undef NBITSMINOR
69 #define	NBITSMINOR	18
70 #endif
71 
72 #define	BSCV_MONITOR_NODE	0
73 #define	BSCV_CONTROL_NODE	(1 << (NBITSMINOR - 1))
74 
75 #define	DEVICETOINSTANCE(x)	((getminor(x)) & (~BSCV_CONTROL_NODE));
76 
77 /*
78  * The maximum number of leds which are supported by this lom implementation.
79  */
80 #define	MAX_LED_ID	7
81 
82 /*
83  * general driver configuration constants which may be changed to improve
84  * performance/efficiency.
85  */
86 
87 #define	 INIT_BUSY_WAIT		10	/* 10 microsecs */
88 
89 #define	 MAX_WDOGTIMEOUT	127	/* maximum wdog timout - 127s */
90 
91 
92 /*
93  * Event processing task status flags.
94  */
95 #define	TASK_ALIVE_FLG		0x01
96 #define	TASK_STOP_FLG		0x02
97 #define	TASK_SLEEPING_FLG	0x04
98 #define	TASK_PAUSE_FLG		0x08
99 #define	TASK_EVENT_PENDING_FLG	0x10
100 #define	TASK_EVENT_CONSUMER_FLG	0x20
101 
102 /*
103  * strace(1M) prints out the debug data once the debug value is set in
104  * the bscv.conf file and the debug driver is installed.
105  *
106  * Debug flags
107  *
108  * '@' - Register (@)ccess
109  * 'A' - (A)ttach
110  * 'B' - (B)lom1 attach extra
111  * 'C' - lom1 (C)allback
112  * 'D' - (D)aemon
113  * 'E' - (E)vents
114  * 'F' - Sel(F)test
115  * 'I' - (I)octl
116  * 'L' - TSa(L)arms
117  * 'M' - (M)odel parameters
118  * 'N' - I(N)terrupt Service Routine
119  * 'O' - (O)pen/Close
120  * 'P' - (P)rogramming
121  * 'Q' - (Q)ueue things
122  * 'R' - Read/Write (R)etry summary.
123  * 'S' - Event (S)trings
124  * 'U' - Programming ioctls
125  * 'V' - ???
126  * 'W' - (W)atchdog
127  * 'X' - additional X86 functional calls
128  * 'Z' - Temporary - just log things
129  */
130 
131 /*
132  * Debug tips :
133  *
134  * strace(1M) prints out the debug data.
135  * A nice way to work out the debug value set in bscv.conf is to use mdb
136  * Say we want to show 'D' Daemon and 'I' IOCTL processing,
137  * you calculate the debug value with the following mdb session :
138  * 	# mdb
139  * 	> 1<<('D'-'@') | 1<<('I'-'@') = X
140  *			210
141  *	> $q
142  * When you insert "debug=0x210;" into bscv.conf, it causes the next
143  * reboot with the debug driver to trace Daemon and IOCTL functionality.
144  */
145 
146 /*
147  * Xbus channel access data
148  */
149 
150 struct xbus_channel {
151 	ddi_acc_handle_t	handle;
152 	uint8_t			*regs;
153 };
154 
155 #define	BSCV_MINCHANNELS	2
156 #define	BSCV_MAXCHANNELS	16
157 
158 /*
159  * soft state structure
160  */
161 
162 typedef
163 struct {
164 	/*
165 	 * Hardware instance variables
166 	 */
167 	uint64_t	debug;		/* debugging turned on */
168 	major_t		majornum;	/* debugging - major number */
169 	minor_t		minornum;	/* debugging - minor number */
170 
171 	dev_info_t	*dip;		/* pointer to device info tree */
172 	int		instance;	/* instance number for the device */
173 	ddi_device_acc_attr_t	attr;	/* device access attributes */
174 
175 	struct xbus_channel	channel[BSCV_MAXCHANNELS];
176 	int			nchannels;
177 
178 	int		progress;	/* progress indicator for attach */
179 
180 	int		bad_resync;	/* Number of bad resyncs */
181 
182 	/*
183 	 * lom data variables/arrays
184 	 */
185 	uint8_t		lom_regs[0x80]; /* registers on the lomlite */
186 	int		serial_reporting;
187 	int		reporting_level;
188 
189 	/*
190 	 * lom2 static information.
191 	 * setup at driver attach and restart after programming.
192 	 */
193 	int		num_fans;
194 	char		fan_names[MAX_FANS][MAX_LOM2_NAME_STR];
195 	uint8_t		fanspeed[MAX_FANS];
196 	char		led_names[MAX_LED_ID][MAX_LOM2_NAME_STR];
197 	lom_volts_t	volts;		/* keep a static copy of this so */
198 					/* dont have to re-read names */
199 	lom_temp_t	temps;		/* keep a static copy of this so */
200 					/* dont have to re-read names */
201 	lom_sflags_t	sflags;		/* keep a static copy of this so */
202 					/* dont have to re-read names */
203 	char		escape_chars[6];	/* local copy */
204 
205 	uint_t		watchdog_timeout;
206 	uint8_t		watchdog_reset_on_timeout;
207 
208 	/*
209 	 * lom2 firmware communication
210 	 */
211 
212 	/*
213 	 * cmd_mutex protects the lom2 command progress variables.
214 	 * These should only be read/updated with the mutex held.
215 	 *
216 	 * command_error - acts as a return code and may be read
217 	 * without the mutex held if a command is not in progress.
218 	 * Note a read only returns failure if the lom does not respond.
219 	 * So you might need to check the error code to see if things really
220 	 * did work!
221 	 *
222 	 * addr_mu is used to protect stopping and starting of the queue.
223 	 * BUT when programming it has different semantics and relies
224 	 * on only the programming thread being in the ioctl routine
225 	 * whilst programming is in progress. The event queue must also
226 	 * be paused at this time.
227 	 */
228 	kmutex_t	cmd_mutex;	/* LOM command mutual exclusion */
229 
230 	int		command_error;	/* error code from last command */
231 					/* valid until the next command */
232 					/* starts. */
233 
234 	boolean_t	had_fault;	/* Current command sequence faulted */
235 	boolean_t	had_session_error;	/* Current session had error */
236 
237 	uint8_t		pat_seq;	/* Watchdog patting sequence number */
238 	uint8_t		cap0;		/* capability byte */
239 	uint8_t		cap1;		/* capability byte */
240 	uint8_t		cap2;		/* capability byte */
241 
242 	/*
243 	 * Programming variables
244 	 */
245 	kmutex_t	prog_mu;	/* Programming mutex. - lom 2 */
246 	boolean_t	prog_mode_only;	/* If true we can only reprogram */
247 					/* the lom */
248 	boolean_t	programming;	/* TRUE is actually programming */
249 					/* the BSC */
250 	boolean_t	cssp_prog;	/* TRUE is CSSP programming the BSC */
251 
252 	int		prog_index;	/* data buffer number - bit */
253 					/* 0x8000 set if last buffer */
254 	int		image_ptr;	/* ptr to next byte in image buffer */
255 					/* for programming */
256 	uint8_t 	*image;		/* ptr to image buffer for */
257 					/* programming */
258 	boolean_t	image2_processing;	/* boolean to say which of */
259 					/* 2 BSC images being processed */
260 	boolean_t	loader_running;	/* Still have the loader running */
261 
262 	/*
263 	 * LOM eeprom window access state
264 	 * Access under bscv_enter/bscv_exit protection.
265 	 */
266 	boolean_t	eeinfo_valid;
267 	uint32_t	eeprom_size;
268 	uint32_t	eventlog_start;
269 	uint32_t	eventlog_size;
270 	boolean_t	oldeeptr_valid;
271 	uint16_t	oldeeptr;
272 
273 	/*
274 	 * Communication with the event processing thread
275 	 *
276 	 * Change these variables with task_mu held and signal task_cv
277 	 * if an event/task needs processing.
278 	 */
279 	kmutex_t	task_mu;	/* mutex for wait on event thread */
280 	kcondvar_t	task_cv;	/* cv for wait on event thread */
281 	kcondvar_t	task_evnt_cv;	/* cv for lom2 wait on event */
282 	int		task_flags;	/* To monitor/stop the event thread */
283 	volatile int	event_active_count; /* Count of event thread runs */
284 	boolean_t	event_waiting;	/* New events are waiting in the lom */
285 	boolean_t	status_change;	/* A status change is waiting */
286 	boolean_t	nodename_change; /* Nodename has changed */
287 	boolean_t	event_sleep;	/* Error reading events - wait a bit */
288 	boolean_t	event_fault_reported;	/* Event fault reported */
289 	boolean_t	watchdog_change; /* Watchdog config has changed */
290 #ifdef __sparc
291 	bscv_sig_t	last_sig;	/* Record of last signature sent */
292 #endif /* __sparc */
293 	uint8_t		last_event[8];	/* last event read and reported */
294 #if defined(__i386) || defined(__amd64)
295 	ddi_periodic_t 	periodic_id; /* watchdog patter periodical callback */
296 	callb_id_t	callb_id;	/* Need to store the ID so we can */
297 					/* unschedule the panic callback */
298 	char		last_nodename[128]; /* copy of last utsname.nodename */
299 #endif /* __i386 || __amd64 */
300 } bscv_soft_state_t;
301 
302 struct bscv_idi_callout {
303 	enum bscv_idi_type type;	/* Type of service */
304 	boolean_t (*fn)(struct bscv_idi_info);	/* Function's address */
305 };
306 
307 #define	BSCV_IDI_CALLOUT_MAGIC		0xb5c1ca11
308 #define	BSCV_IDI_ERR_MSG_THRESHOLD	10
309 struct bscv_idi_callout_mgr {
310 	/*
311 	 * To allow for sanity check.
312 	 */
313 	uint32_t magic;
314 
315 	/*
316 	 * The instance number of "an" instance of the driver.  This is assigned
317 	 * during driver attach.
318 	 */
319 	uint32_t valid_inst;
320 
321 	/*
322 	 * Table of services offered via the idi interface.
323 	 */
324 	struct bscv_idi_callout *tbl;
325 
326 	/*
327 	 * Error message count since last successful use of the idi interface.
328 	 */
329 	uint64_t errs;
330 };
331 
332 
333 
334 #define	BSC_IMAGE_MAX_SIZE (0x20000 + sizeof (lom_prog_data_t))
335 
336 #define	BSC_PROBE_FAULT_LIMIT	8	/* Tries before declaring lom dead */
337 #define	BSC_EVENT_POLL_NORMAL	(drv_usectohz(1000000))		/* 1 second */
338 #define	BSC_EVENT_POLL_FAULTY	(drv_usectohz(10000000))	/* 10 second */
339 
340 #define	BSC_FAILURE_RETRY_LIMIT	5	/* Access retries before giving up */
341 #define	BSC_ERASE_RETRY_LIMIT	5	/* Erase retries */
342 #define	BSC_PAGE_RETRY_LIMIT	5	/* Page write retries */
343 
344 #define	BSC_ADDR_CACHE_LIMIT	\
345 		(sizeof (((bscv_soft_state_t *)NULL)->lom_regs))
346 #define	BSC_INFORM_ONLINE	0x4f530100
347 #define	BSC_INFORM_OFFLINE	0x4f530201
348 #define	BSC_INFORM_PANIC	0x4f530204
349 
350 #include <sys/lom_ebuscodes.h>
351 
352 typedef uint32_t bscv_addr_t;
353 
354 #define	BSC_NEXUS_ADDR(ssp, chan, as, index) \
355 	(&((ssp)->channel[chan].regs[((as) * 256) + (index)]))
356 
357 #define	BSC_NEXUS_OFFSET(as, index) (((as) * 256) + (index))
358 
359 #define	BSCVA(as, index) (((as) * 256) + (index))
360 
361 #define	PSR_SUCCESS(status)	(((status) & EBUS_PROGRAM_PSR_STATUS_MASK) == \
362     EBUS_PROGRAM_PSR_SUCCESS)
363 
364 #define	PSR_PROG(status)	(((status) & EBUS_PROGRAM_PSR_PROG_MODE) != 0)
365 #ifdef	__cplusplus
366 }
367 #endif
368 
369 #endif	/* _SYS_BSCV_IMPL_H */
370