stvar.h revision 1.25 1 1.25 riastrad /* $NetBSD: stvar.h,v 1.25 2015/04/13 16:33:25 riastradh 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.25 riastrad #include <sys/rndsource.h>
53 1.1 bouyer
54 1.1 bouyer #include <dev/scsipi/scsipi_all.h>
55 1.1 bouyer #include <dev/scsipi/scsiconf.h>
56 1.1 bouyer
57 1.2 bouyer #define ST_IO_TIME (3 * 60 * 1000) /* 3 minutes */
58 1.2 bouyer #define ST_CTL_TIME (30 * 1000) /* 30 seconds */
59 1.2 bouyer #define ST_SPC_TIME (4 * 60 * 60 * 1000) /* 4 hours */
60 1.2 bouyer
61 1.2 bouyer #define ST_RETRIES 4 /* only on non IO commands */
62 1.2 bouyer
63 1.1 bouyer struct modes {
64 1.12 reinoud u_int quirks; /* same definitions as in quirkdata */
65 1.1 bouyer int blksize;
66 1.24 mbalmer uint8_t density;
67 1.1 bouyer };
68 1.1 bouyer
69 1.1 bouyer struct quirkdata {
70 1.12 reinoud u_int quirks;
71 1.1 bouyer #define ST_Q_FORCE_BLKSIZE 0x0001
72 1.1 bouyer #define ST_Q_SENSE_HELP 0x0002 /* must do READ for good MODE SENSE */
73 1.1 bouyer #define ST_Q_IGNORE_LOADS 0x0004
74 1.1 bouyer #define ST_Q_BLKSIZE 0x0008 /* variable-block media_blksize > 0 */
75 1.1 bouyer #define ST_Q_UNIMODAL 0x0010 /* unimode drive rejects mode select */
76 1.1 bouyer #define ST_Q_NOPREVENT 0x0020 /* does not support PREVENT */
77 1.1 bouyer #define ST_Q_ERASE_NOIMM 0x0040 /* drive rejects ERASE/w Immed bit */
78 1.3 bouyer #define ST_Q_NOFILEMARKS 0x0080 /* can only write 0 filemarks */
79 1.12 reinoud u_int page_0_size;
80 1.1 bouyer #define MAX_PAGE_0_SIZE 64
81 1.1 bouyer struct modes modes[4];
82 1.1 bouyer };
83 1.1 bouyer
84 1.1 bouyer struct st_quirk_inquiry_pattern {
85 1.1 bouyer struct scsipi_inquiry_pattern pattern;
86 1.1 bouyer struct quirkdata quirkdata;
87 1.1 bouyer };
88 1.1 bouyer
89 1.1 bouyer struct st_softc {
90 1.24 mbalmer device_t sc_dev;
91 1.2 bouyer /*--------------------callback to bus-specific code--------------------------*/
92 1.7 thorpej int (*ops)(struct st_softc *, int, int);
93 1.2 bouyer #define ST_OPS_RBL 0x00 /* read block limit */
94 1.2 bouyer #define ST_OPS_MODESENSE 0x01 /* mode sense */
95 1.2 bouyer #define ST_OPS_MODESELECT 0x02 /* mode select */
96 1.2 bouyer #define ST_OPS_CMPRSS_ON 0x03 /* turn on compression */
97 1.2 bouyer #define ST_OPS_CMPRSS_OFF 0x04 /* turn off compression */
98 1.1 bouyer /*--------------------present operating parameters, flags etc.---------------*/
99 1.1 bouyer int flags; /* see below */
100 1.12 reinoud u_int quirks; /* quirks for the open mode */
101 1.1 bouyer int blksize; /* blksize we are using */
102 1.24 mbalmer uint8_t density; /* present density */
103 1.12 reinoud u_int page_0_size; /* size of page 0 data */
104 1.12 reinoud u_int last_dsty; /* last density opened */
105 1.12 reinoud short mt_resid; /* last (short) resid */
106 1.12 reinoud short mt_erreg; /* last error (sense key) seen */
107 1.5 christos /* relative to BOT location */
108 1.5 christos daddr_t fileno;
109 1.5 christos daddr_t blkno;
110 1.5 christos int32_t last_io_resid;
111 1.5 christos int32_t last_ctl_resid;
112 1.1 bouyer #define mt_key mt_erreg
113 1.24 mbalmer uint8_t asc; /* last asc code seen */
114 1.24 mbalmer uint8_t ascq; /* last asc code seen */
115 1.1 bouyer /*--------------------device/scsi parameters---------------------------------*/
116 1.1 bouyer struct scsipi_periph *sc_periph;/* our link to the adpter etc. */
117 1.1 bouyer /*--------------------parameters reported by the device ---------------------*/
118 1.1 bouyer int blkmin; /* min blk size */
119 1.1 bouyer int blkmax; /* max blk size */
120 1.13 christos const struct quirkdata *quirkdata; /* if we have a rogue entry */
121 1.1 bouyer /*--------------------parameters reported by the device for this media-------*/
122 1.12 reinoud u_long numblks; /* nominal blocks capacity */
123 1.1 bouyer int media_blksize; /* 0 if not ST_FIXEDBLOCKS */
124 1.24 mbalmer uint8_t media_density; /* this is what it said when asked */
125 1.1 bouyer /*--------------------quirks for the whole drive-----------------------------*/
126 1.12 reinoud u_int drive_quirks; /* quirks of this drive */
127 1.1 bouyer /*--------------------How we should set up when opening each minor device----*/
128 1.1 bouyer struct modes modes[4]; /* plus more for each mode */
129 1.24 mbalmer uint8_t modeflags[4]; /* flags for the modes */
130 1.1 bouyer #define DENSITY_SET_BY_USER 0x01
131 1.1 bouyer #define DENSITY_SET_BY_QUIRK 0x02
132 1.1 bouyer #define BLKSIZE_SET_BY_USER 0x04
133 1.1 bouyer #define BLKSIZE_SET_BY_QUIRK 0x08
134 1.1 bouyer /*--------------------storage for sense data returned by the drive-----------*/
135 1.12 reinoud u_char sense_data[MAX_PAGE_0_SIZE]; /*
136 1.1 bouyer * additional sense data needed
137 1.1 bouyer * for mode sense/select.
138 1.1 bouyer */
139 1.15 yamt struct bufq_state *buf_queue; /* the queue of pending IO */
140 1.1 bouyer /* operations */
141 1.9 bouyer struct callout sc_callout; /* restarting the queue after */
142 1.9 bouyer /* transient error */
143 1.17 blymn
144 1.17 blymn struct io_stats *stats; /* statistics for the drive */
145 1.17 blymn
146 1.22 tls krndsource_t rnd_source;
147 1.1 bouyer };
148 1.1 bouyer
149 1.2 bouyer #define ST_INFO_VALID 0x0001
150 1.2 bouyer #define ST_BLOCK_SET 0x0002 /* block size, mode set by ioctl */
151 1.2 bouyer #define ST_WRITTEN 0x0004 /* data has been written, EOD needed */
152 1.2 bouyer #define ST_FIXEDBLOCKS 0x0008
153 1.2 bouyer #define ST_AT_FILEMARK 0x0010
154 1.2 bouyer #define ST_EIO_PENDING 0x0020 /* error reporting deferred until next op */
155 1.2 bouyer #define ST_NEW_MOUNT 0x0040 /* still need to decide mode */
156 1.2 bouyer #define ST_READONLY 0x0080 /* st_mode_sense says write protected */
157 1.2 bouyer #define ST_FM_WRITTEN 0x0100 /*
158 1.2 bouyer * EOF file mark written -- used with
159 1.2 bouyer * ~ST_WRITTEN to indicate that multiple file
160 1.2 bouyer * marks have been written
161 1.2 bouyer */
162 1.2 bouyer #define ST_BLANK_READ 0x0200 /* BLANK CHECK encountered already */
163 1.2 bouyer #define ST_2FM_AT_EOD 0x0400 /* write 2 file marks at EOD */
164 1.2 bouyer #define ST_MOUNTED 0x0800 /* Device is presently mounted */
165 1.2 bouyer #define ST_DONTBUFFER 0x1000 /* Disable buffering/caching */
166 1.2 bouyer #define ST_EARLYWARN 0x2000 /* Do (deferred) EOM for variable mode */
167 1.2 bouyer #define ST_EOM_PENDING 0x4000 /* EOM reporting deferred until next op */
168 1.5 christos #define ST_POSUPDATED 0x8000 /* tape position already updated */
169 1.2 bouyer
170 1.2 bouyer #define ST_PER_ACTION (ST_AT_FILEMARK | ST_EIO_PENDING | ST_EOM_PENDING | \
171 1.2 bouyer ST_BLANK_READ)
172 1.2 bouyer #define ST_PER_MOUNT (ST_INFO_VALID | ST_BLOCK_SET | ST_WRITTEN | \
173 1.2 bouyer ST_FIXEDBLOCKS | ST_READONLY | ST_FM_WRITTEN | \
174 1.5 christos ST_2FM_AT_EOD | ST_PER_ACTION | ST_POSUPDATED)
175 1.1 bouyer
176 1.24 mbalmer void stattach(device_t, device_t, void *);
177 1.19 cegger int stdetach(device_t, int);
178 1.20 pgoyette int st_mode_select(struct st_softc *, int);
179 1.1 bouyer
180 1.1 bouyer extern struct cfdriver st_cd;
181