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