1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef ISCSI_TARGET_CORE_H
3 #define ISCSI_TARGET_CORE_H
5 #include <linux/dma-direction.h> /* enum dma_data_direction */
6 #include <linux/list.h> /* struct list_head */
7 #include <linux/sched.h>
8 #include <linux/socket.h> /* struct sockaddr_storage */
9 #include <linux/types.h> /* u8 */
10 #include <scsi/iscsi_proto.h> /* itt_t */
11 #include <target/target_core_base.h> /* struct se_cmd */
15 #define ISCSIT_VERSION "v4.1.0"
16 #define ISCSI_MAX_DATASN_MISSING_COUNT 16
17 #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
18 #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
19 #define SECONDS_FOR_ASYNC_LOGOUT 10
20 #define SECONDS_FOR_ASYNC_TEXT 10
21 #define SECONDS_FOR_LOGOUT_COMP 15
22 #define WHITE_SPACE " \t\v\f\n\r"
23 #define ISCSIT_MIN_TAGS 16
24 #define ISCSIT_EXTRA_TAGS 8
25 #define ISCSIT_TCP_BACKLOG 256
26 #define ISCSI_RX_THREAD_NAME "iscsi_trx"
27 #define ISCSI_TX_THREAD_NAME "iscsi_ttx"
28 #define ISCSI_IQN_LEN 224
30 /* struct iscsi_node_attrib sanity values */
31 #define NA_DATAOUT_TIMEOUT 3
32 #define NA_DATAOUT_TIMEOUT_MAX 60
33 #define NA_DATAOUT_TIMEOUT_MIX 2
34 #define NA_DATAOUT_TIMEOUT_RETRIES 5
35 #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
36 #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
37 #define NA_NOPIN_TIMEOUT 15
38 #define NA_NOPIN_TIMEOUT_MAX 60
39 #define NA_NOPIN_TIMEOUT_MIN 3
40 #define NA_NOPIN_RESPONSE_TIMEOUT 30
41 #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
42 #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
43 #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
44 #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
45 #define NA_RANDOM_R2T_OFFSETS 0
47 /* struct iscsi_tpg_attrib sanity values */
48 #define TA_AUTHENTICATION 1
49 #define TA_LOGIN_TIMEOUT 15
50 #define TA_LOGIN_TIMEOUT_MAX 30
51 #define TA_LOGIN_TIMEOUT_MIN 5
52 #define TA_NETIF_TIMEOUT 2
53 #define TA_NETIF_TIMEOUT_MAX 15
54 #define TA_NETIF_TIMEOUT_MIN 2
55 #define TA_GENERATE_NODE_ACLS 0
56 #define TA_DEFAULT_CMDSN_DEPTH 64
57 #define TA_DEFAULT_CMDSN_DEPTH_MAX 512
58 #define TA_DEFAULT_CMDSN_DEPTH_MIN 1
59 #define TA_CACHE_DYNAMIC_ACLS 0
60 /* Enabled by default in demo mode (generic_node_acls=1) */
61 #define TA_DEMO_MODE_WRITE_PROTECT 1
62 /* Disabled by default in production mode w/ explict ACLs */
63 #define TA_PROD_MODE_WRITE_PROTECT 0
64 #define TA_DEMO_MODE_DISCOVERY 1
65 #define TA_DEFAULT_ERL 0
66 #define TA_CACHE_CORE_NPS 0
67 /* T10 protection information disabled by default */
68 #define TA_DEFAULT_T10_PI 0
69 #define TA_DEFAULT_FABRIC_PROT_TYPE 0
70 /* TPG status needs to be enabled to return sendtargets discovery endpoint info */
71 #define TA_DEFAULT_TPG_ENABLED_SENDTARGETS 1
73 * Used to control the sending of keys with optional to respond state bit,
74 * as a workaround for non RFC compliant initiators,that do not propose,
75 * nor respond to specific keys required for login to complete.
77 * See iscsi_check_proposer_for_optional_reply() for more details.
79 #define TA_DEFAULT_LOGIN_KEYS_WORKAROUND 1
81 #define ISCSI_IOV_DATA_BUFFER 5
83 enum iscsit_transport_type {
93 /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
94 enum target_conn_state_table {
95 TARG_CONN_STATE_FREE = 0x1,
96 TARG_CONN_STATE_XPT_UP = 0x3,
97 TARG_CONN_STATE_IN_LOGIN = 0x4,
98 TARG_CONN_STATE_LOGGED_IN = 0x5,
99 TARG_CONN_STATE_IN_LOGOUT = 0x6,
100 TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
101 TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
104 /* RFC-3720 7.3.2 Session State Diagram for a Target */
105 enum target_sess_state_table {
106 TARG_SESS_STATE_FREE = 0x1,
107 TARG_SESS_STATE_ACTIVE = 0x2,
108 TARG_SESS_STATE_LOGGED_IN = 0x3,
109 TARG_SESS_STATE_FAILED = 0x4,
110 TARG_SESS_STATE_IN_CONTINUE = 0x5,
113 /* struct iscsi_data_count->type */
114 enum data_count_type {
119 /* struct iscsi_datain_req->dr_complete */
120 enum datain_req_comp_table {
121 DATAIN_COMPLETE_NORMAL = 1,
122 DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
123 DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
126 /* struct iscsi_datain_req->recovery */
127 enum datain_req_rec_table {
128 DATAIN_WITHIN_COMMAND_RECOVERY = 1,
129 DATAIN_CONNECTION_RECOVERY = 2,
132 /* struct iscsi_portal_group->state */
133 enum tpg_state_table {
135 TPG_STATE_ACTIVE = 1,
136 TPG_STATE_INACTIVE = 2,
137 TPG_STATE_COLD_RESET = 3,
140 /* struct iscsi_tiqn->tiqn_state */
141 enum tiqn_state_table {
142 TIQN_STATE_ACTIVE = 1,
143 TIQN_STATE_SHUTDOWN = 2,
146 /* struct iscsi_cmd->cmd_flags */
147 enum cmd_flags_table {
148 ICF_GOT_LAST_DATAOUT = 0x00000001,
149 ICF_GOT_DATACK_SNACK = 0x00000002,
150 ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
151 ICF_SENT_LAST_R2T = 0x00000008,
152 ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
153 ICF_CONTIG_MEMORY = 0x00000020,
154 ICF_ATTACHED_TO_RQUEUE = 0x00000040,
155 ICF_OOO_CMDSN = 0x00000080,
156 ICF_SENDTARGETS_ALL = 0x00000100,
157 ICF_SENDTARGETS_SINGLE = 0x00000200,
160 /* struct iscsi_cmd->i_state */
161 enum cmd_i_state_table {
164 ISTATE_DEFERRED_CMD = 2,
165 ISTATE_UNSOLICITED_DATA = 3,
166 ISTATE_RECEIVE_DATAOUT = 4,
167 ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
168 ISTATE_RECEIVED_LAST_DATAOUT = 6,
169 ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
170 ISTATE_IN_CONNECTION_RECOVERY = 8,
171 ISTATE_RECEIVED_TASKMGT = 9,
172 ISTATE_SEND_ASYNCMSG = 10,
173 ISTATE_SENT_ASYNCMSG = 11,
174 ISTATE_SEND_DATAIN = 12,
175 ISTATE_SEND_LAST_DATAIN = 13,
176 ISTATE_SENT_LAST_DATAIN = 14,
177 ISTATE_SEND_LOGOUTRSP = 15,
178 ISTATE_SENT_LOGOUTRSP = 16,
179 ISTATE_SEND_NOPIN = 17,
180 ISTATE_SENT_NOPIN = 18,
181 ISTATE_SEND_REJECT = 19,
182 ISTATE_SENT_REJECT = 20,
183 ISTATE_SEND_R2T = 21,
184 ISTATE_SENT_R2T = 22,
185 ISTATE_SEND_R2T_RECOVERY = 23,
186 ISTATE_SENT_R2T_RECOVERY = 24,
187 ISTATE_SEND_LAST_R2T = 25,
188 ISTATE_SENT_LAST_R2T = 26,
189 ISTATE_SEND_LAST_R2T_RECOVERY = 27,
190 ISTATE_SENT_LAST_R2T_RECOVERY = 28,
191 ISTATE_SEND_STATUS = 29,
192 ISTATE_SEND_STATUS_BROKEN_PC = 30,
193 ISTATE_SENT_STATUS = 31,
194 ISTATE_SEND_STATUS_RECOVERY = 32,
195 ISTATE_SENT_STATUS_RECOVERY = 33,
196 ISTATE_SEND_TASKMGTRSP = 34,
197 ISTATE_SENT_TASKMGTRSP = 35,
198 ISTATE_SEND_TEXTRSP = 36,
199 ISTATE_SENT_TEXTRSP = 37,
200 ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
201 ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
202 ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
207 /* Used for iscsi_recover_cmdsn() return values */
208 enum recover_cmdsn_ret_table {
209 CMDSN_ERROR_CANNOT_RECOVER = -1,
210 CMDSN_NORMAL_OPERATION = 0,
211 CMDSN_LOWER_THAN_EXP = 1,
212 CMDSN_HIGHER_THAN_EXP = 2,
213 CMDSN_MAXCMDSN_OVERRUN = 3,
216 /* Used for iscsi_handle_immediate_data() return values */
217 enum immedate_data_ret_table {
218 IMMEDIATE_DATA_CANNOT_RECOVER = -1,
219 IMMEDIATE_DATA_NORMAL_OPERATION = 0,
220 IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
223 /* Used for iscsi_decide_dataout_action() return values */
224 enum dataout_action_ret_table {
225 DATAOUT_CANNOT_RECOVER = -1,
227 DATAOUT_SEND_R2T = 1,
228 DATAOUT_SEND_TO_TRANSPORT = 2,
229 DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
232 /* Used for struct iscsi_node_auth->naf_flags */
233 enum naf_flags_table {
234 NAF_USERID_SET = 0x01,
235 NAF_PASSWORD_SET = 0x02,
236 NAF_USERID_IN_SET = 0x04,
237 NAF_PASSWORD_IN_SET = 0x08,
240 /* Used by various struct timer_list to manage iSCSI specific state */
241 enum iscsi_timer_flags_table {
242 ISCSI_TF_RUNNING = 0x01,
243 ISCSI_TF_STOP = 0x02,
244 ISCSI_TF_EXPIRED = 0x04,
247 /* Used for struct iscsi_np->np_flags */
248 enum np_flags_table {
249 NPF_IP_NETWORK = 0x00,
252 /* Used for struct iscsi_np->np_thread_state */
253 enum np_thread_state_table {
254 ISCSI_NP_THREAD_ACTIVE = 1,
255 ISCSI_NP_THREAD_INACTIVE = 2,
256 ISCSI_NP_THREAD_RESET = 3,
257 ISCSI_NP_THREAD_SHUTDOWN = 4,
258 ISCSI_NP_THREAD_EXIT = 5,
261 struct iscsi_conn_ops {
262 u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
263 u8 DataDigest; /* [0,1] == [None,CRC32C] */
264 u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
265 u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
267 * iSER specific connection parameters
269 u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
270 u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */
273 struct iscsi_sess_ops {
274 char InitiatorName[ISCSI_IQN_LEN];
275 char InitiatorAlias[256];
276 char TargetName[ISCSI_IQN_LEN];
277 char TargetAlias[256];
278 char TargetAddress[256];
279 u16 TargetPortalGroupTag; /* [0..65535] */
280 u16 MaxConnections; /* [1..65535] */
281 u8 InitialR2T; /* [0,1] == [No,Yes] */
282 u8 ImmediateData; /* [0,1] == [No,Yes] */
283 u32 MaxBurstLength; /* [512..2**24-1] */
284 u32 FirstBurstLength; /* [512..2**24-1] */
285 u16 DefaultTime2Wait; /* [0..3600] */
286 u16 DefaultTime2Retain; /* [0..3600] */
287 u16 MaxOutstandingR2T; /* [1..65535] */
288 u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
289 u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
290 u8 ErrorRecoveryLevel; /* [0..2] */
291 u8 SessionType; /* [0,1] == [Normal,Discovery]*/
293 * iSER specific session parameters
295 u8 RDMAExtensions; /* [0,1] == [No,Yes] */
298 struct iscsi_queue_req {
300 struct iscsi_cmd *cmd;
301 struct list_head qr_list;
304 struct iscsi_param_list {
306 struct list_head param_list;
307 struct list_head extra_response_list;
310 struct iscsi_datain_req {
311 enum datain_req_comp_table dr_complete;
312 int generate_recovery_values;
313 enum datain_req_rec_table recovery;
322 struct list_head cmd_datain_node;
323 } ____cacheline_aligned;
325 struct iscsi_ooo_cmdsn {
330 struct iscsi_cmd *cmd;
331 struct list_head ooo_list;
332 } ____cacheline_aligned;
334 struct iscsi_datain {
339 } ____cacheline_aligned;
349 struct list_head r2t_list;
350 } ____cacheline_aligned;
353 enum iscsi_timer_flags_table dataout_timer_flags;
354 /* DataOUT timeout retries */
355 u8 dataout_timeout_retries;
356 /* Within command recovery count */
357 u8 error_recovery_count;
358 /* iSCSI dependent state for out or order CmdSNs */
359 enum cmd_i_state_table deferred_i_state;
360 /* iSCSI dependent state */
361 enum cmd_i_state_table i_state;
362 /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
364 /* Immediate data present */
368 /* iSCSI Response Code */
370 /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
372 /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
374 /* MaxCmdSN has been incremented */
376 /* Immediate Unsolicited Dataout */
378 /* Reject reason code */
380 /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
383 enum cmd_flags_table cmd_flags;
384 /* Initiator Task Tag assigned from Initiator */
386 /* Target Transfer Tag assigned from Target */
388 /* CmdSN assigned from Initiator */
390 /* ExpStatSN assigned from Initiator */
392 /* StatSN assigned to this ITT */
398 /* Last DataSN acknowledged via DataAck SNACK */
400 /* Used for echoing NOPOUT ping data */
402 /* Used to store DataDigest */
404 /* Counter for MaxOutstandingR2T */
405 u32 outstanding_r2ts;
406 /* Next R2T Offset when DataSequenceInOrder=Yes */
408 /* Iovec current and orig count for iscsi_cmd->iov_data */
410 u32 orig_iov_data_count;
411 /* Number of miscellaneous iovecs used for IP stack calls */
413 /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
415 /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
417 /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
419 /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
421 /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
423 /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
425 /* Lowest offset in current DataOUT sequence */
426 u32 seq_start_offset;
427 /* Highest offset in current DataOUT sequence */
429 /* Total size in bytes received so far of READ data */
431 /* Total size in bytes received so far of WRITE data */
433 /* Counter for FirstBurstLength key */
435 /* Counter for MaxBurstLength key */
437 /* Transfer size used for IP stack calls */
439 /* Buffer used for various purposes */
441 /* Used by SendTargets=[iqn.,eui.] discovery */
443 /* See include/linux/dma-mapping.h */
444 enum dma_data_direction data_direction;
445 /* iSCSI PDU Header + CRC */
446 unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
447 /* Number of times struct iscsi_cmd is present in immediate queue */
448 atomic_t immed_queue_count;
449 atomic_t response_queue_count;
450 spinlock_t datain_lock;
451 spinlock_t dataout_timeout_lock;
452 /* spinlock for protecting struct iscsi_cmd->i_state */
453 spinlock_t istate_lock;
454 /* spinlock for adding within command recovery entries */
455 spinlock_t error_lock;
456 /* spinlock for adding R2Ts */
459 struct list_head datain_list;
461 struct list_head cmd_r2t_list;
462 /* Timer for DataOUT */
463 struct timer_list dataout_timer;
464 /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
465 struct kvec *iov_data;
467 /* Iovecs for miscellaneous purposes */
468 #define ISCSI_MISC_IOVECS 5
469 struct kvec iov_misc[ISCSI_MISC_IOVECS];
470 /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
471 struct iscsi_pdu *pdu_list;
472 /* Current struct iscsi_pdu used for DataPDUInOrder=No */
473 struct iscsi_pdu *pdu_ptr;
474 /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
475 struct iscsi_seq *seq_list;
476 /* Current struct iscsi_seq used for DataSequenceInOrder=No */
477 struct iscsi_seq *seq_ptr;
478 /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
479 struct iscsi_tmr_req *tmr_req;
480 /* Connection this command is alligient to */
481 struct iscsi_conn *conn;
482 /* Pointer to connection recovery entry */
483 struct iscsi_conn_recovery *cr;
484 /* Session the command is part of, used for connection recovery */
485 struct iscsi_session *sess;
486 /* list_head for connection list */
487 struct list_head i_conn_node;
488 /* The TCM I/O descriptor that is accessed via container_of() */
489 struct se_cmd se_cmd;
490 /* Sense buffer that will be mapped into outgoing status */
491 #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
492 unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN];
497 struct scatterlist *first_data_sg;
498 u32 first_data_sg_off;
500 sense_reason_t sense_reason;
501 } ____cacheline_aligned;
503 struct iscsi_tmr_req {
504 bool task_reassign:1;
506 struct iscsi_cmd *ref_cmd;
507 struct iscsi_conn_recovery *conn_recovery;
508 struct se_tmr_req *se_tmr_req;
512 wait_queue_head_t queues_wq;
513 /* Authentication Successful for this connection */
515 /* State connection is currently in */
517 u8 conn_logout_reason;
518 u8 network_transport;
519 enum iscsi_timer_flags_table nopin_timer_flags;
520 enum iscsi_timer_flags_table nopin_response_timer_flags;
521 /* Used to know what thread encountered a transport failure */
523 /* connection id assigned by the Initiator */
525 /* Remote TCP Port */
531 /* Used for iscsi_tx_login_rsp() */
534 /* Per connection status sequence number */
536 struct sockaddr_storage login_sockaddr;
537 struct sockaddr_storage local_sockaddr;
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 */
557 void (*orig_data_ready)(struct sock *);
558 void (*orig_state_change)(struct sock *);
559 #define LOGIN_FLAGS_READY 0
560 #define LOGIN_FLAGS_INITIAL_PDU 1
561 #define LOGIN_FLAGS_READ_ACTIVE 2
562 #define LOGIN_FLAGS_WRITE_ACTIVE 3
563 #define LOGIN_FLAGS_CLOSED 4
564 unsigned long login_flags;
565 struct delayed_work login_work;
566 struct iscsi_login *login;
567 struct timer_list nopin_timer;
568 struct timer_list nopin_response_timer;
569 struct timer_list transport_timer;
570 struct task_struct *login_kworker;
571 /* Spinlock used for add/deleting cmd's from conn_cmd_list */
573 spinlock_t conn_usage_lock;
574 spinlock_t immed_queue_lock;
575 spinlock_t nopin_timer_lock;
576 spinlock_t response_queue_lock;
577 spinlock_t state_lock;
578 /* libcrypto RX and TX contexts for crc32c */
579 struct ahash_request *conn_rx_hash;
580 struct ahash_request *conn_tx_hash;
581 /* Used for scheduling TX and RX connection kthreads */
582 cpumask_var_t conn_cpumask;
583 unsigned int conn_rx_reset_cpumask:1;
584 unsigned int conn_tx_reset_cpumask:1;
585 /* list_head of struct iscsi_cmd for this connection */
586 struct list_head conn_cmd_list;
587 struct list_head immed_queue_list;
588 struct list_head response_queue_list;
589 struct iscsi_conn_ops *conn_ops;
590 struct iscsi_login *conn_login;
591 struct iscsit_transport *conn_transport;
592 struct iscsi_param_list *param_list;
593 /* Used for per connection auth state machine */
596 struct iscsi_login_thread_s *login_thread;
597 struct iscsi_portal_group *tpg;
598 struct iscsi_tpg_np *tpg_np;
599 /* Pointer to parent session */
600 struct iscsi_session *sess;
602 int rx_thread_active;
603 struct task_struct *rx_thread;
604 struct completion rx_login_comp;
605 int tx_thread_active;
606 struct task_struct *tx_thread;
607 /* list_head for session connection list */
608 struct list_head conn_list;
609 } ____cacheline_aligned;
611 struct iscsi_conn_recovery {
614 u32 maxrecvdatasegmentlength;
615 u32 maxxmitdatasegmentlength;
616 int ready_for_reallegiance;
617 struct list_head conn_recovery_cmd_list;
618 spinlock_t conn_recovery_cmd_lock;
619 struct timer_list time2retain_timer;
620 struct iscsi_session *sess;
621 struct list_head cr_list;
622 } ____cacheline_aligned;
624 struct iscsi_session {
627 enum iscsi_timer_flags_table time2retain_timer_flags;
630 u16 conn_recovery_count;
632 /* state session is currently in */
634 /* session wide counter: initiator assigned task tag */
636 /* session wide counter: target assigned task tag */
640 /* protects cmdsn values */
641 struct mutex cmdsn_mutex;
642 /* session wide counter: expected command sequence number */
644 /* session wide counter: maximum allowed command sequence number */
646 struct list_head sess_ooo_cmdsn_list;
648 /* LIO specific session ID */
651 /* unique within the target */
653 /* Used for session reference counting */
654 int session_usage_count;
655 int session_waiting_on_uc;
656 atomic_long_t cmd_pdus;
657 atomic_long_t rsp_pdus;
658 atomic_long_t tx_data_octets;
659 atomic_long_t rx_data_octets;
660 atomic_long_t conn_digest_errors;
661 atomic_long_t conn_timeout_errors;
663 /* Number of active connections */
665 atomic_t session_continuation;
666 atomic_t session_fall_back_to_erl0;
667 atomic_t session_logout;
668 atomic_t session_reinstatement;
669 atomic_t session_stop_active;
670 atomic_t session_close;
671 /* connection list */
672 struct list_head sess_conn_list;
673 struct list_head cr_active_list;
674 struct list_head cr_inactive_list;
675 spinlock_t conn_lock;
676 spinlock_t cr_a_lock;
677 spinlock_t cr_i_lock;
678 spinlock_t session_usage_lock;
680 struct completion async_msg_comp;
681 struct completion reinstatement_comp;
682 struct completion session_wait_comp;
683 struct completion session_waiting_on_uc_comp;
684 struct timer_list time2retain_timer;
685 struct iscsi_sess_ops *sess_ops;
686 struct se_session *se_sess;
687 struct iscsi_portal_group *tpg;
688 } ____cacheline_aligned;
692 u8 checked_for_existing;
694 u8 leading_connection;
704 u32 initial_exp_statsn;
708 char req[ISCSI_HDR_LEN];
709 char rsp[ISCSI_HDR_LEN];
712 struct iscsi_conn *conn;
714 } ____cacheline_aligned;
716 struct iscsi_node_attrib {
718 u32 dataout_timeout_retries;
721 u32 nopin_response_timeout;
722 u32 random_datain_pdu_offsets;
723 u32 random_datain_seq_offsets;
724 u32 random_r2t_offsets;
727 struct iscsi_node_acl *nacl;
730 struct se_dev_entry_s;
732 struct iscsi_node_auth {
733 enum naf_flags_table naf_flags;
734 int authenticate_target;
735 /* Used for iscsit_global->discovery_auth,
736 * set to zero (auth disabled) by default */
737 int enforce_discovery_auth;
738 #define MAX_USER_LEN 256
739 #define MAX_PASS_LEN 256
740 char userid[MAX_USER_LEN];
741 char password[MAX_PASS_LEN];
742 char userid_mutual[MAX_USER_LEN];
743 char password_mutual[MAX_PASS_LEN];
746 #include "iscsi_target_stat.h"
748 struct iscsi_node_stat_grps {
749 struct config_group iscsi_sess_stats_group;
750 struct config_group iscsi_conn_stats_group;
753 struct iscsi_node_acl {
754 struct se_node_acl se_node_acl;
755 struct iscsi_node_attrib node_attrib;
756 struct iscsi_node_auth node_auth;
757 struct iscsi_node_stat_grps node_stat_grps;
760 struct iscsi_tpg_attrib {
764 u32 generate_node_acls;
765 u32 cache_dynamic_acls;
766 u32 default_cmdsn_depth;
767 u32 demo_mode_write_protect;
768 u32 prod_mode_write_protect;
769 u32 demo_mode_discovery;
772 u32 fabric_prot_type;
773 u32 tpg_enabled_sendtargets;
774 u32 login_keys_workaround;
775 struct iscsi_portal_group *tpg;
779 int np_network_transport;
782 enum np_thread_state_table np_thread_state;
784 atomic_t np_reset_count;
785 enum iscsi_timer_flags_table np_login_timer_flags;
787 enum np_flags_table np_flags;
788 spinlock_t np_thread_lock;
789 struct completion np_restart_comp;
790 struct socket *np_socket;
791 struct sockaddr_storage np_sockaddr;
792 struct task_struct *np_thread;
793 struct timer_list np_login_timer;
795 struct iscsit_transport *np_transport;
796 struct list_head np_list;
797 } ____cacheline_aligned;
799 struct iscsi_tpg_np {
800 struct iscsi_np *tpg_np;
801 struct iscsi_portal_group *tpg;
802 struct iscsi_tpg_np *tpg_np_parent;
803 struct list_head tpg_np_list;
804 struct list_head tpg_np_child_list;
805 struct list_head tpg_np_parent_list;
806 struct se_tpg_np se_tpg_np;
807 spinlock_t tpg_np_parent_lock;
808 struct completion tpg_np_comp;
809 struct kref tpg_np_kref;
812 struct iscsi_portal_group {
813 unsigned char tpg_chap_id;
815 enum tpg_state_table tpg_state;
816 /* Target Portal Group Tag */
818 /* Id assigned to target sessions */
820 /* Number of active sessions */
822 /* Number of Network Portals available for this TPG */
824 /* Per TPG LIO specific session ID. */
826 /* Spinlock for adding/removing Network Portals */
827 spinlock_t tpg_np_lock;
828 spinlock_t tpg_state_lock;
829 struct se_portal_group tpg_se_tpg;
830 struct mutex tpg_access_lock;
831 struct semaphore np_login_sem;
832 struct iscsi_tpg_attrib tpg_attrib;
833 struct iscsi_node_auth tpg_demo_auth;
834 /* Pointer to default list of iSCSI parameters for TPG */
835 struct iscsi_param_list *param_list;
836 struct iscsi_tiqn *tpg_tiqn;
837 struct list_head tpg_gnp_list;
838 struct list_head tpg_list;
839 } ____cacheline_aligned;
841 struct iscsi_wwn_stat_grps {
842 struct config_group iscsi_stat_group;
843 struct config_group iscsi_instance_group;
844 struct config_group iscsi_sess_err_group;
845 struct config_group iscsi_tgt_attr_group;
846 struct config_group iscsi_login_stats_group;
847 struct config_group iscsi_logout_stats_group;
851 unsigned char tiqn[ISCSI_IQN_LEN];
852 enum tiqn_state_table tiqn_state;
853 int tiqn_access_count;
854 u32 tiqn_active_tpgs;
856 u32 tiqn_num_tpg_nps;
858 struct list_head tiqn_list;
859 struct list_head tiqn_tpg_list;
860 spinlock_t tiqn_state_lock;
861 spinlock_t tiqn_tpg_lock;
862 struct se_wwn tiqn_wwn;
863 struct iscsi_wwn_stat_grps tiqn_stat_grps;
865 struct iscsi_sess_err_stats sess_err_stats;
866 struct iscsi_login_stats login_stats;
867 struct iscsi_logout_stats logout_stats;
868 } ____cacheline_aligned;
870 struct iscsit_global {
871 /* In core shutdown */
874 /* Unique identifier used for the authentication daemon */
877 #define ISCSIT_BITMAP_BITS 262144
878 /* Thread Set bitmap pointer */
879 unsigned long *ts_bitmap;
880 spinlock_t ts_bitmap_lock;
881 /* Used for iSCSI discovery session authentication */
882 struct iscsi_node_acl discovery_acl;
883 struct iscsi_portal_group *discovery_tpg;
886 static inline u32 session_get_next_ttt(struct iscsi_session *session)
890 spin_lock_bh(&session->ttt_lock);
891 ttt = session->targ_xfer_tag++;
892 if (ttt == 0xFFFFFFFF)
893 ttt = session->targ_xfer_tag++;
894 spin_unlock_bh(&session->ttt_lock);
899 extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t);
901 static inline void iscsit_thread_check_cpumask(
902 struct iscsi_conn *conn,
903 struct task_struct *p,
907 * mode == 1 signals iscsi_target_tx_thread() usage.
908 * mode == 0 signals iscsi_target_rx_thread() usage.
911 if (!conn->conn_tx_reset_cpumask)
913 conn->conn_tx_reset_cpumask = 0;
915 if (!conn->conn_rx_reset_cpumask)
917 conn->conn_rx_reset_cpumask = 0;
920 * Update the CPU mask for this single kthread so that
921 * both TX and RX kthreads are scheduled to run on the
924 set_cpus_allowed_ptr(p, conn->conn_cpumask);
926 #endif /* ISCSI_TARGET_CORE_H */