17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e213afc3Srralphs  * Common Development and Distribution License (the "License").
6e213afc3Srralphs  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22c6914c10Srralphs  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_STDEF_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_STDEF_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
31f3531714Scz #include <sys/sunddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/note.h>
337c478bd9Sstevel@tonic-gate #include <sys/condvar.h>
347c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
35*f218e94bSrralphs #include <sys/int_limits.h>
367c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
37c6914c10Srralphs #include <sys/scsi/generic/sense.h>
387c478bd9Sstevel@tonic-gate #include <sys/mtio.h>
39*f218e94bSrralphs #include <sys/taskq.h>
40*f218e94bSrralphs #include <sys/taskq_impl.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Defines for SCSI tape drives.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Maximum variable length record size for a single request
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE	65535
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
577c478bd9Sstevel@tonic-gate  * then the following define is used.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
627c478bd9Sstevel@tonic-gate #define	INF 1000000000
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Supported tape device types plus default type for opening.
667c478bd9Sstevel@tonic-gate  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
677c478bd9Sstevel@tonic-gate  * Types 14 - 1f, are 1/4-inch cartridge drives.
687c478bd9Sstevel@tonic-gate  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
697c478bd9Sstevel@tonic-gate  * Types 28+, are rdat (vcr) drives.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #define	ST_TYPE_INVALID		0x00
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
747c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
777c478bd9Sstevel@tonic-gate #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
787c478bd9Sstevel@tonic-gate #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
797c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
827c478bd9Sstevel@tonic-gate #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
837c478bd9Sstevel@tonic-gate #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
847c478bd9Sstevel@tonic-gate #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
857c478bd9Sstevel@tonic-gate #define	ST_TYPE_HP	MT_ISHP		/* HP */
867c478bd9Sstevel@tonic-gate #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
877c478bd9Sstevel@tonic-gate #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
887c478bd9Sstevel@tonic-gate #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
917c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
927c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
937c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
947c478bd9Sstevel@tonic-gate #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
957c478bd9Sstevel@tonic-gate #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
967c478bd9Sstevel@tonic-gate #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
977c478bd9Sstevel@tonic-gate #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
987c478bd9Sstevel@tonic-gate #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
997c478bd9Sstevel@tonic-gate #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
1007c478bd9Sstevel@tonic-gate #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
1015988135dSrralphs #define	ST_TYPE_AIT	MT_ISAIT	/* Sony AIT I, II, III and SAIT */
1025988135dSrralphs #define	ST_LAST_TYPE	ST_TYPE_AIT	/* Add new above type and change this */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* Internal flags */
1067c478bd9Sstevel@tonic-gate #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
1077c478bd9Sstevel@tonic-gate 					/* alloc'ed from the st.conf entry, */
1087c478bd9Sstevel@tonic-gate 					/* instead of being used from the */
1097c478bd9Sstevel@tonic-gate 					/* st_drivetypes array. */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Defines for supported drive options
1137c478bd9Sstevel@tonic-gate  *
1147c478bd9Sstevel@tonic-gate  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
1157c478bd9Sstevel@tonic-gate  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
1167c478bd9Sstevel@tonic-gate  */
1177c478bd9Sstevel@tonic-gate #define	ST_VARIABLE		0x001	/* Device supports variable	*/
1187c478bd9Sstevel@tonic-gate 					/* length record sizes		*/
1197c478bd9Sstevel@tonic-gate #define	ST_QIC			0x002	/* QIC tape device 		*/
1207c478bd9Sstevel@tonic-gate #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
1217c478bd9Sstevel@tonic-gate #define	ST_BSF			0x008	/* Device supports backspace	*/
1227c478bd9Sstevel@tonic-gate 					/* file as in mt(1) bsf : 	*/
1237c478bd9Sstevel@tonic-gate 					/* backspace over EOF marks.	*/
1247c478bd9Sstevel@tonic-gate 					/* Devices not supporting bsf 	*/
1257c478bd9Sstevel@tonic-gate 					/* will fail with ENOTTY upon	*/
1267c478bd9Sstevel@tonic-gate 					/* use of bsf			*/
1277c478bd9Sstevel@tonic-gate #define	ST_BSR			0x010	/* Device supports backspace	*/
1287c478bd9Sstevel@tonic-gate 					/* record as in mt(1) bsr :	*/
1297c478bd9Sstevel@tonic-gate 					/* backspace over records. If	*/
1307c478bd9Sstevel@tonic-gate 					/* the device does not support 	*/
1317c478bd9Sstevel@tonic-gate 					/* bsr, the st driver emulates	*/
1327c478bd9Sstevel@tonic-gate 					/* the action by rewinding the	*/
1337c478bd9Sstevel@tonic-gate 					/* tape and using forward space	*/
1347c478bd9Sstevel@tonic-gate 					/* file (fsf) to the correct	*/
1357c478bd9Sstevel@tonic-gate 					/* file and then uses forward	*/
1367c478bd9Sstevel@tonic-gate 					/* space record (fsr) to the	*/
1377c478bd9Sstevel@tonic-gate 					/* correct  record		*/
1387c478bd9Sstevel@tonic-gate #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
1397c478bd9Sstevel@tonic-gate 					/* than normal to erase		*/
1407c478bd9Sstevel@tonic-gate #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
1417c478bd9Sstevel@tonic-gate 					/* Device can figure out the	*/
1427c478bd9Sstevel@tonic-gate 					/* tape density automatically,	*/
1437c478bd9Sstevel@tonic-gate 					/* without issuing a		*/
1447c478bd9Sstevel@tonic-gate 					/* mode-select/mode-sense 	*/
1457c478bd9Sstevel@tonic-gate #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
1467c478bd9Sstevel@tonic-gate 					/* This disables the device's	*/
1477c478bd9Sstevel@tonic-gate 					/* ability for buffered	writes	*/
1487c478bd9Sstevel@tonic-gate 					/* I.e. The device acknowledges	*/
1497c478bd9Sstevel@tonic-gate 					/* write completion after the	*/
1507c478bd9Sstevel@tonic-gate 					/* data is written to the	*/
1517c478bd9Sstevel@tonic-gate 					/* device's buffer, but before	*/
1527c478bd9Sstevel@tonic-gate 					/* all the data is actually	*/
1537c478bd9Sstevel@tonic-gate 					/* written to tape		*/
1547c478bd9Sstevel@tonic-gate #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
1557c478bd9Sstevel@tonic-gate 					/* parity while talking to it. 	*/
1567c478bd9Sstevel@tonic-gate #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
1577c478bd9Sstevel@tonic-gate 					/* of Data) has been reached.	*/
1587c478bd9Sstevel@tonic-gate 					/* If the device knows EOD, st	*/
1597c478bd9Sstevel@tonic-gate 					/* uses fast file skipping.	*/
1607c478bd9Sstevel@tonic-gate 					/* If it does not know EOD,	*/
1617c478bd9Sstevel@tonic-gate 					/* file skipping happens one	*/
1627c478bd9Sstevel@tonic-gate 					/* file at a time. 		*/
1637c478bd9Sstevel@tonic-gate #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
1647c478bd9Sstevel@tonic-gate 					/* the st driver is unloaded &	*/
1657c478bd9Sstevel@tonic-gate 					/* loaded again; e.g. will	*/
1667c478bd9Sstevel@tonic-gate 					/* return the correct inquiry	*/
1677c478bd9Sstevel@tonic-gate 					/* string			*/
1687c478bd9Sstevel@tonic-gate #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
1697c478bd9Sstevel@tonic-gate 					/* close to report soft errors.	*/
1707c478bd9Sstevel@tonic-gate 					/* Currently only Exabyte and	*/
1717c478bd9Sstevel@tonic-gate 					/* DAT drives support this	*/
1727c478bd9Sstevel@tonic-gate 					/* feature.  			*/
1737c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
1747c478bd9Sstevel@tonic-gate 					/* timeouts for normal		*/
1757c478bd9Sstevel@tonic-gate 					/* operation			*/
1767c478bd9Sstevel@tonic-gate #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
1777c478bd9Sstevel@tonic-gate 					/* driver and pre-acked to the	*/
1787c478bd9Sstevel@tonic-gate 					/* application 			*/
1797c478bd9Sstevel@tonic-gate #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
1807c478bd9Sstevel@tonic-gate 					/* devices only. If flag is	*/
1817c478bd9Sstevel@tonic-gate 					/* set, then don't limit	*/
1827c478bd9Sstevel@tonic-gate 					/* record size to 64k as in	*/
1837c478bd9Sstevel@tonic-gate 					/* pre-Solaris 2.4 releases.	*/
1847c478bd9Sstevel@tonic-gate 					/* The only limit on the	*/
1857c478bd9Sstevel@tonic-gate 					/* record size will be the max	*/
1867c478bd9Sstevel@tonic-gate 					/* record size the device can	*/
1877c478bd9Sstevel@tonic-gate 					/* handle or the max DMA	*/
1887c478bd9Sstevel@tonic-gate 					/* transfer size of the		*/
1897c478bd9Sstevel@tonic-gate 					/* machine, which ever is	*/
1907c478bd9Sstevel@tonic-gate 					/* smaller. Beware of		*/
1917c478bd9Sstevel@tonic-gate 					/* incompatabilities with	*/
1927c478bd9Sstevel@tonic-gate 					/* tapes of pre-Solaris 2.4	*/
1937c478bd9Sstevel@tonic-gate 					/* OS's written with large	*/
1947c478bd9Sstevel@tonic-gate 					/* (>64k) block sizes, as	*/
1957c478bd9Sstevel@tonic-gate 					/* their true block size is	*/
1967c478bd9Sstevel@tonic-gate 					/* a max of approx 64k		*/
1977c478bd9Sstevel@tonic-gate #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
1987c478bd9Sstevel@tonic-gate 					/* configuration page (0x10) to */
1997c478bd9Sstevel@tonic-gate 					/* enable/disable compression	*/
2007c478bd9Sstevel@tonic-gate 					/* instead of density codes for */
2017c478bd9Sstevel@tonic-gate 					/* the "c" and "u" devices	*/
2027c478bd9Sstevel@tonic-gate #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
2037c478bd9Sstevel@tonic-gate 					/* support RESERVE/RELEASE SCSI	*/
2047c478bd9Sstevel@tonic-gate 					/* command. If this is enabled	*/
2057c478bd9Sstevel@tonic-gate 					/* then reserve/release would	*/
2067c478bd9Sstevel@tonic-gate 					/* not be used during open/	*/
2077c478bd9Sstevel@tonic-gate 					/* close for High Availability	*/
2087c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
2097c478bd9Sstevel@tonic-gate 					/* to variable block devices 	*/
2107c478bd9Sstevel@tonic-gate 					/* which support the SILI bit	*/
2117c478bd9Sstevel@tonic-gate 					/* option. It indicates that 	*/
2127c478bd9Sstevel@tonic-gate 					/* the SILI bit will be ignored */
2137c478bd9Sstevel@tonic-gate 					/* during reads  		*/
2147c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
2157c478bd9Sstevel@tonic-gate 					/* EOF marks do not indicate an */
2167c478bd9Sstevel@tonic-gate 					/* EOM. This option is only	*/
2177c478bd9Sstevel@tonic-gate 					/* supported on 1/2" reel tapes */
2187c478bd9Sstevel@tonic-gate #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
2197c478bd9Sstevel@tonic-gate 					/* EXABYTE 8mm tape drives 	*/
2207c478bd9Sstevel@tonic-gate 					/* which support short 		*/
2217c478bd9Sstevel@tonic-gate 					/* filemarks. When this flag 	*/
2227c478bd9Sstevel@tonic-gate 					/* is set, short filemarks 	*/
2237c478bd9Sstevel@tonic-gate 					/* will be used for writing	*/
2247c478bd9Sstevel@tonic-gate 					/* filemarks. 			*/
2257c478bd9Sstevel@tonic-gate #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
2267c478bd9Sstevel@tonic-gate 					/* and the tape is trapped in   */
2277c478bd9Sstevel@tonic-gate 					/* the medium changer, the tape */
2287c478bd9Sstevel@tonic-gate 					/* is automatically ejected	*/
2297c478bd9Sstevel@tonic-gate #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
2307c478bd9Sstevel@tonic-gate 					/* This option applies only to  */
2317c478bd9Sstevel@tonic-gate 					/* IBM MAGSTAR 3590. If this    */
2327c478bd9Sstevel@tonic-gate 					/* flag is set, the st driver   */
2337c478bd9Sstevel@tonic-gate 					/* will retry the last cmd if   */
2347c478bd9Sstevel@tonic-gate 					/* the last error cause a check */
2357c478bd9Sstevel@tonic-gate 					/* condition with error code    */
2367c478bd9Sstevel@tonic-gate 					/* 0x71 and sense code  0x01 	*/
2377c478bd9Sstevel@tonic-gate #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
2387c478bd9Sstevel@tonic-gate 					/* detected to select correct   */
2397c478bd9Sstevel@tonic-gate 					/* density code.		*/
2405988135dSrralphs #define	ST_WORMABLE		0x1000000
2415988135dSrralphs 					/* Drive is capable of doing	*/
2425988135dSrralphs 					/* Write Appends only at EOM	*/
2435988135dSrralphs 					/* if WORM media type is loaded */
2447c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
2457c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2467c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2477c478bd9Sstevel@tonic-gate 					/* byte 21, bitmask 0x08 of	*/
2487c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2497c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
2507c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2517c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2527c478bd9Sstevel@tonic-gate 					/* byte 70, bitmask 0xc0 of	*/
2537c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2547c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
2557c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2567c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2577c478bd9Sstevel@tonic-gate 					/* byte 18, bitmask 0x01 of	*/
2587c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2617c478bd9Sstevel@tonic-gate #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
2627c478bd9Sstevel@tonic-gate 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
2637c478bd9Sstevel@tonic-gate 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
2647c478bd9Sstevel@tonic-gate 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
2657c478bd9Sstevel@tonic-gate 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
2667c478bd9Sstevel@tonic-gate 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
2675988135dSrralphs 	ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate #define	NDENSITIES	MT_NDENSITIES
2707c478bd9Sstevel@tonic-gate #define	NSPEEDS		MT_NSPEEDS
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate /*
2737c478bd9Sstevel@tonic-gate  * defines for Log Sense Pages
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate #define	SUPPORTED_LOG_PAGES_PAGE	0x00
2767c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE		0x0c
2777c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PAGE			0x2e
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * Log Page Control definitions
2817c478bd9Sstevel@tonic-gate  */
2827c478bd9Sstevel@tonic-gate #define	CURRENT_THRESHOLD_VALUES	0x00
2837c478bd9Sstevel@tonic-gate #define	CURRENT_CUMULATIVE_VALUES	0x40
2847c478bd9Sstevel@tonic-gate #define	DEFAULT_THRESHOLD_VALUES	0x80
2857c478bd9Sstevel@tonic-gate #define	DEFAULT_CUMULATIVE_VALUES	0xC0
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * Tape Alert Flag definitions
2897c478bd9Sstevel@tonic-gate  */
2905988135dSrralphs typedef enum {
2915988135dSrralphs 	TAF_READ_WARN			= 0x01,
2925988135dSrralphs 	TAF_WRITE_WARN			= 0x02,
2935988135dSrralphs 	TAF_HARD_ERR			= 0x03,
2945988135dSrralphs 	TAF_MEDIA_ERR			= 0x04,
2955988135dSrralphs 	TAF_READ_FAIL			= 0x05,
2965988135dSrralphs 	TAF_WRITE_FAIL			= 0x06,
2975988135dSrralphs 	TAF_MEDIA_LIFE			= 0x07,
2985988135dSrralphs 	TAF_MEDIA_NOT_DATA_GRADE	= 0x08,
2995988135dSrralphs 	TAF_WRITE_PROTECTED		= 0x09,
3005988135dSrralphs 	TAF_NO_MEDIA_REMOVE		= 0x0A,
3015988135dSrralphs 	TAF_CLEANING_MEDIA		= 0x0B,
3025988135dSrralphs 	TAF_UNSUPPERTED_FORMAT		= 0x0C,
3035988135dSrralphs 	TAF_RECOVERED_TAPE_BREAK	= 0x0D,
3045988135dSrralphs 	TAF_TAPE_BREAK_FAUL		= 0x0E,
3055988135dSrralphs 	TAF_CART_MEM_FAIL		= 0x0F,
3065988135dSrralphs 	TAF_FORCED_EJECT		= 0x10,
3075988135dSrralphs 	TAF_READ_ONLY_FORMAT		= 0x11,
3085988135dSrralphs 	TAF_TAPE_DIR_CORRUPT		= 0x12,
3095988135dSrralphs 	TAF_NEARING_MEDIA_LIFE		= 0x13,
3105988135dSrralphs 	TAF_CLEAN_NOW			= 0x14,
3115988135dSrralphs 	TAF_CLEAN_PERIODIC		= 0x15,
3125988135dSrralphs 	TAF_EXP_CLEAN_CART		= 0x16,
3135988135dSrralphs 	TAF_INVALID_CLEAN_MEDIA		= 0x17,
3145988135dSrralphs 	TAF_RETENSION_REQUEST		= 0x18,
3155988135dSrralphs 	TAF_DUAL_PORT_INTERFACE_ERR	= 0x19,
3165988135dSrralphs 	TAF_COOLING_FAN_FAIL		= 0x1A,
3175988135dSrralphs 	TAF_POWER_SUPPLY_FAIL		= 0x1B,
3185988135dSrralphs 	TAF_POWER_CONSUMPTION		= 0x1C,
3195988135dSrralphs 	TAF_DRIVE_MAINT_REQUEST		= 0x1D,
3205988135dSrralphs 	TAF_HARDWARE_A			= 0x1E,
3215988135dSrralphs 	TAF_HARDWARE_B			= 0x1F,
3225988135dSrralphs 	TAF_INTERFACE			= 0x20,
3235988135dSrralphs 	TAF_EJECT_MEDIA			= 0x21,
3245988135dSrralphs 	TAF_DOWNLOAD_FAIL		= 0x22,
3255988135dSrralphs 	TAF_DRIVE_HUMIDITY		= 0x23,
3265988135dSrralphs 	TAF_DRIVE_TEMP			= 0x24,
3275988135dSrralphs 	TAF_DRIVE_VOLTAGE		= 0x25,
3285988135dSrralphs 	TAF_PREDICTIVE_FAIL		= 0x26,
3295988135dSrralphs 	TAF_DIAG_REQUIRED		= 0x27,
3305988135dSrralphs 	TAF_LOADER_HDWR_A		= 0x28,
3315988135dSrralphs 	TAF_LOADER_STRAY_TAPE		= 0x29,
3325988135dSrralphs 	TAF_LOADER_HDWR_B		= 0x2A,
3335988135dSrralphs 	TAF_LOADER_DOOR			= 0x2B,
3345988135dSrralphs 	TAF_LOADER_HDWR_C		= 0x2C,
3355988135dSrralphs 	TAF_LOADER_MAGAZINE		= 0x2D,
3365988135dSrralphs 	TAF_LOADER_PREDICTIVE_FAIL	= 0x2E,
3375988135dSrralphs 	TAF_LOST_STATISTICS		= 0x32,
3385988135dSrralphs 	TAF_TAPE_DIR_CURRUPT_UNLOAD	= 0x33,
3395988135dSrralphs 	TAF_TAPE_SYS_WRT_FAIL		= 0x34,
3405988135dSrralphs 	TAF_TAPE_SYS_RD_FAIL		= 0x35,
3415988135dSrralphs 	TAF_NO_START_OF_DATA		= 0x36,
3425988135dSrralphs 	TAF_WORM_INTEGRITY		= 0x3B,
3435988135dSrralphs 	TAF_WORM_OVRWRT_ATTEMPT		= 0x3C
3445988135dSrralphs }tape_alert_flags;
3455988135dSrralphs 
3465988135dSrralphs /*
3475988135dSrralphs  * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension
3485988135dSrralphs  * so they reuse TAF_RETENSION_REQUEST.
3495988135dSrralphs  */
3505988135dSrralphs #define	CLEAN_FOR_ERRORS		 0x18
3515988135dSrralphs 
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
3547c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_NOT_SUPPORTED	0x01
3557c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORTED		0x02
3567c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_STILL_DIRTY		0x04
3577c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
3587c478bd9Sstevel@tonic-gate #define	TAPE_PREVIOUSLY_DIRTY		0x10
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_MAX_PARA		64
3617c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
3627c478bd9Sstevel@tonic-gate #define	SEQUENTIAL_NEED_CLN		0x0100
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate  * Parameters
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
3687c478bd9Sstevel@tonic-gate #define	VIDLEN		8	/* size of vendor identifier length */
3697c478bd9Sstevel@tonic-gate #define	PIDLEN		16	/* size of product identifier length */
3707c478bd9Sstevel@tonic-gate #define	VIDPIDLEN	(VIDLEN + PIDLEN)
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate struct st_drivetype {
3747c478bd9Sstevel@tonic-gate 	char	name[ST_NAMESIZE];	/* Name, for debug */
3757c478bd9Sstevel@tonic-gate 	char	length;			/* Length of vendor id */
3767c478bd9Sstevel@tonic-gate 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
3777c478bd9Sstevel@tonic-gate 	char	type;			/* Drive type for driver */
3787c478bd9Sstevel@tonic-gate 	int	bsize;			/* Block size */
3797c478bd9Sstevel@tonic-gate 	int	options;		/* Drive options */
3807c478bd9Sstevel@tonic-gate 	int	max_rretries;		/* Max read retries */
3817c478bd9Sstevel@tonic-gate 	int	max_wretries;		/* Max write retries */
3827c478bd9Sstevel@tonic-gate 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
3837c478bd9Sstevel@tonic-gate 	uchar_t	default_density;	/* default density for this drive */
3847c478bd9Sstevel@tonic-gate 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
3857c478bd9Sstevel@tonic-gate 	ushort_t non_motion_timeout;	/* Inquiry type commands */
3867c478bd9Sstevel@tonic-gate 	ushort_t io_timeout;		/* I/O timeout in seconds */
3877c478bd9Sstevel@tonic-gate 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
3887c478bd9Sstevel@tonic-gate 	ushort_t space_timeout;		/* space cmd timeout in seconds */
3897c478bd9Sstevel@tonic-gate 	ushort_t load_timeout;		/* load tape time in seconds */
3907c478bd9Sstevel@tonic-gate 	ushort_t unload_timeout;	/* unload tape time in seconds */
3917c478bd9Sstevel@tonic-gate 	ushort_t erase_timeout;		/* erase timeout. seconds */
3927c478bd9Sstevel@tonic-gate };
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate #define	MINUTES(val)	((val) * 60)
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate struct comp_mode_page {
3977c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3987c478bd9Sstevel@tonic-gate 	uchar_t	:		6,
3997c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4007c478bd9Sstevel@tonic-gate 		dce:		1;	/* Data Compression Enable */
4017c478bd9Sstevel@tonic-gate 	uchar_t	:		5,
4027c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4037c478bd9Sstevel@tonic-gate 		dde:		1;	/* Data Decompression Enabled */
4047c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4057c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4067c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4077c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4087c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4097c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4107c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4117c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4127c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4137c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4147c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4157c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4187c478bd9Sstevel@tonic-gate 	uchar_t	dce:		1,	/* Data Compression Enable */
4197c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4207c478bd9Sstevel@tonic-gate 		:		6;
4217c478bd9Sstevel@tonic-gate 	uchar_t	dde:		1,	/* Data Decompression Enabled */
4227c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4237c478bd9Sstevel@tonic-gate 		:		5;
4247c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4257c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4267c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4277c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4287c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4297c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4307c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4317c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4327c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4337c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4347c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4357c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4367c478bd9Sstevel@tonic-gate #endif
4377c478bd9Sstevel@tonic-gate };
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate struct dev_mode_page {
4407c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
4417c478bd9Sstevel@tonic-gate 	uchar_t	act_format:	5,	/* active format */
4427c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4435988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4447c478bd9Sstevel@tonic-gate 		:		1;
4457c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4467c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4477c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4487c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4497c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4507c478bd9Sstevel@tonic-gate 	uchar_t	rew:		1,	/* Report Early Warning */
4515988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4527c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4537c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4545988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4555988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4565988135dSrralphs 		obr:		1;	/* Object Buffer Recovery */
4575988135dSrralphs 	uchar_t	gap_size;		/* OBSOLETE */
4585988135dSrralphs 	uchar_t	bam:		1,	/* Block Address Mode */
4595988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4605988135dSrralphs 		swp:		1,	/* Software Write Protection */
4617c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4627c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4637c478bd9Sstevel@tonic-gate 		eod_defined:	3;
4647c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4657c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4667c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4677c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
4685988135dSrralphs 	uchar_t	prmwp:		1,	/* PeRManent Write Protect */
4695988135dSrralphs 		perswp:		1,	/* persistant write protection */
4705988135dSrralphs 		asocwp:		1,	/* associated write protect */
4715988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
4725988135dSrralphs 		oir:		1,	/* Only If Reserved */
4735988135dSrralphs 		wtre:		2;	/* Worm Tamper Read Enable */
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4767c478bd9Sstevel@tonic-gate 	uchar_t	:		1,
4775988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4787c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4797c478bd9Sstevel@tonic-gate 		act_format:	5;	/* active format */
4807c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4817c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4827c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4837c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4847c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4855988135dSrralphs 	uchar_t	obr:		1,	/* Object Buffer Recovery */
4865988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4875988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4887c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4897c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4905988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4917c478bd9Sstevel@tonic-gate 		rew:		1;	/* Report Early Warning */
4925988135dSrralphs 	uchar_t	gap_size;		/* OBSELETE */
4937c478bd9Sstevel@tonic-gate 	uchar_t	eod_defined:	3,
4947c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4957c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4965988135dSrralphs 		swp:		1,	/* Software Write Protection */
4975988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4985988135dSrralphs 		bam:		1;	/* Block Address Mode */
4997c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
5007c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
5017c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
5027c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
5035988135dSrralphs 	uchar_t	wtre:		2,	/* Worm Tamper Read Enable */
5045988135dSrralphs 		oir:		1,	/* Only If Reserved */
5055988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
5065988135dSrralphs 		asocwp:		1,	/* associated write protect */
5075988135dSrralphs 		perswp:		1,	/* persistant write protection */
5085988135dSrralphs 		prmwp:		1;	/* PeRManent Write Protect */
5097c478bd9Sstevel@tonic-gate #endif
5107c478bd9Sstevel@tonic-gate };
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate typedef union {
5137c478bd9Sstevel@tonic-gate 	struct comp_mode_page	comp;
5147c478bd9Sstevel@tonic-gate 	struct dev_mode_page	dev;
5157c478bd9Sstevel@tonic-gate }modepage;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate  *
5197c478bd9Sstevel@tonic-gate  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
5207c478bd9Sstevel@tonic-gate  * The parameter list contains a header, followed by zero or more
5217c478bd9Sstevel@tonic-gate  * block descriptors, followed by vendor unique parameters, if any.
5227c478bd9Sstevel@tonic-gate  *
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate #define	MSIZE	0x0c		/* Size without additional pages */
5257c478bd9Sstevel@tonic-gate struct seq_mode {
5267c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
5277c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5287c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5297c478bd9Sstevel@tonic-gate 	uchar_t	speed	:4,	/* speed */
5307c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5317c478bd9Sstevel@tonic-gate 		wp	:1;	/* write protected, sense only */
5327c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5337c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5347c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5357c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5367c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5377c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5387c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5397c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5407c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5417c478bd9Sstevel@tonic-gate 	uchar_t page_code:	6,
5427c478bd9Sstevel@tonic-gate 		:		1,
5437c478bd9Sstevel@tonic-gate 		ps:		1; /* Page Savable sense only */
5447c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5457c478bd9Sstevel@tonic-gate 	modepage page;
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
5487c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5497c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5507c478bd9Sstevel@tonic-gate 	uchar_t	wp	:1,	/* write protected, sense only */
5517c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5527c478bd9Sstevel@tonic-gate 		speed	:4;	/* speed */
5537c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5547c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5557c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5567c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5577c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5587c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5597c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5607c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5617c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5627c478bd9Sstevel@tonic-gate 	uchar_t	ps:		1, /* Page Savable sense only */
5637c478bd9Sstevel@tonic-gate 		:		1,
5647c478bd9Sstevel@tonic-gate 		page_code:	6;
5657c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5667c478bd9Sstevel@tonic-gate 	modepage page;
5677c478bd9Sstevel@tonic-gate #else
5687c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5697c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
5707c478bd9Sstevel@tonic-gate };
5717c478bd9Sstevel@tonic-gate 
5729f931db8Syl /*
5739f931db8Syl  * One_command parameter data for REPORT SUPPORTED OPERATION CODES.
5749f931db8Syl  */
5759f931db8Syl struct one_com_des {
5769f931db8Syl #if defined(_BIT_FIELDS_LTOH)
5779f931db8Syl 	uchar_t reserved0;
5789f931db8Syl 	uchar_t support:	3,	/* support value */
5799f931db8Syl 		reserved1:	4,
5809f931db8Syl 		ctdp:		1;	/* cmd timeouts descriptor present */
5819f931db8Syl 	ushort_t cdb_size;		/* cdb size */
5829f931db8Syl 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
5839f931db8Syl #elif defined(_BIT_FIELDS_HTOL)
5849f931db8Syl 	uchar_t reserved0;
5859f931db8Syl 	uchar_t ctdp:		1,	/* cmd timeouts descriptor present */
5869f931db8Syl 		reserved1:	4,
5879f931db8Syl 		support:	3;	/* support value */
5889f931db8Syl 	ushort_t cdb_size;		/* cdb size */
5899f931db8Syl 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
5909f931db8Syl #else
5919f931db8Syl #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5929f931db8Syl #endif /* _BIT_FIELDS_LTOH */
5939f931db8Syl };
5949f931db8Syl 
5959f931db8Syl /*
5969f931db8Syl  * Command timeouts descriptor
5979f931db8Syl  */
5989f931db8Syl struct com_timeout_des {
5999f931db8Syl 	ushort_t des_len;	/* descriptor length */
6009f931db8Syl 	uchar_t reserved;
6019f931db8Syl 	uchar_t com_spe;	/* command specific */
6029f931db8Syl 	uint_t nom_timeout;	/* nominal command processing timeout */
6039f931db8Syl 	uint_t rec_timeout;	/* recommended command timeout */
6049f931db8Syl };
6059f931db8Syl 
6069f931db8Syl /*
6079f931db8Syl  * Reporting options
6089f931db8Syl  */
6099f931db8Syl #define	ALL_COMMAND_DATA_FORMAT			0
6109f931db8Syl #define	ONE_COMMAND_NO_SERVICE_DATA_FORMAT	1
6119f931db8Syl #define	ONE_COMMAND_DATA_FORMAT			2
6129f931db8Syl 
6139f931db8Syl /*
6149f931db8Syl  * Support values in One_command parameter data
6159f931db8Syl  */
6169f931db8Syl #define	SUPPORT_VALUES_NOT_AVAILABLE		0
6179f931db8Syl #define	SUPPORT_VALUES_NOT_SUPPORT		1
6189f931db8Syl #define	SUPPORT_VALUES_SUPPORT_SCSI		3
6199f931db8Syl #define	SUPPORT_VALUES_SUPPORT_VENDOR		5
6209f931db8Syl 
6219f931db8Syl /*
6229f931db8Syl  * Parameter data for REPORT DENSITY SUPPORT command
6239f931db8Syl  */
6249f931db8Syl struct report_density_header {
6259f931db8Syl 	ushort_t ava_dens_len;		/* available density support length */
6269f931db8Syl 	uchar_t reserved0;
6279f931db8Syl 	uchar_t reserved1;
6289f931db8Syl };
6299f931db8Syl 
6309f931db8Syl struct report_density_desc {
6319f931db8Syl #if defined(_BIT_FIELDS_LTOH)
6329f931db8Syl 	uchar_t pri_den;		/* primary density code */
6339f931db8Syl 	uchar_t sec_den;		/* secondary density code */
6349f931db8Syl 	uchar_t dlv:1;			/* descriptor length valid */
6359f931db8Syl 	uchar_t reserved:4;
6369f931db8Syl 	uchar_t deflt:1;		/* is default density */
6379f931db8Syl 	uchar_t dup:1;			/* pri density has one descriptor */
6389f931db8Syl 	uchar_t wrtok:1;		/* support writing to media */
6399f931db8Syl 	uchar_t desc_len_hi;		/* descriptor length high */
6409f931db8Syl 	uchar_t desc_len_low;		/* descriptor length low */
6419f931db8Syl 	uchar_t bits_per_mm[3];		/* bits per mm */
6429f931db8Syl 	uchar_t media_width_hi;		/* media width high */
6439f931db8Syl 	uchar_t media_width_low;	/* media width low */
6449f931db8Syl 	ushort_t tracks;		/* tracks */
6459f931db8Syl 	uint_t capacity;		/* capacity */
6469f931db8Syl 	uchar_t ass_org[8];		/* assigning organization */
6479f931db8Syl 	uchar_t den_name[8];		/* density name */
6489f931db8Syl 	uchar_t description[20];	/* description */
6499f931db8Syl #elif defined(_BIT_FIELDS_HTOL)
6509f931db8Syl 	uchar_t pri_den;		/* primary density code */
6519f931db8Syl 	uchar_t sec_den;		/* secondary density code */
6529f931db8Syl 	uchar_t wrtok:1;		/* support writing to media */
6539f931db8Syl 	uchar_t dup:1;			/* pri density has one descriptor */
6549f931db8Syl 	uchar_t deflt:1;		/* is default density */
6559f931db8Syl 	uchar_t reserved:4;
6569f931db8Syl 	uchar_t dlv:1;			/* descriptor length valid */
6579f931db8Syl 	uchar_t desc_len_hi;		/* descriptor length high */
6589f931db8Syl 	uchar_t desc_len_low;		/* descriptor length low */
6599f931db8Syl 	uchar_t bits_per_mm[3];		/* bits per mm */
6609f931db8Syl 	uchar_t media_width_hi;		/* media width high */
6619f931db8Syl 	uchar_t media_width_low;	/* media width low */
6629f931db8Syl 	ushort_t tracks;		/* tracks */
6639f931db8Syl 	uint_t capacity;		/* capacity */
6649f931db8Syl 	uchar_t ass_org[8];		/* assigning organization */
6659f931db8Syl 	uchar_t den_name[8];		/* density name */
6669f931db8Syl 	uchar_t description[20];	/* description */
6679f931db8Syl #else
6689f931db8Syl #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
6699f931db8Syl #endif  /* _BIT_FIELDS_LTOH */
6709f931db8Syl };
6719f931db8Syl 
6727c478bd9Sstevel@tonic-gate /*
6737c478bd9Sstevel@tonic-gate  * Data returned from the READ BLOCK LIMITS command.
6747c478bd9Sstevel@tonic-gate  */
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate #define	RBLSIZE	(sizeof (struct read_blklim))
6777c478bd9Sstevel@tonic-gate struct read_blklim {
6787c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL)
6797c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6807c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6817c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_LTOH)
6827c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6837c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6847c478bd9Sstevel@tonic-gate #endif
6857c478bd9Sstevel@tonic-gate 	uchar_t	max_hi;			/* Maximum block length, high byte */
6867c478bd9Sstevel@tonic-gate 	uchar_t	max_mid;		/* Maximum block length, middle byte */
6877c478bd9Sstevel@tonic-gate 	uchar_t	max_lo;			/* Maximum block length, low byte */
6887c478bd9Sstevel@tonic-gate 	uchar_t	min_hi;			/* Minimum block length, high byte */
6897c478bd9Sstevel@tonic-gate 	uchar_t	min_lo;			/* Minimum block length, low byte */
6907c478bd9Sstevel@tonic-gate };
6917c478bd9Sstevel@tonic-gate 
692c6914c10Srralphs /*
693c6914c10Srralphs  * operation codes
694c6914c10Srralphs  */
695c6914c10Srralphs typedef enum {
696c6914c10Srralphs 	ST_OP_NIL,
697c6914c10Srralphs 	ST_OP_CTL,
698c6914c10Srralphs 	ST_OP_READ,
699c6914c10Srralphs 	ST_OP_WRITE,
700c6914c10Srralphs 	ST_OP_WEOF
701c6914c10Srralphs }optype;
702c6914c10Srralphs 
703c6914c10Srralphs /*
704c6914c10Srralphs  * eof/eot/eom codes.
705c6914c10Srralphs  */
706c6914c10Srralphs typedef enum {
707c6914c10Srralphs 	ST_NO_EOF,
708c6914c10Srralphs 	ST_EOF_PENDING,		/* filemark pending */
709c6914c10Srralphs 	ST_EOF,			/* at filemark */
710c6914c10Srralphs 	ST_EOT_PENDING,		/* logical eot pending */
711c6914c10Srralphs 	ST_EOT,			/* at logical eot */
712c6914c10Srralphs 	ST_EOM,			/* at physical eot */
713c6914c10Srralphs 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
714c6914c10Srralphs }pstatus;
715c6914c10Srralphs 
716c6914c10Srralphs typedef enum { invalid, legacy, logical } posmode;
717c6914c10Srralphs 
718c6914c10Srralphs typedef struct tapepos {
719c6914c10Srralphs 	uint64_t lgclblkno;
720c6914c10Srralphs 	int32_t fileno;
721c6914c10Srralphs 	int32_t blkno;
722c6914c10Srralphs 	int32_t partition;
723c6914c10Srralphs 	pstatus eof;			/* eof states */
724c6914c10Srralphs 	posmode	pmode;
725*f218e94bSrralphs 	uint32_t: 32;
726c6914c10Srralphs }tapepos_t;
727c6914c10Srralphs 
728c6914c10Srralphs /* byte 1 of cdb for type of read position command */
729c6914c10Srralphs typedef enum {
730c6914c10Srralphs 	SHORT_POS	= 0,
731c6914c10Srralphs 	LONG_POS	= 6,
732c6914c10Srralphs 	EXT_POS		= 8,
733c6914c10Srralphs 	NO_POS		= 0xff	/* Drive doesn't support read position */
734c6914c10Srralphs } read_p_types;
735c6914c10Srralphs 
736c6914c10Srralphs 
737c6914c10Srralphs /*
738c6914c10Srralphs  * Data returned from the READ POSITION command.
739c6914c10Srralphs  */
740c6914c10Srralphs 
741c6914c10Srralphs typedef struct tape_position {
742c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
743c6914c10Srralphs 	uchar_t begin_of_part:	1;
744c6914c10Srralphs 	uchar_t end_of_part:	1;
745c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
746c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
747c6914c10Srralphs 	uchar_t reserved0:	1;
748c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
749c6914c10Srralphs 	uchar_t posi_err:	1;
750c6914c10Srralphs 	uchar_t reserved1:	1;
751c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
752c6914c10Srralphs 	uchar_t reserved1:	1;
753c6914c10Srralphs 	uchar_t posi_err:	1;
754c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
755c6914c10Srralphs 	uchar_t reserved0:	1;
756c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
757c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
758c6914c10Srralphs 	uchar_t end_of_part:	1;
759c6914c10Srralphs 	uchar_t begin_of_part:	1;
760c6914c10Srralphs #endif
761c6914c10Srralphs 	uchar_t partition_number;
762c6914c10Srralphs 	uchar_t reserved2[2];
763c6914c10Srralphs 	uint32_t host_block;
764c6914c10Srralphs 	uint32_t media_block;
765c6914c10Srralphs 	uchar_t reserved3;
766c6914c10Srralphs 	uchar_t block_in_buff[3];
767c6914c10Srralphs 	uint32_t byte_in_buff;
768c6914c10Srralphs }tape_position_t;
769c6914c10Srralphs 
770c6914c10Srralphs 
771c6914c10Srralphs typedef struct tape_position_long {
772c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
773c6914c10Srralphs 	uint32_t begin_of_part:	1;
774c6914c10Srralphs 	uint32_t end_of_part:	1;
775c6914c10Srralphs 	uint32_t reserved0:	2;
776c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
777c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
778c6914c10Srralphs 	uint32_t reserved1:	2;
779c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
780c6914c10Srralphs 	uint32_t reserved1:	2;
781c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
782c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
783c6914c10Srralphs 	uint32_t reserved0:	2;
784c6914c10Srralphs 	uint32_t end_of_part:   1;
785c6914c10Srralphs 	uint32_t begin_of_part: 1;
786c6914c10Srralphs #endif
787c6914c10Srralphs 	uint32_t reserved2:	24;
788c6914c10Srralphs 	uint32_t partition;
789c6914c10Srralphs 	uint64_t block_number;
790c6914c10Srralphs 	uint64_t file_number;
791c6914c10Srralphs 	uint64_t set_number;
792c6914c10Srralphs }tape_position_long_t;
793c6914c10Srralphs 
794c6914c10Srralphs typedef struct tape_position_ext {
795c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
796*f218e94bSrralphs 	uchar_t begin_of_part:	1;
797*f218e94bSrralphs 	uchar_t end_of_part:	1;
798*f218e94bSrralphs 	uchar_t blk_cnt_unkwn:	1;
799*f218e94bSrralphs 	uchar_t byte_cnt_unkwn:	1;
800*f218e94bSrralphs 	uchar_t mrk_posi_unkwn:	1;
801*f218e94bSrralphs 	uchar_t blk_posi_unkwn:	1;
802*f218e94bSrralphs 	uchar_t posi_err:	1;
803*f218e94bSrralphs 	uchar_t reserved0:	1;
804*f218e94bSrralphs 
805*f218e94bSrralphs 	uchar_t partition;
806*f218e94bSrralphs 	uint16_t parameter_len;
807c6914c10Srralphs /* start next word */
808c6914c10Srralphs 	uint32_t reserved1:	8;
809c6914c10Srralphs 	uint32_t blks_in_buf:	24;
810c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
811*f218e94bSrralphs 	uchar_t reserved0:	1;
812*f218e94bSrralphs 	uchar_t posi_err:	1;
813*f218e94bSrralphs 	uchar_t blk_posi_unkwn:	1;
814*f218e94bSrralphs 	uchar_t mrk_posi_unkwn:	1;
815*f218e94bSrralphs 	uchar_t byte_cnt_unkwn:	1;
816*f218e94bSrralphs 	uchar_t blk_cnt_unkwn:	1;
817*f218e94bSrralphs 	uchar_t end_of_part:	1;
818*f218e94bSrralphs 	uchar_t begin_of_part:	1;
819*f218e94bSrralphs 
820*f218e94bSrralphs 	uchar_t partition;
821*f218e94bSrralphs 	uint16_t parameter_len;
822c6914c10Srralphs /* start next word */
823c6914c10Srralphs 	uint32_t blks_in_buf:	24;
824c6914c10Srralphs 	uint32_t reserved1:	8;
825c6914c10Srralphs #endif
826c6914c10Srralphs 	uint64_t host_block;
827c6914c10Srralphs 	uint64_t media_block;
828c6914c10Srralphs 	uint64_t byte_in_buf;
829c6914c10Srralphs }tape_position_ext_t;
830c6914c10Srralphs 
831c6914c10Srralphs typedef union {
832c6914c10Srralphs 	tape_position_t srt;
833c6914c10Srralphs 	tape_position_ext_t ext;
834c6914c10Srralphs 	tape_position_long_t lng;
835c6914c10Srralphs }read_pos_data_t;
836c6914c10Srralphs 
837*f218e94bSrralphs typedef struct {
838*f218e94bSrralphs 	unsigned char cmd;
839*f218e94bSrralphs 	unsigned char
840*f218e94bSrralphs 		requires_reserve:	1,	/* reserve must be done */
841*f218e94bSrralphs 		retriable:		1,	/* can be retried */
842*f218e94bSrralphs 		chg_tape_pos:		1,	/* position will change */
843*f218e94bSrralphs 		chg_tape_data:		1,	/* data on media will change */
844*f218e94bSrralphs 		explicit:		1,	/* explicit command set */
845*f218e94bSrralphs 		/*
846*f218e94bSrralphs 		 * 0 doesn't, 1 forward,
847*f218e94bSrralphs 		 * 2 back, 3 either
848*f218e94bSrralphs 		 */
849*f218e94bSrralphs 		chg_tape_direction:	2;	/* direction of pos change */
850*f218e94bSrralphs #define	DIR_NONE	0
851*f218e94bSrralphs #define	DIR_FORW	1
852*f218e94bSrralphs #define	DIR_REVC	2
853*f218e94bSrralphs #define	DIR_EITH	3
854*f218e94bSrralphs 	unsigned char
855*f218e94bSrralphs 		/*
856*f218e94bSrralphs 		 * 0 doesn't 1 read, 2 write
857*f218e94bSrralphs 		 */
858*f218e94bSrralphs 		transfers_data:		2,
859*f218e94bSrralphs #define	TRAN_NONE	0
860*f218e94bSrralphs #define	TRAN_READ	1
861*f218e94bSrralphs #define	TRAN_WRTE	2
862*f218e94bSrralphs 		recov_pos_type:		1,
863*f218e94bSrralphs #define	POS_EXPECTED	0
864*f218e94bSrralphs #define	POS_STARTING	1
865*f218e94bSrralphs 		do_not_recover:		1;
866*f218e94bSrralphs 	uchar_t reserve_byte;
867*f218e94bSrralphs 	uint32_t reserve_mask;
868*f218e94bSrralphs 	uint64_t (*get_cnt)(uchar_t *);
869*f218e94bSrralphs 	uint64_t (*get_lba)(uchar_t *);
870*f218e94bSrralphs }cmd_attribute;
871*f218e94bSrralphs 
872*f218e94bSrralphs typedef struct {
873*f218e94bSrralphs 	buf_t *cmd_bp;
874*f218e94bSrralphs 	size_t privatelen;
875*f218e94bSrralphs }pkt_info;
876*f218e94bSrralphs 
877*f218e94bSrralphs typedef struct {
878*f218e94bSrralphs 	buf_t *cmd_bp;
879*f218e94bSrralphs 	size_t privatelen;
880*f218e94bSrralphs 	tapepos_t pos;
881*f218e94bSrralphs 	const cmd_attribute *cmd_attrib;
882*f218e94bSrralphs }recov_info;
883*f218e94bSrralphs 
884f3531714Scz #ifdef _KERNEL
885f3531714Scz 
88636945f79Smrj #ifdef	__x86
887f3531714Scz /* Data structure used in big block I/O on x86/x64 platform */
888f3531714Scz 
889f3531714Scz /*
890f3531714Scz  * alloc more than one contig_mem, so mutiple I/O can be
891f3531714Scz  * on-going simultaneously
892f3531714Scz  */
893f3531714Scz #define	ST_MAX_CONTIG_MEM_NUM	3
894f3531714Scz 
895f3531714Scz struct contig_mem {
896f3531714Scz 	struct contig_mem *cm_next;
897f3531714Scz 	size_t cm_len;
898f3531714Scz 	caddr_t cm_addr;
899f3531714Scz 	ddi_acc_handle_t cm_acc_hdl;
900f3531714Scz 	struct buf *cm_bp;
901f3531714Scz 	int cm_use_sbuf;
902f3531714Scz };
9034ebb14b2Sfrits 
904f3531714Scz #endif
905f3531714Scz 
906f3531714Scz #endif /* _KERNEL */
907f3531714Scz 
9085988135dSrralphs /*
909c6914c10Srralphs  * driver states..
9105988135dSrralphs  */
9115988135dSrralphs typedef enum {
912c6914c10Srralphs 	ST_STATE_CLOSED,
913c6914c10Srralphs 	ST_STATE_OFFLINE,
914c6914c10Srralphs 	ST_STATE_INITIALIZING,
915c6914c10Srralphs 	ST_STATE_OPENING,
916c6914c10Srralphs 	ST_STATE_OPEN_PENDING_IO,
917c6914c10Srralphs 	ST_STATE_APPEND_TESTING,
918c6914c10Srralphs 	ST_STATE_OPEN,
919c6914c10Srralphs 	ST_STATE_RESOURCE_WAIT,
920c6914c10Srralphs 	ST_STATE_CLOSING,
921c6914c10Srralphs 	ST_STATE_SENSING,
922c6914c10Srralphs 	ST_STATE_CLOSE_PENDING_OPEN
923c6914c10Srralphs }st_states;
924c6914c10Srralphs 
925c6914c10Srralphs typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
9265988135dSrralphs 
9275988135dSrralphs 
9287c478bd9Sstevel@tonic-gate /*
9297c478bd9Sstevel@tonic-gate  * Private info for scsi tapes. Pointed to by the un_private pointer
9307c478bd9Sstevel@tonic-gate  * of one of the SCSI_DEVICE chains.
9317c478bd9Sstevel@tonic-gate  */
9327c478bd9Sstevel@tonic-gate 
9337c478bd9Sstevel@tonic-gate struct scsi_tape {
9347c478bd9Sstevel@tonic-gate 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
9357c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
9367c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
9377c478bd9Sstevel@tonic-gate 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
9387c478bd9Sstevel@tonic-gate 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
9397c478bd9Sstevel@tonic-gate 	struct	buf *un_sbufp;		/* for use in special io */
9407c478bd9Sstevel@tonic-gate 	char	*un_srqbufp;		/* sense buffer for special io */
9417c478bd9Sstevel@tonic-gate 	kcondvar_t un_clscv;		/* closing cv */
9427c478bd9Sstevel@tonic-gate 	struct	buf *un_quef;		/* head of wait queue */
9437c478bd9Sstevel@tonic-gate 	struct	buf *un_quel;		/* tail of wait queue */
9447c478bd9Sstevel@tonic-gate 	struct	buf *un_runqf;		/* head of run queue */
9457c478bd9Sstevel@tonic-gate 	struct	buf *un_runql;		/* tail of run queue */
9467c478bd9Sstevel@tonic-gate 	struct seq_mode *un_mspl;	/* ptr to mode select info */
9477c478bd9Sstevel@tonic-gate 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
9487c478bd9Sstevel@tonic-gate 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
9497c478bd9Sstevel@tonic-gate 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
950c6914c10Srralphs 	tapepos_t un_pos;		/* Current tape position */
9517c478bd9Sstevel@tonic-gate 	int	un_oflags;		/* open flags */
952c6914c10Srralphs 	tapepos_t un_err_pos;		/* block in file where err occurred */
9537c478bd9Sstevel@tonic-gate 	uint_t	un_err_resid;		/* resid from last error */
9547c478bd9Sstevel@tonic-gate 	short	un_fmneeded;		/* filemarks to be written - HP only */
9557c478bd9Sstevel@tonic-gate 	dev_t	un_dev;			/* unix device */
9567c478bd9Sstevel@tonic-gate 	uchar_t	un_attached;		/* unit known && attached */
9577c478bd9Sstevel@tonic-gate 	int	un_pwr_mgmt;		/* power management state */
9587c478bd9Sstevel@tonic-gate 	uchar_t	un_density_known;	/* density is known */
9597c478bd9Sstevel@tonic-gate 	uchar_t	un_curdens;		/* index into density table */
9605988135dSrralphs 	optype	un_lastop;		/* last I/O was: read/write/ctl */
961c6914c10Srralphs 	st_states un_laststate;		/* last state */
962c6914c10Srralphs 	st_states un_state;		/* current state */
9637c478bd9Sstevel@tonic-gate 	uchar_t	un_status;		/* status from last sense */
9647c478bd9Sstevel@tonic-gate 	uchar_t	un_retry_ct;		/* retry count */
9657c478bd9Sstevel@tonic-gate 	uchar_t	un_tran_retry_ct;	/* transport retry count */
9665988135dSrralphs 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
9677c478bd9Sstevel@tonic-gate 	uchar_t	un_test_append;		/* check writing at end of tape */
9687c478bd9Sstevel@tonic-gate 	uchar_t un_arq_enabled;		/* auto request sense enabled */
9697c478bd9Sstevel@tonic-gate 	uchar_t un_untagged_qing;	/* hba has untagged quing */
9707c478bd9Sstevel@tonic-gate 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
9717c478bd9Sstevel@tonic-gate 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
9727c478bd9Sstevel@tonic-gate 	uchar_t	un_ncmds;		/* number of commands outstanding */
9737c478bd9Sstevel@tonic-gate 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
9747c478bd9Sstevel@tonic-gate 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
9757c478bd9Sstevel@tonic-gate 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
9767c478bd9Sstevel@tonic-gate 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
9777c478bd9Sstevel@tonic-gate 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
9787c478bd9Sstevel@tonic-gate 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
9797c478bd9Sstevel@tonic-gate 					/* check condidtion or error */
9807c478bd9Sstevel@tonic-gate 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
9817c478bd9Sstevel@tonic-gate 	uint_t	un_last_resid;		/* keep last resid, for PE */
9827c478bd9Sstevel@tonic-gate 	uint_t	un_last_count;		/* keep last count, for PE */
9837c478bd9Sstevel@tonic-gate 	struct 	kstat *un_stats;	/* for I/O statistics */
9847c478bd9Sstevel@tonic-gate 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
9857c478bd9Sstevel@tonic-gate 	struct	buf *un_wf;		/* head of write queue */
9867c478bd9Sstevel@tonic-gate 	struct	buf *un_wl;		/* tail of write queue */
9877c478bd9Sstevel@tonic-gate 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
9887c478bd9Sstevel@tonic-gate 	int	un_maxdma;		/* max dma xfer allowed by HBA */
9897c478bd9Sstevel@tonic-gate 	uint_t	un_bsize;		/* block size currently being used */
9907c478bd9Sstevel@tonic-gate 	int	un_maxbsize;		/* max block size allowed by drive */
9917c478bd9Sstevel@tonic-gate 	uint_t	un_minbsize;		/* min block size allowed by drive */
9927c478bd9Sstevel@tonic-gate 	int	un_errno;		/* errno (b_error) */
9937c478bd9Sstevel@tonic-gate 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
9947c478bd9Sstevel@tonic-gate 	enum mtio_state	un_mediastate;	/* current media state */
9957c478bd9Sstevel@tonic-gate 	enum mtio_state	un_specified_mediastate;	/* expected state */
9967c478bd9Sstevel@tonic-gate 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
9977c478bd9Sstevel@tonic-gate 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
9987c478bd9Sstevel@tonic-gate 	opaque_t	un_swr_token;	/* scsi_watch request token */
9997c478bd9Sstevel@tonic-gate 	uchar_t	un_comp_page;		/* compression page */
10007c478bd9Sstevel@tonic-gate 	uchar_t	un_rsvd_status;		/* Reservation Status */
10017c478bd9Sstevel@tonic-gate 	kstat_t *un_errstats;		/* for error statistics */
1002*f218e94bSrralphs 	int	un_init_options;	/* Init time drive options */
10037c478bd9Sstevel@tonic-gate 	int	un_save_fileno;		/* Save here for recovery */
10047c478bd9Sstevel@tonic-gate 	daddr_t	un_save_blkno;		/* Save here for recovery */
1005c6914c10Srralphs 	uchar_t un_restore_pos;		/* Indication to do recovery */
1006c6914c10Srralphs 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
10077c478bd9Sstevel@tonic-gate 	uchar_t	un_silent_skip;		/* to catch short reads */
1008c6914c10Srralphs 	short	un_tids_at_suspend;	/* timeouts set at suspend */
1009c6914c10Srralphs 	kcondvar_t un_tape_busy_cv;	/* busy cv */
1010c6914c10Srralphs 	kcondvar_t un_suspend_cv;	/* busy cv */
10117c478bd9Sstevel@tonic-gate 					/* restore on close */
10127c478bd9Sstevel@tonic-gate 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
10137c478bd9Sstevel@tonic-gate 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
10147c478bd9Sstevel@tonic-gate 	uchar_t	un_rqs_state;		/* see define below */
1015c6914c10Srralphs 	struct scsi_extended_sense
1016c6914c10Srralphs 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
10177c478bd9Sstevel@tonic-gate 	uchar_t	un_data_mod;		/* Device required data mod */
10185988135dSrralphs 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
10195988135dSrralphs 	int un_max_cdb_sz;		/* max cdb size to use */
1020c6914c10Srralphs 	read_p_types un_read_pos_type;
1021c6914c10Srralphs 	read_pos_data_t *un_read_pos_data;
1022fa4c0ec8Sbz 	struct mterror_entry_stack *un_error_entry_stk;
1023fa4c0ec8Sbz 					/* latest sense cmd buffer */
1024f3531714Scz 
102536945f79Smrj #ifdef	__x86
1026f3531714Scz 	ddi_dma_handle_t un_contig_mem_hdl;
1027f3531714Scz 	struct contig_mem *un_contig_mem;
1028f3531714Scz 	int un_contig_mem_available_num;
1029f3531714Scz 	int un_contig_mem_total_num;
1030a7333962Scz 	size_t un_max_contig_mem_len;
1031f3531714Scz 	kcondvar_t un_contig_mem_cv;
103236945f79Smrj 	int un_maxdma_arch;		/* max dma xfer allowed by HBA & arch */
1033f3531714Scz #endif
1034*f218e94bSrralphs 	caddr_t un_media_id;
1035*f218e94bSrralphs 	int un_media_id_len;
1036*f218e94bSrralphs 	int (*un_media_id_method)(struct scsi_tape *, int (*)());
1037*f218e94bSrralphs 	buf_t *un_recov_buf;		/* buf to recover failed commands */
1038*f218e94bSrralphs 	kcondvar_t un_recov_buf_cv;	/* cv for buf un_recov_buf */
1039*f218e94bSrralphs 	uchar_t un_recov_buf_busy;
1040*f218e94bSrralphs #ifdef _KERNEL
1041*f218e94bSrralphs 	ddi_taskq_t *un_recov_taskq;
1042*f218e94bSrralphs #else
1043*f218e94bSrralphs 	void *un_recov_taskq;
1044*f218e94bSrralphs #endif
1045*f218e94bSrralphs 	tapepos_t un_running;
1046*f218e94bSrralphs 	uchar_t un_unit_attention_flags;
10477c478bd9Sstevel@tonic-gate };
10484ebb14b2Sfrits 
1049*f218e94bSrralphs typedef int (*bufunc_t)(struct scsi_tape *, int, int64_t, int);
1050*f218e94bSrralphs typedef int (*ubufunc_t)(struct scsi_tape *, struct uscsi_cmd *, int);
1051*f218e94bSrralphs 
10524ebb14b2Sfrits 
10537c478bd9Sstevel@tonic-gate /*
10547c478bd9Sstevel@tonic-gate  * device error kstats
10557c478bd9Sstevel@tonic-gate  */
10567c478bd9Sstevel@tonic-gate struct st_errstats {
10577c478bd9Sstevel@tonic-gate 	struct kstat_named	st_softerrs;
10587c478bd9Sstevel@tonic-gate 	struct kstat_named	st_harderrs;
10597c478bd9Sstevel@tonic-gate 	struct kstat_named	st_transerrs;
10607c478bd9Sstevel@tonic-gate 	struct kstat_named	st_vid;
10617c478bd9Sstevel@tonic-gate 	struct kstat_named	st_pid;
10627c478bd9Sstevel@tonic-gate 	struct kstat_named	st_revision;
10637c478bd9Sstevel@tonic-gate 	struct kstat_named	st_serial;
10647c478bd9Sstevel@tonic-gate };
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate /*
10677c478bd9Sstevel@tonic-gate  * generic log page struct
10687c478bd9Sstevel@tonic-gate  */
10697c478bd9Sstevel@tonic-gate struct log_page {
10707c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
10717c478bd9Sstevel@tonic-gate 	uchar_t	code	:6,	/* page code number */
10727c478bd9Sstevel@tonic-gate 			:2;	/* reserved */
10737c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
10747c478bd9Sstevel@tonic-gate 	uchar_t		:2,	/* reserved */
10757c478bd9Sstevel@tonic-gate 		code	:6;	/* page code number */
10767c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
10777c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
10787c478bd9Sstevel@tonic-gate 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
10797c478bd9Sstevel@tonic-gate 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
10807c478bd9Sstevel@tonic-gate 	/*
10817c478bd9Sstevel@tonic-gate 	 * Log parameters follow right after this...
10827c478bd9Sstevel@tonic-gate 	 */
10837c478bd9Sstevel@tonic-gate };
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate /*
10867c478bd9Sstevel@tonic-gate  * generic log page parameter struct
10877c478bd9Sstevel@tonic-gate  */
10887c478bd9Sstevel@tonic-gate struct log_param {
10897c478bd9Sstevel@tonic-gate 	uchar_t	pc_hi;			/* parameter code (msb) */
10907c478bd9Sstevel@tonic-gate 	uchar_t	pc_lo;			/* parameter code (lsb) */
10917c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
10927c478bd9Sstevel@tonic-gate 	uchar_t		lp	: 1,	/* list parameter */
10937c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
10947c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
10957c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
10967c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
10977c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
10987c478bd9Sstevel@tonic-gate 			du	: 1;	/* disable update */
10997c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
11007c478bd9Sstevel@tonic-gate 	uchar_t		du	: 1,	/* disable update */
11017c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
11027c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
11037c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
11047c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
11057c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
11067c478bd9Sstevel@tonic-gate 			lp	: 1;	/* list parameter */
11077c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
11087c478bd9Sstevel@tonic-gate 	uchar_t	length;		/* length of bytes to follow */
11097c478bd9Sstevel@tonic-gate 	/*
11107c478bd9Sstevel@tonic-gate 	 * Parameter values follow right after this...
11117c478bd9Sstevel@tonic-gate 	 */
11127c478bd9Sstevel@tonic-gate };
11137c478bd9Sstevel@tonic-gate /*
11147c478bd9Sstevel@tonic-gate  * TapeAlert structures
11157c478bd9Sstevel@tonic-gate  */
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate struct st_tape_alert_parameter {
11187c478bd9Sstevel@tonic-gate 	struct log_param log_param;
11197c478bd9Sstevel@tonic-gate 	uchar_t	param_value;
11207c478bd9Sstevel@tonic-gate };
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate struct st_tape_alert {
11237c478bd9Sstevel@tonic-gate 	struct log_page log_page;
11247c478bd9Sstevel@tonic-gate 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
11257c478bd9Sstevel@tonic-gate };
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PARAMETER_LENGTH \
11287c478bd9Sstevel@tonic-gate 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate struct log_sequential_page_parameter {
11317c478bd9Sstevel@tonic-gate 	struct log_param log_param;
11327c478bd9Sstevel@tonic-gate 	uchar_t param_value[8];
11337c478bd9Sstevel@tonic-gate };
11347c478bd9Sstevel@tonic-gate 
11357c478bd9Sstevel@tonic-gate struct log_sequential_page {
11367c478bd9Sstevel@tonic-gate 	struct log_page log_page;
11377c478bd9Sstevel@tonic-gate 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
11387c478bd9Sstevel@tonic-gate };
11397c478bd9Sstevel@tonic-gate 
11407c478bd9Sstevel@tonic-gate #if !defined(__lint)
11417c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
11427c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
11437c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
11447c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
11454ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
11467c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
11477c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
11487c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("save sharing",
11497c478bd9Sstevel@tonic-gate 	scsi_tape::un_allow_large_xfer
11507c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxbsize
11517c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxdma
11527c478bd9Sstevel@tonic-gate ))
115336945f79Smrj #ifdef	__x86
11544ebb14b2Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
11554ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
11564ebb14b2Sfrits #endif
11577c478bd9Sstevel@tonic-gate #endif
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate /*
11617c478bd9Sstevel@tonic-gate  * Power management state
11627c478bd9Sstevel@tonic-gate  */
11637c478bd9Sstevel@tonic-gate #define	ST_PWR_NORMAL				0
11647c478bd9Sstevel@tonic-gate #define	ST_PWR_SUSPENDED			1
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 
1167c6914c10Srralphs #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate /* un_rqs_state codes */
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
11727c478bd9Sstevel@tonic-gate #define	ST_RQS_VALID		0x2	/* RQS data is valid */
11737c478bd9Sstevel@tonic-gate #define	ST_RQS_READ		0x4	/* RQS data was read */
11747c478bd9Sstevel@tonic-gate #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
11757c478bd9Sstevel@tonic-gate 
11767c478bd9Sstevel@tonic-gate /*
1177*f218e94bSrralphs  * st_intr codes
11787c478bd9Sstevel@tonic-gate  */
1179*f218e94bSrralphs typedef enum {
1180*f218e94bSrralphs 	COMMAND_DONE,
1181*f218e94bSrralphs 	COMMAND_DONE_ERROR,
1182*f218e94bSrralphs 	COMMAND_DONE_ERROR_RECOVERED,
1183*f218e94bSrralphs 	QUE_COMMAND,
1184*f218e94bSrralphs 	QUE_BUSY_COMMAND,
1185*f218e94bSrralphs 	QUE_SENSE,
1186*f218e94bSrralphs 	JUST_RETURN,
1187*f218e94bSrralphs 	COMMAND_DONE_EACCES,
1188*f218e94bSrralphs 	QUE_LAST_COMMAND,
1189*f218e94bSrralphs 	COMMAND_TIMEOUT,
1190*f218e94bSrralphs 	PATH_FAILED,
1191*f218e94bSrralphs 	DEVICE_RESET,
1192*f218e94bSrralphs 	DEVICE_TAMPER,
1193*f218e94bSrralphs 	ATTEMPT_RETRY
1194*f218e94bSrralphs }errstate;
1195*f218e94bSrralphs #ifdef _KERNEL
1196*f218e94bSrralphs typedef struct {
1197*f218e94bSrralphs 	struct scsi_pkt ei_failed_pkt;
1198*f218e94bSrralphs 	struct scsi_arq_status ei_failing_status;
1199*f218e94bSrralphs 	tapepos_t ei_expected_pos;
1200*f218e94bSrralphs 	errstate ei_error_type;
1201*f218e94bSrralphs 	buf_t *ei_failing_bp;
1202*f218e94bSrralphs } st_err_info;
1203*f218e94bSrralphs #endif
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate 
12067c478bd9Sstevel@tonic-gate /*
12077c478bd9Sstevel@tonic-gate  *	Reservation Status
12087c478bd9Sstevel@tonic-gate  *
12097c478bd9Sstevel@tonic-gate  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
12107c478bd9Sstevel@tonic-gate  *		         in between opens and also to indicate the reservation
12117c478bd9Sstevel@tonic-gate  *		         has not been done till now.
12127c478bd9Sstevel@tonic-gate  * ST_RELEASE	        -Tape Unit is Released.
12137c478bd9Sstevel@tonic-gate  * ST_RESERVE	        -Tape Unit is Reserved.
12147c478bd9Sstevel@tonic-gate  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
12157c478bd9Sstevel@tonic-gate  *
12167c478bd9Sstevel@tonic-gate  */
12177c478bd9Sstevel@tonic-gate #define	ST_INIT_RESERVE			0x001
12187c478bd9Sstevel@tonic-gate #define	ST_RELEASE			0x002
12197c478bd9Sstevel@tonic-gate #define	ST_RESERVE			0x004
12207c478bd9Sstevel@tonic-gate #define	ST_PRESERVE_RESERVE		0x008
12217c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_CONFLICT 	0x010
12227c478bd9Sstevel@tonic-gate #define	ST_LOST_RESERVE			0x020
1223e213afc3Srralphs #define	ST_APPLICATION_RESERVATIONS	0x040
1224*f218e94bSrralphs #define	ST_INITIATED_RESET		0x080
1225e213afc3Srralphs #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
1226e213afc3Srralphs 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
12277c478bd9Sstevel@tonic-gate 
1228e213afc3Srralphs /*
1229e213afc3Srralphs  * Service action defines for Persistant Reservation Commands
1230e213afc3Srralphs  */
1231e213afc3Srralphs #define	ST_SA_SCSI3_REGISTER			0x00
1232e213afc3Srralphs #define	ST_SA_SCSI3_RESERVE			0x01
1233e213afc3Srralphs #define	ST_SA_SCSI3_RELEASE			0x02
1234e213afc3Srralphs #define	ST_SA_SCSI3_CLEAR			0x03
1235e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPT			0x04
1236e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
1237e213afc3Srralphs #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
1238e213afc3Srralphs #define	ST_SA_MASK				0x1f
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_DELAY		500000
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate /*
12437c478bd9Sstevel@tonic-gate  * Asynch I/O tunables
12447c478bd9Sstevel@tonic-gate  */
12457c478bd9Sstevel@tonic-gate #define	ST_MAX_THROTTLE		4
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate /*
12487c478bd9Sstevel@tonic-gate  * 60 minutes seems a reasonable amount of time
12497c478bd9Sstevel@tonic-gate  * to wait for tape space operations to complete.
12507c478bd9Sstevel@tonic-gate  *
12517c478bd9Sstevel@tonic-gate  */
12527c478bd9Sstevel@tonic-gate #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
12537c478bd9Sstevel@tonic-gate #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate /*
12567c478bd9Sstevel@tonic-gate  * 2 minutes seems a reasonable amount of time
12577c478bd9Sstevel@tonic-gate  * to wait for tape i/o operations to complete.
12587c478bd9Sstevel@tonic-gate  *
12597c478bd9Sstevel@tonic-gate  */
12607c478bd9Sstevel@tonic-gate #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
12617c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate /*
12657c478bd9Sstevel@tonic-gate  * 10 seconds is what we'll wait if we get a Busy Status back
12667c478bd9Sstevel@tonic-gate  */
12677c478bd9Sstevel@tonic-gate #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
12687c478bd9Sstevel@tonic-gate #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
12697c478bd9Sstevel@tonic-gate #define	ST_INTERRUPT_CONTEXT	1
12707c478bd9Sstevel@tonic-gate #define	ST_START_CONTEXT	2
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate /*
12737c478bd9Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
12747c478bd9Sstevel@tonic-gate  *
12757c478bd9Sstevel@tonic-gate  * XXX This includes retries due to transport failure as well as
12767c478bd9Sstevel@tonic-gate  * XXX busy timeouts- Need to distinguish between Target and Transport
12777c478bd9Sstevel@tonic-gate  * XXX failure.
12787c478bd9Sstevel@tonic-gate  */
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate #define	ST_RETRY_COUNT		20
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate /*
12837c478bd9Sstevel@tonic-gate  * Number of times to retry a failed selection
12847c478bd9Sstevel@tonic-gate  */
12857c478bd9Sstevel@tonic-gate #define	ST_SEL_RETRY_COUNT		2
12867c478bd9Sstevel@tonic-gate 
12877c478bd9Sstevel@tonic-gate /*
12887c478bd9Sstevel@tonic-gate  * es_code value for deferred error
12897c478bd9Sstevel@tonic-gate  * should be moved to sense.h
12907c478bd9Sstevel@tonic-gate  */
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate #define	ST_DEFERRED_ERROR		0x01
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate /*
12957c478bd9Sstevel@tonic-gate  * Maximum number of units (determined by minor device byte)
12967c478bd9Sstevel@tonic-gate  */
12977c478bd9Sstevel@tonic-gate #define	ST_MAXUNIT	128
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate /*
13007c478bd9Sstevel@tonic-gate  * Time to wait for completion of a command before cancelling it.
13017c478bd9Sstevel@tonic-gate  * For SUSPEND use only
13027c478bd9Sstevel@tonic-gate  */
13037c478bd9Sstevel@tonic-gate #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate #ifndef	SECSIZE
13067c478bd9Sstevel@tonic-gate #define	SECSIZE	512
13077c478bd9Sstevel@tonic-gate #endif
13087c478bd9Sstevel@tonic-gate #ifndef	SECDIV
13097c478bd9Sstevel@tonic-gate #define	SECDIV	9
13107c478bd9Sstevel@tonic-gate #endif
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate /*
13137c478bd9Sstevel@tonic-gate  * convenient defines
13147c478bd9Sstevel@tonic-gate  */
1315*f218e94bSrralphs #define	ST_SCSI_DEVP		(un->un_sd)
13167c478bd9Sstevel@tonic-gate #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
13177c478bd9Sstevel@tonic-gate #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
13187c478bd9Sstevel@tonic-gate #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
13197c478bd9Sstevel@tonic-gate #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
13207c478bd9Sstevel@tonic-gate #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
13237c478bd9Sstevel@tonic-gate #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
13247c478bd9Sstevel@tonic-gate #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
13257c478bd9Sstevel@tonic-gate #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
13267c478bd9Sstevel@tonic-gate #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
13277c478bd9Sstevel@tonic-gate #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
13287c478bd9Sstevel@tonic-gate #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
13297c478bd9Sstevel@tonic-gate #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
13307c478bd9Sstevel@tonic-gate #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
13337c478bd9Sstevel@tonic-gate 	((un)->un_state == ST_STATE_SENSING && \
13347c478bd9Sstevel@tonic-gate 		(un)->un_laststate == ST_STATE_CLOSING))
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate #define	ASYNC_CMD	0
13377c478bd9Sstevel@tonic-gate #define	SYNC_CMD	1
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate #define	st_bioerror(bp, error) \
13407c478bd9Sstevel@tonic-gate 		{ bioerror(bp, error); \
13417c478bd9Sstevel@tonic-gate 		un->un_errno = error; }
13427c478bd9Sstevel@tonic-gate 
13437c478bd9Sstevel@tonic-gate /*
13447c478bd9Sstevel@tonic-gate  * Macros for internal coding of count for SPACE command:
13457c478bd9Sstevel@tonic-gate  *
1346*f218e94bSrralphs  * Top 3 bits of b_bcount define direction and type of space.
1347*f218e94bSrralphs  * Since b_bcount (size_t) is 32 bits on 32 platforms and 64 bits on
1348*f218e94bSrralphs  * 64 bit platforms different defines are used.
1349*f218e94bSrralphs  * if SP_BACKSP is set direction is backward (toward BOP)
1350*f218e94bSrralphs  * The type of space (Blocks, Filemark or sequential filemarks) is
1351*f218e94bSrralphs  * carried in the next 2 bits. The remaining bits a signed count of
1352*f218e94bSrralphs  * how many of that direction and type to do.
13537c478bd9Sstevel@tonic-gate  */
1354*f218e94bSrralphs #if (SIZE_MAX < UINT64_MAX)
1355*f218e94bSrralphs 
1356*f218e94bSrralphs #define	SP_BLK		UINT32_C(0x00000000)
1357*f218e94bSrralphs #define	SP_FLM		UINT32_C(0x20000000)
1358*f218e94bSrralphs #define	SP_SQFLM	UINT32_C(0x40000000)
1359*f218e94bSrralphs #define	SP_EOD		UINT32_C(0x60000000)
1360*f218e94bSrralphs #define	SP_BACKSP	UINT32_C(0x80000000)
1361*f218e94bSrralphs #define	SP_CMD_MASK	UINT32_C(0x60000000)
1362*f218e94bSrralphs #define	SP_CNT_MASK	UINT32_C(0x1fffffff)
1363*f218e94bSrralphs 
1364*f218e94bSrralphs /* Macros to interpret space cmds */
1365*f218e94bSrralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1366*f218e94bSrralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1367*f218e94bSrralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>29)
1368*f218e94bSrralphs 
1369*f218e94bSrralphs #else /* end of small size_t in buf_t */
1370*f218e94bSrralphs 
1371*f218e94bSrralphs #define	SP_BLK		UINT64_C(0x0000000000000000)
1372*f218e94bSrralphs #define	SP_FLM		UINT64_C(0x2000000000000000)
1373*f218e94bSrralphs #define	SP_SQFLM	UINT64_C(0x4000000000000000)
1374*f218e94bSrralphs #define	SP_EOD		UINT64_C(0x6000000000000000)
1375*f218e94bSrralphs #define	SP_BACKSP	UINT64_C(0x8000000000000000)
1376*f218e94bSrralphs #define	SP_CMD_MASK	UINT64_C(0x6000000000000000)
1377*f218e94bSrralphs #define	SP_CNT_MASK	UINT64_C(0x1fffffffffffffff)
1378*f218e94bSrralphs 
1379*f218e94bSrralphs /* Macros to interpret space cmds */
1380*f218e94bSrralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1381*f218e94bSrralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1382*f218e94bSrralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>61)
1383*f218e94bSrralphs 
1384*f218e94bSrralphs #endif /* end of big size_t in buf_t */
1385c6914c10Srralphs 
1386c6914c10Srralphs /* Macros to assemble space cmds */
1387c6914c10Srralphs #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
1388c6914c10Srralphs #define	Fmk(x)		SPACE(SP_FLM, x)
1389c6914c10Srralphs #define	Blk(x)		SPACE(SP_BLK, x)
1390c6914c10Srralphs 
1391c6914c10Srralphs 
1392c6914c10Srralphs 
1393c6914c10Srralphs /* Defines for byte 4 of load/unload cmd */
1394c6914c10Srralphs #define	LD_UNLOAD	0
1395c6914c10Srralphs #define	LD_LOAD		1
1396c6914c10Srralphs #define	LD_RETEN	2
1397c6914c10Srralphs #define	LD_EOT		4
1398c6914c10Srralphs #define	LD_HOLD		8
1399c6914c10Srralphs 
1400c6914c10Srralphs /* Defines for byte 4 of prevent/allow media removal */
1401c6914c10Srralphs #define	MR_UNLOCK	0
1402c6914c10Srralphs #define	MR_LOCK		1
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate #define	GET_SOFT_STATE(dev)						\
14057c478bd9Sstevel@tonic-gate 	register struct scsi_tape *un;					\
14067c478bd9Sstevel@tonic-gate 	register int instance;						\
14077c478bd9Sstevel@tonic-gate 									\
14087c478bd9Sstevel@tonic-gate 	instance = MTUNIT(dev);						\
14097c478bd9Sstevel@tonic-gate 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
14107c478bd9Sstevel@tonic-gate 		return (ENXIO);
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate /*
14137c478bd9Sstevel@tonic-gate  * Debugging turned on via conditional compilation switch -DSTDEBUG
14147c478bd9Sstevel@tonic-gate  */
14157c478bd9Sstevel@tonic-gate #ifdef DEBUG
14167c478bd9Sstevel@tonic-gate #define	STDEBUG
14177c478bd9Sstevel@tonic-gate #endif
14187c478bd9Sstevel@tonic-gate 
14197c478bd9Sstevel@tonic-gate #ifdef	STDEBUG
1420*f218e94bSrralphs #define	DEBUGGING\
1421*f218e94bSrralphs 	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0x7))
14227c478bd9Sstevel@tonic-gate 
1423*f218e94bSrralphs #define	ST_DARGS(d) st_label, ((d == st_lastdev || d == 0) ?CE_CONT:CE_NOTE)
1424c6914c10Srralphs 
1425c6914c10Srralphs 	/* initialization */
1426*f218e94bSrralphs #define	ST_DEBUG1	if ((st_debug & 0x7) >= 1) scsi_log
14277c478bd9Sstevel@tonic-gate #define	ST_DEBUG	ST_DEBUG1
14287c478bd9Sstevel@tonic-gate 
1429c6914c10Srralphs 	/* errors and UA's */
1430*f218e94bSrralphs #define	ST_DEBUG2	if ((st_debug & 0x7) >= 2) scsi_log
1431c6914c10Srralphs 
1432c6914c10Srralphs 	/* func calls */
1433*f218e94bSrralphs #define	ST_DEBUG3	if ((st_debug & 0x7) >= 3) scsi_log
1434c6914c10Srralphs 
1435c6914c10Srralphs 	/* ioctl calls */
1436*f218e94bSrralphs #define	ST_DEBUG4	if ((st_debug & 0x7) >= 4) scsi_log
14377c478bd9Sstevel@tonic-gate 
1438*f218e94bSrralphs #define	ST_DEBUG5	if ((st_debug & 0x7) >= 5) scsi_log
1439c6914c10Srralphs 
1440c6914c10Srralphs 	/* full data tracking */
1441*f218e94bSrralphs #define	ST_DEBUG6	if ((st_debug & 0x7) >= 6) scsi_log
1442c6914c10Srralphs 
1443*f218e94bSrralphs 	/* debug error recovery */
1444*f218e94bSrralphs #define	ST_RECOV	if (st_debug & 0x8) scsi_log
1445c6914c10Srralphs 
1446c6914c10Srralphs 	/* Entry Point Functions */
1447*f218e94bSrralphs #define	ST_ENTR(d, fn)\
1448*f218e94bSrralphs     if (st_debug & 0x10) { scsi_log(d, ST_DARGS(d), #fn);\
1449*f218e94bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1450c6914c10Srralphs 
1451c6914c10Srralphs 	/* Non-Entry Point Functions */
1452*f218e94bSrralphs #define	ST_FUNC(d, fn)\
1453*f218e94bSrralphs     if (st_debug & 0x20) { scsi_log(d, ST_DARGS(d), #fn);\
1454*f218e94bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1455c6914c10Srralphs 
1456c6914c10Srralphs 	/* Space Information */
1457c6914c10Srralphs #define	ST_SPAC		if (st_debug & 0x40) scsi_log
1458c6914c10Srralphs 
1459c6914c10Srralphs 	/* CDB's sent */
1460*f218e94bSrralphs #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) { \
1461*f218e94bSrralphs     st_print_cdb(d, ST_DARGS(d), cmnt, cdb);\
1462*f218e94bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1463*f218e94bSrralphs 	/* sense data */
1464*f218e94bSrralphs #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) { \
1465*f218e94bSrralphs     st_clean_print(d, ST_DARGS(d), cmnt, sense, size);\
1466*f218e94bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1467*f218e94bSrralphs 	/* position data */
1468*f218e94bSrralphs #define	ST_POS(d, cmnt, pdata) if (st_debug & 0x400) { \
1469*f218e94bSrralphs     st_print_position(d, ST_DARGS(d), cmnt, pdata);\
1470*f218e94bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1471*f218e94bSrralphs 
14727c478bd9Sstevel@tonic-gate 
14737c478bd9Sstevel@tonic-gate #else
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate #define	st_debug	(0)
14767c478bd9Sstevel@tonic-gate #define	DEBUGGING	(0)
14777c478bd9Sstevel@tonic-gate #define	ST_DEBUG	if (0) scsi_log
14787c478bd9Sstevel@tonic-gate #define	ST_DEBUG1	if (0) scsi_log
14797c478bd9Sstevel@tonic-gate #define	ST_DEBUG2	if (0) scsi_log
14807c478bd9Sstevel@tonic-gate #define	ST_DEBUG3	if (0) scsi_log
14817c478bd9Sstevel@tonic-gate #define	ST_DEBUG4	if (0) scsi_log
14827c478bd9Sstevel@tonic-gate #define	ST_DEBUG5	if (0) scsi_log
14837c478bd9Sstevel@tonic-gate #define	ST_DEBUG6	if (0) scsi_log
1484*f218e94bSrralphs #define	ST_RECOV	if (0) scsi_log
14857c478bd9Sstevel@tonic-gate 
1486c6914c10Srralphs #define	ST_ENTR(d, fn)
1487c6914c10Srralphs #define	ST_FUNC(d, fn)
1488c6914c10Srralphs #define	ST_SPAC		if (0) scsi_log
1489c6914c10Srralphs #define	ST_CDB(d, cmnt, cdb)
1490c6914c10Srralphs #define	ST_SENSE(d, cmnt, sense, size)
1491*f218e94bSrralphs #define	ST_SENSE(d, cmnt, sense, size)
1492*f218e94bSrralphs #define	ST_POS(d, cmnt, pdata)
1493c6914c10Srralphs 
14947c478bd9Sstevel@tonic-gate #endif
14957c478bd9Sstevel@tonic-gate 
14967c478bd9Sstevel@tonic-gate /*
14977c478bd9Sstevel@tonic-gate  * Media access values
14987c478bd9Sstevel@tonic-gate  */
14997c478bd9Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
15007c478bd9Sstevel@tonic-gate 
15017c478bd9Sstevel@tonic-gate /*
15027c478bd9Sstevel@tonic-gate  * SCSI tape mode sense page information
15037c478bd9Sstevel@tonic-gate  */
15047c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
15057c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
15067c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
15077c478bd9Sstevel@tonic-gate #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
15087c478bd9Sstevel@tonic-gate 
15097c478bd9Sstevel@tonic-gate /*
15107c478bd9Sstevel@tonic-gate  * SCSI tape data compression Page definition.
15117c478bd9Sstevel@tonic-gate  */
15127c478bd9Sstevel@tonic-gate #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate /*
15177c478bd9Sstevel@tonic-gate  * maxbsize values
15187c478bd9Sstevel@tonic-gate  */
15197c478bd9Sstevel@tonic-gate #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
15207c478bd9Sstevel@tonic-gate 
15217c478bd9Sstevel@tonic-gate #define	ONE_MEG			(1024 * 1024)
15227c478bd9Sstevel@tonic-gate 
15237c478bd9Sstevel@tonic-gate /*
15247c478bd9Sstevel@tonic-gate  * generic soft error reporting
15257c478bd9Sstevel@tonic-gate  *
15267c478bd9Sstevel@tonic-gate  * What we are doing here is allowing a greater number of errors to occur on
15277c478bd9Sstevel@tonic-gate  * smaller transfers (i.e. usually at the beginning of the tape), than on
15287c478bd9Sstevel@tonic-gate  * the rest of the tape.
15297c478bd9Sstevel@tonic-gate  *
15307c478bd9Sstevel@tonic-gate  * A small transfer is defined as :
15317c478bd9Sstevel@tonic-gate  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
15327c478bd9Sstevel@tonic-gate  *
15337c478bd9Sstevel@tonic-gate  * A larget tranfer is defined as :
15347c478bd9Sstevel@tonic-gate  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
15357c478bd9Sstevel@tonic-gate  *
15367c478bd9Sstevel@tonic-gate  */
15377c478bd9Sstevel@tonic-gate #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
15387c478bd9Sstevel@tonic-gate #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
15397c478bd9Sstevel@tonic-gate 
15407c478bd9Sstevel@tonic-gate /*
15417c478bd9Sstevel@tonic-gate  * soft error reporting for exabyte
15427c478bd9Sstevel@tonic-gate  */
15437c478bd9Sstevel@tonic-gate #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
15447c478bd9Sstevel@tonic-gate 
15457c478bd9Sstevel@tonic-gate #define	SENSE_19_BITS  \
15467c478bd9Sstevel@tonic-gate 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
15477c478bd9Sstevel@tonic-gate #define	SENSE_20_BITS  \
15487c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
15497c478bd9Sstevel@tonic-gate #define	SENSE_21_BITS  \
15507c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
15517c478bd9Sstevel@tonic-gate 
15527c478bd9Sstevel@tonic-gate /* these are defined in percentages */
15537c478bd9Sstevel@tonic-gate #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
15547c478bd9Sstevel@tonic-gate #define	EXABYTE_READ_ERROR_THRESHOLD	3
15557c478bd9Sstevel@tonic-gate /*
15567c478bd9Sstevel@tonic-gate  * minumum amount of data transfer(MB) for checking soft error rate.
15577c478bd9Sstevel@tonic-gate  */
15587c478bd9Sstevel@tonic-gate #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
15597c478bd9Sstevel@tonic-gate 
15607c478bd9Sstevel@tonic-gate #define	CLN	0x8
15617c478bd9Sstevel@tonic-gate #define	CLND	0x10
15627c478bd9Sstevel@tonic-gate 
15637c478bd9Sstevel@tonic-gate /*
15647c478bd9Sstevel@tonic-gate  * soft error reporting for Archive 4mm DAT
15657c478bd9Sstevel@tonic-gate  */
15667c478bd9Sstevel@tonic-gate 
15677c478bd9Sstevel@tonic-gate #define	LOG_SENSE_LENGTH		0xff
15687c478bd9Sstevel@tonic-gate #define	MIN_LOG_SENSE_LENGTH		0x2b
15697c478bd9Sstevel@tonic-gate #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
15707c478bd9Sstevel@tonic-gate #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
15717c478bd9Sstevel@tonic-gate #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
15727c478bd9Sstevel@tonic-gate #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
15737c478bd9Sstevel@tonic-gate 
15747c478bd9Sstevel@tonic-gate /*
15757c478bd9Sstevel@tonic-gate  * ST timeouts that need to be cancelled for suspend
15767c478bd9Sstevel@tonic-gate  */
15777c478bd9Sstevel@tonic-gate #define	ST_HIB_TID	0x01
15787c478bd9Sstevel@tonic-gate #define	ST_DELAY_TID	0x02
15797c478bd9Sstevel@tonic-gate 
15807c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
15817c478bd9Sstevel@tonic-gate }
15827c478bd9Sstevel@tonic-gate #endif
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1585