]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libcam/cam_cdbparse.3
sqlite3: Vendor import of sqlite3 3.43.1
[FreeBSD/FreeBSD.git] / lib / libcam / cam_cdbparse.3
1 .\"
2 .\" Copyright (c) 1998 Kenneth D. Merry.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. The name of the author may not be used to endorse or promote products
14 .\"    derived from this software without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" This man page borrows heavily from the old scsi(3) man page, which had
29 .\" the following copyright:
30 .\"
31 .\" Copyright (c) 1994 HD Associates (hd@world.std.com)
32 .\" All rights reserved.
33 .\"
34 .\" Redistribution and use in source and binary forms, with or without
35 .\" modification, are permitted provided that the following conditions
36 .\" are met:
37 .\" 1. Redistributions of source code must retain the above copyright
38 .\"    notice, this list of conditions and the following disclaimer.
39 .\" 2. Redistributions in binary form must reproduce the above copyright
40 .\"    notice, this list of conditions and the following disclaimer in the
41 .\"    documentation and/or other materials provided with the distribution.
42 .\" 3. All advertising materials mentioning features or use of this software
43 .\"    must display the following acknowledgement:
44 .\"     This product includes software developed by HD Associates
45 .\" 4. Neither the name of the HD Associates nor the names of its contributors
46 .\"    may be used to endorse or promote products derived from this software
47 .\"    without specific prior written permission.
48 .\"
49 .\" THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
50 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 .\" ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
53 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 .\" SUCH DAMAGE.
60 .\"
61 .\"
62 .Dd March 13, 2017
63 .Dt CAM_CDBPARSE 3
64 .Os
65 .Sh NAME
66 .Nm csio_build ,
67 .Nm csio_build_visit ,
68 .Nm csio_decode ,
69 .Nm csio_decode_visit ,
70 .Nm buff_decode ,
71 .Nm buff_decode_visit ,
72 .Nm csio_encode ,
73 .Nm csio_encode_visit ,
74 .Nm buff_encode_visit
75 .Nd CAM user library SCSI buffer parsing routines
76 .Sh LIBRARY
77 .Lb libcam
78 .Sh SYNOPSIS
79 .In stdio.h
80 .In camlib.h
81 .Ft int
82 .Fo csio_build
83 .Fa "struct ccb_scsiio *csio"
84 .Fa "uint8_t *data_ptr"
85 .Fa "uint32_t dxfer_len"
86 .Fa "uint32_t flags"
87 .Fa "int retry_count"
88 .Fa "int timeout"
89 .Fa "const char *cmd_spec"
90 .Fa "..."
91 .Fc
92 .Ft int
93 .Fo csio_build_visit
94 .Fa "struct ccb_scsiio *csio"
95 .Fa "uint8_t *data_ptr"
96 .Fa "uint32_t dxfer_len"
97 .Fa "uint32_t flags"
98 .Fa "int retry_count"
99 .Fa "int timeout"
100 .Fa "const char *cmd_spec"
101 .Fa "int (*arg_get)(void *hook, char *field_name)"
102 .Fa "void *gethook"
103 .Fc
104 .Ft int
105 .Fo csio_decode
106 .Fa "struct ccb_scsiio *csio"
107 .Fa "const char *fmt"
108 .Fa "..."
109 .Fc
110 .Ft int
111 .Fo csio_decode_visit
112 .Fa "struct ccb_scsiio *csio"
113 .Fa "const char *fmt"
114 .Fa "void (*arg_put)(void *hook"
115 .Fa "int letter"
116 .Fa "void *val"
117 .Fa "int count"
118 .Fa "char *name)"
119 .Fa "void *puthook"
120 .Fc
121 .Ft int
122 .Fo buff_decode
123 .Fa "uint8_t *buff"
124 .Fa "size_t len"
125 .Fa "const char *fmt"
126 .Fa "..."
127 .Fc
128 .Ft int
129 .Fo buff_decode_visit
130 .Fa "uint8_t *buff"
131 .Fa "size_t len"
132 .Fa "const char *fmt"
133 .Fa "void (*arg_put)(void *, int, void *, int, char *)"
134 .Fa "void *puthook"
135 .Fc
136 .Ft int
137 .Fo csio_encode
138 .Fa "struct ccb_scsiio *csio"
139 .Fa "const char *fmt"
140 .Fa "..."
141 .Fc
142 .Ft int
143 .Fo csio_encode_visit
144 .Fa "struct ccb_scsiio *csio"
145 .Fa "const char *fmt"
146 .Fa "int (*arg_get)(void *hook, char *field_name)"
147 .Fa "void *gethook"
148 .Fc
149 .Ft int
150 .Fo buff_encode_visit
151 .Fa "uint8_t *buff"
152 .Fa "size_t len"
153 .Fa "const char *fmt"
154 .Fa "int (*arg_get)(void *hook, char *field_name)"
155 .Fa "void *gethook"
156 .Fc
157 .Sh DESCRIPTION
158 The CAM buffer/CDB encoding and decoding routines provide a relatively easy
159 migration path for userland
160 .Tn SCSI
161 applications written with the similarly-named
162 .Va scsireq_ Ns *
163 functions from the old
164 .Fx
165 .Tn SCSI
166 layer.
167 .Pp
168 These functions may be used in new applications, but users may find it
169 easier to use the various SCSI CCB building functions included with the
170 .Xr cam 3
171 library, e.g., \&
172 .Fn cam_fill_csio ,
173 .Fn scsi_start_stop ,
174 and
175 .Fn scsi_read_write .
176 .Pp
177 .Fn csio_build
178 builds up a
179 .Va ccb_scsiio
180 structure based on the information provided in
181 the variable argument list.
182 It gracefully handles a NULL
183 .Fa data_ptr
184 argument passed to it.
185 .Pp
186 .Fa dxfer_len
187 is the length of the data phase; the data transfer direction is
188 determined by the
189 .Fa flags
190 argument.
191 .Pp
192 .Fa data_ptr
193 is the data buffer used during the
194 .Tn SCSI
195 data phase.
196 If no data is to be
197 transferred for the
198 .Tn SCSI
199 command in question, this should be set to NULL.
200 If there is data to
201 transfer for the command, this buffer must be at least
202 .Fa dxfer_len
203 long.
204 .Pp
205 .Fa flags
206 are the flags defined in
207 .In cam/cam_ccb.h :
208 .Bd -literal
209 /* Common CCB header */
210 /* CAM CCB flags */
211 typedef enum {
212      CAM_CDB_POINTER       = 0x00000001,/* The CDB field is a pointer    */
213      CAM_SCATTER_VALID     = 0x00000010,/* Scatter/gather list is valid  */
214      CAM_DIS_AUTOSENSE     = 0x00000020,/* Disable autosense feature     */
215      CAM_DIR_RESV          = 0x00000000,/* Data direction (00:reserved)  */
216      CAM_DIR_IN            = 0x00000040,/* Data direction (01:DATA IN)   */
217      CAM_DIR_OUT           = 0x00000080,/* Data direction (10:DATA OUT)  */
218      CAM_DIR_NONE          = 0x000000C0,/* Data direction (11:no data)   */
219      CAM_DIR_MASK          = 0x000000C0,/* Data direction Mask           */
220      CAM_DEV_QFRZDIS       = 0x00000400,/* Disable DEV Q freezing        */
221      CAM_DEV_QFREEZE       = 0x00000800,/* Freeze DEV Q on execution     */
222      CAM_HIGH_POWER        = 0x00001000,/* Command takes a lot of power  */
223      CAM_SENSE_PTR         = 0x00002000,/* Sense data is a pointer       */
224      CAM_SENSE_PHYS        = 0x00004000,/* Sense pointer is physical addr*/
225      CAM_TAG_ACTION_VALID  = 0x00008000,/* Use the tag action in this ccb*/
226      CAM_PASS_ERR_RECOVER  = 0x00010000,/* Pass driver does err. recovery*/
227      CAM_DIS_DISCONNECT    = 0x00020000,/* Disable disconnect            */
228      CAM_SG_LIST_PHYS      = 0x00040000,/* SG list has physical addrs.   */
229      CAM_DATA_PHYS         = 0x00200000,/* SG/Buffer data ptrs are phys. */
230      CAM_CDB_PHYS          = 0x00400000,/* CDB pointer is physical       */
231
232 /* Host target Mode flags */
233      CAM_SEND_SENSE        = 0x08000000,/* Send sense data with status   */
234      CAM_SEND_STATUS       = 0x80000000,/* Send status after data phase  */
235 } ccb_flags;
236 .Ed
237 .Pp
238 Multiple flags should be ORed together.
239 Any of the CCB flags may be used,
240 although it is worth noting several important ones here:
241 .Bl -tag -width CAM_PASS_ERR_RECOVER
242 .It Dv CAM_DIR_IN
243 This indicates that the operation in question is a read operation.
244 i.e.,
245 data is being read from the
246 .Tn SCSI
247 device to the user-supplied buffer.
248 .It Dv CAM_DIR_OUT
249 This indicates that the operation is a write operation.
250 i.e., data is being
251 written from the user-supplied buffer to the device.
252 .It Dv CAM_DIR_NONE
253 This indicates that there is no data to be transferred for this command.
254 .It Dv CAM_DEV_QFRZDIS
255 This flag disables device queue freezing as an error recovery mechanism.
256 .It Dv CAM_PASS_ERR_RECOVER
257 This flag tells the
258 .Xr pass 4
259 driver to enable error recovery.
260 The default is to not perform error
261 recovery, which means that the retry count will not be honored without this
262 flag, among other things.
263 .It Dv CAM_DATA_PHYS
264 This indicates that the address contained in
265 .Fa data_ptr
266 is a physical address, not a virtual address.
267 .El
268 .Pp
269 The
270 .Fa retry_count
271 tells the kernel how many times to retry the command in question.
272 The
273 retry count is ignored unless the
274 .Xr pass 4
275 driver is told to enable error recovery via the
276 .Dv CAM_PASS_ERR_RECOVER
277 flag.
278 .Pp
279 The
280 .Fa timeout
281 tells the kernel how long to wait for the given command to complete.
282 If
283 the timeout expires and the command has not completed, the CCB will be
284 returned from the kernel with an appropriate error status.
285 .Pp
286 .Fa cmd_spec
287 is a CDB format specifier used to build up the SCSI CDB.
288 This text string is made up of a list of field specifiers.
289 Field
290 specifiers specify the value for each CDB field (including indicating
291 that the value be taken from the next argument in the
292 variable argument list), the width
293 of the field in bits or bytes, and an optional name.
294 White space is
295 ignored, and the pound sign ('#') introduces a comment that ends at the
296 end of the current line.
297 .Pp
298 The optional name is the first part of a field specifier and
299 is in curly braces.
300 The text in curly braces in this example are
301 the names:
302 .Dl "{PS} v:b1 {Reserved} 0:b1 {Page Code} v:b6 # Mode select page"
303 .Pp
304 This field specifier has two one bit fields and one six bit field.
305 The second one bit field is the constant value 0 and the first
306 one bit field and the six bit field are taken from the variable
307 argument list.
308 Multi byte fields are swapped into the SCSI byte order in the
309 CDB and white space is ignored.
310 .Pp
311 When the field is a hex value or the letter v, (e.g.,
312 .Fa "1A"
313 or
314 .Fa "v" )
315 then a single byte value
316 is copied to the next unused byte of the CDB.
317 When the letter
318 .Fa v
319 is used the next integer argument is taken from the variable argument list
320 and that value used.
321 .Pp
322 A constant hex value followed by a field width specifier or the letter
323 .Fa v
324 followed by a field width specifier (e.g.,
325 .Fa 3:4 ,
326 .Fa 3:b4 ,
327 .Fa 3:i3 ,
328 .Fa v:i3 )
329 specifies a field of a given bit or byte width.
330 Either the constant value or (for the V specifier) the next integer value from
331 the variable argument list is copied to the next unused
332 bits or bytes of the CDB.
333 .Pp
334 A decimal number or the letter
335 .Fa b
336 followed by a decimal number field width indicates a bit field of that width.
337 The bit fields are packed as tightly as possible beginning with the
338 high bit (so that it reads the same as the SCSI spec), and a new byte of
339 the CDB is started whenever a byte fills completely or when an
340 .Fa i
341 field is encountered.
342 .Pp
343 A field width specifier consisting of the letter
344 .Fa i
345 followed by either
346 1, 2, 3 or 4 indicates a 1, 2, 3 or 4 byte integral value that must
347 be swapped into SCSI byte order (MSB first).
348 .Pp
349 For the
350 .Fa v
351 field specifier the next integer argument is taken from the variable argument
352 list and that value is used swapped into SCSI byte order.
353 .Pp
354 .Fn csio_build_visit
355 operates similarly to
356 .Fn csio_build ,
357 except that the values to substitute for variable arguments in
358 .Fa cmd_spec
359 are retrieved via the
360 .Fn arg_get
361 function passed in to
362 .Fn csio_build_visit
363 instead of via
364 .Xr stdarg 3 .
365 The
366 .Fn arg_get
367 function takes two arguments:
368 .Bl -tag -width field_name
369 .It Fa gethook
370 is passed into the
371 .Fn arg_get
372 function at each invocation.
373 This enables the
374 .Fn arg_get
375 function to keep some state in between calls without using global or static
376 variables.
377 .It Fa field_name
378 is the field name supplied in
379 .Fa fmt ,
380 if any.
381 .El
382 .Pp
383 .Fn csio_decode
384 is used to decode information from the data in phase of the SCSI
385 transfer.
386 .Pp
387 The decoding is similar to
388 the command specifier processing of
389 .Fn csio_build
390 except that the data is extracted from the data pointed to by
391 .Fa csio->data_ptr .
392 The stdarg list should be pointers to integers instead of integer
393 values.
394 A seek field type and a suppression modifier are added.
395 The
396 .Fa *
397 suppression modifier (e.g.,
398 .Fa *i3
399 or
400 .Fa *b4 )
401 suppresses assignment from the field and can be used to skip
402 over bytes or bits in the data, without having to copy
403 them to a dummy variable in the arg list.
404 .Pp
405 The seek field type
406 .Fa s
407 permits you to skip over data.
408 This seeks to an absolute position
409 .Pq Fa s3
410 or a relative position
411 .Pq Fa s+3
412 in the data, based on whether or not the presence of the '+' sign.
413 The seek value can be specified as
414 .Fa v
415 and the next integer value from the argument list will be
416 used as the seek value.
417 .Pp
418 .Fn csio_decode_visit
419 operates like
420 .Fn csio_decode
421 except that instead of placing the decoded contents of the buffer in
422 variadic arguments, the decoded buffer contents are returned to the user
423 via the
424 .Fn arg_put
425 function that is passed in.
426 The
427 .Fn arg_put
428 function takes several arguments:
429 .Bl -tag -width letter
430 .It Fa hook
431 The "hook" is a mechanism to allow the
432 .Fn arg_put
433 function to save state in between calls.
434 .It Fa letter
435 is the letter describing the format of the argument being passed into the
436 function.
437 .It Fa val
438 is a void pointer to the value being passed into the function.
439 .It Fa count
440 is the size of the value being passed into the
441 .Fn arg_put
442 function.
443 The argument format determines the unit of measure.
444 .It Fa name
445 This is a text description of the field, if one was provided in the
446 .Fa fmt .
447 .El
448 .Pp
449 .Fn buff_decode
450 decodes an arbitrary data buffer using the method
451 described above for
452 .Fn csio_decode .
453 .Pp
454 .Fn buff_decode_visit
455 decodes an arbitrary data buffer using the method described above for
456 .Fn csio_decode_visit .
457 .Pp
458 .Fn csio_encode
459 encodes the
460 .Fa data_ptr
461 portion (not the CDB!) of a
462 .Va ccb_scsiio
463 structure, using the method described above for
464 .Fn csio_build .
465 .Pp
466 .Fn csio_encode_visit
467 encodes the
468 .Fa data_ptr
469 portion (not the CDB!) of a
470 .Va ccb_scsiio
471 structure, using the method described above for
472 .Fn csio_build_visit .
473 .Pp
474 .Fn buff_encode_visit
475 encodes an arbitrary data pointer, using the method described
476 above for
477 .Fn csio_build_visit .
478 .Sh RETURN VALUES
479 .Fn csio_build ,
480 .Fn csio_build_visit ,
481 .Fn csio_encode ,
482 .Fn csio_encode_visit ,
483 and
484 .Fn buff_encode_visit
485 return the number of fields processed.
486 .Pp
487 .Fn csio_decode ,
488 .Fn csio_decode_visit ,
489 .Fn buff_decode ,
490 and
491 .Fn buff_decode_visit
492 return the number of assignments performed.
493 .Sh SEE ALSO
494 .Xr cam 3 ,
495 .Xr pass 4 ,
496 .Xr camcontrol 8
497 .Sh HISTORY
498 The CAM versions of these functions are based upon similar functions
499 implemented for the old
500 .Fx
501 .Tn SCSI
502 layer.
503 The encoding/decoding functions in the old
504 .Tn SCSI
505 code were written by
506 .An Peter Dufault Aq Mt dufault@hda.com .
507 .Pp
508 Many systems have comparable interfaces to permit a user to construct a
509 SCSI command in user space.
510 .Pp
511 The old
512 .Va scsireq
513 data structure was almost identical to the SGI /dev/scsi data structure.
514 If anyone knows the name of the authors it should go here;
515 Peter Dufault
516 first read about it in a 1989 Sun Expert magazine.
517 .Pp
518 The new CCB data structures are derived from the CAM-2 and CAM-3
519 specifications.
520 .Pp
521 .An Peter Dufault
522 implemented a clone of SGI's interface in
523 .Bx 386
524 that
525 led to the original
526 .Fx
527 .Tn SCSI
528 library and the related kernel ioctl.
529 If anyone needs that for compatibility, contact
530 .Mt dufault@hda.com .
531 .Sh AUTHORS
532 .An -nosplit
533 .An Kenneth Merry Aq Mt ken@FreeBSD.org
534 implemented the CAM versions of these encoding and decoding functions.
535 This current work is based upon earlier work by
536 .An Peter Dufault Aq Mt dufault@hda.com .
537 .Sh BUGS
538 There should probably be a function that encodes both the CDB and the data
539 buffer portions of a
540 .Tn SCSI
541 CCB.
542 I discovered this while implementing the arbitrary command execution
543 code in
544 .Xr camcontrol 8 ,
545 but I have not yet had time to implement such a function.
546 .Pp
547 Some of the CCB flag descriptions really do not belong here.
548 Rather they
549 belong in a generic CCB man page.
550 Since that man page has not yet been
551 written, the shorter descriptions here will have to suffice.