1 /*-
2 * Largely written by Julian Elischer (julian@tfs.com)
3 * for TRW Financial Systems.
4 *
5 * TRW Financial Systems, in accordance with their agreement with Carnegie
6 * Mellon University, makes this software available to CMU to distribute
7 * or use in any manner that they see fit as long as this message is kept with
8 * the software. For this reason TFS also grants any other persons or
9 * organisations permission to use or modify this software.
10 *
11 * TFS supplies this software to be publicly redistributed
12 * on the understanding that TFS is not responsible for the correct
13 * functioning of this software in any circumstances.
14 *
15 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
16 *
17 * $FreeBSD$
18 */
19
20 /*
21 * SCSI general interface description
22 */
23
24 #ifndef _SCSI_SCSI_ALL_H
25 #define _SCSI_SCSI_ALL_H 1
26
27 #include <sys/cdefs.h>
28
29 #ifdef _KERNEL
30 /*
31 * This is the number of seconds we wait for devices to settle after a SCSI
32 * bus reset.
33 */
34 extern int scsi_delay;
35 #endif /* _KERNEL */
36
37 /*
38 * SCSI command format
39 */
40
41 /*
42 * Define dome bits that are in ALL (or a lot of) scsi commands
43 */
44 #define SCSI_CTL_LINK 0x01
45 #define SCSI_CTL_FLAG 0x02
46 #define SCSI_CTL_VENDOR 0xC0
47 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
48 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
49
50 #define SCSI_MAX_CDBLEN 16 /*
51 * 16 byte commands are in the
52 * SCSI-3 spec
53 */
54 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
55 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
56 #endif
57
58 /* 6byte CDBs special case 0 length to be 256 */
59 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
60
61 /*
62 * This type defines actions to be taken when a particular sense code is
63 * received. Right now, these flags are only defined to take up 16 bits,
64 * but can be expanded in the future if necessary.
65 */
66 typedef enum {
67 SS_NOP = 0x000000, /* Do nothing */
68 SS_RETRY = 0x010000, /* Retry the command */
69 SS_FAIL = 0x020000, /* Bail out */
70 SS_START = 0x030000, /* Send a Start Unit command to the device,
71 * then retry the original command.
72 */
73 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
74 * device, then retry the original command.
75 */
76 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
77 * device, then retry the original command.
78 */
79 SS_MASK = 0xff0000
80 } scsi_sense_action;
81
82 typedef enum {
83 SSQ_NONE = 0x0000,
84 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
85 SSQ_MANY = 0x0200, /* send lots of recovery commands */
86 SSQ_RANGE = 0x0400, /*
87 * This table entry represents the
88 * end of a range of ASCQs that
89 * have identical error actions
90 * and text.
91 */
92 SSQ_PRINT_SENSE = 0x0800,
93 SSQ_MASK = 0xff00
94 } scsi_sense_action_qualifier;
95
96 /* Mask for error status values */
97 #define SS_ERRMASK 0xff
98
99 /* The default, retyable, error action */
100 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
101
102 /* The retyable, error action, with table specified error code */
103 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
104
105 /* Fatal error action, with table specified error code */
106 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
107
108 struct scsi_generic
109 {
110 u_int8_t opcode;
111 u_int8_t bytes[11];
112 };
113
114 struct scsi_request_sense
115 {
116 u_int8_t opcode;
117 u_int8_t byte2;
118 u_int8_t unused[2];
119 u_int8_t length;
120 u_int8_t control;
121 };
122
123 struct scsi_test_unit_ready
124 {
125 u_int8_t opcode;
126 u_int8_t byte2;
127 u_int8_t unused[3];
128 u_int8_t control;
129 };
130
131 struct scsi_send_diag
132 {
133 u_int8_t opcode;
134 u_int8_t byte2;
135 #define SSD_UOL 0x01
136 #define SSD_DOL 0x02
137 #define SSD_SELFTEST 0x04
138 #define SSD_PF 0x10
139 u_int8_t unused[1];
140 u_int8_t paramlen[2];
141 u_int8_t control;
142 };
143
144 struct scsi_sense
145 {
146 u_int8_t opcode;
147 u_int8_t byte2;
148 u_int8_t unused[2];
149 u_int8_t length;
150 u_int8_t control;
151 };
152
153 struct scsi_inquiry
154 {
155 u_int8_t opcode;
156 u_int8_t byte2;
157 #define SI_EVPD 0x01
158 u_int8_t page_code;
159 u_int8_t reserved;
160 u_int8_t length;
161 u_int8_t control;
162 };
163
164 struct scsi_mode_sense_6
165 {
166 u_int8_t opcode;
167 u_int8_t byte2;
168 #define SMS_DBD 0x08
169 u_int8_t page;
170 #define SMS_PAGE_CODE 0x3F
171 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
172 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
173 #define SMS_FORMAT_DEVICE_PAGE 0x03
174 #define SMS_GEOMETRY_PAGE 0x04
175 #define SMS_CACHE_PAGE 0x08
176 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
177 #define SMS_CONTROL_MODE_PAGE 0x0A
178 #define SMS_PROTO_SPECIFIC_PAGE 0x19
179 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C
180 #define SMS_ALL_PAGES_PAGE 0x3F
181 #define SMS_PAGE_CTRL_MASK 0xC0
182 #define SMS_PAGE_CTRL_CURRENT 0x00
183 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
184 #define SMS_PAGE_CTRL_DEFAULT 0x80
185 #define SMS_PAGE_CTRL_SAVED 0xC0
186 u_int8_t unused;
187 u_int8_t length;
188 u_int8_t control;
189 };
190
191 struct scsi_mode_sense_10
192 {
193 u_int8_t opcode;
194 u_int8_t byte2; /* same bits as small version */
195 u_int8_t page; /* same bits as small version */
196 u_int8_t unused[4];
197 u_int8_t length[2];
198 u_int8_t control;
199 };
200
201 struct scsi_mode_select_6
202 {
203 u_int8_t opcode;
204 u_int8_t byte2;
205 #define SMS_SP 0x01
206 #define SMS_PF 0x10
207 u_int8_t unused[2];
208 u_int8_t length;
209 u_int8_t control;
210 };
211
212 struct scsi_mode_select_10
213 {
214 u_int8_t opcode;
215 u_int8_t byte2; /* same bits as small version */
216 u_int8_t unused[5];
217 u_int8_t length[2];
218 u_int8_t control;
219 };
220
221 /*
222 * When sending a mode select to a tape drive, the medium type must be 0.
223 */
224 struct scsi_mode_hdr_6
225 {
226 u_int8_t datalen;
227 u_int8_t medium_type;
228 u_int8_t dev_specific;
229 u_int8_t block_descr_len;
230 };
231
232 struct scsi_mode_hdr_10
233 {
234 u_int8_t datalen[2];
235 u_int8_t medium_type;
236 u_int8_t dev_specific;
237 u_int8_t reserved[2];
238 u_int8_t block_descr_len[2];
239 };
240
241 struct scsi_mode_block_descr
242 {
243 u_int8_t density_code;
244 u_int8_t num_blocks[3];
245 u_int8_t reserved;
246 u_int8_t block_len[3];
247 };
248
249 struct scsi_log_sense
250 {
251 u_int8_t opcode;
252 u_int8_t byte2;
253 #define SLS_SP 0x01
254 #define SLS_PPC 0x02
255 u_int8_t page;
256 #define SLS_PAGE_CODE 0x3F
257 #define SLS_ALL_PAGES_PAGE 0x00
258 #define SLS_OVERRUN_PAGE 0x01
259 #define SLS_ERROR_WRITE_PAGE 0x02
260 #define SLS_ERROR_READ_PAGE 0x03
261 #define SLS_ERROR_READREVERSE_PAGE 0x04
262 #define SLS_ERROR_VERIFY_PAGE 0x05
263 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
264 #define SLS_ERROR_LASTN_PAGE 0x07
265 #define SLS_SELF_TEST_PAGE 0x10
266 #define SLS_IE_PAGE 0x2f
267 #define SLS_PAGE_CTRL_MASK 0xC0
268 #define SLS_PAGE_CTRL_THRESHOLD 0x00
269 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
270 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
271 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
272 u_int8_t reserved[2];
273 u_int8_t paramptr[2];
274 u_int8_t length[2];
275 u_int8_t control;
276 };
277
278 struct scsi_log_select
279 {
280 u_int8_t opcode;
281 u_int8_t byte2;
282 /* SLS_SP 0x01 */
283 #define SLS_PCR 0x02
284 u_int8_t page;
285 /* SLS_PAGE_CTRL_MASK 0xC0 */
286 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
287 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
288 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
289 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
290 u_int8_t reserved[4];
291 u_int8_t length[2];
292 u_int8_t control;
293 };
294
295 struct scsi_log_header
296 {
297 u_int8_t page;
298 u_int8_t reserved;
299 u_int8_t datalen[2];
300 };
301
302 struct scsi_log_param_header {
303 u_int8_t param_code[2];
304 u_int8_t param_control;
305 #define SLP_LP 0x01
306 #define SLP_LBIN 0x02
307 #define SLP_TMC_MASK 0x0C
308 #define SLP_TMC_ALWAYS 0x00
309 #define SLP_TMC_EQUAL 0x04
310 #define SLP_TMC_NOTEQUAL 0x08
311 #define SLP_TMC_GREATER 0x0C
312 #define SLP_ETC 0x10
313 #define SLP_TSD 0x20
314 #define SLP_DS 0x40
315 #define SLP_DU 0x80
316 u_int8_t param_len;
317 };
318
319 struct scsi_control_page {
320 u_int8_t page_code;
321 u_int8_t page_length;
322 u_int8_t rlec;
323 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
324 u_int8_t queue_flags;
325 #define SCP_QUEUE_ALG_MASK 0xF0
326 #define SCP_QUEUE_ALG_RESTRICTED 0x00
327 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
328 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
329 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
330 u_int8_t eca_and_aen;
331 #define SCP_EECA 0x80 /*Enable Extended CA*/
332 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
333 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
334 #define SCP_EAENP 0x01 /*Error AEN Permission*/
335 u_int8_t reserved;
336 u_int8_t aen_holdoff_period[2];
337 };
338
339 struct scsi_cache_page {
340 u_int8_t page_code;
341 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */
342 u_int8_t page_length;
343 u_int8_t cache_flags;
344 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */
345 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */
346 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */
347 u_int8_t rw_cache_policy;
348 u_int8_t dis_prefetch[2];
349 u_int8_t min_prefetch[2];
350 u_int8_t max_prefetch[2];
351 u_int8_t max_prefetch_ceil[2];
352 };
353
354 struct scsi_info_exceptions_page {
355 u_int8_t page_code;
356 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
357 u_int8_t page_length;
358 u_int8_t info_flags;
359 #define SIEP_FLAGS_PERF 0x80
360 #define SIEP_FLAGS_EBF 0x20
361 #define SIEP_FLAGS_EWASC 0x10
362 #define SIEP_FLAGS_DEXCPT 0x08
363 #define SIEP_FLAGS_TEST 0x04
364 #define SIEP_FLAGS_EBACKERR 0x02
365 #define SIEP_FLAGS_LOGERR 0x01
366 u_int8_t mrie;
367 u_int8_t interval_timer[4];
368 u_int8_t report_count[4];
369 };
370
371 struct scsi_proto_specific_page {
372 u_int8_t page_code;
373 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
374 u_int8_t page_length;
375 u_int8_t protocol;
376 #define SPSP_PROTO_FC 0x00
377 #define SPSP_PROTO_SPI 0x01
378 #define SPSP_PROTO_SSA 0x02
379 #define SPSP_PROTO_1394 0x03
380 #define SPSP_PROTO_RDMA 0x04
381 #define SPSP_PROTO_ISCSI 0x05
382 #define SPSP_PROTO_SAS 0x06
383 #define SPSP_PROTO_ADT 0x07
384 #define SPSP_PROTO_ATA 0x08
385 #define SPSP_PROTO_NONE 0x0f
386 };
387
388 struct scsi_reserve
389 {
390 u_int8_t opcode;
391 u_int8_t byte2;
392 u_int8_t unused[2];
393 u_int8_t length;
394 u_int8_t control;
395 };
396
397 struct scsi_release
398 {
399 u_int8_t opcode;
400 u_int8_t byte2;
401 u_int8_t unused[2];
402 u_int8_t length;
403 u_int8_t control;
404 };
405
406 struct scsi_prevent
407 {
408 u_int8_t opcode;
409 u_int8_t byte2;
410 u_int8_t unused[2];
411 u_int8_t how;
412 u_int8_t control;
413 };
414 #define PR_PREVENT 0x01
415 #define PR_ALLOW 0x00
416
417 struct scsi_sync_cache
418 {
419 u_int8_t opcode;
420 u_int8_t byte2;
421 u_int8_t begin_lba[4];
422 u_int8_t reserved;
423 u_int8_t lb_count[2];
424 u_int8_t control;
425 };
426
427
428 struct scsi_changedef
429 {
430 u_int8_t opcode;
431 u_int8_t byte2;
432 u_int8_t unused1;
433 u_int8_t how;
434 u_int8_t unused[4];
435 u_int8_t datalen;
436 u_int8_t control;
437 };
438
439 struct scsi_read_buffer
440 {
441 u_int8_t opcode;
442 u_int8_t byte2;
443 #define RWB_MODE 0x07
444 #define RWB_MODE_HDR_DATA 0x00
445 #define RWB_MODE_DATA 0x02
446 #define RWB_MODE_DOWNLOAD 0x04
447 #define RWB_MODE_DOWNLOAD_SAVE 0x05
448 u_int8_t buffer_id;
449 u_int8_t offset[3];
450 u_int8_t length[3];
451 u_int8_t control;
452 };
453
454 struct scsi_write_buffer
455 {
456 u_int8_t opcode;
457 u_int8_t byte2;
458 u_int8_t buffer_id;
459 u_int8_t offset[3];
460 u_int8_t length[3];
461 u_int8_t control;
462 };
463
464 struct scsi_rw_6
465 {
466 u_int8_t opcode;
467 u_int8_t addr[3];
468 /* only 5 bits are valid in the MSB address byte */
469 #define SRW_TOPADDR 0x1F
470 u_int8_t length;
471 u_int8_t control;
472 };
473
474 struct scsi_rw_10
475 {
476 u_int8_t opcode;
477 #define SRW10_RELADDR 0x01
478 /* EBP defined for WRITE(10) only */
479 #define SRW10_EBP 0x04
480 #define SRW10_FUA 0x08
481 #define SRW10_DPO 0x10
482 u_int8_t byte2;
483 u_int8_t addr[4];
484 u_int8_t reserved;
485 u_int8_t length[2];
486 u_int8_t control;
487 };
488
489 struct scsi_rw_12
490 {
491 u_int8_t opcode;
492 #define SRW12_RELADDR 0x01
493 #define SRW12_FUA 0x08
494 #define SRW12_DPO 0x10
495 u_int8_t byte2;
496 u_int8_t addr[4];
497 u_int8_t length[4];
498 u_int8_t reserved;
499 u_int8_t control;
500 };
501
502 struct scsi_rw_16
503 {
504 u_int8_t opcode;
505 #define SRW16_RELADDR 0x01
506 #define SRW16_FUA 0x08
507 #define SRW16_DPO 0x10
508 u_int8_t byte2;
509 u_int8_t addr[8];
510 u_int8_t length[4];
511 u_int8_t reserved;
512 u_int8_t control;
513 };
514
515 struct scsi_write_same_10
516 {
517 uint8_t opcode;
518 uint8_t byte2;
519 #define SWS_LBDATA 0x02
520 #define SWS_PBDATA 0x04
521 #define SWS_UNMAP 0x08
522 #define SWS_ANCHOR 0x10
523 uint8_t addr[4];
524 uint8_t group;
525 uint8_t length[2];
526 uint8_t control;
527 };
528
529 struct scsi_write_same_16
530 {
531 uint8_t opcode;
532 uint8_t byte2;
533 uint8_t addr[8];
534 uint8_t length[4];
535 uint8_t group;
536 uint8_t control;
537 };
538
539 struct scsi_unmap
540 {
541 uint8_t opcode;
542 uint8_t byte2;
543 #define SU_ANCHOR 0x01
544 uint8_t reserved[4];
545 uint8_t group;
546 uint8_t length[2];
547 uint8_t control;
548 };
549
550 struct scsi_start_stop_unit
551 {
552 u_int8_t opcode;
553 u_int8_t byte2;
554 #define SSS_IMMED 0x01
555 u_int8_t reserved[2];
556 u_int8_t how;
557 #define SSS_START 0x01
558 #define SSS_LOEJ 0x02
559 u_int8_t control;
560 };
561
562 struct ata_pass_12 {
563 u_int8_t opcode;
564 u_int8_t protocol;
565 #define AP_PROTO_HARD_RESET (0x00 << 1)
566 #define AP_PROTO_SRST (0x01 << 1)
567 #define AP_PROTO_NON_DATA (0x03 << 1)
568 #define AP_PROTO_PIO_IN (0x04 << 1)
569 #define AP_PROTO_PIO_OUT (0x05 << 1)
570 #define AP_PROTO_DMA (0x06 << 1)
571 #define AP_PROTO_DMA_QUEUED (0x07 << 1)
572 #define AP_PROTO_DEVICE_DIAG (0x08 << 1)
573 #define AP_PROTO_DEVICE_RESET (0x09 << 1)
574 #define AP_PROTO_UDMA_IN (0x0a << 1)
575 #define AP_PROTO_UDMA_OUT (0x0b << 1)
576 #define AP_PROTO_FPDMA (0x0c << 1)
577 #define AP_PROTO_RESP_INFO (0x0f << 1)
578 #define AP_MULTI 0xe0
579 u_int8_t flags;
580 #define AP_T_LEN 0x03
581 #define AP_BB 0x04
582 #define AP_T_DIR 0x08
583 #define AP_CK_COND 0x20
584 #define AP_OFFLINE 0x60
585 u_int8_t features;
586 u_int8_t sector_count;
587 u_int8_t lba_low;
588 u_int8_t lba_mid;
589 u_int8_t lba_high;
590 u_int8_t device;
591 u_int8_t command;
592 u_int8_t reserved;
593 u_int8_t control;
594 };
595
596 struct ata_pass_16 {
597 u_int8_t opcode;
598 u_int8_t protocol;
599 #define AP_EXTEND 0x01
600 u_int8_t flags;
601 #define AP_FLAG_TLEN_NO_DATA (0 << 0)
602 #define AP_FLAG_TLEN_FEAT (1 << 0)
603 #define AP_FLAG_TLEN_SECT_CNT (2 << 0)
604 #define AP_FLAG_TLEN_STPSIU (3 << 0)
605 #define AP_FLAG_BYT_BLOK_BYTES (0 << 2)
606 #define AP_FLAG_BYT_BLOK_BLOCKS (1 << 2)
607 #define AP_FLAG_TDIR_TO_DEV (0 << 3)
608 #define AP_FLAG_TDIR_FROM_DEV (1 << 3)
609 #define AP_FLAG_CHK_COND (1 << 5)
610 u_int8_t features_ext;
611 u_int8_t features;
612 u_int8_t sector_count_ext;
613 u_int8_t sector_count;
614 u_int8_t lba_low_ext;
615 u_int8_t lba_low;
616 u_int8_t lba_mid_ext;
617 u_int8_t lba_mid;
618 u_int8_t lba_high_ext;
619 u_int8_t lba_high;
620 u_int8_t device;
621 u_int8_t command;
622 u_int8_t control;
623 };
624
625 #define SC_SCSI_1 0x01
626 #define SC_SCSI_2 0x03
627
628 /*
629 * Opcodes
630 */
631
632 #define TEST_UNIT_READY 0x00
633 #define REQUEST_SENSE 0x03
634 #define READ_6 0x08
635 #define WRITE_6 0x0A
636 #define INQUIRY 0x12
637 #define MODE_SELECT_6 0x15
638 #define MODE_SENSE_6 0x1A
639 #define START_STOP_UNIT 0x1B
640 #define START_STOP 0x1B
641 #define RESERVE 0x16
642 #define RELEASE 0x17
643 #define RECEIVE_DIAGNOSTIC 0x1C
644 #define SEND_DIAGNOSTIC 0x1D
645 #define PREVENT_ALLOW 0x1E
646 #define READ_CAPACITY 0x25
647 #define READ_10 0x28
648 #define WRITE_10 0x2A
649 #define POSITION_TO_ELEMENT 0x2B
650 #define SYNCHRONIZE_CACHE 0x35
651 #define READ_DEFECT_DATA_10 0x37
652 #define WRITE_BUFFER 0x3B
653 #define READ_BUFFER 0x3C
654 #define CHANGE_DEFINITION 0x40
655 #define WRITE_SAME_10 0x41
656 #define UNMAP 0x42
657 #define LOG_SELECT 0x4C
658 #define LOG_SENSE 0x4D
659 #define MODE_SELECT_10 0x55
660 #define MODE_SENSE_10 0x5A
661 #define ATA_PASS_16 0x85
662 #define READ_16 0x88
663 #define WRITE_16 0x8A
664 #define WRITE_SAME_16 0x93
665 #define SERVICE_ACTION_IN 0x9E
666 #define REPORT_LUNS 0xA0
667 #define ATA_PASS_12 0xA1
668 #define MAINTENANCE_IN 0xA3
669 #define MAINTENANCE_OUT 0xA4
670 #define MOVE_MEDIUM 0xA5
671 #define READ_12 0xA8
672 #define WRITE_12 0xAA
673 #define READ_ELEMENT_STATUS 0xB8
674 #define READ_CD 0xBE
675
676 /* Maintenance In Service Action Codes */
677 #define REPORT_IDENTIFYING_INFRMATION 0x05
678 #define REPORT_TARGET_PORT_GROUPS 0x0A
679 #define REPORT_ALIASES 0x0B
680 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C
681 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D
682 #define REPORT_PRIORITY 0x0E
683 #define REPORT_TIMESTAMP 0x0F
684 #define MANAGEMENT_PROTOCOL_IN 0x10
685 /* Maintenance Out Service Action Codes */
686 #define SET_IDENTIFY_INFORMATION 0x06
687 #define SET_TARGET_PORT_GROUPS 0x0A
688 #define CHANGE_ALIASES 0x0B
689 #define SET_PRIORITY 0x0E
690 #define SET_TIMESTAMP 0x0F
691 #define MANGAEMENT_PROTOCOL_OUT 0x10
692
693 /*
694 * Device Types
695 */
696 #define T_DIRECT 0x00
697 #define T_SEQUENTIAL 0x01
698 #define T_PRINTER 0x02
699 #define T_PROCESSOR 0x03
700 #define T_WORM 0x04
701 #define T_CDROM 0x05
702 #define T_SCANNER 0x06
703 #define T_OPTICAL 0x07
704 #define T_CHANGER 0x08
705 #define T_COMM 0x09
706 #define T_ASC0 0x0a
707 #define T_ASC1 0x0b
708 #define T_STORARRAY 0x0c
709 #define T_ENCLOSURE 0x0d
710 #define T_RBC 0x0e
711 #define T_OCRW 0x0f
712 #define T_OSD 0x11
713 #define T_ADC 0x12
714 #define T_NODEVICE 0x1f
715 #define T_ANY 0xff /* Used in Quirk table matches */
716
717 #define T_REMOV 1
718 #define T_FIXED 0
719
720 /*
721 * This length is the initial inquiry length used by the probe code, as
722 * well as the length necessary for scsi_print_inquiry() to function
723 * correctly. If either use requires a different length in the future,
724 * the two values should be de-coupled.
725 */
726 #define SHORT_INQUIRY_LENGTH 36
727
728 struct scsi_inquiry_data
729 {
730 u_int8_t device;
731 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
732 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
733 #define SID_QUAL_LU_CONNECTED 0x00 /*
734 * The specified peripheral device
735 * type is currently connected to
736 * logical unit. If the target cannot
737 * determine whether or not a physical
738 * device is currently connected, it
739 * shall also use this peripheral
740 * qualifier when returning the INQUIRY
741 * data. This peripheral qualifier
742 * does not mean that the device is
743 * ready for access by the initiator.
744 */
745 #define SID_QUAL_LU_OFFLINE 0x01 /*
746 * The target is capable of supporting
747 * the specified peripheral device type
748 * on this logical unit; however, the
749 * physical device is not currently
750 * connected to this logical unit.
751 */
752 #define SID_QUAL_RSVD 0x02
753 #define SID_QUAL_BAD_LU 0x03 /*
754 * The target is not capable of
755 * supporting a physical device on
756 * this logical unit. For this
757 * peripheral qualifier the peripheral
758 * device type shall be set to 1Fh to
759 * provide compatibility with previous
760 * versions of SCSI. All other
761 * peripheral device type values are
762 * reserved for this peripheral
763 * qualifier.
764 */
765 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
766 u_int8_t dev_qual2;
767 #define SID_QUAL2 0x7F
768 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
769 u_int8_t version;
770 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
771 #define SCSI_REV_0 0
772 #define SCSI_REV_CCS 1
773 #define SCSI_REV_2 2
774 #define SCSI_REV_SPC 3
775 #define SCSI_REV_SPC2 4
776 #define SCSI_REV_SPC3 5
777 #define SCSI_REV_SPC4 6
778
779 #define SID_ECMA 0x38
780 #define SID_ISO 0xC0
781 u_int8_t response_format;
782 #define SID_AENC 0x80
783 #define SID_TrmIOP 0x40
784 u_int8_t additional_length;
785 #define SID_ADDITIONAL_LENGTH(iqd) \
786 ((iqd)->additional_length + \
787 offsetof(struct scsi_inquiry_data, additional_length) + 1)
788 u_int8_t spc3_flags;
789 #define SPC3_SID_PROTECT 0x01
790 #define SPC3_SID_3PC 0x08
791 #define SPC3_SID_TPGS_MASK 0x30
792 #define SPC3_SID_TPGS_IMPLICIT 0x10
793 #define SPC3_SID_TPGS_EXPLICIT 0x20
794 #define SPC3_SID_ACC 0x40
795 #define SPC3_SID_SCCS 0x80
796 u_int8_t spc2_flags;
797 #define SPC2_SID_MChngr 0x08
798 #define SPC2_SID_MultiP 0x10
799 #define SPC2_SID_EncServ 0x40
800 #define SPC2_SID_BQueue 0x80
801
802 #define INQ_DATA_TQ_ENABLED(iqd) \
803 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
804 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
805 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
806
807 u_int8_t flags;
808 #define SID_SftRe 0x01
809 #define SID_CmdQue 0x02
810 #define SID_Linked 0x08
811 #define SID_Sync 0x10
812 #define SID_WBus16 0x20
813 #define SID_WBus32 0x40
814 #define SID_RelAdr 0x80
815 #define SID_VENDOR_SIZE 8
816 char vendor[SID_VENDOR_SIZE];
817 #define SID_PRODUCT_SIZE 16
818 char product[SID_PRODUCT_SIZE];
819 #define SID_REVISION_SIZE 4
820 char revision[SID_REVISION_SIZE];
821 /*
822 * The following fields were taken from SCSI Primary Commands - 2
823 * (SPC-2) Revision 14, Dated 11 November 1999
824 */
825 #define SID_VENDOR_SPECIFIC_0_SIZE 20
826 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
827 /*
828 * An extension of SCSI Parallel Specific Values
829 */
830 #define SID_SPI_IUS 0x01
831 #define SID_SPI_QAS 0x02
832 #define SID_SPI_CLOCK_ST 0x00
833 #define SID_SPI_CLOCK_DT 0x04
834 #define SID_SPI_CLOCK_DT_ST 0x0C
835 #define SID_SPI_MASK 0x0F
836 u_int8_t spi3data;
837 u_int8_t reserved2;
838 /*
839 * Version Descriptors, stored 2 byte values.
840 */
841 u_int8_t version1[2];
842 u_int8_t version2[2];
843 u_int8_t version3[2];
844 u_int8_t version4[2];
845 u_int8_t version5[2];
846 u_int8_t version6[2];
847 u_int8_t version7[2];
848 u_int8_t version8[2];
849
850 u_int8_t reserved3[22];
851
852 #define SID_VENDOR_SPECIFIC_1_SIZE 160
853 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
854 };
855
856 struct scsi_vpd_supported_page_list
857 {
858 u_int8_t device;
859 u_int8_t page_code;
860 #define SVPD_SUPPORTED_PAGE_LIST 0x00
861 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4
862 u_int8_t reserved;
863 u_int8_t length; /* number of VPD entries */
864 #define SVPD_SUPPORTED_PAGES_SIZE 251
865 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
866 };
867
868 /*
869 * This structure is more suited to target operation, because the
870 * number of supported pages is left to the user to allocate.
871 */
872 struct scsi_vpd_supported_pages
873 {
874 u_int8_t device;
875 u_int8_t page_code;
876 u_int8_t reserved;
877 #define SVPD_SUPPORTED_PAGES 0x00
878 u_int8_t length;
879 u_int8_t page_list[0];
880 };
881
882 struct scsi_vpd_unit_serial_number
883 {
884 u_int8_t device;
885 u_int8_t page_code;
886 #define SVPD_UNIT_SERIAL_NUMBER 0x80
887 u_int8_t reserved;
888 u_int8_t length; /* serial number length */
889 #define SVPD_SERIAL_NUM_SIZE 251
890 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
891 };
892
893 /*
894 * ATA Information VPD Page based on
895 * T10/2126-D Revision 04
896 */
897 #define SVPD_ATA_INFORMATION 0x89
898
899 /*
900 * Block Device Characteristics VPD Page based on
901 * T10/1799-D Revision 31
902 */
903 struct scsi_vpd_block_characteristics
904 {
905 u_int8_t device;
906 u_int8_t page_code;
907 #define SVPD_BDC 0xB1
908 u_int8_t page_length[2];
909 u_int8_t medium_rotation_rate[2];
910 #define SVPD_BDC_RATE_NOT_REPORTED 0x00
911 #define SVPD_BDC_RATE_NONE_ROTATING 0x01
912 u_int8_t reserved1;
913 u_int8_t nominal_form_factor;
914 #define SVPD_BDC_FORM_NOT_REPORTED 0x00
915 #define SVPD_BDC_FORM_5_25INCH 0x01
916 #define SVPD_BDC_FORM_3_5INCH 0x02
917 #define SVPD_BDC_FORM_2_5INCH 0x03
918 #define SVPD_BDC_FORM_1_5INCH 0x04
919 #define SVPD_BDC_FORM_LESSTHAN_1_5INCH 0x05
920 u_int8_t reserved2[56];
921 };
922
923 /*
924 * Logical Block Provisioning VPD Page based on
925 * T10/1799-D Revision 31
926 */
927 struct scsi_vpd_logical_block_prov
928 {
929 u_int8_t device;
930 u_int8_t page_code;
931 #define SVPD_LBP 0xB2
932 u_int8_t page_length[2];
933 #define SVPD_LBP_PL_BASIC 0x04
934 u_int8_t threshold_exponent;
935 u_int8_t flags;
936 #define SVPD_LBP_UNMAP 0x80
937 #define SVPD_LBP_WS16 0x40
938 #define SVPD_LBP_WS10 0x20
939 #define SVPD_LBP_RZ 0x04
940 #define SVPD_LBP_ANC_SUP 0x02
941 #define SVPD_LBP_DP 0x01
942 u_int8_t prov_type;
943 #define SVPD_LBP_RESOURCE 0x01
944 #define SVPD_LBP_THIN 0x02
945 u_int8_t reserved;
946 /*
947 * Provisioning Group Descriptor can be here if SVPD_LBP_DP is set
948 * Its size can be determined from page_length - 4
949 */
950 };
951
952 /*
953 * Block Limits VDP Page based on
954 * T10/1799-D Revision 31
955 */
956 struct scsi_vpd_block_limits
957 {
958 u_int8_t device;
959 u_int8_t page_code;
960 #define SVPD_BLOCK_LIMITS 0xB0
961 u_int8_t page_length[2];
962 #define SVPD_BL_PL_BASIC 0x10
963 #define SVPD_BL_PL_TP 0x3C
964 u_int8_t reserved1;
965 u_int8_t max_cmp_write_len;
966 u_int8_t opt_txfer_len_grain[2];
967 u_int8_t max_txfer_len[4];
968 u_int8_t opt_txfer_len[4];
969 u_int8_t max_prefetch[4];
970 u_int8_t max_unmap_lba_cnt[4];
971 u_int8_t max_unmap_blk_cnt[4];
972 u_int8_t opt_unmap_grain[4];
973 u_int8_t unmap_grain_align[4];
974 u_int8_t max_write_same_length[8];
975 u_int8_t reserved2[20];
976 };
977
978 struct scsi_read_capacity
979 {
980 u_int8_t opcode;
981 u_int8_t byte2;
982 u_int8_t addr[4];
983 u_int8_t unused[3];
984 u_int8_t control;
985 };
986
987 struct scsi_read_capacity_16
988 {
989 uint8_t opcode;
990 #define SRC16_SERVICE_ACTION 0x10
991 uint8_t service_action;
992 uint8_t addr[8];
993 uint8_t alloc_len[4];
994 #define SRC16_PMI 0x01
995 #define SRC16_RELADR 0x02
996 uint8_t reladr;
997 uint8_t control;
998 };
999
1000 struct scsi_read_capacity_data
1001 {
1002 u_int8_t addr[4];
1003 u_int8_t length[4];
1004 };
1005
1006 struct scsi_read_capacity_data_long
1007 {
1008 uint8_t addr[8];
1009 uint8_t length[4];
1010 #define SRC16_PROT_EN 0x01
1011 #define SRC16_P_TYPE 0x0e
1012 uint8_t prot;
1013 #define SRC16_LBPPBE 0x0f
1014 #define SRC16_PI_EXPONENT 0xf0
1015 #define SRC16_PI_EXPONENT_SHIFT 4
1016 uint8_t prot_lbppbe;
1017 #define SRC16_LALBA 0x3fff
1018 #define SRC16_LBPRZ 0x4000
1019 #define SRC16_LBPME 0x8000
1020 uint8_t lalba_lbp[2];
1021 };
1022
1023 struct scsi_report_luns
1024 {
1025 uint8_t opcode;
1026 uint8_t reserved1;
1027 #define RPL_REPORT_DEFAULT 0x00
1028 #define RPL_REPORT_WELLKNOWN 0x01
1029 #define RPL_REPORT_ALL 0x02
1030 uint8_t select_report;
1031 uint8_t reserved2[3];
1032 uint8_t length[4];
1033 uint8_t reserved3;
1034 uint8_t control;
1035 };
1036
1037 struct scsi_report_luns_data {
1038 u_int8_t length[4]; /* length of LUN inventory, in bytes */
1039 u_int8_t reserved[4]; /* unused */
1040 /*
1041 * LUN inventory- we only support the type zero form for now.
1042 */
1043 struct {
1044 u_int8_t lundata[8];
1045 } luns[0];
1046 };
1047 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
1048 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
1049 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
1050 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
1051 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
1052 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
1053 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
1054 #define RPL_LUNDATA_EXT_EAM_WK 0x01
1055 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
1056 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
1057 #define RPL_LUNDATA_ATYP_PERIPH 0x00
1058 #define RPL_LUNDATA_ATYP_FLAT 0x40
1059 #define RPL_LUNDATA_ATYP_LUN 0x80
1060 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
1061
1062 struct scsi_target_group
1063 {
1064 uint8_t opcode;
1065 uint8_t service_action;
1066 #define STG_PDF_LENGTH 0x00
1067 #define RPL_PDF_EXTENDED 0x20
1068 uint8_t reserved1[4];
1069 uint8_t length[4];
1070 uint8_t reserved2;
1071 uint8_t control;
1072 };
1073
1074 struct scsi_target_port_descriptor {
1075 uint8_t reserved[2];
1076 uint8_t relative_target_port_identifier[2];
1077 uint8_t desc_list[];
1078 };
1079
1080 struct scsi_target_port_group_descriptor {
1081 uint8_t pref_state;
1082 #define TPG_PRIMARY 0x80
1083 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf
1084 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0
1085 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1
1086 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2
1087 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3
1088 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4
1089 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE
1090 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF
1091 uint8_t support;
1092 #define TPG_AO_SUP 0x01
1093 #define TPG_AN_SUP 0x02
1094 #define TPG_S_SUP 0x04
1095 #define TPG_U_SUP 0x08
1096 #define TPG_LBD_SUP 0x10
1097 #define TPG_O_SUP 0x40
1098 #define TPG_T_SUP 0x80
1099 uint8_t target_port_group[2];
1100 uint8_t reserved;
1101 uint8_t status;
1102 uint8_t vendor_specific;
1103 uint8_t target_port_count;
1104 struct scsi_target_port_descriptor descriptors[];
1105 };
1106
1107 struct scsi_target_group_data {
1108 uint8_t length[4]; /* length of returned data, in bytes */
1109 struct scsi_target_port_group_descriptor groups[];
1110 };
1111
1112 struct scsi_target_group_data_extended {
1113 uint8_t length[4]; /* length of returned data, in bytes */
1114 uint8_t format_type; /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */
1115 uint8_t implicit_transition_time;
1116 uint8_t reserved[2];
1117 struct scsi_target_port_group_descriptor groups[];
1118 };
1119
1120
1121 struct scsi_sense_data
1122 {
1123 u_int8_t error_code;
1124 #define SSD_ERRCODE 0x7F
1125 #define SSD_CURRENT_ERROR 0x70
1126 #define SSD_DEFERRED_ERROR 0x71
1127 #define SSD_ERRCODE_VALID 0x80
1128 u_int8_t segment;
1129 u_int8_t flags;
1130 #define SSD_KEY 0x0F
1131 #define SSD_KEY_NO_SENSE 0x00
1132 #define SSD_KEY_RECOVERED_ERROR 0x01
1133 #define SSD_KEY_NOT_READY 0x02
1134 #define SSD_KEY_MEDIUM_ERROR 0x03
1135 #define SSD_KEY_HARDWARE_ERROR 0x04
1136 #define SSD_KEY_ILLEGAL_REQUEST 0x05
1137 #define SSD_KEY_UNIT_ATTENTION 0x06
1138 #define SSD_KEY_DATA_PROTECT 0x07
1139 #define SSD_KEY_BLANK_CHECK 0x08
1140 #define SSD_KEY_Vendor_Specific 0x09
1141 #define SSD_KEY_COPY_ABORTED 0x0a
1142 #define SSD_KEY_ABORTED_COMMAND 0x0b
1143 #define SSD_KEY_EQUAL 0x0c
1144 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
1145 #define SSD_KEY_MISCOMPARE 0x0e
1146 #define SSD_KEY_RESERVED 0x0f
1147 #define SSD_ILI 0x20
1148 #define SSD_EOM 0x40
1149 #define SSD_FILEMARK 0x80
1150 u_int8_t info[4];
1151 u_int8_t extra_len;
1152 u_int8_t cmd_spec_info[4];
1153 u_int8_t add_sense_code;
1154 u_int8_t add_sense_code_qual;
1155 u_int8_t fru;
1156 u_int8_t sense_key_spec[3];
1157 #define SSD_SCS_VALID 0x80
1158 #define SSD_FIELDPTR_CMD 0x40
1159 #define SSD_BITPTR_VALID 0x08
1160 #define SSD_BITPTR_VALUE 0x07
1161 #define SSD_MIN_SIZE 18
1162 u_int8_t extra_bytes[14];
1163 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
1164 };
1165
1166 struct scsi_mode_header_6
1167 {
1168 u_int8_t data_length; /* Sense data length */
1169 u_int8_t medium_type;
1170 u_int8_t dev_spec;
1171 u_int8_t blk_desc_len;
1172 };
1173
1174 struct scsi_mode_header_10
1175 {
1176 u_int8_t data_length[2];/* Sense data length */
1177 u_int8_t medium_type;
1178 u_int8_t dev_spec;
1179 u_int8_t unused[2];
1180 u_int8_t blk_desc_len[2];
1181 };
1182
1183 struct scsi_mode_page_header
1184 {
1185 u_int8_t page_code;
1186 u_int8_t page_length;
1187 };
1188
1189 struct scsi_mode_blk_desc
1190 {
1191 u_int8_t density;
1192 u_int8_t nblocks[3];
1193 u_int8_t reserved;
1194 u_int8_t blklen[3];
1195 };
1196
1197 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
1198 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
1199
1200
1201 /*
1202 * Status Byte
1203 */
1204 #define SCSI_STATUS_OK 0x00
1205 #define SCSI_STATUS_CHECK_COND 0x02
1206 #define SCSI_STATUS_COND_MET 0x04
1207 #define SCSI_STATUS_BUSY 0x08
1208 #define SCSI_STATUS_INTERMED 0x10
1209 #define SCSI_STATUS_INTERMED_COND_MET 0x14
1210 #define SCSI_STATUS_RESERV_CONFLICT 0x18
1211 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
1212 #define SCSI_STATUS_QUEUE_FULL 0x28
1213 #define SCSI_STATUS_ACA_ACTIVE 0x30
1214 #define SCSI_STATUS_TASK_ABORTED 0x40
1215
1216 struct scsi_inquiry_pattern {
1217 u_int8_t type;
1218 u_int8_t media_type;
1219 #define SIP_MEDIA_REMOVABLE 0x01
1220 #define SIP_MEDIA_FIXED 0x02
1221 const char *vendor;
1222 const char *product;
1223 const char *revision;
1224 };
1225
1226 struct scsi_static_inquiry_pattern {
1227 u_int8_t type;
1228 u_int8_t media_type;
1229 char vendor[SID_VENDOR_SIZE+1];
1230 char product[SID_PRODUCT_SIZE+1];
1231 char revision[SID_REVISION_SIZE+1];
1232 };
1233
1234 struct scsi_sense_quirk_entry {
1235 struct scsi_inquiry_pattern inq_pat;
1236 int num_sense_keys;
1237 int num_ascs;
1238 struct sense_key_table_entry *sense_key_info;
1239 struct asc_table_entry *asc_info;
1240 };
1241
1242 struct sense_key_table_entry {
1243 u_int8_t sense_key;
1244 u_int32_t action;
1245 const char *desc;
1246 };
1247
1248 struct asc_table_entry {
1249 u_int8_t asc;
1250 u_int8_t ascq;
1251 u_int32_t action;
1252 const char *desc;
1253 };
1254
1255 struct op_table_entry {
1256 u_int8_t opcode;
1257 u_int32_t opmask;
1258 const char *desc;
1259 };
1260
1261 struct scsi_op_quirk_entry {
1262 struct scsi_inquiry_pattern inq_pat;
1263 int num_ops;
1264 struct op_table_entry *op_table;
1265 };
1266
1267 typedef enum {
1268 SSS_FLAG_NONE = 0x00,
1269 SSS_FLAG_PRINT_COMMAND = 0x01
1270 } scsi_sense_string_flags;
1271
1272 struct ccb_scsiio;
1273 struct cam_periph;
1274 union ccb;
1275 #ifndef _KERNEL
1276 struct cam_device;
1277 #endif
1278
1279 extern const char *scsi_sense_key_text[];
1280
1281 struct sbuf;
1282
1283 __BEGIN_DECLS
1284 void scsi_sense_desc(int sense_key, int asc, int ascq,
1285 struct scsi_inquiry_data *inq_data,
1286 const char **sense_key_desc, const char **asc_desc);
1287 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1288 struct scsi_inquiry_data *inq_data,
1289 u_int32_t sense_flags);
1290 const char * scsi_status_string(struct ccb_scsiio *csio);
1291 #ifdef _KERNEL
1292 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
1293 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1294 scsi_sense_string_flags flags);
1295 char * scsi_sense_string(struct ccb_scsiio *csio,
1296 char *str, int str_len);
1297 void scsi_sense_print(struct ccb_scsiio *csio);
1298 int scsi_vpd_supported_page(struct cam_periph *periph,
1299 uint8_t page_id);
1300 #else /* _KERNEL */
1301 int scsi_command_string(struct cam_device *device,
1302 struct ccb_scsiio *csio, struct sbuf *sb);
1303 int scsi_sense_sbuf(struct cam_device *device,
1304 struct ccb_scsiio *csio, struct sbuf *sb,
1305 scsi_sense_string_flags flags);
1306 char * scsi_sense_string(struct cam_device *device,
1307 struct ccb_scsiio *csio,
1308 char *str, int str_len);
1309 void scsi_sense_print(struct cam_device *device,
1310 struct ccb_scsiio *csio, FILE *ofile);
1311 #endif /* _KERNEL */
1312
1313 #define SF_RETRY_UA 0x01
1314 #define SF_NO_PRINT 0x02
1315 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
1316 #define SF_PRINT_ALWAYS 0x08
1317
1318
1319 const char * scsi_op_desc(u_int16_t opcode,
1320 struct scsi_inquiry_data *inq_data);
1321 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
1322 size_t len);
1323
1324 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
1325
1326 u_int scsi_calc_syncsrate(u_int period_factor);
1327 u_int scsi_calc_syncparam(u_int period);
1328
1329 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
1330 void (*cbfcnp)(struct cam_periph *,
1331 union ccb *),
1332 u_int8_t tag_action,
1333 u_int8_t sense_len, u_int32_t timeout);
1334
1335 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
1336 void (*cbfcnp)(struct cam_periph *,
1337 union ccb *),
1338 void *data_ptr, u_int8_t dxfer_len,
1339 u_int8_t tag_action, u_int8_t sense_len,
1340 u_int32_t timeout);
1341
1342 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
1343 void (*cbfcnp)(struct cam_periph *, union ccb *),
1344 u_int8_t tag_action, u_int8_t *inq_buf,
1345 u_int32_t inq_len, int evpd, u_int8_t page_code,
1346 u_int8_t sense_len, u_int32_t timeout);
1347
1348 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
1349 void (*cbfcnp)(struct cam_periph *,
1350 union ccb *),
1351 u_int8_t tag_action, int dbd,
1352 u_int8_t page_code, u_int8_t page,
1353 u_int8_t *param_buf, u_int32_t param_len,
1354 u_int8_t sense_len, u_int32_t timeout);
1355
1356 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
1357 void (*cbfcnp)(struct cam_periph *,
1358 union ccb *),
1359 u_int8_t tag_action, int dbd,
1360 u_int8_t page_code, u_int8_t page,
1361 u_int8_t *param_buf, u_int32_t param_len,
1362 int minimum_cmd_size, u_int8_t sense_len,
1363 u_int32_t timeout);
1364
1365 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1366 void (*cbfcnp)(struct cam_periph *,
1367 union ccb *),
1368 u_int8_t tag_action, int scsi_page_fmt,
1369 int save_pages, u_int8_t *param_buf,
1370 u_int32_t param_len, u_int8_t sense_len,
1371 u_int32_t timeout);
1372
1373 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1374 void (*cbfcnp)(struct cam_periph *,
1375 union ccb *),
1376 u_int8_t tag_action, int scsi_page_fmt,
1377 int save_pages, u_int8_t *param_buf,
1378 u_int32_t param_len, int minimum_cmd_size,
1379 u_int8_t sense_len, u_int32_t timeout);
1380
1381 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1382 void (*cbfcnp)(struct cam_periph *, union ccb *),
1383 u_int8_t tag_action, u_int8_t page_code,
1384 u_int8_t page, int save_pages, int ppc,
1385 u_int32_t paramptr, u_int8_t *param_buf,
1386 u_int32_t param_len, u_int8_t sense_len,
1387 u_int32_t timeout);
1388
1389 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1390 void (*cbfcnp)(struct cam_periph *,
1391 union ccb *), u_int8_t tag_action,
1392 u_int8_t page_code, int save_pages,
1393 int pc_reset, u_int8_t *param_buf,
1394 u_int32_t param_len, u_int8_t sense_len,
1395 u_int32_t timeout);
1396
1397 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1398 void (*cbfcnp)(struct cam_periph *, union ccb *),
1399 u_int8_t tag_action, u_int8_t action,
1400 u_int8_t sense_len, u_int32_t timeout);
1401
1402 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1403 void (*cbfcnp)(struct cam_periph *,
1404 union ccb *), u_int8_t tag_action,
1405 struct scsi_read_capacity_data *,
1406 u_int8_t sense_len, u_int32_t timeout);
1407 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1408 void (*cbfcnp)(struct cam_periph *,
1409 union ccb *), uint8_t tag_action,
1410 uint64_t lba, int reladr, int pmi,
1411 struct scsi_read_capacity_data_long
1412 *rcap_buf, uint8_t sense_len,
1413 uint32_t timeout);
1414
1415 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1416 void (*cbfcnp)(struct cam_periph *,
1417 union ccb *), u_int8_t tag_action,
1418 u_int8_t select_report,
1419 struct scsi_report_luns_data *rpl_buf,
1420 u_int32_t alloc_len, u_int8_t sense_len,
1421 u_int32_t timeout);
1422
1423 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
1424 void (*cbfcnp)(struct cam_periph *,
1425 union ccb *), u_int8_t tag_action,
1426 u_int8_t pdf,
1427 void *buf,
1428 u_int32_t alloc_len, u_int8_t sense_len,
1429 u_int32_t timeout);
1430
1431 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
1432 void (*cbfcnp)(struct cam_periph *,
1433 union ccb *), u_int8_t tag_action, void *buf,
1434 u_int32_t alloc_len, u_int8_t sense_len,
1435 u_int32_t timeout);
1436
1437 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1438 u_int32_t retries,
1439 void (*cbfcnp)(struct cam_periph *,
1440 union ccb *), u_int8_t tag_action,
1441 u_int32_t begin_lba, u_int16_t lb_count,
1442 u_int8_t sense_len, u_int32_t timeout);
1443
1444 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1445 void (*cbfcnp)(struct cam_periph *, union ccb *),
1446 u_int8_t tag_action, int readop, u_int8_t byte2,
1447 int minimum_cmd_size, u_int64_t lba,
1448 u_int32_t block_count, u_int8_t *data_ptr,
1449 u_int32_t dxfer_len, u_int8_t sense_len,
1450 u_int32_t timeout);
1451
1452 void scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
1453 void (*cbfcnp)(struct cam_periph *, union ccb *),
1454 u_int8_t tag_action, u_int8_t byte2,
1455 int minimum_cmd_size, u_int64_t lba,
1456 u_int32_t block_count, u_int8_t *data_ptr,
1457 u_int32_t dxfer_len, u_int8_t sense_len,
1458 u_int32_t timeout);
1459
1460 void scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
1461 void (*cbfcnp)(struct cam_periph *, union ccb *),
1462 u_int8_t tag_action, u_int8_t *data_ptr,
1463 u_int16_t dxfer_len, u_int8_t sense_len,
1464 u_int32_t timeout);
1465
1466 void scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
1467 void (*cbfcnp)(struct cam_periph *, union ccb *),
1468 u_int8_t tag_action, u_int16_t block_count,
1469 u_int8_t *data_ptr, u_int16_t dxfer_len,
1470 u_int8_t sense_len, u_int32_t timeout);
1471
1472 void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
1473 void (*cbfcnp)(struct cam_periph *, union ccb *),
1474 u_int32_t flags, u_int8_t tag_action,
1475 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
1476 u_int16_t sector_count, uint64_t lba, u_int8_t command,
1477 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
1478 u_int8_t sense_len, u_int32_t timeout);
1479
1480 void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
1481 void (*cbfcnp)(struct cam_periph *, union ccb *),
1482 u_int8_t tag_action, u_int8_t byte2,
1483 u_int8_t *data_ptr, u_int16_t dxfer_len,
1484 u_int8_t sense_len, u_int32_t timeout);
1485
1486 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1487 void (*cbfcnp)(struct cam_periph *, union ccb *),
1488 u_int8_t tag_action, int start, int load_eject,
1489 int immediate, u_int8_t sense_len, u_int32_t timeout);
1490
1491 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1492 int scsi_static_inquiry_match(caddr_t inqbuffer,
1493 caddr_t table_entry);
1494
1495 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1496 int *error_code, int *sense_key,
1497 int *asc, int *ascq);
1498 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1499 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1500 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1501 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1502 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1503 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1504 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1505 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1506 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1507 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1508 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1509
1510 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1511 int *error_code, int *sense_key,
1512 int *asc, int *ascq)
1513 {
1514 *error_code = sense->error_code & SSD_ERRCODE;
1515 *sense_key = sense->flags & SSD_KEY;
1516 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1517 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1518 }
1519
1520 static __inline void
1521 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1522 {
1523
1524 bytes[0] = (val >> 8) & 0xff;
1525 bytes[1] = val & 0xff;
1526 }
1527
1528 static __inline void
1529 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1530 {
1531
1532 bytes[0] = (val >> 16) & 0xff;
1533 bytes[1] = (val >> 8) & 0xff;
1534 bytes[2] = val & 0xff;
1535 }
1536
1537 static __inline void
1538 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1539 {
1540
1541 bytes[0] = (val >> 24) & 0xff;
1542 bytes[1] = (val >> 16) & 0xff;
1543 bytes[2] = (val >> 8) & 0xff;
1544 bytes[3] = val & 0xff;
1545 }
1546
1547 static __inline void
1548 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1549 {
1550
1551 bytes[0] = (val >> 56) & 0xff;
1552 bytes[1] = (val >> 48) & 0xff;
1553 bytes[2] = (val >> 40) & 0xff;
1554 bytes[3] = (val >> 32) & 0xff;
1555 bytes[4] = (val >> 24) & 0xff;
1556 bytes[5] = (val >> 16) & 0xff;
1557 bytes[6] = (val >> 8) & 0xff;
1558 bytes[7] = val & 0xff;
1559 }
1560
1561 static __inline u_int32_t
1562 scsi_2btoul(u_int8_t *bytes)
1563 {
1564 u_int32_t rv;
1565
1566 rv = (bytes[0] << 8) |
1567 bytes[1];
1568 return (rv);
1569 }
1570
1571 static __inline u_int32_t
1572 scsi_3btoul(u_int8_t *bytes)
1573 {
1574 u_int32_t rv;
1575
1576 rv = (bytes[0] << 16) |
1577 (bytes[1] << 8) |
1578 bytes[2];
1579 return (rv);
1580 }
1581
1582 static __inline int32_t
1583 scsi_3btol(u_int8_t *bytes)
1584 {
1585 u_int32_t rc = scsi_3btoul(bytes);
1586
1587 if (rc & 0x00800000)
1588 rc |= 0xff000000;
1589
1590 return (int32_t) rc;
1591 }
1592
1593 static __inline u_int32_t
1594 scsi_4btoul(u_int8_t *bytes)
1595 {
1596 u_int32_t rv;
1597
1598 rv = (bytes[0] << 24) |
1599 (bytes[1] << 16) |
1600 (bytes[2] << 8) |
1601 bytes[3];
1602 return (rv);
1603 }
1604
1605 static __inline uint64_t
1606 scsi_8btou64(uint8_t *bytes)
1607 {
1608 uint64_t rv;
1609
1610 rv = (((uint64_t)bytes[0]) << 56) |
1611 (((uint64_t)bytes[1]) << 48) |
1612 (((uint64_t)bytes[2]) << 40) |
1613 (((uint64_t)bytes[3]) << 32) |
1614 (((uint64_t)bytes[4]) << 24) |
1615 (((uint64_t)bytes[5]) << 16) |
1616 (((uint64_t)bytes[6]) << 8) |
1617 bytes[7];
1618 return (rv);
1619 }
1620
1621 /*
1622 * Given the pointer to a returned mode sense buffer, return a pointer to
1623 * the start of the first mode page.
1624 */
1625 static __inline void *
1626 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1627 {
1628 void *page_start;
1629
1630 page_start = (void *)((u_int8_t *)&mode_header[1] +
1631 mode_header->blk_desc_len);
1632
1633 return(page_start);
1634 }
1635
1636 static __inline void *
1637 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1638 {
1639 void *page_start;
1640
1641 page_start = (void *)((u_int8_t *)&mode_header[1] +
1642 scsi_2btoul(mode_header->blk_desc_len));
1643
1644 return(page_start);
1645 }
1646
1647 __END_DECLS
1648
1649 #endif /*_SCSI_SCSI_ALL_H*/
Cache object: 0bde8cec6a4204f9b02687824ae094eb
|