blob: 3d0372e30ca1d2c6ce6ee2956f22864985e354e2 [file] [log] [blame]
Alex Aizman39e84792005-08-04 19:31:00 -07001/*
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
30enum 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
Or Gerlitz264faaa2006-05-02 19:46:36 -050046 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
Mike Christie01cb2252006-06-28 12:00:22 -050050 ISCSI_UEVENT_TGT_DSCVR = UEVENT_BASE + 15,
Mike Christie1d9bf132007-05-30 12:57:11 -050051 ISCSI_UEVENT_SET_HOST_PARAM = UEVENT_BASE + 16,
Mike Christie01cb2252006-06-28 12:00:22 -050052
Alex Aizman39e84792005-08-04 19:31:00 -070053 /* up events */
54 ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
55 ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
56 ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
Mike Christie53cb8a12006-06-28 12:00:32 -050057 ISCSI_KEVENT_DESTROY_SESSION = KEVENT_BASE + 4,
Alex Aizman39e84792005-08-04 19:31:00 -070058};
59
Mike Christie01cb2252006-06-28 12:00:22 -050060enum iscsi_tgt_dscvr {
61 ISCSI_TGT_DSCVR_SEND_TARGETS = 1,
62 ISCSI_TGT_DSCVR_ISNS = 2,
63 ISCSI_TGT_DSCVR_SLP = 3,
64};
65
Alex Aizman39e84792005-08-04 19:31:00 -070066struct iscsi_uevent {
67 uint32_t type; /* k/u events type */
68 uint32_t iferror; /* carries interface or resource errors */
69 uint64_t transport_handle;
70
71 union {
72 /* messages u -> k */
73 struct msg_create_session {
74 uint32_t initial_cmdsn;
75 } c_session;
76 struct msg_destroy_session {
Alex Aizman39e84792005-08-04 19:31:00 -070077 uint32_t sid;
78 } d_session;
79 struct msg_create_conn {
Alex Aizman39e84792005-08-04 19:31:00 -070080 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -050081 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070082 } c_conn;
83 struct msg_bind_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050084 uint32_t sid;
85 uint32_t cid;
Or Gerlitz264faaa2006-05-02 19:46:36 -050086 uint64_t transport_eph;
Alex Aizman39e84792005-08-04 19:31:00 -070087 uint32_t is_leading;
88 } b_conn;
89 struct msg_destroy_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050090 uint32_t sid;
Alex Aizman39e84792005-08-04 19:31:00 -070091 uint32_t cid;
92 } d_conn;
93 struct msg_send_pdu {
Mike Christieb5c7a122006-04-06 21:13:33 -050094 uint32_t sid;
95 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070096 uint32_t hdr_size;
97 uint32_t data_size;
Alex Aizman39e84792005-08-04 19:31:00 -070098 } send_pdu;
99 struct msg_set_param {
Mike Christieb5c7a122006-04-06 21:13:33 -0500100 uint32_t sid;
101 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700102 uint32_t param; /* enum iscsi_param */
Mike Christiefd7255f2006-04-06 21:13:36 -0500103 uint32_t len;
Alex Aizman39e84792005-08-04 19:31:00 -0700104 } set_param;
105 struct msg_start_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -0500106 uint32_t sid;
107 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700108 } start_conn;
109 struct msg_stop_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -0500110 uint32_t sid;
111 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700112 uint64_t conn_handle;
113 uint32_t flag;
114 } stop_conn;
115 struct msg_get_stats {
Mike Christieb5c7a122006-04-06 21:13:33 -0500116 uint32_t sid;
117 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700118 } get_stats;
Or Gerlitz264faaa2006-05-02 19:46:36 -0500119 struct msg_transport_connect {
120 uint32_t non_blocking;
121 } ep_connect;
122 struct msg_transport_poll {
123 uint64_t ep_handle;
124 uint32_t timeout_ms;
125 } ep_poll;
126 struct msg_transport_disconnect {
127 uint64_t ep_handle;
128 } ep_disconnect;
Mike Christie01cb2252006-06-28 12:00:22 -0500129 struct msg_tgt_dscvr {
130 enum iscsi_tgt_dscvr type;
131 uint32_t host_no;
132 /*
133 * enable = 1 to establish a new connection
134 * with the server. enable = 0 to disconnect
135 * from the server. Used primarily to switch
136 * from one iSNS server to another.
137 */
138 uint32_t enable;
139 } tgt_dscvr;
Mike Christie1d9bf132007-05-30 12:57:11 -0500140 struct msg_set_host_param {
141 uint32_t host_no;
142 uint32_t param; /* enum iscsi_host_param */
143 uint32_t len;
144 } set_host_param;
Alex Aizman39e84792005-08-04 19:31:00 -0700145 } u;
146 union {
147 /* messages k -> u */
Alex Aizman39e84792005-08-04 19:31:00 -0700148 int retcode;
149 struct msg_create_session_ret {
Alex Aizman39e84792005-08-04 19:31:00 -0700150 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -0500151 uint32_t host_no;
Alex Aizman39e84792005-08-04 19:31:00 -0700152 } c_session_ret;
Mike Christieb5c7a122006-04-06 21:13:33 -0500153 struct msg_create_conn_ret {
154 uint32_t sid;
155 uint32_t cid;
156 } c_conn_ret;
Alex Aizman39e84792005-08-04 19:31:00 -0700157 struct msg_recv_req {
Mike Christieb5c7a122006-04-06 21:13:33 -0500158 uint32_t sid;
159 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700160 uint64_t recv_handle;
Alex Aizman39e84792005-08-04 19:31:00 -0700161 } recv_req;
162 struct msg_conn_error {
Mike Christieb5c7a122006-04-06 21:13:33 -0500163 uint32_t sid;
164 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700165 uint32_t error; /* enum iscsi_err */
166 } connerror;
Mike Christie53cb8a12006-06-28 12:00:32 -0500167 struct msg_session_destroyed {
168 uint32_t host_no;
169 uint32_t sid;
170 } d_session;
Or Gerlitz264faaa2006-05-02 19:46:36 -0500171 struct msg_transport_connect_ret {
172 uint64_t handle;
173 } ep_connect_ret;
Alex Aizman39e84792005-08-04 19:31:00 -0700174 } r;
175} __attribute__ ((aligned (sizeof(uint64_t))));
176
177/*
178 * Common error codes
179 */
180enum iscsi_err {
181 ISCSI_OK = 0,
182
183 ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
184 ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
185 ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
186 ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
187 ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
188 ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
189 ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
190 ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
191 ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
192 ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
193 ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
194 ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
195 ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
196 ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
197 ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
Mike Christie7996a772006-04-06 21:13:41 -0500198 ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16,
199 ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17,
Alex Aizman39e84792005-08-04 19:31:00 -0700200};
201
202/*
203 * iSCSI Parameters (RFC3720)
204 */
205enum iscsi_param {
Mike Christiefd7255f2006-04-06 21:13:36 -0500206 /* passed in using netlink set param */
207 ISCSI_PARAM_MAX_RECV_DLENGTH,
208 ISCSI_PARAM_MAX_XMIT_DLENGTH,
209 ISCSI_PARAM_HDRDGST_EN,
210 ISCSI_PARAM_DATADGST_EN,
211 ISCSI_PARAM_INITIAL_R2T_EN,
212 ISCSI_PARAM_MAX_R2T,
213 ISCSI_PARAM_IMM_DATA_EN,
214 ISCSI_PARAM_FIRST_BURST,
215 ISCSI_PARAM_MAX_BURST,
216 ISCSI_PARAM_PDU_INORDER_EN,
217 ISCSI_PARAM_DATASEQ_INORDER_EN,
218 ISCSI_PARAM_ERL,
219 ISCSI_PARAM_IFMARKER_EN,
220 ISCSI_PARAM_OFMARKER_EN,
Mike Christie8d2860b2006-05-02 19:46:47 -0500221 ISCSI_PARAM_EXP_STATSN,
Mike Christiefd7255f2006-04-06 21:13:36 -0500222 ISCSI_PARAM_TARGET_NAME,
223 ISCSI_PARAM_TPGT,
224 ISCSI_PARAM_PERSISTENT_ADDRESS,
225 ISCSI_PARAM_PERSISTENT_PORT,
Mike Christie30a6c652006-04-06 21:13:39 -0500226 ISCSI_PARAM_SESS_RECOVERY_TMO,
Mike Christiefd7255f2006-04-06 21:13:36 -0500227
228 /* pased in through bind conn using transport_fd */
229 ISCSI_PARAM_CONN_PORT,
230 ISCSI_PARAM_CONN_ADDRESS,
231
232 /* must always be last */
233 ISCSI_PARAM_MAX,
Alex Aizman39e84792005-08-04 19:31:00 -0700234};
Mike Christiefd7255f2006-04-06 21:13:36 -0500235
236#define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH)
237#define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH)
238#define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN)
239#define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN)
240#define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN)
241#define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T)
242#define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN)
243#define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST)
244#define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST)
245#define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN)
246#define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN)
247#define ISCSI_ERL (1 << ISCSI_PARAM_ERL)
248#define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN)
249#define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN)
Mike Christie8d2860b2006-05-02 19:46:47 -0500250#define ISCSI_EXP_STATSN (1 << ISCSI_PARAM_EXP_STATSN)
Mike Christiefd7255f2006-04-06 21:13:36 -0500251#define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME)
252#define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT)
253#define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS)
254#define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT)
Mike Christie30a6c652006-04-06 21:13:39 -0500255#define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO)
Mike Christiefd7255f2006-04-06 21:13:36 -0500256#define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT)
257#define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS)
Alex Aizman39e84792005-08-04 19:31:00 -0700258
Mike Christie1819dc82007-05-30 12:57:08 -0500259/* iSCSI HBA params */
260enum iscsi_host_param {
261 ISCSI_HOST_PARAM_HWADDRESS,
262 ISCSI_HOST_PARAM_MAX,
263};
264
265#define ISCSI_HOST_HWADDRESS (1 << ISCSI_HOST_PARAM_HWADDRESS)
266
Alex Aizman39e84792005-08-04 19:31:00 -0700267#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
268#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
Mike Christie7b8631b2006-01-13 18:05:50 -0600269#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
270
271/**
272 * iscsi_hostdata - get LLD hostdata from scsi_host
273 * @_hostdata: pointer to scsi host's hostdata
274 **/
Alex Aizman39e84792005-08-04 19:31:00 -0700275#define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
276
277/*
278 * These flags presents iSCSI Data-Path capabilities.
279 */
280#define CAP_RECOVERY_L0 0x1
281#define CAP_RECOVERY_L1 0x2
282#define CAP_RECOVERY_L2 0x4
283#define CAP_MULTI_R2T 0x8
284#define CAP_HDRDGST 0x10
285#define CAP_DATADGST 0x20
286#define CAP_MULTI_CONN 0x40
287#define CAP_TEXT_NEGO 0x80
288#define CAP_MARKERS 0x100
289
290/*
291 * These flags describes reason of stop_conn() call
292 */
293#define STOP_CONN_TERM 0x1
294#define STOP_CONN_SUSPEND 0x2
295#define STOP_CONN_RECOVER 0x3
296
297#define ISCSI_STATS_CUSTOM_MAX 32
298#define ISCSI_STATS_CUSTOM_DESC_MAX 64
299struct iscsi_stats_custom {
300 char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
301 uint64_t value;
302};
303
304/*
305 * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
306 *
307 * Note: this structure contains counters collected on per-connection basis.
308 */
309struct iscsi_stats {
310 /* octets */
311 uint64_t txdata_octets;
312 uint64_t rxdata_octets;
313
314 /* xmit pdus */
315 uint32_t noptx_pdus;
316 uint32_t scsicmd_pdus;
317 uint32_t tmfcmd_pdus;
318 uint32_t login_pdus;
319 uint32_t text_pdus;
320 uint32_t dataout_pdus;
321 uint32_t logout_pdus;
322 uint32_t snack_pdus;
323
324 /* recv pdus */
325 uint32_t noprx_pdus;
326 uint32_t scsirsp_pdus;
327 uint32_t tmfrsp_pdus;
328 uint32_t textrsp_pdus;
329 uint32_t datain_pdus;
330 uint32_t logoutrsp_pdus;
331 uint32_t r2t_pdus;
332 uint32_t async_pdus;
333 uint32_t rjt_pdus;
334
335 /* errors */
336 uint32_t digest_err;
337 uint32_t timeout_err;
338
339 /*
340 * iSCSI Custom Statistics support, i.e. Transport could
341 * extend existing MIB statistics with its own specific statistics
342 * up to ISCSI_STATS_CUSTOM_MAX
343 */
344 uint32_t custom_length;
345 struct iscsi_stats_custom custom[0]
346 __attribute__ ((aligned (sizeof(uint64_t))));
347};
348
349#endif