2 * Copyright (C) 2002 - 2003 Ardis Technolgies <roman@ardistech.com>
3 * Copyright (C) 2007 - 2009 Vladislav Bolkhovitin
4 * Copyright (C) 2007 - 2009 ID7 Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #ifndef __ISCSI_HDR_H__
18 #define __ISCSI_HDR_H__
20 #include <linux/types.h>
21 #include <asm/byteorder.h>
23 #define ISCSI_VERSION 0
26 #define __packed __attribute__ ((packed))
33 #if defined(__BIG_ENDIAN_BITFIELD)
36 unsigned datalength:24;
38 #elif defined(__LITTLE_ENDIAN_BITFIELD)
47 u32 spec3[3]; /* 36 */
50 /* Opcode encoding bits */
51 #define ISCSI_OP_RETRY 0x80
52 #define ISCSI_OP_IMMEDIATE 0x40
53 #define ISCSI_OPCODE_MASK 0x3F
55 /* Client to Server Message Opcode values */
56 #define ISCSI_OP_NOOP_OUT 0x00
57 #define ISCSI_OP_SCSI_CMD 0x01
58 #define ISCSI_OP_SCSI_TASK_MGT_MSG 0x02
59 #define ISCSI_OP_LOGIN_CMD 0x03
60 #define ISCSI_OP_TEXT_CMD 0x04
61 #define ISCSI_OP_SCSI_DATA_OUT 0x05
62 #define ISCSI_OP_LOGOUT_CMD 0x06
63 #define ISCSI_OP_SNACK_CMD 0x10
65 /* Server to Client Message Opcode values */
66 #define ISCSI_OP_NOOP_IN 0x20
67 #define ISCSI_OP_SCSI_RSP 0x21
68 #define ISCSI_OP_SCSI_TASK_MGT_RSP 0x22
69 #define ISCSI_OP_LOGIN_RSP 0x23
70 #define ISCSI_OP_TEXT_RSP 0x24
71 #define ISCSI_OP_SCSI_DATA_IN 0x25
72 #define ISCSI_OP_LOGOUT_RSP 0x26
73 #define ISCSI_OP_R2T 0x31
74 #define ISCSI_OP_ASYNC_MSG 0x32
75 #define ISCSI_OP_REJECT 0x3f
77 struct iscsi_ahs_hdr {
82 #define ISCSI_AHSTYPE_CDB 1
83 #define ISCSI_AHSTYPE_RLENGTH 2
87 u8 isid[6]; /* Initiator Session ID */
88 u16 tsih; /* Target Session ID */
93 struct iscsi_scsi_cmd_hdr {
107 #define ISCSI_CMD_FINAL 0x80
108 #define ISCSI_CMD_READ 0x40
109 #define ISCSI_CMD_WRITE 0x20
110 #define ISCSI_CMD_ATTR_MASK 0x07
111 #define ISCSI_CMD_UNTAGGED 0x00
112 #define ISCSI_CMD_SIMPLE 0x01
113 #define ISCSI_CMD_ORDERED 0x02
114 #define ISCSI_CMD_HEAD_OF_QUEUE 0x03
115 #define ISCSI_CMD_ACA 0x04
117 struct iscsi_cdb_ahdr {
124 struct iscsi_rlength_ahdr {
131 struct iscsi_scsi_rsp_hdr {
145 u32 bi_residual_count;
149 #define ISCSI_FLG_RESIDUAL_UNDERFLOW 0x02
150 #define ISCSI_FLG_RESIDUAL_OVERFLOW 0x04
151 #define ISCSI_FLG_BIRESIDUAL_UNDERFLOW 0x08
152 #define ISCSI_FLG_BIRESIDUAL_OVERFLOW 0x10
154 #define ISCSI_RESPONSE_COMMAND_COMPLETED 0x00
155 #define ISCSI_RESPONSE_TARGET_FAILURE 0x01
157 struct iscsi_sense_data {
162 struct iscsi_task_mgt_hdr {
178 #define ISCSI_FUNCTION_MASK 0x7f
180 #define ISCSI_FUNCTION_ABORT_TASK 1
181 #define ISCSI_FUNCTION_ABORT_TASK_SET 2
182 #define ISCSI_FUNCTION_CLEAR_ACA 3
183 #define ISCSI_FUNCTION_CLEAR_TASK_SET 4
184 #define ISCSI_FUNCTION_LOGICAL_UNIT_RESET 5
185 #define ISCSI_FUNCTION_TARGET_WARM_RESET 6
186 #define ISCSI_FUNCTION_TARGET_COLD_RESET 7
187 #define ISCSI_FUNCTION_TASK_REASSIGN 8
189 struct iscsi_task_rsp_hdr {
205 #define ISCSI_RESPONSE_FUNCTION_COMPLETE 0
206 #define ISCSI_RESPONSE_UNKNOWN_TASK 1
207 #define ISCSI_RESPONSE_UNKNOWN_LUN 2
208 #define ISCSI_RESPONSE_TASK_ALLEGIANT 3
209 #define ISCSI_RESPONSE_ALLEGIANCE_REASSIGNMENT_UNSUPPORTED 4
210 #define ISCSI_RESPONSE_FUNCTION_UNSUPPORTED 5
211 #define ISCSI_RESPONSE_NO_AUTHORIZATION 6
212 #define ISCSI_RESPONSE_FUNCTION_REJECTED 255
214 struct iscsi_data_out_hdr {
231 struct iscsi_data_in_hdr {
249 #define ISCSI_FLG_STATUS 0x01
251 struct iscsi_r2t_hdr {
268 struct iscsi_async_msg_hdr {
288 #define ISCSI_ASYNC_SCSI 0
289 #define ISCSI_ASYNC_LOGOUT 1
290 #define ISCSI_ASYNC_DROP_CONNECTION 2
291 #define ISCSI_ASYNC_DROP_SESSION 3
292 #define ISCSI_ASYNC_PARAM_REQUEST 4
293 #define ISCSI_ASYNC_VENDOR 255
295 struct iscsi_text_req_hdr {
309 struct iscsi_text_rsp_hdr {
324 struct iscsi_login_req_hdr {
327 u8 max_version; /* Max. version supported */
328 u8 min_version; /* Min. version supported */
332 u32 itt; /* Initiator Task Tag */
333 u16 cid; /* Connection ID */
340 struct iscsi_login_rsp_hdr {
343 u8 max_version; /* Max. version supported */
344 u8 active_version; /* Active version */
348 u32 itt; /* Initiator Task Tag */
353 u8 status_class; /* see Login RSP ststus classes below */
354 u8 status_detail; /* see Login RSP Status details below */
358 #define ISCSI_FLG_FINAL 0x80
359 #define ISCSI_FLG_TRANSIT 0x80
360 #define ISCSI_FLG_CSG_SECURITY 0x00
361 #define ISCSI_FLG_CSG_LOGIN 0x04
362 #define ISCSI_FLG_CSG_FULL_FEATURE 0x0c
363 #define ISCSI_FLG_CSG_MASK 0x0c
364 #define ISCSI_FLG_NSG_SECURITY 0x00
365 #define ISCSI_FLG_NSG_LOGIN 0x01
366 #define ISCSI_FLG_NSG_FULL_FEATURE 0x03
367 #define ISCSI_FLG_NSG_MASK 0x03
369 /* Login Status response classes */
370 #define ISCSI_STATUS_SUCCESS 0x00
371 #define ISCSI_STATUS_REDIRECT 0x01
372 #define ISCSI_STATUS_INITIATOR_ERR 0x02
373 #define ISCSI_STATUS_TARGET_ERR 0x03
375 /* Login Status response detail codes */
376 /* Class-0 (Success) */
377 #define ISCSI_STATUS_ACCEPT 0x00
379 /* Class-1 (Redirection) */
380 #define ISCSI_STATUS_TGT_MOVED_TEMP 0x01
381 #define ISCSI_STATUS_TGT_MOVED_PERM 0x02
383 /* Class-2 (Initiator Error) */
384 #define ISCSI_STATUS_INIT_ERR 0x00
385 #define ISCSI_STATUS_AUTH_FAILED 0x01
386 #define ISCSI_STATUS_TGT_FORBIDDEN 0x02
387 #define ISCSI_STATUS_TGT_NOT_FOUND 0x03
388 #define ISCSI_STATUS_TGT_REMOVED 0x04
389 #define ISCSI_STATUS_NO_VERSION 0x05
390 #define ISCSI_STATUS_TOO_MANY_CONN 0x06
391 #define ISCSI_STATUS_MISSING_FIELDS 0x07
392 #define ISCSI_STATUS_CONN_ADD_FAILED 0x08
393 #define ISCSI_STATUS_INV_SESSION_TYPE 0x09
394 #define ISCSI_STATUS_SESSION_NOT_FOUND 0x0a
395 #define ISCSI_STATUS_INV_REQ_TYPE 0x0b
397 /* Class-3 (Target Error) */
398 #define ISCSI_STATUS_TARGET_ERROR 0x00
399 #define ISCSI_STATUS_SVC_UNAVAILABLE 0x01
400 #define ISCSI_STATUS_NO_RESOURCES 0x02
402 struct iscsi_logout_req_hdr {
417 struct iscsi_logout_rsp_hdr {
436 struct iscsi_snack_req_hdr {
452 struct iscsi_reject_hdr {
469 #define ISCSI_REASON_RESERVED 0x01
470 #define ISCSI_REASON_DATA_DIGEST_ERROR 0x02
471 #define ISCSI_REASON_DATA_SNACK_REJECT 0x03
472 #define ISCSI_REASON_PROTOCOL_ERROR 0x04
473 #define ISCSI_REASON_UNSUPPORTED_COMMAND 0x05
474 #define ISCSI_REASON_IMMEDIATE_COMMAND_REJECT 0x06
475 #define ISCSI_REASON_TASK_IN_PROGRESS 0x07
476 #define ISCSI_REASON_INVALID_DATA_ACK 0x08
477 #define ISCSI_REASON_INVALID_PDU_FIELD 0x09
478 #define ISCSI_REASON_OUT_OF_RESOURCES 0x0a
479 #define ISCSI_REASON_NEGOTIATION_RESET 0x0b
480 #define ISCSI_REASON_WAITING_LOGOUT 0x0c
483 struct iscsi_nop_out_hdr {
497 struct iscsi_nop_in_hdr {
512 #define ISCSI_RESERVED_TAG (0xffffffffU)
514 #define cmnd_hdr(cmnd) ((struct iscsi_scsi_cmd_hdr *) (&((cmnd)->pdu.bhs)))
515 #define cmnd_ttt(cmnd) cpu_to_be32((cmnd)->pdu.bhs.ttt)
516 #define cmnd_itt(cmnd) cpu_to_be32((cmnd)->pdu.bhs.itt)
517 #define cmnd_opcode(cmnd) ((cmnd)->pdu.bhs.opcode & ISCSI_OPCODE_MASK)
518 #define cmnd_scsicode(cmnd) (cmnd_hdr((cmnd))->scb[0])
521 #endif /* __ISCSI_HDR_H__ */