xref: /freebsd/lib/libcam/camlib.h (revision a2f733ab)
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  */
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/param.h>
68f736a450SJustin T. Gibbs 
69f736a450SJustin T. Gibbs #include <cam/cam.h>
70f736a450SJustin T. Gibbs #include <cam/cam_ccb.h>
71f736a450SJustin T. Gibbs 
7281321d0aSEnji Cooper #define	CAM_ERRBUF_SIZE 2048	/* CAM library error string size */
73f736a450SJustin T. Gibbs 
74f736a450SJustin T. Gibbs /*
75f736a450SJustin T. Gibbs  * Right now we hard code the transport layer device, but this will change
76f736a450SJustin T. Gibbs  * if we ever get more than one transport layer.
77f736a450SJustin T. Gibbs  */
78f736a450SJustin T. Gibbs #define	XPT_DEVICE	"/dev/xpt0"
79f736a450SJustin T. Gibbs 
80f736a450SJustin T. Gibbs 
81f736a450SJustin T. Gibbs extern char cam_errbuf[];
82f736a450SJustin T. Gibbs 
83f736a450SJustin T. Gibbs struct cam_device {
84bf8aef63SDavid E. O'Brien 	char 		device_path[MAXPATHLEN];/*
85f736a450SJustin T. Gibbs 						   * Pathname of the device
86f736a450SJustin T. Gibbs 						   * given by the user. This
87f736a450SJustin T. Gibbs 						   * may be null if the
88f736a450SJustin T. Gibbs 						   * user states the device
89f736a450SJustin T. Gibbs 						   * name and unit number
90f736a450SJustin T. Gibbs 						   * separately.
91f736a450SJustin T. Gibbs 						   */
92f736a450SJustin T. Gibbs 	char		given_dev_name[DEV_IDLEN+1];/*
93f736a450SJustin T. Gibbs 						     * Device name given by
94f736a450SJustin T. Gibbs 						     * the user.
95f736a450SJustin T. Gibbs 						     */
96f9ffa1efSWarner Losh 	uint32_t	given_unit_number;	    /*
97f736a450SJustin T. Gibbs 						     * Unit number given by
98f736a450SJustin T. Gibbs 						     * the user.
99f736a450SJustin T. Gibbs 						     */
100f736a450SJustin T. Gibbs 	char		device_name[DEV_IDLEN+1];/*
101f736a450SJustin T. Gibbs 						  * Name of the device,
102f736a450SJustin T. Gibbs 						  * e.g. 'pass'
103f736a450SJustin T. Gibbs 						  */
104f9ffa1efSWarner Losh 	uint32_t	dev_unit_num;	/* Unit number of the passthrough
105f736a450SJustin T. Gibbs 					 * device associated with this
106f736a450SJustin T. Gibbs 					 * particular device.
107f736a450SJustin T. Gibbs 					 */
108f736a450SJustin T. Gibbs 
109f736a450SJustin T. Gibbs 	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */
110f9ffa1efSWarner Losh 	uint32_t	sim_unit_number; /* Controller unit number */
111f9ffa1efSWarner Losh 	uint32_t	bus_id;		 /* Controller bus number */
112f736a450SJustin T. Gibbs 	lun_id_t	target_lun;	 /* Logical Unit Number */
113f736a450SJustin T. Gibbs 	target_id_t	target_id;	 /* Target ID */
114f736a450SJustin T. Gibbs 	path_id_t	path_id;	 /* System SCSI bus number */
115f9ffa1efSWarner Losh 	uint16_t	pd_type;	 /* type of peripheral device */
116f736a450SJustin T. Gibbs 	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
117f9ffa1efSWarner Losh 	uint8_t	serial_num[252]; /* device serial number */
118f9ffa1efSWarner Losh 	uint8_t	serial_num_len;  /* length of the serial number */
119f9ffa1efSWarner Losh 	uint8_t	sync_period;	 /* Negotiated sync period */
120f9ffa1efSWarner Losh 	uint8_t	sync_offset;	 /* Negotiated sync offset */
121f9ffa1efSWarner Losh 	uint8_t	bus_width;	 /* Negotiated bus width */
122f736a450SJustin T. Gibbs 	int		fd;		 /* file descriptor for device */
123f736a450SJustin T. Gibbs };
124f736a450SJustin T. Gibbs 
125f736a450SJustin T. Gibbs __BEGIN_DECLS
126f736a450SJustin T. Gibbs /* Basic utility commands */
127f736a450SJustin T. Gibbs struct cam_device *	cam_open_device(const char *path, int flags);
128f736a450SJustin T. Gibbs void			cam_close_device(struct cam_device *dev);
129f736a450SJustin T. Gibbs void			cam_close_spec_device(struct cam_device *dev);
130f736a450SJustin T. Gibbs struct cam_device *	cam_open_spec_device(const char *dev_name,
131f736a450SJustin T. Gibbs 					     int unit, int flags,
132f736a450SJustin T. Gibbs 					     struct cam_device *device);
133f736a450SJustin T. Gibbs struct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
134f736a450SJustin T. Gibbs 				     lun_id_t target_lun, int flags,
135f736a450SJustin T. Gibbs 				     struct cam_device *device);
136f736a450SJustin T. Gibbs struct cam_device *	cam_open_pass(const char *path, int flags,
137f736a450SJustin T. Gibbs 				      struct cam_device *device);
138f736a450SJustin T. Gibbs union ccb *		cam_getccb(struct cam_device *dev);
139f736a450SJustin T. Gibbs void			cam_freeccb(union ccb *ccb);
140f736a450SJustin T. Gibbs int			cam_send_ccb(struct cam_device *device, union ccb *ccb);
141f736a450SJustin T. Gibbs char *			cam_path_string(struct cam_device *dev, char *str,
142f736a450SJustin T. Gibbs 					int len);
143f736a450SJustin T. Gibbs struct cam_device *	cam_device_dup(struct cam_device *device);
144f736a450SJustin T. Gibbs void			cam_device_copy(struct cam_device *src,
145f736a450SJustin T. Gibbs 					struct cam_device *dst);
146f736a450SJustin T. Gibbs int			cam_get_device(const char *path, char *dev_name,
147f736a450SJustin T. Gibbs 				       int devnamelen, int *unit);
148f736a450SJustin T. Gibbs 
149f736a450SJustin T. Gibbs /*
150f736a450SJustin T. Gibbs  * Buffer encoding/decoding routines, from the old SCSI library.
151f736a450SJustin T. Gibbs  */
152cb28eb78SKelly Yancey int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
153cb28eb78SKelly Yancey 		__printflike(2, 3);
154cb28eb78SKelly Yancey int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
155f736a450SJustin T. Gibbs 		      void (*arg_put)(void *, int, void *, int, char *),
156f736a450SJustin T. Gibbs 		      void *puthook);
157f9ffa1efSWarner Losh int buff_decode(uint8_t *buff, size_t len, const char *fmt, ...)
158cb28eb78SKelly Yancey 		__printflike(3, 4);
159f9ffa1efSWarner Losh int buff_decode_visit(uint8_t *buff, size_t len, const char *fmt,
160f736a450SJustin T. Gibbs 		      void (*arg_put)(void *, int, void *, int, char *),
161f736a450SJustin T. Gibbs 		      void *puthook);
162f9ffa1efSWarner Losh int csio_build(struct ccb_scsiio *csio, uint8_t *data_ptr,
163f9ffa1efSWarner Losh 	       uint32_t dxfer_len, uint32_t flags, int retry_count,
164cb28eb78SKelly Yancey 	       int timeout, const char *cmd_spec, ...);
165f9ffa1efSWarner Losh int csio_build_visit(struct ccb_scsiio *csio, uint8_t *data_ptr,
166f9ffa1efSWarner Losh 		     uint32_t dxfer_len, uint32_t flags, int retry_count,
167cb28eb78SKelly Yancey 		     int timeout, const char *cmd_spec,
168f736a450SJustin T. Gibbs 		     int (*arg_get)(void *hook, char *field_name),
169f736a450SJustin T. Gibbs 		     void *gethook);
170cb28eb78SKelly Yancey int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
171cb28eb78SKelly Yancey 		__printflike(2, 3);
172f9ffa1efSWarner Losh int buff_encode_visit(uint8_t *buff, size_t len, const char *fmt,
173f736a450SJustin T. Gibbs 		      int (*arg_get)(void *hook, char *field_name),
174f736a450SJustin T. Gibbs 		      void *gethook);
175cb28eb78SKelly Yancey int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
176f736a450SJustin T. Gibbs 		      int (*arg_get)(void *hook, char *field_name),
177f736a450SJustin T. Gibbs 		      void *gethook);
178f736a450SJustin T. Gibbs __END_DECLS
179f736a450SJustin T. Gibbs 
180f736a450SJustin T. Gibbs #endif /* _CAMLIB_H */
181