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*c6914c10Srralphs  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_STDEF_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_STDEF_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
31f3531714Scz #include <sys/sunddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/note.h>
337c478bd9Sstevel@tonic-gate #include <sys/condvar.h>
347c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
357c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
36*c6914c10Srralphs #include <sys/scsi/generic/sense.h>
377c478bd9Sstevel@tonic-gate #include <sys/mtio.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * Defines for SCSI tape drives.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Maximum variable length record size for a single request
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE	65535
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
547c478bd9Sstevel@tonic-gate  * then the following define is used.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
597c478bd9Sstevel@tonic-gate #define	INF 1000000000
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Supported tape device types plus default type for opening.
637c478bd9Sstevel@tonic-gate  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
647c478bd9Sstevel@tonic-gate  * Types 14 - 1f, are 1/4-inch cartridge drives.
657c478bd9Sstevel@tonic-gate  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
667c478bd9Sstevel@tonic-gate  * Types 28+, are rdat (vcr) drives.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate #define	ST_TYPE_INVALID		0x00
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
717c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
747c478bd9Sstevel@tonic-gate #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
757c478bd9Sstevel@tonic-gate #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
767c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
797c478bd9Sstevel@tonic-gate #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
807c478bd9Sstevel@tonic-gate #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
817c478bd9Sstevel@tonic-gate #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
827c478bd9Sstevel@tonic-gate #define	ST_TYPE_HP	MT_ISHP		/* HP */
837c478bd9Sstevel@tonic-gate #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
847c478bd9Sstevel@tonic-gate #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
857c478bd9Sstevel@tonic-gate #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
887c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
897c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
907c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
917c478bd9Sstevel@tonic-gate #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
927c478bd9Sstevel@tonic-gate #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
937c478bd9Sstevel@tonic-gate #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
947c478bd9Sstevel@tonic-gate #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
957c478bd9Sstevel@tonic-gate #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
967c478bd9Sstevel@tonic-gate #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
977c478bd9Sstevel@tonic-gate #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
985988135dSrralphs #define	ST_TYPE_AIT	MT_ISAIT	/* Sony AIT I, II, III and SAIT */
995988135dSrralphs #define	ST_LAST_TYPE	ST_TYPE_AIT	/* Add new above type and change this */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* Internal flags */
1037c478bd9Sstevel@tonic-gate #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
1047c478bd9Sstevel@tonic-gate 					/* alloc'ed from the st.conf entry, */
1057c478bd9Sstevel@tonic-gate 					/* instead of being used from the */
1067c478bd9Sstevel@tonic-gate 					/* st_drivetypes array. */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Defines for supported drive options
1107c478bd9Sstevel@tonic-gate  *
1117c478bd9Sstevel@tonic-gate  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
1127c478bd9Sstevel@tonic-gate  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate #define	ST_VARIABLE		0x001	/* Device supports variable	*/
1157c478bd9Sstevel@tonic-gate 					/* length record sizes		*/
1167c478bd9Sstevel@tonic-gate #define	ST_QIC			0x002	/* QIC tape device 		*/
1177c478bd9Sstevel@tonic-gate #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
1187c478bd9Sstevel@tonic-gate #define	ST_BSF			0x008	/* Device supports backspace	*/
1197c478bd9Sstevel@tonic-gate 					/* file as in mt(1) bsf : 	*/
1207c478bd9Sstevel@tonic-gate 					/* backspace over EOF marks.	*/
1217c478bd9Sstevel@tonic-gate 					/* Devices not supporting bsf 	*/
1227c478bd9Sstevel@tonic-gate 					/* will fail with ENOTTY upon	*/
1237c478bd9Sstevel@tonic-gate 					/* use of bsf			*/
1247c478bd9Sstevel@tonic-gate #define	ST_BSR			0x010	/* Device supports backspace	*/
1257c478bd9Sstevel@tonic-gate 					/* record as in mt(1) bsr :	*/
1267c478bd9Sstevel@tonic-gate 					/* backspace over records. If	*/
1277c478bd9Sstevel@tonic-gate 					/* the device does not support 	*/
1287c478bd9Sstevel@tonic-gate 					/* bsr, the st driver emulates	*/
1297c478bd9Sstevel@tonic-gate 					/* the action by rewinding the	*/
1307c478bd9Sstevel@tonic-gate 					/* tape and using forward space	*/
1317c478bd9Sstevel@tonic-gate 					/* file (fsf) to the correct	*/
1327c478bd9Sstevel@tonic-gate 					/* file and then uses forward	*/
1337c478bd9Sstevel@tonic-gate 					/* space record (fsr) to the	*/
1347c478bd9Sstevel@tonic-gate 					/* correct  record		*/
1357c478bd9Sstevel@tonic-gate #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
1367c478bd9Sstevel@tonic-gate 					/* than normal to erase		*/
1377c478bd9Sstevel@tonic-gate #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
1387c478bd9Sstevel@tonic-gate 					/* Device can figure out the	*/
1397c478bd9Sstevel@tonic-gate 					/* tape density automatically,	*/
1407c478bd9Sstevel@tonic-gate 					/* without issuing a		*/
1417c478bd9Sstevel@tonic-gate 					/* mode-select/mode-sense 	*/
1427c478bd9Sstevel@tonic-gate #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
1437c478bd9Sstevel@tonic-gate 					/* This disables the device's	*/
1447c478bd9Sstevel@tonic-gate 					/* ability for buffered	writes	*/
1457c478bd9Sstevel@tonic-gate 					/* I.e. The device acknowledges	*/
1467c478bd9Sstevel@tonic-gate 					/* write completion after the	*/
1477c478bd9Sstevel@tonic-gate 					/* data is written to the	*/
1487c478bd9Sstevel@tonic-gate 					/* device's buffer, but before	*/
1497c478bd9Sstevel@tonic-gate 					/* all the data is actually	*/
1507c478bd9Sstevel@tonic-gate 					/* written to tape		*/
1517c478bd9Sstevel@tonic-gate #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
1527c478bd9Sstevel@tonic-gate 					/* parity while talking to it. 	*/
1537c478bd9Sstevel@tonic-gate #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
1547c478bd9Sstevel@tonic-gate 					/* of Data) has been reached.	*/
1557c478bd9Sstevel@tonic-gate 					/* If the device knows EOD, st	*/
1567c478bd9Sstevel@tonic-gate 					/* uses fast file skipping.	*/
1577c478bd9Sstevel@tonic-gate 					/* If it does not know EOD,	*/
1587c478bd9Sstevel@tonic-gate 					/* file skipping happens one	*/
1597c478bd9Sstevel@tonic-gate 					/* file at a time. 		*/
1607c478bd9Sstevel@tonic-gate #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
1617c478bd9Sstevel@tonic-gate 					/* the st driver is unloaded &	*/
1627c478bd9Sstevel@tonic-gate 					/* loaded again; e.g. will	*/
1637c478bd9Sstevel@tonic-gate 					/* return the correct inquiry	*/
1647c478bd9Sstevel@tonic-gate 					/* string			*/
1657c478bd9Sstevel@tonic-gate #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
1667c478bd9Sstevel@tonic-gate 					/* close to report soft errors.	*/
1677c478bd9Sstevel@tonic-gate 					/* Currently only Exabyte and	*/
1687c478bd9Sstevel@tonic-gate 					/* DAT drives support this	*/
1697c478bd9Sstevel@tonic-gate 					/* feature.  			*/
1707c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
1717c478bd9Sstevel@tonic-gate 					/* timeouts for normal		*/
1727c478bd9Sstevel@tonic-gate 					/* operation			*/
1737c478bd9Sstevel@tonic-gate #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
1747c478bd9Sstevel@tonic-gate 					/* driver and pre-acked to the	*/
1757c478bd9Sstevel@tonic-gate 					/* application 			*/
1767c478bd9Sstevel@tonic-gate #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
1777c478bd9Sstevel@tonic-gate 					/* devices only. If flag is	*/
1787c478bd9Sstevel@tonic-gate 					/* set, then don't limit	*/
1797c478bd9Sstevel@tonic-gate 					/* record size to 64k as in	*/
1807c478bd9Sstevel@tonic-gate 					/* pre-Solaris 2.4 releases.	*/
1817c478bd9Sstevel@tonic-gate 					/* The only limit on the	*/
1827c478bd9Sstevel@tonic-gate 					/* record size will be the max	*/
1837c478bd9Sstevel@tonic-gate 					/* record size the device can	*/
1847c478bd9Sstevel@tonic-gate 					/* handle or the max DMA	*/
1857c478bd9Sstevel@tonic-gate 					/* transfer size of the		*/
1867c478bd9Sstevel@tonic-gate 					/* machine, which ever is	*/
1877c478bd9Sstevel@tonic-gate 					/* smaller. Beware of		*/
1887c478bd9Sstevel@tonic-gate 					/* incompatabilities with	*/
1897c478bd9Sstevel@tonic-gate 					/* tapes of pre-Solaris 2.4	*/
1907c478bd9Sstevel@tonic-gate 					/* OS's written with large	*/
1917c478bd9Sstevel@tonic-gate 					/* (>64k) block sizes, as	*/
1927c478bd9Sstevel@tonic-gate 					/* their true block size is	*/
1937c478bd9Sstevel@tonic-gate 					/* a max of approx 64k		*/
1947c478bd9Sstevel@tonic-gate #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
1957c478bd9Sstevel@tonic-gate 					/* configuration page (0x10) to */
1967c478bd9Sstevel@tonic-gate 					/* enable/disable compression	*/
1977c478bd9Sstevel@tonic-gate 					/* instead of density codes for */
1987c478bd9Sstevel@tonic-gate 					/* the "c" and "u" devices	*/
1997c478bd9Sstevel@tonic-gate #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
2007c478bd9Sstevel@tonic-gate 					/* support RESERVE/RELEASE SCSI	*/
2017c478bd9Sstevel@tonic-gate 					/* command. If this is enabled	*/
2027c478bd9Sstevel@tonic-gate 					/* then reserve/release would	*/
2037c478bd9Sstevel@tonic-gate 					/* not be used during open/	*/
2047c478bd9Sstevel@tonic-gate 					/* close for High Availability	*/
2057c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
2067c478bd9Sstevel@tonic-gate 					/* to variable block devices 	*/
2077c478bd9Sstevel@tonic-gate 					/* which support the SILI bit	*/
2087c478bd9Sstevel@tonic-gate 					/* option. It indicates that 	*/
2097c478bd9Sstevel@tonic-gate 					/* the SILI bit will be ignored */
2107c478bd9Sstevel@tonic-gate 					/* during reads  		*/
2117c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
2127c478bd9Sstevel@tonic-gate 					/* EOF marks do not indicate an */
2137c478bd9Sstevel@tonic-gate 					/* EOM. This option is only	*/
2147c478bd9Sstevel@tonic-gate 					/* supported on 1/2" reel tapes */
2157c478bd9Sstevel@tonic-gate #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
2167c478bd9Sstevel@tonic-gate 					/* EXABYTE 8mm tape drives 	*/
2177c478bd9Sstevel@tonic-gate 					/* which support short 		*/
2187c478bd9Sstevel@tonic-gate 					/* filemarks. When this flag 	*/
2197c478bd9Sstevel@tonic-gate 					/* is set, short filemarks 	*/
2207c478bd9Sstevel@tonic-gate 					/* will be used for writing	*/
2217c478bd9Sstevel@tonic-gate 					/* filemarks. 			*/
2227c478bd9Sstevel@tonic-gate #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
2237c478bd9Sstevel@tonic-gate 					/* and the tape is trapped in   */
2247c478bd9Sstevel@tonic-gate 					/* the medium changer, the tape */
2257c478bd9Sstevel@tonic-gate 					/* is automatically ejected	*/
2267c478bd9Sstevel@tonic-gate #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
2277c478bd9Sstevel@tonic-gate 					/* This option applies only to  */
2287c478bd9Sstevel@tonic-gate 					/* IBM MAGSTAR 3590. If this    */
2297c478bd9Sstevel@tonic-gate 					/* flag is set, the st driver   */
2307c478bd9Sstevel@tonic-gate 					/* will retry the last cmd if   */
2317c478bd9Sstevel@tonic-gate 					/* the last error cause a check */
2327c478bd9Sstevel@tonic-gate 					/* condition with error code    */
2337c478bd9Sstevel@tonic-gate 					/* 0x71 and sense code  0x01 	*/
2347c478bd9Sstevel@tonic-gate #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
2357c478bd9Sstevel@tonic-gate 					/* detected to select correct   */
2367c478bd9Sstevel@tonic-gate 					/* density code.		*/
2375988135dSrralphs #define	ST_WORMABLE		0x1000000
2385988135dSrralphs 					/* Drive is capable of doing	*/
2395988135dSrralphs 					/* Write Appends only at EOM	*/
2405988135dSrralphs 					/* if WORM media type is loaded */
2417c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
2427c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2437c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2447c478bd9Sstevel@tonic-gate 					/* byte 21, bitmask 0x08 of	*/
2457c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2467c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
2477c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2487c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2497c478bd9Sstevel@tonic-gate 					/* byte 70, bitmask 0xc0 of	*/
2507c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2517c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
2527c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2537c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2547c478bd9Sstevel@tonic-gate 					/* byte 18, bitmask 0x01 of	*/
2557c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2587c478bd9Sstevel@tonic-gate #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
2597c478bd9Sstevel@tonic-gate 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
2607c478bd9Sstevel@tonic-gate 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
2617c478bd9Sstevel@tonic-gate 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
2627c478bd9Sstevel@tonic-gate 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
2637c478bd9Sstevel@tonic-gate 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
2645988135dSrralphs 	ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate #define	NDENSITIES	MT_NDENSITIES
2677c478bd9Sstevel@tonic-gate #define	NSPEEDS		MT_NSPEEDS
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  * defines for Log Sense Pages
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate #define	SUPPORTED_LOG_PAGES_PAGE	0x00
2737c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE		0x0c
2747c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PAGE			0x2e
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate  * Log Page Control definitions
2787c478bd9Sstevel@tonic-gate  */
2797c478bd9Sstevel@tonic-gate #define	CURRENT_THRESHOLD_VALUES	0x00
2807c478bd9Sstevel@tonic-gate #define	CURRENT_CUMULATIVE_VALUES	0x40
2817c478bd9Sstevel@tonic-gate #define	DEFAULT_THRESHOLD_VALUES	0x80
2827c478bd9Sstevel@tonic-gate #define	DEFAULT_CUMULATIVE_VALUES	0xC0
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate  * Tape Alert Flag definitions
2867c478bd9Sstevel@tonic-gate  */
2875988135dSrralphs typedef enum {
2885988135dSrralphs 	TAF_READ_WARN			= 0x01,
2895988135dSrralphs 	TAF_WRITE_WARN			= 0x02,
2905988135dSrralphs 	TAF_HARD_ERR			= 0x03,
2915988135dSrralphs 	TAF_MEDIA_ERR			= 0x04,
2925988135dSrralphs 	TAF_READ_FAIL			= 0x05,
2935988135dSrralphs 	TAF_WRITE_FAIL			= 0x06,
2945988135dSrralphs 	TAF_MEDIA_LIFE			= 0x07,
2955988135dSrralphs 	TAF_MEDIA_NOT_DATA_GRADE	= 0x08,
2965988135dSrralphs 	TAF_WRITE_PROTECTED		= 0x09,
2975988135dSrralphs 	TAF_NO_MEDIA_REMOVE		= 0x0A,
2985988135dSrralphs 	TAF_CLEANING_MEDIA		= 0x0B,
2995988135dSrralphs 	TAF_UNSUPPERTED_FORMAT		= 0x0C,
3005988135dSrralphs 	TAF_RECOVERED_TAPE_BREAK	= 0x0D,
3015988135dSrralphs 	TAF_TAPE_BREAK_FAUL		= 0x0E,
3025988135dSrralphs 	TAF_CART_MEM_FAIL		= 0x0F,
3035988135dSrralphs 	TAF_FORCED_EJECT		= 0x10,
3045988135dSrralphs 	TAF_READ_ONLY_FORMAT		= 0x11,
3055988135dSrralphs 	TAF_TAPE_DIR_CORRUPT		= 0x12,
3065988135dSrralphs 	TAF_NEARING_MEDIA_LIFE		= 0x13,
3075988135dSrralphs 	TAF_CLEAN_NOW			= 0x14,
3085988135dSrralphs 	TAF_CLEAN_PERIODIC		= 0x15,
3095988135dSrralphs 	TAF_EXP_CLEAN_CART		= 0x16,
3105988135dSrralphs 	TAF_INVALID_CLEAN_MEDIA		= 0x17,
3115988135dSrralphs 	TAF_RETENSION_REQUEST		= 0x18,
3125988135dSrralphs 	TAF_DUAL_PORT_INTERFACE_ERR	= 0x19,
3135988135dSrralphs 	TAF_COOLING_FAN_FAIL		= 0x1A,
3145988135dSrralphs 	TAF_POWER_SUPPLY_FAIL		= 0x1B,
3155988135dSrralphs 	TAF_POWER_CONSUMPTION		= 0x1C,
3165988135dSrralphs 	TAF_DRIVE_MAINT_REQUEST		= 0x1D,
3175988135dSrralphs 	TAF_HARDWARE_A			= 0x1E,
3185988135dSrralphs 	TAF_HARDWARE_B			= 0x1F,
3195988135dSrralphs 	TAF_INTERFACE			= 0x20,
3205988135dSrralphs 	TAF_EJECT_MEDIA			= 0x21,
3215988135dSrralphs 	TAF_DOWNLOAD_FAIL		= 0x22,
3225988135dSrralphs 	TAF_DRIVE_HUMIDITY		= 0x23,
3235988135dSrralphs 	TAF_DRIVE_TEMP			= 0x24,
3245988135dSrralphs 	TAF_DRIVE_VOLTAGE		= 0x25,
3255988135dSrralphs 	TAF_PREDICTIVE_FAIL		= 0x26,
3265988135dSrralphs 	TAF_DIAG_REQUIRED		= 0x27,
3275988135dSrralphs 	TAF_LOADER_HDWR_A		= 0x28,
3285988135dSrralphs 	TAF_LOADER_STRAY_TAPE		= 0x29,
3295988135dSrralphs 	TAF_LOADER_HDWR_B		= 0x2A,
3305988135dSrralphs 	TAF_LOADER_DOOR			= 0x2B,
3315988135dSrralphs 	TAF_LOADER_HDWR_C		= 0x2C,
3325988135dSrralphs 	TAF_LOADER_MAGAZINE		= 0x2D,
3335988135dSrralphs 	TAF_LOADER_PREDICTIVE_FAIL	= 0x2E,
3345988135dSrralphs 	TAF_LOST_STATISTICS		= 0x32,
3355988135dSrralphs 	TAF_TAPE_DIR_CURRUPT_UNLOAD	= 0x33,
3365988135dSrralphs 	TAF_TAPE_SYS_WRT_FAIL		= 0x34,
3375988135dSrralphs 	TAF_TAPE_SYS_RD_FAIL		= 0x35,
3385988135dSrralphs 	TAF_NO_START_OF_DATA		= 0x36,
3395988135dSrralphs 	TAF_WORM_INTEGRITY		= 0x3B,
3405988135dSrralphs 	TAF_WORM_OVRWRT_ATTEMPT		= 0x3C
3415988135dSrralphs }tape_alert_flags;
3425988135dSrralphs 
3435988135dSrralphs /*
3445988135dSrralphs  * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension
3455988135dSrralphs  * so they reuse TAF_RETENSION_REQUEST.
3465988135dSrralphs  */
3475988135dSrralphs #define	CLEAN_FOR_ERRORS		 0x18
3485988135dSrralphs 
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
3517c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_NOT_SUPPORTED	0x01
3527c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORTED		0x02
3537c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_STILL_DIRTY		0x04
3547c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
3557c478bd9Sstevel@tonic-gate #define	TAPE_PREVIOUSLY_DIRTY		0x10
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_MAX_PARA		64
3587c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
3597c478bd9Sstevel@tonic-gate #define	SEQUENTIAL_NEED_CLN		0x0100
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate  * Parameters
3637c478bd9Sstevel@tonic-gate  */
3647c478bd9Sstevel@tonic-gate #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
3657c478bd9Sstevel@tonic-gate #define	VIDLEN		8	/* size of vendor identifier length */
3667c478bd9Sstevel@tonic-gate #define	PIDLEN		16	/* size of product identifier length */
3677c478bd9Sstevel@tonic-gate #define	VIDPIDLEN	(VIDLEN + PIDLEN)
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate struct st_drivetype {
3717c478bd9Sstevel@tonic-gate 	char	name[ST_NAMESIZE];	/* Name, for debug */
3727c478bd9Sstevel@tonic-gate 	char	length;			/* Length of vendor id */
3737c478bd9Sstevel@tonic-gate 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
3747c478bd9Sstevel@tonic-gate 	char	type;			/* Drive type for driver */
3757c478bd9Sstevel@tonic-gate 	int	bsize;			/* Block size */
3767c478bd9Sstevel@tonic-gate 	int	options;		/* Drive options */
3777c478bd9Sstevel@tonic-gate 	int	max_rretries;		/* Max read retries */
3787c478bd9Sstevel@tonic-gate 	int	max_wretries;		/* Max write retries */
3797c478bd9Sstevel@tonic-gate 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
3807c478bd9Sstevel@tonic-gate 	uchar_t	default_density;	/* default density for this drive */
3817c478bd9Sstevel@tonic-gate 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
3827c478bd9Sstevel@tonic-gate 	ushort_t non_motion_timeout;	/* Inquiry type commands */
3837c478bd9Sstevel@tonic-gate 	ushort_t io_timeout;		/* I/O timeout in seconds */
3847c478bd9Sstevel@tonic-gate 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
3857c478bd9Sstevel@tonic-gate 	ushort_t space_timeout;		/* space cmd timeout in seconds */
3867c478bd9Sstevel@tonic-gate 	ushort_t load_timeout;		/* load tape time in seconds */
3877c478bd9Sstevel@tonic-gate 	ushort_t unload_timeout;	/* unload tape time in seconds */
3887c478bd9Sstevel@tonic-gate 	ushort_t erase_timeout;		/* erase timeout. seconds */
3897c478bd9Sstevel@tonic-gate };
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate #define	MINUTES(val)	((val) * 60)
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate struct comp_mode_page {
3947c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3957c478bd9Sstevel@tonic-gate 	uchar_t	:		6,
3967c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
3977c478bd9Sstevel@tonic-gate 		dce:		1;	/* Data Compression Enable */
3987c478bd9Sstevel@tonic-gate 	uchar_t	:		5,
3997c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4007c478bd9Sstevel@tonic-gate 		dde:		1;	/* Data Decompression Enabled */
4017c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4027c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4037c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4047c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4057c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4067c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4077c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4087c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4097c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4107c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4117c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4127c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4157c478bd9Sstevel@tonic-gate 	uchar_t	dce:		1,	/* Data Compression Enable */
4167c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
4177c478bd9Sstevel@tonic-gate 		:		6;
4187c478bd9Sstevel@tonic-gate 	uchar_t	dde:		1,	/* Data Decompression Enabled */
4197c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
4207c478bd9Sstevel@tonic-gate 		:		5;
4217c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
4227c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
4237c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
4247c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
4257c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
4267c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
4277c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
4287c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
4297c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
4307c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
4317c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
4327c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
4337c478bd9Sstevel@tonic-gate #endif
4347c478bd9Sstevel@tonic-gate };
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate struct dev_mode_page {
4377c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
4387c478bd9Sstevel@tonic-gate 	uchar_t	act_format:	5,	/* active format */
4397c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4405988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4417c478bd9Sstevel@tonic-gate 		:		1;
4427c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4437c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4447c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4457c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4467c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4477c478bd9Sstevel@tonic-gate 	uchar_t	rew:		1,	/* Report Early Warning */
4485988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4497c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4507c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4515988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4525988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4535988135dSrralphs 		obr:		1;	/* Object Buffer Recovery */
4545988135dSrralphs 	uchar_t	gap_size;		/* OBSOLETE */
4555988135dSrralphs 	uchar_t	bam:		1,	/* Block Address Mode */
4565988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4575988135dSrralphs 		swp:		1,	/* Software Write Protection */
4587c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4597c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4607c478bd9Sstevel@tonic-gate 		eod_defined:	3;
4617c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4627c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4637c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4647c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
4655988135dSrralphs 	uchar_t	prmwp:		1,	/* PeRManent Write Protect */
4665988135dSrralphs 		perswp:		1,	/* persistant write protection */
4675988135dSrralphs 		asocwp:		1,	/* associated write protect */
4685988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
4695988135dSrralphs 		oir:		1,	/* Only If Reserved */
4705988135dSrralphs 		wtre:		2;	/* Worm Tamper Read Enable */
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4737c478bd9Sstevel@tonic-gate 	uchar_t	:		1,
4745988135dSrralphs 		cap:		1,	/* Change Active Partition OBSOLETE */
4757c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4767c478bd9Sstevel@tonic-gate 		act_format:	5;	/* active format */
4777c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4787c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4797c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4807c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4817c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4825988135dSrralphs 	uchar_t	obr:		1,	/* Object Buffer Recovery */
4835988135dSrralphs 		lois:		1,	/* Logical Object Identifiers Support */
4845988135dSrralphs 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
4857c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4867c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4875988135dSrralphs 		robo:		1,	/* Reverse Object Buffer Order */
4887c478bd9Sstevel@tonic-gate 		rew:		1;	/* Report Early Warning */
4895988135dSrralphs 	uchar_t	gap_size;		/* OBSELETE */
4907c478bd9Sstevel@tonic-gate 	uchar_t	eod_defined:	3,
4917c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4927c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4935988135dSrralphs 		swp:		1,	/* Software Write Protection */
4945988135dSrralphs 		bmal:		1,	/* Block Address Mode Lock */
4955988135dSrralphs 		bam:		1;	/* Block Address Mode */
4967c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4977c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4987c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4997c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
5005988135dSrralphs 	uchar_t	wtre:		2,	/* Worm Tamper Read Enable */
5015988135dSrralphs 		oir:		1,	/* Only If Reserved */
5025988135dSrralphs 		rew_on_rst:	2,	/* rewind on reset */
5035988135dSrralphs 		asocwp:		1,	/* associated write protect */
5045988135dSrralphs 		perswp:		1,	/* persistant write protection */
5055988135dSrralphs 		prmwp:		1;	/* PeRManent Write Protect */
5067c478bd9Sstevel@tonic-gate #endif
5077c478bd9Sstevel@tonic-gate };
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate typedef union {
5107c478bd9Sstevel@tonic-gate 	struct comp_mode_page	comp;
5117c478bd9Sstevel@tonic-gate 	struct dev_mode_page	dev;
5127c478bd9Sstevel@tonic-gate }modepage;
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate  *
5167c478bd9Sstevel@tonic-gate  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
5177c478bd9Sstevel@tonic-gate  * The parameter list contains a header, followed by zero or more
5187c478bd9Sstevel@tonic-gate  * block descriptors, followed by vendor unique parameters, if any.
5197c478bd9Sstevel@tonic-gate  *
5207c478bd9Sstevel@tonic-gate  */
5217c478bd9Sstevel@tonic-gate #define	MSIZE	0x0c		/* Size without additional pages */
5227c478bd9Sstevel@tonic-gate struct seq_mode {
5237c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
5247c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5257c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5267c478bd9Sstevel@tonic-gate 	uchar_t	speed	:4,	/* speed */
5277c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5287c478bd9Sstevel@tonic-gate 		wp	:1;	/* write protected, sense only */
5297c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5307c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5317c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5327c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5337c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5347c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5357c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5367c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5377c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5387c478bd9Sstevel@tonic-gate 	uchar_t page_code:	6,
5397c478bd9Sstevel@tonic-gate 		:		1,
5407c478bd9Sstevel@tonic-gate 		ps:		1; /* Page Savable sense only */
5417c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5427c478bd9Sstevel@tonic-gate 	modepage page;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
5457c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
5467c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
5477c478bd9Sstevel@tonic-gate 	uchar_t	wp	:1,	/* write protected, sense only */
5487c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
5497c478bd9Sstevel@tonic-gate 		speed	:4;	/* speed */
5507c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
5517c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
5527c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
5537c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
5547c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
5557c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
5567c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
5577c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
5587c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
5597c478bd9Sstevel@tonic-gate 	uchar_t	ps:		1, /* Page Savable sense only */
5607c478bd9Sstevel@tonic-gate 		:		1,
5617c478bd9Sstevel@tonic-gate 		page_code:	6;
5627c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
5637c478bd9Sstevel@tonic-gate 	modepage page;
5647c478bd9Sstevel@tonic-gate #else
5657c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
5667c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
5677c478bd9Sstevel@tonic-gate };
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate /*
5707c478bd9Sstevel@tonic-gate  * Data returned from the READ BLOCK LIMITS command.
5717c478bd9Sstevel@tonic-gate  */
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate #define	RBLSIZE	(sizeof (struct read_blklim))
5747c478bd9Sstevel@tonic-gate struct read_blklim {
5757c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL)
5767c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
5777c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
5787c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_LTOH)
5797c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
5807c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
5817c478bd9Sstevel@tonic-gate #endif
5827c478bd9Sstevel@tonic-gate 	uchar_t	max_hi;			/* Maximum block length, high byte */
5837c478bd9Sstevel@tonic-gate 	uchar_t	max_mid;		/* Maximum block length, middle byte */
5847c478bd9Sstevel@tonic-gate 	uchar_t	max_lo;			/* Maximum block length, low byte */
5857c478bd9Sstevel@tonic-gate 	uchar_t	min_hi;			/* Minimum block length, high byte */
5867c478bd9Sstevel@tonic-gate 	uchar_t	min_lo;			/* Minimum block length, low byte */
5877c478bd9Sstevel@tonic-gate };
5887c478bd9Sstevel@tonic-gate 
589*c6914c10Srralphs /*
590*c6914c10Srralphs  * operation codes
591*c6914c10Srralphs  */
592*c6914c10Srralphs typedef enum {
593*c6914c10Srralphs 	ST_OP_NIL,
594*c6914c10Srralphs 	ST_OP_CTL,
595*c6914c10Srralphs 	ST_OP_READ,
596*c6914c10Srralphs 	ST_OP_WRITE,
597*c6914c10Srralphs 	ST_OP_WEOF
598*c6914c10Srralphs }optype;
599*c6914c10Srralphs 
600*c6914c10Srralphs /*
601*c6914c10Srralphs  * eof/eot/eom codes.
602*c6914c10Srralphs  */
603*c6914c10Srralphs typedef enum {
604*c6914c10Srralphs 	ST_NO_EOF,
605*c6914c10Srralphs 	ST_EOF_PENDING,		/* filemark pending */
606*c6914c10Srralphs 	ST_EOF,			/* at filemark */
607*c6914c10Srralphs 	ST_EOT_PENDING,		/* logical eot pending */
608*c6914c10Srralphs 	ST_EOT,			/* at logical eot */
609*c6914c10Srralphs 	ST_EOM,			/* at physical eot */
610*c6914c10Srralphs 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
611*c6914c10Srralphs }pstatus;
612*c6914c10Srralphs 
613*c6914c10Srralphs typedef enum { invalid, legacy, logical } posmode;
614*c6914c10Srralphs 
615*c6914c10Srralphs typedef struct tapepos {
616*c6914c10Srralphs 	uint64_t lgclblkno;
617*c6914c10Srralphs 	int32_t fileno;
618*c6914c10Srralphs 	int32_t blkno;
619*c6914c10Srralphs 	int32_t partition;
620*c6914c10Srralphs 	pstatus eof;			/* eof states */
621*c6914c10Srralphs 	posmode	pmode;
622*c6914c10Srralphs 	char	pad[4];
623*c6914c10Srralphs }tapepos_t;
624*c6914c10Srralphs 
625*c6914c10Srralphs /* byte 1 of cdb for type of read position command */
626*c6914c10Srralphs typedef enum {
627*c6914c10Srralphs 	SHORT_POS	= 0,
628*c6914c10Srralphs 	LONG_POS	= 6,
629*c6914c10Srralphs 	EXT_POS		= 8,
630*c6914c10Srralphs 	NO_POS		= 0xff	/* Drive doesn't support read position */
631*c6914c10Srralphs } read_p_types;
632*c6914c10Srralphs 
633*c6914c10Srralphs 
634*c6914c10Srralphs /*
635*c6914c10Srralphs  * Data returned from the READ POSITION command.
636*c6914c10Srralphs  */
637*c6914c10Srralphs 
638*c6914c10Srralphs typedef struct tape_position {
639*c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
640*c6914c10Srralphs 	uchar_t begin_of_part:	1;
641*c6914c10Srralphs 	uchar_t end_of_part:	1;
642*c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
643*c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
644*c6914c10Srralphs 	uchar_t reserved0:	1;
645*c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
646*c6914c10Srralphs 	uchar_t posi_err:	1;
647*c6914c10Srralphs 	uchar_t reserved1:	1;
648*c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
649*c6914c10Srralphs 	uchar_t reserved1:	1;
650*c6914c10Srralphs 	uchar_t posi_err:	1;
651*c6914c10Srralphs 	uchar_t blk_posi_unkwn:	1;
652*c6914c10Srralphs 	uchar_t reserved0:	1;
653*c6914c10Srralphs 	uchar_t byte_cnt_unkwn:	1;
654*c6914c10Srralphs 	uchar_t blk_cnt_unkwn:	1;
655*c6914c10Srralphs 	uchar_t end_of_part:	1;
656*c6914c10Srralphs 	uchar_t begin_of_part:	1;
657*c6914c10Srralphs #endif
658*c6914c10Srralphs 	uchar_t partition_number;
659*c6914c10Srralphs 	uchar_t reserved2[2];
660*c6914c10Srralphs 	uint32_t host_block;
661*c6914c10Srralphs 	uint32_t media_block;
662*c6914c10Srralphs 	uchar_t reserved3;
663*c6914c10Srralphs 	uchar_t block_in_buff[3];
664*c6914c10Srralphs 	uint32_t byte_in_buff;
665*c6914c10Srralphs }tape_position_t;
666*c6914c10Srralphs 
667*c6914c10Srralphs 
668*c6914c10Srralphs typedef struct tape_position_long {
669*c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
670*c6914c10Srralphs 	uint32_t begin_of_part:	1;
671*c6914c10Srralphs 	uint32_t end_of_part:	1;
672*c6914c10Srralphs 	uint32_t reserved0:	2;
673*c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
674*c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
675*c6914c10Srralphs 	uint32_t reserved1:	2;
676*c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
677*c6914c10Srralphs 	uint32_t reserved1:	2;
678*c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
679*c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
680*c6914c10Srralphs 	uint32_t reserved0:	2;
681*c6914c10Srralphs 	uint32_t end_of_part:   1;
682*c6914c10Srralphs 	uint32_t begin_of_part: 1;
683*c6914c10Srralphs #endif
684*c6914c10Srralphs 	uint32_t reserved2:	24;
685*c6914c10Srralphs 	uint32_t partition;
686*c6914c10Srralphs 	uint64_t block_number;
687*c6914c10Srralphs 	uint64_t file_number;
688*c6914c10Srralphs 	uint64_t set_number;
689*c6914c10Srralphs }tape_position_long_t;
690*c6914c10Srralphs 
691*c6914c10Srralphs typedef struct tape_position_ext {
692*c6914c10Srralphs #if defined(_BIT_FIELDS_HTOL)
693*c6914c10Srralphs 	uint32_t begin_of_part:	1;
694*c6914c10Srralphs 	uint32_t end_of_part:	1;
695*c6914c10Srralphs 	uint32_t blk_cnt_unkwn:	1;
696*c6914c10Srralphs 	uint32_t byte_cnt_unkwn:1;
697*c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
698*c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
699*c6914c10Srralphs 	uint32_t posi_err:	1;
700*c6914c10Srralphs 	uint32_t reserved0:	1;
701*c6914c10Srralphs 	uint32_t partition:	8;
702*c6914c10Srralphs 	uint32_t parameter_len:	16;
703*c6914c10Srralphs /* start next word */
704*c6914c10Srralphs 	uint32_t reserved1:	8;
705*c6914c10Srralphs 	uint32_t blks_in_buf:	24;
706*c6914c10Srralphs #elif defined(_BIT_FIELDS_LTOH)
707*c6914c10Srralphs 	uint32_t parameter_len:	16;
708*c6914c10Srralphs 	uint32_t partition:	8;
709*c6914c10Srralphs 	uint32_t reserved0:	1;
710*c6914c10Srralphs 	uint32_t posi_err:	1;
711*c6914c10Srralphs 	uint32_t blk_posi_unkwn:1;
712*c6914c10Srralphs 	uint32_t mrk_posi_unkwn:1;
713*c6914c10Srralphs 	uint32_t byte_cnt_unkwn:1;
714*c6914c10Srralphs 	uint32_t blk_cnt_unkwn:	1;
715*c6914c10Srralphs 	uint32_t end_of_part:	1;
716*c6914c10Srralphs 	uint32_t begin_of_part:	1;
717*c6914c10Srralphs /* start next word */
718*c6914c10Srralphs 	uint32_t blks_in_buf:	24;
719*c6914c10Srralphs 	uint32_t reserved1:	8;
720*c6914c10Srralphs #endif
721*c6914c10Srralphs 	uint64_t host_block;
722*c6914c10Srralphs 	uint64_t media_block;
723*c6914c10Srralphs 	uint64_t byte_in_buf;
724*c6914c10Srralphs }tape_position_ext_t;
725*c6914c10Srralphs 
726*c6914c10Srralphs typedef union {
727*c6914c10Srralphs 	tape_position_t srt;
728*c6914c10Srralphs 	tape_position_ext_t ext;
729*c6914c10Srralphs 	tape_position_long_t lng;
730*c6914c10Srralphs }read_pos_data_t;
731*c6914c10Srralphs 
732f3531714Scz #ifdef _KERNEL
733f3531714Scz 
734f3531714Scz #if defined(__i386) || defined(__amd64)
735f3531714Scz /* Data structure used in big block I/O on x86/x64 platform */
736f3531714Scz 
737f3531714Scz /*
738f3531714Scz  * alloc more than one contig_mem, so mutiple I/O can be
739f3531714Scz  * on-going simultaneously
740f3531714Scz  */
741f3531714Scz #define	ST_MAX_CONTIG_MEM_NUM	3
742f3531714Scz 
743f3531714Scz /*
744f3531714Scz  * 60K is used due to the limitation(size) of the intermediate buffer
745f3531714Scz  * in DMA bind code(rootnex.c), which is 64K. If the I/O buf is page
746f3531714Scz  * aligned, HBA can do 64K DMA, but if not, HBA can only do
747f3531714Scz  * 64K - PAGESIZE = 60K DMA due to the copy to/from intermediate
748f3531714Scz  * buffer will keep the page offset.
749f3531714Scz  */
750f3531714Scz #define	ST_BIGBLK_XFER		60 * 1024
751f3531714Scz struct contig_mem {
752f3531714Scz 	struct contig_mem *cm_next;
753f3531714Scz 	size_t cm_len;
754f3531714Scz 	caddr_t cm_addr;
755f3531714Scz 	ddi_acc_handle_t cm_acc_hdl;
756f3531714Scz 	struct buf *cm_bp;
757f3531714Scz 	int cm_use_sbuf;
758f3531714Scz };
7594ebb14b2Sfrits 
760f3531714Scz #endif
761f3531714Scz 
762f3531714Scz #endif /* _KERNEL */
763f3531714Scz 
7645988135dSrralphs /*
765*c6914c10Srralphs  * driver states..
7665988135dSrralphs  */
7675988135dSrralphs typedef enum {
768*c6914c10Srralphs 	ST_STATE_CLOSED,
769*c6914c10Srralphs 	ST_STATE_OFFLINE,
770*c6914c10Srralphs 	ST_STATE_INITIALIZING,
771*c6914c10Srralphs 	ST_STATE_OPENING,
772*c6914c10Srralphs 	ST_STATE_OPEN_PENDING_IO,
773*c6914c10Srralphs 	ST_STATE_APPEND_TESTING,
774*c6914c10Srralphs 	ST_STATE_OPEN,
775*c6914c10Srralphs 	ST_STATE_RESOURCE_WAIT,
776*c6914c10Srralphs 	ST_STATE_CLOSING,
777*c6914c10Srralphs 	ST_STATE_SENSING,
778*c6914c10Srralphs 	ST_STATE_CLOSE_PENDING_OPEN
779*c6914c10Srralphs }st_states;
780*c6914c10Srralphs 
781*c6914c10Srralphs typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
7825988135dSrralphs 
7835988135dSrralphs 
7847c478bd9Sstevel@tonic-gate /*
7857c478bd9Sstevel@tonic-gate  * Private info for scsi tapes. Pointed to by the un_private pointer
7867c478bd9Sstevel@tonic-gate  * of one of the SCSI_DEVICE chains.
7877c478bd9Sstevel@tonic-gate  */
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate struct scsi_tape {
7907c478bd9Sstevel@tonic-gate 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
7917c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
7927c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
7937c478bd9Sstevel@tonic-gate 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
7947c478bd9Sstevel@tonic-gate 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
7957c478bd9Sstevel@tonic-gate 	struct	buf *un_sbufp;		/* for use in special io */
7967c478bd9Sstevel@tonic-gate 	char	*un_srqbufp;		/* sense buffer for special io */
7977c478bd9Sstevel@tonic-gate 	kcondvar_t un_clscv;		/* closing cv */
7987c478bd9Sstevel@tonic-gate 	struct	buf *un_quef;		/* head of wait queue */
7997c478bd9Sstevel@tonic-gate 	struct	buf *un_quel;		/* tail of wait queue */
8007c478bd9Sstevel@tonic-gate 	struct	buf *un_runqf;		/* head of run queue */
8017c478bd9Sstevel@tonic-gate 	struct	buf *un_runql;		/* tail of run queue */
8027c478bd9Sstevel@tonic-gate 	struct seq_mode *un_mspl;	/* ptr to mode select info */
8037c478bd9Sstevel@tonic-gate 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
8047c478bd9Sstevel@tonic-gate 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
8057c478bd9Sstevel@tonic-gate 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
806*c6914c10Srralphs 	tapepos_t un_pos;		/* Current tape position */
8077c478bd9Sstevel@tonic-gate 	int	un_oflags;		/* open flags */
808*c6914c10Srralphs 	tapepos_t un_err_pos;		/* block in file where err occurred */
8097c478bd9Sstevel@tonic-gate 	uint_t	un_err_resid;		/* resid from last error */
8107c478bd9Sstevel@tonic-gate 	short	un_fmneeded;		/* filemarks to be written - HP only */
8117c478bd9Sstevel@tonic-gate 	dev_t	un_dev;			/* unix device */
8127c478bd9Sstevel@tonic-gate 	uchar_t	un_attached;		/* unit known && attached */
8137c478bd9Sstevel@tonic-gate 	int	un_pwr_mgmt;		/* power management state */
8147c478bd9Sstevel@tonic-gate 	uchar_t	un_density_known;	/* density is known */
8157c478bd9Sstevel@tonic-gate 	uchar_t	un_curdens;		/* index into density table */
8165988135dSrralphs 	optype	un_lastop;		/* last I/O was: read/write/ctl */
817*c6914c10Srralphs 	st_states un_laststate;		/* last state */
818*c6914c10Srralphs 	st_states un_state;		/* current state */
8197c478bd9Sstevel@tonic-gate 	uchar_t	un_status;		/* status from last sense */
8207c478bd9Sstevel@tonic-gate 	uchar_t	un_retry_ct;		/* retry count */
8217c478bd9Sstevel@tonic-gate 	uchar_t	un_tran_retry_ct;	/* transport retry count */
8225988135dSrralphs 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
8237c478bd9Sstevel@tonic-gate 	uchar_t	un_test_append;		/* check writing at end of tape */
8247c478bd9Sstevel@tonic-gate 	uchar_t un_arq_enabled;		/* auto request sense enabled */
8257c478bd9Sstevel@tonic-gate 	uchar_t un_untagged_qing;	/* hba has untagged quing */
8267c478bd9Sstevel@tonic-gate 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
8277c478bd9Sstevel@tonic-gate 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
8287c478bd9Sstevel@tonic-gate 	uchar_t	un_ncmds;		/* number of commands outstanding */
8297c478bd9Sstevel@tonic-gate 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
8307c478bd9Sstevel@tonic-gate 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
8317c478bd9Sstevel@tonic-gate 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
8327c478bd9Sstevel@tonic-gate 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
8337c478bd9Sstevel@tonic-gate 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
8347c478bd9Sstevel@tonic-gate 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
8357c478bd9Sstevel@tonic-gate 					/* check condidtion or error */
8367c478bd9Sstevel@tonic-gate 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
8377c478bd9Sstevel@tonic-gate 	uint_t	un_last_resid;		/* keep last resid, for PE */
8387c478bd9Sstevel@tonic-gate 	uint_t	un_last_count;		/* keep last count, for PE */
8397c478bd9Sstevel@tonic-gate 	struct 	kstat *un_stats;	/* for I/O statistics */
8407c478bd9Sstevel@tonic-gate 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
8417c478bd9Sstevel@tonic-gate 	struct	buf *un_wf;		/* head of write queue */
8427c478bd9Sstevel@tonic-gate 	struct	buf *un_wl;		/* tail of write queue */
8437c478bd9Sstevel@tonic-gate 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
8447c478bd9Sstevel@tonic-gate 	int	un_maxdma;		/* max dma xfer allowed by HBA */
8457c478bd9Sstevel@tonic-gate 	uint_t	un_bsize;		/* block size currently being used */
8467c478bd9Sstevel@tonic-gate 	int	un_maxbsize;		/* max block size allowed by drive */
8477c478bd9Sstevel@tonic-gate 	uint_t	un_minbsize;		/* min block size allowed by drive */
8487c478bd9Sstevel@tonic-gate 	int	un_errno;		/* errno (b_error) */
8497c478bd9Sstevel@tonic-gate 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
8507c478bd9Sstevel@tonic-gate 	enum mtio_state	un_mediastate;	/* current media state */
8517c478bd9Sstevel@tonic-gate 	enum mtio_state	un_specified_mediastate;	/* expected state */
8527c478bd9Sstevel@tonic-gate 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
8537c478bd9Sstevel@tonic-gate 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
8547c478bd9Sstevel@tonic-gate 	opaque_t	un_swr_token;	/* scsi_watch request token */
8557c478bd9Sstevel@tonic-gate 	uchar_t	un_comp_page;		/* compression page */
8567c478bd9Sstevel@tonic-gate 	uchar_t	un_rsvd_status;		/* Reservation Status */
8577c478bd9Sstevel@tonic-gate 	kstat_t *un_errstats;		/* for error statistics */
8587c478bd9Sstevel@tonic-gate 	int	un_init_options;  	/* Init time drive options */
8597c478bd9Sstevel@tonic-gate 	int	un_save_fileno;		/* Save here for recovery */
8607c478bd9Sstevel@tonic-gate 	daddr_t	un_save_blkno;		/* Save here for recovery */
861*c6914c10Srralphs 	uchar_t un_restore_pos;		/* Indication to do recovery */
862*c6914c10Srralphs 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
8637c478bd9Sstevel@tonic-gate 	uchar_t	un_silent_skip;		/* to catch short reads */
864*c6914c10Srralphs 	short	un_tids_at_suspend;	/* timeouts set at suspend */
865*c6914c10Srralphs 	kcondvar_t un_tape_busy_cv;	/* busy cv */
866*c6914c10Srralphs 	kcondvar_t un_suspend_cv;	/* busy cv */
8677c478bd9Sstevel@tonic-gate 					/* restore on close */
8687c478bd9Sstevel@tonic-gate 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
8697c478bd9Sstevel@tonic-gate 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
8707c478bd9Sstevel@tonic-gate 	uchar_t	un_rqs_state;		/* see define below */
871*c6914c10Srralphs 	struct scsi_extended_sense
872*c6914c10Srralphs 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
8737c478bd9Sstevel@tonic-gate 	uchar_t	un_data_mod;		/* Device required data mod */
8745988135dSrralphs 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
8755988135dSrralphs 	int un_max_cdb_sz;		/* max cdb size to use */
876*c6914c10Srralphs 	read_p_types un_read_pos_type;
877*c6914c10Srralphs 	read_pos_data_t *un_read_pos_data;
878f3531714Scz 
879f3531714Scz #if defined(__i386) || defined(__amd64)
880f3531714Scz 	ddi_dma_handle_t un_contig_mem_hdl;
881f3531714Scz 	struct contig_mem *un_contig_mem;
882f3531714Scz 	int un_contig_mem_available_num;
883f3531714Scz 	int un_contig_mem_total_num;
884a7333962Scz 	size_t un_max_contig_mem_len;
885f3531714Scz 	kcondvar_t un_contig_mem_cv;
886f3531714Scz #endif
8877c478bd9Sstevel@tonic-gate };
8884ebb14b2Sfrits 
8894ebb14b2Sfrits 
8907c478bd9Sstevel@tonic-gate /*
8917c478bd9Sstevel@tonic-gate  * device error kstats
8927c478bd9Sstevel@tonic-gate  */
8937c478bd9Sstevel@tonic-gate struct st_errstats {
8947c478bd9Sstevel@tonic-gate 	struct kstat_named	st_softerrs;
8957c478bd9Sstevel@tonic-gate 	struct kstat_named	st_harderrs;
8967c478bd9Sstevel@tonic-gate 	struct kstat_named	st_transerrs;
8977c478bd9Sstevel@tonic-gate 	struct kstat_named	st_vid;
8987c478bd9Sstevel@tonic-gate 	struct kstat_named	st_pid;
8997c478bd9Sstevel@tonic-gate 	struct kstat_named	st_revision;
9007c478bd9Sstevel@tonic-gate 	struct kstat_named	st_serial;
9017c478bd9Sstevel@tonic-gate };
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate  * generic log page struct
9057c478bd9Sstevel@tonic-gate  */
9067c478bd9Sstevel@tonic-gate struct log_page {
9077c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
9087c478bd9Sstevel@tonic-gate 	uchar_t	code	:6,	/* page code number */
9097c478bd9Sstevel@tonic-gate 			:2;	/* reserved */
9107c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
9117c478bd9Sstevel@tonic-gate 	uchar_t		:2,	/* reserved */
9127c478bd9Sstevel@tonic-gate 		code	:6;	/* page code number */
9137c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
9147c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
9157c478bd9Sstevel@tonic-gate 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
9167c478bd9Sstevel@tonic-gate 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
9177c478bd9Sstevel@tonic-gate 	/*
9187c478bd9Sstevel@tonic-gate 	 * Log parameters follow right after this...
9197c478bd9Sstevel@tonic-gate 	 */
9207c478bd9Sstevel@tonic-gate };
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate  * generic log page parameter struct
9247c478bd9Sstevel@tonic-gate  */
9257c478bd9Sstevel@tonic-gate struct log_param {
9267c478bd9Sstevel@tonic-gate 	uchar_t	pc_hi;			/* parameter code (msb) */
9277c478bd9Sstevel@tonic-gate 	uchar_t	pc_lo;			/* parameter code (lsb) */
9287c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
9297c478bd9Sstevel@tonic-gate 	uchar_t		lp	: 1,	/* list parameter */
9307c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
9317c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
9327c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
9337c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
9347c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
9357c478bd9Sstevel@tonic-gate 			du	: 1;	/* disable update */
9367c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
9377c478bd9Sstevel@tonic-gate 	uchar_t		du	: 1,	/* disable update */
9387c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
9397c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
9407c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
9417c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
9427c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
9437c478bd9Sstevel@tonic-gate 			lp	: 1;	/* list parameter */
9447c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
9457c478bd9Sstevel@tonic-gate 	uchar_t	length;		/* length of bytes to follow */
9467c478bd9Sstevel@tonic-gate 	/*
9477c478bd9Sstevel@tonic-gate 	 * Parameter values follow right after this...
9487c478bd9Sstevel@tonic-gate 	 */
9497c478bd9Sstevel@tonic-gate };
9507c478bd9Sstevel@tonic-gate /*
9517c478bd9Sstevel@tonic-gate  * TapeAlert structures
9527c478bd9Sstevel@tonic-gate  */
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate struct st_tape_alert_parameter {
9557c478bd9Sstevel@tonic-gate 	struct log_param log_param;
9567c478bd9Sstevel@tonic-gate 	uchar_t	param_value;
9577c478bd9Sstevel@tonic-gate };
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate struct st_tape_alert {
9607c478bd9Sstevel@tonic-gate 	struct log_page log_page;
9617c478bd9Sstevel@tonic-gate 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
9627c478bd9Sstevel@tonic-gate };
9637c478bd9Sstevel@tonic-gate 
9647c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PARAMETER_LENGTH \
9657c478bd9Sstevel@tonic-gate 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate struct log_sequential_page_parameter {
9687c478bd9Sstevel@tonic-gate 	struct log_param log_param;
9697c478bd9Sstevel@tonic-gate 	uchar_t param_value[8];
9707c478bd9Sstevel@tonic-gate };
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate struct log_sequential_page {
9737c478bd9Sstevel@tonic-gate 	struct log_page log_page;
9747c478bd9Sstevel@tonic-gate 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
9757c478bd9Sstevel@tonic-gate };
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate #if !defined(__lint)
9787c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
9797c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
9807c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
9817c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
9824ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
9837c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
9847c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
9857c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("save sharing",
9867c478bd9Sstevel@tonic-gate 	scsi_tape::un_allow_large_xfer
9877c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxbsize
9887c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxdma
9897c478bd9Sstevel@tonic-gate ))
9904ebb14b2Sfrits #if defined(__i386) || defined(__amd64)
9914ebb14b2Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
9924ebb14b2Sfrits _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
9934ebb14b2Sfrits #endif
9947c478bd9Sstevel@tonic-gate #endif
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate /*
9987c478bd9Sstevel@tonic-gate  * Power management state
9997c478bd9Sstevel@tonic-gate  */
10007c478bd9Sstevel@tonic-gate #define	ST_PWR_NORMAL				0
10017c478bd9Sstevel@tonic-gate #define	ST_PWR_SUSPENDED			1
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 
1004*c6914c10Srralphs #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate /* un_rqs_state codes */
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
10097c478bd9Sstevel@tonic-gate #define	ST_RQS_VALID		0x2	/* RQS data is valid */
10107c478bd9Sstevel@tonic-gate #define	ST_RQS_READ		0x4	/* RQS data was read */
10117c478bd9Sstevel@tonic-gate #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate /*
10147c478bd9Sstevel@tonic-gate  * stintr codes
10157c478bd9Sstevel@tonic-gate  */
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate #define	COMMAND_DONE					0
10187c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_ERROR				1
10197c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_ERROR_RECOVERED			2
10207c478bd9Sstevel@tonic-gate #define	QUE_COMMAND					3
10217c478bd9Sstevel@tonic-gate #define	QUE_BUSY_COMMAND				4
10227c478bd9Sstevel@tonic-gate #define	QUE_SENSE					5
10237c478bd9Sstevel@tonic-gate #define	JUST_RETURN					6
10247c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_EACCES				7
10257c478bd9Sstevel@tonic-gate #define	QUE_LAST_COMMAND				8
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate /*
10297c478bd9Sstevel@tonic-gate  *	Reservation Status
10307c478bd9Sstevel@tonic-gate  *
10317c478bd9Sstevel@tonic-gate  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
10327c478bd9Sstevel@tonic-gate  *		         in between opens and also to indicate the reservation
10337c478bd9Sstevel@tonic-gate  *		         has not been done till now.
10347c478bd9Sstevel@tonic-gate  * ST_RELEASE	        -Tape Unit is Released.
10357c478bd9Sstevel@tonic-gate  * ST_RESERVE	        -Tape Unit is Reserved.
10367c478bd9Sstevel@tonic-gate  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
10377c478bd9Sstevel@tonic-gate  *
10387c478bd9Sstevel@tonic-gate  */
10397c478bd9Sstevel@tonic-gate #define	ST_INIT_RESERVE			0x001
10407c478bd9Sstevel@tonic-gate #define	ST_RELEASE			0x002
10417c478bd9Sstevel@tonic-gate #define	ST_RESERVE			0x004
10427c478bd9Sstevel@tonic-gate #define	ST_PRESERVE_RESERVE		0x008
10437c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_CONFLICT 	0x010
10447c478bd9Sstevel@tonic-gate #define	ST_LOST_RESERVE			0x020
1045e213afc3Srralphs #define	ST_APPLICATION_RESERVATIONS	0x040
1046e213afc3Srralphs #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
1047e213afc3Srralphs 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
10487c478bd9Sstevel@tonic-gate 
1049e213afc3Srralphs /*
1050e213afc3Srralphs  * Service action defines for Persistant Reservation Commands
1051e213afc3Srralphs  */
1052e213afc3Srralphs #define	ST_SA_SCSI3_REGISTER			0x00
1053e213afc3Srralphs #define	ST_SA_SCSI3_RESERVE			0x01
1054e213afc3Srralphs #define	ST_SA_SCSI3_RELEASE			0x02
1055e213afc3Srralphs #define	ST_SA_SCSI3_CLEAR			0x03
1056e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPT			0x04
1057e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
1058e213afc3Srralphs #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
1059e213afc3Srralphs #define	ST_SA_MASK				0x1f
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_DELAY		500000
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate /*
10647c478bd9Sstevel@tonic-gate  * Asynch I/O tunables
10657c478bd9Sstevel@tonic-gate  */
10667c478bd9Sstevel@tonic-gate #define	ST_MAX_THROTTLE		4
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate /*
10697c478bd9Sstevel@tonic-gate  * 60 minutes seems a reasonable amount of time
10707c478bd9Sstevel@tonic-gate  * to wait for tape space operations to complete.
10717c478bd9Sstevel@tonic-gate  *
10727c478bd9Sstevel@tonic-gate  */
10737c478bd9Sstevel@tonic-gate #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
10747c478bd9Sstevel@tonic-gate #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate /*
10777c478bd9Sstevel@tonic-gate  * 2 minutes seems a reasonable amount of time
10787c478bd9Sstevel@tonic-gate  * to wait for tape i/o operations to complete.
10797c478bd9Sstevel@tonic-gate  *
10807c478bd9Sstevel@tonic-gate  */
10817c478bd9Sstevel@tonic-gate #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
10827c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate /*
10867c478bd9Sstevel@tonic-gate  * 10 seconds is what we'll wait if we get a Busy Status back
10877c478bd9Sstevel@tonic-gate  */
10887c478bd9Sstevel@tonic-gate #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
10897c478bd9Sstevel@tonic-gate #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
10907c478bd9Sstevel@tonic-gate #define	ST_INTERRUPT_CONTEXT	1
10917c478bd9Sstevel@tonic-gate #define	ST_START_CONTEXT	2
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate /*
10947c478bd9Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
10957c478bd9Sstevel@tonic-gate  *
10967c478bd9Sstevel@tonic-gate  * XXX This includes retries due to transport failure as well as
10977c478bd9Sstevel@tonic-gate  * XXX busy timeouts- Need to distinguish between Target and Transport
10987c478bd9Sstevel@tonic-gate  * XXX failure.
10997c478bd9Sstevel@tonic-gate  */
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate #define	ST_RETRY_COUNT		20
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate /*
11047c478bd9Sstevel@tonic-gate  * Number of times to retry a failed selection
11057c478bd9Sstevel@tonic-gate  */
11067c478bd9Sstevel@tonic-gate #define	ST_SEL_RETRY_COUNT		2
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate /*
11097c478bd9Sstevel@tonic-gate  * es_code value for deferred error
11107c478bd9Sstevel@tonic-gate  * should be moved to sense.h
11117c478bd9Sstevel@tonic-gate  */
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate #define	ST_DEFERRED_ERROR		0x01
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate /*
11167c478bd9Sstevel@tonic-gate  * Maximum number of units (determined by minor device byte)
11177c478bd9Sstevel@tonic-gate  */
11187c478bd9Sstevel@tonic-gate #define	ST_MAXUNIT	128
11197c478bd9Sstevel@tonic-gate 
11207c478bd9Sstevel@tonic-gate /*
11217c478bd9Sstevel@tonic-gate  * Time to wait for completion of a command before cancelling it.
11227c478bd9Sstevel@tonic-gate  * For SUSPEND use only
11237c478bd9Sstevel@tonic-gate  */
11247c478bd9Sstevel@tonic-gate #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
11257c478bd9Sstevel@tonic-gate 
11267c478bd9Sstevel@tonic-gate #ifndef	SECSIZE
11277c478bd9Sstevel@tonic-gate #define	SECSIZE	512
11287c478bd9Sstevel@tonic-gate #endif
11297c478bd9Sstevel@tonic-gate #ifndef	SECDIV
11307c478bd9Sstevel@tonic-gate #define	SECDIV	9
11317c478bd9Sstevel@tonic-gate #endif
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate /*
11347c478bd9Sstevel@tonic-gate  * convenient defines
11357c478bd9Sstevel@tonic-gate  */
11367c478bd9Sstevel@tonic-gate #define	ST_SCSI_DEVP	(un->un_sd)
11377c478bd9Sstevel@tonic-gate #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
11387c478bd9Sstevel@tonic-gate #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
11397c478bd9Sstevel@tonic-gate #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
11407c478bd9Sstevel@tonic-gate #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
11417c478bd9Sstevel@tonic-gate #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
11447c478bd9Sstevel@tonic-gate #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
11457c478bd9Sstevel@tonic-gate #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
11467c478bd9Sstevel@tonic-gate #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
11477c478bd9Sstevel@tonic-gate #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
11487c478bd9Sstevel@tonic-gate #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
11497c478bd9Sstevel@tonic-gate #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
11507c478bd9Sstevel@tonic-gate #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
11517c478bd9Sstevel@tonic-gate #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
11547c478bd9Sstevel@tonic-gate 	((un)->un_state == ST_STATE_SENSING && \
11557c478bd9Sstevel@tonic-gate 		(un)->un_laststate == ST_STATE_CLOSING))
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate #define	ASYNC_CMD	0
11587c478bd9Sstevel@tonic-gate #define	SYNC_CMD	1
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate /*
11617c478bd9Sstevel@tonic-gate  * Flush tape wait queue as needed.
11627c478bd9Sstevel@tonic-gate  */
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate #define	IS_PE_FLAG_SET(un) ((un)->un_persistence && (un)->un_persist_errors)
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate #define	TURN_PE_ON(un)		st_turn_pe_on(un)
11677c478bd9Sstevel@tonic-gate #define	TURN_PE_OFF(un)		st_turn_pe_off(un)
11687c478bd9Sstevel@tonic-gate #define	SET_PE_FLAG(un)		st_set_pe_flag(un)
11697c478bd9Sstevel@tonic-gate #define	CLEAR_PE(un)		st_clear_pe(un)
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate #define	st_bioerror(bp, error) \
11727c478bd9Sstevel@tonic-gate 		{ bioerror(bp, error); \
11737c478bd9Sstevel@tonic-gate 		un->un_errno = error; }
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate /*
11767c478bd9Sstevel@tonic-gate  * Macros for internal coding of count for SPACE command:
11777c478bd9Sstevel@tonic-gate  *
11787c478bd9Sstevel@tonic-gate  * Isfmk is 1 when spacing filemarks; 0 when spacing records:
11797c478bd9Sstevel@tonic-gate  * bit 24 set indicates a space filemark command.
11807c478bd9Sstevel@tonic-gate  * Fmk sets the filemark bit (24) and changes a backspace
11817c478bd9Sstevel@tonic-gate  * count into a positive number with the sign bit set.
11827c478bd9Sstevel@tonic-gate  * Blk changes a backspace count into a positive number with
11837c478bd9Sstevel@tonic-gate  * the sign bit set.
11847c478bd9Sstevel@tonic-gate  * space_cnt converts backwards counts to negative numbers.
11857c478bd9Sstevel@tonic-gate  */
1186*c6914c10Srralphs #define	SP_BLK		0
1187*c6914c10Srralphs #define	SP_FLM		((1<<24))
1188*c6914c10Srralphs #define	SP_SQFLM	((2<<24))
1189*c6914c10Srralphs #define	SP_EOD		((3<<24))
1190*c6914c10Srralphs #define	SP_BACKSP	((1<<30))
1191*c6914c10Srralphs #define	SP_CMD_MASK	((7<<24))
1192*c6914c10Srralphs #define	SP_CNT_MASK	((1<<24)-1)
1193*c6914c10Srralphs 
1194*c6914c10Srralphs /* Macros to assemble space cmds */
1195*c6914c10Srralphs #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
1196*c6914c10Srralphs #define	Fmk(x)		SPACE(SP_FLM, x)
1197*c6914c10Srralphs #define	Blk(x)		SPACE(SP_BLK, x)
1198*c6914c10Srralphs 
1199*c6914c10Srralphs /* Macros to interpret space cmds */
1200*c6914c10Srralphs #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1201*c6914c10Srralphs 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1202*c6914c10Srralphs #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>24)
1203*c6914c10Srralphs 
1204*c6914c10Srralphs 
1205*c6914c10Srralphs /* Defines for byte 4 of load/unload cmd */
1206*c6914c10Srralphs #define	LD_UNLOAD	0
1207*c6914c10Srralphs #define	LD_LOAD		1
1208*c6914c10Srralphs #define	LD_RETEN	2
1209*c6914c10Srralphs #define	LD_EOT		4
1210*c6914c10Srralphs #define	LD_HOLD		8
1211*c6914c10Srralphs 
1212*c6914c10Srralphs /* Defines for byte 4 of prevent/allow media removal */
1213*c6914c10Srralphs #define	MR_UNLOCK	0
1214*c6914c10Srralphs #define	MR_LOCK		1
12157c478bd9Sstevel@tonic-gate 
12167c478bd9Sstevel@tonic-gate #define	GET_SOFT_STATE(dev)						\
12177c478bd9Sstevel@tonic-gate 	register struct scsi_tape *un;					\
12187c478bd9Sstevel@tonic-gate 	register int instance;						\
12197c478bd9Sstevel@tonic-gate 									\
12207c478bd9Sstevel@tonic-gate 	instance = MTUNIT(dev);						\
12217c478bd9Sstevel@tonic-gate 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
12227c478bd9Sstevel@tonic-gate 		return (ENXIO);
12237c478bd9Sstevel@tonic-gate 
12247c478bd9Sstevel@tonic-gate /*
12257c478bd9Sstevel@tonic-gate  * Debugging turned on via conditional compilation switch -DSTDEBUG
12267c478bd9Sstevel@tonic-gate  */
12277c478bd9Sstevel@tonic-gate #ifdef DEBUG
12287c478bd9Sstevel@tonic-gate #define	STDEBUG
12297c478bd9Sstevel@tonic-gate #endif
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate #ifdef	STDEBUG
1232*c6914c10Srralphs #define	DEBUGGING	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0xf))
12337c478bd9Sstevel@tonic-gate 
1234*c6914c10Srralphs #define	ST_DARGS	st_label, SCSI_DEBUG
12357c478bd9Sstevel@tonic-gate 
1236*c6914c10Srralphs 
1237*c6914c10Srralphs 	/* initialization */
1238*c6914c10Srralphs #define	ST_DEBUG1	if ((st_debug & 0xf) >= 1) scsi_log
12397c478bd9Sstevel@tonic-gate #define	ST_DEBUG	ST_DEBUG1
12407c478bd9Sstevel@tonic-gate 
1241*c6914c10Srralphs 	/* errors and UA's */
1242*c6914c10Srralphs #define	ST_DEBUG2	if ((st_debug & 0xf) >= 2) scsi_log
1243*c6914c10Srralphs 
1244*c6914c10Srralphs 	/* func calls */
1245*c6914c10Srralphs #define	ST_DEBUG3	if ((st_debug & 0xf) >= 3) scsi_log
1246*c6914c10Srralphs 
1247*c6914c10Srralphs 	/* ioctl calls */
1248*c6914c10Srralphs #define	ST_DEBUG4	if ((st_debug & 0xf) >= 4) scsi_log
12497c478bd9Sstevel@tonic-gate 
1250*c6914c10Srralphs #define	ST_DEBUG5	if ((st_debug & 0xf) >= 5) scsi_log
1251*c6914c10Srralphs 
1252*c6914c10Srralphs 	/* full data tracking */
1253*c6914c10Srralphs #define	ST_DEBUG6	if ((st_debug & 0xf) >= 6) scsi_log
1254*c6914c10Srralphs 
1255*c6914c10Srralphs 	/* special cases */
1256*c6914c10Srralphs #define	ST_DEBUG_SP	if ((st_debug & 0xf) == 10) scsi_log
1257*c6914c10Srralphs 
1258*c6914c10Srralphs 	/* Entry Point Functions */
1259*c6914c10Srralphs #define	ST_ENTR(d, fn)	if (st_debug & 0x10) scsi_log(d, ST_DARGS, #fn)
1260*c6914c10Srralphs 
1261*c6914c10Srralphs 	/* Non-Entry Point Functions */
1262*c6914c10Srralphs #define	ST_FUNC(d, fn)	if (st_debug & 0x20) scsi_log(d, ST_DARGS, #fn)
1263*c6914c10Srralphs 
1264*c6914c10Srralphs 	/* Space Information */
1265*c6914c10Srralphs #define	ST_SPAC		if (st_debug & 0x40) scsi_log
1266*c6914c10Srralphs 
1267*c6914c10Srralphs 	/* CDB's sent */
1268*c6914c10Srralphs #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) \
1269*c6914c10Srralphs     st_print_cdb(d, ST_DARGS, cmnt, cdb)
1270*c6914c10Srralphs #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) \
1271*c6914c10Srralphs     st_clean_print(d, ST_DARGS, cmnt, sense, size)
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate #else
12747c478bd9Sstevel@tonic-gate 
12757c478bd9Sstevel@tonic-gate #define	st_debug	(0)
12767c478bd9Sstevel@tonic-gate #define	DEBUGGING	(0)
12777c478bd9Sstevel@tonic-gate #define	ST_DEBUG	if (0) scsi_log
12787c478bd9Sstevel@tonic-gate #define	ST_DEBUG1	if (0) scsi_log
12797c478bd9Sstevel@tonic-gate #define	ST_DEBUG2	if (0) scsi_log
12807c478bd9Sstevel@tonic-gate #define	ST_DEBUG3	if (0) scsi_log
12817c478bd9Sstevel@tonic-gate #define	ST_DEBUG4	if (0) scsi_log
12827c478bd9Sstevel@tonic-gate #define	ST_DEBUG5	if (0) scsi_log
12837c478bd9Sstevel@tonic-gate #define	ST_DEBUG6	if (0) scsi_log
12847c478bd9Sstevel@tonic-gate 
12857c478bd9Sstevel@tonic-gate #define	ST_DEBUG_SP	if (0) scsi_log /* special cases */
12867c478bd9Sstevel@tonic-gate 
1287*c6914c10Srralphs #define	ST_ENTR(d, fn)
1288*c6914c10Srralphs #define	ST_FUNC(d, fn)
1289*c6914c10Srralphs #define	ST_SPAC		if (0) scsi_log
1290*c6914c10Srralphs #define	ST_CDB(d, cmnt, cdb)
1291*c6914c10Srralphs #define	ST_SENSE(d, cmnt, sense, size)
1292*c6914c10Srralphs 
12937c478bd9Sstevel@tonic-gate #endif
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate /*
12967c478bd9Sstevel@tonic-gate  * Media access values
12977c478bd9Sstevel@tonic-gate  */
12987c478bd9Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
12997c478bd9Sstevel@tonic-gate 
13007c478bd9Sstevel@tonic-gate /*
13017c478bd9Sstevel@tonic-gate  * SCSI tape mode sense page information
13027c478bd9Sstevel@tonic-gate  */
13037c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
13047c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
13057c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
13067c478bd9Sstevel@tonic-gate #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
13077c478bd9Sstevel@tonic-gate 
13087c478bd9Sstevel@tonic-gate /*
13097c478bd9Sstevel@tonic-gate  * SCSI tape data compression Page definition.
13107c478bd9Sstevel@tonic-gate  */
13117c478bd9Sstevel@tonic-gate #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate 
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate /*
13167c478bd9Sstevel@tonic-gate  * maxbsize values
13177c478bd9Sstevel@tonic-gate  */
13187c478bd9Sstevel@tonic-gate #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate #define	ONE_MEG			(1024 * 1024)
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate /*
13237c478bd9Sstevel@tonic-gate  * generic soft error reporting
13247c478bd9Sstevel@tonic-gate  *
13257c478bd9Sstevel@tonic-gate  * What we are doing here is allowing a greater number of errors to occur on
13267c478bd9Sstevel@tonic-gate  * smaller transfers (i.e. usually at the beginning of the tape), than on
13277c478bd9Sstevel@tonic-gate  * the rest of the tape.
13287c478bd9Sstevel@tonic-gate  *
13297c478bd9Sstevel@tonic-gate  * A small transfer is defined as :
13307c478bd9Sstevel@tonic-gate  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
13317c478bd9Sstevel@tonic-gate  *
13327c478bd9Sstevel@tonic-gate  * A larget tranfer is defined as :
13337c478bd9Sstevel@tonic-gate  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
13347c478bd9Sstevel@tonic-gate  *
13357c478bd9Sstevel@tonic-gate  */
13367c478bd9Sstevel@tonic-gate #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
13377c478bd9Sstevel@tonic-gate #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate /*
13407c478bd9Sstevel@tonic-gate  * soft error reporting for exabyte
13417c478bd9Sstevel@tonic-gate  */
13427c478bd9Sstevel@tonic-gate #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
13437c478bd9Sstevel@tonic-gate 
13447c478bd9Sstevel@tonic-gate #define	SENSE_19_BITS  \
13457c478bd9Sstevel@tonic-gate 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
13467c478bd9Sstevel@tonic-gate #define	SENSE_20_BITS  \
13477c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
13487c478bd9Sstevel@tonic-gate #define	SENSE_21_BITS  \
13497c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate /* these are defined in percentages */
13527c478bd9Sstevel@tonic-gate #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
13537c478bd9Sstevel@tonic-gate #define	EXABYTE_READ_ERROR_THRESHOLD	3
13547c478bd9Sstevel@tonic-gate /*
13557c478bd9Sstevel@tonic-gate  * minumum amount of data transfer(MB) for checking soft error rate.
13567c478bd9Sstevel@tonic-gate  */
13577c478bd9Sstevel@tonic-gate #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate #define	CLN	0x8
13607c478bd9Sstevel@tonic-gate #define	CLND	0x10
13617c478bd9Sstevel@tonic-gate 
13627c478bd9Sstevel@tonic-gate /*
13637c478bd9Sstevel@tonic-gate  * soft error reporting for Archive 4mm DAT
13647c478bd9Sstevel@tonic-gate  */
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate #define	LOG_SENSE_LENGTH		0xff
13677c478bd9Sstevel@tonic-gate #define	MIN_LOG_SENSE_LENGTH		0x2b
13687c478bd9Sstevel@tonic-gate #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
13697c478bd9Sstevel@tonic-gate #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
13707c478bd9Sstevel@tonic-gate #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
13717c478bd9Sstevel@tonic-gate #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
13727c478bd9Sstevel@tonic-gate 
13737c478bd9Sstevel@tonic-gate /*
13747c478bd9Sstevel@tonic-gate  * ST timeouts that need to be cancelled for suspend
13757c478bd9Sstevel@tonic-gate  */
13767c478bd9Sstevel@tonic-gate #define	ST_HIB_TID	0x01
13777c478bd9Sstevel@tonic-gate #define	ST_DELAY_TID	0x02
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
13807c478bd9Sstevel@tonic-gate }
13817c478bd9Sstevel@tonic-gate #endif
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1384