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