2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2012,2017 Microsoft Corp.
5 * Copyright (c) 2012 NetApp Inc.
6 * Copyright (c) 2012 Citrix Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef __HV_VSTORAGE_H__
34 #define __HV_VSTORAGE_H__
37 * Major/minor macros. Minor version is in LSB, meaning that earlier flat
38 * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
41 #define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff)
42 #define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff)
43 #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
46 #define VMSTOR_PROTOCOL_VERSION_WIN6 VMSTOR_PROTOCOL_VERSION(2, 0)
47 #define VMSTOR_PROTOCOL_VERSION_WIN7 VMSTOR_PROTOCOL_VERSION(4, 2)
48 #define VMSTOR_PROTOCOL_VERSION_WIN8 VMSTOR_PROTOCOL_VERSION(5, 1)
49 #define VMSTOR_PROTOCOL_VERSION_WIN8_1 VMSTOR_PROTOCOL_VERSION(6, 0)
50 #define VMSTOR_PROTOCOL_VERSION_WIN10 VMSTOR_PROTOCOL_VERSION(6, 2)
54 #define VMSTOR_INVALID_PROTOCOL_VERSION -1
59 * V1 RC < 2008/1/31 1.0
60 * V1 RC > 2008/1/31 2.0
65 #define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(5, 1)
68 * Packet structure ops describing virtual storage requests.
70 enum vstor_packet_ops {
71 VSTOR_OPERATION_COMPLETEIO = 1,
72 VSTOR_OPERATION_REMOVEDEVICE = 2,
73 VSTOR_OPERATION_EXECUTESRB = 3,
74 VSTOR_OPERATION_RESETLUN = 4,
75 VSTOR_OPERATION_RESETADAPTER = 5,
76 VSTOR_OPERATION_RESETBUS = 6,
77 VSTOR_OPERATION_BEGININITIALIZATION = 7,
78 VSTOR_OPERATION_ENDINITIALIZATION = 8,
79 VSTOR_OPERATION_QUERYPROTOCOLVERSION = 9,
80 VSTOR_OPERATION_QUERYPROPERTIES = 10,
81 VSTOR_OPERATION_ENUMERATE_BUS = 11,
82 VSTOR_OPERATION_FCHBA_DATA = 12,
83 VSTOR_OPERATION_CREATE_MULTI_CHANNELS = 13,
84 VSTOR_OPERATION_MAXIMUM = 13
89 * Platform neutral description of a scsi request -
90 * this remains the same across the write regardless of 32/64 bit
91 * note: it's patterned off the Windows DDK SCSI_PASS_THROUGH structure
94 #define CDB16GENERIC_LENGTH 0x10
95 #define SENSE_BUFFER_SIZE 0x14
96 #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
98 #define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
99 #define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
102 struct vmscsi_win8_extension {
104 * The following were added in Windows 8
108 uint8_t queue_action;
110 uint32_t time_out_value;
111 uint32_t queue_sort_ey;
119 /* HBA number, set to the order number detected by initiator. */
121 /* SCSI bus number or bus_id, different from CAM's path_id. */
128 uint8_t sense_info_len;
132 uint32_t transfer_len;
135 uint8_t cdb[CDB16GENERIC_LENGTH];
137 uint8_t sense_data[SENSE_BUFFER_SIZE];
139 uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
143 * The following was added in win8.
145 struct vmscsi_win8_extension win8_extension;
150 * This structure is sent during the initialization phase to get the different
151 * properties of the channel.
154 struct vmstor_chan_props {
159 uint16_t max_channel_cnt;
162 * Note: port number is only really known on the client side
166 uint32_t max_transfer_bytes;
169 * This id is unique for each channel and will correspond with
170 * vendor specific data in the inquiry_ata
177 * This structure is sent during the storage protocol negotiations.
180 struct vmstor_proto_ver
183 * Major (MSW) and minor (LSW) version numbers.
185 uint16_t major_minor;
187 uint16_t revision; /* always zero */
191 * Channel Property Flags
194 #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
195 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
198 struct vstor_packet {
200 * Requested operation type
202 enum vstor_packet_ops operation;
205 * Flags - see below for values
210 * Status of the request returned from the server side.
217 * Structure used to forward SCSI commands from the client to
220 struct vmscsi_req vm_srb;
223 * Structure used to query channel properties.
225 struct vmstor_chan_props chan_props;
228 * Used during version negotiations.
230 struct vmstor_proto_ver version;
233 * Number of multichannels to create
235 uint16_t multi_channels_cnt;
242 * SRB (SCSI Request Block) Status Codes
244 #define SRB_STATUS_PENDING 0x00
245 #define SRB_STATUS_SUCCESS 0x01
246 #define SRB_STATUS_ABORTED 0x02
247 #define SRB_STATUS_ERROR 0x04
248 #define SRB_STATUS_INVALID_LUN 0x20
250 * SRB Status Masks (can be combined with above status codes)
252 #define SRB_STATUS_QUEUE_FROZEN 0x40
253 #define SRB_STATUS_AUTOSENSE_VALID 0x80
255 #define SRB_STATUS(status) \
256 ((status) & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
261 #define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
262 #define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
263 #define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
264 #define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
265 #define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
266 #define SRB_FLAGS_DATA_IN 0x00000040
267 #define SRB_FLAGS_DATA_OUT 0x00000080
268 #define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
269 #define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
270 #define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
271 #define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
272 #define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
278 * This flag indicates that the server should send back a completion for this
281 #define REQUEST_COMPLETION_FLAG 0x1
284 * This is the set of flags that the vsc can set in any packets it sends
286 #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
288 #endif /* __HV_VSTORAGE_H__ */