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