camlib.h revision 225736
11553Srgrimes/*
21553Srgrimes * Copyright (c) 1997, 1998 Kenneth D. Merry.
31553Srgrimes * All rights reserved.
41553Srgrimes *
51553Srgrimes * Redistribution and use in source and binary forms, with or without
61553Srgrimes * modification, are permitted provided that the following conditions
71553Srgrimes * are met:
81553Srgrimes * 1. Redistributions of source code must retain the above copyright
91553Srgrimes *    notice, this list of conditions and the following disclaimer.
101553Srgrimes * 2. The name of the author may not be used to endorse or promote products
111553Srgrimes *    derived from this software without specific prior written permission.
121553Srgrimes *
131553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
141553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
161553Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
171553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
191553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
201553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
211553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
221553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
231553Srgrimes * SUCH DAMAGE.
241553Srgrimes *
251553Srgrimes * $FreeBSD: stable/9/lib/libcam/camlib.h 95331 2002-04-23 23:58:20Z obrien $
261553Srgrimes */
271553Srgrimes/*
281553Srgrimes * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
291553Srgrimes * library and slightly modified.  The original header file had the following
301553Srgrimes * copyright:
311553Srgrimes */
321553Srgrimes/* Copyright (c) 1994 HD Associates (hd@world.std.com)
331553Srgrimes * All rights reserved.
341553Srgrimes *
3584693Sgad * Redistribution and use in source and binary forms, with or without
361553Srgrimes * modification, are permitted provided that the following conditions
371553Srgrimes * are met:
381553Srgrimes * 1. Redistributions of source code must retain the above copyright
391553Srgrimes *    notice, this list of conditions and the following disclaimer.
401553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
4184693Sgad *    notice, this list of conditions and the following disclaimer in the
4217202Sjoerg *    documentation and/or other materials provided with the distribution.
4384693Sgad * 3. All advertising materials mentioning features or use of this software
4484693Sgad *    must display the following acknowledgement:
4584693Sgad * This product includes software developed by HD Associates
461553Srgrimes * 4. Neither the name of the HD Associaates nor the names of its contributors
471553Srgrimes *    may be used to endorse or promote products derived from this software
481553Srgrimes *    without specific prior written permission.
491553Srgrimes *
501553Srgrimes * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
511553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
521553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
531553Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
541553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
551553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
561553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
571553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
581553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
591553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
601553Srgrimes * SUCH DAMAGE.
611553Srgrimes */
621553Srgrimes
631553Srgrimes
641553Srgrimes#ifndef _CAMLIB_H
651553Srgrimes#define _CAMLIB_H
661553Srgrimes
671553Srgrimes#include <sys/cdefs.h>
681553Srgrimes#include <sys/param.h>
691553Srgrimes
701553Srgrimes#include <cam/cam.h>
711553Srgrimes#include <cam/cam_ccb.h>
721553Srgrimes
731553Srgrimes#define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
741553Srgrimes
751553Srgrimes/*
761553Srgrimes * Right now we hard code the transport layer device, but this will change
771553Srgrimes * if we ever get more than one transport layer.
7878146Sgad */
791553Srgrimes#define XPT_DEVICE	"/dev/xpt0"
801553Srgrimes
811553Srgrimes
821553Srgrimesextern char cam_errbuf[];
831553Srgrimes
8417202Sjoergstruct cam_device {
8517202Sjoerg	char 		device_path[MAXPATHLEN];/*
861553Srgrimes						   * Pathname of the device
871553Srgrimes						   * given by the user. This
881553Srgrimes						   * may be null if the
891553Srgrimes						   * user states the device
901553Srgrimes						   * name and unit number
911553Srgrimes						   * separately.
921553Srgrimes						   */
931553Srgrimes	char		given_dev_name[DEV_IDLEN+1];/*
941553Srgrimes						     * Device name given by
951553Srgrimes						     * the user.
961553Srgrimes						     */
971553Srgrimes	u_int32_t	given_unit_number;	    /*
981553Srgrimes						     * Unit number given by
991553Srgrimes						     * the user.
1001553Srgrimes						     */
1011553Srgrimes	char		device_name[DEV_IDLEN+1];/*
1021553Srgrimes						  * Name of the device,
1031553Srgrimes						  * e.g. 'pass'
1041553Srgrimes						  */
1051553Srgrimes	u_int32_t	dev_unit_num;	/* Unit number of the passthrough
1061553Srgrimes					 * device associated with this
1071553Srgrimes					 * particular device.
1081553Srgrimes					 */
1091553Srgrimes
1101553Srgrimes	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */
1111553Srgrimes	u_int32_t	sim_unit_number; /* Controller unit number */
1121553Srgrimes	u_int32_t	bus_id;		 /* Controller bus number */
1131553Srgrimes	lun_id_t	target_lun;	 /* Logical Unit Number */
1141553Srgrimes	target_id_t	target_id;	 /* Target ID */
1151553Srgrimes	path_id_t	path_id;	 /* System SCSI bus number */
1161553Srgrimes	u_int16_t	pd_type;	 /* type of peripheral device */
1171553Srgrimes	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
1181553Srgrimes	u_int8_t	serial_num[252]; /* device serial number */
1191553Srgrimes	u_int8_t	serial_num_len;  /* length of the serial number */
1201553Srgrimes	u_int8_t	sync_period;	 /* Negotiated sync period */
1211553Srgrimes	u_int8_t	sync_offset;	 /* Negotiated sync offset */
1221553Srgrimes	u_int8_t	bus_width;	 /* Negotiated bus width */
1238857Srgrimes	int		fd;		 /* file descriptor for device */
1241553Srgrimes};
1251553Srgrimes
1261553Srgrimes__BEGIN_DECLS
1271553Srgrimes/* Basic utility commands */
1281553Srgrimesstruct cam_device *	cam_open_device(const char *path, int flags);
1291553Srgrimesvoid			cam_close_device(struct cam_device *dev);
1301553Srgrimesvoid			cam_close_spec_device(struct cam_device *dev);
1311553Srgrimesstruct cam_device *	cam_open_spec_device(const char *dev_name,
1321553Srgrimes					     int unit, int flags,
1331553Srgrimes					     struct cam_device *device);
1341553Srgrimesstruct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
1351553Srgrimes				     lun_id_t target_lun, int flags,
1361553Srgrimes				     struct cam_device *device);
1371553Srgrimesstruct cam_device *	cam_open_pass(const char *path, int flags,
1381553Srgrimes				      struct cam_device *device);
1391553Srgrimesunion ccb *		cam_getccb(struct cam_device *dev);
1401553Srgrimesvoid			cam_freeccb(union ccb *ccb);
1411553Srgrimesint			cam_send_ccb(struct cam_device *device, union ccb *ccb);
1421553Srgrimeschar *			cam_path_string(struct cam_device *dev, char *str,
1431553Srgrimes					int len);
1441553Srgrimesstruct cam_device *	cam_device_dup(struct cam_device *device);
1451553Srgrimesvoid			cam_device_copy(struct cam_device *src,
1461553Srgrimes					struct cam_device *dst);
1471553Srgrimesint			cam_get_device(const char *path, char *dev_name,
1481553Srgrimes				       int devnamelen, int *unit);
1491553Srgrimes
1501553Srgrimes/*
1511553Srgrimes * Buffer encoding/decoding routines, from the old SCSI library.
1521553Srgrimes */
1531553Srgrimesint csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
1541553Srgrimes		__printflike(2, 3);
1551553Srgrimesint csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
1561553Srgrimes		      void (*arg_put)(void *, int, void *, int, char *),
1571553Srgrimes		      void *puthook);
1581553Srgrimesint buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
1591553Srgrimes		__printflike(3, 4);
1601553Srgrimesint buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
1611553Srgrimes		      void (*arg_put)(void *, int, void *, int, char *),
1621553Srgrimes		      void *puthook);
1631553Srgrimesint csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
1641553Srgrimes	       u_int32_t dxfer_len, u_int32_t flags, int retry_count,
1651553Srgrimes	       int timeout, const char *cmd_spec, ...);
1661553Srgrimesint csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
1671553Srgrimes		     u_int32_t dxfer_len, u_int32_t flags, int retry_count,
1681553Srgrimes		     int timeout, const char *cmd_spec,
1691553Srgrimes		     int (*arg_get)(void *hook, char *field_name),
1701553Srgrimes		     void *gethook);
1711553Srgrimesint csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
17284693Sgad		__printflike(2, 3);
1731553Srgrimesint buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
1741553Srgrimes		      int (*arg_get)(void *hook, char *field_name),
1751553Srgrimes		      void *gethook);
1761553Srgrimesint csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
1771553Srgrimes		      int (*arg_get)(void *hook, char *field_name),
1781553Srgrimes		      void *gethook);
1791553Srgrimes__END_DECLS
1801553Srgrimes
1811553Srgrimes#endif /* _CAMLIB_H */
1821553Srgrimes