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