xref: /illumos-gate/usr/src/uts/common/sys/scsi/targets/stdef.h (revision e38a713ad4e0a9c42f8cccd9350412b2c6ccccdb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SCSI_TARGETS_STDEF_H
27 #define	_SYS_SCSI_TARGETS_STDEF_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/sunddi.h>
32 #include <sys/note.h>
33 #include <sys/condvar.h>
34 #include <sys/kstat.h>
35 #include <sys/int_limits.h>
36 #include <sys/scsi/scsi_types.h>
37 #include <sys/scsi/generic/sense.h>
38 #include <sys/mtio.h>
39 #include <sys/taskq.h>
40 #include <sys/taskq_impl.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Defines for SCSI tape drives.
48  */
49 
50 /*
51  * Maximum variable length record size for a single request
52  */
53 #define	ST_MAXRECSIZE_VARIABLE	65535
54 
55 /*
56  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
57  * then the following define is used.
58  */
59 #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
60 
61 #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
62 #define	INF 1000000000	/* old external count backwards from this from EOF */
63 #define	LASTBLK (-1)	/* new internal count backwards from EOF */
64 
65 /*
66  * Supported tape device types plus default type for opening.
67  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
68  * Types 14 - 1f, are 1/4-inch cartridge drives.
69  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
70  * Types 28+, are rdat (vcr) drives.
71  */
72 #define	ST_TYPE_INVALID		0x00
73 
74 #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
75 #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
76 
77 #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
78 #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
79 #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
80 #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
81 
82 #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
83 #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
84 #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
85 #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
86 #define	ST_TYPE_HP	MT_ISHP		/* HP */
87 #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
88 #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
89 #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
90 
91 #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
92 #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
93 #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
94 #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
95 #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
96 #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
97 #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
98 #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
99 #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
100 #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
101 #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
102 #define	ST_TYPE_AIT	MT_ISAIT	/* Sony AIT I, II, III and SAIT */
103 #define	ST_LAST_TYPE	ST_TYPE_AIT	/* Add new above type and change this */
104 
105 
106 /* Internal flags */
107 #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
108 					/* alloc'ed from the st.conf entry, */
109 					/* instead of being used from the */
110 					/* st_drivetypes array. */
111 
112 /*
113  * Defines for supported drive options
114  *
115  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
116  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
117  */
118 #define	ST_VARIABLE		0x001	/* Device supports variable	*/
119 					/* length record sizes		*/
120 #define	ST_QIC			0x002	/* QIC tape device 		*/
121 #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
122 #define	ST_BSF			0x008	/* Device supports backspace	*/
123 					/* file as in mt(1) bsf : 	*/
124 					/* backspace over EOF marks.	*/
125 					/* Devices not supporting bsf 	*/
126 					/* will fail with ENOTTY upon	*/
127 					/* use of bsf			*/
128 #define	ST_BSR			0x010	/* Device supports backspace	*/
129 					/* record as in mt(1) bsr :	*/
130 					/* backspace over records. If	*/
131 					/* the device does not support 	*/
132 					/* bsr, the st driver emulates	*/
133 					/* the action by rewinding the	*/
134 					/* tape and using forward space	*/
135 					/* file (fsf) to the correct	*/
136 					/* file and then uses forward	*/
137 					/* space record (fsr) to the	*/
138 					/* correct  record		*/
139 #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
140 					/* than normal to erase		*/
141 #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
142 					/* Device can figure out the	*/
143 					/* tape density automatically,	*/
144 					/* without issuing a		*/
145 					/* mode-select/mode-sense 	*/
146 #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
147 					/* This disables the device's	*/
148 					/* ability for buffered	writes	*/
149 					/* I.e. The device acknowledges	*/
150 					/* write completion after the	*/
151 					/* data is written to the	*/
152 					/* device's buffer, but before	*/
153 					/* all the data is actually	*/
154 					/* written to tape		*/
155 #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
156 					/* parity while talking to it. 	*/
157 #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
158 					/* of Data) has been reached.	*/
159 					/* If the device knows EOD, st	*/
160 					/* uses fast file skipping.	*/
161 					/* If it does not know EOD,	*/
162 					/* file skipping happens one	*/
163 					/* file at a time. 		*/
164 #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
165 					/* the st driver is unloaded &	*/
166 					/* loaded again; e.g. will	*/
167 					/* return the correct inquiry	*/
168 					/* string			*/
169 #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
170 					/* close to report soft errors.	*/
171 					/* Currently only Exabyte and	*/
172 					/* DAT drives support this	*/
173 					/* feature.  			*/
174 #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
175 					/* timeouts for normal		*/
176 					/* operation			*/
177 #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
178 					/* driver and pre-acked to the	*/
179 					/* application 			*/
180 #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
181 					/* devices only. If flag is	*/
182 					/* set, then don't limit	*/
183 					/* record size to 64k as in	*/
184 					/* pre-Solaris 2.4 releases.	*/
185 					/* The only limit on the	*/
186 					/* record size will be the max	*/
187 					/* record size the device can	*/
188 					/* handle or the max DMA	*/
189 					/* transfer size of the		*/
190 					/* machine, which ever is	*/
191 					/* smaller. Beware of		*/
192 					/* incompatabilities with	*/
193 					/* tapes of pre-Solaris 2.4	*/
194 					/* OS's written with large	*/
195 					/* (>64k) block sizes, as	*/
196 					/* their true block size is	*/
197 					/* a max of approx 64k		*/
198 #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
199 					/* configuration page (0x10) to */
200 					/* enable/disable compression	*/
201 					/* instead of density codes for */
202 					/* the "c" and "u" devices	*/
203 #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
204 					/* support RESERVE/RELEASE SCSI	*/
205 					/* command. If this is enabled	*/
206 					/* then reserve/release would	*/
207 					/* not be used during open/	*/
208 					/* close for High Availability	*/
209 #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
210 					/* to variable block devices 	*/
211 					/* which support the SILI bit	*/
212 					/* option. It indicates that 	*/
213 					/* the SILI bit will be ignored */
214 					/* during reads  		*/
215 #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
216 					/* EOF marks do not indicate an */
217 					/* EOM. This option is only	*/
218 					/* supported on 1/2" reel tapes */
219 #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
220 					/* EXABYTE 8mm tape drives 	*/
221 					/* which support short 		*/
222 					/* filemarks. When this flag 	*/
223 					/* is set, short filemarks 	*/
224 					/* will be used for writing	*/
225 					/* filemarks. 			*/
226 #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
227 					/* and the tape is trapped in   */
228 					/* the medium changer, the tape */
229 					/* is automatically ejected	*/
230 #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
231 					/* This option applies only to  */
232 					/* IBM MAGSTAR 3590. If this    */
233 					/* flag is set, the st driver   */
234 					/* will retry the last cmd if   */
235 					/* the last error cause a check */
236 					/* condition with error code    */
237 					/* 0x71 and sense code  0x01 	*/
238 #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
239 					/* detected to select correct   */
240 					/* density code.		*/
241 #define	ST_WORMABLE		0x1000000
242 					/* Drive is capable of doing	*/
243 					/* Write Appends only at EOM	*/
244 					/* if WORM media type is loaded */
245 #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
246 					/* the tape drive provides the	*/
247 					/* clean bit information in	*/
248 					/* byte 21, bitmask 0x08 of	*/
249 					/* Request Sense data		*/
250 #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
251 					/* the tape drive provides the	*/
252 					/* clean bit information in	*/
253 					/* byte 70, bitmask 0xc0 of	*/
254 					/* Request Sense data		*/
255 #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
256 					/* the tape drive provides the	*/
257 					/* clean bit information in	*/
258 					/* byte 18, bitmask 0x01 of	*/
259 					/* Request Sense data		*/
260 
261 #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
262 #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
263 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
264 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
265 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
266 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
267 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
268 	ST_WORMABLE | ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
269 
270 #define	NDENSITIES	MT_NDENSITIES
271 #define	NSPEEDS		MT_NSPEEDS
272 
273 /*
274  * defines for Log Sense Pages
275  */
276 #define	SUPPORTED_LOG_PAGES_PAGE	0x00
277 #define	TAPE_SEQUENTIAL_PAGE		0x0c
278 #define	TAPE_ALERT_PAGE			0x2e
279 
280 /*
281  * Log Page Control definitions
282  */
283 #define	CURRENT_THRESHOLD_VALUES	0x00
284 #define	CURRENT_CUMULATIVE_VALUES	0x40
285 #define	DEFAULT_THRESHOLD_VALUES	0x80
286 #define	DEFAULT_CUMULATIVE_VALUES	0xC0
287 
288 /*
289  * Tape Alert Flag definitions
290  */
291 typedef enum {
292 	TAF_READ_WARN			= 0x01,
293 	TAF_WRITE_WARN			= 0x02,
294 	TAF_HARD_ERR			= 0x03,
295 	TAF_MEDIA_ERR			= 0x04,
296 	TAF_READ_FAIL			= 0x05,
297 	TAF_WRITE_FAIL			= 0x06,
298 	TAF_MEDIA_LIFE			= 0x07,
299 	TAF_MEDIA_NOT_DATA_GRADE	= 0x08,
300 	TAF_WRITE_PROTECTED		= 0x09,
301 	TAF_NO_MEDIA_REMOVE		= 0x0A,
302 	TAF_CLEANING_MEDIA		= 0x0B,
303 	TAF_UNSUPPERTED_FORMAT		= 0x0C,
304 	TAF_RECOVERED_TAPE_BREAK	= 0x0D,
305 	TAF_TAPE_BREAK_FAUL		= 0x0E,
306 	TAF_CART_MEM_FAIL		= 0x0F,
307 	TAF_FORCED_EJECT		= 0x10,
308 	TAF_READ_ONLY_FORMAT		= 0x11,
309 	TAF_TAPE_DIR_CORRUPT		= 0x12,
310 	TAF_NEARING_MEDIA_LIFE		= 0x13,
311 	TAF_CLEAN_NOW			= 0x14,
312 	TAF_CLEAN_PERIODIC		= 0x15,
313 	TAF_EXP_CLEAN_CART		= 0x16,
314 	TAF_INVALID_CLEAN_MEDIA		= 0x17,
315 	TAF_RETENSION_REQUEST		= 0x18,
316 	TAF_DUAL_PORT_INTERFACE_ERR	= 0x19,
317 	TAF_COOLING_FAN_FAIL		= 0x1A,
318 	TAF_POWER_SUPPLY_FAIL		= 0x1B,
319 	TAF_POWER_CONSUMPTION		= 0x1C,
320 	TAF_DRIVE_MAINT_REQUEST		= 0x1D,
321 	TAF_HARDWARE_A			= 0x1E,
322 	TAF_HARDWARE_B			= 0x1F,
323 	TAF_INTERFACE			= 0x20,
324 	TAF_EJECT_MEDIA			= 0x21,
325 	TAF_DOWNLOAD_FAIL		= 0x22,
326 	TAF_DRIVE_HUMIDITY		= 0x23,
327 	TAF_DRIVE_TEMP			= 0x24,
328 	TAF_DRIVE_VOLTAGE		= 0x25,
329 	TAF_PREDICTIVE_FAIL		= 0x26,
330 	TAF_DIAG_REQUIRED		= 0x27,
331 	TAF_LOADER_HDWR_A		= 0x28,
332 	TAF_LOADER_STRAY_TAPE		= 0x29,
333 	TAF_LOADER_HDWR_B		= 0x2A,
334 	TAF_LOADER_DOOR			= 0x2B,
335 	TAF_LOADER_HDWR_C		= 0x2C,
336 	TAF_LOADER_MAGAZINE		= 0x2D,
337 	TAF_LOADER_PREDICTIVE_FAIL	= 0x2E,
338 	TAF_LOST_STATISTICS		= 0x32,
339 	TAF_TAPE_DIR_CURRUPT_UNLOAD	= 0x33,
340 	TAF_TAPE_SYS_WRT_FAIL		= 0x34,
341 	TAF_TAPE_SYS_RD_FAIL		= 0x35,
342 	TAF_NO_START_OF_DATA		= 0x36,
343 	TAF_WORM_INTEGRITY		= 0x3B,
344 	TAF_WORM_OVRWRT_ATTEMPT		= 0x3C
345 }tape_alert_flags;
346 
347 /*
348  * For ST_TYPE_STK9840 drives only. STK drive doesn't support retension
349  * so they reuse TAF_RETENSION_REQUEST.
350  */
351 #define	CLEAN_FOR_ERRORS		 0x18
352 
353 
354 #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
355 #define	TAPE_ALERT_NOT_SUPPORTED	0x01
356 #define	TAPE_ALERT_SUPPORTED		0x02
357 #define	TAPE_ALERT_STILL_DIRTY		0x04
358 #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
359 #define	TAPE_PREVIOUSLY_DIRTY		0x10
360 
361 #define	TAPE_ALERT_MAX_PARA		64
362 #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
363 #define	SEQUENTIAL_NEED_CLN		0x0100
364 
365 /*
366  * Parameters
367  */
368 #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
369 #define	VIDLEN		8	/* size of vendor identifier length */
370 #define	PIDLEN		16	/* size of product identifier length */
371 #define	VIDPIDLEN	(VIDLEN + PIDLEN)
372 
373 
374 struct st_drivetype {
375 	char	name[ST_NAMESIZE];	/* Name, for debug */
376 	char	length;			/* Length of vendor id */
377 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
378 	char	type;			/* Drive type for driver */
379 	int	bsize;			/* Block size */
380 	int	options;		/* Drive options */
381 	int	max_rretries;		/* Max read retries */
382 	int	max_wretries;		/* Max write retries */
383 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
384 	uchar_t	default_density;	/* default density for this drive */
385 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
386 	ushort_t non_motion_timeout;	/* Inquiry type commands */
387 	ushort_t io_timeout;		/* I/O timeout in seconds */
388 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
389 	ushort_t space_timeout;		/* space cmd timeout in seconds */
390 	ushort_t load_timeout;		/* load tape time in seconds */
391 	ushort_t unload_timeout;	/* unload tape time in seconds */
392 	ushort_t erase_timeout;		/* erase timeout. seconds */
393 };
394 
395 #define	MINUTES(val)	((val) * 60)
396 
397 struct comp_mode_page {
398 #if defined(_BIT_FIELDS_LTOH)
399 	uchar_t	:		6,
400 		dcc:		1,	/* Data Compression Capable */
401 		dce:		1;	/* Data Compression Enable */
402 	uchar_t	:		5,
403 		red:		2,	/* Report Exceptions on Decompress */
404 		dde:		1;	/* Data Decompression Enabled */
405 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
406 	uchar_t comp_alg_high;
407 	uchar_t	comp_alg_low;
408 	uchar_t	comp_alg_lsb;
409 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
410 	uchar_t decomp_alg_high;
411 	uchar_t	decomp_alg_low;
412 	uchar_t	decomp_alg_lsb;
413 	uchar_t	reservered0;
414 	uchar_t	reservered1;
415 	uchar_t	reservered2;
416 	uchar_t	reservered3;
417 
418 #elif defined(_BIT_FIELDS_HTOL)
419 	uchar_t	dce:		1,	/* Data Compression Enable */
420 		dcc:		1,	/* Data Compression Capable */
421 		:		6;
422 	uchar_t	dde:		1,	/* Data Decompression Enabled */
423 		red:		2,	/* Report Exceptions on Decompress */
424 		:		5;
425 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
426 	uchar_t comp_alg_high;
427 	uchar_t	comp_alg_low;
428 	uchar_t	comp_alg_lsb;
429 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
430 	uchar_t decomp_alg_high;
431 	uchar_t	decomp_alg_low;
432 	uchar_t	decomp_alg_lsb;
433 	uchar_t	reservered0;
434 	uchar_t	reservered1;
435 	uchar_t	reservered2;
436 	uchar_t	reservered3;
437 #endif
438 };
439 
440 struct dev_mode_page {
441 #if defined(_BIT_FIELDS_LTOH)
442 	uchar_t	act_format:	5,	/* active format */
443 		caf:		1,	/* Change Active Format */
444 		cap:		1,	/* Change Active Partition OBSOLETE */
445 		:		1;
446 	uchar_t	act_partition;		/* active partition */
447 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
448 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
449 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
450 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
451 	uchar_t	rew:		1,	/* Report Early Warning */
452 		robo:		1,	/* Reverse Object Buffer Order */
453 		socf:		2,	/* Stop On Consecutive Filemarks */
454 		avc:		1,	/* Automatic Velocity Control */
455 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
456 		lois:		1,	/* Logical Object Identifiers Support */
457 		obr:		1;	/* Object Buffer Recovery */
458 	uchar_t	gap_size;		/* OBSOLETE */
459 	uchar_t	bam:		1,	/* Block Address Mode */
460 		bmal:		1,	/* Block Address Mode Lock */
461 		swp:		1,	/* Software Write Protection */
462 		sew:		1,	/* Sync data after Early Warning */
463 		eeg:		1,	/* Enable Early Waring */
464 		eod_defined:	3;
465 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
466 	uchar_t	buf_size_leot_mid;
467 	uchar_t	buf_size_leot_lsb;
468 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
469 	uchar_t	prmwp:		1,	/* PeRManent Write Protect */
470 		perswp:		1,	/* persistant write protection */
471 		asocwp:		1,	/* associated write protect */
472 		rew_on_rst:	2,	/* rewind on reset */
473 		oir:		1,	/* Only If Reserved */
474 		wtre:		2;	/* Worm Tamper Read Enable */
475 
476 #elif defined(_BIT_FIELDS_HTOL)
477 	uchar_t	:		1,
478 		cap:		1,	/* Change Active Partition OBSOLETE */
479 		caf:		1,	/* Change Active Format */
480 		act_format:	5;	/* active format */
481 	uchar_t	act_partition;		/* active partition */
482 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
483 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
484 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
485 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
486 	uchar_t	obr:		1,	/* Object Buffer Recovery */
487 		lois:		1,	/* Logical Object Identifiers Support */
488 		rsmk:		1,	/* Report SetMarKs OBSOLETE */
489 		avc:		1,	/* Automatic Velocity Control */
490 		socf:		2,	/* Stop On Consecutive Filemarks */
491 		robo:		1,	/* Reverse Object Buffer Order */
492 		rew:		1;	/* Report Early Warning */
493 	uchar_t	gap_size;		/* OBSELETE */
494 	uchar_t	eod_defined:	3,
495 		eeg:		1,	/* Enable Early Waring */
496 		sew:		1,	/* Sync data after Early Warning */
497 		swp:		1,	/* Software Write Protection */
498 		bmal:		1,	/* Block Address Mode Lock */
499 		bam:		1;	/* Block Address Mode */
500 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
501 	uchar_t	buf_size_leot_mid;
502 	uchar_t	buf_size_leot_lsb;
503 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
504 	uchar_t	wtre:		2,	/* Worm Tamper Read Enable */
505 		oir:		1,	/* Only If Reserved */
506 		rew_on_rst:	2,	/* rewind on reset */
507 		asocwp:		1,	/* associated write protect */
508 		perswp:		1,	/* persistant write protection */
509 		prmwp:		1;	/* PeRManent Write Protect */
510 #endif
511 };
512 
513 typedef union {
514 	struct comp_mode_page	comp;
515 	struct dev_mode_page	dev;
516 }modepage;
517 
518 /*
519  *
520  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
521  * The parameter list contains a header, followed by zero or more
522  * block descriptors, followed by vendor unique parameters, if any.
523  *
524  */
525 #define	MSIZE	0x0c		/* Size without additional pages */
526 struct seq_mode {
527 #if defined(_BIT_FIELDS_LTOH)
528 	uchar_t	data_len;	/* sense data length, sense only */
529 	uchar_t	media_type;	/* medium type, sense only */
530 	uchar_t	speed	:4,	/* speed */
531 		bufm	:3,	/* buffered mode */
532 		wp	:1;	/* write protected, sense only */
533 	uchar_t	bd_len;		/* block length in bytes */
534 	uchar_t	density;	/* density code */
535 	uchar_t	high_nb;	/* number of logical blocks on the medium */
536 	uchar_t	mid_nb;		/* that are to be formatted with the density */
537 	uchar_t	low_nb;		/* code and block length in block descriptor */
538 	uchar_t	reserved;	/* reserved */
539 	uchar_t	high_bl;	/* block length */
540 	uchar_t	mid_bl;		/*   "      "   */
541 	uchar_t	low_bl;		/*   "      "   */
542 	uchar_t page_code:	6,
543 		:		1,
544 		ps:		1; /* Page Savable sense only */
545 	uchar_t	page_len;
546 	modepage page;
547 
548 #elif defined(_BIT_FIELDS_HTOL)
549 	uchar_t	data_len;	/* sense data length, sense only */
550 	uchar_t	media_type;	/* medium type, sense only */
551 	uchar_t	wp	:1,	/* write protected, sense only */
552 		bufm	:3,	/* buffered mode */
553 		speed	:4;	/* speed */
554 	uchar_t	bd_len;		/* block length in bytes */
555 	uchar_t	density;	/* density code */
556 	uchar_t	high_nb;	/* number of logical blocks on the medium */
557 	uchar_t	mid_nb;		/* that are to be formatted with the density */
558 	uchar_t	low_nb;		/* code and block length in block descriptor */
559 	uchar_t	reserved;	/* reserved */
560 	uchar_t	high_bl;	/* block length */
561 	uchar_t	mid_bl;		/*   "      "   */
562 	uchar_t	low_bl;		/*   "      "   */
563 	uchar_t	ps:		1, /* Page Savable sense only */
564 		:		1,
565 		page_code:	6;
566 	uchar_t	page_len;
567 	modepage page;
568 #else
569 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
570 #endif	/* _BIT_FIELDS_LTOH */
571 };
572 
573 /*
574  * One_command parameter data for REPORT SUPPORTED OPERATION CODES.
575  */
576 struct one_com_des {
577 #if defined(_BIT_FIELDS_LTOH)
578 	uchar_t reserved0;
579 	uchar_t support:	3,	/* support value */
580 		reserved1:	4,
581 		ctdp:		1;	/* cmd timeouts descriptor present */
582 	ushort_t cdb_size;		/* cdb size */
583 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
584 #elif defined(_BIT_FIELDS_HTOL)
585 	uchar_t reserved0;
586 	uchar_t ctdp:		1,	/* cmd timeouts descriptor present */
587 		reserved1:	4,
588 		support:	3;	/* support value */
589 	ushort_t cdb_size;		/* cdb size */
590 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
591 #else
592 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
593 #endif /* _BIT_FIELDS_LTOH */
594 };
595 
596 /*
597  * Command timeouts descriptor
598  */
599 struct com_timeout_des {
600 	ushort_t des_len;	/* descriptor length */
601 	uchar_t reserved;
602 	uchar_t com_spe;	/* command specific */
603 	uint_t nom_timeout;	/* nominal command processing timeout */
604 	uint_t rec_timeout;	/* recommended command timeout */
605 };
606 
607 /*
608  * Reporting options
609  */
610 #define	ALL_COMMAND_DATA_FORMAT			0
611 #define	ONE_COMMAND_NO_SERVICE_DATA_FORMAT	1
612 #define	ONE_COMMAND_DATA_FORMAT			2
613 
614 /*
615  * Support values in One_command parameter data
616  */
617 #define	SUPPORT_VALUES_NOT_AVAILABLE		0
618 #define	SUPPORT_VALUES_NOT_SUPPORT		1
619 #define	SUPPORT_VALUES_SUPPORT_SCSI		3
620 #define	SUPPORT_VALUES_SUPPORT_VENDOR		5
621 
622 /*
623  * Parameter data for REPORT DENSITY SUPPORT command
624  */
625 struct report_density_header {
626 	ushort_t ava_dens_len;		/* available density support length */
627 	uchar_t reserved0;
628 	uchar_t reserved1;
629 };
630 
631 struct report_density_desc {
632 #if defined(_BIT_FIELDS_LTOH)
633 	uchar_t pri_den;		/* primary density code */
634 	uchar_t sec_den;		/* secondary density code */
635 	uchar_t dlv:1;			/* descriptor length valid */
636 	uchar_t reserved:4;
637 	uchar_t deflt:1;		/* is default density */
638 	uchar_t dup:1;			/* pri density has one descriptor */
639 	uchar_t wrtok:1;		/* support writing to media */
640 	uchar_t desc_len_hi;		/* descriptor length high */
641 	uchar_t desc_len_low;		/* descriptor length low */
642 	uchar_t bits_per_mm[3];		/* bits per mm */
643 	uchar_t media_width_hi;		/* media width high */
644 	uchar_t media_width_low;	/* media width low */
645 	ushort_t tracks;		/* tracks */
646 	uint_t capacity;		/* capacity */
647 	uchar_t ass_org[8];		/* assigning organization */
648 	uchar_t den_name[8];		/* density name */
649 	uchar_t description[20];	/* description */
650 #elif defined(_BIT_FIELDS_HTOL)
651 	uchar_t pri_den;		/* primary density code */
652 	uchar_t sec_den;		/* secondary density code */
653 	uchar_t wrtok:1;		/* support writing to media */
654 	uchar_t dup:1;			/* pri density has one descriptor */
655 	uchar_t deflt:1;		/* is default density */
656 	uchar_t reserved:4;
657 	uchar_t dlv:1;			/* descriptor length valid */
658 	uchar_t desc_len_hi;		/* descriptor length high */
659 	uchar_t desc_len_low;		/* descriptor length low */
660 	uchar_t bits_per_mm[3];		/* bits per mm */
661 	uchar_t media_width_hi;		/* media width high */
662 	uchar_t media_width_low;	/* media width low */
663 	ushort_t tracks;		/* tracks */
664 	uint_t capacity;		/* capacity */
665 	uchar_t ass_org[8];		/* assigning organization */
666 	uchar_t den_name[8];		/* density name */
667 	uchar_t description[20];	/* description */
668 #else
669 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
670 #endif  /* _BIT_FIELDS_LTOH */
671 };
672 
673 /*
674  * Data returned from the READ BLOCK LIMITS command.
675  */
676 
677 #define	RBLSIZE	(sizeof (struct read_blklim))
678 struct read_blklim {
679 #if defined(_BIT_FIELDS_HTOL)
680 	uchar_t	reserved:	3;	/* reserved */
681 	uchar_t granularity:	5;	/* Minimum Modularity */
682 #elif defined(_BIT_FIELDS_LTOH)
683 	uchar_t granularity:	5;	/* Minimum Modularity */
684 	uchar_t	reserved:	3;	/* reserved */
685 #endif
686 	uchar_t	max_hi;			/* Maximum block length, high byte */
687 	uchar_t	max_mid;		/* Maximum block length, middle byte */
688 	uchar_t	max_lo;			/* Maximum block length, low byte */
689 	uchar_t	min_hi;			/* Minimum block length, high byte */
690 	uchar_t	min_lo;			/* Minimum block length, low byte */
691 };
692 
693 /*
694  * operation codes
695  */
696 typedef enum {
697 	ST_OP_NIL,
698 	ST_OP_CTL,
699 	ST_OP_READ,
700 	ST_OP_WRITE,
701 	ST_OP_WEOF
702 }optype;
703 
704 /*
705  * eof/eot/eom codes.
706  */
707 typedef enum {
708 	ST_NO_EOF,
709 	ST_EOF_PENDING,		/* filemark pending */
710 	ST_EOF,			/* at filemark */
711 	ST_EOT_PENDING,		/* logical eot pending */
712 	ST_EOT,			/* at logical eot */
713 	ST_EOM,			/* at physical eot */
714 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
715 }pstatus;
716 
717 typedef enum { invalid, legacy, logical } posmode;
718 
719 typedef struct tapepos {
720 	uint64_t lgclblkno;
721 	int32_t fileno;
722 	int32_t blkno;
723 	int32_t partition;
724 	pstatus eof;			/* eof states */
725 	posmode	pmode;
726 	uint32_t: 32;
727 }tapepos_t;
728 
729 /* byte 1 of cdb for type of read position command */
730 typedef enum {
731 	SHORT_POS	= 0,
732 	LONG_POS	= 6,
733 	EXT_POS		= 8,
734 	NO_POS		= 0xff	/* Drive doesn't support read position */
735 } read_p_types;
736 
737 
738 /*
739  * Data returned from the READ POSITION command.
740  */
741 
742 typedef struct tape_position {
743 #if defined(_BIT_FIELDS_HTOL)
744 	uchar_t begin_of_part:	1;
745 	uchar_t end_of_part:	1;
746 	uchar_t blk_cnt_unkwn:	1;
747 	uchar_t byte_cnt_unkwn:	1;
748 	uchar_t reserved0:	1;
749 	uchar_t blk_posi_unkwn:	1;
750 	uchar_t posi_err:	1;
751 	uchar_t reserved1:	1;
752 #elif defined(_BIT_FIELDS_LTOH)
753 	uchar_t reserved1:	1;
754 	uchar_t posi_err:	1;
755 	uchar_t blk_posi_unkwn:	1;
756 	uchar_t reserved0:	1;
757 	uchar_t byte_cnt_unkwn:	1;
758 	uchar_t blk_cnt_unkwn:	1;
759 	uchar_t end_of_part:	1;
760 	uchar_t begin_of_part:	1;
761 #endif
762 	uchar_t partition_number;
763 	uchar_t reserved2[2];
764 	uint32_t host_block;
765 	uint32_t media_block;
766 	uchar_t reserved3;
767 	uchar_t block_in_buff[3];
768 	uint32_t byte_in_buff;
769 }tape_position_t;
770 
771 
772 typedef struct tape_position_long {
773 #if defined(_BIT_FIELDS_HTOL)
774 	uint32_t begin_of_part:	1;
775 	uint32_t end_of_part:	1;
776 	uint32_t reserved0:	2;
777 	uint32_t mrk_posi_unkwn:1;
778 	uint32_t blk_posi_unkwn:1;
779 	uint32_t reserved1:	2;
780 #elif defined(_BIT_FIELDS_LTOH)
781 	uint32_t reserved1:	2;
782 	uint32_t blk_posi_unkwn:1;
783 	uint32_t mrk_posi_unkwn:1;
784 	uint32_t reserved0:	2;
785 	uint32_t end_of_part:   1;
786 	uint32_t begin_of_part: 1;
787 #endif
788 	uint32_t reserved2:	24;
789 	uint32_t partition;
790 	uint64_t block_number;
791 	uint64_t file_number;
792 	uint64_t set_number;
793 }tape_position_long_t;
794 
795 typedef struct tape_position_ext {
796 #if defined(_BIT_FIELDS_HTOL)
797 	uchar_t begin_of_part:	1;
798 	uchar_t end_of_part:	1;
799 	uchar_t blk_cnt_unkwn:	1;
800 	uchar_t byte_cnt_unkwn:	1;
801 	uchar_t mrk_posi_unkwn:	1;
802 	uchar_t blk_posi_unkwn:	1;
803 	uchar_t posi_err:	1;
804 	uchar_t reserved0:	1;
805 
806 	uchar_t partition;
807 	uint16_t parameter_len;
808 /* start next word */
809 	uint32_t reserved1:	8;
810 	uint32_t blks_in_buf:	24;
811 #elif defined(_BIT_FIELDS_LTOH)
812 	uchar_t reserved0:	1;
813 	uchar_t posi_err:	1;
814 	uchar_t blk_posi_unkwn:	1;
815 	uchar_t mrk_posi_unkwn:	1;
816 	uchar_t byte_cnt_unkwn:	1;
817 	uchar_t blk_cnt_unkwn:	1;
818 	uchar_t end_of_part:	1;
819 	uchar_t begin_of_part:	1;
820 
821 	uchar_t partition;
822 	uint16_t parameter_len;
823 /* start next word */
824 	uint32_t blks_in_buf:	24;
825 	uint32_t reserved1:	8;
826 #endif
827 	uint64_t host_block;
828 	uint64_t media_block;
829 	uint64_t byte_in_buf;
830 }tape_position_ext_t;
831 
832 typedef union {
833 	tape_position_t srt;
834 	tape_position_ext_t ext;
835 	tape_position_long_t lng;
836 }read_pos_data_t;
837 
838 typedef struct {
839 	unsigned char cmd;
840 	unsigned char
841 		requires_reserve:	1,	/* reserve must be done */
842 		retriable:		1,	/* can be retried */
843 		chg_tape_pos:		1,	/* position will change */
844 		chg_tape_data:		1,	/* data on media will change */
845 		explicit:		1,	/* explicit command set */
846 		/*
847 		 * 0 doesn't, 1 forward,
848 		 * 2 back, 3 either
849 		 */
850 		chg_tape_direction:	2;	/* direction of pos change */
851 #define	DIR_NONE	0
852 #define	DIR_FORW	1
853 #define	DIR_REVC	2
854 #define	DIR_EITH	3
855 	unsigned char
856 		/*
857 		 * 0 doesn't 1 read, 2 write
858 		 */
859 		transfers_data:		2,
860 #define	TRAN_NONE	0
861 #define	TRAN_READ	1
862 #define	TRAN_WRTE	2
863 		recov_pos_type:		1,
864 #define	POS_EXPECTED	0
865 #define	POS_STARTING	1
866 		do_not_recover:		1;
867 	uchar_t reserve_byte;
868 	uint32_t reserve_mask;
869 	uint64_t (*get_cnt)(uchar_t *);
870 	uint64_t (*get_lba)(uchar_t *);
871 }cmd_attribute;
872 
873 typedef struct {
874 	buf_t *cmd_bp;
875 	size_t privatelen;
876 }pkt_info;
877 
878 typedef struct {
879 	buf_t *cmd_bp;
880 	size_t privatelen;
881 	tapepos_t pos;
882 	const cmd_attribute *cmd_attrib;
883 }recov_info;
884 
885 #ifdef _KERNEL
886 
887 #ifdef	__x86
888 /* Data structure used in big block I/O on x86/x64 platform */
889 
890 /*
891  * alloc more than one contig_mem, so mutiple I/O can be
892  * on-going simultaneously
893  */
894 #define	ST_MAX_CONTIG_MEM_NUM	3
895 
896 struct contig_mem {
897 	struct contig_mem *cm_next;
898 	size_t cm_len;
899 	caddr_t cm_addr;
900 	ddi_acc_handle_t cm_acc_hdl;
901 	struct buf *cm_bp;
902 	int cm_use_sbuf;
903 };
904 
905 #endif
906 
907 #endif /* _KERNEL */
908 
909 /*
910  * driver states..
911  */
912 typedef enum {
913 	ST_STATE_CLOSED,
914 	ST_STATE_OFFLINE,
915 	ST_STATE_INITIALIZING,
916 	ST_STATE_OPENING,
917 	ST_STATE_OPEN_PENDING_IO,
918 	ST_STATE_APPEND_TESTING,
919 	ST_STATE_OPEN,
920 	ST_STATE_RESOURCE_WAIT,
921 	ST_STATE_CLOSING,
922 	ST_STATE_SENSING,
923 	ST_STATE_CLOSE_PENDING_OPEN
924 }st_states;
925 
926 typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
927 
928 
929 /*
930  * Private info for scsi tapes. Pointed to by the un_private pointer
931  * of one of the SCSI_DEVICE chains.
932  */
933 
934 struct scsi_tape {
935 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
936 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
937 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
938 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
939 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
940 	struct	buf *un_sbufp;		/* for use in special io */
941 	char	*un_srqbufp;		/* sense buffer for special io */
942 	kcondvar_t un_clscv;		/* closing cv */
943 	struct	buf *un_quef;		/* head of wait queue */
944 	struct	buf *un_quel;		/* tail of wait queue */
945 	struct	buf *un_runqf;		/* head of run queue */
946 	struct	buf *un_runql;		/* tail of run queue */
947 	struct seq_mode *un_mspl;	/* ptr to mode select info */
948 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
949 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
950 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
951 	tapepos_t un_pos;		/* Current tape position */
952 	int	un_oflags;		/* open flags */
953 	tapepos_t un_err_pos;		/* block in file where err occurred */
954 	uint_t	un_err_resid;		/* resid from last error */
955 	short	un_fmneeded;		/* filemarks to be written - HP only */
956 	dev_t	un_dev;			/* unix device */
957 	uchar_t	un_attached;		/* unit known && attached */
958 	int	un_pwr_mgmt;		/* power management state */
959 	uchar_t	un_density_known;	/* density is known */
960 	uchar_t	un_curdens;		/* index into density table */
961 	optype	un_lastop;		/* last I/O was: read/write/ctl */
962 	st_states un_laststate;		/* last state */
963 	st_states un_state;		/* current state */
964 	uchar_t	un_status;		/* status from last sense */
965 	uchar_t	un_retry_ct;		/* retry count */
966 	uchar_t	un_tran_retry_ct;	/* transport retry count */
967 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
968 	uchar_t	un_test_append;		/* check writing at end of tape */
969 	uchar_t un_arq_enabled;		/* auto request sense enabled */
970 	uchar_t un_untagged_qing;	/* hba has untagged quing */
971 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
972 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
973 	uchar_t	un_ncmds;		/* number of commands outstanding */
974 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
975 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
976 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
977 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
978 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
979 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
980 					/* check condidtion or error */
981 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
982 	uint_t	un_last_resid;		/* keep last resid, for PE */
983 	uint_t	un_last_count;		/* keep last count, for PE */
984 	struct 	kstat *un_stats;	/* for I/O statistics */
985 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
986 	struct	buf *un_wf;		/* head of write queue */
987 	struct	buf *un_wl;		/* tail of write queue */
988 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
989 	int	un_maxdma;		/* max dma xfer allowed by HBA */
990 	uint_t	un_bsize;		/* block size currently being used */
991 	int	un_maxbsize;		/* max block size allowed by drive */
992 	uint_t	un_minbsize;		/* min block size allowed by drive */
993 	int	un_errno;		/* errno (b_error) */
994 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
995 	enum mtio_state	un_mediastate;	/* current media state */
996 	enum mtio_state	un_specified_mediastate;	/* expected state */
997 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
998 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
999 	opaque_t	un_swr_token;	/* scsi_watch request token */
1000 	uchar_t	un_comp_page;		/* compression page */
1001 	uchar_t	un_rsvd_status;		/* Reservation Status */
1002 	kstat_t *un_errstats;		/* for error statistics */
1003 	int	un_init_options;	/* Init time drive options */
1004 	int	un_save_fileno;		/* Save here for recovery */
1005 	daddr_t	un_save_blkno;		/* Save here for recovery */
1006 	uchar_t un_restore_pos;		/* Indication to do recovery */
1007 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
1008 	uchar_t	un_silent_skip;		/* to catch short reads */
1009 	short	un_tids_at_suspend;	/* timeouts set at suspend */
1010 	kcondvar_t un_tape_busy_cv;	/* busy cv */
1011 	kcondvar_t un_suspend_cv;	/* busy cv */
1012 					/* restore on close */
1013 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
1014 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
1015 	uchar_t	un_rqs_state;		/* see define below */
1016 	struct scsi_extended_sense
1017 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
1018 	uchar_t	un_data_mod;		/* Device required data mod */
1019 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
1020 	int un_max_cdb_sz;		/* max cdb size to use */
1021 	read_p_types un_read_pos_type;
1022 	read_pos_data_t *un_read_pos_data;
1023 	struct mterror_entry_stack *un_error_entry_stk;
1024 					/* latest sense cmd buffer */
1025 
1026 #ifdef	__x86
1027 	ddi_dma_handle_t un_contig_mem_hdl;
1028 	struct contig_mem *un_contig_mem;
1029 	int un_contig_mem_available_num;
1030 	int un_contig_mem_total_num;
1031 	size_t un_max_contig_mem_len;
1032 	kcondvar_t un_contig_mem_cv;
1033 	int un_maxdma_arch;		/* max dma xfer allowed by HBA & arch */
1034 #endif
1035 	caddr_t un_media_id;
1036 	int un_media_id_len;
1037 	int (*un_media_id_method)(struct scsi_tape *, int (*)());
1038 	buf_t *un_recov_buf;		/* buf to recover failed commands */
1039 	kcondvar_t un_recov_buf_cv;	/* cv for buf un_recov_buf */
1040 	uchar_t un_recov_buf_busy;
1041 #ifdef _KERNEL
1042 	ddi_taskq_t *un_recov_taskq;
1043 #else
1044 	void *un_recov_taskq;
1045 #endif
1046 	tapepos_t un_running;
1047 	uchar_t un_unit_attention_flags;
1048 };
1049 
1050 typedef int (*bufunc_t)(struct scsi_tape *, int, int64_t, int);
1051 typedef int (*ubufunc_t)(struct scsi_tape *, struct uscsi_cmd *, int);
1052 
1053 
1054 /*
1055  * device error kstats
1056  */
1057 struct st_errstats {
1058 	struct kstat_named	st_softerrs;
1059 	struct kstat_named	st_harderrs;
1060 	struct kstat_named	st_transerrs;
1061 	struct kstat_named	st_vid;
1062 	struct kstat_named	st_pid;
1063 	struct kstat_named	st_revision;
1064 	struct kstat_named	st_serial;
1065 };
1066 
1067 /*
1068  * generic log page struct
1069  */
1070 struct log_page {
1071 #if defined(_BIT_FIELDS_LTOH)
1072 	uchar_t	code	:6,	/* page code number */
1073 			:2;	/* reserved */
1074 #elif defined(_BIT_FIELDS_HTOL)
1075 	uchar_t		:2,	/* reserved */
1076 		code	:6;	/* page code number */
1077 #endif	/* _BIT_FIELDS_LTOH */
1078 	uchar_t	reserved;	/* reserved */
1079 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
1080 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
1081 	/*
1082 	 * Log parameters follow right after this...
1083 	 */
1084 };
1085 
1086 /*
1087  * generic log page parameter struct
1088  */
1089 struct log_param {
1090 	uchar_t	pc_hi;			/* parameter code (msb) */
1091 	uchar_t	pc_lo;			/* parameter code (lsb) */
1092 #if defined(_BIT_FIELDS_LTOH)
1093 	uchar_t		lp	: 1,	/* list parameter */
1094 				: 1,	/* reserved */
1095 			tmc	: 2,	/* threshold met criteria */
1096 			etc	: 1,	/* enable threshold comparison */
1097 			tsd	: 1,	/* target save disable */
1098 			ds	: 1,	/* disable save */
1099 			du	: 1;	/* disable update */
1100 #elif defined(_BIT_FIELDS_HTOL)
1101 	uchar_t		du	: 1,	/* disable update */
1102 			ds	: 1,	/* disable save */
1103 			tsd	: 1,	/* target save disable */
1104 			etc	: 1,	/* enable threshold comparison */
1105 			tmc	: 2,	/* threshold met criteria */
1106 				: 1,	/* reserved */
1107 			lp	: 1;	/* list parameter */
1108 #endif	/* _BIT_FIELDS_LTOH */
1109 	uchar_t	length;		/* length of bytes to follow */
1110 	/*
1111 	 * Parameter values follow right after this...
1112 	 */
1113 };
1114 /*
1115  * TapeAlert structures
1116  */
1117 
1118 struct st_tape_alert_parameter {
1119 	struct log_param log_param;
1120 	uchar_t	param_value;
1121 };
1122 
1123 struct st_tape_alert {
1124 	struct log_page log_page;
1125 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
1126 };
1127 
1128 #define	TAPE_ALERT_PARAMETER_LENGTH \
1129 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
1130 
1131 struct log_sequential_page_parameter {
1132 	struct log_param log_param;
1133 	uchar_t param_value[8];
1134 };
1135 
1136 struct log_sequential_page {
1137 	struct log_page log_page;
1138 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
1139 };
1140 
1141 #if !defined(__lint)
1142 _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
1143 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
1144 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
1145 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
1146 _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
1147 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
1148 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
1149 _NOTE(SCHEME_PROTECTS_DATA("save sharing",
1150 	scsi_tape::un_allow_large_xfer
1151 	scsi_tape::un_maxbsize
1152 	scsi_tape::un_maxdma
1153 ))
1154 #ifdef	__x86
1155 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
1156 _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
1157 #endif
1158 #endif
1159 
1160 
1161 /*
1162  * Power management state
1163  */
1164 #define	ST_PWR_NORMAL				0
1165 #define	ST_PWR_SUSPENDED			1
1166 
1167 
1168 #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
1169 
1170 /* un_rqs_state codes */
1171 
1172 #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
1173 #define	ST_RQS_VALID		0x2	/* RQS data is valid */
1174 #define	ST_RQS_READ		0x4	/* RQS data was read */
1175 #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
1176 
1177 /*
1178  * st_intr codes
1179  */
1180 typedef enum {
1181 	COMMAND_DONE,
1182 	COMMAND_DONE_ERROR,
1183 	COMMAND_DONE_ERROR_RECOVERED,
1184 	QUE_COMMAND,
1185 	QUE_BUSY_COMMAND,
1186 	QUE_SENSE,
1187 	JUST_RETURN,
1188 	COMMAND_DONE_EACCES,
1189 	QUE_LAST_COMMAND,
1190 	COMMAND_TIMEOUT,
1191 	PATH_FAILED,
1192 	DEVICE_RESET,
1193 	DEVICE_TAMPER,
1194 	ATTEMPT_RETRY
1195 }errstate;
1196 #ifdef _KERNEL
1197 typedef struct {
1198 	struct scsi_pkt ei_failed_pkt;
1199 	struct scsi_arq_status ei_failing_status;
1200 	tapepos_t ei_expected_pos;
1201 	errstate ei_error_type;
1202 	buf_t *ei_failing_bp;
1203 } st_err_info;
1204 #endif
1205 
1206 
1207 /*
1208  *	Reservation Status
1209  *
1210  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
1211  *		         in between opens and also to indicate the reservation
1212  *		         has not been done till now.
1213  * ST_RELEASE	        -Tape Unit is Released.
1214  * ST_RESERVE	        -Tape Unit is Reserved.
1215  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
1216  *
1217  */
1218 #define	ST_INIT_RESERVE			0x001
1219 #define	ST_RELEASE			0x002
1220 #define	ST_RESERVE			0x004
1221 #define	ST_PRESERVE_RESERVE		0x008
1222 #define	ST_RESERVATION_CONFLICT 	0x010
1223 #define	ST_LOST_RESERVE			0x020
1224 #define	ST_APPLICATION_RESERVATIONS	0x040
1225 #define	ST_INITIATED_RESET		0x080
1226 #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
1227 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
1228 
1229 /*
1230  * Service action defines for Persistant Reservation Commands
1231  */
1232 #define	ST_SA_SCSI3_REGISTER			0x00
1233 #define	ST_SA_SCSI3_RESERVE			0x01
1234 #define	ST_SA_SCSI3_RELEASE			0x02
1235 #define	ST_SA_SCSI3_CLEAR			0x03
1236 #define	ST_SA_SCSI3_PREEMPT			0x04
1237 #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
1238 #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
1239 #define	ST_SA_MASK				0x1f
1240 
1241 #define	ST_RESERVATION_DELAY		500000
1242 
1243 /*
1244  * Asynch I/O tunables
1245  */
1246 #define	ST_MAX_THROTTLE		4
1247 
1248 /*
1249  * 60 minutes seems a reasonable amount of time
1250  * to wait for tape space operations to complete.
1251  *
1252  */
1253 #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
1254 #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
1255 
1256 /*
1257  * 2 minutes seems a reasonable amount of time
1258  * to wait for tape i/o operations to complete.
1259  *
1260  */
1261 #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
1262 #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
1263 
1264 
1265 /*
1266  * 10 seconds is what we'll wait if we get a Busy Status back
1267  */
1268 #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
1269 #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
1270 #define	ST_INTERRUPT_CONTEXT	1
1271 #define	ST_START_CONTEXT	2
1272 
1273 /*
1274  * Number of times we'll retry a normal operation.
1275  *
1276  * XXX This includes retries due to transport failure as well as
1277  * XXX busy timeouts- Need to distinguish between Target and Transport
1278  * XXX failure.
1279  */
1280 
1281 #define	ST_RETRY_COUNT		20
1282 
1283 /*
1284  * Number of times to retry a failed selection
1285  */
1286 #define	ST_SEL_RETRY_COUNT		2
1287 
1288 /*
1289  * es_code value for deferred error
1290  * should be moved to sense.h
1291  */
1292 
1293 #define	ST_DEFERRED_ERROR		0x01
1294 
1295 /*
1296  * Maximum number of units (determined by minor device byte)
1297  */
1298 #define	ST_MAXUNIT	128
1299 
1300 /*
1301  * Time to wait for completion of a command before cancelling it.
1302  * For SUSPEND use only
1303  */
1304 #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
1305 
1306 #ifndef	SECSIZE
1307 #define	SECSIZE	512
1308 #endif
1309 #ifndef	SECDIV
1310 #define	SECDIV	9
1311 #endif
1312 
1313 /*
1314  * convenient defines
1315  */
1316 #define	ST_SCSI_DEVP		(un->un_sd)
1317 #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
1318 #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
1319 #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
1320 #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
1321 #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
1322 
1323 #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
1324 #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
1325 #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
1326 #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
1327 #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
1328 #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
1329 #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
1330 #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
1331 #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
1332 
1333 #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
1334 	((un)->un_state == ST_STATE_SENSING && \
1335 		(un)->un_laststate == ST_STATE_CLOSING))
1336 
1337 #define	ASYNC_CMD	0
1338 #define	SYNC_CMD	1
1339 
1340 #define	st_bioerror(bp, error) \
1341 		{ bioerror(bp, error); \
1342 		un->un_errno = error; }
1343 
1344 /*
1345  * Macros for internal coding of count for SPACE command:
1346  *
1347  * Top 3 bits of b_bcount define direction and type of space.
1348  * Since b_bcount (size_t) is 32 bits on 32 platforms and 64 bits on
1349  * 64 bit platforms different defines are used.
1350  * if SP_BACKSP is set direction is backward (toward BOP)
1351  * The type of space (Blocks, Filemark or sequential filemarks) is
1352  * carried in the next 2 bits. The remaining bits a signed count of
1353  * how many of that direction and type to do.
1354  */
1355 #if (SIZE_MAX < UINT64_MAX)
1356 
1357 #define	SP_BLK		UINT32_C(0x00000000)
1358 #define	SP_FLM		UINT32_C(0x20000000)
1359 #define	SP_SQFLM	UINT32_C(0x40000000)
1360 #define	SP_EOD		UINT32_C(0x60000000)
1361 #define	SP_BACKSP	UINT32_C(0x80000000)
1362 #define	SP_CMD_MASK	UINT32_C(0x60000000)
1363 #define	SP_CNT_MASK	UINT32_C(0x1fffffff)
1364 
1365 /* Macros to interpret space cmds */
1366 #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1367 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1368 #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>29)
1369 
1370 #else /* end of small size_t in buf_t */
1371 
1372 #define	SP_BLK		UINT64_C(0x0000000000000000)
1373 #define	SP_FLM		UINT64_C(0x2000000000000000)
1374 #define	SP_SQFLM	UINT64_C(0x4000000000000000)
1375 #define	SP_EOD		UINT64_C(0x6000000000000000)
1376 #define	SP_BACKSP	UINT64_C(0x8000000000000000)
1377 #define	SP_CMD_MASK	UINT64_C(0x6000000000000000)
1378 #define	SP_CNT_MASK	UINT64_C(0x1fffffffffffffff)
1379 
1380 /* Macros to interpret space cmds */
1381 #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1382 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1383 #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>61)
1384 
1385 #endif /* end of big size_t in buf_t */
1386 
1387 /* Macros to assemble space cmds */
1388 #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
1389 #define	Fmk(x)		SPACE(SP_FLM, x)
1390 #define	Blk(x)		SPACE(SP_BLK, x)
1391 
1392 
1393 
1394 /* Defines for byte 4 of load/unload cmd */
1395 #define	LD_UNLOAD	0
1396 #define	LD_LOAD		1
1397 #define	LD_RETEN	2
1398 #define	LD_EOT		4
1399 #define	LD_HOLD		8
1400 
1401 /* Defines for byte 4 of prevent/allow media removal */
1402 #define	MR_UNLOCK	0
1403 #define	MR_LOCK		1
1404 
1405 #define	GET_SOFT_STATE(dev)						\
1406 	register struct scsi_tape *un;					\
1407 	register int instance;						\
1408 									\
1409 	instance = MTUNIT(dev);						\
1410 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
1411 		return (ENXIO);
1412 
1413 /*
1414  * Debugging turned on via conditional compilation switch -DSTDEBUG
1415  */
1416 #ifdef DEBUG
1417 #define	STDEBUG
1418 #endif
1419 
1420 #ifdef	STDEBUG
1421 #define	DEBUGGING\
1422 	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0x7))
1423 
1424 #define	ST_DARGS(d) st_label, ((d == st_lastdev || d == 0) ?CE_CONT:CE_NOTE)
1425 
1426 	/* initialization */
1427 #define	ST_DEBUG1	if ((st_debug & 0x7) >= 1) scsi_log
1428 #define	ST_DEBUG	ST_DEBUG1
1429 
1430 	/* errors and UA's */
1431 #define	ST_DEBUG2	if ((st_debug & 0x7) >= 2) scsi_log
1432 
1433 	/* func calls */
1434 #define	ST_DEBUG3	if ((st_debug & 0x7) >= 3) scsi_log
1435 
1436 	/* ioctl calls */
1437 #define	ST_DEBUG4	if ((st_debug & 0x7) >= 4) scsi_log
1438 
1439 #define	ST_DEBUG5	if ((st_debug & 0x7) >= 5) scsi_log
1440 
1441 	/* full data tracking */
1442 #define	ST_DEBUG6	if ((st_debug & 0x7) >= 6) scsi_log
1443 
1444 	/* debug error recovery */
1445 #define	ST_RECOV	if (st_debug & 0x8) scsi_log
1446 
1447 	/* Entry Point Functions */
1448 #define	ST_ENTR(d, fn)\
1449     if (st_debug & 0x10) { scsi_log(d, ST_DARGS(d), #fn);\
1450     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1451 
1452 	/* Non-Entry Point Functions */
1453 #define	ST_FUNC(d, fn)\
1454     if (st_debug & 0x20) { scsi_log(d, ST_DARGS(d), #fn);\
1455     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1456 
1457 	/* Space Information */
1458 #define	ST_SPAC		if (st_debug & 0x40) scsi_log
1459 
1460 	/* CDB's sent */
1461 #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) { \
1462     st_print_cdb(d, ST_DARGS(d), cmnt, cdb);\
1463     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1464 	/* sense data */
1465 #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) { \
1466     st_clean_print(d, ST_DARGS(d), cmnt, sense, size);\
1467     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1468 	/* position data */
1469 #define	ST_POS(d, cmnt, pdata) if (st_debug & 0x400) { \
1470     st_print_position(d, ST_DARGS(d), cmnt, pdata);\
1471     if (d != 0 && d != st_lastdev) st_lastdev = d; }
1472 
1473 
1474 #else
1475 
1476 #define	st_debug	(0)
1477 #define	DEBUGGING	(0)
1478 #define	ST_DEBUG	if (0) scsi_log
1479 #define	ST_DEBUG1	if (0) scsi_log
1480 #define	ST_DEBUG2	if (0) scsi_log
1481 #define	ST_DEBUG3	if (0) scsi_log
1482 #define	ST_DEBUG4	if (0) scsi_log
1483 #define	ST_DEBUG5	if (0) scsi_log
1484 #define	ST_DEBUG6	if (0) scsi_log
1485 #define	ST_RECOV	if (0) scsi_log
1486 
1487 #define	ST_ENTR(d, fn)
1488 #define	ST_FUNC(d, fn)
1489 #define	ST_SPAC		if (0) scsi_log
1490 #define	ST_CDB(d, cmnt, cdb)
1491 #define	ST_SENSE(d, cmnt, sense, size)
1492 #define	ST_SENSE(d, cmnt, sense, size)
1493 #define	ST_POS(d, cmnt, pdata)
1494 
1495 #endif
1496 
1497 /*
1498  * Media access values
1499  */
1500 #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
1501 
1502 /*
1503  * SCSI tape mode sense page information
1504  */
1505 #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
1506 #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
1507 #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
1508 #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
1509 
1510 /*
1511  * SCSI tape data compression Page definition.
1512  */
1513 #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
1514 
1515 
1516 
1517 /*
1518  * maxbsize values
1519  */
1520 #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
1521 
1522 #define	ONE_MEG			(1024 * 1024)
1523 
1524 /*
1525  * generic soft error reporting
1526  *
1527  * What we are doing here is allowing a greater number of errors to occur on
1528  * smaller transfers (i.e. usually at the beginning of the tape), than on
1529  * the rest of the tape.
1530  *
1531  * A small transfer is defined as :
1532  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
1533  *
1534  * A larget tranfer is defined as :
1535  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
1536  *
1537  */
1538 #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
1539 #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
1540 
1541 /*
1542  * soft error reporting for exabyte
1543  */
1544 #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
1545 
1546 #define	SENSE_19_BITS  \
1547 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
1548 #define	SENSE_20_BITS  \
1549 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
1550 #define	SENSE_21_BITS  \
1551 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
1552 
1553 /* these are defined in percentages */
1554 #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
1555 #define	EXABYTE_READ_ERROR_THRESHOLD	3
1556 /*
1557  * minumum amount of data transfer(MB) for checking soft error rate.
1558  */
1559 #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
1560 
1561 #define	CLN	0x8
1562 #define	CLND	0x10
1563 
1564 /*
1565  * soft error reporting for Archive 4mm DAT
1566  */
1567 
1568 #define	LOG_SENSE_LENGTH		0xff
1569 #define	MIN_LOG_SENSE_LENGTH		0x2b
1570 #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
1571 #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
1572 #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
1573 #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
1574 
1575 /*
1576  * ST timeouts that need to be cancelled for suspend
1577  */
1578 #define	ST_HIB_TID	0x01
1579 #define	ST_DELAY_TID	0x02
1580 
1581 #ifdef	__cplusplus
1582 }
1583 #endif
1584 
1585 #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1586