xref: /freebsd/sys/dev/hyperv/storvsc/hv_vstorage.h (revision 0aeed3e99367bed5755068d9218cd8041644ff2b)
1 /*-
2  * Copyright (c) 2009-2012 Microsoft Corp.
3  * Copyright (c) 2012 NetApp Inc.
4  * Copyright (c) 2012 Citrix Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef __HV_VSTORAGE_H__
32 #define __HV_VSTORAGE_H__
33 
34 /*
35  * Major/minor macros.  Minor version is in LSB, meaning that earlier flat
36  * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1).
37  */
38 
39 #define VMSTOR_PROTOCOL_MAJOR(VERSION_)         (((VERSION_) >> 8) & 0xff)
40 #define VMSTOR_PROTOCOL_MINOR(VERSION_)         (((VERSION_)     ) & 0xff)
41 #define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
42                                                  (((MINOR_) & 0xff)     ))
43 
44 /*
45  * Invalid version.
46  */
47 #define VMSTOR_INVALID_PROTOCOL_VERSION  -1
48 
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  * Win7: 4.2
55  * Win8: 5.1
56  */
57 
58 #define VMSTOR_PROTOCOL_VERSION_CURRENT	VMSTOR_PROTOCOL_VERSION(5, 1)
59 
60 /**
61  *  Packet structure ops describing virtual storage requests.
62  */
63 enum vstor_packet_ops {
64 	VSTOR_OPERATION_COMPLETEIO            = 1,
65 	VSTOR_OPERATION_REMOVEDEVICE          = 2,
66 	VSTOR_OPERATION_EXECUTESRB            = 3,
67 	VSTOR_OPERATION_RESETLUN              = 4,
68 	VSTOR_OPERATION_RESETADAPTER          = 5,
69 	VSTOR_OPERATION_RESETBUS              = 6,
70 	VSTOR_OPERATION_BEGININITIALIZATION   = 7,
71 	VSTOR_OPERATION_ENDINITIALIZATION     = 8,
72 	VSTOR_OPERATION_QUERYPROTOCOLVERSION  = 9,
73 	VSTOR_OPERATION_QUERYPROPERTIES       = 10,
74 	VSTOR_OPERATION_ENUMERATE_BUS         = 11,
75 	VSTOR_OPERATION_FCHBA_DATA            = 12,
76 	VSTOR_OPERATION_CREATE_MULTI_CHANNELS = 13,
77 	VSTOR_OPERATION_MAXIMUM               = 13
78 };
79 
80 
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 Windows DDK SCSI_PASS_THROUGH structure
85  */
86 
87 #define CDB16GENERIC_LENGTH			0x10
88 #define SENSE_BUFFER_SIZE			0x14
89 #define MAX_DATA_BUFFER_LENGTH_WITH_PADDING	0x14
90 
91 #define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE	0x14
92 #define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE	0x12
93 
94 
95 struct vmscsi_win8_extension {
96 	/*
97 	 * The following were added in Windows 8
98 	 */
99 	uint16_t reserve;
100 	uint8_t  queue_tag;
101 	uint8_t  queue_action;
102 	uint32_t srb_flags;
103 	uint32_t time_out_value;
104 	uint32_t queue_sort_ey;
105 } __packed;
106 
107 struct vmscsi_req {
108 	uint16_t length;
109 	uint8_t  srb_status;
110 	uint8_t  scsi_status;
111 
112 	/* HBA number, set to the order number detected by initiator. */
113 	uint8_t  port;
114 	/* SCSI bus number or bus_id, different from CAM's path_id. */
115 	uint8_t  path_id;
116 
117 	uint8_t  target_id;
118 	uint8_t  lun;
119 
120 	uint8_t  cdb_len;
121 	uint8_t  sense_info_len;
122 	uint8_t  data_in;
123 	uint8_t  reserved;
124 
125 	uint32_t transfer_len;
126 
127 	union {
128 	    uint8_t cdb[CDB16GENERIC_LENGTH];
129 
130 	    uint8_t sense_data[SENSE_BUFFER_SIZE];
131 
132 	    uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
133 	} u;
134 
135 	/*
136 	 * The following was added in win8.
137 	 */
138 	struct vmscsi_win8_extension win8_extension;
139 
140 } __packed;
141 
142 /**
143  *  This structure is sent during the initialization phase to get the different
144  *  properties of the channel.
145  */
146 
147 struct vmstor_chan_props {
148 	uint16_t proto_ver;
149 	uint8_t  path_id;
150 	uint8_t  target_id;
151 
152 	uint16_t max_channel_cnt;
153 
154 	/**
155 	 * Note: port number is only really known on the client side
156 	 */
157 	uint16_t port;
158 	uint32_t flags;
159 	uint32_t max_transfer_bytes;
160 
161 	/**
162 	 *  This id is unique for each channel and will correspond with
163 	 *  vendor specific data in the inquiry_ata
164 	 */
165 	uint64_t unique_id;
166 
167 } __packed;
168 
169 /**
170  *  This structure is sent during the storage protocol negotiations.
171  */
172 
173 struct vmstor_proto_ver
174 {
175 	/**
176 	 * Major (MSW) and minor (LSW) version numbers.
177 	 */
178 	uint16_t major_minor;
179 
180 	uint16_t revision;			/* always zero */
181 } __packed;
182 
183 /**
184  * Channel Property Flags
185  */
186 
187 #define STORAGE_CHANNEL_REMOVABLE_FLAG                  0x1
188 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG               0x2
189 
190 
191 struct vstor_packet {
192 	/**
193 	 * Requested operation type
194 	 */
195 	enum vstor_packet_ops operation;
196 
197 	/*
198 	 * Flags - see below for values
199 	 */
200 	uint32_t flags;
201 
202 	/**
203 	 * Status of the request returned from the server side.
204 	 */
205 	uint32_t status;
206 
207 	union
208 	{
209 	    /**
210 	     * Structure used to forward SCSI commands from the client to
211 	     * the server.
212 	     */
213 	    struct vmscsi_req vm_srb;
214 
215 	    /**
216 	     * Structure used to query channel properties.
217 	     */
218 	    struct vmstor_chan_props chan_props;
219 
220 	    /**
221 	     * Used during version negotiations.
222 	     */
223 	    struct vmstor_proto_ver version;
224 
225 	    /**
226              * Number of multichannels to create
227 	     */
228 	    uint16_t multi_channels_cnt;
229 	} u;
230 
231 } __packed;
232 
233 
234 /**
235  * SRB (SCSI Request Block) Status Codes
236  */
237 #define SRB_STATUS_PENDING		0x00
238 #define SRB_STATUS_SUCCESS		0x01
239 #define SRB_STATUS_ABORTED		0x02
240 #define SRB_STATUS_ABORT_FAILED	0x03
241 #define SRB_STATUS_ERROR 		0x04
242 #define SRB_STATUS_BUSY			0x05
243 
244 /**
245  * SRB Status Masks (can be combined with above status codes)
246  */
247 #define SRB_STATUS_QUEUE_FROZEN		0x40
248 #define SRB_STATUS_AUTOSENSE_VALID	0x80
249 
250 
251 /**
252  *  Packet flags
253  */
254 
255 /**
256  *  This flag indicates that the server should send back a completion for this
257  *  packet.
258  */
259 #define REQUEST_COMPLETION_FLAG	0x1
260 
261 /**
262  *  This is the set of flags that the vsc can set in any packets it sends
263  */
264 #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
265 
266 #endif /* __HV_VSTORAGE_H__ */
267