xref: /freebsd/lib/libcam/cam_cdbparse.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\" This man page borrows heavily from the old scsi(3) man page, which had
2901a4eb82SKenneth D. Merry.\" the following copyright:
3001a4eb82SKenneth D. Merry.\"
3101a4eb82SKenneth D. Merry.\" Copyright (c) 1994 HD Associates (hd@world.std.com)
3201a4eb82SKenneth D. Merry.\" All rights reserved.
3301a4eb82SKenneth D. Merry.\"
3401a4eb82SKenneth D. Merry.\" Redistribution and use in source and binary forms, with or without
3501a4eb82SKenneth D. Merry.\" modification, are permitted provided that the following conditions
3601a4eb82SKenneth D. Merry.\" are met:
3701a4eb82SKenneth D. Merry.\" 1. Redistributions of source code must retain the above copyright
3801a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer.
3901a4eb82SKenneth D. Merry.\" 2. Redistributions in binary form must reproduce the above copyright
4001a4eb82SKenneth D. Merry.\"    notice, this list of conditions and the following disclaimer in the
4101a4eb82SKenneth D. Merry.\"    documentation and/or other materials provided with the distribution.
4201a4eb82SKenneth D. Merry.\" 3. All advertising materials mentioning features or use of this software
4301a4eb82SKenneth D. Merry.\"    must display the following acknowledgement:
4401a4eb82SKenneth D. Merry.\"	This product includes software developed by HD Associates
4501a4eb82SKenneth D. Merry.\" 4. Neither the name of the HD Associates nor the names of its contributors
4601a4eb82SKenneth D. Merry.\"    may be used to endorse or promote products derived from this software
4701a4eb82SKenneth D. Merry.\"    without specific prior written permission.
4801a4eb82SKenneth D. Merry.\"
4901a4eb82SKenneth D. Merry.\" THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
5001a4eb82SKenneth D. Merry.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5101a4eb82SKenneth D. Merry.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5201a4eb82SKenneth D. Merry.\" ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
5301a4eb82SKenneth D. Merry.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5401a4eb82SKenneth D. Merry.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5501a4eb82SKenneth D. Merry.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5601a4eb82SKenneth D. Merry.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5701a4eb82SKenneth D. Merry.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5801a4eb82SKenneth D. Merry.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5901a4eb82SKenneth D. Merry.\" SUCH DAMAGE.
6001a4eb82SKenneth D. Merry.\"
6101a4eb82SKenneth D. Merry.\"
6287b3dc51SEnji Cooper.Dd March 13, 2017
6301a4eb82SKenneth D. Merry.Dt CAM_CDBPARSE 3
64aa12cea2SUlrich Spörlein.Os
6501a4eb82SKenneth D. Merry.Sh NAME
6601a4eb82SKenneth D. Merry.Nm csio_build ,
6701a4eb82SKenneth D. Merry.Nm csio_build_visit ,
6801a4eb82SKenneth D. Merry.Nm csio_decode ,
6901a4eb82SKenneth D. Merry.Nm csio_decode_visit ,
7001a4eb82SKenneth D. Merry.Nm buff_decode ,
7101a4eb82SKenneth D. Merry.Nm buff_decode_visit ,
7201a4eb82SKenneth D. Merry.Nm csio_encode ,
7301a4eb82SKenneth D. Merry.Nm csio_encode_visit ,
7401a4eb82SKenneth D. Merry.Nm buff_encode_visit
7501a4eb82SKenneth D. Merry.Nd CAM user library SCSI buffer parsing routines
76c8baaf18SAlexey Zelkin.Sh LIBRARY
77c8baaf18SAlexey Zelkin.Lb libcam
7801a4eb82SKenneth D. Merry.Sh SYNOPSIS
7932eef9aeSRuslan Ermilov.In stdio.h
8032eef9aeSRuslan Ermilov.In camlib.h
8101a4eb82SKenneth D. Merry.Ft int
8201a4eb82SKenneth D. Merry.Fo csio_build
8301a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
846b99842aSEd Schouten.Fa "uint8_t *data_ptr"
856b99842aSEd Schouten.Fa "uint32_t dxfer_len"
866b99842aSEd Schouten.Fa "uint32_t flags"
8701a4eb82SKenneth D. Merry.Fa "int retry_count"
8801a4eb82SKenneth D. Merry.Fa "int timeout"
89cb28eb78SKelly Yancey.Fa "const char *cmd_spec"
9001a4eb82SKenneth D. Merry.Fa "..."
9101a4eb82SKenneth D. Merry.Fc
9201a4eb82SKenneth D. Merry.Ft int
9301a4eb82SKenneth D. Merry.Fo csio_build_visit
9401a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
956b99842aSEd Schouten.Fa "uint8_t *data_ptr"
966b99842aSEd Schouten.Fa "uint32_t dxfer_len"
976b99842aSEd Schouten.Fa "uint32_t flags"
9801a4eb82SKenneth D. Merry.Fa "int retry_count"
9901a4eb82SKenneth D. Merry.Fa "int timeout"
100cb28eb78SKelly Yancey.Fa "const char *cmd_spec"
10101a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
10201a4eb82SKenneth D. Merry.Fa "void *gethook"
10301a4eb82SKenneth D. Merry.Fc
10401a4eb82SKenneth D. Merry.Ft int
10501a4eb82SKenneth D. Merry.Fo csio_decode
10601a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
107cb28eb78SKelly Yancey.Fa "const char *fmt"
10801a4eb82SKenneth D. Merry.Fa "..."
10901a4eb82SKenneth D. Merry.Fc
11001a4eb82SKenneth D. Merry.Ft int
11101a4eb82SKenneth D. Merry.Fo csio_decode_visit
11201a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
113cb28eb78SKelly Yancey.Fa "const char *fmt"
11401a4eb82SKenneth D. Merry.Fa "void (*arg_put)(void *hook"
11501a4eb82SKenneth D. Merry.Fa "int letter"
11601a4eb82SKenneth D. Merry.Fa "void *val"
11701a4eb82SKenneth D. Merry.Fa "int count"
11801a4eb82SKenneth D. Merry.Fa "char *name)"
11901a4eb82SKenneth D. Merry.Fa "void *puthook"
12001a4eb82SKenneth D. Merry.Fc
12101a4eb82SKenneth D. Merry.Ft int
12201a4eb82SKenneth D. Merry.Fo buff_decode
1236b99842aSEd Schouten.Fa "uint8_t *buff"
12401a4eb82SKenneth D. Merry.Fa "size_t len"
125cb28eb78SKelly Yancey.Fa "const char *fmt"
12601a4eb82SKenneth D. Merry.Fa "..."
12701a4eb82SKenneth D. Merry.Fc
12801a4eb82SKenneth D. Merry.Ft int
12901a4eb82SKenneth D. Merry.Fo buff_decode_visit
1306b99842aSEd Schouten.Fa "uint8_t *buff"
13101a4eb82SKenneth D. Merry.Fa "size_t len"
132cb28eb78SKelly Yancey.Fa "const char *fmt"
13301a4eb82SKenneth D. Merry.Fa "void (*arg_put)(void *, int, void *, int, char *)"
13401a4eb82SKenneth D. Merry.Fa "void *puthook"
13501a4eb82SKenneth D. Merry.Fc
13601a4eb82SKenneth D. Merry.Ft int
13701a4eb82SKenneth D. Merry.Fo csio_encode
13801a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
139cb28eb78SKelly Yancey.Fa "const char *fmt"
14001a4eb82SKenneth D. Merry.Fa "..."
14101a4eb82SKenneth D. Merry.Fc
14201a4eb82SKenneth D. Merry.Ft int
14301a4eb82SKenneth D. Merry.Fo csio_encode_visit
14401a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio"
145cb28eb78SKelly Yancey.Fa "const char *fmt"
14601a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
14701a4eb82SKenneth D. Merry.Fa "void *gethook"
14801a4eb82SKenneth D. Merry.Fc
14901a4eb82SKenneth D. Merry.Ft int
15001a4eb82SKenneth D. Merry.Fo buff_encode_visit
1516b99842aSEd Schouten.Fa "uint8_t *buff"
15201a4eb82SKenneth D. Merry.Fa "size_t len"
153cb28eb78SKelly Yancey.Fa "const char *fmt"
15401a4eb82SKenneth D. Merry.Fa "int (*arg_get)(void *hook, char *field_name)"
15501a4eb82SKenneth D. Merry.Fa "void *gethook"
15601a4eb82SKenneth D. Merry.Fc
15701a4eb82SKenneth D. Merry.Sh DESCRIPTION
15801a4eb82SKenneth D. MerryThe CAM buffer/CDB encoding and decoding routines provide a relatively easy
15901a4eb82SKenneth D. Merrymigration path for userland
16001a4eb82SKenneth D. Merry.Tn SCSI
16101a4eb82SKenneth D. Merryapplications written with the similarly-named
16201a4eb82SKenneth D. Merry.Va scsireq_ Ns *
163b5c508fbSRuslan Ermilovfunctions from the old
164b5c508fbSRuslan Ermilov.Fx
16501a4eb82SKenneth D. Merry.Tn SCSI
16601a4eb82SKenneth D. Merrylayer.
16701a4eb82SKenneth D. Merry.Pp
16801a4eb82SKenneth D. MerryThese functions may be used in new applications, but users may find it
16901a4eb82SKenneth D. Merryeasier to use the various SCSI CCB building functions included with the
17001a4eb82SKenneth D. Merry.Xr cam 3
17187b3dc51SEnji Cooperlibrary, e.g., \&
17201a4eb82SKenneth D. Merry.Fn cam_fill_csio ,
17301a4eb82SKenneth D. Merry.Fn scsi_start_stop ,
17401a4eb82SKenneth D. Merryand
17587b3dc51SEnji Cooper.Fn scsi_read_write .
17601a4eb82SKenneth D. Merry.Pp
17701a4eb82SKenneth D. Merry.Fn csio_build
17801a4eb82SKenneth D. Merrybuilds up a
17901a4eb82SKenneth D. Merry.Va ccb_scsiio
18001a4eb82SKenneth D. Merrystructure based on the information provided in
18101a4eb82SKenneth D. Merrythe variable argument list.
18201a4eb82SKenneth D. MerryIt gracefully handles a NULL
18301a4eb82SKenneth D. Merry.Fa data_ptr
18401a4eb82SKenneth D. Merryargument passed to it.
18501a4eb82SKenneth D. Merry.Pp
18601a4eb82SKenneth D. Merry.Fa dxfer_len
18701a4eb82SKenneth D. Merryis the length of the data phase; the data transfer direction is
18801a4eb82SKenneth D. Merrydetermined by the
18901a4eb82SKenneth D. Merry.Fa flags
19001a4eb82SKenneth D. Merryargument.
19101a4eb82SKenneth D. Merry.Pp
19201a4eb82SKenneth D. Merry.Fa data_ptr
19301a4eb82SKenneth D. Merryis the data buffer used during the
19401a4eb82SKenneth D. Merry.Tn SCSI
1951a0a9345SRuslan Ermilovdata phase.
1961a0a9345SRuslan ErmilovIf no data is to be
19701a4eb82SKenneth D. Merrytransferred for the
19801a4eb82SKenneth D. Merry.Tn SCSI
1991a0a9345SRuslan Ermilovcommand in question, this should be set to NULL.
2001a0a9345SRuslan ErmilovIf there is data to
20101a4eb82SKenneth D. Merrytransfer for the command, this buffer must be at least
20201a4eb82SKenneth D. Merry.Fa dxfer_len
20301a4eb82SKenneth D. Merrylong.
20401a4eb82SKenneth D. Merry.Pp
20501a4eb82SKenneth D. Merry.Fa flags
20601a4eb82SKenneth D. Merryare the flags defined in
207fe08efe6SRuslan Ermilov.In cam/cam_ccb.h :
20801a4eb82SKenneth D. Merry.Bd -literal
20901a4eb82SKenneth D. Merry/* Common CCB header */
21001a4eb82SKenneth D. Merry/* CAM CCB flags */
21101a4eb82SKenneth D. Merrytypedef enum {
21201a4eb82SKenneth D. Merry     CAM_CDB_POINTER       = 0x00000001,/* The CDB field is a pointer    */
21301a4eb82SKenneth D. Merry     CAM_SCATTER_VALID     = 0x00000010,/* Scatter/gather list is valid  */
21401a4eb82SKenneth D. Merry     CAM_DIS_AUTOSENSE     = 0x00000020,/* Disable autosense feature     */
21501a4eb82SKenneth D. Merry     CAM_DIR_RESV          = 0x00000000,/* Data direction (00:reserved)  */
21601a4eb82SKenneth D. Merry     CAM_DIR_IN            = 0x00000040,/* Data direction (01:DATA IN)   */
21701a4eb82SKenneth D. Merry     CAM_DIR_OUT           = 0x00000080,/* Data direction (10:DATA OUT)  */
21801a4eb82SKenneth D. Merry     CAM_DIR_NONE          = 0x000000C0,/* Data direction (11:no data)   */
21901a4eb82SKenneth D. Merry     CAM_DIR_MASK          = 0x000000C0,/* Data direction Mask		 */
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_DATA_PHYS         = 0x00200000,/* SG/Buffer data ptrs are phys. */
23057bd0fc6SJens Schweikhardt     CAM_CDB_PHYS          = 0x00400000,/* CDB pointer is physical	 */
23101a4eb82SKenneth D. Merry
23201a4eb82SKenneth D. Merry/* Host target Mode flags */
233*9ac30e0bSWarner Losh     CAM_SEND_SENSE        = 0x08000000,/* Send sense data with status   */
23401a4eb82SKenneth D. Merry     CAM_SEND_STATUS       = 0x80000000,/* Send status after data phase  */
23501a4eb82SKenneth D. Merry} ccb_flags;
23601a4eb82SKenneth D. Merry.Ed
23701a4eb82SKenneth D. Merry.Pp
2381a0a9345SRuslan ErmilovMultiple flags should be ORed together.
2391a0a9345SRuslan ErmilovAny of the CCB flags may be used,
24001a4eb82SKenneth D. Merryalthough it is worth noting several important ones here:
24101a4eb82SKenneth D. Merry.Bl -tag -width CAM_PASS_ERR_RECOVER
24201a4eb82SKenneth D. Merry.It Dv CAM_DIR_IN
2431a0a9345SRuslan ErmilovThis indicates that the operation in question is a read operation.
2441a0a9345SRuslan Ermilovi.e.,
24501a4eb82SKenneth D. Merrydata is being read from the
24601a4eb82SKenneth D. Merry.Tn SCSI
24701a4eb82SKenneth D. Merrydevice to the user-supplied buffer.
24801a4eb82SKenneth D. Merry.It Dv CAM_DIR_OUT
2491a0a9345SRuslan ErmilovThis indicates that the operation is a write operation.
2501a0a9345SRuslan Ermilovi.e., data is being
25101a4eb82SKenneth D. Merrywritten from the user-supplied buffer to the device.
25201a4eb82SKenneth D. Merry.It Dv CAM_DIR_NONE
25301a4eb82SKenneth D. MerryThis indicates that there is no data to be transferred for this command.
25401a4eb82SKenneth D. Merry.It Dv CAM_DEV_QFRZDIS
25501a4eb82SKenneth D. MerryThis flag disables device queue freezing as an error recovery mechanism.
25601a4eb82SKenneth D. Merry.It Dv CAM_PASS_ERR_RECOVER
25701a4eb82SKenneth D. MerryThis flag tells the
25801a4eb82SKenneth D. Merry.Xr pass 4
2591a0a9345SRuslan Ermilovdriver to enable error recovery.
2601a0a9345SRuslan ErmilovThe default is to not perform error
2610227791bSRuslan Ermilovrecovery, which means that the retry count will not be honored without this
26201a4eb82SKenneth D. Merryflag, among other things.
26301a4eb82SKenneth D. Merry.It Dv CAM_DATA_PHYS
26401a4eb82SKenneth D. MerryThis indicates that the address contained in
26501a4eb82SKenneth D. Merry.Fa data_ptr
26601a4eb82SKenneth D. Merryis a physical address, not a virtual address.
26701a4eb82SKenneth D. Merry.El
26801a4eb82SKenneth D. Merry.Pp
26901a4eb82SKenneth D. MerryThe
27001a4eb82SKenneth D. Merry.Fa retry_count
2711a0a9345SRuslan Ermilovtells the kernel how many times to retry the command in question.
2721a0a9345SRuslan ErmilovThe
27301a4eb82SKenneth D. Merryretry count is ignored unless the
27401a4eb82SKenneth D. Merry.Xr pass 4
27501a4eb82SKenneth D. Merrydriver is told to enable error recovery via the
27601a4eb82SKenneth D. Merry.Dv CAM_PASS_ERR_RECOVER
27701a4eb82SKenneth D. Merryflag.
27801a4eb82SKenneth D. Merry.Pp
27901a4eb82SKenneth D. MerryThe
28001a4eb82SKenneth D. Merry.Fa timeout
2811a0a9345SRuslan Ermilovtells the kernel how long to wait for the given command to complete.
2821a0a9345SRuslan ErmilovIf
2830227791bSRuslan Ermilovthe timeout expires and the command has not completed, the CCB will be
28401a4eb82SKenneth D. Merryreturned from the kernel with an appropriate error status.
28501a4eb82SKenneth D. Merry.Pp
28601a4eb82SKenneth D. Merry.Fa cmd_spec
28701a4eb82SKenneth D. Merryis a CDB format specifier used to build up the SCSI CDB.
2881a0a9345SRuslan ErmilovThis text string is made up of a list of field specifiers.
2891a0a9345SRuslan ErmilovField
29001a4eb82SKenneth D. Merryspecifiers specify the value for each CDB field (including indicating
29101a4eb82SKenneth D. Merrythat the value be taken from the next argument in the
29201a4eb82SKenneth D. Merryvariable argument list), the width
2931a0a9345SRuslan Ermilovof the field in bits or bytes, and an optional name.
2941a0a9345SRuslan ErmilovWhite space is
29501a4eb82SKenneth D. Merryignored, and the pound sign ('#') introduces a comment that ends at the
29601a4eb82SKenneth D. Merryend of the current line.
29701a4eb82SKenneth D. Merry.Pp
29801a4eb82SKenneth D. MerryThe optional name is the first part of a field specifier and
2991a0a9345SRuslan Ermilovis in curly braces.
3001a0a9345SRuslan ErmilovThe text in curly braces in this example are
30101a4eb82SKenneth D. Merrythe names:
302953ae31aSAlexander Langer.Dl "{PS} v:b1 {Reserved} 0:b1 {Page Code} v:b6 # Mode select page"
30301a4eb82SKenneth D. Merry.Pp
30401a4eb82SKenneth D. MerryThis field specifier has two one bit fields and one six bit field.
30501a4eb82SKenneth D. MerryThe second one bit field is the constant value 0 and the first
30601a4eb82SKenneth D. Merryone bit field and the six bit field are taken from the variable
30701a4eb82SKenneth D. Merryargument list.
30801a4eb82SKenneth D. MerryMulti byte fields are swapped into the SCSI byte order in the
30901a4eb82SKenneth D. MerryCDB and white space is ignored.
31001a4eb82SKenneth D. Merry.Pp
31101a4eb82SKenneth D. MerryWhen the field is a hex value or the letter v, (e.g.,
31201a4eb82SKenneth D. Merry.Fa "1A"
31301a4eb82SKenneth D. Merryor
31401a4eb82SKenneth D. Merry.Fa "v" )
31501a4eb82SKenneth D. Merrythen a single byte value
31601a4eb82SKenneth D. Merryis copied to the next unused byte of the CDB.
31701a4eb82SKenneth D. MerryWhen the letter
31801a4eb82SKenneth D. Merry.Fa v
31901a4eb82SKenneth D. Merryis used the next integer argument is taken from the variable argument list
32001a4eb82SKenneth D. Merryand that value used.
32101a4eb82SKenneth D. Merry.Pp
32201a4eb82SKenneth D. MerryA constant hex value followed by a field width specifier or the letter
32301a4eb82SKenneth D. Merry.Fa v
32401a4eb82SKenneth D. Merryfollowed by a field width specifier (e.g.,
32501a4eb82SKenneth D. Merry.Fa 3:4 ,
32601a4eb82SKenneth D. Merry.Fa 3:b4 ,
32701a4eb82SKenneth D. Merry.Fa 3:i3 ,
328382114daSRuslan Ermilov.Fa v:i3 )
32901a4eb82SKenneth D. Merryspecifies a field of a given bit or byte width.
33001a4eb82SKenneth D. MerryEither the constant value or (for the V specifier) the next integer value from
33101a4eb82SKenneth D. Merrythe variable argument list is copied to the next unused
33201a4eb82SKenneth D. Merrybits or bytes of the CDB.
33301a4eb82SKenneth D. Merry.Pp
33401a4eb82SKenneth D. MerryA decimal number or the letter
33501a4eb82SKenneth D. Merry.Fa b
33601a4eb82SKenneth D. Merryfollowed by a decimal number field width indicates a bit field of that width.
33701a4eb82SKenneth D. MerryThe bit fields are packed as tightly as possible beginning with the
33801a4eb82SKenneth D. Merryhigh bit (so that it reads the same as the SCSI spec), and a new byte of
33901a4eb82SKenneth D. Merrythe CDB is started whenever a byte fills completely or when an
34001a4eb82SKenneth D. Merry.Fa i
34101a4eb82SKenneth D. Merryfield is encountered.
34201a4eb82SKenneth D. Merry.Pp
34301a4eb82SKenneth D. MerryA field width specifier consisting of the letter
34401a4eb82SKenneth D. Merry.Fa i
34501a4eb82SKenneth D. Merryfollowed by either
34601a4eb82SKenneth D. Merry1, 2, 3 or 4 indicates a 1, 2, 3 or 4 byte integral value that must
34701a4eb82SKenneth D. Merrybe swapped into SCSI byte order (MSB first).
34801a4eb82SKenneth D. Merry.Pp
34901a4eb82SKenneth D. MerryFor the
35001a4eb82SKenneth D. Merry.Fa v
35101a4eb82SKenneth D. Merryfield specifier the next integer argument is taken from the variable argument
35201a4eb82SKenneth D. Merrylist and that value is used swapped into SCSI byte order.
35301a4eb82SKenneth D. Merry.Pp
35401a4eb82SKenneth D. Merry.Fn csio_build_visit
35501a4eb82SKenneth D. Merryoperates similarly to
35601a4eb82SKenneth D. Merry.Fn csio_build ,
35701a4eb82SKenneth D. Merryexcept that the values to substitute for variable arguments in
35801a4eb82SKenneth D. Merry.Fa cmd_spec
35901a4eb82SKenneth D. Merryare retrieved via the
36001a4eb82SKenneth D. Merry.Fn arg_get
36101a4eb82SKenneth D. Merryfunction passed in to
36201a4eb82SKenneth D. Merry.Fn csio_build_visit
36301a4eb82SKenneth D. Merryinstead of via
36401a4eb82SKenneth D. Merry.Xr stdarg 3 .
36501a4eb82SKenneth D. MerryThe
36601a4eb82SKenneth D. Merry.Fn arg_get
36701a4eb82SKenneth D. Merryfunction takes two arguments:
36801a4eb82SKenneth D. Merry.Bl -tag -width field_name
36901a4eb82SKenneth D. Merry.It Fa gethook
37001a4eb82SKenneth D. Merryis passed into the
37101a4eb82SKenneth D. Merry.Fn arg_get
3721a0a9345SRuslan Ermilovfunction at each invocation.
3731a0a9345SRuslan ErmilovThis enables the
37401a4eb82SKenneth D. Merry.Fn arg_get
37501a4eb82SKenneth D. Merryfunction to keep some state in between calls without using global or static
37601a4eb82SKenneth D. Merryvariables.
37701a4eb82SKenneth D. Merry.It Fa field_name
37801a4eb82SKenneth D. Merryis the field name supplied in
37901a4eb82SKenneth D. Merry.Fa fmt ,
38001a4eb82SKenneth D. Merryif any.
38101a4eb82SKenneth D. Merry.El
38201a4eb82SKenneth D. Merry.Pp
38301a4eb82SKenneth D. Merry.Fn csio_decode
38401a4eb82SKenneth D. Merryis used to decode information from the data in phase of the SCSI
38501a4eb82SKenneth D. Merrytransfer.
38601a4eb82SKenneth D. Merry.Pp
38701a4eb82SKenneth D. MerryThe decoding is similar to
38801a4eb82SKenneth D. Merrythe command specifier processing of
38901a4eb82SKenneth D. Merry.Fn csio_build
39001a4eb82SKenneth D. Merryexcept that the data is extracted from the data pointed to by
39101a4eb82SKenneth D. Merry.Fa csio->data_ptr .
39201a4eb82SKenneth D. MerryThe stdarg list should be pointers to integers instead of integer
39301a4eb82SKenneth D. Merryvalues.
39401a4eb82SKenneth D. MerryA seek field type and a suppression modifier are added.
39501a4eb82SKenneth D. MerryThe
39601a4eb82SKenneth D. Merry.Fa *
39701a4eb82SKenneth D. Merrysuppression modifier (e.g.,
39801a4eb82SKenneth D. Merry.Fa *i3
39901a4eb82SKenneth D. Merryor
40001a4eb82SKenneth D. Merry.Fa *b4 )
40101a4eb82SKenneth D. Merrysuppresses assignment from the field and can be used to skip
40201a4eb82SKenneth D. Merryover bytes or bits in the data, without having to copy
40301a4eb82SKenneth D. Merrythem to a dummy variable in the arg list.
40401a4eb82SKenneth D. Merry.Pp
40501a4eb82SKenneth D. MerryThe seek field type
40601a4eb82SKenneth D. Merry.Fa s
40701a4eb82SKenneth D. Merrypermits you to skip over data.
40894ba280cSRuslan ErmilovThis seeks to an absolute position
40994ba280cSRuslan Ermilov.Pq Fa s3
41094ba280cSRuslan Ermilovor a relative position
41194ba280cSRuslan Ermilov.Pq Fa s+3
41201a4eb82SKenneth D. Merryin the data, based on whether or not the presence of the '+' sign.
41301a4eb82SKenneth D. MerryThe seek value can be specified as
41401a4eb82SKenneth D. Merry.Fa v
41501a4eb82SKenneth D. Merryand the next integer value from the argument list will be
41601a4eb82SKenneth D. Merryused as the seek value.
41701a4eb82SKenneth D. Merry.Pp
41801a4eb82SKenneth D. Merry.Fn csio_decode_visit
41901a4eb82SKenneth D. Merryoperates like
42001a4eb82SKenneth D. Merry.Fn csio_decode
42101a4eb82SKenneth D. Merryexcept that instead of placing the decoded contents of the buffer in
42257bd0fc6SJens Schweikhardtvariadic arguments, the decoded buffer contents are returned to the user
42301a4eb82SKenneth D. Merryvia the
42401a4eb82SKenneth D. Merry.Fn arg_put
42501a4eb82SKenneth D. Merryfunction that is passed in.
42601a4eb82SKenneth D. MerryThe
42701a4eb82SKenneth D. Merry.Fn arg_put
42801a4eb82SKenneth D. Merryfunction takes several arguments:
42901a4eb82SKenneth D. Merry.Bl -tag -width letter
43001a4eb82SKenneth D. Merry.It Fa hook
43101a4eb82SKenneth D. MerryThe "hook" is a mechanism to allow the
43201a4eb82SKenneth D. Merry.Fn arg_put
43301a4eb82SKenneth D. Merryfunction to save state in between calls.
43401a4eb82SKenneth D. Merry.It Fa letter
43501a4eb82SKenneth D. Merryis the letter describing the format of the argument being passed into the
43601a4eb82SKenneth D. Merryfunction.
43701a4eb82SKenneth D. Merry.It Fa val
43801a4eb82SKenneth D. Merryis a void pointer to the value being passed into the function.
43901a4eb82SKenneth D. Merry.It Fa count
4407e32b20dSKelly Yanceyis the size of the value being passed into the
44101a4eb82SKenneth D. Merry.Fn arg_put
4421a0a9345SRuslan Ermilovfunction.
4431a0a9345SRuslan ErmilovThe argument format determines the unit of measure.
44401a4eb82SKenneth D. Merry.It Fa name
44501a4eb82SKenneth D. MerryThis is a text description of the field, if one was provided in the
44601a4eb82SKenneth D. Merry.Fa fmt .
44701a4eb82SKenneth D. Merry.El
44801a4eb82SKenneth D. Merry.Pp
44901a4eb82SKenneth D. Merry.Fn buff_decode
45001a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method
45101a4eb82SKenneth D. Merrydescribed above for
45201a4eb82SKenneth D. Merry.Fn csio_decode .
45301a4eb82SKenneth D. Merry.Pp
45401a4eb82SKenneth D. Merry.Fn buff_decode_visit
45501a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method described above for
45601a4eb82SKenneth D. Merry.Fn csio_decode_visit .
45701a4eb82SKenneth D. Merry.Pp
45801a4eb82SKenneth D. Merry.Fn csio_encode
45901a4eb82SKenneth D. Merryencodes the
46001a4eb82SKenneth D. Merry.Fa data_ptr
46101a4eb82SKenneth D. Merryportion (not the CDB!) of a
46201a4eb82SKenneth D. Merry.Va ccb_scsiio
46301a4eb82SKenneth D. Merrystructure, using the method described above for
46401a4eb82SKenneth D. Merry.Fn csio_build .
46501a4eb82SKenneth D. Merry.Pp
46601a4eb82SKenneth D. Merry.Fn csio_encode_visit
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_visit .
47301a4eb82SKenneth D. Merry.Pp
47401a4eb82SKenneth D. Merry.Fn buff_encode_visit
47501a4eb82SKenneth D. Merryencodes an arbitrary data pointer, using the method described
47601a4eb82SKenneth D. Merryabove for
47701a4eb82SKenneth D. Merry.Fn csio_build_visit .
47801a4eb82SKenneth D. Merry.Sh RETURN VALUES
47901a4eb82SKenneth D. Merry.Fn csio_build ,
48001a4eb82SKenneth D. Merry.Fn csio_build_visit ,
48101a4eb82SKenneth D. Merry.Fn csio_encode ,
48201a4eb82SKenneth D. Merry.Fn csio_encode_visit ,
48301a4eb82SKenneth D. Merryand
48401a4eb82SKenneth D. Merry.Fn buff_encode_visit
48501a4eb82SKenneth D. Merryreturn the number of fields processed.
48601a4eb82SKenneth D. Merry.Pp
48701a4eb82SKenneth D. Merry.Fn csio_decode ,
48801a4eb82SKenneth D. Merry.Fn csio_decode_visit ,
48901a4eb82SKenneth D. Merry.Fn buff_decode ,
49001a4eb82SKenneth D. Merryand
49101a4eb82SKenneth D. Merry.Fn buff_decode_visit
49201a4eb82SKenneth D. Merryreturn the number of assignments performed.
49301a4eb82SKenneth D. Merry.Sh SEE ALSO
49401a4eb82SKenneth D. Merry.Xr cam 3 ,
49501a4eb82SKenneth D. Merry.Xr pass 4 ,
49601a4eb82SKenneth D. Merry.Xr camcontrol 8
49701a4eb82SKenneth D. Merry.Sh HISTORY
49801a4eb82SKenneth D. MerryThe CAM versions of these functions are based upon similar functions
499b5c508fbSRuslan Ermilovimplemented for the old
500b5c508fbSRuslan Ermilov.Fx
50101a4eb82SKenneth D. Merry.Tn SCSI
5021a0a9345SRuslan Ermilovlayer.
5031a0a9345SRuslan ErmilovThe encoding/decoding functions in the old
50401a4eb82SKenneth D. Merry.Tn SCSI
50587b3dc51SEnji Coopercode were written by
50687b3dc51SEnji Cooper.An Peter Dufault Aq Mt dufault@hda.com .
50701a4eb82SKenneth D. Merry.Pp
50801a4eb82SKenneth D. MerryMany systems have comparable interfaces to permit a user to construct a
50901a4eb82SKenneth D. MerrySCSI command in user space.
51001a4eb82SKenneth D. Merry.Pp
51101a4eb82SKenneth D. MerryThe old
51201a4eb82SKenneth D. Merry.Va scsireq
51387b3dc51SEnji Cooperdata structure was almost identical to the SGI /dev/scsi data structure.
51487b3dc51SEnji CooperIf anyone knows the name of the authors it should go here;
51587b3dc51SEnji CooperPeter Dufault
51687b3dc51SEnji Cooperfirst read about it in a 1989 Sun Expert magazine.
51701a4eb82SKenneth D. Merry.Pp
51801a4eb82SKenneth D. MerryThe new CCB data structures are derived from the CAM-2 and CAM-3
51901a4eb82SKenneth D. Merryspecifications.
52001a4eb82SKenneth D. Merry.Pp
521753d686dSRuslan Ermilov.An Peter Dufault
522753d686dSRuslan Ermilovimplemented a clone of SGI's interface in
523753d686dSRuslan Ermilov.Bx 386
524753d686dSRuslan Ermilovthat
525b5c508fbSRuslan Ermilovled to the original
526b5c508fbSRuslan Ermilov.Fx
52701a4eb82SKenneth D. Merry.Tn SCSI
52801a4eb82SKenneth D. Merrylibrary and the related kernel ioctl.
52987b3dc51SEnji CooperIf anyone needs that for compatibility, contact
53087b3dc51SEnji Cooper.Mt dufault@hda.com .
53101a4eb82SKenneth D. Merry.Sh AUTHORS
53287b3dc51SEnji Cooper.An -nosplit
53387b3dc51SEnji Cooper.An Kenneth Merry Aq Mt ken@FreeBSD.org
53487b3dc51SEnji Cooperimplemented the CAM versions of these encoding and decoding functions.
53587b3dc51SEnji CooperThis current work is based upon earlier work by
53687b3dc51SEnji Cooper.An Peter Dufault Aq Mt dufault@hda.com .
53701a4eb82SKenneth D. Merry.Sh BUGS
53801a4eb82SKenneth D. MerryThere should probably be a function that encodes both the CDB and the data
53901a4eb82SKenneth D. Merrybuffer portions of a
54001a4eb82SKenneth D. Merry.Tn SCSI
5411a0a9345SRuslan ErmilovCCB.
5421a0a9345SRuslan ErmilovI discovered this while implementing the arbitrary command execution
54301a4eb82SKenneth D. Merrycode in
54401a4eb82SKenneth D. Merry.Xr camcontrol 8 ,
5450227791bSRuslan Ermilovbut I have not yet had time to implement such a function.
54601a4eb82SKenneth D. Merry.Pp
5470227791bSRuslan ErmilovSome of the CCB flag descriptions really do not belong here.
5481a0a9345SRuslan ErmilovRather they
5491a0a9345SRuslan Ermilovbelong in a generic CCB man page.
5500227791bSRuslan ErmilovSince that man page has not yet been
55101a4eb82SKenneth D. Merrywritten, the shorter descriptions here will have to suffice.
552