11f2de5d4SMatthew Dillon /* 21f2de5d4SMatthew Dillon * Copyright (c) 1997, 1998 Kenneth D. Merry. 31f2de5d4SMatthew Dillon * All rights reserved. 41f2de5d4SMatthew Dillon * 51f2de5d4SMatthew Dillon * Redistribution and use in source and binary forms, with or without 61f2de5d4SMatthew Dillon * modification, are permitted provided that the following conditions 71f2de5d4SMatthew Dillon * are met: 81f2de5d4SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 91f2de5d4SMatthew Dillon * notice, this list of conditions and the following disclaimer. 101f2de5d4SMatthew Dillon * 2. The name of the author may not be used to endorse or promote products 111f2de5d4SMatthew Dillon * derived from this software without specific prior written permission. 121f2de5d4SMatthew Dillon * 131f2de5d4SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 141f2de5d4SMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 151f2de5d4SMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 161f2de5d4SMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 171f2de5d4SMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 181f2de5d4SMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 191f2de5d4SMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 201f2de5d4SMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 211f2de5d4SMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 221f2de5d4SMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 231f2de5d4SMatthew Dillon * SUCH DAMAGE. 241f2de5d4SMatthew Dillon * 251f2de5d4SMatthew Dillon * $FreeBSD: src/lib/libcam/camlib.h,v 1.2 1999/08/28 00:04:06 peter Exp $ 26*19edd1f3SPeter Avalos * $DragonFly: src/sys/sys/camlib.h,v 1.6 2007/11/24 03:13:03 pavalos Exp $ 271f2de5d4SMatthew Dillon */ 281f2de5d4SMatthew Dillon /* 291f2de5d4SMatthew Dillon * Buffer encoding/decoding routines taken from the original FreeBSD SCSI 301f2de5d4SMatthew Dillon * library and slightly modified. The original header file had the following 311f2de5d4SMatthew Dillon * copyright: 321f2de5d4SMatthew Dillon */ 331f2de5d4SMatthew Dillon /* Copyright (c) 1994 HD Associates (hd@world.std.com) 341f2de5d4SMatthew Dillon * All rights reserved. 351f2de5d4SMatthew Dillon * 361f2de5d4SMatthew Dillon * Redistribution and use in source and binary forms, with or without 371f2de5d4SMatthew Dillon * modification, are permitted provided that the following conditions 381f2de5d4SMatthew Dillon * are met: 391f2de5d4SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 401f2de5d4SMatthew Dillon * notice, this list of conditions and the following disclaimer. 411f2de5d4SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 421f2de5d4SMatthew Dillon * notice, this list of conditions and the following disclaimer in the 431f2de5d4SMatthew Dillon * documentation and/or other materials provided with the distribution. 441f2de5d4SMatthew Dillon * 3. All advertising materials mentioning features or use of this software 451f2de5d4SMatthew Dillon * must display the following acknowledgement: 461f2de5d4SMatthew Dillon * This product includes software developed by HD Associates 471f2de5d4SMatthew Dillon * 4. Neither the name of the HD Associaates nor the names of its contributors 481f2de5d4SMatthew Dillon * may be used to endorse or promote products derived from this software 491f2de5d4SMatthew Dillon * without specific prior written permission. 501f2de5d4SMatthew Dillon * 511f2de5d4SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND 521f2de5d4SMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 531f2de5d4SMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 541f2de5d4SMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE 551f2de5d4SMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 561f2de5d4SMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 571f2de5d4SMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 581f2de5d4SMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 591f2de5d4SMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 601f2de5d4SMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 611f2de5d4SMatthew Dillon * SUCH DAMAGE. 621f2de5d4SMatthew Dillon */ 631f2de5d4SMatthew Dillon 641f2de5d4SMatthew Dillon 651bd40720SMatthew Dillon #ifndef _SYS_CAMLIB_H_ 661bd40720SMatthew Dillon #define _SYS_CAMLIB_H_ 671f2de5d4SMatthew Dillon 6803d6a592SMatthew Dillon #ifndef _SYS_CDEFS_H_ 691f2de5d4SMatthew Dillon #include <sys/cdefs.h> 7003d6a592SMatthew Dillon #endif 7103d6a592SMatthew Dillon #ifndef _SYS_PARAM_H_ 721f2de5d4SMatthew Dillon #include <sys/param.h> 7303d6a592SMatthew Dillon #endif 7403d6a592SMatthew Dillon #ifndef _BUS_CAM_CAM_H_ 751f2de5d4SMatthew Dillon #include <bus/cam/cam.h> 7603d6a592SMatthew Dillon #endif 7703d6a592SMatthew Dillon #ifndef _BUS_CAM_CAM_CCB_H_ 781f2de5d4SMatthew Dillon #include <bus/cam/cam_ccb.h> 7903d6a592SMatthew Dillon #endif 801f2de5d4SMatthew Dillon 811f2de5d4SMatthew Dillon #define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */ 821f2de5d4SMatthew Dillon 831f2de5d4SMatthew Dillon /* 841f2de5d4SMatthew Dillon * Right now we hard code the transport layer device, but this will change 851f2de5d4SMatthew Dillon * if we ever get more than one transport layer. 861f2de5d4SMatthew Dillon */ 871f2de5d4SMatthew Dillon #define XPT_DEVICE "/dev/xpt0" 881f2de5d4SMatthew Dillon 891f2de5d4SMatthew Dillon 901f2de5d4SMatthew Dillon extern char cam_errbuf[]; 911f2de5d4SMatthew Dillon 921f2de5d4SMatthew Dillon struct cam_device { 93*19edd1f3SPeter Avalos char device_path[MAXPATHLEN]; /* 941f2de5d4SMatthew Dillon * Pathname of the device 951f2de5d4SMatthew Dillon * given by the user. This 961f2de5d4SMatthew Dillon * may be null if the 971f2de5d4SMatthew Dillon * user states the device 981f2de5d4SMatthew Dillon * name and unit number 991f2de5d4SMatthew Dillon * separately. 1001f2de5d4SMatthew Dillon */ 1011f2de5d4SMatthew Dillon char given_dev_name[DEV_IDLEN+1];/* 1021f2de5d4SMatthew Dillon * Device name given by 1031f2de5d4SMatthew Dillon * the user. 1041f2de5d4SMatthew Dillon */ 1051f2de5d4SMatthew Dillon u_int32_t given_unit_number; /* 1061f2de5d4SMatthew Dillon * Unit number given by 1071f2de5d4SMatthew Dillon * the user. 1081f2de5d4SMatthew Dillon */ 1091f2de5d4SMatthew Dillon char device_name[DEV_IDLEN+1];/* 1101f2de5d4SMatthew Dillon * Name of the device, 1111f2de5d4SMatthew Dillon * e.g. 'pass' 1121f2de5d4SMatthew Dillon */ 1131f2de5d4SMatthew Dillon u_int32_t dev_unit_num; /* Unit number of the passthrough 1141f2de5d4SMatthew Dillon * device associated with this 1151f2de5d4SMatthew Dillon * particular device. 1161f2de5d4SMatthew Dillon */ 1171f2de5d4SMatthew Dillon 1181f2de5d4SMatthew Dillon char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */ 1191f2de5d4SMatthew Dillon u_int32_t sim_unit_number; /* Controller unit number */ 1201f2de5d4SMatthew Dillon u_int32_t bus_id; /* Controller bus number */ 1211f2de5d4SMatthew Dillon lun_id_t target_lun; /* Logical Unit Number */ 1221f2de5d4SMatthew Dillon target_id_t target_id; /* Target ID */ 1231f2de5d4SMatthew Dillon path_id_t path_id; /* System SCSI bus number */ 1241f2de5d4SMatthew Dillon u_int16_t pd_type; /* type of peripheral device */ 1251f2de5d4SMatthew Dillon struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */ 1261f2de5d4SMatthew Dillon u_int8_t serial_num[252]; /* device serial number */ 1271f2de5d4SMatthew Dillon u_int8_t serial_num_len; /* length of the serial number */ 1281f2de5d4SMatthew Dillon u_int8_t sync_period; /* Negotiated sync period */ 1291f2de5d4SMatthew Dillon u_int8_t sync_offset; /* Negotiated sync offset */ 1301f2de5d4SMatthew Dillon u_int8_t bus_width; /* Negotiated bus width */ 1311f2de5d4SMatthew Dillon int fd; /* file descriptor for device */ 1321f2de5d4SMatthew Dillon }; 1331f2de5d4SMatthew Dillon 1341f2de5d4SMatthew Dillon __BEGIN_DECLS 1351f2de5d4SMatthew Dillon /* Basic utility commands */ 1361f2de5d4SMatthew Dillon struct cam_device * cam_open_device(const char *path, int flags); 1371f2de5d4SMatthew Dillon void cam_close_device(struct cam_device *dev); 1381f2de5d4SMatthew Dillon void cam_close_spec_device(struct cam_device *dev); 1391f2de5d4SMatthew Dillon struct cam_device * cam_open_spec_device(const char *dev_name, 1401f2de5d4SMatthew Dillon int unit, int flags, 1411f2de5d4SMatthew Dillon struct cam_device *device); 1421f2de5d4SMatthew Dillon struct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id, 1431f2de5d4SMatthew Dillon lun_id_t target_lun, int flags, 1441f2de5d4SMatthew Dillon struct cam_device *device); 1451f2de5d4SMatthew Dillon struct cam_device * cam_open_pass(const char *path, int flags, 1461f2de5d4SMatthew Dillon struct cam_device *device); 1471f2de5d4SMatthew Dillon union ccb * cam_getccb(struct cam_device *dev); 1481f2de5d4SMatthew Dillon void cam_freeccb(union ccb *ccb); 1491f2de5d4SMatthew Dillon int cam_send_ccb(struct cam_device *device, union ccb *ccb); 1501f2de5d4SMatthew Dillon char * cam_path_string(struct cam_device *dev, char *str, 1511f2de5d4SMatthew Dillon int len); 1521f2de5d4SMatthew Dillon struct cam_device * cam_device_dup(struct cam_device *device); 1531f2de5d4SMatthew Dillon void cam_device_copy(struct cam_device *src, 1541f2de5d4SMatthew Dillon struct cam_device *dst); 1551f2de5d4SMatthew Dillon int cam_get_device(const char *path, char *dev_name, 1561f2de5d4SMatthew Dillon int devnamelen, int *unit); 1571f2de5d4SMatthew Dillon 1581f2de5d4SMatthew Dillon /* 1591f2de5d4SMatthew Dillon * Buffer encoding/decoding routines, from the old SCSI library. 1601f2de5d4SMatthew Dillon */ 1615adc1304SPeter Avalos int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) 1625adc1304SPeter Avalos __printflike(2, 3); 1635adc1304SPeter Avalos int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt, 1641f2de5d4SMatthew Dillon void (*arg_put)(void *, int, void *, int, char *), 1651f2de5d4SMatthew Dillon void *puthook); 1665adc1304SPeter Avalos int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) 1675adc1304SPeter Avalos __printflike(3, 4); 1685adc1304SPeter Avalos int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, 1691f2de5d4SMatthew Dillon void (*arg_put)(void *, int, void *, int, char *), 1701f2de5d4SMatthew Dillon void *puthook); 1711f2de5d4SMatthew Dillon int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, 1721f2de5d4SMatthew Dillon u_int32_t dxfer_len, u_int32_t flags, int retry_count, 1735adc1304SPeter Avalos int timeout, const char *cmd_spec, ...); 1741f2de5d4SMatthew Dillon int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, 1751f2de5d4SMatthew Dillon u_int32_t dxfer_len, u_int32_t flags, int retry_count, 1765adc1304SPeter Avalos int timeout, const char *cmd_spec, 1771f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1781f2de5d4SMatthew Dillon void *gethook); 1795adc1304SPeter Avalos int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) 1805adc1304SPeter Avalos __printflike(2, 3); 1815adc1304SPeter Avalos int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, 1821f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1831f2de5d4SMatthew Dillon void *gethook); 1845adc1304SPeter Avalos int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, 1851f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1861f2de5d4SMatthew Dillon void *gethook); 1871f2de5d4SMatthew Dillon __END_DECLS 1881f2de5d4SMatthew Dillon 1891bd40720SMatthew Dillon #endif /* _SYS_CAMLIB_H_ */ 190