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/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI session interfaces
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#include <sys/bootprops.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi_targetparam.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISCSI_SESS_ENUM_TIMEOUT_DEFAULT 60
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_INQUIRY_PQUAL_MASK 0xE0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapboolean_t iscsi_sess_logging = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * used to store report lun information found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lun_valid: if TRUE means the entry contains a valid entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lun_found: if TRUE means the lun has been found in the sess_lun_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lun_num: contains the lun_number
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * lun_addr_type: indicates lun's type of addressing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct replun_data {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t lun_valid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t lun_found;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t lun_num;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint8_t lun_addr_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} replun_data_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint iscsi_sess_enum_timeout = ISCSI_SESS_ENUM_TIMEOUT_DEFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following private tunable, settable via
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set iscsi:iscsi_sess_max_delay = 64
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in /etc/system, provides customer relief for configurations max interval in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * seconds of retry for a unreachable target during the login.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint iscsi_sess_max_delay = ISCSI_DEFAULT_MAX_STORM_DELAY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Warning messages for the session scsi enumeration
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengstatic const char *iscsi_sess_enum_warn_msgs[] = {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "completed",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "partially successful",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "IO failures",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "submitted",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "unable to submit the enumeration",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "session is gone",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "test unit ready failed"
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng};
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* internal interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINTED E_STATIC_UNUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_sess_t *iscsi_sess_alloc(iscsi_hba_t *ihp, iscsi_sess_type_t type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *iscsi_sess_event_str(iscsi_sess_event_t event);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t iscsi_sess_threads_create(iscsi_sess_t *isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_flush(iscsi_sess_t *isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_offline_luns(iscsi_sess_t *isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t retrieve_lundata(uint32_t lun_count, unsigned char *buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp, uint16_t *lun_data, uint8_t *lun_addr_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* internal state machine interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_state_free(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_event_t event, uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_state_logged_in(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_event_t event, uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_state_failed(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_event_t event, uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_state_in_flush(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_event_t event, uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_state_flushed(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_event_t event, uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* internal enumeration interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_enumeration(void *arg);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengstatic iscsi_status_t iscsi_sess_testunitready(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengstatic iscsi_status_t iscsi_sess_reportluns(iscsi_sess_t *isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_sess_inquiry(iscsi_sess_t *isp, uint16_t lun_num,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint8_t lun_addr_type, uint32_t event_count, iscsi_lun_t *ilp);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing Chinastatic void iscsi_sess_update_busy_luns(iscsi_sess_t *isp, boolean_t clear);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengstatic void iscsi_sess_enum_warn(iscsi_sess_t *isp, iscsi_enum_result_t r);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | External Session Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_create(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t method,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *addr_dsc, char *target_name, int tpgt, uchar_t isid_lsb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_type_t type, uint32_t *oid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tq_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *th_name;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_status_t status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(target_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
17342e82bc36c1e210231c42eed3cf0316719eedJack Mengclean_failed_sess:
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng if (isp != NULL) {
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng (void) iscsi_sess_destroy(isp);
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng }
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp; isp = isp->sess_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Match target name and LSB ISID */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp((char *)isp->sess_name, target_name) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isp->sess_isid[5] == isid_lsb)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Match TPGT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_tpgt_conf == tpgt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Found mathing session, return oid/ptr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *oid = isp->sess_oid;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_wd_thread != NULL &&
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_ic_thread != NULL) {
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng return (isp);
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng if (isp->sess_wd_thread == NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China /*
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China * Under rare cases wd thread is already
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China * freed, create it if so.
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China */
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China th_name = kmem_zalloc(
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ISCSI_TH_MAX_NAME_LEN, KM_SLEEP);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (snprintf(th_name,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China (ISCSI_TH_MAX_NAME_LEN - 1),
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ISCSI_SESS_WD_NAME_FORMAT,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ihp->hba_oid, isp->sess_oid) <
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ISCSI_TH_MAX_NAME_LEN) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_wd_thread =
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_thread_create(
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ihp->hba_dip,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China th_name,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_wd_thread,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China (void) iscsi_thread_start(
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_wd_thread);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China kmem_free(th_name,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China ISCSI_TH_MAX_NAME_LEN);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_wd_thread == NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China /* No way to save it */
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China goto clean_failed_sess;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_ic_thread == NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China status = iscsi_sess_threads_create(isp);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (status != ISCSI_STATUS_SUCCESS) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China goto clean_failed_sess;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Also protect against creating duplicate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sessions with different configured tpgt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * values. default vs. defined.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((((isp->sess_tpgt_conf == ISCSI_DEFAULT_TPGT) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tpgt != ISCSI_DEFAULT_TPGT)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((isp->sess_tpgt_conf != ISCSI_DEFAULT_TPGT) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tpgt == ISCSI_DEFAULT_TPGT)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Dangerous configuration. Fail Request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = (iscsi_sess_t *)kmem_zalloc(sizeof (iscsi_sess_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this session is not a Send Targets session, set the target
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that this session is associated with.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(target_name, SENDTARGETS_DISCOVERY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(SENDTARGETS_DISCOVERY))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_target_oid = iscsi_targetparam_get_oid(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)target_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (method & iSCSIDiscoveryMethodBoot) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* This is boot session. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Associate session with this discovery method */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng method = method & ~(iSCSIDiscoveryMethodBoot);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_discovered_by = method;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addr_dsc == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&isp->sess_discovered_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_discovered_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(addr_dsc, &isp->sess_discovered_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SIZEOF_SOCKADDR(addr_dsc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* assign unique key for the session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&iscsi_oid_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid = iscsi_oid++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *oid = isp->sess_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&iscsi_oid_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup session parameters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_sig = ISCSI_SIG_SESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FREE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_init(&isp->sess_state_rwlock, NULL, RW_DRIVER, NULL);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_init(&isp->sess_reset_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_hba = ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[0] = ISCSI_SUN_ISID_0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[1] = ISCSI_SUN_ISID_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[2] = ISCSI_SUN_ISID_2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[3] = ISCSI_SUN_ISID_3;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[4] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[5] = isid_lsb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_cmdsn = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_expcmdsn = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_maxcmdsn = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_last_err = NoError;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_tsid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_type = type;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China isp->sess_reset_in_progress = B_FALSE;
bbe725837bc5e084e6762c7984672bc05d76baf1Jack Meng isp->sess_boot_nic_reset = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_init(&isp->sess_state_audit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy default driver login parameters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&ihp->hba_params, &isp->sess_params,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_login_params_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy target name into session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((char *)target_name, isp->sess_name, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name_length = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_tpgt_conf = tpgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_tpgt_nego = ISCSI_DEFAULT_TPGT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize pending and completion queues */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_init_queue(&isp->sess_queue_pending);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_init_queue(&isp->sess_queue_completion);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup sessions lun list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_lun_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_init(&isp->sess_lun_list_rwlock, NULL, RW_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup sessions connection list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_act = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_init(&isp->sess_conn_list_rwlock, NULL, RW_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&isp->sess_cmdsn_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create the session task queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tq_name = kmem_zalloc(ISCSI_TH_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(tq_name, (ISCSI_TH_MAX_NAME_LEN - 1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_SESS_LOGIN_TASKQ_NAME_FORMAT, ihp->hba_oid, isp->sess_oid) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_TH_MAX_NAME_LEN) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_login_taskq = ddi_taskq_create(ihp->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tq_name, 1, TASKQ_DEFAULTPRI, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_login_taskq == NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(tq_name, ISCSI_TH_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto iscsi_sess_cleanup2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (snprintf(tq_name, (ISCSI_TH_MAX_NAME_LEN - 1),
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_ENUM_TASKQ_NAME_FORMAT, ihp->hba_oid, isp->sess_oid) <
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_TH_MAX_NAME_LEN) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_taskq = ddi_taskq_create(ihp->hba_dip,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng tq_name, 1, TASKQ_DEFAULTPRI, 0);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(tq_name, ISCSI_TH_MAX_NAME_LEN);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_enum_taskq == NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto iscsi_sess_cleanup1;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* startup watchdog */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte th_name = kmem_zalloc(ISCSI_TH_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(th_name, (ISCSI_TH_MAX_NAME_LEN - 1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_SESS_WD_NAME_FORMAT, ihp->hba_oid, isp->sess_oid) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_TH_MAX_NAME_LEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_wd_thread = iscsi_thread_create(ihp->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte th_name, iscsi_wd_thread, isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_thread_start(isp->sess_wd_thread);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(th_name, ISCSI_TH_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_wd_thread == NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto iscsi_sess_cleanup0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China status = iscsi_sess_threads_create(isp);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (status != ISCSI_STATUS_SUCCESS) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China goto iscsi_sess_cleanup1;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Add new target to the hba target list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ihp->hba_sess_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_sess_list = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_next = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_sess_list = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_INC_HBA_CNTR_SESS(ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_sess_kstat_init(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_FREE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result = ISCSI_SESS_ENUM_COMPLETE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result_count = 0;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_init(&isp->sess_enum_lock, NULL, MUTEX_DRIVER, NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_init(&isp->sess_enum_cv, NULL, CV_DRIVER, NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_init(&isp->sess_state_wmutex, NULL, MUTEX_DRIVER, NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_init(&isp->sess_state_wcv, NULL, CV_DRIVER, NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_state_hasw = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_state_event_count = 0;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_cleanup0:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ddi_taskq_destroy(isp->sess_enum_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_cleanup1:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ddi_taskq_destroy(isp->sess_login_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_cleanup2:
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_wd_thread != NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_thread_destroy(isp->sess_wd_thread);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_wd_thread = NULL;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_ic_thread != NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_thread_destroy(isp->sess_ic_thread);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_ic_thread = NULL;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&isp->sess_cmdsn_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_destroy(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_destroy(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_destroy_queue(&isp->sess_queue_completion);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_destroy_queue(&isp->sess_queue_pending);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_destroy(&isp->sess_state_rwlock);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_destroy(&isp->sess_reset_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isp, sizeof (iscsi_sess_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_get - return the session structure for based on a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in oid and hba instance.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_get(uint32_t oid, iscsi_hba_t *ihp, iscsi_sess_t **ispp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ispp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if we already created this session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp; isp = isp->sess_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* compare target name as the unique identifier */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_oid == oid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Found matching session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If not null this session is already available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Existing session, return it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ispp = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_online - initiate online of sessions connections
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing Chinaiscsi_sess_online(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int idx;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China isp = (iscsi_sess_t *)arg;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Stale /dev links can cause us to get floods
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of config requests. To prevent these repeated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * requests from causing unneeded login to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unreachable target, we won't try it during
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the delay.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_get_lbolt() < isp->sess_failure_lbolt +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SEC_TO_TICK(isp->sess_storm_delay)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Perform a crude version of round robin to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine which connection to use for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this session. Since byte 5 in session ID
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is overridden for full feature session,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the connection to be selected depends on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the result of sess_isid[5] devided by the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * next connection ID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If MS/T is enabled and there are multiple
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IPs are available on the target, we can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * select different IPs to connect in this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * way.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_act;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idx = 0; idx < (isp->sess_isid[5] %
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_next_cid); idx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp->conn_next != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_act = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%d) - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "no connection assigned", isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If connection is in free state, start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * login. If already logged in, try to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * re-enumerate LUs on the session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state == ISCSI_CONN_STATE_FREE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to login into the first connection in our connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list. If this fails, we will try the next connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in our list until end of the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (iscsi_conn_online(icp) == ISCSI_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_act = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the target for this session is unreachable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_failure_lbolt = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_storm_delay == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_storm_delay++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isp->sess_storm_delay * 2) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_max_delay) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_storm_delay =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_storm_delay * 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_storm_delay =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_max_delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_storm_delay = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_failure_lbolt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(&isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N1, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_destroy - Destroys a iscsi session structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and de-associates it from the hba.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_destroy(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rval = ISCSI_STATUS_SUCCESS;
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China iscsi_status_t tmprval = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *t_isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The first step in tearing down the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has to be offlining all the LUNs. This will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ensure there is no outstanding IO by upper
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * level drivers. If this fails then we are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unable to destroy the session.
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China *
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China * Try all luns and continue upon failure
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China * to remove what is removable before returning
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China * the last error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_lun_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = isp->sess_lun_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ilp != NULL) {
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China iscsi_lun_t *ilp_next = ilp->lun_next;
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China tmprval = iscsi_lun_destroy(ihp, ilp);
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China if (!ISCSI_SUCCESS(tmprval)) {
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China rval = tmprval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China ilp = ilp_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China if (!ISCSI_SUCCESS(rval)) {
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China return (rval);
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China }
0349feaba2d30409e4115d7a822e5c1e1961c35eyu, larry liu - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The next step is to logout of the connections. */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap rw_enter(&isp->sess_conn_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_conn_offline(icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Succes, Continue processing... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Failure, Stop processing... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * At this point all connections should be in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a FREE state which will have pushed the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to a FREE state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(isp->sess_state == ISCSI_SESS_STATE_FREE ||
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap isp->sess_state == ISCSI_SESS_STATE_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Stop watchdog before destroying connections */
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng if (isp->sess_wd_thread) {
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng iscsi_thread_destroy(isp->sess_wd_thread);
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng isp->sess_wd_thread = NULL;
17342e82bc36c1e210231c42eed3cf0316719eedJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Destroy connections */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_conn_destroy(icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China /* Destroy Session ic thread */
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_ic_thread != NULL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China iscsi_thread_destroy(isp->sess_ic_thread);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_ic_thread = NULL;
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China }
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Destroy session task queue */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ddi_taskq_destroy(isp->sess_enum_taskq);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ddi_taskq_destroy(isp->sess_login_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* destroy pending and completion queues */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_destroy_queue(&isp->sess_queue_pending);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_destroy_queue(&isp->sess_queue_completion);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Remove session from ihp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ihp->hba_sess_list == isp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* session first item in list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_sess_list = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * search hba list for isp pointing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to session being removed. Then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update that sessions next pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (t_isp->sess_next != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_isp->sess_next == isp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_isp = t_isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_isp->sess_next == isp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_isp->sess_next = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* couldn't find session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* Wait for all enum requests complete */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while (isp->sess_enum_result_count > 0) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_wait(&isp->sess_enum_cv, &isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Destroy this Sessions Data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_sess_kstat_term(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_destroy(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_destroy(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&isp->sess_cmdsn_mutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_destroy(&isp->sess_state_rwlock);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_destroy(&isp->sess_reset_mutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_destroy(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_destroy(&isp->sess_enum_cv);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_destroy(&isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_destroy(&isp->sess_state_wcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isp, sizeof (iscsi_sess_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern ib_boot_prop_t *iscsiboot_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static iscsi_sess_set_auth -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_set_auth(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *init_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_chap_props_t *chap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_auth_props_t *auth = NULL;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uchar_t *tmp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp == (iscsi_sess_t *)NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Obtain initiator's name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_hba == (iscsi_hba_t *)NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_name = (char *)isp->sess_hba->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Zero out the session authentication structure */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bzero(&isp->sess_auth, sizeof (iscsi_auth_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp->sess_boot == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng auth = (iscsi_auth_props_t *)kmem_zalloc
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (sizeof (iscsi_auth_props_t), KM_SLEEP);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Obtain target's authentication settings. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_auth_get((char *)isp->sess_name, auth)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng != B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * If no target authentication settings found,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * try to obtain system wide configuration
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * (from the initiator).
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(auth, sizeof (*auth));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_auth_get(init_name, auth) != B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bzero(auth, sizeof (*auth));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng auth->a_auth_method = authMethodNone;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * We do not support system wide bi-directional
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * auth flag.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng auth->a_bi_auth = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng chap = (iscsi_chap_props_t *)kmem_zalloc
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (sizeof (iscsi_chap_props_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Initialize the target-side chap name to the session name
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * if no chap settings have been saved for the current session.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_chap_get((char *)isp->sess_name, chap)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int name_len = strlen((char *)isp->sess_name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy((char *)isp->sess_name, chap->c_user, name_len);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng chap->c_user_len = name_len;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) (persistent_chap_set((char *)isp->sess_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng chap));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bzero(chap, sizeof (*chap));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (auth->a_auth_method & authMethodCHAP) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Obtain initiator's CHAP settings. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_chap_get(init_name, chap) == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* No initiator secret defined. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(chap, sizeof (iscsi_chap_props_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Set authentication method to NONE */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_length = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(auth, sizeof (iscsi_auth_props_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(chap->c_user, isp->sess_auth.username,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng sizeof (chap->c_user));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(chap->c_secret, isp->sess_auth.password,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng sizeof (chap->c_secret));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_length = chap->c_secret_len;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set authentication method to NONE */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.password_length = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Consider enabling bidirectional authentication only if
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * authentication method is not NONE.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (auth->a_auth_method & authMethodCHAP &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng auth->a_bi_auth == B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Enable bi-directional authentication. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.bidirectional_auth = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bzero(chap, sizeof (*chap));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Obtain target's CHAP settings. */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_chap_get((char *)isp->sess_name, chap)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng == B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(chap->c_secret,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_in,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng sizeof (chap->c_secret));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(chap->c_user, isp->sess_auth.username_in,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((char *)chap->c_user));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_length_in =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng chap->c_secret_len;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * No target secret defined.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * RADIUS server should have been enabled.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* EMPTY */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Disable bi-directional authentication */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.bidirectional_auth = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (auth != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(auth, sizeof (iscsi_auth_props_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (chap != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(chap, sizeof (iscsi_chap_props_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * This session is boot session. We will use the CHAP and
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * the user name got from the boot property structure instead
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of persistent sotre.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop->boot_init.ini_chap_sec == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* CHAP secret */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(iscsiboot_prop->boot_init.ini_chap_sec,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((char *)iscsiboot_prop->boot_init.ini_chap_sec));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * If chap name is not set,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * we will use initiator name instead.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop->boot_init.ini_chap_name == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(init_name, isp->sess_auth.username,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen(init_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng tmp = iscsiboot_prop->boot_init.ini_chap_name;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(tmp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.username, strlen((char *)tmp));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_length =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((char *)iscsiboot_prop->boot_init.ini_chap_sec);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop->boot_tgt.tgt_chap_sec != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Bidirectional authentication is required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng tmp = iscsiboot_prop->boot_tgt.tgt_chap_sec;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(tmp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_in, strlen((char *)tmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * If the target's chap name is not set, we will use
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * session name instead.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop->boot_tgt.tgt_chap_name == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(isp->sess_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.username_in,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_name_length);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng tmp = iscsiboot_prop->boot_tgt.tgt_chap_name;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(tmp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.username_in,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((char *)tmp));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng tmp = iscsiboot_prop->boot_tgt.tgt_chap_sec;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.password_length_in =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((char *)tmp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_auth.bidirectional_auth = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set up authentication buffers only if configured */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isp->sess_auth.password_length != 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isp->sess_auth.password_length_in != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.num_auth_buffers = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[0].address =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isp->sess_auth.auth_client_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[0].length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_auth.auth_client_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[1].address =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isp->sess_auth.auth_recv_string_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[1].length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_auth.auth_recv_string_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[2].address =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isp->sess_auth.auth_send_string_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[2].length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_auth.auth_send_string_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[3].address =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isp->sess_auth.auth_recv_binary_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[3].length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_auth.auth_recv_binary_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[4].address =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isp->sess_auth.auth_send_binary_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_auth.auth_buffers[4].length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isp->sess_auth.auth_send_binary_block);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap/*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iscsi_sess_reserve_itt - Used to reserve an ITT hash slot
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_status_t
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_sess_reserve_scsi_itt(iscsi_cmd_t *icmdp)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_task_t *itp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_t *icp = icmdp->cmd_conn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp = idm_task_alloc(icp->conn_ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (itp == NULL)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (ISCSI_STATUS_INTERNAL_ERROR);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp->idt_private = icmdp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icmdp->cmd_itp = itp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icmdp->cmd_itt = itp->idt_tt;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (ISCSI_STATUS_SUCCESS);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap/*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iscsi_sess_release_scsi_itt - Used to release ITT hash slot
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapvoid
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_sess_release_scsi_itt(iscsi_cmd_t *icmdp)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_task_free(icmdp->cmd_itp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_reserve_itt - Used to reserve an ITT hash slot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_reserve_itt(iscsi_sess_t *isp, iscsi_cmd_t *icmdp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If no more slots are open fail reservation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_cmd_table_count >= ISCSI_CMD_TABLE_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_ITT_TABLE_FULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Keep itt values out of the range used by IDM
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (isp->sess_itt < IDM_TASKIDS_MAX)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap isp->sess_itt = IDM_TASKIDS_MAX;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find the next available slot. Normally its the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * slot pointed to by the session's sess_itt value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this is not true the table has become fragmented.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fragmentation can occur during max loads and IOs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are completed out of order. Defragmentation will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * occur when IO slows down and ITT slots are released.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (isp->sess_cmd_table[isp->sess_itt %
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CMD_TABLE_SIZE] != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_itt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reserve slot and update counters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icmdp->cmd_itt = isp->sess_itt;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap isp->sess_cmd_table[isp->sess_itt %
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CMD_TABLE_SIZE] = icmdp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_cmd_table_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_itt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_release_itt - Used to release ITT hash slot
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_release_itt(iscsi_sess_t *isp, iscsi_cmd_t *icmdp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int hash_index = (icmdp->cmd_itt % ISCSI_CMD_TABLE_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_cmd_table[hash_index] != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release slot and update counters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_cmd_table[hash_index] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_cmd_table_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_redrive_io - Used to redrive IO on connections in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a full feature state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_redrive_io(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_CONN_STATE_FULL_FEATURE(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_state)) {
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng (void) iscsi_thread_send_wakeup(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_tx_thread);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_machine -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 7.3.1 Session State Diagram for an Initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Symbolic Names for States:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Q1: FREE - State on instantiation of after cleanup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Q3: LOGGED_IN - Waiting for all session events.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Q4: FAILED - Waiting for session recovery or session cont.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Q5: IN_FLUSH - A login parameter has changed. We are in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process of flushing active, aborting, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * completed queues. Once flushed the iscsi_ic_thread()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will drop of drop connections (T14) and reconnect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the target with new values.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Q6: FLUSHED - Active, Aborting and Completed Queues flushed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Awaiting reconnect or failure. iscsi_tx/ic_threads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are still running and might be timing-out IOs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * State Q3/4 represent the Full Feature Phase operation of the session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The state diagram is as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * ------ (N5/6/7 == NOOP)
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * / Q1 \
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * +------------------------->\ /<-------------+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | ---+--- |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | N5 |N1 |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | +------+ +-------------+ | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | | V V | V |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | | ----+-- -----+ |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * |N6|N5/7 / Q4 \ / Q3 \(N6 == NOOP) |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * +--+-----\ /----+--->\ /-----+---------+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | ------- /N1 -+---- | N3|
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | (N7 == NOOP) / N7| ^ N1/3/5| |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | / | +-------+ |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | +-------+ / | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | | V / v |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * | | ------- -+---- |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * |N6|N6 / Q6 \ N5 / Q5 \ |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * +--+-----\ /<--------\ /-----+---------+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * ------- ------ | N3
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * (N7 == NOOP) ^ N1/3/5|
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * +-------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The state transition table is as follows:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * +------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * |Q1 |Q3 |Q4 |Q5 |Q6 |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * Q1 |N5/6/7|N1 | - | | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * Q3 |N3 |N1/3/5|N5 |N7 | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * Q4 |N6 |N1 |N5/7| | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * Q5 |N3 | | |N1/3/5/7|N6 |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * Q6 |N6 |N1 |N6/7| | |
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -----+------+------+----+--------+----+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Event definitions:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N1: A connection logged in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N3: A connection logged out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N5: A connection failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Any caller to the state machine (and so as a state writer) must
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * enter the state zone before calling this function, and vice versa
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * any caller that doesn't change the state machine shouldn't enter
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * the zone, and should act as a reader for a better performance.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * The handler of state transition shouldn't try to enter the state
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * zone in the same thread or dead lock will occur.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_machine(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ASSERT(rw_read_locked(&isp->sess_state_rwlock) == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE3(event, iscsi_sess_t *, isp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, iscsi_sess_state_str(isp->sess_state),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, iscsi_sess_event_str(event));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Audit event */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_event(&isp->sess_state_audit,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap SAS_ISCSI_SESS, isp->sess_state, event, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_prev_state = isp->sess_state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state_lbolt = ddi_get_lbolt();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_SESS_LOG(CE_NOTE,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng "DEBUG: sess_state: isp: %p state: %d event: %d event count: %d",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (void *)isp, isp->sess_state, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (isp->sess_state) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FREE:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_free(isp, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_LOGGED_IN:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_logged_in(isp, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FAILED:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_failed(isp, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_IN_FLUSH:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_in_flush(isp, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FLUSHED:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_flushed(isp, event, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Audit state change */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (isp->sess_prev_state != isp->sess_state) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_state_change(&isp->sess_state_audit,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap SAS_ISCSI_SESS, isp->sess_prev_state, isp->sess_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_str -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_state_str(iscsi_sess_state_t state)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (state) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FREE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("free");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_LOGGED_IN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("logged_in");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FAILED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_IN_FLUSH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("in_flush");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_STATE_FLUSHED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("flushed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | Internal Session Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_free -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_free(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t enum_result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state == ISCSI_SESS_STATE_FREE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch on event change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N1: A connection logged in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_state = ISCSI_SESS_STATE_LOGGED_IN;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China cmn_err(CE_NOTE,
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China "!iscsi session(%u) %s online\n",
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_oid, isp->sess_name);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_request(isp, B_TRUE,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result == ISCSI_SESS_ENUM_SUBMITTED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_query(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result != ISCSI_SESS_ENUM_COMPLETE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_warn(isp, enum_result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China /*
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -N5: A connection failed
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China */
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China case ISCSI_SESS_EVENT_N5:
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China /* NOOP - not connected */
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China break;
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - not connected */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All other events are invalid for this state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_logged_in -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_logged_in(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t enum_result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state == ISCSI_SESS_STATE_LOGGED_IN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch on event change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N1: At least one transport connection reached the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LOGGED_IN state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A different connection already logged in. If the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session is NORMAL, just re-enumerate the session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_request(isp, B_TRUE, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result == ISCSI_SESS_ENUM_SUBMITTED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result = iscsi_sess_enum_query(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result != ISCSI_SESS_ENUM_COMPLETE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_warn(isp, enum_result);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N3: A connection logged out.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N3:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N5: A connection failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N5:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MC/S: If this is the last connection to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail then move the the failed state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (event == ISCSI_SESS_EVENT_N3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FREE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no longer connected reset nego tpgt */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_tpgt_nego = ISCSI_DEFAULT_TPGT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_flush(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (event == ISCSI_SESS_EVENT_N3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "!iscsi session(%u) %s offline\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
55364d2b1de5a05a650d36091458090f7209072eJack Meng /*
55364d2b1de5a05a650d36091458090f7209072eJack Meng * During the process of offlining the LUNs
55364d2b1de5a05a650d36091458090f7209072eJack Meng * our ic thread might be calling back into
55364d2b1de5a05a650d36091458090f7209072eJack Meng * the driver via a target driver failure
55364d2b1de5a05a650d36091458090f7209072eJack Meng * path to do a reset or something
55364d2b1de5a05a650d36091458090f7209072eJack Meng * we need to release the sess_state_mutex
55364d2b1de5a05a650d36091458090f7209072eJack Meng * while we are killing these threads so
55364d2b1de5a05a650d36091458090f7209072eJack Meng * they don't get deadlocked.
55364d2b1de5a05a650d36091458090f7209072eJack Meng */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_offline_luns(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_enter(&isp->sess_reset_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China isp->sess_reset_in_progress = B_FALSE;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_exit(&isp->sess_reset_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China /* update busy luns if needed */
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China iscsi_sess_update_busy_luns(isp, B_TRUE);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - Not last connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_IN_FLUSH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All other events are invalid for this state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_failed -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_failed(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t enum_result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state == ISCSI_SESS_STATE_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch on event change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* -N1: A session continuation attempt succeeded */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_state = ISCSI_SESS_STATE_LOGGED_IN;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_request(isp, B_TRUE,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result == ISCSI_SESS_ENUM_SUBMITTED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_query(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result != ISCSI_SESS_ENUM_COMPLETE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_warn(isp, enum_result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China /*
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China * -N5: A connection failed
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China */
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China case ISCSI_SESS_EVENT_N5:
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China /* NOOP - not connected */
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China break;
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FREE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "!iscsi session(%u) %s offline\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_offline_luns(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - not connected */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All other events are invalid for this state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_in_flush -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_in_flush(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state == ISCSI_SESS_STATE_IN_FLUSH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch on event change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* -N1: A session continuation attempt succeeded */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - connections already online */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N3: A connection logged out.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N3:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N5: A connection failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N5:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * MC/S: If this is the last connection to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fail then move the the failed state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (event == ISCSI_SESS_EVENT_N3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FREE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FLUSHED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no longer connected reset nego tpgt */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_tpgt_nego = ISCSI_DEFAULT_TPGT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_flush(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (event == ISCSI_SESS_EVENT_N3) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "!iscsi session(%u) %s offline\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
55364d2b1de5a05a650d36091458090f7209072eJack Meng /*
55364d2b1de5a05a650d36091458090f7209072eJack Meng * During the process of offlining the LUNs
55364d2b1de5a05a650d36091458090f7209072eJack Meng * our ic thread might be calling back into
55364d2b1de5a05a650d36091458090f7209072eJack Meng * the driver via a target driver failure
55364d2b1de5a05a650d36091458090f7209072eJack Meng * path to do a reset or something
55364d2b1de5a05a650d36091458090f7209072eJack Meng * we need to release the sess_state_mutex
55364d2b1de5a05a650d36091458090f7209072eJack Meng * while we are killing these threads so
55364d2b1de5a05a650d36091458090f7209072eJack Meng * they don't get deadlocked.
55364d2b1de5a05a650d36091458090f7209072eJack Meng */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_offline_luns(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_enter(&isp->sess_reset_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China isp->sess_reset_in_progress = B_FALSE;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_exit(&isp->sess_reset_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China /* update busy luns if needed */
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China iscsi_sess_update_busy_luns(isp, B_TRUE);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - Not last connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - Already attempting to update */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All other events are invalid for this state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_state_flushed -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_flushed(iscsi_sess_t *isp, iscsi_sess_event_t event,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t enum_result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state == ISCSI_SESS_STATE_FLUSHED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch on event change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* -N1: A session continuation attempt succeeded */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
08f2684508c2468cb3fd0341c4dbaf48bc02a5a2bing zhao - Sun Microsystems - Beijing China isp->sess_state = ISCSI_SESS_STATE_LOGGED_IN;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_request(isp, B_TRUE,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result == ISCSI_SESS_ENUM_SUBMITTED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_query(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (enum_result != ISCSI_SESS_ENUM_COMPLETE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enum_warn(isp, enum_result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N6: Session state timeout occurred, or a session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reinstatement cleared this session instance. This results in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the freeing of all associated resources and the session state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is discarded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_state = ISCSI_SESS_STATE_FREE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_downgrade(&isp->sess_state_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "!iscsi session(%u) %s offline\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_offline_luns(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -N7: Login parameters for session have changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Re-negeotation required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOOP - not connected */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All other events are invalid for this state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_event_str -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_event_str(iscsi_sess_event_t event)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (event) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("N1");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N3:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("N3");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N5:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("N5");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N6:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("N6");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_SESS_EVENT_N7:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("N7");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_thread_create -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_threads_create(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char th_name[ISCSI_TH_MAX_NAME_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Completion thread creation. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(th_name, sizeof (th_name) - 1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_SESS_IOTH_NAME_FORMAT, ihp->hba_oid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid) >= sizeof (th_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_ic_thread = iscsi_thread_create(ihp->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte th_name, iscsi_ic_thread, isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_ic_thread == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_thread_start(isp->sess_ic_thread);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_enumeration - This function is used to drive the enumeration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of LUs on a session. It will first prepare the target by sending test
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unit ready commands, then it will issue a report luns. If the report
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * luns is successful then it will process all the luns in the report.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If report luns is not successful we will do a stepping enumeration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of luns until no more luns are found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_enumeration(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_task_t *itp = (iscsi_task_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rval = ISCSI_STATUS_SUCCESS;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t enum_result = ISCSI_SESS_ENUM_COMPLETE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count = itp->t_event_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(itp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = (iscsi_sess_t *)itp->t_arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Send initial TEST_UNIT_READY to target. If it fails this we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stop our enumeration as the target is not responding properly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rval = iscsi_sess_testunitready(isp, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now we know the target is ready start our enumeration with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * REPORT LUNs, If this fails we will have to fall back to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stepping
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rval = iscsi_sess_reportluns(isp, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * report luns failed so lets just check for LUN 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will match fcp's enumeration support and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * avoid issues with older devices like the A5K that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * respond poorly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_lun_list == NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_inquiry(isp, 0, 0, event_count,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng enum_result = ISCSI_SESS_ENUM_TUR_FAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(itp, sizeof (iscsi_task_t));
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_enum_result_count != 0) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_DONE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng } else {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_FREE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result = enum_result;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_broadcast(&isp->sess_enum_cv);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_testunitready - This is used during enumeration to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ensure an array is ready to be enumerated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_testunitready(iscsi_sess_t *isp, uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rval = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct uscsi_cmd ucmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char cdb[CDB_GROUP0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* loop until successful sending test unit ready or retries out */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while ((retries++ < 3) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (isp->sess_state_event_count == event_count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cdb is all zeros */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&cdb[0], CDB_GROUP0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup uscsi cmd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ucmd, sizeof (struct uscsi_cmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = iscsi_sess_enum_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = &cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* send test unit ready to lun zero on this session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_handle_passthru(isp, 0, &ucmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If passthru was successful then we were able to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * communicate with the target, continue enumeration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_SIZE 8
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_MASK 0xC0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_PERIPHERAL 0x00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_FLAT_SPACE 0x40
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT 0x80
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_EXTENDED_UNIT 0xC0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT_2B 0x00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT_4B 0x01
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT_6B 0x10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT_8B 0x20
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT_SIZE 0x30
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_reportluns - This is used during enumeration to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ensure an array is ready to be enumerated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_reportluns(iscsi_sess_t *isp, uint32_t event_count)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rval = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct uscsi_cmd ucmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char cdb[CDB_GROUP5];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int buf_len = sizeof (struct scsi_inquiry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lun_list_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t lun_num = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t lun_addr_type = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lun_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lun_start = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lun_total = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retries = 0;
18f21261ca18fa291ada857e650de7bf4323a467andrew.rutz@sun.com iscsi_lun_t *ilp_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte replun_data_t *saved_replun_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Attempt to send report luns until we successfully
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get all the data or the retries run out.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while ((retries++ < 3) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (isp->sess_state_event_count == event_count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate our buffer based on current buf_len.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buf_len may change after we received a response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from the target.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = kmem_zalloc(buf_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup cdb */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&cdb, CDB_GROUP5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[0] = SCMD_REPORT_LUNS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[6] = (buf_len & 0xff000000) >> 24;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[7] = (buf_len & 0x00ff0000) >> 16;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[8] = (buf_len & 0x0000ff00) >> 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[9] = (buf_len & 0x000000ff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup uscsi cmd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ucmd, sizeof (struct uscsi_cmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_flags = USCSI_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = iscsi_sess_enum_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (char *)&cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (char *)buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = buf_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* send uscsi cmd to lun 0 on session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_handle_passthru(isp, 0, &ucmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If passthru successful but not scsi status update istatus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ucmd.uscsi_status != STATUS_GOOD)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ISCSI_STATUS_USCSI_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If successful, check if we have all the data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* total data - header (SCSI_REPORTLUNS_ADDRESS_SIZE) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_list_length = htonl(*(uint32_t *)buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf_len >= lun_list_length +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SCSI_REPORTLUNS_ADDRESS_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we have all the data, were done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We don't have all the data. free up the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory for the next pass and update the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buf_len
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(buf, buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf_len = lun_list_length +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SCSI_REPORTLUNS_ADDRESS_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_state_event_count != event_count) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (buf != NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(buf, buf_len);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng buf = NULL;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (rval);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* If not successful go no further */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(buf, buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find out the number of luns returned by the SCSI ReportLun call
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and allocate buffer space
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_total = lun_list_length / SCSI_REPORTLUNS_ADDRESS_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte saved_replun_ptr = kmem_zalloc(lun_total * sizeof (replun_data_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * walk the isp->sess_lun_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for each lun in this list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look to see if this lun is in the SCSI ReportLun list we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just retrieved
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * if it is in the SCSI ReportLun list and it is already ONLINE or
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * if it is in the SCSI ReportLun list and it is OFFLINE or
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * if it isn't in the SCSI ReportLunlist or then
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * issue the iscsi_sess_inquiry() to handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as we walk the SCSI ReportLun list, we save this lun information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * into the buffer we just allocated. This will save us from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * having to figure out this information later
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_start = 0;
dda652d31edb28ea625fc3f3a72e303ee678aeb6andrew.rutz@sun.com rw_enter(&isp->sess_lun_list_rwlock, RW_WRITER);
18f21261ca18fa291ada857e650de7bf4323a467andrew.rutz@sun.com for (ilp = isp->sess_lun_list; ilp; ilp = ilp_next) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_state_event_count != event_count)
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng break;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
18f21261ca18fa291ada857e650de7bf4323a467andrew.rutz@sun.com ilp_next = ilp->lun_next;
18f21261ca18fa291ada857e650de7bf4323a467andrew.rutz@sun.com
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap for (lun_count = lun_start; lun_count < lun_total;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap lun_count++) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * if the first lun in saved_replun_ptr buffer has
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * already been found we can move on and do not
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * have to check this lun in the future
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_count == lun_start &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte saved_replun_ptr[lun_start].lun_found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_start++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check to see if the lun we are looking for is in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * saved_replun_ptr buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it is, process the lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it isn't, then we must go to SCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Report Lun buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we retrieved to get lun info
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if ((saved_replun_ptr[lun_count].lun_valid
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng == B_TRUE) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (saved_replun_ptr[lun_count].lun_num
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng == ilp->lun_num)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * the lun we are looking for is found,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * give it to iscsi_sess_inquiry()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_exit(&isp->sess_lun_list_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_inquiry(isp, ilp->lun_num,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_addr_type,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count, ilp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_enter(&isp->sess_lun_list_rwlock,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng RW_WRITER);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_found
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * lun information is not found in the
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * saved_replun buffer, retrieve lun
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * information from the SCSI Report Lun buffer
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * and store this information in the
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * saved_replun buffer
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (retrieve_lundata(lun_count, buf, isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &lun_num, &lun_addr_type) !=
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_STATUS_SUCCESS) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng continue;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_valid = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_num = lun_num;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_addr_type =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng lun_addr_type;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp->lun_num == lun_num) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * lun is found in the SCSI Report Lun
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * buffer, give it to inquiry
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_exit(&isp->sess_lun_list_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_inquiry(isp, lun_num,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng lun_addr_type, event_count, ilp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_enter(&isp->sess_lun_list_rwlock,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng RW_WRITER);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_found
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_count == lun_total) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * this lun we found in the sess->lun_list does
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * not exist anymore, need to offline this lun
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng DTRACE_PROBE2(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng sess_reportluns_lun_no_longer_exists,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, ilp->lun_num, int, ilp->lun_state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
dda652d31edb28ea625fc3f3a72e303ee678aeb6andrew.rutz@sun.com (void) iscsi_lun_destroy(ihp, ilp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look for new luns that we found in the SCSI Report Lun buffer that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we did not have in the sess->lun_list and add them into the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lun_count = lun_start; lun_count < lun_total; lun_count++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (saved_replun_ptr[lun_count].lun_valid == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lun information is not in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * saved_replun buffer, retrieve
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it from the SCSI Report Lun buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieve_lundata(lun_count, buf, isp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &lun_num, &lun_addr_type) != ISCSI_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * lun information is in the saved_replun buffer
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * if this lun has been found already,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * then we can move on
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (saved_replun_ptr[lun_count].lun_found == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_num = saved_replun_ptr[lun_count].lun_num;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng lun_addr_type =
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng saved_replun_ptr[lun_count].lun_addr_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* New luns found should not conflict with existing luns */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_lun_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilp = isp->sess_lun_list; ilp; ilp = ilp->lun_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_num == lun_num) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* new lun found, add this lun */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_inquiry(isp, lun_num, lun_addr_type,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "!Duplicate Lun Number(%d) recieved from "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Target(%s)", lun_num, isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (buf != NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(buf, buf_len);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(saved_replun_ptr, lun_total * sizeof (replun_data_t));
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISCSI_MAX_INQUIRY_BUF_SIZE 0xFF
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISCSI_MAX_INQUIRY_RETRIES 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_inquiry - Final processing of a LUN before we create a tgt
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * mapping, if necessary the old lun will be deleted.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * We need to collect the stardard inquiry page and the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * vendor identification page for this LUN. If both of these are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * successful and the identification page contains a NAA or EUI type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we will continue. Otherwise we fail the creation of a tgt for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this LUN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Keep the old lun unchanged if it is online and following things are
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * match, lun_addr_type, lun_type, and lun_guid.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Online the old lun if it is offline/invalid and those three things
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * are match.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Online a new lun if the old lun is offline and any of those three things
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * is not match, and needs to destroy the old first.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Destroy the old lun and online the new lun if the old is online/invalid
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * and any of those three things is not match, and then online the new lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_inquiry(iscsi_sess_t *isp, uint16_t lun_num, uint8_t lun_addr_type,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count, iscsi_lun_t *ilp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct uscsi_cmd ucmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t cdb[CDB_GROUP0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t inq_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *inq83;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t inq83_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_devid_t devid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *guid = NULL;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_hba_t *ihp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_status_t status = ISCSI_STATUS_SUCCESS;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng boolean_t inq_ready = B_FALSE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng boolean_t inq83_ready = B_FALSE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng boolean_t nochange = B_FALSE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uchar_t lun_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ihp = isp->sess_hba;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq = kmem_zalloc(ISCSI_MAX_INQUIRY_BUF_SIZE, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq83 = kmem_zalloc(ISCSI_MAX_INQUIRY_BUF_SIZE, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp == NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* easy case, just to create the new lun */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto sess_inq;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp->lun_addr_type != lun_addr_type) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto offline_old;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto sess_inq;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengoffline_old:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_state_event_count != event_count) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto inq_done;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng status = iscsi_lun_destroy(ihp, ilp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (status != ISCSI_STATUS_SUCCESS) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* have to abort the process */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cmn_err(CE_WARN, "iscsi session(%u) is unable to offline"
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng " obsolete logical unit %d", isp->sess_oid, lun_num);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto inq_done;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ilp = NULL;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengsess_inq:
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (inq_ready == B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto sess_inq83;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STANDARD INQUIRY - We need the standard inquiry information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to feed into the scsi_hba_nodename_compatible_get function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is used to detemine which driver will bind
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on top of us, via the compatible id.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&cdb, CDB_GROUP0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[0] = SCMD_INQUIRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[4] = ISCSI_MAX_INQUIRY_BUF_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ucmd, sizeof (struct uscsi_cmd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_flags = USCSI_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = iscsi_sess_enum_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (char *)&cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (char *)inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = ISCSI_MAX_INQUIRY_BUF_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Attempt to get inquiry information until successful or retries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retries = 0;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while ((retries++ < ISCSI_MAX_INQUIRY_RETRIES) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (isp->sess_state_event_count == event_count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* issue passthru */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_handle_passthru(isp, lun_num, &ucmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we were successful but scsi stat failed update istatus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ucmd.uscsi_status != STATUS_GOOD)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ISCSI_STATUS_USCSI_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If successful break */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq_len = ISCSI_MAX_INQUIRY_BUF_SIZE - ucmd.uscsi_resid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* loop until we are successful or retries run out */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If failed don't continue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%u) unable to enumerate "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "logical unit - inquiry failed lun %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto inq_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng inq_ready = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengsess_inq83:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * T-10 SPC Section 6.4.2. Standard INQUIRY Peripheral
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * qualifier of 000b is the only type we should attempt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to plumb under the IO stack.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((inq[0] & SCSI_INQUIRY_PQUAL_MASK) != 0x00) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* shouldn't enumerate, destroy the old one if exists */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp != NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto offline_old;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto inq_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * If lun type has changed
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng lun_type = ((struct scsi_inquiry *)inq)->inq_dtype & DTYPE_MASK;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if ((ilp != NULL) && (ilp->lun_type != lun_type)) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto offline_old;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (inq83_ready == B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto guid_ready;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * VENDOR IDENTIFICATION INQUIRY - This will be used to identify
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a unique lunId. This Id is passed to the mdi alloc calls so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we can properly plumb into scsi_vhci/mpxio.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&cdb, CDB_GROUP0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[0] = SCMD_INQUIRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[1] = 0x01; /* EVP bit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[2] = 0x83;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb[4] = ISCSI_MAX_INQUIRY_BUF_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_flags = USCSI_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_timeout = iscsi_sess_enum_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdb = (char *)&cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_cdblen = CDB_GROUP0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_bufaddr = (char *)inq83;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_buflen = ISCSI_MAX_INQUIRY_BUF_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Attempt to get inquiry information until successful or retries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retries = 0;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while ((retries++ < ISCSI_MAX_INQUIRY_RETRIES) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (isp->sess_state_event_count == event_count)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* issue passthru command */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_handle_passthru(isp, lun_num, &ucmd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we were successful but scsi stat failed update istatus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ucmd.uscsi_status != STATUS_GOOD)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ISCSI_STATUS_USCSI_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Break if successful */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq83_len = ISCSI_MAX_INQUIRY_BUF_SIZE -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ucmd.uscsi_resid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we were successful collecting page 83 data attempt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to generate a GUID. If no GUID can be generated then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the logical unit will skip attempt to plumb under
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scsi_vhci/mpxio.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(rval)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create DEVID from inquiry data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_devid_scsi_encode(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DEVID_SCSI_ENCODE_VERSION_LATEST, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq, inq_len, NULL, 0, inq83, inq83_len, &devid) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* extract GUID from DEVID */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte guid = ddi_devid_to_guid(devid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* devid no longer needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_devid_free(devid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng inq83_ready = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengguid_ready:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp != NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if ((guid == NULL) && (ilp->lun_guid == NULL)) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng nochange = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if ((guid != NULL) && (ilp->lun_guid != NULL) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ((strlen(guid) + 1) == ilp->lun_guid_size) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (bcmp(guid, ilp->lun_guid, ilp->lun_guid_size) == 0)) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng nochange = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (nochange != B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng goto offline_old;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ilp->lun_state & (ISCSI_LUN_STATE_OFFLINE |
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_LUN_STATE_INVALID)) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_state_event_count == event_count) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (void) iscsi_lun_online(ihp, ilp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng } else {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_state_event_count == event_count) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (void) iscsi_lun_create(isp, lun_num, lun_addr_type,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (struct scsi_inquiry *)inq, guid);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Menginq_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (guid != NULL) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* guid is no longer needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_devid_free_guid(guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free up memory now that we are done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(inq, ISCSI_MAX_INQUIRY_BUF_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(inq83, ISCSI_MAX_INQUIRY_BUF_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretrieve_lundata(uint32_t lun_count, unsigned char *buf, iscsi_sess_t *isp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *lun_num, uint8_t *lun_addr_type)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lun_idx = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(lun_num != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(lun_addr_type != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_idx = (lun_count + 1) * SCSI_REPORTLUNS_ADDRESS_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* determine report luns addressing type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (buf[lun_idx] & SCSI_REPORTLUNS_ADDRESS_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Vendors in the field have been found to be concatenating
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bus/target/lun to equal the complete lun value instead
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of switching to flat space addressing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 00b - peripheral device addressing method */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCSI_REPORTLUNS_ADDRESS_PERIPHERAL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 10b - logical unit addressing method */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCSI_REPORTLUNS_ADDRESS_LOGICAL_UNIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 01b - flat space addressing method */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCSI_REPORTLUNS_ADDRESS_FLAT_SPACE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* byte0 bit0-5=msb lun byte1 bit0-7=lsb lun */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lun_addr_type = (buf[lun_idx] &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SCSI_REPORTLUNS_ADDRESS_MASK) >> 6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lun_num = (buf[lun_idx] & 0x3F) << 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *lun_num |= buf[lun_idx + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default: /* protocol error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%u) unable "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "to enumerate logical units - report "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "luns returned an unsupported format",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_flush - flushes remaining pending io on the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_flush(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_cmd_t *icmdp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state != ISCSI_SESS_STATE_LOGGED_IN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Flush out any remaining commands in the pending
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&isp->sess_queue_pending.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icmdp = isp->sess_queue_pending.head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icmdp != NULL) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China if (isp->sess_state == ISCSI_SESS_STATE_FAILED) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_enter(&icmdp->cmd_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China if (icmdp->cmd_type == ISCSI_CMD_TYPE_SCSI) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China icmdp->cmd_un.scsi.pkt_stat |= STAT_ABORTED;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China }
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_exit(&icmdp->cmd_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China }
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_cmd_state_machine(icmdp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CMD_EVENT_E7, isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icmdp = isp->sess_queue_pending.head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&isp->sess_queue_pending.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_offline_luns - offline all this sessions luns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_offline_luns(iscsi_sess_t *isp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_state != ISCSI_SESS_STATE_LOGGED_IN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_lun_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = isp->sess_lun_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ilp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_lun_offline(ihp, ilp, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_sess_get_by_target - return the session structure for based on a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in target oid and hba instance. NOTE: There may be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multiple sessions associated with any given target. In this case,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we will return the first matching session. This function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is intended to be used in retrieving target info that is constant
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * across sessions (target name, alias, etc.).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_sess_get_by_target(uint32_t target_oid, iscsi_hba_t *ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t **ispp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ispp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if we already created this session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp; isp = isp->sess_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Look for a session associated to the given target.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the first one found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_target_oid == target_oid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Found matching session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If not null this session is already available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Existing session, return it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ispp = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing Chinastatic void
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing Chinaiscsi_sess_update_busy_luns(iscsi_sess_t *isp, boolean_t clear)
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China{
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China iscsi_lun_t *ilp;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China iscsi_hba_t *ihp;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ASSERT(isp != NULL);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ihp = isp->sess_hba;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ASSERT(ihp != NULL);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China rw_enter(&isp->sess_lun_list_rwlock, RW_WRITER);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ilp = isp->sess_lun_list;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China while (ilp != NULL) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China if (clear == B_TRUE) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ~ISCSI_LUN_STATE_BUSY;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China } else {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_BUSY;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China }
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China ilp = ilp->lun_next;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China }
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China rw_exit(&isp->sess_lun_list_rwlock);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China}
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Submits the scsi enumeration request. Returns
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * ISCSI_SESS_ENUM_SUBMITTED upon success, or others if failures are met.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * If the request is submitted and the wait is set to B_TRUE, the caller
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * must call iscsi_sess_enum_query at a later time to unblock next enum
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_enum_result_t
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_enum_request(iscsi_sess_t *isp, boolean_t wait,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_task_t *itp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng itp = kmem_zalloc(sizeof (iscsi_task_t), KM_SLEEP);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng itp->t_arg = isp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng itp->t_event_count = event_count;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while ((isp->sess_enum_status != ISCSI_SESS_ENUM_FREE) &&
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng (isp->sess_enum_status != ISCSI_SESS_ENUM_INPROG)) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_wait(&isp->sess_enum_cv, &isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_enum_status == ISCSI_SESS_ENUM_INPROG) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng /* easy case */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (wait == B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result_count ++;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(itp, sizeof (iscsi_task_t));
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (ISCSI_SESS_ENUM_SUBMITTED);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ASSERT(isp->sess_enum_status == ISCSI_SESS_ENUM_FREE);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ASSERT(isp->sess_enum_result_count == 0);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_INPROG;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ddi_taskq_dispatch(isp->sess_enum_taskq,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enumeration, itp, DDI_SLEEP) != DDI_SUCCESS) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_FREE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng kmem_free(itp, sizeof (iscsi_task_t));
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (ISCSI_SESS_ENUM_SUBFAIL);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (wait == B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result_count ++;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (ISCSI_SESS_ENUM_SUBMITTED);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng}
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Wait and query the result of the enumeration.
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * The last caller is responsible for kicking off the DONE status
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_enum_result_t
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_enum_query(iscsi_sess_t *isp) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_enum_result_t ret = ISCSI_SESS_ENUM_IOFAIL;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while (isp->sess_enum_status != ISCSI_SESS_ENUM_DONE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_wait(&isp->sess_enum_cv, &isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ret = isp->sess_enum_result;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_result_count --;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (isp->sess_enum_result_count == 0) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_enum_status = ISCSI_SESS_ENUM_FREE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_broadcast(&isp->sess_enum_cv);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_enum_lock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng return (ret);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng}
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengstatic void
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_enum_warn(iscsi_sess_t *isp, iscsi_enum_result_t r) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cmn_err(CE_WARN, "iscsi session (%u) enumeration fails - %s",
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_oid, iscsi_sess_enum_warn_msgs[r]);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng}
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengvoid
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_enter_state_zone(iscsi_sess_t *isp) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng while (isp->sess_state_hasw == B_TRUE) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_wait(&isp->sess_state_wcv, &isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng }
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_state_hasw = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_enter(&isp->sess_state_rwlock, RW_WRITER);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng}
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengvoid
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_exit_state_zone(iscsi_sess_t *isp) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng rw_exit(&isp->sess_state_rwlock);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng isp->sess_state_hasw = B_FALSE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng cv_signal(&isp->sess_state_wcv);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&isp->sess_state_wmutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng}