4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 #include "Exceptions.h"
39 getAdapterPortWWN(HBA_HANDLE handle
,HBA_UINT32 index
) {
41 memset(hba_wwn
.wwn
, 0, sizeof (hba_wwn
));
43 Handle
*myHandle
= Handle::findHandle(handle
);
44 HBA
*hba
= myHandle
->getHBA();
45 HBAPort
*port
= hba
->getPortByIndex(index
);
46 uint64_t tmp
= htonll(port
->getPortWWN());
47 memcpy(hba_wwn
.wwn
, &tmp
, sizeof (hba_wwn
));
57 * @memo Retrieves the mapping between FCP targets and OS
59 * @return HBA_STATUS_OK if the mapping structure contains valid
61 * @param handle The HBA to fetch mappings for
62 * @param mapping The user-allocated mapping structure
64 * @doc This routine will call the V2 interface and convert
65 * the results to the old data structure. It will
66 * call the V2 interface for all ports on the HBA.
69 Sun_fcGetFcpTargetMapping(HBA_HANDLE handle
, PHBA_FCPTARGETMAPPING mapping
) {
72 PHBA_FCPTARGETMAPPINGV2 mappingV2
;
73 HBA_ADAPTERATTRIBUTES attributes
;
74 HBA_UINT32 entries
= 0;
75 HBA_UINT32 current
= 0;
79 Trace
log("Sun_fcGetFcpTargetMapping");
81 if (mapping
== NULL
) {
82 log
.userError("NULL mapping argument.");
83 return (HBA_STATUS_ERROR_ARG
);
86 entries
= mapping
->NumberOfEntries
;
88 /* get adapter attributes for number of ports */
89 status
= Sun_fcGetAdapterAttributes(handle
,&attributes
);
90 if (status
!= HBA_STATUS_OK
) {
91 log
.userError("Unable to get adapter attributes");
92 return HBA_STATUS_ERROR
;
95 mappingV2
= (PHBA_FCPTARGETMAPPINGV2
) new uchar_t
[
96 (sizeof (HBA_FCPSCSIENTRYV2
)*(mapping
->NumberOfEntries
-1)) +
97 sizeof (HBA_FCPTARGETMAPPINGV2
)];
98 mapping
->NumberOfEntries
= 0;
100 for(port
= 0; port
< attributes
.NumberOfPorts
; port
++) {
101 mappingV2
->NumberOfEntries
= mapping
->NumberOfEntries
< entries
?
102 entries
- mapping
->NumberOfEntries
: 0 ;
103 status
= Sun_fcGetFcpTargetMappingV2(handle
,
104 getAdapterPortWWN(handle
,port
), mappingV2
);
105 mapping
->NumberOfEntries
+= mappingV2
->NumberOfEntries
;
107 if (status
!= HBA_STATUS_OK
&& status
!= HBA_STATUS_ERROR_MORE_DATA
) {
108 log
.userError("Unable to get mappings for port");
112 * need to copy from PHBA_FCPTARGETMAPPINGV2 to
113 * PHBA_FCPTARGETMAPPING
115 limit
= (mapping
->NumberOfEntries
< entries
) ? mapping
->NumberOfEntries
: entries
;
116 for (count
= current
; count
< limit
; count
++) {
117 memcpy(&mapping
->entry
[count
].ScsiId
,
118 &mappingV2
->entry
[count
-current
].ScsiId
,
119 sizeof (mapping
->entry
[count
].ScsiId
));
120 memcpy(&mapping
->entry
[count
].FcpId
,
121 &mappingV2
->entry
[count
-current
].FcpId
,
122 sizeof (mapping
->entry
[count
].FcpId
));
124 current
= mapping
->NumberOfEntries
;