xref: /freebsd/share/man/man4/cd.4 (revision aa64588d28258aef88cc33b8043112e8856948d0)
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 8, 2009
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 ad 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.Pp
106.Bl -tag -width CDIOCREADSUBCHANNEL
107.It Dv DIOCGDINFO
108.It Dv DIOCSDINFO
109.Pq Li "struct disklabel"
110Read or write the in-core copy of the disklabel for the
111drive.
112The disklabel is initialized with information
113read from the scsi inquiry commands, and should be the same as
114the information printed at boot.
115This structure is defined in
116.Xr disklabel 5 .
117.It Dv CDIOCCAPABILITY
118.Pq Li "struct ioc_capability"
119Retrieve information from the drive on what features it supports.
120The information is returned in the following structure:
121.Bd -literal -offset indent
122struct ioc_capability {
123	u_long	play_function;
124#define CDDOPLAYTRK	0x00000001
125	/* Can play tracks/index */
126#define	CDDOPLAYMSF	0x00000002
127	/* Can play msf to msf */
128#define	CDDOPLAYBLOCKS	0x00000004
129	/* Can play range of blocks */
130#define	CDDOPAUSE	0x00000100
131	/* Output can be paused */
132#define	CDDORESUME	0x00000200
133	/* Output can be resumed */
134#define	CDDORESET	0x00000400
135	/* Drive can be completely reset */
136#define	CDDOSTART	0x00000800
137	/* Audio can be started */
138#define CDDOSTOP	0x00001000
139	/* Audio can be stopped */
140#define CDDOPITCH	0x00002000
141	/* Audio pitch can be changed */
142
143	u_long	routing_function;
144#define CDREADVOLUME	0x00000001
145	/* Volume settings can be read */
146#define CDSETVOLUME	0x00000002
147	/* Volume settings can be set */
148#define	CDSETMONO	0x00000100
149	/* Output can be set to mono */
150#define CDSETSTEREO	0x00000200
151	/* Output can be set to stereo (def) */
152#define	CDSETLEFT	0x00000400
153	/* Output can be set to left only */
154#define	CDSETRIGHT	0x00000800
155	/* Output can be set to right only */
156#define	CDSETMUTE	0x00001000
157	/* Output can be muted */
158#define CDSETPATCH	0x00008000
159	/* Direct routing control allowed */
160
161	u_long	special_function;
162#define	CDDOEJECT	0x00000001
163	/* The tray can be opened */
164#define	CDDOCLOSE	0x00000002
165	/* The tray can be closed */
166#define	CDDOLOCK	0x00000004
167	/* The tray can be locked */
168#define CDREADHEADER	0x00000100
169	/* Can read Table of Contents */
170#define	CDREADENTRIES	0x00000200
171	/* Can read TOC Entries */
172#define	CDREADSUBQ	0x00000200
173	/* Can read Subchannel info */
174#define CDREADRW	0x00000400
175	/* Can read subcodes R-W */
176#define	CDHASDEBUG	0x00004000
177	/* The tray has dynamic debugging */
178};
179.Ed
180.It Dv CDIOCPLAYTRACKS
181.Pq Li "struct ioc_play_track"
182Start audio playback given a track address and length.
183The structure is defined as follows:
184.Bd -literal -offset indent
185struct ioc_play_track
186{
187	u_char	start_track;
188	u_char	start_index;
189	u_char	end_track;
190	u_char	end_index;
191};
192.Ed
193.It Dv CDIOCPLAYBLOCKS
194.Pq Li "struct ioc_play_blocks"
195Start audio playback given a block address and length.
196The structure is defined as follows:
197.Bd -literal -offset indent
198struct ioc_play_blocks
199{
200	int	blk;
201	int	len;
202};
203.Ed
204.It Dv CDIOCPLAYMSF
205.Pq Li "struct ioc_play_msf"
206Start audio playback given a `minutes-seconds-frames' address and
207length.
208The structure is defined as follows:
209.Bd -literal -offset indent
210struct ioc_play_msf
211{
212	u_char	start_m;
213	u_char	start_s;
214	u_char	start_f;
215	u_char	end_m;
216	u_char	end_s;
217	u_char	end_f;
218};
219.Ed
220.It Dv CDIOCREADSUBCHANNEL
221.Pq Li "struct ioc_read_subchannel"
222Read information from the subchannel at the location specified by this
223structure:
224.Bd -literal -offset indent
225struct ioc_read_subchannel {
226	u_char address_format;
227#define CD_LBA_FORMAT	1
228#define CD_MSF_FORMAT	2
229	u_char data_format;
230#define CD_SUBQ_DATA		0
231#define CD_CURRENT_POSITION	1
232#define CD_MEDIA_CATALOG	2
233#define CD_TRACK_INFO		3
234	u_char track;
235	int	data_len;
236	struct  cd_sub_channel_info *data;
237};
238.Ed
239.It Dv CDIOREADTOCHEADER
240.Pq Li "struct ioc_toc_header"
241Return summary information about the table of contents for the mounted
242.Tn CD-ROM .
243The information is returned into the following structure:
244.Bd -literal -offset indent
245struct ioc_toc_header {
246	u_short len;
247	u_char  starting_track;
248	u_char  ending_track;
249};
250.Ed
251.It Dv CDIOREADTOCENTRYS
252.Pq Li "struct ioc_read_toc_entry"
253Return information from the table of contents entries mentioned.
254.Pq Yes, this command name is misspelled.
255The argument structure is defined as follows:
256.Bd -literal -offset indent
257struct ioc_read_toc_entry {
258	u_char	address_format;
259	u_char	starting_track;
260	u_short	data_len;
261	struct  cd_toc_entry *data;
262};
263.Ed
264The requested data is written into an area of size
265.Li data_len
266and pointed to by
267.Li data .
268.It Dv CDIOCSETPATCH
269.Pq Li "struct ioc_patch"
270Attach various audio channels to various output channels.
271The argument structure is defined thusly:
272.Bd -literal -offset indent
273struct ioc_patch {
274	u_char	patch[4];
275	/* one for each channel */
276};
277.Ed
278.It Dv CDIOCGETVOL
279.It Dv CDIOCSETVOL
280.Pq Li "struct ioc_vol"
281Get (set) information about the volume settings of the output channels.
282The argument structure is as follows:
283.Bd -literal -offset indent
284struct	ioc_vol
285{
286	u_char	vol[4];
287	/* one for each channel */
288};
289.Ed
290.It Dv CDIOCSETMONO
291Patch all output channels to all source channels.
292.It Dv CDIOCSETSTEREO
293Patch left source channel to the left output channel and the right
294source channel to the right output channel.
295.It Dv CDIOCSETMUTE
296Mute output without changing the volume settings.
297.It Dv CDIOCSETLEFT
298.It Dv CDIOCSETRIGHT
299Attach both output channels to the left (right) source channel.
300.It Dv CDIOCSETDEBUG
301.It Dv CDIOCCLRDEBUG
302Turn on (off) debugging for the appropriate device.
303.It Dv CDIOCPAUSE
304.It Dv CDIOCRESUME
305Pause (resume) audio play, without resetting the location of the read-head.
306.It Dv CDIOCRESET
307Reset the drive.
308.It Dv CDIOCSTART
309.It Dv CDIOCSTOP
310Tell the drive to spin-up (-down) the
311.Tn CD-ROM .
312.It Dv CDIOCALLOW
313.It Dv CDIOCPREVENT
314Tell the drive to allow (prevent) manual ejection of the
315.Tn CD-ROM
316disc.
317Not all drives support this feature.
318.It Dv CDIOCEJECT
319Eject the
320.Tn CD-ROM .
321.It Dv CDIOCCLOSE
322Tell the drive to close its door and load the media.
323Not all drives support this feature.
324.It Dv CDIOCPITCH
325.Pq Li "struct ioc_pitch"
326For drives that support it, this command instructs the drive to play
327the audio at a faster or slower rate than normal.
328Values of
329.Li speed
330between -32767 and -1 result in slower playback; a zero value
331indicates normal speed; and values from 1 to 32767 give faster
332playback.
333Drives with less than 16 bits of resolution will silently
334ignore less-significant bits.
335The structure is defined thusly:
336.Bd -literal -offset indent
337struct	ioc_pitch
338{
339	short	speed;
340};
341.Ed
342.El
343.Sh NOTES
344When a
345.Tn CD-ROM
346is changed in a drive controlled by the
347.Nm
348driver, then the act of changing the media will invalidate the
349disklabel and information held within the kernel.
350To stop corruption,
351all accesses to the device will be discarded until there are no more
352open file descriptors referencing the device.
353During this period, all
354new open attempts will be rejected.
355When no more open file descriptors
356reference the device, the first next open will load a new set of
357parameters (including disklabel) for the drive.
358.Pp
359The audio code in the
360.Nm
361driver only support
362.Tn SCSI-2
363standard audio commands.
364As many
365.Tn CD-ROM
366manufacturers have not followed the standard, there are many
367.Tn CD-ROM
368drives for which audio will not work.
369Some work is planned to support
370some of the more common `broken'
371.Tn CD-ROM
372drives; however, this is not yet under way.
373.Sh CHANGER OPERATION
374This driver has built-in support for LUN-based CD changers.
375A LUN-based CD
376changer is a drive that can hold two or more CDs, but only has one CD
377player mechanism.
378Each CD in the drive shows up as a separate logical unit
379on the
380.Tn SCSI
381bus.
382The
383.Nm
384driver automatically recognizes LUN-based changers, and routes commands for
385changers through an internal scheduler.
386The scheduler prevents changer
387"thrashing", which is caused by sending commands to different LUNs in the
388changer at the same time.
389.Pp
390The scheduler honors minimum and maximum time
391quanta that the driver will spend on a particular LUN.
392The minimum time
393is the guaranteed minimum amount of time that the driver will spend on a
394given LUN, even if there is no outstanding I/O for that LUN.
395The maximum
396time is the maximum amount of time the changer will spend on a LUN if there
397is outstanding I/O for another LUN.
398If there is no outstanding I/O for
399another LUN, the driver will allow indefinite access to a given LUN.
400.Pp
401The minimum and maximum time quanta are configurable via kernel options and
402also via sysctl and kernel tunable variables.
403The kernel options are:
404.Pp
405.Bl -item -compact
406.It
407.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3"""
408.It
409.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11"""
410.El
411.Pp
412The sysctl/kernel tunable variables are:
413.Pp
414.Bl -item -compact
415.It
416.Va kern.cam.cd.changer.min_busy_seconds
417.It
418.Va kern.cam.cd.changer.max_busy_seconds
419.El
420.Pp
421It is suggested that the user try experimenting with the minimum and
422maximum timeouts via the sysctl variables to arrive at the proper values
423for your changer.
424Once you have settled on the proper timeouts for your
425changer, you can then put them in your kernel config file.
426.Pp
427If your system does have a LUN-based changer, you may notice that the
428probe messages for the various LUNs of the changer will continue to appear
429while the boot process is going on.
430This is normal, and is caused by the
431changer scheduling code.
432.Sh SYSCTL VARIABLES
433The following variables are available as both
434.Xr sysctl 8
435variables and
436.Xr loader 8
437tunables:
438.Bl -tag -width 12
439.It kern.cam.cd.retry_count
440.Pp
441This variable determines how many times the
442.Nm
443driver will retry a READ or WRITE command.
444This does not affect the number of retries used during probe time or for
445the
446.Nm
447driver dump routine.
448This value currently defaults to 4.
449.It kern.cam.cd.%d.minimum_cmd_size
450.Pp
451The
452.Nm
453driver attempts to automatically determine whether the drive it is talking
454to supports 6 byte or 10 byte MODE SENSE/MODE SELECT operations.
455Many
456.Tn SCSI
457drives only support 6 byte commands, and
458.Tn ATAPI
459drives only support 10 byte commands.
460The
461.Nm
462driver first attempts to determine whether the protocol in use typically
463supports 6 byte commands by issuing a CAM Path Inquiry CCB.
464It will then default to 6 byte or 10 byte commands as appropriate.
465After that, the
466.Nm
467driver defaults to using 6 byte commands (assuming the protocol the drive
468speaks claims to support 6 byte commands), until one fails with a
469.Tn SCSI
470ILLEGAL REQUEST error.
471Then it tries the 10 byte version of the command to
472see if that works instead.
473Users can change the default via per-drive
474sysctl variables and loader tunables.
475Where
476.Dq %d
477is the unit number of the drive in question.
478Valid minimum command sizes
479are 6 and 10.
480Any value above 6 will be rounded to 10, and any value below
4816 will be rounded to 6.
482.It kern.cam.cd.changer.min_busy_seconds
483.It kern.cam.cd.changer.max_busy_seconds
484.Pp
485Tune how long individual LUNs are 'locked' for I/O operations to
486optimize changer operation.
487See CHANGER OPERATION section for information on how to use these items.
488.El
489.Sh FILES
490.Bl -tag -width /dev/cd[0-9][a-h] -compact
491.It Pa /dev/cd[0-9][a-h]
492raw mode
493.Tn CD-ROM
494devices
495.El
496.Sh DIAGNOSTICS
497None.
498.Sh SEE ALSO
499.Xr cam 4 ,
500.Xr da 4 ,
501.Xr disklabel 5 ,
502.Xr disklabel 8 ,
503.Xr cd 9
504.Sh HISTORY
505This
506.Nm
507driver is based upon the
508.Nm
509driver written by Julian Elischer, which appeared in
510.Bx 386 0.1 .
511The
512CAM version of the
513.Nm
514driver was written by Kenneth Merry and first appeared in
515.Fx 3.0 .
516.Sh BUGS
517The names of the structures used for the third argument to
518.Fn ioctl
519were poorly chosen, and a number of spelling errors have survived in
520the names of the
521.Fn ioctl
522commands.
523.Pp
524There is no mechanism currently to set different minimum and maximum
525timeouts for different CD changers; the timeout values set by the kernel
526options or the sysctl variables apply to all LUN-based CD changers in the
527system.
528It is possible to implement such support, but the sysctl
529implementation at least would be rather inelegant, because of the current
530inability of the sysctl code to handle the addition of nodes after compile
531time.
532Thus, it would take one dynamically sized sysctl variable and a
533userland utility to get/set the timeout values.
534Implementation of separate
535timeouts for different CD devices in the kernel config file would likely
536require modification of
537.Xr config 8
538to support the two timeouts when hardwiring
539.Nm
540devices.
541