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