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