Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/ibnex/ibnex.c
+++ new/usr/src/uts/common/io/ib/ibnex/ibnex.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 /*
26 26 * The InfiniBand Nexus driver (IB nexus) is a bus nexus driver for IB bus.
27 27 * It supports Port nodes, Virtual Physical Point of Attachment nodes (VPPA)
28 28 * for HCAs registered with IBTL and IOC nodes for all the IOCs present in
29 29 * the IB fabric (that are accessible to the host). It also supports Pseudo
30 30 * device children to be enumerated using their .conf file(s). All Port nodes
31 31 * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo
32 32 * device nodes are children of the IB nexus driver.
33 33 *
34 34 * IB nexus driver provides bus nexus entry points to all the HCA drivers.
35 35 *
36 36 * IB nexus driver registers with InfiniBand Device Manager (IBDM) to get
37 37 * information about all the HCA ports and I/O Controllers (IOCs) connected
38 38 * to the IB fabric. Based on that information, IB nexus will create all the
39 39 * device tree nodes.
40 40 */
41 41
42 42 #include <sys/conf.h>
43 43 #include <sys/stat.h>
44 44 #include <sys/modctl.h>
45 45 #include <sys/taskq.h>
46 46 #include <sys/mdi_impldefs.h>
47 47 #include <sys/sunmdi.h>
48 48 #include <sys/sunpm.h>
49 49 #include <sys/ib/mgt/ibdm/ibdm_impl.h>
50 50 #include <sys/ib/ibnex/ibnex.h>
51 51 #include <sys/ib/ibnex/ibnex_devctl.h>
52 52 #include <sys/ib/ibtl/ibti.h>
53 53 #include <sys/ib/ibtl/impl/ibtl_ibnex.h>
54 54 #include <sys/file.h>
55 55 #include <sys/hwconf.h>
56 56 #include <sys/fs/dv_node.h>
57 57
58 58 /* Function prototypes */
59 59 static int ibnex_attach(dev_info_t *, ddi_attach_cmd_t);
60 60 static int ibnex_getinfo(dev_info_t *, ddi_info_cmd_t,
61 61 void *, void **);
62 62 static int ibnex_detach(dev_info_t *, ddi_detach_cmd_t);
63 63 int ibnex_busctl(dev_info_t *,
64 64 dev_info_t *, ddi_ctl_enum_t, void *, void *);
65 65 int ibnex_map_fault(dev_info_t *,
66 66 dev_info_t *, struct hat *, struct seg *,
67 67 caddr_t, struct devpage *, pfn_t, uint_t, uint_t);
68 68 static int ibnex_init_child(dev_info_t *);
69 69 static ibnex_rval_t ibnex_comm_svc_init(char *, ibnex_node_type_t);
70 70 static void ibnex_comm_svc_fini();
71 71 dev_info_t *ibnex_commsvc_initnode(dev_info_t *,
72 72 ibdm_port_attr_t *, int, int, ib_pkey_t, int *,
73 73 int);
74 74 static void ibnex_delete_port_node_data(ibnex_node_data_t *);
75 75 int ibnex_get_dip_from_guid(ib_guid_t, int,
76 76 ib_pkey_t, dev_info_t **);
77 77 int ibnex_get_node_and_dip_from_guid(ib_guid_t, int,
78 78 ib_pkey_t, ibnex_node_data_t **, dev_info_t **);
79 79 static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t,
80 80 void *, int, ib_pkey_t);
81 81 static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *,
82 82 int, ib_pkey_t);
83 83 static int ibnex_create_port_node_prop(ibdm_port_attr_t *,
84 84 dev_info_t *, char *, ib_pkey_t);
85 85 void ibnex_dm_callback(void *, ibdm_events_t);
86 86 static int ibnex_create_port_compatible_prop(dev_info_t *,
87 87 char *, ibdm_port_attr_t *);
88 88 static int ibnex_create_ioc_srv_props(
89 89 dev_info_t *, ibdm_ioc_info_t *);
90 90 static int ibnex_get_eventcookie(dev_info_t *,
91 91 dev_info_t *, char *, ddi_eventcookie_t *);
92 92 static int ibnex_add_eventcall(dev_info_t *, dev_info_t *,
93 93 ddi_eventcookie_t, void (*)(dev_info_t *,
94 94 ddi_eventcookie_t, void *, void *),
95 95 void *arg, ddi_callback_id_t *cb_id);
96 96 static int ibnex_remove_eventcall(dev_info_t *,
97 97 ddi_callback_id_t);
98 98 static int ibnex_post_event(dev_info_t *, dev_info_t *,
99 99 ddi_eventcookie_t, void *);
100 100 static int ibnex_bus_config(dev_info_t *, uint_t,
101 101 ddi_bus_config_op_t, void *, dev_info_t **);
102 102 static int ibnex_bus_unconfig(dev_info_t *,
103 103 uint_t, ddi_bus_config_op_t, void *);
104 104 dev_info_t *ibnex_config_port_node(dev_info_t *, char *);
105 105 int ibnex_get_pkey_commsvc_index_portnum(
106 106 char *, int *, ib_pkey_t *, uint8_t *);
107 107 void ibnex_config_all_children(dev_info_t *);
108 108 static int ibnex_devname_to_portnum(char *, uint8_t *);
109 109 void ibnex_create_vppa_nodes(dev_info_t *, ibdm_port_attr_t *);
110 110 void ibnex_create_port_nodes(
111 111 dev_info_t *, ibdm_port_attr_t *);
112 112 void ibnex_create_hcasvc_nodes(
113 113 dev_info_t *, ibdm_port_attr_t *);
114 114 static int ibnex_config_root_iocnode(dev_info_t *, char *);
115 115 static int ibnex_devname2port(char *, int *);
116 116 static int ibnex_config_ioc_node(char *, dev_info_t *);
117 117 static int ibnex_devname_to_node_n_ioc_guids(
118 118 char *, ib_guid_t *, ib_guid_t *, char **);
119 119 static void ibnex_ioc_node_cleanup();
120 120 static void ibnex_delete_ioc_node_data(ibnex_node_data_t *);
121 121 int ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *);
122 122 static int ibnex_ioc_initnode_pdip(ibnex_node_data_t *,
123 123 ibdm_ioc_info_t *, dev_info_t *);
124 124 static int ibnex_create_ioc_node_prop(
125 125 ibdm_ioc_info_t *, dev_info_t *);
126 126 static int ibnex_create_ioc_compatible_prop(
127 127 dev_info_t *, ib_dm_ioc_ctrl_profile_t *);
128 128 uint64_t ibnex_str2hex(char *, int, int *);
129 129 int ibnex_str2int(char *, int, int *);
130 130 static int ibnex_create_ioc_portgid_prop(
131 131 dev_info_t *, ibdm_ioc_info_t *);
132 132 static void ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int);
133 133 static void ibnex_wakeup_reprobe_all();
134 134 ibt_status_t ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *);
135 135 void ibnex_pseudo_initnodes(void);
136 136 static char *ibnex_lookup_named_prop(ddi_prop_t *, char *);
137 137 static void ibnex_pseudo_node_cleanup(void);
138 138 static int ibnex_name_child(dev_info_t *, char *, int);
139 139 static int ibnex_name_pseudo_child(dev_info_t *, char *);
140 140
141 141 void ibnex_reprobe_ioc_dev(void *);
142 142 void ibnex_reprobe_ioc_all();
143 143 static void ibnex_update_prop(ibnex_node_data_t *,
144 144 ibdm_ioc_info_t *);
145 145 static ibnex_rval_t ibnex_unique_svcname(char *);
146 146 static void ibnex_handle_reprobe_dev(void *arg);
147 147
148 148 extern int ibnex_open(dev_t *, int, int, cred_t *);
149 149 extern int ibnex_close(dev_t, int, int, cred_t *);
150 150 extern int ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
151 151 extern int ibnex_offline_childdip(dev_info_t *);
152 152
153 153 static int ibnex_ioc_create_pi(
154 154 ibdm_ioc_info_t *, ibnex_node_data_t *,
155 155 dev_info_t *, int *);
156 156 static int ibnex_bus_power(dev_info_t *, void *,
157 157 pm_bus_power_op_t, void *, void *);
158 158 int ibnex_pseudo_create_all_pi(ibnex_node_data_t *);
159 159 static int ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *,
160 160 dev_info_t *);
161 161 int ibnex_pseudo_config_one(
162 162 ibnex_node_data_t *, char *, dev_info_t *);
163 163 int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **,
164 164 char *, char *);
165 165 static void ibnex_config_pseudo_all(dev_info_t *);
166 166 int ibnex_ioc_bus_config_one(dev_info_t **, uint_t,
167 167 ddi_bus_config_op_t, void *, dev_info_t **, int *);
168 168 static int ibnex_is_merge_node(dev_info_t *);
169 169 static void ibnex_hw_in_dev_tree(char *);
170 170 static int ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *,
171 171 dev_info_t *, int);
172 172 static int ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *);
173 173 static int ibnex_ioc_pi_reachable(ibdm_ioc_info_t *,
174 174 dev_info_t *);
175 175
176 176 extern void ibnex_handle_hca_attach(void *);
177 177
178 178 extern struct bus_ops ibnex_ci_busops;
179 179 /*
180 180 * Prototype declarations for the VHCI options
181 181 */
182 182 /*
183 183 * Functions registered with the mpxio framework
184 184 */
185 185 static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int);
186 186 static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int);
187 187 static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *,
188 188 mdi_pathinfo_state_t, uint32_t, int);
189 189 static int ib_vhci_failover(dev_info_t *, dev_info_t *, int);
190 190
191 191
192 192 static mdi_vhci_ops_t ibnex_vhci_ops = {
193 193 MDI_VHCI_OPS_REV,
194 194 ib_vhci_pi_init,
195 195 ib_vhci_pi_uninit,
196 196 ib_vhci_pi_state_change,
197 197 ib_vhci_failover
198 198 };
199 199
200 200
201 201 /*
202 202 * The bus_ops structure defines the capabilities of IB nexus driver.
203 203 * IB nexus drivers does not support any DMA operations for its children
204 204 * as there is no such concept in Infiniband. All the memory operations
205 205 * and DMA operations required by the child drivers can be performed using
206 206 * the IBTF API.
207 207 */
208 208 struct bus_ops ibnex_bus_ops = {
209 209 BUSO_REV,
210 210 nullbusmap, /* bus_map */
211 211 NULL, /* bus_get_intrspec */
212 212 NULL, /* bus_add_intrspec */
213 213 NULL, /* bus_remove_intrspec */
214 214 ibnex_map_fault, /* Map Fault */
215 215 ddi_no_dma_map, /* DMA related entry points */
216 216 ddi_no_dma_allochdl,
217 217 NULL,
218 218 NULL,
219 219 NULL,
220 220 NULL,
221 221 NULL,
222 222 NULL,
223 223 ibnex_busctl, /* bus_ctl */
224 224 ddi_bus_prop_op, /* bus_prop_op */
225 225 ibnex_get_eventcookie, /* bus_get_eventcookie */
226 226 ibnex_add_eventcall, /* bus_add_eventcall */
227 227 ibnex_remove_eventcall, /* bus_remove_eventcall */
228 228 ibnex_post_event, /* bus_post_event */
229 229 NULL,
230 230 ibnex_bus_config, /* bus config */
231 231 ibnex_bus_unconfig, /* bus unconfig */
232 232 NULL, /* bus fm init */
233 233 NULL, /* bus fm fini */
234 234 NULL, /* bus fm access enter */
235 235 NULL, /* bus fm access exit */
236 236 ibnex_bus_power /* bus power */
237 237 };
238 238
239 239 /* ibnex cb_ops */
240 240 static struct cb_ops ibnex_cbops = {
241 241 ibnex_open, /* open */
242 242 ibnex_close, /* close */
243 243 nodev, /* strategy */
244 244 nodev, /* print */
245 245 nodev, /* dump */
246 246 nodev, /* read */
247 247 nodev, /* write */
248 248 ibnex_ioctl, /* ioctl */
249 249 nodev, /* devmap */
250 250 nodev, /* mmap */
251 251 nodev, /* segmap */
252 252 nochpoll, /* poll */
253 253 ddi_prop_op, /* prop_op */
254 254 NULL, /* stream */
255 255 D_MP, /* cb_flag */
256 256 CB_REV, /* rev */
257 257 nodev, /* int (*cb_aread)() */
258 258 nodev /* int (*cb_awrite)() */
259 259 };
260 260
261 261 /*
262 262 * Device options
263 263 * Note: ddi_no_info needs to change during devfs time frame. The drivers
264 264 * with 1 to 1 mapping between minor node and instance should use
265 265 * ddi_1to1_info. (See bug id 4424752)
266 266 */
267 267 static struct dev_ops ibnex_ops = {
268 268 DEVO_REV, /* devo_rev, */
269 269 0, /* refcnt */
270 270 ibnex_getinfo, /* info */
271 271 nulldev, /* identify */
272 272 nulldev, /* probe */
273 273 ibnex_attach, /* attach */
274 274 ibnex_detach, /* detach */
275 275 nodev, /* reset */
276 276 &ibnex_cbops, /* driver ops - devctl interfaces */
277 277 &ibnex_bus_ops, /* bus operations */
278 278 nulldev, /* power */
279 279 ddi_quiesce_not_needed, /* quiesce */
↓ open down ↓ |
279 lines elided |
↑ open up ↑ |
280 280 };
281 281
282 282 /* Module linkage information for the kernel. */
283 283 static struct modldrv modldrv = {
284 284 &mod_driverops, /* Driver module */
285 285 "IB nexus", /* Driver name and version */
286 286 &ibnex_ops, /* driver ops */
287 287 };
288 288
289 289 static struct modlinkage modlinkage = {
290 - MODREV_1, (void *)&modldrv, NULL
290 + MODREV_1, { (void *)&modldrv, NULL }
291 291 };
292 292
293 293 /*
294 294 * Global per-instance IB Nexus data.
295 295 * There is only one instance of IB Nexus supported.
296 296 */
297 297 ibnex_t ibnex;
298 298 #ifdef __lock_lint
299 299 extern ibdm_t ibdm;
300 300 #endif
301 301 _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s))
302 302 _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs
303 303 ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs
304 304 ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs
305 305 ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list))
306 306 _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s))
307 307 _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex))
308 308
309 309 /* The port settling time in seconds */
310 310 int ibnex_port_settling_time = 8;
311 311
312 312 /* create an array of properties supported, easier to add new ones here */
313 313 static struct ibnex_property {
314 314 char *name;
315 315 ibnex_node_type_t type;
316 316 } ibnex_properties[] = {
317 317 { "port-svc-list", IBNEX_PORT_COMMSVC_NODE},
318 318 { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE},
319 319 { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE}
320 320 };
321 321
322 322 #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \
323 323 (sizeof (struct ibnex_property))
324 324
325 325 /*
326 326 * Event Definition
327 327 * Single event, event name defined in ibti_common.h.
328 328 * Event posted to specific child handler. Event posted
329 329 * at kernel priority.
330 330 */
331 331 static ndi_event_definition_t ibnex_ndi_event_defs[] = {
332 332 {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL,
333 333 NDI_EVENT_POST_TO_TGT}
334 334 };
335 335
336 336 #define IB_N_NDI_EVENTS \
337 337 (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t))
338 338
339 339 static ndi_event_set_t ib_ndi_events = {
340 340 NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs};
341 341 static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED;
342 342
343 343
344 344 /*
345 345 * _init
346 346 * Loadable module init, called before any other module.
347 347 */
348 348 int
349 349 _init(void)
350 350 {
351 351 int error;
352 352 char **hca_driver_list;
353 353 int i, ndrivers;
354 354
355 355 if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) {
356 356 ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE;
357 357 hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers);
358 358 for (i = 0; i < ndrivers; i++) {
359 359 ibnex_hw_in_dev_tree(hca_driver_list[i]);
360 360 if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE)
361 361 break;
362 362 }
363 363 mdi_free_phci_driver_list(hca_driver_list, ndrivers);
364 364 }
365 365
366 366 /*
367 367 * IB Nexus _init can be called while force attaching
368 368 * IB Nexus driver or when a HCA is hotplugged.
369 369 *
370 370 * If IB HW is not in device tree or if no HCA driver
371 371 * has been attached, fail IB Nexus _init().
372 372 */
373 373 if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE &&
374 374 ibt_hw_is_present() == 0) {
375 375 IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW");
376 376 return (DDI_FAILURE);
377 377 }
378 378
379 379 IBTF_DPRINTF_L4("ibnex", "\t_init");
380 380 mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL);
381 381 cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL);
382 382 cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL);
383 383 if ((error = mod_install(&modlinkage)) != 0) {
384 384 IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed");
385 385 mutex_destroy(&ibnex.ibnex_mutex);
386 386 cv_destroy(&ibnex.ibnex_reprobe_cv);
387 387 cv_destroy(&ibnex.ibnex_ioc_list_cv);
388 388 } else {
389 389 ibdm_ibnex_register_callback(ibnex_dm_callback);
390 390 ibtl_ibnex_register_callback(ibnex_ibtl_callback);
391 391 }
392 392 return (error);
393 393 }
394 394
395 395
396 396 /*
397 397 * _fini
398 398 * Prepares a module for unloading.
399 399 */
400 400 int
401 401 _fini(void)
402 402 {
403 403 int error;
404 404
405 405 IBTF_DPRINTF_L4("ibnex", "\t_fini");
406 406 if ((error = mod_remove(&modlinkage)) != 0) {
407 407 return (error);
408 408 }
409 409 ibdm_ibnex_unregister_callback();
410 410 ibtl_ibnex_unregister_callback();
411 411 mutex_destroy(&ibnex.ibnex_mutex);
412 412 cv_destroy(&ibnex.ibnex_reprobe_cv);
413 413 cv_destroy(&ibnex.ibnex_ioc_list_cv);
414 414 return (0);
415 415 }
416 416
417 417
418 418 /*
419 419 * _info
420 420 * Returns information about loadable module.
421 421 */
422 422 int
423 423 _info(struct modinfo *modinfop)
424 424 {
425 425 IBTF_DPRINTF_L4("ibnex", "\t_info");
426 426 return (mod_info(&modlinkage, modinfop));
427 427 }
428 428
429 429
430 430 /*
431 431 * ibnex_attach
432 432 * Configure and attach an instance of the IB Nexus driver
433 433 * Only one instance of IB Nexus is supported
434 434 * Create a minor node for cfgadm purpose
435 435 * Initialize communication services
436 436 * Register callback with IBDM
437 437 * Register callback with IBTL
438 438 */
439 439 static int
440 440 ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
441 441 {
442 442 int i;
443 443 int instance = ddi_get_instance(dip);
444 444
445 445 IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd);
446 446
447 447 switch (cmd) {
448 448 case DDI_ATTACH:
449 449 break;
450 450 case DDI_RESUME:
451 451 IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME");
452 452 return (DDI_SUCCESS);
453 453 default:
454 454 return (DDI_FAILURE);
455 455 }
456 456
457 457 /* Fail attach for more than one instance */
458 458 mutex_enter(&ibnex.ibnex_mutex);
459 459 if (ibnex.ibnex_dip != NULL) {
460 460 mutex_exit(&ibnex.ibnex_mutex);
461 461 return (DDI_FAILURE);
462 462 }
463 463 mutex_exit(&ibnex.ibnex_mutex);
464 464
465 465 /*
466 466 * Create a IB nexus taskq
467 467 */
468 468
469 469 ibnex.ibnex_taskq_id = ddi_taskq_create(dip,
470 470 "ibnex-enum-taskq", 1, TASKQ_DEFAULTPRI, 0);
471 471 if (ibnex.ibnex_taskq_id == NULL) {
472 472 IBTF_DPRINTF_L2("ibnex",
473 473 "\tattach: ddi_taskq_create() failed");
474 474 return (DDI_FAILURE);
475 475
476 476 }
477 477
478 478 /* Register with MPxIO framework */
479 479
480 480 if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0)
481 481 != MDI_SUCCESS) {
482 482 IBTF_DPRINTF_L2("ibnex",
483 483 "\tattach: mdi_vhci_register() failed");
484 484 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
485 485 ibnex.ibnex_taskq_id = NULL;
486 486 return (DDI_FAILURE);
487 487 }
488 488
489 489
490 490 /*
491 491 * Create the "fabric" devctl minor-node for IB DR support.
492 492 * The minor number for the "devctl" node is in the same format
493 493 * as the AP minor nodes.
494 494 */
495 495 if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance,
496 496 DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
497 497 IBTF_DPRINTF_L2("ibnex",
498 498 "\tattach: failed to create fabric minornode");
499 499 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
500 500 ibnex.ibnex_taskq_id = NULL;
501 501 (void) mdi_vhci_unregister(dip, 0);
502 502 return (DDI_FAILURE);
503 503 }
504 504
505 505 /*
506 506 * Create "devctl" minor node for general ioctl interface to the
507 507 * ib nexus.
508 508 */
509 509 if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance,
510 510 DDI_NT_IB_NEXUS, 0) != DDI_SUCCESS) {
511 511 IBTF_DPRINTF_L2("ibnex",
512 512 "\tattach: failed to create devctl minornode");
513 513 (void) ddi_remove_minor_node(dip, NULL);
514 514 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
515 515 ibnex.ibnex_taskq_id = NULL;
516 516 (void) mdi_vhci_unregister(dip, 0);
517 517 return (DDI_FAILURE);
518 518 }
519 519
520 520 /*
521 521 * Set pm-want-child-notification property for
522 522 * power management of the phci and client
523 523 */
524 524 if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
525 525 "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) {
526 526 IBTF_DPRINTF_L2("ibnex",
527 527 "_attach: create pm-want-child-notification failed");
528 528 (void) ddi_remove_minor_node(dip, NULL);
529 529 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
530 530 ibnex.ibnex_taskq_id = NULL;
531 531 (void) mdi_vhci_unregister(dip, 0);
532 532 return (DDI_FAILURE);
533 533 }
534 534
535 535 mutex_enter(&ibnex.ibnex_mutex);
536 536 ibnex.ibnex_dip = dip;
537 537 mutex_exit(&ibnex.ibnex_mutex);
538 538
539 539 /*
540 540 * Event Handling: Definition and Binding.
541 541 */
542 542 if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl,
543 543 NDI_SLEEP) != NDI_SUCCESS) {
544 544 IBTF_DPRINTF_L2("ibnex",
545 545 "_attach: ndi_event_alloc_hdl failed");
546 546 (void) ddi_remove_minor_node(dip, NULL);
547 547 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
548 548 ibnex.ibnex_taskq_id = NULL;
549 549 (void) mdi_vhci_unregister(dip, 0);
550 550 return (DDI_FAILURE);
551 551 }
552 552 if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events,
553 553 NDI_SLEEP) != NDI_SUCCESS) {
554 554 (void) ddi_remove_minor_node(dip, NULL);
555 555 (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl);
556 556 IBTF_DPRINTF_L2("ibnex",
557 557 "_attach: ndi_event_bind_set failed");
558 558 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
559 559 ibnex.ibnex_taskq_id = NULL;
560 560 (void) mdi_vhci_unregister(dip, 0);
561 561 return (DDI_FAILURE);
562 562 }
563 563
564 564 for (i = 0; i < N_IBNEX_PROPS; i++) {
565 565 if (ibnex_comm_svc_init(ibnex_properties[i].name,
566 566 ibnex_properties[i].type) != IBNEX_SUCCESS) {
567 567 ibnex_comm_svc_fini();
568 568 (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl,
569 569 &ib_ndi_events, NDI_SLEEP);
570 570 (void) ddi_remove_minor_node(dip, NULL);
571 571 (void) ndi_event_free_hdl(
572 572 ibnex.ibnex_ndi_event_hdl);
573 573 ibnex.ibnex_ndi_event_hdl = NULL;
574 574 IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init"
575 575 " failed %s", ibnex_properties[i].name);
576 576 (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
577 577 ibnex.ibnex_taskq_id = NULL;
578 578 (void) mdi_vhci_unregister(dip, 0);
579 579 return (DDI_FAILURE);
580 580 }
581 581 }
582 582
583 583 /*
584 584 * before anything else comes up:
585 585 * Initialize the internal list of pseudo device nodes by
586 586 * getting all pseudo children of "ib" and processing them.
587 587 */
588 588 ibnex_pseudo_initnodes();
589 589
590 590 return (DDI_SUCCESS);
591 591 }
592 592
593 593
594 594 /*
595 595 * ibnex_getinfo()
596 596 * Given the device number, return the devinfo pointer or the
597 597 * instance number.
598 598 * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
599 599 */
600 600
601 601 /*ARGSUSED*/
602 602 static int
603 603 ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
604 604 {
605 605 int ret = DDI_SUCCESS;
606 606
607 607 IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin");
608 608 switch (cmd) {
609 609 case DDI_INFO_DEVT2DEVINFO:
610 610 if (ibnex.ibnex_dip != NULL)
611 611 *result = ibnex.ibnex_dip;
612 612 else {
613 613 *result = NULL;
614 614 ret = DDI_FAILURE;
615 615 }
616 616 break;
617 617
618 618 case DDI_INFO_DEVT2INSTANCE:
619 619 *result = 0;
620 620 break;
621 621
622 622 default:
623 623 ret = DDI_FAILURE;
624 624 }
625 625 return (ret);
626 626 }
627 627
628 628
629 629 /*
630 630 * ibnex_detach
631 631 * Unregister callback with the IBDM
632 632 * Unregister callback with the IBTL
633 633 * Uninitialize the communication entries
634 634 * Remove all the minor nodes created by this instance
635 635 */
636 636 static int
637 637 ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
638 638 {
639 639
640 640 IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd);
641 641
642 642 switch (cmd) {
643 643
644 644 case DDI_DETACH:
645 645 break;
646 646 case DDI_SUSPEND:
647 647 IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend");
648 648 return (DDI_SUCCESS);
649 649 default:
650 650 return (DDI_FAILURE);
651 651 }
652 652
653 653 mutex_enter(&ibnex.ibnex_mutex);
654 654 if (ibt_hw_is_present()) {
655 655 IBTF_DPRINTF_L2("ibnex",
656 656 "\tdetach: IB HW is present ");
657 657 mutex_exit(&ibnex.ibnex_mutex);
658 658 return (DDI_FAILURE);
659 659 }
660 660 if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) {
661 661 IBTF_DPRINTF_L2("ibnex",
662 662 "\tdetach: ndi_event_free_hdl() failed");
663 663 mutex_exit(&ibnex.ibnex_mutex);
664 664 return (DDI_FAILURE);
665 665 }
666 666 ibnex.ibnex_ndi_event_hdl = NULL;
667 667 ibnex.ibnex_prop_update_evt_cookie = NULL;
668 668
669 669 ibnex_pseudo_node_cleanup();
670 670 ibnex_comm_svc_fini();
671 671 ibnex_ioc_node_cleanup();
672 672
673 673 (void) ddi_remove_minor_node(dip, NULL);
674 674 ibnex.ibnex_dip = NULL;
675 675 mutex_exit(&ibnex.ibnex_mutex);
676 676 (void) mdi_vhci_unregister(dip, 0);
677 677
678 678 if (ibnex.ibnex_taskq_id != NULL) {
679 679 ddi_taskq_destroy(ibnex.ibnex_taskq_id);
680 680 ibnex.ibnex_taskq_id = NULL;
681 681 }
682 682
683 683 return (DDI_SUCCESS);
684 684 }
685 685
686 686
687 687 /*
688 688 * ibnex_pseudo_node_cleanup()
689 689 * This checks if all the "dips" have been deallocated (implying
690 690 * that all the children have been unconfigured) first.
691 691 * If not, it just returns.
692 692 * If yes, then it frees up memory allocated for devi_name,
693 693 * node_addr, and property list.
694 694 */
695 695 static void
696 696 ibnex_pseudo_node_cleanup(void)
697 697 {
698 698 ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head;
699 699 ibnex_pseudo_node_t *pseudo;
700 700
701 701 IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:");
702 702 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
703 703
704 704 for (; nodep; nodep = nodep->node_next)
705 705 if (nodep->node_dip)
706 706 return;
707 707
708 708 IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory");
709 709 for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
710 710 nodep = nodep->node_next) {
711 711
712 712 pseudo = &nodep->node_data.pseudo_node;
713 713 if (pseudo->pseudo_node_addr) {
714 714 kmem_free(pseudo->pseudo_node_addr,
715 715 strlen(pseudo-> pseudo_node_addr) + 1);
716 716 pseudo->pseudo_node_addr = NULL;
717 717 }
718 718
719 719 if (pseudo->pseudo_devi_name) {
720 720 kmem_free(pseudo->pseudo_devi_name,
721 721 strlen(pseudo-> pseudo_devi_name) + 1);
722 722 pseudo->pseudo_devi_name = NULL;
723 723 }
724 724
725 725 if (pseudo->pseudo_unit_addr) {
726 726 kmem_free(pseudo->pseudo_unit_addr,
727 727 pseudo->pseudo_unit_addr_len);
728 728 }
729 729 }
730 730 }
731 731
732 732
733 733 /*
734 734 * This functions wakes up any reprobe requests waiting for completion
735 735 * of reprobe of this IOC. It also send an NDI event, if :
736 736 *
737 737 * notify_flag is set. This is set if :
738 738 * ibt_reprobe_ioc has returned with SUCCESS
739 739 * IBTF client has not been notified for this node.
740 740 * node_data->node_dip != NULL
741 741 * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set
742 742 * An NDI event cookie has been registered.
743 743 */
744 744 static void
745 745 ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag)
746 746 {
747 747 ddi_eventcookie_t evt_cookie;
748 748
749 749 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
750 750 evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
751 751
752 752 if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) ||
753 753 (node_data->node_reprobe_state != 0)) {
754 754 if (notify_flag && (node_data->node_dip != NULL) &&
755 755 (node_data->node_state &
756 756 IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) &&
757 757 (evt_cookie != NULL)) {
758 758 ibt_prop_update_payload_t evt_data;
759 759
760 760 mutex_exit(&ibnex.ibnex_mutex);
761 761
762 762 bzero(&evt_data, sizeof (evt_data));
763 763 if (ndi_post_event(ibnex.ibnex_dip,
764 764 node_data->node_dip,
765 765 evt_cookie, &evt_data) != NDI_SUCCESS)
766 766 IBTF_DPRINTF_L2("ibnex",
767 767 "\tndi_post_event failed\n");
768 768
769 769 mutex_enter(&ibnex.ibnex_mutex);
770 770 }
771 771
772 772 node_data->node_reprobe_state = 0;
773 773 cv_broadcast(&ibnex.ibnex_reprobe_cv);
774 774 }
775 775 node_data->node_reprobe_state = 0;
776 776 }
777 777
778 778 /*
779 779 * This function wakes up any reprobe request waiting for completion
780 780 * of reprobe of all IOCs.
781 781 */
782 782 static void
783 783 ibnex_wakeup_reprobe_all()
784 784 {
785 785 ibnex_node_data_t *ioc_node;
786 786
787 787 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
788 788
789 789 /* Notify if another reprobe_all is pending */
790 790 if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) {
791 791 ibnex.ibnex_reprobe_state = 0;
792 792 cv_broadcast(&ibnex.ibnex_reprobe_cv);
793 793 }
794 794 ibnex.ibnex_reprobe_state = 0;
795 795
796 796 /*
797 797 * The IOC may be hot-removed after the reprobe request.
798 798 * Reset the reprobe states for such IOCs.
799 799 */
800 800 for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node;
801 801 ioc_node = ioc_node->node_next) {
802 802 if (ioc_node->node_reprobe_state != 0) {
803 803 ibnex_wakeup_reprobe_ioc(ioc_node, 1);
804 804 }
805 805 }
806 806 }
807 807
808 808 /*
809 809 * ibnex_ibnex_callback:
810 810 * IBTL_IBNEX_IBC_INIT:
811 811 * Called from ibc_init() which is called from
812 812 * HCA driver _init entry point
813 813 * Initializes the HCA dev_ops structure with default
814 814 * IB nexus structure.
815 815 * IBTL_IBNEX_IBC_FINI:
816 816 * Called from ibc_fini() which is called from
817 817 * HCA driver _fini entry point
818 818 * Un-Initializes the HCA dev_ops structure with default
819 819 * IB nexus strucuture.
820 820 * Returns IBT_SUCCESS
821 821 */
822 822 ibt_status_t
823 823 ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args)
824 824 {
825 825 int retval = IBT_SUCCESS;
826 826 struct dev_ops *hca_dev_ops;
827 827 dev_info_t *clnt_dip;
828 828 ibnex_node_data_t *node_data;
829 829
830 830 IBTF_DPRINTF_L5("ibnex", "\tibtl_callback");
831 831
832 832 switch (cb_args->cb_flag) {
833 833 case IBTL_IBNEX_IBC_INIT:
834 834 /*
835 835 * Get the devops structure of the HCA,
836 836 * and put IB nexus default busops vector in its place.
837 837 */
838 838 hca_dev_ops = ((struct modldrv *)
839 839 (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
840 840 ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL));
841 841 hca_dev_ops->devo_bus_ops = &ibnex_ci_busops;
842 842 break;
843 843
844 844 case IBTL_IBNEX_IBC_FINI:
845 845 hca_dev_ops = ((struct modldrv *)
846 846 (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
847 847 hca_dev_ops->devo_bus_ops = NULL;
848 848 break;
849 849
850 850 case IBTL_IBNEX_REPROBE_DEV_REQ:
851 851 /* IBTL pass down request for ibt_reprobe_dev */
852 852 clnt_dip = cb_args->cb_dip;
853 853 ASSERT(clnt_dip);
854 854
855 855 node_data = ddi_get_parent_data(clnt_dip);
856 856 ASSERT(node_data);
857 857
858 858 /* Reprobe for IOC nodes only */
859 859 ASSERT(node_data->node_type == IBNEX_IOC_NODE);
860 860
861 861 /*
862 862 * Start the reprobe. This could sleep as it is not
863 863 * from interrupt context.
864 864 */
865 865 if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev,
866 866 clnt_dip, TQ_SLEEP) == 0) {
867 867 IBTF_DPRINTF_L2("ibnex",
868 868 "ibnex_ibtl_callback: taskq_dispatch failed");
869 869 mutex_enter(&ibnex.ibnex_mutex);
870 870 ibnex_wakeup_reprobe_ioc(node_data, 0);
871 871 mutex_exit(&ibnex.ibnex_mutex);
872 872 return (IBT_INSUFF_KERNEL_RESOURCE);
873 873 }
874 874 return (IBT_SUCCESS);
875 875 }
876 876
877 877 return (retval);
878 878 }
879 879
880 880
881 881 /*
882 882 * Bus-ops entry points
883 883 */
884 884
885 885 /*
886 886 * ibnex_map_fault
887 887 * IOC drivers need not map memory. Return failure to fail any
888 888 * such calls.
889 889 */
890 890 /*ARGSUSED*/
891 891 int
892 892 ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat,
893 893 struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn,
894 894 uint_t prot, uint_t lock)
895 895 {
896 896 return (DDI_FAILURE);
897 897 }
898 898
899 899
900 900 /*
901 901 * ibnex_busctl
902 902 * bus_ctl bus_ops entry point
903 903 */
904 904 /*ARGSUSED*/
905 905 int
906 906 ibnex_busctl(dev_info_t *dip, dev_info_t *rdip,
907 907 ddi_ctl_enum_t ctlop, void *arg, void *result)
908 908 {
909 909 dev_info_t *child_dip;
910 910
911 911 IBTF_DPRINTF_L4("ibnex",
912 912 "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop);
913 913 IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result);
914 914
915 915 switch (ctlop) {
916 916 case DDI_CTLOPS_REPORTDEV:
917 917 if (rdip == NULL) {
918 918 return (DDI_FAILURE);
919 919 }
920 920
921 921 /* Log the relevant details of dip to sysbuf */
922 922 cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n",
923 923 ddi_node_name(rdip), ddi_get_name_addr(rdip),
924 924 ddi_driver_name(rdip), ddi_get_instance(rdip));
925 925
926 926 return (DDI_SUCCESS);
927 927
928 928 case DDI_CTLOPS_INITCHILD:
929 929 child_dip = (dev_info_t *)arg;
930 930 return (ibnex_init_child(child_dip));
931 931
932 932 case DDI_CTLOPS_UNINITCHILD:
933 933 child_dip = (dev_info_t *)arg;
934 934 ddi_set_name_addr(child_dip, NULL);
935 935 return (DDI_SUCCESS);
936 936
937 937 case DDI_CTLOPS_ATTACH:
938 938 case DDI_CTLOPS_DETACH:
939 939 case DDI_CTLOPS_POWER :
940 940 return (DDI_SUCCESS);
941 941
942 942 case DDI_CTLOPS_SIDDEV:
943 943 /*
944 944 * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and
945 945 * DDI_FAILURE for the nodes enumerated by a Pseudo file.
946 946 */
947 947 return (ndi_dev_is_persistent_node(rdip) ?
948 948 DDI_SUCCESS : DDI_FAILURE);
949 949
950 950
951 951 case DDI_CTLOPS_IOMIN:
952 952 /*
953 953 * Return DDI_SUCCESS, so that consistent buf alloc
954 954 * gets the default DMA IO minimum for the platform
955 955 */
956 956 return (DDI_SUCCESS);
957 957
958 958 /*
959 959 * These ops correspond to functions that "shouldn't" be
960 960 * called by IB Nexus driver.
961 961 */
962 962 case DDI_CTLOPS_DMAPMAPC:
963 963 case DDI_CTLOPS_REPORTINT:
964 964 case DDI_CTLOPS_REGSIZE:
965 965 case DDI_CTLOPS_NREGS:
966 966 case DDI_CTLOPS_SLAVEONLY:
967 967 case DDI_CTLOPS_AFFINITY:
968 968 case DDI_CTLOPS_POKE:
969 969 case DDI_CTLOPS_PEEK:
970 970 IBTF_DPRINTF_L2("ibnex",
971 971 "%s%d: invalid op (%d) from %s inst%d",
972 972 ddi_get_name(dip), ddi_get_instance(dip),
973 973 ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
974 974 return (DDI_FAILURE);
975 975
976 976 /*
977 977 * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we
978 978 * pass up
979 979 */
980 980 default:
981 981 return (ddi_ctlops(dip, rdip, ctlop, arg, result));
982 982 }
983 983 }
984 984
985 985
986 986 /*
987 987 * ibnex_init_child()
988 988 *
989 989 * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD
990 990 * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED.
991 991 */
992 992 static int
993 993 ibnex_init_child(dev_info_t *child)
994 994 {
995 995 int ret;
996 996 char name[MAXNAMELEN];
997 997
998 998 IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child);
999 999
1000 1000 /* Handle Pseudo nodes of client children */
1001 1001 if (ndi_dev_is_persistent_node(child) == 0) {
1002 1002 /* Skip nodes without ib-node-type="merge" */
1003 1003 if (ibnex_is_merge_node(child) != IBNEX_SUCCESS)
1004 1004 return (DDI_FAILURE);
1005 1005
1006 1006 if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS)
1007 1007 return (DDI_FAILURE);
1008 1008
1009 1009 ddi_set_name_addr(child, name);
1010 1010 /*
1011 1011 * Merge the .conf node
1012 1012 */
1013 1013 if (ndi_merge_node(child,
1014 1014 ibnex_name_child) == DDI_SUCCESS) {
1015 1015 ddi_set_name_addr(child, NULL);
1016 1016 return (DDI_FAILURE);
1017 1017 }
1018 1018 return (DDI_NOT_WELL_FORMED);
1019 1019
1020 1020 }
1021 1021
1022 1022 if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS)
1023 1023 return (ret);
1024 1024
1025 1025 ddi_set_name_addr(child, name);
1026 1026
1027 1027 return (DDI_SUCCESS);
1028 1028 }
1029 1029
1030 1030
1031 1031 int
1032 1032 ibnex_name_pseudo_child(dev_info_t *child, char *name)
1033 1033 {
1034 1034 char **unit_addr;
1035 1035 uint_t n;
1036 1036 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
1037 1037 DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
1038 1038 DDI_PROP_SUCCESS) {
1039 1039 IBTF_DPRINTF_L4("ibnex",
1040 1040 "\tname_pseudo_child: cannot find unit-address in %s.conf",
1041 1041 ddi_get_name(child));
1042 1042 return (DDI_FAILURE);
1043 1043 }
1044 1044 if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
1045 1045 cmn_err(CE_WARN, "unit-address property in %s.conf"
1046 1046 " not well-formed", ddi_get_name(child));
1047 1047 ddi_prop_free(unit_addr);
1048 1048 return (DDI_FAILURE);
1049 1049 }
1050 1050 (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr);
1051 1051 ddi_prop_free(unit_addr);
1052 1052 return (DDI_SUCCESS);
1053 1053 }
1054 1054
1055 1055
1056 1056 /*ARGSUSED*/
1057 1057 int
1058 1058 ibnex_name_child(dev_info_t *child, char *name, int flag)
1059 1059 {
1060 1060 ibnex_pseudo_node_t *pseudo;
1061 1061 ibnex_node_data_t *node_datap;
1062 1062 ibnex_port_node_t *port_node;
1063 1063 ibnex_ioc_node_t *ioc;
1064 1064
1065 1065 node_datap = ddi_get_parent_data(child);
1066 1066 if (node_datap == NULL) {
1067 1067 IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL");
1068 1068 return (DDI_NOT_WELL_FORMED);
1069 1069 }
1070 1070 IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p"
1071 1071 "Node type %x", node_datap, node_datap->node_type);
1072 1072 switch (node_datap->node_type) {
1073 1073 case IBNEX_PORT_COMMSVC_NODE:
1074 1074 port_node = &node_datap->node_data.port_node;
1075 1075 (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
1076 1076 port_node->port_num,
1077 1077 ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]);
1078 1078 break;
1079 1079 case IBNEX_VPPA_COMMSVC_NODE:
1080 1080 port_node = &node_datap->node_data.port_node;
1081 1081 (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s",
1082 1082 port_node->port_num, port_node->port_pkey, ibnex.
1083 1083 ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]);
1084 1084 break;
1085 1085 case IBNEX_HCASVC_COMMSVC_NODE:
1086 1086 port_node = &node_datap->node_data.port_node;
1087 1087 (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
1088 1088 port_node->port_num,
1089 1089 ibnex.ibnex_hcasvc_comm_svc_names[port_node->
1090 1090 port_commsvc_idx]);
1091 1091 break;
1092 1092 case IBNEX_IOC_NODE:
1093 1093 ioc = &node_datap->node_data.ioc_node;
1094 1094 (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX",
1095 1095 (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid);
1096 1096 break;
1097 1097 case IBNEX_PSEUDO_NODE:
1098 1098 pseudo = &node_datap->node_data.pseudo_node;
1099 1099 (void) snprintf(name,
1100 1100 IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr);
1101 1101 break;
1102 1102 default:
1103 1103 IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed");
1104 1104 return (DDI_NOT_WELL_FORMED);
1105 1105 }
1106 1106
1107 1107 return (DDI_SUCCESS);
1108 1108 }
1109 1109
1110 1110
1111 1111 /*
1112 1112 * ibnex_bus_config()
1113 1113 *
1114 1114 * BUS_CONFIG_ONE:
1115 1115 * Enumerate the exact instance of the driver. Use the device node name
1116 1116 * to locate the exact instance.
1117 1117 * Query IBDM to find whether the hardware exits for the instance of the
1118 1118 * driver. If exists, create a device node and return NDI_SUCCESS.
1119 1119 *
1120 1120 * BUS_CONFIG_ALL:
1121 1121 * Enumerate all the instances of all the possible children (seen before
1122 1122 * and never seen before).
1123 1123 *
1124 1124 * BUS_CONFIG_DRIVER:
1125 1125 * Enumerate all the instances of a particular driver.
1126 1126 */
1127 1127
1128 1128 static int
1129 1129 ibnex_bus_config(dev_info_t *parent, uint_t flag,
1130 1130 ddi_bus_config_op_t op, void *devname, dev_info_t **child)
1131 1131 {
1132 1132 int ret = IBNEX_SUCCESS, len, circ, need_bus_config;
1133 1133 char *device_name, *cname = NULL, *caddr = NULL;
1134 1134 dev_info_t *cdip;
1135 1135 ibnex_node_data_t *node_data;
1136 1136
1137 1137 switch (op) {
1138 1138 case BUS_CONFIG_ONE:
1139 1139 IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, "
1140 1140 "parent %p", parent);
1141 1141
1142 1142 ndi_devi_enter(parent, &circ);
1143 1143
1144 1144 len = strlen((char *)devname) + 1;
1145 1145 device_name = i_ddi_strdup(devname, KM_SLEEP);
1146 1146 i_ddi_parse_name(device_name, &cname, &caddr, NULL);
1147 1147
1148 1148 if (caddr == NULL || (strlen(caddr) == 0)) {
1149 1149 kmem_free(device_name, len);
1150 1150 ndi_devi_exit(parent, circ);
1151 1151 return (NDI_FAILURE);
1152 1152 }
1153 1153
1154 1154 cdip = ndi_devi_findchild(parent, devname);
1155 1155 if (cdip)
1156 1156 node_data = ddi_get_parent_data(cdip);
1157 1157
1158 1158 ndi_devi_exit(parent, circ);
1159 1159
1160 1160 if (cdip == NULL || (node_data != NULL &&
1161 1161 node_data->node_dip == NULL)) {
1162 1162 /* Node is not present */
1163 1163 if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) {
1164 1164 ret = ibnex_ioc_bus_config_one(&parent, flag,
1165 1165 op, devname, child, &need_bus_config);
1166 1166 if (!need_bus_config) {
1167 1167 kmem_free(device_name, len);
1168 1168 return (ret);
1169 1169 }
1170 1170 } else {
1171 1171 /*
1172 1172 * if IB Nexus is the parent, call MDI. Bus
1173 1173 * config with HCA as the parent would have
1174 1174 * enumerated the Pseudo node.
1175 1175 */
1176 1176 ret = IBNEX_SUCCESS;
1177 1177 ibnex_pseudo_initnodes();
1178 1178 mutex_enter(&ibnex.ibnex_mutex);
1179 1179 ret = ibnex_pseudo_mdi_config_one(flag, devname,
1180 1180 child, cname, caddr);
1181 1181 mutex_exit(&ibnex.ibnex_mutex);
1182 1182 kmem_free(device_name, len);
1183 1183 return (ret);
1184 1184 }
1185 1185 }
1186 1186 kmem_free(device_name, len);
1187 1187 break;
1188 1188
1189 1189 case BUS_CONFIG_ALL:
1190 1190 /*FALLTHRU*/
1191 1191 case BUS_CONFIG_DRIVER:
1192 1192 if (op == BUS_CONFIG_ALL)
1193 1193 IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, "
1194 1194 "parent %p", parent);
1195 1195 else
1196 1196 IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER"
1197 1197 ", parent %p", parent);
1198 1198
1199 1199 /*
1200 1200 * Drive CONFIG requests for IB Nexus parent through
1201 1201 * MDI. This is needed to load the HCA drivers in x86 SRP
1202 1202 * boot case.
1203 1203 *
1204 1204 * CONFIG Requests with HCA parent will probe devices using
1205 1205 * ibdm and configure all children.
1206 1206 */
1207 1207 ibdm_ioc_info_t *ioc_list, *new_ioc_list;
1208 1208
1209 1209 mutex_enter(&ibnex.ibnex_mutex);
1210 1210 while (ibnex.ibnex_ioc_list_state !=
1211 1211 IBNEX_IOC_LIST_READY) {
1212 1212 cv_wait(&ibnex.ibnex_ioc_list_cv,
1213 1213 &ibnex.ibnex_mutex);
1214 1214 }
1215 1215 ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW;
1216 1216 mutex_exit(&ibnex.ibnex_mutex);
1217 1217 /* Enumerate all the IOC's */
1218 1218 ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
1219 1219
1220 1220 new_ioc_list = ibdm_ibnex_get_ioc_list(
1221 1221 IBDM_IBNEX_NORMAL_PROBE);
1222 1222 IBTF_DPRINTF_L4("ibnex",
1223 1223 "\tbus_config: alloc ioc_list %p", new_ioc_list);
1224 1224 /*
1225 1225 * Optimize the calls for each BUS_CONFIG_ALL request
1226 1226 * to the IB Nexus dip. This is currently done for
1227 1227 * each PDIP.
1228 1228 */
1229 1229 mutex_enter(&ibnex.ibnex_mutex);
1230 1230 ioc_list = ibnex.ibnex_ioc_list;
1231 1231 ibnex.ibnex_ioc_list = new_ioc_list;
1232 1232 ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
1233 1233 cv_broadcast(&ibnex.ibnex_ioc_list_cv);
1234 1234 mutex_exit(&ibnex.ibnex_mutex);
1235 1235
1236 1236 if (ioc_list) {
1237 1237 IBTF_DPRINTF_L4("ibnex",
1238 1238 "\tbus_config: freeing ioc_list %p",
1239 1239 ioc_list);
1240 1240 ibdm_ibnex_free_ioc_list(ioc_list);
1241 1241 }
1242 1242
1243 1243
1244 1244 ret = mdi_vhci_bus_config(parent,
1245 1245 flag, op, devname, child, NULL);
1246 1246 return (ret);
1247 1247 default:
1248 1248 IBTF_DPRINTF_L4("ibnex", "\tbus_config: error");
1249 1249 ret = IBNEX_FAILURE;
1250 1250 break;
1251 1251 }
1252 1252
1253 1253 if (ret == IBNEX_SUCCESS) {
1254 1254 ret = ndi_busop_bus_config(
1255 1255 parent, flag, op, devname, child, 0);
1256 1256 IBTF_DPRINTF_L4("ibnex", "\tbus_config:"
1257 1257 "ndi_busop_bus_config : retval %d", ret);
1258 1258 return (ret);
1259 1259 }
1260 1260
1261 1261 return (NDI_FAILURE);
1262 1262 }
1263 1263
1264 1264
1265 1265 /*
1266 1266 * ibnex_config_root_iocnode()
1267 1267 * Configures one particular instance of the IOC driver.
1268 1268 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
1269 1269 */
1270 1270 static int
1271 1271 ibnex_config_root_iocnode(dev_info_t *parent, char *device_name)
1272 1272 {
1273 1273 int ret, port = 0, iter = 0;
1274 1274 boolean_t displayed = B_FALSE;
1275 1275 char *portstr;
1276 1276 ib_guid_t hca_guid, iou_guid, ioc_guid;
1277 1277 ibdm_ioc_info_t *ioc_info;
1278 1278 ibdm_port_attr_t *port_attr;
1279 1279
1280 1280 IBTF_DPRINTF_L4("ibnex",
1281 1281 "\tconfig_root_iocnode: name %s", device_name);
1282 1282
1283 1283 portstr = strstr(device_name, ":port=");
1284 1284 if (portstr == NULL) {
1285 1285 return (IBNEX_FAILURE);
1286 1286 }
1287 1287
1288 1288 portstr[0] = 0; portstr++;
1289 1289 if (ibnex_devname2port(portstr, &port)) {
1290 1290 IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port");
1291 1291 return (IBNEX_FAILURE);
1292 1292 }
1293 1293
1294 1294 if (ibnex_devname_to_node_n_ioc_guids(
1295 1295 device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
1296 1296 return (IBNEX_FAILURE);
1297 1297 }
1298 1298
1299 1299 (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4),
1300 1300 "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid);
1301 1301
1302 1302 hca_guid = ibtl_ibnex_hcadip2guid(parent);
1303 1303 if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) {
1304 1304 IBTF_DPRINTF_L2("ibnex",
1305 1305 "\tconfig_root_iocnode: Port does not exist");
1306 1306 return (IBNEX_FAILURE);
1307 1307 }
1308 1308
1309 1309 /* Wait until "port is up" */
1310 1310 while (port_attr->pa_state != IBT_PORT_ACTIVE) {
1311 1311 ibdm_ibnex_free_port_attr(port_attr);
1312 1312 delay(drv_usectohz(10000));
1313 1313 if ((port_attr = ibdm_ibnex_probe_hcaport(
1314 1314 hca_guid, port)) == NULL) {
1315 1315 return (IBNEX_FAILURE);
1316 1316 }
1317 1317
1318 1318 if (iter++ == 400) {
1319 1319 if (displayed == B_FALSE) {
1320 1320 cmn_err(CE_NOTE, "\tWaiting for Port %d "
1321 1321 "initialization", port_attr->pa_port_num);
1322 1322 displayed = B_TRUE;
1323 1323 }
1324 1324 }
1325 1325 }
1326 1326 ibdm_ibnex_free_port_attr(port_attr);
1327 1327 IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:"
1328 1328 "Port is initialized");
1329 1329
1330 1330 if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) {
1331 1331 ibdm_ibnex_free_ioc_list(ioc_info);
1332 1332 return (IBNEX_FAILURE);
1333 1333 }
1334 1334 mutex_enter(&ibnex.ibnex_mutex);
1335 1335 if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) !=
1336 1336 IBNEX_SUCCESS) {
1337 1337 IBTF_DPRINTF_L2("ibnex",
1338 1338 "\tconfig_root_ioc_node failed for pdip %p", parent);
1339 1339 }
1340 1340 mutex_exit(&ibnex.ibnex_mutex);
1341 1341 ibdm_ibnex_free_ioc_list(ioc_info);
1342 1342 return (ret);
1343 1343 }
1344 1344
1345 1345
1346 1346 static int
1347 1347 ibnex_devname2port(char *portstr, int *port)
1348 1348 {
1349 1349 char *temp;
1350 1350 int ret = IBNEX_FAILURE;
1351 1351
1352 1352 IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin");
1353 1353
1354 1354 temp = strchr(portstr, '=');
1355 1355 if (temp != NULL) {
1356 1356 temp++;
1357 1357 *port = ibnex_str2int(temp, strlen(temp), &ret);
1358 1358 }
1359 1359 return (ret);
1360 1360 }
1361 1361
1362 1362
1363 1363 /*
1364 1364 * ibnex_config_all_children()
1365 1365 * Wait for lata SM initialization case before enumerating the nodes
1366 1366 * Get list of HCA's and HCA port information
1367 1367 * Create device device nodes and its node properties
1368 1368 * for port nodes and VPPA nodes
1369 1369 * Get list of all the IOC node information
1370 1370 * Create device nodes and its properties for all the IOCs
1371 1371 * if not created already
1372 1372 * Bind drivers for all the newly created device nodes
1373 1373 * Support Pseudo nodes enumerated using their .conf file
1374 1374 */
1375 1375 void
1376 1376 ibnex_config_all_children(dev_info_t *parent)
1377 1377 {
1378 1378 int ii;
1379 1379 ibdm_ioc_info_t *ioc_list;
1380 1380 ibdm_hca_list_t *hca_list;
1381 1381 ib_guid_t hca_guid;
1382 1382 int circ;
1383 1383
1384 1384 IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin");
1385 1385
1386 1386
1387 1387 /*
1388 1388 * Enumerate children of this HCA, port nodes,
1389 1389 * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for
1390 1390 * locking. IB Nexus is enumerating the children
1391 1391 * of HCA, not MPXIO clients.
1392 1392 */
1393 1393 ndi_devi_enter(parent, &circ);
1394 1394 hca_guid = ibtl_ibnex_hcadip2guid(parent);
1395 1395 ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time);
1396 1396 hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
1397 1397 if (hca_list == NULL) {
1398 1398 ndi_devi_exit(parent, circ);
1399 1399 return;
1400 1400 }
1401 1401 ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr);
1402 1402 for (ii = 0; ii < hca_list->hl_nports; ii++) {
1403 1403 ibnex_create_port_nodes(
1404 1404 parent, &hca_list->hl_port_attr[ii]);
1405 1405 ibnex_create_vppa_nodes(parent, &hca_list->hl_port_attr[ii]);
1406 1406 }
1407 1407 ibdm_ibnex_free_hca_list(hca_list);
1408 1408 ndi_devi_exit(parent, circ);
1409 1409
1410 1410 /*
1411 1411 * Use mdi_devi_enter() for locking. IB Nexus is
1412 1412 * enumerating MPxIO clients.
1413 1413 */
1414 1414 mdi_devi_enter(parent, &circ);
1415 1415
1416 1416 ibnex_pseudo_initnodes();
1417 1417
1418 1418 mutex_enter(&ibnex.ibnex_mutex);
1419 1419 while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) {
1420 1420 cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex);
1421 1421 }
1422 1422 ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS;
1423 1423 ioc_list = ibnex.ibnex_ioc_list;
1424 1424 while (ioc_list) {
1425 1425 (void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0);
1426 1426 ioc_list = ioc_list->ioc_next;
1427 1427 }
1428 1428 ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
1429 1429 cv_broadcast(&ibnex.ibnex_ioc_list_cv);
1430 1430
1431 1431 /* Config IBTF Pseudo clients */
1432 1432 ibnex_config_pseudo_all(parent);
1433 1433
1434 1434 mutex_exit(&ibnex.ibnex_mutex);
1435 1435 mdi_devi_exit(parent, circ);
1436 1436
1437 1437 IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End");
1438 1438 }
1439 1439
1440 1440
1441 1441 /*
1442 1442 * ibnex_create_port_nodes:
1443 1443 * Creates a device node per each communication service defined
1444 1444 * in the "port-commsvc-list" property per HCA port
1445 1445 */
1446 1446 void
1447 1447 ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
1448 1448 {
1449 1449 int idx;
1450 1450 dev_info_t *dip;
1451 1451 int rval;
1452 1452
1453 1453 mutex_enter(&ibnex.ibnex_mutex);
1454 1454 for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) {
1455 1455 rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
1456 1456 idx, 0, &dip);
1457 1457 if (rval != IBNEX_SUCCESS || dip == NULL) {
1458 1458 (void) ibnex_commsvc_initnode(parent, port_attr, idx,
1459 1459 IBNEX_PORT_COMMSVC_NODE, 0, &rval,
1460 1460 IBNEX_DEVFS_ENUMERATE);
1461 1461 }
1462 1462 }
1463 1463 mutex_exit(&ibnex.ibnex_mutex);
1464 1464 }
1465 1465
1466 1466
1467 1467 /*
1468 1468 * ibnex_create_vppa_nodes:
1469 1469 * Creates a device node per each communication service defined
1470 1470 * in the "vppa-commsvc-list" property and per each PKEY that
1471 1471 * this particular port supports and per HCA port
1472 1472 */
1473 1473 void
1474 1474 ibnex_create_vppa_nodes(
1475 1475 dev_info_t *parent, ibdm_port_attr_t *port_attr)
1476 1476 {
1477 1477 int idx, ii;
1478 1478 int rval;
1479 1479 ib_pkey_t pkey;
1480 1480 dev_info_t *dip;
1481 1481
1482 1482 IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin");
1483 1483
1484 1484 mutex_enter(&ibnex.ibnex_mutex);
1485 1485 if (port_attr->pa_state != IBT_PORT_ACTIVE) {
1486 1486 IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: "
1487 1487 "Port %d is down", port_attr->pa_port_num);
1488 1488 mutex_exit(&ibnex.ibnex_mutex);
1489 1489 return;
1490 1490 }
1491 1491 for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) {
1492 1492 if (strcmp("ipib", ibnex.ibnex_vppa_comm_svc_names[idx]) == 0) {
1493 1493 IBTF_DPRINTF_L2("ibnex", "Skipping IBD devices...");
1494 1494 continue;
1495 1495 }
1496 1496 for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
1497 1497 pkey = port_attr->pa_pkey_tbl[ii].pt_pkey;
1498 1498
1499 1499 if (IBNEX_INVALID_PKEY(pkey)) {
1500 1500 continue;
1501 1501 }
1502 1502 rval = ibnex_get_dip_from_guid(
1503 1503 port_attr->pa_port_guid, idx, pkey, &dip);
1504 1504 if ((rval != IBNEX_SUCCESS) || (dip == NULL)) {
1505 1505 (void) ibnex_commsvc_initnode(parent, port_attr,
1506 1506 idx, IBNEX_VPPA_COMMSVC_NODE,
1507 1507 pkey, &rval, IBNEX_CFGADM_ENUMERATE);
1508 1508 }
1509 1509 }
1510 1510 }
1511 1511 mutex_exit(&ibnex.ibnex_mutex);
1512 1512 }
1513 1513
1514 1514
1515 1515 /*
1516 1516 * ibnex_create_hcasvc_nodes:
1517 1517 * Creates a device node per each communication service defined
1518 1518 * in the "port-commsvc-list" property per HCA port
1519 1519 */
1520 1520 void
1521 1521 ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
1522 1522 {
1523 1523 int idx;
1524 1524 dev_info_t *dip;
1525 1525 int rval;
1526 1526
1527 1527 mutex_enter(&ibnex.ibnex_mutex);
1528 1528 for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) {
1529 1529 rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
1530 1530 idx, 0, &dip);
1531 1531 if (rval != IBNEX_SUCCESS || dip == NULL) {
1532 1532 (void) ibnex_commsvc_initnode(parent, port_attr, idx,
1533 1533 IBNEX_HCASVC_COMMSVC_NODE, 0, &rval,
1534 1534 IBNEX_DEVFS_ENUMERATE);
1535 1535 IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: "
1536 1536 "commsvc_initnode failed, rval %x", rval);
1537 1537 }
1538 1538 }
1539 1539 mutex_exit(&ibnex.ibnex_mutex);
1540 1540 }
1541 1541
1542 1542
1543 1543 /*
1544 1544 * ibnex_bus_unconfig()
1545 1545 *
1546 1546 * Unconfigure a particular device node or all instance of a device
1547 1547 * driver device or all children of IBnex
1548 1548 */
1549 1549 static int
1550 1550 ibnex_bus_unconfig(dev_info_t *parent,
1551 1551 uint_t flag, ddi_bus_config_op_t op, void *device_name)
1552 1552 {
1553 1553 ibnex_node_data_t *ndp;
1554 1554 major_t major = (major_t)(uintptr_t)device_name;
1555 1555 dev_info_t *dip = NULL;
1556 1556
1557 1557 if (ndi_busop_bus_unconfig(parent, flag, op, device_name) !=
1558 1558 DDI_SUCCESS)
1559 1559 return (DDI_FAILURE);
1560 1560
1561 1561 if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) &&
1562 1562 (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) {
1563 1563 mutex_enter(&ibnex.ibnex_mutex);
1564 1564 /*
1565 1565 * IB dip. here we handle IOC and pseudo nodes which
1566 1566 * are the children of IB nexus. Cleanup only the nodes
1567 1567 * with matching major number. We also need to cleanup
1568 1568 * the PathInfo links to the PHCI here.
1569 1569 */
1570 1570 for (ndp = ibnex.ibnex_ioc_node_head;
1571 1571 ndp; ndp = ndp->node_next) {
1572 1572 dip = ndp->node_dip;
1573 1573 if (dip && (ddi_driver_major(dip) == major)) {
1574 1574 (void) ibnex_offline_childdip(dip);
1575 1575 }
1576 1576 }
1577 1577 for (ndp = ibnex.ibnex_pseudo_node_head;
1578 1578 ndp; ndp = ndp->node_next) {
1579 1579 dip = ndp->node_dip;
1580 1580 if (dip && (ddi_driver_major(dip) == major)) {
1581 1581 (void) ibnex_offline_childdip(dip);
1582 1582 }
1583 1583 }
1584 1584 mutex_exit(&ibnex.ibnex_mutex);
1585 1585 }
1586 1586 return (DDI_SUCCESS);
1587 1587 }
1588 1588
1589 1589
1590 1590 /*
1591 1591 * ibnex_config_port_node()
1592 1592 *
1593 1593 * Configures a particular port / HCA node for a particular
1594 1594 * communication service.
1595 1595 * The format of the device_name is
1596 1596 * ibport@<Port#>,<pkey>,<service name>
1597 1597 * where pkey = 0 for port communication service nodes
1598 1598 * Port# = 0 for HCA_SVC communication service nodes
1599 1599 * Returns "dev_info_t" of the "child" node just created
1600 1600 * NULL when failed to enumerate the child node
1601 1601 */
1602 1602 dev_info_t *
1603 1603 ibnex_config_port_node(dev_info_t *parent, char *devname)
1604 1604 {
1605 1605 int ii, index;
1606 1606 int rval;
1607 1607 uint8_t port_num;
1608 1608 ib_guid_t hca_guid, port_guid;
1609 1609 ib_pkey_t pkey;
1610 1610 dev_info_t *cdip;
1611 1611 ibdm_port_attr_t *port_attr;
1612 1612 ibdm_hca_list_t *hca_list;
1613 1613
1614 1614 IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname);
1615 1615
1616 1616 if (ibnex_get_pkey_commsvc_index_portnum(devname,
1617 1617 &index, &pkey, &port_num) != IBNEX_SUCCESS) {
1618 1618 IBTF_DPRINTF_L2("ibnex",
1619 1619 "\tconfig_port_node: Invalid Service Name");
1620 1620 return (NULL);
1621 1621 }
1622 1622
1623 1623 hca_guid = ibtl_ibnex_hcadip2guid(parent);
1624 1624 if (port_num == 0) {
1625 1625 /*
1626 1626 * Use the dummy port attribute for HCA node in hca_list
1627 1627 * Note : pa_state is always IBT_PORT_ACTIVE.
1628 1628 */
1629 1629 hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
1630 1630 ASSERT(hca_list != NULL);
1631 1631 port_attr = hca_list->hl_hca_port_attr;
1632 1632 } else {
1633 1633 if ((port_attr = ibdm_ibnex_probe_hcaport(
1634 1634 hca_guid, port_num)) == NULL) {
1635 1635 IBTF_DPRINTF_L2("ibnex",
1636 1636 "\tconfig_port_node: Port does not exist");
1637 1637 return (NULL);
1638 1638 }
1639 1639
1640 1640 if (port_attr->pa_state != IBT_PORT_ACTIVE) {
1641 1641 ibdm_ibnex_port_settle_wait(
1642 1642 hca_guid, ibnex_port_settling_time);
1643 1643 ibdm_ibnex_free_port_attr(port_attr);
1644 1644 if ((port_attr = ibdm_ibnex_probe_hcaport(
1645 1645 hca_guid, port_num)) == NULL) {
1646 1646 return (NULL);
1647 1647 }
1648 1648 }
1649 1649 }
1650 1650
1651 1651 port_guid = port_attr->pa_port_guid;
1652 1652 mutex_enter(&ibnex.ibnex_mutex);
1653 1653 rval = ibnex_get_dip_from_guid(port_guid, index, pkey, &cdip);
1654 1654 if ((rval == IBNEX_SUCCESS) && cdip != NULL) {
1655 1655 IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists");
1656 1656 mutex_exit(&ibnex.ibnex_mutex);
1657 1657 if (port_num != 0)
1658 1658 ibdm_ibnex_free_port_attr(port_attr);
1659 1659 else
1660 1660 ibdm_ibnex_free_hca_list(hca_list);
1661 1661 return (cdip);
1662 1662 }
1663 1663
1664 1664 if (pkey == 0 && port_num != 0) {
1665 1665 cdip = ibnex_commsvc_initnode(parent,
1666 1666 port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval,
1667 1667 IBNEX_DEVFS_ENUMERATE);
1668 1668 IBTF_DPRINTF_L5("ibnex",
1669 1669 "\t ibnex_commsvc_initnode rval %x", rval);
1670 1670 } else if (pkey == 0 && port_num == 0) {
1671 1671 cdip = ibnex_commsvc_initnode(parent,
1672 1672 port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval,
1673 1673 IBNEX_DEVFS_ENUMERATE);
1674 1674 IBTF_DPRINTF_L5("ibnex",
1675 1675 "\t ibnex_commsvc_initnode rval %x", rval);
1676 1676 } else {
1677 1677 if (port_attr->pa_state != IBT_PORT_ACTIVE) {
1678 1678 IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: "
1679 1679 "Port %d is down", port_attr->pa_port_num);
1680 1680 ibdm_ibnex_free_port_attr(port_attr);
1681 1681 mutex_exit(&ibnex.ibnex_mutex);
1682 1682 return (NULL);
1683 1683 }
1684 1684 for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
1685 1685 if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) {
1686 1686 cdip = ibnex_commsvc_initnode(parent, port_attr,
1687 1687 index, IBNEX_VPPA_COMMSVC_NODE,
1688 1688 pkey, &rval, IBNEX_CFGADM_ENUMERATE);
1689 1689 IBTF_DPRINTF_L5("ibnex",
1690 1690 "\t ibnex_commsvc_initnode rval %x", rval);
1691 1691 break;
1692 1692 }
1693 1693 }
1694 1694 }
1695 1695 mutex_exit(&ibnex.ibnex_mutex);
1696 1696 if (port_num != 0)
1697 1697 ibdm_ibnex_free_port_attr(port_attr);
1698 1698 else
1699 1699 ibdm_ibnex_free_hca_list(hca_list);
1700 1700 return (cdip);
1701 1701 }
1702 1702
1703 1703
1704 1704 /*
1705 1705 * ibnex_get_pkey_commsvc_index_portnum()
1706 1706 * Parses the device node name and extracts PKEY, communication
1707 1707 * service index & Port #.
1708 1708 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
1709 1709 */
1710 1710 int
1711 1711 ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index,
1712 1712 ib_pkey_t *pkey, uint8_t *port_num)
1713 1713 {
1714 1714 char *srv, **service_name, *temp;
1715 1715 int ii, ncommsvcs, ret;
1716 1716
1717 1717 if (ibnex_devname_to_portnum(device_name, port_num) !=
1718 1718 IBNEX_SUCCESS) {
1719 1719 IBTF_DPRINTF_L2("ibnex",
1720 1720 "\tget_pkey_commsvc_index_portnum: Invalid Service Name");
1721 1721 return (IBNEX_FAILURE);
1722 1722 }
1723 1723 srv = strchr(device_name, ',');
1724 1724 if (srv == 0)
1725 1725 return (IBNEX_FAILURE);
1726 1726
1727 1727 srv++;
1728 1728 temp = strchr(srv, ',');
1729 1729 if (temp == 0)
1730 1730 return (IBNEX_FAILURE);
1731 1731 temp++;
1732 1732 *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret);
1733 1733 if (ret != IBNEX_SUCCESS)
1734 1734 return (ret);
1735 1735
1736 1736 if (*pkey == 0 && *port_num != 0) {
1737 1737 service_name = ibnex.ibnex_comm_svc_names;
1738 1738 ncommsvcs = ibnex.ibnex_num_comm_svcs;
1739 1739 } else if (*pkey == 0 && *port_num == 0) {
1740 1740 service_name = ibnex.ibnex_hcasvc_comm_svc_names;
1741 1741 ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs;
1742 1742 } else {
1743 1743 service_name = ibnex.ibnex_vppa_comm_svc_names;
1744 1744 ncommsvcs = ibnex.ibnex_nvppa_comm_svcs;
1745 1745 }
1746 1746
1747 1747 for (ii = 0; ii < ncommsvcs; ii++) {
1748 1748 if (strcmp(service_name[ii], temp) == 0) {
1749 1749 break;
1750 1750 }
1751 1751 }
1752 1752 if (ii == ncommsvcs)
1753 1753 return (IBNEX_FAILURE);
1754 1754
1755 1755 *index = ii;
1756 1756 return (IBNEX_SUCCESS);
1757 1757 }
1758 1758
1759 1759
1760 1760 /*
1761 1761 * ibnex_devname_to_portnum()
1762 1762 * Get portguid from device name
1763 1763 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
1764 1764 */
1765 1765 static int
1766 1766 ibnex_devname_to_portnum(char *device_name, uint8_t *portnum)
1767 1767 {
1768 1768 int ret;
1769 1769 char *temp1, *temp2;
1770 1770
1771 1771 temp1 = strchr(device_name, '@');
1772 1772 if (temp1 == NULL) {
1773 1773 return (IBNEX_FAILURE);
1774 1774 }
1775 1775 temp2 = strchr(temp1, ',');
1776 1776 if (temp2 == NULL)
1777 1777 return (IBNEX_FAILURE);
1778 1778 temp1++;
1779 1779 *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret);
1780 1780 return (ret);
1781 1781 }
1782 1782
1783 1783
1784 1784 /*
1785 1785 * ibnex_config_ioc_node()
1786 1786 * Configures one particular instance of the IOC driver.
1787 1787 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
1788 1788 */
1789 1789 static int
1790 1790 ibnex_config_ioc_node(char *device_name, dev_info_t *pdip)
1791 1791 {
1792 1792 int ret;
1793 1793 ib_guid_t iou_guid, ioc_guid;
1794 1794 ibdm_ioc_info_t *ioc_info;
1795 1795
1796 1796 IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin");
1797 1797
1798 1798 if (ibnex_devname_to_node_n_ioc_guids(
1799 1799 device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
1800 1800 return (IBNEX_FAILURE);
1801 1801 }
1802 1802
1803 1803 ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
1804 1804
1805 1805 if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) ==
1806 1806 NULL) {
1807 1807 ibdm_ibnex_free_ioc_list(ioc_info);
1808 1808 return (IBNEX_FAILURE);
1809 1809 }
1810 1810 mutex_enter(&ibnex.ibnex_mutex);
1811 1811 ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0);
1812 1812 mutex_exit(&ibnex.ibnex_mutex);
1813 1813 ibdm_ibnex_free_ioc_list(ioc_info);
1814 1814 IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x",
1815 1815 ret);
1816 1816 return (ret);
1817 1817 }
1818 1818
1819 1819
1820 1820 /*
1821 1821 * ibnex_devname_to_node_n_ioc_guids()
1822 1822 * Get node guid and ioc guid from the device name
1823 1823 * Format of the device node name is:
1824 1824 * ioc@<IOC GUID>,<IOU GUID>
1825 1825 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
1826 1826 */
1827 1827 static int
1828 1828 ibnex_devname_to_node_n_ioc_guids(
1829 1829 char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid,
1830 1830 char **ioc_guid_strp)
1831 1831 {
1832 1832 char *temp1, *temp;
1833 1833 int len, ret;
1834 1834 char *ioc_guid_str;
1835 1835
1836 1836 IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:"
1837 1837 "Device Name %s", device_name);
1838 1838
1839 1839 if ((temp = strchr(device_name, '@')) == NULL) {
1840 1840 return (IBNEX_FAILURE);
1841 1841 }
1842 1842 if ((temp1 = strchr(++temp, ',')) == NULL) {
1843 1843 return (IBNEX_FAILURE);
1844 1844 }
1845 1845 *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret);
1846 1846 if (ret == IBNEX_SUCCESS) {
1847 1847 if (ioc_guid_strp) {
1848 1848 ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1
1849 1849 - temp) + 1, KM_SLEEP);
1850 1850 (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1);
1851 1851 ioc_guid_str[temp1 - temp] = '\0';
1852 1852 }
1853 1853 len = device_name + strlen(device_name) - ++temp1;
1854 1854 *iou_guid = ibnex_str2hex(temp1, len, &ret);
1855 1855 }
1856 1856 return (ret);
1857 1857 }
1858 1858
1859 1859
1860 1860 /*
1861 1861 * ibnex_ioc_initnode()
1862 1862 * Allocate a pathinfo node for the IOC
1863 1863 * Initialize the device node
1864 1864 * Bind driver to the node
1865 1865 * Update IBnex global data
1866 1866 * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY
1867 1867 */
1868 1868 static int
1869 1869 ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data,
1870 1870 ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
1871 1871 {
1872 1872 int rval, node_valid;
1873 1873 ibnex_node_state_t prev_state;
1874 1874
1875 1875 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
1876 1876 ASSERT(node_data);
1877 1877
1878 1878
1879 1879 /*
1880 1880 * Return EBUSY if another configure/unconfigure
1881 1881 * operation is in progress
1882 1882 */
1883 1883 if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
1884 1884 IBTF_DPRINTF_L4("ibnex",
1885 1885 "\tioc_initnode_pdip : BUSY");
1886 1886 return (IBNEX_BUSY);
1887 1887 }
1888 1888
1889 1889 prev_state = node_data->node_state;
1890 1890 node_data->node_state = IBNEX_CFGADM_CONFIGURING;
1891 1891 mutex_exit(&ibnex.ibnex_mutex);
1892 1892
1893 1893 rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid);
1894 1894
1895 1895 mutex_enter(&ibnex.ibnex_mutex);
1896 1896 if (rval == IBNEX_SUCCESS)
1897 1897 node_data->node_state = IBNEX_CFGADM_CONFIGURED;
1898 1898 else if (node_valid)
1899 1899 node_data->node_state = prev_state;
1900 1900
1901 1901 return (rval);
1902 1902 }
1903 1903
1904 1904 /*
1905 1905 * ibnex_config_pseudo_all()
1906 1906 * Configure all the pseudo nodes
1907 1907 */
1908 1908 static void
1909 1909 ibnex_config_pseudo_all(dev_info_t *pdip)
1910 1910 {
1911 1911 ibnex_node_data_t *nodep;
1912 1912
1913 1913 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
1914 1914
1915 1915 for (nodep = ibnex.ibnex_pseudo_node_head;
1916 1916 nodep; nodep = nodep->node_next) {
1917 1917 (void) ibnex_pseudo_config_one(nodep, NULL, pdip);
1918 1918 }
1919 1919 }
1920 1920
1921 1921
1922 1922 /*
1923 1923 * ibnex_pseudo_config_one()
1924 1924 */
1925 1925 int
1926 1926 ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr,
1927 1927 dev_info_t *pdip)
1928 1928 {
1929 1929 int rval;
1930 1930 ibnex_pseudo_node_t *pseudo;
1931 1931 ibnex_node_state_t prev_state;
1932 1932
1933 1933 IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)",
1934 1934 node_data, caddr, pdip);
1935 1935
1936 1936 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
1937 1937
1938 1938 if (node_data == NULL) {
1939 1939 IBTF_DPRINTF_L4("ibnex",
1940 1940 "\tpseudo_config_one: caddr = %s", caddr);
1941 1941
1942 1942 /*
1943 1943 * This function is now called with PHCI / HCA driver
1944 1944 * as parent. The format of devicename is :
1945 1945 * <driver_name>@<driver_name>,<unit_address>
1946 1946 * The "caddr" part of the devicename matches the
1947 1947 * format of pseudo_node_addr.
1948 1948 *
1949 1949 * Use "caddr" to find a matching Pseudo node entry.
1950 1950 */
1951 1951 node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
1952 1952 (void *)caddr, 0, 0);
1953 1953 }
1954 1954
1955 1955 if (node_data == NULL) {
1956 1956 IBTF_DPRINTF_L2("ibnex",
1957 1957 "\tpseudo_config_one: Invalid node");
1958 1958 return (IBNEX_FAILURE);
1959 1959 }
1960 1960
1961 1961 if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) {
1962 1962 IBTF_DPRINTF_L4("ibnex",
1963 1963 "\tpseudo_config_one: Unconfigured node");
1964 1964 return (IBNEX_FAILURE);
1965 1965 }
1966 1966
1967 1967 pseudo = &node_data->node_data.pseudo_node;
1968 1968
1969 1969 /*
1970 1970 * Do not enumerate nodes with ib-node-type set as "merge"
1971 1971 */
1972 1972 if (pseudo->pseudo_merge_node == 1) {
1973 1973 IBTF_DPRINTF_L4("ibnex",
1974 1974 "\tpseudo_config_one: merge_node");
1975 1975 return (IBNEX_FAILURE);
1976 1976 }
1977 1977
1978 1978 /*
1979 1979 * Check if a PI has already been created for the PDIP.
1980 1980 * If so, return SUCCESS.
1981 1981 */
1982 1982 if (node_data->node_dip != NULL && mdi_pi_find(pdip,
1983 1983 pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) {
1984 1984 IBTF_DPRINTF_L4("ibnex",
1985 1985 "\tpseudo_config_one: PI created,"
1986 1986 " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr);
1987 1987 return (IBNEX_SUCCESS);
1988 1988 }
1989 1989
1990 1990 /*
1991 1991 * Return EBUSY if another unconfigure
1992 1992 * operation is in progress
1993 1993 */
1994 1994 if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
1995 1995 IBTF_DPRINTF_L4("ibnex",
1996 1996 "\tpseudo_config_one: BUSY");
1997 1997 return (IBNEX_BUSY);
1998 1998 }
1999 1999
2000 2000
2001 2001 prev_state = node_data->node_state;
2002 2002 node_data->node_state = IBNEX_CFGADM_CONFIGURING;
2003 2003
2004 2004 mutex_exit(&ibnex.ibnex_mutex);
2005 2005 rval = ibnex_pseudo_create_pi_pdip(node_data, pdip);
2006 2006 mutex_enter(&ibnex.ibnex_mutex);
2007 2007
2008 2008 if (rval == IBNEX_SUCCESS) {
2009 2009 node_data->node_state = IBNEX_CFGADM_CONFIGURED;
2010 2010 } else {
2011 2011 node_data->node_state = prev_state;
2012 2012 }
2013 2013
2014 2014 IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x",
2015 2015 rval);
2016 2016 return (rval);
2017 2017 }
2018 2018
2019 2019
2020 2020 /*
2021 2021 * ibnex_pseudo_mdi_config_one()
2022 2022 * This is similar to ibnex_pseudo_config_one. Few
2023 2023 * differences :
2024 2024 * 1. parent device lock not held(no ndi_devi_enter)
2025 2025 * 2. Called for IB Nexus as parent, not IB HCA as
2026 2026 * parent.
2027 2027 * 3. Calls mdi_vhci_bus_config()
2028 2028 * This function skips checks for node_state, initializing
2029 2029 * node_state, node_dip, etc. These checks and initializations
2030 2030 * are done when BUS_CONFIG is called with PHCI as the parent.
2031 2031 */
2032 2032 int
2033 2033 ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child,
2034 2034 char *cname, char *caddr)
2035 2035 {
2036 2036 int rval, len;
2037 2037 char *node_addr;
2038 2038 ibnex_node_data_t *node_data;
2039 2039
2040 2040 IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:"
2041 2041 "cname = %s caddr = %s", cname, caddr);
2042 2042
2043 2043 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2044 2044
2045 2045 len = strlen(cname) + strlen(caddr) + 2;
2046 2046 node_addr = (char *)kmem_alloc(len, KM_SLEEP);
2047 2047
2048 2048 (void) snprintf(node_addr, len, "%s,%s", cname, caddr);
2049 2049 node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
2050 2050 (void *)node_addr, 0, 0);
2051 2051 kmem_free(node_addr, len);
2052 2052
2053 2053 if (node_data == NULL) {
2054 2054 IBTF_DPRINTF_L2("ibnex",
2055 2055 "\tpseudo_mdi_config_one: Invalid node");
2056 2056 return (IBNEX_FAILURE);
2057 2057 }
2058 2058
2059 2059 mutex_exit(&ibnex.ibnex_mutex);
2060 2060 rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE,
2061 2061 devname, child, node_data->node_data.pseudo_node.pseudo_node_addr);
2062 2062 mutex_enter(&ibnex.ibnex_mutex);
2063 2063
2064 2064 return (rval);
2065 2065 }
2066 2066
2067 2067
2068 2068 /*
2069 2069 * ibnex_pseudo_create_all_pi()
2070 2070 * Create all path infos node for a pseudo entry
2071 2071 */
2072 2072 int
2073 2073 ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep)
2074 2074 {
2075 2075 int hcacnt, rc;
2076 2076 int hcafailcnt = 0;
2077 2077 dev_info_t *hca_dip;
2078 2078 ibdm_hca_list_t *hca_list, *head;
2079 2079
2080 2080 IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)",
2081 2081 nodep);
2082 2082 ibdm_ibnex_get_hca_list(&hca_list, &hcacnt);
2083 2083
2084 2084 head = hca_list;
2085 2085
2086 2086 /*
2087 2087 * We return failure even if we fail for all HCAs.
2088 2088 */
2089 2089 for (; hca_list != NULL; hca_list = hca_list->hl_next) {
2090 2090 hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
2091 2091 rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip);
2092 2092 if (rc != IBNEX_SUCCESS)
2093 2093 hcafailcnt++;
2094 2094 }
2095 2095 if (head)
2096 2096 ibdm_ibnex_free_hca_list(head);
2097 2097
2098 2098 if (hcafailcnt == hcacnt)
2099 2099 rc = IBNEX_FAILURE;
2100 2100 else
2101 2101 rc = IBNEX_SUCCESS;
2102 2102
2103 2103 IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x",
2104 2104 rc);
2105 2105 return (rc);
2106 2106 }
2107 2107
2108 2108 static int
2109 2109 ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip)
2110 2110 {
2111 2111 mdi_pathinfo_t *pip;
2112 2112 int rval;
2113 2113 dev_info_t *cdip = NULL;
2114 2114 ibnex_pseudo_node_t *pseudo;
2115 2115 int first_pi = 0;
2116 2116
2117 2117 IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p",
2118 2118 nodep, hca_dip);
2119 2119
2120 2120 pseudo = &nodep->node_data.pseudo_node;
2121 2121
2122 2122 rval = mdi_pi_alloc(hca_dip,
2123 2123 pseudo->pseudo_devi_name, pseudo->pseudo_node_addr,
2124 2124 pseudo->pseudo_node_addr, 0, &pip);
2125 2125
2126 2126 if (rval != MDI_SUCCESS) {
2127 2127 IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:"
2128 2128 " mdi_pi_alloc failed");
2129 2129 return (IBNEX_FAILURE);
2130 2130 }
2131 2131 cdip = mdi_pi_get_client(pip);
2132 2132
2133 2133 if (nodep->node_dip == NULL) {
2134 2134 IBTF_DPRINTF_L4("ibnex",
2135 2135 "\tpseudo_create_pi: New dip %p", cdip);
2136 2136
2137 2137 first_pi = 1;
2138 2138 nodep->node_dip = cdip;
2139 2139 ddi_set_parent_data(cdip, nodep);
2140 2140 }
2141 2141
2142 2142 rval = mdi_pi_online(pip, 0);
2143 2143
2144 2144 if (rval != MDI_SUCCESS) {
2145 2145 IBTF_DPRINTF_L2("ibnex",
2146 2146 "\tpseudo_create_pi: "
2147 2147 "mdi_pi_online: failed for pseudo dip %p,"
2148 2148 " rval %d", cdip, rval);
2149 2149 rval = IBNEX_FAILURE;
2150 2150 if (first_pi == 1) {
2151 2151 ddi_set_parent_data(cdip, NULL);
2152 2152 (void) ibnex_offline_childdip(cdip);
2153 2153 nodep->node_dip = NULL;
2154 2154 } else
2155 2155 (void) mdi_pi_free(pip, 0);
2156 2156 } else
2157 2157 rval = IBNEX_SUCCESS;
2158 2158 return (rval);
2159 2159 }
2160 2160
2161 2161 /*
2162 2162 * ibnex_ioc_create_pi()
2163 2163 * Create a pathinfo node for the ioc node
2164 2164 */
2165 2165 static int
2166 2166 ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data,
2167 2167 dev_info_t *pdip, int *node_valid)
2168 2168 {
2169 2169 mdi_pathinfo_t *pip;
2170 2170 int rval = DDI_FAILURE;
2171 2171 dev_info_t *cdip = NULL;
2172 2172 int create_prop = 0;
2173 2173 ibnex_ioc_node_t *ioc = &node_data->node_data.ioc_node;
2174 2174
2175 2175 IBTF_DPRINTF_L4("ibnex",
2176 2176 "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip);
2177 2177 *node_valid = 1;
2178 2178
2179 2179 /*
2180 2180 * For CONFIG_ONE requests through HCA dip, alloc
2181 2181 * for HCA dip driving BUS_CONFIG request.
2182 2182 */
2183 2183 rval = mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str,
2184 2184 ioc->ioc_phci_guid, 0, &pip);
2185 2185 if (rval != MDI_SUCCESS) {
2186 2186 IBTF_DPRINTF_L2("ibnex",
2187 2187 "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed",
2188 2188 pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid);
2189 2189 return (IBNEX_FAILURE);
2190 2190 }
2191 2191 cdip = mdi_pi_get_client(pip);
2192 2192
2193 2193 IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p",
2194 2194 cdip);
2195 2195
2196 2196 if (node_data->node_dip == NULL) {
2197 2197 node_data->node_dip = cdip;
2198 2198 ddi_set_parent_data(cdip, node_data);
2199 2199 create_prop = 1;
2200 2200 IBTF_DPRINTF_L4("ibnex",
2201 2201 "\tioc_create_pi: creating prop");
2202 2202 if ((rval = ibnex_create_ioc_node_prop(
2203 2203 ioc_info, cdip)) != IBNEX_SUCCESS) {
2204 2204 IBTF_DPRINTF_L4("ibnex",
2205 2205 "\tioc_create_pi: creating prop failed");
2206 2206 ibnex_delete_ioc_node_data(node_data);
2207 2207 *node_valid = 0;
2208 2208 ddi_prop_remove_all(cdip);
2209 2209 ddi_set_parent_data(cdip, NULL);
2210 2210
2211 2211 (void) ibnex_offline_childdip(cdip);
2212 2212 return (IBNEX_FAILURE);
2213 2213 }
2214 2214 }
2215 2215
2216 2216 rval = mdi_pi_online(pip, 0);
2217 2217
2218 2218 if (rval != MDI_SUCCESS) {
2219 2219 IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: "
2220 2220 "mdi_pi_online() failed ioc dip %p, rval %d",
2221 2221 cdip, rval);
2222 2222 rval = IBNEX_FAILURE;
2223 2223 if (create_prop) {
2224 2224 ddi_set_parent_data(cdip, NULL);
2225 2225 ddi_prop_remove_all(cdip);
2226 2226 ibnex_delete_ioc_node_data(node_data);
2227 2227 *node_valid = 0;
2228 2228 (void) ibnex_offline_childdip(cdip);
2229 2229 } else
2230 2230 (void) mdi_pi_free(pip, 0);
2231 2231 } else
2232 2232 rval = IBNEX_SUCCESS;
2233 2233
2234 2234 IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval);
2235 2235 return (rval);
2236 2236 }
2237 2237
2238 2238
2239 2239 /*
2240 2240 * ibnex_create_ioc_node_prop()
2241 2241 * Create IOC device node properties
2242 2242 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
2243 2243 */
2244 2244 static int
2245 2245 ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip)
2246 2246 {
2247 2247 uint16_t capabilities;
2248 2248 ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile;
2249 2249
2250 2250 IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop");
2251 2251
2252 2252 if (ibnex_create_ioc_compatible_prop(cdip,
2253 2253 ioc_profile) != IBNEX_SUCCESS) {
2254 2254 return (IBNEX_FAILURE);
2255 2255 }
2256 2256 if ((ioc_info->ioc_iou_dc_valid) &&
2257 2257 (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode",
2258 2258 ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) {
2259 2259 IBTF_DPRINTF_L2("ibnex",
2260 2260 "\tcreate_ioc_node_prop: iou-diagcode create failed");
2261 2261 return (IBNEX_FAILURE);
2262 2262 }
2263 2263 if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) {
2264 2264 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode",
2265 2265 ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) {
2266 2266 IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
2267 2267 "ioc-diagcode create failed");
2268 2268 return (IBNEX_FAILURE);
2269 2269 }
2270 2270 }
2271 2271 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth",
2272 2272 ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) {
2273 2273 IBTF_DPRINTF_L2("ibnex",
2274 2274 "\tcreate_ioc_node_prop: rdma-queue-depth create failed");
2275 2275 return (IBNEX_FAILURE);
2276 2276 }
2277 2277 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size",
2278 2278 ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) {
2279 2279 IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
2280 2280 "rdma-transfer-size create failed");
2281 2281 return (IBNEX_FAILURE);
2282 2282 }
2283 2283 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size",
2284 2284 ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) {
2285 2285 IBTF_DPRINTF_L2("ibnex",
2286 2286 "\tcreate_ioc_node_prop: send-message-size create failed");
2287 2287 return (IBNEX_FAILURE);
2288 2288 }
2289 2289 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth",
2290 2290 ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) {
2291 2291 IBTF_DPRINTF_L2("ibnex",
2292 2292 "\tcreate_ioc_node_prop: send-queue-depth create failed");
2293 2293 return (IBNEX_FAILURE);
2294 2294 }
2295 2295
2296 2296 capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8);
2297 2297 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip,
2298 2298 "capabilities", capabilities) != DDI_PROP_SUCCESS) {
2299 2299 IBTF_DPRINTF_L2("ibnex",
2300 2300 "\tcreate_ioc_node_prop: capabilities create failed");
2301 2301 return (IBNEX_FAILURE);
2302 2302 }
2303 2303 if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string",
2304 2304 (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) {
2305 2305 IBTF_DPRINTF_L2("ibnex",
2306 2306 "\tcreate_ioc_node_prop: id-string failed");
2307 2307 return (IBNEX_FAILURE);
2308 2308 }
2309 2309
2310 2310 /*
2311 2311 * Create properties to represent all the service entries supported
2312 2312 * by the IOC. Each service entry consists of 1) Service ID (64 bits)
2313 2313 * and 2) Service name (40 bytes). The service entry table is
2314 2314 * represented by two properties, service-ids and service-names. The
2315 2315 * service-id property is a array of int64's and service names is
2316 2316 * array of strings. The first element in the "service-ids" property
2317 2317 * corresponds to first string in the "service-names" and so on.
2318 2318 */
2319 2319 if ((ioc_profile->ioc_service_entries != 0) &&
2320 2320 (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS))
2321 2321 return (IBNEX_FAILURE);
2322 2322
2323 2323 /* Create destination port GID properties */
2324 2324 if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS)
2325 2325 return (IBNEX_FAILURE);
2326 2326
2327 2327 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version",
2328 2328 ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) {
2329 2329 IBTF_DPRINTF_L2("ibnex",
2330 2330 "\tcreate_ioc_node_prop: protocol-version create failed");
2331 2331 return (IBNEX_FAILURE);
2332 2332 }
2333 2333 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol",
2334 2334 ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) {
2335 2335 IBTF_DPRINTF_L2("ibnex",
2336 2336 "\tcreate_ioc_node_prop: protocol create failed");
2337 2337 return (IBNEX_FAILURE);
2338 2338 }
2339 2339 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass",
2340 2340 ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) {
2341 2341 IBTF_DPRINTF_L2("ibnex",
2342 2342 "\tcreate_ioc_node_prop: subclass create failed");
2343 2343 return (IBNEX_FAILURE);
2344 2344 }
2345 2345 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class",
2346 2346 ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) {
2347 2347 IBTF_DPRINTF_L2("ibnex",
2348 2348 "\tcreate_ioc_node_prop: class prop create failed");
2349 2349 return (IBNEX_FAILURE);
2350 2350 }
2351 2351 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id",
2352 2352 ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) {
2353 2353 IBTF_DPRINTF_L2("ibnex",
2354 2354 "\tcreate_ioc_node_prop: subsys_id create failed");
2355 2355 return (IBNEX_FAILURE);
2356 2356 }
2357 2357 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id",
2358 2358 ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) {
2359 2359 IBTF_DPRINTF_L2("ibnex",
2360 2360 "\tcreate_ioc_node_prop: subsystem vendor create failed");
2361 2361 return (IBNEX_FAILURE);
2362 2362 }
2363 2363 if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid",
2364 2364 ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) {
2365 2365 IBTF_DPRINTF_L2("ibnex",
2366 2366 "\tcreate_ioc_node_prop: protocol create failed");
2367 2367 return (IBNEX_FAILURE);
2368 2368 }
2369 2369 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version",
2370 2370 ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) {
2371 2371 IBTF_DPRINTF_L2("ibnex",
2372 2372 "\tcreate_ioc_node_prop: product-id create failed");
2373 2373 return (IBNEX_FAILURE);
2374 2374 }
2375 2375 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id",
2376 2376 ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) {
2377 2377 IBTF_DPRINTF_L2("ibnex",
2378 2378 "\tcreate_ioc_node_prop: product-id create failed");
2379 2379 return (IBNEX_FAILURE);
2380 2380 }
2381 2381 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id",
2382 2382 ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) {
2383 2383 IBTF_DPRINTF_L2("ibnex",
2384 2384 "\tcreate_ioc_node_prop: vendor-id create failed");
2385 2385 return (IBNEX_FAILURE);
2386 2386 }
2387 2387 return (IBNEX_SUCCESS);
2388 2388 }
2389 2389
2390 2390
2391 2391 /*
2392 2392 * ibnex_create_ioc_portgid_prop()
2393 2393 * Creates "port-entries", "port-list" properties
2394 2394 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
2395 2395 */
2396 2396 static int
2397 2397 ibnex_create_ioc_portgid_prop(
2398 2398 dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
2399 2399 {
2400 2400 uint64_t *port_gids;
2401 2401 int length, ii, jj;
2402 2402 int prop_len;
2403 2403 ibnex_node_data_t *node_data;
2404 2404
2405 2405 IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop");
2406 2406
2407 2407 node_data = ddi_get_parent_data(cdip);
2408 2408 ASSERT(node_data);
2409 2409
2410 2410 prop_len = (ioc_info->ioc_nportgids != 0) ?
2411 2411 (2 * ioc_info->ioc_nportgids) : 1;
2412 2412 length = sizeof (uint64_t) * prop_len;
2413 2413 port_gids = kmem_zalloc(length, KM_SLEEP);
2414 2414
2415 2415 for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) {
2416 2416 port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi;
2417 2417 port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo;
2418 2418 }
2419 2419 if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list",
2420 2420 (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) {
2421 2421 IBTF_DPRINTF_L2("ibnex",
2422 2422 "\tcreate_ioc_portgid_prop: port-list create failed");
2423 2423 kmem_free(port_gids, length);
2424 2424 return (IBNEX_FAILURE);
2425 2425 }
2426 2426 if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries",
2427 2427 ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) {
2428 2428 IBTF_DPRINTF_L2("ibnex",
2429 2429 "\tcreate_ioc_portgid_prop: port-entries create failed");
2430 2430 kmem_free(port_gids, length);
2431 2431 return (IBNEX_FAILURE);
2432 2432 }
2433 2433
2434 2434 kmem_free(port_gids, length);
2435 2435 return (IBNEX_SUCCESS);
2436 2436 }
2437 2437
2438 2438
2439 2439 /*
2440 2440 * ibnex_create_ioc_srv_props()
2441 2441 * Creates "service-name" and "service-id" properties
2442 2442 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
2443 2443 */
2444 2444 static int
2445 2445 ibnex_create_ioc_srv_props(
2446 2446 dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
2447 2447 {
2448 2448 int length, ii;
2449 2449 uint64_t *srv_id;
2450 2450 char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU];
2451 2451 ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile;
2452 2452 ibdm_srvents_info_t *srvents = ioc_info->ioc_serv;
2453 2453
2454 2454 IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props");
2455 2455
2456 2456 length = profile->ioc_service_entries * sizeof (ib_dm_srv_t);
2457 2457 srv_id = kmem_zalloc(length, KM_SLEEP);
2458 2458 temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries));
2459 2459 for (ii = 0; ii < profile->ioc_service_entries; ii++) {
2460 2460 srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN);
2461 2461 }
2462 2462
2463 2463 for (ii = 0; ii < profile->ioc_service_entries; ii++) {
2464 2464 srv_id[ii] = srvents[ii].se_attr.srv_id;
2465 2465 bcopy(srvents[ii].se_attr.srv_name,
2466 2466 srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1));
2467 2467 IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
2468 2468 "Service Names : %s", srv_names[ii]);
2469 2469 IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
2470 2470 "Service ID : %llX", srv_id[ii]);
2471 2471 }
2472 2472
2473 2473 if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip,
2474 2474 "service-id", (int64_t *)srv_id,
2475 2475 profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
2476 2476 IBTF_DPRINTF_L2("ibnex",
2477 2477 "\tcreate_ioc_srv_props: service-id create failed");
2478 2478 kmem_free(srv_id, length);
2479 2479 return (IBNEX_FAILURE);
2480 2480 }
2481 2481
2482 2482 if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
2483 2483 "service-name", (char **)srv_names,
2484 2484 profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
2485 2485 IBTF_DPRINTF_L2("ibnex",
2486 2486 "\tcreate_ioc_srv_props: service-name create failed");
2487 2487 kmem_free(srv_id, length);
2488 2488 return (IBNEX_FAILURE);
2489 2489 }
2490 2490 kmem_free(srv_id, length);
2491 2491 return (IBNEX_SUCCESS);
2492 2492 }
2493 2493
2494 2494
2495 2495 /*
2496 2496 * ibnex_create_ioc_compatible_prop()
2497 2497 * Creates "compatible" property values
2498 2498 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
2499 2499 */
2500 2500 static int
2501 2501 ibnex_create_ioc_compatible_prop(
2502 2502 dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile)
2503 2503 {
2504 2504 char *temp;
2505 2505 int rval, ii;
2506 2506 char *compatible[IBNEX_MAX_COMPAT_NAMES];
2507 2507
2508 2508 /*
2509 2509 * Initialize the "compatible" property string as below:
2510 2510 * Compatible Strings :
2511 2511 * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver>
2512 2512 * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id>
2513 2513 * 3. ib.V<vid>P<pid>v<ver>
2514 2514 * 4. ib.V<vid>P<pid>
2515 2515 * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver>
2516 2516 * 6. ib.C<Class>c<Subclass>p<protocol>
2517 2517 *
2518 2518 * Note:
2519 2519 * All leading zeros must be present
2520 2520 * All numeric values must specified in hex without prefix "0x"
2521 2521 */
2522 2522
2523 2523 temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP);
2524 2524 for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
2525 2525 compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN);
2526 2526
2527 2527 (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
2528 2528 "ib.V%06xP%08xS%06xs%08xv%04x",
2529 2529 ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
2530 2530 ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id,
2531 2531 ioc_profile->ioc_device_ver);
2532 2532
2533 2533 (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
2534 2534 "ib.V%06xP%08xS%06xs%08x",
2535 2535 ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
2536 2536 ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id);
2537 2537
2538 2538 (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
2539 2539 "ib.V%06xP%08xv%04x",
2540 2540 ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
2541 2541 ioc_profile->ioc_device_ver);
2542 2542
2543 2543 (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN,
2544 2544 "ib.V%06xP%08x",
2545 2545 ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid);
2546 2546
2547 2547 (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN,
2548 2548 "ib.C%04xc%04xp%04xr%04x",
2549 2549 ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
2550 2550 ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver);
2551 2551
2552 2552 (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN,
2553 2553 "ib.C%04xc%04xp%04x",
2554 2554 ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
2555 2555 ioc_profile->ioc_protocol);
2556 2556 for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
2557 2557 IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]);
2558 2558
2559 2559 /* Create the compatible property for child cdip */
2560 2560 rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
2561 2561 "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES);
2562 2562
2563 2563 if (rval != DDI_PROP_SUCCESS) {
2564 2564 IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed");
2565 2565 kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
2566 2566 return (IBNEX_FAILURE);
2567 2567 }
2568 2568
2569 2569 kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
2570 2570 return (IBNEX_SUCCESS);
2571 2571 }
2572 2572
2573 2573
2574 2574 static void
2575 2575 ibnex_ioc_node_cleanup()
2576 2576 {
2577 2577 ibnex_node_data_t *node, *delete;
2578 2578
2579 2579 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2580 2580 for (node = ibnex.ibnex_ioc_node_head; node; ) {
2581 2581 delete = node;
2582 2582 node = node->node_next;
2583 2583 mutex_exit(&ibnex.ibnex_mutex);
2584 2584 ibnex_delete_ioc_node_data(delete);
2585 2585 mutex_enter(&ibnex.ibnex_mutex);
2586 2586 }
2587 2587 }
2588 2588
2589 2589 /*
2590 2590 * ibnex_delete_ioc_node_data()
2591 2591 * Delete IOC node from the list
2592 2592 */
2593 2593 static void
2594 2594 ibnex_delete_ioc_node_data(ibnex_node_data_t *node)
2595 2595 {
2596 2596 IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:");
2597 2597
2598 2598 mutex_enter(&ibnex.ibnex_mutex);
2599 2599 if ((node->node_next == NULL) && (node->node_prev == NULL)) {
2600 2600 ASSERT(ibnex.ibnex_ioc_node_head == node);
2601 2601 ibnex.ibnex_ioc_node_head = NULL;
2602 2602 } else if (node->node_next == NULL)
2603 2603 node->node_prev->node_next = NULL;
2604 2604 else if (node->node_prev == NULL) {
2605 2605 node->node_next->node_prev = NULL;
2606 2606 ibnex.ibnex_ioc_node_head = node->node_next;
2607 2607 } else {
2608 2608 node->node_prev->node_next = node->node_next;
2609 2609 node->node_next->node_prev = node->node_prev;
2610 2610 }
2611 2611 IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p",
2612 2612 ibnex.ibnex_ioc_node_head);
2613 2613 mutex_exit(&ibnex.ibnex_mutex);
2614 2614 kmem_free(node, sizeof (ibnex_node_data_t));
2615 2615 }
2616 2616
2617 2617
2618 2618 /*
2619 2619 * ibnex_dm_callback()
2620 2620 *
2621 2621 * This routine is registered with the IBDM during IB nexus attach. It
2622 2622 * is called by the IBDM module when it discovers
2623 2623 * New HCA port
2624 2624 * HCA port removal
2625 2625 * New HCA added
2626 2626 * HCA removed
2627 2627 */
2628 2628 void
2629 2629 ibnex_dm_callback(void *arg, ibdm_events_t flag)
2630 2630 {
2631 2631 char hca_guid[IBNEX_HCAGUID_STRSZ];
2632 2632 ibdm_ioc_info_t *ioc_list, *ioc;
2633 2633 ibnex_node_data_t *node_data;
2634 2634 dev_info_t *phci;
2635 2635 ib_guid_t *guid;
2636 2636
2637 2637 IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag);
2638 2638
2639 2639 switch (flag) {
2640 2640 case IBDM_EVENT_HCA_ADDED:
2641 2641 (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
2642 2642 (*(longlong_t *)arg));
2643 2643 /* Create a devctl minor node for the HCA's port */
2644 2644 if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR,
2645 2645 ddi_get_instance(ibnex.ibnex_dip),
2646 2646 DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
2647 2647 IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
2648 2648 "create minor node for port w/ guid %s", hca_guid);
2649 2649 }
2650 2650
2651 2651 guid = kmem_alloc(sizeof (ib_guid_t), KM_SLEEP);
2652 2652 *guid = *(ib_guid_t *)arg;
2653 2653 if (ddi_taskq_dispatch(ibnex.ibnex_taskq_id,
2654 2654 ibnex_handle_hca_attach, guid, DDI_NOSLEEP)
2655 2655 != DDI_SUCCESS) {
2656 2656 kmem_free(guid, sizeof (ib_guid_t));
2657 2657 IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
2658 2658 "dispatch HCA add event for guid %s", hca_guid);
2659 2659 }
2660 2660
2661 2661 break;
2662 2662
2663 2663 case IBDM_EVENT_HCA_REMOVED:
2664 2664 (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
2665 2665 (*(longlong_t *)arg));
2666 2666 ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid);
2667 2667 break;
2668 2668
2669 2669 case IBDM_EVENT_IOC_PROP_UPDATE:
2670 2670 ioc = ioc_list = (ibdm_ioc_info_t *)arg;
2671 2671 if (ioc_list == NULL)
2672 2672 break;
2673 2673
2674 2674 mutex_enter(&ibnex.ibnex_mutex);
2675 2675 while (ioc_list) {
2676 2676 if ((node_data = ibnex_is_node_data_present(
2677 2677 IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL &&
2678 2678 node_data->node_dip != NULL) {
2679 2679 ibnex_update_prop(node_data, ioc_list);
2680 2680 }
2681 2681 ioc_list = ioc_list->ioc_next;
2682 2682 }
2683 2683 mutex_exit(&ibnex.ibnex_mutex);
2684 2684 ibdm_ibnex_free_ioc_list(ioc);
2685 2685 break;
2686 2686
2687 2687 case IBDM_EVENT_PORT_UP:
2688 2688 case IBDM_EVENT_PORT_PKEY_CHANGE:
2689 2689 phci = ibtl_ibnex_hcaguid2dip(*(longlong_t *)arg);
2690 2690 (void) devfs_clean(phci, NULL, 0);
2691 2691 break;
2692 2692 default:
2693 2693 break;
2694 2694
2695 2695 }
2696 2696 }
2697 2697
2698 2698
2699 2699 /*
2700 2700 * ibnex_get_node_and_dip_from_guid()
2701 2701 *
2702 2702 * Searches the linked list of the port nodes and returns the dip for
2703 2703 * the of the Port / Node guid requested.
2704 2704 * Returns NULL if not found
2705 2705 */
2706 2706 int
2707 2707 ibnex_get_node_and_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
2708 2708 ibnex_node_data_t **nodep, dev_info_t **dip)
2709 2709 {
2710 2710 int node_index;
2711 2711 ib_guid_t node_guid;
2712 2712 ib_pkey_t node_pkey;
2713 2713 ibnex_node_data_t *node_data;
2714 2714
2715 2715 IBTF_DPRINTF_L4("ibnex",
2716 2716 "\tget_node_and_dip_from_guid: guid = %llX", guid);
2717 2717
2718 2718 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2719 2719 /* Search for a matching entry in internal lists */
2720 2720 node_data = ibnex.ibnex_port_node_head;
2721 2721 while (node_data) {
2722 2722 node_guid = node_data->node_data.port_node.port_guid;
2723 2723 node_index = node_data->node_data.port_node.port_commsvc_idx;
2724 2724 node_pkey = node_data->node_data.port_node.port_pkey;
2725 2725 if ((node_guid == guid) && (index == node_index) &&
2726 2726 (node_pkey == pkey)) {
2727 2727 break;
2728 2728 }
2729 2729 node_data = node_data->node_next;
2730 2730 }
2731 2731
2732 2732 /* matching found with a valid dip */
2733 2733 if (node_data && node_data->node_dip) {
2734 2734 *nodep = node_data;
2735 2735 *dip = node_data->node_dip;
2736 2736 return (IBNEX_SUCCESS);
2737 2737 } else if (node_data && !node_data->node_dip) { /* dip is invalid */
2738 2738 *nodep = node_data;
2739 2739 *dip = NULL;
2740 2740 return (IBNEX_SUCCESS);
2741 2741 }
2742 2742
2743 2743 /* no match found */
2744 2744 *nodep = NULL;
2745 2745 *dip = NULL;
2746 2746 return (IBNEX_FAILURE);
2747 2747 }
2748 2748
2749 2749 /*
2750 2750 * ibnex_get_dip_from_guid()
2751 2751 *
2752 2752 * Searches the linked list of the port nodes and returns the dip for
2753 2753 * the of the Port / Node guid requested.
2754 2754 * Returns NULL if not found
2755 2755 */
2756 2756 int
2757 2757 ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
2758 2758 dev_info_t **dip)
2759 2759 {
2760 2760 int node_index;
2761 2761 ib_guid_t node_guid;
2762 2762 ib_pkey_t node_pkey;
2763 2763 ibnex_node_data_t *node_data;
2764 2764
2765 2765 IBTF_DPRINTF_L4("ibnex",
2766 2766 "\tget_dip_from_guid: guid = %llX", guid);
2767 2767
2768 2768 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2769 2769 /* Search for a matching entry in internal lists */
2770 2770 node_data = ibnex.ibnex_port_node_head;
2771 2771 while (node_data) {
2772 2772 node_guid = node_data->node_data.port_node.port_guid;
2773 2773 node_index = node_data->node_data.port_node.port_commsvc_idx;
2774 2774 node_pkey = node_data->node_data.port_node.port_pkey;
2775 2775 if ((node_guid == guid) && (index == node_index) &&
2776 2776 (node_pkey == pkey)) {
2777 2777 break;
2778 2778 }
2779 2779 node_data = node_data->node_next;
2780 2780 }
2781 2781
2782 2782 /* matching found with a valid dip */
2783 2783 if (node_data && node_data->node_dip) {
2784 2784 *dip = node_data->node_dip;
2785 2785 return (IBNEX_SUCCESS);
2786 2786 } else if (node_data && !node_data->node_dip) { /* dip is invalid */
2787 2787 *dip = NULL;
2788 2788 return (IBNEX_SUCCESS);
2789 2789 }
2790 2790
2791 2791 /* no match found */
2792 2792 *dip = NULL;
2793 2793 return (IBNEX_FAILURE);
2794 2794 }
2795 2795
2796 2796
2797 2797 /*
2798 2798 * ibnex_comm_svc_init()
2799 2799 * Read the property and cache the values in the global
2800 2800 * structure.
2801 2801 * Check for max allowed length (4 bytes) of service name
2802 2802 * (each element of the property)
2803 2803 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
2804 2804 */
2805 2805 static ibnex_rval_t
2806 2806 ibnex_comm_svc_init(char *property, ibnex_node_type_t type)
2807 2807 {
2808 2808 int i, len, count;
2809 2809 int ncomm_svcs;
2810 2810 char **comm_svcp;
2811 2811 char **servicep = NULL;
2812 2812 uint_t nservices = 0;
2813 2813 int *valid = NULL;
2814 2814
2815 2815 IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x",
2816 2816 property, type);
2817 2817
2818 2818 /* lookup the string array property */
2819 2819 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip,
2820 2820 DDI_PROP_DONTPASS, property, &servicep, &nservices) !=
2821 2821 DDI_PROP_SUCCESS) {
2822 2822 IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property);
2823 2823 return (IBNEX_SUCCESS);
2824 2824 }
2825 2825
2826 2826 if (nservices)
2827 2827 valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP);
2828 2828
2829 2829
2830 2830 /* first read the file to get a count of valid service entries */
2831 2831 for (ncomm_svcs = 0, count = 0; count < nservices; count++) {
2832 2832 int j;
2833 2833
2834 2834 len = strlen(servicep[count]);
2835 2835 /*
2836 2836 * ib.conf has NULL strings for port-svc-list &
2837 2837 * hca-svc-list, by default. Do not have L2 message
2838 2838 * for these.
2839 2839 */
2840 2840 if (len == 1 || len > 4) {
2841 2841 IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
2842 2842 "Service name %s for property %s invalid : "
2843 2843 "length %d", servicep[count], property, len);
2844 2844 continue;
2845 2845 } else if (len == 0) {
2846 2846 continue;
2847 2847 }
2848 2848 if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) {
2849 2849 IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
2850 2850 "Service name %s invalid : Not unique",
2851 2851 servicep[count]);
2852 2852 continue;
2853 2853 }
2854 2854
2855 2855 /*
2856 2856 * ibnex_unique_svcname checks for uniqueness in service names
2857 2857 * communication services fully initialized. Check uniqueness
2858 2858 * in service names currently initialized.
2859 2859 */
2860 2860 for (j = 0; j < count; j++)
2861 2861 if (valid[j] && strncmp(servicep[count],
2862 2862 servicep[j], 4) == 0) {
2863 2863 IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
2864 2864 "Service name %s invalid : Not unique",
2865 2865 servicep[count]);
2866 2866 continue;
2867 2867 }
2868 2868
2869 2869 valid[count] = 1;
2870 2870 ncomm_svcs++;
2871 2871 }
2872 2872
2873 2873 /* if no valid entries found, bailout */
2874 2874 if (nservices == 0 || ncomm_svcs == 0) {
2875 2875 IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property);
2876 2876 ddi_prop_free(servicep); /* free the property */
2877 2877 if (valid)
2878 2878 kmem_free(valid, nservices * sizeof (int));
2879 2879 return (IBNEX_SUCCESS);
2880 2880 }
2881 2881
2882 2882 comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP);
2883 2883 if (type == IBNEX_PORT_COMMSVC_NODE) {
2884 2884 ibnex.ibnex_comm_svc_names = comm_svcp;
2885 2885 ibnex.ibnex_num_comm_svcs = ncomm_svcs;
2886 2886 } else if (type == IBNEX_VPPA_COMMSVC_NODE) {
2887 2887 ibnex.ibnex_vppa_comm_svc_names = comm_svcp;
2888 2888 ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs;
2889 2889 } else if (type == IBNEX_HCASVC_COMMSVC_NODE) {
2890 2890 ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp;
2891 2891 ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs;
2892 2892 }
2893 2893
2894 2894 /* copy the services into an array of strings */
2895 2895 for (i = 0, count = 0; count < nservices; count++) {
2896 2896 if (valid[count] == 0) /* Skip invalid ones */
2897 2897 continue;
2898 2898 comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP);
2899 2899 (void) strcpy(comm_svcp[i], servicep[count]);
2900 2900 IBTF_DPRINTF_L4("ibnex",
2901 2901 "\t\tService [%d]: %s", i, comm_svcp[i]);
2902 2902 ++i;
2903 2903 }
2904 2904 ddi_prop_free(servicep);
2905 2905 kmem_free(valid, nservices * sizeof (int));
2906 2906 return (IBNEX_SUCCESS);
2907 2907 }
2908 2908
2909 2909
2910 2910 /*
2911 2911 * ibnex_comm_svc_fini()
2912 2912 * Deallocate all the memory allocated for the communication
2913 2913 * service arrays.
2914 2914 */
2915 2915 static void
2916 2916 ibnex_comm_svc_fini()
2917 2917 {
2918 2918 int index;
2919 2919
2920 2920 for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) {
2921 2921 kmem_free(ibnex.ibnex_comm_svc_names[index],
2922 2922 (strlen(ibnex.ibnex_comm_svc_names[index]) + 1));
2923 2923 }
2924 2924 if (ibnex.ibnex_comm_svc_names) {
2925 2925 kmem_free(ibnex.ibnex_comm_svc_names,
2926 2926 ibnex.ibnex_num_comm_svcs * sizeof (char *));
2927 2927 }
2928 2928 for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) {
2929 2929 kmem_free(ibnex.ibnex_vppa_comm_svc_names[index],
2930 2930 strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1);
2931 2931 }
2932 2932 if (ibnex.ibnex_vppa_comm_svc_names) {
2933 2933 kmem_free(ibnex.ibnex_vppa_comm_svc_names,
2934 2934 ibnex.ibnex_nvppa_comm_svcs * sizeof (char *));
2935 2935 }
2936 2936 for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) {
2937 2937 kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index],
2938 2938 strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1);
2939 2939 }
2940 2940 if (ibnex.ibnex_hcasvc_comm_svc_names) {
2941 2941 kmem_free(ibnex.ibnex_hcasvc_comm_svc_names,
2942 2942 ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *));
2943 2943 }
2944 2944 ibnex.ibnex_comm_svc_names = NULL;
2945 2945 ibnex.ibnex_num_comm_svcs = 0;
2946 2946 ibnex.ibnex_vppa_comm_svc_names = NULL;
2947 2947 ibnex.ibnex_nvppa_comm_svcs = 0;
2948 2948 ibnex.ibnex_hcasvc_comm_svc_names = NULL;
2949 2949 ibnex.ibnex_nhcasvc_comm_svcs = 0;
2950 2950 }
2951 2951
2952 2952
2953 2953 /*
2954 2954 * ibnex_commsvc_initnode()
2955 2955 * This routine is specific to port/VPPA node creation
2956 2956 * Creates a device node for the comm service specified by commsvc_index
2957 2957 * Creates all the device node properties
2958 2958 * Allocates and initializes the node specific data
2959 2959 * Binds the device driver of the device node
2960 2960 * Returns "dev_info_t" of the child node or NULL in case of failure
2961 2961 * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect
2962 2962 * if the operation was successful, failed or was not performed.
2963 2963 */
2964 2964 dev_info_t *
2965 2965 ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr,
2966 2966 int index, int node_type, ib_pkey_t pkey, int *rval, int flag)
2967 2967 {
2968 2968 int ret;
2969 2969 char *svcname;
2970 2970 dev_info_t *cdip;
2971 2971 ibnex_node_data_t *node_data;
2972 2972 ibnex_port_node_t *port_node;
2973 2973 char devname[MAXNAMELEN];
2974 2974 int cdip_allocated = 0;
2975 2975
2976 2976 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2977 2977
2978 2978 *rval = IBNEX_SUCCESS;
2979 2979
2980 2980 /*
2981 2981 * prevent any races
2982 2982 * we have seen this node_data and it has been initialized
2983 2983 * Note that node_dip is already NULL if unconfigure is in
2984 2984 * progress.
2985 2985 */
2986 2986 node_data = ibnex_is_node_data_present(node_type, (void *)port_attr,
2987 2987 index, pkey);
2988 2988
2989 2989 /*
2990 2990 * If this node has been explicity unconfigured by cfgadm, then it can
2991 2991 * be configured back again only by cfgadm configure.
2992 2992 */
2993 2993 if (node_data && (node_data->node_ap_state ==
2994 2994 IBNEX_NODE_AP_UNCONFIGURED)) {
2995 2995 *rval = IBNEX_FAILURE;
2996 2996 return (NULL);
2997 2997 }
2998 2998
2999 2999 if (node_data && node_data->node_dip) {
3000 3000 /*
3001 3001 * Return NULL if another configure
3002 3002 * operation is in progress
3003 3003 */
3004 3004 if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) {
3005 3005 *rval = IBNEX_BUSY;
3006 3006 return (NULL);
3007 3007 } else {
3008 3008 return (node_data->node_dip);
3009 3009 }
3010 3010 } else if (node_data == NULL) {
3011 3011 /* allocate a new ibnex_node_data_t */
3012 3012 node_data = ibnex_init_child_nodedata(node_type, port_attr,
3013 3013 index, pkey);
3014 3014 node_data->node_data.port_node.port_pdip = parent;
3015 3015 }
3016 3016
3017 3017 /*
3018 3018 * Return NULL if another unconfigure operation is in progress
3019 3019 */
3020 3020 if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
3021 3021 *rval = IBNEX_BUSY;
3022 3022 return (NULL);
3023 3023 }
3024 3024
3025 3025 ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED);
3026 3026 node_data->node_state = IBNEX_CFGADM_CONFIGURING;
3027 3027
3028 3028 switch (node_type) {
3029 3029 case IBNEX_VPPA_COMMSVC_NODE :
3030 3030 svcname = ibnex.ibnex_vppa_comm_svc_names[index];
3031 3031 port_node = &node_data->node_data.port_node;
3032 3032 (void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s",
3033 3033 IBNEX_IBPORT_CNAME, port_node->port_num,
3034 3034 port_node->port_pkey, svcname);
3035 3035 break;
3036 3036 case IBNEX_HCASVC_COMMSVC_NODE :
3037 3037 svcname = ibnex.ibnex_hcasvc_comm_svc_names[index];
3038 3038 port_node = &node_data->node_data.port_node;
3039 3039 (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
3040 3040 IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
3041 3041 break;
3042 3042 case IBNEX_PORT_COMMSVC_NODE :
3043 3043 svcname = ibnex.ibnex_comm_svc_names[index];
3044 3044 port_node = &node_data->node_data.port_node;
3045 3045 (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
3046 3046 IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
3047 3047 break;
3048 3048 default :
3049 3049 IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:"
3050 3050 "\tInvalid Node type");
3051 3051 *rval = IBNEX_FAILURE;
3052 3052 ibnex_delete_port_node_data(node_data);
3053 3053 return (NULL);
3054 3054 }
3055 3055
3056 3056 if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) {
3057 3057 if (i_ddi_devi_attached(cdip)) {
3058 3058 node_data->node_dip = cdip;
3059 3059 node_data->node_data.port_node.port_pdip = parent;
3060 3060 node_data->node_state = IBNEX_CFGADM_CONFIGURED;
3061 3061 ddi_set_parent_data(cdip, node_data);
3062 3062 IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found "
3063 3063 "attached cdip 0x%p for devname %s", cdip, devname);
3064 3064 return (cdip);
3065 3065 }
3066 3066 } else {
3067 3067 ndi_devi_alloc_sleep(parent,
3068 3068 IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip);
3069 3069 cdip_allocated = 1;
3070 3070 }
3071 3071
3072 3072 node_data->node_dip = cdip;
3073 3073 ddi_set_parent_data(cdip, node_data);
3074 3074 mutex_exit(&ibnex.ibnex_mutex);
3075 3075
3076 3076
3077 3077 if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) ==
3078 3078 IBNEX_SUCCESS) {
3079 3079 if (flag == IBNEX_DEVFS_ENUMERATE)
3080 3080 ret = ndi_devi_bind_driver(cdip, 0);
3081 3081 else
3082 3082 ret = ndi_devi_online(cdip, 0);
3083 3083 if (ret == NDI_SUCCESS) {
3084 3084 mutex_enter(&ibnex.ibnex_mutex);
3085 3085 node_data->node_state = IBNEX_CFGADM_CONFIGURED;
3086 3086 node_data->node_data.port_node.port_pdip = parent;
3087 3087 return (cdip);
3088 3088 }
3089 3089 IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE "
3090 3090 "of cdip 0x%p for devname %s and flag %d failed", cdip,
3091 3091 devname, flag);
3092 3092 }
3093 3093
3094 3094 *rval = IBNEX_FAILURE;
3095 3095 node_data->node_dip = NULL;
3096 3096 ddi_set_parent_data(cdip, NULL);
3097 3097 if (cdip_allocated)
3098 3098 (void) ndi_devi_free(cdip);
3099 3099 mutex_enter(&ibnex.ibnex_mutex);
3100 3100 IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit");
3101 3101 return (NULL);
3102 3102 }
3103 3103
3104 3104
3105 3105 /*
3106 3106 * ibnex_create_port_node_prop()
3107 3107 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
3108 3108 */
3109 3109 static int
3110 3110 ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr,
3111 3111 dev_info_t *child_dip, char *srvname, ib_pkey_t pkey)
3112 3112 {
3113 3113 if (ibnex_create_port_compatible_prop(child_dip,
3114 3114 srvname, port_attr) != DDI_PROP_SUCCESS) {
3115 3115 IBTF_DPRINTF_L2("ibnex",
3116 3116 "\tcreate_port_node_prop: compatible update failed");
3117 3117 return (IBNEX_FAILURE);
3118 3118 }
3119 3119 if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
3120 3120 "port-pkey", pkey) != DDI_PROP_SUCCESS)) {
3121 3121 IBTF_DPRINTF_L2("ibnex",
3122 3122 "\tcreate_port_node_prop: port-num update failed");
3123 3123 return (IBNEX_FAILURE);
3124 3124 }
3125 3125
3126 3126 /*
3127 3127 * For HCA_SVC device nodes, port_num will be 0.
3128 3128 * Do not create the "port-number" & "port-guid" properties.
3129 3129 */
3130 3130 if (port_attr->pa_port_num != 0) {
3131 3131 if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
3132 3132 "port-number", port_attr->pa_port_num) !=
3133 3133 DDI_PROP_SUCCESS) {
3134 3134 IBTF_DPRINTF_L2("ibnex",
3135 3135 "\tcreate_port_node_prop: port-num update failed");
3136 3136 return (IBNEX_FAILURE);
3137 3137 }
3138 3138 if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
3139 3139 "port-guid", port_attr->pa_port_guid) !=
3140 3140 DDI_PROP_SUCCESS) {
3141 3141 IBTF_DPRINTF_L2("ibnex",
3142 3142 "\tcreate_port_node_prop: port-guid update failed");
3143 3143 return (IBNEX_FAILURE);
3144 3144 }
3145 3145 } else {
3146 3146 ibdm_hca_list_t *hca_list;
3147 3147
3148 3148 /*
3149 3149 * HCA_SVC nodes require "num-ports" & "port-guids"
3150 3150 * properties.
3151 3151 *
3152 3152 * To create the num-ports & port-guids attribute :
3153 3153 * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid)
3154 3154 * 2. Form the array of port GUIDs.
3155 3155 */
3156 3156 if ((hca_list = ibdm_ibnex_get_hca_info_by_guid(
3157 3157 port_attr->pa_hca_guid)) == NULL) {
3158 3158 IBTF_DPRINTF_L2("ibnex",
3159 3159 "\tcreate_port_node_prop: hca_info_by_guid failed");
3160 3160 return (IBNEX_FAILURE);
3161 3161 }
3162 3162
3163 3163 if (hca_list->hl_nports != 0) {
3164 3164 ib_guid_t *port_guids;
3165 3165 uint8_t portnum;
3166 3166
3167 3167 ASSERT(hca_list->hl_port_attr != NULL);
3168 3168
3169 3169 port_guids = kmem_zalloc(
3170 3170 hca_list->hl_nports * sizeof (ib_guid_t),
3171 3171 KM_SLEEP);
3172 3172
3173 3173 for (portnum = 0; portnum < hca_list->hl_nports;
3174 3174 portnum++) {
3175 3175 port_guids[portnum] = (hca_list->
3176 3176 hl_port_attr[portnum]).pa_port_guid;
3177 3177 }
3178 3178
3179 3179 if (ndi_prop_update_int64_array(DDI_DEV_T_NONE,
3180 3180 child_dip, "port-guids", (int64_t *)port_guids,
3181 3181 hca_list->hl_nports) != DDI_PROP_SUCCESS) {
3182 3182 IBTF_DPRINTF_L2("ibnex",
3183 3183 "\tcreate_port_node_prop: port-guids "
3184 3184 "create failed");
3185 3185 kmem_free(port_guids, hca_list->hl_nports *
3186 3186 sizeof (ib_guid_t));
3187 3187 ibdm_ibnex_free_hca_list(hca_list);
3188 3188 return (IBNEX_FAILURE);
3189 3189 }
3190 3190 kmem_free(port_guids, hca_list->hl_nports *
3191 3191 sizeof (ib_guid_t));
3192 3192 }
3193 3193
3194 3194 if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
3195 3195 "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) {
3196 3196 IBTF_DPRINTF_L2("ibnex",
3197 3197 "\tcreate_port_node_prop: num-ports update failed");
3198 3198 ibdm_ibnex_free_hca_list(hca_list);
3199 3199 return (IBNEX_FAILURE);
3200 3200 }
3201 3201 ibdm_ibnex_free_hca_list(hca_list);
3202 3202 }
3203 3203
3204 3204 if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
3205 3205 "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) {
3206 3206 IBTF_DPRINTF_L2("ibnex",
3207 3207 "\tcreate_port_node_prop: hca-guid update failed");
3208 3208 return (IBNEX_FAILURE);
3209 3209 }
3210 3210 if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
3211 3211 "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) {
3212 3212 IBTF_DPRINTF_L2("ibnex",
3213 3213 "\tcreate_port_node_prop: product-id update failed");
3214 3214 return (IBNEX_FAILURE);
3215 3215 }
3216 3216 if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
3217 3217 "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) {
3218 3218 IBTF_DPRINTF_L2("ibnex",
3219 3219 "\tcreate_port_node_prop: vendor-id update failed");
3220 3220 return (IBNEX_FAILURE);
3221 3221 }
3222 3222 if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version",
3223 3223 port_attr->pa_dev_version) != DDI_PROP_SUCCESS) {
3224 3224 IBTF_DPRINTF_L2("ibnex",
3225 3225 "\tcreate_port_node_prop: device-version update failed");
3226 3226 return (IBNEX_FAILURE);
3227 3227 }
3228 3228 return (IBNEX_SUCCESS);
3229 3229 }
3230 3230
3231 3231
3232 3232 /*
3233 3233 * ibnex_str2int()
3234 3234 * Utility function that converts a string of length "len" to
3235 3235 * integer.
3236 3236 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
3237 3237 */
3238 3238 int
3239 3239 ibnex_str2int(char *c, int len, int *ret)
3240 3240 {
3241 3241 int intval = 0, ii;
3242 3242
3243 3243 IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c);
3244 3244 *ret = IBNEX_SUCCESS;
3245 3245 for (ii = 0; ii < len; ii ++) {
3246 3246 if ((c[ii] >= '0') && (c[ii] <= '9'))
3247 3247 intval = intval * 10 +c[ii] - '0';
3248 3248 else {
3249 3249 IBTF_DPRINTF_L2("ibnex",
3250 3250 "\tstr2int: Invalid integer string %s..", c);
3251 3251 *ret = IBNEX_FAILURE;
3252 3252 break;
3253 3253 }
3254 3254 }
3255 3255
3256 3256 return (intval);
3257 3257 }
3258 3258
3259 3259
3260 3260 /*
3261 3261 * ibnex_str2hex()
3262 3262 * Utility functions that converts a string of length "len" to
3263 3263 * hex value. Note. This function does not handle strings which
3264 3264 * string length more than 8 bytes.
3265 3265 *
3266 3266 */
3267 3267 uint64_t
3268 3268 ibnex_str2hex(char *c, int len, int *ret)
3269 3269 {
3270 3270 uint64_t hex = 0, ii;
3271 3271
3272 3272 *ret = IBNEX_SUCCESS;
3273 3273 for (ii = 0; ii < len; ii ++) {
3274 3274 hex = (ii == 0) ? hex : (hex << 4);
3275 3275 if ((c[ii] >= '0') && (c[ii] <= '9'))
3276 3276 hex |= c[ii] - '0';
3277 3277 else if ((c[ii] >= 'a') && (c[ii] <= 'f'))
3278 3278 hex |= c[ii] - 'a' + 10;
3279 3279 else if ((c[ii] >= 'A') && (c[ii] <= 'F'))
3280 3280 hex |= c[ii] - 'A' + 10;
3281 3281 else {
3282 3282 IBTF_DPRINTF_L2("ibnex",
3283 3283 "\tstr2hex: Invalid integer string");
3284 3284 *ret = IBNEX_FAILURE;
3285 3285 break;
3286 3286 }
3287 3287 }
3288 3288
3289 3289 return (hex);
3290 3290 }
3291 3291
3292 3292
3293 3293 /*
3294 3294 * ibnex_create_port_compatible_prop()
3295 3295 * Creates 'Compatibility' property for port / HCA_SVC device nodes
3296 3296 * Returns IBNEX_SUCCESS/IBNEX_FAILURE
3297 3297 */
3298 3298 static int
3299 3299 ibnex_create_port_compatible_prop(dev_info_t *child_dip,
3300 3300 char *comm_svcp, ibdm_port_attr_t *port_attr)
3301 3301 {
3302 3302 int rval, i;
3303 3303 char *temp;
3304 3304 char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES];
3305 3305
3306 3306 IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin");
3307 3307 /*
3308 3308 * Initialize the "compatible" property string as below:
3309 3309 * Compatible Strings :
3310 3310 * 1. ib.V<vid>P<pid>v<revision>.<service name>.
3311 3311 * 2. ib.V<vid>P<pid>.<service name>.
3312 3312 * 3. ib.<service name>
3313 3313 * Leading zeros must be present
3314 3314 */
3315 3315 temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP);
3316 3316 for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) {
3317 3317 compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN);
3318 3318 }
3319 3319
3320 3320 (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
3321 3321 "ib.V%06xP%08xv%04x.%s",
3322 3322 port_attr->pa_vendorid, port_attr->pa_productid,
3323 3323 port_attr->pa_dev_version, comm_svcp);
3324 3324 (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
3325 3325 "ib.V%06xP%08x.%s",
3326 3326 port_attr->pa_vendorid, port_attr->pa_productid,
3327 3327 comm_svcp);
3328 3328 (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
3329 3329 "ib.%s", comm_svcp);
3330 3330
3331 3331 for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++)
3332 3332 IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]);
3333 3333
3334 3334 rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip,
3335 3335 "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES);
3336 3336
3337 3337 if (rval != DDI_PROP_SUCCESS) {
3338 3338 kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
3339 3339 return (IBNEX_FAILURE);
3340 3340 }
3341 3341 kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
3342 3342 return (IBNEX_SUCCESS);
3343 3343 }
3344 3344
3345 3345
3346 3346 /*
3347 3347 * ibnex_delete_port_node_data()
3348 3348 * Delete the parent private node data from the linked list
3349 3349 * Deallocate the memory of the port/ioc attributes
3350 3350 * Deallocate the memory of the node data
3351 3351 */
3352 3352 static void
3353 3353 ibnex_delete_port_node_data(ibnex_node_data_t *node)
3354 3354 {
3355 3355 if ((node->node_next == NULL) && (node->node_prev == NULL))
3356 3356 ibnex.ibnex_port_node_head = NULL;
3357 3357 else if (node->node_next == NULL)
3358 3358 node->node_prev->node_next = NULL;
3359 3359 else if (node->node_prev == NULL) {
3360 3360 node->node_next->node_prev = NULL;
3361 3361 ibnex.ibnex_port_node_head = node->node_next;
3362 3362 } else {
3363 3363 node->node_prev->node_next = node->node_next;
3364 3364 node->node_next->node_prev = node->node_prev;
3365 3365 }
3366 3366 kmem_free(node, sizeof (ibnex_node_data_t));
3367 3367 }
3368 3368
3369 3369
3370 3370 /*
3371 3371 * ibnex_is_node_data_present()
3372 3372 * Checks whether ibnex_node_t is created already
3373 3373 * Returns ibnex_node_data_t if found, otherwise NULL
3374 3374 */
3375 3375 static ibnex_node_data_t *
3376 3376 ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr,
3377 3377 int index, ib_pkey_t pkey)
3378 3378 {
3379 3379 ibnex_node_data_t *nodep;
3380 3380 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
3381 3381 if (node_type == IBNEX_IOC_NODE) {
3382 3382 ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr;
3383 3383
3384 3384 for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL;
3385 3385 nodep = nodep->node_next) {
3386 3386 if (nodep->node_data.ioc_node.ioc_guid ==
3387 3387 ioc_infop->ioc_profile.ioc_guid) {
3388 3388 return (nodep);
3389 3389 }
3390 3390 }
3391 3391
3392 3392 } else if (node_type == IBNEX_PSEUDO_NODE) {
3393 3393 for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
3394 3394 nodep = nodep->node_next)
3395 3395 if (strcmp(nodep->node_data.pseudo_node.
3396 3396 pseudo_node_addr, (char *)attr) == 0)
3397 3397 return (nodep);
3398 3398
3399 3399 } else {
3400 3400 ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr;
3401 3401
3402 3402 for (nodep = ibnex.ibnex_port_node_head; nodep != NULL;
3403 3403 nodep = nodep->node_next) {
3404 3404 if ((nodep->node_data.port_node.port_guid ==
3405 3405 pattrp->pa_port_guid) &&
3406 3406 (nodep->node_data.port_node.port_commsvc_idx ==
3407 3407 index) &&
3408 3408 (nodep->node_data.port_node.port_pkey == pkey)) {
3409 3409 return (nodep);
3410 3410 }
3411 3411 }
3412 3412 }
3413 3413 return (NULL);
3414 3414 }
3415 3415
3416 3416 /*
3417 3417 * ibnex_lookup_unit_address_prop:
3418 3418 *
3419 3419 * If property with name is found, return its value
3420 3420 * otherwise return NULL.
3421 3421 */
3422 3422 static char *
3423 3423 ibnex_lookup_named_prop(ddi_prop_t *head, char *name)
3424 3424 {
3425 3425 ddi_prop_t *propp;
3426 3426
3427 3427 /* Search the list of properties for name */
3428 3428 for (propp = head; propp != NULL; propp = propp->prop_next) {
3429 3429 if (strcmp(propp->prop_name, name) != 0)
3430 3430 continue;
3431 3431 /* named property should be valid and have a value */
3432 3432 if (propp->prop_len <= 1)
3433 3433 break;
3434 3434 return ((char *)propp->prop_val);
3435 3435 }
3436 3436
3437 3437 return ((char *)0);
3438 3438 }
3439 3439
3440 3440
3441 3441 /*
3442 3442 * ibnex_pseudo_initnodes()
3443 3443 * This routine is specific to pseudo node information handling
3444 3444 * Creates a ibnex_node_data_t all pseudo nodes children of ibnex
3445 3445 */
3446 3446 void
3447 3447 ibnex_pseudo_initnodes()
3448 3448 {
3449 3449 int pnam_len, len;
3450 3450 ibnex_node_data_t *nodep;
3451 3451 struct hwc_spec *list, *spec;
3452 3452 char *node_addr, *temp, *unit_addr;
3453 3453 char *node_type;
3454 3454
3455 3455 IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes");
3456 3456
3457 3457 mutex_enter(&ibnex.ibnex_mutex);
3458 3458 /*
3459 3459 * get a list of all "pseudo" children of "ib".
3460 3460 * for these children initialize/allocate an internal
3461 3461 * ibnex_node_data_t.
3462 3462 */
3463 3463 list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1);
3464 3464 for (spec = list; spec != NULL; spec = spec->hwc_next) {
3465 3465 if (spec->hwc_devi_sys_prop_ptr == NULL)
3466 3466 continue;
3467 3467
3468 3468 /* Check "ib-node-type" property for IOC .conf */
3469 3469 node_type = ibnex_lookup_named_prop(
3470 3470 spec->hwc_devi_sys_prop_ptr, "ib-node-type");
3471 3471
3472 3472 /* "unit-address" property should be present */
3473 3473 temp = ibnex_lookup_named_prop(
3474 3474 spec->hwc_devi_sys_prop_ptr, "unit-address");
3475 3475 if (temp == NULL)
3476 3476 continue;
3477 3477
3478 3478 pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2;
3479 3479
3480 3480 node_addr = kmem_zalloc(pnam_len, KM_SLEEP);
3481 3481
3482 3482 (void) snprintf(node_addr,
3483 3483 pnam_len, "%s,%s", spec->hwc_devi_name, temp);
3484 3484
3485 3485 nodep = ibnex_is_node_data_present(
3486 3486 IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0);
3487 3487
3488 3488 if (nodep) {
3489 3489 kmem_free(node_addr, pnam_len);
3490 3490 continue;
3491 3491 }
3492 3492
3493 3493 nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE,
3494 3494 (void *)spec->hwc_devi_name, 0, 0);
3495 3495
3496 3496 nodep->node_data.pseudo_node.pseudo_node_addr = node_addr;
3497 3497 (void) snprintf(nodep->node_data.
3498 3498 pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr);
3499 3499
3500 3500 len = strlen(temp) + 1;
3501 3501 unit_addr = (char *)kmem_alloc(len, KM_SLEEP);
3502 3502 nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr;
3503 3503 (void) snprintf(unit_addr, len, "%s", temp);
3504 3504 nodep->node_data.pseudo_node.pseudo_unit_addr_len = len;
3505 3505
3506 3506 if (node_type && strcmp(node_type, "merge") == 0)
3507 3507 nodep->node_data.pseudo_node.pseudo_merge_node = 1;
3508 3508
3509 3509 IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s"
3510 3510 " : drv name = %s", unit_addr, spec->hwc_devi_name);
3511 3511 }
3512 3512 hwc_free_spec_list(list);
3513 3513 mutex_exit(&ibnex.ibnex_mutex);
3514 3514 }
3515 3515
3516 3516
3517 3517 /*
3518 3518 * ibnex_init_child_nodedata()
3519 3519 *
3520 3520 * Allocate memory for the parent private data for device node
3521 3521 * Initializes the parent private child device node data.
3522 3522 * Returns pointer to the parent private data
3523 3523 */
3524 3524 static ibnex_node_data_t *
3525 3525 ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index,
3526 3526 ib_pkey_t pkey)
3527 3527 {
3528 3528 char *devi_name;
3529 3529 ibdm_ioc_info_t *ioc_info;
3530 3530 ibnex_ioc_node_t *ioc_node;
3531 3531 ibnex_node_data_t *node_data;
3532 3532 ib_dm_ioc_ctrl_profile_t *ioc_profile;
3533 3533
3534 3534 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
3535 3535
3536 3536 node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP);
3537 3537 node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED;
3538 3538 node_data->node_state = IBNEX_CFGADM_CONFIGURING;
3539 3539 node_data->node_type = node_type;
3540 3540
3541 3541 if (node_type == IBNEX_IOC_NODE) {
3542 3542 ioc_info = (ibdm_ioc_info_t *)attr;
3543 3543 ioc_profile = &ioc_info->ioc_profile;
3544 3544 ioc_node = &node_data->node_data.ioc_node;
3545 3545
3546 3546 ioc_node->iou_guid = ioc_info->ioc_iou_guid;
3547 3547 ioc_node->ioc_guid = ioc_profile->ioc_guid;
3548 3548 (void) strncpy(ioc_node->ioc_id_string,
3549 3549 (char *)ioc_profile->ioc_id_string,
3550 3550 IB_DM_IOC_ID_STRING_LEN);
3551 3551 ioc_node->ioc_ngids = ioc_info->ioc_nportgids;
3552 3552
3553 3553 node_data->node_next = ibnex.ibnex_ioc_node_head;
3554 3554 node_data->node_prev = NULL;
3555 3555 if (ibnex.ibnex_ioc_node_head)
3556 3556 ibnex.ibnex_ioc_node_head->node_prev = node_data;
3557 3557 ibnex.ibnex_ioc_node_head = node_data;
3558 3558 } else if (node_type == IBNEX_PSEUDO_NODE) {
3559 3559 devi_name = (char *)attr;
3560 3560 node_data->node_data.pseudo_node.pseudo_devi_name =
3561 3561 kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP);
3562 3562 (void) strncpy(node_data->node_data.pseudo_node.
3563 3563 pseudo_devi_name, devi_name, strlen(devi_name));
3564 3564 node_data->node_next = ibnex.ibnex_pseudo_node_head;
3565 3565 node_data->node_prev = NULL;
3566 3566 if (ibnex.ibnex_pseudo_node_head)
3567 3567 ibnex.ibnex_pseudo_node_head->node_prev = node_data;
3568 3568 ibnex.ibnex_pseudo_node_head = node_data;
3569 3569 } else {
3570 3570 node_data->node_data.port_node.port_hcaguid =
3571 3571 ((ibdm_port_attr_t *)attr)->pa_hca_guid;
3572 3572 node_data->node_data.port_node.port_guid =
3573 3573 ((ibdm_port_attr_t *)attr)->pa_port_guid;
3574 3574 node_data->node_data.port_node.port_num =
3575 3575 ((ibdm_port_attr_t *)attr)->pa_port_num;
3576 3576 node_data->node_data.port_node.port_commsvc_idx = index;
3577 3577 node_data->node_data.port_node.port_pkey = pkey;
3578 3578
3579 3579 node_data->node_next = ibnex.ibnex_port_node_head;
3580 3580 node_data->node_prev = NULL;
3581 3581 if (ibnex.ibnex_port_node_head)
3582 3582 ibnex.ibnex_port_node_head->node_prev = node_data;
3583 3583 ibnex.ibnex_port_node_head = node_data;
3584 3584 }
3585 3585 return (node_data);
3586 3586 }
3587 3587
3588 3588 static int
3589 3589 ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
3590 3590 char *eventname, ddi_eventcookie_t *cookie)
3591 3591 {
3592 3592 int rc;
3593 3593
3594 3594
3595 3595 IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)",
3596 3596 dip, rdip, eventname, cookie);
3597 3597
3598 3598 rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl,
3599 3599 rdip, eventname, cookie, NDI_EVENT_NOPASS);
3600 3600 if (rc == NDI_SUCCESS) {
3601 3601 mutex_enter(&ibnex.ibnex_mutex);
3602 3602 ibnex.ibnex_prop_update_evt_cookie = *cookie;
3603 3603 mutex_exit(&ibnex.ibnex_mutex);
3604 3604 }
3605 3605
3606 3606 return (rc);
3607 3607 }
3608 3608
3609 3609 static int
3610 3610 ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
3611 3611 ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip,
3612 3612 ddi_eventcookie_t cookie, void *arg, void *bus_impldata),
3613 3613 void *arg, ddi_callback_id_t *cb_id)
3614 3614 {
3615 3615 IBTF_DPRINTF_L4("ibnex",
3616 3616 "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)",
3617 3617 dip, rdip, cookie, callback, arg, cb_id);
3618 3618
3619 3619 return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl,
3620 3620 rdip, cookie, callback, arg, NDI_SLEEP, cb_id));
3621 3621 }
3622 3622
3623 3623 static int
3624 3624 ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
3625 3625 {
3626 3626 IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)",
3627 3627 dip, cb_id);
3628 3628
3629 3629 return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl,
3630 3630 cb_id));
3631 3631 }
3632 3632
3633 3633 static int
3634 3634 ibnex_post_event(dev_info_t *dip, dev_info_t *rdip,
3635 3635 ddi_eventcookie_t cookie, void *bus_impldata)
3636 3636 {
3637 3637 IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)",
3638 3638 dip, rdip, cookie, bus_impldata);
3639 3639
3640 3640 return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip,
3641 3641 cookie, bus_impldata));
3642 3642 }
3643 3643
3644 3644 /*
3645 3645 * ibnex_reprobe_ioc_dev()
3646 3646 *
3647 3647 * This could be called as a result of ibt_reprobe_dev request or
3648 3648 * cfgadm command. The function is called from a taskq in case of
3649 3649 * ibt_reprobe_dev and from user context for cfgadm command.
3650 3650 *
3651 3651 * This function reprobes the properties for one IOC dip.
3652 3652 *
3653 3653 * node_reprobe_state should be set before calling this function.
3654 3654 */
3655 3655 void
3656 3656 ibnex_reprobe_ioc_dev(void *arg)
3657 3657 {
3658 3658 dev_info_t *dip = (dev_info_t *)arg;
3659 3659 ibnex_node_data_t *node_data;
3660 3660 ibnex_ioc_node_t *ioc_data;
3661 3661 ibdm_ioc_info_t *ioc_info;
3662 3662
3663 3663 /* ASSERT(NO_LOCKS_HELD); */
3664 3664 ASSERT(dip != NULL);
3665 3665
3666 3666 node_data = ddi_get_parent_data(dip);
3667 3667 ASSERT(node_data);
3668 3668
3669 3669 if (node_data->node_dip == NULL) {
3670 3670 IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip");
3671 3671 mutex_enter(&ibnex.ibnex_mutex);
3672 3672 ibnex_wakeup_reprobe_ioc(node_data, 0);
3673 3673 mutex_exit(&ibnex.ibnex_mutex);
3674 3674 return;
3675 3675 }
3676 3676 ioc_data = &(node_data->node_data.ioc_node);
3677 3677
3678 3678 /* Reprobe the IOC */
3679 3679 ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid,
3680 3680 1);
3681 3681 if (ioc_info == NULL) {
3682 3682 IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe");
3683 3683 mutex_enter(&ibnex.ibnex_mutex);
3684 3684 ibnex_wakeup_reprobe_ioc(node_data, 1);
3685 3685 mutex_exit(&ibnex.ibnex_mutex);
3686 3686 return;
3687 3687 }
3688 3688
3689 3689 mutex_enter(&ibnex.ibnex_mutex);
3690 3690 if (node_data->node_dip)
3691 3691 ibnex_update_prop(node_data, ioc_info);
3692 3692 ibnex_wakeup_reprobe_ioc(node_data, 0);
3693 3693 mutex_exit(&ibnex.ibnex_mutex);
3694 3694
3695 3695 ibdm_ibnex_free_ioc_list(ioc_info);
3696 3696 }
3697 3697
3698 3698 /*
3699 3699 * ibnex_reprobe_all()
3700 3700 *
3701 3701 * This could be called as a result of cfgadm command. The function
3702 3702 * is called from user context.
3703 3703 *
3704 3704 * This function reprobes the properties for all IOC dips.
3705 3705 *
3706 3706 * ibnex_reprobe_state should be set before calling this function.
3707 3707 */
3708 3708 void
3709 3709 ibnex_reprobe_ioc_all()
3710 3710 {
3711 3711 ibnex_node_data_t *node_data;
3712 3712 ibdm_ioc_info_t *ioc_info_list, *ioc;
3713 3713
3714 3714 /* ASSERT(NO_LOCKS_HELD); */
3715 3715
3716 3716 /* Sweep the fabric */
3717 3717 ioc = ioc_info_list = ibdm_ibnex_get_ioc_list(
3718 3718 IBDM_IBNEX_REPROBE_ALL);
3719 3719 if (ioc_info_list == NULL) {
3720 3720 mutex_enter(&ibnex.ibnex_mutex);
3721 3721 ibnex_wakeup_reprobe_all();
3722 3722 mutex_exit(&ibnex.ibnex_mutex);
3723 3723 return;
3724 3724 }
3725 3725
3726 3726 mutex_enter(&ibnex.ibnex_mutex);
3727 3727 while (ioc_info_list) {
3728 3728 if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
3729 3729 ioc_info_list, 0, 0)) != NULL &&
3730 3730 node_data->node_dip != NULL) {
3731 3731 ibnex_update_prop(node_data, ioc_info_list);
3732 3732 }
3733 3733 ioc_info_list = ioc_info_list->ioc_next;
3734 3734 }
3735 3735 ibnex_wakeup_reprobe_all();
3736 3736 mutex_exit(&ibnex.ibnex_mutex);
3737 3737
3738 3738 ibdm_ibnex_free_ioc_list(ioc);
3739 3739 }
3740 3740
3741 3741 /*
3742 3742 * Update the properties, if it has modified and notify IBTF client.
3743 3743 */
3744 3744 static void
3745 3745 ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info)
3746 3746 {
3747 3747 ibt_prop_update_payload_t evt_data;
3748 3748 dev_info_t *dip = node_data->node_dip;
3749 3749 ddi_eventcookie_t evt_cookie;
3750 3750 ibnex_ioc_node_t *ioc;
3751 3751
3752 3752 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
3753 3753
3754 3754 ASSERT(dip != NULL);
3755 3755
3756 3756 ioc = &node_data->node_data.ioc_node;
3757 3757
3758 3758 evt_data = ioc_info->ioc_info_updated;
3759 3759 evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
3760 3760
3761 3761 /*
3762 3762 * For a disconnected IOC :
3763 3763 * Store the ioc_profile for supplying cfgadm info
3764 3764 * ibdm maintains no info of disconnected IOC
3765 3765 *
3766 3766 * For reconnected IOC :
3767 3767 * ibdm has info of previous service entries
3768 3768 * ioc_profile maintained by ibnexus is used to
3769 3769 * update ib_srv_prop_updated.
3770 3770 * Free the ibnex maintained ioc_profile
3771 3771 */
3772 3772 if (ioc_info->ioc_nportgids == 0) {
3773 3773 IBTF_DPRINTF_L4("ibnex",
3774 3774 "\tupdate_prop: IOC disconnected");
3775 3775 ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc(
3776 3776 sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP);
3777 3777 bcopy(&ioc_info->ioc_profile, ioc->ioc_profile,
3778 3778 sizeof (ib_dm_ioc_ctrl_profile_t));
3779 3779
3780 3780 ibnex.ibnex_num_disconnect_iocs++;
3781 3781 } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 &&
3782 3782 ioc->ioc_profile != NULL) {
3783 3783 IBTF_DPRINTF_L4("ibnex",
3784 3784 "\tupdate_prop: IOC reconnected");
3785 3785 if (ioc->ioc_profile->ioc_service_entries !=
3786 3786 ioc_info->ioc_profile.ioc_service_entries)
3787 3787 evt_data.ib_srv_prop_updated = 1;
3788 3788
3789 3789 ibnex.ibnex_num_disconnect_iocs--;
3790 3790 kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t));
3791 3791 ioc->ioc_profile = NULL;
3792 3792 }
3793 3793
3794 3794 /* Update the properties that have changed */
3795 3795 mutex_exit(&ibnex.ibnex_mutex);
3796 3796 if (evt_data.ib_gid_prop_updated) {
3797 3797 if (ibnex_create_ioc_portgid_prop(dip, ioc_info) !=
3798 3798 IBNEX_SUCCESS) {
3799 3799 mutex_enter(&ibnex.ibnex_mutex);
3800 3800 return;
3801 3801 }
3802 3802 }
3803 3803 if (evt_data.ib_srv_prop_updated) {
3804 3804 if (ioc_info->ioc_profile.ioc_service_entries != 0 &&
3805 3805 (ibnex_create_ioc_srv_props(dip, ioc_info) !=
3806 3806 IBNEX_SUCCESS)) {
3807 3807 mutex_enter(&ibnex.ibnex_mutex);
3808 3808 return;
3809 3809 } else if (ioc_info->ioc_profile.ioc_service_entries == 0) {
3810 3810 (void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
3811 3811 "service-id");
3812 3812 (void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
3813 3813 "service-name");
3814 3814 }
3815 3815 }
3816 3816 mutex_enter(&ibnex.ibnex_mutex);
3817 3817 ioc->ioc_ngids = ioc_info->ioc_nportgids;
3818 3818
3819 3819 /*
3820 3820 * Post an event if :
3821 3821 * 1. Properites have changed or NOTIFY_ALWAYS is set.
3822 3822 * 2. child dip is configured and a valid cookie for
3823 3823 * IB_PROP_UPDATE_EVENT.
3824 3824 */
3825 3825 if ((evt_data.ib_prop_updated != 0 ||
3826 3826 (node_data->node_reprobe_state &
3827 3827 IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) &&
3828 3828 ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) &&
3829 3829 (evt_cookie != NULL))) {
3830 3830 mutex_exit(&ibnex.ibnex_mutex);
3831 3831
3832 3832 if (ndi_post_event(ibnex.ibnex_dip, dip,
3833 3833 evt_cookie, &evt_data) != NDI_SUCCESS)
3834 3834 IBTF_DPRINTF_L2("ibnex",
3835 3835 "\tndi_post_event failed\n");
3836 3836
3837 3837 mutex_enter(&ibnex.ibnex_mutex);
3838 3838 }
3839 3839
3840 3840 /*
3841 3841 * Cleanup node_reprobe_state, for ibt_reprobe_dev
3842 3842 * requests, when reprobe all / node reprobe is in
3843 3843 * progress. ibnex_reprobe_ioc_dev is not called
3844 3844 * in this case.
3845 3845 */
3846 3846 if (node_data->node_reprobe_state ==
3847 3847 IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)
3848 3848 ibnex_wakeup_reprobe_ioc(node_data, 0);
3849 3849 }
3850 3850
3851 3851 static ibnex_rval_t
3852 3852 ibnex_unique_svcname(char *svcname)
3853 3853 {
3854 3854 int i;
3855 3855
3856 3856 /* Check Port Services */
3857 3857 for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++)
3858 3858 if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname,
3859 3859 ibnex.ibnex_comm_svc_names[i], 4) == 0)
3860 3860 return (IBNEX_FAILURE);
3861 3861
3862 3862 /* Check VPPA Services */
3863 3863 for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++)
3864 3864 if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname,
3865 3865 ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0)
3866 3866 return (IBNEX_FAILURE);
3867 3867
3868 3868 /* Check HCA_SVC Services */
3869 3869 for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++)
3870 3870 if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname,
3871 3871 ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0)
3872 3872 return (IBNEX_FAILURE);
3873 3873
3874 3874 return (IBNEX_SUCCESS);
3875 3875 }
3876 3876
3877 3877 static void
3878 3878 ibnex_handle_reprobe_dev(void *arg)
3879 3879 {
3880 3880 dev_info_t *dip = (dev_info_t *)arg;
3881 3881 ibnex_node_data_t *node_data;
3882 3882
3883 3883 ASSERT(dip != NULL);
3884 3884 node_data = ddi_get_parent_data(dip);
3885 3885 ASSERT(node_data);
3886 3886
3887 3887 /*
3888 3888 * Return success if:
3889 3889 * 1. Reprobe for all nodes are in progress
3890 3890 * 2. Reprobe for this node is in progress.
3891 3891 * The reprobe in progress will complete eventually and
3892 3892 * update the properties, if required.
3893 3893 */
3894 3894 mutex_enter(&ibnex.ibnex_mutex);
3895 3895 if (ibnex.ibnex_reprobe_state != 0 ||
3896 3896 node_data->node_reprobe_state != 0) {
3897 3897 /*
3898 3898 * Setting NOTIFY_ALWAYS to ensure that
3899 3899 * DDI event is delivered always for
3900 3900 * ibt_reprobe_dev
3901 3901 */
3902 3902 node_data->node_reprobe_state |=
3903 3903 IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
3904 3904 mutex_exit(&ibnex.ibnex_mutex);
3905 3905 return;
3906 3906 }
3907 3907 node_data->node_reprobe_state =
3908 3908 IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
3909 3909 mutex_exit(&ibnex.ibnex_mutex);
3910 3910 ibnex_reprobe_ioc_dev(arg);
3911 3911 }
3912 3912
3913 3913
3914 3914 /*
3915 3915 * MPxIO pathmangement routines. Currently IB nexus does not support
3916 3916 * any kind of pathmangement. So, just return success to make MPxIO
3917 3917 * framework happy.
3918 3918 */
3919 3919 /*ARGSUSED*/
3920 3920 static int
3921 3921 ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
3922 3922 {
3923 3923 IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip);
3924 3924 return (MDI_SUCCESS);
3925 3925 }
3926 3926
3927 3927
3928 3928 /*ARGSUSED*/
3929 3929 static int
3930 3930 ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
3931 3931 {
3932 3932 dev_info_t *cdip;
3933 3933 ibnex_node_data_t *node_data;
3934 3934 int clnt_num_pi;
3935 3935 IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip);
3936 3936
3937 3937 if (pip == NULL)
3938 3938 return (MDI_FAILURE);
3939 3939 /*
3940 3940 * Get the Client dev_info from the pathinfo.
3941 3941 */
3942 3942 cdip = mdi_pi_get_client(pip);
3943 3943 if (cdip == NULL)
3944 3944 return (MDI_FAILURE);
3945 3945
3946 3946 /*
3947 3947 * How many PIs do we have from this cdip ?
3948 3948 */
3949 3949 clnt_num_pi = mdi_client_get_path_count(cdip);
3950 3950
3951 3951 /*
3952 3952 * If this is the last PI that is being free'd ( called from
3953 3953 * mdi_pi_free) we have to clean up the node data for the cdip since
3954 3954 * the client would have been detached by mdi_devi_offline.
3955 3955 */
3956 3956 if (clnt_num_pi == 1) {
3957 3957 node_data = ddi_get_parent_data(cdip);
3958 3958 if (node_data == NULL)
3959 3959 return (MDI_SUCCESS);
3960 3960 if (node_data->node_dip == cdip) {
3961 3961 node_data->node_dip = NULL;
3962 3962 node_data->node_state = IBNEX_CFGADM_UNCONFIGURED;
3963 3963 return (MDI_SUCCESS);
3964 3964 }
3965 3965 }
3966 3966 return (MDI_SUCCESS);
3967 3967 }
3968 3968
3969 3969
3970 3970 /*ARGSUSED*/
3971 3971 static int
3972 3972 ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip,
3973 3973 mdi_pathinfo_state_t state, uint32_t arg1, int arg2)
3974 3974 {
3975 3975 IBTF_DPRINTF_L4("ibnex",
3976 3976 "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state);
3977 3977 return (MDI_SUCCESS);
3978 3978 }
3979 3979
3980 3980
3981 3981 /*ARGSUSED*/
3982 3982 static int
3983 3983 ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg)
3984 3984 {
3985 3985 return (MDI_SUCCESS);
3986 3986 }
3987 3987
3988 3988
3989 3989 static int
3990 3990 ibnex_bus_power(dev_info_t *parent, void *impl_arg,
3991 3991 pm_bus_power_op_t op, void *arg, void *result)
3992 3992 {
3993 3993
3994 3994 int ret = DDI_SUCCESS;
3995 3995
3996 3996 IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op);
3997 3997
3998 3998 /*
3999 3999 * Generic processing in MPxIO framework
4000 4000 */
4001 4001 ret = mdi_bus_power(parent, impl_arg, op, arg, result);
4002 4002
4003 4003 switch (ret) {
4004 4004 case MDI_SUCCESS:
4005 4005 ret = DDI_SUCCESS;
4006 4006 break;
4007 4007 case MDI_FAILURE:
4008 4008 ret = DDI_FAILURE;
4009 4009 break;
4010 4010 default:
4011 4011 break;
4012 4012 }
4013 4013
4014 4014 return (ret);
4015 4015 }
4016 4016
4017 4017
4018 4018 /*
4019 4019 * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config.
4020 4020 * ndi_devi_enter is not held during this call. mdi_vhci_bus_config()
4021 4021 * will have called ndi_busop_bus_config(), no need for the caller to call
4022 4022 * ndi_busop_bus_config() again.
4023 4023 *
4024 4024 * If enumerated as a child of HCA device, this could be a case for
4025 4025 * Sparc boot or device enumeration from PHCI, driven by MDI.
4026 4026 * Hold parent lock (ndi_devi_enter). The caller will have to call
4027 4027 * ndi_busop_bus_config() if this function returns SUCCESS.
4028 4028 *
4029 4029 * if the device name contains ":port", then it is the Sparc boot case.
4030 4030 * Handle this as before.
4031 4031 *
4032 4032 * If the device name does *not* contain the ":port", then :
4033 4033 * 1. ibdm to probe IOC
4034 4034 * 2. Create a pathinfo only if the IOC is reachable from the parent dip.
4035 4035 */
4036 4036 int
4037 4037 ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag,
4038 4038 ddi_bus_config_op_t op, void *devname, dev_info_t **child,
4039 4039 int *need_bus_config)
4040 4040 {
4041 4041 int ret = DDI_FAILURE, circ;
4042 4042 dev_info_t *pdip = *pdipp;
4043 4043 ib_guid_t iou_guid, ioc_guid;
4044 4044 char *ioc_guid_str;
4045 4045
4046 4046
4047 4047 *need_bus_config = 1;
4048 4048
4049 4049 if (pdip == ibnex.ibnex_dip) {
4050 4050 if (ibnex_devname_to_node_n_ioc_guids(
4051 4051 (char *)devname, &iou_guid, &ioc_guid,
4052 4052 &ioc_guid_str) != IBNEX_SUCCESS) {
4053 4053 return (ret);
4054 4054 }
4055 4055 ret = mdi_vhci_bus_config(pdip, flag, op, devname, child,
4056 4056 ioc_guid_str);
4057 4057 kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1);
4058 4058 if (ret == MDI_SUCCESS)
4059 4059 *need_bus_config = 0;
4060 4060 } else {
4061 4061 mdi_devi_enter(pdip, &circ);
4062 4062 if (strstr((char *)devname, ":port=") != NULL) {
4063 4063 ret = ibnex_config_root_iocnode(pdip, devname);
4064 4064 ASSERT(ibnex.ibnex_dip == NULL);
4065 4065 *pdipp = ibnex.ibnex_dip;
4066 4066 } else {
4067 4067 ret = ibnex_config_ioc_node(devname, pdip);
4068 4068 }
4069 4069 mdi_devi_exit(pdip, circ);
4070 4070 }
4071 4071 return (ret);
4072 4072 }
4073 4073
4074 4074 static int
4075 4075 ibnex_is_merge_node(dev_info_t *child)
4076 4076 {
4077 4077 char *node;
4078 4078 int ret = IBNEX_INVALID_NODE;
4079 4079
4080 4080 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child,
4081 4081 DDI_PROP_DONTPASS, "ib-node-type", &node) !=
4082 4082 DDI_PROP_SUCCESS) {
4083 4083 return (IBNEX_FAILURE);
4084 4084 }
4085 4085
4086 4086 if (node != NULL && *node != 0) {
4087 4087 if (strcmp(node, "merge") == 0)
4088 4088 ret = IBNEX_SUCCESS;
4089 4089 else {
4090 4090 IBTF_DPRINTF_L4("ibnex",
4091 4091 "\tis_merge_node: ib-node-type = %s", node);
4092 4092 }
4093 4093 }
4094 4094
4095 4095 ddi_prop_free(node);
4096 4096 return (ret);
4097 4097 }
4098 4098
4099 4099 /*
4100 4100 * Checks if the dn_head for the driver has already
4101 4101 * initialized by the prom tree.
4102 4102 */
4103 4103 void
4104 4104 ibnex_hw_in_dev_tree(char *driver_name)
4105 4105 {
4106 4106 major_t major;
4107 4107
4108 4108 IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name);
4109 4109
4110 4110 if (devnamesp == NULL)
4111 4111 return;
4112 4112
4113 4113 major = ddi_name_to_major(driver_name);
4114 4114 if (major == -1)
4115 4115 return;
4116 4116
4117 4117 if (devnamesp[major].dn_head != (dev_info_t *)NULL)
4118 4118 ibnex_hw_status = IBNEX_HW_IN_DEVTREE;
4119 4119 }
4120 4120
4121 4121 int
4122 4122 ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info)
4123 4123 {
4124 4124 ibdm_hca_list_t *hca_list;
4125 4125 dev_info_t *hca_dip;
4126 4126 int rc = IBNEX_FAILURE;
4127 4127
4128 4128 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
4129 4129 /*
4130 4130 * We return failure even if we fail for all HCAs
4131 4131 */
4132 4132 for (hca_list = ioc_info->ioc_hca_list; hca_list;
4133 4133 hca_list = hca_list->hl_next) {
4134 4134 hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
4135 4135 if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) ==
4136 4136 IBNEX_SUCCESS)
4137 4137 rc = IBNEX_SUCCESS;
4138 4138 }
4139 4139 return (rc);
4140 4140 }
4141 4141
4142 4142 static int
4143 4143 ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip,
4144 4144 int pdip_reachable_checked)
4145 4145 {
4146 4146 ibnex_node_data_t *node_data;
4147 4147 int create_pdip = 0;
4148 4148 int rc = IBNEX_SUCCESS;
4149 4149
4150 4150
4151 4151 ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
4152 4152 IBTF_DPRINTF_L4("ibnex",
4153 4153 "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip,
4154 4154 pdip_reachable_checked);
4155 4155
4156 4156 if (pdip_reachable_checked == 0) {
4157 4157 if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) {
4158 4158 IBTF_DPRINTF_L4("ibnex",
4159 4159 "/tioc_config_from_pdip: ioc %p not reachable"
4160 4160 "from %p", ioc_info, pdip);
4161 4161 return (IBNEX_FAILURE);
4162 4162 }
4163 4163 }
4164 4164
4165 4165 node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
4166 4166 (void *)ioc_info, 0, 0);
4167 4167
4168 4168 if (node_data && node_data->node_ap_state ==
4169 4169 IBNEX_NODE_AP_UNCONFIGURED) {
4170 4170 IBTF_DPRINTF_L4("ibnex",
4171 4171 "\tioc_config_from_pdip: Unconfigured node");
4172 4172 return (IBNEX_FAILURE);
4173 4173 }
4174 4174
4175 4175
4176 4176 if (node_data == NULL) {
4177 4177 ibnex_ioc_node_t *ioc;
4178 4178
4179 4179 create_pdip = 1;
4180 4180
4181 4181 node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE,
4182 4182 ioc_info, 0, 0);
4183 4183 ASSERT(node_data);
4184 4184 ioc = &node_data->node_data.ioc_node;
4185 4185 (void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN,
4186 4186 "%llX",
4187 4187 (longlong_t)ioc_info->ioc_profile.ioc_guid);
4188 4188 (void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN,
4189 4189 "%llX,%llX",
4190 4190 (longlong_t)ioc_info->ioc_profile.ioc_guid,
4191 4191 (longlong_t)ioc_info->ioc_iou_guid);
4192 4192 } else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) {
4193 4193 create_pdip = 1;
4194 4194 }
4195 4195
4196 4196 if (create_pdip) {
4197 4197 rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip);
4198 4198 }
4199 4199
4200 4200 IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x",
4201 4201 rc);
4202 4202 return (rc);
4203 4203 }
4204 4204
4205 4205 /*
4206 4206 * This function checks if a pathinfo has already been created
4207 4207 * for the HCA parent. The function returns SUCCESS if a pathinfo
4208 4208 * has already been created, FAILURE if not.
4209 4209 */
4210 4210 static int
4211 4211 ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent)
4212 4212 {
4213 4213 int rc;
4214 4214 ibnex_ioc_node_t *ioc;
4215 4215
4216 4216 ioc = &node_data->node_data.ioc_node;
4217 4217 if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str,
4218 4218 (char *)ioc->ioc_phci_guid) != NULL)
4219 4219 rc = IBNEX_SUCCESS;
4220 4220 else
4221 4221 rc = IBNEX_FAILURE;
4222 4222
4223 4223 IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, "
4224 4224 "phci_guid %s, parent %p, rc %x",
4225 4225 ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc);
4226 4226 return (rc);
4227 4227 }
4228 4228
4229 4229 static int
4230 4230 ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
4231 4231 {
4232 4232 ibdm_hca_list_t *hca_list;
4233 4233 dev_info_t *hca_dip;
4234 4234
4235 4235 IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)",
4236 4236 ioc_info, pdip);
4237 4237 for (hca_list = ioc_info->ioc_hca_list; hca_list;
4238 4238 hca_list = hca_list->hl_next) {
4239 4239 hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
4240 4240 if (hca_dip == pdip) {
4241 4241 IBTF_DPRINTF_L4("ibnex",
4242 4242 "\tioc_pi_reachable FAILURE");
4243 4243 return (IBNEX_SUCCESS);
4244 4244 }
4245 4245 }
4246 4246
4247 4247 IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE");
4248 4248 return (IBNEX_FAILURE);
4249 4249 }
↓ open down ↓ |
3949 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX