3 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
26 /* vstorage.w revision number. This is used in the case of a version match, */
27 /* to alert the user that structure sizes may be mismatched even though the */
28 /* protocol versions match. */
30 #define REVISION_STRING(REVISION_) #REVISION_
31 #define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \
33 char *revisionString = REVISION_STRING($Revision: 6 $) + 11; \
35 while (*revisionString >= '0' && *revisionString <= '9') { \
36 RESULT_LVALUE_ *= 10; \
37 RESULT_LVALUE_ += *revisionString - '0'; \
42 /* Major/minor macros. Minor version is in LSB, meaning that earlier flat */
43 /* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */
44 #define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff)
45 #define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_)) & 0xff)
46 #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
48 #define VMSTOR_INVALID_PROTOCOL_VERSION (-1)
50 /* Version history: */
52 /* V1 RC < 2008/1/31 1.0 */
53 /* V1 RC > 2008/1/31 2.0 */
54 #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
59 /* This will get replaced with the max transfer length that is possible on */
60 /* the host adapter. */
61 /* The max transfer length will be published when we offer a vmbus channel. */
62 #define MAX_TRANSFER_LENGTH 0x40000
63 #define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \
64 sizeof(VSTOR_PACKET) + \
65 (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
68 /* Packet structure describing virtual storage requests. */
70 VStorOperationCompleteIo
= 1,
71 VStorOperationRemoveDevice
= 2,
72 VStorOperationExecuteSRB
= 3,
73 VStorOperationResetLun
= 4,
74 VStorOperationResetAdapter
= 5,
75 VStorOperationResetBus
= 6,
76 VStorOperationBeginInitialization
= 7,
77 VStorOperationEndInitialization
= 8,
78 VStorOperationQueryProtocolVersion
= 9,
79 VStorOperationQueryProperties
= 10,
80 VStorOperationMaximum
= 10
81 } VSTOR_PACKET_OPERATION
;
86 * Platform neutral description of a scsi request -
87 * this remains the same across the write regardless of 32/64 bit
88 * note: it's patterned off the SCSI_PASS_THROUGH structure
91 #define CDB16GENERIC_LENGTH 0x10
93 #ifndef SENSE_BUFFER_SIZE
94 #define SENSE_BUFFER_SIZE 0x12
97 #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
101 unsigned short Length
;
102 unsigned char SrbStatus
;
103 unsigned char ScsiStatus
;
105 unsigned char PortNumber
;
106 unsigned char PathId
;
107 unsigned char TargetId
;
110 unsigned char CdbLength
;
111 unsigned char SenseInfoLength
;
112 unsigned char DataIn
;
113 unsigned char Reserved
;
115 unsigned int DataTransferLength
;
118 unsigned char Cdb
[CDB16GENERIC_LENGTH
];
120 unsigned char SenseData
[SENSE_BUFFER_SIZE
];
122 unsigned char ReservedArray
[MAX_DATA_BUFFER_LENGTH_WITH_PADDING
];
124 } __attribute((packed
)) VMSCSI_REQUEST
, *PVMSCSI_REQUEST
;
128 * This structure is sent during the intialization phase to get the different
129 * properties of the channel.
132 unsigned short ProtocolVersion
;
133 unsigned char PathId
;
134 unsigned char TargetId
;
136 /* Note: port number is only really known on the client side */
137 unsigned int PortNumber
;
139 unsigned int MaxTransferBytes
;
141 /* This id is unique for each channel and will correspond with */
142 /* vendor specific data in the inquirydata */
143 unsigned long long UniqueId
;
144 } __attribute__((packed
)) VMSTORAGE_CHANNEL_PROPERTIES
, *PVMSTORAGE_CHANNEL_PROPERTIES
;
146 /* This structure is sent during the storage protocol negotiations. */
148 /* Major (MSW) and minor (LSW) version numbers. */
149 unsigned short MajorMinor
;
152 * Revision number is auto-incremented whenever this file is changed
153 * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
154 * definitely indicate incompatibility--but it does indicate mismatched
157 unsigned short Revision
;
158 } __attribute__((packed
)) VMSTORAGE_PROTOCOL_VERSION
, *PVMSTORAGE_PROTOCOL_VERSION
;
161 /* Channel Property Flags */
162 #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
163 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
165 typedef struct _VSTOR_PACKET
{
166 /* Requested operation type */
167 VSTOR_PACKET_OPERATION Operation
;
169 /* Flags - see below for values */
172 /* Status of the request returned from the server side. */
175 /* Data payload area */
178 * Structure used to forward SCSI commands from the
179 * client to the server.
181 VMSCSI_REQUEST VmSrb
;
183 /* Structure used to query channel properties. */
184 VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties
;
186 /* Used during version negotiations. */
187 VMSTORAGE_PROTOCOL_VERSION Version
;
190 } __attribute__((packed
)) VSTOR_PACKET
, *PVSTOR_PACKET
;
198 * This flag indicates that the server should send back a completion for this
201 #define REQUEST_COMPLETION_FLAG 0x1
203 /* This is the set of flags that the vsc can set in any packets it sends */
204 #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)