blob: 47524c726ee8c96e6c61fc413038eb5acecaf7f5 [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
46 /* up events */
47 ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
48 ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
49 ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
50};
51
52struct iscsi_uevent {
53 uint32_t type; /* k/u events type */
54 uint32_t iferror; /* carries interface or resource errors */
55 uint64_t transport_handle;
56
57 union {
58 /* messages u -> k */
59 struct msg_create_session {
60 uint32_t initial_cmdsn;
61 } c_session;
62 struct msg_destroy_session {
Alex Aizman39e84792005-08-04 19:31:00 -070063 uint32_t sid;
64 } d_session;
65 struct msg_create_conn {
Alex Aizman39e84792005-08-04 19:31:00 -070066 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -050067 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070068 } c_conn;
69 struct msg_bind_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050070 uint32_t sid;
71 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070072 uint32_t transport_fd;
73 uint32_t is_leading;
74 } b_conn;
75 struct msg_destroy_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050076 uint32_t sid;
Alex Aizman39e84792005-08-04 19:31:00 -070077 uint32_t cid;
78 } d_conn;
79 struct msg_send_pdu {
Mike Christieb5c7a122006-04-06 21:13:33 -050080 uint32_t sid;
81 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070082 uint32_t hdr_size;
83 uint32_t data_size;
Alex Aizman39e84792005-08-04 19:31:00 -070084 } send_pdu;
85 struct msg_set_param {
Mike Christieb5c7a122006-04-06 21:13:33 -050086 uint32_t sid;
87 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070088 uint32_t param; /* enum iscsi_param */
Mike Christiefd7255f2006-04-06 21:13:36 -050089 uint32_t len;
Alex Aizman39e84792005-08-04 19:31:00 -070090 } set_param;
91 struct msg_start_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050092 uint32_t sid;
93 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070094 } start_conn;
95 struct msg_stop_conn {
Mike Christieb5c7a122006-04-06 21:13:33 -050096 uint32_t sid;
97 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -070098 uint64_t conn_handle;
99 uint32_t flag;
100 } stop_conn;
101 struct msg_get_stats {
Mike Christieb5c7a122006-04-06 21:13:33 -0500102 uint32_t sid;
103 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700104 } get_stats;
105 } u;
106 union {
107 /* messages k -> u */
Alex Aizman39e84792005-08-04 19:31:00 -0700108 int retcode;
109 struct msg_create_session_ret {
Alex Aizman39e84792005-08-04 19:31:00 -0700110 uint32_t sid;
Mike Christieb5c7a122006-04-06 21:13:33 -0500111 uint32_t host_no;
Alex Aizman39e84792005-08-04 19:31:00 -0700112 } c_session_ret;
Mike Christieb5c7a122006-04-06 21:13:33 -0500113 struct msg_create_conn_ret {
114 uint32_t sid;
115 uint32_t cid;
116 } c_conn_ret;
Alex Aizman39e84792005-08-04 19:31:00 -0700117 struct msg_recv_req {
Mike Christieb5c7a122006-04-06 21:13:33 -0500118 uint32_t sid;
119 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700120 uint64_t recv_handle;
Alex Aizman39e84792005-08-04 19:31:00 -0700121 } recv_req;
122 struct msg_conn_error {
Mike Christieb5c7a122006-04-06 21:13:33 -0500123 uint32_t sid;
124 uint32_t cid;
Alex Aizman39e84792005-08-04 19:31:00 -0700125 uint32_t error; /* enum iscsi_err */
126 } connerror;
127 } r;
128} __attribute__ ((aligned (sizeof(uint64_t))));
129
130/*
131 * Common error codes
132 */
133enum iscsi_err {
134 ISCSI_OK = 0,
135
136 ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
137 ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
138 ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
139 ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
140 ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
141 ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
142 ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
143 ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
144 ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
145 ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
146 ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
147 ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
148 ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
149 ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
150 ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
Mike Christie7996a772006-04-06 21:13:41 -0500151 ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16,
152 ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17,
Alex Aizman39e84792005-08-04 19:31:00 -0700153};
154
155/*
156 * iSCSI Parameters (RFC3720)
157 */
158enum iscsi_param {
Mike Christiefd7255f2006-04-06 21:13:36 -0500159 /* passed in using netlink set param */
160 ISCSI_PARAM_MAX_RECV_DLENGTH,
161 ISCSI_PARAM_MAX_XMIT_DLENGTH,
162 ISCSI_PARAM_HDRDGST_EN,
163 ISCSI_PARAM_DATADGST_EN,
164 ISCSI_PARAM_INITIAL_R2T_EN,
165 ISCSI_PARAM_MAX_R2T,
166 ISCSI_PARAM_IMM_DATA_EN,
167 ISCSI_PARAM_FIRST_BURST,
168 ISCSI_PARAM_MAX_BURST,
169 ISCSI_PARAM_PDU_INORDER_EN,
170 ISCSI_PARAM_DATASEQ_INORDER_EN,
171 ISCSI_PARAM_ERL,
172 ISCSI_PARAM_IFMARKER_EN,
173 ISCSI_PARAM_OFMARKER_EN,
174 ISCSI_PARAM_TARGET_NAME,
175 ISCSI_PARAM_TPGT,
176 ISCSI_PARAM_PERSISTENT_ADDRESS,
177 ISCSI_PARAM_PERSISTENT_PORT,
Mike Christie30a6c652006-04-06 21:13:39 -0500178 ISCSI_PARAM_SESS_RECOVERY_TMO,
Mike Christiefd7255f2006-04-06 21:13:36 -0500179
180 /* pased in through bind conn using transport_fd */
181 ISCSI_PARAM_CONN_PORT,
182 ISCSI_PARAM_CONN_ADDRESS,
183
184 /* must always be last */
185 ISCSI_PARAM_MAX,
Alex Aizman39e84792005-08-04 19:31:00 -0700186};
Mike Christiefd7255f2006-04-06 21:13:36 -0500187
188#define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH)
189#define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH)
190#define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN)
191#define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN)
192#define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN)
193#define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T)
194#define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN)
195#define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST)
196#define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST)
197#define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN)
198#define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN)
199#define ISCSI_ERL (1 << ISCSI_PARAM_ERL)
200#define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN)
201#define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN)
202#define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME)
203#define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT)
204#define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS)
205#define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT)
Mike Christie30a6c652006-04-06 21:13:39 -0500206#define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO)
Mike Christiefd7255f2006-04-06 21:13:36 -0500207#define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT)
208#define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS)
Alex Aizman39e84792005-08-04 19:31:00 -0700209
Alex Aizman39e84792005-08-04 19:31:00 -0700210#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
211#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
Mike Christie7b8631b2006-01-13 18:05:50 -0600212#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
213
214/**
215 * iscsi_hostdata - get LLD hostdata from scsi_host
216 * @_hostdata: pointer to scsi host's hostdata
217 **/
Alex Aizman39e84792005-08-04 19:31:00 -0700218#define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
219
220/*
221 * These flags presents iSCSI Data-Path capabilities.
222 */
223#define CAP_RECOVERY_L0 0x1
224#define CAP_RECOVERY_L1 0x2
225#define CAP_RECOVERY_L2 0x4
226#define CAP_MULTI_R2T 0x8
227#define CAP_HDRDGST 0x10
228#define CAP_DATADGST 0x20
229#define CAP_MULTI_CONN 0x40
230#define CAP_TEXT_NEGO 0x80
231#define CAP_MARKERS 0x100
232
233/*
234 * These flags describes reason of stop_conn() call
235 */
236#define STOP_CONN_TERM 0x1
237#define STOP_CONN_SUSPEND 0x2
238#define STOP_CONN_RECOVER 0x3
239
240#define ISCSI_STATS_CUSTOM_MAX 32
241#define ISCSI_STATS_CUSTOM_DESC_MAX 64
242struct iscsi_stats_custom {
243 char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
244 uint64_t value;
245};
246
247/*
248 * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
249 *
250 * Note: this structure contains counters collected on per-connection basis.
251 */
252struct iscsi_stats {
253 /* octets */
254 uint64_t txdata_octets;
255 uint64_t rxdata_octets;
256
257 /* xmit pdus */
258 uint32_t noptx_pdus;
259 uint32_t scsicmd_pdus;
260 uint32_t tmfcmd_pdus;
261 uint32_t login_pdus;
262 uint32_t text_pdus;
263 uint32_t dataout_pdus;
264 uint32_t logout_pdus;
265 uint32_t snack_pdus;
266
267 /* recv pdus */
268 uint32_t noprx_pdus;
269 uint32_t scsirsp_pdus;
270 uint32_t tmfrsp_pdus;
271 uint32_t textrsp_pdus;
272 uint32_t datain_pdus;
273 uint32_t logoutrsp_pdus;
274 uint32_t r2t_pdus;
275 uint32_t async_pdus;
276 uint32_t rjt_pdus;
277
278 /* errors */
279 uint32_t digest_err;
280 uint32_t timeout_err;
281
282 /*
283 * iSCSI Custom Statistics support, i.e. Transport could
284 * extend existing MIB statistics with its own specific statistics
285 * up to ISCSI_STATS_CUSTOM_MAX
286 */
287 uint32_t custom_length;
288 struct iscsi_stats_custom custom[0]
289 __attribute__ ((aligned (sizeof(uint64_t))));
290};
291
292#endif