1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21fcf3ce44SJohn Forte /*
2283bf661fSduo liu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fcf3ce44SJohn Forte * Use is subject to license terms.
24fcf3ce44SJohn Forte */
25fcf3ce44SJohn Forte
26fcf3ce44SJohn Forte
27fcf3ce44SJohn Forte
28fcf3ce44SJohn Forte #include "Trace.h"
29fcf3ce44SJohn Forte #include "Exceptions.h"
30fcf3ce44SJohn Forte #include "sun_fc.h"
31fcf3ce44SJohn Forte
32fcf3ce44SJohn Forte
33fcf3ce44SJohn Forte
34fcf3ce44SJohn Forte #include <string.h>
35fcf3ce44SJohn Forte #include "Handle.h"
36fcf3ce44SJohn Forte #include "HBA.h"
37fcf3ce44SJohn Forte #include "HBAPort.h"
38fcf3ce44SJohn Forte inline HBA_WWN
getAdapterPortWWN(HBA_HANDLE handle,HBA_UINT32 index)3983bf661fSduo liu - Sun Microsystems - Beijing China getAdapterPortWWN(HBA_HANDLE handle,HBA_UINT32 index) {
40fcf3ce44SJohn Forte HBA_WWN hba_wwn;
41fcf3ce44SJohn Forte memset(hba_wwn.wwn, 0, sizeof (hba_wwn));
42fcf3ce44SJohn Forte try {
43fcf3ce44SJohn Forte Handle *myHandle = Handle::findHandle(handle);
44fcf3ce44SJohn Forte HBA *hba = myHandle->getHBA();
4583bf661fSduo liu - Sun Microsystems - Beijing China HBAPort *port = hba->getPortByIndex(index);
46fcf3ce44SJohn Forte uint64_t tmp = htonll(port->getPortWWN());
47fcf3ce44SJohn Forte memcpy(hba_wwn.wwn, &tmp, sizeof (hba_wwn));
48fcf3ce44SJohn Forte } catch (...) { }
49fcf3ce44SJohn Forte return (hba_wwn);
50fcf3ce44SJohn Forte }
51fcf3ce44SJohn Forte
52fcf3ce44SJohn Forte #ifdef __cplusplus
53fcf3ce44SJohn Forte extern "C" {
54fcf3ce44SJohn Forte #endif
55fcf3ce44SJohn Forte
56fcf3ce44SJohn Forte /**
57fcf3ce44SJohn Forte * @memo Retrieves the mapping between FCP targets and OS
58fcf3ce44SJohn Forte * SCSI information
59fcf3ce44SJohn Forte * @return HBA_STATUS_OK if the mapping structure contains valid
60fcf3ce44SJohn Forte * mapping data.
61fcf3ce44SJohn Forte * @param handle The HBA to fetch mappings for
62fcf3ce44SJohn Forte * @param mapping The user-allocated mapping structure
63fcf3ce44SJohn Forte *
64fcf3ce44SJohn Forte * @doc This routine will call the V2 interface and convert
65fcf3ce44SJohn Forte * the results to the old data structure. It will
66fcf3ce44SJohn Forte * call the V2 interface for all ports on the HBA.
67fcf3ce44SJohn Forte */
68fcf3ce44SJohn Forte HBA_STATUS
Sun_fcGetFcpTargetMapping(HBA_HANDLE handle,PHBA_FCPTARGETMAPPING mapping)69fcf3ce44SJohn Forte Sun_fcGetFcpTargetMapping(HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) {
70fcf3ce44SJohn Forte HBA_STATUS status;
71fcf3ce44SJohn Forte int count;
72fcf3ce44SJohn Forte PHBA_FCPTARGETMAPPINGV2 mappingV2;
7383bf661fSduo liu - Sun Microsystems - Beijing China HBA_ADAPTERATTRIBUTES attributes;
74*352290fbSduo liu - Sun Microsystems - Beijing China HBA_UINT32 entries = 0;
7583bf661fSduo liu - Sun Microsystems - Beijing China HBA_UINT32 current = 0;
7683bf661fSduo liu - Sun Microsystems - Beijing China HBA_UINT32 port;
7783bf661fSduo liu - Sun Microsystems - Beijing China HBA_UINT32 limit;
78fcf3ce44SJohn Forte
79fcf3ce44SJohn Forte Trace log("Sun_fcGetFcpTargetMapping");
80fcf3ce44SJohn Forte
81fcf3ce44SJohn Forte if (mapping == NULL) {
82fcf3ce44SJohn Forte log.userError("NULL mapping argument.");
83fcf3ce44SJohn Forte return (HBA_STATUS_ERROR_ARG);
84fcf3ce44SJohn Forte }
8583bf661fSduo liu - Sun Microsystems - Beijing China
86*352290fbSduo liu - Sun Microsystems - Beijing China entries = mapping->NumberOfEntries;
87*352290fbSduo liu - Sun Microsystems - Beijing China
8883bf661fSduo liu - Sun Microsystems - Beijing China /* get adapter attributes for number of ports */
8983bf661fSduo liu - Sun Microsystems - Beijing China status = Sun_fcGetAdapterAttributes(handle,&attributes);
9083bf661fSduo liu - Sun Microsystems - Beijing China if (status != HBA_STATUS_OK) {
9183bf661fSduo liu - Sun Microsystems - Beijing China log.userError("Unable to get adapter attributes");
9283bf661fSduo liu - Sun Microsystems - Beijing China return HBA_STATUS_ERROR;
9383bf661fSduo liu - Sun Microsystems - Beijing China }
9483bf661fSduo liu - Sun Microsystems - Beijing China
95fcf3ce44SJohn Forte mappingV2 = (PHBA_FCPTARGETMAPPINGV2) new uchar_t[
96fcf3ce44SJohn Forte (sizeof (HBA_FCPSCSIENTRYV2)*(mapping->NumberOfEntries-1)) +
97fcf3ce44SJohn Forte sizeof (HBA_FCPTARGETMAPPINGV2)];
9883bf661fSduo liu - Sun Microsystems - Beijing China mapping->NumberOfEntries = 0;
99fcf3ce44SJohn Forte
10083bf661fSduo liu - Sun Microsystems - Beijing China for(port = 0; port < attributes.NumberOfPorts; port++) {
10183bf661fSduo liu - Sun Microsystems - Beijing China mappingV2->NumberOfEntries = mapping->NumberOfEntries < entries ?
10283bf661fSduo liu - Sun Microsystems - Beijing China entries - mapping->NumberOfEntries : 0 ;
103fcf3ce44SJohn Forte status = Sun_fcGetFcpTargetMappingV2(handle,
10483bf661fSduo liu - Sun Microsystems - Beijing China getAdapterPortWWN(handle,port), mappingV2);
10583bf661fSduo liu - Sun Microsystems - Beijing China mapping->NumberOfEntries += mappingV2->NumberOfEntries;
10683bf661fSduo liu - Sun Microsystems - Beijing China
10783bf661fSduo liu - Sun Microsystems - Beijing China if (status != HBA_STATUS_OK && status != HBA_STATUS_ERROR_MORE_DATA) {
10883bf661fSduo liu - Sun Microsystems - Beijing China log.userError("Unable to get mappings for port");
10983bf661fSduo liu - Sun Microsystems - Beijing China return status;
11083bf661fSduo liu - Sun Microsystems - Beijing China }
111fcf3ce44SJohn Forte /*
112fcf3ce44SJohn Forte * need to copy from PHBA_FCPTARGETMAPPINGV2 to
113fcf3ce44SJohn Forte * PHBA_FCPTARGETMAPPING
114fcf3ce44SJohn Forte */
11583bf661fSduo liu - Sun Microsystems - Beijing China limit = (mapping->NumberOfEntries < entries) ? mapping->NumberOfEntries : entries;
11683bf661fSduo liu - Sun Microsystems - Beijing China for (count = current; count < limit; count++) {
117fcf3ce44SJohn Forte memcpy(&mapping->entry[count].ScsiId,
11883bf661fSduo liu - Sun Microsystems - Beijing China &mappingV2->entry[count-current].ScsiId,
119fcf3ce44SJohn Forte sizeof (mapping->entry[count].ScsiId));
120fcf3ce44SJohn Forte memcpy(&mapping->entry[count].FcpId,
12183bf661fSduo liu - Sun Microsystems - Beijing China &mappingV2->entry[count-current].FcpId,
122fcf3ce44SJohn Forte sizeof (mapping->entry[count].FcpId));
123fcf3ce44SJohn Forte }
12483bf661fSduo liu - Sun Microsystems - Beijing China current = mapping->NumberOfEntries;
125fcf3ce44SJohn Forte }
126fcf3ce44SJohn Forte
127fcf3ce44SJohn Forte delete(mappingV2);
128fcf3ce44SJohn Forte return (status);
129fcf3ce44SJohn Forte }
130fcf3ce44SJohn Forte #ifdef __cplusplus
131fcf3ce44SJohn Forte }
132fcf3ce44SJohn Forte #endif
133