1.\" 2.\" Copyright (c) 1998 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.\" $Id: camcontrol.8,v 1.6 1998/10/03 19:15:53 ken Exp $ 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 generic args 40.Op command args 41.Nm camcontrol 42devlist 43.Op Fl v 44.Nm camcontrol 45periphlist 46.Op Fl n Ar dev_name 47.Op Fl u Ar unit_number 48.Nm camcontrol 49tur 50.Op generic args 51.Nm camcontrol 52inquiry 53.Op generic args 54.Op Fl D 55.Op Fl S 56.Op Fl R 57.Nm camcontrol 58start 59.Op generic args 60.Nm camcontrol 61stop 62.Op generic args 63.Nm camcontrol 64eject 65.Op generic args 66.Nm camcontrol 67rescan 68.Aq bus Ns Op :target:lun 69.Nm camcontrol 70defects 71.Op generic args 72.Aq Fl f Ar format 73.Op Fl P 74.Op Fl G 75.Nm camcontrol 76modepage 77.Op generic args 78.Aq Fl m Ar page 79.Op Fl P Ar pagectl 80.Op Fl e 81.Op Fl d 82.Nm camcontrol 83cmd 84.Op generic args 85.Aq Fl c Ar cmd Op args 86.Op Fl i Ar len Ar fmt 87.Bk -words 88.Op Fl o Ar len Ar fmt Op args 89.Ek 90.Nm camcontrol 91debug 92.Op Fl I 93.Op Fl T 94.Op Fl S 95.Op Fl c 96.Aq all|off|bus Ns Op :target Ns Op :lun 97.Sh DESCRIPTION 98.Nm camcontrol 99is a utility designed to provide a way for users to access and control the 100.Tn FreeBSD 101CAM subsystem. 102.Pp 103.Nm camcontrol 104can cause a loss of data and/or system crashes if used improperly. Even 105expert users are encouraged to excercise caution when using this command. 106Novice users should stay away from this utility. 107.Pp 108.Nm camcontrol 109has a number of primary functions, most of which take some generic 110arguments: 111.Bl -tag -width 01234567890123 112.It Fl C Ar count 113SCSI command retry count. In order for this to work, error recovery 114.Po 115.Fl E 116.Pc 117must be turned on. 118.It Fl E 119Instruct the kernel to perform generic SCSI error recovery for the given 120command. This is needed in order for the retry count 121.Po 122.Fl C 123.Pc 124to be honored. Other than retrying commands, the generic error recovery in 125the code will generally attempt to spin up drives that are not spinning. 126It may take some other actions, depending upon the sense code returned from 127the command. 128.It Fl n Ar dev_name 129Specify the device type to operate on. The default is 130.Em da . 131.It Fl t Ar timeout 132SCSI command timeout in seconds. This overrides the default timeout for 133any given command. 134.It Fl u Ar unit_number 135Specify the device unit number. The default is 0. 136.It Fl v 137Be verbose, print out sense information for failed SCSI commands. 138.El 139.Pp 140Primary command functions: 141.Bl -tag -width periphlist 142.It devlist 143List all physical devices (logical units) attached to the CAM subsystem. 144This also includes a list of peripheral drivers attached to each device. 145With the 146.Fl v 147argument, SCSI bus number, adapter name and unit numbers are printed as 148well. 149.It periphlist 150List all peripheral drivers attached to a given physical device (logical 151unit). 152.It tur 153Send the SCSI test unit ready (0x00) command to the given device. 154.Nm camcontrol 155will report whether the device is ready or not. 156.It inquiry 157Send a SCSI inquiry command (0x12) to a device. By default, 158.Nm camcontrol 159will print out the standard inquiry data, device serial number, and 160transfer rate information. The user can specify that only certain types of 161inquiry data be printed: 162.Bl -tag -width 1234 163.It Fl D 164Get the standard inquiry data. 165.It Fl S 166Print out the serial number. If this flag is the only one specified, 167.Nm camcontrol 168will not print out "Serial Number" before the value returned by the drive. 169This is to aid in script writing. 170.It Fl R 171Print out transfer rate information. 172.El 173.It start 174Send the SCSI Start/Stop Unit (0x1B) command to the given device with the 175start bit set. 176.It stop 177Send the SCSI Start/Stop Unit (0x1B) command to the given device with the 178start bit cleared. 179.It eject 180Send the SCSI Start/Stop Unit (0x1B) command to the given device with the 181start bit cleared and the eject bit set. 182.It rescan 183Tell the kernel to scan the given bus (XPT_SCAN_BUS), or bus:target:lun 184(XPT_SCAN_LUN) for new devices or devices that have gone away. The user 185may only specify a bus to scan, or a lun. Scanning all luns on a target 186isn't supported. 187.It defects 188Send the SCSI READ DEFECT DATA (10) command (0x37) to the given device, and 189print out any combination of: the total number of defects, the primary 190defect list (PLIST), and the grown defect list (GLIST). 191.Bl -tag -width 01234567890 192.It Fl f Ar format 193The three format options are: 194.Em block , 195to print out the list as logical blocks, 196.Em bfi , 197to print out the list in bytes from index format, and 198.Em phys , 199to print out the list in physical sector format. The format argument is 200required. Most drives support the physical sector format. Some drives 201support the logical block format. Many drives, if they don't support the 202requested format, return the data in an alternate format, along with sense 203information indicating that the requested data format isn't supported. 204.Nm camcontrol 205attempts to detect this, and print out whatever format the drive returns. 206If the drive uses a non-standard sense code to report that it doesn't 207support the requested format, 208.Nm camcontrol 209will probably see the error as a failure to complete the request. 210.It Fl G 211Print out the grown defect list. This is a list of bad blocks that have 212been remapped since the disk left the factory. 213.It Fl P 214Print out the primary defect list. 215.El 216.Pp 217If neither 218.Fl P 219nor 220.Fl G 221is specified, 222.Nm camcontrol 223will print out the number of defects given in the READ DEFECT DATA header 224returned from the drive. 225.It modepage 226Allows the user to display and optionally edit a SCSI mode page. The mode 227page formats are located in 228.Pa /usr/share/misc/scsi_modes . 229This can be overridden by specifying a different file in the 230.Ev SCSI_MODES 231environment variable. The modepage command takes several arguments: 232.Bl -tag -width 012345678901 233.It Fl B 234Disable block descriptors for mode sense. 235.It Fl e 236This flag allows the user to edit values in the mode page. 237.It Fl m Ar mode_page 238This specifies the number of the mode page the user would like to view 239and/or edit. This argument is mandatory. 240.It Fl P page_ctl 241This allows the user to specify the page control field. Possible values are: 242.Bl -tag -width xxx -compact 243.It 0 244Current values 245.It 1 246Changeable values 247.It 2 248Default values 249.It 3 250Saved values 251.El 252.El 253.It cmd 254Allows the user to send an arbitrary SCSI CDB to any device. The cmd 255function requires the 256.Fl c 257argument to specify the CDB. Other arguments are optional, depending on 258the command type. The command and data specification syntax is documented 259in 260.Xr cam 3 . 261NOTE: If the CDB specified causes data to be transfered to or from the 262SCSI device in question, you MUST specify either 263.Fl i 264or 265.Fl o . 266.Bl -tag -width 01234567890123456 267.It Fl c Ar cmd Op args 268This specifies the SCSI CDB. CDBs may be 6, 10, 12 or 16 bytes. 269.It Fl i Ar len Ar fmt 270This specifies the amount of data to read, and how it should be displayed. 271If the format is 272.Sq - , 273.Ar len 274bytes of data will be read from the device and written to standard output. 275.It Fl o Ar len Ar fmt Op args 276This specifies the amount of data to be written to a device, and the data 277that is to be written. If the format is 278.Sq - , 279.Ar len 280bytes of data will be read from standard input and written to the device. 281.El 282.It debug 283Turn on CAM debugging printfs in the kernel. This requires options CAMDEBUG 284in your kernel config file. WARNING: enabling debugging printfs currently 285causes an EXTREME number of kernel printfs. You may have difficulty 286turning off the debugging printfs once they start, since the kernel will be 287busy printing messages and unable to service other requests quickly. 288The debug function takes a number of arguments: 289.Bl -tag -width 012345678901234567 290.It Fl I 291Enable CAM_DEBUG_INFO printfs. 292.It Fl T 293Enable CAM_DEBUG_TRACE printfs. 294.It Fl S 295Enable CAM_DEBUG_SUBTRACE printfs. 296.It Fl c 297Enable CAM_DEBUG_CDB printfs. This will cause the kernel to print out the 298SCSI CDBs sent to the specified device(s). 299.It all 300Enable debugging for all devices. 301.It off 302Turn off debugging for all devices 303.It bus Ns Op :target Ns Op :lun 304Turn on debugging for the given bus, target or lun. If the lun or target 305and lun are not specified, they are wildcarded. (i.e., just specifying a 306bus turns on debugging printfs for all devices on that bus.) 307.El 308.El 309.Sh ENVIRONMENT 310The 311.Ev SCSI_MODES 312variable allows the user to specify an alternate mode page format file. 313.Pp 314The 315.Ev EDITOR 316variable determines which text editor 317.Nm camcontrol 318starts when editing mode pages. 319.Sh FILES 320.Bl -tag -width /usr/share/misc/scsi_modes -compact 321.It Pa /usr/share/misc/scsi_modes 322is the SCSI mode format database. 323.It Pa /dev/xpt0 324is the transport layer device. 325.It Pa /dev/pass* 326are the CAM application passthrough devices. 327.El 328.Sh EXAMPLES 329.Dl camcontrol eject -n cd -u 1 -v 330.Pp 331Eject the CD from cd1, and print SCSI sense information if the command 332fails. 333.Pp 334.Dl camcontrol tur 335.Pp 336Send the SCSI test unit ready command to da0. 337.Nm camcontrol 338will report whether the disk is ready, but will not display sense 339information if the command fails since the 340.Fl v 341switch was not specified. 342.Pp 343.Bd -literal -offset foobar 344camcontrol tur -n da -u 1 -E -C 4 -t 50 -v 345.Ed 346.Pp 347Send a test unit ready command to da1. Enable kernel error recovery. 348Specify a retry count of 4, and a timeout of 50 seconds. Enable sense 349printing (with the 350.Fl v 351flag) if the command fails. Since error recovery is turned on, the 352disk will be spun up if it is not currently spinning. 353.Nm camcontrol 354will report whether the disk is ready. 355.Bd -literal -offset foobar 356camcontrol cmd -n cd -u 1 -v -c "3C 00 00 00 00 00 00 00 0e 00" \e 357 -i 0xe "s1 i3 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1" 358.Ed 359.Pp 360Issue a READ BUFFER command (0x3C) to cd1. Display the buffer size of cd1, 361and display the first 10 bytes from the cache on cd1. Display SCSI sense 362information if the command fails. 363.Pp 364.Bd -literal -offset foobar 365camcontrol cmd -n cd -u u -v -c "3B 00 00 00 00 00 00 00 0e 00" \e 366 -o 14 "00 00 00 00 1 2 3 4 5 6 v v v v" 7 8 9 8 367.Ed 368.Pp 369Issue a WRITE BUFFER (0x3B) command to cd1. Write out 10 bytes of data, 370not including the (reserved) 4 byte header. Print out sense information if 371the command fails. Be very careful with this command, improper use may 372cause data corruption. 373.Pp 374.Bd -literal -offset foobar 375camcontrol modepage -n da -u 3 -m 1 -e -P 3 376.Ed 377.Pp 378Edit mode page 1 (the Read-Write Error Recover page) for da3, and save the 379settings on the drive. Mode page 1 contains a disk drive's auto read and 380write reallocation settings, among other things. 381.Pp 382.Dl camcontrol rescan 0 383.Pp 384Rescan SCSI bus 0 for devices that have been added, removed or changed. 385.Pp 386.Dl camcontrol rescan 0:1:0 387.Pp 388Rescan SCSI bus 0, target 1, lun 0 to see if it has been added, removed, or 389changed. 390.Sh SEE ALSO 391.Xr cam 3 , 392.Xr pass 4 , 393.Xr cam 9 , 394.Xr xpt 9 395.Sh HISTORY 396The 397.Nm camcontrol 398command first appeared in 399.Fx 3.0 . 400.Pp 401The mode page editing code and arbitrary SCSI command code are based upon 402code in the old 403.Xr scsi 8 404utility and 405.Xr scsi 3 406library, written by Julian Ellischer and Peter Dufault. The 407.Xr scsi 8 408program first appeared in 386BSD 0.1.2.4, and first appeared in 409.Tn FreeBSD 410in 411.Fx 2.0.5 . 412.Sh AUTHORS 413.An Kenneth Merry Aq ken@FreeBSD.ORG 414.Sh BUGS 415Most of the man page cross references don't exist yet. This will be fixed 416soon. 417.Pp 418The code that parses the generic command line arguments doesn't know that 419some of the subcommands take multiple arguments. So if, for instance, you 420tried something like this: 421.Bd -literal -offset foobar 422camcontrol -n da -u 1 -c "00 00 00 00 00 v" 0x00 -v 423.Ed 424.Pp 425The sense information from the test unit ready command would not get 426printed out, since the first 427.Xr getopt 3 428call in 429.Nm camcontrol 430bails out when it sees the second argument to 431.Fl c 432.Po 4330x00 434.Pc , 435above. Fixing this behavior would take some gross code, or changes to the 436.Xr getopt 3 437interface. The best way to circumvent this problem is to always make sure 438to specify generic 439.Nm camcontrol 440arguments before any command-specific arguments. 441.Pp 442It might be nice to add a way to allow users to specify devices by 443bus/target/lun or by device string (e.g. "da1"). 444