Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iscsi_target_core.h
Go to the documentation of this file.
1 #ifndef ISCSI_TARGET_CORE_H
2 #define ISCSI_TARGET_CORE_H
3 
4 #include <linux/in.h>
5 #include <linux/configfs.h>
6 #include <net/sock.h>
7 #include <net/tcp.h>
8 #include <scsi/scsi_cmnd.h>
9 #include <scsi/iscsi_proto.h>
11 
12 #define ISCSIT_VERSION "v4.1.0-rc2"
13 #define ISCSI_MAX_DATASN_MISSING_COUNT 16
14 #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
15 #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
16 #define SECONDS_FOR_ASYNC_LOGOUT 10
17 #define SECONDS_FOR_ASYNC_TEXT 10
18 #define SECONDS_FOR_LOGOUT_COMP 15
19 #define WHITE_SPACE " \t\v\f\n\r"
20 
21 /* struct iscsi_node_attrib sanity values */
22 #define NA_DATAOUT_TIMEOUT 3
23 #define NA_DATAOUT_TIMEOUT_MAX 60
24 #define NA_DATAOUT_TIMEOUT_MIX 2
25 #define NA_DATAOUT_TIMEOUT_RETRIES 5
26 #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
27 #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
28 #define NA_NOPIN_TIMEOUT 15
29 #define NA_NOPIN_TIMEOUT_MAX 60
30 #define NA_NOPIN_TIMEOUT_MIN 3
31 #define NA_NOPIN_RESPONSE_TIMEOUT 30
32 #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
33 #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
34 #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
35 #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
36 #define NA_RANDOM_R2T_OFFSETS 0
37 #define NA_DEFAULT_ERL 0
38 #define NA_DEFAULT_ERL_MAX 2
39 #define NA_DEFAULT_ERL_MIN 0
40 
41 /* struct iscsi_tpg_attrib sanity values */
42 #define TA_AUTHENTICATION 1
43 #define TA_LOGIN_TIMEOUT 15
44 #define TA_LOGIN_TIMEOUT_MAX 30
45 #define TA_LOGIN_TIMEOUT_MIN 5
46 #define TA_NETIF_TIMEOUT 2
47 #define TA_NETIF_TIMEOUT_MAX 15
48 #define TA_NETIF_TIMEOUT_MIN 2
49 #define TA_GENERATE_NODE_ACLS 0
50 #define TA_DEFAULT_CMDSN_DEPTH 16
51 #define TA_DEFAULT_CMDSN_DEPTH_MAX 512
52 #define TA_DEFAULT_CMDSN_DEPTH_MIN 1
53 #define TA_CACHE_DYNAMIC_ACLS 0
54 /* Enabled by default in demo mode (generic_node_acls=1) */
55 #define TA_DEMO_MODE_WRITE_PROTECT 1
56 /* Disabled by default in production mode w/ explict ACLs */
57 #define TA_PROD_MODE_WRITE_PROTECT 0
58 #define TA_CACHE_CORE_NPS 0
59 
60 
61 #define ISCSI_IOV_DATA_BUFFER 5
62 
64  ISCSI_TCP = 0,
70 };
71 
72 /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
81 };
82 
83 /* RFC-3720 7.3.2 Session State Diagram for a Target */
90 };
91 
92 /* struct iscsi_data_count->type */
96 };
97 
98 /* struct iscsi_datain_req->dr_complete */
103 };
104 
105 /* struct iscsi_datain_req->recovery */
109 };
110 
111 /* struct iscsi_portal_group->state */
117 };
118 
119 /* struct iscsi_tiqn->tiqn_state */
123 };
124 
125 /* struct iscsi_cmd->cmd_flags */
127  ICF_GOT_LAST_DATAOUT = 0x00000001,
128  ICF_GOT_DATACK_SNACK = 0x00000002,
130  ICF_SENT_LAST_R2T = 0x00000008,
132  ICF_CONTIG_MEMORY = 0x00000020,
134  ICF_OOO_CMDSN = 0x00000080,
135  ICF_REJECT_FAIL_CONN = 0x00000100,
136 };
137 
138 /* struct iscsi_cmd->i_state */
183 };
184 
185 /* Used for iscsi_recover_cmdsn() return values */
191 };
192 
193 /* Used for iscsi_handle_immediate_data() return values */
198 };
199 
200 /* Used for iscsi_decide_dataout_action() return values */
207 };
208 
209 /* Used for struct iscsi_node_auth->naf_flags */
215 };
216 
217 /* Used by various struct timer_list to manage iSCSI specific state */
222 };
223 
224 /* Used for struct iscsi_np->np_flags */
227 };
228 
229 /* Used for struct iscsi_np->np_thread_state */
236 };
237 
239  u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
240  u8 DataDigest; /* [0,1] == [None,CRC32C] */
241  u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
242  u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
243  u8 OFMarker; /* [0,1] == [No,Yes] */
244  u8 IFMarker; /* [0,1] == [No,Yes] */
245  u32 OFMarkInt; /* [1..65535] */
246  u32 IFMarkInt; /* [1..65535] */
247 };
248 
250  char InitiatorName[224];
251  char InitiatorAlias[256];
252  char TargetName[224];
253  char TargetAlias[256];
254  char TargetAddress[256];
255  u16 TargetPortalGroupTag; /* [0..65535] */
256  u16 MaxConnections; /* [1..65535] */
257  u8 InitialR2T; /* [0,1] == [No,Yes] */
258  u8 ImmediateData; /* [0,1] == [No,Yes] */
259  u32 MaxBurstLength; /* [512..2**24-1] */
260  u32 FirstBurstLength; /* [512..2**24-1] */
261  u16 DefaultTime2Wait; /* [0..3600] */
262  u16 DefaultTime2Retain; /* [0..3600] */
263  u16 MaxOutstandingR2T; /* [1..65535] */
264  u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
265  u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
266  u8 ErrorRecoveryLevel; /* [0..2] */
267  u8 SessionType; /* [0,1] == [Normal,Discovery]*/
268 };
269 
271  int state;
272  struct iscsi_cmd *cmd;
274 };
275 
283  struct kvec *iov;
284 };
285 
289 };
290 
305 
311  struct iscsi_cmd *cmd;
314 
315 struct iscsi_datain {
321 
322 struct iscsi_r2t {
325  int sent_r2t;
332 
333 struct iscsi_cmd {
335  /* DataOUT timeout retries */
337  /* Within command recovery count */
339  /* iSCSI dependent state for out or order CmdSNs */
341  /* iSCSI dependent state */
343  /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
345  /* Immediate data present */
347  /* iSCSI Opcode */
349  /* iSCSI Response Code */
351  /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
353  /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
355  /* MaxCmdSN has been incremented */
357  /* Immediate Unsolicited Dataout */
359  /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
361  /* Command flags */
363  /* Initiator Task Tag assigned from Initiator */
365  /* Target Transfer Tag assigned from Target */
367  /* CmdSN assigned from Initiator */
369  /* ExpStatSN assigned from Initiator */
371  /* StatSN assigned to this ITT */
373  /* DataSN Counter */
375  /* R2TSN Counter */
377  /* Last DataSN acknowledged via DataAck SNACK */
379  /* Used for echoing NOPOUT ping data */
381  /* Used to store DataDigest */
383  /* Counter for MaxOutstandingR2T */
385  /* Next R2T Offset when DataSequenceInOrder=Yes */
387  /* Iovec current and orig count for iscsi_cmd->iov_data */
390  /* Number of miscellaneous iovecs used for IP stack calls */
392  /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
394  /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
396  /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
398  /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
400  /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
402  /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
404  /* Lowest offset in current DataOUT sequence */
406  /* Highest offset in current DataOUT sequence */
408  /* Total size in bytes received so far of READ data */
410  /* Total size in bytes received so far of WRITE data */
412  /* Counter for FirstBurstLength key */
414  /* Counter for MaxBurstLength key */
416  /* Transfer size used for IP stack calls */
418  /* Buffer used for various purposes */
419  void *buf_ptr;
420  /* See include/linux/dma-mapping.h */
422  /* iSCSI PDU Header + CRC */
423  unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
424  /* Number of times struct iscsi_cmd is present in immediate queue */
429  /* spinlock for protecting struct iscsi_cmd->i_state */
431  /* spinlock for adding within command recovery entries */
433  /* spinlock for adding R2Ts */
435  /* DataIN List */
437  /* R2T List */
440  /* Timer for DataOUT */
442  /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
443  struct kvec *iov_data;
444  /* Iovecs for miscellaneous purposes */
445 #define ISCSI_MISC_IOVECS 5
447  /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
449  /* Current struct iscsi_pdu used for DataPDUInOrder=No */
451  /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
453  /* Current struct iscsi_seq used for DataSequenceInOrder=No */
455  /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
457  /* Connection this command is alligient to */
458  struct iscsi_conn *conn;
459  /* Pointer to connection recovery entry */
461  /* Session the command is part of, used for connection recovery */
463  /* list_head for connection list */
465  /* The TCM I/O descriptor that is accessed via container_of() */
466  struct se_cmd se_cmd;
467  /* Sense buffer that will be mapped into outgoing status */
468 #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
470 
473 
477 
479 
486 };
487 
488 struct iscsi_conn {
490  /* Authentication Successful for this connection */
492  /* State connection is currently in */
498  /* Used to know what thread encountered a transport failure */
500  /* connection id assigned by the Initiator */
502  /* Remote TCP Port */
505  int net_size;
508  /* Used for iscsi_tx_login_rsp() */
511  /* Per connection status sequence number */
513  /* IFMarkInt's Current Value */
515  /* OFMarkInt's Current Value */
517  /* Used for calculating OFMarker offset to next PDU */
519  /* Complete Bad PDU for sending reject */
520  unsigned char bad_hdr[ISCSI_HDR_LEN];
521 #define IPV6_ADDRESS_SPACE 48
522  unsigned char login_ip[IPV6_ADDRESS_SPACE];
523  unsigned char local_ip[IPV6_ADDRESS_SPACE];
541  /* socket used by this connection */
542  struct socket *sock;
546  /* Spinlock used for add/deleting cmd's from conn_cmd_list */
553  /* libcrypto RX and TX contexts for crc32c */
556  /* Used for scheduling TX and RX connection kthreads */
558  unsigned int conn_rx_reset_cpumask:1;
559  unsigned int conn_tx_reset_cpumask:1;
560  /* list_head of struct iscsi_cmd for this connection */
566  /* Used for per connection auth state machine */
568  struct iscsi_login_thread_s *login_thread;
570  /* Pointer to parent session */
572  /* Pointer to thread_set in use for this conn's threads */
574  /* list_head for session connection list */
577 
590 
593  u8 isid[6];
599  /* state session is currently in */
601  /* session wide counter: initiator assigned task tag */
603  /* session wide counter: target assigned task tag */
606 
607  /* protects cmdsn values */
609  /* session wide counter: expected command sequence number */
611  /* session wide counter: maximum allowed command sequence number */
614 
615  /* LIO specific session ID */
617  char auth_type[8];
618  /* unique within the target */
620  /* Used for session reference counting */
631  /* Number of active connections */
639  /* connection list */
657 
658 struct iscsi_login {
666  char isid[6];
673  char *req;
674  char *rsp;
675  char *req_buf;
676  char *rsp_buf;
678 
691 };
692 
693 struct se_dev_entry_s;
694 
698  /* Used for iscsit_global->discovery_auth,
699  * set to zero (auth disabled) by default */
701 #define MAX_USER_LEN 256
702 #define MAX_PASS_LEN 256
707 };
708 
709 #include "iscsi_target_stat.h"
710 
714 };
715 
721 };
722 
723 #define NODE_STAT_GRPS(nacl) (&(nacl)->node_stat_grps)
724 
725 #define ISCSI_NODE_ATTRIB(t) (&(t)->node_attrib)
726 #define ISCSI_NODE_AUTH(t) (&(t)->node_auth)
727 
738 };
739 
740 struct iscsi_np {
748  unsigned char np_ip[IPV6_ADDRESS_SPACE];
752  struct socket *np_socket;
759 
760 struct iscsi_tpg_np {
761  struct iscsi_np *tpg_np;
769 };
770 
772  unsigned char tpg_chap_id;
773  /* TPG State */
775  /* Target Portal Group Tag */
777  /* Id assigned to target sessions */
779  /* Number of active sessions */
781  /* Number of Network Portals available for this TPG */
783  /* Per TPG LIO specific session ID. */
785  /* Spinlock for adding/removing Network Portals */
792  /* Pointer to default list of iSCSI parameters for TPG */
798 
799 #define ISCSI_TPG_C(c) ((struct iscsi_portal_group *)(c)->tpg)
800 #define ISCSI_TPG_LUN(c, l) ((iscsi_tpg_list_t *)(c)->tpg->tpg_lun_list_t[l])
801 #define ISCSI_TPG_S(s) ((struct iscsi_portal_group *)(s)->tpg)
802 #define ISCSI_TPG_ATTRIB(t) (&(t)->tpg_attrib)
803 #define SE_TPG(tpg) (&(tpg)->tpg_se_tpg)
804 
812 };
813 
814 struct iscsi_tiqn {
815 #define ISCSI_IQN_LEN 224
816  unsigned char tiqn[ISCSI_IQN_LEN];
827  struct se_wwn tiqn_wwn;
834 
835 #define WWN_STAT_GRPS(tiqn) (&(tiqn)->tiqn_stat_grps)
836 
838  /* In core shutdown */
841  /* Unique identifier used for the authentication daemon */
844  /* Thread Set bitmap count */
846  /* Thread Set bitmap pointer */
847  unsigned long *ts_bitmap;
848  /* Used for iSCSI discovery session authentication */
851 };
852 
853 #endif /* ISCSI_TARGET_CORE_H */