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