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