xref: /titanic_51/usr/src/uts/common/sys/bscv_impl.h (revision dd4eeefdb8e4583c47e28a7f315db6087931ef06)
11c42de6dSgd78059 /*
21c42de6dSgd78059  * CDDL HEADER START
31c42de6dSgd78059  *
41c42de6dSgd78059  * The contents of this file are subject to the terms of the
51c42de6dSgd78059  * Common Development and Distribution License (the "License").
61c42de6dSgd78059  * You may not use this file except in compliance with the License.
71c42de6dSgd78059  *
81c42de6dSgd78059  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91c42de6dSgd78059  * or http://www.opensolaris.org/os/licensing.
101c42de6dSgd78059  * See the License for the specific language governing permissions
111c42de6dSgd78059  * and limitations under the License.
121c42de6dSgd78059  *
131c42de6dSgd78059  * When distributing Covered Code, include this CDDL HEADER in each
141c42de6dSgd78059  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151c42de6dSgd78059  * If applicable, add the following below this CDDL HEADER, with the
161c42de6dSgd78059  * fields enclosed by brackets "[]" replaced with your own identifying
171c42de6dSgd78059  * information: Portions Copyright [yyyy] [name of copyright owner]
181c42de6dSgd78059  *
191c42de6dSgd78059  * CDDL HEADER END
201c42de6dSgd78059  */
211c42de6dSgd78059 /*
22*dd4eeefdSeota  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
231c42de6dSgd78059  * Use is subject to license terms.
241c42de6dSgd78059  */
251c42de6dSgd78059 
261c42de6dSgd78059 #ifndef _SYS_BSCV_IMPL_H
271c42de6dSgd78059 #define	_SYS_BSCV_IMPL_H
281c42de6dSgd78059 
291c42de6dSgd78059 #pragma ident	"%Z%%M%	%I%	%E% SMI"
301c42de6dSgd78059 
311c42de6dSgd78059 /*
321c42de6dSgd78059  * Implementation private header file for bscv driver.
331c42de6dSgd78059  */
341c42de6dSgd78059 
351c42de6dSgd78059 #ifdef __cplusplus
361c42de6dSgd78059 extern "C" {
371c42de6dSgd78059 #endif
381c42de6dSgd78059 
391c42de6dSgd78059 #include <sys/lom_priv.h>
401c42de6dSgd78059 
411c42de6dSgd78059 
421c42de6dSgd78059 /*
431c42de6dSgd78059  * Local #defines
441c42de6dSgd78059  */
451c42de6dSgd78059 
461c42de6dSgd78059 #define	BSCV_SUCCESS	DDI_SUCCESS
471c42de6dSgd78059 #define	BSCV_FAILURE	DDI_FAILURE
481c42de6dSgd78059 
491c42de6dSgd78059 /*
501c42de6dSgd78059  * The following are used as progress indicators in bscv_attach()
511c42de6dSgd78059  */
521c42de6dSgd78059 
531c42de6dSgd78059 #define	BSCV_LOCKS		0x01
541c42de6dSgd78059 #define	BSCV_MAPPED_REGS	0x02
551c42de6dSgd78059 #define	BSCV_NODES		0x04
561c42de6dSgd78059 #define	BSCV_THREAD		0x08
571c42de6dSgd78059 #define	BSCV_HOSTNAME_DONE	0x10
581c42de6dSgd78059 #define	BSCV_WDOG_CFG		0x20
591c42de6dSgd78059 #define	BSCV_SIG_SENT		0x40
601c42de6dSgd78059 
611c42de6dSgd78059 /*
621c42de6dSgd78059  * macros to encode device minors and provide mapping to device instances.
631c42de6dSgd78059  * The following is designed to get around the problem of a 32-bit app not
641c42de6dSgd78059  * supporting a 32-bit minor number on an LP64 model system.
651c42de6dSgd78059  */
661c42de6dSgd78059 
671c42de6dSgd78059 #ifdef NBITSMINOR
681c42de6dSgd78059 #undef NBITSMINOR
691c42de6dSgd78059 #define	NBITSMINOR	18
701c42de6dSgd78059 #endif
711c42de6dSgd78059 
721c42de6dSgd78059 #define	BSCV_MONITOR_NODE	0
731c42de6dSgd78059 #define	BSCV_CONTROL_NODE	(1 << (NBITSMINOR - 1))
741c42de6dSgd78059 
751c42de6dSgd78059 #define	DEVICETOINSTANCE(x)	((getminor(x)) & (~BSCV_CONTROL_NODE));
761c42de6dSgd78059 
771c42de6dSgd78059 /*
781c42de6dSgd78059  * The maximum number of leds which are supported by this lom implementation.
791c42de6dSgd78059  */
801c42de6dSgd78059 #define	MAX_LED_ID	7
811c42de6dSgd78059 
821c42de6dSgd78059 /*
831c42de6dSgd78059  * general driver configuration constants which may be changed to improve
841c42de6dSgd78059  * performance/efficiency.
851c42de6dSgd78059  */
861c42de6dSgd78059 
871c42de6dSgd78059 #define	 INIT_BUSY_WAIT		10	/* 10 microsecs */
881c42de6dSgd78059 
891c42de6dSgd78059 #define	 MAX_WDOGTIMEOUT	127	/* maximum wdog timout - 127s */
901c42de6dSgd78059 
911c42de6dSgd78059 
921c42de6dSgd78059 /*
931c42de6dSgd78059  * Event processing task status flags.
941c42de6dSgd78059  */
951c42de6dSgd78059 #define	TASK_ALIVE_FLG		0x01
961c42de6dSgd78059 #define	TASK_STOP_FLG		0x02
971c42de6dSgd78059 #define	TASK_SLEEPING_FLG	0x04
981c42de6dSgd78059 #define	TASK_PAUSE_FLG		0x08
991c42de6dSgd78059 #define	TASK_EVENT_PENDING_FLG	0x10
1001c42de6dSgd78059 #define	TASK_EVENT_CONSUMER_FLG	0x20
1011c42de6dSgd78059 
1021c42de6dSgd78059 /*
1031c42de6dSgd78059  * strace(1M) prints out the debug data once the debug value is set in
1041c42de6dSgd78059  * the bscv.conf file and the debug driver is installed.
1051c42de6dSgd78059  *
1061c42de6dSgd78059  * Debug flags
1071c42de6dSgd78059  *
1081c42de6dSgd78059  * '@' - Register (@)ccess
1091c42de6dSgd78059  * 'A' - (A)ttach
1101c42de6dSgd78059  * 'B' - (B)lom1 attach extra
1111c42de6dSgd78059  * 'C' - lom1 (C)allback
1121c42de6dSgd78059  * 'D' - (D)aemon
1131c42de6dSgd78059  * 'E' - (E)vents
1141c42de6dSgd78059  * 'F' - Sel(F)test
1151c42de6dSgd78059  * 'I' - (I)octl
1161c42de6dSgd78059  * 'L' - TSa(L)arms
1171c42de6dSgd78059  * 'M' - (M)odel parameters
1181c42de6dSgd78059  * 'N' - I(N)terrupt Service Routine
1191c42de6dSgd78059  * 'O' - (O)pen/Close
1201c42de6dSgd78059  * 'P' - (P)rogramming
1211c42de6dSgd78059  * 'Q' - (Q)ueue things
1221c42de6dSgd78059  * 'R' - Read/Write (R)etry summary.
1231c42de6dSgd78059  * 'S' - Event (S)trings
1241c42de6dSgd78059  * 'U' - Programming ioctls
1251c42de6dSgd78059  * 'V' - ???
1261c42de6dSgd78059  * 'W' - (W)atchdog
1271c42de6dSgd78059  * 'X' - additional X86 functional calls
1281c42de6dSgd78059  * 'Z' - Temporary - just log things
1291c42de6dSgd78059  */
1301c42de6dSgd78059 
1311c42de6dSgd78059 /*
1321c42de6dSgd78059  * Debug tips :
1331c42de6dSgd78059  *
1341c42de6dSgd78059  * strace(1M) prints out the debug data.
1351c42de6dSgd78059  * A nice way to work out the debug value set in bscv.conf is to use mdb
1361c42de6dSgd78059  * Say we want to show 'D' Daemon and 'I' IOCTL processing,
1371c42de6dSgd78059  * you calculate the debug value with the following mdb session :
1381c42de6dSgd78059  * 	# mdb
1391c42de6dSgd78059  * 	> 1<<('D'-'@') | 1<<('I'-'@') = X
1401c42de6dSgd78059  *			210
1411c42de6dSgd78059  *	> $q
1421c42de6dSgd78059  * When you insert "debug=0x210;" into bscv.conf, it causes the next
1431c42de6dSgd78059  * reboot with the debug driver to trace Daemon and IOCTL functionality.
1441c42de6dSgd78059  */
1451c42de6dSgd78059 
1461c42de6dSgd78059 /*
1471c42de6dSgd78059  * Xbus channel access data
1481c42de6dSgd78059  */
1491c42de6dSgd78059 
1501c42de6dSgd78059 struct xbus_channel {
1511c42de6dSgd78059 	ddi_acc_handle_t	handle;
1521c42de6dSgd78059 	uint8_t			*regs;
1531c42de6dSgd78059 };
1541c42de6dSgd78059 
1551c42de6dSgd78059 #define	BSCV_MINCHANNELS	2
1561c42de6dSgd78059 #define	BSCV_MAXCHANNELS	16
1571c42de6dSgd78059 
1581c42de6dSgd78059 /*
1591c42de6dSgd78059  * soft state structure
1601c42de6dSgd78059  */
1611c42de6dSgd78059 
1621c42de6dSgd78059 typedef
1631c42de6dSgd78059 struct {
1641c42de6dSgd78059 	/*
1651c42de6dSgd78059 	 * Hardware instance variables
1661c42de6dSgd78059 	 */
1671c42de6dSgd78059 	uint64_t	debug;		/* debugging turned on */
1681c42de6dSgd78059 	major_t		majornum;	/* debugging - major number */
1691c42de6dSgd78059 	minor_t		minornum;	/* debugging - minor number */
1701c42de6dSgd78059 
1711c42de6dSgd78059 	dev_info_t	*dip;		/* pointer to device info tree */
1721c42de6dSgd78059 	int		instance;	/* instance number for the device */
1731c42de6dSgd78059 	ddi_device_acc_attr_t	attr;	/* device access attributes */
1741c42de6dSgd78059 
1751c42de6dSgd78059 	struct xbus_channel	channel[BSCV_MAXCHANNELS];
1761c42de6dSgd78059 	int			nchannels;
1771c42de6dSgd78059 
1781c42de6dSgd78059 	int		progress;	/* progress indicator for attach */
1791c42de6dSgd78059 
1801c42de6dSgd78059 	int		bad_resync;	/* Number of bad resyncs */
1811c42de6dSgd78059 
1821c42de6dSgd78059 	/*
1831c42de6dSgd78059 	 * lom data variables/arrays
1841c42de6dSgd78059 	 */
1851c42de6dSgd78059 	uint8_t		lom_regs[0x80]; /* registers on the lomlite */
1861c42de6dSgd78059 	int		serial_reporting;
1871c42de6dSgd78059 	int		reporting_level;
1881c42de6dSgd78059 
1891c42de6dSgd78059 	/*
1901c42de6dSgd78059 	 * lom2 static information.
1911c42de6dSgd78059 	 * setup at driver attach and restart after programming.
1921c42de6dSgd78059 	 */
1931c42de6dSgd78059 	int		num_fans;
1941c42de6dSgd78059 	char		fan_names[MAX_FANS][MAX_LOM2_NAME_STR];
1951c42de6dSgd78059 	uint8_t		fanspeed[MAX_FANS];
1961c42de6dSgd78059 	char		led_names[MAX_LED_ID][MAX_LOM2_NAME_STR];
1971c42de6dSgd78059 	lom_volts_t	volts;		/* keep a static copy of this so */
1981c42de6dSgd78059 					/* dont have to re-read names */
1991c42de6dSgd78059 	lom_temp_t	temps;		/* keep a static copy of this so */
2001c42de6dSgd78059 					/* dont have to re-read names */
2011c42de6dSgd78059 	lom_sflags_t	sflags;		/* keep a static copy of this so */
2021c42de6dSgd78059 					/* dont have to re-read names */
2031c42de6dSgd78059 	char		escape_chars[6];	/* local copy */
2041c42de6dSgd78059 
2051c42de6dSgd78059 	uint_t		watchdog_timeout;
2061c42de6dSgd78059 	uint8_t		watchdog_reset_on_timeout;
2071c42de6dSgd78059 
2081c42de6dSgd78059 	/*
2091c42de6dSgd78059 	 * lom2 firmware communication
2101c42de6dSgd78059 	 */
2111c42de6dSgd78059 
2121c42de6dSgd78059 	/*
2131c42de6dSgd78059 	 * cmd_mutex protects the lom2 command progress variables.
2141c42de6dSgd78059 	 * These should only be read/updated with the mutex held.
2151c42de6dSgd78059 	 *
2161c42de6dSgd78059 	 * command_error - acts as a return code and may be read
2171c42de6dSgd78059 	 * without the mutex held if a command is not in progress.
2181c42de6dSgd78059 	 * Note a read only returns failure if the lom does not respond.
2191c42de6dSgd78059 	 * So you might need to check the error code to see if things really
2201c42de6dSgd78059 	 * did work!
2211c42de6dSgd78059 	 *
2221c42de6dSgd78059 	 * addr_mu is used to protect stopping and starting of the queue.
2231c42de6dSgd78059 	 * BUT when programming it has different semantics and relies
2241c42de6dSgd78059 	 * on only the programming thread being in the ioctl routine
2251c42de6dSgd78059 	 * whilst programming is in progress. The event queue must also
2261c42de6dSgd78059 	 * be paused at this time.
2271c42de6dSgd78059 	 */
2281c42de6dSgd78059 	kmutex_t	cmd_mutex;	/* LOM command mutual exclusion */
2291c42de6dSgd78059 
2301c42de6dSgd78059 	int		command_error;	/* error code from last command */
2311c42de6dSgd78059 					/* valid until the next command */
2321c42de6dSgd78059 					/* starts. */
2331c42de6dSgd78059 
2341c42de6dSgd78059 	boolean_t	had_fault;	/* Current command sequence faulted */
2351c42de6dSgd78059 	boolean_t	had_session_error;	/* Current session had error */
2361c42de6dSgd78059 
2371c42de6dSgd78059 	uint8_t		pat_seq;	/* Watchdog patting sequence number */
2381c42de6dSgd78059 	uint8_t		cap0;		/* capability byte */
2391c42de6dSgd78059 	uint8_t		cap1;		/* capability byte */
2401c42de6dSgd78059 	uint8_t		cap2;		/* capability byte */
2411c42de6dSgd78059 
2421c42de6dSgd78059 	/*
2431c42de6dSgd78059 	 * Programming variables
2441c42de6dSgd78059 	 */
2451c42de6dSgd78059 	kmutex_t	prog_mu;	/* Programming mutex. - lom 2 */
2461c42de6dSgd78059 	boolean_t	prog_mode_only;	/* If true we can only reprogram */
2471c42de6dSgd78059 					/* the lom */
2481c42de6dSgd78059 	boolean_t	programming;	/* TRUE is actually programming */
2491c42de6dSgd78059 					/* the BSC */
2501c42de6dSgd78059 	boolean_t	cssp_prog;	/* TRUE is CSSP programming the BSC */
2511c42de6dSgd78059 
2521c42de6dSgd78059 	int		prog_index;	/* data buffer number - bit */
2531c42de6dSgd78059 					/* 0x8000 set if last buffer */
2541c42de6dSgd78059 	int		image_ptr;	/* ptr to next byte in image buffer */
2551c42de6dSgd78059 					/* for programming */
2561c42de6dSgd78059 	uint8_t 	*image;		/* ptr to image buffer for */
2571c42de6dSgd78059 					/* programming */
2581c42de6dSgd78059 	boolean_t	image2_processing;	/* boolean to say which of */
2591c42de6dSgd78059 					/* 2 BSC images being processed */
2601c42de6dSgd78059 	boolean_t	loader_running;	/* Still have the loader running */
2611c42de6dSgd78059 
2621c42de6dSgd78059 	/*
2631c42de6dSgd78059 	 * LOM eeprom window access state
2641c42de6dSgd78059 	 * Access under bscv_enter/bscv_exit protection.
2651c42de6dSgd78059 	 */
2661c42de6dSgd78059 	boolean_t	eeinfo_valid;
2671c42de6dSgd78059 	uint32_t	eeprom_size;
2681c42de6dSgd78059 	uint32_t	eventlog_start;
2691c42de6dSgd78059 	uint32_t	eventlog_size;
2701c42de6dSgd78059 	boolean_t	oldeeptr_valid;
2711c42de6dSgd78059 	uint16_t	oldeeptr;
2721c42de6dSgd78059 
2731c42de6dSgd78059 	/*
2741c42de6dSgd78059 	 * Communication with the event processing thread
2751c42de6dSgd78059 	 *
2761c42de6dSgd78059 	 * Change these variables with task_mu held and signal task_cv
2771c42de6dSgd78059 	 * if an event/task needs processing.
2781c42de6dSgd78059 	 */
2791c42de6dSgd78059 	kmutex_t	task_mu;	/* mutex for wait on event thread */
2801c42de6dSgd78059 	kcondvar_t	task_cv;	/* cv for wait on event thread */
2811c42de6dSgd78059 	kcondvar_t	task_evnt_cv;	/* cv for lom2 wait on event */
2821c42de6dSgd78059 	int		task_flags;	/* To monitor/stop the event thread */
2831c42de6dSgd78059 	volatile int	event_active_count; /* Count of event thread runs */
2841c42de6dSgd78059 	boolean_t	event_waiting;	/* New events are waiting in the lom */
2851c42de6dSgd78059 	boolean_t	status_change;	/* A status change is waiting */
2861c42de6dSgd78059 	boolean_t	nodename_change; /* Nodename has changed */
2871c42de6dSgd78059 	boolean_t	event_sleep;	/* Error reading events - wait a bit */
2881c42de6dSgd78059 	boolean_t	event_fault_reported;	/* Event fault reported */
2891c42de6dSgd78059 	boolean_t	watchdog_change; /* Watchdog config has changed */
2901c42de6dSgd78059 #ifdef __sparc
2911c42de6dSgd78059 	bscv_sig_t	last_sig;	/* Record of last signature sent */
2921c42de6dSgd78059 #endif /* __sparc */
2931c42de6dSgd78059 	uint8_t		last_event[8];	/* last event read and reported */
2941c42de6dSgd78059 #if defined(__i386) || defined(__amd64)
295*dd4eeefdSeota 	ddi_periodic_t 	periodic_id; /* watchdog patter periodical callback */
2961c42de6dSgd78059 	callb_id_t	callb_id;	/* Need to store the ID so we can */
2971c42de6dSgd78059 					/* unschedule the panic callback */
2981c42de6dSgd78059 	char		last_nodename[128]; /* copy of last utsname.nodename */
2991c42de6dSgd78059 #endif /* __i386 || __amd64 */
3001c42de6dSgd78059 } bscv_soft_state_t;
3011c42de6dSgd78059 
3021c42de6dSgd78059 struct bscv_idi_callout {
3031c42de6dSgd78059 	enum bscv_idi_type type;	/* Type of service */
3041c42de6dSgd78059 	boolean_t (*fn)(struct bscv_idi_info);	/* Function's address */
3051c42de6dSgd78059 };
3061c42de6dSgd78059 
3071c42de6dSgd78059 #define	BSCV_IDI_CALLOUT_MAGIC		0xb5c1ca11
3081c42de6dSgd78059 #define	BSCV_IDI_ERR_MSG_THRESHOLD	10
3091c42de6dSgd78059 struct bscv_idi_callout_mgr {
3101c42de6dSgd78059 	/*
3111c42de6dSgd78059 	 * To allow for sanity check.
3121c42de6dSgd78059 	 */
3131c42de6dSgd78059 	uint32_t magic;
3141c42de6dSgd78059 
3151c42de6dSgd78059 	/*
3161c42de6dSgd78059 	 * The instance number of "an" instance of the driver.  This is assigned
3171c42de6dSgd78059 	 * during driver attach.
3181c42de6dSgd78059 	 */
3191c42de6dSgd78059 	uint32_t valid_inst;
3201c42de6dSgd78059 
3211c42de6dSgd78059 	/*
3221c42de6dSgd78059 	 * Table of services offered via the idi interface.
3231c42de6dSgd78059 	 */
3241c42de6dSgd78059 	struct bscv_idi_callout *tbl;
3251c42de6dSgd78059 
3261c42de6dSgd78059 	/*
3271c42de6dSgd78059 	 * Error message count since last successful use of the idi interface.
3281c42de6dSgd78059 	 */
3291c42de6dSgd78059 	uint64_t errs;
3301c42de6dSgd78059 };
3311c42de6dSgd78059 
3321c42de6dSgd78059 
3331c42de6dSgd78059 
3341c42de6dSgd78059 #define	BSC_IMAGE_MAX_SIZE (0x20000 + sizeof (lom_prog_data_t))
3351c42de6dSgd78059 
3361c42de6dSgd78059 #define	BSC_PROBE_FAULT_LIMIT	8	/* Tries before declaring lom dead */
3371c42de6dSgd78059 #define	BSC_EVENT_POLL_NORMAL	(drv_usectohz(1000000))		/* 1 second */
3381c42de6dSgd78059 #define	BSC_EVENT_POLL_FAULTY	(drv_usectohz(10000000))	/* 10 second */
3391c42de6dSgd78059 
3401c42de6dSgd78059 #define	BSC_FAILURE_RETRY_LIMIT	5	/* Access retries before giving up */
3411c42de6dSgd78059 #define	BSC_ERASE_RETRY_LIMIT	5	/* Erase retries */
3421c42de6dSgd78059 #define	BSC_PAGE_RETRY_LIMIT	5	/* Page write retries */
3431c42de6dSgd78059 
3441c42de6dSgd78059 #define	BSC_ADDR_CACHE_LIMIT	\
3451c42de6dSgd78059 		(sizeof (((bscv_soft_state_t *)NULL)->lom_regs))
3461c42de6dSgd78059 #define	BSC_INFORM_ONLINE	0x4f530100
3471c42de6dSgd78059 #define	BSC_INFORM_OFFLINE	0x4f530201
3481c42de6dSgd78059 #define	BSC_INFORM_PANIC	0x4f530204
3491c42de6dSgd78059 
3501c42de6dSgd78059 #include <sys/lom_ebuscodes.h>
3511c42de6dSgd78059 
3521c42de6dSgd78059 typedef uint32_t bscv_addr_t;
3531c42de6dSgd78059 
3541c42de6dSgd78059 #define	BSC_NEXUS_ADDR(ssp, chan, as, index) \
3551c42de6dSgd78059 	(&((ssp)->channel[chan].regs[((as) * 256) + (index)]))
3561c42de6dSgd78059 
3571c42de6dSgd78059 #define	BSC_NEXUS_OFFSET(as, index) (((as) * 256) + (index))
3581c42de6dSgd78059 
3591c42de6dSgd78059 #define	BSCVA(as, index) (((as) * 256) + (index))
3601c42de6dSgd78059 
3611c42de6dSgd78059 #define	PSR_SUCCESS(status)	(((status) & EBUS_PROGRAM_PSR_STATUS_MASK) == \
3621c42de6dSgd78059     EBUS_PROGRAM_PSR_SUCCESS)
3631c42de6dSgd78059 
3641c42de6dSgd78059 #define	PSR_PROG(status)	(((status) & EBUS_PROGRAM_PSR_PROG_MODE) != 0)
3651c42de6dSgd78059 #ifdef	__cplusplus
3661c42de6dSgd78059 }
3671c42de6dSgd78059 #endif
3681c42de6dSgd78059 
3691c42de6dSgd78059 #endif	/* _SYS_BSCV_IMPL_H */
370