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
5*e213afc3Srralphs  * Common Development and Distribution License (the "License").
6*e213afc3Srralphs  * 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*e213afc3Srralphs  * Copyright 2006 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>
367c478bd9Sstevel@tonic-gate #include <sys/mtio.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Defines for SCSI tape drives.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Maximum variable length record size for a single request
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE	65535
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
537c478bd9Sstevel@tonic-gate  * then the following define is used.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
587c478bd9Sstevel@tonic-gate #define	INF 1000000000
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Supported tape device types plus default type for opening.
627c478bd9Sstevel@tonic-gate  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
637c478bd9Sstevel@tonic-gate  * Types 14 - 1f, are 1/4-inch cartridge drives.
647c478bd9Sstevel@tonic-gate  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
657c478bd9Sstevel@tonic-gate  * Types 28+, are rdat (vcr) drives.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	ST_TYPE_INVALID		0x00
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
707c478bd9Sstevel@tonic-gate #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
737c478bd9Sstevel@tonic-gate #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
747c478bd9Sstevel@tonic-gate #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
757c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
787c478bd9Sstevel@tonic-gate #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
797c478bd9Sstevel@tonic-gate #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
807c478bd9Sstevel@tonic-gate #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
817c478bd9Sstevel@tonic-gate #define	ST_TYPE_HP	MT_ISHP		/* HP */
827c478bd9Sstevel@tonic-gate #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
837c478bd9Sstevel@tonic-gate #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
847c478bd9Sstevel@tonic-gate #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
877c478bd9Sstevel@tonic-gate #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
887c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
897c478bd9Sstevel@tonic-gate #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
907c478bd9Sstevel@tonic-gate #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
917c478bd9Sstevel@tonic-gate #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
927c478bd9Sstevel@tonic-gate #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
937c478bd9Sstevel@tonic-gate #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
947c478bd9Sstevel@tonic-gate #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
957c478bd9Sstevel@tonic-gate #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
967c478bd9Sstevel@tonic-gate #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
977c478bd9Sstevel@tonic-gate #define	ST_LAST_TYPE	ST_TYPE_LTO	/* Add new above type and change this */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /* Internal flags */
1017c478bd9Sstevel@tonic-gate #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
1027c478bd9Sstevel@tonic-gate 					/* alloc'ed from the st.conf entry, */
1037c478bd9Sstevel@tonic-gate 					/* instead of being used from the */
1047c478bd9Sstevel@tonic-gate 					/* st_drivetypes array. */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Defines for supported drive options
1087c478bd9Sstevel@tonic-gate  *
1097c478bd9Sstevel@tonic-gate  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
1107c478bd9Sstevel@tonic-gate  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	ST_VARIABLE		0x001	/* Device supports variable	*/
1137c478bd9Sstevel@tonic-gate 					/* length record sizes		*/
1147c478bd9Sstevel@tonic-gate #define	ST_QIC			0x002	/* QIC tape device 		*/
1157c478bd9Sstevel@tonic-gate #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
1167c478bd9Sstevel@tonic-gate #define	ST_BSF			0x008	/* Device supports backspace	*/
1177c478bd9Sstevel@tonic-gate 					/* file as in mt(1) bsf : 	*/
1187c478bd9Sstevel@tonic-gate 					/* backspace over EOF marks.	*/
1197c478bd9Sstevel@tonic-gate 					/* Devices not supporting bsf 	*/
1207c478bd9Sstevel@tonic-gate 					/* will fail with ENOTTY upon	*/
1217c478bd9Sstevel@tonic-gate 					/* use of bsf			*/
1227c478bd9Sstevel@tonic-gate #define	ST_BSR			0x010	/* Device supports backspace	*/
1237c478bd9Sstevel@tonic-gate 					/* record as in mt(1) bsr :	*/
1247c478bd9Sstevel@tonic-gate 					/* backspace over records. If	*/
1257c478bd9Sstevel@tonic-gate 					/* the device does not support 	*/
1267c478bd9Sstevel@tonic-gate 					/* bsr, the st driver emulates	*/
1277c478bd9Sstevel@tonic-gate 					/* the action by rewinding the	*/
1287c478bd9Sstevel@tonic-gate 					/* tape and using forward space	*/
1297c478bd9Sstevel@tonic-gate 					/* file (fsf) to the correct	*/
1307c478bd9Sstevel@tonic-gate 					/* file and then uses forward	*/
1317c478bd9Sstevel@tonic-gate 					/* space record (fsr) to the	*/
1327c478bd9Sstevel@tonic-gate 					/* correct  record		*/
1337c478bd9Sstevel@tonic-gate #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
1347c478bd9Sstevel@tonic-gate 					/* than normal to erase		*/
1357c478bd9Sstevel@tonic-gate #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
1367c478bd9Sstevel@tonic-gate 					/* Device can figure out the	*/
1377c478bd9Sstevel@tonic-gate 					/* tape density automatically,	*/
1387c478bd9Sstevel@tonic-gate 					/* without issuing a		*/
1397c478bd9Sstevel@tonic-gate 					/* mode-select/mode-sense 	*/
1407c478bd9Sstevel@tonic-gate #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
1417c478bd9Sstevel@tonic-gate 					/* This disables the device's	*/
1427c478bd9Sstevel@tonic-gate 					/* ability for buffered	writes	*/
1437c478bd9Sstevel@tonic-gate 					/* I.e. The device acknowledges	*/
1447c478bd9Sstevel@tonic-gate 					/* write completion after the	*/
1457c478bd9Sstevel@tonic-gate 					/* data is written to the	*/
1467c478bd9Sstevel@tonic-gate 					/* device's buffer, but before	*/
1477c478bd9Sstevel@tonic-gate 					/* all the data is actually	*/
1487c478bd9Sstevel@tonic-gate 					/* written to tape		*/
1497c478bd9Sstevel@tonic-gate #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
1507c478bd9Sstevel@tonic-gate 					/* parity while talking to it. 	*/
1517c478bd9Sstevel@tonic-gate #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
1527c478bd9Sstevel@tonic-gate 					/* of Data) has been reached.	*/
1537c478bd9Sstevel@tonic-gate 					/* If the device knows EOD, st	*/
1547c478bd9Sstevel@tonic-gate 					/* uses fast file skipping.	*/
1557c478bd9Sstevel@tonic-gate 					/* If it does not know EOD,	*/
1567c478bd9Sstevel@tonic-gate 					/* file skipping happens one	*/
1577c478bd9Sstevel@tonic-gate 					/* file at a time. 		*/
1587c478bd9Sstevel@tonic-gate #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
1597c478bd9Sstevel@tonic-gate 					/* the st driver is unloaded &	*/
1607c478bd9Sstevel@tonic-gate 					/* loaded again; e.g. will	*/
1617c478bd9Sstevel@tonic-gate 					/* return the correct inquiry	*/
1627c478bd9Sstevel@tonic-gate 					/* string			*/
1637c478bd9Sstevel@tonic-gate #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
1647c478bd9Sstevel@tonic-gate 					/* close to report soft errors.	*/
1657c478bd9Sstevel@tonic-gate 					/* Currently only Exabyte and	*/
1667c478bd9Sstevel@tonic-gate 					/* DAT drives support this	*/
1677c478bd9Sstevel@tonic-gate 					/* feature.  			*/
1687c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
1697c478bd9Sstevel@tonic-gate 					/* timeouts for normal		*/
1707c478bd9Sstevel@tonic-gate 					/* operation			*/
1717c478bd9Sstevel@tonic-gate #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
1727c478bd9Sstevel@tonic-gate 					/* driver and pre-acked to the	*/
1737c478bd9Sstevel@tonic-gate 					/* application 			*/
1747c478bd9Sstevel@tonic-gate #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
1757c478bd9Sstevel@tonic-gate 					/* devices only. If flag is	*/
1767c478bd9Sstevel@tonic-gate 					/* set, then don't limit	*/
1777c478bd9Sstevel@tonic-gate 					/* record size to 64k as in	*/
1787c478bd9Sstevel@tonic-gate 					/* pre-Solaris 2.4 releases.	*/
1797c478bd9Sstevel@tonic-gate 					/* The only limit on the	*/
1807c478bd9Sstevel@tonic-gate 					/* record size will be the max	*/
1817c478bd9Sstevel@tonic-gate 					/* record size the device can	*/
1827c478bd9Sstevel@tonic-gate 					/* handle or the max DMA	*/
1837c478bd9Sstevel@tonic-gate 					/* transfer size of the		*/
1847c478bd9Sstevel@tonic-gate 					/* machine, which ever is	*/
1857c478bd9Sstevel@tonic-gate 					/* smaller. Beware of		*/
1867c478bd9Sstevel@tonic-gate 					/* incompatabilities with	*/
1877c478bd9Sstevel@tonic-gate 					/* tapes of pre-Solaris 2.4	*/
1887c478bd9Sstevel@tonic-gate 					/* OS's written with large	*/
1897c478bd9Sstevel@tonic-gate 					/* (>64k) block sizes, as	*/
1907c478bd9Sstevel@tonic-gate 					/* their true block size is	*/
1917c478bd9Sstevel@tonic-gate 					/* a max of approx 64k		*/
1927c478bd9Sstevel@tonic-gate #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
1937c478bd9Sstevel@tonic-gate 					/* configuration page (0x10) to */
1947c478bd9Sstevel@tonic-gate 					/* enable/disable compression	*/
1957c478bd9Sstevel@tonic-gate 					/* instead of density codes for */
1967c478bd9Sstevel@tonic-gate 					/* the "c" and "u" devices	*/
1977c478bd9Sstevel@tonic-gate #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
1987c478bd9Sstevel@tonic-gate 					/* support RESERVE/RELEASE SCSI	*/
1997c478bd9Sstevel@tonic-gate 					/* command. If this is enabled	*/
2007c478bd9Sstevel@tonic-gate 					/* then reserve/release would	*/
2017c478bd9Sstevel@tonic-gate 					/* not be used during open/	*/
2027c478bd9Sstevel@tonic-gate 					/* close for High Availability	*/
2037c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
2047c478bd9Sstevel@tonic-gate 					/* to variable block devices 	*/
2057c478bd9Sstevel@tonic-gate 					/* which support the SILI bit	*/
2067c478bd9Sstevel@tonic-gate 					/* option. It indicates that 	*/
2077c478bd9Sstevel@tonic-gate 					/* the SILI bit will be ignored */
2087c478bd9Sstevel@tonic-gate 					/* during reads  		*/
2097c478bd9Sstevel@tonic-gate #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
2107c478bd9Sstevel@tonic-gate 					/* EOF marks do not indicate an */
2117c478bd9Sstevel@tonic-gate 					/* EOM. This option is only	*/
2127c478bd9Sstevel@tonic-gate 					/* supported on 1/2" reel tapes */
2137c478bd9Sstevel@tonic-gate #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
2147c478bd9Sstevel@tonic-gate 					/* EXABYTE 8mm tape drives 	*/
2157c478bd9Sstevel@tonic-gate 					/* which support short 		*/
2167c478bd9Sstevel@tonic-gate 					/* filemarks. When this flag 	*/
2177c478bd9Sstevel@tonic-gate 					/* is set, short filemarks 	*/
2187c478bd9Sstevel@tonic-gate 					/* will be used for writing	*/
2197c478bd9Sstevel@tonic-gate 					/* filemarks. 			*/
2207c478bd9Sstevel@tonic-gate #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
2217c478bd9Sstevel@tonic-gate 					/* and the tape is trapped in   */
2227c478bd9Sstevel@tonic-gate 					/* the medium changer, the tape */
2237c478bd9Sstevel@tonic-gate 					/* is automatically ejected	*/
2247c478bd9Sstevel@tonic-gate #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
2257c478bd9Sstevel@tonic-gate 					/* This option applies only to  */
2267c478bd9Sstevel@tonic-gate 					/* IBM MAGSTAR 3590. If this    */
2277c478bd9Sstevel@tonic-gate 					/* flag is set, the st driver   */
2287c478bd9Sstevel@tonic-gate 					/* will retry the last cmd if   */
2297c478bd9Sstevel@tonic-gate 					/* the last error cause a check */
2307c478bd9Sstevel@tonic-gate 					/* condition with error code    */
2317c478bd9Sstevel@tonic-gate 					/* 0x71 and sense code  0x01 	*/
2327c478bd9Sstevel@tonic-gate #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
2337c478bd9Sstevel@tonic-gate 					/* detected to select correct   */
2347c478bd9Sstevel@tonic-gate 					/* density code.		*/
2357c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
2367c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2377c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2387c478bd9Sstevel@tonic-gate 					/* byte 21, bitmask 0x08 of	*/
2397c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2407c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
2417c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2427c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2437c478bd9Sstevel@tonic-gate 					/* byte 70, bitmask 0xc0 of	*/
2447c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2457c478bd9Sstevel@tonic-gate #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
2467c478bd9Sstevel@tonic-gate 					/* the tape drive provides the	*/
2477c478bd9Sstevel@tonic-gate 					/* clean bit information in	*/
2487c478bd9Sstevel@tonic-gate 					/* byte 18, bitmask 0x01 of	*/
2497c478bd9Sstevel@tonic-gate 					/* Request Sense data		*/
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2527c478bd9Sstevel@tonic-gate #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
2537c478bd9Sstevel@tonic-gate 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
2547c478bd9Sstevel@tonic-gate 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
2557c478bd9Sstevel@tonic-gate 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
2567c478bd9Sstevel@tonic-gate 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
2577c478bd9Sstevel@tonic-gate 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
2587c478bd9Sstevel@tonic-gate 	ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate #define	NDENSITIES	MT_NDENSITIES
2617c478bd9Sstevel@tonic-gate #define	NSPEEDS		MT_NSPEEDS
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * defines for Log Sense Pages
2657c478bd9Sstevel@tonic-gate  */
2667c478bd9Sstevel@tonic-gate #define	SUPPORTED_LOG_PAGES_PAGE	0x00
2677c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE		0x0c
2687c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PAGE			0x2e
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate  * Log Page Control definitions
2727c478bd9Sstevel@tonic-gate  */
2737c478bd9Sstevel@tonic-gate #define	CURRENT_THRESHOLD_VALUES	0x00
2747c478bd9Sstevel@tonic-gate #define	CURRENT_CUMULATIVE_VALUES	0x40
2757c478bd9Sstevel@tonic-gate #define	DEFAULT_THRESHOLD_VALUES	0x80
2767c478bd9Sstevel@tonic-gate #define	DEFAULT_CUMULATIVE_VALUES	0xC0
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  * Tape Alert Flag definitions
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate #define	CLEANING_MEDIA			11
2827c478bd9Sstevel@tonic-gate #define	CLEAN_NOW			20
2837c478bd9Sstevel@tonic-gate #define	CLEAN_PERIODIC			21
2847c478bd9Sstevel@tonic-gate #define	CLEAN_FOR_ERRORS		24
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
2877c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_NOT_SUPPORTED	0x01
2887c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_SUPPORTED		0x02
2897c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_STILL_DIRTY		0x04
2907c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
2917c478bd9Sstevel@tonic-gate #define	TAPE_PREVIOUSLY_DIRTY		0x10
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_MAX_PARA		64
2947c478bd9Sstevel@tonic-gate #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
2957c478bd9Sstevel@tonic-gate #define	SEQUENTIAL_NEED_CLN		0x0100
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate  * Parameters
2997c478bd9Sstevel@tonic-gate  */
3007c478bd9Sstevel@tonic-gate #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
3017c478bd9Sstevel@tonic-gate #define	VIDLEN		8	/* size of vendor identifier length */
3027c478bd9Sstevel@tonic-gate #define	PIDLEN		16	/* size of product identifier length */
3037c478bd9Sstevel@tonic-gate #define	VIDPIDLEN	(VIDLEN + PIDLEN)
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate struct st_drivetype {
3077c478bd9Sstevel@tonic-gate 	char	name[ST_NAMESIZE];	/* Name, for debug */
3087c478bd9Sstevel@tonic-gate 	char	length;			/* Length of vendor id */
3097c478bd9Sstevel@tonic-gate 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
3107c478bd9Sstevel@tonic-gate 	char	type;			/* Drive type for driver */
3117c478bd9Sstevel@tonic-gate 	int	bsize;			/* Block size */
3127c478bd9Sstevel@tonic-gate 	int	options;		/* Drive options */
3137c478bd9Sstevel@tonic-gate 	int	max_rretries;		/* Max read retries */
3147c478bd9Sstevel@tonic-gate 	int	max_wretries;		/* Max write retries */
3157c478bd9Sstevel@tonic-gate 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
3167c478bd9Sstevel@tonic-gate 	uchar_t	default_density;	/* default density for this drive */
3177c478bd9Sstevel@tonic-gate 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
3187c478bd9Sstevel@tonic-gate 	ushort_t non_motion_timeout;	/* Inquiry type commands */
3197c478bd9Sstevel@tonic-gate 	ushort_t io_timeout;		/* I/O timeout in seconds */
3207c478bd9Sstevel@tonic-gate 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
3217c478bd9Sstevel@tonic-gate 	ushort_t space_timeout;		/* space cmd timeout in seconds */
3227c478bd9Sstevel@tonic-gate 	ushort_t load_timeout;		/* load tape time in seconds */
3237c478bd9Sstevel@tonic-gate 	ushort_t unload_timeout;	/* unload tape time in seconds */
3247c478bd9Sstevel@tonic-gate 	ushort_t erase_timeout;		/* erase timeout. seconds */
3257c478bd9Sstevel@tonic-gate };
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate #define	MINUTES(val)	((val) * 60)
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate struct comp_mode_page {
3307c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3317c478bd9Sstevel@tonic-gate 	uchar_t	:		6,
3327c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
3337c478bd9Sstevel@tonic-gate 		dce:		1;	/* Data Compression Enable */
3347c478bd9Sstevel@tonic-gate 	uchar_t	:		5,
3357c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
3367c478bd9Sstevel@tonic-gate 		dde:		1;	/* Data Decompression Enabled */
3377c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
3387c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
3397c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
3407c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
3417c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
3427c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
3437c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
3447c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
3457c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
3467c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
3477c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
3487c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
3517c478bd9Sstevel@tonic-gate 	uchar_t	dce:		1,	/* Data Compression Enable */
3527c478bd9Sstevel@tonic-gate 		dcc:		1,	/* Data Compression Capable */
3537c478bd9Sstevel@tonic-gate 		:		6;
3547c478bd9Sstevel@tonic-gate 	uchar_t	dde:		1,	/* Data Decompression Enabled */
3557c478bd9Sstevel@tonic-gate 		red:		2,	/* Report Exceptions on Decompress */
3567c478bd9Sstevel@tonic-gate 		:		5;
3577c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
3587c478bd9Sstevel@tonic-gate 	uchar_t comp_alg_high;
3597c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_low;
3607c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg_lsb;
3617c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
3627c478bd9Sstevel@tonic-gate 	uchar_t decomp_alg_high;
3637c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_low;
3647c478bd9Sstevel@tonic-gate 	uchar_t	decomp_alg_lsb;
3657c478bd9Sstevel@tonic-gate 	uchar_t	reservered0;
3667c478bd9Sstevel@tonic-gate 	uchar_t	reservered1;
3677c478bd9Sstevel@tonic-gate 	uchar_t	reservered2;
3687c478bd9Sstevel@tonic-gate 	uchar_t	reservered3;
3697c478bd9Sstevel@tonic-gate #endif
3707c478bd9Sstevel@tonic-gate };
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate struct dev_mode_page {
3737c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
3747c478bd9Sstevel@tonic-gate 	uchar_t	act_format:	5,	/* active format */
3757c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
3767c478bd9Sstevel@tonic-gate 		cap:		1,	/* Change Active Partition */
3777c478bd9Sstevel@tonic-gate 		:		1;
3787c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
3797c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
3807c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
3817c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
3827c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
3837c478bd9Sstevel@tonic-gate 	uchar_t	rew:		1,	/* Report Early Warning */
3847c478bd9Sstevel@tonic-gate 		rbo:		1,	/* Reverse Buffer Order */
3857c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
3867c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
3877c478bd9Sstevel@tonic-gate 		rsmk:		1,	/* Report SetMarKs */
3887c478bd9Sstevel@tonic-gate 		bis:		1,	/* Block Ids Supported */
3897c478bd9Sstevel@tonic-gate 		dbr:		1;	/* Data Buffer Recovery */
3907c478bd9Sstevel@tonic-gate 	uchar_t	gap_size;
3917c478bd9Sstevel@tonic-gate 	uchar_t	:		3,
3927c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
3937c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
3947c478bd9Sstevel@tonic-gate 		eod_defined:	3;
3957c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
3967c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
3977c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
3987c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
3997c478bd9Sstevel@tonic-gate 	uchar_t	reservered;
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4027c478bd9Sstevel@tonic-gate 	uchar_t	:		1,
4037c478bd9Sstevel@tonic-gate 		cap:		1,	/* Change Active Partition */
4047c478bd9Sstevel@tonic-gate 		caf:		1,	/* Change Active Format */
4057c478bd9Sstevel@tonic-gate 		act_format:	5;	/* active format */
4067c478bd9Sstevel@tonic-gate 	uchar_t	act_partition;		/* active partition */
4077c478bd9Sstevel@tonic-gate 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
4087c478bd9Sstevel@tonic-gate 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
4097c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
4107c478bd9Sstevel@tonic-gate 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
4117c478bd9Sstevel@tonic-gate 	uchar_t	dbr:		1,	/* Data Buffer Recovery */
4127c478bd9Sstevel@tonic-gate 		bis:		1,	/* Block Ids Supported */
4137c478bd9Sstevel@tonic-gate 		rsmk:		1,	/* Report SetMarKs */
4147c478bd9Sstevel@tonic-gate 		avc:		1,	/* Automatic Velocity Control */
4157c478bd9Sstevel@tonic-gate 		socf:		2,	/* Stop On Consecutive Filemarks */
4167c478bd9Sstevel@tonic-gate 		rbo:		1,	/* Reverse Buffer Order */
4177c478bd9Sstevel@tonic-gate 		rew:		1;	/* Report Early Warning */
4187c478bd9Sstevel@tonic-gate 	uchar_t	gap_size;
4197c478bd9Sstevel@tonic-gate 	uchar_t	eod_defined:	3,
4207c478bd9Sstevel@tonic-gate 		eeg:		1,	/* Enable Early Waring */
4217c478bd9Sstevel@tonic-gate 		sew:		1,	/* Sync data after Early Warning */
4227c478bd9Sstevel@tonic-gate 		:		3;
4237c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
4247c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_mid;
4257c478bd9Sstevel@tonic-gate 	uchar_t	buf_size_leot_lsb;
4267c478bd9Sstevel@tonic-gate 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
4277c478bd9Sstevel@tonic-gate 	uchar_t	reservered;
4287c478bd9Sstevel@tonic-gate #endif
4297c478bd9Sstevel@tonic-gate };
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate typedef union {
4327c478bd9Sstevel@tonic-gate 	struct comp_mode_page	comp;
4337c478bd9Sstevel@tonic-gate 	struct dev_mode_page	dev;
4347c478bd9Sstevel@tonic-gate }modepage;
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate /*
4377c478bd9Sstevel@tonic-gate  *
4387c478bd9Sstevel@tonic-gate  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
4397c478bd9Sstevel@tonic-gate  * The parameter list contains a header, followed by zero or more
4407c478bd9Sstevel@tonic-gate  * block descriptors, followed by vendor unique parameters, if any.
4417c478bd9Sstevel@tonic-gate  *
4427c478bd9Sstevel@tonic-gate  */
4437c478bd9Sstevel@tonic-gate #define	MSIZE	0x0c		/* Size without additional pages */
4447c478bd9Sstevel@tonic-gate struct seq_mode {
4457c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
4467c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
4477c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
4487c478bd9Sstevel@tonic-gate 	uchar_t	speed	:4,	/* speed */
4497c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
4507c478bd9Sstevel@tonic-gate 		wp	:1;	/* write protected, sense only */
4517c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
4527c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
4537c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
4547c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
4557c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
4567c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
4577c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
4587c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
4597c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
4607c478bd9Sstevel@tonic-gate 	uchar_t page_code:	6,
4617c478bd9Sstevel@tonic-gate 		:		1,
4627c478bd9Sstevel@tonic-gate 		ps:		1; /* Page Savable sense only */
4637c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
4647c478bd9Sstevel@tonic-gate 	modepage page;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
4677c478bd9Sstevel@tonic-gate 	uchar_t	data_len;	/* sense data length, sense only */
4687c478bd9Sstevel@tonic-gate 	uchar_t	media_type;	/* medium type, sense only */
4697c478bd9Sstevel@tonic-gate 	uchar_t	wp	:1,	/* write protected, sense only */
4707c478bd9Sstevel@tonic-gate 		bufm	:3,	/* buffered mode */
4717c478bd9Sstevel@tonic-gate 		speed	:4;	/* speed */
4727c478bd9Sstevel@tonic-gate 	uchar_t	bd_len;		/* block length in bytes */
4737c478bd9Sstevel@tonic-gate 	uchar_t	density;	/* density code */
4747c478bd9Sstevel@tonic-gate 	uchar_t	high_nb;	/* number of logical blocks on the medium */
4757c478bd9Sstevel@tonic-gate 	uchar_t	mid_nb;		/* that are to be formatted with the density */
4767c478bd9Sstevel@tonic-gate 	uchar_t	low_nb;		/* code and block length in block descriptor */
4777c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
4787c478bd9Sstevel@tonic-gate 	uchar_t	high_bl;	/* block length */
4797c478bd9Sstevel@tonic-gate 	uchar_t	mid_bl;		/*   "      "   */
4807c478bd9Sstevel@tonic-gate 	uchar_t	low_bl;		/*   "      "   */
4817c478bd9Sstevel@tonic-gate 	uchar_t	ps:		1, /* Page Savable sense only */
4827c478bd9Sstevel@tonic-gate 		:		1,
4837c478bd9Sstevel@tonic-gate 		page_code:	6;
4847c478bd9Sstevel@tonic-gate 	uchar_t	page_len;
4857c478bd9Sstevel@tonic-gate 	modepage page;
4867c478bd9Sstevel@tonic-gate #else
4877c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
4887c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
4897c478bd9Sstevel@tonic-gate };
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate  * Data returned from the READ BLOCK LIMITS command.
4937c478bd9Sstevel@tonic-gate  */
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate #define	RBLSIZE	(sizeof (struct read_blklim))
4967c478bd9Sstevel@tonic-gate struct read_blklim {
4977c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL)
4987c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
4997c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
5007c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_LTOH)
5017c478bd9Sstevel@tonic-gate 	uchar_t granularity:	5;	/* Minimum Modularity */
5027c478bd9Sstevel@tonic-gate 	uchar_t	reserved:	3;	/* reserved */
5037c478bd9Sstevel@tonic-gate #endif
5047c478bd9Sstevel@tonic-gate 	uchar_t	max_hi;			/* Maximum block length, high byte */
5057c478bd9Sstevel@tonic-gate 	uchar_t	max_mid;		/* Maximum block length, middle byte */
5067c478bd9Sstevel@tonic-gate 	uchar_t	max_lo;			/* Maximum block length, low byte */
5077c478bd9Sstevel@tonic-gate 	uchar_t	min_hi;			/* Minimum block length, high byte */
5087c478bd9Sstevel@tonic-gate 	uchar_t	min_lo;			/* Minimum block length, low byte */
5097c478bd9Sstevel@tonic-gate };
5107c478bd9Sstevel@tonic-gate 
511f3531714Scz #ifdef _KERNEL
512f3531714Scz 
513f3531714Scz #if defined(__i386) || defined(__amd64)
514f3531714Scz /* Data structure used in big block I/O on x86/x64 platform */
515f3531714Scz 
516f3531714Scz /*
517f3531714Scz  * alloc more than one contig_mem, so mutiple I/O can be
518f3531714Scz  * on-going simultaneously
519f3531714Scz  */
520f3531714Scz #define	ST_MAX_CONTIG_MEM_NUM	3
521f3531714Scz 
522f3531714Scz /*
523f3531714Scz  * 60K is used due to the limitation(size) of the intermediate buffer
524f3531714Scz  * in DMA bind code(rootnex.c), which is 64K. If the I/O buf is page
525f3531714Scz  * aligned, HBA can do 64K DMA, but if not, HBA can only do
526f3531714Scz  * 64K - PAGESIZE = 60K DMA due to the copy to/from intermediate
527f3531714Scz  * buffer will keep the page offset.
528f3531714Scz  */
529f3531714Scz #define	ST_BIGBLK_XFER		60 * 1024
530f3531714Scz struct contig_mem {
531f3531714Scz 	struct contig_mem *cm_next;
532f3531714Scz 	size_t cm_len;
533f3531714Scz 	caddr_t cm_addr;
534f3531714Scz 	ddi_acc_handle_t cm_acc_hdl;
535f3531714Scz 	struct buf *cm_bp;
536f3531714Scz 	int cm_use_sbuf;
537f3531714Scz };
538f3531714Scz #endif
539f3531714Scz 
540f3531714Scz #endif /* _KERNEL */
541f3531714Scz 
5427c478bd9Sstevel@tonic-gate /*
5437c478bd9Sstevel@tonic-gate  * Private info for scsi tapes. Pointed to by the un_private pointer
5447c478bd9Sstevel@tonic-gate  * of one of the SCSI_DEVICE chains.
5457c478bd9Sstevel@tonic-gate  */
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate struct scsi_tape {
5487c478bd9Sstevel@tonic-gate 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
5497c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
5507c478bd9Sstevel@tonic-gate 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
5517c478bd9Sstevel@tonic-gate 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
5527c478bd9Sstevel@tonic-gate 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
5537c478bd9Sstevel@tonic-gate 	struct	buf *un_sbufp;		/* for use in special io */
5547c478bd9Sstevel@tonic-gate 	char	*un_srqbufp;		/* sense buffer for special io */
5557c478bd9Sstevel@tonic-gate 	kcondvar_t un_clscv;		/* closing cv */
5567c478bd9Sstevel@tonic-gate 	struct	buf *un_quef;		/* head of wait queue */
5577c478bd9Sstevel@tonic-gate 	struct	buf *un_quel;		/* tail of wait queue */
5587c478bd9Sstevel@tonic-gate 	struct	buf *un_runqf;		/* head of run queue */
5597c478bd9Sstevel@tonic-gate 	struct	buf *un_runql;		/* tail of run queue */
5607c478bd9Sstevel@tonic-gate 	struct seq_mode *un_mspl;	/* ptr to mode select info */
5617c478bd9Sstevel@tonic-gate 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
5627c478bd9Sstevel@tonic-gate 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
5637c478bd9Sstevel@tonic-gate 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
5647c478bd9Sstevel@tonic-gate 	daddr_t	un_blkno;		/* block # in file (512 byte blocks) */
5657c478bd9Sstevel@tonic-gate 	int	un_oflags;		/* open flags */
5667c478bd9Sstevel@tonic-gate 	int	un_fileno;		/* current file number on tape */
5677c478bd9Sstevel@tonic-gate 	int	un_err_fileno;		/* file where error occurred */
5687c478bd9Sstevel@tonic-gate 	daddr_t	un_err_blkno;		/* block in file where err occurred */
5697c478bd9Sstevel@tonic-gate 	uint_t	un_err_resid;		/* resid from last error */
5707c478bd9Sstevel@tonic-gate 	short	un_fmneeded;		/* filemarks to be written - HP only */
5717c478bd9Sstevel@tonic-gate 	dev_t	un_dev;			/* unix device */
5727c478bd9Sstevel@tonic-gate 	uchar_t	un_attached;		/* unit known && attached */
5737c478bd9Sstevel@tonic-gate 	int	un_pwr_mgmt;		/* power management state */
5747c478bd9Sstevel@tonic-gate 	uchar_t	un_density_known;	/* density is known */
5757c478bd9Sstevel@tonic-gate 	uchar_t	un_curdens;		/* index into density table */
5767c478bd9Sstevel@tonic-gate 	uchar_t	un_lastop;		/* last I/O was: read/write/ctl */
5777c478bd9Sstevel@tonic-gate 	uchar_t	un_eof;			/* eof states */
5787c478bd9Sstevel@tonic-gate 	uchar_t	un_laststate;		/* last state */
5797c478bd9Sstevel@tonic-gate 	uchar_t	un_state;		/* current state */
5807c478bd9Sstevel@tonic-gate 	uchar_t	un_status;		/* status from last sense */
5817c478bd9Sstevel@tonic-gate 	uchar_t	un_retry_ct;		/* retry count */
5827c478bd9Sstevel@tonic-gate 	uchar_t	un_tran_retry_ct;	/* transport retry count */
5837c478bd9Sstevel@tonic-gate 	uchar_t	un_read_only;		/* 1 == opened O_RDONLY */
5847c478bd9Sstevel@tonic-gate 	uchar_t	un_test_append;		/* check writing at end of tape */
5857c478bd9Sstevel@tonic-gate 	uchar_t un_arq_enabled;		/* auto request sense enabled */
5867c478bd9Sstevel@tonic-gate 	uchar_t un_untagged_qing;	/* hba has untagged quing */
5877c478bd9Sstevel@tonic-gate 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
5887c478bd9Sstevel@tonic-gate 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
5897c478bd9Sstevel@tonic-gate 	uchar_t	un_ncmds;		/* number of commands outstanding */
5907c478bd9Sstevel@tonic-gate 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
5917c478bd9Sstevel@tonic-gate 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
5927c478bd9Sstevel@tonic-gate 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
5937c478bd9Sstevel@tonic-gate 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
5947c478bd9Sstevel@tonic-gate 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
5957c478bd9Sstevel@tonic-gate 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
5967c478bd9Sstevel@tonic-gate 					/* check condidtion or error */
5977c478bd9Sstevel@tonic-gate 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
5987c478bd9Sstevel@tonic-gate 	uint_t	un_last_resid;		/* keep last resid, for PE */
5997c478bd9Sstevel@tonic-gate 	uint_t	un_last_count;		/* keep last count, for PE */
6007c478bd9Sstevel@tonic-gate 	struct 	kstat *un_stats;	/* for I/O statistics */
6017c478bd9Sstevel@tonic-gate 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
6027c478bd9Sstevel@tonic-gate 	struct	buf *un_wf;		/* head of write queue */
6037c478bd9Sstevel@tonic-gate 	struct	buf *un_wl;		/* tail of write queue */
6047c478bd9Sstevel@tonic-gate 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
6057c478bd9Sstevel@tonic-gate 	int	un_maxdma;		/* max dma xfer allowed by HBA */
6067c478bd9Sstevel@tonic-gate 	uint_t	un_bsize;		/* block size currently being used */
6077c478bd9Sstevel@tonic-gate 	int	un_maxbsize;		/* max block size allowed by drive */
6087c478bd9Sstevel@tonic-gate 	uint_t	un_minbsize;		/* min block size allowed by drive */
6097c478bd9Sstevel@tonic-gate 	int	un_errno;		/* errno (b_error) */
6107c478bd9Sstevel@tonic-gate 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
6117c478bd9Sstevel@tonic-gate 	enum mtio_state	un_mediastate;	/* current media state */
6127c478bd9Sstevel@tonic-gate 	enum mtio_state	un_specified_mediastate;	/* expected state */
6137c478bd9Sstevel@tonic-gate 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
6147c478bd9Sstevel@tonic-gate 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
6157c478bd9Sstevel@tonic-gate 	opaque_t	un_swr_token;	/* scsi_watch request token */
6167c478bd9Sstevel@tonic-gate 	uchar_t	un_comp_page;		/* compression page */
6177c478bd9Sstevel@tonic-gate 	uchar_t	un_rsvd_status;		/* Reservation Status */
6187c478bd9Sstevel@tonic-gate 	kstat_t *un_errstats;		/* for error statistics */
6197c478bd9Sstevel@tonic-gate 	int	un_init_options;  	/* Init time drive options */
6207c478bd9Sstevel@tonic-gate 	int	un_save_fileno;		/* Save here for recovery */
6217c478bd9Sstevel@tonic-gate 	daddr_t	un_save_blkno;		/* Save here for recovery */
6227c478bd9Sstevel@tonic-gate 	uchar_t	un_restore_pos;		/* Indication to do recovery */
6237c478bd9Sstevel@tonic-gate 	int	un_suspend_fileno;	/* Save fileno for SUSPEND */
6247c478bd9Sstevel@tonic-gate 	daddr_t	un_suspend_blkno;	/* Save blkno for SUSPEND */
6257c478bd9Sstevel@tonic-gate 	uchar_t	un_silent_skip;		/* to catch short reads */
6267c478bd9Sstevel@tonic-gate 	short	un_tids_at_suspend; /* timeouts set at suspend */
6277c478bd9Sstevel@tonic-gate 	kcondvar_t	un_tape_busy_cv;	/* busy cv */
6287c478bd9Sstevel@tonic-gate 	kcondvar_t	un_suspend_cv;	/* busy cv */
6297c478bd9Sstevel@tonic-gate 					/* restore on close */
6307c478bd9Sstevel@tonic-gate 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
6317c478bd9Sstevel@tonic-gate 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
6327c478bd9Sstevel@tonic-gate 	uchar_t	un_rqs_state;		/* see define below */
6337c478bd9Sstevel@tonic-gate 	caddr_t	un_uscsi_rqs_buf;	/* uscsi_rqs: buffer for RQS data */
6347c478bd9Sstevel@tonic-gate 	uchar_t	un_data_mod;		/* Device required data mod */
635f3531714Scz 
636f3531714Scz #if defined(__i386) || defined(__amd64)
637f3531714Scz 	ddi_dma_handle_t un_contig_mem_hdl;
638f3531714Scz 	struct contig_mem *un_contig_mem;
639f3531714Scz 	int un_contig_mem_available_num;
640f3531714Scz 	int un_contig_mem_total_num;
641a7333962Scz 	size_t un_max_contig_mem_len;
642f3531714Scz 	kcondvar_t un_contig_mem_cv;
643f3531714Scz #endif
6447c478bd9Sstevel@tonic-gate };
6457c478bd9Sstevel@tonic-gate /*
6467c478bd9Sstevel@tonic-gate  * device error kstats
6477c478bd9Sstevel@tonic-gate  */
6487c478bd9Sstevel@tonic-gate struct st_errstats {
6497c478bd9Sstevel@tonic-gate 	struct kstat_named	st_softerrs;
6507c478bd9Sstevel@tonic-gate 	struct kstat_named	st_harderrs;
6517c478bd9Sstevel@tonic-gate 	struct kstat_named	st_transerrs;
6527c478bd9Sstevel@tonic-gate 	struct kstat_named	st_vid;
6537c478bd9Sstevel@tonic-gate 	struct kstat_named	st_pid;
6547c478bd9Sstevel@tonic-gate 	struct kstat_named	st_revision;
6557c478bd9Sstevel@tonic-gate 	struct kstat_named	st_serial;
6567c478bd9Sstevel@tonic-gate };
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate /*
6597c478bd9Sstevel@tonic-gate  * generic log page struct
6607c478bd9Sstevel@tonic-gate  */
6617c478bd9Sstevel@tonic-gate struct log_page {
6627c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
6637c478bd9Sstevel@tonic-gate 	uchar_t	code	:6,	/* page code number */
6647c478bd9Sstevel@tonic-gate 			:2;	/* reserved */
6657c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
6667c478bd9Sstevel@tonic-gate 	uchar_t		:2,	/* reserved */
6677c478bd9Sstevel@tonic-gate 		code	:6;	/* page code number */
6687c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
6697c478bd9Sstevel@tonic-gate 	uchar_t	reserved;	/* reserved */
6707c478bd9Sstevel@tonic-gate 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
6717c478bd9Sstevel@tonic-gate 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
6727c478bd9Sstevel@tonic-gate 	/*
6737c478bd9Sstevel@tonic-gate 	 * Log parameters follow right after this...
6747c478bd9Sstevel@tonic-gate 	 */
6757c478bd9Sstevel@tonic-gate };
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate /*
6787c478bd9Sstevel@tonic-gate  * generic log page parameter struct
6797c478bd9Sstevel@tonic-gate  */
6807c478bd9Sstevel@tonic-gate struct log_param {
6817c478bd9Sstevel@tonic-gate 	uchar_t	pc_hi;			/* parameter code (msb) */
6827c478bd9Sstevel@tonic-gate 	uchar_t	pc_lo;			/* parameter code (lsb) */
6837c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
6847c478bd9Sstevel@tonic-gate 	uchar_t		lp	: 1,	/* list parameter */
6857c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
6867c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
6877c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
6887c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
6897c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
6907c478bd9Sstevel@tonic-gate 			du	: 1;	/* disable update */
6917c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
6927c478bd9Sstevel@tonic-gate 	uchar_t		du	: 1,	/* disable update */
6937c478bd9Sstevel@tonic-gate 			ds	: 1,	/* disable save */
6947c478bd9Sstevel@tonic-gate 			tsd	: 1,	/* target save disable */
6957c478bd9Sstevel@tonic-gate 			etc	: 1,	/* enable threshold comparison */
6967c478bd9Sstevel@tonic-gate 			tmc	: 2,	/* threshold met criteria */
6977c478bd9Sstevel@tonic-gate 				: 1,	/* reserved */
6987c478bd9Sstevel@tonic-gate 			lp	: 1;	/* list parameter */
6997c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
7007c478bd9Sstevel@tonic-gate 	uchar_t	length;		/* length of bytes to follow */
7017c478bd9Sstevel@tonic-gate 	/*
7027c478bd9Sstevel@tonic-gate 	 * Parameter values follow right after this...
7037c478bd9Sstevel@tonic-gate 	 */
7047c478bd9Sstevel@tonic-gate };
7057c478bd9Sstevel@tonic-gate /*
7067c478bd9Sstevel@tonic-gate  * TapeAlert structures
7077c478bd9Sstevel@tonic-gate  */
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate struct st_tape_alert_parameter {
7107c478bd9Sstevel@tonic-gate 	struct log_param log_param;
7117c478bd9Sstevel@tonic-gate 	uchar_t	param_value;
7127c478bd9Sstevel@tonic-gate };
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate struct st_tape_alert {
7157c478bd9Sstevel@tonic-gate 	struct log_page log_page;
7167c478bd9Sstevel@tonic-gate 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
7177c478bd9Sstevel@tonic-gate };
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate #define	TAPE_ALERT_PARAMETER_LENGTH \
7207c478bd9Sstevel@tonic-gate 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate struct log_sequential_page_parameter {
7237c478bd9Sstevel@tonic-gate 	struct log_param log_param;
7247c478bd9Sstevel@tonic-gate 	uchar_t param_value[8];
7257c478bd9Sstevel@tonic-gate };
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate struct log_sequential_page {
7287c478bd9Sstevel@tonic-gate 	struct log_page log_page;
7297c478bd9Sstevel@tonic-gate 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
7307c478bd9Sstevel@tonic-gate };
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate #if !defined(__lint)
7337c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
7347c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
7357c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
7367c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
7377c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
7387c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
7397c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("save sharing",
7407c478bd9Sstevel@tonic-gate 	scsi_tape::un_allow_large_xfer
7417c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxbsize
7427c478bd9Sstevel@tonic-gate 	scsi_tape::un_maxdma
7437c478bd9Sstevel@tonic-gate ))
7447c478bd9Sstevel@tonic-gate #endif
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate  * driver states..
7497c478bd9Sstevel@tonic-gate  */
7507c478bd9Sstevel@tonic-gate #define	ST_STATE_CLOSED				0
7517c478bd9Sstevel@tonic-gate #define	ST_STATE_OFFLINE			1
7527c478bd9Sstevel@tonic-gate #define	ST_STATE_INITIALIZING			2
7537c478bd9Sstevel@tonic-gate #define	ST_STATE_OPENING			3
7547c478bd9Sstevel@tonic-gate #define	ST_STATE_OPEN_PENDING_IO		4
7557c478bd9Sstevel@tonic-gate #define	ST_STATE_APPEND_TESTING			5
7567c478bd9Sstevel@tonic-gate #define	ST_STATE_OPEN				6
7577c478bd9Sstevel@tonic-gate #define	ST_STATE_RESOURCE_WAIT			7
7587c478bd9Sstevel@tonic-gate #define	ST_STATE_CLOSING			8
7597c478bd9Sstevel@tonic-gate #define	ST_STATE_SENSING			9
7607c478bd9Sstevel@tonic-gate #define	ST_STATE_CLOSE_PENDING_OPEN		10
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate /*
7637c478bd9Sstevel@tonic-gate  * Power management state
7647c478bd9Sstevel@tonic-gate  */
7657c478bd9Sstevel@tonic-gate #define	ST_PWR_NORMAL				0
7667c478bd9Sstevel@tonic-gate #define	ST_PWR_SUSPENDED			1
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate /*
7697c478bd9Sstevel@tonic-gate  * operation codes
7707c478bd9Sstevel@tonic-gate  */
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate #define	ST_OP_NIL	0
7737c478bd9Sstevel@tonic-gate #define	ST_OP_CTL	1
7747c478bd9Sstevel@tonic-gate #define	ST_OP_READ	2
7757c478bd9Sstevel@tonic-gate #define	ST_OP_WRITE	3
7767c478bd9Sstevel@tonic-gate #define	ST_OP_WEOF	4
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate /*
7797c478bd9Sstevel@tonic-gate  * eof/eot/eom codes.
7807c478bd9Sstevel@tonic-gate  */
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate #define	ST_NO_EOF		0x00
7837c478bd9Sstevel@tonic-gate #define	ST_EOF_PENDING		0x01	/* filemark pending */
7847c478bd9Sstevel@tonic-gate #define	ST_EOF			0x02	/* at filemark */
7857c478bd9Sstevel@tonic-gate #define	ST_EOT_PENDING		0x03	/* logical eot pending */
7867c478bd9Sstevel@tonic-gate #define	ST_EOT			0x04	/* at logical eot */
7877c478bd9Sstevel@tonic-gate #define	ST_EOM			0x05	/* at physical eot */
7887c478bd9Sstevel@tonic-gate #define	ST_WRITE_AFTER_EOM	0x06	/* flag for allowing writes after EOM */
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate #define	IN_EOF(un)	(un->un_eof == ST_EOF_PENDING || un->un_eof == ST_EOF)
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate /* un_rqs_state codes */
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
7957c478bd9Sstevel@tonic-gate #define	ST_RQS_VALID		0x2	/* RQS data is valid */
7967c478bd9Sstevel@tonic-gate #define	ST_RQS_READ		0x4	/* RQS data was read */
7977c478bd9Sstevel@tonic-gate #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate /*
8007c478bd9Sstevel@tonic-gate  * stintr codes
8017c478bd9Sstevel@tonic-gate  */
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate #define	COMMAND_DONE					0
8047c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_ERROR				1
8057c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_ERROR_RECOVERED			2
8067c478bd9Sstevel@tonic-gate #define	QUE_COMMAND					3
8077c478bd9Sstevel@tonic-gate #define	QUE_BUSY_COMMAND				4
8087c478bd9Sstevel@tonic-gate #define	QUE_SENSE					5
8097c478bd9Sstevel@tonic-gate #define	JUST_RETURN					6
8107c478bd9Sstevel@tonic-gate #define	COMMAND_DONE_EACCES				7
8117c478bd9Sstevel@tonic-gate #define	QUE_LAST_COMMAND				8
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate /*
8157c478bd9Sstevel@tonic-gate  *	Reservation Status
8167c478bd9Sstevel@tonic-gate  *
8177c478bd9Sstevel@tonic-gate  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
8187c478bd9Sstevel@tonic-gate  *		         in between opens and also to indicate the reservation
8197c478bd9Sstevel@tonic-gate  *		         has not been done till now.
8207c478bd9Sstevel@tonic-gate  * ST_RELEASE	        -Tape Unit is Released.
8217c478bd9Sstevel@tonic-gate  * ST_RESERVE	        -Tape Unit is Reserved.
8227c478bd9Sstevel@tonic-gate  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
8237c478bd9Sstevel@tonic-gate  *
8247c478bd9Sstevel@tonic-gate  */
8257c478bd9Sstevel@tonic-gate #define	ST_INIT_RESERVE			0x001
8267c478bd9Sstevel@tonic-gate #define	ST_RELEASE			0x002
8277c478bd9Sstevel@tonic-gate #define	ST_RESERVE			0x004
8287c478bd9Sstevel@tonic-gate #define	ST_PRESERVE_RESERVE		0x008
8297c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_CONFLICT 	0x010
8307c478bd9Sstevel@tonic-gate #define	ST_LOST_RESERVE			0x020
831*e213afc3Srralphs #define	ST_APPLICATION_RESERVATIONS	0x040
832*e213afc3Srralphs #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
833*e213afc3Srralphs 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
8347c478bd9Sstevel@tonic-gate 
835*e213afc3Srralphs /*
836*e213afc3Srralphs  * Service action defines for Persistant Reservation Commands
837*e213afc3Srralphs  */
838*e213afc3Srralphs #define	ST_SA_SCSI3_REGISTER			0x00
839*e213afc3Srralphs #define	ST_SA_SCSI3_RESERVE			0x01
840*e213afc3Srralphs #define	ST_SA_SCSI3_RELEASE			0x02
841*e213afc3Srralphs #define	ST_SA_SCSI3_CLEAR			0x03
842*e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPT			0x04
843*e213afc3Srralphs #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
844*e213afc3Srralphs #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
845*e213afc3Srralphs #define	ST_SA_MASK				0x1f
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate #define	ST_RESERVATION_DELAY		500000
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate /*
8507c478bd9Sstevel@tonic-gate  * Asynch I/O tunables
8517c478bd9Sstevel@tonic-gate  */
8527c478bd9Sstevel@tonic-gate #define	ST_MAX_THROTTLE		4
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate /*
8557c478bd9Sstevel@tonic-gate  * 60 minutes seems a reasonable amount of time
8567c478bd9Sstevel@tonic-gate  * to wait for tape space operations to complete.
8577c478bd9Sstevel@tonic-gate  *
8587c478bd9Sstevel@tonic-gate  */
8597c478bd9Sstevel@tonic-gate #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
8607c478bd9Sstevel@tonic-gate #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate /*
8637c478bd9Sstevel@tonic-gate  * 2 minutes seems a reasonable amount of time
8647c478bd9Sstevel@tonic-gate  * to wait for tape i/o operations to complete.
8657c478bd9Sstevel@tonic-gate  *
8667c478bd9Sstevel@tonic-gate  */
8677c478bd9Sstevel@tonic-gate #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
8687c478bd9Sstevel@tonic-gate #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate /*
8727c478bd9Sstevel@tonic-gate  * 10 seconds is what we'll wait if we get a Busy Status back
8737c478bd9Sstevel@tonic-gate  */
8747c478bd9Sstevel@tonic-gate #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
8757c478bd9Sstevel@tonic-gate #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
8767c478bd9Sstevel@tonic-gate #define	ST_INTERRUPT_CONTEXT	1
8777c478bd9Sstevel@tonic-gate #define	ST_START_CONTEXT	2
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate /*
8807c478bd9Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
8817c478bd9Sstevel@tonic-gate  *
8827c478bd9Sstevel@tonic-gate  * XXX This includes retries due to transport failure as well as
8837c478bd9Sstevel@tonic-gate  * XXX busy timeouts- Need to distinguish between Target and Transport
8847c478bd9Sstevel@tonic-gate  * XXX failure.
8857c478bd9Sstevel@tonic-gate  */
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate #define	ST_RETRY_COUNT		20
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate /*
8907c478bd9Sstevel@tonic-gate  * Number of times to retry a failed selection
8917c478bd9Sstevel@tonic-gate  */
8927c478bd9Sstevel@tonic-gate #define	ST_SEL_RETRY_COUNT		2
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate /*
8957c478bd9Sstevel@tonic-gate  * es_code value for deferred error
8967c478bd9Sstevel@tonic-gate  * should be moved to sense.h
8977c478bd9Sstevel@tonic-gate  */
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate #define	ST_DEFERRED_ERROR		0x01
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate /*
9027c478bd9Sstevel@tonic-gate  * Maximum number of units (determined by minor device byte)
9037c478bd9Sstevel@tonic-gate  */
9047c478bd9Sstevel@tonic-gate #define	ST_MAXUNIT	128
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate /*
9077c478bd9Sstevel@tonic-gate  * Time to wait for completion of a command before cancelling it.
9087c478bd9Sstevel@tonic-gate  * For SUSPEND use only
9097c478bd9Sstevel@tonic-gate  */
9107c478bd9Sstevel@tonic-gate #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate #ifndef	SECSIZE
9137c478bd9Sstevel@tonic-gate #define	SECSIZE	512
9147c478bd9Sstevel@tonic-gate #endif
9157c478bd9Sstevel@tonic-gate #ifndef	SECDIV
9167c478bd9Sstevel@tonic-gate #define	SECDIV	9
9177c478bd9Sstevel@tonic-gate #endif
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate /*
9207c478bd9Sstevel@tonic-gate  * convenient defines
9217c478bd9Sstevel@tonic-gate  */
9227c478bd9Sstevel@tonic-gate #define	ST_SCSI_DEVP	(un->un_sd)
9237c478bd9Sstevel@tonic-gate #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
9247c478bd9Sstevel@tonic-gate #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
9257c478bd9Sstevel@tonic-gate #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
9267c478bd9Sstevel@tonic-gate #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
9277c478bd9Sstevel@tonic-gate #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
9307c478bd9Sstevel@tonic-gate #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
9317c478bd9Sstevel@tonic-gate #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
9327c478bd9Sstevel@tonic-gate #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
9337c478bd9Sstevel@tonic-gate #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
9347c478bd9Sstevel@tonic-gate #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
9357c478bd9Sstevel@tonic-gate #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
9367c478bd9Sstevel@tonic-gate #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
9377c478bd9Sstevel@tonic-gate #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
9407c478bd9Sstevel@tonic-gate 	((un)->un_state == ST_STATE_SENSING && \
9417c478bd9Sstevel@tonic-gate 		(un)->un_laststate == ST_STATE_CLOSING))
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate #define	ASYNC_CMD	0
9447c478bd9Sstevel@tonic-gate #define	SYNC_CMD	1
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate /*
9477c478bd9Sstevel@tonic-gate  * Flush tape wait queue as needed.
9487c478bd9Sstevel@tonic-gate  */
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate #define	IS_PE_FLAG_SET(un) ((un)->un_persistence && (un)->un_persist_errors)
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate #define	TURN_PE_ON(un)		st_turn_pe_on(un)
9537c478bd9Sstevel@tonic-gate #define	TURN_PE_OFF(un)		st_turn_pe_off(un)
9547c478bd9Sstevel@tonic-gate #define	SET_PE_FLAG(un)		st_set_pe_flag(un)
9557c478bd9Sstevel@tonic-gate #define	CLEAR_PE(un)		st_clear_pe(un)
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate #define	st_bioerror(bp, error) \
9587c478bd9Sstevel@tonic-gate 		{ bioerror(bp, error); \
9597c478bd9Sstevel@tonic-gate 		un->un_errno = error; }
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate /*
9627c478bd9Sstevel@tonic-gate  * Macros for internal coding of count for SPACE command:
9637c478bd9Sstevel@tonic-gate  *
9647c478bd9Sstevel@tonic-gate  * Isfmk is 1 when spacing filemarks; 0 when spacing records:
9657c478bd9Sstevel@tonic-gate  * bit 24 set indicates a space filemark command.
9667c478bd9Sstevel@tonic-gate  * Fmk sets the filemark bit (24) and changes a backspace
9677c478bd9Sstevel@tonic-gate  * count into a positive number with the sign bit set.
9687c478bd9Sstevel@tonic-gate  * Blk changes a backspace count into a positive number with
9697c478bd9Sstevel@tonic-gate  * the sign bit set.
9707c478bd9Sstevel@tonic-gate  * space_cnt converts backwards counts to negative numbers.
9717c478bd9Sstevel@tonic-gate  */
9727c478bd9Sstevel@tonic-gate #define	Isfmk(x)	((x & (1<<24)) != 0)
9737c478bd9Sstevel@tonic-gate #define	Fmk(x)		((1<<24)|((x < 0) ? ((-(x)) | (1<<30)): x))
9747c478bd9Sstevel@tonic-gate #define	Blk(x)		((x < 0)? ((-(x))|(1<<30)): x)
9757c478bd9Sstevel@tonic-gate #define	space_cnt(x)	(((x) & (1<<30))? (-((x)&((1<<24)-1))):(x)&((1<<24)-1))
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate #define	GET_SOFT_STATE(dev)						\
9797c478bd9Sstevel@tonic-gate 	register struct scsi_tape *un;					\
9807c478bd9Sstevel@tonic-gate 	register int instance;						\
9817c478bd9Sstevel@tonic-gate 									\
9827c478bd9Sstevel@tonic-gate 	instance = MTUNIT(dev);						\
9837c478bd9Sstevel@tonic-gate 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
9847c478bd9Sstevel@tonic-gate 		return (ENXIO);
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate /*
9877c478bd9Sstevel@tonic-gate  * Debugging turned on via conditional compilation switch -DSTDEBUG
9887c478bd9Sstevel@tonic-gate  */
9897c478bd9Sstevel@tonic-gate #ifdef DEBUG
9907c478bd9Sstevel@tonic-gate #define	STDEBUG
9917c478bd9Sstevel@tonic-gate #endif
9927c478bd9Sstevel@tonic-gate 
9937c478bd9Sstevel@tonic-gate #ifdef	STDEBUG
9947c478bd9Sstevel@tonic-gate #define	DEBUGGING	((scsi_options & SCSI_DEBUG_TGT) || st_debug > 1)
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate #define	ST_DEBUG1	if (st_debug >= 1) scsi_log	/* initialization */
9987c478bd9Sstevel@tonic-gate #define	ST_DEBUG	ST_DEBUG1
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate #define	ST_DEBUG2	if (st_debug >= 2) scsi_log	/* errors and UA's */
10017c478bd9Sstevel@tonic-gate #define	ST_DEBUG3	if (st_debug >= 3) scsi_log	/* func calls */
10027c478bd9Sstevel@tonic-gate #define	ST_DEBUG4	if (st_debug >= 4) scsi_log	/* ioctl calls */
10037c478bd9Sstevel@tonic-gate #define	ST_DEBUG5	if (st_debug >= 5) scsi_log
10047c478bd9Sstevel@tonic-gate #define	ST_DEBUG6	if (st_debug >= 6) scsi_log	/* full data tracking */
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate #define	ST_DEBUG_SP	if (st_debug == 10) scsi_log	/* special cases */
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate #else
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate #define	st_debug	(0)
10117c478bd9Sstevel@tonic-gate #define	DEBUGGING	(0)
10127c478bd9Sstevel@tonic-gate #define	ST_DEBUG	if (0) scsi_log
10137c478bd9Sstevel@tonic-gate #define	ST_DEBUG1	if (0) scsi_log
10147c478bd9Sstevel@tonic-gate #define	ST_DEBUG2	if (0) scsi_log
10157c478bd9Sstevel@tonic-gate #define	ST_DEBUG3	if (0) scsi_log
10167c478bd9Sstevel@tonic-gate #define	ST_DEBUG4	if (0) scsi_log
10177c478bd9Sstevel@tonic-gate #define	ST_DEBUG5	if (0) scsi_log
10187c478bd9Sstevel@tonic-gate #define	ST_DEBUG6	if (0) scsi_log
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate #define	ST_DEBUG_SP	if (0) scsi_log /* special cases */
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate #endif
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate /*
10257c478bd9Sstevel@tonic-gate  * Media access values
10267c478bd9Sstevel@tonic-gate  */
10277c478bd9Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate /*
10307c478bd9Sstevel@tonic-gate  * SCSI tape mode sense page information
10317c478bd9Sstevel@tonic-gate  */
10327c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
10337c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
10347c478bd9Sstevel@tonic-gate #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
10357c478bd9Sstevel@tonic-gate #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate /*
10387c478bd9Sstevel@tonic-gate  * SCSI tape data compression Page definition.
10397c478bd9Sstevel@tonic-gate  */
10407c478bd9Sstevel@tonic-gate #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate /*
10457c478bd9Sstevel@tonic-gate  * maxbsize values
10467c478bd9Sstevel@tonic-gate  */
10477c478bd9Sstevel@tonic-gate #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate #define	ONE_MEG			(1024 * 1024)
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate /*
10527c478bd9Sstevel@tonic-gate  * generic soft error reporting
10537c478bd9Sstevel@tonic-gate  *
10547c478bd9Sstevel@tonic-gate  * What we are doing here is allowing a greater number of errors to occur on
10557c478bd9Sstevel@tonic-gate  * smaller transfers (i.e. usually at the beginning of the tape), than on
10567c478bd9Sstevel@tonic-gate  * the rest of the tape.
10577c478bd9Sstevel@tonic-gate  *
10587c478bd9Sstevel@tonic-gate  * A small transfer is defined as :
10597c478bd9Sstevel@tonic-gate  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
10607c478bd9Sstevel@tonic-gate  *
10617c478bd9Sstevel@tonic-gate  * A larget tranfer is defined as :
10627c478bd9Sstevel@tonic-gate  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
10637c478bd9Sstevel@tonic-gate  *
10647c478bd9Sstevel@tonic-gate  */
10657c478bd9Sstevel@tonic-gate #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
10667c478bd9Sstevel@tonic-gate #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate /*
10697c478bd9Sstevel@tonic-gate  * soft error reporting for exabyte
10707c478bd9Sstevel@tonic-gate  */
10717c478bd9Sstevel@tonic-gate #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate #define	SENSE_19_BITS  \
10747c478bd9Sstevel@tonic-gate 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
10757c478bd9Sstevel@tonic-gate #define	SENSE_20_BITS  \
10767c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
10777c478bd9Sstevel@tonic-gate #define	SENSE_21_BITS  \
10787c478bd9Sstevel@tonic-gate 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate /* these are defined in percentages */
10817c478bd9Sstevel@tonic-gate #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
10827c478bd9Sstevel@tonic-gate #define	EXABYTE_READ_ERROR_THRESHOLD	3
10837c478bd9Sstevel@tonic-gate /*
10847c478bd9Sstevel@tonic-gate  * minumum amount of data transfer(MB) for checking soft error rate.
10857c478bd9Sstevel@tonic-gate  */
10867c478bd9Sstevel@tonic-gate #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate #define	CLN	0x8
10897c478bd9Sstevel@tonic-gate #define	CLND	0x10
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate /*
10927c478bd9Sstevel@tonic-gate  * soft error reporting for Archive 4mm DAT
10937c478bd9Sstevel@tonic-gate  */
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate #define	LOG_SENSE_LENGTH		0xff
10967c478bd9Sstevel@tonic-gate #define	MIN_LOG_SENSE_LENGTH		0x2b
10977c478bd9Sstevel@tonic-gate #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
10987c478bd9Sstevel@tonic-gate #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
10997c478bd9Sstevel@tonic-gate #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
11007c478bd9Sstevel@tonic-gate #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate /*
11037c478bd9Sstevel@tonic-gate  * ST timeouts that need to be cancelled for suspend
11047c478bd9Sstevel@tonic-gate  */
11057c478bd9Sstevel@tonic-gate #define	ST_HIB_TID	0x01
11067c478bd9Sstevel@tonic-gate #define	ST_DELAY_TID	0x02
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
11097c478bd9Sstevel@tonic-gate }
11107c478bd9Sstevel@tonic-gate #endif
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1113