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