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