aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJames Bottomley <jejb@titanic.(none)>2005-09-08 10:37:35 -0400
committerJames Bottomley <jejb@titanic.(none)>2005-09-08 10:37:35 -0400
commitf5c7f03113fc9c547012cf403aec4b534d575ef0 (patch)
tree255bd4ff0c5a9314be427cf0695349ac432f9d7c /include
parentcaf39e87cc1182f7dae84eefc43ca14d54c78ef9 (diff)
parent471417c9cfb4c2574e2c03bf2273fe12f5388a8e (diff)
Merge HEAD from ../scsi-iscsi-2.6
Diffstat (limited to 'include')
-rw-r--r--include/scsi/iscsi_if.h245
-rw-r--r--include/scsi/iscsi_proto.h566
-rw-r--r--include/scsi/scsi_transport_iscsi.h202
3 files changed, 866 insertions, 147 deletions
diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h
new file mode 100644
index 000000000000..be1bc792ab18
--- /dev/null
+++ b/include/scsi/iscsi_if.h
@@ -0,0 +1,245 @@
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
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 {
63 uint64_t session_handle;
64 uint32_t sid;
65 } d_session;
66 struct msg_create_conn {
67 uint64_t session_handle;
68 uint32_t cid;
69 uint32_t sid;
70 } c_conn;
71 struct msg_bind_conn {
72 uint64_t session_handle;
73 uint64_t conn_handle;
74 uint32_t transport_fd;
75 uint32_t is_leading;
76 } b_conn;
77 struct msg_destroy_conn {
78 uint64_t conn_handle;
79 uint32_t cid;
80 } d_conn;
81 struct msg_send_pdu {
82 uint32_t hdr_size;
83 uint32_t data_size;
84 uint64_t conn_handle;
85 } send_pdu;
86 struct msg_set_param {
87 uint64_t conn_handle;
88 uint32_t param; /* enum iscsi_param */
89 uint32_t value;
90 } set_param;
91 struct msg_start_conn {
92 uint64_t conn_handle;
93 } start_conn;
94 struct msg_stop_conn {
95 uint64_t conn_handle;
96 uint32_t flag;
97 } stop_conn;
98 struct msg_get_stats {
99 uint64_t conn_handle;
100 } get_stats;
101 } u;
102 union {
103 /* messages k -> u */
104 uint64_t handle;
105 int retcode;
106 struct msg_create_session_ret {
107 uint64_t session_handle;
108 uint32_t sid;
109 } c_session_ret;
110 struct msg_recv_req {
111 uint64_t recv_handle;
112 uint64_t conn_handle;
113 } recv_req;
114 struct msg_conn_error {
115 uint64_t conn_handle;
116 uint32_t error; /* enum iscsi_err */
117 } connerror;
118 } r;
119} __attribute__ ((aligned (sizeof(uint64_t))));
120
121/*
122 * Common error codes
123 */
124enum iscsi_err {
125 ISCSI_OK = 0,
126
127 ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
128 ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
129 ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
130 ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
131 ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
132 ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
133 ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
134 ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
135 ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
136 ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
137 ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
138 ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
139 ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
140 ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
141 ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
142 ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16
143};
144
145/*
146 * iSCSI Parameters (RFC3720)
147 */
148enum iscsi_param {
149 ISCSI_PARAM_MAX_RECV_DLENGTH = 0,
150 ISCSI_PARAM_MAX_XMIT_DLENGTH = 1,
151 ISCSI_PARAM_HDRDGST_EN = 2,
152 ISCSI_PARAM_DATADGST_EN = 3,
153 ISCSI_PARAM_INITIAL_R2T_EN = 4,
154 ISCSI_PARAM_MAX_R2T = 5,
155 ISCSI_PARAM_IMM_DATA_EN = 6,
156 ISCSI_PARAM_FIRST_BURST = 7,
157 ISCSI_PARAM_MAX_BURST = 8,
158 ISCSI_PARAM_PDU_INORDER_EN = 9,
159 ISCSI_PARAM_DATASEQ_INORDER_EN = 10,
160 ISCSI_PARAM_ERL = 11,
161 ISCSI_PARAM_IFMARKER_EN = 12,
162 ISCSI_PARAM_OFMARKER_EN = 13,
163};
164#define ISCSI_PARAM_MAX 14
165
166typedef uint64_t iscsi_sessionh_t; /* iSCSI Data-Path session handle */
167typedef uint64_t iscsi_connh_t; /* iSCSI Data-Path connection handle */
168
169#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
170#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
171#define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
172
173/*
174 * These flags presents iSCSI Data-Path capabilities.
175 */
176#define CAP_RECOVERY_L0 0x1
177#define CAP_RECOVERY_L1 0x2
178#define CAP_RECOVERY_L2 0x4
179#define CAP_MULTI_R2T 0x8
180#define CAP_HDRDGST 0x10
181#define CAP_DATADGST 0x20
182#define CAP_MULTI_CONN 0x40
183#define CAP_TEXT_NEGO 0x80
184#define CAP_MARKERS 0x100
185
186/*
187 * These flags describes reason of stop_conn() call
188 */
189#define STOP_CONN_TERM 0x1
190#define STOP_CONN_SUSPEND 0x2
191#define STOP_CONN_RECOVER 0x3
192
193#define ISCSI_STATS_CUSTOM_MAX 32
194#define ISCSI_STATS_CUSTOM_DESC_MAX 64
195struct iscsi_stats_custom {
196 char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
197 uint64_t value;
198};
199
200/*
201 * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
202 *
203 * Note: this structure contains counters collected on per-connection basis.
204 */
205struct iscsi_stats {
206 /* octets */
207 uint64_t txdata_octets;
208 uint64_t rxdata_octets;
209
210 /* xmit pdus */
211 uint32_t noptx_pdus;
212 uint32_t scsicmd_pdus;
213 uint32_t tmfcmd_pdus;
214 uint32_t login_pdus;
215 uint32_t text_pdus;
216 uint32_t dataout_pdus;
217 uint32_t logout_pdus;
218 uint32_t snack_pdus;
219
220 /* recv pdus */
221 uint32_t noprx_pdus;
222 uint32_t scsirsp_pdus;
223 uint32_t tmfrsp_pdus;
224 uint32_t textrsp_pdus;
225 uint32_t datain_pdus;
226 uint32_t logoutrsp_pdus;
227 uint32_t r2t_pdus;
228 uint32_t async_pdus;
229 uint32_t rjt_pdus;
230
231 /* errors */
232 uint32_t digest_err;
233 uint32_t timeout_err;
234
235 /*
236 * iSCSI Custom Statistics support, i.e. Transport could
237 * extend existing MIB statistics with its own specific statistics
238 * up to ISCSI_STATS_CUSTOM_MAX
239 */
240 uint32_t custom_length;
241 struct iscsi_stats_custom custom[0]
242 __attribute__ ((aligned (sizeof(uint64_t))));
243};
244
245#endif
diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
new file mode 100644
index 000000000000..6c08551c79f5
--- /dev/null
+++ b/include/scsi/iscsi_proto.h
@@ -0,0 +1,566 @@
1/*
2 * RFC 3720 (iSCSI) protocol data types
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_PROTO_H
22#define ISCSI_PROTO_H
23
24#define ISCSI_VERSION_STR "0.3"
25#define ISCSI_DATE_STR "22-Apr-2005"
26#define ISCSI_DRAFT20_VERSION 0x00
27
28/* default iSCSI listen port for incoming connections */
29#define ISCSI_LISTEN_PORT 3260
30
31/* Padding word length */
32#define PAD_WORD_LEN 4
33
34/*
35 * useful common(control and data pathes) macro
36 */
37#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
38#define hton24(p, v) { \
39 p[0] = (((v) >> 16) & 0xFF); \
40 p[1] = (((v) >> 8) & 0xFF); \
41 p[2] = ((v) & 0xFF); \
42}
43#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
44
45/*
46 * iSCSI Template Message Header
47 */
48struct iscsi_hdr {
49 uint8_t opcode;
50 uint8_t flags; /* Final bit */
51 uint8_t rsvd2[2];
52 uint8_t hlength; /* AHSs total length */
53 uint8_t dlength[3]; /* Data length */
54 uint8_t lun[8];
55 __be32 itt; /* Initiator Task Tag */
56 __be32 ttt; /* Target Task Tag */
57 __be32 statsn;
58 __be32 exp_statsn;
59 uint8_t other[16];
60};
61
62/************************* RFC 3720 Begin *****************************/
63
64#define ISCSI_RESERVED_TAG 0xffffffff
65
66/* Opcode encoding bits */
67#define ISCSI_OP_RETRY 0x80
68#define ISCSI_OP_IMMEDIATE 0x40
69#define ISCSI_OPCODE_MASK 0x3F
70
71/* Initiator Opcode values */
72#define ISCSI_OP_NOOP_OUT 0x00
73#define ISCSI_OP_SCSI_CMD 0x01
74#define ISCSI_OP_SCSI_TMFUNC 0x02
75#define ISCSI_OP_LOGIN 0x03
76#define ISCSI_OP_TEXT 0x04
77#define ISCSI_OP_SCSI_DATA_OUT 0x05
78#define ISCSI_OP_LOGOUT 0x06
79#define ISCSI_OP_SNACK 0x10
80
81/* Target Opcode values */
82#define ISCSI_OP_NOOP_IN 0x20
83#define ISCSI_OP_SCSI_CMD_RSP 0x21
84#define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
85#define ISCSI_OP_LOGIN_RSP 0x23
86#define ISCSI_OP_TEXT_RSP 0x24
87#define ISCSI_OP_SCSI_DATA_IN 0x25
88#define ISCSI_OP_LOGOUT_RSP 0x26
89#define ISCSI_OP_R2T 0x31
90#define ISCSI_OP_ASYNC_EVENT 0x32
91#define ISCSI_OP_REJECT 0x3f
92
93/* iSCSI PDU Header */
94struct iscsi_cmd {
95 uint8_t opcode;
96 uint8_t flags;
97 uint8_t rsvd2;
98 uint8_t cmdrn;
99 uint8_t hlength;
100 uint8_t dlength[3];
101 uint8_t lun[8];
102 __be32 itt; /* Initiator Task Tag */
103 __be32 data_length;
104 __be32 cmdsn;
105 __be32 exp_statsn;
106 uint8_t cdb[16]; /* SCSI Command Block */
107 /* Additional Data (Command Dependent) */
108};
109
110/* Command PDU flags */
111#define ISCSI_FLAG_CMD_FINAL 0x80
112#define ISCSI_FLAG_CMD_READ 0x40
113#define ISCSI_FLAG_CMD_WRITE 0x20
114#define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
115
116/* SCSI Command Attribute values */
117#define ISCSI_ATTR_UNTAGGED 0
118#define ISCSI_ATTR_SIMPLE 1
119#define ISCSI_ATTR_ORDERED 2
120#define ISCSI_ATTR_HEAD_OF_QUEUE 3
121#define ISCSI_ATTR_ACA 4
122
123/* SCSI Response Header */
124struct iscsi_cmd_rsp {
125 uint8_t opcode;
126 uint8_t flags;
127 uint8_t response;
128 uint8_t cmd_status;
129 uint8_t hlength;
130 uint8_t dlength[3];
131 uint8_t rsvd[8];
132 __be32 itt; /* Initiator Task Tag */
133 __be32 rsvd1;
134 __be32 statsn;
135 __be32 exp_cmdsn;
136 __be32 max_cmdsn;
137 __be32 exp_datasn;
138 __be32 bi_residual_count;
139 __be32 residual_count;
140 /* Response or Sense Data (optional) */
141};
142
143/* Command Response PDU flags */
144#define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
145#define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
146#define ISCSI_FLAG_CMD_OVERFLOW 0x04
147#define ISCSI_FLAG_CMD_UNDERFLOW 0x02
148
149/* iSCSI Status values. Valid if Rsp Selector bit is not set */
150#define ISCSI_STATUS_CMD_COMPLETED 0
151#define ISCSI_STATUS_TARGET_FAILURE 1
152#define ISCSI_STATUS_SUBSYS_FAILURE 2
153
154/* Asynchronous Event Header */
155struct iscsi_async {
156 uint8_t opcode;
157 uint8_t flags;
158 uint8_t rsvd2[2];
159 uint8_t rsvd3;
160 uint8_t dlength[3];
161 uint8_t lun[8];
162 uint8_t rsvd4[8];
163 __be32 statsn;
164 __be32 exp_cmdsn;
165 __be32 max_cmdsn;
166 uint8_t async_event;
167 uint8_t async_vcode;
168 __be16 param1;
169 __be16 param2;
170 __be16 param3;
171 uint8_t rsvd5[4];
172};
173
174/* iSCSI Event Codes */
175#define ISCSI_ASYNC_MSG_SCSI_EVENT 0
176#define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
177#define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
178#define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
179#define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
180#define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
181
182/* NOP-Out Message */
183struct iscsi_nopout {
184 uint8_t opcode;
185 uint8_t flags;
186 __be16 rsvd2;
187 uint8_t rsvd3;
188 uint8_t dlength[3];
189 uint8_t lun[8];
190 __be32 itt; /* Initiator Task Tag */
191 __be32 ttt; /* Target Transfer Tag */
192 __be32 cmdsn;
193 __be32 exp_statsn;
194 uint8_t rsvd4[16];
195};
196
197/* NOP-In Message */
198struct iscsi_nopin {
199 uint8_t opcode;
200 uint8_t flags;
201 __be16 rsvd2;
202 uint8_t rsvd3;
203 uint8_t dlength[3];
204 uint8_t lun[8];
205 __be32 itt; /* Initiator Task Tag */
206 __be32 ttt; /* Target Transfer Tag */
207 __be32 statsn;
208 __be32 exp_cmdsn;
209 __be32 max_cmdsn;
210 uint8_t rsvd4[12];
211};
212
213/* SCSI Task Management Message Header */
214struct iscsi_tm {
215 uint8_t opcode;
216 uint8_t flags;
217 uint8_t rsvd1[2];
218 uint8_t hlength;
219 uint8_t dlength[3];
220 uint8_t lun[8];
221 __be32 itt; /* Initiator Task Tag */
222 __be32 rtt; /* Reference Task Tag */
223 __be32 cmdsn;
224 __be32 exp_statsn;
225 __be32 refcmdsn;
226 __be32 exp_datasn;
227 uint8_t rsvd2[8];
228};
229
230#define ISCSI_FLAG_TASK_MGMT_FUNCTION_MASK 0x7F
231
232/* Function values */
233#define ISCSI_TM_FUNC_ABORT_TASK 1
234#define ISCSI_TM_FUNC_ABORT_TASK_SET 2
235#define ISCSI_TM_FUNC_CLEAR_ACA 3
236#define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
237#define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
238#define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
239#define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
240#define ISCSI_TM_FUNC_TASK_REASSIGN 8
241
242/* SCSI Task Management Response Header */
243struct iscsi_tm_rsp {
244 uint8_t opcode;
245 uint8_t flags;
246 uint8_t response; /* see Response values below */
247 uint8_t qualifier;
248 uint8_t hlength;
249 uint8_t dlength[3];
250 uint8_t rsvd2[8];
251 __be32 itt; /* Initiator Task Tag */
252 __be32 rtt; /* Reference Task Tag */
253 __be32 statsn;
254 __be32 exp_cmdsn;
255 __be32 max_cmdsn;
256 uint8_t rsvd3[12];
257};
258
259/* Response values */
260#define SCSI_TCP_TM_RESP_COMPLETE 0x00
261#define SCSI_TCP_TM_RESP_NO_TASK 0x01
262#define SCSI_TCP_TM_RESP_NO_LUN 0x02
263#define SCSI_TCP_TM_RESP_TASK_ALLEGIANT 0x03
264#define SCSI_TCP_TM_RESP_NO_FAILOVER 0x04
265#define SCSI_TCP_TM_RESP_NOT_SUPPORTED 0x05
266#define SCSI_TCP_TM_RESP_AUTH_FAILED 0x06
267#define SCSI_TCP_TM_RESP_REJECTED 0xff
268
269/* Ready To Transfer Header */
270struct iscsi_r2t_rsp {
271 uint8_t opcode;
272 uint8_t flags;
273 uint8_t rsvd2[2];
274 uint8_t hlength;
275 uint8_t dlength[3];
276 uint8_t lun[8];
277 __be32 itt; /* Initiator Task Tag */
278 __be32 ttt; /* Target Transfer Tag */
279 __be32 statsn;
280 __be32 exp_cmdsn;
281 __be32 max_cmdsn;
282 __be32 r2tsn;
283 __be32 data_offset;
284 __be32 data_length;
285};
286
287/* SCSI Data Hdr */
288struct iscsi_data {
289 uint8_t opcode;
290 uint8_t flags;
291 uint8_t rsvd2[2];
292 uint8_t rsvd3;
293 uint8_t dlength[3];
294 uint8_t lun[8];
295 __be32 itt;
296 __be32 ttt;
297 __be32 rsvd4;
298 __be32 exp_statsn;
299 __be32 rsvd5;
300 __be32 datasn;
301 __be32 offset;
302 __be32 rsvd6;
303 /* Payload */
304};
305
306/* SCSI Data Response Hdr */
307struct iscsi_data_rsp {
308 uint8_t opcode;
309 uint8_t flags;
310 uint8_t rsvd2;
311 uint8_t cmd_status;
312 uint8_t hlength;
313 uint8_t dlength[3];
314 uint8_t lun[8];
315 __be32 itt;
316 __be32 ttt;
317 __be32 statsn;
318 __be32 exp_cmdsn;
319 __be32 max_cmdsn;
320 __be32 datasn;
321 __be32 offset;
322 __be32 residual_count;
323};
324
325/* Data Response PDU flags */
326#define ISCSI_FLAG_DATA_ACK 0x40
327#define ISCSI_FLAG_DATA_OVERFLOW 0x04
328#define ISCSI_FLAG_DATA_UNDERFLOW 0x02
329#define ISCSI_FLAG_DATA_STATUS 0x01
330
331/* Text Header */
332struct iscsi_text {
333 uint8_t opcode;
334 uint8_t flags;
335 uint8_t rsvd2[2];
336 uint8_t hlength;
337 uint8_t dlength[3];
338 uint8_t rsvd4[8];
339 __be32 itt;
340 __be32 ttt;
341 __be32 cmdsn;
342 __be32 exp_statsn;
343 uint8_t rsvd5[16];
344 /* Text - key=value pairs */
345};
346
347#define ISCSI_FLAG_TEXT_CONTINUE 0x40
348
349/* Text Response Header */
350struct iscsi_text_rsp {
351 uint8_t opcode;
352 uint8_t flags;
353 uint8_t rsvd2[2];
354 uint8_t hlength;
355 uint8_t dlength[3];
356 uint8_t rsvd4[8];
357 __be32 itt;
358 __be32 ttt;
359 __be32 statsn;
360 __be32 exp_cmdsn;
361 __be32 max_cmdsn;
362 uint8_t rsvd5[12];
363 /* Text Response - key:value pairs */
364};
365
366/* Login Header */
367struct iscsi_login {
368 uint8_t opcode;
369 uint8_t flags;
370 uint8_t max_version; /* Max. version supported */
371 uint8_t min_version; /* Min. version supported */
372 uint8_t hlength;
373 uint8_t dlength[3];
374 uint8_t isid[6]; /* Initiator Session ID */
375 __be16 tsih; /* Target Session Handle */
376 __be32 itt; /* Initiator Task Tag */
377 __be16 cid;
378 __be16 rsvd3;
379 __be32 cmdsn;
380 __be32 exp_statsn;
381 uint8_t rsvd5[16];
382};
383
384/* Login PDU flags */
385#define ISCSI_FLAG_LOGIN_TRANSIT 0x80
386#define ISCSI_FLAG_LOGIN_CONTINUE 0x40
387#define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
388#define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
389
390#define ISCSI_LOGIN_CURRENT_STAGE(flags) \
391 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
392#define ISCSI_LOGIN_NEXT_STAGE(flags) \
393 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
394
395/* Login Response Header */
396struct iscsi_login_rsp {
397 uint8_t opcode;
398 uint8_t flags;
399 uint8_t max_version; /* Max. version supported */
400 uint8_t active_version; /* Active version */
401 uint8_t hlength;
402 uint8_t dlength[3];
403 uint8_t isid[6]; /* Initiator Session ID */
404 __be16 tsih; /* Target Session Handle */
405 __be32 itt; /* Initiator Task Tag */
406 __be32 rsvd3;
407 __be32 statsn;
408 __be32 exp_cmdsn;
409 __be32 max_cmdsn;
410 uint8_t status_class; /* see Login RSP ststus classes below */
411 uint8_t status_detail; /* see Login RSP Status details below */
412 uint8_t rsvd4[10];
413};
414
415/* Login stage (phase) codes for CSG, NSG */
416#define ISCSI_INITIAL_LOGIN_STAGE -1
417#define ISCSI_SECURITY_NEGOTIATION_STAGE 0
418#define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
419#define ISCSI_FULL_FEATURE_PHASE 3
420
421/* Login Status response classes */
422#define ISCSI_STATUS_CLS_SUCCESS 0x00
423#define ISCSI_STATUS_CLS_REDIRECT 0x01
424#define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
425#define ISCSI_STATUS_CLS_TARGET_ERR 0x03
426
427/* Login Status response detail codes */
428/* Class-0 (Success) */
429#define ISCSI_LOGIN_STATUS_ACCEPT 0x00
430
431/* Class-1 (Redirection) */
432#define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
433#define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
434
435/* Class-2 (Initiator Error) */
436#define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
437#define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
438#define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
439#define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
440#define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
441#define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
442#define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
443#define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
444#define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
445#define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
446#define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
447#define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
448
449/* Class-3 (Target Error) */
450#define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
451#define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
452#define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
453
454/* Logout Header */
455struct iscsi_logout {
456 uint8_t opcode;
457 uint8_t flags;
458 uint8_t rsvd1[2];
459 uint8_t hlength;
460 uint8_t dlength[3];
461 uint8_t rsvd2[8];
462 __be32 itt; /* Initiator Task Tag */
463 __be16 cid;
464 uint8_t rsvd3[2];
465 __be32 cmdsn;
466 __be32 exp_statsn;
467 uint8_t rsvd4[16];
468};
469
470/* Logout PDU flags */
471#define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
472
473/* logout reason_code values */
474
475#define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
476#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
477#define ISCSI_LOGOUT_REASON_RECOVERY 2
478#define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
479
480/* Logout Response Header */
481struct iscsi_logout_rsp {
482 uint8_t opcode;
483 uint8_t flags;
484 uint8_t response; /* see Logout response values below */
485 uint8_t rsvd2;
486 uint8_t hlength;
487 uint8_t dlength[3];
488 uint8_t rsvd3[8];
489 __be32 itt; /* Initiator Task Tag */
490 __be32 rsvd4;
491 __be32 statsn;
492 __be32 exp_cmdsn;
493 __be32 max_cmdsn;
494 __be32 rsvd5;
495 __be16 t2wait;
496 __be16 t2retain;
497 __be32 rsvd6;
498};
499
500/* logout response status values */
501
502#define ISCSI_LOGOUT_SUCCESS 0
503#define ISCSI_LOGOUT_CID_NOT_FOUND 1
504#define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
505#define ISCSI_LOGOUT_CLEANUP_FAILED 3
506
507/* SNACK Header */
508struct iscsi_snack {
509 uint8_t opcode;
510 uint8_t flags;
511 uint8_t rsvd2[14];
512 __be32 itt;
513 __be32 begrun;
514 __be32 runlength;
515 __be32 exp_statsn;
516 __be32 rsvd3;
517 __be32 exp_datasn;
518 uint8_t rsvd6[8];
519};
520
521/* SNACK PDU flags */
522#define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
523
524/* Reject Message Header */
525struct iscsi_reject {
526 uint8_t opcode;
527 uint8_t flags;
528 uint8_t reason;
529 uint8_t rsvd2;
530 uint8_t rsvd3;
531 uint8_t dlength[3];
532 uint8_t rsvd4[16];
533 __be32 statsn;
534 __be32 exp_cmdsn;
535 __be32 max_cmdsn;
536 __be32 datasn;
537 uint8_t rsvd5[8];
538 /* Text - Rejected hdr */
539};
540
541/* Reason for Reject */
542#define CMD_BEFORE_LOGIN 1
543#define DATA_DIGEST_ERROR 2
544#define DATA_SNACK_REJECT 3
545#define ISCSI_PROTOCOL_ERROR 4
546#define CMD_NOT_SUPPORTED 5
547#define IMM_CMD_REJECT 6
548#define TASK_IN_PROGRESS 7
549#define INVALID_SNACK 8
550#define BOOKMARK_REJECTED 9
551#define BOOKMARK_NO_RESOURCES 10
552#define NEGOTIATION_RESET 11
553
554/* Max. number of Key=Value pairs in a text message */
555#define MAX_KEY_VALUE_PAIRS 8192
556
557/* maximum length for text keys/values */
558#define KEY_MAXLEN 64
559#define VALUE_MAXLEN 255
560#define TARGET_NAME_MAXLEN VALUE_MAXLEN
561
562#define DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH 8192
563
564/************************* RFC 3720 End *****************************/
565
566#endif /* ISCSI_PROTO_H */
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index 1b26a6c0aa2a..f25041c386ec 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -1,8 +1,10 @@
1/* 1/*
2 * iSCSI transport class definitions 2 * iSCSI transport class definitions
3 * 3 *
4 * Copyright (C) IBM Corporation, 2004 4 * Copyright (C) IBM Corporation, 2004
5 * Copyright (C) Mike Christie, 2004 5 * Copyright (C) Mike Christie, 2004 - 2005
6 * Copyright (C) Dmitry Yusupov, 2004 - 2005
7 * Copyright (C) Alex Aizman, 2004 - 2005
6 * 8 *
7 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -21,158 +23,64 @@
21#ifndef SCSI_TRANSPORT_ISCSI_H 23#ifndef SCSI_TRANSPORT_ISCSI_H
22#define SCSI_TRANSPORT_ISCSI_H 24#define SCSI_TRANSPORT_ISCSI_H
23 25
24#include <linux/config.h> 26#include <scsi/iscsi_if.h>
25#include <linux/in6.h>
26#include <linux/in.h>
27
28struct scsi_transport_template;
29 27
30struct iscsi_class_session { 28/**
31 uint8_t isid[6]; 29 * struct iscsi_transport - iSCSI Transport template
32 uint16_t tsih; 30 *
33 int header_digest; /* 1 CRC32, 0 None */ 31 * @name: transport name
34 int data_digest; /* 1 CRC32, 0 None */ 32 * @caps: iSCSI Data-Path capabilities
35 uint16_t tpgt; 33 * @create_session: create new iSCSI session object
36 union { 34 * @destroy_session: destroy existing iSCSI session object
37 struct in6_addr sin6_addr; 35 * @create_conn: create new iSCSI connection
38 struct in_addr sin_addr; 36 * @bind_conn: associate this connection with existing iSCSI session
39 } u; 37 * and specified transport descriptor
40 sa_family_t addr_type; /* must be AF_INET or AF_INET6 */ 38 * @destroy_conn: destroy inactive iSCSI connection
41 uint16_t port; /* must be in network byte order */ 39 * @set_param: set iSCSI Data-Path operational parameter
42 int initial_r2t; /* 1 Yes, 0 No */ 40 * @start_conn: set connection to be operational
43 int immediate_data; /* 1 Yes, 0 No */ 41 * @stop_conn: suspend/recover/terminate connection
44 uint32_t max_recv_data_segment_len; 42 * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
45 uint32_t max_burst_len; 43 *
46 uint32_t first_burst_len; 44 * Template API provided by iSCSI Transport
47 uint16_t def_time2wait; 45 */
48 uint16_t def_time2retain; 46struct iscsi_transport {
49 uint16_t max_outstanding_r2t; 47 struct module *owner;
50 int data_pdu_in_order; /* 1 Yes, 0 No */ 48 char *name;
51 int data_sequence_in_order; /* 1 Yes, 0 No */ 49 unsigned int caps;
52 int erl; 50 struct scsi_host_template *host_template;
51 int hostdata_size;
52 int max_lun;
53 unsigned int max_conn;
54 unsigned int max_cmd_len;
55 iscsi_sessionh_t (*create_session) (uint32_t initial_cmdsn,
56 struct Scsi_Host *shost);
57 void (*destroy_session) (iscsi_sessionh_t session);
58 iscsi_connh_t (*create_conn) (iscsi_sessionh_t session, uint32_t cid);
59 int (*bind_conn) (iscsi_sessionh_t session, iscsi_connh_t conn,
60 uint32_t transport_fd, int is_leading);
61 int (*start_conn) (iscsi_connh_t conn);
62 void (*stop_conn) (iscsi_connh_t conn, int flag);
63 void (*destroy_conn) (iscsi_connh_t conn);
64 int (*set_param) (iscsi_connh_t conn, enum iscsi_param param,
65 uint32_t value);
66 int (*get_param) (iscsi_connh_t conn, enum iscsi_param param,
67 uint32_t *value);
68 int (*send_pdu) (iscsi_connh_t conn, struct iscsi_hdr *hdr,
69 char *data, uint32_t data_size);
70 void (*get_stats) (iscsi_connh_t conn, struct iscsi_stats *stats);
53}; 71};
54 72
55/* 73/*
56 * accessor macros 74 * transport registration upcalls
57 */ 75 */
58#define iscsi_isid(x) \ 76extern int iscsi_register_transport(struct iscsi_transport *tt);
59 (((struct iscsi_class_session *)&(x)->starget_data)->isid) 77extern int iscsi_unregister_transport(struct iscsi_transport *tt);
60#define iscsi_tsih(x) \
61 (((struct iscsi_class_session *)&(x)->starget_data)->tsih)
62#define iscsi_header_digest(x) \
63 (((struct iscsi_class_session *)&(x)->starget_data)->header_digest)
64#define iscsi_data_digest(x) \
65 (((struct iscsi_class_session *)&(x)->starget_data)->data_digest)
66#define iscsi_port(x) \
67 (((struct iscsi_class_session *)&(x)->starget_data)->port)
68#define iscsi_addr_type(x) \
69 (((struct iscsi_class_session *)&(x)->starget_data)->addr_type)
70#define iscsi_sin_addr(x) \
71 (((struct iscsi_class_session *)&(x)->starget_data)->u.sin_addr)
72#define iscsi_sin6_addr(x) \
73 (((struct iscsi_class_session *)&(x)->starget_data)->u.sin6_addr)
74#define iscsi_tpgt(x) \
75 (((struct iscsi_class_session *)&(x)->starget_data)->tpgt)
76#define iscsi_initial_r2t(x) \
77 (((struct iscsi_class_session *)&(x)->starget_data)->initial_r2t)
78#define iscsi_immediate_data(x) \
79 (((struct iscsi_class_session *)&(x)->starget_data)->immediate_data)
80#define iscsi_max_recv_data_segment_len(x) \
81 (((struct iscsi_class_session *)&(x)->starget_data)->max_recv_data_segment_len)
82#define iscsi_max_burst_len(x) \
83 (((struct iscsi_class_session *)&(x)->starget_data)->max_burst_len)
84#define iscsi_first_burst_len(x) \
85 (((struct iscsi_class_session *)&(x)->starget_data)->first_burst_len)
86#define iscsi_def_time2wait(x) \
87 (((struct iscsi_class_session *)&(x)->starget_data)->def_time2wait)
88#define iscsi_def_time2retain(x) \
89 (((struct iscsi_class_session *)&(x)->starget_data)->def_time2retain)
90#define iscsi_max_outstanding_r2t(x) \
91 (((struct iscsi_class_session *)&(x)->starget_data)->max_outstanding_r2t)
92#define iscsi_data_pdu_in_order(x) \
93 (((struct iscsi_class_session *)&(x)->starget_data)->data_pdu_in_order)
94#define iscsi_data_sequence_in_order(x) \
95 (((struct iscsi_class_session *)&(x)->starget_data)->data_sequence_in_order)
96#define iscsi_erl(x) \
97 (((struct iscsi_class_session *)&(x)->starget_data)->erl)
98 78
99/* 79/*
100 * The functions by which the transport class and the driver communicate 80 * control plane upcalls
101 */ 81 */
102struct iscsi_function_template { 82extern void iscsi_conn_error(iscsi_connh_t conn, enum iscsi_err error);
103 /* 83extern int iscsi_recv_pdu(iscsi_connh_t conn, struct iscsi_hdr *hdr,
104 * target attrs 84 char *data, uint32_t data_size);
105 */
106 void (*get_isid)(struct scsi_target *);
107 void (*get_tsih)(struct scsi_target *);
108 void (*get_header_digest)(struct scsi_target *);
109 void (*get_data_digest)(struct scsi_target *);
110 void (*get_port)(struct scsi_target *);
111 void (*get_tpgt)(struct scsi_target *);
112 /*
113 * In get_ip_address the lld must set the address and
114 * the address type
115 */
116 void (*get_ip_address)(struct scsi_target *);
117 /*
118 * The lld should snprintf the name or alias to the buffer
119 */
120 ssize_t (*get_target_name)(struct scsi_target *, char *, ssize_t);
121 ssize_t (*get_target_alias)(struct scsi_target *, char *, ssize_t);
122 void (*get_initial_r2t)(struct scsi_target *);
123 void (*get_immediate_data)(struct scsi_target *);
124 void (*get_max_recv_data_segment_len)(struct scsi_target *);
125 void (*get_max_burst_len)(struct scsi_target *);
126 void (*get_first_burst_len)(struct scsi_target *);
127 void (*get_def_time2wait)(struct scsi_target *);
128 void (*get_def_time2retain)(struct scsi_target *);
129 void (*get_max_outstanding_r2t)(struct scsi_target *);
130 void (*get_data_pdu_in_order)(struct scsi_target *);
131 void (*get_data_sequence_in_order)(struct scsi_target *);
132 void (*get_erl)(struct scsi_target *);
133
134 /*
135 * host atts
136 */
137
138 /*
139 * The lld should snprintf the name or alias to the buffer
140 */
141 ssize_t (*get_initiator_alias)(struct Scsi_Host *, char *, ssize_t);
142 ssize_t (*get_initiator_name)(struct Scsi_Host *, char *, ssize_t);
143 /*
144 * The driver sets these to tell the transport class it
145 * wants the attributes displayed in sysfs. If the show_ flag
146 * is not set, the attribute will be private to the transport
147 * class. We could probably just test if a get_ fn was set
148 * since we only use the values for sysfs but this is how
149 * fc does it too.
150 */
151 unsigned long show_isid:1;
152 unsigned long show_tsih:1;
153 unsigned long show_header_digest:1;
154 unsigned long show_data_digest:1;
155 unsigned long show_port:1;
156 unsigned long show_tpgt:1;
157 unsigned long show_ip_address:1;
158 unsigned long show_target_name:1;
159 unsigned long show_target_alias:1;
160 unsigned long show_initial_r2t:1;
161 unsigned long show_immediate_data:1;
162 unsigned long show_max_recv_data_segment_len:1;
163 unsigned long show_max_burst_len:1;
164 unsigned long show_first_burst_len:1;
165 unsigned long show_def_time2wait:1;
166 unsigned long show_def_time2retain:1;
167 unsigned long show_max_outstanding_r2t:1;
168 unsigned long show_data_pdu_in_order:1;
169 unsigned long show_data_sequence_in_order:1;
170 unsigned long show_erl:1;
171 unsigned long show_initiator_name:1;
172 unsigned long show_initiator_alias:1;
173};
174
175struct scsi_transport_template *iscsi_attach_transport(struct iscsi_function_template *);
176void iscsi_release_transport(struct scsi_transport_template *);
177 85
178#endif 86#endif