xref: /spdk/include/spdk/scsi_spec.h (revision da6841e4509a8eec7972dfe154ea9f13d09d9be1)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2016 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 /**
7  * \file
8  * SCSI specification definitions
9  */
10 
11 #ifndef SPDK_SCSI_SPEC_H
12 #define SPDK_SCSI_SPEC_H
13 
14 #include "spdk/stdinc.h"
15 
16 #include "spdk/assert.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 enum spdk_scsi_group_code {
23 	SPDK_SCSI_6BYTE_CMD = 0x00,
24 	SPDK_SCSI_10BYTE_CMD = 0x20,
25 	SPDK_SCSI_10BYTE_CMD2 = 0x40,
26 	SPDK_SCSI_16BYTE_CMD = 0x80,
27 	SPDK_SCSI_12BYTE_CMD = 0xa0,
28 };
29 
30 #define SPDK_SCSI_GROUP_MASK	0xe0
31 #define SPDK_SCSI_OPCODE_MASK	0x1f
32 
33 enum spdk_scsi_status {
34 	SPDK_SCSI_STATUS_GOOD = 0x00,
35 	SPDK_SCSI_STATUS_CHECK_CONDITION = 0x02,
36 	SPDK_SCSI_STATUS_CONDITION_MET = 0x04,
37 	SPDK_SCSI_STATUS_BUSY = 0x08,
38 	SPDK_SCSI_STATUS_INTERMEDIATE = 0x10,
39 	SPDK_SCSI_STATUS_INTERMEDIATE_CONDITION_MET = 0x14,
40 	SPDK_SCSI_STATUS_RESERVATION_CONFLICT = 0x18,
41 	SPDK_SCSI_STATUS_Obsolete = 0x22,
42 	SPDK_SCSI_STATUS_TASK_SET_FULL = 0x28,
43 	SPDK_SCSI_STATUS_ACA_ACTIVE = 0x30,
44 	SPDK_SCSI_STATUS_TASK_ABORTED = 0x40,
45 };
46 
47 enum spdk_scsi_sense {
48 	SPDK_SCSI_SENSE_NO_SENSE = 0x00,
49 	SPDK_SCSI_SENSE_RECOVERED_ERROR = 0x01,
50 	SPDK_SCSI_SENSE_NOT_READY = 0x02,
51 	SPDK_SCSI_SENSE_MEDIUM_ERROR = 0x03,
52 	SPDK_SCSI_SENSE_HARDWARE_ERROR = 0x04,
53 	SPDK_SCSI_SENSE_ILLEGAL_REQUEST = 0x05,
54 	SPDK_SCSI_SENSE_UNIT_ATTENTION = 0x06,
55 	SPDK_SCSI_SENSE_DATA_PROTECT = 0x07,
56 	SPDK_SCSI_SENSE_BLANK_CHECK = 0x08,
57 	SPDK_SCSI_SENSE_VENDOR_SPECIFIC = 0x09,
58 	SPDK_SCSI_SENSE_COPY_ABORTED = 0x0a,
59 	SPDK_SCSI_SENSE_ABORTED_COMMAND = 0x0b,
60 	SPDK_SCSI_SENSE_VOLUME_OVERFLOW = 0x0d,
61 	SPDK_SCSI_SENSE_MISCOMPARE = 0x0e,
62 };
63 
64 enum spdk_scsi_asc {
65 	SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE = 0x00,
66 	SPDK_SCSI_ASC_PERIPHERAL_DEVICE_WRITE_FAULT = 0x03,
67 	SPDK_SCSI_ASC_LOGICAL_UNIT_NOT_READY = 0x04,
68 	SPDK_SCSI_ASC_WARNING = 0x0b,
69 	SPDK_SCSI_ASC_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x10,
70 	SPDK_SCSI_ASC_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x10,
71 	SPDK_SCSI_ASC_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x10,
72 	SPDK_SCSI_ASC_UNRECOVERED_READ_ERROR = 0x11,
73 	SPDK_SCSI_ASC_MISCOMPARE_DURING_VERIFY_OPERATION = 0x1d,
74 	SPDK_SCSI_ASC_INVALID_COMMAND_OPERATION_CODE = 0x20,
75 	SPDK_SCSI_ASC_ACCESS_DENIED = 0x20,
76 	SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE = 0x21,
77 	SPDK_SCSI_ASC_INVALID_FIELD_IN_CDB = 0x24,
78 	SPDK_SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED = 0x25,
79 	SPDK_SCSI_ASC_WRITE_PROTECTED = 0x27,
80 	SPDK_SCSI_ASC_CAPACITY_DATA_HAS_CHANGED = 0x2a,
81 	SPDK_SCSI_ASC_FORMAT_COMMAND_FAILED = 0x31,
82 	SPDK_SCSI_ASC_SAVING_PARAMETERS_NOT_SUPPORTED = 0x39,
83 	SPDK_SCSI_ASC_INTERNAL_TARGET_FAILURE = 0x44,
84 };
85 
86 enum spdk_scsi_ascq {
87 	SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE = 0x00,
88 	SPDK_SCSI_ASCQ_BECOMING_READY = 0x01,
89 	SPDK_SCSI_ASCQ_FORMAT_COMMAND_FAILED = 0x01,
90 	SPDK_SCSI_ASCQ_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x01,
91 	SPDK_SCSI_ASCQ_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x02,
92 	SPDK_SCSI_ASCQ_NO_ACCESS_RIGHTS = 0x02,
93 	SPDK_SCSI_ASCQ_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x03,
94 	SPDK_SCSI_ASCQ_POWER_LOSS_EXPECTED = 0x08,
95 	SPDK_SCSI_ASCQ_INVALID_LU_IDENTIFIER = 0x09,
96 	SPDK_SCSI_ASCQ_CAPACITY_DATA_HAS_CHANGED = 0x09,
97 };
98 
99 enum spdk_spc_opcode {
100 	/* SPC3 related */
101 	SPDK_SPC_ACCESS_CONTROL_IN = 0x86,
102 	SPDK_SPC_ACCESS_CONTROL_OUT = 0x87,
103 	SPDK_SPC_EXTENDED_COPY = 0x83,
104 	SPDK_SPC_INQUIRY = 0x12,
105 	SPDK_SPC_LOG_SELECT = 0x4c,
106 	SPDK_SPC_LOG_SENSE = 0x4d,
107 	SPDK_SPC_MODE_SELECT_6 = 0x15,
108 	SPDK_SPC_MODE_SELECT_10 = 0x55,
109 	SPDK_SPC_MODE_SENSE_6 = 0x1a,
110 	SPDK_SPC_MODE_SENSE_10 = 0x5a,
111 	SPDK_SPC_PERSISTENT_RESERVE_IN = 0x5e,
112 	SPDK_SPC_PERSISTENT_RESERVE_OUT = 0x5f,
113 	SPDK_SPC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,
114 	SPDK_SPC_READ_ATTRIBUTE = 0x8c,
115 	SPDK_SPC_READ_BUFFER = 0x3c,
116 	SPDK_SPC_RECEIVE_COPY_RESULTS = 0x84,
117 	SPDK_SPC_RECEIVE_DIAGNOSTIC_RESULTS = 0x1c,
118 	SPDK_SPC_REPORT_LUNS = 0xa0,
119 	SPDK_SPC_REQUEST_SENSE = 0x03,
120 	SPDK_SPC_SEND_DIAGNOSTIC = 0x1d,
121 	SPDK_SPC_TEST_UNIT_READY = 0x00,
122 	SPDK_SPC_WRITE_ATTRIBUTE = 0x8d,
123 	SPDK_SPC_WRITE_BUFFER = 0x3b,
124 
125 	SPDK_SPC_SERVICE_ACTION_IN_12 = 0xab,
126 	SPDK_SPC_SERVICE_ACTION_OUT_12 = 0xa9,
127 	SPDK_SPC_SERVICE_ACTION_IN_16 = 0x9e,
128 	SPDK_SPC_SERVICE_ACTION_OUT_16 = 0x9f,
129 
130 	SPDK_SPC_VARIABLE_LENGTH = 0x7f,
131 
132 	SPDK_SPC_MO_CHANGE_ALIASES = 0x0b,
133 	SPDK_SPC_MO_SET_DEVICE_IDENTIFIER = 0x06,
134 	SPDK_SPC_MO_SET_PRIORITY = 0x0e,
135 	SPDK_SPC_MO_SET_TARGET_PORT_GROUPS = 0x0a,
136 	SPDK_SPC_MO_SET_TIMESTAMP = 0x0f,
137 	SPDK_SPC_MI_REPORT_ALIASES = 0x0b,
138 	SPDK_SPC_MI_REPORT_DEVICE_IDENTIFIER = 0x05,
139 	SPDK_SPC_MI_REPORT_PRIORITY = 0x0e,
140 	SPDK_SPC_MI_REPORT_SUPPORTED_OPERATION_CODES = 0x0c,
141 	SPDK_SPC_MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS = 0x0d,
142 	SPDK_SPC_MI_REPORT_TARGET_PORT_GROUPS = 0x0a,
143 	SPDK_SPC_MI_REPORT_TIMESTAMP = 0x0f,
144 
145 	/* SPC2 related (Obsolete) */
146 	SPDK_SPC2_RELEASE_6 = 0x17,
147 	SPDK_SPC2_RELEASE_10 = 0x57,
148 	SPDK_SPC2_RESERVE_6 = 0x16,
149 	SPDK_SPC2_RESERVE_10 = 0x56,
150 };
151 
152 enum spdk_scc_opcode {
153 	SPDK_SCC_MAINTENANCE_IN = 0xa3,
154 	SPDK_SCC_MAINTENANCE_OUT = 0xa4,
155 };
156 
157 enum spdk_sbc_opcode {
158 	SPDK_SBC_COMPARE_AND_WRITE = 0x89,
159 	SPDK_SBC_FORMAT_UNIT = 0x04,
160 	SPDK_SBC_GET_LBA_STATUS = 0x0012009e,
161 	SPDK_SBC_ORWRITE_16 = 0x8b,
162 	SPDK_SBC_PRE_FETCH_10 = 0x34,
163 	SPDK_SBC_PRE_FETCH_16 = 0x90,
164 	SPDK_SBC_READ_6 = 0x08,
165 	SPDK_SBC_READ_10 = 0x28,
166 	SPDK_SBC_READ_12 = 0xa8,
167 	SPDK_SBC_READ_16 = 0x88,
168 	SPDK_SBC_READ_ATTRIBUTE = 0x8c,
169 	SPDK_SBC_READ_BUFFER = 0x3c,
170 	SPDK_SBC_READ_CAPACITY_10 = 0x25,
171 	SPDK_SBC_READ_DEFECT_DATA_10 = 0x37,
172 	SPDK_SBC_READ_DEFECT_DATA_12 = 0xb7,
173 	SPDK_SBC_READ_LONG_10 = 0x3e,
174 	SPDK_SBC_REASSIGN_BLOCKS = 0x07,
175 	SPDK_SBC_SANITIZE = 0x48,
176 	SPDK_SBC_START_STOP_UNIT = 0x1b,
177 	SPDK_SBC_SYNCHRONIZE_CACHE_10 = 0x35,
178 	SPDK_SBC_SYNCHRONIZE_CACHE_16 = 0x91,
179 	SPDK_SBC_UNMAP = 0x42,
180 	SPDK_SBC_VERIFY_10 = 0x2f,
181 	SPDK_SBC_VERIFY_12 = 0xaf,
182 	SPDK_SBC_VERIFY_16 = 0x8f,
183 	SPDK_SBC_WRITE_6 = 0x0a,
184 	SPDK_SBC_WRITE_10 = 0x2a,
185 	SPDK_SBC_WRITE_12 = 0xaa,
186 	SPDK_SBC_WRITE_16 = 0x8a,
187 	SPDK_SBC_WRITE_AND_VERIFY_10 = 0x2e,
188 	SPDK_SBC_WRITE_AND_VERIFY_12 = 0xae,
189 	SPDK_SBC_WRITE_AND_VERIFY_16 = 0x8e,
190 	SPDK_SBC_WRITE_LONG_10 = 0x3f,
191 	SPDK_SBC_WRITE_SAME_10 = 0x41,
192 	SPDK_SBC_WRITE_SAME_16 = 0x93,
193 	SPDK_SBC_XDREAD_10 = 0x52,
194 	SPDK_SBC_XDWRITE_10 = 0x50,
195 	SPDK_SBC_XDWRITEREAD_10 = 0x53,
196 	SPDK_SBC_XPWRITE_10 = 0x51,
197 
198 	SPDK_SBC_SAI_READ_CAPACITY_16 = 0x10,
199 	SPDK_SBC_SAI_READ_LONG_16 = 0x11,
200 	SPDK_SBC_SAO_WRITE_LONG_16 = 0x11,
201 
202 	SPDK_SBC_VL_READ_32 = 0x0009,
203 	SPDK_SBC_VL_VERIFY_32 = 0x000a,
204 	SPDK_SBC_VL_WRITE_32 = 0x000b,
205 	SPDK_SBC_VL_WRITE_AND_VERIFY_32 = 0x000c,
206 	SPDK_SBC_VL_WRITE_SAME_32 = 0x000d,
207 	SPDK_SBC_VL_XDREAD_32 = 0x0003,
208 	SPDK_SBC_VL_XDWRITE_32 = 0x0004,
209 	SPDK_SBC_VL_XDWRITEREAD_32 = 0x0007,
210 	SPDK_SBC_VL_XPWRITE_32 = 0x0006,
211 };
212 
213 #define SPDK_SBC_START_STOP_UNIT_START_BIT (1 << 0)
214 
215 enum spdk_mmc_opcode {
216 	/* MMC6 */
217 	SPDK_MMC_READ_DISC_STRUCTURE = 0xad,
218 
219 	/* MMC4 */
220 	SPDK_MMC_BLANK = 0xa1,
221 	SPDK_MMC_CLOSE_TRACK_SESSION = 0x5b,
222 	SPDK_MMC_ERASE_10 = 0x2c,
223 	SPDK_MMC_FORMAT_UNIT = 0x04,
224 	SPDK_MMC_GET_CONFIGURATION = 0x46,
225 	SPDK_MMC_GET_EVENT_STATUS_NOTIFICATION = 0x4a,
226 	SPDK_MMC_GET_PERFORMANCE = 0xac,
227 	SPDK_MMC_INQUIRY = 0x12,
228 	SPDK_MMC_LOAD_UNLOAD_MEDIUM = 0xa6,
229 	SPDK_MMC_MECHANISM_STATUS = 0xbd,
230 	SPDK_MMC_MODE_SELECT_10 = 0x55,
231 	SPDK_MMC_MODE_SENSE_10 = 0x5a,
232 	SPDK_MMC_PAUSE_RESUME = 0x4b,
233 	SPDK_MMC_PLAY_AUDIO_10 = 0x45,
234 	SPDK_MMC_PLAY_AUDIO_12 = 0xa5,
235 	SPDK_MMC_PLAY_AUDIO_MSF = 0x47,
236 	SPDK_MMC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,
237 	SPDK_MMC_READ_10 = 0x28,
238 	SPDK_MMC_READ_12 = 0xa8,
239 	SPDK_MMC_READ_BUFFER = 0x3c,
240 	SPDK_MMC_READ_BUFFER_CAPACITY = 0x5c,
241 	SPDK_MMC_READ_CAPACITY = 0x25,
242 	SPDK_MMC_READ_CD = 0xbe,
243 	SPDK_MMC_READ_CD_MSF = 0xb9,
244 	SPDK_MMC_READ_DISC_INFORMATION = 0x51,
245 	SPDK_MMC_READ_DVD_STRUCTURE = 0xad,
246 	SPDK_MMC_READ_FORMAT_CAPACITIES = 0x23,
247 	SPDK_MMC_READ_SUB_CHANNEL = 0x42,
248 	SPDK_MMC_READ_TOC_PMA_ATIP = 0x43,
249 	SPDK_MMC_READ_TRACK_INFORMATION = 0x52,
250 	SPDK_MMC_REPAIR_TRACK = 0x58,
251 	SPDK_MMC_REPORT_KEY = 0xa4,
252 	SPDK_MMC_REQUEST_SENSE = 0x03,
253 	SPDK_MMC_RESERVE_TRACK = 0x53,
254 	SPDK_MMC_SCAN = 0xba,
255 	SPDK_MMC_SEEK_10 = 0x2b,
256 	SPDK_MMC_SEND_CUE_SHEET = 0x5d,
257 	SPDK_MMC_SEND_DVD_STRUCTURE = 0xbf,
258 	SPDK_MMC_SEND_KEY = 0xa3,
259 	SPDK_MMC_SEND_OPC_INFORMATION = 0x54,
260 	SPDK_MMC_SET_CD_SPEED = 0xbb,
261 	SPDK_MMC_SET_READ_AHEAD = 0xa7,
262 	SPDK_MMC_SET_STREAMING = 0xb6,
263 	SPDK_MMC_START_STOP_UNIT = 0x1b,
264 	SPDK_MMC_STOP_PLAY_SCAN = 0x4e,
265 	SPDK_MMC_SYNCHRONIZE_CACHE = 0x35,
266 	SPDK_MMC_TEST_UNIT_READY = 0x00,
267 	SPDK_MMC_VERIFY_10 = 0x2f,
268 	SPDK_MMC_WRITE_10 = 0xa2,
269 	SPDK_MMC_WRITE_12 = 0xaa,
270 	SPDK_MMC_WRITE_AND_VERIFY_10 = 0x2e,
271 	SPDK_MMC_WRITE_BUFFER = 0x3b,
272 };
273 
274 enum spdk_ssc_opcode {
275 	SPDK_SSC_ERASE_6 = 0x19,
276 	SPDK_SSC_FORMAT_MEDIUM = 0x04,
277 	SPDK_SSC_LOAD_UNLOAD = 0x1b,
278 	SPDK_SSC_LOCATE_10 = 0x2b,
279 	SPDK_SSC_LOCATE_16 = 0x92,
280 	SPDK_SSC_MOVE_MEDIUM_ATTACHED = 0xa7,
281 	SPDK_SSC_READ_6 = 0x08,
282 	SPDK_SSC_READ_BLOCK_LIMITS = 0x05,
283 	SPDK_SSC_READ_ELEMENT_STATUS_ATTACHED = 0xb4,
284 	SPDK_SSC_READ_POSITION = 0x34,
285 	SPDK_SSC_READ_REVERSE_6 = 0x0f,
286 	SPDK_SSC_RECOVER_BUFFERED_DATA = 0x14,
287 	SPDK_SSC_REPORT_DENSITY_SUPPORT = 0x44,
288 	SPDK_SSC_REWIND = 0x01,
289 	SPDK_SSC_SET_CAPACITY = 0x0b,
290 	SPDK_SSC_SPACE_6 = 0x11,
291 	SPDK_SSC_SPACE_16 = 0x91,
292 	SPDK_SSC_VERIFY_6 = 0x13,
293 	SPDK_SSC_WRITE_6 = 0x0a,
294 	SPDK_SSC_WRITE_FILEMARKS_6 = 0x10,
295 };
296 
297 enum spdk_spc_vpd {
298 	SPDK_SPC_VPD_DEVICE_IDENTIFICATION = 0x83,
299 	SPDK_SPC_VPD_EXTENDED_INQUIRY_DATA = 0x86,
300 	SPDK_SPC_VPD_MANAGEMENT_NETWORK_ADDRESSES = 0x85,
301 	SPDK_SPC_VPD_MODE_PAGE_POLICY = 0x87,
302 	SPDK_SPC_VPD_SCSI_PORTS = 0x88,
303 	SPDK_SPC_VPD_SOFTWARE_INTERFACE_IDENTIFICATION = 0x84,
304 	SPDK_SPC_VPD_SUPPORTED_VPD_PAGES = 0x00,
305 	SPDK_SPC_VPD_UNIT_SERIAL_NUMBER = 0x80,
306 	SPDK_SPC_VPD_BLOCK_LIMITS = 0xb0,
307 	SPDK_SPC_VPD_BLOCK_DEV_CHARS = 0xb1,
308 	SPDK_SPC_VPD_BLOCK_THIN_PROVISION = 0xb2,
309 };
310 
311 enum spdk_spc_peripheral_qualifier {
312 	SPDK_SPC_PERIPHERAL_QUALIFIER_CONNECTED = 0,
313 	SPDK_SPC_PERIPHERAL_QUALIFIER_NOT_CONNECTED = 1,
314 	SPDK_SPC_PERIPHERAL_QUALIFIER_NOT_CAPABLE = 3,
315 };
316 
317 enum {
318 	SPDK_SPC_PERIPHERAL_DEVICE_TYPE_DISK = 0x00,
319 	SPDK_SPC_PERIPHERAL_DEVICE_TYPE_TAPE = 0x01,
320 	SPDK_SPC_PERIPHERAL_DEVICE_TYPE_DVD = 0x05,
321 	SPDK_SPC_PERIPHERAL_DEVICE_TYPE_CHANGER = 0x08,
322 
323 	SPDK_SPC_VERSION_NONE = 0x00,
324 	SPDK_SPC_VERSION_SPC = 0x03,
325 	SPDK_SPC_VERSION_SPC2 = 0x04,
326 	SPDK_SPC_VERSION_SPC3 = 0x05,
327 	SPDK_SPC_VERSION_SPC4 = 0x06,
328 
329 	SPDK_SPC_PROTOCOL_IDENTIFIER_FC = 0x00,
330 	SPDK_SPC_PROTOCOL_IDENTIFIER_PSCSI = 0x01,
331 	SPDK_SPC_PROTOCOL_IDENTIFIER_SSA = 0x02,
332 	SPDK_SPC_PROTOCOL_IDENTIFIER_IEEE1394 = 0x03,
333 	SPDK_SPC_PROTOCOL_IDENTIFIER_RDMA = 0x04,
334 	SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI = 0x05,
335 	SPDK_SPC_PROTOCOL_IDENTIFIER_SAS = 0x06,
336 	SPDK_SPC_PROTOCOL_IDENTIFIER_ADT = 0x07,
337 	SPDK_SPC_PROTOCOL_IDENTIFIER_ATA = 0x08,
338 
339 	SPDK_SPC_VPD_CODE_SET_BINARY = 0x01,
340 	SPDK_SPC_VPD_CODE_SET_ASCII = 0x02,
341 	SPDK_SPC_VPD_CODE_SET_UTF8 = 0x03,
342 
343 	SPDK_SPC_VPD_ASSOCIATION_LOGICAL_UNIT = 0x00,
344 	SPDK_SPC_VPD_ASSOCIATION_TARGET_PORT = 0x01,
345 	SPDK_SPC_VPD_ASSOCIATION_TARGET_DEVICE = 0x02,
346 
347 	SPDK_SPC_VPD_IDENTIFIER_TYPE_VENDOR_SPECIFIC = 0x00,
348 	SPDK_SPC_VPD_IDENTIFIER_TYPE_T10_VENDOR_ID = 0x01,
349 	SPDK_SPC_VPD_IDENTIFIER_TYPE_EUI64 = 0x02,
350 	SPDK_SPC_VPD_IDENTIFIER_TYPE_NAA = 0x03,
351 	SPDK_SPC_VPD_IDENTIFIER_TYPE_RELATIVE_TARGET_PORT = 0x04,
352 	SPDK_SPC_VPD_IDENTIFIER_TYPE_TARGET_PORT_GROUP = 0x05,
353 	SPDK_SPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP = 0x06,
354 	SPDK_SPC_VPD_IDENTIFIER_TYPE_MD5_LOGICAL_UNIT = 0x07,
355 	SPDK_SPC_VPD_IDENTIFIER_TYPE_SCSI_NAME = 0x08,
356 };
357 
358 struct spdk_scsi_cdb_inquiry {
359 	uint8_t opcode;
360 	uint8_t evpd;
361 	uint8_t page_code;
362 	uint8_t alloc_len[2];
363 	uint8_t control;
364 };
365 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_cdb_inquiry) == 6, "incorrect CDB size");
366 
367 struct spdk_scsi_cdb_inquiry_data {
368 	uint8_t peripheral_device_type : 5;
369 	uint8_t peripheral_qualifier : 3;
370 	uint8_t rmb;
371 	uint8_t version;
372 	uint8_t response;
373 	uint8_t add_len;
374 	uint8_t flags;
375 	uint8_t flags2;
376 	uint8_t flags3;
377 	uint8_t t10_vendor_id[8];
378 	uint8_t product_id[16];
379 	uint8_t product_rev[4];
380 	uint8_t vendor[20];
381 	uint8_t ius;
382 	uint8_t reserved;
383 	uint8_t desc[];
384 };
385 
386 struct spdk_scsi_vpd_page {
387 	uint8_t peripheral_device_type : 5;
388 	uint8_t peripheral_qualifier : 3;
389 	uint8_t page_code;
390 	uint8_t alloc_len[2];
391 	uint8_t params[];
392 };
393 
394 #define SPDK_SCSI_VEXT_REF_CHK		0x01
395 #define SPDK_SCSI_VEXT_APP_CHK		0x02
396 #define SPDK_SCSI_VEXT_GRD_CHK		0x04
397 #define SPDK_SCSI_VEXT_SIMPSUP		0x01
398 #define SPDK_SCSI_VEXT_ORDSUP		0x02
399 #define SPDK_SCSI_VEXT_HEADSUP		0x04
400 #define SPDK_SCSI_VEXT_PRIOR_SUP	0x08
401 #define SPDK_SCSI_VEXT_GROUP_SUP	0x10
402 #define SPDK_SCSI_VEXT_UASK_SUP		0x20
403 #define SPDK_SCSI_VEXT_V_SUP		0x01
404 #define SPDK_SCSI_VEXT_NV_SUP		0x02
405 #define SPDK_SCSI_VEXT_CRD_SUP		0x04
406 #define SPDK_SCSI_VEXT_WU_SUP		0x08
407 
408 struct spdk_scsi_vpd_ext_inquiry {
409 	uint8_t peripheral;
410 	uint8_t page_code;
411 	uint8_t alloc_len[2];
412 	uint8_t check;
413 	uint8_t sup;
414 	uint8_t sup2;
415 	uint8_t luiclr;
416 	uint8_t cbcs;
417 	uint8_t micro_dl;
418 	uint8_t reserved[54];
419 };
420 
421 #define SPDK_SPC_VPD_DESIG_PIV	0x80
422 
423 /* designation descriptor */
424 struct spdk_scsi_desig_desc {
425 	uint8_t code_set	: 4;
426 	uint8_t protocol_id	: 4;
427 	uint8_t type		: 4;
428 	uint8_t association	: 2;
429 	uint8_t reserved0	: 1;
430 	uint8_t piv		: 1;
431 	uint8_t reserved1;
432 	uint8_t	len;
433 	uint8_t desig[];
434 };
435 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_desig_desc) == 4, "Invalid size");
436 
437 /* mode page policy descriptor */
438 struct spdk_scsi_mpage_policy_desc {
439 	uint8_t page_code;
440 	uint8_t sub_page_code;
441 	uint8_t policy;
442 	uint8_t reserved;
443 };
444 
445 /* target port descriptor */
446 struct spdk_scsi_tgt_port_desc {
447 	uint8_t code_set;
448 	uint8_t desig_type;
449 	uint8_t reserved;
450 	uint8_t	len;
451 	uint8_t designator[];
452 };
453 
454 /* SCSI port designation descriptor */
455 struct spdk_scsi_port_desc {
456 	uint16_t reserved;
457 	uint16_t rel_port_id;
458 	uint16_t reserved2;
459 	uint16_t init_port_len;
460 	uint16_t init_port_id;
461 	uint16_t reserved3;
462 	uint16_t tgt_desc_len;
463 	uint8_t tgt_desc[];
464 };
465 
466 /* iSCSI initiator port TransportID header */
467 struct spdk_scsi_iscsi_transport_id {
468 	uint8_t protocol_id : 4;
469 	uint8_t reserved1   : 2;
470 	uint8_t format      : 2;
471 	uint8_t reserved2;
472 	uint16_t additional_len;
473 	uint8_t name[];
474 };
475 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_iscsi_transport_id) == 4, "Incorrect size");
476 
477 /* SCSI UNMAP block descriptor */
478 struct spdk_scsi_unmap_bdesc {
479 	/* UNMAP LOGICAL BLOCK ADDRESS */
480 	uint64_t lba;
481 
482 	/* NUMBER OF LOGICAL BLOCKS */
483 	uint32_t block_count;
484 
485 	/* RESERVED */
486 	uint32_t reserved;
487 };
488 
489 /* SCSI Persistent Reserve In action codes */
490 enum spdk_scsi_pr_in_action_code {
491 	/* Read all registered reservation keys */
492 	SPDK_SCSI_PR_IN_READ_KEYS		= 0x00,
493 	/* Read current persistent reservations */
494 	SPDK_SCSI_PR_IN_READ_RESERVATION	= 0x01,
495 	/* Return capabilities information */
496 	SPDK_SCSI_PR_IN_REPORT_CAPABILITIES	= 0x02,
497 	/* Read all registrations and persistent reservations */
498 	SPDK_SCSI_PR_IN_READ_FULL_STATUS	= 0x03,
499 	/* 0x04h - 0x1fh Reserved */
500 };
501 
502 enum spdk_scsi_pr_scope_code {
503 	/* Persistent reservation applies to full logical unit */
504 	SPDK_SCSI_PR_LU_SCOPE			= 0x00,
505 };
506 
507 /* SCSI Persistent Reservation type codes */
508 enum spdk_scsi_pr_type_code {
509 	/* Write Exclusive */
510 	SPDK_SCSI_PR_WRITE_EXCLUSIVE		= 0x01,
511 	/* Exclusive Access */
512 	SPDK_SCSI_PR_EXCLUSIVE_ACCESS		= 0x03,
513 	/* Write Exclusive - Registrants Only */
514 	SPDK_SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY	= 0x05,
515 	/* Exclusive Access - Registrants Only */
516 	SPDK_SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY	= 0x06,
517 	/* Write Exclusive - All Registrants */
518 	SPDK_SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS	= 0x07,
519 	/* Exclusive Access - All Registrants */
520 	SPDK_SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS	= 0x08,
521 };
522 
523 /* SCSI Persistent Reserve In header for
524  * Read Keys, Read Reservation, Read Full Status
525  */
526 struct spdk_scsi_pr_in_read_header {
527 	/* persistent reservation generation */
528 	uint32_t pr_generation;
529 	uint32_t additional_len;
530 };
531 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_read_header) == 8, "Incorrect size");
532 
533 /* SCSI Persistent Reserve In read keys data */
534 struct spdk_scsi_pr_in_read_keys_data {
535 	struct spdk_scsi_pr_in_read_header header;
536 	/* reservation key list */
537 	uint64_t rkeys[];
538 };
539 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_read_keys_data) == 8, "Incorrect size");
540 
541 /* SCSI Persistent Reserve In read reservations data */
542 struct spdk_scsi_pr_in_read_reservations_data {
543 	/* Fixed 0x10 with reservation and 0 for no reservation */
544 	struct spdk_scsi_pr_in_read_header header;
545 	/* reservation key */
546 	uint64_t rkey;
547 	uint32_t obsolete1;
548 	uint8_t reserved;
549 	uint8_t type  : 4;
550 	uint8_t scope : 4;
551 	uint16_t obsolete2;
552 };
553 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_read_reservations_data) == 24, "Incorrect size");
554 
555 /* SCSI Persistent Reserve In report capabilities data */
556 struct spdk_scsi_pr_in_report_capabilities_data {
557 	/* Fixed value 0x8 */
558 	uint16_t length;
559 
560 	/* Persist through power loss capable */
561 	uint8_t ptpl_c    : 1;
562 	uint8_t reserved1 : 1;
563 	/* All target ports capable */
564 	uint8_t atp_c     : 1;
565 	/* Specify initiator port capable */
566 	uint8_t sip_c     : 1;
567 	/* Compatible reservation handing bit to indicate
568 	 * SPC-2 reserve/release is supported
569 	 */
570 	uint8_t crh       : 1;
571 	uint8_t reserved2 : 3;
572 	/* Persist through power loss activated */
573 	uint8_t ptpl_a    : 1;
574 	uint8_t reserved3 : 6;
575 	/* Type mask valid */
576 	uint8_t tmv       : 1;
577 
578 	/* Type mask format */
579 	uint8_t reserved4 : 1;
580 	/* Write Exclusive */
581 	uint8_t wr_ex     : 1;
582 	uint8_t reserved5 : 1;
583 	/* Exclusive Access */
584 	uint8_t ex_ac     : 1;
585 	uint8_t reserved6 : 1;
586 	/* Write Exclusive - Registrants Only */
587 	uint8_t wr_ex_ro  : 1;
588 	/* Exclusive Access - Registrants Only */
589 	uint8_t ex_ac_ro  : 1;
590 	/* Write Exclusive - All Registrants */
591 	uint8_t wr_ex_ar  : 1;
592 	/* Exclusive Access - All Registrants */
593 	uint8_t ex_ac_ar  : 1;
594 	uint8_t reserved7 : 7;
595 
596 	uint8_t reserved8[2];
597 };
598 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_report_capabilities_data) == 8, "Incorrect size");
599 
600 /* SCSI Persistent Reserve In full status descriptor */
601 struct spdk_scsi_pr_in_full_status_desc {
602 	/* Reservation key */
603 	uint64_t rkey;
604 	uint8_t reserved1[4];
605 
606 	/* 0 - Registrant only
607 	 * 1 - Registrant and reservation holder
608 	 */
609 	uint8_t r_holder  : 1;
610 	/* All target ports */
611 	uint8_t all_tg_pt : 1;
612 	uint8_t reserved2 : 6;
613 
614 	/* Reservation type */
615 	uint8_t type      : 4;
616 	/* Set to LU_SCOPE */
617 	uint8_t scope     : 4;
618 
619 	uint8_t reserved3[4];
620 	uint16_t relative_target_port_id;
621 	/* Size of TransportID */
622 	uint32_t desc_len;
623 
624 	uint8_t transport_id[];
625 };
626 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_full_status_desc) == 24, "Incorrect size");
627 
628 /* SCSI Persistent Reserve In full status data */
629 struct spdk_scsi_pr_in_full_status_data {
630 	struct spdk_scsi_pr_in_read_header header;
631 	/* Full status descriptors */
632 	struct spdk_scsi_pr_in_full_status_desc desc_list[];
633 };
634 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_in_full_status_data) == 8, "Incorrect size");
635 
636 /* SCSI Persistent Reserve Out service action codes */
637 enum spdk_scsi_pr_out_service_action_code {
638 	/* Register/unregister a reservation key */
639 	SPDK_SCSI_PR_OUT_REGISTER		= 0x00,
640 	/* Create a persistent reservation */
641 	SPDK_SCSI_PR_OUT_RESERVE		= 0x01,
642 	/* Release a persistent reservation */
643 	SPDK_SCSI_PR_OUT_RELEASE		= 0x02,
644 	/* Clear all reservation keys and persistent reservations */
645 	SPDK_SCSI_PR_OUT_CLEAR			= 0x03,
646 	/* Preempt persistent reservations and/or remove registrants */
647 	SPDK_SCSI_PR_OUT_PREEMPT		= 0x04,
648 	/* Preempt persistent reservations and or remove registrants
649 	 * and abort all tasks for all preempted I_T nexuses
650 	 */
651 	SPDK_SCSI_PR_OUT_PREEMPT_AND_ABORT	= 0x05,
652 	/* Register/unregister a reservation key based on the ignore bit */
653 	SPDK_SCSI_PR_OUT_REG_AND_IGNORE_KEY	= 0x06,
654 	/* Register a reservation key for another I_T nexus
655 	 * and move a persistent reservation to that I_T nexus
656 	 */
657 	SPDK_SCSI_PR_OUT_REG_AND_MOVE		= 0x07,
658 	/* 0x08 - 0x1f Reserved */
659 };
660 
661 /* SCSI Persistent Reserve Out parameter list */
662 struct spdk_scsi_pr_out_param_list {
663 	/* Reservation key */
664 	uint64_t rkey;
665 	/* Service action reservation key */
666 	uint64_t sa_rkey;
667 	uint8_t obsolete1[4];
668 
669 	/* Active persist through power loss */
670 	uint8_t aptpl     : 1;
671 	uint8_t reserved1 : 1;
672 	/* All target ports */
673 	uint8_t all_tg_pt : 1;
674 	/* Specify initiator ports */
675 	uint8_t spec_i_pt : 1;
676 	uint8_t reserved2 : 4;
677 
678 	uint8_t reserved3;
679 	uint16_t obsolete2;
680 
681 	uint8_t param_data[];
682 };
683 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_out_param_list) == 24, "Incorrect size");
684 
685 struct spdk_scsi_pr_out_reg_and_move_param_list {
686 	/* Reservation key */
687 	uint64_t rkey;
688 	/* Service action reservation key */
689 	uint64_t sa_rkey;
690 	uint8_t reserved1;
691 
692 	/* Active persist through power loss */
693 	uint8_t aptpl     : 1;
694 	/* Unregister */
695 	uint8_t unreg     : 1;
696 	uint8_t reserved2 : 6;
697 
698 	uint16_t relative_target_port_id;
699 	/* TransportID parameter data length */
700 	uint32_t transport_id_len;
701 	uint8_t transport_id[];
702 };
703 SPDK_STATIC_ASSERT(sizeof(struct spdk_scsi_pr_out_reg_and_move_param_list) == 24, "Incorrect size");
704 
705 /*
706  * SPC-4
707  * Table-258 SECURITY PROTOCOL field in SECURITY PROTOCOL IN command
708  */
709 #define SPDK_SCSI_SECP_INFO	0x00
710 #define SPDK_SCSI_SECP_TCG	0x01
711 
712 #define SPDK_SCSI_UNMAP_LBPU			1 << 7
713 #define SPDK_SCSI_UNMAP_LBPWS			1 << 6
714 #define SPDK_SCSI_UNMAP_LBPWS10			1 << 5
715 
716 #define SPDK_SCSI_UNMAP_FULL_PROVISIONING	0x00
717 #define SPDK_SCSI_UNMAP_RESOURCE_PROVISIONING	0x01
718 #define SPDK_SCSI_UNMAP_THIN_PROVISIONING	0x02
719 
720 #ifdef __cplusplus
721 }
722 #endif
723 
724 #endif /* SPDK_SCSI_SPEC_H */
725