/*-1* SPDX-License-Identifier: (BSD-2-Clause AND BSD-4-Clause)2*3* Copyright (c) 1997, 1998 Kenneth D. Merry.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. The name of the author may not be used to endorse or promote products12* derived from this software without specific prior written permission.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/26/*27* Buffer encoding/decoding routines taken from the original FreeBSD SCSI28* library and slightly modified. The original header file had the following29* copyright:30*/31/* Copyright (c) 1994 HD Associates ([email protected])32* All rights reserved.33*34* Redistribution and use in source and binary forms, with or without35* modification, are permitted provided that the following conditions36* are met:37* 1. Redistributions of source code must retain the above copyright38* notice, this list of conditions and the following disclaimer.39* 2. Redistributions in binary form must reproduce the above copyright40* notice, this list of conditions and the following disclaimer in the41* documentation and/or other materials provided with the distribution.42* 3. All advertising materials mentioning features or use of this software43* must display the following acknowledgement:44* This product includes software developed by HD Associates45* 4. Neither the name of the HD Associaates nor the names of its contributors46* may be used to endorse or promote products derived from this software47* without specific prior written permission.48*49* THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES``AS IS'' AND50* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE51* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE52* ARE DISCLAIMED. IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE53* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL54* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS55* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)56* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT57* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY58* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF59* SUCH DAMAGE.60*/616263#ifndef _CAMLIB_H64#define _CAMLIB_H6566#include <sys/param.h>6768#include <cam/cam.h>69#include <cam/cam_ccb.h>7071#define CAM_ERRBUF_SIZE 2048 /* CAM library error string size */7273/*74* Right now we hard code the transport layer device, but this will change75* if we ever get more than one transport layer.76*/77#define XPT_DEVICE "/dev/xpt0"787980extern char cam_errbuf[];8182struct cam_device {83char device_path[MAXPATHLEN];/*84* Pathname of the device85* given by the user. This86* may be null if the87* user states the device88* name and unit number89* separately.90*/91char given_dev_name[DEV_IDLEN+1];/*92* Device name given by93* the user.94*/95uint32_t given_unit_number; /*96* Unit number given by97* the user.98*/99char device_name[DEV_IDLEN+1];/*100* Name of the device,101* e.g. 'pass'102*/103uint32_t dev_unit_num; /* Unit number of the passthrough104* device associated with this105* particular device.106*/107108char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */109uint32_t sim_unit_number; /* Controller unit number */110uint32_t bus_id; /* Controller bus number */111lun_id_t target_lun; /* Logical Unit Number */112target_id_t target_id; /* Target ID */113path_id_t path_id; /* System SCSI bus number */114uint16_t pd_type; /* type of peripheral device */115struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */116uint8_t serial_num[252]; /* device serial number */117uint8_t serial_num_len; /* length of the serial number */118uint8_t sync_period; /* Negotiated sync period */119uint8_t sync_offset; /* Negotiated sync offset */120uint8_t bus_width; /* Negotiated bus width */121int fd; /* file descriptor for device */122};123124__BEGIN_DECLS125/* Basic utility commands */126struct cam_device * cam_open_device(const char *path, int flags);127void cam_close_device(struct cam_device *dev);128void cam_close_spec_device(struct cam_device *dev);129struct cam_device * cam_open_spec_device(const char *dev_name,130int unit, int flags,131struct cam_device *device);132struct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id,133lun_id_t target_lun, int flags,134struct cam_device *device);135struct cam_device * cam_open_pass(const char *path, int flags,136struct cam_device *device);137union ccb * cam_getccb(struct cam_device *dev);138void cam_freeccb(union ccb *ccb);139int cam_send_ccb(struct cam_device *device, union ccb *ccb);140char * cam_path_string(struct cam_device *dev, char *str,141int len);142struct cam_device * cam_device_dup(struct cam_device *device);143void cam_device_copy(struct cam_device *src,144struct cam_device *dst);145int cam_get_device(const char *path, char *dev_name,146int devnamelen, int *unit);147148/*149* Buffer encoding/decoding routines, from the old SCSI library.150*/151int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)152__printflike(2, 3);153int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,154void (*arg_put)(void *, int, void *, int, char *),155void *puthook);156int buff_decode(uint8_t *buff, size_t len, const char *fmt, ...)157__printflike(3, 4);158int buff_decode_visit(uint8_t *buff, size_t len, const char *fmt,159void (*arg_put)(void *, int, void *, int, char *),160void *puthook);161int csio_build(struct ccb_scsiio *csio, uint8_t *data_ptr,162uint32_t dxfer_len, uint32_t flags, int retry_count,163int timeout, const char *cmd_spec, ...);164int csio_build_visit(struct ccb_scsiio *csio, uint8_t *data_ptr,165uint32_t dxfer_len, uint32_t flags, int retry_count,166int timeout, const char *cmd_spec,167int (*arg_get)(void *hook, char *field_name),168void *gethook);169int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)170__printflike(2, 3);171int buff_encode_visit(uint8_t *buff, size_t len, const char *fmt,172int (*arg_get)(void *hook, char *field_name),173void *gethook);174int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,175int (*arg_get)(void *hook, char *field_name),176void *gethook);177__END_DECLS178179#endif /* _CAMLIB_H */180181182