1 |
/* $MidnightBSD$ */ |
2 |
/* |
3 |
* Copyright (c) 1997, 1998 Kenneth D. Merry. |
4 |
* All rights reserved. |
5 |
* |
6 |
* Redistribution and use in source and binary forms, with or without |
7 |
* modification, are permitted provided that the following conditions |
8 |
* are met: |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* 2. The name of the author may not be used to endorse or promote products |
12 |
* derived from this software without specific prior written permission. |
13 |
* |
14 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
15 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
17 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
18 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
19 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
20 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
21 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
22 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
24 |
* SUCH DAMAGE. |
25 |
* |
26 |
* $FreeBSD: stable/10/lib/libcam/camlib.h 316316 2017-03-31 04:42:00Z ngie $ |
27 |
*/ |
28 |
/* |
29 |
* Buffer encoding/decoding routines taken from the original FreeBSD SCSI |
30 |
* library and slightly modified. The original header file had the following |
31 |
* copyright: |
32 |
*/ |
33 |
/* Copyright (c) 1994 HD Associates (hd@world.std.com) |
34 |
* All rights reserved. |
35 |
* |
36 |
* Redistribution and use in source and binary forms, with or without |
37 |
* modification, are permitted provided that the following conditions |
38 |
* are met: |
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. |
50 |
* |
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 |
61 |
* SUCH DAMAGE. |
62 |
*/ |
63 |
|
64 |
|
65 |
#ifndef _CAMLIB_H |
66 |
#define _CAMLIB_H |
67 |
|
68 |
#include <sys/cdefs.h> |
69 |
#include <sys/param.h> |
70 |
|
71 |
#include <cam/cam.h> |
72 |
#include <cam/cam_ccb.h> |
73 |
|
74 |
#define CAM_ERRBUF_SIZE 2048 /* CAM library error string size */ |
75 |
|
76 |
/* |
77 |
* Right now we hard code the transport layer device, but this will change |
78 |
* if we ever get more than one transport layer. |
79 |
*/ |
80 |
#define XPT_DEVICE "/dev/xpt0" |
81 |
|
82 |
|
83 |
extern char cam_errbuf[]; |
84 |
|
85 |
struct cam_device { |
86 |
char device_path[MAXPATHLEN];/* |
87 |
* Pathname of the device |
88 |
* given by the user. This |
89 |
* may be null if the |
90 |
* user states the device |
91 |
* name and unit number |
92 |
* separately. |
93 |
*/ |
94 |
char given_dev_name[DEV_IDLEN+1];/* |
95 |
* Device name given by |
96 |
* the user. |
97 |
*/ |
98 |
u_int32_t given_unit_number; /* |
99 |
* Unit number given by |
100 |
* the user. |
101 |
*/ |
102 |
char device_name[DEV_IDLEN+1];/* |
103 |
* Name of the device, |
104 |
* e.g. 'pass' |
105 |
*/ |
106 |
u_int32_t dev_unit_num; /* Unit number of the passthrough |
107 |
* device associated with this |
108 |
* particular device. |
109 |
*/ |
110 |
|
111 |
char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */ |
112 |
u_int32_t sim_unit_number; /* Controller unit number */ |
113 |
u_int32_t bus_id; /* Controller bus number */ |
114 |
lun_id_t target_lun; /* Logical Unit Number */ |
115 |
target_id_t target_id; /* Target ID */ |
116 |
path_id_t path_id; /* System SCSI bus number */ |
117 |
u_int16_t pd_type; /* type of peripheral device */ |
118 |
struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */ |
119 |
u_int8_t serial_num[252]; /* device serial number */ |
120 |
u_int8_t serial_num_len; /* length of the serial number */ |
121 |
u_int8_t sync_period; /* Negotiated sync period */ |
122 |
u_int8_t sync_offset; /* Negotiated sync offset */ |
123 |
u_int8_t bus_width; /* Negotiated bus width */ |
124 |
int fd; /* file descriptor for device */ |
125 |
}; |
126 |
|
127 |
__BEGIN_DECLS |
128 |
/* Basic utility commands */ |
129 |
struct cam_device * cam_open_device(const char *path, int flags); |
130 |
void cam_close_device(struct cam_device *dev); |
131 |
void cam_close_spec_device(struct cam_device *dev); |
132 |
struct cam_device * cam_open_spec_device(const char *dev_name, |
133 |
int unit, int flags, |
134 |
struct cam_device *device); |
135 |
struct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id, |
136 |
lun_id_t target_lun, int flags, |
137 |
struct cam_device *device); |
138 |
struct cam_device * cam_open_pass(const char *path, int flags, |
139 |
struct cam_device *device); |
140 |
union ccb * cam_getccb(struct cam_device *dev); |
141 |
void cam_freeccb(union ccb *ccb); |
142 |
int cam_send_ccb(struct cam_device *device, union ccb *ccb); |
143 |
char * cam_path_string(struct cam_device *dev, char *str, |
144 |
int len); |
145 |
struct cam_device * cam_device_dup(struct cam_device *device); |
146 |
void cam_device_copy(struct cam_device *src, |
147 |
struct cam_device *dst); |
148 |
int cam_get_device(const char *path, char *dev_name, |
149 |
int devnamelen, int *unit); |
150 |
|
151 |
/* |
152 |
* Buffer encoding/decoding routines, from the old SCSI library. |
153 |
*/ |
154 |
int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) |
155 |
__printflike(2, 3); |
156 |
int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt, |
157 |
void (*arg_put)(void *, int, void *, int, char *), |
158 |
void *puthook); |
159 |
int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) |
160 |
__printflike(3, 4); |
161 |
int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, |
162 |
void (*arg_put)(void *, int, void *, int, char *), |
163 |
void *puthook); |
164 |
int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, |
165 |
u_int32_t dxfer_len, u_int32_t flags, int retry_count, |
166 |
int timeout, const char *cmd_spec, ...); |
167 |
int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, |
168 |
u_int32_t dxfer_len, u_int32_t flags, int retry_count, |
169 |
int timeout, const char *cmd_spec, |
170 |
int (*arg_get)(void *hook, char *field_name), |
171 |
void *gethook); |
172 |
int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) |
173 |
__printflike(2, 3); |
174 |
int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, |
175 |
int (*arg_get)(void *hook, char *field_name), |
176 |
void *gethook); |
177 |
int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, |
178 |
int (*arg_get)(void *hook, char *field_name), |
179 |
void *gethook); |
180 |
__END_DECLS |
181 |
|
182 |
#endif /* _CAMLIB_H */ |