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. 261Note that this can have a destructive impact 262on the system. 263.It defects 264Send the SCSI READ DEFECT DATA (10) command (0x37) to the given device, and 265print out any combination of: the total number of defects, the primary 266defect list (PLIST), and the grown defect list (GLIST). 267.Bl -tag -width 01234567890 268.It Fl f Ar format 269The three format options are: 270.Em block , 271to print out the list as logical blocks, 272.Em bfi , 273to print out the list in bytes from index format, and 274.Em phys , 275to print out the list in physical sector format. The format argument is 276required. Most drives support the physical sector format. Some drives 277support the logical block format. Many drives, if they don't support the 278requested format, return the data in an alternate format, along with sense 279information indicating that the requested data format isn't supported. 280.Nm camcontrol 281attempts to detect this, and print out whatever format the drive returns. 282If the drive uses a non-standard sense code to report that it doesn't 283support the requested format, 284.Nm camcontrol 285will probably see the error as a failure to complete the request. 286.It Fl G 287Print out the grown defect list. This is a list of bad blocks that have 288been remapped since the disk left the factory. 289.It Fl P 290Print out the primary defect list. 291.El 292.Pp 293If neither 294.Fl P 295nor 296.Fl G 297is specified, 298.Nm camcontrol 299will print out the number of defects given in the READ DEFECT DATA header 300returned from the drive. 301.It modepage 302Allows the user to display and optionally edit a SCSI mode page. The mode 303page formats are located in 304.Pa /usr/share/misc/scsi_modes . 305This can be overridden by specifying a different file in the 306.Ev SCSI_MODES 307environment variable. The modepage command takes several arguments: 308.Bl -tag -width 012345678901 309.It Fl d 310Disable block descriptors for mode sense. 311.It Fl e 312This flag allows the user to edit values in the mode page. 313.It Fl m Ar mode_page 314This specifies the number of the mode page the user would like to view 315and/or edit. This argument is mandatory. 316.It Fl P Ar pgctl 317This allows the user to specify the page control field. Possible values are: 318.Bl -tag -width xxx -compact 319.It 0 320Current values 321.It 1 322Changeable values 323.It 2 324Default values 325.It 3 326Saved values 327.El 328.El 329.It cmd 330Allows the user to send an arbitrary SCSI CDB to any device. The cmd 331function requires the 332.Fl c 333argument to specify the CDB. Other arguments are optional, depending on 334the command type. The command and data specification syntax is documented 335in 336.Xr cam 3 . 337NOTE: If the CDB specified causes data to be transfered to or from the 338SCSI device in question, you MUST specify either 339.Fl i 340or 341.Fl o . 342.Bl -tag -width 01234567890123456 343.It Fl c Ar cmd Op args 344This specifies the SCSI CDB. CDBs may be 6, 10, 12 or 16 bytes. 345.It Fl i Ar len Ar fmt 346This specifies the amount of data to read, and how it should be displayed. 347If the format is 348.Sq - , 349.Ar len 350bytes of data will be read from the device and written to standard output. 351.It Fl o Ar len Ar fmt Op args 352This specifies the amount of data to be written to a device, and the data 353that is to be written. If the format is 354.Sq - , 355.Ar len 356bytes of data will be read from standard input and written to the device. 357.El 358.It debug 359Turn on CAM debugging printfs in the kernel. This requires options CAMDEBUG 360in your kernel config file. WARNING: enabling debugging printfs currently 361causes an EXTREME number of kernel printfs. You may have difficulty 362turning off the debugging printfs once they start, since the kernel will be 363busy printing messages and unable to service other requests quickly. 364The debug function takes a number of arguments: 365.Bl -tag -width 012345678901234567 366.It Fl I 367Enable CAM_DEBUG_INFO printfs. 368.It Fl T 369Enable CAM_DEBUG_TRACE printfs. 370.It Fl S 371Enable CAM_DEBUG_SUBTRACE printfs. 372.It Fl c 373Enable CAM_DEBUG_CDB printfs. This will cause the kernel to print out the 374SCSI CDBs sent to the specified device(s). 375.It all 376Enable debugging for all devices. 377.It off 378Turn off debugging for all devices 379.It bus Ns Op :target Ns Op :lun 380Turn on debugging for the given bus, target or lun. If the lun or target 381and lun are not specified, they are wildcarded. (i.e., just specifying a 382bus turns on debugging printfs for all devices on that bus.) 383.El 384.It tags 385Show or set the number of "tagged openings" or simultaneous transactions 386we attempt to queue to a particular device. By default, the 387.Sq tags 388command, with no command-specific arguments (i.e. only generic arguments) 389prints out the "soft" maximum number of transactions that can be queued to 390the device in question. For more detailed information, use the 391.Fl v 392argument described below. 393.Bl -tag -width 0123456 394.It Fl N Ar tags 395Set the number of tags for the given device. This must be between the 396minimum and maximum number set in the kernel quirk table. The default for 397most devices that support tagged queueing is a minimum of 2 and a maximum 398of 255. The minimum and maximum values for a given device may be 399determined by using the 400.Fl v 401switch. The meaning of the 402.Fl v 403switch for this 404.Nm camcontrol 405subcommand is described below. 406.It Fl q 407Be quiet, and don't report the number of tags. This is generally used when 408setting the number of tags. 409.It Fl v 410The verbose flag has special functionality for the 411.Em tags 412argument. It causes 413.Nm camcontrol 414to print out the tagged queueing related fields of the XPT_GDEV_TYPE CCB: 415.Bl -tag -width 0123456789012 416.It dev_openings 417This is the amount of capacity for transactions queued to a given device. 418.It dev_active 419This is the number of transactions currently queued to a device. 420.It devq_openings 421This is the kernel queue space for transactions. This count usually mirrors 422dev_openings except during error recovery operations when 423the device queue is frozen (device is not allowed to receive 424commands), the number of dev_openings is reduced, or transaction 425replay is occurring. 426.It devq_queued 427This is the number of transactions waiting in the kernel queue for capacity 428on the device. This number is usually zero unless error recovery is in 429progress. 430.It held 431The held count is the number of CCBs held by peripheral drivers that have 432either just been completed or are about to be released to the transport 433layer for service by a device. Held CCBs reserve capacity on a given 434device. 435.It mintags 436This is the current "hard" minimum number of transactions that can be 437queued to a device at once. The 438.Ar dev_openings 439value above cannot go below this number. The default value for 440.Ar mintags 441is 2, although it may be set higher or lower for various devices. 442.It maxtags 443This is the "hard" maximum number of transactions that can be queued to a 444device at one time. The 445.Ar dev_openings 446value cannot go above this number. The default value for 447.Ar maxtags 448is 255, although it may be set higher or lower for various devices. 449.El 450.El 451.It negotiate 452Show or negotiate various communication parameters. Some controllers may 453not support setting or changing some of these values. For instance, the 454Adaptec 174x controllers do not support changing a device's sync rate or 455offset. 456.Nm camcontrol 457will not attempt to set the parameter if the controller indicates that it 458does not support setting the parameter. To find out what the controller 459supports, use the 460.Fl v 461flag. The meaning of the 462.Fl v 463flag for the 464.Sq negotiate 465command is described below. Also, some controller drivers don't support 466setting negotiation parameters, even if the underlying controller supports 467negotiation changes. Some controllers, such as the Advansys wide 468controllers, support enabling and disabling synchronous negotiation for 469a device, but do not support setting the synchronous negotiation rate. 470.Bl -tag -width 01234567890123456 471.It Fl a 472Attempt to make the negotiation settings take effect immediately by sending 473a Test Unit Ready command to the device. 474.It Fl c 475Show or set current negotiation settings. This is the default. 476.It Fl D Ar enable|disable 477Enable or disable disconnection. 478.It Fl O Ar offset 479Set the command delay offset. 480.It Fl q 481Be quiet, don't print anything. This is generally useful when you want to 482set a parameter, but don't want any status information. 483.It Fl R Ar syncrate 484Change the synchronization rate for a device. The sync rate is a floating 485point value specified in MHz. So, for instance, 486.Sq 20.000 487is a legal value, as is 488.Sq 20 . 489.It Fl T Ar enable|disable 490Enable or disable tagged queueing for a device. 491.It Fl U 492Show or set user negotiation settings. The default is to show or set 493current negotiation settings. 494.It Fl v 495The verbose switch has special meaning for the 496.Sq negotiate 497subcommand. It causes 498.Nm camcontrol 499to print out the contents of a Path Inquiry (XPT_PATH_INQ) CCB sent to the 500controller driver. 501.It Fl W Ar bus_width 502Specify the bus width to negotiate with a device. The bus width is 503specified in bits. The only useful values to specify are 8, 16, and 32 504bits. The controller must support the bus width in question in order for 505the setting to take effect. 506.El 507.Pp 508In general, sync rate and offset settings will not take effect for a 509device until a command has been sent to the device. The 510.Fl a 511switch above will automatically send a Test Unit Ready to the device so 512negotiation parameters will take effect. 513.It help 514Print out verbose usage information. 515.El 516.Sh ENVIRONMENT 517The 518.Ev SCSI_MODES 519variable allows the user to specify an alternate mode page format file. 520.Pp 521The 522.Ev EDITOR 523variable determines which text editor 524.Nm camcontrol 525starts when editing mode pages. 526.Sh FILES 527.Bl -tag -width /usr/share/misc/scsi_modes -compact 528.It Pa /usr/share/misc/scsi_modes 529is the SCSI mode format database. 530.It Pa /dev/xpt0 531is the transport layer device. 532.It Pa /dev/pass* 533are the CAM application passthrough devices. 534.El 535.Sh EXAMPLES 536.Dl camcontrol eject -n cd -u 1 -v 537.Pp 538Eject the CD from cd1, and print SCSI sense information if the command 539fails. 540.Pp 541.Dl camcontrol tur 542.Pp 543Send the SCSI test unit ready command to da0. 544.Nm camcontrol 545will report whether the disk is ready, but will not display sense 546information if the command fails since the 547.Fl v 548switch was not specified. 549.Pp 550.Bd -literal -offset foobar 551camcontrol tur da1 -E -C 4 -t 50 -v 552.Ed 553.Pp 554Send a test unit ready command to da1. Enable kernel error recovery. 555Specify a retry count of 4, and a timeout of 50 seconds. Enable sense 556printing (with the 557.Fl v 558flag) if the command fails. Since error recovery is turned on, the 559disk will be spun up if it is not currently spinning. 560.Nm camcontrol 561will report whether the disk is ready. 562.Bd -literal -offset foobar 563camcontrol cmd -n cd -u 1 -v -c "3C 00 00 00 00 00 00 00 0e 00" \e 564 -i 0xe "s1 i3 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1" 565.Ed 566.Pp 567Issue a READ BUFFER command (0x3C) to cd1. Display the buffer size of cd1, 568and display the first 10 bytes from the cache on cd1. Display SCSI sense 569information if the command fails. 570.Pp 571.Bd -literal -offset foobar 572camcontrol cmd -n cd -u 1 -v -c "3B 00 00 00 00 00 00 00 0e 00" \e 573 -o 14 "00 00 00 00 1 2 3 4 5 6 v v v v" 7 8 9 8 574.Ed 575.Pp 576Issue a WRITE BUFFER (0x3B) command to cd1. Write out 10 bytes of data, 577not including the (reserved) 4 byte header. Print out sense information if 578the command fails. Be very careful with this command, improper use may 579cause data corruption. 580.Pp 581.Bd -literal -offset foobar 582camcontrol modepage da3 -m 1 -e -P 3 583.Ed 584.Pp 585Edit mode page 1 (the Read-Write Error Recover page) for da3, and save the 586settings on the drive. Mode page 1 contains a disk drive's auto read and 587write reallocation settings, among other things. 588.Pp 589.Dl camcontrol rescan 0 590.Pp 591Rescan SCSI bus 0 for devices that have been added, removed or changed. 592.Pp 593.Dl camcontrol rescan 0:1:0 594.Pp 595Rescan SCSI bus 0, target 1, lun 0 to see if it has been added, removed, or 596changed. 597.Pp 598.Dl camcontrol tags da5 -N 24 599.Pp 600Set the number of concurrent transactions for da5 to 24. 601.Pp 602.Bd -literal -offset foobar 603camcontrol negotiate -n da -u 4 -T disable 604.Ed 605.Pp 606Disable tagged queueing for da4. 607.Pp 608.Bd -literal -offset foobar 609camcontrol negotiate -n da -u 3 -R 20.000 -O 15 -a 610.Ed 611.Pp 612Negotiate a sync rate of 20MHz and an offset of 15 with da3. Then send a 613Test Unit Ready command to make the settings take effect. 614.Pp 615.Bd -literal -offset foobar 616camcontrol cmd -n da -u 3 -v -t 7200 -c "4 0 0 0 0 0" 617.Ed 618.Pp 619Send the FORMAT UNIT (0x04) command to da3. This will low-level format the 620disk. Print sense information if the command fails, and set the timeout to 621two hours (or 7200 seconds). 622.Pp 623.Em WARNING! WARNING! WARNING! 624.Pp 625Low level formatting a disk will destroy ALL data on the disk. Use 626extreme caution when issuing this command. Many users low-level format 627disks that do not really need to be low-level formatted. There are 628relatively few scenarios that call for low-level formatting a disk. 629One reason for 630low-level formatting a disk is if you want to change the physical sector 631size of the disk. Another reason for low-level formatting a disk is to 632revive the disk if you are getting "medium format corrupted" errors from the 633disk in response to read and write requests. 634.Pp 635Some disks take longer than others to format. Users should specify a 636timeout long enough to allow the format to complete. Some hard disks 637will complete a format operation in a very short period of time (on the 638order of 5 minutes or less). This is often because the drive doesn't 639really support the FORMAT UNIT command -- it just accepts the command, 640waits a few minutes and then returns it. 641.Sh SEE ALSO 642.Xr cam 3 , 643.Xr cam_cdbparse 3 , 644.Xr cam 4 , 645.Xr pass 4 , 646.Xr xpt 4 647.Sh HISTORY 648The 649.Nm camcontrol 650command first appeared in 651.Fx 3.0 . 652.Pp 653The mode page editing code and arbitrary SCSI command code are based upon 654code in the old 655.Xr scsi 8 656utility and 657.Xr scsi 3 658library, written by Julian Elischer and Peter Dufault. The 659.Xr scsi 8 660program first appeared in 386BSD 0.1.2.4, and first appeared in 661.Tn FreeBSD 662in 663.Fx 2.0.5 . 664.Sh AUTHORS 665.An Kenneth Merry Aq ken@FreeBSD.org 666.Sh BUGS 667The code that parses the generic command line arguments doesn't know that 668some of the subcommands take multiple arguments. So if, for instance, you 669tried something like this: 670.Bd -literal -offset foobar 671camcontrol cmd -n da -u 1 -c "00 00 00 00 00 v" 0x00 -v 672.Ed 673.Pp 674The sense information from the test unit ready command would not get 675printed out, since the first 676.Xr getopt 3 677call in 678.Nm camcontrol 679bails out when it sees the second argument to 680.Fl c 681.Po 6820x00 683.Pc , 684above. Fixing this behavior would take some gross code, or changes to the 685.Xr getopt 3 686interface. The best way to circumvent this problem is to always make sure 687to specify generic 688.Nm camcontrol 689arguments before any command-specific arguments. 690