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 February 8, 2012 29.Dt CD 4 30.Os 31.Sh NAME 32.Nm cd 33.Nd SCSI CD-ROM driver 34.Sh SYNOPSIS 35.Cd device cd 36.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3""" 37.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11""" 38.Sh DESCRIPTION 39The 40.Nm 41driver provides support for a 42.Tn SCSI 43.Tn CD-ROM 44(Compact Disc-Read Only Memory) drive. 45In an attempt to look like a regular disk, the 46.Nm 47driver synthesizes a partition table, with one partition covering the entire 48.Tn CD-ROM . 49It is possible to modify this partition table using 50.Xr disklabel 8 , 51but it will only last until the 52.Tn CD-ROM 53is unmounted. 54In general the interfaces are similar to those described by 55.Xr ada 4 56and 57.Xr da 4 . 58.Pp 59As the 60.Tn SCSI 61adapter is probed during boot, the 62.Tn SCSI 63bus is scanned for devices. 64Any devices found which answer as CDROM 65(type 5) or WORM (type 4) type devices will be `attached' to the 66.Nm 67driver. 68Prior to 69.Fx 2.1 , 70the first device found will be attached as 71.Li cd0 72the next, 73.Li cd1 , 74etc. 75Beginning in 76.Fx 2.1 77it is possible to specify what cd unit a device should 78come on line as; refer to 79.Xr scsi 4 80for details on kernel configuration. 81.Pp 82The system utility 83.Xr disklabel 8 84may be used to read the synthesized 85disk label 86structure, which will contain correct figures for the size of the 87.Tn CD-ROM 88should that information be required. 89.Sh KERNEL CONFIGURATION 90Any number of 91.Tn CD-ROM 92devices may be attached to the system regardless of system 93configuration as all resources are dynamically allocated. 94.Sh IOCTLS 95The following 96.Xr ioctl 2 97calls which apply to 98.Tn SCSI 99.Tn CD-ROM 100drives are defined 101in the header files 102.In sys/cdio.h 103and 104.In sys/disklabel.h . 105.Bl -tag -width CDIOCREADSUBCHANNEL 106.It Dv DIOCGDINFO 107.It Dv DIOCSDINFO 108.Pq Li "struct disklabel" 109Read or write the in-core copy of the disklabel for the 110drive. 111The disklabel is initialized with information 112read from the scsi inquiry commands, and should be the same as 113the information printed at boot. 114This structure is defined in the header file 115.In sys/disklabel.h . 116.It Dv CDIOCPLAYTRACKS 117.Pq Li "struct ioc_play_track" 118Start audio playback given a track address and length. 119The structure is defined as follows: 120.Bd -literal -offset indent 121struct ioc_play_track 122{ 123 u_char start_track; 124 u_char start_index; 125 u_char end_track; 126 u_char end_index; 127}; 128.Ed 129.It Dv CDIOCPLAYBLOCKS 130.Pq Li "struct ioc_play_blocks" 131Start audio playback given a block address and length. 132The structure is defined as follows: 133.Bd -literal -offset indent 134struct ioc_play_blocks 135{ 136 int blk; 137 int len; 138}; 139.Ed 140.It Dv CDIOCPLAYMSF 141.Pq Li "struct ioc_play_msf" 142Start audio playback given a `minutes-seconds-frames' address and 143length. 144The structure is defined as follows: 145.Bd -literal -offset indent 146struct ioc_play_msf 147{ 148 u_char start_m; 149 u_char start_s; 150 u_char start_f; 151 u_char end_m; 152 u_char end_s; 153 u_char end_f; 154}; 155.Ed 156.It Dv CDIOCREADSUBCHANNEL 157.Pq Li "struct ioc_read_subchannel" 158Read information from the subchannel at the location specified by this 159structure: 160.Bd -literal -offset indent 161struct ioc_read_subchannel { 162 u_char address_format; 163#define CD_LBA_FORMAT 1 164#define CD_MSF_FORMAT 2 165 u_char data_format; 166#define CD_SUBQ_DATA 0 167#define CD_CURRENT_POSITION 1 168#define CD_MEDIA_CATALOG 2 169#define CD_TRACK_INFO 3 170 u_char track; 171 int data_len; 172 struct cd_sub_channel_info *data; 173}; 174.Ed 175.It Dv CDIOREADTOCHEADER 176.Pq Li "struct ioc_toc_header" 177Return summary information about the table of contents for the mounted 178.Tn CD-ROM . 179The information is returned into the following structure: 180.Bd -literal -offset indent 181struct ioc_toc_header { 182 u_short len; 183 u_char starting_track; 184 u_char ending_track; 185}; 186.Ed 187.It Dv CDIOREADTOCENTRYS 188.Pq Li "struct ioc_read_toc_entry" 189Return information from the table of contents entries mentioned. 190.Pq Yes, this command name is misspelled. 191The argument structure is defined as follows: 192.Bd -literal -offset indent 193struct ioc_read_toc_entry { 194 u_char address_format; 195 u_char starting_track; 196 u_short data_len; 197 struct cd_toc_entry *data; 198}; 199.Ed 200The requested data is written into an area of size 201.Li data_len 202and pointed to by 203.Li data . 204.It Dv CDIOCSETPATCH 205.Pq Li "struct ioc_patch" 206Attach various audio channels to various output channels. 207The argument structure is defined thusly: 208.Bd -literal -offset indent 209struct ioc_patch { 210 u_char patch[4]; 211 /* one for each channel */ 212}; 213.Ed 214.It Dv CDIOCGETVOL 215.It Dv CDIOCSETVOL 216.Pq Li "struct ioc_vol" 217Get (set) information about the volume settings of the output channels. 218The argument structure is as follows: 219.Bd -literal -offset indent 220struct ioc_vol 221{ 222 u_char vol[4]; 223 /* one for each channel */ 224}; 225.Ed 226.It Dv CDIOCSETMONO 227Patch all output channels to all source channels. 228.It Dv CDIOCSETSTEREO 229Patch left source channel to the left output channel and the right 230source channel to the right output channel. 231.It Dv CDIOCSETMUTE 232Mute output without changing the volume settings. 233.It Dv CDIOCSETLEFT 234.It Dv CDIOCSETRIGHT 235Attach both output channels to the left (right) source channel. 236.It Dv CDIOCSETDEBUG 237.It Dv CDIOCCLRDEBUG 238Turn on (off) debugging for the appropriate device. 239.It Dv CDIOCPAUSE 240.It Dv CDIOCRESUME 241Pause (resume) audio play, without resetting the location of the read-head. 242.It Dv CDIOCRESET 243Reset the drive. 244.It Dv CDIOCSTART 245.It Dv CDIOCSTOP 246Tell the drive to spin-up (-down) the 247.Tn CD-ROM . 248.It Dv CDIOCALLOW 249.It Dv CDIOCPREVENT 250Tell the drive to allow (prevent) manual ejection of the 251.Tn CD-ROM 252disc. 253Not all drives support this feature. 254.It Dv CDIOCEJECT 255Eject the 256.Tn CD-ROM . 257.It Dv CDIOCCLOSE 258Tell the drive to close its door and load the media. 259Not all drives support this feature. 260.El 261.Sh NOTES 262When a 263.Tn CD-ROM 264is changed in a drive controlled by the 265.Nm 266driver, then the act of changing the media will invalidate the 267disklabel and information held within the kernel. 268To stop corruption, 269all accesses to the device will be discarded until there are no more 270open file descriptors referencing the device. 271During this period, all 272new open attempts will be rejected. 273When no more open file descriptors 274reference the device, the first next open will load a new set of 275parameters (including disklabel) for the drive. 276.Pp 277The audio code in the 278.Nm 279driver only support 280.Tn SCSI-2 281standard audio commands. 282As many 283.Tn CD-ROM 284manufacturers have not followed the standard, there are many 285.Tn CD-ROM 286drives for which audio will not work. 287Some work is planned to support 288some of the more common `broken' 289.Tn CD-ROM 290drives; however, this is not yet under way. 291.Sh CHANGER OPERATION 292This driver has built-in support for LUN-based CD changers. 293A LUN-based CD 294changer is a drive that can hold two or more CDs, but only has one CD 295player mechanism. 296Each CD in the drive shows up as a separate logical unit 297on the 298.Tn SCSI 299bus. 300The 301.Nm 302driver automatically recognizes LUN-based changers, and routes commands for 303changers through an internal scheduler. 304The scheduler prevents changer 305"thrashing", which is caused by sending commands to different LUNs in the 306changer at the same time. 307.Pp 308The scheduler honors minimum and maximum time 309quanta that the driver will spend on a particular LUN. 310The minimum time 311is the guaranteed minimum amount of time that the driver will spend on a 312given LUN, even if there is no outstanding I/O for that LUN. 313The maximum 314time is the maximum amount of time the changer will spend on a LUN if there 315is outstanding I/O for another LUN. 316If there is no outstanding I/O for 317another LUN, the driver will allow indefinite access to a given LUN. 318.Pp 319The minimum and maximum time quanta are configurable via kernel options and 320also via sysctl and kernel tunable variables. 321The kernel options are: 322.Pp 323.Bl -item -compact 324.It 325.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3""" 326.It 327.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11""" 328.El 329.Pp 330The sysctl/kernel tunable variables are: 331.Pp 332.Bl -item -compact 333.It 334.Va kern.cam.cd.changer.min_busy_seconds 335.It 336.Va kern.cam.cd.changer.max_busy_seconds 337.El 338.Pp 339It is suggested that the user try experimenting with the minimum and 340maximum timeouts via the sysctl variables to arrive at the proper values 341for your changer. 342Once you have settled on the proper timeouts for your 343changer, you can then put them in your kernel config file. 344.Pp 345If your system does have a LUN-based changer, you may notice that the 346probe messages for the various LUNs of the changer will continue to appear 347while the boot process is going on. 348This is normal, and is caused by the 349changer scheduling code. 350.Sh SYSCTL VARIABLES 351The following variables are available as both 352.Xr sysctl 8 353variables and 354.Xr loader 8 355tunables: 356.Bl -tag -width 12 357.It kern.cam.cd.retry_count 358.Pp 359This variable determines how many times the 360.Nm 361driver will retry a READ or WRITE command. 362This does not affect the number of retries used during probe time or for 363the 364.Nm 365driver dump routine. 366This value currently defaults to 4. 367.It kern.cam.cd.%d.minimum_cmd_size 368.Pp 369The 370.Nm 371driver attempts to automatically determine whether the drive it is talking 372to supports 6 byte or 10 byte MODE SENSE/MODE SELECT operations. 373Many 374.Tn SCSI 375drives only support 6 byte commands, and 376.Tn ATAPI 377drives only support 10 byte commands. 378The 379.Nm 380driver first attempts to determine whether the protocol in use typically 381supports 6 byte commands by issuing a CAM Path Inquiry CCB. 382It will then default to 6 byte or 10 byte commands as appropriate. 383After that, the 384.Nm 385driver defaults to using 6 byte commands (assuming the protocol the drive 386speaks claims to support 6 byte commands), until one fails with a 387.Tn SCSI 388ILLEGAL REQUEST error. 389Then it tries the 10 byte version of the command to 390see if that works instead. 391Users can change the default via per-drive 392sysctl variables and loader tunables. 393Where 394.Dq %d 395is the unit number of the drive in question. 396Valid minimum command sizes 397are 6 and 10. 398Any value above 6 will be rounded to 10, and any value below 3996 will be rounded to 6. 400.It kern.cam.cd.changer.min_busy_seconds 401.It kern.cam.cd.changer.max_busy_seconds 402.Pp 403Tune how long individual LUNs are 'locked' for I/O operations to 404optimize changer operation. 405See CHANGER OPERATION section for information on how to use these items. 406.El 407.Sh FILES 408.Bl -tag -width /dev/cd[0-9][a-h] -compact 409.It Pa /dev/cd[0-9][a-h] 410raw mode 411.Tn CD-ROM 412devices 413.El 414.Sh DIAGNOSTICS 415None. 416.Sh SEE ALSO 417.Xr cam 4 , 418.Xr da 4 , 419.Xr disklabel 8 , 420.Xr cd 9 421.Sh HISTORY 422This 423.Nm 424driver is based upon the 425.Nm 426driver written by Julian Elischer, which appeared in 427.Bx 386 0.1 . 428The 429CAM version of the 430.Nm 431driver was written by Kenneth Merry and first appeared in 432.Fx 3.0 . 433.Sh BUGS 434The names of the structures used for the third argument to 435.Fn ioctl 436were poorly chosen, and a number of spelling errors have survived in 437the names of the 438.Fn ioctl 439commands. 440.Pp 441There is no mechanism currently to set different minimum and maximum 442timeouts for different CD changers; the timeout values set by the kernel 443options or the sysctl variables apply to all LUN-based CD changers in the 444system. 445It is possible to implement such support, but the sysctl 446implementation at least would be rather inelegant, because of the current 447inability of the sysctl code to handle the addition of nodes after compile 448time. 449Thus, it would take one dynamically sized sysctl variable and a 450userland utility to get/set the timeout values. 451Implementation of separate 452timeouts for different CD devices in the kernel config file would likely 453require modification of 454.Xr config 8 455to support the two timeouts when hardwiring 456.Nm 457devices. 458