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/*
c465437abaf8cc10b6cafec2fc1576bc770537baallan * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <FCHBAPort.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <Exceptions.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <Trace.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sun_fc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <iostream>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <iomanip>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stropts.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <dirent.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/fc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/fcio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/ulp/fcp_util.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/ulp/fcsm.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/impl/fc_error.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/fc_appif.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/commands.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/commands.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/sense.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/inquiry.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/status.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <FCHBANPIVPort.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusing namespace std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst int FCHBAPort::MAX_FCIO_MSG_LEN = 256;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst string FCHBAPort::FCSM_DRIVER_PATH = "/devices/pseudo/fcsm@0:fcsm";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst string FCHBAPort::FCP_DRIVER_PATH = "/devices/pseudo/fcp@0:fcp";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Interpret the error code in the fcio_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * message must be at least MAX_FCIO_MSG_LEN in length.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteFCHBAPort::transportError(uint32_t fcio_errno, char *message) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("transportError");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string fcioErrorString;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (message == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("NULL routine argument");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (fcio_errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (uint32_t)FC_FAILURE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "general failure";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (uint32_t)FC_FAILURE_SILENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "general failure but fail silently";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "successful completion";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_CAP_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "FCA capability error";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_CAP_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "FCA capability unsettable";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_CAP_SETTABLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "FCA capability settable";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_UNBOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "unbound stuff";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_NOMEM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "allocation error";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADPACKET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid packet specified/supplied";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_OFFLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "I/O resource unavailable";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_OLDPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "operation on non-loop port";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_NO_MAP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "requested map unavailable";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TRANSPORT_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "unable to transport I/O";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ELS_FREJECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "ELS rejected by a Fabric";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ELS_PREJECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "ELS rejected by an N_port";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ELS_BAD:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "ELS rejected by FCA/fctl";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ELS_MALFORMED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "poorly formed ELS request";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TOOMANY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "resource request too large";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_UB_BADTOKEN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid unsolicited buffer token";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_UB_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid unsol buf request";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_UB_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "buffer already in use";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADULP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "Unknown ulp";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADTYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "ULP not registered to handle this FC4 type";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_UNCLAIMED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "request or data not claimed";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ULP_SAMEMODULE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "module already in use";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ULP_SAMETYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "FC4 module already in use";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ABORTED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "request aborted";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ABORT_FAILED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "abort request failed";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADEXCHANGE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "exchange doesn�t exist";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADWWN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "WWN not recognized";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADDEV:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "device unrecognized";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADCMD:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid command issued";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADOBJECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid object requested";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "invalid port specified";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_NOTTHISPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "resource not at this port";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_PREJECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "reject at remote N_Port";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_FREJECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "reject at remote Fabric";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_PBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "remote N_Port busy";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_FBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "remote Fabric busy";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_ALREADY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "already logged in";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_LOGINREQ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "login required";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_RESETFAIL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "reset failed";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_INVALID_REQUEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "request is invalid";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_OUTOFBOUNDS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "port number is out of bounds";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TRAN_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "command transport busy";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_STATEC_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "port driver currently busy";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_DEVICE_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "transport working on this device";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_DEVICE_NOT_TGT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString = "device is not a SCSI target";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(message, MAX_FCIO_MSG_LEN, "Unknown error code 0x%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(message, MAX_FCIO_MSG_LEN, "%s", fcioErrorString.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortereportSense(struct scsi_extended_sense *sense, const char *routine) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("reportSense");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string msg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sense) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("NULL sense argument passed.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!routine) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("NULL routine argument passed.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("SCSI FAILURE");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (sense->es_key) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NO_SENSE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "No sense";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_RECOVERABLE_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Recoverable error";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_NOT_READY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Not ready";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_MEDIUM_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Medium error";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_HARDWARE_ERROR:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Hardware error";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ILLEGAL_REQUEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Illegal request";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_UNIT_ATTENTION:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Unit attention";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_DATA_PROTECT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Data protect";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_BLANK_CHECK:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Blank check";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_VENDOR_UNIQUE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Vendor Unique";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_COPY_ABORTED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Copy aborted";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_ABORTED_COMMAND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Aborted command";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_EQUAL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Equal";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_VOLUME_OVERFLOW:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Volume overflow";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_MISCOMPARE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Miscompare";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case KEY_RESERVED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "Reserved";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg = "unknown sense key";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("\tSense key: %s", msg.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("\tASC = 0x%x", sense->es_add_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("\tASCQ = 0x%x", sense->es_qual_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue a SCSI pass thru command.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns a scsi status value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendSCSIPassThru(struct fcp_scsi_cmd *fscsi,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *responseSize, HBA_UINT32 *senseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 *scsiStatus) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendSCSIPassThru");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char fcioErrorString[MAX_FCIO_MSG_LEN] = "";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hrtime_t start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hrtime_t end;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctl_errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte double duration;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte la_wwn_t wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fscsi == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiStatus == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&wwn, fscsi->scsi_fc_pwwn.raw_wwn, sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_fc_port_num = instanceNumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = HBA::_open(FCP_DRIVER_PATH, O_RDONLY | O_NDELAY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctl_errno = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCP_TGT_SEND_SCSI, fscsi) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save off errno */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctl_errno = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * collect SCSI status first regrardless of the value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 is a good status so this should be okay
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *scsiStatus = fscsi->scsi_bufstatus & STATUS_MASK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transportError(fscsi->scsi_fc_status, fcioErrorString);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Did we get a check condition? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fscsi->scsi_bufstatus & STATUS_MASK) == STATUS_CHECK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *senseSize = fscsi->scsi_rqlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw CheckConditionException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fscsi->scsi_fc_status == FC_DEVICE_NOT_TGT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fcp driver returns FC_DEVICE_NOT_TGT when the node is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scsi-capable like remote hba nodes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw NotATargetException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fscsi->scsi_fc_status == FC_INVALID_LUN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InvalidLUNException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ioctl_errno == EBUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BusyException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ioctl_errno == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw TryAgainException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ioctl_errno == ENOTSUP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw NotSupportedException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ioctl_errno == ENOENT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw UnavailableException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IOError(this, wwnConversion(wwn.raw_wwn),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Just in case, check for a check-condition state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fscsi->scsi_bufstatus & STATUS_MASK) == STATUS_CHECK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *scsiStatus = fscsi->scsi_bufstatus & STATUS_MASK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *senseSize = fscsi->scsi_rqlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw CheckConditionException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Record the response data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *scsiStatus = fscsi->scsi_bufstatus & STATUS_MASK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *responseSize = fscsi->scsi_buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *senseSize = fscsi->scsi_rqlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Do some quick duration calcuations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte duration = end - start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte duration /= HR_SECOND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Total SCSI IO time for HBA %s "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "target %016llx was %.4f seconds", getPath().c_str(),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnConversion(wwn.raw_wwn), duration);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Did we have any failure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Ioctl failed for device \"%s\" target %016llx."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Errno: \"%s\"(%d), "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Transport: \"%s\", SCSI Status: 0x%x"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "responseSize = %d, senseSize = %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getPath().c_str(), wwnConversion(fscsi->scsi_fc_pwwn.raw_wwn),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(ioctl_errno), ioctl_errno, fcioErrorString,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *scsiStatus, *responseSize, *senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We may or may not have sense data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reportSense((struct scsi_extended_sense *)fscsi->scsi_rqbufaddr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ROUTINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * constructs the fcp_scsi_cmd struct for SCSI_Inquiry, SendReadCapacity, or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SendReportLUNs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*#include <fcio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcp_util.h>*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinline void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortescsi_cmd_init(struct fcp_scsi_cmd *fscsi, const char *portname, void *reqbuf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t req_len, void *responseBuffer, size_t resp_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *senseBuffer, size_t sense_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("scsi_cmd_init");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_fc_rspcode = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_flags = FCP_SCSI_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_timeout = 10 /* sec */;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_cdbbufaddr = (char *)reqbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_cdblen = (uint32_t) req_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_bufaddr = (char *)responseBuffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_buflen = (uint32_t) resp_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_bufresid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_bufstatus = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_rqbufaddr = (char *)senseBuffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_rqlen = (uint32_t) sense_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi->scsi_rqresid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteFCHBAPort::FCHBAPort(string thePath) : HBAPort() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::FCHBAPort");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Initializing HBA port %s", thePath.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size = 200;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_npiv_port_list_t *pathList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool retry = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bufSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path = lookupControllerPath(thePath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(path.c_str(), "/dev/cfg/c%d", &controllerNumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Unable to lookup controller path and number for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thePath.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path = "/devices";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path += thePath;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path += ":fc";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte controllerNumber = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Fetch the minor number for later use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(path.c_str(), &sbuf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IOError("Unable to stat device path: " + path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte instanceNumber = minor(sbuf.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // This routine is not index based, so we can discard stateChange
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attrs = getPortAttributes(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp, &attrs.PortWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portWWN = ntohll(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp, &attrs.NodeWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodeWWN = ntohll(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // For reference, here's how to dump WWN's through C++ streams.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // cout << "\tPort WWN: " << hex << setfill('0') << setw(16) << portWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // << endl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // cout << "\tNode WWN: " << hex << setfill('0') << setw(16) << nodeWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // << endl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // we should add code here to build NPIVPORT instance
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Get Port's NPIV port list ( include nwwn and pwwn and path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((caddr_t)&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_NPIV_PORT_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retry = false;
c465437abaf8cc10b6cafec2fc1576bc770537baallan bufSize = MAXPATHLEN * (size - 1) + (int) sizeof (fc_hba_npiv_port_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathList = (fc_hba_npiv_port_list_t *) new uchar_t[bufSize];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathList->numAdapters = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = bufSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (char *)pathList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathList->numAdapters > size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Buffer too small for number of NPIV Port.Retry.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = pathList->numAdapters;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retry = true;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (pathList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (retry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Get %d npiv ports", pathList->numAdapters);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Make instance for each NPIV Port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for ( int i = 0; i < pathList->numAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addPort(new FCHBANPIVPort(pathList->hbaPaths[i]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Ignoring partial failure");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (pathList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t FCHBAPort::deleteNPIVPort(uint64_t vportwwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::deleteNPIVPort");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte la_wwn_t lawwn[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof(fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t en_wwn = htonll(vportwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&lawwn[0], &en_wwn, sizeof (en_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_DELETE_NPIV_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (la_wwn_t) * 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&lawwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t FCHBAPort::createNPIVPort(uint64_t vnodewwn, uint64_t vportwwn, uint32_t vindex) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::createNPIVPort");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte la_wwn_t lawwn[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t vportindex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_NPIVCREATEENTRY entrybuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof(fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t en_wwn = htonll(vnodewwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&entrybuf.VNodeWWN, &en_wwn, sizeof (en_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte en_wwn = htonll(vportwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&entrybuf.VPortWWN, &en_wwn, sizeof (en_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entrybuf.vindex = vindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_CREATE_NPIV_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&vportindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (HBA_NPIVCREATEENTRY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&entrybuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (vportindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTNPIVATTRIBUTES FCHBAPort::getPortNPIVAttributes(uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getPortNPIVAttributes");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES attributes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_port_npiv_attributes_t attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof(fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attributes, 0, sizeof(attributes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_ADAPTER_PORT_NPIV_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof(attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stateChange = attrs.lastChange;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.npivflag = attrs.npivflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.NodeWWN, &attrs.NodeWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortWWN, &attrs.PortWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.MaxNumberOfNPIVPorts = attrs.MaxNumberOfNPIVPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberOfNPIVPorts = attrs.NumberOfNPIVPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (attributes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES FCHBAPort::getPortAttributes(uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getPortAttributes");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attributes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_port_attributes_t attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attributes, 0, sizeof (attributes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_ADAPTER_PORT_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stateChange = attrs.lastChange;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortFcId = attrs.PortFcId;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortType = attrs.PortType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortState = attrs.PortState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSpeed = attrs.PortSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.NodeWWN, &attrs.NodeWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortWWN, &attrs.PortWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy((char *)attributes.OSDeviceName, getPath().c_str(), 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (attributes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES FCHBAPort::getDiscoveredAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 discoveredport, uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getDiscoverdAttributes(i)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attributes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_port_attributes_t attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attributes, 0, sizeof (attributes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_DISCOVERED_PORT_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (discoveredport);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&discoveredport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stateChange = attrs.lastChange;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortFcId = attrs.PortFcId;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortType = attrs.PortType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortState = attrs.PortState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSpeed = attrs.PortSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.NodeWWN, &attrs.NodeWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortWWN, &attrs.PortWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (attributes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_PORTATTRIBUTES FCHBAPort::getDiscoveredAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t wwn, uint64_t &stateChange) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getDiscoverdAttributes(p)");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attributes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_port_attributes_t attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte la_wwn_t lawwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attributes, 0, sizeof (attributes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t en_wwn = htonll(wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&lawwn, &en_wwn, sizeof (en_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_PORT_ATTRIBUTES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&lawwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stateChange = attrs.lastChange;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortFcId = attrs.PortFcId;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortType = attrs.PortType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortState = attrs.PortState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedClassofService = attrs.PortSupportedClassofService;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSupportedSpeed = attrs.PortSupportedSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortSpeed = attrs.PortSpeed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.PortMaxFrameSize = attrs.PortMaxFrameSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attributes.NumberofDiscoveredPorts = attrs.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.NodeWWN, &attrs.NodeWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortWWN, &attrs.PortWWN, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.FabricName, &attrs.FabricName, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSupportedFc4Types, &attrs.PortSupportedFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortActiveFc4Types, &attrs.PortActiveFc4Types, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&attributes.PortSymbolicName, &attrs.PortSymbolicName, 256);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (attributes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::getTargetMappings(PHBA_FCPTARGETMAPPINGV2 userMappings) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getTargetMappings");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t total_entries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_ioctl fioctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_hba_target_mappings_t *mappings;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool zeroLength = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (userMappings == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("Null mapping argument ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It's possible they didn't give any space */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (userMappings->NumberOfEntries == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte zeroLength = true;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->NumberOfEntries = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We have to give the driver at least one space */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings = (fc_hba_target_mappings_t *)new uchar_t[
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sizeof (fc_hba_mapping_entry_t)) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (userMappings->NumberOfEntries - 1) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (fc_hba_target_mappings_t)];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mappings == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.noMemory();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fioctl.fp_minor = instanceNumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fioctl.listlen = ((uint32_t) (sizeof (fc_hba_mapping_entry_t))) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (userMappings->NumberOfEntries - 1) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint32_t) sizeof (fc_hba_target_mappings_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fioctl.list = (caddr_t)mappings;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = HBA::_open(FCP_DRIVER_PATH, O_RDONLY | O_NDELAY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Performing IOCTL to fetch mappings");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCP_GET_TARGET_MAPPINGS, &fioctl) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (mappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno == EBUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BusyException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno == EAGAIN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw TryAgainException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno == ENOTSUP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw NotSupportedException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno == ENOENT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw UnavailableException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IOError("Unable to fetch target mappings");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Quickly iterate through and copy the data over to the client
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < userMappings->NumberOfEntries && !zeroLength &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i < mappings->numLuns; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string raw = mappings->entries[i].targetDriver;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (raw.length() <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("Bad target mapping without path, truncating.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ideally, we'd like to ask some standard Solaris interface
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "What is the prefered minor node for this target?"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but no such interface exists today. So, for now,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we just hard-code ":n" for tapes, ":c,raw" for disks,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and ":0" for enclosures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Devices with other generic names will be presented through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * first matching /dev path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((raw.find("/st@") != raw.npos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (raw.find("/tape@") != raw.npos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte raw += ":n";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((raw.find("/ssd@") != raw.npos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (raw.find("/sd@") != raw.npos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (raw.find("/disk@") != raw.npos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte raw += ":c,raw";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((raw.find("/ses@") != raw.npos) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (raw.find("/enclosure@") != raw.npos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte raw += ":0";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Unrecognized target driver (%s), using first matching /dev path",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte raw.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(userMappings->entry[i].ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (userMappings->entry[i].ScsiId.OSDeviceName),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "/devices%s", raw.c_str());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->entry[i].ScsiId.ScsiBusNumber =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte controllerNumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->entry[i].ScsiId.ScsiTargetNumber =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].targetNumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->entry[i].ScsiId.ScsiOSLun =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].osLUN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->entry[i].FcpId.FcId =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].d_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(userMappings->entry[i].FcpId.NodeWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].NodeWWN.raw_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(userMappings->entry[i].FcpId.PortWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].PortWWN.raw_wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->entry[i].FcpId.FcpLun =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].samLUN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(userMappings->entry[i].LUID.buffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->entries[i].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (userMappings->entry[i].LUID.buffer));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Total mappings: %d %08x %08x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappings->numLuns, mappings->entries[i].osLUN, mappings->entries[i].samLUN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // If everything is good, convert paths to sym-links
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mappings->numLuns > 0 && !zeroLength) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (userMappings->NumberOfEntries >= mappings->numLuns) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // User buffer is larger than needed. (All is good)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->NumberOfEntries = mappings->numLuns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte convertToShortNames(userMappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // User buffer is non zero, but too small. Don't bother with links
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->NumberOfEntries = mappings->numLuns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (mappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw MoreDataException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (mappings->numLuns > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Zero length buffer, but we've got mappings
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->NumberOfEntries = mappings->numLuns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (mappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw MoreDataException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // No mappings, no worries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userMappings->NumberOfEntries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (mappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (mappings);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::getRNIDMgmtInfo(PHBA_MGMTINFO info) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::getRNIDMgmtInfo");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status = HBA_STATUS_OK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_rnid_t rnid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (info == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("NULL port management info");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Get the RNID information from the first port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&rnid, 0, sizeof (fc_rnid_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((caddr_t)&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_NODE_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = sizeof (fc_rnid_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)&rnid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Copy out the struct members of rnid into PHBA_MGMTINFO struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->wwn, &(rnid.global_id), sizeof (info->wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->unittype, &(rnid.unit_type), sizeof (info->unittype));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->PortId, &(rnid.port_id), sizeof (info->PortId));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->NumberOfAttachedNodes, &(rnid.num_attached),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (info->NumberOfAttachedNodes));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->IPVersion, &(rnid.ip_version), sizeof (info->IPVersion));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->UDPPort, &(rnid.udp_port), sizeof (info->UDPPort));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->IPAddress, &(rnid.ip_addr), sizeof (info->IPAddress));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&info->TopologyDiscoveryFlags, &(rnid.topo_flags),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (info->TopologyDiscoveryFlags));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendCTPassThru(void *requestBuffer, HBA_UINT32 requestSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *responseBuffer, HBA_UINT32 *responseSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendCTPassThru");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_t minor_node;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hrtime_t start, end;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte double duration;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (requestBuffer == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("NULL request buffer");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (responseBuffer == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("NULL response buffer");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_node = instanceNumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // construct fcio struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fcio, 0, sizeof (fcio_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCSMIO_CT_CMD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_RW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = requestSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (char *)requestBuffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = *responseSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (char *)responseBuffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_alen = sizeof (minor_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_abuf = (char *)&minor_node;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcsm_ioctl(FCSMIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Do some calculations on the duration of the ioctl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte end = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte duration = end - start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte duration /= HR_SECOND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Total CTPASS ioctl call for HBA %s was %.4f seconds",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getPath().c_str(), duration);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendRLS(uint64_t destWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *pRspBuffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *pRspBufferSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendRLS");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_portid_t rls_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pRspBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pRspBufferSize == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("NULL hba");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // check to see if we are sending RLS to the HBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getPortWWN() == destWWN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attrs = getPortAttributes(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attrs = getDiscoveredAttributes(destWWN, tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&rls_req, &attrs.PortFcId,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (attrs.PortFcId));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((caddr_t)&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_LINK_STATUS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&rls_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (rls_req);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_RW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd_flags = FCIO_CFLAGS_RLS_DEST_NPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (char *)new uchar_t[*pRspBufferSize];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = *pRspBufferSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio.fcio_obuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.noMemory();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(pRspBuffer, fcio.fcio_obuf, *pRspBufferSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio.fcio_obuf != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete(fcio.fcio_obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendReportLUNs(uint64_t wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *responseBuffer, HBA_UINT32 *responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 *scsiStatus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *senseBuffer, HBA_UINT32 *senseSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendReportLUNs");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_scsi_cmd fscsi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union scsi_cdb scsi_rl_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t targetWwn = htonll(wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (responseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fscsi, 0, sizeof (fscsi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&scsi_rl_req, 0, sizeof (scsi_rl_req));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(fscsi.scsi_fc_pwwn.raw_wwn, &targetWwn, sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_cmd_init(&fscsi, getPath().c_str(), &scsi_rl_req,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (scsi_rl_req), responseBuffer, *responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer, *senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi.scsi_lun = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_rl_req.scc_cmd = SCMD_REPORT_LUNS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FORMG5COUNT(&scsi_rl_req, *responseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sendSCSIPassThru(&fscsi, responseSize, senseSize, scsiStatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn - remote target WWN where the SCSI Inquiry shall be sent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fcLun - the SCSI LUN to which the SCSI Inquiry shall be sent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cdb1 - the second byte of the CDB for the SCSI Inquiry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cdb2 - the third byte of teh CDB for the SCSI Inquiry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * responseBuffer - shall be a pointer to a buffer to receive the SCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inquiry command response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * responseSize - a pointer to the size of the buffer to receive
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the SCSI Inquiry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scsiStatus - a pointer to a buffer to receive SCSI status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * senseBuffer - pointer to a buffer to receive SCSI sense data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * seneseSize - pointer to the size of the buffer to receive SCSI sense
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendScsiInquiry(uint64_t wwn, HBA_UINT64 fcLun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 cdb1, HBA_UINT8 cdb2, void *responseBuffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *responseSize, HBA_UINT8 *scsiStatus, void *senseBuffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *senseSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendScsiInquiry");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_scsi_cmd fscsi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union scsi_cdb scsi_inq_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t targetWwn = htonll(wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (responseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fscsi, 0, sizeof (fscsi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&scsi_inq_req, 0, sizeof (scsi_inq_req));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(fscsi.scsi_fc_pwwn.raw_wwn, &targetWwn, sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_cmd_init(&fscsi, getPath().c_str(), &scsi_inq_req,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (scsi_inq_req), responseBuffer, *responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer, *senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi.scsi_lun = fcLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inq_req.scc_cmd = SCMD_INQUIRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inq_req.g0_addr1 = cdb2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inq_req.g0_addr2 = cdb1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_inq_req.g0_count0 = *responseSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sendSCSIPassThru(&fscsi, responseSize, senseSize, scsiStatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendReadCapacity(uint64_t pwwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT64 fcLun, void *responseBuffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *responseSize, HBA_UINT8 *scsiStatus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *senseBuffer, HBA_UINT32 *senseSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendReadCapacity");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct fcp_scsi_cmd fscsi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union scsi_cdb scsi_rc_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t targetWwn = htonll(pwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (responseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiStatus == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&fscsi, 0, sizeof (fscsi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&scsi_rc_req, 0, sizeof (scsi_rc_req));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_cmd_init(&fscsi, getPath().c_str(), &scsi_rc_req,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (scsi_rc_req), responseBuffer, *responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseBuffer, *senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(fscsi.scsi_fc_pwwn.raw_wwn, &targetWwn, sizeof (la_wwn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fscsi.scsi_lun = fcLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_rc_req.scc_cmd = SCMD_READ_CAPACITY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_rc_req.g1_reladdr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_rc_req.g1_addr3 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_rc_req.g1_count0 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sendSCSIPassThru(&fscsi, responseSize, senseSize, scsiStatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::sendRNID(uint64_t destwwn, HBA_UINT32 destfcid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 nodeIdDataFormat, void *pRspBuffer,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 *RspBufferSize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::sendRNID");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int localportfound, remoteportfound, send;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Validate the arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pRspBuffer == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RspBufferSize == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // NodeIdDataFormat must be within the range of 0x00 and 0xff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodeIdDataFormat > 0xff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "NodeIdDataFormat must be within the range of 0x00 "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "and 0xFF");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remoteportfound = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (destfcid != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES attrs = getDiscoveredAttributes(destwwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (attrs.PortFcId == destfcid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte send = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remoteportfound = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte send = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remoteportfound = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (HBAException &e) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Send RNID if destination port not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * present in the discovered ports table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (remoteportfound == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte send = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte send = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!send) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Can we log something so we can figure out why?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BadArgumentException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((caddr_t)&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t netdestwwn = htonll(destwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_SEND_NODE_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd_flags = nodeIdDataFormat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (la_wwn_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&netdestwwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = *RspBufferSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (char *)new uchar_t[*RspBufferSize];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio.fcio_obuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.noMemory();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(pRspBuffer, fcio.fcio_obuf, *RspBufferSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio.fcio_obuf != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete(fcio.fcio_obuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::setRNID(HBA_MGMTINFO info) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::setRNID");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_rnid_t rnid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&rnid, 0, sizeof (fc_rnid_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((caddr_t)&fcio, 0, sizeof (fcio));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_SET_NODE_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ilen = sizeof (fc_rnid_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_ibuf = (caddr_t)&rnid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Copy the HBA_MGMTINFO into fc_rnid_t struct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.unit_type), &(info.unittype), sizeof (rnid.unit_type));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.port_id), &(info.PortId), sizeof (rnid.port_id));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.global_id), &(info.wwn), sizeof (info.wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.num_attached), &(info.NumberOfAttachedNodes),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (rnid.num_attached));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.ip_version), &(info.IPVersion), sizeof (rnid.ip_version));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.udp_port), &(info.UDPPort), sizeof (rnid.udp_port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.ip_addr), &info.IPAddress, sizeof (rnid.ip_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&(rnid.topo_flags), &(info.TopologyDiscoveryFlags),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (rnid.topo_flags));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(getPath(), FCIO_CMD, &fcio, O_NDELAY | O_RDONLY | O_EXCL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::fp_ioctl(string path, int cmd, fcio_t *fcio, int openflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::fp_ioctl with openflag");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char fcioErrorString[MAX_FCIO_MSG_LEN] = "";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd = HBA::_open(path, openflag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA::_ioctl(fd, cmd, (uchar_t *)fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fcio->fcio_errno == FC_STATEC_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA::_ioctl(fd, cmd, (uchar_t *)fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > 10) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fcio->fcio_errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IOError("IOCTL transport failure");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte transportError(fcio->fcio_errno, fcioErrorString);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.genericIOError("ioctl (0x%x) failed. Transport: \"%s\"", cmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcioErrorString);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (fcio->fcio_errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADWWN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IllegalWWNException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_BADPORT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IllegalWWNException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_OUTOFBOUNDS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IllegalIndexException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_PBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_FBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_TRAN_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_STATEC_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_DEVICE_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw BusyException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case FC_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::fp_ioctl(string path, int cmd, fcio_t *fcio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("FCHBAPort::fp_ioctl");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(path, cmd, fcio, O_NDELAY | O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid FCHBAPort::fcsm_ioctl(int cmd, fcio_t *fcio) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // We use the same error handling as fp, so just re-use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fp_ioctl(FCSM_DRIVER_PATH, cmd, fcio);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}