OSDN Git Service

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