Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 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 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 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 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 30 | #define REVISION_STRING(REVISION_) #REVISION_ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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 | } \ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 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). */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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) |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 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 */ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 54 | #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0) |
| 55 | |
| 56 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 57 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 58 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 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. */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 62 | #define MAX_TRANSFER_LENGTH 0x40000 |
| 63 | #define DEFAULT_PACKET_SIZE (sizeof(VMDATA_GPA_DIRECT) + \ |
| 64 | sizeof(VSTOR_PACKET) + \ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 65 | (sizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE))) |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 66 | |
| 67 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 68 | /* Packet structure describing virtual storage requests. */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 81 | } VSTOR_PACKET_OPERATION; |
| 82 | |
| 83 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 84 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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 | */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 90 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 91 | #define CDB16GENERIC_LENGTH 0x10 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 92 | |
| 93 | #ifndef SENSE_BUFFER_SIZE |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 94 | #define SENSE_BUFFER_SIZE 0x12 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 95 | #endif |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 96 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 97 | #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 98 | |
| 99 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 100 | typedef struct { |
| 101 | unsigned short Length; |
| 102 | unsigned char SrbStatus; |
| 103 | unsigned char ScsiStatus; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 104 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 105 | unsigned char PortNumber; |
| 106 | unsigned char PathId; |
| 107 | unsigned char TargetId; |
| 108 | unsigned char Lun; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 109 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 110 | unsigned char CdbLength; |
| 111 | unsigned char SenseInfoLength; |
| 112 | unsigned char DataIn; |
| 113 | unsigned char Reserved; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 114 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 115 | unsigned int DataTransferLength; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 116 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 117 | union { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 118 | unsigned char Cdb[CDB16GENERIC_LENGTH]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 119 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 120 | unsigned char SenseData[SENSE_BUFFER_SIZE]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 121 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 122 | unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 123 | }; |
| 124 | } __attribute((packed)) VMSCSI_REQUEST, *PVMSCSI_REQUEST; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 125 | |
| 126 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 135 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 136 | /* Note: port number is only really known on the client side */ |
| 137 | unsigned int PortNumber; |
| 138 | unsigned int Flags; |
| 139 | unsigned int MaxTransferBytes; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 140 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 145 | |
| 146 | /* This structure is sent during the storage protocol negotiations. */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 147 | typedef struct { |
| 148 | /* Major (MSW) and minor (LSW) version numbers. */ |
| 149 | unsigned short MajorMinor; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 150 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 159 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 160 | |
| 161 | /* Channel Property Flags */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 162 | #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 |
| 163 | #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 164 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 165 | typedef struct _VSTOR_PACKET { |
| 166 | /* Requested operation type */ |
| 167 | VSTOR_PACKET_OPERATION Operation; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 168 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 169 | /* Flags - see below for values */ |
| 170 | unsigned int Flags; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 171 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 172 | /* Status of the request returned from the server side. */ |
| 173 | unsigned int Status; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 174 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 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; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 182 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 183 | /* Structure used to query channel properties. */ |
| 184 | VMSTORAGE_CHANNEL_PROPERTIES StorageChannelProperties; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 185 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 186 | /* Used during version negotiations. */ |
| 187 | VMSTORAGE_PROTOCOL_VERSION Version; |
| 188 | }; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 189 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 190 | } __attribute__((packed)) VSTOR_PACKET, *PVSTOR_PACKET; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 191 | |
| 192 | |
| 193 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 194 | /* Packet flags */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 195 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 196 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 197 | /* |
| 198 | * This flag indicates that the server should send back a completion for this |
| 199 | * packet. |
| 200 | */ |
| 201 | #define REQUEST_COMPLETION_FLAG 0x1 |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 202 | |
| 203 | /* This is the set of flags that the vsc can set in any packets it sends */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame^] | 204 | #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) |