vdc.h revision 655fd6a9f385606a30bca083569a79e9a6b6c181
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _VDC_H
#define _VDC_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Virtual disk client implementation definitions
*/
#include <sys/sysmacros.h>
#include <sys/vio_mailbox.h>
#include <sys/vdsk_mailbox.h>
#include <sys/vdsk_common.h>
#ifdef __cplusplus
extern "C" {
#endif
#define VDC_DRIVER_NAME "vdc"
/*
* Bit-field values to indicate if parts of the vdc driver are initialised.
*/
#define VDC_SOFT_STATE 0x0001
#define VDC_LOCKS 0x0002
#define VDC_MINOR 0x0004
#define VDC_THREAD 0x0008
#define VDC_LDC 0x0010
#define VDC_LDC_INIT 0x0020
#define VDC_LDC_CB 0x0040
#define VDC_LDC_OPEN 0x0080
/*
* Definitions of strings to be used to create device node properties.
* (vdc uses the capitalised versions of these properties as they are 64-bit)
*/
#define VDC_NBLOCKS_PROP_NAME "Nblocks"
#define VDC_SIZE_PROP_NAME "Size"
/*
* Definitions of MD nodes/properties.
*/
#define VDC_MD_CHAN_NAME "channel-endpoint"
#define VDC_MD_VDEV_NAME "virtual-device"
#define VDC_MD_PORT_NAME "virtual-device-port"
#define VDC_MD_DISK_NAME "disk"
#define VDC_MD_CFG_HDL "cfg-handle"
#define VDC_MD_TIMEOUT "vdc-timeout"
#define VDC_MD_ID "id"
/*
* Definition of actions to be carried out when processing the sequence ID
* of a message received from the vDisk server. The function verifying the
* sequence number checks the 'seq_num_xxx' fields in the soft state and
* returns whether the message should be processed (VDC_SEQ_NUM_TODO) or
* whether it was it was previously processed (VDC_SEQ_NUM_SKIP).
*/
#define VDC_SEQ_NUM_SKIP 0 /* Request already processed */
/*
* Macros to get UNIT and PART number
*/
#define VDCUNIT_SHIFT 3
#define VDCPART_MASK 7
/*
* Scheme to store the instance number and the slice number in the minor number.
* (NOTE: Uses the same format and definitions as the sd(7D) driver)
*/
/*
* variables controlling how long to wait before timing out and how many
* retries to attempt before giving up when communicating with vds.
*
* These values need to be sufficiently large so that a guest can survive
* the reboot of the service domain.
*/
#define VDC_RETRIES 10
/*
* This macro returns the number of Hz that the vdc driver should wait before
* a timeout is triggered. The 'timeout' parameter specifiecs the wait
* time in Hz. The 'mul' parameter allows for a multiplier to be
* specified allowing for a backoff to be implemented (e.g. using the
* retry number as a multiplier) where the wait time will get longer if
* there is no response on the previous retry.
*/
/*
* Macros to manipulate Descriptor Ring variables in the soft state
* structure.
*/
{ \
}
/* Initialise the Session ID and Sequence Num in the DRing msg */
/*
* The states that the read thread can be in.
*/
typedef enum vdc_rd_state {
VDC_READ_IDLE, /* idling - conn is not up */
VDC_READ_WAITING, /* waiting for data */
VDC_READ_PENDING, /* pending data avail for read */
VDC_READ_RESET /* channel was reset - stop reads */
/*
* The states that the vdc-vds connection can be in.
*/
typedef enum vdc_state {
VDC_STATE_INIT, /* device is initialized */
VDC_STATE_INIT_WAITING, /* waiting for ldc connection */
VDC_STATE_NEGOTIATE, /* doing handshake negotiation */
VDC_STATE_HANDLE_PENDING, /* handle requests in backup dring */
VDC_STATE_RUNNING, /* running and accepting requests */
VDC_STATE_DETACH, /* detaching */
VDC_STATE_RESETTING /* resetting connection with vds */
} vdc_state_t;
/*
* The states that the vdc instance can be in.
*/
typedef enum vdc_lc_state {
VDC_LC_ATTACHING, /* driver is attaching */
VDC_LC_ONLINE, /* driver is attached and online */
VDC_LC_DETACHING /* driver is detaching */
/*
* Local Descriptor Ring entry
*
* vdc creates a Local (private) descriptor ring the same size as the
* public descriptor ring it exports to vds.
*/
typedef enum {
VIO_read_dir, /* read data from server */
VIO_write_dir, /* write data to server */
VIO_both_dir /* transfer both in and out in same buffer */
typedef enum {
CB_STRATEGY, /* non-blocking strategy call */
CB_SYNC /* synchronous operation */
typedef struct vdc_local_desc {
int operation; /* VD_OP_xxx to be performed */
int slice;
void *cb_arg; /* buf passed to strategy() */
/*
* vdc soft state structure
*/
typedef struct vdc {
int initialized; /* keeps track of what's init'ed */
int hshake_cnt; /* number of failed handshakes */
int open_count; /* count of outstanding opens */
int dkio_flush_pending; /* # outstanding DKIO flushes */
int instance; /* driver instance number */
int local_dring_backup_tail; /* backup dring tail */
int local_dring_backup_len; /* backup dring len */
} vdc_t;
/*
* Debugging macros
*/
#ifdef DEBUG
extern int vdc_msglevel;
extern uint64_t vdc_matchinst;
do { \
if (vdc_msglevel > err_level && \
__func__, __VA_ARGS__); \
} while (0);
do { \
if (vdc_msglevel > err_level) \
} while (0);
#define VDC_DUMP_DRING_MSG(dmsgp) \
DMSGX(0, "sq:%lu start:%d end:%d ident:%lu\n", \
#else /* !DEBUG */
#define VDC_DUMP_DRING_MSG(dmsgp)
#endif /* !DEBUG */
#ifdef __cplusplus
}
#endif
#endif /* _VDC_H */