xref: /aosp_15_r20/external/kernel-headers/modified/scsi/scsi_proto.h (revision f80ad8b4341604f5951dab671d41019a6d7087ce)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * This header file contains public constants and structures used by
4  * both the SCSI initiator and the SCSI target code.
5  *
6  * For documentation on the OPCODES, MESSAGES, and SENSE values,
7  * please consult the SCSI standard.
8  */
9 
10 #ifndef _SCSI_PROTO_H_
11 #define _SCSI_PROTO_H_
12 
13 #ifdef __KERNEL__
14 #include <linux/build_bug.h>
15 #endif /* __KERNEL__ */
16 #include <linux/types.h>
17 
18 /*
19  *      SCSI opcodes
20  */
21 
22 #define TEST_UNIT_READY       0x00
23 #define REZERO_UNIT           0x01
24 #define REQUEST_SENSE         0x03
25 #define FORMAT_UNIT           0x04
26 #define READ_BLOCK_LIMITS     0x05
27 #define REASSIGN_BLOCKS       0x07
28 #define INITIALIZE_ELEMENT_STATUS 0x07
29 #define READ_6                0x08
30 #define WRITE_6               0x0a
31 #define SEEK_6                0x0b
32 #define READ_REVERSE          0x0f
33 #define WRITE_FILEMARKS       0x10
34 #define SPACE                 0x11
35 #define INQUIRY               0x12
36 #define RECOVER_BUFFERED_DATA 0x14
37 #define MODE_SELECT           0x15
38 #define RESERVE               0x16
39 #define RELEASE               0x17
40 #define COPY                  0x18
41 #define ERASE                 0x19
42 #define MODE_SENSE            0x1a
43 #define START_STOP            0x1b
44 #define RECEIVE_DIAGNOSTIC    0x1c
45 #define SEND_DIAGNOSTIC       0x1d
46 #define ALLOW_MEDIUM_REMOVAL  0x1e
47 
48 #define READ_FORMAT_CAPACITIES 0x23
49 #define SET_WINDOW            0x24
50 #define READ_CAPACITY         0x25
51 #define READ_10               0x28
52 #define WRITE_10              0x2a
53 #define SEEK_10               0x2b
54 #define POSITION_TO_ELEMENT   0x2b
55 #define WRITE_VERIFY          0x2e
56 #define VERIFY                0x2f
57 #define SEARCH_HIGH           0x30
58 #define SEARCH_EQUAL          0x31
59 #define SEARCH_LOW            0x32
60 #define SET_LIMITS            0x33
61 #define PRE_FETCH             0x34
62 #define READ_POSITION         0x34
63 #define SYNCHRONIZE_CACHE     0x35
64 #define LOCK_UNLOCK_CACHE     0x36
65 #define READ_DEFECT_DATA      0x37
66 #define MEDIUM_SCAN           0x38
67 #define COMPARE               0x39
68 #define COPY_VERIFY           0x3a
69 #define WRITE_BUFFER          0x3b
70 #define READ_BUFFER           0x3c
71 #define UPDATE_BLOCK          0x3d
72 #define READ_LONG             0x3e
73 #define WRITE_LONG            0x3f
74 #define CHANGE_DEFINITION     0x40
75 #define WRITE_SAME            0x41
76 #define UNMAP		      0x42
77 #define READ_TOC              0x43
78 #define READ_HEADER           0x44
79 #define GET_EVENT_STATUS_NOTIFICATION 0x4a
80 #define LOG_SELECT            0x4c
81 #define LOG_SENSE             0x4d
82 #define XDWRITEREAD_10        0x53
83 #define MODE_SELECT_10        0x55
84 #define RESERVE_10            0x56
85 #define RELEASE_10            0x57
86 #define MODE_SENSE_10         0x5a
87 #define PERSISTENT_RESERVE_IN 0x5e
88 #define PERSISTENT_RESERVE_OUT 0x5f
89 #define VARIABLE_LENGTH_CMD   0x7f
90 #define REPORT_LUNS           0xa0
91 #define SECURITY_PROTOCOL_IN  0xa2
92 #define MAINTENANCE_IN        0xa3
93 #define MAINTENANCE_OUT       0xa4
94 #define MOVE_MEDIUM           0xa5
95 #define EXCHANGE_MEDIUM       0xa6
96 #define READ_12               0xa8
97 #define SERVICE_ACTION_OUT_12 0xa9
98 #define WRITE_12              0xaa
99 #define READ_MEDIA_SERIAL_NUMBER 0xab /* Obsolete with SPC-2 */
100 #define SERVICE_ACTION_IN_12  0xab
101 #define WRITE_VERIFY_12       0xae
102 #define VERIFY_12	      0xaf
103 #define SEARCH_HIGH_12        0xb0
104 #define SEARCH_EQUAL_12       0xb1
105 #define SEARCH_LOW_12         0xb2
106 #define SECURITY_PROTOCOL_OUT 0xb5
107 #define READ_ELEMENT_STATUS   0xb8
108 #define SEND_VOLUME_TAG       0xb6
109 #define WRITE_LONG_2          0xea
110 #define EXTENDED_COPY         0x83
111 #define RECEIVE_COPY_RESULTS  0x84
112 #define ACCESS_CONTROL_IN     0x86
113 #define ACCESS_CONTROL_OUT    0x87
114 #define READ_16               0x88
115 #define COMPARE_AND_WRITE     0x89
116 #define WRITE_16              0x8a
117 #define READ_ATTRIBUTE        0x8c
118 #define WRITE_ATTRIBUTE	      0x8d
119 #define WRITE_VERIFY_16	      0x8e
120 #define VERIFY_16	      0x8f
121 #define SYNCHRONIZE_CACHE_16  0x91
122 #define WRITE_SAME_16	      0x93
123 #define ZBC_OUT		      0x94
124 #define ZBC_IN		      0x95
125 #define WRITE_ATOMIC_16	0x9c
126 #define SERVICE_ACTION_BIDIRECTIONAL 0x9d
127 #define SERVICE_ACTION_IN_16  0x9e
128 #define SERVICE_ACTION_OUT_16 0x9f
129 #ifdef __KERNEL__
130 /* values for service action in */
131 #define	SAI_READ_CAPACITY_16  0x10
132 #define SAI_GET_LBA_STATUS    0x12
133 #define SAI_REPORT_REFERRALS  0x13
134 #define SAI_GET_STREAM_STATUS 0x16
135 /* values for maintenance in */
136 #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
137 #define MI_REPORT_TARGET_PGS  0x0a
138 #define MI_REPORT_ALIASES     0x0b
139 #define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
140 #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
141 #define MI_REPORT_PRIORITY    0x0e
142 #define MI_REPORT_TIMESTAMP   0x0f
143 #define MI_MANAGEMENT_PROTOCOL_IN 0x10
144 /* value for MI_REPORT_TARGET_PGS ext header */
145 #define MI_EXT_HDR_PARAM_FMT  0x20
146 /* values for maintenance out */
147 #define MO_SET_IDENTIFYING_INFORMATION 0x06
148 #define MO_SET_TARGET_PGS     0x0a
149 #define MO_CHANGE_ALIASES     0x0b
150 #define MO_SET_PRIORITY       0x0e
151 #define MO_SET_TIMESTAMP      0x0f
152 #define MO_MANAGEMENT_PROTOCOL_OUT 0x10
153 /* values for ZBC_IN */
154 #define ZI_REPORT_ZONES	      0x00
155 /* values for ZBC_OUT */
156 #define ZO_CLOSE_ZONE	      0x01
157 #define ZO_FINISH_ZONE	      0x02
158 #define ZO_OPEN_ZONE	      0x03
159 #define ZO_RESET_WRITE_POINTER 0x04
160 /* values for PR in service action */
161 #define READ_KEYS             0x00
162 #define READ_RESERVATION      0x01
163 #define REPORT_CAPABILITES    0x02
164 #define READ_FULL_STATUS      0x03
165 /* values for variable length command */
166 #define XDREAD_32	      0x03
167 #define XDWRITE_32	      0x04
168 #define XPWRITE_32	      0x06
169 #define XDWRITEREAD_32	      0x07
170 #define READ_32		      0x09
171 #define VERIFY_32	      0x0a
172 #define WRITE_32	      0x0b
173 #define WRITE_VERIFY_32	      0x0c
174 #define WRITE_SAME_32	      0x0d
175 #define ATA_32		      0x1ff0
176 
177 /* Values for T10/04-262r7 */
178 #define	ATA_16		      0x85	/* 16-byte pass-thru */
179 #define	ATA_12		      0xa1	/* 12-byte pass-thru */
180 
181 /* Vendor specific CDBs start here */
182 #define VENDOR_SPECIFIC_CDB 0xc0
183 
184 /*
185  *	SCSI command lengths
186  */
187 
188 #define SCSI_MAX_VARLEN_CDB_SIZE 260
189 
190 /* defined in T10 SCSI Primary Commands-2 (SPC2) */
191 struct scsi_varlen_cdb_hdr {
192 	__u8 opcode;        /* opcode always == VARIABLE_LENGTH_CMD */
193 	__u8 control;
194 	__u8 misc[5];
195 	__u8 additional_cdb_length;         /* total cdb length - 8 */
196 	__be16 service_action;
197 	/* service specific data follows */
198 };
199 
200 /*
201  *  SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
202  *  T10/1561-D Revision 4 Draft dated 7th November 2002.
203  */
204 enum sam_status {
205 	SAM_STAT_GOOD				= 0x00,
206 	SAM_STAT_CHECK_CONDITION		= 0x02,
207 	SAM_STAT_CONDITION_MET			= 0x04,
208 	SAM_STAT_BUSY				= 0x08,
209 	SAM_STAT_INTERMEDIATE			= 0x10,
210 	SAM_STAT_INTERMEDIATE_CONDITION_MET	= 0x14,
211 	SAM_STAT_RESERVATION_CONFLICT		= 0x18,
212 	SAM_STAT_COMMAND_TERMINATED		= 0x22,	/* obsolete in SAM-3 */
213 	SAM_STAT_TASK_SET_FULL			= 0x28,
214 	SAM_STAT_ACA_ACTIVE			= 0x30,
215 	SAM_STAT_TASK_ABORTED			= 0x40,
216 };
217 #endif /* __KERNEL__ */
218 
219 #define STATUS_MASK         0xfe
220 
221 /*
222  *  SENSE KEYS
223  */
224 #define NO_SENSE            0x00
225 #define RECOVERED_ERROR     0x01
226 #define NOT_READY           0x02
227 #define MEDIUM_ERROR        0x03
228 #define HARDWARE_ERROR      0x04
229 #define ILLEGAL_REQUEST     0x05
230 #define UNIT_ATTENTION      0x06
231 #define DATA_PROTECT        0x07
232 #define BLANK_CHECK         0x08
233 #define VENDOR_SPECIFIC     0x09
234 #define COPY_ABORTED        0x0a
235 #define ABORTED_COMMAND     0x0b
236 #define VOLUME_OVERFLOW     0x0d
237 #define MISCOMPARE          0x0e
238 #define COMPLETED	    0x0f
239 
240 /*
241  *  DEVICE TYPES
242  *  Please keep them in 0x%02x format for $MODALIAS to work
243  */
244 
245 #define TYPE_DISK           0x00
246 #define TYPE_TAPE           0x01
247 #define TYPE_PRINTER        0x02
248 #define TYPE_PROCESSOR      0x03    /* HP scanners use this */
249 #define TYPE_WORM           0x04    /* Treated as ROM by our system */
250 #define TYPE_ROM            0x05
251 #define TYPE_SCANNER        0x06
252 #define TYPE_MOD            0x07    /* Magneto-optical disk -
253 				     * - treated as TYPE_DISK */
254 #define TYPE_MEDIUM_CHANGER 0x08
255 #define TYPE_COMM           0x09    /* Communications device */
256 #define TYPE_RAID           0x0c
257 #define TYPE_ENCLOSURE      0x0d    /* Enclosure Services Device */
258 #define TYPE_RBC	    0x0e
259 #define TYPE_OSD            0x11
260 #define TYPE_ZBC            0x14
261 #define TYPE_WLUN           0x1e    /* well-known logical unit */
262 #define TYPE_NO_LUN         0x7f
263 
264 #ifdef __KERNEL__
265 /* SCSI protocols; these are taken from SPC-3 section 7.5 */
266 enum scsi_protocol {
267 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
268 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
269 	SCSI_PROTOCOL_SSA = 2,	/* Serial Storage Architecture - Obsolete */
270 	SCSI_PROTOCOL_SBP = 3,	/* firewire */
271 	SCSI_PROTOCOL_SRP = 4,	/* Infiniband RDMA */
272 	SCSI_PROTOCOL_ISCSI = 5,
273 	SCSI_PROTOCOL_SAS = 6,
274 	SCSI_PROTOCOL_ADT = 7,	/* Media Changers */
275 	SCSI_PROTOCOL_ATA = 8,
276 	SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
277 };
278 
279 /*
280  * ScsiLun: 8 byte LUN.
281  */
282 struct scsi_lun {
283 	__u8 scsi_lun[8];
284 };
285 
286 /* SBC-5 IO advice hints group descriptor */
287 struct scsi_io_group_descriptor {
288 #if defined(__BIG_ENDIAN)
289 	u8 io_advice_hints_mode: 2;
290 	u8 reserved1: 3;
291 	u8 st_enble: 1;
292 	u8 cs_enble: 1;
293 	u8 ic_enable: 1;
294 #elif defined(__LITTLE_ENDIAN)
295 	u8 ic_enable: 1;
296 	u8 cs_enble: 1;
297 	u8 st_enble: 1;
298 	u8 reserved1: 3;
299 	u8 io_advice_hints_mode: 2;
300 #else
301 #error
302 #endif
303 	u8 reserved2[3];
304 	/* Logical block markup descriptor */
305 #if defined(__BIG_ENDIAN)
306 	u8 acdlu: 1;
307 	u8 reserved3: 1;
308 	u8 rlbsr: 2;
309 	u8 lbm_descriptor_type: 4;
310 #elif defined(__LITTLE_ENDIAN)
311 	u8 lbm_descriptor_type: 4;
312 	u8 rlbsr: 2;
313 	u8 reserved3: 1;
314 	u8 acdlu: 1;
315 #else
316 #error
317 #endif
318 	u8 params[2];
319 	u8 reserved4;
320 	u8 reserved5[8];
321 };
322 
323 static_assert(sizeof(struct scsi_io_group_descriptor) == 16);
324 
325 /* SCSI stream status descriptor */
326 struct scsi_stream_status {
327 #if defined(__BIG_ENDIAN)
328 	u8 perm: 1;
329 	u8 reserved1: 7;
330 #elif defined(__LITTLE_ENDIAN)
331 	u8 reserved1: 7;
332 	u8 perm: 1;
333 #else
334 #error
335 #endif
336 	u8 reserved2;
337 	__be16 stream_identifier;
338 #if defined(__BIG_ENDIAN)
339 	u8 reserved3: 2;
340 	u8 rel_lifetime: 6;
341 #elif defined(__LITTLE_ENDIAN)
342 	u8 rel_lifetime: 6;
343 	u8 reserved3: 2;
344 #else
345 #error
346 #endif
347 	u8 reserved4[3];
348 };
349 
350 static_assert(sizeof(struct scsi_stream_status) == 8);
351 
352 /* GET STREAM STATUS parameter data */
353 struct scsi_stream_status_header {
354 	__be32 len;	/* length in bytes of stream_status[] array. */
355 	u16 reserved;
356 	__be16 number_of_open_streams;
357 	DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status);
358 };
359 
360 static_assert(sizeof(struct scsi_stream_status_header) == 8);
361 #endif /* __KERNEL__ */
362 
363 /* SPC asymmetric access states */
364 #define SCSI_ACCESS_STATE_OPTIMAL     0x00
365 #define SCSI_ACCESS_STATE_ACTIVE      0x01
366 #define SCSI_ACCESS_STATE_STANDBY     0x02
367 #define SCSI_ACCESS_STATE_UNAVAILABLE 0x03
368 #define SCSI_ACCESS_STATE_LBA         0x04
369 #define SCSI_ACCESS_STATE_OFFLINE     0x0e
370 #define SCSI_ACCESS_STATE_TRANSITIONING 0x0f
371 
372 /* Values for REPORT TARGET GROUP STATES */
373 #define SCSI_ACCESS_STATE_MASK        0x0f
374 #define SCSI_ACCESS_STATE_PREFERRED   0x80
375 
376 /* Reporting options for REPORT ZONES */
377 enum zbc_zone_reporting_options {
378 	ZBC_ZONE_REPORTING_OPTION_ALL		= 0x00,
379 	ZBC_ZONE_REPORTING_OPTION_EMPTY		= 0x01,
380 	ZBC_ZONE_REPORTING_OPTION_IMPLICIT_OPEN	= 0x02,
381 	ZBC_ZONE_REPORTING_OPTION_EXPLICIT_OPEN	= 0x03,
382 	ZBC_ZONE_REPORTING_OPTION_CLOSED	= 0x04,
383 	ZBC_ZONE_REPORTING_OPTION_FULL		= 0x05,
384 	ZBC_ZONE_REPORTING_OPTION_READONLY	= 0x06,
385 	ZBC_ZONE_REPORTING_OPTION_OFFLINE	= 0x07,
386 	/* 0x08 to 0x0f are reserved */
387 	ZBC_ZONE_REPORTING_OPTION_NEED_RESET_WP	= 0x10,
388 	ZBC_ZONE_REPORTING_OPTION_NON_SEQWRITE	= 0x11,
389 	/* 0x12 to 0x3e are reserved */
390 	ZBC_ZONE_REPORTING_OPTION_NON_WP	= 0x3f,
391 };
392 
393 #define ZBC_REPORT_ZONE_PARTIAL 0x80
394 
395 /* Zone types of REPORT ZONES zone descriptors */
396 enum zbc_zone_type {
397 	ZBC_ZONE_TYPE_CONV		= 0x1,
398 	ZBC_ZONE_TYPE_SEQWRITE_REQ	= 0x2,
399 	ZBC_ZONE_TYPE_SEQWRITE_PREF	= 0x3,
400 	ZBC_ZONE_TYPE_SEQ_OR_BEFORE_REQ	= 0x4,
401 	ZBC_ZONE_TYPE_GAP		= 0x5,
402 	/* 0x6 to 0xf are reserved */
403 };
404 
405 /* Zone conditions of REPORT ZONES zone descriptors */
406 enum zbc_zone_cond {
407 	ZBC_ZONE_COND_NO_WP		= 0x0,
408 	ZBC_ZONE_COND_EMPTY		= 0x1,
409 	ZBC_ZONE_COND_IMP_OPEN		= 0x2,
410 	ZBC_ZONE_COND_EXP_OPEN		= 0x3,
411 	ZBC_ZONE_COND_CLOSED		= 0x4,
412 	/* 0x5 to 0xc are reserved */
413 	ZBC_ZONE_COND_READONLY		= 0xd,
414 	ZBC_ZONE_COND_FULL		= 0xe,
415 	ZBC_ZONE_COND_OFFLINE		= 0xf,
416 };
417 
418 enum zbc_zone_alignment_method {
419 	ZBC_CONSTANT_ZONE_LENGTH	= 0x1,
420 	ZBC_CONSTANT_ZONE_START_OFFSET	= 0x8,
421 };
422 
423 /* Version descriptor values for INQUIRY */
424 enum scsi_version_descriptor {
425 	SCSI_VERSION_DESCRIPTOR_FCP4	= 0x0a40,
426 	SCSI_VERSION_DESCRIPTOR_ISCSI	= 0x0960,
427 	SCSI_VERSION_DESCRIPTOR_SAM5	= 0x00a0,
428 	SCSI_VERSION_DESCRIPTOR_SAS3	= 0x0c60,
429 	SCSI_VERSION_DESCRIPTOR_SBC3	= 0x04c0,
430 	SCSI_VERSION_DESCRIPTOR_SBP3	= 0x0980,
431 	SCSI_VERSION_DESCRIPTOR_SPC4	= 0x0460,
432 	SCSI_VERSION_DESCRIPTOR_SRP	= 0x0940
433 };
434 
435 enum scsi_support_opcode {
436 	SCSI_SUPPORT_NO_INFO		= 0,
437 	SCSI_SUPPORT_NOT_SUPPORTED	= 1,
438 	SCSI_SUPPORT_FULL		= 3,
439 	SCSI_SUPPORT_VENDOR		= 5,
440 };
441 
442 #define SCSI_CONTROL_MASK 0
443 #define SCSI_GROUP_NUMBER_MASK 0
444 
445 #endif /* _SCSI_PROTO_H_ */
446