1139825Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)mtio.h 8.1 (Berkeley) 6/2/93 3050477Speter * $FreeBSD: releng/10.3/sys/sys/mtio.h 280438 2015-03-24 14:36:10Z ken $ 311541Srgrimes */ 321541Srgrimes 3318444Sbde#ifndef _SYS_MTIO_H_ 3418444Sbde#define _SYS_MTIO_H_ 351549Srgrimes 3655205Speter#ifndef _KERNEL 3718444Sbde#include <sys/types.h> 3818444Sbde#endif 3918444Sbde#include <sys/ioccom.h> 4018444Sbde 411541Srgrimes/* 421541Srgrimes * Structures and definitions for mag tape io control commands 431541Srgrimes */ 441541Srgrimes 451541Srgrimes/* structure for MTIOCTOP - mag tape op command */ 461541Srgrimesstruct mtop { 471541Srgrimes short mt_op; /* operations defined below */ 4896564Sphk int32_t mt_count; /* how many of them */ 491541Srgrimes}; 501541Srgrimes 511541Srgrimes/* operations */ 521541Srgrimes#define MTWEOF 0 /* write an end-of-file record */ 531541Srgrimes#define MTFSF 1 /* forward space file */ 541541Srgrimes#define MTBSF 2 /* backward space file */ 551541Srgrimes#define MTFSR 3 /* forward space record */ 561541Srgrimes#define MTBSR 4 /* backward space record */ 571541Srgrimes#define MTREW 5 /* rewind */ 581541Srgrimes#define MTOFFL 6 /* rewind and put the drive offline */ 591541Srgrimes#define MTNOP 7 /* no operation, sets status only */ 601541Srgrimes#define MTCACHE 8 /* enable controller cache */ 611541Srgrimes#define MTNOCACHE 9 /* disable controller cache */ 621541Srgrimes 631549Srgrimes#if defined(__FreeBSD__) 641549Srgrimes/* Set block size for device. If device is a variable size dev */ 651549Srgrimes/* a non zero parameter will change the device to a fixed block size */ 661549Srgrimes/* device with block size set to that of the parameter passed in. */ 671549Srgrimes/* Resetting the block size to 0 will restore the device to a variable */ 681549Srgrimes/* block size device. */ 691549Srgrimes 701549Srgrimes#define MTSETBSIZ 10 711549Srgrimes 7241991Smjacob/* Set density values for device. Sets the value for the opened mode only. */ 731549Srgrimes 741549Srgrimes#define MTSETDNSTY 11 753963Sjkh 767217Sdufault#define MTERASE 12 /* erase to EOM */ 7713347Sjoerg#define MTEOD 13 /* Space to EOM */ 787217Sdufault#define MTCOMP 14 /* select compression mode 0=off, 1=def */ 7913347Sjoerg#define MTRETENS 15 /* re-tension tape */ 8041991Smjacob#define MTWSS 16 /* write setmark(s) */ 8141991Smjacob#define MTFSS 17 /* forward space setmark */ 8241991Smjacob#define MTBSS 18 /* backward space setmark */ 83280438Sken#define MTLOAD 19 /* load tape in drive */ 84280438Sken#define MTWEOFI 20 /* write an end-of-file record without waiting*/ 853963Sjkh 8639248Sgibbs#define MT_COMP_ENABLE 0xffffffff 8739248Sgibbs#define MT_COMP_DISABLED 0xfffffffe 8839248Sgibbs#define MT_COMP_UNSUPP 0xfffffffd 8943630Smjacob 9043630Smjacob/* 9143630Smjacob * Values in mt_dsreg that say what the device is doing 9243630Smjacob */ 9343630Smjacob#define MTIO_DSREG_NIL 0 /* Unknown */ 9443630Smjacob#define MTIO_DSREG_REST 1 /* Doing Nothing */ 9543630Smjacob#define MTIO_DSREG_RBSY 2 /* Communicating with tape (but no motion) */ 9643630Smjacob#define MTIO_DSREG_WR 20 /* Writing */ 9743630Smjacob#define MTIO_DSREG_FMK 21 /* Writing Filemarks */ 9843630Smjacob#define MTIO_DSREG_ZER 22 /* Erasing */ 9943630Smjacob#define MTIO_DSREG_RD 30 /* Reading */ 10043630Smjacob#define MTIO_DSREG_FWD 40 /* Spacing Forward */ 10143630Smjacob#define MTIO_DSREG_REV 41 /* Spacing Reverse */ 10243630Smjacob#define MTIO_DSREG_POS 42 /* Hardware Positioning (direction unknown) */ 10343630Smjacob#define MTIO_DSREG_REW 43 /* Rewinding */ 10443630Smjacob#define MTIO_DSREG_TEN 44 /* Retensioning */ 10543630Smjacob#define MTIO_DSREG_UNL 45 /* Unloading */ 10646925Smjacob#define MTIO_DSREG_LD 46 /* Loading */ 10743630Smjacob 10841944Smjacob#endif /* __FreeBSD__ */ 1091549Srgrimes 1101541Srgrimes/* structure for MTIOCGET - mag tape get status command */ 1111541Srgrimes 1121541Srgrimesstruct mtget { 1131541Srgrimes short mt_type; /* type of magtape device */ 1141541Srgrimes/* the following two registers are grossly device dependent */ 1151541Srgrimes short mt_dsreg; /* ``drive status'' register */ 1161541Srgrimes short mt_erreg; /* ``error'' register */ 1171541Srgrimes/* end device-dependent registers */ 11871312Smjacob /* 11971312Smjacob * Note that the residual count, while maintained, may be 12071312Smjacob * be nonsense because the size of the residual may (greatly) 12171312Smjacob * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a 12271312Smjacob * more accurate count. 12371312Smjacob */ 1241541Srgrimes short mt_resid; /* residual count */ 1251549Srgrimes#if defined (__FreeBSD__) 12696564Sphk int32_t mt_blksiz; /* presently operating blocksize */ 12796564Sphk int32_t mt_density; /* presently operating density */ 12839248Sgibbs u_int32_t mt_comp; /* presently operating compression */ 12996564Sphk int32_t mt_blksiz0; /* blocksize for mode 0 */ 13096564Sphk int32_t mt_blksiz1; /* blocksize for mode 1 */ 13196564Sphk int32_t mt_blksiz2; /* blocksize for mode 2 */ 13296564Sphk int32_t mt_blksiz3; /* blocksize for mode 3 */ 13396564Sphk int32_t mt_density0; /* density for mode 0 */ 13496564Sphk int32_t mt_density1; /* density for mode 1 */ 13596564Sphk int32_t mt_density2; /* density for mode 2 */ 13696564Sphk int32_t mt_density3; /* density for mode 3 */ 1377217Sdufault/* the following are not yet implemented */ 13839248Sgibbs u_int32_t mt_comp0; /* compression type for mode 0 */ 13939248Sgibbs u_int32_t mt_comp1; /* compression type for mode 1 */ 14039248Sgibbs u_int32_t mt_comp2; /* compression type for mode 2 */ 14139248Sgibbs u_int32_t mt_comp3; /* compression type for mode 3 */ 14243639Smjacob/* end not yet implemented */ 1431549Srgrimes#endif 14496564Sphk int32_t mt_fileno; /* relative file number of current position */ 14596564Sphk int32_t mt_blkno; /* relative block number of current position */ 1461541Srgrimes}; 1471541Srgrimes 14841944Smjacob/* structure for MTIOCERRSTAT - tape get error status command */ 14941944Smjacob/* really only supported for SCSI tapes right now */ 15041944Smjacobstruct scsi_tape_errors { 15141944Smjacob /* 15241944Smjacob * These are latched from the last command that had a SCSI 15341944Smjacob * Check Condition noted for these operations. The act 15441944Smjacob * of issuing an MTIOCERRSTAT unlatches and clears them. 15541944Smjacob */ 15641944Smjacob u_int8_t io_sense[32]; /* Last Sense Data For Data I/O */ 15771312Smjacob int32_t io_resid; /* residual count from last Data I/O */ 15842008Smjacob u_int8_t io_cdb[16]; /* Command that Caused the Last Data Sense */ 15941944Smjacob u_int8_t ctl_sense[32]; /* Last Sense Data For Control I/O */ 16071312Smjacob int32_t ctl_resid; /* residual count from last Control I/O */ 16142008Smjacob u_int8_t ctl_cdb[16]; /* Command that Caused the Last Control Sense */ 16241944Smjacob /* 16341944Smjacob * These are the read and write cumulative error counters. 16441944Smjacob * (how to reset cumulative error counters is not yet defined). 16541944Smjacob * (not implemented as yet but space is being reserved for them) 16641944Smjacob */ 16741944Smjacob struct { 16841944Smjacob u_int32_t retries; /* total # retries performed */ 16941944Smjacob u_int32_t corrected; /* total # corrections performed */ 17089609Smpp u_int32_t processed; /* total # corrections successful */ 17141944Smjacob u_int32_t failures; /* total # corrections/retries failed */ 17241944Smjacob u_int64_t nbytes; /* total # bytes processed */ 17343639Smjacob } wterr, rderr; 17441944Smjacob}; 17541944Smjacob 17641944Smjacobunion mterrstat { 17741944Smjacob struct scsi_tape_errors scsi_errstat; 17841944Smjacob char _reserved_padding[256]; 17941944Smjacob}; 18041944Smjacob 181280438Skenstruct mtrblim { 182280438Sken uint32_t granularity; 183280438Sken uint32_t min_block_length; 184280438Sken uint32_t max_block_length; 185280438Sken}; 186280438Sken 187280438Skentypedef enum { 188280438Sken MT_LOCATE_DEST_OBJECT = 0x00, 189280438Sken MT_LOCATE_DEST_FILE = 0x01, 190280438Sken MT_LOCATE_DEST_SET = 0x02, 191280438Sken MT_LOCATE_DEST_EOD = 0x03 192280438Sken} mt_locate_dest_type; 193280438Sken 194280438Skentypedef enum { 195280438Sken MT_LOCATE_BAM_IMPLICIT = 0x00, 196280438Sken MT_LOCATE_BAM_EXPLICIT = 0x01 197280438Sken} mt_locate_bam; 198280438Sken 199280438Skentypedef enum { 200280438Sken MT_LOCATE_FLAG_IMMED = 0x01, 201280438Sken MT_LOCATE_FLAG_CHANGE_PART = 0x02 202280438Sken} mt_locate_flags; 203280438Sken 204280438Skenstruct mtlocate { 205280438Sken mt_locate_flags flags; 206280438Sken mt_locate_dest_type dest_type; 207280438Sken mt_locate_bam block_address_mode; 208280438Sken int64_t partition; 209280438Sken uint64_t logical_id; 210280438Sken uint8_t reserved[64]; 211280438Sken}; 212280438Sken 213280438Skentypedef enum { 214280438Sken MT_EXT_GET_NONE, 215280438Sken MT_EXT_GET_OK, 216280438Sken MT_EXT_GET_NEED_MORE_SPACE, 217280438Sken MT_EXT_GET_ERROR 218280438Sken} mt_ext_get_status; 219280438Sken 220280438Skenstruct mtextget { 221280438Sken uint32_t alloc_len; 222280438Sken char *status_xml; 223280438Sken uint32_t fill_len; 224280438Sken mt_ext_get_status status; 225280438Sken char error_str[128]; 226280438Sken uint8_t reserved[64]; 227280438Sken}; 228280438Sken 229280438Sken#define MT_EXT_GET_ROOT_NAME "mtextget" 230280438Sken#define MT_DENSITY_ROOT_NAME "mtdensity" 231280438Sken#define MT_MEDIA_DENSITY_NAME "media_density" 232280438Sken#define MT_DENSITY_REPORT_NAME "density_report" 233280438Sken#define MT_MEDIUM_TYPE_REPORT_NAME "medium_type_report" 234280438Sken#define MT_MEDIA_REPORT_NAME "media_report" 235280438Sken#define MT_DENSITY_ENTRY_NAME "density_entry" 236280438Sken 237280438Sken#define MT_DENS_WRITE_OK 0x80 238280438Sken#define MT_DENS_DUP 0x40 239280438Sken#define MT_DENS_DEFLT 0x20 240280438Sken 241280438Sken 242280438Sken#define MT_PARAM_FIXED_STR_LEN 32 243280438Skenunion mt_param_value { 244280438Sken int64_t value_signed; 245280438Sken uint64_t value_unsigned; 246280438Sken char *value_var_str; 247280438Sken char value_fixed_str[MT_PARAM_FIXED_STR_LEN]; 248280438Sken uint8_t reserved[64]; 249280438Sken}; 250280438Sken 251280438Skentypedef enum { 252280438Sken MT_PARAM_SET_NONE, 253280438Sken MT_PARAM_SET_SIGNED, 254280438Sken MT_PARAM_SET_UNSIGNED, 255280438Sken MT_PARAM_SET_VAR_STR, 256280438Sken MT_PARAM_SET_FIXED_STR 257280438Sken} mt_param_set_type; 258280438Sken 259280438Skentypedef enum { 260280438Sken MT_PARAM_STATUS_NONE, 261280438Sken MT_PARAM_STATUS_OK, 262280438Sken MT_PARAM_STATUS_ERROR 263280438Sken} mt_param_set_status; 264280438Sken 265280438Sken#define MT_PARAM_VALUE_NAME_LEN 64 266280438Skenstruct mtparamset { 267280438Sken char value_name[MT_PARAM_VALUE_NAME_LEN]; 268280438Sken mt_param_set_type value_type; 269280438Sken int value_len; 270280438Sken union mt_param_value value; 271280438Sken mt_param_set_status status; 272280438Sken char error_str[128]; 273280438Sken}; 274280438Sken 275280438Sken#define MT_PARAM_ROOT_NAME "mtparamget" 276280438Sken#define MT_PROTECTION_NAME "protection" 277280438Sken 2781541Srgrimes/* 279280438Sken * Set a list of parameters. 280280438Sken */ 281280438Skenstruct mtsetlist { 282280438Sken int num_params; 283280438Sken int param_len; 284280438Sken struct mtparamset *params; 285280438Sken}; 286280438Sken 287280438Sken/* 2881541Srgrimes * Constants for mt_type byte. These are the same 2891541Srgrimes * for controllers compatible with the types listed. 2901541Srgrimes */ 2911541Srgrimes#define MT_ISTS 0x01 /* TS-11 */ 2921541Srgrimes#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ 2931541Srgrimes#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ 2941541Srgrimes#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ 2951541Srgrimes#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ 2961541Srgrimes#define MT_ISCPC 0x06 /* SUN */ 2971541Srgrimes#define MT_ISAR 0x07 /* SUN */ 2981541Srgrimes#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ 2991541Srgrimes#define MT_ISCY 0x09 /* CCI Cipher */ 3001541Srgrimes#define MT_ISCT 0x0a /* HP 1/4 tape */ 3011541Srgrimes#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */ 3021541Srgrimes#define MT_ISEXABYTE 0x0c /* Exabyte */ 3031541Srgrimes#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */ 3041541Srgrimes#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */ 3051541Srgrimes#define MT_ISVIPER1 0x0e /* Archive Viper-150 */ 3061541Srgrimes#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */ 3071541Srgrimes#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */ 3081541Srgrimes#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */ 3091541Srgrimes#define MT_ISTK50 0x12 /* DEC SCSI TK50 */ 3101541Srgrimes#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */ 3111541Srgrimes 3121541Srgrimes/* mag tape io control commands */ 3131541Srgrimes#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ 3141541Srgrimes#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ 31541944Smjacob/* these two do not appear to be used anywhere */ 3161541Srgrimes#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */ 3171541Srgrimes#define MTIOCEEOT _IO('m', 4) /* enable EOT error */ 31841909Smjacob/* 31941909Smjacob * When more SCSI-3 SSC (streaming device) devices are out there 32041909Smjacob * that support the full 32 byte type 2 structure, we'll have to 32141909Smjacob * rethink these ioctls to support all the entities they haul into 32241909Smjacob * the picture (64 bit blocks, logical file record numbers, etc..). 32341909Smjacob */ 32441909Smjacob#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */ 32541909Smjacob#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */ 32641909Smjacob#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */ 32741909Smjacob#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */ 32841944Smjacob#define MTIOCERRSTAT _IOR('m', 7, union mterrstat) /* get tape errors */ 329280438Sken 33046925Smjacob/* 33146925Smjacob * Set EOT model- argument is number of filemarks to end a tape with. 33246925Smjacob * Note that not all possible values will be accepted. 33346925Smjacob */ 33446925Smjacob#define MTIOCSETEOTMODEL _IOW('m', 8, u_int32_t) 33546925Smjacob/* Get current EOT model */ 33646925Smjacob#define MTIOCGETEOTMODEL _IOR('m', 8, u_int32_t) 3371541Srgrimes 338280438Sken#define MTIOCRBLIM _IOR('m', 9, struct mtrblim) /* get block limits */ 339280438Sken#define MTIOCEXTLOCATE _IOW('m', 10, struct mtlocate) /* seek to position */ 340280438Sken#define MTIOCEXTGET _IOWR('m', 11, struct mtextget) /* get tape status */ 341280438Sken#define MTIOCPARAMGET _IOWR('m', 12, struct mtextget) /* get tape params */ 342280438Sken#define MTIOCPARAMSET _IOWR('m', 13, struct mtparamset) /* set tape params */ 343280438Sken#define MTIOCSETLIST _IOWR('m', 14, struct mtsetlist) /* set N params */ 344280438Sken 34555205Speter#ifndef _KERNEL 34670545Smjacob#define DEFTAPE "/dev/nsa0" 3471541Srgrimes#endif 3481541Srgrimes 34918444Sbde#endif /* !_SYS_MTIO_H_ */ 350