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 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 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 | |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 28 | #define REVISION_STRING(REVISION_) #REVISION_ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 29 | #define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \ |
| 30 | { \ |
| 31 | char *revisionString = REVISION_STRING($Revision: 6 $) + 11; \ |
| 32 | RESULT_LVALUE_ = 0; \ |
| 33 | while (*revisionString >= '0' && *revisionString <= '9') { \ |
| 34 | RESULT_LVALUE_ *= 10; \ |
| 35 | RESULT_LVALUE_ += *revisionString - '0'; \ |
| 36 | revisionString++; \ |
| 37 | } \ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 40 | /* Major/minor macros. Minor version is in LSB, meaning that earlier flat */ |
| 41 | /* 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] | 42 | #define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff) |
| 43 | #define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_)) & 0xff) |
| 44 | #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \ |
| 45 | (((MINOR_) & 0xff))) |
| 46 | #define VMSTOR_INVALID_PROTOCOL_VERSION (-1) |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 47 | |
| 48 | /* Version history: */ |
| 49 | /* V1 Beta 0.1 */ |
| 50 | /* V1 RC < 2008/1/31 1.0 */ |
| 51 | /* V1 RC > 2008/1/31 2.0 */ |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 52 | #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0) |
| 53 | |
| 54 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 55 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 56 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 57 | /* This will get replaced with the max transfer length that is possible on */ |
| 58 | /* the host adapter. */ |
| 59 | /* 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] | 60 | #define MAX_TRANSFER_LENGTH 0x40000 |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame^] | 61 | #define DEFAULT_PACKET_SIZE (sizeof(struct vmdata_gpa_direct) + \ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 62 | sizeof(struct vstor_packet) + \ |
| 63 | sizesizeof(u64) * (MAX_TRANSFER_LENGTH / PAGE_SIZE))) |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 64 | |
| 65 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 66 | /* Packet structure describing virtual storage requests. */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 67 | enum vstor_packet_operation { |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 68 | VStorOperationCompleteIo = 1, |
| 69 | VStorOperationRemoveDevice = 2, |
| 70 | VStorOperationExecuteSRB = 3, |
| 71 | VStorOperationResetLun = 4, |
| 72 | VStorOperationResetAdapter = 5, |
| 73 | VStorOperationResetBus = 6, |
| 74 | VStorOperationBeginInitialization = 7, |
| 75 | VStorOperationEndInitialization = 8, |
| 76 | VStorOperationQueryProtocolVersion = 9, |
| 77 | VStorOperationQueryProperties = 10, |
| 78 | VStorOperationMaximum = 10 |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 79 | }; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 80 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Platform neutral description of a scsi request - |
| 83 | * this remains the same across the write regardless of 32/64 bit |
| 84 | * note: it's patterned off the SCSI_PASS_THROUGH structure |
| 85 | */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 86 | #define CDB16GENERIC_LENGTH 0x10 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 87 | |
| 88 | #ifndef SENSE_BUFFER_SIZE |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 89 | #define SENSE_BUFFER_SIZE 0x12 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 90 | #endif |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 91 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 92 | #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 93 | |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 94 | struct vmscsi_request { |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 95 | unsigned short Length; |
| 96 | unsigned char SrbStatus; |
| 97 | unsigned char ScsiStatus; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 98 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 99 | unsigned char PortNumber; |
| 100 | unsigned char PathId; |
| 101 | unsigned char TargetId; |
| 102 | unsigned char Lun; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 103 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 104 | unsigned char CdbLength; |
| 105 | unsigned char SenseInfoLength; |
| 106 | unsigned char DataIn; |
| 107 | unsigned char Reserved; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 108 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 109 | unsigned int DataTransferLength; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 110 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 111 | union { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 112 | unsigned char Cdb[CDB16GENERIC_LENGTH]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 113 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 114 | unsigned char SenseData[SENSE_BUFFER_SIZE]; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 115 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 116 | unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 117 | }; |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 118 | } __attribute((packed)); |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 119 | |
| 120 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 121 | /* |
| 122 | * This structure is sent during the intialization phase to get the different |
| 123 | * properties of the channel. |
| 124 | */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 125 | struct vmstorage_channel_properties { |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 126 | unsigned short ProtocolVersion; |
| 127 | unsigned char PathId; |
| 128 | unsigned char TargetId; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 129 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 130 | /* Note: port number is only really known on the client side */ |
| 131 | unsigned int PortNumber; |
| 132 | unsigned int Flags; |
| 133 | unsigned int MaxTransferBytes; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 134 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 135 | /* This id is unique for each channel and will correspond with */ |
| 136 | /* vendor specific data in the inquirydata */ |
| 137 | unsigned long long UniqueId; |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 138 | } __attribute__((packed)); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 139 | |
| 140 | /* This structure is sent during the storage protocol negotiations. */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 141 | struct vmstorage_protocol_version { |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 142 | /* Major (MSW) and minor (LSW) version numbers. */ |
| 143 | unsigned short MajorMinor; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 144 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 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; |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 152 | } __attribute__((packed)); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 153 | |
| 154 | /* Channel Property Flags */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 155 | #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 |
| 156 | #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 157 | |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 158 | struct vstor_packet { |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 159 | /* Requested operation type */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 160 | enum vstor_packet_operation Operation; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 161 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 162 | /* Flags - see below for values */ |
| 163 | unsigned int Flags; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 164 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 165 | /* Status of the request returned from the server side. */ |
| 166 | unsigned int Status; |
Hank Janssen | 565e7dc | 2009-07-13 15:15:47 -0700 | [diff] [blame] | 167 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 168 | /* Data payload area */ |
| 169 | union { |
| 170 | /* |
| 171 | * Structure used to forward SCSI commands from the |
| 172 | * client to the server. |
| 173 | */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 174 | struct vmscsi_request VmSrb; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 175 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 176 | /* Structure used to query channel properties. */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 177 | struct vmstorage_channel_properties StorageChannelProperties; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 178 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 179 | /* Used during version negotiations. */ |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 180 | struct vmstorage_protocol_version Version; |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 181 | }; |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 182 | } __attribute__((packed)); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 183 | |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 184 | /* Packet flags */ |
Greg Kroah-Hartman | d7363a1 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 185 | /* |
| 186 | * This flag indicates that the server should send back a completion for this |
| 187 | * packet. |
| 188 | */ |
| 189 | #define REQUEST_COMPLETION_FLAG 0x1 |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 190 | |
| 191 | /* 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] | 192 | #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) |