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