1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
ca6d128098b8e877673c13a3db1a0d3417ce5879Alexandre Chartre * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoextern "C" {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * This header file contains the private LDoms Virtual Disk (vDisk) definitions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * common to both the server (vds) and the client (vdc)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vDisk definitions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The number of Descriptor Ring entries
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Constraints:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * - overall DRing size must be greater than 8K (MMU_PAGESIZE)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * - overall DRing size should be 8K aligned (desirable but not enforced)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * - DRing entry must be 8 byte aligned
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_DRING_ENTRY_SZ (sizeof (vd_dring_entry_t) + \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The maximum block size we can transmit using one Descriptor Ring entry
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Currently no FS uses more than 128K and it doesn't look like they
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * will either as there is no perf gain to be had by larger values.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * ( see ZFS comment at definition of SPA_MAXBLOCKSIZE ).
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * We choose 256K to give us some headroom.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_MAX_COOKIES ((VD_MAX_BLOCK_SIZE / PAGESIZE) + 1)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Flags used by ioctl routines to indicate if a copyin/copyout is needed
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vDisk operations on physical devices
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_OP_FLUSH 0x03 /* Flush disk write cache contents */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_OP_SET_WCE 0x05 /* Enable/Disable disk W$ */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_OP_GET_CAPACITY 0x11 /* Get disk capacity */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_OP_MASK 0xFF /* mask of all possible operations */
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Status for the VD_OP_GET_ACCESS operation
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_DENIED 0x00 /* access is not allowed */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_ALLOWED 0x01 /* access is allowed */
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Flags for the VD_OP_SET_ACCESS operation
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_SET_CLEAR 0x00 /* clear exclusive access rights */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_SET_EXCLUSIVE 0x01 /* set exclusive access rights */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_SET_PREEMPT 0x02 /* forcefully set access rights */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_ACCESS_SET_PRESERVE 0x04 /* preserve access rights */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * This is a mask of all the basic operations supported by all
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * disk types (v1.0).
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Mask for additional operations provided for SCSI disks (v1.1)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * macro to check if the operation 'op' is supported by checking the list
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * of operations supported which is exported by the vDisk server.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm#define VD_OP_SUPPORTED(ops_bitmask, op) ((ops_bitmask) & (1 << (op)))
87a7269eb068de448caa9e4404e38bebf4449531achartre * Slice for absolute disk transaction.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * EFI disks do not have a slice 7. Actually that slice is used to represent
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * the whole disk.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Definitions of the various ways vds can export disk support to vdc.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Definitions of the various disk label that vDisk supports.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vDisk Descriptor payload
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint8_t operation; /* operation for server to perform */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_mem_cookie_t cookie[1]; /* variable sized array */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vDisk Descriptor entry
edcc07547a39d6570197493a9836083bd6b2a197achartre * vDisk logical partition
edcc07547a39d6570197493a9836083bd6b2a197achartre daddr_t nblocks; /* number of blocks in the slice */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vDisk control operation structures
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * vDisk geometry definition (VD_OP_GET_DISKGEOM and VD_OP_SET_DISKGEOM)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm uint16_t write_reinstruct; /* # sectors to skip, writes */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * vDisk partition definition
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * vDisk VTOC definition (VD_OP_GET_VTOC and VD_OP_SET_VTOC)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm#define VD_VOLNAME_LEN 8 /* length of volume_name field */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm#define VD_ASCIILABEL_LEN 128 /* length of ascii_label field */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm vd_partition_t partition[V_NUMPAR]; /* partition headers */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * vDisk EFI definition (VD_OP_GET_EFI and VD_OP_SET_EFI)
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * vDisk DEVID definition (VD_OP_GET_DEVID)
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan#define VD_DEVID_SIZE(l) (sizeof (vd_devid_t) - 1 + l)
2f5224ae5d04383463098ad866ccee0464ee6429achartre * vDisk CAPACITY definition (VD_OP_GET_CAPACITY)
2f5224ae5d04383463098ad866ccee0464ee6429achartre uint32_t vdisk_block_size; /* block size in bytes */
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* Identifier for unknown disk size */
2f5224ae5d04383463098ad866ccee0464ee6429achartre * vDisk SCSI definition (VD_OP_SCSICMD)
2f5224ae5d04383463098ad866ccee0464ee6429achartre uint8_t cmd_status; /* command completion status */
2f5224ae5d04383463098ad866ccee0464ee6429achartre uint8_t sense_status; /* sense command completion status */
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* Minimum size of the vd_scsi structure */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_SCSI_SIZE (sizeof (vd_scsi_t) - sizeof (uint64_t))
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Macros to access data buffers in a vd_scsi structure. When using these
2f5224ae5d04383463098ad866ccee0464ee6429achartre * macros, the vd_scsi structure needs to be populated with the sizes of
2f5224ae5d04383463098ad866ccee0464ee6429achartre * data buffers allocated in the structure.
2f5224ae5d04383463098ad866ccee0464ee6429achartre ((struct scsi_extended_sense *)(uintptr_t)((vscsi)->data + \
2f5224ae5d04383463098ad866ccee0464ee6429achartre P2ROUNDUP((vscsi)->sense_len, sizeof (uint64_t)) + \
2f5224ae5d04383463098ad866ccee0464ee6429achartre P2ROUNDUP((vscsi)->datain_len, sizeof (uint64_t))))
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* vDisk SCSI task attribute */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_SCSI_TASK_ORDERED 0x02 /* ordered task */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_SCSI_TASK_HQUEUE 0x03 /* head of queue task */
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* vDisk SCSI options */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_SCSI_OPT_CRN 0x01 /* request has a CRN */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_SCSI_OPT_NORETRY 0x02 /* do not attempt any retry */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Copy the contents of a vd_geom_t to the contents of a dk_geom struct
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (dk_geom)->dkg_write_reinstruct = (vd_geom)->write_reinstruct; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (dk_geom)->dkg_read_reinstruct = (vd_geom)->read_reinstruct; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Copy the contents of a vd_vtoc_t to the contents of a vtoc struct
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vtoc)->v_part[i].p_tag = (vd_vtoc)->partition[i].id_tag; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vtoc)->v_part[i].p_flag = (vd_vtoc)->partition[i].perm; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vtoc)->v_part[i].p_start = (vd_vtoc)->partition[i].start; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vtoc)->v_part[i].p_size = (vd_vtoc)->partition[i].nblocks; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Copy the contents of a dk_geom struct to the contents of a vd_geom_t
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_geom)->write_reinstruct = (dk_geom)->dkg_write_reinstruct; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_geom)->read_reinstruct = (dk_geom)->dkg_read_reinstruct; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Copy the contents of a vtoc struct to the contents of a vd_vtoc_t
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_vtoc)->partition[i].id_tag = (vtoc)->v_part[i].p_tag; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_vtoc)->partition[i].perm = (vtoc)->v_part[i].p_flag; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_vtoc)->partition[i].start = (vtoc)->v_part[i].p_start; \
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm (vd_vtoc)->partition[i].nblocks = (vtoc)->v_part[i].p_size; \
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Copy the contents of a vd_efi_t to the contents of a dk_efi_t.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Note that (dk_efi)->dki_data and (vd_efi)->data should be correctly
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * initialized prior to using this macro.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bcopy((vd_efi)->data, (dk_efi)->dki_data, (dk_efi)->dki_length); \
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Copy the contents of dk_efi_t to the contents of vd_efi_t.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Note that (dk_efi)->dki_data and (vd_efi)->data should be correctly
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * initialized prior to using this macro.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bcopy((dk_efi)->dki_data, (vd_efi)->data, (vd_efi)->length); \
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * If the media type returned by the DKIOCGMEDIAINFO ioctl is greater than
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * 0xFFFF then this is not an optical media and we consider that this is
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * a fixed media.
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * Otherwise, we have an optical media. If this is a SCSI media then the media
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * type is actually the profile number returned by the SCSI GET CONFIGURATION
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * command. In that case, the possible values we can have are described in the
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * SCSI Multi-Media Commands (MMC) documentation.
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * Not all SCSI optical media profile numbers are defined in Solaris. However
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * undefined profiles are essentially different variants of DVD (like Blu-Ray
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * or HD-DVD). So we consider that any optical media that we can not explicitly
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre * identify is a DVD.
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre (((mt) > DK_MEDIA_OPTICAL_MAX)? VD_MEDIA_FIXED : \
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre (mt) == DK_REMOVABLE_DISK ? VD_MEDIA_FIXED : \
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * Hooks for EFI support
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * The EFI alloc_and_read() function will use some ioctls to get EFI data
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * but the device reference we will use is different depending if the command
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * is issued from the vDisk server side (vds) or from the vDisk client side
edcc07547a39d6570197493a9836083bd6b2a197achartre * (vdc). The vd_efi_dev structure is filled by vdc/vds to indicate the ioctl
edcc07547a39d6570197493a9836083bd6b2a197achartre * function to call back and to provide information about the virtual disk.
edcc07547a39d6570197493a9836083bd6b2a197achartretypedef int (*vd_efi_ioctl_func)(void *, int, uintptr_t);
edcc07547a39d6570197493a9836083bd6b2a197achartre vd_efi_ioctl_func vdisk_ioctl; /* vdisk ioctl function */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VDSK_EFI_DEV_SET(efi_dev, vdsk, ioctl, bsize, dsize) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (efi_dev).vdisk = vdsk; \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (efi_dev).vdisk_ioctl = ioctl; \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (efi_dev).block_size = bsize; \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (efi_dev).disk_size = dsize;
edcc07547a39d6570197493a9836083bd6b2a197achartreint vd_efi_alloc_and_read(vd_efi_dev_t *dev, efi_gpt_t **gpt, efi_gpe_t **gpe);
edcc07547a39d6570197493a9836083bd6b2a197achartrevoid vd_efi_free(vd_efi_dev_t *dev, efi_gpt_t *gpt, efi_gpe_t *gpe);
366a92acff1608754cee271ee6b74357c2891fdflm * Macros to update the I/O statistics kstat consumed by iostat(1m).
366a92acff1608754cee271ee6b74357c2891fdflm * Given a pointer to the instance private data of a vDisk driver (vd),
366a92acff1608754cee271ee6b74357c2891fdflm * the type of operation and the number of bytes read/written, this macro
366a92acff1608754cee271ee6b74357c2891fdflm * updates the I/O statistics in the kstat.
366a92acff1608754cee271ee6b74357c2891fdflm ASSERT(((op) == VD_OP_BREAD) || ((op) == VD_OP_BWRITE));\
366a92acff1608754cee271ee6b74357c2891fdflm } else { \
366a92acff1608754cee271ee6b74357c2891fdflm * These wrapper macros take a pointer to the I/O statistics kstat and
366a92acff1608754cee271ee6b74357c2891fdflm * update the queue length statistics. These are 'safe' wrappers which
366a92acff1608754cee271ee6b74357c2891fdflm * check to see if the kstat was created when the vDisk instance was
366a92acff1608754cee271ee6b74357c2891fdflm * added (i.e. is not NULL).
ca6d128098b8e877673c13a3db1a0d3417ce5879Alexandre Chartre kstat_runq_back_to_waitq(KSTAT_IO_PTR((vd)->io_stats)); \
366a92acff1608754cee271ee6b74357c2891fdflm * Given a pointer to the instance private data of a vDisk driver (vd) and
366a92acff1608754cee271ee6b74357c2891fdflm * the name of the error stats entry we wish to update, increment that value
366a92acff1608754cee271ee6b74357c2891fdflm/* Structure to record vDisk error statistics */
366a92acff1608754cee271ee6b74357c2891fdflm struct kstat_named vd_capacity; /* Capacity of the disk */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* _VDSK_COMMON_H */