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 * Returns the number of HBAs supported by the library. This returns the
31 * current number of HBAs, even if this changes
34 HBA_UINT32
Sun_sasGetNumberOfPorts(
35 HBA_HANDLE handle
, HBA_UINT32
*numberofports
)
37 const char ROUTINE
[] = "Sun_sasGetNumberOfPorts";
39 struct sun_sas_hba
*hba_ptr
;
40 struct sun_sas_port
*hba_port_ptr
;
42 if (numberofports
== NULL
) {
43 log(LOG_DEBUG
, ROUTINE
, "NULL numberofPorts pointer");
44 return (HBA_STATUS_ERROR_ARG
);
48 index
= RetrieveIndex(handle
);
49 lock(&open_handles_lock
);
50 hba_ptr
= RetrieveHandle(index
);
51 if (hba_ptr
== NULL
) {
52 log(LOG_DEBUG
, ROUTINE
, "Invalid handle %08lx.", handle
);
53 /* on error, need to set NumberOfEntries to 0 */
54 unlock(&open_handles_lock
);
55 unlock(&all_hbas_lock
);
56 return (HBA_STATUS_ERROR_INVALID_HANDLE
);
58 /* goes through hba list counting all the hbas found */
59 if (hba_ptr
->first_port
== NULL
) {
60 log(LOG_DEBUG
, ROUTINE
, "No HBA Port found on handle %08lx.",
62 /* on error, need to set NumberOfPorts to 0 */
64 unlock(&open_handles_lock
);
65 unlock(&all_hbas_lock
);
66 return (HBA_STATUS_OK
);
69 for (count
= 0, hba_port_ptr
= hba_ptr
->first_port
;
70 hba_port_ptr
!= NULL
; hba_port_ptr
= hba_port_ptr
->next
, count
++) {}
72 *numberofports
= count
;
74 unlock(&open_handles_lock
);
75 unlock(&all_hbas_lock
);
77 return (HBA_STATUS_OK
);