xref: /dragonfly/sys/dev/disk/nata/atapi-tape.h (revision 2458a87a)
1 /*-
2  * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
3  * 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  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/dev/ata/atapi-tape.h,v 1.24 2006/01/05 21:27:19 sos Exp $
27  */
28 
29 #include <sys/param.h>
30 #include <sys/devicestat.h>
31 
32 /* ATAPI tape drive Capabilities and Mechanical Status Page */
33 struct ast_cappage {
34     /* mode page data header */
35     u_int8_t    data_length;                    /* total length of data */
36     u_int8_t    medium_type;                    /* medium type (if any) */
37     u_int8_t    reserved        :4;
38     u_int8_t    mode            :3;             /* buffering mode */
39     u_int8_t    write_protect   :1;             /* media is writeprotected */
40     u_int8_t    blk_desc_len;                   /* block Descriptor Length */
41 
42     /* capabilities page */
43     u_int8_t    page_code       :6;
44 #define ATAPI_TAPE_CAP_PAGE     0x2a
45 
46     u_int8_t    reserved0_6     :1;
47     u_int8_t    ps              :1;             /* parameters saveable */
48     u_int8_t    page_length;                    /* page Length == 0x12 */
49     u_int8_t    reserved2;
50     u_int8_t    reserved3;
51     u_int8_t    readonly        :1;             /* read Only Mode */
52     u_int8_t    reserved4_1234  :4;
53     u_int8_t    reverse         :1;             /* supports reverse direction */
54     u_int8_t    reserved4_67    :2;
55     u_int8_t    reserved5_012   :3;
56     u_int8_t    eformat         :1;             /* supports ERASE formatting */
57     u_int8_t    reserved5_4     :1;
58     u_int8_t    qfa             :1;             /* supports QFA formats */
59     u_int8_t    reserved5_67    :2;
60     u_int8_t    lock            :1;             /* supports locking media */
61     u_int8_t    locked          :1;             /* the media is locked */
62     u_int8_t    prevent         :1;             /* defaults to prevent state */
63     u_int8_t    eject           :1;             /* supports eject */
64     u_int8_t    disconnect      :1;             /* can break request > ctl */
65     u_int8_t    reserved6_5     :1;
66     u_int8_t    ecc             :1;             /* supports error correction */
67     u_int8_t    compress        :1;             /* supports data compression */
68     u_int8_t    reserved7_0     :1;
69     u_int8_t    blk512          :1;             /* supports 512b block size */
70     u_int8_t    blk1024         :1;             /* supports 1024b block size */
71     u_int8_t    reserved7_3456  :4;
72     u_int8_t    blk32k          :1;             /* supports 32kb block size */
73     u_int16_t   max_speed;                      /* supported speed in KBps */
74     u_int16_t   max_defects;                    /* max stored defect entries */
75     u_int16_t   ctl;                            /* continuous transfer limit */
76     u_int16_t   speed;                          /* current Speed, in KBps */
77     u_int16_t   buffer_size;                    /* buffer Size, in 512 bytes */
78     u_int8_t    reserved18;
79     u_int8_t    reserved19;
80 };
81 
82 /* ATAPI OnStream ADR data transfer mode page (ADR unique) */
83 struct ast_transferpage {
84     /* mode page data header */
85     u_int8_t    data_length;                    /* total length of data */
86     u_int8_t    medium_type;                    /* medium type (if any) */
87     u_int8_t    dsp;                            /* device specific parameter */
88     u_int8_t    blk_desc_len;                   /* block Descriptor Length */
89 
90     /* data transfer page */
91     u_int8_t    page_code       :6;
92 #define ATAPI_TAPE_TRANSFER_PAGE     0x30
93 
94     u_int8_t    reserved0_6     :1;
95     u_int8_t    ps              :1;             /* parameters saveable */
96     u_int8_t    page_length;                    /* page Length == 0x02 */
97     u_int8_t    reserved2;
98     u_int8_t    read32k         :1;             /* 32k blk size (data only) */
99     u_int8_t    read32k5        :1;             /* 32.5k blk size (data&AUX) */
100     u_int8_t    reserved3_23    :2;
101     u_int8_t    write32k        :1;             /* 32k blk size (data only) */
102     u_int8_t    write32k5       :1;             /* 32.5k blk size (data&AUX) */
103     u_int8_t    reserved3_6     :1;
104     u_int8_t    streaming       :1;             /* streaming mode enable */
105 };
106 
107 /* ATAPI OnStream ADR vendor identification mode page (ADR unique) */
108 struct ast_identifypage {
109     /* mode page data header */
110     u_int8_t    data_length;                    /* total length of data */
111     u_int8_t    medium_type;                    /* medium type (if any) */
112     u_int8_t    dsp;                            /* device specific parameter */
113     u_int8_t    blk_desc_len;                   /* block Descriptor Length */
114 
115     /* data transfer page */
116     u_int8_t    page_code       :6;
117 #define ATAPI_TAPE_IDENTIFY_PAGE     0x36
118 
119     u_int8_t    reserved0_6     :1;
120     u_int8_t    ps              :1;             /* parameters saveable */
121     u_int8_t    page_length;                    /* page Length == 0x06 */
122     u_int8_t    ident[4];                       /* host id string */
123     u_int8_t    reserved6;
124     u_int8_t    reserved7;
125 };
126 
127 /* ATAPI read position structure */
128 struct ast_readposition {
129     u_int8_t    reserved0_05    :6;
130     u_int8_t    eop             :1;             /* end of partition */
131     u_int8_t    bop             :1;             /* beginning of partition */
132     u_int8_t    reserved1;
133     u_int8_t    reserved2;
134     u_int8_t    reserved3;
135     u_int32_t   host;                           /* frame address in buffer */
136     u_int32_t   tape;                           /* frame address on tape */
137     u_int8_t    reserved12;
138     u_int8_t    reserved13;
139     u_int8_t    reserved14;
140     u_int8_t    blks_in_buf;                    /* blocks in buffer */
141     u_int8_t    reserved16;
142     u_int8_t    reserved17;
143     u_int8_t    reserved18;
144     u_int8_t    reserved19;
145 };
146 
147 struct ast_softc {
148     int                         flags;          /* device state flags */
149 #define         F_CTL_WARN              0x0001  /* warned about CTL wrong? */
150 #define         F_WRITEPROTECT          0x0002  /* media is writeprotected */
151 #define         F_DATA_WRITTEN          0x0004  /* data has been written */
152 #define         F_FM_WRITTEN            0x0008  /* filemark has been written */
153 #define         F_ONSTREAM              0x0100  /* OnStream ADR device */
154 
155     int                         blksize;        /* block size (512 | 1024) */
156     struct atapi_params         *param;         /* drive parameters table */
157     struct ast_cappage          cap;            /* capabilities page info */
158     struct devstat              stats;          /* devstat entry */
159     cdev_t                      cdev1, cdev2;   /* device place holders */
160 };
161