iscsi.h revision 171568
1/*-
2 * Copyright (c) 2005-2007 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 171568 2007-07-24 15:35:02Z 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
297union ipdu_u {
298     bhs_t	bhs;
299     scsi_req_t	scsi_req;
300     scsi_rsp_t	scsi_rsp;
301     nop_out_t	nop_out;
302     nop_in_t	nop_in;
303     r2t_t	r2t;
304     data_out_t	data_out;
305     data_in_t	data_in;
306     reject_t	reject;
307     async_t	async;
308};
309
310/*
311 | Sequence Numbers
312 */
313typedef struct {
314     u_int	itt;
315     u_int      cmd;
316     u_int      expCmd;
317     u_int      maxCmd;
318     u_int      stat;
319     u_int      expStat;
320     u_int      data;
321} sn_t;
322
323/*
324 | in-core version of a Protocol Data Unit
325 */
326typedef struct {
327     union ipdu_u	ipdu;
328
329     ahs_t		*ahs;
330     u_int		ahs_len;
331     u_int		ahs_size;	// the allocated size
332     u_int		hdr_dig;	// header digest
333
334     u_char		*ds;
335     u_int		ds_len;
336     u_int		ds_size;	// the allocated size
337     u_int		ds_dig;		// data digest
338} pdu_t;
339
340typedef struct opvals {
341     int	port;
342     int	tags;
343     int	maxluns;
344     int	sockbufsize;
345
346     int	maxConnections;
347     int	maxRecvDataSegmentLength;
348     int	maxXmitDataSegmentLength; // pseudo ...
349     int	maxBurstLength;
350     int	firstBurstLength;
351     int	defaultTime2Wait;
352     int	defaultTime2Retain;
353     int	maxOutstandingR2T;
354     int	errorRecoveryLevel;
355     int	targetPortalGroupTag;
356
357     boolean_t	initialR2T;
358     boolean_t	immediateData;
359     boolean_t	dataPDUInOrder;
360     boolean_t	dataSequenceInOrder;
361     char	*headerDigest;
362     char	*dataDigest;
363     char	*sessionType;
364     char	*sendTargets;
365     char	*targetAddress;
366     char	*targetAlias;
367     char	*targetName;
368     char	*initiatorName;
369     char	*initiatorAlias;
370     char	*authMethod;
371     char	*chapSecret;
372     char	*chapIName;
373     char	*chapDigest;
374     char	*tgtChapName;
375     char	*tgtChapSecret;
376     int	tgtChallengeLen;
377     u_char	tgtChapID;
378     char	*tgtChapDigest;
379     char	*iqn;
380} isc_opt_t;
381
382/*
383 | ioctl
384 */
385#define ISCSISETSES	_IOR('i', 1, int)
386#define ISCSISETSOC	_IOW('i', 2, int)
387#define ISCSISETOPT	_IOW('i', 5, isc_opt_t)
388#define ISCSIGETOPT	_IOR('i', 6, isc_opt_t)
389
390#define ISCSISEND	_IOW('i', 10, pdu_t)
391#define ISCSIRECV	_IOWR('i', 11, pdu_t)
392
393#define ISCSIPING	_IO('i', 20)
394#define ISCSISIGNAL	_IOW('i', 21, int *)
395
396#define ISCSISTART	_IO('i', 30)
397#define ISCSIRESTART	_IO('i', 31)
398#define ISCSISTOP	_IO('i', 32)
399
400typedef struct iscsi_cam {
401     path_id_t		path_id;
402     target_id_t	target_id;
403     int		target_nluns;
404     lun_id_t		target_lun[ISCSI_MAX_LUNS];
405} iscsi_cam_t;
406
407#define ISCSIGETCAM	_IOR('i', 33, iscsi_cam_t)
408