camlib.h revision 50476
1189251Ssam/*
2189251Ssam * Copyright (c) 1997, 1998 Kenneth D. Merry.
3189251Ssam * All rights reserved.
4189251Ssam *
5189251Ssam * Redistribution and use in source and binary forms, with or without
6189251Ssam * modification, are permitted provided that the following conditions
7189251Ssam * are met:
8189251Ssam * 1. Redistributions of source code must retain the above copyright
9189251Ssam *    notice, this list of conditions and the following disclaimer.
10189251Ssam * 2. The name of the author may not be used to endorse or promote products
11189251Ssam *    derived from this software without specific prior written permission.
12189251Ssam *
13189251Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14189251Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15189251Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16189251Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17189251Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18214734Srpaulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19189251Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20189251Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21189251Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22189251Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23189251Ssam * SUCH DAMAGE.
24189251Ssam *
25189251Ssam * $FreeBSD: head/lib/libcam/camlib.h 50476 1999-08-28 00:22:10Z peter $
26189251Ssam */
27189251Ssam/*
28189251Ssam * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
29189251Ssam * library and slightly modified.  The original header file had the following
30189251Ssam * copyright:
31189251Ssam */
32189251Ssam/* Copyright (c) 1994 HD Associates (hd@world.std.com)
33189251Ssam * All rights reserved.
34189251Ssam *
35189251Ssam * Redistribution and use in source and binary forms, with or without
36189251Ssam * modification, are permitted provided that the following conditions
37189251Ssam * are met:
38189251Ssam * 1. Redistributions of source code must retain the above copyright
39189251Ssam *    notice, this list of conditions and the following disclaimer.
40189251Ssam * 2. Redistributions in binary form must reproduce the above copyright
41189251Ssam *    notice, this list of conditions and the following disclaimer in the
42189251Ssam *    documentation and/or other materials provided with the distribution.
43189251Ssam * 3. All advertising materials mentioning features or use of this software
44189251Ssam *    must display the following acknowledgement:
45189251Ssam * This product includes software developed by HD Associates
46189251Ssam * 4. Neither the name of the HD Associaates nor the names of its contributors
47189251Ssam *    may be used to endorse or promote products derived from this software
48189251Ssam *    without specific prior written permission.
49189251Ssam *
50189251Ssam * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
51189251Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52189251Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53189251Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
54189251Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55189251Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56189251Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57189251Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58189251Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59189251Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60189251Ssam * SUCH DAMAGE.
61189251Ssam */
62189251Ssam
63189251Ssam
64189251Ssam#ifndef _CAMLIB_H
65189251Ssam#define _CAMLIB_H
66189251Ssam
67189251Ssam#include <sys/cdefs.h>
68189251Ssam#include <sys/param.h>
69189251Ssam
70189251Ssam#include <cam/cam.h>
71189251Ssam#include <cam/cam_ccb.h>
72189251Ssam
73189251Ssam#define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
74189251Ssam
75189251Ssam/*
76189251Ssam * Right now we hard code the transport layer device, but this will change
77189251Ssam * if we ever get more than one transport layer.
78189251Ssam */
79189251Ssam#define XPT_DEVICE	"/dev/xpt0"
80189251Ssam
81189251Ssam
82189251Ssamextern char cam_errbuf[];
83189251Ssam
84189251Ssamstruct cam_device {
85189251Ssam	char 		device_path[MAXPATHLEN+1];/*
86189251Ssam						   * Pathname of the device
87189251Ssam						   * given by the user. This
88189251Ssam						   * may be null if the
89189251Ssam						   * user states the device
90189251Ssam						   * name and unit number
91189251Ssam						   * separately.
92189251Ssam						   */
93189251Ssam	char		given_dev_name[DEV_IDLEN+1];/*
94189251Ssam						     * Device name given by
95189251Ssam						     * the user.
96189251Ssam						     */
97189251Ssam	u_int32_t	given_unit_number;	    /*
98189251Ssam						     * Unit number given by
99189251Ssam						     * the user.
100189251Ssam						     */
101189251Ssam	char		device_name[DEV_IDLEN+1];/*
102189251Ssam						  * Name of the device,
103189251Ssam						  * e.g. 'pass'
104189251Ssam						  */
105189251Ssam	u_int32_t	dev_unit_num;	/* Unit number of the passthrough
106189251Ssam					 * device associated with this
107189251Ssam					 * particular device.
108189251Ssam					 */
109189251Ssam
110189251Ssam	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */
111189251Ssam	u_int32_t	sim_unit_number; /* Controller unit number */
112189251Ssam	u_int32_t	bus_id;		 /* Controller bus number */
113189251Ssam	lun_id_t	target_lun;	 /* Logical Unit Number */
114189251Ssam	target_id_t	target_id;	 /* Target ID */
115189251Ssam	path_id_t	path_id;	 /* System SCSI bus number */
116189251Ssam	u_int16_t	pd_type;	 /* type of peripheral device */
117189251Ssam	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
118189251Ssam	u_int8_t	serial_num[252]; /* device serial number */
119189251Ssam	u_int8_t	serial_num_len;  /* length of the serial number */
120189251Ssam	u_int8_t	sync_period;	 /* Negotiated sync period */
121189251Ssam	u_int8_t	sync_offset;	 /* Negotiated sync offset */
122189251Ssam	u_int8_t	bus_width;	 /* Negotiated bus width */
123189251Ssam	int		fd;		 /* file descriptor for device */
124189251Ssam};
125189251Ssam
126189251Ssam__BEGIN_DECLS
127189251Ssam/* Basic utility commands */
128189251Ssamstruct cam_device *	cam_open_device(const char *path, int flags);
129189251Ssamvoid			cam_close_device(struct cam_device *dev);
130189251Ssamvoid			cam_close_spec_device(struct cam_device *dev);
131189251Ssamstruct cam_device *	cam_open_spec_device(const char *dev_name,
132189251Ssam					     int unit, int flags,
133189251Ssam					     struct cam_device *device);
134189251Ssamstruct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
135189251Ssam				     lun_id_t target_lun, int flags,
136189251Ssam				     struct cam_device *device);
137189251Ssamstruct cam_device *	cam_open_pass(const char *path, int flags,
138189251Ssam				      struct cam_device *device);
139189251Ssamunion ccb *		cam_getccb(struct cam_device *dev);
140189251Ssamvoid			cam_freeccb(union ccb *ccb);
141189251Ssamint			cam_send_ccb(struct cam_device *device, union ccb *ccb);
142189251Ssamchar *			cam_path_string(struct cam_device *dev, char *str,
143189251Ssam					int len);
144189251Ssamstruct cam_device *	cam_device_dup(struct cam_device *device);
145189251Ssamvoid			cam_device_copy(struct cam_device *src,
146189251Ssam					struct cam_device *dst);
147189251Ssamint			cam_get_device(const char *path, char *dev_name,
148189251Ssam				       int devnamelen, int *unit);
149189251Ssam
150189251Ssam/*
151 * Buffer encoding/decoding routines, from the old SCSI library.
152 */
153int csio_decode(struct ccb_scsiio *csio, char *fmt, ...);
154int csio_decode_visit(struct ccb_scsiio *csio, char *fmt,
155		      void (*arg_put)(void *, int, void *, int, char *),
156		      void *puthook);
157int buff_decode(u_int8_t *buff, size_t len, char *fmt, ...);
158int buff_decode_visit(u_int8_t *buff, size_t len, char *fmt,
159		      void (*arg_put)(void *, int, void *, int, char *),
160		      void *puthook);
161int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
162	       u_int32_t dxfer_len, u_int32_t flags, int retry_count,
163	       int timeout, char *cmd_spec, ...);
164int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
165		     u_int32_t dxfer_len, u_int32_t flags, int retry_count,
166		     int timeout, char *cmd_spec,
167		     int (*arg_get)(void *hook, char *field_name),
168		     void *gethook);
169int csio_encode(struct ccb_scsiio *csio, char *fmt, ...);
170int buff_encode_visit(u_int8_t *buff, size_t len, char *fmt,
171		      int (*arg_get)(void *hook, char *field_name),
172		      void *gethook);
173int csio_encode_visit(struct ccb_scsiio *csio, char *fmt,
174		      int (*arg_get)(void *hook, char *field_name),
175		      void *gethook);
176__END_DECLS
177
178#endif /* _CAMLIB_H */
179