blob: 3ab98616723f59ea62302563737f1b225d9b4ff1 [file] [log] [blame]
Hank Janssen565e7dc2009-07-13 15:15:47 -07001/*
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
27//#include <vmbuspacketformat.h>
28//#include <ntddscsi.h>
29
30#define C_ASSERT(x)
31//
32// public interface to the server
33//
34
35//
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//
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 { \
57 RESULT_LVALUE_ *= 10; \
58 RESULT_LVALUE_ += *revisionString - '0'; \
59 revisionString++; \
60 } \
61}
62
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//
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) | \
71 (((MINOR_) & 0xff) ))
72
73//
74// Invalid version.
75//
76
77#define VMSTOR_INVALID_PROTOCOL_VERSION -1
78
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//
85#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
86
87
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//
93
94#define MAX_TRANSFER_LENGTH 0x40000
95#define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \
96 sizeof(VSTOR_PACKET) + \
97 (sizeof(UINT64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
98
99
100
101//
102// Packet structure describing virtual storage requests.
103//
104
105typedef 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
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//
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
137C_ASSERT(SENSE_BUFFER_SIZE == 0x12);
138
139#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
140
141
142typedef struct
143{
144 USHORT Length;
145 UCHAR SrbStatus;
146 UCHAR ScsiStatus;
147
148 UCHAR PortNumber;
149 UCHAR PathId;
150 UCHAR TargetId;
151 UCHAR Lun;
152
153 UCHAR CdbLength;
154 UCHAR SenseInfoLength;
155 UCHAR DataIn;
156 UCHAR Reserved;
157
158 ULONG DataTransferLength;
159
160 union
161 {
162 UCHAR Cdb[CDB16GENERIC_LENGTH];
163
164 UCHAR SenseData[SENSE_BUFFER_SIZE];
165
166 UCHAR ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
167 };
168
169} VMSCSI_REQUEST, *PVMSCSI_REQUEST;
170
171C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) == 0);
172
173
174//
175// This structure is sent during the intialization phase to get the different
176// properties of the channel.
177//
178
179typedef struct
180{
181 USHORT ProtocolVersion;
182 UCHAR PathId;
183 UCHAR TargetId;
184
185 //
186 // Note: port number is only really known on the client side
187 //
188 ULONG PortNumber;
189
190 ULONG Flags;
191
192 ULONG MaxTransferBytes;
193
194 //
195 // This id is unique for each channel and will correspond with
196 // vendor specific data in the inquirydata
197 //
198
199 ULONGLONG UniqueId;
200
201} VMSTORAGE_CHANNEL_PROPERTIES, *PVMSTORAGE_CHANNEL_PROPERTIES;
202
203C_ASSERT((sizeof(VMSTORAGE_CHANNEL_PROPERTIES) % 4) == 0);
204
205
206//
207// This structure is sent during the storage protocol negotiations.
208//
209
210typedef struct
211{
212 //
213 // Major (MSW) and minor (LSW) version numbers.
214 //
215
216 USHORT MajorMinor;
217
218
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 //
224
225 USHORT Revision;
226
227} VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION;
228
229C_ASSERT((sizeof(VMSTORAGE_PROTOCOL_VERSION) % 4) == 0);
230
231
232//
233// Channel Property Flags
234//
235
236#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
237#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
238
239
240typedef struct _VSTOR_PACKET
241{
242 //
243 // Requested operation type
244 //
245
246 VSTOR_PACKET_OPERATION Operation;
247
248 //
249 // Flags - see below for values
250 //
251
252 ULONG Flags;
253
254 //
255 // Status of the request returned from the server side.
256 //
257
258 ULONG Status;
259
260 //
261 // Data payload area
262 //
263
264 union
265 {
266 //
267 // Structure used to forward SCSI commands from the client to the server.
268 //
269
270 VMSCSI_REQUEST VmSrb;
271
272 //
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;
283 };
284
285} VSTOR_PACKET, *PVSTOR_PACKET;
286
287C_ASSERT((sizeof(VSTOR_PACKET) % 4) == 0);
288
289//
290// Packet flags
291//
292
293//
294// This flag indicates that the server should send back a completion for this
295// packet.
296//
297
298#define REQUEST_COMPLETION_FLAG 0x1
299
300//
301// This is the set of flags that the vsc can set in any packets it sends
302//
303
304#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
305
306
307#pragma pack(pop)
308
309