- Update to the latest IET r145
[mirror/scst/.git] / scst / include / scst_user.h
1 /*
2  *  include/scst_user.h
3  *  
4  *  Copyright (C) 2007 Vladislav Bolkhovitin <vst@vlnb.net>
5  *  
6  *  Contains constants and data structures for scst_user module.
7  *  See http://scst.sourceforge.net/doc/scst_user_spec.txt or
8  *  scst_user_spec.txt for description.
9  * 
10  *  This program is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU General Public License
12  *  as published by the Free Software Foundation, version 2
13  *  of the License.
14  * 
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  *  GNU General Public License for more details.
19  */
20
21 #ifndef __SCST_USER_H
22 #define __SCST_USER_H
23
24 #include <scst_const.h>
25
26 #define DEV_USER_NAME                   "scst_user"
27 #define DEV_USER_PATH                   "/dev/"
28 #define DEV_USER_VERSION                963
29
30 /* 
31  * Chosen so sizeof(scst_user_sess) <= sizeof(scst_user_scsi_cmd_exec) 
32  * (the largest one)
33  */
34 #define SCST_MAX_NAME                   45
35
36 #define SCST_USER_PARSE_STANDARD        0
37 #define SCST_USER_PARSE_CALL            1
38 #define SCST_USER_PARSE_EXCEPTION       2
39 #define SCST_USER_MAX_PARSE_OPT         SCST_USER_PARSE_EXCEPTION
40
41 #define SCST_USER_ON_FREE_CMD_CALL      0
42 #define SCST_USER_ON_FREE_CMD_IGNORE    1
43 #define SCST_USER_MAX_ON_FREE_CMD_OPT   SCST_USER_ON_FREE_CMD_IGNORE
44
45 #define SCST_USER_MEM_NO_REUSE          0
46 #define SCST_USER_MEM_REUSE_READ        1
47 #define SCST_USER_MEM_REUSE_WRITE       2
48 #define SCST_USER_MEM_REUSE_ALL         3
49 #define SCST_USER_MAX_MEM_REUSE_OPT     SCST_USER_MEM_REUSE_ALL
50
51 #define SCST_USER_PRIO_QUEUE_SINGLE     0
52 #define SCST_USER_PRIO_QUEUE_SEPARATE   1
53 #define SCST_USER_MAX_PRIO_QUEUE_OPT    SCST_USER_PRIO_QUEUE_SEPARATE
54
55 #define SCST_USER_PARTIAL_TRANSFERS_NOT_SUPPORTED       0
56 #define SCST_USER_PARTIAL_TRANSFERS_SUPPORTED_ORDERED   1
57 #define SCST_USER_PARTIAL_TRANSFERS_SUPPORTED           2
58 #define SCST_USER_MAX_PARTIAL_TRANSFERS_OPT             SCST_USER_PARTIAL_TRANSFERS_SUPPORTED
59
60 #ifndef aligned_u64
61 #define aligned_u64 uint64_t __attribute__((aligned(8)))
62 #endif
63
64 /************************************************************* 
65  ** Private ucmd states
66  *************************************************************/
67 #define UCMD_STATE_NEW                  0
68 #define UCMD_STATE_PARSING              1
69 #define UCMD_STATE_BUF_ALLOCING         2
70 #define UCMD_STATE_EXECING              3
71 #define UCMD_STATE_ON_FREEING           4
72 #define UCMD_STATE_ON_FREE_SKIPPED      5
73 #define UCMD_STATE_ON_CACHE_FREEING     6
74 #define UCMD_STATE_TM_EXECING           7
75
76 #define UCMD_STATE_ATTACH_SESS          0x20
77 #define UCMD_STATE_DETACH_SESS          0x21
78
79 /* Must be changed under cmd_lists.cmd_list_lock */
80 #define UCMD_STATE_SENT_MASK            0x10000
81 #define UCMD_STATE_RECV_MASK            0x20000
82 #define UCMD_STATE_JAMMED_MASK          0x40000
83
84 #define UCMD_STATE_MASK                 (UCMD_STATE_SENT_MASK | \
85                                          UCMD_STATE_RECV_MASK | \
86                                          UCMD_STATE_JAMMED_MASK)
87
88 struct scst_user_opt
89 {
90         uint8_t parse_type;
91         uint8_t on_free_cmd_type;
92         uint8_t memory_reuse_type;
93         uint8_t prio_queue_type;
94         uint8_t partial_transfers_type;
95         int32_t partial_len;
96
97         /* SCSI control mode page parameters, see SPC */
98         uint8_t tst;
99         uint8_t queue_alg;
100         uint8_t tas;
101         uint8_t swp;
102
103         uint8_t has_own_order_mgmt;
104 };
105
106 struct scst_user_dev_desc
107 {
108         uint32_t version;
109         uint8_t type;
110         struct scst_user_opt opt;
111         uint32_t block_size;
112         char name[SCST_MAX_NAME];
113 };
114
115 struct scst_user_sess
116 {
117         aligned_u64 sess_h;
118         aligned_u64 lun;
119         uint16_t threads_num;
120         uint8_t rd_only;
121         char initiator_name[SCST_MAX_NAME];
122 };
123
124 struct scst_user_scsi_cmd_parse
125 {
126         aligned_u64 sess_h;
127
128         uint8_t cdb[SCST_MAX_CDB_SIZE];
129         int32_t cdb_len;
130
131         uint32_t timeout;
132         int32_t bufflen;
133
134         uint8_t queue_type;
135         uint8_t data_direction;
136
137         uint8_t expected_values_set;
138         uint8_t expected_data_direction;
139         int32_t expected_transfer_len;
140
141         uint32_t sn;
142 };
143
144 struct scst_user_scsi_cmd_alloc_mem
145 {
146         aligned_u64 sess_h;
147
148         uint8_t cdb[SCST_MAX_CDB_SIZE];
149         int32_t cdb_len;
150
151         int32_t alloc_len;
152
153         uint8_t queue_type;
154         uint8_t data_direction;
155
156         uint32_t sn;
157 };
158
159 struct scst_user_scsi_cmd_exec
160 {
161         aligned_u64 sess_h;
162
163         uint8_t cdb[SCST_MAX_CDB_SIZE];
164         int32_t cdb_len;
165
166         int32_t data_len;
167         int32_t bufflen;
168         int32_t alloc_len;
169         aligned_u64 pbuf;
170         uint8_t queue_type;
171         uint8_t data_direction;
172         uint8_t partial;
173         uint32_t timeout;
174
175         uint32_t sn;
176
177         uint32_t parent_cmd_h;
178         int32_t parent_cmd_data_len;
179         uint32_t partial_offset;
180 };
181
182 struct scst_user_scsi_on_free_cmd
183 {
184         aligned_u64 pbuf;
185         int32_t resp_data_len;
186         uint8_t buffer_cached;
187         uint8_t aborted;
188         uint8_t status;
189         uint8_t delivery_status;
190 };
191
192 struct scst_user_on_cached_mem_free
193 {
194         aligned_u64 pbuf;
195 };
196
197 struct scst_user_tm
198 {
199         aligned_u64 sess_h;
200         uint32_t fn;
201         uint32_t cmd_h_to_abort;
202         uint32_t cmd_sn;
203         uint8_t cmd_sn_set;
204 };
205
206 struct scst_user_get_cmd
207 {
208         aligned_u64 preply;
209         uint32_t cmd_h;
210         uint32_t subcode;
211         union {
212                 struct scst_user_sess sess;
213                 struct scst_user_scsi_cmd_parse parse_cmd;
214                 struct scst_user_scsi_cmd_alloc_mem alloc_cmd;
215                 struct scst_user_scsi_cmd_exec exec_cmd;
216                 struct scst_user_scsi_on_free_cmd on_free_cmd;
217                 struct scst_user_on_cached_mem_free on_cached_mem_free;
218                 struct scst_user_tm tm_cmd;
219         };
220 };
221
222 struct scst_user_scsi_cmd_reply_parse
223 {
224         uint8_t queue_type;
225         uint8_t data_direction;
226         int32_t data_len;
227         int32_t bufflen;
228 };
229
230 struct scst_user_scsi_cmd_reply_alloc_mem
231 {
232         aligned_u64 pbuf;
233 };
234
235 struct scst_user_scsi_cmd_reply_exec
236 {
237         int32_t resp_data_len;
238         aligned_u64 pbuf;
239
240 #define SCST_EXEC_REPLY_BACKGROUND      0
241 #define SCST_EXEC_REPLY_COMPLETED       1
242         uint8_t reply_type;
243
244         uint8_t status;
245         uint8_t sense_len;
246         aligned_u64 psense_buffer;
247 };
248
249 struct scst_user_reply_cmd
250 {
251         uint32_t cmd_h;
252         uint32_t subcode;
253         union {
254                 int32_t result;
255                 struct scst_user_scsi_cmd_reply_parse parse_reply;
256                 struct scst_user_scsi_cmd_reply_alloc_mem alloc_reply;
257                 struct scst_user_scsi_cmd_reply_exec exec_reply;
258         };
259 };
260
261 #define SCST_USER_REGISTER_DEVICE       _IOW('u', 1, struct scst_user_dev_desc)
262 #define SCST_USER_SET_OPTIONS           _IOW('u', 3, struct scst_user_opt)
263 #define SCST_USER_GET_OPTIONS           _IOR('u', 4, struct scst_user_opt)
264 #define SCST_USER_REPLY_AND_GET_CMD     _IOWR('u', 5, struct scst_user_get_cmd)
265 #define SCST_USER_REPLY_AND_GET_PRIO_CMD _IOWR('u', 6, struct scst_user_get_cmd)
266 #define SCST_USER_REPLY_CMD             _IOW('u', 7, struct scst_user_reply_cmd)
267
268 /* Values for scst_user_get_cmd.subcode */
269 #define SCST_USER_ATTACH_SESS           _IOR('s', UCMD_STATE_ATTACH_SESS, struct scst_user_sess)
270 #define SCST_USER_DETACH_SESS           _IOR('s', UCMD_STATE_DETACH_SESS, struct scst_user_sess)
271 #define SCST_USER_PARSE                 _IOWR('s', UCMD_STATE_PARSING, struct scst_user_scsi_cmd_parse)
272 #define SCST_USER_ALLOC_MEM             _IOWR('s', UCMD_STATE_BUF_ALLOCING, struct scst_user_scsi_cmd_alloc_mem)
273 #define SCST_USER_EXEC                  _IOWR('s', UCMD_STATE_EXECING, struct scst_user_scsi_cmd_exec)
274 #define SCST_USER_ON_FREE_CMD           _IOR('s', UCMD_STATE_ON_FREEING, struct scst_user_scsi_on_free_cmd)
275 #define SCST_USER_ON_CACHED_MEM_FREE    _IOR('s', UCMD_STATE_ON_CACHE_FREEING, struct scst_user_on_cached_mem_free)
276 #define SCST_USER_TASK_MGMT             _IOWR('s', UCMD_STATE_TM_EXECING, struct scst_user_tm)
277
278 #endif /* __SCST_USER_H */