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