build: improve pcap dependency handling
[dpdk.git] / examples / vhost_scsi / scsi_spec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 /**
6  * SCSI specification definition
7  * refer http://www.t10.org/drafts.htm#SPC_Family for SPC-3 and SBC-3
8  */
9
10 #ifndef _SCSI_SPEC_H
11 #define _SCSI_SPEC_H
12
13 #include <stdint.h>
14
15 enum scsi_group_code {
16         SCSI_6BYTE_CMD = 0x00,
17         SCSI_10BYTE_CMD = 0x20,
18         SCSI_10BYTE_CMD2 = 0x40,
19         SCSI_16BYTE_CMD = 0x80,
20         SCSI_12BYTE_CMD = 0xa0,
21 };
22
23 #define SCSI_GROUP_MASK 0xe0
24 #define SCSI_OPCODE_MASK        0x1f
25
26 enum scsi_status {
27         SCSI_STATUS_GOOD = 0x00,
28         SCSI_STATUS_CHECK_CONDITION = 0x02,
29         SCSI_STATUS_CONDITION_MET = 0x04,
30         SCSI_STATUS_BUSY = 0x08,
31         SCSI_STATUS_INTERMEDIATE = 0x10,
32         SCSI_STATUS_INTERMEDIATE_CONDITION_MET = 0x14,
33         SCSI_STATUS_RESERVATION_CONFLICT = 0x18,
34         SCSI_STATUS_Obsolete = 0x22,
35         SCSI_STATUS_TASK_SET_FULL = 0x28,
36         SCSI_STATUS_ACA_ACTIVE = 0x30,
37         SCSI_STATUS_TASK_ABORTED = 0x40,
38 };
39
40 enum scsi_sense {
41         SCSI_SENSE_NO_SENSE = 0x00,
42         SCSI_SENSE_RECOVERED_ERROR = 0x01,
43         SCSI_SENSE_NOT_READY = 0x02,
44         SCSI_SENSE_MEDIUM_ERROR = 0x03,
45         SCSI_SENSE_HARDWARE_ERROR = 0x04,
46         SCSI_SENSE_ILLEGAL_REQUEST = 0x05,
47         SCSI_SENSE_UNIT_ATTENTION = 0x06,
48         SCSI_SENSE_DATA_PROTECT = 0x07,
49         SCSI_SENSE_BLANK_CHECK = 0x08,
50         SCSI_SENSE_VENDOR_SPECIFIC = 0x09,
51         SCSI_SENSE_COPY_ABORTED = 0x0a,
52         SCSI_SENSE_ABORTED_COMMAND = 0x0b,
53         SCSI_SENSE_VOLUME_OVERFLOW = 0x0d,
54         SCSI_SENSE_MISCOMPARE = 0x0e,
55 };
56
57 enum scsi_asc {
58         SCSI_ASC_NO_ADDITIONAL_SENSE = 0x00,
59         SCSI_ASC_PERIPHERAL_DEVICE_WRITE_FAULT = 0x03,
60         SCSI_ASC_LOGICAL_UNIT_NOT_READY = 0x04,
61         SCSI_ASC_WARNING = 0x0b,
62         SCSI_ASC_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x10,
63         SCSI_ASC_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x10,
64         SCSI_ASC_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x10,
65         SCSI_ASC_UNRECOVERED_READ_ERROR = 0x11,
66         SCSI_ASC_MISCOMPARE_DURING_VERIFY_OPERATION = 0x1d,
67         SCSI_ASC_INVALID_COMMAND_OPERATION_CODE = 0x20,
68         SCSI_ASC_ACCESS_DENIED = 0x20,
69         SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE = 0x21,
70         SCSI_ASC_INVALID_FIELD_IN_CDB = 0x24,
71         SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED = 0x25,
72         SCSI_ASC_WRITE_PROTECTED = 0x27,
73         SCSI_ASC_FORMAT_COMMAND_FAILED = 0x31,
74         SCSI_ASC_INTERNAL_TARGET_FAILURE = 0x44,
75 };
76
77 enum scsi_ascq {
78         SCSI_ASCQ_CAUSE_NOT_REPORTABLE = 0x00,
79         SCSI_ASCQ_BECOMING_READY = 0x01,
80         SCSI_ASCQ_FORMAT_COMMAND_FAILED = 0x01,
81         SCSI_ASCQ_LOGICAL_BLOCK_GUARD_CHECK_FAILED = 0x01,
82         SCSI_ASCQ_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = 0x02,
83         SCSI_ASCQ_NO_ACCESS_RIGHTS = 0x02,
84         SCSI_ASCQ_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = 0x03,
85         SCSI_ASCQ_POWER_LOSS_EXPECTED = 0x08,
86         SCSI_ASCQ_INVALID_LU_IDENTIFIER = 0x09,
87 };
88
89 enum spc_opcode {
90         /* SPC3 related */
91         SPC_ACCESS_CONTROL_IN = 0x86,
92         SPC_ACCESS_CONTROL_OUT = 0x87,
93         SPC_EXTENDED_COPY = 0x83,
94         SPC_INQUIRY = 0x12,
95         SPC_LOG_SELECT = 0x4c,
96         SPC_LOG_SENSE = 0x4d,
97         SPC_MODE_SELECT_6 = 0x15,
98         SPC_MODE_SELECT_10 = 0x55,
99         SPC_MODE_SENSE_6 = 0x1a,
100         SPC_MODE_SENSE_10 = 0x5a,
101         SPC_PERSISTENT_RESERVE_IN = 0x5e,
102         SPC_PERSISTENT_RESERVE_OUT = 0x5f,
103         SPC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,
104         SPC_READ_ATTRIBUTE = 0x8c,
105         SPC_READ_BUFFER = 0x3c,
106         SPC_RECEIVE_COPY_RESULTS = 0x84,
107         SPC_RECEIVE_DIAGNOSTIC_RESULTS = 0x1c,
108         SPC_REPORT_LUNS = 0xa0,
109         SPC_REQUEST_SENSE = 0x03,
110         SPC_SEND_DIAGNOSTIC = 0x1d,
111         SPC_TEST_UNIT_READY = 0x00,
112         SPC_WRITE_ATTRIBUTE = 0x8d,
113         SPC_WRITE_BUFFER = 0x3b,
114
115         SPC_SERVICE_ACTION_IN_12 = 0xab,
116         SPC_SERVICE_ACTION_OUT_12 = 0xa9,
117         SPC_SERVICE_ACTION_IN_16 = 0x9e,
118         SPC_SERVICE_ACTION_OUT_16 = 0x9f,
119
120         SPC_VARIABLE_LENGTH = 0x7f,
121
122         SPC_MO_CHANGE_ALIASES = 0x0b,
123         SPC_MO_SET_DEVICE_IDENTIFIER = 0x06,
124         SPC_MO_SET_PRIORITY = 0x0e,
125         SPC_MO_SET_TARGET_PORT_GROUPS = 0x0a,
126         SPC_MO_SET_TIMESTAMP = 0x0f,
127         SPC_MI_REPORT_ALIASES = 0x0b,
128         SPC_MI_REPORT_DEVICE_IDENTIFIER = 0x05,
129         SPC_MI_REPORT_PRIORITY = 0x0e,
130         SPC_MI_REPORT_SUPPORTED_OPERATION_CODES = 0x0c,
131         SPC_MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS = 0x0d,
132         SPC_MI_REPORT_TARGET_PORT_GROUPS = 0x0a,
133         SPC_MI_REPORT_TIMESTAMP = 0x0f,
134
135         /* SPC2 related (Obsolete) */
136         SPC2_RELEASE_6 = 0x17,
137         SPC2_RELEASE_10 = 0x57,
138         SPC2_RESERVE_6 = 0x16,
139         SPC2_RESERVE_10 = 0x56,
140 };
141
142 enum scc_opcode {
143         SCC_MAINTENANCE_IN = 0xa3,
144         SCC_MAINTENANCE_OUT = 0xa4,
145 };
146
147 enum sbc_opcode {
148         SBC_COMPARE_AND_WRITE = 0x89,
149         SBC_FORMAT_UNIT = 0x04,
150         SBC_GET_LBA_STATUS = 0x0012009e,
151         SBC_ORWRITE_16 = 0x8b,
152         SBC_PRE_FETCH_10 = 0x34,
153         SBC_PRE_FETCH_16 = 0x90,
154         SBC_READ_6 = 0x08,
155         SBC_READ_10 = 0x28,
156         SBC_READ_12 = 0xa8,
157         SBC_READ_16 = 0x88,
158         SBC_READ_ATTRIBUTE = 0x8c,
159         SBC_READ_BUFFER = 0x3c,
160         SBC_READ_CAPACITY_10 = 0x25,
161         SBC_READ_DEFECT_DATA_10 = 0x37,
162         SBC_READ_DEFECT_DATA_12 = 0xb7,
163         SBC_READ_LONG_10 = 0x3e,
164         SBC_REASSIGN_BLOCKS = 0x07,
165         SBC_SANITIZE = 0x48,
166         SBC_START_STOP_UNIT = 0x1b,
167         SBC_SYNCHRONIZE_CACHE_10 = 0x35,
168         SBC_SYNCHRONIZE_CACHE_16 = 0x91,
169         SBC_UNMAP = 0x42,
170         SBC_VERIFY_10 = 0x2f,
171         SBC_VERIFY_12 = 0xaf,
172         SBC_VERIFY_16 = 0x8f,
173         SBC_WRITE_6 = 0x0a,
174         SBC_WRITE_10 = 0x2a,
175         SBC_WRITE_12 = 0xaa,
176         SBC_WRITE_16 = 0x8a,
177         SBC_WRITE_AND_VERIFY_10 = 0x2e,
178         SBC_WRITE_AND_VERIFY_12 = 0xae,
179         SBC_WRITE_AND_VERIFY_16 = 0x8e,
180         SBC_WRITE_LONG_10 = 0x3f,
181         SBC_WRITE_SAME_10 = 0x41,
182         SBC_WRITE_SAME_16 = 0x93,
183         SBC_XDREAD_10 = 0x52,
184         SBC_XDWRITE_10 = 0x50,
185         SBC_XDWRITEREAD_10 = 0x53,
186         SBC_XPWRITE_10 = 0x51,
187
188         SBC_SAI_READ_CAPACITY_16 = 0x10,
189         SBC_SAI_READ_LONG_16 = 0x11,
190         SBC_SAO_WRITE_LONG_16 = 0x11,
191
192         SBC_VL_READ_32 = 0x0009,
193         SBC_VL_VERIFY_32 = 0x000a,
194         SBC_VL_WRITE_32 = 0x000b,
195         SBC_VL_WRITE_AND_VERIFY_32 = 0x000c,
196         SBC_VL_WRITE_SAME_32 = 0x000d,
197         SBC_VL_XDREAD_32 = 0x0003,
198         SBC_VL_XDWRITE_32 = 0x0004,
199         SBC_VL_XDWRITEREAD_32 = 0x0007,
200         SBC_VL_XPWRITE_32 = 0x0006,
201 };
202
203 enum mmc_opcode {
204         /* MMC6 */
205         MMC_READ_DISC_STRUCTURE = 0xad,
206
207         /* MMC4 */
208         MMC_BLANK = 0xa1,
209         MMC_CLOSE_TRACK_SESSION = 0x5b,
210         MMC_ERASE_10 = 0x2c,
211         MMC_FORMAT_UNIT = 0x04,
212         MMC_GET_CONFIGURATION = 0x46,
213         MMC_GET_EVENT_STATUS_NOTIFICATION = 0x4a,
214         MMC_GET_PERFORMANCE = 0xac,
215         MMC_INQUIRY = 0x12,
216         MMC_LOAD_UNLOAD_MEDIUM = 0xa6,
217         MMC_MECHANISM_STATUS = 0xbd,
218         MMC_MODE_SELECT_10 = 0x55,
219         MMC_MODE_SENSE_10 = 0x5a,
220         MMC_PAUSE_RESUME = 0x4b,
221         MMC_PLAY_AUDIO_10 = 0x45,
222         MMC_PLAY_AUDIO_12 = 0xa5,
223         MMC_PLAY_AUDIO_MSF = 0x47,
224         MMC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,
225         MMC_READ_10 = 0x28,
226         MMC_READ_12 = 0xa8,
227         MMC_READ_BUFFER = 0x3c,
228         MMC_READ_BUFFER_CAPACITY = 0x5c,
229         MMC_READ_CAPACITY = 0x25,
230         MMC_READ_CD = 0xbe,
231         MMC_READ_CD_MSF = 0xb9,
232         MMC_READ_DISC_INFORMATION = 0x51,
233         MMC_READ_DVD_STRUCTURE = 0xad,
234         MMC_READ_FORMAT_CAPACITIES = 0x23,
235         MMC_READ_SUB_CHANNEL = 0x42,
236         MMC_READ_TOC_PMA_ATIP = 0x43,
237         MMC_READ_TRACK_INFORMATION = 0x52,
238         MMC_REPAIR_TRACK = 0x58,
239         MMC_REPORT_KEY = 0xa4,
240         MMC_REQUEST_SENSE = 0x03,
241         MMC_RESERVE_TRACK = 0x53,
242         MMC_SCAN = 0xba,
243         MMC_SEEK_10 = 0x2b,
244         MMC_SEND_CUE_SHEET = 0x5d,
245         MMC_SEND_DVD_STRUCTURE = 0xbf,
246         MMC_SEND_KEY = 0xa3,
247         MMC_SEND_OPC_INFORMATION = 0x54,
248         MMC_SET_CD_SPEED = 0xbb,
249         MMC_SET_READ_AHEAD = 0xa7,
250         MMC_SET_STREAMING = 0xb6,
251         MMC_START_STOP_UNIT = 0x1b,
252         MMC_STOP_PLAY_SCAN = 0x4e,
253         MMC_SYNCHRONIZE_CACHE = 0x35,
254         MMC_TEST_UNIT_READY = 0x00,
255         MMC_VERIFY_10 = 0x2f,
256         MMC_WRITE_10 = 0xa2,
257         MMC_WRITE_12 = 0xaa,
258         MMC_WRITE_AND_VERIFY_10 = 0x2e,
259         MMC_WRITE_BUFFER = 0x3b,
260 };
261
262 enum ssc_opcode {
263         SSC_ERASE_6 = 0x19,
264         SSC_FORMAT_MEDIUM = 0x04,
265         SSC_LOAD_UNLOAD = 0x1b,
266         SSC_LOCATE_10 = 0x2b,
267         SSC_LOCATE_16 = 0x92,
268         SSC_MOVE_MEDIUM_ATTACHED = 0xa7,
269         SSC_READ_6 = 0x08,
270         SSC_READ_BLOCK_LIMITS = 0x05,
271         SSC_READ_ELEMENT_STATUS_ATTACHED = 0xb4,
272         SSC_READ_POSITION = 0x34,
273         SSC_READ_REVERSE_6 = 0x0f,
274         SSC_RECOVER_BUFFERED_DATA = 0x14,
275         SSC_REPORT_DENSITY_SUPPORT = 0x44,
276         SSC_REWIND = 0x01,
277         SSC_SET_CAPACITY = 0x0b,
278         SSC_SPACE_6 = 0x11,
279         SSC_SPACE_16 = 0x91,
280         SSC_VERIFY_6 = 0x13,
281         SSC_WRITE_6 = 0x0a,
282         SSC_WRITE_FILEMARKS_6 = 0x10,
283 };
284
285 enum spc_vpd {
286         SPC_VPD_DEVICE_IDENTIFICATION = 0x83,
287         SPC_VPD_EXTENDED_INQUIRY_DATA = 0x86,
288         SPC_VPD_MANAGEMENT_NETWORK_ADDRESSES = 0x85,
289         SPC_VPD_MODE_PAGE_POLICY = 0x87,
290         SPC_VPD_SCSI_PORTS = 0x88,
291         SPC_VPD_SOFTWARE_INTERFACE_IDENTIFICATION = 0x84,
292         SPC_VPD_SUPPORTED_VPD_PAGES = 0x00,
293         SPC_VPD_UNIT_SERIAL_NUMBER = 0x80,
294         SPC_VPD_BLOCK_LIMITS = 0xb0,
295         SPC_VPD_BLOCK_DEV_CHARS = 0xb1,
296         SPC_VPD_BLOCK_THIN_PROVISION = 0xb2,
297 };
298
299 enum {
300         SPC_PERIPHERAL_DEVICE_TYPE_DISK = 0x00,
301         SPC_PERIPHERAL_DEVICE_TYPE_TAPE = 0x01,
302         SPC_PERIPHERAL_DEVICE_TYPE_DVD = 0x05,
303         SPC_PERIPHERAL_DEVICE_TYPE_CHANGER = 0x08,
304
305         SPC_VERSION_NONE = 0x00,
306         SPC_VERSION_SPC = 0x03,
307         SPC_VERSION_SPC2 = 0x04,
308         SPC_VERSION_SPC3 = 0x05,
309         SPC_VERSION_SPC4 = 0x06,
310
311         SPC_PROTOCOL_IDENTIFIER_FC = 0x00,
312         SPC_PROTOCOL_IDENTIFIER_PSCSI = 0x01,
313         SPC_PROTOCOL_IDENTIFIER_SSA = 0x02,
314         SPC_PROTOCOL_IDENTIFIER_IEEE1394 = 0x03,
315         SPC_PROTOCOL_IDENTIFIER_RDMA = 0x04,
316         SPC_PROTOCOL_IDENTIFIER_ISCSI = 0x05,
317         SPC_PROTOCOL_IDENTIFIER_SAS = 0x06,
318         SPC_PROTOCOL_IDENTIFIER_ADT = 0x07,
319         SPC_PROTOCOL_IDENTIFIER_ATA = 0x08,
320
321         SPC_VPD_CODE_SET_BINARY = 0x01,
322         SPC_VPD_CODE_SET_ASCII = 0x02,
323         SPC_VPD_CODE_SET_UTF8 = 0x03,
324
325         SPC_VPD_ASSOCIATION_LOGICAL_UNIT = 0x00,
326         SPC_VPD_ASSOCIATION_TARGET_PORT = 0x01,
327         SPC_VPD_ASSOCIATION_TARGET_DEVICE = 0x02,
328
329         SPC_VPD_IDENTIFIER_TYPE_VENDOR_SPECIFIC = 0x00,
330         SPC_VPD_IDENTIFIER_TYPE_T10_VENDOR_ID = 0x01,
331         SPC_VPD_IDENTIFIER_TYPE_EUI64 = 0x02,
332         SPC_VPD_IDENTIFIER_TYPE_NAA = 0x03,
333         SPC_VPD_IDENTIFIER_TYPE_RELATIVE_TARGET_PORT = 0x04,
334         SPC_VPD_IDENTIFIER_TYPE_TARGET_PORT_GROUP = 0x05,
335         SPC_VPD_IDENTIFIER_TYPE_LOGICAL_UNIT_GROUP = 0x06,
336         SPC_VPD_IDENTIFIER_TYPE_MD5_LOGICAL_UNIT = 0x07,
337         SPC_VPD_IDENTIFIER_TYPE_SCSI_NAME = 0x08,
338 };
339
340 struct scsi_cdb_inquiry {
341         uint8_t opcode;
342         uint8_t evpd;
343         uint8_t page_code;
344         uint16_t alloc_len;
345         uint8_t control;
346 };
347
348 struct scsi_cdb_inquiry_data {
349         uint8_t peripheral;
350         uint8_t rmb;
351         uint8_t version;
352         uint8_t response;
353         uint8_t add_len;
354         uint8_t flags;
355         uint8_t flags2;
356         uint8_t flags3;
357         uint8_t t10_vendor_id[8];
358         uint8_t product_id[16];
359         uint8_t product_rev[4];
360         uint8_t vendor[20];
361         uint8_t ius;
362         uint8_t reserved;
363         uint8_t desc[];
364 };
365
366 struct scsi_vpd_page {
367         uint8_t peripheral;
368         uint8_t page_code;
369         uint16_t alloc_len;
370         uint8_t params[32];
371 };
372
373 #define SCSI_VEXT_REF_CHK               0x01
374 #define SCSI_VEXT_APP_CHK               0x02
375 #define SCSI_VEXT_GRD_CHK               0x04
376 #define SCSI_VEXT_SIMPSUP               0x01
377 #define SCSI_VEXT_ORDSUP                0x02
378 #define SCSI_VEXT_HEADSUP               0x04
379 #define SCSI_VEXT_PRIOR_SUP     0x08
380 #define SCSI_VEXT_GROUP_SUP     0x10
381 #define SCSI_VEXT_UASK_SUP              0x20
382 #define SCSI_VEXT_V_SUP         0x01
383 #define SCSI_VEXT_NV_SUP                0x02
384 #define SCSI_VEXT_CRD_SUP               0x04
385 #define SCSI_VEXT_WU_SUP                0x08
386
387 struct scsi_vpd_ext_inquiry {
388         uint8_t peripheral;
389         uint8_t page_code;
390         uint16_t alloc_len;
391         uint8_t check;
392         uint8_t sup;
393         uint8_t sup2;
394         uint8_t luiclr;
395         uint8_t cbcs;
396         uint8_t micro_dl;
397         uint8_t reserved[54];
398 };
399
400 #define SPC_VPD_DESIG_PIV       0x80
401
402 /* designation descriptor */
403 struct scsi_desig_desc {
404         uint8_t code_set        : 4;
405         uint8_t protocol_id     : 4;
406         uint8_t type            : 4;
407         uint8_t association     : 2;
408         uint8_t reserved0       : 1;
409         uint8_t piv             : 1;
410         uint8_t reserved1;
411         uint8_t len;
412         uint8_t desig[];
413 };
414
415 /* mode page policy descriptor */
416 struct scsi_mpage_policy_desc {
417         uint8_t page_code;
418         uint8_t sub_page_code;
419         uint8_t policy;
420         uint8_t reserved;
421 };
422
423 /* target port descriptor */
424 struct scsi_tgt_port_desc {
425         uint8_t code_set;
426         uint8_t desig_type;
427         uint8_t reserved;
428         uint8_t len;
429         uint8_t designator[];
430 };
431
432 /* SCSI port designation descriptor */
433 struct scsi_port_desc {
434         uint16_t reserved;
435         uint16_t rel_port_id;
436         uint16_t reserved2;
437         uint16_t init_port_len;
438         uint16_t init_port_id;
439         uint16_t reserved3;
440         uint16_t tgt_desc_len;
441         uint8_t tgt_desc[];
442 };
443
444 /* SCSI UNMAP block descriptor */
445 struct scsi_unmap_bdesc {
446         /* UNMAP LOGICAL BLOCK ADDRESS */
447         uint64_t lba;
448
449         /* NUMBER OF LOGICAL BLOCKS */
450         uint32_t block_count;
451
452         /* RESERVED */
453         uint32_t reserved;
454 };
455
456 #define SCSI_UNMAP_LBPU                         (1 << 7)
457 #define SCSI_UNMAP_LBPWS                        (1 << 6)
458 #define SCSI_UNMAP_LBPWS10                      (1 << 5)
459
460 #define SCSI_UNMAP_FULL_PROVISIONING    0x00
461 #define SCSI_UNMAP_RESOURCE_PROVISIONING        0x01
462 #define SCSI_UNMAP_THIN_PROVISIONING    0x02
463
464 #endif /* _SCSI_SPEC_H */