xref: /titanic_53/usr/src/uts/sun4v/sys/vdc.h (revision 0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
231ae08745Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo #ifndef	_VDC_H
281ae08745Sheppo #define	_VDC_H
291ae08745Sheppo 
301ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311ae08745Sheppo 
321ae08745Sheppo /*
331ae08745Sheppo  * Virtual disk client implementation definitions
341ae08745Sheppo  */
351ae08745Sheppo 
361ae08745Sheppo #include <sys/sysmacros.h>
371ae08745Sheppo #include <sys/note.h>
381ae08745Sheppo 
391ae08745Sheppo #include <sys/ldc.h>
401ae08745Sheppo #include <sys/vio_mailbox.h>
411ae08745Sheppo #include <sys/vdsk_mailbox.h>
421ae08745Sheppo #include <sys/vdsk_common.h>
431ae08745Sheppo 
441ae08745Sheppo #ifdef	__cplusplus
451ae08745Sheppo extern "C" {
461ae08745Sheppo #endif
471ae08745Sheppo 
481ae08745Sheppo #define	VDC_DRIVER_NAME		"vdc"
491ae08745Sheppo 
501ae08745Sheppo /*
511ae08745Sheppo  * Bit-field values to indicate if parts of the vdc driver are initialised.
521ae08745Sheppo  */
531ae08745Sheppo #define	VDC_SOFT_STATE	0x0001
541ae08745Sheppo #define	VDC_LOCKS	0x0002
551ae08745Sheppo #define	VDC_MINOR	0x0004
561ae08745Sheppo #define	VDC_THREAD	0x0008
571ae08745Sheppo #define	VDC_LDC		0x0010
581ae08745Sheppo #define	VDC_LDC_INIT	0x0020
591ae08745Sheppo #define	VDC_LDC_CB	0x0040
601ae08745Sheppo #define	VDC_LDC_OPEN	0x0080
611ae08745Sheppo #define	VDC_DRING_INIT	0x0100	/* The DRing was created */
621ae08745Sheppo #define	VDC_DRING_BOUND	0x0200	/* The DRing was bound to an LDC channel */
631ae08745Sheppo #define	VDC_DRING_LOCAL	0x0400	/* The local private DRing was allocated */
641ae08745Sheppo #define	VDC_DRING_ENTRY	0x0800	/* At least one DRing entry was initialised */
651ae08745Sheppo #define	VDC_DRING	(VDC_DRING_INIT | VDC_DRING_BOUND |	\
661ae08745Sheppo 				VDC_DRING_LOCAL | VDC_DRING_ENTRY)
671ae08745Sheppo #define	VDC_HANDSHAKE	0x1000	/* Indicates if a handshake is in progress */
681ae08745Sheppo #define	VDC_HANDSHAKE_STOP	0x2000	/* stop further handshakes */
691ae08745Sheppo 
701ae08745Sheppo /*
711ae08745Sheppo  * Definitions of strings to be used to create device node properties.
721ae08745Sheppo  * (vdc uses the capitalised versions of these properties as they are 64-bit)
731ae08745Sheppo  */
741ae08745Sheppo #define	VDC_NBLOCKS_PROP_NAME		"Nblocks"
751ae08745Sheppo #define	VDC_SIZE_PROP_NAME		"Size"
761ae08745Sheppo 
771ae08745Sheppo /*
781ae08745Sheppo  * Definitions of MD nodes/properties.
791ae08745Sheppo  */
801ae08745Sheppo #define	VDC_MD_CHAN_NAME		"channel-endpoint"
811ae08745Sheppo #define	VDC_MD_VDEV_NAME		"virtual-device"
821ae08745Sheppo #define	VDC_MD_DISK_NAME		"disk"
831ae08745Sheppo #define	VDC_MD_CFG_HDL			"cfg-handle"
841ae08745Sheppo #define	VDC_ID_PROP			"id"
851ae08745Sheppo 
861ae08745Sheppo /*
871ae08745Sheppo  * Scheme to store the instance number and the slice number in the minor number.
881ae08745Sheppo  * (Uses the same format and definitions as the sd(7D) driver)
891ae08745Sheppo  */
901ae08745Sheppo #define	VD_MAKE_DEV(instance, minor)	((instance << SDUNIT_SHIFT) | minor)
911ae08745Sheppo 
921ae08745Sheppo /*
931ae08745Sheppo  * variables controlling how long to wait before timing out and how many
941ae08745Sheppo  * retries to attempt before giving up when communicating with vds.
951ae08745Sheppo  */
96*0a55fbb7Slm66018 #define	VDC_RETRIES	3
971ae08745Sheppo 
981ae08745Sheppo #define	VDC_USEC_TIMEOUT_MIN	(30 * MICROSEC)		/* 30 sec */
991ae08745Sheppo 
1001ae08745Sheppo #define	VD_GET_TIMEOUT_HZ(mul)	\
1011ae08745Sheppo 	(ddi_get_lbolt() + (vdc_hz_timeout * MAX(1, mul)))
1021ae08745Sheppo 
1031ae08745Sheppo /*
1041ae08745Sheppo  * Macros to manipulate Descriptor Ring variables in the soft state
1051ae08745Sheppo  * structure.
1061ae08745Sheppo  */
1071ae08745Sheppo #define	VDC_GET_NEXT_REQ_ID(vdc)	((vdc->req_id)++)
1081ae08745Sheppo 
1091ae08745Sheppo #define	VDC_GET_DRING_ENTRY_PTR(vdc, idx)	\
1101ae08745Sheppo 		(vd_dring_entry_t *)(vdc->dring_mem_info.vaddr +	\
1111ae08745Sheppo 			(idx * vdc->dring_entry_size))
1121ae08745Sheppo 
1131ae08745Sheppo #define	VDC_MARK_DRING_ENTRY_FREE(vdc, idx)			\
1141ae08745Sheppo 	{ \
1151ae08745Sheppo 		vd_dring_entry_t *dep = NULL;				\
1161ae08745Sheppo 		ASSERT(vdc != NULL);					\
1171ae08745Sheppo 		ASSERT((idx >= 0) && (idx < VD_DRING_LEN));		\
1181ae08745Sheppo 		ASSERT(vdc->dring_mem_info.vaddr != NULL);		\
1191ae08745Sheppo 		dep = (vd_dring_entry_t *)(vdc->dring_mem_info.vaddr +	\
1201ae08745Sheppo 			(idx * vdc->dring_entry_size));			\
1211ae08745Sheppo 		ASSERT(dep != NULL);					\
1221ae08745Sheppo 		dep->hdr.dstate = VIO_DESC_FREE;			\
1231ae08745Sheppo 	}
1241ae08745Sheppo 
1251ae08745Sheppo /* Initialise the Session ID and Sequence Num in the DRing msg */
1261ae08745Sheppo #define	VDC_INIT_DRING_DATA_MSG_IDS(dmsg, vdc)		\
1271ae08745Sheppo 		ASSERT(vdc != NULL);			\
1281ae08745Sheppo 		dmsg.tag.vio_sid = vdc->session_id;	\
129*0a55fbb7Slm66018 		dmsg.seq_num = vdc->seq_num;
1301ae08745Sheppo 
1311ae08745Sheppo /*
1321ae08745Sheppo  * The states the message processing thread can be in.
1331ae08745Sheppo  */
1341ae08745Sheppo typedef enum vdc_thr_state {
1351ae08745Sheppo 	VDC_THR_RUNNING,	/* thread is running & ready to process */
1361ae08745Sheppo 	VDC_THR_STOP,		/* The detach func signals the thread to stop */
1371ae08745Sheppo 	VDC_THR_DONE		/* Thread has exited */
1381ae08745Sheppo } vdc_thr_state_t;
1391ae08745Sheppo 
1401ae08745Sheppo /*
1411ae08745Sheppo  * Local Descriptor Ring entry
1421ae08745Sheppo  *
1431ae08745Sheppo  * vdc creates a Local (private) descriptor ring the same size as the
1441ae08745Sheppo  * public descriptor ring it exports to vds.
1451ae08745Sheppo  */
1461ae08745Sheppo typedef struct vdc_local_desc {
1471ae08745Sheppo 	kmutex_t		lock;		/* protects all fields */
1481ae08745Sheppo 	kcondvar_t		cv;		/* indicate processing done */
1491ae08745Sheppo 	int			flags;		/* Dring entry state, etc */
1501ae08745Sheppo 	int			operation;	/* VD_OP_xxx to be performed */
1511ae08745Sheppo 	caddr_t			addr;		/* addr passed in by consumer */
1521ae08745Sheppo 	caddr_t			align_addr;	/* used if addr non-aligned */
1531ae08745Sheppo 	struct buf 		*buf;		/* buf passed to strategy() */
1541ae08745Sheppo 	ldc_mem_handle_t	desc_mhdl;	/* Mem handle of buf */
1551ae08745Sheppo 	vd_dring_entry_t	*dep;		/* public Dring Entry Pointer */
1561ae08745Sheppo } vdc_local_desc_t;
1571ae08745Sheppo 
1581ae08745Sheppo /*
1591ae08745Sheppo  * vdc soft state structure
1601ae08745Sheppo  */
1611ae08745Sheppo typedef struct vdc {
1621ae08745Sheppo 	kmutex_t	attach_lock;	/* used by CV which waits in attach */
1631ae08745Sheppo 	kcondvar_t	attach_cv;	/* signal when attach can finish */
1641ae08745Sheppo 
1651ae08745Sheppo 	kmutex_t	lock;		/* protects next 2 sections of vars */
1661ae08745Sheppo 	kcondvar_t	cv;		/* signal when upper layers can send */
1671ae08745Sheppo 
1681ae08745Sheppo 	dev_info_t	*dip;		/* device info pointer */
1691ae08745Sheppo 	int		instance;	/* driver instance number */
1701ae08745Sheppo 	int		initialized;	/* keeps track of what's init'ed */
171*0a55fbb7Slm66018 	int		hshake_cnt;	/* number of failed handshakes */
1721ae08745Sheppo 	int		open;		/* count of outstanding opens */
1731ae08745Sheppo 	int		dkio_flush_pending;	/* # outstanding DKIO flushes */
1741ae08745Sheppo 
175*0a55fbb7Slm66018 	vio_ver_t	ver;		/* version number agreed with server */
1761ae08745Sheppo 	uint64_t	session_id;	/* common ID sent with all messages */
1771ae08745Sheppo 	uint64_t	seq_num;	/* most recent sequence num generated */
1781ae08745Sheppo 	uint64_t	seq_num_reply;	/* Last seq num ACK/NACK'ed by vds */
1791ae08745Sheppo 	uint64_t	req_id;		/* Most recent Request ID generated */
1801ae08745Sheppo 	vd_state_t	state;		/* Current handshake state */
1811ae08745Sheppo 	vd_disk_type_t	vdisk_type;	/* type of device/disk being imported */
1821ae08745Sheppo 	uint64_t	vdisk_size;	/* device size in bytes */
1831ae08745Sheppo 	uint64_t	max_xfer_sz;	/* maximum block size of a descriptor */
1841ae08745Sheppo 	uint64_t	block_size;	/* device block size used */
185*0a55fbb7Slm66018 	struct dk_label	*label;		/* structure to store disk label */
1861ae08745Sheppo 	struct dk_cinfo	*cinfo;		/* structure to store DKIOCINFO data */
1871ae08745Sheppo 	struct dk_minfo	*minfo;		/* structure for DKIOCGMEDIAINFO data */
1881ae08745Sheppo 	struct vtoc	*vtoc;		/* structure to store VTOC data */
1891ae08745Sheppo 
1901ae08745Sheppo 	/*
1911ae08745Sheppo 	 * The mutex 'msg_proc_lock' protects the following group of fields.
1921ae08745Sheppo 	 *
1931ae08745Sheppo 	 * The callback function checks to see if LDC triggered it due to
1941ae08745Sheppo 	 * there being data available and the callback will signal to
1951ae08745Sheppo 	 * the message processing thread waiting on 'msg_proc_cv'.
1961ae08745Sheppo 	 */
1971ae08745Sheppo 	kmutex_t		msg_proc_lock;
1981ae08745Sheppo 	kcondvar_t		msg_proc_cv;
1991ae08745Sheppo 	boolean_t		msg_pending;
2001ae08745Sheppo 	vdc_thr_state_t		msg_proc_thr_state;
2011ae08745Sheppo 	kthread_t		*msg_proc_thr_id;
2021ae08745Sheppo 
2031ae08745Sheppo 	/*
2041ae08745Sheppo 	 * The mutex 'dring_lock'  protects the following group of fields.
2051ae08745Sheppo 	 */
2061ae08745Sheppo 	kmutex_t		dring_lock;
2071ae08745Sheppo 	ldc_mem_info_t		dring_mem_info;
2081ae08745Sheppo 	uint_t			dring_curr_idx;
2091ae08745Sheppo 	uint32_t		dring_len;
2101ae08745Sheppo 	uint32_t		dring_cookie_count;
2111ae08745Sheppo 	uint32_t		dring_entry_size;
2121ae08745Sheppo 	ldc_mem_cookie_t	*dring_cookie;
2131ae08745Sheppo 	uint64_t		dring_ident;
2141ae08745Sheppo 
2151ae08745Sheppo 	vdc_local_desc_t	*local_dring;
2161ae08745Sheppo 
2171ae08745Sheppo 	uint64_t		ldc_id;
2181ae08745Sheppo 	ldc_status_t		ldc_state;
2191ae08745Sheppo 	ldc_handle_t		ldc_handle;
2201ae08745Sheppo 	ldc_dring_handle_t	ldc_dring_hdl;
2211ae08745Sheppo } vdc_t;
2221ae08745Sheppo 
2231ae08745Sheppo /*
2241ae08745Sheppo  * Debugging macros
2251ae08745Sheppo  */
2261ae08745Sheppo #ifdef DEBUG
2271ae08745Sheppo extern int	vdc_msglevel;
2281ae08745Sheppo 
2291ae08745Sheppo #define	PR0 if (vdc_msglevel > 0)	\
2301ae08745Sheppo 		vdc_msg
2311ae08745Sheppo 
2321ae08745Sheppo #define	PR1 if (vdc_msglevel > 1)	\
2331ae08745Sheppo 		vdc_msg
2341ae08745Sheppo 
2351ae08745Sheppo #define	PR2 if (vdc_msglevel > 2)	\
2361ae08745Sheppo 		vdc_msg
2371ae08745Sheppo 
2381ae08745Sheppo #define	VDC_DUMP_DRING_MSG(dmsgp)					\
2391ae08745Sheppo 		vdc_msg("sq:%d start:%d end:%d ident:%x\n",		\
2401ae08745Sheppo 			dmsgp->seq_num, dmsgp->start_idx,		\
2411ae08745Sheppo 			dmsgp->end_idx, dmsgp->dring_ident);
2421ae08745Sheppo 
2431ae08745Sheppo #else	/* !DEBUG */
2441ae08745Sheppo #define	PR0(...)
2451ae08745Sheppo #define	PR1(...)
2461ae08745Sheppo #define	PR2(...)
2471ae08745Sheppo 
2481ae08745Sheppo #define	VDC_DUMP_DRING_MSG(dmsgp)
2491ae08745Sheppo 
2501ae08745Sheppo #endif	/* !DEBUG */
2511ae08745Sheppo 
2521ae08745Sheppo #ifdef	__cplusplus
2531ae08745Sheppo }
2541ae08745Sheppo #endif
2551ae08745Sheppo 
2561ae08745Sheppo #endif	/* _VDC_H */
257