4 * Copyright (C) 2007 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5 * Copyright (C) 2007 - 2009 ID7 Ltd.
7 * Contains constants and data structures for scst_user module.
8 * See http://scst.sourceforge.net/doc/scst_user_spec.txt or
9 * scst_user_spec.txt for description.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, version 2
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
25 #include <scst_const.h>
27 #define DEV_USER_NAME "scst_user"
28 #define DEV_USER_PATH "/dev/"
29 #define DEV_USER_VERSION_NAME "1.0.2"
30 #define DEV_USER_VERSION \
31 DEV_USER_VERSION_NAME "$Revision$" SCST_CONST_VERSION
33 #define SCST_USER_PARSE_STANDARD 0
34 #define SCST_USER_PARSE_CALL 1
35 #define SCST_USER_PARSE_EXCEPTION 2
36 #define SCST_USER_MAX_PARSE_OPT SCST_USER_PARSE_EXCEPTION
38 #define SCST_USER_ON_FREE_CMD_CALL 0
39 #define SCST_USER_ON_FREE_CMD_IGNORE 1
40 #define SCST_USER_MAX_ON_FREE_CMD_OPT SCST_USER_ON_FREE_CMD_IGNORE
42 #define SCST_USER_MEM_NO_REUSE 0
43 #define SCST_USER_MEM_REUSE_READ 1
44 #define SCST_USER_MEM_REUSE_WRITE 2
45 #define SCST_USER_MEM_REUSE_ALL 3
46 #define SCST_USER_MAX_MEM_REUSE_OPT SCST_USER_MEM_REUSE_ALL
48 #define SCST_USER_PARTIAL_TRANSFERS_NOT_SUPPORTED 0
49 #define SCST_USER_PARTIAL_TRANSFERS_SUPPORTED_ORDERED 1
50 #define SCST_USER_PARTIAL_TRANSFERS_SUPPORTED 2
51 #define SCST_USER_MAX_PARTIAL_TRANSFERS_OPT \
52 SCST_USER_PARTIAL_TRANSFERS_SUPPORTED
55 #define aligned_u64 uint64_t __attribute__((aligned(8)))
58 /*************************************************************
59 ** Private ucmd states
60 *************************************************************/
61 #define UCMD_STATE_NEW 0
62 #define UCMD_STATE_PARSING 1
63 #define UCMD_STATE_BUF_ALLOCING 2
64 #define UCMD_STATE_EXECING 3
65 #define UCMD_STATE_ON_FREEING 4
66 #define UCMD_STATE_ON_FREE_SKIPPED 5
67 #define UCMD_STATE_ON_CACHE_FREEING 6
68 #define UCMD_STATE_TM_EXECING 7
70 #define UCMD_STATE_ATTACH_SESS 0x20
71 #define UCMD_STATE_DETACH_SESS 0x21
73 struct scst_user_opt {
75 uint8_t on_free_cmd_type;
76 uint8_t memory_reuse_type;
77 uint8_t partial_transfers_type;
80 /* SCSI control mode page parameters, see SPC */
87 uint8_t has_own_order_mgmt;
90 struct scst_user_dev_desc {
91 aligned_u64 version_str;
94 struct scst_user_opt opt;
96 char name[SCST_MAX_NAME];
97 char sgv_name[SCST_MAX_NAME];
100 struct scst_user_sess {
103 uint16_t threads_num;
105 char initiator_name[SCST_MAX_NAME];
106 char target_name[SCST_MAX_NAME];
109 struct scst_user_scsi_cmd_parse {
112 uint8_t cdb[SCST_MAX_CDB_SIZE];
114 uint16_t ext_cdb_len;
121 uint8_t data_direction;
123 uint8_t expected_values_set;
124 uint8_t expected_data_direction;
125 int32_t expected_transfer_len;
130 struct scst_user_scsi_cmd_alloc_mem {
133 uint8_t cdb[SCST_MAX_CDB_SIZE];
135 uint16_t ext_cdb_len;
140 uint8_t data_direction;
145 struct scst_user_scsi_cmd_exec {
148 uint8_t cdb[SCST_MAX_CDB_SIZE];
150 uint16_t ext_cdb_len;
157 uint8_t data_direction;
161 aligned_u64 p_in_buf;
166 uint32_t parent_cmd_h;
167 int32_t parent_cmd_data_len;
168 uint32_t partial_offset;
171 struct scst_user_scsi_on_free_cmd {
173 int32_t resp_data_len;
174 uint8_t buffer_cached;
177 uint8_t delivery_status;
180 struct scst_user_on_cached_mem_free {
184 struct scst_user_tm {
187 uint32_t cmd_h_to_abort;
192 struct scst_user_get_cmd {
197 struct scst_user_sess sess;
198 struct scst_user_scsi_cmd_parse parse_cmd;
199 struct scst_user_scsi_cmd_alloc_mem alloc_cmd;
200 struct scst_user_scsi_cmd_exec exec_cmd;
201 struct scst_user_scsi_on_free_cmd on_free_cmd;
202 struct scst_user_on_cached_mem_free on_cached_mem_free;
203 struct scst_user_tm tm_cmd;
207 /* Be careful adding new members here, this structure is allocated on stack! */
208 struct scst_user_scsi_cmd_reply_parse {
210 uint8_t data_direction;
211 uint8_t write_medium;
216 /* Be careful adding new members here, this structure is allocated on stack! */
217 struct scst_user_scsi_cmd_reply_alloc_mem {
221 /* Be careful adding new members here, this structure is allocated on stack! */
222 struct scst_user_scsi_cmd_reply_exec {
223 int32_t resp_data_len;
226 #define SCST_EXEC_REPLY_BACKGROUND 0
227 #define SCST_EXEC_REPLY_COMPLETED 1
232 aligned_u64 psense_buffer;
235 /* Be careful adding new members here, this structure is allocated on stack! */
236 struct scst_user_reply_cmd {
241 struct scst_user_scsi_cmd_reply_parse parse_reply;
242 struct scst_user_scsi_cmd_reply_alloc_mem alloc_reply;
243 struct scst_user_scsi_cmd_reply_exec exec_reply;
247 struct scst_user_get_ext_cdb {
249 aligned_u64 ext_cdb_buffer;
252 #define SCST_USER_REGISTER_DEVICE _IOW('u', 1, struct scst_user_dev_desc)
253 #define SCST_USER_UNREGISTER_DEVICE _IO('u', 2)
254 #define SCST_USER_SET_OPTIONS _IOW('u', 3, struct scst_user_opt)
255 #define SCST_USER_GET_OPTIONS _IOR('u', 4, struct scst_user_opt)
256 #define SCST_USER_REPLY_AND_GET_CMD _IOWR('u', 5, struct scst_user_get_cmd)
257 #define SCST_USER_REPLY_CMD _IOW('u', 6, struct scst_user_reply_cmd)
258 #define SCST_USER_FLUSH_CACHE _IO('u', 7)
259 #define SCST_USER_DEVICE_CAPACITY_CHANGED _IO('u', 8)
260 #define SCST_USER_GET_EXTENDED_CDB _IOWR('u', 9, struct scst_user_get_ext_cdb)
262 /* Values for scst_user_get_cmd.subcode */
263 #define SCST_USER_ATTACH_SESS \
264 _IOR('s', UCMD_STATE_ATTACH_SESS, struct scst_user_sess)
265 #define SCST_USER_DETACH_SESS \
266 _IOR('s', UCMD_STATE_DETACH_SESS, struct scst_user_sess)
267 #define SCST_USER_PARSE \
268 _IOWR('s', UCMD_STATE_PARSING, struct scst_user_scsi_cmd_parse)
269 #define SCST_USER_ALLOC_MEM \
270 _IOWR('s', UCMD_STATE_BUF_ALLOCING, struct scst_user_scsi_cmd_alloc_mem)
271 #define SCST_USER_EXEC \
272 _IOWR('s', UCMD_STATE_EXECING, struct scst_user_scsi_cmd_exec)
273 #define SCST_USER_ON_FREE_CMD \
274 _IOR('s', UCMD_STATE_ON_FREEING, struct scst_user_scsi_on_free_cmd)
275 #define SCST_USER_ON_CACHED_MEM_FREE \
276 _IOR('s', UCMD_STATE_ON_CACHE_FREEING, \
277 struct scst_user_on_cached_mem_free)
278 #define SCST_USER_TASK_MGMT \
279 _IOWR('s', UCMD_STATE_TM_EXECING, struct scst_user_tm)
281 #endif /* __SCST_USER_H */