Hopefully get the Kconfig PCI stuff right, finally.
[linux-2.6/linux-mips.git] / Documentation / scsi / st.txt
blobd5a0ac9153bc2575d388b85c979f6934dd0485e9
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@kolumbus.fi)
5 Last modified: Sat Apr 12 20:26:37 2003 by makisara
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, error ENOMEM is returned.
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.
89 4. If the open option O_NONBLOCK is used, open succeeds even if the
90 drive is not ready. If O_NONBLOCK is not used, the driver waits for
91 the drive to become ready. If this does not happen in ST_BLOCK_SECONDS
92 seconds, open fails with the errno value EIO. With O_NONBLOCK the
93 device can be opened for writing even if there is a write protected
94 tape in the drive (commands trying to write something return error if
95 attempted).
98 BSD AND SYS V SEMANTICS
100 The user can choose between these two behaviours of the tape driver by
101 defining the value of the symbol ST_SYSV. The semantics differ when a
102 file being read is closed. The BSD semantics leaves the tape where it
103 currently is whereas the SYS V semantics moves the tape past the next
104 filemark unless the filemark has just been crossed.
106 The default is BSD semantics.
109 BUFFERING
111 The driver tries to do tranfers directly to/from user space. If this
112 is not possible, a driver buffer allocated at run-time is used. If
113 direct i/o is not possible for the whole transfer, the driver buffer
114 is used (i.e., bounce buffers for individual pages are not
115 used). Direct i/o can be impossible because of several reasons, e.g.:
116 - one or more pages are at addresses not reachable by the HBA
117 - the number of pages in the transfer exceeds the number of
118   scatter/gather segments permitted by the HBA
119 - one or more pages can't be locked into memory (should not happen in
120   any reasonable situation)
122 The size of the driver buffers is always at least one tape block. In fixed
123 block mode, the minimum buffer size is defined (in 1024 byte units) by
124 ST_FIXED_BUFFER_BLOCKS. With small block size this allows buffering of
125 several blocks and using one SCSI read or write to transfer all of the
126 blocks. Buffering of data across write calls in fixed block mode is
127 allowed if ST_BUFFER_WRITES is non-zero and direct i/o is not used.
128 Buffer allocation uses chunks of memory having sizes 2^n * (page
129 size). Because of this the actual buffer size may be larger than the
130 minimum allowable buffer size.
132 Asynchronous writing. Writing the buffer contents to the tape is
133 started and the write call returns immediately. The status is checked
134 at the next tape operation. Asynchronous writes are not done with
135 direct i/o and not in fixed block mode.
137 Buffered writes and asynchronous writes may in some rare cases cause
138 problems in multivolume operations if there is not enough space on the
139 tape after the early-warning mark to flush the driver buffer.
141 Read ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
142 attempted even if the user does not want to get all of the data at
143 this read command. Should be disabled for those drives that don't like
144 a filemark to truncate a read request or that don't like backspacing.
146 Scatter/gather buffers (buffers that consist of chunks non-contiguous
147 in the physical memory) are used if contiguous buffers can't be
148 allocated. To support all SCSI adapters (including those not
149 supporting scatter/gather), buffer allocation is using the following
150 three kinds of chunks:
151 1. The initial segment that is used for all SCSI adapters including
152 those not supporting scatter/gather. The size of this buffer will be
153 (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
154 this size (and it is not larger than the buffer size specified by
155 ST_BUFFER_BLOCKS). If this size is not available, the driver halves
156 the size and tries again until the size of one page. The default
157 settings in st_options.h make the driver to try to allocate all of the
158 buffer as one chunk.
159 2. The scatter/gather segments to fill the specified buffer size are
160 allocated so that as many segments as possible are used but the number
161 of segments does not exceed ST_FIRST_SG.
162 3. The remaining segments between ST_MAX_SG (or the module parameter
163 max_sg_segs) and the number of segments used in phases 1 and 2
164 are used to extend the buffer at run-time if this is necessary. The
165 number of scatter/gather segments allowed for the SCSI adapter is not
166 exceeded if it is smaller than the maximum number of scatter/gather
167 segments specified. If the maximum number allowed for the SCSI adapter
168 is smaller than the number of segments used in phases 1 and 2,
169 extending the buffer will always fail.
172 EOM BEHAVIOUR WHEN WRITING
174 When the end of medium early warning is encountered, the current write
175 is finished and the number of bytes is returned. The next write
176 returns -1 and errno is set to ENOSPC. To enable writing a trailer,
177 the next write is allowed to proceed and, if successful, the number of
178 bytes is returned. After this, -1 and the number of bytes are
179 alternately returned until the physical end of medium (or some other
180 error) is encountered.
183 MODULE PARAMETERS
185 The buffer size, write threshold, and the maximum number of allocated buffers
186 are configurable when the driver is loaded as a module. The keywords are:
188 buffer_kbs=xxx             the buffer size for fixed block mode is set
189                            to xxx kilobytes
190 write_threshold_kbs=xxx    the write threshold in kilobytes set to xxx
191 max_sg_segs=xxx            the maximum number of scatter/gather
192                            segments
193 try_direct_io=x            try direct transfer between user buffer and
194                            tape drive if this is non-zero
196 Note that if the buffer size is changed but the write threshold is not
197 set, the write threshold is set to the new buffer size - 2 kB.
200 BOOT TIME CONFIGURATION
202 If the driver is compiled into the kernel, the same parameters can be
203 also set using, e.g., the LILO command line. The preferred syntax is
204 is to use the same keyword used when loading as module but prepended
205 with 'st.'. For instance, to set the maximum number of scatter/gather
206 segments, the parameter 'st.max_sg_segs=xx' should be used (xx is the
207 number of scatter/gather segments).
209 For compatibility, the old syntax from early 2.5 and 2.4 kernel
210 versions is supported. The same keywords can be used as when loading
211 the driver as module. If several parameters are set, the keyword-value
212 pairs are separated with a comma (no spaces allowed). A colon can be
213 used instead of the equal mark. The definition is prepended by the
214 string st=. Here is an example:
216         st=buffer_kbs:64,write_threhold_kbs:60
218 The following syntax used by the old kernel versions is also supported:
220            st=aa[,bb[,dd]]
222 where
223   aa is the buffer size for fixed block mode in 1024 byte units
224   bb is the write threshold in 1024 byte units
225   dd is the maximum number of scatter/gather segments
228 IOCTLS
230 The tape is positioned and the drive parameters are set with ioctls
231 defined in mtio.h The tape control program 'mt' uses these ioctls. Try
232 to find an mt that supports all of the Linux SCSI tape ioctls and
233 opens the device for writing if the tape contents will be modified
234 (look for a package mt-st* from the Linux ftp sites; the GNU mt does
235 not open for writing for, e.g., erase).
237 The supported ioctls are:
239 The following use the structure mtop:
241 MTFSF   Space forward over count filemarks. Tape positioned after filemark.
242 MTFSFM  As above but tape positioned before filemark.
243 MTBSF   Space backward over count filemarks. Tape positioned before
244         filemark.
245 MTBSFM  As above but ape positioned after filemark.
246 MTFSR   Space forward over count records.
247 MTBSR   Space backward over count records.
248 MTFSS   Space forward over count setmarks.
249 MTBSS   Space backward over count setmarks.
250 MTWEOF  Write count filemarks.
251 MTWSM   Write count setmarks.
252 MTREW   Rewind tape.
253 MTOFFL  Set device off line (often rewind plus eject).
254 MTNOP   Do nothing except flush the buffers.
255 MTRETEN Re-tension tape.
256 MTEOM   Space to end of recorded data.
257 MTERASE Erase tape. If the argument is zero, the short erase command
258         is used. The long erase command is used with all other values
259         of the argument.
260 MTSEEK  Seek to tape block count. Uses Tandberg-compatible seek (QFA)
261         for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
262         block numbers in the status are not valid after a seek.
263 MTSETBLK Set the drive block size. Setting to zero sets the drive into
264         variable block mode (if applicable).
265 MTSETDENSITY Sets the drive density code to arg. See drive
266         documentation for available codes.
267 MTLOCK and MTUNLOCK Explicitly lock/unlock the tape drive door.
268 MTLOAD and MTUNLOAD Explicitly load and unload the tape. If the
269         command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
270         MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
271         drive with the command and it selects the tape slot to use of
272         HP C1553A changer.
273 MTCOMPRESSION Sets compressing or uncompressing drive mode using the
274         SCSI mode page 15. Note that some drives other methods for
275         control of compression. Some drives (like the Exabytes) use
276         density codes for compression control. Some drives use another
277         mode page but this page has not been implemented in the
278         driver. Some drives without compression capability will accept
279         any compression mode without error.
280 MTSETPART Moves the tape to the partition given by the argument at the
281         next tape operation. The block at which the tape is positioned
282         is the block where the tape was previously positioned in the
283         new active partition unless the next tape operation is
284         MTSEEK. In this case the tape is moved directly to the block
285         specified by MTSEEK. MTSETPART is inactive unless
286         MT_ST_CAN_PARTITIONS set.
287 MTMKPART Formats the tape with one partition (argument zero) or two
288         partitions (the argument gives in megabytes the size of
289         partition 1 that is physically the first partition of the
290         tape). The drive has to support partitions with size specified
291         by the initiator. Inactive unless MT_ST_CAN_PARTITIONS set.
292 MTSETDRVBUFFER
293         Is used for several purposes. The command is obtained from count
294         with mask MT_SET_OPTIONS, the low order bits are used as argument.
295         This command is only allowed for the superuser (root). The
296         subcommands are:
297         0
298            The drive buffer option is set to the argument. Zero means
299            no buffering.
300         MT_ST_BOOLEANS
301            Sets the buffering options. The bits are the new states
302            (enabled/disabled) the following options (in the
303            parenthesis is specified whether the option is global or
304            can be specified differently for each mode):
305              MT_ST_BUFFER_WRITES write buffering (mode)
306              MT_ST_ASYNC_WRITES asynchronous writes (mode)
307              MT_ST_READ_AHEAD  read ahead (mode)
308              MT_ST_TWO_FM writing of two filemarks (global)
309              MT_ST_FAST_EOM using the SCSI spacing to EOD (global)
310              MT_ST_AUTO_LOCK automatic locking of the drive door (global)
311              MT_ST_DEF_WRITES the defaults are meant only for writes (mode)
312              MT_ST_CAN_BSR backspacing over more than one records can
313                 be used for repositioning the tape (global)
314              MT_ST_NO_BLKLIMS the driver does not ask the block limits
315                 from the drive (block size can be changed only to
316                 variable) (global)
317              MT_ST_CAN_PARTITIONS enables support for partitioned
318                 tapes (global)
319              MT_ST_SCSI2LOGICAL the logical block number is used in
320                 the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
321                 the device dependent address. It is recommended to set
322                 this flag unless there are tapes using the device
323                 dependent (from the old times) (global)
324              MT_ST_SYSV sets the SYSV sematics (mode)
325              MT_ST_NOWAIT enables immediate mode (i.e., don't wait for
326                 the command to finish) for some commands (e.g., rewind)
327              MT_ST_DEBUGGING debugging (global; debugging must be
328                 compiled into the driver)
329         MT_ST_SETBOOLEANS
330         MT_ST_CLEARBOOLEANS
331            Sets or clears the option bits.
332         MT_ST_WRITE_THRESHOLD
333            Sets the write threshold for this device to kilobytes
334            specified by the lowest bits.
335         MT_ST_DEF_BLKSIZE
336            Defines the default block size set automatically. Value
337            0xffffff means that the default is not used any more.
338         MT_ST_DEF_DENSITY
339         MT_ST_DEF_DRVBUFFER
340            Used to set or clear the density (8 bits), and drive buffer
341            state (3 bits). If the value is MT_ST_CLEAR_DEFAULT
342            (0xfffff) the default will not be used any more. Otherwise
343            the lowermost bits of the value contain the new value of
344            the parameter.
345         MT_ST_DEF_COMPRESSION
346            The compression default will not be used if the value of
347            the lowermost byte is 0xff. Otherwise the lowermost bit
348            contains the new default. If the bits 8-15 are set to a
349            non-zero number, and this number is not 0xff, the number is
350            used as the compression algorithm. The value
351            MT_ST_CLEAR_DEFAULT can be used to clear the compression
352            default.
353         MT_ST_SET_TIMEOUT
354            Set the normal timeout in seconds for this device. The
355            default is 900 seconds (15 minutes). The timeout should be
356            long enough for the retries done by the device while
357            reading/writing.
358         MT_ST_SET_LONG_TIMEOUT
359            Set the long timeout that is used for operations that are
360            known to take a long time. The default is 14000 seconds
361            (3.9 hours). For erase this value is further multiplied by
362            eight.
363         MT_ST_SET_CLN
364            Set the cleaning request interpretation parameters using
365            the lowest 24 bits of the argument. The driver can set the
366            generic status bit GMT_CLN if a cleaning request bit pattern
367            is found from the extended sense data. Many drives set one or
368            more bits in the extended sense data when the drive needs
369            cleaning. The bits are device-dependent. The driver is
370            given the number of the sense data byte (the lowest eight
371            bits of the argument; must be >= 18 (values 1 - 17
372            reserved) and <= the maximum requested sense data sixe), 
373            a mask to select the relevant bits (the bits 9-16), and the
374            bit pattern (bits 17-23). If the bit pattern is zero, one
375            or more bits under the mask indicate cleaning request. If
376            the pattern is non-zero, the pattern must match the masked
377            sense data byte.
379            (The cleaning bit is set if the additional sense code and
380            qualifier 00h 17h are seen regardless of the setting of
381            MT_ST_SET_CLN.)
383 The following ioctl uses the structure mtpos:
384 MTIOCPOS Reads the current position from the drive. Uses
385         Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
386         command for the SCSI-2 drives.
388 The following ioctl uses the structure mtget to return the status:
389 MTIOCGET Returns some status information.
390         The file number and block number within file are returned. The
391         block is -1 when it can't be determined (e.g., after MTBSF).
392         The drive type is either MTISSCSI1 or MTISSCSI2.
393         The number of recovered errors since the previous status call
394         is stored in the lower word of the field mt_erreg.
395         The current block size and the density code are stored in the field
396         mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
397         MT_ST_DENSITY_SHIFT).
398         The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
399         is set if there is no tape in the drive. GMT_EOD means either
400         end of recorded data or end of tape. GMT_EOT means end of tape.
403 MISCELLANEOUS COMPILE OPTIONS
405 The recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
406 is defined.
408 The maximum number of tape devices is determined by the define
409 ST_MAX_TAPES. If more tapes are detected at driver initialization, the
410 maximum is adjusted accordingly.
412 Immediate return from tape positioning SCSI commands can be enabled by
413 defining ST_NOWAIT. If this is defined, the user should take care that
414 the next tape operation is not started before the previous one has
415 finished. The drives and SCSI adapters should handle this condition
416 gracefully, but some drive/adapter combinations are known to hang the
417 SCSI bus in this case.
419 The MTEOM command is by default implemented as spacing over 32767
420 filemarks. With this method the file number in the status is
421 correct. The user can request using direct spacing to EOD by setting
422 ST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
423 number will be invalid.
425 When using read ahead or buffered writes the position within the file
426 may not be correct after the file is closed (correct position may
427 require backspacing over more than one record). The correct position
428 within file can be obtained if ST_IN_FILE_POS is defined at compile
429 time or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
430 (The driver always backs over a filemark crossed by read ahead if the
431 user does not request data that far.)
434 DEBUGGING HINTS
436 To enable debugging messages, edit st.c and #define DEBUG 1. As seen
437 above, debugging can be switched off with an ioctl if debugging is
438 compiled into the driver. The debugging output is not voluminuous.
440 If the tape seems to hang, I would be very interested to hear where
441 the driver is waiting. With the command 'ps -l' you can see the state
442 of the process using the tape. If the state is D, the process is
443 waiting for something. The field WCHAN tells where the driver is
444 waiting. If you have the current System.map in the correct place (in
445 /boot for the procps I use) or have updated /etc/psdatabase (for kmem
446 ps), ps writes the function name in the WCHAN field. If not, you have
447 to look up the function from System.map.
449 Note also that the timeouts are very long compared to most other
450 drivers. This means that the Linux driver may appear hung although the
451 real reason is that the tape firmware has got confused.