a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER START
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The contents of this file are subject to the terms of the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Common Development and Distribution License (the "License").
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You may not use this file except in compliance with the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * See the License for the specific language governing permissions
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and limitations under the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * When distributing Covered Code, include this CDDL HEADER in each
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If applicable, add the following below this CDDL HEADER, with the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fields enclosed by brackets "[]" replaced with your own identifying
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * information: Portions Copyright [yyyy] [name of copyright owner]
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER END
d618d68dcf9c6c8f2c1e2fbbd4de1de0cf30150ePriya Krishnan * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
57ff5e7e2f79bd09ccd01cdeba02f38fdde17a80Jeff Biseda * Copyright (c) 2013 by Delphix. All rights reserved.
ff9de39482f57a342b973f41ee343e24db962236Rick McNeal * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s1_free(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s2_xpt_wait(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s3_xpt_up(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s4_in_login(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s5_logged_in(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s6_in_logout(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s7_logout_req(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s8_cleanup(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s9_init_error(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapidm_state_s9a_rejected(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesidm_state_s9b_wait_snd_done_cb(idm_pdu_t *pdu,
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_status_t status);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesidm_state_s9b_wait_snd_done(idm_conn_t *ic,
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_conn_event_ctx_t *event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s10_in_cleanup(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s11_complete(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s12_enable_dm(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_update_state(idm_conn_t *ic, idm_conn_state_t new_state,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_sm_validate_pdu(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_ffp_disable(idm_conn_t *ic, idm_ffp_disable_t disable_type);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_initial_login_actions(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_login_success_actions(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Caller should have assigned a unique connection ID. Use this
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * connection ID to create a unique connection name string
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) snprintf(taskq_name, sizeof (taskq_name) - 1, "conn_sm%08x",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ic->ic_state_taskq = taskq_create(taskq_name, 1, minclsyspri, 4, 16384,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap mutex_init(&ic->ic_state_mutex, NULL, MUTEX_DEFAULT, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap cv_init(&ic->ic_state_cv, NULL, CV_DEFAULT, NULL);
1050fd6d7cf8ededf1816f2b4d8e5d047410260cJames Moore * The connection may only be partially created. If there
1050fd6d7cf8ededf1816f2b4d8e5d047410260cJames Moore * is no taskq, then the connection SM was not initialized.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The thread that generated the event that got us here may still
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * hold the ic_state_mutex. Once it is released we can safely
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * destroy it since there is no way to locate the object now.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_event(idm_conn_t *ic, idm_conn_event_t event, uintptr_t event_info)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event_locked(ic, event, event_info, CT_NONE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_reinstate_event(idm_conn_t *old_ic, idm_conn_t *new_ic)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (((old_ic->ic_conn_type == CONN_TYPE_INI) &&
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event_locked(new_ic->ic_reinstate_conn,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap CE_CONN_REINSTATE, (uintptr_t)new_ic, CT_NONE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_tx_pdu_event(idm_conn_t *ic, idm_conn_event_t event,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event_locked(ic, event, event_info, CT_TX_PDU);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_rx_pdu_event(idm_conn_t *ic, idm_conn_event_t event,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event_locked(ic, event, event_info, CT_RX_PDU);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_event_locked(idm_conn_t *ic, idm_conn_event_t event,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uintptr_t event_info, idm_pdu_event_type_t pdu_event_type)
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(mutex_owned(&ic->ic_state_mutex));
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_sm_audit_event(&ic->ic_state_audit, SAS_IDM_CONN,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * It's very difficult to prevent a few straggling events
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * at the end. For example idm_sorx_thread will generate
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * a CE_TRANSPORT_FAIL event when it exits. Rather than
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * push complicated restrictions all over the code to
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * prevent this we will simply drop the events (and in
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the case of PDU events release them appropriately)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * since they are irrelevant once we are in a terminal state.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Of course those threads need to have appropriate holds on
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the connection otherwise it might disappear.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap IDM_SM_LOG(CE_NOTE, "*** Dropping event %s (%d) because of"
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap "state %s (%d)",
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Normal event handling
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap event_ctx = kmem_zalloc(sizeof (*event_ctx), KM_SLEEP);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap event_ctx->iec_pdu_event_type = pdu_event_type;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) taskq_dispatch(ic->ic_state_taskq, &idm_conn_event_handler,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event_ctx_t *event_ctx = event_ctx_opaque;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_pdu_t *pdu = (idm_pdu_t *)event_ctx->iec_info;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap IDM_SM_LOG(CE_NOTE, "idm_conn_event_handler: conn %p event %s(%d)",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_t *, ic, idm_conn_event_ctx_t *, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate event
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT3U(event_ctx->iec_event, <, CE_MAX_EVENT);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate current state
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate PDU-related events against the current state. If a PDU
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is not allowed in the current state we change the event to a
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * protocol error. This simplifies the state-specific event handlers.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * For example the CS_S2_XPT_WAIT state only needs to handle the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CE_TX_PROTOCOL_ERROR and CE_RX_PROTOCOL_ERROR events since
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * no PDU's can be transmitted or received in that state.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (event_ctx->iec_pdu_event_type != CT_NONE) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = idm_conn_sm_validate_pdu(ic, event_ctx, pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Change event and forward the PDU
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Change event and forward the PDU.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Let the state-specific event handlers take
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * care of it.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * It never even happened
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap IDM_SM_LOG(CE_NOTE, "*** drop PDU %p", (void *) pdu);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States case CS_S9B_WAIT_SND_DONE:
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_state_s9b_wait_snd_done(ic, event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Now that we've updated the state machine, if this was
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * a PDU-related event take the appropriate action on the PDU
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * (transmit it, forward it to the clients RX callback, drop
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (event_ctx->iec_pdu_event_type != CT_NONE) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Update outstanding PDU event count (see idm_pdu_tx for
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * how this is used)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ||
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_pdu_event_type == CT_RX_PDU)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s1_free(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S2_XPT_WAIT, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* This should never happen */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s2_xpt_wait(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S4_IN_LOGIN, event_ctx);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States case CE_TRANSPORT_FAIL:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s3_xpt_up(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
ff9de39482f57a342b973f41ee343e24db962236Rick McNeal /* Keep login timeout active through S3 and into S4 */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S4_IN_LOGIN, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Don't need to cancel login timer since the timer is
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * presumed to be the source of this event.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_LOGIN_FAIL, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Iscsit doesn't want to hear from us again in this case.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Since it rejected the connection it doesn't have a
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * connection context to handle additional notifications.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * IDM needs to just clean things up on its own.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap idm_update_state(ic, CS_S9A_REJECTED, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_LOGIN_FAIL, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s4_in_login(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Login timer should no longer be active after leaving this
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ic->ic_client_callback == NULL);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S12_ENABLE_DM, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S5_LOGGED_IN, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_LOGIN_FAIL, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allow the logout response pdu to be sent and defer
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * the state machine cleanup until the completion callback.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Only 1 level or callback interposition is allowed.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_state_s9b_wait_snd_done_cb;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_update_state(ic, CS_S9B_WAIT_SND_DONE,
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ic->ic_client_callback == NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Need to deliver this PDU to the initiator now because after
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * we update the state to CS_S9_INIT_ERROR the initiator will
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * no longer be in an appropriate state.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* FALLTHROUGH */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_LOGIN_FAIL, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan * A session reinstatement request can be received while a
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan * session is active and a login is in process. The iSCSI
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan * connections are shut down by a CE_LOGOUT_SESSION_SUCCESS
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan * event sent from the session to the IDM layer.
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan ic->ic_transport_ops->it_ini_conn_disconnect(ic);
47715e7fd18d93fbdad6de94604baaa63665f0fbPriya Krishnan idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ic->ic_client_callback == NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Initiator connections will see initial login PDU
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * in this state. Target connections see initial
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * login PDU in "xpt up" state.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (!(ic->ic_state_flags & CF_INITIAL_LOGIN)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s5_logged_in(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
d618d68dcf9c6c8f2c1e2fbbd4de1de0cf30150ePriya Krishnan /* MC/S: when removing the non-leading connection */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_CONN_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S6_IN_LOGOUT, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_SESS_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S6_IN_LOGOUT, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_SESS_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Close connection */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_ini_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S7_LOGOUT_REQ, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_CONN_FAIL); /* Implicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S8_CLEANUP, event_ctx);
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_TIMEOUT:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s6_in_logout_success_snd_done(idm_pdu_t *pdu, idm_status_t status)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * This pdu callback can be invoked by the tx thread,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * so run the disconnect code from another thread.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event(ic, CE_LOGOUT_SUCCESS_SND_DONE, (uintptr_t)pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s6_in_logout_fail_snd_done(idm_pdu_t *pdu, idm_status_t status)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * This pdu callback can be invoked by the tx thread,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * so run the disconnect code from another thread.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event(ic, CE_LOGOUT_FAIL_SND_DONE, (uintptr_t)pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s6_in_logout(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Close connection (if it's not already closed) */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* restore client callback */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* restore client callback */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S8_CLEANUP, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allow the logout response pdu to be sent and defer
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the state machine update until the completion callback.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Only 1 level or callback interposition is allowed.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (event_ctx->iec_event == CE_LOGOUT_SUCCESS_SND) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Need to deliver this PDU to the initiator now because after
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * we update the state to CS_S11_COMPLETE the initiator will
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * no longer be in an appropriate state.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* FALLTHROUGH */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Close connection (if it's not already closed) */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_ini_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* T14 Do nothing */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S8_CLEANUP, event_ctx);
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_TIMEOUT:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s7_logout_req(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Must cancel logout timer before leaving this state */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_CONN_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S6_IN_LOGOUT, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_SESS_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S6_IN_LOGOUT, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* T12 Do nothing */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* FALLTHROUGH */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_CONN_FAIL); /* Implicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S8_CLEANUP, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ffp_disable(ic, FD_SESS_LOGOUT); /* Explicit logout */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Close connection (if it's not already closed) */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_ini_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_TIMEOUT:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s8_cleanup(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Need to cancel the cleanup timeout before leaving this state
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * if it hasn't already fired.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*FALLTHROUGH*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S10_IN_CLEANUP, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* restore client callback */
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_TIMEOUT:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* ARGSUSED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s9_init_error(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /* All events ignored in this state */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap/* ARGSUSED */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapidm_state_s9a_rejected(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /* All events ignored in this state */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States}
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesidm_state_s9b_wait_snd_done_cb(idm_pdu_t *pdu, idm_status_t status)
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States{
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_conn_t *ic = pdu->isp_ic;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * This pdu callback can be invoked by the tx thread,
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * so run the disconnect code from another thread.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States pdu->isp_status = status;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_conn_event(ic, CE_LOGIN_FAIL_SND_DONE, (uintptr_t)pdu);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States}
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States/*
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * CS_S9B_WAIT_SND_DONE -- wait for callback completion.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States/* ARGSUSED */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United Statesidm_state_s9b_wait_snd_done(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States{
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_pdu_t *pdu;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * Wait for completion of the login fail sequence and then
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * go to state S9_INIT_ERROR to clean up the connection.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States switch (event_ctx->iec_event) {
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_FAIL_SND_DONE:
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States pdu = (idm_pdu_t *)event_ctx->iec_info;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /* restore client callback */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States pdu->isp_callback = ic->ic_client_callback;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States ic->ic_client_callback = NULL;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_pdu_complete(pdu, pdu->isp_status);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States /* All other events ignored */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States }
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s10_in_cleanup(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Need to cancel the cleanup timeout before leaving this state
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * if it hasn't already fired.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S8_CLEANUP, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*FALLTHROUGH*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S11_COMPLETE, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* restore client callback */
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States case CE_LOGIN_TIMEOUT:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Don't care */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* ARGSUSED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s11_complete(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Cleanup logout success/fail completion if it's been delayed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * until now.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States *
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * All new events are filtered out before reaching this state, but
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * there might already be events in the event queue, so handle the
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * SND_DONE events here. Note that if either of the following
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * SND_DONE events happens AFTER the change to state S11, then the
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * event filter inside dm_conn_event_locked does enough cleanup.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* restore client callback */
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_state_s12_enable_dm(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S5_LOGGED_IN, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_update_state(ic, CS_S9_INIT_ERROR, event_ctx);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * We expect to always hear back from the transport layer
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * once we have an "enable data-mover" request outstanding.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Therefore we'll ignore other events that may occur even
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * when they clearly indicate a problem and wait for
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CE_ENABLE_DM_FAIL. On a related note this means the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * transport must ensure that it eventually completes the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * "enable data-mover" operation with either success or
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * failure -- otherwise we'll be stuck here.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_update_state(idm_conn_t *ic, idm_conn_state_t new_state,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate new state
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Update state in context. We protect this with a mutex
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * even though the state machine code is single threaded so that
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * other threads can check the state value atomically.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap IDM_SM_LOG(CE_NOTE, "idm_update_state: conn %p, evt %s(%d), "
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_ce_name[event_ctx->iec_event], event_ctx->iec_event,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_t *, ic, idm_conn_state_t, new_state);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_sm_audit_state_change(&ic->ic_state_audit, SAS_IDM_CONN,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Finish any connection related setup including
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * waking up the idm_tgt_conn_accept thread.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and starting the login timer. If the function
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fails then we return to "free" state.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((rc = idm_tgt_conn_finish(ic)) != IDM_STATUS_SUCCESS) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * First login received will cause a transition to
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CS_S4_IN_LOGIN. Start login timer.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_state_timeout = timeout(idm_login_timeout, ic,
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) idm_notify_client(ic, CN_READY_FOR_LOGIN, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IDM can go to FFP before the initiator but it
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * needs to go to FFP after the target (IDM target should
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * go to FFP after notify_ack).
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Connection reinstatement is complete */
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_conn_event(ic->ic_reinstate_conn,
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States CE_CONN_REINSTATE_SUCCESS, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Start logout timer for target connections */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_state_timeout = timeout(idm_logout_req_timeout,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Close connection (if it's not already closed) */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_ini_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Stop executing active tasks */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Start logout timer */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_state_timeout = timeout(idm_cleanup_timeout, ic,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * We never finished establishing the connection so no
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States * disconnect. No client notifications because the client
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * rejected the connection.
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States case CS_S9B_WAIT_SND_DONE:
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_conn_disconnect(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*FALLTHROUGH*/
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * No more traffic on this connection. If this is an
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * initiator connection and we weren't connected yet
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * then don't send the "connect lost" event.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * It's useful to the initiator to know whether we were
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * logging in at the time so send that information in the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * data field.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (uintptr_t)(ic->ic_last_state == CS_S4_IN_LOGIN));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Abort all tasks */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Handle terminal state actions on the global taskq so
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * we can clean up all the connection resources from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * a separate thread context.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_refcnt_async_wait_ref(&ic->ic_refcnt, &idm_conn_unref);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The Enable DM state indicates the initiator to initiate
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the hello sequence and the target to get ready to accept
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the iSER Hello Message.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_ini_enable_datamover(ic) :
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ic->ic_transport_ops->it_tgt_enable_datamover(ic);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_conn_event(ic, CE_ENABLE_DM_SUCCESS, NULL);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States default:
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(0);
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
e97fb1537da57d70dafde456e25bbd6bcc839475Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Client should not be notified that the connection is destroyed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * until all references on the idm connection have been removed.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Otherwise references on the associated client context would need
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * to be tracked separately which seems like a waste (at least when
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * there is a one for one correspondence with references on the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IDM connection).
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_CONNECT_DESTROY, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Initiator may destroy connection during this call */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) idm_notify_client(ic, CN_CONNECT_DESTROY, NULL);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Don't notify the client since it rejected the connection */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_conn_sm_validate_pdu(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT((event_ctx->iec_pdu_event_type == CT_RX_PDU) ||
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Let's check the simple stuff first. Make sure if this is a
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target connection that the PDU is appropriate for a target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and if this is an initiator connection that the PDU is
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * appropriate for an initiator. This code is not in the data
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * path so organization is more important than performance.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Only the initiator should send these PDU's and
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * only the target should receive them.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_pdu_event_type == CT_RX_PDU)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap reason_string = "Invalid RX PDU for initiator";
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_pdu_event_type == CT_TX_PDU)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Only the target should send these PDU's and
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * only the initiator should receive them.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_pdu_event_type == CT_RX_PDU)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_pdu_event_type == CT_TX_PDU)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap reason_string = "Invalid TX PDU for initiator";
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Now validate the opcodes against the current state.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap reason_string = "PDU not allowed in current state";
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Obviously S1-S3 are not allowed since login hasn't started.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * S8 is probably out as well since the connection has been
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* This should never happen -- we already checked above */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*NOTREACHED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap action = ((event_ctx->iec_pdu_event_type == CT_TX_PDU) ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* ARGSUSED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_pdu_tx_protocol_error(idm_conn_t *ic, idm_pdu_t *pdu)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return the PDU to the caller indicating it was a protocol error.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Caller can take appropriate action.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_pdu_complete(pdu, IDM_STATUS_PROTOCOL_ERROR);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_pdu_rx_protocol_error(idm_conn_t *ic, idm_pdu_t *pdu)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Forward PDU to caller indicating it is a protocol error.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Caller should take appropriate action.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*ic->ic_conn_ops.icb_rx_error)(ic, pdu, IDM_STATUS_PROTOCOL_ERROR);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_notify_client(idm_conn_t *ic, idm_client_notify_t cn, uintptr_t data)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * We may want to make this more complicated at some point but
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * for now lets just call the client's notify function and return
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the status.
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(!mutex_owned(&ic->ic_state_mutex));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap IDM_SM_LOG(CE_NOTE, "idm_notify_client: ic=%p %s(%d)\n",
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return ((*ic->ic_conn_ops.icb_client_notify)(ic, cn, data));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * On the initiator side the client will see this notification
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * before the actual login succes PDU. This shouldn't be a big
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * deal since the initiator drives the connection. It can simply
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * wait for the login response then start sending SCSI commands.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Kind ugly though compared with the way things work on target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * connections.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rc = idm_notify_client(ic, CN_FFP_ENABLED, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_ffp_disable(idm_conn_t *ic, idm_ffp_disable_t disable_type)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Client can't "fail" CN_FFP_DISABLED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_initial_login_actions(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT((event_ctx->iec_event == CE_LOGIN_RCV) ||
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Currently it's not clear what we would do here -- since
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * we went to the trouble of coding an "initial login" hook
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * we'll leave it in for now. Remove before integration if
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it's not used for anything.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapidm_login_success_actions(idm_conn_t *ic, idm_conn_event_ctx_t *event_ctx)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_pdu_t *pdu = (idm_pdu_t *)event_ctx->iec_info;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT((event_ctx->iec_event == CE_LOGIN_SUCCESS_RCV) ||
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (event_ctx->iec_event == CE_LOGIN_SUCCESS_SND));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Save off CID