1 /* 2 * Copyright 2004-2015, Haiku, Inc. All RightsReserved. 3 * Copyright 2002/03, Thomas Kurschel. All rights reserved. 4 * 5 * Distributed under the terms of the MIT License. 6 */ 7 #ifndef _SCSI_CMDS_H 8 #define _SCSI_CMDS_H 9 10 11 //! SCSI commands and their data structures and constants 12 13 14 #include <lendian_bitfield.h> 15 16 17 // Always keep in mind that SCSI is big-endian! 18 19 #define SCSI_STD_TIMEOUT 10 20 21 // SCSI device status (as the result of a command) 22 #define SCSI_STATUS_GOOD (0 << 1) 23 #define SCSI_STATUS_CHECK_CONDITION (1 << 1) // error occured 24 #define SCSI_STATUS_CONDITION_MET (2 << 1) 25 // "found" for SEARCH DATA and PREFETCH 26 #define SCSI_STATUS_BUSY (4 << 1) 27 // try again later (??? == QUEUE_FULL ???) 28 #define SCSI_STATUS_INTERMEDIATE (8 << 1) 29 // used by linked command only 30 #define SCSI_STATUS_INTERMEDIATE_COND_MET (10 << 1) // ditto 31 #define SCSI_STATUS_RESERVATION_CONFLICT (12 << 1) 32 // only if RESERVE/RELEASE is used 33 #define SCSI_STATUS_COMMAND_TERMINATED (17 << 1) 34 // aborted by TERMINATE I/O PROCESS 35 #define SCSI_STATUS_QUEUE_FULL (20 << 1) // queue full 36 37 #define SCSI_STATUS_MASK 0xfe 38 39 // SCSI sense key 40 #define SCSIS_KEY_NO_SENSE 0 41 #define SCSIS_KEY_RECOVERED_ERROR 1 42 #define SCSIS_KEY_NOT_READY 2 43 // operator intervention may be required 44 #define SCSIS_KEY_MEDIUM_ERROR 3 45 // can be set if source could be hardware error 46 #define SCSIS_KEY_HARDWARE_ERROR 4 47 #define SCSIS_KEY_ILLEGAL_REQUEST 5 // invalid command 48 #define SCSIS_KEY_UNIT_ATTENTION 6 49 // medium changed or target reset 50 #define SCSIS_KEY_DATA_PROTECT 7 // data access forbidden 51 #define SCSIS_KEY_BLANK_CHECK 8 52 // tried to read blank or to write non-blank medium 53 #define SCSIS_KEY_VENDOR_SPECIFIC 9 54 #define SCSIS_KEY_COPY_ABORTED 10 55 // error in COPY or COMPARE command 56 #define SCSIS_KEY_ABORTED_COMMAND 11 57 // aborted by target, retry *may* help 58 #define SCSIS_KEY_EQUAL 12 // during SEARCH: data found 59 #define SCSIS_KEY_VOLUME_OVERFLOW 13 60 // tried to write buffered data beyond end of medium 61 #define SCSIS_KEY_MISCOMPARE 14 62 #define SCSIS_KEY_RESERVED 15 63 64 // SCSI ASC and ASCQ data - (ASC << 8) | ASCQ 65 // all codes with bit 7 of ASC or ASCQ set are vendor-specific 66 #define SCSIS_ASC_NO_SENSE 0x0000 67 #define SCSIS_ASC_IO_PROC_TERMINATED 0x0006 68 #define SCSIS_ASC_AUDIO_PLAYING 0x0011 69 #define SCSIS_ASC_AUDIO_PAUSED 0x0012 70 #define SCSIS_ASC_AUDIO_COMPLETED 0x0013 71 #define SCSIS_ASC_AUDIO_ERROR 0x0014 72 // playing has stopped due to error 73 #define SCSIS_ASC_AUDIO_NO_STATUS 0x0015 74 #define SCSIS_ASC_NO_INDEX 0x0100 // no index/sector signal 75 #define SCSIS_ASC_NO_SEEK_CMP 0x0200 // ??? 76 #define SCSIS_ASC_WRITE_FAULT 0x0300 77 #define SCSIS_ASC_LUN_NOT_READY 0x0400 78 // LUN not ready, cause not reportable 79 #define SCSIS_ASC_LUN_BECOMING_READY 0x0401 80 // LUN in progress of becoming ready 81 #define SCSIS_ASC_LUN_NEED_INIT 0x0402 82 // LUN need initializing command 83 #define SCSIS_ASC_LUN_NEED_MANUAL_HELP 0x0403 84 // LUN needs manual intervention 85 #define SCSIS_ASC_LUN_FORMATTING 0x0404 86 // LUN format in progress 87 #define SCSIS_ASC_LUN_SEL_FAILED 0x0500 88 // LUN doesn't respond to selection 89 #define SCSIS_ASC_LUN_COM_FAILURE 0x0800 // LUN communication failure 90 #define SCSIS_ASC_LUN_TIMEOUT 0x0801 91 // LUN communication time-out 92 #define SCSIS_ASC_LUN_COM_PARITY 0x0802 93 // LUN communication parity failure 94 #define SCSIS_ASC_LUN_COM_CRC 0x0803 95 // LUN communication CRC failure (SCSI-3) 96 #define SCSIS_ASC_WRITE_ERR_AUTOREALLOC 0x0c01 97 // recovered by auto-reallocation 98 #define SCSIS_ASC_WRITE_ERR_AUTOREALLOC_FAILED 0x0c02 99 #define SCSIS_ASC_ECC_ERROR 0x1000 100 #define SCSIS_ASC_UNREC_READ_ERR 0x1100 // unrecovered read error 101 #define SCSIS_ASC_READ_RETRIES_EXH 0x1101 // read retries exhausted 102 #define SCSIS_ASC_UNREC_READ_ERR_AUTOREALLOC_FAILED 0x1104 103 // above + auto-reallocate failed 104 #define SCSIS_ASC_RECORD_NOT_FOUND 0x1401 105 #define SCSIS_ASC_RANDOM_POS_ERROR 0x1500 // random positioning error 106 #define SCSIS_ASC_POSITIONING_ERR 0x1501 107 // mechanical positioning error 108 #define SCSIS_ASC_POS_ERR_ON_READ 0x1502 109 // positioning error detected by reading 110 #define SCSIS_ASC_DATA_RECOV_NO_ERR_CORR 0x1700 111 // recovered with no error correction applied 112 #define SCSIS_ASC_DATA_RECOV_WITH_RETRIES 0x1701 113 #define SCSIS_ASC_DATA_RECOV_POS_HEAD_OFS 0x1702 114 // ?recovered with positive head offset 115 #define SCSIS_ASC_DATA_RECOV_NEG_HEAD_OFS 0x1703 116 // ?recovered with negative head offset 117 #define SCSIS_ASC_DATA_RECOV_WITH_RETRIES_CIRC 0x1704 118 // recovered with retries/CIRC 119 #define SCSIS_ASC_DATA_RECOV_PREV_SECT_ID 0x1705 120 // recovered using previous sector ID 121 #define SCSIS_ASC_DATA_RECOV_NO_ECC_AUTOREALLOC 0x1706 122 #define SCSIS_ASC_DATA_RECOV_NO_ECC_REASSIGN 0x1707 // reassign recommended 123 #define SCSIS_ASC_DATA_RECOV_NO_ECC_REWRITE 0x1708 // rewrite recommended 124 #define SCSIS_ASC_DATA_RECOV_WITH_CORR 0x1800 125 // recovered using error correction 126 #define SCSIS_ASC_DATA_RECOV_WITH_CORR_RETRIES 0x1801 127 // used error correction and retries 128 #define SCSIS_ASC_DATA_RECOV_AUTOREALLOC 0x1802 129 #define SCSIS_ASC_DATA_RECOV_CIRC 0x1803 // recovered using CIRC 130 #define SCSIS_ASC_DATA_RECOV_LEC 0x1804 // recovered using LEC 131 #define SCSIS_ASC_DATA_RECOV_REASSIGN 0x1805 // reassign recommended 132 #define SCSIS_ASC_DATA_RECOV_REWRITE 0x1806 // rewrite recommended 133 #define SCSIS_ASC_PARAM_LIST_LENGTH_ERR 0x1a00 // parameter list too short 134 #define SCSIS_ASC_ID_RECOV 0x1e00 // recoved ID with ECC 135 #define SCSIS_ASC_INV_OPCODE 0x2000 136 #define SCSIS_ASC_LBA_OOR 0x2100 // LBA out of range 137 #define SCSIS_ASC_ILL_FUNCTION 0x2200 138 // better use 0x2000/0x2400/0x2600 instead 139 #define SCSIS_ASC_INV_CDB_FIELD 0x2400 140 #define SCSIS_ASC_LUN_NOT_SUPPORTED 0x2500 141 #define SCSIS_ASC_INV_PARAM_LIST_FIELD 0x2600 142 #define SCSIS_ASC_PARAM_NOT_SUPPORTED 0x2601 143 #define SCSIS_ASC_PARAM_VALUE_INV 0x2602 144 #define SCSIS_ASC_WRITE_PROTECTED 0x2700 145 #define SCSIS_ASC_MEDIUM_CHANGED 0x2800 146 #define SCSIS_ASC_WAS_RESET 0x2900 147 // reset by power-on/bus reset/device reset 148 #define SCSIS_ASC_PARAMS_CHANGED 0x2a00 149 #define SCSIS_ASC_CAPACITY_DATA_HAS_CHANGED 0x2a09 150 #define SCSIS_ASC_MEDIUM_FORMAT_CORRUPTED 0x3100 151 #define SCSIS_ASC_ROUNDED_PARAM 0x3700 // parameter got rounded 152 #define SCSIS_ASC_NO_MEDIUM 0x3a00 // medium not present 153 #define SCSIS_ASC_INTERNAL_FAILURE 0x4400 154 #define SCSIS_ASC_SEL_FAILURE 0x4500 // select/reselect failure 155 #define SCSIS_ASC_UNSUCC_SOFT_RESET 0x4600 // unsuccessful soft reset 156 #define SCSIS_ASC_SCSI_PARITY_ERR 0x4700 // SCSI parity error 157 #define SCSIS_ASC_LOAD_EJECT_FAILED 0x5300 158 // media load or eject failed 159 #define SCSIS_ASC_REMOVAL_PREVENTED 0x5302 // medium removal prevented 160 #define SCSIS_ASC_REMOVAL_REQUESTED 0x5a01 161 // operator requests medium removal 162 163 // some scsi op-codes 164 #define SCSI_OP_TEST_UNIT_READY 0x00 165 #define SCSI_OP_REQUEST_SENSE 0x03 166 #define SCSI_OP_FORMAT 0x04 167 #define SCSI_OP_READ_6 0x08 168 #define SCSI_OP_WRITE_6 0x0a 169 #define SCSI_OP_INQUIRY 0x12 170 #define SCSI_OP_VERIFY_6 0x13 171 #define SCSI_OP_MODE_SELECT_6 0x15 172 #define SCSI_OP_RESERVE 0x16 173 #define SCSI_OP_RELEASE 0x17 174 #define SCSI_OP_MODE_SENSE_6 0x1a 175 #define SCSI_OP_START_STOP 0x1b 176 #define SCSI_OP_RECEIVE_DIAGNOSTIC 0x1c 177 #define SCSI_OP_SEND_DIAGNOSTIC 0x1d 178 #define SCSI_OP_PREVENT_ALLOW 0x1e 179 #define SCSI_OP_READ_CAPACITY 0x25 180 #define SCSI_OP_READ_10 0x28 181 #define SCSI_OP_WRITE_10 0x2a 182 #define SCSI_OP_POSITION_TO_ELEMENT 0x2b 183 #define SCSI_OP_VERIFY_10 0x2f 184 #define SCSI_OP_SYNCHRONIZE_CACHE 0x35 185 #define SCSI_OP_WRITE_BUFFER 0x3b 186 #define SCSI_OP_READ_BUFFER 0x3c 187 #define SCSI_OP_CHANGE_DEFINITION 0x40 188 #define SCSI_OP_WRITE_SAME_10 0x41 189 #define SCSI_OP_UNMAP 0x42 190 #define SCSI_OP_READ_SUB_CHANNEL 0x42 191 #define SCSI_OP_READ_TOC 0x43 192 #define SCSI_OP_PLAY_MSF 0x47 193 #define SCSI_OP_PLAY_AUDIO_TRACK_INDEX 0x48 // obsolete, spec missing 194 #define SCSI_OP_PAUSE_RESUME 0x4b 195 #define SCSI_OP_STOP_PLAY 0x4e 196 #define SCSI_OP_MODE_SELECT_10 0x55 197 #define SCSI_OP_MODE_SENSE_10 0x5a 198 #define SCSI_OP_VARIABLE_LENGTH_CDB 0x7f 199 #define SCSI_OP_READ_16 0x88 200 #define SCSI_OP_WRITE_16 0x8a 201 #define SCSI_OP_VERIFY_16 0x8f 202 #define SCSI_OP_WRITE_SAME_16 0x93 203 #define SCSI_OP_SERVICE_ACTION_IN 0x9e 204 #define SCSI_OP_SERVICE_ACTION_OUT 0x9f 205 #define SCSI_OP_MOVE_MEDIUM 0xa5 206 #define SCSI_OP_READ_12 0xa8 207 #define SCSI_OP_WRITE_12 0xaa 208 #define SCSI_OP_VERIFY_12 0xaf 209 #define SCSI_OP_READ_ELEMENT_STATUS 0xb8 210 #define SCSI_OP_SCAN 0xba 211 #define SCSI_OP_READ_CD 0xbe 212 213 // Service-Action-In defines 214 #define SCSI_SAI_READ_CAPACITY_16 0x10 215 #define SCSI_SAI_READ_LONG 0x11 216 217 // Service-Action-Out defines 218 #define SCSI_SAO_WRITE_LONG 0x11 219 220 221 // INQUIRY 222 223 typedef struct scsi_cmd_inquiry { 224 uint8 opcode; 225 B_LBITFIELD8_3( 226 evpd : 1, // enhanced vital product data 227 _res1_1 : 4, 228 lun : 3 229 ); 230 uint8 page_code; 231 uint8 _res3; 232 uint8 allocation_length; 233 uint8 control; 234 } _PACKED scsi_cmd_inquiry; 235 236 typedef struct scsi_res_inquiry { 237 B_LBITFIELD8_2( 238 device_type : 5, 239 device_qualifier : 3 240 ); 241 B_LBITFIELD8_2( 242 device_type_modifier : 7, // obsolete, normally set to zero 243 removable_medium : 1 244 ); 245 B_LBITFIELD8_3( // 0 always means "not conforming" 246 ansi_version : 3, // 1 for SCSI-1, 2 for SCSI-2 etc. 247 ecma_version : 3, 248 iso_version : 2 249 ); 250 B_LBITFIELD8_4( 251 response_data_format : 4, // 2 = SCSI/2 compliant 252 _res3_4 : 2, 253 term_iop : 1, // 1 = supports TERMINATE I/O PROCESS 254 async_enc : 1 // processor devices only : 255 // Asynchronous Event Notification Capable 256 ); 257 uint8 additional_length; // total (whished) length = this + 4 258 uint8 _res5; 259 uint8 _res6; 260 B_LBITFIELD8_8( 261 soft_reset : 1, // 0 = soft reset leads to hard reset 262 cmd_queue : 1, // 1 = supports tagged command queuing 263 _res7_2 : 1, 264 linked : 1, // 1 = supports linked commands 265 sync : 1, // 1 = supports synchronous transfers 266 write_bus16 : 1, // 1 = supports 16 bit transfers 267 write_bus32 : 1, // 1 = supports 32 bit transfers 268 relative_address : 1 // 1 = supports relative addr. for linking 269 ); 270 char vendor_ident[8]; 271 char product_ident[16]; 272 char product_rev[4]; 273 274 // XPT doesn't return following data on XPT_GDEV_TYPE 275 uint8 vendor_spec[20]; 276 uint8 _res56[2]; 277 278 uint16 version_descriptor[8]; // array of supported standards, big endian 279 280 uint8 _res74[22]; 281 /* additional vendor specific data */ 282 } _PACKED scsi_res_inquiry; 283 284 enum scsi_peripheral_qualifier { 285 scsi_periph_qual_connected = 0, 286 scsi_periph_qual_not_connected = 2, 287 scsi_periph_qual_not_connectable = 3 288 // value 1 is reserved, values of 4 and above are vendor-specific 289 }; 290 291 enum scsi_device_type { 292 scsi_dev_direct_access = 0, 293 scsi_dev_sequential_access = 1, 294 scsi_dev_printer = 2, 295 scsi_dev_processor = 3, 296 scsi_dev_WORM = 4, 297 scsi_dev_CDROM = 5, 298 scsi_dev_scanner = 6, 299 scsi_dev_optical = 7, 300 scsi_dev_medium_changer = 8, 301 scsi_dev_communication = 9, 302 // 0xa - 0xb are graphics arts pre-press devices 303 // 0xc - 0x1e reserved 304 scsi_dev_storage_array = 0xc, 305 scsi_dev_enclosure_services = 0xd, 306 scsi_dev_simplified_direct_access = 0xe, 307 scsi_dev_optical_card = 0xf, 308 scsi_dev_unknown = 0x1f // used for scsi_periph_qual_not_connectable 309 }; 310 311 312 // vital product data: pages 313 #define SCSI_PAGE_SUPPORTED_VPD 0x00 /* Supported VPD Pages */ 314 #define SCSI_PAGE_USN 0x80 /* Unit serial number */ 315 #define SCSI_PAGE_BLOCK_LIMITS 0xb0 /* Block limits */ 316 #define SCSI_PAGE_BLOCK_DEVICE_CHARS 0xb1 /* Block device characteristics */ 317 #define SCSI_PAGE_LB_PROVISIONING 0xb2 /* Logical block provisioning */ 318 #define SCSI_PAGE_REFERRALS 0xb3 /* Referrals */ 319 320 // vital product data: supported pages 321 typedef struct scsi_page_list { 322 B_LBITFIELD8_2( 323 device_type : 5, 324 device_qualifier : 3 325 ); 326 uint8 page_code; 327 uint8 _res2; 328 329 uint8 page_length; 330 uint8 pages[1]; // size according to page_length 331 } _PACKED scsi_page_list; 332 333 // vital product data: unit serial number page 334 typedef struct scsi_page_usn { 335 B_LBITFIELD8_2( 336 device_type : 5, 337 device_qualifier : 3 338 ); 339 uint8 page_code; 340 uint8 _res2; 341 342 uint8 _page_length; // total size = this + 3 343 char psn[1]; // size according to page_length 344 } _PACKED scsi_page_usn; 345 346 typedef struct scsi_page_block_limits { 347 B_LBITFIELD8_2( 348 device_type : 5, 349 device_qualifier : 3 350 ); 351 uint8 page_code; 352 353 uint16 _page_length; 354 B_LBITFIELD8_2( 355 wsnz : 1, 356 _res4_1 : 7 357 ); 358 uint8 max_cmp_write_length; 359 uint16 opt_transfer_length_grain; 360 uint32 max_transfer_length; 361 uint32 opt_transfer_length; 362 uint32 max_prefetch_length; 363 uint32 max_unmap_lba_count; 364 uint32 max_unmap_blk_count; 365 uint32 opt_unmap_grain; 366 uint32 unmap_grain_align; 367 uint64 max_write_same_length; 368 uint8 _res44[20]; 369 } _PACKED scsi_page_block_limits; 370 371 typedef struct scsi_page_lb_provisioning { 372 B_LBITFIELD8_2( 373 device_type : 5, 374 device_qualifier : 3 375 ); 376 uint8 page_code; 377 378 uint16 page_length; 379 uint8 threshold_exponent; 380 B_LBITFIELD8_7( 381 dp : 1, 382 anc_sup : 1, 383 lbprz : 1, 384 _res5_3 : 2, 385 lbpws10 : 1, 386 lbpws : 1, 387 lbpu : 1 388 ); 389 B_LBITFIELD8_2( 390 provisioning_type : 3, 391 _res6_3 : 5 392 ); 393 uint8 _res7; 394 } _PACKED scsi_page_lb_provisioning; 395 396 397 // READ CAPACITY (10) 398 399 typedef struct scsi_cmd_read_capacity { 400 uint8 opcode; 401 B_LBITFIELD8_3( 402 relative_address : 1, // relative address 403 _res1_1 : 4, 404 lun : 3 405 ); 406 uint32 lba; 407 uint8 _res6[2]; 408 B_LBITFIELD8_2( 409 pmi : 1, // partial medium indicator 410 _res8_1 : 7 411 ); 412 uint8 control; 413 } _PACKED scsi_cmd_read_capacity; 414 415 typedef struct scsi_res_read_capacity { 416 uint32 lba; // big endian 417 uint32 block_size; // in bytes 418 } _PACKED scsi_res_read_capacity; 419 420 // READ CAPACITY (16) 421 422 typedef struct scsi_cmd_read_capacity_long { 423 uint8 opcode; 424 uint8 service_action; 425 uint64 lba; 426 uint32 alloc_length; 427 uint8 relative_address; 428 uint8 control; 429 } _PACKED scsi_cmd_read_capacity_long; 430 431 typedef struct scsi_res_read_capacity_long { 432 uint64 lba; // big endian 433 uint32 block_size; // in bytes 434 } _PACKED scsi_res_read_capacity_long; 435 436 437 // READ (6), WRITE (6) 438 439 typedef struct scsi_cmd_rw_6 { 440 uint8 opcode; 441 B_LBITFIELD8_2( 442 high_lba : 5, 443 lun : 3 444 ); 445 uint8 mid_lba; 446 uint8 low_lba; 447 uint8 length; // 0 = 256 blocks 448 uint8 control; 449 } _PACKED scsi_cmd_rw_6; 450 451 452 // READ (10), WRITE (10) 453 454 typedef struct scsi_cmd_rw_10 { 455 uint8 opcode; 456 B_LBITFIELD8_5( 457 relative_address : 1, // relative address 458 _res1_1 : 2, 459 force_unit_access : 1, // force unit access (1 = safe, cacheless access) 460 disable_page_out : 1, // disable page out (1 = not worth caching) 461 lun : 3 462 ); 463 uint32 lba; // big endian 464 uint8 _res6; 465 uint16 length; // 0 = no block 466 uint8 control; 467 } _PACKED scsi_cmd_rw_10; 468 469 470 // READ (12), WRITE (12) 471 472 typedef struct scsi_cmd_rw_12 { 473 uint8 opcode; 474 B_LBITFIELD8_5( 475 relative_address : 1, // relative address 476 _res1_1 : 2, 477 force_unit_access : 1, // force unit access (1 = safe, cacheless access) 478 disable_page_out : 1, // disable page out (1 = not worth caching) 479 lun : 3 480 ); 481 uint32 lba; // big endian 482 uint32 length; // 0 = no block 483 uint8 _res10; 484 uint8 control; 485 } _PACKED scsi_cmd_rw_12; 486 487 488 // READ (16), WRITE (16) 489 490 typedef struct scsi_cmd_rw_16 { 491 uint8 opcode; 492 B_LBITFIELD8_6( 493 _res1_0 : 1, 494 force_unit_access_non_volatile : 1, 495 _res1_2 : 1, 496 force_unit_access : 1, 497 disable_page_out : 1, 498 read_protect : 3 499 ); 500 uint64 lba; // big endian 501 uint32 length; 502 B_LBITFIELD8_3( 503 group_number : 5, 504 _res_14_5 : 2, 505 _res_14_7 : 1 506 ); 507 uint8 control; 508 } _PACKED scsi_cmd_rw_16; 509 510 511 // WRITE SAME (16) 512 513 typedef struct scsi_cmd_wsame_16 { 514 uint8 opcode; 515 B_LBITFIELD8_6( 516 _res1_0 : 1, 517 lb_data : 1, 518 pb_data : 1, 519 unmap : 1, 520 _res1_4 : 1, 521 write_protect : 3 522 ); 523 uint64 lba; 524 uint32 length; 525 B_LBITFIELD8_2( 526 group_number : 5, 527 _res14_5 : 3 528 ); 529 uint8 control; 530 } _PACKED scsi_cmd_wsame_16; 531 532 533 // UNMAP 534 535 typedef struct scsi_cmd_unmap { 536 uint8 opcode; 537 B_LBITFIELD8_2( 538 anchor : 1, 539 _reserved1_7 : 7 540 ); 541 uint32 _reserved1; 542 B_LBITFIELD8_2( 543 group_number : 5, 544 _reserved5_7 : 3 545 ); 546 uint16 length; 547 uint8 control; 548 } _PACKED scsi_cmd_unmap; 549 550 struct scsi_unmap_block_descriptor { 551 uint64 lba; 552 uint32 block_count; 553 uint32 _reserved1; 554 } _PACKED; 555 556 struct scsi_unmap_parameter_list { 557 uint16 data_length; 558 uint16 block_data_length; 559 uint32 _reserved1; 560 struct scsi_unmap_block_descriptor blocks[1]; 561 } _PACKED; 562 563 564 // REQUEST SENSE 565 566 typedef struct scsi_cmd_request_sense { 567 uint8 opcode; 568 B_LBITFIELD8_2( 569 _res1_0 : 5, 570 lun : 3 571 ); 572 uint8 _res2[2]; 573 uint8 allocation_length; 574 uint8 control; 575 } _PACKED scsi_cmd_request_sense; 576 577 578 // sense data structures 579 580 #define SCSIS_CURR_ERROR 0x70 581 #define SCSIS_DEFERRED_ERROR 0x71 582 583 typedef struct scsi_sense { 584 B_LBITFIELD8_2( 585 error_code : 7, 586 valid : 1 // 0 = not conforming to standard 587 ); 588 uint8 segment_number; // for COPY/COPY AND VERIFY/COMPARE 589 B_LBITFIELD8_5( 590 sense_key : 4, 591 res2_4 : 1, 592 ILI : 1, // incorrect length indicator - req. block 593 // length doesn't match physical block length 594 EOM : 1, // serial devices only 595 Filemark : 1 // optional for random access 596 ); 597 598 uint8 highest_inf; // device-type or command specific 599 uint8 high_inf; // device-type 0, 4, 5, 7: block address 600 uint8 mid_inf; // device-type 1, 2, 3: req length - act. length 601 uint8 low_inf; // (and others for sequential dev. and COPY cmds 602 603 uint8 add_sense_length; // total length = this + 7 604 605 uint8 highest_cmd_inf; 606 uint8 high_cmd_inf; 607 uint8 mid_cmd_inf; 608 uint8 low_cmd_inf; 609 uint8 asc; 610 uint8 ascq; // this can be zero if unsupported 611 uint8 unit_code; // != 0 to specify internal device unit 612 613 union { 614 struct { 615 B_LBITFIELD8_2( 616 high_key_spec : 7, 617 SKSV : 1 // 1 = sense key specific (byte 15-17) valid 618 ); 619 uint8 mid_key_spec; 620 uint8 low_key_spec; 621 } raw; 622 623 // ILLEGAL REQUEST 624 struct { 625 B_LBITFIELD8_5( 626 bit_pointer : 3, // points to (highest) invalid bit of parameter 627 BPV : 1, // 1 = bit_pointer is valid 628 res15_4 : 2, 629 c_d : 2, // 1 = error command, 0 = error in data 630 SKSV : 1 // s.a. 631 ); 632 uint8 high_field_pointer; // points to (highest) invalid byte of parameter 633 uint8 low_field_pointer; // (!using big endian, this means the first byte!) 634 } ill_request; 635 636 // access error (RECOVERED, HARDWARE or MEDIUM ERROR) 637 struct { 638 B_LBITFIELD8_2( 639 res15_0 : 7, 640 SKSV : 1 641 ); 642 uint8 high_retry_cnt; 643 uint8 low_retry_cnt; 644 } acc_error; 645 646 // format progress (if sense key = NOT READY) 647 struct { 648 B_LBITFIELD8_2( 649 res15_0 : 7, 650 SKSV : 1 651 ); 652 uint16 progress; // 0 = start, 0xffff = almost finished 653 } format_progress; 654 } sense_key_spec; 655 656 // starting with offset 18 there are additional sense byte 657 } _PACKED scsi_sense; 658 659 660 // PREVENT ALLOW 661 662 typedef struct scsi_cmd_prevent_allow { 663 uint8 opcode; 664 B_LBITFIELD8_2( 665 _res1_0 : 5, 666 lun : 3 667 ); 668 uint8 _res2[2]; 669 B_LBITFIELD8_2( 670 prevent : 1, // 1 - prevent medium removal, 0 - allow removal 671 _res4_1 : 7 672 ); 673 uint8 control; 674 } _PACKED scsi_cmd_prevent_allow; 675 676 // START STOP UNIT 677 678 typedef struct scsi_cmd_ssu { 679 uint8 opcode; 680 B_LBITFIELD8_3( 681 immediately : 1, // 1 - return immediately, 0 - return on completion 682 _res1_1 : 4, 683 lun : 3 684 ); 685 uint8 res2[2]; 686 B_LBITFIELD8_3( 687 start : 1, // 1 - load+start, i.e. allow, 0 - eject+stop, i.e. deny 688 load_eject : 1, // 1 - include loading/ejecting, 0 - only to allow/deny 689 _res4_2 : 6 690 ); 691 uint8 control; 692 } _PACKED scsi_cmd_ssu; 693 694 695 // MODE SELECT (6) 696 697 typedef struct scsi_cmd_mode_select_6 { 698 uint8 opcode; 699 B_LBITFIELD8_4( 700 save_pages : 1, // 1 = save pages to non-volatile memory 701 _res1_1 : 3, 702 pf : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format 703 lun : 3 704 ); 705 uint8 _res2[2]; 706 uint8 param_list_length; // data size 707 uint8 control; 708 } _PACKED scsi_cmd_mode_select_6; 709 710 711 // MODE SENSE (6) 712 713 typedef struct scsi_cmd_mode_sense_6 { 714 uint8 opcode; 715 B_LBITFIELD8_4( 716 _res1_0 : 3, 717 disable_block_desc : 1, // disable block descriptors 718 _res1_4 : 1, 719 lun : 3 720 ); 721 B_LBITFIELD8_2( 722 page_code : 6, 723 page_control : 2 // page control field 724 ); 725 uint8 _res3; 726 uint8 allocation_length; // maximum amount of data 727 uint8 control; 728 } _PACKED scsi_cmd_mode_sense_6; 729 730 731 // MODE SELECT (10) 732 733 typedef struct scsi_cmd_mode_select_10 { 734 uint8 opcode; 735 B_LBITFIELD8_4( 736 save_pages : 1, // 1 = save pages to non-volatile memory 737 _res1_1 : 3, 738 pf : 1, // 0 = old SCSI-1; 1 = new SCSI-2 format 739 lun : 3 740 ); 741 uint8 _res2[5]; 742 uint16 param_list_length; // data size, big endian 743 uint8 control; 744 } _PACKED scsi_cmd_mode_select_10; 745 746 747 // MODE SENSE (10) 748 749 typedef struct scsi_cmd_mode_sense_10 { 750 uint8 opcode; 751 B_LBITFIELD8_4( 752 _res1_0 : 3, 753 disable_block_desc : 1, // disable block descriptors 754 _res1_4 : 1, 755 lun : 3 756 ); 757 B_LBITFIELD8_2( 758 page_code : 6, 759 page_control : 2 // page control field 760 ); 761 uint8 _res3[4]; 762 uint16 allocation_length; // maximum amount of data, big endian 763 uint8 control; 764 } _PACKED scsi_cmd_mode_sense_10; 765 766 // possible contents of page control (PC) 767 #define SCSI_MODE_SENSE_PC_CURRENT 0 768 #define SCSI_MODE_SENSE_PC_CHANGABLE 1 769 // changable field are filled with "1" 770 #define SCSI_MODE_SENSE_PC_DEFAULT 2 771 #define SCSI_MODE_SENSE_PC_SAVED 3 772 773 // special mode page indicating to return all mode pages 774 #define SCSI_MODEPAGE_ALL 0x3f 775 776 // header of mode data; followed by block descriptors and mode pages 777 typedef struct scsi_mode_param_header_6 { 778 uint8 mode_data_length; // total length excluding this byte 779 uint8 medium_type; 780 uint8 dev_spec_parameter; 781 uint8 block_desc_length; // total length of all transmitted block descriptors 782 } _PACKED scsi_mode_param_header_6; 783 784 typedef struct scsi_mode_param_header_10 { 785 uint16 mode_data_length; // total length excluding these two bytes 786 uint8 medium_type; 787 uint8 dev_spec_parameter; 788 uint8 _res4[2]; 789 uint16 block_desc_length; // total length of all transmitted block descriptors 790 } _PACKED scsi_mode_param_header_10; 791 792 793 // content of dev_spec_parameter for direct access devices 794 typedef struct scsi_mode_param_dev_spec_da { 795 B_LBITFIELD8_4( 796 _res0_0 : 4, 797 dpo_fua : 1, // 1 = supports DPO and FUA, see READ (10) (sense only) 798 _res0_6 : 1, 799 write_protected : 1 // write protected (sense only) 800 ); 801 } _PACKED scsi_mode_param_dev_spec_da; 802 803 typedef struct scsi_mode_param_block_desc { 804 uint8 density; // density code of area 805 uint8 high_numblocks; // size of this area in blocks 806 uint8 med_numblocks; // 0 = all remaining blocks 807 uint8 low_numblocks; 808 uint8 _res4; 809 uint8 high_blocklen; // block size 810 uint8 med_blocklen; 811 uint8 low_blocklen; 812 } _PACKED scsi_mode_param_block_desc; 813 814 815 // header of a mode pages 816 typedef struct scsi_modepage_header { 817 B_LBITFIELD8_3( 818 page_code : 6, 819 _res0_6 : 1, 820 PS : 1 // 1 = page can be saved (only valid for MODE SENSE) 821 ); 822 uint8 page_length; // size of page excluding this common header 823 } _PACKED scsi_modepage_header; 824 825 826 // control mode page 827 #define SCSI_MODEPAGE_CONTROL 0xa 828 829 typedef struct scsi_modepage_control { 830 scsi_modepage_header header; 831 B_LBITFIELD8_2( 832 RLEC : 1, // Report Log Exception Condition 833 res2_1 : 7 834 ); 835 B_LBITFIELD8_4( 836 DQue : 1, // disable Queuing 837 QErr : 1, // abort queued commands on contingent allegiance condition 838 res3_2 : 2, 839 QAM : 4 // Queue Algorithm Modifier 840 ); 841 B_LBITFIELD8_5( 842 EAENP : 1, // error AEN permission; true = send AEN on deferred error 843 // false = generate UA condition after deferred error 844 UAAENP : 1, // unit attention AEN permission; true = send AEN, 845 // false = generate UA condition (for everything but init.) 846 RAENP : 1, // ready AEN permission; true = send async event notification 847 // (AEN) instead of generating an Unit Attention (UA) Condition 848 // after initialization 849 res4_3 : 4, 850 EECA : 1 // enable Extended Contingent Allegiance 851 ); 852 uint8 res5; 853 uint8 high_AEN_holdoff; // ready AEN hold off period - delay in ms between 854 uint8 low_AEN_holdoff; // initialization and AEN 855 } scsi_modepage_control; 856 857 // values for QAM 858 #define SCSI_QAM_RESTRICTED 0 859 #define SCSI_QAM_UNRESTRICTED 1 860 // 2 - 7 reserved, 8 - 0xf vendor-specific 861 862 863 // CD audio control page 864 #define SCSI_MODEPAGE_AUDIO 0xe 865 866 typedef struct scsi_modepage_audio { 867 scsi_modepage_header header; 868 B_LBITFIELD8_4( 869 _res2_0 : 1, 870 stop_on_track_crossing : 1, // Stop On Track Crossing 871 // 0 - stop according transfer length, 1 - stop at end of track 872 immediately : 1, // must be one 873 _res2_3 : 5 874 ); 875 uint8 _res3[3]; 876 uint8 _obsolete6[2]; 877 struct { 878 B_LBITFIELD8_2( 879 channel : 4, // select channel to connect to this port 880 _res0_4 : 4 881 ); 882 uint8 volume; 883 } ports[4]; 884 } _PACKED scsi_modepage_audio; 885 886 // connection between output port and audio channel 887 #define SCSI_CHANNEL_SEL_MUTED 0 // mute port 888 #define SCSI_CHANNEL_SEL_CHANNEL0 1 // connect to channel 0 889 #define SCSI_CHANNEL_SEL_CHANNEL1 2 // connect to channel 1 890 #define SCSI_CHANNEL_SEL_CHANNEL0_1 3 // connect to channel 0 and channel 1 891 #define SCSI_CHANNEL_SEL_CHANNEL2 4 // connect to channel 2 892 #define SCSI_CHANNEL_SEL_CHANNEL3 8 // connect to channel 3 893 894 // TUR 895 896 typedef struct scsi_cmd_tur { 897 uint8 opcode; 898 B_LBITFIELD8_2( 899 _res1_0 : 5, 900 lun : 3 901 ); 902 uint8 _res3[3]; 903 uint8 control; 904 } _PACKED scsi_cmd_tur; 905 906 907 // READ_TOC 908 909 typedef struct scsi_cmd_read_toc { 910 uint8 opcode; 911 B_LBITFIELD8_4( 912 _res1_0 : 1, 913 time : 1, // true, to use MSF format, false for LBA format 914 _res1_2 : 3, 915 lun : 3 916 ); 917 B_LBITFIELD8_2( 918 format : 4, // see below 919 _res2_4 : 4 920 ); 921 uint8 _res3[3]; 922 uint8 track; // (starting) track 923 uint16 allocation_length; // maximum amount of data (big endian) 924 uint8 control; 925 } _PACKED scsi_cmd_read_toc; 926 927 // values of <format> in TOC command 928 #define SCSI_TOC_FORMAT_TOC 0 // all TOCs starting with <track> (0xaa for lead-out) 929 #define SCSI_TOC_FORMAT_SESSION_INFO 1 // Session info 930 #define SCSI_TOC_FORMAT_FULL_TOC 2 // all Q-channel data in TOC 931 #define SCSI_TOC_FORMAT_PMA 3 // Q-channel data in PMA area 932 #define SCSI_TOC_FORMAT_ATIP 4 // get ATIP data 933 #define SCSI_TOC_FORMAT_CD_TEXT 5 // get CD-Text from R/W-channel in lead-in 934 935 // general structure of response 936 typedef struct scsi_toc_general { 937 uint16 data_length; // big endian, total length - 2 938 uint8 first; // first track/session/reserved 939 uint8 last; // last one 940 // remainder are parameter list descriptors 941 } _PACKED scsi_toc_general; 942 943 // definition of CD-ROM LBA 944 typedef uint32 scsi_cd_lba; // big endian 945 946 // definition of CD-ROM MSF time 947 typedef struct scsi_cd_msf { 948 uint8 _reserved; 949 uint8 minute; 950 uint8 second; 951 uint8 frame; 952 } _PACKED scsi_cd_msf; 953 954 // definition of Track Number address format 955 typedef struct scsi_cd_track_number { 956 uint8 _res0[3]; 957 uint8 track; 958 } _PACKED scsi_cd_track_number; 959 960 // one track for SCSI_TOC_FORMAT_TOC 961 typedef struct scsi_toc_track { 962 uint8 _res0; 963 B_LBITFIELD8_2( 964 control : 4, 965 adr : 4 966 ); 967 uint8 track_number; // track number (hex) 968 uint8 _res3; 969 union { // start of track (time or LBA, see TIME of command) 970 scsi_cd_lba lba; 971 scsi_cd_msf time; 972 } start; 973 } _PACKED scsi_toc_track; 974 975 // possible value of ADR-field (described Q-channel content) 976 enum scsi_adr { 977 scsi_adr_none = 0, // no Q-channel mode info 978 scsi_adr_position = 1, // Q-channel encodes current position data 979 scsi_adr_mcn = 2, // Q-channel encodes Media Catalog Number 980 scsi_adr_isrc = 3 // Q-channel encodes ISRC 981 }; 982 983 // value of Q-channel control field (CONTROL) 984 enum scsi_q_control { 985 scsi_q_control_2audio = 0, // stereo audio 986 scsi_q_control_2audio_preemp = 1, // stereo audio with 50/15µs pre-emphasis 987 scsi_q_control_1audio = 8, // audio (reserved in CD-R/W) 988 scsi_q_control_1audio_preemp = 9, // audio with pre-emphasis (reserved in CD-R/W) 989 scsi_q_control_data_un_intr = 4, // data, recorded un-interrupted 990 scsi_q_control_data_incr = 5, // data, recorded incremental 991 scsi_q_control_ddcd = 4, // DDCD data 992 scsi_q_control_copy_perm = 2 // copy permitted (or-ed with value above) 993 }; 994 995 // format SCSI_TOC_FORMAT_TOC 996 typedef struct scsi_toc_toc { 997 uint16 data_length; // big endian, total length - 2 998 uint8 first_track; // first track 999 uint8 last_track; // last track 1000 1001 scsi_toc_track tracks[1]; // one entry per track 1002 } _PACKED scsi_toc_toc; 1003 1004 1005 // READ SUB-CHANNEL 1006 1007 typedef struct scsi_cmd_read_subchannel { 1008 uint8 opcode; 1009 B_LBITFIELD8_4( 1010 _res1_0 : 1, 1011 time : 1, // true, to use MSF format, false for LBA format 1012 _res1_2 : 3, 1013 lun : 3 1014 ); 1015 B_LBITFIELD8_3( 1016 _res2_0 : 6, 1017 subq : 1, // 1 - return Q sub-channel data 1018 _res2_7 : 1 1019 ); 1020 uint8 parameter_list; // see below 1021 uint8 _res4[2]; 1022 uint8 track; // track number (hex) 1023 uint16 allocation_length; // maximum amount of data, big endian 1024 uint8 control; 1025 } _PACKED scsi_cmd_read_subchannel; 1026 1027 // values of parameter_list 1028 enum scsi_sub_channel_parameter_list { 1029 scsi_sub_channel_parameter_list_cd_pos = 1, // CD current position 1030 scsi_sub_channel_parameter_list_mcn = 2, // Media Catalog Number 1031 scsi_sub_channel_parameter_list_isrc = 3 // Track International Standard Recording Code 1032 }; 1033 1034 // header of response 1035 typedef struct scsi_subchannel_data_header { 1036 uint8 _res0; 1037 uint8 audio_status; // see below 1038 uint16 data_length; // total length - 4, big endian 1039 } _PACKED scsi_subchannel_data_header; 1040 1041 // possible audio_status 1042 enum scsi_audio_status { 1043 scsi_audio_status_not_supported = 0, 1044 scsi_audio_status_playing = 0x11, 1045 scsi_audio_status_paused = 0x12, 1046 scsi_audio_status_completed = 0x13, 1047 scsi_audio_status_error_stop = 0x14, 1048 scsi_audio_status_no_status = 0x15 1049 }; 1050 1051 typedef struct scsi_cd_current_position { 1052 uint8 format_code; // always 1 1053 B_LBITFIELD8_2( 1054 control : 4, // see scsi_q_control 1055 adr : 4 // see scsi_adr 1056 ); 1057 uint8 track; 1058 uint8 index; 1059 union { // current position, relative to logical beginning 1060 scsi_cd_lba lba; 1061 scsi_cd_msf time; 1062 } absolute_address; 1063 union { // current position, relative to track 1064 scsi_cd_lba lba; 1065 scsi_cd_msf time; 1066 } track_relative_address; 1067 } _PACKED scsi_cd_current_position; 1068 1069 1070 // PLAY AUDIO MSF 1071 1072 typedef struct scsi_cmd_play_msf { 1073 uint8 opcode; 1074 B_LBITFIELD8_2( 1075 _res1_0 : 5, 1076 lun : 3 1077 ); 1078 uint8 _res2; 1079 uint8 start_minute; // start time 1080 uint8 start_second; 1081 uint8 start_frame; 1082 uint8 end_minute; // end time (excluding) 1083 uint8 end_second; 1084 uint8 end_frame; 1085 uint8 control; 1086 } _PACKED scsi_cmd_play_msf; 1087 1088 1089 // STOP AUDIO 1090 1091 typedef struct scsi_cmd_stop_play { 1092 uint8 opcode; 1093 B_LBITFIELD8_2( 1094 _res1_0 : 5, 1095 lun : 3 1096 ); 1097 uint8 _res2[7]; 1098 uint8 control; 1099 } _PACKED scsi_cmd_stop_play; 1100 1101 1102 // PAUSE/RESUME 1103 1104 typedef struct scsi_cmd_pause_resume { 1105 uint8 opcode; 1106 B_LBITFIELD8_2( 1107 _res1_0 : 5, 1108 lun : 3 1109 ); 1110 uint8 _res2[6]; 1111 B_LBITFIELD8_2( 1112 resume : 1, // 1 for resume, 0 for pause 1113 _res8_2 : 7 1114 ); 1115 uint8 control; 1116 } _PACKED scsi_cmd_pause_resume; 1117 1118 1119 // SCAN 1120 1121 typedef struct scsi_cmd_scan { 1122 uint8 opcode; 1123 B_LBITFIELD8_4( 1124 relative_address : 1, // must be zero 1125 _res1_1 : 3, 1126 direct : 1, // direction: 0 forward, 1 backward 1127 lun : 3 1128 ); 1129 union { // start of track (depends on <type>) 1130 scsi_cd_lba lba; 1131 scsi_cd_msf time; 1132 scsi_cd_track_number track_number; 1133 } start; 1134 uint8 _res6[3]; 1135 B_LBITFIELD8_2( 1136 res9_0 : 6, 1137 type : 2 // actual type of <start> (see below) 1138 ); 1139 uint8 _res10; 1140 uint8 control; 1141 } _PACKED scsi_cmd_scan; 1142 1143 // possible values for type 1144 enum scsi_scan_type { 1145 scsi_scan_lba = 0, 1146 scsi_scan_msf = 1, 1147 scsi_scan_tno = 2 1148 }; 1149 1150 1151 // READ_CD 1152 1153 typedef struct scsi_cmd_read_cd { 1154 uint8 opcode; 1155 B_LBITFIELD8_4( 1156 relative_address : 1, // must be zero 1157 _res1_1 : 1, 1158 sector_type : 3, // required sector type (1=CDDA) 1159 lun : 3 1160 ); 1161 scsi_cd_lba lba; 1162 uint8 high_length; 1163 uint8 mid_length; 1164 uint8 low_length; 1165 B_LBITFIELD8_6( 1166 _res9_0 : 1, 1167 error_field : 2, 1168 edc_ecc : 1, // include EDC/ECC; includes 8 byte padding for Mode 1 format 1169 user_data : 1, // if 1, include user data 1170 // (mode select block size is ignored) 1171 header_code : 2, 1172 sync : 1 // if 1, include sync field from sector 1173 ); 1174 B_LBITFIELD8_2( 1175 sub_channel_selection : 4, 1176 _res10_4 : 4 1177 ); 1178 uint8 control; 1179 } _PACKED scsi_cmd_read_cd; 1180 1181 // possible values for header_code 1182 enum scsi_read_cd_header_code { 1183 scsi_read_cd_header_none = 0, 1184 scsi_read_cd_header_hdr_only = 1, 1185 scsi_read_cd_header_sub_header_only = 2, 1186 scsi_read_cd_header_all_headers = 3, 1187 }; 1188 1189 // possible values for error_field 1190 enum scsi_read_cd_error_field { 1191 scsi_read_cd_error_none = 0, 1192 scsi_read_cd_error_c2_error = 1, // include 2352 bits indicating error in byte 1193 scsi_read_cd_error_c2_and_block_error = 2, // include or of C2 data plus pad byte 1194 }; 1195 1196 // possible values for sub_channel_selection 1197 enum scsi_read_cd_sub_channel_selection { 1198 scsi_read_cd_sub_channel_none = 0, 1199 scsi_read_cd_sub_channel_RAW = 1, 1200 scsi_read_cd_sub_channel_Q = 2, 1201 scsi_read_cd_sub_channel_P_W = 4 // R/W data, depending on CD capabilities 1202 // and Mechanism status page 1203 }; 1204 1205 // SYNCHRONIZE CACHE (10) 1206 1207 typedef struct scsi_cmd_sync_cache { 1208 uint8 opcode; 1209 B_LBITFIELD8_4( 1210 relative_address : 1, // must be zero 1211 immediately : 1, // 1 - return immediately, 0 - return on completion 1212 _res1_1 : 3, 1213 lun : 3 1214 ); 1215 scsi_cd_lba lba; 1216 uint8 _res2; 1217 uint16 block_count; // big endian 1218 uint8 control; 1219 } _PACKED scsi_cmd_sync_cache; 1220 1221 1222 #endif /* _SCSI_CMDS_H */ 1223