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> |
149d0e48 | 14 | #include <scsi/scsi_status.h> |
f290f197 JB |
15 | |
16 | struct scsi_cmnd; | |
1da177e4 | 17 | |
0816c925 MP |
18 | enum scsi_timeouts { |
19 | SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ, | |
20 | }; | |
21 | ||
13f05c8d MP |
22 | /* |
23 | * DIX-capable adapters effectively support infinite chaining for the | |
24 | * protection information scatterlist | |
25 | */ | |
26 | #define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF | |
27 | ||
e02f3f59 CH |
28 | /* |
29 | * Special value for scanning to specify scanning or rescanning of all | |
30 | * possible channels, (target) ids, or luns on a given shost. | |
31 | */ | |
32 | #define SCAN_WILD_CARD ~0 | |
33 | ||
1da177e4 LT |
34 | /* |
35 | * standard mode-select header prepended to all mode-select commands | |
36 | */ | |
37 | ||
38 | struct ccs_modesel_head { | |
39 | __u8 _r1; /* reserved */ | |
40 | __u8 medium; /* device-specific medium type */ | |
41 | __u8 _r2; /* reserved */ | |
42 | __u8 block_desc_length; /* block descriptor length */ | |
43 | __u8 density; /* device-specific density code */ | |
44 | __u8 number_blocks_hi; /* number of blocks in this block desc */ | |
45 | __u8 number_blocks_med; | |
46 | __u8 number_blocks_lo; | |
47 | __u8 _r3; | |
48 | __u8 block_length_hi; /* block length for blocks in this desc */ | |
49 | __u8 block_length_med; | |
50 | __u8 block_length_lo; | |
51 | }; | |
52 | ||
01b291bd JB |
53 | /* |
54 | * The Well Known LUNS (SAM-3) in our int representation of a LUN | |
55 | */ | |
56 | #define SCSI_W_LUN_BASE 0xc100 | |
57 | #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1) | |
58 | #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2) | |
59 | #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3) | |
60 | ||
9cb78c16 | 61 | static inline int scsi_is_wlun(u64 lun) |
01b291bd JB |
62 | { |
63 | return (lun & 0xff00) == SCSI_W_LUN_BASE; | |
64 | } | |
65 | ||
d0672a03 HR |
66 | /** |
67 | * scsi_status_is_check_condition - check the status return. | |
68 | * | |
69 | * @status: the status passed up from the driver (including host and | |
70 | * driver components) | |
71 | * | |
72 | * This returns true if the status code is SAM_STAT_CHECK_CONDITION. | |
73 | */ | |
74 | static inline int scsi_status_is_check_condition(int status) | |
75 | { | |
76 | if (status < 0) | |
77 | return false; | |
78 | status &= 0xfe; | |
79 | return status == SAM_STAT_CHECK_CONDITION; | |
80 | } | |
01b291bd | 81 | |
1da177e4 | 82 | /* |
149d0e48 | 83 | * Extended message codes. |
1da177e4 | 84 | */ |
1da177e4 LT |
85 | #define EXTENDED_MODIFY_DATA_POINTER 0x00 |
86 | #define EXTENDED_SDTR 0x01 | |
87 | #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ | |
88 | #define EXTENDED_WDTR 0x03 | |
89 | #define EXTENDED_PPR 0x04 | |
90 | #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 | |
1da177e4 | 91 | |
1da177e4 LT |
92 | /* |
93 | * Internal return values. | |
94 | */ | |
b8e162f9 BVA |
95 | enum scsi_disposition { |
96 | NEEDS_RETRY = 0x2001, | |
97 | SUCCESS = 0x2002, | |
98 | FAILED = 0x2003, | |
99 | QUEUED = 0x2004, | |
100 | SOFT_ERROR = 0x2005, | |
101 | ADD_TO_MLQUEUE = 0x2006, | |
102 | TIMEOUT_ERROR = 0x2007, | |
103 | SCSI_RETURN_NOT_HANDLED = 0x2008, | |
104 | FAST_IO_FAIL = 0x2009, | |
105 | }; | |
1da177e4 LT |
106 | |
107 | /* | |
108 | * Midlevel queue return values. | |
109 | */ | |
110 | #define SCSI_MLQUEUE_HOST_BUSY 0x1055 | |
111 | #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056 | |
112 | #define SCSI_MLQUEUE_EH_RETRY 0x1057 | |
f0c0a376 | 113 | #define SCSI_MLQUEUE_TARGET_BUSY 0x1058 |
1da177e4 LT |
114 | |
115 | /* | |
116 | * Use these to separate status msg and our bytes | |
117 | * | |
118 | * These are set by: | |
119 | * | |
120 | * status byte = set from target device | |
54cf31d0 | 121 | * msg_byte (unused) |
1da177e4 | 122 | * host_byte = set by low-level driver to indicate status. |
1da177e4 | 123 | */ |
1da177e4 | 124 | #define host_byte(result) (((result) >> 16) & 0xff) |
1da177e4 LT |
125 | |
126 | #define sense_class(sense) (((sense) >> 4) & 0x7) | |
127 | #define sense_error(sense) ((sense) & 0xf) | |
497888cf | 128 | #define sense_valid(sense) ((sense) & 0x80) |
1da177e4 | 129 | |
b6651129 | 130 | /* |
131 | * default timeouts | |
132 | */ | |
133 | #define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ) | |
134 | #define START_STOP_TIMEOUT (60 * HZ) | |
135 | #define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ) | |
136 | #define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ) | |
137 | #define READ_DEFECT_DATA_TIMEOUT (60 * HZ ) | |
138 | ||
1da177e4 LT |
139 | |
140 | #define IDENTIFY_BASE 0x80 | |
141 | #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\ | |
142 | ((can_disconnect) ? 0x40 : 0) |\ | |
143 | ((lun) & 0x07)) | |
144 | ||
145 | /* | |
146 | * struct scsi_device::scsi_level values. For SCSI devices other than those | |
147 | * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1) | |
148 | * where "resp" is a byte array of the response to an INQUIRY. The scsi_level | |
149 | * variable is visible to the user via sysfs. | |
150 | */ | |
151 | ||
152 | #define SCSI_UNKNOWN 0 | |
153 | #define SCSI_1 1 | |
154 | #define SCSI_1_CCS 2 | |
155 | #define SCSI_2 3 | |
156 | #define SCSI_3 4 /* SPC */ | |
157 | #define SCSI_SPC_2 5 | |
158 | #define SCSI_SPC_3 6 | |
159 | ||
160 | /* | |
161 | * INQ PERIPHERAL QUALIFIERS | |
162 | */ | |
163 | #define SCSI_INQ_PQ_CON 0x00 | |
164 | #define SCSI_INQ_PQ_NOT_CON 0x01 | |
165 | #define SCSI_INQ_PQ_NOT_CAP 0x03 | |
166 | ||
167 | ||
168 | /* | |
169 | * Here are some scsi specific ioctl commands which are sometimes useful. | |
170 | * | |
171 | * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395 | |
172 | */ | |
173 | ||
174 | /* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */ | |
175 | #define SCSI_IOCTL_GET_IDLUN 0x5382 | |
176 | ||
177 | /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */ | |
178 | ||
179 | /* Used to obtain the host number of a device. */ | |
180 | #define SCSI_IOCTL_PROBE_HOST 0x5385 | |
181 | ||
182 | /* Used to obtain the bus number for a device */ | |
183 | #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 | |
184 | ||
185 | /* Used to obtain the PCI location of a device */ | |
186 | #define SCSI_IOCTL_GET_PCI 0x5387 | |
187 | ||
1ee27534 JY |
188 | /** scsi_status_is_good - check the status return. |
189 | * | |
190 | * @status: the status passed up from the driver (including host and | |
191 | * driver components) | |
192 | * | |
193 | * This returns true for known good conditions that may be treated as | |
194 | * command completed normally | |
195 | */ | |
ced202f7 | 196 | static inline bool scsi_status_is_good(int status) |
1ee27534 | 197 | { |
ced202f7 HR |
198 | if (status < 0) |
199 | return false; | |
200 | ||
1ee27534 | 201 | if (host_byte(status) == DID_NO_CONNECT) |
ced202f7 | 202 | return false; |
1ee27534 JY |
203 | |
204 | /* | |
205 | * FIXME: bit0 is listed as reserved in SCSI-2, but is | |
206 | * significant in SCSI-3. For now, we follow the SCSI-2 | |
207 | * behaviour and ignore reserved bits. | |
208 | */ | |
209 | status &= 0xfe; | |
210 | return ((status == SAM_STAT_GOOD) || | |
211 | (status == SAM_STAT_CONDITION_MET) || | |
212 | /* Next two "intermediate" statuses are obsolete in SAM-4 */ | |
213 | (status == SAM_STAT_INTERMEDIATE) || | |
214 | (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) || | |
215 | /* FIXME: this is obsolete in SAM-3 */ | |
216 | (status == SAM_STAT_COMMAND_TERMINATED)); | |
217 | } | |
218 | ||
1da177e4 | 219 | #endif /* _SCSI_SCSI_H */ |