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