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 mtaching 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 match_smhba_sas_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
) {
59 /* add the hba to the hba list */
60 if (devtree_get_one_hba(node
) ==
62 /* succeed to refresh the adapater. */
65 /* Found a node. No need to walk any more. */
66 di_devfs_path_free(devpath
);
67 return (DI_WALK_TERMINATE
);
69 di_devfs_path_free(devpath
);
72 return (DI_WALK_CONTINUE
);
76 * Refreshes information about an HBA
78 * Note: This routine holds the locks in write mode
79 * during most of the processing, and as such, will cause
80 * all other threads to block on entry into the library
81 * until the refresh is complete. An optimization would be
82 * to put fine-grain locking in for the open_handle structures.
85 Sun_sasRefreshInformation(HBA_HANDLE handle
)
87 const char ROUTINE
[] = "Sun_sasRefreshInformation";
88 struct sun_sas_hba
*hba_ptr
;
89 struct open_handle
*oHandle
;
96 /* take a lock for hbas and handles during rerfresh. */
98 lock(&open_handles_lock
);
100 oHandle
= RetrieveOpenHandle(handle
);
101 if (oHandle
== NULL
) {
102 log(LOG_DEBUG
, ROUTINE
, "Invalid handle %08lx", handle
);
103 unlock(&open_handles_lock
);
104 unlock(&all_hbas_lock
);
108 /* now we know the associated hba exists in the global list. */
110 /* Grab device tree */
111 if ((root
= di_init("/", DINFOCACHE
)) == DI_NODE_NIL
) {
112 log(LOG_DEBUG
, ROUTINE
,
113 "Unable to load device tree for reason \"%s\"",
115 unlock(&open_handles_lock
);
116 unlock(&all_hbas_lock
);
121 duration
= end
- start
;
122 duration
/= HR_SECOND
;
123 log(LOG_DEBUG
, ROUTINE
, "Device tree init took "
124 "%.6f seconds", duration
);
126 hba_ptr
= RetrieveHandle(oHandle
->adapterIndex
);
127 wa
.devpath
= hba_ptr
->device_path
;
128 wa
.flag
= (boolean_t
*)calloc(1, sizeof (boolean_t
));
131 /* found the matching hba node and refresh hba ports and targets. */
132 if (di_walk_node(root
, DI_WALK_SIBFIRST
, &wa
,
133 match_smhba_sas_hba
) != 0) {
134 log(LOG_DEBUG
, ROUTINE
, "di_walk_node failed.");
135 unlock(&open_handles_lock
);
136 unlock(&all_hbas_lock
);
142 if (*wa
.flag
!= B_TRUE
) {
143 /* no matching HBA. */
144 log(LOG_DEBUG
, ROUTINE
, "No matching HBA found.");
145 unlock(&open_handles_lock
);
146 unlock(&all_hbas_lock
);
156 /* All done, release the locks */
157 unlock(&open_handles_lock
);
158 unlock(&all_hbas_lock
);