📄 iscsi.h
字号:
/* * $Id: iscsi.h,v 1.13 2001/04/24 22:26:45 mbrown Exp $ * * iscsi.h contains common definitions useful for iscsi_client and * iscsi_sever modules. In addition, any hardware supported iSCSI * processing might have use of the definitions in this header. These * definitions follow the current internet draft on iSCSI: * ( http://search.ietf.org/internet-drafts/draft-ietf-ips-iscsi-03.txt ) * and is subject to change. These interfaces will not remain constant. * Copyright (C) 2001 Michael F. Brown (mbrown@cs.uml.edu) * * Changes : * * $Log: iscsi.h,v $ * Revision 1.13 2001/04/24 22:26:45 mbrown * moved back to version 3 opcodes * * Revision 1.12 2001/04/21 04:07:01 mbrown * more bug fixing, mount readonly works, use the new DISK file, it * contains a valid ext2 partition * * Revision 1.11 2001/04/15 03:01:04 mostman * Some debugging * * Revision 1.10 2001/04/06 04:07:37 mbrown * bug fix having to do with byte ordering fixed. Added lots of debug * prints in iscsi_client.c now that I can start testing * * Revision 1.9 2001/04/03 09:44:58 mbrown * iscsi.o and iscsi_client.o now successfully compile. * * Revision 1.8 2001/04/03 03:04:39 mbrown * latest and greatest hacks. iscsi_client_reader() implemented along with * iscsi_client_proc_info(). Should be all set to test now, will work * on compiling. * * Revision 1.7 2001/03/15 12:43:31 mbrown * morpheus is going down for spring break, need to sync my * latest stuff so mike and josh can get work done * * Revision 1.6 2001/03/12 10:49:31 mbrown * iscsi_client is now basically fully implemented minus proper * /proc communication and compilation fixes. This is going * to be put aside for now. * * Revision 1.5 2001/03/09 11:03:15 mbrown * implemented queue_command. All that's left is the dispatch * function, /proc stuff, and cleanup. Then its on to help * mostman and jhawkins with the pass-through target. * * Revision 1.4 2001/03/04 10:25:44 mbrown * added typedef's for connection and session * * Revision 1.3 2001/03/02 22:58:56 mbrown * name of iscsi_send changed to iscsi_sendv to look more like unix * functions readv() and writev(). * * Revision 1.2 2001/03/02 08:55:05 mbrown * fixed bug in iscsi_header_t.reject definition * * Revision 1.1 2001/03/02 08:39:13 mbrown * initial revision * * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * */#ifndef _ISCSI_H#define _ISCSI_H#include <linux/types.h>#define ISCSI_HDR_SIZE sizeof(iscsi_header_t)#define ISCSI_OP_MASK 0xFF/* Initiator op codes */#define ISCSI_OP_NOP_OUT 0x00#define ISCSI_OP_SCSI_CMD 0x01#define ISCSI_OP_TASK_CMD 0x02#define ISCSI_OP_LOGIN_CMD 0x03#define ISCSI_OP_TEXT_CMD 0x04#define ISCSI_OP_WRITE_DATA 0x05#define ISCSI_OP_LOGOUT_CMD 0x06#define ISCSI_OP_SACK_REQ 0x10/* Target op codes */#define ISCSI_OP_NOP_IN 0x80#define ISCSI_OP_SCSI_RSP 0x81#define ISCSI_OP_TASK_RSP 0x82#define ISCSI_OP_LOGIN_RSP 0x83#define ISCSI_OP_TEXT_RSP 0x84#define ISCSI_OP_READ_DATA 0x85#define ISCSI_OP_LOGOUT_RSP 0x86#define ISCSI_OP_R2T 0x90#define ISCSI_OP_ASYNC_EVENT 0x91#define ISCSI_OP_REJECT 0xef#define ISCSI_X_BIT 0x80#define ISCSI_P_BIT ISCSI_X_BIT#define ISCSI_R_BIT 0x00400000#define ISCSI_W_BIT 0x00200000#define ISCSI_TASK_ATTR_MASK 0x00070000#define ISCSI_TASK_UNTAG 0x00000000#define ISCSI_TASK_SIMPLE 0x00010000#define ISCSI_TASK_ORDERED 0x00020000#define ISCSI_TASK_H_QUEUE 0x00030000#define ISCSI_TASK_ACA 0x00040000#define ISCSI_RESID_UNDER 0x00010000#define ISCSI_RESID_OVER 0x00020000#define ISCSI_BIDI_UNDER 0x00040000#define ISCSI_BIDI_OVER 0x00080000#define ISCSI_TASK_ABORT 0x00010000#define ISCSI_TASKSET_ABORT 0x00020000#define ISCSI_TASK_CLR_ACA 0x00030000#define ISCSI_TASKSET_CLR 0x00040000#define ISCSI_TASK_LUN_RESET 0x00050000#define ISCSI_TASK_WARM_RESET 0x00060000#define ISCSI_TASK_COLD_RESET 0x00070000#define ISCSI_TASK_COMPLETE 0x00000000#define ISCSI_TASK_NOT_FOUND 0x01000000#define ISCSI_TASK_REJECT 0xff000000#define ISCSI_F_BIT ISCSI_X_BIT#define ISCSI_LOGIN_ACCEPT 0#define ISCSI_LOGIN_REJECT 1#define ISCSI_PORT 4000/* iscsi_header_t * * We probably want a more sane solution than a big union, but for * prototyping purposes this is convenient. This header conforms to: * draft-ietf-ips-iscsi-05.txt except for WN */typedef union iscsi_header_t { u8 op; u8 raw[48]; struct { u8 op; u8 reserved1; u8 version_max; u8 version_min; u32 len; u16 cid; u8 reserved2[2]; u16 isid; u16 tsid; u32 itt; u8 reserved3[4]; u32 init_cmd_rn; /* or 0 */ u8 reserved4[20]; } login_cmd; struct { u8 op; u8 F_reserved1; u8 version_max; u8 version_active; u32 len; u8 reserved2[4]; u16 isid; u16 tsid; u32 itt; u8 reserved3[4]; u32 init_stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 status; u8 reserved4[11]; } login_rsp; struct { u8 op; u8 flags; u8 reserved; u8 add_cdb; u32 len; u64 lun; u32 itt; u32 exp_data_len; /* SAM-2 bytes count */ u32 cmd_rn; u32 exp_stat_rn; u8 cdb[16]; } scsi_cmd; struct { u8 op; u8 flags; u8 reserved1[2]; u32 len; u8 reserved2[8]; u32 itt; u32 resid_cnt; u32 stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 status; u8 reserved3[3]; u16 sense_len; u8 reserved4[2]; u32 bidi_resid_cnt; } scsi_rsp; struct { u8 op; u8 F_reserved1[3]; u32 len; /* 0's in n/a */ u64 lun; u32 itt; u32 ttt; /* or 0xFFFFFFFF */ u8 reserved2[4]; u32 exp_stat_rn; u8 reserved3[8]; u32 buf_offset; u8 reserved4[4]; } scsi_write; struct { u8 op; u8 flags; u8 reserved1[2]; u32 len; u8 reserved2[8]; u32 itt; u32 ttt; /* or 0xFFFFFFFF */ u32 data_rn_stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 status; u8 reserved3[3]; u32 buf_offset; u32 resid_cnt; } scsi_read; struct { u8 op; u8 reserved1[3]; u32 len; u8 reserved2[8]; u32 itt; u32 ttt; u8 reserved3[4]; u32 exp_cmd_rn; u32 max_cmd_rn; u32 desired_data_len; u32 buf_offset; u8 reserved4[4]; } r2t; struct { u8 op; u8 function; u16 reserved1; u32 len; /* 0's if n/a */ u64 lun; u32 itt; /* 0's if n/a */ u32 rtt; u32 cmd_rn; u32 exp_stat_rn; u8 reserved2[16]; } task_cmd; struct { u8 op; u8 reserved1[3]; u32 len; u64 lun; u32 itt; /* 0's if n/a */ u32 rtt; u32 stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 response; u8 reserved2[3]; u8 reserved3[8]; } task_rsp; struct { u8 op; u8 reserved1[3]; u32 len; u32 reserved2[2]; u32 itt; u32 reserved3; u32 cmd_rn; u32 exp_stat_rn; u8 reserved4[16]; } text_cmd; struct { u8 op; u8 reserved1[3]; u32 len; u32 reserved2[2]; u32 itt; u32 reserved3; u32 stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 reserved4[12]; } text_rsp; struct { u8 op; u8 P_reserved1[3]; u32 len; u64 lun; u32 itt; u32 ttt; u32 cmd_rn; u32 exp_stat_rn; u32 exp_data_rn; u8 reserved2[12]; } nop_out; struct { u8 op; u8 P_reserved1[3]; u32 len; u32 reserved2[2]; u32 itt; u32 ttt; u32 stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u8 reserved3[12]; } nop_in; struct { u8 op; u8 reserved1[3]; u32 len; u16 cid; u8 reserved2; u8 reason; u32 reserved3; u32 itt; u8 reserved4[28]; } logout_cmd; struct { u8 op; u8 reserved1[3]; u32 len; u32 reserved2[2]; u32 itt; u32 reserved3[2]; u32 exp_cmd_rn; u32 max_cmd_rn; u8 status; u8 reserved4[3]; u8 reserved5[8]; } logout_rsp; struct { u8 op; u8 reserved1[3]; u32 len; u64 lun; u32 reserved2[2]; u32 stat_rn; u32 exp_cmd_rn; u32 max_cmd_rn; u16 indicator; u16 param1; u16 param2; u16 reserved3; u32 reserved4; } async_event; struct { u8 op; u8 reserved1[3]; u32 len; u32 reserved2[7]; u8 reason; u8 reserved3[3]; u32 reserved4[2]; } reject;} iscsi_header_t;/* Utility functions */extern void iscsi_print_header (void *hdr);/* iscsi_sendv (sock, iov, iovlen) * * Because of the way data should be sent, we're using iovec structures * to pass data to iscsi_sendv. The first argument should be a connected * socket. The second argument should be the address of the first * iovec in a contiguous list, and the third argument specifies how many * iovec structures in the list. The first iov MUST always be the * iscsi header. ie you might do something like: * * struct iovec iov[2]; iov[0].iov_base = &my_header; iov[0].iov_len = 48; * iov[1].iov_base = &my_buf; iov[1].iov_len = my_buf_len; * iscsi_sendv (sock, iov, 2); * * iscsi_sendv() returns the number of bytes sent on successful completion or * a negative value otherwise. */extern s32 iscsi_sendv (struct socket *sock, struct iovec *iov, u32 num_iov);/* iscsi_read_header (sock, hdr) * * sock should be an open and connected socket and hdr should be the * address of a header structure you'd like the header dumped into. * * iscsi_read_header() returns THE NUMBER OF BYTES LEFT IN THE ISCSI MESSAGE * it DOES NOT return the number of bytes read. It returns a negative value * if an error occurs. In most cases, iscsi_read() should be called * immediately after iscsi_read_header() specifying the value returned by * the latter function as the third argument to the former. ie: * * if ((len_left = iscsi_read_header (sock, &my_header)) < 0) { * handle_error(); * } * iscsi_read (sock, &my_buf, len_left); */extern s32 iscsi_read_header (struct socket *sock, iscsi_header_t *hdr);/* iscsi_read (sock, buf, len) * * sock should be an open and connected socket, buf is the address of * the buffer you want the data read into, and len is the number of * bytes to read. * iscsi_read() returns the number of bytes read or a negative value * if an error occurs */extern s32 iscsi_read (struct socket *sock, void *buf, u32 len);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -