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.
27 * Copyright 2019 Joyent, Inc.
33 * Discover an HBA node with matching path.
34 * The di_node_t argument should be the root of the device tree.
35 * This routine assumes the locks have been taken
38 find_matching_hba(di_node_t node
, void *arg
)
41 walkarg_t
*wa
= (walkarg_t
*)arg
;
42 char *devpath
, fulldevpath
[MAXPATHLEN
];
44 /* Skip stub(instance -1) nodes */
45 if (IS_STUB_NODE(node
)) {
46 return (DI_WALK_CONTINUE
);
49 rval
= di_prop_lookup_ints(DDI_DEV_T_ANY
, node
,
50 "sm-hba-supported", &propData
);
52 return (DI_WALK_CONTINUE
);
54 if ((devpath
= di_devfs_path(node
)) == NULL
) {
55 /* still continue to see if there is matching one. */
56 return (DI_WALK_CONTINUE
);
58 (void) snprintf(fulldevpath
, MAXPATHLEN
, "%s%s", DEVICES_DIR
,
61 if ((strstr(fulldevpath
, wa
->devpath
)) != NULL
) {
63 /* Found a node. No need to walk any more. */
64 di_devfs_path_free(devpath
);
65 return (DI_WALK_TERMINATE
);
67 di_devfs_path_free(devpath
);
70 return (DI_WALK_CONTINUE
);
74 * Refreshes information about an HBA
76 * Note: This routine holds the locks in write mode
77 * during most of the processing, and as such, will cause
78 * all other threads to block on entry into the library
79 * until the refresh is complete. An optimization would be
80 * to put fine-grain locking in for the open_handle structures.
83 Sun_sasRefreshAdapterConfiguration()
85 const char ROUTINE
[] =
86 "Sun_sasRefreshAdapterConfiguration";
87 struct sun_sas_hba
*hba_ptr
;
95 * We're going to be tweaking a lot of global lists, so write
99 lock(&open_handles_lock
);
102 /* Grab device tree */
103 if ((root
= di_init("/", DINFOCACHE
)) == DI_NODE_NIL
) {
104 log(LOG_DEBUG
, ROUTINE
,
105 "Unable to load device tree for reason \"%s\"",
107 unlock(&open_handles_lock
);
108 unlock(&all_hbas_lock
);
113 duration
= end
- start
;
114 duration
/= HR_SECOND
;
115 log(LOG_DEBUG
, ROUTINE
, "Device tree init took "
116 "%.6f seconds", duration
);
118 for (hba_ptr
= global_hba_head
; hba_ptr
!= NULL
;
119 hba_ptr
= hba_ptr
->next
) {
120 wa
.devpath
= hba_ptr
->device_path
;
121 wa
.flag
= (boolean_t
*)calloc(1, sizeof (boolean_t
));
124 if (di_walk_node(root
, DI_WALK_SIBFIRST
, &wa
,
125 find_matching_hba
) != 0) {
126 log(LOG_DEBUG
, ROUTINE
, "di_walk_node failed.");
127 unlock(&open_handles_lock
);
128 unlock(&all_hbas_lock
);
134 if (*wa
.flag
== B_FALSE
) {
136 * Keep the HBA as it is including open handles
137 * per the SM-HBA standards. Just mark it as invalid.
139 log(LOG_DEBUG
, ROUTINE
, "No matching HBA found. %s",
140 hba_ptr
->device_path
);
141 hba_ptr
->invalid
= B_TRUE
;
147 * Now we marked missing HBA(s). Redisoover hbas to refresh
148 * or add any new adapter to the hba list.
149 * Simply call devtree_get_all_hbas().
151 if (devtree_get_all_hbas(root
) != HBA_STATUS_OK
) {
152 log(LOG_DEBUG
, ROUTINE
, "devtree_get_all_hbas failed.");
156 unlock(&open_handles_lock
);
157 unlock(&all_hbas_lock
);