blob: 931b49458d17ef2f147771cbf985fc46bc6ff327 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This header file contains public constants and structures used by
Bart Van Asschec5f1ac82015-05-08 10:07:18 +02003 * the SCSI initiator code.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5#ifndef _SCSI_SCSI_H
6#define _SCSI_SCSI_H
7
8#include <linux/types.h>
David Dillowac61c462011-01-16 15:12:39 -05009#include <linux/scatterlist.h>
Martin K. Petersen0816c922013-05-10 10:36:04 -040010#include <linux/kernel.h>
Bart Van Assche07e38422015-05-08 10:07:48 +020011#include <scsi/scsi_common.h>
Bart Van Asschec5f1ac82015-05-08 10:07:18 +020012#include <scsi/scsi_proto.h>
James Bottomleyf290f192009-02-08 21:59:48 -060013
14struct scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Martin K. Petersen0816c922013-05-10 10:36:04 -040016enum scsi_timeouts {
17 SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ,
18};
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
Martin K. Petersen13f05c82010-09-10 20:50:10 +020021 * DIX-capable adapters effectively support infinite chaining for the
22 * protection information scatterlist
23 */
24#define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF
25
26/*
Christoph Hellwige02f3f52006-01-13 19:04:00 +010027 * Special value for scanning to specify scanning or rescanning of all
28 * possible channels, (target) ids, or luns on a given shost.
29 */
30#define SCAN_WILD_CARD ~0
31
Holger Machtde50ada2012-06-25 16:13:02 +080032#ifdef CONFIG_ACPI
33struct acpi_bus_type;
34
35extern int
36scsi_register_acpi_bus_type(struct acpi_bus_type *bus);
37
38extern void
39scsi_unregister_acpi_bus_type(struct acpi_bus_type *bus);
40#endif
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/** scsi_status_is_good - check the status return.
43 *
44 * @status: the status passed up from the driver (including host and
45 * driver components)
46 *
47 * This returns true for known good conditions that may be treated as
48 * command completed normally
49 */
50static inline int scsi_status_is_good(int status)
51{
52 /*
53 * FIXME: bit0 is listed as reserved in SCSI-2, but is
54 * significant in SCSI-3. For now, we follow the SCSI-2
55 * behaviour and ignore reserved bits.
56 */
57 status &= 0xfe;
58 return ((status == SAM_STAT_GOOD) ||
59 (status == SAM_STAT_INTERMEDIATE) ||
60 (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
61 /* FIXME: this is obsolete in SAM-3 */
62 (status == SAM_STAT_COMMAND_TERMINATED));
63}
64
Matthew Wilcox4ff36712006-07-04 12:15:20 -060065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/*
67 * standard mode-select header prepended to all mode-select commands
68 */
69
70struct ccs_modesel_head {
71 __u8 _r1; /* reserved */
72 __u8 medium; /* device-specific medium type */
73 __u8 _r2; /* reserved */
74 __u8 block_desc_length; /* block descriptor length */
75 __u8 density; /* device-specific density code */
76 __u8 number_blocks_hi; /* number of blocks in this block desc */
77 __u8 number_blocks_med;
78 __u8 number_blocks_lo;
79 __u8 _r3;
80 __u8 block_length_hi; /* block length for blocks in this desc */
81 __u8 block_length_med;
82 __u8 block_length_lo;
83};
84
85/*
James Bottomley01b291b2008-08-21 15:14:14 -050086 * The Well Known LUNS (SAM-3) in our int representation of a LUN
87 */
88#define SCSI_W_LUN_BASE 0xc100
89#define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
90#define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
91#define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
92
Hannes Reinecke9cb78c12014-06-25 15:27:36 +020093static inline int scsi_is_wlun(u64 lun)
James Bottomley01b291b2008-08-21 15:14:14 -050094{
95 return (lun & 0xff00) == SCSI_W_LUN_BASE;
96}
97
98
99/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 * MESSAGE CODES
101 */
102
103#define COMMAND_COMPLETE 0x00
104#define EXTENDED_MESSAGE 0x01
105#define EXTENDED_MODIFY_DATA_POINTER 0x00
106#define EXTENDED_SDTR 0x01
107#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
108#define EXTENDED_WDTR 0x03
109#define EXTENDED_PPR 0x04
110#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
111#define SAVE_POINTERS 0x02
112#define RESTORE_POINTERS 0x03
113#define DISCONNECT 0x04
114#define INITIATOR_ERROR 0x05
115#define ABORT_TASK_SET 0x06
116#define MESSAGE_REJECT 0x07
117#define NOP 0x08
118#define MSG_PARITY_ERROR 0x09
119#define LINKED_CMD_COMPLETE 0x0a
120#define LINKED_FLG_CMD_COMPLETE 0x0b
121#define TARGET_RESET 0x0c
122#define ABORT_TASK 0x0d
123#define CLEAR_TASK_SET 0x0e
124#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
125#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
126#define CLEAR_ACA 0x16
127#define LOGICAL_UNIT_RESET 0x17
128#define SIMPLE_QUEUE_TAG 0x20
129#define HEAD_OF_QUEUE_TAG 0x21
130#define ORDERED_QUEUE_TAG 0x22
131#define IGNORE_WIDE_RESIDUE 0x23
132#define ACA 0x24
133#define QAS_REQUEST 0x55
134
135/* Old SCSI2 names, don't use in new code */
136#define BUS_DEVICE_RESET TARGET_RESET
137#define ABORT ABORT_TASK_SET
138
139/*
140 * Host byte codes
141 */
142
143#define DID_OK 0x00 /* NO error */
144#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
145#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
146#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
147#define DID_BAD_TARGET 0x04 /* BAD target. */
148#define DID_ABORT 0x05 /* Told to abort for some other reason */
149#define DID_PARITY 0x06 /* Parity error */
150#define DID_ERROR 0x07 /* Internal error */
151#define DID_RESET 0x08 /* Reset by somebody. */
152#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
153#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
154#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
155#define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */
bf341912005-04-12 17:49:09 -0500156#define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also
157 * without decrementing the retry count */
Mike Christiea4dfaa62008-08-19 18:45:25 -0500158#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution
159 * and the driver blocked the port to
160 * recover the link. Transport class will
161 * retry or fail IO */
162#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */
Hannes Reinecke63583cc2011-01-18 10:13:11 +0100163#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
164 * other paths */
165#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other
166 * paths might yield different results */
Hannes Reineckea9d6ceb82013-07-01 15:16:25 +0200167#define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */
Hannes Reinecke7e782af2013-07-01 15:16:26 +0200168#define DID_MEDIUM_ERROR 0x13 /* Medium error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#define DRIVER_OK 0x00 /* Driver status */
170
171/*
172 * These indicate the error that occurred, and what is available.
173 */
174
175#define DRIVER_BUSY 0x01
176#define DRIVER_SOFT 0x02
177#define DRIVER_MEDIA 0x03
178#define DRIVER_ERROR 0x04
179
180#define DRIVER_INVALID 0x05
181#define DRIVER_TIMEOUT 0x06
182#define DRIVER_HARD 0x07
183#define DRIVER_SENSE 0x08
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/*
186 * Internal return values.
187 */
188
189#define NEEDS_RETRY 0x2001
190#define SUCCESS 0x2002
191#define FAILED 0x2003
192#define QUEUED 0x2004
193#define SOFT_ERROR 0x2005
194#define ADD_TO_MLQUEUE 0x2006
195#define TIMEOUT_ERROR 0x2007
Chandra Seetharamana6a8d9f2008-05-01 14:49:46 -0700196#define SCSI_RETURN_NOT_HANDLED 0x2008
Christof Schmitt2f2eb582010-03-24 16:50:30 +0100197#define FAST_IO_FAIL 0x2009
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199/*
200 * Midlevel queue return values.
201 */
202#define SCSI_MLQUEUE_HOST_BUSY 0x1055
203#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
204#define SCSI_MLQUEUE_EH_RETRY 0x1057
Mike Christief0c0a372008-08-17 15:24:38 -0500205#define SCSI_MLQUEUE_TARGET_BUSY 0x1058
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207/*
208 * Use these to separate status msg and our bytes
209 *
210 * These are set by:
211 *
212 * status byte = set from target device
213 * msg_byte = return status from host adapter itself.
214 * host_byte = set by low-level driver to indicate status.
215 * driver_byte = set by mid-level.
216 */
217#define status_byte(result) (((result) >> 1) & 0x7f)
218#define msg_byte(result) (((result) >> 8) & 0xff)
219#define host_byte(result) (((result) >> 16) & 0xff)
220#define driver_byte(result) (((result) >> 24) & 0xff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222#define sense_class(sense) (((sense) >> 4) & 0x7)
223#define sense_error(sense) ((sense) & 0xf)
Phil Carmody497888c2011-07-14 15:07:13 +0300224#define sense_valid(sense) ((sense) & 0x80)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
b6651122005-04-03 14:52:44 -0500226/*
227 * default timeouts
228*/
229#define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ)
230#define START_STOP_TIMEOUT (60 * HZ)
231#define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ)
232#define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)
233#define READ_DEFECT_DATA_TIMEOUT (60 * HZ )
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236#define IDENTIFY_BASE 0x80
237#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
238 ((can_disconnect) ? 0x40 : 0) |\
239 ((lun) & 0x07))
240
241/*
242 * struct scsi_device::scsi_level values. For SCSI devices other than those
243 * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
244 * where "resp" is a byte array of the response to an INQUIRY. The scsi_level
245 * variable is visible to the user via sysfs.
246 */
247
248#define SCSI_UNKNOWN 0
249#define SCSI_1 1
250#define SCSI_1_CCS 2
251#define SCSI_2 3
252#define SCSI_3 4 /* SPC */
253#define SCSI_SPC_2 5
254#define SCSI_SPC_3 6
255
256/*
257 * INQ PERIPHERAL QUALIFIERS
258 */
259#define SCSI_INQ_PQ_CON 0x00
260#define SCSI_INQ_PQ_NOT_CON 0x01
261#define SCSI_INQ_PQ_NOT_CAP 0x03
262
James Bottomley2908d772006-08-29 09:22:51 -0500263/* Pull a u32 out of a SCSI message (using BE SCSI conventions) */
FUJITA Tomonori4a531e82006-10-20 09:08:18 +0900264static inline __u32 scsi_to_u32(__u8 *ptr)
James Bottomley2908d772006-08-29 09:22:51 -0500265{
266 return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#endif /* _SCSI_SCSI_H */