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