-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscsi_spc.h
628 lines (562 loc) · 15.7 KB
/
scsi_spc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/* $NetBSD: scsi_spc.h,v 1.6 2019/03/28 10:44:29 kardel Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* SCSI Primary Commands (SPC) --
* Commands for all device types
*/
/*
* Largely written by Julian Elischer ([email protected])
* for TRW Financial Systems.
*
* TRW Financial Systems, in accordance with their agreement with Carnegie
* Mellon University, makes this software available to CMU to distribute
* or use in any manner that they see fit as long as this message is kept with
* the software. For this reason TFS also grants any other persons or
* organisations permission to use or modify this software.
*
* TFS supplies this software to be publicly redistributed
* on the understanding that TFS is not responsible for the correct
* functioning of this software in any circumstances.
*
* Ported to run under 386BSD by Julian Elischer ([email protected]) Sept 1992
*/
#ifndef _DEV_SCSIPI_SCSI_SPC_H_
#define _DEV_SCSIPI_SCSI_SPC_H_
/*
* EXTENDED COPY
*/
/*
* INQUIRY
*/
/*
* LOG SELECT
*/
/*
* LOG SENSE
*/
/*
* MODE SELECT
*/
#define SCSI_MODE_SELECT_6 0x15
struct scsi_mode_select_6 {
uint8_t opcode;
uint8_t byte2;
#define SMS_SP 0x01 /* save page */
#define SMS_PF 0x10 /* page format (0 = SCSI-1, 1 = SCSI-2) */
uint8_t reserved[2];
uint8_t length;
uint8_t control;
};
#define SCSI_MODE_SELECT_10 0x55
struct scsi_mode_select_10 {
uint8_t opcode;
uint8_t byte2; /* see MODE SELECT (6) */
uint8_t reserved[5];
uint8_t length[2];
uint8_t control;
};
/*
* MODE SENSE
*/
#define SCSI_MODE_SENSE_6 0x1a
struct scsi_mode_sense_6 {
uint8_t opcode;
uint8_t byte2;
#define SMS_DBD 0x08 /* disable block descriptors */
uint8_t page;
#define SMS_PAGE_MASK 0x3f
#define SMS_PCTRL_MASK 0xc0
#define SMS_PCTRL_CURRENT 0x00
#define SMS_PCTRL_CHANGEABLE 0x40
#define SMS_PCTRL_DEFAULT 0x80
#define SMS_PCTRL_SAVED 0xc0
uint8_t reserved;
uint8_t length;
uint8_t control;
};
#define SCSI_MODE_SENSE_10 0x5a
struct scsi_mode_sense_10 {
uint8_t opcode;
uint8_t byte2; /* see MODE SENSE (6) */
#define SMS_LLBAA 0x10
uint8_t page; /* See MODE SENSE (6) */
uint8_t reserved[4];
uint8_t length[2];
uint8_t control;
};
/*
* Page code usage:
* 0x00 Vendor-specific (does not require page format)
* 0x01 - 0x1f Device-type-specific pages
* 0x20 - 0x3e Vendor-specific (page format required)
* 0x3f Return all mode pages
*/
#define SMS_PAGE_ALL_PAGES 0x3f
/*
* Mode parameters are returned in the following format:
*
* Mode parameter header
* Block descriptor(s) [zero or more]
* Page(s) [zero or more, variable-length]
*/
struct scsi_mode_parameter_header_6 {
uint8_t data_length;
uint8_t medium_type;
uint8_t dev_spec;
uint8_t blk_desc_len; /* unused on ATAPI */
};
struct scsi_mode_parameter_header_10 {
uint8_t data_length[2];
uint8_t medium_type;
uint8_t dev_spec;
uint8_t byte5;
#define SMPH_LONGLBA 0x01
uint8_t reserved;
uint8_t blk_desc_len[2];
};
struct scsi_general_block_descriptor {
uint8_t density;
uint8_t nblocks[3];
uint8_t reserved;
uint8_t blklen[3];
};
struct scsi_da_block_descriptor {
uint8_t nblocks[4];
uint8_t density;
uint8_t blklen[3];
};
struct scsi_longlba_block_descriptor {
uint8_t nblocks[8];
uint8_t density;
uint8_t reserved[3];
uint8_t blklen[4];
};
/*
* Header common to all mode parameter pages.
*/
struct scsi_mode_page_header {
uint8_t pg_code;
#define PGCODE_MASK 0x3f /* page code mask */
#define PGCODE_PS 0x80 /* page is saveable */
uint8_t pg_length; /* page length (not including header) */
};
/*
* Control mode page
*/
#define SCSI_CONTROL_MODE_PAGE 0x0a
struct scsi_control_mode_page {
uint8_t pg_code; /* 0x0a */
uint8_t pg_length; /* 0x0a */
uint8_t byte3;
#define SCMP_RLEC 0x01 /* report log exception condition */
#define SCMP_GLTSD 0x02 /* global logging target save disable */
#define SCMP_TST_mask 0x7 /* task set type */
#define SCMP_TST_shift 5
#define SCMP_TST_ALL_INIT 0 /* per LU for all initiators */
#define SCMP_TST_PER_INIT 1 /* per initiator per LU */
uint8_t queue_params;
#define SCMP_DQue 0x01 /* disable queueing */
#define SCMP_QErr_mask 0x3 /* queue error management */
#define SCMP_QErr_shift 1
#define SCMP_QAM_mask 0xf /* queue algorithm modifier */
#define SCMP_QAM_shift 4
#define SCMP_QAM_RESTRICTED 0x0 /* restricted reordering allowed */
#define SCMP_QAM_UNRESTRICTED 0x1 /* unrestricted reordering allowed */
/* 0x2 - 0x7 Reserved */
/* 0x8 - 0xf Vendor-specific */
uint8_t byte5;
#define SCMP_EAERP 0x01
#define SCMP_UAAERP 0x02
#define SCMP_RAERP 0x04
#define SCMP_SWP 0x08
#define SCMP_RAC 0x40
#define SCMP_TAS 0x80
uint8_t byte6;
#define SCMP_AM_mask 0x7 /* autload mode */
#define SCMP_AM_FULL 0
#define SCMP_AM_AUXMEM 1
#define SCMP_AM_NOLOAD 2
uint8_t rahp[2]; /* ready aer holdoff period */
uint8_t btp[2]; /* busy timeout period */
uint8_t estct[2]; /* extended self-test completion time */
};
/*
* Disconnect-reconnect page
*/
#define SCSI_DISCONNECT_RECONNECT_PAGE 0x02
struct scsi_disconnect_reconnect_page {
uint8_t pg_code; /* 0x02 */
uint8_t pg_length; /* 0x0e */
uint8_t buffer_full_ratio;
uint8_t buffer_empty_ratio;
uint8_t bus_inactivity_limit[2];
uint8_t disconnect_time_limit[2];
uint8_t connect_time_limit[2];
uint8_t maximum_burst_size[2];
uint8_t flags;
#define SDRP_DTDC_mask 0x7 /* data transfer disconnect control */
#define SDRP_DImm 0x08
#define SDRP_FA_mask 0x7
#define SDRP_FA_shift 4
#define SDRP_EMDP 0x80
uint8_t reserved;
uint8_t first_burst_size[2];
};
/*
* Informational exceptions control page
*/
#define SCSI_INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE 0x1c
struct scsi_informational_exceptions_control_page {
uint8_t pg_code; /* 0x1c */
uint8_t pg_length; /* 0x0a */
uint8_t byte3;
#define SIECP_LogErr 0x01
#define SIECP_TEST 0x04
#define SIECP_DExcpt 0x08
#define SIECP_EWasc 0x10
#define SIECP_EBF 0x20
#define SIECP_PERF 0x80
uint8_t byte4;
#define SIECP_MRIE_mask 0xf /* method of reporting
informational exceptions */
#define SIECP_MRIE_NO_REPORTING 0x00
#define SIECP_MRIE_ASYNC_EVENT 0x01
#define SIECP_MRIE_UNIT_ATN 0x02
#define SIECP_MRIE_COND_RECOV_ERR 0x03
#define SIECP_MRIE_UNCOND_RECOV_ERR 0x04
#define SIECP_MRIE_NO_SENSE 0x05
#define SIECP_MRIE_ON_REQUEST 0x06
/* 0x07 - 0x0b reserved */
/* 0x0c - 0x0f Vendor-specific */
uint8_t interval_timer[2];
uint8_t report_count[2];
};
/*
* Power condition page
*/
#define SCSI_POWER_CONDITION_PAGE 0x1a
struct scsi_power_condition_page {
uint8_t pg_code; /* 0x1a */
uint8_t pg_length; /* 0x0a */
uint8_t reserved;
uint8_t byte4;
#define SPCP_STANDBY 0x01
#define SPCP_IDLE 0x02
uint8_t idle_timer[2]; /* 100ms increments */
uint8_t standby_timer[2]; /* 100ms increments */
};
/*
* Protocol specific LUN page
*/
#define SCSI_PROTOCOL_SPECIFIC_LUN_PAGE 0x18
struct scsi_protocol_specific_lun_page {
uint8_t pg_code; /* 0x18 */
uint8_t pg_length; /* variable */
uint8_t byte3;
#define SPSLP_PROTOCOL_mask 0xf
#define SPSLP_PROTOCOL_FCP 0x00 /* Fibre Channel */
#define SPSLP_PROTOCOL_SPI 0x01 /* parallel SCSI */
#define SPSLP_PROTOCOL_SSA 0x02 /* SSA-S2P or SSA-S3P */
#define SPSLP_PROTOCOL_SBP2 0x03 /* IEEE 1394 */
#define SPSLP_PROTOCOL_SRP 0x04 /* SCSI RDMA */
#define SPSLP_PROTOCOL_ISCSI 0x05 /* iSCSI */
/* protocol specific mode parameters follow */
};
/*
* Protocol specific port page
*/
#define SCSI_PROTOCOL_SPECIFIC_PORT_PAGE 0x19
struct scsi_protocol_specific_port_page {
uint8_t pg_code; /* 0x18 */
uint8_t pg_length; /* variable */
uint8_t byte3; /* see SCSI PROTOCOL SPECIFIC LUN PAGE */
/* protocol specific mode parameters follow */
};
/*
* PERSISTENT RESERVE IN
*/
/*
* PERSISTENT RESERVE OUT
*/
/*
* PREVENT ALLOW MEDIUM REMOVAL
*/
#define SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
struct scsi_prevent_allow_medium_removal {
uint8_t opcode;
uint8_t byte2;
uint8_t reserved[2];
uint8_t how;
#define SPAMR_ALLOW 0x00
#define SPAMR_PREVENT_DT 0x01
#define SPAMR_PREVENT_MC 0x02
#define SPAMR_PREVENT_ALL 0x03
uint8_t control;
};
/*
* READ BUFFER
*/
/*
* RECEIVE COPY RESULTS
*/
/*
* RECEIVE DIAGNOSTIC RESULTS
*/
/*
* RESERVE / RELEASE
*/
#define SCSI_RESERVE_6 0x16
#define SCSI_RELEASE_6 0x17
struct scsi_reserve_release_6 {
uint8_t opcode;
uint8_t byte2;
uint8_t obsolete;
uint8_t reserved[2];
uint8_t control;
};
#define SCSI_RESERVE_10 0x56
#define SCSI_RELEASE_10 0x57
struct scsi_reserve_release_10 {
uint8_t opcode;
uint8_t byte2;
#define SR_LongID 0x02
#define SR_3rdPty 0x10
uint8_t obsolete;
uint8_t thirdpartyid;
uint8_t reserved[3];
uint8_t paramlen[2];
uint8_t control;
};
struct scsi_reserve_release_10_idparam {
uint8_t thirdpartyid[8];
};
/*
* REPORT DEVICE IDENTIFIER
*/
/*
* REPORT LUNS
*/
/*
* MAINTENANCE_IN[REPORT SUPPORTED OPERATION CODES]
*/
#define SCSI_MAINTENANCE_IN 0xA3
struct scsi_repsuppopcode {
u_int8_t opcode;
u_int8_t svcaction;
#define RSOC_REPORT_SUPPORTED_OPCODES 0x0C
u_int8_t repoption;
#define RSOC_ALL 0x00 /* report all */
#define RSOC_ONE 0x01 /* report one */
#define RSOC_ONESACD 0x02 /* report one or CHECK CONDITION */
#define RSOC_ONESA 0x03 /* report one mark presense in data */
#define RSOC_RCTD 0x80 /* report timeouts */
u_int8_t reqopcode;
u_int8_t reqsvcaction[2];
u_int8_t alloclen[4];
u_int8_t _res0;
u_int8_t control;
};
struct scsi_repsupopcode_all_commands_descriptor {
u_int8_t opcode;
u_int8_t _res0;
u_int8_t serviceaction[2];
u_int8_t _res1;
u_int8_t flags;
#define RSOC_ACD_CTDP 0x02 /* timeouts present */
#define RSOC_ACD_SERVACTV 0x01 /* service action valid */
u_int8_t cdblen[2];
};
struct scsi_repsupopcode_one_command_descriptor {
u_int8_t _res0;
u_int8_t support;
#define RSOC_OCD_CTDP 0x80 /* timeouts present */
#define RSOC_OCD_SUP_NOT_AVAIL 0x00 /* not available */
#define RSOC_OCD_SUP_NOT_SUPP 0x01 /* not supported */
#define RSOC_OCD_SUP_SUPP_STD 0x03 /* supported - standard */
#define RSOC_OCD_SUP_SUPP_VENDOR 0x05 /* supported - vendor */
#define RSOC_OCD_SUP 0x07 /* mask for support field */
u_int8_t cdblen[2];
/*
* u_int8_t usage[0...]- cdblen bytes
* usage data
*/
/*
* scsi_repsupopcode_timeouts_descriptor
* if RSOC_OCD_CTDP is set
*/
};
struct scsi_repsupopcode_timeouts_descriptor {
u_int8_t descriptor_length[2];
u_int8_t _res0;
u_int8_t cmd_specific;
u_int8_t nom_process_timeout[4];
u_int8_t cmd_process_timeout[4];
};
/*
* REQUEST SENSE
*/
#define SCSI_REQUEST_SENSE 0x03
struct scsi_request_sense {
uint8_t opcode;
uint8_t byte2;
uint8_t reserved[2];
uint8_t length;
uint8_t control;
};
struct scsi_sense_data {
/* 1*/ uint8_t response_code;
#define SSD_RCODE(x) ((x) & 0x7f)
#define SSD_RCODE_CURRENT 0x70
#define SSD_RCODE_DEFERRED 0x71
#define SSD_RCODE_VALID 0x80
/* 2*/ uint8_t segment; /* obsolete */
/* 3*/ uint8_t flags;
#define SSD_SENSE_KEY(x) ((x) & 0x0f)
#define SSD_ILI 0x20
#define SSD_EOM 0x40
#define SSD_FILEMARK 0x80
/* 7*/ uint8_t info[4];
/* 8*/ uint8_t extra_len; /* Additional sense length */
/*12*/ uint8_t csi[4]; /* Command-specific information */
/*13*/ uint8_t asc; /* Additional sense code */
/*14*/ uint8_t ascq; /* Additional sense code qualifier */
/*15*/ uint8_t fru; /* Field replaceable unit code */
union {
uint8_t sks_bytes[3];
/* ILLEGAL REQUEST */
struct {
uint8_t byte0;
#define SSD_SKS_FP_BIT(x) ((x) & 0x7)
#define SSD_SKS_FP_BPV 0x08
#define SSK_SKS_FP_CD 0x40 /* 1=command, 0=data */
uint8_t val[2];
} field_pointer;
/* RECOVERED ERROR, HARDWARE ERROR, MEDIUM ERROR */
struct {
uint8_t byte0;
uint8_t val[2];
} actual_retry_count;
/* NOT READY, NO SENSE */
struct {
uint8_t byte0;
uint8_t val[2];
} progress_indication;
/* COPY ABORTED */
struct {
uint8_t byte0;
#define SSD_SKS_SP_BIT(x) ((x) & 0x7)
#define SSD_SKS_SP_BPV 0x08
#define SSD_SKS_SP_SD 0x20 /* 0=param list, 1=segment desc */
uint8_t val[2];
} segment_pointer;
/*18*/ } sks; /* Sense-key specific */
#define SSD_SKSV 0x80 /* byte0 of sks field */
/*32*/ uint8_t extra_bytes[14]; /* really variable length */
};
/*
* Sense bytes described by the extra_len field start at csi[], and can
* only continue up to the end of the 32-byte sense structure that we
* have defined (which might be too short for some cases).
*/
#define SSD_ADD_BYTES_LIM(sp) \
((((int)(sp)->extra_len) < (int)sizeof(struct scsi_sense_data) - 8) ? \
(sp)->extra_len : sizeof(struct scsi_sense_data) - 8)
#define SKEY_NO_SENSE 0x00
#define SKEY_RECOVERED_ERROR 0x01
#define SKEY_NOT_READY 0x02
#define SKEY_MEDIUM_ERROR 0x03
#define SKEY_HARDWARE_ERROR 0x04
#define SKEY_ILLEGAL_REQUEST 0x05
#define SKEY_UNIT_ATTENTION 0x06
#define SKEY_DATA_PROTECT 0x07
#define SKEY_BLANK_CHECK 0x08
#define SKEY_VENDOR_SPECIFIC 0x09
#define SKEY_COPY_ABORTED 0x0a
#define SKEY_ABORTED_COMMAND 0x0b
#define SKEY_EQUAL 0x0c /* obsolete */
#define SKEY_VOLUME_OVERFLOW 0x0d
#define SKEY_MISCOMPARE 0x0e
/* 0x0f reserved */
/* XXX This is not described in SPC-2. */
struct scsi_sense_data_unextended {
uint8_t response_code;
uint8_t block[3];
};
/*
* SEND DIAGNOSTIC
*/
#define SCSI_SEND_DIAGNOSTIC 0x1d
struct scsi_send_diagnostic {
uint8_t opcode;
uint8_t byte2;
#define SSD_UnitOffL 0x01
#define SSD_DevOffL 0x02
#define SSD_SelfTest 0x04 /* standard self-test */
#define SSD_PF 0x10 /* results in page format */
#define SSD_CODE(x) ((x) << 5)
/*
* Codes:
*
* 0 This value shall be used when the SelfTest bit is
* set to one or if the SEND DIAGNOSTIC command is not
* invoking one of the other self-test functions such
* as enclosure services or the Translate Address page.
*
* 1 Background short self-test. Parameter length is 0.
*
* 2 Background extended self-test. Parameter length is 0.
*
* 4 Abort background self-test. Parameter length is 0.
*
* 5 Foreground short self-test. Parameter length is 0.
*
* 6 Foreground extended self-test. Parameter length is 0.
*/
uint8_t reserved;
uint8_t paramlen[2];
uint8_t control;
};
/*
* SET DEVICE IDENTIFIER
*/
/*
* TEST UNIT READY
*/
#define SCSI_TEST_UNIT_READY 0x00
struct scsi_test_unit_ready {
uint8_t opcode;
uint8_t byte2;
uint8_t reserved[3];
uint8_t control;
};
/*
* WRITE BUFFER
*/
#endif /* _DEV_SCSIPI_SCSI_SPC_H_ */