Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[pandora-kernel.git] / 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 /* vstorage.w revision number.  This is used in the case of a version match, */
25 /* to alert the user that structure sizes may be mismatched even though the */
26 /* protocol versions match. */
27
28 #define REVISION_STRING(REVISION_) #REVISION_
29 #define FILL_VMSTOR_REVISION(RESULT_LVALUE_)                            \
30         do {                                                            \
31                 char *revision_string                                   \
32                         = REVISION_STRING($Rev : 6 $) + 6;              \
33                 RESULT_LVALUE_ = 0;                                     \
34                 while (*revision_string >= '0'                          \
35                         && *revision_string <= '9') {                   \
36                         RESULT_LVALUE_ *= 10;                           \
37                         RESULT_LVALUE_ += *revision_string - '0';       \
38                         revision_string++;                              \
39                 }                                                       \
40         } while (0)
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(struct vmdata_gpa_direct) + \
64                         sizeof(struct vstor_packet) +           \
65                         sizesizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
66
67
68 /*  Packet structure describing virtual storage requests. */
69 enum vstor_packet_operation {
70         VSTOR_OPERATION_COMPLETE_IO             = 1,
71         VSTOR_OPERATION_REMOVE_DEVICE           = 2,
72         VSTOR_OPERATION_EXECUTE_SRB             = 3,
73         VSTOR_OPERATION_RESET_LUN               = 4,
74         VSTOR_OPERATION_RESET_ADAPTER           = 5,
75         VSTOR_OPERATION_RESET_BUS               = 6,
76         VSTOR_OPERATION_BEGIN_INITIALIZATION    = 7,
77         VSTOR_OPERATION_END_INITIALIZATION      = 8,
78         VSTOR_OPERATION_QUERY_PROTOCOL_VERSION  = 9,
79         VSTOR_OPERATION_QUERY_PROPERTIES        = 10,
80         VSTOR_OPERATION_MAXIMUM                 = 10
81 };
82
83 /*
84  * Platform neutral description of a scsi request -
85  * this remains the same across the write regardless of 32/64 bit
86  * note: it's patterned off the SCSI_PASS_THROUGH structure
87  */
88 #define CDB16GENERIC_LENGTH                     0x10
89
90 #ifndef SENSE_BUFFER_SIZE
91 #define SENSE_BUFFER_SIZE                       0x12
92 #endif
93
94 #define MAX_DATA_BUF_LEN_WITH_PADDING           0x14
95
96 struct vmscsi_request {
97         unsigned short length;
98         unsigned char srb_status;
99         unsigned char scsi_status;
100
101         unsigned char port_number;
102         unsigned char path_id;
103         unsigned char target_id;
104         unsigned char lun;
105
106         unsigned char cdb_length;
107         unsigned char sense_info_length;
108         unsigned char data_in;
109         unsigned char reserved;
110
111         unsigned int data_transfer_length;
112
113         union {
114                 unsigned char cdb[CDB16GENERIC_LENGTH];
115                 unsigned char sense_data[SENSE_BUFFER_SIZE];
116                 unsigned char reserved_array[MAX_DATA_BUF_LEN_WITH_PADDING];
117         };
118 } __attribute((packed));
119
120
121 /*
122  * This structure is sent during the intialization phase to get the different
123  * properties of the channel.
124  */
125 struct vmstorage_channel_properties {
126         unsigned short protocol_version;
127         unsigned char path_id;
128         unsigned char target_id;
129
130         /* Note: port number is only really known on the client side */
131         unsigned int port_number;
132         unsigned int flags;
133         unsigned int max_transfer_bytes;
134
135         /*  This id is unique for each channel and will correspond with */
136         /*  vendor specific data in the inquirydata */
137         unsigned long long unique_id;
138 } __attribute__((packed));
139
140 /*  This structure is sent during the storage protocol negotiations. */
141 struct vmstorage_protocol_version {
142         /* Major (MSW) and minor (LSW) version numbers. */
143         unsigned short major_minor;
144
145         /*
146          * Revision number is auto-incremented whenever this file is changed
147          * (See FILL_VMSTOR_REVISION macro above).  Mismatch does not
148          * definitely indicate incompatibility--but it does indicate mismatched
149          * builds.
150          */
151         unsigned short revision;
152 } __attribute__((packed));
153
154 /* Channel Property Flags */
155 #define STORAGE_CHANNEL_REMOVABLE_FLAG          0x1
156 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG       0x2
157
158 struct vstor_packet {
159         /* Requested operation type */
160         enum vstor_packet_operation operation;
161
162         /*  Flags - see below for values */
163         unsigned int flags;
164
165         /* Status of the request returned from the server side. */
166         unsigned int status;
167
168         /* Data payload area */
169         union {
170                 /*
171                  * Structure used to forward SCSI commands from the
172                  * client to the server.
173                  */
174                 struct vmscsi_request vm_srb;
175
176                 /* Structure used to query channel properties. */
177                 struct vmstorage_channel_properties storage_channel_properties;
178
179                 /* Used during version negotiations. */
180                 struct vmstorage_protocol_version version;
181         };
182 } __attribute__((packed));
183
184 /* Packet flags */
185 /*
186  * This flag indicates that the server should send back a completion for this
187  * packet.
188  */
189 #define REQUEST_COMPLETION_FLAG 0x1
190
191 /*  This is the set of flags that the vsc can set in any packets it sends */
192 #define VSC_LEGAL_FLAGS         (REQUEST_COMPLETION_FLAG)