450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER START
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * The contents of this file are subject to the terms of the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Common Development and Distribution License (the "License").
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You may not use this file except in compliance with the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * or http://www.opensolaris.org/os/licensing.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * See the License for the specific language governing permissions
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * and limitations under the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If applicable, add the following below this CDDL HEADER, with the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER END
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/cpuvar.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/types.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/conf.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/file.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/ddi.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/sunddi.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/modctl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/sysmacros.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/socket.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/strsubr.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/door.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/note.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/sdt.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/stmf.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/stmf_ioctl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/portif.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define PPPT_TGT_SM_STRINGS
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "pppt.h"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetypedef struct {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte list_node_t te_ctx_node;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_event_t te_ctx_event;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte} tgt_event_ctx_t;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_sm_event(pppt_tgt_t *tgt, pppt_tgt_event_t event);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_event_locked(pppt_tgt_t *tgt, pppt_tgt_event_t event);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_event_dispatch(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_created(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_onlining(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_online(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_stmf_online(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_need_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_offlining(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_stmf_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_stmf_dereg(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_stmf_dereg_fail(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlapstatic void
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlappppt_tgt_offline_task(void *arg);
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_dereg_retry(void *arg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_dereg_task(void *arg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_new_state(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_state_t new_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_sm_ctl(stmf_local_port_t *lport, int cmd, void *arg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *pppt_tgt;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt = (pppt_tgt_t *)lport->lport_port_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (cmd) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_CMD_LPORT_ONLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(pppt_tgt, TE_STMF_ONLINE_REQ);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_CMD_LPORT_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(pppt_tgt, TE_STMF_OFFLINE_REQ);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ACK_LPORT_ONLINE_COMPLETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(pppt_tgt, TE_STMF_ONLINE_COMPLETE_ACK);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ACK_LPORT_OFFLINE_COMPLETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(pppt_tgt, TE_STMF_OFFLINE_COMPLETE_ACK);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_t *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_create(stmf_ic_reg_port_msg_t *reg_port, stmf_status_t *msg_errcode)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *result;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_local_port_t *lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int total_devid_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte total_devid_len = sizeof (scsi_devid_desc_t) +
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte reg_port->icrp_port_id->ident_length - 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Each target is an STMF local port. Allocate an STMF local port
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * including enough space to store a scsi_devid_desc_t for this target.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport = stmf_alloc(STMF_STRUCT_STMF_LOCAL_PORT,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (pppt_tgt_t) + total_devid_len, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lport == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *msg_errcode = STMF_ALLOC_FAILURE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = lport->lport_port_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_state = TS_CREATED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Use pointer arithmetic to find scsi_devid_desc_t */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_devid = (scsi_devid_desc_t *)(result + 1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(reg_port->icrp_port_id, result->target_devid, total_devid_len);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_devid->piv = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_devid->code_set = CODE_SET_ASCII;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_devid->association = ID_IS_TARGET_PORT;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_init(&result->target_mutex, NULL, MUTEX_DEFAULT, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cv_init(&result->target_cv, NULL, CV_DEFAULT, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte list_create(&result->target_events, sizeof (tgt_event_ctx_t),
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte offsetof(tgt_event_ctx_t, te_ctx_node));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte avl_create(&result->target_sess_list, pppt_sess_avl_compare_by_name,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (pppt_sess_t), offsetof(pppt_sess_t, ps_target_ln));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_abort_timeout = 120; /* seconds */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_id = result->target_devid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_pp = pppt_global.global_pp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_ds = pppt_global.global_dbuf_store;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_xfer_data = &pppt_lport_xfer_data;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_send_status = &pppt_lport_send_status;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_task_free = &pppt_lport_task_free;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_abort = &pppt_lport_abort;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_ctl = &pppt_lport_ctl;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result->target_stmf_lport = lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Since this is a proxy port we need to do set the relative
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * target port identifier before registering it with STMF.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_set_port_standby(lport, reg_port->icrp_relative_port_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Register the target with STMF. STMF may immediately ask us to go
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * online so insure any additional config setup is complete.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_register_local_port(lport) != STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *msg_errcode = STMF_FAILURE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_destroy(result);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (result);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_destroy(pppt_tgt_t *tgt)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Destroy target */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte avl_destroy(&tgt->target_sess_list);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte list_destroy(&tgt->target_events);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cv_destroy(&tgt->target_cv);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_destroy(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_free(tgt->target_stmf_lport); /* Also frees "tgt' */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_t *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_lookup(scsi_devid_desc_t *tgt_devid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *result;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_GLOBAL_LOCK();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = pppt_tgt_lookup_locked(tgt_devid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_GLOBAL_UNLOCK();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (result);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_t *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_lookup_locked(scsi_devid_desc_t *tgt_devid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *result;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t tmptgt;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bzero(&tmptgt, sizeof (tmptgt));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tmptgt.target_devid = tgt_devid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = avl_find(&pppt_global.global_target_list, &tmptgt, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (result);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_async_delete(pppt_tgt_t *tgt)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Generate TE_DELETE event to target state machine */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_DELETE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte const pppt_tgt_t *ptgt1 = void_tgt1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte const pppt_tgt_t *ptgt2 = void_tgt2;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int result;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Sort by code set then ident */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ptgt1->target_devid->code_set <
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptgt2->target_devid->code_set) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (-1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (ptgt1->target_devid->code_set >
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptgt2->target_devid->code_set) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Next by ident length */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ptgt1->target_devid->ident_length <
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptgt2->target_devid->ident_length) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (-1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (ptgt1->target_devid->ident_length >
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptgt2->target_devid->ident_length) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Code set and ident length both match, now compare idents */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = memcmp(ptgt1->target_devid->ident, ptgt2->target_devid->ident,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptgt1->target_devid->ident_length);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (result < 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (-1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (result > 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Target state machine
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_sm_event(pppt_tgt_t *tgt, pppt_tgt_event_t event)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_event_locked(tgt, event);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_event_locked(pppt_tgt_t *tgt, pppt_tgt_event_t event)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_event_ctx_t *ctx;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap event = (event < TE_MAX_EVENT) ? event : TE_UNDEFINED;
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap DTRACE_PROBE2(pppt__tgt__event, pppt_tgt_t *, tgt,
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap pppt_tgt_event_t, event);
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap stmf_trace("pppt", "pppt_tgt_event: tgt %p event %s(%d)",
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap (void *)tgt, pppt_te_name[event], event);
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_refcount++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ctx = kmem_zalloc(sizeof (*ctx), KM_SLEEP);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ctx->te_ctx_event = event;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte list_insert_tail(&tgt->target_events, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Use the target_sm_busy flag to keep the state machine single
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * threaded. This also serves as recursion avoidance since this
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * flag will always be set if we call pppt_tgt_sm_event from
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * within the state machine code.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (!tgt->target_sm_busy) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_sm_busy = B_TRUE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte while (!list_is_empty(&tgt->target_events)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ctx = list_head(&tgt->target_events);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte list_remove(&tgt->target_events, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_event_dispatch(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_sm_busy = B_FALSE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_refcount--;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cv_signal(&tgt->target_cv);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_event_dispatch(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap stmf_trace("pppt", "pppt_tgt_event_dispatch: tgt %p event %s(%d)",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void *)tgt, pppt_te_name[ctx->te_ctx_event], ctx->te_ctx_event);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* State independent actions */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_deleting = B_TRUE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* State dependent actions */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (tgt->target_state) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_CREATED:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_created(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_ONLINING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_onlining(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_ONLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_online(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_STMF_ONLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_stmf_online(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_NEED_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_deleting_need_offline(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_OFFLINING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_offlining(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_offline(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_STMF_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_stmf_offline(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_STMF_DEREG:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_deleting_stmf_dereg(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_STMF_DEREG_FAIL:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_deleting_stmf_dereg_fail(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_deleting(tgt, ctx);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte kmem_free(ctx, sizeof (*ctx));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_created(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_ONLINING);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_STMF_DEREG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We're already offline but update to an equivelant
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * state just to note that STMF talked to us.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_onlining(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_ONLINE_SUCCESS:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_ONLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_ONLINE_FAIL:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_STMF_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* TE_DELETE is handled in tgt_sm_event_dispatch() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are busy going
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * online.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_online(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (tgt->target_deleting) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_NEED_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_STMF_ONLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* TE_DELETE is handled in tgt_sm_event_dispatch() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are busy going
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * online (waiting for acknowlegement from STMF)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_stmf_online(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_NEED_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_OFFLINING);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Already online */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_ALREADY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_ONLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_need_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_OFFLINING);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* TE_DELETE is handled in tgt_sm_event_dispatch() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we need to be offlined
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_ONLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_offlining(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_OFFLINE_COMPLETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* TE_DELETE is handled in tgt_sm_event_dispatch() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are busy going
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * offline.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (tgt->target_deleting) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_STMF_DEREG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_STMF_OFFLINE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* TE_DELETE is handled in tgt_sm_event_dispatch() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are busy going
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * offline.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_stmf_offline(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_ONLINING);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_DELETE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_STMF_DEREG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Already offline */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_ALREADY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_stmf_dereg(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Terminal state, no events */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are being deleted
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_DEREG_SUCCESS:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_DEREG_FAIL:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_STMF_DEREG_FAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting_stmf_dereg_fail(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Terminal state, no events */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are being deleted
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_DEREG_RETRY:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt_sm_new_state(tgt, ctx, TS_DELETING_STMF_DEREG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_deleting(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Terminal state, no events */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ctx->te_ctx_event) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_REQ:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We can't complete STMF's request since we are being deleted
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl((ctx->te_ctx_event == TE_STMF_ONLINE_REQ) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_ONLINE_COMPLETE :
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_ONLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TE_STMF_OFFLINE_COMPLETE_ACK:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlappppt_tgt_offline(pppt_tgt_t *tgt)
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap{
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap (void) taskq_dispatch(pppt_global.global_dispatch_taskq,
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap pppt_tgt_offline_task, tgt, KM_SLEEP);
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap}
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlapstatic void
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlappppt_tgt_offline_task(void *arg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *tgt = arg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_sess_t *ps, *next_ps;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap stmf_trace("pppt", "pppt_tgt_offline %p", (void *)tgt);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_GLOBAL_LOCK();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ps = avl_first(&tgt->target_sess_list); ps != NULL; ps = next_ps) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte next_ps = AVL_NEXT(&tgt->target_sess_list, ps);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&ps->ps_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (!ps->ps_closed) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_sess_close_locked(ps);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&ps->ps_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_GLOBAL_UNLOCK();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_OFFLINE_COMPLETE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_OFFLINE_COMPLETE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_stmf_lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap stmf_trace("pppt", "pppt_tgt_offline complete %p", (void *)tgt);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_dereg_retry(void *arg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *tgt = arg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Rather than guaranteeing the target state machine code will not
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * block for long periods of time (tying up this callout thread)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * we will queue a task on the taskq to send the retry event.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If it fails we'll setup another timeout and try again later.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (taskq_dispatch(pppt_global.global_dispatch_taskq,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_dereg_task, tgt, KM_NOSLEEP) == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Dispatch failed, try again later */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) timeout(pppt_tgt_dereg_retry, tgt,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte drv_usectohz(TGT_DEREG_RETRY_SECONDS * 1000000));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_tgt_dereg_task(void *arg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *tgt = arg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_STMF_DEREG_RETRY);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetgt_sm_new_state(pppt_tgt_t *tgt, tgt_event_ctx_t *ctx,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_state_t new_state)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_local_port_t *lport = tgt->target_stmf_lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_change_status_t scs;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_state_change_info_t sci;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t stmfrc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_completion_status = STMF_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scs.st_additional_info = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Validate new state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(new_state != TS_UNDEFINED);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT3U(new_state, <, TS_MAX_STATE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte new_state = (new_state < TS_MAX_STATE) ?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte new_state : TS_UNDEFINED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap stmf_trace("pppt", "pppt_target_state_change: "
e617f2142235c62bb299718a60e6d2f79b6f472fpeter dunlap "tgt %p, %s(%d) --> %s(%d)\n",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void *) tgt, pppt_ts_name[tgt->target_state], tgt->target_state,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_ts_name[new_state], new_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte DTRACE_PROBE3(pppt__target__state__change,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_t *, tgt, tgt_event_ctx_t *, ctx,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_state_t, new_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_last_state = tgt->target_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tgt->target_state = new_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cv_signal(&tgt->target_cv);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&tgt->target_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (tgt->target_state) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_ONLINING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_ONLINE_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Let STMF know the how the online operation completed.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * STMF will respond with an acknowlege later
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_ONLINE_COMPLETE, lport, &scs);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_ONLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_STMF_ONLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_NEED_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sci.st_rflags = STMF_RFLAG_STAY_OFFLINED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sci.st_additional_info = "Offline for delete";
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_OFFLINE, lport, &sci);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_OFFLINING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Async callback generates completion event */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_offline(tgt);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_STMF_OFFLINE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_STMF_DEREG:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfrc = stmf_deregister_local_port(tgt->target_stmf_lport);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmfrc == STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_STMF_DEREG_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_tgt_sm_event(tgt, TE_STMF_DEREG_FAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING_STMF_DEREG_FAIL:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Retry dereg in 1 second */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) timeout(pppt_tgt_dereg_retry, tgt,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte drv_usectohz(TGT_DEREG_RETRY_SECONDS * 1000000));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case TS_DELETING:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}