139209Sgibbs/*
239209Sgibbs * Copyright (c) 1997, 1998 Kenneth D. Merry.
339209Sgibbs * All rights reserved.
439209Sgibbs *
539209Sgibbs * Redistribution and use in source and binary forms, with or without
639209Sgibbs * modification, are permitted provided that the following conditions
739209Sgibbs * are met:
839209Sgibbs * 1. Redistributions of source code must retain the above copyright
939209Sgibbs *    notice, this list of conditions and the following disclaimer.
1039209Sgibbs * 2. The name of the author may not be used to endorse or promote products
1139209Sgibbs *    derived from this software without specific prior written permission.
1239209Sgibbs *
1339209Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1439209Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1539209Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1639209Sgibbs * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1739209Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1839209Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1939209Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2039209Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2139209Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2239209Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2339209Sgibbs * SUCH DAMAGE.
2439209Sgibbs *
2550476Speter * $FreeBSD: releng/10.3/lib/libcam/camlib.h 95331 2002-04-23 23:58:20Z obrien $
2639209Sgibbs */
2739209Sgibbs/*
2839209Sgibbs * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
2939209Sgibbs * library and slightly modified.  The original header file had the following
3039209Sgibbs * copyright:
3139209Sgibbs */
3239209Sgibbs/* Copyright (c) 1994 HD Associates (hd@world.std.com)
3339209Sgibbs * All rights reserved.
3439209Sgibbs *
3539209Sgibbs * Redistribution and use in source and binary forms, with or without
3639209Sgibbs * modification, are permitted provided that the following conditions
3739209Sgibbs * are met:
3839209Sgibbs * 1. Redistributions of source code must retain the above copyright
3939209Sgibbs *    notice, this list of conditions and the following disclaimer.
4039209Sgibbs * 2. Redistributions in binary form must reproduce the above copyright
4139209Sgibbs *    notice, this list of conditions and the following disclaimer in the
4239209Sgibbs *    documentation and/or other materials provided with the distribution.
4339209Sgibbs * 3. All advertising materials mentioning features or use of this software
4439209Sgibbs *    must display the following acknowledgement:
4539209Sgibbs * This product includes software developed by HD Associates
4639209Sgibbs * 4. Neither the name of the HD Associaates nor the names of its contributors
4739209Sgibbs *    may be used to endorse or promote products derived from this software
4839209Sgibbs *    without specific prior written permission.
4939209Sgibbs *
5039209Sgibbs * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
5139209Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5239209Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5339209Sgibbs * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
5439209Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5539209Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5639209Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5739209Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5839209Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5939209Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6039209Sgibbs * SUCH DAMAGE.
6139209Sgibbs */
6239209Sgibbs
6339209Sgibbs
6439209Sgibbs#ifndef _CAMLIB_H
6539209Sgibbs#define _CAMLIB_H
6639209Sgibbs
6739209Sgibbs#include <sys/cdefs.h>
6839209Sgibbs#include <sys/param.h>
6939209Sgibbs
7039209Sgibbs#include <cam/cam.h>
7139209Sgibbs#include <cam/cam_ccb.h>
7239209Sgibbs
7339209Sgibbs#define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
7439209Sgibbs
7539209Sgibbs/*
7639209Sgibbs * Right now we hard code the transport layer device, but this will change
7739209Sgibbs * if we ever get more than one transport layer.
7839209Sgibbs */
7939209Sgibbs#define XPT_DEVICE	"/dev/xpt0"
8039209Sgibbs
8139209Sgibbs
8239209Sgibbsextern char cam_errbuf[];
8339209Sgibbs
8439209Sgibbsstruct cam_device {
8595331Sobrien	char 		device_path[MAXPATHLEN];/*
8639209Sgibbs						   * Pathname of the device
8739209Sgibbs						   * given by the user. This
8839209Sgibbs						   * may be null if the
8939209Sgibbs						   * user states the device
9039209Sgibbs						   * name and unit number
9139209Sgibbs						   * separately.
9239209Sgibbs						   */
9339209Sgibbs	char		given_dev_name[DEV_IDLEN+1];/*
9439209Sgibbs						     * Device name given by
9539209Sgibbs						     * the user.
9639209Sgibbs						     */
9739209Sgibbs	u_int32_t	given_unit_number;	    /*
9839209Sgibbs						     * Unit number given by
9939209Sgibbs						     * the user.
10039209Sgibbs						     */
10139209Sgibbs	char		device_name[DEV_IDLEN+1];/*
10239209Sgibbs						  * Name of the device,
10339209Sgibbs						  * e.g. 'pass'
10439209Sgibbs						  */
10539209Sgibbs	u_int32_t	dev_unit_num;	/* Unit number of the passthrough
10639209Sgibbs					 * device associated with this
10739209Sgibbs					 * particular device.
10839209Sgibbs					 */
10939209Sgibbs
11039209Sgibbs	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */
11139209Sgibbs	u_int32_t	sim_unit_number; /* Controller unit number */
11239209Sgibbs	u_int32_t	bus_id;		 /* Controller bus number */
11339209Sgibbs	lun_id_t	target_lun;	 /* Logical Unit Number */
11439209Sgibbs	target_id_t	target_id;	 /* Target ID */
11539209Sgibbs	path_id_t	path_id;	 /* System SCSI bus number */
11639209Sgibbs	u_int16_t	pd_type;	 /* type of peripheral device */
11739209Sgibbs	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
11839209Sgibbs	u_int8_t	serial_num[252]; /* device serial number */
11939209Sgibbs	u_int8_t	serial_num_len;  /* length of the serial number */
12039209Sgibbs	u_int8_t	sync_period;	 /* Negotiated sync period */
12139209Sgibbs	u_int8_t	sync_offset;	 /* Negotiated sync offset */
12239209Sgibbs	u_int8_t	bus_width;	 /* Negotiated bus width */
12339209Sgibbs	int		fd;		 /* file descriptor for device */
12439209Sgibbs};
12539209Sgibbs
12639209Sgibbs__BEGIN_DECLS
12739209Sgibbs/* Basic utility commands */
12839209Sgibbsstruct cam_device *	cam_open_device(const char *path, int flags);
12939209Sgibbsvoid			cam_close_device(struct cam_device *dev);
13039209Sgibbsvoid			cam_close_spec_device(struct cam_device *dev);
13139209Sgibbsstruct cam_device *	cam_open_spec_device(const char *dev_name,
13239209Sgibbs					     int unit, int flags,
13339209Sgibbs					     struct cam_device *device);
13439209Sgibbsstruct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
13539209Sgibbs				     lun_id_t target_lun, int flags,
13639209Sgibbs				     struct cam_device *device);
13739209Sgibbsstruct cam_device *	cam_open_pass(const char *path, int flags,
13839209Sgibbs				      struct cam_device *device);
13939209Sgibbsunion ccb *		cam_getccb(struct cam_device *dev);
14039209Sgibbsvoid			cam_freeccb(union ccb *ccb);
14139209Sgibbsint			cam_send_ccb(struct cam_device *device, union ccb *ccb);
14239209Sgibbschar *			cam_path_string(struct cam_device *dev, char *str,
14339209Sgibbs					int len);
14439209Sgibbsstruct cam_device *	cam_device_dup(struct cam_device *device);
14539209Sgibbsvoid			cam_device_copy(struct cam_device *src,
14639209Sgibbs					struct cam_device *dst);
14739209Sgibbsint			cam_get_device(const char *path, char *dev_name,
14839209Sgibbs				       int devnamelen, int *unit);
14939209Sgibbs
15039209Sgibbs/*
15139209Sgibbs * Buffer encoding/decoding routines, from the old SCSI library.
15239209Sgibbs */
15388090Skbyancint csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
15488090Skbyanc		__printflike(2, 3);
15588090Skbyancint csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
15639209Sgibbs		      void (*arg_put)(void *, int, void *, int, char *),
15739209Sgibbs		      void *puthook);
15888090Skbyancint buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
15988090Skbyanc		__printflike(3, 4);
16088090Skbyancint buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
16139209Sgibbs		      void (*arg_put)(void *, int, void *, int, char *),
16239209Sgibbs		      void *puthook);
16339209Sgibbsint csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
16439209Sgibbs	       u_int32_t dxfer_len, u_int32_t flags, int retry_count,
16588090Skbyanc	       int timeout, const char *cmd_spec, ...);
16639209Sgibbsint csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
16739209Sgibbs		     u_int32_t dxfer_len, u_int32_t flags, int retry_count,
16888090Skbyanc		     int timeout, const char *cmd_spec,
16939209Sgibbs		     int (*arg_get)(void *hook, char *field_name),
17039209Sgibbs		     void *gethook);
17188090Skbyancint csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
17288090Skbyanc		__printflike(2, 3);
17388090Skbyancint buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
17439209Sgibbs		      int (*arg_get)(void *hook, char *field_name),
17539209Sgibbs		      void *gethook);
17688090Skbyancint csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
17739209Sgibbs		      int (*arg_get)(void *hook, char *field_name),
17839209Sgibbs		      void *gethook);
17939209Sgibbs__END_DECLS
18039209Sgibbs
18139209Sgibbs#endif /* _CAMLIB_H */
182