FreeBSD/Linux Kernel Cross Reference
sys/cam/cam.h
1 /*-
2 * Data structures and definitions for the CAM system.
3 *
4 * Copyright (c) 1997 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
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
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/cam/cam.h 198849 2009-11-03 11:19:05Z mav $
29 */
30
31 #ifndef _CAM_CAM_H
32 #define _CAM_CAM_H 1
33
34 #ifdef _KERNEL
35 #include <opt_cam.h>
36 #endif
37
38 #include <sys/cdefs.h>
39
40 typedef u_int path_id_t;
41 typedef u_int target_id_t;
42 typedef u_int lun_id_t;
43
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)
48
49 /*
50 * Maximum length for a CAM CDB.
51 */
52 #define CAM_MAX_CDBLEN 16
53
54 /*
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
58 * xpt_schedule API.
59 */
60 struct cam_periph;
61
62 /*
63 * Priority information for a CAM structure. The generation number is
64 * incremented everytime a new entry is entered into the queue giving round
65 * robin per priority level scheduling.
66 */
67 typedef struct {
68 u_int32_t priority;
69 #define CAM_PRIORITY_BUS 0
70 #define CAM_PRIORITY_DEV 0
71 #define CAM_PRIORITY_NORMAL 1
72 #define CAM_PRIORITY_NONE (u_int32_t)-1
73 u_int32_t generation;
74 int index;
75 #define CAM_UNQUEUED_INDEX -1
76 #define CAM_ACTIVE_INDEX -2
77 #define CAM_DONEQ_INDEX -3
78 } cam_pinfo;
79
80 /*
81 * Macro to compare two generation numbers. It is used like this:
82 *
83 * if (GENERATIONCMP(a, >=, b))
84 * ...;
85 *
86 * GERERATIONCMP uses modular arithmetic to guard against wraps
87 * wraps in the generation number.
88 */
89 #define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
90
91 /* CAM flags XXX Move to cam_periph.h ??? */
92 typedef enum {
93 CAM_FLAG_NONE = 0x00,
94 CAM_EXPECT_INQ_CHANGE = 0x01,
95 CAM_RETRY_SELTO = 0x02 /* Retry Selection Timeouts */
96 } cam_flags;
97
98 /* CAM Status field values */
99 typedef enum {
100 CAM_REQ_INPROG, /* CCB request is in progress */
101 CAM_REQ_CMP, /* CCB request completed without error */
102 CAM_REQ_ABORTED, /* CCB request aborted by the host */
103 CAM_UA_ABORT, /* Unable to abort CCB request */
104 CAM_REQ_CMP_ERR, /* CCB request completed with an error */
105 CAM_BUSY, /* CAM subsystem is busy */
106 CAM_REQ_INVALID, /* CCB request was invalid */
107 CAM_PATH_INVALID, /* Supplied Path ID is invalid */
108 CAM_DEV_NOT_THERE, /* SCSI Device Not Installed/there */
109 CAM_UA_TERMIO, /* Unable to terminate I/O CCB request */
110 CAM_SEL_TIMEOUT, /* Target Selection Timeout */
111 CAM_CMD_TIMEOUT, /* Command timeout */
112 CAM_SCSI_STATUS_ERROR, /* SCSI error, look at error code in CCB */
113 CAM_MSG_REJECT_REC, /* Message Reject Received */
114 CAM_SCSI_BUS_RESET, /* SCSI Bus Reset Sent/Received */
115 CAM_UNCOR_PARITY, /* Uncorrectable parity error occurred */
116 CAM_AUTOSENSE_FAIL = 0x10,/* Autosense: request sense cmd fail */
117 CAM_NO_HBA, /* No HBA Detected error */
118 CAM_DATA_RUN_ERR, /* Data Overrun error */
119 CAM_UNEXP_BUSFREE, /* Unexpected Bus Free */
120 CAM_SEQUENCE_FAIL, /* Target Bus Phase Sequence Failure */
121 CAM_CCB_LEN_ERR, /* CCB length supplied is inadequate */
122 CAM_PROVIDE_FAIL, /* Unable to provide requested capability */
123 CAM_BDR_SENT, /* A SCSI BDR msg was sent to target */
124 CAM_REQ_TERMIO, /* CCB request terminated by the host */
125 CAM_UNREC_HBA_ERROR, /* Unrecoverable Host Bus Adapter Error */
126 CAM_REQ_TOO_BIG, /* The request was too large for this host */
127 CAM_REQUEUE_REQ, /*
128 * This request should be requeued to preserve
129 * transaction ordering. This typically occurs
130 * when the SIM recognizes an error that should
131 * freeze the queue and must place additional
132 * requests for the target at the sim level
133 * back into the XPT queue.
134 */
135 CAM_ATA_STATUS_ERROR, /* ATA error, look at error code in CCB */
136 CAM_SCSI_IT_NEXUS_LOST, /* Initiator/Target Nexus lost. */
137 CAM_IDE = 0x33, /* Initiator Detected Error */
138 CAM_RESRC_UNAVAIL, /* Resource Unavailable */
139 CAM_UNACKED_EVENT, /* Unacknowledged Event by Host */
140 CAM_MESSAGE_RECV, /* Message Received in Host Target Mode */
141 CAM_INVALID_CDB, /* Invalid CDB received in Host Target Mode */
142 CAM_LUN_INVALID, /* Lun supplied is invalid */
143 CAM_TID_INVALID, /* Target ID supplied is invalid */
144 CAM_FUNC_NOTAVAIL, /* The requested function is not available */
145 CAM_NO_NEXUS, /* Nexus is not established */
146 CAM_IID_INVALID, /* The initiator ID is invalid */
147 CAM_CDB_RECVD, /* The SCSI CDB has been received */
148 CAM_LUN_ALRDY_ENA, /* The LUN is already enabled for target mode */
149 CAM_SCSI_BUSY, /* SCSI Bus Busy */
150
151 CAM_DEV_QFRZN = 0x40, /* The DEV queue is frozen w/this err */
152
153 /* Autosense data valid for target */
154 CAM_AUTOSNS_VALID = 0x80,
155 CAM_RELEASE_SIMQ = 0x100,/* SIM ready to take more commands */
156 CAM_SIM_QUEUED = 0x200,/* SIM has this command in it's queue */
157
158 CAM_STATUS_MASK = 0x3F, /* Mask bits for just the status # */
159
160 /* Target Specific Adjunct Status */
161 CAM_SENT_SENSE = 0x40000000 /* sent sense with status */
162 } cam_status;
163
164 typedef enum {
165 CAM_ESF_NONE = 0x00,
166 CAM_ESF_COMMAND = 0x01,
167 CAM_ESF_CAM_STATUS = 0x02,
168 CAM_ESF_PROTO_STATUS = 0x04,
169 CAM_ESF_ALL = 0xff
170 } cam_error_string_flags;
171
172 typedef enum {
173 CAM_EPF_NONE = 0x00,
174 CAM_EPF_MINIMAL = 0x01,
175 CAM_EPF_NORMAL = 0x02,
176 CAM_EPF_ALL = 0x03,
177 CAM_EPF_LEVEL_MASK = 0x0f
178 /* All bits above bit 3 are protocol-specific */
179 } cam_error_proto_flags;
180
181 typedef enum {
182 CAM_ESF_PRINT_NONE = 0x00,
183 CAM_ESF_PRINT_STATUS = 0x10,
184 CAM_ESF_PRINT_SENSE = 0x20
185 } cam_error_scsi_flags;
186
187 typedef enum {
188 CAM_EAF_PRINT_NONE = 0x00,
189 CAM_EAF_PRINT_STATUS = 0x10,
190 CAM_EAF_PRINT_RESULT = 0x20
191 } cam_error_ata_flags;
192
193 struct cam_status_entry
194 {
195 cam_status status_code;
196 const char *status_text;
197 };
198
199 extern const struct cam_status_entry cam_status_table[];
200 extern const int num_cam_status_entries;
201 union ccb;
202
203 #ifdef SYSCTL_DECL /* from sysctl.h */
204 SYSCTL_DECL(_kern_cam);
205 #endif
206
207 __BEGIN_DECLS
208 typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
209
210 caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
211 int entry_size, cam_quirkmatch_t *comp_func);
212
213 void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
214
215 int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
216 const struct cam_status_entry*
217 cam_fetch_status_entry(cam_status status);
218 #ifdef _KERNEL
219 char * cam_error_string(union ccb *ccb, char *str, int str_len,
220 cam_error_string_flags flags,
221 cam_error_proto_flags proto_flags);
222 void cam_error_print(union ccb *ccb, cam_error_string_flags flags,
223 cam_error_proto_flags proto_flags);
224 #else /* _KERNEL */
225 struct cam_device;
226
227 char * cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
228 int str_len, cam_error_string_flags flags,
229 cam_error_proto_flags proto_flags);
230 void cam_error_print(struct cam_device *device, union ccb *ccb,
231 cam_error_string_flags flags,
232 cam_error_proto_flags proto_flags, FILE *ofile);
233 #endif /* _KERNEL */
234 __END_DECLS
235
236 #ifdef _KERNEL
237 static __inline void cam_init_pinfo(cam_pinfo *pinfo);
238
239 static __inline void cam_init_pinfo(cam_pinfo *pinfo)
240 {
241 pinfo->priority = CAM_PRIORITY_NONE;
242 pinfo->index = CAM_UNQUEUED_INDEX;
243 }
244 #endif
245
246 #endif /* _CAM_CAM_H */
Cache object: 6fa9015ad8671f014e698a6a8339146b
|