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/*
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "fcinfo.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct lun {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t val[8];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef enum {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte REMOTE_PORT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte LOGICAL_UNIT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} resource_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct rep_luns_rsp {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t rsrvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct lun lun[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} rep_luns_rsp_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int getTargetMapping(HBA_HANDLE, HBA_WWN myhbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 **mapping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int processHBA(HBA_HANDLE handle, HBA_ADAPTERATTRIBUTES attrs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portIndex, HBA_PORTATTRIBUTES port, HBA_FCPTARGETMAPPINGV2 *map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int resourceType, int flags, int mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void processRemotePort(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map, int wwnCount, char **wwn_argv, int flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void handleRemotePort(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN myRemotePortWWN, HBA_PORTATTRIBUTES *discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void printLinkStat(HBA_HANDLE handle, HBA_WWN hbaportWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN destWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void handleScsiTarget(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN scsiTargetWWN, HBA_FCPTARGETMAPPINGV2 *map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int retrieveAttrs(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES *attrs, HBA_PORTATTRIBUTES *port, int *portIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void searchDevice(discoveredDevice **devList, HBA_FCPSCSIENTRYV2 entry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN initiatorPortWWN, HBA_HANDLE handle, boolean_t verbose);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function retrieve the adapater attributes, port attributes, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portIndex for the given handle and hba port WWN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle an HBA_HANDLE to a adapter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hbaPortWWN WWN of the port on the adapter to which to retrieve
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HBA_PORTATTRIBUTES from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attrs pointer to a HBA_ADAPTERATTRIBUTES structure. Upon
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * successful completion, this structure will be filled in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port pointer to a HBA_PORTATTRIBUTES structure. Upon successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * completion, this structure will be fill in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portIndex the Index count of the port on the adapter that is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associated with the WWN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 successfully retrieve all information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * >0 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteretrieveAttrs(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES *attrs, HBA_PORTATTRIBUTES *port, int *portIndex)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portCtr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (attrs == NULL || port == NULL || portIndex == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error: Invalid arguments to "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "retreiveAttrs\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* retrieve Adapter attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(attrs, 0, sizeof (HBA_ADAPTERATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Failed to get adapter "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "attributes handle(%d) Reason: "), handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find the corresponding port on the adapter and retrieve
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port attributes as well as the port index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(port, 0, sizeof (HBA_PORTATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portCtr = 0; portCtr < attrs->NumberOfPorts; portCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portCtr, port)) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to get port (%d) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "attributes reason: "), portCtr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(hbaPortWWN.wwn, port->PortWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (port->PortWWN.wwn)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portCtr >= attrs->NumberOfPorts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not able to find corresponding port WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returning an error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portIndex = portCtr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function retrieves target mapping information for the HBA port WWN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will allocate space for the mapping structure which the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must free when they are finished
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hbaPortWWN - the port WWN for the HBA port to retrieve the mappings for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mapping - a pointer to a pointer for the target mapping structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Upon successful completion of this function, *mapping will contain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the target mapping information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegetTargetMapping(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 **mapping)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument sanity checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mapping == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Internal Error: mapping is NULL"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mapping = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map = calloc(1, sizeof (HBA_FCPTARGETMAPPINGV2))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Internal Error: Unable to calloc map"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetFcpTargetMappingV2(handle, hbaPortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = map->NumberOfEntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_ERROR_MORE_DATA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map = calloc(1, (sizeof (HBA_FCPSCSIENTRYV2)*(count-1)) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (HBA_FCPTARGETMAPPINGV2))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Unable to calloc map of size: %d"), count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map->NumberOfEntries = count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetFcpTargetMappingV2(handle, hbaPortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Unable to get Target Mapping\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mapping = map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function handles the remoteport object. It will issue a report lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to determine whether it is a scsi-target and then print the information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portWWN - the port WWN for the HBA port we will be issuing the SCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ReportLUNS through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remotePortWWN - the port WWN we will be issuing the report lun call to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discPort - PORTATTRIBUTES structure for the remotePortWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortehandleRemotePort(HBA_HANDLE handle, HBA_WWN portWWN, HBA_WWN remotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES *discPort)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int scsiTargetType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t raw_luns[LUN_LENGTH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 responseSize = LUN_LENGTH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_extended_sense sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 rep_luns_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discPort == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(raw_luns, 0, sizeof (raw_luns));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* going to issue a report lun to check if this is a scsi-target */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiReportLUNsV2(handle, portWWN, remotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)raw_luns, &responseSize, &rep_luns_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&sense, &senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetType = SCSI_TARGET_TYPE_YES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (status == HBA_STATUS_ERROR_NOT_A_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetType = SCSI_TARGET_TYPE_NO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetType = SCSI_TARGET_TYPE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printDiscoPortInfo(discPort, scsiTargetType);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will issue the RLS and print out the port statistics for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the given destWWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hbaPortWWN - the hba port WWN through which the RLS will be sent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * destWWN - the remote port to which the RLS will be sent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprintLinkStat(HBA_HANDLE handle, HBA_WWN hbaPortWWN, HBA_WWN destWWN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_rls_acc_t rls_payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t rls_payload_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&rls_payload, 0, sizeof (rls_payload));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rls_payload_size = sizeof (rls_payload);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_SendRLS(handle, hbaPortWWN, destWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &rls_payload, &rls_payload_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error: SendRLS failed for %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnConversion(destWWN.wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printPortStat(&rls_payload);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprintHBANPIVPortInfo(HBA_HANDLE handle, int portindex)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES portattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_NPIVATTRIBUTES npivattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(handle, portindex, &portattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle, portindex, &portattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tNPIV Not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to get port (%d) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "npiv attributes reason: "), portindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portattrs.MaxNumberOfNPIVPorts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tMax NPIV Ports: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portattrs.MaxNumberOfNPIVPorts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tNPIV Not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tNPIV port list:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < portattrs.NumberOfNPIVPorts; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetNPIVPortInfo(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portindex, index, &npivattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetNPIVPortInfo(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portindex, index, &npivattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to get npiv port (%d) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "attributes reason: "), index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("\t Virtual Port%d:\n"), index+1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\t\tNode WWN: %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnConversion(npivattrs.NodeWWN.wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\t\tPort WWN: %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnConversion(npivattrs.PortWWN.wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will process hba port, remote port and scsi-target information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the given handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resourceType - resourceType flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * possible values include: HBA_PORT, REMOTE_PORT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flags - represents options passed in by the user
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return Value:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 sucessfully processed handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 error has occured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprocessHBA(HBA_HANDLE handle, HBA_ADAPTERATTRIBUTES attrs, int portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES port, HBA_FCPTARGETMAPPINGV2 *map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int resourceType, int flags, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES discPort;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int discPortCount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resourceType == HBA_PORT) {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if ((flags & PRINT_FCOE) == PRINT_FCOE &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang attrs.VendorSpecificID != 0xFC0E) {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang return (0);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printHBAPortInfo(&port, &attrs, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLinkStat(handle, port.PortWWN, port.PortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process each of the remote targets from this hba port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (discPortCount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discPortCount < port.NumberofDiscoveredPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discPortCount++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetDiscoveredPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex, discPortCount, &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to get discovered port (%d)"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " attributes reason :"), discPortCount);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resourceType == REMOTE_PORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleRemotePort(handle, port.PortWWN, discPort.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLinkStat(handle, port.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discPort.PortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleScsiTarget(handle, port.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discPort.PortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will process remote port information for the given handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portWWN - the port WWN for the HBA port we will be issuing the SCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ReportLUNS through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwnCount - the number of wwns in wwn_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_argv - argument vector of WWNs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprocessRemotePort(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map, int wwnCount, char **wwn_argv, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int remote_wwn_counter;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t remotePortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN myremotePortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES discPort;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (remote_wwn_counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remote_wwn_counter < wwnCount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remote_wwn_counter++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[remote_wwn_counter], "%016llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &remotePortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remotePortWWN = htonll(remotePortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(myremotePortWWN.wwn, &remotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (remotePortWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&discPort, 0, sizeof (discPort));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetPortAttributesByWWN(handle, myremotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetPortAttributesByWWN(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte myremotePortWWN, &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("HBA_GetPortAttributesByWWN "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed: reason: "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleRemotePort(handle, portWWN, myremotePortWWN, &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLinkStat(handle, portWWN, myremotePortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleScsiTarget(handle, portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte myremotePortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function handles printing Scsi target information for remote ports
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - a handle to a HBA that we will be processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hbaPortWWN - the port WWN for the HBA port through which the SCSI call
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is being sent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scsiTargetWWN - target port WWN of the remote target the SCSI call is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * being sent to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map - a pointer to the target mapping structure for the given HBA port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortehandleScsiTarget(HBA_HANDLE handle, HBA_WWN hbaPortWWN, HBA_WWN scsiTargetWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_inquiry inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_extended_sense sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 responseSize, senseSize = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 inq_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t raw_luns[DEFAULT_LUN_LENGTH], *lun_string;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 rep_luns_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rep_luns_rsp_t *lun_resp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t fcLUN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lunNum, numberOfLun, lunCount, count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t lunlength, tmp_lunlength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize = DEFAULT_LUN_LENGTH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&sense, 0, sizeof (sense));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiReportLUNsV2(handle, hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetWWN, (void *)raw_luns, &responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &rep_luns_status, (void *)&sense, &senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if HBA_STATUS_ERROR_NOT_A_TARGET is return, we can assume this is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a remote HBA and move on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_ERROR_NOT_A_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error has occured. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "HBA_ScsiReportLUNsV2 failed. reason "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_resp = (rep_luns_rsp_t *)raw_luns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp_lunlength, &(lun_resp->length), sizeof (tmp_lunlength));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lunlength = htonl(tmp_lunlength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&numberOfLun, &lunlength, sizeof (numberOfLun));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lunCount = 0; lunCount < (numberOfLun / 8); lunCount++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now issue standard inquiry to get Vendor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and product information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize = sizeof (struct scsi_inquiry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&inq, 0, sizeof (struct scsi_inquiry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&sense, 0, sizeof (sense));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcLUN = ntohll(wwnConversion(lun_resp->lun[lunCount].val));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiInquiryV2(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcLUN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* EVPD */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq, &responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sense, &senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Not able to issue Inquiry.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(inq.inq_vid, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(inq.inq_pid, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (count = 0; count < map->NumberOfEntries; count++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((memcmp(map->entry[count].FcpId.PortWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsiTargetWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (scsiTargetWWN.wwn))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (memcmp(&(map->entry[count].FcpId.FcpLun),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &fcLUN, sizeof (fcLUN)) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLUNInfo(&inq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map->entry[count].ScsiId.ScsiOSLun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map->entry[count].ScsiId.OSDeviceName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count == map->NumberOfEntries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_string = lun_resp->lun[lunCount].val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lunNum = ((lun_string[0] & 0x3F) << 8) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_string[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLUNInfo(&inq, lunNum, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not able to get any target mapping information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_string = lun_resp->lun[lunCount].val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lunNum = ((lun_string[0] & 0x3F) << 8) |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_string[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLUNInfo(&inq, lunNum, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * function to handle the list remoteport command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwnCount - the number of wwns in wwn_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if wwnCount == 0, then print information on all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remote ports. wwn_argv will not be used in this case
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if wwnCount > 0, then print information for the WWNs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * given in wwn_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_argv - argument vector of WWNs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options - any options specified by the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_remoteport(int wwnCount, char **wwn_argv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t hbaPortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN myhbaPortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int processHBA_flags = 0, portCount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* grab the hba port wwn from the -p option */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; options->optval; options++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options->optval == 'p') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &hbaPortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options->optval == 's') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_SCSI_TARGET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options->optval == 'l') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_LINKSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error: Illegal option: %c.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte options->optval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -h option was not specified, this should not happen either.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmdparse should catch this problem, but checking anyways
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hbaPortWWN == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: -p option was not specified.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hbaPortWWN = htonll(hbaPortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(myhbaPortWWN.wwn, &hbaPortWWN, sizeof (hbaPortWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_OpenAdapterByWWN(&handle, myhbaPortWWN))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_OpenTgtAdapterByWWN(&handle, myhbaPortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to open adapter port. Reason "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_SCSI_TARGET) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: Unsupported option for target mode: %c.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 's');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = TARGET_MODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = INITIATOR_MODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getTargetMapping(handle, myhbaPortWWN, &map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnCount == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (attrs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&port, 0, sizeof (port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveAttrs(handle, myhbaPortWWN, &attrs, &port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &portCount) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA(handle, attrs, portCount, port, map, REMOTE_PORT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processRemotePort(handle, myhbaPortWWN, map, wwnCount,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv, processHBA_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process the hbaport object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwnCount - count of the number of WWNs in wwn_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if wwnCount > 0, then we will only print information for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the hba ports listed in wwn_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if wwnCount == 0, then we will print information on all hba ports
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn_argv - argument array of hba port WWNs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options - any options specified by the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int port_wwn_counter, numAdapters = 0, numTgtAdapters = 0, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char adapterName[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t hbaWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN myWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int processHBA_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portIndex = 0, err_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each of the options */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; options->optval; options++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options->optval == 'l') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_LINKSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options->optval == 'i') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_INITIATOR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (options->optval == 't') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_TARGET;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang } else if (options->optval == 'e') {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang processHBA_flags |= PRINT_FCOE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print both initiator and target if no initiator/target flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((processHBA_flags & PRINT_INITIATOR) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((processHBA_flags & PRINT_TARGET) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_INITIATOR | PRINT_TARGET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnCount > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list only ports given in wwn_argv */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (port_wwn_counter = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_counter < wwnCount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port_wwn_counter++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[port_wwn_counter], "%016llx", &hbaWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hbaWWN = htonll(hbaWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(myWWN.wwn, &hbaWWN, sizeof (hbaWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first check to see if it is an initiator port. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_INITIATOR) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PRINT_INITIATOR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, myWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, myWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now see if it is a target mode FC port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_TARGET) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PRINT_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Sun_HBA_OpenTgtAdapterByWWN(&handle, myWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[port_wwn_counter]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = TARGET_MODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[port_wwn_counter]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = INITIATOR_MODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try target mode discovery if print target is set. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((processHBA_flags & PRINT_TARGET) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PRINT_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Sun_HBA_OpenTgtAdapterByWWN(&handle, myWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[port_wwn_counter]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = TARGET_MODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should not get here. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[port_wwn_counter]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (attrs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&port, 0, sizeof (port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveAttrs(handle, myWWN, &attrs, &port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &portIndex) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA(handle, attrs, portIndex, port, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORT, processHBA_flags, mode);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if ((processHBA_flags & PRINT_FCOE) != PRINT_FCOE &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang attrs.VendorSpecificID != 0xFC0E &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang printHBANPIVPortInfo(handle, portIndex) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if PRINT_INITIATOR is specified, get the list of initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mod port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_INITIATOR) == PRINT_INITIATOR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numAdapters = HBA_GetNumberOfAdapters();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((numAdapters == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((processHBA_flags & ~PRINT_INITIATOR) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("No Adapters Found.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterName(i, adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = HBA_OpenAdapter(adapterName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to open adapter %s.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (attrs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Sun_HBA_NPIVGetAdapterAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Sun_HBA_NPIVGetAdapterAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to get adapter attributes "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "handle(%d) Reason: "), handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
63c17d01856124d99676ad972bf973d4a005a877Raghuram Prahlada HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on the given adatpter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex < attrs.NumberOfPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&port, 0, sizeof (port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle, portIndex, &port))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not able to get port attributes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print out error * message and move
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on to the next port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to get port "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA(handle, attrs, portIndex, port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, HBA_PORT, processHBA_flags,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte INITIATOR_MODE);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if ((processHBA_flags & PRINT_FCOE) !=
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang PRINT_FCOE &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang attrs.VendorSpecificID != 0xFC0E &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang printHBANPIVPortInfo(handle,
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang portIndex) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the info on the target mode FC port if PRINT_TARGET
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_TARGET) == PRINT_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numTgtAdapters = Sun_HBA_GetNumberOfTgtAdapters();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (numTgtAdapters == 0 && numAdapters == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("No Adapters Found.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numTgtAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetTgtAdapterName(i, adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = Sun_HBA_OpenTgtAdapter(adapterName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to open adapter %s.\n"), adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (attrs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterAttributes(handle, &attrs))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to get target mode adapter"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "attributes handle(%d) Reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on the given adatpter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex < attrs.NumberOfPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&port, 0, sizeof (port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle, portIndex, &port))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not able to get port attributes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print out error * message and move
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on to the next port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to get port "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA(handle, attrs, portIndex, port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, HBA_PORT, processHBA_flags,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TARGET_MODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print additional error msg for partial failure when more than
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one wwn is specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err_cnt != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnCount > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err_cnt == wwnCount) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: All specified HBA ports are not found\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: Some of specified HBA ports are not found\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Search the existing device list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take one of two actions:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add an entry if an entry doesn't exist
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add WWN data to it if an entry does exist
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devList - OS device path list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * map - target mapping data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * index - index into target mapping data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiatorPortWWN - HBA port WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * verbose - boolean indicating whether to get additional data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * none
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesearchDevice(discoveredDevice **devList, HBA_FCPSCSIENTRYV2 entry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_WWN initiatorPortWWN, HBA_HANDLE handle, boolean_t verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevice *discoveredDevList, *newDevice;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portWWNList *WWNList, *newWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tgtPortWWNList *newTgtWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t foundDevice = B_FALSE, foundWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_inquiry inq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_extended_sense sense;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 responseSize, senseSize = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT8 inq_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (discoveredDevList = *devList; discoveredDevList != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevList = discoveredDevList->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(entry.ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevList->OSDeviceName) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if only device names are requested,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no reason to go any further
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundDevice = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (foundDevice == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add initiator Port WWN if it doesn't exist */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (WWNList = discoveredDevList->HBAPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundWWN = B_FALSE; WWNList != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWNList = WWNList->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp((void *)&(WWNList->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&initiatorPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (HBA_WWN)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundWWN = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discoveredDevList->inqSuccess == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize = sizeof (struct scsi_inquiry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&inq, 0, sizeof (struct scsi_inquiry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&sense, 0, sizeof (sense));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiInquiryV2(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initiatorPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry.FcpId.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry.FcpId.FcpLun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq, &responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sense, &senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(discoveredDevList->VID, inq.inq_vid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (discoveredDevList->VID));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(discoveredDevList->PID, inq.inq_pid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (discoveredDevList->PID));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevList->dType = inq.inq_dtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevList->inqSuccess = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (foundWWN == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN = (portWWNList *)calloc(1, sizeof (portWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newWWN == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN->next = discoveredDevList->HBAPortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevList->HBAPortWWN = newWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&initiatorPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add Target Port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN->tgtPortWWN = (tgtPortWWNList *)calloc(1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (tgtPortWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newWWN->tgtPortWWN == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newWWN->tgtPortWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&(entry.FcpId.PortWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newWWN->tgtPortWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN->tgtPortWWN->scsiOSLun = entry.ScsiId.ScsiOSLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* add it to existing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newTgtWWN = (tgtPortWWNList *)calloc(1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (tgtPortWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newTgtWWN == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newTgtWWN->next = WWNList->tgtPortWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWNList->tgtPortWWN = newTgtWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newTgtWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&(entry.FcpId.PortWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newTgtWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newTgtWWN->scsiOSLun = entry.ScsiId.ScsiOSLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* add new entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice = (discoveredDevice *)calloc(1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (discoveredDevice));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newDevice == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->next = *devList; /* insert at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *devList = newDevice; /* set new head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy device name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(newDevice->OSDeviceName, entry.ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newDevice->OSDeviceName) - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if only device names are requested,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no reason to go any further
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy WWN data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->HBAPortWWN = (portWWNList *)calloc(1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (portWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newDevice->HBAPortWWN == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newDevice->HBAPortWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&initiatorPortWWN, sizeof (newWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->HBAPortWWN->tgtPortWWN =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tgtPortWWNList *)calloc(1, sizeof (tgtPortWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (newDevice->HBAPortWWN->tgtPortWWN == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("Out of memory");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newDevice->HBAPortWWN->tgtPortWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&(entry.FcpId.PortWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newDevice->HBAPortWWN->tgtPortWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->HBAPortWWN->tgtPortWWN->scsiOSLun =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry.ScsiId.ScsiOSLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte responseSize = sizeof (struct scsi_inquiry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&inq, 0, sizeof (struct scsi_inquiry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&sense, 0, sizeof (sense));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiInquiryV2(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initiatorPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry.FcpId.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry.FcpId.FcpLun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq, &responseSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &inq_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sense, &senseSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize VID/PID/dType as "Unknown" */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(newDevice->VID, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(newDevice->PID, "Unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->dType = DTYPE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize inq status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->inqSuccess = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(newDevice->VID, inq.inq_vid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newDevice->VID));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(newDevice->PID, inq.inq_pid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newDevice->PID));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->dType = inq.inq_dtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize inq status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newDevice->inqSuccess = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process the logical-unit object
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Arguments:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * luCount - count of the number of device paths in paths_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if pathCount > 0, then we will only print information for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the device paths listed in paths_argv
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if pathCount == 0, then we will print information on all device
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * luArgv - argument array of device paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options - any options specified by the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * > 0 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_logicalunit(int luCount, char **luArgv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pathCtr, numAdapters, i, count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char adapterName[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t verbose = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte discoveredDevice *devListWalk, *devList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t pathFound;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each of the options */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; options->optval; options++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options->optval == 'v') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verbose = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Retrieve all device paths. We'll need to traverse the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * until we find the input paths or all paths if none were given. We
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot print as we go since there can be duplicate paths returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numAdapters = HBA_GetNumberOfAdapters();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (numAdapters == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterName(i, adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = HBA_OpenAdapter(adapterName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Failed to open adapter %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapter attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (attrs));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to get adapter attributes "
63c17d01856124d99676ad972bf973d4a005a877Raghuram Prahlada "handle(%d) Reason: "), handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret++;
63c17d01856124d99676ad972bf973d4a005a877Raghuram Prahlada HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on adapter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portIndex = 0; portIndex < attrs.NumberOfPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&port, 0, sizeof (port));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex, &port)) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not able to get port attributes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print out error message and move
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on to the next port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Failed to get port "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get OS Device Paths */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getTargetMapping(handle, port.PortWWN, &map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (map != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (count = 0; count < map->NumberOfEntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte searchDevice(&devList,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte map->entry[count], port.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle, verbose);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luCount == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list all paths */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (devListWalk = devList; devListWalk != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devListWalk = devListWalk->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printOSDeviceNameInfo(devListWalk, verbose);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list any paths not found first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this gives the user cleaner output
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pathCtr = 0; pathCtr < luCount; pathCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (devListWalk = devList, pathFound = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devListWalk != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devListWalk = devListWalk->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(devListWalk->OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luArgv[pathCtr]) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathFound = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathFound == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "%s: no such path\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luArgv[pathCtr]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list all paths requested in order requested */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pathCtr = 0; pathCtr < luCount; pathCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (devListWalk = devList; devListWalk != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devListWalk = devListWalk->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(devListWalk->OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luArgv[pathCtr]) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printOSDeviceNameInfo(devListWalk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verbose);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}