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 * Discover an HBA node with matching path.
31 * The di_node_t argument should be the root of the device tree.
32 * This routine assumes the locks have been taken
35 find_matching_hba(di_node_t node
, void *arg
)
38 walkarg_t
*wa
= (walkarg_t
*)arg
;
39 char *devpath
, fulldevpath
[MAXPATHLEN
];
41 /* Skip stub(instance -1) nodes */
42 if (IS_STUB_NODE(node
)) {
43 return (DI_WALK_CONTINUE
);
46 rval
= di_prop_lookup_ints(DDI_DEV_T_ANY
, node
,
47 "sm-hba-supported", &propData
);
49 return (DI_WALK_CONTINUE
);
51 if ((devpath
= di_devfs_path(node
)) == NULL
) {
52 /* still continue to see if there is matching one. */
53 return (DI_WALK_CONTINUE
);
55 (void) snprintf(fulldevpath
, MAXPATHLEN
, "%s%s", DEVICES_DIR
,
58 if ((strstr(fulldevpath
, wa
->devpath
)) != NULL
) {
60 /* Found a node. No need to walk any more. */
61 di_devfs_path_free(devpath
);
62 return (DI_WALK_TERMINATE
);
64 di_devfs_path_free(devpath
);
67 return (DI_WALK_CONTINUE
);
71 * Refreshes information about an HBA
73 * Note: This routine holds the locks in write mode
74 * during most of the processing, and as such, will cause
75 * all other threads to block on entry into the library
76 * until the refresh is complete. An optimization would be
77 * to put fine-grain locking in for the open_handle structures.
80 Sun_sasRefreshAdapterConfiguration()
82 const char ROUTINE
[] =
83 "Sun_sasRefreshAdapterConfiguration";
84 struct sun_sas_hba
*hba_ptr
;
92 * We're going to be tweaking a lot of global lists, so write
96 lock(&open_handles_lock
);
99 /* Grab device tree */
100 if ((root
= di_init("/", DINFOCACHE
)) == DI_NODE_NIL
) {
101 log(LOG_DEBUG
, ROUTINE
,
102 "Unable to load device tree for reason \"%s\"",
104 unlock(&open_handles_lock
);
105 unlock(&all_hbas_lock
);
110 duration
= end
- start
;
111 duration
/= HR_SECOND
;
112 log(LOG_DEBUG
, ROUTINE
, "Device tree init took "
113 "%.6f seconds", duration
);
115 for (hba_ptr
= global_hba_head
; hba_ptr
!= NULL
;
116 hba_ptr
= hba_ptr
->next
) {
117 wa
.devpath
= hba_ptr
->device_path
;
118 wa
.flag
= (boolean_t
*)calloc(1, sizeof (boolean_t
));
121 if (di_walk_node(root
, DI_WALK_SIBFIRST
, &wa
,
122 find_matching_hba
) != 0) {
123 log(LOG_DEBUG
, ROUTINE
, "di_walk_node failed.");
124 unlock(&open_handles_lock
);
125 unlock(&all_hbas_lock
);
131 if (*wa
.flag
== B_FALSE
) {
133 * Keep the HBA as it is including open handles
134 * per the SM-HBA standards. Just mark it as invalid.
136 log(LOG_DEBUG
, ROUTINE
, "No matching HBA found. %s",
137 hba_ptr
->device_path
);
138 hba_ptr
->invalid
= B_TRUE
;
144 * Now we marked missing HBA(s). Redisoover hbas to refresh
145 * or add any new adapter to the hba list.
146 * Simply call devtree_get_all_hbas().
148 if (devtree_get_all_hbas(root
) != HBA_STATUS_OK
) {
149 log(LOG_DEBUG
, ROUTINE
, "devtree_get_all_hbas failed.");
153 unlock(&open_handles_lock
);
154 unlock(&all_hbas_lock
);