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
18 /*
19 * SCSI general interface description
20 */
21
22 #ifndef _SCSI_SCSI_ALL_H
23 #define _SCSI_SCSI_ALL_H 1
24
25 #include <sys/cdefs.h>
26 #ifdef _KERNEL
27 #include <machine/stdarg.h>
28 #else
29 #include <stdarg.h>
30 #endif
31
32 #ifdef _KERNEL
33 /*
34 * This is the number of seconds we wait for devices to settle after a SCSI
35 * bus reset.
36 */
37 extern int scsi_delay;
38 #endif /* _KERNEL */
39
40 /*
41 * SCSI command format
42 */
43
44 /*
45 * Define dome bits that are in ALL (or a lot of) scsi commands
46 */
47 #define SCSI_CTL_LINK 0x01
48 #define SCSI_CTL_FLAG 0x02
49 #define SCSI_CTL_VENDOR 0xC0
50 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
51 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
52
53 #define SCSI_MAX_CDBLEN 16 /*
54 * 16 byte commands are in the
55 * SCSI-3 spec
56 */
57 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
58 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
59 #endif
60
61 /* 6byte CDBs special case 0 length to be 256 */
62 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
63
64 /*
65 * This type defines actions to be taken when a particular sense code is
66 * received. Right now, these flags are only defined to take up 16 bits,
67 * but can be expanded in the future if necessary.
68 */
69 typedef enum {
70 SS_NOP = 0x000000, /* Do nothing */
71 SS_RETRY = 0x010000, /* Retry the command */
72 SS_FAIL = 0x020000, /* Bail out */
73 SS_START = 0x030000, /* Send a Start Unit command to the device,
74 * then retry the original command.
75 */
76 SS_TUR = 0x040000, /* Send a Test Unit Ready 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_UA = 0x1000, /* Broadcast UA. */
94 SSQ_RESCAN = 0x2000, /* Rescan target for LUNs. */
95 SSQ_LOST = 0x4000, /* Destroy the LUNs. */
96 SSQ_MASK = 0xff00
97 } scsi_sense_action_qualifier;
98
99 /* Mask for error status values */
100 #define SS_ERRMASK 0xff
101
102 /* The default, retyable, error action */
103 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
104
105 /* The retyable, error action, with table specified error code */
106 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
107
108 /* Wait for transient error status to change */
109 #define SS_WAIT SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
110
111 /* Fatal error action, with table specified error code */
112 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
113
114 struct scsi_generic
115 {
116 u_int8_t opcode;
117 u_int8_t bytes[11];
118 };
119
120 struct scsi_request_sense
121 {
122 u_int8_t opcode;
123 u_int8_t byte2;
124 #define SRS_DESC 0x01
125 u_int8_t unused[2];
126 u_int8_t length;
127 u_int8_t control;
128 };
129
130 struct scsi_test_unit_ready
131 {
132 u_int8_t opcode;
133 u_int8_t byte2;
134 u_int8_t unused[3];
135 u_int8_t control;
136 };
137
138 struct scsi_receive_diag {
139 uint8_t opcode;
140 uint8_t byte2;
141 #define SRD_PCV 0x01
142 uint8_t page_code;
143 uint8_t length[2];
144 uint8_t control;
145 };
146
147 struct scsi_send_diag {
148 uint8_t opcode;
149 uint8_t byte2;
150 #define SSD_UNITOFFL 0x01
151 #define SSD_DEVOFFL 0x02
152 #define SSD_SELFTEST 0x04
153 #define SSD_PF 0x10
154 #define SSD_SELF_TEST_CODE_MASK 0xE0
155 #define SSD_SELF_TEST_CODE_SHIFT 5
156 #define SSD_SELF_TEST_CODE_NONE 0x00
157 #define SSD_SELF_TEST_CODE_BG_SHORT 0x01
158 #define SSD_SELF_TEST_CODE_BG_EXTENDED 0x02
159 #define SSD_SELF_TEST_CODE_BG_ABORT 0x04
160 #define SSD_SELF_TEST_CODE_FG_SHORT 0x05
161 #define SSD_SELF_TEST_CODE_FG_EXTENDED 0x06
162 uint8_t reserved;
163 uint8_t length[2];
164 uint8_t control;
165 };
166
167 struct scsi_sense
168 {
169 u_int8_t opcode;
170 u_int8_t byte2;
171 u_int8_t unused[2];
172 u_int8_t length;
173 u_int8_t control;
174 };
175
176 struct scsi_inquiry
177 {
178 u_int8_t opcode;
179 u_int8_t byte2;
180 #define SI_EVPD 0x01
181 #define SI_CMDDT 0x02
182 u_int8_t page_code;
183 u_int8_t length[2];
184 u_int8_t control;
185 };
186
187 struct scsi_mode_sense_6
188 {
189 u_int8_t opcode;
190 u_int8_t byte2;
191 #define SMS_DBD 0x08
192 u_int8_t page;
193 #define SMS_PAGE_CODE 0x3F
194 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
195 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
196 #define SMS_FORMAT_DEVICE_PAGE 0x03
197 #define SMS_GEOMETRY_PAGE 0x04
198 #define SMS_CACHE_PAGE 0x08
199 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
200 #define SMS_CONTROL_MODE_PAGE 0x0A
201 #define SMS_PROTO_SPECIFIC_PAGE 0x19
202 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C
203 #define SMS_ALL_PAGES_PAGE 0x3F
204 #define SMS_PAGE_CTRL_MASK 0xC0
205 #define SMS_PAGE_CTRL_CURRENT 0x00
206 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
207 #define SMS_PAGE_CTRL_DEFAULT 0x80
208 #define SMS_PAGE_CTRL_SAVED 0xC0
209 u_int8_t subpage;
210 #define SMS_SUBPAGE_PAGE_0 0x00
211 #define SMS_SUBPAGE_ALL 0xff
212 u_int8_t length;
213 u_int8_t control;
214 };
215
216 struct scsi_mode_sense_10
217 {
218 u_int8_t opcode;
219 u_int8_t byte2; /* same bits as small version */
220 #define SMS10_LLBAA 0x10
221 u_int8_t page; /* same bits as small version */
222 u_int8_t subpage;
223 u_int8_t unused[3];
224 u_int8_t length[2];
225 u_int8_t control;
226 };
227
228 struct scsi_mode_select_6
229 {
230 u_int8_t opcode;
231 u_int8_t byte2;
232 #define SMS_SP 0x01
233 #define SMS_RTD 0x02
234 #define SMS_PF 0x10
235 u_int8_t unused[2];
236 u_int8_t length;
237 u_int8_t control;
238 };
239
240 struct scsi_mode_select_10
241 {
242 u_int8_t opcode;
243 u_int8_t byte2; /* same bits as small version */
244 u_int8_t unused[5];
245 u_int8_t length[2];
246 u_int8_t control;
247 };
248
249 /*
250 * When sending a mode select to a tape drive, the medium type must be 0.
251 */
252 struct scsi_mode_hdr_6
253 {
254 u_int8_t datalen;
255 u_int8_t medium_type;
256 u_int8_t dev_specific;
257 u_int8_t block_descr_len;
258 };
259
260 struct scsi_mode_hdr_10
261 {
262 u_int8_t datalen[2];
263 u_int8_t medium_type;
264 u_int8_t dev_specific;
265 u_int8_t flags;
266 #define SMH_LONGLBA 0x01
267 u_int8_t reserved;
268 u_int8_t block_descr_len[2];
269 };
270
271 struct scsi_mode_block_descr
272 {
273 u_int8_t density_code;
274 u_int8_t num_blocks[3];
275 u_int8_t reserved;
276 u_int8_t block_len[3];
277 };
278
279 struct scsi_mode_block_descr_dshort
280 {
281 u_int8_t num_blocks[4];
282 u_int8_t reserved;
283 u_int8_t block_len[3];
284 };
285
286 struct scsi_mode_block_descr_dlong
287 {
288 u_int8_t num_blocks[8];
289 u_int8_t reserved[4];
290 u_int8_t block_len[4];
291 };
292
293 struct scsi_per_res_in
294 {
295 u_int8_t opcode;
296 u_int8_t action;
297 #define SPRI_RK 0x00
298 #define SPRI_RR 0x01
299 #define SPRI_RC 0x02
300 #define SPRI_RS 0x03
301 u_int8_t reserved[5];
302 u_int8_t length[2];
303 #define SPRI_MAX_LEN 0xffff
304 u_int8_t control;
305 };
306
307 struct scsi_per_res_in_header
308 {
309 u_int8_t generation[4];
310 u_int8_t length[4];
311 };
312
313 struct scsi_per_res_key
314 {
315 u_int8_t key[8];
316 };
317
318 struct scsi_per_res_in_keys
319 {
320 struct scsi_per_res_in_header header;
321 struct scsi_per_res_key keys[0];
322 };
323
324 struct scsi_per_res_cap
325 {
326 uint8_t length[2];
327 uint8_t flags1;
328 #define SPRI_RLR_C 0x80
329 #define SPRI_CRH 0x10
330 #define SPRI_SIP_C 0x08
331 #define SPRI_ATP_C 0x04
332 #define SPRI_PTPL_C 0x01
333 uint8_t flags2;
334 #define SPRI_TMV 0x80
335 #define SPRI_ALLOW_CMD_MASK 0x70
336 #define SPRI_ALLOW_CMD_SHIFT 4
337 #define SPRI_ALLOW_NA 0x00
338 #define SPRI_ALLOW_1 0x10
339 #define SPRI_ALLOW_2 0x20
340 #define SPRI_ALLOW_3 0x30
341 #define SPRI_ALLOW_4 0x40
342 #define SPRI_ALLOW_5 0x50
343 #define SPRI_PTPL_A 0x01
344 uint8_t type_mask[2];
345 #define SPRI_TM_WR_EX_AR 0x8000
346 #define SPRI_TM_EX_AC_RO 0x4000
347 #define SPRI_TM_WR_EX_RO 0x2000
348 #define SPRI_TM_EX_AC 0x0800
349 #define SPRI_TM_WR_EX 0x0200
350 #define SPRI_TM_EX_AC_AR 0x0001
351 uint8_t reserved[2];
352 };
353
354 struct scsi_per_res_in_rsrv_data
355 {
356 uint8_t reservation[8];
357 uint8_t scope_addr[4];
358 uint8_t reserved;
359 uint8_t scopetype;
360 #define SPRT_WE 0x01
361 #define SPRT_EA 0x03
362 #define SPRT_WERO 0x05
363 #define SPRT_EARO 0x06
364 #define SPRT_WEAR 0x07
365 #define SPRT_EAAR 0x08
366 uint8_t extent_length[2];
367 };
368
369 struct scsi_per_res_in_rsrv
370 {
371 struct scsi_per_res_in_header header;
372 struct scsi_per_res_in_rsrv_data data;
373 };
374
375 struct scsi_per_res_in_full_desc
376 {
377 struct scsi_per_res_key res_key;
378 uint8_t reserved1[4];
379 uint8_t flags;
380 #define SPRI_FULL_ALL_TG_PT 0x02
381 #define SPRI_FULL_R_HOLDER 0x01
382 uint8_t scopetype;
383 uint8_t reserved2[4];
384 uint8_t rel_trgt_port_id[2];
385 uint8_t additional_length[4];
386 uint8_t transport_id[];
387 };
388
389 struct scsi_per_res_in_full
390 {
391 struct scsi_per_res_in_header header;
392 struct scsi_per_res_in_full_desc desc[];
393 };
394
395 struct scsi_per_res_out
396 {
397 u_int8_t opcode;
398 u_int8_t action;
399 #define SPRO_REGISTER 0x00
400 #define SPRO_RESERVE 0x01
401 #define SPRO_RELEASE 0x02
402 #define SPRO_CLEAR 0x03
403 #define SPRO_PREEMPT 0x04
404 #define SPRO_PRE_ABO 0x05
405 #define SPRO_REG_IGNO 0x06
406 #define SPRO_REG_MOVE 0x07
407 #define SPRO_REPL_LOST_RES 0x08
408 #define SPRO_ACTION_MASK 0x1f
409 u_int8_t scope_type;
410 #define SPR_SCOPE_MASK 0xf0
411 #define SPR_SCOPE_SHIFT 4
412 #define SPR_LU_SCOPE 0x00
413 #define SPR_EXTENT_SCOPE 0x10
414 #define SPR_ELEMENT_SCOPE 0x20
415 #define SPR_TYPE_MASK 0x0f
416 #define SPR_TYPE_RD_SHARED 0x00
417 #define SPR_TYPE_WR_EX 0x01
418 #define SPR_TYPE_RD_EX 0x02
419 #define SPR_TYPE_EX_AC 0x03
420 #define SPR_TYPE_SHARED 0x04
421 #define SPR_TYPE_WR_EX_RO 0x05
422 #define SPR_TYPE_EX_AC_RO 0x06
423 #define SPR_TYPE_WR_EX_AR 0x07
424 #define SPR_TYPE_EX_AC_AR 0x08
425 u_int8_t reserved[2];
426 u_int8_t length[4];
427 u_int8_t control;
428 };
429
430 struct scsi_per_res_out_parms
431 {
432 struct scsi_per_res_key res_key;
433 u_int8_t serv_act_res_key[8];
434 u_int8_t scope_spec_address[4];
435 u_int8_t flags;
436 #define SPR_SPEC_I_PT 0x08
437 #define SPR_ALL_TG_PT 0x04
438 #define SPR_APTPL 0x01
439 u_int8_t reserved1;
440 u_int8_t extent_length[2];
441 u_int8_t transport_id_list[];
442 };
443
444 struct scsi_per_res_out_trans_ids {
445 u_int8_t additional_length[4];
446 u_int8_t transport_ids[];
447 };
448
449 /*
450 * Used with REGISTER AND MOVE serivce action of the PERSISTENT RESERVE OUT
451 * command.
452 */
453 struct scsi_per_res_reg_move
454 {
455 struct scsi_per_res_key res_key;
456 u_int8_t serv_act_res_key[8];
457 u_int8_t reserved;
458 u_int8_t flags;
459 #define SPR_REG_MOVE_UNREG 0x02
460 #define SPR_REG_MOVE_APTPL 0x01
461 u_int8_t rel_trgt_port_id[2];
462 u_int8_t transport_id_length[4];
463 u_int8_t transport_id[];
464 };
465
466 struct scsi_transportid_header
467 {
468 uint8_t format_protocol;
469 #define SCSI_TRN_FORMAT_MASK 0xc0
470 #define SCSI_TRN_FORMAT_SHIFT 6
471 #define SCSI_TRN_PROTO_MASK 0x0f
472 };
473
474 struct scsi_transportid_fcp
475 {
476 uint8_t format_protocol;
477 #define SCSI_TRN_FCP_FORMAT_DEFAULT 0x00
478 uint8_t reserved1[7];
479 uint8_t n_port_name[8];
480 uint8_t reserved2[8];
481 };
482
483 struct scsi_transportid_spi
484 {
485 uint8_t format_protocol;
486 #define SCSI_TRN_SPI_FORMAT_DEFAULT 0x00
487 uint8_t reserved1;
488 uint8_t scsi_addr[2];
489 uint8_t obsolete[2];
490 uint8_t rel_trgt_port_id[2];
491 uint8_t reserved2[16];
492 };
493
494 struct scsi_transportid_1394
495 {
496 uint8_t format_protocol;
497 #define SCSI_TRN_1394_FORMAT_DEFAULT 0x00
498 uint8_t reserved1[7];
499 uint8_t eui64[8];
500 uint8_t reserved2[8];
501 };
502
503 struct scsi_transportid_rdma
504 {
505 uint8_t format_protocol;
506 #define SCSI_TRN_RDMA_FORMAT_DEFAULT 0x00
507 uint8_t reserved[7];
508 #define SCSI_TRN_RDMA_PORT_LEN 16
509 uint8_t initiator_port_id[SCSI_TRN_RDMA_PORT_LEN];
510 };
511
512 struct scsi_transportid_iscsi_device
513 {
514 uint8_t format_protocol;
515 #define SCSI_TRN_ISCSI_FORMAT_DEVICE 0x00
516 uint8_t reserved;
517 uint8_t additional_length[2];
518 uint8_t iscsi_name[];
519 };
520
521 struct scsi_transportid_iscsi_port
522 {
523 uint8_t format_protocol;
524 #define SCSI_TRN_ISCSI_FORMAT_PORT 0x40
525 uint8_t reserved;
526 uint8_t additional_length[2];
527 uint8_t iscsi_name[];
528 /*
529 * Followed by a separator and iSCSI initiator session ID
530 */
531 };
532
533 struct scsi_transportid_sas
534 {
535 uint8_t format_protocol;
536 #define SCSI_TRN_SAS_FORMAT_DEFAULT 0x00
537 uint8_t reserved1[3];
538 uint8_t sas_address[8];
539 uint8_t reserved2[12];
540 };
541
542 struct scsi_sop_routing_id_norm {
543 uint8_t bus;
544 uint8_t devfunc;
545 #define SCSI_TRN_SOP_BUS_MAX 0xff
546 #define SCSI_TRN_SOP_DEV_MAX 0x1f
547 #define SCSI_TRN_SOP_DEV_MASK 0xf8
548 #define SCSI_TRN_SOP_DEV_SHIFT 3
549 #define SCSI_TRN_SOP_FUNC_NORM_MASK 0x07
550 #define SCSI_TRN_SOP_FUNC_NORM_MAX 0x07
551 };
552
553 struct scsi_sop_routing_id_alt {
554 uint8_t bus;
555 uint8_t function;
556 #define SCSI_TRN_SOP_FUNC_ALT_MAX 0xff
557 };
558
559 struct scsi_transportid_sop
560 {
561 uint8_t format_protocol;
562 #define SCSI_TRN_SOP_FORMAT_DEFAULT 0x00
563 uint8_t reserved1;
564 uint8_t routing_id[2];
565 uint8_t reserved2[20];
566 };
567
568 struct scsi_log_sense
569 {
570 u_int8_t opcode;
571 u_int8_t byte2;
572 #define SLS_SP 0x01
573 #define SLS_PPC 0x02
574 u_int8_t page;
575 #define SLS_PAGE_CODE 0x3F
576 #define SLS_SUPPORTED_PAGES_PAGE 0x00
577 #define SLS_OVERRUN_PAGE 0x01
578 #define SLS_ERROR_WRITE_PAGE 0x02
579 #define SLS_ERROR_READ_PAGE 0x03
580 #define SLS_ERROR_READREVERSE_PAGE 0x04
581 #define SLS_ERROR_VERIFY_PAGE 0x05
582 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
583 #define SLS_ERROR_LASTN_PAGE 0x07
584 #define SLS_LOGICAL_BLOCK_PROVISIONING 0x0c
585 #define SLS_TEMPERATURE 0x0d
586 #define SLS_SELF_TEST_PAGE 0x10
587 #define SLS_SOLID_STATE_MEDIA 0x11
588 #define SLS_STAT_AND_PERF 0x19
589 #define SLS_IE_PAGE 0x2f
590 #define SLS_PAGE_CTRL_MASK 0xC0
591 #define SLS_PAGE_CTRL_THRESHOLD 0x00
592 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
593 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
594 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
595 u_int8_t subpage;
596 #define SLS_SUPPORTED_SUBPAGES_SUBPAGE 0xff
597 u_int8_t reserved;
598 u_int8_t paramptr[2];
599 u_int8_t length[2];
600 u_int8_t control;
601 };
602
603 struct scsi_log_select
604 {
605 u_int8_t opcode;
606 u_int8_t byte2;
607 /* SLS_SP 0x01 */
608 #define SLS_PCR 0x02
609 u_int8_t page;
610 /* SLS_PAGE_CTRL_MASK 0xC0 */
611 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
612 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
613 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
614 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
615 u_int8_t reserved[4];
616 u_int8_t length[2];
617 u_int8_t control;
618 };
619
620 struct scsi_log_header
621 {
622 u_int8_t page;
623 #define SL_PAGE_CODE 0x3F
624 #define SL_SPF 0x40
625 #define SL_DS 0x80
626 u_int8_t subpage;
627 u_int8_t datalen[2];
628 };
629
630 struct scsi_log_param_header {
631 u_int8_t param_code[2];
632 u_int8_t param_control;
633 #define SLP_LP 0x01
634 #define SLP_LBIN 0x02
635 #define SLP_TMC_MASK 0x0C
636 #define SLP_TMC_ALWAYS 0x00
637 #define SLP_TMC_EQUAL 0x04
638 #define SLP_TMC_NOTEQUAL 0x08
639 #define SLP_TMC_GREATER 0x0C
640 #define SLP_ETC 0x10
641 #define SLP_TSD 0x20
642 #define SLP_DS 0x40
643 #define SLP_DU 0x80
644 u_int8_t param_len;
645 };
646
647 struct scsi_log_media_pct_used {
648 struct scsi_log_param_header hdr;
649 #define SLP_SS_MEDIA_PCT_USED 0x0001
650 uint8_t reserved[3];
651 uint8_t pct_used;
652 };
653
654 struct scsi_log_stat_and_perf {
655 struct scsi_log_param_header hdr;
656 #define SLP_SAP 0x0001
657 uint8_t read_num[8];
658 uint8_t write_num[8];
659 uint8_t recvieved_lba[8];
660 uint8_t transmitted_lba[8];
661 uint8_t read_int[8];
662 uint8_t write_int[8];
663 uint8_t weighted_num[8];
664 uint8_t weighted_int[8];
665 };
666
667 struct scsi_log_idle_time {
668 struct scsi_log_param_header hdr;
669 #define SLP_IT 0x0002
670 uint8_t idle_int[8];
671 };
672
673 struct scsi_log_time_interval {
674 struct scsi_log_param_header hdr;
675 #define SLP_TI 0x0003
676 uint8_t exponent[4];
677 uint8_t integer[4];
678 };
679
680 struct scsi_log_fua_stat_and_perf {
681 struct scsi_log_param_header hdr;
682 #define SLP_FUA_SAP 0x0004
683 uint8_t fua_read_num[8];
684 uint8_t fua_write_num[8];
685 uint8_t fuanv_read_num[8];
686 uint8_t fuanv_write_num[8];
687 uint8_t fua_read_int[8];
688 uint8_t fua_write_int[8];
689 uint8_t fuanv_read_int[8];
690 uint8_t fuanv_write_int[8];
691 };
692
693 struct scsi_log_informational_exceptions {
694 struct scsi_log_param_header hdr;
695 #define SLP_IE_GEN 0x0000
696 uint8_t ie_asc;
697 uint8_t ie_ascq;
698 uint8_t temperature;
699 };
700
701 struct scsi_log_temperature {
702 struct scsi_log_param_header hdr;
703 #define SLP_TEMPERATURE 0x0000
704 #define SLP_REFTEMPERATURE 0x0001
705 uint8_t reserved;
706 uint8_t temperature;
707 };
708
709 struct scsi_control_page {
710 u_int8_t page_code;
711 u_int8_t page_length;
712 u_int8_t rlec;
713 #define SCP_RLEC 0x01 /*Report Log Exception Cond*/
714 #define SCP_GLTSD 0x02 /*Global Logging target
715 save disable */
716 #define SCP_DSENSE 0x04 /*Descriptor Sense */
717 #define SCP_DPICZ 0x08 /*Disable Prot. Info Check
718 if Prot. Field is Zero */
719 #define SCP_TMF_ONLY 0x10 /*TM Functions Only*/
720 #define SCP_TST_MASK 0xE0 /*Task Set Type Mask*/
721 #define SCP_TST_ONE 0x00 /*One Task Set*/
722 #define SCP_TST_SEPARATE 0x20 /*Separate Task Sets*/
723 u_int8_t queue_flags;
724 #define SCP_QUEUE_ALG_MASK 0xF0
725 #define SCP_QUEUE_ALG_RESTRICTED 0x00
726 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
727 #define SCP_NUAR 0x08 /*No UA on release*/
728 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
729 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
730 u_int8_t eca_and_aen;
731 #define SCP_EECA 0x80 /*Enable Extended CA*/
732 #define SCP_RAC 0x40 /*Report a check*/
733 #define SCP_SWP 0x08 /*Software Write Protect*/
734 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
735 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
736 #define SCP_EAENP 0x01 /*Error AEN Permission*/
737 u_int8_t flags4;
738 #define SCP_ATO 0x80 /*Application tag owner*/
739 #define SCP_TAS 0x40 /*Task aborted status*/
740 #define SCP_ATMPE 0x20 /*Application tag mode page*/
741 #define SCP_RWWP 0x10 /*Reject write without prot*/
742 u_int8_t aen_holdoff_period[2];
743 u_int8_t busy_timeout_period[2];
744 u_int8_t extended_selftest_completion_time[2];
745 };
746
747 struct scsi_control_ext_page {
748 uint8_t page_code;
749 #define SCEP_PAGE_CODE 0x0a
750 uint8_t subpage_code;
751 #define SCEP_SUBPAGE_CODE 0x01
752 uint8_t page_length[2];
753 uint8_t flags;
754 #define SCEP_TCMOS 0x04 /* Timestamp Changeable by */
755 #define SCEP_SCSIP 0x02 /* SCSI Precedence (clock) */
756 #define SCEP_IALUAE 0x01 /* Implicit ALUA Enabled */
757 uint8_t prio;
758 uint8_t max_sense;
759 uint8_t reserve[25];
760 };
761
762 struct scsi_cache_page {
763 u_int8_t page_code;
764 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */
765 u_int8_t page_length;
766 u_int8_t cache_flags;
767 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */
768 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */
769 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */
770 u_int8_t rw_cache_policy;
771 u_int8_t dis_prefetch[2];
772 u_int8_t min_prefetch[2];
773 u_int8_t max_prefetch[2];
774 u_int8_t max_prefetch_ceil[2];
775 };
776
777 /*
778 * XXX KDM
779 * Updated version of the cache page, as of SBC. Update this to SBC-3 and
780 * rationalize the two.
781 */
782 struct scsi_caching_page {
783 uint8_t page_code;
784 #define SMS_CACHING_PAGE 0x08
785 uint8_t page_length;
786 uint8_t flags1;
787 #define SCP_IC 0x80
788 #define SCP_ABPF 0x40
789 #define SCP_CAP 0x20
790 #define SCP_DISC 0x10
791 #define SCP_SIZE 0x08
792 #define SCP_WCE 0x04
793 #define SCP_MF 0x02
794 #define SCP_RCD 0x01
795 uint8_t ret_priority;
796 uint8_t disable_pf_transfer_len[2];
797 uint8_t min_prefetch[2];
798 uint8_t max_prefetch[2];
799 uint8_t max_pf_ceiling[2];
800 uint8_t flags2;
801 #define SCP_FSW 0x80
802 #define SCP_LBCSS 0x40
803 #define SCP_DRA 0x20
804 #define SCP_VS1 0x10
805 #define SCP_VS2 0x08
806 uint8_t cache_segments;
807 uint8_t cache_seg_size[2];
808 uint8_t reserved;
809 uint8_t non_cache_seg_size[3];
810 };
811
812 struct scsi_info_exceptions_page {
813 u_int8_t page_code;
814 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
815 u_int8_t page_length;
816 u_int8_t info_flags;
817 #define SIEP_FLAGS_PERF 0x80
818 #define SIEP_FLAGS_EBF 0x20
819 #define SIEP_FLAGS_EWASC 0x10
820 #define SIEP_FLAGS_DEXCPT 0x08
821 #define SIEP_FLAGS_TEST 0x04
822 #define SIEP_FLAGS_EBACKERR 0x02
823 #define SIEP_FLAGS_LOGERR 0x01
824 u_int8_t mrie;
825 #define SIEP_MRIE_NO 0x00
826 #define SIEP_MRIE_UA 0x02
827 #define SIEP_MRIE_REC_COND 0x03
828 #define SIEP_MRIE_REC_UNCOND 0x04
829 #define SIEP_MRIE_NO_SENSE 0x05
830 #define SIEP_MRIE_ON_REQ 0x06
831 u_int8_t interval_timer[4];
832 u_int8_t report_count[4];
833 };
834
835 struct scsi_logical_block_provisioning_page_descr {
836 uint8_t flags;
837 #define SLBPPD_ENABLED 0x80
838 #define SLBPPD_TYPE_MASK 0x38
839 #define SLBPPD_ARMING_MASK 0x07
840 #define SLBPPD_ARMING_DEC 0x02
841 #define SLBPPD_ARMING_INC 0x01
842 uint8_t resource;
843 uint8_t reserved[2];
844 uint8_t count[4];
845 };
846
847 struct scsi_logical_block_provisioning_page {
848 uint8_t page_code;
849 uint8_t subpage_code;
850 uint8_t page_length[2];
851 uint8_t flags;
852 #define SLBPP_SITUA 0x01
853 uint8_t reserved[11];
854 struct scsi_logical_block_provisioning_page_descr descr[0];
855 };
856
857 /*
858 * SCSI protocol identifier values, current as of SPC4r36l.
859 */
860 #define SCSI_PROTO_FC 0x00 /* Fibre Channel */
861 #define SCSI_PROTO_SPI 0x01 /* Parallel SCSI */
862 #define SCSI_PROTO_SSA 0x02 /* Serial Storage Arch. */
863 #define SCSI_PROTO_1394 0x03 /* IEEE 1394 (Firewire) */
864 #define SCSI_PROTO_RDMA 0x04 /* SCSI RDMA Protocol */
865 #define SCSI_PROTO_ISCSI 0x05 /* Internet SCSI */
866 #define SCSI_PROTO_iSCSI 0x05 /* Internet SCSI */
867 #define SCSI_PROTO_SAS 0x06 /* SAS Serial SCSI Protocol */
868 #define SCSI_PROTO_ADT 0x07 /* Automation/Drive Int. Trans. Prot.*/
869 #define SCSI_PROTO_ADITP 0x07 /* Automation/Drive Int. Trans. Prot.*/
870 #define SCSI_PROTO_ATA 0x08 /* AT Attachment Interface */
871 #define SCSI_PROTO_UAS 0x09 /* USB Atached SCSI */
872 #define SCSI_PROTO_SOP 0x0a /* SCSI over PCI Express */
873 #define SCSI_PROTO_NONE 0x0f /* No specific protocol */
874
875 struct scsi_proto_specific_page {
876 u_int8_t page_code;
877 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
878 u_int8_t page_length;
879 u_int8_t protocol;
880 #define SPSP_PROTO_FC SCSI_PROTO_FC
881 #define SPSP_PROTO_SPI SCSI_PROTO_SPI
882 #define SPSP_PROTO_SSA SCSI_PROTO_SSA
883 #define SPSP_PROTO_1394 SCSI_PROTO_1394
884 #define SPSP_PROTO_RDMA SCSI_PROTO_RDMA
885 #define SPSP_PROTO_ISCSI SCSI_PROTO_ISCSI
886 #define SPSP_PROTO_SAS SCSI_PROTO_SAS
887 #define SPSP_PROTO_ADT SCSI_PROTO_ADITP
888 #define SPSP_PROTO_ATA SCSI_PROTO_ATA
889 #define SPSP_PROTO_UAS SCSI_PROTO_UAS
890 #define SPSP_PROTO_SOP SCSI_PROTO_SOP
891 #define SPSP_PROTO_NONE SCSI_PROTO_NONE
892 };
893
894 struct scsi_reserve
895 {
896 u_int8_t opcode;
897 u_int8_t byte2;
898 #define SR_EXTENT 0x01
899 #define SR_ID_MASK 0x0e
900 #define SR_3RDPTY 0x10
901 #define SR_LUN_MASK 0xe0
902 u_int8_t resv_id;
903 u_int8_t length[2];
904 u_int8_t control;
905 };
906
907 struct scsi_reserve_10 {
908 uint8_t opcode;
909 uint8_t byte2;
910 #define SR10_3RDPTY 0x10
911 #define SR10_LONGID 0x02
912 #define SR10_EXTENT 0x01
913 uint8_t resv_id;
914 uint8_t thirdparty_id;
915 uint8_t reserved[3];
916 uint8_t length[2];
917 uint8_t control;
918 };
919
920 struct scsi_release
921 {
922 u_int8_t opcode;
923 u_int8_t byte2;
924 u_int8_t resv_id;
925 u_int8_t unused[1];
926 u_int8_t length;
927 u_int8_t control;
928 };
929
930 struct scsi_release_10 {
931 uint8_t opcode;
932 uint8_t byte2;
933 uint8_t resv_id;
934 uint8_t thirdparty_id;
935 uint8_t reserved[3];
936 uint8_t length[2];
937 uint8_t control;
938 };
939
940 struct scsi_prevent
941 {
942 u_int8_t opcode;
943 u_int8_t byte2;
944 u_int8_t unused[2];
945 u_int8_t how;
946 u_int8_t control;
947 };
948 #define PR_PREVENT 0x01
949 #define PR_ALLOW 0x00
950
951 struct scsi_sync_cache
952 {
953 u_int8_t opcode;
954 u_int8_t byte2;
955 #define SSC_IMMED 0x02
956 #define SSC_RELADR 0x01
957 u_int8_t begin_lba[4];
958 u_int8_t reserved;
959 u_int8_t lb_count[2];
960 u_int8_t control;
961 };
962
963 struct scsi_sync_cache_16
964 {
965 uint8_t opcode;
966 uint8_t byte2;
967 uint8_t begin_lba[8];
968 uint8_t lb_count[4];
969 uint8_t reserved;
970 uint8_t control;
971 };
972
973 struct scsi_format {
974 uint8_t opcode;
975 uint8_t byte2;
976 #define SF_LONGLIST 0x20
977 #define SF_FMTDATA 0x10
978 #define SF_CMPLIST 0x08
979 #define SF_FORMAT_MASK 0x07
980 #define SF_FORMAT_BLOCK 0x00
981 #define SF_FORMAT_LONG_BLOCK 0x03
982 #define SF_FORMAT_BFI 0x04
983 #define SF_FORMAT_PHYS 0x05
984 uint8_t vendor;
985 uint8_t interleave[2];
986 uint8_t control;
987 };
988
989 struct scsi_format_header_short {
990 uint8_t reserved;
991 #define SF_DATA_FOV 0x80
992 #define SF_DATA_DPRY 0x40
993 #define SF_DATA_DCRT 0x20
994 #define SF_DATA_STPF 0x10
995 #define SF_DATA_IP 0x08
996 #define SF_DATA_DSP 0x04
997 #define SF_DATA_IMMED 0x02
998 #define SF_DATA_VS 0x01
999 uint8_t byte2;
1000 uint8_t defect_list_len[2];
1001 };
1002
1003 struct scsi_format_header_long {
1004 uint8_t reserved;
1005 uint8_t byte2;
1006 uint8_t reserved2[2];
1007 uint8_t defect_list_len[4];
1008 };
1009
1010 struct scsi_changedef
1011 {
1012 u_int8_t opcode;
1013 u_int8_t byte2;
1014 u_int8_t unused1;
1015 u_int8_t how;
1016 u_int8_t unused[4];
1017 u_int8_t datalen;
1018 u_int8_t control;
1019 };
1020
1021 struct scsi_read_buffer
1022 {
1023 u_int8_t opcode;
1024 u_int8_t byte2;
1025 #define RWB_MODE 0x1F
1026 #define RWB_MODE_HDR_DATA 0x00
1027 #define RWB_MODE_VENDOR 0x01
1028 #define RWB_MODE_DATA 0x02
1029 #define RWB_MODE_DESCR 0x03
1030 #define RWB_MODE_DOWNLOAD 0x04
1031 #define RWB_MODE_DOWNLOAD_SAVE 0x05
1032 #define RWB_MODE_ECHO 0x0A
1033 #define RWB_MODE_ECHO_DESCR 0x0B
1034 #define RWB_MODE_ERROR_HISTORY 0x1C
1035 u_int8_t buffer_id;
1036 u_int8_t offset[3];
1037 u_int8_t length[3];
1038 u_int8_t control;
1039 };
1040
1041 struct scsi_read_buffer_16
1042 {
1043 uint8_t opcode;
1044 uint8_t byte2;
1045 uint8_t offset[8];
1046 uint8_t length[4];
1047 uint8_t buffer_id;
1048 uint8_t control;
1049 };
1050
1051 struct scsi_write_buffer
1052 {
1053 u_int8_t opcode;
1054 u_int8_t byte2;
1055 u_int8_t buffer_id;
1056 u_int8_t offset[3];
1057 u_int8_t length[3];
1058 u_int8_t control;
1059 };
1060
1061 struct scsi_read_attribute
1062 {
1063 u_int8_t opcode;
1064 u_int8_t service_action;
1065 #define SRA_SA_ATTR_VALUES 0x00
1066 #define SRA_SA_ATTR_LIST 0x01
1067 #define SRA_SA_LOG_VOL_LIST 0x02
1068 #define SRA_SA_PART_LIST 0x03
1069 #define SRA_SA_RESTRICTED 0x04
1070 #define SRA_SA_SUPPORTED_ATTRS 0x05
1071 #define SRA_SA_MASK 0x1f
1072 u_int8_t element[2];
1073 u_int8_t elem_type;
1074 u_int8_t logical_volume;
1075 u_int8_t reserved1;
1076 u_int8_t partition;
1077 u_int8_t first_attribute[2];
1078 u_int8_t length[4];
1079 u_int8_t cache;
1080 #define SRA_CACHE 0x01
1081 u_int8_t control;
1082 };
1083
1084 struct scsi_write_attribute
1085 {
1086 u_int8_t opcode;
1087 u_int8_t byte2;
1088 #define SWA_WTC 0x01
1089 u_int8_t element[3];
1090 u_int8_t logical_volume;
1091 u_int8_t reserved1;
1092 u_int8_t partition;
1093 u_int8_t reserved2[2];
1094 u_int8_t length[4];
1095 u_int8_t reserved3;
1096 u_int8_t control;
1097 };
1098
1099 struct scsi_read_attribute_values
1100 {
1101 u_int8_t length[4];
1102 u_int8_t attribute_0[0];
1103 };
1104
1105 struct scsi_mam_attribute_header
1106 {
1107 u_int8_t id[2];
1108 /*
1109 * Attributes obtained from SPC-4r36g (section 7.4.2.2) and
1110 * SSC-4r03 (section 4.2.21).
1111 */
1112 #define SMA_ATTR_ID_DEVICE_MIN 0x0000
1113
1114 #define SMA_ATTR_REM_CAP_PARTITION 0x0000
1115 #define SMA_ATTR_MAX_CAP_PARTITION 0x0001
1116 #define SMA_ATTR_TAPEALERT_FLAGS 0x0002
1117 #define SMA_ATTR_LOAD_COUNT 0x0003
1118 #define SMA_ATTR_MAM_SPACE_REMAINING 0x0004
1119
1120 #define SMA_ATTR_DEV_ASSIGNING_ORG 0x0005
1121 #define SMA_ATTR_FORMAT_DENSITY_CODE 0x0006
1122 #define SMA_ATTR_INITIALIZATION_COUNT 0x0007
1123 #define SMA_ATTR_VOLUME_ID 0x0008
1124 #define SMA_ATTR_VOLUME_CHANGE_REF 0x0009
1125
1126 #define SMA_ATTR_DEV_SERIAL_LAST_LOAD 0x020a
1127 #define SMA_ATTR_DEV_SERIAL_LAST_LOAD_1 0x020b
1128 #define SMA_ATTR_DEV_SERIAL_LAST_LOAD_2 0x020c
1129 #define SMA_ATTR_DEV_SERIAL_LAST_LOAD_3 0x020d
1130
1131 #define SMA_ATTR_TOTAL_MB_WRITTEN_LT 0x0220
1132 #define SMA_ATTR_TOTAL_MB_READ_LT 0x0221
1133 #define SMA_ATTR_TOTAL_MB_WRITTEN_CUR 0x0222
1134 #define SMA_ATTR_TOTAL_MB_READ_CUR 0x0223
1135 #define SMA_ATTR_FIRST_ENC_BLOCK 0x0224
1136 #define SMA_ATTR_NEXT_UNENC_BLOCK 0x0225
1137
1138 #define SMA_ATTR_MEDIUM_USAGE_HIST 0x0340
1139 #define SMA_ATTR_PART_USAGE_HIST 0x0341
1140
1141 #define SMA_ATTR_ID_DEVICE_MAX 0x03ff
1142
1143 #define SMA_ATTR_ID_MEDIUM_MIN 0x0400
1144
1145 #define SMA_ATTR_MED_MANUF 0x0400
1146 #define SMA_ATTR_MED_SERIAL 0x0401
1147
1148 #define SMA_ATTR_MED_LENGTH 0x0402
1149 #define SMA_ATTR_MED_WIDTH 0x0403
1150 #define SMA_ATTR_MED_ASSIGNING_ORG 0x0404
1151 #define SMA_ATTR_MED_DENSITY_CODE 0x0405
1152
1153 #define SMA_ATTR_MED_MANUF_DATE 0x0406
1154 #define SMA_ATTR_MAM_CAPACITY 0x0407
1155 #define SMA_ATTR_MED_TYPE 0x0408
1156 #define SMA_ATTR_MED_TYPE_INFO 0x0409
1157 #define SMA_ATTR_MED_SERIAL_NUM 0x040a
1158
1159 #define SMA_ATTR_ID_MEDIUM_MAX 0x07ff
1160
1161 #define SMA_ATTR_ID_HOST_MIN 0x0800
1162
1163 #define SMA_ATTR_APP_VENDOR 0x0800
1164 #define SMA_ATTR_APP_NAME 0x0801
1165 #define SMA_ATTR_APP_VERSION 0x0802
1166 #define SMA_ATTR_USER_MED_TEXT_LABEL 0x0803
1167 #define SMA_ATTR_LAST_WRITTEN_TIME 0x0804
1168 #define SMA_ATTR_TEXT_LOCAL_ID 0x0805
1169 #define SMA_ATTR_BARCODE 0x0806
1170 #define SMA_ATTR_HOST_OWNER_NAME 0x0807
1171 #define SMA_ATTR_MEDIA_POOL 0x0808
1172 #define SMA_ATTR_PART_USER_LABEL 0x0809
1173 #define SMA_ATTR_LOAD_UNLOAD_AT_PART 0x080a
1174 #define SMA_ATTR_APP_FORMAT_VERSION 0x080b
1175 #define SMA_ATTR_VOL_COHERENCY_INFO 0x080c
1176
1177 #define SMA_ATTR_ID_HOST_MAX 0x0bff
1178
1179 #define SMA_ATTR_VENDOR_DEVICE_MIN 0x0c00
1180 #define SMA_ATTR_VENDOR_DEVICE_MAX 0x0fff
1181 #define SMA_ATTR_VENDOR_MEDIUM_MIN 0x1000
1182 #define SMA_ATTR_VENDOR_MEDIUM_MAX 0x13ff
1183 #define SMA_ATTR_VENDOR_HOST_MIN 0x1400
1184 #define SMA_ATTR_VENDOR_HOST_MAX 0x17ff
1185 u_int8_t byte2;
1186 #define SMA_FORMAT_BINARY 0x00
1187 #define SMA_FORMAT_ASCII 0x01
1188 #define SMA_FORMAT_TEXT 0x02
1189 #define SMA_FORMAT_MASK 0x03
1190 #define SMA_READ_ONLY 0x80
1191 u_int8_t length[2];
1192 u_int8_t attribute[0];
1193 };
1194
1195 struct scsi_attrib_list_header {
1196 u_int8_t length[4];
1197 u_int8_t first_attr_0[0];
1198 };
1199
1200 struct scsi_attrib_lv_list {
1201 u_int8_t length[2];
1202 u_int8_t first_lv_number;
1203 u_int8_t num_logical_volumes;
1204 };
1205
1206 struct scsi_attrib_vendser {
1207 uint8_t vendor[8];
1208 uint8_t serial_num[32];
1209 };
1210
1211 /*
1212 * These values are used to decode the Volume Coherency Information
1213 * Attribute (0x080c) for LTFS-format coherency information.
1214 * Although the Application Client Specific lengths are different for
1215 * Version 0 and Version 1, the data is in fact the same. The length
1216 * difference was due to a code bug.
1217 */
1218 #define SCSI_LTFS_VER0_LEN 42
1219 #define SCSI_LTFS_VER1_LEN 43
1220 #define SCSI_LTFS_UUID_LEN 36
1221 #define SCSI_LTFS_STR_NAME "LTFS"
1222 #define SCSI_LTFS_STR_LEN 4
1223
1224 typedef enum {
1225 SCSI_ATTR_FLAG_NONE = 0x00,
1226 SCSI_ATTR_FLAG_HEX = 0x01,
1227 SCSI_ATTR_FLAG_FP = 0x02,
1228 SCSI_ATTR_FLAG_DIV_10 = 0x04,
1229 SCSI_ATTR_FLAG_FP_1DIGIT = 0x08
1230 } scsi_attrib_flags;
1231
1232 typedef enum {
1233 SCSI_ATTR_OUTPUT_NONE = 0x00,
1234 SCSI_ATTR_OUTPUT_TEXT_MASK = 0x03,
1235 SCSI_ATTR_OUTPUT_TEXT_RAW = 0x00,
1236 SCSI_ATTR_OUTPUT_TEXT_ESC = 0x01,
1237 SCSI_ATTR_OUTPUT_TEXT_RSV1 = 0x02,
1238 SCSI_ATTR_OUTPUT_TEXT_RSV2 = 0x03,
1239 SCSI_ATTR_OUTPUT_NONASCII_MASK = 0x0c,
1240 SCSI_ATTR_OUTPUT_NONASCII_TRIM = 0x00,
1241 SCSI_ATTR_OUTPUT_NONASCII_ESC = 0x04,
1242 SCSI_ATTR_OUTPUT_NONASCII_RAW = 0x08,
1243 SCSI_ATTR_OUTPUT_NONASCII_RSV1 = 0x0c,
1244 SCSI_ATTR_OUTPUT_FIELD_MASK = 0xf0,
1245 SCSI_ATTR_OUTPUT_FIELD_ALL = 0xf0,
1246 SCSI_ATTR_OUTPUT_FIELD_NONE = 0x00,
1247 SCSI_ATTR_OUTPUT_FIELD_DESC = 0x10,
1248 SCSI_ATTR_OUTPUT_FIELD_NUM = 0x20,
1249 SCSI_ATTR_OUTPUT_FIELD_SIZE = 0x40,
1250 SCSI_ATTR_OUTPUT_FIELD_RW = 0x80
1251 } scsi_attrib_output_flags;
1252
1253 struct sbuf;
1254
1255 struct scsi_attrib_table_entry
1256 {
1257 u_int32_t id;
1258 u_int32_t flags;
1259 const char *desc;
1260 const char *suffix;
1261 int (*to_str)(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
1262 uint32_t valid_len, uint32_t flags,
1263 uint32_t output_flags, char *error_str,
1264 int error_str_len);
1265 int (*parse_str)(char *str, struct scsi_mam_attribute_header *hdr,
1266 uint32_t alloc_len, uint32_t flags, char *error_str,
1267 int error_str_len);
1268 };
1269
1270 struct scsi_rw_6
1271 {
1272 u_int8_t opcode;
1273 u_int8_t addr[3];
1274 /* only 5 bits are valid in the MSB address byte */
1275 #define SRW_TOPADDR 0x1F
1276 u_int8_t length;
1277 u_int8_t control;
1278 };
1279
1280 struct scsi_rw_10
1281 {
1282 u_int8_t opcode;
1283 #define SRW10_RELADDR 0x01
1284 /* EBP defined for WRITE(10) only */
1285 #define SRW10_EBP 0x04
1286 #define SRW10_FUA 0x08
1287 #define SRW10_DPO 0x10
1288 u_int8_t byte2;
1289 u_int8_t addr[4];
1290 u_int8_t reserved;
1291 u_int8_t length[2];
1292 u_int8_t control;
1293 };
1294
1295 struct scsi_rw_12
1296 {
1297 u_int8_t opcode;
1298 #define SRW12_RELADDR 0x01
1299 #define SRW12_FUA 0x08
1300 #define SRW12_DPO 0x10
1301 u_int8_t byte2;
1302 u_int8_t addr[4];
1303 u_int8_t length[4];
1304 u_int8_t reserved;
1305 u_int8_t control;
1306 };
1307
1308 struct scsi_rw_16
1309 {
1310 u_int8_t opcode;
1311 #define SRW16_RELADDR 0x01
1312 #define SRW16_FUA 0x08
1313 #define SRW16_DPO 0x10
1314 u_int8_t byte2;
1315 u_int8_t addr[8];
1316 u_int8_t length[4];
1317 u_int8_t reserved;
1318 u_int8_t control;
1319 };
1320
1321 struct scsi_write_atomic_16
1322 {
1323 uint8_t opcode;
1324 uint8_t byte2;
1325 uint8_t addr[8];
1326 uint8_t boundary[2];
1327 uint8_t length[2];
1328 uint8_t group;
1329 uint8_t control;
1330 };
1331
1332 struct scsi_write_same_10
1333 {
1334 uint8_t opcode;
1335 uint8_t byte2;
1336 #define SWS_LBDATA 0x02
1337 #define SWS_PBDATA 0x04
1338 #define SWS_UNMAP 0x08
1339 #define SWS_ANCHOR 0x10
1340 uint8_t addr[4];
1341 uint8_t group;
1342 uint8_t length[2];
1343 uint8_t control;
1344 };
1345
1346 struct scsi_write_same_16
1347 {
1348 uint8_t opcode;
1349 uint8_t byte2;
1350 #define SWS_NDOB 0x01
1351 uint8_t addr[8];
1352 uint8_t length[4];
1353 uint8_t group;
1354 uint8_t control;
1355 };
1356
1357 struct scsi_unmap
1358 {
1359 uint8_t opcode;
1360 uint8_t byte2;
1361 #define SU_ANCHOR 0x01
1362 uint8_t reserved[4];
1363 uint8_t group;
1364 uint8_t length[2];
1365 uint8_t control;
1366 };
1367
1368 struct scsi_unmap_header
1369 {
1370 uint8_t length[2];
1371 uint8_t desc_length[2];
1372 uint8_t reserved[4];
1373 };
1374
1375 struct scsi_unmap_desc
1376 {
1377 uint8_t lba[8];
1378 uint8_t length[4];
1379 uint8_t reserved[4];
1380 };
1381
1382 struct scsi_write_verify_10
1383 {
1384 uint8_t opcode;
1385 uint8_t byte2;
1386 #define SWV_BYTCHK 0x02
1387 #define SWV_DPO 0x10
1388 #define SWV_WRPROECT_MASK 0xe0
1389 uint8_t addr[4];
1390 uint8_t group;
1391 uint8_t length[2];
1392 uint8_t control;
1393 };
1394
1395 struct scsi_write_verify_12
1396 {
1397 uint8_t opcode;
1398 uint8_t byte2;
1399 uint8_t addr[4];
1400 uint8_t length[4];
1401 uint8_t group;
1402 uint8_t control;
1403 };
1404
1405 struct scsi_write_verify_16
1406 {
1407 uint8_t opcode;
1408 uint8_t byte2;
1409 uint8_t addr[8];
1410 uint8_t length[4];
1411 uint8_t group;
1412 uint8_t control;
1413 };
1414
1415 struct scsi_start_stop_unit
1416 {
1417 u_int8_t opcode;
1418 u_int8_t byte2;
1419 #define SSS_IMMED 0x01
1420 u_int8_t reserved[2];
1421 u_int8_t how;
1422 #define SSS_START 0x01
1423 #define SSS_LOEJ 0x02
1424 #define SSS_PC_MASK 0xf0
1425 #define SSS_PC_START_VALID 0x00
1426 #define SSS_PC_ACTIVE 0x10
1427 #define SSS_PC_IDLE 0x20
1428 #define SSS_PC_STANDBY 0x30
1429 #define SSS_PC_LU_CONTROL 0x70
1430 #define SSS_PC_FORCE_IDLE_0 0xa0
1431 #define SSS_PC_FORCE_STANDBY_0 0xb0
1432 u_int8_t control;
1433 };
1434
1435 struct ata_pass_12 {
1436 u_int8_t opcode;
1437 u_int8_t protocol;
1438 #define AP_PROTO_HARD_RESET (0x00 << 1)
1439 #define AP_PROTO_SRST (0x01 << 1)
1440 #define AP_PROTO_NON_DATA (0x03 << 1)
1441 #define AP_PROTO_PIO_IN (0x04 << 1)
1442 #define AP_PROTO_PIO_OUT (0x05 << 1)
1443 #define AP_PROTO_DMA (0x06 << 1)
1444 #define AP_PROTO_DMA_QUEUED (0x07 << 1)
1445 #define AP_PROTO_DEVICE_DIAG (0x08 << 1)
1446 #define AP_PROTO_DEVICE_RESET (0x09 << 1)
1447 #define AP_PROTO_UDMA_IN (0x0a << 1)
1448 #define AP_PROTO_UDMA_OUT (0x0b << 1)
1449 #define AP_PROTO_FPDMA (0x0c << 1)
1450 #define AP_PROTO_RESP_INFO (0x0f << 1)
1451 #define AP_PROTO_MASK 0x1e
1452 #define AP_MULTI 0xe0
1453 u_int8_t flags;
1454 #define AP_T_LEN 0x03
1455 #define AP_BB 0x04
1456 #define AP_T_DIR 0x08
1457 #define AP_CK_COND 0x20
1458 #define AP_OFFLINE 0x60
1459 u_int8_t features;
1460 u_int8_t sector_count;
1461 u_int8_t lba_low;
1462 u_int8_t lba_mid;
1463 u_int8_t lba_high;
1464 u_int8_t device;
1465 u_int8_t command;
1466 u_int8_t reserved;
1467 u_int8_t control;
1468 };
1469
1470 struct scsi_maintenance_in
1471 {
1472 uint8_t opcode;
1473 uint8_t byte2;
1474 #define SERVICE_ACTION_MASK 0x1f
1475 #define SA_RPRT_TRGT_GRP 0x0a
1476 uint8_t reserved[4];
1477 uint8_t length[4];
1478 uint8_t reserved1;
1479 uint8_t control;
1480 };
1481
1482 struct scsi_report_ident_info
1483 {
1484 uint8_t opcode;
1485 uint8_t service_action;
1486 uint8_t reserved[4];
1487 uint8_t length[4];
1488 uint8_t type;
1489 #define RII_LUII 0x00
1490 #define RII_LUTII 0x04
1491 #define RII_IIS 0xfc
1492 uint8_t control;
1493 };
1494
1495 struct scsi_report_ident_info_data
1496 {
1497 uint8_t reserved[2];
1498 uint8_t length[2];
1499 };
1500
1501 struct scsi_report_ident_info_descr
1502 {
1503 uint8_t type;
1504 uint8_t reserved;
1505 uint8_t length[2];
1506 };
1507
1508 struct scsi_report_supported_opcodes
1509 {
1510 uint8_t opcode;
1511 uint8_t service_action;
1512 uint8_t options;
1513 #define RSO_RCTD 0x80
1514 #define RSO_OPTIONS_MASK 0x07
1515 #define RSO_OPTIONS_ALL 0x00
1516 #define RSO_OPTIONS_OC 0x01
1517 #define RSO_OPTIONS_OC_SA 0x02
1518 #define RSO_OPTIONS_OC_ASA 0x03
1519 uint8_t requested_opcode;
1520 uint8_t requested_service_action[2];
1521 uint8_t length[4];
1522 uint8_t reserved1;
1523 uint8_t control;
1524 };
1525
1526 struct scsi_report_supported_opcodes_timeout
1527 {
1528 uint8_t length[2];
1529 uint8_t reserved;
1530 uint8_t cmd_specific;
1531 uint8_t nominal_time[4];
1532 uint8_t recommended_time[4];
1533 };
1534
1535 struct scsi_report_supported_opcodes_descr
1536 {
1537 uint8_t opcode;
1538 uint8_t reserved;
1539 uint8_t service_action[2];
1540 uint8_t reserved2;
1541 uint8_t flags;
1542 #define RSO_SERVACTV 0x01
1543 #define RSO_CTDP 0x02
1544 #define RSO_CDLP_MASK 0x0c
1545 #define RSO_CDLP_NO 0x00
1546 #define RSO_CDLP_A 0x04
1547 #define RSO_CDLP_B 0x08
1548 uint8_t cdb_length[2];
1549 struct scsi_report_supported_opcodes_timeout timeout[0];
1550 };
1551
1552 struct scsi_report_supported_opcodes_all
1553 {
1554 uint8_t length[4];
1555 struct scsi_report_supported_opcodes_descr descr[0];
1556 };
1557
1558 struct scsi_report_supported_opcodes_one
1559 {
1560 uint8_t reserved;
1561 uint8_t support;
1562 #define RSO_ONE_CTDP 0x80
1563 #define RSO_ONE_CDLP_MASK 0x18
1564 #define RSO_ONE_CDLP_NO 0x00
1565 #define RSO_ONE_CDLP_A 0x08
1566 #define RSO_ONE_CDLP_B 0x10
1567 #define RSO_ONE_SUP_MASK 0x07
1568 #define RSO_ONE_SUP_UNAVAIL 0x00
1569 #define RSO_ONE_SUP_NOT_SUP 0x01
1570 #define RSO_ONE_SUP_AVAIL 0x03
1571 #define RSO_ONE_SUP_VENDOR 0x05
1572 uint8_t cdb_length[2];
1573 uint8_t cdb_usage[];
1574 };
1575
1576 struct scsi_report_supported_tmf
1577 {
1578 uint8_t opcode;
1579 uint8_t service_action;
1580 uint8_t options;
1581 #define RST_REPD 0x80
1582 uint8_t reserved[3];
1583 uint8_t length[4];
1584 uint8_t reserved1;
1585 uint8_t control;
1586 };
1587
1588 struct scsi_report_supported_tmf_data
1589 {
1590 uint8_t byte1;
1591 #define RST_WAKES 0x01
1592 #define RST_TRS 0x02
1593 #define RST_QTS 0x04
1594 #define RST_LURS 0x08
1595 #define RST_CTSS 0x10
1596 #define RST_CACAS 0x20
1597 #define RST_ATSS 0x40
1598 #define RST_ATS 0x80
1599 uint8_t byte2;
1600 #define RST_ITNRS 0x01
1601 #define RST_QTSS 0x02
1602 #define RST_QAES 0x04
1603 uint8_t reserved;
1604 uint8_t length;
1605 };
1606
1607 struct scsi_report_supported_tmf_ext_data
1608 {
1609 uint8_t byte1;
1610 uint8_t byte2;
1611 uint8_t reserved;
1612 uint8_t length;
1613 uint8_t byte5;
1614 #define RST_TMFTMOV 0x01
1615 uint8_t reserved2;
1616 uint8_t byte7;
1617 #define RST_WAKETS 0x01
1618 #define RST_TRTS 0x02
1619 #define RST_QTTS 0x04
1620 #define RST_LURTS 0x08
1621 #define RST_CTSTS 0x10
1622 #define RST_CACATS 0x20
1623 #define RST_ATSTS 0x40
1624 #define RST_ATTS 0x80
1625 uint8_t byte8;
1626 #define RST_ITNRTS 0x01
1627 #define RST_QTSTS 0x02
1628 #define RST_QAETS 0x04
1629 uint8_t long_timeout[4];
1630 uint8_t short_timeout[4];
1631 };
1632
1633 struct scsi_report_timestamp
1634 {
1635 uint8_t opcode;
1636 uint8_t service_action;
1637 uint8_t reserved[4];
1638 uint8_t length[4];
1639 uint8_t reserved1;
1640 uint8_t control;
1641 };
1642
1643 struct scsi_report_timestamp_data
1644 {
1645 uint8_t length[2];
1646 uint8_t origin;
1647 #define RTS_ORIG_MASK 0x00
1648 #define RTS_ORIG_ZERO 0x00
1649 #define RTS_ORIG_SET 0x02
1650 #define RTS_ORIG_OUTSIDE 0x03
1651 uint8_t reserved;
1652 uint8_t timestamp[6];
1653 uint8_t reserve2[2];
1654 };
1655
1656 struct scsi_receive_copy_status_lid1
1657 {
1658 uint8_t opcode;
1659 uint8_t service_action;
1660 #define RCS_RCS_LID1 0x00
1661 uint8_t list_identifier;
1662 uint8_t reserved[7];
1663 uint8_t length[4];
1664 uint8_t reserved1;
1665 uint8_t control;
1666 };
1667
1668 struct scsi_receive_copy_status_lid1_data
1669 {
1670 uint8_t available_data[4];
1671 uint8_t copy_command_status;
1672 #define RCS_CCS_INPROG 0x00
1673 #define RCS_CCS_COMPLETED 0x01
1674 #define RCS_CCS_ERROR 0x02
1675 uint8_t segments_processed[2];
1676 uint8_t transfer_count_units;
1677 #define RCS_TC_BYTES 0x00
1678 #define RCS_TC_KBYTES 0x01
1679 #define RCS_TC_MBYTES 0x02
1680 #define RCS_TC_GBYTES 0x03
1681 #define RCS_TC_TBYTES 0x04
1682 #define RCS_TC_PBYTES 0x05
1683 #define RCS_TC_EBYTES 0x06
1684 #define RCS_TC_LBAS 0xf1
1685 uint8_t transfer_count[4];
1686 };
1687
1688 struct scsi_receive_copy_failure_details
1689 {
1690 uint8_t opcode;
1691 uint8_t service_action;
1692 #define RCS_RCFD 0x04
1693 uint8_t list_identifier;
1694 uint8_t reserved[7];
1695 uint8_t length[4];
1696 uint8_t reserved1;
1697 uint8_t control;
1698 };
1699
1700 struct scsi_receive_copy_failure_details_data
1701 {
1702 uint8_t available_data[4];
1703 uint8_t reserved[52];
1704 uint8_t copy_command_status;
1705 uint8_t reserved2;
1706 uint8_t sense_data_length[2];
1707 uint8_t sense_data[];
1708 };
1709
1710 struct scsi_receive_copy_status_lid4
1711 {
1712 uint8_t opcode;
1713 uint8_t service_action;
1714 #define RCS_RCS_LID4 0x05
1715 uint8_t list_identifier[4];
1716 uint8_t reserved[4];
1717 uint8_t length[4];
1718 uint8_t reserved1;
1719 uint8_t control;
1720 };
1721
1722 struct scsi_receive_copy_status_lid4_data
1723 {
1724 uint8_t available_data[4];
1725 uint8_t response_to_service_action;
1726 uint8_t copy_command_status;
1727 #define RCS_CCS_COMPLETED_PROD 0x03
1728 #define RCS_CCS_COMPLETED_RESID 0x04
1729 #define RCS_CCS_INPROG_FGBG 0x10
1730 #define RCS_CCS_INPROG_FG 0x11
1731 #define RCS_CCS_INPROG_BG 0x12
1732 #define RCS_CCS_ABORTED 0x60
1733 uint8_t operation_counter[2];
1734 uint8_t estimated_status_update_delay[4];
1735 uint8_t extended_copy_completion_status;
1736 uint8_t length_of_the_sense_data_field;
1737 uint8_t sense_data_length;
1738 uint8_t transfer_count_units;
1739 uint8_t transfer_count[8];
1740 uint8_t segments_processed[2];
1741 uint8_t reserved[6];
1742 uint8_t sense_data[];
1743 };
1744
1745 struct scsi_receive_copy_operating_parameters
1746 {
1747 uint8_t opcode;
1748 uint8_t service_action;
1749 #define RCS_RCOP 0x03
1750 uint8_t reserved[8];
1751 uint8_t length[4];
1752 uint8_t reserved1;
1753 uint8_t control;
1754 };
1755
1756 struct scsi_receive_copy_operating_parameters_data
1757 {
1758 uint8_t length[4];
1759 uint8_t snlid;
1760 #define RCOP_SNLID 0x01
1761 uint8_t reserved[3];
1762 uint8_t maximum_cscd_descriptor_count[2];
1763 uint8_t maximum_segment_descriptor_count[2];
1764 uint8_t maximum_descriptor_list_length[4];
1765 uint8_t maximum_segment_length[4];
1766 uint8_t maximum_inline_data_length[4];
1767 uint8_t held_data_limit[4];
1768 uint8_t maximum_stream_device_transfer_size[4];
1769 uint8_t reserved2[2];
1770 uint8_t total_concurrent_copies[2];
1771 uint8_t maximum_concurrent_copies;
1772 uint8_t data_segment_granularity;
1773 uint8_t inline_data_granularity;
1774 uint8_t held_data_granularity;
1775 uint8_t reserved3[3];
1776 uint8_t implemented_descriptor_list_length;
1777 uint8_t list_of_implemented_descriptor_type_codes[0];
1778 };
1779
1780 struct scsi_extended_copy
1781 {
1782 uint8_t opcode;
1783 uint8_t service_action;
1784 #define EC_EC_LID1 0x00
1785 #define EC_EC_LID4 0x01
1786 uint8_t reserved[8];
1787 uint8_t length[4];
1788 uint8_t reserved1;
1789 uint8_t control;
1790 };
1791
1792 struct scsi_ec_cscd_dtsp
1793 {
1794 uint8_t flags;
1795 #define EC_CSCD_FIXED 0x01
1796 #define EC_CSCD_PAD 0x04
1797 uint8_t block_length[3];
1798 };
1799
1800 struct scsi_ec_cscd
1801 {
1802 uint8_t type_code;
1803 #define EC_CSCD_EXT 0xff
1804 uint8_t luidt_pdt;
1805 #define EC_NUL 0x20
1806 #define EC_LUIDT_MASK 0xc0
1807 #define EC_LUIDT_LUN 0x00
1808 #define EC_LUIDT_PROXY_TOKEN 0x40
1809 uint8_t relative_initiator_port[2];
1810 uint8_t cscd_params[24];
1811 struct scsi_ec_cscd_dtsp dtsp;
1812 };
1813
1814 struct scsi_ec_cscd_id
1815 {
1816 uint8_t type_code;
1817 #define EC_CSCD_ID 0xe4
1818 uint8_t luidt_pdt;
1819 uint8_t relative_initiator_port[2];
1820 uint8_t codeset;
1821 uint8_t id_type;
1822 uint8_t reserved;
1823 uint8_t length;
1824 uint8_t designator[20];
1825 struct scsi_ec_cscd_dtsp dtsp;
1826 };
1827
1828 struct scsi_ec_segment
1829 {
1830 uint8_t type_code;
1831 uint8_t flags;
1832 #define EC_SEG_DC 0x02
1833 #define EC_SEG_CAT 0x01
1834 uint8_t descr_length[2];
1835 uint8_t params[];
1836 };
1837
1838 struct scsi_ec_segment_b2b
1839 {
1840 uint8_t type_code;
1841 #define EC_SEG_B2B 0x02
1842 uint8_t flags;
1843 uint8_t descr_length[2];
1844 uint8_t src_cscd[2];
1845 uint8_t dst_cscd[2];
1846 uint8_t reserved[2];
1847 uint8_t number_of_blocks[2];
1848 uint8_t src_lba[8];
1849 uint8_t dst_lba[8];
1850 };
1851
1852 struct scsi_ec_segment_verify
1853 {
1854 uint8_t type_code;
1855 #define EC_SEG_VERIFY 0x07
1856 uint8_t reserved;
1857 uint8_t descr_length[2];
1858 uint8_t src_cscd[2];
1859 uint8_t reserved2[2];
1860 uint8_t tur;
1861 uint8_t reserved3[3];
1862 };
1863
1864 struct scsi_ec_segment_register_key
1865 {
1866 uint8_t type_code;
1867 #define EC_SEG_REGISTER_KEY 0x14
1868 uint8_t reserved;
1869 uint8_t descr_length[2];
1870 uint8_t reserved2[2];
1871 uint8_t dst_cscd[2];
1872 uint8_t res_key[8];
1873 uint8_t sa_res_key[8];
1874 uint8_t reserved3[4];
1875 };
1876
1877 struct scsi_extended_copy_lid1_data
1878 {
1879 uint8_t list_identifier;
1880 uint8_t flags;
1881 #define EC_PRIORITY 0x07
1882 #define EC_LIST_ID_USAGE_MASK 0x18
1883 #define EC_LIST_ID_USAGE_FULL 0x08
1884 #define EC_LIST_ID_USAGE_NOHOLD 0x10
1885 #define EC_LIST_ID_USAGE_NONE 0x18
1886 #define EC_STR 0x20
1887 uint8_t cscd_list_length[2];
1888 uint8_t reserved[4];
1889 uint8_t segment_list_length[4];
1890 uint8_t inline_data_length[4];
1891 uint8_t data[];
1892 };
1893
1894 struct scsi_extended_copy_lid4_data
1895 {
1896 uint8_t list_format;
1897 #define EC_LIST_FORMAT 0x01
1898 uint8_t flags;
1899 uint8_t header_cscd_list_length[2];
1900 uint8_t reserved[11];
1901 uint8_t flags2;
1902 #define EC_IMMED 0x01
1903 #define EC_G_SENSE 0x02
1904 uint8_t header_cscd_type_code;
1905 uint8_t reserved2[3];
1906 uint8_t list_identifier[4];
1907 uint8_t reserved3[18];
1908 uint8_t cscd_list_length[2];
1909 uint8_t segment_list_length[2];
1910 uint8_t inline_data_length[2];
1911 uint8_t data[];
1912 };
1913
1914 struct scsi_copy_operation_abort
1915 {
1916 uint8_t opcode;
1917 uint8_t service_action;
1918 #define EC_COA 0x1c
1919 uint8_t list_identifier[4];
1920 uint8_t reserved[9];
1921 uint8_t control;
1922 };
1923
1924 struct scsi_populate_token
1925 {
1926 uint8_t opcode;
1927 uint8_t service_action;
1928 #define EC_PT 0x10
1929 uint8_t reserved[4];
1930 uint8_t list_identifier[4];
1931 uint8_t length[4];
1932 uint8_t group_number;
1933 uint8_t control;
1934 };
1935
1936 struct scsi_range_desc
1937 {
1938 uint8_t lba[8];
1939 uint8_t length[4];
1940 uint8_t reserved[4];
1941 };
1942
1943 struct scsi_populate_token_data
1944 {
1945 uint8_t length[2];
1946 uint8_t flags;
1947 #define EC_PT_IMMED 0x01
1948 #define EC_PT_RTV 0x02
1949 uint8_t reserved;
1950 uint8_t inactivity_timeout[4];
1951 uint8_t rod_type[4];
1952 uint8_t reserved2[2];
1953 uint8_t range_descriptor_length[2];
1954 struct scsi_range_desc desc[];
1955 };
1956
1957 struct scsi_write_using_token
1958 {
1959 uint8_t opcode;
1960 uint8_t service_action;
1961 #define EC_WUT 0x11
1962 uint8_t reserved[4];
1963 uint8_t list_identifier[4];
1964 uint8_t length[4];
1965 uint8_t group_number;
1966 uint8_t control;
1967 };
1968
1969 struct scsi_write_using_token_data
1970 {
1971 uint8_t length[2];
1972 uint8_t flags;
1973 #define EC_WUT_IMMED 0x01
1974 #define EC_WUT_DEL_TKN 0x02
1975 uint8_t reserved[5];
1976 uint8_t offset_into_rod[8];
1977 uint8_t rod_token[512];
1978 uint8_t reserved2[6];
1979 uint8_t range_descriptor_length[2];
1980 struct scsi_range_desc desc[];
1981 };
1982
1983 struct scsi_receive_rod_token_information
1984 {
1985 uint8_t opcode;
1986 uint8_t service_action;
1987 #define RCS_RRTI 0x07
1988 uint8_t list_identifier[4];
1989 uint8_t reserved[4];
1990 uint8_t length[4];
1991 uint8_t reserved2;
1992 uint8_t control;
1993 };
1994
1995 struct scsi_token
1996 {
1997 uint8_t type[4];
1998 #define ROD_TYPE_INTERNAL 0x00000000
1999 #define ROD_TYPE_AUR 0x00010000
2000 #define ROD_TYPE_PIT_DEF 0x00800000
2001 #define ROD_TYPE_PIT_VULN 0x00800001
2002 #define ROD_TYPE_PIT_PERS 0x00800002
2003 #define ROD_TYPE_PIT_ANY 0x0080FFFF
2004 #define ROD_TYPE_BLOCK_ZERO 0xFFFF0001
2005 uint8_t reserved[2];
2006 uint8_t length[2];
2007 uint8_t body[0];
2008 };
2009
2010 struct scsi_report_all_rod_tokens
2011 {
2012 uint8_t opcode;
2013 uint8_t service_action;
2014 #define RCS_RART 0x08
2015 uint8_t reserved[8];
2016 uint8_t length[4];
2017 uint8_t reserved2;
2018 uint8_t control;
2019 };
2020
2021 struct scsi_report_all_rod_tokens_data
2022 {
2023 uint8_t available_data[4];
2024 uint8_t reserved[4];
2025 uint8_t rod_management_token_list[];
2026 };
2027
2028 struct ata_pass_16 {
2029 u_int8_t opcode;
2030 u_int8_t protocol;
2031 #define AP_EXTEND 0x01
2032 u_int8_t flags;
2033 #define AP_FLAG_TLEN_NO_DATA (0 << 0)
2034 #define AP_FLAG_TLEN_FEAT (1 << 0)
2035 #define AP_FLAG_TLEN_SECT_CNT (2 << 0)
2036 #define AP_FLAG_TLEN_STPSIU (3 << 0)
2037 #define AP_FLAG_BYT_BLOK_BYTES (0 << 2)
2038 #define AP_FLAG_BYT_BLOK_BLOCKS (1 << 2)
2039 #define AP_FLAG_TDIR_TO_DEV (0 << 3)
2040 #define AP_FLAG_TDIR_FROM_DEV (1 << 3)
2041 #define AP_FLAG_CHK_COND (1 << 5)
2042 u_int8_t features_ext;
2043 u_int8_t features;
2044 u_int8_t sector_count_ext;
2045 u_int8_t sector_count;
2046 u_int8_t lba_low_ext;
2047 u_int8_t lba_low;
2048 u_int8_t lba_mid_ext;
2049 u_int8_t lba_mid;
2050 u_int8_t lba_high_ext;
2051 u_int8_t lba_high;
2052 u_int8_t device;
2053 u_int8_t command;
2054 u_int8_t control;
2055 };
2056
2057 struct ata_pass_32 {
2058 uint8_t opcode;
2059 uint8_t control;
2060 uint8_t reserved1[5];
2061 uint8_t length;
2062 uint8_t service_action[2];
2063 #define ATA_PASS_32_SA 0x1ff0
2064 uint8_t protocol;
2065 uint8_t flags;
2066 uint8_t reserved2[2];
2067 uint8_t lba[6];
2068 uint8_t features[2];
2069 uint8_t count[2];
2070 uint8_t device;
2071 uint8_t command;
2072 uint8_t reserved3;
2073 uint8_t icc;
2074 uint8_t auxiliary[4];
2075 };
2076
2077 #define SC_SCSI_1 0x01
2078 #define SC_SCSI_2 0x03
2079
2080 /*
2081 * Opcodes
2082 */
2083
2084 #define TEST_UNIT_READY 0x00
2085 #define REQUEST_SENSE 0x03
2086 #define READ_6 0x08
2087 #define WRITE_6 0x0A
2088 #define INQUIRY 0x12
2089 #define MODE_SELECT_6 0x15
2090 #define MODE_SENSE_6 0x1A
2091 #define START_STOP_UNIT 0x1B
2092 #define START_STOP 0x1B
2093 #define RESERVE 0x16
2094 #define RELEASE 0x17
2095 #define RECEIVE_DIAGNOSTIC 0x1C
2096 #define SEND_DIAGNOSTIC 0x1D
2097 #define PREVENT_ALLOW 0x1E
2098 #define READ_CAPACITY 0x25
2099 #define READ_10 0x28
2100 #define WRITE_10 0x2A
2101 #define POSITION_TO_ELEMENT 0x2B
2102 #define WRITE_VERIFY_10 0x2E
2103 #define VERIFY_10 0x2F
2104 #define SYNCHRONIZE_CACHE 0x35
2105 #define READ_DEFECT_DATA_10 0x37
2106 #define WRITE_BUFFER 0x3B
2107 #define READ_BUFFER 0x3C
2108 #define CHANGE_DEFINITION 0x40
2109 #define WRITE_SAME_10 0x41
2110 #define UNMAP 0x42
2111 #define LOG_SELECT 0x4C
2112 #define LOG_SENSE 0x4D
2113 #define MODE_SELECT_10 0x55
2114 #define RESERVE_10 0x56
2115 #define RELEASE_10 0x57
2116 #define MODE_SENSE_10 0x5A
2117 #define PERSISTENT_RES_IN 0x5E
2118 #define PERSISTENT_RES_OUT 0x5F
2119 #define EXTENDED_CDB 0x7E
2120 #define VARIABLE_LEN_CDB 0x7F
2121 #define EXTENDED_COPY 0x83
2122 #define RECEIVE_COPY_STATUS 0x84
2123 #define ATA_PASS_16 0x85
2124 #define READ_16 0x88
2125 #define COMPARE_AND_WRITE 0x89
2126 #define WRITE_16 0x8A
2127 #define READ_ATTRIBUTE 0x8C
2128 #define WRITE_ATTRIBUTE 0x8D
2129 #define WRITE_VERIFY_16 0x8E
2130 #define VERIFY_16 0x8F
2131 #define SYNCHRONIZE_CACHE_16 0x91
2132 #define WRITE_SAME_16 0x93
2133 #define READ_BUFFER_16 0x9B
2134 #define WRITE_ATOMIC_16 0x9C
2135 #define SERVICE_ACTION_IN 0x9E
2136 #define REPORT_LUNS 0xA0
2137 #define ATA_PASS_12 0xA1
2138 #define SECURITY_PROTOCOL_IN 0xA2
2139 #define MAINTENANCE_IN 0xA3
2140 #define MAINTENANCE_OUT 0xA4
2141 #define MOVE_MEDIUM 0xA5
2142 #define READ_12 0xA8
2143 #define WRITE_12 0xAA
2144 #define WRITE_VERIFY_12 0xAE
2145 #define VERIFY_12 0xAF
2146 #define SECURITY_PROTOCOL_OUT 0xB5
2147 #define READ_ELEMENT_STATUS 0xB8
2148 #define READ_CD 0xBE
2149
2150 /* Maintenance In Service Action Codes */
2151 #define REPORT_IDENTIFYING_INFRMATION 0x05
2152 #define REPORT_TARGET_PORT_GROUPS 0x0A
2153 #define REPORT_ALIASES 0x0B
2154 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C
2155 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D
2156 #define REPORT_PRIORITY 0x0E
2157 #define REPORT_TIMESTAMP 0x0F
2158 #define MANAGEMENT_PROTOCOL_IN 0x10
2159 /* Maintenance Out Service Action Codes */
2160 #define SET_IDENTIFY_INFORMATION 0x06
2161 #define SET_TARGET_PORT_GROUPS 0x0A
2162 #define CHANGE_ALIASES 0x0B
2163 #define SET_PRIORITY 0x0E
2164 #define SET_TIMESTAMP 0x0F
2165 #define MANAGEMENT_PROTOCOL_OUT 0x10
2166
2167 /*
2168 * Device Types
2169 */
2170 #define T_DIRECT 0x00
2171 #define T_SEQUENTIAL 0x01
2172 #define T_PRINTER 0x02
2173 #define T_PROCESSOR 0x03
2174 #define T_WORM 0x04
2175 #define T_CDROM 0x05
2176 #define T_SCANNER 0x06
2177 #define T_OPTICAL 0x07
2178 #define T_CHANGER 0x08
2179 #define T_COMM 0x09
2180 #define T_ASC0 0x0a
2181 #define T_ASC1 0x0b
2182 #define T_STORARRAY 0x0c
2183 #define T_ENCLOSURE 0x0d
2184 #define T_RBC 0x0e
2185 #define T_OCRW 0x0f
2186 #define T_OSD 0x11
2187 #define T_ADC 0x12
2188 #define T_ZBC_HM 0x14
2189 #define T_NODEVICE 0x1f
2190 #define T_ANY 0xff /* Used in Quirk table matches */
2191
2192 #define T_REMOV 1
2193 #define T_FIXED 0
2194
2195 /*
2196 * This length is the initial inquiry length used by the probe code, as
2197 * well as the length necessary for scsi_print_inquiry() to function
2198 * correctly. If either use requires a different length in the future,
2199 * the two values should be de-coupled.
2200 */
2201 #define SHORT_INQUIRY_LENGTH 36
2202
2203 struct scsi_inquiry_data
2204 {
2205 u_int8_t device;
2206 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
2207 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
2208 #define SID_QUAL_LU_CONNECTED 0x00 /*
2209 * The specified peripheral device
2210 * type is currently connected to
2211 * logical unit. If the target cannot
2212 * determine whether or not a physical
2213 * device is currently connected, it
2214 * shall also use this peripheral
2215 * qualifier when returning the INQUIRY
2216 * data. This peripheral qualifier
2217 * does not mean that the device is
2218 * ready for access by the initiator.
2219 */
2220 #define SID_QUAL_LU_OFFLINE 0x01 /*
2221 * The target is capable of supporting
2222 * the specified peripheral device type
2223 * on this logical unit; however, the
2224 * physical device is not currently
2225 * connected to this logical unit.
2226 */
2227 #define SID_QUAL_RSVD 0x02
2228 #define SID_QUAL_BAD_LU 0x03 /*
2229 * The target is not capable of
2230 * supporting a physical device on
2231 * this logical unit. For this
2232 * peripheral qualifier the peripheral
2233 * device type shall be set to 1Fh to
2234 * provide compatibility with previous
2235 * versions of SCSI. All other
2236 * peripheral device type values are
2237 * reserved for this peripheral
2238 * qualifier.
2239 */
2240 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x04) != 0)
2241 u_int8_t dev_qual2;
2242 #define SID_QUAL2 0x7F
2243 #define SID_LU_CONG 0x40
2244 #define SID_RMB 0x80
2245 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & SID_RMB) != 0)
2246 u_int8_t version;
2247 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
2248 #define SCSI_REV_0 0
2249 #define SCSI_REV_CCS 1
2250 #define SCSI_REV_2 2
2251 #define SCSI_REV_SPC 3
2252 #define SCSI_REV_SPC2 4
2253 #define SCSI_REV_SPC3 5
2254 #define SCSI_REV_SPC4 6
2255 #define SCSI_REV_SPC5 7
2256
2257 #define SID_ECMA 0x38
2258 #define SID_ISO 0xC0
2259 u_int8_t response_format;
2260 #define SID_AENC 0x80
2261 #define SID_TrmIOP 0x40
2262 #define SID_NormACA 0x20
2263 #define SID_HiSup 0x10
2264 u_int8_t additional_length;
2265 #define SID_ADDITIONAL_LENGTH(iqd) \
2266 ((iqd)->additional_length + \
2267 __offsetof(struct scsi_inquiry_data, additional_length) + 1)
2268 u_int8_t spc3_flags;
2269 #define SPC3_SID_PROTECT 0x01
2270 #define SPC3_SID_3PC 0x08
2271 #define SPC3_SID_TPGS_MASK 0x30
2272 #define SPC3_SID_TPGS_IMPLICIT 0x10
2273 #define SPC3_SID_TPGS_EXPLICIT 0x20
2274 #define SPC3_SID_ACC 0x40
2275 #define SPC3_SID_SCCS 0x80
2276 u_int8_t spc2_flags;
2277 #define SPC2_SID_ADDR16 0x01
2278 #define SPC2_SID_MChngr 0x08
2279 #define SPC2_SID_MultiP 0x10
2280 #define SPC2_SID_EncServ 0x40
2281 #define SPC2_SID_BQueue 0x80
2282
2283 #define INQ_DATA_TQ_ENABLED(iqd) \
2284 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
2285 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
2286 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
2287
2288 u_int8_t flags;
2289 #define SID_SftRe 0x01
2290 #define SID_CmdQue 0x02
2291 #define SID_Linked 0x08
2292 #define SID_Sync 0x10
2293 #define SID_WBus16 0x20
2294 #define SID_WBus32 0x40
2295 #define SID_RelAdr 0x80
2296 #define SID_VENDOR_SIZE 8
2297 char vendor[SID_VENDOR_SIZE];
2298 #define SID_PRODUCT_SIZE 16
2299 char product[SID_PRODUCT_SIZE];
2300 #define SID_REVISION_SIZE 4
2301 char revision[SID_REVISION_SIZE];
2302 /*
2303 * The following fields were taken from SCSI Primary Commands - 2
2304 * (SPC-2) Revision 14, Dated 11 November 1999
2305 */
2306 #define SID_VENDOR_SPECIFIC_0_SIZE 20
2307 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
2308 /*
2309 * An extension of SCSI Parallel Specific Values
2310 */
2311 #define SID_SPI_IUS 0x01
2312 #define SID_SPI_QAS 0x02
2313 #define SID_SPI_CLOCK_ST 0x00
2314 #define SID_SPI_CLOCK_DT 0x04
2315 #define SID_SPI_CLOCK_DT_ST 0x0C
2316 #define SID_SPI_MASK 0x0F
2317 u_int8_t spi3data;
2318 u_int8_t reserved2;
2319 /*
2320 * Version Descriptors, stored 2 byte values.
2321 */
2322 u_int8_t version1[2];
2323 u_int8_t version2[2];
2324 u_int8_t version3[2];
2325 u_int8_t version4[2];
2326 u_int8_t version5[2];
2327 u_int8_t version6[2];
2328 u_int8_t version7[2];
2329 u_int8_t version8[2];
2330
2331 u_int8_t reserved3[22];
2332
2333 #define SID_VENDOR_SPECIFIC_1_SIZE 160
2334 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
2335 };
2336
2337 /*
2338 * This structure is more suited to initiator operation, because the
2339 * maximum number of supported pages is already allocated.
2340 */
2341 struct scsi_vpd_supported_page_list
2342 {
2343 u_int8_t device;
2344 u_int8_t page_code;
2345 #define SVPD_SUPPORTED_PAGE_LIST 0x00
2346 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4
2347 u_int8_t reserved;
2348 u_int8_t length; /* number of VPD entries */
2349 #define SVPD_SUPPORTED_PAGES_SIZE 251
2350 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
2351 };
2352
2353 /*
2354 * This structure is more suited to target operation, because the
2355 * number of supported pages is left to the user to allocate.
2356 */
2357 struct scsi_vpd_supported_pages
2358 {
2359 u_int8_t device;
2360 u_int8_t page_code;
2361 u_int8_t reserved;
2362 #define SVPD_SUPPORTED_PAGES 0x00
2363 u_int8_t length;
2364 u_int8_t page_list[0];
2365 };
2366
2367 struct scsi_vpd_unit_serial_number
2368 {
2369 u_int8_t device;
2370 u_int8_t page_code;
2371 #define SVPD_UNIT_SERIAL_NUMBER 0x80
2372 u_int8_t reserved;
2373 u_int8_t length; /* serial number length */
2374 #define SVPD_SERIAL_NUM_SIZE 251
2375 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
2376 };
2377
2378 struct scsi_vpd_device_id
2379 {
2380 u_int8_t device;
2381 u_int8_t page_code;
2382 #define SVPD_DEVICE_ID 0x83
2383 #define SVPD_DEVICE_ID_MAX_SIZE 252
2384 #define SVPD_DEVICE_ID_HDR_LEN \
2385 __offsetof(struct scsi_vpd_device_id, desc_list)
2386 u_int8_t length[2];
2387 u_int8_t desc_list[];
2388 };
2389
2390 struct scsi_vpd_id_descriptor
2391 {
2392 u_int8_t proto_codeset;
2393 /*
2394 * See the SCSI_PROTO definitions above for the protocols.
2395 */
2396 #define SVPD_ID_PROTO_SHIFT 4
2397 #define SVPD_ID_CODESET_BINARY 0x01
2398 #define SVPD_ID_CODESET_ASCII 0x02
2399 #define SVPD_ID_CODESET_UTF8 0x03
2400 #define SVPD_ID_CODESET_MASK 0x0f
2401 u_int8_t id_type;
2402 #define SVPD_ID_PIV 0x80
2403 #define SVPD_ID_ASSOC_LUN 0x00
2404 #define SVPD_ID_ASSOC_PORT 0x10
2405 #define SVPD_ID_ASSOC_TARGET 0x20
2406 #define SVPD_ID_ASSOC_MASK 0x30
2407 #define SVPD_ID_TYPE_VENDOR 0x00
2408 #define SVPD_ID_TYPE_T10 0x01
2409 #define SVPD_ID_TYPE_EUI64 0x02
2410 #define SVPD_ID_TYPE_NAA 0x03
2411 #define SVPD_ID_TYPE_RELTARG 0x04
2412 #define SVPD_ID_TYPE_TPORTGRP 0x05
2413 #define SVPD_ID_TYPE_LUNGRP 0x06
2414 #define SVPD_ID_TYPE_MD5_LUN_ID 0x07
2415 #define SVPD_ID_TYPE_SCSI_NAME 0x08
2416 #define SVPD_ID_TYPE_PROTO 0x09
2417 #define SVPD_ID_TYPE_UUID 0x0a
2418 #define SVPD_ID_TYPE_MASK 0x0f
2419 u_int8_t reserved;
2420 u_int8_t length;
2421 #define SVPD_DEVICE_ID_DESC_HDR_LEN \
2422 __offsetof(struct scsi_vpd_id_descriptor, identifier)
2423 u_int8_t identifier[];
2424 };
2425
2426 struct scsi_vpd_id_t10
2427 {
2428 u_int8_t vendor[8];
2429 u_int8_t vendor_spec_id[0];
2430 };
2431
2432 struct scsi_vpd_id_eui64
2433 {
2434 u_int8_t ieee_company_id[3];
2435 u_int8_t extension_id[5];
2436 };
2437
2438 struct scsi_vpd_id_naa_basic
2439 {
2440 uint8_t naa;
2441 /* big endian, packed:
2442 uint8_t naa : 4;
2443 uint8_t naa_desig : 4;
2444 */
2445 #define SVPD_ID_NAA_NAA_SHIFT 4
2446 #define SVPD_ID_NAA_IEEE_EXT 0x02
2447 #define SVPD_ID_NAA_LOCAL_REG 0x03
2448 #define SVPD_ID_NAA_IEEE_REG 0x05
2449 #define SVPD_ID_NAA_IEEE_REG_EXT 0x06
2450 uint8_t naa_data[];
2451 };
2452
2453 struct scsi_vpd_id_naa_ieee_extended_id
2454 {
2455 uint8_t naa;
2456 uint8_t vendor_specific_id_a;
2457 uint8_t ieee_company_id[3];
2458 uint8_t vendor_specific_id_b[4];
2459 };
2460
2461 struct scsi_vpd_id_naa_local_reg
2462 {
2463 uint8_t naa;
2464 uint8_t local_value[7];
2465 };
2466
2467 struct scsi_vpd_id_naa_ieee_reg
2468 {
2469 uint8_t naa;
2470 uint8_t reg_value[7];
2471 /* big endian, packed:
2472 uint8_t naa_basic : 4;
2473 uint8_t ieee_company_id_0 : 4;
2474 uint8_t ieee_company_id_1[2];
2475 uint8_t ieee_company_id_2 : 4;
2476 uint8_t vendor_specific_id_0 : 4;
2477 uint8_t vendor_specific_id_1[4];
2478 */
2479 };
2480
2481 struct scsi_vpd_id_naa_ieee_reg_extended
2482 {
2483 uint8_t naa;
2484 uint8_t reg_value[15];
2485 /* big endian, packed:
2486 uint8_t naa_basic : 4;
2487 uint8_t ieee_company_id_0 : 4;
2488 uint8_t ieee_company_id_1[2];
2489 uint8_t ieee_company_id_2 : 4;
2490 uint8_t vendor_specific_id_0 : 4;
2491 uint8_t vendor_specific_id_1[4];
2492 uint8_t vendor_specific_id_ext[8];
2493 */
2494 };
2495
2496 struct scsi_vpd_id_rel_trgt_port_id
2497 {
2498 uint8_t obsolete[2];
2499 uint8_t rel_trgt_port_id[2];
2500 };
2501
2502 struct scsi_vpd_id_trgt_port_grp_id
2503 {
2504 uint8_t reserved[2];
2505 uint8_t trgt_port_grp[2];
2506 };
2507
2508 struct scsi_vpd_id_lun_grp_id
2509 {
2510 uint8_t reserved[2];
2511 uint8_t log_unit_grp[2];
2512 };
2513
2514 struct scsi_vpd_id_md5_lun_id
2515 {
2516 uint8_t lun_id[16];
2517 };
2518
2519 struct scsi_vpd_id_scsi_name
2520 {
2521 uint8_t name_string[256];
2522 };
2523
2524 struct scsi_service_action_in
2525 {
2526 uint8_t opcode;
2527 uint8_t service_action;
2528 uint8_t action_dependent[13];
2529 uint8_t control;
2530 };
2531
2532 struct scsi_vpd_extended_inquiry_data
2533 {
2534 uint8_t device;
2535 uint8_t page_code;
2536 #define SVPD_EXTENDED_INQUIRY_DATA 0x86
2537 uint8_t page_length[2];
2538 uint8_t flags1;
2539
2540 /* These values are for direct access devices */
2541 #define SVPD_EID_AM_MASK 0xC0
2542 #define SVPD_EID_AM_DEFER 0x80
2543 #define SVPD_EID_AM_IMMED 0x40
2544 #define SVPD_EID_AM_UNDEFINED 0x00
2545 #define SVPD_EID_AM_RESERVED 0xc0
2546 #define SVPD_EID_SPT 0x38
2547 #define SVPD_EID_SPT_1 0x00
2548 #define SVPD_EID_SPT_12 0x08
2549 #define SVPD_EID_SPT_2 0x10
2550 #define SVPD_EID_SPT_13 0x18
2551 #define SVPD_EID_SPT_3 0x20
2552 #define SVPD_EID_SPT_23 0x28
2553 #define SVPD_EID_SPT_123 0x38
2554
2555 /* These values are for sequential access devices */
2556 #define SVPD_EID_SA_SPT_LBP 0x08
2557
2558 #define SVPD_EID_GRD_CHK 0x04
2559 #define SVPD_EID_APP_CHK 0x02
2560 #define SVPD_EID_REF_CHK 0x01
2561
2562 uint8_t flags2;
2563 #define SVPD_EID_UASK_SUP 0x20
2564 #define SVPD_EID_GROUP_SUP 0x10
2565 #define SVPD_EID_PRIOR_SUP 0x08
2566 #define SVPD_EID_HEADSUP 0x04
2567 #define SVPD_EID_ORDSUP 0x02
2568 #define SVPD_EID_SIMPSUP 0x01
2569 uint8_t flags3;
2570 #define SVPD_EID_WU_SUP 0x08
2571 #define SVPD_EID_CRD_SUP 0x04
2572 #define SVPD_EID_NV_SUP 0x02
2573 #define SVPD_EID_V_SUP 0x01
2574 uint8_t flags4;
2575 #define SVPD_EID_NO_PI_CHK 0x20
2576 #define SVPD_EID_P_I_I_SUP 0x10
2577 #define SVPD_EID_LUICLR 0x01
2578 uint8_t flags5;
2579 #define SVPD_EID_LUCT_MASK 0xe0
2580 #define SVPD_EID_LUCT_NOT_REP 0x00
2581 #define SVPD_EID_LUCT_CONGL 0x20
2582 #define SVPD_EID_LUCT_GROUP 0x40
2583 #define SVPD_EID_R_SUP 0x10
2584 #define SVPD_EID_RTD_SUP 0x08
2585 #define SVPD_EID_HSSRELEF 0x02
2586 #define SVPD_EID_CBCS 0x01
2587 uint8_t flags6;
2588 #define SVPD_EID_MULTI_I_T_FW 0x0F
2589 #define SVPD_EID_MC_VENDOR_SPEC 0x00
2590 #define SVPD_EID_MC_MODE_1 0x01
2591 #define SVPD_EID_MC_MODE_2 0x02
2592 #define SVPD_EID_MC_MODE_3 0x03
2593 uint8_t est[2];
2594 uint8_t flags7;
2595 #define SVPD_EID_POA_SUP 0x80
2596 #define SVPD_EID_HRA_SUP 0x40
2597 #define SVPD_EID_VSA_SUP 0x20
2598 uint8_t max_sense_length;
2599 uint8_t bind_flags;
2600 #define SVPD_EID_IBS 0x80
2601 #define SVPD_EID_IAS 0x40
2602 #define SVPD_EID_SAC 0x04
2603 #define SVPD_EID_NRD1 0x02
2604 #define SVPD_EID_NRD0 0x01
2605 uint8_t reserved2[49];
2606 };
2607
2608 struct scsi_vpd_mode_page_policy_descr
2609 {
2610 uint8_t page_code;
2611 uint8_t subpage_code;
2612 uint8_t policy;
2613 #define SVPD_MPP_SHARED 0x00
2614 #define SVPD_MPP_PORT 0x01
2615 #define SVPD_MPP_I_T 0x03
2616 #define SVPD_MPP_MLUS 0x80
2617 uint8_t reserved;
2618 };
2619
2620 struct scsi_vpd_mode_page_policy
2621 {
2622 uint8_t device;
2623 uint8_t page_code;
2624 #define SVPD_MODE_PAGE_POLICY 0x87
2625 uint8_t page_length[2];
2626 struct scsi_vpd_mode_page_policy_descr descr[0];
2627 };
2628
2629 struct scsi_diag_page {
2630 uint8_t page_code;
2631 uint8_t page_specific_flags;
2632 uint8_t length[2];
2633 uint8_t params[0];
2634 };
2635
2636 struct scsi_vpd_port_designation
2637 {
2638 uint8_t reserved[2];
2639 uint8_t relative_port_id[2];
2640 uint8_t reserved2[2];
2641 uint8_t initiator_transportid_length[2];
2642 uint8_t initiator_transportid[0];
2643 };
2644
2645 struct scsi_vpd_port_designation_cont
2646 {
2647 uint8_t reserved[2];
2648 uint8_t target_port_descriptors_length[2];
2649 struct scsi_vpd_id_descriptor target_port_descriptors[0];
2650 };
2651
2652 struct scsi_vpd_scsi_ports
2653 {
2654 u_int8_t device;
2655 u_int8_t page_code;
2656 #define SVPD_SCSI_PORTS 0x88
2657 u_int8_t page_length[2];
2658 struct scsi_vpd_port_designation design[];
2659 };
2660
2661 /*
2662 * ATA Information VPD Page based on
2663 * T10/2126-D Revision 04
2664 */
2665 #define SVPD_ATA_INFORMATION 0x89
2666
2667 struct scsi_vpd_tpc_descriptor
2668 {
2669 uint8_t desc_type[2];
2670 uint8_t desc_length[2];
2671 uint8_t parameters[];
2672 };
2673
2674 struct scsi_vpd_tpc_descriptor_bdrl
2675 {
2676 uint8_t desc_type[2];
2677 #define SVPD_TPC_BDRL 0x0000
2678 uint8_t desc_length[2];
2679 uint8_t vendor_specific[6];
2680 uint8_t maximum_ranges[2];
2681 uint8_t maximum_inactivity_timeout[4];
2682 uint8_t default_inactivity_timeout[4];
2683 uint8_t maximum_token_transfer_size[8];
2684 uint8_t optimal_transfer_count[8];
2685 };
2686
2687 struct scsi_vpd_tpc_descriptor_sc_descr
2688 {
2689 uint8_t opcode;
2690 uint8_t sa_length;
2691 uint8_t supported_service_actions[0];
2692 };
2693
2694 struct scsi_vpd_tpc_descriptor_sc
2695 {
2696 uint8_t desc_type[2];
2697 #define SVPD_TPC_SC 0x0001
2698 uint8_t desc_length[2];
2699 uint8_t list_length;
2700 struct scsi_vpd_tpc_descriptor_sc_descr descr[];
2701 };
2702
2703 struct scsi_vpd_tpc_descriptor_pd
2704 {
2705 uint8_t desc_type[2];
2706 #define SVPD_TPC_PD 0x0004
2707 uint8_t desc_length[2];
2708 uint8_t reserved[4];
2709 uint8_t maximum_cscd_descriptor_count[2];
2710 uint8_t maximum_segment_descriptor_count[2];
2711 uint8_t maximum_descriptor_list_length[4];
2712 uint8_t maximum_inline_data_length[4];
2713 uint8_t reserved2[12];
2714 };
2715
2716 struct scsi_vpd_tpc_descriptor_sd
2717 {
2718 uint8_t desc_type[2];
2719 #define SVPD_TPC_SD 0x0008
2720 uint8_t desc_length[2];
2721 uint8_t list_length;
2722 uint8_t supported_descriptor_codes[];
2723 };
2724
2725 struct scsi_vpd_tpc_descriptor_sdid
2726 {
2727 uint8_t desc_type[2];
2728 #define SVPD_TPC_SDID 0x000C
2729 uint8_t desc_length[2];
2730 uint8_t list_length[2];
2731 uint8_t supported_descriptor_ids[];
2732 };
2733
2734 struct scsi_vpd_tpc_descriptor_rtf_block
2735 {
2736 uint8_t type_format;
2737 #define SVPD_TPC_RTF_BLOCK 0x00
2738 uint8_t reserved;
2739 uint8_t desc_length[2];
2740 uint8_t reserved2[2];
2741 uint8_t optimal_length_granularity[2];
2742 uint8_t maximum_bytes[8];
2743 uint8_t optimal_bytes[8];
2744 uint8_t optimal_bytes_to_token_per_segment[8];
2745 uint8_t optimal_bytes_from_token_per_segment[8];
2746 uint8_t reserved3[8];
2747 };
2748
2749 struct scsi_vpd_tpc_descriptor_rtf
2750 {
2751 uint8_t desc_type[2];
2752 #define SVPD_TPC_RTF 0x0106
2753 uint8_t desc_length[2];
2754 uint8_t remote_tokens;
2755 uint8_t reserved[11];
2756 uint8_t minimum_token_lifetime[4];
2757 uint8_t maximum_token_lifetime[4];
2758 uint8_t maximum_token_inactivity_timeout[4];
2759 uint8_t reserved2[18];
2760 uint8_t type_specific_features_length[2];
2761 uint8_t type_specific_features[0];
2762 };
2763
2764 struct scsi_vpd_tpc_descriptor_srtd
2765 {
2766 uint8_t rod_type[4];
2767 uint8_t flags;
2768 #define SVPD_TPC_SRTD_TOUT 0x01
2769 #define SVPD_TPC_SRTD_TIN 0x02
2770 #define SVPD_TPC_SRTD_ECPY 0x80
2771 uint8_t reserved;
2772 uint8_t preference_indicator[2];
2773 uint8_t reserved2[56];
2774 };
2775
2776 struct scsi_vpd_tpc_descriptor_srt
2777 {
2778 uint8_t desc_type[2];
2779 #define SVPD_TPC_SRT 0x0108
2780 uint8_t desc_length[2];
2781 uint8_t reserved[2];
2782 uint8_t rod_type_descriptors_length[2];
2783 uint8_t rod_type_descriptors[0];
2784 };
2785
2786 struct scsi_vpd_tpc_descriptor_gco
2787 {
2788 uint8_t desc_type[2];
2789 #define SVPD_TPC_GCO 0x8001
2790 uint8_t desc_length[2];
2791 uint8_t total_concurrent_copies[4];
2792 uint8_t maximum_identified_concurrent_copies[4];
2793 uint8_t maximum_segment_length[4];
2794 uint8_t data_segment_granularity;
2795 uint8_t inline_data_granularity;
2796 uint8_t reserved[18];
2797 };
2798
2799 struct scsi_vpd_tpc
2800 {
2801 uint8_t device;
2802 uint8_t page_code;
2803 #define SVPD_SCSI_TPC 0x8F
2804 uint8_t page_length[2];
2805 struct scsi_vpd_tpc_descriptor descr[];
2806 };
2807
2808 /*
2809 * SCSI Feature Sets VPD Page
2810 */
2811 struct scsi_vpd_sfs
2812 {
2813 uint8_t device;
2814 uint8_t page_code;
2815 #define SVPD_SCSI_SFS 0x92
2816 uint8_t page_length[2];
2817 uint8_t reserved[4];
2818 uint8_t codes[];
2819 };
2820
2821 /*
2822 * Block Device Characteristics VPD Page
2823 */
2824 struct scsi_vpd_block_device_characteristics
2825 {
2826 uint8_t device;
2827 uint8_t page_code;
2828 #define SVPD_BDC 0xB1
2829 uint8_t page_length[2];
2830 uint8_t medium_rotation_rate[2];
2831 #define SVPD_NOT_REPORTED 0x0000
2832 #define SVPD_NON_ROTATING 0x0001
2833 uint8_t product_type;
2834 uint8_t wab_wac_ff;
2835 uint8_t flags;
2836 #define SVPD_VBULS 0x01
2837 #define SVPD_FUAB 0x02
2838 #define SVPD_BOCS 0x04
2839 #define SVPD_RBWZ 0x08
2840 #define SVPD_ZBC_NR 0x00 /* Not Reported */
2841 #define SVPD_HAW_ZBC 0x10 /* Host Aware */
2842 #define SVPD_DM_ZBC 0x20 /* Drive Managed */
2843 #define SVPD_ZBC_MASK 0x30 /* Zoned mask */
2844 uint8_t reserved[3];
2845 uint8_t depopulation_time[4];
2846 uint8_t reserved2[48];
2847 };
2848
2849 #define SBDC_IS_PRESENT(bdc, length, field) \
2850 ((length >= offsetof(struct scsi_vpd_block_device_characteristics, \
2851 field) + sizeof(bdc->field)) ? 1 : 0)
2852
2853 /*
2854 * Logical Block Provisioning VPD Page based on
2855 * T10/1799-D Revision 31
2856 */
2857 struct scsi_vpd_logical_block_prov
2858 {
2859 u_int8_t device;
2860 u_int8_t page_code;
2861 #define SVPD_LBP 0xB2
2862 u_int8_t page_length[2];
2863 #define SVPD_LBP_PL_BASIC 0x04
2864 u_int8_t threshold_exponent;
2865 u_int8_t flags;
2866 #define SVPD_LBP_UNMAP 0x80
2867 #define SVPD_LBP_WS16 0x40
2868 #define SVPD_LBP_WS10 0x20
2869 #define SVPD_LBP_RZ 0x04
2870 #define SVPD_LBP_ANC_SUP 0x02
2871 #define SVPD_LBP_DP 0x01
2872 u_int8_t prov_type;
2873 #define SVPD_LBP_RESOURCE 0x01
2874 #define SVPD_LBP_THIN 0x02
2875 u_int8_t reserved;
2876 /*
2877 * Provisioning Group Descriptor can be here if SVPD_LBP_DP is set
2878 * Its size can be determined from page_length - 4
2879 */
2880 };
2881
2882 /*
2883 * Block Limits VDP Page based on SBC-4 Revision 17
2884 */
2885 struct scsi_vpd_block_limits
2886 {
2887 u_int8_t device;
2888 u_int8_t page_code;
2889 #define SVPD_BLOCK_LIMITS 0xB0
2890 u_int8_t page_length[2];
2891 #define SVPD_BL_PL_BASIC 0x10
2892 #define SVPD_BL_PL_TP 0x3C
2893 u_int8_t flags;
2894 #define SVPD_BL_WSNZ 0x01
2895 u_int8_t max_cmp_write_len;
2896 u_int8_t opt_txfer_len_grain[2];
2897 u_int8_t max_txfer_len[4];
2898 u_int8_t opt_txfer_len[4];
2899 u_int8_t max_prefetch[4];
2900 u_int8_t max_unmap_lba_cnt[4];
2901 u_int8_t max_unmap_blk_cnt[4];
2902 u_int8_t opt_unmap_grain[4];
2903 u_int8_t unmap_grain_align[4];
2904 u_int8_t max_write_same_length[8];
2905 u_int8_t max_atomic_transfer_length[4];
2906 u_int8_t atomic_alignment[4];
2907 u_int8_t atomic_transfer_length_granularity[4];
2908 u_int8_t max_atomic_transfer_length_with_atomic_boundary[4];
2909 u_int8_t max_atomic_boundary_size[4];
2910 };
2911
2912 /*
2913 * Zoned Block Device Characacteristics VPD page.
2914 * From ZBC-r04, dated August 12, 2015.
2915 */
2916 struct scsi_vpd_zoned_bdc {
2917 uint8_t device;
2918 uint8_t page_code;
2919 #define SVPD_ZONED_BDC 0xB6
2920 uint8_t page_length[2];
2921 #define SVPD_ZBDC_PL 0x3C
2922 uint8_t flags;
2923 #define SVPD_ZBDC_URSWRZ 0x01
2924 uint8_t reserved1[3];
2925 uint8_t optimal_seq_zones[4];
2926 #define SVPD_ZBDC_OPT_SEQ_NR 0xffffffff
2927 uint8_t optimal_nonseq_zones[4];
2928 #define SVPD_ZBDC_OPT_NONSEQ_NR 0xffffffff
2929 uint8_t max_seq_req_zones[4];
2930 #define SVPD_ZBDC_MAX_SEQ_UNLIMITED 0xffffffff
2931 uint8_t reserved2[44];
2932 };
2933
2934 struct scsi_read_capacity
2935 {
2936 u_int8_t opcode;
2937 u_int8_t byte2;
2938 #define SRC_RELADR 0x01
2939 u_int8_t addr[4];
2940 u_int8_t unused[2];
2941 u_int8_t pmi;
2942 #define SRC_PMI 0x01
2943 u_int8_t control;
2944 };
2945
2946 struct scsi_read_capacity_16
2947 {
2948 uint8_t opcode;
2949 #define SRC16_SERVICE_ACTION 0x10
2950 uint8_t service_action;
2951 uint8_t addr[8];
2952 uint8_t alloc_len[4];
2953 #define SRC16_PMI 0x01
2954 #define SRC16_RELADR 0x02
2955 uint8_t reladr;
2956 uint8_t control;
2957 };
2958
2959 struct scsi_read_capacity_data
2960 {
2961 u_int8_t addr[4];
2962 u_int8_t length[4];
2963 };
2964
2965 struct scsi_read_capacity_data_long
2966 {
2967 uint8_t addr[8];
2968 uint8_t length[4];
2969 #define SRC16_PROT_EN 0x01
2970 #define SRC16_P_TYPE 0x0e
2971 #define SRC16_P_TYPE_SHIFT 1
2972 #define SRC16_PTYPE_1 0x00
2973 #define SRC16_PTYPE_2 0x02
2974 #define SRC16_PTYPE_3 0x04
2975 uint8_t prot;
2976 #define SRC16_LBPPBE 0x0f
2977 #define SRC16_PI_EXPONENT 0xf0
2978 #define SRC16_PI_EXPONENT_SHIFT 4
2979 uint8_t prot_lbppbe;
2980 #define SRC16_LALBA 0x3f
2981 #define SRC16_LBPRZ 0x40
2982 #define SRC16_LBPME 0x80
2983 /*
2984 * Alternate versions of these macros that are intended for use on a 16-bit
2985 * version of the lalba_lbp field instead of the array of 2 8 bit numbers.
2986 */
2987 #define SRC16_LALBA_A 0x3fff
2988 #define SRC16_LBPRZ_A 0x4000
2989 #define SRC16_LBPME_A 0x8000
2990 uint8_t lalba_lbp[2];
2991 uint8_t reserved[16];
2992 };
2993
2994 struct scsi_get_lba_status
2995 {
2996 uint8_t opcode;
2997 #define SGLS_SERVICE_ACTION 0x12
2998 uint8_t service_action;
2999 uint8_t addr[8];
3000 uint8_t alloc_len[4];
3001 uint8_t reserved;
3002 uint8_t control;
3003 };
3004
3005 struct scsi_get_lba_status_data_descr
3006 {
3007 uint8_t addr[8];
3008 uint8_t length[4];
3009 uint8_t status;
3010 uint8_t reserved[3];
3011 };
3012
3013 struct scsi_get_lba_status_data
3014 {
3015 uint8_t length[4];
3016 uint8_t reserved[4];
3017 struct scsi_get_lba_status_data_descr descr[];
3018 };
3019
3020 struct scsi_report_luns
3021 {
3022 uint8_t opcode;
3023 uint8_t reserved1;
3024 #define RPL_REPORT_DEFAULT 0x00
3025 #define RPL_REPORT_WELLKNOWN 0x01
3026 #define RPL_REPORT_ALL 0x02
3027 #define RPL_REPORT_ADMIN 0x10
3028 #define RPL_REPORT_NONSUBSID 0x11
3029 #define RPL_REPORT_CONGLOM 0x12
3030 uint8_t select_report;
3031 uint8_t reserved2[3];
3032 uint8_t length[4];
3033 uint8_t reserved3;
3034 uint8_t control;
3035 };
3036
3037 struct scsi_report_luns_lundata {
3038 uint8_t lundata[8];
3039 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
3040 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
3041 #define RPL_LUNDATA_FLAT_LUN_BITS 0x06
3042 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
3043 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
3044 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
3045 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
3046 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
3047 #define RPL_LUNDATA_EXT_EAM_WK 0x01
3048 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
3049 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
3050 #define RPL_LUNDATA_ATYP_PERIPH 0x00
3051 #define RPL_LUNDATA_ATYP_FLAT 0x40
3052 #define RPL_LUNDATA_ATYP_LUN 0x80
3053 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
3054 };
3055
3056 struct scsi_report_luns_data {
3057 u_int8_t length[4]; /* length of LUN inventory, in bytes */
3058 u_int8_t reserved[4]; /* unused */
3059 /*
3060 * LUN inventory- we only support the type zero form for now.
3061 */
3062 struct scsi_report_luns_lundata luns[0];
3063 };
3064
3065 struct scsi_target_group
3066 {
3067 uint8_t opcode;
3068 uint8_t service_action;
3069 #define STG_PDF_MASK 0xe0
3070 #define STG_PDF_LENGTH 0x00
3071 #define STG_PDF_EXTENDED 0x20
3072 uint8_t reserved1[4];
3073 uint8_t length[4];
3074 uint8_t reserved2;
3075 uint8_t control;
3076 };
3077
3078 struct scsi_timestamp
3079 {
3080 uint8_t opcode;
3081 uint8_t service_action;
3082 uint8_t reserved1[4];
3083 uint8_t length[4];
3084 uint8_t reserved2;
3085 uint8_t control;
3086 };
3087
3088 struct scsi_set_timestamp_parameters
3089 {
3090 uint8_t reserved1[4];
3091 uint8_t timestamp[6];
3092 uint8_t reserved2[2];
3093 };
3094
3095 struct scsi_report_timestamp_parameter_data
3096 {
3097 uint8_t length[2];
3098 uint8_t reserved1[2];
3099 uint8_t timestamp[6];
3100 uint8_t reserved2[2];
3101 };
3102
3103 struct scsi_target_port_descriptor {
3104 uint8_t reserved[2];
3105 uint8_t relative_target_port_identifier[2];
3106 uint8_t desc_list[];
3107 };
3108
3109 struct scsi_target_port_group_descriptor {
3110 uint8_t pref_state;
3111 #define TPG_PRIMARY 0x80
3112 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf
3113 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0
3114 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1
3115 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2
3116 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3
3117 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4
3118 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE
3119 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF
3120 uint8_t support;
3121 #define TPG_AO_SUP 0x01
3122 #define TPG_AN_SUP 0x02
3123 #define TPG_S_SUP 0x04
3124 #define TPG_U_SUP 0x08
3125 #define TPG_LBD_SUP 0x10
3126 #define TPG_O_SUP 0x40
3127 #define TPG_T_SUP 0x80
3128 uint8_t target_port_group[2];
3129 uint8_t reserved;
3130 uint8_t status;
3131 #define TPG_UNAVLBL 0
3132 #define TPG_SET_BY_STPG 0x01
3133 #define TPG_IMPLICIT 0x02
3134 uint8_t vendor_specific;
3135 uint8_t target_port_count;
3136 struct scsi_target_port_descriptor descriptors[];
3137 };
3138
3139 struct scsi_target_group_data {
3140 uint8_t length[4]; /* length of returned data, in bytes */
3141 struct scsi_target_port_group_descriptor groups[];
3142 };
3143
3144 struct scsi_target_group_data_extended {
3145 uint8_t length[4]; /* length of returned data, in bytes */
3146 uint8_t format_type; /* STG_PDF_LENGTH or STG_PDF_EXTENDED */
3147 uint8_t implicit_transition_time;
3148 uint8_t reserved[2];
3149 struct scsi_target_port_group_descriptor groups[];
3150 };
3151
3152 struct scsi_security_protocol_in
3153 {
3154 uint8_t opcode;
3155 uint8_t security_protocol;
3156 #define SPI_PROT_INFORMATION 0x00
3157 #define SPI_PROT_CBCS 0x07
3158 #define SPI_PROT_TAPE_DATA_ENC 0x20
3159 #define SPI_PROT_DATA_ENC_CONFIG 0x21
3160 #define SPI_PROT_SA_CREATE_CAP 0x40
3161 #define SPI_PROT_IKEV2_SCSI 0x41
3162 #define SPI_PROT_JEDEC_UFS 0xEC
3163 #define SPI_PROT_SDCARD_TFSSS 0xED
3164 #define SPI_PROT_AUTH_HOST_TRANSIENT 0xEE
3165 #define SPI_PROT_ATA_DEVICE_PASSWORD 0xEF
3166 uint8_t security_protocol_specific[2];
3167 uint8_t byte4;
3168 #define SPI_INC_512 0x80
3169 uint8_t reserved1;
3170 uint8_t length[4];
3171 uint8_t reserved2;
3172 uint8_t control;
3173 };
3174
3175 struct scsi_security_protocol_out
3176 {
3177 uint8_t opcode;
3178 uint8_t security_protocol;
3179 uint8_t security_protocol_specific[2];
3180 uint8_t byte4;
3181 #define SPO_INC_512 0x80
3182 uint8_t reserved1;
3183 uint8_t length[4];
3184 uint8_t reserved2;
3185 uint8_t control;
3186 };
3187
3188 typedef enum {
3189 SSD_TYPE_NONE,
3190 SSD_TYPE_FIXED,
3191 SSD_TYPE_DESC
3192 } scsi_sense_data_type;
3193
3194 typedef enum {
3195 SSD_ELEM_NONE,
3196 SSD_ELEM_SKIP,
3197 SSD_ELEM_DESC,
3198 SSD_ELEM_SKS,
3199 SSD_ELEM_COMMAND,
3200 SSD_ELEM_INFO,
3201 SSD_ELEM_FRU,
3202 SSD_ELEM_STREAM,
3203 SSD_ELEM_MAX
3204 } scsi_sense_elem_type;
3205
3206 struct scsi_sense_data
3207 {
3208 uint8_t error_code;
3209 /*
3210 * SPC-4 says that the maximum length of sense data is 252 bytes.
3211 * So this structure is exactly 252 bytes log.
3212 */
3213 #define SSD_FULL_SIZE 252
3214 uint8_t sense_buf[SSD_FULL_SIZE - 1];
3215 /*
3216 * XXX KDM is this still a reasonable minimum size?
3217 */
3218 #define SSD_MIN_SIZE 18
3219 /*
3220 * Maximum value for the extra_len field in the sense data.
3221 */
3222 #define SSD_EXTRA_MAX 244
3223 };
3224
3225 /*
3226 * Fixed format sense data.
3227 */
3228 struct scsi_sense_data_fixed
3229 {
3230 u_int8_t error_code;
3231 #define SSD_ERRCODE 0x7F
3232 #define SSD_CURRENT_ERROR 0x70
3233 #define SSD_DEFERRED_ERROR 0x71
3234 #define SSD_ERRCODE_VALID 0x80
3235 u_int8_t segment;
3236 u_int8_t flags;
3237 #define SSD_KEY 0x0F
3238 #define SSD_KEY_NO_SENSE 0x00
3239 #define SSD_KEY_RECOVERED_ERROR 0x01
3240 #define SSD_KEY_NOT_READY 0x02
3241 #define SSD_KEY_MEDIUM_ERROR 0x03
3242 #define SSD_KEY_HARDWARE_ERROR 0x04
3243 #define SSD_KEY_ILLEGAL_REQUEST 0x05
3244 #define SSD_KEY_UNIT_ATTENTION 0x06
3245 #define SSD_KEY_DATA_PROTECT 0x07
3246 #define SSD_KEY_BLANK_CHECK 0x08
3247 #define SSD_KEY_Vendor_Specific 0x09
3248 #define SSD_KEY_COPY_ABORTED 0x0a
3249 #define SSD_KEY_ABORTED_COMMAND 0x0b
3250 #define SSD_KEY_EQUAL 0x0c
3251 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
3252 #define SSD_KEY_MISCOMPARE 0x0e
3253 #define SSD_KEY_COMPLETED 0x0f
3254 #define SSD_SDAT_OVFL 0x10
3255 #define SSD_ILI 0x20
3256 #define SSD_EOM 0x40
3257 #define SSD_FILEMARK 0x80
3258 u_int8_t info[4];
3259 u_int8_t extra_len;
3260 u_int8_t cmd_spec_info[4];
3261 u_int8_t add_sense_code;
3262 u_int8_t add_sense_code_qual;
3263 u_int8_t fru;
3264 u_int8_t sense_key_spec[3];
3265 #define SSD_SCS_VALID 0x80
3266 #define SSD_FIELDPTR_CMD 0x40
3267 #define SSD_BITPTR_VALID 0x08
3268 #define SSD_BITPTR_VALUE 0x07
3269 u_int8_t extra_bytes[14];
3270 #define SSD_FIXED_IS_PRESENT(sense, length, field) \
3271 ((length >= (offsetof(struct scsi_sense_data_fixed, field) + \
3272 sizeof(sense->field))) ? 1 :0)
3273 #define SSD_FIXED_IS_FILLED(sense, field) \
3274 ((((offsetof(struct scsi_sense_data_fixed, field) + \
3275 sizeof(sense->field)) - \
3276 (offsetof(struct scsi_sense_data_fixed, extra_len) + \
3277 sizeof(sense->extra_len))) <= sense->extra_len) ? 1 : 0)
3278 };
3279
3280 /*
3281 * Descriptor format sense data definitions.
3282 * Introduced in SPC-3.
3283 */
3284 struct scsi_sense_data_desc
3285 {
3286 uint8_t error_code;
3287 #define SSD_DESC_CURRENT_ERROR 0x72
3288 #define SSD_DESC_DEFERRED_ERROR 0x73
3289 uint8_t sense_key;
3290 uint8_t add_sense_code;
3291 uint8_t add_sense_code_qual;
3292 uint8_t flags;
3293 #define SSDD_SDAT_OVFL 0x80
3294 uint8_t reserved[2];
3295 /*
3296 * Note that SPC-4, section 4.5.2.1 says that the extra_len field
3297 * must be less than or equal to 244.
3298 */
3299 uint8_t extra_len;
3300 uint8_t sense_desc[0];
3301 #define SSD_DESC_IS_PRESENT(sense, length, field) \
3302 ((length >= (offsetof(struct scsi_sense_data_desc, field) + \
3303 sizeof(sense->field))) ? 1 :0)
3304 };
3305
3306 struct scsi_sense_desc_header
3307 {
3308 uint8_t desc_type;
3309 uint8_t length;
3310 };
3311 /*
3312 * The information provide in the Information descriptor is device type or
3313 * command specific information, and defined in a command standard.
3314 *
3315 * Note that any changes to the field names or positions in this structure,
3316 * even reserved fields, should be accompanied by an examination of the
3317 * code in ctl_set_sense() that uses them.
3318 *
3319 * Maximum descriptors allowed: 1 (as of SPC-4)
3320 */
3321 struct scsi_sense_info
3322 {
3323 uint8_t desc_type;
3324 #define SSD_DESC_INFO 0x00
3325 uint8_t length;
3326 uint8_t byte2;
3327 #define SSD_INFO_VALID 0x80
3328 uint8_t reserved;
3329 uint8_t info[8];
3330 };
3331
3332 /*
3333 * Command-specific information depends on the command for which the
3334 * reported condition occurred.
3335 *
3336 * Note that any changes to the field names or positions in this structure,
3337 * even reserved fields, should be accompanied by an examination of the
3338 * code in ctl_set_sense() that uses them.
3339 *
3340 * Maximum descriptors allowed: 1 (as of SPC-4)
3341 */
3342 struct scsi_sense_command
3343 {
3344 uint8_t desc_type;
3345 #define SSD_DESC_COMMAND 0x01
3346 uint8_t length;
3347 uint8_t reserved[2];
3348 uint8_t command_info[8];
3349 };
3350
3351 /*
3352 * Sense key specific descriptor. The sense key specific data format
3353 * depends on the sense key in question.
3354 *
3355 * Maximum descriptors allowed: 1 (as of SPC-4)
3356 */
3357 struct scsi_sense_sks
3358 {
3359 uint8_t desc_type;
3360 #define SSD_DESC_SKS 0x02
3361 uint8_t length;
3362 uint8_t reserved1[2];
3363 uint8_t sense_key_spec[3];
3364 #define SSD_SKS_VALID 0x80
3365 uint8_t reserved2;
3366 };
3367
3368 /*
3369 * This is used for the Illegal Request sense key (0x05) only.
3370 */
3371 struct scsi_sense_sks_field
3372 {
3373 uint8_t byte0;
3374 #define SSD_SKS_FIELD_VALID 0x80
3375 #define SSD_SKS_FIELD_CMD 0x40
3376 #define SSD_SKS_BPV 0x08
3377 #define SSD_SKS_BIT_VALUE 0x07
3378 uint8_t field[2];
3379 };
3380
3381 /*
3382 * This is used for the Hardware Error (0x04), Medium Error (0x03) and
3383 * Recovered Error (0x01) sense keys.
3384 */
3385 struct scsi_sense_sks_retry
3386 {
3387 uint8_t byte0;
3388 #define SSD_SKS_RETRY_VALID 0x80
3389 uint8_t actual_retry_count[2];
3390 };
3391
3392 /*
3393 * Used with the NO Sense (0x00) or Not Ready (0x02) sense keys.
3394 */
3395 struct scsi_sense_sks_progress
3396 {
3397 uint8_t byte0;
3398 #define SSD_SKS_PROGRESS_VALID 0x80
3399 uint8_t progress[2];
3400 #define SSD_SKS_PROGRESS_DENOM 0x10000
3401 };
3402
3403 /*
3404 * Used with the Copy Aborted (0x0a) sense key.
3405 */
3406 struct scsi_sense_sks_segment
3407 {
3408 uint8_t byte0;
3409 #define SSD_SKS_SEGMENT_VALID 0x80
3410 #define SSD_SKS_SEGMENT_SD 0x20
3411 #define SSD_SKS_SEGMENT_BPV 0x08
3412 #define SSD_SKS_SEGMENT_BITPTR 0x07
3413 uint8_t field[2];
3414 };
3415
3416 /*
3417 * Used with the Unit Attention (0x06) sense key.
3418 *
3419 * This is currently used to indicate that the unit attention condition
3420 * queue has overflowed (when the overflow bit is set).
3421 */
3422 struct scsi_sense_sks_overflow
3423 {
3424 uint8_t byte0;
3425 #define SSD_SKS_OVERFLOW_VALID 0x80
3426 #define SSD_SKS_OVERFLOW_SET 0x01
3427 uint8_t reserved[2];
3428 };
3429
3430 /*
3431 * This specifies which component is associated with the sense data. There
3432 * is no standard meaning for the fru value.
3433 *
3434 * Maximum descriptors allowed: 1 (as of SPC-4)
3435 */
3436 struct scsi_sense_fru
3437 {
3438 uint8_t desc_type;
3439 #define SSD_DESC_FRU 0x03
3440 uint8_t length;
3441 uint8_t reserved;
3442 uint8_t fru;
3443 };
3444
3445 /*
3446 * Used for Stream commands, defined in SSC-4.
3447 *
3448 * Maximum descriptors allowed: 1 (as of SPC-4)
3449 */
3450
3451 struct scsi_sense_stream
3452 {
3453 uint8_t desc_type;
3454 #define SSD_DESC_STREAM 0x04
3455 uint8_t length;
3456 uint8_t reserved;
3457 uint8_t byte3;
3458 #define SSD_DESC_STREAM_FM 0x80
3459 #define SSD_DESC_STREAM_EOM 0x40
3460 #define SSD_DESC_STREAM_ILI 0x20
3461 };
3462
3463 /*
3464 * Used for Block commands, defined in SBC-3.
3465 *
3466 * This is currently (as of SBC-3) only used for the Incorrect Length
3467 * Indication (ILI) bit, which says that the data length requested in the
3468 * READ LONG or WRITE LONG command did not match the length of the logical
3469 * block.
3470 *
3471 * Maximum descriptors allowed: 1 (as of SPC-4)
3472 */
3473 struct scsi_sense_block
3474 {
3475 uint8_t desc_type;
3476 #define SSD_DESC_BLOCK 0x05
3477 uint8_t length;
3478 uint8_t reserved;
3479 uint8_t byte3;
3480 #define SSD_DESC_BLOCK_ILI 0x20
3481 };
3482
3483 /*
3484 * Used for Object-Based Storage Devices (OSD-3).
3485 *
3486 * Maximum descriptors allowed: 1 (as of SPC-4)
3487 */
3488 struct scsi_sense_osd_objid
3489 {
3490 uint8_t desc_type;
3491 #define SSD_DESC_OSD_OBJID 0x06
3492 uint8_t length;
3493 uint8_t reserved[6];
3494 /*
3495 * XXX KDM provide the bit definitions here? There are a lot of
3496 * them, and we don't have an OSD driver yet.
3497 */
3498 uint8_t not_init_cmds[4];
3499 uint8_t completed_cmds[4];
3500 uint8_t partition_id[8];
3501 uint8_t object_id[8];
3502 };
3503
3504 /*
3505 * Used for Object-Based Storage Devices (OSD-3).
3506 *
3507 * Maximum descriptors allowed: 1 (as of SPC-4)
3508 */
3509 struct scsi_sense_osd_integrity
3510 {
3511 uint8_t desc_type;
3512 #define SSD_DESC_OSD_INTEGRITY 0x07
3513 uint8_t length;
3514 uint8_t integ_check_val[32];
3515 };
3516
3517 /*
3518 * Used for Object-Based Storage Devices (OSD-3).
3519 *
3520 * Maximum descriptors allowed: 1 (as of SPC-4)
3521 */
3522 struct scsi_sense_osd_attr_id
3523 {
3524 uint8_t desc_type;
3525 #define SSD_DESC_OSD_ATTR_ID 0x08
3526 uint8_t length;
3527 uint8_t reserved[2];
3528 uint8_t attr_desc[0];
3529 };
3530
3531 /*
3532 * ATA Return descriptor, used for the SCSI ATA PASS-THROUGH(12), (16) and
3533 * (32) commands. Described in SAT-4r05.
3534 */
3535 struct scsi_sense_ata_ret_desc
3536 {
3537 uint8_t desc_type;
3538 #define SSD_DESC_ATA 0x09
3539 uint8_t length;
3540 uint8_t flags;
3541 #define SSD_DESC_ATA_FLAG_EXTEND 0x01
3542 uint8_t error;
3543 uint8_t count_15_8;
3544 uint8_t count_7_0;
3545 uint8_t lba_31_24;
3546 uint8_t lba_7_0;
3547 uint8_t lba_39_32;
3548 uint8_t lba_15_8;
3549 uint8_t lba_47_40;
3550 uint8_t lba_23_16;
3551 uint8_t device;
3552 uint8_t status;
3553 };
3554 /*
3555 * Used with Sense keys No Sense (0x00) and Not Ready (0x02).
3556 *
3557 * Maximum descriptors allowed: 32 (as of SPC-4)
3558 */
3559 struct scsi_sense_progress
3560 {
3561 uint8_t desc_type;
3562 #define SSD_DESC_PROGRESS 0x0a
3563 uint8_t length;
3564 uint8_t sense_key;
3565 uint8_t add_sense_code;
3566 uint8_t add_sense_code_qual;
3567 uint8_t reserved;
3568 uint8_t progress[2];
3569 };
3570
3571 /*
3572 * This is typically forwarded as the result of an EXTENDED COPY command.
3573 *
3574 * Maximum descriptors allowed: 2 (as of SPC-4)
3575 */
3576 struct scsi_sense_forwarded
3577 {
3578 uint8_t desc_type;
3579 #define SSD_DESC_FORWARDED 0x0c
3580 uint8_t length;
3581 uint8_t byte2;
3582 #define SSD_FORWARDED_FSDT 0x80
3583 #define SSD_FORWARDED_SDS_MASK 0x0f
3584 #define SSD_FORWARDED_SDS_UNK 0x00
3585 #define SSD_FORWARDED_SDS_EXSRC 0x01
3586 #define SSD_FORWARDED_SDS_EXDST 0x02
3587 uint8_t status;
3588 uint8_t sense_data[];
3589 };
3590
3591 /*
3592 * Vendor-specific sense descriptor. The desc_type field will be in the
3593 * range between MIN and MAX inclusive.
3594 */
3595 struct scsi_sense_vendor
3596 {
3597 uint8_t desc_type;
3598 #define SSD_DESC_VENDOR_MIN 0x80
3599 #define SSD_DESC_VENDOR_MAX 0xff
3600 uint8_t length;
3601 uint8_t data[0];
3602 };
3603
3604 struct scsi_mode_header_6
3605 {
3606 u_int8_t data_length; /* Sense data length */
3607 u_int8_t medium_type;
3608 u_int8_t dev_spec;
3609 u_int8_t blk_desc_len;
3610 };
3611
3612 struct scsi_mode_header_10
3613 {
3614 u_int8_t data_length[2];/* Sense data length */
3615 u_int8_t medium_type;
3616 u_int8_t dev_spec;
3617 u_int8_t flags;
3618 #define SMH_LONGLBA 0x01
3619 u_int8_t unused;
3620 u_int8_t blk_desc_len[2];
3621 };
3622
3623 struct scsi_mode_page_header
3624 {
3625 u_int8_t page_code;
3626 #define SMPH_PS 0x80
3627 #define SMPH_SPF 0x40
3628 #define SMPH_PC_MASK 0x3f
3629 u_int8_t page_length;
3630 };
3631
3632 struct scsi_mode_page_header_sp
3633 {
3634 uint8_t page_code;
3635 uint8_t subpage;
3636 uint8_t page_length[2];
3637 };
3638
3639 struct scsi_mode_blk_desc
3640 {
3641 u_int8_t density;
3642 u_int8_t nblocks[3];
3643 u_int8_t reserved;
3644 u_int8_t blklen[3];
3645 };
3646
3647 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
3648 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
3649
3650 /*
3651 * Status Byte
3652 */
3653 #define SCSI_STATUS_OK 0x00
3654 #define SCSI_STATUS_CHECK_COND 0x02
3655 #define SCSI_STATUS_COND_MET 0x04
3656 #define SCSI_STATUS_BUSY 0x08
3657 #define SCSI_STATUS_INTERMED 0x10
3658 #define SCSI_STATUS_INTERMED_COND_MET 0x14
3659 #define SCSI_STATUS_RESERV_CONFLICT 0x18
3660 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
3661 #define SCSI_STATUS_QUEUE_FULL 0x28
3662 #define SCSI_STATUS_ACA_ACTIVE 0x30
3663 #define SCSI_STATUS_TASK_ABORTED 0x40
3664
3665 struct scsi_inquiry_pattern {
3666 u_int8_t type;
3667 u_int8_t media_type;
3668 #define SIP_MEDIA_REMOVABLE 0x01
3669 #define SIP_MEDIA_FIXED 0x02
3670 const char *vendor;
3671 const char *product;
3672 const char *revision;
3673 };
3674
3675 struct scsi_static_inquiry_pattern {
3676 u_int8_t type;
3677 u_int8_t media_type;
3678 char vendor[SID_VENDOR_SIZE+1];
3679 char product[SID_PRODUCT_SIZE+1];
3680 char revision[SID_REVISION_SIZE+1];
3681 };
3682
3683 struct scsi_sense_quirk_entry {
3684 struct scsi_inquiry_pattern inq_pat;
3685 int num_sense_keys;
3686 int num_ascs;
3687 struct sense_key_table_entry *sense_key_info;
3688 struct asc_table_entry *asc_info;
3689 };
3690
3691 struct sense_key_table_entry {
3692 u_int8_t sense_key;
3693 u_int32_t action;
3694 const char *desc;
3695 };
3696
3697 struct asc_table_entry {
3698 u_int8_t asc;
3699 u_int8_t ascq;
3700 u_int32_t action;
3701 const char *desc;
3702 };
3703
3704 struct op_table_entry {
3705 u_int8_t opcode;
3706 u_int32_t opmask;
3707 const char *desc;
3708 };
3709
3710 struct scsi_op_quirk_entry {
3711 struct scsi_inquiry_pattern inq_pat;
3712 int num_ops;
3713 struct op_table_entry *op_table;
3714 };
3715
3716 typedef enum {
3717 SSS_FLAG_NONE = 0x00,
3718 SSS_FLAG_PRINT_COMMAND = 0x01
3719 } scsi_sense_string_flags;
3720
3721 struct scsi_nv {
3722 const char *name;
3723 uint64_t value;
3724 };
3725
3726 typedef enum {
3727 SCSI_NV_FOUND,
3728 SCSI_NV_AMBIGUOUS,
3729 SCSI_NV_NOT_FOUND
3730 } scsi_nv_status;
3731
3732 typedef enum {
3733 SCSI_NV_FLAG_NONE = 0x00,
3734 SCSI_NV_FLAG_IG_CASE = 0x01 /* Case insensitive comparison */
3735 } scsi_nv_flags;
3736
3737 struct ccb_scsiio;
3738 struct cam_periph;
3739 union ccb;
3740 #ifndef _KERNEL
3741 struct cam_device;
3742 #endif
3743
3744 extern const char *scsi_sense_key_text[];
3745
3746 __BEGIN_DECLS
3747 void scsi_sense_desc(int sense_key, int asc, int ascq,
3748 struct scsi_inquiry_data *inq_data,
3749 const char **sense_key_desc, const char **asc_desc);
3750 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
3751 struct scsi_inquiry_data *inq_data,
3752 u_int32_t sense_flags);
3753 const char * scsi_status_string(struct ccb_scsiio *csio);
3754
3755 void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3756 int (*iter_func)(struct scsi_sense_data_desc *sense,
3757 u_int, struct scsi_sense_desc_header *,
3758 void *), void *arg);
3759 uint8_t *scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3760 uint8_t desc_type);
3761 void scsi_set_sense_data(struct scsi_sense_data *sense_data,
3762 scsi_sense_data_type sense_format, int current_error,
3763 int sense_key, int asc, int ascq, ...) ;
3764 void scsi_set_sense_data_len(struct scsi_sense_data *sense_data,
3765 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3766 int sense_key, int asc, int ascq, ...) ;
3767 void scsi_set_sense_data_va(struct scsi_sense_data *sense_data,
3768 u_int *sense_len, scsi_sense_data_type sense_format,
3769 int current_error, int sense_key, int asc, int ascq, va_list ap);
3770 int scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
3771 uint8_t info_type, uint64_t *info,
3772 int64_t *signed_info);
3773 int scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len,
3774 uint8_t *sks);
3775 int scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
3776 struct scsi_inquiry_data *inq_data,
3777 uint8_t *block_bits);
3778 int scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
3779 struct scsi_inquiry_data *inq_data,
3780 uint8_t *stream_bits);
3781 void scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3782 struct scsi_inquiry_data *inq_data, uint64_t info);
3783 void scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3784 struct scsi_inquiry_data *inq_data, uint64_t csi);
3785 void scsi_progress_sbuf(struct sbuf *sb, uint16_t progress);
3786 int scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks);
3787 void scsi_fru_sbuf(struct sbuf *sb, uint64_t fru);
3788 void scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits);
3789 void scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits);
3790 void scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3791 u_int sense_len, uint8_t *cdb, int cdb_len,
3792 struct scsi_inquiry_data *inq_data,
3793 struct scsi_sense_desc_header *header);
3794
3795 void scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3796 u_int sense_len, uint8_t *cdb, int cdb_len,
3797 struct scsi_inquiry_data *inq_data,
3798 struct scsi_sense_desc_header *header);
3799 void scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3800 u_int sense_len, uint8_t *cdb, int cdb_len,
3801 struct scsi_inquiry_data *inq_data,
3802 struct scsi_sense_desc_header *header);
3803 void scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3804 u_int sense_len, uint8_t *cdb, int cdb_len,
3805 struct scsi_inquiry_data *inq_data,
3806 struct scsi_sense_desc_header *header);
3807 void scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3808 u_int sense_len, uint8_t *cdb, int cdb_len,
3809 struct scsi_inquiry_data *inq_data,
3810 struct scsi_sense_desc_header *header);
3811 void scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3812 u_int sense_len, uint8_t *cdb, int cdb_len,
3813 struct scsi_inquiry_data *inq_data,
3814 struct scsi_sense_desc_header *header);
3815 void scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3816 u_int sense_len, uint8_t *cdb, int cdb_len,
3817 struct scsi_inquiry_data *inq_data,
3818 struct scsi_sense_desc_header *header);
3819 void scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3820 u_int sense_len, uint8_t *cdb, int cdb_len,
3821 struct scsi_inquiry_data *inq_data,
3822 struct scsi_sense_desc_header *header);
3823 void scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3824 u_int sense_len, uint8_t *cdb, int cdb_len,
3825 struct scsi_inquiry_data *inq_data,
3826 struct scsi_sense_desc_header *header);
3827 void scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3828 u_int sense_len, uint8_t *cdb, int cdb_len,
3829 struct scsi_inquiry_data *inq_data,
3830 struct scsi_sense_desc_header *header);
3831 void scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3832 u_int sense_len, uint8_t *cdb, int cdb_len,
3833 struct scsi_inquiry_data *inq_data,
3834 struct scsi_sense_desc_header *header);
3835 scsi_sense_data_type scsi_sense_type(struct scsi_sense_data *sense_data);
3836
3837 void scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
3838 struct sbuf *sb, char *path_str,
3839 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
3840 int cdb_len);
3841
3842 #ifdef _KERNEL
3843 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
3844 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
3845 scsi_sense_string_flags flags);
3846 char * scsi_sense_string(struct ccb_scsiio *csio,
3847 char *str, int str_len);
3848 void scsi_sense_print(struct ccb_scsiio *csio);
3849 int scsi_vpd_supported_page(struct cam_periph *periph,
3850 uint8_t page_id);
3851 #else /* _KERNEL */
3852 int scsi_command_string(struct cam_device *device,
3853 struct ccb_scsiio *csio, struct sbuf *sb);
3854 int scsi_sense_sbuf(struct cam_device *device,
3855 struct ccb_scsiio *csio, struct sbuf *sb,
3856 scsi_sense_string_flags flags);
3857 char * scsi_sense_string(struct cam_device *device,
3858 struct ccb_scsiio *csio,
3859 char *str, int str_len);
3860 void scsi_sense_print(struct cam_device *device,
3861 struct ccb_scsiio *csio, FILE *ofile);
3862 #endif /* _KERNEL */
3863
3864 const char * scsi_op_desc(u_int16_t opcode,
3865 struct scsi_inquiry_data *inq_data);
3866 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
3867 size_t len);
3868 void scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb);
3869
3870 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
3871 void scsi_print_inquiry_sbuf(struct sbuf *sb,
3872 struct scsi_inquiry_data *inq_data);
3873 void scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data);
3874 void scsi_print_inquiry_short_sbuf(struct sbuf *sb,
3875 struct scsi_inquiry_data *inq_data);
3876
3877 u_int scsi_calc_syncsrate(u_int period_factor);
3878 u_int scsi_calc_syncparam(u_int period);
3879
3880 typedef int (*scsi_devid_checkfn_t)(uint8_t *);
3881 int scsi_devid_is_naa_ieee_reg(uint8_t *bufp);
3882 int scsi_devid_is_sas_target(uint8_t *bufp);
3883 int scsi_devid_is_lun_eui64(uint8_t *bufp);
3884 int scsi_devid_is_lun_naa(uint8_t *bufp);
3885 int scsi_devid_is_lun_name(uint8_t *bufp);
3886 int scsi_devid_is_lun_t10(uint8_t *bufp);
3887 int scsi_devid_is_lun_md5(uint8_t *bufp);
3888 int scsi_devid_is_lun_uuid(uint8_t *bufp);
3889 int scsi_devid_is_port_naa(uint8_t *bufp);
3890 struct scsi_vpd_id_descriptor *
3891 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t len,
3892 scsi_devid_checkfn_t ck_fn);
3893 struct scsi_vpd_id_descriptor *
3894 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
3895 scsi_devid_checkfn_t ck_fn);
3896
3897 int scsi_transportid_sbuf(struct sbuf *sb,
3898 struct scsi_transportid_header *hdr,
3899 uint32_t valid_len);
3900
3901 const char * scsi_nv_to_str(struct scsi_nv *table, int num_table_entries,
3902 uint64_t value);
3903
3904 scsi_nv_status scsi_get_nv(struct scsi_nv *table, int num_table_entries,
3905 char *name, int *table_entry, scsi_nv_flags flags);
3906
3907 int scsi_parse_transportid_64bit(int proto_id, char *id_str,
3908 struct scsi_transportid_header **hdr,
3909 unsigned int *alloc_len,
3910 #ifdef _KERNEL
3911 struct malloc_type *type, int flags,
3912 #endif
3913 char *error_str, int error_str_len);
3914
3915 int scsi_parse_transportid_spi(char *id_str,
3916 struct scsi_transportid_header **hdr,
3917 unsigned int *alloc_len,
3918 #ifdef _KERNEL
3919 struct malloc_type *type, int flags,
3920 #endif
3921 char *error_str, int error_str_len);
3922
3923 int scsi_parse_transportid_rdma(char *id_str,
3924 struct scsi_transportid_header **hdr,
3925 unsigned int *alloc_len,
3926 #ifdef _KERNEL
3927 struct malloc_type *type, int flags,
3928 #endif
3929 char *error_str, int error_str_len);
3930
3931 int scsi_parse_transportid_iscsi(char *id_str,
3932 struct scsi_transportid_header **hdr,
3933 unsigned int *alloc_len,
3934 #ifdef _KERNEL
3935 struct malloc_type *type, int flags,
3936 #endif
3937 char *error_str,int error_str_len);
3938
3939 int scsi_parse_transportid_sop(char *id_str,
3940 struct scsi_transportid_header **hdr,
3941 unsigned int *alloc_len,
3942 #ifdef _KERNEL
3943 struct malloc_type *type, int flags,
3944 #endif
3945 char *error_str,int error_str_len);
3946
3947 int scsi_parse_transportid(char *transportid_str,
3948 struct scsi_transportid_header **hdr,
3949 unsigned int *alloc_len,
3950 #ifdef _KERNEL
3951 struct malloc_type *type, int flags,
3952 #endif
3953 char *error_str, int error_str_len);
3954
3955 int scsi_attrib_volcoh_sbuf(struct sbuf *sb,
3956 struct scsi_mam_attribute_header *hdr,
3957 uint32_t valid_len, uint32_t flags,
3958 uint32_t output_flags, char *error_str,
3959 int error_str_len);
3960
3961 int scsi_attrib_vendser_sbuf(struct sbuf *sb,
3962 struct scsi_mam_attribute_header *hdr,
3963 uint32_t valid_len, uint32_t flags,
3964 uint32_t output_flags, char *error_str,
3965 int error_str_len);
3966
3967 int scsi_attrib_hexdump_sbuf(struct sbuf *sb,
3968 struct scsi_mam_attribute_header *hdr,
3969 uint32_t valid_len, uint32_t flags,
3970 uint32_t output_flags, char *error_str,
3971 int error_str_len);
3972
3973 int scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
3974 uint32_t valid_len, uint32_t flags,
3975 uint32_t output_flags, char *error_str,
3976 int error_str_len);
3977
3978 int scsi_attrib_ascii_sbuf(struct sbuf *sb,
3979 struct scsi_mam_attribute_header *hdr,
3980 uint32_t valid_len, uint32_t flags,
3981 uint32_t output_flags, char *error_str,
3982 int error_str_len);
3983
3984 int scsi_attrib_text_sbuf(struct sbuf *sb,
3985 struct scsi_mam_attribute_header *hdr,
3986 uint32_t valid_len, uint32_t flags,
3987 uint32_t output_flags, char *error_str,
3988 int error_str_len);
3989
3990 struct scsi_attrib_table_entry *scsi_find_attrib_entry(
3991 struct scsi_attrib_table_entry *table,
3992 size_t num_table_entries, uint32_t id);
3993
3994 struct scsi_attrib_table_entry *scsi_get_attrib_entry(uint32_t id);
3995
3996 int scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
3997 struct scsi_mam_attribute_header *hdr,
3998 uint32_t output_flags, char *error_str,
3999 size_t error_str_len);
4000
4001 void scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
4002 struct scsi_mam_attribute_header *hdr,
4003 uint32_t valid_len, const char *desc);
4004
4005 int scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
4006 uint32_t valid_len,
4007 struct scsi_attrib_table_entry *user_table,
4008 size_t num_user_entries, int prefer_user_table,
4009 uint32_t output_flags, char *error_str, int error_str_len);
4010
4011 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
4012 void (*cbfcnp)(struct cam_periph *,
4013 union ccb *),
4014 u_int8_t tag_action,
4015 u_int8_t sense_len, u_int32_t timeout);
4016
4017 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
4018 void (*cbfcnp)(struct cam_periph *,
4019 union ccb *),
4020 void *data_ptr, u_int8_t dxfer_len,
4021 u_int8_t tag_action, u_int8_t sense_len,
4022 u_int32_t timeout);
4023
4024 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
4025 void (*cbfcnp)(struct cam_periph *, union ccb *),
4026 u_int8_t tag_action, u_int8_t *inq_buf,
4027 u_int32_t inq_len, int evpd, u_int8_t page_code,
4028 u_int8_t sense_len, u_int32_t timeout);
4029
4030 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
4031 void (*cbfcnp)(struct cam_periph *, union ccb *),
4032 uint8_t tag_action, int dbd, uint8_t pc, uint8_t page,
4033 uint8_t *param_buf, uint32_t param_len,
4034 uint8_t sense_len, uint32_t timeout);
4035
4036 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
4037 void (*cbfcnp)(struct cam_periph *, union ccb *),
4038 uint8_t tag_action, int dbd, uint8_t pc, uint8_t page,
4039 uint8_t *param_buf, uint32_t param_len,
4040 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout);
4041
4042 void scsi_mode_sense_subpage(struct ccb_scsiio *csio,
4043 uint32_t retries,
4044 void (*cbfcnp)(struct cam_periph *, union ccb *),
4045 uint8_t tag_action, int dbd, uint8_t pc,
4046 uint8_t page, uint8_t subpage,
4047 uint8_t *param_buf, uint32_t param_len,
4048 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout);
4049
4050 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
4051 void (*cbfcnp)(struct cam_periph *,
4052 union ccb *),
4053 u_int8_t tag_action, int scsi_page_fmt,
4054 int save_pages, u_int8_t *param_buf,
4055 u_int32_t param_len, u_int8_t sense_len,
4056 u_int32_t timeout);
4057
4058 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
4059 void (*cbfcnp)(struct cam_periph *,
4060 union ccb *),
4061 u_int8_t tag_action, int scsi_page_fmt,
4062 int save_pages, u_int8_t *param_buf,
4063 u_int32_t param_len, int minimum_cmd_size,
4064 u_int8_t sense_len, u_int32_t timeout);
4065
4066 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
4067 void (*cbfcnp)(struct cam_periph *, union ccb *),
4068 u_int8_t tag_action, u_int8_t page_code,
4069 u_int8_t page, int save_pages, int ppc,
4070 u_int32_t paramptr, u_int8_t *param_buf,
4071 u_int32_t param_len, u_int8_t sense_len,
4072 u_int32_t timeout);
4073
4074 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
4075 void (*cbfcnp)(struct cam_periph *,
4076 union ccb *), u_int8_t tag_action,
4077 u_int8_t page_code, int save_pages,
4078 int pc_reset, u_int8_t *param_buf,
4079 u_int32_t param_len, u_int8_t sense_len,
4080 u_int32_t timeout);
4081
4082 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
4083 void (*cbfcnp)(struct cam_periph *, union ccb *),
4084 u_int8_t tag_action, u_int8_t action,
4085 u_int8_t sense_len, u_int32_t timeout);
4086
4087 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
4088 void (*cbfcnp)(struct cam_periph *,
4089 union ccb *), u_int8_t tag_action,
4090 struct scsi_read_capacity_data *,
4091 u_int8_t sense_len, u_int32_t timeout);
4092 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
4093 void (*cbfcnp)(struct cam_periph *,
4094 union ccb *), uint8_t tag_action,
4095 uint64_t lba, int reladr, int pmi,
4096 uint8_t *rcap_buf, int rcap_buf_len,
4097 uint8_t sense_len, uint32_t timeout);
4098
4099 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
4100 void (*cbfcnp)(struct cam_periph *,
4101 union ccb *), u_int8_t tag_action,
4102 u_int8_t select_report,
4103 struct scsi_report_luns_data *rpl_buf,
4104 u_int32_t alloc_len, u_int8_t sense_len,
4105 u_int32_t timeout);
4106
4107 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
4108 void (*cbfcnp)(struct cam_periph *,
4109 union ccb *), u_int8_t tag_action,
4110 u_int8_t pdf,
4111 void *buf,
4112 u_int32_t alloc_len, u_int8_t sense_len,
4113 u_int32_t timeout);
4114
4115 void scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
4116 void (*cbfcnp)(struct cam_periph *,
4117 union ccb *), u_int8_t tag_action,
4118 u_int8_t pdf,
4119 void *buf,
4120 u_int32_t alloc_len, u_int8_t sense_len,
4121 u_int32_t timeout);
4122
4123 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
4124 void (*cbfcnp)(struct cam_periph *,
4125 union ccb *), u_int8_t tag_action, void *buf,
4126 u_int32_t alloc_len, u_int8_t sense_len,
4127 u_int32_t timeout);
4128
4129 void scsi_create_timestamp(uint8_t *timestamp_6b_buf,
4130 uint64_t timestamp);
4131
4132 void scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
4133 void (*cbfcnp)(struct cam_periph *,
4134 union ccb *), u_int8_t tag_action,
4135 void *buf, u_int32_t alloc_len,
4136 u_int8_t sense_len, u_int32_t timeout);
4137
4138 void scsi_synchronize_cache(struct ccb_scsiio *csio,
4139 u_int32_t retries,
4140 void (*cbfcnp)(struct cam_periph *,
4141 union ccb *), u_int8_t tag_action,
4142 u_int32_t begin_lba, u_int16_t lb_count,
4143 u_int8_t sense_len, u_int32_t timeout);
4144
4145 void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
4146 void (*cbfcnp)(struct cam_periph *,
4147 union ccb*),
4148 uint8_t tag_action, int pcv,
4149 uint8_t page_code, uint8_t *data_ptr,
4150 uint16_t allocation_length,
4151 uint8_t sense_len, uint32_t timeout);
4152
4153 void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
4154 void (*cbfcnp)(struct cam_periph *, union ccb *),
4155 uint8_t tag_action, int unit_offline,
4156 int device_offline, int self_test, int page_format,
4157 int self_test_code, uint8_t *data_ptr,
4158 uint16_t param_list_length, uint8_t sense_len,
4159 uint32_t timeout);
4160
4161 void scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
4162 void (*cbfcnp)(struct cam_periph *, union ccb*),
4163 uint8_t tag_action, int mode,
4164 uint8_t buffer_id, u_int32_t offset,
4165 uint8_t *data_ptr, uint32_t allocation_length,
4166 uint8_t sense_len, uint32_t timeout);
4167
4168 void scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
4169 void (*cbfcnp)(struct cam_periph *, union ccb *),
4170 uint8_t tag_action, int mode,
4171 uint8_t buffer_id, u_int32_t offset,
4172 uint8_t *data_ptr, uint32_t param_list_length,
4173 uint8_t sense_len, uint32_t timeout);
4174
4175 #define SCSI_RW_READ 0x0001
4176 #define SCSI_RW_WRITE 0x0002
4177 #define SCSI_RW_DIRMASK 0x0003
4178 #define SCSI_RW_BIO 0x1000
4179 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
4180 void (*cbfcnp)(struct cam_periph *, union ccb *),
4181 u_int8_t tag_action, int readop, u_int8_t byte2,
4182 int minimum_cmd_size, u_int64_t lba,
4183 u_int32_t block_count, u_int8_t *data_ptr,
4184 u_int32_t dxfer_len, u_int8_t sense_len,
4185 u_int32_t timeout);
4186
4187 void scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
4188 void (*cbfcnp)(struct cam_periph *, union ccb *),
4189 u_int8_t tag_action, u_int8_t byte2,
4190 int minimum_cmd_size, u_int64_t lba,
4191 u_int32_t block_count, u_int8_t *data_ptr,
4192 u_int32_t dxfer_len, u_int8_t sense_len,
4193 u_int32_t timeout);
4194
4195 void scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
4196 void (*cbfcnp)(struct cam_periph *, union ccb *),
4197 u_int8_t tag_action, u_int8_t *data_ptr,
4198 u_int16_t dxfer_len, u_int8_t sense_len,
4199 u_int32_t timeout);
4200
4201 void scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
4202 void (*cbfcnp)(struct cam_periph *, union ccb *),
4203 u_int8_t tag_action, u_int16_t block_count,
4204 u_int8_t *data_ptr, u_int16_t dxfer_len,
4205 u_int8_t sense_len, u_int32_t timeout);
4206
4207 int scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries,
4208 void (*cbfcnp)(struct cam_periph *, union ccb *),
4209 uint8_t tag_action, uint32_t log_address,
4210 uint32_t page_number, uint16_t block_count,
4211 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
4212 uint8_t sense_len, uint32_t timeout);
4213
4214 int scsi_ata_setfeatures(struct ccb_scsiio *csio, uint32_t retries,
4215 void (*cbfcnp)(struct cam_periph *, union ccb *),
4216 uint8_t tag_action, uint8_t feature,
4217 uint64_t lba, uint32_t count,
4218 uint8_t sense_len, uint32_t timeout);
4219
4220 int scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
4221 void (*cbfcnp)(struct cam_periph *, union ccb *),
4222 uint32_t flags, uint8_t tag_action,
4223 uint8_t protocol, uint8_t ata_flags, uint16_t features,
4224 uint16_t sector_count, uint64_t lba, uint8_t command,
4225 uint8_t device, uint8_t icc, uint32_t auxiliary,
4226 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
4227 uint8_t *cdb_storage, size_t cdb_storage_len,
4228 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout);
4229
4230 void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
4231 void (*cbfcnp)(struct cam_periph *, union ccb *),
4232 u_int32_t flags, u_int8_t tag_action,
4233 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
4234 u_int16_t sector_count, uint64_t lba, u_int8_t command,
4235 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
4236 u_int8_t sense_len, u_int32_t timeout);
4237
4238 void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
4239 void (*cbfcnp)(struct cam_periph *, union ccb *),
4240 u_int8_t tag_action, u_int8_t byte2,
4241 u_int8_t *data_ptr, u_int16_t dxfer_len,
4242 u_int8_t sense_len, u_int32_t timeout);
4243
4244 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
4245 void (*cbfcnp)(struct cam_periph *, union ccb *),
4246 u_int8_t tag_action, int start, int load_eject,
4247 int immediate, u_int8_t sense_len, u_int32_t timeout);
4248 void scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
4249 void (*cbfcnp)(struct cam_periph *, union ccb *),
4250 u_int8_t tag_action, u_int8_t service_action,
4251 uint32_t element, u_int8_t elem_type,
4252 int logical_volume, int partition,
4253 u_int32_t first_attribute, int cache, u_int8_t *data_ptr,
4254 u_int32_t length, int sense_len, u_int32_t timeout);
4255 void scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
4256 void (*cbfcnp)(struct cam_periph *, union ccb *),
4257 u_int8_t tag_action, uint32_t element,
4258 int logical_volume, int partition, int wtc, u_int8_t *data_ptr,
4259 u_int32_t length, int sense_len, u_int32_t timeout);
4260
4261 void scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
4262 void (*cbfcnp)(struct cam_periph *, union ccb *),
4263 uint8_t tag_action, uint32_t security_protocol,
4264 uint32_t security_protocol_specific, int byte4,
4265 uint8_t *data_ptr, uint32_t dxfer_len,
4266 int sense_len, int timeout);
4267
4268 void scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
4269 void (*cbfcnp)(struct cam_periph *,union ccb *),
4270 uint8_t tag_action, uint32_t security_protocol,
4271 uint32_t security_protocol_specific, int byte4,
4272 uint8_t *data_ptr, uint32_t dxfer_len,
4273 int sense_len, int timeout);
4274
4275 void scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
4276 void (*cbfcnp)(struct cam_periph *,union ccb *),
4277 uint8_t tag_action, int service_action,
4278 uint8_t *data_ptr, uint32_t dxfer_len,
4279 int sense_len, int timeout);
4280
4281 void scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
4282 void (*cbfcnp)(struct cam_periph *,
4283 union ccb *),
4284 uint8_t tag_action, int service_action,
4285 int scope, int res_type, uint8_t *data_ptr,
4286 uint32_t dxfer_len, int sense_len,
4287 int timeout);
4288
4289 void scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
4290 void (*cbfcnp)(struct cam_periph *,
4291 union ccb *),
4292 uint8_t tag_action, int options,
4293 int req_opcode, int req_service_action,
4294 uint8_t *data_ptr, uint32_t dxfer_len,
4295 int sense_len, int timeout);
4296
4297 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
4298 int scsi_static_inquiry_match(caddr_t inqbuffer,
4299 caddr_t table_entry);
4300 int scsi_devid_match(uint8_t *rhs, size_t rhs_len,
4301 uint8_t *lhs, size_t lhs_len);
4302
4303 void scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
4304 int *sense_key, int *asc, int *ascq);
4305 int scsi_extract_sense_ccb(union ccb *ccb, int *error_code, int *sense_key,
4306 int *asc, int *ascq);
4307 void scsi_extract_sense_len(struct scsi_sense_data *sense,
4308 u_int sense_len, int *error_code, int *sense_key,
4309 int *asc, int *ascq, int show_errors);
4310 int scsi_get_sense_key(struct scsi_sense_data *sense, u_int sense_len,
4311 int show_errors);
4312 int scsi_get_asc(struct scsi_sense_data *sense, u_int sense_len,
4313 int show_errors);
4314 int scsi_get_ascq(struct scsi_sense_data *sense, u_int sense_len,
4315 int show_errors);
4316
4317 static __inline void
scsi_ulto2b(u_int32_t val,u_int8_t * bytes)4318 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
4319 {
4320
4321 bytes[0] = (val >> 8) & 0xff;
4322 bytes[1] = val & 0xff;
4323 }
4324
4325 static __inline void
scsi_ulto3b(u_int32_t val,u_int8_t * bytes)4326 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
4327 {
4328
4329 bytes[0] = (val >> 16) & 0xff;
4330 bytes[1] = (val >> 8) & 0xff;
4331 bytes[2] = val & 0xff;
4332 }
4333
4334 static __inline void
scsi_ulto4b(u_int32_t val,u_int8_t * bytes)4335 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
4336 {
4337
4338 bytes[0] = (val >> 24) & 0xff;
4339 bytes[1] = (val >> 16) & 0xff;
4340 bytes[2] = (val >> 8) & 0xff;
4341 bytes[3] = val & 0xff;
4342 }
4343
4344 static __inline void
scsi_u64to8b(u_int64_t val,u_int8_t * bytes)4345 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
4346 {
4347
4348 bytes[0] = (val >> 56) & 0xff;
4349 bytes[1] = (val >> 48) & 0xff;
4350 bytes[2] = (val >> 40) & 0xff;
4351 bytes[3] = (val >> 32) & 0xff;
4352 bytes[4] = (val >> 24) & 0xff;
4353 bytes[5] = (val >> 16) & 0xff;
4354 bytes[6] = (val >> 8) & 0xff;
4355 bytes[7] = val & 0xff;
4356 }
4357
4358 static __inline uint32_t
scsi_2btoul(const uint8_t * bytes)4359 scsi_2btoul(const uint8_t *bytes)
4360 {
4361 uint32_t rv;
4362
4363 rv = (bytes[0] << 8) |
4364 bytes[1];
4365 return (rv);
4366 }
4367
4368 static __inline uint32_t
scsi_3btoul(const uint8_t * bytes)4369 scsi_3btoul(const uint8_t *bytes)
4370 {
4371 uint32_t rv;
4372
4373 rv = (bytes[0] << 16) |
4374 (bytes[1] << 8) |
4375 bytes[2];
4376 return (rv);
4377 }
4378
4379 static __inline int32_t
scsi_3btol(const uint8_t * bytes)4380 scsi_3btol(const uint8_t *bytes)
4381 {
4382 uint32_t rc = scsi_3btoul(bytes);
4383
4384 if (rc & 0x00800000)
4385 rc |= 0xff000000;
4386
4387 return (int32_t) rc;
4388 }
4389
4390 static __inline uint32_t
scsi_4btoul(const uint8_t * bytes)4391 scsi_4btoul(const uint8_t *bytes)
4392 {
4393 uint32_t rv;
4394
4395 rv = (bytes[0] << 24) |
4396 (bytes[1] << 16) |
4397 (bytes[2] << 8) |
4398 bytes[3];
4399 return (rv);
4400 }
4401
4402 static __inline uint64_t
scsi_8btou64(const uint8_t * bytes)4403 scsi_8btou64(const uint8_t *bytes)
4404 {
4405 uint64_t rv;
4406
4407 rv = (((uint64_t)bytes[0]) << 56) |
4408 (((uint64_t)bytes[1]) << 48) |
4409 (((uint64_t)bytes[2]) << 40) |
4410 (((uint64_t)bytes[3]) << 32) |
4411 (((uint64_t)bytes[4]) << 24) |
4412 (((uint64_t)bytes[5]) << 16) |
4413 (((uint64_t)bytes[6]) << 8) |
4414 bytes[7];
4415 return (rv);
4416 }
4417
4418 /*
4419 * Given the pointer to a returned mode sense buffer, return a pointer to
4420 * the start of the first mode page.
4421 */
4422 static __inline void *
find_mode_page_6(struct scsi_mode_header_6 * mode_header)4423 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
4424 {
4425 void *page_start;
4426
4427 page_start = (void *)((u_int8_t *)&mode_header[1] +
4428 mode_header->blk_desc_len);
4429
4430 return(page_start);
4431 }
4432
4433 static __inline void *
find_mode_page_10(struct scsi_mode_header_10 * mode_header)4434 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
4435 {
4436 void *page_start;
4437
4438 page_start = (void *)((u_int8_t *)&mode_header[1] +
4439 scsi_2btoul(mode_header->blk_desc_len));
4440
4441 return(page_start);
4442 }
4443
4444 __END_DECLS
4445
4446 #endif /*_SCSI_SCSI_ALL_H*/
4447