xref: /freebsd/lib/libcam/camlib.h (revision bf8aef63e10957004c61f8febdbc3921f9f190c9)
1f736a450SJustin T. Gibbs /*
2f736a450SJustin T. Gibbs  * Copyright (c) 1997, 1998 Kenneth D. Merry.
3f736a450SJustin T. Gibbs  * All rights reserved.
4f736a450SJustin T. Gibbs  *
5f736a450SJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
6f736a450SJustin T. Gibbs  * modification, are permitted provided that the following conditions
7f736a450SJustin T. Gibbs  * are met:
8f736a450SJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
9f736a450SJustin T. Gibbs  *    notice, this list of conditions and the following disclaimer.
10f736a450SJustin T. Gibbs  * 2. The name of the author may not be used to endorse or promote products
11f736a450SJustin T. Gibbs  *    derived from this software without specific prior written permission.
12f736a450SJustin T. Gibbs  *
13f736a450SJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14f736a450SJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15f736a450SJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16f736a450SJustin T. Gibbs  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17f736a450SJustin T. Gibbs  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18f736a450SJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19f736a450SJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20f736a450SJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21f736a450SJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22f736a450SJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23f736a450SJustin T. Gibbs  * SUCH DAMAGE.
24f736a450SJustin T. Gibbs  *
257f3dea24SPeter Wemm  * $FreeBSD$
26f736a450SJustin T. Gibbs  */
27f736a450SJustin T. Gibbs /*
28f736a450SJustin T. Gibbs  * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
29f736a450SJustin T. Gibbs  * library and slightly modified.  The original header file had the following
30f736a450SJustin T. Gibbs  * copyright:
31f736a450SJustin T. Gibbs  */
32f736a450SJustin T. Gibbs /* Copyright (c) 1994 HD Associates (hd@world.std.com)
33f736a450SJustin T. Gibbs  * All rights reserved.
34f736a450SJustin T. Gibbs  *
35f736a450SJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
36f736a450SJustin T. Gibbs  * modification, are permitted provided that the following conditions
37f736a450SJustin T. Gibbs  * are met:
38f736a450SJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
39f736a450SJustin T. Gibbs  *    notice, this list of conditions and the following disclaimer.
40f736a450SJustin T. Gibbs  * 2. Redistributions in binary form must reproduce the above copyright
41f736a450SJustin T. Gibbs  *    notice, this list of conditions and the following disclaimer in the
42f736a450SJustin T. Gibbs  *    documentation and/or other materials provided with the distribution.
43f736a450SJustin T. Gibbs  * 3. All advertising materials mentioning features or use of this software
44f736a450SJustin T. Gibbs  *    must display the following acknowledgement:
45f736a450SJustin T. Gibbs  * This product includes software developed by HD Associates
46f736a450SJustin T. Gibbs  * 4. Neither the name of the HD Associaates nor the names of its contributors
47f736a450SJustin T. Gibbs  *    may be used to endorse or promote products derived from this software
48f736a450SJustin T. Gibbs  *    without specific prior written permission.
49f736a450SJustin T. Gibbs  *
50f736a450SJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
51f736a450SJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52f736a450SJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53f736a450SJustin T. Gibbs  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
54f736a450SJustin T. Gibbs  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55f736a450SJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56f736a450SJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57f736a450SJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58f736a450SJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59f736a450SJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60f736a450SJustin T. Gibbs  * SUCH DAMAGE.
61f736a450SJustin T. Gibbs  */
62f736a450SJustin T. Gibbs 
63f736a450SJustin T. Gibbs 
64f736a450SJustin T. Gibbs #ifndef _CAMLIB_H
65f736a450SJustin T. Gibbs #define _CAMLIB_H
66f736a450SJustin T. Gibbs 
67f736a450SJustin T. Gibbs #include <sys/cdefs.h>
68f736a450SJustin T. Gibbs #include <sys/param.h>
69f736a450SJustin T. Gibbs 
70f736a450SJustin T. Gibbs #include <cam/cam.h>
71f736a450SJustin T. Gibbs #include <cam/cam_ccb.h>
72f736a450SJustin T. Gibbs 
73f736a450SJustin T. Gibbs #define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
74f736a450SJustin T. Gibbs 
75f736a450SJustin T. Gibbs /*
76f736a450SJustin T. Gibbs  * Right now we hard code the transport layer device, but this will change
77f736a450SJustin T. Gibbs  * if we ever get more than one transport layer.
78f736a450SJustin T. Gibbs  */
79f736a450SJustin T. Gibbs #define XPT_DEVICE	"/dev/xpt0"
80f736a450SJustin T. Gibbs 
81f736a450SJustin T. Gibbs 
82f736a450SJustin T. Gibbs extern char cam_errbuf[];
83f736a450SJustin T. Gibbs 
84f736a450SJustin T. Gibbs struct cam_device {
85bf8aef63SDavid E. O'Brien 	char 		device_path[MAXPATHLEN];/*
86f736a450SJustin T. Gibbs 						   * Pathname of the device
87f736a450SJustin T. Gibbs 						   * given by the user. This
88f736a450SJustin T. Gibbs 						   * may be null if the
89f736a450SJustin T. Gibbs 						   * user states the device
90f736a450SJustin T. Gibbs 						   * name and unit number
91f736a450SJustin T. Gibbs 						   * separately.
92f736a450SJustin T. Gibbs 						   */
93f736a450SJustin T. Gibbs 	char		given_dev_name[DEV_IDLEN+1];/*
94f736a450SJustin T. Gibbs 						     * Device name given by
95f736a450SJustin T. Gibbs 						     * the user.
96f736a450SJustin T. Gibbs 						     */
97f736a450SJustin T. Gibbs 	u_int32_t	given_unit_number;	    /*
98f736a450SJustin T. Gibbs 						     * Unit number given by
99f736a450SJustin T. Gibbs 						     * the user.
100f736a450SJustin T. Gibbs 						     */
101f736a450SJustin T. Gibbs 	char		device_name[DEV_IDLEN+1];/*
102f736a450SJustin T. Gibbs 						  * Name of the device,
103f736a450SJustin T. Gibbs 						  * e.g. 'pass'
104f736a450SJustin T. Gibbs 						  */
105f736a450SJustin T. Gibbs 	u_int32_t	dev_unit_num;	/* Unit number of the passthrough
106f736a450SJustin T. Gibbs 					 * device associated with this
107f736a450SJustin T. Gibbs 					 * particular device.
108f736a450SJustin T. Gibbs 					 */
109f736a450SJustin T. Gibbs 
110f736a450SJustin T. Gibbs 	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */
111f736a450SJustin T. Gibbs 	u_int32_t	sim_unit_number; /* Controller unit number */
112f736a450SJustin T. Gibbs 	u_int32_t	bus_id;		 /* Controller bus number */
113f736a450SJustin T. Gibbs 	lun_id_t	target_lun;	 /* Logical Unit Number */
114f736a450SJustin T. Gibbs 	target_id_t	target_id;	 /* Target ID */
115f736a450SJustin T. Gibbs 	path_id_t	path_id;	 /* System SCSI bus number */
116f736a450SJustin T. Gibbs 	u_int16_t	pd_type;	 /* type of peripheral device */
117f736a450SJustin T. Gibbs 	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
118f736a450SJustin T. Gibbs 	u_int8_t	serial_num[252]; /* device serial number */
119f736a450SJustin T. Gibbs 	u_int8_t	serial_num_len;  /* length of the serial number */
120f736a450SJustin T. Gibbs 	u_int8_t	sync_period;	 /* Negotiated sync period */
121f736a450SJustin T. Gibbs 	u_int8_t	sync_offset;	 /* Negotiated sync offset */
122f736a450SJustin T. Gibbs 	u_int8_t	bus_width;	 /* Negotiated bus width */
123f736a450SJustin T. Gibbs 	int		fd;		 /* file descriptor for device */
124f736a450SJustin T. Gibbs };
125f736a450SJustin T. Gibbs 
126f736a450SJustin T. Gibbs __BEGIN_DECLS
127f736a450SJustin T. Gibbs /* Basic utility commands */
128f736a450SJustin T. Gibbs struct cam_device *	cam_open_device(const char *path, int flags);
129f736a450SJustin T. Gibbs void			cam_close_device(struct cam_device *dev);
130f736a450SJustin T. Gibbs void			cam_close_spec_device(struct cam_device *dev);
131f736a450SJustin T. Gibbs struct cam_device *	cam_open_spec_device(const char *dev_name,
132f736a450SJustin T. Gibbs 					     int unit, int flags,
133f736a450SJustin T. Gibbs 					     struct cam_device *device);
134f736a450SJustin T. Gibbs struct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
135f736a450SJustin T. Gibbs 				     lun_id_t target_lun, int flags,
136f736a450SJustin T. Gibbs 				     struct cam_device *device);
137f736a450SJustin T. Gibbs struct cam_device *	cam_open_pass(const char *path, int flags,
138f736a450SJustin T. Gibbs 				      struct cam_device *device);
139f736a450SJustin T. Gibbs union ccb *		cam_getccb(struct cam_device *dev);
140f736a450SJustin T. Gibbs void			cam_freeccb(union ccb *ccb);
141f736a450SJustin T. Gibbs int			cam_send_ccb(struct cam_device *device, union ccb *ccb);
142f736a450SJustin T. Gibbs char *			cam_path_string(struct cam_device *dev, char *str,
143f736a450SJustin T. Gibbs 					int len);
144f736a450SJustin T. Gibbs struct cam_device *	cam_device_dup(struct cam_device *device);
145f736a450SJustin T. Gibbs void			cam_device_copy(struct cam_device *src,
146f736a450SJustin T. Gibbs 					struct cam_device *dst);
147f736a450SJustin T. Gibbs int			cam_get_device(const char *path, char *dev_name,
148f736a450SJustin T. Gibbs 				       int devnamelen, int *unit);
149f736a450SJustin T. Gibbs 
150f736a450SJustin T. Gibbs /*
151f736a450SJustin T. Gibbs  * Buffer encoding/decoding routines, from the old SCSI library.
152f736a450SJustin T. Gibbs  */
153cb28eb78SKelly Yancey int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
154cb28eb78SKelly Yancey 		__printflike(2, 3);
155cb28eb78SKelly Yancey int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
156f736a450SJustin T. Gibbs 		      void (*arg_put)(void *, int, void *, int, char *),
157f736a450SJustin T. Gibbs 		      void *puthook);
158cb28eb78SKelly Yancey int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
159cb28eb78SKelly Yancey 		__printflike(3, 4);
160cb28eb78SKelly Yancey int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
161f736a450SJustin T. Gibbs 		      void (*arg_put)(void *, int, void *, int, char *),
162f736a450SJustin T. Gibbs 		      void *puthook);
163f736a450SJustin T. Gibbs int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
164f736a450SJustin T. Gibbs 	       u_int32_t dxfer_len, u_int32_t flags, int retry_count,
165cb28eb78SKelly Yancey 	       int timeout, const char *cmd_spec, ...);
166f736a450SJustin T. Gibbs int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
167f736a450SJustin T. Gibbs 		     u_int32_t dxfer_len, u_int32_t flags, int retry_count,
168cb28eb78SKelly Yancey 		     int timeout, const char *cmd_spec,
169f736a450SJustin T. Gibbs 		     int (*arg_get)(void *hook, char *field_name),
170f736a450SJustin T. Gibbs 		     void *gethook);
171cb28eb78SKelly Yancey int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
172cb28eb78SKelly Yancey 		__printflike(2, 3);
173cb28eb78SKelly Yancey int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
174f736a450SJustin T. Gibbs 		      int (*arg_get)(void *hook, char *field_name),
175f736a450SJustin T. Gibbs 		      void *gethook);
176cb28eb78SKelly Yancey int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
177f736a450SJustin T. Gibbs 		      int (*arg_get)(void *hook, char *field_name),
178f736a450SJustin T. Gibbs 		      void *gethook);
179f736a450SJustin T. Gibbs __END_DECLS
180f736a450SJustin T. Gibbs 
181f736a450SJustin T. Gibbs #endif /* _CAMLIB_H */
182