blob: 33646e76da7ce18d15b35d1919e5b0c2049c23c8 [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
Bill Pemberton454f18a2009-07-27 16:47:24 -040027/* #include <vmbuspacketformat.h> */
28/* #include <ntddscsi.h> */
Hank Janssen565e7dc2009-07-13 15:15:47 -070029
30#define C_ASSERT(x)
Hank Janssen565e7dc2009-07-13 15:15:47 -070031
Bill Pemberton454f18a2009-07-27 16:47:24 -040032/* public interface to the server */
Hank Janssen565e7dc2009-07-13 15:15:47 -070033
34
Hank Janssen565e7dc2009-07-13 15:15:47 -070035
Bill Pemberton454f18a2009-07-27 16:47:24 -040036/* 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 Janssen565e7dc2009-07-13 15:15:47 -070049
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 Pemberton454f18a2009-07-27 16:47:24 -040057 RESULT_LVALUE_ *= 10; \
58 RESULT_LVALUE_ += *revisionString - '0'; \
59 revisionString++; \
Hank Janssen565e7dc2009-07-13 15:15:47 -070060 } \
61}
62
Bill Pemberton454f18a2009-07-27 16:47:24 -040063
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 Janssen565e7dc2009-07-13 15:15:47 -070067
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 Pemberton454f18a2009-07-27 16:47:24 -040071 (((MINOR_) & 0xff) ))
Hank Janssen565e7dc2009-07-13 15:15:47 -070072
Bill Pemberton454f18a2009-07-27 16:47:24 -040073
74/* Invalid version. */
75
Hank Janssen565e7dc2009-07-13 15:15:47 -070076
77#define VMSTOR_INVALID_PROTOCOL_VERSION -1
78
Bill Pemberton454f18a2009-07-27 16:47:24 -040079
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 Janssen565e7dc2009-07-13 15:15:47 -070085#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
86
87
Bill Pemberton454f18a2009-07-27 16:47:24 -040088
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 Janssen565e7dc2009-07-13 15:15:47 -070093
94#define MAX_TRANSFER_LENGTH 0x40000
95#define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \
Bill Pemberton454f18a2009-07-27 16:47:24 -040096 sizeof(VSTOR_PACKET) + \
97 (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
Hank Janssen565e7dc2009-07-13 15:15:47 -070098
99
100
Bill Pemberton454f18a2009-07-27 16:47:24 -0400101
102/* Packet structure describing virtual storage requests. */
103
Hank Janssen565e7dc2009-07-13 15:15:47 -0700104
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
Bill Pemberton454f18a2009-07-27 16:47:24 -0400122
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 Janssen565e7dc2009-07-13 15:15:47 -0700127
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{
Greg Kroah-Hartman2be80932009-07-14 15:11:03 -0700144 unsigned short Length;
Greg Kroah-Hartman59471432009-07-14 15:10:26 -0700145 unsigned char SrbStatus;
146 unsigned char ScsiStatus;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700147
Greg Kroah-Hartman59471432009-07-14 15:10:26 -0700148 unsigned char PortNumber;
149 unsigned char PathId;
150 unsigned char TargetId;
151 unsigned char Lun;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700152
Greg Kroah-Hartman59471432009-07-14 15:10:26 -0700153 unsigned char CdbLength;
154 unsigned char SenseInfoLength;
155 unsigned char DataIn;
156 unsigned char Reserved;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700157
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700158 unsigned int DataTransferLength;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700159
160 union
161 {
Bill Pemberton454f18a2009-07-27 16:47:24 -0400162 unsigned char Cdb[CDB16GENERIC_LENGTH];
Hank Janssen565e7dc2009-07-13 15:15:47 -0700163
Bill Pemberton454f18a2009-07-27 16:47:24 -0400164 unsigned char SenseData[SENSE_BUFFER_SIZE];
Hank Janssen565e7dc2009-07-13 15:15:47 -0700165
Bill Pemberton454f18a2009-07-27 16:47:24 -0400166 unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
Hank Janssen565e7dc2009-07-13 15:15:47 -0700167 };
168
169} VMSCSI_REQUEST, *PVMSCSI_REQUEST;
170
171C_ASSERT((sizeof(VMSCSI_REQUEST) % 4) == 0);
172
173
Bill Pemberton454f18a2009-07-27 16:47:24 -0400174
175/* This structure is sent during the intialization phase to get the different */
176/* properties of the channel. */
177
Hank Janssen565e7dc2009-07-13 15:15:47 -0700178
179typedef struct
180{
Greg Kroah-Hartman2be80932009-07-14 15:11:03 -0700181 unsigned short ProtocolVersion;
Greg Kroah-Hartman59471432009-07-14 15:10:26 -0700182 unsigned char PathId;
183 unsigned char TargetId;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700184
Bill Pemberton454f18a2009-07-27 16:47:24 -0400185
186 /* Note: port number is only really known on the client side */
187
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700188 unsigned int PortNumber;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700189
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700190 unsigned int Flags;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700191
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700192 unsigned int MaxTransferBytes;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700193
Bill Pemberton454f18a2009-07-27 16:47:24 -0400194
195 /* This id is unique for each channel and will correspond with */
196 /* vendor specific data in the inquirydata */
197
Hank Janssen565e7dc2009-07-13 15:15:47 -0700198
Greg Kroah-Hartmanb509bf52009-07-14 15:11:45 -0700199 unsigned long long UniqueId;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700200
201} VMSTORAGE_CHANNEL_PROPERTIES, *PVMSTORAGE_CHANNEL_PROPERTIES;
202
203C_ASSERT((sizeof(VMSTORAGE_CHANNEL_PROPERTIES) % 4) == 0);
204
205
Bill Pemberton454f18a2009-07-27 16:47:24 -0400206
207/* This structure is sent during the storage protocol negotiations. */
208
Hank Janssen565e7dc2009-07-13 15:15:47 -0700209
210typedef struct
211{
Bill Pemberton454f18a2009-07-27 16:47:24 -0400212
213 /* Major (MSW) and minor (LSW) version numbers. */
214
Hank Janssen565e7dc2009-07-13 15:15:47 -0700215
Greg Kroah-Hartman2be80932009-07-14 15:11:03 -0700216 unsigned short MajorMinor;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700217
218
Bill Pemberton454f18a2009-07-27 16:47:24 -0400219
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 Janssen565e7dc2009-07-13 15:15:47 -0700224
Greg Kroah-Hartman2be80932009-07-14 15:11:03 -0700225 unsigned short Revision;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700226
227} VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION;
228
229C_ASSERT((sizeof(VMSTORAGE_PROTOCOL_VERSION) % 4) == 0);
230
231
Bill Pemberton454f18a2009-07-27 16:47:24 -0400232
233/* Channel Property Flags */
234
Hank Janssen565e7dc2009-07-13 15:15:47 -0700235
236#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
237#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
238
239
240typedef struct _VSTOR_PACKET
241{
Bill Pemberton454f18a2009-07-27 16:47:24 -0400242
243 /* Requested operation type */
244
Hank Janssen565e7dc2009-07-13 15:15:47 -0700245
246 VSTOR_PACKET_OPERATION Operation;
247
Bill Pemberton454f18a2009-07-27 16:47:24 -0400248
249 /* Flags - see below for values */
250
Hank Janssen565e7dc2009-07-13 15:15:47 -0700251
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700252 unsigned int Flags;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700253
Bill Pemberton454f18a2009-07-27 16:47:24 -0400254
255 /* Status of the request returned from the server side. */
256
Hank Janssen565e7dc2009-07-13 15:15:47 -0700257
Greg Kroah-Hartman3abcbc42009-07-14 15:13:46 -0700258 unsigned int Status;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700259
Bill Pemberton454f18a2009-07-27 16:47:24 -0400260
261 /* Data payload area */
262
Hank Janssen565e7dc2009-07-13 15:15:47 -0700263
264 union
265 {
Hank Janssen565e7dc2009-07-13 15:15:47 -0700266
Bill Pemberton454f18a2009-07-27 16:47:24 -0400267 /* Structure used to forward SCSI commands from the client to the server. */
Hank Janssen565e7dc2009-07-13 15:15:47 -0700268
Hank Janssen565e7dc2009-07-13 15:15:47 -0700269
Bill Pemberton454f18a2009-07-27 16:47:24 -0400270 VMSCSI_REQUEST VmSrb;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700271
Hank Janssen565e7dc2009-07-13 15:15:47 -0700272
Bill Pemberton454f18a2009-07-27 16:47:24 -0400273 /* 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 Janssen565e7dc2009-07-13 15:15:47 -0700283 };
284
285} VSTOR_PACKET, *PVSTOR_PACKET;
286
287C_ASSERT((sizeof(VSTOR_PACKET) % 4) == 0);
288
Hank Janssen565e7dc2009-07-13 15:15:47 -0700289
Bill Pemberton454f18a2009-07-27 16:47:24 -0400290/* Packet flags */
291
292
293
294/* This flag indicates that the server should send back a completion for this */
295/* packet. */
296
Hank Janssen565e7dc2009-07-13 15:15:47 -0700297
298#define REQUEST_COMPLETION_FLAG 0x1
299
Bill Pemberton454f18a2009-07-27 16:47:24 -0400300
301/* This is the set of flags that the vsc can set in any packets it sends */
302
Hank Janssen565e7dc2009-07-13 15:15:47 -0700303
304#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
305
306
307#pragma pack(pop)