17836SJohn.Forte@Sun.COM /* 27836SJohn.Forte@Sun.COM * CDDL HEADER START 37836SJohn.Forte@Sun.COM * 47836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the 57836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License"). 67836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License. 77836SJohn.Forte@Sun.COM * 87836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing. 107836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions 117836SJohn.Forte@Sun.COM * and limitations under the License. 127836SJohn.Forte@Sun.COM * 137836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 147836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 167836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 177836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 187836SJohn.Forte@Sun.COM * 197836SJohn.Forte@Sun.COM * CDDL HEADER END 207836SJohn.Forte@Sun.COM */ 217836SJohn.Forte@Sun.COM /* 22*10155SDuo.Liu@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237836SJohn.Forte@Sun.COM * Use is subject to license terms. 247836SJohn.Forte@Sun.COM */ 257836SJohn.Forte@Sun.COM 267836SJohn.Forte@Sun.COM 277836SJohn.Forte@Sun.COM 287836SJohn.Forte@Sun.COM #include "Trace.h" 297836SJohn.Forte@Sun.COM #include "Exceptions.h" 307836SJohn.Forte@Sun.COM #include "sun_fc.h" 317836SJohn.Forte@Sun.COM 327836SJohn.Forte@Sun.COM 337836SJohn.Forte@Sun.COM 347836SJohn.Forte@Sun.COM #include <string.h> 357836SJohn.Forte@Sun.COM #include "Handle.h" 367836SJohn.Forte@Sun.COM #include "HBA.h" 377836SJohn.Forte@Sun.COM #include "HBAPort.h" 387836SJohn.Forte@Sun.COM inline HBA_WWN 39*10155SDuo.Liu@Sun.COM getAdapterPortWWN(HBA_HANDLE handle,HBA_UINT32 index) { 407836SJohn.Forte@Sun.COM HBA_WWN hba_wwn; 417836SJohn.Forte@Sun.COM memset(hba_wwn.wwn, 0, sizeof (hba_wwn)); 427836SJohn.Forte@Sun.COM try { 437836SJohn.Forte@Sun.COM Handle *myHandle = Handle::findHandle(handle); 447836SJohn.Forte@Sun.COM HBA *hba = myHandle->getHBA(); 45*10155SDuo.Liu@Sun.COM HBAPort *port = hba->getPortByIndex(index); 467836SJohn.Forte@Sun.COM uint64_t tmp = htonll(port->getPortWWN()); 477836SJohn.Forte@Sun.COM memcpy(hba_wwn.wwn, &tmp, sizeof (hba_wwn)); 487836SJohn.Forte@Sun.COM } catch (...) { } 497836SJohn.Forte@Sun.COM return (hba_wwn); 507836SJohn.Forte@Sun.COM } 517836SJohn.Forte@Sun.COM 527836SJohn.Forte@Sun.COM #ifdef __cplusplus 537836SJohn.Forte@Sun.COM extern "C" { 547836SJohn.Forte@Sun.COM #endif 557836SJohn.Forte@Sun.COM 567836SJohn.Forte@Sun.COM /** 577836SJohn.Forte@Sun.COM * @memo Retrieves the mapping between FCP targets and OS 587836SJohn.Forte@Sun.COM * SCSI information 597836SJohn.Forte@Sun.COM * @return HBA_STATUS_OK if the mapping structure contains valid 607836SJohn.Forte@Sun.COM * mapping data. 617836SJohn.Forte@Sun.COM * @param handle The HBA to fetch mappings for 627836SJohn.Forte@Sun.COM * @param mapping The user-allocated mapping structure 637836SJohn.Forte@Sun.COM * 647836SJohn.Forte@Sun.COM * @doc This routine will call the V2 interface and convert 657836SJohn.Forte@Sun.COM * the results to the old data structure. It will 667836SJohn.Forte@Sun.COM * call the V2 interface for all ports on the HBA. 677836SJohn.Forte@Sun.COM */ 687836SJohn.Forte@Sun.COM HBA_STATUS 697836SJohn.Forte@Sun.COM Sun_fcGetFcpTargetMapping(HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) { 707836SJohn.Forte@Sun.COM HBA_STATUS status; 717836SJohn.Forte@Sun.COM int count; 727836SJohn.Forte@Sun.COM PHBA_FCPTARGETMAPPINGV2 mappingV2; 73*10155SDuo.Liu@Sun.COM HBA_ADAPTERATTRIBUTES attributes; 74*10155SDuo.Liu@Sun.COM HBA_UINT32 entries = mapping->NumberOfEntries; 75*10155SDuo.Liu@Sun.COM HBA_UINT32 current = 0; 76*10155SDuo.Liu@Sun.COM HBA_UINT32 port; 77*10155SDuo.Liu@Sun.COM HBA_UINT32 limit; 787836SJohn.Forte@Sun.COM 797836SJohn.Forte@Sun.COM Trace log("Sun_fcGetFcpTargetMapping"); 807836SJohn.Forte@Sun.COM 817836SJohn.Forte@Sun.COM if (mapping == NULL) { 827836SJohn.Forte@Sun.COM log.userError("NULL mapping argument."); 837836SJohn.Forte@Sun.COM return (HBA_STATUS_ERROR_ARG); 847836SJohn.Forte@Sun.COM } 85*10155SDuo.Liu@Sun.COM 86*10155SDuo.Liu@Sun.COM /* get adapter attributes for number of ports */ 87*10155SDuo.Liu@Sun.COM status = Sun_fcGetAdapterAttributes(handle,&attributes); 88*10155SDuo.Liu@Sun.COM if (status != HBA_STATUS_OK) { 89*10155SDuo.Liu@Sun.COM log.userError("Unable to get adapter attributes"); 90*10155SDuo.Liu@Sun.COM return HBA_STATUS_ERROR; 91*10155SDuo.Liu@Sun.COM } 92*10155SDuo.Liu@Sun.COM 937836SJohn.Forte@Sun.COM mappingV2 = (PHBA_FCPTARGETMAPPINGV2) new uchar_t[ 947836SJohn.Forte@Sun.COM (sizeof (HBA_FCPSCSIENTRYV2)*(mapping->NumberOfEntries-1)) + 957836SJohn.Forte@Sun.COM sizeof (HBA_FCPTARGETMAPPINGV2)]; 96*10155SDuo.Liu@Sun.COM mapping->NumberOfEntries = 0; 977836SJohn.Forte@Sun.COM 98*10155SDuo.Liu@Sun.COM for(port = 0; port < attributes.NumberOfPorts; port++) { 99*10155SDuo.Liu@Sun.COM mappingV2->NumberOfEntries = mapping->NumberOfEntries < entries ? 100*10155SDuo.Liu@Sun.COM entries - mapping->NumberOfEntries : 0 ; 101*10155SDuo.Liu@Sun.COM status = Sun_fcGetFcpTargetMappingV2(handle, 102*10155SDuo.Liu@Sun.COM getAdapterPortWWN(handle,port), mappingV2); 103*10155SDuo.Liu@Sun.COM mapping->NumberOfEntries += mappingV2->NumberOfEntries; 104*10155SDuo.Liu@Sun.COM 105*10155SDuo.Liu@Sun.COM if (status != HBA_STATUS_OK && status != HBA_STATUS_ERROR_MORE_DATA) { 106*10155SDuo.Liu@Sun.COM log.userError("Unable to get mappings for port"); 107*10155SDuo.Liu@Sun.COM return status; 108*10155SDuo.Liu@Sun.COM } 1097836SJohn.Forte@Sun.COM /* 1107836SJohn.Forte@Sun.COM * need to copy from PHBA_FCPTARGETMAPPINGV2 to 1117836SJohn.Forte@Sun.COM * PHBA_FCPTARGETMAPPING 1127836SJohn.Forte@Sun.COM */ 113*10155SDuo.Liu@Sun.COM limit = (mapping->NumberOfEntries < entries) ? mapping->NumberOfEntries : entries; 114*10155SDuo.Liu@Sun.COM for (count = current; count < limit; count++) { 1157836SJohn.Forte@Sun.COM memcpy(&mapping->entry[count].ScsiId, 116*10155SDuo.Liu@Sun.COM &mappingV2->entry[count-current].ScsiId, 1177836SJohn.Forte@Sun.COM sizeof (mapping->entry[count].ScsiId)); 1187836SJohn.Forte@Sun.COM memcpy(&mapping->entry[count].FcpId, 119*10155SDuo.Liu@Sun.COM &mappingV2->entry[count-current].FcpId, 1207836SJohn.Forte@Sun.COM sizeof (mapping->entry[count].FcpId)); 1217836SJohn.Forte@Sun.COM } 122*10155SDuo.Liu@Sun.COM current = mapping->NumberOfEntries; 1237836SJohn.Forte@Sun.COM } 1247836SJohn.Forte@Sun.COM 1257836SJohn.Forte@Sun.COM delete(mappingV2); 1267836SJohn.Forte@Sun.COM return (status); 1277836SJohn.Forte@Sun.COM } 1287836SJohn.Forte@Sun.COM #ifdef __cplusplus 1297836SJohn.Forte@Sun.COM } 1307836SJohn.Forte@Sun.COM #endif 131