xref: /OK3568_Linux_fs/kernel/Documentation/scsi/st.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun====================
4*4882a593SmuzhiyunThe SCSI Tape Driver
5*4882a593Smuzhiyun====================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThis file contains brief information about the SCSI tape driver.
8*4882a593SmuzhiyunThe driver is currently maintained by Kai Mäkisara (email
9*4882a593SmuzhiyunKai.Makisara@kolumbus.fi)
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunLast modified: Tue Feb  9 21:54:16 2016 by kai.makisara
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunBasics
15*4882a593Smuzhiyun======
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunThe driver is generic, i.e., it does not contain any code tailored
18*4882a593Smuzhiyunto any specific tape drive. The tape parameters can be specified with
19*4882a593Smuzhiyunone of the following three methods:
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun1. Each user can specify the tape parameters he/she wants to use
22*4882a593Smuzhiyundirectly with ioctls. This is administratively a very simple and
23*4882a593Smuzhiyunflexible method and applicable to single-user workstations. However,
24*4882a593Smuzhiyunin a multiuser environment the next user finds the tape parameters in
25*4882a593Smuzhiyunstate the previous user left them.
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun2. The system manager (root) can define default values for some tape
28*4882a593Smuzhiyunparameters, like block size and density using the MTSETDRVBUFFER ioctl.
29*4882a593SmuzhiyunThese parameters can be programmed to come into effect either when a
30*4882a593Smuzhiyunnew tape is loaded into the drive or if writing begins at the
31*4882a593Smuzhiyunbeginning of the tape. The second method is applicable if the tape
32*4882a593Smuzhiyundrive performs auto-detection of the tape format well (like some
33*4882a593SmuzhiyunQIC-drives). The result is that any tape can be read, writing can be
34*4882a593Smuzhiyuncontinued using existing format, and the default format is used if
35*4882a593Smuzhiyunthe tape is rewritten from the beginning (or a new tape is written
36*4882a593Smuzhiyunfor the first time). The first method is applicable if the drive
37*4882a593Smuzhiyundoes not perform auto-detection well enough and there is a single
38*4882a593Smuzhiyun"sensible" mode for the device. An example is a DAT drive that is
39*4882a593Smuzhiyunused only in variable block mode (I don't know if this is sensible
40*4882a593Smuzhiyunor not :-).
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThe user can override the parameters defined by the system
43*4882a593Smuzhiyunmanager. The changes persist until the defaults again come into
44*4882a593Smuzhiyuneffect.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun3. By default, up to four modes can be defined and selected using the minor
47*4882a593Smuzhiyunnumber (bits 5 and 6). The number of modes can be changed by changing
48*4882a593SmuzhiyunST_NBR_MODE_BITS in st.h. Mode 0 corresponds to the defaults discussed
49*4882a593Smuzhiyunabove. Additional modes are dormant until they are defined by the
50*4882a593Smuzhiyunsystem manager (root). When specification of a new mode is started,
51*4882a593Smuzhiyunthe configuration of mode 0 is used to provide a starting point for
52*4882a593Smuzhiyundefinition of the new mode.
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunUsing the modes allows the system manager to give the users choices
55*4882a593Smuzhiyunover some of the buffering parameters not directly accessible to the
56*4882a593Smuzhiyunusers (buffered and asynchronous writes). The modes also allow choices
57*4882a593Smuzhiyunbetween formats in multi-tape operations (the explicitly overridden
58*4882a593Smuzhiyunparameters are reset when a new tape is loaded).
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunIf more than one mode is used, all modes should contain definitions
61*4882a593Smuzhiyunfor the same set of parameters.
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunMany Unices contain internal tables that associate different modes to
64*4882a593Smuzhiyunsupported devices. The Linux SCSI tape driver does not contain such
65*4882a593Smuzhiyuntables (and will not do that in future). Instead of that, a utility
66*4882a593Smuzhiyunprogram can be made that fetches the inquiry data sent by the device,
67*4882a593Smuzhiyunscans its database, and sets up the modes using the ioctls. Another
68*4882a593Smuzhiyunalternative is to make a small script that uses mt to set the defaults
69*4882a593Smuzhiyuntailored to the system.
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunThe driver supports fixed and variable block size (within buffer
72*4882a593Smuzhiyunlimits). Both the auto-rewind (minor equals device number) and
73*4882a593Smuzhiyunnon-rewind devices (minor is 128 + device number) are implemented.
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunIn variable block mode, the byte count in write() determines the size
76*4882a593Smuzhiyunof the physical block on tape. When reading, the drive reads the next
77*4882a593Smuzhiyuntape block and returns to the user the data if the read() byte count
78*4882a593Smuzhiyunis at least the block size. Otherwise, error ENOMEM is returned.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunIn fixed block mode, the data transfer between the drive and the
81*4882a593Smuzhiyundriver is in multiples of the block size. The write() byte count must
82*4882a593Smuzhiyunbe a multiple of the block size. This is not required when reading but
83*4882a593Smuzhiyunmay be advisable for portability.
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunSupport is provided for changing the tape partition and partitioning
86*4882a593Smuzhiyunof the tape with one or two partitions. By default support for
87*4882a593Smuzhiyunpartitioned tape is disabled for each driver and it can be enabled
88*4882a593Smuzhiyunwith the ioctl MTSETDRVBUFFER.
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunBy default the driver writes one filemark when the device is closed after
91*4882a593Smuzhiyunwriting and the last operation has been a write. Two filemarks can be
92*4882a593Smuzhiyunoptionally written. In both cases end of data is signified by
93*4882a593Smuzhiyunreturning zero bytes for two consecutive reads.
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunWriting filemarks without the immediate bit set in the SCSI command block acts
96*4882a593Smuzhiyunas a synchronization point, i.e., all remaining data form the drive buffers is
97*4882a593Smuzhiyunwritten to tape before the command returns. This makes sure that write errors
98*4882a593Smuzhiyunare caught at that point, but this takes time. In some applications, several
99*4882a593Smuzhiyunconsecutive files must be written fast. The MTWEOFI operation can be used to
100*4882a593Smuzhiyunwrite the filemarks without flushing the drive buffer. Writing filemark at
101*4882a593Smuzhiyunclose() is always flushing the drive buffers. However, if the previous
102*4882a593Smuzhiyunoperation is MTWEOFI, close() does not write a filemark. This can be used if
103*4882a593Smuzhiyunthe program wants to close/open the tape device between files and wants to
104*4882a593Smuzhiyunskip waiting.
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunIf rewind, offline, bsf, or seek is done and previous tape operation was
107*4882a593Smuzhiyunwrite, a filemark is written before moving tape.
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunThe compile options are defined in the file linux/drivers/scsi/st_options.h.
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun4. If the open option O_NONBLOCK is used, open succeeds even if the
112*4882a593Smuzhiyundrive is not ready. If O_NONBLOCK is not used, the driver waits for
113*4882a593Smuzhiyunthe drive to become ready. If this does not happen in ST_BLOCK_SECONDS
114*4882a593Smuzhiyunseconds, open fails with the errno value EIO. With O_NONBLOCK the
115*4882a593Smuzhiyundevice can be opened for writing even if there is a write protected
116*4882a593Smuzhiyuntape in the drive (commands trying to write something return error if
117*4882a593Smuzhiyunattempted).
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunMinor Numbers
121*4882a593Smuzhiyun=============
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunThe tape driver currently supports up to 2^17 drives if 4 modes for
124*4882a593Smuzhiyuneach drive are used.
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunThe minor numbers consist of the following bit fields::
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun    dev_upper non-rew mode dev-lower
129*4882a593Smuzhiyun    20 -  8     7    6 5  4      0
130*4882a593Smuzhiyun
131*4882a593SmuzhiyunThe non-rewind bit is always bit 7 (the uppermost bit in the lowermost
132*4882a593Smuzhiyunbyte). The bits defining the mode are below the non-rewind bit. The
133*4882a593Smuzhiyunremaining bits define the tape device number. This numbering is
134*4882a593Smuzhiyunbackward compatible with the numbering used when the minor number was
135*4882a593Smuzhiyunonly 8 bits wide.
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunSysfs Support
139*4882a593Smuzhiyun=============
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunThe driver creates the directory /sys/class/scsi_tape and populates it with
142*4882a593Smuzhiyundirectories corresponding to the existing tape devices. There are autorewind
143*4882a593Smuzhiyunand non-rewind entries for each mode. The names are stxy and nstxy, where x
144*4882a593Smuzhiyunis the tape number and y a character corresponding to the mode (none, l, m,
145*4882a593Smuzhiyuna). For example, the directories for the first tape device are (assuming four
146*4882a593Smuzhiyunmodes): st0  nst0  st0l  nst0l  st0m  nst0m  st0a  nst0a.
147*4882a593Smuzhiyun
148*4882a593SmuzhiyunEach directory contains the entries: default_blksize  default_compression
149*4882a593Smuzhiyundefault_density  defined  dev  device  driver. The file 'defined' contains 1
150*4882a593Smuzhiyunif the mode is defined and zero if not defined. The files 'default_*' contain
151*4882a593Smuzhiyunthe defaults set by the user. The value -1 means the default is not set. The
152*4882a593Smuzhiyunfile 'dev' contains the device numbers corresponding to this device. The links
153*4882a593Smuzhiyun'device' and 'driver' point to the SCSI device and driver entries.
154*4882a593Smuzhiyun
155*4882a593SmuzhiyunEach directory also contains the entry 'options' which shows the currently
156*4882a593Smuzhiyunenabled driver and mode options. The value in the file is a bit mask where the
157*4882a593Smuzhiyunbit definitions are the same as those used with MTSETDRVBUFFER in setting the
158*4882a593Smuzhiyunoptions.
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunA link named 'tape' is made from the SCSI device directory to the class
161*4882a593Smuzhiyundirectory corresponding to the mode 0 auto-rewind device (e.g., st0).
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun
164*4882a593SmuzhiyunSysfs and Statistics for Tape Devices
165*4882a593Smuzhiyun=====================================
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunThe st driver maintains statistics for tape drives inside the sysfs filesystem.
168*4882a593SmuzhiyunThe following method can be used to locate the statistics that are
169*4882a593Smuzhiyunavailable (assuming that sysfs is mounted at /sys):
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun1. Use opendir(3) on the directory /sys/class/scsi_tape
172*4882a593Smuzhiyun2. Use readdir(3) to read the directory contents
173*4882a593Smuzhiyun3. Use regcomp(3)/regexec(3) to match directory entries to the extended
174*4882a593Smuzhiyun   regular expression "^st[0-9]+$"
175*4882a593Smuzhiyun4. Access the statistics from the /sys/class/scsi_tape/<match>/stats
176*4882a593Smuzhiyun   directory (where <match> is a directory entry from /sys/class/scsi_tape
177*4882a593Smuzhiyun   that matched the extended regular expression)
178*4882a593Smuzhiyun
179*4882a593SmuzhiyunThe reason for using this approach is that all the character devices
180*4882a593Smuzhiyunpointing to the same tape drive use the same statistics. That means
181*4882a593Smuzhiyunthat st0 would have the same statistics as nst0.
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunThe directory contains the following statistics files:
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun1.  in_flight
186*4882a593Smuzhiyun      - The number of I/Os currently outstanding to this device.
187*4882a593Smuzhiyun2.  io_ns
188*4882a593Smuzhiyun      - The amount of time spent waiting (in nanoseconds) for all I/O
189*4882a593Smuzhiyun        to complete (including read and write). This includes tape movement
190*4882a593Smuzhiyun        commands such as seeking between file or set marks and implicit tape
191*4882a593Smuzhiyun        movement such as when rewind on close tape devices are used.
192*4882a593Smuzhiyun3.  other_cnt
193*4882a593Smuzhiyun      - The number of I/Os issued to the tape drive other than read or
194*4882a593Smuzhiyun        write commands. The time taken to complete these commands uses the
195*4882a593Smuzhiyun        following calculation io_ms-read_ms-write_ms.
196*4882a593Smuzhiyun4.  read_byte_cnt
197*4882a593Smuzhiyun      - The number of bytes read from the tape drive.
198*4882a593Smuzhiyun5.  read_cnt
199*4882a593Smuzhiyun      - The number of read requests issued to the tape drive.
200*4882a593Smuzhiyun6.  read_ns
201*4882a593Smuzhiyun      - The amount of time (in nanoseconds) spent waiting for read
202*4882a593Smuzhiyun        requests to complete.
203*4882a593Smuzhiyun7.  write_byte_cnt
204*4882a593Smuzhiyun      - The number of bytes written to the tape drive.
205*4882a593Smuzhiyun8.  write_cnt
206*4882a593Smuzhiyun      - The number of write requests issued to the tape drive.
207*4882a593Smuzhiyun9.  write_ns
208*4882a593Smuzhiyun      - The amount of time (in nanoseconds) spent waiting for write
209*4882a593Smuzhiyun        requests to complete.
210*4882a593Smuzhiyun10. resid_cnt
211*4882a593Smuzhiyun      - The number of times during a read or write we found
212*4882a593Smuzhiyun	the residual amount to be non-zero. This should mean that a program
213*4882a593Smuzhiyun	is issuing a read larger thean the block size on tape. For write
214*4882a593Smuzhiyun	not all data made it to tape.
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun.. Note::
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun   The in_flight value is incremented when an I/O starts the I/O
219*4882a593Smuzhiyun   itself is not added to the statistics until it completes.
220*4882a593Smuzhiyun
221*4882a593SmuzhiyunThe total of read_cnt, write_cnt, and other_cnt may not total to the same
222*4882a593Smuzhiyunvalue as iodone_cnt at the device level. The tape statistics only count
223*4882a593SmuzhiyunI/O issued via the st module.
224*4882a593Smuzhiyun
225*4882a593SmuzhiyunWhen read the statistics may not be temporally consistent while I/O is in
226*4882a593Smuzhiyunprogress. The individual values are read and written to atomically however
227*4882a593Smuzhiyunwhen reading them back via sysfs they may be in the process of being
228*4882a593Smuzhiyunupdated when starting an I/O or when it is completed.
229*4882a593Smuzhiyun
230*4882a593SmuzhiyunThe value shown in in_flight is incremented before any statstics are
231*4882a593Smuzhiyunupdated and decremented when an I/O completes after updating statistics.
232*4882a593SmuzhiyunThe value of in_flight is 0 when there are no I/Os outstanding that are
233*4882a593Smuzhiyunissued by the st driver. Tape statistics do not take into account any
234*4882a593SmuzhiyunI/O performed via the sg device.
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunBSD and Sys V Semantics
237*4882a593Smuzhiyun=======================
238*4882a593Smuzhiyun
239*4882a593SmuzhiyunThe user can choose between these two behaviours of the tape driver by
240*4882a593Smuzhiyundefining the value of the symbol ST_SYSV. The semantics differ when a
241*4882a593Smuzhiyunfile being read is closed. The BSD semantics leaves the tape where it
242*4882a593Smuzhiyuncurrently is whereas the SYS V semantics moves the tape past the next
243*4882a593Smuzhiyunfilemark unless the filemark has just been crossed.
244*4882a593Smuzhiyun
245*4882a593SmuzhiyunThe default is BSD semantics.
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun
248*4882a593SmuzhiyunBuffering
249*4882a593Smuzhiyun=========
250*4882a593Smuzhiyun
251*4882a593SmuzhiyunThe driver tries to do transfers directly to/from user space. If this
252*4882a593Smuzhiyunis not possible, a driver buffer allocated at run-time is used. If
253*4882a593Smuzhiyundirect i/o is not possible for the whole transfer, the driver buffer
254*4882a593Smuzhiyunis used (i.e., bounce buffers for individual pages are not
255*4882a593Smuzhiyunused). Direct i/o can be impossible because of several reasons, e.g.:
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun- one or more pages are at addresses not reachable by the HBA
258*4882a593Smuzhiyun- the number of pages in the transfer exceeds the number of
259*4882a593Smuzhiyun  scatter/gather segments permitted by the HBA
260*4882a593Smuzhiyun- one or more pages can't be locked into memory (should not happen in
261*4882a593Smuzhiyun  any reasonable situation)
262*4882a593Smuzhiyun
263*4882a593SmuzhiyunThe size of the driver buffers is always at least one tape block. In fixed
264*4882a593Smuzhiyunblock mode, the minimum buffer size is defined (in 1024 byte units) by
265*4882a593SmuzhiyunST_FIXED_BUFFER_BLOCKS. With small block size this allows buffering of
266*4882a593Smuzhiyunseveral blocks and using one SCSI read or write to transfer all of the
267*4882a593Smuzhiyunblocks. Buffering of data across write calls in fixed block mode is
268*4882a593Smuzhiyunallowed if ST_BUFFER_WRITES is non-zero and direct i/o is not used.
269*4882a593SmuzhiyunBuffer allocation uses chunks of memory having sizes 2^n * (page
270*4882a593Smuzhiyunsize). Because of this the actual buffer size may be larger than the
271*4882a593Smuzhiyunminimum allowable buffer size.
272*4882a593Smuzhiyun
273*4882a593SmuzhiyunNOTE that if direct i/o is used, the small writes are not buffered. This may
274*4882a593Smuzhiyuncause a surprise when moving from 2.4. There small writes (e.g., tar without
275*4882a593Smuzhiyun-b option) may have had good throughput but this is not true any more with
276*4882a593Smuzhiyun2.6. Direct i/o can be turned off to solve this problem but a better solution
277*4882a593Smuzhiyunis to use bigger write() byte counts (e.g., tar -b 64).
278*4882a593Smuzhiyun
279*4882a593SmuzhiyunAsynchronous writing. Writing the buffer contents to the tape is
280*4882a593Smuzhiyunstarted and the write call returns immediately. The status is checked
281*4882a593Smuzhiyunat the next tape operation. Asynchronous writes are not done with
282*4882a593Smuzhiyundirect i/o and not in fixed block mode.
283*4882a593Smuzhiyun
284*4882a593SmuzhiyunBuffered writes and asynchronous writes may in some rare cases cause
285*4882a593Smuzhiyunproblems in multivolume operations if there is not enough space on the
286*4882a593Smuzhiyuntape after the early-warning mark to flush the driver buffer.
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunRead ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
289*4882a593Smuzhiyunattempted even if the user does not want to get all of the data at
290*4882a593Smuzhiyunthis read command. Should be disabled for those drives that don't like
291*4882a593Smuzhiyuna filemark to truncate a read request or that don't like backspacing.
292*4882a593Smuzhiyun
293*4882a593SmuzhiyunScatter/gather buffers (buffers that consist of chunks non-contiguous
294*4882a593Smuzhiyunin the physical memory) are used if contiguous buffers can't be
295*4882a593Smuzhiyunallocated. To support all SCSI adapters (including those not
296*4882a593Smuzhiyunsupporting scatter/gather), buffer allocation is using the following
297*4882a593Smuzhiyunthree kinds of chunks:
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun1. The initial segment that is used for all SCSI adapters including
300*4882a593Smuzhiyun   those not supporting scatter/gather. The size of this buffer will be
301*4882a593Smuzhiyun   (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
302*4882a593Smuzhiyun   this size (and it is not larger than the buffer size specified by
303*4882a593Smuzhiyun   ST_BUFFER_BLOCKS). If this size is not available, the driver halves
304*4882a593Smuzhiyun   the size and tries again until the size of one page. The default
305*4882a593Smuzhiyun   settings in st_options.h make the driver to try to allocate all of the
306*4882a593Smuzhiyun   buffer as one chunk.
307*4882a593Smuzhiyun2. The scatter/gather segments to fill the specified buffer size are
308*4882a593Smuzhiyun   allocated so that as many segments as possible are used but the number
309*4882a593Smuzhiyun   of segments does not exceed ST_FIRST_SG.
310*4882a593Smuzhiyun3. The remaining segments between ST_MAX_SG (or the module parameter
311*4882a593Smuzhiyun   max_sg_segs) and the number of segments used in phases 1 and 2
312*4882a593Smuzhiyun   are used to extend the buffer at run-time if this is necessary. The
313*4882a593Smuzhiyun   number of scatter/gather segments allowed for the SCSI adapter is not
314*4882a593Smuzhiyun   exceeded if it is smaller than the maximum number of scatter/gather
315*4882a593Smuzhiyun   segments specified. If the maximum number allowed for the SCSI adapter
316*4882a593Smuzhiyun   is smaller than the number of segments used in phases 1 and 2,
317*4882a593Smuzhiyun   extending the buffer will always fail.
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun
320*4882a593SmuzhiyunEOM Behaviour When Writing
321*4882a593Smuzhiyun==========================
322*4882a593Smuzhiyun
323*4882a593SmuzhiyunWhen the end of medium early warning is encountered, the current write
324*4882a593Smuzhiyunis finished and the number of bytes is returned. The next write
325*4882a593Smuzhiyunreturns -1 and errno is set to ENOSPC. To enable writing a trailer,
326*4882a593Smuzhiyunthe next write is allowed to proceed and, if successful, the number of
327*4882a593Smuzhiyunbytes is returned. After this, -1 and the number of bytes are
328*4882a593Smuzhiyunalternately returned until the physical end of medium (or some other
329*4882a593Smuzhiyunerror) is encountered.
330*4882a593Smuzhiyun
331*4882a593SmuzhiyunModule Parameters
332*4882a593Smuzhiyun=================
333*4882a593Smuzhiyun
334*4882a593SmuzhiyunThe buffer size, write threshold, and the maximum number of allocated buffers
335*4882a593Smuzhiyunare configurable when the driver is loaded as a module. The keywords are:
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun========================== ===========================================
338*4882a593Smuzhiyunbuffer_kbs=xxx             the buffer size for fixed block mode is set
339*4882a593Smuzhiyun			   to xxx kilobytes
340*4882a593Smuzhiyunwrite_threshold_kbs=xxx    the write threshold in kilobytes set to xxx
341*4882a593Smuzhiyunmax_sg_segs=xxx		   the maximum number of scatter/gather
342*4882a593Smuzhiyun			   segments
343*4882a593Smuzhiyuntry_direct_io=x		   try direct transfer between user buffer and
344*4882a593Smuzhiyun			   tape drive if this is non-zero
345*4882a593Smuzhiyun========================== ===========================================
346*4882a593Smuzhiyun
347*4882a593SmuzhiyunNote that if the buffer size is changed but the write threshold is not
348*4882a593Smuzhiyunset, the write threshold is set to the new buffer size - 2 kB.
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun
351*4882a593SmuzhiyunBoot Time Configuration
352*4882a593Smuzhiyun=======================
353*4882a593Smuzhiyun
354*4882a593SmuzhiyunIf the driver is compiled into the kernel, the same parameters can be
355*4882a593Smuzhiyunalso set using, e.g., the LILO command line. The preferred syntax is
356*4882a593Smuzhiyunto use the same keyword used when loading as module but prepended
357*4882a593Smuzhiyunwith 'st.'. For instance, to set the maximum number of scatter/gather
358*4882a593Smuzhiyunsegments, the parameter 'st.max_sg_segs=xx' should be used (xx is the
359*4882a593Smuzhiyunnumber of scatter/gather segments).
360*4882a593Smuzhiyun
361*4882a593SmuzhiyunFor compatibility, the old syntax from early 2.5 and 2.4 kernel
362*4882a593Smuzhiyunversions is supported. The same keywords can be used as when loading
363*4882a593Smuzhiyunthe driver as module. If several parameters are set, the keyword-value
364*4882a593Smuzhiyunpairs are separated with a comma (no spaces allowed). A colon can be
365*4882a593Smuzhiyunused instead of the equal mark. The definition is prepended by the
366*4882a593Smuzhiyunstring st=. Here is an example::
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun	st=buffer_kbs:64,write_threshold_kbs:60
369*4882a593Smuzhiyun
370*4882a593SmuzhiyunThe following syntax used by the old kernel versions is also supported::
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun           st=aa[,bb[,dd]]
373*4882a593Smuzhiyun
374*4882a593Smuzhiyunwhere:
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun  - aa is the buffer size for fixed block mode in 1024 byte units
377*4882a593Smuzhiyun  - bb is the write threshold in 1024 byte units
378*4882a593Smuzhiyun  - dd is the maximum number of scatter/gather segments
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun
381*4882a593SmuzhiyunIOCTLs
382*4882a593Smuzhiyun======
383*4882a593Smuzhiyun
384*4882a593SmuzhiyunThe tape is positioned and the drive parameters are set with ioctls
385*4882a593Smuzhiyundefined in mtio.h The tape control program 'mt' uses these ioctls. Try
386*4882a593Smuzhiyunto find an mt that supports all of the Linux SCSI tape ioctls and
387*4882a593Smuzhiyunopens the device for writing if the tape contents will be modified
388*4882a593Smuzhiyun(look for a package mt-st* from the Linux ftp sites; the GNU mt does
389*4882a593Smuzhiyunnot open for writing for, e.g., erase).
390*4882a593Smuzhiyun
391*4882a593SmuzhiyunThe supported ioctls are:
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunThe following use the structure mtop:
394*4882a593Smuzhiyun
395*4882a593SmuzhiyunMTFSF
396*4882a593Smuzhiyun	Space forward over count filemarks. Tape positioned after filemark.
397*4882a593SmuzhiyunMTFSFM
398*4882a593Smuzhiyun	As above but tape positioned before filemark.
399*4882a593SmuzhiyunMTBSF
400*4882a593Smuzhiyun	Space backward over count filemarks. Tape positioned before
401*4882a593Smuzhiyun        filemark.
402*4882a593SmuzhiyunMTBSFM
403*4882a593Smuzhiyun	As above but ape positioned after filemark.
404*4882a593SmuzhiyunMTFSR
405*4882a593Smuzhiyun	Space forward over count records.
406*4882a593SmuzhiyunMTBSR
407*4882a593Smuzhiyun	Space backward over count records.
408*4882a593SmuzhiyunMTFSS
409*4882a593Smuzhiyun	Space forward over count setmarks.
410*4882a593SmuzhiyunMTBSS
411*4882a593Smuzhiyun	Space backward over count setmarks.
412*4882a593SmuzhiyunMTWEOF
413*4882a593Smuzhiyun	Write count filemarks.
414*4882a593SmuzhiyunMTWEOFI
415*4882a593Smuzhiyun	Write count filemarks with immediate bit set (i.e., does not
416*4882a593Smuzhiyun	wait until data is on tape)
417*4882a593SmuzhiyunMTWSM
418*4882a593Smuzhiyun	Write count setmarks.
419*4882a593SmuzhiyunMTREW
420*4882a593Smuzhiyun	Rewind tape.
421*4882a593SmuzhiyunMTOFFL
422*4882a593Smuzhiyun	Set device off line (often rewind plus eject).
423*4882a593SmuzhiyunMTNOP
424*4882a593Smuzhiyun	Do nothing except flush the buffers.
425*4882a593SmuzhiyunMTRETEN
426*4882a593Smuzhiyun	Re-tension tape.
427*4882a593SmuzhiyunMTEOM
428*4882a593Smuzhiyun	Space to end of recorded data.
429*4882a593SmuzhiyunMTERASE
430*4882a593Smuzhiyun	Erase tape. If the argument is zero, the short erase command
431*4882a593Smuzhiyun	is used. The long erase command is used with all other values
432*4882a593Smuzhiyun	of the argument.
433*4882a593SmuzhiyunMTSEEK
434*4882a593Smuzhiyun	Seek to tape block count. Uses Tandberg-compatible seek (QFA)
435*4882a593Smuzhiyun        for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
436*4882a593Smuzhiyun	block numbers in the status are not valid after a seek.
437*4882a593SmuzhiyunMTSETBLK
438*4882a593Smuzhiyun	Set the drive block size. Setting to zero sets the drive into
439*4882a593Smuzhiyun        variable block mode (if applicable).
440*4882a593SmuzhiyunMTSETDENSITY
441*4882a593Smuzhiyun	Sets the drive density code to arg. See drive
442*4882a593Smuzhiyun        documentation for available codes.
443*4882a593SmuzhiyunMTLOCK and MTUNLOCK
444*4882a593Smuzhiyun	Explicitly lock/unlock the tape drive door.
445*4882a593SmuzhiyunMTLOAD and MTUNLOAD
446*4882a593Smuzhiyun	Explicitly load and unload the tape. If the
447*4882a593Smuzhiyun	command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
448*4882a593Smuzhiyun	MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
449*4882a593Smuzhiyun	drive with the command and it selects the tape slot to use of
450*4882a593Smuzhiyun	HP C1553A changer.
451*4882a593SmuzhiyunMTCOMPRESSION
452*4882a593Smuzhiyun	Sets compressing or uncompressing drive mode using the
453*4882a593Smuzhiyun	SCSI mode page 15. Note that some drives other methods for
454*4882a593Smuzhiyun	control of compression. Some drives (like the Exabytes) use
455*4882a593Smuzhiyun	density codes for compression control. Some drives use another
456*4882a593Smuzhiyun	mode page but this page has not been implemented in the
457*4882a593Smuzhiyun	driver. Some drives without compression capability will accept
458*4882a593Smuzhiyun	any compression mode without error.
459*4882a593SmuzhiyunMTSETPART
460*4882a593Smuzhiyun	Moves the tape to the partition given by the argument at the
461*4882a593Smuzhiyun	next tape operation. The block at which the tape is positioned
462*4882a593Smuzhiyun	is the block where the tape was previously positioned in the
463*4882a593Smuzhiyun	new active partition unless the next tape operation is
464*4882a593Smuzhiyun	MTSEEK. In this case the tape is moved directly to the block
465*4882a593Smuzhiyun	specified by MTSEEK. MTSETPART is inactive unless
466*4882a593Smuzhiyun	MT_ST_CAN_PARTITIONS set.
467*4882a593SmuzhiyunMTMKPART
468*4882a593Smuzhiyun	Formats the tape with one partition (argument zero) or two
469*4882a593Smuzhiyun	partitions (argument non-zero). If the argument is positive,
470*4882a593Smuzhiyun	it specifies the size of partition 1 in megabytes. For DDS
471*4882a593Smuzhiyun	drives and several early drives this is the physically first
472*4882a593Smuzhiyun	partition of the tape. If the argument is negative, its absolute
473*4882a593Smuzhiyun	value specifies the size of partition 0 in megabytes. This is
474*4882a593Smuzhiyun	the physically first partition of many later drives, like the
475*4882a593Smuzhiyun	LTO drives from LTO-5 upwards. The drive has to support partitions
476*4882a593Smuzhiyun	with size specified by the initiator. Inactive unless
477*4882a593Smuzhiyun	MT_ST_CAN_PARTITIONS set.
478*4882a593SmuzhiyunMTSETDRVBUFFER
479*4882a593Smuzhiyun	Is used for several purposes. The command is obtained from count
480*4882a593Smuzhiyun        with mask MT_SET_OPTIONS, the low order bits are used as argument.
481*4882a593Smuzhiyun	This command is only allowed for the superuser (root). The
482*4882a593Smuzhiyun	subcommands are:
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun	* 0
485*4882a593Smuzhiyun           The drive buffer option is set to the argument. Zero means
486*4882a593Smuzhiyun           no buffering.
487*4882a593Smuzhiyun        * MT_ST_BOOLEANS
488*4882a593Smuzhiyun           Sets the buffering options. The bits are the new states
489*4882a593Smuzhiyun           (enabled/disabled) the following options (in the
490*4882a593Smuzhiyun	   parenthesis is specified whether the option is global or
491*4882a593Smuzhiyun	   can be specified differently for each mode):
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun	     MT_ST_BUFFER_WRITES
494*4882a593Smuzhiyun		write buffering (mode)
495*4882a593Smuzhiyun	     MT_ST_ASYNC_WRITES
496*4882a593Smuzhiyun		asynchronous writes (mode)
497*4882a593Smuzhiyun             MT_ST_READ_AHEAD
498*4882a593Smuzhiyun		read ahead (mode)
499*4882a593Smuzhiyun             MT_ST_TWO_FM
500*4882a593Smuzhiyun		writing of two filemarks (global)
501*4882a593Smuzhiyun	     MT_ST_FAST_EOM
502*4882a593Smuzhiyun		using the SCSI spacing to EOD (global)
503*4882a593Smuzhiyun	     MT_ST_AUTO_LOCK
504*4882a593Smuzhiyun		automatic locking of the drive door (global)
505*4882a593Smuzhiyun             MT_ST_DEF_WRITES
506*4882a593Smuzhiyun		the defaults are meant only for writes (mode)
507*4882a593Smuzhiyun	     MT_ST_CAN_BSR
508*4882a593Smuzhiyun		backspacing over more than one records can
509*4882a593Smuzhiyun		be used for repositioning the tape (global)
510*4882a593Smuzhiyun	     MT_ST_NO_BLKLIMS
511*4882a593Smuzhiyun		the driver does not ask the block limits
512*4882a593Smuzhiyun		from the drive (block size can be changed only to
513*4882a593Smuzhiyun		variable) (global)
514*4882a593Smuzhiyun	     MT_ST_CAN_PARTITIONS
515*4882a593Smuzhiyun		enables support for partitioned
516*4882a593Smuzhiyun		tapes (global)
517*4882a593Smuzhiyun	     MT_ST_SCSI2LOGICAL
518*4882a593Smuzhiyun		the logical block number is used in
519*4882a593Smuzhiyun		the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
520*4882a593Smuzhiyun		the device dependent address. It is recommended to set
521*4882a593Smuzhiyun		this flag unless there are tapes using the device
522*4882a593Smuzhiyun		dependent (from the old times) (global)
523*4882a593Smuzhiyun	     MT_ST_SYSV
524*4882a593Smuzhiyun		sets the SYSV semantics (mode)
525*4882a593Smuzhiyun	     MT_ST_NOWAIT
526*4882a593Smuzhiyun		enables immediate mode (i.e., don't wait for
527*4882a593Smuzhiyun	        the command to finish) for some commands (e.g., rewind)
528*4882a593Smuzhiyun	     MT_ST_NOWAIT_EOF
529*4882a593Smuzhiyun		enables immediate filemark mode (i.e. when
530*4882a593Smuzhiyun	        writing a filemark, don't wait for it to complete). Please
531*4882a593Smuzhiyun		see the BASICS note about MTWEOFI with respect to the
532*4882a593Smuzhiyun		possible dangers of writing immediate filemarks.
533*4882a593Smuzhiyun	     MT_ST_SILI
534*4882a593Smuzhiyun		enables setting the SILI bit in SCSI commands when
535*4882a593Smuzhiyun		reading in variable block mode to enhance performance when
536*4882a593Smuzhiyun		reading blocks shorter than the byte count; set this only
537*4882a593Smuzhiyun		if you are sure that the drive supports SILI and the HBA
538*4882a593Smuzhiyun		correctly returns transfer residuals
539*4882a593Smuzhiyun	     MT_ST_DEBUGGING
540*4882a593Smuzhiyun		debugging (global; debugging must be
541*4882a593Smuzhiyun		compiled into the driver)
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun	* MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS
544*4882a593Smuzhiyun	   Sets or clears the option bits.
545*4882a593Smuzhiyun        * MT_ST_WRITE_THRESHOLD
546*4882a593Smuzhiyun           Sets the write threshold for this device to kilobytes
547*4882a593Smuzhiyun           specified by the lowest bits.
548*4882a593Smuzhiyun	* MT_ST_DEF_BLKSIZE
549*4882a593Smuzhiyun	   Defines the default block size set automatically. Value
550*4882a593Smuzhiyun	   0xffffff means that the default is not used any more.
551*4882a593Smuzhiyun	* MT_ST_DEF_DENSITY, MT_ST_DEF_DRVBUFFER
552*4882a593Smuzhiyun	   Used to set or clear the density (8 bits), and drive buffer
553*4882a593Smuzhiyun	   state (3 bits). If the value is MT_ST_CLEAR_DEFAULT
554*4882a593Smuzhiyun	   (0xfffff) the default will not be used any more. Otherwise
555*4882a593Smuzhiyun	   the lowermost bits of the value contain the new value of
556*4882a593Smuzhiyun	   the parameter.
557*4882a593Smuzhiyun	* MT_ST_DEF_COMPRESSION
558*4882a593Smuzhiyun	   The compression default will not be used if the value of
559*4882a593Smuzhiyun	   the lowermost byte is 0xff. Otherwise the lowermost bit
560*4882a593Smuzhiyun	   contains the new default. If the bits 8-15 are set to a
561*4882a593Smuzhiyun	   non-zero number, and this number is not 0xff, the number is
562*4882a593Smuzhiyun	   used as the compression algorithm. The value
563*4882a593Smuzhiyun	   MT_ST_CLEAR_DEFAULT can be used to clear the compression
564*4882a593Smuzhiyun	   default.
565*4882a593Smuzhiyun	* MT_ST_SET_TIMEOUT
566*4882a593Smuzhiyun	   Set the normal timeout in seconds for this device. The
567*4882a593Smuzhiyun	   default is 900 seconds (15 minutes). The timeout should be
568*4882a593Smuzhiyun	   long enough for the retries done by the device while
569*4882a593Smuzhiyun	   reading/writing.
570*4882a593Smuzhiyun	* MT_ST_SET_LONG_TIMEOUT
571*4882a593Smuzhiyun	   Set the long timeout that is used for operations that are
572*4882a593Smuzhiyun	   known to take a long time. The default is 14000 seconds
573*4882a593Smuzhiyun	   (3.9 hours). For erase this value is further multiplied by
574*4882a593Smuzhiyun	   eight.
575*4882a593Smuzhiyun	* MT_ST_SET_CLN
576*4882a593Smuzhiyun	   Set the cleaning request interpretation parameters using
577*4882a593Smuzhiyun	   the lowest 24 bits of the argument. The driver can set the
578*4882a593Smuzhiyun	   generic status bit GMT_CLN if a cleaning request bit pattern
579*4882a593Smuzhiyun	   is found from the extended sense data. Many drives set one or
580*4882a593Smuzhiyun	   more bits in the extended sense data when the drive needs
581*4882a593Smuzhiyun	   cleaning. The bits are device-dependent. The driver is
582*4882a593Smuzhiyun	   given the number of the sense data byte (the lowest eight
583*4882a593Smuzhiyun	   bits of the argument; must be >= 18 (values 1 - 17
584*4882a593Smuzhiyun	   reserved) and <= the maximum requested sense data sixe),
585*4882a593Smuzhiyun	   a mask to select the relevant bits (the bits 9-16), and the
586*4882a593Smuzhiyun	   bit pattern (bits 17-23). If the bit pattern is zero, one
587*4882a593Smuzhiyun	   or more bits under the mask indicate cleaning request. If
588*4882a593Smuzhiyun	   the pattern is non-zero, the pattern must match the masked
589*4882a593Smuzhiyun	   sense data byte.
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun	   (The cleaning bit is set if the additional sense code and
592*4882a593Smuzhiyun	   qualifier 00h 17h are seen regardless of the setting of
593*4882a593Smuzhiyun	   MT_ST_SET_CLN.)
594*4882a593Smuzhiyun
595*4882a593SmuzhiyunThe following ioctl uses the structure mtpos:
596*4882a593Smuzhiyun
597*4882a593SmuzhiyunMTIOCPOS
598*4882a593Smuzhiyun	Reads the current position from the drive. Uses
599*4882a593Smuzhiyun        Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
600*4882a593Smuzhiyun        command for the SCSI-2 drives.
601*4882a593Smuzhiyun
602*4882a593SmuzhiyunThe following ioctl uses the structure mtget to return the status:
603*4882a593Smuzhiyun
604*4882a593SmuzhiyunMTIOCGET
605*4882a593Smuzhiyun	Returns some status information.
606*4882a593Smuzhiyun        The file number and block number within file are returned. The
607*4882a593Smuzhiyun        block is -1 when it can't be determined (e.g., after MTBSF).
608*4882a593Smuzhiyun        The drive type is either MTISSCSI1 or MTISSCSI2.
609*4882a593Smuzhiyun        The number of recovered errors since the previous status call
610*4882a593Smuzhiyun        is stored in the lower word of the field mt_erreg.
611*4882a593Smuzhiyun        The current block size and the density code are stored in the field
612*4882a593Smuzhiyun        mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
613*4882a593Smuzhiyun        MT_ST_DENSITY_SHIFT).
614*4882a593Smuzhiyun	The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
615*4882a593Smuzhiyun	is set if there is no tape in the drive. GMT_EOD means either
616*4882a593Smuzhiyun	end of recorded data or end of tape. GMT_EOT means end of tape.
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun
619*4882a593SmuzhiyunMiscellaneous Compile Options
620*4882a593Smuzhiyun=============================
621*4882a593Smuzhiyun
622*4882a593SmuzhiyunThe recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
623*4882a593Smuzhiyunis defined.
624*4882a593Smuzhiyun
625*4882a593SmuzhiyunThe maximum number of tape devices is determined by the define
626*4882a593SmuzhiyunST_MAX_TAPES. If more tapes are detected at driver initialization, the
627*4882a593Smuzhiyunmaximum is adjusted accordingly.
628*4882a593Smuzhiyun
629*4882a593SmuzhiyunImmediate return from tape positioning SCSI commands can be enabled by
630*4882a593Smuzhiyundefining ST_NOWAIT. If this is defined, the user should take care that
631*4882a593Smuzhiyunthe next tape operation is not started before the previous one has
632*4882a593Smuzhiyunfinished. The drives and SCSI adapters should handle this condition
633*4882a593Smuzhiyungracefully, but some drive/adapter combinations are known to hang the
634*4882a593SmuzhiyunSCSI bus in this case.
635*4882a593Smuzhiyun
636*4882a593SmuzhiyunThe MTEOM command is by default implemented as spacing over 32767
637*4882a593Smuzhiyunfilemarks. With this method the file number in the status is
638*4882a593Smuzhiyuncorrect. The user can request using direct spacing to EOD by setting
639*4882a593SmuzhiyunST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
640*4882a593Smuzhiyunnumber will be invalid.
641*4882a593Smuzhiyun
642*4882a593SmuzhiyunWhen using read ahead or buffered writes the position within the file
643*4882a593Smuzhiyunmay not be correct after the file is closed (correct position may
644*4882a593Smuzhiyunrequire backspacing over more than one record). The correct position
645*4882a593Smuzhiyunwithin file can be obtained if ST_IN_FILE_POS is defined at compile
646*4882a593Smuzhiyuntime or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
647*4882a593Smuzhiyun(The driver always backs over a filemark crossed by read ahead if the
648*4882a593Smuzhiyunuser does not request data that far.)
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun
651*4882a593SmuzhiyunDebugging Hints
652*4882a593Smuzhiyun===============
653*4882a593Smuzhiyun
654*4882a593SmuzhiyunDebugging code is now compiled in by default but debugging is turned off
655*4882a593Smuzhiyunwith the kernel module parameter debug_flag defaulting to 0.  Debugging
656*4882a593Smuzhiyuncan still be switched on and off with an ioctl.  To enable debug at
657*4882a593Smuzhiyunmodule load time add debug_flag=1 to the module load options, the
658*4882a593Smuzhiyundebugging output is not voluminous. Debugging can also be enabled
659*4882a593Smuzhiyunand disabled by writing a '0' (disable) or '1' (enable) to the sysfs
660*4882a593Smuzhiyunfile /sys/bus/scsi/drivers/st/debug_flag.
661*4882a593Smuzhiyun
662*4882a593SmuzhiyunIf the tape seems to hang, I would be very interested to hear where
663*4882a593Smuzhiyunthe driver is waiting. With the command 'ps -l' you can see the state
664*4882a593Smuzhiyunof the process using the tape. If the state is D, the process is
665*4882a593Smuzhiyunwaiting for something. The field WCHAN tells where the driver is
666*4882a593Smuzhiyunwaiting. If you have the current System.map in the correct place (in
667*4882a593Smuzhiyun/boot for the procps I use) or have updated /etc/psdatabase (for kmem
668*4882a593Smuzhiyunps), ps writes the function name in the WCHAN field. If not, you have
669*4882a593Smuzhiyunto look up the function from System.map.
670*4882a593Smuzhiyun
671*4882a593SmuzhiyunNote also that the timeouts are very long compared to most other
672*4882a593Smuzhiyundrivers. This means that the Linux driver may appear hung although the
673*4882a593Smuzhiyunreal reason is that the tape firmware has got confused.
674