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 * $FreeBSD$ 29 */ 30 31 #ifndef __HV_VSTORAGE_H__ 32 #define __HV_VSTORAGE_H__ 33 34 /* 35 * Major/minor macros. Minor version is in LSB, meaning that earlier flat 36 * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). 37 */ 38 39 #define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff) 40 #define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff) 41 #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \ 42 (((MINOR_) & 0xff) )) 43 44 /* 45 * Invalid version. 46 */ 47 #define VMSTOR_INVALID_PROTOCOL_VERSION -1 48 49 /* 50 * Version history: 51 * V1 Beta 0.1 52 * V1 RC < 2008/1/31 1.0 53 * V1 RC > 2008/1/31 2.0 54 */ 55 56 #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(5, 1) 57 58 /** 59 * Packet structure ops describing virtual storage requests. 60 */ 61 enum vstor_packet_ops { 62 VSTOR_OPERATION_COMPLETEIO = 1, 63 VSTOR_OPERATION_REMOVEDEVICE = 2, 64 VSTOR_OPERATION_EXECUTESRB = 3, 65 VSTOR_OPERATION_RESETLUN = 4, 66 VSTOR_OPERATION_RESETADAPTER = 5, 67 VSTOR_OPERATION_RESETBUS = 6, 68 VSTOR_OPERATION_BEGININITIALIZATION = 7, 69 VSTOR_OPERATION_ENDINITIALIZATION = 8, 70 VSTOR_OPERATION_QUERYPROTOCOLVERSION = 9, 71 VSTOR_OPERATION_QUERYPROPERTIES = 10, 72 VSTOR_OPERATION_ENUMERATE_BUS = 11, 73 VSTOR_OPERATION_FCHBA_DATA = 12, 74 VSTOR_OPERATION_CREATE_MULTI_CHANNELS = 13, 75 VSTOR_OPERATION_MAXIMUM = 13 76 }; 77 78 79 /* 80 * Platform neutral description of a scsi request - 81 * this remains the same across the write regardless of 32/64 bit 82 * note: it's patterned off the Windows DDK SCSI_PASS_THROUGH structure 83 */ 84 85 #define CDB16GENERIC_LENGTH 0x10 86 #define SENSE_BUFFER_SIZE 0x12 87 #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 88 89 struct vmscsi_req { 90 uint16_t length; 91 uint8_t srb_status; 92 uint8_t scsi_status; 93 94 /* HBA number, set to the order number detected by initiator. */ 95 uint8_t port; 96 /* SCSI bus number or bus_id, different from CAM's path_id. */ 97 uint8_t path_id; 98 99 uint8_t target_id; 100 uint8_t lun; 101 102 uint8_t cdb_len; 103 uint8_t sense_info_len; 104 uint8_t data_in; 105 uint8_t reserved; 106 107 uint32_t transfer_len; 108 109 union { 110 uint8_t cdb[CDB16GENERIC_LENGTH]; 111 112 uint8_t sense_data[SENSE_BUFFER_SIZE]; 113 114 uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; 115 } u; 116 117 } __packed; 118 119 /** 120 * This structure is sent during the initialization phase to get the different 121 * properties of the channel. 122 */ 123 124 struct vmstor_chan_props { 125 uint16_t proto_ver; 126 uint8_t path_id; 127 uint8_t target_id; 128 129 uint16_t max_channel_cnt; 130 131 /** 132 * Note: port number is only really known on the client side 133 */ 134 uint16_t port; 135 uint32_t flags; 136 uint32_t max_transfer_bytes; 137 138 /** 139 * This id is unique for each channel and will correspond with 140 * vendor specific data in the inquiry_ata 141 */ 142 uint64_t unique_id; 143 144 } __packed; 145 146 /** 147 * This structure is sent during the storage protocol negotiations. 148 */ 149 150 struct vmstor_proto_ver 151 { 152 /** 153 * Major (MSW) and minor (LSW) version numbers. 154 */ 155 uint16_t major_minor; 156 157 uint16_t revision; /* always zero */ 158 } __packed; 159 160 /** 161 * Channel Property Flags 162 */ 163 164 #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 165 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 166 167 168 struct vstor_packet { 169 /** 170 * Requested operation type 171 */ 172 enum vstor_packet_ops operation; 173 174 /* 175 * Flags - see below for values 176 */ 177 uint32_t flags; 178 179 /** 180 * Status of the request returned from the server side. 181 */ 182 uint32_t status; 183 184 union 185 { 186 /** 187 * Structure used to forward SCSI commands from the client to 188 * the server. 189 */ 190 struct vmscsi_req vm_srb; 191 192 /** 193 * Structure used to query channel properties. 194 */ 195 struct vmstor_chan_props chan_props; 196 197 /** 198 * Used during version negotiations. 199 */ 200 struct vmstor_proto_ver version; 201 202 /** 203 * Number of multichannels to create 204 */ 205 uint16_t multi_channels_cnt; 206 } u; 207 208 } __packed; 209 210 211 /** 212 * SRB (SCSI Request Block) Status Codes 213 */ 214 #define SRB_STATUS_PENDING 0x00 215 #define SRB_STATUS_SUCCESS 0x01 216 #define SRB_STATUS_ABORTED 0x02 217 #define SRB_STATUS_ABORT_FAILED 0x03 218 #define SRB_STATUS_ERROR 0x04 219 #define SRB_STATUS_BUSY 0x05 220 221 /** 222 * SRB Status Masks (can be combined with above status codes) 223 */ 224 #define SRB_STATUS_QUEUE_FROZEN 0x40 225 #define SRB_STATUS_AUTOSENSE_VALID 0x80 226 227 228 /** 229 * Packet flags 230 */ 231 232 /** 233 * This flag indicates that the server should send back a completion for this 234 * packet. 235 */ 236 #define REQUEST_COMPLETION_FLAG 0x1 237 238 /** 239 * This is the set of flags that the vsc can set in any packets it sends 240 */ 241 #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) 242 243 #endif /* __HV_VSTORAGE_H__ */ 244