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