1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 25 * Copyright (c) 2017, Joyent, Inc. All rights reserved. 26 */ 27 28 #ifndef _ISCSIT_H_ 29 #define _ISCSIT_H_ 30 31 #include <sys/iscsit/iscsi_if.h> 32 #include <sys/iscsit/iscsit_common.h> 33 34 #include "iscsit_authclient.h" 35 36 /* 37 * For some reason iscsi_protocol.h lists the max version as "0x02" and the 38 * min version as "0x00". RFC3720 clearly states that the current version 39 * number is 0x00 so that is what we will use. 40 */ 41 #define ISCSIT_MIN_VERSION 0x00 42 #define ISCSIT_MAX_VERSION 0x00 43 #define ISCSIT_MAX_CONNECTIONS 32 /* MC/S support */ 44 #define ISCSIT_MAX_RECV_DATA_SEGMENT_LENGTH (32*1024) 45 #define ISCSIT_MAX_BURST_LENGTH (1024*1024) 46 #define ISCSIT_MAX_FIRST_BURST_LENGTH ISCSI_DEFAULT_FIRST_BURST_LENGTH 47 #define ISCSIT_MAX_TIME2WAIT ISCSI_MAX_TIME2WAIT 48 #define ISCSIT_MAX_TIME2RETAIN ISCSI_DEFAULT_TIME_TO_RETAIN 49 #define ISCSIT_MAX_OUTSTANDING_R2T ISCSI_DEFAULT_MAX_OUT_R2T 50 #define ISCSIT_MAX_ERROR_RECOVERY_LEVEL 0 51 #define ISCSIT_MAX_OUTSTANDING_UNEXPECTED_PDUS 0 52 53 #define ISCSIT_DEFAULT_TPG "iscsit-default-tpg" 54 #define ISCSIT_DEFAULT_TPGT 1 55 56 #define ISCSI_MAX_TSIH 0xffff 57 #define ISCSI_UNSPEC_TSIH 0 58 59 #define ISCSIT_MAX_WINDOW 1024 60 #define ISCSIT_RXPDU_QUEUE_LEN 2048 61 62 /* 63 * MC/S: A timeout is maintained to recover from lost CmdSN (holes in the 64 * CmdSN ordering). When the timeout is reached, the ExpCmdSN is advanced 65 * past the hole to continue processing the queued commands. This value is 66 * system-tunable (volatile rxpdu_queue_threshold) and should be in the 67 * range from 5 to 30 seconds. 68 */ 69 #define ISCSIT_RXPDU_QUEUE_THRESHOLD 5 /* 5 seconds */ 70 #define ISCSIT_RXPDU_QUEUE_MONITOR_INTERVAL 5 /* 5 seconds */ 71 72 /* Time in seconds to wait between calls to stmf_deregister_local_port */ 73 #define TGT_DEREG_RETRY_SECONDS 1 74 75 #define ISCSIT_GLOBAL_LOCK(rw) rw_enter(&iscsit_global.global_rwlock, (rw)) 76 #define ISCSIT_GLOBAL_UNLOCK() rw_exit(&iscsit_global.global_rwlock) 77 78 /* Circular buffer to hold the out-of-order PDUs in MC/S */ 79 typedef struct { 80 idm_pdu_t *cb_buffer[ISCSIT_RXPDU_QUEUE_LEN]; 81 int cb_num_elems; 82 } iscsit_cbuf_t; 83 84 /* 85 * Used for serial number arithmetic (RFC 1982) 86 */ 87 #define ISCSIT_SNA32_CHECK 0x80000000 88 89 typedef struct { 90 char tpg_name[MAX_TPG_NAMELEN]; 91 kmutex_t tpg_mutex; 92 idm_refcnt_t tpg_refcnt; 93 int tpg_online; 94 avl_tree_t tpg_portal_list; 95 avl_node_t tpg_global_ln; 96 list_node_t tpg_delete_ln; 97 } iscsit_tpg_t; 98 99 #define IS_DEFAULT_TPGT(TPGT) \ 100 (((TPGT) != NULL) && \ 101 ((TPGT)->tpgt_tpg == iscsit_global.global_default_tpg)) 102 103 typedef struct { 104 iscsit_tpg_t *tpgt_tpg; 105 idm_refcnt_t tpgt_refcnt; 106 avl_node_t tpgt_tgt_ln; 107 list_node_t tpgt_delete_ln; 108 uint16_t tpgt_tag; 109 boolean_t tpgt_needs_tpg_offline; 110 } iscsit_tpgt_t; 111 112 typedef struct { 113 struct sockaddr_storage portal_addr; 114 int portal_online; 115 idm_refcnt_t portal_refcnt; 116 avl_node_t portal_tpg_ln; 117 iscsit_tpg_t *portal_tpg; 118 idm_svc_t *portal_svc; 119 boolean_t portal_default; 120 void *portal_isns; 121 } iscsit_portal_t; 122 123 124 #define TGT_STATE_LIST() \ 125 item(TS_UNDEFINED) \ 126 item(TS_CREATED) \ 127 item(TS_ONLINING) \ 128 item(TS_ONLINE) \ 129 item(TS_STMF_ONLINE) \ 130 item(TS_DELETING_NEED_OFFLINE) \ 131 item(TS_OFFLINING) \ 132 item(TS_OFFLINE) \ 133 item(TS_STMF_OFFLINE) \ 134 item(TS_DELETING_STMF_DEREG) \ 135 item(TS_DELETING_STMF_DEREG_FAIL) \ 136 item(TS_DELETING) \ 137 item(TS_MAX_STATE) 138 139 /* Target states and events, update iscsit_ts_name table whenever modified */ 140 typedef enum { 141 #define item(a) a, 142 TGT_STATE_LIST() 143 #undef item 144 } iscsit_tgt_state_t; 145 146 #ifdef ISCSIT_TGT_SM_STRINGS 147 static const char *iscsit_ts_name[TS_MAX_STATE + 1] = { 148 #define item(a) #a, 149 TGT_STATE_LIST() 150 #undef item 151 }; 152 #endif 153 154 #define TGT_EVENT_LIST() \ 155 item(TE_UNDEFINED) \ 156 item(TE_STMF_ONLINE_REQ) \ 157 item(TE_ONLINE_SUCCESS) \ 158 item(TE_ONLINE_FAIL) \ 159 item(TE_STMF_ONLINE_COMPLETE_ACK) \ 160 item(TE_STMF_OFFLINE_REQ) \ 161 item(TE_OFFLINE_COMPLETE) \ 162 item(TE_STMF_OFFLINE_COMPLETE_ACK) \ 163 item(TE_DELETE) \ 164 item(TE_STMF_DEREG_SUCCESS) \ 165 item(TE_STMF_DEREG_FAIL) \ 166 item(TE_STMF_DEREG_RETRY) \ 167 item(TE_WAIT_REF_COMPLETE) \ 168 item(TE_MAX_EVENT) 169 170 typedef enum { 171 #define item(a) a, 172 TGT_EVENT_LIST() 173 #undef item 174 } iscsit_tgt_event_t; 175 176 #ifdef ISCSIT_TGT_SM_STRINGS 177 static const char *iscsit_te_name[TE_MAX_EVENT + 1] = { 178 #define item(a) #a, 179 TGT_EVENT_LIST() 180 #undef item 181 }; 182 #endif 183 184 typedef struct { 185 char *target_name; 186 nvlist_t *target_props; 187 kmutex_t target_mutex; 188 idm_refcnt_t target_refcnt; 189 idm_refcnt_t target_sess_refcnt; 190 avl_tree_t target_tpgt_list; 191 avl_tree_t target_sess_list; 192 avl_node_t target_global_ln; 193 avl_node_t target_global_deleted_ln; 194 /* STMF lport == iSCSI target */ 195 scsi_devid_desc_t *target_devid; 196 stmf_local_port_t *target_stmf_lport; 197 uint8_t target_stmf_lport_registered; 198 199 /* Target state */ 200 boolean_t target_sm_busy; 201 boolean_t target_deleting; 202 iscsit_tgt_state_t target_state; 203 iscsit_tgt_state_t target_last_state; 204 sm_audit_buf_t target_state_audit; 205 list_t target_events; 206 uint64_t target_generation; 207 } iscsit_tgt_t; 208 209 typedef struct { 210 char ini_name[MAX_ISCSI_NODENAMELEN]; 211 nvlist_t *ini_props; 212 avl_node_t ini_global_ln; 213 } iscsit_ini_t; 214 215 /* 216 * iSCSI Auth Information 217 */ 218 typedef struct conn_auth { 219 char ca_tgt_chapuser[iscsitAuthStringMaxLength]; 220 uint8_t ca_tgt_chapsecret[iscsitAuthStringMaxLength]; 221 int ca_tgt_chapsecretlen; 222 223 char ca_ini_chapuser[iscsitAuthStringMaxLength]; 224 uint8_t ca_ini_chapsecret[iscsitAuthStringMaxLength]; 225 int ca_ini_chapsecretlen; 226 227 /* RADIUS authentication information */ 228 boolean_t ca_use_radius; 229 struct sockaddr_storage ca_radius_server; 230 uint8_t ca_radius_secret[iscsitAuthStringMaxLength]; 231 int ca_radius_secretlen; 232 233 /* authentication method list */ 234 iscsit_auth_method_t ca_method_valid_list[iscsitAuthMethodMaxCount]; 235 236 /* Target alias */ 237 char ca_tgt_alias[MAX_ISCSI_NODENAMELEN]; 238 } conn_auth_t; 239 240 /* 241 * We have three state machines (so far) between the IDM connection state 242 * machine, the session state machine, and the login state machine. All 243 * of these states have some concept of "full feature mode". It's going 244 * to be obnoxious if we use a mixture of these "ffp" representations 245 * since it will be difficult to ensure the three state machines 246 * transition at exactly the same time. We should drive decisions that 247 * depend on FFP from the IDM state machine which is actually snooping 248 * the iSCSI PDU's and will always transition at the correct time. 249 * 250 * A consequence of this approach is that there is a window just after 251 * login completes where we may get a SCSI request but the session 252 * or login state machine has not quite transitioned to "FFP". Whether 253 * this is a problem depends on how we use those state machines. This 254 * is what we should use them for: 255 * 256 * IDM Connection state machine - Decisions related to command processing 257 * including whether a connection is in FFP 258 * 259 * Session state machine - Summarize the state of all available connections 260 * for the purposes of ERL1, ERL2 and MC/S. A session in LOGGED_IN state 261 * should always have at least one FFP connection but there may be a brief 262 * window where a session in ACTIVE might have one or more FFP connections 263 * even though ACTIVE is not strictly an FFP state according to the RFC. 264 * 265 * Login state machine -- drive the login process, collect negotiated 266 * parameters. Another side effect of this approach is that we may get 267 * the "notify ffp" callback from the IDM connection state machine before 268 * the login state machine has actually transitioned to FFP state. 269 */ 270 271 struct iscsit_conn_s; 272 273 /* Add new session states above SS_MAX_STATE */ 274 #define SESSION_STATE_LIST() \ 275 item(SS_UNDEFINED) \ 276 item(SS_Q1_FREE) \ 277 item(SS_Q2_ACTIVE) \ 278 item(SS_Q3_LOGGED_IN) \ 279 item(SS_Q4_FAILED) \ 280 item(SS_Q5_CONTINUE) \ 281 item(SS_Q6_DONE) \ 282 item(SS_Q7_ERROR) \ 283 item(SS_MAX_STATE) 284 285 /* Update iscsit_ss_name table whenever session states are modified */ 286 typedef enum { 287 #define item(a) a, 288 SESSION_STATE_LIST() 289 #undef item 290 } iscsit_session_state_t; 291 292 #ifdef ISCSIT_SESS_SM_STRINGS 293 /* An array of state text values, for use in logging state transitions */ 294 static const char *iscsit_ss_name[SS_MAX_STATE + 1] = { 295 #define item(a) #a, 296 SESSION_STATE_LIST() 297 #undef item 298 }; 299 #endif 300 301 /* Add new events above SE_MAX_EVENT */ 302 #define SESSION_EVENT_LIST() \ 303 item(SE_UNDEFINED) \ 304 item(SE_CONN_IN_LOGIN) /* From login state machine */ \ 305 item(SE_CONN_LOGGED_IN) /* FFP enabled client notification */ \ 306 item(SE_CONN_FFP_FAIL) /* FFP disabled client notification */ \ 307 item(SE_CONN_FFP_DISABLE) /* FFP disabled client notification */ \ 308 item(SE_CONN_FAIL) /* Conn destroy client notification */ \ 309 item(SE_SESSION_CLOSE) /* FFP disabled client notification */ \ 310 item(SE_SESSION_REINSTATE) /* From login state machine */ \ 311 item(SE_SESSION_TIMEOUT) /* Internal */ \ 312 item(SE_SESSION_CONTINUE) /* From login state machine */ \ 313 item(SE_SESSION_CONTINUE_FAIL) /* From login state machine? */ \ 314 item(SE_MAX_EVENT) 315 316 /* Update iscsit_se_name table whenever session events are modified */ 317 typedef enum { 318 #define item(a) a, 319 SESSION_EVENT_LIST() 320 #undef item 321 } iscsit_session_event_t; 322 323 #ifdef ISCSIT_SESS_SM_STRINGS 324 /* An array of event text values, for use in logging events */ 325 static const char *iscsit_se_name[SE_MAX_EVENT + 1] = { 326 #define item(a) #a, 327 SESSION_EVENT_LIST() 328 #undef item 329 }; 330 #endif 331 332 /* 333 * Set in ist_tgt after iscsit_tgt_unbind_sess to differentiate an unbound 334 * session from a discovery session. 335 */ 336 #define SESS_UNBOUND_FROM_TGT -1 337 338 typedef struct { 339 stmf_scsi_session_t *ist_stmf_sess; 340 stmf_local_port_t *ist_lport; 341 iscsit_tgt_t *ist_tgt; 342 idm_refcnt_t ist_refcnt; 343 kmem_cache_t *ist_task_cache; 344 kmutex_t ist_sn_mutex; 345 kmutex_t ist_mutex; 346 kcondvar_t ist_cv; 347 iscsit_session_state_t ist_state; 348 iscsit_session_state_t ist_last_state; 349 sm_audit_buf_t ist_state_audit; 350 boolean_t ist_sm_busy; 351 boolean_t ist_sm_complete; 352 boolean_t ist_admin_close; 353 list_t ist_events; 354 int ist_conn_count; 355 int ist_ffp_conn_count; 356 struct iscsit_conn_s *ist_failed_conn; 357 timeout_id_t ist_state_timeout; 358 list_t ist_conn_list; 359 avl_node_t ist_tgt_ln; 360 char *ist_initiator_name; 361 char *ist_initiator_alias; 362 char *ist_target_name; 363 char *ist_target_alias; 364 uint8_t ist_isid[ISCSI_ISID_LEN]; 365 uint16_t ist_tsih; 366 uint16_t ist_tpgt_tag; 367 uint32_t ist_expcmdsn; 368 uint32_t ist_maxcmdsn; 369 avl_tree_t ist_task_list; 370 iscsit_cbuf_t *ist_rxpdu_queue; 371 } iscsit_sess_t; 372 373 /* Add new login states above ILS_MAX_STATE */ 374 #define LOGIN_STATE_LIST() \ 375 item(ILS_UNDEFINED) \ 376 item(ILS_LOGIN_INIT) \ 377 item(ILS_LOGIN_WAITING) /* Waiting for more login PDU's */ \ 378 item(ILS_LOGIN_PROCESSING) /* Processing login request */ \ 379 item(ILS_LOGIN_RESPONDING) /* Sending login response */ \ 380 item(ILS_LOGIN_RESPONDED) /* Sent login response (no trans. to FFP) */ \ 381 item(ILS_LOGIN_FFP) /* Sending last login PDU for final response */ \ 382 item(ILS_LOGIN_DONE) /* Last login PDU sent (so we can free it) */ \ 383 item(ILS_LOGIN_ERROR) /* Login error, login failed */ \ 384 item(ILS_MAX_STATE) 385 386 /* Update iscsit_ils_name table whenever login states are modified */ 387 typedef enum { 388 #define item(a) a, 389 LOGIN_STATE_LIST() 390 #undef item 391 } iscsit_login_state_t; 392 393 #ifdef ISCSIT_LOGIN_SM_STRINGS 394 /* An array of login state text values, for use in logging login progess */ 395 static const char *iscsit_ils_name[ILS_MAX_STATE + 1] = { 396 #define item(a) #a, 397 LOGIN_STATE_LIST() 398 #undef item 399 }; 400 #endif 401 402 /* Add new login events above ILE_MAX_EVENT */ 403 #define LOGIN_EVENT_LIST() \ 404 item(ILE_UNDEFINED) \ 405 item(ILE_LOGIN_RCV) \ 406 item(ILE_LOGIN_RESP_READY) \ 407 item(ILE_LOGIN_FFP) \ 408 item(ILE_LOGIN_RESP_COMPLETE) \ 409 item(ILE_LOGIN_ERROR) \ 410 item(ILE_LOGIN_CONN_ERROR) \ 411 item(ILE_MAX_EVENT) 412 413 /* Update iscsit_ile_name table whenever login events are modified */ 414 typedef enum { 415 #define item(a) a, 416 LOGIN_EVENT_LIST() 417 #undef item 418 } iscsit_login_event_t; 419 420 #ifdef ISCSIT_LOGIN_SM_STRINGS 421 /* An array of login event text values, for use in loggin login events */ 422 static const char *iscsit_ile_name[ILE_MAX_EVENT + 1] = { 423 #define item(a) #a, 424 LOGIN_EVENT_LIST() 425 #undef item 426 }; 427 #endif 428 429 typedef struct { 430 uint32_t op_initial_params_set:1, 431 op_discovery_session:1, 432 op_initial_r2t:1, 433 op_immed_data:1, 434 op_data_pdu_in_order:1, 435 op_data_sequence_in_order:1, 436 op_declarative_params_set:1; 437 uint64_t op_max_connections; 438 uint64_t op_max_recv_data_segment_length; 439 uint64_t op_max_burst_length; 440 uint64_t op_first_burst_length; 441 uint64_t op_default_time_2_wait; 442 uint64_t op_default_time_2_retain; 443 uint64_t op_max_outstanding_r2t; 444 uint64_t op_error_recovery_level; 445 } iscsit_op_params_t; 446 447 typedef struct { 448 iscsit_login_state_t icl_login_state; 449 iscsit_login_state_t icl_login_last_state; 450 sm_audit_buf_t icl_state_audit; 451 boolean_t icl_busy; 452 boolean_t icl_login_complete; 453 kmutex_t icl_mutex; 454 uint32_t icl_login_itt; 455 uint8_t icl_login_csg; 456 uint8_t icl_login_nsg; 457 boolean_t icl_login_transit; 458 conn_auth_t icl_auth; 459 iscsit_auth_client_t icl_auth_client; 460 int icl_auth_pass; 461 list_t icl_login_events; 462 list_t icl_pdu_list; 463 uint16_t icl_tsih; 464 uint8_t icl_isid[ISCSI_ISID_LEN]; 465 uint32_t icl_cmdsn; 466 uint16_t icl_tpgt_tag; 467 char *icl_target_name; 468 char *icl_target_alias; 469 char *icl_initiator_name; 470 char *icl_login_resp_buf; 471 void *icl_login_resp_itb; /* mult-pdu idm buf */ 472 int icl_login_resp_len; /* For kmem_free */ 473 int icl_login_resp_valid_len; 474 uint8_t icl_login_resp_err_class; 475 uint8_t icl_login_resp_err_detail; 476 iscsi_login_rsp_hdr_t *icl_login_resp_tmpl; 477 nvlist_t *icl_request_nvlist; 478 nvlist_t *icl_response_nvlist; 479 nvlist_t *icl_negotiated_values; 480 } iscsit_conn_login_t; 481 482 #define SET_LOGIN_ERROR(SLE_ICT, SLE_CLASS, SLE_DETAIL) \ 483 (SLE_ICT)->ict_login_sm.icl_login_resp_err_class = (SLE_CLASS); \ 484 (SLE_ICT)->ict_login_sm.icl_login_resp_err_detail = (SLE_DETAIL); 485 486 typedef struct iscsit_conn_s { 487 idm_conn_t *ict_ic; 488 iscsit_sess_t *ict_sess; 489 kmutex_t ict_mutex; 490 idm_refcnt_t ict_refcnt; 491 idm_refcnt_t ict_dispatch_refcnt; 492 list_node_t ict_sess_ln; 493 iscsit_conn_login_t ict_login_sm; 494 iscsit_op_params_t ict_op; 495 uint16_t ict_cid; 496 uint32_t ict_statsn; 497 kmutex_t ict_statsn_mutex; 498 uint32_t ict_keepalive_ttt; 499 struct iscsit_conn_s *ict_reinstate_conn; 500 uint32_t ict_reinstating:1, 501 ict_lost:1, 502 ict_destroyed:1; 503 /* 504 * Parameters for processing text commands 505 */ 506 char *ict_text_rsp_buf; 507 uint32_t ict_text_rsp_len; 508 uint32_t ict_text_rsp_valid_len; 509 uint32_t ict_text_rsp_off; 510 uint32_t ict_text_req_itt; /* from initiator */ 511 uint32_t ict_text_rsp_ttt; 512 } iscsit_conn_t; 513 514 #define ICT_FLAGS_DISCOVERY 0x00000001 515 516 typedef struct { 517 idm_buf_t *ibuf_idm_buf; 518 stmf_data_buf_t *ibuf_stmf_buf; 519 idm_pdu_t *ibuf_immed_data_pdu; 520 boolean_t ibuf_is_immed; 521 } iscsit_buf_t; 522 523 typedef struct { 524 scsi_task_t *it_stmf_task; 525 idm_task_t *it_idm_task; 526 iscsit_buf_t *it_immed_data; 527 iscsit_conn_t *it_ict; 528 kmutex_t it_mutex; 529 idm_pdu_t *it_tm_pdu; 530 uint32_t it_stmf_abort:1, 531 it_aborted:1, 532 it_active:1, 533 it_tm_task:1, 534 it_tm_responded:1; 535 uint32_t it_cmdsn; 536 uint32_t it_itt; 537 uint32_t it_ttt; 538 avl_node_t it_sess_ln; 539 } iscsit_task_t; 540 541 typedef struct iscsit_isns_cfg { 542 kmutex_t isns_mutex; 543 boolean_t isns_state; 544 list_t isns_svrs; 545 } iscsit_isns_cfg_t; 546 547 #define SERVICE_ENABLED_LIST() \ 548 item(ISE_UNDEFINED) \ 549 item(ISE_DETACHED) \ 550 item(ISE_DISABLED) \ 551 item(ISE_ENABLING) \ 552 item(ISE_ENABLED) \ 553 item(ISE_BUSY) \ 554 item(ISE_DISABLING) 555 556 /* 557 * State values for the iscsit service 558 */ 559 typedef enum { 560 #define item(a) a, 561 SERVICE_ENABLED_LIST() 562 #undef item 563 } iscsit_service_enabled_t; 564 565 566 typedef struct { 567 iscsit_service_enabled_t global_svc_state; 568 dev_info_t *global_dip; 569 ldi_ident_t global_li; 570 nvlist_t *global_props; 571 stmf_port_provider_t *global_pp; 572 stmf_dbuf_store_t *global_dbuf_store; 573 taskq_t *global_dispatch_taskq; 574 idm_refcnt_t global_refcnt; 575 avl_tree_t global_discovery_sessions; 576 avl_tree_t global_target_list; 577 list_t global_deleted_target_list; 578 avl_tree_t global_tpg_list; 579 avl_tree_t global_ini_list; 580 iscsit_tpg_t *global_default_tpg; 581 vmem_t *global_tsih_pool; 582 iscsit_isns_cfg_t global_isns_cfg; 583 iscsi_radius_props_t global_radius_server; 584 krwlock_t global_rwlock; 585 kmutex_t global_state_mutex; 586 } iscsit_global_t; 587 588 extern iscsit_global_t iscsit_global; 589 590 void 591 iscsit_global_hold(); 592 593 void 594 iscsit_global_rele(); 595 596 void 597 iscsit_global_wait_ref(); 598 599 idm_status_t 600 iscsit_login_sm_init(iscsit_conn_t *ict); 601 602 void 603 iscsit_login_sm_fini(iscsit_conn_t *ict); 604 605 void 606 iscsit_login_sm_event(iscsit_conn_t *ic, iscsit_login_event_t event, 607 idm_pdu_t *pdu); 608 609 void 610 iscsit_login_sm_event_locked(iscsit_conn_t *ic, iscsit_login_event_t event, 611 idm_pdu_t *pdu); 612 613 int 614 iscsit_is_v4_mapped(struct sockaddr_storage *sa, struct sockaddr_storage *v4sa); 615 616 void 617 iscsit_send_async_event(iscsit_conn_t *ict, uint8_t async_event); 618 619 void 620 iscsit_pdu_tx(idm_pdu_t *pdu); 621 622 void 623 iscsit_send_reject(iscsit_conn_t *ict, idm_pdu_t *rejected_pdu, uint8_t reason); 624 625 void 626 iscsit_text_cmd_fini(iscsit_conn_t *ict); 627 628 /* 629 * IDM conn ops 630 */ 631 632 idm_rx_pdu_cb_t iscsit_op_scsi_cmd; 633 idm_rx_pdu_cb_t iscsit_rx_pdu; 634 idm_rx_pdu_error_cb_t iscsit_rx_pdu_error; 635 idm_rx_pdu_cb_t iscsit_rx_scsi_rsp; 636 idm_task_cb_t iscsit_task_aborted; 637 idm_client_notify_cb_t iscsit_client_notify; 638 idm_build_hdr_cb_t iscsit_build_hdr; 639 idm_update_statsn_cb_t iscsit_update_statsn; 640 idm_keepalive_cb_t iscsit_keepalive; 641 642 /* 643 * lport entry points 644 */ 645 stmf_status_t 646 iscsit_xfer_scsi_data(scsi_task_t *task, stmf_data_buf_t *dbuf, 647 uint32_t ioflags); 648 649 stmf_status_t 650 iscsit_send_scsi_status(scsi_task_t *task, uint32_t ioflags); 651 652 void 653 iscsit_lport_task_free(scsi_task_t *task); 654 655 stmf_status_t 656 iscsit_abort(stmf_local_port_t *lport, int abort_cmd, void *arg, 657 uint32_t flags); 658 659 void 660 iscsit_ctl(stmf_local_port_t *lport, int cmd, void *arg); 661 662 /* 663 * Connection functions 664 */ 665 idm_status_t 666 iscsit_conn_reinstate(iscsit_conn_t *existing_ict, iscsit_conn_t *ict); 667 668 void 669 iscsit_conn_set_auth(iscsit_conn_t *ict); 670 671 void 672 iscsit_conn_hold(iscsit_conn_t *ict); 673 674 void 675 iscsit_conn_rele(iscsit_conn_t *ict); 676 677 void 678 iscsit_conn_logout(iscsit_conn_t *ict); 679 680 /* 681 * Session functions 682 */ 683 int 684 iscsit_sess_avl_compare(const void *void_sess1, const void *void_sess2); 685 686 iscsit_sess_t * 687 iscsit_sess_create(iscsit_tgt_t *tgt, iscsit_conn_t *ict, 688 uint32_t cmdsn, uint8_t *isid, uint16_t tag, 689 char *initiator_name, char *target_name, 690 uint8_t *error_class, uint8_t *error_detail); 691 692 void 693 iscsit_sess_destroy(iscsit_sess_t *ist); 694 695 void 696 iscsit_sess_hold(iscsit_sess_t *ist); 697 698 idm_status_t 699 iscsit_sess_check_hold(iscsit_sess_t *ist); 700 701 void 702 iscsit_sess_rele(iscsit_sess_t *ist); 703 704 iscsit_conn_t * 705 iscsit_sess_lookup_conn(iscsit_sess_t *ist, uint16_t cid); 706 707 void 708 iscsit_sess_bind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict); 709 710 void 711 iscsit_sess_unbind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict); 712 713 void 714 iscsit_sess_close(iscsit_sess_t *ist); 715 716 iscsit_sess_t * 717 iscsit_sess_reinstate(iscsit_tgt_t *tgt, iscsit_sess_t *ist, iscsit_conn_t *ict, 718 uint8_t *error_class, uint8_t *error_detail); 719 720 void 721 iscsit_sess_sm_event(iscsit_sess_t *ist, iscsit_session_event_t event, 722 iscsit_conn_t *ict); 723 724 /* 725 * Target, TPGT, TPGT and portal functions 726 */ 727 728 void 729 iscsit_tgt_sm_event(iscsit_tgt_t *tgt, iscsit_tgt_event_t event); 730 731 void 732 tgt_sm_event_locked(iscsit_tgt_t *tgt, iscsit_tgt_event_t event); 733 734 it_cfg_status_t 735 iscsit_config_merge_tgt(it_config_t *cfg); 736 737 void 738 iscsit_config_destroy_tgts(list_t *tgt_del_list); 739 740 void 741 iscsit_config_destroy_tpgts(list_t *tpgt_del_list); 742 743 iscsit_tgt_t * 744 iscsit_tgt_lookup(char *target_name); 745 746 iscsit_tgt_t * 747 iscsit_tgt_lookup_locked(char *target_name); 748 749 int 750 iscsit_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2); 751 752 int 753 iscsit_tpgt_avl_compare(const void *void_tpgt1, const void *void_tpgt2); 754 755 void 756 iscsit_tgt_hold(iscsit_tgt_t *tgt); 757 758 void 759 iscsit_tgt_rele(iscsit_tgt_t *tgt); 760 761 iscsit_tpgt_t * 762 iscsit_tgt_lookup_tpgt(iscsit_tgt_t *tgt, uint16_t tag); 763 764 void 765 iscsit_tpgt_hold(iscsit_tpgt_t *tpgt); 766 767 void 768 iscsit_tpgt_rele(iscsit_tpgt_t *tpgt); 769 770 iscsit_portal_t * 771 iscsit_tgt_lookup_portal(iscsit_tgt_t *tgt, struct sockaddr_storage *sa, 772 iscsit_tpgt_t **output_tpgt); 773 774 iscsit_sess_t * 775 iscsit_tgt_lookup_sess(iscsit_tgt_t *tgt, char *initiator_name, 776 uint8_t *isid, uint16_t tsih, uint16_t tag); 777 778 void 779 iscsit_tgt_bind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess); 780 781 void 782 iscsit_tgt_unbind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess); 783 784 it_cfg_status_t 785 iscsit_config_merge_tpg(it_config_t *cfg, list_t *tpg_del_list); 786 787 void 788 iscsit_config_destroy_tpgs(list_t *tpg_del_list); 789 790 iscsit_tpg_t * 791 iscsit_tpg_lookup(char *tpg_name); 792 793 int 794 iscsit_tpg_avl_compare(const void *void_tpg1, const void *void_tpg2); 795 796 void 797 iscsit_tpg_hold(iscsit_tpg_t *tpg); 798 799 void 800 iscsit_tpg_rele(iscsit_tpg_t *tpg); 801 802 iscsit_tpg_t * 803 iscsit_tpg_createdefault(); 804 805 void 806 iscsit_tpg_destroydefault(iscsit_tpg_t *tpg); 807 808 idm_status_t 809 iscsit_tpg_online(iscsit_tpg_t *tpg); 810 811 void 812 iscsit_tpg_offline(iscsit_tpg_t *tpg); 813 814 iscsit_portal_t * 815 iscsit_tpg_portal_lookup(iscsit_tpg_t *tpg, struct sockaddr_storage *sa); 816 817 void 818 iscsit_portal_hold(iscsit_portal_t *portal); 819 820 void 821 iscsit_portal_rele(iscsit_portal_t *portal); 822 823 it_cfg_status_t 824 iscsit_config_merge_ini(it_config_t *cfg); 825 826 int 827 iscsit_ini_avl_compare(const void *void_ini1, const void *void_ini2); 828 829 iscsit_ini_t * 830 iscsit_ini_lookup_locked(char *ini_name); 831 832 int 833 iscsit_portal_avl_compare(const void *void_portal1, const void *void_portal2); 834 835 int 836 iscsit_verify_chap_resp(iscsit_conn_login_t *lsm, 837 unsigned int chap_i, uchar_t *chap_c, unsigned int challenge_len, 838 uchar_t *chap_r, unsigned int resp_len); 839 840 void 841 iscsit_rxpdu_queue_monitor_start(void); 842 843 void 844 iscsit_rxpdu_queue_monitor_stop(void); 845 846 #endif /* _ISCSIT_H_ */ 847