xref: /freebsd-13-stable/sys/sys/mtio.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)mtio.h	8.1 (Berkeley) 6/2/93
32  */
33 
34 #ifndef	_SYS_MTIO_H_
35 #define	_SYS_MTIO_H_
36 
37 #ifndef _KERNEL
38 #include <sys/types.h>
39 #endif
40 #include <sys/ioccom.h>
41 
42 /*
43  * Structures and definitions for mag tape io control commands
44  */
45 
46 /* structure for MTIOCTOP - mag tape op command */
47 struct mtop {
48 	short	mt_op;		/* operations defined below */
49 	int32_t	mt_count;	/* how many of them */
50 };
51 
52 /* operations */
53 #define MTWEOF		0	/* write an end-of-file record */
54 #define MTFSF		1	/* forward space file */
55 #define MTBSF		2	/* backward space file */
56 #define MTFSR		3	/* forward space record */
57 #define MTBSR		4	/* backward space record */
58 #define MTREW		5	/* rewind */
59 #define MTOFFL		6	/* rewind and put the drive offline */
60 #define MTNOP		7	/* no operation, sets status only */
61 #define MTCACHE		8	/* enable controller cache */
62 #define MTNOCACHE	9	/* disable controller cache */
63 
64 #if defined(__FreeBSD__)
65 /* Set block size for device. If device is a variable size dev		*/
66 /* a non zero parameter will change the device to a fixed block size	*/
67 /* device with block size set to that of the parameter passed in.	*/
68 /* Resetting the block size to 0 will restore the device to a variable	*/
69 /* block size device. */
70 
71 #define MTSETBSIZ	10
72 
73 /* Set density values for device. Sets the value for the opened mode only. */
74 
75 #define MTSETDNSTY	11
76 
77 #define MTERASE		12	/* erase to EOM */
78 #define MTEOD		13	/* Space to EOM */
79 #define MTCOMP		14	/* select compression mode 0=off, 1=def */
80 #define MTRETENS	15	/* re-tension tape */
81 #define MTWSS		16	/* write setmark(s) */
82 #define MTFSS		17	/* forward space setmark */
83 #define MTBSS		18	/* backward space setmark */
84 #define MTLOAD		19	/* load tape in drive */
85 #define MTWEOFI		20	/* write an end-of-file record without waiting*/
86 
87 #define MT_COMP_ENABLE		0xffffffff
88 #define MT_COMP_DISABLED	0xfffffffe
89 #define MT_COMP_UNSUPP		0xfffffffd
90 
91 /*
92  * Values in mt_dsreg that say what the device is doing
93  */
94 #define	MTIO_DSREG_NIL	0	/* Unknown */
95 #define	MTIO_DSREG_REST	1	/* Doing Nothing */
96 #define	MTIO_DSREG_RBSY	2	/* Communicating with tape (but no motion) */
97 #define	MTIO_DSREG_WR	20	/* Writing */
98 #define	MTIO_DSREG_FMK	21	/* Writing Filemarks */
99 #define	MTIO_DSREG_ZER	22	/* Erasing */
100 #define	MTIO_DSREG_RD	30	/* Reading */
101 #define	MTIO_DSREG_FWD	40	/* Spacing Forward */
102 #define	MTIO_DSREG_REV	41	/* Spacing Reverse */
103 #define	MTIO_DSREG_POS	42	/* Hardware Positioning (direction unknown) */
104 #define	MTIO_DSREG_REW	43	/* Rewinding */
105 #define	MTIO_DSREG_TEN	44	/* Retensioning */
106 #define	MTIO_DSREG_UNL	45	/* Unloading */
107 #define	MTIO_DSREG_LD	46	/* Loading */
108 
109 #endif	/* __FreeBSD__ */
110 
111 /* structure for MTIOCGET - mag tape get status command */
112 
113 struct mtget {
114 	short	mt_type;	/* type of magtape device */
115 /* the following two registers are grossly device dependent */
116 	short	mt_dsreg;	/* ``drive status'' register */
117 	short	mt_erreg;	/* ``error'' register */
118 /* end device-dependent registers */
119 	/*
120 	 * Note that the residual count, while maintained, may be
121 	 * be nonsense because the size of the residual may (greatly)
122 	 * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
123 	 * more accurate count.
124 	 */
125 	short	mt_resid;	/* residual count */
126 #if defined (__FreeBSD__)
127 	int32_t mt_blksiz;	/* presently operating blocksize */
128 	int32_t mt_density;	/* presently operating density */
129 	u_int32_t mt_comp;	/* presently operating compression */
130 	int32_t mt_blksiz0;	/* blocksize for mode 0 */
131 	int32_t mt_blksiz1;	/* blocksize for mode 1 */
132 	int32_t mt_blksiz2;	/* blocksize for mode 2 */
133 	int32_t mt_blksiz3;	/* blocksize for mode 3 */
134 	int32_t mt_density0;	/* density for mode 0 */
135 	int32_t mt_density1;	/* density for mode 1 */
136 	int32_t mt_density2;	/* density for mode 2 */
137 	int32_t mt_density3;	/* density for mode 3 */
138 /* the following are not yet implemented */
139 	u_int32_t mt_comp0;	/* compression type for mode 0 */
140 	u_int32_t mt_comp1;	/* compression type for mode 1 */
141 	u_int32_t mt_comp2;	/* compression type for mode 2 */
142 	u_int32_t mt_comp3;	/* compression type for mode 3 */
143 /* end not yet implemented */
144 #endif
145 	int32_t	mt_fileno;	/* relative file number of current position */
146 	int32_t	mt_blkno;	/* relative block number of current position */
147 };
148 
149 /* structure for MTIOCERRSTAT - tape get error status command */
150 /* really only supported for SCSI tapes right now */
151 struct scsi_tape_errors {
152 	/*
153 	 * These are latched from the last command that had a SCSI
154 	 * Check Condition noted for these operations. The act
155 	 * of issuing an MTIOCERRSTAT unlatches and clears them.
156 	 */
157 	u_int8_t io_sense[32];	/* Last Sense Data For Data I/O */
158 	int32_t io_resid;	/* residual count from last Data I/O */
159 	u_int8_t io_cdb[16];	/* Command that Caused the Last Data Sense */
160 	u_int8_t ctl_sense[32];	/* Last Sense Data For Control I/O */
161 	int32_t ctl_resid;	/* residual count from last Control I/O */
162 	u_int8_t ctl_cdb[16];	/* Command that Caused the Last Control Sense */
163 	/*
164 	 * These are the read and write cumulative error counters.
165 	 * (how to reset cumulative error counters is not yet defined).
166 	 * (not implemented as yet but space is being reserved for them)
167 	 */
168 	struct {
169 		u_int32_t retries;	/* total # retries performed */
170 		u_int32_t corrected;	/* total # corrections performed */
171 		u_int32_t processed;	/* total # corrections successful */
172 		u_int32_t failures;	/* total # corrections/retries failed */
173 		u_int64_t nbytes;	/* total # bytes processed */
174 	} wterr, rderr;
175 };
176 
177 union mterrstat {
178 	struct scsi_tape_errors scsi_errstat;
179 	char _reserved_padding[256];
180 };
181 
182 struct mtrblim {
183 	uint32_t granularity;
184 	uint32_t min_block_length;
185 	uint32_t max_block_length;
186 };
187 
188 typedef enum {
189 	MT_LOCATE_DEST_OBJECT	= 0x00,
190 	MT_LOCATE_DEST_FILE	= 0x01,
191 	MT_LOCATE_DEST_SET	= 0x02,
192 	MT_LOCATE_DEST_EOD	= 0x03
193 } mt_locate_dest_type;
194 
195 typedef enum {
196 	MT_LOCATE_BAM_IMPLICIT	= 0x00,
197 	MT_LOCATE_BAM_EXPLICIT	= 0x01
198 } mt_locate_bam;
199 
200 typedef enum {
201 	MT_LOCATE_FLAG_IMMED		= 0x01,
202 	MT_LOCATE_FLAG_CHANGE_PART	= 0x02
203 } mt_locate_flags;
204 
205 struct mtlocate {
206 	mt_locate_flags		flags;
207 	mt_locate_dest_type 	dest_type;
208 	mt_locate_bam		block_address_mode;
209 	int64_t			partition;
210 	uint64_t		logical_id;
211 	uint8_t			reserved[64];
212 };
213 
214 typedef enum {
215 	MT_EXT_GET_NONE,
216 	MT_EXT_GET_OK,
217 	MT_EXT_GET_NEED_MORE_SPACE,
218 	MT_EXT_GET_ERROR
219 } mt_ext_get_status;
220 
221 struct mtextget {
222 	uint32_t		alloc_len;
223 	char			*status_xml;
224 	uint32_t		fill_len;
225 	mt_ext_get_status	status;
226 	char			error_str[128];
227 	uint8_t			reserved[64];
228 };
229 
230 #define	MT_EXT_GET_ROOT_NAME		"mtextget"
231 #define	MT_DENSITY_ROOT_NAME		"mtdensity"
232 #define	MT_MEDIA_DENSITY_NAME		"media_density"
233 #define	MT_DENSITY_REPORT_NAME		"density_report"
234 #define	MT_MEDIUM_TYPE_REPORT_NAME	"medium_type_report"
235 #define	MT_MEDIA_REPORT_NAME		"media_report"
236 #define	MT_DENSITY_ENTRY_NAME		"density_entry"
237 
238 #define	MT_DENS_WRITE_OK		0x80
239 #define	MT_DENS_DUP			0x40
240 #define	MT_DENS_DEFLT			0x20
241 
242 #define	MT_PARAM_FIXED_STR_LEN	32
243 union mt_param_value {
244 	int64_t		value_signed;
245 	uint64_t	value_unsigned;
246 	char		*value_var_str;
247 	char		value_fixed_str[MT_PARAM_FIXED_STR_LEN];
248 	uint8_t		reserved[64];
249 };
250 
251 typedef enum {
252 	MT_PARAM_SET_NONE,
253 	MT_PARAM_SET_SIGNED,
254 	MT_PARAM_SET_UNSIGNED,
255 	MT_PARAM_SET_VAR_STR,
256 	MT_PARAM_SET_FIXED_STR
257 } mt_param_set_type;
258 
259 typedef enum {
260 	MT_PARAM_STATUS_NONE,
261 	MT_PARAM_STATUS_OK,
262 	MT_PARAM_STATUS_ERROR
263 } mt_param_set_status;
264 
265 #define	MT_PARAM_VALUE_NAME_LEN	64
266 struct mtparamset {
267 	char			value_name[MT_PARAM_VALUE_NAME_LEN];
268 	mt_param_set_type	value_type;
269 	int			value_len;
270 	union mt_param_value	value;
271 	mt_param_set_status	status;
272 	char			error_str[128];
273 };
274 
275 #define	MT_PARAM_ROOT_NAME	"mtparamget"
276 #define	MT_PROTECTION_NAME	"protection"
277 
278 /*
279  * Set a list of parameters.
280  */
281 struct mtsetlist {
282 	int num_params;
283 	int param_len;
284 	struct mtparamset *params;
285 };
286 
287 /*
288  * Constants for mt_type byte.  These are the same
289  * for controllers compatible with the types listed.
290  */
291 #define	MT_ISTS		0x01		/* TS-11 */
292 #define	MT_ISHT		0x02		/* TM03 Massbus: TE16, TU45, TU77 */
293 #define	MT_ISTM		0x03		/* TM11/TE10 Unibus */
294 #define	MT_ISMT		0x04		/* TM78/TU78 Massbus */
295 #define	MT_ISUT		0x05		/* SI TU-45 emulation on Unibus */
296 #define	MT_ISCPC	0x06		/* SUN */
297 #define	MT_ISAR		0x07		/* SUN */
298 #define	MT_ISTMSCP	0x08		/* DEC TMSCP protocol (TU81, TK50) */
299 #define MT_ISCY		0x09		/* CCI Cipher */
300 #define MT_ISCT		0x0a		/* HP 1/4 tape */
301 #define MT_ISFHP	0x0b		/* HP 7980 1/2 tape */
302 #define MT_ISEXABYTE	0x0c		/* Exabyte */
303 #define MT_ISEXA8200	0x0c		/* Exabyte EXB-8200 */
304 #define MT_ISEXA8500	0x0d		/* Exabyte EXB-8500 */
305 #define MT_ISVIPER1	0x0e		/* Archive Viper-150 */
306 #define MT_ISPYTHON	0x0f		/* Archive Python (DAT) */
307 #define MT_ISHPDAT	0x10		/* HP 35450A DAT drive */
308 #define MT_ISMFOUR	0x11		/* M4 Data 1/2 9track drive */
309 #define MT_ISTK50	0x12		/* DEC SCSI TK50 */
310 #define MT_ISMT02	0x13		/* Emulex MT02 SCSI tape controller */
311 
312 /* mag tape io control commands */
313 #define	MTIOCTOP	_IOW('m', 1, struct mtop)	/* do a mag tape op */
314 #define	MTIOCGET	_IOR('m', 2, struct mtget)	/* get tape status */
315 /* these two do not appear to be used anywhere */
316 #define MTIOCIEOT	_IO('m', 3)			/* ignore EOT error */
317 #define MTIOCEEOT	_IO('m', 4)			/* enable EOT error */
318 /*
319  * When more SCSI-3 SSC (streaming device) devices are out there
320  * that support the full 32 byte type 2 structure, we'll have to
321  * rethink these ioctls to support all the entities they haul into
322  * the picture (64 bit blocks, logical file record numbers, etc..).
323  */
324 #define	MTIOCRDSPOS	_IOR('m', 5, u_int32_t)	/* get logical blk addr */
325 #define	MTIOCRDHPOS	_IOR('m', 6, u_int32_t)	/* get hardware blk addr */
326 #define	MTIOCSLOCATE	_IOW('m', 5, u_int32_t)	/* seek to logical blk addr */
327 #define	MTIOCHLOCATE	_IOW('m', 6, u_int32_t)	/* seek to hardware blk addr */
328 #define	MTIOCERRSTAT	_IOR('m', 7, union mterrstat)	/* get tape errors */
329 
330 /*
331  * Set EOT model- argument is number of filemarks to end a tape with.
332  * Note that not all possible values will be accepted.
333  */
334 #define	MTIOCSETEOTMODEL	_IOW('m', 8, u_int32_t)
335 /* Get current EOT model */
336 #define	MTIOCGETEOTMODEL	_IOR('m', 8, u_int32_t)
337 
338 #define	MTIOCRBLIM	_IOR('m', 9, struct mtrblim)    /* get block limits */
339 #define	MTIOCEXTLOCATE	_IOW('m', 10, struct mtlocate)  /* seek to position */
340 #define	MTIOCEXTGET	_IOWR('m', 11, struct mtextget) /* get tape status */
341 #define	MTIOCPARAMGET	_IOWR('m', 12, struct mtextget) /* get tape params */
342 #define	MTIOCPARAMSET	_IOWR('m', 13, struct mtparamset) /* set tape params */
343 #define	MTIOCSETLIST	_IOWR('m', 14, struct mtsetlist) /* set N params */
344 
345 #ifndef _KERNEL
346 #define	DEFTAPE	"/dev/nsa0"
347 #endif
348 
349 #endif /* !_SYS_MTIO_H_ */
350