Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 17 | * |
| 18 | * Authors: |
| 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 20 | * Hank Janssen <hjanssen@microsoft.com> |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #pragma once |
| 26 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 27 | /* #include <vmbuspacketformat.h> */ |
| 28 | /* #include <ntddscsi.h> */ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 29 | |
| 30 | #define C_ASSERT(x) |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 31 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 32 | /* public interface to the server */ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 33 | |
| 34 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 35 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 36 | /* Storvsp device interface guid */ |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | /* Protocol versions. */ |
| 42 | |
| 43 | |
| 44 | |
| 45 | /* vstorage.w revision number. This is used in the case of a version match, */ |
| 46 | /* to alert the user that structure sizes may be mismatched even though the */ |
| 47 | /* protocol versions match. */ |
| 48 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 49 | |
| 50 | #define REVISION_STRING(REVISION_) #REVISION_ |
| 51 | #define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \ |
| 52 | { \ |
| 53 | char *revisionString = REVISION_STRING($Revision: 6 $) + 11; \ |
| 54 | RESULT_LVALUE_ = 0; \ |
| 55 | while (*revisionString >= '0' && *revisionString <= '9') \ |
| 56 | { \ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 57 | RESULT_LVALUE_ *= 10; \ |
| 58 | RESULT_LVALUE_ += *revisionString - '0'; \ |
| 59 | revisionString++; \ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 60 | } \ |
| 61 | } |
| 62 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 63 | |
| 64 | /* Major/minor macros. Minor version is in LSB, meaning that earlier flat */ |
| 65 | /* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */ |
| 66 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 67 | |
| 68 | #define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff) |
| 69 | #define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff) |
| 70 | #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 71 | (((MINOR_) & 0xff) )) |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 72 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 73 | |
| 74 | /* Invalid version. */ |
| 75 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 76 | |
| 77 | #define VMSTOR_INVALID_PROTOCOL_VERSION -1 |
| 78 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 79 | |
| 80 | /* Version history: */ |
| 81 | /* V1 Beta 0.1 */ |
| 82 | /* V1 RC < 2008/1/31 1.0 */ |
| 83 | /* V1 RC > 2008/1/31 2.0 */ |
| 84 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 85 | #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0) |
| 86 | |
| 87 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 88 | |
| 89 | /* This will get replaced with the max transfer length that is possible on */ |
| 90 | /* the host adapter. */ |
| 91 | /* The max transfer length will be published when we offer a vmbus channel. */ |
| 92 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 93 | |
| 94 | #define MAX_TRANSFER_LENGTH 0x40000 |
| 95 | #define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 96 | sizeof(VSTOR_PACKET) + \ |
| 97 | (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE))) |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 98 | |
| 99 | |
| 100 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 101 | |
| 102 | /* Packet structure describing virtual storage requests. */ |
| 103 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 104 | |
| 105 | typedef enum |
| 106 | { |
| 107 | VStorOperationCompleteIo = 1, |
| 108 | VStorOperationRemoveDevice = 2, |
| 109 | VStorOperationExecuteSRB = 3, |
| 110 | VStorOperationResetLun = 4, |
| 111 | VStorOperationResetAdapter = 5, |
| 112 | VStorOperationResetBus = 6, |
| 113 | VStorOperationBeginInitialization = 7, |
| 114 | VStorOperationEndInitialization = 8, |
| 115 | VStorOperationQueryProtocolVersion = 9, |
| 116 | VStorOperationQueryProperties = 10, |
| 117 | VStorOperationMaximum = 10 |
| 118 | |
| 119 | } VSTOR_PACKET_OPERATION; |
| 120 | |
| 121 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 122 | |
| 123 | /* Platform neutral description of a scsi request - */ |
| 124 | /* this remains the same across the write regardless of 32/64 bit */ |
| 125 | /* note: it's patterned off the SCSI_PASS_THROUGH structure */ |
| 126 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 127 | |
| 128 | |
| 129 | #pragma pack(push,1) |
| 130 | |
| 131 | |
| 132 | #define CDB16GENERIC_LENGTH 0x10 |
| 133 | |
| 134 | #ifndef SENSE_BUFFER_SIZE |
| 135 | #define SENSE_BUFFER_SIZE 0x12 |
| 136 | #endif |
| 137 | C_ASSERT(SENSE_BUFFER_SIZE == 0x12); |
| 138 | |
| 139 | #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 |
| 140 | |
| 141 | |
| 142 | typedef struct |
| 143 | { |
Greg Kroah-Hartman | 2be8093 | 2009-07-14 15:11:03 -0700 | [diff] [blame] | 144 | unsigned short Length; |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 145 | unsigned char SrbStatus; |
| 146 | unsigned char ScsiStatus; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 147 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 148 | unsigned char PortNumber; |
| 149 | unsigned char PathId; |
| 150 | unsigned char TargetId; |
| 151 | unsigned char Lun; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 152 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 153 | unsigned char CdbLength; |
| 154 | unsigned char SenseInfoLength; |
| 155 | unsigned char DataIn; |
| 156 | unsigned char Reserved; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 157 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 158 | unsigned int DataTransferLength; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 159 | |
| 160 | union |
| 161 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 162 | unsigned char Cdb[CDB16GENERIC_LENGTH]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 163 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 164 | unsigned char SenseData[SENSE_BUFFER_SIZE]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 165 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 166 | unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | } VMSCSI_REQUEST, *PVMSCSI_REQUEST; |
| 170 | |
| 171 | C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) == 0); |
| 172 | |
| 173 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 174 | |
| 175 | /* This structure is sent during the intialization phase to get the different */ |
| 176 | /* properties of the channel. */ |
| 177 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 178 | |
| 179 | typedef struct |
| 180 | { |
Greg Kroah-Hartman | 2be8093 | 2009-07-14 15:11:03 -0700 | [diff] [blame] | 181 | unsigned short ProtocolVersion; |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 182 | unsigned char PathId; |
| 183 | unsigned char TargetId; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 184 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 185 | |
| 186 | /* Note: port number is only really known on the client side */ |
| 187 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 188 | unsigned int PortNumber; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 189 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 190 | unsigned int Flags; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 191 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 192 | unsigned int MaxTransferBytes; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 193 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 194 | |
| 195 | /* This id is unique for each channel and will correspond with */ |
| 196 | /* vendor specific data in the inquirydata */ |
| 197 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 198 | |
Greg Kroah-Hartman | b509bf5 | 2009-07-14 15:11:45 -0700 | [diff] [blame] | 199 | unsigned long long UniqueId; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 200 | |
| 201 | } VMSTORAGE_CHANNEL_PROPERTIES, *PVMSTORAGE_CHANNEL_PROPERTIES; |
| 202 | |
| 203 | C_ASSERT((sizeof(VMSTORAGE_CHANNEL_PROPERTIES) % 4) == 0); |
| 204 | |
| 205 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 206 | |
| 207 | /* This structure is sent during the storage protocol negotiations. */ |
| 208 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 209 | |
| 210 | typedef struct |
| 211 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 212 | |
| 213 | /* Major (MSW) and minor (LSW) version numbers. */ |
| 214 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 215 | |
Greg Kroah-Hartman | 2be8093 | 2009-07-14 15:11:03 -0700 | [diff] [blame] | 216 | unsigned short MajorMinor; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 217 | |
| 218 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 219 | |
| 220 | /* Revision number is auto-incremented whenever this file is changed */ |
| 221 | /* (See FILL_VMSTOR_REVISION macro above). Mismatch does not definitely */ |
| 222 | /* indicate incompatibility--but it does indicate mismatched builds. */ |
| 223 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 224 | |
Greg Kroah-Hartman | 2be8093 | 2009-07-14 15:11:03 -0700 | [diff] [blame] | 225 | unsigned short Revision; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 226 | |
| 227 | } VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION; |
| 228 | |
| 229 | C_ASSERT((sizeof(VMSTORAGE_PROTOCOL_VERSION) % 4) == 0); |
| 230 | |
| 231 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 232 | |
| 233 | /* Channel Property Flags */ |
| 234 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 235 | |
| 236 | #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 |
| 237 | #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 |
| 238 | |
| 239 | |
| 240 | typedef struct _VSTOR_PACKET |
| 241 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 242 | |
| 243 | /* Requested operation type */ |
| 244 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 245 | |
| 246 | VSTOR_PACKET_OPERATION Operation; |
| 247 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 248 | |
| 249 | /* Flags - see below for values */ |
| 250 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 251 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 252 | unsigned int Flags; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 253 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 254 | |
| 255 | /* Status of the request returned from the server side. */ |
| 256 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 257 | |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 258 | unsigned int Status; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 259 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 260 | |
| 261 | /* Data payload area */ |
| 262 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 263 | |
| 264 | union |
| 265 | { |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 266 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 267 | /* Structure used to forward SCSI commands from the client to the server. */ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 268 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 269 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 270 | VMSCSI_REQUEST VmSrb; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 271 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 272 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 273 | /* Structure used to query channel properties. */ |
| 274 | |
| 275 | |
| 276 | VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties; |
| 277 | |
| 278 | |
| 279 | /* Used during version negotiations. */ |
| 280 | |
| 281 | |
| 282 | VMSTORAGE_PROTOCOL_VERSION Version; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | } VSTOR_PACKET, *PVSTOR_PACKET; |
| 286 | |
| 287 | C_ASSERT((sizeof(VSTOR_PACKET) % 4) == 0); |
| 288 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 289 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 290 | /* Packet flags */ |
| 291 | |
| 292 | |
| 293 | |
| 294 | /* This flag indicates that the server should send back a completion for this */ |
| 295 | /* packet. */ |
| 296 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 297 | |
| 298 | #define REQUEST_COMPLETION_FLAG 0x1 |
| 299 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame^] | 300 | |
| 301 | /* This is the set of flags that the vsc can set in any packets it sends */ |
| 302 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 303 | |
| 304 | #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) |
| 305 | |
| 306 | |
| 307 | #pragma pack(pop) |