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