xref: /freebsd/share/man/man4/sa.4 (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1.\" Copyright (c) 1996
2.\"	Julian Elischer <julian@FreeBSD.org>.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\"
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd January 18, 2022
27.Dt SA 4
28.Os
29.Sh NAME
30.Nm sa
31.Nd SCSI Sequential Access device driver
32.Sh SYNOPSIS
33.Cd device sa
34.Sh DESCRIPTION
35The
36.Nm
37driver provides support for all
38.Tn SCSI
39devices of the sequential access class that are attached to the system
40through a supported
41.Tn SCSI
42Host Adapter.
43The sequential access class includes tape and other linear access devices.
44.Pp
45A
46.Tn SCSI
47Host
48adapter must also be separately configured into the system
49before a
50.Tn SCSI
51sequential access device can be configured.
52.Sh MOUNT SESSIONS
53The
54.Nm
55driver is based around the concept of a
56.Dq Em mount session ,
57which is defined as the period between the time that a tape is
58mounted, and the time when it is unmounted.
59Any parameters set during
60a mount session remain in effect for the remainder of the session or
61until replaced.
62The tape can be unmounted, bringing the session to a
63close in several ways.
64These include:
65.Bl -enum
66.It
67Closing a `rewind device',
68referred to as sub-mode 00 below.
69An example is
70.Pa /dev/sa0 .
71.It
72Using the MTOFFL
73.Xr ioctl 2
74command, reachable through the
75.Sq Cm offline
76command of
77.Xr mt 1 .
78.El
79.Pp
80It should be noted that tape devices are exclusive open devices, except in
81the case where a control mode device is opened.
82In the latter case, exclusive
83access is only sought when needed (e.g., to set parameters).
84.Sh SUB-MODES
85The sub-modes differ in the action taken when the device is closed:
86.Bl -tag -width XXXX
87.It Pa /dev/sa*
88A close will rewind the device; if the tape has been
89written, then a file mark will be written before the rewind is requested.
90The device is unmounted.
91.It Pa /dev/nsa*
92A close will leave the tape mounted.
93If the tape was written to, a file mark will be written.
94No other head positioning takes place.
95Any further reads or writes will occur directly after the
96last read, or the written file mark.
97.It Pa /dev/esa*
98A close will rewind the device.
99If the tape has been
100written, then a file mark will be written before the rewind is requested.
101On completion of the rewind an unload command will be issued.
102The device is unmounted.
103.El
104.Sh BLOCKING MODES
105.Tn SCSI
106tapes may run in either
107.Sq Em variable
108or
109.Sq Em fixed
110block-size modes.
111Most
112.Tn QIC Ns -type
113devices run in fixed block-size mode, where most nine-track tapes and
114many new cartridge formats allow variable block-size.
115The difference between the two is as follows:
116.Bl -inset
117.It Variable block-size:
118Each write made to the device results in a single logical record
119written to the tape.
120One can never read or write
121.Em part
122of a record from tape (though you may request a larger block and read
123a smaller record); nor can one read multiple blocks.
124Data from a single write is therefore read by a single read.
125The block size used
126may be any value supported by the device, the
127.Tn SCSI
128adapter and the system (usually between 1 byte and 64 Kbytes,
129sometimes more).
130.Pp
131When reading a variable record/block from the tape, the head is
132logically considered to be immediately after the last item read,
133and before the next item after that.
134If the next item is a file mark,
135but it was never read, then the next
136process to read will immediately hit the file mark and receive an end-of-file notification.
137.It Fixed block-size:
138Data written by the user is passed to the tape as a succession of
139fixed size blocks.
140It may be contiguous in memory, but it is
141considered to be a series of independent blocks.
142One may never write
143an amount of data that is not an exact multiple of the blocksize.
144One may read and write the same data as a different set of records.
145In other words, blocks that were written together may be read separately,
146and vice-versa.
147.Pp
148If one requests more blocks than remain in the file, the drive will
149encounter the file mark.
150As there is some data to return (unless
151there were no records before the file mark), the read will succeed,
152returning that data.
153The next read will return immediately with a value
154of 0.
155(As above, if the file mark is never read, it remains for the next
156process to read if in no-rewind mode.)
157.El
158.Sh BLOCK SIZES
159By default, the driver will NOT accept reads or writes to a tape device that
160are larger than may be written to or read from the mounted tape using a single
161write or read request.
162Because of this, the application author may have confidence that his wishes
163are respected in terms of the block size written to tape.
164For example, if the user tries to write a 256KB block to the tape, but the
165controller can handle no more than 128KB, the write will fail.
166The previous
167.Fx
168behavior, prior to
169.Fx
17010.0,
171was to break up large reads or writes into smaller blocks when going to the
172tape.
173The problem with that behavior, though, is that it hides the actual on-tape
174block size from the application writer, at least in variable block mode.
175.Pp
176If the user would like his large reads and writes broken up into separate
177pieces, he may set the following loader tunables.
178Note that these tunables WILL GO AWAY in
179.Fx 11.0 .
180They are provided for transition purposes only.
181.Bl -tag -width 12
182.It kern.cam.sa.allow_io_split
183.Pp
184This variable, when set to 1, will configure all
185.Nm
186devices to split large buffers into smaller pieces when needed.
187.It kern.cam.sa.%d.allow_io_split
188.Pp
189This variable, when set to 1, will configure the given
190.Nm
191unit to split large buffers into multiple pieces.
192This will override the global setting, if it exists.
193.El
194.Pp
195There are several
196.Xr sysctl 8
197variables available to view block handling parameters:
198.Bl -tag -width 12
199.It kern.cam.sa.%d.allow_io_split
200.Pp
201This variable allows the user to see, but not modify, the current I/O split
202setting.
203The user is not permitted to modify this setting so that there is no chance
204of behavior changing for the application while a tape is mounted.
205.It kern.cam.sa.%d.maxio
206.Pp
207This variable shows the maximum I/O size in bytes that is allowed by the
208combination of kernel tuning parameters (MAXPHYS, DFLTPHYS) and the
209capabilities of the controller that is attached to the tape drive.
210Applications may look at this value for a guide on how large an I/O may be
211permitted, but should keep in mind that the actual maximum may be
212restricted further by the tape drive via the
213.Tn SCSI
214READ BLOCK LIMITS command.
215.It kern.cam.sa.%d.cpi_maxio
216.Pp
217This variable shows the maximum I/O size supported by the controller, in
218bytes, that is reported via the CAM Path Inquiry CCB (XPT_PATH_INQ).
219If this is 0, that means that the controller has not reported a maximum I/O
220size.
221.El
222.Sh FILE MARK HANDLING
223The handling of file marks on write is automatic.
224If the user has
225written to the tape, and has not done a read since the last write,
226then a file mark will be written to the tape when the device is
227closed.
228If a rewind is requested after a write, then the driver
229assumes that the last file on the tape has been written, and ensures
230that there are two file marks written to the tape.
231The exception to
232this is that there seems to be a standard (which we follow, but do not
233understand why) that certain types of tape do not actually write two
234file marks to tape, but when read, report a `phantom' file mark when the
235last file is read.
236These devices include the QIC family of devices.
237(It might be that this set of devices is the same set as that of fixed
238block devices.
239This has not been determined yet, and they are treated
240as separate behaviors by the driver at this time.)
241.Sh PARAMETERS
242The
243.Nm
244driver supports a number of parameters.
245The user can query parameters using
246.Dq mt param -l
247(which uses the
248.Dv MTIOCPARAMGET
249ioctl) and the user can set parameters using
250.Dq mt param -s
251(which uses the
252.Dv MTIOCPARAMSET
253ioctl).
254See
255.Xr mt 1
256and
257.Xr mtio 4
258for more details on the interface.
259.Pp
260Supported parameters:
261.Bl -tag -width 5n
262.It sili
263The default is 0.
264When set to 1, it sets the Suppress Incorrect Length Indicator (SILI) bit
265on tape reads.
266Tape drives normally return sense data (which contains the residual) when the
267application reads a block that is not the same length as the amount of data
268requested.
269The SILI bit suppresses that notification in most cases.
270See the SSC-5 spec (available at t10.org), specifically the section on the
271READ(6) command, for more information.
272.It eot_warn
273The default is 0.
274By default, the
275.Nm
276driver reports entering Programmable Early Warning, Early Warning and End
277of Media conditions by returning a write with 0 bytes written, and
278.Dv errno
279set to 0.
280If
281.Va eot_warn
282is set to 1, the
283.Nm
284driver will set
285.Dv errno
286to
287.Dv ENOSPC
288when it enters any of the out of space conditions.
289.It protection.protection_supported
290This is a read-only parameter, and is set to 1 if the tape drive supports
291protection information.
292.It protection.prot_method
293If protection is supported, set this to the desired protection method
294supported by the tape drive.
295As of SSC-5r03 (available at t10.org), the protection method values are:
296.Bl -tag -width 3n
297.It 0
298No protection.
299.It 1
300Reed-Solomon CRC, 4 bytes in length.
301.It 2
302CRC32C, 4 bytes in length.
303.El
304.It protection.pi_length
305Length of the protection information, see above for lengths.
306.It protection.lbp_w
307If set to 1, enable logical block protection on writes.
308The CRC must be appended to the end of the block written to the tape driver.
309The tape drive will verify the CRC when it receives the block.
310.It protection.lbp_r
311If set to 1, enable logical block protection on reads.
312The CRC will be appended to the end of the block read from the tape driver.
313The application should verify the CRC when it receives the block.
314.It protection.rdbp
315If set to 1, enable logical block protection on the RECOVER BUFFERED DATA
316command.
317The
318.Nm
319driver does not currently use the
320RECOVER BUFFERED DATA command.
321.El
322.Sh TIMEOUTS
323The
324.Nm
325driver has a set of default timeouts for SCSI commands (READ, WRITE, TEST UNIT
326READY, etc.) that will likely work in most cases for many tape drives.
327.Pp
328For newer tape drives that claim to support the SPC-4
329standard (SCSI Primary Commands 4) or later standards, the
330.Nm
331driver will attempt to use the REPORT SUPPORTED OPERATION CODES command to
332fetch timeout descriptors from the drive.
333If the drive does report timeout descriptors, the
334.Nm
335driver will use the drive's recommended timeouts for commands.
336.Pp
337The timeouts in use are reported in units of
338.Sy thousandths
339of a second via the
340.Va kern.cam.sa.%d.timeout.*
341.Xr sysctl 8
342variables.
343.Pp
344To override either the default timeouts, or the timeouts recommended by the
345drive, you can set one of two sets of loader tunable values.
346If you have a drive that supports the REPORT SUPPORTED OPERATION CODES
347timeout descriptors (see the
348.Xr camcontrol 8
349.Va opcodes
350subcommand) it is generally best to use those values.
351The global
352.Va kern.cam.sa.timeout.*
353values will override the timeouts for all
354.Nm
355driver instances.
356If there are 5 tape drives in the system, they'll all get the same timeouts.
357The
358.Va kern.cam.sa.%d.timeout.*
359values (where %d is the numeric
360.Nm
361instance number) will override the global timeouts as well as either the
362default timeouts or the timeouts recommended by the drive.
363.Pp
364To set timeouts after boot, the per-instance timeout values, for example:
365.Va kern.cam.sa.0.timeout.read ,
366are available as sysctl variables.
367.Pp
368If a tape drive arrives after boot, the global tunables or per-instance
369tunables that apply to the newly arrived drive will be used.
370.Pp
371Loader tunables:
372.Pp
373.Bl -tag -compact
374.It kern.cam.sa.timeout.erase
375.It kern.cam.sa.timeout.locate
376.It kern.cam.sa.timeout.mode_select
377.It kern.cam.sa.timeout.mode_sense
378.It kern.cam.sa.timeout.prevent
379.It kern.cam.sa.timeout.read
380.It kern.cam.sa.timeout.read_position
381.It kern.cam.sa.timeout.read_block_limits
382.It kern.cam.sa.timeout.report_density
383.It kern.cam.sa.timeout.reserve
384.It kern.cam.sa.timeout.rewind
385.It kern.cam.sa.timeout.space
386.It kern.cam.sa.timeout.tur
387.It kern.cam.sa.timeout.write
388.It kern.cam.sa.timeout.write_filemarks
389.El
390.Pp
391Loader tunable values and
392.Xr sysctl 8
393values:
394.Pp
395.Bl -tag -compact
396.It kern.cam.sa.%d.timeout.erase
397.It kern.cam.sa.%d.timeout.locate
398.It kern.cam.sa.%d.timeout.mode_select
399.It kern.cam.sa.%d.timeout.mode_sense
400.It kern.cam.sa.%d.timeout.prevent
401.It kern.cam.sa.%d.timeout.read
402.It kern.cam.sa.%d.timeout.read_position
403.It kern.cam.sa.%d.timeout.read_block_limits
404.It kern.cam.sa.%d.timeout.report_density
405.It kern.cam.sa.%d.timeout.reserve
406.It kern.cam.sa.%d.timeout.rewind
407.It kern.cam.sa.%d.timeout.space
408.It kern.cam.sa.%d.timeout.tur
409.It kern.cam.sa.%d.timeout.write
410.It kern.cam.sa.%d.timeout.write_filemarks
411.El
412.Pp
413As mentioned above, the timeouts are set and reported in
414.Sy thousandths
415of a second, so be sure to account for that when setting them.
416.Sh IOCTLS
417The
418.Nm
419driver supports all of the ioctls of
420.Xr mtio 4 .
421.Sh FILES
422.Bl -tag -width /dev/[n][e]sa[0-9] -compact
423.It Pa /dev/[n][e]sa[0-9]
424general form:
425.It Pa /dev/sa0
426Rewind on close
427.It Pa /dev/nsa0
428No rewind on close
429.It Pa /dev/esa0
430Eject on close (if capable)
431.It Pa /dev/sa0.ctl
432Control mode device (to examine state while another program is
433accessing the device, e.g.).
434.El
435.Sh DIAGNOSTICS
436The
437.Nm
438driver supports injecting End Of Media (EOM) notification to aid
439application development and testing.
440EOM is indicated to the application by returning the read or write with 0
441bytes written.
442In addition, when EOM is injected, the tape position status will be updated
443to temporarily show Beyond of the Programmable Early Warning (BPEW) status.
444To see BPEW status, use the
445.Dv MTIOCEXTGET
446ioctl, which is used by the
447.Dq mt status
448command.
449To inject an EOM notification, set the
450.Pp
451.Va kern.cam.sa.%d.inject_eom
452.Pp
453sysctl variable to 1.
454One EOM notification will be sent, BPEW status will be set for one position
455query, and then the driver state will be reset to normal.
456.Sh SEE ALSO
457.Xr mt 1 ,
458.Xr cam 4 ,
459.Xr mtio 4
460.Sh AUTHORS
461.An -nosplit
462The
463.Nm
464driver was written for the
465.Tn CAM
466.Tn SCSI
467subsystem by
468.An Justin T. Gibbs
469and
470.An Kenneth Merry .
471Many ideas were gleaned from the
472.Nm st
473device driver written and ported from
474.Tn Mach
4752.5
476by
477.An Julian Elischer .
478.Pp
479The owner of record for many years was
480.An Matthew Jacob .
481The current maintainer is
482.An Kenneth Merry
483.Sh BUGS
484This driver lacks many of the hacks required to deal with older devices.
485Many older
486.Tn SCSI-1
487devices may not work properly with this driver yet.
488.Pp
489Additionally, certain
490tapes (QIC tapes mostly) that were written under
491.Fx
4922.X
493are not automatically read correctly with this driver: you may need to
494explicitly set variable block mode or set to the blocksize that works best
495for your device in order to read tapes written under
496.Fx
4972.X.
498.Pp
499Partitions are only supported for status information and location.
500It would be nice to add support for creating and editing tape partitions.
501