xref: /aosp_15_r20/external/kernel-headers/modified/scsi/scsi.h (revision f80ad8b4341604f5951dab671d41019a6d7087ce)
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 
11 #include <asm/param.h>
12 
13 #ifdef __KERNEL__
14 #include <scsi/scsi_common.h>
15 #endif /* __KERNEL__ */
16 #include <scsi/scsi_proto.h>
17 #include <scsi/scsi_status.h>
18 
19 #ifdef __KERNEL__
20 struct scsi_cmnd;
21 
22 enum scsi_timeouts {
23 	SCSI_DEFAULT_EH_TIMEOUT		= 10 * HZ,
24 };
25 
26 /*
27  * DIX-capable adapters effectively support infinite chaining for the
28  * protection information scatterlist
29  */
30 #define SCSI_MAX_PROT_SG_SEGMENTS	0xFFFF
31 
32 /*
33  * Special value for scanning to specify scanning or rescanning of all
34  * possible channels, (target) ids, or luns on a given shost.
35  */
36 #define SCAN_WILD_CARD	~0
37 #endif /* __KERNEL__ */
38 
39 /*
40  * standard mode-select header prepended to all mode-select commands
41  */
42 
43 struct ccs_modesel_head {
44 	__u8 _r1;			/* reserved */
45 	__u8 medium;		/* device-specific medium type */
46 	__u8 _r2;			/* reserved */
47 	__u8 block_desc_length;	/* block descriptor length */
48 	__u8 density;		/* device-specific density code */
49 	__u8 number_blocks_hi;	/* number of blocks in this block desc */
50 	__u8 number_blocks_med;
51 	__u8 number_blocks_lo;
52 	__u8 _r3;
53 	__u8 block_length_hi;	/* block length for blocks in this desc */
54 	__u8 block_length_med;
55 	__u8 block_length_lo;
56 };
57 
58 #ifdef __KERNEL__
59 /*
60  * The Well Known LUNS (SAM-3) in our int representation of a LUN
61  */
62 #define SCSI_W_LUN_BASE 0xc100
63 #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
64 #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
65 #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
66 
scsi_is_wlun(u64 lun)67 static inline int scsi_is_wlun(u64 lun)
68 {
69 	return (lun & 0xff00) == SCSI_W_LUN_BASE;
70 }
71 
72 /**
73  * scsi_status_is_check_condition - check the status return.
74  *
75  * @status: the status passed up from the driver (including host and
76  *          driver components)
77  *
78  * Returns: %true if the status code is SAM_STAT_CHECK_CONDITION.
79  */
scsi_status_is_check_condition(int status)80 static inline int scsi_status_is_check_condition(int status)
81 {
82 	if (status < 0)
83 		return false;
84 	status &= 0xfe;
85 	return status == SAM_STAT_CHECK_CONDITION;
86 }
87 #endif /* __KERNEL__ */
88 
89 /*
90  *  Extended message codes.
91  */
92 
93 #define     EXTENDED_MODIFY_DATA_POINTER    0x00
94 #define     EXTENDED_SDTR                   0x01
95 #define     EXTENDED_EXTENDED_IDENTIFY      0x02    /* SCSI-I only */
96 #define     EXTENDED_WDTR                   0x03
97 #define     EXTENDED_PPR                    0x04
98 #define     EXTENDED_MODIFY_BIDI_DATA_PTR   0x05
99 
100 #ifdef __KERNEL__
101 /*
102  * Internal return values.
103  */
104 enum scsi_disposition {
105 	NEEDS_RETRY		= 0x2001,
106 	SUCCESS			= 0x2002,
107 	FAILED			= 0x2003,
108 	QUEUED			= 0x2004,
109 	SOFT_ERROR		= 0x2005,
110 	ADD_TO_MLQUEUE		= 0x2006,
111 	TIMEOUT_ERROR		= 0x2007,
112 	SCSI_RETURN_NOT_HANDLED	= 0x2008,
113 	FAST_IO_FAIL		= 0x2009,
114 };
115 
116 /*
117  * Midlevel queue return values.
118  */
119 #define SCSI_MLQUEUE_HOST_BUSY   0x1055
120 #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
121 #define SCSI_MLQUEUE_EH_RETRY    0x1057
122 #define SCSI_MLQUEUE_TARGET_BUSY 0x1058
123 
124 /*
125  *  Use these to separate status msg and our bytes
126  *
127  *  These are set by:
128  *
129  *      status byte = set from target device
130  *      msg_byte    (unused)
131  *      host_byte   = set by low-level driver to indicate status.
132  */
133 #define status_byte(result) (result & 0xff)
134 #define host_byte(result)   (((result) >> 16) & 0xff)
135 
136 #define sense_class(sense)  (((sense) >> 4) & 0x7)
137 #define sense_error(sense)  ((sense) & 0xf)
138 #define sense_valid(sense)  ((sense) & 0x80)
139 
140 /*
141  * default timeouts
142 */
143 #define FORMAT_UNIT_TIMEOUT		(2 * 60 * 60 * HZ)
144 #define START_STOP_TIMEOUT		(60 * HZ)
145 #define MOVE_MEDIUM_TIMEOUT		(5 * 60 * HZ)
146 #define READ_ELEMENT_STATUS_TIMEOUT	(5 * 60 * HZ)
147 #define READ_DEFECT_DATA_TIMEOUT	(60 * HZ )
148 
149 
150 #define IDENTIFY_BASE       0x80
151 #define IDENTIFY(can_disconnect, lun)   (IDENTIFY_BASE |\
152 		     ((can_disconnect) ?  0x40 : 0) |\
153 		     ((lun) & 0x07))
154 
155 /*
156  *  struct scsi_device::scsi_level values. For SCSI devices other than those
157  *  prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
158  *  where "resp" is a byte array of the response to an INQUIRY. The scsi_level
159  *  variable is visible to the user via sysfs.
160  */
161 
162 #define SCSI_UNKNOWN    0
163 #define SCSI_1          1
164 #define SCSI_1_CCS      2
165 #define SCSI_2          3
166 #define SCSI_3          4        /* SPC */
167 #define SCSI_SPC_2      5
168 #define SCSI_SPC_3      6
169 #define SCSI_SPC_4	7
170 #define SCSI_SPC_5	8
171 #define SCSI_SPC_6	14
172 
173 /*
174  * INQ PERIPHERAL QUALIFIERS
175  */
176 #define SCSI_INQ_PQ_CON         0x00
177 #define SCSI_INQ_PQ_NOT_CON     0x01
178 #define SCSI_INQ_PQ_NOT_CAP     0x03
179 #endif /* __KERNEL__ */
180 
181 
182 /*
183  * Here are some scsi specific ioctl commands which are sometimes useful.
184  *
185  * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
186  */
187 
188 /* Used to obtain PUN and LUN info.  Conflicts with CDROMAUDIOBUFSIZ */
189 #define SCSI_IOCTL_GET_IDLUN		0x5382
190 
191 /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
192 
193 /* Used to obtain the host number of a device. */
194 #define SCSI_IOCTL_PROBE_HOST		0x5385
195 
196 /* Used to obtain the bus number for a device */
197 #define SCSI_IOCTL_GET_BUS_NUMBER	0x5386
198 
199 /* Used to obtain the PCI location of a device */
200 #define SCSI_IOCTL_GET_PCI		0x5387
201 
202 /**
203  * scsi_status_is_good - check the status return.
204  *
205  * @status: the status passed up from the driver (including host and
206  *          driver components)
207  *
208  * Returns: %true for known good conditions that may be treated as
209  * command completed normally
210  */
scsi_status_is_good(int status)211 static inline bool scsi_status_is_good(int status)
212 {
213 	if (status < 0)
214 		return false;
215 
216 	if (host_byte(status) == DID_NO_CONNECT)
217 		return false;
218 
219 	/*
220 	 * FIXME: bit0 is listed as reserved in SCSI-2, but is
221 	 * significant in SCSI-3.  For now, we follow the SCSI-2
222 	 * behaviour and ignore reserved bits.
223 	 */
224 	status &= 0xfe;
225 	return ((status == SAM_STAT_GOOD) ||
226 		(status == SAM_STAT_CONDITION_MET) ||
227 		/* Next two "intermediate" statuses are obsolete in SAM-4 */
228 		(status == SAM_STAT_INTERMEDIATE) ||
229 		(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
230 		/* FIXME: this is obsolete in SAM-3 */
231 		(status == SAM_STAT_COMMAND_TERMINATED));
232 }
233 
234 #endif /* _SCSI_SCSI_H */
235