blob: 8813f0f4c624467eff6751622b8941c5b9c2569b [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,
51
Alex Aizman39e84792005-08-04 19:31:00 -070052 /* up events */
53 ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
54 ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
55 ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
56};
57
Mike Christie01cb2252006-06-28 12:00:22 -050058enum iscsi_tgt_dscvr {
59 ISCSI_TGT_DSCVR_SEND_TARGETS = 1,
60 ISCSI_TGT_DSCVR_ISNS = 2,
61 ISCSI_TGT_DSCVR_SLP = 3,
62};
63
Alex Aizman39e84792005-08-04 19:31:00 -070064struct iscsi_uevent {
65 uint32_t type; /* k/u events type */
66 uint32_t iferror; /* carries interface or resource errors */
67 uint64_t transport_handle;
68
69 union {
70 /* messages u -> k */
71 struct msg_create_session {
72 uint32_t initial_cmdsn;
73 } c_session;
74 struct msg_destroy_session {
Alex Aizman39e84792005-08-04 19:31:00 -070075 uint32_t sid;
76 } d_session;
77 struct msg_create_conn {
Alex Aizman39e84792005-08-04 19:31:00 -070078 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -050079 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070080 } c_conn;
81 struct msg_bind_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050082 uint32_t sid;
83 uint32_t cid;
Or Gerlitz264faaa2006-05-02 19:46:36 -050084 uint64_t transport_eph;
Alex Aizman39e84792005-08-04 19:31:00 -070085 uint32_t is_leading;
86 } b_conn;
87 struct msg_destroy_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050088 uint32_t sid;
Alex Aizman39e84792005-08-04 19:31:00 -070089 uint32_t cid;
90 } d_conn;
91 struct msg_send_pdu {
Mike Christieb5c7a122006-04-06 21:13:33 -050092 uint32_t sid;
93 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070094 uint32_t hdr_size;
95 uint32_t data_size;
Alex Aizman39e84792005-08-04 19:31:00 -070096 } send_pdu;
97 struct msg_set_param {
Mike Christieb5c7a122006-04-06 21:13:33 -050098 uint32_t sid;
99 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700100 uint32_t param; /* enum iscsi_param */
Mike Christiefd7255f2006-04-06 21:13:36 -0500101 uint32_t len;
Alex Aizman39e84792005-08-04 19:31:00 -0700102 } set_param;
103 struct msg_start_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -0500104 uint32_t sid;
105 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700106 } start_conn;
107 struct msg_stop_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -0500108 uint32_t sid;
109 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700110 uint64_t conn_handle;
111 uint32_t flag;
112 } stop_conn;
113 struct msg_get_stats {
Mike Christieb5c7a122006-04-06 21:13:33 -0500114 uint32_t sid;
115 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700116 } get_stats;
Or Gerlitz264faaa2006-05-02 19:46:36 -0500117 struct msg_transport_connect {
118 uint32_t non_blocking;
119 } ep_connect;
120 struct msg_transport_poll {
121 uint64_t ep_handle;
122 uint32_t timeout_ms;
123 } ep_poll;
124 struct msg_transport_disconnect {
125 uint64_t ep_handle;
126 } ep_disconnect;
Mike Christie01cb2252006-06-28 12:00:22 -0500127 struct msg_tgt_dscvr {
128 enum iscsi_tgt_dscvr type;
129 uint32_t host_no;
130 /*
131 * enable = 1 to establish a new connection
132 * with the server. enable = 0 to disconnect
133 * from the server. Used primarily to switch
134 * from one iSNS server to another.
135 */
136 uint32_t enable;
137 } tgt_dscvr;
Alex Aizman39e84792005-08-04 19:31:00 -0700138 } u;
139 union {
140 /* messages k -> u */
Alex Aizman39e84792005-08-04 19:31:00 -0700141 int retcode;
142 struct msg_create_session_ret {
Alex Aizman39e84792005-08-04 19:31:00 -0700143 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -0500144 uint32_t host_no;
Alex Aizman39e84792005-08-04 19:31:00 -0700145 } c_session_ret;
Mike Christieb5c7a122006-04-06 21:13:33 -0500146 struct msg_create_conn_ret {
147 uint32_t sid;
148 uint32_t cid;
149 } c_conn_ret;
Alex Aizman39e84792005-08-04 19:31:00 -0700150 struct msg_recv_req {
Mike Christieb5c7a122006-04-06 21:13:33 -0500151 uint32_t sid;
152 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700153 uint64_t recv_handle;
Alex Aizman39e84792005-08-04 19:31:00 -0700154 } recv_req;
155 struct msg_conn_error {
Mike Christieb5c7a122006-04-06 21:13:33 -0500156 uint32_t sid;
157 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700158 uint32_t error; /* enum iscsi_err */
159 } connerror;
Or Gerlitz264faaa2006-05-02 19:46:36 -0500160 struct msg_transport_connect_ret {
161 uint64_t handle;
162 } ep_connect_ret;
Mike Christie01cb2252006-06-28 12:00:22 -0500163 struct msg_tgt_dscvr_ret {
164 /*
165 * session/connection pair used to reference
166 * the connection to server
167 */
168 uint32_t sid;
169 uint32_t cid;
170 union {
171 struct isns {
172 /* port # for conn to iSNS server */
173 uint16_t isns_port;
174 /* listening port to receive SCNs */
175 uint16_t scn_port;
176 /* listening port to receive ESIs */
177 uint16_t esi_port;
178 } isns_attrib;
179 } u;
180 } tgt_dscvr_ret;
Alex Aizman39e84792005-08-04 19:31:00 -0700181 } r;
182} __attribute__ ((aligned (sizeof(uint64_t))));
183
184/*
185 * Common error codes
186 */
187enum iscsi_err {
188 ISCSI_OK = 0,
189
190 ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
191 ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
192 ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
193 ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
194 ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
195 ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
196 ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
197 ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
198 ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
199 ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
200 ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
201 ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
202 ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
203 ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
204 ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
Mike Christie7996a772006-04-06 21:13:41 -0500205 ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16,
206 ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17,
Alex Aizman39e84792005-08-04 19:31:00 -0700207};
208
209/*
210 * iSCSI Parameters (RFC3720)
211 */
212enum iscsi_param {
Mike Christiefd7255f2006-04-06 21:13:36 -0500213 /* passed in using netlink set param */
214 ISCSI_PARAM_MAX_RECV_DLENGTH,
215 ISCSI_PARAM_MAX_XMIT_DLENGTH,
216 ISCSI_PARAM_HDRDGST_EN,
217 ISCSI_PARAM_DATADGST_EN,
218 ISCSI_PARAM_INITIAL_R2T_EN,
219 ISCSI_PARAM_MAX_R2T,
220 ISCSI_PARAM_IMM_DATA_EN,
221 ISCSI_PARAM_FIRST_BURST,
222 ISCSI_PARAM_MAX_BURST,
223 ISCSI_PARAM_PDU_INORDER_EN,
224 ISCSI_PARAM_DATASEQ_INORDER_EN,
225 ISCSI_PARAM_ERL,
226 ISCSI_PARAM_IFMARKER_EN,
227 ISCSI_PARAM_OFMARKER_EN,
Mike Christie8d2860b2006-05-02 19:46:47 -0500228 ISCSI_PARAM_EXP_STATSN,
Mike Christiefd7255f2006-04-06 21:13:36 -0500229 ISCSI_PARAM_TARGET_NAME,
230 ISCSI_PARAM_TPGT,
231 ISCSI_PARAM_PERSISTENT_ADDRESS,
232 ISCSI_PARAM_PERSISTENT_PORT,
Mike Christie30a6c652006-04-06 21:13:39 -0500233 ISCSI_PARAM_SESS_RECOVERY_TMO,
Mike Christiefd7255f2006-04-06 21:13:36 -0500234
235 /* pased in through bind conn using transport_fd */
236 ISCSI_PARAM_CONN_PORT,
237 ISCSI_PARAM_CONN_ADDRESS,
238
239 /* must always be last */
240 ISCSI_PARAM_MAX,
Alex Aizman39e84792005-08-04 19:31:00 -0700241};
Mike Christiefd7255f2006-04-06 21:13:36 -0500242
243#define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH)
244#define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH)
245#define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN)
246#define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN)
247#define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN)
248#define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T)
249#define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN)
250#define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST)
251#define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST)
252#define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN)
253#define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN)
254#define ISCSI_ERL (1 << ISCSI_PARAM_ERL)
255#define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN)
256#define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN)
Mike Christie8d2860b2006-05-02 19:46:47 -0500257#define ISCSI_EXP_STATSN (1 << ISCSI_PARAM_EXP_STATSN)
Mike Christiefd7255f2006-04-06 21:13:36 -0500258#define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME)
259#define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT)
260#define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS)
261#define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT)
Mike Christie30a6c652006-04-06 21:13:39 -0500262#define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO)
Mike Christiefd7255f2006-04-06 21:13:36 -0500263#define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT)
264#define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS)
Alex Aizman39e84792005-08-04 19:31:00 -0700265
Alex Aizman39e84792005-08-04 19:31:00 -0700266#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
267#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
Mike Christie7b8631b2006-01-13 18:05:50 -0600268#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
269
270/**
271 * iscsi_hostdata - get LLD hostdata from scsi_host
272 * @_hostdata: pointer to scsi host's hostdata
273 **/
Alex Aizman39e84792005-08-04 19:31:00 -0700274#define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
275
276/*
277 * These flags presents iSCSI Data-Path capabilities.
278 */
279#define CAP_RECOVERY_L0 0x1
280#define CAP_RECOVERY_L1 0x2
281#define CAP_RECOVERY_L2 0x4
282#define CAP_MULTI_R2T 0x8
283#define CAP_HDRDGST 0x10
284#define CAP_DATADGST 0x20
285#define CAP_MULTI_CONN 0x40
286#define CAP_TEXT_NEGO 0x80
287#define CAP_MARKERS 0x100
288
289/*
290 * These flags describes reason of stop_conn() call
291 */
292#define STOP_CONN_TERM 0x1
293#define STOP_CONN_SUSPEND 0x2
294#define STOP_CONN_RECOVER 0x3
295
296#define ISCSI_STATS_CUSTOM_MAX 32
297#define ISCSI_STATS_CUSTOM_DESC_MAX 64
298struct iscsi_stats_custom {
299 char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
300 uint64_t value;
301};
302
303/*
304 * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
305 *
306 * Note: this structure contains counters collected on per-connection basis.
307 */
308struct iscsi_stats {
309 /* octets */
310 uint64_t txdata_octets;
311 uint64_t rxdata_octets;
312
313 /* xmit pdus */
314 uint32_t noptx_pdus;
315 uint32_t scsicmd_pdus;
316 uint32_t tmfcmd_pdus;
317 uint32_t login_pdus;
318 uint32_t text_pdus;
319 uint32_t dataout_pdus;
320 uint32_t logout_pdus;
321 uint32_t snack_pdus;
322
323 /* recv pdus */
324 uint32_t noprx_pdus;
325 uint32_t scsirsp_pdus;
326 uint32_t tmfrsp_pdus;
327 uint32_t textrsp_pdus;
328 uint32_t datain_pdus;
329 uint32_t logoutrsp_pdus;
330 uint32_t r2t_pdus;
331 uint32_t async_pdus;
332 uint32_t rjt_pdus;
333
334 /* errors */
335 uint32_t digest_err;
336 uint32_t timeout_err;
337
338 /*
339 * iSCSI Custom Statistics support, i.e. Transport could
340 * extend existing MIB statistics with its own specific statistics
341 * up to ISCSI_STATS_CUSTOM_MAX
342 */
343 uint32_t custom_length;
344 struct iscsi_stats_custom custom[0]
345 __attribute__ ((aligned (sizeof(uint64_t))));
346};
347
348#endif