fcinfo-list.c revision 2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef enum {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct rep_luns_rsp {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int getTargetMapping(HBA_HANDLE, HBA_WWN myhbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int processHBA(HBA_HANDLE handle, HBA_ADAPTERATTRIBUTES attrs,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portIndex, HBA_PORTATTRIBUTES port, HBA_FCPTARGETMAPPINGV2 *map,
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 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 * This function retrieve the adapater attributes, port attributes, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * portIndex for the given handle and hba port WWN.
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 * 0 successfully retrieve all information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * >0 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteretrieveAttrs(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES *attrs, HBA_PORTATTRIBUTES *port, int *portIndex)
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 /* retrieve Adapter attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(attrs, 0, sizeof (HBA_ADAPTERATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find the corresponding port on the adapter and retrieve
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port attributes as well as the port index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portCtr = 0; portCtr < attrs->NumberOfPorts; portCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not able to find corresponding port WWN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returning an error
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 * 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 * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegetTargetMapping(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument sanity checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Internal Error: mapping is NULL"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map = calloc(1, sizeof (HBA_FCPTARGETMAPPINGV2))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Internal Error: Unable to calloc map"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetFcpTargetMappingV2(handle, hbaPortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((map = calloc(1, (sizeof (HBA_FCPSCSIENTRYV2)*(count-1)) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Unable to calloc map of size: %d"), count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetFcpTargetMappingV2(handle, hbaPortWWN, map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Unable to get Target Mapping\n"));
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 * 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 FortehandleRemotePort(HBA_HANDLE handle, HBA_WWN portWWN, HBA_WWN remotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 senseSize = sizeof (struct scsi_extended_sense);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument checking */
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 } else if (status == HBA_STATUS_ERROR_NOT_A_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will issue the RLS and print out the port statistics for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the given destWWN
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 ForteprintLinkStat(HBA_HANDLE handle, HBA_WWN hbaPortWWN, HBA_WWN destWWN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_SendRLS(handle, hbaPortWWN, destWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error: SendRLS failed for %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprintHBANPIVPortInfo(HBA_HANDLE handle, int portindex)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(handle, portindex, &portattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tNPIV Not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tMax NPIV Ports: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\tNPIV Not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < portattrs.NumberOfNPIVPorts; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\t\tNode WWN: %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("\t\tPort WWN: %016llx\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will process hba port, remote port and scsi-target information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for the given handle.
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 * Return Value:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 sucessfully processed handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 error has occured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteprocessHBA(HBA_HANDLE handle, HBA_ADAPTERATTRIBUTES attrs, int portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES port, HBA_FCPTARGETMAPPINGV2 *map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printLinkStat(handle, port.PortWWN, port.PortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process each of the remote targets from this hba port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleRemotePort(handle, port.PortWWN, discPort.PortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will process remote port information for the given handle.
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 ForteprocessRemotePort(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FCPTARGETMAPPINGV2 *map, int wwnCount, char **wwn_argv, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetPortAttributesByWWN(handle, myremotePortWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("HBA_GetPortAttributesByWWN "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed: reason: "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handleRemotePort(handle, portWWN, myremotePortWWN, &discPort);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_LINKSTAT) == PRINT_LINKSTAT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function handles printing Scsi target information for remote ports
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 FortehandleScsiTarget(HBA_HANDLE handle, HBA_WWN hbaPortWWN, HBA_WWN scsiTargetWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t raw_luns[DEFAULT_LUN_LENGTH], *lun_string;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_ScsiReportLUNsV2(handle, hbaPortWWN,
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 "HBA_ScsiReportLUNsV2 failed. reason "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&tmp_lunlength, &(lun_resp->length), sizeof (tmp_lunlength));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&numberOfLun, &lunlength, sizeof (numberOfLun));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lunCount = 0; lunCount < (numberOfLun / 8); lunCount++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * now issue standard inquiry to get Vendor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and product information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcLUN = ntohll(wwnConversion(lun_resp->lun[lunCount].val));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* EVPD */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Not able to issue Inquiry.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (count = 0; count < map->NumberOfEntries; count++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not able to get any target mapping information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * function to handle the list remoteport command
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 * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_remoteport(int wwnCount, char **wwn_argv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* grab the hba port wwn from the -p option */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Error: Illegal option: %c.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -h option was not specified, this should not happen either.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmdparse should catch this problem, but checking anyways
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: -p option was not specified.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(myhbaPortWWN.wwn, &hbaPortWWN, sizeof (hbaPortWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_OpenAdapterByWWN(&handle, myhbaPortWWN))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_OpenTgtAdapterByWWN(&handle, myhbaPortWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Failed to open adapter port. Reason "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: Unsupported option for target mode: %c.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_SCSI_TARGET) == PRINT_SCSI_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveAttrs(handle, myhbaPortWWN, &attrs, &port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA(handle, attrs, portCount, port, map, REMOTE_PORT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processRemotePort(handle, myhbaPortWWN, map, wwnCount,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process the hbaport object
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 * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int port_wwn_counter, numAdapters = 0, numTgtAdapters = 0, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each of the options */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print both initiator and target if no initiator/target flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((processHBA_flags & PRINT_INITIATOR) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte processHBA_flags |= PRINT_INITIATOR | PRINT_TARGET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list only ports given in wwn_argv */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[port_wwn_counter], "%016llx", &hbaWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first check to see if it is an initiator port. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now see if it is a target mode FC port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try target mode discovery if print target is set. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the port mode. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* should not get here. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: HBA port %s: not found\n"),
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if ((processHBA_flags & PRINT_FCOE) != PRINT_FCOE &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if PRINT_INITIATOR is specified, get the list of initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_INITIATOR) == PRINT_INITIATOR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stdout, gettext("No Adapters Found.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = HBA_OpenAdapter(adapterName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to open adapter %s.\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on the given adatpter */
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 "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the info on the target mode FC port if PRINT_TARGET
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((processHBA_flags & PRINT_TARGET) == PRINT_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numTgtAdapters = Sun_HBA_GetNumberOfTgtAdapters();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numTgtAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetTgtAdapterName(i, adapterName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = Sun_HBA_OpenTgtAdapter(adapterName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapater attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterAttributes(handle, &attrs))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "attributes handle(%d) Reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on the given adatpter */
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 "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * print additional error msg for partial failure when more than
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one wwn is specified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: All specified HBA ports are not found\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: Some of specified HBA ports are not found\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Search the existing device list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take one of two actions:
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 * 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 FortesearchDevice(discoveredDevice **devList, HBA_FCPSCSIENTRYV2 entry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_WWN initiatorPortWWN, HBA_HANDLE handle, boolean_t verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (discoveredDevList = *devList; discoveredDevList != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if only device names are requested,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no reason to go any further
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add initiator Port WWN if it doesn't exist */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (HBA_WWN)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN = (portWWNList *)calloc(1, sizeof (portWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* add Target Port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newWWN->tgtPortWWN->scsiOSLun = entry.ScsiId.ScsiOSLun;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* add it to existing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert at head */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* add new entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy device name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(newDevice->OSDeviceName, entry.ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if only device names are requested,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no reason to go any further
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy WWN data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newDevice->HBAPortWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&initiatorPortWWN, sizeof (newWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (tgtPortWWNList *)calloc(1, sizeof (tgtPortWWNList));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy((void *)&(newDevice->HBAPortWWN->tgtPortWWN->portWWN),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (newDevice->HBAPortWWN->tgtPortWWN->portWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set LUN data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, /* CDB Byte 2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize VID/PID/dType as "Unknown" */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize inq status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize inq status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process the logical-unit object
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 * luArgv - argument array of device paths
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * options - any options specified by the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 if successful
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * > 0 otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_list_logicalunit(int luCount, char **luArgv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each of the options */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
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 for (i = 0; i < numAdapters; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to get adapter %d. Reason: "), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((handle = HBA_OpenAdapter(adapterName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, gettext("Failed to open adapter %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get adapter attributes for the given handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* process each port on adapter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portIndex = 0; portIndex < attrs.NumberOfPorts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_GetAdapterPortAttributes(handle,
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 "(%d) attributes reason: "),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get OS Device Paths */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list all paths */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list any paths not found first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this gives the user cleaner output
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pathCtr = 0; pathCtr < luCount; pathCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* list all paths requested in order requested */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pathCtr = 0; pathCtr < luCount; pathCtr++) {