xref: /onnv-gate/usr/src/uts/common/sys/scsi/targets/stdef.h (revision 5628:ddcf8536c1f9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51697Srralphs  * Common Development and Distribution License (the "License").
61697Srralphs  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
224549Srralphs  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_STDEF_H
270Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_STDEF_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
31177Scz147101 #include <sys/sunddi.h>
320Sstevel@tonic-gate #include <sys/note.h>
330Sstevel@tonic-gate #include <sys/condvar.h>
340Sstevel@tonic-gate #include <sys/kstat.h>
35*5628Srralphs #include <sys/int_limits.h>
360Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
374549Srralphs #include <sys/scsi/generic/sense.h>
380Sstevel@tonic-gate #include <sys/mtio.h>
39*5628Srralphs #include <sys/taskq.h>
40*5628Srralphs #include <sys/taskq_impl.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * Defines for SCSI tape drives.
480Sstevel@tonic-gate  */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Maximum variable length record size for a single request
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE	65535
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
570Sstevel@tonic-gate  * then the following define is used.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
620Sstevel@tonic-gate #define	INF 1000000000
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * Supported tape device types plus default type for opening.
660Sstevel@tonic-gate  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
670Sstevel@tonic-gate  * Types 14 - 1f, are 1/4-inch cartridge drives.
680Sstevel@tonic-gate  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
690Sstevel@tonic-gate  * Types 28+, are rdat (vcr) drives.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate #define	ST_TYPE_INVALID		0x00
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
740Sstevel@tonic-gate #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
770Sstevel@tonic-gate #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
780Sstevel@tonic-gate #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
790Sstevel@tonic-gate #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
820Sstevel@tonic-gate #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
830Sstevel@tonic-gate #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
840Sstevel@tonic-gate #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
850Sstevel@tonic-gate #define	ST_TYPE_HP	MT_ISHP		/* HP */
860Sstevel@tonic-gate #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
870Sstevel@tonic-gate #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
880Sstevel@tonic-gate #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
910Sstevel@tonic-gate #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
920Sstevel@tonic-gate #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
930Sstevel@tonic-gate #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
940Sstevel@tonic-gate #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
950Sstevel@tonic-gate #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
960Sstevel@tonic-gate #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
970Sstevel@tonic-gate #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
980Sstevel@tonic-gate #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
990Sstevel@tonic-gate #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
1000Sstevel@tonic-gate #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
1012537Srralphs #define	ST_TYPE_AIT	MT_ISAIT	/* Sony AIT I, II, III and SAIT */
1022537Srralphs #define	ST_LAST_TYPE	ST_TYPE_AIT	/* Add new above type and change this */
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /* Internal flags */
1060Sstevel@tonic-gate #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
1070Sstevel@tonic-gate 					/* alloc'ed from the st.conf entry, */
1080Sstevel@tonic-gate 					/* instead of being used from the */
1090Sstevel@tonic-gate 					/* st_drivetypes array. */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * Defines for supported drive options
1130Sstevel@tonic-gate  *
1140Sstevel@tonic-gate  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
1150Sstevel@tonic-gate  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate #define	ST_VARIABLE		0x001	/* Device supports variable	*/
1180Sstevel@tonic-gate 					/* length record sizes		*/
1190Sstevel@tonic-gate #define	ST_QIC			0x002	/* QIC tape device 		*/
1200Sstevel@tonic-gate #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
1210Sstevel@tonic-gate #define	ST_BSF			0x008	/* Device supports backspace	*/
1220Sstevel@tonic-gate 					/* file as in mt(1) bsf : 	*/
1230Sstevel@tonic-gate 					/* backspace over EOF marks.	*/
1240Sstevel@tonic-gate 					/* Devices not supporting bsf 	*/
1250Sstevel@tonic-gate 					/* will fail with ENOTTY upon	*/
1260Sstevel@tonic-gate 					/* use of bsf			*/
1270Sstevel@tonic-gate #define	ST_BSR			0x010	/* Device supports backspace	*/
1280Sstevel@tonic-gate 					/* record as in mt(1) bsr :	*/
1290Sstevel@tonic-gate 					/* backspace over records. If	*/
1300Sstevel@tonic-gate 					/* the device does not support 	*/
1310Sstevel@tonic-gate 					/* bsr, the st driver emulates	*/
1320Sstevel@tonic-gate 					/* the action by rewinding the	*/
1330Sstevel@tonic-gate 					/* tape and using forward space	*/
1340Sstevel@tonic-gate 					/* file (fsf) to the correct	*/
1350Sstevel@tonic-gate 					/* file and then uses forward	*/
1360Sstevel@tonic-gate 					/* space record (fsr) to the	*/
1370Sstevel@tonic-gate 					/* correct  record		*/
1380Sstevel@tonic-gate #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
1390Sstevel@tonic-gate 					/* than normal to erase		*/
1400Sstevel@tonic-gate #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
1410Sstevel@tonic-gate 					/* Device can figure out the	*/
1420Sstevel@tonic-gate 					/* tape density automatically,	*/
1430Sstevel@tonic-gate 					/* without issuing a		*/
1440Sstevel@tonic-gate 					/* mode-select/mode-sense 	*/
1450Sstevel@tonic-gate #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
1460Sstevel@tonic-gate 					/* This disables the device's	*/
1470Sstevel@tonic-gate 					/* ability for buffered	writes	*/
1480Sstevel@tonic-gate 					/* I.e. The device acknowledges	*/
1490Sstevel@tonic-gate 					/* write completion after the	*/
1500Sstevel@tonic-gate 					/* data is written to the	*/
1510Sstevel@tonic-gate 					/* device's buffer, but before	*/
1520Sstevel@tonic-gate 					/* all the data is actually	*/
1530Sstevel@tonic-gate 					/* written to tape		*/
1540Sstevel@tonic-gate #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
1550Sstevel@tonic-gate 					/* parity while talking to it. 	*/
1560Sstevel@tonic-gate #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
1570Sstevel@tonic-gate 					/* of Data) has been reached.	*/
1580Sstevel@tonic-gate 					/* If the device knows EOD, st	*/
1590Sstevel@tonic-gate 					/* uses fast file skipping.	*/
1600Sstevel@tonic-gate 					/* If it does not know EOD,	*/
1610Sstevel@tonic-gate 					/* file skipping happens one	*/
1620Sstevel@tonic-gate 					/* file at a time. 		*/
1630Sstevel@tonic-gate #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
1640Sstevel@tonic-gate 					/* the st driver is unloaded &	*/
1650Sstevel@tonic-gate 					/* loaded again; e.g. will	*/
1660Sstevel@tonic-gate 					/* return the correct inquiry	*/
1670Sstevel@tonic-gate 					/* string			*/
1680Sstevel@tonic-gate #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
1690Sstevel@tonic-gate 					/* close to report soft errors.	*/
1700Sstevel@tonic-gate 					/* Currently only Exabyte and	*/
1710Sstevel@tonic-gate 					/* DAT drives support this	*/
1720Sstevel@tonic-gate 					/* feature.  			*/
1730Sstevel@tonic-gate #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
1740Sstevel@tonic-gate 					/* timeouts for normal		*/
1750Sstevel@tonic-gate 					/* operation			*/
1760Sstevel@tonic-gate #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
1770Sstevel@tonic-gate 					/* driver and pre-acked to the	*/
1780Sstevel@tonic-gate 					/* application 			*/
1790Sstevel@tonic-gate #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
1800Sstevel@tonic-gate 					/* devices only. If flag is	*/
1810Sstevel@tonic-gate 					/* set, then don't limit	*/
1820Sstevel@tonic-gate 					/* record size to 64k as in	*/
1830Sstevel@tonic-gate 					/* pre-Solaris 2.4 releases.	*/
1840Sstevel@tonic-gate 					/* The only limit on the	*/
1850Sstevel@tonic-gate 					/* record size will be the max	*/
1860Sstevel@tonic-gate 					/* record size the device can	*/
1870Sstevel@tonic-gate 					/* handle or the max DMA	*/
1880Sstevel@tonic-gate 					/* transfer size of the		*/
1890Sstevel@tonic-gate 					/* machine, which ever is	*/
1900Sstevel@tonic-gate 					/* smaller. Beware of		*/
1910Sstevel@tonic-gate 					/* incompatabilities with	*/
1920Sstevel@tonic-gate 					/* tapes of pre-Solaris 2.4	*/
1930Sstevel@tonic-gate 					/* OS's written with large	*/
1940Sstevel@tonic-gate 					/* (>64k) block sizes, as	*/
1950Sstevel@tonic-gate 					/* their true block size is	*/
1960Sstevel@tonic-gate 					/* a max of approx 64k		*/
1970Sstevel@tonic-gate #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
1980Sstevel@tonic-gate 					/* configuration page (0x10) to */
1990Sstevel@tonic-gate 					/* enable/disable compression	*/
2000Sstevel@tonic-gate 					/* instead of density codes for */
2010Sstevel@tonic-gate 					/* the "c" and "u" devices	*/
2020Sstevel@tonic-gate #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
2030Sstevel@tonic-gate 					/* support RESERVE/RELEASE SCSI	*/
2040Sstevel@tonic-gate 					/* command. If this is enabled	*/
2050Sstevel@tonic-gate 					/* then reserve/release would	*/
2060Sstevel@tonic-gate 					/* not be used during open/	*/
2070Sstevel@tonic-gate 					/* close for High Availability	*/
2080Sstevel@tonic-gate #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
2090Sstevel@tonic-gate 					/* to variable block devices 	*/
2100Sstevel@tonic-gate 					/* which support the SILI bit	*/
2110Sstevel@tonic-gate 					/* option. It indicates that 	*/
2120Sstevel@tonic-gate 					/* the SILI bit will be ignored */
2130Sstevel@tonic-gate 					/* during reads  		*/
2140Sstevel@tonic-gate #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
2150Sstevel@tonic-gate 					/* EOF marks do not indicate an */
2160Sstevel@tonic-gate 					/* EOM. This option is only	*/
2170Sstevel@tonic-gate 					/* supported on 1/2" reel tapes */
2180Sstevel@tonic-gate #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
2190Sstevel@tonic-gate 					/* EXABYTE 8mm tape drives 	*/
2200Sstevel@tonic-gate 					/* which support short 		*/
2210Sstevel@tonic-gate 					/* filemarks. When this flag 	*/
2220Sstevel@tonic-gate 					/* is set, short filemarks 	*/
2230Sstevel@tonic-gate 					/* will be used for writing	*/
2240Sstevel@tonic-gate 					/* filemarks. 			*/
2250Sstevel@tonic-gate #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
2260Sstevel@tonic-gate 					/* and the tape is trapped in   */
2270Sstevel@tonic-gate 					/* the medium changer, the tape */
2280Sstevel@tonic-gate 					/* is automatically ejected	*/
2290Sstevel@tonic-gate #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
2300Sstevel@tonic-gate 					/* This option applies only to  */
2310Sstevel@tonic-gate 					/* IBM MAGSTAR 3590. If this    */
2320Sstevel@tonic-gate 					/* flag is set, the st driver   */
2330Sstevel@tonic-gate 					/* will retry the last cmd if   */
2340Sstevel@tonic-gate 					/* the last error cause a check */
2350Sstevel@tonic-gate 					/* condition with error code    */
2360Sstevel@tonic-gate 					/* 0x71 and sense code  0x01 	*/
2370Sstevel@tonic-gate #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
2380Sstevel@tonic-gate 					/* detected to select correct   */
2390Sstevel@tonic-gate 					/* density code.		*/
2402537Srralphs #define	ST_WORMABLE		0x1000000
2412537Srralphs 					/* Drive is capable of doing	*/
2422537Srralphs 					/* Write Appends only at EOM	*/
2432537Srralphs 					/* if WORM media type is loaded */
2440Sstevel@tonic-gate #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
2450Sstevel@tonic-gate 					/* the tape drive provides the	*/
2460Sstevel@tonic-gate 					/* clean bit information in	*/
2470Sstevel@tonic-gate 					/* byte 21, bitmask 0x08 of	*/
2480Sstevel@tonic-gate 					/* Request Sense data		*/
2490Sstevel@tonic-gate #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
2500Sstevel@tonic-gate 					/* the tape drive provides the	*/
2510Sstevel@tonic-gate 					/* clean bit information in	*/
2520Sstevel@tonic-gate 					/* byte 70, bitmask 0xc0 of	*/
2530Sstevel@tonic-gate 					/* Request Sense data		*/
2540Sstevel@tonic-gate #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
2550Sstevel@tonic-gate 					/* the tape drive provides the	*/
2560Sstevel@tonic-gate 					/* clean bit information in	*/
2570Sstevel@tonic-gate 					/* byte 18, bitmask 0x01 of	*/
2580Sstevel@tonic-gate 					/* Request Sense data		*/
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2610Sstevel@tonic-gate #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
2620Sstevel@tonic-gate 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
2630Sstevel@tonic-gate 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
2640Sstevel@tonic-gate 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
2650Sstevel@tonic-gate 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
2660Sstevel@tonic-gate 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
2672537Srralphs 	ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate #define	NDENSITIES	MT_NDENSITIES
2700Sstevel@tonic-gate #define	NSPEEDS		MT_NSPEEDS
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate /*
2730Sstevel@tonic-gate  * defines for Log Sense Pages
2740Sstevel@tonic-gate  */
2750Sstevel@tonic-gate #define	SUPPORTED_LOG_PAGES_PAGE	0x00
2760Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE		0x0c
2770Sstevel@tonic-gate #define	TAPE_ALERT_PAGE			0x2e
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate  * Log Page Control definitions
2810Sstevel@tonic-gate  */
2820Sstevel@tonic-gate #define	CURRENT_THRESHOLD_VALUES	0x00
2830Sstevel@tonic-gate #define	CURRENT_CUMULATIVE_VALUES	0x40
2840Sstevel@tonic-gate #define	DEFAULT_THRESHOLD_VALUES	0x80
2850Sstevel@tonic-gate #define	DEFAULT_CUMULATIVE_VALUES	0xC0
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate  * Tape Alert Flag definitions
2890Sstevel@tonic-gate  */
2902537Srralphs typedef enum {
2912537Srralphs 	TAF_READ_WARN			= 0x01,
2922537Srralphs 	TAF_WRITE_WARN			= 0x02,
2932537Srralphs 	TAF_HARD_ERR			= 0x03,
2942537Srralphs 	TAF_MEDIA_ERR			= 0x04,
2952537Srralphs 	TAF_READ_FAIL			= 0x05,
2962537Srralphs 	TAF_WRITE_FAIL			= 0x06,
2972537Srralphs 	TAF_MEDIA_LIFE			= 0x07,
2982537Srralphs 	TAF_MEDIA_NOT_DATA_GRADE	= 0x08,
2992537Srralphs 	TAF_WRITE_PROTECTED		= 0x09,
3002537Srralphs 	TAF_NO_MEDIA_REMOVE		= 0x0A,
3012537Srralphs 	TAF_CLEANING_MEDIA		= 0x0B,
3022537Srralphs 	TAF_UNSUPPERTED_FORMAT		= 0x0C,
3032537Srralphs 	TAF_RECOVERED_TAPE_BREAK	= 0x0D,
3042537Srralphs 	TAF_TAPE_BREAK_FAUL		= 0x0E,
3052537Srralphs 	TAF_CART_MEM_FAIL		= 0x0F,
3062537Srralphs 	TAF_FORCED_EJECT		= 0x10,
3072537Srralphs 	TAF_READ_ONLY_FORMAT		= 0x11,
3082537Srralphs 	TAF_TAPE_DIR_CORRUPT		= 0x12,
3092537Srralphs 	TAF_NEARING_MEDIA_LIFE		= 0x13,
3102537Srralphs 	TAF_CLEAN_NOW			= 0x14,
3112537Srralphs 	TAF_CLEAN_PERIODIC		= 0x15,
3122537Srralphs 	TAF_EXP_CLEAN_CART		= 0x16,
3132537Srralphs 	TAF_INVALID_CLEAN_MEDIA		= 0x17,
3142537Srralphs 	TAF_RETENSION_REQUEST		= 0x18,
3152537Srralphs 	TAF_DUAL_PORT_INTERFACE_ERR	= 0x19,
3162537Srralphs 	TAF_COOLING_FAN_FAIL		= 0x1A,
3172537Srralphs 	TAF_POWER_SUPPLY_FAIL		= 0x1B,
3182537Srralphs 	TAF_POWER_CONSUMPTION		= 0x1C,
3192537Srralphs 	TAF_DRIVE_MAINT_REQUEST		= 0x1D,
3202537Srralphs 	TAF_HARDWARE_A			= 0x1E,
3212537Srralphs 	TAF_HARDWARE_B			= 0x1F,
3222537Srralphs 	TAF_INTERFACE			= 0x20,
3232537Srralphs 	TAF_EJECT_MEDIA			= 0x21,
3242537Srralphs 	TAF_DOWNLOAD_FAIL		= 0x22,
3252537Srralphs 	TAF_DRIVE_HUMIDITY		= 0x23,
3262537Srralphs 	TAF_DRIVE_TEMP			= 0x24,
3272537Srralphs 	TAF_DRIVE_VOLTAGE		= 0x25,
3282537Srralphs 	TAF_PREDICTIVE_FAIL		= 0x26,
3292537Srralphs 	TAF_DIAG_REQUIRED		= 0x27,
3302537Srralphs 	TAF_LOADER_HDWR_A		= 0x28,
3312537Srralphs 	TAF_LOADER_STRAY_TAPE		= 0x29,
3322537Srralphs 	TAF_LOADER_HDWR_B		= 0x2A,
3332537Srralphs 	TAF_LOADER_DOOR			= 0x2B,
3342537Srralphs 	TAF_LOADER_HDWR_C		= 0x2C,
3352537Srralphs 	TAF_LOADER_MAGAZINE		= 0x2D,
3362537Srralphs 	TAF_LOADER_PREDICTIVE_FAIL	= 0x2E,
3372537Srralphs 	TAF_LOST_STATISTICS		= 0x32,
3382537Srralphs 	TAF_TAPE_DIR_CURRUPT_UNLOAD	= 0x33,
3392537Srralphs 	TAF_TAPE_SYS_WRT_FAIL		= 0x34,
3402537Srralphs 	TAF_TAPE_SYS_RD_FAIL		= 0x35,
3412537Srralphs 	TAF_NO_START_OF_DATA		= 0x36,
3422537Srralphs 	TAF_WORM_INTEGRITY		= 0x3B,
3432537Srralphs 	TAF_WORM_OVRWRT_ATTEMPT		= 0x3C
3442537Srralphs }tape_alert_flags;
3452537Srralphs 
3462537Srralphs /*
3472537Srralphs  * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension
3482537Srralphs  * so they reuse TAF_RETENSION_REQUEST.
3492537Srralphs  */
3502537Srralphs #define	CLEAN_FOR_ERRORS		 0x18
3512537Srralphs 
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
3540Sstevel@tonic-gate #define	TAPE_ALERT_NOT_SUPPORTED	0x01
3550Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORTED		0x02
3560Sstevel@tonic-gate #define	TAPE_ALERT_STILL_DIRTY		0x04
3570Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
3580Sstevel@tonic-gate #define	TAPE_PREVIOUSLY_DIRTY		0x10
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate #define	TAPE_ALERT_MAX_PARA		64
3610Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
3620Sstevel@tonic-gate #define	SEQUENTIAL_NEED_CLN		0x0100
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate /*
3650Sstevel@tonic-gate  * Parameters
3660Sstevel@tonic-gate  */
3670Sstevel@tonic-gate #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
3680Sstevel@tonic-gate #define	VIDLEN		8	/* size of vendor identifier length */
3690Sstevel@tonic-gate #define	PIDLEN		16	/* size of product identifier length */
3700Sstevel@tonic-gate #define	VIDPIDLEN	(VIDLEN + PIDLEN)
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate struct st_drivetype {
3740Sstevel@tonic-gate 	char	name[ST_NAMESIZE];	/* Name, for debug */
3750Sstevel@tonic-gate 	char	length;			/* Length of vendor id */
3760Sstevel@tonic-gate 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
3770Sstevel@tonic-gate 	char	type;			/* Drive type for driver */
3780Sstevel@tonic-gate 	int	bsize;			/* Block size */
3790Sstevel@tonic-gate 	int	options;		/* Drive options */
3800Sstevel@tonic-gate 	int	max_rretries;		/* Max read retries */
3810Sstevel@tonic-gate 	int	max_wretries;		/* Max write retries */
3820Sstevel@tonic-gate 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
3830Sstevel@tonic-gate 	uchar_t	default_density;	/* default density for this drive */
3840Sstevel@tonic-gate 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
3850Sstevel@tonic-gate 	ushort_t non_motion_timeout;	/* Inquiry type commands */
3860Sstevel@tonic-gate 	ushort_t io_timeout;		/* I/O timeout in seconds */
3870Sstevel@tonic-gate 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
3880Sstevel@tonic-gate 	ushort_t space_timeout;		/* space cmd timeout in seconds */
3890Sstevel@tonic-gate 	ushort_t load_timeout;		/* load tape time in seconds */
3900Sstevel@tonic-gate 	ushort_t unload_timeout;	/* unload tape time in seconds */
3910Sstevel@tonic-gate 	ushort_t erase_timeout;		/* erase timeout. seconds */
3920Sstevel@tonic-gate };
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate #define	MINUTES(val)	((val) * 60)
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate struct comp_mode_page {
3970Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3980Sstevel@tonic-gate 	uchar_t	:		6,
3990Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4000Sstevel@tonic-gate 		dce:		1;	/* Data Compression Enable */
4010Sstevel@tonic-gate 	uchar_t	:		5,
4020Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4030Sstevel@tonic-gate 		dde:		1;	/* Data Decompression Enabled */
4040Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4050Sstevel@tonic-gate 	uchar_t comp_alg_high;
4060Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4070Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4080Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4090Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4100Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4110Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4120Sstevel@tonic-gate 	uchar_t	reservered0;
4130Sstevel@tonic-gate 	uchar_t	reservered1;
4140Sstevel@tonic-gate 	uchar_t	reservered2;
4150Sstevel@tonic-gate 	uchar_t	reservered3;
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4180Sstevel@tonic-gate 	uchar_t	dce:		1,	/* Data Compression Enable */
4190Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4200Sstevel@tonic-gate 		:		6;
4210Sstevel@tonic-gate 	uchar_t	dde:		1,	/* Data Decompression Enabled */
4220Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4230Sstevel@tonic-gate 		:		5;
4240Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4250Sstevel@tonic-gate 	uchar_t comp_alg_high;
4260Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4270Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4280Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4290Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4300Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4310Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4320Sstevel@tonic-gate 	uchar_t	reservered0;
4330Sstevel@tonic-gate 	uchar_t	reservered1;
4340Sstevel@tonic-gate 	uchar_t	reservered2;
4350Sstevel@tonic-gate 	uchar_t	reservered3;
4360Sstevel@tonic-gate #endif
4370Sstevel@tonic-gate };
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate struct dev_mode_page {
4400Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
4410Sstevel@tonic-gate 	uchar_t	act_format:	5,	/* active format */
4420Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4432537Srralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4440Sstevel@tonic-gate 		:		1;
4450Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4460Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4470Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4480Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4490Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4500Sstevel@tonic-gate 	uchar_t	rew:		1,	/* Report Early Warning */
4512537Srralphs 		robo:		1,	/* Reverse Object Buffer Order */
4520Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4530Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4542537Srralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4552537Srralphs 		lois:		1,	/* Logical Object Identifiers Support */
4562537Srralphs 		obr:		1;	/* Object Buffer Recovery */
4572537Srralphs 	uchar_t	gap_size;		/* OBSOLETE */
4582537Srralphs 	uchar_t	bam:		1,	/* Block Address Mode */
4592537Srralphs 		bmal:		1,	/* Block Address Mode Lock */
4602537Srralphs 		swp:		1,	/* Software Write Protection */
4610Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4620Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4630Sstevel@tonic-gate 		eod_defined:	3;
4640Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4650Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4660Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4670Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
4682537Srralphs 	uchar_t	prmwp:		1,	/* PeRManent Write Protect */
4692537Srralphs 		perswp:		1,	/* persistant write protection */
4702537Srralphs 		asocwp:		1,	/* associated write protect */
4712537Srralphs 		rew_on_rst:	2,	/* rewind on reset */
4722537Srralphs 		oir:		1,	/* Only If Reserved */
4732537Srralphs 		wtre:		2;	/* Worm Tamper Read Enable */
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4760Sstevel@tonic-gate 	uchar_t	:		1,
4772537Srralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4780Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4790Sstevel@tonic-gate 		act_format:	5;	/* active format */
4800Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4810Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4820Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4830Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4840Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4852537Srralphs 	uchar_t	obr:		1,	/* Object Buffer Recovery */
4862537Srralphs 		lois:		1,	/* Logical Object Identifiers Support */
4872537Srralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4880Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4890Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4902537Srralphs 		robo:		1,	/* Reverse Object Buffer Order */
4910Sstevel@tonic-gate 		rew:		1;	/* Report Early Warning */
4922537Srralphs 	uchar_t	gap_size;		/* OBSELETE */
4930Sstevel@tonic-gate 	uchar_t	eod_defined:	3,
4940Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4950Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4962537Srralphs 		swp:		1,	/* Software Write Protection */
4972537Srralphs 		bmal:		1,	/* Block Address Mode Lock */
4982537Srralphs 		bam:		1;	/* Block Address Mode */
4990Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
5000Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
5010Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
5020Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
5032537Srralphs 	uchar_t	wtre:		2,	/* Worm Tamper Read Enable */
5042537Srralphs 		oir:		1,	/* Only If Reserved */
5052537Srralphs 		rew_on_rst:	2,	/* rewind on reset */
5062537Srralphs 		asocwp:		1,	/* associated write protect */
5072537Srralphs 		perswp:		1,	/* persistant write protection */
5082537Srralphs 		prmwp:		1;	/* PeRManent Write Protect */
5090Sstevel@tonic-gate #endif
5100Sstevel@tonic-gate };
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate typedef union {
5130Sstevel@tonic-gate 	struct comp_mode_page	comp;
5140Sstevel@tonic-gate 	struct dev_mode_page	dev;
5150Sstevel@tonic-gate }modepage;
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate /*
5180Sstevel@tonic-gate  *
5190Sstevel@tonic-gate  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
5200Sstevel@tonic-gate  * The parameter list contains a header, followed by zero or more
5210Sstevel@tonic-gate  * block descriptors, followed by vendor unique parameters, if any.
5220Sstevel@tonic-gate  *
5230Sstevel@tonic-gate  */
5240Sstevel@tonic-gate #define	MSIZE	0x0c		/* Size without additional pages */
5250Sstevel@tonic-gate struct seq_mode {
5260Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
5270Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5280Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5290Sstevel@tonic-gate 	uchar_t	speed	:4,	/* speed */
5300Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5310Sstevel@tonic-gate 		wp	:1;	/* write protected, sense only */
5320Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5330Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5340Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5350Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5360Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5370Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5380Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5390Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5400Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5410Sstevel@tonic-gate 	uchar_t page_code:	6,
5420Sstevel@tonic-gate 		:		1,
5430Sstevel@tonic-gate 		ps:		1; /* Page Savable sense only */
5440Sstevel@tonic-gate 	uchar_t	page_len;
5450Sstevel@tonic-gate 	modepage page;
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
5480Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5490Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5500Sstevel@tonic-gate 	uchar_t	wp	:1,	/* write protected, sense only */
5510Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5520Sstevel@tonic-gate 		speed	:4;	/* speed */
5530Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5540Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5550Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5560Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5570Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5580Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5590Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5600Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5610Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5620Sstevel@tonic-gate 	uchar_t	ps:		1, /* Page Savable sense only */
5630Sstevel@tonic-gate 		:		1,
5640Sstevel@tonic-gate 		page_code:	6;
5650Sstevel@tonic-gate 	uchar_t	page_len;
5660Sstevel@tonic-gate 	modepage page;
5670Sstevel@tonic-gate #else
5680Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5690Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
5700Sstevel@tonic-gate };
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate /*
5735425Syl194034  * One_command parameter data for REPORT SUPPORTED OPERATION CODES.
5745425Syl194034  */
5755425Syl194034 struct one_com_des {
5765425Syl194034 #if defined(_BIT_FIELDS_LTOH)
5775425Syl194034 	uchar_t reserved0;
5785425Syl194034 	uchar_t support:	3,	/* support value */
5795425Syl194034 		reserved1:	4,
5805425Syl194034 		ctdp:		1;	/* cmd timeouts descriptor present */
5815425Syl194034 	ushort_t cdb_size;		/* cdb size */
5825425Syl194034 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
5835425Syl194034 #elif defined(_BIT_FIELDS_HTOL)
5845425Syl194034 	uchar_t reserved0;
5855425Syl194034 	uchar_t ctdp:		1,	/* cmd timeouts descriptor present */
5865425Syl194034 		reserved1:	4,
5875425Syl194034 		support:	3;	/* support value */
5885425Syl194034 	ushort_t cdb_size;		/* cdb size */
5895425Syl194034 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
5905425Syl194034 #else
5915425Syl194034 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5925425Syl194034 #endif /* _BIT_FIELDS_LTOH */
5935425Syl194034 };
5945425Syl194034 
5955425Syl194034 /*
5965425Syl194034  * Command timeouts descriptor
5975425Syl194034  */
5985425Syl194034 struct com_timeout_des {
5995425Syl194034 	ushort_t des_len;	/* descriptor length */
6005425Syl194034 	uchar_t reserved;
6015425Syl194034 	uchar_t com_spe;	/* command specific */
6025425Syl194034 	uint_t nom_timeout;	/* nominal command processing timeout */
6035425Syl194034 	uint_t rec_timeout;	/* recommended command timeout */
6045425Syl194034 };
6055425Syl194034 
6065425Syl194034 /*
6075425Syl194034  * Reporting options
6085425Syl194034  */
6095425Syl194034 #define	ALL_COMMAND_DATA_FORMAT			0
6105425Syl194034 #define	ONE_COMMAND_NO_SERVICE_DATA_FORMAT	1
6115425Syl194034 #define	ONE_COMMAND_DATA_FORMAT			2
6125425Syl194034 
6135425Syl194034 /*
6145425Syl194034  * Support values in One_command parameter data
6155425Syl194034  */
6165425Syl194034 #define	SUPPORT_VALUES_NOT_AVAILABLE		0
6175425Syl194034 #define	SUPPORT_VALUES_NOT_SUPPORT		1
6185425Syl194034 #define	SUPPORT_VALUES_SUPPORT_SCSI		3
6195425Syl194034 #define	SUPPORT_VALUES_SUPPORT_VENDOR		5
6205425Syl194034 
6215425Syl194034 /*
6225425Syl194034  * Parameter data for REPORT DENSITY SUPPORT command
6235425Syl194034  */
6245425Syl194034 struct report_density_header {
6255425Syl194034 	ushort_t ava_dens_len;		/* available density support length */
6265425Syl194034 	uchar_t reserved0;
6275425Syl194034 	uchar_t reserved1;
6285425Syl194034 };
6295425Syl194034 
6305425Syl194034 struct report_density_desc {
6315425Syl194034 #if defined(_BIT_FIELDS_LTOH)
6325425Syl194034 	uchar_t pri_den;		/* primary density code */
6335425Syl194034 	uchar_t sec_den;		/* secondary density code */
6345425Syl194034 	uchar_t dlv:1;			/* descriptor length valid */
6355425Syl194034 	uchar_t reserved:4;
6365425Syl194034 	uchar_t deflt:1;		/* is default density */
6375425Syl194034 	uchar_t dup:1;			/* pri density has one descriptor */
6385425Syl194034 	uchar_t wrtok:1;		/* support writing to media */
6395425Syl194034 	uchar_t desc_len_hi;		/* descriptor length high */
6405425Syl194034 	uchar_t desc_len_low;		/* descriptor length low */
6415425Syl194034 	uchar_t bits_per_mm[3];		/* bits per mm */
6425425Syl194034 	uchar_t media_width_hi;		/* media width high */
6435425Syl194034 	uchar_t media_width_low;	/* media width low */
6445425Syl194034 	ushort_t tracks;		/* tracks */
6455425Syl194034 	uint_t capacity;		/* capacity */
6465425Syl194034 	uchar_t ass_org[8];		/* assigning organization */
6475425Syl194034 	uchar_t den_name[8];		/* density name */
6485425Syl194034 	uchar_t description[20];	/* description */
6495425Syl194034 #elif defined(_BIT_FIELDS_HTOL)
6505425Syl194034 	uchar_t pri_den;		/* primary density code */
6515425Syl194034 	uchar_t sec_den;		/* secondary density code */
6525425Syl194034 	uchar_t wrtok:1;		/* support writing to media */
6535425Syl194034 	uchar_t dup:1;			/* pri density has one descriptor */
6545425Syl194034 	uchar_t deflt:1;		/* is default density */
6555425Syl194034 	uchar_t reserved:4;
6565425Syl194034 	uchar_t dlv:1;			/* descriptor length valid */
6575425Syl194034 	uchar_t desc_len_hi;		/* descriptor length high */
6585425Syl194034 	uchar_t desc_len_low;		/* descriptor length low */
6595425Syl194034 	uchar_t bits_per_mm[3];		/* bits per mm */
6605425Syl194034 	uchar_t media_width_hi;		/* media width high */
6615425Syl194034 	uchar_t media_width_low;	/* media width low */
6625425Syl194034 	ushort_t tracks;		/* tracks */
6635425Syl194034 	uint_t capacity;		/* capacity */
6645425Syl194034 	uchar_t ass_org[8];		/* assigning organization */
6655425Syl194034 	uchar_t den_name[8];		/* density name */
6665425Syl194034 	uchar_t description[20];	/* description */
6675425Syl194034 #else
6685425Syl194034 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
6695425Syl194034 #endif  /* _BIT_FIELDS_LTOH */
6705425Syl194034 };
6715425Syl194034 
6725425Syl194034 /*
6730Sstevel@tonic-gate  * Data returned from the READ BLOCK LIMITS command.
6740Sstevel@tonic-gate  */
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate #define	RBLSIZE	(sizeof (struct read_blklim))
6770Sstevel@tonic-gate struct read_blklim {
6780Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL)
6790Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6800Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6810Sstevel@tonic-gate #elif defined(_BIT_FIELDS_LTOH)
6820Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6830Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6840Sstevel@tonic-gate #endif
6850Sstevel@tonic-gate 	uchar_t	max_hi;			/* Maximum block length, high byte */
6860Sstevel@tonic-gate 	uchar_t	max_mid;		/* Maximum block length, middle byte */
6870Sstevel@tonic-gate 	uchar_t	max_lo;			/* Maximum block length, low byte */
6880Sstevel@tonic-gate 	uchar_t	min_hi;			/* Minimum block length, high byte */
6890Sstevel@tonic-gate 	uchar_t	min_lo;			/* Minimum block length, low byte */
6900Sstevel@tonic-gate };
6910Sstevel@tonic-gate 
6924549Srralphs /*
6934549Srralphs  * operation codes
6944549Srralphs  */
6954549Srralphs typedef enum {
6964549Srralphs 	ST_OP_NIL,
6974549Srralphs 	ST_OP_CTL,
6984549Srralphs 	ST_OP_READ,
6994549Srralphs 	ST_OP_WRITE,
7004549Srralphs 	ST_OP_WEOF
7014549Srralphs }optype;
7024549Srralphs 
7034549Srralphs /*
7044549Srralphs  * eof/eot/eom codes.
7054549Srralphs  */
7064549Srralphs typedef enum {
7074549Srralphs 	ST_NO_EOF,
7084549Srralphs 	ST_EOF_PENDING,		/* filemark pending */
7094549Srralphs 	ST_EOF,			/* at filemark */
7104549Srralphs 	ST_EOT_PENDING,		/* logical eot pending */
7114549Srralphs 	ST_EOT,			/* at logical eot */
7124549Srralphs 	ST_EOM,			/* at physical eot */
7134549Srralphs 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
7144549Srralphs }pstatus;
7154549Srralphs 
7164549Srralphs typedef enum { invalid, legacy, logical } posmode;
7174549Srralphs 
7184549Srralphs typedef struct tapepos {
7194549Srralphs 	uint64_t lgclblkno;
7204549Srralphs 	int32_t fileno;
7214549Srralphs 	int32_t blkno;
7224549Srralphs 	int32_t partition;
7234549Srralphs 	pstatus eof;			/* eof states */
7244549Srralphs 	posmode	pmode;
725*5628Srralphs 	uint32_t: 32;
7264549Srralphs }tapepos_t;
7274549Srralphs 
7284549Srralphs /* byte 1 of cdb for type of read position command */
7294549Srralphs typedef enum {
7304549Srralphs 	SHORT_POS	= 0,
7314549Srralphs 	LONG_POS	= 6,
7324549Srralphs 	EXT_POS		= 8,
7334549Srralphs 	NO_POS		= 0xff	/* Drive doesn't support read position */
7344549Srralphs } read_p_types;
7354549Srralphs 
7364549Srralphs 
7374549Srralphs /*
7384549Srralphs  * Data returned from the READ POSITION command.
7394549Srralphs  */
7404549Srralphs 
7414549Srralphs typedef struct tape_position {
7424549Srralphs #if defined(_BIT_FIELDS_HTOL)
7434549Srralphs 	uchar_t begin_of_part:	1;
7444549Srralphs 	uchar_t end_of_part:	1;
7454549Srralphs 	uchar_t blk_cnt_unkwn:	1;
7464549Srralphs 	uchar_t byte_cnt_unkwn:	1;
7474549Srralphs 	uchar_t reserved0:	1;
7484549Srralphs 	uchar_t blk_posi_unkwn:	1;
7494549Srralphs 	uchar_t posi_err:	1;
7504549Srralphs 	uchar_t reserved1:	1;
7514549Srralphs #elif defined(_BIT_FIELDS_LTOH)
7524549Srralphs 	uchar_t reserved1:	1;
7534549Srralphs 	uchar_t posi_err:	1;
7544549Srralphs 	uchar_t blk_posi_unkwn:	1;
7554549Srralphs 	uchar_t reserved0:	1;
7564549Srralphs 	uchar_t byte_cnt_unkwn:	1;
7574549Srralphs 	uchar_t blk_cnt_unkwn:	1;
7584549Srralphs 	uchar_t end_of_part:	1;
7594549Srralphs 	uchar_t begin_of_part:	1;
7604549Srralphs #endif
7614549Srralphs 	uchar_t partition_number;
7624549Srralphs 	uchar_t reserved2[2];
7634549Srralphs 	uint32_t host_block;
7644549Srralphs 	uint32_t media_block;
7654549Srralphs 	uchar_t reserved3;
7664549Srralphs 	uchar_t block_in_buff[3];
7674549Srralphs 	uint32_t byte_in_buff;
7684549Srralphs }tape_position_t;
7694549Srralphs 
7704549Srralphs 
7714549Srralphs typedef struct tape_position_long {
7724549Srralphs #if defined(_BIT_FIELDS_HTOL)
7734549Srralphs 	uint32_t begin_of_part:	1;
7744549Srralphs 	uint32_t end_of_part:	1;
7754549Srralphs 	uint32_t reserved0:	2;
7764549Srralphs 	uint32_t mrk_posi_unkwn:1;
7774549Srralphs 	uint32_t blk_posi_unkwn:1;
7784549Srralphs 	uint32_t reserved1:	2;
7794549Srralphs #elif defined(_BIT_FIELDS_LTOH)
7804549Srralphs 	uint32_t reserved1:	2;
7814549Srralphs 	uint32_t blk_posi_unkwn:1;
7824549Srralphs 	uint32_t mrk_posi_unkwn:1;
7834549Srralphs 	uint32_t reserved0:	2;
7844549Srralphs 	uint32_t end_of_part:   1;
7854549Srralphs 	uint32_t begin_of_part: 1;
7864549Srralphs #endif
7874549Srralphs 	uint32_t reserved2:	24;
7884549Srralphs 	uint32_t partition;
7894549Srralphs 	uint64_t block_number;
7904549Srralphs 	uint64_t file_number;
7914549Srralphs 	uint64_t set_number;
7924549Srralphs }tape_position_long_t;
7934549Srralphs 
7944549Srralphs typedef struct tape_position_ext {
7954549Srralphs #if defined(_BIT_FIELDS_HTOL)
796*5628Srralphs 	uchar_t begin_of_part:	1;
797*5628Srralphs 	uchar_t end_of_part:	1;
798*5628Srralphs 	uchar_t blk_cnt_unkwn:	1;
799*5628Srralphs 	uchar_t byte_cnt_unkwn:	1;
800*5628Srralphs 	uchar_t mrk_posi_unkwn:	1;
801*5628Srralphs 	uchar_t blk_posi_unkwn:	1;
802*5628Srralphs 	uchar_t posi_err:	1;
803*5628Srralphs 	uchar_t reserved0:	1;
804*5628Srralphs 
805*5628Srralphs 	uchar_t partition;
806*5628Srralphs 	uint16_t parameter_len;
8074549Srralphs /* start next word */
8084549Srralphs 	uint32_t reserved1:	8;
8094549Srralphs 	uint32_t blks_in_buf:	24;
8104549Srralphs #elif defined(_BIT_FIELDS_LTOH)
811*5628Srralphs 	uchar_t reserved0:	1;
812*5628Srralphs 	uchar_t posi_err:	1;
813*5628Srralphs 	uchar_t blk_posi_unkwn:	1;
814*5628Srralphs 	uchar_t mrk_posi_unkwn:	1;
815*5628Srralphs 	uchar_t byte_cnt_unkwn:	1;
816*5628Srralphs 	uchar_t blk_cnt_unkwn:	1;
817*5628Srralphs 	uchar_t end_of_part:	1;
818*5628Srralphs 	uchar_t begin_of_part:	1;
819*5628Srralphs 
820*5628Srralphs 	uchar_t partition;
821*5628Srralphs 	uint16_t parameter_len;
8224549Srralphs /* start next word */
8234549Srralphs 	uint32_t blks_in_buf:	24;
8244549Srralphs 	uint32_t reserved1:	8;
8254549Srralphs #endif
8264549Srralphs 	uint64_t host_block;
8274549Srralphs 	uint64_t media_block;
8284549Srralphs 	uint64_t byte_in_buf;
8294549Srralphs }tape_position_ext_t;
8304549Srralphs 
8314549Srralphs typedef union {
8324549Srralphs 	tape_position_t srt;
8334549Srralphs 	tape_position_ext_t ext;
8344549Srralphs 	tape_position_long_t lng;
8354549Srralphs }read_pos_data_t;
8364549Srralphs 
837*5628Srralphs typedef struct {
838*5628Srralphs 	unsigned char cmd;
839*5628Srralphs 	unsigned char
840*5628Srralphs 		requires_reserve:	1,	/* reserve must be done */
841*5628Srralphs 		retriable:		1,	/* can be retried */
842*5628Srralphs 		chg_tape_pos:		1,	/* position will change */
843*5628Srralphs 		chg_tape_data:		1,	/* data on media will change */
844*5628Srralphs 		explicit:		1,	/* explicit command set */
845*5628Srralphs 		/*
846*5628Srralphs 		 * 0 doesn't, 1 forward,
847*5628Srralphs 		 * 2 back, 3 either
848*5628Srralphs 		 */
849*5628Srralphs 		chg_tape_direction:	2;	/* direction of pos change */
850*5628Srralphs #define	DIR_NONE	0
851*5628Srralphs #define	DIR_FORW	1
852*5628Srralphs #define	DIR_REVC	2
853*5628Srralphs #define	DIR_EITH	3
854*5628Srralphs 	unsigned char
855*5628Srralphs 		/*
856*5628Srralphs 		 * 0 doesn't 1 read, 2 write
857*5628Srralphs 		 */
858*5628Srralphs 		transfers_data:		2,
859*5628Srralphs #define	TRAN_NONE	0
860*5628Srralphs #define	TRAN_READ	1
861*5628Srralphs #define	TRAN_WRTE	2
862*5628Srralphs 		recov_pos_type:		1,
863*5628Srralphs #define	POS_EXPECTED	0
864*5628Srralphs #define	POS_STARTING	1
865*5628Srralphs 		do_not_recover:		1;
866*5628Srralphs 	uchar_t reserve_byte;
867*5628Srralphs 	uint32_t reserve_mask;
868*5628Srralphs 	uint64_t (*get_cnt)(uchar_t *);
869*5628Srralphs 	uint64_t (*get_lba)(uchar_t *);
870*5628Srralphs }cmd_attribute;
871*5628Srralphs 
872*5628Srralphs typedef struct {
873*5628Srralphs 	buf_t *cmd_bp;
874*5628Srralphs 	size_t privatelen;
875*5628Srralphs }pkt_info;
876*5628Srralphs 
877*5628Srralphs typedef struct {
878*5628Srralphs 	buf_t *cmd_bp;
879*5628Srralphs 	size_t privatelen;
880*5628Srralphs 	tapepos_t pos;
881*5628Srralphs 	const cmd_attribute *cmd_attrib;
882*5628Srralphs }recov_info;
883*5628Srralphs 
884177Scz147101 #ifdef _KERNEL
885177Scz147101 
8865251Smrj #ifdef	__x86
887177Scz147101 /* Data structure used in big block I/O on x86/x64 platform */
888177Scz147101 
889177Scz147101 /*
890177Scz147101  * alloc more than one contig_mem, so mutiple I/O can be
891177Scz147101  * on-going simultaneously
892177Scz147101  */
893177Scz147101 #define	ST_MAX_CONTIG_MEM_NUM	3
894177Scz147101 
895177Scz147101 struct contig_mem {
896177Scz147101 	struct contig_mem *cm_next;
897177Scz147101 	size_t cm_len;
898177Scz147101 	caddr_t cm_addr;
899177Scz147101 	ddi_acc_handle_t cm_acc_hdl;
900177Scz147101 	struct buf *cm_bp;
901177Scz147101 	int cm_use_sbuf;
902177Scz147101 };
9033138Sfrits 
904177Scz147101 #endif
905177Scz147101 
906177Scz147101 #endif /* _KERNEL */
907177Scz147101 
9080Sstevel@tonic-gate /*
9094549Srralphs  * driver states..
9102537Srralphs  */
9112537Srralphs typedef enum {
9124549Srralphs 	ST_STATE_CLOSED,
9134549Srralphs 	ST_STATE_OFFLINE,
9144549Srralphs 	ST_STATE_INITIALIZING,
9154549Srralphs 	ST_STATE_OPENING,
9164549Srralphs 	ST_STATE_OPEN_PENDING_IO,
9174549Srralphs 	ST_STATE_APPEND_TESTING,
9184549Srralphs 	ST_STATE_OPEN,
9194549Srralphs 	ST_STATE_RESOURCE_WAIT,
9204549Srralphs 	ST_STATE_CLOSING,
9214549Srralphs 	ST_STATE_SENSING,
9224549Srralphs 	ST_STATE_CLOSE_PENDING_OPEN
9234549Srralphs }st_states;
9242537Srralphs 
9254549Srralphs typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
9264549Srralphs 
9272537Srralphs 
9282537Srralphs /*
9290Sstevel@tonic-gate  * Private info for scsi tapes. Pointed to by the un_private pointer
9300Sstevel@tonic-gate  * of one of the SCSI_DEVICE chains.
9310Sstevel@tonic-gate  */
9320Sstevel@tonic-gate 
9330Sstevel@tonic-gate struct scsi_tape {
9340Sstevel@tonic-gate 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
9350Sstevel@tonic-gate 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
9360Sstevel@tonic-gate 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
9370Sstevel@tonic-gate 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
9380Sstevel@tonic-gate 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
9390Sstevel@tonic-gate 	struct	buf *un_sbufp;		/* for use in special io */
9400Sstevel@tonic-gate 	char	*un_srqbufp;		/* sense buffer for special io */
9410Sstevel@tonic-gate 	kcondvar_t un_clscv;		/* closing cv */
9420Sstevel@tonic-gate 	struct	buf *un_quef;		/* head of wait queue */
9430Sstevel@tonic-gate 	struct	buf *un_quel;		/* tail of wait queue */
9440Sstevel@tonic-gate 	struct	buf *un_runqf;		/* head of run queue */
9450Sstevel@tonic-gate 	struct	buf *un_runql;		/* tail of run queue */
9460Sstevel@tonic-gate 	struct seq_mode *un_mspl;	/* ptr to mode select info */
9470Sstevel@tonic-gate 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
9480Sstevel@tonic-gate 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
9490Sstevel@tonic-gate 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
9504549Srralphs 	tapepos_t un_pos;		/* Current tape position */
9510Sstevel@tonic-gate 	int	un_oflags;		/* open flags */
9524549Srralphs 	tapepos_t un_err_pos;		/* block in file where err occurred */
9530Sstevel@tonic-gate 	uint_t	un_err_resid;		/* resid from last error */
9540Sstevel@tonic-gate 	short	un_fmneeded;		/* filemarks to be written - HP only */
9550Sstevel@tonic-gate 	dev_t	un_dev;			/* unix device */
9560Sstevel@tonic-gate 	uchar_t	un_attached;		/* unit known && attached */
9570Sstevel@tonic-gate 	int	un_pwr_mgmt;		/* power management state */
9580Sstevel@tonic-gate 	uchar_t	un_density_known;	/* density is known */
9590Sstevel@tonic-gate 	uchar_t	un_curdens;		/* index into density table */
9602537Srralphs 	optype	un_lastop;		/* last I/O was: read/write/ctl */
9614549Srralphs 	st_states un_laststate;		/* last state */
9624549Srralphs 	st_states un_state;		/* current state */
9630Sstevel@tonic-gate 	uchar_t	un_status;		/* status from last sense */
9640Sstevel@tonic-gate 	uchar_t	un_retry_ct;		/* retry count */
9650Sstevel@tonic-gate 	uchar_t	un_tran_retry_ct;	/* transport retry count */
9662537Srralphs 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
9670Sstevel@tonic-gate 	uchar_t	un_test_append;		/* check writing at end of tape */
9680Sstevel@tonic-gate 	uchar_t un_arq_enabled;		/* auto request sense enabled */
9690Sstevel@tonic-gate 	uchar_t un_untagged_qing;	/* hba has untagged quing */
9700Sstevel@tonic-gate 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
9710Sstevel@tonic-gate 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
9720Sstevel@tonic-gate 	uchar_t	un_ncmds;		/* number of commands outstanding */
9730Sstevel@tonic-gate 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
9740Sstevel@tonic-gate 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
9750Sstevel@tonic-gate 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
9760Sstevel@tonic-gate 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
9770Sstevel@tonic-gate 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
9780Sstevel@tonic-gate 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
9790Sstevel@tonic-gate 					/* check condidtion or error */
9800Sstevel@tonic-gate 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
9810Sstevel@tonic-gate 	uint_t	un_last_resid;		/* keep last resid, for PE */
9820Sstevel@tonic-gate 	uint_t	un_last_count;		/* keep last count, for PE */
9830Sstevel@tonic-gate 	struct 	kstat *un_stats;	/* for I/O statistics */
9840Sstevel@tonic-gate 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
9850Sstevel@tonic-gate 	struct	buf *un_wf;		/* head of write queue */
9860Sstevel@tonic-gate 	struct	buf *un_wl;		/* tail of write queue */
9870Sstevel@tonic-gate 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
9880Sstevel@tonic-gate 	int	un_maxdma;		/* max dma xfer allowed by HBA */
9890Sstevel@tonic-gate 	uint_t	un_bsize;		/* block size currently being used */
9900Sstevel@tonic-gate 	int	un_maxbsize;		/* max block size allowed by drive */
9910Sstevel@tonic-gate 	uint_t	un_minbsize;		/* min block size allowed by drive */
9920Sstevel@tonic-gate 	int	un_errno;		/* errno (b_error) */
9930Sstevel@tonic-gate 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
9940Sstevel@tonic-gate 	enum mtio_state	un_mediastate;	/* current media state */
9950Sstevel@tonic-gate 	enum mtio_state	un_specified_mediastate;	/* expected state */
9960Sstevel@tonic-gate 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
9970Sstevel@tonic-gate 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
9980Sstevel@tonic-gate 	opaque_t	un_swr_token;	/* scsi_watch request token */
9990Sstevel@tonic-gate 	uchar_t	un_comp_page;		/* compression page */
10000Sstevel@tonic-gate 	uchar_t	un_rsvd_status;		/* Reservation Status */
10010Sstevel@tonic-gate 	kstat_t *un_errstats;		/* for error statistics */
1002*5628Srralphs 	int	un_init_options;	/* Init time drive options */
10030Sstevel@tonic-gate 	int	un_save_fileno;		/* Save here for recovery */
10040Sstevel@tonic-gate 	daddr_t	un_save_blkno;		/* Save here for recovery */
10054549Srralphs 	uchar_t un_restore_pos;		/* Indication to do recovery */
10064549Srralphs 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
10070Sstevel@tonic-gate 	uchar_t	un_silent_skip;		/* to catch short reads */
10084549Srralphs 	short	un_tids_at_suspend;	/* timeouts set at suspend */
10094549Srralphs 	kcondvar_t un_tape_busy_cv;	/* busy cv */
10104549Srralphs 	kcondvar_t un_suspend_cv;	/* busy cv */
10110Sstevel@tonic-gate 					/* restore on close */
10120Sstevel@tonic-gate 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
10130Sstevel@tonic-gate 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
10140Sstevel@tonic-gate 	uchar_t	un_rqs_state;		/* see define below */
10154549Srralphs 	struct scsi_extended_sense
10164549Srralphs 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
10170Sstevel@tonic-gate 	uchar_t	un_data_mod;		/* Device required data mod */
10182537Srralphs 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
10192537Srralphs 	int un_max_cdb_sz;		/* max cdb size to use */
10204549Srralphs 	read_p_types un_read_pos_type;
10214549Srralphs 	read_pos_data_t *un_read_pos_data;
10225077Sbz211116 	struct mterror_entry_stack *un_error_entry_stk;
10235077Sbz211116 					/* latest sense cmd buffer */
1024177Scz147101 
10255251Smrj #ifdef	__x86
1026177Scz147101 	ddi_dma_handle_t un_contig_mem_hdl;
1027177Scz147101 	struct contig_mem *un_contig_mem;
1028177Scz147101 	int un_contig_mem_available_num;
1029177Scz147101 	int un_contig_mem_total_num;
1030932Scz147101 	size_t un_max_contig_mem_len;
1031177Scz147101 	kcondvar_t un_contig_mem_cv;
10325251Smrj 	int un_maxdma_arch;		/* max dma xfer allowed by HBA & arch */
1033177Scz147101 #endif
1034*5628Srralphs 	caddr_t un_media_id;
1035*5628Srralphs 	int un_media_id_len;
1036*5628Srralphs 	int (*un_media_id_method)(struct scsi_tape *, int (*)());
1037*5628Srralphs 	buf_t *un_recov_buf;		/* buf to recover failed commands */
1038*5628Srralphs 	kcondvar_t un_recov_buf_cv;	/* cv for buf un_recov_buf */
1039*5628Srralphs 	uchar_t un_recov_buf_busy;
1040*5628Srralphs #ifdef _KERNEL
1041*5628Srralphs 	ddi_taskq_t *un_recov_taskq;
1042*5628Srralphs #else
1043*5628Srralphs 	void *un_recov_taskq;
1044*5628Srralphs #endif
1045*5628Srralphs 	tapepos_t un_running;
1046*5628Srralphs 	uchar_t un_unit_attention_flags;
10470Sstevel@tonic-gate };
10483138Sfrits 
1049*5628Srralphs typedef int (*bufunc_t)(struct scsi_tape *, int, int64_t, int);
1050*5628Srralphs typedef int (*ubufunc_t)(struct scsi_tape *, struct uscsi_cmd *, int);
1051*5628Srralphs 
10523138Sfrits 
10530Sstevel@tonic-gate /*
10540Sstevel@tonic-gate  * device error kstats
10550Sstevel@tonic-gate  */
10560Sstevel@tonic-gate struct st_errstats {
10570Sstevel@tonic-gate 	struct kstat_named	st_softerrs;
10580Sstevel@tonic-gate 	struct kstat_named	st_harderrs;
10590Sstevel@tonic-gate 	struct kstat_named	st_transerrs;
10600Sstevel@tonic-gate 	struct kstat_named	st_vid;
10610Sstevel@tonic-gate 	struct kstat_named	st_pid;
10620Sstevel@tonic-gate 	struct kstat_named	st_revision;
10630Sstevel@tonic-gate 	struct kstat_named	st_serial;
10640Sstevel@tonic-gate };
10650Sstevel@tonic-gate 
10660Sstevel@tonic-gate /*
10670Sstevel@tonic-gate  * generic log page struct
10680Sstevel@tonic-gate  */
10690Sstevel@tonic-gate struct log_page {
10700Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
10710Sstevel@tonic-gate 	uchar_t	code	:6,	/* page code number */
10720Sstevel@tonic-gate 			:2;	/* reserved */
10730Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
10740Sstevel@tonic-gate 	uchar_t		:2,	/* reserved */
10750Sstevel@tonic-gate 		code	:6;	/* page code number */
10760Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
10770Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
10780Sstevel@tonic-gate 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
10790Sstevel@tonic-gate 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
10800Sstevel@tonic-gate 	/*
10810Sstevel@tonic-gate 	 * Log parameters follow right after this...
10820Sstevel@tonic-gate 	 */
10830Sstevel@tonic-gate };
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate /*
10860Sstevel@tonic-gate  * generic log page parameter struct
10870Sstevel@tonic-gate  */
10880Sstevel@tonic-gate struct log_param {
10890Sstevel@tonic-gate 	uchar_t	pc_hi;			/* parameter code (msb) */
10900Sstevel@tonic-gate 	uchar_t	pc_lo;			/* parameter code (lsb) */
10910Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
10920Sstevel@tonic-gate 	uchar_t		lp	: 1,	/* list parameter */
10930Sstevel@tonic-gate 				: 1,	/* reserved */
10940Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
10950Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
10960Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
10970Sstevel@tonic-gate 			ds	: 1,	/* disable save */
10980Sstevel@tonic-gate 			du	: 1;	/* disable update */
10990Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
11000Sstevel@tonic-gate 	uchar_t		du	: 1,	/* disable update */
11010Sstevel@tonic-gate 			ds	: 1,	/* disable save */
11020Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
11030Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
11040Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
11050Sstevel@tonic-gate 				: 1,	/* reserved */
11060Sstevel@tonic-gate 			lp	: 1;	/* list parameter */
11070Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
11080Sstevel@tonic-gate 	uchar_t	length;		/* length of bytes to follow */
11090Sstevel@tonic-gate 	/*
11100Sstevel@tonic-gate 	 * Parameter values follow right after this...
11110Sstevel@tonic-gate 	 */
11120Sstevel@tonic-gate };
11130Sstevel@tonic-gate /*
11140Sstevel@tonic-gate  * TapeAlert structures
11150Sstevel@tonic-gate  */
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate struct st_tape_alert_parameter {
11180Sstevel@tonic-gate 	struct log_param log_param;
11190Sstevel@tonic-gate 	uchar_t	param_value;
11200Sstevel@tonic-gate };
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate struct st_tape_alert {
11230Sstevel@tonic-gate 	struct log_page log_page;
11240Sstevel@tonic-gate 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
11250Sstevel@tonic-gate };
11260Sstevel@tonic-gate 
11270Sstevel@tonic-gate #define	TAPE_ALERT_PARAMETER_LENGTH \
11280Sstevel@tonic-gate 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate struct log_sequential_page_parameter {
11310Sstevel@tonic-gate 	struct log_param log_param;
11320Sstevel@tonic-gate 	uchar_t param_value[8];
11330Sstevel@tonic-gate };
11340Sstevel@tonic-gate 
11350Sstevel@tonic-gate struct log_sequential_page {
11360Sstevel@tonic-gate 	struct log_page log_page;
11370Sstevel@tonic-gate 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
11380Sstevel@tonic-gate };
11390Sstevel@tonic-gate 
11400Sstevel@tonic-gate #if !defined(__lint)
11410Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
11420Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
11430Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
11440Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
11453138Sfrits _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
11460Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
11470Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
11480Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("save sharing",
11490Sstevel@tonic-gate 	scsi_tape::un_allow_large_xfer
11500Sstevel@tonic-gate 	scsi_tape::un_maxbsize
11510Sstevel@tonic-gate 	scsi_tape::un_maxdma
11520Sstevel@tonic-gate ))
11535251Smrj #ifdef	__x86
11543138Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
11553138Sfrits _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
11563138Sfrits #endif
11570Sstevel@tonic-gate #endif
11580Sstevel@tonic-gate 
11590Sstevel@tonic-gate 
11600Sstevel@tonic-gate /*
11610Sstevel@tonic-gate  * Power management state
11620Sstevel@tonic-gate  */
11630Sstevel@tonic-gate #define	ST_PWR_NORMAL				0
11640Sstevel@tonic-gate #define	ST_PWR_SUSPENDED			1
11650Sstevel@tonic-gate 
11660Sstevel@tonic-gate 
11674549Srralphs #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
11680Sstevel@tonic-gate 
11690Sstevel@tonic-gate /* un_rqs_state codes */
11700Sstevel@tonic-gate 
11710Sstevel@tonic-gate #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
11720Sstevel@tonic-gate #define	ST_RQS_VALID		0x2	/* RQS data is valid */
11730Sstevel@tonic-gate #define	ST_RQS_READ		0x4	/* RQS data was read */
11740Sstevel@tonic-gate #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
11750Sstevel@tonic-gate 
11760Sstevel@tonic-gate /*
1177*5628Srralphs  * st_intr codes
11780Sstevel@tonic-gate  */
1179*5628Srralphs typedef enum {
1180*5628Srralphs 	COMMAND_DONE,
1181*5628Srralphs 	COMMAND_DONE_ERROR,
1182*5628Srralphs 	COMMAND_DONE_ERROR_RECOVERED,
1183*5628Srralphs 	QUE_COMMAND,
1184*5628Srralphs 	QUE_BUSY_COMMAND,
1185*5628Srralphs 	QUE_SENSE,
1186*5628Srralphs 	JUST_RETURN,
1187*5628Srralphs 	COMMAND_DONE_EACCES,
1188*5628Srralphs 	QUE_LAST_COMMAND,
1189*5628Srralphs 	COMMAND_TIMEOUT,
1190*5628Srralphs 	PATH_FAILED,
1191*5628Srralphs 	DEVICE_RESET,
1192*5628Srralphs 	DEVICE_TAMPER,
1193*5628Srralphs 	ATTEMPT_RETRY
1194*5628Srralphs }errstate;
1195*5628Srralphs #ifdef _KERNEL
1196*5628Srralphs typedef struct {
1197*5628Srralphs 	struct scsi_pkt ei_failed_pkt;
1198*5628Srralphs 	struct scsi_arq_status ei_failing_status;
1199*5628Srralphs 	tapepos_t ei_expected_pos;
1200*5628Srralphs 	errstate ei_error_type;
1201*5628Srralphs 	buf_t *ei_failing_bp;
1202*5628Srralphs } st_err_info;
1203*5628Srralphs #endif
12040Sstevel@tonic-gate 
12050Sstevel@tonic-gate 
12060Sstevel@tonic-gate /*
12070Sstevel@tonic-gate  *	Reservation Status
12080Sstevel@tonic-gate  *
12090Sstevel@tonic-gate  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
12100Sstevel@tonic-gate  *		         in between opens and also to indicate the reservation
12110Sstevel@tonic-gate  *		         has not been done till now.
12120Sstevel@tonic-gate  * ST_RELEASE	        -Tape Unit is Released.
12130Sstevel@tonic-gate  * ST_RESERVE	        -Tape Unit is Reserved.
12140Sstevel@tonic-gate  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
12150Sstevel@tonic-gate  *
12160Sstevel@tonic-gate  */
12170Sstevel@tonic-gate #define	ST_INIT_RESERVE			0x001
12180Sstevel@tonic-gate #define	ST_RELEASE			0x002
12190Sstevel@tonic-gate #define	ST_RESERVE			0x004
12200Sstevel@tonic-gate #define	ST_PRESERVE_RESERVE		0x008
12210Sstevel@tonic-gate #define	ST_RESERVATION_CONFLICT 	0x010
12220Sstevel@tonic-gate #define	ST_LOST_RESERVE			0x020
12231697Srralphs #define	ST_APPLICATION_RESERVATIONS	0x040
1224*5628Srralphs #define	ST_INITIATED_RESET		0x080
12251697Srralphs #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
12261697Srralphs 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
12270Sstevel@tonic-gate 
12281697Srralphs /*
12291697Srralphs  * Service action defines for Persistant Reservation Commands
12301697Srralphs  */
12311697Srralphs #define	ST_SA_SCSI3_REGISTER			0x00
12321697Srralphs #define	ST_SA_SCSI3_RESERVE			0x01
12331697Srralphs #define	ST_SA_SCSI3_RELEASE			0x02
12341697Srralphs #define	ST_SA_SCSI3_CLEAR			0x03
12351697Srralphs #define	ST_SA_SCSI3_PREEMPT			0x04
12361697Srralphs #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
12371697Srralphs #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
12381697Srralphs #define	ST_SA_MASK				0x1f
12390Sstevel@tonic-gate 
12400Sstevel@tonic-gate #define	ST_RESERVATION_DELAY		500000
12410Sstevel@tonic-gate 
12420Sstevel@tonic-gate /*
12430Sstevel@tonic-gate  * Asynch I/O tunables
12440Sstevel@tonic-gate  */
12450Sstevel@tonic-gate #define	ST_MAX_THROTTLE		4
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate /*
12480Sstevel@tonic-gate  * 60 minutes seems a reasonable amount of time
12490Sstevel@tonic-gate  * to wait for tape space operations to complete.
12500Sstevel@tonic-gate  *
12510Sstevel@tonic-gate  */
12520Sstevel@tonic-gate #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
12530Sstevel@tonic-gate #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
12540Sstevel@tonic-gate 
12550Sstevel@tonic-gate /*
12560Sstevel@tonic-gate  * 2 minutes seems a reasonable amount of time
12570Sstevel@tonic-gate  * to wait for tape i/o operations to complete.
12580Sstevel@tonic-gate  *
12590Sstevel@tonic-gate  */
12600Sstevel@tonic-gate #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
12610Sstevel@tonic-gate #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
12620Sstevel@tonic-gate 
12630Sstevel@tonic-gate 
12640Sstevel@tonic-gate /*
12650Sstevel@tonic-gate  * 10 seconds is what we'll wait if we get a Busy Status back
12660Sstevel@tonic-gate  */
12670Sstevel@tonic-gate #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
12680Sstevel@tonic-gate #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
12690Sstevel@tonic-gate #define	ST_INTERRUPT_CONTEXT	1
12700Sstevel@tonic-gate #define	ST_START_CONTEXT	2
12710Sstevel@tonic-gate 
12720Sstevel@tonic-gate /*
12730Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
12740Sstevel@tonic-gate  *
12750Sstevel@tonic-gate  * XXX This includes retries due to transport failure as well as
12760Sstevel@tonic-gate  * XXX busy timeouts- Need to distinguish between Target and Transport
12770Sstevel@tonic-gate  * XXX failure.
12780Sstevel@tonic-gate  */
12790Sstevel@tonic-gate 
12800Sstevel@tonic-gate #define	ST_RETRY_COUNT		20
12810Sstevel@tonic-gate 
12820Sstevel@tonic-gate /*
12830Sstevel@tonic-gate  * Number of times to retry a failed selection
12840Sstevel@tonic-gate  */
12850Sstevel@tonic-gate #define	ST_SEL_RETRY_COUNT		2
12860Sstevel@tonic-gate 
12870Sstevel@tonic-gate /*
12880Sstevel@tonic-gate  * es_code value for deferred error
12890Sstevel@tonic-gate  * should be moved to sense.h
12900Sstevel@tonic-gate  */
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate #define	ST_DEFERRED_ERROR		0x01
12930Sstevel@tonic-gate 
12940Sstevel@tonic-gate /*
12950Sstevel@tonic-gate  * Maximum number of units (determined by minor device byte)
12960Sstevel@tonic-gate  */
12970Sstevel@tonic-gate #define	ST_MAXUNIT	128
12980Sstevel@tonic-gate 
12990Sstevel@tonic-gate /*
13000Sstevel@tonic-gate  * Time to wait for completion of a command before cancelling it.
13010Sstevel@tonic-gate  * For SUSPEND use only
13020Sstevel@tonic-gate  */
13030Sstevel@tonic-gate #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
13040Sstevel@tonic-gate 
13050Sstevel@tonic-gate #ifndef	SECSIZE
13060Sstevel@tonic-gate #define	SECSIZE	512
13070Sstevel@tonic-gate #endif
13080Sstevel@tonic-gate #ifndef	SECDIV
13090Sstevel@tonic-gate #define	SECDIV	9
13100Sstevel@tonic-gate #endif
13110Sstevel@tonic-gate 
13120Sstevel@tonic-gate /*
13130Sstevel@tonic-gate  * convenient defines
13140Sstevel@tonic-gate  */
1315*5628Srralphs #define	ST_SCSI_DEVP		(un->un_sd)
13160Sstevel@tonic-gate #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
13170Sstevel@tonic-gate #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
13180Sstevel@tonic-gate #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
13190Sstevel@tonic-gate #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
13200Sstevel@tonic-gate #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
13210Sstevel@tonic-gate 
13220Sstevel@tonic-gate #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
13230Sstevel@tonic-gate #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
13240Sstevel@tonic-gate #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
13250Sstevel@tonic-gate #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
13260Sstevel@tonic-gate #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
13270Sstevel@tonic-gate #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
13280Sstevel@tonic-gate #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
13290Sstevel@tonic-gate #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
13300Sstevel@tonic-gate #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
13310Sstevel@tonic-gate 
13320Sstevel@tonic-gate #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
13330Sstevel@tonic-gate 	((un)->un_state == ST_STATE_SENSING && \
13340Sstevel@tonic-gate 		(un)->un_laststate == ST_STATE_CLOSING))
13350Sstevel@tonic-gate 
13360Sstevel@tonic-gate #define	ASYNC_CMD	0
13370Sstevel@tonic-gate #define	SYNC_CMD	1
13380Sstevel@tonic-gate 
13390Sstevel@tonic-gate #define	st_bioerror(bp, error) \
13400Sstevel@tonic-gate 		{ bioerror(bp, error); \
13410Sstevel@tonic-gate 		un->un_errno = error; }
13420Sstevel@tonic-gate 
13430Sstevel@tonic-gate /*
13440Sstevel@tonic-gate  * Macros for internal coding of count for SPACE command:
13450Sstevel@tonic-gate  *
1346*5628Srralphs  * Top 3 bits of b_bcount define direction and type of space.
1347*5628Srralphs  * Since b_bcount (size_t) is 32 bits on 32 platforms and 64 bits on
1348*5628Srralphs  * 64 bit platforms different defines are used.
1349*5628Srralphs  * if SP_BACKSP is set direction is backward (toward BOP)
1350*5628Srralphs  * The type of space (Blocks, Filemark or sequential filemarks) is
1351*5628Srralphs  * carried in the next 2 bits. The remaining bits a signed count of
1352*5628Srralphs  * how many of that direction and type to do.
13530Sstevel@tonic-gate  */
1354*5628Srralphs #if (SIZE_MAX < UINT64_MAX)
1355*5628Srralphs 
1356*5628Srralphs #define	SP_BLK		UINT32_C(0x00000000)
1357*5628Srralphs #define	SP_FLM		UINT32_C(0x20000000)
1358*5628Srralphs #define	SP_SQFLM	UINT32_C(0x40000000)
1359*5628Srralphs #define	SP_EOD		UINT32_C(0x60000000)
1360*5628Srralphs #define	SP_BACKSP	UINT32_C(0x80000000)
1361*5628Srralphs #define	SP_CMD_MASK	UINT32_C(0x60000000)
1362*5628Srralphs #define	SP_CNT_MASK	UINT32_C(0x1fffffff)
1363*5628Srralphs 
1364*5628Srralphs /* Macros to interpret space cmds */
1365*5628Srralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1366*5628Srralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1367*5628Srralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>29)
1368*5628Srralphs 
1369*5628Srralphs #else /* end of small size_t in buf_t */
1370*5628Srralphs 
1371*5628Srralphs #define	SP_BLK		UINT64_C(0x0000000000000000)
1372*5628Srralphs #define	SP_FLM		UINT64_C(0x2000000000000000)
1373*5628Srralphs #define	SP_SQFLM	UINT64_C(0x4000000000000000)
1374*5628Srralphs #define	SP_EOD		UINT64_C(0x6000000000000000)
1375*5628Srralphs #define	SP_BACKSP	UINT64_C(0x8000000000000000)
1376*5628Srralphs #define	SP_CMD_MASK	UINT64_C(0x6000000000000000)
1377*5628Srralphs #define	SP_CNT_MASK	UINT64_C(0x1fffffffffffffff)
1378*5628Srralphs 
1379*5628Srralphs /* Macros to interpret space cmds */
1380*5628Srralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1381*5628Srralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1382*5628Srralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>61)
1383*5628Srralphs 
1384*5628Srralphs #endif /* end of big size_t in buf_t */
13854549Srralphs 
13864549Srralphs /* Macros to assemble space cmds */
13874549Srralphs #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
13884549Srralphs #define	Fmk(x)		SPACE(SP_FLM, x)
13894549Srralphs #define	Blk(x)		SPACE(SP_BLK, x)
13900Sstevel@tonic-gate 
13914549Srralphs 
13924549Srralphs 
13934549Srralphs /* Defines for byte 4 of load/unload cmd */
13944549Srralphs #define	LD_UNLOAD	0
13954549Srralphs #define	LD_LOAD		1
13964549Srralphs #define	LD_RETEN	2
13974549Srralphs #define	LD_EOT		4
13984549Srralphs #define	LD_HOLD		8
13994549Srralphs 
14004549Srralphs /* Defines for byte 4 of prevent/allow media removal */
14014549Srralphs #define	MR_UNLOCK	0
14024549Srralphs #define	MR_LOCK		1
14030Sstevel@tonic-gate 
14040Sstevel@tonic-gate #define	GET_SOFT_STATE(dev)						\
14050Sstevel@tonic-gate 	register struct scsi_tape *un;					\
14060Sstevel@tonic-gate 	register int instance;						\
14070Sstevel@tonic-gate 									\
14080Sstevel@tonic-gate 	instance = MTUNIT(dev);						\
14090Sstevel@tonic-gate 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
14100Sstevel@tonic-gate 		return (ENXIO);
14110Sstevel@tonic-gate 
14120Sstevel@tonic-gate /*
14130Sstevel@tonic-gate  * Debugging turned on via conditional compilation switch -DSTDEBUG
14140Sstevel@tonic-gate  */
14150Sstevel@tonic-gate #ifdef DEBUG
14160Sstevel@tonic-gate #define	STDEBUG
14170Sstevel@tonic-gate #endif
14180Sstevel@tonic-gate 
14190Sstevel@tonic-gate #ifdef	STDEBUG
1420*5628Srralphs #define	DEBUGGING\
1421*5628Srralphs 	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0x7))
14224549Srralphs 
1423*5628Srralphs #define	ST_DARGS(d) st_label, ((d == st_lastdev || d == 0) ?CE_CONT:CE_NOTE)
14240Sstevel@tonic-gate 
14254549Srralphs 	/* initialization */
1426*5628Srralphs #define	ST_DEBUG1	if ((st_debug & 0x7) >= 1) scsi_log
14270Sstevel@tonic-gate #define	ST_DEBUG	ST_DEBUG1
14280Sstevel@tonic-gate 
14294549Srralphs 	/* errors and UA's */
1430*5628Srralphs #define	ST_DEBUG2	if ((st_debug & 0x7) >= 2) scsi_log
14314549Srralphs 
14324549Srralphs 	/* func calls */
1433*5628Srralphs #define	ST_DEBUG3	if ((st_debug & 0x7) >= 3) scsi_log
14344549Srralphs 
14354549Srralphs 	/* ioctl calls */
1436*5628Srralphs #define	ST_DEBUG4	if ((st_debug & 0x7) >= 4) scsi_log
14374549Srralphs 
1438*5628Srralphs #define	ST_DEBUG5	if ((st_debug & 0x7) >= 5) scsi_log
14394549Srralphs 
14404549Srralphs 	/* full data tracking */
1441*5628Srralphs #define	ST_DEBUG6	if ((st_debug & 0x7) >= 6) scsi_log
14420Sstevel@tonic-gate 
1443*5628Srralphs 	/* debug error recovery */
1444*5628Srralphs #define	ST_RECOV	if (st_debug & 0x8) scsi_log
14454549Srralphs 
14464549Srralphs 	/* Entry Point Functions */
1447*5628Srralphs #define	ST_ENTR(d, fn)\
1448*5628Srralphs     if (st_debug & 0x10) { scsi_log(d, ST_DARGS(d), #fn);\
1449*5628Srralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
14504549Srralphs 
14514549Srralphs 	/* Non-Entry Point Functions */
1452*5628Srralphs #define	ST_FUNC(d, fn)\
1453*5628Srralphs     if (st_debug & 0x20) { scsi_log(d, ST_DARGS(d), #fn);\
1454*5628Srralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
14554549Srralphs 
14564549Srralphs 	/* Space Information */
14574549Srralphs #define	ST_SPAC		if (st_debug & 0x40) scsi_log
14584549Srralphs 
14594549Srralphs 	/* CDB's sent */
1460*5628Srralphs #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) { \
1461*5628Srralphs     st_print_cdb(d, ST_DARGS(d), cmnt, cdb);\
1462*5628Srralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1463*5628Srralphs 	/* sense data */
1464*5628Srralphs #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) { \
1465*5628Srralphs     st_clean_print(d, ST_DARGS(d), cmnt, sense, size);\
1466*5628Srralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1467*5628Srralphs 	/* position data */
1468*5628Srralphs #define	ST_POS(d, cmnt, pdata) if (st_debug & 0x400) { \
1469*5628Srralphs     st_print_position(d, ST_DARGS(d), cmnt, pdata);\
1470*5628Srralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1471*5628Srralphs 
14720Sstevel@tonic-gate 
14730Sstevel@tonic-gate #else
14740Sstevel@tonic-gate 
14750Sstevel@tonic-gate #define	st_debug	(0)
14760Sstevel@tonic-gate #define	DEBUGGING	(0)
14770Sstevel@tonic-gate #define	ST_DEBUG	if (0) scsi_log
14780Sstevel@tonic-gate #define	ST_DEBUG1	if (0) scsi_log
14790Sstevel@tonic-gate #define	ST_DEBUG2	if (0) scsi_log
14800Sstevel@tonic-gate #define	ST_DEBUG3	if (0) scsi_log
14810Sstevel@tonic-gate #define	ST_DEBUG4	if (0) scsi_log
14820Sstevel@tonic-gate #define	ST_DEBUG5	if (0) scsi_log
14830Sstevel@tonic-gate #define	ST_DEBUG6	if (0) scsi_log
1484*5628Srralphs #define	ST_RECOV	if (0) scsi_log
14850Sstevel@tonic-gate 
14864549Srralphs #define	ST_ENTR(d, fn)
14874549Srralphs #define	ST_FUNC(d, fn)
14884549Srralphs #define	ST_SPAC		if (0) scsi_log
14894549Srralphs #define	ST_CDB(d, cmnt, cdb)
14904549Srralphs #define	ST_SENSE(d, cmnt, sense, size)
1491*5628Srralphs #define	ST_SENSE(d, cmnt, sense, size)
1492*5628Srralphs #define	ST_POS(d, cmnt, pdata)
14934549Srralphs 
14940Sstevel@tonic-gate #endif
14950Sstevel@tonic-gate 
14960Sstevel@tonic-gate /*
14970Sstevel@tonic-gate  * Media access values
14980Sstevel@tonic-gate  */
14990Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
15000Sstevel@tonic-gate 
15010Sstevel@tonic-gate /*
15020Sstevel@tonic-gate  * SCSI tape mode sense page information
15030Sstevel@tonic-gate  */
15040Sstevel@tonic-gate #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
15050Sstevel@tonic-gate #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
15060Sstevel@tonic-gate #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
15070Sstevel@tonic-gate #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
15080Sstevel@tonic-gate 
15090Sstevel@tonic-gate /*
15100Sstevel@tonic-gate  * SCSI tape data compression Page definition.
15110Sstevel@tonic-gate  */
15120Sstevel@tonic-gate #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
15130Sstevel@tonic-gate 
15140Sstevel@tonic-gate 
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate /*
15170Sstevel@tonic-gate  * maxbsize values
15180Sstevel@tonic-gate  */
15190Sstevel@tonic-gate #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
15200Sstevel@tonic-gate 
15210Sstevel@tonic-gate #define	ONE_MEG			(1024 * 1024)
15220Sstevel@tonic-gate 
15230Sstevel@tonic-gate /*
15240Sstevel@tonic-gate  * generic soft error reporting
15250Sstevel@tonic-gate  *
15260Sstevel@tonic-gate  * What we are doing here is allowing a greater number of errors to occur on
15270Sstevel@tonic-gate  * smaller transfers (i.e. usually at the beginning of the tape), than on
15280Sstevel@tonic-gate  * the rest of the tape.
15290Sstevel@tonic-gate  *
15300Sstevel@tonic-gate  * A small transfer is defined as :
15310Sstevel@tonic-gate  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
15320Sstevel@tonic-gate  *
15330Sstevel@tonic-gate  * A larget tranfer is defined as :
15340Sstevel@tonic-gate  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
15350Sstevel@tonic-gate  *
15360Sstevel@tonic-gate  */
15370Sstevel@tonic-gate #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
15380Sstevel@tonic-gate #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
15390Sstevel@tonic-gate 
15400Sstevel@tonic-gate /*
15410Sstevel@tonic-gate  * soft error reporting for exabyte
15420Sstevel@tonic-gate  */
15430Sstevel@tonic-gate #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
15440Sstevel@tonic-gate 
15450Sstevel@tonic-gate #define	SENSE_19_BITS  \
15460Sstevel@tonic-gate 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
15470Sstevel@tonic-gate #define	SENSE_20_BITS  \
15480Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
15490Sstevel@tonic-gate #define	SENSE_21_BITS  \
15500Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
15510Sstevel@tonic-gate 
15520Sstevel@tonic-gate /* these are defined in percentages */
15530Sstevel@tonic-gate #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
15540Sstevel@tonic-gate #define	EXABYTE_READ_ERROR_THRESHOLD	3
15550Sstevel@tonic-gate /*
15560Sstevel@tonic-gate  * minumum amount of data transfer(MB) for checking soft error rate.
15570Sstevel@tonic-gate  */
15580Sstevel@tonic-gate #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
15590Sstevel@tonic-gate 
15600Sstevel@tonic-gate #define	CLN	0x8
15610Sstevel@tonic-gate #define	CLND	0x10
15620Sstevel@tonic-gate 
15630Sstevel@tonic-gate /*
15640Sstevel@tonic-gate  * soft error reporting for Archive 4mm DAT
15650Sstevel@tonic-gate  */
15660Sstevel@tonic-gate 
15670Sstevel@tonic-gate #define	LOG_SENSE_LENGTH		0xff
15680Sstevel@tonic-gate #define	MIN_LOG_SENSE_LENGTH		0x2b
15690Sstevel@tonic-gate #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
15700Sstevel@tonic-gate #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
15710Sstevel@tonic-gate #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
15720Sstevel@tonic-gate #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
15730Sstevel@tonic-gate 
15740Sstevel@tonic-gate /*
15750Sstevel@tonic-gate  * ST timeouts that need to be cancelled for suspend
15760Sstevel@tonic-gate  */
15770Sstevel@tonic-gate #define	ST_HIB_TID	0x01
15780Sstevel@tonic-gate #define	ST_DELAY_TID	0x02
15790Sstevel@tonic-gate 
15800Sstevel@tonic-gate #ifdef	__cplusplus
15810Sstevel@tonic-gate }
15820Sstevel@tonic-gate #endif
15830Sstevel@tonic-gate 
15840Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1585