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