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