xref: /freebsd/sbin/camcontrol/camcontrol.8 (revision daf1cffce2e07931f27c6c6998652e90df6ba87e)
1.\"
2.\" Copyright (c) 1998, 1999 Kenneth D. Merry.
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
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.\" 3. The name of the author may not be used to endorse or promote products
14.\"    derived from this software without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\" $FreeBSD$
29.\"
30.Dd September 14, 1998
31.Dt CAMCONTROL 8
32.Os FreeBSD 3.0
33.Sh NAME
34.Nm camcontrol
35.Nd CAM control program
36.Sh SYNOPSIS
37.Nm camcontrol
38.Aq command
39.Op device id
40.Op generic args
41.Op command args
42.Nm camcontrol
43devlist
44.Op Fl v
45.Nm camcontrol
46periphlist
47.Op device id
48.Op Fl n Ar dev_name
49.Op Fl u Ar unit_number
50.Nm camcontrol
51tur
52.Op device id
53.Op generic args
54.Nm camcontrol
55inquiry
56.Op device id
57.Op generic args
58.Op Fl D
59.Op Fl S
60.Op Fl R
61.Nm camcontrol
62start
63.Op device id
64.Op generic args
65.Nm camcontrol
66stop
67.Op device id
68.Op generic args
69.Nm camcontrol
70eject
71.Op device id
72.Op generic args
73.Nm camcontrol
74rescan
75.Aq bus Ns Op :target:lun
76.Nm camcontrol
77reset
78.Aq bus Ns Op :target:lun
79.Nm camcontrol
80defects
81.Op device id
82.Op generic args
83.Aq Fl f Ar format
84.Op Fl P
85.Op Fl G
86.Nm camcontrol
87modepage
88.Op device id
89.Op generic args
90.Aq Fl m Ar page
91.Op Fl P Ar pgctl
92.Op Fl e
93.Op Fl d
94.Nm camcontrol
95cmd
96.Op device id
97.Op generic args
98.Aq Fl c Ar cmd Op args
99.Op Fl i Ar len Ar fmt
100.Bk -words
101.Op Fl o Ar len Ar fmt Op args
102.Ek
103.Nm camcontrol
104debug
105.Op Fl I
106.Op Fl T
107.Op Fl S
108.Op Fl c
109.Aq all|off|bus Ns Op :target Ns Op :lun
110.Nm camcontrol
111tags
112.Op device id
113.Op generic args
114.Op Fl N Ar tags
115.Op Fl q
116.Op Fl v
117.Nm camcontrol
118negotiate
119.Op device id
120.Op generic args
121.Op Fl c
122.Op Fl D Ar enable|disable
123.Op Fl O Ar offset
124.Op Fl q
125.Op Fl R Ar syncrate
126.Op Fl T Ar enable|disable
127.Op Fl U
128.Op Fl W Ar bus_width
129.Op Fl v
130.Nm camcontrol
131help
132.Sh DESCRIPTION
133.Nm camcontrol
134is a utility designed to provide a way for users to access and control the
135.Tn FreeBSD
136CAM subsystem.
137.Pp
138.Nm camcontrol
139can cause a loss of data and/or system crashes if used improperly.  Even
140expert users are encouraged to exercise caution when using this command.
141Novice users should stay away from this utility.
142.Pp
143.Nm camcontrol
144has a number of primary functions, many of which support an optional
145device identifier.  A device identifier can take one of three forms:
146.Bl -tag -width 01234567890123
147.It deviceUNIT
148Specify a device name and unit number combination, like "da5" or "cd3".
149Note that character device node names (e.g. /dev/rsd0.ctl) are
150.Em not
151allowed here.
152.It bus:target
153Specify a bus number and target id.  The bus number can be determined from
154the output of
155.Dq camcontrol devlist .
156The lun defaults to 0.
157.It bus:target:lun
158Specify the bus, target and lun for a device.  (e.g. 1:2:0)
159.El
160.Pp
161The device identifier, if it is specified,
162.Em must
163come immediately after the function name, and before any generic or
164function-specific arguments.  Note that the
165.Fl n
166and
167.Fl u
168arguments described below will override any device name or unit number
169specified beforehand.  The
170.Fl n
171and
172.Fl u
173arguments will
174.Em not
175override a specified bus:target or bus:target:lun, howevever.
176.Pp
177Most of the
178.Nm camcontrol
179primary functions support these generic arguments:
180.Bl -tag -width 01234567890123
181.It Fl C Ar count
182SCSI command retry count.  In order for this to work, error recovery
183.Po
184.Fl E
185.Pc
186must be turned on.
187.It Fl E
188Instruct the kernel to perform generic SCSI error recovery for the given
189command.  This is needed in order for the retry count
190.Po
191.Fl C
192.Pc
193to be honored.  Other than retrying commands, the generic error recovery in
194the code will generally attempt to spin up drives that are not spinning.
195It may take some other actions, depending upon the sense code returned from
196the command.
197.It Fl n Ar dev_name
198Specify the device type to operate on.  The default is
199.Em da .
200.It Fl t Ar timeout
201SCSI command timeout in seconds.  This overrides the default timeout for
202any given command.
203.It Fl u Ar unit_number
204Specify the device unit number.  The default is 0.
205.It Fl v
206Be verbose, print out sense information for failed SCSI commands.
207.El
208.Pp
209Primary command functions:
210.Bl -tag -width periphlist
211.It devlist
212List all physical devices (logical units) attached to the CAM subsystem.
213This also includes a list of peripheral drivers attached to each device.
214With the
215.Fl v
216argument, SCSI bus number, adapter name and unit numbers are printed as
217well.
218.It periphlist
219List all peripheral drivers attached to a given physical device (logical
220unit).
221.It tur
222Send the SCSI test unit ready (0x00) command to the given device.
223.Nm camcontrol
224will report whether the device is ready or not.
225.It inquiry
226Send a SCSI inquiry command (0x12) to a device.  By default,
227.Nm camcontrol
228will print out the standard inquiry data, device serial number, and
229transfer rate information.  The user can specify that only certain types of
230inquiry data be printed:
231.Bl -tag -width 1234
232.It Fl D
233Get the standard inquiry data.
234.It Fl S
235Print out the serial number.  If this flag is the only one specified,
236.Nm camcontrol
237will not print out "Serial Number" before the value returned by the drive.
238This is to aid in script writing.
239.It Fl R
240Print out transfer rate information.
241.El
242.It start
243Send the SCSI Start/Stop Unit (0x1B) command to the given device with the
244start bit set.
245.It stop
246Send the SCSI Start/Stop Unit (0x1B) command to the given device with the
247start bit cleared.
248.It eject
249Send the SCSI Start/Stop Unit (0x1B) command to the given device with the
250start bit cleared and the eject bit set.
251.It rescan
252Tell the kernel to scan the given bus (XPT_SCAN_BUS), or bus:target:lun
253(XPT_SCAN_LUN) for new devices or devices that have gone away.  The user
254may only specify a bus to scan, or a lun.  Scanning all luns on a target
255isn't supported.
256.It reset
257Tell the kernel to reset the given bus (XPT_RESET_BUS) by issuing a SCSI bus
258reset for that bus, or to reset the given bus:target:lun
259(XPT_RESET_DEV), typically by issuing a BUS DEVICE RESET message after
260connecting to that device. Note that this can have a destructive impact
261on the system.
262.It defects
263Send the SCSI READ DEFECT DATA (10) command (0x37) to the given device, and
264print out any combination of: the total number of defects, the primary
265defect list (PLIST), and the grown defect list (GLIST).
266.Bl -tag -width 01234567890
267.It Fl f Ar format
268The three format options are:
269.Em block ,
270to print out the list as logical blocks,
271.Em bfi ,
272to print out the list in bytes from index format, and
273.Em phys ,
274to print out the list in physical sector format.  The format argument is
275required.  Most drives support the physical sector format.  Some drives
276support the logical block format.  Many drives, if they don't support the
277requested format, return the data in an alternate format, along with sense
278information indicating that the requested data format isn't supported.
279.Nm camcontrol
280attempts to detect this, and print out whatever format the drive returns.
281If the drive uses a non-standard sense code to report that it doesn't
282support the requested format,
283.Nm camcontrol
284will probably see the error as a failure to complete the request.
285.It Fl G
286Print out the grown defect list.  This is a list of bad blocks that have
287been remapped since the disk left the factory.
288.It Fl P
289Print out the primary defect list.
290.El
291.Pp
292If neither
293.Fl P
294nor
295.Fl G
296is specified,
297.Nm camcontrol
298will print out the number of defects given in the READ DEFECT DATA header
299returned from the drive.
300.It modepage
301Allows the user to display and optionally edit a SCSI mode page.  The mode
302page formats are located in
303.Pa /usr/share/misc/scsi_modes .
304This can be overridden by specifying a different file in the
305.Ev SCSI_MODES
306environment variable.  The modepage command takes several arguments:
307.Bl -tag -width 012345678901
308.It Fl d
309Disable block descriptors for mode sense.
310.It Fl e
311This flag allows the user to edit values in the mode page.
312.It Fl m Ar mode_page
313This specifies the number of the mode page the user would like to view
314and/or edit.  This argument is mandatory.
315.It Fl P Ar pgctl
316This allows the user to specify the page control field.  Possible values are:
317.Bl -tag -width xxx -compact
318.It 0
319Current values
320.It 1
321Changeable values
322.It 2
323Default values
324.It 3
325Saved values
326.El
327.El
328.It cmd
329Allows the user to send an arbitrary SCSI CDB to any device.  The cmd
330function requires the
331.Fl c
332argument to specify the CDB.  Other arguments are optional, depending on
333the command type.  The command and data specification syntax is documented
334in
335.Xr cam 3 .
336NOTE:  If the CDB specified causes data to be transfered to or from the
337SCSI device in question, you MUST specify either
338.Fl i
339or
340.Fl o .
341.Bl -tag -width 01234567890123456
342.It Fl c Ar cmd Op args
343This specifies the SCSI CDB.  CDBs may be 6, 10, 12 or 16 bytes.
344.It Fl i Ar len Ar fmt
345This specifies the amount of data to read, and how it should be displayed.
346If the format is
347.Sq - ,
348.Ar len
349bytes of data will be read from the device and written to standard output.
350.It Fl o Ar len Ar fmt Op args
351This specifies the amount of data to be written to a device, and the data
352that is to be written.  If the format is
353.Sq - ,
354.Ar len
355bytes of data will be read from standard input and written to the device.
356.El
357.It debug
358Turn on CAM debugging printfs in the kernel.  This requires options CAMDEBUG
359in your kernel config file.  WARNING:  enabling debugging printfs currently
360causes an EXTREME number of kernel printfs.  You may have difficulty
361turning off the debugging printfs once they start, since the kernel will be
362busy printing messages and unable to service other requests quickly.
363The debug function takes a number of arguments:
364.Bl -tag -width 012345678901234567
365.It Fl I
366Enable CAM_DEBUG_INFO printfs.
367.It Fl T
368Enable CAM_DEBUG_TRACE printfs.
369.It Fl S
370Enable CAM_DEBUG_SUBTRACE printfs.
371.It Fl c
372Enable CAM_DEBUG_CDB printfs.  This will cause the kernel to print out the
373SCSI CDBs sent to the specified device(s).
374.It all
375Enable debugging for all devices.
376.It off
377Turn off debugging for all devices
378.It bus Ns Op :target Ns Op :lun
379Turn on debugging for the given bus, target or lun.  If the lun or target
380and lun are not specified, they are wildcarded.  (i.e., just specifying a
381bus turns on debugging printfs for all devices on that bus.)
382.El
383.It tags
384Show or set the number of "tagged openings" or simultaneous transactions
385we attempt to queue to a particular device.  By default, the
386.Sq tags
387command, with no command-specific arguments (i.e. only generic arguments)
388prints out the "soft" maximum number of transactions that can be queued to
389the device in question.  For more detailed information, use the
390.Fl v
391argument described below.
392.Bl -tag -width 0123456
393.It Fl N Ar tags
394Set the number of tags for the given device.  This must be between the
395minimum and maximum number set in the kernel quirk table.  The default for
396most devices that support tagged queueing is a minimum of 2 and a maximum
397of 255.  The minimum and maximum values for a given device may be
398determined by using the
399.Fl v
400switch.  The meaning of the
401.Fl v
402switch for this
403.Nm camcontrol
404subcommand is described below.
405.It Fl q
406Be quiet, and don't report the number of tags.  This is generally used when
407setting the number of tags.
408.It Fl v
409The verbose flag has special functionality for the
410.Em tags
411argument.  It causes
412.Nm camcontrol
413to print out the tagged queueing related fields of the XPT_GDEV_TYPE CCB:
414.Bl -tag -width 0123456789012
415.It dev_openings
416This is the amount of capacity for transactions queued to a given device.
417.It dev_active
418This is the number of transactions currently queued to a device.
419.It devq_openings
420This is the kernel queue space for transactions.  This count usually mirrors
421dev_openings except during error recovery operations when
422the device queue is frozen (device is not allowed to receive
423commands), the number of dev_openings is reduced, or transaction
424replay is occurring.
425.It devq_queued
426This is the number of transactions waiting in the kernel queue for capacity
427on the device.  This number is usually zero unless error recovery is in
428progress.
429.It held
430The held count is the number of CCBs held by peripheral drivers that have
431either just been completed or are about to be released to the transport
432layer for service by a device.  Held CCBs reserve capacity on a given
433device.
434.It mintags
435This is the current "hard" minimum number of transactions that can be
436queued to a device at once.  The
437.Ar dev_openings
438value above cannot go below this number.  The default value for
439.Ar mintags
440is 2, although it may be set higher or lower for various devices.
441.It maxtags
442This is the "hard" maximum number of transactions that can be queued to a
443device at one time.  The
444.Ar dev_openings
445value cannot go above this number.  The default value for
446.Ar maxtags
447is 255, although it may be set higher or lower for various devices.
448.El
449.El
450.It negotiate
451Show or negotiate various communication parameters.  Some controllers may
452not support setting or changing some of these values.  For instance, the
453Adaptec 174x controllers do not support changing a device's sync rate or
454offset.
455.Nm camcontrol
456will not attempt to set the parameter if the controller indicates that it
457does not support setting the parameter.  To find out what the controller
458supports, use the
459.Fl v
460flag.  The meaning of the
461.Fl v
462flag for the
463.Sq negotiate
464command is described below.  Also, some controller drivers don't support
465setting negotiation parameters, even if the underlying controller supports
466negotiation changes.  Some controllers, such as the Advansys wide
467controllers, support enabling and disabling synchronous negotiation for
468a device, but do not support setting the synchronous negotiation rate.
469.Bl -tag -width 01234567890123456
470.It Fl a
471Attempt to make the negotiation settings take effect immediately by sending
472a Test Unit Ready command to the device.
473.It Fl c
474Show or set current negotiation settings.  This is the default.
475.It Fl D Ar enable|disable
476Enable or disable disconnection.
477.It Fl O Ar offset
478Set the command delay offset.
479.It Fl q
480Be quiet, don't print anything.  This is generally useful when you want to
481set a parameter, but don't want any status information.
482.It Fl R Ar syncrate
483Change the synchronization rate for a device.  The sync rate is a floating
484point value specified in MHz.  So, for instance,
485.Sq 20.000
486is a legal value, as is
487.Sq 20 .
488.It Fl T Ar enable|disable
489Enable or disable tagged queueing for a device.
490.It Fl U
491Show or set user negotiation settings.  The default is to show or set
492current negotiation settings.
493.It Fl v
494The verbose switch has special meaning for the
495.Sq negotiate
496subcommand.  It causes
497.Nm camcontrol
498to print out the contents of a Path Inquiry (XPT_PATH_INQ) CCB sent to the
499controller driver.
500.It Fl W Ar bus_width
501Specify the bus width to negotiate with a device.  The bus width is
502specified in bits.  The only useful values to specify are 8, 16, and 32
503bits.  The controller must support the bus width in question in order for
504the setting to take effect.
505.El
506.Pp
507In general, sync rate and offset settings will not take effect for a
508device until a command has been sent to the device.  The
509.Fl a
510switch above will automatically send a Test Unit Ready to the device so
511negotiation parameters will take effect.
512.It help
513Print out verbose usage information.
514.El
515.Sh ENVIRONMENT
516The
517.Ev SCSI_MODES
518variable allows the user to specify an alternate mode page format file.
519.Pp
520The
521.Ev EDITOR
522variable determines which text editor
523.Nm camcontrol
524starts when editing mode pages.
525.Sh FILES
526.Bl -tag -width /usr/share/misc/scsi_modes -compact
527.It Pa /usr/share/misc/scsi_modes
528is the SCSI mode format database.
529.It Pa /dev/xpt0
530is the transport layer device.
531.It Pa /dev/pass*
532are the CAM application passthrough devices.
533.El
534.Sh EXAMPLES
535.Dl camcontrol eject -n cd -u 1 -v
536.Pp
537Eject the CD from cd1, and print SCSI sense information if the command
538fails.
539.Pp
540.Dl camcontrol tur
541.Pp
542Send the SCSI test unit ready command to da0.
543.Nm camcontrol
544will report whether the disk is ready, but will not display sense
545information if the command fails since the
546.Fl v
547switch was not specified.
548.Pp
549.Bd -literal -offset foobar
550camcontrol tur da1 -E -C 4 -t 50 -v
551.Ed
552.Pp
553Send a test unit ready command to da1.  Enable kernel error recovery.
554Specify a retry count of 4, and a timeout of 50 seconds.  Enable sense
555printing (with the
556.Fl v
557flag) if the command fails.  Since error recovery is turned on, the
558disk will be spun up if it is not currently spinning.
559.Nm camcontrol
560will report whether the disk is ready.
561.Bd -literal -offset foobar
562camcontrol cmd -n cd -u 1 -v -c "3C 00 00 00 00 00 00 00 0e 00" \e
563	-i 0xe "s1 i3 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1"
564.Ed
565.Pp
566Issue a READ BUFFER command (0x3C) to cd1.  Display the buffer size of cd1,
567and display the first 10 bytes from the cache on cd1.  Display SCSI sense
568information if the command fails.
569.Pp
570.Bd -literal -offset foobar
571camcontrol cmd -n cd -u 1 -v -c "3B 00 00 00 00 00 00 00 0e 00" \e
572	-o 14 "00 00 00 00 1 2 3 4 5 6 v v v v" 7 8 9 8
573.Ed
574.Pp
575Issue a WRITE BUFFER (0x3B) command to cd1.  Write out 10 bytes of data,
576not including the (reserved) 4 byte header.  Print out sense information if
577the command fails.  Be very careful with this command, improper use may
578cause data corruption.
579.Pp
580.Bd -literal -offset foobar
581camcontrol modepage da3 -m 1 -e -P 3
582.Ed
583.Pp
584Edit mode page 1 (the Read-Write Error Recover page) for da3, and save the
585settings on the drive.  Mode page 1 contains a disk drive's auto read and
586write reallocation settings, among other things.
587.Pp
588.Dl camcontrol rescan 0
589.Pp
590Rescan SCSI bus 0 for devices that have been added, removed or changed.
591.Pp
592.Dl camcontrol rescan 0:1:0
593.Pp
594Rescan SCSI bus 0, target 1, lun 0 to see if it has been added, removed, or
595changed.
596.Pp
597.Dl camcontrol tags da5 -N 24
598.Pp
599Set the number of concurrent transactions for da5 to 24.
600.Pp
601.Bd -literal -offset foobar
602camcontrol negotiate -n da -u 4 -T disable
603.Ed
604.Pp
605Disable tagged queueing for da4.
606.Pp
607.Bd -literal -offset foobar
608camcontrol negotiate -n da -u 3 -R 20.000 -O 15 -a
609.Ed
610.Pp
611Negotiate a sync rate of 20MHz and an offset of 15 with da3.  Then send a
612Test Unit Ready command to make the settings take effect.
613.Pp
614.Bd -literal -offset foobar
615camcontrol cmd -n da -u 3 -v -t 7200 -c "4 0 0 0 0 0"
616.Ed
617.Pp
618Send the FORMAT UNIT (0x04) command to da3.  This will low-level format the
619disk.  Print sense information if the command fails, and set the timeout to
620two hours (or 7200 seconds).
621.Pp
622.Em WARNING! WARNING! WARNING!
623.Pp
624Low level formatting a disk will destroy ALL data on the disk.  Use
625extreme caution when issuing this command.  Many users low-level format
626disks that do not really need to be low-level formatted.  There are
627relatively few scenarios that call for low-level formatting a disk.
628One reason for
629low-level formatting a disk is if you want to change the physical sector
630size of the disk.  Another reason for low-level formatting a disk is to
631revive the disk if you are getting "medium format corrupted" errors from the
632disk in response to read and write requests.
633.Pp
634Some disks take longer than others to format.  Users should specify a
635timeout long enough to allow the format to complete.  Some hard disks
636will complete a format operation in a very short period of time (on the
637order of 5 minutes or less).  This is often because the drive doesn't
638really support the FORMAT UNIT command -- it just accepts the command,
639waits a few minutes and then returns it.
640.Sh SEE ALSO
641.Xr cam 3 ,
642.Xr cam_cdbparse 3 ,
643.Xr cam 4 ,
644.Xr pass 4 ,
645.Xr xpt 4
646.Sh HISTORY
647The
648.Nm camcontrol
649command first appeared in
650.Fx 3.0 .
651.Pp
652The mode page editing code and arbitrary SCSI command code are based upon
653code in the old
654.Xr scsi 8
655utility and
656.Xr scsi 3
657library, written by Julian Elischer and Peter Dufault.  The
658.Xr scsi 8
659program first appeared in 386BSD 0.1.2.4, and first appeared in
660.Tn FreeBSD
661in
662.Fx 2.0.5 .
663.Sh AUTHORS
664.An Kenneth Merry Aq ken@FreeBSD.org
665.Sh BUGS
666The code that parses the generic command line arguments doesn't know that
667some of the subcommands take multiple arguments.  So if, for instance, you
668tried something like this:
669.Bd -literal -offset foobar
670camcontrol cmd -n da -u 1 -c "00 00 00 00 00 v" 0x00 -v
671.Ed
672.Pp
673The sense information from the test unit ready command would not get
674printed out, since the first
675.Xr getopt 3
676call in
677.Nm camcontrol
678bails out when it sees the second argument to
679.Fl c
680.Po
6810x00
682.Pc ,
683above.  Fixing this behavior would take some gross code, or changes to the
684.Xr getopt 3
685interface.  The best way to circumvent this problem is to always make sure
686to specify generic
687.Nm camcontrol
688arguments before any command-specific arguments.
689