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