1 /* 2 * Structures and definitions for SCSI commands to Direct Access Devices 3 */ 4 5 /*- 6 * Some lines of this file come from a file of the name "scsi.h" 7 * distributed by OSF as part of mach2.5, 8 * so the following disclaimer has been kept. 9 * 10 * Copyright 1990 by Open Software Foundation, 11 * Grenoble, FRANCE 12 * 13 * All Rights Reserved 14 * 15 * Permission to use, copy, modify, and distribute this software and 16 * its documentation for any purpose and without fee is hereby granted, 17 * provided that the above copyright notice appears in all copies and 18 * that both the copyright notice and this permission notice appear in 19 * supporting documentation, and that the name of OSF or Open Software 20 * Foundation not be used in advertising or publicity pertaining to 21 * distribution of the software without specific, written prior 22 * permission. 23 * 24 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 25 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 26 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 27 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 28 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 29 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 30 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 */ 32 33 /*- 34 * Largely written by Julian Elischer (julian@tfs.com) 35 * for TRW Financial Systems. 36 * 37 * TRW Financial Systems, in accordance with their agreement with Carnegie 38 * Mellon University, makes this software available to CMU to distribute 39 * or use in any manner that they see fit as long as this message is kept with 40 * the software. For this reason TFS also grants any other persons or 41 * organisations permission to use or modify this software. 42 * 43 * TFS supplies this software to be publicly redistributed 44 * on the understanding that TFS is not responsible for the correct 45 * functioning of this software in any circumstances. 46 * 47 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 48 * 49 * $FreeBSD$ 50 */ 51 52 #ifndef _SCSI_SCSI_DA_H 53 #define _SCSI_SCSI_DA_H 1 54 55 #include <sys/cdefs.h> 56 57 struct scsi_rezero_unit 58 { 59 u_int8_t opcode; 60 #define SRZU_LUN_MASK 0xE0 61 u_int8_t byte2; 62 u_int8_t reserved[3]; 63 u_int8_t control; 64 }; 65 66 /* 67 * NOTE: The lower three bits of byte2 of the format CDB are the same as 68 * the lower three bits of byte2 of the read defect data CDB, below. 69 */ 70 struct scsi_format_unit 71 { 72 u_int8_t opcode; 73 u_int8_t byte2; 74 #define FU_FORMAT_MASK SRDD10_DLIST_FORMAT_MASK 75 #define FU_BLOCK_FORMAT SRDD10_BLOCK_FORMAT 76 #define FU_BFI_FORMAT SRDD10_BYTES_FROM_INDEX_FORMAT 77 #define FU_PHYS_FORMAT SRDD10_PHYSICAL_SECTOR_FORMAT 78 #define FU_CMPLST 0x08 79 #define FU_FMT_DATA 0x10 80 u_int8_t vendor_specific; 81 u_int8_t interleave[2]; 82 u_int8_t control; 83 }; 84 85 struct scsi_reassign_blocks 86 { 87 u_int8_t opcode; 88 u_int8_t byte2; 89 u_int8_t unused[3]; 90 u_int8_t control; 91 }; 92 93 struct scsi_read_defect_data_10 94 { 95 uint8_t opcode; 96 uint8_t byte2; 97 #define SRDD10_GLIST 0x08 98 #define SRDD10_PLIST 0x10 99 #define SRDD10_DLIST_FORMAT_MASK 0x07 100 #define SRDD10_BLOCK_FORMAT 0x00 101 #define SRDD10_BYTES_FROM_INDEX_FORMAT 0x04 102 #define SRDD10_PHYSICAL_SECTOR_FORMAT 0x05 103 uint8_t format; 104 uint8_t reserved[4]; 105 uint8_t alloc_length[2]; 106 #define SRDD10_MAX_LENGTH 0xffff 107 uint8_t control; 108 }; 109 110 struct scsi_sanitize 111 { 112 u_int8_t opcode; 113 u_int8_t byte2; 114 #define SSZ_SERVICE_ACTION_OVERWRITE 0x01 115 #define SSZ_SERVICE_ACTION_BLOCK_ERASE 0x02 116 #define SSZ_SERVICE_ACTION_CRYPTO_ERASE 0x03 117 #define SSZ_SERVICE_ACTION_EXIT_MODE_FAILURE 0x1F 118 #define SSZ_UNRESTRICTED_EXIT 0x20 119 #define SSZ_IMMED 0x80 120 u_int8_t reserved[5]; 121 u_int8_t length[2]; 122 u_int8_t control; 123 }; 124 125 struct scsi_sanitize_parameter_list 126 { 127 u_int8_t byte1; 128 #define SSZPL_INVERT 0x80 129 u_int8_t reserved; 130 u_int8_t length[2]; 131 /* Variable length initialization pattern. */ 132 #define SSZPL_MAX_PATTERN_LENGTH 65535 133 }; 134 135 struct scsi_read_defect_data_12 136 { 137 uint8_t opcode; 138 #define SRDD12_GLIST 0x08 139 #define SRDD12_PLIST 0x10 140 #define SRDD12_DLIST_FORMAT_MASK 0x07 141 #define SRDD12_BLOCK_FORMAT 0x00 142 #define SRDD12_BYTES_FROM_INDEX_FORMAT 0x04 143 #define SRDD12_PHYSICAL_SECTOR_FORMAT 0x05 144 uint8_t format; 145 uint8_t address_descriptor_index[4]; 146 uint8_t alloc_length[4]; 147 uint8_t reserved; 148 uint8_t control; 149 }; 150 151 152 /* 153 * Opcodes 154 */ 155 #define REZERO_UNIT 0x01 156 #define FORMAT_UNIT 0x04 157 #define REASSIGN_BLOCKS 0x07 158 #define MODE_SELECT 0x15 159 #define MODE_SENSE 0x1a 160 #define READ_FORMAT_CAPACITIES 0x23 161 #define WRITE_AND_VERIFY 0x2e 162 #define VERIFY 0x2f 163 #define READ_DEFECT_DATA_10 0x37 164 #define SANITIZE 0x48 165 #define READ_DEFECT_DATA_12 0xb7 166 167 struct format_defect_list_header 168 { 169 u_int8_t reserved; 170 u_int8_t byte2; 171 #define FU_DLH_VS 0x01 172 #define FU_DLH_IMMED 0x02 173 #define FU_DLH_DSP 0x04 174 #define FU_DLH_IP 0x08 175 #define FU_DLH_STPF 0x10 176 #define FU_DLH_DCRT 0x20 177 #define FU_DLH_DPRY 0x40 178 #define FU_DLH_FOV 0x80 179 u_int8_t defect_list_length[2]; 180 }; 181 182 struct format_ipat_descriptor 183 { 184 u_int8_t byte1; 185 #define FU_INIT_NO_HDR 0x00 186 #define FU_INIT_LBA_MSB 0x40 187 #define FU_INIT_LBA_EACH 0x80 188 #define FU_INIT_SI 0x20 189 u_int8_t pattern_type; 190 #define FU_INIT_PAT_DEFAULT 0x00 191 #define FU_INIT_PAT_REPEAT 0x01 192 u_int8_t pat_length[2]; 193 }; 194 195 struct scsi_read_format_capacities 196 { 197 uint8_t opcode; /* READ_FORMAT_CAPACITIES */ 198 uint8_t byte2; 199 #define SRFC_LUN_MASK 0xE0 200 uint8_t reserved0[5]; 201 uint8_t alloc_length[2]; 202 uint8_t reserved1[3]; 203 }; 204 205 struct scsi_verify_10 206 { 207 uint8_t opcode; /* VERIFY(10) */ 208 uint8_t byte2; 209 #define SVFY_LUN_MASK 0xE0 210 #define SVFY_RELADR 0x01 211 #define SVFY_BYTCHK 0x02 212 #define SVFY_DPO 0x10 213 uint8_t addr[4]; /* LBA to begin verification at */ 214 uint8_t group; 215 uint8_t length[2]; /* number of blocks to verify */ 216 uint8_t control; 217 }; 218 219 struct scsi_verify_12 220 { 221 uint8_t opcode; /* VERIFY(12) */ 222 uint8_t byte2; 223 uint8_t addr[4]; /* LBA to begin verification at */ 224 uint8_t length[4]; /* number of blocks to verify */ 225 uint8_t group; 226 uint8_t control; 227 }; 228 229 struct scsi_verify_16 230 { 231 uint8_t opcode; /* VERIFY(16) */ 232 uint8_t byte2; 233 uint8_t addr[8]; /* LBA to begin verification at */ 234 uint8_t length[4]; /* number of blocks to verify */ 235 uint8_t group; 236 uint8_t control; 237 }; 238 239 struct scsi_compare_and_write 240 { 241 uint8_t opcode; /* COMPARE AND WRITE */ 242 uint8_t byte2; 243 uint8_t addr[8]; /* LBA to begin verification at */ 244 uint8_t reserved[3]; 245 uint8_t length; /* number of blocks */ 246 uint8_t group; 247 uint8_t control; 248 }; 249 250 struct scsi_write_and_verify 251 { 252 uint8_t opcode; /* WRITE_AND_VERIFY */ 253 uint8_t byte2; 254 #define SWVY_LUN_MASK 0xE0 255 #define SWVY_RELADR 0x01 256 #define SWVY_BYTECHK 0x02 257 #define SWVY_DPO 0x10 258 uint8_t addr[4]; /* LBA to begin verification at */ 259 uint8_t reserved0[1]; 260 uint8_t len[2]; /* number of blocks to write and verify */ 261 uint8_t reserved1[3]; 262 }; 263 264 /* 265 * Replies to READ_FORMAT_CAPACITIES look like this: 266 * 267 * struct format_capacity_list_header 268 * struct format_capacity_descriptor[1..n] 269 * 270 * These are similar, but not totally identical to, the 271 * defect list used to format a rigid disk. 272 * 273 * The appropriate csio_decode() format string looks like this: 274 * "{} *i3 {Len} i1 {Blocks} i4 {} *b6 {Code} b2 {Blocklen} i3" 275 * 276 * If the capacity_list_length is greater than 277 * sizeof(struct format_capacity_descriptor), then there are 278 * additional format capacity descriptors available which 279 * denote which format(s) the drive can handle. 280 * 281 * (Source: USB Mass Storage UFI Specification) 282 */ 283 284 struct format_capacity_list_header { 285 uint8_t unused[3]; 286 uint8_t capacity_list_length; 287 }; 288 289 struct format_capacity_descriptor { 290 uint8_t nblocks[4]; /* total number of LBAs */ 291 uint8_t byte4; /* only present in max/cur descriptor */ 292 #define FCD_CODE_MASK 0x03 /* mask for code field above */ 293 #define FCD_UNFORMATTED 0x01 /* unformatted media present, 294 * maximum capacity returned */ 295 #define FCD_FORMATTED 0x02 /* formatted media present, 296 * current capacity returned */ 297 #define FCD_NOMEDIA 0x03 /* no media present, 298 * maximum device capacity returned */ 299 uint8_t block_length[3]; /* length of an LBA in bytes */ 300 }; 301 302 struct scsi_reassign_blocks_data 303 { 304 u_int8_t reserved[2]; 305 u_int8_t length[2]; 306 struct { 307 u_int8_t dlbaddr[4]; /* defect logical block address */ 308 } defect_descriptor[1]; 309 }; 310 311 312 /* 313 * This is the list header for the READ DEFECT DATA(10) command above. 314 * It may be a bit wrong to append the 10 at the end of the data structure, 315 * since it's only 4 bytes but it does tie it to the 10 byte command. 316 */ 317 struct scsi_read_defect_data_hdr_10 318 { 319 u_int8_t reserved; 320 #define SRDDH10_GLIST 0x08 321 #define SRDDH10_PLIST 0x10 322 #define SRDDH10_DLIST_FORMAT_MASK 0x07 323 #define SRDDH10_BLOCK_FORMAT 0x00 324 #define SRDDH10_BYTES_FROM_INDEX_FORMAT 0x04 325 #define SRDDH10_PHYSICAL_SECTOR_FORMAT 0x05 326 u_int8_t format; 327 u_int8_t length[2]; 328 }; 329 330 struct scsi_defect_desc_block 331 { 332 u_int8_t address[4]; 333 }; 334 335 struct scsi_defect_desc_bytes_from_index 336 { 337 u_int8_t cylinder[3]; 338 u_int8_t head; 339 u_int8_t bytes_from_index[4]; 340 }; 341 342 struct scsi_defect_desc_phys_sector 343 { 344 u_int8_t cylinder[3]; 345 u_int8_t head; 346 u_int8_t sector[4]; 347 }; 348 349 struct scsi_read_defect_data_hdr_12 350 { 351 u_int8_t reserved; 352 #define SRDDH12_GLIST 0x08 353 #define SRDDH12_PLIST 0x10 354 #define SRDDH12_DLIST_FORMAT_MASK 0x07 355 #define SRDDH12_BLOCK_FORMAT 0x00 356 #define SRDDH12_BYTES_FROM_INDEX_FORMAT 0x04 357 #define SRDDH12_PHYSICAL_SECTOR_FORMAT 0x05 358 u_int8_t format; 359 u_int8_t generation[2]; 360 u_int8_t length[4]; 361 }; 362 363 union disk_pages /* this is the structure copied from osf */ 364 { 365 struct format_device_page { 366 u_int8_t pg_code; /* page code (should be 3) */ 367 #define SMS_FORMAT_DEVICE_PAGE 0x03 /* only 6 bits valid */ 368 u_int8_t pg_length; /* page length (should be 0x16) */ 369 #define SMS_FORMAT_DEVICE_PLEN 0x16 370 u_int8_t trk_z_1; /* tracks per zone (MSB) */ 371 u_int8_t trk_z_0; /* tracks per zone (LSB) */ 372 u_int8_t alt_sec_1; /* alternate sectors per zone (MSB) */ 373 u_int8_t alt_sec_0; /* alternate sectors per zone (LSB) */ 374 u_int8_t alt_trk_z_1; /* alternate tracks per zone (MSB) */ 375 u_int8_t alt_trk_z_0; /* alternate tracks per zone (LSB) */ 376 u_int8_t alt_trk_v_1; /* alternate tracks per volume (MSB) */ 377 u_int8_t alt_trk_v_0; /* alternate tracks per volume (LSB) */ 378 u_int8_t ph_sec_t_1; /* physical sectors per track (MSB) */ 379 u_int8_t ph_sec_t_0; /* physical sectors per track (LSB) */ 380 u_int8_t bytes_s_1; /* bytes per sector (MSB) */ 381 u_int8_t bytes_s_0; /* bytes per sector (LSB) */ 382 u_int8_t interleave_1; /* interleave (MSB) */ 383 u_int8_t interleave_0; /* interleave (LSB) */ 384 u_int8_t trk_skew_1; /* track skew factor (MSB) */ 385 u_int8_t trk_skew_0; /* track skew factor (LSB) */ 386 u_int8_t cyl_skew_1; /* cylinder skew (MSB) */ 387 u_int8_t cyl_skew_0; /* cylinder skew (LSB) */ 388 u_int8_t flags; /* various */ 389 #define DISK_FMT_SURF 0x10 390 #define DISK_FMT_RMB 0x20 391 #define DISK_FMT_HSEC 0x40 392 #define DISK_FMT_SSEC 0x80 393 u_int8_t reserved21; 394 u_int8_t reserved22; 395 u_int8_t reserved23; 396 } format_device; 397 struct rigid_geometry_page { 398 u_int8_t pg_code; /* page code (should be 4) */ 399 #define SMS_RIGID_GEOMETRY_PAGE 0x04 400 u_int8_t pg_length; /* page length (should be 0x16) */ 401 #define SMS_RIGID_GEOMETRY_PLEN 0x16 402 u_int8_t ncyl_2; /* number of cylinders (MSB) */ 403 u_int8_t ncyl_1; /* number of cylinders */ 404 u_int8_t ncyl_0; /* number of cylinders (LSB) */ 405 u_int8_t nheads; /* number of heads */ 406 u_int8_t st_cyl_wp_2; /* starting cyl., write precomp (MSB) */ 407 u_int8_t st_cyl_wp_1; /* starting cyl., write precomp */ 408 u_int8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ 409 u_int8_t st_cyl_rwc_2; /* starting cyl., red. write cur (MSB)*/ 410 u_int8_t st_cyl_rwc_1; /* starting cyl., red. write cur */ 411 u_int8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ 412 u_int8_t driv_step_1; /* drive step rate (MSB) */ 413 u_int8_t driv_step_0; /* drive step rate (LSB) */ 414 u_int8_t land_zone_2; /* landing zone cylinder (MSB) */ 415 u_int8_t land_zone_1; /* landing zone cylinder */ 416 u_int8_t land_zone_0; /* landing zone cylinder (LSB) */ 417 u_int8_t rpl; /* rotational position locking (2 bits) */ 418 u_int8_t rot_offset; /* rotational offset */ 419 u_int8_t reserved19; 420 u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ 421 u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ 422 u_int8_t reserved22; 423 u_int8_t reserved23; 424 } rigid_geometry; 425 struct flexible_disk_page { 426 u_int8_t pg_code; /* page code (should be 5) */ 427 #define SMS_FLEXIBLE_GEOMETRY_PAGE 0x05 428 u_int8_t pg_length; /* page length (should be 0x1E) */ 429 #define SMS_FLEXIBLE_GEOMETRY_PLEN 0x1E 430 u_int8_t xfr_rate_1; /* transfer rate (MSB) */ 431 u_int8_t xfr_rate_0; /* transfer rate (LSB) */ 432 u_int8_t nheads; /* number of heads */ 433 u_int8_t sec_per_track; /* Sectors per track */ 434 u_int8_t bytes_s_1; /* bytes per sector (MSB) */ 435 u_int8_t bytes_s_0; /* bytes per sector (LSB) */ 436 u_int8_t ncyl_1; /* number of cylinders (MSB) */ 437 u_int8_t ncyl_0; /* number of cylinders (LSB) */ 438 u_int8_t st_cyl_wp_1; /* starting cyl., write precomp (MSB) */ 439 u_int8_t st_cyl_wp_0; /* starting cyl., write precomp (LSB) */ 440 u_int8_t st_cyl_rwc_1; /* starting cyl., red. write cur (MSB)*/ 441 u_int8_t st_cyl_rwc_0; /* starting cyl., red. write cur (LSB)*/ 442 u_int8_t driv_step_1; /* drive step rate (MSB) */ 443 u_int8_t driv_step_0; /* drive step rate (LSB) */ 444 u_int8_t driv_step_pw; /* drive step pulse width */ 445 u_int8_t head_stl_del_1;/* Head settle delay (MSB) */ 446 u_int8_t head_stl_del_0;/* Head settle delay (LSB) */ 447 u_int8_t motor_on_del; /* Motor on delay */ 448 u_int8_t motor_off_del; /* Motor off delay */ 449 u_int8_t trdy_ssn_mo; /* XXX ??? */ 450 u_int8_t spc; /* XXX ??? */ 451 u_int8_t write_comp; /* Write compensation */ 452 u_int8_t head_load_del; /* Head load delay */ 453 u_int8_t head_uload_del;/* Head un-load delay */ 454 u_int8_t pin32_pin2; 455 u_int8_t pin4_pint1; 456 u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */ 457 u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */ 458 u_int8_t reserved30; 459 u_int8_t reserved31; 460 } flexible_disk; 461 }; 462 463 /* 464 * XXX KDM 465 * Here for CTL compatibility, reconcile this. 466 */ 467 struct scsi_format_page { 468 uint8_t page_code; 469 uint8_t page_length; 470 uint8_t tracks_per_zone[2]; 471 uint8_t alt_sectors_per_zone[2]; 472 uint8_t alt_tracks_per_zone[2]; 473 uint8_t alt_tracks_per_lun[2]; 474 uint8_t sectors_per_track[2]; 475 uint8_t bytes_per_sector[2]; 476 uint8_t interleave[2]; 477 uint8_t track_skew[2]; 478 uint8_t cylinder_skew[2]; 479 uint8_t flags; 480 #define SFP_SSEC 0x80 481 #define SFP_HSEC 0x40 482 #define SFP_RMB 0x20 483 #define SFP_SURF 0x10 484 uint8_t reserved[3]; 485 }; 486 487 /* 488 * XXX KDM 489 * Here for CTL compatibility, reconcile this. 490 */ 491 struct scsi_rigid_disk_page { 492 uint8_t page_code; 493 #define SMS_RIGID_DISK_PAGE 0x04 494 uint8_t page_length; 495 uint8_t cylinders[3]; 496 uint8_t heads; 497 uint8_t start_write_precomp[3]; 498 uint8_t start_reduced_current[3]; 499 uint8_t step_rate[2]; 500 uint8_t landing_zone_cylinder[3]; 501 uint8_t rpl; 502 #define SRDP_RPL_DISABLED 0x00 503 #define SRDP_RPL_SLAVE 0x01 504 #define SRDP_RPL_MASTER 0x02 505 #define SRDP_RPL_MASTER_CONTROL 0x03 506 uint8_t rotational_offset; 507 uint8_t reserved1; 508 uint8_t rotation_rate[2]; 509 uint8_t reserved2[2]; 510 }; 511 512 513 struct scsi_da_rw_recovery_page { 514 u_int8_t page_code; 515 #define SMS_RW_ERROR_RECOVERY_PAGE 0x01 516 u_int8_t page_length; 517 u_int8_t byte3; 518 #define SMS_RWER_AWRE 0x80 519 #define SMS_RWER_ARRE 0x40 520 #define SMS_RWER_TB 0x20 521 #define SMS_RWER_RC 0x10 522 #define SMS_RWER_EER 0x08 523 #define SMS_RWER_PER 0x04 524 #define SMS_RWER_DTE 0x02 525 #define SMS_RWER_DCR 0x01 526 u_int8_t read_retry_count; 527 u_int8_t correction_span; 528 u_int8_t head_offset_count; 529 u_int8_t data_strobe_offset_cnt; 530 u_int8_t byte8; 531 #define SMS_RWER_LBPERE 0x80 532 u_int8_t write_retry_count; 533 u_int8_t reserved2; 534 u_int8_t recovery_time_limit[2]; 535 }; 536 537 __BEGIN_DECLS 538 /* 539 * XXX This is only left out of the kernel build to silence warnings. If, 540 * for some reason this function is used in the kernel, the ifdefs should 541 * be moved so it is included both in the kernel and userland. 542 */ 543 #ifndef _KERNEL 544 void scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries, 545 void (*cbfcnp)(struct cam_periph *, union ccb *), 546 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave, 547 u_int8_t *data_ptr, u_int32_t dxfer_len, 548 u_int8_t sense_len, u_int32_t timeout); 549 550 void scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries, 551 void (*cbfcnp)(struct cam_periph *, union ccb *), 552 u_int8_t tag_action, u_int8_t byte2, u_int16_t control, 553 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 554 u_int32_t timeout); 555 556 #endif /* !_KERNEL */ 557 __END_DECLS 558 559 #endif /* _SCSI_SCSI_DA_H */ 560