]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/target/iscsi/iscsi_target_core.h
Merge remote-tracking branch 'spi/fix/s3c64xx' into spi-linus
[karo-tx-linux.git] / drivers / target / iscsi / iscsi_target_core.h
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>
10 #include <target/target_core_base.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
63 enum iscsit_transport_type {
64         ISCSI_TCP                               = 0,
65         ISCSI_SCTP_TCP                          = 1,
66         ISCSI_SCTP_UDP                          = 2,
67         ISCSI_IWARP_TCP                         = 3,
68         ISCSI_IWARP_SCTP                        = 4,
69         ISCSI_INFINIBAND                        = 5,
70 };
71
72 /* RFC-3720 7.1.4  Standard Connection State Diagram for a Target */
73 enum target_conn_state_table {
74         TARG_CONN_STATE_FREE                    = 0x1,
75         TARG_CONN_STATE_XPT_UP                  = 0x3,
76         TARG_CONN_STATE_IN_LOGIN                = 0x4,
77         TARG_CONN_STATE_LOGGED_IN               = 0x5,
78         TARG_CONN_STATE_IN_LOGOUT               = 0x6,
79         TARG_CONN_STATE_LOGOUT_REQUESTED        = 0x7,
80         TARG_CONN_STATE_CLEANUP_WAIT            = 0x8,
81 };
82
83 /* RFC-3720 7.3.2  Session State Diagram for a Target */
84 enum target_sess_state_table {
85         TARG_SESS_STATE_FREE                    = 0x1,
86         TARG_SESS_STATE_ACTIVE                  = 0x2,
87         TARG_SESS_STATE_LOGGED_IN               = 0x3,
88         TARG_SESS_STATE_FAILED                  = 0x4,
89         TARG_SESS_STATE_IN_CONTINUE             = 0x5,
90 };
91
92 /* struct iscsi_data_count->type */
93 enum data_count_type {
94         ISCSI_RX_DATA   = 1,
95         ISCSI_TX_DATA   = 2,
96 };
97
98 /* struct iscsi_datain_req->dr_complete */
99 enum datain_req_comp_table {
100         DATAIN_COMPLETE_NORMAL                  = 1,
101         DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
102         DATAIN_COMPLETE_CONNECTION_RECOVERY     = 3,
103 };
104
105 /* struct iscsi_datain_req->recovery */
106 enum datain_req_rec_table {
107         DATAIN_WITHIN_COMMAND_RECOVERY          = 1,
108         DATAIN_CONNECTION_RECOVERY              = 2,
109 };
110
111 /* struct iscsi_portal_group->state */
112 enum tpg_state_table {
113         TPG_STATE_FREE                          = 0,
114         TPG_STATE_ACTIVE                        = 1,
115         TPG_STATE_INACTIVE                      = 2,
116         TPG_STATE_COLD_RESET                    = 3,
117 };
118
119 /* struct iscsi_tiqn->tiqn_state */
120 enum tiqn_state_table {
121         TIQN_STATE_ACTIVE                       = 1,
122         TIQN_STATE_SHUTDOWN                     = 2,
123 };
124
125 /* struct iscsi_cmd->cmd_flags */
126 enum cmd_flags_table {
127         ICF_GOT_LAST_DATAOUT                    = 0x00000001,
128         ICF_GOT_DATACK_SNACK                    = 0x00000002,
129         ICF_NON_IMMEDIATE_UNSOLICITED_DATA      = 0x00000004,
130         ICF_SENT_LAST_R2T                       = 0x00000008,
131         ICF_WITHIN_COMMAND_RECOVERY             = 0x00000010,
132         ICF_CONTIG_MEMORY                       = 0x00000020,
133         ICF_ATTACHED_TO_RQUEUE                  = 0x00000040,
134         ICF_OOO_CMDSN                           = 0x00000080,
135         IFC_SENDTARGETS_ALL                     = 0x00000100,
136         IFC_SENDTARGETS_SINGLE                  = 0x00000200,
137 };
138
139 /* struct iscsi_cmd->i_state */
140 enum cmd_i_state_table {
141         ISTATE_NO_STATE                 = 0,
142         ISTATE_NEW_CMD                  = 1,
143         ISTATE_DEFERRED_CMD             = 2,
144         ISTATE_UNSOLICITED_DATA         = 3,
145         ISTATE_RECEIVE_DATAOUT          = 4,
146         ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
147         ISTATE_RECEIVED_LAST_DATAOUT    = 6,
148         ISTATE_WITHIN_DATAOUT_RECOVERY  = 7,
149         ISTATE_IN_CONNECTION_RECOVERY   = 8,
150         ISTATE_RECEIVED_TASKMGT         = 9,
151         ISTATE_SEND_ASYNCMSG            = 10,
152         ISTATE_SENT_ASYNCMSG            = 11,
153         ISTATE_SEND_DATAIN              = 12,
154         ISTATE_SEND_LAST_DATAIN         = 13,
155         ISTATE_SENT_LAST_DATAIN         = 14,
156         ISTATE_SEND_LOGOUTRSP           = 15,
157         ISTATE_SENT_LOGOUTRSP           = 16,
158         ISTATE_SEND_NOPIN               = 17,
159         ISTATE_SENT_NOPIN               = 18,
160         ISTATE_SEND_REJECT              = 19,
161         ISTATE_SENT_REJECT              = 20,
162         ISTATE_SEND_R2T                 = 21,
163         ISTATE_SENT_R2T                 = 22,
164         ISTATE_SEND_R2T_RECOVERY        = 23,
165         ISTATE_SENT_R2T_RECOVERY        = 24,
166         ISTATE_SEND_LAST_R2T            = 25,
167         ISTATE_SENT_LAST_R2T            = 26,
168         ISTATE_SEND_LAST_R2T_RECOVERY   = 27,
169         ISTATE_SENT_LAST_R2T_RECOVERY   = 28,
170         ISTATE_SEND_STATUS              = 29,
171         ISTATE_SEND_STATUS_BROKEN_PC    = 30,
172         ISTATE_SENT_STATUS              = 31,
173         ISTATE_SEND_STATUS_RECOVERY     = 32,
174         ISTATE_SENT_STATUS_RECOVERY     = 33,
175         ISTATE_SEND_TASKMGTRSP          = 34,
176         ISTATE_SENT_TASKMGTRSP          = 35,
177         ISTATE_SEND_TEXTRSP             = 36,
178         ISTATE_SENT_TEXTRSP             = 37,
179         ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
180         ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
181         ISTATE_SEND_NOPIN_NO_RESPONSE   = 40,
182         ISTATE_REMOVE                   = 41,
183         ISTATE_FREE                     = 42,
184 };
185
186 /* Used for iscsi_recover_cmdsn() return values */
187 enum recover_cmdsn_ret_table {
188         CMDSN_ERROR_CANNOT_RECOVER      = -1,
189         CMDSN_NORMAL_OPERATION          = 0,
190         CMDSN_LOWER_THAN_EXP            = 1,
191         CMDSN_HIGHER_THAN_EXP           = 2,
192 };
193
194 /* Used for iscsi_handle_immediate_data() return values */
195 enum immedate_data_ret_table {
196         IMMEDIATE_DATA_CANNOT_RECOVER   = -1,
197         IMMEDIATE_DATA_NORMAL_OPERATION = 0,
198         IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
199 };
200
201 /* Used for iscsi_decide_dataout_action() return values */
202 enum dataout_action_ret_table {
203         DATAOUT_CANNOT_RECOVER          = -1,
204         DATAOUT_NORMAL                  = 0,
205         DATAOUT_SEND_R2T                = 1,
206         DATAOUT_SEND_TO_TRANSPORT       = 2,
207         DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
208 };
209
210 /* Used for struct iscsi_node_auth->naf_flags */
211 enum naf_flags_table {
212         NAF_USERID_SET                  = 0x01,
213         NAF_PASSWORD_SET                = 0x02,
214         NAF_USERID_IN_SET               = 0x04,
215         NAF_PASSWORD_IN_SET             = 0x08,
216 };
217
218 /* Used by various struct timer_list to manage iSCSI specific state */
219 enum iscsi_timer_flags_table {
220         ISCSI_TF_RUNNING                = 0x01,
221         ISCSI_TF_STOP                   = 0x02,
222         ISCSI_TF_EXPIRED                = 0x04,
223 };
224
225 /* Used for struct iscsi_np->np_flags */
226 enum np_flags_table {
227         NPF_IP_NETWORK          = 0x00,
228 };
229
230 /* Used for struct iscsi_np->np_thread_state */
231 enum np_thread_state_table {
232         ISCSI_NP_THREAD_ACTIVE          = 1,
233         ISCSI_NP_THREAD_INACTIVE        = 2,
234         ISCSI_NP_THREAD_RESET           = 3,
235         ISCSI_NP_THREAD_SHUTDOWN        = 4,
236         ISCSI_NP_THREAD_EXIT            = 5,
237 };
238
239 struct iscsi_conn_ops {
240         u8      HeaderDigest;                   /* [0,1] == [None,CRC32C] */
241         u8      DataDigest;                     /* [0,1] == [None,CRC32C] */
242         u32     MaxRecvDataSegmentLength;       /* [512..2**24-1] */
243         u32     MaxXmitDataSegmentLength;       /* [512..2**24-1] */
244         u8      OFMarker;                       /* [0,1] == [No,Yes] */
245         u8      IFMarker;                       /* [0,1] == [No,Yes] */
246         u32     OFMarkInt;                      /* [1..65535] */
247         u32     IFMarkInt;                      /* [1..65535] */
248         /*
249          * iSER specific connection parameters
250          */
251         u32     InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
252         u32     TargetRecvDataSegmentLength;    /* [512..2**24-1] */
253 };
254
255 struct iscsi_sess_ops {
256         char    InitiatorName[224];
257         char    InitiatorAlias[256];
258         char    TargetName[224];
259         char    TargetAlias[256];
260         char    TargetAddress[256];
261         u16     TargetPortalGroupTag;           /* [0..65535] */
262         u16     MaxConnections;                 /* [1..65535] */
263         u8      InitialR2T;                     /* [0,1] == [No,Yes] */
264         u8      ImmediateData;                  /* [0,1] == [No,Yes] */
265         u32     MaxBurstLength;                 /* [512..2**24-1] */
266         u32     FirstBurstLength;               /* [512..2**24-1] */
267         u16     DefaultTime2Wait;               /* [0..3600] */
268         u16     DefaultTime2Retain;             /* [0..3600] */
269         u16     MaxOutstandingR2T;              /* [1..65535] */
270         u8      DataPDUInOrder;                 /* [0,1] == [No,Yes] */
271         u8      DataSequenceInOrder;            /* [0,1] == [No,Yes] */
272         u8      ErrorRecoveryLevel;             /* [0..2] */
273         u8      SessionType;                    /* [0,1] == [Normal,Discovery]*/
274         /*
275          * iSER specific session parameters
276          */
277         u8      RDMAExtensions;                 /* [0,1] == [No,Yes] */
278 };
279
280 struct iscsi_queue_req {
281         int                     state;
282         struct iscsi_cmd        *cmd;
283         struct list_head        qr_list;
284 };
285
286 struct iscsi_data_count {
287         int                     data_length;
288         int                     sync_and_steering;
289         enum data_count_type    type;
290         u32                     iov_count;
291         u32                     ss_iov_count;
292         u32                     ss_marker_count;
293         struct kvec             *iov;
294 };
295
296 struct iscsi_param_list {
297         bool                    iser;
298         struct list_head        param_list;
299         struct list_head        extra_response_list;
300 };
301
302 struct iscsi_datain_req {
303         enum datain_req_comp_table dr_complete;
304         int                     generate_recovery_values;
305         enum datain_req_rec_table recovery;
306         u32                     begrun;
307         u32                     runlength;
308         u32                     data_length;
309         u32                     data_offset;
310         u32                     data_sn;
311         u32                     next_burst_len;
312         u32                     read_data_done;
313         u32                     seq_send_order;
314         struct list_head        cmd_datain_node;
315 } ____cacheline_aligned;
316
317 struct iscsi_ooo_cmdsn {
318         u16                     cid;
319         u32                     batch_count;
320         u32                     cmdsn;
321         u32                     exp_cmdsn;
322         struct iscsi_cmd        *cmd;
323         struct list_head        ooo_list;
324 } ____cacheline_aligned;
325
326 struct iscsi_datain {
327         u8                      flags;
328         u32                     data_sn;
329         u32                     length;
330         u32                     offset;
331 } ____cacheline_aligned;
332
333 struct iscsi_r2t {
334         int                     seq_complete;
335         int                     recovery_r2t;
336         int                     sent_r2t;
337         u32                     r2t_sn;
338         u32                     offset;
339         u32                     targ_xfer_tag;
340         u32                     xfer_len;
341         struct list_head        r2t_list;
342 } ____cacheline_aligned;
343
344 struct iscsi_cmd {
345         enum iscsi_timer_flags_table dataout_timer_flags;
346         /* DataOUT timeout retries */
347         u8                      dataout_timeout_retries;
348         /* Within command recovery count */
349         u8                      error_recovery_count;
350         /* iSCSI dependent state for out or order CmdSNs */
351         enum cmd_i_state_table  deferred_i_state;
352         /* iSCSI dependent state */
353         enum cmd_i_state_table  i_state;
354         /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
355         u8                      immediate_cmd;
356         /* Immediate data present */
357         u8                      immediate_data;
358         /* iSCSI Opcode */
359         u8                      iscsi_opcode;
360         /* iSCSI Response Code */
361         u8                      iscsi_response;
362         /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
363         u8                      logout_reason;
364         /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
365         u8                      logout_response;
366         /* MaxCmdSN has been incremented */
367         u8                      maxcmdsn_inc;
368         /* Immediate Unsolicited Dataout */
369         u8                      unsolicited_data;
370         /* Reject reason code */
371         u8                      reject_reason;
372         /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
373         u16                     logout_cid;
374         /* Command flags */
375         enum cmd_flags_table    cmd_flags;
376         /* Initiator Task Tag assigned from Initiator */
377         itt_t                   init_task_tag;
378         /* Target Transfer Tag assigned from Target */
379         u32                     targ_xfer_tag;
380         /* CmdSN assigned from Initiator */
381         u32                     cmd_sn;
382         /* ExpStatSN assigned from Initiator */
383         u32                     exp_stat_sn;
384         /* StatSN assigned to this ITT */
385         u32                     stat_sn;
386         /* DataSN Counter */
387         u32                     data_sn;
388         /* R2TSN Counter */
389         u32                     r2t_sn;
390         /* Last DataSN acknowledged via DataAck SNACK */
391         u32                     acked_data_sn;
392         /* Used for echoing NOPOUT ping data */
393         u32                     buf_ptr_size;
394         /* Used to store DataDigest */
395         u32                     data_crc;
396         /* Counter for MaxOutstandingR2T */
397         u32                     outstanding_r2ts;
398         /* Next R2T Offset when DataSequenceInOrder=Yes */
399         u32                     r2t_offset;
400         /* Iovec current and orig count for iscsi_cmd->iov_data */
401         u32                     iov_data_count;
402         u32                     orig_iov_data_count;
403         /* Number of miscellaneous iovecs used for IP stack calls */
404         u32                     iov_misc_count;
405         /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
406         u32                     pdu_count;
407         /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
408         u32                     pdu_send_order;
409         /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
410         u32                     pdu_start;
411         /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
412         u32                     seq_send_order;
413         /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
414         u32                     seq_count;
415         /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
416         u32                     seq_no;
417         /* Lowest offset in current DataOUT sequence */
418         u32                     seq_start_offset;
419         /* Highest offset in current DataOUT sequence */
420         u32                     seq_end_offset;
421         /* Total size in bytes received so far of READ data */
422         u32                     read_data_done;
423         /* Total size in bytes received so far of WRITE data */
424         u32                     write_data_done;
425         /* Counter for FirstBurstLength key */
426         u32                     first_burst_len;
427         /* Counter for MaxBurstLength key */
428         u32                     next_burst_len;
429         /* Transfer size used for IP stack calls */
430         u32                     tx_size;
431         /* Buffer used for various purposes */
432         void                    *buf_ptr;
433         /* Used by SendTargets=[iqn.,eui.] discovery */
434         void                    *text_in_ptr;
435         /* See include/linux/dma-mapping.h */
436         enum dma_data_direction data_direction;
437         /* iSCSI PDU Header + CRC */
438         unsigned char           pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
439         /* Number of times struct iscsi_cmd is present in immediate queue */
440         atomic_t                immed_queue_count;
441         atomic_t                response_queue_count;
442         spinlock_t              datain_lock;
443         spinlock_t              dataout_timeout_lock;
444         /* spinlock for protecting struct iscsi_cmd->i_state */
445         spinlock_t              istate_lock;
446         /* spinlock for adding within command recovery entries */
447         spinlock_t              error_lock;
448         /* spinlock for adding R2Ts */
449         spinlock_t              r2t_lock;
450         /* DataIN List */
451         struct list_head        datain_list;
452         /* R2T List */
453         struct list_head        cmd_r2t_list;
454         /* Timer for DataOUT */
455         struct timer_list       dataout_timer;
456         /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
457         struct kvec             *iov_data;
458         /* Iovecs for miscellaneous purposes */
459 #define ISCSI_MISC_IOVECS                       5
460         struct kvec             iov_misc[ISCSI_MISC_IOVECS];
461         /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
462         struct iscsi_pdu        *pdu_list;
463         /* Current struct iscsi_pdu used for DataPDUInOrder=No */
464         struct iscsi_pdu        *pdu_ptr;
465         /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
466         struct iscsi_seq        *seq_list;
467         /* Current struct iscsi_seq used for DataSequenceInOrder=No */
468         struct iscsi_seq        *seq_ptr;
469         /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
470         struct iscsi_tmr_req    *tmr_req;
471         /* Connection this command is alligient to */
472         struct iscsi_conn       *conn;
473         /* Pointer to connection recovery entry */
474         struct iscsi_conn_recovery *cr;
475         /* Session the command is part of,  used for connection recovery */
476         struct iscsi_session    *sess;
477         /* list_head for connection list */
478         struct list_head        i_conn_node;
479         /* The TCM I/O descriptor that is accessed via container_of() */
480         struct se_cmd           se_cmd;
481         /* Sense buffer that will be mapped into outgoing status */
482 #define ISCSI_SENSE_BUFFER_LEN          (TRANSPORT_SENSE_BUFFER + 2)
483         unsigned char           sense_buffer[ISCSI_SENSE_BUFFER_LEN];
484
485         u32                     padding;
486         u8                      pad_bytes[4];
487
488         struct scatterlist      *first_data_sg;
489         u32                     first_data_sg_off;
490         u32                     kmapped_nents;
491         sense_reason_t          sense_reason;
492         void (*release_cmd)(struct iscsi_cmd *);
493 }  ____cacheline_aligned;
494
495 struct iscsi_tmr_req {
496         bool                    task_reassign:1;
497         u32                     exp_data_sn;
498         struct iscsi_cmd        *ref_cmd;
499         struct iscsi_conn_recovery *conn_recovery;
500         struct se_tmr_req       *se_tmr_req;
501 };
502
503 struct iscsi_conn {
504         wait_queue_head_t       queues_wq;
505         /* Authentication Successful for this connection */
506         u8                      auth_complete;
507         /* State connection is currently in */
508         u8                      conn_state;
509         u8                      conn_logout_reason;
510         u8                      network_transport;
511         enum iscsi_timer_flags_table nopin_timer_flags;
512         enum iscsi_timer_flags_table nopin_response_timer_flags;
513         /* Used to know what thread encountered a transport failure */
514         u8                      which_thread;
515         /* connection id assigned by the Initiator */
516         u16                     cid;
517         /* Remote TCP Port */
518         u16                     login_port;
519         u16                     local_port;
520         int                     net_size;
521         int                     login_family;
522         u32                     auth_id;
523         u32                     conn_flags;
524         /* Used for iscsi_tx_login_rsp() */
525         itt_t                   login_itt;
526         u32                     exp_statsn;
527         /* Per connection status sequence number */
528         u32                     stat_sn;
529         /* IFMarkInt's Current Value */
530         u32                     if_marker;
531         /* OFMarkInt's Current Value */
532         u32                     of_marker;
533         /* Used for calculating OFMarker offset to next PDU */
534         u32                     of_marker_offset;
535 #define IPV6_ADDRESS_SPACE                              48
536         unsigned char           login_ip[IPV6_ADDRESS_SPACE];
537         unsigned char           local_ip[IPV6_ADDRESS_SPACE];
538         int                     conn_usage_count;
539         int                     conn_waiting_on_uc;
540         atomic_t                check_immediate_queue;
541         atomic_t                conn_logout_remove;
542         atomic_t                connection_exit;
543         atomic_t                connection_recovery;
544         atomic_t                connection_reinstatement;
545         atomic_t                connection_wait_rcfr;
546         atomic_t                sleep_on_conn_wait_comp;
547         atomic_t                transport_failed;
548         struct completion       conn_post_wait_comp;
549         struct completion       conn_wait_comp;
550         struct completion       conn_wait_rcfr_comp;
551         struct completion       conn_waiting_on_uc_comp;
552         struct completion       conn_logout_comp;
553         struct completion       tx_half_close_comp;
554         struct completion       rx_half_close_comp;
555         /* socket used by this connection */
556         struct socket           *sock;
557         struct timer_list       nopin_timer;
558         struct timer_list       nopin_response_timer;
559         struct timer_list       transport_timer;
560         /* Spinlock used for add/deleting cmd's from conn_cmd_list */
561         spinlock_t              cmd_lock;
562         spinlock_t              conn_usage_lock;
563         spinlock_t              immed_queue_lock;
564         spinlock_t              nopin_timer_lock;
565         spinlock_t              response_queue_lock;
566         spinlock_t              state_lock;
567         /* libcrypto RX and TX contexts for crc32c */
568         struct hash_desc        conn_rx_hash;
569         struct hash_desc        conn_tx_hash;
570         /* Used for scheduling TX and RX connection kthreads */
571         cpumask_var_t           conn_cpumask;
572         unsigned int            conn_rx_reset_cpumask:1;
573         unsigned int            conn_tx_reset_cpumask:1;
574         /* list_head of struct iscsi_cmd for this connection */
575         struct list_head        conn_cmd_list;
576         struct list_head        immed_queue_list;
577         struct list_head        response_queue_list;
578         struct iscsi_conn_ops   *conn_ops;
579         struct iscsi_login      *conn_login;
580         struct iscsit_transport *conn_transport;
581         struct iscsi_param_list *param_list;
582         /* Used for per connection auth state machine */
583         void                    *auth_protocol;
584         void                    *context;
585         struct iscsi_login_thread_s *login_thread;
586         struct iscsi_portal_group *tpg;
587         /* Pointer to parent session */
588         struct iscsi_session    *sess;
589         /* Pointer to thread_set in use for this conn's threads */
590         struct iscsi_thread_set *thread_set;
591         /* list_head for session connection list */
592         struct list_head        conn_list;
593 } ____cacheline_aligned;
594
595 struct iscsi_conn_recovery {
596         u16                     cid;
597         u32                     cmd_count;
598         u32                     maxrecvdatasegmentlength;
599         u32                     maxxmitdatasegmentlength;
600         int                     ready_for_reallegiance;
601         struct list_head        conn_recovery_cmd_list;
602         spinlock_t              conn_recovery_cmd_lock;
603         struct timer_list       time2retain_timer;
604         struct iscsi_session    *sess;
605         struct list_head        cr_list;
606 }  ____cacheline_aligned;
607
608 struct iscsi_session {
609         u8                      initiator_vendor;
610         u8                      isid[6];
611         enum iscsi_timer_flags_table time2retain_timer_flags;
612         u8                      version_active;
613         u16                     cid_called;
614         u16                     conn_recovery_count;
615         u16                     tsih;
616         /* state session is currently in */
617         u32                     session_state;
618         /* session wide counter: initiator assigned task tag */
619         itt_t                   init_task_tag;
620         /* session wide counter: target assigned task tag */
621         u32                     targ_xfer_tag;
622         u32                     cmdsn_window;
623
624         /* protects cmdsn values */
625         struct mutex            cmdsn_mutex;
626         /* session wide counter: expected command sequence number */
627         u32                     exp_cmd_sn;
628         /* session wide counter: maximum allowed command sequence number */
629         u32                     max_cmd_sn;
630         struct list_head        sess_ooo_cmdsn_list;
631
632         /* LIO specific session ID */
633         u32                     sid;
634         char                    auth_type[8];
635         /* unique within the target */
636         int                     session_index;
637         /* Used for session reference counting */
638         int                     session_usage_count;
639         int                     session_waiting_on_uc;
640         u32                     cmd_pdus;
641         u32                     rsp_pdus;
642         u64                     tx_data_octets;
643         u64                     rx_data_octets;
644         u32                     conn_digest_errors;
645         u32                     conn_timeout_errors;
646         u64                     creation_time;
647         spinlock_t              session_stats_lock;
648         /* Number of active connections */
649         atomic_t                nconn;
650         atomic_t                session_continuation;
651         atomic_t                session_fall_back_to_erl0;
652         atomic_t                session_logout;
653         atomic_t                session_reinstatement;
654         atomic_t                session_stop_active;
655         atomic_t                sleep_on_sess_wait_comp;
656         /* connection list */
657         struct list_head        sess_conn_list;
658         struct list_head        cr_active_list;
659         struct list_head        cr_inactive_list;
660         spinlock_t              conn_lock;
661         spinlock_t              cr_a_lock;
662         spinlock_t              cr_i_lock;
663         spinlock_t              session_usage_lock;
664         spinlock_t              ttt_lock;
665         struct completion       async_msg_comp;
666         struct completion       reinstatement_comp;
667         struct completion       session_wait_comp;
668         struct completion       session_waiting_on_uc_comp;
669         struct timer_list       time2retain_timer;
670         struct iscsi_sess_ops   *sess_ops;
671         struct se_session       *se_sess;
672         struct iscsi_portal_group *tpg;
673 } ____cacheline_aligned;
674
675 struct iscsi_login {
676         u8 auth_complete;
677         u8 checked_for_existing;
678         u8 current_stage;
679         u8 leading_connection;
680         u8 first_request;
681         u8 version_min;
682         u8 version_max;
683         u8 login_complete;
684         u8 login_failed;
685         char isid[6];
686         u32 cmd_sn;
687         itt_t init_task_tag;
688         u32 initial_exp_statsn;
689         u32 rsp_length;
690         u16 cid;
691         u16 tsih;
692         char req[ISCSI_HDR_LEN];
693         char rsp[ISCSI_HDR_LEN];
694         char *req_buf;
695         char *rsp_buf;
696         struct iscsi_conn *conn;
697 } ____cacheline_aligned;
698
699 struct iscsi_node_attrib {
700         u32                     dataout_timeout;
701         u32                     dataout_timeout_retries;
702         u32                     default_erl;
703         u32                     nopin_timeout;
704         u32                     nopin_response_timeout;
705         u32                     random_datain_pdu_offsets;
706         u32                     random_datain_seq_offsets;
707         u32                     random_r2t_offsets;
708         u32                     tmr_cold_reset;
709         u32                     tmr_warm_reset;
710         struct iscsi_node_acl *nacl;
711 };
712
713 struct se_dev_entry_s;
714
715 struct iscsi_node_auth {
716         enum naf_flags_table    naf_flags;
717         int                     authenticate_target;
718         /* Used for iscsit_global->discovery_auth,
719          * set to zero (auth disabled) by default */
720         int                     enforce_discovery_auth;
721 #define MAX_USER_LEN                            256
722 #define MAX_PASS_LEN                            256
723         char                    userid[MAX_USER_LEN];
724         char                    password[MAX_PASS_LEN];
725         char                    userid_mutual[MAX_USER_LEN];
726         char                    password_mutual[MAX_PASS_LEN];
727 };
728
729 #include "iscsi_target_stat.h"
730
731 struct iscsi_node_stat_grps {
732         struct config_group     iscsi_sess_stats_group;
733         struct config_group     iscsi_conn_stats_group;
734 };
735
736 struct iscsi_node_acl {
737         struct iscsi_node_attrib node_attrib;
738         struct iscsi_node_auth  node_auth;
739         struct iscsi_node_stat_grps node_stat_grps;
740         struct se_node_acl      se_node_acl;
741 };
742
743 #define NODE_STAT_GRPS(nacl)    (&(nacl)->node_stat_grps)
744
745 #define ISCSI_NODE_ATTRIB(t)    (&(t)->node_attrib)
746 #define ISCSI_NODE_AUTH(t)      (&(t)->node_auth)
747
748 struct iscsi_tpg_attrib {
749         u32                     authentication;
750         u32                     login_timeout;
751         u32                     netif_timeout;
752         u32                     generate_node_acls;
753         u32                     cache_dynamic_acls;
754         u32                     default_cmdsn_depth;
755         u32                     demo_mode_write_protect;
756         u32                     prod_mode_write_protect;
757         struct iscsi_portal_group *tpg;
758 };
759
760 struct iscsi_np {
761         int                     np_network_transport;
762         int                     np_ip_proto;
763         int                     np_sock_type;
764         enum np_thread_state_table np_thread_state;
765         enum iscsi_timer_flags_table np_login_timer_flags;
766         u32                     np_exports;
767         enum np_flags_table     np_flags;
768         unsigned char           np_ip[IPV6_ADDRESS_SPACE];
769         u16                     np_port;
770         spinlock_t              np_thread_lock;
771         struct completion       np_restart_comp;
772         struct socket           *np_socket;
773         struct __kernel_sockaddr_storage np_sockaddr;
774         struct task_struct      *np_thread;
775         struct timer_list       np_login_timer;
776         struct iscsi_portal_group *np_login_tpg;
777         void                    *np_context;
778         struct iscsit_transport *np_transport;
779         struct list_head        np_list;
780 } ____cacheline_aligned;
781
782 struct iscsi_tpg_np {
783         struct iscsi_np         *tpg_np;
784         struct iscsi_portal_group *tpg;
785         struct iscsi_tpg_np     *tpg_np_parent;
786         struct list_head        tpg_np_list;
787         struct list_head        tpg_np_child_list;
788         struct list_head        tpg_np_parent_list;
789         struct se_tpg_np        se_tpg_np;
790         spinlock_t              tpg_np_parent_lock;
791 };
792
793 struct iscsi_portal_group {
794         unsigned char           tpg_chap_id;
795         /* TPG State */
796         enum tpg_state_table    tpg_state;
797         /* Target Portal Group Tag */
798         u16                     tpgt;
799         /* Id assigned to target sessions */
800         u16                     ntsih;
801         /* Number of active sessions */
802         u32                     nsessions;
803         /* Number of Network Portals available for this TPG */
804         u32                     num_tpg_nps;
805         /* Per TPG LIO specific session ID. */
806         u32                     sid;
807         /* Spinlock for adding/removing Network Portals */
808         spinlock_t              tpg_np_lock;
809         spinlock_t              tpg_state_lock;
810         struct se_portal_group tpg_se_tpg;
811         struct mutex            tpg_access_lock;
812         struct mutex            np_login_lock;
813         struct iscsi_tpg_attrib tpg_attrib;
814         struct iscsi_node_auth  tpg_demo_auth;
815         /* Pointer to default list of iSCSI parameters for TPG */
816         struct iscsi_param_list *param_list;
817         struct iscsi_tiqn       *tpg_tiqn;
818         struct list_head        tpg_gnp_list;
819         struct list_head        tpg_list;
820 } ____cacheline_aligned;
821
822 #define ISCSI_TPG_C(c)          ((struct iscsi_portal_group *)(c)->tpg)
823 #define ISCSI_TPG_LUN(c, l)  ((iscsi_tpg_list_t *)(c)->tpg->tpg_lun_list_t[l])
824 #define ISCSI_TPG_S(s)          ((struct iscsi_portal_group *)(s)->tpg)
825 #define ISCSI_TPG_ATTRIB(t)     (&(t)->tpg_attrib)
826 #define SE_TPG(tpg)             (&(tpg)->tpg_se_tpg)
827
828 struct iscsi_wwn_stat_grps {
829         struct config_group     iscsi_stat_group;
830         struct config_group     iscsi_instance_group;
831         struct config_group     iscsi_sess_err_group;
832         struct config_group     iscsi_tgt_attr_group;
833         struct config_group     iscsi_login_stats_group;
834         struct config_group     iscsi_logout_stats_group;
835 };
836
837 struct iscsi_tiqn {
838 #define ISCSI_IQN_LEN                           224
839         unsigned char           tiqn[ISCSI_IQN_LEN];
840         enum tiqn_state_table   tiqn_state;
841         int                     tiqn_access_count;
842         u32                     tiqn_active_tpgs;
843         u32                     tiqn_ntpgs;
844         u32                     tiqn_num_tpg_nps;
845         u32                     tiqn_nsessions;
846         struct list_head        tiqn_list;
847         struct list_head        tiqn_tpg_list;
848         spinlock_t              tiqn_state_lock;
849         spinlock_t              tiqn_tpg_lock;
850         struct se_wwn           tiqn_wwn;
851         struct iscsi_wwn_stat_grps tiqn_stat_grps;
852         int                     tiqn_index;
853         struct iscsi_sess_err_stats  sess_err_stats;
854         struct iscsi_login_stats     login_stats;
855         struct iscsi_logout_stats    logout_stats;
856 } ____cacheline_aligned;
857
858 #define WWN_STAT_GRPS(tiqn)     (&(tiqn)->tiqn_stat_grps)
859
860 struct iscsit_global {
861         /* In core shutdown */
862         u32                     in_shutdown;
863         u32                     active_ts;
864         /* Unique identifier used for the authentication daemon */
865         u32                     auth_id;
866         u32                     inactive_ts;
867         /* Thread Set bitmap count */
868         int                     ts_bitmap_count;
869         /* Thread Set bitmap pointer */
870         unsigned long           *ts_bitmap;
871         /* Used for iSCSI discovery session authentication */
872         struct iscsi_node_acl   discovery_acl;
873         struct iscsi_portal_group       *discovery_tpg;
874 };
875
876 #endif /* ISCSI_TARGET_CORE_H */