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 #include <sys/stdint.h>
37 #include <sys/objcache.h>
38 #include <bus/cam/cam.h>
39 #include <sys/device.h>
41 #define ISCSIDEV "iscsi"
43 #define ISCSI_MAX_TARGETS 4 //64
45 #define ISCSI_MAX_LUNS 4
54 #define ISCSI_NOP_OUT 0x00
55 #define ISCSI_SCSI_CMD 0x01
56 #define ISCSI_TASK_CMD 0x02
57 #define ISCSI_LOGIN_CMD 0x03
58 #define ISCSI_TEXT_CMD 0x04
59 #define ISCSI_WRITE_DATA 0x05
60 #define ISCSI_LOGOUT_CMD 0x06
61 #define ISCSI_SNACK 0x10
65 #define ISCSI_NOP_IN 0x20
66 #define ISCSI_SCSI_RSP 0x21
67 #define ISCSI_TASK_RSP 0x22
68 #define ISCSI_LOGIN_RSP 0x23
69 #define ISCSI_TEXT_RSP 0x24
70 #define ISCSI_READ_DATA 0x25
71 #define ISCSI_LOGOUT_RSP 0x26
72 #define ISCSI_R2T 0x31
73 #define ISCSI_ASYNC 0x32
74 #define ISCSI_REJECT 0x3f
79 | BHS Basic Header Segment
82 // the order is network byte order!
87 u_char F
:1; // Final bit
90 u_int AHSLength
:8; // in 4byte words
91 u_int DSLength
:24; // in bytes
93 u_int LUN
[2]; // or Opcode-specific fields
95 u_int OpcodeSpecificFields
[7];
96 #define CmdSN OpcodeSpecificFields[1]
97 #define ExpStSN OpcodeSpecificFields[2]
98 #define MaxCmdSN OpcodeSpecificFields[3]
110 // (computers were invented to count, right?)
118 // (computers were invented to count, right?)
124 typedef struct scsi_req
{
125 u_char opcode
:6; // 0x01
134 #define iSCSI_TASK_UNTAGGED 0
135 #define iSCSI_TASK_SIMPLE 1
136 #define iSCSI_TASK_ORDER 2
137 #define iSCSI_TASK_HOFQ 3
138 #define iSCSI_TASK_ACA 4
143 int edtlen
; // expectect data transfere length
149 typedef struct scsi_rsp
{
161 int bdrcnt
; // bidirectional residual count
162 int rcnt
; // residual count
165 typedef struct nop_out
{
166 // the order is network byte order!
171 u_char F
:1; // Final bit
182 typedef struct nop_in
{
183 // the order is network byte order!
188 u_char F
:1; // Final bit
205 u_char F
:1; // Final bit
218 typedef struct data_out
{
223 u_char F
:1; // Final bit
231 u_int dsn
; // data seq. number
236 typedef struct data_in
{
246 u_char F
:1; // Final bit
260 typedef struct reject
{
270 u_int tt
[2]; // must be -1
272 u_int dataSN
; // or R2TSN or reserved
276 typedef struct async
{
285 u_int itt
; // must be -1
299 typedef struct login_req
{
311 int len
; // remapped via standard bhs
314 int itt
; // Initiator Task Tag;
324 typedef struct login_rsp
{
335 int len
; // remapped via standard bhs
338 int itt
; // Initiator Task Tag;
346 typedef struct text_req
{
350 u_char C
:1; // Continuation
355 int itt
; // Initiator Task Tag
357 int ttt
; // Target Transfer Tag
363 typedef struct logout_req
{
365 char reason
; // 0 - close session
366 // 1 - close connection
367 // 2 - remove the connection for recovery
372 int itt
; // Initiator Task Tag;
382 typedef struct logout_rsp
{
423 | in-core version of a Protocol Data Unit
430 u_int ahs_size
; // the allocated size
431 u_int hdr_dig
; // header digest
435 u_int ds_size
; // the allocated size
436 u_int ds_dig
; // data digest
439 typedef struct opvals
{
446 int maxRecvDataSegmentLength
;
447 int maxXmitDataSegmentLength
; // pseudo ...
449 int firstBurstLength
;
450 int defaultTime2Wait
;
451 int defaultTime2Retain
;
452 int maxOutstandingR2T
;
453 int errorRecoveryLevel
;
454 int targetPortalGroupTag
;
459 bool dataSequenceInOrder
;
468 char *initiatorAlias
;
484 #define ISCSISETSES _IOR('i', 1, int)
485 #define ISCSISETSOC _IOW('i', 2, int)
486 #define ISCSISETOPT _IOW('i', 5, isc_opt_t)
487 #define ISCSIGETOPT _IOR('i', 6, isc_opt_t)
489 #define ISCSISEND _IOW('i', 10, pdu_t)
490 #define ISCSIRECV _IOWR('i', 11, pdu_t)
492 #define ISCSIPING _IO('i', 20)
493 #define ISCSISIGNAL _IOW('i', 21, int *)
495 #define ISCSISTART _IO('i', 30)
496 #define ISCSIRESTART _IO('i', 31)
497 #define ISCSISTOP _IO('i', 32)
499 typedef struct iscsi_cam
{
501 target_id_t target_id
;
503 lun_id_t target_lun
[ISCSI_MAX_LUNS
];
506 #define ISCSIGETCAM _IOR('i', 33, iscsi_cam_t)