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*1bd40720SMatthew Dillon * $DragonFly: src/sys/sys/camlib.h,v 1.2 2006/05/20 02:42:13 dillon 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 65*1bd40720SMatthew Dillon #ifndef _SYS_CAMLIB_H_ 66*1bd40720SMatthew Dillon #define _SYS_CAMLIB_H_ 671f2de5d4SMatthew Dillon 681f2de5d4SMatthew Dillon #include <sys/cdefs.h> 691f2de5d4SMatthew Dillon #include <sys/param.h> 701f2de5d4SMatthew Dillon 711f2de5d4SMatthew Dillon #include <bus/cam/cam.h> 721f2de5d4SMatthew Dillon #include <bus/cam/cam_ccb.h> 731f2de5d4SMatthew Dillon 741f2de5d4SMatthew Dillon #define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */ 751f2de5d4SMatthew Dillon 761f2de5d4SMatthew Dillon /* 771f2de5d4SMatthew Dillon * Right now we hard code the transport layer device, but this will change 781f2de5d4SMatthew Dillon * if we ever get more than one transport layer. 791f2de5d4SMatthew Dillon */ 801f2de5d4SMatthew Dillon #define XPT_DEVICE "/dev/xpt0" 811f2de5d4SMatthew Dillon 821f2de5d4SMatthew Dillon 831f2de5d4SMatthew Dillon extern char cam_errbuf[]; 841f2de5d4SMatthew Dillon 851f2de5d4SMatthew Dillon struct cam_device { 861f2de5d4SMatthew Dillon char device_path[MAXPATHLEN+1];/* 871f2de5d4SMatthew Dillon * Pathname of the device 881f2de5d4SMatthew Dillon * given by the user. This 891f2de5d4SMatthew Dillon * may be null if the 901f2de5d4SMatthew Dillon * user states the device 911f2de5d4SMatthew Dillon * name and unit number 921f2de5d4SMatthew Dillon * separately. 931f2de5d4SMatthew Dillon */ 941f2de5d4SMatthew Dillon char given_dev_name[DEV_IDLEN+1];/* 951f2de5d4SMatthew Dillon * Device name given by 961f2de5d4SMatthew Dillon * the user. 971f2de5d4SMatthew Dillon */ 981f2de5d4SMatthew Dillon u_int32_t given_unit_number; /* 991f2de5d4SMatthew Dillon * Unit number given by 1001f2de5d4SMatthew Dillon * the user. 1011f2de5d4SMatthew Dillon */ 1021f2de5d4SMatthew Dillon char device_name[DEV_IDLEN+1];/* 1031f2de5d4SMatthew Dillon * Name of the device, 1041f2de5d4SMatthew Dillon * e.g. 'pass' 1051f2de5d4SMatthew Dillon */ 1061f2de5d4SMatthew Dillon u_int32_t dev_unit_num; /* Unit number of the passthrough 1071f2de5d4SMatthew Dillon * device associated with this 1081f2de5d4SMatthew Dillon * particular device. 1091f2de5d4SMatthew Dillon */ 1101f2de5d4SMatthew Dillon 1111f2de5d4SMatthew Dillon char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */ 1121f2de5d4SMatthew Dillon u_int32_t sim_unit_number; /* Controller unit number */ 1131f2de5d4SMatthew Dillon u_int32_t bus_id; /* Controller bus number */ 1141f2de5d4SMatthew Dillon lun_id_t target_lun; /* Logical Unit Number */ 1151f2de5d4SMatthew Dillon target_id_t target_id; /* Target ID */ 1161f2de5d4SMatthew Dillon path_id_t path_id; /* System SCSI bus number */ 1171f2de5d4SMatthew Dillon u_int16_t pd_type; /* type of peripheral device */ 1181f2de5d4SMatthew Dillon struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */ 1191f2de5d4SMatthew Dillon u_int8_t serial_num[252]; /* device serial number */ 1201f2de5d4SMatthew Dillon u_int8_t serial_num_len; /* length of the serial number */ 1211f2de5d4SMatthew Dillon u_int8_t sync_period; /* Negotiated sync period */ 1221f2de5d4SMatthew Dillon u_int8_t sync_offset; /* Negotiated sync offset */ 1231f2de5d4SMatthew Dillon u_int8_t bus_width; /* Negotiated bus width */ 1241f2de5d4SMatthew Dillon int fd; /* file descriptor for device */ 1251f2de5d4SMatthew Dillon }; 1261f2de5d4SMatthew Dillon 1271f2de5d4SMatthew Dillon __BEGIN_DECLS 1281f2de5d4SMatthew Dillon /* Basic utility commands */ 1291f2de5d4SMatthew Dillon struct cam_device * cam_open_device(const char *path, int flags); 1301f2de5d4SMatthew Dillon void cam_close_device(struct cam_device *dev); 1311f2de5d4SMatthew Dillon void cam_close_spec_device(struct cam_device *dev); 1321f2de5d4SMatthew Dillon struct cam_device * cam_open_spec_device(const char *dev_name, 1331f2de5d4SMatthew Dillon int unit, int flags, 1341f2de5d4SMatthew Dillon struct cam_device *device); 1351f2de5d4SMatthew Dillon struct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id, 1361f2de5d4SMatthew Dillon lun_id_t target_lun, int flags, 1371f2de5d4SMatthew Dillon struct cam_device *device); 1381f2de5d4SMatthew Dillon struct cam_device * cam_open_pass(const char *path, int flags, 1391f2de5d4SMatthew Dillon struct cam_device *device); 1401f2de5d4SMatthew Dillon union ccb * cam_getccb(struct cam_device *dev); 1411f2de5d4SMatthew Dillon void cam_freeccb(union ccb *ccb); 1421f2de5d4SMatthew Dillon int cam_send_ccb(struct cam_device *device, union ccb *ccb); 1431f2de5d4SMatthew Dillon char * cam_path_string(struct cam_device *dev, char *str, 1441f2de5d4SMatthew Dillon int len); 1451f2de5d4SMatthew Dillon struct cam_device * cam_device_dup(struct cam_device *device); 1461f2de5d4SMatthew Dillon void cam_device_copy(struct cam_device *src, 1471f2de5d4SMatthew Dillon struct cam_device *dst); 1481f2de5d4SMatthew Dillon int cam_get_device(const char *path, char *dev_name, 1491f2de5d4SMatthew Dillon int devnamelen, int *unit); 1501f2de5d4SMatthew Dillon 1511f2de5d4SMatthew Dillon /* 1521f2de5d4SMatthew Dillon * Buffer encoding/decoding routines, from the old SCSI library. 1531f2de5d4SMatthew Dillon */ 1541f2de5d4SMatthew Dillon int csio_decode(struct ccb_scsiio *csio, char *fmt, ...); 1551f2de5d4SMatthew Dillon int csio_decode_visit(struct ccb_scsiio *csio, char *fmt, 1561f2de5d4SMatthew Dillon void (*arg_put)(void *, int, void *, int, char *), 1571f2de5d4SMatthew Dillon void *puthook); 1581f2de5d4SMatthew Dillon int buff_decode(u_int8_t *buff, size_t len, char *fmt, ...); 1591f2de5d4SMatthew Dillon int buff_decode_visit(u_int8_t *buff, size_t len, char *fmt, 1601f2de5d4SMatthew Dillon void (*arg_put)(void *, int, void *, int, char *), 1611f2de5d4SMatthew Dillon void *puthook); 1621f2de5d4SMatthew Dillon int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, 1631f2de5d4SMatthew Dillon u_int32_t dxfer_len, u_int32_t flags, int retry_count, 1641f2de5d4SMatthew Dillon int timeout, char *cmd_spec, ...); 1651f2de5d4SMatthew Dillon int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, 1661f2de5d4SMatthew Dillon u_int32_t dxfer_len, u_int32_t flags, int retry_count, 1671f2de5d4SMatthew Dillon int timeout, char *cmd_spec, 1681f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1691f2de5d4SMatthew Dillon void *gethook); 1701f2de5d4SMatthew Dillon int csio_encode(struct ccb_scsiio *csio, char *fmt, ...); 1711f2de5d4SMatthew Dillon int buff_encode_visit(u_int8_t *buff, size_t len, char *fmt, 1721f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1731f2de5d4SMatthew Dillon void *gethook); 1741f2de5d4SMatthew Dillon int csio_encode_visit(struct ccb_scsiio *csio, char *fmt, 1751f2de5d4SMatthew Dillon int (*arg_get)(void *hook, char *field_name), 1761f2de5d4SMatthew Dillon void *gethook); 1771f2de5d4SMatthew Dillon __END_DECLS 1781f2de5d4SMatthew Dillon 179*1bd40720SMatthew Dillon #endif /* _SYS_CAMLIB_H_ */ 180