hv_vstorage.h revision 250199
1/*- 2 * Copyright (c) 2009-2012 Microsoft Corp. 3 * Copyright (c) 2012 NetApp Inc. 4 * Copyright (c) 2012 Citrix Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice unmodified, this list of conditions, and the following 12 * disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef __HV_VSTORAGE_H__ 30#define __HV_VSTORAGE_H__ 31 32/* 33 * Major/minor macros. Minor version is in LSB, meaning that earlier flat 34 * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). 35 */ 36 37#define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff) 38#define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff) 39#define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \ 40 (((MINOR_) & 0xff) )) 41 42/* 43 * Invalid version. 44 */ 45#define VMSTOR_INVALID_PROTOCOL_VERSION -1 46 47/* 48 * Version history: 49 * V1 Beta 0.1 50 * V1 RC < 2008/1/31 1.0 51 * V1 RC > 2008/1/31 2.0 52 */ 53 54#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0) 55 56/** 57 * Packet structure ops describing virtual storage requests. 58 */ 59enum vstor_packet_ops { 60 VSTOR_OPERATION_COMPLETEIO = 1, 61 VSTOR_OPERATION_REMOVEDEVICE = 2, 62 VSTOR_OPERATION_EXECUTESRB = 3, 63 VSTOR_OPERATION_RESETLUN = 4, 64 VSTOR_OPERATION_RESETADAPTER = 5, 65 VSTOR_OPERATION_RESETBUS = 6, 66 VSTOR_OPERATION_BEGININITIALIZATION = 7, 67 VSTOR_OPERATION_ENDINITIALIZATION = 8, 68 VSTOR_OPERATION_QUERYPROTOCOLVERSION = 9, 69 VSTOR_OPERATION_QUERYPROPERTIES = 10, 70 VSTOR_OPERATION_MAXIMUM = 10 71}; 72 73 74/* 75 * Platform neutral description of a scsi request - 76 * this remains the same across the write regardless of 32/64 bit 77 * note: it's patterned off the Windows DDK SCSI_PASS_THROUGH structure 78 */ 79 80#define CDB16GENERIC_LENGTH 0x10 81#define SENSE_BUFFER_SIZE 0x12 82#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 83 84struct vmscsi_req { 85 uint16_t length; 86 uint8_t srb_status; 87 uint8_t scsi_status; 88 89 /* HBA number, set to the order number detected by initiator. */ 90 uint8_t port; 91 /* SCSI bus number or bus_id, different from CAM's path_id. */ 92 uint8_t path_id; 93 94 uint8_t target_id; 95 uint8_t lun; 96 97 uint8_t cdb_len; 98 uint8_t sense_info_len; 99 uint8_t data_in; 100 uint8_t reserved; 101 102 uint32_t transfer_len; 103 104 union { 105 uint8_t cdb[CDB16GENERIC_LENGTH]; 106 107 uint8_t sense_data[SENSE_BUFFER_SIZE]; 108 109 uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; 110 }; 111 112} __packed; 113 114/** 115 * This structure is sent during the initialization phase to get the different 116 * properties of the channel. 117 */ 118 119struct vmstor_chan_props { 120 uint16_t proto_ver; 121 uint8_t path_id; 122 uint8_t target_id; 123 124 /** 125 * Note: port number is only really known on the client side 126 */ 127 uint32_t port; 128 uint32_t flags; 129 uint32_t max_transfer_bytes; 130 131 /** 132 * This id is unique for each channel and will correspond with 133 * vendor specific data in the inquiry_ata 134 */ 135 uint64_t unique_id; 136 137} __packed; 138 139/** 140 * This structure is sent during the storage protocol negotiations. 141 */ 142 143struct vmstor_proto_ver 144{ 145 /** 146 * Major (MSW) and minor (LSW) version numbers. 147 */ 148 uint16_t major_minor; 149 150 uint16_t revision; /* always zero */ 151} __packed; 152 153/** 154 * Channel Property Flags 155 */ 156 157#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 158#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 159 160 161struct vstor_packet { 162 /** 163 * Requested operation type 164 */ 165 enum vstor_packet_ops operation; 166 167 /* 168 * Flags - see below for values 169 */ 170 uint32_t flags; 171 172 /** 173 * Status of the request returned from the server side. 174 */ 175 uint32_t status; 176 177 union 178 { 179 /** 180 * Structure used to forward SCSI commands from the client to 181 * the server. 182 */ 183 struct vmscsi_req vm_srb; 184 185 /** 186 * Structure used to query channel properties. 187 */ 188 struct vmstor_chan_props chan_props; 189 190 /** 191 * Used during version negotiations. 192 */ 193 struct vmstor_proto_ver version; 194 }; 195 196} __packed; 197 198 199/** 200 * SRB (SCSI Request Block) Status Codes 201 */ 202#define SRB_STATUS_PENDING 0x00 203#define SRB_STATUS_SUCCESS 0x01 204#define SRB_STATUS_ABORTED 0x02 205#define SRB_STATUS_ABORT_FAILED 0x03 206#define SRB_STATUS_ERROR 0x04 207#define SRB_STATUS_BUSY 0x05 208 209/** 210 * SRB Status Masks (can be combined with above status codes) 211 */ 212#define SRB_STATUS_QUEUE_FROZEN 0x40 213#define SRB_STATUS_AUTOSENSE_VALID 0x80 214 215 216/** 217 * Packet flags 218 */ 219 220/** 221 * This flag indicates that the server should send back a completion for this 222 * packet. 223 */ 224#define REQUEST_COMPLETION_FLAG 0x1 225 226/** 227 * This is the set of flags that the vsc can set in any packets it sends 228 */ 229#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) 230 231#endif /* __HV_VSTORAGE_H__ */ 232