xref: /linux/Documentation/scsi/st.rst (revision ead5d1f4d877e92c051e1a1ade623d0d30e71619)
1*bf65c846SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
2*bf65c846SMauro Carvalho Chehab
3*bf65c846SMauro Carvalho Chehab====================
4*bf65c846SMauro Carvalho ChehabThe SCSI Tape Driver
5*bf65c846SMauro Carvalho Chehab====================
6*bf65c846SMauro Carvalho Chehab
7*bf65c846SMauro Carvalho ChehabThis file contains brief information about the SCSI tape driver.
8*bf65c846SMauro Carvalho ChehabThe driver is currently maintained by Kai Mäkisara (email
9*bf65c846SMauro Carvalho ChehabKai.Makisara@kolumbus.fi)
10*bf65c846SMauro Carvalho Chehab
11*bf65c846SMauro Carvalho ChehabLast modified: Tue Feb  9 21:54:16 2016 by kai.makisara
12*bf65c846SMauro Carvalho Chehab
13*bf65c846SMauro Carvalho Chehab
14*bf65c846SMauro Carvalho ChehabBasics
15*bf65c846SMauro Carvalho Chehab======
16*bf65c846SMauro Carvalho Chehab
17*bf65c846SMauro Carvalho ChehabThe driver is generic, i.e., it does not contain any code tailored
18*bf65c846SMauro Carvalho Chehabto any specific tape drive. The tape parameters can be specified with
19*bf65c846SMauro Carvalho Chehabone of the following three methods:
20*bf65c846SMauro Carvalho Chehab
21*bf65c846SMauro Carvalho Chehab1. Each user can specify the tape parameters he/she wants to use
22*bf65c846SMauro Carvalho Chehabdirectly with ioctls. This is administratively a very simple and
23*bf65c846SMauro Carvalho Chehabflexible method and applicable to single-user workstations. However,
24*bf65c846SMauro Carvalho Chehabin a multiuser environment the next user finds the tape parameters in
25*bf65c846SMauro Carvalho Chehabstate the previous user left them.
26*bf65c846SMauro Carvalho Chehab
27*bf65c846SMauro Carvalho Chehab2. The system manager (root) can define default values for some tape
28*bf65c846SMauro Carvalho Chehabparameters, like block size and density using the MTSETDRVBUFFER ioctl.
29*bf65c846SMauro Carvalho ChehabThese parameters can be programmed to come into effect either when a
30*bf65c846SMauro Carvalho Chehabnew tape is loaded into the drive or if writing begins at the
31*bf65c846SMauro Carvalho Chehabbeginning of the tape. The second method is applicable if the tape
32*bf65c846SMauro Carvalho Chehabdrive performs auto-detection of the tape format well (like some
33*bf65c846SMauro Carvalho ChehabQIC-drives). The result is that any tape can be read, writing can be
34*bf65c846SMauro Carvalho Chehabcontinued using existing format, and the default format is used if
35*bf65c846SMauro Carvalho Chehabthe tape is rewritten from the beginning (or a new tape is written
36*bf65c846SMauro Carvalho Chehabfor the first time). The first method is applicable if the drive
37*bf65c846SMauro Carvalho Chehabdoes not perform auto-detection well enough and there is a single
38*bf65c846SMauro Carvalho Chehab"sensible" mode for the device. An example is a DAT drive that is
39*bf65c846SMauro Carvalho Chehabused only in variable block mode (I don't know if this is sensible
40*bf65c846SMauro Carvalho Chehabor not :-).
41*bf65c846SMauro Carvalho Chehab
42*bf65c846SMauro Carvalho ChehabThe user can override the parameters defined by the system
43*bf65c846SMauro Carvalho Chehabmanager. The changes persist until the defaults again come into
44*bf65c846SMauro Carvalho Chehabeffect.
45*bf65c846SMauro Carvalho Chehab
46*bf65c846SMauro Carvalho Chehab3. By default, up to four modes can be defined and selected using the minor
47*bf65c846SMauro Carvalho Chehabnumber (bits 5 and 6). The number of modes can be changed by changing
48*bf65c846SMauro Carvalho ChehabST_NBR_MODE_BITS in st.h. Mode 0 corresponds to the defaults discussed
49*bf65c846SMauro Carvalho Chehababove. Additional modes are dormant until they are defined by the
50*bf65c846SMauro Carvalho Chehabsystem manager (root). When specification of a new mode is started,
51*bf65c846SMauro Carvalho Chehabthe configuration of mode 0 is used to provide a starting point for
52*bf65c846SMauro Carvalho Chehabdefinition of the new mode.
53*bf65c846SMauro Carvalho Chehab
54*bf65c846SMauro Carvalho ChehabUsing the modes allows the system manager to give the users choices
55*bf65c846SMauro Carvalho Chehabover some of the buffering parameters not directly accessible to the
56*bf65c846SMauro Carvalho Chehabusers (buffered and asynchronous writes). The modes also allow choices
57*bf65c846SMauro Carvalho Chehabbetween formats in multi-tape operations (the explicitly overridden
58*bf65c846SMauro Carvalho Chehabparameters are reset when a new tape is loaded).
59*bf65c846SMauro Carvalho Chehab
60*bf65c846SMauro Carvalho ChehabIf more than one mode is used, all modes should contain definitions
61*bf65c846SMauro Carvalho Chehabfor the same set of parameters.
62*bf65c846SMauro Carvalho Chehab
63*bf65c846SMauro Carvalho ChehabMany Unices contain internal tables that associate different modes to
64*bf65c846SMauro Carvalho Chehabsupported devices. The Linux SCSI tape driver does not contain such
65*bf65c846SMauro Carvalho Chehabtables (and will not do that in future). Instead of that, a utility
66*bf65c846SMauro Carvalho Chehabprogram can be made that fetches the inquiry data sent by the device,
67*bf65c846SMauro Carvalho Chehabscans its database, and sets up the modes using the ioctls. Another
68*bf65c846SMauro Carvalho Chehabalternative is to make a small script that uses mt to set the defaults
69*bf65c846SMauro Carvalho Chehabtailored to the system.
70*bf65c846SMauro Carvalho Chehab
71*bf65c846SMauro Carvalho ChehabThe driver supports fixed and variable block size (within buffer
72*bf65c846SMauro Carvalho Chehablimits). Both the auto-rewind (minor equals device number) and
73*bf65c846SMauro Carvalho Chehabnon-rewind devices (minor is 128 + device number) are implemented.
74*bf65c846SMauro Carvalho Chehab
75*bf65c846SMauro Carvalho ChehabIn variable block mode, the byte count in write() determines the size
76*bf65c846SMauro Carvalho Chehabof the physical block on tape. When reading, the drive reads the next
77*bf65c846SMauro Carvalho Chehabtape block and returns to the user the data if the read() byte count
78*bf65c846SMauro Carvalho Chehabis at least the block size. Otherwise, error ENOMEM is returned.
79*bf65c846SMauro Carvalho Chehab
80*bf65c846SMauro Carvalho ChehabIn fixed block mode, the data transfer between the drive and the
81*bf65c846SMauro Carvalho Chehabdriver is in multiples of the block size. The write() byte count must
82*bf65c846SMauro Carvalho Chehabbe a multiple of the block size. This is not required when reading but
83*bf65c846SMauro Carvalho Chehabmay be advisable for portability.
84*bf65c846SMauro Carvalho Chehab
85*bf65c846SMauro Carvalho ChehabSupport is provided for changing the tape partition and partitioning
86*bf65c846SMauro Carvalho Chehabof the tape with one or two partitions. By default support for
87*bf65c846SMauro Carvalho Chehabpartitioned tape is disabled for each driver and it can be enabled
88*bf65c846SMauro Carvalho Chehabwith the ioctl MTSETDRVBUFFER.
89*bf65c846SMauro Carvalho Chehab
90*bf65c846SMauro Carvalho ChehabBy default the driver writes one filemark when the device is closed after
91*bf65c846SMauro Carvalho Chehabwriting and the last operation has been a write. Two filemarks can be
92*bf65c846SMauro Carvalho Chehaboptionally written. In both cases end of data is signified by
93*bf65c846SMauro Carvalho Chehabreturning zero bytes for two consecutive reads.
94*bf65c846SMauro Carvalho Chehab
95*bf65c846SMauro Carvalho ChehabWriting filemarks without the immediate bit set in the SCSI command block acts
96*bf65c846SMauro Carvalho Chehabas a synchronization point, i.e., all remaining data form the drive buffers is
97*bf65c846SMauro Carvalho Chehabwritten to tape before the command returns. This makes sure that write errors
98*bf65c846SMauro Carvalho Chehabare caught at that point, but this takes time. In some applications, several
99*bf65c846SMauro Carvalho Chehabconsecutive files must be written fast. The MTWEOFI operation can be used to
100*bf65c846SMauro Carvalho Chehabwrite the filemarks without flushing the drive buffer. Writing filemark at
101*bf65c846SMauro Carvalho Chehabclose() is always flushing the drive buffers. However, if the previous
102*bf65c846SMauro Carvalho Chehaboperation is MTWEOFI, close() does not write a filemark. This can be used if
103*bf65c846SMauro Carvalho Chehabthe program wants to close/open the tape device between files and wants to
104*bf65c846SMauro Carvalho Chehabskip waiting.
105*bf65c846SMauro Carvalho Chehab
106*bf65c846SMauro Carvalho ChehabIf rewind, offline, bsf, or seek is done and previous tape operation was
107*bf65c846SMauro Carvalho Chehabwrite, a filemark is written before moving tape.
108*bf65c846SMauro Carvalho Chehab
109*bf65c846SMauro Carvalho ChehabThe compile options are defined in the file linux/drivers/scsi/st_options.h.
110*bf65c846SMauro Carvalho Chehab
111*bf65c846SMauro Carvalho Chehab4. If the open option O_NONBLOCK is used, open succeeds even if the
112*bf65c846SMauro Carvalho Chehabdrive is not ready. If O_NONBLOCK is not used, the driver waits for
113*bf65c846SMauro Carvalho Chehabthe drive to become ready. If this does not happen in ST_BLOCK_SECONDS
114*bf65c846SMauro Carvalho Chehabseconds, open fails with the errno value EIO. With O_NONBLOCK the
115*bf65c846SMauro Carvalho Chehabdevice can be opened for writing even if there is a write protected
116*bf65c846SMauro Carvalho Chehabtape in the drive (commands trying to write something return error if
117*bf65c846SMauro Carvalho Chehabattempted).
118*bf65c846SMauro Carvalho Chehab
119*bf65c846SMauro Carvalho Chehab
120*bf65c846SMauro Carvalho ChehabMinor Numbers
121*bf65c846SMauro Carvalho Chehab=============
122*bf65c846SMauro Carvalho Chehab
123*bf65c846SMauro Carvalho ChehabThe tape driver currently supports up to 2^17 drives if 4 modes for
124*bf65c846SMauro Carvalho Chehabeach drive are used.
125*bf65c846SMauro Carvalho Chehab
126*bf65c846SMauro Carvalho ChehabThe minor numbers consist of the following bit fields::
127*bf65c846SMauro Carvalho Chehab
128*bf65c846SMauro Carvalho Chehab    dev_upper non-rew mode dev-lower
129*bf65c846SMauro Carvalho Chehab    20 -  8     7    6 5  4      0
130*bf65c846SMauro Carvalho Chehab
131*bf65c846SMauro Carvalho ChehabThe non-rewind bit is always bit 7 (the uppermost bit in the lowermost
132*bf65c846SMauro Carvalho Chehabbyte). The bits defining the mode are below the non-rewind bit. The
133*bf65c846SMauro Carvalho Chehabremaining bits define the tape device number. This numbering is
134*bf65c846SMauro Carvalho Chehabbackward compatible with the numbering used when the minor number was
135*bf65c846SMauro Carvalho Chehabonly 8 bits wide.
136*bf65c846SMauro Carvalho Chehab
137*bf65c846SMauro Carvalho Chehab
138*bf65c846SMauro Carvalho ChehabSysfs Support
139*bf65c846SMauro Carvalho Chehab=============
140*bf65c846SMauro Carvalho Chehab
141*bf65c846SMauro Carvalho ChehabThe driver creates the directory /sys/class/scsi_tape and populates it with
142*bf65c846SMauro Carvalho Chehabdirectories corresponding to the existing tape devices. There are autorewind
143*bf65c846SMauro Carvalho Chehaband non-rewind entries for each mode. The names are stxy and nstxy, where x
144*bf65c846SMauro Carvalho Chehabis the tape number and y a character corresponding to the mode (none, l, m,
145*bf65c846SMauro Carvalho Chehaba). For example, the directories for the first tape device are (assuming four
146*bf65c846SMauro Carvalho Chehabmodes): st0  nst0  st0l  nst0l  st0m  nst0m  st0a  nst0a.
147*bf65c846SMauro Carvalho Chehab
148*bf65c846SMauro Carvalho ChehabEach directory contains the entries: default_blksize  default_compression
149*bf65c846SMauro Carvalho Chehabdefault_density  defined  dev  device  driver. The file 'defined' contains 1
150*bf65c846SMauro Carvalho Chehabif the mode is defined and zero if not defined. The files 'default_*' contain
151*bf65c846SMauro Carvalho Chehabthe defaults set by the user. The value -1 means the default is not set. The
152*bf65c846SMauro Carvalho Chehabfile 'dev' contains the device numbers corresponding to this device. The links
153*bf65c846SMauro Carvalho Chehab'device' and 'driver' point to the SCSI device and driver entries.
154*bf65c846SMauro Carvalho Chehab
155*bf65c846SMauro Carvalho ChehabEach directory also contains the entry 'options' which shows the currently
156*bf65c846SMauro Carvalho Chehabenabled driver and mode options. The value in the file is a bit mask where the
157*bf65c846SMauro Carvalho Chehabbit definitions are the same as those used with MTSETDRVBUFFER in setting the
158*bf65c846SMauro Carvalho Chehaboptions.
159*bf65c846SMauro Carvalho Chehab
160*bf65c846SMauro Carvalho ChehabA link named 'tape' is made from the SCSI device directory to the class
161*bf65c846SMauro Carvalho Chehabdirectory corresponding to the mode 0 auto-rewind device (e.g., st0).
162*bf65c846SMauro Carvalho Chehab
163*bf65c846SMauro Carvalho Chehab
164*bf65c846SMauro Carvalho ChehabSysfs and Statistics for Tape Devices
165*bf65c846SMauro Carvalho Chehab=====================================
166*bf65c846SMauro Carvalho Chehab
167*bf65c846SMauro Carvalho ChehabThe st driver maintains statistics for tape drives inside the sysfs filesystem.
168*bf65c846SMauro Carvalho ChehabThe following method can be used to locate the statistics that are
169*bf65c846SMauro Carvalho Chehabavailable (assuming that sysfs is mounted at /sys):
170*bf65c846SMauro Carvalho Chehab
171*bf65c846SMauro Carvalho Chehab1. Use opendir(3) on the directory /sys/class/scsi_tape
172*bf65c846SMauro Carvalho Chehab2. Use readdir(3) to read the directory contents
173*bf65c846SMauro Carvalho Chehab3. Use regcomp(3)/regexec(3) to match directory entries to the extended
174*bf65c846SMauro Carvalho Chehab   regular expression "^st[0-9]+$"
175*bf65c846SMauro Carvalho Chehab4. Access the statistics from the /sys/class/scsi_tape/<match>/stats
176*bf65c846SMauro Carvalho Chehab   directory (where <match> is a directory entry from /sys/class/scsi_tape
177*bf65c846SMauro Carvalho Chehab   that matched the extended regular expression)
178*bf65c846SMauro Carvalho Chehab
179*bf65c846SMauro Carvalho ChehabThe reason for using this approach is that all the character devices
180*bf65c846SMauro Carvalho Chehabpointing to the same tape drive use the same statistics. That means
181*bf65c846SMauro Carvalho Chehabthat st0 would have the same statistics as nst0.
182*bf65c846SMauro Carvalho Chehab
183*bf65c846SMauro Carvalho ChehabThe directory contains the following statistics files:
184*bf65c846SMauro Carvalho Chehab
185*bf65c846SMauro Carvalho Chehab1.  in_flight
186*bf65c846SMauro Carvalho Chehab      - The number of I/Os currently outstanding to this device.
187*bf65c846SMauro Carvalho Chehab2.  io_ns
188*bf65c846SMauro Carvalho Chehab      - The amount of time spent waiting (in nanoseconds) for all I/O
189*bf65c846SMauro Carvalho Chehab        to complete (including read and write). This includes tape movement
190*bf65c846SMauro Carvalho Chehab        commands such as seeking between file or set marks and implicit tape
191*bf65c846SMauro Carvalho Chehab        movement such as when rewind on close tape devices are used.
192*bf65c846SMauro Carvalho Chehab3.  other_cnt
193*bf65c846SMauro Carvalho Chehab      - The number of I/Os issued to the tape drive other than read or
194*bf65c846SMauro Carvalho Chehab        write commands. The time taken to complete these commands uses the
195*bf65c846SMauro Carvalho Chehab        following calculation io_ms-read_ms-write_ms.
196*bf65c846SMauro Carvalho Chehab4.  read_byte_cnt
197*bf65c846SMauro Carvalho Chehab      - The number of bytes read from the tape drive.
198*bf65c846SMauro Carvalho Chehab5.  read_cnt
199*bf65c846SMauro Carvalho Chehab      - The number of read requests issued to the tape drive.
200*bf65c846SMauro Carvalho Chehab6.  read_ns
201*bf65c846SMauro Carvalho Chehab      - The amount of time (in nanoseconds) spent waiting for read
202*bf65c846SMauro Carvalho Chehab        requests to complete.
203*bf65c846SMauro Carvalho Chehab7.  write_byte_cnt
204*bf65c846SMauro Carvalho Chehab      - The number of bytes written to the tape drive.
205*bf65c846SMauro Carvalho Chehab8.  write_cnt
206*bf65c846SMauro Carvalho Chehab      - The number of write requests issued to the tape drive.
207*bf65c846SMauro Carvalho Chehab9.  write_ns
208*bf65c846SMauro Carvalho Chehab      - The amount of time (in nanoseconds) spent waiting for write
209*bf65c846SMauro Carvalho Chehab        requests to complete.
210*bf65c846SMauro Carvalho Chehab10. resid_cnt
211*bf65c846SMauro Carvalho Chehab      - The number of times during a read or write we found
212*bf65c846SMauro Carvalho Chehab	the residual amount to be non-zero. This should mean that a program
213*bf65c846SMauro Carvalho Chehab	is issuing a read larger thean the block size on tape. For write
214*bf65c846SMauro Carvalho Chehab	not all data made it to tape.
215*bf65c846SMauro Carvalho Chehab
216*bf65c846SMauro Carvalho Chehab.. Note::
217*bf65c846SMauro Carvalho Chehab
218*bf65c846SMauro Carvalho Chehab   The in_flight value is incremented when an I/O starts the I/O
219*bf65c846SMauro Carvalho Chehab   itself is not added to the statistics until it completes.
220*bf65c846SMauro Carvalho Chehab
221*bf65c846SMauro Carvalho ChehabThe total of read_cnt, write_cnt, and other_cnt may not total to the same
222*bf65c846SMauro Carvalho Chehabvalue as iodone_cnt at the device level. The tape statistics only count
223*bf65c846SMauro Carvalho ChehabI/O issued via the st module.
224*bf65c846SMauro Carvalho Chehab
225*bf65c846SMauro Carvalho ChehabWhen read the statistics may not be temporally consistent while I/O is in
226*bf65c846SMauro Carvalho Chehabprogress. The individual values are read and written to atomically however
227*bf65c846SMauro Carvalho Chehabwhen reading them back via sysfs they may be in the process of being
228*bf65c846SMauro Carvalho Chehabupdated when starting an I/O or when it is completed.
229*bf65c846SMauro Carvalho Chehab
230*bf65c846SMauro Carvalho ChehabThe value shown in in_flight is incremented before any statstics are
231*bf65c846SMauro Carvalho Chehabupdated and decremented when an I/O completes after updating statistics.
232*bf65c846SMauro Carvalho ChehabThe value of in_flight is 0 when there are no I/Os outstanding that are
233*bf65c846SMauro Carvalho Chehabissued by the st driver. Tape statistics do not take into account any
234*bf65c846SMauro Carvalho ChehabI/O performed via the sg device.
235*bf65c846SMauro Carvalho Chehab
236*bf65c846SMauro Carvalho ChehabBSD and Sys V Semantics
237*bf65c846SMauro Carvalho Chehab=======================
238*bf65c846SMauro Carvalho Chehab
239*bf65c846SMauro Carvalho ChehabThe user can choose between these two behaviours of the tape driver by
240*bf65c846SMauro Carvalho Chehabdefining the value of the symbol ST_SYSV. The semantics differ when a
241*bf65c846SMauro Carvalho Chehabfile being read is closed. The BSD semantics leaves the tape where it
242*bf65c846SMauro Carvalho Chehabcurrently is whereas the SYS V semantics moves the tape past the next
243*bf65c846SMauro Carvalho Chehabfilemark unless the filemark has just been crossed.
244*bf65c846SMauro Carvalho Chehab
245*bf65c846SMauro Carvalho ChehabThe default is BSD semantics.
246*bf65c846SMauro Carvalho Chehab
247*bf65c846SMauro Carvalho Chehab
248*bf65c846SMauro Carvalho ChehabBuffering
249*bf65c846SMauro Carvalho Chehab=========
250*bf65c846SMauro Carvalho Chehab
251*bf65c846SMauro Carvalho ChehabThe driver tries to do transfers directly to/from user space. If this
252*bf65c846SMauro Carvalho Chehabis not possible, a driver buffer allocated at run-time is used. If
253*bf65c846SMauro Carvalho Chehabdirect i/o is not possible for the whole transfer, the driver buffer
254*bf65c846SMauro Carvalho Chehabis used (i.e., bounce buffers for individual pages are not
255*bf65c846SMauro Carvalho Chehabused). Direct i/o can be impossible because of several reasons, e.g.:
256*bf65c846SMauro Carvalho Chehab
257*bf65c846SMauro Carvalho Chehab- one or more pages are at addresses not reachable by the HBA
258*bf65c846SMauro Carvalho Chehab- the number of pages in the transfer exceeds the number of
259*bf65c846SMauro Carvalho Chehab  scatter/gather segments permitted by the HBA
260*bf65c846SMauro Carvalho Chehab- one or more pages can't be locked into memory (should not happen in
261*bf65c846SMauro Carvalho Chehab  any reasonable situation)
262*bf65c846SMauro Carvalho Chehab
263*bf65c846SMauro Carvalho ChehabThe size of the driver buffers is always at least one tape block. In fixed
264*bf65c846SMauro Carvalho Chehabblock mode, the minimum buffer size is defined (in 1024 byte units) by
265*bf65c846SMauro Carvalho ChehabST_FIXED_BUFFER_BLOCKS. With small block size this allows buffering of
266*bf65c846SMauro Carvalho Chehabseveral blocks and using one SCSI read or write to transfer all of the
267*bf65c846SMauro Carvalho Chehabblocks. Buffering of data across write calls in fixed block mode is
268*bf65c846SMauro Carvalho Chehaballowed if ST_BUFFER_WRITES is non-zero and direct i/o is not used.
269*bf65c846SMauro Carvalho ChehabBuffer allocation uses chunks of memory having sizes 2^n * (page
270*bf65c846SMauro Carvalho Chehabsize). Because of this the actual buffer size may be larger than the
271*bf65c846SMauro Carvalho Chehabminimum allowable buffer size.
272*bf65c846SMauro Carvalho Chehab
273*bf65c846SMauro Carvalho ChehabNOTE that if direct i/o is used, the small writes are not buffered. This may
274*bf65c846SMauro Carvalho Chehabcause a surprise when moving from 2.4. There small writes (e.g., tar without
275*bf65c846SMauro Carvalho Chehab-b option) may have had good throughput but this is not true any more with
276*bf65c846SMauro Carvalho Chehab2.6. Direct i/o can be turned off to solve this problem but a better solution
277*bf65c846SMauro Carvalho Chehabis to use bigger write() byte counts (e.g., tar -b 64).
278*bf65c846SMauro Carvalho Chehab
279*bf65c846SMauro Carvalho ChehabAsynchronous writing. Writing the buffer contents to the tape is
280*bf65c846SMauro Carvalho Chehabstarted and the write call returns immediately. The status is checked
281*bf65c846SMauro Carvalho Chehabat the next tape operation. Asynchronous writes are not done with
282*bf65c846SMauro Carvalho Chehabdirect i/o and not in fixed block mode.
283*bf65c846SMauro Carvalho Chehab
284*bf65c846SMauro Carvalho ChehabBuffered writes and asynchronous writes may in some rare cases cause
285*bf65c846SMauro Carvalho Chehabproblems in multivolume operations if there is not enough space on the
286*bf65c846SMauro Carvalho Chehabtape after the early-warning mark to flush the driver buffer.
287*bf65c846SMauro Carvalho Chehab
288*bf65c846SMauro Carvalho ChehabRead ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
289*bf65c846SMauro Carvalho Chehabattempted even if the user does not want to get all of the data at
290*bf65c846SMauro Carvalho Chehabthis read command. Should be disabled for those drives that don't like
291*bf65c846SMauro Carvalho Chehaba filemark to truncate a read request or that don't like backspacing.
292*bf65c846SMauro Carvalho Chehab
293*bf65c846SMauro Carvalho ChehabScatter/gather buffers (buffers that consist of chunks non-contiguous
294*bf65c846SMauro Carvalho Chehabin the physical memory) are used if contiguous buffers can't be
295*bf65c846SMauro Carvalho Chehaballocated. To support all SCSI adapters (including those not
296*bf65c846SMauro Carvalho Chehabsupporting scatter/gather), buffer allocation is using the following
297*bf65c846SMauro Carvalho Chehabthree kinds of chunks:
298*bf65c846SMauro Carvalho Chehab
299*bf65c846SMauro Carvalho Chehab1. The initial segment that is used for all SCSI adapters including
300*bf65c846SMauro Carvalho Chehab   those not supporting scatter/gather. The size of this buffer will be
301*bf65c846SMauro Carvalho Chehab   (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
302*bf65c846SMauro Carvalho Chehab   this size (and it is not larger than the buffer size specified by
303*bf65c846SMauro Carvalho Chehab   ST_BUFFER_BLOCKS). If this size is not available, the driver halves
304*bf65c846SMauro Carvalho Chehab   the size and tries again until the size of one page. The default
305*bf65c846SMauro Carvalho Chehab   settings in st_options.h make the driver to try to allocate all of the
306*bf65c846SMauro Carvalho Chehab   buffer as one chunk.
307*bf65c846SMauro Carvalho Chehab2. The scatter/gather segments to fill the specified buffer size are
308*bf65c846SMauro Carvalho Chehab   allocated so that as many segments as possible are used but the number
309*bf65c846SMauro Carvalho Chehab   of segments does not exceed ST_FIRST_SG.
310*bf65c846SMauro Carvalho Chehab3. The remaining segments between ST_MAX_SG (or the module parameter
311*bf65c846SMauro Carvalho Chehab   max_sg_segs) and the number of segments used in phases 1 and 2
312*bf65c846SMauro Carvalho Chehab   are used to extend the buffer at run-time if this is necessary. The
313*bf65c846SMauro Carvalho Chehab   number of scatter/gather segments allowed for the SCSI adapter is not
314*bf65c846SMauro Carvalho Chehab   exceeded if it is smaller than the maximum number of scatter/gather
315*bf65c846SMauro Carvalho Chehab   segments specified. If the maximum number allowed for the SCSI adapter
316*bf65c846SMauro Carvalho Chehab   is smaller than the number of segments used in phases 1 and 2,
317*bf65c846SMauro Carvalho Chehab   extending the buffer will always fail.
318*bf65c846SMauro Carvalho Chehab
319*bf65c846SMauro Carvalho Chehab
320*bf65c846SMauro Carvalho ChehabEOM Behaviour When Writing
321*bf65c846SMauro Carvalho Chehab==========================
322*bf65c846SMauro Carvalho Chehab
323*bf65c846SMauro Carvalho ChehabWhen the end of medium early warning is encountered, the current write
324*bf65c846SMauro Carvalho Chehabis finished and the number of bytes is returned. The next write
325*bf65c846SMauro Carvalho Chehabreturns -1 and errno is set to ENOSPC. To enable writing a trailer,
326*bf65c846SMauro Carvalho Chehabthe next write is allowed to proceed and, if successful, the number of
327*bf65c846SMauro Carvalho Chehabbytes is returned. After this, -1 and the number of bytes are
328*bf65c846SMauro Carvalho Chehabalternately returned until the physical end of medium (or some other
329*bf65c846SMauro Carvalho Chehaberror) is encountered.
330*bf65c846SMauro Carvalho Chehab
331*bf65c846SMauro Carvalho ChehabModule Parameters
332*bf65c846SMauro Carvalho Chehab=================
333*bf65c846SMauro Carvalho Chehab
334*bf65c846SMauro Carvalho ChehabThe buffer size, write threshold, and the maximum number of allocated buffers
335*bf65c846SMauro Carvalho Chehabare configurable when the driver is loaded as a module. The keywords are:
336*bf65c846SMauro Carvalho Chehab
337*bf65c846SMauro Carvalho Chehab========================== ===========================================
338*bf65c846SMauro Carvalho Chehabbuffer_kbs=xxx             the buffer size for fixed block mode is set
339*bf65c846SMauro Carvalho Chehab			   to xxx kilobytes
340*bf65c846SMauro Carvalho Chehabwrite_threshold_kbs=xxx    the write threshold in kilobytes set to xxx
341*bf65c846SMauro Carvalho Chehabmax_sg_segs=xxx		   the maximum number of scatter/gather
342*bf65c846SMauro Carvalho Chehab			   segments
343*bf65c846SMauro Carvalho Chehabtry_direct_io=x		   try direct transfer between user buffer and
344*bf65c846SMauro Carvalho Chehab			   tape drive if this is non-zero
345*bf65c846SMauro Carvalho Chehab========================== ===========================================
346*bf65c846SMauro Carvalho Chehab
347*bf65c846SMauro Carvalho ChehabNote that if the buffer size is changed but the write threshold is not
348*bf65c846SMauro Carvalho Chehabset, the write threshold is set to the new buffer size - 2 kB.
349*bf65c846SMauro Carvalho Chehab
350*bf65c846SMauro Carvalho Chehab
351*bf65c846SMauro Carvalho ChehabBoot Time Configuration
352*bf65c846SMauro Carvalho Chehab=======================
353*bf65c846SMauro Carvalho Chehab
354*bf65c846SMauro Carvalho ChehabIf the driver is compiled into the kernel, the same parameters can be
355*bf65c846SMauro Carvalho Chehabalso set using, e.g., the LILO command line. The preferred syntax is
356*bf65c846SMauro Carvalho Chehabto use the same keyword used when loading as module but prepended
357*bf65c846SMauro Carvalho Chehabwith 'st.'. For instance, to set the maximum number of scatter/gather
358*bf65c846SMauro Carvalho Chehabsegments, the parameter 'st.max_sg_segs=xx' should be used (xx is the
359*bf65c846SMauro Carvalho Chehabnumber of scatter/gather segments).
360*bf65c846SMauro Carvalho Chehab
361*bf65c846SMauro Carvalho ChehabFor compatibility, the old syntax from early 2.5 and 2.4 kernel
362*bf65c846SMauro Carvalho Chehabversions is supported. The same keywords can be used as when loading
363*bf65c846SMauro Carvalho Chehabthe driver as module. If several parameters are set, the keyword-value
364*bf65c846SMauro Carvalho Chehabpairs are separated with a comma (no spaces allowed). A colon can be
365*bf65c846SMauro Carvalho Chehabused instead of the equal mark. The definition is prepended by the
366*bf65c846SMauro Carvalho Chehabstring st=. Here is an example::
367*bf65c846SMauro Carvalho Chehab
368*bf65c846SMauro Carvalho Chehab	st=buffer_kbs:64,write_threshold_kbs:60
369*bf65c846SMauro Carvalho Chehab
370*bf65c846SMauro Carvalho ChehabThe following syntax used by the old kernel versions is also supported::
371*bf65c846SMauro Carvalho Chehab
372*bf65c846SMauro Carvalho Chehab           st=aa[,bb[,dd]]
373*bf65c846SMauro Carvalho Chehab
374*bf65c846SMauro Carvalho Chehabwhere:
375*bf65c846SMauro Carvalho Chehab
376*bf65c846SMauro Carvalho Chehab  - aa is the buffer size for fixed block mode in 1024 byte units
377*bf65c846SMauro Carvalho Chehab  - bb is the write threshold in 1024 byte units
378*bf65c846SMauro Carvalho Chehab  - dd is the maximum number of scatter/gather segments
379*bf65c846SMauro Carvalho Chehab
380*bf65c846SMauro Carvalho Chehab
381*bf65c846SMauro Carvalho ChehabIOCTLs
382*bf65c846SMauro Carvalho Chehab======
383*bf65c846SMauro Carvalho Chehab
384*bf65c846SMauro Carvalho ChehabThe tape is positioned and the drive parameters are set with ioctls
385*bf65c846SMauro Carvalho Chehabdefined in mtio.h The tape control program 'mt' uses these ioctls. Try
386*bf65c846SMauro Carvalho Chehabto find an mt that supports all of the Linux SCSI tape ioctls and
387*bf65c846SMauro Carvalho Chehabopens the device for writing if the tape contents will be modified
388*bf65c846SMauro Carvalho Chehab(look for a package mt-st* from the Linux ftp sites; the GNU mt does
389*bf65c846SMauro Carvalho Chehabnot open for writing for, e.g., erase).
390*bf65c846SMauro Carvalho Chehab
391*bf65c846SMauro Carvalho ChehabThe supported ioctls are:
392*bf65c846SMauro Carvalho Chehab
393*bf65c846SMauro Carvalho ChehabThe following use the structure mtop:
394*bf65c846SMauro Carvalho Chehab
395*bf65c846SMauro Carvalho ChehabMTFSF
396*bf65c846SMauro Carvalho Chehab	Space forward over count filemarks. Tape positioned after filemark.
397*bf65c846SMauro Carvalho ChehabMTFSFM
398*bf65c846SMauro Carvalho Chehab	As above but tape positioned before filemark.
399*bf65c846SMauro Carvalho ChehabMTBSF
400*bf65c846SMauro Carvalho Chehab	Space backward over count filemarks. Tape positioned before
401*bf65c846SMauro Carvalho Chehab        filemark.
402*bf65c846SMauro Carvalho ChehabMTBSFM
403*bf65c846SMauro Carvalho Chehab	As above but ape positioned after filemark.
404*bf65c846SMauro Carvalho ChehabMTFSR
405*bf65c846SMauro Carvalho Chehab	Space forward over count records.
406*bf65c846SMauro Carvalho ChehabMTBSR
407*bf65c846SMauro Carvalho Chehab	Space backward over count records.
408*bf65c846SMauro Carvalho ChehabMTFSS
409*bf65c846SMauro Carvalho Chehab	Space forward over count setmarks.
410*bf65c846SMauro Carvalho ChehabMTBSS
411*bf65c846SMauro Carvalho Chehab	Space backward over count setmarks.
412*bf65c846SMauro Carvalho ChehabMTWEOF
413*bf65c846SMauro Carvalho Chehab	Write count filemarks.
414*bf65c846SMauro Carvalho ChehabMTWEOFI
415*bf65c846SMauro Carvalho Chehab	Write count filemarks with immediate bit set (i.e., does not
416*bf65c846SMauro Carvalho Chehab	wait until data is on tape)
417*bf65c846SMauro Carvalho ChehabMTWSM
418*bf65c846SMauro Carvalho Chehab	Write count setmarks.
419*bf65c846SMauro Carvalho ChehabMTREW
420*bf65c846SMauro Carvalho Chehab	Rewind tape.
421*bf65c846SMauro Carvalho ChehabMTOFFL
422*bf65c846SMauro Carvalho Chehab	Set device off line (often rewind plus eject).
423*bf65c846SMauro Carvalho ChehabMTNOP
424*bf65c846SMauro Carvalho Chehab	Do nothing except flush the buffers.
425*bf65c846SMauro Carvalho ChehabMTRETEN
426*bf65c846SMauro Carvalho Chehab	Re-tension tape.
427*bf65c846SMauro Carvalho ChehabMTEOM
428*bf65c846SMauro Carvalho Chehab	Space to end of recorded data.
429*bf65c846SMauro Carvalho ChehabMTERASE
430*bf65c846SMauro Carvalho Chehab	Erase tape. If the argument is zero, the short erase command
431*bf65c846SMauro Carvalho Chehab	is used. The long erase command is used with all other values
432*bf65c846SMauro Carvalho Chehab	of the argument.
433*bf65c846SMauro Carvalho ChehabMTSEEK
434*bf65c846SMauro Carvalho Chehab	Seek to tape block count. Uses Tandberg-compatible seek (QFA)
435*bf65c846SMauro Carvalho Chehab        for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
436*bf65c846SMauro Carvalho Chehab	block numbers in the status are not valid after a seek.
437*bf65c846SMauro Carvalho ChehabMTSETBLK
438*bf65c846SMauro Carvalho Chehab	Set the drive block size. Setting to zero sets the drive into
439*bf65c846SMauro Carvalho Chehab        variable block mode (if applicable).
440*bf65c846SMauro Carvalho ChehabMTSETDENSITY
441*bf65c846SMauro Carvalho Chehab	Sets the drive density code to arg. See drive
442*bf65c846SMauro Carvalho Chehab        documentation for available codes.
443*bf65c846SMauro Carvalho ChehabMTLOCK and MTUNLOCK
444*bf65c846SMauro Carvalho Chehab	Explicitly lock/unlock the tape drive door.
445*bf65c846SMauro Carvalho ChehabMTLOAD and MTUNLOAD
446*bf65c846SMauro Carvalho Chehab	Explicitly load and unload the tape. If the
447*bf65c846SMauro Carvalho Chehab	command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
448*bf65c846SMauro Carvalho Chehab	MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
449*bf65c846SMauro Carvalho Chehab	drive with the command and it selects the tape slot to use of
450*bf65c846SMauro Carvalho Chehab	HP C1553A changer.
451*bf65c846SMauro Carvalho ChehabMTCOMPRESSION
452*bf65c846SMauro Carvalho Chehab	Sets compressing or uncompressing drive mode using the
453*bf65c846SMauro Carvalho Chehab	SCSI mode page 15. Note that some drives other methods for
454*bf65c846SMauro Carvalho Chehab	control of compression. Some drives (like the Exabytes) use
455*bf65c846SMauro Carvalho Chehab	density codes for compression control. Some drives use another
456*bf65c846SMauro Carvalho Chehab	mode page but this page has not been implemented in the
457*bf65c846SMauro Carvalho Chehab	driver. Some drives without compression capability will accept
458*bf65c846SMauro Carvalho Chehab	any compression mode without error.
459*bf65c846SMauro Carvalho ChehabMTSETPART
460*bf65c846SMauro Carvalho Chehab	Moves the tape to the partition given by the argument at the
461*bf65c846SMauro Carvalho Chehab	next tape operation. The block at which the tape is positioned
462*bf65c846SMauro Carvalho Chehab	is the block where the tape was previously positioned in the
463*bf65c846SMauro Carvalho Chehab	new active partition unless the next tape operation is
464*bf65c846SMauro Carvalho Chehab	MTSEEK. In this case the tape is moved directly to the block
465*bf65c846SMauro Carvalho Chehab	specified by MTSEEK. MTSETPART is inactive unless
466*bf65c846SMauro Carvalho Chehab	MT_ST_CAN_PARTITIONS set.
467*bf65c846SMauro Carvalho ChehabMTMKPART
468*bf65c846SMauro Carvalho Chehab	Formats the tape with one partition (argument zero) or two
469*bf65c846SMauro Carvalho Chehab	partitions (argument non-zero). If the argument is positive,
470*bf65c846SMauro Carvalho Chehab	it specifies the size of partition 1 in megabytes. For DDS
471*bf65c846SMauro Carvalho Chehab	drives and several early drives this is the physically first
472*bf65c846SMauro Carvalho Chehab	partition of the tape. If the argument is negative, its absolute
473*bf65c846SMauro Carvalho Chehab	value specifies the size of partition 0 in megabytes. This is
474*bf65c846SMauro Carvalho Chehab	the physically first partition of many later drives, like the
475*bf65c846SMauro Carvalho Chehab	LTO drives from LTO-5 upwards. The drive has to support partitions
476*bf65c846SMauro Carvalho Chehab	with size specified by the initiator. Inactive unless
477*bf65c846SMauro Carvalho Chehab	MT_ST_CAN_PARTITIONS set.
478*bf65c846SMauro Carvalho ChehabMTSETDRVBUFFER
479*bf65c846SMauro Carvalho Chehab	Is used for several purposes. The command is obtained from count
480*bf65c846SMauro Carvalho Chehab        with mask MT_SET_OPTIONS, the low order bits are used as argument.
481*bf65c846SMauro Carvalho Chehab	This command is only allowed for the superuser (root). The
482*bf65c846SMauro Carvalho Chehab	subcommands are:
483*bf65c846SMauro Carvalho Chehab
484*bf65c846SMauro Carvalho Chehab	* 0
485*bf65c846SMauro Carvalho Chehab           The drive buffer option is set to the argument. Zero means
486*bf65c846SMauro Carvalho Chehab           no buffering.
487*bf65c846SMauro Carvalho Chehab        * MT_ST_BOOLEANS
488*bf65c846SMauro Carvalho Chehab           Sets the buffering options. The bits are the new states
489*bf65c846SMauro Carvalho Chehab           (enabled/disabled) the following options (in the
490*bf65c846SMauro Carvalho Chehab	   parenthesis is specified whether the option is global or
491*bf65c846SMauro Carvalho Chehab	   can be specified differently for each mode):
492*bf65c846SMauro Carvalho Chehab
493*bf65c846SMauro Carvalho Chehab	     MT_ST_BUFFER_WRITES
494*bf65c846SMauro Carvalho Chehab		write buffering (mode)
495*bf65c846SMauro Carvalho Chehab	     MT_ST_ASYNC_WRITES
496*bf65c846SMauro Carvalho Chehab		asynchronous writes (mode)
497*bf65c846SMauro Carvalho Chehab             MT_ST_READ_AHEAD
498*bf65c846SMauro Carvalho Chehab		read ahead (mode)
499*bf65c846SMauro Carvalho Chehab             MT_ST_TWO_FM
500*bf65c846SMauro Carvalho Chehab		writing of two filemarks (global)
501*bf65c846SMauro Carvalho Chehab	     MT_ST_FAST_EOM
502*bf65c846SMauro Carvalho Chehab		using the SCSI spacing to EOD (global)
503*bf65c846SMauro Carvalho Chehab	     MT_ST_AUTO_LOCK
504*bf65c846SMauro Carvalho Chehab		automatic locking of the drive door (global)
505*bf65c846SMauro Carvalho Chehab             MT_ST_DEF_WRITES
506*bf65c846SMauro Carvalho Chehab		the defaults are meant only for writes (mode)
507*bf65c846SMauro Carvalho Chehab	     MT_ST_CAN_BSR
508*bf65c846SMauro Carvalho Chehab		backspacing over more than one records can
509*bf65c846SMauro Carvalho Chehab		be used for repositioning the tape (global)
510*bf65c846SMauro Carvalho Chehab	     MT_ST_NO_BLKLIMS
511*bf65c846SMauro Carvalho Chehab		the driver does not ask the block limits
512*bf65c846SMauro Carvalho Chehab		from the drive (block size can be changed only to
513*bf65c846SMauro Carvalho Chehab		variable) (global)
514*bf65c846SMauro Carvalho Chehab	     MT_ST_CAN_PARTITIONS
515*bf65c846SMauro Carvalho Chehab		enables support for partitioned
516*bf65c846SMauro Carvalho Chehab		tapes (global)
517*bf65c846SMauro Carvalho Chehab	     MT_ST_SCSI2LOGICAL
518*bf65c846SMauro Carvalho Chehab		the logical block number is used in
519*bf65c846SMauro Carvalho Chehab		the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
520*bf65c846SMauro Carvalho Chehab		the device dependent address. It is recommended to set
521*bf65c846SMauro Carvalho Chehab		this flag unless there are tapes using the device
522*bf65c846SMauro Carvalho Chehab		dependent (from the old times) (global)
523*bf65c846SMauro Carvalho Chehab	     MT_ST_SYSV
524*bf65c846SMauro Carvalho Chehab		sets the SYSV semantics (mode)
525*bf65c846SMauro Carvalho Chehab	     MT_ST_NOWAIT
526*bf65c846SMauro Carvalho Chehab		enables immediate mode (i.e., don't wait for
527*bf65c846SMauro Carvalho Chehab	        the command to finish) for some commands (e.g., rewind)
528*bf65c846SMauro Carvalho Chehab	     MT_ST_NOWAIT_EOF
529*bf65c846SMauro Carvalho Chehab		enables immediate filemark mode (i.e. when
530*bf65c846SMauro Carvalho Chehab	        writing a filemark, don't wait for it to complete). Please
531*bf65c846SMauro Carvalho Chehab		see the BASICS note about MTWEOFI with respect to the
532*bf65c846SMauro Carvalho Chehab		possible dangers of writing immediate filemarks.
533*bf65c846SMauro Carvalho Chehab	     MT_ST_SILI
534*bf65c846SMauro Carvalho Chehab		enables setting the SILI bit in SCSI commands when
535*bf65c846SMauro Carvalho Chehab		reading in variable block mode to enhance performance when
536*bf65c846SMauro Carvalho Chehab		reading blocks shorter than the byte count; set this only
537*bf65c846SMauro Carvalho Chehab		if you are sure that the drive supports SILI and the HBA
538*bf65c846SMauro Carvalho Chehab		correctly returns transfer residuals
539*bf65c846SMauro Carvalho Chehab	     MT_ST_DEBUGGING
540*bf65c846SMauro Carvalho Chehab		debugging (global; debugging must be
541*bf65c846SMauro Carvalho Chehab		compiled into the driver)
542*bf65c846SMauro Carvalho Chehab
543*bf65c846SMauro Carvalho Chehab	* MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS
544*bf65c846SMauro Carvalho Chehab	   Sets or clears the option bits.
545*bf65c846SMauro Carvalho Chehab        * MT_ST_WRITE_THRESHOLD
546*bf65c846SMauro Carvalho Chehab           Sets the write threshold for this device to kilobytes
547*bf65c846SMauro Carvalho Chehab           specified by the lowest bits.
548*bf65c846SMauro Carvalho Chehab	* MT_ST_DEF_BLKSIZE
549*bf65c846SMauro Carvalho Chehab	   Defines the default block size set automatically. Value
550*bf65c846SMauro Carvalho Chehab	   0xffffff means that the default is not used any more.
551*bf65c846SMauro Carvalho Chehab	* MT_ST_DEF_DENSITY, MT_ST_DEF_DRVBUFFER
552*bf65c846SMauro Carvalho Chehab	   Used to set or clear the density (8 bits), and drive buffer
553*bf65c846SMauro Carvalho Chehab	   state (3 bits). If the value is MT_ST_CLEAR_DEFAULT
554*bf65c846SMauro Carvalho Chehab	   (0xfffff) the default will not be used any more. Otherwise
555*bf65c846SMauro Carvalho Chehab	   the lowermost bits of the value contain the new value of
556*bf65c846SMauro Carvalho Chehab	   the parameter.
557*bf65c846SMauro Carvalho Chehab	* MT_ST_DEF_COMPRESSION
558*bf65c846SMauro Carvalho Chehab	   The compression default will not be used if the value of
559*bf65c846SMauro Carvalho Chehab	   the lowermost byte is 0xff. Otherwise the lowermost bit
560*bf65c846SMauro Carvalho Chehab	   contains the new default. If the bits 8-15 are set to a
561*bf65c846SMauro Carvalho Chehab	   non-zero number, and this number is not 0xff, the number is
562*bf65c846SMauro Carvalho Chehab	   used as the compression algorithm. The value
563*bf65c846SMauro Carvalho Chehab	   MT_ST_CLEAR_DEFAULT can be used to clear the compression
564*bf65c846SMauro Carvalho Chehab	   default.
565*bf65c846SMauro Carvalho Chehab	* MT_ST_SET_TIMEOUT
566*bf65c846SMauro Carvalho Chehab	   Set the normal timeout in seconds for this device. The
567*bf65c846SMauro Carvalho Chehab	   default is 900 seconds (15 minutes). The timeout should be
568*bf65c846SMauro Carvalho Chehab	   long enough for the retries done by the device while
569*bf65c846SMauro Carvalho Chehab	   reading/writing.
570*bf65c846SMauro Carvalho Chehab	* MT_ST_SET_LONG_TIMEOUT
571*bf65c846SMauro Carvalho Chehab	   Set the long timeout that is used for operations that are
572*bf65c846SMauro Carvalho Chehab	   known to take a long time. The default is 14000 seconds
573*bf65c846SMauro Carvalho Chehab	   (3.9 hours). For erase this value is further multiplied by
574*bf65c846SMauro Carvalho Chehab	   eight.
575*bf65c846SMauro Carvalho Chehab	* MT_ST_SET_CLN
576*bf65c846SMauro Carvalho Chehab	   Set the cleaning request interpretation parameters using
577*bf65c846SMauro Carvalho Chehab	   the lowest 24 bits of the argument. The driver can set the
578*bf65c846SMauro Carvalho Chehab	   generic status bit GMT_CLN if a cleaning request bit pattern
579*bf65c846SMauro Carvalho Chehab	   is found from the extended sense data. Many drives set one or
580*bf65c846SMauro Carvalho Chehab	   more bits in the extended sense data when the drive needs
581*bf65c846SMauro Carvalho Chehab	   cleaning. The bits are device-dependent. The driver is
582*bf65c846SMauro Carvalho Chehab	   given the number of the sense data byte (the lowest eight
583*bf65c846SMauro Carvalho Chehab	   bits of the argument; must be >= 18 (values 1 - 17
584*bf65c846SMauro Carvalho Chehab	   reserved) and <= the maximum requested sense data sixe),
585*bf65c846SMauro Carvalho Chehab	   a mask to select the relevant bits (the bits 9-16), and the
586*bf65c846SMauro Carvalho Chehab	   bit pattern (bits 17-23). If the bit pattern is zero, one
587*bf65c846SMauro Carvalho Chehab	   or more bits under the mask indicate cleaning request. If
588*bf65c846SMauro Carvalho Chehab	   the pattern is non-zero, the pattern must match the masked
589*bf65c846SMauro Carvalho Chehab	   sense data byte.
590*bf65c846SMauro Carvalho Chehab
591*bf65c846SMauro Carvalho Chehab	   (The cleaning bit is set if the additional sense code and
592*bf65c846SMauro Carvalho Chehab	   qualifier 00h 17h are seen regardless of the setting of
593*bf65c846SMauro Carvalho Chehab	   MT_ST_SET_CLN.)
594*bf65c846SMauro Carvalho Chehab
595*bf65c846SMauro Carvalho ChehabThe following ioctl uses the structure mtpos:
596*bf65c846SMauro Carvalho Chehab
597*bf65c846SMauro Carvalho ChehabMTIOCPOS
598*bf65c846SMauro Carvalho Chehab	Reads the current position from the drive. Uses
599*bf65c846SMauro Carvalho Chehab        Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
600*bf65c846SMauro Carvalho Chehab        command for the SCSI-2 drives.
601*bf65c846SMauro Carvalho Chehab
602*bf65c846SMauro Carvalho ChehabThe following ioctl uses the structure mtget to return the status:
603*bf65c846SMauro Carvalho Chehab
604*bf65c846SMauro Carvalho ChehabMTIOCGET
605*bf65c846SMauro Carvalho Chehab	Returns some status information.
606*bf65c846SMauro Carvalho Chehab        The file number and block number within file are returned. The
607*bf65c846SMauro Carvalho Chehab        block is -1 when it can't be determined (e.g., after MTBSF).
608*bf65c846SMauro Carvalho Chehab        The drive type is either MTISSCSI1 or MTISSCSI2.
609*bf65c846SMauro Carvalho Chehab        The number of recovered errors since the previous status call
610*bf65c846SMauro Carvalho Chehab        is stored in the lower word of the field mt_erreg.
611*bf65c846SMauro Carvalho Chehab        The current block size and the density code are stored in the field
612*bf65c846SMauro Carvalho Chehab        mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
613*bf65c846SMauro Carvalho Chehab        MT_ST_DENSITY_SHIFT).
614*bf65c846SMauro Carvalho Chehab	The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
615*bf65c846SMauro Carvalho Chehab	is set if there is no tape in the drive. GMT_EOD means either
616*bf65c846SMauro Carvalho Chehab	end of recorded data or end of tape. GMT_EOT means end of tape.
617*bf65c846SMauro Carvalho Chehab
618*bf65c846SMauro Carvalho Chehab
619*bf65c846SMauro Carvalho ChehabMiscellaneous Compile Options
620*bf65c846SMauro Carvalho Chehab=============================
621*bf65c846SMauro Carvalho Chehab
622*bf65c846SMauro Carvalho ChehabThe recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
623*bf65c846SMauro Carvalho Chehabis defined.
624*bf65c846SMauro Carvalho Chehab
625*bf65c846SMauro Carvalho ChehabThe maximum number of tape devices is determined by the define
626*bf65c846SMauro Carvalho ChehabST_MAX_TAPES. If more tapes are detected at driver initialization, the
627*bf65c846SMauro Carvalho Chehabmaximum is adjusted accordingly.
628*bf65c846SMauro Carvalho Chehab
629*bf65c846SMauro Carvalho ChehabImmediate return from tape positioning SCSI commands can be enabled by
630*bf65c846SMauro Carvalho Chehabdefining ST_NOWAIT. If this is defined, the user should take care that
631*bf65c846SMauro Carvalho Chehabthe next tape operation is not started before the previous one has
632*bf65c846SMauro Carvalho Chehabfinished. The drives and SCSI adapters should handle this condition
633*bf65c846SMauro Carvalho Chehabgracefully, but some drive/adapter combinations are known to hang the
634*bf65c846SMauro Carvalho ChehabSCSI bus in this case.
635*bf65c846SMauro Carvalho Chehab
636*bf65c846SMauro Carvalho ChehabThe MTEOM command is by default implemented as spacing over 32767
637*bf65c846SMauro Carvalho Chehabfilemarks. With this method the file number in the status is
638*bf65c846SMauro Carvalho Chehabcorrect. The user can request using direct spacing to EOD by setting
639*bf65c846SMauro Carvalho ChehabST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
640*bf65c846SMauro Carvalho Chehabnumber will be invalid.
641*bf65c846SMauro Carvalho Chehab
642*bf65c846SMauro Carvalho ChehabWhen using read ahead or buffered writes the position within the file
643*bf65c846SMauro Carvalho Chehabmay not be correct after the file is closed (correct position may
644*bf65c846SMauro Carvalho Chehabrequire backspacing over more than one record). The correct position
645*bf65c846SMauro Carvalho Chehabwithin file can be obtained if ST_IN_FILE_POS is defined at compile
646*bf65c846SMauro Carvalho Chehabtime or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
647*bf65c846SMauro Carvalho Chehab(The driver always backs over a filemark crossed by read ahead if the
648*bf65c846SMauro Carvalho Chehabuser does not request data that far.)
649*bf65c846SMauro Carvalho Chehab
650*bf65c846SMauro Carvalho Chehab
651*bf65c846SMauro Carvalho ChehabDebugging Hints
652*bf65c846SMauro Carvalho Chehab===============
653*bf65c846SMauro Carvalho Chehab
654*bf65c846SMauro Carvalho ChehabDebugging code is now compiled in by default but debugging is turned off
655*bf65c846SMauro Carvalho Chehabwith the kernel module parameter debug_flag defaulting to 0.  Debugging
656*bf65c846SMauro Carvalho Chehabcan still be switched on and off with an ioctl.  To enable debug at
657*bf65c846SMauro Carvalho Chehabmodule load time add debug_flag=1 to the module load options, the
658*bf65c846SMauro Carvalho Chehabdebugging output is not voluminous. Debugging can also be enabled
659*bf65c846SMauro Carvalho Chehaband disabled by writing a '0' (disable) or '1' (enable) to the sysfs
660*bf65c846SMauro Carvalho Chehabfile /sys/bus/scsi/drivers/st/debug_flag.
661*bf65c846SMauro Carvalho Chehab
662*bf65c846SMauro Carvalho ChehabIf the tape seems to hang, I would be very interested to hear where
663*bf65c846SMauro Carvalho Chehabthe driver is waiting. With the command 'ps -l' you can see the state
664*bf65c846SMauro Carvalho Chehabof the process using the tape. If the state is D, the process is
665*bf65c846SMauro Carvalho Chehabwaiting for something. The field WCHAN tells where the driver is
666*bf65c846SMauro Carvalho Chehabwaiting. If you have the current System.map in the correct place (in
667*bf65c846SMauro Carvalho Chehab/boot for the procps I use) or have updated /etc/psdatabase (for kmem
668*bf65c846SMauro Carvalho Chehabps), ps writes the function name in the WCHAN field. If not, you have
669*bf65c846SMauro Carvalho Chehabto look up the function from System.map.
670*bf65c846SMauro Carvalho Chehab
671*bf65c846SMauro Carvalho ChehabNote also that the timeouts are very long compared to most other
672*bf65c846SMauro Carvalho Chehabdrivers. This means that the Linux driver may appear hung although the
673*bf65c846SMauro Carvalho Chehabreal reason is that the tape firmware has got confused.
674