2 * Data structures and definitions for the CAM system.
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/cdefs.h>
40 typedef u_int path_id_t;
41 typedef u_int target_id_t;
42 typedef u_int lun_id_t;
44 #define CAM_XPT_PATH_ID ((path_id_t)~0)
45 #define CAM_BUS_WILDCARD ((path_id_t)~0)
46 #define CAM_TARGET_WILDCARD ((target_id_t)~0)
47 #define CAM_LUN_WILDCARD ((lun_id_t)~0)
50 * Maximum length for a CAM CDB.
52 #define CAM_MAX_CDBLEN 16
55 * Definition of a CAM peripheral driver entry. Peripheral drivers instantiate
56 * one of these for each device they wish to communicate with and pass it into
57 * the xpt layer when they wish to schedule work on that device via the
63 * Priority information for a CAM structure.
74 * The generation number is incremented everytime a new entry is entered into
75 * the queue giving round robin per priority level scheduling.
79 #define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80)
80 #define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80)
81 #define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80)
82 #define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80)
83 #define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80)
84 #define CAM_PRIORITY_NONE (u_int32_t)-1
85 #define CAM_PRIORITY_TO_RL(x) ((x) >> 8)
88 #define CAM_UNQUEUED_INDEX -1
89 #define CAM_ACTIVE_INDEX -2
90 #define CAM_DONEQ_INDEX -3
94 * Macro to compare two generation numbers. It is used like this:
96 * if (GENERATIONCMP(a, >=, b))
99 * GERERATIONCMP uses modular arithmetic to guard against wraps
100 * wraps in the generation number.
102 #define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
104 /* CAM flags XXX Move to cam_periph.h ??? */
106 CAM_FLAG_NONE = 0x00,
107 CAM_EXPECT_INQ_CHANGE = 0x01,
108 CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */
112 SF_RETRY_UA = 0x01, /* Retry UNIT ATTENTION conditions. */
113 SF_NO_PRINT = 0x02, /* Never print error status. */
114 SF_QUIET_IR = 0x04, /* Be quiet about Illegal Request reponses */
115 SF_PRINT_ALWAYS = 0x08, /* Always print error status. */
116 SF_NO_RECOVERY = 0x10, /* Don't do active error recovery. */
117 SF_NO_RETRY = 0x20 /* Don't do any retries. */
120 /* CAM Status field values */
122 CAM_REQ_INPROG, /* CCB request is in progress */
123 CAM_REQ_CMP, /* CCB request completed without error */
124 CAM_REQ_ABORTED, /* CCB request aborted by the host */
125 CAM_UA_ABORT, /* Unable to abort CCB request */
126 CAM_REQ_CMP_ERR, /* CCB request completed with an error */
127 CAM_BUSY, /* CAM subsystem is busy */
128 CAM_REQ_INVALID, /* CCB request was invalid */
129 CAM_PATH_INVALID, /* Supplied Path ID is invalid */
130 CAM_DEV_NOT_THERE, /* SCSI Device Not Installed/there */
131 CAM_UA_TERMIO, /* Unable to terminate I/O CCB request */
132 CAM_SEL_TIMEOUT, /* Target Selection Timeout */
133 CAM_CMD_TIMEOUT, /* Command timeout */
134 CAM_SCSI_STATUS_ERROR, /* SCSI error, look at error code in CCB */
135 CAM_MSG_REJECT_REC, /* Message Reject Received */
136 CAM_SCSI_BUS_RESET, /* SCSI Bus Reset Sent/Received */
137 CAM_UNCOR_PARITY, /* Uncorrectable parity error occurred */
138 CAM_AUTOSENSE_FAIL = 0x10,/* Autosense: request sense cmd fail */
139 CAM_NO_HBA, /* No HBA Detected error */
140 CAM_DATA_RUN_ERR, /* Data Overrun error */
141 CAM_UNEXP_BUSFREE, /* Unexpected Bus Free */
142 CAM_SEQUENCE_FAIL, /* Target Bus Phase Sequence Failure */
143 CAM_CCB_LEN_ERR, /* CCB length supplied is inadequate */
144 CAM_PROVIDE_FAIL, /* Unable to provide requested capability */
145 CAM_BDR_SENT, /* A SCSI BDR msg was sent to target */
146 CAM_REQ_TERMIO, /* CCB request terminated by the host */
147 CAM_UNREC_HBA_ERROR, /* Unrecoverable Host Bus Adapter Error */
148 CAM_REQ_TOO_BIG, /* The request was too large for this host */
150 * This request should be requeued to preserve
151 * transaction ordering. This typically occurs
152 * when the SIM recognizes an error that should
153 * freeze the queue and must place additional
154 * requests for the target at the sim level
155 * back into the XPT queue.
157 CAM_ATA_STATUS_ERROR, /* ATA error, look at error code in CCB */
158 CAM_SCSI_IT_NEXUS_LOST, /* Initiator/Target Nexus lost. */
159 CAM_SMP_STATUS_ERROR, /* SMP error, look at error code in CCB */
160 CAM_IDE = 0x33, /* Initiator Detected Error */
161 CAM_RESRC_UNAVAIL, /* Resource Unavailable */
162 CAM_UNACKED_EVENT, /* Unacknowledged Event by Host */
163 CAM_MESSAGE_RECV, /* Message Received in Host Target Mode */
164 CAM_INVALID_CDB, /* Invalid CDB received in Host Target Mode */
165 CAM_LUN_INVALID, /* Lun supplied is invalid */
166 CAM_TID_INVALID, /* Target ID supplied is invalid */
167 CAM_FUNC_NOTAVAIL, /* The requested function is not available */
168 CAM_NO_NEXUS, /* Nexus is not established */
169 CAM_IID_INVALID, /* The initiator ID is invalid */
170 CAM_CDB_RECVD, /* The SCSI CDB has been received */
171 CAM_LUN_ALRDY_ENA, /* The LUN is already enabled for target mode */
172 CAM_SCSI_BUSY, /* SCSI Bus Busy */
174 CAM_DEV_QFRZN = 0x40, /* The DEV queue is frozen w/this err */
176 /* Autosense data valid for target */
177 CAM_AUTOSNS_VALID = 0x80,
178 CAM_RELEASE_SIMQ = 0x100,/* SIM ready to take more commands */
179 CAM_SIM_QUEUED = 0x200,/* SIM has this command in it's queue */
181 CAM_STATUS_MASK = 0x3F, /* Mask bits for just the status # */
183 /* Target Specific Adjunct Status */
184 CAM_SENT_SENSE = 0x40000000 /* sent sense with status */
189 CAM_ESF_COMMAND = 0x01,
190 CAM_ESF_CAM_STATUS = 0x02,
191 CAM_ESF_PROTO_STATUS = 0x04,
193 } cam_error_string_flags;
197 CAM_EPF_MINIMAL = 0x01,
198 CAM_EPF_NORMAL = 0x02,
200 CAM_EPF_LEVEL_MASK = 0x0f
201 /* All bits above bit 3 are protocol-specific */
202 } cam_error_proto_flags;
205 CAM_ESF_PRINT_NONE = 0x00,
206 CAM_ESF_PRINT_STATUS = 0x10,
207 CAM_ESF_PRINT_SENSE = 0x20
208 } cam_error_scsi_flags;
211 CAM_ESMF_PRINT_NONE = 0x00,
212 CAM_ESMF_PRINT_STATUS = 0x10,
213 CAM_ESMF_PRINT_FULL_CMD = 0x20,
214 } cam_error_smp_flags;
217 CAM_EAF_PRINT_NONE = 0x00,
218 CAM_EAF_PRINT_STATUS = 0x10,
219 CAM_EAF_PRINT_RESULT = 0x20
220 } cam_error_ata_flags;
222 struct cam_status_entry
224 cam_status status_code;
225 const char *status_text;
228 extern const struct cam_status_entry cam_status_table[];
229 extern const int num_cam_status_entries;
232 #ifdef SYSCTL_DECL /* from sysctl.h */
233 SYSCTL_DECL(_kern_cam);
237 typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
239 caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
240 int entry_size, cam_quirkmatch_t *comp_func);
242 void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
244 int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
245 const struct cam_status_entry*
246 cam_fetch_status_entry(cam_status status);
248 char * cam_error_string(union ccb *ccb, char *str, int str_len,
249 cam_error_string_flags flags,
250 cam_error_proto_flags proto_flags);
251 void cam_error_print(union ccb *ccb, cam_error_string_flags flags,
252 cam_error_proto_flags proto_flags);
256 char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
257 int str_len, cam_error_string_flags flags,
258 cam_error_proto_flags proto_flags);
259 void cam_error_print(struct cam_device *device, union ccb *ccb,
260 cam_error_string_flags flags,
261 cam_error_proto_flags proto_flags, FILE *ofile);
266 static __inline void cam_init_pinfo(cam_pinfo *pinfo);
268 static __inline void cam_init_pinfo(cam_pinfo *pinfo)
270 pinfo->priority = CAM_PRIORITY_NONE;
271 pinfo->index = CAM_UNQUEUED_INDEX;
275 #endif /* _CAM_CAM_H */