1 /*-
2  * check-sources:disable-copyright-check
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  * 4. 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  * $FreeBSD: stable/7/sys/sys/mtio.h 139825 2005-01-07 02:29:27Z imp $
33  */
34 
35 #ifndef BAREOS_LIB_BMTIO_H
36 #define BAREOS_LIB_BMTIO_H
37 
38 #ifndef _KERNEL
39 #  include <sys/types.h>
40 #endif
41 #include <sys/ioccom.h>
42 
43 /** @file
44  * Structures and definitions for mag tape io control commands
45  */
46 
47 /* structure for MTIOCTOP - mag tape op command */
48 struct mtop {
49   short mt_op;      /* operations defined below */
50   int32_t mt_count; /* how many of them */
51 };
52 
53 /* operations */
54 #define MTWEOF 0    /**< write an end-of-file record */
55 #define MTFSF 1     /**< forward space file */
56 #define MTBSF 2     /**< backward space file */
57 #define MTFSR 3     /**< forward space record */
58 #define MTBSR 4     /**< backward space record */
59 #define MTREW 5     /**< rewind */
60 #define MTOFFL 6    /**< rewind and put the drive offline */
61 #define MTNOP 7     /**< no operation, sets status only */
62 #define MTCACHE 8   /**< enable controller cache */
63 #define MTNOCACHE 9 /**< disable controller cache */
64 
65 #if defined(__FreeBSD__)
66 /* Set block size for device. If device is a variable size dev    */
67 /* a non zero parameter will change the device to a fixed block size */
68 /* device with block size set to that of the parameter passed in. */
69 /* Resetting the block size to 0 will restore the device to a variable  */
70 /* block size device. */
71 
72 #  define MTSETBSIZ 10
73 
74 /* Set density values for device. Sets the value for the opened mode only. */
75 
76 #  define MTSETDNSTY 11
77 
78 #  define MTERASE 12  /**< erase to EOM */
79 #  define MTEOD 13    /**< Space to EOM */
80 #  define MTCOMP 14   /**< select compression mode 0=off, 1=def */
81 #  define MTRETENS 15 /**< re-tension tape */
82 #  define MTWSS 16    /**< write setmark(s) */
83 #  define MTFSS 17    /**< forward space setmark */
84 #  define MTBSS 18    /**< backward space setmark */
85 
86 #  define MT_COMP_ENABLE 0xffffffff
87 #  define MT_COMP_DISABLED 0xfffffffe
88 #  define MT_COMP_UNSUPP 0xfffffffd
89 
90 /*
91  * Values in mt_dsreg that say what the device is doing
92  */
93 #  define MTIO_DSREG_NIL 0  /**< Unknown */
94 #  define MTIO_DSREG_REST 1 /**< Doing Nothing */
95 #  define MTIO_DSREG_RBSY 2 /**< Communicating with tape (but no motion) */
96 #  define MTIO_DSREG_WR 20  /**< Writing */
97 #  define MTIO_DSREG_FMK 21 /**< Writing Filemarks */
98 #  define MTIO_DSREG_ZER 22 /**< Erasing */
99 #  define MTIO_DSREG_RD 30  /**< Reading */
100 #  define MTIO_DSREG_FWD 40 /**< Spacing Forward */
101 #  define MTIO_DSREG_REV 41 /**< Spacing Reverse */
102 #  define MTIO_DSREG_POS 42 /**< Hardware Positioning (direction unknown) */
103 #  define MTIO_DSREG_REW 43 /**< Rewinding */
104 #  define MTIO_DSREG_TEN 44 /**< Retensioning */
105 #  define MTIO_DSREG_UNL 45 /**< Unloading */
106 #  define MTIO_DSREG_LD 46  /**< Loading */
107 
108 #endif /* __FreeBSD__ */
109 
110 /* structure for MTIOCGET - mag tape get status command */
111 
112 struct mtget {
113   short mt_type;  /**< type of magtape device */
114                   /* the following two registers are grossly device dependent */
115   short mt_dsreg; /**< ``drive status'' register */
116   short mt_erreg; /**< ``error'' register */
117                   /* end device-dependent registers */
118   /*
119    * Note that the residual count, while maintained, may be
120    * be nonsense because the size of the residual may (greatly)
121    * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
122    * more accurate count.
123    */
124   short mt_resid; /**< residual count */
125 #if defined(__FreeBSD__)
126   int32_t mt_blksiz;   /**< presently operating blocksize */
127   int32_t mt_density;  /**< presently operating density */
128   uint32_t mt_comp;    /**< presently operating compression */
129   int32_t mt_blksiz0;  /**< blocksize for mode 0 */
130   int32_t mt_blksiz1;  /**< blocksize for mode 1 */
131   int32_t mt_blksiz2;  /**< blocksize for mode 2 */
132   int32_t mt_blksiz3;  /**< blocksize for mode 3 */
133   int32_t mt_density0; /**< density for mode 0 */
134   int32_t mt_density1; /**< density for mode 1 */
135   int32_t mt_density2; /**< density for mode 2 */
136   int32_t mt_density3; /**< density for mode 3 */
137                        /* the following are not yet implemented */
138   uint32_t mt_comp0;   /**< compression type for mode 0 */
139   uint32_t mt_comp1;   /**< compression type for mode 1 */
140   uint32_t mt_comp2;   /**< compression type for mode 2 */
141   uint32_t mt_comp3;   /**< compression type for mode 3 */
142 /* end not yet implemented */
143 #endif
144   int32_t mt_fileno; /**< relative file number of current position */
145   int32_t mt_blkno;  /**< relative block number of current position */
146 };
147 
148 /* structure for MTIOCERRSTAT - tape get error status command */
149 /* really only supported for SCSI tapes right now */
150 struct scsi_tape_errors {
151   /*
152    * These are latched from the last command that had a SCSI
153    * Check Condition noted for these operations. The act
154    * of issuing an MTIOCERRSTAT unlatches and clears them.
155    */
156   uint8_t io_sense[32];  /**< Last Sense Data For Data I/O */
157   int32_t io_resid;      /**< residual count from last Data I/O */
158   uint8_t io_cdb[16];    /**< Command that Caused the Last Data Sense */
159   uint8_t ctl_sense[32]; /**< Last Sense Data For Control I/O */
160   int32_t ctl_resid;     /**< residual count from last Control I/O */
161   uint8_t ctl_cdb[16];   /**< Command that Caused the Last Control Sense */
162   /*
163    * These are the read and write cumulative error counters.
164    * (how to reset cumulative error counters is not yet defined).
165    * (not implemented as yet but space is being reserved for them)
166    */
167   struct {
168     uint32_t retries;   /**< total # retries performed */
169     uint32_t corrected; /**< total # corrections performed */
170     uint32_t processed; /**< total # corrections successful */
171     uint32_t failures;  /**< total # corrections/retries failed */
172     uint64_t nbytes;    /**< total # bytes processed */
173   } wterr, rderr;
174 };
175 
176 union mterrstat {
177   struct scsi_tape_errors scsi_errstat;
178   char _reserved_padding[256];
179 };
180 
181 /*
182  * Constants for mt_type byte.  These are the same
183  * for controllers compatible with the types listed.
184  */
185 #define MT_ISTS 0x01      /**< TS-11 */
186 #define MT_ISHT 0x02      /**< TM03 Massbus: TE16, TU45, TU77 */
187 #define MT_ISTM 0x03      /**< TM11/TE10 Unibus */
188 #define MT_ISMT 0x04      /**< TM78/TU78 Massbus */
189 #define MT_ISUT 0x05      /**< SI TU-45 emulation on Unibus */
190 #define MT_ISCPC 0x06     /**< SUN */
191 #define MT_ISAR 0x07      /**< SUN */
192 #define MT_ISTMSCP 0x08   /**< DEC TMSCP protocol (TU81, TK50) */
193 #define MT_ISCY 0x09      /**< CCI Cipher */
194 #define MT_ISCT 0x0a      /**< HP 1/4 tape */
195 #define MT_ISFHP 0x0b     /**< HP 7980 1/2 tape */
196 #define MT_ISEXABYTE 0x0c /**< Exabyte */
197 #define MT_ISEXA8200 0x0c /**< Exabyte EXB-8200 */
198 #define MT_ISEXA8500 0x0d /**< Exabyte EXB-8500 */
199 #define MT_ISVIPER1 0x0e  /**< Archive Viper-150 */
200 #define MT_ISPYTHON 0x0f  /**< Archive Python (DAT) */
201 #define MT_ISHPDAT 0x10   /**< HP 35450A DAT drive */
202 #define MT_ISMFOUR 0x11   /**< M4 Data 1/2 9track drive */
203 #define MT_ISTK50 0x12    /**< DEC SCSI TK50 */
204 #define MT_ISMT02 0x13    /**< Emulex MT02 SCSI tape controller */
205 
206 /* mag tape io control commands */
207 #define MTIOCTOP _IOW('m', 1, struct mtop)  /**< do a mag tape op */
208 #define MTIOCGET _IOR('m', 2, struct mtget) /**< get tape status */
209 /* these two do not appear to be used anywhere */
210 #define MTIOCIEOT _IO('m', 3) /**< ignore EOT error */
211 #define MTIOCEEOT _IO('m', 4) /**< enable EOT error */
212 /*
213  * When more SCSI-3 SSC (streaming device) devices are out there
214  * that support the full 32 byte type 2 structure, we'll have to
215  * rethink these ioctls to support all the entities they haul into
216  * the picture (64 bit blocks, logical file record numbers, etc..).
217  */
218 #define MTIOCRDSPOS _IOR('m', 5, uint32_t)  /**< get logical blk addr */
219 #define MTIOCRDHPOS _IOR('m', 6, uint32_t)  /**< get hardware blk addr */
220 #define MTIOCSLOCATE _IOW('m', 5, uint32_t) /**< seek to logical blk addr */
221 #define MTIOCHLOCATE _IOW('m', 6, uint32_t) /**< seek to hardware blk addr */
222 #define MTIOCERRSTAT _IOR('m', 7, union mterrstat) /**< get tape errors */
223 /*
224  * Set EOT model- argument is number of filemarks to end a tape with.
225  * Note that not all possible values will be accepted.
226  */
227 #define MTIOCSETEOTMODEL _IOW('m', 8, uint32_t)
228 /* Get current EOT model */
229 #define MTIOCGETEOTMODEL _IOR('m', 8, uint32_t)
230 
231 #ifndef _KERNEL
232 #  define DEFTAPE "/dev/nsa0"
233 #endif
234 
235 #endif /* !BAREOS_LIB_BMTIO_H */
236