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