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.\" 6487b3dc51SEnji Cooper.Dd March 13, 2017 6501a4eb82SKenneth D. Merry.Dt CAM_CDBPARSE 3 66aa12cea2SUlrich Spörlein.Os 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 8132eef9aeSRuslan Ermilov.In stdio.h 8232eef9aeSRuslan Ermilov.In camlib.h 8301a4eb82SKenneth D. Merry.Ft int 8401a4eb82SKenneth D. Merry.Fo csio_build 8501a4eb82SKenneth D. Merry.Fa "struct ccb_scsiio *csio" 866b99842aSEd Schouten.Fa "uint8_t *data_ptr" 876b99842aSEd Schouten.Fa "uint32_t dxfer_len" 886b99842aSEd Schouten.Fa "uint32_t flags" 8901a4eb82SKenneth D. Merry.Fa "int retry_count" 9001a4eb82SKenneth D. Merry.Fa "int timeout" 91cb28eb78SKelly Yancey.Fa "const 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" 976b99842aSEd Schouten.Fa "uint8_t *data_ptr" 986b99842aSEd Schouten.Fa "uint32_t dxfer_len" 996b99842aSEd Schouten.Fa "uint32_t flags" 10001a4eb82SKenneth D. Merry.Fa "int retry_count" 10101a4eb82SKenneth D. Merry.Fa "int timeout" 102cb28eb78SKelly Yancey.Fa "const 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" 109cb28eb78SKelly Yancey.Fa "const 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" 115cb28eb78SKelly Yancey.Fa "const 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 1256b99842aSEd Schouten.Fa "uint8_t *buff" 12601a4eb82SKenneth D. Merry.Fa "size_t len" 127cb28eb78SKelly Yancey.Fa "const char *fmt" 12801a4eb82SKenneth D. Merry.Fa "..." 12901a4eb82SKenneth D. Merry.Fc 13001a4eb82SKenneth D. Merry.Ft int 13101a4eb82SKenneth D. Merry.Fo buff_decode_visit 1326b99842aSEd Schouten.Fa "uint8_t *buff" 13301a4eb82SKenneth D. Merry.Fa "size_t len" 134cb28eb78SKelly Yancey.Fa "const 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" 141cb28eb78SKelly Yancey.Fa "const 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" 147cb28eb78SKelly Yancey.Fa "const 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 1536b99842aSEd Schouten.Fa "uint8_t *buff" 15401a4eb82SKenneth D. Merry.Fa "size_t len" 155cb28eb78SKelly Yancey.Fa "const 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 * 165b5c508fbSRuslan Ermilovfunctions from the old 166b5c508fbSRuslan Ermilov.Fx 16701a4eb82SKenneth D. Merry.Tn SCSI 16801a4eb82SKenneth D. Merrylayer. 16901a4eb82SKenneth D. Merry.Pp 17001a4eb82SKenneth D. MerryThese functions may be used in new applications, but users may find it 17101a4eb82SKenneth D. Merryeasier to use the various SCSI CCB building functions included with the 17201a4eb82SKenneth D. Merry.Xr cam 3 17387b3dc51SEnji Cooperlibrary, e.g., \& 17401a4eb82SKenneth D. Merry.Fn cam_fill_csio , 17501a4eb82SKenneth D. Merry.Fn scsi_start_stop , 17601a4eb82SKenneth D. Merryand 17787b3dc51SEnji Cooper.Fn scsi_read_write . 17801a4eb82SKenneth D. Merry.Pp 17901a4eb82SKenneth D. Merry.Fn csio_build 18001a4eb82SKenneth D. Merrybuilds up a 18101a4eb82SKenneth D. Merry.Va ccb_scsiio 18201a4eb82SKenneth D. Merrystructure based on the information provided in 18301a4eb82SKenneth D. Merrythe variable argument list. 18401a4eb82SKenneth D. MerryIt gracefully handles a NULL 18501a4eb82SKenneth D. Merry.Fa data_ptr 18601a4eb82SKenneth D. Merryargument passed to it. 18701a4eb82SKenneth D. Merry.Pp 18801a4eb82SKenneth D. Merry.Fa dxfer_len 18901a4eb82SKenneth D. Merryis the length of the data phase; the data transfer direction is 19001a4eb82SKenneth D. Merrydetermined by the 19101a4eb82SKenneth D. Merry.Fa flags 19201a4eb82SKenneth D. Merryargument. 19301a4eb82SKenneth D. Merry.Pp 19401a4eb82SKenneth D. Merry.Fa data_ptr 19501a4eb82SKenneth D. Merryis the data buffer used during the 19601a4eb82SKenneth D. Merry.Tn SCSI 1971a0a9345SRuslan Ermilovdata phase. 1981a0a9345SRuslan ErmilovIf no data is to be 19901a4eb82SKenneth D. Merrytransferred for the 20001a4eb82SKenneth D. Merry.Tn SCSI 2011a0a9345SRuslan Ermilovcommand in question, this should be set to NULL. 2021a0a9345SRuslan ErmilovIf there is data to 20301a4eb82SKenneth D. Merrytransfer for the command, this buffer must be at least 20401a4eb82SKenneth D. Merry.Fa dxfer_len 20501a4eb82SKenneth D. Merrylong. 20601a4eb82SKenneth D. Merry.Pp 20701a4eb82SKenneth D. Merry.Fa flags 20801a4eb82SKenneth D. Merryare the flags defined in 209fe08efe6SRuslan Ermilov.In cam/cam_ccb.h : 21001a4eb82SKenneth D. Merry.Bd -literal 21101a4eb82SKenneth D. Merry/* Common CCB header */ 21201a4eb82SKenneth D. Merry/* CAM CCB flags */ 21301a4eb82SKenneth D. Merrytypedef enum { 21401a4eb82SKenneth D. Merry CAM_CDB_POINTER = 0x00000001,/* The CDB field is a pointer */ 21501a4eb82SKenneth D. Merry CAM_SCATTER_VALID = 0x00000010,/* Scatter/gather list is valid */ 21601a4eb82SKenneth D. Merry CAM_DIS_AUTOSENSE = 0x00000020,/* Disable autosense feature */ 21701a4eb82SKenneth D. Merry CAM_DIR_RESV = 0x00000000,/* Data direction (00:reserved) */ 21801a4eb82SKenneth D. Merry CAM_DIR_IN = 0x00000040,/* Data direction (01:DATA IN) */ 21901a4eb82SKenneth D. Merry CAM_DIR_OUT = 0x00000080,/* Data direction (10:DATA OUT) */ 22001a4eb82SKenneth D. Merry CAM_DIR_NONE = 0x000000C0,/* Data direction (11:no data) */ 22101a4eb82SKenneth D. Merry CAM_DIR_MASK = 0x000000C0,/* Data direction Mask */ 22201a4eb82SKenneth D. Merry CAM_DEV_QFRZDIS = 0x00000400,/* Disable DEV Q freezing */ 22301a4eb82SKenneth D. Merry CAM_DEV_QFREEZE = 0x00000800,/* Freeze DEV Q on execution */ 22401a4eb82SKenneth D. Merry CAM_HIGH_POWER = 0x00001000,/* Command takes a lot of power */ 22501a4eb82SKenneth D. Merry CAM_SENSE_PTR = 0x00002000,/* Sense data is a pointer */ 22601a4eb82SKenneth D. Merry CAM_SENSE_PHYS = 0x00004000,/* Sense pointer is physical addr*/ 22701a4eb82SKenneth D. Merry CAM_TAG_ACTION_VALID = 0x00008000,/* Use the tag action in this ccb*/ 22801a4eb82SKenneth D. Merry CAM_PASS_ERR_RECOVER = 0x00010000,/* Pass driver does err. recovery*/ 22901a4eb82SKenneth D. Merry CAM_DIS_DISCONNECT = 0x00020000,/* Disable disconnect */ 23001a4eb82SKenneth D. Merry CAM_SG_LIST_PHYS = 0x00040000,/* SG list has physical addrs. */ 23101a4eb82SKenneth D. Merry CAM_DATA_PHYS = 0x00200000,/* SG/Buffer data ptrs are phys. */ 23257bd0fc6SJens Schweikhardt CAM_CDB_PHYS = 0x00400000,/* CDB pointer is physical */ 23301a4eb82SKenneth D. Merry 23401a4eb82SKenneth D. Merry/* Host target Mode flags */ 235*9ac30e0bSWarner Losh CAM_SEND_SENSE = 0x08000000,/* Send sense data with status */ 23601a4eb82SKenneth D. Merry CAM_SEND_STATUS = 0x80000000,/* Send status after data phase */ 23701a4eb82SKenneth D. Merry} ccb_flags; 23801a4eb82SKenneth D. Merry.Ed 23901a4eb82SKenneth D. Merry.Pp 2401a0a9345SRuslan ErmilovMultiple flags should be ORed together. 2411a0a9345SRuslan ErmilovAny of the CCB flags may be used, 24201a4eb82SKenneth D. Merryalthough it is worth noting several important ones here: 24301a4eb82SKenneth D. Merry.Bl -tag -width CAM_PASS_ERR_RECOVER 24401a4eb82SKenneth D. Merry.It Dv CAM_DIR_IN 2451a0a9345SRuslan ErmilovThis indicates that the operation in question is a read operation. 2461a0a9345SRuslan Ermilovi.e., 24701a4eb82SKenneth D. Merrydata is being read from the 24801a4eb82SKenneth D. Merry.Tn SCSI 24901a4eb82SKenneth D. Merrydevice to the user-supplied buffer. 25001a4eb82SKenneth D. Merry.It Dv CAM_DIR_OUT 2511a0a9345SRuslan ErmilovThis indicates that the operation is a write operation. 2521a0a9345SRuslan Ermilovi.e., data is being 25301a4eb82SKenneth D. Merrywritten from the user-supplied buffer to the device. 25401a4eb82SKenneth D. Merry.It Dv CAM_DIR_NONE 25501a4eb82SKenneth D. MerryThis indicates that there is no data to be transferred for this command. 25601a4eb82SKenneth D. Merry.It Dv CAM_DEV_QFRZDIS 25701a4eb82SKenneth D. MerryThis flag disables device queue freezing as an error recovery mechanism. 25801a4eb82SKenneth D. Merry.It Dv CAM_PASS_ERR_RECOVER 25901a4eb82SKenneth D. MerryThis flag tells the 26001a4eb82SKenneth D. Merry.Xr pass 4 2611a0a9345SRuslan Ermilovdriver to enable error recovery. 2621a0a9345SRuslan ErmilovThe default is to not perform error 2630227791bSRuslan Ermilovrecovery, which means that the retry count will not be honored without this 26401a4eb82SKenneth D. Merryflag, among other things. 26501a4eb82SKenneth D. Merry.It Dv CAM_DATA_PHYS 26601a4eb82SKenneth D. MerryThis indicates that the address contained in 26701a4eb82SKenneth D. Merry.Fa data_ptr 26801a4eb82SKenneth D. Merryis a physical address, not a virtual address. 26901a4eb82SKenneth D. Merry.El 27001a4eb82SKenneth D. Merry.Pp 27101a4eb82SKenneth D. MerryThe 27201a4eb82SKenneth D. Merry.Fa retry_count 2731a0a9345SRuslan Ermilovtells the kernel how many times to retry the command in question. 2741a0a9345SRuslan ErmilovThe 27501a4eb82SKenneth D. Merryretry count is ignored unless the 27601a4eb82SKenneth D. Merry.Xr pass 4 27701a4eb82SKenneth D. Merrydriver is told to enable error recovery via the 27801a4eb82SKenneth D. Merry.Dv CAM_PASS_ERR_RECOVER 27901a4eb82SKenneth D. Merryflag. 28001a4eb82SKenneth D. Merry.Pp 28101a4eb82SKenneth D. MerryThe 28201a4eb82SKenneth D. Merry.Fa timeout 2831a0a9345SRuslan Ermilovtells the kernel how long to wait for the given command to complete. 2841a0a9345SRuslan ErmilovIf 2850227791bSRuslan Ermilovthe timeout expires and the command has not completed, the CCB will be 28601a4eb82SKenneth D. Merryreturned from the kernel with an appropriate error status. 28701a4eb82SKenneth D. Merry.Pp 28801a4eb82SKenneth D. Merry.Fa cmd_spec 28901a4eb82SKenneth D. Merryis a CDB format specifier used to build up the SCSI CDB. 2901a0a9345SRuslan ErmilovThis text string is made up of a list of field specifiers. 2911a0a9345SRuslan ErmilovField 29201a4eb82SKenneth D. Merryspecifiers specify the value for each CDB field (including indicating 29301a4eb82SKenneth D. Merrythat the value be taken from the next argument in the 29401a4eb82SKenneth D. Merryvariable argument list), the width 2951a0a9345SRuslan Ermilovof the field in bits or bytes, and an optional name. 2961a0a9345SRuslan ErmilovWhite space is 29701a4eb82SKenneth D. Merryignored, and the pound sign ('#') introduces a comment that ends at the 29801a4eb82SKenneth D. Merryend of the current line. 29901a4eb82SKenneth D. Merry.Pp 30001a4eb82SKenneth D. MerryThe optional name is the first part of a field specifier and 3011a0a9345SRuslan Ermilovis in curly braces. 3021a0a9345SRuslan ErmilovThe text in curly braces in this example are 30301a4eb82SKenneth D. Merrythe names: 304953ae31aSAlexander Langer.Dl "{PS} v:b1 {Reserved} 0:b1 {Page Code} v:b6 # Mode select page" 30501a4eb82SKenneth D. Merry.Pp 30601a4eb82SKenneth D. MerryThis field specifier has two one bit fields and one six bit field. 30701a4eb82SKenneth D. MerryThe second one bit field is the constant value 0 and the first 30801a4eb82SKenneth D. Merryone bit field and the six bit field are taken from the variable 30901a4eb82SKenneth D. Merryargument list. 31001a4eb82SKenneth D. MerryMulti byte fields are swapped into the SCSI byte order in the 31101a4eb82SKenneth D. MerryCDB and white space is ignored. 31201a4eb82SKenneth D. Merry.Pp 31301a4eb82SKenneth D. MerryWhen the field is a hex value or the letter v, (e.g., 31401a4eb82SKenneth D. Merry.Fa "1A" 31501a4eb82SKenneth D. Merryor 31601a4eb82SKenneth D. Merry.Fa "v" ) 31701a4eb82SKenneth D. Merrythen a single byte value 31801a4eb82SKenneth D. Merryis copied to the next unused byte of the CDB. 31901a4eb82SKenneth D. MerryWhen the letter 32001a4eb82SKenneth D. Merry.Fa v 32101a4eb82SKenneth D. Merryis used the next integer argument is taken from the variable argument list 32201a4eb82SKenneth D. Merryand that value used. 32301a4eb82SKenneth D. Merry.Pp 32401a4eb82SKenneth D. MerryA constant hex value followed by a field width specifier or the letter 32501a4eb82SKenneth D. Merry.Fa v 32601a4eb82SKenneth D. Merryfollowed by a field width specifier (e.g., 32701a4eb82SKenneth D. Merry.Fa 3:4 , 32801a4eb82SKenneth D. Merry.Fa 3:b4 , 32901a4eb82SKenneth D. Merry.Fa 3:i3 , 330382114daSRuslan Ermilov.Fa v:i3 ) 33101a4eb82SKenneth D. Merryspecifies a field of a given bit or byte width. 33201a4eb82SKenneth D. MerryEither the constant value or (for the V specifier) the next integer value from 33301a4eb82SKenneth D. Merrythe variable argument list is copied to the next unused 33401a4eb82SKenneth D. Merrybits or bytes of the CDB. 33501a4eb82SKenneth D. Merry.Pp 33601a4eb82SKenneth D. MerryA decimal number or the letter 33701a4eb82SKenneth D. Merry.Fa b 33801a4eb82SKenneth D. Merryfollowed by a decimal number field width indicates a bit field of that width. 33901a4eb82SKenneth D. MerryThe bit fields are packed as tightly as possible beginning with the 34001a4eb82SKenneth D. Merryhigh bit (so that it reads the same as the SCSI spec), and a new byte of 34101a4eb82SKenneth D. Merrythe CDB is started whenever a byte fills completely or when an 34201a4eb82SKenneth D. Merry.Fa i 34301a4eb82SKenneth D. Merryfield is encountered. 34401a4eb82SKenneth D. Merry.Pp 34501a4eb82SKenneth D. MerryA field width specifier consisting of the letter 34601a4eb82SKenneth D. Merry.Fa i 34701a4eb82SKenneth D. Merryfollowed by either 34801a4eb82SKenneth D. Merry1, 2, 3 or 4 indicates a 1, 2, 3 or 4 byte integral value that must 34901a4eb82SKenneth D. Merrybe swapped into SCSI byte order (MSB first). 35001a4eb82SKenneth D. Merry.Pp 35101a4eb82SKenneth D. MerryFor the 35201a4eb82SKenneth D. Merry.Fa v 35301a4eb82SKenneth D. Merryfield specifier the next integer argument is taken from the variable argument 35401a4eb82SKenneth D. Merrylist and that value is used swapped into SCSI byte order. 35501a4eb82SKenneth D. Merry.Pp 35601a4eb82SKenneth D. Merry.Fn csio_build_visit 35701a4eb82SKenneth D. Merryoperates similarly to 35801a4eb82SKenneth D. Merry.Fn csio_build , 35901a4eb82SKenneth D. Merryexcept that the values to substitute for variable arguments in 36001a4eb82SKenneth D. Merry.Fa cmd_spec 36101a4eb82SKenneth D. Merryare retrieved via the 36201a4eb82SKenneth D. Merry.Fn arg_get 36301a4eb82SKenneth D. Merryfunction passed in to 36401a4eb82SKenneth D. Merry.Fn csio_build_visit 36501a4eb82SKenneth D. Merryinstead of via 36601a4eb82SKenneth D. Merry.Xr stdarg 3 . 36701a4eb82SKenneth D. MerryThe 36801a4eb82SKenneth D. Merry.Fn arg_get 36901a4eb82SKenneth D. Merryfunction takes two arguments: 37001a4eb82SKenneth D. Merry.Bl -tag -width field_name 37101a4eb82SKenneth D. Merry.It Fa gethook 37201a4eb82SKenneth D. Merryis passed into the 37301a4eb82SKenneth D. Merry.Fn arg_get 3741a0a9345SRuslan Ermilovfunction at each invocation. 3751a0a9345SRuslan ErmilovThis enables the 37601a4eb82SKenneth D. Merry.Fn arg_get 37701a4eb82SKenneth D. Merryfunction to keep some state in between calls without using global or static 37801a4eb82SKenneth D. Merryvariables. 37901a4eb82SKenneth D. Merry.It Fa field_name 38001a4eb82SKenneth D. Merryis the field name supplied in 38101a4eb82SKenneth D. Merry.Fa fmt , 38201a4eb82SKenneth D. Merryif any. 38301a4eb82SKenneth D. Merry.El 38401a4eb82SKenneth D. Merry.Pp 38501a4eb82SKenneth D. Merry.Fn csio_decode 38601a4eb82SKenneth D. Merryis used to decode information from the data in phase of the SCSI 38701a4eb82SKenneth D. Merrytransfer. 38801a4eb82SKenneth D. Merry.Pp 38901a4eb82SKenneth D. MerryThe decoding is similar to 39001a4eb82SKenneth D. Merrythe command specifier processing of 39101a4eb82SKenneth D. Merry.Fn csio_build 39201a4eb82SKenneth D. Merryexcept that the data is extracted from the data pointed to by 39301a4eb82SKenneth D. Merry.Fa csio->data_ptr . 39401a4eb82SKenneth D. MerryThe stdarg list should be pointers to integers instead of integer 39501a4eb82SKenneth D. Merryvalues. 39601a4eb82SKenneth D. MerryA seek field type and a suppression modifier are added. 39701a4eb82SKenneth D. MerryThe 39801a4eb82SKenneth D. Merry.Fa * 39901a4eb82SKenneth D. Merrysuppression modifier (e.g., 40001a4eb82SKenneth D. Merry.Fa *i3 40101a4eb82SKenneth D. Merryor 40201a4eb82SKenneth D. Merry.Fa *b4 ) 40301a4eb82SKenneth D. Merrysuppresses assignment from the field and can be used to skip 40401a4eb82SKenneth D. Merryover bytes or bits in the data, without having to copy 40501a4eb82SKenneth D. Merrythem to a dummy variable in the arg list. 40601a4eb82SKenneth D. Merry.Pp 40701a4eb82SKenneth D. MerryThe seek field type 40801a4eb82SKenneth D. Merry.Fa s 40901a4eb82SKenneth D. Merrypermits you to skip over data. 41094ba280cSRuslan ErmilovThis seeks to an absolute position 41194ba280cSRuslan Ermilov.Pq Fa s3 41294ba280cSRuslan Ermilovor a relative position 41394ba280cSRuslan Ermilov.Pq Fa s+3 41401a4eb82SKenneth D. Merryin the data, based on whether or not the presence of the '+' sign. 41501a4eb82SKenneth D. MerryThe seek value can be specified as 41601a4eb82SKenneth D. Merry.Fa v 41701a4eb82SKenneth D. Merryand the next integer value from the argument list will be 41801a4eb82SKenneth D. Merryused as the seek value. 41901a4eb82SKenneth D. Merry.Pp 42001a4eb82SKenneth D. Merry.Fn csio_decode_visit 42101a4eb82SKenneth D. Merryoperates like 42201a4eb82SKenneth D. Merry.Fn csio_decode 42301a4eb82SKenneth D. Merryexcept that instead of placing the decoded contents of the buffer in 42457bd0fc6SJens Schweikhardtvariadic arguments, the decoded buffer contents are returned to the user 42501a4eb82SKenneth D. Merryvia the 42601a4eb82SKenneth D. Merry.Fn arg_put 42701a4eb82SKenneth D. Merryfunction that is passed in. 42801a4eb82SKenneth D. MerryThe 42901a4eb82SKenneth D. Merry.Fn arg_put 43001a4eb82SKenneth D. Merryfunction takes several arguments: 43101a4eb82SKenneth D. Merry.Bl -tag -width letter 43201a4eb82SKenneth D. Merry.It Fa hook 43301a4eb82SKenneth D. MerryThe "hook" is a mechanism to allow the 43401a4eb82SKenneth D. Merry.Fn arg_put 43501a4eb82SKenneth D. Merryfunction to save state in between calls. 43601a4eb82SKenneth D. Merry.It Fa letter 43701a4eb82SKenneth D. Merryis the letter describing the format of the argument being passed into the 43801a4eb82SKenneth D. Merryfunction. 43901a4eb82SKenneth D. Merry.It Fa val 44001a4eb82SKenneth D. Merryis a void pointer to the value being passed into the function. 44101a4eb82SKenneth D. Merry.It Fa count 4427e32b20dSKelly Yanceyis the size of the value being passed into the 44301a4eb82SKenneth D. Merry.Fn arg_put 4441a0a9345SRuslan Ermilovfunction. 4451a0a9345SRuslan ErmilovThe argument format determines the unit of measure. 44601a4eb82SKenneth D. Merry.It Fa name 44701a4eb82SKenneth D. MerryThis is a text description of the field, if one was provided in the 44801a4eb82SKenneth D. Merry.Fa fmt . 44901a4eb82SKenneth D. Merry.El 45001a4eb82SKenneth D. Merry.Pp 45101a4eb82SKenneth D. Merry.Fn buff_decode 45201a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method 45301a4eb82SKenneth D. Merrydescribed above for 45401a4eb82SKenneth D. Merry.Fn csio_decode . 45501a4eb82SKenneth D. Merry.Pp 45601a4eb82SKenneth D. Merry.Fn buff_decode_visit 45701a4eb82SKenneth D. Merrydecodes an arbitrary data buffer using the method described above for 45801a4eb82SKenneth D. Merry.Fn csio_decode_visit . 45901a4eb82SKenneth D. Merry.Pp 46001a4eb82SKenneth D. Merry.Fn csio_encode 46101a4eb82SKenneth D. Merryencodes the 46201a4eb82SKenneth D. Merry.Fa data_ptr 46301a4eb82SKenneth D. Merryportion (not the CDB!) of a 46401a4eb82SKenneth D. Merry.Va ccb_scsiio 46501a4eb82SKenneth D. Merrystructure, using the method described above for 46601a4eb82SKenneth D. Merry.Fn csio_build . 46701a4eb82SKenneth D. Merry.Pp 46801a4eb82SKenneth D. Merry.Fn csio_encode_visit 46901a4eb82SKenneth D. Merryencodes the 47001a4eb82SKenneth D. Merry.Fa data_ptr 47101a4eb82SKenneth D. Merryportion (not the CDB!) of a 47201a4eb82SKenneth D. Merry.Va ccb_scsiio 47301a4eb82SKenneth D. Merrystructure, using the method described above for 47401a4eb82SKenneth D. Merry.Fn csio_build_visit . 47501a4eb82SKenneth D. Merry.Pp 47601a4eb82SKenneth D. Merry.Fn buff_encode_visit 47701a4eb82SKenneth D. Merryencodes an arbitrary data pointer, using the method described 47801a4eb82SKenneth D. Merryabove for 47901a4eb82SKenneth D. Merry.Fn csio_build_visit . 48001a4eb82SKenneth D. Merry.Sh RETURN VALUES 48101a4eb82SKenneth D. Merry.Fn csio_build , 48201a4eb82SKenneth D. Merry.Fn csio_build_visit , 48301a4eb82SKenneth D. Merry.Fn csio_encode , 48401a4eb82SKenneth D. Merry.Fn csio_encode_visit , 48501a4eb82SKenneth D. Merryand 48601a4eb82SKenneth D. Merry.Fn buff_encode_visit 48701a4eb82SKenneth D. Merryreturn the number of fields processed. 48801a4eb82SKenneth D. Merry.Pp 48901a4eb82SKenneth D. Merry.Fn csio_decode , 49001a4eb82SKenneth D. Merry.Fn csio_decode_visit , 49101a4eb82SKenneth D. Merry.Fn buff_decode , 49201a4eb82SKenneth D. Merryand 49301a4eb82SKenneth D. Merry.Fn buff_decode_visit 49401a4eb82SKenneth D. Merryreturn the number of assignments performed. 49501a4eb82SKenneth D. Merry.Sh SEE ALSO 49601a4eb82SKenneth D. Merry.Xr cam 3 , 49701a4eb82SKenneth D. Merry.Xr pass 4 , 49801a4eb82SKenneth D. Merry.Xr camcontrol 8 49901a4eb82SKenneth D. Merry.Sh HISTORY 50001a4eb82SKenneth D. MerryThe CAM versions of these functions are based upon similar functions 501b5c508fbSRuslan Ermilovimplemented for the old 502b5c508fbSRuslan Ermilov.Fx 50301a4eb82SKenneth D. Merry.Tn SCSI 5041a0a9345SRuslan Ermilovlayer. 5051a0a9345SRuslan ErmilovThe encoding/decoding functions in the old 50601a4eb82SKenneth D. Merry.Tn SCSI 50787b3dc51SEnji Coopercode were written by 50887b3dc51SEnji Cooper.An Peter Dufault Aq Mt dufault@hda.com . 50901a4eb82SKenneth D. Merry.Pp 51001a4eb82SKenneth D. MerryMany systems have comparable interfaces to permit a user to construct a 51101a4eb82SKenneth D. MerrySCSI command in user space. 51201a4eb82SKenneth D. Merry.Pp 51301a4eb82SKenneth D. MerryThe old 51401a4eb82SKenneth D. Merry.Va scsireq 51587b3dc51SEnji Cooperdata structure was almost identical to the SGI /dev/scsi data structure. 51687b3dc51SEnji CooperIf anyone knows the name of the authors it should go here; 51787b3dc51SEnji CooperPeter Dufault 51887b3dc51SEnji Cooperfirst 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 523753d686dSRuslan Ermilov.An Peter Dufault 524753d686dSRuslan Ermilovimplemented a clone of SGI's interface in 525753d686dSRuslan Ermilov.Bx 386 526753d686dSRuslan Ermilovthat 527b5c508fbSRuslan Ermilovled to the original 528b5c508fbSRuslan Ermilov.Fx 52901a4eb82SKenneth D. Merry.Tn SCSI 53001a4eb82SKenneth D. Merrylibrary and the related kernel ioctl. 53187b3dc51SEnji CooperIf anyone needs that for compatibility, contact 53287b3dc51SEnji Cooper.Mt dufault@hda.com . 53301a4eb82SKenneth D. Merry.Sh AUTHORS 53487b3dc51SEnji Cooper.An -nosplit 53587b3dc51SEnji Cooper.An Kenneth Merry Aq Mt ken@FreeBSD.org 53687b3dc51SEnji Cooperimplemented the CAM versions of these encoding and decoding functions. 53787b3dc51SEnji CooperThis current work is based upon earlier work by 53887b3dc51SEnji Cooper.An Peter Dufault Aq Mt dufault@hda.com . 53901a4eb82SKenneth D. Merry.Sh BUGS 54001a4eb82SKenneth D. MerryThere should probably be a function that encodes both the CDB and the data 54101a4eb82SKenneth D. Merrybuffer portions of a 54201a4eb82SKenneth D. Merry.Tn SCSI 5431a0a9345SRuslan ErmilovCCB. 5441a0a9345SRuslan ErmilovI discovered this while implementing the arbitrary command execution 54501a4eb82SKenneth D. Merrycode in 54601a4eb82SKenneth D. Merry.Xr camcontrol 8 , 5470227791bSRuslan Ermilovbut I have not yet had time to implement such a function. 54801a4eb82SKenneth D. Merry.Pp 5490227791bSRuslan ErmilovSome of the CCB flag descriptions really do not belong here. 5501a0a9345SRuslan ErmilovRather they 5511a0a9345SRuslan Ermilovbelong in a generic CCB man page. 5520227791bSRuslan ErmilovSince that man page has not yet been 55301a4eb82SKenneth D. Merrywritten, the shorter descriptions here will have to suffice. 554