xref: /netbsd-src/sys/dev/scsipi/stvar.h (revision 27578b9aac214cc7796ead81dcc5427e79d5f2a0)
1 /*	$NetBSD: stvar.h,v 1.2 2001/06/18 09:05:05 bouyer 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 	u_int page_0_size;
89 #define	MAX_PAGE_0_SIZE	64
90 	struct modes modes[4];
91 };
92 
93 struct st_quirk_inquiry_pattern {
94 	struct scsipi_inquiry_pattern pattern;
95 	struct quirkdata quirkdata;
96 };
97 
98 struct st_softc {
99 	struct device sc_dev;
100 /*--------------------callback to bus-specific code--------------------------*/
101 	int (*ops) __P((struct st_softc *, int, int));
102 #define ST_OPS_RBL		0x00	/* read block limit */
103 #define ST_OPS_MODESENSE	0x01	/* mode sense */
104 #define ST_OPS_MODESELECT	0x02	/* mode select */
105 #define ST_OPS_CMPRSS_ON 	0x03	/* turn on compression */
106 #define ST_OPS_CMPRSS_OFF 	0x04	/* turn off compression */
107 /*--------------------present operating parameters, flags etc.---------------*/
108 	int flags;		/* see below                         */
109 	u_int quirks;		/* quirks for the open mode          */
110 	int blksize;		/* blksize we are using              */
111 	u_int8_t density;	/* present density                   */
112 	u_int page_0_size;	/* size of page 0 data		     */
113 	u_int last_dsty;	/* last density opened               */
114 	short mt_resid;		/* last (short) resid                */
115 	short mt_erreg;		/* last error (sense key) seen       */
116 #define	mt_key	mt_erreg
117 	u_int8_t asc;		/* last asc code seen		     */
118 	u_int8_t ascq;		/* last asc code seen		     */
119 /*--------------------device/scsi parameters---------------------------------*/
120 	struct scsipi_periph *sc_periph;/* our link to the adpter etc.       */
121 /*--------------------parameters reported by the device ---------------------*/
122 	int blkmin;		/* min blk size                       */
123 	int blkmax;		/* max blk size                       */
124 	struct quirkdata *quirkdata;	/* if we have a rogue entry          */
125 /*--------------------parameters reported by the device for this media-------*/
126 	u_long numblks;		/* nominal blocks capacity            */
127 	int media_blksize;	/* 0 if not ST_FIXEDBLOCKS            */
128 	u_int8_t media_density;	/* this is what it said when asked    */
129 /*--------------------quirks for the whole drive-----------------------------*/
130 	u_int drive_quirks;	/* quirks of this drive               */
131 /*--------------------How we should set up when opening each minor device----*/
132 	struct modes modes[4];	/* plus more for each mode            */
133 	u_int8_t  modeflags[4];	/* flags for the modes                */
134 #define DENSITY_SET_BY_USER	0x01
135 #define DENSITY_SET_BY_QUIRK	0x02
136 #define BLKSIZE_SET_BY_USER	0x04
137 #define BLKSIZE_SET_BY_QUIRK	0x08
138 /*--------------------storage for sense data returned by the drive-----------*/
139 	u_char sense_data[MAX_PAGE_0_SIZE];	/*
140 						 * additional sense data needed
141 						 * for mode sense/select.
142 						 */
143 	struct buf_queue buf_queue;	/* the queue of pending IO */
144 					/* operations */
145 #if NRND > 0
146 	rndsource_element_t	rnd_source;
147 #endif
148 };
149 
150 #define	ST_INFO_VALID	0x0001
151 #define	ST_BLOCK_SET	0x0002	/* block size, mode set by ioctl      */
152 #define	ST_WRITTEN	0x0004	/* data has been written, EOD needed */
153 #define	ST_FIXEDBLOCKS	0x0008
154 #define	ST_AT_FILEMARK	0x0010
155 #define	ST_EIO_PENDING	0x0020	/* error reporting deferred until next op */
156 #define	ST_NEW_MOUNT	0x0040	/* still need to decide mode             */
157 #define	ST_READONLY	0x0080	/* st_mode_sense says write protected */
158 #define	ST_FM_WRITTEN	0x0100	/*
159 				 * EOF file mark written  -- used with
160 				 * ~ST_WRITTEN to indicate that multiple file
161 				 * marks have been written
162 				 */
163 #define	ST_BLANK_READ	0x0200	/* BLANK CHECK encountered already */
164 #define	ST_2FM_AT_EOD	0x0400	/* write 2 file marks at EOD */
165 #define	ST_MOUNTED	0x0800	/* Device is presently mounted */
166 #define	ST_DONTBUFFER	0x1000	/* Disable buffering/caching */
167 #define	ST_EARLYWARN	0x2000	/* Do (deferred) EOM for variable mode */
168 #define	ST_EOM_PENDING	0x4000	/* EOM reporting deferred until next op */
169 
170 #define	ST_PER_ACTION	(ST_AT_FILEMARK | ST_EIO_PENDING | ST_EOM_PENDING | \
171 			 ST_BLANK_READ)
172 #define	ST_PER_MOUNT	(ST_INFO_VALID | ST_BLOCK_SET | ST_WRITTEN |	\
173 			 ST_FIXEDBLOCKS | ST_READONLY | ST_FM_WRITTEN |	\
174 			 ST_2FM_AT_EOD | ST_PER_ACTION)
175 
176 void	stattach __P((struct device *, struct st_softc *, void *));
177 
178 extern struct cfdriver st_cd;
179