1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_SCSI_TARGETS_STDEF_H 27 #define _SYS_SCSI_TARGETS_STDEF_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/sunddi.h> 32 #include <sys/note.h> 33 #include <sys/condvar.h> 34 #include <sys/kstat.h> 35 #include <sys/scsi/scsi_types.h> 36 #include <sys/scsi/generic/sense.h> 37 #include <sys/mtio.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * Defines for SCSI tape drives. 45 */ 46 47 /* 48 * Maximum variable length record size for a single request 49 */ 50 #define ST_MAXRECSIZE_VARIABLE 65535 51 52 /* 53 * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE, 54 * then the following define is used. 55 */ 56 #define ST_MAXRECSIZE_VARIABLE_LIMIT 65534 57 58 #define ST_MAXRECSIZE_FIXED (63<<10) /* maximum fixed record size */ 59 #define INF 1000000000 60 61 /* 62 * Supported tape device types plus default type for opening. 63 * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED* 64 * Types 14 - 1f, are 1/4-inch cartridge drives. 65 * Types 20 - 28, are 1/2-inch cartridge or reel drives. 66 * Types 28+, are rdat (vcr) drives. 67 */ 68 #define ST_TYPE_INVALID 0x00 69 70 #define ST_TYPE_SYSGEN1 MT_ISSYSGEN11 /* Sysgen with QIC-11 only */ 71 #define ST_TYPE_SYSGEN MT_ISSYSGEN /* Sysgen with QIC-24 and QIC-11 */ 72 73 #define ST_TYPE_DEFAULT MT_ISDEFAULT /* Generic 1/4" or undetermined */ 74 #define ST_TYPE_EMULEX MT_ISMT02 /* Emulex MT-02 */ 75 #define ST_TYPE_ARCHIVE MT_ISVIPER1 /* Archive QIC-150 */ 76 #define ST_TYPE_WANGTEK MT_ISWANGTEK1 /* Wangtek QIC-150 */ 77 78 #define ST_TYPE_CDC MT_ISCDC /* CDC - (not tested) */ 79 #define ST_TYPE_FUJI MT_ISFUJI /* Fujitsu - (not tested) */ 80 #define ST_TYPE_KENNEDY MT_ISKENNEDY /* Kennedy */ 81 #define ST_TYPE_ANRITSU MT_ISANRITSU /* Anritsu */ 82 #define ST_TYPE_HP MT_ISHP /* HP */ 83 #define ST_TYPE_HIC MT_ISCCS23 /* Generic 1/2" Cartridge */ 84 #define ST_TYPE_REEL MT_ISCCS24 /* Generic 1/2" Reel Tape */ 85 #define ST_TYPE_DAT MT_ISCCS28 /* Generic DAT Tape */ 86 87 #define ST_TYPE_EXABYTE MT_ISEXABYTE /* Exabyte 8200 */ 88 #define ST_TYPE_EXB8500 MT_ISEXB8500 /* Exabyte 8500 */ 89 #define ST_TYPE_WANGTHS MT_ISWANGTHS /* Wangtek 6130HS */ 90 #define ST_TYPE_WANGDAT MT_ISWANGDAT /* WangDAT */ 91 #define ST_TYPE_PYTHON MT_ISPYTHON /* Archive Python DAT */ 92 #define ST_TYPE_STC3490 MT_ISSTC /* IBM STC 3490 */ 93 #define ST_TYPE_TAND25G MT_ISTAND25G /* TANDBERG 2.5G */ 94 #define ST_TYPE_DLT MT_ISDLT /* DLT */ 95 #define ST_TYPE_STK9840 MT_ISSTK9840 /* StorageTek 9840, 9940, 9840B */ 96 #define ST_TYPE_BMDLT1 MT_ISBMDLT1 /* Benchmark DTL1 */ 97 #define ST_TYPE_LTO MT_LTO /* sun: LTO's by HP, Seagate, IBM.. */ 98 #define ST_TYPE_AIT MT_ISAIT /* Sony AIT I, II, III and SAIT */ 99 #define ST_LAST_TYPE ST_TYPE_AIT /* Add new above type and change this */ 100 101 102 /* Internal flags */ 103 #define ST_DYNAMIC 0x2000 /* Device name has been dynamically */ 104 /* alloc'ed from the st.conf entry, */ 105 /* instead of being used from the */ 106 /* st_drivetypes array. */ 107 108 /* 109 * Defines for supported drive options 110 * 111 * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS 112 * WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME 113 */ 114 #define ST_VARIABLE 0x001 /* Device supports variable */ 115 /* length record sizes */ 116 #define ST_QIC 0x002 /* QIC tape device */ 117 #define ST_REEL 0x004 /* 1/2-inch reel tape device */ 118 #define ST_BSF 0x008 /* Device supports backspace */ 119 /* file as in mt(1) bsf : */ 120 /* backspace over EOF marks. */ 121 /* Devices not supporting bsf */ 122 /* will fail with ENOTTY upon */ 123 /* use of bsf */ 124 #define ST_BSR 0x010 /* Device supports backspace */ 125 /* record as in mt(1) bsr : */ 126 /* backspace over records. If */ 127 /* the device does not support */ 128 /* bsr, the st driver emulates */ 129 /* the action by rewinding the */ 130 /* tape and using forward space */ 131 /* file (fsf) to the correct */ 132 /* file and then uses forward */ 133 /* space record (fsr) to the */ 134 /* correct record */ 135 #define ST_LONG_ERASE 0x020 /* Device needs a longer time */ 136 /* than normal to erase */ 137 #define ST_AUTODEN_OVERRIDE 0x040 /* Auto-Density override flag */ 138 /* Device can figure out the */ 139 /* tape density automatically, */ 140 /* without issuing a */ 141 /* mode-select/mode-sense */ 142 #define ST_NOBUF 0x080 /* Don't use buffered mode. */ 143 /* This disables the device's */ 144 /* ability for buffered writes */ 145 /* I.e. The device acknowledges */ 146 /* write completion after the */ 147 /* data is written to the */ 148 /* device's buffer, but before */ 149 /* all the data is actually */ 150 /* written to tape */ 151 #define ST_RESERVED_BIT1 0x100 /* resreved bit */ 152 /* parity while talking to it. */ 153 #define ST_KNOWS_EOD 0x200 /* Device knows when EOD (End */ 154 /* of Data) has been reached. */ 155 /* If the device knows EOD, st */ 156 /* uses fast file skipping. */ 157 /* If it does not know EOD, */ 158 /* file skipping happens one */ 159 /* file at a time. */ 160 #define ST_UNLOADABLE 0x400 /* Device will not complain if */ 161 /* the st driver is unloaded & */ 162 /* loaded again; e.g. will */ 163 /* return the correct inquiry */ 164 /* string */ 165 #define ST_SOFT_ERROR_REPORTING 0x800 /* Do request or log sense on */ 166 /* close to report soft errors. */ 167 /* Currently only Exabyte and */ 168 /* DAT drives support this */ 169 /* feature. */ 170 #define ST_LONG_TIMEOUTS 0x1000 /* Device needs 5 times longer */ 171 /* timeouts for normal */ 172 /* operation */ 173 #define ST_BUFFERED_WRITES 0x4000 /* The data is buffered in the */ 174 /* driver and pre-acked to the */ 175 /* application */ 176 #define ST_NO_RECSIZE_LIMIT 0x8000 /* For variable record size */ 177 /* devices only. If flag is */ 178 /* set, then don't limit */ 179 /* record size to 64k as in */ 180 /* pre-Solaris 2.4 releases. */ 181 /* The only limit on the */ 182 /* record size will be the max */ 183 /* record size the device can */ 184 /* handle or the max DMA */ 185 /* transfer size of the */ 186 /* machine, which ever is */ 187 /* smaller. Beware of */ 188 /* incompatabilities with */ 189 /* tapes of pre-Solaris 2.4 */ 190 /* OS's written with large */ 191 /* (>64k) block sizes, as */ 192 /* their true block size is */ 193 /* a max of approx 64k */ 194 #define ST_MODE_SEL_COMP 0x10000 /* use mode select of device */ 195 /* configuration page (0x10) to */ 196 /* enable/disable compression */ 197 /* instead of density codes for */ 198 /* the "c" and "u" devices */ 199 #define ST_NO_RESERVE_RELEASE 0x20000 /* For devices which do not */ 200 /* support RESERVE/RELEASE SCSI */ 201 /* command. If this is enabled */ 202 /* then reserve/release would */ 203 /* not be used during open/ */ 204 /* close for High Availability */ 205 #define ST_READ_IGNORE_ILI 0x40000 /* This flag is only applicable */ 206 /* to variable block devices */ 207 /* which support the SILI bit */ 208 /* option. It indicates that */ 209 /* the SILI bit will be ignored */ 210 /* during reads */ 211 #define ST_READ_IGNORE_EOFS 0x80000 /* When this flag is set two */ 212 /* EOF marks do not indicate an */ 213 /* EOM. This option is only */ 214 /* supported on 1/2" reel tapes */ 215 #define ST_SHORT_FILEMARKS 0x100000 /* This option applies only to */ 216 /* EXABYTE 8mm tape drives */ 217 /* which support short */ 218 /* filemarks. When this flag */ 219 /* is set, short filemarks */ 220 /* will be used for writing */ 221 /* filemarks. */ 222 #define ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set */ 223 /* and the tape is trapped in */ 224 /* the medium changer, the tape */ 225 /* is automatically ejected */ 226 #define ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000 227 /* This option applies only to */ 228 /* IBM MAGSTAR 3590. If this */ 229 /* flag is set, the st driver */ 230 /* will retry the last cmd if */ 231 /* the last error cause a check */ 232 /* condition with error code */ 233 /* 0x71 and sense code 0x01 */ 234 #define ST_KNOWS_MEDIA 0x800000 /* Use configured media type */ 235 /* detected to select correct */ 236 /* density code. */ 237 #define ST_WORMABLE 0x1000000 238 /* Drive is capable of doing */ 239 /* Write Appends only at EOM */ 240 /* if WORM media type is loaded */ 241 #define ST_CLN_TYPE_1 0x10000000 /* When this flag is set, */ 242 /* the tape drive provides the */ 243 /* clean bit information in */ 244 /* byte 21, bitmask 0x08 of */ 245 /* Request Sense data */ 246 #define ST_CLN_TYPE_2 0x20000000 /* When this flag is set, */ 247 /* the tape drive provides the */ 248 /* clean bit information in */ 249 /* byte 70, bitmask 0xc0 of */ 250 /* Request Sense data */ 251 #define ST_CLN_TYPE_3 0x40000000 /* When this flag is set, */ 252 /* the tape drive provides the */ 253 /* clean bit information in */ 254 /* byte 18, bitmask 0x01 of */ 255 /* Request Sense data */ 256 257 #define ST_CLN_MASK (ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3) 258 #define ST_VALID_OPTS (ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\ 259 ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\ 260 ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\ 261 ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\ 262 ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\ 263 ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\ 264 ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3) 265 266 #define NDENSITIES MT_NDENSITIES 267 #define NSPEEDS MT_NSPEEDS 268 269 /* 270 * defines for Log Sense Pages 271 */ 272 #define SUPPORTED_LOG_PAGES_PAGE 0x00 273 #define TAPE_SEQUENTIAL_PAGE 0x0c 274 #define TAPE_ALERT_PAGE 0x2e 275 276 /* 277 * Log Page Control definitions 278 */ 279 #define CURRENT_THRESHOLD_VALUES 0x00 280 #define CURRENT_CUMULATIVE_VALUES 0x40 281 #define DEFAULT_THRESHOLD_VALUES 0x80 282 #define DEFAULT_CUMULATIVE_VALUES 0xC0 283 284 /* 285 * Tape Alert Flag definitions 286 */ 287 typedef enum { 288 TAF_READ_WARN = 0x01, 289 TAF_WRITE_WARN = 0x02, 290 TAF_HARD_ERR = 0x03, 291 TAF_MEDIA_ERR = 0x04, 292 TAF_READ_FAIL = 0x05, 293 TAF_WRITE_FAIL = 0x06, 294 TAF_MEDIA_LIFE = 0x07, 295 TAF_MEDIA_NOT_DATA_GRADE = 0x08, 296 TAF_WRITE_PROTECTED = 0x09, 297 TAF_NO_MEDIA_REMOVE = 0x0A, 298 TAF_CLEANING_MEDIA = 0x0B, 299 TAF_UNSUPPERTED_FORMAT = 0x0C, 300 TAF_RECOVERED_TAPE_BREAK = 0x0D, 301 TAF_TAPE_BREAK_FAUL = 0x0E, 302 TAF_CART_MEM_FAIL = 0x0F, 303 TAF_FORCED_EJECT = 0x10, 304 TAF_READ_ONLY_FORMAT = 0x11, 305 TAF_TAPE_DIR_CORRUPT = 0x12, 306 TAF_NEARING_MEDIA_LIFE = 0x13, 307 TAF_CLEAN_NOW = 0x14, 308 TAF_CLEAN_PERIODIC = 0x15, 309 TAF_EXP_CLEAN_CART = 0x16, 310 TAF_INVALID_CLEAN_MEDIA = 0x17, 311 TAF_RETENSION_REQUEST = 0x18, 312 TAF_DUAL_PORT_INTERFACE_ERR = 0x19, 313 TAF_COOLING_FAN_FAIL = 0x1A, 314 TAF_POWER_SUPPLY_FAIL = 0x1B, 315 TAF_POWER_CONSUMPTION = 0x1C, 316 TAF_DRIVE_MAINT_REQUEST = 0x1D, 317 TAF_HARDWARE_A = 0x1E, 318 TAF_HARDWARE_B = 0x1F, 319 TAF_INTERFACE = 0x20, 320 TAF_EJECT_MEDIA = 0x21, 321 TAF_DOWNLOAD_FAIL = 0x22, 322 TAF_DRIVE_HUMIDITY = 0x23, 323 TAF_DRIVE_TEMP = 0x24, 324 TAF_DRIVE_VOLTAGE = 0x25, 325 TAF_PREDICTIVE_FAIL = 0x26, 326 TAF_DIAG_REQUIRED = 0x27, 327 TAF_LOADER_HDWR_A = 0x28, 328 TAF_LOADER_STRAY_TAPE = 0x29, 329 TAF_LOADER_HDWR_B = 0x2A, 330 TAF_LOADER_DOOR = 0x2B, 331 TAF_LOADER_HDWR_C = 0x2C, 332 TAF_LOADER_MAGAZINE = 0x2D, 333 TAF_LOADER_PREDICTIVE_FAIL = 0x2E, 334 TAF_LOST_STATISTICS = 0x32, 335 TAF_TAPE_DIR_CURRUPT_UNLOAD = 0x33, 336 TAF_TAPE_SYS_WRT_FAIL = 0x34, 337 TAF_TAPE_SYS_RD_FAIL = 0x35, 338 TAF_NO_START_OF_DATA = 0x36, 339 TAF_WORM_INTEGRITY = 0x3B, 340 TAF_WORM_OVRWRT_ATTEMPT = 0x3C 341 }tape_alert_flags; 342 343 /* 344 * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension 345 * so they reuse TAF_RETENSION_REQUEST. 346 */ 347 #define CLEAN_FOR_ERRORS 0x18 348 349 350 #define TAPE_ALERT_SUPPORT_UNKNOWN 0x00 351 #define TAPE_ALERT_NOT_SUPPORTED 0x01 352 #define TAPE_ALERT_SUPPORTED 0x02 353 #define TAPE_ALERT_STILL_DIRTY 0x04 354 #define TAPE_SEQUENTIAL_SUPPORTED 0x08 355 #define TAPE_PREVIOUSLY_DIRTY 0x10 356 357 #define TAPE_ALERT_MAX_PARA 64 358 #define TAPE_SEQUENTIAL_PAGE_PARA 64 /* way more then really used */ 359 #define SEQUENTIAL_NEED_CLN 0x0100 360 361 /* 362 * Parameters 363 */ 364 #define ST_NAMESIZE 44 /* size of pretty string for vid/pid */ 365 #define VIDLEN 8 /* size of vendor identifier length */ 366 #define PIDLEN 16 /* size of product identifier length */ 367 #define VIDPIDLEN (VIDLEN + PIDLEN) 368 369 370 struct st_drivetype { 371 char name[ST_NAMESIZE]; /* Name, for debug */ 372 char length; /* Length of vendor id */ 373 char vid[VIDPIDLEN]; /* Vendor id and model (product) id */ 374 char type; /* Drive type for driver */ 375 int bsize; /* Block size */ 376 int options; /* Drive options */ 377 int max_rretries; /* Max read retries */ 378 int max_wretries; /* Max write retries */ 379 uchar_t densities[NDENSITIES]; /* density codes, low->hi */ 380 uchar_t default_density; /* default density for this drive */ 381 uchar_t mediatype[NDENSITIES]; /* was speed. mediatype for density. */ 382 ushort_t non_motion_timeout; /* Inquiry type commands */ 383 ushort_t io_timeout; /* I/O timeout in seconds */ 384 ushort_t rewind_timeout; /* rewind timeout in seconds */ 385 ushort_t space_timeout; /* space cmd timeout in seconds */ 386 ushort_t load_timeout; /* load tape time in seconds */ 387 ushort_t unload_timeout; /* unload tape time in seconds */ 388 ushort_t erase_timeout; /* erase timeout. seconds */ 389 }; 390 391 #define MINUTES(val) ((val) * 60) 392 393 struct comp_mode_page { 394 #if defined(_BIT_FIELDS_LTOH) 395 uchar_t : 6, 396 dcc: 1, /* Data Compression Capable */ 397 dce: 1; /* Data Compression Enable */ 398 uchar_t : 5, 399 red: 2, /* Report Exceptions on Decompress */ 400 dde: 1; /* Data Decompression Enabled */ 401 uchar_t comp_alg_msb; /* Compression Algorithm */ 402 uchar_t comp_alg_high; 403 uchar_t comp_alg_low; 404 uchar_t comp_alg_lsb; 405 uchar_t decomp_alg_msb; /* Decompression Algorithm */ 406 uchar_t decomp_alg_high; 407 uchar_t decomp_alg_low; 408 uchar_t decomp_alg_lsb; 409 uchar_t reservered0; 410 uchar_t reservered1; 411 uchar_t reservered2; 412 uchar_t reservered3; 413 414 #elif defined(_BIT_FIELDS_HTOL) 415 uchar_t dce: 1, /* Data Compression Enable */ 416 dcc: 1, /* Data Compression Capable */ 417 : 6; 418 uchar_t dde: 1, /* Data Decompression Enabled */ 419 red: 2, /* Report Exceptions on Decompress */ 420 : 5; 421 uchar_t comp_alg_msb; /* Compression Algorithm */ 422 uchar_t comp_alg_high; 423 uchar_t comp_alg_low; 424 uchar_t comp_alg_lsb; 425 uchar_t decomp_alg_msb; /* Decompression Algorithm */ 426 uchar_t decomp_alg_high; 427 uchar_t decomp_alg_low; 428 uchar_t decomp_alg_lsb; 429 uchar_t reservered0; 430 uchar_t reservered1; 431 uchar_t reservered2; 432 uchar_t reservered3; 433 #endif 434 }; 435 436 struct dev_mode_page { 437 #if defined(_BIT_FIELDS_LTOH) 438 uchar_t act_format: 5, /* active format */ 439 caf: 1, /* Change Active Format */ 440 cap: 1, /* Change Active Partition OBSOLETE */ 441 : 1; 442 uchar_t act_partition; /* active partition */ 443 uchar_t wrt_buf_full_ratio; /* write buffer full ratio */ 444 uchar_t rd_buf_full_ratio; /* read buffer full ratio */ 445 uchar_t wrt_delay_time_msb; /* write delay time MSB */ 446 uchar_t wrt_delay_time_lsb; /* write delay time LSB */ 447 uchar_t rew: 1, /* Report Early Warning */ 448 robo: 1, /* Reverse Object Buffer Order */ 449 socf: 2, /* Stop On Consecutive Filemarks */ 450 avc: 1, /* Automatic Velocity Control */ 451 rsmk: 1, /* Report SetMarKs OBSOLETE */ 452 lois: 1, /* Logical Object Identifiers Support */ 453 obr: 1; /* Object Buffer Recovery */ 454 uchar_t gap_size; /* OBSOLETE */ 455 uchar_t bam: 1, /* Block Address Mode */ 456 bmal: 1, /* Block Address Mode Lock */ 457 swp: 1, /* Software Write Protection */ 458 sew: 1, /* Sync data after Early Warning */ 459 eeg: 1, /* Enable Early Waring */ 460 eod_defined: 3; 461 uchar_t buf_size_leot_msb; /* Buffer size after early warning */ 462 uchar_t buf_size_leot_mid; 463 uchar_t buf_size_leot_lsb; 464 uchar_t comp_alg; /* Compression Algorithm (enable) */ 465 uchar_t prmwp: 1, /* PeRManent Write Protect */ 466 perswp: 1, /* persistant write protection */ 467 asocwp: 1, /* associated write protect */ 468 rew_on_rst: 2, /* rewind on reset */ 469 oir: 1, /* Only If Reserved */ 470 wtre: 2; /* Worm Tamper Read Enable */ 471 472 #elif defined(_BIT_FIELDS_HTOL) 473 uchar_t : 1, 474 cap: 1, /* Change Active Partition OBSOLETE */ 475 caf: 1, /* Change Active Format */ 476 act_format: 5; /* active format */ 477 uchar_t act_partition; /* active partition */ 478 uchar_t wrt_buf_full_ratio; /* write buffer full ratio */ 479 uchar_t rd_buf_full_ratio; /* read buffer full ratio */ 480 uchar_t wrt_delay_time_msb; /* write delay time MSB */ 481 uchar_t wrt_delay_time_lsb; /* write delay time LSB */ 482 uchar_t obr: 1, /* Object Buffer Recovery */ 483 lois: 1, /* Logical Object Identifiers Support */ 484 rsmk: 1, /* Report SetMarKs OBSOLETE */ 485 avc: 1, /* Automatic Velocity Control */ 486 socf: 2, /* Stop On Consecutive Filemarks */ 487 robo: 1, /* Reverse Object Buffer Order */ 488 rew: 1; /* Report Early Warning */ 489 uchar_t gap_size; /* OBSELETE */ 490 uchar_t eod_defined: 3, 491 eeg: 1, /* Enable Early Waring */ 492 sew: 1, /* Sync data after Early Warning */ 493 swp: 1, /* Software Write Protection */ 494 bmal: 1, /* Block Address Mode Lock */ 495 bam: 1; /* Block Address Mode */ 496 uchar_t buf_size_leot_msb; /* Buffer size after early warning */ 497 uchar_t buf_size_leot_mid; 498 uchar_t buf_size_leot_lsb; 499 uchar_t comp_alg; /* Compression Algorithm (enable) */ 500 uchar_t wtre: 2, /* Worm Tamper Read Enable */ 501 oir: 1, /* Only If Reserved */ 502 rew_on_rst: 2, /* rewind on reset */ 503 asocwp: 1, /* associated write protect */ 504 perswp: 1, /* persistant write protection */ 505 prmwp: 1; /* PeRManent Write Protect */ 506 #endif 507 }; 508 509 typedef union { 510 struct comp_mode_page comp; 511 struct dev_mode_page dev; 512 }modepage; 513 514 /* 515 * 516 * Parameter list for the MODE_SELECT and MODE_SENSE commands. 517 * The parameter list contains a header, followed by zero or more 518 * block descriptors, followed by vendor unique parameters, if any. 519 * 520 */ 521 #define MSIZE 0x0c /* Size without additional pages */ 522 struct seq_mode { 523 #if defined(_BIT_FIELDS_LTOH) 524 uchar_t data_len; /* sense data length, sense only */ 525 uchar_t media_type; /* medium type, sense only */ 526 uchar_t speed :4, /* speed */ 527 bufm :3, /* buffered mode */ 528 wp :1; /* write protected, sense only */ 529 uchar_t bd_len; /* block length in bytes */ 530 uchar_t density; /* density code */ 531 uchar_t high_nb; /* number of logical blocks on the medium */ 532 uchar_t mid_nb; /* that are to be formatted with the density */ 533 uchar_t low_nb; /* code and block length in block descriptor */ 534 uchar_t reserved; /* reserved */ 535 uchar_t high_bl; /* block length */ 536 uchar_t mid_bl; /* " " */ 537 uchar_t low_bl; /* " " */ 538 uchar_t page_code: 6, 539 : 1, 540 ps: 1; /* Page Savable sense only */ 541 uchar_t page_len; 542 modepage page; 543 544 #elif defined(_BIT_FIELDS_HTOL) 545 uchar_t data_len; /* sense data length, sense only */ 546 uchar_t media_type; /* medium type, sense only */ 547 uchar_t wp :1, /* write protected, sense only */ 548 bufm :3, /* buffered mode */ 549 speed :4; /* speed */ 550 uchar_t bd_len; /* block length in bytes */ 551 uchar_t density; /* density code */ 552 uchar_t high_nb; /* number of logical blocks on the medium */ 553 uchar_t mid_nb; /* that are to be formatted with the density */ 554 uchar_t low_nb; /* code and block length in block descriptor */ 555 uchar_t reserved; /* reserved */ 556 uchar_t high_bl; /* block length */ 557 uchar_t mid_bl; /* " " */ 558 uchar_t low_bl; /* " " */ 559 uchar_t ps: 1, /* Page Savable sense only */ 560 : 1, 561 page_code: 6; 562 uchar_t page_len; 563 modepage page; 564 #else 565 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 566 #endif /* _BIT_FIELDS_LTOH */ 567 }; 568 569 /* 570 * Data returned from the READ BLOCK LIMITS command. 571 */ 572 573 #define RBLSIZE (sizeof (struct read_blklim)) 574 struct read_blklim { 575 #if defined(_BIT_FIELDS_HTOL) 576 uchar_t reserved: 3; /* reserved */ 577 uchar_t granularity: 5; /* Minimum Modularity */ 578 #elif defined(_BIT_FIELDS_LTOH) 579 uchar_t granularity: 5; /* Minimum Modularity */ 580 uchar_t reserved: 3; /* reserved */ 581 #endif 582 uchar_t max_hi; /* Maximum block length, high byte */ 583 uchar_t max_mid; /* Maximum block length, middle byte */ 584 uchar_t max_lo; /* Maximum block length, low byte */ 585 uchar_t min_hi; /* Minimum block length, high byte */ 586 uchar_t min_lo; /* Minimum block length, low byte */ 587 }; 588 589 /* 590 * operation codes 591 */ 592 typedef enum { 593 ST_OP_NIL, 594 ST_OP_CTL, 595 ST_OP_READ, 596 ST_OP_WRITE, 597 ST_OP_WEOF 598 }optype; 599 600 /* 601 * eof/eot/eom codes. 602 */ 603 typedef enum { 604 ST_NO_EOF, 605 ST_EOF_PENDING, /* filemark pending */ 606 ST_EOF, /* at filemark */ 607 ST_EOT_PENDING, /* logical eot pending */ 608 ST_EOT, /* at logical eot */ 609 ST_EOM, /* at physical eot */ 610 ST_WRITE_AFTER_EOM /* flag for allowing writes after EOM */ 611 }pstatus; 612 613 typedef enum { invalid, legacy, logical } posmode; 614 615 typedef struct tapepos { 616 uint64_t lgclblkno; 617 int32_t fileno; 618 int32_t blkno; 619 int32_t partition; 620 pstatus eof; /* eof states */ 621 posmode pmode; 622 char pad[4]; 623 }tapepos_t; 624 625 /* byte 1 of cdb for type of read position command */ 626 typedef enum { 627 SHORT_POS = 0, 628 LONG_POS = 6, 629 EXT_POS = 8, 630 NO_POS = 0xff /* Drive doesn't support read position */ 631 } read_p_types; 632 633 634 /* 635 * Data returned from the READ POSITION command. 636 */ 637 638 typedef struct tape_position { 639 #if defined(_BIT_FIELDS_HTOL) 640 uchar_t begin_of_part: 1; 641 uchar_t end_of_part: 1; 642 uchar_t blk_cnt_unkwn: 1; 643 uchar_t byte_cnt_unkwn: 1; 644 uchar_t reserved0: 1; 645 uchar_t blk_posi_unkwn: 1; 646 uchar_t posi_err: 1; 647 uchar_t reserved1: 1; 648 #elif defined(_BIT_FIELDS_LTOH) 649 uchar_t reserved1: 1; 650 uchar_t posi_err: 1; 651 uchar_t blk_posi_unkwn: 1; 652 uchar_t reserved0: 1; 653 uchar_t byte_cnt_unkwn: 1; 654 uchar_t blk_cnt_unkwn: 1; 655 uchar_t end_of_part: 1; 656 uchar_t begin_of_part: 1; 657 #endif 658 uchar_t partition_number; 659 uchar_t reserved2[2]; 660 uint32_t host_block; 661 uint32_t media_block; 662 uchar_t reserved3; 663 uchar_t block_in_buff[3]; 664 uint32_t byte_in_buff; 665 }tape_position_t; 666 667 668 typedef struct tape_position_long { 669 #if defined(_BIT_FIELDS_HTOL) 670 uint32_t begin_of_part: 1; 671 uint32_t end_of_part: 1; 672 uint32_t reserved0: 2; 673 uint32_t mrk_posi_unkwn:1; 674 uint32_t blk_posi_unkwn:1; 675 uint32_t reserved1: 2; 676 #elif defined(_BIT_FIELDS_LTOH) 677 uint32_t reserved1: 2; 678 uint32_t blk_posi_unkwn:1; 679 uint32_t mrk_posi_unkwn:1; 680 uint32_t reserved0: 2; 681 uint32_t end_of_part: 1; 682 uint32_t begin_of_part: 1; 683 #endif 684 uint32_t reserved2: 24; 685 uint32_t partition; 686 uint64_t block_number; 687 uint64_t file_number; 688 uint64_t set_number; 689 }tape_position_long_t; 690 691 typedef struct tape_position_ext { 692 #if defined(_BIT_FIELDS_HTOL) 693 uint32_t begin_of_part: 1; 694 uint32_t end_of_part: 1; 695 uint32_t blk_cnt_unkwn: 1; 696 uint32_t byte_cnt_unkwn:1; 697 uint32_t mrk_posi_unkwn:1; 698 uint32_t blk_posi_unkwn:1; 699 uint32_t posi_err: 1; 700 uint32_t reserved0: 1; 701 uint32_t partition: 8; 702 uint32_t parameter_len: 16; 703 /* start next word */ 704 uint32_t reserved1: 8; 705 uint32_t blks_in_buf: 24; 706 #elif defined(_BIT_FIELDS_LTOH) 707 uint32_t parameter_len: 16; 708 uint32_t partition: 8; 709 uint32_t reserved0: 1; 710 uint32_t posi_err: 1; 711 uint32_t blk_posi_unkwn:1; 712 uint32_t mrk_posi_unkwn:1; 713 uint32_t byte_cnt_unkwn:1; 714 uint32_t blk_cnt_unkwn: 1; 715 uint32_t end_of_part: 1; 716 uint32_t begin_of_part: 1; 717 /* start next word */ 718 uint32_t blks_in_buf: 24; 719 uint32_t reserved1: 8; 720 #endif 721 uint64_t host_block; 722 uint64_t media_block; 723 uint64_t byte_in_buf; 724 }tape_position_ext_t; 725 726 typedef union { 727 tape_position_t srt; 728 tape_position_ext_t ext; 729 tape_position_long_t lng; 730 }read_pos_data_t; 731 732 #ifdef _KERNEL 733 734 #ifdef __x86 735 /* Data structure used in big block I/O on x86/x64 platform */ 736 737 /* 738 * alloc more than one contig_mem, so mutiple I/O can be 739 * on-going simultaneously 740 */ 741 #define ST_MAX_CONTIG_MEM_NUM 3 742 743 struct contig_mem { 744 struct contig_mem *cm_next; 745 size_t cm_len; 746 caddr_t cm_addr; 747 ddi_acc_handle_t cm_acc_hdl; 748 struct buf *cm_bp; 749 int cm_use_sbuf; 750 }; 751 752 #endif 753 754 #endif /* _KERNEL */ 755 756 /* 757 * driver states.. 758 */ 759 typedef enum { 760 ST_STATE_CLOSED, 761 ST_STATE_OFFLINE, 762 ST_STATE_INITIALIZING, 763 ST_STATE_OPENING, 764 ST_STATE_OPEN_PENDING_IO, 765 ST_STATE_APPEND_TESTING, 766 ST_STATE_OPEN, 767 ST_STATE_RESOURCE_WAIT, 768 ST_STATE_CLOSING, 769 ST_STATE_SENSING, 770 ST_STATE_CLOSE_PENDING_OPEN 771 }st_states; 772 773 typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity; 774 775 776 /* 777 * Private info for scsi tapes. Pointed to by the un_private pointer 778 * of one of the SCSI_DEVICE chains. 779 */ 780 781 struct scsi_tape { 782 struct scsi_device *un_sd; /* back pointer to SCSI_DEVICE */ 783 struct scsi_pkt *un_rqs; /* ptr to request sense command */ 784 struct scsi_pkt *un_mkr_pkt; /* ptr to marker packet */ 785 kcondvar_t un_sbuf_cv; /* cv on ownership of special buf */ 786 kcondvar_t un_queue_cv; /* cv on all queued commands */ 787 struct buf *un_sbufp; /* for use in special io */ 788 char *un_srqbufp; /* sense buffer for special io */ 789 kcondvar_t un_clscv; /* closing cv */ 790 struct buf *un_quef; /* head of wait queue */ 791 struct buf *un_quel; /* tail of wait queue */ 792 struct buf *un_runqf; /* head of run queue */ 793 struct buf *un_runql; /* tail of run queue */ 794 struct seq_mode *un_mspl; /* ptr to mode select info */ 795 struct st_drivetype *un_dp; /* ptr to drive table entry */ 796 uint_t un_dp_size; /* size of un_dp alloc'ed */ 797 caddr_t un_tmpbuf; /* buf for append, autodens ops */ 798 tapepos_t un_pos; /* Current tape position */ 799 int un_oflags; /* open flags */ 800 tapepos_t un_err_pos; /* block in file where err occurred */ 801 uint_t un_err_resid; /* resid from last error */ 802 short un_fmneeded; /* filemarks to be written - HP only */ 803 dev_t un_dev; /* unix device */ 804 uchar_t un_attached; /* unit known && attached */ 805 int un_pwr_mgmt; /* power management state */ 806 uchar_t un_density_known; /* density is known */ 807 uchar_t un_curdens; /* index into density table */ 808 optype un_lastop; /* last I/O was: read/write/ctl */ 809 st_states un_laststate; /* last state */ 810 st_states un_state; /* current state */ 811 uchar_t un_status; /* status from last sense */ 812 uchar_t un_retry_ct; /* retry count */ 813 uchar_t un_tran_retry_ct; /* transport retry count */ 814 writablity un_read_only; /* RDWR, RDONLY, WORM, RDWORM */ 815 uchar_t un_test_append; /* check writing at end of tape */ 816 uchar_t un_arq_enabled; /* auto request sense enabled */ 817 uchar_t un_untagged_qing; /* hba has untagged quing */ 818 uchar_t un_allow_large_xfer; /* allow >64k xfers if requested */ 819 uchar_t un_sbuf_busy; /* sbuf busy flag */ 820 uchar_t un_ncmds; /* number of commands outstanding */ 821 uchar_t un_throttle; /* curr. max number of cmds outst. */ 822 uchar_t un_last_throttle; /* saved max number of cmds outst. */ 823 uchar_t un_max_throttle; /* max poss. number cmds outstanding */ 824 uchar_t un_persistence; /* 1 = persistence on, 0 off */ 825 uchar_t un_persist_errors; /* 1 = persistenced flagged */ 826 uchar_t un_flush_on_errors; /* HBA will flush all I/O's on a */ 827 /* check condidtion or error */ 828 uint_t un_kbytes_xferred; /* bytes (in K) counter */ 829 uint_t un_last_resid; /* keep last resid, for PE */ 830 uint_t un_last_count; /* keep last count, for PE */ 831 struct kstat *un_stats; /* for I/O statistics */ 832 struct buf *un_rqs_bp; /* bp used in rqpkt */ 833 struct buf *un_wf; /* head of write queue */ 834 struct buf *un_wl; /* tail of write queue */ 835 struct read_blklim *un_rbl; /* ptr to read block limit info */ 836 int un_maxdma; /* max dma xfer allowed by HBA */ 837 uint_t un_bsize; /* block size currently being used */ 838 int un_maxbsize; /* max block size allowed by drive */ 839 uint_t un_minbsize; /* min block size allowed by drive */ 840 int un_errno; /* errno (b_error) */ 841 kcondvar_t un_state_cv; /* mediastate condition variable */ 842 enum mtio_state un_mediastate; /* current media state */ 843 enum mtio_state un_specified_mediastate; /* expected state */ 844 timeout_id_t un_delay_tid; /* delayed cv tid */ 845 timeout_id_t un_hib_tid; /* handle interrupt busy tid */ 846 opaque_t un_swr_token; /* scsi_watch request token */ 847 uchar_t un_comp_page; /* compression page */ 848 uchar_t un_rsvd_status; /* Reservation Status */ 849 kstat_t *un_errstats; /* for error statistics */ 850 int un_init_options; /* Init time drive options */ 851 int un_save_fileno; /* Save here for recovery */ 852 daddr_t un_save_blkno; /* Save here for recovery */ 853 uchar_t un_restore_pos; /* Indication to do recovery */ 854 tapepos_t un_suspend_pos; /* Save blkno for SUSPEND */ 855 uchar_t un_silent_skip; /* to catch short reads */ 856 short un_tids_at_suspend; /* timeouts set at suspend */ 857 kcondvar_t un_tape_busy_cv; /* busy cv */ 858 kcondvar_t un_suspend_cv; /* busy cv */ 859 /* restore on close */ 860 uchar_t un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */ 861 uchar_t un_HeadClean; /* support and need head cleaning? */ 862 uchar_t un_rqs_state; /* see define below */ 863 struct scsi_extended_sense 864 *un_uscsi_rqs_buf; /* uscsi_rqs: buffer for RQS data */ 865 uchar_t un_data_mod; /* Device required data mod */ 866 writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */ 867 int un_max_cdb_sz; /* max cdb size to use */ 868 read_p_types un_read_pos_type; 869 read_pos_data_t *un_read_pos_data; 870 struct mterror_entry_stack *un_error_entry_stk; 871 /* latest sense cmd buffer */ 872 873 #ifdef __x86 874 ddi_dma_handle_t un_contig_mem_hdl; 875 struct contig_mem *un_contig_mem; 876 int un_contig_mem_available_num; 877 int un_contig_mem_total_num; 878 size_t un_max_contig_mem_len; 879 kcondvar_t un_contig_mem_cv; 880 int un_maxdma_arch; /* max dma xfer allowed by HBA & arch */ 881 #endif 882 }; 883 884 885 /* 886 * device error kstats 887 */ 888 struct st_errstats { 889 struct kstat_named st_softerrs; 890 struct kstat_named st_harderrs; 891 struct kstat_named st_transerrs; 892 struct kstat_named st_vid; 893 struct kstat_named st_pid; 894 struct kstat_named st_revision; 895 struct kstat_named st_serial; 896 }; 897 898 /* 899 * generic log page struct 900 */ 901 struct log_page { 902 #if defined(_BIT_FIELDS_LTOH) 903 uchar_t code :6, /* page code number */ 904 :2; /* reserved */ 905 #elif defined(_BIT_FIELDS_HTOL) 906 uchar_t :2, /* reserved */ 907 code :6; /* page code number */ 908 #endif /* _BIT_FIELDS_LTOH */ 909 uchar_t reserved; /* reserved */ 910 uchar_t length_hi; /* length of bytes to follow (msb) */ 911 uchar_t length_lo; /* length of bytes to follow (lsb) */ 912 /* 913 * Log parameters follow right after this... 914 */ 915 }; 916 917 /* 918 * generic log page parameter struct 919 */ 920 struct log_param { 921 uchar_t pc_hi; /* parameter code (msb) */ 922 uchar_t pc_lo; /* parameter code (lsb) */ 923 #if defined(_BIT_FIELDS_LTOH) 924 uchar_t lp : 1, /* list parameter */ 925 : 1, /* reserved */ 926 tmc : 2, /* threshold met criteria */ 927 etc : 1, /* enable threshold comparison */ 928 tsd : 1, /* target save disable */ 929 ds : 1, /* disable save */ 930 du : 1; /* disable update */ 931 #elif defined(_BIT_FIELDS_HTOL) 932 uchar_t du : 1, /* disable update */ 933 ds : 1, /* disable save */ 934 tsd : 1, /* target save disable */ 935 etc : 1, /* enable threshold comparison */ 936 tmc : 2, /* threshold met criteria */ 937 : 1, /* reserved */ 938 lp : 1; /* list parameter */ 939 #endif /* _BIT_FIELDS_LTOH */ 940 uchar_t length; /* length of bytes to follow */ 941 /* 942 * Parameter values follow right after this... 943 */ 944 }; 945 /* 946 * TapeAlert structures 947 */ 948 949 struct st_tape_alert_parameter { 950 struct log_param log_param; 951 uchar_t param_value; 952 }; 953 954 struct st_tape_alert { 955 struct log_page log_page; 956 struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA]; 957 }; 958 959 #define TAPE_ALERT_PARAMETER_LENGTH \ 960 (sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA 961 962 struct log_sequential_page_parameter { 963 struct log_param log_param; 964 uchar_t param_value[8]; 965 }; 966 967 struct log_sequential_page { 968 struct log_page log_page; 969 struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA]; 970 }; 971 972 #if !defined(__lint) 973 _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape)) 974 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp)) 975 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd)) 976 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs)) 977 _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp)) 978 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize)) 979 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status)) 980 _NOTE(SCHEME_PROTECTS_DATA("save sharing", 981 scsi_tape::un_allow_large_xfer 982 scsi_tape::un_maxbsize 983 scsi_tape::un_maxdma 984 )) 985 #ifdef __x86 986 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl)) 987 _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem)) 988 #endif 989 #endif 990 991 992 /* 993 * Power management state 994 */ 995 #define ST_PWR_NORMAL 0 996 #define ST_PWR_SUSPENDED 1 997 998 999 #define IN_EOF(pos) (pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF) 1000 1001 /* un_rqs_state codes */ 1002 1003 #define ST_RQS_OVR 0x1 /* RQS data was overwritten */ 1004 #define ST_RQS_VALID 0x2 /* RQS data is valid */ 1005 #define ST_RQS_READ 0x4 /* RQS data was read */ 1006 #define ST_RQS_ERROR 0x8 /* RQS resulted in an EIO */ 1007 1008 /* 1009 * stintr codes 1010 */ 1011 1012 #define COMMAND_DONE 0 1013 #define COMMAND_DONE_ERROR 1 1014 #define COMMAND_DONE_ERROR_RECOVERED 2 1015 #define QUE_COMMAND 3 1016 #define QUE_BUSY_COMMAND 4 1017 #define QUE_SENSE 5 1018 #define JUST_RETURN 6 1019 #define COMMAND_DONE_EACCES 7 1020 #define QUE_LAST_COMMAND 8 1021 1022 1023 /* 1024 * Reservation Status 1025 * 1026 * ST_INIT_RESERVE -Used to check if the reservation has been lost 1027 * in between opens and also to indicate the reservation 1028 * has not been done till now. 1029 * ST_RELEASE -Tape Unit is Released. 1030 * ST_RESERVE -Tape Unit is Reserved. 1031 * ST_PRESERVE_RESERVE -Reservation is to be preserved across opens. 1032 * 1033 */ 1034 #define ST_INIT_RESERVE 0x001 1035 #define ST_RELEASE 0x002 1036 #define ST_RESERVE 0x004 1037 #define ST_PRESERVE_RESERVE 0x008 1038 #define ST_RESERVATION_CONFLICT 0x010 1039 #define ST_LOST_RESERVE 0x020 1040 #define ST_APPLICATION_RESERVATIONS 0x040 1041 #define ST_LOST_RESERVE_BETWEEN_OPENS \ 1042 (ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE) 1043 1044 /* 1045 * Service action defines for Persistant Reservation Commands 1046 */ 1047 #define ST_SA_SCSI3_REGISTER 0x00 1048 #define ST_SA_SCSI3_RESERVE 0x01 1049 #define ST_SA_SCSI3_RELEASE 0x02 1050 #define ST_SA_SCSI3_CLEAR 0x03 1051 #define ST_SA_SCSI3_PREEMPT 0x04 1052 #define ST_SA_SCSI3_PREEMPTANDABORT 0x05 1053 #define ST_SA_SCSI3_REGISTERANDIGNOREKEY 0x06 1054 #define ST_SA_MASK 0x1f 1055 1056 #define ST_RESERVATION_DELAY 500000 1057 1058 /* 1059 * Asynch I/O tunables 1060 */ 1061 #define ST_MAX_THROTTLE 4 1062 1063 /* 1064 * 60 minutes seems a reasonable amount of time 1065 * to wait for tape space operations to complete. 1066 * 1067 */ 1068 #define ST_SPACE_TIME MINUTES(60) /* 60 minutes per space operation */ 1069 #define ST_LONG_SPACE_TIME_X 5 /* multipiler for long space ops */ 1070 1071 /* 1072 * 2 minutes seems a reasonable amount of time 1073 * to wait for tape i/o operations to complete. 1074 * 1075 */ 1076 #define ST_IO_TIME MINUTES(2) /* minutes per i/o */ 1077 #define ST_LONG_TIMEOUT_X 5 /* multiplier for very long timeouts */ 1078 1079 1080 /* 1081 * 10 seconds is what we'll wait if we get a Busy Status back 1082 */ 1083 #define ST_STATUS_BUSY_TIMEOUT 10*hz /* seconds Busy Waiting */ 1084 #define ST_TRAN_BUSY_TIMEOUT 1*hz /* seconds retry on TRAN_BSY */ 1085 #define ST_INTERRUPT_CONTEXT 1 1086 #define ST_START_CONTEXT 2 1087 1088 /* 1089 * Number of times we'll retry a normal operation. 1090 * 1091 * XXX This includes retries due to transport failure as well as 1092 * XXX busy timeouts- Need to distinguish between Target and Transport 1093 * XXX failure. 1094 */ 1095 1096 #define ST_RETRY_COUNT 20 1097 1098 /* 1099 * Number of times to retry a failed selection 1100 */ 1101 #define ST_SEL_RETRY_COUNT 2 1102 1103 /* 1104 * es_code value for deferred error 1105 * should be moved to sense.h 1106 */ 1107 1108 #define ST_DEFERRED_ERROR 0x01 1109 1110 /* 1111 * Maximum number of units (determined by minor device byte) 1112 */ 1113 #define ST_MAXUNIT 128 1114 1115 /* 1116 * Time to wait for completion of a command before cancelling it. 1117 * For SUSPEND use only 1118 */ 1119 #define ST_WAIT_CMDS_COMPLETE 10 /* seconds */ 1120 1121 #ifndef SECSIZE 1122 #define SECSIZE 512 1123 #endif 1124 #ifndef SECDIV 1125 #define SECDIV 9 1126 #endif 1127 1128 /* 1129 * convenient defines 1130 */ 1131 #define ST_SCSI_DEVP (un->un_sd) 1132 #define ST_DEVINFO (ST_SCSI_DEVP->sd_dev) 1133 #define ST_INQUIRY (ST_SCSI_DEVP->sd_inq) 1134 #define ST_RQSENSE (ST_SCSI_DEVP->sd_sense) 1135 #define ST_MUTEX (&ST_SCSI_DEVP->sd_mutex) 1136 #define ROUTE (&ST_SCSI_DEVP->sd_address) 1137 1138 #define BSD_BEHAVIOR (getminor(un->un_dev) & MT_BSD) 1139 #define SVR4_BEHAVIOR ((getminor(un->un_dev) & MT_BSD) == 0) 1140 #define SCBP(pkt) ((struct scsi_status *)(pkt)->pkt_scbp) 1141 #define SCBP_C(pkt) ((*(pkt)->pkt_scbp) & STATUS_MASK) 1142 #define CDBP(pkt) ((union scsi_cdb *)(pkt)->pkt_cdbp) 1143 #define BP_PKT(bp) ((struct scsi_pkt *)(bp)->av_back) 1144 #define SET_BP_PKT(bp, pkt) ((bp)->av_back = (struct buf *)(pkt)) 1145 #define BP_UCMD(bp) ((struct uscsi_cmd *)(bp)->b_back) 1146 #define USCSI_CMD(bp) (((bp) == un->un_sbufp) && (BP_UCMD(bp))) 1147 1148 #define IS_CLOSING(un) ((un)->un_state == ST_STATE_CLOSING || \ 1149 ((un)->un_state == ST_STATE_SENSING && \ 1150 (un)->un_laststate == ST_STATE_CLOSING)) 1151 1152 #define ASYNC_CMD 0 1153 #define SYNC_CMD 1 1154 1155 /* 1156 * Flush tape wait queue as needed. 1157 */ 1158 1159 #define IS_PE_FLAG_SET(un) ((un)->un_persistence && (un)->un_persist_errors) 1160 1161 #define TURN_PE_ON(un) st_turn_pe_on(un) 1162 #define TURN_PE_OFF(un) st_turn_pe_off(un) 1163 #define SET_PE_FLAG(un) st_set_pe_flag(un) 1164 #define CLEAR_PE(un) st_clear_pe(un) 1165 1166 #define st_bioerror(bp, error) \ 1167 { bioerror(bp, error); \ 1168 un->un_errno = error; } 1169 1170 /* 1171 * Macros for internal coding of count for SPACE command: 1172 * 1173 * Isfmk is 1 when spacing filemarks; 0 when spacing records: 1174 * bit 24 set indicates a space filemark command. 1175 * Fmk sets the filemark bit (24) and changes a backspace 1176 * count into a positive number with the sign bit set. 1177 * Blk changes a backspace count into a positive number with 1178 * the sign bit set. 1179 * space_cnt converts backwards counts to negative numbers. 1180 */ 1181 #define SP_BLK 0 1182 #define SP_FLM ((1<<24)) 1183 #define SP_SQFLM ((2<<24)) 1184 #define SP_EOD ((3<<24)) 1185 #define SP_BACKSP ((1<<30)) 1186 #define SP_CMD_MASK ((7<<24)) 1187 #define SP_CNT_MASK ((1<<24)-1) 1188 1189 /* Macros to assemble space cmds */ 1190 #define SPACE(cmd, cnt) ((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt)) 1191 #define Fmk(x) SPACE(SP_FLM, x) 1192 #define Blk(x) SPACE(SP_BLK, x) 1193 1194 /* Macros to interpret space cmds */ 1195 #define SPACE_CNT(x) (((x) & SP_BACKSP)? \ 1196 (-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK)) 1197 #define SPACE_TYPE(x) ((x & SP_CMD_MASK)>>24) 1198 1199 1200 /* Defines for byte 4 of load/unload cmd */ 1201 #define LD_UNLOAD 0 1202 #define LD_LOAD 1 1203 #define LD_RETEN 2 1204 #define LD_EOT 4 1205 #define LD_HOLD 8 1206 1207 /* Defines for byte 4 of prevent/allow media removal */ 1208 #define MR_UNLOCK 0 1209 #define MR_LOCK 1 1210 1211 #define GET_SOFT_STATE(dev) \ 1212 register struct scsi_tape *un; \ 1213 register int instance; \ 1214 \ 1215 instance = MTUNIT(dev); \ 1216 if ((un = ddi_get_soft_state(st_state, instance)) == NULL) \ 1217 return (ENXIO); 1218 1219 /* 1220 * Debugging turned on via conditional compilation switch -DSTDEBUG 1221 */ 1222 #ifdef DEBUG 1223 #define STDEBUG 1224 #endif 1225 1226 #ifdef STDEBUG 1227 #define DEBUGGING ((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0xf)) 1228 1229 #define ST_DARGS st_label, SCSI_DEBUG 1230 1231 1232 /* initialization */ 1233 #define ST_DEBUG1 if ((st_debug & 0xf) >= 1) scsi_log 1234 #define ST_DEBUG ST_DEBUG1 1235 1236 /* errors and UA's */ 1237 #define ST_DEBUG2 if ((st_debug & 0xf) >= 2) scsi_log 1238 1239 /* func calls */ 1240 #define ST_DEBUG3 if ((st_debug & 0xf) >= 3) scsi_log 1241 1242 /* ioctl calls */ 1243 #define ST_DEBUG4 if ((st_debug & 0xf) >= 4) scsi_log 1244 1245 #define ST_DEBUG5 if ((st_debug & 0xf) >= 5) scsi_log 1246 1247 /* full data tracking */ 1248 #define ST_DEBUG6 if ((st_debug & 0xf) >= 6) scsi_log 1249 1250 /* special cases */ 1251 #define ST_DEBUG_SP if ((st_debug & 0xf) == 10) scsi_log 1252 1253 /* Entry Point Functions */ 1254 #define ST_ENTR(d, fn) if (st_debug & 0x10) scsi_log(d, ST_DARGS, #fn) 1255 1256 /* Non-Entry Point Functions */ 1257 #define ST_FUNC(d, fn) if (st_debug & 0x20) scsi_log(d, ST_DARGS, #fn) 1258 1259 /* Space Information */ 1260 #define ST_SPAC if (st_debug & 0x40) scsi_log 1261 1262 /* CDB's sent */ 1263 #define ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) \ 1264 st_print_cdb(d, ST_DARGS, cmnt, cdb) 1265 #define ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) \ 1266 st_clean_print(d, ST_DARGS, cmnt, sense, size) 1267 1268 #else 1269 1270 #define st_debug (0) 1271 #define DEBUGGING (0) 1272 #define ST_DEBUG if (0) scsi_log 1273 #define ST_DEBUG1 if (0) scsi_log 1274 #define ST_DEBUG2 if (0) scsi_log 1275 #define ST_DEBUG3 if (0) scsi_log 1276 #define ST_DEBUG4 if (0) scsi_log 1277 #define ST_DEBUG5 if (0) scsi_log 1278 #define ST_DEBUG6 if (0) scsi_log 1279 1280 #define ST_DEBUG_SP if (0) scsi_log /* special cases */ 1281 1282 #define ST_ENTR(d, fn) 1283 #define ST_FUNC(d, fn) 1284 #define ST_SPAC if (0) scsi_log 1285 #define ST_CDB(d, cmnt, cdb) 1286 #define ST_SENSE(d, cmnt, sense, size) 1287 1288 #endif 1289 1290 /* 1291 * Media access values 1292 */ 1293 #define MEDIA_ACCESS_DELAY 5000000 /* usecs wait for media state change */ 1294 1295 /* 1296 * SCSI tape mode sense page information 1297 */ 1298 #define ST_DEV_CONFIG_PAGE 0x10 /* device config mode page */ 1299 #define ST_DEV_CONFIG_NO_COMP 0x00 /* use no compression */ 1300 #define ST_DEV_CONFIG_DEF_COMP 0x01 /* use default compression alg */ 1301 #define ST_COMPRESSION_DENSITY 3 /* compression minor number */ 1302 1303 /* 1304 * SCSI tape data compression Page definition. 1305 */ 1306 #define ST_DEV_DATACOMP_PAGE 0x0F /* data compression page */ 1307 1308 1309 1310 /* 1311 * maxbsize values 1312 */ 1313 #define MAXBSIZE_UNKNOWN -2 /* not found yet */ 1314 1315 #define ONE_MEG (1024 * 1024) 1316 1317 /* 1318 * generic soft error reporting 1319 * 1320 * What we are doing here is allowing a greater number of errors to occur on 1321 * smaller transfers (i.e. usually at the beginning of the tape), than on 1322 * the rest of the tape. 1323 * 1324 * A small transfer is defined as : 1325 * Transfers <= SOFT_ERROR_WARNING_THRESHOLD allow about 1.5 times more errors 1326 * 1327 * A larget tranfer is defined as : 1328 * Transfers > SOFT_ERROR_WARNING_THRESHOLD allow normal amount 1329 * 1330 */ 1331 #define READ_SOFT_ERROR_WARNING_THRESHOLD (25 * ONE_MEG) 1332 #define WRITE_SOFT_ERROR_WARNING_THRESHOLD (20 * ONE_MEG) 1333 1334 /* 1335 * soft error reporting for exabyte 1336 */ 1337 #define TAPE_SENSE_LENGTH 32 /* allows for softerror info */ 1338 1339 #define SENSE_19_BITS \ 1340 "\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT" 1341 #define SENSE_20_BITS \ 1342 "\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW" 1343 #define SENSE_21_BITS \ 1344 "\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0" 1345 1346 /* these are defined in percentages */ 1347 #define EXABYTE_WRITE_ERROR_THRESHOLD 6 1348 #define EXABYTE_READ_ERROR_THRESHOLD 3 1349 /* 1350 * minumum amount of data transfer(MB) for checking soft error rate. 1351 */ 1352 #define EXABYTE_MIN_TRANSFER (25 * ONE_MEG) 1353 1354 #define CLN 0x8 1355 #define CLND 0x10 1356 1357 /* 1358 * soft error reporting for Archive 4mm DAT 1359 */ 1360 1361 #define LOG_SENSE_LENGTH 0xff 1362 #define MIN_LOG_SENSE_LENGTH 0x2b 1363 #define DAT_SMALL_WRITE_ERROR_THRESHOLD 40 /* retries per 20 mg */ 1364 #define DAT_LARGE_WRITE_ERROR_THRESHOLD 200 /* retries for more 20 mg */ 1365 #define DAT_SMALL_READ_ERROR_THRESHOLD 5 /* errors allowed */ 1366 #define DAT_LARGE_READ_ERROR_THRESHOLD 3 /* errors allowed */ 1367 1368 /* 1369 * ST timeouts that need to be cancelled for suspend 1370 */ 1371 #define ST_HIB_TID 0x01 1372 #define ST_DELAY_TID 0x02 1373 1374 #ifdef __cplusplus 1375 } 1376 #endif 1377 1378 #endif /* _SYS_SCSI_TARGETS_STDEF_H */ 1379