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