xref: /titanic_52/usr/src/uts/sun4v/sys/vdc.h (revision ca6d128098b8e877673c13a3db1a0d3417ce5879)
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 /*
23*ca6d1280SAlexandre Chartre  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
241ae08745Sheppo  */
251ae08745Sheppo 
261ae08745Sheppo #ifndef	_VDC_H
271ae08745Sheppo #define	_VDC_H
281ae08745Sheppo 
291ae08745Sheppo /*
301ae08745Sheppo  * Virtual disk client implementation definitions
311ae08745Sheppo  */
321ae08745Sheppo 
331ae08745Sheppo #include <sys/sysmacros.h>
341ae08745Sheppo #include <sys/note.h>
351ae08745Sheppo 
361ae08745Sheppo #include <sys/ldc.h>
371ae08745Sheppo #include <sys/vio_mailbox.h>
381ae08745Sheppo #include <sys/vdsk_mailbox.h>
391ae08745Sheppo #include <sys/vdsk_common.h>
401ae08745Sheppo 
411ae08745Sheppo #ifdef	__cplusplus
421ae08745Sheppo extern "C" {
431ae08745Sheppo #endif
441ae08745Sheppo 
451ae08745Sheppo #define	VDC_DRIVER_NAME		"vdc"
461ae08745Sheppo 
471ae08745Sheppo /*
481ae08745Sheppo  * Bit-field values to indicate if parts of the vdc driver are initialised.
491ae08745Sheppo  */
501ae08745Sheppo #define	VDC_SOFT_STATE	0x0001
511ae08745Sheppo #define	VDC_LOCKS	0x0002
521ae08745Sheppo #define	VDC_MINOR	0x0004
531ae08745Sheppo #define	VDC_THREAD	0x0008
548cd10891Snarayan #define	VDC_DRING_INIT	0x0010	/* The DRing was created */
558cd10891Snarayan #define	VDC_DRING_BOUND	0x0020	/* The DRing was bound to an LDC channel */
568cd10891Snarayan #define	VDC_DRING_LOCAL	0x0040	/* The local private DRing was allocated */
578cd10891Snarayan #define	VDC_DRING_ENTRY	0x0080	/* At least one DRing entry was initialised */
581ae08745Sheppo #define	VDC_DRING	(VDC_DRING_INIT | VDC_DRING_BOUND |	\
591ae08745Sheppo 				VDC_DRING_LOCAL | VDC_DRING_ENTRY)
608cd10891Snarayan #define	VDC_HANDSHAKE	0x0100	/* Indicates if a handshake is in progress */
618cd10891Snarayan #define	VDC_HANDSHAKE_STOP	0x0200	/* stop further handshakes */
621ae08745Sheppo 
631ae08745Sheppo /*
641ae08745Sheppo  * Definitions of MD nodes/properties.
651ae08745Sheppo  */
661ae08745Sheppo #define	VDC_MD_CHAN_NAME		"channel-endpoint"
671ae08745Sheppo #define	VDC_MD_VDEV_NAME		"virtual-device"
68655fd6a9Sachartre #define	VDC_MD_PORT_NAME		"virtual-device-port"
691ae08745Sheppo #define	VDC_MD_DISK_NAME		"disk"
701ae08745Sheppo #define	VDC_MD_CFG_HDL			"cfg-handle"
71655fd6a9Sachartre #define	VDC_MD_TIMEOUT			"vdc-timeout"
72655fd6a9Sachartre #define	VDC_MD_ID			"id"
731ae08745Sheppo 
741ae08745Sheppo /*
75e1ebb9ecSlm66018  * Definition of actions to be carried out when processing the sequence ID
76e1ebb9ecSlm66018  * of a message received from the vDisk server. The function verifying the
77e1ebb9ecSlm66018  * sequence number checks the 'seq_num_xxx' fields in the soft state and
78e1ebb9ecSlm66018  * returns whether the message should be processed (VDC_SEQ_NUM_TODO) or
79e1ebb9ecSlm66018  * whether it was it was previously processed (VDC_SEQ_NUM_SKIP).
80e1ebb9ecSlm66018  */
81e1ebb9ecSlm66018 #define	VDC_SEQ_NUM_INVALID		-1	/* Error */
82e1ebb9ecSlm66018 #define	VDC_SEQ_NUM_SKIP		0	/* Request already processed */
83e1ebb9ecSlm66018 #define	VDC_SEQ_NUM_TODO		1	/* Request needs processing */
84e1ebb9ecSlm66018 
85e1ebb9ecSlm66018 /*
86007a3653SAlexandre Chartre  * DRing reserved entries. Entry 0 is reserved and only used for error
87007a3653SAlexandre Chartre  * checking. This is done so that error checking can be done even if the
88007a3653SAlexandre Chartre  * DRing is full. All other entries are available for regular I/Os.
89007a3653SAlexandre Chartre  */
90007a3653SAlexandre Chartre #define	VDC_DRING_NUM_RESV		1	/* #reserved entries */
91007a3653SAlexandre Chartre #define	VDC_DRING_FIRST_RESV		0	/* 1st reserved entry */
92007a3653SAlexandre Chartre #define	VDC_DRING_FIRST_ENTRY		\
93007a3653SAlexandre Chartre 	    (VDC_DRING_FIRST_RESV + VDC_DRING_NUM_RESV)	/* 1st non-resv entry */
94007a3653SAlexandre Chartre 
95007a3653SAlexandre Chartre /*
966ace3c90SAlexandre Chartre  * Flags for virtual disk operations.
976ace3c90SAlexandre Chartre  */
986ace3c90SAlexandre Chartre #define	VDC_OP_STATE_RUNNING	0x01	/* do operation in running state */
996ace3c90SAlexandre Chartre #define	VDC_OP_ERRCHK_BACKEND	0x02	/* check backend on error */
1006ace3c90SAlexandre Chartre #define	VDC_OP_ERRCHK_CONFLICT	0x04	/* check resv conflict on error */
101007a3653SAlexandre Chartre #define	VDC_OP_DRING_RESERVED	0x08	/* use dring reserved entry */
102*ca6d1280SAlexandre Chartre #define	VDC_OP_RESUBMIT		0x10	/* I/O is being resubmitted */
1036ace3c90SAlexandre Chartre 
1046ace3c90SAlexandre Chartre #define	VDC_OP_ERRCHK	(VDC_OP_ERRCHK_BACKEND | VDC_OP_ERRCHK_CONFLICT)
1056ace3c90SAlexandre Chartre #define	VDC_OP_NORMAL	(VDC_OP_STATE_RUNNING | VDC_OP_ERRCHK)
1066ace3c90SAlexandre Chartre 
1076ace3c90SAlexandre Chartre /*
1080d0c8d4bSnarayan  * Macros to get UNIT and PART number
1091ae08745Sheppo  */
1100d0c8d4bSnarayan #define	VDCUNIT_SHIFT	3
1110d0c8d4bSnarayan #define	VDCPART_MASK	7
1120d0c8d4bSnarayan 
1130d0c8d4bSnarayan #define	VDCUNIT(dev)	(getminor((dev)) >> VDCUNIT_SHIFT)
1140d0c8d4bSnarayan #define	VDCPART(dev)	(getminor((dev)) &  VDCPART_MASK)
1150d0c8d4bSnarayan 
1160d0c8d4bSnarayan /*
1170d0c8d4bSnarayan  * Scheme to store the instance number and the slice number in the minor number.
1180d0c8d4bSnarayan  * (NOTE: Uses the same format and definitions as the sd(7D) driver)
1190d0c8d4bSnarayan  */
1200d0c8d4bSnarayan #define	VD_MAKE_DEV(instance, minor)	((instance << VDCUNIT_SHIFT) | minor)
1211ae08745Sheppo 
12265908c77Syu, larry liu - Sun Microsystems - Beijing China #define	VDC_EFI_DEV_SET(dev, vdsk, ioctl)	\
12365908c77Syu, larry liu - Sun Microsystems - Beijing China 	VDSK_EFI_DEV_SET(dev, vdsk, ioctl,	\
12465908c77Syu, larry liu - Sun Microsystems - Beijing China 	    (vdsk)->vdisk_bsize, (vdsk)->vdisk_size)
12565908c77Syu, larry liu - Sun Microsystems - Beijing China 
126*ca6d1280SAlexandre Chartre /* max number of handshake retries per server */
127*ca6d1280SAlexandre Chartre #define	VDC_HSHAKE_RETRIES	3
1281ae08745Sheppo 
129*ca6d1280SAlexandre Chartre /* minimum number of attribute negotiations before handshake failure */
130*ca6d1280SAlexandre Chartre #define	VDC_HATTR_MIN_INITIAL	3
131*ca6d1280SAlexandre Chartre #define	VDC_HATTR_MIN		1
1321ae08745Sheppo 
133e1ebb9ecSlm66018 /*
134e1ebb9ecSlm66018  * This macro returns the number of Hz that the vdc driver should wait before
135e1ebb9ecSlm66018  * a timeout is triggered. The 'timeout' parameter specifiecs the wait
136e1ebb9ecSlm66018  * time in Hz. The 'mul' parameter allows for a multiplier to be
137e1ebb9ecSlm66018  * specified allowing for a backoff to be implemented (e.g. using the
138e1ebb9ecSlm66018  * retry number as a multiplier) where the wait time will get longer if
139e1ebb9ecSlm66018  * there is no response on the previous retry.
140e1ebb9ecSlm66018  */
141e1ebb9ecSlm66018 #define	VD_GET_TIMEOUT_HZ(timeout, mul)	\
142e1ebb9ecSlm66018 	(ddi_get_lbolt() + ((timeout) * MAX(1, (mul))))
1431ae08745Sheppo 
1441ae08745Sheppo /*
1451ae08745Sheppo  * Macros to manipulate Descriptor Ring variables in the soft state
1461ae08745Sheppo  * structure.
1471ae08745Sheppo  */
148e1ebb9ecSlm66018 #define	VDC_GET_NEXT_REQ_ID(vdc)	((vdc)->req_id++)
1491ae08745Sheppo 
1501ae08745Sheppo #define	VDC_GET_DRING_ENTRY_PTR(vdc, idx)	\
15117cadca8Slm66018 		(vd_dring_entry_t *)(uintptr_t)((vdc)->dring_mem_info.vaddr + \
152e1ebb9ecSlm66018 			(idx * (vdc)->dring_entry_size))
1531ae08745Sheppo 
1541ae08745Sheppo #define	VDC_MARK_DRING_ENTRY_FREE(vdc, idx)			\
1551ae08745Sheppo 	{ \
1561ae08745Sheppo 		vd_dring_entry_t *dep = NULL;				\
1571ae08745Sheppo 		ASSERT(vdc != NULL);					\
15817cadca8Slm66018 		ASSERT(idx < vdc->dring_len);		\
1591ae08745Sheppo 		ASSERT(vdc->dring_mem_info.vaddr != NULL);		\
16017cadca8Slm66018 		dep = (vd_dring_entry_t *)(uintptr_t)			\
16117cadca8Slm66018 			(vdc->dring_mem_info.vaddr +	\
1621ae08745Sheppo 			(idx * vdc->dring_entry_size));			\
1631ae08745Sheppo 		ASSERT(dep != NULL);					\
1641ae08745Sheppo 		dep->hdr.dstate = VIO_DESC_FREE;			\
1651ae08745Sheppo 	}
1661ae08745Sheppo 
1671ae08745Sheppo /* Initialise the Session ID and Sequence Num in the DRing msg */
1681ae08745Sheppo #define	VDC_INIT_DRING_DATA_MSG_IDS(dmsg, vdc)		\
1691ae08745Sheppo 		ASSERT(vdc != NULL);			\
1701ae08745Sheppo 		dmsg.tag.vio_sid = vdc->session_id;	\
1710a55fbb7Slm66018 		dmsg.seq_num = vdc->seq_num;
1721ae08745Sheppo 
1731ae08745Sheppo /*
1743af08d82Slm66018  * The states that the read thread can be in.
1751ae08745Sheppo  */
1763af08d82Slm66018 typedef enum vdc_rd_state {
1773af08d82Slm66018 	VDC_READ_IDLE,			/* idling - conn is not up */
1783af08d82Slm66018 	VDC_READ_WAITING,		/* waiting for data */
1793af08d82Slm66018 	VDC_READ_PENDING,		/* pending data avail for read */
1803af08d82Slm66018 	VDC_READ_RESET			/* channel was reset - stop reads */
1813af08d82Slm66018 } vdc_rd_state_t;
1823af08d82Slm66018 
1833af08d82Slm66018 /*
1843af08d82Slm66018  * The states that the vdc-vds connection can be in.
1853af08d82Slm66018  */
1863af08d82Slm66018 typedef enum vdc_state {
1873af08d82Slm66018 	VDC_STATE_INIT,			/* device is initialized */
1883af08d82Slm66018 	VDC_STATE_INIT_WAITING,		/* waiting for ldc connection */
1893af08d82Slm66018 	VDC_STATE_NEGOTIATE,		/* doing handshake negotiation */
1903af08d82Slm66018 	VDC_STATE_HANDLE_PENDING,	/* handle requests in backup dring */
1916ace3c90SAlexandre Chartre 	VDC_STATE_FAULTED,		/* multipath backend is inaccessible */
1926ace3c90SAlexandre Chartre 	VDC_STATE_FAILED,		/* device is not usable */
1933af08d82Slm66018 	VDC_STATE_RUNNING,		/* running and accepting requests */
1943af08d82Slm66018 	VDC_STATE_DETACH,		/* detaching */
1953af08d82Slm66018 	VDC_STATE_RESETTING		/* resetting connection with vds */
1963af08d82Slm66018 } vdc_state_t;
1973af08d82Slm66018 
1983af08d82Slm66018 /*
1996ace3c90SAlexandre Chartre  * States of the service provided by a vds server
2006ace3c90SAlexandre Chartre  */
2016ace3c90SAlexandre Chartre typedef enum vdc_service_state {
2026ace3c90SAlexandre Chartre 	VDC_SERVICE_NONE = -1, 		/* no state define */
2036ace3c90SAlexandre Chartre 	VDC_SERVICE_OFFLINE,		/* no connection with the service */
2046ace3c90SAlexandre Chartre 	VDC_SERVICE_CONNECTED,		/* connection established */
2056ace3c90SAlexandre Chartre 	VDC_SERVICE_ONLINE,		/* connection and backend available */
2066ace3c90SAlexandre Chartre 	VDC_SERVICE_FAILED,		/* connection failed */
2076ace3c90SAlexandre Chartre 	VDC_SERVICE_FAULTED		/* connection but backend unavailable */
2086ace3c90SAlexandre Chartre } vdc_service_state_t;
2096ace3c90SAlexandre Chartre 
2106ace3c90SAlexandre Chartre /*
2113af08d82Slm66018  * The states that the vdc instance can be in.
2123af08d82Slm66018  */
2133af08d82Slm66018 typedef enum vdc_lc_state {
2143af08d82Slm66018 	VDC_LC_ATTACHING,	/* driver is attaching */
215*ca6d1280SAlexandre Chartre 	VDC_LC_ONLINE_PENDING,	/* driver is attached, handshake pending */
2163af08d82Slm66018 	VDC_LC_ONLINE,		/* driver is attached and online */
2173af08d82Slm66018 	VDC_LC_DETACHING	/* driver is detaching */
2183af08d82Slm66018 } vdc_lc_state_t;
2191ae08745Sheppo 
2201ae08745Sheppo /*
2211ae08745Sheppo  * Local Descriptor Ring entry
2221ae08745Sheppo  *
2231ae08745Sheppo  * vdc creates a Local (private) descriptor ring the same size as the
2241ae08745Sheppo  * public descriptor ring it exports to vds.
2251ae08745Sheppo  */
2263af08d82Slm66018 
2273af08d82Slm66018 typedef enum {
2283af08d82Slm66018 	VIO_read_dir,		/* read data from server */
2293af08d82Slm66018 	VIO_write_dir,		/* write data to server */
2303af08d82Slm66018 	VIO_both_dir		/* transfer both in and out in same buffer */
2313af08d82Slm66018 } vio_desc_direction_t;
2323af08d82Slm66018 
2331ae08745Sheppo typedef struct vdc_local_desc {
2343af08d82Slm66018 	boolean_t		is_free;	/* local state - inuse or not */
2353af08d82Slm66018 
2361ae08745Sheppo 	int			operation;	/* VD_OP_xxx to be performed */
2371ae08745Sheppo 	caddr_t			addr;		/* addr passed in by consumer */
2383af08d82Slm66018 	int			slice;
2393af08d82Slm66018 	diskaddr_t		offset;		/* disk offset */
2403af08d82Slm66018 	size_t			nbytes;
2416ace3c90SAlexandre Chartre 	struct buf		*buf;		/* buf of operation */
2423af08d82Slm66018 	vio_desc_direction_t	dir;		/* direction of transfer */
2436ace3c90SAlexandre Chartre 	int			flags;		/* flags of operation */
2443af08d82Slm66018 
2451ae08745Sheppo 	caddr_t			align_addr;	/* used if addr non-aligned */
2461ae08745Sheppo 	ldc_mem_handle_t	desc_mhdl;	/* Mem handle of buf */
2471ae08745Sheppo 	vd_dring_entry_t	*dep;		/* public Dring Entry Pointer */
2483af08d82Slm66018 
2491ae08745Sheppo } vdc_local_desc_t;
2501ae08745Sheppo 
2511ae08745Sheppo /*
2526ace3c90SAlexandre Chartre  * I/O queue used for checking backend or failfast
2532f5224aeSachartre  */
2542f5224aeSachartre typedef struct vdc_io {
2552f5224aeSachartre 	struct vdc_io	*vio_next;	/* next pending I/O in the queue */
2566ace3c90SAlexandre Chartre 	int		vio_index;	/* descriptor index */
2572f5224aeSachartre 	clock_t		vio_qtime;	/* time the I/O was queued */
2582f5224aeSachartre } vdc_io_t;
2592f5224aeSachartre 
2602f5224aeSachartre /*
2618cd10891Snarayan  * Per vDisk server channel states
2628cd10891Snarayan  */
2638cd10891Snarayan #define	VDC_LDC_INIT	0x0001
2648cd10891Snarayan #define	VDC_LDC_CB	0x0002
2658cd10891Snarayan #define	VDC_LDC_OPEN	0x0004
2668cd10891Snarayan #define	VDC_LDC		(VDC_LDC_INIT | VDC_LDC_CB | VDC_LDC_OPEN)
2678cd10891Snarayan 
2688cd10891Snarayan /*
2698cd10891Snarayan  * vDisk server information
2708cd10891Snarayan  */
2718cd10891Snarayan typedef struct vdc_server {
2728cd10891Snarayan 	struct vdc_server	*next;			/* Next server */
2738cd10891Snarayan 	struct vdc		*vdcp;			/* Ptr to vdc struct */
2748cd10891Snarayan 	uint64_t		id;			/* Server port id */
2758cd10891Snarayan 	uint64_t		state;			/* Server state */
2766ace3c90SAlexandre Chartre 	vdc_service_state_t	svc_state;		/* Service state */
2776ace3c90SAlexandre Chartre 	vdc_service_state_t	log_state;		/* Last state logged */
2788cd10891Snarayan 	uint64_t		ldc_id;			/* Server LDC id */
2798cd10891Snarayan 	ldc_handle_t		ldc_handle;		/* Server LDC handle */
2808cd10891Snarayan 	ldc_status_t		ldc_state;		/* Server LDC state */
2818cd10891Snarayan 	uint64_t		ctimeout;		/* conn tmout (secs) */
282*ca6d1280SAlexandre Chartre 	uint_t			hshake_cnt;		/* handshakes count */
283*ca6d1280SAlexandre Chartre 	uint_t			hattr_cnt;		/* attr. neg. count */
284*ca6d1280SAlexandre Chartre 	uint_t			hattr_total;		/* attr. neg. total */
2858cd10891Snarayan } vdc_server_t;
2868cd10891Snarayan 
2878cd10891Snarayan /*
2881ae08745Sheppo  * vdc soft state structure
2891ae08745Sheppo  */
2901ae08745Sheppo typedef struct vdc {
2911ae08745Sheppo 
2921ae08745Sheppo 	kmutex_t	lock;		/* protects next 2 sections of vars */
2933af08d82Slm66018 	kcondvar_t	running_cv;	/* signal when upper layers can send */
2943af08d82Slm66018 	kcondvar_t	initwait_cv;	/* signal when ldc conn is up */
2953af08d82Slm66018 	kcondvar_t	dring_free_cv;	/* signal when desc is avail */
2963af08d82Slm66018 	kcondvar_t	membind_cv;	/* signal when mem can be bound */
2976ace3c90SAlexandre Chartre 	boolean_t	self_reset;	/* self initiated reset */
2986ace3c90SAlexandre Chartre 	kcondvar_t	io_pending_cv;	/* signal on pending I/O */
2996ace3c90SAlexandre Chartre 	boolean_t	io_pending;	/* pending I/O */
3001ae08745Sheppo 
3011ae08745Sheppo 	int		initialized;	/* keeps track of what's init'ed */
3023af08d82Slm66018 	vdc_lc_state_t	lifecycle;	/* Current state of the vdc instance */
303*ca6d1280SAlexandre Chartre 	uint_t		hattr_min;	/* min. # attribute negotiations */
3043af08d82Slm66018 
30578fcd0a1Sachartre 	uint8_t		open[OTYPCNT];	/* mask of opened slices */
30678fcd0a1Sachartre 	uint8_t		open_excl;	/* mask of exclusively opened slices */
30778fcd0a1Sachartre 	ulong_t		open_lyr[V_NUMPAR]; /* number of layered opens */
3081ae08745Sheppo 	int		dkio_flush_pending; /* # outstanding DKIO flushes */
30978fcd0a1Sachartre 	int		validate_pending; /* # outstanding validate request */
31078fcd0a1Sachartre 	vd_disk_label_t vdisk_label; 	/* label type of device/disk imported */
311342440ecSPrasad Singamsetty 	struct extvtoc	*vtoc;		/* structure to store VTOC data */
31278fcd0a1Sachartre 	struct dk_geom	*geom;		/* structure to store geometry data */
313edcc0754Sachartre 	vd_slice_t	slice[V_NUMPAR]; /* logical partitions */
3141ae08745Sheppo 
3153af08d82Slm66018 	kthread_t	*msg_proc_thr;	/* main msg processing thread */
3163af08d82Slm66018 
3173af08d82Slm66018 	kmutex_t	read_lock;	/* lock to protect read */
3183af08d82Slm66018 	kcondvar_t	read_cv;	/* cv to wait for READ events */
3193af08d82Slm66018 	vdc_rd_state_t	read_state;	/* current read state */
3203af08d82Slm66018 
3213af08d82Slm66018 	uint32_t	sync_op_cnt;	/* num of active sync operations */
3223af08d82Slm66018 	boolean_t	sync_op_blocked; /* blocked waiting to do sync op */
3233af08d82Slm66018 	kcondvar_t	sync_blocked_cv; /* cv wait for other syncs to finish */
3243af08d82Slm66018 
3251ae08745Sheppo 	uint64_t	session_id;	/* common ID sent with all messages */
3261ae08745Sheppo 	uint64_t	seq_num;	/* most recent sequence num generated */
3271ae08745Sheppo 	uint64_t	seq_num_reply;	/* Last seq num ACK/NACK'ed by vds */
3281ae08745Sheppo 	uint64_t	req_id;		/* Most recent Request ID generated */
329e1ebb9ecSlm66018 	uint64_t	req_id_proc;	/* Last request ID processed by vdc */
3303af08d82Slm66018 	vdc_state_t	state;		/* Current disk client-server state */
331e1ebb9ecSlm66018 
332e1ebb9ecSlm66018 	dev_info_t	*dip;		/* device info pointer */
333e1ebb9ecSlm66018 	int		instance;	/* driver instance number */
3343af08d82Slm66018 
335e1ebb9ecSlm66018 	vio_ver_t	ver;		/* version number agreed with server */
3361ae08745Sheppo 	vd_disk_type_t	vdisk_type;	/* type of device/disk being imported */
33717cadca8Slm66018 	uint32_t	vdisk_media;	/* physical media type of vDisk */
3384bac2208Snarayan 	uint64_t	vdisk_size;	/* device size in blocks */
3391ae08745Sheppo 	uint64_t	max_xfer_sz;	/* maximum block size of a descriptor */
34065908c77Syu, larry liu - Sun Microsystems - Beijing China 	uint64_t	vdisk_bsize;	/* blk size for the virtual disk */
34165908c77Syu, larry liu - Sun Microsystems - Beijing China 	uint32_t	vio_bmask;	/* mask to check vio blk alignment */
34265908c77Syu, larry liu - Sun Microsystems - Beijing China 	int		vio_bshift;	/* shift for vio blk conversion */
34317cadca8Slm66018 	uint64_t	operations;	/* bitmask of ops. server supports */
3441ae08745Sheppo 	struct dk_cinfo	*cinfo;		/* structure to store DKIOCINFO data */
3451ae08745Sheppo 	struct dk_minfo	*minfo;		/* structure for DKIOCGMEDIAINFO data */
3464bac2208Snarayan 	ddi_devid_t	devid;		/* device id */
347655fd6a9Sachartre 	boolean_t	ctimeout_reached; /* connection timeout has expired */
3481ae08745Sheppo 
3492f5224aeSachartre 	/*
3502f5224aeSachartre 	 * The ownership fields are protected by the lock mutex. The
3512f5224aeSachartre 	 * ownership_lock mutex is used to serialize ownership operations;
3522f5224aeSachartre 	 * it should be acquired before the lock mutex.
3532f5224aeSachartre 	 */
3542f5224aeSachartre 	kmutex_t	ownership_lock;		/* serialize ownership ops */
3552f5224aeSachartre 	int		ownership;		/* ownership status flags */
3562f5224aeSachartre 	kthread_t	*ownership_thread;	/* ownership thread */
3572f5224aeSachartre 	kcondvar_t	ownership_cv;		/* cv for ownership update */
3582f5224aeSachartre 
3592f5224aeSachartre 	/*
3606ace3c90SAlexandre Chartre 	 * The eio and failfast fields are protected by the lock mutex.
3612f5224aeSachartre 	 */
3626ace3c90SAlexandre Chartre 	kthread_t	*eio_thread;		/* error io thread */
3636ace3c90SAlexandre Chartre 	kcondvar_t	eio_cv;			/* cv for eio thread update */
3646ace3c90SAlexandre Chartre 	vdc_io_t	*eio_queue;		/* error io queue */
3652f5224aeSachartre 	clock_t		failfast_interval;	/* interval in microsecs */
3662f5224aeSachartre 
367366a92acSlm66018 	/*
368366a92acSlm66018 	 * kstats used to store I/O statistics consumed by iostat(1M).
369366a92acSlm66018 	 * These are protected by the lock mutex.
370366a92acSlm66018 	 */
371366a92acSlm66018 	kstat_t		*io_stats;
372366a92acSlm66018 	kstat_t		*err_stats;
373366a92acSlm66018 
3748cd10891Snarayan 	ldc_dring_handle_t	dring_hdl;		/* dring handle */
3753af08d82Slm66018 	ldc_mem_info_t		dring_mem_info;		/* dring information */
3763af08d82Slm66018 	uint_t			dring_curr_idx;		/* current index */
3773af08d82Slm66018 	uint32_t		dring_len;		/* dring length */
3783af08d82Slm66018 	uint32_t		dring_max_cookies;	/* dring max cookies */
3793af08d82Slm66018 	uint32_t		dring_cookie_count;	/* num cookies */
3803af08d82Slm66018 	uint32_t		dring_entry_size;	/* descriptor size */
3813af08d82Slm66018 	ldc_mem_cookie_t 	*dring_cookie;		/* dring cookies */
3823af08d82Slm66018 	uint64_t		dring_ident;		/* dring ident */
3831ae08745Sheppo 
3843af08d82Slm66018 	uint64_t		threads_pending; 	/* num of threads */
3851ae08745Sheppo 
3863af08d82Slm66018 	vdc_local_desc_t	*local_dring;		/* local dring */
3873af08d82Slm66018 	vdc_local_desc_t	*local_dring_backup;	/* local dring backup */
3883af08d82Slm66018 	int			local_dring_backup_tail; /* backup dring tail */
3893af08d82Slm66018 	int			local_dring_backup_len;	/* backup dring len */
3901ae08745Sheppo 
3918cd10891Snarayan 	int			num_servers;		/* no. of servers */
3928cd10891Snarayan 	vdc_server_t		*server_list;		/* vdisk server list */
3938cd10891Snarayan 	vdc_server_t		*curr_server;		/* curr vdisk server */
3941ae08745Sheppo } vdc_t;
3951ae08745Sheppo 
3961ae08745Sheppo /*
3972f5224aeSachartre  * Ownership status flags
3982f5224aeSachartre  */
3992f5224aeSachartre #define	VDC_OWNERSHIP_NONE	0x00 /* no ownership wanted */
4002f5224aeSachartre #define	VDC_OWNERSHIP_WANTED	0x01 /* ownership is wanted */
4012f5224aeSachartre #define	VDC_OWNERSHIP_GRANTED	0x02 /* ownership has been granted */
4022f5224aeSachartre #define	VDC_OWNERSHIP_RESET	0x04 /* ownership has been reset */
4032f5224aeSachartre 
4042f5224aeSachartre /*
4052f5224aeSachartre  * Reservation conflict panic message
4062f5224aeSachartre  */
4072f5224aeSachartre #define	VDC_RESV_CONFLICT_FMT_STR	"Reservation Conflict\nDisk: "
4082f5224aeSachartre #define	VDC_RESV_CONFLICT_FMT_LEN 	(sizeof (VDC_RESV_CONFLICT_FMT_STR))
4092f5224aeSachartre 
4102f5224aeSachartre /*
4111ae08745Sheppo  * Debugging macros
4121ae08745Sheppo  */
4131ae08745Sheppo #ifdef DEBUG
4141ae08745Sheppo extern int	vdc_msglevel;
4153af08d82Slm66018 extern uint64_t	vdc_matchinst;
4161ae08745Sheppo 
4173af08d82Slm66018 #define	DMSG(_vdc, err_level, format, ...)				\
4183af08d82Slm66018 	do {								\
4193af08d82Slm66018 		if (vdc_msglevel > err_level &&				\
4203af08d82Slm66018 		(vdc_matchinst & (1ull << (_vdc)->instance)))		\
4213af08d82Slm66018 			cmn_err(CE_CONT, "?[%d,t@%p] %s: "format,	\
4223af08d82Slm66018 			(_vdc)->instance, (void *)curthread,		\
4233af08d82Slm66018 			__func__, __VA_ARGS__);				\
4243af08d82Slm66018 		_NOTE(CONSTANTCONDITION)				\
4253af08d82Slm66018 	} while (0);
4263af08d82Slm66018 
4273af08d82Slm66018 #define	DMSGX(err_level, format, ...)					\
428e1ebb9ecSlm66018 	do {								\
429e1ebb9ecSlm66018 		if (vdc_msglevel > err_level)				\
4303af08d82Slm66018 			cmn_err(CE_CONT, "?%s: "format, __func__, __VA_ARGS__);\
431e1ebb9ecSlm66018 		_NOTE(CONSTANTCONDITION)				\
432e1ebb9ecSlm66018 	} while (0);
4331ae08745Sheppo 
4341ae08745Sheppo #define	VDC_DUMP_DRING_MSG(dmsgp)					\
4353af08d82Slm66018 		DMSGX(0, "sq:%lu start:%d end:%d ident:%lu\n",		\
4361ae08745Sheppo 			dmsgp->seq_num, dmsgp->start_idx,		\
4371ae08745Sheppo 			dmsgp->end_idx, dmsgp->dring_ident);
4381ae08745Sheppo 
4391ae08745Sheppo #else	/* !DEBUG */
440e1ebb9ecSlm66018 #define	DMSG(err_level, ...)
4413af08d82Slm66018 #define	DMSGX(err_level, format, ...)
4421ae08745Sheppo #define	VDC_DUMP_DRING_MSG(dmsgp)
4431ae08745Sheppo 
4441ae08745Sheppo #endif	/* !DEBUG */
4451ae08745Sheppo 
4461ae08745Sheppo #ifdef	__cplusplus
4471ae08745Sheppo }
4481ae08745Sheppo #endif
4491ae08745Sheppo 
4501ae08745Sheppo #endif	/* _VDC_H */
451