Commit | Line | Data |
---|---|---|
39e84790 AA |
1 | /* |
2 | * iSCSI User/Kernel Shares (Defines, Constants, Protocol definitions, etc) | |
3 | * | |
4 | * Copyright (C) 2005 Dmitry Yusupov | |
5 | * Copyright (C) 2005 Alex Aizman | |
6 | * maintained by open-iscsi@googlegroups.com | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published | |
10 | * by the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * See the file COPYING included with this distribution for more details. | |
19 | */ | |
20 | ||
21 | #ifndef ISCSI_IF_H | |
22 | #define ISCSI_IF_H | |
23 | ||
24 | #include <scsi/iscsi_proto.h> | |
25 | ||
26 | #define UEVENT_BASE 10 | |
27 | #define KEVENT_BASE 100 | |
28 | #define ISCSI_ERR_BASE 1000 | |
29 | ||
30 | enum iscsi_uevent_e { | |
31 | ISCSI_UEVENT_UNKNOWN = 0, | |
32 | ||
33 | /* down events */ | |
34 | ISCSI_UEVENT_CREATE_SESSION = UEVENT_BASE + 1, | |
35 | ISCSI_UEVENT_DESTROY_SESSION = UEVENT_BASE + 2, | |
36 | ISCSI_UEVENT_CREATE_CONN = UEVENT_BASE + 3, | |
37 | ISCSI_UEVENT_DESTROY_CONN = UEVENT_BASE + 4, | |
38 | ISCSI_UEVENT_BIND_CONN = UEVENT_BASE + 5, | |
39 | ISCSI_UEVENT_SET_PARAM = UEVENT_BASE + 6, | |
40 | ISCSI_UEVENT_START_CONN = UEVENT_BASE + 7, | |
41 | ISCSI_UEVENT_STOP_CONN = UEVENT_BASE + 8, | |
42 | ISCSI_UEVENT_SEND_PDU = UEVENT_BASE + 9, | |
43 | ISCSI_UEVENT_GET_STATS = UEVENT_BASE + 10, | |
44 | ISCSI_UEVENT_GET_PARAM = UEVENT_BASE + 11, | |
45 | ||
264faaaa OG |
46 | ISCSI_UEVENT_TRANSPORT_EP_CONNECT = UEVENT_BASE + 12, |
47 | ISCSI_UEVENT_TRANSPORT_EP_POLL = UEVENT_BASE + 13, | |
48 | ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT = UEVENT_BASE + 14, | |
49 | ||
01cb225d | 50 | ISCSI_UEVENT_TGT_DSCVR = UEVENT_BASE + 15, |
1d9bf13a | 51 | ISCSI_UEVENT_SET_HOST_PARAM = UEVENT_BASE + 16, |
26974789 | 52 | ISCSI_UEVENT_UNBIND_SESSION = UEVENT_BASE + 17, |
01cb225d | 53 | |
39e84790 AA |
54 | /* up events */ |
55 | ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1, | |
56 | ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2, | |
57 | ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3, | |
53cb8a1f | 58 | ISCSI_KEVENT_DESTROY_SESSION = KEVENT_BASE + 4, |
26974789 MC |
59 | ISCSI_KEVENT_UNBIND_SESSION = KEVENT_BASE + 5, |
60 | ISCSI_KEVENT_CREATE_SESSION = KEVENT_BASE + 6, | |
39e84790 AA |
61 | }; |
62 | ||
01cb225d MC |
63 | enum iscsi_tgt_dscvr { |
64 | ISCSI_TGT_DSCVR_SEND_TARGETS = 1, | |
65 | ISCSI_TGT_DSCVR_ISNS = 2, | |
66 | ISCSI_TGT_DSCVR_SLP = 3, | |
67 | }; | |
68 | ||
39e84790 AA |
69 | struct iscsi_uevent { |
70 | uint32_t type; /* k/u events type */ | |
71 | uint32_t iferror; /* carries interface or resource errors */ | |
72 | uint64_t transport_handle; | |
73 | ||
74 | union { | |
75 | /* messages u -> k */ | |
76 | struct msg_create_session { | |
77 | uint32_t initial_cmdsn; | |
1548271e MC |
78 | uint16_t cmds_max; |
79 | uint16_t queue_depth; | |
39e84790 AA |
80 | } c_session; |
81 | struct msg_destroy_session { | |
39e84790 AA |
82 | uint32_t sid; |
83 | } d_session; | |
84 | struct msg_create_conn { | |
39e84790 | 85 | uint32_t sid; |
b5c7a12d | 86 | uint32_t cid; |
39e84790 AA |
87 | } c_conn; |
88 | struct msg_bind_conn { | |
b5c7a12d MC |
89 | uint32_t sid; |
90 | uint32_t cid; | |
264faaaa | 91 | uint64_t transport_eph; |
39e84790 AA |
92 | uint32_t is_leading; |
93 | } b_conn; | |
94 | struct msg_destroy_conn { | |
b5c7a12d | 95 | uint32_t sid; |
39e84790 AA |
96 | uint32_t cid; |
97 | } d_conn; | |
98 | struct msg_send_pdu { | |
b5c7a12d MC |
99 | uint32_t sid; |
100 | uint32_t cid; | |
39e84790 AA |
101 | uint32_t hdr_size; |
102 | uint32_t data_size; | |
39e84790 AA |
103 | } send_pdu; |
104 | struct msg_set_param { | |
b5c7a12d MC |
105 | uint32_t sid; |
106 | uint32_t cid; | |
39e84790 | 107 | uint32_t param; /* enum iscsi_param */ |
fd7255f5 | 108 | uint32_t len; |
39e84790 AA |
109 | } set_param; |
110 | struct msg_start_conn { | |
b5c7a12d MC |
111 | uint32_t sid; |
112 | uint32_t cid; | |
39e84790 AA |
113 | } start_conn; |
114 | struct msg_stop_conn { | |
b5c7a12d MC |
115 | uint32_t sid; |
116 | uint32_t cid; | |
39e84790 AA |
117 | uint64_t conn_handle; |
118 | uint32_t flag; | |
119 | } stop_conn; | |
120 | struct msg_get_stats { | |
b5c7a12d MC |
121 | uint32_t sid; |
122 | uint32_t cid; | |
39e84790 | 123 | } get_stats; |
264faaaa OG |
124 | struct msg_transport_connect { |
125 | uint32_t non_blocking; | |
126 | } ep_connect; | |
127 | struct msg_transport_poll { | |
128 | uint64_t ep_handle; | |
129 | uint32_t timeout_ms; | |
130 | } ep_poll; | |
131 | struct msg_transport_disconnect { | |
132 | uint64_t ep_handle; | |
133 | } ep_disconnect; | |
01cb225d MC |
134 | struct msg_tgt_dscvr { |
135 | enum iscsi_tgt_dscvr type; | |
136 | uint32_t host_no; | |
137 | /* | |
138 | * enable = 1 to establish a new connection | |
139 | * with the server. enable = 0 to disconnect | |
140 | * from the server. Used primarily to switch | |
141 | * from one iSNS server to another. | |
142 | */ | |
143 | uint32_t enable; | |
144 | } tgt_dscvr; | |
1d9bf13a MC |
145 | struct msg_set_host_param { |
146 | uint32_t host_no; | |
147 | uint32_t param; /* enum iscsi_host_param */ | |
148 | uint32_t len; | |
149 | } set_host_param; | |
39e84790 AA |
150 | } u; |
151 | union { | |
152 | /* messages k -> u */ | |
39e84790 AA |
153 | int retcode; |
154 | struct msg_create_session_ret { | |
39e84790 | 155 | uint32_t sid; |
b5c7a12d | 156 | uint32_t host_no; |
39e84790 | 157 | } c_session_ret; |
b5c7a12d MC |
158 | struct msg_create_conn_ret { |
159 | uint32_t sid; | |
160 | uint32_t cid; | |
161 | } c_conn_ret; | |
26974789 MC |
162 | struct msg_unbind_session { |
163 | uint32_t sid; | |
164 | uint32_t host_no; | |
165 | } unbind_session; | |
39e84790 | 166 | struct msg_recv_req { |
b5c7a12d MC |
167 | uint32_t sid; |
168 | uint32_t cid; | |
39e84790 | 169 | uint64_t recv_handle; |
39e84790 AA |
170 | } recv_req; |
171 | struct msg_conn_error { | |
b5c7a12d MC |
172 | uint32_t sid; |
173 | uint32_t cid; | |
39e84790 AA |
174 | uint32_t error; /* enum iscsi_err */ |
175 | } connerror; | |
53cb8a1f MC |
176 | struct msg_session_destroyed { |
177 | uint32_t host_no; | |
178 | uint32_t sid; | |
179 | } d_session; | |
264faaaa OG |
180 | struct msg_transport_connect_ret { |
181 | uint64_t handle; | |
182 | } ep_connect_ret; | |
39e84790 AA |
183 | } r; |
184 | } __attribute__ ((aligned (sizeof(uint64_t)))); | |
185 | ||
186 | /* | |
187 | * Common error codes | |
188 | */ | |
189 | enum iscsi_err { | |
190 | ISCSI_OK = 0, | |
191 | ||
192 | ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1, | |
193 | ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2, | |
194 | ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3, | |
195 | ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4, | |
196 | ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5, | |
197 | ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6, | |
198 | ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7, | |
199 | ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8, | |
200 | ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9, | |
201 | ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10, | |
202 | ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11, | |
203 | ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12, | |
204 | ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13, | |
205 | ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14, | |
206 | ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15, | |
7996a778 MC |
207 | ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16, |
208 | ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17, | |
39e84790 AA |
209 | }; |
210 | ||
211 | /* | |
212 | * iSCSI Parameters (RFC3720) | |
213 | */ | |
214 | enum iscsi_param { | |
fd7255f5 MC |
215 | /* passed in using netlink set param */ |
216 | ISCSI_PARAM_MAX_RECV_DLENGTH, | |
217 | ISCSI_PARAM_MAX_XMIT_DLENGTH, | |
218 | ISCSI_PARAM_HDRDGST_EN, | |
219 | ISCSI_PARAM_DATADGST_EN, | |
220 | ISCSI_PARAM_INITIAL_R2T_EN, | |
221 | ISCSI_PARAM_MAX_R2T, | |
222 | ISCSI_PARAM_IMM_DATA_EN, | |
223 | ISCSI_PARAM_FIRST_BURST, | |
224 | ISCSI_PARAM_MAX_BURST, | |
225 | ISCSI_PARAM_PDU_INORDER_EN, | |
226 | ISCSI_PARAM_DATASEQ_INORDER_EN, | |
227 | ISCSI_PARAM_ERL, | |
228 | ISCSI_PARAM_IFMARKER_EN, | |
229 | ISCSI_PARAM_OFMARKER_EN, | |
8d2860b3 | 230 | ISCSI_PARAM_EXP_STATSN, |
fd7255f5 MC |
231 | ISCSI_PARAM_TARGET_NAME, |
232 | ISCSI_PARAM_TPGT, | |
233 | ISCSI_PARAM_PERSISTENT_ADDRESS, | |
234 | ISCSI_PARAM_PERSISTENT_PORT, | |
30a6c652 | 235 | ISCSI_PARAM_SESS_RECOVERY_TMO, |
fd7255f5 MC |
236 | |
237 | /* pased in through bind conn using transport_fd */ | |
238 | ISCSI_PARAM_CONN_PORT, | |
239 | ISCSI_PARAM_CONN_ADDRESS, | |
240 | ||
b2c64167 MC |
241 | ISCSI_PARAM_USERNAME, |
242 | ISCSI_PARAM_USERNAME_IN, | |
243 | ISCSI_PARAM_PASSWORD, | |
244 | ISCSI_PARAM_PASSWORD_IN, | |
245 | ||
843c0a8a | 246 | ISCSI_PARAM_FAST_ABORT, |
f6d5180c MC |
247 | ISCSI_PARAM_ABORT_TMO, |
248 | ISCSI_PARAM_LU_RESET_TMO, | |
249 | ISCSI_PARAM_HOST_RESET_TMO, | |
250 | ||
251 | ISCSI_PARAM_PING_TMO, | |
252 | ISCSI_PARAM_RECV_TMO, | |
fd7255f5 MC |
253 | /* must always be last */ |
254 | ISCSI_PARAM_MAX, | |
39e84790 | 255 | }; |
fd7255f5 MC |
256 | |
257 | #define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH) | |
258 | #define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH) | |
259 | #define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN) | |
260 | #define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN) | |
261 | #define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN) | |
262 | #define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T) | |
263 | #define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN) | |
264 | #define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST) | |
265 | #define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST) | |
266 | #define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN) | |
267 | #define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN) | |
268 | #define ISCSI_ERL (1 << ISCSI_PARAM_ERL) | |
269 | #define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN) | |
270 | #define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN) | |
8d2860b3 | 271 | #define ISCSI_EXP_STATSN (1 << ISCSI_PARAM_EXP_STATSN) |
fd7255f5 MC |
272 | #define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME) |
273 | #define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT) | |
274 | #define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS) | |
275 | #define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT) | |
30a6c652 | 276 | #define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO) |
fd7255f5 MC |
277 | #define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT) |
278 | #define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS) | |
b2c64167 MC |
279 | #define ISCSI_USERNAME (1 << ISCSI_PARAM_USERNAME) |
280 | #define ISCSI_USERNAME_IN (1 << ISCSI_PARAM_USERNAME_IN) | |
281 | #define ISCSI_PASSWORD (1 << ISCSI_PARAM_PASSWORD) | |
282 | #define ISCSI_PASSWORD_IN (1 << ISCSI_PARAM_PASSWORD_IN) | |
843c0a8a | 283 | #define ISCSI_FAST_ABORT (1 << ISCSI_PARAM_FAST_ABORT) |
f6d5180c MC |
284 | #define ISCSI_ABORT_TMO (1 << ISCSI_PARAM_ABORT_TMO) |
285 | #define ISCSI_LU_RESET_TMO (1 << ISCSI_PARAM_LU_RESET_TMO) | |
286 | #define ISCSI_HOST_RESET_TMO (1 << ISCSI_PARAM_HOST_RESET_TMO) | |
287 | #define ISCSI_PING_TMO (1 << ISCSI_PARAM_PING_TMO) | |
288 | #define ISCSI_RECV_TMO (1 << ISCSI_PARAM_RECV_TMO) | |
39e84790 | 289 | |
1819dc81 MC |
290 | /* iSCSI HBA params */ |
291 | enum iscsi_host_param { | |
292 | ISCSI_HOST_PARAM_HWADDRESS, | |
8ad5781a | 293 | ISCSI_HOST_PARAM_INITIATOR_NAME, |
d8196ed2 | 294 | ISCSI_HOST_PARAM_NETDEV_NAME, |
22236961 | 295 | ISCSI_HOST_PARAM_IPADDRESS, |
1819dc81 MC |
296 | ISCSI_HOST_PARAM_MAX, |
297 | }; | |
298 | ||
299 | #define ISCSI_HOST_HWADDRESS (1 << ISCSI_HOST_PARAM_HWADDRESS) | |
8ad5781a | 300 | #define ISCSI_HOST_INITIATOR_NAME (1 << ISCSI_HOST_PARAM_INITIATOR_NAME) |
d8196ed2 | 301 | #define ISCSI_HOST_NETDEV_NAME (1 << ISCSI_HOST_PARAM_NETDEV_NAME) |
22236961 | 302 | #define ISCSI_HOST_IPADDRESS (1 << ISCSI_HOST_PARAM_IPADDRESS) |
1819dc81 | 303 | |
39e84790 AA |
304 | #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle) |
305 | #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr) | |
7b8631b5 MC |
306 | #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata)) |
307 | ||
308 | /** | |
309 | * iscsi_hostdata - get LLD hostdata from scsi_host | |
310 | * @_hostdata: pointer to scsi host's hostdata | |
311 | **/ | |
39e84790 AA |
312 | #define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long)) |
313 | ||
314 | /* | |
315 | * These flags presents iSCSI Data-Path capabilities. | |
316 | */ | |
317 | #define CAP_RECOVERY_L0 0x1 | |
318 | #define CAP_RECOVERY_L1 0x2 | |
319 | #define CAP_RECOVERY_L2 0x4 | |
320 | #define CAP_MULTI_R2T 0x8 | |
321 | #define CAP_HDRDGST 0x10 | |
322 | #define CAP_DATADGST 0x20 | |
323 | #define CAP_MULTI_CONN 0x40 | |
324 | #define CAP_TEXT_NEGO 0x80 | |
325 | #define CAP_MARKERS 0x100 | |
0ab823db MC |
326 | #define CAP_FW_DB 0x200 |
327 | #define CAP_SENDTARGETS_OFFLOAD 0x400 | |
d8196ed2 | 328 | #define CAP_DATA_PATH_OFFLOAD 0x800 |
39e84790 AA |
329 | |
330 | /* | |
331 | * These flags describes reason of stop_conn() call | |
332 | */ | |
333 | #define STOP_CONN_TERM 0x1 | |
334 | #define STOP_CONN_SUSPEND 0x2 | |
335 | #define STOP_CONN_RECOVER 0x3 | |
336 | ||
337 | #define ISCSI_STATS_CUSTOM_MAX 32 | |
338 | #define ISCSI_STATS_CUSTOM_DESC_MAX 64 | |
339 | struct iscsi_stats_custom { | |
340 | char desc[ISCSI_STATS_CUSTOM_DESC_MAX]; | |
341 | uint64_t value; | |
342 | }; | |
343 | ||
344 | /* | |
345 | * struct iscsi_stats - iSCSI Statistics (iSCSI MIB) | |
346 | * | |
347 | * Note: this structure contains counters collected on per-connection basis. | |
348 | */ | |
349 | struct iscsi_stats { | |
350 | /* octets */ | |
351 | uint64_t txdata_octets; | |
352 | uint64_t rxdata_octets; | |
353 | ||
354 | /* xmit pdus */ | |
355 | uint32_t noptx_pdus; | |
356 | uint32_t scsicmd_pdus; | |
357 | uint32_t tmfcmd_pdus; | |
358 | uint32_t login_pdus; | |
359 | uint32_t text_pdus; | |
360 | uint32_t dataout_pdus; | |
361 | uint32_t logout_pdus; | |
362 | uint32_t snack_pdus; | |
363 | ||
364 | /* recv pdus */ | |
365 | uint32_t noprx_pdus; | |
366 | uint32_t scsirsp_pdus; | |
367 | uint32_t tmfrsp_pdus; | |
368 | uint32_t textrsp_pdus; | |
369 | uint32_t datain_pdus; | |
370 | uint32_t logoutrsp_pdus; | |
371 | uint32_t r2t_pdus; | |
372 | uint32_t async_pdus; | |
373 | uint32_t rjt_pdus; | |
374 | ||
375 | /* errors */ | |
376 | uint32_t digest_err; | |
377 | uint32_t timeout_err; | |
378 | ||
379 | /* | |
380 | * iSCSI Custom Statistics support, i.e. Transport could | |
381 | * extend existing MIB statistics with its own specific statistics | |
382 | * up to ISCSI_STATS_CUSTOM_MAX | |
383 | */ | |
384 | uint32_t custom_length; | |
385 | struct iscsi_stats_custom custom[0] | |
386 | __attribute__ ((aligned (sizeof(uint64_t)))); | |
387 | }; | |
388 | ||
389 | #endif |