xref: /freebsd/lib/libcam/cam_cdbparse.3 (revision c8baaf1823e92bd846922b18b6e99baa6e0a33fe)
101a4eb82SKenneth D. Merry.\"
201a4eb82SKenneth D. Merry.\" Copyright (c) 1998 Kenneth D. Merry.
301a4eb82SKenneth D. Merry.\" All rights reserved.
401a4eb82SKenneth D. Merry.\"
501a4eb82SKenneth D. Merry.\" Redistribution and use in source and binary forms, with or without
601a4eb82SKenneth D. Merry.\" modification, are permitted provided that the following conditions
701a4eb82SKenneth D. Merry.\" are met:
801a4eb82SKenneth D. Merry.\" 1. Redistributions of source code must retain the above copyright
901a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer.
1001a4eb82SKenneth D. Merry.\" 2. Redistributions in binary form must reproduce the above copyright
1101a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer in the
1201a4eb82SKenneth D. Merry.\"    documentation and/or other materials provided with the distribution.
1301a4eb82SKenneth D. Merry.\" 3. The name of the author may not be used to endorse or promote products
1401a4eb82SKenneth D. Merry.\"    derived from this software without specific prior written permission.
1501a4eb82SKenneth D. Merry.\"
1601a4eb82SKenneth D. Merry.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1701a4eb82SKenneth D. Merry.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1801a4eb82SKenneth D. Merry.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1901a4eb82SKenneth D. Merry.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2001a4eb82SKenneth D. Merry.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2101a4eb82SKenneth D. Merry.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2201a4eb82SKenneth D. Merry.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2301a4eb82SKenneth D. Merry.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2401a4eb82SKenneth D. Merry.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2501a4eb82SKenneth D. Merry.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2601a4eb82SKenneth D. Merry.\" SUCH DAMAGE.
2701a4eb82SKenneth D. Merry.\"
287f3dea24SPeter Wemm.\" $FreeBSD$
2901a4eb82SKenneth D. Merry.\"
3001a4eb82SKenneth D. Merry.\" This man page borrows heavily from the old scsi(3) man page, which had
3101a4eb82SKenneth D. Merry.\" the following copyright:
3201a4eb82SKenneth D. Merry.\"
3301a4eb82SKenneth D. Merry.\" Copyright (c) 1994 HD Associates (hd@world.std.com)
3401a4eb82SKenneth D. Merry.\" All rights reserved.
3501a4eb82SKenneth D. Merry.\"
3601a4eb82SKenneth D. Merry.\" Redistribution and use in source and binary forms, with or without
3701a4eb82SKenneth D. Merry.\" modification, are permitted provided that the following conditions
3801a4eb82SKenneth D. Merry.\" are met:
3901a4eb82SKenneth D. Merry.\" 1. Redistributions of source code must retain the above copyright
4001a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer.
4101a4eb82SKenneth D. Merry.\" 2. Redistributions in binary form must reproduce the above copyright
4201a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer in the
4301a4eb82SKenneth D. Merry.\"    documentation and/or other materials provided with the distribution.
4401a4eb82SKenneth D. Merry.\" 3. All advertising materials mentioning features or use of this software
4501a4eb82SKenneth D. Merry.\"    must display the following acknowledgement:
4601a4eb82SKenneth D. Merry.\"	This product includes software developed by HD Associates
4701a4eb82SKenneth D. Merry.\" 4. Neither the name of the HD Associates nor the names of its contributors
4801a4eb82SKenneth D. Merry.\"    may be used to endorse or promote products derived from this software
4901a4eb82SKenneth D. Merry.\"    without specific prior written permission.
5001a4eb82SKenneth D. Merry.\"
5101a4eb82SKenneth D. Merry.\" THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
5201a4eb82SKenneth D. Merry.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5301a4eb82SKenneth D. Merry.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5401a4eb82SKenneth D. Merry.\" ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
5501a4eb82SKenneth D. Merry.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5601a4eb82SKenneth D. Merry.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5701a4eb82SKenneth D. Merry.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5801a4eb82SKenneth D. Merry.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5901a4eb82SKenneth D. Merry.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6001a4eb82SKenneth D. Merry.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6101a4eb82SKenneth D. Merry.\" SUCH DAMAGE.
6201a4eb82SKenneth D. Merry.\"
6301a4eb82SKenneth D. Merry.\"
6401a4eb82SKenneth D. Merry.Dd October 13, 1998
6501a4eb82SKenneth D. Merry.Os FreeBSD 3.0
6601a4eb82SKenneth D. Merry.Dt CAM_CDBPARSE 3
6701a4eb82SKenneth D. Merry.Sh NAME
6801a4eb82SKenneth D. Merry.Nm csio_build ,
6901a4eb82SKenneth D. Merry.Nm csio_build_visit ,
7001a4eb82SKenneth D. Merry.Nm csio_decode ,
7101a4eb82SKenneth D. Merry.Nm csio_decode_visit ,
7201a4eb82SKenneth D. Merry.Nm buff_decode ,
7301a4eb82SKenneth D. Merry.Nm buff_decode_visit ,
7401a4eb82SKenneth D. Merry.Nm csio_encode ,
7501a4eb82SKenneth D. Merry.Nm csio_encode_visit ,
7601a4eb82SKenneth D. Merry.Nm buff_encode_visit
7701a4eb82SKenneth D. Merry.Nd CAM user library SCSI buffer parsing routines
78c8baaf18SAlexey Zelkin.Sh LIBRARY
79c8baaf18SAlexey Zelkin.Lb libcam
8001a4eb82SKenneth D. Merry.Sh SYNOPSIS
817970c113SBruce Evans.Fd #include <stdio.h>
8201a4eb82SKenneth D. Merry.Fd #include <camlib.h>
8301a4eb82SKenneth D. Merry.Ft int
8401a4eb82SKenneth D. Merry.Fo csio_build
8501a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
8601a4eb82SKenneth D. Merry.Fa "u_int8_t *data_ptr"
8701a4eb82SKenneth D. Merry.Fa "u_int32_t dxfer_len"
8801a4eb82SKenneth D. Merry.Fa "u_int32_t flags"
8901a4eb82SKenneth D. Merry.Fa "int retry_count"
9001a4eb82SKenneth D. Merry.Fa "int timeout"
9101a4eb82SKenneth D. Merry.Fa "char *cmd_spec"
9201a4eb82SKenneth D. Merry.Fa "..."
9301a4eb82SKenneth D. Merry.Fc
9401a4eb82SKenneth D. Merry.Ft int
9501a4eb82SKenneth D. Merry.Fo csio_build_visit
9601a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
9701a4eb82SKenneth D. Merry.Fa "u_int8_t *data_ptr"
9801a4eb82SKenneth D. Merry.Fa "u_int32_t dxfer_len"
9901a4eb82SKenneth D. Merry.Fa "u_int32_t flags"
10001a4eb82SKenneth D. Merry.Fa "int retry_count"
10101a4eb82SKenneth D. Merry.Fa "int timeout"
10201a4eb82SKenneth D. Merry.Fa "char *cmd_spec"
10301a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
10401a4eb82SKenneth D. Merry.Fa "void *gethook"
10501a4eb82SKenneth D. Merry.Fc
10601a4eb82SKenneth D. Merry.Ft int
10701a4eb82SKenneth D. Merry.Fo csio_decode
10801a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
10901a4eb82SKenneth D. Merry.Fa "char *fmt"
11001a4eb82SKenneth D. Merry.Fa "..."
11101a4eb82SKenneth D. Merry.Fc
11201a4eb82SKenneth D. Merry.Ft int
11301a4eb82SKenneth D. Merry.Fo csio_decode_visit
11401a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
11501a4eb82SKenneth D. Merry.Fa "char *fmt"
11601a4eb82SKenneth D. Merry.Fa "void (*arg_put)(void *hook"
11701a4eb82SKenneth D. Merry.Fa "int letter"
11801a4eb82SKenneth D. Merry.Fa "void *val"
11901a4eb82SKenneth D. Merry.Fa "int count"
12001a4eb82SKenneth D. Merry.Fa "char *name)"
12101a4eb82SKenneth D. Merry.Fa "void *puthook"
12201a4eb82SKenneth D. Merry.Fc
12301a4eb82SKenneth D. Merry.Ft int
12401a4eb82SKenneth D. Merry.Fo buff_decode
12501a4eb82SKenneth D. Merry.Fa "u_int8_t *buff"
12601a4eb82SKenneth D. Merry.Fa "size_t len"
12701a4eb82SKenneth D. Merry.Fa "char *fmt"
12801a4eb82SKenneth D. Merry.Fa "..."
12901a4eb82SKenneth D. Merry.Fc
13001a4eb82SKenneth D. Merry.Ft int
13101a4eb82SKenneth D. Merry.Fo buff_decode_visit
13201a4eb82SKenneth D. Merry.Fa "u_int8_t *buff"
13301a4eb82SKenneth D. Merry.Fa "size_t len"
13401a4eb82SKenneth D. Merry.Fa "char *fmt"
13501a4eb82SKenneth D. Merry.Fa "void (*arg_put)(void *, int, void *, int, char *)"
13601a4eb82SKenneth D. Merry.Fa "void *puthook"
13701a4eb82SKenneth D. Merry.Fc
13801a4eb82SKenneth D. Merry.Ft int
13901a4eb82SKenneth D. Merry.Fo csio_encode
14001a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
14101a4eb82SKenneth D. Merry.Fa "char *fmt"
14201a4eb82SKenneth D. Merry.Fa "..."
14301a4eb82SKenneth D. Merry.Fc
14401a4eb82SKenneth D. Merry.Ft int
14501a4eb82SKenneth D. Merry.Fo csio_encode_visit
14601a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
14701a4eb82SKenneth D. Merry.Fa "char *fmt"
14801a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
14901a4eb82SKenneth D. Merry.Fa "void *gethook"
15001a4eb82SKenneth D. Merry.Fc
15101a4eb82SKenneth D. Merry.Ft int
15201a4eb82SKenneth D. Merry.Fo buff_encode_visit
15301a4eb82SKenneth D. Merry.Fa "u_int8_t *buff"
15401a4eb82SKenneth D. Merry.Fa "size_t len"
15501a4eb82SKenneth D. Merry.Fa "char *fmt"
15601a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
15701a4eb82SKenneth D. Merry.Fa "void *gethook"
15801a4eb82SKenneth D. Merry.Fc
15901a4eb82SKenneth D. Merry.Sh DESCRIPTION
16001a4eb82SKenneth D. MerryThe CAM buffer/CDB encoding and decoding routines provide a relatively easy
16101a4eb82SKenneth D. Merrymigration path for userland
16201a4eb82SKenneth D. Merry.Tn SCSI
16301a4eb82SKenneth D. Merryapplications written with the similarly-named
16401a4eb82SKenneth D. Merry.Va scsireq_ Ns *
16501a4eb82SKenneth D. Merryfunctions from the old FreeBSD
16601a4eb82SKenneth D. Merry.Tn SCSI
16701a4eb82SKenneth D. Merrylayer.
16801a4eb82SKenneth D. Merry.Pp
16901a4eb82SKenneth D. MerryThese functions may be used in new applications, but users may find it
17001a4eb82SKenneth D. Merryeasier to use the various SCSI CCB building functions included with the
17101a4eb82SKenneth D. Merry.Xr cam 3
17201a4eb82SKenneth D. Merrylibrary.  (e.g.
17301a4eb82SKenneth D. Merry.Fn cam_fill_csio ,
17401a4eb82SKenneth D. Merry.Fn scsi_start_stop ,
17501a4eb82SKenneth D. Merryand
17601a4eb82SKenneth D. Merry.Fn scsi_read_write )
17701a4eb82SKenneth D. Merry.Pp
17801a4eb82SKenneth D. Merry.Fn csio_build
17901a4eb82SKenneth D. Merrybuilds up a
18001a4eb82SKenneth D. Merry.Va ccb_scsiio
18101a4eb82SKenneth D. Merrystructure based on the information provided in
18201a4eb82SKenneth D. Merrythe variable argument list.
18301a4eb82SKenneth D. MerryIt gracefully handles a NULL
18401a4eb82SKenneth D. Merry.Fa data_ptr
18501a4eb82SKenneth D. Merryargument passed to it.
18601a4eb82SKenneth D. Merry.Pp
18701a4eb82SKenneth D. Merry.Fa dxfer_len
18801a4eb82SKenneth D. Merryis the length of the data phase; the data transfer direction is
18901a4eb82SKenneth D. Merrydetermined by the
19001a4eb82SKenneth D. Merry.Fa flags
19101a4eb82SKenneth D. Merryargument.
19201a4eb82SKenneth D. Merry.Pp
19301a4eb82SKenneth D. Merry.Fa data_ptr
19401a4eb82SKenneth D. Merryis the data buffer used during the
19501a4eb82SKenneth D. Merry.Tn SCSI
19601a4eb82SKenneth D. Merrydata phase.  If no data is to be
19701a4eb82SKenneth D. Merrytransferred for the
19801a4eb82SKenneth D. Merry.Tn SCSI
19901a4eb82SKenneth D. Merrycommand in question, this should be set to NULL.  If there is data to
20001a4eb82SKenneth D. Merrytransfer for the command, this buffer must be at least
20101a4eb82SKenneth D. Merry.Fa dxfer_len
20201a4eb82SKenneth D. Merrylong.
20301a4eb82SKenneth D. Merry.Pp
20401a4eb82SKenneth D. Merry.Fa flags
20501a4eb82SKenneth D. Merryare the flags defined in
20601a4eb82SKenneth D. Merry.Aq Pa cam/cam_ccb.h :
20701a4eb82SKenneth D. Merry.Bd -literal
20801a4eb82SKenneth D. Merry/* Common CCB header */
20901a4eb82SKenneth D. Merry/* CAM CCB flags */
21001a4eb82SKenneth D. Merrytypedef enum {
21101a4eb82SKenneth D. Merry     CAM_CDB_POINTER       = 0x00000001,/* The CDB field is a pointer    */
21201a4eb82SKenneth D. Merry     CAM_QUEUE_ENABLE      = 0x00000002,/* SIM queue actions are enabled */
21301a4eb82SKenneth D. Merry     CAM_CDB_LINKED        = 0x00000004,/* CCB contains a linked CDB     */
21401a4eb82SKenneth D. Merry     CAM_SCATTER_VALID     = 0x00000010,/* Scatter/gather list is valid  */
21501a4eb82SKenneth D. Merry     CAM_DIS_AUTOSENSE     = 0x00000020,/* Disable autosense feature     */
21601a4eb82SKenneth D. Merry     CAM_DIR_RESV          = 0x00000000,/* Data direction (00:reserved)  */
21701a4eb82SKenneth D. Merry     CAM_DIR_IN            = 0x00000040,/* Data direction (01:DATA IN)   */
21801a4eb82SKenneth D. Merry     CAM_DIR_OUT           = 0x00000080,/* Data direction (10:DATA OUT)  */
21901a4eb82SKenneth D. Merry     CAM_DIR_NONE          = 0x000000C0,/* Data direction (11:no data)   */
22001a4eb82SKenneth D. Merry     CAM_DIR_MASK          = 0x000000C0,/* Data direction Mask		 */
22101a4eb82SKenneth D. Merry     CAM_SOFT_RST_OP       = 0x00000100,/* Use Soft reset alternative    */
22201a4eb82SKenneth D. Merry     CAM_ENG_SYNC          = 0x00000200,/* Flush resid bytes on complete */
22301a4eb82SKenneth D. Merry     CAM_DEV_QFRZDIS       = 0x00000400,/* Disable DEV Q freezing	 */
22401a4eb82SKenneth D. Merry     CAM_DEV_QFREEZE       = 0x00000800,/* Freeze DEV Q on execution     */
22501a4eb82SKenneth D. Merry     CAM_HIGH_POWER        = 0x00001000,/* Command takes a lot of power  */
22601a4eb82SKenneth D. Merry     CAM_SENSE_PTR         = 0x00002000,/* Sense data is a pointer	 */
22701a4eb82SKenneth D. Merry     CAM_SENSE_PHYS        = 0x00004000,/* Sense pointer is physical addr*/
22801a4eb82SKenneth D. Merry     CAM_TAG_ACTION_VALID  = 0x00008000,/* Use the tag action in this ccb*/
22901a4eb82SKenneth D. Merry     CAM_PASS_ERR_RECOVER  = 0x00010000,/* Pass driver does err. recovery*/
23001a4eb82SKenneth D. Merry     CAM_DIS_DISCONNECT    = 0x00020000,/* Disable disconnect		 */
23101a4eb82SKenneth D. Merry     CAM_SG_LIST_PHYS      = 0x00040000,/* SG list has physical addrs.   */
23201a4eb82SKenneth D. Merry     CAM_MSG_BUF_PHYS      = 0x00080000,/* Message buffer ptr is physical*/
23301a4eb82SKenneth D. Merry     CAM_SNS_BUF_PHYS      = 0x00100000,/* Autosense data ptr is physical*/
23401a4eb82SKenneth D. Merry     CAM_DATA_PHYS         = 0x00200000,/* SG/Buffer data ptrs are phys. */
23501a4eb82SKenneth D. Merry     CAM_CDB_PHYS          = 0x00400000,/* CDB poiner is physical	 */
23601a4eb82SKenneth D. Merry     CAM_ENG_SGLIST        = 0x00800000,/* SG list is for the HBA engine */
23701a4eb82SKenneth D. Merry
23801a4eb82SKenneth D. Merry/* Phase cognizant mode flags */
23901a4eb82SKenneth D. Merry     CAM_DIS_AUTOSRP       = 0x01000000,/* Diable autosave/restore ptrs	*/
24001a4eb82SKenneth D. Merry     CAM_DIS_AUTODISC      = 0x02000000,/* Disable auto disconnect	*/
24101a4eb82SKenneth D. Merry     CAM_TGT_CCB_AVAIL     = 0x04000000,/* Target CCB available		*/
24201a4eb82SKenneth D. Merry     CAM_TGT_PHASE_MODE    = 0x08000000,/* The SIM runs in phase mode	*/
24301a4eb82SKenneth D. Merry     CAM_MSGB_VALID        = 0x20000000,/* Message buffer valid		*/
24401a4eb82SKenneth D. Merry     CAM_STATUS_VALID      = 0x40000000,/* Status buffer valid		*/
24501a4eb82SKenneth D. Merry     CAM_DATAB_VALID       = 0x80000000,/* Data buffer valid		*/
24601a4eb82SKenneth D. Merry
24701a4eb82SKenneth D. Merry/* Host target Mode flags */
24801a4eb82SKenneth D. Merry     CAM_TERM_IO           = 0x20000000,/* Terminate I/O Message sup.    */
24901a4eb82SKenneth D. Merry     CAM_DISCONNECT        = 0x40000000,/* Disconnects are mandatory     */
25001a4eb82SKenneth D. Merry     CAM_SEND_STATUS       = 0x80000000,/* Send status after data phase  */
25101a4eb82SKenneth D. Merry} ccb_flags;
25201a4eb82SKenneth D. Merry.Ed
25301a4eb82SKenneth D. Merry.Pp
25401a4eb82SKenneth D. MerryMultiple flags should be ORed together.  Any of the CCB flags may be used,
25501a4eb82SKenneth D. Merryalthough it is worth noting several important ones here:
25601a4eb82SKenneth D. Merry.Pp
25701a4eb82SKenneth D. Merry.Bl -tag -width CAM_PASS_ERR_RECOVER
25801a4eb82SKenneth D. Merry.It Dv CAM_DIR_IN
25901a4eb82SKenneth D. MerryThis indicates that the operation in question is a read operation.  i.e.,
26001a4eb82SKenneth D. Merrydata is being read from the
26101a4eb82SKenneth D. Merry.Tn SCSI
26201a4eb82SKenneth D. Merrydevice to the user-supplied buffer.
26301a4eb82SKenneth D. Merry.It Dv CAM_DIR_OUT
26401a4eb82SKenneth D. MerryThis indicates that the operation is a write operation.  i.e. data is being
26501a4eb82SKenneth D. Merrywritten from the user-supplied buffer to the device.
26601a4eb82SKenneth D. Merry.It Dv CAM_DIR_NONE
26701a4eb82SKenneth D. MerryThis indicates that there is no data to be transferred for this command.
26801a4eb82SKenneth D. Merry.It Dv CAM_DEV_QFRZDIS
26901a4eb82SKenneth D. MerryThis flag disables device queue freezing as an error recovery mechanism.
27001a4eb82SKenneth D. Merry.It Dv CAM_PASS_ERR_RECOVER
27101a4eb82SKenneth D. MerryThis flag tells the
27201a4eb82SKenneth D. Merry.Xr pass 4
27301a4eb82SKenneth D. Merrydriver to enable error recovery.  The default is to not perform error
27401a4eb82SKenneth D. Merryrecovery, which means that the retry count won't be honored without this
27501a4eb82SKenneth D. Merryflag, among other things.
27601a4eb82SKenneth D. Merry.It Dv CAM_DATA_PHYS
27701a4eb82SKenneth D. MerryThis indicates that the address contained in
27801a4eb82SKenneth D. Merry.Fa data_ptr
27901a4eb82SKenneth D. Merryis a physical address, not a virtual address.
28001a4eb82SKenneth D. Merry.El
28101a4eb82SKenneth D. Merry.Pp
28201a4eb82SKenneth D. MerryThe
28301a4eb82SKenneth D. Merry.Fa retry_count
28401a4eb82SKenneth D. Merrytells the kernel how many times to retry the command in question.  The
28501a4eb82SKenneth D. Merryretry count is ignored unless the
28601a4eb82SKenneth D. Merry.Xr pass 4
28701a4eb82SKenneth D. Merrydriver is told to enable error recovery via the
28801a4eb82SKenneth D. Merry.Dv CAM_PASS_ERR_RECOVER
28901a4eb82SKenneth D. Merryflag.
29001a4eb82SKenneth D. Merry.Pp
29101a4eb82SKenneth D. MerryThe
29201a4eb82SKenneth D. Merry.Fa timeout
29301a4eb82SKenneth D. Merrytells the kernel how long to wait for the given command to complete.  If
29401a4eb82SKenneth D. Merrythe timeout expires and the command hasn't completed, the CCB will be
29501a4eb82SKenneth D. Merryreturned from the kernel with an appropriate error status.
29601a4eb82SKenneth D. Merry.Pp
29701a4eb82SKenneth D. Merry.Fa cmd_spec
29801a4eb82SKenneth D. Merryis a CDB format specifier used to build up the SCSI CDB.
29901a4eb82SKenneth D. MerryThis text string is made up of a list of field specifiers.  Field
30001a4eb82SKenneth D. Merryspecifiers specify the value for each CDB field (including indicating
30101a4eb82SKenneth D. Merrythat the value be taken from the next argument in the
30201a4eb82SKenneth D. Merryvariable argument list), the width
30301a4eb82SKenneth D. Merryof the field in bits or bytes, and an optional name.  White space is
30401a4eb82SKenneth D. Merryignored, and the pound sign ('#') introduces a comment that ends at the
30501a4eb82SKenneth D. Merryend of the current line.
30601a4eb82SKenneth D. Merry.Pp
30701a4eb82SKenneth D. MerryThe optional name is the first part of a field specifier and
30801a4eb82SKenneth D. Merryis in curly braces.  The text in curly braces in this example are
30901a4eb82SKenneth D. Merrythe names:
31001a4eb82SKenneth D. Merry.Bd -literal -offset indent
31101a4eb82SKenneth D. Merry.Fa "{PS} v:b1 {Reserved} 0:b1 {Page Code} v:b6 # Mode select page"
31201a4eb82SKenneth D. Merry.Ed
31301a4eb82SKenneth D. Merry.Pp
31401a4eb82SKenneth D. MerryThis field specifier has two one bit fields and one six bit field.
31501a4eb82SKenneth D. MerryThe second one bit field is the constant value 0 and the first
31601a4eb82SKenneth D. Merryone bit field and the six bit field are taken from the variable
31701a4eb82SKenneth D. Merryargument list.
31801a4eb82SKenneth D. MerryMulti byte fields are swapped into the SCSI byte order in the
31901a4eb82SKenneth D. MerryCDB and white space is ignored.
32001a4eb82SKenneth D. Merry.Pp
32101a4eb82SKenneth D. MerryWhen the field is a hex value or the letter v, (e.g.,
32201a4eb82SKenneth D. Merry.Fa "1A"
32301a4eb82SKenneth D. Merryor
32401a4eb82SKenneth D. Merry.Fa "v" )
32501a4eb82SKenneth D. Merrythen a single byte value
32601a4eb82SKenneth D. Merryis copied to the next unused byte of the CDB.
32701a4eb82SKenneth D. MerryWhen the letter
32801a4eb82SKenneth D. Merry.Fa v
32901a4eb82SKenneth D. Merryis used the next integer argument is taken from the variable argument list
33001a4eb82SKenneth D. Merryand that value used.
33101a4eb82SKenneth D. Merry.Pp
33201a4eb82SKenneth D. MerryA constant hex value followed by a field width specifier or the letter
33301a4eb82SKenneth D. Merry.Fa v
33401a4eb82SKenneth D. Merryfollowed by a field width specifier (e.g.,
33501a4eb82SKenneth D. Merry.Fa 3:4 ,
33601a4eb82SKenneth D. Merry.Fa 3:b4 ,
33701a4eb82SKenneth D. Merry.Fa 3:i3 ,
33801a4eb82SKenneth D. Merry.FR v:i3 )
33901a4eb82SKenneth D. Merryspecifies a field of a given bit or byte width.
34001a4eb82SKenneth D. MerryEither the constant value or (for the V specifier) the next integer value from
34101a4eb82SKenneth D. Merrythe variable argument list is copied to the next unused
34201a4eb82SKenneth D. Merrybits or bytes of the CDB.
34301a4eb82SKenneth D. Merry.Pp
34401a4eb82SKenneth D. MerryA decimal number or the letter
34501a4eb82SKenneth D. Merry.Fa b
34601a4eb82SKenneth D. Merryfollowed by a decimal number field width indicates a bit field of that width.
34701a4eb82SKenneth D. MerryThe bit fields are packed as tightly as possible beginning with the
34801a4eb82SKenneth D. Merryhigh bit (so that it reads the same as the SCSI spec), and a new byte of
34901a4eb82SKenneth D. Merrythe CDB is started whenever a byte fills completely or when an
35001a4eb82SKenneth D. Merry.Fa i
35101a4eb82SKenneth D. Merryfield is encountered.
35201a4eb82SKenneth D. Merry.Pp
35301a4eb82SKenneth D. MerryA field width specifier consisting of the letter
35401a4eb82SKenneth D. Merry.Fa i
35501a4eb82SKenneth D. Merryfollowed by either
35601a4eb82SKenneth D. Merry1, 2, 3 or 4 indicates a 1, 2, 3 or 4 byte integral value that must
35701a4eb82SKenneth D. Merrybe swapped into SCSI byte order (MSB first).
35801a4eb82SKenneth D. Merry.Pp
35901a4eb82SKenneth D. MerryFor the
36001a4eb82SKenneth D. Merry.Fa v
36101a4eb82SKenneth D. Merryfield specifier the next integer argument is taken from the variable argument
36201a4eb82SKenneth D. Merrylist and that value is used swapped into SCSI byte order.
36301a4eb82SKenneth D. Merry.Pp
36401a4eb82SKenneth D. Merry.Fn csio_build_visit
36501a4eb82SKenneth D. Merryoperates similarly to
36601a4eb82SKenneth D. Merry.Fn csio_build ,
36701a4eb82SKenneth D. Merryexcept that the values to substitute for variable arguments in
36801a4eb82SKenneth D. Merry.Fa cmd_spec
36901a4eb82SKenneth D. Merryare retrieved via the
37001a4eb82SKenneth D. Merry.Fn arg_get
37101a4eb82SKenneth D. Merryfunction passed in to
37201a4eb82SKenneth D. Merry.Fn csio_build_visit
37301a4eb82SKenneth D. Merryinstead of via
37401a4eb82SKenneth D. Merry.Xr stdarg 3 .
37501a4eb82SKenneth D. MerryThe
37601a4eb82SKenneth D. Merry.Fn arg_get
37701a4eb82SKenneth D. Merryfunction takes two arguments:
37801a4eb82SKenneth D. Merry.Bl -tag -width field_name
37901a4eb82SKenneth D. Merry.It Fa gethook
38001a4eb82SKenneth D. Merryis passed into the
38101a4eb82SKenneth D. Merry.Fn arg_get
38201a4eb82SKenneth D. Merryfunction at each invocation.  This enables the
38301a4eb82SKenneth D. Merry.Fn arg_get
38401a4eb82SKenneth D. Merryfunction to keep some state in between calls without using global or static
38501a4eb82SKenneth D. Merryvariables.
38601a4eb82SKenneth D. Merry.It Fa field_name
38701a4eb82SKenneth D. Merryis the field name supplied in
38801a4eb82SKenneth D. Merry.Fa fmt ,
38901a4eb82SKenneth D. Merryif any.
39001a4eb82SKenneth D. Merry.El
39101a4eb82SKenneth D. Merry.Pp
39201a4eb82SKenneth D. Merry.Fn csio_decode
39301a4eb82SKenneth D. Merryis used to decode information from the data in phase of the SCSI
39401a4eb82SKenneth D. Merrytransfer.
39501a4eb82SKenneth D. Merry.Pp
39601a4eb82SKenneth D. MerryThe decoding is similar to
39701a4eb82SKenneth D. Merrythe command specifier processing of
39801a4eb82SKenneth D. Merry.Fn csio_build
39901a4eb82SKenneth D. Merryexcept that the data is extracted from the data pointed to by
40001a4eb82SKenneth D. Merry.Fa csio->data_ptr .
40101a4eb82SKenneth D. MerryThe stdarg list should be pointers to integers instead of integer
40201a4eb82SKenneth D. Merryvalues.
40301a4eb82SKenneth D. MerryA seek field type and a suppression modifier are added.
40401a4eb82SKenneth D. MerryThe
40501a4eb82SKenneth D. Merry.Fa *
40601a4eb82SKenneth D. Merrysuppression modifier (e.g.,
40701a4eb82SKenneth D. Merry.Fa *i3
40801a4eb82SKenneth D. Merryor
40901a4eb82SKenneth D. Merry.Fa *b4 )
41001a4eb82SKenneth D. Merrysuppresses assignment from the field and can be used to skip
41101a4eb82SKenneth D. Merryover bytes or bits in the data, without having to copy
41201a4eb82SKenneth D. Merrythem to a dummy variable in the arg list.
41301a4eb82SKenneth D. Merry.Pp
41401a4eb82SKenneth D. MerryThe seek field type
41501a4eb82SKenneth D. Merry.Fa s
41601a4eb82SKenneth D. Merrypermits you to skip over data.
41701a4eb82SKenneth D. MerryThis seeks to an absolute position (
41801a4eb82SKenneth D. Merry.Fa s3 )
41901a4eb82SKenneth D. Merryor a relative position (
42001a4eb82SKenneth D. Merry.Fa s+3 )
42101a4eb82SKenneth D. Merryin the data, based on whether or not the presence of the '+' sign.
42201a4eb82SKenneth D. MerryThe seek value can be specified as
42301a4eb82SKenneth D. Merry.Fa v
42401a4eb82SKenneth D. Merryand the next integer value from the argument list will be
42501a4eb82SKenneth D. Merryused as the seek value.
42601a4eb82SKenneth D. Merry.Pp
42701a4eb82SKenneth D. Merry.Fn csio_decode_visit
42801a4eb82SKenneth D. Merryoperates like
42901a4eb82SKenneth D. Merry.Fn csio_decode
43001a4eb82SKenneth D. Merryexcept that instead of placing the decoded contents of the buffer in
43101a4eb82SKenneth D. Merryvarardic arguments, the decoded buffer contents are returned to the user
43201a4eb82SKenneth D. Merryvia the
43301a4eb82SKenneth D. Merry.Fn arg_put
43401a4eb82SKenneth D. Merryfunction that is passed in.
43501a4eb82SKenneth D. MerryThe
43601a4eb82SKenneth D. Merry.Fn arg_put
43701a4eb82SKenneth D. Merryfunction takes several arguments:
43801a4eb82SKenneth D. Merry.Bl -tag -width letter
43901a4eb82SKenneth D. Merry.It Fa hook
44001a4eb82SKenneth D. MerryThe "hook" is a mechanism to allow the
44101a4eb82SKenneth D. Merry.Fn arg_put
44201a4eb82SKenneth D. Merryfunction to save state in between calls.
44301a4eb82SKenneth D. Merry.It Fa letter
44401a4eb82SKenneth D. Merryis the letter describing the format of the argument being passed into the
44501a4eb82SKenneth D. Merryfunction.
44601a4eb82SKenneth D. Merry.It Fa val
44701a4eb82SKenneth D. Merryis a void pointer to the value being passed into the function.
44801a4eb82SKenneth D. Merry.It Fa count
44901a4eb82SKenneth D. Merryis the number of arguments being passed into the
45001a4eb82SKenneth D. Merry.Fn arg_put
45101a4eb82SKenneth D. Merryfunction.  At present this will only be set to 1.
45201a4eb82SKenneth D. Merry.It Fa name
45301a4eb82SKenneth D. MerryThis is a text description of the field, if one was provided in the
45401a4eb82SKenneth D. Merry.Fa fmt .
45501a4eb82SKenneth D. Merry.El
45601a4eb82SKenneth D. Merry.Pp
45701a4eb82SKenneth D. Merry.Fn buff_decode
45801a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method
45901a4eb82SKenneth D. Merrydescribed above for
46001a4eb82SKenneth D. Merry.Fn csio_decode .
46101a4eb82SKenneth D. Merry.Pp
46201a4eb82SKenneth D. Merry.Fn buff_decode_visit
46301a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method described above for
46401a4eb82SKenneth D. Merry.Fn csio_decode_visit .
46501a4eb82SKenneth D. Merry.Pp
46601a4eb82SKenneth D. Merry.Fn csio_encode
46701a4eb82SKenneth D. Merryencodes the
46801a4eb82SKenneth D. Merry.Fa data_ptr
46901a4eb82SKenneth D. Merryportion (not the CDB!) of a
47001a4eb82SKenneth D. Merry.Va ccb_scsiio
47101a4eb82SKenneth D. Merrystructure, using the method described above for
47201a4eb82SKenneth D. Merry.Fn csio_build .
47301a4eb82SKenneth D. Merry.Pp
47401a4eb82SKenneth D. Merry.Fn csio_encode_visit
47501a4eb82SKenneth D. Merryencodes the
47601a4eb82SKenneth D. Merry.Fa data_ptr
47701a4eb82SKenneth D. Merryportion (not the CDB!) of a
47801a4eb82SKenneth D. Merry.Va ccb_scsiio
47901a4eb82SKenneth D. Merrystructure, using the method described above for
48001a4eb82SKenneth D. Merry.Fn csio_build_visit .
48101a4eb82SKenneth D. Merry.Pp
48201a4eb82SKenneth D. Merry.Fn buff_encode_visit
48301a4eb82SKenneth D. Merryencodes an arbitrary data pointer, using the method described
48401a4eb82SKenneth D. Merryabove for
48501a4eb82SKenneth D. Merry.Fn csio_build_visit .
48601a4eb82SKenneth D. Merry.Sh RETURN VALUES
48701a4eb82SKenneth D. Merry.Fn csio_build ,
48801a4eb82SKenneth D. Merry.Fn csio_build_visit ,
48901a4eb82SKenneth D. Merry.Fn csio_encode ,
49001a4eb82SKenneth D. Merry.Fn csio_encode_visit ,
49101a4eb82SKenneth D. Merryand
49201a4eb82SKenneth D. Merry.Fn buff_encode_visit
49301a4eb82SKenneth D. Merryreturn the number of fields processed.
49401a4eb82SKenneth D. Merry.Pp
49501a4eb82SKenneth D. Merry.Fn csio_decode ,
49601a4eb82SKenneth D. Merry.Fn csio_decode_visit ,
49701a4eb82SKenneth D. Merry.Fn buff_decode ,
49801a4eb82SKenneth D. Merryand
49901a4eb82SKenneth D. Merry.Fn buff_decode_visit
50001a4eb82SKenneth D. Merryreturn the number of assignments performed.
50101a4eb82SKenneth D. Merry.Sh SEE ALSO
50201a4eb82SKenneth D. Merry.Xr cam 3 ,
50301a4eb82SKenneth D. Merry.Xr pass 4 ,
50401a4eb82SKenneth D. Merry.Xr camcontrol 8
50501a4eb82SKenneth D. Merry.Sh HISTORY
50601a4eb82SKenneth D. Merry.Pp
50701a4eb82SKenneth D. MerryThe CAM versions of these functions are based upon similar functions
50801a4eb82SKenneth D. Merryimplemented for the old FreeBSD
50901a4eb82SKenneth D. Merry.Tn SCSI
51001a4eb82SKenneth D. Merrylayer.  The encoding/decoding functions in the old
51101a4eb82SKenneth D. Merry.Tn SCSI
51201a4eb82SKenneth D. Merrycode were written by Peter Dufault.
51301a4eb82SKenneth D. Merry.Pp
51401a4eb82SKenneth D. MerryMany systems have comparable interfaces to permit a user to construct a
51501a4eb82SKenneth D. MerrySCSI command in user space.
51601a4eb82SKenneth D. Merry.Pp
51701a4eb82SKenneth D. MerryThe old
51801a4eb82SKenneth D. Merry.Va scsireq
51901a4eb82SKenneth D. Merrydata structure was almost identical to the SGI /dev/scsi data
52001a4eb82SKenneth D. Merrystructure.  If anyone knows the name of the authors it should
52101a4eb82SKenneth D. Merrygo here; Peter Dufault first read about it in a 1989 Sun Expert magazine.
52201a4eb82SKenneth D. Merry.Pp
52301a4eb82SKenneth D. MerryThe new CCB data structures are derived from the CAM-2 and CAM-3
52401a4eb82SKenneth D. Merryspecifications.
52501a4eb82SKenneth D. Merry.Pp
52601a4eb82SKenneth D. MerryPeter Dufault implemented a clone of SGI's interface in 386bsd that
52701a4eb82SKenneth D. Merryled to the original FreeBSD
52801a4eb82SKenneth D. Merry.Tn SCSI
52901a4eb82SKenneth D. Merrylibrary and the related kernel ioctl.
53001a4eb82SKenneth D. MerryIf anyone needs that for compatibility contact dufault@hda.com.
53101a4eb82SKenneth D. Merry.Sh AUTHORS
53201a4eb82SKenneth D. MerryKenneth Merry implemented the CAM versions of these encoding and decoding
53301a4eb82SKenneth D. Merryfunctions.  This current work is based upon earlier work by Peter Dufault.
53401a4eb82SKenneth D. Merry.Sh BUGS
53501a4eb82SKenneth D. MerryThere should probably be a function that encodes both the CDB and the data
53601a4eb82SKenneth D. Merrybuffer portions of a
53701a4eb82SKenneth D. Merry.Tn SCSI
53801a4eb82SKenneth D. MerryCCB.  I discovered this while implementing the arbitrary command execution
53901a4eb82SKenneth D. Merrycode in
54001a4eb82SKenneth D. Merry.Xr camcontrol 8 ,
54101a4eb82SKenneth D. Merrybut I haven't yet had time to implement such a function.
54201a4eb82SKenneth D. Merry.Pp
54301a4eb82SKenneth D. MerrySome of the CCB flag descriptions really don't belong here.  Rather they
54401a4eb82SKenneth D. Merrybelong in a generic CCB man page.  Since that man page hasn't yet been
54501a4eb82SKenneth D. Merrywritten, the shorter descriptions here will have to suffice.
546