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/socket.h> /* struct sockaddr_storage */
8 #include <linux/types.h> /* u8 */
9 #include <scsi/iscsi_proto.h> /* itt_t */
10 #include <target/target_core_base.h> /* struct se_cmd */
14 #define ISCSIT_VERSION "v4.1.0"
15 #define ISCSI_MAX_DATASN_MISSING_COUNT 16
16 #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
17 #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
18 #define SECONDS_FOR_ASYNC_LOGOUT 10
19 #define SECONDS_FOR_ASYNC_TEXT 10
20 #define SECONDS_FOR_LOGOUT_COMP 15
21 #define WHITE_SPACE " \t\v\f\n\r"
22 #define ISCSIT_MIN_TAGS 16
23 #define ISCSIT_EXTRA_TAGS 8
24 #define ISCSIT_TCP_BACKLOG 256
25 #define ISCSI_RX_THREAD_NAME "iscsi_trx"
26 #define ISCSI_TX_THREAD_NAME "iscsi_ttx"
28 /* struct iscsi_node_attrib sanity values */
29 #define NA_DATAOUT_TIMEOUT 3
30 #define NA_DATAOUT_TIMEOUT_MAX 60
31 #define NA_DATAOUT_TIMEOUT_MIX 2
32 #define NA_DATAOUT_TIMEOUT_RETRIES 5
33 #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
34 #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
35 #define NA_NOPIN_TIMEOUT 15
36 #define NA_NOPIN_TIMEOUT_MAX 60
37 #define NA_NOPIN_TIMEOUT_MIN 3
38 #define NA_NOPIN_RESPONSE_TIMEOUT 30
39 #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
40 #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
41 #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
42 #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
43 #define NA_RANDOM_R2T_OFFSETS 0
45 /* struct iscsi_tpg_attrib sanity values */
46 #define TA_AUTHENTICATION 1
47 #define TA_LOGIN_TIMEOUT 15
48 #define TA_LOGIN_TIMEOUT_MAX 30
49 #define TA_LOGIN_TIMEOUT_MIN 5
50 #define TA_NETIF_TIMEOUT 2
51 #define TA_NETIF_TIMEOUT_MAX 15
52 #define TA_NETIF_TIMEOUT_MIN 2
53 #define TA_GENERATE_NODE_ACLS 0
54 #define TA_DEFAULT_CMDSN_DEPTH 64
55 #define TA_DEFAULT_CMDSN_DEPTH_MAX 512
56 #define TA_DEFAULT_CMDSN_DEPTH_MIN 1
57 #define TA_CACHE_DYNAMIC_ACLS 0
58 /* Enabled by default in demo mode (generic_node_acls=1) */
59 #define TA_DEMO_MODE_WRITE_PROTECT 1
60 /* Disabled by default in production mode w/ explict ACLs */
61 #define TA_PROD_MODE_WRITE_PROTECT 0
62 #define TA_DEMO_MODE_DISCOVERY 1
63 #define TA_DEFAULT_ERL 0
64 #define TA_CACHE_CORE_NPS 0
65 /* T10 protection information disabled by default */
66 #define TA_DEFAULT_T10_PI 0
67 #define TA_DEFAULT_FABRIC_PROT_TYPE 0
68 /* TPG status needs to be enabled to return sendtargets discovery endpoint info */
69 #define TA_DEFAULT_TPG_ENABLED_SENDTARGETS 1
71 * Used to control the sending of keys with optional to respond state bit,
72 * as a workaround for non RFC compliant initiators,that do not propose,
73 * nor respond to specific keys required for login to complete.
75 * See iscsi_check_proposer_for_optional_reply() for more details.
77 #define TA_DEFAULT_LOGIN_KEYS_WORKAROUND 1
79 #define ISCSI_IOV_DATA_BUFFER 5
81 enum iscsit_transport_type
{
91 /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
92 enum target_conn_state_table
{
93 TARG_CONN_STATE_FREE
= 0x1,
94 TARG_CONN_STATE_XPT_UP
= 0x3,
95 TARG_CONN_STATE_IN_LOGIN
= 0x4,
96 TARG_CONN_STATE_LOGGED_IN
= 0x5,
97 TARG_CONN_STATE_IN_LOGOUT
= 0x6,
98 TARG_CONN_STATE_LOGOUT_REQUESTED
= 0x7,
99 TARG_CONN_STATE_CLEANUP_WAIT
= 0x8,
102 /* RFC-3720 7.3.2 Session State Diagram for a Target */
103 enum target_sess_state_table
{
104 TARG_SESS_STATE_FREE
= 0x1,
105 TARG_SESS_STATE_ACTIVE
= 0x2,
106 TARG_SESS_STATE_LOGGED_IN
= 0x3,
107 TARG_SESS_STATE_FAILED
= 0x4,
108 TARG_SESS_STATE_IN_CONTINUE
= 0x5,
111 /* struct iscsi_data_count->type */
112 enum data_count_type
{
117 /* struct iscsi_datain_req->dr_complete */
118 enum datain_req_comp_table
{
119 DATAIN_COMPLETE_NORMAL
= 1,
120 DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY
= 2,
121 DATAIN_COMPLETE_CONNECTION_RECOVERY
= 3,
124 /* struct iscsi_datain_req->recovery */
125 enum datain_req_rec_table
{
126 DATAIN_WITHIN_COMMAND_RECOVERY
= 1,
127 DATAIN_CONNECTION_RECOVERY
= 2,
130 /* struct iscsi_portal_group->state */
131 enum tpg_state_table
{
133 TPG_STATE_ACTIVE
= 1,
134 TPG_STATE_INACTIVE
= 2,
135 TPG_STATE_COLD_RESET
= 3,
138 /* struct iscsi_tiqn->tiqn_state */
139 enum tiqn_state_table
{
140 TIQN_STATE_ACTIVE
= 1,
141 TIQN_STATE_SHUTDOWN
= 2,
144 /* struct iscsi_cmd->cmd_flags */
145 enum cmd_flags_table
{
146 ICF_GOT_LAST_DATAOUT
= 0x00000001,
147 ICF_GOT_DATACK_SNACK
= 0x00000002,
148 ICF_NON_IMMEDIATE_UNSOLICITED_DATA
= 0x00000004,
149 ICF_SENT_LAST_R2T
= 0x00000008,
150 ICF_WITHIN_COMMAND_RECOVERY
= 0x00000010,
151 ICF_CONTIG_MEMORY
= 0x00000020,
152 ICF_ATTACHED_TO_RQUEUE
= 0x00000040,
153 ICF_OOO_CMDSN
= 0x00000080,
154 ICF_SENDTARGETS_ALL
= 0x00000100,
155 ICF_SENDTARGETS_SINGLE
= 0x00000200,
158 /* struct iscsi_cmd->i_state */
159 enum cmd_i_state_table
{
162 ISTATE_DEFERRED_CMD
= 2,
163 ISTATE_UNSOLICITED_DATA
= 3,
164 ISTATE_RECEIVE_DATAOUT
= 4,
165 ISTATE_RECEIVE_DATAOUT_RECOVERY
= 5,
166 ISTATE_RECEIVED_LAST_DATAOUT
= 6,
167 ISTATE_WITHIN_DATAOUT_RECOVERY
= 7,
168 ISTATE_IN_CONNECTION_RECOVERY
= 8,
169 ISTATE_RECEIVED_TASKMGT
= 9,
170 ISTATE_SEND_ASYNCMSG
= 10,
171 ISTATE_SENT_ASYNCMSG
= 11,
172 ISTATE_SEND_DATAIN
= 12,
173 ISTATE_SEND_LAST_DATAIN
= 13,
174 ISTATE_SENT_LAST_DATAIN
= 14,
175 ISTATE_SEND_LOGOUTRSP
= 15,
176 ISTATE_SENT_LOGOUTRSP
= 16,
177 ISTATE_SEND_NOPIN
= 17,
178 ISTATE_SENT_NOPIN
= 18,
179 ISTATE_SEND_REJECT
= 19,
180 ISTATE_SENT_REJECT
= 20,
181 ISTATE_SEND_R2T
= 21,
182 ISTATE_SENT_R2T
= 22,
183 ISTATE_SEND_R2T_RECOVERY
= 23,
184 ISTATE_SENT_R2T_RECOVERY
= 24,
185 ISTATE_SEND_LAST_R2T
= 25,
186 ISTATE_SENT_LAST_R2T
= 26,
187 ISTATE_SEND_LAST_R2T_RECOVERY
= 27,
188 ISTATE_SENT_LAST_R2T_RECOVERY
= 28,
189 ISTATE_SEND_STATUS
= 29,
190 ISTATE_SEND_STATUS_BROKEN_PC
= 30,
191 ISTATE_SENT_STATUS
= 31,
192 ISTATE_SEND_STATUS_RECOVERY
= 32,
193 ISTATE_SENT_STATUS_RECOVERY
= 33,
194 ISTATE_SEND_TASKMGTRSP
= 34,
195 ISTATE_SENT_TASKMGTRSP
= 35,
196 ISTATE_SEND_TEXTRSP
= 36,
197 ISTATE_SENT_TEXTRSP
= 37,
198 ISTATE_SEND_NOPIN_WANT_RESPONSE
= 38,
199 ISTATE_SENT_NOPIN_WANT_RESPONSE
= 39,
200 ISTATE_SEND_NOPIN_NO_RESPONSE
= 40,
205 /* Used for iscsi_recover_cmdsn() return values */
206 enum recover_cmdsn_ret_table
{
207 CMDSN_ERROR_CANNOT_RECOVER
= -1,
208 CMDSN_NORMAL_OPERATION
= 0,
209 CMDSN_LOWER_THAN_EXP
= 1,
210 CMDSN_HIGHER_THAN_EXP
= 2,
211 CMDSN_MAXCMDSN_OVERRUN
= 3,
214 /* Used for iscsi_handle_immediate_data() return values */
215 enum immedate_data_ret_table
{
216 IMMEDIATE_DATA_CANNOT_RECOVER
= -1,
217 IMMEDIATE_DATA_NORMAL_OPERATION
= 0,
218 IMMEDIATE_DATA_ERL1_CRC_FAILURE
= 1,
221 /* Used for iscsi_decide_dataout_action() return values */
222 enum dataout_action_ret_table
{
223 DATAOUT_CANNOT_RECOVER
= -1,
225 DATAOUT_SEND_R2T
= 1,
226 DATAOUT_SEND_TO_TRANSPORT
= 2,
227 DATAOUT_WITHIN_COMMAND_RECOVERY
= 3,
230 /* Used for struct iscsi_node_auth->naf_flags */
231 enum naf_flags_table
{
232 NAF_USERID_SET
= 0x01,
233 NAF_PASSWORD_SET
= 0x02,
234 NAF_USERID_IN_SET
= 0x04,
235 NAF_PASSWORD_IN_SET
= 0x08,
238 /* Used by various struct timer_list to manage iSCSI specific state */
239 enum iscsi_timer_flags_table
{
240 ISCSI_TF_RUNNING
= 0x01,
241 ISCSI_TF_STOP
= 0x02,
242 ISCSI_TF_EXPIRED
= 0x04,
245 /* Used for struct iscsi_np->np_flags */
246 enum np_flags_table
{
247 NPF_IP_NETWORK
= 0x00,
250 /* Used for struct iscsi_np->np_thread_state */
251 enum np_thread_state_table
{
252 ISCSI_NP_THREAD_ACTIVE
= 1,
253 ISCSI_NP_THREAD_INACTIVE
= 2,
254 ISCSI_NP_THREAD_RESET
= 3,
255 ISCSI_NP_THREAD_SHUTDOWN
= 4,
256 ISCSI_NP_THREAD_EXIT
= 5,
259 struct iscsi_conn_ops
{
260 u8 HeaderDigest
; /* [0,1] == [None,CRC32C] */
261 u8 DataDigest
; /* [0,1] == [None,CRC32C] */
262 u32 MaxRecvDataSegmentLength
; /* [512..2**24-1] */
263 u32 MaxXmitDataSegmentLength
; /* [512..2**24-1] */
265 * iSER specific connection parameters
267 u32 InitiatorRecvDataSegmentLength
; /* [512..2**24-1] */
268 u32 TargetRecvDataSegmentLength
; /* [512..2**24-1] */
271 struct iscsi_sess_ops
{
272 char InitiatorName
[224];
273 char InitiatorAlias
[256];
274 char TargetName
[224];
275 char TargetAlias
[256];
276 char TargetAddress
[256];
277 u16 TargetPortalGroupTag
; /* [0..65535] */
278 u16 MaxConnections
; /* [1..65535] */
279 u8 InitialR2T
; /* [0,1] == [No,Yes] */
280 u8 ImmediateData
; /* [0,1] == [No,Yes] */
281 u32 MaxBurstLength
; /* [512..2**24-1] */
282 u32 FirstBurstLength
; /* [512..2**24-1] */
283 u16 DefaultTime2Wait
; /* [0..3600] */
284 u16 DefaultTime2Retain
; /* [0..3600] */
285 u16 MaxOutstandingR2T
; /* [1..65535] */
286 u8 DataPDUInOrder
; /* [0,1] == [No,Yes] */
287 u8 DataSequenceInOrder
; /* [0,1] == [No,Yes] */
288 u8 ErrorRecoveryLevel
; /* [0..2] */
289 u8 SessionType
; /* [0,1] == [Normal,Discovery]*/
291 * iSER specific session parameters
293 u8 RDMAExtensions
; /* [0,1] == [No,Yes] */
296 struct iscsi_queue_req
{
298 struct iscsi_cmd
*cmd
;
299 struct list_head qr_list
;
302 struct iscsi_data_count
{
304 int sync_and_steering
;
305 enum data_count_type type
;
312 struct iscsi_param_list
{
314 struct list_head param_list
;
315 struct list_head extra_response_list
;
318 struct iscsi_datain_req
{
319 enum datain_req_comp_table dr_complete
;
320 int generate_recovery_values
;
321 enum datain_req_rec_table recovery
;
330 struct list_head cmd_datain_node
;
331 } ____cacheline_aligned
;
333 struct iscsi_ooo_cmdsn
{
338 struct iscsi_cmd
*cmd
;
339 struct list_head ooo_list
;
340 } ____cacheline_aligned
;
342 struct iscsi_datain
{
347 } ____cacheline_aligned
;
357 struct list_head r2t_list
;
358 } ____cacheline_aligned
;
361 enum iscsi_timer_flags_table dataout_timer_flags
;
362 /* DataOUT timeout retries */
363 u8 dataout_timeout_retries
;
364 /* Within command recovery count */
365 u8 error_recovery_count
;
366 /* iSCSI dependent state for out or order CmdSNs */
367 enum cmd_i_state_table deferred_i_state
;
368 /* iSCSI dependent state */
369 enum cmd_i_state_table i_state
;
370 /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
372 /* Immediate data present */
376 /* iSCSI Response Code */
378 /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
380 /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
382 /* MaxCmdSN has been incremented */
384 /* Immediate Unsolicited Dataout */
386 /* Reject reason code */
388 /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
391 enum cmd_flags_table cmd_flags
;
392 /* Initiator Task Tag assigned from Initiator */
394 /* Target Transfer Tag assigned from Target */
396 /* CmdSN assigned from Initiator */
398 /* ExpStatSN assigned from Initiator */
400 /* StatSN assigned to this ITT */
406 /* Last DataSN acknowledged via DataAck SNACK */
408 /* Used for echoing NOPOUT ping data */
410 /* Used to store DataDigest */
412 /* Counter for MaxOutstandingR2T */
413 u32 outstanding_r2ts
;
414 /* Next R2T Offset when DataSequenceInOrder=Yes */
416 /* Iovec current and orig count for iscsi_cmd->iov_data */
418 u32 orig_iov_data_count
;
419 /* Number of miscellaneous iovecs used for IP stack calls */
421 /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
423 /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
425 /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
427 /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
429 /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
431 /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
433 /* Lowest offset in current DataOUT sequence */
434 u32 seq_start_offset
;
435 /* Highest offset in current DataOUT sequence */
437 /* Total size in bytes received so far of READ data */
439 /* Total size in bytes received so far of WRITE data */
441 /* Counter for FirstBurstLength key */
443 /* Counter for MaxBurstLength key */
445 /* Transfer size used for IP stack calls */
447 /* Buffer used for various purposes */
449 /* Used by SendTargets=[iqn.,eui.] discovery */
451 /* See include/linux/dma-mapping.h */
452 enum dma_data_direction data_direction
;
453 /* iSCSI PDU Header + CRC */
454 unsigned char pdu
[ISCSI_HDR_LEN
+ ISCSI_CRC_LEN
];
455 /* Number of times struct iscsi_cmd is present in immediate queue */
456 atomic_t immed_queue_count
;
457 atomic_t response_queue_count
;
458 spinlock_t datain_lock
;
459 spinlock_t dataout_timeout_lock
;
460 /* spinlock for protecting struct iscsi_cmd->i_state */
461 spinlock_t istate_lock
;
462 /* spinlock for adding within command recovery entries */
463 spinlock_t error_lock
;
464 /* spinlock for adding R2Ts */
467 struct list_head datain_list
;
469 struct list_head cmd_r2t_list
;
470 /* Timer for DataOUT */
471 struct timer_list dataout_timer
;
472 /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
473 struct kvec
*iov_data
;
474 /* Iovecs for miscellaneous purposes */
475 #define ISCSI_MISC_IOVECS 5
476 struct kvec iov_misc
[ISCSI_MISC_IOVECS
];
477 /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
478 struct iscsi_pdu
*pdu_list
;
479 /* Current struct iscsi_pdu used for DataPDUInOrder=No */
480 struct iscsi_pdu
*pdu_ptr
;
481 /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
482 struct iscsi_seq
*seq_list
;
483 /* Current struct iscsi_seq used for DataSequenceInOrder=No */
484 struct iscsi_seq
*seq_ptr
;
485 /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
486 struct iscsi_tmr_req
*tmr_req
;
487 /* Connection this command is alligient to */
488 struct iscsi_conn
*conn
;
489 /* Pointer to connection recovery entry */
490 struct iscsi_conn_recovery
*cr
;
491 /* Session the command is part of, used for connection recovery */
492 struct iscsi_session
*sess
;
493 /* list_head for connection list */
494 struct list_head i_conn_node
;
495 /* The TCM I/O descriptor that is accessed via container_of() */
496 struct se_cmd se_cmd
;
497 /* Sense buffer that will be mapped into outgoing status */
498 #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
499 unsigned char sense_buffer
[ISCSI_SENSE_BUFFER_LEN
];
504 struct scatterlist
*first_data_sg
;
505 u32 first_data_sg_off
;
507 sense_reason_t sense_reason
;
508 } ____cacheline_aligned
;
510 struct iscsi_tmr_req
{
511 bool task_reassign
:1;
513 struct iscsi_cmd
*ref_cmd
;
514 struct iscsi_conn_recovery
*conn_recovery
;
515 struct se_tmr_req
*se_tmr_req
;
519 wait_queue_head_t queues_wq
;
520 /* Authentication Successful for this connection */
522 /* State connection is currently in */
524 u8 conn_logout_reason
;
525 u8 network_transport
;
526 enum iscsi_timer_flags_table nopin_timer_flags
;
527 enum iscsi_timer_flags_table nopin_response_timer_flags
;
528 /* Used to know what thread encountered a transport failure */
530 /* connection id assigned by the Initiator */
532 /* Remote TCP Port */
538 /* Used for iscsi_tx_login_rsp() */
541 /* Per connection status sequence number */
543 struct sockaddr_storage login_sockaddr
;
544 struct sockaddr_storage local_sockaddr
;
545 int conn_usage_count
;
546 int conn_waiting_on_uc
;
547 atomic_t check_immediate_queue
;
548 atomic_t conn_logout_remove
;
549 atomic_t connection_exit
;
550 atomic_t connection_recovery
;
551 atomic_t connection_reinstatement
;
552 atomic_t connection_wait_rcfr
;
553 atomic_t sleep_on_conn_wait_comp
;
554 atomic_t transport_failed
;
555 struct completion conn_post_wait_comp
;
556 struct completion conn_wait_comp
;
557 struct completion conn_wait_rcfr_comp
;
558 struct completion conn_waiting_on_uc_comp
;
559 struct completion conn_logout_comp
;
560 struct completion tx_half_close_comp
;
561 struct completion rx_half_close_comp
;
562 /* socket used by this connection */
564 void (*orig_data_ready
)(struct sock
*);
565 void (*orig_state_change
)(struct sock
*);
566 #define LOGIN_FLAGS_READ_ACTIVE 1
567 #define LOGIN_FLAGS_CLOSED 2
568 #define LOGIN_FLAGS_READY 4
569 #define LOGIN_FLAGS_INITIAL_PDU 8
570 unsigned long login_flags
;
571 struct delayed_work login_work
;
572 struct iscsi_login
*login
;
573 struct timer_list nopin_timer
;
574 struct timer_list nopin_response_timer
;
575 struct timer_list transport_timer
;
576 struct task_struct
*login_kworker
;
577 /* Spinlock used for add/deleting cmd's from conn_cmd_list */
579 spinlock_t conn_usage_lock
;
580 spinlock_t immed_queue_lock
;
581 spinlock_t nopin_timer_lock
;
582 spinlock_t response_queue_lock
;
583 spinlock_t state_lock
;
584 /* libcrypto RX and TX contexts for crc32c */
585 struct ahash_request
*conn_rx_hash
;
586 struct ahash_request
*conn_tx_hash
;
587 /* Used for scheduling TX and RX connection kthreads */
588 cpumask_var_t conn_cpumask
;
589 unsigned int conn_rx_reset_cpumask
:1;
590 unsigned int conn_tx_reset_cpumask
:1;
591 /* list_head of struct iscsi_cmd for this connection */
592 struct list_head conn_cmd_list
;
593 struct list_head immed_queue_list
;
594 struct list_head response_queue_list
;
595 struct iscsi_conn_ops
*conn_ops
;
596 struct iscsi_login
*conn_login
;
597 struct iscsit_transport
*conn_transport
;
598 struct iscsi_param_list
*param_list
;
599 /* Used for per connection auth state machine */
602 struct iscsi_login_thread_s
*login_thread
;
603 struct iscsi_portal_group
*tpg
;
604 struct iscsi_tpg_np
*tpg_np
;
605 /* Pointer to parent session */
606 struct iscsi_session
*sess
;
608 int rx_thread_active
;
609 struct task_struct
*rx_thread
;
610 struct completion rx_login_comp
;
611 int tx_thread_active
;
612 struct task_struct
*tx_thread
;
613 /* list_head for session connection list */
614 struct list_head conn_list
;
615 } ____cacheline_aligned
;
617 struct iscsi_conn_recovery
{
620 u32 maxrecvdatasegmentlength
;
621 u32 maxxmitdatasegmentlength
;
622 int ready_for_reallegiance
;
623 struct list_head conn_recovery_cmd_list
;
624 spinlock_t conn_recovery_cmd_lock
;
625 struct timer_list time2retain_timer
;
626 struct iscsi_session
*sess
;
627 struct list_head cr_list
;
628 } ____cacheline_aligned
;
630 struct iscsi_session
{
633 enum iscsi_timer_flags_table time2retain_timer_flags
;
636 u16 conn_recovery_count
;
638 /* state session is currently in */
640 /* session wide counter: initiator assigned task tag */
642 /* session wide counter: target assigned task tag */
646 /* protects cmdsn values */
647 struct mutex cmdsn_mutex
;
648 /* session wide counter: expected command sequence number */
650 /* session wide counter: maximum allowed command sequence number */
652 struct list_head sess_ooo_cmdsn_list
;
654 /* LIO specific session ID */
657 /* unique within the target */
659 /* Used for session reference counting */
660 int session_usage_count
;
661 int session_waiting_on_uc
;
662 atomic_long_t cmd_pdus
;
663 atomic_long_t rsp_pdus
;
664 atomic_long_t tx_data_octets
;
665 atomic_long_t rx_data_octets
;
666 atomic_long_t conn_digest_errors
;
667 atomic_long_t conn_timeout_errors
;
669 /* Number of active connections */
671 atomic_t session_continuation
;
672 atomic_t session_fall_back_to_erl0
;
673 atomic_t session_logout
;
674 atomic_t session_reinstatement
;
675 atomic_t session_stop_active
;
676 atomic_t sleep_on_sess_wait_comp
;
677 /* connection list */
678 struct list_head sess_conn_list
;
679 struct list_head cr_active_list
;
680 struct list_head cr_inactive_list
;
681 spinlock_t conn_lock
;
682 spinlock_t cr_a_lock
;
683 spinlock_t cr_i_lock
;
684 spinlock_t session_usage_lock
;
686 struct completion async_msg_comp
;
687 struct completion reinstatement_comp
;
688 struct completion session_wait_comp
;
689 struct completion session_waiting_on_uc_comp
;
690 struct timer_list time2retain_timer
;
691 struct iscsi_sess_ops
*sess_ops
;
692 struct se_session
*se_sess
;
693 struct iscsi_portal_group
*tpg
;
694 } ____cacheline_aligned
;
698 u8 checked_for_existing
;
700 u8 leading_connection
;
710 u32 initial_exp_statsn
;
714 char req
[ISCSI_HDR_LEN
];
715 char rsp
[ISCSI_HDR_LEN
];
718 struct iscsi_conn
*conn
;
720 } ____cacheline_aligned
;
722 struct iscsi_node_attrib
{
724 u32 dataout_timeout_retries
;
727 u32 nopin_response_timeout
;
728 u32 random_datain_pdu_offsets
;
729 u32 random_datain_seq_offsets
;
730 u32 random_r2t_offsets
;
733 struct iscsi_node_acl
*nacl
;
736 struct se_dev_entry_s
;
738 struct iscsi_node_auth
{
739 enum naf_flags_table naf_flags
;
740 int authenticate_target
;
741 /* Used for iscsit_global->discovery_auth,
742 * set to zero (auth disabled) by default */
743 int enforce_discovery_auth
;
744 #define MAX_USER_LEN 256
745 #define MAX_PASS_LEN 256
746 char userid
[MAX_USER_LEN
];
747 char password
[MAX_PASS_LEN
];
748 char userid_mutual
[MAX_USER_LEN
];
749 char password_mutual
[MAX_PASS_LEN
];
752 #include "iscsi_target_stat.h"
754 struct iscsi_node_stat_grps
{
755 struct config_group iscsi_sess_stats_group
;
756 struct config_group iscsi_conn_stats_group
;
759 struct iscsi_node_acl
{
760 struct se_node_acl se_node_acl
;
761 struct iscsi_node_attrib node_attrib
;
762 struct iscsi_node_auth node_auth
;
763 struct iscsi_node_stat_grps node_stat_grps
;
766 struct iscsi_tpg_attrib
{
770 u32 generate_node_acls
;
771 u32 cache_dynamic_acls
;
772 u32 default_cmdsn_depth
;
773 u32 demo_mode_write_protect
;
774 u32 prod_mode_write_protect
;
775 u32 demo_mode_discovery
;
778 u32 fabric_prot_type
;
779 u32 tpg_enabled_sendtargets
;
780 u32 login_keys_workaround
;
781 struct iscsi_portal_group
*tpg
;
785 int np_network_transport
;
788 enum np_thread_state_table np_thread_state
;
790 atomic_t np_reset_count
;
791 enum iscsi_timer_flags_table np_login_timer_flags
;
793 enum np_flags_table np_flags
;
794 spinlock_t np_thread_lock
;
795 struct completion np_restart_comp
;
796 struct socket
*np_socket
;
797 struct sockaddr_storage np_sockaddr
;
798 struct task_struct
*np_thread
;
799 struct timer_list np_login_timer
;
801 struct iscsit_transport
*np_transport
;
802 struct list_head np_list
;
803 } ____cacheline_aligned
;
805 struct iscsi_tpg_np
{
806 struct iscsi_np
*tpg_np
;
807 struct iscsi_portal_group
*tpg
;
808 struct iscsi_tpg_np
*tpg_np_parent
;
809 struct list_head tpg_np_list
;
810 struct list_head tpg_np_child_list
;
811 struct list_head tpg_np_parent_list
;
812 struct se_tpg_np se_tpg_np
;
813 spinlock_t tpg_np_parent_lock
;
814 struct completion tpg_np_comp
;
815 struct kref tpg_np_kref
;
818 struct iscsi_portal_group
{
819 unsigned char tpg_chap_id
;
821 enum tpg_state_table tpg_state
;
822 /* Target Portal Group Tag */
824 /* Id assigned to target sessions */
826 /* Number of active sessions */
828 /* Number of Network Portals available for this TPG */
830 /* Per TPG LIO specific session ID. */
832 /* Spinlock for adding/removing Network Portals */
833 spinlock_t tpg_np_lock
;
834 spinlock_t tpg_state_lock
;
835 struct se_portal_group tpg_se_tpg
;
836 struct mutex tpg_access_lock
;
837 struct semaphore np_login_sem
;
838 struct iscsi_tpg_attrib tpg_attrib
;
839 struct iscsi_node_auth tpg_demo_auth
;
840 /* Pointer to default list of iSCSI parameters for TPG */
841 struct iscsi_param_list
*param_list
;
842 struct iscsi_tiqn
*tpg_tiqn
;
843 struct list_head tpg_gnp_list
;
844 struct list_head tpg_list
;
845 } ____cacheline_aligned
;
847 struct iscsi_wwn_stat_grps
{
848 struct config_group iscsi_stat_group
;
849 struct config_group iscsi_instance_group
;
850 struct config_group iscsi_sess_err_group
;
851 struct config_group iscsi_tgt_attr_group
;
852 struct config_group iscsi_login_stats_group
;
853 struct config_group iscsi_logout_stats_group
;
857 #define ISCSI_IQN_LEN 224
858 unsigned char tiqn
[ISCSI_IQN_LEN
];
859 enum tiqn_state_table tiqn_state
;
860 int tiqn_access_count
;
861 u32 tiqn_active_tpgs
;
863 u32 tiqn_num_tpg_nps
;
865 struct list_head tiqn_list
;
866 struct list_head tiqn_tpg_list
;
867 spinlock_t tiqn_state_lock
;
868 spinlock_t tiqn_tpg_lock
;
869 struct se_wwn tiqn_wwn
;
870 struct iscsi_wwn_stat_grps tiqn_stat_grps
;
872 struct iscsi_sess_err_stats sess_err_stats
;
873 struct iscsi_login_stats login_stats
;
874 struct iscsi_logout_stats logout_stats
;
875 } ____cacheline_aligned
;
877 struct iscsit_global
{
878 /* In core shutdown */
881 /* Unique identifier used for the authentication daemon */
884 #define ISCSIT_BITMAP_BITS 262144
885 /* Thread Set bitmap pointer */
886 unsigned long *ts_bitmap
;
887 spinlock_t ts_bitmap_lock
;
888 /* Used for iSCSI discovery session authentication */
889 struct iscsi_node_acl discovery_acl
;
890 struct iscsi_portal_group
*discovery_tpg
;
893 static inline u32
session_get_next_ttt(struct iscsi_session
*session
)
897 spin_lock_bh(&session
->ttt_lock
);
898 ttt
= session
->targ_xfer_tag
++;
899 if (ttt
== 0xFFFFFFFF)
900 ttt
= session
->targ_xfer_tag
++;
901 spin_unlock_bh(&session
->ttt_lock
);
906 extern struct iscsi_cmd
*iscsit_find_cmd_from_itt(struct iscsi_conn
*, itt_t
);
908 static inline void iscsit_thread_check_cpumask(
909 struct iscsi_conn
*conn
,
910 struct task_struct
*p
,
914 * mode == 1 signals iscsi_target_tx_thread() usage.
915 * mode == 0 signals iscsi_target_rx_thread() usage.
918 if (!conn
->conn_tx_reset_cpumask
)
920 conn
->conn_tx_reset_cpumask
= 0;
922 if (!conn
->conn_rx_reset_cpumask
)
924 conn
->conn_rx_reset_cpumask
= 0;
927 * Update the CPU mask for this single kthread so that
928 * both TX and RX kthreads are scheduled to run on the
931 set_cpus_allowed_ptr(p
, conn
->conn_cpumask
);
933 #endif /* ISCSI_TARGET_CORE_H */