iscsi.h revision 185289
1/*-
2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/iscsi/initiator/iscsi.h 185289 2008-11-25 07:17:11Z scottl $
27 */
28/*
29 | $Id: iscsi.h,v 1.17 2006/12/01 09:10:17 danny Exp danny $
30 */
31#define	TRUE	1
32#define FALSE	0
33#ifndef _KERNEL
34typedef int boolean_t;
35#endif
36
37#include <cam/cam.h>
38
39#define ISCSIDEV	"iscsi"
40
41#define ISCSI_MAX_TARGETS	4 //64
42
43#define ISCSI_MAX_LUNS		4
44
45/*
46 | iSCSI commands
47 */
48
49/*
50 | Initiator Opcodes:
51 */
52#define ISCSI_NOP_OUT		0x00
53#define ISCSI_SCSI_CMD		0x01
54#define ISCSI_TASK_CMD		0x02
55#define ISCSI_LOGIN_CMD		0x03
56#define ISCSI_TEXT_CMD		0x04
57#define ISCSI_WRITE_DATA	0x05
58#define ISCSI_LOGOUT_CMD	0x06
59#define ISCSI_SNACK		0x10
60/*
61 | Target Opcodes:
62 */
63#define ISCSI_NOP_IN		0x20
64#define ISCSI_SCSI_RSP		0x21
65#define ISCSI_TASK_RSP		0x22
66#define ISCSI_LOGIN_RSP		0x23
67#define ISCSI_TEXT_RSP		0x24
68#define ISCSI_READ_DATA		0x25
69#define ISCSI_LOGOUT_RSP	0x26
70#define ISCSI_R2T		0x31
71#define ISCSI_ASYNC		0x32
72#define ISCSI_REJECT		0x3f
73/*
74 | PDU stuff
75 */
76/*
77 | BHS Basic Header Segment
78 */
79typedef struct bhs {
80     // the order is network byte order!
81     u_char	opcode:6;
82     u_char	I:1;
83     u_char	_:1;
84     u_char	__:7;
85     u_char	F:1;			// Final bit
86     u_char	___[2];
87
88     u_int	AHSLength:8;		// in 4byte words
89     u_int	DSLength:24;		// in bytes
90
91     u_int	LUN[2];			// or Opcode-specific fields
92     u_int	itt;
93     u_int	OpcodeSpecificFields[7];
94#define	CmdSN		OpcodeSpecificFields[1]
95#define	ExpStSN		OpcodeSpecificFields[2]
96#define MaxCmdSN	OpcodeSpecificFields[3]
97} bhs_t;
98
99typedef struct ahs {
100     u_int	len:16;
101     u_int	type:8;
102     u_int	spec:8;
103     char	data[0];
104} ahs_t;
105
106typedef struct {
107     // Sequence Numbers
108     // (computers were invented to count, right?)
109     int	cmd;
110     int	expcmd;
111     int	maxcmd;
112} req_sn_t;
113
114typedef struct {
115     // Sequence Numbers
116     // (computers were invented to count, right?)
117     int	stat;
118     int	expcmd;
119     int	maxcmd;
120} rsp_sn_t;
121
122typedef struct scsi_req {
123     u_char	opcode:6; // 0x01
124     u_char	I:1;
125     u_char	_:1;
126
127     u_char	attr:3;
128     u_char	_0:2;
129     u_char	W:1;
130     u_char	R:1;
131     u_char	F:1;
132#define		iSCSI_TASK_UNTAGGED	0
133#define		iSCSI_TASK_SIMPLE	1
134#define		iSCSI_TASK_ORDER	2
135#define		iSCSI_TASK_HOFQ		3
136#define		iSCSI_TASK_ACA		4
137     char	_1[2];
138     int	len;
139     int	lun[2];
140     int	itt;
141     int	edtlen;		// expectect data transfere length
142     int	cmdSN;
143     int	extStatSN;
144     int	cdb[4];
145} scsi_req_t;
146
147typedef struct scsi_rsp {
148     char	opcode;	// 0x21
149     u_char	flag;
150     u_char	response;
151     u_char	status;
152
153     int	len;
154     int	_[2];
155     int	itt;
156     int	stag;
157     rsp_sn_t	sn;
158     int	expdatasn;
159     int	bdrcnt;	// bidirectional residual count
160     int	rcnt;	// residual count
161} scsi_rsp_t;
162
163typedef struct nop_out {
164     // the order is network byte order!
165     u_char	opcode:6;
166     u_char	I:1;
167     u_char	_:1;
168     u_char	__:7;
169     u_char	F:1;			// Final bit
170     u_char	___[2];
171
172     u_int	len;
173     u_int	lun[2];
174     u_int	itt;
175     u_int	ttt;
176     req_sn_t	sn;
177     u_int	mbz[3];
178} nop_out_t;
179
180typedef struct nop_in {
181     // the order is network byte order!
182     u_char	opcode:6;
183     u_char	I:1;
184     u_char	_:1;
185     u_char	__:7;
186     u_char	F:1;			// Final bit
187     u_char	___[2];
188
189     u_int	len;
190     u_int	lun[2];
191     u_int	itt;
192     u_int	ttt;
193     rsp_sn_t	sn;
194     u_int	____[2];
195
196} nop_in_t;
197
198typedef struct r2t {
199     u_char	opcode:6;
200     u_char	I:1;
201     u_char	_:1;
202     u_char	__:7;
203     u_char	F:1;			// Final bit
204     u_char	___[2];
205
206     u_int	len;
207     u_int	lun[2];
208     u_int	itt;
209     u_int	ttt;
210     rsp_sn_t	sn;
211     u_int	r2tSN;
212     u_int	bo;
213     u_int	ddtl;
214} r2t_t;
215
216typedef struct data_out {
217     u_char	opcode:6;
218     u_char	I:1;
219     u_char	_:1;
220     u_char	__:7;
221     u_char	F:1;			// Final bit
222     u_char	___[2];
223
224     u_int	len;
225     u_int	lun[2];
226     u_int	itt;
227     u_int	ttt;
228     rsp_sn_t	sn;
229     u_int	dsn;	// data seq. number
230     u_int	bo;
231     u_int	____;
232} data_out_t;
233
234typedef struct data_in {
235     u_char	opcode:6;
236     u_char	I:1;
237     u_char	_:1;
238
239     u_char	S:1;
240     u_char	U:1;
241     u_char	O:1;
242     u_char	__:3;
243     u_char	A:1;
244     u_char	F:1;			// Final bit
245     u_char	___[1];
246     u_char	status;
247
248     u_int	len;
249     u_int	lun[2];
250     u_int	itt;
251     u_int	ttt;
252     rsp_sn_t	sn;
253     u_int	dataSN;
254     u_int	bo;
255     u_int	____;
256} data_in_t;
257
258typedef struct reject {
259     u_char	opcode:6;
260     u_char	_:2;
261     u_char	F:1;
262     u_char	__:7;
263     u_char	reason;
264     u_char	___;
265
266     u_int	len;
267     u_int	____[2];
268     u_int	tt[2];	// must be -1
269     rsp_sn_t	sn;
270     u_int	dataSN;	// or R2TSN or reserved
271     u_int	_____[2];
272} reject_t;
273
274typedef struct async {
275     u_char	opcode:6;
276     u_char	_:2;
277     u_char	F:1;
278     u_char	__:7;
279     u_char	___[2];
280
281     u_int	len;
282     u_int	lun[2];
283     u_int	itt;	// must be -1
284     u_int	____;
285     rsp_sn_t	sn;
286
287     u_char	asyncEvent;
288     u_char	asyncVCode;
289     u_char	param1[2];
290     u_char	param2[2];
291     u_char	param3[2];
292
293     u_int	_____;
294
295} async_t;
296
297typedef struct login_req {
298     char	cmd;	// 0x03
299
300     u_char	NSG:2;
301     u_char	CSG:2;
302     u_char	_:2;
303     u_char	C:1;
304     u_char	T:1;
305
306     char	v_max;
307     char	v_min;
308
309     int	len;	// remapped via standard bhs
310     char	isid[6];
311     short	tsih;
312     int	itt;	// Initiator Task Tag;
313
314     int	CID:16;
315     int	rsv:16;
316
317     int	cmdSN;
318     int	expStatSN;
319     int	unused[4];
320} login_req_t;
321
322typedef struct login_rsp {
323     char	cmd;	// 0x23
324     u_char	NSG:2;
325     u_char	CSG:2;
326     u_char	_1:2;
327     u_char	C:1;
328     u_char	T:1;
329
330     char	v_max;
331     char	v_act;
332
333     int	len;	// remapped via standard bhs
334     char	isid[6];
335     short	tsih;
336     int	itt;	// Initiator Task Tag;
337     int	_2;
338     rsp_sn_t	sn;
339     int	status:16;
340     int	_3:16;
341     int	_4[2];
342} login_rsp_t;
343
344typedef struct text_req {
345     char	cmd;	// 0x04
346
347     u_char	_1:6;
348     u_char	C:1;	// Continuation
349     u_char	F:1;	// Final
350     char	_2[2];
351
352     int	len;
353     int	itt;		// Initiator Task Tag
354     int	LUN[2];
355     int	ttt;		// Target Transfer Tag
356     int	cmdSN;
357     int	expStatSN;
358     int	unused[4];
359} text_req_t;
360
361typedef struct logout_req {
362     char	cmd;	// 0x06
363     char	reason;	// 0 - close session
364     			// 1 - close connection
365     			// 2 - remove the connection for recovery
366     char	_2[2];
367
368     int	len;
369     int	_r[2];
370     int	itt;	// Initiator Task Tag;
371
372     u_int	CID:16;
373     u_int	rsv:16;
374
375     int	cmdSN;
376     int	expStatSN;
377     int	unused[4];
378} logout_req_t;
379
380typedef struct logout_rsp {
381     char	cmd;	// 0x26
382     char	cbits;
383     char	_1[2];
384     int	len;
385     int	_2[2];
386     int	itt;
387     int	_3;
388     rsp_sn_t	sn;
389     short	time2wait;
390     short	time2retain;
391     int	_4;
392} logout_rsp_t;
393
394union ipdu_u {
395     bhs_t	bhs;
396     scsi_req_t	scsi_req;
397     scsi_rsp_t	scsi_rsp;
398     nop_out_t	nop_out;
399     nop_in_t	nop_in;
400     r2t_t	r2t;
401     data_out_t	data_out;
402     data_in_t	data_in;
403     reject_t	reject;
404     async_t	async;
405};
406
407/*
408 | Sequence Numbers
409 */
410typedef struct {
411     u_int	itt;
412     u_int      cmd;
413     u_int      expCmd;
414     u_int      maxCmd;
415     u_int      stat;
416     u_int      expStat;
417     u_int      data;
418} sn_t;
419
420/*
421 | in-core version of a Protocol Data Unit
422 */
423typedef struct {
424     union ipdu_u	ipdu;
425
426     ahs_t		*ahs;
427     u_int		ahs_len;
428     u_int		ahs_size;	// the allocated size
429     u_int		hdr_dig;	// header digest
430
431     u_char		*ds;
432     u_int		ds_len;
433     u_int		ds_size;	// the allocated size
434     u_int		ds_dig;		// data digest
435} pdu_t;
436
437typedef struct opvals {
438     int	port;
439     int	tags;
440     int	maxluns;
441     int	sockbufsize;
442
443     int	maxConnections;
444     int	maxRecvDataSegmentLength;
445     int	maxXmitDataSegmentLength; // pseudo ...
446     int	maxBurstLength;
447     int	firstBurstLength;
448     int	defaultTime2Wait;
449     int	defaultTime2Retain;
450     int	maxOutstandingR2T;
451     int	errorRecoveryLevel;
452     int	targetPortalGroupTag;
453
454     boolean_t	initialR2T;
455     boolean_t	immediateData;
456     boolean_t	dataPDUInOrder;
457     boolean_t	dataSequenceInOrder;
458     char	*headerDigest;
459     char	*dataDigest;
460     char	*sessionType;
461     char	*sendTargets;
462     char	*targetAddress;
463     char	*targetAlias;
464     char	*targetName;
465     char	*initiatorName;
466     char	*initiatorAlias;
467     char	*authMethod;
468     char	*chapSecret;
469     char	*chapIName;
470     char	*chapDigest;
471     char	*tgtChapName;
472     char	*tgtChapSecret;
473     int	tgtChallengeLen;
474     u_char	tgtChapID;
475     char	*tgtChapDigest;
476     char	*iqn;
477} isc_opt_t;
478
479/*
480 | ioctl
481 */
482#define ISCSISETSES	_IOR('i', 1, int)
483#define ISCSISETSOC	_IOW('i', 2, int)
484#define ISCSISETOPT	_IOW('i', 5, isc_opt_t)
485#define ISCSIGETOPT	_IOR('i', 6, isc_opt_t)
486
487#define ISCSISEND	_IOW('i', 10, pdu_t)
488#define ISCSIRECV	_IOWR('i', 11, pdu_t)
489
490#define ISCSIPING	_IO('i', 20)
491#define ISCSISIGNAL	_IOW('i', 21, int *)
492
493#define ISCSISTART	_IO('i', 30)
494#define ISCSIRESTART	_IO('i', 31)
495#define ISCSISTOP	_IO('i', 32)
496
497typedef struct iscsi_cam {
498     path_id_t		path_id;
499     target_id_t	target_id;
500     int		target_nluns;
501     lun_id_t		target_lun[ISCSI_MAX_LUNS];
502} iscsi_cam_t;
503
504#define ISCSIGETCAM	_IOR('i', 33, iscsi_cam_t)
505