stvar.h revision 1.2.2.4 1 1.2.2.4 nathanw /* $NetBSD: stvar.h,v 1.2.2.4 2002/04/01 07:47:21 nathanw Exp $ */
2 1.2.2.2 nathanw
3 1.2.2.2 nathanw /*-
4 1.2.2.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2.2.2 nathanw * All rights reserved.
6 1.2.2.2 nathanw *
7 1.2.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 nathanw * by Charles M. Hannum.
9 1.2.2.2 nathanw *
10 1.2.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.2.2 nathanw * are met:
13 1.2.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 nathanw * must display the following acknowledgement:
20 1.2.2.2 nathanw * This product includes software developed by the NetBSD
21 1.2.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.2.2 nathanw * from this software without specific prior written permission.
25 1.2.2.2 nathanw *
26 1.2.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 nathanw */
38 1.2.2.2 nathanw
39 1.2.2.2 nathanw /*
40 1.2.2.2 nathanw * Originally written by Julian Elischer (julian (at) tfs.com)
41 1.2.2.2 nathanw * for TRW Financial Systems for use under the MACH(2.5) operating system.
42 1.2.2.2 nathanw *
43 1.2.2.2 nathanw * TRW Financial Systems, in accordance with their agreement with Carnegie
44 1.2.2.2 nathanw * Mellon University, makes this software available to CMU to distribute
45 1.2.2.2 nathanw * or use in any manner that they see fit as long as this message is kept with
46 1.2.2.2 nathanw * the software. For this reason TFS also grants any other persons or
47 1.2.2.2 nathanw * organisations permission to use or modify this software.
48 1.2.2.2 nathanw *
49 1.2.2.2 nathanw * TFS supplies this software to be publicly redistributed
50 1.2.2.2 nathanw * on the understanding that TFS is not responsible for the correct
51 1.2.2.2 nathanw * functioning of this software in any circumstances.
52 1.2.2.2 nathanw *
53 1.2.2.2 nathanw * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
54 1.2.2.2 nathanw * major changes by Julian Elischer (julian (at) jules.dialix.oz.au) May 1993
55 1.2.2.2 nathanw *
56 1.2.2.2 nathanw * A lot of rewhacking done by mjacob (mjacob (at) nas.nasa.gov).
57 1.2.2.2 nathanw */
58 1.2.2.2 nathanw
59 1.2.2.2 nathanw #include "rnd.h"
60 1.2.2.2 nathanw #if NRND > 0
61 1.2.2.2 nathanw #include <sys/rnd.h>
62 1.2.2.2 nathanw #endif
63 1.2.2.2 nathanw
64 1.2.2.2 nathanw #include <dev/scsipi/scsipi_all.h>
65 1.2.2.2 nathanw #include <dev/scsipi/scsiconf.h>
66 1.2.2.2 nathanw
67 1.2.2.2 nathanw #define ST_IO_TIME (3 * 60 * 1000) /* 3 minutes */
68 1.2.2.2 nathanw #define ST_CTL_TIME (30 * 1000) /* 30 seconds */
69 1.2.2.2 nathanw #define ST_SPC_TIME (4 * 60 * 60 * 1000) /* 4 hours */
70 1.2.2.2 nathanw
71 1.2.2.2 nathanw #define ST_RETRIES 4 /* only on non IO commands */
72 1.2.2.2 nathanw
73 1.2.2.2 nathanw struct modes {
74 1.2.2.2 nathanw u_int quirks; /* same definitions as in quirkdata */
75 1.2.2.2 nathanw int blksize;
76 1.2.2.2 nathanw u_int8_t density;
77 1.2.2.2 nathanw };
78 1.2.2.2 nathanw
79 1.2.2.2 nathanw struct quirkdata {
80 1.2.2.2 nathanw u_int quirks;
81 1.2.2.2 nathanw #define ST_Q_FORCE_BLKSIZE 0x0001
82 1.2.2.2 nathanw #define ST_Q_SENSE_HELP 0x0002 /* must do READ for good MODE SENSE */
83 1.2.2.2 nathanw #define ST_Q_IGNORE_LOADS 0x0004
84 1.2.2.2 nathanw #define ST_Q_BLKSIZE 0x0008 /* variable-block media_blksize > 0 */
85 1.2.2.2 nathanw #define ST_Q_UNIMODAL 0x0010 /* unimode drive rejects mode select */
86 1.2.2.2 nathanw #define ST_Q_NOPREVENT 0x0020 /* does not support PREVENT */
87 1.2.2.2 nathanw #define ST_Q_ERASE_NOIMM 0x0040 /* drive rejects ERASE/w Immed bit */
88 1.2.2.3 nathanw #define ST_Q_NOFILEMARKS 0x0080 /* can only write 0 filemarks */
89 1.2.2.2 nathanw u_int page_0_size;
90 1.2.2.2 nathanw #define MAX_PAGE_0_SIZE 64
91 1.2.2.2 nathanw struct modes modes[4];
92 1.2.2.2 nathanw };
93 1.2.2.2 nathanw
94 1.2.2.2 nathanw struct st_quirk_inquiry_pattern {
95 1.2.2.2 nathanw struct scsipi_inquiry_pattern pattern;
96 1.2.2.2 nathanw struct quirkdata quirkdata;
97 1.2.2.2 nathanw };
98 1.2.2.2 nathanw
99 1.2.2.2 nathanw struct st_softc {
100 1.2.2.2 nathanw struct device sc_dev;
101 1.2.2.2 nathanw /*--------------------callback to bus-specific code--------------------------*/
102 1.2.2.2 nathanw int (*ops) __P((struct st_softc *, int, int));
103 1.2.2.2 nathanw #define ST_OPS_RBL 0x00 /* read block limit */
104 1.2.2.2 nathanw #define ST_OPS_MODESENSE 0x01 /* mode sense */
105 1.2.2.2 nathanw #define ST_OPS_MODESELECT 0x02 /* mode select */
106 1.2.2.2 nathanw #define ST_OPS_CMPRSS_ON 0x03 /* turn on compression */
107 1.2.2.2 nathanw #define ST_OPS_CMPRSS_OFF 0x04 /* turn off compression */
108 1.2.2.2 nathanw /*--------------------present operating parameters, flags etc.---------------*/
109 1.2.2.2 nathanw int flags; /* see below */
110 1.2.2.2 nathanw u_int quirks; /* quirks for the open mode */
111 1.2.2.2 nathanw int blksize; /* blksize we are using */
112 1.2.2.2 nathanw u_int8_t density; /* present density */
113 1.2.2.2 nathanw u_int page_0_size; /* size of page 0 data */
114 1.2.2.2 nathanw u_int last_dsty; /* last density opened */
115 1.2.2.2 nathanw short mt_resid; /* last (short) resid */
116 1.2.2.2 nathanw short mt_erreg; /* last error (sense key) seen */
117 1.2.2.4 nathanw /* relative to BOT location */
118 1.2.2.4 nathanw daddr_t fileno;
119 1.2.2.4 nathanw daddr_t blkno;
120 1.2.2.4 nathanw int32_t last_io_resid;
121 1.2.2.4 nathanw int32_t last_ctl_resid;
122 1.2.2.2 nathanw #define mt_key mt_erreg
123 1.2.2.2 nathanw u_int8_t asc; /* last asc code seen */
124 1.2.2.2 nathanw u_int8_t ascq; /* last asc code seen */
125 1.2.2.2 nathanw /*--------------------device/scsi parameters---------------------------------*/
126 1.2.2.2 nathanw struct scsipi_periph *sc_periph;/* our link to the adpter etc. */
127 1.2.2.2 nathanw /*--------------------parameters reported by the device ---------------------*/
128 1.2.2.2 nathanw int blkmin; /* min blk size */
129 1.2.2.2 nathanw int blkmax; /* max blk size */
130 1.2.2.2 nathanw struct quirkdata *quirkdata; /* if we have a rogue entry */
131 1.2.2.2 nathanw /*--------------------parameters reported by the device for this media-------*/
132 1.2.2.2 nathanw u_long numblks; /* nominal blocks capacity */
133 1.2.2.2 nathanw int media_blksize; /* 0 if not ST_FIXEDBLOCKS */
134 1.2.2.2 nathanw u_int8_t media_density; /* this is what it said when asked */
135 1.2.2.2 nathanw /*--------------------quirks for the whole drive-----------------------------*/
136 1.2.2.2 nathanw u_int drive_quirks; /* quirks of this drive */
137 1.2.2.2 nathanw /*--------------------How we should set up when opening each minor device----*/
138 1.2.2.2 nathanw struct modes modes[4]; /* plus more for each mode */
139 1.2.2.2 nathanw u_int8_t modeflags[4]; /* flags for the modes */
140 1.2.2.2 nathanw #define DENSITY_SET_BY_USER 0x01
141 1.2.2.2 nathanw #define DENSITY_SET_BY_QUIRK 0x02
142 1.2.2.2 nathanw #define BLKSIZE_SET_BY_USER 0x04
143 1.2.2.2 nathanw #define BLKSIZE_SET_BY_QUIRK 0x08
144 1.2.2.2 nathanw /*--------------------storage for sense data returned by the drive-----------*/
145 1.2.2.2 nathanw u_char sense_data[MAX_PAGE_0_SIZE]; /*
146 1.2.2.2 nathanw * additional sense data needed
147 1.2.2.2 nathanw * for mode sense/select.
148 1.2.2.2 nathanw */
149 1.2.2.2 nathanw struct buf_queue buf_queue; /* the queue of pending IO */
150 1.2.2.2 nathanw /* operations */
151 1.2.2.2 nathanw #if NRND > 0
152 1.2.2.2 nathanw rndsource_element_t rnd_source;
153 1.2.2.2 nathanw #endif
154 1.2.2.2 nathanw };
155 1.2.2.2 nathanw
156 1.2.2.2 nathanw #define ST_INFO_VALID 0x0001
157 1.2.2.2 nathanw #define ST_BLOCK_SET 0x0002 /* block size, mode set by ioctl */
158 1.2.2.2 nathanw #define ST_WRITTEN 0x0004 /* data has been written, EOD needed */
159 1.2.2.2 nathanw #define ST_FIXEDBLOCKS 0x0008
160 1.2.2.2 nathanw #define ST_AT_FILEMARK 0x0010
161 1.2.2.2 nathanw #define ST_EIO_PENDING 0x0020 /* error reporting deferred until next op */
162 1.2.2.2 nathanw #define ST_NEW_MOUNT 0x0040 /* still need to decide mode */
163 1.2.2.2 nathanw #define ST_READONLY 0x0080 /* st_mode_sense says write protected */
164 1.2.2.2 nathanw #define ST_FM_WRITTEN 0x0100 /*
165 1.2.2.2 nathanw * EOF file mark written -- used with
166 1.2.2.2 nathanw * ~ST_WRITTEN to indicate that multiple file
167 1.2.2.2 nathanw * marks have been written
168 1.2.2.2 nathanw */
169 1.2.2.2 nathanw #define ST_BLANK_READ 0x0200 /* BLANK CHECK encountered already */
170 1.2.2.2 nathanw #define ST_2FM_AT_EOD 0x0400 /* write 2 file marks at EOD */
171 1.2.2.2 nathanw #define ST_MOUNTED 0x0800 /* Device is presently mounted */
172 1.2.2.2 nathanw #define ST_DONTBUFFER 0x1000 /* Disable buffering/caching */
173 1.2.2.2 nathanw #define ST_EARLYWARN 0x2000 /* Do (deferred) EOM for variable mode */
174 1.2.2.2 nathanw #define ST_EOM_PENDING 0x4000 /* EOM reporting deferred until next op */
175 1.2.2.4 nathanw #define ST_POSUPDATED 0x8000 /* tape position already updated */
176 1.2.2.2 nathanw
177 1.2.2.2 nathanw #define ST_PER_ACTION (ST_AT_FILEMARK | ST_EIO_PENDING | ST_EOM_PENDING | \
178 1.2.2.2 nathanw ST_BLANK_READ)
179 1.2.2.2 nathanw #define ST_PER_MOUNT (ST_INFO_VALID | ST_BLOCK_SET | ST_WRITTEN | \
180 1.2.2.2 nathanw ST_FIXEDBLOCKS | ST_READONLY | ST_FM_WRITTEN | \
181 1.2.2.4 nathanw ST_2FM_AT_EOD | ST_PER_ACTION | ST_POSUPDATED)
182 1.2.2.2 nathanw
183 1.2.2.2 nathanw void stattach __P((struct device *, struct st_softc *, void *));
184 1.2.2.3 nathanw int stactivate __P((struct device *, enum devact));
185 1.2.2.3 nathanw int stdetach __P((struct device *, int));
186 1.2.2.2 nathanw
187 1.2.2.2 nathanw extern struct cfdriver st_cd;
188