2 * Copyright (c) 1997, 1998 Kenneth D. Merry.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * $FreeBSD: src/lib/libcam/camlib.h,v 1.2 1999/08/28 00:04:06 peter Exp $
26 * $DragonFly: src/sys/sys/camlib.h,v 1.3 2006/05/21 03:43:47 dillon Exp $
29 * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
30 * library and slightly modified. The original header file had the following
33 /* Copyright (c) 1994 HD Associates (hd@world.std.com)
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by HD Associates
47 * 4. Neither the name of the HD Associaates nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 #ifndef _SYS_CAMLIB_H_
66 #define _SYS_CAMLIB_H_
69 #include <sys/cdefs.h>
72 #include <sys/param.h>
74 #ifndef _BUS_CAM_CAM_H_
75 #include <bus/cam/cam.h>
77 #ifndef _BUS_CAM_CAM_CCB_H_
78 #include <bus/cam/cam_ccb.h>
81 #define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */
84 * Right now we hard code the transport layer device, but this will change
85 * if we ever get more than one transport layer.
87 #define XPT_DEVICE "/dev/xpt0"
90 extern char cam_errbuf
[];
93 char device_path
[MAXPATHLEN
+1];/*
94 * Pathname of the device
95 * given by the user. This
97 * user states the device
98 * name and unit number
101 char given_dev_name
[DEV_IDLEN
+1];/*
102 * Device name given by
105 u_int32_t given_unit_number
; /*
106 * Unit number given by
109 char device_name
[DEV_IDLEN
+1];/*
110 * Name of the device,
113 u_int32_t dev_unit_num
; /* Unit number of the passthrough
114 * device associated with this
118 char sim_name
[SIM_IDLEN
+1]; /* Controller name, e.g. 'ahc' */
119 u_int32_t sim_unit_number
; /* Controller unit number */
120 u_int32_t bus_id
; /* Controller bus number */
121 lun_id_t target_lun
; /* Logical Unit Number */
122 target_id_t target_id
; /* Target ID */
123 path_id_t path_id
; /* System SCSI bus number */
124 u_int16_t pd_type
; /* type of peripheral device */
125 struct scsi_inquiry_data inq_data
; /* SCSI Inquiry data */
126 u_int8_t serial_num
[252]; /* device serial number */
127 u_int8_t serial_num_len
; /* length of the serial number */
128 u_int8_t sync_period
; /* Negotiated sync period */
129 u_int8_t sync_offset
; /* Negotiated sync offset */
130 u_int8_t bus_width
; /* Negotiated bus width */
131 int fd
; /* file descriptor for device */
135 /* Basic utility commands */
136 struct cam_device
* cam_open_device(const char *path
, int flags
);
137 void cam_close_device(struct cam_device
*dev
);
138 void cam_close_spec_device(struct cam_device
*dev
);
139 struct cam_device
* cam_open_spec_device(const char *dev_name
,
141 struct cam_device
*device
);
142 struct cam_device
* cam_open_btl(path_id_t path_id
, target_id_t target_id
,
143 lun_id_t target_lun
, int flags
,
144 struct cam_device
*device
);
145 struct cam_device
* cam_open_pass(const char *path
, int flags
,
146 struct cam_device
*device
);
147 union ccb
* cam_getccb(struct cam_device
*dev
);
148 void cam_freeccb(union ccb
*ccb
);
149 int cam_send_ccb(struct cam_device
*device
, union ccb
*ccb
);
150 char * cam_path_string(struct cam_device
*dev
, char *str
,
152 struct cam_device
* cam_device_dup(struct cam_device
*device
);
153 void cam_device_copy(struct cam_device
*src
,
154 struct cam_device
*dst
);
155 int cam_get_device(const char *path
, char *dev_name
,
156 int devnamelen
, int *unit
);
159 * Buffer encoding/decoding routines, from the old SCSI library.
161 int csio_decode(struct ccb_scsiio
*csio
, char *fmt
, ...);
162 int csio_decode_visit(struct ccb_scsiio
*csio
, char *fmt
,
163 void (*arg_put
)(void *, int, void *, int, char *),
165 int buff_decode(u_int8_t
*buff
, size_t len
, char *fmt
, ...);
166 int buff_decode_visit(u_int8_t
*buff
, size_t len
, char *fmt
,
167 void (*arg_put
)(void *, int, void *, int, char *),
169 int csio_build(struct ccb_scsiio
*csio
, u_int8_t
*data_ptr
,
170 u_int32_t dxfer_len
, u_int32_t flags
, int retry_count
,
171 int timeout
, char *cmd_spec
, ...);
172 int csio_build_visit(struct ccb_scsiio
*csio
, u_int8_t
*data_ptr
,
173 u_int32_t dxfer_len
, u_int32_t flags
, int retry_count
,
174 int timeout
, char *cmd_spec
,
175 int (*arg_get
)(void *hook
, char *field_name
),
177 int csio_encode(struct ccb_scsiio
*csio
, char *fmt
, ...);
178 int buff_encode_visit(u_int8_t
*buff
, size_t len
, char *fmt
,
179 int (*arg_get
)(void *hook
, char *field_name
),
181 int csio_encode_visit(struct ccb_scsiio
*csio
, char *fmt
,
182 int (*arg_get
)(void *hook
, char *field_name
),
186 #endif /* _SYS_CAMLIB_H_ */