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