2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
26 * $FreeBSD: src/sys/dev/iscsi/initiator/iscsi.h,v 1.2 2008/11/25 07:17:11 scottl Exp $
29 | $Id: iscsi.h,v 1.17 2006/12/01 09:10:17 danny Exp danny $
34 typedef int boolean_t;
37 #include <sys/objcache.h>
38 #include <bus/cam/cam.h>
39 #include <sys/device.h>
40 #include <sys/bootmaj.h>
42 #define ISCSIDEV "iscsi"
44 #define ISCSI_MAX_TARGETS 4 //64
46 #define ISCSI_MAX_LUNS 4
55 #define ISCSI_NOP_OUT 0x00
56 #define ISCSI_SCSI_CMD 0x01
57 #define ISCSI_TASK_CMD 0x02
58 #define ISCSI_LOGIN_CMD 0x03
59 #define ISCSI_TEXT_CMD 0x04
60 #define ISCSI_WRITE_DATA 0x05
61 #define ISCSI_LOGOUT_CMD 0x06
62 #define ISCSI_SNACK 0x10
66 #define ISCSI_NOP_IN 0x20
67 #define ISCSI_SCSI_RSP 0x21
68 #define ISCSI_TASK_RSP 0x22
69 #define ISCSI_LOGIN_RSP 0x23
70 #define ISCSI_TEXT_RSP 0x24
71 #define ISCSI_READ_DATA 0x25
72 #define ISCSI_LOGOUT_RSP 0x26
73 #define ISCSI_R2T 0x31
74 #define ISCSI_ASYNC 0x32
75 #define ISCSI_REJECT 0x3f
80 | BHS Basic Header Segment
83 // the order is network byte order!
88 u_char F:1; // Final bit
91 u_int AHSLength:8; // in 4byte words
92 u_int DSLength:24; // in bytes
94 u_int LUN[2]; // or Opcode-specific fields
96 u_int OpcodeSpecificFields[7];
97 #define CmdSN OpcodeSpecificFields[1]
98 #define ExpStSN OpcodeSpecificFields[2]
99 #define MaxCmdSN OpcodeSpecificFields[3]
111 // (computers were invented to count, right?)
119 // (computers were invented to count, right?)
125 typedef struct scsi_req {
126 u_char opcode:6; // 0x01
135 #define iSCSI_TASK_UNTAGGED 0
136 #define iSCSI_TASK_SIMPLE 1
137 #define iSCSI_TASK_ORDER 2
138 #define iSCSI_TASK_HOFQ 3
139 #define iSCSI_TASK_ACA 4
144 int edtlen; // expectect data transfere length
150 typedef struct scsi_rsp {
162 int bdrcnt; // bidirectional residual count
163 int rcnt; // residual count
166 typedef struct nop_out {
167 // the order is network byte order!
172 u_char F:1; // Final bit
183 typedef struct nop_in {
184 // the order is network byte order!
189 u_char F:1; // Final bit
206 u_char F:1; // Final bit
219 typedef struct data_out {
224 u_char F:1; // Final bit
232 u_int dsn; // data seq. number
237 typedef struct data_in {
247 u_char F:1; // Final bit
261 typedef struct reject {
271 u_int tt[2]; // must be -1
273 u_int dataSN; // or R2TSN or reserved
277 typedef struct async {
286 u_int itt; // must be -1
300 typedef struct login_req {
312 int len; // remapped via standard bhs
315 int itt; // Initiator Task Tag;
325 typedef struct login_rsp {
336 int len; // remapped via standard bhs
339 int itt; // Initiator Task Tag;
347 typedef struct text_req {
351 u_char C:1; // Continuation
356 int itt; // Initiator Task Tag
358 int ttt; // Target Transfer Tag
364 typedef struct logout_req {
366 char reason; // 0 - close session
367 // 1 - close connection
368 // 2 - remove the connection for recovery
373 int itt; // Initiator Task Tag;
383 typedef struct logout_rsp {
424 | in-core version of a Protocol Data Unit
431 u_int ahs_size; // the allocated size
432 u_int hdr_dig; // header digest
436 u_int ds_size; // the allocated size
437 u_int ds_dig; // data digest
440 typedef struct opvals {
447 int maxRecvDataSegmentLength;
448 int maxXmitDataSegmentLength; // pseudo ...
450 int firstBurstLength;
451 int defaultTime2Wait;
452 int defaultTime2Retain;
453 int maxOutstandingR2T;
454 int errorRecoveryLevel;
455 int targetPortalGroupTag;
457 boolean_t initialR2T;
458 boolean_t immediateData;
459 boolean_t dataPDUInOrder;
460 boolean_t dataSequenceInOrder;
469 char *initiatorAlias;
485 #define ISCSISETSES _IOR('i', 1, int)
486 #define ISCSISETSOC _IOW('i', 2, int)
487 #define ISCSISETOPT _IOW('i', 5, isc_opt_t)
488 #define ISCSIGETOPT _IOR('i', 6, isc_opt_t)
490 #define ISCSISEND _IOW('i', 10, pdu_t)
491 #define ISCSIRECV _IOWR('i', 11, pdu_t)
493 #define ISCSIPING _IO('i', 20)
494 #define ISCSISIGNAL _IOW('i', 21, int *)
496 #define ISCSISTART _IO('i', 30)
497 #define ISCSIRESTART _IO('i', 31)
498 #define ISCSISTOP _IO('i', 32)
500 typedef struct iscsi_cam {
502 target_id_t target_id;
504 lun_id_t target_lun[ISCSI_MAX_LUNS];
507 #define ISCSIGETCAM _IOR('i', 33, iscsi_cam_t)