]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * This header file contains public constants and structures used by | |
c5f1ac8b | 4 | * the SCSI initiator code. |
1da177e4 LT |
5 | */ |
6 | #ifndef _SCSI_SCSI_H | |
7 | #define _SCSI_SCSI_H | |
8 | ||
9 | #include <linux/types.h> | |
ac61c46f | 10 | #include <linux/scatterlist.h> |
0816c925 | 11 | #include <linux/kernel.h> |
07e38420 | 12 | #include <scsi/scsi_common.h> |
c5f1ac8b | 13 | #include <scsi/scsi_proto.h> |
f290f197 JB |
14 | |
15 | struct scsi_cmnd; | |
1da177e4 | 16 | |
0816c925 MP |
17 | enum scsi_timeouts { |
18 | SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ, | |
19 | }; | |
20 | ||
13f05c8d MP |
21 | /* |
22 | * DIX-capable adapters effectively support infinite chaining for the | |
23 | * protection information scatterlist | |
24 | */ | |
25 | #define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF | |
26 | ||
e02f3f59 CH |
27 | /* |
28 | * Special value for scanning to specify scanning or rescanning of all | |
29 | * possible channels, (target) ids, or luns on a given shost. | |
30 | */ | |
31 | #define SCAN_WILD_CARD ~0 | |
32 | ||
1da177e4 LT |
33 | /** scsi_status_is_good - check the status return. |
34 | * | |
35 | * @status: the status passed up from the driver (including host and | |
36 | * driver components) | |
37 | * | |
38 | * This returns true for known good conditions that may be treated as | |
39 | * command completed normally | |
40 | */ | |
41 | static inline int scsi_status_is_good(int status) | |
42 | { | |
43 | /* | |
44 | * FIXME: bit0 is listed as reserved in SCSI-2, but is | |
45 | * significant in SCSI-3. For now, we follow the SCSI-2 | |
46 | * behaviour and ignore reserved bits. | |
47 | */ | |
48 | status &= 0xfe; | |
49 | return ((status == SAM_STAT_GOOD) || | |
1875ede0 DG |
50 | (status == SAM_STAT_CONDITION_MET) || |
51 | /* Next two "intermediate" statuses are obsolete in SAM-4 */ | |
1da177e4 LT |
52 | (status == SAM_STAT_INTERMEDIATE) || |
53 | (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) || | |
54 | /* FIXME: this is obsolete in SAM-3 */ | |
55 | (status == SAM_STAT_COMMAND_TERMINATED)); | |
56 | } | |
57 | ||
4ff36718 | 58 | |
1da177e4 LT |
59 | /* |
60 | * standard mode-select header prepended to all mode-select commands | |
61 | */ | |
62 | ||
63 | struct ccs_modesel_head { | |
64 | __u8 _r1; /* reserved */ | |
65 | __u8 medium; /* device-specific medium type */ | |
66 | __u8 _r2; /* reserved */ | |
67 | __u8 block_desc_length; /* block descriptor length */ | |
68 | __u8 density; /* device-specific density code */ | |
69 | __u8 number_blocks_hi; /* number of blocks in this block desc */ | |
70 | __u8 number_blocks_med; | |
71 | __u8 number_blocks_lo; | |
72 | __u8 _r3; | |
73 | __u8 block_length_hi; /* block length for blocks in this desc */ | |
74 | __u8 block_length_med; | |
75 | __u8 block_length_lo; | |
76 | }; | |
77 | ||
01b291bd JB |
78 | /* |
79 | * The Well Known LUNS (SAM-3) in our int representation of a LUN | |
80 | */ | |
81 | #define SCSI_W_LUN_BASE 0xc100 | |
82 | #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1) | |
83 | #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2) | |
84 | #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3) | |
85 | ||
9cb78c16 | 86 | static inline int scsi_is_wlun(u64 lun) |
01b291bd JB |
87 | { |
88 | return (lun & 0xff00) == SCSI_W_LUN_BASE; | |
89 | } | |
90 | ||
91 | ||
1da177e4 LT |
92 | /* |
93 | * MESSAGE CODES | |
94 | */ | |
95 | ||
96 | #define COMMAND_COMPLETE 0x00 | |
97 | #define EXTENDED_MESSAGE 0x01 | |
98 | #define EXTENDED_MODIFY_DATA_POINTER 0x00 | |
99 | #define EXTENDED_SDTR 0x01 | |
100 | #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ | |
101 | #define EXTENDED_WDTR 0x03 | |
102 | #define EXTENDED_PPR 0x04 | |
103 | #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 | |
104 | #define SAVE_POINTERS 0x02 | |
105 | #define RESTORE_POINTERS 0x03 | |
106 | #define DISCONNECT 0x04 | |
107 | #define INITIATOR_ERROR 0x05 | |
108 | #define ABORT_TASK_SET 0x06 | |
109 | #define MESSAGE_REJECT 0x07 | |
110 | #define NOP 0x08 | |
111 | #define MSG_PARITY_ERROR 0x09 | |
112 | #define LINKED_CMD_COMPLETE 0x0a | |
113 | #define LINKED_FLG_CMD_COMPLETE 0x0b | |
114 | #define TARGET_RESET 0x0c | |
115 | #define ABORT_TASK 0x0d | |
116 | #define CLEAR_TASK_SET 0x0e | |
117 | #define INITIATE_RECOVERY 0x0f /* SCSI-II only */ | |
118 | #define RELEASE_RECOVERY 0x10 /* SCSI-II only */ | |
d8cd784f | 119 | #define TERMINATE_IO_PROC 0x11 /* SCSI-II only */ |
1da177e4 LT |
120 | #define CLEAR_ACA 0x16 |
121 | #define LOGICAL_UNIT_RESET 0x17 | |
122 | #define SIMPLE_QUEUE_TAG 0x20 | |
123 | #define HEAD_OF_QUEUE_TAG 0x21 | |
124 | #define ORDERED_QUEUE_TAG 0x22 | |
125 | #define IGNORE_WIDE_RESIDUE 0x23 | |
126 | #define ACA 0x24 | |
127 | #define QAS_REQUEST 0x55 | |
128 | ||
129 | /* Old SCSI2 names, don't use in new code */ | |
130 | #define BUS_DEVICE_RESET TARGET_RESET | |
131 | #define ABORT ABORT_TASK_SET | |
132 | ||
133 | /* | |
134 | * Host byte codes | |
135 | */ | |
136 | ||
137 | #define DID_OK 0x00 /* NO error */ | |
138 | #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ | |
139 | #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ | |
140 | #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ | |
141 | #define DID_BAD_TARGET 0x04 /* BAD target. */ | |
142 | #define DID_ABORT 0x05 /* Told to abort for some other reason */ | |
143 | #define DID_PARITY 0x06 /* Parity error */ | |
144 | #define DID_ERROR 0x07 /* Internal error */ | |
145 | #define DID_RESET 0x08 /* Reset by somebody. */ | |
146 | #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ | |
147 | #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ | |
148 | #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ | |
149 | #define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ | |
bf341919 JB |
150 | #define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also |
151 | * without decrementing the retry count */ | |
a4dfaa6f MC |
152 | #define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution |
153 | * and the driver blocked the port to | |
154 | * recover the link. Transport class will | |
155 | * retry or fail IO */ | |
156 | #define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ | |
63583cca HR |
157 | #define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on |
158 | * other paths */ | |
159 | #define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other | |
160 | * paths might yield different results */ | |
a9d6ceb8 | 161 | #define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */ |
7e782af5 | 162 | #define DID_MEDIUM_ERROR 0x13 /* Medium error */ |
962c8dcd | 163 | #define DID_TRANSPORT_MARGINAL 0x14 /* Transport marginal errors */ |
1da177e4 LT |
164 | #define DRIVER_OK 0x00 /* Driver status */ |
165 | ||
166 | /* | |
167 | * These indicate the error that occurred, and what is available. | |
168 | */ | |
169 | ||
170 | #define DRIVER_BUSY 0x01 | |
171 | #define DRIVER_SOFT 0x02 | |
172 | #define DRIVER_MEDIA 0x03 | |
173 | #define DRIVER_ERROR 0x04 | |
174 | ||
175 | #define DRIVER_INVALID 0x05 | |
176 | #define DRIVER_TIMEOUT 0x06 | |
177 | #define DRIVER_HARD 0x07 | |
178 | #define DRIVER_SENSE 0x08 | |
179 | ||
1da177e4 LT |
180 | /* |
181 | * Internal return values. | |
182 | */ | |
b8e162f9 BVA |
183 | enum scsi_disposition { |
184 | NEEDS_RETRY = 0x2001, | |
185 | SUCCESS = 0x2002, | |
186 | FAILED = 0x2003, | |
187 | QUEUED = 0x2004, | |
188 | SOFT_ERROR = 0x2005, | |
189 | ADD_TO_MLQUEUE = 0x2006, | |
190 | TIMEOUT_ERROR = 0x2007, | |
191 | SCSI_RETURN_NOT_HANDLED = 0x2008, | |
192 | FAST_IO_FAIL = 0x2009, | |
193 | }; | |
1da177e4 LT |
194 | |
195 | /* | |
196 | * Midlevel queue return values. | |
197 | */ | |
198 | #define SCSI_MLQUEUE_HOST_BUSY 0x1055 | |
199 | #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056 | |
200 | #define SCSI_MLQUEUE_EH_RETRY 0x1057 | |
f0c0a376 | 201 | #define SCSI_MLQUEUE_TARGET_BUSY 0x1058 |
1da177e4 LT |
202 | |
203 | /* | |
204 | * Use these to separate status msg and our bytes | |
205 | * | |
206 | * These are set by: | |
207 | * | |
208 | * status byte = set from target device | |
209 | * msg_byte = return status from host adapter itself. | |
210 | * host_byte = set by low-level driver to indicate status. | |
211 | * driver_byte = set by mid-level. | |
212 | */ | |
213 | #define status_byte(result) (((result) >> 1) & 0x7f) | |
214 | #define msg_byte(result) (((result) >> 8) & 0xff) | |
215 | #define host_byte(result) (((result) >> 16) & 0xff) | |
216 | #define driver_byte(result) (((result) >> 24) & 0xff) | |
1da177e4 LT |
217 | |
218 | #define sense_class(sense) (((sense) >> 4) & 0x7) | |
219 | #define sense_error(sense) ((sense) & 0xf) | |
497888cf | 220 | #define sense_valid(sense) ((sense) & 0x80) |
1da177e4 | 221 | |
b6651129 CH |
222 | /* |
223 | * default timeouts | |
224 | */ | |
225 | #define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ) | |
226 | #define START_STOP_TIMEOUT (60 * HZ) | |
227 | #define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ) | |
228 | #define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ) | |
229 | #define READ_DEFECT_DATA_TIMEOUT (60 * HZ ) | |
230 | ||
1da177e4 LT |
231 | |
232 | #define IDENTIFY_BASE 0x80 | |
233 | #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\ | |
234 | ((can_disconnect) ? 0x40 : 0) |\ | |
235 | ((lun) & 0x07)) | |
236 | ||
237 | /* | |
238 | * struct scsi_device::scsi_level values. For SCSI devices other than those | |
239 | * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1) | |
240 | * where "resp" is a byte array of the response to an INQUIRY. The scsi_level | |
241 | * variable is visible to the user via sysfs. | |
242 | */ | |
243 | ||
244 | #define SCSI_UNKNOWN 0 | |
245 | #define SCSI_1 1 | |
246 | #define SCSI_1_CCS 2 | |
247 | #define SCSI_2 3 | |
248 | #define SCSI_3 4 /* SPC */ | |
249 | #define SCSI_SPC_2 5 | |
250 | #define SCSI_SPC_3 6 | |
251 | ||
252 | /* | |
253 | * INQ PERIPHERAL QUALIFIERS | |
254 | */ | |
255 | #define SCSI_INQ_PQ_CON 0x00 | |
256 | #define SCSI_INQ_PQ_NOT_CON 0x01 | |
257 | #define SCSI_INQ_PQ_NOT_CAP 0x03 | |
258 | ||
259 | ||
260 | /* | |
261 | * Here are some scsi specific ioctl commands which are sometimes useful. | |
262 | * | |
263 | * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395 | |
264 | */ | |
265 | ||
266 | /* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */ | |
267 | #define SCSI_IOCTL_GET_IDLUN 0x5382 | |
268 | ||
269 | /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */ | |
270 | ||
271 | /* Used to obtain the host number of a device. */ | |
272 | #define SCSI_IOCTL_PROBE_HOST 0x5385 | |
273 | ||
274 | /* Used to obtain the bus number for a device */ | |
275 | #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 | |
276 | ||
277 | /* Used to obtain the PCI location of a device */ | |
278 | #define SCSI_IOCTL_GET_PCI 0x5387 | |
279 | ||
280 | #endif /* _SCSI_SCSI_H */ |