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/*
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Exceptions.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sun_fc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Handle.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "HBA.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "HBAPort.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinline HBA_WWN
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing ChinagetAdapterPortWWN(HBA_HANDLE handle,HBA_UINT32 index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN hba_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(hba_wwn.wwn, 0, sizeof (hba_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Handle *myHandle = Handle::findHandle(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA *hba = myHandle->getHBA();
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China HBAPort *port = hba->getPortByIndex(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t tmp = htonll(port->getPortWWN());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(hba_wwn.wwn, &tmp, sizeof (hba_wwn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) { }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (hba_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Retrieves the mapping between FCP targets and OS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SCSI information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return HBA_STATUS_OK if the mapping structure contains valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mapping data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param handle The HBA to fetch mappings for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param mapping The user-allocated mapping structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc This routine will call the V2 interface and convert
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the results to the old data structure. It will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * call the V2 interface for all ports on the HBA.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBA_STATUS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteSun_fcGetFcpTargetMapping(HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PHBA_FCPTARGETMAPPINGV2 mappingV2;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China HBA_ADAPTERATTRIBUTES attributes;
352290fbea989358b5153ef1750fc3c3fcdca668duo liu - Sun Microsystems - Beijing China HBA_UINT32 entries = 0;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China HBA_UINT32 current = 0;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China HBA_UINT32 port;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China HBA_UINT32 limit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("Sun_fcGetFcpTargetMapping");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mapping == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.userError("NULL mapping argument.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (HBA_STATUS_ERROR_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China
352290fbea989358b5153ef1750fc3c3fcdca668duo liu - Sun Microsystems - Beijing China entries = mapping->NumberOfEntries;
352290fbea989358b5153ef1750fc3c3fcdca668duo liu - Sun Microsystems - Beijing China
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China /* get adapter attributes for number of ports */
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China status = Sun_fcGetAdapterAttributes(handle,&attributes);
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China if (status != HBA_STATUS_OK) {
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China log.userError("Unable to get adapter attributes");
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China return HBA_STATUS_ERROR;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China }
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mappingV2 = (PHBA_FCPTARGETMAPPINGV2) new uchar_t[
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sizeof (HBA_FCPSCSIENTRYV2)*(mapping->NumberOfEntries-1)) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (HBA_FCPTARGETMAPPINGV2)];
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China mapping->NumberOfEntries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China for(port = 0; port < attributes.NumberOfPorts; port++) {
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China mappingV2->NumberOfEntries = mapping->NumberOfEntries < entries ?
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China entries - mapping->NumberOfEntries : 0 ;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China status = Sun_fcGetFcpTargetMappingV2(handle,
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China getAdapterPortWWN(handle,port), mappingV2);
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China mapping->NumberOfEntries += mappingV2->NumberOfEntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China if (status != HBA_STATUS_OK && status != HBA_STATUS_ERROR_MORE_DATA) {
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China log.userError("Unable to get mappings for port");
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China return status;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need to copy from PHBA_FCPTARGETMAPPINGV2 to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PHBA_FCPTARGETMAPPING
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China limit = (mapping->NumberOfEntries < entries) ? mapping->NumberOfEntries : entries;
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China for (count = current; count < limit; count++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&mapping->entry[count].ScsiId,
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China &mappingV2->entry[count-current].ScsiId,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (mapping->entry[count].ScsiId));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(&mapping->entry[count].FcpId,
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China &mappingV2->entry[count-current].FcpId,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (mapping->entry[count].FcpId));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
83bf661f7a0eb06268ce891fcad997e6a39830d8duo liu - Sun Microsystems - Beijing China current = mapping->NumberOfEntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete(mappingV2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif