xref: /dragonfly/sys/sys/mtio.h (revision b40e316c)
1 /*
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)mtio.h	8.1 (Berkeley) 6/2/93
34  * $FreeBSD: src/sys/sys/mtio.h,v 1.20.2.2 2001/01/22 18:02:47 mjacob Exp $
35  * $DragonFly: src/sys/sys/mtio.h,v 1.3 2004/02/06 03:20:47 rob Exp $
36  */
37 
38 #ifndef	_SYS_MTIO_H_
39 #define	_SYS_MTIO_H_
40 
41 #ifndef _KERNEL
42 #include <sys/types.h>
43 #endif
44 #include <sys/ioccom.h>
45 
46 /*
47  * Structures and definitions for mag tape io control commands
48  */
49 
50 /* structure for MTIOCTOP - mag tape op command */
51 struct mtop {
52 	short	mt_op;		/* operations defined below */
53 	daddr_t	mt_count;	/* how many of them */
54 };
55 
56 /* operations */
57 #define MTWEOF		0	/* write an end-of-file record */
58 #define MTFSF		1	/* forward space file */
59 #define MTBSF		2	/* backward space file */
60 #define MTFSR		3	/* forward space record */
61 #define MTBSR		4	/* backward space record */
62 #define MTREW		5	/* rewind */
63 #define MTOFFL		6	/* rewind and put the drive offline */
64 #define MTNOP		7	/* no operation, sets status only */
65 #define MTCACHE		8	/* enable controller cache */
66 #define MTNOCACHE	9	/* disable controller cache */
67 
68 #if defined(__DragonFly__)
69 /* Set block size for device. If device is a variable size dev		*/
70 /* a non zero parameter will change the device to a fixed block size	*/
71 /* device with block size set to that of the parameter passed in.	*/
72 /* Resetting the block size to 0 will restore the device to a variable	*/
73 /* block size device. */
74 
75 #define MTSETBSIZ	10
76 
77 /* Set density values for device. Sets the value for the opened mode only. */
78 
79 #define MTSETDNSTY	11
80 
81 #define MTERASE		12	/* erase to EOM */
82 #define MTEOD		13	/* Space to EOM */
83 #define MTCOMP		14	/* select compression mode 0=off, 1=def */
84 #define MTRETENS	15	/* re-tension tape */
85 #define MTWSS		16	/* write setmark(s) */
86 #define MTFSS		17	/* forward space setmark */
87 #define MTBSS		18	/* backward space setmark */
88 
89 #define MT_COMP_ENABLE		0xffffffff
90 #define MT_COMP_DISABLED	0xfffffffe
91 #define MT_COMP_UNSUPP		0xfffffffd
92 
93 /*
94  * Values in mt_dsreg that say what the device is doing
95  */
96 #define	MTIO_DSREG_NIL	0	/* Unknown */
97 #define	MTIO_DSREG_REST	1	/* Doing Nothing */
98 #define	MTIO_DSREG_RBSY	2	/* Communicating with tape (but no motion) */
99 #define	MTIO_DSREG_WR	20	/* Writing */
100 #define	MTIO_DSREG_FMK	21	/* Writing Filemarks */
101 #define	MTIO_DSREG_ZER	22	/* Erasing */
102 #define	MTIO_DSREG_RD	30	/* Reading */
103 #define	MTIO_DSREG_FWD	40	/* Spacing Forward */
104 #define	MTIO_DSREG_REV	41	/* Spacing Reverse */
105 #define	MTIO_DSREG_POS	42	/* Hardware Positioning (direction unknown) */
106 #define	MTIO_DSREG_REW	43	/* Rewinding */
107 #define	MTIO_DSREG_TEN	44	/* Retensioning */
108 #define	MTIO_DSREG_UNL	45	/* Unloading */
109 #define	MTIO_DSREG_LD	46	/* Loading */
110 
111 #endif	/* __DragonFly__ */
112 
113 /* structure for MTIOCGET - mag tape get status command */
114 
115 struct mtget {
116 	short	mt_type;	/* type of magtape device */
117 /* the following two registers are grossly device dependent */
118 	short	mt_dsreg;	/* ``drive status'' register */
119 	short	mt_erreg;	/* ``error'' register */
120 /* end device-dependent registers */
121 	/*
122 	 * Note that the residual count, while maintained, may be
123 	 * be nonsense because the size of the residual may (greatly)
124 	 * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
125 	 * more accurate count.
126 	 */
127 	short	mt_resid;	/* residual count */
128 #if defined (__DragonFly__)
129 	daddr_t mt_blksiz;	/* presently operating blocksize */
130 	daddr_t mt_density;	/* presently operating density */
131 	u_int32_t mt_comp;	/* presently operating compression */
132 	daddr_t mt_blksiz0;	/* blocksize for mode 0 */
133 	daddr_t mt_blksiz1;	/* blocksize for mode 1 */
134 	daddr_t mt_blksiz2;	/* blocksize for mode 2 */
135 	daddr_t mt_blksiz3;	/* blocksize for mode 3 */
136 	daddr_t mt_density0;	/* density for mode 0 */
137 	daddr_t mt_density1;	/* density for mode 1 */
138 	daddr_t mt_density2;	/* density for mode 2 */
139 	daddr_t mt_density3;	/* density for mode 3 */
140 /* the following are not yet implemented */
141 	u_int32_t mt_comp0;	/* compression type for mode 0 */
142 	u_int32_t mt_comp1;	/* compression type for mode 1 */
143 	u_int32_t mt_comp2;	/* compression type for mode 2 */
144 	u_int32_t mt_comp3;	/* compression type for mode 3 */
145 /* end not yet implemented */
146 #endif
147 	daddr_t	mt_fileno;	/* relative file number of current position */
148 	daddr_t	mt_blkno;	/* relative block number of current position */
149 };
150 
151 /* structure for MTIOCERRSTAT - tape get error status command */
152 /* really only supported for SCSI tapes right now */
153 struct scsi_tape_errors {
154 	/*
155 	 * These are latched from the last command that had a SCSI
156 	 * Check Condition noted for these operations. The act
157 	 * of issuing an MTIOCERRSTAT unlatches and clears them.
158 	 */
159 	u_int8_t io_sense[32];	/* Last Sense Data For Data I/O */
160 	int32_t io_resid;	/* residual count from last Data I/O */
161 	u_int8_t io_cdb[16];	/* Command that Caused the Last Data Sense */
162 	u_int8_t ctl_sense[32];	/* Last Sense Data For Control I/O */
163 	int32_t ctl_resid;	/* residual count from last Control I/O */
164 	u_int8_t ctl_cdb[16];	/* Command that Caused the Last Control Sense */
165 	/*
166 	 * These are the read and write cumulative error counters.
167 	 * (how to reset cumulative error counters is not yet defined).
168 	 * (not implemented as yet but space is being reserved for them)
169 	 */
170 	struct {
171 		u_int32_t retries;	/* total # retries performed */
172 		u_int32_t corrected;	/* total # corrections performed */
173 		u_int32_t processed;	/* total # corrections succssful */
174 		u_int32_t failures;	/* total # corrections/retries failed */
175 		u_int64_t nbytes;	/* total # bytes processed */
176 	} wterr, rderr;
177 };
178 
179 union mterrstat {
180 	struct scsi_tape_errors scsi_errstat;
181 	char _reserved_padding[256];
182 };
183 
184 /*
185  * Constants for mt_type byte.  These are the same
186  * for controllers compatible with the types listed.
187  */
188 #define	MT_ISTS		0x01		/* TS-11 */
189 #define	MT_ISHT		0x02		/* TM03 Massbus: TE16, TU45, TU77 */
190 #define	MT_ISTM		0x03		/* TM11/TE10 Unibus */
191 #define	MT_ISMT		0x04		/* TM78/TU78 Massbus */
192 #define	MT_ISUT		0x05		/* SI TU-45 emulation on Unibus */
193 #define	MT_ISCPC	0x06		/* SUN */
194 #define	MT_ISAR		0x07		/* SUN */
195 #define	MT_ISTMSCP	0x08		/* DEC TMSCP protocol (TU81, TK50) */
196 #define MT_ISCY		0x09		/* CCI Cipher */
197 #define MT_ISCT		0x0a		/* HP 1/4 tape */
198 #define MT_ISFHP	0x0b		/* HP 7980 1/2 tape */
199 #define MT_ISEXABYTE	0x0c		/* Exabyte */
200 #define MT_ISEXA8200	0x0c		/* Exabyte EXB-8200 */
201 #define MT_ISEXA8500	0x0d		/* Exabyte EXB-8500 */
202 #define MT_ISVIPER1	0x0e		/* Archive Viper-150 */
203 #define MT_ISPYTHON	0x0f		/* Archive Python (DAT) */
204 #define MT_ISHPDAT	0x10		/* HP 35450A DAT drive */
205 #define MT_ISMFOUR	0x11		/* M4 Data 1/2 9track drive */
206 #define MT_ISTK50	0x12		/* DEC SCSI TK50 */
207 #define MT_ISMT02	0x13		/* Emulex MT02 SCSI tape controller */
208 
209 /* mag tape io control commands */
210 #define	MTIOCTOP	_IOW('m', 1, struct mtop)	/* do a mag tape op */
211 #define	MTIOCGET	_IOR('m', 2, struct mtget)	/* get tape status */
212 /* these two do not appear to be used anywhere */
213 #define MTIOCIEOT	_IO('m', 3)			/* ignore EOT error */
214 #define MTIOCEEOT	_IO('m', 4)			/* enable EOT error */
215 /*
216  * When more SCSI-3 SSC (streaming device) devices are out there
217  * that support the full 32 byte type 2 structure, we'll have to
218  * rethink these ioctls to support all the entities they haul into
219  * the picture (64 bit blocks, logical file record numbers, etc..).
220  */
221 #define	MTIOCRDSPOS	_IOR('m', 5, u_int32_t)	/* get logical blk addr */
222 #define	MTIOCRDHPOS	_IOR('m', 6, u_int32_t)	/* get hardware blk addr */
223 #define	MTIOCSLOCATE	_IOW('m', 5, u_int32_t)	/* seek to logical blk addr */
224 #define	MTIOCHLOCATE	_IOW('m', 6, u_int32_t)	/* seek to hardware blk addr */
225 #define	MTIOCERRSTAT	_IOR('m', 7, union mterrstat)	/* get tape errors */
226 /*
227  * Set EOT model- argument is number of filemarks to end a tape with.
228  * Note that not all possible values will be accepted.
229  */
230 #define	MTIOCSETEOTMODEL	_IOW('m', 8, u_int32_t)
231 /* Get current EOT model */
232 #define	MTIOCGETEOTMODEL	_IOR('m', 8, u_int32_t)
233 
234 #ifndef _KERNEL
235 #define	DEFTAPE	"/dev/nsa0"
236 #endif
237 
238 #ifdef	_KERNEL
239 /*
240  * minor device number
241  */
242 
243 #define	T_UNIT		003		/* unit selection */
244 #define	T_NOREWIND	004		/* no rewind on close */
245 #define	T_DENSEL	030		/* density select */
246 #define	T_800BPI	000		/* select  800 bpi */
247 #define	T_1600BPI	010		/* select 1600 bpi */
248 #define	T_6250BPI	020		/* select 6250 bpi */
249 #define	T_BADBPI	030		/* undefined selection */
250 #endif
251 
252 #endif /* !_SYS_MTIO_H_ */
253