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