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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 * Retrieves the attributes for a specified port of an adapter
33 Sun_sasGetAdapterPortAttributes(HBA_HANDLE handle
,
34 HBA_UINT32 port
, PSMHBA_PORTATTRIBUTES attributes
) {
35 const char ROUTINE
[] = "Sun_sasGetAdapterPortAttributes";
37 struct sun_sas_hba
*hba_ptr
;
38 struct sun_sas_port
*hba_port_ptr
;
41 /* Validate the arguments */
42 if ((attributes
== NULL
) ||
43 (attributes
->PortSpecificAttribute
.SASPort
== NULL
)) {
44 log(LOG_DEBUG
, ROUTINE
, "NULL attributes");
45 return (HBA_STATUS_ERROR_ARG
);
49 index
= RetrieveIndex(handle
);
50 lock(&open_handles_lock
);
51 hba_ptr
= RetrieveHandle(index
);
52 if (hba_ptr
== NULL
) {
53 log(LOG_DEBUG
, ROUTINE
, "Invalid handle %08lx", handle
);
54 unlock(&open_handles_lock
);
55 unlock(&all_hbas_lock
);
56 return (HBA_STATUS_ERROR_INVALID_HANDLE
);
59 /* Check for stale data */
60 status
= verifyAdapter(hba_ptr
);
61 if (status
!= HBA_STATUS_OK
) {
62 log(LOG_DEBUG
, ROUTINE
, "Verify Adapter failed");
63 unlock(&open_handles_lock
);
64 unlock(&all_hbas_lock
);
68 if (hba_ptr
->first_port
== NULL
) {
69 /* This is probably an internal failure of the library */
70 if (hba_ptr
->device_path
) {
71 log(LOG_DEBUG
, ROUTINE
,
72 "Internal failure: Adapter %s contains no port data",
73 hba_ptr
->device_path
);
75 log(LOG_DEBUG
, ROUTINE
,
76 "Internal failure: Adapter at index %d contains no port "
77 "data", hba_ptr
->index
);
79 unlock(&open_handles_lock
);
80 unlock(&all_hbas_lock
);
81 return (HBA_STATUS_ERROR
);
83 for (hba_port_ptr
= hba_ptr
->first_port
;
84 hba_port_ptr
!= NULL
; hba_port_ptr
= hba_port_ptr
->next
) {
85 if (hba_port_ptr
->index
== port
) {
89 if (hba_port_ptr
== NULL
|| hba_port_ptr
->index
!= port
) {
90 log(LOG_DEBUG
, ROUTINE
,
91 "Invalid port index %d for handle %08lx.",
93 unlock(&open_handles_lock
);
94 unlock(&all_hbas_lock
);
95 return (HBA_STATUS_ERROR_ILLEGAL_INDEX
);
98 attributes
->PortType
= hba_port_ptr
->port_attributes
.PortType
;
99 attributes
->PortState
= hba_port_ptr
->port_attributes
.PortState
;
100 (void) strlcpy(attributes
->OSDeviceName
,
101 hba_port_ptr
->port_attributes
.OSDeviceName
,
102 sizeof (attributes
->OSDeviceName
));
103 (void) memcpy(attributes
->PortSpecificAttribute
.SASPort
,
104 hba_port_ptr
->port_attributes
.PortSpecificAttribute
.SASPort
,
105 sizeof (struct SMHBA_SAS_Port
));
107 unlock(&open_handles_lock
);
108 unlock(&all_hbas_lock
);
110 return (HBA_STATUS_OK
);