1139743Simp/*- 239212Sgibbs * Data structures and definitions for the CAM system. 339212Sgibbs * 439212Sgibbs * Copyright (c) 1997 Justin T. Gibbs. 539212Sgibbs * All rights reserved. 639212Sgibbs * 739212Sgibbs * Redistribution and use in source and binary forms, with or without 839212Sgibbs * modification, are permitted provided that the following conditions 939212Sgibbs * are met: 1039212Sgibbs * 1. Redistributions of source code must retain the above copyright 1139212Sgibbs * notice, this list of conditions, and the following disclaimer, 1239212Sgibbs * without modification, immediately at the beginning of the file. 1339212Sgibbs * 2. The name of the author may not be used to endorse or promote products 1439212Sgibbs * derived from this software without specific prior written permission. 1539212Sgibbs * 1639212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1739212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1839212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1939212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 2039212Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2139212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2239212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2339212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2439212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2539212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2639212Sgibbs * SUCH DAMAGE. 2739212Sgibbs * 2850477Speter * $FreeBSD$ 2939212Sgibbs */ 3039212Sgibbs 3139212Sgibbs#ifndef _CAM_CAM_H 3239212Sgibbs#define _CAM_CAM_H 1 3339212Sgibbs 3455206Speter#ifdef _KERNEL 3539212Sgibbs#include <opt_cam.h> 3655206Speter#endif 3739212Sgibbs 3839212Sgibbs#include <sys/cdefs.h> 3939212Sgibbs 4039212Sgibbstypedef u_int path_id_t; 4139212Sgibbstypedef u_int target_id_t; 4239212Sgibbstypedef u_int lun_id_t; 4339212Sgibbs 4439212Sgibbs#define CAM_XPT_PATH_ID ((path_id_t)~0) 4539212Sgibbs#define CAM_BUS_WILDCARD ((path_id_t)~0) 4639212Sgibbs#define CAM_TARGET_WILDCARD ((target_id_t)~0) 4739212Sgibbs#define CAM_LUN_WILDCARD ((lun_id_t)~0) 4839212Sgibbs 4939212Sgibbs/* 5039212Sgibbs * Maximum length for a CAM CDB. 5139212Sgibbs */ 5239212Sgibbs#define CAM_MAX_CDBLEN 16 5339212Sgibbs 5439212Sgibbs/* 5539212Sgibbs * Definition of a CAM peripheral driver entry. Peripheral drivers instantiate 5639212Sgibbs * one of these for each device they wish to communicate with and pass it into 5739212Sgibbs * the xpt layer when they wish to schedule work on that device via the 5858111Sn_hibma * xpt_schedule API. 5939212Sgibbs */ 6039212Sgibbsstruct cam_periph; 6139212Sgibbs 6239212Sgibbs/* 63203108Smav * Priority information for a CAM structure. 6439212Sgibbs */ 65203108Smavtypedef enum { 66203108Smav CAM_RL_HOST, 67203108Smav CAM_RL_BUS, 68203108Smav CAM_RL_XPT, 69203108Smav CAM_RL_DEV, 70203108Smav CAM_RL_NORMAL, 71203108Smav CAM_RL_VALUES 72203108Smav} cam_rl; 73203108Smav/* 74203108Smav * The generation number is incremented everytime a new entry is entered into 75203108Smav * the queue giving round robin per priority level scheduling. 76203108Smav */ 7739212Sgibbstypedef struct { 7839212Sgibbs u_int32_t priority; 79203108Smav#define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80) 80203108Smav#define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80) 81203108Smav#define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80) 82203108Smav#define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80) 83256216Smav#define CAM_PRIORITY_OOB (CAM_RL_DEV << 8) 84203108Smav#define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80) 8539212Sgibbs#define CAM_PRIORITY_NONE (u_int32_t)-1 8639212Sgibbs u_int32_t generation; 8739212Sgibbs int index; 8839212Sgibbs#define CAM_UNQUEUED_INDEX -1 8939212Sgibbs#define CAM_ACTIVE_INDEX -2 9039212Sgibbs#define CAM_DONEQ_INDEX -3 91256220Smav#define CAM_EXTRAQ_INDEX INT_MAX 9239212Sgibbs} cam_pinfo; 9339212Sgibbs 9445441Sgibbs/* 9545441Sgibbs * Macro to compare two generation numbers. It is used like this: 9645441Sgibbs * 9745441Sgibbs * if (GENERATIONCMP(a, >=, b)) 9845441Sgibbs * ...; 9945441Sgibbs * 10045441Sgibbs * GERERATIONCMP uses modular arithmetic to guard against wraps 10145441Sgibbs * wraps in the generation number. 10245441Sgibbs */ 10345441Sgibbs#define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0) 10445441Sgibbs 10574840Sken/* CAM flags XXX Move to cam_periph.h ??? */ 10639212Sgibbstypedef enum { 10739212Sgibbs CAM_FLAG_NONE = 0x00, 10874840Sken CAM_EXPECT_INQ_CHANGE = 0x01, 10974840Sken CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */ 11039212Sgibbs} cam_flags; 11139212Sgibbs 112237327Smavenum { 113237327Smav SF_RETRY_UA = 0x01, /* Retry UNIT ATTENTION conditions. */ 114237327Smav SF_NO_PRINT = 0x02, /* Never print error status. */ 115237327Smav SF_QUIET_IR = 0x04, /* Be quiet about Illegal Request reponses */ 116237327Smav SF_PRINT_ALWAYS = 0x08, /* Always print error status. */ 117237327Smav SF_NO_RECOVERY = 0x10, /* Don't do active error recovery. */ 118237327Smav SF_NO_RETRY = 0x20 /* Don't do any retries. */ 119237327Smav}; 120237327Smav 12139212Sgibbs/* CAM Status field values */ 12239212Sgibbstypedef enum { 12339212Sgibbs CAM_REQ_INPROG, /* CCB request is in progress */ 12439212Sgibbs CAM_REQ_CMP, /* CCB request completed without error */ 12539212Sgibbs CAM_REQ_ABORTED, /* CCB request aborted by the host */ 12639212Sgibbs CAM_UA_ABORT, /* Unable to abort CCB request */ 12739212Sgibbs CAM_REQ_CMP_ERR, /* CCB request completed with an error */ 12875030Smurray CAM_BUSY, /* CAM subsystem is busy */ 12939212Sgibbs CAM_REQ_INVALID, /* CCB request was invalid */ 13039212Sgibbs CAM_PATH_INVALID, /* Supplied Path ID is invalid */ 13139212Sgibbs CAM_DEV_NOT_THERE, /* SCSI Device Not Installed/there */ 13239212Sgibbs CAM_UA_TERMIO, /* Unable to terminate I/O CCB request */ 13339212Sgibbs CAM_SEL_TIMEOUT, /* Target Selection Timeout */ 13439212Sgibbs CAM_CMD_TIMEOUT, /* Command timeout */ 13539212Sgibbs CAM_SCSI_STATUS_ERROR, /* SCSI error, look at error code in CCB */ 13658111Sn_hibma CAM_MSG_REJECT_REC, /* Message Reject Received */ 13739212Sgibbs CAM_SCSI_BUS_RESET, /* SCSI Bus Reset Sent/Received */ 13839212Sgibbs CAM_UNCOR_PARITY, /* Uncorrectable parity error occurred */ 13939212Sgibbs CAM_AUTOSENSE_FAIL = 0x10,/* Autosense: request sense cmd fail */ 14039212Sgibbs CAM_NO_HBA, /* No HBA Detected error */ 14139212Sgibbs CAM_DATA_RUN_ERR, /* Data Overrun error */ 14239212Sgibbs CAM_UNEXP_BUSFREE, /* Unexpected Bus Free */ 14339212Sgibbs CAM_SEQUENCE_FAIL, /* Target Bus Phase Sequence Failure */ 14439212Sgibbs CAM_CCB_LEN_ERR, /* CCB length supplied is inadequate */ 14539212Sgibbs CAM_PROVIDE_FAIL, /* Unable to provide requested capability */ 14639212Sgibbs CAM_BDR_SENT, /* A SCSI BDR msg was sent to target */ 14739212Sgibbs CAM_REQ_TERMIO, /* CCB request terminated by the host */ 14839212Sgibbs CAM_UNREC_HBA_ERROR, /* Unrecoverable Host Bus Adapter Error */ 14939212Sgibbs CAM_REQ_TOO_BIG, /* The request was too large for this host */ 15039212Sgibbs CAM_REQUEUE_REQ, /* 15139212Sgibbs * This request should be requeued to preserve 15239212Sgibbs * transaction ordering. This typically occurs 15339212Sgibbs * when the SIM recognizes an error that should 15439212Sgibbs * freeze the queue and must place additional 15539212Sgibbs * requests for the target at the sim level 15639212Sgibbs * back into the XPT queue. 15739212Sgibbs */ 158195534Sscottl CAM_ATA_STATUS_ERROR, /* ATA error, look at error code in CCB */ 159183145Ssbruno CAM_SCSI_IT_NEXUS_LOST, /* Initiator/Target Nexus lost. */ 160216088Sken CAM_SMP_STATUS_ERROR, /* SMP error, look at error code in CCB */ 16139212Sgibbs CAM_IDE = 0x33, /* Initiator Detected Error */ 16239212Sgibbs CAM_RESRC_UNAVAIL, /* Resource Unavailable */ 16339212Sgibbs CAM_UNACKED_EVENT, /* Unacknowledged Event by Host */ 16439212Sgibbs CAM_MESSAGE_RECV, /* Message Received in Host Target Mode */ 16539212Sgibbs CAM_INVALID_CDB, /* Invalid CDB received in Host Target Mode */ 16639212Sgibbs CAM_LUN_INVALID, /* Lun supplied is invalid */ 16739212Sgibbs CAM_TID_INVALID, /* Target ID supplied is invalid */ 16839212Sgibbs CAM_FUNC_NOTAVAIL, /* The requested function is not available */ 16939212Sgibbs CAM_NO_NEXUS, /* Nexus is not established */ 17039212Sgibbs CAM_IID_INVALID, /* The initiator ID is invalid */ 17139212Sgibbs CAM_CDB_RECVD, /* The SCSI CDB has been received */ 17274840Sken CAM_LUN_ALRDY_ENA, /* The LUN is already enabled for target mode */ 17339212Sgibbs CAM_SCSI_BUSY, /* SCSI Bus Busy */ 17439212Sgibbs 17539212Sgibbs CAM_DEV_QFRZN = 0x40, /* The DEV queue is frozen w/this err */ 17639212Sgibbs 17739212Sgibbs /* Autosense data valid for target */ 17839212Sgibbs CAM_AUTOSNS_VALID = 0x80, 17939212Sgibbs CAM_RELEASE_SIMQ = 0x100,/* SIM ready to take more commands */ 18039212Sgibbs CAM_SIM_QUEUED = 0x200,/* SIM has this command in it's queue */ 18139212Sgibbs 18256143Smjacob CAM_STATUS_MASK = 0x3F, /* Mask bits for just the status # */ 18356143Smjacob 18456143Smjacob /* Target Specific Adjunct Status */ 18556143Smjacob CAM_SENT_SENSE = 0x40000000 /* sent sense with status */ 18639212Sgibbs} cam_status; 18739212Sgibbs 18874840Skentypedef enum { 18974840Sken CAM_ESF_NONE = 0x00, 19074840Sken CAM_ESF_COMMAND = 0x01, 19174840Sken CAM_ESF_CAM_STATUS = 0x02, 19274840Sken CAM_ESF_PROTO_STATUS = 0x04, 19374840Sken CAM_ESF_ALL = 0xff 19474840Sken} cam_error_string_flags; 19574840Sken 19674840Skentypedef enum { 19774840Sken CAM_EPF_NONE = 0x00, 19874840Sken CAM_EPF_MINIMAL = 0x01, 19974840Sken CAM_EPF_NORMAL = 0x02, 20074840Sken CAM_EPF_ALL = 0x03, 20174840Sken CAM_EPF_LEVEL_MASK = 0x0f 20274840Sken /* All bits above bit 3 are protocol-specific */ 20374840Sken} cam_error_proto_flags; 20474840Sken 20574840Skentypedef enum { 20674840Sken CAM_ESF_PRINT_NONE = 0x00, 20774840Sken CAM_ESF_PRINT_STATUS = 0x10, 20874840Sken CAM_ESF_PRINT_SENSE = 0x20 20974840Sken} cam_error_scsi_flags; 21074840Sken 211198849Smavtypedef enum { 212216088Sken CAM_ESMF_PRINT_NONE = 0x00, 213216088Sken CAM_ESMF_PRINT_STATUS = 0x10, 214216088Sken CAM_ESMF_PRINT_FULL_CMD = 0x20, 215216088Sken} cam_error_smp_flags; 216216088Sken 217216088Skentypedef enum { 218198849Smav CAM_EAF_PRINT_NONE = 0x00, 219198849Smav CAM_EAF_PRINT_STATUS = 0x10, 220198849Smav CAM_EAF_PRINT_RESULT = 0x20 221198849Smav} cam_error_ata_flags; 222198849Smav 22374840Skenstruct cam_status_entry 22474840Sken{ 22574840Sken cam_status status_code; 22674840Sken const char *status_text; 22774840Sken}; 22874840Sken 22974840Skenextern const struct cam_status_entry cam_status_table[]; 23074840Skenextern const int num_cam_status_entries; 231251301Ssmh#ifdef _KERNEL 232251301Ssmhextern int cam_sort_io_queues; 233251301Ssmh#endif 23474840Skenunion ccb; 23574840Sken 23689114Smsmith#ifdef SYSCTL_DECL /* from sysctl.h */ 23789114SmsmithSYSCTL_DECL(_kern_cam); 23889114Smsmith#endif 23989114Smsmith 24039212Sgibbs__BEGIN_DECLS 24139212Sgibbstypedef int (cam_quirkmatch_t)(caddr_t, caddr_t); 24239212Sgibbs 24339212Sgibbscaddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, 24439212Sgibbs int entry_size, cam_quirkmatch_t *comp_func); 24539212Sgibbs 24639212Sgibbsvoid cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen); 24739212Sgibbs 24839212Sgibbsint cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len); 24974840Skenconst struct cam_status_entry* 25074840Sken cam_fetch_status_entry(cam_status status); 25174840Sken#ifdef _KERNEL 25274840Skenchar * cam_error_string(union ccb *ccb, char *str, int str_len, 25374840Sken cam_error_string_flags flags, 25474840Sken cam_error_proto_flags proto_flags); 25574840Skenvoid cam_error_print(union ccb *ccb, cam_error_string_flags flags, 25674840Sken cam_error_proto_flags proto_flags); 25774840Sken#else /* _KERNEL */ 25874840Skenstruct cam_device; 25974840Sken 26074840Skenchar * cam_error_string(struct cam_device *device, union ccb *ccb, char *str, 26174840Sken int str_len, cam_error_string_flags flags, 26274840Sken cam_error_proto_flags proto_flags); 26374840Skenvoid cam_error_print(struct cam_device *device, union ccb *ccb, 26474840Sken cam_error_string_flags flags, 26574840Sken cam_error_proto_flags proto_flags, FILE *ofile); 26674840Sken#endif /* _KERNEL */ 26739212Sgibbs__END_DECLS 26839212Sgibbs 26955206Speter#ifdef _KERNEL 27039212Sgibbsstatic __inline void cam_init_pinfo(cam_pinfo *pinfo); 27139212Sgibbs 27239212Sgibbsstatic __inline void cam_init_pinfo(cam_pinfo *pinfo) 27339212Sgibbs{ 27439212Sgibbs pinfo->priority = CAM_PRIORITY_NONE; 27539212Sgibbs pinfo->index = CAM_UNQUEUED_INDEX; 27639212Sgibbs} 27755206Speter#endif 27839212Sgibbs 27939212Sgibbs#endif /* _CAM_CAM_H */ 280