fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko/*
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko * Copyright 2012, Nexenta Systems, Inc. All rights reserved.
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * Copyright (c) 2013 by Delphix. All rights reserved.
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/file.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sunddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/modctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/scsi.h>
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan#include <sys/scsi/generic/persist.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/scsi_reset_notify.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/disp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/byteorder.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/atomic.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ethernet.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nvpair.h>
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv#include <sys/zone.h>
427fcaf873956aad428be801380a44e59d38b8b5tim szeto#include <sys/id_space.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/stmf.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/lpif.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/portif.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/stmf_ioctl.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/pppt_ic_if.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "stmf_impl.h"
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "lun_map.h"
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "stmf_state.h"
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "stmf_stats.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto/*
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto * Lock order:
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto * stmf_state_lock --> ilport_lock/iss_lockp --> ilu_task_lock
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto */
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint64_t stmf_session_counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint16_t stmf_rtpid_counter = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* start messages at 1 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic uint64_t stmf_proxy_msg_id = 1;
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte#define MSG_ID_TM_BIT 0x8000000000000000
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan#define ALIGNED_TO_8BYTE_BOUNDARY(i) (((i) + 7) & ~7)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov/*
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * When stmf_io_deadman_enabled is set to B_TRUE, we check that finishing up
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * I/O operations on an offlining LU doesn't take longer than stmf_io_deadman
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * seconds. If it does, we trigger a panic to inform the user of hung I/O
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * blocking us for too long.
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov */
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovboolean_t stmf_io_deadman_enabled = B_TRUE;
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovint stmf_io_deadman = 1000; /* seconds */
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenkostruct stmf_svc_clocks;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void **result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_open(dev_t *devp, int flag, int otype, cred_t *credp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_close(dev_t dev, int flag, int otype, cred_t *credp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cred_t *credp, int *rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_get_stmf_state(stmf_state_desc_t *std);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_set_stmf_state(stmf_state_desc_t *std);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void stmf_abort_task_offline(scsi_task_t *task, int offline_lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *info);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int stmf_set_alua_state(stmf_alua_state_desc_t *alua_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void stmf_get_alua_state(stmf_alua_state_desc_t *alua_state);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Fortestatic void stmf_task_audit(stmf_i_scsi_task_t *itask,
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte task_audit_event_t te, uint32_t cmd_or_iof, stmf_data_buf_t *dbuf);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstatic boolean_t stmf_base16_str_to_binary(char *c, int dplen, uint8_t *dp);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstatic char stmf_ctoi(char c);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_xfer_data_t *stmf_prepare_tpgs_data(uint8_t ilu_alua);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_svc_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_svc_fini();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_svc(void *arg);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovstatic void stmf_wait_ilu_tasks_finish(stmf_i_lu_t *ilu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_svc_queue(int cmd, void *obj, stmf_state_change_info_t *info);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenkostatic void stmf_svc_kill_obj_requests(void *obj);
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenkostatic void stmf_svc_timeout(struct stmf_svc_clocks *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_check_freetask();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_abort_target_reset(scsi_task_t *task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_lun_reset_poll(stmf_lu_t *lu, struct scsi_task *task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int target_reset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_target_reset_poll(struct scsi_task *task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_handle_lun_reset(scsi_task_t *task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_handle_target_reset(scsi_task_t *task);
91159e90831fc9243576f2ec1a483b3bb462bcf4John Fortevoid stmf_xd_to_dbuf(stmf_data_buf_t *dbuf, int set_rel_off);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint stmf_load_ppd_ioctl(stmf_ppioctl_data_t *ppi, uint64_t *ppi_token,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t *err_ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint stmf_delete_ppd_ioctl(stmf_ppioctl_data_t *ppi);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint stmf_get_ppd_ioctl(stmf_ppioctl_data_t *ppi, stmf_ppioctl_data_t *ppi_out,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t *err_ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_delete_ppd(stmf_pp_data_t *ppd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_delete_all_ppds();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_trace_clear();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_worker_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_worker_fini();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_worker_mgmt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_worker_task(void *arg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void stmf_task_lu_free(scsi_task_t *task, stmf_i_scsi_session_t *iss);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic stmf_status_t stmf_ic_lu_reg(stmf_ic_reg_dereg_lun_msg_t *msg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t type);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic stmf_status_t stmf_ic_lu_dereg(stmf_ic_reg_dereg_lun_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic stmf_status_t stmf_ic_rx_scsi_status(stmf_ic_scsi_status_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic stmf_status_t stmf_ic_rx_status(stmf_ic_status_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic stmf_status_t stmf_ic_rx_scsi_data(stmf_ic_scsi_data_msg_t *msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid stmf_task_lu_killall(stmf_lu_t *lu, scsi_task_t *tm_task, stmf_status_t s);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* pppt modhandle */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteddi_modhandle_t pppt_mod;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* pppt modload imported functions */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_reg_port_msg_alloc_func_t ic_reg_port_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_dereg_port_msg_alloc_func_t ic_dereg_port_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_reg_lun_msg_alloc_func_t ic_reg_lun_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_dereg_lun_msg_alloc_func_t ic_dereg_lun_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_lun_active_msg_alloc_func_t ic_lun_active_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_scsi_cmd_msg_alloc_func_t ic_scsi_cmd_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_scsi_data_xfer_done_msg_alloc_func_t ic_scsi_data_xfer_done_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_session_create_msg_alloc_func_t ic_session_reg_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_session_destroy_msg_alloc_func_t ic_session_dereg_msg_alloc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_tx_msg_func_t ic_tx_msg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_msg_free_func_t ic_msg_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_itl_task_start(stmf_i_scsi_task_t *itask);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_itl_lu_new_task(stmf_i_scsi_task_t *itask);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_itl_task_done(stmf_i_scsi_task_t *itask);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_lport_xfer_start(stmf_i_scsi_task_t *itask,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_data_buf_t *dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_lport_xfer_done(stmf_i_scsi_task_t *itask,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_data_buf_t *dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void stmf_update_kstat_lu_q(scsi_task_t *, void());
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void stmf_update_kstat_lport_q(scsi_task_t *, void());
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void stmf_update_kstat_lu_io(scsi_task_t *, stmf_data_buf_t *);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void stmf_update_kstat_lport_io(scsi_task_t *, stmf_data_buf_t *);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic int stmf_irport_compare(const void *void_irport1,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto const void *void_irport2);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *stmf_irport_create(scsi_devid_desc_t *rport_devid);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_irport_destroy(stmf_i_remote_port_t *irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *stmf_irport_register(
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_devid_desc_t *rport_devid);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *stmf_irport_lookup_locked(
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_devid_desc_t *rport_devid);
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void stmf_irport_deregister(stmf_i_remote_port_t *irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern struct mod_ops mod_driverops;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* =====[ Tunables ]===== */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Internal tracing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_trace_on = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_trace_buf_size = (1 * 1024 * 1024);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The reason default task timeout is 75 is because we want the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host to timeout 1st and mostly host timeout is 60 seconds.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_default_task_timeout = 75;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Setting this to one means, you are responsible for config load and keeping
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * things in sync with persistent database.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_allow_modunload = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_max_nworkers = 256;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_min_nworkers = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile int stmf_worker_scale_down_delay = 20;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* === [ Debugging and fault injection ] === */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
9c68c0524222ca5eac2fb0835154553c1cdaa96cJosef 'Jeff' Sipekvolatile uint32_t stmf_drop_task_counter = 0;
9c68c0524222ca5eac2fb0835154553c1cdaa96cJosef 'Jeff' Sipekvolatile uint32_t stmf_drop_buf_counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_state_t stmf_state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic stmf_lu_t *dlun0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint8_t stmf_first_zero[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 0xff };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint8_t stmf_first_one[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { 0xff, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t trace_buf_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int trace_buf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int trace_buf_curndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecaddr_t stmf_trace_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic enum {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_WORKERS_DISABLED = 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_WORKERS_ENABLING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_WORKERS_ENABLED
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} stmf_workers_state = STMF_WORKERS_DISABLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_i_max_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_i_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_nworkers_cur; /* # of workers currently running */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_nworkers_needed; /* # of workers need to be running */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_worker_sel_counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t stmf_cur_ntasks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic clock_t stmf_wm_last = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is equal to stmf_nworkers_cur while we are increasing # workers and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmf_nworkers_needed while we are decreasing the worker count.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_nworkers_accepting_cmds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic stmf_worker_t *stmf_workers = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic clock_t stmf_worker_mgmt_delay = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic clock_t stmf_worker_scale_down_timer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int stmf_worker_scale_down_qd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct cb_ops stmf_cb_ops = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_open, /* open */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_close, /* close */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* strategy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* print */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* dump */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* read */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* write */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ioctl, /* ioctl */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* devmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* mmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* segmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nochpoll, /* chpoll */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_prop_op, /* cb_prop_op */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* streamtab */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte D_NEW | D_MP, /* cb_flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CB_REV, /* rev */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* aread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev /* awrite */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct dev_ops stmf_ops = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DEVO_REV,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_getinfo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nulldev, /* identify */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nulldev, /* probe */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_attach,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_detach,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodev, /* reset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &stmf_cb_ops,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, /* bus_ops */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL /* power */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto#define STMF_NAME "COMSTAR STMF"
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto#define STMF_MODULE_NAME "stmf"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct modldrv modldrv = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &mod_driverops,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_NAME,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &stmf_ops
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct modlinkage modlinkage = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MODREV_1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &modldrv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_init(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = mod_install(&modlinkage);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace_buf = kmem_zalloc(stmf_trace_buf_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_size = stmf_trace_buf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_curndx = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&trace_buf_lock, NULL, MUTEX_DRIVER, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmf_state, sizeof (stmf_state_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* STMF service is off by default */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_service_running = 0;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli /* default lu/lport states are online */
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_state.stmf_default_lu_state = STMF_STATE_ONLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_state.stmf_default_lport_state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&stmf_state.stmf_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&stmf_state.stmf_cv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_session_counter = (uint64_t)ddi_get_lbolt();
427fcaf873956aad428be801380a44e59d38b8b5tim szeto avl_create(&stmf_state.stmf_irportlist,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_irport_compare, sizeof (stmf_i_remote_port_t),
427fcaf873956aad428be801380a44e59d38b8b5tim szeto offsetof(stmf_i_remote_port_t, irport_ln));
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_state.stmf_ilport_inst_space =
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_space_create("lport-instances", 0, MAX_ILPORT);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_state.stmf_irport_inst_space =
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_space_create("rport-instances", 0, MAX_IRPORT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_dlun_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_fini(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_remote_port_t *irport;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto void *avl_dest_cookie = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_service_running)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!stmf_allow_modunload) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_state.stmf_config_state != STMF_CONFIG_NONE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_nlps || stmf_state.stmf_npps) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_dlun_fini() != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_worker_fini() != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_dlun_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_svc_fini() != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_dlun_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = mod_remove(&modlinkage);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_dlun_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_clear_config();
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto while ((irport = avl_destroy_nodes(&stmf_state.stmf_irportlist,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto &avl_dest_cookie)) != NULL)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_irport_destroy(irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto avl_destroy(&stmf_state.stmf_irportlist);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_space_destroy(stmf_state.stmf_ilport_inst_space);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_space_destroy(stmf_state.stmf_irport_inst_space);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stmf_trace_buf, stmf_trace_buf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_info(struct modinfo *modinfop)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (mod_info(&modlinkage, modinfop));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DDI_INFO_DEVT2DEVINFO:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *result = stmf_state.stmf_dip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DDI_INFO_DEVT2INSTANCE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *result =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void *)(uintptr_t)ddi_get_instance(stmf_state.stmf_dip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DDI_ATTACH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_dip = dip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_create_minor_node(dip, "admin", S_IFCHR, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_NT_STMF, 0) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_report_dev(dip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case DDI_DETACH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_remove_minor_node(dip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DDI_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_open(dev_t *devp, int flag, int otype, cred_t *credp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_exclusive_open) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & FEXCL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_opened) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_exclusive_open = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_opened = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_close(dev_t dev, int flag, int otype, cred_t *credp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_opened = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_exclusive_open &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_state.stmf_config_state != STMF_CONFIG_INIT_DONE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_config_state = STMF_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_delete_all_ppds();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_clear_config();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_exclusive_open = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_copyin_iocdata(intptr_t data, int mode, stmf_iocdata_t **iocd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void **ibuf, void **obuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ibuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *obuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *iocd = kmem_zalloc(sizeof (stmf_iocdata_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ddi_copyin((void *)data, *iocd, sizeof (stmf_iocdata_t), mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*iocd)->stmf_version != STMF_VERSION_1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto copyin_iocdata_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*iocd)->stmf_ibuf_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ibuf = kmem_zalloc((*iocd)->stmf_ibuf_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ddi_copyin((void *)((unsigned long)(*iocd)->stmf_ibuf),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ibuf, (*iocd)->stmf_ibuf_size, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*iocd)->stmf_obuf_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *obuf = kmem_zalloc((*iocd)->stmf_obuf_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecopyin_iocdata_done:;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*obuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(*obuf, (*iocd)->stmf_obuf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *obuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ibuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(*ibuf, (*iocd)->stmf_ibuf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ibuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(*iocd, sizeof (stmf_iocdata_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_copyout_iocdata(intptr_t data, int mode, stmf_iocdata_t *iocd, void *obuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iocd->stmf_obuf_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ddi_copyout(obuf, (void *)(unsigned long)iocd->stmf_obuf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_size, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ddi_copyout(iocd, (void *)data, sizeof (stmf_iocdata_t), mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cred_t *credp, int *rval)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t *iocd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *ibuf = NULL, *obuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_lu_t *luid_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_target_port_t *lportid_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_scsi_session_t *iss_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sioc_lu_props_t *lup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sioc_target_port_props_t *lportp;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_ppioctl_data_t *ppi, *ppi_out = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t *ppi_token = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *p_id, *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t *std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ctl_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_change_info_t ssi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_group_op_data_t *grp_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_group_name_t *grpname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_op_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_type_t idtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_list_t *id_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *view_entry;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props_t *stmf_set_props;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t veid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cmd & 0xff000000) != STMF_IOCTL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOTTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (drv_priv(credp) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EPERM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_copyin_iocdata(data, mode, &iocd, &ibuf, &obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_LU_LIST:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* retrieves both registered/unregistered */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_list = &stmf_state.stmf_luid_list;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n = min(id_list->id_count,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_obuf_size)/sizeof (slist_lu_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_max_nentries = id_list->id_count;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luid_list = (slist_lu_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry = id_list->idl_head;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < n; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id_entry->id_data, luid_list[i].lu_guid, 16);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry = id_entry->id_next;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n = iocd->stmf_obuf_size/sizeof (slist_lu_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (ilu = stmf_state.stmf_ilulist; ilu; ilu = ilu->ilu_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id = (uint8_t *)ilu->ilu_lu->lu_id;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmf_lookup_id(id_list, 16, id + 4) == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_max_nentries++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (i < n) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id + 4, luid_list[i].lu_guid,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (slist_lu_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto i++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_nentries = i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_IOCTL_REG_LU_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = stmf_state.stmf_nlus;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(stmf_state.stmf_nlus,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (iocd->stmf_obuf_size)/sizeof (slist_lu_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = stmf_state.stmf_ilulist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid_list = (slist_lu_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilu->ilu_lu->lu_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(id + 4, luid_list[i].lu_guid, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_IOCTL_VE_LU_LIST:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_list = &stmf_state.stmf_luid_list;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n = min(id_list->id_count,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_obuf_size)/sizeof (slist_lu_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_max_nentries = id_list->id_count;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_nentries = n;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luid_list = (slist_lu_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry = id_list->idl_head;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < n; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id_entry->id_data, luid_list[i].lu_guid, 16);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry = id_entry->id_next;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_TARGET_PORT_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = stmf_state.stmf_nlports;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(stmf_state.stmf_nlports,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (iocd->stmf_obuf_size)/sizeof (slist_target_port_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_state.stmf_ilportlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportid_list = (slist_target_port_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilport->ilport_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(id, lportid_list[i].target, id[3] + 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_SESSION_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_id = (uint8_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((p_id == NULL) || (iocd->stmf_ibuf_size < 4) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < (p_id[3] + 4))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport; ilport =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilport->ilport_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((p_id[3] == id[3]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(p_id + 4, id + 4, id[3]) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = ilport->ilport_nsessions;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(ilport->ilport_nsessions,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_obuf_size)/sizeof (slist_scsi_session_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = ilport->ilport_ss_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss_list = (slist_scsi_session_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)iss->iss_ss->ss_rport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(id, iss_list[i].initiator, id[3] + 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss_list[i].creation_time = (uint32_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_creation_time;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_ss->ss_rport_alias) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(iss_list[i].alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_ss->ss_rport_alias, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss_list[i].alias[255] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss_list[i].alias[0] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = iss->iss_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_LU_PROPERTIES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_id = (uint8_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((iocd->stmf_ibuf_size < 16) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_obuf_size < sizeof (sioc_lu_props_t)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (p_id[0] == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu; ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(p_id, ilu->ilu_lu->lu_id->ident, 16) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup = (sioc_lu_props_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ilu->ilu_lu->lu_id->ident, lup->lu_guid, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup->lu_state = ilu->ilu_state & 0x0f;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup->lu_present = 1; /* XXX */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(lup->lu_provider_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_lu->lu_lp->lp_name, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup->lu_provider_name[254] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_lu->lu_alias) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(lup->lu_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_lu->lu_alias, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup->lu_alias[255] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lup->lu_alias[0] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_TARGET_PORT_PROPERTIES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_id = (uint8_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((p_id == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < (p_id[3] + 4)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_obuf_size <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (sioc_target_port_props_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilport->ilport_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((p_id[3] == id[3]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(p_id+4, id+4, id[3]) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp = (sioc_target_port_props_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ilport->ilport_lport->lport_id, lportp->tgt_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport->lport_id->ident_length + 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp->tgt_state = ilport->ilport_state & 0x0f;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp->tgt_present = 1; /* XXX */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(lportp->tgt_provider_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport->lport_pp->pp_name, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp->tgt_provider_name[254] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_lport->lport_alias) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(lportp->tgt_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport->lport_alias, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp->tgt_alias[255] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lportp->tgt_alias[0] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_SET_STMF_STATE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_state_desc_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_set_stmf_state((stmf_state_desc_t *)ibuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_STMF_STATE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((obuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_obuf_size < sizeof (stmf_state_desc_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_get_stmf_state((stmf_state_desc_t *)obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_IOCTL_SET_ALUA_STATE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ibuf == NULL) ||
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_alua_state_desc_t))) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = EINVAL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = stmf_set_alua_state((stmf_alua_state_desc_t *)ibuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_IOCTL_GET_ALUA_STATE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((obuf == NULL) ||
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (iocd->stmf_obuf_size < sizeof (stmf_alua_state_desc_t))) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = EINVAL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_get_alua_state((stmf_alua_state_desc_t *)obuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_SET_LU_STATE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_rflags = STMF_RFLAG_USER_REQUEST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_additional_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte std = (stmf_state_desc_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_state_desc_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_id = std->ident;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EBUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu; ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(p_id, ilu->ilu_lu->lu_id->ident, 16) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = (std->state == STMF_STATE_ONLINE) ? STMF_CMD_LU_ONLINE :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_CMD_LU_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_ret = stmf_ctl(cmd, (void *)ilu->ilu_lu, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctl_ret == STMF_ALREADY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan else if (ctl_ret == STMF_BUSY)
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = EBUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ctl_ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_IOCTL_SET_STMF_PROPS:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((ibuf == NULL) ||
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (iocd->stmf_ibuf_size < sizeof (stmf_set_props_t))) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = EINVAL;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props = (stmf_set_props_t *)ibuf;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli mutex_enter(&stmf_state.stmf_lock);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((stmf_set_props->default_lu_state_value ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_OFFLINE) ||
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (stmf_set_props->default_lu_state_value ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE)) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_state.stmf_default_lu_state =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_lu_state_value;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((stmf_set_props->default_target_state_value ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_OFFLINE) ||
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (stmf_set_props->default_target_state_value ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE)) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_state.stmf_default_lport_state =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_target_state_value;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli mutex_exit(&stmf_state.stmf_lock);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_SET_TARGET_PORT_STATE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_rflags = STMF_RFLAG_USER_REQUEST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_additional_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte std = (stmf_state_desc_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_state_desc_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_id = std->ident;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EBUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilport->ilport_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((id[3] == p_id[3]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(id+4, p_id+4, id[3]) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = (std->state == STMF_STATE_ONLINE) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_CMD_LPORT_ONLINE : STMF_CMD_LPORT_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_ret = stmf_ctl(cmd, (void *)ilport->ilport_lport, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctl_ret == STMF_ALREADY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan else if (ctl_ret == STMF_BUSY)
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = EBUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ctl_ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_ADD_HG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_ADD_TG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_ADD_TG_ENTRY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_TARGET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry = (stmf_group_op_data_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_group_op_data_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp_entry->group.name[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* not allowed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_group_member(grp_entry->group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->group.name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->ident + 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->ident[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_REMOVE_HG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_HOST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_REMOVE_TG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_REMOVE_TG_ENTRY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_TARGET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry = (stmf_group_op_data_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_group_op_data_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp_entry->group.name[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* not allowed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_remove_group_member(grp_entry->group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->group.name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->ident + 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry->ident[3],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_CREATE_HOST_GROUP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_HOST_GROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_CREATE_TARGET_GROUP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname = (stmf_group_name_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_CREATE_TARGET_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_TARGET_GROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_group_name_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grpname->name[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* not allowed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_group(grpname->name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname->name_size, idtype, &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_REMOVE_HOST_GROUP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_HOST_GROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_REMOVE_TARGET_GROUP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname = (stmf_group_name_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_REMOVE_TARGET_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idtype = STMF_ID_TYPE_TARGET_GROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_group_name_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grpname->name[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* not allowed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_remove_group(grpname->name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname->name_size, idtype, &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCTL_VALIDATE_VIEW:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_ADD_VIEW_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_op_entry_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_view_op_entry_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve->ve_lu_number_valid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lu_nbr[2] = 0xFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_all_hosts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_host_group.name[0] = '*';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_host_group.name_size = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_all_targets) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_target_group.name[0] = '*';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_target_group.name_size = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_ndx_valid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veid = ve->ve_ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veid = 0xffffffff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (cmd == STMF_IOCTL_ADD_VIEW_ENTRY) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = stmf_add_ve(ve->ve_host_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_host_group.name_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_target_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_target_group.name_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_guid,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto &veid,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_lu_nbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto &iocd->stmf_error);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else { /* STMF_IOCTL_VALIDATE_VIEW */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = stmf_validate_lun_ve(ve->ve_host_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_host_group.name_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_target_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_target_group.name_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve->ve_lu_nbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto &iocd->stmf_error);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!ve->ve_ndx_valid || !ve->ve_lu_number_valid) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_size >= sizeof (stmf_view_op_entry_t)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_op_entry_t *ve_ret =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_view_op_entry_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve->ve_ndx_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_ret->ve_ndx = veid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_ret->ve_ndx_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve->ve_lu_number_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_ret->ve_lu_number_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ve->ve_lu_nbr, ve_ret->ve_lu_nbr, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_REMOVE_VIEW_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_op_entry_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_view_op_entry_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve->ve_ndx_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_remove_ve_by_id(ve->ve_guid, ve->ve_ndx,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_HG_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_list = &stmf_state.stmf_hg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_TG_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_GET_TG_LIST)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_list = &stmf_state.stmf_tg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = id_list->id_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(id_list->id_count,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_obuf_size)/sizeof (stmf_group_name_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry = id_list->idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname = (stmf_group_name_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (id_entry->id_data[0] == '*') {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iocd->stmf_obuf_nentries > 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_nentries--;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry = id_entry->id_next;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto grpname->name_size = id_entry->id_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id_entry->id_data, grpname->name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto grpname++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry = id_entry->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_HG_ENTRIES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_list = &stmf_state.stmf_hg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHROUGH */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_TG_ENTRIES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname = (stmf_group_name_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ibuf == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_group_name_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == STMF_IOCTL_GET_TG_ENTRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_list = &stmf_state.stmf_tg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry = stmf_lookup_id(id_list, grpname->name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname->name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!id_entry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ge_ident_t *grp_entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_list = (stmf_id_list_t *)id_entry->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_max_nentries = id_list->id_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min(id_list->id_count,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_size/sizeof (stmf_ge_ident_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry = id_list->idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_entry = (stmf_ge_ident_t *)obuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < n; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id_entry->id_data, grp_entry->ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto grp_entry->ident_size = id_entry->id_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_entry = id_entry->id_next;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto grp_entry++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_VE_LIST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = iocd->stmf_obuf_size/sizeof (stmf_view_op_entry_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_op_entry_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (id_entry = stmf_state.stmf_luid_list.idl_head;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry; id_entry = id_entry->id_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (view_entry = (stmf_view_entry_t *)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry->id_impl_specific; view_entry;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry = view_entry->ve_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_max_nentries++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iocd->stmf_obuf_nentries >= n)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_ndx_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_ndx = view_entry->ve_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lu_number_valid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(view_entry->ve_lun, ve->ve_lu_nbr, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(view_entry->ve_luid->id_data, ve->ve_guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte view_entry->ve_luid->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (view_entry->ve_hg->id_data[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_all_hosts = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(view_entry->ve_hg->id_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_host_group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte view_entry->ve_hg->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_host_group.name_size =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_hg->id_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (view_entry->ve_tg->id_data[0] == '*') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_all_targets = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(view_entry->ve_tg->id_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_target_group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte view_entry->ve_tg->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_target_group.name_size =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_tg->id_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_obuf_nentries++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_IOCTL_LU_VE_LIST:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p_id = (uint8_t *)ibuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((iocd->stmf_ibuf_size != 16) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_obuf_size < sizeof (stmf_view_op_entry_t))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EINVAL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n = iocd->stmf_obuf_size/sizeof (stmf_view_op_entry_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve = (stmf_view_op_entry_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (id_entry = stmf_state.stmf_luid_list.idl_head;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry; id_entry = id_entry->id_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (bcmp(id_entry->id_data, p_id, 16) != 0)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (view_entry = (stmf_view_entry_t *)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id_entry->id_impl_specific; view_entry;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry = view_entry->ve_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_max_nentries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iocd->stmf_obuf_nentries >= n)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_ndx_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_ndx = view_entry->ve_id;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_lu_number_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(view_entry->ve_lun, ve->ve_lu_nbr, 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(view_entry->ve_luid->id_data, ve->ve_guid,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_luid->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (view_entry->ve_hg->id_data[0] == '*') {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_all_hosts = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(view_entry->ve_hg->id_data,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_host_group.name,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_hg->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_host_group.name_size =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_hg->id_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (view_entry->ve_tg->id_data[0] == '*') {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_all_targets = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(view_entry->ve_tg->id_data,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_target_group.name,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_tg->id_data_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve->ve_target_group.name_size =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto view_entry->ve_tg->id_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ve++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_obuf_nentries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_LOAD_PP_DATA:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi = (stmf_ppioctl_data_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppi == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_ppioctl_data_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* returned token */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_token = (uint64_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ppi_token == NULL) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_obuf_size < sizeof (uint64_t))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EINVAL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmf_load_ppd_ioctl(ppi, ppi_token, &iocd->stmf_error);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_IOCTL_GET_PP_DATA:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EACCES;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi = (stmf_ppioctl_data_t *)ibuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi == NULL ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_ibuf_size < sizeof (stmf_ppioctl_data_t))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EINVAL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out = (stmf_ppioctl_data_t *)obuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ppi_out == NULL) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (iocd->stmf_obuf_size < sizeof (stmf_ppioctl_data_t))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EINVAL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmf_get_ppd_ioctl(ppi, ppi_out, &iocd->stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_CLEAR_PP_DATA:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_NONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EACCES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iocd->stmf_error = STMF_IOCERR_UPDATE_NEED_CFG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi = (stmf_ppioctl_data_t *)ibuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppi == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (iocd->stmf_ibuf_size < sizeof (stmf_ppioctl_data_t))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_delete_ppd_ioctl(ppi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_CLEAR_TRACE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace_clear();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_ADD_TRACE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iocd->stmf_ibuf_size && ibuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint8_t *)ibuf)[iocd->stmf_ibuf_size - 1] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace("\nstradm", "%s\n", ibuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_TRACE_POSITION:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (obuf && (iocd->stmf_obuf_size > 3)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *((int *)obuf) = trace_buf_curndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCTL_GET_TRACE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((iocd->stmf_obuf_size == 0) || (iocd->stmf_ibuf_size < 4)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = *((int *)ibuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i > trace_buf_size) || ((i + iocd->stmf_obuf_size) >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_size)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(stmf_trace_buf + i, obuf, iocd->stmf_obuf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = ENOTTY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_copyout_iocdata(data, mode, iocd, obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (iocd->stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_copyout_iocdata(data, mode, iocd, obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (obuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(obuf, iocd->stmf_obuf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte obuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ibuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ibuf, iocd->stmf_ibuf_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ibuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iocd, sizeof (stmf_iocdata_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_service_state()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int online = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offline = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int onlining = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offlining = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state == STMF_STATE_OFFLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilport->ilport_state == STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte online++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilport->ilport_state == STMF_STATE_ONLINING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte onlining++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilport->ilport_state == STMF_STATE_OFFLINING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offlining++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_state == STMF_STATE_OFFLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilu->ilu_state == STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte online++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilu->ilu_state == STMF_STATE_ONLINING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte onlining++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (ilu->ilu_state == STMF_STATE_OFFLINING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offlining++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_service_running) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (onlining)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATE_ONLINING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATE_ONLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (offlining) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATE_OFFLINING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATE_OFFLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_set_stmf_state(stmf_state_desc_t *std)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_change_info_t ssi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int svc_state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_rflags = STMF_RFLAG_USER_REQUEST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssi.st_additional_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stmf_state.stmf_exclusive_open) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((std->state != STMF_STATE_ONLINE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (std->state != STMF_STATE_OFFLINE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc_state = stmf_get_service_state();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((svc_state == STMF_STATE_OFFLINING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (svc_state == STMF_STATE_ONLINING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svc_state == STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (std->config_state == STMF_CONFIG_INIT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (std->state != STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_config_state = STMF_CONFIG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_delete_all_ppds();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_clear_config();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
5dfbf9be7aa351a2746b8259a906f60caf81fdcfSue Gleeson if ((stmf_state.stmf_config_state == STMF_CONFIG_INIT) ||
5dfbf9be7aa351a2746b8259a906f60caf81fdcfSue Gleeson (stmf_state.stmf_config_state == STMF_CONFIG_NONE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (std->config_state != STMF_CONFIG_INIT_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_config_state = STMF_CONFIG_INIT_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (std->state == STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_INIT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_service_running = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_default_lport_state !=
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_ONLINE,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ilport->ilport_lport, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = ilu->ilu_next) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_default_lu_state !=
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LU_ONLINE, ilu->ilu_lu, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* svc_state is STMF_STATE_ONLINE here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((std->state != STMF_STATE_OFFLINE) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (std->config_state == STMF_CONFIG_INIT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_service_running = 0;
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LPORT_OFFLINE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_state != STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LU_OFFLINE, ilu->ilu_lu, &ssi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_inventory_locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_stmf_state(stmf_state_desc_t *std)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte std->state = stmf_get_service_state();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte std->config_state = stmf_state.stmf_config_state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * handles registration message from pppt for a logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_lu_reg(stmf_ic_reg_dereg_lun_msg_t *msg, uint32_t type)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_provider_t *ilp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_lu_provider_t *lp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilp = stmf_state.stmf_ilplist; ilp != NULL; ilp = ilp->ilp_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (strcmp(msg->icrl_lu_provider_name,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilp->ilp_lp->lp_name) == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lp = ilp->ilp_lp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lp->lp_proxy_msg(msg->icrl_lun_id, msg->icrl_cb_arg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte msg->icrl_cb_arg_len, type);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * handles de-registration message from pppt for a logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_lu_dereg(stmf_ic_reg_dereg_lun_msg_t *msg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_provider_t *ilp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_lu_provider_t *lp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilp = stmf_state.stmf_ilplist; ilp != NULL; ilp = ilp->ilp_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (strcmp(msg->icrl_lu_provider_name,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilp->ilp_lp->lp_name) == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lp = ilp->ilp_lp;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lp->lp_proxy_msg(msg->icrl_lun_id, NULL, 0,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_MSG_LU_DEREGISTER);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * helper function to find a task that matches a task_msgid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortescsi_task_t *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortefind_task_from_msgid(uint8_t *lu_id, stmf_ic_msgid_t task_msgid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_t *ilu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_scsi_task_t *itask;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL; ilu = ilu->ilu_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (bcmp(lu_id, ilu->ilu_lu->lu_id->ident, 16) == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilu == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&ilu->ilu_task_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (itask = ilu->ilu_tasks; itask != NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask = itask->itask_lu_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (itask->itask_flags & (ITASK_IN_FREE_LIST |
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ITASK_BEING_ABORTED)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (itask->itask_proxy_msg_id == task_msgid) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&ilu->ilu_task_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (itask != NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (itask->itask_task);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* task not found. Likely already aborted. */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * message received from pppt/ic
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_msg_rx(stmf_ic_msg_t *msg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_state != 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "stmf alua state is disabled");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_msg_free(msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (msg->icm_msg_type) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_REGISTER_LUN:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_lu_reg(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_reg_dereg_lun_msg_t *)msg->icm_msg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_MSG_LU_REGISTER);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_LUN_ACTIVE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_lu_reg(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_reg_dereg_lun_msg_t *)msg->icm_msg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_MSG_LU_ACTIVE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_DEREGISTER_LUN:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_lu_dereg(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_reg_dereg_lun_msg_t *)msg->icm_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_SCSI_DATA:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_rx_scsi_data(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_scsi_data_msg_t *)msg->icm_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_SCSI_STATUS:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_rx_scsi_status(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_scsi_status_msg_t *)msg->icm_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ICM_STATUS:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_ic_rx_status(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_status_msg_t *)msg->icm_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "unknown message received %d",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte msg->icm_msg_type);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_msg_free(msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_msg_free(msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_rx_status(stmf_ic_status_msg_t *msg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_local_port_t *ilport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (msg->ics_msg_type != STMF_ICM_REGISTER_PROXY_PORT) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* for now, ignore other message status */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (msg->ics_status != STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = ilport->ilport_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (msg->ics_msgid == ilport->ilport_reg_msgid) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_proxy_registered = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * handles scsi status message from pppt
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_rx_scsi_status(stmf_ic_scsi_status_msg_t *msg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scsi_task_t *task;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte /* is this a task management command */
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte if (msg->icss_task_msgid & MSG_ID_TM_BIT) {
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte return (STMF_SUCCESS);
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte }
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task = find_task_from_msgid(msg->icss_lun_id, msg->icss_task_msgid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (task == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_scsi_status = msg->icss_status;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_sense_data = msg->icss_sense;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_sense_length = msg->icss_sense_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_send_scsi_status(task, STMF_IOF_LU_DONE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * handles scsi data message from pppt
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_ic_rx_scsi_data(stmf_ic_scsi_data_msg_t *msg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_scsi_task_t *itask;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scsi_task_t *task;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_xfer_data_t *xd = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_data_buf_t *dbuf;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t sz, minsz, xd_sz, asz;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte /* is this a task management command */
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte if (msg->icsd_task_msgid & MSG_ID_TM_BIT) {
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte return (STMF_SUCCESS);
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte }
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task = find_task_from_msgid(msg->icsd_lun_id, msg->icsd_task_msgid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (task == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_xfer_done_msg = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte static uint64_t data_msg_id;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t ic_ret = STMF_FAILURE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte data_msg_id = stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * send xfer done status to pppt
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * for now, set the session id to 0 as we cannot
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * ascertain it since we cannot find the task
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_xfer_done_msg = ic_scsi_data_xfer_done_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte msg->icsd_task_msgid, 0, STMF_FAILURE, data_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_xfer_done_msg) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_xfer_done_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret != STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "unable to xmit proxy msg");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte dbuf = itask->itask_proxy_dbuf;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte task->task_cmd_xfer_length += msg->icsd_data_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (task->task_additional_flags &
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte TASK_AF_NO_EXPECTED_XFER_LENGTH) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_expected_xfer_length =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_cmd_xfer_length;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sz = min(task->task_expected_xfer_length,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_cmd_xfer_length);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd_sz = msg->icsd_data_len;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte asz = xd_sz + sizeof (*xd) - 4;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd = (stmf_xfer_data_t *)kmem_zalloc(asz, KM_NOSLEEP);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (xd == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_ALLOC_FAILURE, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd->alloc_size = asz;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd->size_left = xd_sz;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(msg->icsd_data, xd->buf, xd_sz);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sz = min(sz, xd->size_left);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd->size_left = sz;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte minsz = min(512, sz);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (dbuf == NULL)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte dbuf = stmf_alloc_dbuf(task, sz, &minsz, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (dbuf == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte kmem_free(xd, xd->alloc_size);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_ALLOC_FAILURE, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte dbuf->db_lu_private = xd;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte dbuf->db_relative_offset = task->task_nbytes_transferred;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte stmf_xd_to_dbuf(dbuf, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_proxy_scsi_cmd(scsi_task_t *task, stmf_data_buf_t *dbuf)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_scsi_task_t *itask =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_local_port_t *ilport =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_i_local_port_t *)task->task_lport->lport_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_cmd_msg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t ret = STMF_FAILURE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte if (stmf_state.stmf_alua_state != 1) {
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte cmn_err(CE_WARN, "stmf alua state is disabled");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte if (ilport->ilport_proxy_registered == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask->itask_proxy_msg_id = stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask->itask_proxy_dbuf = dbuf;
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte /*
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte * stmf will now take over the task handling for this task
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte * but it still needs to be treated differently from other
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte * default handled tasks, hence the ITASK_PROXY_TASK.
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte * If this is a task management function, we're really just
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte * duping the command to the peer. Set the TM bit so that
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte * we can recognize this on return since we won't be completing
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte * the proxied task in that case.
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte */
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte if (task->task_mgmt_function) {
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte itask->itask_proxy_msg_id |= MSG_ID_TM_BIT;
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte } else {
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte uint32_t new, old;
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte do {
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte new = old = itask->itask_flags;
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte if (new & ITASK_BEING_ABORTED)
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte return (STMF_FAILURE);
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte new |= ITASK_DEFAULT_HANDLING | ITASK_PROXY_TASK;
fdff21492ef0ebf614bb66c3e9d90526a4f0c9c0John Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (dbuf) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_cmd_msg = ic_scsi_cmd_msg_alloc(itask->itask_proxy_msg_id,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task, dbuf->db_data_size, dbuf->db_sglist[0].seg_addr,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask->itask_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_cmd_msg = ic_scsi_cmd_msg_alloc(itask->itask_proxy_msg_id,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task, 0, NULL, itask->itask_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_cmd_msg) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_cmd_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_modload()
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int error;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pppt_mod == NULL && ((pppt_mod =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modopen("drv/pppt", KRTLD_MODE_FIRST, &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "Unable to load pppt");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_port_msg_alloc == NULL && ((ic_reg_port_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_reg_port_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_reg_port_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_reg_port_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_dereg_port_msg_alloc == NULL && ((ic_dereg_port_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_dereg_port_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_dereg_port_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_dereg_port_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_lun_msg_alloc == NULL && ((ic_reg_lun_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_reg_lun_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_reg_lun_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_reg_lun_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_lun_active_msg_alloc == NULL && ((ic_lun_active_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_lun_active_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_lun_active_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_lun_active_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_dereg_lun_msg_alloc == NULL && ((ic_dereg_lun_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_dereg_lun_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_dereg_lun_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_dereg_lun_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_scsi_cmd_msg_alloc == NULL && ((ic_scsi_cmd_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_scsi_cmd_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_scsi_cmd_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol - stmf_ic_scsi_cmd_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_scsi_data_xfer_done_msg_alloc == NULL &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ((ic_scsi_data_xfer_done_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_scsi_data_xfer_done_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_scsi_data_xfer_done_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol -"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "stmf_ic_scsi_data_xfer_done_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_session_reg_msg_alloc == NULL &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ((ic_session_reg_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_session_create_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_session_create_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol -"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "stmf_ic_session_create_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_session_dereg_msg_alloc == NULL &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ((ic_session_dereg_msg_alloc =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_session_destroy_msg_alloc_func_t)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ddi_modsym(pppt_mod, "stmf_ic_session_destroy_msg_alloc",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Unable to find symbol -"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "stmf_ic_session_destroy_msg_alloc");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_tx_msg == NULL && ((ic_tx_msg =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_tx_msg_func_t)ddi_modsym(pppt_mod, "stmf_ic_tx_msg",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "Unable to find symbol - stmf_ic_tx_msg");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_msg_free == NULL && ((ic_msg_free =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_ic_msg_free_func_t)ddi_modsym(pppt_mod, "stmf_ic_msg_free",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &error)) == NULL)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "Unable to find symbol - stmf_ic_msg_free");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_FAILURE);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_get_alua_state(stmf_alua_state_desc_t *alua_state)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte alua_state->alua_node = stmf_state.stmf_alua_node;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte alua_state->alua_state = stmf_state.stmf_alua_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_set_alua_state(stmf_alua_state_desc_t *alua_state)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_local_port_t *ilport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_t *ilu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_lu_t *lu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_reg_lun, *ic_reg_port;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_local_port_t *lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (alua_state->alua_state > 1 || alua_state->alua_node > 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (EINVAL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (alua_state->alua_state == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pppt_modload() == STMF_FAILURE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = EIO;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte goto err;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (alua_state->alua_node != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* reset existing rtpids to new base */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_rtpid_counter = 255;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_state.stmf_alua_node = alua_state->alua_node;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_state.stmf_alua_state = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* register existing local ports with ppp */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = ilport->ilport_next) {
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte /* skip standby ports and non-alua participants */
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte if (ilport->ilport_standby == 1 ||
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_alua == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (alua_state->alua_node != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_rtpid =
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_16_nv(&stmf_rtpid_counter);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport = ilport->ilport_lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_reg_port = ic_reg_port_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_id, ilport->ilport_rtpid,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte 0, NULL, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_port) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_reg_port);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_reg_msgid =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "error on port registration "
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "port - %s",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_kstat_tgt_name);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* register existing logical units */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu = ilu->ilu_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilu->ilu_access != STMF_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* register with proxy module */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu = ilu->ilu_lu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lu->lu_lp && lu->lu_lp->lp_lpif_rev == LPIF_REV_2 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_alua_support) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_alua = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* allocate the register message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_reg_lun = ic_reg_lun_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_id->ident, lu->lu_lp->lp_name,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_proxy_reg_arg_len,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (uint8_t *)lu->lu_proxy_reg_arg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* send the message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_lun) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_reg_lun);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_state.stmf_alua_state = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteerr:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *bp; /* back pointer from internal struct to main struct */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int alloc_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} __istmf_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte __istmf_t *fp; /* Framework private */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *cp; /* Caller private */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *ss; /* struct specific */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} __stmf_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int shared;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fw_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} stmf_sizes[] = { { 0, 0 },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_lu_provider_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_lu_provider_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_port_provider_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_port_provider_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_local_port_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_local_port_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_lu_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_lu_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_scsi_session_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_scsi_session_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(scsi_task_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(stmf_i_scsi_task_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_data_buf_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(__istmf_t) },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { GET_STRUCT_SIZE(stmf_dbuf_store_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte GET_STRUCT_SIZE(__istmf_t) }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_alloc(stmf_struct_id_t struct_id, int additional_size, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stmf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int kmem_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte __stmf_t *sh;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((struct_id == 0) || (struct_id >= STMF_MAX_STRUCT_IDS))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((curthread->t_flag & T_INTR_THREAD) || (flags & AF_FORCE_NOSLEEP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_flag = KM_NOSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_flag = KM_SLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte additional_size = (additional_size + 7) & (~7);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_size = stmf_sizes[struct_id].shared +
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv stmf_sizes[struct_id].fw_private + additional_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (flags & AF_DONTZERO)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore sh = (__stmf_t *)kmem_alloc(stmf_size, kmem_flag);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore else
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore sh = (__stmf_t *)kmem_zalloc(stmf_size, kmem_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sh == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang /*
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * In principle, the implementation inside stmf_alloc should not
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * be changed anyway. But the original order of framework private
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * data and caller private data does not support sglist in the caller
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * private data.
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * To work around this, the memory segments of framework private
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * data and caller private data are re-ordered here.
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * A better solution is to provide a specific interface to allocate
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * the sglist, then we will not need this workaround any more.
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * But before the new interface is available, the memory segment
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * ordering should be kept as is.
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang */
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang sh->cp = GET_BYTE_OFFSET(sh, stmf_sizes[struct_id].shared);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang sh->fp = (__istmf_t *)GET_BYTE_OFFSET(sh,
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang stmf_sizes[struct_id].shared + additional_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sh->fp->bp = sh;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Just store the total size instead of storing additional size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sh->fp->alloc_size = stmf_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sh);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_free(void *ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte __stmf_t *sh = (__stmf_t *)ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So far we dont need any struct specific processing. If such
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a need ever arises, then store the struct id in the framework
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * private section and get it here as sh->fp->struct_id.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ptr, sh->fp->alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Given a pointer to stmf_lu_t, verifies if this lu is registered with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * framework and returns a pointer to framework private data for the lu.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns NULL if the lu was not found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_lu_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_lu(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL; ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_lu == lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ilu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto * Given a pointer to stmf_local_port_t, verifies if this lport is registered
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto * with the framework and returns a pointer to framework private data for
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto * the lport.
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto * Returns NULL if the lport was not found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_local_port_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_lport(stmf_local_port_t *lport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_lport == lport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ilport);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_lu_provider(stmf_lu_provider_t *lp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_provider_t *ilp = (stmf_i_lu_provider_t *)lp->lp_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t *ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cb_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lp->lp_lpif_rev != LPIF_REV_1 && lp->lp_lpif_rev != LPIF_REV_2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_next = stmf_state.stmf_ilplist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ilplist = ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlps++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if we need to do a callback */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = ppd->ppd_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ppd->ppd_name, lp->lp_name) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppd == NULL) || (ppd->ppd_nv == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto rlp_bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_ppd = ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider = ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lp->lp_cb == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto rlp_bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_cb_in_progress = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb_flags = STMF_PCB_PREG_COMPLETE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_INIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb_flags |= STMF_PCB_STMF_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lp->lp_cb(lp, STMF_PROVIDER_DATA_UPDATED, ppd->ppd_nv, cb_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_cb_in_progress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterlp_bail_out:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_lu_provider(stmf_lu_provider_t *lp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_provider_t **ppilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_provider_t *ilp = (stmf_i_lu_provider_t *)lp->lp_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->ilp_nlus || ilp->ilp_cb_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppilp = &stmf_state.stmf_ilplist; *ppilp != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppilp = &((*ppilp)->ilp_next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ppilp == ilp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ppilp = ilp->ilp_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlps--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->ilp_ppd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_ppd->ppd_provider = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_ppd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_port_provider(stmf_port_provider_t *pp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_port_provider_t *ipp =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_port_provider_t *)pp->pp_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t *ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cb_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pp->pp_portif_rev != PORTIF_REV_1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_next = stmf_state.stmf_ipplist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ipplist = ipp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_npps++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if we need to do a callback */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = ppd->ppd_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ppd->ppd_name, pp->pp_name) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppd == NULL) || (ppd->ppd_nv == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto rpp_bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_ppd = ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider = ipp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pp->pp_cb == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto rpp_bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_cb_in_progress = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb_flags = STMF_PCB_PREG_COMPLETE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_INIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb_flags |= STMF_PCB_STMF_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp->pp_cb(pp, STMF_PROVIDER_DATA_UPDATED, ppd->ppd_nv, cb_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_cb_in_progress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterpp_bail_out:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_port_provider(stmf_port_provider_t *pp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_port_provider_t *ipp =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_port_provider_t *)pp->pp_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_port_provider_t **ppipp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipp->ipp_npps || ipp->ipp_cb_in_progress) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppipp = &stmf_state.stmf_ipplist; *ppipp != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppipp = &((*ppipp)->ipp_next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ppipp == ipp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ppipp = ipp->ipp_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_npps--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipp->ipp_ppd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_ppd->ppd_provider = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_ppd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmf_load_ppd_ioctl(stmf_ppioctl_data_t *ppi, uint64_t *ppi_token,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t *err_ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_port_provider_t *ipp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_provider_t *ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t *ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nvlist_t *nv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *err_ret = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppi->ppi_lu_provider + ppi->ppi_port_provider) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = ppd->ppd_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppi->ppi_lu_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ppd->ppd_lu_provider)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ppi->ppi_port_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ppd->ppd_port_provider)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(ppi->ppi_name, ppd->ppd_name, 254) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* New provider */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = strlen(ppi->ppi_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (s > 254) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s += sizeof (stmf_pp_data_t) - 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd = kmem_zalloc(s, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_alloc_size = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ppd->ppd_name, ppi->ppi_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if this provider already exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppi->ppi_lu_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_lu_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilp = stmf_state.stmf_ilplist; ilp != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = ilp->ilp_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ppi->ppi_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_lp->lp_name) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider = ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_ppd = ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_port_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ipp = stmf_state.stmf_ipplist; ipp != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp = ipp->ipp_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ppi->ppi_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_pp->pp_name) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider = ipp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_ppd = ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Link this ppd in */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_next = stmf_state.stmf_ppdlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ppdlist = ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * User is requesting that the token be checked.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * If there was another set after the user's get
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * it's an error
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi->ppi_token_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi->ppi_token != ppd->ppd_token) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *err_ret = STMF_IOCERR_PPD_UPDATED;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (EINVAL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = nvlist_unpack((char *)ppi->ppi_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (size_t)ppi->ppi_data_size, &nv, KM_NOSLEEP)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free any existing lists and add this one to the ppd */
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(ppd->ppd_nv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_nv = nv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* set the token for writes */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppd->ppd_token++;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* return token to caller */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi_token) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ppi_token = ppd->ppd_token;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If there is a provider registered, do the notifications */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd->ppd_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cb_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_config_state == STMF_CONFIG_INIT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb_flags |= STMF_PCB_STMF_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppi->ppi_lu_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = (stmf_i_lu_provider_t *)ppd->ppd_provider;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->ilp_lp->lp_cb == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_cb_in_progress = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_lp->lp_cb(ilp->ilp_lp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_PROVIDER_DATA_UPDATED, ppd->ppd_nv, cb_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->ilp_cb_in_progress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp = (stmf_i_port_provider_t *)ppd->ppd_provider;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipp->ipp_pp->pp_cb == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bail_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_cb_in_progress = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_pp->pp_cb(ipp->ipp_pp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_PROVIDER_DATA_UPDATED, ppd->ppd_nv, cb_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->ipp_cb_in_progress = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebail_out:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_delete_ppd(stmf_pp_data_t *ppd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t **pppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd->ppd_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd->ppd_lu_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_lu_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider)->ilp_ppd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_port_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider)->ipp_ppd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppd->ppd_provider = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pppd = &stmf_state.stmf_ppdlist; *pppd != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv pppd = &((*pppd)->ppd_next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*pppd == ppd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*pppd == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pppd = ppd->ppd_next;
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(ppd->ppd_nv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ppd, ppd->ppd_alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_delete_ppd_ioctl(stmf_ppioctl_data_t *ppi)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t *ppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = ENOENT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ppi->ppi_lu_provider + ppi->ppi_port_provider) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = ppd->ppd_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppi->ppi_lu_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ppd->ppd_lu_provider)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ppi->ppi_port_provider) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ppd->ppd_port_provider)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(ppi->ppi_name, ppd->ppd_name, 254) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_delete_ppd(ppd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmf_get_ppd_ioctl(stmf_ppioctl_data_t *ppi, stmf_ppioctl_data_t *ppi_out,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t *err_ret)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_pp_data_t *ppd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto size_t req_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = ENOENT;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto char *bufp = (char *)ppi_out->ppi_data;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ppi->ppi_lu_provider + ppi->ppi_port_provider) != 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (EINVAL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = ppd->ppd_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi->ppi_lu_provider) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (!ppd->ppd_lu_provider)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (ppi->ppi_port_provider) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (!ppd->ppd_port_provider)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strncmp(ppi->ppi_name, ppd->ppd_name, 254) == 0)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppd && ppd->ppd_nv) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out->ppi_token = ppd->ppd_token;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = nvlist_size(ppd->ppd_nv, &req_size,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto NV_ENCODE_XDR)) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out->ppi_data_size = req_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (req_size > ppi->ppi_data_size) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *err_ret = STMF_IOCERR_INSUFFICIENT_BUF;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = EINVAL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = nvlist_pack(ppd->ppd_nv, &bufp, &req_size,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto NV_ENCODE_XDR, 0)) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_delete_all_ppds()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_pp_data_t *ppd, *nppd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppd = stmf_state.stmf_ppdlist; ppd != NULL; ppd = nppd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nppd = ppd->ppd_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_delete_ppd(ppd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto/*
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto * 16 is the max string length of a protocol_ident, increase
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto * the size if needed.
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto#define STMF_KSTAT_LU_SZ (STMF_GUID_INPUT + 1 + 256)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto#define STMF_KSTAT_TGT_SZ (256 * 2 + 16)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto/*
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto * This array matches the Protocol Identifier in stmf_ioctl.h
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto#define MAX_PROTO_STR_LEN 32
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetochar *protocol_ident[PROTOCOL_ANY] = {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "Fibre Channel",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "Parallel SCSI",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "SSA",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "IEEE_1394",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "SRP",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "iSCSI",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "SAS",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "ADT",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "ATAPI",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN"
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto};
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto/*
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto * Update the lun wait/run queue count
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_update_kstat_lu_q(scsi_task_t *task, void func())
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_i_lu_t *ilu;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_io_t *kip;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (task->task_lu == dlun0)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilu != NULL && ilu->ilu_kstat_io != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kip = KSTAT_IO_PTR(ilu->ilu_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (kip != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto func(kip);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto/*
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto * Update the target(lport) wait/run queue count
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_update_kstat_lport_q(scsi_task_t *task, void func())
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_i_local_port_t *ilp;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_io_t *kip;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilp = (stmf_i_local_port_t *)task->task_lport->lport_stmf_private;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilp != NULL && ilp->ilport_kstat_io != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kip = KSTAT_IO_PTR(ilp->ilport_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (kip != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_enter(ilp->ilport_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto func(kip);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_exit(ilp->ilport_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_update_kstat_lport_io(scsi_task_t *task, stmf_data_buf_t *dbuf)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_i_local_port_t *ilp;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_io_t *kip;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilp = (stmf_i_local_port_t *)task->task_lport->lport_stmf_private;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilp != NULL && ilp->ilport_kstat_io != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kip = KSTAT_IO_PTR(ilp->ilport_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (kip != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_enter(ilp->ilport_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto STMF_UPDATE_KSTAT_IO(kip, dbuf);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_exit(ilp->ilport_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_update_kstat_lu_io(scsi_task_t *task, stmf_data_buf_t *dbuf)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_i_lu_t *ilu;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_io_t *kip;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilu != NULL && ilu->ilu_kstat_io != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kip = KSTAT_IO_PTR(ilu->ilu_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (kip != NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_enter(ilu->ilu_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto STMF_UPDATE_KSTAT_IO(kip, dbuf);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_exit(ilu->ilu_kstat_io->ks_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_create_kstat_lu(stmf_i_lu_t *ilu)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto char ks_nm[KSTAT_STRLEN];
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_kstat_lu_info_t *ks_lu;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* create kstat lun info */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ks_lu = (stmf_kstat_lu_info_t *)kmem_zalloc(STMF_KSTAT_LU_SZ,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KM_NOSLEEP);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ks_lu == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kmem_zalloc failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bzero(ks_nm, sizeof (ks_nm));
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (void) sprintf(ks_nm, "stmf_lu_%"PRIxPTR"", (uintptr_t)ilu);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if ((ilu->ilu_kstat_info = kstat_create(STMF_MODULE_NAME, 0,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ks_nm, "misc", KSTAT_TYPE_NAMED,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto sizeof (stmf_kstat_lu_info_t) / sizeof (kstat_named_t),
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_FLAG_VIRTUAL)) == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kmem_free(ks_lu, STMF_KSTAT_LU_SZ);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kstat_create lu failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilu->ilu_kstat_info->ks_data_size = STMF_KSTAT_LU_SZ;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilu->ilu_kstat_info->ks_data = ks_lu;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_init(&ks_lu->i_lun_guid, "lun-guid",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_DATA_STRING);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_init(&ks_lu->i_lun_alias, "lun-alias",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_DATA_STRING);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* convert guid to hex string */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto int i;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto uint8_t *p = ilu->ilu_lu->lu_id->ident;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bzero(ilu->ilu_ascii_hex_guid, sizeof (ilu->ilu_ascii_hex_guid));
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto for (i = 0; i < STMF_GUID_INPUT / 2; i++) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (void) sprintf(&ilu->ilu_ascii_hex_guid[i * 2], "%02x", p[i]);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_setstr(&ks_lu->i_lun_guid,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (const char *)ilu->ilu_ascii_hex_guid);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_setstr(&ks_lu->i_lun_alias,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (const char *)ilu->ilu_lu->lu_alias);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_install(ilu->ilu_kstat_info);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* create kstat lun io */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bzero(ks_nm, sizeof (ks_nm));
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (void) sprintf(ks_nm, "stmf_lu_io_%"PRIxPTR"", (uintptr_t)ilu);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if ((ilu->ilu_kstat_io = kstat_create(STMF_MODULE_NAME, 0,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ks_nm, "io", KSTAT_TYPE_IO, 1, 0)) == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kstat_create lu_io failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_init(&ilu->ilu_kstat_lock, NULL, MUTEX_DRIVER, 0);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilu->ilu_kstat_io->ks_lock = &ilu->ilu_kstat_lock;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_install(ilu->ilu_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostatic void
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szetostmf_create_kstat_lport(stmf_i_local_port_t *ilport)
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto{
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto char ks_nm[KSTAT_STRLEN];
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_kstat_tgt_info_t *ks_tgt;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto int id, len;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* create kstat lport info */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ks_tgt = (stmf_kstat_tgt_info_t *)kmem_zalloc(STMF_KSTAT_TGT_SZ,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KM_NOSLEEP);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ks_tgt == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kmem_zalloc failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bzero(ks_nm, sizeof (ks_nm));
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (void) sprintf(ks_nm, "stmf_tgt_%"PRIxPTR"", (uintptr_t)ilport);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if ((ilport->ilport_kstat_info = kstat_create(STMF_MODULE_NAME,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto 0, ks_nm, "misc", KSTAT_TYPE_NAMED,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto sizeof (stmf_kstat_tgt_info_t) / sizeof (kstat_named_t),
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_FLAG_VIRTUAL)) == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kmem_free(ks_tgt, STMF_KSTAT_TGT_SZ);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kstat_create target failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilport->ilport_kstat_info->ks_data_size = STMF_KSTAT_TGT_SZ;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilport->ilport_kstat_info->ks_data = ks_tgt;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_init(&ks_tgt->i_tgt_name, "target-name",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_DATA_STRING);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_init(&ks_tgt->i_tgt_alias, "target-alias",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_DATA_STRING);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_init(&ks_tgt->i_protocol, "protocol",
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto KSTAT_DATA_STRING);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* ident might not be null terminated */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto len = ilport->ilport_lport->lport_id->ident_length;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bcopy(ilport->ilport_lport->lport_id->ident,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilport->ilport_kstat_tgt_name, len);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilport->ilport_kstat_tgt_name[len + 1] = NULL;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_setstr(&ks_tgt->i_tgt_name,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (const char *)ilport->ilport_kstat_tgt_name);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_setstr(&ks_tgt->i_tgt_alias,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (const char *)ilport->ilport_lport->lport_alias);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* protocol */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if ((id = ilport->ilport_lport->lport_id->protocol_id) > PROTOCOL_ANY) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: protocol_id out of bound");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto id = PROTOCOL_ANY;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_named_setstr(&ks_tgt->i_protocol, protocol_ident[id]);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_install(ilport->ilport_kstat_info);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto /* create kstat lport io */
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto bzero(ks_nm, sizeof (ks_nm));
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto (void) sprintf(ks_nm, "stmf_tgt_io_%"PRIxPTR"", (uintptr_t)ilport);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if ((ilport->ilport_kstat_io = kstat_create(STMF_MODULE_NAME, 0,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ks_nm, "io", KSTAT_TYPE_IO, 1, 0)) == NULL) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto cmn_err(CE_WARN, "STMF: kstat_create target_io failed");
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto return;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_init(&ilport->ilport_kstat_lock, NULL, MUTEX_DRIVER, 0);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto ilport->ilport_kstat_io->ks_lock = &ilport->ilport_kstat_lock;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_install(ilport->ilport_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto}
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * set the asymmetric access state for a logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * caller is responsible for establishing SCSI unit attention on
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * state change
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_status_t
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_set_lu_access(stmf_lu_t *lu, uint8_t access_state)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_t *ilu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint8_t *p1, *p2;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((access_state != STMF_LU_STANDBY) &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (access_state != STMF_LU_ACTIVE)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p1 = &lu->lu_id->ident[0];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_inventory_locked) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_BUSY);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL; ilu = ilu->ilu_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p2 = &ilu->ilu_lu->lu_id->ident[0];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (bcmp(p1, p2, 16) == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (!ilu) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * We're changing access state on an existing logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Send the proxy registration message for this logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if we're in alua mode.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If the requested state is STMF_LU_ACTIVE, we want to register
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * this logical unit.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If the requested state is STMF_LU_STANDBY, we're going to
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * abort all tasks for this logical unit.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_state == 1 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte access_state == STMF_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret = STMF_IC_MSG_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_reg_lun;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lu->lu_lp && lu->lu_lp->lp_lpif_rev == LPIF_REV_2 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_alua_support) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_alua = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* allocate the register message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_reg_lun = ic_lun_active_msg_alloc(p1,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_name,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_proxy_reg_arg_len,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (uint8_t *)lu->lu_proxy_reg_arg,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* send the message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_lun) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_reg_lun);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (stmf_state.stmf_alua_state == 1 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte access_state == STMF_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* abort all tasks for this lu */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_task_lu_killall(lu, NULL, STMF_ABORTED);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_access = access_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_SUCCESS);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_lu(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p1, *p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_change_info_t ssci;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lu->lu_id->ident_type != ID_TYPE_NAA) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lu->lu_id->ident_length != 16) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((lu->lu_id->ident[0] & 0xf0) != 0x60)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p1 = &lu->lu_id->ident[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu != NULL; ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p2 = &ilu->ilu_lu->lu_id->ident[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(p1, p2, 16) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_lookup_id(&stmf_state.stmf_luid_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_id->ident_length, lu->lu_id->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid->id_pt_to_object = (void *)ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_alias = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_next = stmf_state.stmf_ilulist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_next->ilu_prev = ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ilulist = ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlus++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu->lu_lp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_lu_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lu->lu_lp->lp_stmf_private))->ilp_nlus++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_cur_task_cntr = &ilu->ilu_task_cntr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_ALLOC_HANDLE(ilu->ilu_event_hdl);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov cv_init(&ilu->ilu_offline_pending_cv, NULL, CV_DRIVER, NULL);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_create_kstat_lu(ilu);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * register with proxy module if available and logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * is in active state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_state == 1 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_access == STMF_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret = STMF_IC_MSG_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_reg_lun;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lu->lu_lp && lu->lu_lp->lp_lpif_rev == LPIF_REV_2 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_alua_support) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_alua = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* allocate the register message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_reg_lun = ic_reg_lun_msg_alloc(p1,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_name, lu->lu_proxy_reg_arg_len,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (uint8_t *)lu->lu_proxy_reg_arg, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* send the message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_lun) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_reg_lun);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli /* check the default state for lu */
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_default_lu_state == STMF_STATE_OFFLINE) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ilu->ilu_prev_state = STMF_STATE_OFFLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ilu->ilu_prev_state = STMF_STATE_ONLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_service_running) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ssci.st_rflags = 0;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ssci.st_additional_info = NULL;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (void) stmf_ctl(STMF_CMD_LU_ONLINE, lu, &ssci);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* XXX: Generate event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_lu(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = stmf_lookup_lu(lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_state == STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilu->ilu_ntasks == ilu->ilu_ntasks_free);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ilu->ilu_flags & ILU_STALL_DEREGISTER) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&stmf_state.stmf_cv, &stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_ntasks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask, *nitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitask = ilu->ilu_tasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = nitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitask = itask->itask_lu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_task_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (nitask != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_tasks = ilu->ilu_free_tasks = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks = ilu->ilu_ntasks_free = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* de-register with proxy if available */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilu->ilu_access == STMF_LU_ACTIVE &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_state.stmf_alua_state == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* de-register with proxy module */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret = STMF_IC_MSG_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_dereg_lun;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lu->lu_lp && lu->lu_lp->lp_lpif_rev == LPIF_REV_2 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_lp->lp_alua_support) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilu->ilu_alua = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* allocate the de-register message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_dereg_lun = ic_dereg_lun_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lu->lu_id->ident, lu->lu_lp->lp_name, 0,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte NULL, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* send the message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_dereg_lun) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_dereg_lun);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_next->ilu_prev = ilu->ilu_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_prev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_prev->ilu_next = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ilulist = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlus--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == stmf_state.stmf_svc_ilu_draining) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_ilu_draining = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == stmf_state.stmf_svc_ilu_timing) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_ilu_timing = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu->lu_lp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_lu_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lu->lu_lp->lp_stmf_private))->ilp_nlus--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_luid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_id_data_t *)ilu->ilu_luid)->id_pt_to_object =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_FREE_HANDLE(ilu->ilu_event_hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilu->ilu_kstat_info) {
3c9850a686c2fcba473e4f602616772c17c21deeDan McDonald kmem_free(ilu->ilu_kstat_info->ks_data, STMF_KSTAT_LU_SZ);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_delete(ilu->ilu_kstat_info);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilu->ilu_kstat_io) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_delete(ilu->ilu_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_destroy(&ilu->ilu_kstat_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov cv_destroy(&ilu->ilu_offline_pending_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_set_port_standby(stmf_local_port_t *lport, uint16_t rtpid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_local_port_t *ilport =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_i_local_port_t *)lport->lport_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_rtpid = rtpid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_standby = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Fortevoid
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Fortestmf_set_port_alua(stmf_local_port_t *lport)
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte{
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte stmf_i_local_port_t *ilport =
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte (stmf_i_local_port_t *)lport->lport_stmf_private;
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_alua = 1;
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte}
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_local_port(stmf_local_port_t *lport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_change_info_t ssci;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int start_workers = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = (stmf_i_local_port_t *)lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_init(&ilport->ilport_lock, NULL, RW_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ilport->ilport_instance =
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_alloc_nosleep(stmf_state.stmf_ilport_inst_space);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (ilport->ilport_instance == -1) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (STMF_FAILURE);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_next = stmf_state.stmf_ilportlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_next->ilport_prev = ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ilportlist = ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlports++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lport->lport_pp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_port_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lport->lport_pp->pp_stmf_private))->ipp_npps++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lookup_group_for_target(lport->lport_id->ident,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv lport->lport_id->ident_length);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * rtpid will/must be set if this is a standby port
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * only register ports that are not standby (proxy) ports
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte * and ports that are alua participants (ilport_alua == 1)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilport->ilport_standby == 0) {
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek ilport->ilport_rtpid = atomic_inc_16_nv(&stmf_rtpid_counter);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_state == 1 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_standby == 0 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_alua == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_reg_port;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_local_port_t *lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport = ilport->ilport_lport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_reg_port = ic_reg_port_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_id, ilport->ilport_rtpid,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte 0, NULL, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_reg_port) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_reg_port);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport->ilport_reg_msgid = stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "error on port registration "
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "port - %s", ilport->ilport_kstat_tgt_name);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_ALLOC_HANDLE(ilport->ilport_event_hdl);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_create_kstat_lport(ilport);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_workers_state == STMF_WORKERS_DISABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers_state = STMF_WORKERS_ENABLING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_workers = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start_workers)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_init();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli /* the default state of LPORT */
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_default_lport_state == STMF_STATE_OFFLINE) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ilport->ilport_prev_state = STMF_STATE_OFFLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ilport->ilport_prev_state = STMF_STATE_ONLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_state.stmf_service_running) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ssci.st_rflags = 0;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ssci.st_additional_info = NULL;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (void) stmf_ctl(STMF_CMD_LPORT_ONLINE, lport, &ssci);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* XXX: Generate event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_local_port(stmf_local_port_t *lport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_inventory_locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* dequeue all object requests from active queue */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_svc_kill_obj_requests(lport);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = (stmf_i_local_port_t *)lport->lport_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * deregister ports that are not standby (proxy)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_state == 1 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_standby == 0 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_alua == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_dereg_port;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_status_t ic_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_dereg_port = ic_dereg_port_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lport->lport_id, 0, NULL, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_dereg_port) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_dereg_port);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_nsessions == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_next->ilport_prev = ilport->ilport_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_prev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_prev->ilport_next = ilport->ilport_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ilportlist = ilport->ilport_next;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_free(stmf_state.stmf_ilport_inst_space,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ilport->ilport_instance);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_destroy(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_nlports--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lport->lport_pp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_i_port_provider_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lport->lport_pp->pp_stmf_private))->ipp_npps--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_FREE_HANDLE(ilport->ilport_event_hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilport->ilport_kstat_info) {
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto kmem_free(ilport->ilport_kstat_info->ks_data,
3c9850a686c2fcba473e4f602616772c17c21deeDan McDonald STMF_KSTAT_TGT_SZ);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_delete(ilport->ilport_kstat_info);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (ilport->ilport_kstat_io) {
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto kstat_delete(ilport->ilport_kstat_io);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto mutex_destroy(&ilport->ilport_kstat_lock);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto/*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * Rport id/instance mappings remain valid until STMF is unloaded
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic int
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_compare(const void *void_irport1, const void *void_irport2)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto const stmf_i_remote_port_t *irport1 = void_irport1;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto const stmf_i_remote_port_t *irport2 = void_irport2;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto int result;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Sort by code set then ident */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport1->irport_id->code_set <
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport2->irport_id->code_set) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (-1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto } else if (irport1->irport_id->code_set >
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport2->irport_id->code_set) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Next by ident length */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport1->irport_id->ident_length <
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport2->irport_id->ident_length) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (-1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto } else if (irport1->irport_id->ident_length >
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport2->irport_id->ident_length) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Code set and ident length both match, now compare idents */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto result = memcmp(irport1->irport_id->ident,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport2->irport_id->ident,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport1->irport_id->ident_length);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (result < 0) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (-1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto } else if (result > 0) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (0);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_create(scsi_devid_desc_t *rport_devid)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto int alloc_len;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_remote_port_t *irport;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * Lookup will bump the refcnt if there's an existing rport
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * context for this identifier.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto alloc_len = sizeof (*irport) + sizeof (scsi_devid_desc_t) +
427fcaf873956aad428be801380a44e59d38b8b5tim szeto rport_devid->ident_length - 1;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport = kmem_zalloc(alloc_len, KM_NOSLEEP);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport == NULL) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (NULL);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_instance =
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_alloc_nosleep(stmf_state.stmf_irport_inst_space);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport->irport_instance == -1) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto kmem_free(irport, alloc_len);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (NULL);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_id =
427fcaf873956aad428be801380a44e59d38b8b5tim szeto (struct scsi_devid_desc *)(irport + 1); /* Ptr. Arith. */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto bcopy(rport_devid, irport->irport_id,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto sizeof (scsi_devid_desc_t) + rport_devid->ident_length - 1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_refcnt = 1;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_init(&irport->irport_mutex, NULL, MUTEX_DEFAULT, NULL);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_destroy(stmf_i_remote_port_t *irport)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto id_free(stmf_state.stmf_irport_inst_space, irport->irport_instance);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_destroy(&irport->irport_mutex);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto kmem_free(irport, sizeof (*irport) + sizeof (scsi_devid_desc_t) +
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_id->ident_length - 1);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_register(scsi_devid_desc_t *rport_devid)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_remote_port_t *irport;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_enter(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * Lookup will bump the refcnt if there's an existing rport
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * context for this identifier.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if ((irport = stmf_irport_lookup_locked(rport_devid)) != NULL) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport = stmf_irport_create(rport_devid);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport == NULL) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (NULL);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto avl_add(&stmf_state.stmf_irportlist, irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic stmf_i_remote_port_t *
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_lookup_locked(scsi_devid_desc_t *rport_devid)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_remote_port_t *irport;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_remote_port_t tmp_irport;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
427fcaf873956aad428be801380a44e59d38b8b5tim szeto tmp_irport.irport_id = rport_devid;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport = avl_find(&stmf_state.stmf_irportlist, &tmp_irport, NULL);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (irport != NULL) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_enter(&irport->irport_mutex);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_refcnt++;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&irport->irport_mutex);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (irport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_irport_deregister(stmf_i_remote_port_t *irport)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * If we were actually going to remove unreferenced remote ports
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * we would want to acquire stmf_state.stmf_lock before getting
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * the irport mutex.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto *
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * Instead we're just going to leave it there even if unreferenced.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_enter(&irport->irport_mutex);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto irport->irport_refcnt--;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(&irport->irport_mutex);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Port provider has to make sure that register/deregister session and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port are serialized calls.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_scsi_session(stmf_local_port_t *lport, stmf_scsi_session_t *ss)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport = (stmf_i_local_port_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t lun[8];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Port state has to be online to register a scsi session. It is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * possible that we started an offline operation and a new SCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session started at the same time (in that case also we are going
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to fail the registeration). But any other state is simply
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a bad port provider implementation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_OFFLINING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace(lport->lport_alias, "Port is trying to "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "register a session while the state is neither "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "online nor offlining");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(lun, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)ss->ss_stmf_private;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if ((iss->iss_irport = stmf_irport_register(ss->ss_rport_id)) == NULL) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_trace(lport->lport_alias, "Could not register "
427fcaf873956aad428be801380a44e59d38b8b5tim szeto "remote port during session registration");
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (STMF_FAILURE);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_flags |= ISS_BEING_CREATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (ss->ss_rport == NULL) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iss->iss_flags |= ISS_NULL_TPTID;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ss->ss_rport = stmf_scsilib_devid_to_remote_port(
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ss->ss_rport_id);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (ss->ss_rport == NULL) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iss->iss_flags &= ~(ISS_NULL_TPTID | ISS_BEING_CREATED);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_trace(lport->lport_alias, "Device id to "
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan "remote port conversion failed");
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (STMF_FAILURE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan } else {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (!stmf_scsilib_tptid_validate(ss->ss_rport->rport_tptid,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ss->ss_rport->rport_tptid_sz, NULL)) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iss->iss_flags &= ~ISS_BEING_CREATED;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_trace(lport->lport_alias, "Remote port "
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan "transport id validation failed");
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (STMF_FAILURE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* sessions use the ilport_lock. No separate lock is required */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_lockp = &ilport->ilport_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto if (iss->iss_sm != NULL)
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto cmn_err(CE_PANIC, "create lun map called with non NULL map");
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto iss->iss_sm = (stmf_lun_map_t *)kmem_zalloc(sizeof (stmf_lun_map_t),
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto KM_SLEEP);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ilport->ilport_lock, RW_WRITER);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto (void) stmf_session_create_lun_map(ilport, iss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_nsessions++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_next = ilport->ilport_ss_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_ss_list = iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_creation_time = ddi_get_time();
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek ss->ss_session_id = atomic_inc_64_nv(&stmf_session_counter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_flags &= ~ISS_BEING_CREATED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* XXX should we remove ISS_LUN_INVENTORY_CHANGED on new session? */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte iss->iss_flags &= ~ISS_LUN_INVENTORY_CHANGED;
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE2(session__online, stmf_local_port_t *, lport,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto stmf_scsi_session_t *, ss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_scsi_session(stmf_local_port_t *lport, stmf_scsi_session_t *ss)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport = (stmf_i_local_port_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss, **ppss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_session_dereg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t ic_ret = STMF_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE2(session__offline, stmf_local_port_t *, lport,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto stmf_scsi_session_t *, ss);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)ss->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ss->ss_rport_alias) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss->ss_rport_alias = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetry_dereg_ss_again:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ~(ISS_LUN_INVENTORY_CHANGED | ISS_GOT_INITIAL_LUNS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_flags & ISS_EVENT_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto try_dereg_ss_again;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* dereg proxy session if not standby port */
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte if (stmf_state.stmf_alua_state == 1 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_standby == 0 &&
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte ilport->ilport_alua == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_session_dereg = ic_session_dereg_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ss, stmf_proxy_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_session_dereg) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_session_dereg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret == STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ilport->ilport_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppss = &ilport->ilport_ss_list; *ppss != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppss = &((*ppss)->iss_next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss == (*ppss)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ppss = (*ppss)->iss_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "Deregister session called for non existent"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " session");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_nsessions--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_irport_deregister(iss->iss_irport);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_session_destroy_lun_map(ilport, iss);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto rw_exit(&ilport->ilport_lock);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto mutex_exit(&stmf_state.stmf_lock);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (iss->iss_flags & ISS_NULL_TPTID) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_remote_port_free(ss->ss_rport);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_scsi_session_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_id_to_issptr(uint64_t session_id, int stay_locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ilport->ilport_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv iss = iss->iss_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_ss->ss_session_id == session_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stay_locked)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_release_itl_handle(stmf_lu_t *lu, stmf_itl_data_t *itl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_itl_data_t **itlpp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itl->itl_flags & STMF_ITL_BEING_TERMINATED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (itlpp = &ilu->ilu_itl_list; (*itlpp) != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv itlpp = &(*itlpp)->itl_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*itlpp) == itl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((*itlpp) != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *itlpp = itl->itl_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_abort(lu, STMF_LU_ITL_HANDLE_REMOVED, itl->itl_handle,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (uint32_t)itl->itl_hdlrm_reason);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(itl, sizeof (*itl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_register_itl_handle(stmf_lu_t *lu, uint8_t *lun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsi_session_t *ss, uint64_t session_id, void *itl_handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_itl_data_t *itl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lun_map_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ss == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = stmf_session_id_to_issptr(session_id, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)ss->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a8e2ef8ffd76e062a138e86bdafe5484f62f6b5btim szeto mutex_enter(&stmf_state.stmf_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto rw_enter(iss->iss_lockp, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = ((uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent = (stmf_lun_map_ent_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv stmf_get_ent_from_map(iss->iss_sm, n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lun_map_ent == NULL) || (lun_map_ent->ent_lu != lu)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
a8e2ef8ffd76e062a138e86bdafe5484f62f6b5btim szeto mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_map_ent->ent_itl_datap != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
a8e2ef8ffd76e062a138e86bdafe5484f62f6b5btim szeto mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl = (stmf_itl_data_t *)kmem_zalloc(sizeof (*itl), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itl == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
a8e2ef8ffd76e062a138e86bdafe5484f62f6b5btim szeto mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALLOC_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itl->itl_ilu = ilu;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itl->itl_session = iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl->itl_counter = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl->itl_lun = n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl->itl_handle = itl_handle;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl->itl_next = ilu->ilu_itl_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_itl_list = itl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent->ent_itl_datap = itl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
a8e2ef8ffd76e062a138e86bdafe5484f62f6b5btim szeto mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_do_itl_dereg(stmf_lu_t *lu, stmf_itl_data_t *itl, uint8_t hdlrm_reason)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itl->itl_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & STMF_ITL_BEING_TERMINATED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= STMF_ITL_BEING_TERMINATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_8(&itl->itl_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl->itl_hdlrm_reason = hdlrm_reason;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itl->itl_counter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek if (atomic_dec_32_nv(&itl->itl_counter))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_release_itl_handle(lu, itl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_deregister_all_lu_itl_handles(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *lm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t nmaps, nu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_itl_data_t **itl_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedereg_itl_start:;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nmaps = ilu->ilu_ref_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nmaps == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl_list = (stmf_itl_data_t **)kmem_zalloc(
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv nmaps * sizeof (stmf_itl_data_t *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nmaps != ilu->ilu_ref_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Something changed, start all over */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(itl_list, nmaps * sizeof (stmf_itl_data_t *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto dereg_itl_start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nu = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ilport->ilport_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss != NULL;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv iss = iss->iss_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!lm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ent->ent_lu == lu) &&
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (ent->ent_itl_datap)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itl_list[nu++] = ent->ent_itl_datap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->ent_itl_datap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nu == nmaps) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto dai_scan_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* lun table for a session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* sessions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* ports */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedai_scan_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < nu; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_itl_dereg(lu, itl_list[i],
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_ITL_REASON_DEREG_REQUEST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(itl_list, nmaps * sizeof (stmf_itl_data_t *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_itl_handle(stmf_lu_t *lu, uint8_t *lun, stmf_scsi_session_t *ss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t session_id, void **itl_handle_retp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *lm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ss == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = stmf_session_id_to_issptr(session_id, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)ss->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ent->ent_lu == lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = ((uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = (stmf_lun_map_ent_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv stmf_get_ent_from_map(iss->iss_sm, n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu && (ent->ent_lu != lu))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ent && ent->ent_itl_datap) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *itl_handle_retp = ent->ent_itl_datap->itl_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_data_buf_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_alloc_dbuf(scsi_task_t *task, uint32_t size, uint32_t *pminsize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_local_port_t *lport = task->task_lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndx = stmf_first_zero[itask->itask_allocated_buf_map];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndx == 0xff)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = itask->itask_dbufs[ndx] = lport->lport_ds->ds_alloc_data_buf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task, size, pminsize, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cur_nbufs++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_allocated_buf_map |= (1 << ndx);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte dbuf->db_flags &= ~DB_LPORT_XFER_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_handle = ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestmf_status_t
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestmf_setup_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf, uint32_t flags)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore{
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_i_scsi_task_t *itask =
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore (stmf_i_scsi_task_t *)task->task_stmf_private;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_local_port_t *lport = task->task_lport;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint8_t ndx;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_status_t ret;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(task->task_additional_flags & TASK_AF_ACCEPT_LU_DBUF);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(lport->lport_ds->ds_setup_dbuf != NULL);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(dbuf->db_flags & DB_LU_DATA_BUF);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if ((task->task_additional_flags & TASK_AF_ACCEPT_LU_DBUF) == 0)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return (STMF_FAILURE);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (lport->lport_ds->ds_setup_dbuf == NULL)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return (STMF_FAILURE);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ndx = stmf_first_zero[itask->itask_allocated_buf_map];
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (ndx == 0xff)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return (STMF_FAILURE);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ret = lport->lport_ds->ds_setup_dbuf(task, dbuf, flags);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (ret == STMF_FAILURE)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return (STMF_FAILURE);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore itask->itask_dbufs[ndx] = dbuf;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore task->task_cur_nbufs++;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore itask->itask_allocated_buf_map |= (1 << ndx);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore dbuf->db_handle = ndx;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return (STMF_SUCCESS);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore}
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorevoid
3fb517f786391b507780c78aabb8d98bfea9efe9James Moorestmf_teardown_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore{
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_i_scsi_task_t *itask =
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore (stmf_i_scsi_task_t *)task->task_stmf_private;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_local_port_t *lport = task->task_lport;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(task->task_additional_flags & TASK_AF_ACCEPT_LU_DBUF);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(lport->lport_ds->ds_teardown_dbuf != NULL);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(dbuf->db_flags & DB_LU_DATA_BUF);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore itask->itask_allocated_buf_map &= ~(1 << dbuf->db_handle);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore task->task_cur_nbufs--;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore lport->lport_ds->ds_teardown_dbuf(lport->lport_ds, dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore}
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_free_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_local_port_t *lport = task->task_lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_allocated_buf_map &= ~(1 << dbuf->db_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cur_nbufs--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_ds->ds_free_data_buf(lport->lport_ds, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_data_buf_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_handle_to_buf(scsi_task_t *task, uint8_t h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h > 3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (itask->itask_dbufs[h]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct scsi_task *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_alloc(struct stmf_local_port *lport, stmf_scsi_session_t *ss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lun, uint16_t cdb_length_in, uint16_t ext_id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t **ppitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *l;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lun_map_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t cdb_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t luNbr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t new_task = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We allocate 7 extra bytes for CDB to provide a cdb pointer which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is guaranteed to be 8 byte aligned. Some LU providers like OSD
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depend upon this alignment.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdb_length_in >= 16)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb_length = cdb_length_in + 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb_length = 16 + 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)ss->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luNbr = ((uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_lun_map_ent_t *)stmf_get_ent_from_map(iss->iss_sm, luNbr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!lun_map_ent) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = dlun0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = lun_map_ent->ent_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov ASSERT(lu == dlun0 || (ilu->ilu_state != STMF_STATE_OFFLINING &&
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov ilu->ilu_state != STMF_STATE_OFFLINE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_free_tasks == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_task = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ppitask = &ilu->ilu_free_tasks; (*ppitask != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((*ppitask)->itask_cdb_buf_size < cdb_length);
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ppitask = &((*ppitask)->itask_lu_free_next))
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ppitask) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = *ppitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ppitask = (*ppitask)->itask_lu_free_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_free--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_ntasks_free < ilu->ilu_ntasks_min_free)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_min_free = ilu->ilu_ntasks_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_task = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!new_task) {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore /*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * Save the task_cdb pointer and zero per cmd fields.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * We know the task_cdb_length is large enough by task
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * selection process above.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uint8_t *save_cdb;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore uintptr_t t_start, t_end;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task = itask->itask_task;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore save_cdb = task->task_cdb; /* save */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore t_start = (uintptr_t)&task->task_flags;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore t_end = (uintptr_t)&task->task_extended_cmd;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore bzero((void *)t_start, (size_t)(t_end - t_start));
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore task->task_cdb = save_cdb; /* restore */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_ncmds = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task = (scsi_task_t *)stmf_alloc(STMF_STRUCT_SCSI_TASK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb_length, AF_FORCE_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu = lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l = task->task_lun_no;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[0] = lun[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[1] = lun[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[2] = lun[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[3] = lun[3];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[4] = lun[4];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[5] = lun[5];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[6] = lun[6];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l[7] = lun[7];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb = (uint8_t *)task->task_port_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ulong_t)(task->task_cdb) & 7ul) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb = (uint8_t *)(((ulong_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_cdb) + 7ul) & ~(7ul));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cdb_buf_size = cdb_length;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte mutex_init(&itask->itask_audit_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session = ss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lport = lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb_length = cdb_length_in;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_flags = ITASK_IN_TRANSITION;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_waitq_time = 0;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_lu_read_time = itask->itask_lu_write_time = 0;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_lport_read_time = itask->itask_lport_write_time = 0;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_read_xfer = itask->itask_write_xfer = 0;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte itask->itask_audit_index = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (new_task) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu->lu_task_alloc(task) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_next = ilu->ilu_tasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_tasks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_tasks->itask_lu_prev = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_tasks = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* kmem_zalloc automatically makes itask->itask_lu_prev NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_ilu_task_cntr = ilu->ilu_cur_task_cntr;
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_32(itask->itask_ilu_task_cntr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_start_time = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lun_map_ent != NULL) && ((itask->itask_itl_datap =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent->ent_itl_datap) != NULL)) {
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_32(&itask->itask_itl_datap->itl_counter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_itl_handle = itask->itask_itl_datap->itl_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_itl_datap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_itl_handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_task_lu_free(scsi_task_t *task, stmf_i_scsi_session_t *iss)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ASSERT(rw_lock_held(iss->iss_lockp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_flags = ITASK_IN_FREE_LIST;
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte itask->itask_proxy_msg_id = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_free_next = ilu->ilu_free_tasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_free_tasks = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_free++;
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov if (ilu->ilu_ntasks == ilu->ilu_ntasks_free)
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov cv_signal(&ilu->ilu_offline_pending_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(itask->itask_ilu_task_cntr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_lu_check_freelist(stmf_i_lu_t *ilu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t num_to_release, ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu = ilu->ilu_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilu->ilu_ntasks_min_free <= ilu->ilu_ntasks_free);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free half of the minimal free of the free tasks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_to_release = (ilu->ilu_ntasks_min_free + 1) / 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!num_to_release) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ndx = 0; ndx < num_to_release; ndx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = ilu->ilu_free_tasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_free_tasks = itask->itask_lu_free_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_free--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_task_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_lu_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_next->itask_lu_prev =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_lu_prev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_prev->itask_lu_next =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_lu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_tasks = itask->itask_lu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called with stmf_lock held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_check_freetask()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t endtime = ddi_get_lbolt() + drv_usectohz(10000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* stmf_svc_ilu_draining may get changed after stmf_lock is released */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((ilu = stmf_state.stmf_svc_ilu_draining) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_ilu_draining = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ilu->ilu_ntasks_min_free) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_min_free = ilu->ilu_ntasks_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_flags |= ILU_STALL_DEREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_lu_check_freelist(ilu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we do not care about the accuracy of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ilu_ntasks_min_free, so we don't lock here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_ntasks_min_free = ilu->ilu_ntasks_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_flags &= ~ILU_STALL_DEREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() >= endtime)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_do_ilu_timeouts(stmf_i_lu_t *ilu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t l = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t ps = drv_usectohz(1000000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t to;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (itask = ilu->ilu_tasks; itask != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = itask->itask_lu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & (ITASK_IN_FREE_LIST |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_BEING_ABORTED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task = itask->itask_task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_timeout == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte to = stmf_default_task_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte to = task->task_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_start_time + (to * ps)) > l)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_TIMEOUT, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called with stmf_lock held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_check_ilu_timing()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t endtime = ddi_get_lbolt() + drv_usectohz(10000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* stmf_svc_ilu_timing may get changed after stmf_lock is released */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((ilu = stmf_state.stmf_svc_ilu_timing) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_ilu_timing = ilu->ilu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_cur_task_cntr == (&ilu->ilu_task_cntr1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_task_cntr2 == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_cur_task_cntr = &ilu->ilu_task_cntr2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_task_cntr1 == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_cur_task_cntr = &ilu->ilu_task_cntr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we are here then it means that there is some slowdown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in tasks on this lu. We need to check.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_flags |= ILU_STALL_DEREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_ilu_timeouts(ilu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_flags &= ~ILU_STALL_DEREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() >= endtime)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Kills all tasks on a lu except tm_task
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_lu_killall(stmf_lu_t *lu, scsi_task_t *tm_task, stmf_status_t s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (itask = ilu->ilu_tasks; itask != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = itask->itask_lu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & ITASK_IN_FREE_LIST)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_task == tm_task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, itask->itask_task, s, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ilu->ilu_task_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_free_task_bufs(stmf_i_scsi_task_t *itask, stmf_local_port_t *lport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if ((map = itask->itask_allocated_buf_map) == 0)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore return;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore for (i = 0; i < 4; i++) {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (map & 1) {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore dbuf = itask->itask_dbufs[i];
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (dbuf->db_xfer_start_timestamp) {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_lport_xfer_done(itask, dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore }
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore if (dbuf->db_flags & DB_LU_DATA_BUF) {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore /*
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * LU needs to clean up buffer.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * LU is required to free the buffer
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore * in the xfer_done handler.
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore scsi_task_t *task = itask->itask_task;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore stmf_lu_t *lu = task->task_lu;
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore lu->lu_dbuf_free(task, dbuf);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(((itask->itask_allocated_buf_map>>i)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore & 1) == 0); /* must be gone */
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore } else {
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ASSERT(dbuf->db_lu_private == NULL);
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore dbuf->db_lu_private = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_ds->ds_free_data_buf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_ds, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore map >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore itask->itask_allocated_buf_map = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_free(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_local_port_t *lport = task->task_lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = (stmf_i_scsi_task_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_scsi_session_t *iss = (stmf_i_scsi_session_t *)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_TASK_FREE, CMD_OR_IOF_NA, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_task_bufs(itask, lport);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_task_done(itask);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE2(stmf__task__end, scsi_task_t *, task,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto hrtime_t,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_done_timestamp - itask->itask_start_timestamp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_itl_datap) {
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek if (atomic_dec_32_nv(&itask->itask_itl_datap->itl_counter) ==
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_release_itl_handle(task->task_lu,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv itask->itask_itl_datap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte rw_enter(iss->iss_lockp, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_task_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_worker) {
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(&stmf_cur_ntasks);
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(&itask->itask_worker->worker_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * After calling stmf_task_lu_free, the task pointer can no longer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be trusted.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_task_lu_free(task, iss);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_post_task(scsi_task_t *task, stmf_data_buf_t *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = (stmf_i_scsi_task_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w, *w1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t tm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_max_nbufs > 4)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_max_nbufs = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cur_nbufs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Latest value of currently running tasks */
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek ct = atomic_inc_32_nv(&stmf_cur_ntasks);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Select the next worker using round robin */
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek nv = (int)atomic_inc_32_nv((uint32_t *)&stmf_worker_sel_counter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nv >= stmf_nworkers_accepting_cmds) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int s = nv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nv -= stmf_nworkers_accepting_cmds;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (nv >= stmf_nworkers_accepting_cmds);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nv < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nv = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Its ok if this cas fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) atomic_cas_32((uint32_t *)&stmf_worker_sel_counter,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s, nv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = &stmf_workers[nv];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A worker can be pinned by interrupt. So select the next one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it has lower load.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nv + 1) >= stmf_nworkers_accepting_cmds) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w1 = stmf_workers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w1 = &stmf_workers[nv + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w1->worker_queue_depth < w->worker_queue_depth)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = w1;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((w->worker_flags & STMF_WORKER_STARTED) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (w->worker_flags & STMF_WORKER_TERMINATE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Maybe we are in the middle of a change. Just go to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the 1st worker.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = stmf_workers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker = w;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Track max system load inside the worker as we already have the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * worker lock (no point implementing another lock). The service
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * thread will do the comparisons and figure out the max overall
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * system load.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_max_sys_qdepth_pu < ct)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_sys_qdepth_pu = ct;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_KNOWN_TO_TGT_PORT | ITASK_IN_WORKER_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tm = task->task_mgmt_function;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tm == TM_TARGET_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tm == TM_TARGET_COLD_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tm == TM_TARGET_WARM_RESET)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_DEFAULT_HANDLING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (task->task_cdb[0] == SCMD_REPORT_LUNS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_DEFAULT_HANDLING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_IN_TRANSITION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_task_start(itask);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Measure task waitq time */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_waitq_enter_timestamp = gethrtime();
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_32(&w->worker_ref_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cmd_stack[0] = ITASK_CMD_NEW_TASK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_ncmds = 1;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_TASK_START, CMD_OR_IOF_NA, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_allocated_buf_map = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_dbufs[0] = dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_handle = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_allocated_buf_map = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_dbufs[0] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto w->worker_signal_timestamp = gethrtime();
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE2(worker__signal, stmf_worker_t *, w,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_task_t *, task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This can only happen if during stmf_task_alloc(), ILU_RESET_ACTIVE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * was set between checking of ILU_RESET_ACTIVE and clearing of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ITASK_IN_FREE_LIST flag. Take care of these "sneaked-in" tasks here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task, STMF_ABORTED, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Fortestatic void
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Fortestmf_task_audit(stmf_i_scsi_task_t *itask,
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte task_audit_event_t te, uint32_t cmd_or_iof, stmf_data_buf_t *dbuf)
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte{
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit_rec_t *ar;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte mutex_enter(&itask->itask_audit_mutex);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ar = &itask->itask_audit_records[itask->itask_audit_index++];
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte itask->itask_audit_index &= (ITASK_TASK_AUDIT_DEPTH - 1);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ar->ta_event = te;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ar->ta_cmd_or_iof = cmd_or_iof;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ar->ta_itask_flags = itask->itask_flags;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ar->ta_dbuf = dbuf;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte gethrestime(&ar->ta_timestamp);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte mutex_exit(&itask->itask_audit_mutex);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte}
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ++++++++++++++ ABORT LOGIC ++++++++++++++++++++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Once ITASK_BEING_ABORTED is set, ITASK_KNOWN_TO_LU can be reset already
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i.e. before ITASK_BEING_ABORTED being set. But if it was not, it cannot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be reset until the LU explicitly calls stmf_task_lu_aborted(). Of course
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the LU will make this call only if we call the LU's abort entry point.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we will only call that entry point if ITASK_KNOWN_TO_LU was set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Same logic applies for the port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Also ITASK_BEING_ABORTED will not be allowed to set if both KNOWN_TO_LU
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and KNOWN_TO_TGT_PORT are reset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +++++++++++++++++++++++++++++++++++++++++++++++
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_xfer_data(scsi_task_t *task, stmf_data_buf_t *dbuf, uint32_t ioflags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_status_t ret = STMF_SUCCESS;
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_XFER_START, ioflags, dbuf);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioflags & STMF_IOF_LU_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new, old;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (new & ITASK_BEING_ABORTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_KNOWN_TO_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & ITASK_BEING_ABORTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (!(ioflags & STMF_IOF_STATS_ONLY) && stmf_drop_buf_counter > 0) {
9c68c0524222ca5eac2fb0835154553c1cdaa96cJosef 'Jeff' Sipek if (atomic_dec_32_nv(&stmf_drop_buf_counter) == 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_update_kstat_lu_io(task, dbuf);
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto stmf_update_kstat_lport_io(task, dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_lport_xfer_start(itask, dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (ioflags & STMF_IOF_STATS_ONLY) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_lport_xfer_done(itask, dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return (STMF_SUCCESS);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte dbuf->db_flags |= DB_LPORT_XFER_ACTIVE;
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto ret = task->task_lport->lport_xfer_data(task, dbuf, ioflags);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * Port provider may have already called the buffer callback in
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * which case dbuf->db_xfer_start_timestamp will be 0.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte if (ret != STMF_SUCCESS) {
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte dbuf->db_flags &= ~DB_LPORT_XFER_ACTIVE;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte if (dbuf->db_xfer_start_timestamp != 0)
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_lport_xfer_done(itask, dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_data_xfer_done(scsi_task_t *task, stmf_data_buf_t *dbuf, uint32_t iof)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = itask->itask_worker;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new, old;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto uint8_t update_queue_flags, free_it, queue_it;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_lport_xfer_done(itask, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_XFER_DONE, iof, dbuf);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte /* Guard against unexpected completions from the lport */
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte if (dbuf->db_flags & DB_LPORT_XFER_ACTIVE) {
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte dbuf->db_flags &= ~DB_LPORT_XFER_ACTIVE;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte } else {
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte /*
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte * This should never happen.
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte */
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ilport = task->task_lport->lport_stmf_private;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte ilport->ilport_unexpected_comp++;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte cmn_err(CE_PANIC, "Unexpected xfer completion task %p dbuf %p",
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte (void *)task, (void *)dbuf);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte return;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte }
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_BEING_ABORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iof & STMF_IOF_LPORT_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_KNOWN_TO_TGT_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_completion_status = dbuf->db_xfer_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the task is known to LU then queue it. But if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is already queued (multiple completions) then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just update the buffer information by grabbing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * worker lock. If the task is not known to LU,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * completed/aborted, then see if we need to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free this task.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_KNOWN_TO_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update_queue_flags = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_IN_WORKER_QUEUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_it = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_IN_WORKER_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update_queue_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (update_queue_flags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t cmd = (dbuf->db_handle << 5) | ITASK_CMD_DATA_XFER_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itask->itask_ncmds < ITASK_MAX_NCMDS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cmd_stack[itask->itask_ncmds++] = cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (queue_it) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Measure task waitq time */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_waitq_enter_timestamp = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (free_it) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & (ITASK_KNOWN_TO_LU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_TGT_PORT | ITASK_IN_WORKER_QUEUE |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_BEING_ABORTED)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_send_scsi_status(scsi_task_t *task, uint32_t ioflags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE1(scsi__send__status, scsi_task_t *, task);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_scsi_task_t *)task->task_stmf_private;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_SEND_STATUS, ioflags, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioflags & STMF_IOF_LU_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new, old;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (new & ITASK_BEING_ABORTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_KNOWN_TO_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(itask->itask_flags & ITASK_KNOWN_TO_TGT_PORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & ITASK_BEING_ABORTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags & TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_status_ctrl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_resid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (task->task_cmd_xfer_length >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_status_ctrl = TASK_SCTRL_OVER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_resid = task->task_cmd_xfer_length -
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_expected_xfer_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (task->task_nbytes_transferred <
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_expected_xfer_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_status_ctrl = TASK_SCTRL_UNDER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_resid = task->task_expected_xfer_length -
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_nbytes_transferred;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_status_ctrl = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_resid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (task->task_lport->lport_send_status(task, ioflags));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_send_status_done(scsi_task_t *task, stmf_status_t s, uint32_t iof)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = itask->itask_worker;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new, old;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto uint8_t free_it, queue_it;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_SEND_STATUS_DONE, iof, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_BEING_ABORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iof & STMF_IOF_LPORT_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_KNOWN_TO_TGT_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the task is known to LU then queue it. But if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it is already queued (multiple completions) then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just update the buffer information by grabbing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * worker lock. If the task is not known to LU,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * completed/aborted, then see if we need to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free this task.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_KNOWN_TO_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_it = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_IN_WORKER_QUEUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "status completion received"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " when task is already in worker queue "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " task = %p", (void *)task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_IN_WORKER_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queue_it = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_completion_status = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (queue_it) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itask->itask_ncmds < ITASK_MAX_NCMDS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cmd_stack[itask->itask_ncmds++] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_CMD_STATUS_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* Measure task waitq time */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_waitq_enter_timestamp = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (free_it) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & (ITASK_KNOWN_TO_LU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_TGT_PORT | ITASK_IN_WORKER_QUEUE |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_BEING_ABORTED)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "LU is done with the task but LPORT "
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte " is not done, itask %p itask_flags %x",
437be37266d159c6a27c02e61710a578bef3d15fJohn Forte (void *)itask, itask->itask_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_lu_done(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = itask->itask_worker;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new, old;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_BEING_ABORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_IN_WORKER_QUEUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "task_lu_done received"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " when task is in worker queue "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " task = %p", (void *)task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~ITASK_KNOWN_TO_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & (ITASK_KNOWN_TO_LU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_TGT_PORT | ITASK_IN_WORKER_QUEUE |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_BEING_ABORTED)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "stmf_lu_done should be the last stage but "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " the task is still not done, task = %p", (void *)task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_queue_task_for_abort(scsi_task_t *task, stmf_status_t s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_TASK_ABORT, CMD_OR_IOF_NA, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((old & ITASK_BEING_ABORTED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((old & (ITASK_KNOWN_TO_TGT_PORT |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_LU)) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_BEING_ABORTED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_completion_status = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_start_time = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((w = itask->itask_worker) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (itask->itask_flags & ITASK_IN_TRANSITION)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Queue it and get out */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & ITASK_IN_WORKER_QUEUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&itask->itask_flags, ITASK_IN_WORKER_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_abort(int abort_cmd, scsi_task_t *task, stmf_status_t s, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t old, new, f, rf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE2(scsi__task__abort, scsi_task_t *, task,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto stmf_status_t, s);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (abort_cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_QUEUE_ABORT_LU:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_lu_killall((stmf_lu_t *)arg, task, s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_QUEUE_TASK_ABORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_queue_task_for_abort(task, s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_REQUEUE_TASK_ABORT_LPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rf = ITASK_TGT_PORT_ABORT_CALLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte f = ITASK_KNOWN_TO_TGT_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_REQUEUE_TASK_ABORT_LU:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rf = ITASK_LU_ABORT_CALLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte f = ITASK_KNOWN_TO_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte f |= ITASK_BEING_ABORTED | rf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((old & f) != f) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new &= ~rf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_lu_aborted(scsi_task_t *task, stmf_status_t s, uint32_t iof)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char info[STMF_CHANGE_INFO_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = TASK_TO_ITASK(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long long st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_TASK_LU_ABORTED, iof, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = s; /* gcc fix */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((s != STMF_ABORT_SUCCESS) && (s != STMF_NOT_FOUND)) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "task %p, lu failed to abort ret=%llx", (void *)task, st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((iof & STMF_IOF_LU_DONE) == 0) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Task aborted but LU is not finished, task ="
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%p, s=%llx, iof=%x", (void *)task, st, iof);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LU abort successfully
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&itask->itask_flags, ~ITASK_KNOWN_TO_LU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(task, 1, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_lport_aborted(scsi_task_t *task, stmf_status_t s, uint32_t iof)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto char info[STMF_CHANGE_INFO_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = TASK_TO_ITASK(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long long st;
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto uint32_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_TASK_LPORT_ABORTED, iof, NULL);
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((s != STMF_ABORT_SUCCESS) && (s != STMF_NOT_FOUND)) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "task %p, tgt port failed to abort ret=%llx", (void *)task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((iof & STMF_IOF_LPORT_DONE) == 0) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Task aborted but tgt port is not finished, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "task=%p, s=%llx, iof=%x", (void *)task, st, iof);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto * LPORT abort successfully
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto do {
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto old = new = itask->itask_flags;
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto if (!(old & ITASK_KNOWN_TO_TGT_PORT))
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto return;
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto new &= ~ITASK_KNOWN_TO_TGT_PORT;
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(task, 0, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_poll_lu(scsi_task_t *task, uint32_t timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = (stmf_i_scsi_task_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = itask->itask_worker;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itask->itask_flags & ITASK_KNOWN_TO_LU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_ncmds >= ITASK_MAX_NCMDS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < itask->itask_ncmds; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_cmd_stack[i] == ITASK_CMD_POLL_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cmd_stack[itask->itask_ncmds++] = ITASK_CMD_POLL_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (timeout == ITASK_DEFAULT_POLL_TIMEOUT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_poll_timeout = ddi_get_lbolt() + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t t = drv_usectohz(timeout * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_poll_timeout = ddi_get_lbolt() + t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & ITASK_IN_WORKER_QUEUE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&itask->itask_flags, ITASK_IN_WORKER_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_task_poll_lport(scsi_task_t *task, uint32_t timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = (stmf_i_scsi_task_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = itask->itask_worker;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itask->itask_flags & ITASK_KNOWN_TO_TGT_PORT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_ncmds >= ITASK_MAX_NCMDS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < itask->itask_ncmds; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_cmd_stack[i] == ITASK_CMD_POLL_LPORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_cmd_stack[itask->itask_ncmds++] = ITASK_CMD_POLL_LPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (timeout == ITASK_DEFAULT_POLL_TIMEOUT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_poll_timeout = ddi_get_lbolt() + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t t = drv_usectohz(timeout * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_poll_timeout = ddi_get_lbolt() + t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & ITASK_IN_WORKER_QUEUE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_max_qdepth_pu = w->worker_queue_depth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_do_task_abort(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask = TASK_TO_ITASK(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_local_port_t *lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long long ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t call_lu_abort, call_port_abort;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char info[STMF_CHANGE_INFO_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = task->task_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport = task->task_lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((old & (ITASK_KNOWN_TO_LU | ITASK_LU_ABORT_CALLED)) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_LU_ABORT_CALLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte call_lu_abort = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte call_lu_abort = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (call_lu_abort) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & ITASK_DEFAULT_HANDLING) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = lu->lu_abort(lu, STMF_LU_ABORT_TASK, task, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = dlun0->lu_abort(lu, STMF_LU_ABORT_TASK, task, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret == STMF_ABORT_SUCCESS) || (ret == STMF_NOT_FOUND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_lu_aborted(task, ret, STMF_IOF_LU_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret == STMF_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&itask->itask_flags,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~ITASK_LU_ABORT_CALLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret != STMF_SUCCESS) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Abort failed by LU %p, ret %llx", (void *)lu, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(task, 1, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (itask->itask_flags & ITASK_KNOWN_TO_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() > (itask->itask_start_time +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SEC2TICK(lu->lu_abort_timeout?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_abort_timeout : ITASK_DEFAULT_ABORT_TIMEOUT))) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "lu abort timed out");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(itask->itask_task, 1, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = new = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((old & (ITASK_KNOWN_TO_TGT_PORT |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_TGT_PORT_ABORT_CALLED)) == ITASK_KNOWN_TO_TGT_PORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new |= ITASK_TGT_PORT_ABORT_CALLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte call_port_abort = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte call_port_abort = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (call_port_abort) {
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ret = lport->lport_abort(lport, STMF_LPORT_ABORT_TASK, task, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret == STMF_ABORT_SUCCESS) || (ret == STMF_NOT_FOUND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_lport_aborted(task, ret, STMF_IOF_LPORT_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret == STMF_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&itask->itask_flags,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~ITASK_TGT_PORT_ABORT_CALLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret != STMF_SUCCESS) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Abort failed by tgt port %p ret %llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)lport, ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(task, 0, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (itask->itask_flags & ITASK_KNOWN_TO_TGT_PORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() > (itask->itask_start_time +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SEC2TICK(lport->lport_abort_timeout?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lport->lport_abort_timeout :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_DEFAULT_ABORT_TIMEOUT))) {
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan (void) snprintf(info, sizeof (info),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "lport abort timed out");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_task_offline(itask->itask_task, 0, info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_ctl(int cmd, void *obj, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_change_info_t *ssci = (stmf_state_change_info_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_INVALID_ARG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd & STMF_CMD_LU_OP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = stmf_lookup_lu((stmf_lu_t *)obj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE3(lu__state__change,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto stmf_lu_t *, ilu->ilu_lu,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto int, cmd, stmf_state_change_info_t *, ssci);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cmd & STMF_CMD_LPORT_OP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_lookup_lport((stmf_local_port_t *)obj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE3(lport__state__change,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto stmf_local_port_t *, ilport->ilport_lport,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto int, cmd, stmf_state_change_info_t *, ssci);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan switch (ilu->ilu_state) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_SUCCESS;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_ALREADY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BUSY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan default:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan if (ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_queue(cmd, obj, (stmf_state_change_info_t *)arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_ONLINE_COMPLETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_state != STMF_STATE_ONLINING) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_change_status_t *)arg)->st_completion_status ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_lu_t *)obj)->lu_ctl((stmf_lu_t *)obj,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ACK_LU_ONLINE_COMPLETE, arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lu_to_active_sessions((stmf_lu_t *)obj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* XXX: should throw a meesage an record more data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan switch (ilu->ilu_state) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_SUCCESS;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_ALREADY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BUSY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan default:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan if (ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_OFFLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_queue(cmd, obj, (stmf_state_change_info_t *)arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_OFFLINE_COMPLETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_state != STMF_STATE_OFFLINING) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_change_status_t *)arg)->st_completion_status ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_lu_t *)obj)->lu_ctl((stmf_lu_t *)obj,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ACK_LU_OFFLINE_COMPLETE, arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lu_to_active_sessions((stmf_lu_t *)obj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LPORT_ONLINE/OFFLINE has nothing to do with link offline/online.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It's related with hardware disable/enable.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan switch (ilport->ilport_state) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_SUCCESS;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_ALREADY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BUSY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan default:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan if (ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only user request can recover the port from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * FORCED_OFFLINE state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_flags & ILPORT_FORCED_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(ssci->st_rflags & STMF_RFLAG_USER_REQUEST)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Avoid too frequent request to online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ssci->st_rflags & STMF_RFLAG_USER_REQUEST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_online_times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_avg_interval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ilport->ilport_avg_interval < STMF_AVG_ONLINE_INTERVAL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ilport->ilport_online_times >= 4)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_flags |= ILPORT_FORCED_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace(NULL, "stmf_ctl: too frequent request to "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "online the port");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "stmf_ctl: too frequent request to "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "online the port, set FORCED_OFFLINE now");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_online_times > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_online_times == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_avg_interval = ddi_get_lbolt() -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_last_online_clock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_avg_interval =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ilport->ilport_avg_interval +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_get_lbolt() -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_last_online_clock) >> 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_last_online_clock = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_online_times++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Submit online service request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_flags &= ~ILPORT_FORCED_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_queue(cmd, obj, (stmf_state_change_info_t *)arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_ONLINE_COMPLETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_ONLINING) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_change_status_t *)arg)->st_completion_status ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_local_port_t *)obj)->lport_ctl(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_local_port_t *)obj,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ACK_LPORT_ONLINE_COMPLETE, arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan switch (ilport->ilport_state) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_SUCCESS;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINE:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_OFFLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_ALREADY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan case STMF_STATE_ONLINING:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BUSY;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan default:
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan if (ret != STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_OFFLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_queue(cmd, obj, (stmf_state_change_info_t *)arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_OFFLINE_COMPLETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_OFFLINING) {
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan ret = STMF_BADSTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_change_status_t *)arg)->st_completion_status ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stmf_local_port_t *)obj)->lport_ctl(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_local_port_t *)obj,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ACK_LPORT_OFFLINE_COMPLETE, arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "Invalid ctl cmd received %x", cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_INVALID_ARG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_ctl_lock_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_ctl_lock_exit:;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_info_impl(uint32_t cmd, void *arg1, void *arg2, uint8_t *buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *bufsizep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_SUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_info(uint32_t cmd, void *arg1, void *arg2, uint8_t *buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *bufsizep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cl = SI_GET_CLASS(cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl == SI_STMF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (stmf_info_impl(cmd, arg1, arg2, buf, bufsizep));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl == SI_LPORT) {
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv return (((stmf_local_port_t *)arg1)->lport_info(cmd, arg1,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv arg2, buf, bufsizep));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl == SI_LU) {
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv return (((stmf_lu_t *)arg1)->lu_info(cmd, arg1, arg2, buf,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv bufsizep));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_SUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States * Used by port providers. pwwn is 8 byte wwn, sdid is the devid used by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmf to register local ports. The ident should have 20 bytes in buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * space to convert the wwn to "wwn.xxxxxxxxxxxxxxxx" string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_wwn_to_devid_desc(scsi_devid_desc_t *sdid, uint8_t *wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t protocol_id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States char wwn_str[20+1];
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdid->protocol_id = protocol_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdid->piv = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdid->code_set = CODE_SET_ASCII;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdid->association = ID_IS_TARGET_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdid->ident_length = 20;
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Convert wwn value to "wwn.XXXXXXXXXXXXXXXX" format */
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) snprintf(wwn_str, sizeof (wwn_str),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "wwn.%02X%02X%02X%02X%02X%02X%02X%02X",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn[0], wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]);
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(wwn_str, (char *)sdid->ident, 20);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
70c284ca5360ed73476d9e94223d4905dd80b1adPeter Cudhea - Sun Microsystems - Burlington, MA United States
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_xfer_data_t *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestmf_prepare_tpgs_data(uint8_t ilu_alua)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t sz, asz, nports = 0, nports_standby = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* check if any ports are standby and create second group */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = ilport->ilport_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilport->ilport_standby == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte nports_standby++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte nports++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* The spec only allows for 255 ports to be reported per group */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte nports = min(nports, 255);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte nports_standby = min(nports_standby, 255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = (nports * 4) + 12;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (nports_standby && ilu_alua) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sz += (nports_standby * 4) + 8;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte asz = sz + sizeof (*xd) - 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = (stmf_xfer_data_t *)kmem_zalloc(asz, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->alloc_size = asz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_left = sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = xd->buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *((uint32_t *)p) = BE_32(sz - 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = 0x80; /* PREF */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[1] = 5; /* AO_SUP, S_SUP */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_node == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[3] = 1; /* Group 1 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[3] = 0; /* Group 0 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[7] = nports & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p += 8;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = ilport->ilport_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilport->ilport_standby == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint16_t *)p)[1] = BE_16(ilport->ilport_rtpid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p += 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (nports_standby && ilu_alua) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[0] = 0x02; /* Non PREF, Standby */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[1] = 5; /* AO_SUP, S_SUP */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_state.stmf_alua_node == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[3] = 0; /* Group 0 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[3] = 1; /* Group 1 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[7] = nports_standby & 0xff;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p += 8;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = ilport->ilport_next) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilport->ilport_standby == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ((uint16_t *)p)[1] = BE_16(ilport->ilport_rtpid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p += 4;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostruct scsi_devid_desc *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmf_scsilib_get_devid_desc(uint16_t rtpid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scsi_devid_desc_t *devid = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_i_local_port_t *ilport;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (ilport = stmf_state.stmf_ilportlist; ilport;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ilport = ilport->ilport_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ilport->ilport_rtpid == rtpid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scsi_devid_desc_t *id = ilport->ilport_lport->lport_id;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint32_t id_sz = sizeof (scsi_devid_desc_t) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id->ident_length;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto devid = (scsi_devid_desc_t *)kmem_zalloc(id_sz,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto KM_NOSLEEP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (devid != NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(id, devid, id_sz);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (devid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetouint16_t
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmf_scsilib_get_lport_rtid(struct scsi_devid_desc *devid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_i_local_port_t *ilport;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scsi_devid_desc_t *id;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint16_t rtpid = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (ilport = stmf_state.stmf_ilportlist; ilport;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ilport = ilport->ilport_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto id = ilport->ilport_lport->lport_id;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((devid->ident_length == id->ident_length) &&
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (memcmp(devid->ident, id->ident, id->ident_length) == 0)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto rtpid = ilport->ilport_rtpid;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&stmf_state.stmf_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (rtpid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint16_t stmf_lu_id_gen_number = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_scsilib_uniq_lu_id(uint32_t company_id, scsi_devid_desc_t *lu_id)
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte{
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte return (stmf_scsilib_uniq_lu_id2(company_id, 0, lu_id));
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte}
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Fortestmf_status_t
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Fortestmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte scsi_devid_desc_t *lu_id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval32 timestamp32;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *t = (uint32_t *)&timestamp32;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ether_addr mac;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *e = (uint8_t *)&mac;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte int hid = (int)host_id;
57ff5e7e2f79bd09ccd01cdeba02f38fdde17a80Jeff Biseda uint16_t gen_number;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (company_id == COMPANY_ID_NONE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte company_id = COMPANY_ID_SUN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu_id->ident_length != 0x10)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (uint8_t *)lu_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek gen_number = atomic_inc_16_nv(&stmf_lu_id_gen_number);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = 0xf1; p[1] = 3; p[2] = 0; p[3] = 0x10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[4] = ((company_id >> 20) & 0xf) | 0x60;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[5] = (company_id >> 12) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[6] = (company_id >> 4) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[7] = (company_id << 4) & 0xf0;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (hid == 0 && !localetheraddr((struct ether_addr *)NULL, &mac)) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte hid = BE_32((int)zone_get_hostid(NULL));
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (hid != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e[0] = (hid >> 24) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e[1] = (hid >> 16) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e[2] = (hid >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e[3] = hid & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e[4] = e[5] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(e, p+8, 6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uniqtime32(&timestamp32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *t = BE_32(*t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(t, p+14, 4);
57ff5e7e2f79bd09ccd01cdeba02f38fdde17a80Jeff Biseda p[18] = (gen_number >> 8) & 0xff;
57ff5e7e2f79bd09ccd01cdeba02f38fdde17a80Jeff Biseda p[19] = gen_number & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * saa is sense key, ASC, ASCQ
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_scsilib_send_status(scsi_task_t *task, uint8_t st, uint32_t saa)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t sd[18];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_scsi_status = st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (st == 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(sd, 18);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd[0] = 0x70;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd[2] = (saa >> 16) & 0xf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd[7] = 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd[12] = (saa >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd[13] = saa & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_sense_data = sd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_sense_length = 18;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_sense_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_sense_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_send_scsi_status(task, STMF_IOF_LU_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_scsilib_prepare_vpd_page83(scsi_task_t *task, uint8_t *page,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t page_len, uint8_t byte0, uint32_t vpd_mask)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t small_buf[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t sz = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t n = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t m = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t last_bit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (page_len < 4)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (page_len > 65535)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page_len = 65535;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page[0] = byte0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page[1] = 0x83;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte m += sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sz && (page_len > n)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t copysz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copysz = page_len > (n + sz) ? sz : page_len - n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(p, page + n, copysz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n += copysz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vpd_mask &= ~last_bit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vpd_mask == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vpd_mask & STMF_VPD_LU_ID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_bit = STMF_VPD_LU_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = task->task_lu->lu_id->ident_length + 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (uint8_t *)task->task_lu->lu_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (vpd_mask & STMF_VPD_TARGET_ID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_bit = STMF_VPD_TARGET_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = task->task_lport->lport_id->ident_length + 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (uint8_t *)task->task_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (vpd_mask & STMF_VPD_TP_GROUP) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_bit = STMF_VPD_TP_GROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = small_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(p, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[1] = 0x15;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = 4;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ilport = (stmf_i_local_port_t *)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_lport->lport_stmf_private;
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte /*
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte * If we're in alua mode, group 1 contains all alua
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte * participating ports and all standby ports
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte * > 255. Otherwise, if we're in alua mode, any local
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte * ports (non standby/pppt) are also in group 1 if the
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte * alua node is 1. Otherwise the group is 0.
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte */
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte if ((stmf_state.stmf_alua_state &&
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte (ilport->ilport_alua || ilport->ilport_standby) &&
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte ilport->ilport_rtpid > 255) ||
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte (stmf_state.stmf_alua_node == 1 &&
94d9b8e175557451537bf7b214abfc1cd7e52a90John Forte ilport->ilport_standby != 1)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte p[7] = 1; /* Group 1 */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (vpd_mask & STMF_VPD_RELATIVE_TP_ID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte last_bit = STMF_VPD_RELATIVE_TP_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = small_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(p, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[1] = 0x14;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = (stmf_i_local_port_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[6] = (ilport->ilport_rtpid >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[7] = ilport->ilport_rtpid & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "Invalid vpd_mask");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page[2] = (m >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page[3] = m & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_scsilib_handle_report_tpgs(scsi_task_t *task, stmf_data_buf_t *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_scsi_task_t *)task->task_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_lu_t *ilu =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t sz, minsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_flags |= ITASK_DEFAULT_HANDLING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((((uint32_t)task->task_cdb[6]) << 24) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uint32_t)task->task_cdb[7]) << 16) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uint32_t)task->task_cdb[8]) << 8) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint32_t)task->task_cdb[9]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
729dd25c639d07bd7cb8a85466d8d1dc9af10d0cWayne Ihde if (task->task_cmd_xfer_length == 0) {
729dd25c639d07bd7cb8a85466d8d1dc9af10d0cWayne Ihde stmf_scsilib_send_status(task, STATUS_GOOD, 0);
729dd25c639d07bd7cb8a85466d8d1dc9af10d0cWayne Ihde return;
729dd25c639d07bd7cb8a85466d8d1dc9af10d0cWayne Ihde }
729dd25c639d07bd7cb8a85466d8d1dc9af10d0cWayne Ihde if (task->task_cmd_xfer_length < 4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(task->task_expected_xfer_length,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte xd = stmf_prepare_tpgs_data(ilu->ilu_alua);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(sz, xd->size_left);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_left = sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsz = min(512, sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, sz, &minsz, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(xd, xd->alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_lu_private = xd;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte stmf_xd_to_dbuf(dbuf, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_scsilib_handle_task_mgmt(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For now we will abort all I/Os on the LU in case of ABORT_TASK_SET
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and ABORT_TASK. But unlike LUN_RESET we will not reset LU state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in these cases. This needs to be changed to abort only the required
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_CLEAR_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_LUN_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_handle_lun_reset(task);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* issue the reset to the proxy node as well */
7beff157537d14493d525a42d33f0621b0b26217John Forte if (stmf_state.stmf_alua_state == 1) {
7beff157537d14493d525a42d33f0621b0b26217John Forte (void) stmf_proxy_scsi_cmd(task, NULL);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_COLD_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_WARM_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_handle_target_reset(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We dont support this task mgmt function */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CMD_IU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_handle_lun_reset(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * To sync with target reset, grab this lock. The LU is not going
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * anywhere as there is atleast one task pending (this task).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_SAA_OPERATION_IN_PROGRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&ilu->ilu_flags, ILU_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Mark this task as the one causing LU reset so that we know who
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * was responsible for setting the ILU_RESET_ACTIVE. In case this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * task itself gets aborted, we will clear ILU_RESET_ACTIVE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_flags |= ITASK_DEFAULT_HANDLING | ITASK_CAUSING_LU_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initiatiate abort on all commands on this LU except this one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_ABORT_LU, task, STMF_ABORTED, task->task_lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Start polling on this task */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_task_poll_lu(task, ITASK_DEFAULT_POLL_TIMEOUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task, STMF_ALLOC_FAILURE,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_handle_target_reset(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *lm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lm_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, lf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * To sync with LUN reset, grab this lock. The session is not going
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * anywhere as there is atleast one task pending (this task).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta /* Grab the session lock as a writer to prevent any changes in it */
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta rw_enter(iss->iss_lockp, RW_WRITER);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_flags & ISS_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_SAA_OPERATION_IN_PROGRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&iss->iss_flags, ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now go through each LUN in this session and make sure all of them
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * can be reset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0, lf = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lf++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm_ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)(lm_ent->ent_lu->lu_stmf_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags, ~ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_SAA_OPERATION_IN_PROGRESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lf == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No luns in this session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags, ~ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ok, start the damage */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_flags |= ITASK_DEFAULT_HANDLING |
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ITASK_CAUSING_TARGET_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm_ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)(lm_ent->ent_lu->lu_stmf_private);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&ilu->ilu_flags, ILU_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm_ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_ABORT_LU, task, STMF_ABORTED,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv lm_ent->ent_lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto rw_exit(iss->iss_lockp);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto mutex_exit(&stmf_state.stmf_lock);
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Start polling on this task */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_task_poll_lu(task, ITASK_DEFAULT_POLL_TIMEOUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task, STMF_ALLOC_FAILURE,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_handle_cmd_during_ic(stmf_i_scsi_task_t *itask)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task = itask->itask_task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss = (stmf_i_scsi_session_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((iss->iss_flags & ISS_LUN_INVENTORY_CHANGED) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_cdb[0] == SCMD_INQUIRY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ~(ISS_LUN_INVENTORY_CHANGED | ISS_GOT_INITIAL_LUNS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_cdb[0] == SCMD_REPORT_LUNS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_REPORT_LUN_DATA_HAS_CHANGED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_worker_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Make local copy of global tunables */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_max_nworkers = stmf_max_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_min_nworkers = stmf_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(stmf_workers == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_i_min_nworkers < 4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_min_nworkers = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_i_max_nworkers < stmf_i_min_nworkers) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_max_nworkers = stmf_i_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers = (stmf_worker_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_worker_t) * stmf_i_max_nworkers, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < stmf_i_max_nworkers; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = &stmf_workers[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&w->worker_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&w->worker_cv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_mgmt_delay = drv_usectohz(20 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers_state = STMF_WORKERS_ENABLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Workers will be started by stmf_worker_mgmt() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Lets wait for atleast one worker to start */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (stmf_nworkers_cur == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(20 * 1000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_mgmt_delay = drv_usectohz(3 * 1000 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_worker_fini()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t sb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_workers_state == STMF_WORKERS_DISABLED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(stmf_workers);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers_state = STMF_WORKERS_DISABLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_mgmt_delay = drv_usectohz(20 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sb = ddi_get_lbolt() + drv_usectohz(10 * 1000 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wait for all the threads to die */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (stmf_nworkers_cur != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() > sb) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers_state = STMF_WORKERS_ENABLED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(100 * 1000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < stmf_i_max_nworkers; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w = &stmf_workers[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stmf_workers, sizeof (stmf_worker_t) * stmf_i_max_nworkers);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_worker_task(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t wait_timer = 0;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni clock_t wait_ticks, wait_delta = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t old, new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t curcmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t abort_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t wait_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t dec_qdepth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = (stmf_worker_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_ticks = drv_usectohz(10000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE1(worker__create, stmf_worker_t, w);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_flags |= STMF_WORKER_STARTED | STMF_WORKER_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_worker_loop:;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_ref_count == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (w->worker_flags & STMF_WORKER_TERMINATE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_flags &= ~(STMF_WORKER_STARTED |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_WORKER_ACTIVE | STMF_WORKER_TERMINATE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_tid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE1(worker__destroy, stmf_worker_t, w);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thread_exit();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dec_qdepth = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wait_timer && (ddi_get_lbolt() >= wait_timer)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_timer = 0;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni wait_delta = 0;
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta if (w->worker_wait_head) {
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta ASSERT(w->worker_wait_tail);
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta if (w->worker_task_head == NULL)
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta w->worker_task_head =
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta w->worker_wait_head;
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta else
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta w->worker_task_tail->itask_worker_next =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv w->worker_wait_head;
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta w->worker_task_tail = w->worker_wait_tail;
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta w->worker_wait_head = w->worker_wait_tail =
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta NULL;
d6b3018d1023e158e4d4f1315056f98b55c6f590Sumit Gupta }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask = w->worker_task_head) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task = itask->itask_task;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE2(worker__active, stmf_worker_t, w,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_task_t *, task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask->itask_worker_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_head == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_queue = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte abort_free = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_ncmds > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curcmd = itask->itask_cmd_stack[itask->itask_ncmds - 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itask->itask_flags & ITASK_BEING_ABORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old = itask->itask_flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old & ITASK_BEING_ABORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_ncmds = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curcmd = itask->itask_cmd_stack[0] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_CMD_ABORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out_itask_flag_loop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((curcmd & ITASK_CMD_MASK) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_CMD_NEW_TASK) {
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto /*
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto * set ITASK_KSTAT_IN_RUNQ, this flag
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto * will not reset until task completed
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto */
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto new = old | ITASK_KNOWN_TO_LU |
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto ITASK_KSTAT_IN_RUNQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out_itask_flag_loop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (atomic_cas_32(&itask->itask_flags, old, new) != old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout_itask_flag_loop:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Decide if this task needs to go to a queue and/or if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we can decrement the itask_cmd_stack.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (curcmd == ITASK_CMD_ABORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (itask->itask_flags & (ITASK_KNOWN_TO_LU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ITASK_KNOWN_TO_TGT_PORT)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_queue = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte abort_free = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((curcmd & ITASK_CMD_POLL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (itask->itask_poll_timeout > ddi_get_lbolt())) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_queue = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wait_queue) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_wait_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_wait_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_wait_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_wait_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wait_timer == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_timer = ddi_get_lbolt() + wait_ticks;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni wait_delta = wait_ticks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((--(itask->itask_ncmds)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask->itask_worker_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_task_tail) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail->itask_worker_next = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_head = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_task_tail = itask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&itask->itask_flags,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ~ITASK_IN_WORKER_QUEUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is where the queue depth should go down by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one but we delay that on purpose to account for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the call into the provider. The actual decrement
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * happens after the worker has done its job.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dec_qdepth = 1;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_waitq_time +=
427fcaf873956aad428be801380a44e59d38b8b5tim szeto gethrtime() - itask->itask_waitq_enter_timestamp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We made it here means we are going to call LU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((itask->itask_flags & ITASK_DEFAULT_HANDLING) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = task->task_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = dlun0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = itask->itask_dbufs[ITASK_CMD_BUF_NDX(curcmd)];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curcmd &= ITASK_CMD_MASK;
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte stmf_task_audit(itask, TE_PROCESS_CMD, curcmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (curcmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_NEW_TASK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session->ss_stmf_private;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_lu_new_task(itask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_flags & ISS_LUN_INVENTORY_CHANGED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_handle_cmd_during_ic(itask))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_drop_task_counter > 0) {
9c68c0524222ca5eac2fb0835154553c1cdaa96cJosef 'Jeff' Sipek if (atomic_dec_32_nv(&stmf_drop_task_counter)
9c68c0524222ca5eac2fb0835154553c1cdaa96cJosef 'Jeff' Sipek == 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE1(scsi__task__start, scsi_task_t *, task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_new_task(task, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_DATA_XFER_DONE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_dbuf_xfer_done(task, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_STATUS_DONE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_send_status_done(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_ABORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abort_free) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_free(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_task_abort(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_POLL_LU:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!wait_queue) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu->lu_task_poll(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_POLL_LPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!wait_queue)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lport->lport_task_poll(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ITASK_CMD_SEND_STATUS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* case ITASK_CMD_XFER_DATA: */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dec_qdepth) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_queue_depth--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_TERMINATE) && (wait_timer == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (w->worker_ref_count == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_worker_loop;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_timer = ddi_get_lbolt() + 1;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni wait_delta = 1;
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_flags &= ~STMF_WORKER_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wait_timer) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE1(worker__timed__sleep, stmf_worker_t, w);
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni (void) cv_reltimedwait(&w->worker_cv, &w->worker_lock,
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni wait_delta, TR_CLOCK_TICK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE1(worker__sleep, stmf_worker_t, w);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&w->worker_cv, &w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE1(worker__wakeup, stmf_worker_t, w);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_flags |= STMF_WORKER_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto stmf_worker_loop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_worker_mgmt()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int workers_needed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t qd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t tps, d = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cur_max_ntasks = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_t *w;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if we are trying to increase the # of threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = stmf_nworkers_cur; i < stmf_nworkers_needed; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_workers[i].worker_flags & STMF_WORKER_STARTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_cur++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_accepting_cmds++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wait for transition to complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if we are trying to decrease the # of workers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = (stmf_nworkers_cur - 1); i >= stmf_nworkers_needed; i--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmf_workers[i].worker_flags & STMF_WORKER_STARTED) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_cur--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmf_nworkers_accepting_cmds has already been
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * updated by the request to reduce the # of workers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wait for transition to complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if we are being asked to quit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_workers_state != STMF_WORKERS_ENABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_nworkers_cur) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte workers_needed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto worker_mgmt_trigger_change;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if we are starting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_nworkers_cur < stmf_i_min_nworkers) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte workers_needed = stmf_i_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto worker_mgmt_trigger_change;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tps = drv_usectohz(1 * 1000 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmf_wm_last != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((d = ddi_get_lbolt() - stmf_wm_last) > tps)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < stmf_nworkers_accepting_cmds; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qd += stmf_workers[i].worker_max_qdepth_pu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers[i].worker_max_qdepth_pu = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_workers[i].worker_max_sys_qdepth_pu >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_max_ntasks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_max_ntasks =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers[i].worker_max_sys_qdepth_pu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_workers[i].worker_max_sys_qdepth_pu = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_wm_last = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (d <= tps) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* still ramping up */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* max qdepth cannot be more than max tasks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd > cur_max_ntasks)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qd = cur_max_ntasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if we have more workers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd < stmf_nworkers_accepting_cmds) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Since we dont reduce the worker count right away, monitor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the highest load during the scale_down_delay.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd > stmf_worker_scale_down_qd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_qd = qd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_worker_scale_down_timer == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_timer = ddi_get_lbolt() +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte drv_usectohz(stmf_worker_scale_down_delay *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1000 * 1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() < stmf_worker_scale_down_timer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Its time to reduce the workers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_worker_scale_down_qd < stmf_i_min_nworkers)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_qd = stmf_i_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_worker_scale_down_qd > stmf_i_max_nworkers)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_qd = stmf_i_max_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_worker_scale_down_qd == stmf_nworkers_cur)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte workers_needed = stmf_worker_scale_down_qd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_qd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto worker_mgmt_trigger_change;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_qd = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_worker_scale_down_timer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd > stmf_i_max_nworkers)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qd = stmf_i_max_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd < stmf_i_min_nworkers)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qd = stmf_i_min_nworkers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qd == stmf_nworkers_cur)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte workers_needed = qd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto worker_mgmt_trigger_change;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteworker_mgmt_trigger_change:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(workers_needed != stmf_nworkers_cur);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (workers_needed > stmf_nworkers_cur) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_needed = workers_needed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = stmf_nworkers_cur; i < workers_needed; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = &stmf_workers[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_tid = thread_create(NULL, 0, stmf_worker_task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&stmf_workers[i], 0, &p0, TS_RUN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minclsyspri);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* At this point we know that we are decreasing the # of workers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_accepting_cmds = workers_needed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_nworkers_needed = workers_needed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Signal the workers that its time to quit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = (stmf_nworkers_cur - 1); i >= stmf_nworkers_needed; i--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w = &stmf_workers[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(w && (w->worker_flags & STMF_WORKER_STARTED));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte w->worker_flags |= STMF_WORKER_TERMINATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&w->worker_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&w->worker_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fills out a dbuf from stmf_xfer_data_t (contained in the db_lu_private).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If all the data has been filled out, frees the xd and makes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * db_lu_private NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
91159e90831fc9243576f2ec1a483b3bb462bcf4John Fortestmf_xd_to_dbuf(stmf_data_buf_t *dbuf, int set_rel_off)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = (stmf_xfer_data_t *)dbuf->db_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = 0;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte if (set_rel_off)
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte dbuf->db_relative_offset = xd->size_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < dbuf->db_sglist_length; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = min(xd->size_left, dbuf->db_sglist[i].seg_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = &xd->buf[xd->size_done];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(p, dbuf->db_sglist[i].seg_addr, s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_left -= s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_done += s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size += s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xd->size_left == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(xd, xd->alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_lu_private = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_task_alloc(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_new_task(scsi_task_t *task, stmf_data_buf_t *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *cdbp = (uint8_t *)&task->task_cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t sz, minsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t inq_page_length = 31;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_handle_task_mgmt(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cdbp[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCMD_INQUIRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Basic protocol checks. In addition, only reply to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * standard inquiry. Otherwise, the LU provider needs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to respond.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdbp[2] || (cdbp[1] & 1) || cdbp[5]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uint32_t)cdbp[3]) << 8) | cdbp[4];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(task->task_expected_xfer_length,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte min(36, task->task_cmd_xfer_length));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsz = 36;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sz == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf && (dbuf->db_sglist[0].seg_length < 36)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ignore any preallocated dbuf if the size is less
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * than 36. It will be freed during the task_free.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, minsz, &minsz, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dbuf == NULL) || (dbuf->db_sglist[0].seg_length < sz)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_lu_private = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = dbuf->db_sglist[0].seg_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Standard inquiry handling only.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(p, inq_page_length + 5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = DPQ_SUPPORTED | DTYPE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[2] = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = 0x12;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[4] = inq_page_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[6] = 0x80;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy((char *)p+8, "SUN ", 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy((char *)p+16, "COMSTAR ", 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy((char *)p+32, "1.0 ", 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_relative_offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCMD_REPORT_LUNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((((uint32_t)task->task_cdb[6]) << 24) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uint32_t)task->task_cdb[7]) << 16) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uint32_t)task->task_cdb[8]) << 8) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint32_t)task->task_cdb[9]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(task->task_expected_xfer_length,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sz < 16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = (stmf_i_scsi_session_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = stmf_session_prepare_report_lun_data(iss->iss_sm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xd == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(sz, xd->size_left);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_left = sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsz = min(512, sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, sz, &minsz, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(xd, xd->alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_lu_private = xd;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte stmf_xd_to_dbuf(dbuf, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv ~(ISS_LUN_INVENTORY_CHANGED | ISS_GOT_INITIAL_LUNS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK, STMF_SAA_INVALID_OPCODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_dbuf_done(scsi_task_t *task, stmf_data_buf_t *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_i_scsi_task_t *itask =
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (stmf_i_scsi_task_t *)task->task_stmf_private;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf->db_xfer_status != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte task->task_nbytes_transferred += dbuf->db_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf->db_lu_private) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* There is more */
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte stmf_xd_to_dbuf(dbuf, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte stmf_free_dbuf(task, dbuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If this is a proxy task, it will need to be completed from the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * proxy port provider. This message lets pppt know that the xfer
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * is complete. When we receive the status from pppt, we will
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * then relay that status back to the lport.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (itask->itask_flags & ITASK_PROXY_TASK) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ic_msg_t *ic_xfer_done_msg = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t ic_ret = STMF_FAILURE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint64_t session_msg_id;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_enter(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte session_msg_id = stmf_proxy_msg_id++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte mutex_exit(&stmf_state.stmf_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* send xfer done status to pppt */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_xfer_done_msg = ic_scsi_data_xfer_done_msg_alloc(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte itask->itask_proxy_msg_id,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte task->task_session->ss_session_id,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SUCCESS, session_msg_id);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_xfer_done_msg) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ic_ret = ic_tx_msg(ic_xfer_done_msg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ic_ret != STMF_IC_MSG_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmn_err(CE_WARN, "unable to xmit session msg");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* task will be completed from pppt */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_status_done(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_task_free(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_abort(struct stmf_lu *lu, int abort_cmd, void *arg, uint32_t flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task = (scsi_task_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_scsi_task_t *)task->task_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_mgmt_function) && (itask->itask_flags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ITASK_CAUSING_LU_RESET | ITASK_CAUSING_TARGET_RESET))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_CLEAR_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_LUN_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&ilu->ilu_flags, ~ILU_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_COLD_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_WARM_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort_target_reset(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORT_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OK so its not a task mgmt. Make sure we free any xd sitting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inside any dbuf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map = itask->itask_allocated_buf_map) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < 4; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map & 1) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((itask->itask_dbufs[i])->db_lu_private)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = itask->itask_dbufs[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = (stmf_xfer_data_t *)dbuf->db_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_lu_private = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(xd, xd->alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map >>= 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORT_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_task_poll(struct scsi_task *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Right now we only do this for handling task management functions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(task->task_mgmt_function);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_ABORT_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_CLEAR_TASK_SET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_LUN_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_lun_reset_poll(task->task_lu, task, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_COLD_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TM_TARGET_WARM_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_target_reset_poll(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun0_ctl(struct stmf_lu *lu, int cmd, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This function will never be called */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "stmf_dlun0_ctl called with cmd %x", cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0 = stmf_alloc(STMF_STRUCT_STMF_LU, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_task_alloc = stmf_dlun0_task_alloc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_new_task = stmf_dlun0_new_task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_dbuf_xfer_done = stmf_dlun0_dbuf_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_send_status_done = stmf_dlun0_status_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_task_free = stmf_dlun0_task_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_abort = stmf_dlun0_abort;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_task_poll = stmf_dlun0_task_poll;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_ctl = stmf_dlun0_ctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)dlun0->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_cur_task_cntr = &ilu->ilu_task_cntr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_dlun_fini()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)dlun0->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilu->ilu_ntasks == ilu->ilu_ntasks_free);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_ntasks) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_task_t *itask, *nitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitask = ilu->ilu_tasks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itask = nitask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitask = itask->itask_lu_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlun0->lu_task_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(itask->itask_task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (nitask != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free(dlun0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_abort_target_reset(scsi_task_t *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss = (stmf_i_scsi_session_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *lm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lm_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm_ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lm_ent->ent_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&ilu->ilu_flags, ~ILU_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags, ~ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The return value is only used by function managing target reset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lun_reset_poll(stmf_lu_t *lu, struct scsi_task *task, int target_reset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ntasks_pending;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntasks_pending = ilu->ilu_ntasks - ilu->ilu_ntasks_free;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is also used during Target reset. The idea is that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * once all the commands are aborted, call the LU's reset entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * point (abort entry point with a reset flag). But if this Task
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mgmt is running on this LU then all the tasks cannot be aborted.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one task (this task) will still be running which is OK.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ntasks_pending == 0) || ((task->task_lu == lu) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ntasks_pending == 1))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_mgmt_function == TM_LUN_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_mgmt_function == TM_TARGET_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_mgmt_function == TM_TARGET_WARM_RESET) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_mgmt_function == TM_TARGET_COLD_RESET)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = lu->lu_abort(lu, STMF_LU_RESET_STATE, task, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&ilu->ilu_flags, ~ILU_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target_reset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task, ret, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target_reset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Tell target reset polling code that we are not done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_task_poll_lu(task, ITASK_DEFAULT_POLL_TIMEOUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_target_reset_poll(struct scsi_task *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss = (stmf_i_scsi_session_t *)
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv task->task_session->ss_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *lm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lm_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int not_done = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(iss->iss_flags & ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm_ent = (stmf_lun_map_ent_t *)lm->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lm_ent->ent_lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_flags & ILU_RESET_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_lun_reset_poll(lm_ent->ent_lu, task, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(iss->iss_lockp, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte not_done = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ABORTED, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(iss->iss_lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (not_done) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_task_poll_lu(task, ITASK_DEFAULT_POLL_TIMEOUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_and_32(&iss->iss_flags, ~ISS_RESET_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lu_add_event(stmf_lu_t *lu, int eventid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((eventid < 0) || (eventid >= STMF_MAX_NUM_EVENTS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_ADD(ilu->ilu_event_hdl, eventid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lu_remove_event(stmf_lu_t *lu, int eventid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (eventid == STMF_EVENT_ALL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_CLEAR_ALL(ilu->ilu_event_hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((eventid < 0) || (eventid >= STMF_MAX_NUM_EVENTS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_REMOVE(ilu->ilu_event_hdl, eventid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lport_add_event(stmf_local_port_t *lport, int eventid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_local_port_t *)lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((eventid < 0) || (eventid >= STMF_MAX_NUM_EVENTS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_ADD(ilport->ilport_event_hdl, eventid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lport_remove_event(stmf_local_port_t *lport, int eventid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport =
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv (stmf_i_local_port_t *)lport->lport_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (eventid == STMF_EVENT_ALL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_CLEAR_ALL(ilport->ilport_event_hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((eventid < 0) || (eventid >= STMF_MAX_NUM_EVENTS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_EVENT_REMOVE(ilport->ilport_event_hdl, eventid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_generate_lu_event(stmf_i_lu_t *ilu, int eventid, void *arg, uint32_t flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (STMF_EVENT_ENABLED(ilu->ilu_event_hdl, eventid) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ilu->ilu_lu->lu_event_handler != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_lu->lu_event_handler(ilu->ilu_lu, eventid, arg, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_generate_lport_event(stmf_i_local_port_t *ilport, int eventid, void *arg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (STMF_EVENT_ENABLED(ilport->ilport_event_hdl, eventid) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ilport->ilport_lport->lport_event_handler != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport->lport_event_handler(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_lport, eventid, arg, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto/*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * With the possibility of having multiple itl sessions pointing to the
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * same itl_kstat_info, the ilu_kstat_lock mutex is used to synchronize
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * the kstat update of the ilu_kstat_io, itl_kstat_taskq and itl_kstat_lu_xfer
427fcaf873956aad428be801380a44e59d38b8b5tim szeto * statistics.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto */
427fcaf873956aad428be801380a44e59d38b8b5tim szetovoid
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_itl_task_start(stmf_i_scsi_task_t *itask)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_data_t *itl = itask->itask_itl_datap;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_task_t *task = itask->itask_task;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_lu_t *ilu;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itl == NULL || task->task_lu == dlun0)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto itask->itask_start_timestamp = gethrtime();
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda if (ilu->ilu_kstat_io != NULL) {
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda mutex_enter(ilu->ilu_kstat_io->ks_lock);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda stmf_update_kstat_lu_q(itask->itask_task, kstat_waitq_enter);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda mutex_exit(ilu->ilu_kstat_io->ks_lock);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lport_q(itask->itask_task, kstat_waitq_enter);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetovoid
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_itl_lu_new_task(stmf_i_scsi_task_t *itask)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_data_t *itl = itask->itask_itl_datap;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_task_t *task = itask->itask_task;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_lu_t *ilu;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itl == NULL || task->task_lu == dlun0)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda if (ilu->ilu_kstat_io != NULL) {
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda mutex_enter(ilu->ilu_kstat_io->ks_lock);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda stmf_update_kstat_lu_q(itask->itask_task, kstat_waitq_to_runq);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda mutex_exit(ilu->ilu_kstat_io->ks_lock);
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lport_q(itask->itask_task, kstat_waitq_to_runq);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetovoid
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_itl_task_done(stmf_i_scsi_task_t *itask)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_data_t *itl = itask->itask_itl_datap;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto scsi_task_t *task = itask->itask_task;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_i_lu_t *ilu;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda itask->itask_done_timestamp = gethrtime();
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itl == NULL || task->task_lu == dlun0)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto ilu = (stmf_i_lu_t *)task->task_lu->lu_stmf_private;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda if (ilu->ilu_kstat_io == NULL)
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda mutex_enter(ilu->ilu_kstat_io->ks_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itask->itask_flags & ITASK_KSTAT_IN_RUNQ) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lu_q(task, kstat_runq_exit);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(ilu->ilu_kstat_io->ks_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lport_q(task, kstat_runq_exit);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto } else {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lu_q(task, kstat_waitq_exit);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto mutex_exit(ilu->ilu_kstat_io->ks_lock);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_update_kstat_lport_q(task, kstat_waitq_exit);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_lport_xfer_start(stmf_i_scsi_task_t *itask, stmf_data_buf_t *dbuf)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_data_t *itl = itask->itask_itl_datap;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itl == NULL)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE2(scsi__xfer__start, scsi_task_t *, itask->itask_task,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_data_buf_t *, dbuf);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto dbuf->db_xfer_start_timestamp = gethrtime();
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szetostatic void
427fcaf873956aad428be801380a44e59d38b8b5tim szetostmf_lport_xfer_done(stmf_i_scsi_task_t *itask, stmf_data_buf_t *dbuf)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_itl_data_t *itl = itask->itask_itl_datap;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto hrtime_t elapsed_time;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto uint64_t xfer_size;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (itl == NULL)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto xfer_size = (dbuf->db_xfer_status == STMF_SUCCESS) ?
427fcaf873956aad428be801380a44e59d38b8b5tim szeto dbuf->db_data_size : 0;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto elapsed_time = gethrtime() - dbuf->db_xfer_start_timestamp;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (dbuf->db_flags & DB_DIRECTION_TO_RPORT) {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto atomic_add_64((uint64_t *)&itask->itask_lport_read_time,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto elapsed_time);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto atomic_add_64((uint64_t *)&itask->itask_read_xfer,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto xfer_size);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto } else {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto atomic_add_64((uint64_t *)&itask->itask_lport_write_time,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto elapsed_time);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto atomic_add_64((uint64_t *)&itask->itask_write_xfer,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto xfer_size);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto DTRACE_PROBE3(scsi__xfer__end, scsi_task_t *, itask->itask_task,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto stmf_data_buf_t *, dbuf, hrtime_t, elapsed_time);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto dbuf->db_xfer_start_timestamp = 0;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_svc_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_svc_flags & STMF_SVC_STARTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_tailp = &stmf_state.stmf_svc_active;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_taskq = ddi_taskq_create(0, "STMF_SVC_TASKQ", 1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TASKQ_DEFAULTPRI, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_taskq_dispatch(stmf_state.stmf_svc_taskq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc, 0, DDI_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_svc_fini()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_svc_flags & STMF_SVC_STARTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_flags |= STMF_SVC_TERMINATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wait for 5 seconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < 500; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_svc_flags & STMF_SVC_STARTED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(drv_usectohz(10000));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i == 500)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_BUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_taskq_destroy(stmf_state.stmf_svc_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenkostruct stmf_svc_clocks {
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clock_t drain_start, drain_next;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clock_t timing_start, timing_next;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clock_t worker_delay;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko};
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_svc(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_svc_req_t *req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_local_port_t *lport;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko struct stmf_svc_clocks clks = { 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_flags |= STMF_SVC_STARTED | STMF_SVC_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko while (!(stmf_state.stmf_svc_flags & STMF_SVC_TERMINATE)) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_svc_active == NULL) {
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko stmf_svc_timeout(&clks);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko continue;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /*
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * Pop the front request from the active list. After this,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * the request will no longer be referenced by global state,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * so it should be safe to access it without holding the
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * stmf state lock.
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req = stmf_state.stmf_svc_active;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_svc_active = req->svc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_svc_active == NULL)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_tailp = &stmf_state.stmf_svc_active;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (req->svc_cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_ONLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fallthrough */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LPORT_OFFLINE:
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko mutex_exit(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lport = (stmf_local_port_t *)req->svc_obj;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lport->lport_ctl(lport, req->svc_cmd, &req->svc_info);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_ONLINE:
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko mutex_exit(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lu = (stmf_lu_t *)req->svc_obj;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lu->lu_ctl(lu, req->svc_cmd, &req->svc_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_OFFLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Remove all mappings of this LU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_session_lu_unmapall((stmf_lu_t *)req->svc_obj);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Kill all the pending I/Os for this LU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_task_lu_killall((stmf_lu_t *)req->svc_obj, NULL,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv STMF_ABORTED);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lu = (stmf_lu_t *)req->svc_obj;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov stmf_wait_ilu_tasks_finish(ilu);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko lu->lu_ctl(lu, req->svc_cmd, &req->svc_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "stmf_svc: unknown cmd %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_cmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
09409df0fea2444decd38bc1b87ab7a80d3251e5Jeff Biseda kmem_free(req, req->svc_req_alloc_size);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko mutex_enter(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_flags &= ~(STMF_SVC_STARTED | STMF_SVC_ACTIVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenkostatic void
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenkostmf_svc_timeout(struct stmf_svc_clocks *clks)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko{
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko clock_t td;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_i_local_port_t *ilport, *next_ilport;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_i_scsi_session_t *iss;
4f4863587e52ddab00c1f01266a9198314761416Nattuvetty Bhavyan
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko td = drv_usectohz(20000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* Do timeouts */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_nlus &&
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko ((!clks->timing_next) || (ddi_get_lbolt() >= clks->timing_next))) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (!stmf_state.stmf_svc_ilu_timing) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we are starting a new round */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_ilu_timing =
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_ilulist;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->timing_start = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_check_ilu_timing();
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (!stmf_state.stmf_svc_ilu_timing) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we finished a complete round */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->timing_next =
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->timing_start + drv_usectohz(5*1000*1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we still have some ilu items to check */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->timing_next =
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ddi_get_lbolt() + drv_usectohz(1*1000*1000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_svc_active)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* Check if there are free tasks to clear */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_nlus &&
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko ((!clks->drain_next) || (ddi_get_lbolt() >= clks->drain_next))) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (!stmf_state.stmf_svc_ilu_draining) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we are starting a new round */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_ilu_draining =
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_ilulist;
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->drain_start = ddi_get_lbolt();
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_check_freetask();
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (!stmf_state.stmf_svc_ilu_draining) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we finished a complete round */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->drain_next =
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->drain_start + drv_usectohz(10*1000*1000);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko } else {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* we still have some ilu items to check */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->drain_next =
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ddi_get_lbolt() + drv_usectohz(1*1000*1000);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_svc_active)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko return;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* Check if we need to run worker_mgmt */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko if (ddi_get_lbolt() > clks->worker_delay) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_worker_mgmt();
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko clks->worker_delay = ddi_get_lbolt() +
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_worker_mgmt_delay;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* Check if any active session got its 1st LUN */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_state.stmf_process_initial_luns) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko int stmf_level = 0;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko int port_level;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko for (ilport = stmf_state.stmf_ilportlist; ilport;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ilport = next_ilport) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko int ilport_lock_held;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko next_ilport = ilport->ilport_next;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if ((ilport->ilport_flags &
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ILPORT_SS_GOT_INITIAL_LUNS) == 0)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko continue;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko port_level = 0;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko rw_enter(&ilport->ilport_lock, RW_READER);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ilport_lock_held = 1;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko for (iss = ilport->ilport_ss_list; iss;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko iss = iss->iss_next) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if ((iss->iss_flags &
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ISS_GOT_INITIAL_LUNS) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko port_level++;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_level++;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko atomic_and_32(&iss->iss_flags,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ~ISS_GOT_INITIAL_LUNS);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko atomic_or_32(&iss->iss_flags,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ISS_EVENT_ACTIVE);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko rw_exit(&ilport->ilport_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ilport_lock_held = 0;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko mutex_exit(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_generate_lport_event(ilport,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko LPORT_EVENT_INITIAL_LUN_MAPPED,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko iss->iss_ss, 0);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko atomic_and_32(&iss->iss_flags,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ~ISS_EVENT_ACTIVE);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko mutex_enter(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /*
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * scan all the ilports again as the
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko * ilport list might have changed.
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko next_ilport = stmf_state.stmf_ilportlist;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (port_level == 0)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko atomic_and_32(&ilport->ilport_flags,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ~ILPORT_SS_GOT_INITIAL_LUNS);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* drop the lock if we are holding it. */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (ilport_lock_held == 1)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko rw_exit(&ilport->ilport_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* Max 4 session at a time */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_level >= 4)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (stmf_level == 0)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_process_initial_luns = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_flags &= ~STMF_SVC_ACTIVE;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko (void) cv_reltimedwait(&stmf_state.stmf_cv,
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko &stmf_state.stmf_lock, td, TR_CLOCK_TICK);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_flags |= STMF_SVC_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov/*
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * Waits for ongoing I/O tasks to finish on an LU in preparation for
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * the LU's offlining. The LU should already be in an Offlining state
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * (otherwise I/O to the LU might never end). There is an additional
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov * enforcement of this via a deadman timer check.
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov */
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovstatic void
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovstmf_wait_ilu_tasks_finish(stmf_i_lu_t *ilu)
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov{
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov clock_t start, now, deadline;
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov start = now = ddi_get_lbolt();
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov deadline = start + drv_usectohz(stmf_io_deadman * 1000000llu);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov mutex_enter(&ilu->ilu_task_lock);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov while (ilu->ilu_ntasks != ilu->ilu_ntasks_free) {
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov (void) cv_timedwait(&ilu->ilu_offline_pending_cv,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov &ilu->ilu_task_lock, deadline);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov now = ddi_get_lbolt();
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov if (now > deadline) {
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov if (stmf_io_deadman_enabled) {
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov cmn_err(CE_PANIC, "stmf_svc: I/O deadman hit "
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov "on STMF_CMD_LU_OFFLINE after %d seconds",
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov stmf_io_deadman);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov } else {
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* keep on spinning */
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov deadline = now + drv_usectohz(stmf_io_deadman *
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov 1000000llu);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov }
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov }
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov }
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov mutex_exit(&ilu->ilu_task_lock);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov DTRACE_PROBE1(deadman__timeout__wait, clock_t, now - start);
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov}
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_svc_queue(int cmd, void *obj, stmf_state_change_info_t *info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_svc_req_t *req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = sizeof (stmf_svc_req_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (info->st_additional_info) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s += strlen(info->st_additional_info) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req = kmem_zalloc(s, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_cmd = cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_obj = obj;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_info.st_rflags = info->st_rflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (info->st_additional_info) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_info.st_additional_info = (char *)(GET_BYTE_OFFSET(req,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_svc_req_t)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(req->svc_info.st_additional_info,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte info->st_additional_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->svc_req_alloc_size = s;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko req->svc_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&stmf_state.stmf_lock);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko *stmf_state.stmf_svc_tailp = req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_tailp = &req->svc_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((stmf_state.stmf_svc_flags & STMF_SVC_ACTIVE) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_signal(&stmf_state.stmf_cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&stmf_state.stmf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenkostatic void
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenkostmf_svc_kill_obj_requests(void *obj)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko{
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_svc_req_t *prev_req = NULL;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_svc_req_t *next_req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_svc_req_t *req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko ASSERT(mutex_owned(&stmf_state.stmf_lock));
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko for (req = stmf_state.stmf_svc_active; req != NULL; req = next_req) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko next_req = req->svc_next;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (req->svc_obj == obj) {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (prev_req != NULL)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko prev_req->svc_next = next_req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko else
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_active = next_req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko if (next_req == NULL)
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko stmf_state.stmf_svc_tailp = (prev_req != NULL) ?
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko &prev_req->svc_next :
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko &stmf_state.stmf_svc_active;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko kmem_free(req, req->svc_req_alloc_size);
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko } else {
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko prev_req = req;
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko }
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko}
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_trace(caddr_t ident, const char *fmt, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list args;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char tbuf[160];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stmf_trace_on)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = snprintf(tbuf, 158, "%s:%07lu: ", ident ? ident : "",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_get_lbolt());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(args, fmt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len += vsnprintf(tbuf + len, 158 - len, fmt, args);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(args);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > 158) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = 158;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tbuf[len++] = '\n';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tbuf[len] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(tbuf, &stmf_trace_buf[trace_buf_curndx], len+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_curndx += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (trace_buf_curndx > (trace_buf_size - 320))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_curndx = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_trace_clear()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stmf_trace_on)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trace_buf_curndx = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (trace_buf_size > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace_buf[0] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&trace_buf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_abort_task_offline(scsi_task_t *task, int offline_lu, char *info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto stmf_state_change_info_t change_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *ctl_private;
554c2b163439bbe1231a5d9ff5b9b0045c510c69tim szeto uint32_t ctl_cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int msg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace("FROM STMF", "abort_task_offline called for %s: %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline_lu ? "LU" : "LPORT", info ? info : "no additional info");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte change_info.st_additional_info = info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (offline_lu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte change_info.st_rflags = STMF_RFLAG_RESET |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_RFLAG_LU_ABORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_private = task->task_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_i_lu_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu->lu_stmf_private)->ilu_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_cmd = STMF_CMD_LU_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte change_info.st_rflags = STMF_RFLAG_RESET |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_RFLAG_LPORT_ABORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_private = task->task_lport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((stmf_i_local_port_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lport->lport_stmf_private)->ilport_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctl_cmd = STMF_CMD_LPORT_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (msg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_trace(0, "Calling stmf_ctl to offline %s : %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline_lu ? "LU" : "LPORT", info ? info :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "<no additional info>");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(ctl_cmd, ctl_private, &change_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstatic char
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_ctoi(char c)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((c >= '0') && (c <= '9'))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan c -= '0';
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan else if ((c >= 'A') && (c <= 'F'))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan c = c - 'A' + 10;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan else if ((c >= 'a') && (c <= 'f'))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan c = c - 'a' + 10;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan else
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan c = -1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (c);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan/* Convert from Hex value in ASCII format to the equivalent bytes */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstatic boolean_t
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_base16_str_to_binary(char *c, int dplen, uint8_t *dp)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan int ii;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan for (ii = 0; ii < dplen; ii++) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan char nibble1, nibble2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan char enc_char = *c++;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan nibble1 = stmf_ctoi(enc_char);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan enc_char = *c++;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan nibble2 = stmf_ctoi(enc_char);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (nibble1 == -1 || nibble2 == -1)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan dp[ii] = (nibble1 << 4) | nibble2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_TRUE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanboolean_t
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_scsilib_tptid_validate(scsi_transport_id_t *tptid, uint32_t total_sz,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t *tptid_sz)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t tpd_len = SCSI_TPTID_SIZE;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (tptid_sz)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan *tptid_sz = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (total_sz < sizeof (scsi_transport_id_t))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan switch (tptid->protocol_id) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_FIBRE_CHANNEL:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /* FC Transport ID validation checks. SPC3 rev23, Table 284 */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (total_sz < tpd_len || tptid->format_code != 0)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_iSCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsi_transport_id_t *iscsiid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t adn_len, name_len;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /* Check for valid format code, SPC3 rev 23 Table 288 */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((total_sz < tpd_len) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (tptid->format_code != 0 && tptid->format_code != 1))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsiid = (iscsi_transport_id_t *)tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan adn_len = READ_SCSI16(iscsiid->add_len, uint16_t);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan tpd_len = sizeof (iscsi_transport_id_t) + adn_len - 1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /*
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * iSCSI Transport ID validation checks.
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * As per SPC3 rev 23 Section 7.5.4.6 and Table 289 & Table 290
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (adn_len < 20 || (adn_len % 4 != 0))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan name_len = strnlen(iscsiid->iscsi_name, adn_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (name_len == 0 || name_len >= adn_len)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /* If the format_code is 1 check for ISID seperator */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((tptid->format_code == 1) && (strstr(iscsiid->iscsi_name,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan SCSI_TPTID_ISCSI_ISID_SEPERATOR) == NULL))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SRP:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /* SRP Transport ID validation checks. SPC3 rev23, Table 287 */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (total_sz < tpd_len || tptid->format_code != 0)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_PARALLEL_SCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SSA:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_IEEE_1394:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SAS:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ADT:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ATAPI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan default:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_dflt_scsi_tptid_t *dflttpd;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan tpd_len = sizeof (stmf_dflt_scsi_tptid_t);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (total_sz < tpd_len)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan dflttpd = (stmf_dflt_scsi_tptid_t *)tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan tpd_len = tpd_len + SCSI_READ16(&dflttpd->ident_len) - 1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (total_sz < tpd_len)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (tptid_sz)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan *tptid_sz = tpd_len;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_TRUE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanboolean_t
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_scsilib_tptid_compare(scsi_transport_id_t *tpd1,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan scsi_transport_id_t *tpd2)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((tpd1->protocol_id != tpd2->protocol_id) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (tpd1->format_code != tpd2->format_code))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan switch (tpd1->protocol_id) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_iSCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsi_transport_id_t *iscsitpd1, *iscsitpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t len;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsitpd1 = (iscsi_transport_id_t *)tpd1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsitpd2 = (iscsi_transport_id_t *)tpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan len = SCSI_READ16(&iscsitpd1->add_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((memcmp(iscsitpd1->add_len, iscsitpd2->add_len, 2) != 0) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (memcmp(iscsitpd1->iscsi_name, iscsitpd2->iscsi_name, len)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan != 0))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SRP:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan scsi_srp_transport_id_t *srptpd1, *srptpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan srptpd1 = (scsi_srp_transport_id_t *)tpd1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan srptpd2 = (scsi_srp_transport_id_t *)tpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (memcmp(srptpd1->srp_name, srptpd2->srp_name,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sizeof (srptpd1->srp_name)) != 0)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_FIBRE_CHANNEL:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan scsi_fc_transport_id_t *fctpd1, *fctpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan fctpd1 = (scsi_fc_transport_id_t *)tpd1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan fctpd2 = (scsi_fc_transport_id_t *)tpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if (memcmp(fctpd1->port_name, fctpd2->port_name,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sizeof (fctpd1->port_name)) != 0)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_PARALLEL_SCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SSA:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_IEEE_1394:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SAS:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ADT:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ATAPI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan default:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_dflt_scsi_tptid_t *dflt1, *dflt2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t len;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan dflt1 = (stmf_dflt_scsi_tptid_t *)tpd1;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan dflt2 = (stmf_dflt_scsi_tptid_t *)tpd2;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan len = SCSI_READ16(&dflt1->ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((memcmp(dflt1->ident_len, dflt2->ident_len, 2) != 0) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (memcmp(dflt1->ident, dflt2->ident, len) != 0))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_FALSE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (B_TRUE);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan/*
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * Changes devid_desc to corresponding TransportID format
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * Returns :- pointer to stmf_remote_port_t
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * Note :- Allocates continous memory for stmf_remote_port_t and TransportID,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * This memory need to be freed when this remote_port is no longer
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * used.
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_remote_port_t *
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_scsilib_devid_to_remote_port(scsi_devid_desc_t *devid)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan struct scsi_fc_transport_id *fc_tpd;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan struct iscsi_transport_id *iscsi_tpd;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan struct scsi_srp_transport_id *srp_tpd;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan struct stmf_dflt_scsi_tptid *dflt_tpd;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan uint16_t ident_len, sz = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_remote_port_t *rpt = NULL;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ident_len = devid->ident_length;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ASSERT(ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan switch (devid->protocol_id) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_FIBRE_CHANNEL:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sz = sizeof (scsi_fc_transport_id_t);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt = stmf_remote_port_alloc(sz);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->format_code = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->protocol_id = devid->protocol_id;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan fc_tpd = (scsi_fc_transport_id_t *)rpt->rport_tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /*
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * convert from "wwn.xxxxxxxxxxxxxxxx" to 8-byte binary
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * skip first 4 byte for "wwn."
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ASSERT(strncmp("wwn.", (char *)devid->ident, 4) == 0);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((ident_len < SCSI_TPTID_FC_PORT_NAME_SIZE * 2 + 4) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan !stmf_base16_str_to_binary((char *)devid->ident + 4,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan SCSI_TPTID_FC_PORT_NAME_SIZE, fc_tpd->port_name))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan goto devid_to_remote_port_fail;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_iSCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sz = ALIGNED_TO_8BYTE_BOUNDARY(sizeof (iscsi_transport_id_t) +
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ident_len - 1);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt = stmf_remote_port_alloc(sz);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->format_code = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->protocol_id = devid->protocol_id;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan iscsi_tpd = (iscsi_transport_id_t *)rpt->rport_tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan SCSI_WRITE16(iscsi_tpd->add_len, ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (void) memcpy(iscsi_tpd->iscsi_name, devid->ident, ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SRP:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sz = sizeof (scsi_srp_transport_id_t);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt = stmf_remote_port_alloc(sz);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->format_code = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->protocol_id = devid->protocol_id;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan srp_tpd = (scsi_srp_transport_id_t *)rpt->rport_tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /*
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * convert from "eui.xxxxxxxxxxxxxxx" to 8-byte binary
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * skip first 4 byte for "eui."
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * Assume 8-byte initiator-extension part of srp_name is NOT
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * stored in devid and hence will be set as zero
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ASSERT(strncmp("eui.", (char *)devid->ident, 4) == 0);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan if ((ident_len < (SCSI_TPTID_SRP_PORT_NAME_LEN - 8) * 2 + 4) ||
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan !stmf_base16_str_to_binary((char *)devid->ident+4,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan SCSI_TPTID_SRP_PORT_NAME_LEN, srp_tpd->srp_name))
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan goto devid_to_remote_port_fail;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_PARALLEL_SCSI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SSA:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_IEEE_1394:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_SAS:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ADT:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan case PROTOCOL_ATAPI:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan default :
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ident_len = devid->ident_length;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sz = ALIGNED_TO_8BYTE_BOUNDARY(sizeof (stmf_dflt_scsi_tptid_t) +
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan ident_len - 1);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt = stmf_remote_port_alloc(sz);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->format_code = 0;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid->protocol_id = devid->protocol_id;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan dflt_tpd = (stmf_dflt_scsi_tptid_t *)rpt->rport_tptid;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan SCSI_WRITE16(dflt_tpd->ident_len, ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan (void) memcpy(dflt_tpd->ident, devid->ident, ident_len);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan break;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan }
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (rpt);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyandevid_to_remote_port_fail:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_remote_port_free(rpt);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (NULL);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_remote_port_t *
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_remote_port_alloc(uint16_t tptid_sz) {
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan stmf_remote_port_t *rpt;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt = (stmf_remote_port_t *)kmem_zalloc(
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan sizeof (stmf_remote_port_t) + tptid_sz, KM_SLEEP);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid_sz = tptid_sz;
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan rpt->rport_tptid = (scsi_transport_id_t *)(rpt + 1);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan return (rpt);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanvoid
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyanstmf_remote_port_free(stmf_remote_port_t *rpt)
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan{
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /*
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * Note: stmf_scsilib_devid_to_remote_port() function allocates
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * remote port structures for all transports in the same way, So
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * it is safe to deallocate it in a protocol independent manner.
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * If any of the allocation method changes, corresponding changes
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan * need to be made here too.
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan */
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan kmem_free(rpt, sizeof (stmf_remote_port_t) + rpt->rport_tptid_sz);
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan}