1169691Skan/* 2169691Skan * Copyright (c) 1997, 1998 Kenneth D. Merry. 3169691Skan * All rights reserved. 4169691Skan * 5169691Skan * Redistribution and use in source and binary forms, with or without 6169691Skan * modification, are permitted provided that the following conditions 7169691Skan * are met: 8169691Skan * 1. Redistributions of source code must retain the above copyright 9169691Skan * notice, this list of conditions and the following disclaimer. 10169691Skan * 2. The name of the author may not be used to endorse or promote products 11169691Skan * derived from this software without specific prior written permission. 12169691Skan * 13169691Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14169691Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16169691Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17169691Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18169691Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19169691Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21169691Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22169691Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23169691Skan * SUCH DAMAGE. 24169691Skan * 25169691Skan * $FreeBSD$ 26169691Skan */ 27169691Skan/* 28169691Skan * Buffer encoding/decoding routines taken from the original FreeBSD SCSI 29169691Skan * library and slightly modified. The original header file had the following 30169691Skan * copyright: 31169691Skan */ 32169691Skan/* Copyright (c) 1994 HD Associates (hd@world.std.com) 33169691Skan * All rights reserved. 34169691Skan * 35169691Skan * Redistribution and use in source and binary forms, with or without 36169691Skan * modification, are permitted provided that the following conditions 37169691Skan * are met: 38169691Skan * 1. Redistributions of source code must retain the above copyright 39169691Skan * notice, this list of conditions and the following disclaimer. 40169691Skan * 2. Redistributions in binary form must reproduce the above copyright 41169691Skan * notice, this list of conditions and the following disclaimer in the 42169691Skan * documentation and/or other materials provided with the distribution. 43169691Skan * 3. All advertising materials mentioning features or use of this software 44169691Skan * must display the following acknowledgement: 45169691Skan * This product includes software developed by HD Associates 46169691Skan * 4. Neither the name of the HD Associaates nor the names of its contributors 47169691Skan * may be used to endorse or promote products derived from this software 48169691Skan * without specific prior written permission. 49169691Skan * 50169691Skan * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND 51169691Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53169691Skan * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE 54169691Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55169691Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56169691Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58169691Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59169691Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60169691Skan * SUCH DAMAGE. 61169691Skan */ 62169691Skan 63169691Skan 64169691Skan#ifndef _CAMLIB_H 65169691Skan#define _CAMLIB_H 66169691Skan 67169691Skan#include <sys/cdefs.h> 68169691Skan#include <sys/param.h> 69169691Skan 70169691Skan#include <cam/cam.h> 71169691Skan#include <cam/cam_ccb.h> 72169691Skan 73169691Skan#define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */ 74169691Skan 75169691Skan/* 76169691Skan * Right now we hard code the transport layer device, but this will change 77169691Skan * if we ever get more than one transport layer. 78169691Skan */ 79169691Skan#define XPT_DEVICE "/dev/xpt0" 80169691Skan 81169691Skan 82169691Skanextern char cam_errbuf[]; 83169691Skan 84169691Skanstruct cam_device { 85169691Skan char device_path[MAXPATHLEN];/* 86169691Skan * Pathname of the device 87169691Skan * given by the user. This 88169691Skan * may be null if the 89169691Skan * user states the device 90169691Skan * name and unit number 91169691Skan * separately. 92169691Skan */ 93169691Skan char given_dev_name[DEV_IDLEN+1];/* 94169691Skan * Device name given by 95169691Skan * the user. 96169691Skan */ 97169691Skan u_int32_t given_unit_number; /* 98169691Skan * Unit number given by 99169691Skan * the user. 100169691Skan */ 101169691Skan char device_name[DEV_IDLEN+1];/* 102169691Skan * Name of the device, 103169691Skan * e.g. 'pass' 104169691Skan */ 105169691Skan u_int32_t dev_unit_num; /* Unit number of the passthrough 106169691Skan * device associated with this 107169691Skan * particular device. 108169691Skan */ 109169691Skan 110169691Skan char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */ 111169691Skan u_int32_t sim_unit_number; /* Controller unit number */ 112169691Skan u_int32_t bus_id; /* Controller bus number */ 113169691Skan lun_id_t target_lun; /* Logical Unit Number */ 114169691Skan target_id_t target_id; /* Target ID */ 115169691Skan path_id_t path_id; /* System SCSI bus number */ 116169691Skan u_int16_t pd_type; /* type of peripheral device */ 117169691Skan struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */ 118169691Skan u_int8_t serial_num[252]; /* device serial number */ 119169691Skan u_int8_t serial_num_len; /* length of the serial number */ 120169691Skan u_int8_t sync_period; /* Negotiated sync period */ 121169691Skan u_int8_t sync_offset; /* Negotiated sync offset */ 122169691Skan u_int8_t bus_width; /* Negotiated bus width */ 123169691Skan int fd; /* file descriptor for device */ 124169691Skan}; 125169691Skan 126169691Skan__BEGIN_DECLS 127169691Skan/* Basic utility commands */ 128169691Skanstruct cam_device * cam_open_device(const char *path, int flags); 129169691Skanvoid cam_close_device(struct cam_device *dev); 130169691Skanvoid cam_close_spec_device(struct cam_device *dev); 131169691Skanstruct cam_device * cam_open_spec_device(const char *dev_name, 132169691Skan int unit, int flags, 133169691Skan struct cam_device *device); 134169691Skanstruct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id, 135169691Skan lun_id_t target_lun, int flags, 136169691Skan struct cam_device *device); 137169691Skanstruct cam_device * cam_open_pass(const char *path, int flags, 138169691Skan struct cam_device *device); 139169691Skanunion ccb * cam_getccb(struct cam_device *dev); 140169691Skanvoid cam_freeccb(union ccb *ccb); 141169691Skanint cam_send_ccb(struct cam_device *device, union ccb *ccb); 142169691Skanchar * cam_path_string(struct cam_device *dev, char *str, 143169691Skan int len); 144169691Skanstruct cam_device * cam_device_dup(struct cam_device *device); 145169691Skanvoid cam_device_copy(struct cam_device *src, 146169691Skan struct cam_device *dst); 147169691Skanint cam_get_device(const char *path, char *dev_name, 148169691Skan int devnamelen, int *unit); 149169691Skan 150169691Skan/* 151169691Skan * Buffer encoding/decoding routines, from the old SCSI library. 152169691Skan */ 153169691Skanint csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) 154169691Skan __printflike(2, 3); 155169691Skanint csio_decode_visit(struct ccb_scsiio *csio, const char *fmt, 156169691Skan void (*arg_put)(void *, int, void *, int, char *), 157169691Skan void *puthook); 158169691Skanint buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) 159169691Skan __printflike(3, 4); 160169691Skanint buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, 161169691Skan void (*arg_put)(void *, int, void *, int, char *), 162169691Skan void *puthook); 163169691Skanint csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, 164169691Skan u_int32_t dxfer_len, u_int32_t flags, int retry_count, 165169691Skan int timeout, const char *cmd_spec, ...); 166169691Skanint csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, 167169691Skan u_int32_t dxfer_len, u_int32_t flags, int retry_count, 168169691Skan int timeout, const char *cmd_spec, 169169691Skan int (*arg_get)(void *hook, char *field_name), 170169691Skan void *gethook); 171169691Skanint csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) 172169691Skan __printflike(2, 3); 173169691Skanint buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, 174169691Skan int (*arg_get)(void *hook, char *field_name), 175169691Skan void *gethook); 176169691Skanint csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, 177169691Skan int (*arg_get)(void *hook, char *field_name), 178169691Skan void *gethook); 179169691Skan__END_DECLS 180169691Skan 181169691Skan#endif /* _CAMLIB_H */ 182169691Skan