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