source: rtems-libbsd/freebsd/sys/cam/cam.h @ 6d9d7b1

55-freebsd-126-freebsd-12
Last change on this file since 6d9d7b1 was 75b706f, checked in by Sebastian Huber <sebastian.huber@…>, on 12/09/16 at 13:19:03

Update to FreeBSD head 2016-12-10

Git mirror commit 80c55f08a05ab3b26a73b226ccb56adc3122a55c.

  • Property mode set to 100644
File size: 10.6 KB
Line 
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$
29 */
30
31#ifndef _CAM_CAM_H
32#define _CAM_CAM_H 1
33
34#ifdef _KERNEL
35#ifndef __rtems__
36#include <opt_cam.h>
37#else /* __rtems__ */
38#include <rtems/bsd/local/opt_cam.h>
39#endif /* __rtems__ */
40#endif
41
42#include <sys/cdefs.h>
43
44typedef u_int path_id_t;
45typedef u_int target_id_t;
46typedef u_int64_t lun_id_t;
47
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 (~(u_int)0)
52
53#define CAM_EXTLUN_BYTE_SWIZZLE(lun) (  \
54        ((((u_int64_t)lun) & 0xffff000000000000L) >> 48) | \
55        ((((u_int64_t)lun) & 0x0000ffff00000000L) >> 16) | \
56        ((((u_int64_t)lun) & 0x00000000ffff0000L) << 16) | \
57        ((((u_int64_t)lun) & 0x000000000000ffffL) << 48))
58
59/*
60 * Maximum length for a CAM CDB. 
61 */
62#define CAM_MAX_CDBLEN 16
63
64/*
65 * Definition of a CAM peripheral driver entry.  Peripheral drivers instantiate
66 * one of these for each device they wish to communicate with and pass it into
67 * the xpt layer when they wish to schedule work on that device via the
68 * xpt_schedule API.
69 */
70struct cam_periph;
71
72/*
73 * Priority information for a CAM structure.
74 */
75typedef enum {
76    CAM_RL_HOST,
77    CAM_RL_BUS,
78    CAM_RL_XPT,
79    CAM_RL_DEV,
80    CAM_RL_NORMAL,
81    CAM_RL_VALUES
82} cam_rl;
83/*
84 * The generation number is incremented every time a new entry is entered into
85 * the queue giving round robin per priority level scheduling.
86 */
87typedef struct {
88        u_int32_t priority;
89#define CAM_PRIORITY_HOST       ((CAM_RL_HOST << 8) + 0x80)
90#define CAM_PRIORITY_BUS        ((CAM_RL_BUS << 8) + 0x80)
91#define CAM_PRIORITY_XPT        ((CAM_RL_XPT << 8) + 0x80)
92#define CAM_PRIORITY_DEV        ((CAM_RL_DEV << 8) + 0x80)
93#define CAM_PRIORITY_OOB        (CAM_RL_DEV << 8)
94#define CAM_PRIORITY_NORMAL     ((CAM_RL_NORMAL << 8) + 0x80)
95#define CAM_PRIORITY_NONE       (u_int32_t)-1
96        u_int32_t generation;
97        int       index;
98#define CAM_UNQUEUED_INDEX      -1
99#define CAM_ACTIVE_INDEX        -2     
100#define CAM_DONEQ_INDEX         -3     
101#define CAM_EXTRAQ_INDEX        INT_MAX
102} cam_pinfo;
103
104/*
105 * Macro to compare two generation numbers.  It is used like this: 
106 *
107 *      if (GENERATIONCMP(a, >=, b))
108 *              ...;
109 *
110 * GERERATIONCMP uses modular arithmetic to guard against wraps
111 * wraps in the generation number.
112 */
113#define GENERATIONCMP(x, op, y) ((int32_t)((x) - (y)) op 0)
114
115/* CAM flags XXX Move to cam_periph.h ??? */
116typedef enum {
117        CAM_FLAG_NONE           = 0x00,
118        CAM_EXPECT_INQ_CHANGE   = 0x01,
119        CAM_RETRY_SELTO         = 0x02 /* Retry Selection Timeouts */
120} cam_flags;
121
122enum {
123        SF_RETRY_UA             = 0x01, /* Retry UNIT ATTENTION conditions. */
124        SF_NO_PRINT             = 0x02, /* Never print error status. */
125        SF_QUIET_IR             = 0x04, /* Be quiet about Illegal Request responses */
126        SF_PRINT_ALWAYS         = 0x08, /* Always print error status. */
127        SF_NO_RECOVERY          = 0x10, /* Don't do active error recovery. */
128        SF_NO_RETRY             = 0x20, /* Don't do any retries. */
129        SF_RETRY_BUSY           = 0x40  /* Retry BUSY status. */
130};
131
132/* CAM  Status field values */
133typedef enum {
134        /* CCB request is in progress */
135        CAM_REQ_INPROG          = 0x00,
136
137        /* CCB request completed without error */
138        CAM_REQ_CMP             = 0x01,
139
140        /* CCB request aborted by the host */
141        CAM_REQ_ABORTED         = 0x02,
142
143        /* Unable to abort CCB request */
144        CAM_UA_ABORT            = 0x03,
145
146        /* CCB request completed with an error */
147        CAM_REQ_CMP_ERR         = 0x04,
148
149        /* CAM subsystem is busy */
150        CAM_BUSY                = 0x05,
151
152        /* CCB request was invalid */
153        CAM_REQ_INVALID         = 0x06,
154
155        /* Supplied Path ID is invalid */
156        CAM_PATH_INVALID        = 0x07,
157
158        /* SCSI Device Not Installed/there */
159        CAM_DEV_NOT_THERE       = 0x08,
160
161        /* Unable to terminate I/O CCB request */
162        CAM_UA_TERMIO           = 0x09,
163
164        /* Target Selection Timeout */
165        CAM_SEL_TIMEOUT         = 0x0a,
166
167        /* Command timeout */
168        CAM_CMD_TIMEOUT         = 0x0b,
169
170        /* SCSI error, look at error code in CCB */
171        CAM_SCSI_STATUS_ERROR   = 0x0c,
172
173        /* Message Reject Received */
174        CAM_MSG_REJECT_REC      = 0x0d,
175
176        /* SCSI Bus Reset Sent/Received */
177        CAM_SCSI_BUS_RESET      = 0x0e,
178
179        /* Uncorrectable parity error occurred */
180        CAM_UNCOR_PARITY        = 0x0f,
181
182        /* Autosense: request sense cmd fail */
183        CAM_AUTOSENSE_FAIL      = 0x10,
184
185        /* No HBA Detected error */
186        CAM_NO_HBA              = 0x11,
187
188        /* Data Overrun error */
189        CAM_DATA_RUN_ERR        = 0x12,
190
191        /* Unexpected Bus Free */
192        CAM_UNEXP_BUSFREE       = 0x13,
193
194        /* Target Bus Phase Sequence Failure */
195        CAM_SEQUENCE_FAIL       = 0x14,
196
197        /* CCB length supplied is inadequate */
198        CAM_CCB_LEN_ERR         = 0x15,
199
200        /* Unable to provide requested capability*/
201        CAM_PROVIDE_FAIL        = 0x16,
202
203        /* A SCSI BDR msg was sent to target */
204        CAM_BDR_SENT            = 0x17,
205
206        /* CCB request terminated by the host */
207        CAM_REQ_TERMIO          = 0x18,
208
209        /* Unrecoverable Host Bus Adapter Error */
210        CAM_UNREC_HBA_ERROR     = 0x19,
211
212        /* Request was too large for this host */
213        CAM_REQ_TOO_BIG         = 0x1a,
214
215        /*
216         * This request should be requeued to preserve
217         * transaction ordering.  This typically occurs
218         * when the SIM recognizes an error that should
219         * freeze the queue and must place additional
220         * requests for the target at the sim level
221         * back into the XPT queue.
222         */
223        CAM_REQUEUE_REQ         = 0x1b,
224
225        /* ATA error, look at error code in CCB */
226        CAM_ATA_STATUS_ERROR    = 0x1c,
227
228        /* Initiator/Target Nexus lost. */
229        CAM_SCSI_IT_NEXUS_LOST  = 0x1d,
230
231        /* SMP error, look at error code in CCB */
232        CAM_SMP_STATUS_ERROR    = 0x1e,
233
234        /*
235         * Command completed without error but  exceeded the soft
236         * timeout threshold.
237         */
238        CAM_REQ_SOFTTIMEOUT     = 0x1f,
239
240        /*
241         * 0x20 - 0x32 are unassigned
242         */
243
244        /* Initiator Detected Error */
245        CAM_IDE                 = 0x33,
246
247        /* Resource Unavailable */
248        CAM_RESRC_UNAVAIL       = 0x34,
249
250        /* Unacknowledged Event by Host */
251        CAM_UNACKED_EVENT       = 0x35,
252
253        /* Message Received in Host Target Mode */
254        CAM_MESSAGE_RECV        = 0x36,
255
256        /* Invalid CDB received in Host Target Mode */
257        CAM_INVALID_CDB         = 0x37,
258
259        /* Lun supplied is invalid */
260        CAM_LUN_INVALID         = 0x38,
261
262        /* Target ID supplied is invalid */
263        CAM_TID_INVALID         = 0x39,
264
265        /* The requested function is not available */
266        CAM_FUNC_NOTAVAIL       = 0x3a,
267
268        /* Nexus is not established */
269        CAM_NO_NEXUS            = 0x3b,
270
271        /* The initiator ID is invalid */
272        CAM_IID_INVALID         = 0x3c,
273
274        /* The SCSI CDB has been received */
275        CAM_CDB_RECVD           = 0x3d,
276
277        /* The LUN is already enabled for target mode */
278        CAM_LUN_ALRDY_ENA       = 0x3e,
279
280        /* SCSI Bus Busy */
281        CAM_SCSI_BUSY           = 0x3f,
282
283
284        /*
285         * Flags
286         */
287
288        /* The DEV queue is frozen w/this err */
289        CAM_DEV_QFRZN           = 0x40,
290
291        /* Autosense data valid for target */
292        CAM_AUTOSNS_VALID       = 0x80,
293
294        /* SIM ready to take more commands */
295        CAM_RELEASE_SIMQ        = 0x100,
296
297        /* SIM has this command in its queue */
298        CAM_SIM_QUEUED          = 0x200,
299
300        /* Quality of service data is valid */
301        CAM_QOS_VALID           = 0x400,
302
303        /* Mask bits for just the status # */
304        CAM_STATUS_MASK = 0x3F,
305
306        /*
307         * Target Specific Adjunct Status
308         */
309       
310        /* sent sense with status */
311        CAM_SENT_SENSE          = 0x40000000
312} cam_status;
313
314typedef enum {
315        CAM_ESF_NONE            = 0x00,
316        CAM_ESF_COMMAND         = 0x01,
317        CAM_ESF_CAM_STATUS      = 0x02,
318        CAM_ESF_PROTO_STATUS    = 0x04,
319        CAM_ESF_ALL             = 0xff
320} cam_error_string_flags;
321
322typedef enum {
323        CAM_EPF_NONE            = 0x00,
324        CAM_EPF_MINIMAL         = 0x01,
325        CAM_EPF_NORMAL          = 0x02,
326        CAM_EPF_ALL             = 0x03,
327        CAM_EPF_LEVEL_MASK      = 0x0f
328        /* All bits above bit 3 are protocol-specific */
329} cam_error_proto_flags;
330
331typedef enum {
332        CAM_ESF_PRINT_NONE      = 0x00,
333        CAM_ESF_PRINT_STATUS    = 0x10,
334        CAM_ESF_PRINT_SENSE     = 0x20
335} cam_error_scsi_flags;
336
337typedef enum {
338        CAM_ESMF_PRINT_NONE     = 0x00,
339        CAM_ESMF_PRINT_STATUS   = 0x10,
340        CAM_ESMF_PRINT_FULL_CMD = 0x20,
341} cam_error_smp_flags;
342
343typedef enum {
344        CAM_EAF_PRINT_NONE      = 0x00,
345        CAM_EAF_PRINT_STATUS    = 0x10,
346        CAM_EAF_PRINT_RESULT    = 0x20
347} cam_error_ata_flags;
348
349typedef enum {
350        CAM_STRVIS_FLAG_NONE            = 0x00,
351        CAM_STRVIS_FLAG_NONASCII_MASK   = 0x03,
352        CAM_STRVIS_FLAG_NONASCII_TRIM   = 0x00,
353        CAM_STRVIS_FLAG_NONASCII_RAW    = 0x01,
354        CAM_STRVIS_FLAG_NONASCII_SPC    = 0x02,
355        CAM_STRVIS_FLAG_NONASCII_ESC    = 0x03
356} cam_strvis_flags;
357
358struct cam_status_entry
359{
360        cam_status  status_code;
361        const char *status_text;
362};
363
364extern const struct cam_status_entry cam_status_table[];
365extern const int num_cam_status_entries;
366#ifdef _KERNEL
367extern int cam_sort_io_queues;
368#endif
369union ccb;
370struct sbuf;
371
372#ifdef SYSCTL_DECL      /* from sysctl.h */
373SYSCTL_DECL(_kern_cam);
374#endif
375
376__BEGIN_DECLS
377typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
378
379caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
380                       int entry_size, cam_quirkmatch_t *comp_func);
381
382void    cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
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*
388        cam_fetch_status_entry(cam_status status);
389#ifdef _KERNEL
390char *  cam_error_string(union ccb *ccb, char *str, int str_len,
391                         cam_error_string_flags flags,
392                         cam_error_proto_flags proto_flags);
393void    cam_error_print(union ccb *ccb, cam_error_string_flags 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,
402                        cam_error_string_flags flags,
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
410static __inline void cam_init_pinfo(cam_pinfo *pinfo)
411{
412        pinfo->priority = CAM_PRIORITY_NONE;   
413        pinfo->index = CAM_UNQUEUED_INDEX;
414}
415#endif
416
417#endif /* _CAM_CAM_H */
Note: See TracBrowser for help on using the repository browser.