pre-2.3.4..
[davej-history.git] / drivers / scsi / README.st
blob8537cf9bbf0e0fb22b638adeea1d1600ab46bda4
1 This file contains brief information about the SCSI tape driver.
2 The driver is currently maintained by Kai M{kisara (email
3 Kai.Makisara@metla.fi)
5 Last modified: Sun Apr 18 13:24:43 1999 by makisara@home
8 BASICS
10 The driver is generic, i.e., it does not contain any code tailored
11 to any specific tape drive. The tape parameters can be specified with
12 one of the following three methods:
14 1. Each user can specify the tape parameters he/she wants to use
15 directly with ioctls. This is administratively a very simple and
16 flexible method and applicable to single-user workstations. However,
17 in a multiuser environment the next user finds the tape parameters in
18 state the previous user left them.
20 2. The system manager (root) can define default values for some tape
21 parameters, like block size and density using the MTSETDRVBUFFER ioctl.
22 These parameters can be programmed to come into effect either when a
23 new tape is loaded into the drive or if writing begins at the
24 beginning of the tape. The second method is applicable if the tape
25 drive performs auto-detection of the tape format well (like some
26 QIC-drives). The result is that any tape can be read, writing can be
27 continued using existing format, and the default format is used if
28 the tape is rewritten from the beginning (or a new tape is written
29 for the first time). The first method is applicable if the drive
30 does not perform auto-detection well enough and there is a single
31 "sensible" mode for the device. An example is a DAT drive that is
32 used only in variable block mode (I don't know if this is sensible
33 or not :-).
35 The user can override the parameters defined by the system
36 manager. The changes persist until the defaults again come into
37 effect.
39 3. Up to four modes can be defined and selected using the minor number
40 (bits 5 and 6). Mode 0 corresponds to the defaults discussed
41 above. Additional modes are dormant until they are defined by the
42 system manager (root). When specification of a new mode is started,
43 the configuration of mode 0 is used to provide a starting point for
44 definition of the new mode.
46 Using the modes allows the system manager to give the users choices
47 over some of the buffering parameters not directly accessible to the
48 users (buffered and asynchronous writes). The modes also allow choices
49 between formats in multi-tape operations (the explicitly overridden
50 parameters are reset when a new tape is loaded).
52 If more than one mode is used, all modes should contain definitions
53 for the same set of parameters.
55 Many Unices contain internal tables that associate different modes to
56 supported devices. The Linux SCSI tape driver does not contain such
57 tables (and will not do that in future). Instead of that, a utility
58 program can be made that fetches the inquiry data sent by the device,
59 scans its database, and sets up the modes using the ioctls. Another
60 alternative is to make a small script that uses mt to set the defaults
61 tailored to the system.
63 The driver supports fixed and variable block size (within buffer
64 limits). Both the auto-rewind (minor equals device number) and
65 non-rewind devices (minor is 128 + device number) are implemented.
67 In variable block mode, the byte count in write() determines the size
68 of the physical block on tape. When reading, the drive reads the next
69 tape block and returns to the user the data if the read() byte count
70 is at least the block size. Otherwise the data is truncated.
72 In fixed block mode, the data transfer between the drive and the
73 driver is in multiples of the block size. The write() byte count must
74 be a multiple of the block size. This is not required when reading but
75 may be advisable for portability.
77 Support is provided for changing the tape partition and partitioning
78 of the tape with one or two partitions. By default support for
79 partitioned tape is disabled for each driver and it can be enabled
80 with the ioctl MTSETDRVBUFFER.
82 By default the driver writes one filemark when the device is closed after
83 writing and the last operation has been a write. Two filemarks can be
84 optionally written. In both cases end of data is signified by
85 returning zero bytes for two consecutive reads.
87 The compile options are defined in the file linux/drivers/scsi/st_options.h.
90 BSD AND SYS V SEMANTICS
92 The user can choose between these two behaviours of the tape driver by
93 defining the value of the symbol ST_SYSV. The semantics differ when a
94 file being read is closed. The BSD semantics leaves the tape where it
95 currently is whereas the SYS V semantics moves the tape past the next
96 filemark unless the filemark has just been crossed.
98 The default is BSD semantics.
101 BUFFERING
103 The driver uses tape buffers allocated either at system initialization
104 or at run-time when needed. One buffer is used for each open tape
105 device. The size of the buffers is selectable at compile and/or boot
106 time. The buffers are used to store the data being transferred to/from
107 the SCSI adapter. The following buffering options are selectable at
108 compile time and/or at run time (via ioctl):
110 Buffering of data across write calls in fixed block mode (define
111 ST_BUFFER_WRITES).
113 Asynchronous writing. Writing the buffer contents to the tape is
114 started and the write call returns immediately. The status is checked
115 at the next tape operation.
117 Buffered writes and asynchronous writes may in some rare cases cause
118 problems in multivolume operations if there is not enough space after
119 the early-warning mark to flush the driver buffer.
121 Read ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
122 attempted even if the user does not want to get all of the data at
123 this read command. Should be disabled for those drives that don't like
124 a filemark to truncate a read request or that don't like backspacing.
126 The buffer size is defined (in 1024 byte units) by ST_BUFFER_BLOCKS or
127 at boot time. If this size is not enough, the driver tries to allocate
128 a large enough temporary buffer that is released when the device is
129 closed. Buffer allocation uses chunks of memory having sizes
130 2^n * (page size). Because of this the actual buffer size may be
131 larger than the buffer size specified with ST_BUFFER_BLOCKS.
133 Allocation of the buffers is done at run-time when they are
134 needed. Allocation of the specified number of buffers can be done at
135 initialization if ST_RUNTIME_BUFFERS is defined non-zero. The
136 advantage of run-time allocation is that memory is not wasted for
137 buffers not being used. The disadvantage is that there may not be
138 memory available at the time when a buffer is needed for the first
139 time (once a buffer is allocated, it is not released).
141 The maximum number of buffers allocated at initialization is defined by
142 ST_MAX_BUFFERS. One buffer is allocated for each drive detected when
143 the driver is initialized up to the maximum. The minimum number of
144 allocated buffers is ST_EXTRA_DEVS (in hosts.h). This ensures some
145 functionality also for the drives found after tape driver
146 initialization (a SCSI adapter driver is loaded as a module). The
147 default for ST_EXTRA_DEVS is two. The driver tries to allocate new
148 buffers at run-time if necessary.
150 The threshold for triggering asynchronous write in fixed block mode
151 is defined by ST_WRITE_THRESHOLD. This may be optimized for each
152 use pattern. The default triggers asynchronous write after three
153 default sized writes (10 kB) from tar.
155 Scatter/gather buffers (buffers that consist of chunks non-contiguous
156 in the physical memory) are used if contiguous buffers can't be
157 allocated. To support all SCSI adapters (including those not
158 supporting scatter/gather), buffer allocation is using the following
159 three kinds of chunks:
160 1. The initial segment that is used for all SCSI adapters including
161 those not supporting scatter/gather. The size of this buffer will be
162 (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
163 this size (and it is not larger than the buffer size specified by
164 ST_BUFFER_BLOCKS). If this size is not available, the driver halves
165 the size and tries again until the size of one page. The default
166 settings in st_options.h make the driver to try to allocate all of the
167 buffer as one chunk.
168 2. The scatter/gather segments to fill the specified buffer size are
169 allocated so that as many segments as possible are used but the number
170 of segments does not exceed ST_FIRST_SG.
171 3. The remaining segments between ST_MAX_SG (or the module parameter
172 max_sg_segs) and the number of segments used in phases 1 and 2
173 are used to extend the buffer at run-time if this is necessary. The
174 number of scatter/gather segments allowed for the SCSI adapter is not
175 exceeded if it is smaller than the maximum number of scatter/gather
176 segments specified. If the maximum number allowed for the SCSI adapter
177 is smaller than the number of segments used in phases 1 and 2,
178 extending the buffer will always fail.
181 BOOT TIME CONFIGURATION
183 The buffer size, write threshold, and the maximum number of allocated buffers
184 are configurable at boot time using, e.g., the LILO command line. The option
185 syntax is the following:
187            st=aa[,bb[,cc]]
189 where
190   aa is the buffer size in 1024 byte units
191   bb is the write threshold in 1024 byte units
192   cc is the maximum number of tape buffers to allocate (the number of
193         buffers is bounded also by the number of drives detected)
196 MODULE PARAMETERS
198 The same parameters can be also set when the driver is loaded as a
199 module. The keywords are:
201 buffer_kbs=xxx             the buffer size in kilobytes is set to xxx
202 write_threshold_kbs=xxx    the write threshold in kilobytes set to xxx
203 max_buffers=xxx            the maximum number of tape buffer set to xxx
204 max_sg_segs=xxx            the maximum number of scatter/gather
205                            segments
208 IOCTLS
210 The tape is positioned and the drive parameters are set with ioctls
211 defined in mtio.h The tape control program 'mt' uses these ioctls. Try
212 to find an mt that supports all of the Linux SCSI tape ioctls and
213 opens the device for writing if the tape contents will be modified
214 (look for a package mt-st* from the Linux ftp sites; the GNU mt does
215 not open for writing for, e.g., erase).
217 The supported ioctls are:
219 The following use the structure mtop:
221 MTFSF   Space forward over count filemarks. Tape positioned after filemark.
222 MTFSFM  As above but tape positioned before filemark.
223 MTBSF   Space backward over count filemarks. Tape positioned before
224         filemark.
225 MTBSFM  As above but ape positioned after filemark.
226 MTFSR   Space forward over count records.
227 MTBSR   Space backward over count records.
228 MTFSS   Space forward over count setmarks.
229 MTBSS   Space backward over count setmarks.
230 MTWEOF  Write count filemarks.
231 MTWSM   Write count setmarks.
232 MTREW   Rewind tape.
233 MTOFFL  Set device off line (often rewind plus eject).
234 MTNOP   Do nothing except flush the buffers.
235 MTRETEN Re-tension tape.
236 MTEOM   Space to end of recorded data.
237 MTERASE Erase tape.
238 MTSEEK  Seek to tape block count. Uses Tandberg-compatible seek (QFA)
239         for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
240         block numbers in the status are not valid after a seek.
241 MTSETBLK Set the drive block size. Setting to zero sets the drive into
242         variable block mode (if applicable).
243 MTSETDENSITY Sets the drive density code to arg. See drive
244         documentation for available codes.
245 MTLOCK and MTUNLOCK Explicitly lock/unlock the tape drive door.
246 MTLOAD and MTUNLOAD Explicitly load and unload the tape. If the
247         command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
248         MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
249         drive with the command and it selects the tape slot to use of
250         HP C1553A changer.
251 MTCOMPRESSION Sets compressing or uncompressing drive mode using the
252         SCSI mode page 15. Note that some drives other methods for
253         control of compression. Some drives (like the Exabytes) use
254         density codes for compression control. Some drives use another
255         mode page but this page has not been implemented in the
256         driver. Some drives without compression capability will accept
257         any compression mode without error.
258 MTSETPART Moves the tape to the partition given by the argument at the
259         next tape operation. The block at which the tape is positioned
260         is the block where the tape was previously positioned in the
261         new active partition unless the next tape operation is
262         MTSEEK. In this case the tape is moved directly to the block
263         specified by MTSEEK. MTSETPART is inactive unless
264         MT_ST_CAN_PARTITIONS set.
265 MTMKPART Formats the tape with one partition (argument zero) or two
266         partitions (the argument gives in megabytes the size of
267         partition 1 that is physically the first partition of the
268         tape). The drive has to support partitions with size specified
269         by the initiator. Inactive unless MT_ST_CAN_PARTITIONS set.
270 MTSETDRVBUFFER
271         Is used for several purposes. The command is obtained from count
272         with mask MT_SET_OPTIONS, the low order bits are used as argument.
273         This command is only allowed for the superuser (root). The
274         subcommands are:
275         0
276            The drive buffer option is set to the argument. Zero means
277            no buffering.
278         MT_ST_BOOLEANS
279            Sets the buffering options. The bits are the new states
280            (enabled/disabled) the following options (in the
281            parenthesis is specified whether the option is global or
282            can be specified differently for each mode):
283              MT_ST_BUFFER_WRITES write buffering (mode)
284              MT_ST_ASYNC_WRITES asynchronous writes (mode)
285              MT_ST_READ_AHEAD  read ahead (mode)
286              MT_ST_TWO_FM writing of two filemarks (global)
287              MT_ST_FAST_EOM using the SCSI spacing to EOD (global)
288              MT_ST_AUTO_LOCK automatic locking of the drive door (global)
289              MT_ST_DEF_WRITES the defaults are meant only for writes (mode)
290              MT_ST_CAN_BSR backspacing over more than one records can
291                 be used for repositioning the tape (global)
292              MT_ST_NO_BLKLIMS the driver does not ask the block limits
293                 from the drive (block size can be changed only to
294                 variable) (global)
295              MT_ST_CAN_PARTITIONS enables support for partitioned
296                 tapes (global)
297              MT_ST_SCSI2LOGICAL the logical block number is used in
298                 the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
299                 the device dependent address. It is recommended to set
300                 this flag unless there are tapes using the device
301                 dependent (from the old times) (global)
302              MT_ST_SYSV sets the SYSV sematics (mode)
303              MT_ST_DEBUGGING debugging (global; debugging must be
304                 compiled into the driver)
305         MT_ST_SETBOOLEANS
306         MT_ST_CLEARBOOLEANS
307            Sets or clears the option bits.
308         MT_ST_WRITE_THRESHOLD
309            Sets the write threshold for this device to kilobytes
310            specified by the lowest bits.
311         MT_ST_DEF_BLKSIZE
312            Defines the default block size set automatically. Value
313            0xffffff means that the default is not used any more.
314         MT_ST_DEF_DENSITY
315         MT_ST_DEF_DRVBUFFER
316         MT_ST_DEF_COMPRESSION
317            Used to set or clear the density (8 bits), drive buffer
318            state (3 bits), and compression (single bit). If the value is
319            MT_ST_CLEAR_DEFAULT (0xfffff), the default will not be used
320            any more. Otherwise the lower-most bits of the value contain
321            the new value of the parameter.
322         MT_ST_SET_TIMEOUT
323            Set the normal timeout in seconds for this device. The
324            default is 900 seconds (15 minutes). The timeout should be
325            long enough for the retries done by the device while
326            reading/writing.
327         MT_ST_SET_LONG_TIMEOUT
328            Set the long timeout that is used for operations that are
329            known to take a long time. The default is 14000 seconds
330            (3.9 hours). For erase this value is further multiplied by
331            eight.
333 The following ioctl uses the structure mtpos:
334 MTIOCPOS Reads the current position from the drive. Uses
335         Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
336         command for the SCSI-2 drives.
338 The following ioctl uses the structure mtget to return the status:
339 MTIOCGET Returns some status information.
340         The file number and block number within file are returned. The
341         block is -1 when it can't be determined (e.g., after MTBSF).
342         The drive type is either MTISSCSI1 or MTISSCSI2.
343         The number of recovered errors since the previous status call
344         is stored in the lower word of the field mt_erreg.
345         The current block size and the density code are stored in the field
346         mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
347         MT_ST_DENSITY_SHIFT).
348         The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
349         is set if there is no tape in the drive. GMT_EOD means either
350         end of recorded data or end of tape. GMT_EOT means end of tape.
353 MISCELLANEOUS COMPILE OPTIONS
355 The recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
356 is defined.
358 The maximum number of tape devices is determined by the define
359 ST_MAX_TAPES. If more tapes are detected at driver initialization, the
360 maximum is adjusted accordingly.
362 Immediate return from tape positioning SCSI commands can be enabled by
363 defining ST_NOWAIT. If this is defined, the user should take care that
364 the next tape operation is not started before the previous one has
365 finished. The drives and SCSI adapters should handle this condition
366 gracefully, but some drive/adapter combinations are known to hang the
367 SCSI bus in this case.
369 The MTEOM command is by default implemented as spacing over 32767
370 filemarks. With this method the file number in the status is
371 correct. The user can request using direct spacing to EOD by setting
372 ST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
373 number will be invalid.
375 When using read ahead or buffered writes the position within the file
376 may not be correct after the file is closed (correct position may
377 require backspacing over more than one record). The correct position
378 within file can be obtained if ST_IN_FILE_POS is defined at compile
379 time or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
380 (The driver always backs over a filemark crossed by read ahead if the
381 user does not request data that far.)
384 DEBUGGING HINTS
386 To enable debugging messages, edit st.c and #define DEBUG 1. As seen
387 above, debugging can be switched off with an ioctl if debugging is
388 compiled into the driver. The debugging output is not voluminuous.
390 If the tape seems to hang, I would be very interested to hear where
391 the driver is waiting. With the command 'ps -l' you can see the state
392 of the process using the tape. If the state is D, the process is
393 waiting for something. The field WCHAN tells where the driver is
394 waiting. If you have the current System.map in the correct place (in
395 /boot for the procps I use) or have updated /etc/psdatabase (for kmem
396 ps), ps writes the function name in the WCHAN field. If not, you have
397 to look up the function from System.map.
399 Note also that the timeouts are very long compared to most other
400 drivers. This means that the Linux driver may appear hung although the
401 real reason is that the tape firmware has got confused.