Staging: hv: move vstorage.h to hv dir
[safe/jmp/linux-2.6] / drivers / staging / hv / vstorage.h
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
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. */
29
30 #define REVISION_STRING(REVISION_) #REVISION_
31 #define FILL_VMSTOR_REVISION(RESULT_LVALUE_)                            \
32 {                                                                       \
33         char *revisionString = REVISION_STRING($Revision: 6 $) + 11;    \
34         RESULT_LVALUE_ = 0;                                             \
35         while (*revisionString >= '0' && *revisionString <= '9') {      \
36                 RESULT_LVALUE_ *= 10;                                   \
37                 RESULT_LVALUE_ += *revisionString - '0';                \
38                 revisionString++;                                       \
39         }                                                               \
40 }
41
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) | \
47                                                  (((MINOR_) & 0xff)))
48 #define VMSTOR_INVALID_PROTOCOL_VERSION         (-1)
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 #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
55
56
57
58
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)))
66
67
68 /*  Packet structure describing virtual storage requests. */
69 typedef enum {
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;
82
83
84
85 /*
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
89  */
90
91 #define CDB16GENERIC_LENGTH                     0x10
92
93 #ifndef SENSE_BUFFER_SIZE
94 #define SENSE_BUFFER_SIZE                       0x12
95 #endif
96
97 #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING     0x14
98
99
100 typedef struct {
101         unsigned short Length;
102         unsigned char SrbStatus;
103         unsigned char ScsiStatus;
104
105         unsigned char PortNumber;
106         unsigned char PathId;
107         unsigned char TargetId;
108         unsigned char Lun;
109
110         unsigned char CdbLength;
111         unsigned char SenseInfoLength;
112         unsigned char DataIn;
113         unsigned char Reserved;
114
115         unsigned int DataTransferLength;
116
117         union {
118         unsigned char Cdb[CDB16GENERIC_LENGTH];
119
120         unsigned char SenseData[SENSE_BUFFER_SIZE];
121
122         unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
123         };
124 } __attribute((packed)) VMSCSI_REQUEST, *PVMSCSI_REQUEST;
125
126
127 /*
128  * This structure is sent during the intialization phase to get the different
129  * properties of the channel.
130  */
131 typedef struct {
132         unsigned short ProtocolVersion;
133         unsigned char  PathId;
134         unsigned char  TargetId;
135
136         /* Note: port number is only really known on the client side */
137         unsigned int  PortNumber;
138         unsigned int  Flags;
139         unsigned int  MaxTransferBytes;
140
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;
145
146 /*  This structure is sent during the storage protocol negotiations. */
147 typedef struct {
148         /* Major (MSW) and minor (LSW) version numbers. */
149         unsigned short MajorMinor;
150
151         /*
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
155          * builds.
156          */
157         unsigned short Revision;
158 } __attribute__((packed)) VMSTORAGE_PROTOCOL_VERSION, *PVMSTORAGE_PROTOCOL_VERSION;
159
160
161 /* Channel Property Flags */
162 #define STORAGE_CHANNEL_REMOVABLE_FLAG          0x1
163 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG       0x2
164
165 typedef struct _VSTOR_PACKET {
166         /* Requested operation type */
167         VSTOR_PACKET_OPERATION Operation;
168
169         /*  Flags - see below for values */
170         unsigned int     Flags;
171
172         /* Status of the request returned from the server side. */
173         unsigned int     Status;
174
175         /* Data payload area */
176         union {
177                 /*
178                  * Structure used to forward SCSI commands from the
179                  * client to the server.
180                  */
181                 VMSCSI_REQUEST VmSrb;
182
183                 /* Structure used to query channel properties. */
184                 VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties;
185
186                 /* Used during version negotiations. */
187                 VMSTORAGE_PROTOCOL_VERSION Version;
188         };
189
190 } __attribute__((packed)) VSTOR_PACKET, *PVSTOR_PACKET;
191
192
193
194 /* Packet flags */
195
196
197 /*
198  * This flag indicates that the server should send back a completion for this
199  * packet.
200  */
201 #define REQUEST_COMPLETION_FLAG 0x1
202
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)