xref: /dflybsd-src/sys/sys/camlib.h (revision 7efec73e6977f03c831f7c3c0a7080b8de0e2c38)
11f2de5d4SMatthew Dillon /*
21f2de5d4SMatthew Dillon  * Copyright (c) 1997, 1998 Kenneth D. Merry.
31f2de5d4SMatthew Dillon  * All rights reserved.
41f2de5d4SMatthew Dillon  *
51f2de5d4SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
61f2de5d4SMatthew Dillon  * modification, are permitted provided that the following conditions
71f2de5d4SMatthew Dillon  * are met:
81f2de5d4SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
91f2de5d4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
101f2de5d4SMatthew Dillon  * 2. The name of the author may not be used to endorse or promote products
111f2de5d4SMatthew Dillon  *    derived from this software without specific prior written permission.
121f2de5d4SMatthew Dillon  *
131f2de5d4SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
141f2de5d4SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151f2de5d4SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
161f2de5d4SMatthew Dillon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
171f2de5d4SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181f2de5d4SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
191f2de5d4SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
201f2de5d4SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
211f2de5d4SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
221f2de5d4SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
231f2de5d4SMatthew Dillon  * SUCH DAMAGE.
241f2de5d4SMatthew Dillon  *
251f2de5d4SMatthew Dillon  * $FreeBSD: src/lib/libcam/camlib.h,v 1.2 1999/08/28 00:04:06 peter Exp $
261f2de5d4SMatthew Dillon  */
271f2de5d4SMatthew Dillon /*
281f2de5d4SMatthew Dillon  * Buffer encoding/decoding routines taken from the original FreeBSD SCSI
291f2de5d4SMatthew Dillon  * library and slightly modified.  The original header file had the following
301f2de5d4SMatthew Dillon  * copyright:
311f2de5d4SMatthew Dillon  */
321f2de5d4SMatthew Dillon /* Copyright (c) 1994 HD Associates (hd@world.std.com)
331f2de5d4SMatthew Dillon  * All rights reserved.
341f2de5d4SMatthew Dillon  *
351f2de5d4SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
361f2de5d4SMatthew Dillon  * modification, are permitted provided that the following conditions
371f2de5d4SMatthew Dillon  * are met:
381f2de5d4SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
391f2de5d4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
401f2de5d4SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
411f2de5d4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
421f2de5d4SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
431f2de5d4SMatthew Dillon  * 3. All advertising materials mentioning features or use of this software
441f2de5d4SMatthew Dillon  *    must display the following acknowledgement:
451f2de5d4SMatthew Dillon  * This product includes software developed by HD Associates
461f2de5d4SMatthew Dillon  * 4. Neither the name of the HD Associaates nor the names of its contributors
471f2de5d4SMatthew Dillon  *    may be used to endorse or promote products derived from this software
481f2de5d4SMatthew Dillon  *    without specific prior written permission.
491f2de5d4SMatthew Dillon  *
501f2de5d4SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND
511f2de5d4SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
521f2de5d4SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
531f2de5d4SMatthew Dillon  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
541f2de5d4SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
551f2de5d4SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
561f2de5d4SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
571f2de5d4SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
581f2de5d4SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
591f2de5d4SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
601f2de5d4SMatthew Dillon  * SUCH DAMAGE.
611f2de5d4SMatthew Dillon  */
621f2de5d4SMatthew Dillon 
631f2de5d4SMatthew Dillon 
641bd40720SMatthew Dillon #ifndef _SYS_CAMLIB_H_
651bd40720SMatthew Dillon #define _SYS_CAMLIB_H_
661f2de5d4SMatthew Dillon 
6703d6a592SMatthew Dillon #ifndef _SYS_CDEFS_H_
681f2de5d4SMatthew Dillon #include <sys/cdefs.h>
6903d6a592SMatthew Dillon #endif
7003d6a592SMatthew Dillon #ifndef _SYS_PARAM_H_
711f2de5d4SMatthew Dillon #include <sys/param.h>
7203d6a592SMatthew Dillon #endif
7303d6a592SMatthew Dillon #ifndef _BUS_CAM_CAM_H_
741f2de5d4SMatthew Dillon #include <bus/cam/cam.h>
7503d6a592SMatthew Dillon #endif
7603d6a592SMatthew Dillon #ifndef _BUS_CAM_CAM_CCB_H_
771f2de5d4SMatthew Dillon #include <bus/cam/cam_ccb.h>
7803d6a592SMatthew Dillon #endif
791f2de5d4SMatthew Dillon 
801f2de5d4SMatthew Dillon #define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
811f2de5d4SMatthew Dillon 
821f2de5d4SMatthew Dillon /*
831f2de5d4SMatthew Dillon  * Right now we hard code the transport layer device, but this will change
841f2de5d4SMatthew Dillon  * if we ever get more than one transport layer.
851f2de5d4SMatthew Dillon  */
861f2de5d4SMatthew Dillon #define XPT_DEVICE	"/dev/xpt0"
871f2de5d4SMatthew Dillon 
881f2de5d4SMatthew Dillon 
891f2de5d4SMatthew Dillon extern char cam_errbuf[];
901f2de5d4SMatthew Dillon 
911f2de5d4SMatthew Dillon struct cam_device {
9219edd1f3SPeter Avalos 	char 		device_path[MAXPATHLEN];  /*
931f2de5d4SMatthew Dillon 						   * Pathname of the device
941f2de5d4SMatthew Dillon 						   * given by the user. This
951f2de5d4SMatthew Dillon 						   * may be null if the
961f2de5d4SMatthew Dillon 						   * user states the device
971f2de5d4SMatthew Dillon 						   * name and unit number
981f2de5d4SMatthew Dillon 						   * separately.
991f2de5d4SMatthew Dillon 						   */
1001f2de5d4SMatthew Dillon 	char		given_dev_name[DEV_IDLEN+1];/*
1011f2de5d4SMatthew Dillon 						     * Device name given by
1021f2de5d4SMatthew Dillon 						     * the user.
1031f2de5d4SMatthew Dillon 						     */
1041f2de5d4SMatthew Dillon 	u_int32_t	given_unit_number;	    /*
1051f2de5d4SMatthew Dillon 						     * Unit number given by
1061f2de5d4SMatthew Dillon 						     * the user.
1071f2de5d4SMatthew Dillon 						     */
1081f2de5d4SMatthew Dillon 	char		device_name[DEV_IDLEN+1];/*
1091f2de5d4SMatthew Dillon 						  * Name of the device,
1101f2de5d4SMatthew Dillon 						  * e.g. 'pass'
1111f2de5d4SMatthew Dillon 						  */
1121f2de5d4SMatthew Dillon 	u_int32_t	dev_unit_num;	/* Unit number of the passthrough
1131f2de5d4SMatthew Dillon 					 * device associated with this
1141f2de5d4SMatthew Dillon 					 * particular device.
1151f2de5d4SMatthew Dillon 					 */
1161f2de5d4SMatthew Dillon 
117*7efec73eSSascha Wildner 	char		sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahci' */
1181f2de5d4SMatthew Dillon 	u_int32_t	sim_unit_number; /* Controller unit number */
1191f2de5d4SMatthew Dillon 	u_int32_t	bus_id;		 /* Controller bus number */
1201f2de5d4SMatthew Dillon 	lun_id_t	target_lun;	 /* Logical Unit Number */
1211f2de5d4SMatthew Dillon 	target_id_t	target_id;	 /* Target ID */
1221f2de5d4SMatthew Dillon 	path_id_t	path_id;	 /* System SCSI bus number */
1231f2de5d4SMatthew Dillon 	u_int16_t	pd_type;	 /* type of peripheral device */
1241f2de5d4SMatthew Dillon 	struct scsi_inquiry_data inq_data;  /* SCSI Inquiry data */
1251f2de5d4SMatthew Dillon 	u_int8_t	serial_num[252]; /* device serial number */
1261f2de5d4SMatthew Dillon 	u_int8_t	serial_num_len;  /* length of the serial number */
1271f2de5d4SMatthew Dillon 	u_int8_t	sync_period;	 /* Negotiated sync period */
1281f2de5d4SMatthew Dillon 	u_int8_t	sync_offset;	 /* Negotiated sync offset */
1291f2de5d4SMatthew Dillon 	u_int8_t	bus_width;	 /* Negotiated bus width */
1301f2de5d4SMatthew Dillon 	int		fd;		 /* file descriptor for device */
1311f2de5d4SMatthew Dillon };
1321f2de5d4SMatthew Dillon 
1331f2de5d4SMatthew Dillon __BEGIN_DECLS
1341f2de5d4SMatthew Dillon /* Basic utility commands */
1351f2de5d4SMatthew Dillon struct cam_device *	cam_open_device(const char *path, int flags);
1361f2de5d4SMatthew Dillon void			cam_close_device(struct cam_device *dev);
1371f2de5d4SMatthew Dillon void			cam_close_spec_device(struct cam_device *dev);
1381f2de5d4SMatthew Dillon struct cam_device *	cam_open_spec_device(const char *dev_name,
1391f2de5d4SMatthew Dillon 					     int unit, int flags,
1401f2de5d4SMatthew Dillon 					     struct cam_device *device);
1411f2de5d4SMatthew Dillon struct cam_device *	cam_open_btl(path_id_t path_id, target_id_t target_id,
1421f2de5d4SMatthew Dillon 				     lun_id_t target_lun, int flags,
1431f2de5d4SMatthew Dillon 				     struct cam_device *device);
1441f2de5d4SMatthew Dillon struct cam_device *	cam_open_pass(const char *path, int flags,
1451f2de5d4SMatthew Dillon 				      struct cam_device *device);
1461f2de5d4SMatthew Dillon union ccb *		cam_getccb(struct cam_device *dev);
1471f2de5d4SMatthew Dillon void			cam_freeccb(union ccb *ccb);
1481f2de5d4SMatthew Dillon int			cam_send_ccb(struct cam_device *device, union ccb *ccb);
1491f2de5d4SMatthew Dillon char *			cam_path_string(struct cam_device *dev, char *str,
1501f2de5d4SMatthew Dillon 					int len);
1511f2de5d4SMatthew Dillon struct cam_device *	cam_device_dup(struct cam_device *device);
1521f2de5d4SMatthew Dillon void			cam_device_copy(struct cam_device *src,
1531f2de5d4SMatthew Dillon 					struct cam_device *dst);
1541f2de5d4SMatthew Dillon int			cam_get_device(const char *path, char *dev_name,
1551f2de5d4SMatthew Dillon 				       int devnamelen, int *unit);
1561f2de5d4SMatthew Dillon 
1571f2de5d4SMatthew Dillon /*
1581f2de5d4SMatthew Dillon  * Buffer encoding/decoding routines, from the old SCSI library.
1591f2de5d4SMatthew Dillon  */
1605adc1304SPeter Avalos int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
1615adc1304SPeter Avalos 		__printflike(2, 3);
1625adc1304SPeter Avalos int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
1631f2de5d4SMatthew Dillon 		      void (*arg_put)(void *, int, void *, int, char *),
1641f2de5d4SMatthew Dillon 		      void *puthook);
1655adc1304SPeter Avalos int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
1665adc1304SPeter Avalos 		__printflike(3, 4);
1675adc1304SPeter Avalos int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
1681f2de5d4SMatthew Dillon 		      void (*arg_put)(void *, int, void *, int, char *),
1691f2de5d4SMatthew Dillon 		      void *puthook);
1701f2de5d4SMatthew Dillon int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
1711f2de5d4SMatthew Dillon 	       u_int32_t dxfer_len, u_int32_t flags, int retry_count,
1725adc1304SPeter Avalos 	       int timeout, const char *cmd_spec, ...);
1731f2de5d4SMatthew Dillon int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
1741f2de5d4SMatthew Dillon 		     u_int32_t dxfer_len, u_int32_t flags, int retry_count,
1755adc1304SPeter Avalos 		     int timeout, const char *cmd_spec,
1761f2de5d4SMatthew Dillon 		     int (*arg_get)(void *hook, char *field_name),
1771f2de5d4SMatthew Dillon 		     void *gethook);
1785adc1304SPeter Avalos int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
1795adc1304SPeter Avalos 		__printflike(2, 3);
1805adc1304SPeter Avalos int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
1811f2de5d4SMatthew Dillon 		      int (*arg_get)(void *hook, char *field_name),
1821f2de5d4SMatthew Dillon 		      void *gethook);
1835adc1304SPeter Avalos int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
1841f2de5d4SMatthew Dillon 		      int (*arg_get)(void *hook, char *field_name),
1851f2de5d4SMatthew Dillon 		      void *gethook);
1861f2de5d4SMatthew Dillon __END_DECLS
1871f2de5d4SMatthew Dillon 
1881bd40720SMatthew Dillon #endif /* _SYS_CAMLIB_H_ */
189