1 /* 2 * Copyright (c) 1990, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Van Jacobson of Lawrence Berkeley Laboratory. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)scsireg.h 8.1 (Berkeley) 06/10/93 11 */ 12 13 /* 14 * MB89352 SCSI Protocol Controller Hardware Description. 15 */ 16 17 struct scsidevice { 18 u_char scsi_bdid, p0, p1, p2; /* 000 */ 19 u_char scsi_sctl, p3, p4, p5; /* 004 */ 20 #define SCTL_DISABLE 0x80 21 #define SCTL_CTRLRST 0x40 22 #define SCTL_DIAG 0x20 23 #define SCTL_ABRT_ENAB 0x10 24 #define SCTL_PARITY_ENAB 0x08 25 #define SCTL_SEL_ENAB 0x04 26 #define SCTL_RESEL_ENAB 0x02 27 #define SCTL_INTR_ENAB 0x01 28 u_char scsi_scmd, p6, p7, p8; /* 008 */ 29 #define SCMD_RST 0x10 30 #define SCMD_ICPT_XFR 0x08 31 #define SCMD_PROG_XFR 0x04 32 #define SCMD_PAD 0x01 /* if initiator */ 33 #define SCMD_PERR_STOP 0x01 /* if target */ 34 /* command codes */ 35 #define SCMD_BUS_REL 0x00 36 #define SCMD_SELECT 0x20 37 #define SCMD_RST_ATN 0x40 38 #define SCMD_SET_ATN 0x60 39 #define SCMD_XFR 0x80 40 #define SCMD_XFR_PAUSE 0xa0 41 #define SCMD_RST_ACK 0xc0 42 #define SCMD_SET_ACK 0xe0 43 u_char scsi_tmod, p9, p10, p11; /* 00C */ 44 #define TMOD_SYNC 0x80 45 u_char scsi_ints, p12, p13, p14; /* 010 */ 46 #define INTS_SEL 0x80 47 #define INTS_RESEL 0x40 48 #define INTS_DISCON 0x20 49 #define INTS_CMD_DONE 0x10 50 #define INTS_SRV_REQ 0x08 51 #define INTS_TIMEOUT 0x04 52 #define INTS_HARD_ERR 0x02 53 #define INTS_RST 0x01 54 u_char scsi_psns, p15, p16, p17; /* 014 */ 55 #define PSNS_REQ 0x80 56 #define PSNS_ACK 0x40 57 #define PSNS_ATN 0x20 58 #define PSNS_SEL 0x10 59 #define PSNS_BSY 0x08 60 #define scsi_sdgc scsi_psns 61 #define SDGC_XFER_ENAB 0x20 62 u_char scsi_ssts, p18, p19, p20; /* 018 */ 63 #define SSTS_INITIATOR 0x80 64 #define SSTS_TARGET 0x40 65 #define SSTS_BUSY 0x20 66 #define SSTS_XFR 0x10 67 #define SSTS_ACTIVE (SSTS_INITIATOR|SSTS_XFR) 68 #define SSTS_RST 0x08 69 #define SSTS_TCZERO 0x04 70 #define SSTS_DREG_FULL 0x02 71 #define SSTS_DREG_EMPTY 0x01 72 u_char scsi_serr, p21, p22, p23; /* 01C */ 73 #define SERR_SCSI_PAR 0x80 74 #define SERR_SPC_PAR 0x40 75 #define SERR_XFER_OUT 0x20 76 #define SERR_TC_PAR 0x08 77 #define SERR_PHASE_ERR 0x04 78 #define SERR_SHORT_XFR 0x02 79 #define SERR_OFFSET 0x01 80 u_char scsi_pctl, p24, p25, p26; /* 020 */ 81 #define PCTL_BFINT_ENAB 0x80 82 u_char scsi_mbc, p27, p28, p29; /* 024 */ 83 u_char scsi_dreg, p30, p31, p32; /* 028 */ 84 u_char scsi_temp, p33, p34, p35; /* 02C */ 85 u_char scsi_tch, p36, p37, p38; /* 030 */ 86 u_char scsi_tcm, p39, p40, p41; /* 034 */ 87 u_char scsi_tcl, p42, p43, p44; /* 038 */ 88 u_char scsi_exbf, p45, p46, p47; /* 03C */ 89 }; 90 91 /* psns/pctl phase lines as bits */ 92 #define PHASE_MSG 0x04 93 #define PHASE_CD 0x02 /* =1 if 'command' */ 94 #define PHASE_IO 0x01 /* =1 if data inbound */ 95 /* Phase lines as values */ 96 #define PHASE 0x07 /* mask for psns/pctl phase */ 97 #define DATA_OUT_PHASE 0x00 98 #define DATA_IN_PHASE 0x01 99 #define CMD_PHASE 0x02 100 #define STATUS_PHASE 0x03 101 #define BUS_FREE_PHASE 0x04 102 #define ARB_SEL_PHASE 0x05 /* Fuji chip combines arbitration with sel. */ 103 #define MESG_OUT_PHASE 0x06 104 #define MESG_IN_PHASE 0x07 105 106 /* SCSI Messages */ 107 108 #define MSG_CMD_COMPLETE 0x00 109 #define MSG_EXT_MESSAGE 0x01 110 #define MSG_SAVE_DATA_PTR 0x02 111 #define MSG_RESTORE_PTR 0x03 112 #define MSG_DISCONNECT 0x04 113 #define MSG_INIT_DETECT_ERROR 0x05 114 #define MSG_ABORT 0x06 115 #define MSG_REJECT 0x07 116 #define MSG_NOOP 0x08 117 #define MSG_PARITY_ERROR 0x09 118 #define MSG_BUS_DEVICE_RESET 0x0C 119 #define MSG_IDENTIFY 0x80 120 #define MSG_IDENTIFY_DR 0xc0 /* (disconnect/reconnect allowed) */ 121 #define MSG_SYNC_REQ 0x01 122 123 /* SCSI Commands */ 124 125 #define CMD_TEST_UNIT_READY 0x00 126 #define CMD_REQUEST_SENSE 0x03 127 #define CMD_INQUIRY 0x12 128 #define CMD_SEND_DIAGNOSTIC 0x1D 129 130 #define CMD_REWIND 0x01 131 #define CMD_FORMAT_UNIT 0x04 132 #define CMD_READ_BLOCK_LIMITS 0x05 133 #define CMD_REASSIGN_BLOCKS 0x07 134 #define CMD_READ 0x08 135 #define CMD_WRITE 0x0A 136 #define CMD_WRITE_FILEMARK 0x10 137 #define CMD_SPACE 0x11 138 #define CMD_MODE_SELECT 0x15 139 #define CMD_RELEASE_UNIT 0x17 140 #define CMD_ERASE 0x19 141 #define CMD_MODE_SENSE 0x1A 142 #define CMD_LOADUNLOAD 0x1B 143 #define CMD_RECEIVE_DIAG 0x1C 144 #define CMD_SEND_DIAG 0x1D 145 #define CMD_P_A_MEDIA_REMOVAL 0x1E 146 #define CMD_READ_CAPACITY 0x25 147 #define CMD_READ_EXT 0x28 148 #define CMD_WRITE_EXT 0x2A 149 #define CMD_READ_DEFECT_DATA 0x37 150 #define SD_MANUFAC_DEFECTS 0x14000000 151 #define SD_GROWN_DEFECTS 0x0c000000 152 #define CMD_READ_BUFFER 0x3B 153 #define CMD_WRITE_BUFFER 0x3C 154 #define CMD_READ_FULL 0xF0 155 #define CMD_MEDIA_TEST 0xF1 156 #define CMD_ACCESS_LOG 0xF2 157 #define CMD_WRITE_FULL 0xFC 158 #define CMD_MANAGE_PRIMARY 0xFD 159 #define CMD_EXECUTE_DATA 0xFE 160 161 /* SCSI status bits */ 162 163 #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */ 164 #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */ 165 #define STS_BUSY 0x08 166 #define STS_INTERMED 0x10 /* Intermediate status sent */ 167 #define STS_EXT 0x80 /* Extended status valid */ 168 169 /* command descriptor blocks */ 170 171 struct scsi_cdb6 { 172 u_char cmd; /* command code */ 173 u_char lun: 3, /* logical unit on ctlr */ 174 lbah: 5; /* msb of read/write logical block addr */ 175 u_char lbam; /* middle byte of l.b.a. */ 176 u_char lbal; /* lsb of l.b.a. */ 177 u_char len; /* transfer length */ 178 u_char xtra; 179 }; 180 181 struct scsi_cdb10 { 182 u_char cmd; /* command code */ 183 u_char lun: 3, /* logical unit on ctlr */ 184 : 4, 185 rel: 1; /* l.b.a. is relative addr if =1 */ 186 u_char lbah; /* msb of read/write logical block addr */ 187 u_char lbahm; /* high middle byte of l.b.a. */ 188 u_char lbalm; /* low middle byte of l.b.a. */ 189 u_char lbal; /* lsb of l.b.a. */ 190 u_char reserved; 191 u_char lenh; /* msb transfer length */ 192 u_char lenl; /* lsb transfer length */ 193 u_char xtra; 194 }; 195 196 /* basic sense data */ 197 198 struct scsi_sense { 199 u_char valid: 1, /* l.b.a. is valid */ 200 class: 3, 201 code: 4; 202 u_char vu: 4, /* vendor unique */ 203 lbah: 4; 204 u_char lbam; 205 u_char lbal; 206 }; 207 208 struct scsi_xsense { 209 u_char valid: 1, /* l.b.a. is valid */ 210 class: 3, 211 code: 4; 212 u_char segment; 213 u_char filemark: 1, 214 eom: 1, 215 ili: 1, /* illegal length indicator */ 216 rsvd: 1, 217 key: 4; 218 u_char info1; 219 u_char info2; 220 u_char info3; 221 u_char info4; 222 u_char len; /* additional sense length */ 223 }; 224 225 /* inquiry data */ 226 struct scsi_inquiry { 227 u_char type; 228 u_char qual; 229 u_char version; 230 u_char rsvd; 231 u_char len; 232 char class[3]; 233 char vendor_id[8]; 234 char product_id[16]; 235 char rev[4]; 236 }; 237 238 struct scsi_format_parms { /* physical BFI format */ 239 u_short reserved; 240 u_short list_len; 241 struct defect { 242 unsigned cyl : 24; 243 unsigned head : 8; 244 long bytes_from_index; 245 } defect[127]; 246 } format_parms; 247 248 struct scsi_reassign_parms { 249 u_short reserved; 250 u_short list_len; /* length in bytes of defects only */ 251 struct new_defect { 252 unsigned lba; /* logical block address */ 253 } new_defect[2]; 254 } reassign_parms; 255 256 struct scsi_modesel_hdr { 257 u_char rsvd1; 258 u_char media_type; 259 u_char rsvd2; 260 u_char block_desc_len; 261 u_int density : 8; 262 u_int number_blocks :24; 263 u_int rsvd3 : 8; 264 u_int block_length :24; 265 }; 266 267 struct scsi_modesense_hdr { 268 u_char len; 269 u_char media_type; 270 u_char wp : 1; 271 u_char rsvd1 : 7; 272 u_char block_desc_len; 273 u_int density : 8; 274 u_int number_blocks :24; 275 u_int rsvd2 : 8; 276 u_int block_length :24; 277 }; 278 279 /* 280 * Mode Select / Mode sense "pages" 281 */ 282 283 /* 284 * Page One - Error Recovery Parameters 285 */ 286 struct scsi_err_recovery { 287 u_char page_savable : 1; /* save parameters */ 288 u_char reserved : 1; 289 u_char page_code : 6; /* = 0x01 */ 290 u_char page_length; /* = 6 */ 291 u_char awre : 1; /* auto write realloc enabled */ 292 u_char arre : 1; /* auto read realloc enabled */ 293 u_char tb : 1; /* transfer block */ 294 u_char rc : 1; /* read continuous */ 295 u_char eec : 1; /* enable early correction */ 296 u_char per : 1; /* post error */ 297 u_char dte : 1; /* disable transfer on error */ 298 u_char dcr : 1; /* disable correction */ 299 u_char retry_count; 300 u_char correction_span; 301 u_char head_offset_count; 302 u_char strobe_offset_count; 303 u_char recovery_time_limit; 304 }; 305 306 /* 307 * Page Two - Disconnect / Reconnect Control Parameters 308 */ 309 struct scsi_disco_reco { 310 u_char page_savable : 1; /* save parameters */ 311 u_char rsvd : 1; 312 u_char page_code : 6; /* = 0x02 */ 313 u_char page_length; /* = 10 */ 314 u_char buffer_full_ratio; /* write, how full before reconnect? */ 315 u_char buffer_empty_ratio; /* read, how full before reconnect? */ 316 317 u_short bus_inactivity_limit; /* how much bus time for busy */ 318 u_short disconnect_time_limit; /* min to remain disconnected */ 319 u_short connect_time_limit; /* min to remain connected */ 320 u_short reserved_1; 321 }; 322 323 /* 324 * Page Three - Direct Access Device Format Parameters 325 */ 326 struct scsi_format { 327 u_char page_savable : 1; /* save parameters */ 328 u_char rsvd : 1; 329 u_char page_code : 6; /* = 0x03 */ 330 u_char page_length; /* = 22 */ 331 u_short tracks_per_zone; /* Handling of Defects Fields */ 332 u_short alt_sect_zone; 333 u_short alt_tracks_zone; 334 u_short alt_tracks_vol; 335 u_short sect_track; /* Track Format Field */ 336 u_short data_sect; /* Sector Format Fields */ 337 u_short interleave; 338 u_short track_skew_factor; 339 u_short cyl_skew_factor; 340 u_char ssec : 1; /* Drive Type Field */ 341 u_char hsec : 1; 342 u_char rmb : 1; 343 u_char surf : 1; 344 u_char ins : 1; 345 u_char reserved_1 : 3; 346 u_char reserved_2; 347 u_char reserved_3; 348 u_char reserved_4; 349 }; 350 351 /* 352 * Page Four - Rigid Disk Drive Geometry Parameters 353 */ 354 struct scsi_geometry { 355 u_char page_savable : 1; /* save parameters */ 356 u_char rsvd : 1; 357 u_char page_code : 6; /* = 0x04 */ 358 u_char page_length; /* = 18 */ 359 u_char cyl_ub; /* number of cylinders */ 360 u_char cyl_mb; 361 u_char cyl_lb; 362 u_char heads; /* number of heads */ 363 u_char precomp_cyl_ub; /* cylinder to start precomp */ 364 u_char precomp_cyl_mb; 365 u_char precomp_cyl_lb; 366 u_char current_cyl_ub; /* cyl to start reduced current */ 367 u_char current_cyl_mb; 368 u_char current_cyl_lb; 369 u_short step_rate; /* drive step rate */ 370 u_char landing_cyl_ub; /* landing zone cylinder */ 371 u_char landing_cyl_mb; 372 u_char landing_cyl_lb; 373 u_char reserved_1; 374 u_char reserved_2; 375 u_char reserved_3; 376 }; 377 378 /* 379 * Page 0x38 - Cache Control Parameters 380 */ 381 struct scsi_cache { 382 u_char page_savable : 1; /* save parameters */ 383 u_char rsvd : 1; 384 u_char page_code : 6; /* = 0x38 */ 385 u_char page_length; /* = 14 */ 386 u_char rsvd_1 : 1; 387 u_char wie : 1; /* write index enable */ 388 u_char rsvd_2 : 1; 389 u_char ce : 1; /* cache enable */ 390 u_char table_size : 4; 391 u_char prefetch_threshold; 392 u_char maximum_threshold; 393 u_char maximumprefetch_multiplier; 394 u_char minimum_threshold; 395 u_char minimum_prefetch_multiplier; 396 u_char reserved[8]; 397 }; 398 399 /* 400 * Driver ioctl's for various scsi operations. 401 */ 402 #ifndef _IOCTL_ 403 #include <sys/ioctl.h> 404 #endif 405 406 /* 407 * Control for SCSI "format" mode. 408 * 409 * "Format" mode allows a privileged process to issue direct SCSI 410 * commands to a drive (it is intended primarily to allow on-line 411 * formatting). SDIOCSFORMAT with a non-zero arg will put the drive 412 * into format mode; a zero arg will take it out. When in format 413 * mode, only the process that issued the SDIOCFORMAT can read or 414 * write the drive. 415 * 416 * In format mode, process is expected to 417 * - do SDIOCSCSICOMMAND to supply cdb for next SCSI op 418 * - do read or write as appropriate for cdb 419 * - if i/o error, optionally do SDIOCSENSE to get completion 420 * status and sense data from last scsi operation. 421 */ 422 423 struct scsi_fmt_cdb { 424 int len; /* cdb length (in bytes) */ 425 u_char cdb[28]; /* cdb to use on next read/write */ 426 }; 427 428 struct scsi_fmt_sense { 429 u_int status; /* completion status of last op */ 430 u_char sense[28]; /* sense data (if any) from last op */ 431 }; 432 433 #define SDIOCSFORMAT _IOW('S', 0x1, int) 434 #define SDIOCGFORMAT _IOR('S', 0x2, int) 435 #define SDIOCSCSICOMMAND _IOW('S', 0x3, struct scsi_fmt_cdb) 436 #define SDIOCSENSE _IOR('S', 0x4, struct scsi_fmt_sense) 437