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;
48 #define CAM_XPT_PATH_ID ((path_id_t)~0)
49 #define CAM_BUS_WILDCARD ((path_id_t)~0)
50 #define CAM_TARGET_WILDCARD ((target_id_t)~0)
51 #define CAM_LUN_WILDCARD ((lun_id_t)~0)
54 * Maximum length for a CAM CDB.
56 #define CAM_MAX_CDBLEN 16
59 * Definition of a CAM peripheral driver entry. Peripheral drivers instantiate
60 * one of these for each device they wish to communicate with and pass it into
61 * the xpt layer when they wish to schedule work on that device via the
67 * Priority information for a CAM structure.
78 * The generation number is incremented everytime a new entry is entered into
79 * the queue giving round robin per priority level scheduling.
83 #define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80)
84 #define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80)
85 #define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80)
86 #define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80)
87 #define CAM_PRIORITY_OOB (CAM_RL_DEV << 8)
88 #define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80)
89 #define CAM_PRIORITY_NONE (u_int32_t)-1
92 #define CAM_UNQUEUED_INDEX -1
93 #define CAM_ACTIVE_INDEX -2
94 #define CAM_DONEQ_INDEX -3
95 #define CAM_EXTRAQ_INDEX INT_MAX
99 * Macro to compare two generation numbers. It is used like this:
101 * if (GENERATIONCMP(a, >=, b))
104 * GERERATIONCMP uses modular arithmetic to guard against wraps
105 * wraps in the generation number.
107 #define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
109 /* CAM flags XXX Move to cam_periph.h ??? */
111 CAM_FLAG_NONE = 0x00,
112 CAM_EXPECT_INQ_CHANGE = 0x01,
113 CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */
117 SF_RETRY_UA = 0x01, /* Retry UNIT ATTENTION conditions. */
118 SF_NO_PRINT = 0x02, /* Never print error status. */
119 SF_QUIET_IR = 0x04, /* Be quiet about Illegal Request reponses */
120 SF_PRINT_ALWAYS = 0x08, /* Always print error status. */
121 SF_NO_RECOVERY = 0x10, /* Don't do active error recovery. */
122 SF_NO_RETRY = 0x20 /* Don't do any retries. */
125 /* CAM Status field values */
127 /* CCB request is in progress */
128 CAM_REQ_INPROG = 0x00,
130 /* CCB request completed without error */
133 /* CCB request aborted by the host */
134 CAM_REQ_ABORTED = 0x02,
136 /* Unable to abort CCB request */
139 /* CCB request completed with an error */
140 CAM_REQ_CMP_ERR = 0x04,
142 /* CAM subsystem is busy */
145 /* CCB request was invalid */
146 CAM_REQ_INVALID = 0x06,
148 /* Supplied Path ID is invalid */
149 CAM_PATH_INVALID = 0x07,
151 /* SCSI Device Not Installed/there */
152 CAM_DEV_NOT_THERE = 0x08,
154 /* Unable to terminate I/O CCB request */
155 CAM_UA_TERMIO = 0x09,
157 /* Target Selection Timeout */
158 CAM_SEL_TIMEOUT = 0x0a,
160 /* Command timeout */
161 CAM_CMD_TIMEOUT = 0x0b,
163 /* SCSI error, look at error code in CCB */
164 CAM_SCSI_STATUS_ERROR = 0x0c,
166 /* Message Reject Received */
167 CAM_MSG_REJECT_REC = 0x0d,
169 /* SCSI Bus Reset Sent/Received */
170 CAM_SCSI_BUS_RESET = 0x0e,
172 /* Uncorrectable parity error occurred */
173 CAM_UNCOR_PARITY = 0x0f,
175 /* Autosense: request sense cmd fail */
176 CAM_AUTOSENSE_FAIL = 0x10,
178 /* No HBA Detected error */
181 /* Data Overrun error */
182 CAM_DATA_RUN_ERR = 0x12,
184 /* Unexpected Bus Free */
185 CAM_UNEXP_BUSFREE = 0x13,
187 /* Target Bus Phase Sequence Failure */
188 CAM_SEQUENCE_FAIL = 0x14,
190 /* CCB length supplied is inadequate */
191 CAM_CCB_LEN_ERR = 0x15,
193 /* Unable to provide requested capability*/
194 CAM_PROVIDE_FAIL = 0x16,
196 /* A SCSI BDR msg was sent to target */
199 /* CCB request terminated by the host */
200 CAM_REQ_TERMIO = 0x18,
202 /* Unrecoverable Host Bus Adapter Error */
203 CAM_UNREC_HBA_ERROR = 0x19,
205 /* Request was too large for this host */
206 CAM_REQ_TOO_BIG = 0x1a,
209 * This request should be requeued to preserve
210 * transaction ordering. This typically occurs
211 * when the SIM recognizes an error that should
212 * freeze the queue and must place additional
213 * requests for the target at the sim level
214 * back into the XPT queue.
216 CAM_REQUEUE_REQ = 0x1b,
218 /* ATA error, look at error code in CCB */
219 CAM_ATA_STATUS_ERROR = 0x1c,
221 /* Initiator/Target Nexus lost. */
222 CAM_SCSI_IT_NEXUS_LOST = 0x1d,
224 /* SMP error, look at error code in CCB */
225 CAM_SMP_STATUS_ERROR = 0x1e,
228 * Command completed without error but exceeded the soft
231 CAM_REQ_SOFTTIMEOUT = 0x1f,
234 * 0x20 - 0x32 are unassigned
237 /* Initiator Detected Error */
240 /* Resource Unavailable */
241 CAM_RESRC_UNAVAIL = 0x34,
243 /* Unacknowledged Event by Host */
244 CAM_UNACKED_EVENT = 0x35,
246 /* Message Received in Host Target Mode */
247 CAM_MESSAGE_RECV = 0x36,
249 /* Invalid CDB received in Host Target Mode */
250 CAM_INVALID_CDB = 0x37,
252 /* Lun supplied is invalid */
253 CAM_LUN_INVALID = 0x38,
255 /* Target ID supplied is invalid */
256 CAM_TID_INVALID = 0x39,
258 /* The requested function is not available */
259 CAM_FUNC_NOTAVAIL = 0x3a,
261 /* Nexus is not established */
264 /* The initiator ID is invalid */
265 CAM_IID_INVALID = 0x3c,
267 /* The SCSI CDB has been received */
268 CAM_CDB_RECVD = 0x3d,
270 /* The LUN is already enabled for target mode */
271 CAM_LUN_ALRDY_ENA = 0x3e,
274 CAM_SCSI_BUSY = 0x3f,
281 /* The DEV queue is frozen w/this err */
282 CAM_DEV_QFRZN = 0x40,
284 /* Autosense data valid for target */
285 CAM_AUTOSNS_VALID = 0x80,
287 /* SIM ready to take more commands */
288 CAM_RELEASE_SIMQ = 0x100,
290 /* SIM has this command in it's queue */
291 CAM_SIM_QUEUED = 0x200,
293 /* Quality of service data is valid */
294 CAM_QOS_VALID = 0x400,
296 /* Mask bits for just the status # */
297 CAM_STATUS_MASK = 0x3F,
300 * Target Specific Adjunct Status
303 /* sent sense with status */
304 CAM_SENT_SENSE = 0x40000000
309 CAM_ESF_COMMAND = 0x01,
310 CAM_ESF_CAM_STATUS = 0x02,
311 CAM_ESF_PROTO_STATUS = 0x04,
313 } cam_error_string_flags;
317 CAM_EPF_MINIMAL = 0x01,
318 CAM_EPF_NORMAL = 0x02,
320 CAM_EPF_LEVEL_MASK = 0x0f
321 /* All bits above bit 3 are protocol-specific */
322 } cam_error_proto_flags;
325 CAM_ESF_PRINT_NONE = 0x00,
326 CAM_ESF_PRINT_STATUS = 0x10,
327 CAM_ESF_PRINT_SENSE = 0x20
328 } cam_error_scsi_flags;
331 CAM_ESMF_PRINT_NONE = 0x00,
332 CAM_ESMF_PRINT_STATUS = 0x10,
333 CAM_ESMF_PRINT_FULL_CMD = 0x20,
334 } cam_error_smp_flags;
337 CAM_EAF_PRINT_NONE = 0x00,
338 CAM_EAF_PRINT_STATUS = 0x10,
339 CAM_EAF_PRINT_RESULT = 0x20
340 } cam_error_ata_flags;
342 struct cam_status_entry
344 cam_status status_code;
345 const char *status_text;
348 extern const struct cam_status_entry cam_status_table[];
349 extern const int num_cam_status_entries;
351 extern int cam_sort_io_queues;
355 #ifdef SYSCTL_DECL /* from sysctl.h */
356 SYSCTL_DECL(_kern_cam);
360 typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
362 caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
363 int entry_size, cam_quirkmatch_t *comp_func);
365 void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
367 int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
368 const struct cam_status_entry*
369 cam_fetch_status_entry(cam_status status);
371 char * cam_error_string(union ccb *ccb, char *str, int str_len,
372 cam_error_string_flags flags,
373 cam_error_proto_flags proto_flags);
374 void cam_error_print(union ccb *ccb, cam_error_string_flags flags,
375 cam_error_proto_flags proto_flags);
379 char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
380 int str_len, cam_error_string_flags flags,
381 cam_error_proto_flags proto_flags);
382 void cam_error_print(struct cam_device *device, union ccb *ccb,
383 cam_error_string_flags flags,
384 cam_error_proto_flags proto_flags, FILE *ofile);
389 static __inline void cam_init_pinfo(cam_pinfo *pinfo);
391 static __inline void cam_init_pinfo(cam_pinfo *pinfo)
393 pinfo->priority = CAM_PRIORITY_NONE;
394 pinfo->index = CAM_UNQUEUED_INDEX;
398 #endif /* _CAM_CAM_H */