4 * Copyright (C) 2004 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5 * Copyright (C) 2007 - 2009 ID7 Ltd.
7 * Contains common SCST constants.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, version 2
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #ifndef __SCST_CONST_H
21 #define __SCST_CONST_H
23 #ifndef GENERATING_UPSTREAM_PATCH
25 * Include <linux/version.h> only when not converting this header file into
26 * a patch for upstream review because only then the symbol LINUX_VERSION_CODE
29 #include <linux/version.h>
31 #include <scsi/scsi.h>
33 #define SCST_CONST_VERSION "$Revision$"
35 /*** Shared constants between user and kernel spaces ***/
38 #define SCST_MAX_CDB_SIZE 16
40 /* Max size of various names */
41 #define SCST_MAX_NAME 50
43 /* Max size of external names, like initiator name */
44 #define SCST_MAX_EXTERNAL_NAME 256
47 * Size of sense sufficient to carry standard sense data.
48 * Warning! It's allocated on stack!
50 #define SCST_STANDARD_SENSE_LEN 18
52 /* Max size of sense */
53 #define SCST_SENSE_BUFFERSIZE 96
55 /*************************************************************
56 ** Allowed delivery statuses for cmd's delivery_status
57 *************************************************************/
59 #define SCST_CMD_DELIVERY_SUCCESS 0
60 #define SCST_CMD_DELIVERY_FAILED -1
61 #define SCST_CMD_DELIVERY_ABORTED -2
63 /*************************************************************
64 ** Values for task management functions
65 *************************************************************/
66 #define SCST_ABORT_TASK 0
67 #define SCST_ABORT_TASK_SET 1
68 #define SCST_CLEAR_ACA 2
69 #define SCST_CLEAR_TASK_SET 3
70 #define SCST_LUN_RESET 4
71 #define SCST_TARGET_RESET 5
73 /** SCST extensions **/
76 * Notifies about I_T nexus loss event in the corresponding session.
77 * Aborts all tasks there, resets the reservation, if any, and sets
78 * up the I_T Nexus loss UA.
80 #define SCST_NEXUS_LOSS_SESS 6
82 /* Aborts all tasks in the corresponding session */
83 #define SCST_ABORT_ALL_TASKS_SESS 7
86 * Notifies about I_T nexus loss event. Aborts all tasks in all sessions
87 * of the tgt, resets the reservations, if any, and sets up the I_T Nexus
90 #define SCST_NEXUS_LOSS 8
92 /* Aborts all tasks in all sessions of the tgt */
93 #define SCST_ABORT_ALL_TASKS 9
96 * Internal TM command issued by SCST in scst_unregister_session(). It is the
97 * same as SCST_NEXUS_LOSS_SESS, except:
98 * - it doesn't call task_mgmt_affected_cmds_done()
99 * - it doesn't call task_mgmt_fn_done()
100 * - it doesn't queue NEXUS LOSS UA.
102 * Target driver shall NEVER use it!!
104 #define SCST_UNREG_SESS_TM 10
106 /*************************************************************
107 ** Values for mgmt cmd's status field. Codes taken from iSCSI
108 *************************************************************/
109 #define SCST_MGMT_STATUS_SUCCESS 0
110 #define SCST_MGMT_STATUS_TASK_NOT_EXIST -1
111 #define SCST_MGMT_STATUS_LUN_NOT_EXIST -2
112 #define SCST_MGMT_STATUS_FN_NOT_SUPPORTED -5
113 #define SCST_MGMT_STATUS_REJECTED -255
114 #define SCST_MGMT_STATUS_FAILED -129
116 /*************************************************************
117 ** SCSI task attribute queue types
118 *************************************************************/
119 enum scst_cmd_queue_type {
120 SCST_CMD_QUEUE_UNTAGGED = 0,
121 SCST_CMD_QUEUE_SIMPLE,
122 SCST_CMD_QUEUE_ORDERED,
123 SCST_CMD_QUEUE_HEAD_OF_QUEUE,
127 /*************************************************************
128 ** Data direction aliases. Changing it don't forget to change
129 ** scst_to_tgt_dma_dir as well!!
130 *************************************************************/
131 #define SCST_DATA_UNKNOWN 0
132 #define SCST_DATA_WRITE 1
133 #define SCST_DATA_READ 2
134 #define SCST_DATA_BIDI (SCST_DATA_WRITE | SCST_DATA_READ)
135 #define SCST_DATA_NONE 4
137 /*************************************************************
138 ** Name of the "Default" security group
139 *************************************************************/
140 #define SCST_DEFAULT_ACG_NAME "Default"
142 /*************************************************************
143 ** Default suffix for targets with NULL names
144 *************************************************************/
145 #define SCST_DEFAULT_TGT_NAME_SUFFIX "_target_"
147 /*************************************************************
148 ** Sense manipulation and examination
149 *************************************************************/
150 #define SCST_LOAD_SENSE(key_asc_ascq) key_asc_ascq
152 #define SCST_SENSE_VALID(sense) ((sense != NULL) && \
153 ((((const uint8_t *)(sense))[0] & 0x70) == 0x70))
155 #define SCST_NO_SENSE(sense) ((sense != NULL) && \
156 (((const uint8_t *)(sense))[2] == 0))
158 /*************************************************************
159 ** Sense data for the appropriate errors. Can be used with
160 ** scst_set_cmd_error()
161 *************************************************************/
162 #define scst_sense_no_sense NO_SENSE, 0x00, 0
163 #define scst_sense_hardw_error HARDWARE_ERROR, 0x44, 0
164 #define scst_sense_aborted_command ABORTED_COMMAND, 0x00, 0
165 #define scst_sense_invalid_opcode ILLEGAL_REQUEST, 0x20, 0
166 #define scst_sense_invalid_field_in_cdb ILLEGAL_REQUEST, 0x24, 0
167 #define scst_sense_invalid_field_in_parm_list ILLEGAL_REQUEST, 0x26, 0
168 #define scst_sense_parameter_value_invalid ILLEGAL_REQUEST, 0x26, 2
169 #define scst_sense_reset_UA UNIT_ATTENTION, 0x29, 0
170 #define scst_sense_nexus_loss_UA UNIT_ATTENTION, 0x29, 0x7
171 #define scst_sense_saving_params_unsup ILLEGAL_REQUEST, 0x39, 0
172 #define scst_sense_lun_not_supported ILLEGAL_REQUEST, 0x25, 0
173 #define scst_sense_data_protect DATA_PROTECT, 0x00, 0
174 #define scst_sense_miscompare_error MISCOMPARE, 0x1D, 0
175 #define scst_sense_block_out_range_error ILLEGAL_REQUEST, 0x21, 0
176 #define scst_sense_medium_changed_UA UNIT_ATTENTION, 0x28, 0
177 #define scst_sense_read_error MEDIUM_ERROR, 0x11, 0
178 #define scst_sense_write_error MEDIUM_ERROR, 0x03, 0
179 #define scst_sense_not_ready NOT_READY, 0x04, 0x10
180 #define scst_sense_invalid_message ILLEGAL_REQUEST, 0x49, 0
181 #define scst_sense_cleared_by_another_ini_UA UNIT_ATTENTION, 0x2F, 0
182 #define scst_sense_capacity_data_changed UNIT_ATTENTION, 0x2A, 0x9
183 #define scst_sense_reported_luns_data_changed UNIT_ATTENTION, 0x3F, 0xE
184 #define scst_sense_inquery_data_changed UNIT_ATTENTION, 0x3F, 0x3
186 /*************************************************************
187 * SCSI opcodes not listed anywhere else
188 *************************************************************/
189 #define REPORT_DEVICE_IDENTIFIER 0xA3
190 #define INIT_ELEMENT_STATUS 0x07
191 #define INIT_ELEMENT_STATUS_RANGE 0x37
192 #define PREVENT_ALLOW_MEDIUM 0x1E
193 #define READ_ATTRIBUTE 0x8C
194 #define REQUEST_VOLUME_ADDRESS 0xB5
195 #define WRITE_ATTRIBUTE 0x8D
196 #define WRITE_VERIFY_16 0x8E
197 #define VERIFY_6 0x13
198 #define VERIFY_12 0xAF
199 #ifndef GENERATING_UPSTREAM_PATCH
201 * The constants below have been defined in the kernel header <scsi/scsi.h>
202 * and hence are not needed when this header file is included in kernel code.
203 * The definitions below are only used when this header file is included during
204 * compilation of SCST's user space components.
210 #define WRITE_16 0x8a
213 #define VERIFY_16 0x8f
215 #ifndef SERVICE_ACTION_IN
216 #define SERVICE_ACTION_IN 0x9e
218 #ifndef SAI_READ_CAPACITY_16
219 /* values for service action in */
220 #define SAI_READ_CAPACITY_16 0x10
223 #ifndef GENERATING_UPSTREAM_PATCH
225 #define REPORT_LUNS 0xa0
229 /*************************************************************
230 ** SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
231 ** T10/1561-D Revision 4 Draft dated 7th November 2002.
232 *************************************************************/
233 #define SAM_STAT_GOOD 0x00
234 #define SAM_STAT_CHECK_CONDITION 0x02
235 #define SAM_STAT_CONDITION_MET 0x04
236 #define SAM_STAT_BUSY 0x08
237 #define SAM_STAT_INTERMEDIATE 0x10
238 #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14
239 #define SAM_STAT_RESERVATION_CONFLICT 0x18
240 #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */
241 #define SAM_STAT_TASK_SET_FULL 0x28
242 #define SAM_STAT_ACA_ACTIVE 0x30
243 #define SAM_STAT_TASK_ABORTED 0x40
245 /*************************************************************
246 ** Control byte field in CDB
247 *************************************************************/
248 #define CONTROL_BYTE_LINK_BIT 0x01
249 #define CONTROL_BYTE_NACA_BIT 0x04
251 /*************************************************************
252 ** Byte 1 in INQUIRY CDB
253 *************************************************************/
254 #define SCST_INQ_EVPD 0x01
256 /*************************************************************
257 ** Byte 3 in Standard INQUIRY data
258 *************************************************************/
259 #define SCST_INQ_BYTE3 3
261 #define SCST_INQ_NORMACA_BIT 0x20
263 /*************************************************************
264 ** Byte 2 in RESERVE_10 CDB
265 *************************************************************/
266 #define SCST_RES_3RDPTY 0x10
267 #define SCST_RES_LONGID 0x02
269 /*************************************************************
270 ** Values for the control mode page TST field
271 *************************************************************/
272 #define SCST_CONTR_MODE_ONE_TASK_SET 0
273 #define SCST_CONTR_MODE_SEP_TASK_SETS 1
275 /*******************************************************************
276 ** Values for the control mode page QUEUE ALGORITHM MODIFIER field
277 *******************************************************************/
278 #define SCST_CONTR_MODE_QUEUE_ALG_RESTRICTED_REORDER 0
279 #define SCST_CONTR_MODE_QUEUE_ALG_UNRESTRICTED_REORDER 1
281 /*************************************************************
282 ** Values for the control mode page D_SENSE field
283 *************************************************************/
284 #define SCST_CONTR_MODE_FIXED_SENSE 0
285 #define SCST_CONTR_MODE_DESCR_SENSE 1
287 /*************************************************************
288 ** Misc SCSI constants
289 *************************************************************/
290 #define SCST_SENSE_ASC_UA_RESET 0x29
291 #define READ_CAP_LEN 8
292 #define READ_CAP16_LEN 32
294 #define POSITION_LEN_SHORT 20
295 #define POSITION_LEN_LONG 32
297 /*************************************************************
299 *************************************************************/
300 #define SCST_DEFAULT_TIMEOUT (60 * HZ)
302 #define SCST_GENERIC_CHANGER_TIMEOUT (3 * HZ)
303 #define SCST_GENERIC_CHANGER_LONG_TIMEOUT (14000 * HZ)
305 #define SCST_GENERIC_PROCESSOR_TIMEOUT (3 * HZ)
306 #define SCST_GENERIC_PROCESSOR_LONG_TIMEOUT (14000 * HZ)
308 #define SCST_GENERIC_TAPE_SMALL_TIMEOUT (3 * HZ)
309 #define SCST_GENERIC_TAPE_REG_TIMEOUT (900 * HZ)
310 #define SCST_GENERIC_TAPE_LONG_TIMEOUT (14000 * HZ)
312 #define SCST_GENERIC_MODISK_SMALL_TIMEOUT (3 * HZ)
313 #define SCST_GENERIC_MODISK_REG_TIMEOUT (900 * HZ)
314 #define SCST_GENERIC_MODISK_LONG_TIMEOUT (14000 * HZ)
316 #define SCST_GENERIC_DISK_SMALL_TIMEOUT (3 * HZ)
317 #define SCST_GENERIC_DISK_REG_TIMEOUT (60 * HZ)
318 #define SCST_GENERIC_DISK_LONG_TIMEOUT (3600 * HZ)
320 #define SCST_GENERIC_RAID_TIMEOUT (3 * HZ)
321 #define SCST_GENERIC_RAID_LONG_TIMEOUT (14000 * HZ)
323 #define SCST_GENERIC_CDROM_SMALL_TIMEOUT (3 * HZ)
324 #define SCST_GENERIC_CDROM_REG_TIMEOUT (900 * HZ)
325 #define SCST_GENERIC_CDROM_LONG_TIMEOUT (14000 * HZ)
327 #define SCST_MAX_OTHER_TIMEOUT (14000 * HZ)
329 /*************************************************************
331 *************************************************************/
332 #define SCST_SYSFS_BLOCK_SIZE PAGE_SIZE
334 #endif /* __SCST_CONST_H */