blob: dc04185ba8040752047d5313200206c779e6c82b [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
Bill Pemberton454f18a2009-07-27 16:47:24 -040025
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
Hank Janssen565e7dc2009-07-13 15:15:47 -070030#define REVISION_STRING(REVISION_) #REVISION_
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070031#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 } \
Hank Janssen565e7dc2009-07-13 15:15:47 -070040}
41
Bill Pemberton454f18a2009-07-27 16:47:24 -040042/* 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). */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070044#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)
Bill Pemberton454f18a2009-07-27 16:47:24 -040049
50/* Version history: */
51/* V1 Beta 0.1 */
52/* V1 RC < 2008/1/31 1.0 */
53/* V1 RC > 2008/1/31 2.0 */
Hank Janssen565e7dc2009-07-13 15:15:47 -070054#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0)
55
56
Bill Pemberton454f18a2009-07-27 16:47:24 -040057
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070058
Bill Pemberton454f18a2009-07-27 16:47:24 -040059/* 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. */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070062#define MAX_TRANSFER_LENGTH 0x40000
63#define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \
64 sizeof(VSTOR_PACKET) + \
Bill Pemberton454f18a2009-07-27 16:47:24 -040065 (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE)))
Hank Janssen565e7dc2009-07-13 15:15:47 -070066
67
Bill Pemberton454f18a2009-07-27 16:47:24 -040068/* Packet structure describing virtual storage requests. */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070069typedef 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
Hank Janssen565e7dc2009-07-13 15:15:47 -070081} VSTOR_PACKET_OPERATION;
82
83
Bill Pemberton454f18a2009-07-27 16:47:24 -040084
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070085/*
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 */
Bill Pemberton454f18a2009-07-27 16:47:24 -040090
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070091#define CDB16GENERIC_LENGTH 0x10
Hank Janssen565e7dc2009-07-13 15:15:47 -070092
93#ifndef SENSE_BUFFER_SIZE
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070094#define SENSE_BUFFER_SIZE 0x12
Hank Janssen565e7dc2009-07-13 15:15:47 -070095#endif
Hank Janssen565e7dc2009-07-13 15:15:47 -070096
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -070097#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
Hank Janssen565e7dc2009-07-13 15:15:47 -070098
99
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700100typedef struct {
101 unsigned short Length;
102 unsigned char SrbStatus;
103 unsigned char ScsiStatus;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700104
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700105 unsigned char PortNumber;
106 unsigned char PathId;
107 unsigned char TargetId;
108 unsigned char Lun;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700109
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700110 unsigned char CdbLength;
111 unsigned char SenseInfoLength;
112 unsigned char DataIn;
113 unsigned char Reserved;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700114
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700115 unsigned int DataTransferLength;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700116
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700117 union {
Bill Pemberton454f18a2009-07-27 16:47:24 -0400118 unsigned char Cdb[CDB16GENERIC_LENGTH];
Hank Janssen565e7dc2009-07-13 15:15:47 -0700119
Bill Pemberton454f18a2009-07-27 16:47:24 -0400120 unsigned char SenseData[SENSE_BUFFER_SIZE];
Hank Janssen565e7dc2009-07-13 15:15:47 -0700121
Bill Pemberton454f18a2009-07-27 16:47:24 -0400122 unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700123 };
124} __attribute((packed)) VMSCSI_REQUEST, *PVMSCSI_REQUEST;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700125
126
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700127/*
128 * This structure is sent during the intialization phase to get the different
129 * properties of the channel.
130 */
131typedef struct {
132 unsigned short ProtocolVersion;
133 unsigned char PathId;
134 unsigned char TargetId;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400135
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700136 /* Note: port number is only really known on the client side */
137 unsigned int PortNumber;
138 unsigned int Flags;
139 unsigned int MaxTransferBytes;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400140
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700141 /* 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;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400145
146/* This structure is sent during the storage protocol negotiations. */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700147typedef struct {
148 /* Major (MSW) and minor (LSW) version numbers. */
149 unsigned short MajorMinor;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400150
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700151 /*
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;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700159
Bill Pemberton454f18a2009-07-27 16:47:24 -0400160
161/* Channel Property Flags */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700162#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
163#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
Bill Pemberton454f18a2009-07-27 16:47:24 -0400164
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700165typedef struct _VSTOR_PACKET {
166 /* Requested operation type */
167 VSTOR_PACKET_OPERATION Operation;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700168
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700169 /* Flags - see below for values */
170 unsigned int Flags;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700171
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700172 /* Status of the request returned from the server side. */
173 unsigned int Status;
Hank Janssen565e7dc2009-07-13 15:15:47 -0700174
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700175 /* 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;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400182
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700183 /* Structure used to query channel properties. */
184 VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400185
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700186 /* Used during version negotiations. */
187 VMSTORAGE_PROTOCOL_VERSION Version;
188 };
Hank Janssen565e7dc2009-07-13 15:15:47 -0700189
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700190} __attribute__((packed)) VSTOR_PACKET, *PVSTOR_PACKET;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400191
192
193
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700194/* Packet flags */
Bill Pemberton454f18a2009-07-27 16:47:24 -0400195
Hank Janssen565e7dc2009-07-13 15:15:47 -0700196
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700197/*
198 * This flag indicates that the server should send back a completion for this
199 * packet.
200 */
201#define REQUEST_COMPLETION_FLAG 0x1
Bill Pemberton454f18a2009-07-27 16:47:24 -0400202
203/* This is the set of flags that the vsc can set in any packets it sends */
Greg Kroah-Hartmand7363a12009-08-18 15:21:19 -0700204#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)