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