2 * Data structures and definitions for the CAM system.
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 1997 Justin T. Gibbs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification, immediately at the beginning of the file.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #include <sys/cdefs.h>
42 typedef u_int path_id_t;
43 typedef u_int target_id_t;
44 typedef u_int64_t lun_id_t;
46 #define CAM_XPT_PATH_ID ((path_id_t)~0)
47 #define CAM_BUS_WILDCARD ((path_id_t)~0)
48 #define CAM_TARGET_WILDCARD ((target_id_t)~0)
49 #define CAM_LUN_WILDCARD (~(u_int)0)
51 #define CAM_EXTLUN_BYTE_SWIZZLE(lun) ( \
52 ((((u_int64_t)lun) & 0xffff000000000000L) >> 48) | \
53 ((((u_int64_t)lun) & 0x0000ffff00000000L) >> 16) | \
54 ((((u_int64_t)lun) & 0x00000000ffff0000L) << 16) | \
55 ((((u_int64_t)lun) & 0x000000000000ffffL) << 48))
58 * Maximum length for a CAM CDB.
60 #define CAM_MAX_CDBLEN 16
63 * Definition of a CAM peripheral driver entry. Peripheral drivers instantiate
64 * one of these for each device they wish to communicate with and pass it into
65 * the xpt layer when they wish to schedule work on that device via the
71 * Priority information for a CAM structure.
82 * The generation number is incremented every time a new entry is entered into
83 * the queue giving round robin per priority level scheduling.
87 #define CAM_PRIORITY_HOST ((CAM_RL_HOST << 8) + 0x80)
88 #define CAM_PRIORITY_BUS ((CAM_RL_BUS << 8) + 0x80)
89 #define CAM_PRIORITY_XPT ((CAM_RL_XPT << 8) + 0x80)
90 #define CAM_PRIORITY_DEV ((CAM_RL_DEV << 8) + 0x80)
91 #define CAM_PRIORITY_OOB (CAM_RL_DEV << 8)
92 #define CAM_PRIORITY_NORMAL ((CAM_RL_NORMAL << 8) + 0x80)
93 #define CAM_PRIORITY_NONE (u_int32_t)-1
96 #define CAM_UNQUEUED_INDEX -1
97 #define CAM_ACTIVE_INDEX -2
98 #define CAM_DONEQ_INDEX -3
99 #define CAM_EXTRAQ_INDEX INT_MAX
103 * Macro to compare two generation numbers. It is used like this:
105 * if (GENERATIONCMP(a, >=, b))
108 * GERERATIONCMP uses modular arithmetic to guard against wraps
109 * wraps in the generation number.
111 #define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
113 /* CAM flags XXX Move to cam_periph.h ??? */
115 CAM_FLAG_NONE = 0x00,
116 CAM_EXPECT_INQ_CHANGE = 0x01,
117 CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */
121 SF_RETRY_UA = 0x01, /* Retry UNIT ATTENTION conditions. */
122 SF_NO_PRINT = 0x02, /* Never print error status. */
123 SF_QUIET_IR = 0x04, /* Be quiet about Illegal Request responses */
124 SF_PRINT_ALWAYS = 0x08, /* Always print error status. */
125 SF_NO_RECOVERY = 0x10, /* Don't do active error recovery. */
126 SF_NO_RETRY = 0x20, /* Don't do any retries. */
127 SF_RETRY_BUSY = 0x40 /* Retry BUSY status. */
130 /* CAM Status field values */
132 /* CCB request is in progress */
133 CAM_REQ_INPROG = 0x00,
135 /* CCB request completed without error */
138 /* CCB request aborted by the host */
139 CAM_REQ_ABORTED = 0x02,
141 /* Unable to abort CCB request */
144 /* CCB request completed with an error */
145 CAM_REQ_CMP_ERR = 0x04,
147 /* CAM subsystem is busy */
150 /* CCB request was invalid */
151 CAM_REQ_INVALID = 0x06,
153 /* Supplied Path ID is invalid */
154 CAM_PATH_INVALID = 0x07,
156 /* SCSI Device Not Installed/there */
157 CAM_DEV_NOT_THERE = 0x08,
159 /* Unable to terminate I/O CCB request */
160 CAM_UA_TERMIO = 0x09,
162 /* Target Selection Timeout */
163 CAM_SEL_TIMEOUT = 0x0a,
165 /* Command timeout */
166 CAM_CMD_TIMEOUT = 0x0b,
168 /* SCSI error, look at error code in CCB */
169 CAM_SCSI_STATUS_ERROR = 0x0c,
171 /* Message Reject Received */
172 CAM_MSG_REJECT_REC = 0x0d,
174 /* SCSI Bus Reset Sent/Received */
175 CAM_SCSI_BUS_RESET = 0x0e,
177 /* Uncorrectable parity error occurred */
178 CAM_UNCOR_PARITY = 0x0f,
180 /* Autosense: request sense cmd fail */
181 CAM_AUTOSENSE_FAIL = 0x10,
183 /* No HBA Detected error */
186 /* Data Overrun error */
187 CAM_DATA_RUN_ERR = 0x12,
189 /* Unexpected Bus Free */
190 CAM_UNEXP_BUSFREE = 0x13,
192 /* Target Bus Phase Sequence Failure */
193 CAM_SEQUENCE_FAIL = 0x14,
195 /* CCB length supplied is inadequate */
196 CAM_CCB_LEN_ERR = 0x15,
198 /* Unable to provide requested capability*/
199 CAM_PROVIDE_FAIL = 0x16,
201 /* A SCSI BDR msg was sent to target */
204 /* CCB request terminated by the host */
205 CAM_REQ_TERMIO = 0x18,
207 /* Unrecoverable Host Bus Adapter Error */
208 CAM_UNREC_HBA_ERROR = 0x19,
210 /* Request was too large for this host */
211 CAM_REQ_TOO_BIG = 0x1a,
214 * This request should be requeued to preserve
215 * transaction ordering. This typically occurs
216 * when the SIM recognizes an error that should
217 * freeze the queue and must place additional
218 * requests for the target at the sim level
219 * back into the XPT queue.
221 CAM_REQUEUE_REQ = 0x1b,
223 /* ATA error, look at error code in CCB */
224 CAM_ATA_STATUS_ERROR = 0x1c,
226 /* Initiator/Target Nexus lost. */
227 CAM_SCSI_IT_NEXUS_LOST = 0x1d,
229 /* SMP error, look at error code in CCB */
230 CAM_SMP_STATUS_ERROR = 0x1e,
233 * Command completed without error but exceeded the soft
236 CAM_REQ_SOFTTIMEOUT = 0x1f,
239 * 0x20 - 0x32 are unassigned
242 /* Initiator Detected Error */
245 /* Resource Unavailable */
246 CAM_RESRC_UNAVAIL = 0x34,
248 /* Unacknowledged Event by Host */
249 CAM_UNACKED_EVENT = 0x35,
251 /* Message Received in Host Target Mode */
252 CAM_MESSAGE_RECV = 0x36,
254 /* Invalid CDB received in Host Target Mode */
255 CAM_INVALID_CDB = 0x37,
257 /* Lun supplied is invalid */
258 CAM_LUN_INVALID = 0x38,
260 /* Target ID supplied is invalid */
261 CAM_TID_INVALID = 0x39,
263 /* The requested function is not available */
264 CAM_FUNC_NOTAVAIL = 0x3a,
266 /* Nexus is not established */
269 /* The initiator ID is invalid */
270 CAM_IID_INVALID = 0x3c,
272 /* The SCSI CDB has been received */
273 CAM_CDB_RECVD = 0x3d,
275 /* The LUN is already enabled for target mode */
276 CAM_LUN_ALRDY_ENA = 0x3e,
279 CAM_SCSI_BUSY = 0x3f,
285 /* The DEV queue is frozen w/this err */
286 CAM_DEV_QFRZN = 0x40,
288 /* Autosense data valid for target */
289 CAM_AUTOSNS_VALID = 0x80,
291 /* SIM ready to take more commands */
292 CAM_RELEASE_SIMQ = 0x100,
294 /* SIM has this command in its queue */
295 CAM_SIM_QUEUED = 0x200,
297 /* Quality of service data is valid */
298 CAM_QOS_VALID = 0x400,
300 /* Mask bits for just the status # */
301 CAM_STATUS_MASK = 0x3F,
304 * Target Specific Adjunct Status
307 /* sent sense with status */
308 CAM_SENT_SENSE = 0x40000000
313 CAM_ESF_COMMAND = 0x01,
314 CAM_ESF_CAM_STATUS = 0x02,
315 CAM_ESF_PROTO_STATUS = 0x04,
317 } cam_error_string_flags;
321 CAM_EPF_MINIMAL = 0x01,
322 CAM_EPF_NORMAL = 0x02,
324 CAM_EPF_LEVEL_MASK = 0x0f
325 /* All bits above bit 3 are protocol-specific */
326 } cam_error_proto_flags;
329 CAM_ESF_PRINT_NONE = 0x00,
330 CAM_ESF_PRINT_STATUS = 0x10,
331 CAM_ESF_PRINT_SENSE = 0x20
332 } cam_error_scsi_flags;
335 CAM_ESMF_PRINT_NONE = 0x00,
336 CAM_ESMF_PRINT_STATUS = 0x10,
337 CAM_ESMF_PRINT_FULL_CMD = 0x20,
338 } cam_error_smp_flags;
341 CAM_EAF_PRINT_NONE = 0x00,
342 CAM_EAF_PRINT_STATUS = 0x10,
343 CAM_EAF_PRINT_RESULT = 0x20
344 } cam_error_ata_flags;
347 CAM_STRVIS_FLAG_NONE = 0x00,
348 CAM_STRVIS_FLAG_NONASCII_MASK = 0x03,
349 CAM_STRVIS_FLAG_NONASCII_TRIM = 0x00,
350 CAM_STRVIS_FLAG_NONASCII_RAW = 0x01,
351 CAM_STRVIS_FLAG_NONASCII_SPC = 0x02,
352 CAM_STRVIS_FLAG_NONASCII_ESC = 0x03
355 struct cam_status_entry
357 cam_status status_code;
358 const char *status_text;
361 extern const struct cam_status_entry cam_status_table[];
362 extern const int num_cam_status_entries;
364 extern int cam_sort_io_queues;
369 #ifdef SYSCTL_DECL /* from sysctl.h */
370 SYSCTL_DECL(_kern_cam);
374 typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
376 caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
377 int entry_size, cam_quirkmatch_t *comp_func);
379 void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
380 void cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen,
383 int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
384 const struct cam_status_entry*
385 cam_fetch_status_entry(cam_status status);
387 char * cam_error_string(union ccb *ccb, char *str, int str_len,
388 cam_error_string_flags flags,
389 cam_error_proto_flags proto_flags);
390 void cam_error_print(union ccb *ccb, cam_error_string_flags flags,
391 cam_error_proto_flags proto_flags);
395 char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
396 int str_len, cam_error_string_flags flags,
397 cam_error_proto_flags proto_flags);
398 void cam_error_print(struct cam_device *device, union ccb *ccb,
399 cam_error_string_flags flags,
400 cam_error_proto_flags proto_flags, FILE *ofile);
405 static __inline void cam_init_pinfo(cam_pinfo *pinfo)
407 pinfo->priority = CAM_PRIORITY_NONE;
408 pinfo->index = CAM_UNQUEUED_INDEX;
412 #endif /* _CAM_CAM_H */