xref: /illumos-gate/usr/src/uts/common/sys/mtio.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  *	Copyright (c) 1983-1989 by AT&T.
26  *	All rights reserved.
27  */
28 
29 /*
30  * Portions of this source code were derived from Berkeley 4.3 BSD
31  * under license from the Regents of the University of California.
32  */
33 
34 #ifndef	_SYS_MTIO_H
35 #define	_SYS_MTIO_H
36 
37 #include <sys/types.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Structures and definitions for mag tape io control commands
45  */
46 
47 /*
48  * structure for MTIOCTOP - mag tape op command
49  */
50 struct mtop	{
51 	short		mt_op;		/* operations defined below */
52 	daddr_t		mt_count;	/* how many of them */
53 };
54 
55 #if defined(_SYSCALL32)
56 struct mtop32	{
57 	short		mt_op;		/* operations defined below */
58 	daddr32_t	mt_count;	/* how many of them */
59 };
60 #endif /* _SYSCALL32 */
61 
62 /*
63  * structure for MTIOCLTOP - mag tape op command
64  */
65 struct mtlop	{
66 	short		mt_op;
67 	short		pad[3];
68 	int64_t		mt_count;
69 };
70 
71 /*
72  * values for mt_op
73  */
74 #define	MTWEOF		0	/* write an end-of-file record */
75 #define	MTFSF		1	/* forward space over file mark */
76 #define	MTBSF		2	/* backward space over file mark (1/2" only ) */
77 #define	MTFSR		3	/* forward space to inter-record gap */
78 #define	MTBSR		4	/* backward space to inter-record gap */
79 #define	MTREW		5	/* rewind */
80 #define	MTOFFL		6	/* rewind and put the drive offline */
81 #define	MTNOP		7	/* no operation, sets status only */
82 #define	MTRETEN		8	/* retension the tape (cartridge tape only) */
83 #define	MTERASE		9	/* erase the entire tape */
84 #define	MTEOM		10	/* position to end of media */
85 #define	MTNBSF		11	/* backward space file to BOF */
86 #define	MTSRSZ		12	/* set record size */
87 #define	MTGRSZ		13	/* get record size */
88 #define	MTLOAD		14	/* for loading a tape (use o_delay to open */
89 				/* the tape device) */
90 #define	MTBSSF		15	/* Backward space to x sequential filemarks */
91 #define	MTFSSF		16	/* Forward space to x sequential filemarks */
92 #define	MTTELL		17	/* get current logical block position */
93 #define	MTSEEK		18	/* position to logical block position */
94 #define	MTLOCK		19	/* lock media */
95 #define	MTUNLOCK	20	/* unlock media */
96 
97 /*
98  * structure for MTIOCGET - mag tape get status command
99  */
100 struct mtget	{
101 	short		mt_type;	/* type of magtape device */
102 	/* the following two registers are grossly device dependent */
103 	short		mt_dsreg;	/* ``drive status'' register */
104 	short		mt_erreg;	/* ``error'' register */
105 	/* optional error info. */
106 	daddr_t		mt_resid;	/* residual count */
107 	daddr_t		mt_fileno;	/* file number of current position */
108 	daddr_t		mt_blkno;	/* block number of current position */
109 	ushort_t	mt_flags;
110 	short		mt_bf;		/* optimum blocking factor */
111 };
112 
113 #if defined(_SYSCALL32)
114 struct mtget32	{
115 	short		mt_type;	/* type of magtape device */
116 	/* the following two registers are grossly device dependent */
117 	short		mt_dsreg;	/* ``drive status'' register */
118 	short		mt_erreg;	/* ``error'' register */
119 	/* optional error info. */
120 	daddr32_t	mt_resid;	/* residual count */
121 	daddr32_t	mt_fileno;	/* file number of current position */
122 	daddr32_t	mt_blkno;	/* block number of current position */
123 	ushort_t	mt_flags;
124 	short		mt_bf;		/* optimum blocking factor */
125 };
126 #endif /* _SYSCALL32 */
127 
128 #define	MT_NDENSITIES	4
129 #define	MT_NSPEEDS	4
130 
131 /*
132  * struct for MTIOCGETDRIVETYPE - get tape config data
133  */
134 struct mtdrivetype {
135 	char    name[64];		/* Name, for debug */
136 	char    vid[25];		/* Vendor id and model (product) id */
137 	char    type;			/* Drive type for driver */
138 	int	bsize;			/* Block size */
139 	int	options;		/* Drive options */
140 	int	max_rretries;		/* Max read retries */
141 	int	max_wretries;		/* Max write retries */
142 	uchar_t densities[MT_NDENSITIES];	/* density codes, low->hi */
143 	uchar_t	default_density;	/* Default density chosen */
144 	uchar_t speeds[MT_NSPEEDS];	/* speed codes, low->hi */
145 	ushort_t non_motion_timeout;    /* Inquiry type commands */
146 	ushort_t io_timeout;		/* io timeout. seconds */
147 	ushort_t rewind_timeout;	/* rewind timeout. seconds */
148 	ushort_t space_timeout;		/* space cmd timeout. seconds */
149 	ushort_t load_timeout;		/* load tape time in seconds */
150 	ushort_t unload_timeout;	/* Unload tape time in scounds */
151 	ushort_t erase_timeout;		/* erase timeout. seconds */
152 };
153 
154 /*
155  * struct for MTIOCGETERROR - get recent error entry command
156  */
157 struct mterror_entry {
158 	size_t mtee_cdb_len;			/* CDB length */
159 	uchar_t *mtee_cdb_buf;			/* CDB sent to the device */
160 	size_t mtee_arq_status_len;		/* length of scsi arq status */
161 	struct scsi_arq_status *mtee_arq_status;
162 						/* scsi arq status buffer */
163 };
164 
165 #define	MTERROR_ENTRY_SIZE_64 (sizeof (struct mterror_entry))
166 
167 #if defined(_SYSCALL32)
168 struct mterror_entry32 {
169 	size32_t mtee_cdb_len;			/* CDB length */
170 	caddr32_t mtee_cdb_buf;			/* CDB sent to the device */
171 	size32_t mtee_arq_status_len;		/* length of scsi arq status */
172 	caddr32_t mtee_arq_status;
173 						/* scsi arq status buffer */
174 };
175 
176 #define	MTERROR_ENTRY_SIZE_32 (sizeof (struct mterror_entry32))
177 
178 #endif /* _SYSCALL32 */
179 
180 /*
181  * error entry stack
182  */
183 struct mterror_entry_stack {
184 	struct mterror_entry mtees_entry;
185 	struct mterror_entry_stack *mtees_nextp;
186 };
187 
188 #define	MTERROR_LINK_ENTRY_SIZE (sizeof (struct mterror_entry_stack))
189 
190 struct mtdrivetype_request {
191 	int	size;
192 	struct  mtdrivetype *mtdtp;
193 };
194 
195 #if defined(_SYSCALL32)
196 struct mtdrivetype_request32 {
197 	int		size;
198 	caddr32_t	mtdtp;
199 };
200 #endif /* _SYSCALL32 */
201 
202 
203 /*
204  * values for mt_flags
205  */
206 #define	MTF_SCSI		0x01
207 #define	MTF_REEL		0x02
208 #define	MTF_ASF			0x04
209 
210 #define	MTF_TAPE_HEAD_DIRTY	0x08
211 #define	MTF_TAPE_CLN_SUPPORTED	0x10
212 #define	MTF_WORM_MEDIA		0x20
213 #define	MTF_LOGICAL_BLOCK	0x40
214 
215 /*
216  * Constants for mt_type byte (these are somewhat obsolete)
217  */
218 #define	MT_ISTS		0x01		/* vax: unibus ts-11 */
219 #define	MT_ISHT		0x02		/* vax: massbus tu77, etc */
220 #define	MT_ISTM		0x03		/* vax: unibus tm-11 */
221 #define	MT_ISMT		0x04		/* vax: massbus tu78 */
222 #define	MT_ISUT		0x05		/* vax: unibus gcr */
223 #define	MT_ISCPC	0x06		/* sun: multibus cpc */
224 #define	MT_ISAR		0x07		/* sun: multibus archive */
225 #define	MT_ISSC		0x08		/* sun: SCSI archive */
226 #define	MT_ISSYSGEN11	0x10		/* sun: SCSI Sysgen, QIC-11 only */
227 #define	MT_ISSYSGEN	0x11		/* sun: SCSI Sysgen QIC-24/11 */
228 #define	MT_ISDEFAULT	0x12		/* sun: SCSI default CCS */
229 #define	MT_ISCCS3	0x13		/* sun: SCSI generic (unknown) CCS */
230 #define	MT_ISMT02	0x14		/* sun: SCSI Emulex MT02 */
231 #define	MT_ISVIPER1	0x15		/* sun: SCSI Archive QIC-150 Viper */
232 #define	MT_ISWANGTEK1	0x16		/* sun: SCSI Wangtek QIC-150 */
233 #define	MT_ISCCS7	0x17		/* sun: SCSI generic (unknown) CCS */
234 #define	MT_ISCCS8	0x18		/* sun: SCSI generic (unknown) CCS */
235 #define	MT_ISCCS9	0x19		/* sun: SCSI generic (unknown) CCS */
236 #define	MT_ISCCS11	0x1a		/* sun: SCSI generic (unknown) CCS */
237 #define	MT_ISCCS12	0x1b		/* sun: SCSI generic (unknown) CCS */
238 #define	MT_ISCCS13	0x1c		/* sun: SCSI generic (unknown) CCS */
239 #define	MT_ISCCS14	0x1d		/* sun: SCSI generic (unknown) CCS */
240 #define	MT_ISCCS15	0x1e		/* sun: SCSI generic (unknown) CCS */
241 #define	MT_ISCCS16	0x1f		/* sun: SCSI generic (unknown) CCS */
242 #define	MT_ISCDC	0x20		/* sun: SCSI CDC 1/2" cartridge */
243 #define	MT_ISFUJI	0x21		/* sun: SCSI Fujitsu 1/2" cartridge */
244 #define	MT_ISKENNEDY	0x22		/* sun: SCSI Kennedy 1/2" reel */
245 #define	MT_ISHP		0x23		/* sun: SCSI HP 1/2" reel */
246 #define	MT_ISSTC	0x24		/* sun: SCSI IBM STC 3490 */
247 #define	MT_ISANRITSU	0x25		/* nihon sun: Anritsu 1/2" reel */
248 #define	MT_ISCCS23	0x26		/* sun: SCSI generic  1/2" */
249 #define	MT_ISCCS24	0x27		/* sun: SCSI generic  1/2" */
250 #define	MT_ISEXABYTE	0x28		/* sun: SCSI Exabyte 8mm cartridge */
251 #define	MT_ISEXB8500	0x29		/* sun: SCSI Exabyte 8500 8mm cart */
252 #define	MT_ISWANGTHS	0x2a		/* sun: SCSI Wangtek 6130HS RDAT */
253 #define	MT_ISWANGDAT	0x2b		/* sun: SCSI WangDAT */
254 #define	MT_ISPYTHON	0x2c		/* sun: SCSI Archive Python DAT  */
255 #define	MT_ISCCS28	0x2d		/* sun: SCSI generic DAT CCS */
256 #define	MT_ISCCS29	0x2e		/* sun: SCSI generic (unknown) CCS */
257 #define	MT_ISCCS30	0x2f		/* sun: SCSI generic (unknown) CCS */
258 #define	MT_ISCCS31	0x30		/* sun: SCSI generic (unknown) CCS */
259 #define	MT_ISCCS32	0x31		/* sun: SCSI generic (unknown) CCS */
260 
261 
262 /*
263  * these are recommended
264  */
265 #define	MT_ISQIC	0x32		/* generic QIC tape drive */
266 #define	MT_ISREEL	0x33		/* generic reel tape drive */
267 #define	MT_ISDAT	0x34		/* generic DAT tape drive */
268 #define	MT_IS8MM	0x35		/* generic 8mm tape drive */
269 #define	MT_ISOTHER	0x36		/* generic other type of tape drive */
270 
271 /* more Sun devices */
272 #define	MT_ISTAND25G	0x37		/* sun: SCSI Tandberg 2.5 Gig QIC */
273 #define	MT_ISDLT	0x38		/* sun: SCSI DLT tape drive */
274 #define	MT_ISSTK9840	0x39		/* sun: STK 9840, 9940, 9840B */
275 #define	MT_ISBMDLT1	0x3a		/* sun: Benchmark DLT1 */
276 #define	MT_LTO		0x3b		/* sun: LTO,s by Hp, Seagate, IBM .. */
277 #define	MT_ISAIT	0x3c		/* Sony: AIT I II III and SAIT */
278 
279 /*
280  * Device table structure and data for looking tape name from
281  * tape id number.  Used by mt.c.
282  */
283 struct mt_tape_info {
284 	short	t_type;		/* type of magtape device */
285 	char	*t_name;	/* printing name */
286 	char	*t_dsbits;	/* "drive status" register */
287 	char	*t_erbits;	/* "error" register */
288 };
289 
290 
291 /* mag tape io control commands */
292 #define	MTIOC			('m'<<8)
293 #define	MTIOCTOP		(MTIOC|1)	/* do a mag tape op */
294 #define	MTIOCGET		(MTIOC|2)	/* get tape status */
295 #define	MTIOCGETDRIVETYPE	(MTIOC|3)	/* get tape config data */
296 #define	MTIOCPERSISTENT		(MTIOC|4)	/* turn on persistent errors */
297 #define	MTIOCPERSISTENTSTATUS	(MTIOC|5)	/* query persis. err status */
298 #define	MTIOCLRERR		(MTIOC|6)	/* clear a persitent error */
299 #define	MTIOCGUARANTEEDORDER	(MTIOC|7)	/* check for guaranteed order */
300 #define	MTIOCRESERVE		(MTIOC|8)	/* preserve reserve */
301 #define	MTIOCRELEASE		(MTIOC|9)	/* turnoff preserve reserve */
302 #define	MTIOCFORCERESERVE	(MTIOC|10)	/* break reservation drive */
303 #define	MTIOCGETERROR		(MTIOC|11)	/* Get recently error record */
304 #define	MTIOCSTATE		(MTIOC|13)	/* Inquire insert/eject state */
305 
306 #define	MTIOCREADIGNOREILI  	(MTIOC|14)	/* Enable/Disable ILI */
307 #define	MTIOCREADIGNOREEOFS 	(MTIOC|15)	/* Enable/Disable Ignore EOF */
308 #define	MTIOCSHORTFMK		(MTIOC|16)	/* Enable/Disable Short FMK */
309 #define	MTIOCGETPOS		(MTIOC|17)	/* Get drive position */
310 #define	MTIOCRESTPOS		(MTIOC|18)	/* Go back to position */
311 #define	MTIOCLTOP		(MTIOC|19)	/* do a mag tape op */
312 
313 /*
314  * This state enum is the argument passed to the MTIOCSTATE ioctl.
315  */
316 enum mtio_state { MTIO_NONE, MTIO_EJECTED, MTIO_INSERTED };
317 
318 #ifndef KERNEL
319 /*
320  * don't use DEFTAPE.
321  */
322 #define	DEFTAPE	"/dev/rmt/0"
323 #endif
324 
325 /*
326  * Layout of minor device byte
327  * 15 - 8    7    6    5    4    3    2    1    0
328  * --------------------------------------------
329  * |    |    |    |    |    |    |    |    |----| Unit #. lower 2 bits
330  * |    |    |    |    |    |    |    |---------- No rewind on close bit....
331  * |    |    |    |    |    |----|--------------- Density Select
332  * |    |    |    |    |------------------------- Resrvd.(add. campus dens. bit)
333  * |    |    |    |------------------------------ BSD behavior
334  * |----|----|----------------------------------- Unit #  bit 2-10
335  */
336 
337 #define	MTUNIT(dev)	(((getminor(dev) & 0xff80) >> 5) + \
338 			    (getminor(dev) & 0x3))
339 #define	MT_NOREWIND	(1 <<2)
340 #define	MT_DENSITY_MASK	(3 <<3)
341 #define	MT_DENSITY1	(0 <<3)		/* Lowest density/format */
342 #define	MT_DENSITY2	(1 <<3)
343 #define	MT_DENSITY3	(2 <<3)
344 #define	MT_DENSITY4	(3 <<3)		/* Highest density/format */
345 #define	MTMINOR(unit)	((((unit) & 0x7fc) << 5) + ((unit) & 0x3))
346 #define	MT_BSD		(1 <<6)		/* BSD behavior on close */
347 #define	MT_DENSITY(dev) ((getminor(dev) & MT_DENSITY_MASK) >> 3)
348 
349 #ifdef	__cplusplus
350 }
351 #endif
352 
353 #endif /* _SYS_MTIO_H */
354