FreeBSD kernel CAM code
cam.h
Go to the documentation of this file.
1/*-
2 * Data structures and definitions for the CAM system.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 1997 Justin T. Gibbs.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
17 *
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
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD$
31 */
32
33#ifndef _CAM_CAM_H
34#define _CAM_CAM_H 1
35
36#ifdef _KERNEL
37#include "opt_cam.h"
38#endif
39
40#include <sys/cdefs.h>
41
42typedef u_int path_id_t;
43typedef u_int target_id_t;
44typedef u_int64_t lun_id_t;
45
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)
50
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))
56
57/*
58 * Maximum length for a CAM CDB.
59 */
60#define CAM_MAX_CDBLEN 16
61
62/*
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
66 * xpt_schedule API.
67 */
68struct cam_periph;
69
70/*
71 * Priority information for a CAM structure.
72 */
73typedef enum {
81/*
82 * The generation number is incremented every time a new entry is entered into
83 * the queue giving round robin per priority level scheduling.
84 */
85typedef struct {
86 u_int32_t priority;
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
94 u_int32_t generation;
95 int index;
96#define CAM_UNQUEUED_INDEX -1
97#define CAM_ACTIVE_INDEX -2
98#define CAM_DONEQ_INDEX -3
99#define CAM_ASYNC_INDEX -4
100#define CAM_EXTRAQ_INDEX INT_MAX
101} cam_pinfo;
102
103/*
104 * Macro to compare two generation numbers. It is used like this:
105 *
106 * if (GENERATIONCMP(a, >=, b))
107 * ...;
108 *
109 * GERERATIONCMP uses modular arithmetic to guard against wraps
110 * wraps in the generation number.
111 */
112#define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
113
114/* CAM flags XXX Move to cam_periph.h ??? */
115typedef enum {
118 CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */
120
121enum {
122 SF_RETRY_UA = 0x01, /* Retry UNIT ATTENTION conditions. */
123 SF_NO_PRINT = 0x02, /* Never print error status. */
124 SF_QUIET_IR = 0x04, /* Be quiet about Illegal Request responses */
125 SF_PRINT_ALWAYS = 0x08, /* Always print error status. */
126 SF_NO_RECOVERY = 0x10, /* Don't do active error recovery. */
127 SF_NO_RETRY = 0x20, /* Don't do any retries. */
128 SF_RETRY_BUSY = 0x40 /* Retry BUSY status. */
130
131/* CAM Status field values */
132typedef enum {
133 /* CCB request is in progress */
135
136 /* CCB request completed without error */
138
139 /* CCB request aborted by the host */
141
142 /* Unable to abort CCB request */
144
145 /* CCB request completed with an error */
147
148 /* CAM subsystem is busy */
149 CAM_BUSY = 0x05,
150
151 /* CCB request was invalid */
153
154 /* Supplied Path ID is invalid */
156
157 /* SCSI Device Not Installed/there */
159
160 /* Unable to terminate I/O CCB request */
162
163 /* Target Selection Timeout */
165
166 /* Command timeout */
168
169 /* SCSI error, look at error code in CCB */
171
172 /* Message Reject Received */
174
175 /* SCSI Bus Reset Sent/Received */
177
178 /* Uncorrectable parity error occurred */
180
181 /* Autosense: request sense cmd fail */
183
184 /* No HBA Detected error */
186
187 /* Data Overrun error */
189
190 /* Unexpected Bus Free */
192
193 /* Target Bus Phase Sequence Failure */
195
196 /* CCB length supplied is inadequate */
198
199 /* Unable to provide requested capability*/
201
202 /* A SCSI BDR msg was sent to target */
204
205 /* CCB request terminated by the host */
207
208 /* Unrecoverable Host Bus Adapter Error */
210
211 /* Request was too large for this host */
213
214 /*
215 * This request should be requeued to preserve
216 * transaction ordering. This typically occurs
217 * when the SIM recognizes an error that should
218 * freeze the queue and must place additional
219 * requests for the target at the sim level
220 * back into the XPT queue.
221 */
223
224 /* ATA error, look at error code in CCB */
226
227 /* Initiator/Target Nexus lost. */
229
230 /* SMP error, look at error code in CCB */
232
233 /*
234 * Command completed without error but exceeded the soft
235 * timeout threshold.
236 */
238
239 /*
240 * 0x20 - 0x32 are unassigned
241 */
242
243 /* Initiator Detected Error */
244 CAM_IDE = 0x33,
245
246 /* Resource Unavailable */
248
249 /* Unacknowledged Event by Host */
251
252 /* Message Received in Host Target Mode */
254
255 /* Invalid CDB received in Host Target Mode */
257
258 /* Lun supplied is invalid */
260
261 /* Target ID supplied is invalid */
263
264 /* The requested function is not available */
266
267 /* Nexus is not established */
269
270 /* The initiator ID is invalid */
272
273 /* The SCSI CDB has been received */
275
276 /* The LUN is already enabled for target mode */
278
279 /* SCSI Bus Busy */
281
282 /*
283 * Flags
284 */
285
286 /* The DEV queue is frozen w/this err */
288
289 /* Autosense data valid for target */
291
292 /* SIM ready to take more commands */
294
295 /* SIM has this command in its queue */
297
298 /* Quality of service data is valid */
300
301 /* Mask bits for just the status # */
303
304 /*
305 * Target Specific Adjunct Status
306 */
307
308 /* sent sense with status */
309 CAM_SENT_SENSE = 0x40000000
311
312typedef enum {
317 CAM_ESF_ALL = 0xff
319
320typedef enum {
325 CAM_EPF_LEVEL_MASK = 0x0f
326 /* All bits above bit 3 are protocol-specific */
328
329typedef enum {
334
335typedef enum {
340
341typedef enum {
346
347typedef enum {
355
357{
359 const char *status_text;
360};
361
362extern const struct cam_status_entry cam_status_table[];
363extern const int num_cam_status_entries;
364#ifdef _KERNEL
365extern int cam_sort_io_queues;
366#endif
367union ccb;
368struct sbuf;
369
370#ifdef SYSCTL_DECL /* from sysctl.h */
371SYSCTL_DECL(_kern_cam);
372#endif
373
374__BEGIN_DECLS
375typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
376
377caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
378 int entry_size, cam_quirkmatch_t *comp_func);
379
380void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
381void cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen,
382 int dstlen, uint32_t flags);
383void cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen,
384 uint32_t flags);
385
386int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
387const struct cam_status_entry*
389#ifdef _KERNEL
390char * cam_error_string(union ccb *ccb, char *str, int str_len,
392 cam_error_proto_flags proto_flags);
394 cam_error_proto_flags proto_flags);
395#else /* _KERNEL */
396struct cam_device;
397
398char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
399 int str_len, cam_error_string_flags flags,
400 cam_error_proto_flags proto_flags);
401void cam_error_print(struct cam_device *device, union ccb *ccb,
403 cam_error_proto_flags proto_flags, FILE *ofile);
404#endif /* _KERNEL */
405__END_DECLS
406
407#ifdef _KERNEL
408static __inline void cam_init_pinfo(cam_pinfo *pinfo)
409{
411 pinfo->index = CAM_UNQUEUED_INDEX;
412}
413#endif
414
415#endif /* _CAM_CAM_H */
cam_error_proto_flags
Definition: cam.h:320
@ CAM_EPF_LEVEL_MASK
Definition: cam.h:325
@ CAM_EPF_NONE
Definition: cam.h:321
@ CAM_EPF_MINIMAL
Definition: cam.h:322
@ CAM_EPF_ALL
Definition: cam.h:324
@ CAM_EPF_NORMAL
Definition: cam.h:323
@ SF_QUIET_IR
Definition: cam.h:124
@ SF_PRINT_ALWAYS
Definition: cam.h:125
@ SF_RETRY_UA
Definition: cam.h:122
@ SF_RETRY_BUSY
Definition: cam.h:128
@ SF_NO_RETRY
Definition: cam.h:127
@ SF_NO_RECOVERY
Definition: cam.h:126
@ SF_NO_PRINT
Definition: cam.h:123
cam_strvis_flags
Definition: cam.h:347
@ CAM_STRVIS_FLAG_NONASCII_MASK
Definition: cam.h:349
@ CAM_STRVIS_FLAG_NONASCII_ESC
Definition: cam.h:353
@ CAM_STRVIS_FLAG_NONASCII_SPC
Definition: cam.h:352
@ CAM_STRVIS_FLAG_NONASCII_RAW
Definition: cam.h:351
@ CAM_STRVIS_FLAG_NONE
Definition: cam.h:348
@ CAM_STRVIS_FLAG_NONASCII_TRIM
Definition: cam.h:350
cam_flags
Definition: cam.h:115
@ CAM_RETRY_SELTO
Definition: cam.h:118
@ CAM_FLAG_NONE
Definition: cam.h:116
@ CAM_EXPECT_INQ_CHANGE
Definition: cam.h:117
const struct cam_status_entry cam_status_table[]
Definition: cam.c:63
#define CAM_PRIORITY_NONE
Definition: cam.h:93
char * cam_error_string(union ccb *ccb, char *str, int str_len, cam_error_string_flags flags, cam_error_proto_flags proto_flags)
Definition: cam.c:315
caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, int entry_size, cam_quirkmatch_t *comp_func)
Definition: cam.c:281
#define CAM_UNQUEUED_INDEX
Definition: cam.h:96
u_int path_id_t
Definition: cam.h:42
cam_error_string_flags
Definition: cam.h:312
@ CAM_ESF_COMMAND
Definition: cam.h:314
@ CAM_ESF_ALL
Definition: cam.h:317
@ CAM_ESF_PROTO_STATUS
Definition: cam.h:316
@ CAM_ESF_CAM_STATUS
Definition: cam.h:315
@ CAM_ESF_NONE
Definition: cam.h:313
int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len)
Definition: cam.c:204
void cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, uint32_t flags)
Definition: cam.c:142
const struct cam_status_entry * cam_fetch_status_entry(cam_status status)
Definition: cam.c:292
static __END_DECLS __inline void cam_init_pinfo(cam_pinfo *pinfo)
Definition: cam.h:408
int cam_sort_io_queues
Definition: cam.c:118
cam_status
Definition: cam.h:132
@ CAM_ATA_STATUS_ERROR
Definition: cam.h:225
@ CAM_PATH_INVALID
Definition: cam.h:155
@ CAM_NO_NEXUS
Definition: cam.h:268
@ CAM_SCSI_BUS_RESET
Definition: cam.h:176
@ CAM_REQ_INVALID
Definition: cam.h:152
@ CAM_REQ_INPROG
Definition: cam.h:134
@ CAM_BUSY
Definition: cam.h:149
@ CAM_AUTOSENSE_FAIL
Definition: cam.h:182
@ CAM_IDE
Definition: cam.h:244
@ CAM_PROVIDE_FAIL
Definition: cam.h:200
@ CAM_SCSI_IT_NEXUS_LOST
Definition: cam.h:228
@ CAM_REQ_SOFTTIMEOUT
Definition: cam.h:237
@ CAM_UA_TERMIO
Definition: cam.h:161
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_AUTOSNS_VALID
Definition: cam.h:290
@ CAM_REQUEUE_REQ
Definition: cam.h:222
@ CAM_NO_HBA
Definition: cam.h:185
@ CAM_DEV_NOT_THERE
Definition: cam.h:158
@ CAM_CMD_TIMEOUT
Definition: cam.h:167
@ CAM_UA_ABORT
Definition: cam.h:143
@ CAM_RESRC_UNAVAIL
Definition: cam.h:247
@ CAM_UNCOR_PARITY
Definition: cam.h:179
@ CAM_MESSAGE_RECV
Definition: cam.h:253
@ CAM_SEQUENCE_FAIL
Definition: cam.h:194
@ CAM_SCSI_BUSY
Definition: cam.h:280
@ CAM_UNACKED_EVENT
Definition: cam.h:250
@ CAM_REQ_TOO_BIG
Definition: cam.h:212
@ CAM_REQ_CMP_ERR
Definition: cam.h:146
@ CAM_STATUS_MASK
Definition: cam.h:302
@ CAM_MSG_REJECT_REC
Definition: cam.h:173
@ CAM_SENT_SENSE
Definition: cam.h:309
@ CAM_REQ_ABORTED
Definition: cam.h:140
@ CAM_LUN_INVALID
Definition: cam.h:259
@ CAM_SMP_STATUS_ERROR
Definition: cam.h:231
@ CAM_FUNC_NOTAVAIL
Definition: cam.h:265
@ CAM_RELEASE_SIMQ
Definition: cam.h:293
@ CAM_CCB_LEN_ERR
Definition: cam.h:197
@ CAM_REQ_TERMIO
Definition: cam.h:206
@ CAM_SIM_QUEUED
Definition: cam.h:296
@ CAM_QOS_VALID
Definition: cam.h:299
@ CAM_UNREC_HBA_ERROR
Definition: cam.h:209
@ CAM_INVALID_CDB
Definition: cam.h:256
@ CAM_UNEXP_BUSFREE
Definition: cam.h:191
@ CAM_SCSI_STATUS_ERROR
Definition: cam.h:170
@ CAM_IID_INVALID
Definition: cam.h:271
@ CAM_LUN_ALRDY_ENA
Definition: cam.h:277
@ CAM_CDB_RECVD
Definition: cam.h:274
@ CAM_BDR_SENT
Definition: cam.h:203
@ CAM_TID_INVALID
Definition: cam.h:262
@ CAM_SEL_TIMEOUT
Definition: cam.h:164
@ CAM_DATA_RUN_ERR
Definition: cam.h:188
@ CAM_DEV_QFRZN
Definition: cam.h:287
const int num_cam_status_entries
void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen)
Definition: cam.c:124
void cam_strvis_flag(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen, uint32_t flags)
Definition: cam.c:131
cam_rl
Definition: cam.h:73
@ CAM_RL_VALUES
Definition: cam.h:79
@ CAM_RL_NORMAL
Definition: cam.h:78
@ CAM_RL_DEV
Definition: cam.h:77
@ CAM_RL_BUS
Definition: cam.h:75
@ CAM_RL_HOST
Definition: cam.h:74
@ CAM_RL_XPT
Definition: cam.h:76
cam_error_scsi_flags
Definition: cam.h:329
@ CAM_ESF_PRINT_SENSE
Definition: cam.h:332
@ CAM_ESF_PRINT_STATUS
Definition: cam.h:331
@ CAM_ESF_PRINT_NONE
Definition: cam.h:330
cam_error_ata_flags
Definition: cam.h:341
@ CAM_EAF_PRINT_STATUS
Definition: cam.h:343
@ CAM_EAF_PRINT_NONE
Definition: cam.h:342
@ CAM_EAF_PRINT_RESULT
Definition: cam.h:344
__BEGIN_DECLS typedef int() cam_quirkmatch_t(caddr_t, caddr_t)
cam_error_smp_flags
Definition: cam.h:335
@ CAM_ESMF_PRINT_FULL_CMD
Definition: cam.h:338
@ CAM_ESMF_PRINT_NONE
Definition: cam.h:336
@ CAM_ESMF_PRINT_STATUS
Definition: cam.h:337
void cam_error_print(union ccb *ccb, cam_error_string_flags flags, cam_error_proto_flags proto_flags)
Definition: cam.c:510
u_int target_id_t
Definition: cam.h:43
u_int64_t lun_id_t
Definition: cam.h:44
SYSCTL_DECL(_kern_cam_enc)
Definition: cam.h:85
u_int32_t priority
Definition: cam.h:86
u_int32_t generation
Definition: cam.h:94
int index
Definition: cam.h:95
Definition: cam.h:357
cam_status status_code
Definition: cam.h:358
const char * status_text
Definition: cam.h:359
Definition: cam_ccb.h:1345