xref: /titanic_50/usr/src/uts/common/sys/scsi/targets/stdef.h (revision 0b46ffbad80838700776674f5dea3ad9b16dd6e4)
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 2006 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/scsi/scsi_types.h>
36 #include <sys/mtio.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Defines for SCSI tape drives.
44  */
45 
46 /*
47  * Maximum variable length record size for a single request
48  */
49 #define	ST_MAXRECSIZE_VARIABLE	65535
50 
51 /*
52  * If the requested record size exceeds ST_MAXRECSIZE_VARIABLE,
53  * then the following define is used.
54  */
55 #define	ST_MAXRECSIZE_VARIABLE_LIMIT	65534
56 
57 #define	ST_MAXRECSIZE_FIXED	(63<<10)	/* maximum fixed record size */
58 #define	INF 1000000000
59 
60 /*
61  * Supported tape device types plus default type for opening.
62  * Types 10 - 13, are special (ancient too) drives - *NOT SUPPORTED*
63  * Types 14 - 1f, are 1/4-inch cartridge drives.
64  * Types 20 - 28, are 1/2-inch cartridge or reel drives.
65  * Types 28+, are rdat (vcr) drives.
66  */
67 #define	ST_TYPE_INVALID		0x00
68 
69 #define	ST_TYPE_SYSGEN1	MT_ISSYSGEN11	/* Sysgen with QIC-11 only */
70 #define	ST_TYPE_SYSGEN	MT_ISSYSGEN	/* Sysgen with QIC-24 and QIC-11 */
71 
72 #define	ST_TYPE_DEFAULT	MT_ISDEFAULT	/* Generic 1/4" or undetermined  */
73 #define	ST_TYPE_EMULEX	MT_ISMT02	/* Emulex MT-02 */
74 #define	ST_TYPE_ARCHIVE	MT_ISVIPER1	/* Archive QIC-150 */
75 #define	ST_TYPE_WANGTEK	MT_ISWANGTEK1	/* Wangtek QIC-150 */
76 
77 #define	ST_TYPE_CDC	MT_ISCDC	/* CDC - (not tested) */
78 #define	ST_TYPE_FUJI	MT_ISFUJI	/* Fujitsu - (not tested) */
79 #define	ST_TYPE_KENNEDY	MT_ISKENNEDY	/* Kennedy */
80 #define	ST_TYPE_ANRITSU	MT_ISANRITSU	/* Anritsu */
81 #define	ST_TYPE_HP	MT_ISHP		/* HP */
82 #define	ST_TYPE_HIC	MT_ISCCS23	/* Generic 1/2" Cartridge */
83 #define	ST_TYPE_REEL	MT_ISCCS24	/* Generic 1/2" Reel Tape */
84 #define	ST_TYPE_DAT	MT_ISCCS28	/* Generic DAT Tape */
85 
86 #define	ST_TYPE_EXABYTE	MT_ISEXABYTE	/* Exabyte 8200 */
87 #define	ST_TYPE_EXB8500	MT_ISEXB8500	/* Exabyte 8500 */
88 #define	ST_TYPE_WANGTHS	MT_ISWANGTHS	/* Wangtek 6130HS */
89 #define	ST_TYPE_WANGDAT	MT_ISWANGDAT	/* WangDAT */
90 #define	ST_TYPE_PYTHON  MT_ISPYTHON	/* Archive Python DAT */
91 #define	ST_TYPE_STC3490 MT_ISSTC	/* IBM STC 3490 */
92 #define	ST_TYPE_TAND25G MT_ISTAND25G	/* TANDBERG 2.5G */
93 #define	ST_TYPE_DLT	MT_ISDLT	/* DLT */
94 #define	ST_TYPE_STK9840	MT_ISSTK9840	/* StorageTek 9840, 9940, 9840B */
95 #define	ST_TYPE_BMDLT1	MT_ISBMDLT1	/* Benchmark DTL1 */
96 #define	ST_TYPE_LTO	MT_LTO		/* sun: LTO's by HP, Seagate, IBM.. */
97 #define	ST_LAST_TYPE	ST_TYPE_LTO	/* Add new above type and change this */
98 
99 
100 /* Internal flags */
101 #define	ST_DYNAMIC		0x2000	/* Device name has been dynamically */
102 					/* alloc'ed from the st.conf entry, */
103 					/* instead of being used from the */
104 					/* st_drivetypes array. */
105 
106 /*
107  * Defines for supported drive options
108  *
109  * WARNING : THESE OPTIONS SHOULD NEVER BE CHANGED, AS OLDER CONFIGURATIONS
110  * 		WILL DEPEND ON THE FLAG VALUES REMAINING THE SAME
111  */
112 #define	ST_VARIABLE		0x001	/* Device supports variable	*/
113 					/* length record sizes		*/
114 #define	ST_QIC			0x002	/* QIC tape device 		*/
115 #define	ST_REEL			0x004	/* 1/2-inch reel tape device	*/
116 #define	ST_BSF			0x008	/* Device supports backspace	*/
117 					/* file as in mt(1) bsf : 	*/
118 					/* backspace over EOF marks.	*/
119 					/* Devices not supporting bsf 	*/
120 					/* will fail with ENOTTY upon	*/
121 					/* use of bsf			*/
122 #define	ST_BSR			0x010	/* Device supports backspace	*/
123 					/* record as in mt(1) bsr :	*/
124 					/* backspace over records. If	*/
125 					/* the device does not support 	*/
126 					/* bsr, the st driver emulates	*/
127 					/* the action by rewinding the	*/
128 					/* tape and using forward space	*/
129 					/* file (fsf) to the correct	*/
130 					/* file and then uses forward	*/
131 					/* space record (fsr) to the	*/
132 					/* correct  record		*/
133 #define	ST_LONG_ERASE		0x020	/* Device needs a longer time	*/
134 					/* than normal to erase		*/
135 #define	ST_AUTODEN_OVERRIDE	0x040	/* Auto-Density override flag	*/
136 					/* Device can figure out the	*/
137 					/* tape density automatically,	*/
138 					/* without issuing a		*/
139 					/* mode-select/mode-sense 	*/
140 #define	ST_NOBUF		0x080	/* Don't use buffered mode.	*/
141 					/* This disables the device's	*/
142 					/* ability for buffered	writes	*/
143 					/* I.e. The device acknowledges	*/
144 					/* write completion after the	*/
145 					/* data is written to the	*/
146 					/* device's buffer, but before	*/
147 					/* all the data is actually	*/
148 					/* written to tape		*/
149 #define	ST_RESERVED_BIT1	0x100	/* resreved bit 		*/
150 					/* parity while talking to it. 	*/
151 #define	ST_KNOWS_EOD		0x200	/* Device knows when EOD (End	*/
152 					/* of Data) has been reached.	*/
153 					/* If the device knows EOD, st	*/
154 					/* uses fast file skipping.	*/
155 					/* If it does not know EOD,	*/
156 					/* file skipping happens one	*/
157 					/* file at a time. 		*/
158 #define	ST_UNLOADABLE		0x400	/* Device will not complain if	*/
159 					/* the st driver is unloaded &	*/
160 					/* loaded again; e.g. will	*/
161 					/* return the correct inquiry	*/
162 					/* string			*/
163 #define	ST_SOFT_ERROR_REPORTING 0x800	/* Do request or log sense on	*/
164 					/* close to report soft errors.	*/
165 					/* Currently only Exabyte and	*/
166 					/* DAT drives support this	*/
167 					/* feature.  			*/
168 #define	ST_LONG_TIMEOUTS	0x1000	/* Device needs 5 times longer	*/
169 					/* timeouts for normal		*/
170 					/* operation			*/
171 #define	ST_BUFFERED_WRITES	0x4000	/* The data is buffered in the	*/
172 					/* driver and pre-acked to the	*/
173 					/* application 			*/
174 #define	ST_NO_RECSIZE_LIMIT	0x8000	/* For variable record size	*/
175 					/* devices only. If flag is	*/
176 					/* set, then don't limit	*/
177 					/* record size to 64k as in	*/
178 					/* pre-Solaris 2.4 releases.	*/
179 					/* The only limit on the	*/
180 					/* record size will be the max	*/
181 					/* record size the device can	*/
182 					/* handle or the max DMA	*/
183 					/* transfer size of the		*/
184 					/* machine, which ever is	*/
185 					/* smaller. Beware of		*/
186 					/* incompatabilities with	*/
187 					/* tapes of pre-Solaris 2.4	*/
188 					/* OS's written with large	*/
189 					/* (>64k) block sizes, as	*/
190 					/* their true block size is	*/
191 					/* a max of approx 64k		*/
192 #define	ST_MODE_SEL_COMP	0x10000	/* use mode select of device	*/
193 					/* configuration page (0x10) to */
194 					/* enable/disable compression	*/
195 					/* instead of density codes for */
196 					/* the "c" and "u" devices	*/
197 #define	ST_NO_RESERVE_RELEASE	0x20000	/* For devices which do not	*/
198 					/* support RESERVE/RELEASE SCSI	*/
199 					/* command. If this is enabled	*/
200 					/* then reserve/release would	*/
201 					/* not be used during open/	*/
202 					/* close for High Availability	*/
203 #define	ST_READ_IGNORE_ILI	0x40000 /* This flag is only applicable */
204 					/* to variable block devices 	*/
205 					/* which support the SILI bit	*/
206 					/* option. It indicates that 	*/
207 					/* the SILI bit will be ignored */
208 					/* during reads  		*/
209 #define	ST_READ_IGNORE_EOFS 	0x80000 /* When this flag is set two 	*/
210 					/* EOF marks do not indicate an */
211 					/* EOM. This option is only	*/
212 					/* supported on 1/2" reel tapes */
213 #define	ST_SHORT_FILEMARKS	0x100000 /* This option applies only to */
214 					/* EXABYTE 8mm tape drives 	*/
215 					/* which support short 		*/
216 					/* filemarks. When this flag 	*/
217 					/* is set, short filemarks 	*/
218 					/* will be used for writing	*/
219 					/* filemarks. 			*/
220 #define	ST_EJECT_ON_CHANGER_FAILURE 0x200000 /* When this flag is set   */
221 					/* and the tape is trapped in   */
222 					/* the medium changer, the tape */
223 					/* is automatically ejected	*/
224 #define	ST_RETRY_ON_RECOVERED_DEFERRED_ERROR 0x400000
225 					/* This option applies only to  */
226 					/* IBM MAGSTAR 3590. If this    */
227 					/* flag is set, the st driver   */
228 					/* will retry the last cmd if   */
229 					/* the last error cause a check */
230 					/* condition with error code    */
231 					/* 0x71 and sense code  0x01 	*/
232 #define	ST_KNOWS_MEDIA		0x800000 /* Use configured media type	*/
233 					/* detected to select correct   */
234 					/* density code.		*/
235 #define	ST_CLN_TYPE_1		0x10000000 /* When this flag is set,	*/
236 					/* the tape drive provides the	*/
237 					/* clean bit information in	*/
238 					/* byte 21, bitmask 0x08 of	*/
239 					/* Request Sense data		*/
240 #define	ST_CLN_TYPE_2		0x20000000 /* When this flag is set,	*/
241 					/* the tape drive provides the	*/
242 					/* clean bit information in	*/
243 					/* byte 70, bitmask 0xc0 of	*/
244 					/* Request Sense data		*/
245 #define	ST_CLN_TYPE_3		0x40000000 /* When this flag is set,	*/
246 					/* the tape drive provides the	*/
247 					/* clean bit information in	*/
248 					/* byte 18, bitmask 0x01 of	*/
249 					/* Request Sense data		*/
250 
251 #define	ST_CLN_MASK	(ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
252 #define	ST_VALID_OPTS	(ST_VARIABLE | ST_QIC | ST_REEL | ST_BSF | ST_BSR |\
253 	ST_LONG_ERASE | ST_AUTODEN_OVERRIDE | ST_NOBUF | ST_KNOWS_EOD |\
254 	ST_UNLOADABLE | ST_SOFT_ERROR_REPORTING | ST_LONG_TIMEOUTS |\
255 	ST_NO_RECSIZE_LIMIT | ST_MODE_SEL_COMP | ST_NO_RESERVE_RELEASE |\
256 	ST_READ_IGNORE_ILI | ST_READ_IGNORE_EOFS | ST_SHORT_FILEMARKS |\
257 	ST_EJECT_ON_CHANGER_FAILURE | ST_RETRY_ON_RECOVERED_DEFERRED_ERROR |\
258 	ST_CLN_TYPE_1 | ST_CLN_TYPE_2 | ST_CLN_TYPE_3)
259 
260 #define	NDENSITIES	MT_NDENSITIES
261 #define	NSPEEDS		MT_NSPEEDS
262 
263 /*
264  * defines for Log Sense Pages
265  */
266 #define	SUPPORTED_LOG_PAGES_PAGE	0x00
267 #define	TAPE_SEQUENTIAL_PAGE		0x0c
268 #define	TAPE_ALERT_PAGE			0x2e
269 
270 /*
271  * Log Page Control definitions
272  */
273 #define	CURRENT_THRESHOLD_VALUES	0x00
274 #define	CURRENT_CUMULATIVE_VALUES	0x40
275 #define	DEFAULT_THRESHOLD_VALUES	0x80
276 #define	DEFAULT_CUMULATIVE_VALUES	0xC0
277 
278 /*
279  * Tape Alert Flag definitions
280  */
281 #define	CLEANING_MEDIA			11
282 #define	CLEAN_NOW			20
283 #define	CLEAN_PERIODIC			21
284 #define	CLEAN_FOR_ERRORS		24
285 
286 #define	TAPE_ALERT_SUPPORT_UNKNOWN	0x00
287 #define	TAPE_ALERT_NOT_SUPPORTED	0x01
288 #define	TAPE_ALERT_SUPPORTED		0x02
289 #define	TAPE_ALERT_STILL_DIRTY		0x04
290 #define	TAPE_SEQUENTIAL_SUPPORTED	0x08
291 #define	TAPE_PREVIOUSLY_DIRTY		0x10
292 
293 #define	TAPE_ALERT_MAX_PARA		64
294 #define	TAPE_SEQUENTIAL_PAGE_PARA	64	/* way more then really used */
295 #define	SEQUENTIAL_NEED_CLN		0x0100
296 
297 /*
298  * Parameters
299  */
300 #define	ST_NAMESIZE	44	/* size of pretty string for vid/pid */
301 #define	VIDLEN		8	/* size of vendor identifier length */
302 #define	PIDLEN		16	/* size of product identifier length */
303 #define	VIDPIDLEN	(VIDLEN + PIDLEN)
304 
305 
306 struct st_drivetype {
307 	char	name[ST_NAMESIZE];	/* Name, for debug */
308 	char	length;			/* Length of vendor id */
309 	char	vid[VIDPIDLEN];		/* Vendor id and model (product) id */
310 	char	type;			/* Drive type for driver */
311 	int	bsize;			/* Block size */
312 	int	options;		/* Drive options */
313 	int	max_rretries;		/* Max read retries */
314 	int	max_wretries;		/* Max write retries */
315 	uchar_t	densities[NDENSITIES];	/* density codes, low->hi */
316 	uchar_t	default_density;	/* default density for this drive */
317 	uchar_t	mediatype[NDENSITIES];	/* was speed. mediatype for density. */
318 	ushort_t non_motion_timeout;	/* Inquiry type commands */
319 	ushort_t io_timeout;		/* I/O timeout in seconds */
320 	ushort_t rewind_timeout;	/* rewind timeout in seconds */
321 	ushort_t space_timeout;		/* space cmd timeout in seconds */
322 	ushort_t load_timeout;		/* load tape time in seconds */
323 	ushort_t unload_timeout;	/* unload tape time in seconds */
324 	ushort_t erase_timeout;		/* erase timeout. seconds */
325 };
326 
327 #define	MINUTES(val)	((val) * 60)
328 
329 struct comp_mode_page {
330 #if defined(_BIT_FIELDS_LTOH)
331 	uchar_t	:		6,
332 		dcc:		1,	/* Data Compression Capable */
333 		dce:		1;	/* Data Compression Enable */
334 	uchar_t	:		5,
335 		red:		2,	/* Report Exceptions on Decompress */
336 		dde:		1;	/* Data Decompression Enabled */
337 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
338 	uchar_t comp_alg_high;
339 	uchar_t	comp_alg_low;
340 	uchar_t	comp_alg_lsb;
341 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
342 	uchar_t decomp_alg_high;
343 	uchar_t	decomp_alg_low;
344 	uchar_t	decomp_alg_lsb;
345 	uchar_t	reservered0;
346 	uchar_t	reservered1;
347 	uchar_t	reservered2;
348 	uchar_t	reservered3;
349 
350 #elif defined(_BIT_FIELDS_HTOL)
351 	uchar_t	dce:		1,	/* Data Compression Enable */
352 		dcc:		1,	/* Data Compression Capable */
353 		:		6;
354 	uchar_t	dde:		1,	/* Data Decompression Enabled */
355 		red:		2,	/* Report Exceptions on Decompress */
356 		:		5;
357 	uchar_t	comp_alg_msb;		/* Compression Algorithm */
358 	uchar_t comp_alg_high;
359 	uchar_t	comp_alg_low;
360 	uchar_t	comp_alg_lsb;
361 	uchar_t	decomp_alg_msb;		/* Decompression Algorithm */
362 	uchar_t decomp_alg_high;
363 	uchar_t	decomp_alg_low;
364 	uchar_t	decomp_alg_lsb;
365 	uchar_t	reservered0;
366 	uchar_t	reservered1;
367 	uchar_t	reservered2;
368 	uchar_t	reservered3;
369 #endif
370 };
371 
372 struct dev_mode_page {
373 #if defined(_BIT_FIELDS_LTOH)
374 	uchar_t	act_format:	5,	/* active format */
375 		caf:		1,	/* Change Active Format */
376 		cap:		1,	/* Change Active Partition */
377 		:		1;
378 	uchar_t	act_partition;		/* active partition */
379 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
380 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
381 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
382 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
383 	uchar_t	rew:		1,	/* Report Early Warning */
384 		rbo:		1,	/* Reverse Buffer Order */
385 		socf:		2,	/* Stop On Consecutive Filemarks */
386 		avc:		1,	/* Automatic Velocity Control */
387 		rsmk:		1,	/* Report SetMarKs */
388 		bis:		1,	/* Block Ids Supported */
389 		dbr:		1;	/* Data Buffer Recovery */
390 	uchar_t	gap_size;
391 	uchar_t	:		3,
392 		sew:		1,	/* Sync data after Early Warning */
393 		eeg:		1,	/* Enable Early Waring */
394 		eod_defined:	3;
395 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
396 	uchar_t	buf_size_leot_mid;
397 	uchar_t	buf_size_leot_lsb;
398 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
399 	uchar_t	reservered;
400 
401 #elif defined(_BIT_FIELDS_HTOL)
402 	uchar_t	:		1,
403 		cap:		1,	/* Change Active Partition */
404 		caf:		1,	/* Change Active Format */
405 		act_format:	5;	/* active format */
406 	uchar_t	act_partition;		/* active partition */
407 	uchar_t	wrt_buf_full_ratio;	/* write buffer full ratio */
408 	uchar_t	rd_buf_full_ratio;	/* read buffer full ratio */
409 	uchar_t	wrt_delay_time_msb;	/* write delay time MSB */
410 	uchar_t	wrt_delay_time_lsb;	/* write delay time LSB */
411 	uchar_t	dbr:		1,	/* Data Buffer Recovery */
412 		bis:		1,	/* Block Ids Supported */
413 		rsmk:		1,	/* Report SetMarKs */
414 		avc:		1,	/* Automatic Velocity Control */
415 		socf:		2,	/* Stop On Consecutive Filemarks */
416 		rbo:		1,	/* Reverse Buffer Order */
417 		rew:		1;	/* Report Early Warning */
418 	uchar_t	gap_size;
419 	uchar_t	eod_defined:	3,
420 		eeg:		1,	/* Enable Early Waring */
421 		sew:		1,	/* Sync data after Early Warning */
422 		:		3;
423 	uchar_t	buf_size_leot_msb;	/* Buffer size after early warning */
424 	uchar_t	buf_size_leot_mid;
425 	uchar_t	buf_size_leot_lsb;
426 	uchar_t	comp_alg;		/* Compression Algorithm (enable) */
427 	uchar_t	reservered;
428 #endif
429 };
430 
431 typedef union {
432 	struct comp_mode_page	comp;
433 	struct dev_mode_page	dev;
434 }modepage;
435 
436 /*
437  *
438  * Parameter list for the MODE_SELECT and MODE_SENSE commands.
439  * The parameter list contains a header, followed by zero or more
440  * block descriptors, followed by vendor unique parameters, if any.
441  *
442  */
443 #define	MSIZE	0x0c		/* Size without additional pages */
444 struct seq_mode {
445 #if defined(_BIT_FIELDS_LTOH)
446 	uchar_t	data_len;	/* sense data length, sense only */
447 	uchar_t	media_type;	/* medium type, sense only */
448 	uchar_t	speed	:4,	/* speed */
449 		bufm	:3,	/* buffered mode */
450 		wp	:1;	/* write protected, sense only */
451 	uchar_t	bd_len;		/* block length in bytes */
452 	uchar_t	density;	/* density code */
453 	uchar_t	high_nb;	/* number of logical blocks on the medium */
454 	uchar_t	mid_nb;		/* that are to be formatted with the density */
455 	uchar_t	low_nb;		/* code and block length in block descriptor */
456 	uchar_t	reserved;	/* reserved */
457 	uchar_t	high_bl;	/* block length */
458 	uchar_t	mid_bl;		/*   "      "   */
459 	uchar_t	low_bl;		/*   "      "   */
460 	uchar_t page_code:	6,
461 		:		1,
462 		ps:		1; /* Page Savable sense only */
463 	uchar_t	page_len;
464 	modepage page;
465 
466 #elif defined(_BIT_FIELDS_HTOL)
467 	uchar_t	data_len;	/* sense data length, sense only */
468 	uchar_t	media_type;	/* medium type, sense only */
469 	uchar_t	wp	:1,	/* write protected, sense only */
470 		bufm	:3,	/* buffered mode */
471 		speed	:4;	/* speed */
472 	uchar_t	bd_len;		/* block length in bytes */
473 	uchar_t	density;	/* density code */
474 	uchar_t	high_nb;	/* number of logical blocks on the medium */
475 	uchar_t	mid_nb;		/* that are to be formatted with the density */
476 	uchar_t	low_nb;		/* code and block length in block descriptor */
477 	uchar_t	reserved;	/* reserved */
478 	uchar_t	high_bl;	/* block length */
479 	uchar_t	mid_bl;		/*   "      "   */
480 	uchar_t	low_bl;		/*   "      "   */
481 	uchar_t	ps:		1, /* Page Savable sense only */
482 		:		1,
483 		page_code:	6;
484 	uchar_t	page_len;
485 	modepage page;
486 #else
487 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
488 #endif	/* _BIT_FIELDS_LTOH */
489 };
490 
491 /*
492  * Data returned from the READ BLOCK LIMITS command.
493  */
494 
495 #define	RBLSIZE	(sizeof (struct read_blklim))
496 struct read_blklim {
497 #if defined(_BIT_FIELDS_HTOL)
498 	uchar_t	reserved:	3;	/* reserved */
499 	uchar_t granularity:	5;	/* Minimum Modularity */
500 #elif defined(_BIT_FIELDS_LTOH)
501 	uchar_t granularity:	5;	/* Minimum Modularity */
502 	uchar_t	reserved:	3;	/* reserved */
503 #endif
504 	uchar_t	max_hi;			/* Maximum block length, high byte */
505 	uchar_t	max_mid;		/* Maximum block length, middle byte */
506 	uchar_t	max_lo;			/* Maximum block length, low byte */
507 	uchar_t	min_hi;			/* Minimum block length, high byte */
508 	uchar_t	min_lo;			/* Minimum block length, low byte */
509 };
510 
511 #ifdef _KERNEL
512 
513 #if defined(__i386) || defined(__amd64)
514 /* Data structure used in big block I/O on x86/x64 platform */
515 
516 /*
517  * alloc more than one contig_mem, so mutiple I/O can be
518  * on-going simultaneously
519  */
520 #define	ST_MAX_CONTIG_MEM_NUM	3
521 
522 /*
523  * 60K is used due to the limitation(size) of the intermediate buffer
524  * in DMA bind code(rootnex.c), which is 64K. If the I/O buf is page
525  * aligned, HBA can do 64K DMA, but if not, HBA can only do
526  * 64K - PAGESIZE = 60K DMA due to the copy to/from intermediate
527  * buffer will keep the page offset.
528  */
529 #define	ST_BIGBLK_XFER		60 * 1024
530 struct contig_mem {
531 	struct contig_mem *cm_next;
532 	size_t cm_len;
533 	caddr_t cm_addr;
534 	ddi_acc_handle_t cm_acc_hdl;
535 	struct buf *cm_bp;
536 	int cm_use_sbuf;
537 };
538 #endif
539 
540 #endif /* _KERNEL */
541 
542 /*
543  * Private info for scsi tapes. Pointed to by the un_private pointer
544  * of one of the SCSI_DEVICE chains.
545  */
546 
547 struct scsi_tape {
548 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
549 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
550 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
551 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
552 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
553 	struct	buf *un_sbufp;		/* for use in special io */
554 	char	*un_srqbufp;		/* sense buffer for special io */
555 	kcondvar_t un_clscv;		/* closing cv */
556 	struct	buf *un_quef;		/* head of wait queue */
557 	struct	buf *un_quel;		/* tail of wait queue */
558 	struct	buf *un_runqf;		/* head of run queue */
559 	struct	buf *un_runql;		/* tail of run queue */
560 	struct seq_mode *un_mspl;	/* ptr to mode select info */
561 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
562 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
563 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
564 	daddr_t	un_blkno;		/* block # in file (512 byte blocks) */
565 	int	un_oflags;		/* open flags */
566 	int	un_fileno;		/* current file number on tape */
567 	int	un_err_fileno;		/* file where error occurred */
568 	daddr_t	un_err_blkno;		/* block in file where err occurred */
569 	uint_t	un_err_resid;		/* resid from last error */
570 	short	un_fmneeded;		/* filemarks to be written - HP only */
571 	dev_t	un_dev;			/* unix device */
572 	uchar_t	un_attached;		/* unit known && attached */
573 	int	un_pwr_mgmt;		/* power management state */
574 	uchar_t	un_density_known;	/* density is known */
575 	uchar_t	un_curdens;		/* index into density table */
576 	uchar_t	un_lastop;		/* last I/O was: read/write/ctl */
577 	uchar_t	un_eof;			/* eof states */
578 	uchar_t	un_laststate;		/* last state */
579 	uchar_t	un_state;		/* current state */
580 	uchar_t	un_status;		/* status from last sense */
581 	uchar_t	un_retry_ct;		/* retry count */
582 	uchar_t	un_tran_retry_ct;	/* transport retry count */
583 	uchar_t	un_read_only;		/* 1 == opened O_RDONLY */
584 	uchar_t	un_test_append;		/* check writing at end of tape */
585 	uchar_t un_arq_enabled;		/* auto request sense enabled */
586 	uchar_t un_untagged_qing;	/* hba has untagged quing */
587 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
588 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
589 	uchar_t	un_ncmds;		/* number of commands outstanding */
590 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
591 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
592 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
593 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
594 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
595 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
596 					/* check condidtion or error */
597 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
598 	uint_t	un_last_resid;		/* keep last resid, for PE */
599 	uint_t	un_last_count;		/* keep last count, for PE */
600 	struct 	kstat *un_stats;	/* for I/O statistics */
601 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
602 	struct	buf *un_wf;		/* head of write queue */
603 	struct	buf *un_wl;		/* tail of write queue */
604 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
605 	int	un_maxdma;		/* max dma xfer allowed by HBA */
606 	uint_t	un_bsize;		/* block size currently being used */
607 	int	un_maxbsize;		/* max block size allowed by drive */
608 	uint_t	un_minbsize;		/* min block size allowed by drive */
609 	int	un_errno;		/* errno (b_error) */
610 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
611 	enum mtio_state	un_mediastate;	/* current media state */
612 	enum mtio_state	un_specified_mediastate;	/* expected state */
613 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
614 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
615 	opaque_t	un_swr_token;	/* scsi_watch request token */
616 	uchar_t	un_comp_page;		/* compression page */
617 	uchar_t	un_rsvd_status;		/* Reservation Status */
618 	kstat_t *un_errstats;		/* for error statistics */
619 	int	un_init_options;  	/* Init time drive options */
620 	int	un_save_fileno;		/* Save here for recovery */
621 	daddr_t	un_save_blkno;		/* Save here for recovery */
622 	uchar_t	un_restore_pos;		/* Indication to do recovery */
623 	int	un_suspend_fileno;	/* Save fileno for SUSPEND */
624 	daddr_t	un_suspend_blkno;	/* Save blkno for SUSPEND */
625 	uchar_t	un_silent_skip;		/* to catch short reads */
626 	short	un_tids_at_suspend; /* timeouts set at suspend */
627 	kcondvar_t	un_tape_busy_cv;	/* busy cv */
628 	kcondvar_t	un_suspend_cv;	/* busy cv */
629 					/* restore on close */
630 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
631 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
632 	uchar_t	un_rqs_state;		/* see define below */
633 	caddr_t	un_uscsi_rqs_buf;	/* uscsi_rqs: buffer for RQS data */
634 	uchar_t	un_data_mod;		/* Device required data mod */
635 
636 #if defined(__i386) || defined(__amd64)
637 	ddi_dma_handle_t un_contig_mem_hdl;
638 	struct contig_mem *un_contig_mem;
639 	int un_contig_mem_available_num;
640 	int un_contig_mem_total_num;
641 	size_t un_max_contig_mem_len;
642 	kcondvar_t un_contig_mem_cv;
643 #endif
644 };
645 /*
646  * device error kstats
647  */
648 struct st_errstats {
649 	struct kstat_named	st_softerrs;
650 	struct kstat_named	st_harderrs;
651 	struct kstat_named	st_transerrs;
652 	struct kstat_named	st_vid;
653 	struct kstat_named	st_pid;
654 	struct kstat_named	st_revision;
655 	struct kstat_named	st_serial;
656 };
657 
658 /*
659  * generic log page struct
660  */
661 struct log_page {
662 #if defined(_BIT_FIELDS_LTOH)
663 	uchar_t	code	:6,	/* page code number */
664 			:2;	/* reserved */
665 #elif defined(_BIT_FIELDS_HTOL)
666 	uchar_t		:2,	/* reserved */
667 		code	:6;	/* page code number */
668 #endif	/* _BIT_FIELDS_LTOH */
669 	uchar_t	reserved;	/* reserved */
670 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
671 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
672 	/*
673 	 * Log parameters follow right after this...
674 	 */
675 };
676 
677 /*
678  * generic log page parameter struct
679  */
680 struct log_param {
681 	uchar_t	pc_hi;			/* parameter code (msb) */
682 	uchar_t	pc_lo;			/* parameter code (lsb) */
683 #if defined(_BIT_FIELDS_LTOH)
684 	uchar_t		lp	: 1,	/* list parameter */
685 				: 1,	/* reserved */
686 			tmc	: 2,	/* threshold met criteria */
687 			etc	: 1,	/* enable threshold comparison */
688 			tsd	: 1,	/* target save disable */
689 			ds	: 1,	/* disable save */
690 			du	: 1;	/* disable update */
691 #elif defined(_BIT_FIELDS_HTOL)
692 	uchar_t		du	: 1,	/* disable update */
693 			ds	: 1,	/* disable save */
694 			tsd	: 1,	/* target save disable */
695 			etc	: 1,	/* enable threshold comparison */
696 			tmc	: 2,	/* threshold met criteria */
697 				: 1,	/* reserved */
698 			lp	: 1;	/* list parameter */
699 #endif	/* _BIT_FIELDS_LTOH */
700 	uchar_t	length;		/* length of bytes to follow */
701 	/*
702 	 * Parameter values follow right after this...
703 	 */
704 };
705 /*
706  * TapeAlert structures
707  */
708 
709 struct st_tape_alert_parameter {
710 	struct log_param log_param;
711 	uchar_t	param_value;
712 };
713 
714 struct st_tape_alert {
715 	struct log_page log_page;
716 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
717 };
718 
719 #define	TAPE_ALERT_PARAMETER_LENGTH \
720 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
721 
722 struct log_sequential_page_parameter {
723 	struct log_param log_param;
724 	uchar_t param_value[8];
725 };
726 
727 struct log_sequential_page {
728 	struct log_page log_page;
729 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
730 };
731 
732 #if !defined(__lint)
733 _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
734 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
735 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
736 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
737 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
738 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
739 _NOTE(SCHEME_PROTECTS_DATA("save sharing",
740 	scsi_tape::un_allow_large_xfer
741 	scsi_tape::un_maxbsize
742 	scsi_tape::un_maxdma
743 ))
744 #endif
745 
746 
747 /*
748  * driver states..
749  */
750 #define	ST_STATE_CLOSED				0
751 #define	ST_STATE_OFFLINE			1
752 #define	ST_STATE_INITIALIZING			2
753 #define	ST_STATE_OPENING			3
754 #define	ST_STATE_OPEN_PENDING_IO		4
755 #define	ST_STATE_APPEND_TESTING			5
756 #define	ST_STATE_OPEN				6
757 #define	ST_STATE_RESOURCE_WAIT			7
758 #define	ST_STATE_CLOSING			8
759 #define	ST_STATE_SENSING			9
760 #define	ST_STATE_CLOSE_PENDING_OPEN		10
761 
762 /*
763  * Power management state
764  */
765 #define	ST_PWR_NORMAL				0
766 #define	ST_PWR_SUSPENDED			1
767 
768 /*
769  * operation codes
770  */
771 
772 #define	ST_OP_NIL	0
773 #define	ST_OP_CTL	1
774 #define	ST_OP_READ	2
775 #define	ST_OP_WRITE	3
776 #define	ST_OP_WEOF	4
777 
778 /*
779  * eof/eot/eom codes.
780  */
781 
782 #define	ST_NO_EOF		0x00
783 #define	ST_EOF_PENDING		0x01	/* filemark pending */
784 #define	ST_EOF			0x02	/* at filemark */
785 #define	ST_EOT_PENDING		0x03	/* logical eot pending */
786 #define	ST_EOT			0x04	/* at logical eot */
787 #define	ST_EOM			0x05	/* at physical eot */
788 #define	ST_WRITE_AFTER_EOM	0x06	/* flag for allowing writes after EOM */
789 
790 #define	IN_EOF(un)	(un->un_eof == ST_EOF_PENDING || un->un_eof == ST_EOF)
791 
792 /* un_rqs_state codes */
793 
794 #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
795 #define	ST_RQS_VALID		0x2	/* RQS data is valid */
796 #define	ST_RQS_READ		0x4	/* RQS data was read */
797 #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
798 
799 /*
800  * stintr codes
801  */
802 
803 #define	COMMAND_DONE					0
804 #define	COMMAND_DONE_ERROR				1
805 #define	COMMAND_DONE_ERROR_RECOVERED			2
806 #define	QUE_COMMAND					3
807 #define	QUE_BUSY_COMMAND				4
808 #define	QUE_SENSE					5
809 #define	JUST_RETURN					6
810 #define	COMMAND_DONE_EACCES				7
811 #define	QUE_LAST_COMMAND				8
812 
813 
814 /*
815  *	Reservation Status
816  *
817  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
818  *		         in between opens and also to indicate the reservation
819  *		         has not been done till now.
820  * ST_RELEASE	        -Tape Unit is Released.
821  * ST_RESERVE	        -Tape Unit is Reserved.
822  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
823  *
824  */
825 #define	ST_INIT_RESERVE			0x001
826 #define	ST_RELEASE			0x002
827 #define	ST_RESERVE			0x004
828 #define	ST_PRESERVE_RESERVE		0x008
829 #define	ST_RESERVATION_CONFLICT 	0x010
830 #define	ST_LOST_RESERVE			0x020
831 #define	ST_APPLICATION_RESERVATIONS	0x040
832 #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
833 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
834 
835 /*
836  * Service action defines for Persistant Reservation Commands
837  */
838 #define	ST_SA_SCSI3_REGISTER			0x00
839 #define	ST_SA_SCSI3_RESERVE			0x01
840 #define	ST_SA_SCSI3_RELEASE			0x02
841 #define	ST_SA_SCSI3_CLEAR			0x03
842 #define	ST_SA_SCSI3_PREEMPT			0x04
843 #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
844 #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
845 #define	ST_SA_MASK				0x1f
846 
847 #define	ST_RESERVATION_DELAY		500000
848 
849 /*
850  * Asynch I/O tunables
851  */
852 #define	ST_MAX_THROTTLE		4
853 
854 /*
855  * 60 minutes seems a reasonable amount of time
856  * to wait for tape space operations to complete.
857  *
858  */
859 #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
860 #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
861 
862 /*
863  * 2 minutes seems a reasonable amount of time
864  * to wait for tape i/o operations to complete.
865  *
866  */
867 #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
868 #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
869 
870 
871 /*
872  * 10 seconds is what we'll wait if we get a Busy Status back
873  */
874 #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
875 #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
876 #define	ST_INTERRUPT_CONTEXT	1
877 #define	ST_START_CONTEXT	2
878 
879 /*
880  * Number of times we'll retry a normal operation.
881  *
882  * XXX This includes retries due to transport failure as well as
883  * XXX busy timeouts- Need to distinguish between Target and Transport
884  * XXX failure.
885  */
886 
887 #define	ST_RETRY_COUNT		20
888 
889 /*
890  * Number of times to retry a failed selection
891  */
892 #define	ST_SEL_RETRY_COUNT		2
893 
894 /*
895  * es_code value for deferred error
896  * should be moved to sense.h
897  */
898 
899 #define	ST_DEFERRED_ERROR		0x01
900 
901 /*
902  * Maximum number of units (determined by minor device byte)
903  */
904 #define	ST_MAXUNIT	128
905 
906 /*
907  * Time to wait for completion of a command before cancelling it.
908  * For SUSPEND use only
909  */
910 #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
911 
912 #ifndef	SECSIZE
913 #define	SECSIZE	512
914 #endif
915 #ifndef	SECDIV
916 #define	SECDIV	9
917 #endif
918 
919 /*
920  * convenient defines
921  */
922 #define	ST_SCSI_DEVP	(un->un_sd)
923 #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
924 #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
925 #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
926 #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
927 #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
928 
929 #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
930 #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
931 #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
932 #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
933 #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
934 #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
935 #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
936 #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
937 #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
938 
939 #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
940 	((un)->un_state == ST_STATE_SENSING && \
941 		(un)->un_laststate == ST_STATE_CLOSING))
942 
943 #define	ASYNC_CMD	0
944 #define	SYNC_CMD	1
945 
946 /*
947  * Flush tape wait queue as needed.
948  */
949 
950 #define	IS_PE_FLAG_SET(un) ((un)->un_persistence && (un)->un_persist_errors)
951 
952 #define	TURN_PE_ON(un)		st_turn_pe_on(un)
953 #define	TURN_PE_OFF(un)		st_turn_pe_off(un)
954 #define	SET_PE_FLAG(un)		st_set_pe_flag(un)
955 #define	CLEAR_PE(un)		st_clear_pe(un)
956 
957 #define	st_bioerror(bp, error) \
958 		{ bioerror(bp, error); \
959 		un->un_errno = error; }
960 
961 /*
962  * Macros for internal coding of count for SPACE command:
963  *
964  * Isfmk is 1 when spacing filemarks; 0 when spacing records:
965  * bit 24 set indicates a space filemark command.
966  * Fmk sets the filemark bit (24) and changes a backspace
967  * count into a positive number with the sign bit set.
968  * Blk changes a backspace count into a positive number with
969  * the sign bit set.
970  * space_cnt converts backwards counts to negative numbers.
971  */
972 #define	Isfmk(x)	((x & (1<<24)) != 0)
973 #define	Fmk(x)		((1<<24)|((x < 0) ? ((-(x)) | (1<<30)): x))
974 #define	Blk(x)		((x < 0)? ((-(x))|(1<<30)): x)
975 #define	space_cnt(x)	(((x) & (1<<30))? (-((x)&((1<<24)-1))):(x)&((1<<24)-1))
976 
977 
978 #define	GET_SOFT_STATE(dev)						\
979 	register struct scsi_tape *un;					\
980 	register int instance;						\
981 									\
982 	instance = MTUNIT(dev);						\
983 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
984 		return (ENXIO);
985 
986 /*
987  * Debugging turned on via conditional compilation switch -DSTDEBUG
988  */
989 #ifdef DEBUG
990 #define	STDEBUG
991 #endif
992 
993 #ifdef	STDEBUG
994 #define	DEBUGGING	((scsi_options & SCSI_DEBUG_TGT) || st_debug > 1)
995 
996 
997 #define	ST_DEBUG1	if (st_debug >= 1) scsi_log	/* initialization */
998 #define	ST_DEBUG	ST_DEBUG1
999 
1000 #define	ST_DEBUG2	if (st_debug >= 2) scsi_log	/* errors and UA's */
1001 #define	ST_DEBUG3	if (st_debug >= 3) scsi_log	/* func calls */
1002 #define	ST_DEBUG4	if (st_debug >= 4) scsi_log	/* ioctl calls */
1003 #define	ST_DEBUG5	if (st_debug >= 5) scsi_log
1004 #define	ST_DEBUG6	if (st_debug >= 6) scsi_log	/* full data tracking */
1005 
1006 #define	ST_DEBUG_SP	if (st_debug == 10) scsi_log	/* special cases */
1007 
1008 #else
1009 
1010 #define	st_debug	(0)
1011 #define	DEBUGGING	(0)
1012 #define	ST_DEBUG	if (0) scsi_log
1013 #define	ST_DEBUG1	if (0) scsi_log
1014 #define	ST_DEBUG2	if (0) scsi_log
1015 #define	ST_DEBUG3	if (0) scsi_log
1016 #define	ST_DEBUG4	if (0) scsi_log
1017 #define	ST_DEBUG5	if (0) scsi_log
1018 #define	ST_DEBUG6	if (0) scsi_log
1019 
1020 #define	ST_DEBUG_SP	if (0) scsi_log /* special cases */
1021 
1022 #endif
1023 
1024 /*
1025  * Media access values
1026  */
1027 #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
1028 
1029 /*
1030  * SCSI tape mode sense page information
1031  */
1032 #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
1033 #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
1034 #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
1035 #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
1036 
1037 /*
1038  * SCSI tape data compression Page definition.
1039  */
1040 #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
1041 
1042 
1043 
1044 /*
1045  * maxbsize values
1046  */
1047 #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
1048 
1049 #define	ONE_MEG			(1024 * 1024)
1050 
1051 /*
1052  * generic soft error reporting
1053  *
1054  * What we are doing here is allowing a greater number of errors to occur on
1055  * smaller transfers (i.e. usually at the beginning of the tape), than on
1056  * the rest of the tape.
1057  *
1058  * A small transfer is defined as :
1059  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
1060  *
1061  * A larget tranfer is defined as :
1062  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
1063  *
1064  */
1065 #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
1066 #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
1067 
1068 /*
1069  * soft error reporting for exabyte
1070  */
1071 #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
1072 
1073 #define	SENSE_19_BITS  \
1074 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
1075 #define	SENSE_20_BITS  \
1076 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
1077 #define	SENSE_21_BITS  \
1078 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
1079 
1080 /* these are defined in percentages */
1081 #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
1082 #define	EXABYTE_READ_ERROR_THRESHOLD	3
1083 /*
1084  * minumum amount of data transfer(MB) for checking soft error rate.
1085  */
1086 #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
1087 
1088 #define	CLN	0x8
1089 #define	CLND	0x10
1090 
1091 /*
1092  * soft error reporting for Archive 4mm DAT
1093  */
1094 
1095 #define	LOG_SENSE_LENGTH		0xff
1096 #define	MIN_LOG_SENSE_LENGTH		0x2b
1097 #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
1098 #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
1099 #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
1100 #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
1101 
1102 /*
1103  * ST timeouts that need to be cancelled for suspend
1104  */
1105 #define	ST_HIB_TID	0x01
1106 #define	ST_DELAY_TID	0x02
1107 
1108 #ifdef	__cplusplus
1109 }
1110 #endif
1111 
1112 #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1113