#ifndef _CAM_CAM_H
#define _CAM_CAM_H 1
#ifdef _KERNEL
#include "opt_cam.h"
#include <sys/queue.h>
#include <sys/sdt.h>
#endif
#ifndef _KERNEL
#include <stdbool.h>
#include <stdio.h>
#endif
typedef u_int path_id_t;
typedef u_int target_id_t;
typedef uint64_t lun_id_t;
#define CAM_XPT_PATH_ID ((path_id_t)~0)
#define CAM_BUS_WILDCARD ((path_id_t)~0)
#define CAM_TARGET_WILDCARD ((target_id_t)~0)
#define CAM_LUN_WILDCARD (~(u_int)0)
#define CAM_EXTLUN_BYTE_SWIZZLE(lun) ( \
((((uint64_t)lun) & 0xffff000000000000L) >> 48) | \
((((uint64_t)lun) & 0x0000ffff00000000L) >> 16) | \
((((uint64_t)lun) & 0x00000000ffff0000L) << 16) | \
((((uint64_t)lun) & 0x000000000000ffffL) << 48))
#define CAM_MAX_CDBLEN 16
struct cam_periph;
typedef enum {
CAM_RL_HOST,
CAM_RL_BUS,
CAM_RL_XPT,
CAM_RL_DEV,
CAM_RL_NORMAL,
CAM_RL_VALUES
} cam_rl;
typedef struct {
uint32_t priority;
#define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80)
#define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80)
#define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80)
#define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80)
#define CAM_PRIORITY_OOB (CAM_RL_DEV << 8)
#define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80)
#define CAM_PRIORITY_NONE (uint32_t)-1
uint32_t generation;
int index;
#define CAM_UNQUEUED_INDEX -1
#define CAM_ACTIVE_INDEX -2
#define CAM_DONEQ_INDEX -3
#define CAM_ASYNC_INDEX -4
#define CAM_EXTRAQ_INDEX INT_MAX
} cam_pinfo;
#define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
typedef enum {
CAM_FLAG_NONE = 0x00,
CAM_EXPECT_INQ_CHANGE = 0x01,
CAM_RETRY_SELTO = 0x02
} cam_flags;
enum {
SF_RETRY_UA = 0x01,
SF_NO_PRINT = 0x02,
SF_QUIET_IR = 0x04,
SF_PRINT_ALWAYS = 0x08,
SF_NO_RECOVERY = 0x10,
SF_NO_RETRY = 0x20,
SF_RETRY_BUSY = 0x40
};
typedef enum {
CAM_REQ_INPROG = 0x00,
CAM_REQ_CMP = 0x01,
CAM_REQ_ABORTED = 0x02,
CAM_UA_ABORT = 0x03,
CAM_REQ_CMP_ERR = 0x04,
CAM_BUSY = 0x05,
CAM_REQ_INVALID = 0x06,
CAM_PATH_INVALID = 0x07,
CAM_DEV_NOT_THERE = 0x08,
CAM_UA_TERMIO = 0x09,
CAM_SEL_TIMEOUT = 0x0a,
CAM_CMD_TIMEOUT = 0x0b,
CAM_SCSI_STATUS_ERROR = 0x0c,
CAM_MSG_REJECT_REC = 0x0d,
CAM_SCSI_BUS_RESET = 0x0e,
CAM_UNCOR_PARITY = 0x0f,
CAM_AUTOSENSE_FAIL = 0x10,
CAM_NO_HBA = 0x11,
CAM_DATA_RUN_ERR = 0x12,
CAM_UNEXP_BUSFREE = 0x13,
CAM_SEQUENCE_FAIL = 0x14,
CAM_CCB_LEN_ERR = 0x15,
CAM_PROVIDE_FAIL = 0x16,
CAM_BDR_SENT = 0x17,
CAM_REQ_TERMIO = 0x18,
CAM_UNREC_HBA_ERROR = 0x19,
CAM_REQ_TOO_BIG = 0x1a,
CAM_REQUEUE_REQ = 0x1b,
CAM_ATA_STATUS_ERROR = 0x1c,
CAM_SCSI_IT_NEXUS_LOST = 0x1d,
CAM_SMP_STATUS_ERROR = 0x1e,
CAM_REQ_SOFTTIMEOUT = 0x1f,
CAM_NVME_STATUS_ERROR = 0x20,
CAM_IDE = 0x33,
CAM_RESRC_UNAVAIL = 0x34,
CAM_UNACKED_EVENT = 0x35,
CAM_MESSAGE_RECV = 0x36,
CAM_INVALID_CDB = 0x37,
CAM_LUN_INVALID = 0x38,
CAM_TID_INVALID = 0x39,
CAM_FUNC_NOTAVAIL = 0x3a,
CAM_NO_NEXUS = 0x3b,
CAM_IID_INVALID = 0x3c,
CAM_CDB_RECVD = 0x3d,
CAM_LUN_ALRDY_ENA = 0x3e,
CAM_SCSI_BUSY = 0x3f,
CAM_DEV_QFRZN = 0x40,
CAM_AUTOSNS_VALID = 0x80,
CAM_RELEASE_SIMQ = 0x100,
CAM_SIM_QUEUED = 0x200,
CAM_QOS_VALID = 0x400,
CAM_STATUS_MASK = 0x3F,
CAM_SENT_SENSE = 0x40000000
} cam_status;
typedef enum {
CAM_ESF_NONE = 0x00,
CAM_ESF_COMMAND = 0x01,
CAM_ESF_CAM_STATUS = 0x02,
CAM_ESF_PROTO_STATUS = 0x04,
CAM_ESF_ALL = 0xff
} cam_error_string_flags;
typedef enum {
CAM_EPF_NONE = 0x00,
CAM_EPF_MINIMAL = 0x01,
CAM_EPF_NORMAL = 0x02,
CAM_EPF_ALL = 0x03,
CAM_EPF_LEVEL_MASK = 0x0f
} cam_error_proto_flags;
typedef enum {
CAM_ESF_PRINT_NONE = 0x00,
CAM_ESF_PRINT_STATUS = 0x10,
CAM_ESF_PRINT_SENSE = 0x20
} cam_error_scsi_flags;
typedef enum {
CAM_ESMF_PRINT_NONE = 0x00,
CAM_ESMF_PRINT_STATUS = 0x10,
CAM_ESMF_PRINT_FULL_CMD = 0x20,
} cam_error_smp_flags;
typedef enum {
CAM_EAF_PRINT_NONE = 0x00,
CAM_EAF_PRINT_STATUS = 0x10,
CAM_EAF_PRINT_RESULT = 0x20
} cam_error_ata_flags;
typedef enum {
CAM_ENF_PRINT_NONE = 0x00,
CAM_ENF_PRINT_STATUS = 0x10,
} cam_error_nvme_flags;
typedef enum {
CAM_STRVIS_FLAG_NONE = 0x00,
CAM_STRVIS_FLAG_NONASCII_MASK = 0x03,
CAM_STRVIS_FLAG_NONASCII_TRIM = 0x00,
CAM_STRVIS_FLAG_NONASCII_RAW = 0x01,
CAM_STRVIS_FLAG_NONASCII_SPC = 0x02,
CAM_STRVIS_FLAG_NONASCII_ESC = 0x03
} cam_strvis_flags;
struct cam_status_entry
{
cam_status status_code;
const char *status_text;
};
extern const struct cam_status_entry cam_status_table[];
extern const int num_cam_status_entries;
#ifdef _KERNEL
extern int cam_sort_io_queues;
#ifdef SDT_PROVIDER_DECLARE
SDT_PROVIDER_DECLARE(cam);
#endif
#define CAM_PROBE1(group, probe, arg0) \
SDT_PROBE1(cam, , group, probe, arg0)
#define CAM_PROBE2(group, probe, arg0, arg1) \
SDT_PROBE2(cam, , group, probe, arg0, arg1)
#define CAM_PROBE3(group, probe, arg0, arg1, arg2) \
SDT_PROBE3(cam, , group, probe, arg0, arg1, arg2)
#define CAM_PROBE4(group, probe, arg0, arg1, arg2, arg3) \
SDT_PROBE4(cam, , group, probe, arg0, arg1, arg2, arg3)
#endif
union ccb;
struct sbuf;
#ifdef SYSCTL_DECL
SYSCTL_DECL(_kern_cam);
#endif
__BEGIN_DECLS
typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
int entry_size, cam_quirkmatch_t *comp_func);
void cam_strvis(uint8_t *dst, const uint8_t *src, int srclen, int dstlen);
void cam_strvis_flag(uint8_t *dst, const uint8_t *src, int srclen,
int dstlen, uint32_t flags);
void cam_strvis_sbuf(struct sbuf *sb, const uint8_t *src, int srclen,
uint32_t flags);
int cam_strmatch(const uint8_t *str, const uint8_t *pattern, int str_len);
const struct cam_status_entry*
cam_fetch_status_entry(cam_status status);
#ifdef _KERNEL
char * cam_error_string(union ccb *ccb, char *str, int str_len,
cam_error_string_flags flags,
cam_error_proto_flags proto_flags);
void cam_error_print(union ccb *ccb, cam_error_string_flags flags,
cam_error_proto_flags proto_flags);
#else
struct cam_device;
char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
int str_len, cam_error_string_flags flags,
cam_error_proto_flags proto_flags);
void cam_error_print(struct cam_device *device, union ccb *ccb,
cam_error_string_flags flags,
cam_error_proto_flags proto_flags, FILE *ofile);
#endif
__END_DECLS
#ifdef _KERNEL
static __inline void cam_init_pinfo(cam_pinfo *pinfo)
{
pinfo->priority = CAM_PRIORITY_NONE;
pinfo->index = CAM_UNQUEUED_INDEX;
}
#endif
#endif