xref: /titanic_52/usr/src/uts/common/sys/scsi/targets/stdef.h (revision 47911a7d5f24c2fc37e7b5bcc696fe32e750c16c)
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  * One_command parameter data for REPORT SUPPORTED OPERATION CODES.
571  */
572 struct one_com_des {
573 #if defined(_BIT_FIELDS_LTOH)
574 	uchar_t reserved0;
575 	uchar_t support:	3,	/* support value */
576 		reserved1:	4,
577 		ctdp:		1;	/* cmd timeouts descriptor present */
578 	ushort_t cdb_size;		/* cdb size */
579 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
580 #elif defined(_BIT_FIELDS_HTOL)
581 	uchar_t reserved0;
582 	uchar_t ctdp:		1,	/* cmd timeouts descriptor present */
583 		reserved1:	4,
584 		support:	3;	/* support value */
585 	ushort_t cdb_size;		/* cdb size */
586 	uchar_t usage[CDB_GROUP4];	/* 16 bytes, the largest CDB group */
587 #else
588 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
589 #endif /* _BIT_FIELDS_LTOH */
590 };
591 
592 /*
593  * Command timeouts descriptor
594  */
595 struct com_timeout_des {
596 	ushort_t des_len;	/* descriptor length */
597 	uchar_t reserved;
598 	uchar_t com_spe;	/* command specific */
599 	uint_t nom_timeout;	/* nominal command processing timeout */
600 	uint_t rec_timeout;	/* recommended command timeout */
601 };
602 
603 /*
604  * Reporting options
605  */
606 #define	ALL_COMMAND_DATA_FORMAT			0
607 #define	ONE_COMMAND_NO_SERVICE_DATA_FORMAT	1
608 #define	ONE_COMMAND_DATA_FORMAT			2
609 
610 /*
611  * Support values in One_command parameter data
612  */
613 #define	SUPPORT_VALUES_NOT_AVAILABLE		0
614 #define	SUPPORT_VALUES_NOT_SUPPORT		1
615 #define	SUPPORT_VALUES_SUPPORT_SCSI		3
616 #define	SUPPORT_VALUES_SUPPORT_VENDOR		5
617 
618 /*
619  * Parameter data for REPORT DENSITY SUPPORT command
620  */
621 struct report_density_header {
622 	ushort_t ava_dens_len;		/* available density support length */
623 	uchar_t reserved0;
624 	uchar_t reserved1;
625 };
626 
627 struct report_density_desc {
628 #if defined(_BIT_FIELDS_LTOH)
629 	uchar_t pri_den;		/* primary density code */
630 	uchar_t sec_den;		/* secondary density code */
631 	uchar_t dlv:1;			/* descriptor length valid */
632 	uchar_t reserved:4;
633 	uchar_t deflt:1;		/* is default density */
634 	uchar_t dup:1;			/* pri density has one descriptor */
635 	uchar_t wrtok:1;		/* support writing to media */
636 	uchar_t desc_len_hi;		/* descriptor length high */
637 	uchar_t desc_len_low;		/* descriptor length low */
638 	uchar_t bits_per_mm[3];		/* bits per mm */
639 	uchar_t media_width_hi;		/* media width high */
640 	uchar_t media_width_low;	/* media width low */
641 	ushort_t tracks;		/* tracks */
642 	uint_t capacity;		/* capacity */
643 	uchar_t ass_org[8];		/* assigning organization */
644 	uchar_t den_name[8];		/* density name */
645 	uchar_t description[20];	/* description */
646 #elif defined(_BIT_FIELDS_HTOL)
647 	uchar_t pri_den;		/* primary density code */
648 	uchar_t sec_den;		/* secondary density code */
649 	uchar_t wrtok:1;		/* support writing to media */
650 	uchar_t dup:1;			/* pri density has one descriptor */
651 	uchar_t deflt:1;		/* is default density */
652 	uchar_t reserved:4;
653 	uchar_t dlv:1;			/* descriptor length valid */
654 	uchar_t desc_len_hi;		/* descriptor length high */
655 	uchar_t desc_len_low;		/* descriptor length low */
656 	uchar_t bits_per_mm[3];		/* bits per mm */
657 	uchar_t media_width_hi;		/* media width high */
658 	uchar_t media_width_low;	/* media width low */
659 	ushort_t tracks;		/* tracks */
660 	uint_t capacity;		/* capacity */
661 	uchar_t ass_org[8];		/* assigning organization */
662 	uchar_t den_name[8];		/* density name */
663 	uchar_t description[20];	/* description */
664 #else
665 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
666 #endif  /* _BIT_FIELDS_LTOH */
667 };
668 
669 /*
670  * Data returned from the READ BLOCK LIMITS command.
671  */
672 
673 #define	RBLSIZE	(sizeof (struct read_blklim))
674 struct read_blklim {
675 #if defined(_BIT_FIELDS_HTOL)
676 	uchar_t	reserved:	3;	/* reserved */
677 	uchar_t granularity:	5;	/* Minimum Modularity */
678 #elif defined(_BIT_FIELDS_LTOH)
679 	uchar_t granularity:	5;	/* Minimum Modularity */
680 	uchar_t	reserved:	3;	/* reserved */
681 #endif
682 	uchar_t	max_hi;			/* Maximum block length, high byte */
683 	uchar_t	max_mid;		/* Maximum block length, middle byte */
684 	uchar_t	max_lo;			/* Maximum block length, low byte */
685 	uchar_t	min_hi;			/* Minimum block length, high byte */
686 	uchar_t	min_lo;			/* Minimum block length, low byte */
687 };
688 
689 /*
690  * operation codes
691  */
692 typedef enum {
693 	ST_OP_NIL,
694 	ST_OP_CTL,
695 	ST_OP_READ,
696 	ST_OP_WRITE,
697 	ST_OP_WEOF
698 }optype;
699 
700 /*
701  * eof/eot/eom codes.
702  */
703 typedef enum {
704 	ST_NO_EOF,
705 	ST_EOF_PENDING,		/* filemark pending */
706 	ST_EOF,			/* at filemark */
707 	ST_EOT_PENDING,		/* logical eot pending */
708 	ST_EOT,			/* at logical eot */
709 	ST_EOM,			/* at physical eot */
710 	ST_WRITE_AFTER_EOM	/* flag for allowing writes after EOM */
711 }pstatus;
712 
713 typedef enum { invalid, legacy, logical } posmode;
714 
715 typedef struct tapepos {
716 	uint64_t lgclblkno;
717 	int32_t fileno;
718 	int32_t blkno;
719 	int32_t partition;
720 	pstatus eof;			/* eof states */
721 	posmode	pmode;
722 	char	pad[4];
723 }tapepos_t;
724 
725 /* byte 1 of cdb for type of read position command */
726 typedef enum {
727 	SHORT_POS	= 0,
728 	LONG_POS	= 6,
729 	EXT_POS		= 8,
730 	NO_POS		= 0xff	/* Drive doesn't support read position */
731 } read_p_types;
732 
733 
734 /*
735  * Data returned from the READ POSITION command.
736  */
737 
738 typedef struct tape_position {
739 #if defined(_BIT_FIELDS_HTOL)
740 	uchar_t begin_of_part:	1;
741 	uchar_t end_of_part:	1;
742 	uchar_t blk_cnt_unkwn:	1;
743 	uchar_t byte_cnt_unkwn:	1;
744 	uchar_t reserved0:	1;
745 	uchar_t blk_posi_unkwn:	1;
746 	uchar_t posi_err:	1;
747 	uchar_t reserved1:	1;
748 #elif defined(_BIT_FIELDS_LTOH)
749 	uchar_t reserved1:	1;
750 	uchar_t posi_err:	1;
751 	uchar_t blk_posi_unkwn:	1;
752 	uchar_t reserved0:	1;
753 	uchar_t byte_cnt_unkwn:	1;
754 	uchar_t blk_cnt_unkwn:	1;
755 	uchar_t end_of_part:	1;
756 	uchar_t begin_of_part:	1;
757 #endif
758 	uchar_t partition_number;
759 	uchar_t reserved2[2];
760 	uint32_t host_block;
761 	uint32_t media_block;
762 	uchar_t reserved3;
763 	uchar_t block_in_buff[3];
764 	uint32_t byte_in_buff;
765 }tape_position_t;
766 
767 
768 typedef struct tape_position_long {
769 #if defined(_BIT_FIELDS_HTOL)
770 	uint32_t begin_of_part:	1;
771 	uint32_t end_of_part:	1;
772 	uint32_t reserved0:	2;
773 	uint32_t mrk_posi_unkwn:1;
774 	uint32_t blk_posi_unkwn:1;
775 	uint32_t reserved1:	2;
776 #elif defined(_BIT_FIELDS_LTOH)
777 	uint32_t reserved1:	2;
778 	uint32_t blk_posi_unkwn:1;
779 	uint32_t mrk_posi_unkwn:1;
780 	uint32_t reserved0:	2;
781 	uint32_t end_of_part:   1;
782 	uint32_t begin_of_part: 1;
783 #endif
784 	uint32_t reserved2:	24;
785 	uint32_t partition;
786 	uint64_t block_number;
787 	uint64_t file_number;
788 	uint64_t set_number;
789 }tape_position_long_t;
790 
791 typedef struct tape_position_ext {
792 #if defined(_BIT_FIELDS_HTOL)
793 	uint32_t begin_of_part:	1;
794 	uint32_t end_of_part:	1;
795 	uint32_t blk_cnt_unkwn:	1;
796 	uint32_t byte_cnt_unkwn:1;
797 	uint32_t mrk_posi_unkwn:1;
798 	uint32_t blk_posi_unkwn:1;
799 	uint32_t posi_err:	1;
800 	uint32_t reserved0:	1;
801 	uint32_t partition:	8;
802 	uint32_t parameter_len:	16;
803 /* start next word */
804 	uint32_t reserved1:	8;
805 	uint32_t blks_in_buf:	24;
806 #elif defined(_BIT_FIELDS_LTOH)
807 	uint32_t parameter_len:	16;
808 	uint32_t partition:	8;
809 	uint32_t reserved0:	1;
810 	uint32_t posi_err:	1;
811 	uint32_t blk_posi_unkwn:1;
812 	uint32_t mrk_posi_unkwn:1;
813 	uint32_t byte_cnt_unkwn:1;
814 	uint32_t blk_cnt_unkwn:	1;
815 	uint32_t end_of_part:	1;
816 	uint32_t begin_of_part:	1;
817 /* start next word */
818 	uint32_t blks_in_buf:	24;
819 	uint32_t reserved1:	8;
820 #endif
821 	uint64_t host_block;
822 	uint64_t media_block;
823 	uint64_t byte_in_buf;
824 }tape_position_ext_t;
825 
826 typedef union {
827 	tape_position_t srt;
828 	tape_position_ext_t ext;
829 	tape_position_long_t lng;
830 }read_pos_data_t;
831 
832 #ifdef _KERNEL
833 
834 #ifdef	__x86
835 /* Data structure used in big block I/O on x86/x64 platform */
836 
837 /*
838  * alloc more than one contig_mem, so mutiple I/O can be
839  * on-going simultaneously
840  */
841 #define	ST_MAX_CONTIG_MEM_NUM	3
842 
843 struct contig_mem {
844 	struct contig_mem *cm_next;
845 	size_t cm_len;
846 	caddr_t cm_addr;
847 	ddi_acc_handle_t cm_acc_hdl;
848 	struct buf *cm_bp;
849 	int cm_use_sbuf;
850 };
851 
852 #endif
853 
854 #endif /* _KERNEL */
855 
856 /*
857  * driver states..
858  */
859 typedef enum {
860 	ST_STATE_CLOSED,
861 	ST_STATE_OFFLINE,
862 	ST_STATE_INITIALIZING,
863 	ST_STATE_OPENING,
864 	ST_STATE_OPEN_PENDING_IO,
865 	ST_STATE_APPEND_TESTING,
866 	ST_STATE_OPEN,
867 	ST_STATE_RESOURCE_WAIT,
868 	ST_STATE_CLOSING,
869 	ST_STATE_SENSING,
870 	ST_STATE_CLOSE_PENDING_OPEN
871 }st_states;
872 
873 typedef enum { RDWR, RDONLY, WORM, RDWORM, FAILED } writablity;
874 
875 
876 /*
877  * Private info for scsi tapes. Pointed to by the un_private pointer
878  * of one of the SCSI_DEVICE chains.
879  */
880 
881 struct scsi_tape {
882 	struct scsi_device *un_sd;	/* back pointer to SCSI_DEVICE */
883 	struct scsi_pkt *un_rqs;	/* ptr to request sense command */
884 	struct scsi_pkt *un_mkr_pkt;	/* ptr to marker packet */
885 	kcondvar_t un_sbuf_cv;		/* cv on ownership of special buf */
886 	kcondvar_t un_queue_cv;		/* cv on all queued commands */
887 	struct	buf *un_sbufp;		/* for use in special io */
888 	char	*un_srqbufp;		/* sense buffer for special io */
889 	kcondvar_t un_clscv;		/* closing cv */
890 	struct	buf *un_quef;		/* head of wait queue */
891 	struct	buf *un_quel;		/* tail of wait queue */
892 	struct	buf *un_runqf;		/* head of run queue */
893 	struct	buf *un_runql;		/* tail of run queue */
894 	struct seq_mode *un_mspl;	/* ptr to mode select info */
895 	struct st_drivetype *un_dp;	/* ptr to drive table entry */
896 	uint_t	un_dp_size;		/* size of un_dp alloc'ed */
897 	caddr_t	un_tmpbuf;		/* buf for append, autodens ops */
898 	tapepos_t un_pos;		/* Current tape position */
899 	int	un_oflags;		/* open flags */
900 	tapepos_t un_err_pos;		/* block in file where err occurred */
901 	uint_t	un_err_resid;		/* resid from last error */
902 	short	un_fmneeded;		/* filemarks to be written - HP only */
903 	dev_t	un_dev;			/* unix device */
904 	uchar_t	un_attached;		/* unit known && attached */
905 	int	un_pwr_mgmt;		/* power management state */
906 	uchar_t	un_density_known;	/* density is known */
907 	uchar_t	un_curdens;		/* index into density table */
908 	optype	un_lastop;		/* last I/O was: read/write/ctl */
909 	st_states un_laststate;		/* last state */
910 	st_states un_state;		/* current state */
911 	uchar_t	un_status;		/* status from last sense */
912 	uchar_t	un_retry_ct;		/* retry count */
913 	uchar_t	un_tran_retry_ct;	/* transport retry count */
914 	writablity un_read_only;	/* RDWR, RDONLY, WORM, RDWORM */
915 	uchar_t	un_test_append;		/* check writing at end of tape */
916 	uchar_t un_arq_enabled;		/* auto request sense enabled */
917 	uchar_t un_untagged_qing;	/* hba has untagged quing */
918 	uchar_t	un_allow_large_xfer;	/* allow >64k xfers if requested */
919 	uchar_t	un_sbuf_busy;		/* sbuf busy flag */
920 	uchar_t	un_ncmds;		/* number of commands outstanding */
921 	uchar_t	un_throttle;		/* curr. max number of cmds outst. */
922 	uchar_t	un_last_throttle;	/* saved max number of cmds outst. */
923 	uchar_t	un_max_throttle;	/* max poss. number cmds outstanding */
924 	uchar_t	un_persistence;		/* 1 = persistence on, 0 off */
925 	uchar_t	un_persist_errors;	/* 1 = persistenced flagged */
926 	uchar_t	un_flush_on_errors;	/* HBA will flush all I/O's on a */
927 					/* check condidtion or error */
928 	uint_t	un_kbytes_xferred;	/* bytes (in K) counter */
929 	uint_t	un_last_resid;		/* keep last resid, for PE */
930 	uint_t	un_last_count;		/* keep last count, for PE */
931 	struct 	kstat *un_stats;	/* for I/O statistics */
932 	struct buf *un_rqs_bp;		/* bp used in rqpkt */
933 	struct	buf *un_wf;		/* head of write queue */
934 	struct	buf *un_wl;		/* tail of write queue */
935 	struct	read_blklim *un_rbl;	/* ptr to read block limit info */
936 	int	un_maxdma;		/* max dma xfer allowed by HBA */
937 	uint_t	un_bsize;		/* block size currently being used */
938 	int	un_maxbsize;		/* max block size allowed by drive */
939 	uint_t	un_minbsize;		/* min block size allowed by drive */
940 	int	un_errno;		/* errno (b_error) */
941 	kcondvar_t	un_state_cv;	/* mediastate condition variable */
942 	enum mtio_state	un_mediastate;	/* current media state */
943 	enum mtio_state	un_specified_mediastate;	/* expected state */
944 	timeout_id_t	un_delay_tid;	/* delayed cv tid */
945 	timeout_id_t	un_hib_tid;	/* handle interrupt busy tid */
946 	opaque_t	un_swr_token;	/* scsi_watch request token */
947 	uchar_t	un_comp_page;		/* compression page */
948 	uchar_t	un_rsvd_status;		/* Reservation Status */
949 	kstat_t *un_errstats;		/* for error statistics */
950 	int	un_init_options;  	/* Init time drive options */
951 	int	un_save_fileno;		/* Save here for recovery */
952 	daddr_t	un_save_blkno;		/* Save here for recovery */
953 	uchar_t un_restore_pos;		/* Indication to do recovery */
954 	tapepos_t un_suspend_pos;	/* Save blkno for SUSPEND */
955 	uchar_t	un_silent_skip;		/* to catch short reads */
956 	short	un_tids_at_suspend;	/* timeouts set at suspend */
957 	kcondvar_t un_tape_busy_cv;	/* busy cv */
958 	kcondvar_t un_suspend_cv;	/* busy cv */
959 					/* restore on close */
960 	uchar_t	un_eject_tape_on_failure; /* 1 = eject tape, 0 = don't */
961 	uchar_t	un_HeadClean; 		/* support and need head cleaning? */
962 	uchar_t	un_rqs_state;		/* see define below */
963 	struct scsi_extended_sense
964 	    *un_uscsi_rqs_buf;		/* uscsi_rqs: buffer for RQS data */
965 	uchar_t	un_data_mod;		/* Device required data mod */
966 	writablity (*un_wormable) (struct scsi_tape *un); /* worm test fuct */
967 	int un_max_cdb_sz;		/* max cdb size to use */
968 	read_p_types un_read_pos_type;
969 	read_pos_data_t *un_read_pos_data;
970 	struct mterror_entry_stack *un_error_entry_stk;
971 					/* latest sense cmd buffer */
972 
973 #ifdef	__x86
974 	ddi_dma_handle_t un_contig_mem_hdl;
975 	struct contig_mem *un_contig_mem;
976 	int un_contig_mem_available_num;
977 	int un_contig_mem_total_num;
978 	size_t un_max_contig_mem_len;
979 	kcondvar_t un_contig_mem_cv;
980 	int un_maxdma_arch;		/* max dma xfer allowed by HBA & arch */
981 #endif
982 };
983 
984 
985 /*
986  * device error kstats
987  */
988 struct st_errstats {
989 	struct kstat_named	st_softerrs;
990 	struct kstat_named	st_harderrs;
991 	struct kstat_named	st_transerrs;
992 	struct kstat_named	st_vid;
993 	struct kstat_named	st_pid;
994 	struct kstat_named	st_revision;
995 	struct kstat_named	st_serial;
996 };
997 
998 /*
999  * generic log page struct
1000  */
1001 struct log_page {
1002 #if defined(_BIT_FIELDS_LTOH)
1003 	uchar_t	code	:6,	/* page code number */
1004 			:2;	/* reserved */
1005 #elif defined(_BIT_FIELDS_HTOL)
1006 	uchar_t		:2,	/* reserved */
1007 		code	:6;	/* page code number */
1008 #endif	/* _BIT_FIELDS_LTOH */
1009 	uchar_t	reserved;	/* reserved */
1010 	uchar_t	length_hi;	/* length of bytes to follow (msb) */
1011 	uchar_t	length_lo;	/* length of bytes to follow (lsb) */
1012 	/*
1013 	 * Log parameters follow right after this...
1014 	 */
1015 };
1016 
1017 /*
1018  * generic log page parameter struct
1019  */
1020 struct log_param {
1021 	uchar_t	pc_hi;			/* parameter code (msb) */
1022 	uchar_t	pc_lo;			/* parameter code (lsb) */
1023 #if defined(_BIT_FIELDS_LTOH)
1024 	uchar_t		lp	: 1,	/* list parameter */
1025 				: 1,	/* reserved */
1026 			tmc	: 2,	/* threshold met criteria */
1027 			etc	: 1,	/* enable threshold comparison */
1028 			tsd	: 1,	/* target save disable */
1029 			ds	: 1,	/* disable save */
1030 			du	: 1;	/* disable update */
1031 #elif defined(_BIT_FIELDS_HTOL)
1032 	uchar_t		du	: 1,	/* disable update */
1033 			ds	: 1,	/* disable save */
1034 			tsd	: 1,	/* target save disable */
1035 			etc	: 1,	/* enable threshold comparison */
1036 			tmc	: 2,	/* threshold met criteria */
1037 				: 1,	/* reserved */
1038 			lp	: 1;	/* list parameter */
1039 #endif	/* _BIT_FIELDS_LTOH */
1040 	uchar_t	length;		/* length of bytes to follow */
1041 	/*
1042 	 * Parameter values follow right after this...
1043 	 */
1044 };
1045 /*
1046  * TapeAlert structures
1047  */
1048 
1049 struct st_tape_alert_parameter {
1050 	struct log_param log_param;
1051 	uchar_t	param_value;
1052 };
1053 
1054 struct st_tape_alert {
1055 	struct log_page log_page;
1056 	struct st_tape_alert_parameter param[TAPE_ALERT_MAX_PARA];
1057 };
1058 
1059 #define	TAPE_ALERT_PARAMETER_LENGTH \
1060 	(sizeof (struct st_tape_alert_parameter)) * TAPE_ALERT_MAX_PARA
1061 
1062 struct log_sequential_page_parameter {
1063 	struct log_param log_param;
1064 	uchar_t param_value[8];
1065 };
1066 
1067 struct log_sequential_page {
1068 	struct log_page log_page;
1069 	struct log_sequential_page_parameter param[TAPE_SEQUENTIAL_PAGE_PARA];
1070 };
1071 
1072 #if !defined(__lint)
1073 _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_tape))
1074 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_dp))
1075 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_tape::un_sd))
1076 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_tape::un_rqs))
1077 _NOTE(SCHEME_PROTECTS_DATA("protected by cv", scsi_tape::un_sbufp))
1078 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_bsize))
1079 _NOTE(SCHEME_PROTECTS_DATA("not shared", scsi_arq_status))
1080 _NOTE(SCHEME_PROTECTS_DATA("save sharing",
1081 	scsi_tape::un_allow_large_xfer
1082 	scsi_tape::un_maxbsize
1083 	scsi_tape::un_maxdma
1084 ))
1085 #ifdef	__x86
1086 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_tape::un_contig_mem_hdl))
1087 _NOTE(SCHEME_PROTECTS_DATA("not shared", contig_mem))
1088 #endif
1089 #endif
1090 
1091 
1092 /*
1093  * Power management state
1094  */
1095 #define	ST_PWR_NORMAL				0
1096 #define	ST_PWR_SUSPENDED			1
1097 
1098 
1099 #define	IN_EOF(pos)	(pos.eof == ST_EOF_PENDING || pos.eof == ST_EOF)
1100 
1101 /* un_rqs_state codes */
1102 
1103 #define	ST_RQS_OVR		0x1	/* RQS data was overwritten */
1104 #define	ST_RQS_VALID		0x2	/* RQS data is valid */
1105 #define	ST_RQS_READ		0x4	/* RQS data was read */
1106 #define	ST_RQS_ERROR		0x8	/* RQS resulted in an EIO */
1107 
1108 /*
1109  * stintr codes
1110  */
1111 
1112 #define	COMMAND_DONE					0
1113 #define	COMMAND_DONE_ERROR				1
1114 #define	COMMAND_DONE_ERROR_RECOVERED			2
1115 #define	QUE_COMMAND					3
1116 #define	QUE_BUSY_COMMAND				4
1117 #define	QUE_SENSE					5
1118 #define	JUST_RETURN					6
1119 #define	COMMAND_DONE_EACCES				7
1120 #define	QUE_LAST_COMMAND				8
1121 
1122 
1123 /*
1124  *	Reservation Status
1125  *
1126  * ST_INIT_RESERVE      -Used to check if the reservation has been lost
1127  *		         in between opens and also to indicate the reservation
1128  *		         has not been done till now.
1129  * ST_RELEASE	        -Tape Unit is Released.
1130  * ST_RESERVE	        -Tape Unit is Reserved.
1131  * ST_PRESERVE_RESERVE  -Reservation is to be preserved across opens.
1132  *
1133  */
1134 #define	ST_INIT_RESERVE			0x001
1135 #define	ST_RELEASE			0x002
1136 #define	ST_RESERVE			0x004
1137 #define	ST_PRESERVE_RESERVE		0x008
1138 #define	ST_RESERVATION_CONFLICT 	0x010
1139 #define	ST_LOST_RESERVE			0x020
1140 #define	ST_APPLICATION_RESERVATIONS	0x040
1141 #define	ST_LOST_RESERVE_BETWEEN_OPENS  \
1142 		(ST_RESERVE | ST_LOST_RESERVE | ST_PRESERVE_RESERVE)
1143 
1144 /*
1145  * Service action defines for Persistant Reservation Commands
1146  */
1147 #define	ST_SA_SCSI3_REGISTER			0x00
1148 #define	ST_SA_SCSI3_RESERVE			0x01
1149 #define	ST_SA_SCSI3_RELEASE			0x02
1150 #define	ST_SA_SCSI3_CLEAR			0x03
1151 #define	ST_SA_SCSI3_PREEMPT			0x04
1152 #define	ST_SA_SCSI3_PREEMPTANDABORT		0x05
1153 #define	ST_SA_SCSI3_REGISTERANDIGNOREKEY	0x06
1154 #define	ST_SA_MASK				0x1f
1155 
1156 #define	ST_RESERVATION_DELAY		500000
1157 
1158 /*
1159  * Asynch I/O tunables
1160  */
1161 #define	ST_MAX_THROTTLE		4
1162 
1163 /*
1164  * 60 minutes seems a reasonable amount of time
1165  * to wait for tape space operations to complete.
1166  *
1167  */
1168 #define	ST_SPACE_TIME	MINUTES(60)	/* 60 minutes per space operation */
1169 #define	ST_LONG_SPACE_TIME_X	5	/* multipiler for long space ops */
1170 
1171 /*
1172  * 2 minutes seems a reasonable amount of time
1173  * to wait for tape i/o operations to complete.
1174  *
1175  */
1176 #define	ST_IO_TIME	MINUTES(2)	/* minutes per i/o */
1177 #define	ST_LONG_TIMEOUT_X	5	/* multiplier for very long timeouts */
1178 
1179 
1180 /*
1181  * 10 seconds is what we'll wait if we get a Busy Status back
1182  */
1183 #define	ST_STATUS_BUSY_TIMEOUT	10*hz	/* seconds Busy Waiting */
1184 #define	ST_TRAN_BUSY_TIMEOUT	1*hz	/* seconds retry on TRAN_BSY */
1185 #define	ST_INTERRUPT_CONTEXT	1
1186 #define	ST_START_CONTEXT	2
1187 
1188 /*
1189  * Number of times we'll retry a normal operation.
1190  *
1191  * XXX This includes retries due to transport failure as well as
1192  * XXX busy timeouts- Need to distinguish between Target and Transport
1193  * XXX failure.
1194  */
1195 
1196 #define	ST_RETRY_COUNT		20
1197 
1198 /*
1199  * Number of times to retry a failed selection
1200  */
1201 #define	ST_SEL_RETRY_COUNT		2
1202 
1203 /*
1204  * es_code value for deferred error
1205  * should be moved to sense.h
1206  */
1207 
1208 #define	ST_DEFERRED_ERROR		0x01
1209 
1210 /*
1211  * Maximum number of units (determined by minor device byte)
1212  */
1213 #define	ST_MAXUNIT	128
1214 
1215 /*
1216  * Time to wait for completion of a command before cancelling it.
1217  * For SUSPEND use only
1218  */
1219 #define	ST_WAIT_CMDS_COMPLETE		10	/* seconds */
1220 
1221 #ifndef	SECSIZE
1222 #define	SECSIZE	512
1223 #endif
1224 #ifndef	SECDIV
1225 #define	SECDIV	9
1226 #endif
1227 
1228 /*
1229  * convenient defines
1230  */
1231 #define	ST_SCSI_DEVP	(un->un_sd)
1232 #define	ST_DEVINFO		(ST_SCSI_DEVP->sd_dev)
1233 #define	ST_INQUIRY		(ST_SCSI_DEVP->sd_inq)
1234 #define	ST_RQSENSE		(ST_SCSI_DEVP->sd_sense)
1235 #define	ST_MUTEX		(&ST_SCSI_DEVP->sd_mutex)
1236 #define	ROUTE			(&ST_SCSI_DEVP->sd_address)
1237 
1238 #define	BSD_BEHAVIOR	(getminor(un->un_dev) & MT_BSD)
1239 #define	SVR4_BEHAVIOR	((getminor(un->un_dev) & MT_BSD) == 0)
1240 #define	SCBP(pkt)		((struct scsi_status *)(pkt)->pkt_scbp)
1241 #define	SCBP_C(pkt)		((*(pkt)->pkt_scbp) & STATUS_MASK)
1242 #define	CDBP(pkt)		((union scsi_cdb *)(pkt)->pkt_cdbp)
1243 #define	BP_PKT(bp)		((struct scsi_pkt *)(bp)->av_back)
1244 #define	SET_BP_PKT(bp, pkt)	((bp)->av_back = (struct buf *)(pkt))
1245 #define	BP_UCMD(bp)		((struct uscsi_cmd *)(bp)->b_back)
1246 #define	USCSI_CMD(bp)	(((bp) == un->un_sbufp) && (BP_UCMD(bp)))
1247 
1248 #define	IS_CLOSING(un)	((un)->un_state == ST_STATE_CLOSING || \
1249 	((un)->un_state == ST_STATE_SENSING && \
1250 		(un)->un_laststate == ST_STATE_CLOSING))
1251 
1252 #define	ASYNC_CMD	0
1253 #define	SYNC_CMD	1
1254 
1255 /*
1256  * Flush tape wait queue as needed.
1257  */
1258 
1259 #define	IS_PE_FLAG_SET(un) ((un)->un_persistence && (un)->un_persist_errors)
1260 
1261 #define	TURN_PE_ON(un)		st_turn_pe_on(un)
1262 #define	TURN_PE_OFF(un)		st_turn_pe_off(un)
1263 #define	SET_PE_FLAG(un)		st_set_pe_flag(un)
1264 #define	CLEAR_PE(un)		st_clear_pe(un)
1265 
1266 #define	st_bioerror(bp, error) \
1267 		{ bioerror(bp, error); \
1268 		un->un_errno = error; }
1269 
1270 /*
1271  * Macros for internal coding of count for SPACE command:
1272  *
1273  * Isfmk is 1 when spacing filemarks; 0 when spacing records:
1274  * bit 24 set indicates a space filemark command.
1275  * Fmk sets the filemark bit (24) and changes a backspace
1276  * count into a positive number with the sign bit set.
1277  * Blk changes a backspace count into a positive number with
1278  * the sign bit set.
1279  * space_cnt converts backwards counts to negative numbers.
1280  */
1281 #define	SP_BLK		0
1282 #define	SP_FLM		((1<<24))
1283 #define	SP_SQFLM	((2<<24))
1284 #define	SP_EOD		((3<<24))
1285 #define	SP_BACKSP	((1<<30))
1286 #define	SP_CMD_MASK	((7<<24))
1287 #define	SP_CNT_MASK	((1<<24)-1)
1288 
1289 /* Macros to assemble space cmds */
1290 #define	SPACE(cmd, cnt)	((cnt < 0) ? (SP_BACKSP | (-(cnt)) | cmd) : (cmd | cnt))
1291 #define	Fmk(x)		SPACE(SP_FLM, x)
1292 #define	Blk(x)		SPACE(SP_BLK, x)
1293 
1294 /* Macros to interpret space cmds */
1295 #define	SPACE_CNT(x)	(((x) & SP_BACKSP)? \
1296 	(-((x)&(SP_CNT_MASK))):(x)&(SP_CNT_MASK))
1297 #define	SPACE_TYPE(x)	((x & SP_CMD_MASK)>>24)
1298 
1299 
1300 /* Defines for byte 4 of load/unload cmd */
1301 #define	LD_UNLOAD	0
1302 #define	LD_LOAD		1
1303 #define	LD_RETEN	2
1304 #define	LD_EOT		4
1305 #define	LD_HOLD		8
1306 
1307 /* Defines for byte 4 of prevent/allow media removal */
1308 #define	MR_UNLOCK	0
1309 #define	MR_LOCK		1
1310 
1311 #define	GET_SOFT_STATE(dev)						\
1312 	register struct scsi_tape *un;					\
1313 	register int instance;						\
1314 									\
1315 	instance = MTUNIT(dev);						\
1316 	if ((un = ddi_get_soft_state(st_state, instance)) == NULL)	\
1317 		return (ENXIO);
1318 
1319 /*
1320  * Debugging turned on via conditional compilation switch -DSTDEBUG
1321  */
1322 #ifdef DEBUG
1323 #define	STDEBUG
1324 #endif
1325 
1326 #ifdef	STDEBUG
1327 #define	DEBUGGING	((scsi_options & SCSI_DEBUG_TGT) || (st_debug & 0xf))
1328 
1329 #define	ST_DARGS	st_label, SCSI_DEBUG
1330 
1331 
1332 	/* initialization */
1333 #define	ST_DEBUG1	if ((st_debug & 0xf) >= 1) scsi_log
1334 #define	ST_DEBUG	ST_DEBUG1
1335 
1336 	/* errors and UA's */
1337 #define	ST_DEBUG2	if ((st_debug & 0xf) >= 2) scsi_log
1338 
1339 	/* func calls */
1340 #define	ST_DEBUG3	if ((st_debug & 0xf) >= 3) scsi_log
1341 
1342 	/* ioctl calls */
1343 #define	ST_DEBUG4	if ((st_debug & 0xf) >= 4) scsi_log
1344 
1345 #define	ST_DEBUG5	if ((st_debug & 0xf) >= 5) scsi_log
1346 
1347 	/* full data tracking */
1348 #define	ST_DEBUG6	if ((st_debug & 0xf) >= 6) scsi_log
1349 
1350 	/* special cases */
1351 #define	ST_DEBUG_SP	if ((st_debug & 0xf) == 10) scsi_log
1352 
1353 	/* Entry Point Functions */
1354 #define	ST_ENTR(d, fn)	if (st_debug & 0x10) scsi_log(d, ST_DARGS, #fn)
1355 
1356 	/* Non-Entry Point Functions */
1357 #define	ST_FUNC(d, fn)	if (st_debug & 0x20) scsi_log(d, ST_DARGS, #fn)
1358 
1359 	/* Space Information */
1360 #define	ST_SPAC		if (st_debug & 0x40) scsi_log
1361 
1362 	/* CDB's sent */
1363 #define	ST_CDB(d, cmnt, cdb) if (st_debug & 0x180) \
1364     st_print_cdb(d, ST_DARGS, cmnt, cdb)
1365 #define	ST_SENSE(d, cmnt, sense, size) if (st_debug & 0x200) \
1366     st_clean_print(d, ST_DARGS, cmnt, sense, size)
1367 
1368 #else
1369 
1370 #define	st_debug	(0)
1371 #define	DEBUGGING	(0)
1372 #define	ST_DEBUG	if (0) scsi_log
1373 #define	ST_DEBUG1	if (0) scsi_log
1374 #define	ST_DEBUG2	if (0) scsi_log
1375 #define	ST_DEBUG3	if (0) scsi_log
1376 #define	ST_DEBUG4	if (0) scsi_log
1377 #define	ST_DEBUG5	if (0) scsi_log
1378 #define	ST_DEBUG6	if (0) scsi_log
1379 
1380 #define	ST_DEBUG_SP	if (0) scsi_log /* special cases */
1381 
1382 #define	ST_ENTR(d, fn)
1383 #define	ST_FUNC(d, fn)
1384 #define	ST_SPAC		if (0) scsi_log
1385 #define	ST_CDB(d, cmnt, cdb)
1386 #define	ST_SENSE(d, cmnt, sense, size)
1387 
1388 #endif
1389 
1390 /*
1391  * Media access values
1392  */
1393 #define	MEDIA_ACCESS_DELAY 5000000	/* usecs wait for media state change */
1394 
1395 /*
1396  * SCSI tape mode sense page information
1397  */
1398 #define	ST_DEV_CONFIG_PAGE	0x10	/* device config mode page */
1399 #define	ST_DEV_CONFIG_NO_COMP	0x00	/* use no compression */
1400 #define	ST_DEV_CONFIG_DEF_COMP	0x01	/* use default compression alg */
1401 #define	ST_COMPRESSION_DENSITY	3	/* compression minor number */
1402 
1403 /*
1404  * SCSI tape data compression Page definition.
1405  */
1406 #define	ST_DEV_DATACOMP_PAGE	0x0F	/* data compression page */
1407 
1408 
1409 
1410 /*
1411  * maxbsize values
1412  */
1413 #define	MAXBSIZE_UNKNOWN	-2	/*  not found yet */
1414 
1415 #define	ONE_MEG			(1024 * 1024)
1416 
1417 /*
1418  * generic soft error reporting
1419  *
1420  * What we are doing here is allowing a greater number of errors to occur on
1421  * smaller transfers (i.e. usually at the beginning of the tape), than on
1422  * the rest of the tape.
1423  *
1424  * A small transfer is defined as :
1425  * Transfers <= SOFT_ERROR_WARNING_THRESHOLD  allow about 1.5 times more errors
1426  *
1427  * A larget tranfer is defined as :
1428  * Transfers >  SOFT_ERROR_WARNING_THRESHOLD  allow normal amount
1429  *
1430  */
1431 #define	READ_SOFT_ERROR_WARNING_THRESHOLD    (25 * ONE_MEG)
1432 #define	WRITE_SOFT_ERROR_WARNING_THRESHOLD    (20 * ONE_MEG)
1433 
1434 /*
1435  * soft error reporting for exabyte
1436  */
1437 #define	TAPE_SENSE_LENGTH	32	/* allows for softerror info */
1438 
1439 #define	SENSE_19_BITS  \
1440 	"\20\10PF\07BPE\06FPE\05ME\04ECO\03TME\02TNP\01LBOT"
1441 #define	SENSE_20_BITS  \
1442 	"\20\10RSVD\07RSVD\06WP\05FMKE\04URE\03WE1\02SSE\01FW"
1443 #define	SENSE_21_BITS  \
1444 	"\20\10RSVD\07RSVD\06RRR\05CLND\04CLN\03PEOT\02WSEB\01WSE0"
1445 
1446 /* these are defined in percentages */
1447 #define	EXABYTE_WRITE_ERROR_THRESHOLD	6
1448 #define	EXABYTE_READ_ERROR_THRESHOLD	3
1449 /*
1450  * minumum amount of data transfer(MB) for checking soft error rate.
1451  */
1452 #define	EXABYTE_MIN_TRANSFER			(25 * ONE_MEG)
1453 
1454 #define	CLN	0x8
1455 #define	CLND	0x10
1456 
1457 /*
1458  * soft error reporting for Archive 4mm DAT
1459  */
1460 
1461 #define	LOG_SENSE_LENGTH		0xff
1462 #define	MIN_LOG_SENSE_LENGTH		0x2b
1463 #define	DAT_SMALL_WRITE_ERROR_THRESHOLD	40	/* retries per 20 mg */
1464 #define	DAT_LARGE_WRITE_ERROR_THRESHOLD	200	/* retries for more 20 mg */
1465 #define	DAT_SMALL_READ_ERROR_THRESHOLD	5	/* errors allowed */
1466 #define	DAT_LARGE_READ_ERROR_THRESHOLD	3	/* errors allowed */
1467 
1468 /*
1469  * ST timeouts that need to be cancelled for suspend
1470  */
1471 #define	ST_HIB_TID	0x01
1472 #define	ST_DELAY_TID	0x02
1473 
1474 #ifdef	__cplusplus
1475 }
1476 #endif
1477 
1478 #endif	/* _SYS_SCSI_TARGETS_STDEF_H */
1479