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