450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * See the License for the specific language governing permissions
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * and limitations under the License.
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 * CDDL HEADER END
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
ef3b9e2fd29bbac9dc0e750d67355287620587a5Dan McDonald * Copyright 2013, Nexenta Systems, Inc. All rights reserved.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_tgt_register(stmf_ic_msg_t *reg_port);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_tgt_deregister(stmf_ic_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_session_destroy(stmf_ic_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_scsi_cmd(stmf_ic_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_data_xfer_done(stmf_ic_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void pppt_msg_handle_status(stmf_ic_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Ignore, all proxy data will be immediate for now */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Other message types are not allowed */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_msg_tx_status(stmf_ic_msg_t *orig_msg, stmf_status_t status)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If TX of status fails it should be treated the same as a loss of
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * connection. We expect the remote node to handle it.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte msg = stmf_ic_status_msg_alloc(status, orig_msg->icm_msg_type,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pppt_global.global_svc_state != PSS_ENABLED) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * For now we assume that the marshall/unmarshall code is responsible
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * for validating the message length and ensuring the resulting
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * request structure is self consistent. Make sure this
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * target doesn't already exist.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((result = pppt_tgt_lookup_locked(reg_port->icrp_port_id)) != NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = pppt_tgt_create(reg_port, &stmf_status);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte avl_add(&pppt_global.global_target_list, result);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pppt_global.global_svc_state != PSS_ENABLED) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Lookup target */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((tgt = pppt_tgt_lookup_locked(dereg_port->icdp_port_id)) == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte avl_remove(&pppt_global.global_target_list, tgt);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Wait for delete to complete */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_session_create_destroy_msg_t *sess_destroy;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Look for existing session for this ID
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ps = pppt_sess_lookup_locked(sess_destroy->icscd_session_id,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sess_destroy->icscd_tgt_devid, sess_destroy->icscd_rport);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Release the reference from the lookup */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Make sure another thread is not already closing the session */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Found matching open session, quiesce... */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Get a task context
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We must be very low on memory. Just free the message
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * and let the command timeout.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Session are created implicitly on the first use of an
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_sess = pppt_sess_lookup_create(scmd->icsc_tgt_devid,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Add task to our internal task set.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Release hold from pppt_sess_lookup_create() */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_LOG(CE_WARN, "Duplicate taskid from remote node 0x%llx",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Allocate STMF task context
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ptask->pt_stmf_task = stmf_task_alloc(lport, stmf_sess,
ef3b9e2fd29bbac9dc0e750d67355287620587a5Dan McDonald /* NOTE: pppt_task_done() will free ptask. */
ef3b9e2fd29bbac9dc0e750d67355287620587a5Dan McDonald /* task_port_private reference is a real reference. */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Set task->task_mgmt_function to TM_NONE for a normal SCSI task
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * or one of these values for a task management command:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_ABORT_TASK ***
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_ABORT_TASK_SET
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_CLEAR_ACA
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_CLEAR_TASK_SET
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_LUN_RESET
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_TARGET_WARM_RESET
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * TM_TARGET_COLD_RESET
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * *** Note that STMF does not currently support TM_ABORT_TASK so
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * port providers must implement this command on their own
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * (e.g. lookup the desired task and call stmf_abort).
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_mgmt_function = scmd->icsc_task_mgmt_function;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte task->task_max_nbufs = 1; /* Don't allow parallel xfers */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pbuf->pbuf_stmf_buf->db_data_size = scmd->icsc_immed_data_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pbuf->pbuf_stmf_buf->db_buf_size = scmd->icsc_immed_data_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_scsi_data_xfer_done_msg_t *data_xfer_done;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_task = pppt_task_lookup(data_xfer_done->icsx_task_msgid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* If we found one, complete the transfer */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_xfer_read_complete(pppt_task, data_xfer_done->icsx_status);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Don't care for now */