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.
31 * Loads the HBA Library. Must be called before calling any HBA library
35 * HBA_STATUS_OK library properly loaded
36 * HBA_STATUS_ERROR library loaded incorrectly
39 HBA_STATUS
Sun_sasLoadLibrary() {
40 const char ROUTINE
[] = "Sun_sasLoadLibrary";
42 boolean_t atLeastOneHBA
= B_FALSE
;
43 boolean_t atLeastOneFailure
= B_FALSE
;
48 /* Make sure that library has not been already loaded */
49 if (loadCount
++ > 0) {
50 log(LOG_DEBUG
, ROUTINE
, "Library already loaded %d time."
51 " Ignoring.", loadCount
);
52 return (HBA_STATUS_ERROR
);
55 open_handle_index
= 1;
56 /* Initialize the read-write lock */
57 if (mutex_init(&all_hbas_lock
, USYNC_THREAD
, NULL
)) {
58 log(LOG_DEBUG
, ROUTINE
,
59 "Unable to initialize lock in LoadLibrary for reason \"%s\"",
61 return (HBA_STATUS_ERROR
);
67 if ((root
= di_init("/", DINFOCACHE
)) == DI_NODE_NIL
) {
68 log(LOG_DEBUG
, ROUTINE
,
69 "Unable to load device tree for reason \"%s\"",
71 unlock(&all_hbas_lock
);
72 return (HBA_STATUS_ERROR
);
75 duration
= end
- start
;
76 duration
/= HR_SECOND
;
77 log(LOG_DEBUG
, ROUTINE
, "Loading device tree init took "
78 "%.6f seconds", duration
);
80 /* At load time, we only gather libdevinfo information */
81 if (devtree_get_all_hbas(root
) == HBA_STATUS_OK
) {
82 atLeastOneHBA
= B_TRUE
;
84 atLeastOneFailure
= B_TRUE
;
89 unlock(&all_hbas_lock
);
91 /* Now determine what status code to return */
93 /* We've got at least one HBA and possibly some failures */
94 return (HBA_STATUS_OK
);
95 } else if (atLeastOneFailure
) {
96 /* We have no HBAs but have failures */
97 return (HBA_STATUS_ERROR
);
99 /* We have no HBAs and no failures */
100 return (HBA_STATUS_OK
);