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