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 /*
22*af483cc8Sjianfei wang - Sun Microsystems - Beijing China  * Copyright 2009 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 
29f3531714Scz #include <sys/sunddi.h>
307c478bd9Sstevel@tonic-gate #include <sys/note.h>
317c478bd9Sstevel@tonic-gate #include <sys/condvar.h>
327c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
33f218e94bSrralphs #include <sys/int_limits.h>
347c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
35c6914c10Srralphs #include <sys/scsi/generic/sense.h>
367c478bd9Sstevel@tonic-gate #include <sys/mtio.h>
37f218e94bSrralphs #include <sys/taskq.h>
38f218e94bSrralphs #include <sys/taskq_impl.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Defines for SCSI tape drives.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Maximum variable length record size for a single request
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE	65535
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
557c478bd9Sstevel@tonic-gate  * then the following define is used.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
60a6ccd511Srralphs #define	INF 1000000000	/* old external count backwards from this from EOF */
61a6ccd511Srralphs #define	LASTBLK (-1)	/* new internal count backwards from EOF */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Supported tape device types plus default type for opening.
657c478bd9Sstevel@tonic-gate  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
667c478bd9Sstevel@tonic-gate  * Types 14 - 1f, are 1/4-inch cartridge drives.
677c478bd9Sstevel@tonic-gate  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
687c478bd9Sstevel@tonic-gate  * Types 28+, are rdat (vcr) drives.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate #define	ST_TYPE_INVALID		0x00
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
737c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
767c478bd9Sstevel@tonic-gate #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
777c478bd9Sstevel@tonic-gate #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
787c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
817c478bd9Sstevel@tonic-gate #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
827c478bd9Sstevel@tonic-gate #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
837c478bd9Sstevel@tonic-gate #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
847c478bd9Sstevel@tonic-gate #define	ST_TYPE_HP	MT_ISHP		/* HP */
857c478bd9Sstevel@tonic-gate #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
867c478bd9Sstevel@tonic-gate #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
877c478bd9Sstevel@tonic-gate #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
907c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
917c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
927c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
937c478bd9Sstevel@tonic-gate #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
947c478bd9Sstevel@tonic-gate #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
957c478bd9Sstevel@tonic-gate #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
967c478bd9Sstevel@tonic-gate #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
977c478bd9Sstevel@tonic-gate #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
987c478bd9Sstevel@tonic-gate #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
997c478bd9Sstevel@tonic-gate #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
1005988135dSrralphs #define	ST_TYPE_AIT	MT_ISAIT	/* Sony AIT I, II, III and SAIT */
1015988135dSrralphs #define	ST_LAST_TYPE	ST_TYPE_AIT	/* Add new above type and change this */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /* Internal flags */
1057c478bd9Sstevel@tonic-gate #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
1067c478bd9Sstevel@tonic-gate 					/* alloc'ed from the st.conf entry, */
1077c478bd9Sstevel@tonic-gate 					/* instead of being used from the */
1087c478bd9Sstevel@tonic-gate 					/* st_drivetypes array. */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Defines for supported drive options
1127c478bd9Sstevel@tonic-gate  *
1137c478bd9Sstevel@tonic-gate  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
1147c478bd9Sstevel@tonic-gate  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate #define	ST_VARIABLE		0x001	/* Device supports variable	*/
1177c478bd9Sstevel@tonic-gate 					/* length record sizes		*/
1187c478bd9Sstevel@tonic-gate #define	ST_QIC			0x002	/* QIC tape device 		*/
1197c478bd9Sstevel@tonic-gate #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
1207c478bd9Sstevel@tonic-gate #define	ST_BSF			0x008	/* Device supports backspace	*/
1217c478bd9Sstevel@tonic-gate 					/* file as in mt(1) bsf : 	*/
1227c478bd9Sstevel@tonic-gate 					/* backspace over EOF marks.	*/
1237c478bd9Sstevel@tonic-gate 					/* Devices not supporting bsf 	*/
1247c478bd9Sstevel@tonic-gate 					/* will fail with ENOTTY upon	*/
1257c478bd9Sstevel@tonic-gate 					/* use of bsf			*/
1267c478bd9Sstevel@tonic-gate #define	ST_BSR			0x010	/* Device supports backspace	*/
1277c478bd9Sstevel@tonic-gate 					/* record as in mt(1) bsr :	*/
1287c478bd9Sstevel@tonic-gate 					/* backspace over records. If	*/
1297c478bd9Sstevel@tonic-gate 					/* the device does not support 	*/
1307c478bd9Sstevel@tonic-gate 					/* bsr, the st driver emulates	*/
1317c478bd9Sstevel@tonic-gate 					/* the action by rewinding the	*/
1327c478bd9Sstevel@tonic-gate 					/* tape and using forward space	*/
1337c478bd9Sstevel@tonic-gate 					/* file (fsf) to the correct	*/
1347c478bd9Sstevel@tonic-gate 					/* file and then uses forward	*/
1357c478bd9Sstevel@tonic-gate 					/* space record (fsr) to the	*/
1367c478bd9Sstevel@tonic-gate 					/* correct  record		*/
1377c478bd9Sstevel@tonic-gate #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
1387c478bd9Sstevel@tonic-gate 					/* than normal to erase		*/
1397c478bd9Sstevel@tonic-gate #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
1407c478bd9Sstevel@tonic-gate 					/* Device can figure out the	*/
1417c478bd9Sstevel@tonic-gate 					/* tape density automatically,	*/
1427c478bd9Sstevel@tonic-gate 					/* without issuing a		*/
1437c478bd9Sstevel@tonic-gate 					/* mode-select/mode-sense 	*/
1447c478bd9Sstevel@tonic-gate #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
1457c478bd9Sstevel@tonic-gate 					/* This disables the device's	*/
1467c478bd9Sstevel@tonic-gate 					/* ability for buffered	writes	*/
1477c478bd9Sstevel@tonic-gate 					/* I.e. The device acknowledges	*/
1487c478bd9Sstevel@tonic-gate 					/* write completion after the	*/
1497c478bd9Sstevel@tonic-gate 					/* data is written to the	*/
1507c478bd9Sstevel@tonic-gate 					/* device's buffer, but before	*/
1517c478bd9Sstevel@tonic-gate 					/* all the data is actually	*/
1527c478bd9Sstevel@tonic-gate 					/* written to tape		*/
1537c478bd9Sstevel@tonic-gate #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
1547c478bd9Sstevel@tonic-gate 					/* parity while talking to it. 	*/
1557c478bd9Sstevel@tonic-gate #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
1567c478bd9Sstevel@tonic-gate 					/* of Data) has been reached.	*/
1577c478bd9Sstevel@tonic-gate 					/* If the device knows EOD, st	*/
1587c478bd9Sstevel@tonic-gate 					/* uses fast file skipping.	*/
1597c478bd9Sstevel@tonic-gate 					/* If it does not know EOD,	*/
1607c478bd9Sstevel@tonic-gate 					/* file skipping happens one	*/
1617c478bd9Sstevel@tonic-gate 					/* file at a time. 		*/
1627c478bd9Sstevel@tonic-gate #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
1637c478bd9Sstevel@tonic-gate 					/* the st driver is unloaded &	*/
1647c478bd9Sstevel@tonic-gate 					/* loaded again; e.g. will	*/
1657c478bd9Sstevel@tonic-gate 					/* return the correct inquiry	*/
1667c478bd9Sstevel@tonic-gate 					/* string			*/
1677c478bd9Sstevel@tonic-gate #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
1687c478bd9Sstevel@tonic-gate 					/* close to report soft errors.	*/
1697c478bd9Sstevel@tonic-gate 					/* Currently only Exabyte and	*/
1707c478bd9Sstevel@tonic-gate 					/* DAT drives support this	*/
1717c478bd9Sstevel@tonic-gate 					/* feature.  			*/
1727c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
1737c478bd9Sstevel@tonic-gate 					/* timeouts for normal		*/
1747c478bd9Sstevel@tonic-gate 					/* operation			*/
1757c478bd9Sstevel@tonic-gate #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
1767c478bd9Sstevel@tonic-gate 					/* driver and pre-acked to the	*/
1777c478bd9Sstevel@tonic-gate 					/* application 			*/
1787c478bd9Sstevel@tonic-gate #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
1797c478bd9Sstevel@tonic-gate 					/* devices only. If flag is	*/
1807c478bd9Sstevel@tonic-gate 					/* set, then don't limit	*/
1817c478bd9Sstevel@tonic-gate 					/* record size to 64k as in	*/
1827c478bd9Sstevel@tonic-gate 					/* pre-Solaris 2.4 releases.	*/
1837c478bd9Sstevel@tonic-gate 					/* The only limit on the	*/
1847c478bd9Sstevel@tonic-gate 					/* record size will be the max	*/
1857c478bd9Sstevel@tonic-gate 					/* record size the device can	*/
1867c478bd9Sstevel@tonic-gate 					/* handle or the max DMA	*/
1877c478bd9Sstevel@tonic-gate 					/* transfer size of the		*/
1887c478bd9Sstevel@tonic-gate 					/* machine, which ever is	*/
1897c478bd9Sstevel@tonic-gate 					/* smaller. Beware of		*/
1907c478bd9Sstevel@tonic-gate 					/* incompatabilities with	*/
1917c478bd9Sstevel@tonic-gate 					/* tapes of pre-Solaris 2.4	*/
1927c478bd9Sstevel@tonic-gate 					/* OS's written with large	*/
1937c478bd9Sstevel@tonic-gate 					/* (>64k) block sizes, as	*/
1947c478bd9Sstevel@tonic-gate 					/* their true block size is	*/
1957c478bd9Sstevel@tonic-gate 					/* a max of approx 64k		*/
1967c478bd9Sstevel@tonic-gate #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
1977c478bd9Sstevel@tonic-gate 					/* configuration page (0x10) to */
1987c478bd9Sstevel@tonic-gate 					/* enable/disable compression	*/
1997c478bd9Sstevel@tonic-gate 					/* instead of density codes for */
2007c478bd9Sstevel@tonic-gate 					/* the "c" and "u" devices	*/
2017c478bd9Sstevel@tonic-gate #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
2027c478bd9Sstevel@tonic-gate 					/* support RESERVE/RELEASE SCSI	*/
2037c478bd9Sstevel@tonic-gate 					/* command. If this is enabled	*/
2047c478bd9Sstevel@tonic-gate 					/* then reserve/release would	*/
2057c478bd9Sstevel@tonic-gate 					/* not be used during open/	*/
2067c478bd9Sstevel@tonic-gate 					/* close for High Availability	*/
2077c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
2087c478bd9Sstevel@tonic-gate 					/* to variable block devices 	*/
2097c478bd9Sstevel@tonic-gate 					/* which support the SILI bit	*/
2107c478bd9Sstevel@tonic-gate 					/* option. It indicates that 	*/
2117c478bd9Sstevel@tonic-gate 					/* the SILI bit will be ignored */
2127c478bd9Sstevel@tonic-gate 					/* during reads  		*/
2137c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
2147c478bd9Sstevel@tonic-gate 					/* EOF marks do not indicate an */
2157c478bd9Sstevel@tonic-gate 					/* EOM. This option is only	*/
2167c478bd9Sstevel@tonic-gate 					/* supported on 1/2" reel tapes */
2177c478bd9Sstevel@tonic-gate #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
2187c478bd9Sstevel@tonic-gate 					/* EXABYTE 8mm tape drives 	*/
2197c478bd9Sstevel@tonic-gate 					/* which support short 		*/
2207c478bd9Sstevel@tonic-gate 					/* filemarks. When this flag 	*/
2217c478bd9Sstevel@tonic-gate 					/* is set, short filemarks 	*/
2227c478bd9Sstevel@tonic-gate 					/* will be used for writing	*/
2237c478bd9Sstevel@tonic-gate 					/* filemarks. 			*/
2247c478bd9Sstevel@tonic-gate #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
2257c478bd9Sstevel@tonic-gate 					/* and the tape is trapped in   */
2267c478bd9Sstevel@tonic-gate 					/* the medium changer, the tape */
2277c478bd9Sstevel@tonic-gate 					/* is automatically ejected	*/
2287c478bd9Sstevel@tonic-gate #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
2297c478bd9Sstevel@tonic-gate 					/* This option applies only to  */
2307c478bd9Sstevel@tonic-gate 					/* IBM MAGSTAR 3590. If this    */
2317c478bd9Sstevel@tonic-gate 					/* flag is set, the st driver   */
2327c478bd9Sstevel@tonic-gate 					/* will retry the last cmd if   */
2337c478bd9Sstevel@tonic-gate 					/* the last error cause a check */
2347c478bd9Sstevel@tonic-gate 					/* condition with error code    */
2357c478bd9Sstevel@tonic-gate 					/* 0x71 and sense code  0x01 	*/
2367c478bd9Sstevel@tonic-gate #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
2377c478bd9Sstevel@tonic-gate 					/* detected to select correct   */
2387c478bd9Sstevel@tonic-gate 					/* density code.		*/
2395988135dSrralphs #define	ST_WORMABLE		0x1000000
2405988135dSrralphs 					/* Drive is capable of doing	*/
2415988135dSrralphs 					/* Write Appends only at EOM	*/
2425988135dSrralphs 					/* if WORM media type is loaded */
2437c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
2447c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2457c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2467c478bd9Sstevel@tonic-gate 					/* byte 21, bitmask 0x08 of	*/
2477c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2487c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
2497c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2507c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2517c478bd9Sstevel@tonic-gate 					/* byte 70, bitmask 0xc0 of	*/
2527c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2537c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
2547c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2557c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2567c478bd9Sstevel@tonic-gate 					/* byte 18, bitmask 0x01 of	*/
2577c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2607c478bd9Sstevel@tonic-gate #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
2617c478bd9Sstevel@tonic-gate 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
2627c478bd9Sstevel@tonic-gate 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
2637c478bd9Sstevel@tonic-gate 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
2647c478bd9Sstevel@tonic-gate 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
2657c478bd9Sstevel@tonic-gate 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
2665988135dSrralphs 	ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate #define	NDENSITIES	MT_NDENSITIES
2697c478bd9Sstevel@tonic-gate #define	NSPEEDS		MT_NSPEEDS
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate  * defines for Log Sense Pages
2737c478bd9Sstevel@tonic-gate  */
2747c478bd9Sstevel@tonic-gate #define	SUPPORTED_LOG_PAGES_PAGE	0x00
2757c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE		0x0c
2767c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PAGE			0x2e
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  * Log Page Control definitions
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate #define	CURRENT_THRESHOLD_VALUES	0x00
2827c478bd9Sstevel@tonic-gate #define	CURRENT_CUMULATIVE_VALUES	0x40
2837c478bd9Sstevel@tonic-gate #define	DEFAULT_THRESHOLD_VALUES	0x80
2847c478bd9Sstevel@tonic-gate #define	DEFAULT_CUMULATIVE_VALUES	0xC0
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate /*
2877c478bd9Sstevel@tonic-gate  * Tape Alert Flag definitions
2887c478bd9Sstevel@tonic-gate  */
2895988135dSrralphs typedef enum {
2905988135dSrralphs 	TAF_READ_WARN			= 0x01,
2915988135dSrralphs 	TAF_WRITE_WARN			= 0x02,
2925988135dSrralphs 	TAF_HARD_ERR			= 0x03,
2935988135dSrralphs 	TAF_MEDIA_ERR			= 0x04,
2945988135dSrralphs 	TAF_READ_FAIL			= 0x05,
2955988135dSrralphs 	TAF_WRITE_FAIL			= 0x06,
2965988135dSrralphs 	TAF_MEDIA_LIFE			= 0x07,
2975988135dSrralphs 	TAF_MEDIA_NOT_DATA_GRADE	= 0x08,
2985988135dSrralphs 	TAF_WRITE_PROTECTED		= 0x09,
2995988135dSrralphs 	TAF_NO_MEDIA_REMOVE		= 0x0A,
3005988135dSrralphs 	TAF_CLEANING_MEDIA		= 0x0B,
3015988135dSrralphs 	TAF_UNSUPPERTED_FORMAT		= 0x0C,
3025988135dSrralphs 	TAF_RECOVERED_TAPE_BREAK	= 0x0D,
3035988135dSrralphs 	TAF_TAPE_BREAK_FAUL		= 0x0E,
3045988135dSrralphs 	TAF_CART_MEM_FAIL		= 0x0F,
3055988135dSrralphs 	TAF_FORCED_EJECT		= 0x10,
3065988135dSrralphs 	TAF_READ_ONLY_FORMAT		= 0x11,
3075988135dSrralphs 	TAF_TAPE_DIR_CORRUPT		= 0x12,
3085988135dSrralphs 	TAF_NEARING_MEDIA_LIFE		= 0x13,
3095988135dSrralphs 	TAF_CLEAN_NOW			= 0x14,
3105988135dSrralphs 	TAF_CLEAN_PERIODIC		= 0x15,
3115988135dSrralphs 	TAF_EXP_CLEAN_CART		= 0x16,
3125988135dSrralphs 	TAF_INVALID_CLEAN_MEDIA		= 0x17,
3135988135dSrralphs 	TAF_RETENSION_REQUEST		= 0x18,
3145988135dSrralphs 	TAF_DUAL_PORT_INTERFACE_ERR	= 0x19,
3155988135dSrralphs 	TAF_COOLING_FAN_FAIL		= 0x1A,
3165988135dSrralphs 	TAF_POWER_SUPPLY_FAIL		= 0x1B,
3175988135dSrralphs 	TAF_POWER_CONSUMPTION		= 0x1C,
3185988135dSrralphs 	TAF_DRIVE_MAINT_REQUEST		= 0x1D,
3195988135dSrralphs 	TAF_HARDWARE_A			= 0x1E,
3205988135dSrralphs 	TAF_HARDWARE_B			= 0x1F,
3215988135dSrralphs 	TAF_INTERFACE			= 0x20,
3225988135dSrralphs 	TAF_EJECT_MEDIA			= 0x21,
3235988135dSrralphs 	TAF_DOWNLOAD_FAIL		= 0x22,
3245988135dSrralphs 	TAF_DRIVE_HUMIDITY		= 0x23,
3255988135dSrralphs 	TAF_DRIVE_TEMP			= 0x24,
3265988135dSrralphs 	TAF_DRIVE_VOLTAGE		= 0x25,
3275988135dSrralphs 	TAF_PREDICTIVE_FAIL		= 0x26,
3285988135dSrralphs 	TAF_DIAG_REQUIRED		= 0x27,
3295988135dSrralphs 	TAF_LOADER_HDWR_A		= 0x28,
3305988135dSrralphs 	TAF_LOADER_STRAY_TAPE		= 0x29,
3315988135dSrralphs 	TAF_LOADER_HDWR_B		= 0x2A,
3325988135dSrralphs 	TAF_LOADER_DOOR			= 0x2B,
3335988135dSrralphs 	TAF_LOADER_HDWR_C		= 0x2C,
3345988135dSrralphs 	TAF_LOADER_MAGAZINE		= 0x2D,
3355988135dSrralphs 	TAF_LOADER_PREDICTIVE_FAIL	= 0x2E,
3365988135dSrralphs 	TAF_LOST_STATISTICS		= 0x32,
3375988135dSrralphs 	TAF_TAPE_DIR_CURRUPT_UNLOAD	= 0x33,
3385988135dSrralphs 	TAF_TAPE_SYS_WRT_FAIL		= 0x34,
3395988135dSrralphs 	TAF_TAPE_SYS_RD_FAIL		= 0x35,
3405988135dSrralphs 	TAF_NO_START_OF_DATA		= 0x36,
3415988135dSrralphs 	TAF_WORM_INTEGRITY		= 0x3B,
3425988135dSrralphs 	TAF_WORM_OVRWRT_ATTEMPT		= 0x3C
3435988135dSrralphs }tape_alert_flags;
3445988135dSrralphs 
3455988135dSrralphs /*
3465988135dSrralphs  * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension
3475988135dSrralphs  * so they reuse TAF_RETENSION_REQUEST.
3485988135dSrralphs  */
3495988135dSrralphs #define	CLEAN_FOR_ERRORS		 0x18
3505988135dSrralphs 
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
3537c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_NOT_SUPPORTED	0x01
3547c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORTED		0x02
3557c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_STILL_DIRTY		0x04
3567c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
3577c478bd9Sstevel@tonic-gate #define	TAPE_PREVIOUSLY_DIRTY		0x10
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_MAX_PARA		64
3607c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
3617c478bd9Sstevel@tonic-gate #define	SEQUENTIAL_NEED_CLN		0x0100
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /*
3647c478bd9Sstevel@tonic-gate  * Parameters
3657c478bd9Sstevel@tonic-gate  */
3667c478bd9Sstevel@tonic-gate #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
3677c478bd9Sstevel@tonic-gate #define	VIDLEN		8	/* size of vendor identifier length */
3687c478bd9Sstevel@tonic-gate #define	PIDLEN		16	/* size of product identifier length */
3697c478bd9Sstevel@tonic-gate #define	VIDPIDLEN	(VIDLEN + PIDLEN)
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate struct st_drivetype {
3737c478bd9Sstevel@tonic-gate 	char	name[ST_NAMESIZE];	/* Name, for debug */
3747c478bd9Sstevel@tonic-gate 	char	length;			/* Length of vendor id */
3757c478bd9Sstevel@tonic-gate 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
3767c478bd9Sstevel@tonic-gate 	char	type;			/* Drive type for driver */
3777c478bd9Sstevel@tonic-gate 	int	bsize;			/* Block size */
3787c478bd9Sstevel@tonic-gate 	int	options;		/* Drive options */
3797c478bd9Sstevel@tonic-gate 	int	max_rretries;		/* Max read retries */
3807c478bd9Sstevel@tonic-gate 	int	max_wretries;		/* Max write retries */
3817c478bd9Sstevel@tonic-gate 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
3827c478bd9Sstevel@tonic-gate 	uchar_t	default_density;	/* default density for this drive */
3837c478bd9Sstevel@tonic-gate 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
3847c478bd9Sstevel@tonic-gate 	ushort_t non_motion_timeout;	/* Inquiry type commands */
3857c478bd9Sstevel@tonic-gate 	ushort_t io_timeout;		/* I/O timeout in seconds */
3867c478bd9Sstevel@tonic-gate 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
3877c478bd9Sstevel@tonic-gate 	ushort_t space_timeout;		/* space cmd timeout in seconds */
3887c478bd9Sstevel@tonic-gate 	ushort_t load_timeout;		/* load tape time in seconds */
3897c478bd9Sstevel@tonic-gate 	ushort_t unload_timeout;	/* unload tape time in seconds */
3907c478bd9Sstevel@tonic-gate 	ushort_t erase_timeout;		/* erase timeout. seconds */
3917c478bd9Sstevel@tonic-gate };
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate #define	MINUTES(val)	((val) * 60)
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate struct comp_mode_page {
3967c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3977c478bd9Sstevel@tonic-gate 	uchar_t	:		6,
3987c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
3997c478bd9Sstevel@tonic-gate 		dce:		1;	/* Data Compression Enable */
4007c478bd9Sstevel@tonic-gate 	uchar_t	:		5,
4017c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4027c478bd9Sstevel@tonic-gate 		dde:		1;	/* Data Decompression Enabled */
4037c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4047c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4057c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4067c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4077c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4087c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4097c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4107c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4117c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4127c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4137c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4147c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4177c478bd9Sstevel@tonic-gate 	uchar_t	dce:		1,	/* Data Compression Enable */
4187c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4197c478bd9Sstevel@tonic-gate 		:		6;
4207c478bd9Sstevel@tonic-gate 	uchar_t	dde:		1,	/* Data Decompression Enabled */
4217c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4227c478bd9Sstevel@tonic-gate 		:		5;
4237c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4247c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4257c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4267c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4277c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4287c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4297c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4307c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4317c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4327c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4337c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4347c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4357c478bd9Sstevel@tonic-gate #endif
4367c478bd9Sstevel@tonic-gate };
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate struct dev_mode_page {
4397c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
4407c478bd9Sstevel@tonic-gate 	uchar_t	act_format:	5,	/* active format */
4417c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4425988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4437c478bd9Sstevel@tonic-gate 		:		1;
4447c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4457c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4467c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4477c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4487c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4497c478bd9Sstevel@tonic-gate 	uchar_t	rew:		1,	/* Report Early Warning */
4505988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4517c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4527c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4535988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4545988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4555988135dSrralphs 		obr:		1;	/* Object Buffer Recovery */
4565988135dSrralphs 	uchar_t	gap_size;		/* OBSOLETE */
4575988135dSrralphs 	uchar_t	bam:		1,	/* Block Address Mode */
4585988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4595988135dSrralphs 		swp:		1,	/* Software Write Protection */
4607c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4617c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4627c478bd9Sstevel@tonic-gate 		eod_defined:	3;
4637c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4647c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4657c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4667c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
4675988135dSrralphs 	uchar_t	prmwp:		1,	/* PeRManent Write Protect */
4685988135dSrralphs 		perswp:		1,	/* persistant write protection */
4695988135dSrralphs 		asocwp:		1,	/* associated write protect */
4705988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
4715988135dSrralphs 		oir:		1,	/* Only If Reserved */
4725988135dSrralphs 		wtre:		2;	/* Worm Tamper Read Enable */
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4757c478bd9Sstevel@tonic-gate 	uchar_t	:		1,
4765988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4777c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4787c478bd9Sstevel@tonic-gate 		act_format:	5;	/* active format */
4797c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4807c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4817c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4827c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4837c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4845988135dSrralphs 	uchar_t	obr:		1,	/* Object Buffer Recovery */
4855988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4865988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4877c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4887c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4895988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4907c478bd9Sstevel@tonic-gate 		rew:		1;	/* Report Early Warning */
4915988135dSrralphs 	uchar_t	gap_size;		/* OBSELETE */
4927c478bd9Sstevel@tonic-gate 	uchar_t	eod_defined:	3,
4937c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4947c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4955988135dSrralphs 		swp:		1,	/* Software Write Protection */
4965988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4975988135dSrralphs 		bam:		1;	/* Block Address Mode */
4987c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4997c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
5007c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
5017c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
5025988135dSrralphs 	uchar_t	wtre:		2,	/* Worm Tamper Read Enable */
5035988135dSrralphs 		oir:		1,	/* Only If Reserved */
5045988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
5055988135dSrralphs 		asocwp:		1,	/* associated write protect */
5065988135dSrralphs 		perswp:		1,	/* persistant write protection */
5075988135dSrralphs 		prmwp:		1;	/* PeRManent Write Protect */
5087c478bd9Sstevel@tonic-gate #endif
5097c478bd9Sstevel@tonic-gate };
5107c478bd9Sstevel@tonic-gate 
511*af483cc8Sjianfei wang - Sun Microsystems - Beijing China struct sas_lun_mode {
512*af483cc8Sjianfei wang - Sun Microsystems - Beijing China #if defined(_BIT_FIELDS_HTOL)
513*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	uchar_t :		3,
514*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 		tran_layer_ret:	1,
515*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 		protocol_id:	4;
516*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	uchar_t reserved[5];
517*af483cc8Sjianfei wang - Sun Microsystems - Beijing China #elif defined(_BIT_FIELDS_LTOH)
518*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	uchar_t protocol_id:	4,
519*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 		tran_layer_ret:	1,
520*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 		:		3;
521*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	uchar_t reserved[5];
522*af483cc8Sjianfei wang - Sun Microsystems - Beijing China #endif
523*af483cc8Sjianfei wang - Sun Microsystems - Beijing China };
5247c478bd9Sstevel@tonic-gate typedef union {
5257c478bd9Sstevel@tonic-gate 	struct comp_mode_page	comp;
5267c478bd9Sstevel@tonic-gate 	struct dev_mode_page	dev;
527*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	struct sas_lun_mode	saslun;
5287c478bd9Sstevel@tonic-gate }modepage;
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate /*
5317c478bd9Sstevel@tonic-gate  *
5327c478bd9Sstevel@tonic-gate  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
5337c478bd9Sstevel@tonic-gate  * The parameter list contains a header, followed by zero or more
5347c478bd9Sstevel@tonic-gate  * block descriptors, followed by vendor unique parameters, if any.
5357c478bd9Sstevel@tonic-gate  *
5367c478bd9Sstevel@tonic-gate  */
5377c478bd9Sstevel@tonic-gate #define	MSIZE	0x0c		/* Size without additional pages */
5387c478bd9Sstevel@tonic-gate struct seq_mode {
5397c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
5407c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5417c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5427c478bd9Sstevel@tonic-gate 	uchar_t	speed	:4,	/* speed */
5437c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5447c478bd9Sstevel@tonic-gate 		wp	:1;	/* write protected, sense only */
5457c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5467c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5477c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5487c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5497c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5507c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5517c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5527c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5537c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5547c478bd9Sstevel@tonic-gate 	uchar_t page_code:	6,
5557c478bd9Sstevel@tonic-gate 		:		1,
5567c478bd9Sstevel@tonic-gate 		ps:		1; /* Page Savable sense only */
5577c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5587c478bd9Sstevel@tonic-gate 	modepage page;
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
5617c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5627c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5637c478bd9Sstevel@tonic-gate 	uchar_t	wp	:1,	/* write protected, sense only */
5647c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5657c478bd9Sstevel@tonic-gate 		speed	:4;	/* speed */
5667c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5677c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5687c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5697c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5707c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5717c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5727c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5737c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5747c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5757c478bd9Sstevel@tonic-gate 	uchar_t	ps:		1, /* Page Savable sense only */
5767c478bd9Sstevel@tonic-gate 		:		1,
5777c478bd9Sstevel@tonic-gate 		page_code:	6;
5787c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5797c478bd9Sstevel@tonic-gate 	modepage page;
5807c478bd9Sstevel@tonic-gate #else
5817c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5827c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
5837c478bd9Sstevel@tonic-gate };
5847c478bd9Sstevel@tonic-gate 
5859f931db8Syl /*
5869f931db8Syl  * One_command parameter data for REPORT SUPPORTED OPERATION CODES.
5879f931db8Syl  */
5889f931db8Syl struct one_com_des {
5899f931db8Syl #if defined(_BIT_FIELDS_LTOH)
5909f931db8Syl 	uchar_t reserved0;
5919f931db8Syl 	uchar_t support:	3,	/* support value */
5929f931db8Syl 		reserved1:	4,
5939f931db8Syl 		ctdp:		1;	/* cmd timeouts descriptor present */
5949f931db8Syl 	ushort_t cdb_size;		/* cdb size */
5959f931db8Syl 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
5969f931db8Syl #elif defined(_BIT_FIELDS_HTOL)
5979f931db8Syl 	uchar_t reserved0;
5989f931db8Syl 	uchar_t ctdp:		1,	/* cmd timeouts descriptor present */
5999f931db8Syl 		reserved1:	4,
6009f931db8Syl 		support:	3;	/* support value */
6019f931db8Syl 	ushort_t cdb_size;		/* cdb size */
6029f931db8Syl 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
6039f931db8Syl #else
6049f931db8Syl #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
6059f931db8Syl #endif /* _BIT_FIELDS_LTOH */
6069f931db8Syl };
6079f931db8Syl 
6089f931db8Syl /*
6099f931db8Syl  * Command timeouts descriptor
6109f931db8Syl  */
6119f931db8Syl struct com_timeout_des {
6129f931db8Syl 	ushort_t des_len;	/* descriptor length */
6139f931db8Syl 	uchar_t reserved;
6149f931db8Syl 	uchar_t com_spe;	/* command specific */
6159f931db8Syl 	uint_t nom_timeout;	/* nominal command processing timeout */
6169f931db8Syl 	uint_t rec_timeout;	/* recommended command timeout */
6179f931db8Syl };
6189f931db8Syl 
6199f931db8Syl /*
6209f931db8Syl  * Reporting options
6219f931db8Syl  */
6229f931db8Syl #define	ALL_COMMAND_DATA_FORMAT			0
6239f931db8Syl #define	ONE_COMMAND_NO_SERVICE_DATA_FORMAT	1
6249f931db8Syl #define	ONE_COMMAND_DATA_FORMAT			2
6259f931db8Syl 
6269f931db8Syl /*
6279f931db8Syl  * Support values in One_command parameter data
6289f931db8Syl  */
6299f931db8Syl #define	SUPPORT_VALUES_NOT_AVAILABLE		0
6309f931db8Syl #define	SUPPORT_VALUES_NOT_SUPPORT		1
6319f931db8Syl #define	SUPPORT_VALUES_SUPPORT_SCSI		3
6329f931db8Syl #define	SUPPORT_VALUES_SUPPORT_VENDOR		5
6339f931db8Syl 
6349f931db8Syl /*
6359f931db8Syl  * Parameter data for REPORT DENSITY SUPPORT command
6369f931db8Syl  */
6379f931db8Syl struct report_density_header {
6389f931db8Syl 	ushort_t ava_dens_len;		/* available density support length */
6399f931db8Syl 	uchar_t reserved0;
6409f931db8Syl 	uchar_t reserved1;
6419f931db8Syl };
6429f931db8Syl 
6439f931db8Syl struct report_density_desc {
6449f931db8Syl #if defined(_BIT_FIELDS_LTOH)
6459f931db8Syl 	uchar_t pri_den;		/* primary density code */
6469f931db8Syl 	uchar_t sec_den;		/* secondary density code */
6479f931db8Syl 	uchar_t dlv:1;			/* descriptor length valid */
6489f931db8Syl 	uchar_t reserved:4;
6499f931db8Syl 	uchar_t deflt:1;		/* is default density */
6509f931db8Syl 	uchar_t dup:1;			/* pri density has one descriptor */
6519f931db8Syl 	uchar_t wrtok:1;		/* support writing to media */
6529f931db8Syl 	uchar_t desc_len_hi;		/* descriptor length high */
6539f931db8Syl 	uchar_t desc_len_low;		/* descriptor length low */
6549f931db8Syl 	uchar_t bits_per_mm[3];		/* bits per mm */
6559f931db8Syl 	uchar_t media_width_hi;		/* media width high */
6569f931db8Syl 	uchar_t media_width_low;	/* media width low */
6579f931db8Syl 	ushort_t tracks;		/* tracks */
6589f931db8Syl 	uint_t capacity;		/* capacity */
6599f931db8Syl 	uchar_t ass_org[8];		/* assigning organization */
6609f931db8Syl 	uchar_t den_name[8];		/* density name */
6619f931db8Syl 	uchar_t description[20];	/* description */
6629f931db8Syl #elif defined(_BIT_FIELDS_HTOL)
6639f931db8Syl 	uchar_t pri_den;		/* primary density code */
6649f931db8Syl 	uchar_t sec_den;		/* secondary density code */
6659f931db8Syl 	uchar_t wrtok:1;		/* support writing to media */
6669f931db8Syl 	uchar_t dup:1;			/* pri density has one descriptor */
6679f931db8Syl 	uchar_t deflt:1;		/* is default density */
6689f931db8Syl 	uchar_t reserved:4;
6699f931db8Syl 	uchar_t dlv:1;			/* descriptor length valid */
6709f931db8Syl 	uchar_t desc_len_hi;		/* descriptor length high */
6719f931db8Syl 	uchar_t desc_len_low;		/* descriptor length low */
6729f931db8Syl 	uchar_t bits_per_mm[3];		/* bits per mm */
6739f931db8Syl 	uchar_t media_width_hi;		/* media width high */
6749f931db8Syl 	uchar_t media_width_low;	/* media width low */
6759f931db8Syl 	ushort_t tracks;		/* tracks */
6769f931db8Syl 	uint_t capacity;		/* capacity */
6779f931db8Syl 	uchar_t ass_org[8];		/* assigning organization */
6789f931db8Syl 	uchar_t den_name[8];		/* density name */
6799f931db8Syl 	uchar_t description[20];	/* description */
6809f931db8Syl #else
6819f931db8Syl #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
6829f931db8Syl #endif  /* _BIT_FIELDS_LTOH */
6839f931db8Syl };
6849f931db8Syl 
6857c478bd9Sstevel@tonic-gate /*
6867c478bd9Sstevel@tonic-gate  * Data returned from the READ BLOCK LIMITS command.
6877c478bd9Sstevel@tonic-gate  */
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate #define	RBLSIZE	(sizeof (struct read_blklim))
6907c478bd9Sstevel@tonic-gate struct read_blklim {
6917c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL)
6927c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6937c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6947c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_LTOH)
6957c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
6967c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
6977c478bd9Sstevel@tonic-gate #endif
6987c478bd9Sstevel@tonic-gate 	uchar_t	max_hi;			/* Maximum block length, high byte */
6997c478bd9Sstevel@tonic-gate 	uchar_t	max_mid;		/* Maximum block length, middle byte */
7007c478bd9Sstevel@tonic-gate 	uchar_t	max_lo;			/* Maximum block length, low byte */
7017c478bd9Sstevel@tonic-gate 	uchar_t	min_hi;			/* Minimum block length, high byte */
7027c478bd9Sstevel@tonic-gate 	uchar_t	min_lo;			/* Minimum block length, low byte */
7037c478bd9Sstevel@tonic-gate };
7047c478bd9Sstevel@tonic-gate 
705c6914c10Srralphs /*
706c6914c10Srralphs  * operation codes
707c6914c10Srralphs  */
708c6914c10Srralphs typedef enum {
709c6914c10Srralphs 	ST_OP_NIL,
710c6914c10Srralphs 	ST_OP_CTL,
711c6914c10Srralphs 	ST_OP_READ,
712c6914c10Srralphs 	ST_OP_WRITE,
713c6914c10Srralphs 	ST_OP_WEOF
714c6914c10Srralphs }optype;
715c6914c10Srralphs 
716c6914c10Srralphs /*
717c6914c10Srralphs  * eof/eot/eom codes.
718c6914c10Srralphs  */
719c6914c10Srralphs typedef enum {
720c6914c10Srralphs 	ST_NO_EOF,
721c6914c10Srralphs 	ST_EOF_PENDING,		/* filemark pending */
722c6914c10Srralphs 	ST_EOF,			/* at filemark */
723c6914c10Srralphs 	ST_EOT_PENDING,		/* logical eot pending */
724c6914c10Srralphs 	ST_EOT,			/* at logical eot */
725c6914c10Srralphs 	ST_EOM,			/* at physical eot */
726c6914c10Srralphs 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
727c6914c10Srralphs }pstatus;
728c6914c10Srralphs 
729c6914c10Srralphs typedef enum { invalid, legacy, logical } posmode;
730c6914c10Srralphs 
731c6914c10Srralphs typedef struct tapepos {
732c6914c10Srralphs 	uint64_t lgclblkno;
733c6914c10Srralphs 	int32_t fileno;
734c6914c10Srralphs 	int32_t blkno;
735c6914c10Srralphs 	int32_t partition;
736c6914c10Srralphs 	pstatus eof;			/* eof states */
737c6914c10Srralphs 	posmode	pmode;
738f218e94bSrralphs 	uint32_t: 32;
739c6914c10Srralphs }tapepos_t;
740c6914c10Srralphs 
741c6914c10Srralphs /* byte 1 of cdb for type of read position command */
742c6914c10Srralphs typedef enum {
743c6914c10Srralphs 	SHORT_POS	= 0,
744c6914c10Srralphs 	LONG_POS	= 6,
745c6914c10Srralphs 	EXT_POS		= 8,
746c6914c10Srralphs 	NO_POS		= 0xff	/* Drive doesn't support read position */
747c6914c10Srralphs } read_p_types;
748c6914c10Srralphs 
749c6914c10Srralphs 
750c6914c10Srralphs /*
751c6914c10Srralphs  * Data returned from the READ POSITION command.
752c6914c10Srralphs  */
753c6914c10Srralphs 
754c6914c10Srralphs typedef struct tape_position {
755c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
756c6914c10Srralphs 	uchar_t begin_of_part:	1;
757c6914c10Srralphs 	uchar_t end_of_part:	1;
758c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
759c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
760c6914c10Srralphs 	uchar_t reserved0:	1;
761c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
762c6914c10Srralphs 	uchar_t posi_err:	1;
763c6914c10Srralphs 	uchar_t reserved1:	1;
764c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
765c6914c10Srralphs 	uchar_t reserved1:	1;
766c6914c10Srralphs 	uchar_t posi_err:	1;
767c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
768c6914c10Srralphs 	uchar_t reserved0:	1;
769c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
770c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
771c6914c10Srralphs 	uchar_t end_of_part:	1;
772c6914c10Srralphs 	uchar_t begin_of_part:	1;
773c6914c10Srralphs #endif
774c6914c10Srralphs 	uchar_t partition_number;
775c6914c10Srralphs 	uchar_t reserved2[2];
776c6914c10Srralphs 	uint32_t host_block;
777c6914c10Srralphs 	uint32_t media_block;
778c6914c10Srralphs 	uchar_t reserved3;
779c6914c10Srralphs 	uchar_t block_in_buff[3];
780c6914c10Srralphs 	uint32_t byte_in_buff;
781c6914c10Srralphs }tape_position_t;
782c6914c10Srralphs 
783c6914c10Srralphs 
784c6914c10Srralphs typedef struct tape_position_long {
785c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
786c6914c10Srralphs 	uint32_t begin_of_part:	1;
787c6914c10Srralphs 	uint32_t end_of_part:	1;
788c6914c10Srralphs 	uint32_t reserved0:	2;
789c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
790c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
791c6914c10Srralphs 	uint32_t reserved1:	2;
792c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
793c6914c10Srralphs 	uint32_t reserved1:	2;
794c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
795c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
796c6914c10Srralphs 	uint32_t reserved0:	2;
797c6914c10Srralphs 	uint32_t end_of_part:   1;
798c6914c10Srralphs 	uint32_t begin_of_part: 1;
799c6914c10Srralphs #endif
800c6914c10Srralphs 	uint32_t reserved2:	24;
801c6914c10Srralphs 	uint32_t partition;
802c6914c10Srralphs 	uint64_t block_number;
803c6914c10Srralphs 	uint64_t file_number;
804c6914c10Srralphs 	uint64_t set_number;
805c6914c10Srralphs }tape_position_long_t;
806c6914c10Srralphs 
807c6914c10Srralphs typedef struct tape_position_ext {
808c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
809f218e94bSrralphs 	uchar_t begin_of_part:	1;
810f218e94bSrralphs 	uchar_t end_of_part:	1;
811f218e94bSrralphs 	uchar_t blk_cnt_unkwn:	1;
812f218e94bSrralphs 	uchar_t byte_cnt_unkwn:	1;
813f218e94bSrralphs 	uchar_t mrk_posi_unkwn:	1;
814f218e94bSrralphs 	uchar_t blk_posi_unkwn:	1;
815f218e94bSrralphs 	uchar_t posi_err:	1;
816f218e94bSrralphs 	uchar_t reserved0:	1;
817f218e94bSrralphs 
818f218e94bSrralphs 	uchar_t partition;
819f218e94bSrralphs 	uint16_t parameter_len;
820c6914c10Srralphs /* start next word */
821c6914c10Srralphs 	uint32_t reserved1:	8;
822c6914c10Srralphs 	uint32_t blks_in_buf:	24;
823c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
824f218e94bSrralphs 	uchar_t reserved0:	1;
825f218e94bSrralphs 	uchar_t posi_err:	1;
826f218e94bSrralphs 	uchar_t blk_posi_unkwn:	1;
827f218e94bSrralphs 	uchar_t mrk_posi_unkwn:	1;
828f218e94bSrralphs 	uchar_t byte_cnt_unkwn:	1;
829f218e94bSrralphs 	uchar_t blk_cnt_unkwn:	1;
830f218e94bSrralphs 	uchar_t end_of_part:	1;
831f218e94bSrralphs 	uchar_t begin_of_part:	1;
832f218e94bSrralphs 
833f218e94bSrralphs 	uchar_t partition;
834f218e94bSrralphs 	uint16_t parameter_len;
835c6914c10Srralphs /* start next word */
836c6914c10Srralphs 	uint32_t blks_in_buf:	24;
837c6914c10Srralphs 	uint32_t reserved1:	8;
838c6914c10Srralphs #endif
839c6914c10Srralphs 	uint64_t host_block;
840c6914c10Srralphs 	uint64_t media_block;
841c6914c10Srralphs 	uint64_t byte_in_buf;
842c6914c10Srralphs }tape_position_ext_t;
843c6914c10Srralphs 
844c6914c10Srralphs typedef union {
845c6914c10Srralphs 	tape_position_t srt;
846c6914c10Srralphs 	tape_position_ext_t ext;
847c6914c10Srralphs 	tape_position_long_t lng;
848c6914c10Srralphs }read_pos_data_t;
849c6914c10Srralphs 
850f218e94bSrralphs typedef struct {
851f218e94bSrralphs 	unsigned char cmd;
852f218e94bSrralphs 	unsigned char
853f218e94bSrralphs 		requires_reserve:	1,	/* reserve must be done */
854f218e94bSrralphs 		retriable:		1,	/* can be retried */
855f218e94bSrralphs 		chg_tape_pos:		1,	/* position will change */
856f218e94bSrralphs 		chg_tape_data:		1,	/* data on media will change */
8579fa098b4Sbo zhou - Sun Microsystems - Beijing China 		explicit_cmd_set:	1,	/* explicit command set */
858f218e94bSrralphs 		/*
859f218e94bSrralphs 		 * 0 doesn't, 1 forward,
860f218e94bSrralphs 		 * 2 back, 3 either
861f218e94bSrralphs 		 */
862f218e94bSrralphs 		chg_tape_direction:	2;	/* direction of pos change */
863f218e94bSrralphs #define	DIR_NONE	0
864f218e94bSrralphs #define	DIR_FORW	1
865f218e94bSrralphs #define	DIR_REVC	2
866f218e94bSrralphs #define	DIR_EITH	3
867f218e94bSrralphs 	unsigned char
868f218e94bSrralphs 		/*
869f218e94bSrralphs 		 * 0 doesn't 1 read, 2 write
870f218e94bSrralphs 		 */
871f218e94bSrralphs 		transfers_data:		2,
872f218e94bSrralphs #define	TRAN_NONE	0
873f218e94bSrralphs #define	TRAN_READ	1
874f218e94bSrralphs #define	TRAN_WRTE	2
875f218e94bSrralphs 		recov_pos_type:		1,
876f218e94bSrralphs #define	POS_EXPECTED	0
877f218e94bSrralphs #define	POS_STARTING	1
878f218e94bSrralphs 		do_not_recover:		1;
879f218e94bSrralphs 	uchar_t reserve_byte;
880f218e94bSrralphs 	uint32_t reserve_mask;
881f218e94bSrralphs 	uint64_t (*get_cnt)(uchar_t *);
882f218e94bSrralphs 	uint64_t (*get_lba)(uchar_t *);
883f218e94bSrralphs }cmd_attribute;
884f218e94bSrralphs 
885f218e94bSrralphs typedef struct {
886f218e94bSrralphs 	buf_t *cmd_bp;
887f218e94bSrralphs 	size_t privatelen;
8880205780bSrralphs 	int str_retry_cnt;
8890205780bSrralphs 	int pkt_retry_cnt;
890f218e94bSrralphs }pkt_info;
891f218e94bSrralphs 
892f218e94bSrralphs typedef struct {
893f218e94bSrralphs 	buf_t *cmd_bp;
894f218e94bSrralphs 	size_t privatelen;
8950205780bSrralphs 	int str_retry_cnt;
8960205780bSrralphs 	int pkt_retry_cnt;
897f218e94bSrralphs 	tapepos_t pos;
898f218e94bSrralphs 	const cmd_attribute *cmd_attrib;
899f218e94bSrralphs }recov_info;
900f218e94bSrralphs 
901f3531714Scz #ifdef _KERNEL
902f3531714Scz 
90336945f79Smrj #ifdef	__x86
904f3531714Scz /* Data structure used in big block I/O on x86/x64 platform */
905f3531714Scz 
906f3531714Scz /*
907f3531714Scz  * alloc more than one contig_mem, so mutiple I/O can be
908f3531714Scz  * on-going simultaneously
909f3531714Scz  */
910f3531714Scz #define	ST_MAX_CONTIG_MEM_NUM	3
911f3531714Scz 
912f3531714Scz struct contig_mem {
913f3531714Scz 	struct contig_mem *cm_next;
914f3531714Scz 	size_t cm_len;
915f3531714Scz 	caddr_t cm_addr;
916f3531714Scz 	ddi_acc_handle_t cm_acc_hdl;
917f3531714Scz 	struct buf *cm_bp;
918f3531714Scz 	int cm_use_sbuf;
919f3531714Scz };
9204ebb14b2Sfrits 
921f3531714Scz #endif
922f3531714Scz 
923f3531714Scz #endif /* _KERNEL */
924f3531714Scz 
9255988135dSrralphs /*
926c6914c10Srralphs  * driver states..
9275988135dSrralphs  */
9285988135dSrralphs typedef enum {
929c6914c10Srralphs 	ST_STATE_CLOSED,
930c6914c10Srralphs 	ST_STATE_OFFLINE,
931c6914c10Srralphs 	ST_STATE_INITIALIZING,
932c6914c10Srralphs 	ST_STATE_OPENING,
933c6914c10Srralphs 	ST_STATE_OPEN_PENDING_IO,
934c6914c10Srralphs 	ST_STATE_APPEND_TESTING,
935c6914c10Srralphs 	ST_STATE_OPEN,
936c6914c10Srralphs 	ST_STATE_RESOURCE_WAIT,
937c6914c10Srralphs 	ST_STATE_CLOSING,
938c6914c10Srralphs 	ST_STATE_SENSING,
939c6914c10Srralphs 	ST_STATE_CLOSE_PENDING_OPEN
940c6914c10Srralphs }st_states;
941c6914c10Srralphs 
942c6914c10Srralphs typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
943*af483cc8Sjianfei wang - Sun Microsystems - Beijing China typedef enum {
944*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	TLR_NOT_KNOWN,
945*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	TLR_NOT_SUPPORTED,
946*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	TLR_SAS_ONE_DEVICE,
947*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	TLR_SAS_TWO_DEVICE
948*af483cc8Sjianfei wang - Sun Microsystems - Beijing China }st_tlr_state;
9495988135dSrralphs 
9505988135dSrralphs 
9517c478bd9Sstevel@tonic-gate /*
9527c478bd9Sstevel@tonic-gate  * Private info for scsi tapes. Pointed to by the un_private pointer
9537c478bd9Sstevel@tonic-gate  * of one of the SCSI_DEVICE chains.
9547c478bd9Sstevel@tonic-gate  */
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate struct scsi_tape {
9577c478bd9Sstevel@tonic-gate 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
9587c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
9597c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
9607c478bd9Sstevel@tonic-gate 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
9617c478bd9Sstevel@tonic-gate 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
9627c478bd9Sstevel@tonic-gate 	struct	buf *un_sbufp;		/* for use in special io */
9637c478bd9Sstevel@tonic-gate 	char	*un_srqbufp;		/* sense buffer for special io */
9647c478bd9Sstevel@tonic-gate 	kcondvar_t un_clscv;		/* closing cv */
9657c478bd9Sstevel@tonic-gate 	struct	buf *un_quef;		/* head of wait queue */
9667c478bd9Sstevel@tonic-gate 	struct	buf *un_quel;		/* tail of wait queue */
9677c478bd9Sstevel@tonic-gate 	struct	buf *un_runqf;		/* head of run queue */
9687c478bd9Sstevel@tonic-gate 	struct	buf *un_runql;		/* tail of run queue */
9697c478bd9Sstevel@tonic-gate 	struct seq_mode *un_mspl;	/* ptr to mode select info */
9707c478bd9Sstevel@tonic-gate 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
9717c478bd9Sstevel@tonic-gate 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
9727c478bd9Sstevel@tonic-gate 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
973c6914c10Srralphs 	tapepos_t un_pos;		/* Current tape position */
9747c478bd9Sstevel@tonic-gate 	int	un_oflags;		/* open flags */
975c6914c10Srralphs 	tapepos_t un_err_pos;		/* block in file where err occurred */
9767c478bd9Sstevel@tonic-gate 	uint_t	un_err_resid;		/* resid from last error */
9777c478bd9Sstevel@tonic-gate 	short	un_fmneeded;		/* filemarks to be written - HP only */
9787c478bd9Sstevel@tonic-gate 	dev_t	un_dev;			/* unix device */
9797c478bd9Sstevel@tonic-gate 	uchar_t	un_attached;		/* unit known && attached */
9807c478bd9Sstevel@tonic-gate 	int	un_pwr_mgmt;		/* power management state */
9817c478bd9Sstevel@tonic-gate 	uchar_t	un_density_known;	/* density is known */
9827c478bd9Sstevel@tonic-gate 	uchar_t	un_curdens;		/* index into density table */
9835988135dSrralphs 	optype	un_lastop;		/* last I/O was: read/write/ctl */
984c6914c10Srralphs 	st_states un_laststate;		/* last state */
985c6914c10Srralphs 	st_states un_state;		/* current state */
9867c478bd9Sstevel@tonic-gate 	uchar_t	un_status;		/* status from last sense */
9877c478bd9Sstevel@tonic-gate 	uchar_t	un_retry_ct;		/* retry count */
9885988135dSrralphs 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
9897c478bd9Sstevel@tonic-gate 	uchar_t	un_test_append;		/* check writing at end of tape */
9907c478bd9Sstevel@tonic-gate 	uchar_t un_arq_enabled;		/* auto request sense enabled */
9917c478bd9Sstevel@tonic-gate 	uchar_t un_untagged_qing;	/* hba has untagged quing */
9927c478bd9Sstevel@tonic-gate 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
9937c478bd9Sstevel@tonic-gate 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
9947c478bd9Sstevel@tonic-gate 	uchar_t	un_ncmds;		/* number of commands outstanding */
9957c478bd9Sstevel@tonic-gate 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
9967c478bd9Sstevel@tonic-gate 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
9977c478bd9Sstevel@tonic-gate 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
9987c478bd9Sstevel@tonic-gate 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
9997c478bd9Sstevel@tonic-gate 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
10007c478bd9Sstevel@tonic-gate 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
10017c478bd9Sstevel@tonic-gate 					/* check condidtion or error */
10027c478bd9Sstevel@tonic-gate 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
10037c478bd9Sstevel@tonic-gate 	uint_t	un_last_resid;		/* keep last resid, for PE */
10047c478bd9Sstevel@tonic-gate 	uint_t	un_last_count;		/* keep last count, for PE */
10057c478bd9Sstevel@tonic-gate 	struct 	kstat *un_stats;	/* for I/O statistics */
10067c478bd9Sstevel@tonic-gate 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
10077c478bd9Sstevel@tonic-gate 	struct	buf *un_wf;		/* head of write queue */
10087c478bd9Sstevel@tonic-gate 	struct	buf *un_wl;		/* tail of write queue */
10097c478bd9Sstevel@tonic-gate 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
10107c478bd9Sstevel@tonic-gate 	int	un_maxdma;		/* max dma xfer allowed by HBA */
10117c478bd9Sstevel@tonic-gate 	uint_t	un_bsize;		/* block size currently being used */
10127c478bd9Sstevel@tonic-gate 	int	un_maxbsize;		/* max block size allowed by drive */
10137c478bd9Sstevel@tonic-gate 	uint_t	un_minbsize;		/* min block size allowed by drive */
10147c478bd9Sstevel@tonic-gate 	int	un_errno;		/* errno (b_error) */
10157c478bd9Sstevel@tonic-gate 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
10167c478bd9Sstevel@tonic-gate 	enum mtio_state	un_mediastate;	/* current media state */
10177c478bd9Sstevel@tonic-gate 	enum mtio_state	un_specified_mediastate;	/* expected state */
10187c478bd9Sstevel@tonic-gate 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
10197c478bd9Sstevel@tonic-gate 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
10207c478bd9Sstevel@tonic-gate 	opaque_t	un_swr_token;	/* scsi_watch request token */
10217c478bd9Sstevel@tonic-gate 	uchar_t	un_comp_page;		/* compression page */
10227c478bd9Sstevel@tonic-gate 	uchar_t	un_rsvd_status;		/* Reservation Status */
10237c478bd9Sstevel@tonic-gate 	kstat_t *un_errstats;		/* for error statistics */
1024f218e94bSrralphs 	int	un_init_options;	/* Init time drive options */
10257c478bd9Sstevel@tonic-gate 	int	un_save_fileno;		/* Save here for recovery */
10267c478bd9Sstevel@tonic-gate 	daddr_t	un_save_blkno;		/* Save here for recovery */
1027c6914c10Srralphs 	uchar_t un_restore_pos;		/* Indication to do recovery */
1028c6914c10Srralphs 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
10297c478bd9Sstevel@tonic-gate 	uchar_t	un_silent_skip;		/* to catch short reads */
1030c6914c10Srralphs 	short	un_tids_at_suspend;	/* timeouts set at suspend */
1031c6914c10Srralphs 	kcondvar_t un_tape_busy_cv;	/* busy cv */
1032c6914c10Srralphs 	kcondvar_t un_suspend_cv;	/* busy cv */
10337c478bd9Sstevel@tonic-gate 					/* restore on close */
10347c478bd9Sstevel@tonic-gate 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
10357c478bd9Sstevel@tonic-gate 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
10367c478bd9Sstevel@tonic-gate 	uchar_t	un_rqs_state;		/* see define below */
1037c6914c10Srralphs 	struct scsi_extended_sense
1038c6914c10Srralphs 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
10397c478bd9Sstevel@tonic-gate 	uchar_t	un_data_mod;		/* Device required data mod */
10405988135dSrralphs 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
10415988135dSrralphs 	int un_max_cdb_sz;		/* max cdb size to use */
1042c6914c10Srralphs 	read_p_types un_read_pos_type;
1043c6914c10Srralphs 	read_pos_data_t *un_read_pos_data;
1044fa4c0ec8Sbz 	struct mterror_entry_stack *un_error_entry_stk;
1045fa4c0ec8Sbz 					/* latest sense cmd buffer */
104636945f79Smrj #ifdef	__x86
1047f3531714Scz 	ddi_dma_handle_t un_contig_mem_hdl;
1048f3531714Scz 	struct contig_mem *un_contig_mem;
1049f3531714Scz 	int un_contig_mem_available_num;
1050f3531714Scz 	int un_contig_mem_total_num;
1051a7333962Scz 	size_t un_max_contig_mem_len;
1052f3531714Scz 	kcondvar_t un_contig_mem_cv;
105336945f79Smrj 	int un_maxdma_arch;		/* max dma xfer allowed by HBA & arch */
1054f3531714Scz #endif
1055f218e94bSrralphs 	caddr_t un_media_id;
1056f218e94bSrralphs 	int un_media_id_len;
1057f218e94bSrralphs 	int (*un_media_id_method)(struct scsi_tape *, int (*)());
1058f218e94bSrralphs 	buf_t *un_recov_buf;		/* buf to recover failed commands */
1059f218e94bSrralphs 	kcondvar_t un_recov_buf_cv;	/* cv for buf un_recov_buf */
1060f218e94bSrralphs 	uchar_t un_recov_buf_busy;
1061f218e94bSrralphs #ifdef _KERNEL
1062f218e94bSrralphs 	ddi_taskq_t *un_recov_taskq;
1063f218e94bSrralphs #else
1064f218e94bSrralphs 	void *un_recov_taskq;
1065f218e94bSrralphs #endif
1066f218e94bSrralphs 	tapepos_t un_running;
1067f218e94bSrralphs 	uchar_t un_unit_attention_flags;
10680205780bSrralphs 	uchar_t un_multipath;
10690205780bSrralphs 	ulong_t un_last_path_instance;
1070*af483cc8Sjianfei wang - Sun Microsystems - Beijing China 	st_tlr_state un_tlr_flag;		/* tape support TLR flag */
10717c478bd9Sstevel@tonic-gate };
10724ebb14b2Sfrits 
1073f218e94bSrralphs typedef int (*bufunc_t)(struct scsi_tape *, int, int64_t, int);
1074f218e94bSrralphs typedef int (*ubufunc_t)(struct scsi_tape *, struct uscsi_cmd *, int);
1075f218e94bSrralphs 
10764ebb14b2Sfrits 
10777c478bd9Sstevel@tonic-gate /*
10787c478bd9Sstevel@tonic-gate  * device error kstats
10797c478bd9Sstevel@tonic-gate  */
10807c478bd9Sstevel@tonic-gate struct st_errstats {
10817c478bd9Sstevel@tonic-gate 	struct kstat_named	st_softerrs;
10827c478bd9Sstevel@tonic-gate 	struct kstat_named	st_harderrs;
10837c478bd9Sstevel@tonic-gate 	struct kstat_named	st_transerrs;
10847c478bd9Sstevel@tonic-gate 	struct kstat_named	st_vid;
10857c478bd9Sstevel@tonic-gate 	struct kstat_named	st_pid;
10867c478bd9Sstevel@tonic-gate 	struct kstat_named	st_revision;
10877c478bd9Sstevel@tonic-gate 	struct kstat_named	st_serial;
10887c478bd9Sstevel@tonic-gate };
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate /*
10917c478bd9Sstevel@tonic-gate  * generic log page struct
10927c478bd9Sstevel@tonic-gate  */
10937c478bd9Sstevel@tonic-gate struct log_page {
10947c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
10957c478bd9Sstevel@tonic-gate 	uchar_t	code	:6,	/* page code number */
10967c478bd9Sstevel@tonic-gate 			:2;	/* reserved */
10977c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
10987c478bd9Sstevel@tonic-gate 	uchar_t		:2,	/* reserved */
10997c478bd9Sstevel@tonic-gate 		code	:6;	/* page code number */
11007c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
11017c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
11027c478bd9Sstevel@tonic-gate 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
11037c478bd9Sstevel@tonic-gate 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
11047c478bd9Sstevel@tonic-gate 	/*
11057c478bd9Sstevel@tonic-gate 	 * Log parameters follow right after this...
11067c478bd9Sstevel@tonic-gate 	 */
11077c478bd9Sstevel@tonic-gate };
11087c478bd9Sstevel@tonic-gate 
11097c478bd9Sstevel@tonic-gate /*
11107c478bd9Sstevel@tonic-gate  * generic log page parameter struct
11117c478bd9Sstevel@tonic-gate  */
11127c478bd9Sstevel@tonic-gate struct log_param {
11137c478bd9Sstevel@tonic-gate 	uchar_t	pc_hi;			/* parameter code (msb) */
11147c478bd9Sstevel@tonic-gate 	uchar_t	pc_lo;			/* parameter code (lsb) */
11157c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
11167c478bd9Sstevel@tonic-gate 	uchar_t		lp	: 1,	/* list parameter */
11177c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
11187c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
11197c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
11207c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
11217c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
11227c478bd9Sstevel@tonic-gate 			du	: 1;	/* disable update */
11237c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
11247c478bd9Sstevel@tonic-gate 	uchar_t		du	: 1,	/* disable update */
11257c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
11267c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
11277c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
11287c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
11297c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
11307c478bd9Sstevel@tonic-gate 			lp	: 1;	/* list parameter */
11317c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
11327c478bd9Sstevel@tonic-gate 	uchar_t	length;		/* length of bytes to follow */
11337c478bd9Sstevel@tonic-gate 	/*
11347c478bd9Sstevel@tonic-gate 	 * Parameter values follow right after this...
11357c478bd9Sstevel@tonic-gate 	 */
11367c478bd9Sstevel@tonic-gate };
11377c478bd9Sstevel@tonic-gate /*
11387c478bd9Sstevel@tonic-gate  * TapeAlert structures
11397c478bd9Sstevel@tonic-gate  */
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate struct st_tape_alert_parameter {
11427c478bd9Sstevel@tonic-gate 	struct log_param log_param;
11437c478bd9Sstevel@tonic-gate 	uchar_t	param_value;
11447c478bd9Sstevel@tonic-gate };
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate struct st_tape_alert {
11477c478bd9Sstevel@tonic-gate 	struct log_page log_page;
11487c478bd9Sstevel@tonic-gate 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
11497c478bd9Sstevel@tonic-gate };
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PARAMETER_LENGTH \
11527c478bd9Sstevel@tonic-gate 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate struct log_sequential_page_parameter {
11557c478bd9Sstevel@tonic-gate 	struct log_param log_param;
11567c478bd9Sstevel@tonic-gate 	uchar_t param_value[8];
11577c478bd9Sstevel@tonic-gate };
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate struct log_sequential_page {
11607c478bd9Sstevel@tonic-gate 	struct log_page log_page;
11617c478bd9Sstevel@tonic-gate 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
11627c478bd9Sstevel@tonic-gate };
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate #if !defined(__lint)
11657c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
11667c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
11677c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
11687c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
11694ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
11707c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
11717c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
11727c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("save sharing",
11737c478bd9Sstevel@tonic-gate 	scsi_tape::un_allow_large_xfer
11747c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxbsize
11757c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxdma
11767c478bd9Sstevel@tonic-gate ))
117736945f79Smrj #ifdef	__x86
11784ebb14b2Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
11794ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
11804ebb14b2Sfrits #endif
11817c478bd9Sstevel@tonic-gate #endif
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate /*
11857c478bd9Sstevel@tonic-gate  * Power management state
11867c478bd9Sstevel@tonic-gate  */
11877c478bd9Sstevel@tonic-gate #define	ST_PWR_NORMAL				0
11887c478bd9Sstevel@tonic-gate #define	ST_PWR_SUSPENDED			1
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 
1191c6914c10Srralphs #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate /* un_rqs_state codes */
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
11967c478bd9Sstevel@tonic-gate #define	ST_RQS_VALID		0x2	/* RQS data is valid */
11977c478bd9Sstevel@tonic-gate #define	ST_RQS_READ		0x4	/* RQS data was read */
11987c478bd9Sstevel@tonic-gate #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate /*
1201f218e94bSrralphs  * st_intr codes
12027c478bd9Sstevel@tonic-gate  */
1203f218e94bSrralphs typedef enum {
1204f218e94bSrralphs 	COMMAND_DONE,
1205f218e94bSrralphs 	COMMAND_DONE_ERROR,
1206f218e94bSrralphs 	COMMAND_DONE_ERROR_RECOVERED,
1207f218e94bSrralphs 	QUE_COMMAND,
1208f218e94bSrralphs 	QUE_BUSY_COMMAND,
1209f218e94bSrralphs 	QUE_SENSE,
1210f218e94bSrralphs 	JUST_RETURN,
1211f218e94bSrralphs 	COMMAND_DONE_EACCES,
1212f218e94bSrralphs 	QUE_LAST_COMMAND,
1213f218e94bSrralphs 	COMMAND_TIMEOUT,
1214f218e94bSrralphs 	PATH_FAILED,
1215f218e94bSrralphs 	DEVICE_RESET,
1216f218e94bSrralphs 	DEVICE_TAMPER,
1217f218e94bSrralphs 	ATTEMPT_RETRY
1218f218e94bSrralphs }errstate;
1219f218e94bSrralphs #ifdef _KERNEL
1220f218e94bSrralphs typedef struct {
1221602ca9eaScth 	struct scsi_arq_status	ei_failing_status;
1222602ca9eaScth 	tapepos_t		ei_expected_pos;
1223602ca9eaScth 	errstate		ei_error_type;
1224602ca9eaScth 	buf_t			*ei_failing_bp;
1225602ca9eaScth 	struct scsi_pkt		ei_failed_pkt;		/* must be last */
1226602ca9eaScth 							/* ...scsi_pkt_size() */
1227f218e94bSrralphs } st_err_info;
1228602ca9eaScth #define	ST_ERR_INFO_SIZE	(sizeof (st_err_info) - \
1229602ca9eaScth 				sizeof (struct scsi_pkt) + scsi_pkt_size())
1230f218e94bSrralphs #endif
12317c478bd9Sstevel@tonic-gate 
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate /*
12347c478bd9Sstevel@tonic-gate  *	Reservation Status
12357c478bd9Sstevel@tonic-gate  *
12367c478bd9Sstevel@tonic-gate  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
12377c478bd9Sstevel@tonic-gate  *		         in between opens and also to indicate the reservation
12387c478bd9Sstevel@tonic-gate  *		         has not been done till now.
12397c478bd9Sstevel@tonic-gate  * ST_RELEASE	        -Tape Unit is Released.
12407c478bd9Sstevel@tonic-gate  * ST_RESERVE	        -Tape Unit is Reserved.
12417c478bd9Sstevel@tonic-gate  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
12427c478bd9Sstevel@tonic-gate  *
12437c478bd9Sstevel@tonic-gate  */
12447c478bd9Sstevel@tonic-gate #define	ST_INIT_RESERVE			0x001
12457c478bd9Sstevel@tonic-gate #define	ST_RELEASE			0x002
12467c478bd9Sstevel@tonic-gate #define	ST_RESERVE			0x004
12477c478bd9Sstevel@tonic-gate #define	ST_PRESERVE_RESERVE		0x008
12487c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_CONFLICT 	0x010
12497c478bd9Sstevel@tonic-gate #define	ST_LOST_RESERVE			0x020
1250e213afc3Srralphs #define	ST_APPLICATION_RESERVATIONS	0x040
1251f218e94bSrralphs #define	ST_INITIATED_RESET		0x080
1252e213afc3Srralphs #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
1253e213afc3Srralphs 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
12547c478bd9Sstevel@tonic-gate 
1255e213afc3Srralphs /*
1256e213afc3Srralphs  * Service action defines for Persistant Reservation Commands
1257e213afc3Srralphs  */
1258e213afc3Srralphs #define	ST_SA_SCSI3_REGISTER			0x00
1259e213afc3Srralphs #define	ST_SA_SCSI3_RESERVE			0x01
1260e213afc3Srralphs #define	ST_SA_SCSI3_RELEASE			0x02
1261e213afc3Srralphs #define	ST_SA_SCSI3_CLEAR			0x03
1262e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPT			0x04
1263e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
1264e213afc3Srralphs #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
1265e213afc3Srralphs #define	ST_SA_MASK				0x1f
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_DELAY		500000
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate /*
12707c478bd9Sstevel@tonic-gate  * Asynch I/O tunables
12717c478bd9Sstevel@tonic-gate  */
12727c478bd9Sstevel@tonic-gate #define	ST_MAX_THROTTLE		4
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate /*
12757c478bd9Sstevel@tonic-gate  * 60 minutes seems a reasonable amount of time
12767c478bd9Sstevel@tonic-gate  * to wait for tape space operations to complete.
12777c478bd9Sstevel@tonic-gate  *
12787c478bd9Sstevel@tonic-gate  */
12797c478bd9Sstevel@tonic-gate #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
12807c478bd9Sstevel@tonic-gate #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate /*
12837c478bd9Sstevel@tonic-gate  * 2 minutes seems a reasonable amount of time
12847c478bd9Sstevel@tonic-gate  * to wait for tape i/o operations to complete.
12857c478bd9Sstevel@tonic-gate  *
12867c478bd9Sstevel@tonic-gate  */
12877c478bd9Sstevel@tonic-gate #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
12887c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate /*
12927c478bd9Sstevel@tonic-gate  * 10 seconds is what we'll wait if we get a Busy Status back
12937c478bd9Sstevel@tonic-gate  */
12947c478bd9Sstevel@tonic-gate #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
12950205780bSrralphs #define	ST_TRAN_BUSY_TIMEOUT	4*hz	/* seconds retry on TRAN_BSY */
12967c478bd9Sstevel@tonic-gate #define	ST_INTERRUPT_CONTEXT	1
12977c478bd9Sstevel@tonic-gate #define	ST_START_CONTEXT	2
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate /*
13007c478bd9Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
13017c478bd9Sstevel@tonic-gate  *
13027c478bd9Sstevel@tonic-gate  * XXX This includes retries due to transport failure as well as
13037c478bd9Sstevel@tonic-gate  * XXX busy timeouts- Need to distinguish between Target and Transport
13047c478bd9Sstevel@tonic-gate  * XXX failure.
13057c478bd9Sstevel@tonic-gate  */
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate #define	ST_RETRY_COUNT		20
13087c478bd9Sstevel@tonic-gate 
13097c478bd9Sstevel@tonic-gate /*
13107c478bd9Sstevel@tonic-gate  * Number of times to retry a failed selection
13117c478bd9Sstevel@tonic-gate  */
13127c478bd9Sstevel@tonic-gate #define	ST_SEL_RETRY_COUNT		2
13137c478bd9Sstevel@tonic-gate 
13147c478bd9Sstevel@tonic-gate /*
13157c478bd9Sstevel@tonic-gate  * es_code value for deferred error
13167c478bd9Sstevel@tonic-gate  * should be moved to sense.h
13177c478bd9Sstevel@tonic-gate  */
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate #define	ST_DEFERRED_ERROR		0x01
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate /*
13227c478bd9Sstevel@tonic-gate  * Maximum number of units (determined by minor device byte)
13237c478bd9Sstevel@tonic-gate  */
13247c478bd9Sstevel@tonic-gate #define	ST_MAXUNIT	128
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate /*
13277c478bd9Sstevel@tonic-gate  * Time to wait for completion of a command before cancelling it.
13287c478bd9Sstevel@tonic-gate  * For SUSPEND use only
13297c478bd9Sstevel@tonic-gate  */
13307c478bd9Sstevel@tonic-gate #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate #ifndef	SECSIZE
13337c478bd9Sstevel@tonic-gate #define	SECSIZE	512
13347c478bd9Sstevel@tonic-gate #endif
13357c478bd9Sstevel@tonic-gate #ifndef	SECDIV
13367c478bd9Sstevel@tonic-gate #define	SECDIV	9
13377c478bd9Sstevel@tonic-gate #endif
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate /*
13407c478bd9Sstevel@tonic-gate  * convenient defines
13417c478bd9Sstevel@tonic-gate  */
1342f218e94bSrralphs #define	ST_SCSI_DEVP		(un->un_sd)
13437c478bd9Sstevel@tonic-gate #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
13447c478bd9Sstevel@tonic-gate #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
13457c478bd9Sstevel@tonic-gate #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
13467c478bd9Sstevel@tonic-gate #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
13477c478bd9Sstevel@tonic-gate #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
13507c478bd9Sstevel@tonic-gate #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
13510205780bSrralphs #define	ST_STATUS_MASK	(STATUS_MASK | STATUS_TASK_ABORT)
13527c478bd9Sstevel@tonic-gate #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
13530205780bSrralphs #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & ST_STATUS_MASK)
13547c478bd9Sstevel@tonic-gate #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
13557c478bd9Sstevel@tonic-gate #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
13567c478bd9Sstevel@tonic-gate #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
13577c478bd9Sstevel@tonic-gate #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
13587c478bd9Sstevel@tonic-gate #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
13597c478bd9Sstevel@tonic-gate 
13607c478bd9Sstevel@tonic-gate #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
13617c478bd9Sstevel@tonic-gate 	((un)->un_state == ST_STATE_SENSING && \
13627c478bd9Sstevel@tonic-gate 		(un)->un_laststate == ST_STATE_CLOSING))
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate #define	ASYNC_CMD	0
13657c478bd9Sstevel@tonic-gate #define	SYNC_CMD	1
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate #define	st_bioerror(bp, error) \
13687c478bd9Sstevel@tonic-gate 		{ bioerror(bp, error); \
13697c478bd9Sstevel@tonic-gate 		un->un_errno = error; }
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate /*
13727c478bd9Sstevel@tonic-gate  * Macros for internal coding of count for SPACE command:
13737c478bd9Sstevel@tonic-gate  *
1374f218e94bSrralphs  * Top 3 bits of b_bcount define direction and type of space.
1375f218e94bSrralphs  * Since b_bcount (size_t) is 32 bits on 32 platforms and 64 bits on
1376f218e94bSrralphs  * 64 bit platforms different defines are used.
1377f218e94bSrralphs  * if SP_BACKSP is set direction is backward (toward BOP)
1378f218e94bSrralphs  * The type of space (Blocks, Filemark or sequential filemarks) is
1379f218e94bSrralphs  * carried in the next 2 bits. The remaining bits a signed count of
1380f218e94bSrralphs  * how many of that direction and type to do.
13817c478bd9Sstevel@tonic-gate  */
13820205780bSrralphs 
13830205780bSrralphs #if (defined(__lock_lint))
13840205780bSrralphs /*
13850205780bSrralphs  * This is a workaround for warlock not being able to parse an #ULL constant.
13860205780bSrralphs  */
13870205780bSrralphs #undef	UINT64_MAX
13880205780bSrralphs #define	UINT64_MAX	(18446744073709551615UL)
13890205780bSrralphs #endif /* __lock_lint */
13900205780bSrralphs 
13910205780bSrralphs #if (defined(__lock_lint) || (SIZE_MAX < UINT64_MAX))
1392f218e94bSrralphs 
1393f218e94bSrralphs #define	SP_BLK		UINT32_C(0x00000000)
1394f218e94bSrralphs #define	SP_FLM		UINT32_C(0x20000000)
1395f218e94bSrralphs #define	SP_SQFLM	UINT32_C(0x40000000)
1396f218e94bSrralphs #define	SP_EOD		UINT32_C(0x60000000)
1397f218e94bSrralphs #define	SP_BACKSP	UINT32_C(0x80000000)
1398f218e94bSrralphs #define	SP_CMD_MASK	UINT32_C(0x60000000)
1399f218e94bSrralphs #define	SP_CNT_MASK	UINT32_C(0x1fffffff)
1400f218e94bSrralphs 
1401f218e94bSrralphs /* Macros to interpret space cmds */
1402f218e94bSrralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1403f218e94bSrralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1404f218e94bSrralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>29)
1405f218e94bSrralphs 
1406f218e94bSrralphs #else /* end of small size_t in buf_t */
1407f218e94bSrralphs 
1408f218e94bSrralphs #define	SP_BLK		UINT64_C(0x0000000000000000)
1409f218e94bSrralphs #define	SP_FLM		UINT64_C(0x2000000000000000)
1410f218e94bSrralphs #define	SP_SQFLM	UINT64_C(0x4000000000000000)
1411f218e94bSrralphs #define	SP_EOD		UINT64_C(0x6000000000000000)
1412f218e94bSrralphs #define	SP_BACKSP	UINT64_C(0x8000000000000000)
1413f218e94bSrralphs #define	SP_CMD_MASK	UINT64_C(0x6000000000000000)
1414f218e94bSrralphs #define	SP_CNT_MASK	UINT64_C(0x1fffffffffffffff)
1415f218e94bSrralphs 
1416f218e94bSrralphs /* Macros to interpret space cmds */
1417f218e94bSrralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1418f218e94bSrralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1419f218e94bSrralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>61)
1420f218e94bSrralphs 
1421f218e94bSrralphs #endif /* end of big size_t in buf_t */
1422c6914c10Srralphs 
1423c6914c10Srralphs /* Macros to assemble space cmds */
1424c6914c10Srralphs #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
1425c6914c10Srralphs #define	Fmk(x)		SPACE(SP_FLM, x)
1426c6914c10Srralphs #define	Blk(x)		SPACE(SP_BLK, x)
1427c6914c10Srralphs 
1428c6914c10Srralphs 
1429c6914c10Srralphs 
1430c6914c10Srralphs /* Defines for byte 4 of load/unload cmd */
1431c6914c10Srralphs #define	LD_UNLOAD	0
1432c6914c10Srralphs #define	LD_LOAD		1
1433c6914c10Srralphs #define	LD_RETEN	2
1434c6914c10Srralphs #define	LD_EOT		4
1435c6914c10Srralphs #define	LD_HOLD		8
1436c6914c10Srralphs 
1437c6914c10Srralphs /* Defines for byte 4 of prevent/allow media removal */
1438c6914c10Srralphs #define	MR_UNLOCK	0
1439c6914c10Srralphs #define	MR_LOCK		1
14407c478bd9Sstevel@tonic-gate 
14417c478bd9Sstevel@tonic-gate #define	GET_SOFT_STATE(dev)						\
14427c478bd9Sstevel@tonic-gate 	register struct scsi_tape *un;					\
14437c478bd9Sstevel@tonic-gate 	register int instance;						\
14447c478bd9Sstevel@tonic-gate 									\
14457c478bd9Sstevel@tonic-gate 	instance = MTUNIT(dev);						\
14467c478bd9Sstevel@tonic-gate 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
14477c478bd9Sstevel@tonic-gate 		return (ENXIO);
14487c478bd9Sstevel@tonic-gate 
14497c478bd9Sstevel@tonic-gate /*
14507c478bd9Sstevel@tonic-gate  * Debugging turned on via conditional compilation switch -DSTDEBUG
14517c478bd9Sstevel@tonic-gate  */
14527c478bd9Sstevel@tonic-gate #ifdef DEBUG
14537c478bd9Sstevel@tonic-gate #define	STDEBUG
14547c478bd9Sstevel@tonic-gate #endif
14557c478bd9Sstevel@tonic-gate 
14567c478bd9Sstevel@tonic-gate #ifdef	STDEBUG
1457f218e94bSrralphs #define	DEBUGGING\
1458f218e94bSrralphs 	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0x7))
14597c478bd9Sstevel@tonic-gate 
14600205780bSrralphs #define	DEBLOCK(d) int lev = CE_NOTE; mutex_enter(&st_debug_mutex); \
14610205780bSrralphs     if (d == st_lastdev || d == 0) lev = CE_CONT; mutex_exit(&st_debug_mutex);
14620205780bSrralphs 
14630205780bSrralphs #define	DEBUNLOCK(d) mutex_enter(&st_debug_mutex); \
14640205780bSrralphs     if (d != 0 && d != st_lastdev) st_lastdev = d; mutex_exit(&st_debug_mutex);
1465c6914c10Srralphs 
1466c6914c10Srralphs 	/* initialization */
1467f218e94bSrralphs #define	ST_DEBUG1	if ((st_debug & 0x7) >= 1) scsi_log
14687c478bd9Sstevel@tonic-gate #define	ST_DEBUG	ST_DEBUG1
14697c478bd9Sstevel@tonic-gate 
1470c6914c10Srralphs 	/* errors and UA's */
1471f218e94bSrralphs #define	ST_DEBUG2	if ((st_debug & 0x7) >= 2) scsi_log
1472c6914c10Srralphs 
1473c6914c10Srralphs 	/* func calls */
1474f218e94bSrralphs #define	ST_DEBUG3	if ((st_debug & 0x7) >= 3) scsi_log
1475c6914c10Srralphs 
1476c6914c10Srralphs 	/* ioctl calls */
1477f218e94bSrralphs #define	ST_DEBUG4	if ((st_debug & 0x7) >= 4) scsi_log
14787c478bd9Sstevel@tonic-gate 
1479f218e94bSrralphs #define	ST_DEBUG5	if ((st_debug & 0x7) >= 5) scsi_log
1480c6914c10Srralphs 
1481c6914c10Srralphs 	/* full data tracking */
1482f218e94bSrralphs #define	ST_DEBUG6	if ((st_debug & 0x7) >= 6) scsi_log
1483c6914c10Srralphs 
1484f218e94bSrralphs 	/* debug error recovery */
1485f218e94bSrralphs #define	ST_RECOV	if (st_debug & 0x8) scsi_log
1486c6914c10Srralphs 
1487c6914c10Srralphs 	/* Entry Point Functions */
14880205780bSrralphs #define	ST_ENTR(d, fn) if (st_debug & 0x10) { DEBLOCK(d) \
14890205780bSrralphs     scsi_log(d, st_label, lev, #fn); DEBUNLOCK(d) }
1490c6914c10Srralphs 
1491c6914c10Srralphs 	/* Non-Entry Point Functions */
14920205780bSrralphs #define	ST_FUNC(d, fn) if (st_debug & 0x20) { DEBLOCK(d) \
14930205780bSrralphs     scsi_log(d, st_label, lev, #fn); DEBUNLOCK(d) }
1494c6914c10Srralphs 
1495c6914c10Srralphs 	/* Space Information */
1496c6914c10Srralphs #define	ST_SPAC		if (st_debug & 0x40) scsi_log
1497c6914c10Srralphs 
1498c6914c10Srralphs 	/* CDB's sent */
14990205780bSrralphs #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) { DEBLOCK(d) \
15000205780bSrralphs     st_print_cdb(d, st_label, lev, cmnt, cdb); DEBUNLOCK(d) }
15010205780bSrralphs 
1502f218e94bSrralphs 	/* sense data */
15030205780bSrralphs #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) { DEBLOCK(d) \
15040205780bSrralphs     st_clean_print(d, st_label, lev, cmnt, sense, size); DEBUNLOCK(d) }
15050205780bSrralphs 
1506f218e94bSrralphs 	/* position data */
15070205780bSrralphs #define	ST_POS(d, cmnt, pdata) if (st_debug & 0x400) { DEBLOCK(d) \
15080205780bSrralphs     st_print_position(d, st_label, lev, cmnt, pdata); DEBUNLOCK(d) }
1509f218e94bSrralphs 
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate #else
15127c478bd9Sstevel@tonic-gate 
15137c478bd9Sstevel@tonic-gate #define	st_debug	(0)
15147c478bd9Sstevel@tonic-gate #define	DEBUGGING	(0)
15157c478bd9Sstevel@tonic-gate #define	ST_DEBUG	if (0) scsi_log
15167c478bd9Sstevel@tonic-gate #define	ST_DEBUG1	if (0) scsi_log
15177c478bd9Sstevel@tonic-gate #define	ST_DEBUG2	if (0) scsi_log
15187c478bd9Sstevel@tonic-gate #define	ST_DEBUG3	if (0) scsi_log
15197c478bd9Sstevel@tonic-gate #define	ST_DEBUG4	if (0) scsi_log
15207c478bd9Sstevel@tonic-gate #define	ST_DEBUG5	if (0) scsi_log
15217c478bd9Sstevel@tonic-gate #define	ST_DEBUG6	if (0) scsi_log
1522f218e94bSrralphs #define	ST_RECOV	if (0) scsi_log
15237c478bd9Sstevel@tonic-gate 
1524c6914c10Srralphs #define	ST_ENTR(d, fn)
1525c6914c10Srralphs #define	ST_FUNC(d, fn)
1526c6914c10Srralphs #define	ST_SPAC		if (0) scsi_log
1527c6914c10Srralphs #define	ST_CDB(d, cmnt, cdb)
1528c6914c10Srralphs #define	ST_SENSE(d, cmnt, sense, size)
1529f218e94bSrralphs #define	ST_SENSE(d, cmnt, sense, size)
1530f218e94bSrralphs #define	ST_POS(d, cmnt, pdata)
1531c6914c10Srralphs 
15327c478bd9Sstevel@tonic-gate #endif
15337c478bd9Sstevel@tonic-gate 
15347c478bd9Sstevel@tonic-gate /*
15357c478bd9Sstevel@tonic-gate  * Media access values
15367c478bd9Sstevel@tonic-gate  */
15377c478bd9Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
15387c478bd9Sstevel@tonic-gate 
15397c478bd9Sstevel@tonic-gate /*
15407c478bd9Sstevel@tonic-gate  * SCSI tape mode sense page information
15417c478bd9Sstevel@tonic-gate  */
15427c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
15437c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
15447c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
15457c478bd9Sstevel@tonic-gate #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
15467c478bd9Sstevel@tonic-gate 
15477c478bd9Sstevel@tonic-gate /*
15487c478bd9Sstevel@tonic-gate  * SCSI tape data compression Page definition.
15497c478bd9Sstevel@tonic-gate  */
15507c478bd9Sstevel@tonic-gate #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
15517c478bd9Sstevel@tonic-gate 
15527c478bd9Sstevel@tonic-gate 
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate /*
15557c478bd9Sstevel@tonic-gate  * maxbsize values
15567c478bd9Sstevel@tonic-gate  */
15577c478bd9Sstevel@tonic-gate #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
15587c478bd9Sstevel@tonic-gate 
15597c478bd9Sstevel@tonic-gate #define	ONE_MEG			(1024 * 1024)
15607c478bd9Sstevel@tonic-gate 
15617c478bd9Sstevel@tonic-gate /*
15627c478bd9Sstevel@tonic-gate  * generic soft error reporting
15637c478bd9Sstevel@tonic-gate  *
15647c478bd9Sstevel@tonic-gate  * What we are doing here is allowing a greater number of errors to occur on
15657c478bd9Sstevel@tonic-gate  * smaller transfers (i.e. usually at the beginning of the tape), than on
15667c478bd9Sstevel@tonic-gate  * the rest of the tape.
15677c478bd9Sstevel@tonic-gate  *
15687c478bd9Sstevel@tonic-gate  * A small transfer is defined as :
15697c478bd9Sstevel@tonic-gate  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
15707c478bd9Sstevel@tonic-gate  *
15717c478bd9Sstevel@tonic-gate  * A larget tranfer is defined as :
15727c478bd9Sstevel@tonic-gate  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
15737c478bd9Sstevel@tonic-gate  *
15747c478bd9Sstevel@tonic-gate  */
15757c478bd9Sstevel@tonic-gate #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
15767c478bd9Sstevel@tonic-gate #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
15777c478bd9Sstevel@tonic-gate 
15787c478bd9Sstevel@tonic-gate /*
15797c478bd9Sstevel@tonic-gate  * soft error reporting for exabyte
15807c478bd9Sstevel@tonic-gate  */
15817c478bd9Sstevel@tonic-gate #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
15827c478bd9Sstevel@tonic-gate 
15837c478bd9Sstevel@tonic-gate #define	SENSE_19_BITS  \
15847c478bd9Sstevel@tonic-gate 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
15857c478bd9Sstevel@tonic-gate #define	SENSE_20_BITS  \
15867c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
15877c478bd9Sstevel@tonic-gate #define	SENSE_21_BITS  \
15887c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
15897c478bd9Sstevel@tonic-gate 
15907c478bd9Sstevel@tonic-gate /* these are defined in percentages */
15917c478bd9Sstevel@tonic-gate #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
15927c478bd9Sstevel@tonic-gate #define	EXABYTE_READ_ERROR_THRESHOLD	3
15937c478bd9Sstevel@tonic-gate /*
15947c478bd9Sstevel@tonic-gate  * minumum amount of data transfer(MB) for checking soft error rate.
15957c478bd9Sstevel@tonic-gate  */
15967c478bd9Sstevel@tonic-gate #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
15977c478bd9Sstevel@tonic-gate 
15987c478bd9Sstevel@tonic-gate #define	CLN	0x8
15997c478bd9Sstevel@tonic-gate #define	CLND	0x10
16007c478bd9Sstevel@tonic-gate 
16017c478bd9Sstevel@tonic-gate /*
16027c478bd9Sstevel@tonic-gate  * soft error reporting for Archive 4mm DAT
16037c478bd9Sstevel@tonic-gate  */
16047c478bd9Sstevel@tonic-gate 
16057c478bd9Sstevel@tonic-gate #define	LOG_SENSE_LENGTH		0xff
16067c478bd9Sstevel@tonic-gate #define	MIN_LOG_SENSE_LENGTH		0x2b
16077c478bd9Sstevel@tonic-gate #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
16087c478bd9Sstevel@tonic-gate #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
16097c478bd9Sstevel@tonic-gate #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
16107c478bd9Sstevel@tonic-gate #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
16117c478bd9Sstevel@tonic-gate 
16127c478bd9Sstevel@tonic-gate /*
16137c478bd9Sstevel@tonic-gate  * ST timeouts that need to be cancelled for suspend
16147c478bd9Sstevel@tonic-gate  */
16157c478bd9Sstevel@tonic-gate #define	ST_HIB_TID	0x01
16167c478bd9Sstevel@tonic-gate #define	ST_DELAY_TID	0x02
16177c478bd9Sstevel@tonic-gate 
16187c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
16197c478bd9Sstevel@tonic-gate }
16207c478bd9Sstevel@tonic-gate #endif
16217c478bd9Sstevel@tonic-gate 
16227c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1623