xref: /titanic_52/usr/src/uts/common/io/ib/ibnex/ibnex.c (revision 1aae5cd0fbf4c2622e76b8be40ca23c7c1f78e2b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
505fa0d51Spramodbg  * Common Development and Distribution License (the "License").
605fa0d51Spramodbg  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
221cfa752fSRamaswamy Tummala  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * The InfiniBand  Nexus driver (IB nexus) is a bus nexus driver for IB bus.
277c478bd9Sstevel@tonic-gate  * It supports  Port nodes, Virtual Physical Point of Attachment nodes (VPPA)
287c478bd9Sstevel@tonic-gate  * for  HCAs registered with IBTL and IOC nodes for all the IOCs present in
297c478bd9Sstevel@tonic-gate  * the IB fabric (that are accessible to the host). It also supports Pseudo
307c478bd9Sstevel@tonic-gate  * device children to be enumerated using their .conf file(s). All Port nodes
317c478bd9Sstevel@tonic-gate  * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo
327c478bd9Sstevel@tonic-gate  * device nodes are children of the IB nexus driver.
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * IB nexus driver provides bus nexus entry points to all the HCA drivers.
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * IB nexus  driver registers with  InfiniBand Device  Manager (IBDM) to get
377c478bd9Sstevel@tonic-gate  * information about all the HCA ports and  I/O Controllers (IOCs) connected
387c478bd9Sstevel@tonic-gate  * to the IB fabric. Based on that information, IB nexus will create all the
397c478bd9Sstevel@tonic-gate  * device tree nodes.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/conf.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
457c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
467c478bd9Sstevel@tonic-gate #include <sys/mdi_impldefs.h>
477c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h>
487c478bd9Sstevel@tonic-gate #include <sys/sunpm.h>
497c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h>
507c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h>
517c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h>
527c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h>
537c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h>
547c478bd9Sstevel@tonic-gate #include <sys/file.h>
557c478bd9Sstevel@tonic-gate #include <sys/hwconf.h>
56dcf1eb70SSudhakar Dindukurti #include <sys/fs/dv_node.h>
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* Function prototypes */
597c478bd9Sstevel@tonic-gate static int		ibnex_attach(dev_info_t *, ddi_attach_cmd_t);
607c478bd9Sstevel@tonic-gate static int		ibnex_getinfo(dev_info_t *, ddi_info_cmd_t,
617c478bd9Sstevel@tonic-gate 			    void *, void **);
627c478bd9Sstevel@tonic-gate static int		ibnex_detach(dev_info_t *, ddi_detach_cmd_t);
631cfa752fSRamaswamy Tummala int			ibnex_busctl(dev_info_t *,
647c478bd9Sstevel@tonic-gate 			    dev_info_t *, ddi_ctl_enum_t, void *, void *);
651cfa752fSRamaswamy Tummala int			ibnex_map_fault(dev_info_t *,
667c478bd9Sstevel@tonic-gate 			    dev_info_t *, struct hat *, struct seg *,
677c478bd9Sstevel@tonic-gate 			    caddr_t, struct devpage *, pfn_t, uint_t, uint_t);
687c478bd9Sstevel@tonic-gate static int		ibnex_init_child(dev_info_t *);
697c478bd9Sstevel@tonic-gate static ibnex_rval_t	ibnex_comm_svc_init(char *, ibnex_node_type_t);
707c478bd9Sstevel@tonic-gate static void		ibnex_comm_svc_fini();
717c478bd9Sstevel@tonic-gate dev_info_t		*ibnex_commsvc_initnode(dev_info_t *,
727c478bd9Sstevel@tonic-gate 			    ibdm_port_attr_t *, int, int, ib_pkey_t, int *,
737c478bd9Sstevel@tonic-gate 			    int);
747c478bd9Sstevel@tonic-gate static void		ibnex_delete_port_node_data(ibnex_node_data_t *);
757c478bd9Sstevel@tonic-gate int			ibnex_get_dip_from_guid(ib_guid_t, int,
767c478bd9Sstevel@tonic-gate 			    ib_pkey_t, dev_info_t **);
771cfa752fSRamaswamy Tummala int 			ibnex_get_node_and_dip_from_guid(ib_guid_t, int,
781cfa752fSRamaswamy Tummala 			    ib_pkey_t, ibnex_node_data_t **, dev_info_t **);
797c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t,
807c478bd9Sstevel@tonic-gate 			    void *, int, ib_pkey_t);
817c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *,
827c478bd9Sstevel@tonic-gate 			    int, ib_pkey_t);
837c478bd9Sstevel@tonic-gate static int		ibnex_create_port_node_prop(ibdm_port_attr_t *,
847c478bd9Sstevel@tonic-gate 			    dev_info_t *, char *, ib_pkey_t);
857c478bd9Sstevel@tonic-gate void			ibnex_dm_callback(void *, ibdm_events_t);
867c478bd9Sstevel@tonic-gate static int		ibnex_create_port_compatible_prop(dev_info_t *,
877c478bd9Sstevel@tonic-gate 			    char *, ibdm_port_attr_t *);
887c478bd9Sstevel@tonic-gate static int		ibnex_create_ioc_srv_props(
897c478bd9Sstevel@tonic-gate 			    dev_info_t *, ibdm_ioc_info_t *);
907c478bd9Sstevel@tonic-gate static int		ibnex_get_eventcookie(dev_info_t *,
917c478bd9Sstevel@tonic-gate 			    dev_info_t *, char *, ddi_eventcookie_t *);
927c478bd9Sstevel@tonic-gate static int		ibnex_add_eventcall(dev_info_t *, dev_info_t *,
937c478bd9Sstevel@tonic-gate 			    ddi_eventcookie_t, void (*)(dev_info_t *,
947c478bd9Sstevel@tonic-gate 			    ddi_eventcookie_t, void *, void *),
957c478bd9Sstevel@tonic-gate 			    void *arg, ddi_callback_id_t *cb_id);
967c478bd9Sstevel@tonic-gate static int		ibnex_remove_eventcall(dev_info_t *,
977c478bd9Sstevel@tonic-gate 			    ddi_callback_id_t);
987c478bd9Sstevel@tonic-gate static int		ibnex_post_event(dev_info_t *, dev_info_t *,
997c478bd9Sstevel@tonic-gate 			    ddi_eventcookie_t, void *);
1007c478bd9Sstevel@tonic-gate static int		ibnex_bus_config(dev_info_t *, uint_t,
1017c478bd9Sstevel@tonic-gate 			    ddi_bus_config_op_t, void *, dev_info_t **);
1027c478bd9Sstevel@tonic-gate static int		ibnex_bus_unconfig(dev_info_t *,
1037c478bd9Sstevel@tonic-gate 			    uint_t, ddi_bus_config_op_t, void *);
1041cfa752fSRamaswamy Tummala dev_info_t	*ibnex_config_port_node(dev_info_t *, char *);
1051cfa752fSRamaswamy Tummala int		ibnex_get_pkey_commsvc_index_portnum(
1067c478bd9Sstevel@tonic-gate 			    char *, int *, ib_pkey_t *, uint8_t *);
1071cfa752fSRamaswamy Tummala void		ibnex_config_all_children(dev_info_t *);
1087c478bd9Sstevel@tonic-gate static int		ibnex_devname_to_portnum(char *, uint8_t *);
1091cfa752fSRamaswamy Tummala void		ibnex_create_vppa_nodes(dev_info_t *, ibdm_port_attr_t *);
1101cfa752fSRamaswamy Tummala void		ibnex_create_port_nodes(
1117c478bd9Sstevel@tonic-gate 			    dev_info_t *, ibdm_port_attr_t *);
1121cfa752fSRamaswamy Tummala void		ibnex_create_hcasvc_nodes(
1137c478bd9Sstevel@tonic-gate 			    dev_info_t *, ibdm_port_attr_t *);
1147c478bd9Sstevel@tonic-gate static int		ibnex_config_root_iocnode(dev_info_t *, char *);
1157c478bd9Sstevel@tonic-gate static int		ibnex_devname2port(char *, int *);
1169d3d2ed0Shiremath static int		ibnex_config_ioc_node(char *, dev_info_t *);
1177c478bd9Sstevel@tonic-gate static int		ibnex_devname_to_node_n_ioc_guids(
1189d3d2ed0Shiremath 			    char *, ib_guid_t *, ib_guid_t *, char **);
1197c478bd9Sstevel@tonic-gate static void		ibnex_ioc_node_cleanup();
1207c478bd9Sstevel@tonic-gate static void		ibnex_delete_ioc_node_data(ibnex_node_data_t *);
12100a3eaf3SRamaswamy Tummala int			ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *);
12200a3eaf3SRamaswamy Tummala static int		ibnex_ioc_initnode_pdip(ibnex_node_data_t *,
12300a3eaf3SRamaswamy Tummala 			    ibdm_ioc_info_t *, dev_info_t *);
1247c478bd9Sstevel@tonic-gate static int		ibnex_create_ioc_node_prop(
1257c478bd9Sstevel@tonic-gate 			    ibdm_ioc_info_t *, dev_info_t *);
1267c478bd9Sstevel@tonic-gate static int		ibnex_create_ioc_compatible_prop(
1277c478bd9Sstevel@tonic-gate 			    dev_info_t *, ib_dm_ioc_ctrl_profile_t *);
1287c478bd9Sstevel@tonic-gate uint64_t		ibnex_str2hex(char *, int, int *);
1291cfa752fSRamaswamy Tummala int		ibnex_str2int(char *, int, int *);
1307c478bd9Sstevel@tonic-gate static int		ibnex_create_ioc_portgid_prop(
1317c478bd9Sstevel@tonic-gate 			    dev_info_t *, ibdm_ioc_info_t *);
1327c478bd9Sstevel@tonic-gate static void		ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int);
1337c478bd9Sstevel@tonic-gate static void		ibnex_wakeup_reprobe_all();
1347c478bd9Sstevel@tonic-gate ibt_status_t		ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *);
1357c478bd9Sstevel@tonic-gate void			ibnex_pseudo_initnodes(void);
1369d3d2ed0Shiremath static char		*ibnex_lookup_named_prop(ddi_prop_t *, char *);
1377c478bd9Sstevel@tonic-gate static void		ibnex_pseudo_node_cleanup(void);
1387c478bd9Sstevel@tonic-gate static int		ibnex_name_child(dev_info_t *, char *, int);
1397c478bd9Sstevel@tonic-gate static int		ibnex_name_pseudo_child(dev_info_t *, char *);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate void			ibnex_reprobe_ioc_dev(void *);
1427c478bd9Sstevel@tonic-gate void			ibnex_reprobe_ioc_all();
1437c478bd9Sstevel@tonic-gate static void		ibnex_update_prop(ibnex_node_data_t *,
1447c478bd9Sstevel@tonic-gate 			    ibdm_ioc_info_t *);
1457c478bd9Sstevel@tonic-gate static ibnex_rval_t	ibnex_unique_svcname(char *);
1467c478bd9Sstevel@tonic-gate static void		ibnex_handle_reprobe_dev(void *arg);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate extern int		ibnex_open(dev_t *, int, int, cred_t *);
1497c478bd9Sstevel@tonic-gate extern int		ibnex_close(dev_t, int, int, cred_t *);
1507c478bd9Sstevel@tonic-gate extern int		ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
1517c478bd9Sstevel@tonic-gate extern int		ibnex_offline_childdip(dev_info_t *);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate static int		ibnex_ioc_create_pi(
1549d3d2ed0Shiremath 			    ibdm_ioc_info_t *, ibnex_node_data_t *,
15500a3eaf3SRamaswamy Tummala 			    dev_info_t *, int *);
1567c478bd9Sstevel@tonic-gate static int		ibnex_bus_power(dev_info_t *, void *,
1577c478bd9Sstevel@tonic-gate 			    pm_bus_power_op_t, void *, void *);
15800a3eaf3SRamaswamy Tummala int			ibnex_pseudo_create_all_pi(ibnex_node_data_t *);
15900a3eaf3SRamaswamy Tummala static int		ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *,
1609d3d2ed0Shiremath 			    dev_info_t *);
1611cfa752fSRamaswamy Tummala int		ibnex_pseudo_config_one(
16205fa0d51Spramodbg 			    ibnex_node_data_t *, char *, dev_info_t *);
1631cfa752fSRamaswamy Tummala int		ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **,
1649d3d2ed0Shiremath 			    char *, char *);
1659d3d2ed0Shiremath static void		ibnex_config_pseudo_all(dev_info_t *);
1661cfa752fSRamaswamy Tummala int		ibnex_ioc_bus_config_one(dev_info_t **, uint_t,
1679d3d2ed0Shiremath 			    ddi_bus_config_op_t, void *, dev_info_t **, int *);
1689d3d2ed0Shiremath static int		ibnex_is_merge_node(dev_info_t *);
169f7209cf2Spramodbg static void		ibnex_hw_in_dev_tree(char *);
17000a3eaf3SRamaswamy Tummala static int		ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *,
17100a3eaf3SRamaswamy Tummala     dev_info_t *, int);
17200a3eaf3SRamaswamy Tummala static int		ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *);
17300a3eaf3SRamaswamy Tummala static int		ibnex_ioc_pi_reachable(ibdm_ioc_info_t *,
17400a3eaf3SRamaswamy Tummala     dev_info_t *);
1759d3d2ed0Shiremath 
1761cfa752fSRamaswamy Tummala extern void ibnex_handle_hca_attach(void *);
1777c478bd9Sstevel@tonic-gate 
1781cfa752fSRamaswamy Tummala extern struct bus_ops ibnex_ci_busops;
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Prototype declarations for the VHCI options
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate  * Functions registered with the mpxio framework
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int);
1867c478bd9Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int);
1877c478bd9Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *,
1887c478bd9Sstevel@tonic-gate 		mdi_pathinfo_state_t, uint32_t, int);
1897c478bd9Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = {
1937c478bd9Sstevel@tonic-gate 	MDI_VHCI_OPS_REV,
1947c478bd9Sstevel@tonic-gate 	ib_vhci_pi_init,
1957c478bd9Sstevel@tonic-gate 	ib_vhci_pi_uninit,
1967c478bd9Sstevel@tonic-gate 	ib_vhci_pi_state_change,
1977c478bd9Sstevel@tonic-gate 	ib_vhci_failover
1987c478bd9Sstevel@tonic-gate };
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * The  bus_ops  structure  defines the  capabilities  of IB nexus driver.
2037c478bd9Sstevel@tonic-gate  * IB nexus drivers does not  support any DMA  operations for its children
2047c478bd9Sstevel@tonic-gate  * as there is  no  such concept in Infiniband.  All the memory operations
2057c478bd9Sstevel@tonic-gate  * and DMA operations required by the child drivers can be performed using
2067c478bd9Sstevel@tonic-gate  * the IBTF API.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = {
2097c478bd9Sstevel@tonic-gate 	BUSO_REV,
2107c478bd9Sstevel@tonic-gate 	nullbusmap,		/* bus_map */
2117c478bd9Sstevel@tonic-gate 	NULL,			/* bus_get_intrspec */
2127c478bd9Sstevel@tonic-gate 	NULL,			/* bus_add_intrspec */
2137c478bd9Sstevel@tonic-gate 	NULL,			/* bus_remove_intrspec */
2147c478bd9Sstevel@tonic-gate 	ibnex_map_fault,	/* Map Fault */
2157c478bd9Sstevel@tonic-gate 	ddi_no_dma_map,		/* DMA related entry points */
2167c478bd9Sstevel@tonic-gate 	ddi_no_dma_allochdl,
2177c478bd9Sstevel@tonic-gate 	NULL,
2187c478bd9Sstevel@tonic-gate 	NULL,
2197c478bd9Sstevel@tonic-gate 	NULL,
2207c478bd9Sstevel@tonic-gate 	NULL,
2217c478bd9Sstevel@tonic-gate 	NULL,
2227c478bd9Sstevel@tonic-gate 	NULL,
2237c478bd9Sstevel@tonic-gate 	ibnex_busctl,		/* bus_ctl */
2247c478bd9Sstevel@tonic-gate 	ddi_bus_prop_op,	/* bus_prop_op */
2257c478bd9Sstevel@tonic-gate 	ibnex_get_eventcookie,	/* bus_get_eventcookie	*/
2267c478bd9Sstevel@tonic-gate 	ibnex_add_eventcall,	/* bus_add_eventcall	*/
2277c478bd9Sstevel@tonic-gate 	ibnex_remove_eventcall,	/* bus_remove_eventcall	*/
2287c478bd9Sstevel@tonic-gate 	ibnex_post_event,		/* bus_post_event	*/
2297c478bd9Sstevel@tonic-gate 	NULL,
2307c478bd9Sstevel@tonic-gate 	ibnex_bus_config,	/* bus config */
2317c478bd9Sstevel@tonic-gate 	ibnex_bus_unconfig,	/* bus unconfig */
2327c478bd9Sstevel@tonic-gate 	NULL,			/* bus fm init */
2337c478bd9Sstevel@tonic-gate 	NULL,			/* bus fm fini */
2347c478bd9Sstevel@tonic-gate 	NULL,			/* bus fm access enter */
2357c478bd9Sstevel@tonic-gate 	NULL,			/* bus fm access exit */
2367c478bd9Sstevel@tonic-gate 	ibnex_bus_power		/* bus power */
2377c478bd9Sstevel@tonic-gate };
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /* ibnex cb_ops */
2407c478bd9Sstevel@tonic-gate static struct cb_ops ibnex_cbops = {
2417c478bd9Sstevel@tonic-gate 	ibnex_open,		/* open */
2427c478bd9Sstevel@tonic-gate 	ibnex_close,		/* close */
2437c478bd9Sstevel@tonic-gate 	nodev,			/* strategy */
2447c478bd9Sstevel@tonic-gate 	nodev,			/* print */
2457c478bd9Sstevel@tonic-gate 	nodev,			/* dump */
2467c478bd9Sstevel@tonic-gate 	nodev,			/* read */
2477c478bd9Sstevel@tonic-gate 	nodev,			/* write */
2487c478bd9Sstevel@tonic-gate 	ibnex_ioctl,		/* ioctl */
2497c478bd9Sstevel@tonic-gate 	nodev,			/* devmap */
2507c478bd9Sstevel@tonic-gate 	nodev,			/* mmap */
2517c478bd9Sstevel@tonic-gate 	nodev,			/* segmap */
2527c478bd9Sstevel@tonic-gate 	nochpoll,		/* poll */
2537c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* prop_op */
2547c478bd9Sstevel@tonic-gate 	NULL,			/* stream */
2557c478bd9Sstevel@tonic-gate 	D_MP,			/* cb_flag */
2567c478bd9Sstevel@tonic-gate 	CB_REV, 		/* rev */
2577c478bd9Sstevel@tonic-gate 	nodev,			/* int (*cb_aread)() */
2587c478bd9Sstevel@tonic-gate 	nodev			/* int (*cb_awrite)() */
2597c478bd9Sstevel@tonic-gate };
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate  * Device options
2637c478bd9Sstevel@tonic-gate  * Note: ddi_no_info needs to change during devfs time frame. The drivers
2647c478bd9Sstevel@tonic-gate  *	 with 1 to 1 mapping between minor node and instance should use
2657c478bd9Sstevel@tonic-gate  *	 ddi_1to1_info. (See bug id 4424752)
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate static struct dev_ops ibnex_ops = {
2687c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
2697c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
2707c478bd9Sstevel@tonic-gate 	ibnex_getinfo,		/* info */
2717c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
2727c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
2737c478bd9Sstevel@tonic-gate 	ibnex_attach,		/* attach */
2747c478bd9Sstevel@tonic-gate 	ibnex_detach,		/* detach */
2757c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
2767c478bd9Sstevel@tonic-gate 	&ibnex_cbops,		/* driver ops - devctl interfaces */
2777c478bd9Sstevel@tonic-gate 	&ibnex_bus_ops,		/* bus operations */
27819397407SSherry Moore 	nulldev,		/* power */
27919397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
2807c478bd9Sstevel@tonic-gate };
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /* Module linkage information for the kernel.  */
2837c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
2847c478bd9Sstevel@tonic-gate 	&mod_driverops,		/* Driver module */
28519397407SSherry Moore 	"IB nexus",		/* Driver name and version */
2867c478bd9Sstevel@tonic-gate 	&ibnex_ops,		/* driver ops */
2877c478bd9Sstevel@tonic-gate };
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
2907c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
2917c478bd9Sstevel@tonic-gate };
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  * Global per-instance IB Nexus data.
2957c478bd9Sstevel@tonic-gate  * There is only one instance of IB Nexus supported.
2967c478bd9Sstevel@tonic-gate  */
2977c478bd9Sstevel@tonic-gate ibnex_t ibnex;
2987c478bd9Sstevel@tonic-gate #ifdef __lock_lint
2997c478bd9Sstevel@tonic-gate extern ibdm_t ibdm;
3007c478bd9Sstevel@tonic-gate #endif
3017c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s))
3027c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs
3037c478bd9Sstevel@tonic-gate 	ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs
3047c478bd9Sstevel@tonic-gate 	ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs
30500a3eaf3SRamaswamy Tummala 	ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list))
3067c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s))
3077c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex))
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate /* The port settling time in seconds */
310*1aae5cd0SRajkumar Sivaprakasam int	ibnex_port_settling_time = 8;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */
3137c478bd9Sstevel@tonic-gate static struct ibnex_property {
3147c478bd9Sstevel@tonic-gate 	char			*name;
3157c478bd9Sstevel@tonic-gate 	ibnex_node_type_t	type;
3167c478bd9Sstevel@tonic-gate } ibnex_properties[]  = {
3177c478bd9Sstevel@tonic-gate 	{ "port-svc-list",  IBNEX_PORT_COMMSVC_NODE},
3187c478bd9Sstevel@tonic-gate 	{ "vppa-svc-list",  IBNEX_VPPA_COMMSVC_NODE},
3197c478bd9Sstevel@tonic-gate 	{ "hca-svc-list",	IBNEX_HCASVC_COMMSVC_NODE}
3207c478bd9Sstevel@tonic-gate };
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate #define	N_IBNEX_PROPS	(sizeof (ibnex_properties))/ \
3237c478bd9Sstevel@tonic-gate 				(sizeof (struct ibnex_property))
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate  * Event Definition
3277c478bd9Sstevel@tonic-gate  *	Single event, event name defined in ibti_common.h.
3287c478bd9Sstevel@tonic-gate  *	Event posted to specific child handler. Event posted
3297c478bd9Sstevel@tonic-gate  *	at kernel priority.
3307c478bd9Sstevel@tonic-gate  */
3317c478bd9Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = {
3327c478bd9Sstevel@tonic-gate 	{IB_EVENT_TAG_PROP_UPDATE,  IB_PROP_UPDATE_EVENT, EPL_KERNEL,
3337c478bd9Sstevel@tonic-gate 		NDI_EVENT_POST_TO_TGT}
3347c478bd9Sstevel@tonic-gate };
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate #define	IB_N_NDI_EVENTS	\
3377c478bd9Sstevel@tonic-gate 	(sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t))
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = {
3407c478bd9Sstevel@tonic-gate 	NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs};
3419d3d2ed0Shiremath static int	ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  * _init
3467c478bd9Sstevel@tonic-gate  *	Loadable module init, called before any other module.
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate int
3497c478bd9Sstevel@tonic-gate _init(void)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate 	int	error;
352f7209cf2Spramodbg 	char	**hca_driver_list;
353f7209cf2Spramodbg 	int	i, ndrivers;
3547c478bd9Sstevel@tonic-gate 
3559d3d2ed0Shiremath 	if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) {
356f7209cf2Spramodbg 		ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE;
357f7209cf2Spramodbg 		hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers);
358f7209cf2Spramodbg 		for (i = 0; i < ndrivers; i++) {
359f7209cf2Spramodbg 			ibnex_hw_in_dev_tree(hca_driver_list[i]);
360f7209cf2Spramodbg 			if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE)
361f7209cf2Spramodbg 				break;
362f7209cf2Spramodbg 		}
363f7209cf2Spramodbg 		mdi_free_phci_driver_list(hca_driver_list, ndrivers);
3649d3d2ed0Shiremath 	}
3659d3d2ed0Shiremath 
3669d3d2ed0Shiremath 	/*
3679d3d2ed0Shiremath 	 * IB Nexus _init can be called while force attaching
3689d3d2ed0Shiremath 	 * IB Nexus driver or when a HCA is hotplugged.
3699d3d2ed0Shiremath 	 *
3709d3d2ed0Shiremath 	 * If IB HW is not in device tree or if no HCA driver
3719d3d2ed0Shiremath 	 * has been attached, fail IB Nexus _init().
3729d3d2ed0Shiremath 	 */
3739d3d2ed0Shiremath 	if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE &&
3749d3d2ed0Shiremath 	    ibt_hw_is_present() == 0) {
3759d3d2ed0Shiremath 		IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW");
3769d3d2ed0Shiremath 		return (DDI_FAILURE);
3779d3d2ed0Shiremath 	}
3789d3d2ed0Shiremath 
3797c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_init");
3807c478bd9Sstevel@tonic-gate 	mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL);
3817c478bd9Sstevel@tonic-gate 	cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL);
38251f34d4bSRajkumar Sivaprakasam 	cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL);
3837c478bd9Sstevel@tonic-gate 	if ((error = mod_install(&modlinkage)) != 0) {
3847c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed");
3857c478bd9Sstevel@tonic-gate 		mutex_destroy(&ibnex.ibnex_mutex);
3867c478bd9Sstevel@tonic-gate 		cv_destroy(&ibnex.ibnex_reprobe_cv);
38751f34d4bSRajkumar Sivaprakasam 		cv_destroy(&ibnex.ibnex_ioc_list_cv);
3887c478bd9Sstevel@tonic-gate 	} else {
3897c478bd9Sstevel@tonic-gate 		ibdm_ibnex_register_callback(ibnex_dm_callback);
3907c478bd9Sstevel@tonic-gate 		ibtl_ibnex_register_callback(ibnex_ibtl_callback);
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 	return (error);
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate /*
3977c478bd9Sstevel@tonic-gate  * _fini
3987c478bd9Sstevel@tonic-gate  *	Prepares a module for unloading.
3997c478bd9Sstevel@tonic-gate  */
4007c478bd9Sstevel@tonic-gate int
4017c478bd9Sstevel@tonic-gate _fini(void)
4027c478bd9Sstevel@tonic-gate {
4037c478bd9Sstevel@tonic-gate 	int	error;
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_fini");
4067c478bd9Sstevel@tonic-gate 	if ((error = mod_remove(&modlinkage)) != 0) {
4077c478bd9Sstevel@tonic-gate 		return (error);
4087c478bd9Sstevel@tonic-gate 	}
4097c478bd9Sstevel@tonic-gate 	ibdm_ibnex_unregister_callback();
4107c478bd9Sstevel@tonic-gate 	ibtl_ibnex_unregister_callback();
4117c478bd9Sstevel@tonic-gate 	mutex_destroy(&ibnex.ibnex_mutex);
4127c478bd9Sstevel@tonic-gate 	cv_destroy(&ibnex.ibnex_reprobe_cv);
41351f34d4bSRajkumar Sivaprakasam 	cv_destroy(&ibnex.ibnex_ioc_list_cv);
4147c478bd9Sstevel@tonic-gate 	return (0);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /*
4197c478bd9Sstevel@tonic-gate  * _info
4207c478bd9Sstevel@tonic-gate  *	Returns information about loadable module.
4217c478bd9Sstevel@tonic-gate  */
4227c478bd9Sstevel@tonic-gate int
4237c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_info");
4267c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate /*
4317c478bd9Sstevel@tonic-gate  * ibnex_attach
4327c478bd9Sstevel@tonic-gate  *	Configure and attach an instance of the IB Nexus driver
4337c478bd9Sstevel@tonic-gate  *	Only one instance of IB Nexus is supported
4347c478bd9Sstevel@tonic-gate  *	Create a minor node for cfgadm purpose
4357c478bd9Sstevel@tonic-gate  *	Initialize communication services
4367c478bd9Sstevel@tonic-gate  *	Register callback with IBDM
4377c478bd9Sstevel@tonic-gate  *	Register callback with IBTL
4387c478bd9Sstevel@tonic-gate  */
4397c478bd9Sstevel@tonic-gate static int
4407c478bd9Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4417c478bd9Sstevel@tonic-gate {
4427c478bd9Sstevel@tonic-gate 	int		i;
4437c478bd9Sstevel@tonic-gate 	int		instance = ddi_get_instance(dip);
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	switch (cmd) {
4487c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
4497c478bd9Sstevel@tonic-gate 		break;
4507c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
4517c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME");
4527c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
4537c478bd9Sstevel@tonic-gate 	default:
4547c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4557c478bd9Sstevel@tonic-gate 	}
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	/* Fail attach for more than one instance */
4587c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
4597c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_dip != NULL) {
4607c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
4617c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4627c478bd9Sstevel@tonic-gate 	}
4637c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
4647c478bd9Sstevel@tonic-gate 
4651cfa752fSRamaswamy Tummala 	/*
4661cfa752fSRamaswamy Tummala 	 * Create a IB nexus taskq
4671cfa752fSRamaswamy Tummala 	 */
4681cfa752fSRamaswamy Tummala 
4691cfa752fSRamaswamy Tummala 	ibnex.ibnex_taskq_id = ddi_taskq_create(dip,
4701cfa752fSRamaswamy Tummala 	    "ibnex-enum-taskq", 1, TASKQ_DEFAULTPRI, 0);
4711cfa752fSRamaswamy Tummala 	if (ibnex.ibnex_taskq_id == NULL) {
4721cfa752fSRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
4731cfa752fSRamaswamy Tummala 		    "\tattach: ddi_taskq_create() failed");
4741cfa752fSRamaswamy Tummala 		return (DDI_FAILURE);
4751cfa752fSRamaswamy Tummala 
4761cfa752fSRamaswamy Tummala 	}
4771cfa752fSRamaswamy Tummala 
4787c478bd9Sstevel@tonic-gate 	/* Register with MPxIO framework */
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0)
4817c478bd9Sstevel@tonic-gate 	    != MDI_SUCCESS) {
4827c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
4837c478bd9Sstevel@tonic-gate 		    "\tattach: mdi_vhci_register() failed");
4841cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
4851cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
4867c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4877c478bd9Sstevel@tonic-gate 	}
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	/*
4917c478bd9Sstevel@tonic-gate 	 * Create the "fabric" devctl minor-node for IB DR support.
4927c478bd9Sstevel@tonic-gate 	 * The minor number for the "devctl" node is in the same format
4937c478bd9Sstevel@tonic-gate 	 * as the AP minor nodes.
4947c478bd9Sstevel@tonic-gate 	 */
4957c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance,
4967c478bd9Sstevel@tonic-gate 	    DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
4977c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
4987c478bd9Sstevel@tonic-gate 		    "\tattach: failed to create fabric minornode");
4991cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5001cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
5017c478bd9Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5027c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5037c478bd9Sstevel@tonic-gate 	}
5047c478bd9Sstevel@tonic-gate 
505d1a5c838SRamaswamy Tummala 	/*
506d1a5c838SRamaswamy Tummala 	 * Create "devctl" minor node for general ioctl interface to the
507d1a5c838SRamaswamy Tummala 	 * ib nexus.
508d1a5c838SRamaswamy Tummala 	 */
509d1a5c838SRamaswamy Tummala 	if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance,
510d1a5c838SRamaswamy Tummala 	    DDI_NT_IB_NEXUS, 0) != DDI_SUCCESS) {
511d1a5c838SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
512d1a5c838SRamaswamy Tummala 		    "\tattach: failed to create devctl minornode");
513d1a5c838SRamaswamy Tummala 		(void) ddi_remove_minor_node(dip, NULL);
5141cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5151cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
516d1a5c838SRamaswamy Tummala 		(void) mdi_vhci_unregister(dip, 0);
517d1a5c838SRamaswamy Tummala 		return (DDI_FAILURE);
518d1a5c838SRamaswamy Tummala 	}
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	/*
5217c478bd9Sstevel@tonic-gate 	 * Set pm-want-child-notification property for
5227c478bd9Sstevel@tonic-gate 	 * power management of the phci and client
5237c478bd9Sstevel@tonic-gate 	 */
5247c478bd9Sstevel@tonic-gate 	if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
5257c478bd9Sstevel@tonic-gate 	    "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) {
5267c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5277c478bd9Sstevel@tonic-gate 		    "_attach: create pm-want-child-notification failed");
5287c478bd9Sstevel@tonic-gate 		(void) ddi_remove_minor_node(dip, NULL);
5291cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5301cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
5317c478bd9Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5327c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
5367c478bd9Sstevel@tonic-gate 	ibnex.ibnex_dip  = dip;
5377c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	/*
5407c478bd9Sstevel@tonic-gate 	 * Event Handling: Definition and Binding.
5417c478bd9Sstevel@tonic-gate 	 */
5427c478bd9Sstevel@tonic-gate 	if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl,
5437c478bd9Sstevel@tonic-gate 	    NDI_SLEEP) != NDI_SUCCESS) {
5447c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5457c478bd9Sstevel@tonic-gate 		    "_attach: ndi_event_alloc_hdl failed");
5461cfa752fSRamaswamy Tummala 		(void) ddi_remove_minor_node(dip, NULL);
5471cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5481cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
5497c478bd9Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5507c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5517c478bd9Sstevel@tonic-gate 	}
5527c478bd9Sstevel@tonic-gate 	if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events,
5537c478bd9Sstevel@tonic-gate 	    NDI_SLEEP) != NDI_SUCCESS) {
5547c478bd9Sstevel@tonic-gate 		(void) ddi_remove_minor_node(dip, NULL);
5557c478bd9Sstevel@tonic-gate 		(void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl);
5567c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5577c478bd9Sstevel@tonic-gate 		    "_attach: ndi_event_bind_set failed");
5581cfa752fSRamaswamy Tummala 		(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5591cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
5607c478bd9Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5617c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
5627c478bd9Sstevel@tonic-gate 	}
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	for (i = 0; i < N_IBNEX_PROPS; i++) {
5657c478bd9Sstevel@tonic-gate 		if (ibnex_comm_svc_init(ibnex_properties[i].name,
5667c478bd9Sstevel@tonic-gate 		    ibnex_properties[i].type) != IBNEX_SUCCESS) {
5677c478bd9Sstevel@tonic-gate 			ibnex_comm_svc_fini();
5687c478bd9Sstevel@tonic-gate 			(void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl,
5697c478bd9Sstevel@tonic-gate 			    &ib_ndi_events, NDI_SLEEP);
5707c478bd9Sstevel@tonic-gate 			(void) ddi_remove_minor_node(dip, NULL);
5717c478bd9Sstevel@tonic-gate 			(void) ndi_event_free_hdl(
5727c478bd9Sstevel@tonic-gate 			    ibnex.ibnex_ndi_event_hdl);
5737c478bd9Sstevel@tonic-gate 			ibnex.ibnex_ndi_event_hdl = NULL;
5747c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init"
5757c478bd9Sstevel@tonic-gate 			    " failed %s", ibnex_properties[i].name);
5761cfa752fSRamaswamy Tummala 			(void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5771cfa752fSRamaswamy Tummala 			ibnex.ibnex_taskq_id = NULL;
5787c478bd9Sstevel@tonic-gate 			(void) mdi_vhci_unregister(dip, 0);
5797c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
5807c478bd9Sstevel@tonic-gate 		}
5817c478bd9Sstevel@tonic-gate 	}
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	/*
5847c478bd9Sstevel@tonic-gate 	 * before anything else comes up:
5857c478bd9Sstevel@tonic-gate 	 * Initialize the internal list of pseudo device nodes by
5867c478bd9Sstevel@tonic-gate 	 * getting all pseudo children of "ib" and processing them.
5877c478bd9Sstevel@tonic-gate 	 */
5887c478bd9Sstevel@tonic-gate 	ibnex_pseudo_initnodes();
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate /*
5957c478bd9Sstevel@tonic-gate  * ibnex_getinfo()
5967c478bd9Sstevel@tonic-gate  * Given the device number, return the devinfo pointer or the
5977c478bd9Sstevel@tonic-gate  * instance number.
5987c478bd9Sstevel@tonic-gate  * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
5997c478bd9Sstevel@tonic-gate  */
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6027c478bd9Sstevel@tonic-gate static int
6037c478bd9Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
6047c478bd9Sstevel@tonic-gate {
6057c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin");
6087c478bd9Sstevel@tonic-gate 	switch (cmd) {
6097c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
6107c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_dip != NULL)
6117c478bd9Sstevel@tonic-gate 			*result = ibnex.ibnex_dip;
6127c478bd9Sstevel@tonic-gate 		else {
6137c478bd9Sstevel@tonic-gate 			*result = NULL;
6147c478bd9Sstevel@tonic-gate 			ret = DDI_FAILURE;
6157c478bd9Sstevel@tonic-gate 		}
6167c478bd9Sstevel@tonic-gate 		break;
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
6197c478bd9Sstevel@tonic-gate 		*result = 0;
6207c478bd9Sstevel@tonic-gate 		break;
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	default:
6237c478bd9Sstevel@tonic-gate 		ret = DDI_FAILURE;
6247c478bd9Sstevel@tonic-gate 	}
6257c478bd9Sstevel@tonic-gate 	return (ret);
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate /*
6307c478bd9Sstevel@tonic-gate  * ibnex_detach
6317c478bd9Sstevel@tonic-gate  *	Unregister callback with the IBDM
6327c478bd9Sstevel@tonic-gate  *	Unregister callback with the IBTL
6337c478bd9Sstevel@tonic-gate  *	Uninitialize the communication entries
6347c478bd9Sstevel@tonic-gate  *	Remove all the minor nodes created by this instance
6357c478bd9Sstevel@tonic-gate  */
6367c478bd9Sstevel@tonic-gate static int
6377c478bd9Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
6387c478bd9Sstevel@tonic-gate {
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd);
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	switch (cmd) {
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
6457c478bd9Sstevel@tonic-gate 		break;
6467c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
6477c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend");
6487c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
6497c478bd9Sstevel@tonic-gate 	default:
6507c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6517c478bd9Sstevel@tonic-gate 	}
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
6547c478bd9Sstevel@tonic-gate 	if (ibt_hw_is_present()) {
6557c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
6567c478bd9Sstevel@tonic-gate 		    "\tdetach: IB HW is present ");
6577c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
6587c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6597c478bd9Sstevel@tonic-gate 	}
6607c478bd9Sstevel@tonic-gate 	if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) {
6617c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
6627c478bd9Sstevel@tonic-gate 		    "\tdetach: ndi_event_free_hdl() failed");
6637c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
6647c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6657c478bd9Sstevel@tonic-gate 	}
6667c478bd9Sstevel@tonic-gate 	ibnex.ibnex_ndi_event_hdl = NULL;
6677c478bd9Sstevel@tonic-gate 	ibnex.ibnex_prop_update_evt_cookie = NULL;
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 	ibnex_pseudo_node_cleanup();
6707c478bd9Sstevel@tonic-gate 	ibnex_comm_svc_fini();
6717c478bd9Sstevel@tonic-gate 	ibnex_ioc_node_cleanup();
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	(void) ddi_remove_minor_node(dip, NULL);
6747c478bd9Sstevel@tonic-gate 	ibnex.ibnex_dip = NULL;
6757c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
6767c478bd9Sstevel@tonic-gate 	(void) mdi_vhci_unregister(dip, 0);
6771cfa752fSRamaswamy Tummala 
6781cfa752fSRamaswamy Tummala 	if (ibnex.ibnex_taskq_id != NULL) {
6791cfa752fSRamaswamy Tummala 		ddi_taskq_destroy(ibnex.ibnex_taskq_id);
6801cfa752fSRamaswamy Tummala 		ibnex.ibnex_taskq_id = NULL;
6811cfa752fSRamaswamy Tummala 	}
6821cfa752fSRamaswamy Tummala 
6837c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate /*
6887c478bd9Sstevel@tonic-gate  * ibnex_pseudo_node_cleanup()
6897c478bd9Sstevel@tonic-gate  *	This checks if all the "dips" have been deallocated (implying
6907c478bd9Sstevel@tonic-gate  *	that all the children have been unconfigured) first.
6917c478bd9Sstevel@tonic-gate  *	If not, it just returns.
6927c478bd9Sstevel@tonic-gate  *	If yes, then it frees up memory allocated for devi_name,
6937c478bd9Sstevel@tonic-gate  *	node_addr, and property list.
6947c478bd9Sstevel@tonic-gate  */
6957c478bd9Sstevel@tonic-gate static void
6967c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void)
6977c478bd9Sstevel@tonic-gate {
6987c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*nodep =  ibnex.ibnex_pseudo_node_head;
6997c478bd9Sstevel@tonic-gate 	ibnex_pseudo_node_t	*pseudo;
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:");
7027c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 	for (; nodep; nodep = nodep->node_next)
7057c478bd9Sstevel@tonic-gate 		if (nodep->node_dip)
7067c478bd9Sstevel@tonic-gate 			return;
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory");
7097c478bd9Sstevel@tonic-gate 	for (nodep =  ibnex.ibnex_pseudo_node_head; nodep;
7107c478bd9Sstevel@tonic-gate 	    nodep = nodep->node_next) {
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 		pseudo = &nodep->node_data.pseudo_node;
7137c478bd9Sstevel@tonic-gate 		if (pseudo->pseudo_node_addr) {
7147c478bd9Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_node_addr,
7157c478bd9Sstevel@tonic-gate 			    strlen(pseudo-> pseudo_node_addr) + 1);
7167c478bd9Sstevel@tonic-gate 			pseudo->pseudo_node_addr = NULL;
7177c478bd9Sstevel@tonic-gate 		}
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 		if (pseudo->pseudo_devi_name) {
7207c478bd9Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_devi_name,
7217c478bd9Sstevel@tonic-gate 			    strlen(pseudo-> pseudo_devi_name) + 1);
7227c478bd9Sstevel@tonic-gate 			pseudo->pseudo_devi_name = NULL;
7237c478bd9Sstevel@tonic-gate 		}
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 		if (pseudo->pseudo_unit_addr) {
7267c478bd9Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_unit_addr,
7277c478bd9Sstevel@tonic-gate 			    pseudo->pseudo_unit_addr_len);
7287c478bd9Sstevel@tonic-gate 		}
7297c478bd9Sstevel@tonic-gate 	}
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate  * This functions wakes up any reprobe requests waiting for completion
7357c478bd9Sstevel@tonic-gate  * of reprobe of this IOC. It also send an NDI event, if  :
7367c478bd9Sstevel@tonic-gate  *
7377c478bd9Sstevel@tonic-gate  *	notify_flag is set. This is set if :
7387c478bd9Sstevel@tonic-gate  *		ibt_reprobe_ioc has returned with SUCCESS
7397c478bd9Sstevel@tonic-gate  *		IBTF client has not been notified for this node.
7407c478bd9Sstevel@tonic-gate  *	node_data->node_dip != NULL
7417c478bd9Sstevel@tonic-gate  *	node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set
7427c478bd9Sstevel@tonic-gate  *	An NDI event cookie has been registered.
7437c478bd9Sstevel@tonic-gate  */
7447c478bd9Sstevel@tonic-gate static void
7457c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag)
7467c478bd9Sstevel@tonic-gate {
7477c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t	evt_cookie;
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7507c478bd9Sstevel@tonic-gate 	evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate 	if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) ||
7537c478bd9Sstevel@tonic-gate 	    (node_data->node_reprobe_state != 0)) {
7547c478bd9Sstevel@tonic-gate 		if (notify_flag && (node_data->node_dip != NULL) &&
7557c478bd9Sstevel@tonic-gate 		    (node_data->node_state &
7567c478bd9Sstevel@tonic-gate 		    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) &&
7577c478bd9Sstevel@tonic-gate 		    (evt_cookie != NULL)) {
7587c478bd9Sstevel@tonic-gate 			ibt_prop_update_payload_t	evt_data;
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 			bzero(&evt_data, sizeof (evt_data));
7637c478bd9Sstevel@tonic-gate 			if (ndi_post_event(ibnex.ibnex_dip,
7647c478bd9Sstevel@tonic-gate 			    node_data->node_dip,
7657c478bd9Sstevel@tonic-gate 			    evt_cookie, &evt_data) != NDI_SUCCESS)
7667c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
7677c478bd9Sstevel@tonic-gate 				    "\tndi_post_event failed\n");
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
7707c478bd9Sstevel@tonic-gate 		}
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 		node_data->node_reprobe_state = 0;
7737c478bd9Sstevel@tonic-gate 		cv_broadcast(&ibnex.ibnex_reprobe_cv);
7747c478bd9Sstevel@tonic-gate 	}
7757c478bd9Sstevel@tonic-gate 	node_data->node_reprobe_state = 0;
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate /*
7797c478bd9Sstevel@tonic-gate  * This function wakes up any reprobe request waiting for completion
7807c478bd9Sstevel@tonic-gate  * of reprobe of all IOCs.
7817c478bd9Sstevel@tonic-gate  */
7827c478bd9Sstevel@tonic-gate static void
7837c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all()
7847c478bd9Sstevel@tonic-gate {
7857c478bd9Sstevel@tonic-gate 	ibnex_node_data_t *ioc_node;
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	/* Notify if another reprobe_all is pending */
7907c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) {
7917c478bd9Sstevel@tonic-gate 		ibnex.ibnex_reprobe_state = 0;
7927c478bd9Sstevel@tonic-gate 		cv_broadcast(&ibnex.ibnex_reprobe_cv);
7937c478bd9Sstevel@tonic-gate 	}
7947c478bd9Sstevel@tonic-gate 	ibnex.ibnex_reprobe_state = 0;
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 	/*
7977c478bd9Sstevel@tonic-gate 	 * The IOC may be hot-removed after the reprobe request.
7987c478bd9Sstevel@tonic-gate 	 * Reset the reprobe states for such IOCs.
7997c478bd9Sstevel@tonic-gate 	 */
8007c478bd9Sstevel@tonic-gate 	for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node;
8017c478bd9Sstevel@tonic-gate 	    ioc_node = ioc_node->node_next) {
8027c478bd9Sstevel@tonic-gate 		if (ioc_node->node_reprobe_state != 0) {
8037c478bd9Sstevel@tonic-gate 			ibnex_wakeup_reprobe_ioc(ioc_node, 1);
8047c478bd9Sstevel@tonic-gate 		}
8057c478bd9Sstevel@tonic-gate 	}
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate /*
8097c478bd9Sstevel@tonic-gate  * ibnex_ibnex_callback:
8107c478bd9Sstevel@tonic-gate  *	IBTL_IBNEX_IBC_INIT:
8117c478bd9Sstevel@tonic-gate  *		Called from ibc_init() which is called from
8127c478bd9Sstevel@tonic-gate  *		HCA driver _init entry point
8137c478bd9Sstevel@tonic-gate  *		Initializes the HCA dev_ops structure with default
8147c478bd9Sstevel@tonic-gate  *		IB nexus structure.
8157c478bd9Sstevel@tonic-gate  *	IBTL_IBNEX_IBC_FINI:
8167c478bd9Sstevel@tonic-gate  *		Called from ibc_fini() which is called from
8177c478bd9Sstevel@tonic-gate  *		HCA driver _fini entry point
8187c478bd9Sstevel@tonic-gate  *		Un-Initializes the HCA dev_ops structure with default
8197c478bd9Sstevel@tonic-gate  *		IB nexus strucuture.
8207c478bd9Sstevel@tonic-gate  *	Returns IBT_SUCCESS
8217c478bd9Sstevel@tonic-gate  */
8227c478bd9Sstevel@tonic-gate ibt_status_t
8237c478bd9Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args)
8247c478bd9Sstevel@tonic-gate {
8257c478bd9Sstevel@tonic-gate 	int			retval = IBT_SUCCESS;
8267c478bd9Sstevel@tonic-gate 	struct dev_ops 		*hca_dev_ops;
8277c478bd9Sstevel@tonic-gate 	dev_info_t		*clnt_dip;
8287c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L5("ibnex", "\tibtl_callback");
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	switch (cb_args->cb_flag) {
8337c478bd9Sstevel@tonic-gate 	case IBTL_IBNEX_IBC_INIT:
8347c478bd9Sstevel@tonic-gate 		/*
8357c478bd9Sstevel@tonic-gate 		 * Get the devops structure of the HCA,
8367c478bd9Sstevel@tonic-gate 		 * and put IB nexus default busops vector in its place.
8377c478bd9Sstevel@tonic-gate 		 */
8387c478bd9Sstevel@tonic-gate 		hca_dev_ops = ((struct modldrv *)
8397c478bd9Sstevel@tonic-gate 		    (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8407c478bd9Sstevel@tonic-gate 		ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL));
8417c478bd9Sstevel@tonic-gate 		hca_dev_ops->devo_bus_ops = &ibnex_ci_busops;
8427c478bd9Sstevel@tonic-gate 		break;
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	case IBTL_IBNEX_IBC_FINI:
8457c478bd9Sstevel@tonic-gate 		hca_dev_ops = ((struct modldrv *)
8467c478bd9Sstevel@tonic-gate 		    (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8477c478bd9Sstevel@tonic-gate 		hca_dev_ops->devo_bus_ops = NULL;
8487c478bd9Sstevel@tonic-gate 		break;
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 	case IBTL_IBNEX_REPROBE_DEV_REQ:
8517c478bd9Sstevel@tonic-gate 		/* IBTL pass down request for ibt_reprobe_dev */
8527c478bd9Sstevel@tonic-gate 		clnt_dip = cb_args->cb_dip;
8537c478bd9Sstevel@tonic-gate 		ASSERT(clnt_dip);
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 		node_data = ddi_get_parent_data(clnt_dip);
8567c478bd9Sstevel@tonic-gate 		ASSERT(node_data);
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 		/* Reprobe for IOC nodes only */
8597c478bd9Sstevel@tonic-gate 		ASSERT(node_data->node_type == IBNEX_IOC_NODE);
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 		/*
8627c478bd9Sstevel@tonic-gate 		 * Start the reprobe. This could sleep as it is not
8637c478bd9Sstevel@tonic-gate 		 * from interrupt context.
8647c478bd9Sstevel@tonic-gate 		 */
8657c478bd9Sstevel@tonic-gate 		if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev,
8667c478bd9Sstevel@tonic-gate 		    clnt_dip, TQ_SLEEP) == 0) {
8677c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
8687c478bd9Sstevel@tonic-gate 			    "ibnex_ibtl_callback: taskq_dispatch failed");
8697c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
8707c478bd9Sstevel@tonic-gate 			ibnex_wakeup_reprobe_ioc(node_data, 0);
8717c478bd9Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
8727c478bd9Sstevel@tonic-gate 			return (IBT_INSUFF_KERNEL_RESOURCE);
8737c478bd9Sstevel@tonic-gate 		}
8747c478bd9Sstevel@tonic-gate 		return (IBT_SUCCESS);
8757c478bd9Sstevel@tonic-gate 	}
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 	return (retval);
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate /*
8827c478bd9Sstevel@tonic-gate  * Bus-ops entry points
8837c478bd9Sstevel@tonic-gate  */
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate /*
8867c478bd9Sstevel@tonic-gate  * ibnex_map_fault
8877c478bd9Sstevel@tonic-gate  * 	IOC drivers need not map memory. Return failure to fail any
8887c478bd9Sstevel@tonic-gate  *	such calls.
8897c478bd9Sstevel@tonic-gate  */
8907c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8911cfa752fSRamaswamy Tummala int
8927c478bd9Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat,
8937c478bd9Sstevel@tonic-gate     struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn,
8947c478bd9Sstevel@tonic-gate     uint_t prot, uint_t lock)
8957c478bd9Sstevel@tonic-gate {
8967c478bd9Sstevel@tonic-gate 	return (DDI_FAILURE);
8977c478bd9Sstevel@tonic-gate }
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate /*
9017c478bd9Sstevel@tonic-gate  * ibnex_busctl
9027c478bd9Sstevel@tonic-gate  * 	bus_ctl bus_ops entry point
9037c478bd9Sstevel@tonic-gate  */
9047c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9051cfa752fSRamaswamy Tummala int
9067c478bd9Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip,
9077c478bd9Sstevel@tonic-gate     ddi_ctl_enum_t ctlop, void *arg, void *result)
9087c478bd9Sstevel@tonic-gate {
9097c478bd9Sstevel@tonic-gate 	dev_info_t		*child_dip;
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
9127c478bd9Sstevel@tonic-gate 	    "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop);
9137c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result);
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 	switch (ctlop) {
9167c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
9177c478bd9Sstevel@tonic-gate 		if (rdip == NULL) {
9187c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
9197c478bd9Sstevel@tonic-gate 		}
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 		/* Log the relevant details of dip to sysbuf */
9227c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n",
9237c478bd9Sstevel@tonic-gate 		    ddi_node_name(rdip), ddi_get_name_addr(rdip),
9247c478bd9Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
9297c478bd9Sstevel@tonic-gate 		child_dip = (dev_info_t *)arg;
9307c478bd9Sstevel@tonic-gate 		return (ibnex_init_child(child_dip));
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
9337c478bd9Sstevel@tonic-gate 		child_dip = (dev_info_t *)arg;
9347c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child_dip, NULL);
9357c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_ATTACH:
9387c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DETACH:
9397c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POWER :
9407c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
9437c478bd9Sstevel@tonic-gate 		/*
9447c478bd9Sstevel@tonic-gate 		 * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and
9457c478bd9Sstevel@tonic-gate 		 * DDI_FAILURE for the nodes enumerated by a Pseudo file.
9467c478bd9Sstevel@tonic-gate 		 */
9477c478bd9Sstevel@tonic-gate 		return (ndi_dev_is_persistent_node(rdip) ?
9487c478bd9Sstevel@tonic-gate 		    DDI_SUCCESS : DDI_FAILURE);
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_IOMIN:
9527c478bd9Sstevel@tonic-gate 		/*
9537c478bd9Sstevel@tonic-gate 		 * Return DDI_SUCCESS, so that consistent buf alloc
9547c478bd9Sstevel@tonic-gate 		 * gets the default DMA IO minimum for the platform
9557c478bd9Sstevel@tonic-gate 		 */
9567c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	/*
9597c478bd9Sstevel@tonic-gate 	 * These ops correspond to functions that "shouldn't" be
9607c478bd9Sstevel@tonic-gate 	 * called by IB Nexus driver.
9617c478bd9Sstevel@tonic-gate 	 */
9627c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DMAPMAPC:
9637c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTINT:
9647c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
9657c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
9667c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SLAVEONLY:
9677c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_AFFINITY:
9687c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POKE:
9697c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_PEEK:
9707c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
9717c478bd9Sstevel@tonic-gate 		    "%s%d: invalid op (%d) from %s inst%d",
9727c478bd9Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip),
9737c478bd9Sstevel@tonic-gate 		    ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
9747c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	/*
9777c478bd9Sstevel@tonic-gate 	 * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we
9787c478bd9Sstevel@tonic-gate 	 * pass up
9797c478bd9Sstevel@tonic-gate 	 */
9807c478bd9Sstevel@tonic-gate 	default:
9817c478bd9Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
9827c478bd9Sstevel@tonic-gate 	}
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate /*
9877c478bd9Sstevel@tonic-gate  * ibnex_init_child()
9887c478bd9Sstevel@tonic-gate  *
9897c478bd9Sstevel@tonic-gate  * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD
9907c478bd9Sstevel@tonic-gate  * entry. Function returns DDI_SUCCESS,  DDI_FAILURE or DDI_NOT_WELL_FORMED.
9917c478bd9Sstevel@tonic-gate  */
9927c478bd9Sstevel@tonic-gate static int
9937c478bd9Sstevel@tonic-gate ibnex_init_child(dev_info_t *child)
9947c478bd9Sstevel@tonic-gate {
9957c478bd9Sstevel@tonic-gate 	int			ret;
9967c478bd9Sstevel@tonic-gate 	char			name[MAXNAMELEN];
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child);
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate 	/* Handle Pseudo nodes of client children */
10017c478bd9Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
10029d3d2ed0Shiremath 		/* Skip nodes without ib-node-type="merge" */
10039d3d2ed0Shiremath 		if (ibnex_is_merge_node(child) != IBNEX_SUCCESS)
10049d3d2ed0Shiremath 			return (DDI_FAILURE);
10059d3d2ed0Shiremath 
10067c478bd9Sstevel@tonic-gate 		if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS)
10077c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child, name);
10107c478bd9Sstevel@tonic-gate 		/*
10117c478bd9Sstevel@tonic-gate 		 * Merge the .conf node
10127c478bd9Sstevel@tonic-gate 		 */
10137c478bd9Sstevel@tonic-gate 		if (ndi_merge_node(child,
10147c478bd9Sstevel@tonic-gate 		    ibnex_name_child) == DDI_SUCCESS) {
10157c478bd9Sstevel@tonic-gate 			ddi_set_name_addr(child, NULL);
10167c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
10177c478bd9Sstevel@tonic-gate 		}
10187c478bd9Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 	}
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS)
10237c478bd9Sstevel@tonic-gate 		return (ret);
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	ddi_set_name_addr(child, name);
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
10287c478bd9Sstevel@tonic-gate }
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate int
10327c478bd9Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name)
10337c478bd9Sstevel@tonic-gate {
10347c478bd9Sstevel@tonic-gate 	char **unit_addr;
10357c478bd9Sstevel@tonic-gate 	uint_t n;
10367c478bd9Sstevel@tonic-gate 	if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
10377c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
10387c478bd9Sstevel@tonic-gate 	    DDI_PROP_SUCCESS) {
10399d3d2ed0Shiremath 		IBTF_DPRINTF_L4("ibnex",
10409d3d2ed0Shiremath 		    "\tname_pseudo_child: cannot find unit-address in %s.conf",
10417c478bd9Sstevel@tonic-gate 		    ddi_get_name(child));
10427c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10437c478bd9Sstevel@tonic-gate 	}
10447c478bd9Sstevel@tonic-gate 	if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
10457c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "unit-address property in %s.conf"
10467c478bd9Sstevel@tonic-gate 		    " not well-formed", ddi_get_name(child));
10477c478bd9Sstevel@tonic-gate 		ddi_prop_free(unit_addr);
10487c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10497c478bd9Sstevel@tonic-gate 	}
10507c478bd9Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN, "%s", *unit_addr);
10517c478bd9Sstevel@tonic-gate 	ddi_prop_free(unit_addr);
10527c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
10537c478bd9Sstevel@tonic-gate }
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10577c478bd9Sstevel@tonic-gate int
10587c478bd9Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag)
10597c478bd9Sstevel@tonic-gate {
10607c478bd9Sstevel@tonic-gate 	ibnex_pseudo_node_t	*pseudo;
10617c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_datap;
10627c478bd9Sstevel@tonic-gate 	ibnex_port_node_t	*port_node;
10637c478bd9Sstevel@tonic-gate 	ibnex_ioc_node_t	*ioc;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 	node_datap = ddi_get_parent_data(child);
10667c478bd9Sstevel@tonic-gate 	if (node_datap == NULL) {
10677c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL");
10687c478bd9Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
10697c478bd9Sstevel@tonic-gate 	}
10707c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p"
10717c478bd9Sstevel@tonic-gate 	    "Node type %x", node_datap, node_datap->node_type);
10727c478bd9Sstevel@tonic-gate 	switch (node_datap->node_type) {
10737c478bd9Sstevel@tonic-gate 	case IBNEX_PORT_COMMSVC_NODE:
10747c478bd9Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10757c478bd9Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10767c478bd9Sstevel@tonic-gate 		    port_node->port_num,
10777c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]);
10787c478bd9Sstevel@tonic-gate 		break;
10797c478bd9Sstevel@tonic-gate 	case IBNEX_VPPA_COMMSVC_NODE:
10807c478bd9Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10817c478bd9Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s",
10827c478bd9Sstevel@tonic-gate 		    port_node->port_num, port_node->port_pkey, ibnex.
10837c478bd9Sstevel@tonic-gate 		    ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]);
10847c478bd9Sstevel@tonic-gate 		break;
10857c478bd9Sstevel@tonic-gate 	case IBNEX_HCASVC_COMMSVC_NODE:
10867c478bd9Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10877c478bd9Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10887c478bd9Sstevel@tonic-gate 		    port_node->port_num,
10897c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_hcasvc_comm_svc_names[port_node->
10907c478bd9Sstevel@tonic-gate 		    port_commsvc_idx]);
10917c478bd9Sstevel@tonic-gate 		break;
10927c478bd9Sstevel@tonic-gate 	case IBNEX_IOC_NODE:
10937c478bd9Sstevel@tonic-gate 		ioc = &node_datap->node_data.ioc_node;
10947c478bd9Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX",
10957c478bd9Sstevel@tonic-gate 		    (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid);
10967c478bd9Sstevel@tonic-gate 		break;
10977c478bd9Sstevel@tonic-gate 	case IBNEX_PSEUDO_NODE:
10987c478bd9Sstevel@tonic-gate 		pseudo = &node_datap->node_data.pseudo_node;
10997c478bd9Sstevel@tonic-gate 		(void) snprintf(name,
11007c478bd9Sstevel@tonic-gate 		    IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr);
11017c478bd9Sstevel@tonic-gate 		break;
11027c478bd9Sstevel@tonic-gate 	default:
11037c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed");
11047c478bd9Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
11057c478bd9Sstevel@tonic-gate 	}
11067c478bd9Sstevel@tonic-gate 
11077c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
11087c478bd9Sstevel@tonic-gate }
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate /*
11127c478bd9Sstevel@tonic-gate  * ibnex_bus_config()
11137c478bd9Sstevel@tonic-gate  *
11147c478bd9Sstevel@tonic-gate  * BUS_CONFIG_ONE:
11157c478bd9Sstevel@tonic-gate  *	Enumerate the exact instance of the driver. Use the device node name
11167c478bd9Sstevel@tonic-gate  *	to locate the exact instance.
11177c478bd9Sstevel@tonic-gate  *	Query IBDM to find whether the hardware exits for the instance of the
11187c478bd9Sstevel@tonic-gate  *	driver. If exists, create a device node and return NDI_SUCCESS.
11197c478bd9Sstevel@tonic-gate  *
11207c478bd9Sstevel@tonic-gate  * BUS_CONFIG_ALL:
11217c478bd9Sstevel@tonic-gate  *	Enumerate all the instances of all the possible children (seen before
11227c478bd9Sstevel@tonic-gate  *	and never seen before).
11237c478bd9Sstevel@tonic-gate  *
11247c478bd9Sstevel@tonic-gate  * BUS_CONFIG_DRIVER:
11257c478bd9Sstevel@tonic-gate  *	Enumerate all the instances of a particular driver.
11267c478bd9Sstevel@tonic-gate  */
11271cfa752fSRamaswamy Tummala 
11287c478bd9Sstevel@tonic-gate static int
11297c478bd9Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag,
11307c478bd9Sstevel@tonic-gate     ddi_bus_config_op_t op, void *devname, dev_info_t **child)
11317c478bd9Sstevel@tonic-gate {
11329d3d2ed0Shiremath 	int			ret = IBNEX_SUCCESS, len, circ, need_bus_config;
11337c478bd9Sstevel@tonic-gate 	char 			*device_name, *cname = NULL, *caddr = NULL;
11341cfa752fSRamaswamy Tummala 	dev_info_t		*cdip;
11357c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 	switch (op) {
11387c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_ONE:
113905fa0d51Spramodbg 		IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, "
114005fa0d51Spramodbg 		    "parent %p", parent);
11417c478bd9Sstevel@tonic-gate 
11421cfa752fSRamaswamy Tummala 		ndi_devi_enter(parent, &circ);
11431cfa752fSRamaswamy Tummala 
11447c478bd9Sstevel@tonic-gate 		len = strlen((char *)devname) + 1;
11457c478bd9Sstevel@tonic-gate 		device_name = i_ddi_strdup(devname, KM_SLEEP);
11467c478bd9Sstevel@tonic-gate 		i_ddi_parse_name(device_name, &cname, &caddr, NULL);
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 		if (caddr == NULL || (strlen(caddr) == 0)) {
11497c478bd9Sstevel@tonic-gate 			kmem_free(device_name, len);
11507c478bd9Sstevel@tonic-gate 			ndi_devi_exit(parent, circ);
11517c478bd9Sstevel@tonic-gate 			return (NDI_FAILURE);
11527c478bd9Sstevel@tonic-gate 		}
11537c478bd9Sstevel@tonic-gate 
11541cfa752fSRamaswamy Tummala 		cdip = ndi_devi_findchild(parent, devname);
115500a3eaf3SRamaswamy Tummala 		if (cdip)
115600a3eaf3SRamaswamy Tummala 			node_data = ddi_get_parent_data(cdip);
11571cfa752fSRamaswamy Tummala 
11581cfa752fSRamaswamy Tummala 		ndi_devi_exit(parent, circ);
11591cfa752fSRamaswamy Tummala 
116000a3eaf3SRamaswamy Tummala 		if (cdip == NULL || (node_data != NULL &&
116100a3eaf3SRamaswamy Tummala 		    node_data->node_dip == NULL)) {
11627c478bd9Sstevel@tonic-gate 			/* Node is not present */
11637c478bd9Sstevel@tonic-gate 			if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) {
11649d3d2ed0Shiremath 				ret = ibnex_ioc_bus_config_one(&parent, flag,
11659d3d2ed0Shiremath 				    op, devname, child, &need_bus_config);
116605fa0d51Spramodbg 				if (!need_bus_config) {
116705fa0d51Spramodbg 					kmem_free(device_name, len);
11689d3d2ed0Shiremath 					return (ret);
116905fa0d51Spramodbg 				}
11709d3d2ed0Shiremath 			} else {
11717c478bd9Sstevel@tonic-gate 				/*
11721cfa752fSRamaswamy Tummala 				 * if IB Nexus is the parent, call MDI. Bus
11731cfa752fSRamaswamy Tummala 				 * config with HCA as the parent would have
11741cfa752fSRamaswamy Tummala 				 * enumerated the Pseudo node.
11757c478bd9Sstevel@tonic-gate 				 */
11767c478bd9Sstevel@tonic-gate 				ret = IBNEX_SUCCESS;
11777c478bd9Sstevel@tonic-gate 				ibnex_pseudo_initnodes();
11787c478bd9Sstevel@tonic-gate 				mutex_enter(&ibnex.ibnex_mutex);
11791cfa752fSRamaswamy Tummala 				ret = ibnex_pseudo_mdi_config_one(flag, devname,
11801cfa752fSRamaswamy Tummala 				    child, cname, caddr);
11817c478bd9Sstevel@tonic-gate 				mutex_exit(&ibnex.ibnex_mutex);
118205fa0d51Spramodbg 				kmem_free(device_name, len);
11839d3d2ed0Shiremath 				return (ret);
11849d3d2ed0Shiremath 			}
1185a1e3386eShiremath 		}
11867c478bd9Sstevel@tonic-gate 		kmem_free(device_name, len);
11877c478bd9Sstevel@tonic-gate 		break;
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_ALL:
11909d3d2ed0Shiremath 		/*FALLTHRU*/
11917c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_DRIVER:
11929d3d2ed0Shiremath 		if (op == BUS_CONFIG_ALL)
119305fa0d51Spramodbg 			IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, "
119405fa0d51Spramodbg 			    "parent %p", parent);
11959d3d2ed0Shiremath 		else
119605fa0d51Spramodbg 			IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER"
119705fa0d51Spramodbg 			    ", parent %p", parent);
11987c478bd9Sstevel@tonic-gate 
11999d3d2ed0Shiremath 		/*
12009d3d2ed0Shiremath 		 * Drive CONFIG requests for IB Nexus parent through
12019d3d2ed0Shiremath 		 * MDI. This is needed to load the HCA drivers in x86 SRP
12029d3d2ed0Shiremath 		 * boot case.
12039d3d2ed0Shiremath 		 *
12049d3d2ed0Shiremath 		 * CONFIG Requests with HCA parent will probe devices using
12059d3d2ed0Shiremath 		 * ibdm and configure all children.
12069d3d2ed0Shiremath 		 */
120751f34d4bSRajkumar Sivaprakasam 		ibdm_ioc_info_t	*ioc_list, *new_ioc_list;
120800a3eaf3SRamaswamy Tummala 
120951f34d4bSRajkumar Sivaprakasam 		mutex_enter(&ibnex.ibnex_mutex);
121051f34d4bSRajkumar Sivaprakasam 		while (ibnex.ibnex_ioc_list_state !=
121151f34d4bSRajkumar Sivaprakasam 		    IBNEX_IOC_LIST_READY) {
121251f34d4bSRajkumar Sivaprakasam 			cv_wait(&ibnex.ibnex_ioc_list_cv,
121351f34d4bSRajkumar Sivaprakasam 			    &ibnex.ibnex_mutex);
121451f34d4bSRajkumar Sivaprakasam 		}
121551f34d4bSRajkumar Sivaprakasam 		ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW;
121651f34d4bSRajkumar Sivaprakasam 		mutex_exit(&ibnex.ibnex_mutex);
121751f34d4bSRajkumar Sivaprakasam 		/* Enumerate all the IOC's */
12181cfa752fSRamaswamy Tummala 		ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
121951f34d4bSRajkumar Sivaprakasam 
122051f34d4bSRajkumar Sivaprakasam 		new_ioc_list = ibdm_ibnex_get_ioc_list(
122151f34d4bSRajkumar Sivaprakasam 		    IBDM_IBNEX_NORMAL_PROBE);
122251f34d4bSRajkumar Sivaprakasam 		IBTF_DPRINTF_L4("ibnex",
122351f34d4bSRajkumar Sivaprakasam 		    "\tbus_config: alloc ioc_list %p", new_ioc_list);
122400a3eaf3SRamaswamy Tummala 		/*
122500a3eaf3SRamaswamy Tummala 		 * Optimize the calls for each BUS_CONFIG_ALL request
122600a3eaf3SRamaswamy Tummala 		 * to the IB Nexus dip. This is currently done for
122700a3eaf3SRamaswamy Tummala 		 * each PDIP.
122800a3eaf3SRamaswamy Tummala 		 */
122951f34d4bSRajkumar Sivaprakasam 		mutex_enter(&ibnex.ibnex_mutex);
123051f34d4bSRajkumar Sivaprakasam 		ioc_list = ibnex.ibnex_ioc_list;
123151f34d4bSRajkumar Sivaprakasam 		ibnex.ibnex_ioc_list = new_ioc_list;
123251f34d4bSRajkumar Sivaprakasam 		ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
123351f34d4bSRajkumar Sivaprakasam 		cv_broadcast(&ibnex.ibnex_ioc_list_cv);
123451f34d4bSRajkumar Sivaprakasam 		mutex_exit(&ibnex.ibnex_mutex);
123551f34d4bSRajkumar Sivaprakasam 
123651f34d4bSRajkumar Sivaprakasam 		if (ioc_list) {
123700a3eaf3SRamaswamy Tummala 			IBTF_DPRINTF_L4("ibnex",
123800a3eaf3SRamaswamy Tummala 			    "\tbus_config: freeing ioc_list %p",
123951f34d4bSRajkumar Sivaprakasam 			    ioc_list);
124051f34d4bSRajkumar Sivaprakasam 			ibdm_ibnex_free_ioc_list(ioc_list);
124100a3eaf3SRamaswamy Tummala 		}
124200a3eaf3SRamaswamy Tummala 
124300a3eaf3SRamaswamy Tummala 
12449d3d2ed0Shiremath 		ret = mdi_vhci_bus_config(parent,
12459d3d2ed0Shiremath 		    flag, op, devname, child, NULL);
12469d3d2ed0Shiremath 		return (ret);
12477c478bd9Sstevel@tonic-gate 	default:
12487c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tbus_config: error");
12497c478bd9Sstevel@tonic-gate 		ret = IBNEX_FAILURE;
12507c478bd9Sstevel@tonic-gate 		break;
12517c478bd9Sstevel@tonic-gate 	}
12525e3986cbScth 
12537c478bd9Sstevel@tonic-gate 	if (ret == IBNEX_SUCCESS) {
12547c478bd9Sstevel@tonic-gate 		ret = ndi_busop_bus_config(
12551cfa752fSRamaswamy Tummala 		    parent, flag, op, devname, child, 0);
12567c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tbus_config:"
12577c478bd9Sstevel@tonic-gate 		    "ndi_busop_bus_config : retval %d", ret);
12587c478bd9Sstevel@tonic-gate 		return (ret);
12597c478bd9Sstevel@tonic-gate 	}
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate 	return (NDI_FAILURE);
12627c478bd9Sstevel@tonic-gate }
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate /*
12667c478bd9Sstevel@tonic-gate  * ibnex_config_root_iocnode()
12677c478bd9Sstevel@tonic-gate  *	Configures one particular instance of the IOC driver.
12687c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
12697c478bd9Sstevel@tonic-gate  */
12707c478bd9Sstevel@tonic-gate static int
12717c478bd9Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name)
12727c478bd9Sstevel@tonic-gate {
12737c478bd9Sstevel@tonic-gate 	int			ret, port = 0, iter = 0;
12747c478bd9Sstevel@tonic-gate 	boolean_t		displayed = B_FALSE;
12757c478bd9Sstevel@tonic-gate 	char			*portstr;
12767c478bd9Sstevel@tonic-gate 	ib_guid_t		hca_guid, iou_guid, ioc_guid;
12777c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
12787c478bd9Sstevel@tonic-gate 	ibdm_port_attr_t	*port_attr;
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
12817c478bd9Sstevel@tonic-gate 	    "\tconfig_root_iocnode: name %s", device_name);
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	portstr = strstr(device_name, ":port=");
12847c478bd9Sstevel@tonic-gate 	if (portstr == NULL) {
12857c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
12867c478bd9Sstevel@tonic-gate 	}
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 	portstr[0] = 0; portstr++;
12897c478bd9Sstevel@tonic-gate 	if (ibnex_devname2port(portstr, &port)) {
12907c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port");
12917c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
12927c478bd9Sstevel@tonic-gate 	}
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate 	if (ibnex_devname_to_node_n_ioc_guids(
12959d3d2ed0Shiremath 	    device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
12967c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
12977c478bd9Sstevel@tonic-gate 	}
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate 	(void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4),
13007c478bd9Sstevel@tonic-gate 	    "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid);
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
13037c478bd9Sstevel@tonic-gate 	if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) {
13047c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
13057c478bd9Sstevel@tonic-gate 		    "\tconfig_root_iocnode: Port does not exist");
13067c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
13077c478bd9Sstevel@tonic-gate 	}
13087c478bd9Sstevel@tonic-gate 
13097c478bd9Sstevel@tonic-gate 	/* Wait until "port is up" */
13107c478bd9Sstevel@tonic-gate 	while (port_attr->pa_state != IBT_PORT_ACTIVE) {
13117c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
13127c478bd9Sstevel@tonic-gate 		delay(drv_usectohz(10000));
13137c478bd9Sstevel@tonic-gate 		if ((port_attr = ibdm_ibnex_probe_hcaport(
13147c478bd9Sstevel@tonic-gate 		    hca_guid, port)) == NULL) {
13157c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
13167c478bd9Sstevel@tonic-gate 		}
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate 		if (iter++ == 400) {
13197c478bd9Sstevel@tonic-gate 			if (displayed == B_FALSE) {
13207c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE, "\tWaiting for Port %d "
13217c478bd9Sstevel@tonic-gate 				    "initialization", port_attr->pa_port_num);
13227c478bd9Sstevel@tonic-gate 				displayed = B_TRUE;
13237c478bd9Sstevel@tonic-gate 			}
13247c478bd9Sstevel@tonic-gate 		}
13257c478bd9Sstevel@tonic-gate 	}
13267c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_port_attr(port_attr);
13277c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:"
13287c478bd9Sstevel@tonic-gate 	    "Port is initialized");
13297c478bd9Sstevel@tonic-gate 
13307c478bd9Sstevel@tonic-gate 	if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) {
13317c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc_info);
13327c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
13337c478bd9Sstevel@tonic-gate 	}
13347c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
133500a3eaf3SRamaswamy Tummala 	if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) !=
133600a3eaf3SRamaswamy Tummala 	    IBNEX_SUCCESS) {
133700a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
133800a3eaf3SRamaswamy Tummala 		    "\tconfig_root_ioc_node failed for pdip %p", parent);
133900a3eaf3SRamaswamy Tummala 	}
13407c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
13417c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
13427c478bd9Sstevel@tonic-gate 	return (ret);
13437c478bd9Sstevel@tonic-gate }
13447c478bd9Sstevel@tonic-gate 
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate static int
13477c478bd9Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port)
13487c478bd9Sstevel@tonic-gate {
13497c478bd9Sstevel@tonic-gate 	char	*temp;
13507c478bd9Sstevel@tonic-gate 	int	ret = IBNEX_FAILURE;
13517c478bd9Sstevel@tonic-gate 
13527c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin");
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate 	temp = strchr(portstr, '=');
13557c478bd9Sstevel@tonic-gate 	if (temp != NULL) {
13567c478bd9Sstevel@tonic-gate 		temp++;
13577c478bd9Sstevel@tonic-gate 		*port = ibnex_str2int(temp, strlen(temp), &ret);
13587c478bd9Sstevel@tonic-gate 	}
13597c478bd9Sstevel@tonic-gate 	return (ret);
13607c478bd9Sstevel@tonic-gate }
13617c478bd9Sstevel@tonic-gate 
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate /*
13647c478bd9Sstevel@tonic-gate  * ibnex_config_all_children()
13657c478bd9Sstevel@tonic-gate  *	Wait for lata SM initialization case before enumerating the nodes
13667c478bd9Sstevel@tonic-gate  *	Get list of HCA's and HCA port information
13677c478bd9Sstevel@tonic-gate  *		Create device device nodes and its node properties
13687c478bd9Sstevel@tonic-gate  *		for port nodes and VPPA nodes
13697c478bd9Sstevel@tonic-gate  *	Get list of all the IOC node information
13707c478bd9Sstevel@tonic-gate  *		Create device nodes and its properties for all the IOCs
13717c478bd9Sstevel@tonic-gate  *		if not created already
13727c478bd9Sstevel@tonic-gate  *	Bind drivers for all the newly created device nodes
13737c478bd9Sstevel@tonic-gate  *	Support Pseudo nodes enumerated using their .conf file
13747c478bd9Sstevel@tonic-gate  */
13751cfa752fSRamaswamy Tummala void
13767c478bd9Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent)
13777c478bd9Sstevel@tonic-gate {
13787c478bd9Sstevel@tonic-gate 	int			ii;
137900a3eaf3SRamaswamy Tummala 	ibdm_ioc_info_t		*ioc_list;
13807c478bd9Sstevel@tonic-gate 	ibdm_hca_list_t		*hca_list;
13817c478bd9Sstevel@tonic-gate 	ib_guid_t		hca_guid;
13825e3986cbScth 	int			circ;
13837c478bd9Sstevel@tonic-gate 
13847c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin");
13857c478bd9Sstevel@tonic-gate 
13861cfa752fSRamaswamy Tummala 
13877c478bd9Sstevel@tonic-gate 	/*
13889d3d2ed0Shiremath 	 * Enumerate children of this HCA, port nodes,
13895e3986cbScth 	 * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for
13905e3986cbScth 	 * locking. IB Nexus is enumerating the children
13915e3986cbScth 	 * of HCA, not MPXIO clients.
13927c478bd9Sstevel@tonic-gate 	 */
13935e3986cbScth 	ndi_devi_enter(parent, &circ);
13947c478bd9Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
139500a3eaf3SRamaswamy Tummala 	ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time);
13967c478bd9Sstevel@tonic-gate 	hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
1397f9edfba4Spramodbg 	if (hca_list == NULL) {
1398f9edfba4Spramodbg 		ndi_devi_exit(parent, circ);
13997c478bd9Sstevel@tonic-gate 		return;
1400f9edfba4Spramodbg 	}
14017c478bd9Sstevel@tonic-gate 	ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr);
14027c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < hca_list->hl_nports; ii++) {
14037c478bd9Sstevel@tonic-gate 		ibnex_create_port_nodes(
14047c478bd9Sstevel@tonic-gate 		    parent, &hca_list->hl_port_attr[ii]);
14051cfa752fSRamaswamy Tummala 		ibnex_create_vppa_nodes(parent, &hca_list->hl_port_attr[ii]);
14067c478bd9Sstevel@tonic-gate 	}
14077c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_hca_list(hca_list);
14085e3986cbScth 	ndi_devi_exit(parent, circ);
14095e3986cbScth 
14105e3986cbScth 	/*
14115e3986cbScth 	 * Use mdi_devi_enter() for locking. IB Nexus is
14128b2e16e7Seota 	 * enumerating MPxIO clients.
14135e3986cbScth 	 */
14145e3986cbScth 	mdi_devi_enter(parent, &circ);
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate 	ibnex_pseudo_initnodes();
14177c478bd9Sstevel@tonic-gate 
14187c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
141951f34d4bSRajkumar Sivaprakasam 	while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) {
142051f34d4bSRajkumar Sivaprakasam 		cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex);
142151f34d4bSRajkumar Sivaprakasam 	}
142251f34d4bSRajkumar Sivaprakasam 	ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS;
142351f34d4bSRajkumar Sivaprakasam 	ioc_list = ibnex.ibnex_ioc_list;
14247c478bd9Sstevel@tonic-gate 	while (ioc_list) {
142500a3eaf3SRamaswamy Tummala 		(void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0);
14267c478bd9Sstevel@tonic-gate 		ioc_list = ioc_list->ioc_next;
14277c478bd9Sstevel@tonic-gate 	}
142851f34d4bSRajkumar Sivaprakasam 	ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
142951f34d4bSRajkumar Sivaprakasam 	cv_broadcast(&ibnex.ibnex_ioc_list_cv);
14309d3d2ed0Shiremath 
14319d3d2ed0Shiremath 	/* Config IBTF Pseudo clients */
14329d3d2ed0Shiremath 	ibnex_config_pseudo_all(parent);
14339d3d2ed0Shiremath 
14347c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
14355e3986cbScth 	mdi_devi_exit(parent, circ);
14369d3d2ed0Shiremath 
14377c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End");
14387c478bd9Sstevel@tonic-gate }
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 
14417c478bd9Sstevel@tonic-gate /*
14427c478bd9Sstevel@tonic-gate  * ibnex_create_port_nodes:
14437c478bd9Sstevel@tonic-gate  *	Creates a device node per each communication service defined
14447c478bd9Sstevel@tonic-gate  *	in the "port-commsvc-list" property per HCA port
14457c478bd9Sstevel@tonic-gate  */
14461cfa752fSRamaswamy Tummala void
14477c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
14487c478bd9Sstevel@tonic-gate {
14497c478bd9Sstevel@tonic-gate 	int		idx;
14507c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;
14517c478bd9Sstevel@tonic-gate 	int		rval;
14527c478bd9Sstevel@tonic-gate 
14537c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
14547c478bd9Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) {
14557c478bd9Sstevel@tonic-gate 		rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
14567c478bd9Sstevel@tonic-gate 		    idx, 0, &dip);
14571cfa752fSRamaswamy Tummala 		if (rval != IBNEX_SUCCESS || dip == NULL) {
14587c478bd9Sstevel@tonic-gate 			(void) ibnex_commsvc_initnode(parent, port_attr, idx,
14597c478bd9Sstevel@tonic-gate 			    IBNEX_PORT_COMMSVC_NODE, 0, &rval,
14607c478bd9Sstevel@tonic-gate 			    IBNEX_DEVFS_ENUMERATE);
14617c478bd9Sstevel@tonic-gate 		}
14627c478bd9Sstevel@tonic-gate 	}
14637c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
14647c478bd9Sstevel@tonic-gate }
14657c478bd9Sstevel@tonic-gate 
14667c478bd9Sstevel@tonic-gate 
14677c478bd9Sstevel@tonic-gate /*
14687c478bd9Sstevel@tonic-gate  * ibnex_create_vppa_nodes:
14697c478bd9Sstevel@tonic-gate  *	Creates a device node per each communication service defined
14707c478bd9Sstevel@tonic-gate  *	in the "vppa-commsvc-list" property and per each PKEY that
14717c478bd9Sstevel@tonic-gate  *	this particular port supports and per HCA port
14727c478bd9Sstevel@tonic-gate  */
14731cfa752fSRamaswamy Tummala void
14741cfa752fSRamaswamy Tummala ibnex_create_vppa_nodes(
14751cfa752fSRamaswamy Tummala     dev_info_t *parent, ibdm_port_attr_t *port_attr)
14767c478bd9Sstevel@tonic-gate {
14777c478bd9Sstevel@tonic-gate 	int 		idx, ii;
14787c478bd9Sstevel@tonic-gate 	int		rval;
14797c478bd9Sstevel@tonic-gate 	ib_pkey_t 	pkey;
14807c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;
14817c478bd9Sstevel@tonic-gate 
14827c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin");
14837c478bd9Sstevel@tonic-gate 
14847c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
14857c478bd9Sstevel@tonic-gate 	if (port_attr->pa_state != IBT_PORT_ACTIVE) {
14867c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: "
14877c478bd9Sstevel@tonic-gate 		    "Port %d is down", port_attr->pa_port_num);
14887c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
14897c478bd9Sstevel@tonic-gate 		return;
14907c478bd9Sstevel@tonic-gate 	}
14917c478bd9Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) {
14921cfa752fSRamaswamy Tummala 		if (strcmp("ipib", ibnex.ibnex_vppa_comm_svc_names[idx]) == 0) {
14931cfa752fSRamaswamy Tummala 			IBTF_DPRINTF_L2("ibnex", "Skipping IBD devices...");
14941cfa752fSRamaswamy Tummala 			continue;
14951cfa752fSRamaswamy Tummala 		}
14967c478bd9Sstevel@tonic-gate 		for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
14977c478bd9Sstevel@tonic-gate 			pkey = port_attr->pa_pkey_tbl[ii].pt_pkey;
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate 			if (IBNEX_INVALID_PKEY(pkey)) {
15007c478bd9Sstevel@tonic-gate 				continue;
15017c478bd9Sstevel@tonic-gate 			}
15027c478bd9Sstevel@tonic-gate 			rval = ibnex_get_dip_from_guid(
15037c478bd9Sstevel@tonic-gate 			    port_attr->pa_port_guid, idx, pkey, &dip);
150400a3eaf3SRamaswamy Tummala 			if ((rval != IBNEX_SUCCESS) || (dip == NULL)) {
15057c478bd9Sstevel@tonic-gate 				(void) ibnex_commsvc_initnode(parent, port_attr,
15067c478bd9Sstevel@tonic-gate 				    idx, IBNEX_VPPA_COMMSVC_NODE,
15077c478bd9Sstevel@tonic-gate 				    pkey, &rval, IBNEX_CFGADM_ENUMERATE);
15087c478bd9Sstevel@tonic-gate 			}
15097c478bd9Sstevel@tonic-gate 		}
15107c478bd9Sstevel@tonic-gate 	}
15117c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
15127c478bd9Sstevel@tonic-gate }
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 
15157c478bd9Sstevel@tonic-gate /*
15167c478bd9Sstevel@tonic-gate  * ibnex_create_hcasvc_nodes:
15177c478bd9Sstevel@tonic-gate  *	Creates a device node per each communication service defined
15187c478bd9Sstevel@tonic-gate  *	in the "port-commsvc-list" property per HCA port
15197c478bd9Sstevel@tonic-gate  */
15201cfa752fSRamaswamy Tummala void
15217c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
15227c478bd9Sstevel@tonic-gate {
15237c478bd9Sstevel@tonic-gate 	int		idx;
15247c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;
15257c478bd9Sstevel@tonic-gate 	int		rval;
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
15287c478bd9Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) {
15297c478bd9Sstevel@tonic-gate 		rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
15307c478bd9Sstevel@tonic-gate 		    idx, 0, &dip);
15311cfa752fSRamaswamy Tummala 		if (rval != IBNEX_SUCCESS || dip == NULL) {
15327c478bd9Sstevel@tonic-gate 			(void) ibnex_commsvc_initnode(parent, port_attr, idx,
15337c478bd9Sstevel@tonic-gate 			    IBNEX_HCASVC_COMMSVC_NODE, 0, &rval,
15347c478bd9Sstevel@tonic-gate 			    IBNEX_DEVFS_ENUMERATE);
15357c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: "
15367c478bd9Sstevel@tonic-gate 			    "commsvc_initnode failed, rval %x", rval);
15377c478bd9Sstevel@tonic-gate 		}
15387c478bd9Sstevel@tonic-gate 	}
15397c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
15407c478bd9Sstevel@tonic-gate }
15417c478bd9Sstevel@tonic-gate 
15427c478bd9Sstevel@tonic-gate 
15437c478bd9Sstevel@tonic-gate /*
15447c478bd9Sstevel@tonic-gate  * ibnex_bus_unconfig()
15457c478bd9Sstevel@tonic-gate  *
15467c478bd9Sstevel@tonic-gate  *	Unconfigure a particular device node or all instance of a device
15477c478bd9Sstevel@tonic-gate  *	driver device or all children of IBnex
15487c478bd9Sstevel@tonic-gate  */
15497c478bd9Sstevel@tonic-gate static int
15507c478bd9Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent,
15517c478bd9Sstevel@tonic-gate     uint_t flag, ddi_bus_config_op_t op, void *device_name)
15527c478bd9Sstevel@tonic-gate {
155300a3eaf3SRamaswamy Tummala 	ibnex_node_data_t	*ndp;
155400a3eaf3SRamaswamy Tummala 	major_t			major = (major_t)(uintptr_t)device_name;
155500a3eaf3SRamaswamy Tummala 	dev_info_t		*dip = NULL;
155600a3eaf3SRamaswamy Tummala 
155700a3eaf3SRamaswamy Tummala 	if (ndi_busop_bus_unconfig(parent, flag, op, device_name) !=
155800a3eaf3SRamaswamy Tummala 	    DDI_SUCCESS)
155900a3eaf3SRamaswamy Tummala 		return (DDI_FAILURE);
156000a3eaf3SRamaswamy Tummala 
156100a3eaf3SRamaswamy Tummala 	if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) &&
156200a3eaf3SRamaswamy Tummala 	    (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) {
156300a3eaf3SRamaswamy Tummala 		mutex_enter(&ibnex.ibnex_mutex);
156400a3eaf3SRamaswamy Tummala 		/*
156500a3eaf3SRamaswamy Tummala 		 * IB dip. here we handle IOC and pseudo nodes which
156600a3eaf3SRamaswamy Tummala 		 * are the children of IB nexus. Cleanup only the nodes
156700a3eaf3SRamaswamy Tummala 		 * with matching major number. We also need to cleanup
156800a3eaf3SRamaswamy Tummala 		 * the PathInfo links to the PHCI here.
156900a3eaf3SRamaswamy Tummala 		 */
157000a3eaf3SRamaswamy Tummala 		for (ndp = ibnex.ibnex_ioc_node_head;
157100a3eaf3SRamaswamy Tummala 		    ndp; ndp = ndp->node_next) {
157200a3eaf3SRamaswamy Tummala 			dip = ndp->node_dip;
157300a3eaf3SRamaswamy Tummala 			if (dip && (ddi_driver_major(dip) == major)) {
1574332f545bSEiji Ota 				(void) ibnex_offline_childdip(dip);
157500a3eaf3SRamaswamy Tummala 			}
157600a3eaf3SRamaswamy Tummala 		}
157700a3eaf3SRamaswamy Tummala 		for (ndp = ibnex.ibnex_pseudo_node_head;
157800a3eaf3SRamaswamy Tummala 		    ndp; ndp = ndp->node_next) {
157900a3eaf3SRamaswamy Tummala 			dip = ndp->node_dip;
158000a3eaf3SRamaswamy Tummala 			if (dip && (ddi_driver_major(dip) == major)) {
1581332f545bSEiji Ota 				(void) ibnex_offline_childdip(dip);
158200a3eaf3SRamaswamy Tummala 			}
158300a3eaf3SRamaswamy Tummala 		}
158400a3eaf3SRamaswamy Tummala 		mutex_exit(&ibnex.ibnex_mutex);
158500a3eaf3SRamaswamy Tummala 	}
158600a3eaf3SRamaswamy Tummala 	return (DDI_SUCCESS);
15877c478bd9Sstevel@tonic-gate }
15887c478bd9Sstevel@tonic-gate 
15897c478bd9Sstevel@tonic-gate 
15907c478bd9Sstevel@tonic-gate /*
15917c478bd9Sstevel@tonic-gate  * ibnex_config_port_node()
15927c478bd9Sstevel@tonic-gate  *
15937c478bd9Sstevel@tonic-gate  *	Configures a particular port / HCA  node for a particular
15947c478bd9Sstevel@tonic-gate  *	communication service.
15957c478bd9Sstevel@tonic-gate  *	The format of the device_name is
15967c478bd9Sstevel@tonic-gate  *		ibport@<Port#>,<pkey>,<service name>
15977c478bd9Sstevel@tonic-gate  *	where pkey = 0 for port communication service nodes
15987c478bd9Sstevel@tonic-gate  *		  Port# = 0 for HCA_SVC communication service nodes
15997c478bd9Sstevel@tonic-gate  *	Returns "dev_info_t" of the "child" node just created
16007c478bd9Sstevel@tonic-gate  *	NULL when failed to enumerate the child node
16017c478bd9Sstevel@tonic-gate  */
16021cfa752fSRamaswamy Tummala dev_info_t *
16037c478bd9Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname)
16047c478bd9Sstevel@tonic-gate {
16057c478bd9Sstevel@tonic-gate 	int			ii, index;
16067c478bd9Sstevel@tonic-gate 	int			rval;
16077c478bd9Sstevel@tonic-gate 	uint8_t			port_num;
16087c478bd9Sstevel@tonic-gate 	ib_guid_t		hca_guid, port_guid;
16097c478bd9Sstevel@tonic-gate 	ib_pkey_t		pkey;
16107c478bd9Sstevel@tonic-gate 	dev_info_t		*cdip;
16117c478bd9Sstevel@tonic-gate 	ibdm_port_attr_t	*port_attr;
16127c478bd9Sstevel@tonic-gate 	ibdm_hca_list_t		*hca_list;
16137c478bd9Sstevel@tonic-gate 
16147c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname);
16157c478bd9Sstevel@tonic-gate 
16167c478bd9Sstevel@tonic-gate 	if (ibnex_get_pkey_commsvc_index_portnum(devname,
16177c478bd9Sstevel@tonic-gate 	    &index, &pkey, &port_num) != IBNEX_SUCCESS) {
16187c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
16197c478bd9Sstevel@tonic-gate 		    "\tconfig_port_node: Invalid Service Name");
16207c478bd9Sstevel@tonic-gate 		return (NULL);
16217c478bd9Sstevel@tonic-gate 	}
16227c478bd9Sstevel@tonic-gate 
16237c478bd9Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
16247c478bd9Sstevel@tonic-gate 	if (port_num == 0) {
16257c478bd9Sstevel@tonic-gate 		/*
16267c478bd9Sstevel@tonic-gate 		 * Use the dummy port attribute for HCA node in hca_list
16277c478bd9Sstevel@tonic-gate 		 * Note : pa_state is always IBT_PORT_ACTIVE.
16287c478bd9Sstevel@tonic-gate 		 */
16297c478bd9Sstevel@tonic-gate 		hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
16307c478bd9Sstevel@tonic-gate 		ASSERT(hca_list != NULL);
16317c478bd9Sstevel@tonic-gate 		port_attr = hca_list->hl_hca_port_attr;
16327c478bd9Sstevel@tonic-gate 	} else {
16337c478bd9Sstevel@tonic-gate 		if ((port_attr = ibdm_ibnex_probe_hcaport(
16347c478bd9Sstevel@tonic-gate 		    hca_guid, port_num)) == NULL) {
16357c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
16367c478bd9Sstevel@tonic-gate 			    "\tconfig_port_node: Port does not exist");
16377c478bd9Sstevel@tonic-gate 			return (NULL);
16387c478bd9Sstevel@tonic-gate 		}
16397c478bd9Sstevel@tonic-gate 
16407c478bd9Sstevel@tonic-gate 		if (port_attr->pa_state != IBT_PORT_ACTIVE) {
164100a3eaf3SRamaswamy Tummala 			ibdm_ibnex_port_settle_wait(
164200a3eaf3SRamaswamy Tummala 			    hca_guid, ibnex_port_settling_time);
16437c478bd9Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
16447c478bd9Sstevel@tonic-gate 			if ((port_attr = ibdm_ibnex_probe_hcaport(
16457c478bd9Sstevel@tonic-gate 			    hca_guid, port_num)) == NULL) {
16467c478bd9Sstevel@tonic-gate 				return (NULL);
16477c478bd9Sstevel@tonic-gate 			}
16487c478bd9Sstevel@tonic-gate 		}
16497c478bd9Sstevel@tonic-gate 	}
16507c478bd9Sstevel@tonic-gate 
16517c478bd9Sstevel@tonic-gate 	port_guid = port_attr->pa_port_guid;
16527c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
16531cfa752fSRamaswamy Tummala 	rval = ibnex_get_dip_from_guid(port_guid, index, pkey, &cdip);
16541cfa752fSRamaswamy Tummala 	if ((rval == IBNEX_SUCCESS) && cdip != NULL) {
16557c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists");
16567c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
16577c478bd9Sstevel@tonic-gate 		if (port_num != 0)
16587c478bd9Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
16597c478bd9Sstevel@tonic-gate 		else
16607c478bd9Sstevel@tonic-gate 			ibdm_ibnex_free_hca_list(hca_list);
16617c478bd9Sstevel@tonic-gate 		return (cdip);
16627c478bd9Sstevel@tonic-gate 	}
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	if (pkey == 0 && port_num != 0) {
16657c478bd9Sstevel@tonic-gate 		cdip = ibnex_commsvc_initnode(parent,
16667c478bd9Sstevel@tonic-gate 		    port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval,
16677c478bd9Sstevel@tonic-gate 		    IBNEX_DEVFS_ENUMERATE);
16687c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L5("ibnex",
16697c478bd9Sstevel@tonic-gate 		    "\t ibnex_commsvc_initnode rval %x", rval);
16707c478bd9Sstevel@tonic-gate 	} else if (pkey == 0 && port_num == 0) {
16717c478bd9Sstevel@tonic-gate 		cdip = ibnex_commsvc_initnode(parent,
16727c478bd9Sstevel@tonic-gate 		    port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval,
16737c478bd9Sstevel@tonic-gate 		    IBNEX_DEVFS_ENUMERATE);
16747c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L5("ibnex",
16757c478bd9Sstevel@tonic-gate 		    "\t ibnex_commsvc_initnode rval %x", rval);
16767c478bd9Sstevel@tonic-gate 	} else {
16777c478bd9Sstevel@tonic-gate 		if (port_attr->pa_state != IBT_PORT_ACTIVE) {
16787c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: "
16797c478bd9Sstevel@tonic-gate 			    "Port %d is down", port_attr->pa_port_num);
16807c478bd9Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
16817c478bd9Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
16827c478bd9Sstevel@tonic-gate 			return (NULL);
16837c478bd9Sstevel@tonic-gate 		}
16847c478bd9Sstevel@tonic-gate 		for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
16857c478bd9Sstevel@tonic-gate 			if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) {
16867c478bd9Sstevel@tonic-gate 				cdip = ibnex_commsvc_initnode(parent, port_attr,
16877c478bd9Sstevel@tonic-gate 				    index, IBNEX_VPPA_COMMSVC_NODE,
16887c478bd9Sstevel@tonic-gate 				    pkey, &rval, IBNEX_CFGADM_ENUMERATE);
16897c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L5("ibnex",
16907c478bd9Sstevel@tonic-gate 				    "\t ibnex_commsvc_initnode rval %x", rval);
16917c478bd9Sstevel@tonic-gate 				break;
16927c478bd9Sstevel@tonic-gate 			}
16937c478bd9Sstevel@tonic-gate 		}
16947c478bd9Sstevel@tonic-gate 	}
16957c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
16967c478bd9Sstevel@tonic-gate 	if (port_num != 0)
16977c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
16987c478bd9Sstevel@tonic-gate 	else
16997c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_hca_list(hca_list);
17007c478bd9Sstevel@tonic-gate 	return (cdip);
17017c478bd9Sstevel@tonic-gate }
17027c478bd9Sstevel@tonic-gate 
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate /*
17057c478bd9Sstevel@tonic-gate  * ibnex_get_pkey_commsvc_index_portnum()
17067c478bd9Sstevel@tonic-gate  *	Parses the device node name and extracts PKEY, communication
17077c478bd9Sstevel@tonic-gate  *	service index & Port #.
17087c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
17097c478bd9Sstevel@tonic-gate  */
17101cfa752fSRamaswamy Tummala int
17117c478bd9Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index,
17127c478bd9Sstevel@tonic-gate     ib_pkey_t *pkey, uint8_t *port_num)
17137c478bd9Sstevel@tonic-gate {
17147c478bd9Sstevel@tonic-gate 	char 	*srv, **service_name, *temp;
17157c478bd9Sstevel@tonic-gate 	int  	ii, ncommsvcs, ret;
17167c478bd9Sstevel@tonic-gate 
17177c478bd9Sstevel@tonic-gate 	if (ibnex_devname_to_portnum(device_name, port_num) !=
17187c478bd9Sstevel@tonic-gate 	    IBNEX_SUCCESS) {
17197c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
1720d88af761SRajkumar Sivaprakasam 		    "\tget_pkey_commsvc_index_portnum: Invalid Service Name");
1721d88af761SRajkumar Sivaprakasam 		return (IBNEX_FAILURE);
17227c478bd9Sstevel@tonic-gate 	}
17237c478bd9Sstevel@tonic-gate 	srv = strchr(device_name, ',');
17247c478bd9Sstevel@tonic-gate 	if (srv == 0)
17257c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
17267c478bd9Sstevel@tonic-gate 
17277c478bd9Sstevel@tonic-gate 	srv++;
17287c478bd9Sstevel@tonic-gate 	temp = strchr(srv, ',');
17297c478bd9Sstevel@tonic-gate 	if (temp == 0)
17307c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
17317c478bd9Sstevel@tonic-gate 	temp++;
17327c478bd9Sstevel@tonic-gate 	*pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret);
17337c478bd9Sstevel@tonic-gate 	if (ret != IBNEX_SUCCESS)
17347c478bd9Sstevel@tonic-gate 		return (ret);
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate 	if (*pkey == 0 && *port_num != 0) {
17377c478bd9Sstevel@tonic-gate 		service_name = ibnex.ibnex_comm_svc_names;
17387c478bd9Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_num_comm_svcs;
17397c478bd9Sstevel@tonic-gate 	} else if (*pkey == 0 && *port_num == 0) {
17407c478bd9Sstevel@tonic-gate 		service_name = ibnex.ibnex_hcasvc_comm_svc_names;
17417c478bd9Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs;
17427c478bd9Sstevel@tonic-gate 	} else {
17437c478bd9Sstevel@tonic-gate 		service_name = ibnex.ibnex_vppa_comm_svc_names;
17447c478bd9Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_nvppa_comm_svcs;
17457c478bd9Sstevel@tonic-gate 	}
17467c478bd9Sstevel@tonic-gate 
17477c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < ncommsvcs; ii++) {
17487c478bd9Sstevel@tonic-gate 		if (strcmp(service_name[ii], temp) == 0) {
17497c478bd9Sstevel@tonic-gate 			break;
17507c478bd9Sstevel@tonic-gate 		}
17517c478bd9Sstevel@tonic-gate 	}
17527c478bd9Sstevel@tonic-gate 	if (ii == ncommsvcs)
17537c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
17547c478bd9Sstevel@tonic-gate 
17557c478bd9Sstevel@tonic-gate 	*index = ii;
17567c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
17577c478bd9Sstevel@tonic-gate }
17587c478bd9Sstevel@tonic-gate 
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate /*
17617c478bd9Sstevel@tonic-gate  * ibnex_devname_to_portnum()
17627c478bd9Sstevel@tonic-gate  *	Get portguid from device name
17637c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
17647c478bd9Sstevel@tonic-gate  */
17657c478bd9Sstevel@tonic-gate static int
17667c478bd9Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum)
17677c478bd9Sstevel@tonic-gate {
17687c478bd9Sstevel@tonic-gate 	int	ret;
17697c478bd9Sstevel@tonic-gate 	char	*temp1, *temp2;
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 	temp1 = strchr(device_name, '@');
17727c478bd9Sstevel@tonic-gate 	if (temp1 == NULL) {
17737c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
17747c478bd9Sstevel@tonic-gate 	}
17757c478bd9Sstevel@tonic-gate 	temp2 = strchr(temp1, ',');
17767c478bd9Sstevel@tonic-gate 	if (temp2 == NULL)
17777c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
17787c478bd9Sstevel@tonic-gate 	temp1++;
17797c478bd9Sstevel@tonic-gate 	*portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret);
17807c478bd9Sstevel@tonic-gate 	return (ret);
17817c478bd9Sstevel@tonic-gate }
17827c478bd9Sstevel@tonic-gate 
17837c478bd9Sstevel@tonic-gate 
17847c478bd9Sstevel@tonic-gate /*
17857c478bd9Sstevel@tonic-gate  * ibnex_config_ioc_node()
17867c478bd9Sstevel@tonic-gate  *	Configures one particular instance of the IOC driver.
17877c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
17887c478bd9Sstevel@tonic-gate  */
17897c478bd9Sstevel@tonic-gate static int
17909d3d2ed0Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip)
17917c478bd9Sstevel@tonic-gate {
17927c478bd9Sstevel@tonic-gate 	int			ret;
17937c478bd9Sstevel@tonic-gate 	ib_guid_t		iou_guid, ioc_guid;
17947c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin");
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 	if (ibnex_devname_to_node_n_ioc_guids(
17999d3d2ed0Shiremath 	    device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
18007c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
18017c478bd9Sstevel@tonic-gate 	}
18027c478bd9Sstevel@tonic-gate 
180300a3eaf3SRamaswamy Tummala 	ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
18047c478bd9Sstevel@tonic-gate 
18057c478bd9Sstevel@tonic-gate 	if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) ==
18067c478bd9Sstevel@tonic-gate 	    NULL) {
18077c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc_info);
18087c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
18097c478bd9Sstevel@tonic-gate 	}
18107c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
181100a3eaf3SRamaswamy Tummala 	ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0);
18127c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
18137c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
181400a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x",
181500a3eaf3SRamaswamy Tummala 	    ret);
18167c478bd9Sstevel@tonic-gate 	return (ret);
18177c478bd9Sstevel@tonic-gate }
18187c478bd9Sstevel@tonic-gate 
18197c478bd9Sstevel@tonic-gate 
18207c478bd9Sstevel@tonic-gate /*
18217c478bd9Sstevel@tonic-gate  * ibnex_devname_to_node_n_ioc_guids()
18227c478bd9Sstevel@tonic-gate  *	Get node guid and ioc guid from the device name
18237c478bd9Sstevel@tonic-gate  *	Format of the device node name is:
18247c478bd9Sstevel@tonic-gate  *		ioc@<IOC GUID>,<IOU GUID>
18257c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
18267c478bd9Sstevel@tonic-gate  */
18277c478bd9Sstevel@tonic-gate static int
18287c478bd9Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids(
18299d3d2ed0Shiremath     char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid,
18309d3d2ed0Shiremath     char **ioc_guid_strp)
18317c478bd9Sstevel@tonic-gate {
18327c478bd9Sstevel@tonic-gate 	char	*temp1, *temp;
18337c478bd9Sstevel@tonic-gate 	int	len, ret;
18349d3d2ed0Shiremath 	char	*ioc_guid_str;
18357c478bd9Sstevel@tonic-gate 
18367c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:"
18377c478bd9Sstevel@tonic-gate 	    "Device Name %s", device_name);
18387c478bd9Sstevel@tonic-gate 
18397c478bd9Sstevel@tonic-gate 	if ((temp = strchr(device_name, '@')) == NULL) {
18407c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
18417c478bd9Sstevel@tonic-gate 	}
18427c478bd9Sstevel@tonic-gate 	if ((temp1 = strchr(++temp, ',')) == NULL) {
18437c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
18447c478bd9Sstevel@tonic-gate 	}
18457c478bd9Sstevel@tonic-gate 	*ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret);
18467c478bd9Sstevel@tonic-gate 	if (ret == IBNEX_SUCCESS) {
18479d3d2ed0Shiremath 		if (ioc_guid_strp) {
18489d3d2ed0Shiremath 			ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1
18499d3d2ed0Shiremath 			    - temp) + 1, KM_SLEEP);
18509d3d2ed0Shiremath 			(void) strncpy(ioc_guid_str, temp, temp1 - temp + 1);
18519d3d2ed0Shiremath 			ioc_guid_str[temp1 - temp] = '\0';
18529d3d2ed0Shiremath 		}
18537c478bd9Sstevel@tonic-gate 		len = device_name + strlen(device_name) - ++temp1;
18547c478bd9Sstevel@tonic-gate 		*iou_guid = ibnex_str2hex(temp1, len, &ret);
18557c478bd9Sstevel@tonic-gate 	}
18567c478bd9Sstevel@tonic-gate 	return (ret);
18577c478bd9Sstevel@tonic-gate }
18587c478bd9Sstevel@tonic-gate 
18597c478bd9Sstevel@tonic-gate 
18607c478bd9Sstevel@tonic-gate /*
18617c478bd9Sstevel@tonic-gate  * ibnex_ioc_initnode()
18627c478bd9Sstevel@tonic-gate  *	Allocate a pathinfo node for the IOC
18637c478bd9Sstevel@tonic-gate  *	Initialize the device node
18647c478bd9Sstevel@tonic-gate  *	Bind driver to the node
18657c478bd9Sstevel@tonic-gate  *	Update IBnex global data
18667c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY
18677c478bd9Sstevel@tonic-gate  */
186800a3eaf3SRamaswamy Tummala static int
186900a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data,
187000a3eaf3SRamaswamy Tummala     ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
18717c478bd9Sstevel@tonic-gate {
187200a3eaf3SRamaswamy Tummala 	int			rval, node_valid;
187300a3eaf3SRamaswamy Tummala 	ibnex_node_state_t	prev_state;
18747c478bd9Sstevel@tonic-gate 
18757c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
187600a3eaf3SRamaswamy Tummala 	ASSERT(node_data);
18777c478bd9Sstevel@tonic-gate 
18787c478bd9Sstevel@tonic-gate 
18797c478bd9Sstevel@tonic-gate 	/*
18807c478bd9Sstevel@tonic-gate 	 * Return EBUSY if another configure/unconfigure
18817c478bd9Sstevel@tonic-gate 	 * operation is in progress
18827c478bd9Sstevel@tonic-gate 	 */
18837c478bd9Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
188400a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
188500a3eaf3SRamaswamy Tummala 		    "\tioc_initnode_pdip : BUSY");
18867c478bd9Sstevel@tonic-gate 		return (IBNEX_BUSY);
18877c478bd9Sstevel@tonic-gate 	}
18887c478bd9Sstevel@tonic-gate 
188900a3eaf3SRamaswamy Tummala 	prev_state = node_data->node_state;
18907c478bd9Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
18917c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
18927c478bd9Sstevel@tonic-gate 
189300a3eaf3SRamaswamy Tummala 	rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid);
18947c478bd9Sstevel@tonic-gate 
18957c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
18967c478bd9Sstevel@tonic-gate 	if (rval == IBNEX_SUCCESS)
18977c478bd9Sstevel@tonic-gate 		node_data->node_state = IBNEX_CFGADM_CONFIGURED;
189800a3eaf3SRamaswamy Tummala 	else if (node_valid)
189900a3eaf3SRamaswamy Tummala 		node_data->node_state = prev_state;
19007c478bd9Sstevel@tonic-gate 
19017c478bd9Sstevel@tonic-gate 	return (rval);
19027c478bd9Sstevel@tonic-gate }
19037c478bd9Sstevel@tonic-gate 
19047c478bd9Sstevel@tonic-gate /*
19057c478bd9Sstevel@tonic-gate  * ibnex_config_pseudo_all()
19067c478bd9Sstevel@tonic-gate  *	Configure all the pseudo nodes
19077c478bd9Sstevel@tonic-gate  */
19087c478bd9Sstevel@tonic-gate static void
19099d3d2ed0Shiremath ibnex_config_pseudo_all(dev_info_t *pdip)
19107c478bd9Sstevel@tonic-gate {
19117c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
19127c478bd9Sstevel@tonic-gate 
19137c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
19147c478bd9Sstevel@tonic-gate 
19157c478bd9Sstevel@tonic-gate 	for (nodep = ibnex.ibnex_pseudo_node_head;
19167c478bd9Sstevel@tonic-gate 	    nodep; nodep = nodep->node_next) {
191705fa0d51Spramodbg 		(void) ibnex_pseudo_config_one(nodep, NULL, pdip);
19187c478bd9Sstevel@tonic-gate 	}
19197c478bd9Sstevel@tonic-gate }
19207c478bd9Sstevel@tonic-gate 
19217c478bd9Sstevel@tonic-gate 
19227c478bd9Sstevel@tonic-gate /*
19237c478bd9Sstevel@tonic-gate  * ibnex_pseudo_config_one()
19247c478bd9Sstevel@tonic-gate  */
19251cfa752fSRamaswamy Tummala int
192605fa0d51Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr,
19279d3d2ed0Shiremath     dev_info_t *pdip)
19287c478bd9Sstevel@tonic-gate {
192905fa0d51Spramodbg 	int			rval;
193000a3eaf3SRamaswamy Tummala 	ibnex_pseudo_node_t	*pseudo;
193100a3eaf3SRamaswamy Tummala 	ibnex_node_state_t	prev_state;
19327c478bd9Sstevel@tonic-gate 
193300a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)",
193405fa0d51Spramodbg 	    node_data, caddr, pdip);
19357c478bd9Sstevel@tonic-gate 
19367c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
19377c478bd9Sstevel@tonic-gate 
19387c478bd9Sstevel@tonic-gate 	if (node_data == NULL) {
193900a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
194000a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: caddr = %s", caddr);
19417c478bd9Sstevel@tonic-gate 
194205fa0d51Spramodbg 		/*
194305fa0d51Spramodbg 		 * This function is now called with PHCI / HCA driver
194405fa0d51Spramodbg 		 * as parent. The format of devicename is :
194505fa0d51Spramodbg 		 * 	<driver_name>@<driver_name>,<unit_address>
194605fa0d51Spramodbg 		 * The "caddr" part of the devicename matches the
194705fa0d51Spramodbg 		 * format of pseudo_node_addr.
194805fa0d51Spramodbg 		 *
194905fa0d51Spramodbg 		 * Use "caddr" to find a matching Pseudo node entry.
195005fa0d51Spramodbg 		 */
19517c478bd9Sstevel@tonic-gate 		node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
195205fa0d51Spramodbg 		    (void *)caddr, 0, 0);
19537c478bd9Sstevel@tonic-gate 	}
19547c478bd9Sstevel@tonic-gate 
195500a3eaf3SRamaswamy Tummala 	if (node_data == NULL) {
195600a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
195700a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: Invalid node");
195800a3eaf3SRamaswamy Tummala 		return (IBNEX_FAILURE);
195900a3eaf3SRamaswamy Tummala 	}
196000a3eaf3SRamaswamy Tummala 
196100a3eaf3SRamaswamy Tummala 	if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) {
196200a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
196300a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: Unconfigured node");
196400a3eaf3SRamaswamy Tummala 		return (IBNEX_FAILURE);
196500a3eaf3SRamaswamy Tummala 	}
196600a3eaf3SRamaswamy Tummala 
196700a3eaf3SRamaswamy Tummala 	pseudo = &node_data->node_data.pseudo_node;
196800a3eaf3SRamaswamy Tummala 
19697c478bd9Sstevel@tonic-gate 	/*
19709d3d2ed0Shiremath 	 * Do not enumerate nodes with ib-node-type set as "merge"
19719d3d2ed0Shiremath 	 */
197200a3eaf3SRamaswamy Tummala 	if (pseudo->pseudo_merge_node == 1) {
197300a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
197400a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: merge_node");
19759d3d2ed0Shiremath 		return (IBNEX_FAILURE);
19769d3d2ed0Shiremath 	}
19779d3d2ed0Shiremath 
19789d3d2ed0Shiremath 	/*
197900a3eaf3SRamaswamy Tummala 	 * Check if a PI has already been created for the PDIP.
198000a3eaf3SRamaswamy Tummala 	 * If so, return SUCCESS.
19817c478bd9Sstevel@tonic-gate 	 */
198200a3eaf3SRamaswamy Tummala 	if (node_data->node_dip != NULL && mdi_pi_find(pdip,
198300a3eaf3SRamaswamy Tummala 	    pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) {
198400a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
198500a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: PI created,"
198600a3eaf3SRamaswamy Tummala 		    " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr);
198700a3eaf3SRamaswamy Tummala 		return (IBNEX_SUCCESS);
19887c478bd9Sstevel@tonic-gate 	}
19897c478bd9Sstevel@tonic-gate 
19907c478bd9Sstevel@tonic-gate 	/*
199100a3eaf3SRamaswamy Tummala 	 * Return EBUSY if another unconfigure
19927c478bd9Sstevel@tonic-gate 	 * operation is in progress
19937c478bd9Sstevel@tonic-gate 	 */
19947c478bd9Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
199500a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
199600a3eaf3SRamaswamy Tummala 		    "\tpseudo_config_one: BUSY");
19977c478bd9Sstevel@tonic-gate 		return (IBNEX_BUSY);
19987c478bd9Sstevel@tonic-gate 	}
19997c478bd9Sstevel@tonic-gate 
20007c478bd9Sstevel@tonic-gate 
200100a3eaf3SRamaswamy Tummala 	prev_state = node_data->node_state;
20027c478bd9Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
200500a3eaf3SRamaswamy Tummala 	rval = ibnex_pseudo_create_pi_pdip(node_data, pdip);
20067c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
20077c478bd9Sstevel@tonic-gate 
200800a3eaf3SRamaswamy Tummala 	if (rval == IBNEX_SUCCESS) {
20097c478bd9Sstevel@tonic-gate 		node_data->node_state = IBNEX_CFGADM_CONFIGURED;
201000a3eaf3SRamaswamy Tummala 	} else {
201100a3eaf3SRamaswamy Tummala 		node_data->node_state = prev_state;
20127c478bd9Sstevel@tonic-gate 	}
20137c478bd9Sstevel@tonic-gate 
201400a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x",
201500a3eaf3SRamaswamy Tummala 	    rval);
20167c478bd9Sstevel@tonic-gate 	return (rval);
20177c478bd9Sstevel@tonic-gate }
20187c478bd9Sstevel@tonic-gate 
20197c478bd9Sstevel@tonic-gate 
20209d3d2ed0Shiremath /*
20219d3d2ed0Shiremath  * ibnex_pseudo_mdi_config_one()
20229d3d2ed0Shiremath  *	This is similar to ibnex_pseudo_config_one. Few
20239d3d2ed0Shiremath  *	differences :
20249d3d2ed0Shiremath  *	1. parent device lock not held(no ndi_devi_enter)
20259d3d2ed0Shiremath  *	2. Called for IB Nexus as parent, not IB HCA as
20269d3d2ed0Shiremath  *	   parent.
20279d3d2ed0Shiremath  *	3. Calls mdi_vhci_bus_config()
202805fa0d51Spramodbg  * This function skips checks for node_state, initializing
202905fa0d51Spramodbg  * node_state, node_dip, etc. These checks and initializations
203005fa0d51Spramodbg  * are done when BUS_CONFIG is called with PHCI as the parent.
20319d3d2ed0Shiremath  */
20321cfa752fSRamaswamy Tummala int
20339d3d2ed0Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child,
20349d3d2ed0Shiremath     char *cname, char *caddr)
20359d3d2ed0Shiremath {
20369d3d2ed0Shiremath 	int			rval, len;
20379d3d2ed0Shiremath 	char			*node_addr;
20389d3d2ed0Shiremath 	ibnex_node_data_t	*node_data;
20399d3d2ed0Shiremath 
20409d3d2ed0Shiremath 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:"
20419d3d2ed0Shiremath 	    "cname = %s caddr = %s", cname, caddr);
20429d3d2ed0Shiremath 
20439d3d2ed0Shiremath 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
20449d3d2ed0Shiremath 
20459d3d2ed0Shiremath 	len = strlen(cname) + strlen(caddr) + 2;
20469d3d2ed0Shiremath 	node_addr = (char *)kmem_alloc(len, KM_SLEEP);
20479d3d2ed0Shiremath 
20489d3d2ed0Shiremath 	(void) snprintf(node_addr, len, "%s,%s", cname, caddr);
20499d3d2ed0Shiremath 	node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
20509d3d2ed0Shiremath 	    (void *)node_addr, 0, 0);
20519d3d2ed0Shiremath 	kmem_free(node_addr, len);
20529d3d2ed0Shiremath 
205305fa0d51Spramodbg 	if (node_data == NULL) {
20549d3d2ed0Shiremath 		IBTF_DPRINTF_L2("ibnex",
20559d3d2ed0Shiremath 		    "\tpseudo_mdi_config_one: Invalid node");
20569d3d2ed0Shiremath 		return (IBNEX_FAILURE);
20579d3d2ed0Shiremath 	}
20589d3d2ed0Shiremath 
20599d3d2ed0Shiremath 	mutex_exit(&ibnex.ibnex_mutex);
20609d3d2ed0Shiremath 	rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE,
20619d3d2ed0Shiremath 	    devname, child, node_data->node_data.pseudo_node.pseudo_node_addr);
20629d3d2ed0Shiremath 	mutex_enter(&ibnex.ibnex_mutex);
20639d3d2ed0Shiremath 
20649d3d2ed0Shiremath 	return (rval);
20659d3d2ed0Shiremath }
20669d3d2ed0Shiremath 
206700a3eaf3SRamaswamy Tummala 
20687c478bd9Sstevel@tonic-gate /*
206900a3eaf3SRamaswamy Tummala  * ibnex_pseudo_create_all_pi()
207000a3eaf3SRamaswamy Tummala  *	Create all path infos node for a pseudo entry
20717c478bd9Sstevel@tonic-gate  */
20727c478bd9Sstevel@tonic-gate int
207300a3eaf3SRamaswamy Tummala ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep)
20747c478bd9Sstevel@tonic-gate {
207500a3eaf3SRamaswamy Tummala 	int		hcacnt, rc;
207600a3eaf3SRamaswamy Tummala 	int		hcafailcnt = 0;
207700a3eaf3SRamaswamy Tummala 	dev_info_t	*hca_dip;
20787c478bd9Sstevel@tonic-gate 	ibdm_hca_list_t	*hca_list, *head;
20797c478bd9Sstevel@tonic-gate 
208000a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)",
208100a3eaf3SRamaswamy Tummala 	    nodep);
20827c478bd9Sstevel@tonic-gate 	ibdm_ibnex_get_hca_list(&hca_list, &hcacnt);
20837c478bd9Sstevel@tonic-gate 
20847c478bd9Sstevel@tonic-gate 	head = hca_list;
20857c478bd9Sstevel@tonic-gate 
20869d3d2ed0Shiremath 	/*
208700a3eaf3SRamaswamy Tummala 	 * We return failure even if we fail for all HCAs.
20889d3d2ed0Shiremath 	 */
208900a3eaf3SRamaswamy Tummala 	for (; hca_list != NULL; hca_list = hca_list->hl_next) {
209000a3eaf3SRamaswamy Tummala 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
209100a3eaf3SRamaswamy Tummala 		rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip);
209200a3eaf3SRamaswamy Tummala 		if (rc != IBNEX_SUCCESS)
209300a3eaf3SRamaswamy Tummala 			hcafailcnt++;
209400a3eaf3SRamaswamy Tummala 	}
209500a3eaf3SRamaswamy Tummala 	if (head)
209600a3eaf3SRamaswamy Tummala 		ibdm_ibnex_free_hca_list(head);
209700a3eaf3SRamaswamy Tummala 
209800a3eaf3SRamaswamy Tummala 	if (hcafailcnt == hcacnt)
209900a3eaf3SRamaswamy Tummala 		rc = IBNEX_FAILURE;
210000a3eaf3SRamaswamy Tummala 	else
210100a3eaf3SRamaswamy Tummala 		rc = IBNEX_SUCCESS;
210200a3eaf3SRamaswamy Tummala 
210300a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x",
210400a3eaf3SRamaswamy Tummala 	    rc);
210500a3eaf3SRamaswamy Tummala 	return (rc);
210600a3eaf3SRamaswamy Tummala }
210700a3eaf3SRamaswamy Tummala 
210800a3eaf3SRamaswamy Tummala static int
210900a3eaf3SRamaswamy Tummala ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip)
211000a3eaf3SRamaswamy Tummala {
211100a3eaf3SRamaswamy Tummala 	mdi_pathinfo_t		*pip;
211200a3eaf3SRamaswamy Tummala 	int			rval;
211300a3eaf3SRamaswamy Tummala 	dev_info_t		*cdip = NULL;
211400a3eaf3SRamaswamy Tummala 	ibnex_pseudo_node_t	*pseudo;
211500a3eaf3SRamaswamy Tummala 	int			first_pi = 0;
211600a3eaf3SRamaswamy Tummala 
211700a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p",
211800a3eaf3SRamaswamy Tummala 	    nodep, hca_dip);
211900a3eaf3SRamaswamy Tummala 
212000a3eaf3SRamaswamy Tummala 	pseudo = &nodep->node_data.pseudo_node;
21219d3d2ed0Shiremath 
21227c478bd9Sstevel@tonic-gate 	rval = mdi_pi_alloc(hca_dip,
21237c478bd9Sstevel@tonic-gate 	    pseudo->pseudo_devi_name, pseudo->pseudo_node_addr,
21247c478bd9Sstevel@tonic-gate 	    pseudo->pseudo_node_addr, 0, &pip);
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate 	if (rval != MDI_SUCCESS) {
212700a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:"
212800a3eaf3SRamaswamy Tummala 		    " mdi_pi_alloc failed");
21297c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
21307c478bd9Sstevel@tonic-gate 	}
21317c478bd9Sstevel@tonic-gate 	cdip = mdi_pi_get_client(pip);
21327c478bd9Sstevel@tonic-gate 
213300a3eaf3SRamaswamy Tummala 	if (nodep->node_dip == NULL) {
21347c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
21357c478bd9Sstevel@tonic-gate 		    "\tpseudo_create_pi: New dip %p", cdip);
21367c478bd9Sstevel@tonic-gate 
213700a3eaf3SRamaswamy Tummala 		first_pi = 1;
21387c478bd9Sstevel@tonic-gate 		nodep->node_dip = cdip;
21397c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(cdip, nodep);
214000a3eaf3SRamaswamy Tummala 	}
21417c478bd9Sstevel@tonic-gate 
21427c478bd9Sstevel@tonic-gate 	rval = mdi_pi_online(pip, 0);
21437c478bd9Sstevel@tonic-gate 
21447c478bd9Sstevel@tonic-gate 	if (rval != MDI_SUCCESS) {
214500a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
214600a3eaf3SRamaswamy Tummala 		    "\tpseudo_create_pi: "
21477c478bd9Sstevel@tonic-gate 		    "mdi_pi_online: failed for pseudo dip %p,"
21487c478bd9Sstevel@tonic-gate 		    " rval %d", cdip, rval);
21497c478bd9Sstevel@tonic-gate 		rval = IBNEX_FAILURE;
215000a3eaf3SRamaswamy Tummala 		if (first_pi == 1) {
215100a3eaf3SRamaswamy Tummala 			ddi_set_parent_data(cdip, NULL);
215200a3eaf3SRamaswamy Tummala 			(void) ibnex_offline_childdip(cdip);
215300a3eaf3SRamaswamy Tummala 			nodep->node_dip = NULL;
215400a3eaf3SRamaswamy Tummala 		} else
215500a3eaf3SRamaswamy Tummala 			(void) mdi_pi_free(pip, 0);
21567c478bd9Sstevel@tonic-gate 	} else
21577c478bd9Sstevel@tonic-gate 		rval = IBNEX_SUCCESS;
21587c478bd9Sstevel@tonic-gate 	return (rval);
21597c478bd9Sstevel@tonic-gate }
21607c478bd9Sstevel@tonic-gate 
21617c478bd9Sstevel@tonic-gate /*
21627c478bd9Sstevel@tonic-gate  * ibnex_ioc_create_pi()
21637c478bd9Sstevel@tonic-gate  *	Create a pathinfo node for the ioc node
21647c478bd9Sstevel@tonic-gate  */
21657c478bd9Sstevel@tonic-gate static int
21669d3d2ed0Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data,
216700a3eaf3SRamaswamy Tummala     dev_info_t *pdip, int *node_valid)
21687c478bd9Sstevel@tonic-gate {
21697c478bd9Sstevel@tonic-gate 	mdi_pathinfo_t		*pip;
21709d3d2ed0Shiremath 	int			rval = DDI_FAILURE;
217100a3eaf3SRamaswamy Tummala 	dev_info_t		*cdip = NULL;
217200a3eaf3SRamaswamy Tummala 	int			create_prop = 0;
217300a3eaf3SRamaswamy Tummala 	ibnex_ioc_node_t	*ioc = &node_data->node_data.ioc_node;
21747c478bd9Sstevel@tonic-gate 
217500a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex",
217600a3eaf3SRamaswamy Tummala 	    "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip);
217700a3eaf3SRamaswamy Tummala 	*node_valid = 1;
21787c478bd9Sstevel@tonic-gate 
21799d3d2ed0Shiremath 	/*
21809d3d2ed0Shiremath 	 * For CONFIG_ONE requests through HCA dip, alloc
21819d3d2ed0Shiremath 	 * for HCA dip driving BUS_CONFIG request.
21829d3d2ed0Shiremath 	 */
218300a3eaf3SRamaswamy Tummala 	rval =  mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str,
218400a3eaf3SRamaswamy Tummala 	    ioc->ioc_phci_guid, 0, &pip);
21857c478bd9Sstevel@tonic-gate 	if (rval != MDI_SUCCESS) {
218600a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L2("ibnex",
218700a3eaf3SRamaswamy Tummala 		    "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed",
218800a3eaf3SRamaswamy Tummala 		    pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid);
21897c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
21907c478bd9Sstevel@tonic-gate 	}
21917c478bd9Sstevel@tonic-gate 	cdip = mdi_pi_get_client(pip);
21927c478bd9Sstevel@tonic-gate 
219300a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p",
219400a3eaf3SRamaswamy Tummala 	    cdip);
21957c478bd9Sstevel@tonic-gate 
219600a3eaf3SRamaswamy Tummala 	if (node_data->node_dip == NULL) {
21977c478bd9Sstevel@tonic-gate 		node_data->node_dip = cdip;
21987c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(cdip, node_data);
219900a3eaf3SRamaswamy Tummala 		create_prop = 1;
220000a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
220100a3eaf3SRamaswamy Tummala 		    "\tioc_create_pi: creating prop");
22027c478bd9Sstevel@tonic-gate 		if ((rval = ibnex_create_ioc_node_prop(
22037c478bd9Sstevel@tonic-gate 		    ioc_info, cdip)) != IBNEX_SUCCESS) {
220400a3eaf3SRamaswamy Tummala 			IBTF_DPRINTF_L4("ibnex",
220500a3eaf3SRamaswamy Tummala 			    "\tioc_create_pi: creating prop failed");
22067c478bd9Sstevel@tonic-gate 			ibnex_delete_ioc_node_data(node_data);
220700a3eaf3SRamaswamy Tummala 			*node_valid = 0;
22087c478bd9Sstevel@tonic-gate 			ddi_prop_remove_all(cdip);
22097c478bd9Sstevel@tonic-gate 			ddi_set_parent_data(cdip, NULL);
22107c478bd9Sstevel@tonic-gate 
22117c478bd9Sstevel@tonic-gate 			(void) ibnex_offline_childdip(cdip);
22127c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
22137c478bd9Sstevel@tonic-gate 		}
22147c478bd9Sstevel@tonic-gate 	}
22157c478bd9Sstevel@tonic-gate 
22167c478bd9Sstevel@tonic-gate 	rval = mdi_pi_online(pip, 0);
22177c478bd9Sstevel@tonic-gate 
22187c478bd9Sstevel@tonic-gate 	if (rval != MDI_SUCCESS) {
22197c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: "
22207c478bd9Sstevel@tonic-gate 		    "mdi_pi_online() failed ioc dip %p, rval %d",
22217c478bd9Sstevel@tonic-gate 		    cdip, rval);
22227c478bd9Sstevel@tonic-gate 		rval = IBNEX_FAILURE;
222300a3eaf3SRamaswamy Tummala 		if (create_prop) {
222400a3eaf3SRamaswamy Tummala 			ddi_set_parent_data(cdip, NULL);
222500a3eaf3SRamaswamy Tummala 			ddi_prop_remove_all(cdip);
222600a3eaf3SRamaswamy Tummala 			ibnex_delete_ioc_node_data(node_data);
222700a3eaf3SRamaswamy Tummala 			*node_valid = 0;
222800a3eaf3SRamaswamy Tummala 			(void) ibnex_offline_childdip(cdip);
222900a3eaf3SRamaswamy Tummala 		} else
223000a3eaf3SRamaswamy Tummala 			(void) mdi_pi_free(pip, 0);
22317c478bd9Sstevel@tonic-gate 	} else
22327c478bd9Sstevel@tonic-gate 		rval = IBNEX_SUCCESS;
22339d3d2ed0Shiremath 
223400a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval);
22357c478bd9Sstevel@tonic-gate 	return (rval);
22367c478bd9Sstevel@tonic-gate }
22377c478bd9Sstevel@tonic-gate 
22387c478bd9Sstevel@tonic-gate 
22397c478bd9Sstevel@tonic-gate /*
22407c478bd9Sstevel@tonic-gate  * ibnex_create_ioc_node_prop()
22417c478bd9Sstevel@tonic-gate  *	Create IOC device node properties
22427c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
22437c478bd9Sstevel@tonic-gate  */
22447c478bd9Sstevel@tonic-gate static int
22457c478bd9Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip)
22467c478bd9Sstevel@tonic-gate {
22477c478bd9Sstevel@tonic-gate 	uint16_t		 capabilities;
22487c478bd9Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile;
22497c478bd9Sstevel@tonic-gate 
22507c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop");
22517c478bd9Sstevel@tonic-gate 
22527c478bd9Sstevel@tonic-gate 	if (ibnex_create_ioc_compatible_prop(cdip,
22537c478bd9Sstevel@tonic-gate 	    ioc_profile) != IBNEX_SUCCESS) {
22547c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22557c478bd9Sstevel@tonic-gate 	}
22567c478bd9Sstevel@tonic-gate 	if ((ioc_info->ioc_iou_dc_valid) &&
22577c478bd9Sstevel@tonic-gate 	    (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode",
22587c478bd9Sstevel@tonic-gate 	    ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) {
22597c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
22607c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: iou-diagcode create failed");
22617c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22627c478bd9Sstevel@tonic-gate 	}
22637c478bd9Sstevel@tonic-gate 	if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) {
22647c478bd9Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode",
22657c478bd9Sstevel@tonic-gate 		    ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) {
22667c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
22677c478bd9Sstevel@tonic-gate 			    "ioc-diagcode create failed");
22687c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
22697c478bd9Sstevel@tonic-gate 		}
22707c478bd9Sstevel@tonic-gate 	}
22717c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth",
22727c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) {
22737c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
22747c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: rdma-queue-depth create failed");
22757c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22767c478bd9Sstevel@tonic-gate 	}
22777c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size",
22787c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) {
22797c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
22807c478bd9Sstevel@tonic-gate 		    "rdma-transfer-size create failed");
22817c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22827c478bd9Sstevel@tonic-gate 	}
22837c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size",
22847c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) {
22857c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
22867c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: send-message-size create failed");
22877c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22887c478bd9Sstevel@tonic-gate 	}
22897c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth",
22907c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) {
22917c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
22927c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: send-queue-depth create failed");
22937c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22947c478bd9Sstevel@tonic-gate 	}
22957c478bd9Sstevel@tonic-gate 
22967c478bd9Sstevel@tonic-gate 	capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8);
22977c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip,
22987c478bd9Sstevel@tonic-gate 	    "capabilities", capabilities) != DDI_PROP_SUCCESS) {
22997c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23007c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: capabilities create failed");
23017c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23027c478bd9Sstevel@tonic-gate 	}
23037c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string",
23047c478bd9Sstevel@tonic-gate 	    (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) {
23057c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23067c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: id-string failed");
23077c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23087c478bd9Sstevel@tonic-gate 	}
23097c478bd9Sstevel@tonic-gate 
23107c478bd9Sstevel@tonic-gate 	/*
23117c478bd9Sstevel@tonic-gate 	 * Create properties to represent all the service entries supported
23127c478bd9Sstevel@tonic-gate 	 * by the IOC. Each service entry consists of 1) Service ID (64 bits)
23137c478bd9Sstevel@tonic-gate 	 * and 2) Service name (40 bytes). The service entry table is
23147c478bd9Sstevel@tonic-gate 	 * represented by two properties, service-ids and service-names. The
23157c478bd9Sstevel@tonic-gate 	 * service-id property is a array of int64's and service names is
23167c478bd9Sstevel@tonic-gate 	 * array of strings. The first element in the "service-ids" property
23177c478bd9Sstevel@tonic-gate 	 * corresponds to first string in the "service-names" and so on.
23187c478bd9Sstevel@tonic-gate 	 */
23197c478bd9Sstevel@tonic-gate 	if ((ioc_profile->ioc_service_entries != 0) &&
23207c478bd9Sstevel@tonic-gate 	    (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS))
23217c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23227c478bd9Sstevel@tonic-gate 
23237c478bd9Sstevel@tonic-gate 	/* Create destination port GID properties */
23247c478bd9Sstevel@tonic-gate 	if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS)
23257c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23267c478bd9Sstevel@tonic-gate 
23277c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version",
23287c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) {
23297c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23307c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol-version create failed");
23317c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23327c478bd9Sstevel@tonic-gate 	}
23337c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol",
23347c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) {
23357c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23367c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol create failed");
23377c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23387c478bd9Sstevel@tonic-gate 	}
23397c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass",
23407c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) {
23417c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23427c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subclass create failed");
23437c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23447c478bd9Sstevel@tonic-gate 	}
23457c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class",
23467c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) {
23477c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23487c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: class prop create failed");
23497c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23507c478bd9Sstevel@tonic-gate 	}
23517c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id",
23527c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) {
23537c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23547c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subsys_id create failed");
23557c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23567c478bd9Sstevel@tonic-gate 	}
23577c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id",
23587c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) {
23597c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23607c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subsystem vendor create failed");
23617c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23627c478bd9Sstevel@tonic-gate 	}
23637c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid",
23647c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) {
23657c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23667c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol create failed");
23677c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23687c478bd9Sstevel@tonic-gate 	}
23697c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version",
23707c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) {
23717c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23727c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: product-id create failed");
23737c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23747c478bd9Sstevel@tonic-gate 	}
23757c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id",
23767c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) {
23777c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23787c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: product-id create failed");
23797c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23807c478bd9Sstevel@tonic-gate 	}
23817c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id",
23827c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) {
23837c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
23847c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: vendor-id create failed");
23857c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
23867c478bd9Sstevel@tonic-gate 	}
23877c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
23887c478bd9Sstevel@tonic-gate }
23897c478bd9Sstevel@tonic-gate 
23907c478bd9Sstevel@tonic-gate 
23917c478bd9Sstevel@tonic-gate /*
23927c478bd9Sstevel@tonic-gate  * ibnex_create_ioc_portgid_prop()
23937c478bd9Sstevel@tonic-gate  *	Creates "port-entries", "port-list" properties
23947c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
23957c478bd9Sstevel@tonic-gate  */
23967c478bd9Sstevel@tonic-gate static int
23977c478bd9Sstevel@tonic-gate ibnex_create_ioc_portgid_prop(
23987c478bd9Sstevel@tonic-gate     dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
23997c478bd9Sstevel@tonic-gate {
24007c478bd9Sstevel@tonic-gate 	uint64_t	*port_gids;
24017c478bd9Sstevel@tonic-gate 	int		length, ii, jj;
24027c478bd9Sstevel@tonic-gate 	int		prop_len;
24037c478bd9Sstevel@tonic-gate 	ibnex_node_data_t *node_data;
24047c478bd9Sstevel@tonic-gate 
24057c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop");
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate 	node_data = ddi_get_parent_data(cdip);
24087c478bd9Sstevel@tonic-gate 	ASSERT(node_data);
24097c478bd9Sstevel@tonic-gate 
24107c478bd9Sstevel@tonic-gate 	prop_len = (ioc_info->ioc_nportgids != 0) ?
24117c478bd9Sstevel@tonic-gate 	    (2 * ioc_info->ioc_nportgids) : 1;
24127c478bd9Sstevel@tonic-gate 	length = sizeof (uint64_t) * prop_len;
24137c478bd9Sstevel@tonic-gate 	port_gids = kmem_zalloc(length, KM_SLEEP);
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate 	for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) {
24167c478bd9Sstevel@tonic-gate 		port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi;
24177c478bd9Sstevel@tonic-gate 		port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo;
24187c478bd9Sstevel@tonic-gate 	}
24197c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list",
24207c478bd9Sstevel@tonic-gate 	    (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) {
24217c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
24227c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_portgid_prop: port-list create failed");
24237c478bd9Sstevel@tonic-gate 		kmem_free(port_gids, length);
24247c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
24257c478bd9Sstevel@tonic-gate 	}
24267c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries",
24277c478bd9Sstevel@tonic-gate 	    ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) {
24287c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
24297c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_portgid_prop: port-entries create failed");
24307c478bd9Sstevel@tonic-gate 		kmem_free(port_gids, length);
24317c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
24327c478bd9Sstevel@tonic-gate 	}
24337c478bd9Sstevel@tonic-gate 
24347c478bd9Sstevel@tonic-gate 	kmem_free(port_gids, length);
24357c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
24367c478bd9Sstevel@tonic-gate }
24377c478bd9Sstevel@tonic-gate 
24387c478bd9Sstevel@tonic-gate 
24397c478bd9Sstevel@tonic-gate /*
24407c478bd9Sstevel@tonic-gate  * ibnex_create_ioc_srv_props()
24417c478bd9Sstevel@tonic-gate  *	Creates "service-name" and "service-id" properties
24427c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
24437c478bd9Sstevel@tonic-gate  */
24447c478bd9Sstevel@tonic-gate static int
24457c478bd9Sstevel@tonic-gate ibnex_create_ioc_srv_props(
24467c478bd9Sstevel@tonic-gate     dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
24477c478bd9Sstevel@tonic-gate {
24487c478bd9Sstevel@tonic-gate 	int			length, ii;
24497c478bd9Sstevel@tonic-gate 	uint64_t		*srv_id;
24507c478bd9Sstevel@tonic-gate 	char			*temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU];
24517c478bd9Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile;
24527c478bd9Sstevel@tonic-gate 	ibdm_srvents_info_t	 *srvents = ioc_info->ioc_serv;
24537c478bd9Sstevel@tonic-gate 
24547c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props");
24557c478bd9Sstevel@tonic-gate 
24567c478bd9Sstevel@tonic-gate 	length = profile->ioc_service_entries * sizeof (ib_dm_srv_t);
24577c478bd9Sstevel@tonic-gate 	srv_id = kmem_zalloc(length, KM_SLEEP);
24587c478bd9Sstevel@tonic-gate 	temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries));
24597c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < profile->ioc_service_entries; ii++) {
24607c478bd9Sstevel@tonic-gate 		srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN);
24617c478bd9Sstevel@tonic-gate 	}
24627c478bd9Sstevel@tonic-gate 
24637c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < profile->ioc_service_entries; ii++) {
24647c478bd9Sstevel@tonic-gate 		srv_id[ii] = srvents[ii].se_attr.srv_id;
24657c478bd9Sstevel@tonic-gate 		bcopy(srvents[ii].se_attr.srv_name,
24667c478bd9Sstevel@tonic-gate 		    srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1));
24677c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
24687c478bd9Sstevel@tonic-gate 		    "Service Names : %s", srv_names[ii]);
24697c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
24709d3d2ed0Shiremath 		    "Service ID : %llX", srv_id[ii]);
24717c478bd9Sstevel@tonic-gate 	}
24727c478bd9Sstevel@tonic-gate 
24737c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip,
24747c478bd9Sstevel@tonic-gate 	    "service-id", (int64_t *)srv_id,
24757c478bd9Sstevel@tonic-gate 	    profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
24767c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
24777c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_srv_props: service-id create failed");
24787c478bd9Sstevel@tonic-gate 		kmem_free(srv_id, length);
24797c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
24807c478bd9Sstevel@tonic-gate 	}
24817c478bd9Sstevel@tonic-gate 
24827c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
24837c478bd9Sstevel@tonic-gate 	    "service-name", (char **)srv_names,
24847c478bd9Sstevel@tonic-gate 	    profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
24857c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
24867c478bd9Sstevel@tonic-gate 		    "\tcreate_ioc_srv_props: service-name create failed");
24877c478bd9Sstevel@tonic-gate 		kmem_free(srv_id, length);
24887c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
24897c478bd9Sstevel@tonic-gate 	}
24907c478bd9Sstevel@tonic-gate 	kmem_free(srv_id, length);
24917c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
24927c478bd9Sstevel@tonic-gate }
24937c478bd9Sstevel@tonic-gate 
24947c478bd9Sstevel@tonic-gate 
24957c478bd9Sstevel@tonic-gate /*
24967c478bd9Sstevel@tonic-gate  * ibnex_create_ioc_compatible_prop()
24977c478bd9Sstevel@tonic-gate  *	Creates "compatible" property values
24987c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
24997c478bd9Sstevel@tonic-gate  */
25007c478bd9Sstevel@tonic-gate static int
25017c478bd9Sstevel@tonic-gate ibnex_create_ioc_compatible_prop(
25027c478bd9Sstevel@tonic-gate     dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile)
25037c478bd9Sstevel@tonic-gate {
25047c478bd9Sstevel@tonic-gate 	char		*temp;
25057c478bd9Sstevel@tonic-gate 	int		rval, ii;
25067c478bd9Sstevel@tonic-gate 	char		*compatible[IBNEX_MAX_COMPAT_NAMES];
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate 	/*
25097c478bd9Sstevel@tonic-gate 	 * Initialize the "compatible" property string as below:
25107c478bd9Sstevel@tonic-gate 	 * Compatible Strings :
25117c478bd9Sstevel@tonic-gate 	 *	1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver>
25127c478bd9Sstevel@tonic-gate 	 *	2. ib.V<vid>P<pid>S<subsys vid>s<subsys id>
25137c478bd9Sstevel@tonic-gate 	 *	3. ib.V<vid>P<pid>v<ver>
25147c478bd9Sstevel@tonic-gate 	 *	4. ib.V<vid>P<pid>
25157c478bd9Sstevel@tonic-gate 	 *	5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver>
25167c478bd9Sstevel@tonic-gate 	 *	6. ib.C<Class>c<Subclass>p<protocol>
25177c478bd9Sstevel@tonic-gate 	 *
25187c478bd9Sstevel@tonic-gate 	 * Note:
25197c478bd9Sstevel@tonic-gate 	 *	All leading zeros must be present
25207c478bd9Sstevel@tonic-gate 	 *	All numeric values must specified in hex without prefix "0x"
25217c478bd9Sstevel@tonic-gate 	 */
25227c478bd9Sstevel@tonic-gate 
25237c478bd9Sstevel@tonic-gate 	temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP);
25247c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
25257c478bd9Sstevel@tonic-gate 		compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN);
25267c478bd9Sstevel@tonic-gate 
25277c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
25287c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08xS%06xs%08xv%04x",
25297c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25307c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id,
25317c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver);
25327c478bd9Sstevel@tonic-gate 
25337c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
25347c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08xS%06xs%08x",
25357c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25367c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id);
25377c478bd9Sstevel@tonic-gate 
25387c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
25397c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08xv%04x",
25407c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25417c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver);
25427c478bd9Sstevel@tonic-gate 
25437c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN,
25447c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08x",
25457c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid);
25467c478bd9Sstevel@tonic-gate 
25477c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN,
25487c478bd9Sstevel@tonic-gate 	    "ib.C%04xc%04xp%04xr%04x",
25497c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
25507c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver);
25517c478bd9Sstevel@tonic-gate 
25527c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN,
25537c478bd9Sstevel@tonic-gate 	    "ib.C%04xc%04xp%04x",
25547c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
25557c478bd9Sstevel@tonic-gate 	    ioc_profile->ioc_protocol);
25567c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
25577c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]);
25587c478bd9Sstevel@tonic-gate 
25597c478bd9Sstevel@tonic-gate 	/* Create the compatible property for child cdip */
25607c478bd9Sstevel@tonic-gate 	rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
25617c478bd9Sstevel@tonic-gate 	    "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES);
25627c478bd9Sstevel@tonic-gate 
25637c478bd9Sstevel@tonic-gate 	if (rval != DDI_PROP_SUCCESS) {
25647c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed");
25657c478bd9Sstevel@tonic-gate 		kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
25667c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25677c478bd9Sstevel@tonic-gate 	}
25687c478bd9Sstevel@tonic-gate 
25697c478bd9Sstevel@tonic-gate 	kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
25707c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
25717c478bd9Sstevel@tonic-gate }
25727c478bd9Sstevel@tonic-gate 
25737c478bd9Sstevel@tonic-gate 
25747c478bd9Sstevel@tonic-gate static void
25757c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup()
25767c478bd9Sstevel@tonic-gate {
25777c478bd9Sstevel@tonic-gate 	ibnex_node_data_t *node, *delete;
25787c478bd9Sstevel@tonic-gate 
25797c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
25807c478bd9Sstevel@tonic-gate 	for (node = ibnex.ibnex_ioc_node_head; node; ) {
25817c478bd9Sstevel@tonic-gate 		delete = node;
25827c478bd9Sstevel@tonic-gate 		node = node->node_next;
25837c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
25847c478bd9Sstevel@tonic-gate 		ibnex_delete_ioc_node_data(delete);
25857c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
25867c478bd9Sstevel@tonic-gate 	}
25877c478bd9Sstevel@tonic-gate }
25887c478bd9Sstevel@tonic-gate 
25897c478bd9Sstevel@tonic-gate /*
25907c478bd9Sstevel@tonic-gate  * ibnex_delete_ioc_node_data()
25917c478bd9Sstevel@tonic-gate  *	Delete IOC node from the list
25927c478bd9Sstevel@tonic-gate  */
25937c478bd9Sstevel@tonic-gate static void
25947c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node)
25957c478bd9Sstevel@tonic-gate {
25967c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:");
25977c478bd9Sstevel@tonic-gate 
25987c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
25997c478bd9Sstevel@tonic-gate 	if ((node->node_next == NULL) && (node->node_prev == NULL)) {
26007c478bd9Sstevel@tonic-gate 		ASSERT(ibnex.ibnex_ioc_node_head == node);
26017c478bd9Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = NULL;
26027c478bd9Sstevel@tonic-gate 	} else if (node->node_next == NULL)
26037c478bd9Sstevel@tonic-gate 		node->node_prev->node_next = NULL;
26047c478bd9Sstevel@tonic-gate 	else if (node->node_prev == NULL) {
26057c478bd9Sstevel@tonic-gate 		node->node_next->node_prev = NULL;
26067c478bd9Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = node->node_next;
26077c478bd9Sstevel@tonic-gate 	} else {
26087c478bd9Sstevel@tonic-gate 		node->node_prev->node_next = node->node_next;
26097c478bd9Sstevel@tonic-gate 		node->node_next->node_prev = node->node_prev;
26107c478bd9Sstevel@tonic-gate 	}
26117c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p",
26127c478bd9Sstevel@tonic-gate 	    ibnex.ibnex_ioc_node_head);
26137c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
26147c478bd9Sstevel@tonic-gate 	kmem_free(node, sizeof (ibnex_node_data_t));
26157c478bd9Sstevel@tonic-gate }
26167c478bd9Sstevel@tonic-gate 
26177c478bd9Sstevel@tonic-gate 
26187c478bd9Sstevel@tonic-gate /*
26197c478bd9Sstevel@tonic-gate  * ibnex_dm_callback()
26207c478bd9Sstevel@tonic-gate  *
26217c478bd9Sstevel@tonic-gate  *	This routine is registered with the IBDM during IB nexus attach. It
26227c478bd9Sstevel@tonic-gate  *	is called by the IBDM module when it discovers
26237c478bd9Sstevel@tonic-gate  *		New HCA port
26247c478bd9Sstevel@tonic-gate  *		HCA port removal
26257c478bd9Sstevel@tonic-gate  *		New HCA added
26267c478bd9Sstevel@tonic-gate  *		HCA removed
26277c478bd9Sstevel@tonic-gate  */
26287c478bd9Sstevel@tonic-gate void
26297c478bd9Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag)
26307c478bd9Sstevel@tonic-gate {
26317c478bd9Sstevel@tonic-gate 	char	hca_guid[IBNEX_HCAGUID_STRSZ];
26327c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t	*ioc_list, *ioc;
26337c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
2634dcf1eb70SSudhakar Dindukurti 	dev_info_t		*phci;
26351cfa752fSRamaswamy Tummala 	ib_guid_t		*guid;
26367c478bd9Sstevel@tonic-gate 
26377c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag);
26387c478bd9Sstevel@tonic-gate 
26397c478bd9Sstevel@tonic-gate 	switch (flag) {
26407c478bd9Sstevel@tonic-gate 	case IBDM_EVENT_HCA_ADDED:
26417c478bd9Sstevel@tonic-gate 		(void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
26427c478bd9Sstevel@tonic-gate 		    (*(longlong_t *)arg));
26437c478bd9Sstevel@tonic-gate 		/* Create a devctl minor node for the HCA's port  */
26447c478bd9Sstevel@tonic-gate 		if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR,
26457c478bd9Sstevel@tonic-gate 		    ddi_get_instance(ibnex.ibnex_dip),
26467c478bd9Sstevel@tonic-gate 		    DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
26477c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
26487c478bd9Sstevel@tonic-gate 			    "create minor node for port w/ guid %s", hca_guid);
26497c478bd9Sstevel@tonic-gate 		}
26507c478bd9Sstevel@tonic-gate 
26511cfa752fSRamaswamy Tummala 		guid = kmem_alloc(sizeof (ib_guid_t), KM_SLEEP);
26521cfa752fSRamaswamy Tummala 		*guid = *(ib_guid_t *)arg;
26531cfa752fSRamaswamy Tummala 		if (ddi_taskq_dispatch(ibnex.ibnex_taskq_id,
26541cfa752fSRamaswamy Tummala 		    ibnex_handle_hca_attach, guid, DDI_NOSLEEP)
26551cfa752fSRamaswamy Tummala 		    != DDI_SUCCESS) {
265603c76a6eSRajkumar Sivaprakasam 			kmem_free(guid, sizeof (ib_guid_t));
26571cfa752fSRamaswamy Tummala 			IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
26581cfa752fSRamaswamy Tummala 			    "dispatch HCA add event for guid %s", hca_guid);
26591cfa752fSRamaswamy Tummala 		}
26601cfa752fSRamaswamy Tummala 
26617c478bd9Sstevel@tonic-gate 		break;
26627c478bd9Sstevel@tonic-gate 
26637c478bd9Sstevel@tonic-gate 	case IBDM_EVENT_HCA_REMOVED:
26647c478bd9Sstevel@tonic-gate 		(void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
26657c478bd9Sstevel@tonic-gate 		    (*(longlong_t *)arg));
26667c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid);
26677c478bd9Sstevel@tonic-gate 		break;
26687c478bd9Sstevel@tonic-gate 
26697c478bd9Sstevel@tonic-gate 	case IBDM_EVENT_IOC_PROP_UPDATE:
26707c478bd9Sstevel@tonic-gate 		ioc = ioc_list = (ibdm_ioc_info_t *)arg;
26717c478bd9Sstevel@tonic-gate 		if (ioc_list == NULL)
26727c478bd9Sstevel@tonic-gate 			break;
26737c478bd9Sstevel@tonic-gate 
26747c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
26757c478bd9Sstevel@tonic-gate 		while (ioc_list) {
26767c478bd9Sstevel@tonic-gate 			if ((node_data = ibnex_is_node_data_present(
26777c478bd9Sstevel@tonic-gate 			    IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL &&
26787c478bd9Sstevel@tonic-gate 			    node_data->node_dip != NULL) {
26797c478bd9Sstevel@tonic-gate 				ibnex_update_prop(node_data, ioc_list);
26807c478bd9Sstevel@tonic-gate 			}
26817c478bd9Sstevel@tonic-gate 			ioc_list = ioc_list->ioc_next;
26827c478bd9Sstevel@tonic-gate 		}
26837c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
26847c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc);
2685dcf1eb70SSudhakar Dindukurti 		break;
2686dcf1eb70SSudhakar Dindukurti 
2687dcf1eb70SSudhakar Dindukurti 	case IBDM_EVENT_PORT_UP:
2688dcf1eb70SSudhakar Dindukurti 	case IBDM_EVENT_PORT_PKEY_CHANGE:
2689dcf1eb70SSudhakar Dindukurti 		phci = ibtl_ibnex_hcaguid2dip(*(longlong_t *)arg);
2690c1374a13SSurya Prakki 		(void) devfs_clean(phci, NULL, 0);
2691dcf1eb70SSudhakar Dindukurti 		break;
2692dcf1eb70SSudhakar Dindukurti 	default:
2693dcf1eb70SSudhakar Dindukurti 		break;
2694dcf1eb70SSudhakar Dindukurti 
26957c478bd9Sstevel@tonic-gate 	}
26967c478bd9Sstevel@tonic-gate }
26977c478bd9Sstevel@tonic-gate 
26987c478bd9Sstevel@tonic-gate 
26997c478bd9Sstevel@tonic-gate /*
27001cfa752fSRamaswamy Tummala  * ibnex_get_node_and_dip_from_guid()
27011cfa752fSRamaswamy Tummala  *
27021cfa752fSRamaswamy Tummala  *	Searches the linked list of the port nodes and returns the dip for
27031cfa752fSRamaswamy Tummala  *	the of the Port / Node guid requested.
27041cfa752fSRamaswamy Tummala  *	Returns NULL if not found
27051cfa752fSRamaswamy Tummala  */
27061cfa752fSRamaswamy Tummala int
27071cfa752fSRamaswamy Tummala ibnex_get_node_and_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
27081cfa752fSRamaswamy Tummala     ibnex_node_data_t **nodep, dev_info_t **dip)
27091cfa752fSRamaswamy Tummala {
27101cfa752fSRamaswamy Tummala 	int			node_index;
27111cfa752fSRamaswamy Tummala 	ib_guid_t		node_guid;
27121cfa752fSRamaswamy Tummala 	ib_pkey_t		node_pkey;
27131cfa752fSRamaswamy Tummala 	ibnex_node_data_t	*node_data;
27141cfa752fSRamaswamy Tummala 
27151cfa752fSRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex",
27161cfa752fSRamaswamy Tummala 	    "\tget_node_and_dip_from_guid: guid = %llX", guid);
27171cfa752fSRamaswamy Tummala 
27181cfa752fSRamaswamy Tummala 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
27191cfa752fSRamaswamy Tummala 	/* Search for a matching entry in internal lists */
27201cfa752fSRamaswamy Tummala 	node_data = ibnex.ibnex_port_node_head;
27211cfa752fSRamaswamy Tummala 	while (node_data) {
27221cfa752fSRamaswamy Tummala 		node_guid = node_data->node_data.port_node.port_guid;
27231cfa752fSRamaswamy Tummala 		node_index = node_data->node_data.port_node.port_commsvc_idx;
27241cfa752fSRamaswamy Tummala 		node_pkey = node_data->node_data.port_node.port_pkey;
27251cfa752fSRamaswamy Tummala 		if ((node_guid == guid) && (index == node_index) &&
27261cfa752fSRamaswamy Tummala 		    (node_pkey == pkey)) {
27271cfa752fSRamaswamy Tummala 			break;
27281cfa752fSRamaswamy Tummala 		}
27291cfa752fSRamaswamy Tummala 		node_data = node_data->node_next;
27301cfa752fSRamaswamy Tummala 	}
27311cfa752fSRamaswamy Tummala 
27321cfa752fSRamaswamy Tummala 	/* matching found with a valid dip */
27331cfa752fSRamaswamy Tummala 	if (node_data && node_data->node_dip) {
27341cfa752fSRamaswamy Tummala 		*nodep = node_data;
27351cfa752fSRamaswamy Tummala 		*dip = node_data->node_dip;
27361cfa752fSRamaswamy Tummala 		return (IBNEX_SUCCESS);
27371cfa752fSRamaswamy Tummala 	} else if (node_data && !node_data->node_dip) {	/* dip is invalid */
27381cfa752fSRamaswamy Tummala 		*nodep = node_data;
27391cfa752fSRamaswamy Tummala 		*dip = NULL;
27401cfa752fSRamaswamy Tummala 		return (IBNEX_SUCCESS);
27411cfa752fSRamaswamy Tummala 	}
27421cfa752fSRamaswamy Tummala 
27431cfa752fSRamaswamy Tummala 	/* no match found */
27441cfa752fSRamaswamy Tummala 	*nodep = NULL;
27451cfa752fSRamaswamy Tummala 	*dip = NULL;
27461cfa752fSRamaswamy Tummala 	return (IBNEX_FAILURE);
27471cfa752fSRamaswamy Tummala }
27481cfa752fSRamaswamy Tummala 
27491cfa752fSRamaswamy Tummala /*
27507c478bd9Sstevel@tonic-gate  * ibnex_get_dip_from_guid()
27517c478bd9Sstevel@tonic-gate  *
27527c478bd9Sstevel@tonic-gate  *	Searches the linked list of the port nodes and returns the dip for
27537c478bd9Sstevel@tonic-gate  *	the of the Port / Node guid requested.
27547c478bd9Sstevel@tonic-gate  *	Returns NULL if not found
27557c478bd9Sstevel@tonic-gate  */
27567c478bd9Sstevel@tonic-gate int
27577c478bd9Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
27587c478bd9Sstevel@tonic-gate     dev_info_t **dip)
27597c478bd9Sstevel@tonic-gate {
27607c478bd9Sstevel@tonic-gate 	int			node_index;
27617c478bd9Sstevel@tonic-gate 	ib_guid_t		node_guid;
27627c478bd9Sstevel@tonic-gate 	ib_pkey_t		node_pkey;
27637c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
27647c478bd9Sstevel@tonic-gate 
27657c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
27669d3d2ed0Shiremath 	    "\tget_dip_from_guid: guid = %llX", guid);
27677c478bd9Sstevel@tonic-gate 
27687c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
27697c478bd9Sstevel@tonic-gate 	/* Search for a matching entry in internal lists */
27707c478bd9Sstevel@tonic-gate 	node_data = ibnex.ibnex_port_node_head;
27717c478bd9Sstevel@tonic-gate 	while (node_data) {
27727c478bd9Sstevel@tonic-gate 		node_guid = node_data->node_data.port_node.port_guid;
27737c478bd9Sstevel@tonic-gate 		node_index = node_data->node_data.port_node.port_commsvc_idx;
27747c478bd9Sstevel@tonic-gate 		node_pkey = node_data->node_data.port_node.port_pkey;
27757c478bd9Sstevel@tonic-gate 		if ((node_guid == guid) && (index == node_index) &&
27767c478bd9Sstevel@tonic-gate 		    (node_pkey == pkey)) {
27777c478bd9Sstevel@tonic-gate 			break;
27787c478bd9Sstevel@tonic-gate 		}
27797c478bd9Sstevel@tonic-gate 		node_data = node_data->node_next;
27807c478bd9Sstevel@tonic-gate 	}
27817c478bd9Sstevel@tonic-gate 
27827c478bd9Sstevel@tonic-gate 	/* matching found with a valid dip */
27837c478bd9Sstevel@tonic-gate 	if (node_data && node_data->node_dip) {
27847c478bd9Sstevel@tonic-gate 		*dip = node_data->node_dip;
27857c478bd9Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
27867c478bd9Sstevel@tonic-gate 	} else if (node_data && !node_data->node_dip) {	/* dip is invalid */
27877c478bd9Sstevel@tonic-gate 		*dip = NULL;
27887c478bd9Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
27897c478bd9Sstevel@tonic-gate 	}
27907c478bd9Sstevel@tonic-gate 
27917c478bd9Sstevel@tonic-gate 	/* no match found */
27927c478bd9Sstevel@tonic-gate 	*dip = NULL;
27937c478bd9Sstevel@tonic-gate 	return (IBNEX_FAILURE);
27947c478bd9Sstevel@tonic-gate }
27957c478bd9Sstevel@tonic-gate 
27967c478bd9Sstevel@tonic-gate 
27977c478bd9Sstevel@tonic-gate /*
27987c478bd9Sstevel@tonic-gate  * ibnex_comm_svc_init()
27997c478bd9Sstevel@tonic-gate  *	Read the property and cache the values in the global
28007c478bd9Sstevel@tonic-gate  *	structure.
28017c478bd9Sstevel@tonic-gate  *	Check for max allowed length (4 bytes) of service name
28027c478bd9Sstevel@tonic-gate  *	(each element of the property)
28037c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
28047c478bd9Sstevel@tonic-gate  */
28057c478bd9Sstevel@tonic-gate static ibnex_rval_t
28067c478bd9Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type)
28077c478bd9Sstevel@tonic-gate {
28087c478bd9Sstevel@tonic-gate 	int		i, len, count;
28097c478bd9Sstevel@tonic-gate 	int		ncomm_svcs;
28107c478bd9Sstevel@tonic-gate 	char		**comm_svcp;
28117c478bd9Sstevel@tonic-gate 	char		**servicep = NULL;
28127c478bd9Sstevel@tonic-gate 	uint_t		nservices = 0;
28137c478bd9Sstevel@tonic-gate 	int			*valid = NULL;
28147c478bd9Sstevel@tonic-gate 
28157c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x",
28167c478bd9Sstevel@tonic-gate 	    property, type);
28177c478bd9Sstevel@tonic-gate 
28187c478bd9Sstevel@tonic-gate 	/* lookup the string array property */
28197c478bd9Sstevel@tonic-gate 	if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip,
28207c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, property, &servicep, &nservices) !=
28217c478bd9Sstevel@tonic-gate 	    DDI_PROP_SUCCESS) {
28227c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property);
28237c478bd9Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
28247c478bd9Sstevel@tonic-gate 	}
28257c478bd9Sstevel@tonic-gate 
28267c478bd9Sstevel@tonic-gate 	if (nservices)
28277c478bd9Sstevel@tonic-gate 		valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP);
28287c478bd9Sstevel@tonic-gate 
28297c478bd9Sstevel@tonic-gate 
28307c478bd9Sstevel@tonic-gate 	/* first read the file to get a count of valid service entries */
28317c478bd9Sstevel@tonic-gate 	for (ncomm_svcs = 0, count = 0; count < nservices; count++) {
28327c478bd9Sstevel@tonic-gate 		int j;
28337c478bd9Sstevel@tonic-gate 
28347c478bd9Sstevel@tonic-gate 		len = strlen(servicep[count]);
283500a3eaf3SRamaswamy Tummala 		/*
283600a3eaf3SRamaswamy Tummala 		 * ib.conf has NULL strings for port-svc-list &
283700a3eaf3SRamaswamy Tummala 		 * hca-svc-list, by default. Do not have L2 message
283800a3eaf3SRamaswamy Tummala 		 * for these.
283900a3eaf3SRamaswamy Tummala 		 */
284000a3eaf3SRamaswamy Tummala 		if (len == 1 || len > 4) {
28417c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
284200a3eaf3SRamaswamy Tummala 			    "Service name %s for property %s invalid : "
284300a3eaf3SRamaswamy Tummala 			    "length %d", servicep[count], property, len);
284400a3eaf3SRamaswamy Tummala 			continue;
284500a3eaf3SRamaswamy Tummala 		} else if (len == 0) {
28467c478bd9Sstevel@tonic-gate 			continue;
28477c478bd9Sstevel@tonic-gate 		}
28487c478bd9Sstevel@tonic-gate 		if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) {
28497c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
28507c478bd9Sstevel@tonic-gate 			    "Service name %s invalid : Not unique",
28517c478bd9Sstevel@tonic-gate 			    servicep[count]);
28527c478bd9Sstevel@tonic-gate 			continue;
28537c478bd9Sstevel@tonic-gate 		}
28547c478bd9Sstevel@tonic-gate 
28557c478bd9Sstevel@tonic-gate 		/*
28567c478bd9Sstevel@tonic-gate 		 * ibnex_unique_svcname checks for uniqueness in service names
28577c478bd9Sstevel@tonic-gate 		 * communication services fully initialized. Check uniqueness
28587c478bd9Sstevel@tonic-gate 		 * in service names currently initialized.
28597c478bd9Sstevel@tonic-gate 		 */
28607c478bd9Sstevel@tonic-gate 		for (j = 0; j < count; j++)
28617c478bd9Sstevel@tonic-gate 			if (valid[j] && strncmp(servicep[count],
28627c478bd9Sstevel@tonic-gate 			    servicep[j], 4) == 0) {
28637c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
28647c478bd9Sstevel@tonic-gate 				    "Service name %s invalid : Not unique",
28657c478bd9Sstevel@tonic-gate 				    servicep[count]);
28667c478bd9Sstevel@tonic-gate 					continue;
28677c478bd9Sstevel@tonic-gate 			}
28687c478bd9Sstevel@tonic-gate 
28697c478bd9Sstevel@tonic-gate 		valid[count] = 1;
28707c478bd9Sstevel@tonic-gate 		ncomm_svcs++;
28717c478bd9Sstevel@tonic-gate 	}
28727c478bd9Sstevel@tonic-gate 
28737c478bd9Sstevel@tonic-gate 	/* if no valid entries found, bailout */
28747c478bd9Sstevel@tonic-gate 	if (nservices == 0 || ncomm_svcs == 0) {
28757c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property);
28767c478bd9Sstevel@tonic-gate 		ddi_prop_free(servicep); /* free the property */
28777c478bd9Sstevel@tonic-gate 		if (valid)
28787c478bd9Sstevel@tonic-gate 			kmem_free(valid, nservices * sizeof (int));
28797c478bd9Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
28807c478bd9Sstevel@tonic-gate 	}
28817c478bd9Sstevel@tonic-gate 
28827c478bd9Sstevel@tonic-gate 	comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP);
28837c478bd9Sstevel@tonic-gate 	if (type == IBNEX_PORT_COMMSVC_NODE) {
28847c478bd9Sstevel@tonic-gate 		ibnex.ibnex_comm_svc_names = comm_svcp;
28857c478bd9Sstevel@tonic-gate 		ibnex.ibnex_num_comm_svcs = ncomm_svcs;
28867c478bd9Sstevel@tonic-gate 	} else if (type == IBNEX_VPPA_COMMSVC_NODE) {
28877c478bd9Sstevel@tonic-gate 		ibnex.ibnex_vppa_comm_svc_names = comm_svcp;
28887c478bd9Sstevel@tonic-gate 		ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs;
28897c478bd9Sstevel@tonic-gate 	} else if (type == IBNEX_HCASVC_COMMSVC_NODE) {
28907c478bd9Sstevel@tonic-gate 		ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp;
28917c478bd9Sstevel@tonic-gate 		ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs;
28927c478bd9Sstevel@tonic-gate 	}
28937c478bd9Sstevel@tonic-gate 
28947c478bd9Sstevel@tonic-gate 	/* copy the services into an array of strings */
28957c478bd9Sstevel@tonic-gate 	for (i = 0, count = 0; count < nservices; count++) {
28967c478bd9Sstevel@tonic-gate 		if (valid[count] == 0)	/* Skip invalid ones */
28977c478bd9Sstevel@tonic-gate 			continue;
28987c478bd9Sstevel@tonic-gate 		comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP);
28997c478bd9Sstevel@tonic-gate 		(void) strcpy(comm_svcp[i], servicep[count]);
29007c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
29017c478bd9Sstevel@tonic-gate 		    "\t\tService [%d]: %s", i, comm_svcp[i]);
29027c478bd9Sstevel@tonic-gate 		++i;
29037c478bd9Sstevel@tonic-gate 	}
29047c478bd9Sstevel@tonic-gate 	ddi_prop_free(servicep);
29057c478bd9Sstevel@tonic-gate 	kmem_free(valid, nservices * sizeof (int));
29067c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
29077c478bd9Sstevel@tonic-gate }
29087c478bd9Sstevel@tonic-gate 
29097c478bd9Sstevel@tonic-gate 
29107c478bd9Sstevel@tonic-gate /*
29117c478bd9Sstevel@tonic-gate  * ibnex_comm_svc_fini()
29127c478bd9Sstevel@tonic-gate  *	Deallocate all the memory allocated for the communication
29137c478bd9Sstevel@tonic-gate  *	service arrays.
29147c478bd9Sstevel@tonic-gate  */
29157c478bd9Sstevel@tonic-gate static void
29167c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini()
29177c478bd9Sstevel@tonic-gate {
29187c478bd9Sstevel@tonic-gate 	int	index;
29197c478bd9Sstevel@tonic-gate 
29207c478bd9Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) {
29217c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_comm_svc_names[index],
29227c478bd9Sstevel@tonic-gate 		    (strlen(ibnex.ibnex_comm_svc_names[index]) + 1));
29237c478bd9Sstevel@tonic-gate 	}
29247c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_comm_svc_names) {
29257c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_comm_svc_names,
29267c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_num_comm_svcs * sizeof (char *));
29277c478bd9Sstevel@tonic-gate 	}
29287c478bd9Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) {
29297c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_vppa_comm_svc_names[index],
29307c478bd9Sstevel@tonic-gate 		    strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1);
29317c478bd9Sstevel@tonic-gate 	}
29327c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_vppa_comm_svc_names) {
29337c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_vppa_comm_svc_names,
29347c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_nvppa_comm_svcs * sizeof (char *));
29357c478bd9Sstevel@tonic-gate 	}
29367c478bd9Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) {
29377c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index],
29387c478bd9Sstevel@tonic-gate 		    strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1);
29397c478bd9Sstevel@tonic-gate 	}
29407c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_hcasvc_comm_svc_names) {
29417c478bd9Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_hcasvc_comm_svc_names,
29427c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *));
29437c478bd9Sstevel@tonic-gate 	}
29447c478bd9Sstevel@tonic-gate 	ibnex.ibnex_comm_svc_names = NULL;
29457c478bd9Sstevel@tonic-gate 	ibnex.ibnex_num_comm_svcs = 0;
29467c478bd9Sstevel@tonic-gate 	ibnex.ibnex_vppa_comm_svc_names = NULL;
29477c478bd9Sstevel@tonic-gate 	ibnex.ibnex_nvppa_comm_svcs = 0;
29487c478bd9Sstevel@tonic-gate 	ibnex.ibnex_hcasvc_comm_svc_names = NULL;
29497c478bd9Sstevel@tonic-gate 	ibnex.ibnex_nhcasvc_comm_svcs = 0;
29507c478bd9Sstevel@tonic-gate }
29517c478bd9Sstevel@tonic-gate 
29527c478bd9Sstevel@tonic-gate 
29537c478bd9Sstevel@tonic-gate /*
29547c478bd9Sstevel@tonic-gate  * ibnex_commsvc_initnode()
29557c478bd9Sstevel@tonic-gate  *	This routine is specific to port/VPPA node creation
29567c478bd9Sstevel@tonic-gate  *	Creates a device node for the comm service specified by commsvc_index
29577c478bd9Sstevel@tonic-gate  *	Creates all the device node properties
29587c478bd9Sstevel@tonic-gate  *	Allocates and initializes the node specific data
29597c478bd9Sstevel@tonic-gate  *	Binds the device driver of the device node
29607c478bd9Sstevel@tonic-gate  *	Returns "dev_info_t" of the child node or NULL in case of failure
29617c478bd9Sstevel@tonic-gate  *	Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect
29627c478bd9Sstevel@tonic-gate  *	if the operation was successful, failed or was not performed.
29637c478bd9Sstevel@tonic-gate  */
29647c478bd9Sstevel@tonic-gate dev_info_t *
29657c478bd9Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr,
29667c478bd9Sstevel@tonic-gate     int index, int node_type, ib_pkey_t pkey, int *rval, int flag)
29677c478bd9Sstevel@tonic-gate {
29687c478bd9Sstevel@tonic-gate 	int			ret;
29697c478bd9Sstevel@tonic-gate 	char			*svcname;
29707c478bd9Sstevel@tonic-gate 	dev_info_t		*cdip;
29717c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
297200a3eaf3SRamaswamy Tummala 	ibnex_port_node_t	*port_node;
297300a3eaf3SRamaswamy Tummala 	char devname[MAXNAMELEN];
297451f34d4bSRajkumar Sivaprakasam 	int 			cdip_allocated = 0;
29757c478bd9Sstevel@tonic-gate 
29767c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
29777c478bd9Sstevel@tonic-gate 
29787c478bd9Sstevel@tonic-gate 	*rval = IBNEX_SUCCESS;
29797c478bd9Sstevel@tonic-gate 
29807c478bd9Sstevel@tonic-gate 	/*
29817c478bd9Sstevel@tonic-gate 	 * prevent any races
29827c478bd9Sstevel@tonic-gate 	 * we have seen this node_data and it has been initialized
29837c478bd9Sstevel@tonic-gate 	 * Note that node_dip is already NULL if unconfigure is in
29847c478bd9Sstevel@tonic-gate 	 * progress.
29857c478bd9Sstevel@tonic-gate 	 */
29867c478bd9Sstevel@tonic-gate 	node_data = ibnex_is_node_data_present(node_type, (void *)port_attr,
29877c478bd9Sstevel@tonic-gate 	    index, pkey);
298800a3eaf3SRamaswamy Tummala 
298900a3eaf3SRamaswamy Tummala 	/*
299000a3eaf3SRamaswamy Tummala 	 * If this node has been explicity unconfigured by cfgadm, then it can
299100a3eaf3SRamaswamy Tummala 	 * be configured back again only by cfgadm configure.
299200a3eaf3SRamaswamy Tummala 	 */
299300a3eaf3SRamaswamy Tummala 	if (node_data && (node_data->node_ap_state ==
299400a3eaf3SRamaswamy Tummala 	    IBNEX_NODE_AP_UNCONFIGURED)) {
299500a3eaf3SRamaswamy Tummala 		*rval = IBNEX_FAILURE;
299600a3eaf3SRamaswamy Tummala 		return (NULL);
299700a3eaf3SRamaswamy Tummala 	}
299800a3eaf3SRamaswamy Tummala 
29997c478bd9Sstevel@tonic-gate 	if (node_data && node_data->node_dip) {
30007c478bd9Sstevel@tonic-gate 		/*
30017c478bd9Sstevel@tonic-gate 		 * Return NULL if another configure
30027c478bd9Sstevel@tonic-gate 		 * operation is in progress
30037c478bd9Sstevel@tonic-gate 		 */
30047c478bd9Sstevel@tonic-gate 		if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) {
30057c478bd9Sstevel@tonic-gate 			*rval = IBNEX_BUSY;
30067c478bd9Sstevel@tonic-gate 			return (NULL);
30077c478bd9Sstevel@tonic-gate 		} else {
30087c478bd9Sstevel@tonic-gate 			return (node_data->node_dip);
30097c478bd9Sstevel@tonic-gate 		}
30107c478bd9Sstevel@tonic-gate 	} else if (node_data == NULL) {
30117c478bd9Sstevel@tonic-gate 		/* allocate a new ibnex_node_data_t */
30127c478bd9Sstevel@tonic-gate 		node_data = ibnex_init_child_nodedata(node_type, port_attr,
30137c478bd9Sstevel@tonic-gate 		    index, pkey);
301400a3eaf3SRamaswamy Tummala 		node_data->node_data.port_node.port_pdip = parent;
30157c478bd9Sstevel@tonic-gate 	}
30167c478bd9Sstevel@tonic-gate 
30177c478bd9Sstevel@tonic-gate 	/*
30187c478bd9Sstevel@tonic-gate 	 * Return NULL if another unconfigure operation is in progress
30197c478bd9Sstevel@tonic-gate 	 */
30207c478bd9Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
30217c478bd9Sstevel@tonic-gate 		*rval = IBNEX_BUSY;
30227c478bd9Sstevel@tonic-gate 		return (NULL);
30237c478bd9Sstevel@tonic-gate 	}
30247c478bd9Sstevel@tonic-gate 
30257c478bd9Sstevel@tonic-gate 	ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED);
30267c478bd9Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
30277c478bd9Sstevel@tonic-gate 
30287c478bd9Sstevel@tonic-gate 	switch (node_type) {
30297c478bd9Sstevel@tonic-gate 		case IBNEX_VPPA_COMMSVC_NODE :
30307c478bd9Sstevel@tonic-gate 			svcname = ibnex.ibnex_vppa_comm_svc_names[index];
303100a3eaf3SRamaswamy Tummala 			port_node = &node_data->node_data.port_node;
303200a3eaf3SRamaswamy Tummala 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s",
303300a3eaf3SRamaswamy Tummala 			    IBNEX_IBPORT_CNAME, port_node->port_num,
303400a3eaf3SRamaswamy Tummala 			    port_node->port_pkey, svcname);
30357c478bd9Sstevel@tonic-gate 			break;
30367c478bd9Sstevel@tonic-gate 		case IBNEX_HCASVC_COMMSVC_NODE :
30377c478bd9Sstevel@tonic-gate 			svcname = ibnex.ibnex_hcasvc_comm_svc_names[index];
303800a3eaf3SRamaswamy Tummala 			port_node = &node_data->node_data.port_node;
303900a3eaf3SRamaswamy Tummala 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
304000a3eaf3SRamaswamy Tummala 			    IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
30417c478bd9Sstevel@tonic-gate 			break;
30427c478bd9Sstevel@tonic-gate 		case IBNEX_PORT_COMMSVC_NODE :
30437c478bd9Sstevel@tonic-gate 			svcname = ibnex.ibnex_comm_svc_names[index];
304400a3eaf3SRamaswamy Tummala 			port_node = &node_data->node_data.port_node;
304500a3eaf3SRamaswamy Tummala 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
304600a3eaf3SRamaswamy Tummala 			    IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
30477c478bd9Sstevel@tonic-gate 			break;
30487c478bd9Sstevel@tonic-gate 		default :
30497c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:"
30507c478bd9Sstevel@tonic-gate 			    "\tInvalid Node type");
30517c478bd9Sstevel@tonic-gate 			*rval = IBNEX_FAILURE;
30527c478bd9Sstevel@tonic-gate 			ibnex_delete_port_node_data(node_data);
30537c478bd9Sstevel@tonic-gate 			return (NULL);
30547c478bd9Sstevel@tonic-gate 	}
30557c478bd9Sstevel@tonic-gate 
305600a3eaf3SRamaswamy Tummala 	if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) {
305700a3eaf3SRamaswamy Tummala 		if (i_ddi_devi_attached(cdip)) {
305800a3eaf3SRamaswamy Tummala 			node_data->node_dip	= cdip;
305900a3eaf3SRamaswamy Tummala 			node_data->node_data.port_node.port_pdip = parent;
306000a3eaf3SRamaswamy Tummala 			node_data->node_state = IBNEX_CFGADM_CONFIGURED;
306100a3eaf3SRamaswamy Tummala 			ddi_set_parent_data(cdip, node_data);
306251f34d4bSRajkumar Sivaprakasam 			IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found "
306351f34d4bSRajkumar Sivaprakasam 			    "attached cdip 0x%p for devname %s", cdip, devname);
306400a3eaf3SRamaswamy Tummala 			return (cdip);
306500a3eaf3SRamaswamy Tummala 		}
306600a3eaf3SRamaswamy Tummala 	} else {
306700a3eaf3SRamaswamy Tummala 		ndi_devi_alloc_sleep(parent,
306800a3eaf3SRamaswamy Tummala 		    IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip);
306951f34d4bSRajkumar Sivaprakasam 		cdip_allocated = 1;
307000a3eaf3SRamaswamy Tummala 	}
307100a3eaf3SRamaswamy Tummala 
307200a3eaf3SRamaswamy Tummala 	node_data->node_dip	= cdip;
307300a3eaf3SRamaswamy Tummala 	ddi_set_parent_data(cdip, node_data);
307400a3eaf3SRamaswamy Tummala 	mutex_exit(&ibnex.ibnex_mutex);
307500a3eaf3SRamaswamy Tummala 
307600a3eaf3SRamaswamy Tummala 
30777c478bd9Sstevel@tonic-gate 	if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) ==
30787c478bd9Sstevel@tonic-gate 	    IBNEX_SUCCESS) {
30797c478bd9Sstevel@tonic-gate 		if (flag == IBNEX_DEVFS_ENUMERATE)
30807c478bd9Sstevel@tonic-gate 			ret = ndi_devi_bind_driver(cdip, 0);
30817c478bd9Sstevel@tonic-gate 		else
30827c478bd9Sstevel@tonic-gate 			ret = ndi_devi_online(cdip, 0);
30837c478bd9Sstevel@tonic-gate 		if (ret == NDI_SUCCESS) {
30847c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
30857c478bd9Sstevel@tonic-gate 			node_data->node_state	= IBNEX_CFGADM_CONFIGURED;
308600a3eaf3SRamaswamy Tummala 			node_data->node_data.port_node.port_pdip = parent;
30877c478bd9Sstevel@tonic-gate 			return (cdip);
30887c478bd9Sstevel@tonic-gate 		}
308951f34d4bSRajkumar Sivaprakasam 		IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE "
309051f34d4bSRajkumar Sivaprakasam 		    "of cdip 0x%p for devname %s and flag %d failed", cdip,
309151f34d4bSRajkumar Sivaprakasam 		    devname, flag);
30927c478bd9Sstevel@tonic-gate 	}
309300a3eaf3SRamaswamy Tummala 
30947c478bd9Sstevel@tonic-gate 	*rval = IBNEX_FAILURE;
309551f34d4bSRajkumar Sivaprakasam 	node_data->node_dip = NULL;
309651f34d4bSRajkumar Sivaprakasam 	ddi_set_parent_data(cdip, NULL);
309751f34d4bSRajkumar Sivaprakasam 	if (cdip_allocated)
30987c478bd9Sstevel@tonic-gate 		(void) ndi_devi_free(cdip);
30997c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
31007c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit");
31017c478bd9Sstevel@tonic-gate 	return (NULL);
31027c478bd9Sstevel@tonic-gate }
31037c478bd9Sstevel@tonic-gate 
31047c478bd9Sstevel@tonic-gate 
31057c478bd9Sstevel@tonic-gate /*
31067c478bd9Sstevel@tonic-gate  * ibnex_create_port_node_prop()
31077c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
31087c478bd9Sstevel@tonic-gate  */
31097c478bd9Sstevel@tonic-gate static int
31107c478bd9Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr,
31117c478bd9Sstevel@tonic-gate     dev_info_t *child_dip, char *srvname, ib_pkey_t pkey)
31127c478bd9Sstevel@tonic-gate {
31137c478bd9Sstevel@tonic-gate 	if (ibnex_create_port_compatible_prop(child_dip,
31147c478bd9Sstevel@tonic-gate 	    srvname, port_attr) != DDI_PROP_SUCCESS) {
31157c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
31167c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: compatible update failed");
31177c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
31187c478bd9Sstevel@tonic-gate 	}
31197c478bd9Sstevel@tonic-gate 	if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
31207c478bd9Sstevel@tonic-gate 	    "port-pkey", pkey) != DDI_PROP_SUCCESS)) {
31217c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
31227c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: port-num update failed");
31237c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
31247c478bd9Sstevel@tonic-gate 	}
31257c478bd9Sstevel@tonic-gate 
31267c478bd9Sstevel@tonic-gate 	/*
31277c478bd9Sstevel@tonic-gate 	 * For HCA_SVC device nodes, port_num will be 0.
31287c478bd9Sstevel@tonic-gate 	 * Do not create the "port-number" & "port-guid" properties.
31297c478bd9Sstevel@tonic-gate 	 */
31307c478bd9Sstevel@tonic-gate 	if (port_attr->pa_port_num != 0) {
31317c478bd9Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
31327c478bd9Sstevel@tonic-gate 		    "port-number", port_attr->pa_port_num) !=
31337c478bd9Sstevel@tonic-gate 		    DDI_PROP_SUCCESS) {
31347c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
31357c478bd9Sstevel@tonic-gate 			    "\tcreate_port_node_prop: port-num update failed");
31367c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
31377c478bd9Sstevel@tonic-gate 		}
31387c478bd9Sstevel@tonic-gate 		if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
31397c478bd9Sstevel@tonic-gate 		    "port-guid", port_attr->pa_port_guid) !=
31407c478bd9Sstevel@tonic-gate 		    DDI_PROP_SUCCESS) {
31417c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
31427c478bd9Sstevel@tonic-gate 			    "\tcreate_port_node_prop: port-guid update failed");
31437c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
31447c478bd9Sstevel@tonic-gate 		}
31457c478bd9Sstevel@tonic-gate 	} else {
31467c478bd9Sstevel@tonic-gate 		ibdm_hca_list_t	*hca_list;
31477c478bd9Sstevel@tonic-gate 
31487c478bd9Sstevel@tonic-gate 		/*
31497c478bd9Sstevel@tonic-gate 		 * HCA_SVC nodes require "num-ports" & "port-guids"
31507c478bd9Sstevel@tonic-gate 		 * properties.
31517c478bd9Sstevel@tonic-gate 		 *
31527c478bd9Sstevel@tonic-gate 		 * To create the num-ports & port-guids attribute :
31537c478bd9Sstevel@tonic-gate 		 * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid)
31547c478bd9Sstevel@tonic-gate 		 * 2. Form the array of port GUIDs.
31557c478bd9Sstevel@tonic-gate 		 */
31567c478bd9Sstevel@tonic-gate 		if ((hca_list = ibdm_ibnex_get_hca_info_by_guid(
31577c478bd9Sstevel@tonic-gate 		    port_attr->pa_hca_guid)) == NULL) {
31587c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
31597c478bd9Sstevel@tonic-gate 			    "\tcreate_port_node_prop: hca_info_by_guid failed");
31607c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
31617c478bd9Sstevel@tonic-gate 		}
31627c478bd9Sstevel@tonic-gate 
31637c478bd9Sstevel@tonic-gate 		if (hca_list->hl_nports != 0) {
31647c478bd9Sstevel@tonic-gate 			ib_guid_t	*port_guids;
31657c478bd9Sstevel@tonic-gate 			uint8_t		portnum;
31667c478bd9Sstevel@tonic-gate 
31677c478bd9Sstevel@tonic-gate 			ASSERT(hca_list->hl_port_attr != NULL);
31687c478bd9Sstevel@tonic-gate 
31697c478bd9Sstevel@tonic-gate 			port_guids = kmem_zalloc(
31707c478bd9Sstevel@tonic-gate 			    hca_list->hl_nports * sizeof (ib_guid_t),
31717c478bd9Sstevel@tonic-gate 			    KM_SLEEP);
31727c478bd9Sstevel@tonic-gate 
31737c478bd9Sstevel@tonic-gate 			for (portnum = 0; portnum < hca_list->hl_nports;
31747c478bd9Sstevel@tonic-gate 			    portnum++) {
31757c478bd9Sstevel@tonic-gate 				port_guids[portnum] = (hca_list->
31767c478bd9Sstevel@tonic-gate 				    hl_port_attr[portnum]).pa_port_guid;
31777c478bd9Sstevel@tonic-gate 			}
31787c478bd9Sstevel@tonic-gate 
31797c478bd9Sstevel@tonic-gate 			if (ndi_prop_update_int64_array(DDI_DEV_T_NONE,
31807c478bd9Sstevel@tonic-gate 			    child_dip, "port-guids", (int64_t *)port_guids,
31817c478bd9Sstevel@tonic-gate 			    hca_list->hl_nports) != DDI_PROP_SUCCESS) {
31827c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
31837c478bd9Sstevel@tonic-gate 				    "\tcreate_port_node_prop: port-guids "
31847c478bd9Sstevel@tonic-gate 				    "create failed");
31857c478bd9Sstevel@tonic-gate 				kmem_free(port_guids, hca_list->hl_nports *
31867c478bd9Sstevel@tonic-gate 				    sizeof (ib_guid_t));
31877c478bd9Sstevel@tonic-gate 				ibdm_ibnex_free_hca_list(hca_list);
31887c478bd9Sstevel@tonic-gate 				return (IBNEX_FAILURE);
31897c478bd9Sstevel@tonic-gate 			}
31907c478bd9Sstevel@tonic-gate 			kmem_free(port_guids, hca_list->hl_nports *
31917c478bd9Sstevel@tonic-gate 			    sizeof (ib_guid_t));
31927c478bd9Sstevel@tonic-gate 		}
31937c478bd9Sstevel@tonic-gate 
31947c478bd9Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
31957c478bd9Sstevel@tonic-gate 		    "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) {
31967c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
31977c478bd9Sstevel@tonic-gate 			    "\tcreate_port_node_prop: num-ports update failed");
31987c478bd9Sstevel@tonic-gate 			ibdm_ibnex_free_hca_list(hca_list);
31997c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
32007c478bd9Sstevel@tonic-gate 		}
32017c478bd9Sstevel@tonic-gate 		ibdm_ibnex_free_hca_list(hca_list);
32027c478bd9Sstevel@tonic-gate 	}
32037c478bd9Sstevel@tonic-gate 
32047c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
32057c478bd9Sstevel@tonic-gate 	    "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) {
32067c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
32077c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: hca-guid update failed");
32087c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
32097c478bd9Sstevel@tonic-gate 	}
32107c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
32117c478bd9Sstevel@tonic-gate 	    "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) {
32127c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
32137c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: product-id update failed");
32147c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
32157c478bd9Sstevel@tonic-gate 	}
32167c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
32177c478bd9Sstevel@tonic-gate 	    "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) {
32187c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
32197c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: vendor-id update failed");
32207c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
32217c478bd9Sstevel@tonic-gate 	}
32227c478bd9Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version",
32237c478bd9Sstevel@tonic-gate 	    port_attr->pa_dev_version) != DDI_PROP_SUCCESS) {
32247c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
32257c478bd9Sstevel@tonic-gate 		    "\tcreate_port_node_prop: device-version update failed");
32267c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
32277c478bd9Sstevel@tonic-gate 	}
32287c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
32297c478bd9Sstevel@tonic-gate }
32307c478bd9Sstevel@tonic-gate 
32317c478bd9Sstevel@tonic-gate 
32327c478bd9Sstevel@tonic-gate /*
32337c478bd9Sstevel@tonic-gate  * ibnex_str2int()
32347c478bd9Sstevel@tonic-gate  *	Utility function that converts a string of length  "len" to
32357c478bd9Sstevel@tonic-gate  *	integer.
32367c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
32377c478bd9Sstevel@tonic-gate  */
32381cfa752fSRamaswamy Tummala int
32397c478bd9Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret)
32407c478bd9Sstevel@tonic-gate {
32417c478bd9Sstevel@tonic-gate 	int intval = 0, ii;
32427c478bd9Sstevel@tonic-gate 
32437c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c);
32447c478bd9Sstevel@tonic-gate 	*ret = IBNEX_SUCCESS;
32457c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < len; ii ++) {
32467c478bd9Sstevel@tonic-gate 		if ((c[ii] >= '0') && (c[ii] <= '9'))
32477c478bd9Sstevel@tonic-gate 			intval = intval * 10 +c[ii] - '0';
32487c478bd9Sstevel@tonic-gate 		else {
32497c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
32507c478bd9Sstevel@tonic-gate 			    "\tstr2int: Invalid integer string %s..", c);
32517c478bd9Sstevel@tonic-gate 			*ret = IBNEX_FAILURE;
32527c478bd9Sstevel@tonic-gate 			break;
32537c478bd9Sstevel@tonic-gate 		}
32547c478bd9Sstevel@tonic-gate 	}
32557c478bd9Sstevel@tonic-gate 
32567c478bd9Sstevel@tonic-gate 	return (intval);
32577c478bd9Sstevel@tonic-gate }
32587c478bd9Sstevel@tonic-gate 
32597c478bd9Sstevel@tonic-gate 
32607c478bd9Sstevel@tonic-gate /*
32617c478bd9Sstevel@tonic-gate  * ibnex_str2hex()
32627c478bd9Sstevel@tonic-gate  *	Utility functions that converts a string of length  "len" to
32637c478bd9Sstevel@tonic-gate  *	hex value. Note. This function does not handle strings which
32647c478bd9Sstevel@tonic-gate  *	string length more than 8 bytes.
32657c478bd9Sstevel@tonic-gate  *
32667c478bd9Sstevel@tonic-gate  */
32677c478bd9Sstevel@tonic-gate uint64_t
32687c478bd9Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret)
32697c478bd9Sstevel@tonic-gate {
32707c478bd9Sstevel@tonic-gate 	uint64_t hex = 0, ii;
32717c478bd9Sstevel@tonic-gate 
32727c478bd9Sstevel@tonic-gate 	*ret = IBNEX_SUCCESS;
32737c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < len; ii ++) {
32747c478bd9Sstevel@tonic-gate 		hex = (ii == 0) ? hex : (hex << 4);
32757c478bd9Sstevel@tonic-gate 		if ((c[ii] >= '0') && (c[ii] <= '9'))
32767c478bd9Sstevel@tonic-gate 			hex |= c[ii] - '0';
32777c478bd9Sstevel@tonic-gate 		else if ((c[ii] >= 'a') && (c[ii] <= 'f'))
32787c478bd9Sstevel@tonic-gate 			hex |= c[ii] - 'a' + 10;
32797c478bd9Sstevel@tonic-gate 		else if ((c[ii] >= 'A') && (c[ii] <= 'F'))
32807c478bd9Sstevel@tonic-gate 			hex |= c[ii] - 'A' + 10;
32817c478bd9Sstevel@tonic-gate 		else {
32827c478bd9Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
32837c478bd9Sstevel@tonic-gate 			    "\tstr2hex: Invalid integer string");
32847c478bd9Sstevel@tonic-gate 			*ret = IBNEX_FAILURE;
32857c478bd9Sstevel@tonic-gate 			break;
32867c478bd9Sstevel@tonic-gate 		}
32877c478bd9Sstevel@tonic-gate 	}
32887c478bd9Sstevel@tonic-gate 
32897c478bd9Sstevel@tonic-gate 	return (hex);
32907c478bd9Sstevel@tonic-gate }
32917c478bd9Sstevel@tonic-gate 
32927c478bd9Sstevel@tonic-gate 
32937c478bd9Sstevel@tonic-gate /*
32947c478bd9Sstevel@tonic-gate  * ibnex_create_port_compatible_prop()
32957c478bd9Sstevel@tonic-gate  *	Creates 'Compatibility' property for port / HCA_SVC device nodes
32967c478bd9Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
32977c478bd9Sstevel@tonic-gate  */
32987c478bd9Sstevel@tonic-gate static int
32997c478bd9Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip,
33007c478bd9Sstevel@tonic-gate     char *comm_svcp, ibdm_port_attr_t *port_attr)
33017c478bd9Sstevel@tonic-gate {
33027c478bd9Sstevel@tonic-gate 	int 	rval, i;
33037c478bd9Sstevel@tonic-gate 	char	*temp;
33047c478bd9Sstevel@tonic-gate 	char	*compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES];
33057c478bd9Sstevel@tonic-gate 
33067c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin");
33077c478bd9Sstevel@tonic-gate 	/*
33087c478bd9Sstevel@tonic-gate 	 * Initialize the "compatible" property string as below:
33097c478bd9Sstevel@tonic-gate 	 * Compatible Strings :
33107c478bd9Sstevel@tonic-gate 	 * 1. ib.V<vid>P<pid>v<revision>.<service name>.
33117c478bd9Sstevel@tonic-gate 	 * 2. ib.V<vid>P<pid>.<service name>.
33127c478bd9Sstevel@tonic-gate 	 * 3. ib.<service name>
33137c478bd9Sstevel@tonic-gate 	 * Leading zeros must be present
33147c478bd9Sstevel@tonic-gate 	 */
33157c478bd9Sstevel@tonic-gate 	temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP);
33167c478bd9Sstevel@tonic-gate 	for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) {
33177c478bd9Sstevel@tonic-gate 		compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN);
33187c478bd9Sstevel@tonic-gate 	}
33197c478bd9Sstevel@tonic-gate 
33207c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
33217c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08xv%04x.%s",
33227c478bd9Sstevel@tonic-gate 	    port_attr->pa_vendorid, port_attr->pa_productid,
33237c478bd9Sstevel@tonic-gate 	    port_attr->pa_dev_version, comm_svcp);
33247c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
33257c478bd9Sstevel@tonic-gate 	    "ib.V%06xP%08x.%s",
33267c478bd9Sstevel@tonic-gate 	    port_attr->pa_vendorid, port_attr->pa_productid,
33277c478bd9Sstevel@tonic-gate 	    comm_svcp);
33287c478bd9Sstevel@tonic-gate 	(void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
33297c478bd9Sstevel@tonic-gate 	    "ib.%s", comm_svcp);
33307c478bd9Sstevel@tonic-gate 
33317c478bd9Sstevel@tonic-gate 	for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++)
33327c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]);
33337c478bd9Sstevel@tonic-gate 
33347c478bd9Sstevel@tonic-gate 	rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip,
33357c478bd9Sstevel@tonic-gate 	    "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES);
33367c478bd9Sstevel@tonic-gate 
33377c478bd9Sstevel@tonic-gate 	if (rval != DDI_PROP_SUCCESS) {
33387c478bd9Sstevel@tonic-gate 		kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
33397c478bd9Sstevel@tonic-gate 		return (IBNEX_FAILURE);
33407c478bd9Sstevel@tonic-gate 	}
33417c478bd9Sstevel@tonic-gate 	kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
33427c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
33437c478bd9Sstevel@tonic-gate }
33447c478bd9Sstevel@tonic-gate 
33457c478bd9Sstevel@tonic-gate 
33467c478bd9Sstevel@tonic-gate /*
33477c478bd9Sstevel@tonic-gate  * ibnex_delete_port_node_data()
33487c478bd9Sstevel@tonic-gate  *	Delete the parent private node data from the linked list
33497c478bd9Sstevel@tonic-gate  *	Deallocate the memory of the port/ioc attributes
33507c478bd9Sstevel@tonic-gate  *	Deallocate the memory of the node data
33517c478bd9Sstevel@tonic-gate  */
33527c478bd9Sstevel@tonic-gate static void
33537c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node)
33547c478bd9Sstevel@tonic-gate {
33557c478bd9Sstevel@tonic-gate 	if ((node->node_next == NULL) && (node->node_prev == NULL))
33567c478bd9Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = NULL;
33577c478bd9Sstevel@tonic-gate 	else if (node->node_next == NULL)
33587c478bd9Sstevel@tonic-gate 		node->node_prev->node_next = NULL;
33597c478bd9Sstevel@tonic-gate 	else if (node->node_prev == NULL) {
33607c478bd9Sstevel@tonic-gate 		node->node_next->node_prev = NULL;
33617c478bd9Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = node->node_next;
33627c478bd9Sstevel@tonic-gate 	} else {
33637c478bd9Sstevel@tonic-gate 		node->node_prev->node_next = node->node_next;
33647c478bd9Sstevel@tonic-gate 		node->node_next->node_prev = node->node_prev;
33657c478bd9Sstevel@tonic-gate 	}
33667c478bd9Sstevel@tonic-gate 	kmem_free(node, sizeof (ibnex_node_data_t));
33677c478bd9Sstevel@tonic-gate }
33687c478bd9Sstevel@tonic-gate 
33697c478bd9Sstevel@tonic-gate 
33707c478bd9Sstevel@tonic-gate /*
33717c478bd9Sstevel@tonic-gate  * ibnex_is_node_data_present()
33727c478bd9Sstevel@tonic-gate  *	Checks whether ibnex_node_t is created already
33737c478bd9Sstevel@tonic-gate  *	Returns ibnex_node_data_t if found, otherwise NULL
33747c478bd9Sstevel@tonic-gate  */
33757c478bd9Sstevel@tonic-gate static ibnex_node_data_t *
33767c478bd9Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr,
33777c478bd9Sstevel@tonic-gate     int index, ib_pkey_t pkey)
33787c478bd9Sstevel@tonic-gate {
33797c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
33807c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
33817c478bd9Sstevel@tonic-gate 	if (node_type == IBNEX_IOC_NODE) {
33827c478bd9Sstevel@tonic-gate 		ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr;
33837c478bd9Sstevel@tonic-gate 
33847c478bd9Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL;
33857c478bd9Sstevel@tonic-gate 		    nodep = nodep->node_next) {
33867c478bd9Sstevel@tonic-gate 			if (nodep->node_data.ioc_node.ioc_guid ==
33877c478bd9Sstevel@tonic-gate 			    ioc_infop->ioc_profile.ioc_guid) {
33887c478bd9Sstevel@tonic-gate 				return (nodep);
33897c478bd9Sstevel@tonic-gate 			}
33907c478bd9Sstevel@tonic-gate 		}
33917c478bd9Sstevel@tonic-gate 
33927c478bd9Sstevel@tonic-gate 	} else if (node_type == IBNEX_PSEUDO_NODE) {
33937c478bd9Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
33947c478bd9Sstevel@tonic-gate 		    nodep = nodep->node_next)
33957c478bd9Sstevel@tonic-gate 			if (strcmp(nodep->node_data.pseudo_node.
33967c478bd9Sstevel@tonic-gate 			    pseudo_node_addr, (char *)attr) == 0)
33977c478bd9Sstevel@tonic-gate 				return (nodep);
33987c478bd9Sstevel@tonic-gate 
33997c478bd9Sstevel@tonic-gate 	} else {
34007c478bd9Sstevel@tonic-gate 		ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr;
34017c478bd9Sstevel@tonic-gate 
34027c478bd9Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_port_node_head; nodep != NULL;
34037c478bd9Sstevel@tonic-gate 		    nodep = nodep->node_next) {
34047c478bd9Sstevel@tonic-gate 			if ((nodep->node_data.port_node.port_guid ==
34057c478bd9Sstevel@tonic-gate 			    pattrp->pa_port_guid) &&
34067c478bd9Sstevel@tonic-gate 			    (nodep->node_data.port_node.port_commsvc_idx ==
34077c478bd9Sstevel@tonic-gate 			    index) &&
34087c478bd9Sstevel@tonic-gate 			    (nodep->node_data.port_node.port_pkey == pkey)) {
34097c478bd9Sstevel@tonic-gate 				return (nodep);
34107c478bd9Sstevel@tonic-gate 			}
34117c478bd9Sstevel@tonic-gate 		}
34127c478bd9Sstevel@tonic-gate 	}
34137c478bd9Sstevel@tonic-gate 	return (NULL);
34147c478bd9Sstevel@tonic-gate }
34157c478bd9Sstevel@tonic-gate 
34167c478bd9Sstevel@tonic-gate /*
34177c478bd9Sstevel@tonic-gate  * ibnex_lookup_unit_address_prop:
34187c478bd9Sstevel@tonic-gate  *
34199d3d2ed0Shiremath  *	If property with name is found, return its value
34207c478bd9Sstevel@tonic-gate  *	otherwise return NULL.
34217c478bd9Sstevel@tonic-gate  */
34227c478bd9Sstevel@tonic-gate static char *
34239d3d2ed0Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name)
34247c478bd9Sstevel@tonic-gate {
34257c478bd9Sstevel@tonic-gate 	ddi_prop_t	*propp;
34267c478bd9Sstevel@tonic-gate 
34279d3d2ed0Shiremath 	/* Search the list of properties for name */
34287c478bd9Sstevel@tonic-gate 	for (propp = head; propp != NULL; propp = propp->prop_next)  {
34299d3d2ed0Shiremath 		if (strcmp(propp->prop_name, name) != 0)
34307c478bd9Sstevel@tonic-gate 			continue;
34319d3d2ed0Shiremath 		/* named property should be valid and have a value */
34327c478bd9Sstevel@tonic-gate 		if (propp->prop_len <= 1)
34337c478bd9Sstevel@tonic-gate 			break;
34347c478bd9Sstevel@tonic-gate 		return ((char *)propp->prop_val);
34357c478bd9Sstevel@tonic-gate 	}
34367c478bd9Sstevel@tonic-gate 
34377c478bd9Sstevel@tonic-gate 	return ((char *)0);
34387c478bd9Sstevel@tonic-gate }
34397c478bd9Sstevel@tonic-gate 
34407c478bd9Sstevel@tonic-gate 
34417c478bd9Sstevel@tonic-gate /*
34427c478bd9Sstevel@tonic-gate  * ibnex_pseudo_initnodes()
34437c478bd9Sstevel@tonic-gate  *	This routine is specific to pseudo node information handling
34447c478bd9Sstevel@tonic-gate  *	Creates a ibnex_node_data_t all pseudo nodes children of ibnex
34457c478bd9Sstevel@tonic-gate  */
34467c478bd9Sstevel@tonic-gate void
34477c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes()
34487c478bd9Sstevel@tonic-gate {
34497c478bd9Sstevel@tonic-gate 	int			pnam_len, len;
34507c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
34517c478bd9Sstevel@tonic-gate 	struct hwc_spec		*list, *spec;
34527c478bd9Sstevel@tonic-gate 	char			*node_addr, *temp, *unit_addr;
34539d3d2ed0Shiremath 	char			*node_type;
34547c478bd9Sstevel@tonic-gate 
34557c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes");
34567c478bd9Sstevel@tonic-gate 
34577c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
34587c478bd9Sstevel@tonic-gate 	/*
34597c478bd9Sstevel@tonic-gate 	 * get a list of all "pseudo" children of "ib".
34607c478bd9Sstevel@tonic-gate 	 * for these children initialize/allocate an internal
34617c478bd9Sstevel@tonic-gate 	 * ibnex_node_data_t.
34627c478bd9Sstevel@tonic-gate 	 */
34637c478bd9Sstevel@tonic-gate 	list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1);
34647c478bd9Sstevel@tonic-gate 	for (spec = list; spec != NULL; spec = spec->hwc_next) {
34657c478bd9Sstevel@tonic-gate 		if (spec->hwc_devi_sys_prop_ptr == NULL)
34667c478bd9Sstevel@tonic-gate 			continue;
34677c478bd9Sstevel@tonic-gate 
34689d3d2ed0Shiremath 		/* Check "ib-node-type" property for IOC .conf */
34699d3d2ed0Shiremath 		node_type = ibnex_lookup_named_prop(
34709d3d2ed0Shiremath 		    spec->hwc_devi_sys_prop_ptr, "ib-node-type");
34719d3d2ed0Shiremath 
34727c478bd9Sstevel@tonic-gate 		/* "unit-address" property should be present */
34739d3d2ed0Shiremath 		temp = ibnex_lookup_named_prop(
34749d3d2ed0Shiremath 		    spec->hwc_devi_sys_prop_ptr, "unit-address");
34757c478bd9Sstevel@tonic-gate 		if (temp == NULL)
34767c478bd9Sstevel@tonic-gate 			continue;
34777c478bd9Sstevel@tonic-gate 
34787c478bd9Sstevel@tonic-gate 		pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2;
34797c478bd9Sstevel@tonic-gate 
34807c478bd9Sstevel@tonic-gate 		node_addr = kmem_zalloc(pnam_len, KM_SLEEP);
34817c478bd9Sstevel@tonic-gate 
34827c478bd9Sstevel@tonic-gate 		(void) snprintf(node_addr,
34837c478bd9Sstevel@tonic-gate 		    pnam_len, "%s,%s", spec->hwc_devi_name, temp);
34847c478bd9Sstevel@tonic-gate 
34857c478bd9Sstevel@tonic-gate 		nodep = ibnex_is_node_data_present(
34867c478bd9Sstevel@tonic-gate 		    IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0);
34877c478bd9Sstevel@tonic-gate 
34887c478bd9Sstevel@tonic-gate 		if (nodep) {
34897c478bd9Sstevel@tonic-gate 			kmem_free(node_addr, pnam_len);
34907c478bd9Sstevel@tonic-gate 			continue;
34917c478bd9Sstevel@tonic-gate 		}
34927c478bd9Sstevel@tonic-gate 
34937c478bd9Sstevel@tonic-gate 		nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE,
34947c478bd9Sstevel@tonic-gate 		    (void *)spec->hwc_devi_name, 0, 0);
34957c478bd9Sstevel@tonic-gate 
34967c478bd9Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_node_addr = node_addr;
34977c478bd9Sstevel@tonic-gate 		(void) snprintf(nodep->node_data.
34987c478bd9Sstevel@tonic-gate 		    pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr);
34997c478bd9Sstevel@tonic-gate 
35007c478bd9Sstevel@tonic-gate 		len = strlen(temp) + 1;
35017c478bd9Sstevel@tonic-gate 		unit_addr = (char *)kmem_alloc(len, KM_SLEEP);
35027c478bd9Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr;
35037c478bd9Sstevel@tonic-gate 		(void) snprintf(unit_addr, len, "%s", temp);
35047c478bd9Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_unit_addr_len = len;
35057c478bd9Sstevel@tonic-gate 
35069d3d2ed0Shiremath 		if (node_type && strcmp(node_type, "merge") == 0)
35079d3d2ed0Shiremath 			nodep->node_data.pseudo_node.pseudo_merge_node = 1;
35089d3d2ed0Shiremath 
35097c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s"
35107c478bd9Sstevel@tonic-gate 		    " : drv name = %s", unit_addr, spec->hwc_devi_name);
35117c478bd9Sstevel@tonic-gate 	}
35127c478bd9Sstevel@tonic-gate 	hwc_free_spec_list(list);
35137c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
35147c478bd9Sstevel@tonic-gate }
35157c478bd9Sstevel@tonic-gate 
35167c478bd9Sstevel@tonic-gate 
35177c478bd9Sstevel@tonic-gate /*
35187c478bd9Sstevel@tonic-gate  * ibnex_init_child_nodedata()
35197c478bd9Sstevel@tonic-gate  *
35207c478bd9Sstevel@tonic-gate  *	Allocate memory for the parent private data for device node
35217c478bd9Sstevel@tonic-gate  *	Initializes the parent private child device node data.
35227c478bd9Sstevel@tonic-gate  *	Returns pointer to the parent private data
35237c478bd9Sstevel@tonic-gate  */
35247c478bd9Sstevel@tonic-gate static ibnex_node_data_t *
35257c478bd9Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index,
35267c478bd9Sstevel@tonic-gate     ib_pkey_t pkey)
35277c478bd9Sstevel@tonic-gate {
35287c478bd9Sstevel@tonic-gate 	char			 *devi_name;
35297c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t		 *ioc_info;
35307c478bd9Sstevel@tonic-gate 	ibnex_ioc_node_t	 *ioc_node;
35317c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	 *node_data;
35327c478bd9Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *ioc_profile;
35337c478bd9Sstevel@tonic-gate 
35347c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
35357c478bd9Sstevel@tonic-gate 
35367c478bd9Sstevel@tonic-gate 	node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP);
353700a3eaf3SRamaswamy Tummala 	node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED;
35387c478bd9Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
35397c478bd9Sstevel@tonic-gate 	node_data->node_type	= node_type;
35407c478bd9Sstevel@tonic-gate 
35417c478bd9Sstevel@tonic-gate 	if (node_type == IBNEX_IOC_NODE) {
35427c478bd9Sstevel@tonic-gate 		ioc_info	= (ibdm_ioc_info_t *)attr;
35437c478bd9Sstevel@tonic-gate 		ioc_profile	= &ioc_info->ioc_profile;
35447c478bd9Sstevel@tonic-gate 		ioc_node	= &node_data->node_data.ioc_node;
35457c478bd9Sstevel@tonic-gate 
35467c478bd9Sstevel@tonic-gate 		ioc_node->iou_guid = ioc_info->ioc_iou_guid;
35477c478bd9Sstevel@tonic-gate 		ioc_node->ioc_guid = ioc_profile->ioc_guid;
35487c478bd9Sstevel@tonic-gate 		(void) strncpy(ioc_node->ioc_id_string,
35497c478bd9Sstevel@tonic-gate 		    (char *)ioc_profile->ioc_id_string,
35507c478bd9Sstevel@tonic-gate 		    IB_DM_IOC_ID_STRING_LEN);
35517c478bd9Sstevel@tonic-gate 		ioc_node->ioc_ngids = ioc_info->ioc_nportgids;
35527c478bd9Sstevel@tonic-gate 
35537c478bd9Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_ioc_node_head;
35547c478bd9Sstevel@tonic-gate 		node_data->node_prev = NULL;
35557c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_ioc_node_head)
35567c478bd9Sstevel@tonic-gate 			ibnex.ibnex_ioc_node_head->node_prev = node_data;
35577c478bd9Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = node_data;
35587c478bd9Sstevel@tonic-gate 	} else if (node_type == IBNEX_PSEUDO_NODE) {
35597c478bd9Sstevel@tonic-gate 		devi_name = (char *)attr;
35607c478bd9Sstevel@tonic-gate 		node_data->node_data.pseudo_node.pseudo_devi_name =
35617c478bd9Sstevel@tonic-gate 		    kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP);
35627c478bd9Sstevel@tonic-gate 		(void) strncpy(node_data->node_data.pseudo_node.
35637c478bd9Sstevel@tonic-gate 		    pseudo_devi_name, devi_name, strlen(devi_name));
35647c478bd9Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_pseudo_node_head;
35657c478bd9Sstevel@tonic-gate 		node_data->node_prev = NULL;
35667c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_pseudo_node_head)
35677c478bd9Sstevel@tonic-gate 			ibnex.ibnex_pseudo_node_head->node_prev = node_data;
35687c478bd9Sstevel@tonic-gate 		ibnex.ibnex_pseudo_node_head = node_data;
35697c478bd9Sstevel@tonic-gate 	} else {
35707c478bd9Sstevel@tonic-gate 		node_data->node_data.port_node.port_hcaguid =
35717c478bd9Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_hca_guid;
35727c478bd9Sstevel@tonic-gate 		node_data->node_data.port_node.port_guid =
35737c478bd9Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_port_guid;
35747c478bd9Sstevel@tonic-gate 		node_data->node_data.port_node.port_num =
35757c478bd9Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_port_num;
35767c478bd9Sstevel@tonic-gate 		node_data->node_data.port_node.port_commsvc_idx = index;
35777c478bd9Sstevel@tonic-gate 		node_data->node_data.port_node.port_pkey = pkey;
35787c478bd9Sstevel@tonic-gate 
35797c478bd9Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_port_node_head;
35807c478bd9Sstevel@tonic-gate 		node_data->node_prev = NULL;
35817c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_port_node_head)
35827c478bd9Sstevel@tonic-gate 			ibnex.ibnex_port_node_head->node_prev = node_data;
35837c478bd9Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = node_data;
35847c478bd9Sstevel@tonic-gate 	}
35857c478bd9Sstevel@tonic-gate 	return (node_data);
35867c478bd9Sstevel@tonic-gate }
35877c478bd9Sstevel@tonic-gate 
35887c478bd9Sstevel@tonic-gate static int
35897c478bd9Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
35907c478bd9Sstevel@tonic-gate     char *eventname, ddi_eventcookie_t *cookie)
35917c478bd9Sstevel@tonic-gate {
35927c478bd9Sstevel@tonic-gate 	int rc;
35937c478bd9Sstevel@tonic-gate 
35947c478bd9Sstevel@tonic-gate 
35957c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)",
35967c478bd9Sstevel@tonic-gate 	    dip, rdip, eventname, cookie);
35977c478bd9Sstevel@tonic-gate 
35987c478bd9Sstevel@tonic-gate 	rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl,
35997c478bd9Sstevel@tonic-gate 	    rdip, eventname, cookie, NDI_EVENT_NOPASS);
36007c478bd9Sstevel@tonic-gate 	if (rc == NDI_SUCCESS) {
36017c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
36027c478bd9Sstevel@tonic-gate 		ibnex.ibnex_prop_update_evt_cookie = *cookie;
36037c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
36047c478bd9Sstevel@tonic-gate 	}
36057c478bd9Sstevel@tonic-gate 
36067c478bd9Sstevel@tonic-gate 	return (rc);
36077c478bd9Sstevel@tonic-gate }
36087c478bd9Sstevel@tonic-gate 
36097c478bd9Sstevel@tonic-gate static int
36107c478bd9Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
36117c478bd9Sstevel@tonic-gate     ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip,
36127c478bd9Sstevel@tonic-gate     ddi_eventcookie_t cookie, void *arg, void *bus_impldata),
36137c478bd9Sstevel@tonic-gate     void *arg, ddi_callback_id_t *cb_id)
36147c478bd9Sstevel@tonic-gate {
36157c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
36167c478bd9Sstevel@tonic-gate 	    "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)",
36177c478bd9Sstevel@tonic-gate 	    dip, rdip, cookie, callback, arg, cb_id);
36187c478bd9Sstevel@tonic-gate 
36197c478bd9Sstevel@tonic-gate 	return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl,
36207c478bd9Sstevel@tonic-gate 	    rdip, cookie, callback, arg, NDI_SLEEP, cb_id));
36217c478bd9Sstevel@tonic-gate }
36227c478bd9Sstevel@tonic-gate 
36237c478bd9Sstevel@tonic-gate static int
36247c478bd9Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
36257c478bd9Sstevel@tonic-gate {
36267c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)",
36277c478bd9Sstevel@tonic-gate 	    dip, cb_id);
36287c478bd9Sstevel@tonic-gate 
36297c478bd9Sstevel@tonic-gate 	return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl,
36307c478bd9Sstevel@tonic-gate 	    cb_id));
36317c478bd9Sstevel@tonic-gate }
36327c478bd9Sstevel@tonic-gate 
36337c478bd9Sstevel@tonic-gate static int
36347c478bd9Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip,
36357c478bd9Sstevel@tonic-gate     ddi_eventcookie_t cookie, void *bus_impldata)
36367c478bd9Sstevel@tonic-gate {
36377c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)",
36387c478bd9Sstevel@tonic-gate 	    dip, rdip, cookie, bus_impldata);
36397c478bd9Sstevel@tonic-gate 
36407c478bd9Sstevel@tonic-gate 	return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip,
36417c478bd9Sstevel@tonic-gate 	    cookie, bus_impldata));
36427c478bd9Sstevel@tonic-gate }
36437c478bd9Sstevel@tonic-gate 
36447c478bd9Sstevel@tonic-gate /*
36457c478bd9Sstevel@tonic-gate  * ibnex_reprobe_ioc_dev()
36467c478bd9Sstevel@tonic-gate  *
36477c478bd9Sstevel@tonic-gate  * This could be called as a result of ibt_reprobe_dev request or
36487c478bd9Sstevel@tonic-gate  * cfgadm command. The function is called from a taskq in case of
36497c478bd9Sstevel@tonic-gate  * ibt_reprobe_dev and from user context for cfgadm command.
36507c478bd9Sstevel@tonic-gate  *
36517c478bd9Sstevel@tonic-gate  * This function reprobes the properties for one IOC dip.
36527c478bd9Sstevel@tonic-gate  *
36537c478bd9Sstevel@tonic-gate  * node_reprobe_state should be set before calling this function.
36547c478bd9Sstevel@tonic-gate  */
36557c478bd9Sstevel@tonic-gate void
36567c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg)
36577c478bd9Sstevel@tonic-gate {
36587c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = (dev_info_t *)arg;
36597c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
36607c478bd9Sstevel@tonic-gate 	ibnex_ioc_node_t	*ioc_data;
36617c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
36627c478bd9Sstevel@tonic-gate 
36637c478bd9Sstevel@tonic-gate 	/* ASSERT(NO_LOCKS_HELD); */
36647c478bd9Sstevel@tonic-gate 	ASSERT(dip != NULL);
36657c478bd9Sstevel@tonic-gate 
36667c478bd9Sstevel@tonic-gate 	node_data = ddi_get_parent_data(dip);
36677c478bd9Sstevel@tonic-gate 	ASSERT(node_data);
36687c478bd9Sstevel@tonic-gate 
36697c478bd9Sstevel@tonic-gate 	if (node_data->node_dip == NULL) {
36707c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip");
36717c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
36727c478bd9Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 0);
36737c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
36747c478bd9Sstevel@tonic-gate 		return;
36757c478bd9Sstevel@tonic-gate 	}
36767c478bd9Sstevel@tonic-gate 	ioc_data = &(node_data->node_data.ioc_node);
36777c478bd9Sstevel@tonic-gate 
36787c478bd9Sstevel@tonic-gate 	/* Reprobe the IOC */
36797c478bd9Sstevel@tonic-gate 	ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid,
36807c478bd9Sstevel@tonic-gate 	    1);
36817c478bd9Sstevel@tonic-gate 	if (ioc_info == NULL) {
36827c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe");
36837c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
36847c478bd9Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 1);
36857c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
36867c478bd9Sstevel@tonic-gate 		return;
36877c478bd9Sstevel@tonic-gate 	}
36887c478bd9Sstevel@tonic-gate 
36897c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
36907c478bd9Sstevel@tonic-gate 	if (node_data->node_dip)
36917c478bd9Sstevel@tonic-gate 		ibnex_update_prop(node_data, ioc_info);
36927c478bd9Sstevel@tonic-gate 	ibnex_wakeup_reprobe_ioc(node_data, 0);
36937c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
36947c478bd9Sstevel@tonic-gate 
36957c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
36967c478bd9Sstevel@tonic-gate }
36977c478bd9Sstevel@tonic-gate 
36987c478bd9Sstevel@tonic-gate /*
36997c478bd9Sstevel@tonic-gate  * ibnex_reprobe_all()
37007c478bd9Sstevel@tonic-gate  *
37017c478bd9Sstevel@tonic-gate  * This could be called as a result of cfgadm command. The function
37027c478bd9Sstevel@tonic-gate  * is called from user context.
37037c478bd9Sstevel@tonic-gate  *
37047c478bd9Sstevel@tonic-gate  * This function reprobes the properties for all IOC dips.
37057c478bd9Sstevel@tonic-gate  *
37067c478bd9Sstevel@tonic-gate  * ibnex_reprobe_state should be set before calling this function.
37077c478bd9Sstevel@tonic-gate  */
37087c478bd9Sstevel@tonic-gate void
37097c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_all()
37107c478bd9Sstevel@tonic-gate {
37117c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
37127c478bd9Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info_list, *ioc;
37137c478bd9Sstevel@tonic-gate 
37147c478bd9Sstevel@tonic-gate 	/* ASSERT(NO_LOCKS_HELD); */
37157c478bd9Sstevel@tonic-gate 
37167c478bd9Sstevel@tonic-gate 	/* Sweep the fabric */
37177c478bd9Sstevel@tonic-gate 	ioc = ioc_info_list = ibdm_ibnex_get_ioc_list(
37187c478bd9Sstevel@tonic-gate 	    IBDM_IBNEX_REPROBE_ALL);
37197c478bd9Sstevel@tonic-gate 	if (ioc_info_list == NULL) {
37207c478bd9Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
37217c478bd9Sstevel@tonic-gate 		ibnex_wakeup_reprobe_all();
37227c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
37237c478bd9Sstevel@tonic-gate 		return;
37247c478bd9Sstevel@tonic-gate 	}
37257c478bd9Sstevel@tonic-gate 
37267c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
37277c478bd9Sstevel@tonic-gate 	while (ioc_info_list) {
37287c478bd9Sstevel@tonic-gate 		if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
37297c478bd9Sstevel@tonic-gate 		    ioc_info_list, 0, 0)) != NULL &&
37307c478bd9Sstevel@tonic-gate 		    node_data->node_dip != NULL) {
37317c478bd9Sstevel@tonic-gate 			ibnex_update_prop(node_data, ioc_info_list);
37327c478bd9Sstevel@tonic-gate 		}
37337c478bd9Sstevel@tonic-gate 		ioc_info_list = ioc_info_list->ioc_next;
37347c478bd9Sstevel@tonic-gate 	}
37357c478bd9Sstevel@tonic-gate 	ibnex_wakeup_reprobe_all();
37367c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
37377c478bd9Sstevel@tonic-gate 
37387c478bd9Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc);
37397c478bd9Sstevel@tonic-gate }
37407c478bd9Sstevel@tonic-gate 
37417c478bd9Sstevel@tonic-gate /*
37427c478bd9Sstevel@tonic-gate  * Update the properties, if it has modified and notify IBTF client.
37437c478bd9Sstevel@tonic-gate  */
37447c478bd9Sstevel@tonic-gate static void
37457c478bd9Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info)
37467c478bd9Sstevel@tonic-gate {
37477c478bd9Sstevel@tonic-gate 	ibt_prop_update_payload_t	evt_data;
37487c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = node_data->node_dip;
37497c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t	evt_cookie;
37507c478bd9Sstevel@tonic-gate 	ibnex_ioc_node_t *ioc;
37517c478bd9Sstevel@tonic-gate 
37527c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
37537c478bd9Sstevel@tonic-gate 
37547c478bd9Sstevel@tonic-gate 	ASSERT(dip != NULL);
37557c478bd9Sstevel@tonic-gate 
37567c478bd9Sstevel@tonic-gate 	ioc = &node_data->node_data.ioc_node;
37577c478bd9Sstevel@tonic-gate 
37587c478bd9Sstevel@tonic-gate 	evt_data = ioc_info->ioc_info_updated;
37597c478bd9Sstevel@tonic-gate 	evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
37607c478bd9Sstevel@tonic-gate 
37617c478bd9Sstevel@tonic-gate 	/*
37627c478bd9Sstevel@tonic-gate 	 * For a disconnected IOC :
37637c478bd9Sstevel@tonic-gate 	 *	Store the ioc_profile for supplying cfgadm info
37647c478bd9Sstevel@tonic-gate 	 *	ibdm maintains no info of disconnected IOC
37657c478bd9Sstevel@tonic-gate 	 *
37667c478bd9Sstevel@tonic-gate 	 * For reconnected IOC :
37677c478bd9Sstevel@tonic-gate 	 *	ibdm has info of previous service entries
37687c478bd9Sstevel@tonic-gate 	 *	ioc_profile maintained by ibnexus is used to
37697c478bd9Sstevel@tonic-gate 	 *	update ib_srv_prop_updated.
37707c478bd9Sstevel@tonic-gate 	 *	Free the ibnex maintained ioc_profile
37717c478bd9Sstevel@tonic-gate 	 */
37727c478bd9Sstevel@tonic-gate 	if (ioc_info->ioc_nportgids == 0) {
37737c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
37747c478bd9Sstevel@tonic-gate 		    "\tupdate_prop:  IOC disconnected");
37757c478bd9Sstevel@tonic-gate 		ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc(
37767c478bd9Sstevel@tonic-gate 		    sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP);
37777c478bd9Sstevel@tonic-gate 		bcopy(&ioc_info->ioc_profile, ioc->ioc_profile,
37787c478bd9Sstevel@tonic-gate 		    sizeof (ib_dm_ioc_ctrl_profile_t));
37797c478bd9Sstevel@tonic-gate 
37807c478bd9Sstevel@tonic-gate 		ibnex.ibnex_num_disconnect_iocs++;
37817c478bd9Sstevel@tonic-gate 	} else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 &&
37827c478bd9Sstevel@tonic-gate 	    ioc->ioc_profile != NULL) {
37837c478bd9Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
37847c478bd9Sstevel@tonic-gate 		    "\tupdate_prop: IOC reconnected");
37857c478bd9Sstevel@tonic-gate 		if (ioc->ioc_profile->ioc_service_entries !=
37867c478bd9Sstevel@tonic-gate 		    ioc_info->ioc_profile.ioc_service_entries)
37877c478bd9Sstevel@tonic-gate 			evt_data.ib_srv_prop_updated = 1;
37887c478bd9Sstevel@tonic-gate 
37897c478bd9Sstevel@tonic-gate 		ibnex.ibnex_num_disconnect_iocs--;
37907c478bd9Sstevel@tonic-gate 		kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t));
37917c478bd9Sstevel@tonic-gate 		ioc->ioc_profile = NULL;
37927c478bd9Sstevel@tonic-gate 	}
37937c478bd9Sstevel@tonic-gate 
37947c478bd9Sstevel@tonic-gate 	/* Update the properties that have changed */
37957c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
37967c478bd9Sstevel@tonic-gate 	if (evt_data.ib_gid_prop_updated) {
37977c478bd9Sstevel@tonic-gate 		if (ibnex_create_ioc_portgid_prop(dip, ioc_info) !=
37987c478bd9Sstevel@tonic-gate 		    IBNEX_SUCCESS) {
37997c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
38007c478bd9Sstevel@tonic-gate 			return;
38017c478bd9Sstevel@tonic-gate 		}
38027c478bd9Sstevel@tonic-gate 	}
38037c478bd9Sstevel@tonic-gate 	if (evt_data.ib_srv_prop_updated) {
38047c478bd9Sstevel@tonic-gate 		if (ioc_info->ioc_profile.ioc_service_entries != 0 &&
38057c478bd9Sstevel@tonic-gate 		    (ibnex_create_ioc_srv_props(dip, ioc_info) !=
38067c478bd9Sstevel@tonic-gate 		    IBNEX_SUCCESS)) {
38077c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
38087c478bd9Sstevel@tonic-gate 			return;
38097c478bd9Sstevel@tonic-gate 		} else if (ioc_info->ioc_profile.ioc_service_entries == 0) {
38107c478bd9Sstevel@tonic-gate 			(void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
38117c478bd9Sstevel@tonic-gate 			    "service-id");
38127c478bd9Sstevel@tonic-gate 			(void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
38137c478bd9Sstevel@tonic-gate 			    "service-name");
38147c478bd9Sstevel@tonic-gate 		}
38157c478bd9Sstevel@tonic-gate 	}
38167c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
38177c478bd9Sstevel@tonic-gate 	ioc->ioc_ngids = ioc_info->ioc_nportgids;
38187c478bd9Sstevel@tonic-gate 
38197c478bd9Sstevel@tonic-gate 	/*
38207c478bd9Sstevel@tonic-gate 	 * Post an event if :
38217c478bd9Sstevel@tonic-gate 	 *	1. Properites have changed or NOTIFY_ALWAYS is set.
38227c478bd9Sstevel@tonic-gate 	 *	2. child dip is configured and a valid cookie for
38237c478bd9Sstevel@tonic-gate 	 *	   IB_PROP_UPDATE_EVENT.
38247c478bd9Sstevel@tonic-gate 	 */
38257c478bd9Sstevel@tonic-gate 	if ((evt_data.ib_prop_updated != 0 ||
38267c478bd9Sstevel@tonic-gate 	    (node_data->node_reprobe_state &
38277c478bd9Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) &&
38287c478bd9Sstevel@tonic-gate 	    ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) &&
38297c478bd9Sstevel@tonic-gate 	    (evt_cookie != NULL))) {
38307c478bd9Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
38317c478bd9Sstevel@tonic-gate 
38327c478bd9Sstevel@tonic-gate 			if (ndi_post_event(ibnex.ibnex_dip, dip,
38337c478bd9Sstevel@tonic-gate 			    evt_cookie, &evt_data) != NDI_SUCCESS)
38347c478bd9Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
38357c478bd9Sstevel@tonic-gate 				    "\tndi_post_event failed\n");
38367c478bd9Sstevel@tonic-gate 
38377c478bd9Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
38387c478bd9Sstevel@tonic-gate 	}
38397c478bd9Sstevel@tonic-gate 
38407c478bd9Sstevel@tonic-gate 	/*
38417c478bd9Sstevel@tonic-gate 	 * Cleanup node_reprobe_state, for ibt_reprobe_dev
38427c478bd9Sstevel@tonic-gate 	 * requests, when reprobe all / node reprobe is in
38437c478bd9Sstevel@tonic-gate 	 * progress. ibnex_reprobe_ioc_dev is not called
38447c478bd9Sstevel@tonic-gate 	 * in this case.
38457c478bd9Sstevel@tonic-gate 	 */
38467c478bd9Sstevel@tonic-gate 	if (node_data->node_reprobe_state ==
38477c478bd9Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)
38487c478bd9Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 0);
38497c478bd9Sstevel@tonic-gate }
38507c478bd9Sstevel@tonic-gate 
38517c478bd9Sstevel@tonic-gate static ibnex_rval_t
38527c478bd9Sstevel@tonic-gate ibnex_unique_svcname(char *svcname)
38537c478bd9Sstevel@tonic-gate {
38547c478bd9Sstevel@tonic-gate 	int i;
38557c478bd9Sstevel@tonic-gate 
38567c478bd9Sstevel@tonic-gate 	/* Check Port Services */
38577c478bd9Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++)
38587c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname,
38597c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_comm_svc_names[i], 4) == 0)
38607c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
38617c478bd9Sstevel@tonic-gate 
38627c478bd9Sstevel@tonic-gate 	/* Check VPPA Services */
38637c478bd9Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++)
38647c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname,
38657c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0)
38667c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
38677c478bd9Sstevel@tonic-gate 
38687c478bd9Sstevel@tonic-gate 	/* Check HCA_SVC Services */
38697c478bd9Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++)
38707c478bd9Sstevel@tonic-gate 		if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname,
38717c478bd9Sstevel@tonic-gate 		    ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0)
38727c478bd9Sstevel@tonic-gate 			return (IBNEX_FAILURE);
38737c478bd9Sstevel@tonic-gate 
38747c478bd9Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
38757c478bd9Sstevel@tonic-gate }
38767c478bd9Sstevel@tonic-gate 
38777c478bd9Sstevel@tonic-gate static void
38787c478bd9Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg)
38797c478bd9Sstevel@tonic-gate {
38807c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = (dev_info_t *)arg;
38817c478bd9Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
38827c478bd9Sstevel@tonic-gate 
38837c478bd9Sstevel@tonic-gate 	ASSERT(dip != NULL);
38847c478bd9Sstevel@tonic-gate 	node_data = ddi_get_parent_data(dip);
38857c478bd9Sstevel@tonic-gate 	ASSERT(node_data);
38867c478bd9Sstevel@tonic-gate 
38877c478bd9Sstevel@tonic-gate 	/*
38887c478bd9Sstevel@tonic-gate 	 * Return success if:
38897c478bd9Sstevel@tonic-gate 	 *	1. Reprobe for all nodes are in progress
38907c478bd9Sstevel@tonic-gate 	 *	2. Reprobe for this node is in progress.
38917c478bd9Sstevel@tonic-gate 	 * The reprobe in progress will complete eventually and
38927c478bd9Sstevel@tonic-gate 	 * update the properties, if required.
38937c478bd9Sstevel@tonic-gate 	 */
38947c478bd9Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
38957c478bd9Sstevel@tonic-gate 	if (ibnex.ibnex_reprobe_state != 0 ||
38967c478bd9Sstevel@tonic-gate 	    node_data->node_reprobe_state != 0) {
38977c478bd9Sstevel@tonic-gate 		/*
38987c478bd9Sstevel@tonic-gate 		 * Setting NOTIFY_ALWAYS to ensure that
38997c478bd9Sstevel@tonic-gate 		 * DDI event is delivered always for
39007c478bd9Sstevel@tonic-gate 		 * ibt_reprobe_dev
39017c478bd9Sstevel@tonic-gate 		 */
39027c478bd9Sstevel@tonic-gate 		node_data->node_reprobe_state |=
39037c478bd9Sstevel@tonic-gate 		    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
39047c478bd9Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
39057c478bd9Sstevel@tonic-gate 		return;
39067c478bd9Sstevel@tonic-gate 	}
39077c478bd9Sstevel@tonic-gate 	node_data->node_reprobe_state =
39087c478bd9Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
39097c478bd9Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
39107c478bd9Sstevel@tonic-gate 	ibnex_reprobe_ioc_dev(arg);
39117c478bd9Sstevel@tonic-gate }
39127c478bd9Sstevel@tonic-gate 
39137c478bd9Sstevel@tonic-gate 
39147c478bd9Sstevel@tonic-gate /*
39157c478bd9Sstevel@tonic-gate  * MPxIO pathmangement routines. Currently IB nexus does not support
39167c478bd9Sstevel@tonic-gate  * any kind of pathmangement. So, just return success to make MPxIO
39177c478bd9Sstevel@tonic-gate  * framework happy.
39187c478bd9Sstevel@tonic-gate  */
39197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39207c478bd9Sstevel@tonic-gate static int
392100a3eaf3SRamaswamy Tummala ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
39227c478bd9Sstevel@tonic-gate {
392300a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip);
39247c478bd9Sstevel@tonic-gate 	return (MDI_SUCCESS);
39257c478bd9Sstevel@tonic-gate }
39267c478bd9Sstevel@tonic-gate 
39277c478bd9Sstevel@tonic-gate 
39287c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39297c478bd9Sstevel@tonic-gate static int
393000a3eaf3SRamaswamy Tummala ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
39317c478bd9Sstevel@tonic-gate {
393200a3eaf3SRamaswamy Tummala 	dev_info_t *cdip;
393300a3eaf3SRamaswamy Tummala 	ibnex_node_data_t *node_data;
393400a3eaf3SRamaswamy Tummala 	int clnt_num_pi;
393500a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip);
393600a3eaf3SRamaswamy Tummala 
393700a3eaf3SRamaswamy Tummala 	if (pip == NULL)
393800a3eaf3SRamaswamy Tummala 		return (MDI_FAILURE);
393900a3eaf3SRamaswamy Tummala 	/*
394000a3eaf3SRamaswamy Tummala 	 * Get the Client dev_info from the pathinfo.
394100a3eaf3SRamaswamy Tummala 	 */
394200a3eaf3SRamaswamy Tummala 	cdip = mdi_pi_get_client(pip);
394300a3eaf3SRamaswamy Tummala 	if (cdip == NULL)
394400a3eaf3SRamaswamy Tummala 		return (MDI_FAILURE);
394500a3eaf3SRamaswamy Tummala 
394600a3eaf3SRamaswamy Tummala 	/*
394700a3eaf3SRamaswamy Tummala 	 * How many PIs do we have from this cdip ?
394800a3eaf3SRamaswamy Tummala 	 */
394900a3eaf3SRamaswamy Tummala 	clnt_num_pi = mdi_client_get_path_count(cdip);
395000a3eaf3SRamaswamy Tummala 
395100a3eaf3SRamaswamy Tummala 	/*
395200a3eaf3SRamaswamy Tummala 	 * If this is the last PI that is being free'd ( called from
395300a3eaf3SRamaswamy Tummala 	 * mdi_pi_free) we have to clean up the node data for the cdip since
395400a3eaf3SRamaswamy Tummala 	 * the client would have been detached by mdi_devi_offline.
395500a3eaf3SRamaswamy Tummala 	 */
395600a3eaf3SRamaswamy Tummala 	if (clnt_num_pi == 1) {
39571cfa752fSRamaswamy Tummala 		node_data = ddi_get_parent_data(cdip);
39581cfa752fSRamaswamy Tummala 		if (node_data == NULL)
39591cfa752fSRamaswamy Tummala 			return (MDI_SUCCESS);
396000a3eaf3SRamaswamy Tummala 		if (node_data->node_dip == cdip) {
396100a3eaf3SRamaswamy Tummala 			node_data->node_dip = NULL;
39621cfa752fSRamaswamy Tummala 			node_data->node_state = IBNEX_CFGADM_UNCONFIGURED;
396300a3eaf3SRamaswamy Tummala 			return (MDI_SUCCESS);
396400a3eaf3SRamaswamy Tummala 		}
396500a3eaf3SRamaswamy Tummala 	}
39667c478bd9Sstevel@tonic-gate 	return (MDI_SUCCESS);
39677c478bd9Sstevel@tonic-gate }
39687c478bd9Sstevel@tonic-gate 
39697c478bd9Sstevel@tonic-gate 
39707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39717c478bd9Sstevel@tonic-gate static int
397200a3eaf3SRamaswamy Tummala ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip,
39737c478bd9Sstevel@tonic-gate 		mdi_pathinfo_state_t state, uint32_t arg1, int arg2)
39747c478bd9Sstevel@tonic-gate {
39757c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
397600a3eaf3SRamaswamy Tummala 	    "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state);
39777c478bd9Sstevel@tonic-gate 	return (MDI_SUCCESS);
39787c478bd9Sstevel@tonic-gate }
39797c478bd9Sstevel@tonic-gate 
39807c478bd9Sstevel@tonic-gate 
39817c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39827c478bd9Sstevel@tonic-gate static int
39837c478bd9Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg)
39847c478bd9Sstevel@tonic-gate {
39857c478bd9Sstevel@tonic-gate 	return (MDI_SUCCESS);
39867c478bd9Sstevel@tonic-gate }
39877c478bd9Sstevel@tonic-gate 
39887c478bd9Sstevel@tonic-gate 
39897c478bd9Sstevel@tonic-gate static int
39907c478bd9Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg,
39917c478bd9Sstevel@tonic-gate     pm_bus_power_op_t op, void *arg, void *result)
39927c478bd9Sstevel@tonic-gate {
39937c478bd9Sstevel@tonic-gate 
39947c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
39957c478bd9Sstevel@tonic-gate 
39967c478bd9Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op);
39977c478bd9Sstevel@tonic-gate 
39987c478bd9Sstevel@tonic-gate 	/*
39997c478bd9Sstevel@tonic-gate 	 * Generic processing in MPxIO framework
40007c478bd9Sstevel@tonic-gate 	 */
40017c478bd9Sstevel@tonic-gate 	ret = mdi_bus_power(parent, impl_arg, op, arg, result);
40027c478bd9Sstevel@tonic-gate 
40037c478bd9Sstevel@tonic-gate 	switch (ret) {
40047c478bd9Sstevel@tonic-gate 	case MDI_SUCCESS:
40057c478bd9Sstevel@tonic-gate 		ret = DDI_SUCCESS;
40067c478bd9Sstevel@tonic-gate 		break;
40077c478bd9Sstevel@tonic-gate 	case MDI_FAILURE:
40087c478bd9Sstevel@tonic-gate 		ret = DDI_FAILURE;
40097c478bd9Sstevel@tonic-gate 		break;
40107c478bd9Sstevel@tonic-gate 	default:
40117c478bd9Sstevel@tonic-gate 		break;
40127c478bd9Sstevel@tonic-gate 	}
40137c478bd9Sstevel@tonic-gate 
40147c478bd9Sstevel@tonic-gate 	return (ret);
40157c478bd9Sstevel@tonic-gate }
40169d3d2ed0Shiremath 
40179d3d2ed0Shiremath 
40189d3d2ed0Shiremath /*
40199d3d2ed0Shiremath  * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config.
40209d3d2ed0Shiremath  * ndi_devi_enter is not held during this call. mdi_vhci_bus_config()
40219d3d2ed0Shiremath  * will have called ndi_busop_bus_config(), no need for the caller to call
40229d3d2ed0Shiremath  * ndi_busop_bus_config() again.
40239d3d2ed0Shiremath  *
40249d3d2ed0Shiremath  * If enumerated as a child of HCA device, this could be a case for
40259d3d2ed0Shiremath  * Sparc boot or device enumeration from PHCI, driven by MDI.
40269d3d2ed0Shiremath  * Hold parent lock (ndi_devi_enter). The caller will have to call
40279d3d2ed0Shiremath  * ndi_busop_bus_config() if this function returns SUCCESS.
40289d3d2ed0Shiremath  *
40299d3d2ed0Shiremath  * if the device name contains ":port", then it is the Sparc boot case.
40309d3d2ed0Shiremath  * Handle this as before.
40319d3d2ed0Shiremath  *
40329d3d2ed0Shiremath  * If the device name does *not* contain the ":port", then :
40339d3d2ed0Shiremath  *	1. ibdm to probe IOC
40349d3d2ed0Shiremath  *	2. Create a pathinfo only if the IOC is reachable from the parent dip.
40359d3d2ed0Shiremath  */
40361cfa752fSRamaswamy Tummala int
40379d3d2ed0Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag,
40389d3d2ed0Shiremath     ddi_bus_config_op_t op, void *devname, dev_info_t **child,
40399d3d2ed0Shiremath     int *need_bus_config)
40409d3d2ed0Shiremath {
40419d3d2ed0Shiremath 	int ret = DDI_FAILURE, circ;
40429d3d2ed0Shiremath 	dev_info_t *pdip = *pdipp;
40439d3d2ed0Shiremath 	ib_guid_t	iou_guid, ioc_guid;
40449d3d2ed0Shiremath 	char *ioc_guid_str;
40459d3d2ed0Shiremath 
40469d3d2ed0Shiremath 
40479d3d2ed0Shiremath 	*need_bus_config = 1;
40489d3d2ed0Shiremath 
40499d3d2ed0Shiremath 	if (pdip == ibnex.ibnex_dip) {
40509d3d2ed0Shiremath 		if (ibnex_devname_to_node_n_ioc_guids(
40519d3d2ed0Shiremath 		    (char *)devname, &iou_guid, &ioc_guid,
40529d3d2ed0Shiremath 		    &ioc_guid_str) != IBNEX_SUCCESS) {
40539d3d2ed0Shiremath 			return (ret);
40549d3d2ed0Shiremath 		}
40559d3d2ed0Shiremath 		ret = mdi_vhci_bus_config(pdip, flag, op, devname, child,
40569d3d2ed0Shiremath 		    ioc_guid_str);
40579d3d2ed0Shiremath 		kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1);
40589d3d2ed0Shiremath 		if (ret == MDI_SUCCESS)
40599d3d2ed0Shiremath 			*need_bus_config = 0;
40609d3d2ed0Shiremath 	} else {
40615e3986cbScth 		mdi_devi_enter(pdip, &circ);
40629d3d2ed0Shiremath 		if (strstr((char *)devname, ":port=") != NULL) {
40639d3d2ed0Shiremath 			ret = ibnex_config_root_iocnode(pdip, devname);
40649d3d2ed0Shiremath 			ASSERT(ibnex.ibnex_dip == NULL);
40659d3d2ed0Shiremath 			*pdipp = ibnex.ibnex_dip;
40669d3d2ed0Shiremath 		} else {
40679d3d2ed0Shiremath 			ret = ibnex_config_ioc_node(devname, pdip);
40689d3d2ed0Shiremath 		}
40695e3986cbScth 		mdi_devi_exit(pdip, circ);
40709d3d2ed0Shiremath 	}
40719d3d2ed0Shiremath 	return (ret);
40729d3d2ed0Shiremath }
40739d3d2ed0Shiremath 
40749d3d2ed0Shiremath static int
40759d3d2ed0Shiremath ibnex_is_merge_node(dev_info_t *child)
40769d3d2ed0Shiremath {
40779d3d2ed0Shiremath 	char	*node;
40789d3d2ed0Shiremath 	int	ret = IBNEX_INVALID_NODE;
40799d3d2ed0Shiremath 
40809d3d2ed0Shiremath 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child,
40819d3d2ed0Shiremath 	    DDI_PROP_DONTPASS, "ib-node-type", &node) !=
40829d3d2ed0Shiremath 	    DDI_PROP_SUCCESS) {
40839d3d2ed0Shiremath 		return (IBNEX_FAILURE);
40849d3d2ed0Shiremath 	}
40859d3d2ed0Shiremath 
40869d3d2ed0Shiremath 	if (node != NULL && *node != 0) {
40879d3d2ed0Shiremath 		if (strcmp(node, "merge") == 0)
40889d3d2ed0Shiremath 			ret = IBNEX_SUCCESS;
40899d3d2ed0Shiremath 		else {
40909d3d2ed0Shiremath 			IBTF_DPRINTF_L4("ibnex",
40919d3d2ed0Shiremath 			    "\tis_merge_node: ib-node-type = %s", node);
40929d3d2ed0Shiremath 		}
40939d3d2ed0Shiremath 	}
40949d3d2ed0Shiremath 
40959d3d2ed0Shiremath 	ddi_prop_free(node);
40969d3d2ed0Shiremath 	return (ret);
40979d3d2ed0Shiremath }
40989d3d2ed0Shiremath 
40999d3d2ed0Shiremath /*
41009d3d2ed0Shiremath  * Checks if the dn_head for the driver has already
41019d3d2ed0Shiremath  * initialized by the prom tree.
41029d3d2ed0Shiremath  */
4103f7209cf2Spramodbg void
41049d3d2ed0Shiremath ibnex_hw_in_dev_tree(char *driver_name)
41059d3d2ed0Shiremath {
41069d3d2ed0Shiremath 	major_t	major;
41079d3d2ed0Shiremath 
4108f7209cf2Spramodbg 	IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name);
4109f7209cf2Spramodbg 
41109d3d2ed0Shiremath 	if (devnamesp == NULL)
4111f7209cf2Spramodbg 		return;
41129d3d2ed0Shiremath 
41139d3d2ed0Shiremath 	major = ddi_name_to_major(driver_name);
41149d3d2ed0Shiremath 	if (major == -1)
4115f7209cf2Spramodbg 		return;
41169d3d2ed0Shiremath 
4117f7209cf2Spramodbg 	if (devnamesp[major].dn_head != (dev_info_t *)NULL)
4118f7209cf2Spramodbg 		ibnex_hw_status = IBNEX_HW_IN_DEVTREE;
41199d3d2ed0Shiremath }
412000a3eaf3SRamaswamy Tummala 
412100a3eaf3SRamaswamy Tummala int
412200a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info)
412300a3eaf3SRamaswamy Tummala {
412400a3eaf3SRamaswamy Tummala 	ibdm_hca_list_t	*hca_list;
412500a3eaf3SRamaswamy Tummala 	dev_info_t	*hca_dip;
412600a3eaf3SRamaswamy Tummala 	int	rc = IBNEX_FAILURE;
412700a3eaf3SRamaswamy Tummala 
412800a3eaf3SRamaswamy Tummala 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
412900a3eaf3SRamaswamy Tummala 	/*
413000a3eaf3SRamaswamy Tummala 	 * We return failure even if we fail for all HCAs
413100a3eaf3SRamaswamy Tummala 	 */
413200a3eaf3SRamaswamy Tummala 	for (hca_list = ioc_info->ioc_hca_list; hca_list;
413300a3eaf3SRamaswamy Tummala 	    hca_list = hca_list->hl_next) {
413400a3eaf3SRamaswamy Tummala 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
413500a3eaf3SRamaswamy Tummala 		if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) ==
413600a3eaf3SRamaswamy Tummala 		    IBNEX_SUCCESS)
413700a3eaf3SRamaswamy Tummala 			rc = IBNEX_SUCCESS;
413800a3eaf3SRamaswamy Tummala 	}
413900a3eaf3SRamaswamy Tummala 	return (rc);
414000a3eaf3SRamaswamy Tummala }
414100a3eaf3SRamaswamy Tummala 
414200a3eaf3SRamaswamy Tummala static int
414300a3eaf3SRamaswamy Tummala ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip,
414400a3eaf3SRamaswamy Tummala     int pdip_reachable_checked)
414500a3eaf3SRamaswamy Tummala {
414600a3eaf3SRamaswamy Tummala 	ibnex_node_data_t	*node_data;
414700a3eaf3SRamaswamy Tummala 	int			create_pdip = 0;
414800a3eaf3SRamaswamy Tummala 	int			rc = IBNEX_SUCCESS;
414900a3eaf3SRamaswamy Tummala 
415000a3eaf3SRamaswamy Tummala 
415100a3eaf3SRamaswamy Tummala 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
415200a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex",
415300a3eaf3SRamaswamy Tummala 	    "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip,
415400a3eaf3SRamaswamy Tummala 	    pdip_reachable_checked);
415500a3eaf3SRamaswamy Tummala 
415600a3eaf3SRamaswamy Tummala 	if (pdip_reachable_checked == 0) {
415700a3eaf3SRamaswamy Tummala 		if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) {
415800a3eaf3SRamaswamy Tummala 			IBTF_DPRINTF_L4("ibnex",
415900a3eaf3SRamaswamy Tummala 			    "/tioc_config_from_pdip: ioc %p not reachable"
416000a3eaf3SRamaswamy Tummala 			    "from %p", ioc_info, pdip);
416100a3eaf3SRamaswamy Tummala 			return (IBNEX_FAILURE);
416200a3eaf3SRamaswamy Tummala 		}
416300a3eaf3SRamaswamy Tummala 	}
416400a3eaf3SRamaswamy Tummala 
416500a3eaf3SRamaswamy Tummala 	node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
416600a3eaf3SRamaswamy Tummala 	    (void *)ioc_info, 0, 0);
416700a3eaf3SRamaswamy Tummala 
416800a3eaf3SRamaswamy Tummala 	if (node_data && node_data->node_ap_state ==
416900a3eaf3SRamaswamy Tummala 	    IBNEX_NODE_AP_UNCONFIGURED) {
417000a3eaf3SRamaswamy Tummala 		IBTF_DPRINTF_L4("ibnex",
417100a3eaf3SRamaswamy Tummala 		    "\tioc_config_from_pdip: Unconfigured node");
417200a3eaf3SRamaswamy Tummala 		return (IBNEX_FAILURE);
417300a3eaf3SRamaswamy Tummala 	}
417400a3eaf3SRamaswamy Tummala 
417500a3eaf3SRamaswamy Tummala 
417600a3eaf3SRamaswamy Tummala 	if (node_data == NULL) {
417700a3eaf3SRamaswamy Tummala 		ibnex_ioc_node_t	*ioc;
417800a3eaf3SRamaswamy Tummala 
417900a3eaf3SRamaswamy Tummala 		create_pdip = 1;
418000a3eaf3SRamaswamy Tummala 
418100a3eaf3SRamaswamy Tummala 		node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE,
418200a3eaf3SRamaswamy Tummala 		    ioc_info, 0, 0);
418300a3eaf3SRamaswamy Tummala 		ASSERT(node_data);
418400a3eaf3SRamaswamy Tummala 		ioc = &node_data->node_data.ioc_node;
418500a3eaf3SRamaswamy Tummala 		(void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN,
418600a3eaf3SRamaswamy Tummala 		    "%llX",
418700a3eaf3SRamaswamy Tummala 		    (longlong_t)ioc_info->ioc_profile.ioc_guid);
418800a3eaf3SRamaswamy Tummala 		(void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN,
418900a3eaf3SRamaswamy Tummala 		    "%llX,%llX",
419000a3eaf3SRamaswamy Tummala 		    (longlong_t)ioc_info->ioc_profile.ioc_guid,
419100a3eaf3SRamaswamy Tummala 		    (longlong_t)ioc_info->ioc_iou_guid);
419200a3eaf3SRamaswamy Tummala 	} else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) {
419300a3eaf3SRamaswamy Tummala 		create_pdip = 1;
419400a3eaf3SRamaswamy Tummala 	}
419500a3eaf3SRamaswamy Tummala 
419600a3eaf3SRamaswamy Tummala 	if (create_pdip) {
419700a3eaf3SRamaswamy Tummala 		rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip);
419800a3eaf3SRamaswamy Tummala 	}
419900a3eaf3SRamaswamy Tummala 
420000a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x",
420100a3eaf3SRamaswamy Tummala 	    rc);
420200a3eaf3SRamaswamy Tummala 	return (rc);
420300a3eaf3SRamaswamy Tummala }
420400a3eaf3SRamaswamy Tummala 
420500a3eaf3SRamaswamy Tummala /*
420600a3eaf3SRamaswamy Tummala  * This function checks if a pathinfo has already been created
420700a3eaf3SRamaswamy Tummala  * for the HCA parent. The function returns SUCCESS if a pathinfo
420800a3eaf3SRamaswamy Tummala  * has already been created, FAILURE if not.
420900a3eaf3SRamaswamy Tummala  */
421000a3eaf3SRamaswamy Tummala static int
421100a3eaf3SRamaswamy Tummala ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent)
421200a3eaf3SRamaswamy Tummala {
421300a3eaf3SRamaswamy Tummala 	int	rc;
421400a3eaf3SRamaswamy Tummala 	ibnex_ioc_node_t	*ioc;
421500a3eaf3SRamaswamy Tummala 
421600a3eaf3SRamaswamy Tummala 	ioc = &node_data->node_data.ioc_node;
421700a3eaf3SRamaswamy Tummala 	if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str,
421800a3eaf3SRamaswamy Tummala 	    (char *)ioc->ioc_phci_guid) != NULL)
421900a3eaf3SRamaswamy Tummala 		rc = IBNEX_SUCCESS;
422000a3eaf3SRamaswamy Tummala 	else
422100a3eaf3SRamaswamy Tummala 		rc = IBNEX_FAILURE;
422200a3eaf3SRamaswamy Tummala 
422300a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, "
422400a3eaf3SRamaswamy Tummala 	    "phci_guid %s, parent %p, rc %x",
422500a3eaf3SRamaswamy Tummala 	    ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc);
422600a3eaf3SRamaswamy Tummala 	return (rc);
422700a3eaf3SRamaswamy Tummala }
422800a3eaf3SRamaswamy Tummala 
422900a3eaf3SRamaswamy Tummala static int
423000a3eaf3SRamaswamy Tummala ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
423100a3eaf3SRamaswamy Tummala {
423200a3eaf3SRamaswamy Tummala 	ibdm_hca_list_t	*hca_list;
423300a3eaf3SRamaswamy Tummala 	dev_info_t	*hca_dip;
423400a3eaf3SRamaswamy Tummala 
423500a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)",
423600a3eaf3SRamaswamy Tummala 	    ioc_info, pdip);
423700a3eaf3SRamaswamy Tummala 	for (hca_list = ioc_info->ioc_hca_list; hca_list;
423800a3eaf3SRamaswamy Tummala 	    hca_list = hca_list->hl_next) {
423900a3eaf3SRamaswamy Tummala 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
424000a3eaf3SRamaswamy Tummala 		if (hca_dip == pdip) {
424100a3eaf3SRamaswamy Tummala 			IBTF_DPRINTF_L4("ibnex",
424200a3eaf3SRamaswamy Tummala 			    "\tioc_pi_reachable FAILURE");
424300a3eaf3SRamaswamy Tummala 			return (IBNEX_SUCCESS);
424400a3eaf3SRamaswamy Tummala 		}
424500a3eaf3SRamaswamy Tummala 	}
424600a3eaf3SRamaswamy Tummala 
424700a3eaf3SRamaswamy Tummala 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE");
424800a3eaf3SRamaswamy Tummala 	return (IBNEX_FAILURE);
424900a3eaf3SRamaswamy Tummala }
4250