- Possibility to operate with single size entries as well as control of the reclamat...
[mirror/scst/.git] / scst / include / scst_user.h
1 /*
2  *  include/scst_user.h
3  *
4  *  Copyright (C) 2007 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5  *  Copyright (C) 2007 - 2009 ID7 Ltd.
6  *
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.
10  *
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
14  *  of the License.
15  *
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.
20  */
21
22 #ifndef __SCST_USER_H
23 #define __SCST_USER_H
24
25 #include <scst_const.h>
26
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
32
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
37
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
41
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
47
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
53
54 #ifndef aligned_u64
55 #define aligned_u64 uint64_t __attribute__((aligned(8)))
56 #endif
57
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
69
70 #define UCMD_STATE_ATTACH_SESS          0x20
71 #define UCMD_STATE_DETACH_SESS          0x21
72
73 struct scst_user_opt {
74         uint8_t parse_type;
75         uint8_t on_free_cmd_type;
76         uint8_t memory_reuse_type;
77         uint8_t partial_transfers_type;
78         int32_t partial_len;
79
80         /* SCSI control mode page parameters, see SPC */
81         uint8_t tst;
82         uint8_t queue_alg;
83         uint8_t tas;
84         uint8_t swp;
85         uint8_t d_sense;
86
87         uint8_t has_own_order_mgmt;
88 };
89
90 struct scst_user_dev_desc {
91         aligned_u64 version_str;
92         uint8_t type;
93         uint8_t sgv_shared;
94         int32_t sgv_single_alloc_pages;
95         int32_t sgv_purge_interval;
96         struct scst_user_opt opt;
97         uint32_t block_size;
98         char name[SCST_MAX_NAME];
99         char sgv_name[SCST_MAX_NAME];
100 };
101
102 struct scst_user_sess {
103         aligned_u64 sess_h;
104         aligned_u64 lun;
105         uint16_t threads_num;
106         uint8_t rd_only;
107         char initiator_name[SCST_MAX_NAME];
108         char target_name[SCST_MAX_NAME];
109 };
110
111 struct scst_user_scsi_cmd_parse {
112         aligned_u64 sess_h;
113
114         uint8_t cdb[SCST_MAX_CDB_SIZE];
115         int16_t cdb_len;
116         uint16_t ext_cdb_len;
117
118         int32_t timeout;
119         int32_t bufflen;
120         int32_t in_bufflen;
121
122         uint8_t queue_type;
123         uint8_t data_direction;
124
125         uint8_t expected_values_set;
126         uint8_t expected_data_direction;
127         int32_t expected_transfer_len;
128
129         uint32_t sn;
130 };
131
132 struct scst_user_scsi_cmd_alloc_mem {
133         aligned_u64 sess_h;
134
135         uint8_t cdb[SCST_MAX_CDB_SIZE];
136         int16_t cdb_len;
137         uint16_t ext_cdb_len;
138
139         int32_t alloc_len;
140
141         uint8_t queue_type;
142         uint8_t data_direction;
143
144         uint32_t sn;
145 };
146
147 struct scst_user_scsi_cmd_exec {
148         aligned_u64 sess_h;
149
150         uint8_t cdb[SCST_MAX_CDB_SIZE];
151         int16_t cdb_len;
152         uint16_t ext_cdb_len;
153
154         int32_t data_len;
155         int32_t bufflen;
156         int32_t alloc_len;
157         aligned_u64 pbuf;
158         uint8_t queue_type;
159         uint8_t data_direction;
160         uint8_t partial;
161         int32_t timeout;
162
163         aligned_u64 p_in_buf;
164         int32_t in_bufflen;
165
166         uint32_t sn;
167
168         uint32_t parent_cmd_h;
169         int32_t parent_cmd_data_len;
170         uint32_t partial_offset;
171 };
172
173 struct scst_user_scsi_on_free_cmd {
174         aligned_u64 pbuf;
175         int32_t resp_data_len;
176         uint8_t buffer_cached;
177         uint8_t aborted;
178         uint8_t status;
179         uint8_t delivery_status;
180 };
181
182 struct scst_user_on_cached_mem_free {
183         aligned_u64 pbuf;
184 };
185
186 struct scst_user_tm {
187         aligned_u64 sess_h;
188         uint32_t fn;
189         uint32_t cmd_h_to_abort;
190         uint32_t cmd_sn;
191         uint8_t cmd_sn_set;
192 };
193
194 struct scst_user_get_cmd {
195         uint32_t cmd_h;
196         uint32_t subcode;
197         union {
198                 aligned_u64 preply;
199                 struct scst_user_sess sess;
200                 struct scst_user_scsi_cmd_parse parse_cmd;
201                 struct scst_user_scsi_cmd_alloc_mem alloc_cmd;
202                 struct scst_user_scsi_cmd_exec exec_cmd;
203                 struct scst_user_scsi_on_free_cmd on_free_cmd;
204                 struct scst_user_on_cached_mem_free on_cached_mem_free;
205                 struct scst_user_tm tm_cmd;
206         };
207 };
208
209 /* Be careful adding new members here, this structure is allocated on stack! */
210 struct scst_user_scsi_cmd_reply_parse {
211         uint8_t queue_type;
212         uint8_t data_direction;
213         uint8_t write_medium;
214         int32_t data_len;
215         int32_t bufflen;
216 };
217
218 /* Be careful adding new members here, this structure is allocated on stack! */
219 struct scst_user_scsi_cmd_reply_alloc_mem {
220         aligned_u64 pbuf;
221 };
222
223 /* Be careful adding new members here, this structure is allocated on stack! */
224 struct scst_user_scsi_cmd_reply_exec {
225         int32_t resp_data_len;
226         aligned_u64 pbuf;
227
228 #define SCST_EXEC_REPLY_BACKGROUND      0
229 #define SCST_EXEC_REPLY_COMPLETED       1
230         uint8_t reply_type;
231
232         uint8_t status;
233         uint8_t sense_len;
234         aligned_u64 psense_buffer;
235 };
236
237 /* Be careful adding new members here, this structure is allocated on stack! */
238 struct scst_user_reply_cmd {
239         uint32_t cmd_h;
240         uint32_t subcode;
241         union {
242                 int32_t result;
243                 struct scst_user_scsi_cmd_reply_parse parse_reply;
244                 struct scst_user_scsi_cmd_reply_alloc_mem alloc_reply;
245                 struct scst_user_scsi_cmd_reply_exec exec_reply;
246         };
247 };
248
249 struct scst_user_get_ext_cdb {
250         uint32_t cmd_h;
251         aligned_u64 ext_cdb_buffer;
252 };
253
254 #define SCST_USER_REGISTER_DEVICE       _IOW('u', 1, struct scst_user_dev_desc)
255 #define SCST_USER_UNREGISTER_DEVICE     _IO('u', 2)
256 #define SCST_USER_SET_OPTIONS           _IOW('u', 3, struct scst_user_opt)
257 #define SCST_USER_GET_OPTIONS           _IOR('u', 4, struct scst_user_opt)
258 #define SCST_USER_REPLY_AND_GET_CMD     _IOWR('u', 5, struct scst_user_get_cmd)
259 #define SCST_USER_REPLY_CMD             _IOW('u', 6, struct scst_user_reply_cmd)
260 #define SCST_USER_FLUSH_CACHE           _IO('u', 7)
261 #define SCST_USER_DEVICE_CAPACITY_CHANGED _IO('u', 8)
262 #define SCST_USER_GET_EXTENDED_CDB      _IOWR('u', 9, struct scst_user_get_ext_cdb)
263
264 /* Values for scst_user_get_cmd.subcode */
265 #define SCST_USER_ATTACH_SESS           \
266         _IOR('s', UCMD_STATE_ATTACH_SESS, struct scst_user_sess)
267 #define SCST_USER_DETACH_SESS           \
268         _IOR('s', UCMD_STATE_DETACH_SESS, struct scst_user_sess)
269 #define SCST_USER_PARSE                 \
270         _IOWR('s', UCMD_STATE_PARSING, struct scst_user_scsi_cmd_parse)
271 #define SCST_USER_ALLOC_MEM             \
272         _IOWR('s', UCMD_STATE_BUF_ALLOCING, struct scst_user_scsi_cmd_alloc_mem)
273 #define SCST_USER_EXEC                  \
274         _IOWR('s', UCMD_STATE_EXECING, struct scst_user_scsi_cmd_exec)
275 #define SCST_USER_ON_FREE_CMD           \
276         _IOR('s', UCMD_STATE_ON_FREEING, struct scst_user_scsi_on_free_cmd)
277 #define SCST_USER_ON_CACHED_MEM_FREE            \
278         _IOR('s', UCMD_STATE_ON_CACHE_FREEING,  \
279         struct scst_user_on_cached_mem_free)
280 #define SCST_USER_TASK_MGMT             \
281         _IOWR('s', UCMD_STATE_TM_EXECING, struct scst_user_tm)
282
283 #endif /* __SCST_USER_H */