xref: /onnv-gate/usr/src/uts/common/io/ib/ibnex/ibnex.c (revision 8082:f52c9d98dc8c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51689Spramodbg  * Common Development and Distribution License (the "License").
61689Spramodbg  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
226601Seota  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * The InfiniBand  Nexus driver (IB nexus) is a bus nexus driver for IB bus.
280Sstevel@tonic-gate  * It supports  Port nodes, Virtual Physical Point of Attachment nodes (VPPA)
290Sstevel@tonic-gate  * for  HCAs registered with IBTL and IOC nodes for all the IOCs present in
300Sstevel@tonic-gate  * the IB fabric (that are accessible to the host). It also supports Pseudo
310Sstevel@tonic-gate  * device children to be enumerated using their .conf file(s). All Port nodes
320Sstevel@tonic-gate  * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo
330Sstevel@tonic-gate  * device nodes are children of the IB nexus driver.
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * IB nexus driver provides bus nexus entry points to all the HCA drivers.
360Sstevel@tonic-gate  *
370Sstevel@tonic-gate  * IB nexus  driver registers with  InfiniBand Device  Manager (IBDM) to get
380Sstevel@tonic-gate  * information about all the HCA ports and  I/O Controllers (IOCs) connected
390Sstevel@tonic-gate  * to the IB fabric. Based on that information, IB nexus will create all the
400Sstevel@tonic-gate  * device tree nodes.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <sys/conf.h>
440Sstevel@tonic-gate #include <sys/stat.h>
450Sstevel@tonic-gate #include <sys/modctl.h>
460Sstevel@tonic-gate #include <sys/taskq.h>
470Sstevel@tonic-gate #include <sys/mdi_impldefs.h>
480Sstevel@tonic-gate #include <sys/sunmdi.h>
490Sstevel@tonic-gate #include <sys/sunpm.h>
500Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h>
510Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h>
520Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h>
530Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h>
540Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h>
550Sstevel@tonic-gate #include <sys/file.h>
560Sstevel@tonic-gate #include <sys/hwconf.h>
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* Function prototypes */
590Sstevel@tonic-gate static int		ibnex_attach(dev_info_t *, ddi_attach_cmd_t);
600Sstevel@tonic-gate static int		ibnex_getinfo(dev_info_t *, ddi_info_cmd_t,
610Sstevel@tonic-gate 			    void *, void **);
620Sstevel@tonic-gate static int		ibnex_detach(dev_info_t *, ddi_detach_cmd_t);
630Sstevel@tonic-gate static int		ibnex_busctl(dev_info_t *,
640Sstevel@tonic-gate 			    dev_info_t *, ddi_ctl_enum_t, void *, void *);
650Sstevel@tonic-gate static int		ibnex_map_fault(dev_info_t *,
660Sstevel@tonic-gate 			    dev_info_t *, struct hat *, struct seg *,
670Sstevel@tonic-gate 			    caddr_t, struct devpage *, pfn_t, uint_t, uint_t);
680Sstevel@tonic-gate static int		ibnex_init_child(dev_info_t *);
690Sstevel@tonic-gate static ibnex_rval_t	ibnex_comm_svc_init(char *, ibnex_node_type_t);
700Sstevel@tonic-gate static void		ibnex_comm_svc_fini();
710Sstevel@tonic-gate dev_info_t		*ibnex_commsvc_initnode(dev_info_t *,
720Sstevel@tonic-gate 			    ibdm_port_attr_t *, int, int, ib_pkey_t, int *,
730Sstevel@tonic-gate 			    int);
740Sstevel@tonic-gate static void		ibnex_delete_port_node_data(ibnex_node_data_t *);
750Sstevel@tonic-gate int			ibnex_get_dip_from_guid(ib_guid_t, int,
760Sstevel@tonic-gate 			    ib_pkey_t, dev_info_t **);
770Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t,
780Sstevel@tonic-gate 			    void *, int, ib_pkey_t);
790Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *,
800Sstevel@tonic-gate 			    int, ib_pkey_t);
810Sstevel@tonic-gate static int		ibnex_create_port_node_prop(ibdm_port_attr_t *,
820Sstevel@tonic-gate 			    dev_info_t *, char *, ib_pkey_t);
830Sstevel@tonic-gate void			ibnex_dm_callback(void *, ibdm_events_t);
840Sstevel@tonic-gate static int		ibnex_create_port_compatible_prop(dev_info_t *,
850Sstevel@tonic-gate 			    char *, ibdm_port_attr_t *);
860Sstevel@tonic-gate static int		ibnex_create_ioc_srv_props(
870Sstevel@tonic-gate 			    dev_info_t *, ibdm_ioc_info_t *);
880Sstevel@tonic-gate static int		ibnex_get_eventcookie(dev_info_t *,
890Sstevel@tonic-gate 			    dev_info_t *, char *, ddi_eventcookie_t *);
900Sstevel@tonic-gate static int		ibnex_add_eventcall(dev_info_t *, dev_info_t *,
910Sstevel@tonic-gate 			    ddi_eventcookie_t, void (*)(dev_info_t *,
920Sstevel@tonic-gate 			    ddi_eventcookie_t, void *, void *),
930Sstevel@tonic-gate 			    void *arg, ddi_callback_id_t *cb_id);
940Sstevel@tonic-gate static int		ibnex_remove_eventcall(dev_info_t *,
950Sstevel@tonic-gate 			    ddi_callback_id_t);
960Sstevel@tonic-gate static int		ibnex_post_event(dev_info_t *, dev_info_t *,
970Sstevel@tonic-gate 			    ddi_eventcookie_t, void *);
980Sstevel@tonic-gate static int		ibnex_bus_config(dev_info_t *, uint_t,
990Sstevel@tonic-gate 			    ddi_bus_config_op_t, void *, dev_info_t **);
1000Sstevel@tonic-gate static int		ibnex_bus_unconfig(dev_info_t *,
1010Sstevel@tonic-gate 			    uint_t, ddi_bus_config_op_t, void *);
1020Sstevel@tonic-gate static dev_info_t	*ibnex_config_port_node(dev_info_t *, char *);
1030Sstevel@tonic-gate static dev_info_t	*ibnex_config_obp_args(dev_info_t *, char *);
1040Sstevel@tonic-gate static int		ibnex_get_pkey_commsvc_index_portnum(
1050Sstevel@tonic-gate 			    char *, int *, ib_pkey_t *, uint8_t *);
1060Sstevel@tonic-gate static void		ibnex_config_all_children(dev_info_t *);
1070Sstevel@tonic-gate static int		ibnex_devname_to_portnum(char *, uint8_t *);
1080Sstevel@tonic-gate static void		ibnex_create_vppa_nodes(
1090Sstevel@tonic-gate 			    dev_info_t *, ibdm_port_attr_t *);
1100Sstevel@tonic-gate static void		ibnex_create_port_nodes(
1110Sstevel@tonic-gate 			    dev_info_t *, ibdm_port_attr_t *);
1120Sstevel@tonic-gate static void		ibnex_create_hcasvc_nodes(
1130Sstevel@tonic-gate 			    dev_info_t *, ibdm_port_attr_t *);
1140Sstevel@tonic-gate static int		ibnex_config_root_iocnode(dev_info_t *, char *);
1150Sstevel@tonic-gate static int		ibnex_devname2port(char *, int *);
1161093Shiremath static int		ibnex_config_ioc_node(char *, dev_info_t *);
1170Sstevel@tonic-gate static int		ibnex_devname_to_node_n_ioc_guids(
1181093Shiremath 			    char *, ib_guid_t *, ib_guid_t *, char **);
1190Sstevel@tonic-gate static void		ibnex_ioc_node_cleanup();
1200Sstevel@tonic-gate static void		ibnex_delete_ioc_node_data(ibnex_node_data_t *);
121*8082SRamaswamy.Tummala@Sun.COM int			ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *);
122*8082SRamaswamy.Tummala@Sun.COM static int		ibnex_ioc_initnode_pdip(ibnex_node_data_t *,
123*8082SRamaswamy.Tummala@Sun.COM 			    ibdm_ioc_info_t *, dev_info_t *);
1240Sstevel@tonic-gate static int		ibnex_create_ioc_node_prop(
1250Sstevel@tonic-gate 			    ibdm_ioc_info_t *, dev_info_t *);
1260Sstevel@tonic-gate static int		ibnex_create_ioc_compatible_prop(
1270Sstevel@tonic-gate 			    dev_info_t *, ib_dm_ioc_ctrl_profile_t *);
1280Sstevel@tonic-gate uint64_t		ibnex_str2hex(char *, int, int *);
1290Sstevel@tonic-gate static int		ibnex_str2int(char *, int, int *);
1300Sstevel@tonic-gate static int		ibnex_create_ioc_portgid_prop(
1310Sstevel@tonic-gate 			    dev_info_t *, ibdm_ioc_info_t *);
1320Sstevel@tonic-gate static void		ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int);
1330Sstevel@tonic-gate static void		ibnex_wakeup_reprobe_all();
1340Sstevel@tonic-gate ibt_status_t		ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *);
1350Sstevel@tonic-gate static int		ibnex_prom_devname_to_pkey_n_portnum(
1360Sstevel@tonic-gate 			    char *, ib_pkey_t *, uint8_t *);
1370Sstevel@tonic-gate void			ibnex_pseudo_initnodes(void);
1381093Shiremath static char		*ibnex_lookup_named_prop(ddi_prop_t *, char *);
1390Sstevel@tonic-gate static void		ibnex_pseudo_node_cleanup(void);
1400Sstevel@tonic-gate static int		ibnex_name_child(dev_info_t *, char *, int);
1410Sstevel@tonic-gate static int		ibnex_name_pseudo_child(dev_info_t *, char *);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate void			ibnex_reprobe_ioc_dev(void *);
1440Sstevel@tonic-gate void			ibnex_reprobe_ioc_all();
1450Sstevel@tonic-gate static void		ibnex_update_prop(ibnex_node_data_t *,
1460Sstevel@tonic-gate 			    ibdm_ioc_info_t *);
1470Sstevel@tonic-gate static ibnex_rval_t	ibnex_unique_svcname(char *);
1480Sstevel@tonic-gate static void		ibnex_handle_reprobe_dev(void *arg);
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate extern int		ibnex_open(dev_t *, int, int, cred_t *);
1510Sstevel@tonic-gate extern int		ibnex_close(dev_t, int, int, cred_t *);
1520Sstevel@tonic-gate extern int		ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
1530Sstevel@tonic-gate extern int		ibnex_offline_childdip(dev_info_t *);
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate static int		ibnex_ioc_create_pi(
1561093Shiremath 			    ibdm_ioc_info_t *, ibnex_node_data_t *,
157*8082SRamaswamy.Tummala@Sun.COM 			    dev_info_t *, int *);
1580Sstevel@tonic-gate static int		ibnex_bus_power(dev_info_t *, void *,
1590Sstevel@tonic-gate 			    pm_bus_power_op_t, void *, void *);
160*8082SRamaswamy.Tummala@Sun.COM int			ibnex_pseudo_create_all_pi(ibnex_node_data_t *);
161*8082SRamaswamy.Tummala@Sun.COM static int		ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *,
1621093Shiremath 			    dev_info_t *);
1631689Spramodbg static int		ibnex_pseudo_config_one(
1641689Spramodbg 			    ibnex_node_data_t *, char *, dev_info_t *);
1651093Shiremath static int		ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **,
1661093Shiremath 			    char *, char *);
1671093Shiremath static void		ibnex_config_pseudo_all(dev_info_t *);
1681093Shiremath static int		ibnex_ioc_bus_config_one(dev_info_t **, uint_t,
1691093Shiremath 			    ddi_bus_config_op_t, void *, dev_info_t **, int *);
1701093Shiremath static int		ibnex_is_merge_node(dev_info_t *);
1712402Spramodbg static void		ibnex_hw_in_dev_tree(char *);
172*8082SRamaswamy.Tummala@Sun.COM static int		ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *,
173*8082SRamaswamy.Tummala@Sun.COM     dev_info_t *, int);
174*8082SRamaswamy.Tummala@Sun.COM static int		ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *);
175*8082SRamaswamy.Tummala@Sun.COM static int		ibnex_ioc_pi_reachable(ibdm_ioc_info_t *,
176*8082SRamaswamy.Tummala@Sun.COM     dev_info_t *);
1771093Shiremath 
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate  * The bus_ops structure defines the capabilities of HCA nexus driver.
1800Sstevel@tonic-gate  */
1810Sstevel@tonic-gate struct bus_ops ibnex_ci_busops = {
1820Sstevel@tonic-gate 	BUSO_REV,
1830Sstevel@tonic-gate 	nullbusmap,		/* bus_map */
1840Sstevel@tonic-gate 	NULL,			/* bus_get_intrspec */
1850Sstevel@tonic-gate 	NULL,			/* bus_add_intrspec */
1860Sstevel@tonic-gate 	NULL,			/* bus_remove_intrspec */
1870Sstevel@tonic-gate 	ibnex_map_fault,	/* Map Fault */
1880Sstevel@tonic-gate 	ddi_no_dma_map,		/* DMA related entry points */
1890Sstevel@tonic-gate 	NULL,
1900Sstevel@tonic-gate 	NULL,
1910Sstevel@tonic-gate 	NULL,
1920Sstevel@tonic-gate 	NULL,
1930Sstevel@tonic-gate 	NULL,
1940Sstevel@tonic-gate 	NULL,
1950Sstevel@tonic-gate 	NULL,
1960Sstevel@tonic-gate 	ibnex_busctl,		/* bus_ctl */
1970Sstevel@tonic-gate 	ddi_bus_prop_op,	/* bus_prop_op */
1980Sstevel@tonic-gate 	NULL,			/* bus_get_eventcookie	*/
1990Sstevel@tonic-gate 	NULL,			/* bus_add_eventcall	*/
2000Sstevel@tonic-gate 	NULL,			/* bus_remove_eventcall	*/
2010Sstevel@tonic-gate 	NULL,			/* bus_post_event	*/
2020Sstevel@tonic-gate 	NULL,
2030Sstevel@tonic-gate 	ibnex_bus_config,	/* bus config */
2040Sstevel@tonic-gate 	ibnex_bus_unconfig	/* bus unconfig */
2050Sstevel@tonic-gate };
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate /*
2080Sstevel@tonic-gate  * Prototype declarations for the VHCI options
2090Sstevel@tonic-gate  */
2100Sstevel@tonic-gate /*
2110Sstevel@tonic-gate  * Functions registered with the mpxio framework
2120Sstevel@tonic-gate  */
2130Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int);
2140Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int);
2150Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *,
2160Sstevel@tonic-gate 		mdi_pathinfo_state_t, uint32_t, int);
2170Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = {
2210Sstevel@tonic-gate 	MDI_VHCI_OPS_REV,
2220Sstevel@tonic-gate 	ib_vhci_pi_init,
2230Sstevel@tonic-gate 	ib_vhci_pi_uninit,
2240Sstevel@tonic-gate 	ib_vhci_pi_state_change,
2250Sstevel@tonic-gate 	ib_vhci_failover
2260Sstevel@tonic-gate };
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate  * The  bus_ops  structure  defines the  capabilities  of IB nexus driver.
2310Sstevel@tonic-gate  * IB nexus drivers does not  support any DMA  operations for its children
2320Sstevel@tonic-gate  * as there is  no  such concept in Infiniband.  All the memory operations
2330Sstevel@tonic-gate  * and DMA operations required by the child drivers can be performed using
2340Sstevel@tonic-gate  * the IBTF API.
2350Sstevel@tonic-gate  */
2360Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = {
2370Sstevel@tonic-gate 	BUSO_REV,
2380Sstevel@tonic-gate 	nullbusmap,		/* bus_map */
2390Sstevel@tonic-gate 	NULL,			/* bus_get_intrspec */
2400Sstevel@tonic-gate 	NULL,			/* bus_add_intrspec */
2410Sstevel@tonic-gate 	NULL,			/* bus_remove_intrspec */
2420Sstevel@tonic-gate 	ibnex_map_fault,	/* Map Fault */
2430Sstevel@tonic-gate 	ddi_no_dma_map,		/* DMA related entry points */
2440Sstevel@tonic-gate 	ddi_no_dma_allochdl,
2450Sstevel@tonic-gate 	NULL,
2460Sstevel@tonic-gate 	NULL,
2470Sstevel@tonic-gate 	NULL,
2480Sstevel@tonic-gate 	NULL,
2490Sstevel@tonic-gate 	NULL,
2500Sstevel@tonic-gate 	NULL,
2510Sstevel@tonic-gate 	ibnex_busctl,		/* bus_ctl */
2520Sstevel@tonic-gate 	ddi_bus_prop_op,	/* bus_prop_op */
2530Sstevel@tonic-gate 	ibnex_get_eventcookie,	/* bus_get_eventcookie	*/
2540Sstevel@tonic-gate 	ibnex_add_eventcall,	/* bus_add_eventcall	*/
2550Sstevel@tonic-gate 	ibnex_remove_eventcall,	/* bus_remove_eventcall	*/
2560Sstevel@tonic-gate 	ibnex_post_event,		/* bus_post_event	*/
2570Sstevel@tonic-gate 	NULL,
2580Sstevel@tonic-gate 	ibnex_bus_config,	/* bus config */
2590Sstevel@tonic-gate 	ibnex_bus_unconfig,	/* bus unconfig */
2600Sstevel@tonic-gate 	NULL,			/* bus fm init */
2610Sstevel@tonic-gate 	NULL,			/* bus fm fini */
2620Sstevel@tonic-gate 	NULL,			/* bus fm access enter */
2630Sstevel@tonic-gate 	NULL,			/* bus fm access exit */
2640Sstevel@tonic-gate 	ibnex_bus_power		/* bus power */
2650Sstevel@tonic-gate };
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /* ibnex cb_ops */
2680Sstevel@tonic-gate static struct cb_ops ibnex_cbops = {
2690Sstevel@tonic-gate 	ibnex_open,		/* open */
2700Sstevel@tonic-gate 	ibnex_close,		/* close */
2710Sstevel@tonic-gate 	nodev,			/* strategy */
2720Sstevel@tonic-gate 	nodev,			/* print */
2730Sstevel@tonic-gate 	nodev,			/* dump */
2740Sstevel@tonic-gate 	nodev,			/* read */
2750Sstevel@tonic-gate 	nodev,			/* write */
2760Sstevel@tonic-gate 	ibnex_ioctl,		/* ioctl */
2770Sstevel@tonic-gate 	nodev,			/* devmap */
2780Sstevel@tonic-gate 	nodev,			/* mmap */
2790Sstevel@tonic-gate 	nodev,			/* segmap */
2800Sstevel@tonic-gate 	nochpoll,		/* poll */
2810Sstevel@tonic-gate 	ddi_prop_op,		/* prop_op */
2820Sstevel@tonic-gate 	NULL,			/* stream */
2830Sstevel@tonic-gate 	D_MP,			/* cb_flag */
2840Sstevel@tonic-gate 	CB_REV, 		/* rev */
2850Sstevel@tonic-gate 	nodev,			/* int (*cb_aread)() */
2860Sstevel@tonic-gate 	nodev			/* int (*cb_awrite)() */
2870Sstevel@tonic-gate };
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate  * Device options
2910Sstevel@tonic-gate  * Note: ddi_no_info needs to change during devfs time frame. The drivers
2920Sstevel@tonic-gate  *	 with 1 to 1 mapping between minor node and instance should use
2930Sstevel@tonic-gate  *	 ddi_1to1_info. (See bug id 4424752)
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate static struct dev_ops ibnex_ops = {
2960Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
2970Sstevel@tonic-gate 	0,			/* refcnt  */
2980Sstevel@tonic-gate 	ibnex_getinfo,		/* info */
2990Sstevel@tonic-gate 	nulldev,		/* identify */
3000Sstevel@tonic-gate 	nulldev,		/* probe */
3010Sstevel@tonic-gate 	ibnex_attach,		/* attach */
3020Sstevel@tonic-gate 	ibnex_detach,		/* detach */
3030Sstevel@tonic-gate 	nodev,			/* reset */
3040Sstevel@tonic-gate 	&ibnex_cbops,		/* driver ops - devctl interfaces */
3050Sstevel@tonic-gate 	&ibnex_bus_ops,		/* bus operations */
3067656SSherry.Moore@Sun.COM 	nulldev,		/* power */
3077656SSherry.Moore@Sun.COM 	ddi_quiesce_not_needed,		/* quiesce */
3080Sstevel@tonic-gate };
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate /* Module linkage information for the kernel.  */
3110Sstevel@tonic-gate static struct modldrv modldrv = {
3120Sstevel@tonic-gate 	&mod_driverops,		/* Driver module */
3137656SSherry.Moore@Sun.COM 	"IB nexus",		/* Driver name and version */
3140Sstevel@tonic-gate 	&ibnex_ops,		/* driver ops */
3150Sstevel@tonic-gate };
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate static struct modlinkage modlinkage = {
3180Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
3190Sstevel@tonic-gate };
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate /*
3220Sstevel@tonic-gate  * Global per-instance IB Nexus data.
3230Sstevel@tonic-gate  * There is only one instance of IB Nexus supported.
3240Sstevel@tonic-gate  */
3250Sstevel@tonic-gate ibnex_t ibnex;
3260Sstevel@tonic-gate #ifdef __lock_lint
3270Sstevel@tonic-gate extern ibdm_t ibdm;
3280Sstevel@tonic-gate #endif
3290Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s))
3300Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs
3310Sstevel@tonic-gate 	ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs
3320Sstevel@tonic-gate 	ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs
333*8082SRamaswamy.Tummala@Sun.COM 	ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list))
3340Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s))
3350Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex))
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate /* The port settling time in seconds */
338*8082SRamaswamy.Tummala@Sun.COM int	ibnex_port_settling_time = 30;
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */
3410Sstevel@tonic-gate static struct ibnex_property {
3420Sstevel@tonic-gate 	char			*name;
3430Sstevel@tonic-gate 	ibnex_node_type_t	type;
3440Sstevel@tonic-gate } ibnex_properties[]  = {
3450Sstevel@tonic-gate 	{ "port-svc-list",  IBNEX_PORT_COMMSVC_NODE},
3460Sstevel@tonic-gate 	{ "vppa-svc-list",  IBNEX_VPPA_COMMSVC_NODE},
3470Sstevel@tonic-gate 	{ "hca-svc-list",	IBNEX_HCASVC_COMMSVC_NODE}
3480Sstevel@tonic-gate };
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate #define	N_IBNEX_PROPS	(sizeof (ibnex_properties))/ \
3510Sstevel@tonic-gate 				(sizeof (struct ibnex_property))
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate /*
3540Sstevel@tonic-gate  * Event Definition
3550Sstevel@tonic-gate  *	Single event, event name defined in ibti_common.h.
3560Sstevel@tonic-gate  *	Event posted to specific child handler. Event posted
3570Sstevel@tonic-gate  *	at kernel priority.
3580Sstevel@tonic-gate  */
3590Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = {
3600Sstevel@tonic-gate 	{IB_EVENT_TAG_PROP_UPDATE,  IB_PROP_UPDATE_EVENT, EPL_KERNEL,
3610Sstevel@tonic-gate 		NDI_EVENT_POST_TO_TGT}
3620Sstevel@tonic-gate };
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate #define	IB_N_NDI_EVENTS	\
3650Sstevel@tonic-gate 	(sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t))
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = {
3680Sstevel@tonic-gate 	NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs};
3691093Shiremath static int	ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED;
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate /*
3730Sstevel@tonic-gate  * _init
3740Sstevel@tonic-gate  *	Loadable module init, called before any other module.
3750Sstevel@tonic-gate  */
3760Sstevel@tonic-gate int
3770Sstevel@tonic-gate _init(void)
3780Sstevel@tonic-gate {
3790Sstevel@tonic-gate 	int	error;
3802402Spramodbg 	char	**hca_driver_list;
3812402Spramodbg 	int	i, ndrivers;
3820Sstevel@tonic-gate 
3831093Shiremath 	if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) {
3842402Spramodbg 		ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE;
3852402Spramodbg 		hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers);
3862402Spramodbg 		for (i = 0; i < ndrivers; i++) {
3872402Spramodbg 			ibnex_hw_in_dev_tree(hca_driver_list[i]);
3882402Spramodbg 			if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE)
3892402Spramodbg 				break;
3902402Spramodbg 		}
3912402Spramodbg 		mdi_free_phci_driver_list(hca_driver_list, ndrivers);
3921093Shiremath 	}
3931093Shiremath 
3941093Shiremath 	/*
3951093Shiremath 	 * IB Nexus _init can be called while force attaching
3961093Shiremath 	 * IB Nexus driver or when a HCA is hotplugged.
3971093Shiremath 	 *
3981093Shiremath 	 * If IB HW is not in device tree or if no HCA driver
3991093Shiremath 	 * has been attached, fail IB Nexus _init().
4001093Shiremath 	 */
4011093Shiremath 	if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE &&
4021093Shiremath 	    ibt_hw_is_present() == 0) {
4031093Shiremath 		IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW");
4041093Shiremath 		return (DDI_FAILURE);
4051093Shiremath 	}
4061093Shiremath 
4070Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_init");
4080Sstevel@tonic-gate 	mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL);
4090Sstevel@tonic-gate 	cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL);
4100Sstevel@tonic-gate 	if ((error = mod_install(&modlinkage)) != 0) {
4110Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed");
4120Sstevel@tonic-gate 		mutex_destroy(&ibnex.ibnex_mutex);
4130Sstevel@tonic-gate 		cv_destroy(&ibnex.ibnex_reprobe_cv);
4140Sstevel@tonic-gate 	} else {
4150Sstevel@tonic-gate 		ibdm_ibnex_register_callback(ibnex_dm_callback);
4160Sstevel@tonic-gate 		ibtl_ibnex_register_callback(ibnex_ibtl_callback);
4170Sstevel@tonic-gate 	}
4180Sstevel@tonic-gate 	return (error);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate /*
4230Sstevel@tonic-gate  * _fini
4240Sstevel@tonic-gate  *	Prepares a module for unloading.
4250Sstevel@tonic-gate  */
4260Sstevel@tonic-gate int
4270Sstevel@tonic-gate _fini(void)
4280Sstevel@tonic-gate {
4290Sstevel@tonic-gate 	int	error;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_fini");
4320Sstevel@tonic-gate 	if ((error = mod_remove(&modlinkage)) != 0) {
4330Sstevel@tonic-gate 		return (error);
4340Sstevel@tonic-gate 	}
4350Sstevel@tonic-gate 	ibdm_ibnex_unregister_callback();
4360Sstevel@tonic-gate 	ibtl_ibnex_unregister_callback();
4370Sstevel@tonic-gate 	mutex_destroy(&ibnex.ibnex_mutex);
4380Sstevel@tonic-gate 	cv_destroy(&ibnex.ibnex_reprobe_cv);
4390Sstevel@tonic-gate 	return (0);
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate /*
4440Sstevel@tonic-gate  * _info
4450Sstevel@tonic-gate  *	Returns information about loadable module.
4460Sstevel@tonic-gate  */
4470Sstevel@tonic-gate int
4480Sstevel@tonic-gate _info(struct modinfo *modinfop)
4490Sstevel@tonic-gate {
4500Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\t_info");
4510Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate /*
4560Sstevel@tonic-gate  * ibnex_attach
4570Sstevel@tonic-gate  *	Configure and attach an instance of the IB Nexus driver
4580Sstevel@tonic-gate  *	Only one instance of IB Nexus is supported
4590Sstevel@tonic-gate  *	Create a minor node for cfgadm purpose
4600Sstevel@tonic-gate  *	Initialize communication services
4610Sstevel@tonic-gate  *	Register callback with IBDM
4620Sstevel@tonic-gate  *	Register callback with IBTL
4630Sstevel@tonic-gate  */
4640Sstevel@tonic-gate static int
4650Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4660Sstevel@tonic-gate {
4670Sstevel@tonic-gate 	int		i;
4680Sstevel@tonic-gate 	int		instance = ddi_get_instance(dip);
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd);
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	switch (cmd) {
4730Sstevel@tonic-gate 	case DDI_ATTACH:
4740Sstevel@tonic-gate 		break;
4750Sstevel@tonic-gate 	case DDI_RESUME:
4760Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME");
4770Sstevel@tonic-gate 		return (DDI_SUCCESS);
4780Sstevel@tonic-gate 	default:
4790Sstevel@tonic-gate 		return (DDI_FAILURE);
4800Sstevel@tonic-gate 	}
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	/* Fail attach for more than one instance */
4830Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
4840Sstevel@tonic-gate 	if (ibnex.ibnex_dip != NULL) {
4850Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
4860Sstevel@tonic-gate 		return (DDI_FAILURE);
4870Sstevel@tonic-gate 	}
4880Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	/* Register with MPxIO framework */
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0)
4930Sstevel@tonic-gate 	    != MDI_SUCCESS) {
4940Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
4950Sstevel@tonic-gate 		    "\tattach: mdi_vhci_register() failed");
4960Sstevel@tonic-gate 		return (DDI_FAILURE);
4970Sstevel@tonic-gate 	}
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate 	/*
5010Sstevel@tonic-gate 	 * Create the "fabric" devctl minor-node for IB DR support.
5020Sstevel@tonic-gate 	 * The minor number for the "devctl" node is in the same format
5030Sstevel@tonic-gate 	 * as the AP minor nodes.
5040Sstevel@tonic-gate 	 */
5050Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance,
5060Sstevel@tonic-gate 	    DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
5070Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5080Sstevel@tonic-gate 		    "\tattach: failed to create fabric minornode");
5090Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5100Sstevel@tonic-gate 		return (DDI_FAILURE);
5110Sstevel@tonic-gate 	}
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	/*
5150Sstevel@tonic-gate 	 * Set pm-want-child-notification property for
5160Sstevel@tonic-gate 	 * power management of the phci and client
5170Sstevel@tonic-gate 	 */
5180Sstevel@tonic-gate 	if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
5190Sstevel@tonic-gate 	    "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) {
5200Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5210Sstevel@tonic-gate 		    "_attach: create pm-want-child-notification failed");
5220Sstevel@tonic-gate 		(void) ddi_remove_minor_node(dip, NULL);
5230Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5240Sstevel@tonic-gate 		return (DDI_FAILURE);
5250Sstevel@tonic-gate 	}
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
5280Sstevel@tonic-gate 	ibnex.ibnex_dip  = dip;
5290Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 	/*
5320Sstevel@tonic-gate 	 * Event Handling: Definition and Binding.
5330Sstevel@tonic-gate 	 */
5340Sstevel@tonic-gate 	if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl,
5350Sstevel@tonic-gate 	    NDI_SLEEP) != NDI_SUCCESS) {
5360Sstevel@tonic-gate 		(void) ddi_remove_minor_node(dip, NULL);
5370Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5380Sstevel@tonic-gate 		    "_attach: ndi_event_alloc_hdl failed");
5390Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5400Sstevel@tonic-gate 		return (DDI_FAILURE);
5410Sstevel@tonic-gate 	}
5420Sstevel@tonic-gate 	if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events,
5430Sstevel@tonic-gate 	    NDI_SLEEP) != NDI_SUCCESS) {
5440Sstevel@tonic-gate 		(void) ddi_remove_minor_node(dip, NULL);
5450Sstevel@tonic-gate 		(void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl);
5460Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
5470Sstevel@tonic-gate 		    "_attach: ndi_event_bind_set failed");
5480Sstevel@tonic-gate 		(void) mdi_vhci_unregister(dip, 0);
5490Sstevel@tonic-gate 		return (DDI_FAILURE);
5500Sstevel@tonic-gate 	}
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 	for (i = 0; i < N_IBNEX_PROPS; i++) {
5530Sstevel@tonic-gate 		if (ibnex_comm_svc_init(ibnex_properties[i].name,
5540Sstevel@tonic-gate 		    ibnex_properties[i].type) != IBNEX_SUCCESS) {
5550Sstevel@tonic-gate 			ibnex_comm_svc_fini();
5560Sstevel@tonic-gate 			(void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl,
5570Sstevel@tonic-gate 			    &ib_ndi_events, NDI_SLEEP);
5580Sstevel@tonic-gate 			(void) ddi_remove_minor_node(dip, NULL);
5590Sstevel@tonic-gate 			(void) ndi_event_free_hdl(
5600Sstevel@tonic-gate 			    ibnex.ibnex_ndi_event_hdl);
5610Sstevel@tonic-gate 			ibnex.ibnex_ndi_event_hdl = NULL;
5620Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init"
5630Sstevel@tonic-gate 			    " failed %s", ibnex_properties[i].name);
5640Sstevel@tonic-gate 			(void) mdi_vhci_unregister(dip, 0);
5650Sstevel@tonic-gate 			return (DDI_FAILURE);
5660Sstevel@tonic-gate 		}
5670Sstevel@tonic-gate 	}
5680Sstevel@tonic-gate 
5690Sstevel@tonic-gate 	/*
5700Sstevel@tonic-gate 	 * before anything else comes up:
5710Sstevel@tonic-gate 	 * Initialize the internal list of pseudo device nodes by
5720Sstevel@tonic-gate 	 * getting all pseudo children of "ib" and processing them.
5730Sstevel@tonic-gate 	 */
5740Sstevel@tonic-gate 	ibnex_pseudo_initnodes();
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	return (DDI_SUCCESS);
5770Sstevel@tonic-gate }
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate /*
5810Sstevel@tonic-gate  * ibnex_getinfo()
5820Sstevel@tonic-gate  * Given the device number, return the devinfo pointer or the
5830Sstevel@tonic-gate  * instance number.
5840Sstevel@tonic-gate  * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
5850Sstevel@tonic-gate  */
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate /*ARGSUSED*/
5880Sstevel@tonic-gate static int
5890Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
5900Sstevel@tonic-gate {
5910Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin");
5940Sstevel@tonic-gate 	switch (cmd) {
5950Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
5960Sstevel@tonic-gate 		if (ibnex.ibnex_dip != NULL)
5970Sstevel@tonic-gate 			*result = ibnex.ibnex_dip;
5980Sstevel@tonic-gate 		else {
5990Sstevel@tonic-gate 			*result = NULL;
6000Sstevel@tonic-gate 			ret = DDI_FAILURE;
6010Sstevel@tonic-gate 		}
6020Sstevel@tonic-gate 		break;
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
6050Sstevel@tonic-gate 		*result = 0;
6060Sstevel@tonic-gate 		break;
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate 	default:
6090Sstevel@tonic-gate 		ret = DDI_FAILURE;
6100Sstevel@tonic-gate 	}
6110Sstevel@tonic-gate 	return (ret);
6120Sstevel@tonic-gate }
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate 
6150Sstevel@tonic-gate /*
6160Sstevel@tonic-gate  * ibnex_detach
6170Sstevel@tonic-gate  *	Unregister callback with the IBDM
6180Sstevel@tonic-gate  *	Unregister callback with the IBTL
6190Sstevel@tonic-gate  *	Uninitialize the communication entries
6200Sstevel@tonic-gate  *	Remove all the minor nodes created by this instance
6210Sstevel@tonic-gate  */
6220Sstevel@tonic-gate static int
6230Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
6240Sstevel@tonic-gate {
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd);
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate 	switch (cmd) {
6290Sstevel@tonic-gate 
6300Sstevel@tonic-gate 	case DDI_DETACH:
6310Sstevel@tonic-gate 		break;
6320Sstevel@tonic-gate 	case DDI_SUSPEND:
6330Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend");
6340Sstevel@tonic-gate 		return (DDI_SUCCESS);
6350Sstevel@tonic-gate 	default:
6360Sstevel@tonic-gate 		return (DDI_FAILURE);
6370Sstevel@tonic-gate 	}
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
6400Sstevel@tonic-gate 	if (ibt_hw_is_present()) {
6410Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
6420Sstevel@tonic-gate 		    "\tdetach: IB HW is present ");
6430Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
6440Sstevel@tonic-gate 		return (DDI_FAILURE);
6450Sstevel@tonic-gate 	}
6460Sstevel@tonic-gate 	if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) {
6470Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
6480Sstevel@tonic-gate 		    "\tdetach: ndi_event_free_hdl() failed");
6490Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
6500Sstevel@tonic-gate 		return (DDI_FAILURE);
6510Sstevel@tonic-gate 	}
6520Sstevel@tonic-gate 	ibnex.ibnex_ndi_event_hdl = NULL;
6530Sstevel@tonic-gate 	ibnex.ibnex_prop_update_evt_cookie = NULL;
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	ibnex_pseudo_node_cleanup();
6560Sstevel@tonic-gate 	ibnex_comm_svc_fini();
6570Sstevel@tonic-gate 	ibnex_ioc_node_cleanup();
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate 	(void) ddi_remove_minor_node(dip, NULL);
6600Sstevel@tonic-gate 	ibnex.ibnex_dip = NULL;
6610Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
6620Sstevel@tonic-gate 	(void) mdi_vhci_unregister(dip, 0);
6630Sstevel@tonic-gate 	return (DDI_SUCCESS);
6640Sstevel@tonic-gate }
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate /*
6680Sstevel@tonic-gate  * ibnex_pseudo_node_cleanup()
6690Sstevel@tonic-gate  *	This checks if all the "dips" have been deallocated (implying
6700Sstevel@tonic-gate  *	that all the children have been unconfigured) first.
6710Sstevel@tonic-gate  *	If not, it just returns.
6720Sstevel@tonic-gate  *	If yes, then it frees up memory allocated for devi_name,
6730Sstevel@tonic-gate  *	node_addr, and property list.
6740Sstevel@tonic-gate  */
6750Sstevel@tonic-gate static void
6760Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void)
6770Sstevel@tonic-gate {
6780Sstevel@tonic-gate 	ibnex_node_data_t	*nodep =  ibnex.ibnex_pseudo_node_head;
6790Sstevel@tonic-gate 	ibnex_pseudo_node_t	*pseudo;
6800Sstevel@tonic-gate 
6810Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:");
6820Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate 	for (; nodep; nodep = nodep->node_next)
6850Sstevel@tonic-gate 		if (nodep->node_dip)
6860Sstevel@tonic-gate 			return;
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory");
6890Sstevel@tonic-gate 	for (nodep =  ibnex.ibnex_pseudo_node_head; nodep;
6900Sstevel@tonic-gate 	    nodep = nodep->node_next) {
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 		pseudo = &nodep->node_data.pseudo_node;
6930Sstevel@tonic-gate 		if (pseudo->pseudo_node_addr) {
6940Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_node_addr,
6950Sstevel@tonic-gate 			    strlen(pseudo-> pseudo_node_addr) + 1);
6960Sstevel@tonic-gate 			pseudo->pseudo_node_addr = NULL;
6970Sstevel@tonic-gate 		}
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate 		if (pseudo->pseudo_devi_name) {
7000Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_devi_name,
7010Sstevel@tonic-gate 			    strlen(pseudo-> pseudo_devi_name) + 1);
7020Sstevel@tonic-gate 			pseudo->pseudo_devi_name = NULL;
7030Sstevel@tonic-gate 		}
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate 		if (pseudo->pseudo_unit_addr) {
7060Sstevel@tonic-gate 			kmem_free(pseudo->pseudo_unit_addr,
7070Sstevel@tonic-gate 			    pseudo->pseudo_unit_addr_len);
7080Sstevel@tonic-gate 		}
7090Sstevel@tonic-gate 	}
7100Sstevel@tonic-gate }
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate /*
7140Sstevel@tonic-gate  * This functions wakes up any reprobe requests waiting for completion
7150Sstevel@tonic-gate  * of reprobe of this IOC. It also send an NDI event, if  :
7160Sstevel@tonic-gate  *
7170Sstevel@tonic-gate  *	notify_flag is set. This is set if :
7180Sstevel@tonic-gate  *		ibt_reprobe_ioc has returned with SUCCESS
7190Sstevel@tonic-gate  *		IBTF client has not been notified for this node.
7200Sstevel@tonic-gate  *	node_data->node_dip != NULL
7210Sstevel@tonic-gate  *	node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set
7220Sstevel@tonic-gate  *	An NDI event cookie has been registered.
7230Sstevel@tonic-gate  */
7240Sstevel@tonic-gate static void
7250Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag)
7260Sstevel@tonic-gate {
7270Sstevel@tonic-gate 	ddi_eventcookie_t	evt_cookie;
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7300Sstevel@tonic-gate 	evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate 	if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) ||
7330Sstevel@tonic-gate 	    (node_data->node_reprobe_state != 0)) {
7340Sstevel@tonic-gate 		if (notify_flag && (node_data->node_dip != NULL) &&
7350Sstevel@tonic-gate 		    (node_data->node_state &
7360Sstevel@tonic-gate 		    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) &&
7370Sstevel@tonic-gate 		    (evt_cookie != NULL)) {
7380Sstevel@tonic-gate 			ibt_prop_update_payload_t	evt_data;
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 			bzero(&evt_data, sizeof (evt_data));
7430Sstevel@tonic-gate 			if (ndi_post_event(ibnex.ibnex_dip,
7440Sstevel@tonic-gate 			    node_data->node_dip,
7450Sstevel@tonic-gate 			    evt_cookie, &evt_data) != NDI_SUCCESS)
7460Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
7470Sstevel@tonic-gate 				    "\tndi_post_event failed\n");
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
7500Sstevel@tonic-gate 		}
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 		node_data->node_reprobe_state = 0;
7530Sstevel@tonic-gate 		cv_broadcast(&ibnex.ibnex_reprobe_cv);
7540Sstevel@tonic-gate 	}
7550Sstevel@tonic-gate 	node_data->node_reprobe_state = 0;
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate /*
7590Sstevel@tonic-gate  * This function wakes up any reprobe request waiting for completion
7600Sstevel@tonic-gate  * of reprobe of all IOCs.
7610Sstevel@tonic-gate  */
7620Sstevel@tonic-gate static void
7630Sstevel@tonic-gate ibnex_wakeup_reprobe_all()
7640Sstevel@tonic-gate {
7650Sstevel@tonic-gate 	ibnex_node_data_t *ioc_node;
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate 	/* Notify if another reprobe_all is pending */
7700Sstevel@tonic-gate 	if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) {
7710Sstevel@tonic-gate 		ibnex.ibnex_reprobe_state = 0;
7720Sstevel@tonic-gate 		cv_broadcast(&ibnex.ibnex_reprobe_cv);
7730Sstevel@tonic-gate 	}
7740Sstevel@tonic-gate 	ibnex.ibnex_reprobe_state = 0;
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 	/*
7770Sstevel@tonic-gate 	 * The IOC may be hot-removed after the reprobe request.
7780Sstevel@tonic-gate 	 * Reset the reprobe states for such IOCs.
7790Sstevel@tonic-gate 	 */
7800Sstevel@tonic-gate 	for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node;
7810Sstevel@tonic-gate 	    ioc_node = ioc_node->node_next) {
7820Sstevel@tonic-gate 		if (ioc_node->node_reprobe_state != 0) {
7830Sstevel@tonic-gate 			ibnex_wakeup_reprobe_ioc(ioc_node, 1);
7840Sstevel@tonic-gate 		}
7850Sstevel@tonic-gate 	}
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate /*
7890Sstevel@tonic-gate  * ibnex_ibnex_callback:
7900Sstevel@tonic-gate  *	IBTL_IBNEX_IBC_INIT:
7910Sstevel@tonic-gate  *		Called from ibc_init() which is called from
7920Sstevel@tonic-gate  *		HCA driver _init entry point
7930Sstevel@tonic-gate  *		Initializes the HCA dev_ops structure with default
7940Sstevel@tonic-gate  *		IB nexus structure.
7950Sstevel@tonic-gate  *	IBTL_IBNEX_IBC_FINI:
7960Sstevel@tonic-gate  *		Called from ibc_fini() which is called from
7970Sstevel@tonic-gate  *		HCA driver _fini entry point
7980Sstevel@tonic-gate  *		Un-Initializes the HCA dev_ops structure with default
7990Sstevel@tonic-gate  *		IB nexus strucuture.
8000Sstevel@tonic-gate  *	Returns IBT_SUCCESS
8010Sstevel@tonic-gate  */
8020Sstevel@tonic-gate ibt_status_t
8030Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args)
8040Sstevel@tonic-gate {
8050Sstevel@tonic-gate 	int			retval = IBT_SUCCESS;
8060Sstevel@tonic-gate 	struct dev_ops 		*hca_dev_ops;
8070Sstevel@tonic-gate 	dev_info_t		*clnt_dip;
8080Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
8090Sstevel@tonic-gate 
8100Sstevel@tonic-gate 	IBTF_DPRINTF_L5("ibnex", "\tibtl_callback");
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	switch (cb_args->cb_flag) {
8130Sstevel@tonic-gate 	case IBTL_IBNEX_IBC_INIT:
8140Sstevel@tonic-gate 		/*
8150Sstevel@tonic-gate 		 * Get the devops structure of the HCA,
8160Sstevel@tonic-gate 		 * and put IB nexus default busops vector in its place.
8170Sstevel@tonic-gate 		 */
8180Sstevel@tonic-gate 		hca_dev_ops = ((struct modldrv *)
8195470Spramodbg 		    (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8200Sstevel@tonic-gate 		ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL));
8210Sstevel@tonic-gate 		hca_dev_ops->devo_bus_ops = &ibnex_ci_busops;
8220Sstevel@tonic-gate 		break;
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate 	case IBTL_IBNEX_IBC_FINI:
8250Sstevel@tonic-gate 		hca_dev_ops = ((struct modldrv *)
8265470Spramodbg 		    (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8270Sstevel@tonic-gate 		hca_dev_ops->devo_bus_ops = NULL;
8280Sstevel@tonic-gate 		break;
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	case IBTL_IBNEX_REPROBE_DEV_REQ:
8310Sstevel@tonic-gate 		/* IBTL pass down request for ibt_reprobe_dev */
8320Sstevel@tonic-gate 		clnt_dip = cb_args->cb_dip;
8330Sstevel@tonic-gate 		ASSERT(clnt_dip);
8340Sstevel@tonic-gate 
8350Sstevel@tonic-gate 		node_data = ddi_get_parent_data(clnt_dip);
8360Sstevel@tonic-gate 		ASSERT(node_data);
8370Sstevel@tonic-gate 
8380Sstevel@tonic-gate 		/* Reprobe for IOC nodes only */
8390Sstevel@tonic-gate 		ASSERT(node_data->node_type == IBNEX_IOC_NODE);
8400Sstevel@tonic-gate 
8410Sstevel@tonic-gate 		/*
8420Sstevel@tonic-gate 		 * Start the reprobe. This could sleep as it is not
8430Sstevel@tonic-gate 		 * from interrupt context.
8440Sstevel@tonic-gate 		 */
8450Sstevel@tonic-gate 		if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev,
8460Sstevel@tonic-gate 		    clnt_dip, TQ_SLEEP) == 0) {
8470Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
8480Sstevel@tonic-gate 			    "ibnex_ibtl_callback: taskq_dispatch failed");
8490Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
8500Sstevel@tonic-gate 			ibnex_wakeup_reprobe_ioc(node_data, 0);
8510Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
8520Sstevel@tonic-gate 			return (IBT_INSUFF_KERNEL_RESOURCE);
8530Sstevel@tonic-gate 		}
8540Sstevel@tonic-gate 		return (IBT_SUCCESS);
8550Sstevel@tonic-gate 	}
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate 	return (retval);
8580Sstevel@tonic-gate }
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 
8610Sstevel@tonic-gate /*
8620Sstevel@tonic-gate  * Bus-ops entry points
8630Sstevel@tonic-gate  */
8640Sstevel@tonic-gate 
8650Sstevel@tonic-gate /*
8660Sstevel@tonic-gate  * ibnex_map_fault
8670Sstevel@tonic-gate  * 	IOC drivers need not map memory. Return failure to fail any
8680Sstevel@tonic-gate  *	such calls.
8690Sstevel@tonic-gate  */
8700Sstevel@tonic-gate /*ARGSUSED*/
8710Sstevel@tonic-gate static int
8720Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat,
8730Sstevel@tonic-gate     struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn,
8740Sstevel@tonic-gate     uint_t prot, uint_t lock)
8750Sstevel@tonic-gate {
8760Sstevel@tonic-gate 	return (DDI_FAILURE);
8770Sstevel@tonic-gate }
8780Sstevel@tonic-gate 
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate /*
8810Sstevel@tonic-gate  * ibnex_busctl
8820Sstevel@tonic-gate  * 	bus_ctl bus_ops entry point
8830Sstevel@tonic-gate  */
8840Sstevel@tonic-gate /*ARGSUSED*/
8850Sstevel@tonic-gate static int
8860Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip,
8870Sstevel@tonic-gate     ddi_ctl_enum_t ctlop, void *arg, void *result)
8880Sstevel@tonic-gate {
8890Sstevel@tonic-gate 	dev_info_t		*child_dip;
8900Sstevel@tonic-gate 
8910Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
8920Sstevel@tonic-gate 	    "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop);
8930Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result);
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 	switch (ctlop) {
8960Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
8970Sstevel@tonic-gate 		if (rdip == NULL) {
8980Sstevel@tonic-gate 			return (DDI_FAILURE);
8990Sstevel@tonic-gate 		}
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate 		/* Log the relevant details of dip to sysbuf */
9020Sstevel@tonic-gate 		cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n",
9030Sstevel@tonic-gate 		    ddi_node_name(rdip), ddi_get_name_addr(rdip),
9040Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 		return (DDI_SUCCESS);
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
9090Sstevel@tonic-gate 		child_dip = (dev_info_t *)arg;
9100Sstevel@tonic-gate 		return (ibnex_init_child(child_dip));
9110Sstevel@tonic-gate 
9120Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
9130Sstevel@tonic-gate 		child_dip = (dev_info_t *)arg;
9140Sstevel@tonic-gate 		ddi_set_name_addr(child_dip, NULL);
9150Sstevel@tonic-gate 		return (DDI_SUCCESS);
9160Sstevel@tonic-gate 
9170Sstevel@tonic-gate 	case DDI_CTLOPS_ATTACH:
9180Sstevel@tonic-gate 	case DDI_CTLOPS_DETACH:
9190Sstevel@tonic-gate 	case DDI_CTLOPS_POWER :
9200Sstevel@tonic-gate 		return (DDI_SUCCESS);
9210Sstevel@tonic-gate 
9220Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
9230Sstevel@tonic-gate 		/*
9240Sstevel@tonic-gate 		 * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and
9250Sstevel@tonic-gate 		 * DDI_FAILURE for the nodes enumerated by a Pseudo file.
9260Sstevel@tonic-gate 		 */
9270Sstevel@tonic-gate 		return (ndi_dev_is_persistent_node(rdip) ?
9280Sstevel@tonic-gate 		    DDI_SUCCESS : DDI_FAILURE);
9290Sstevel@tonic-gate 
9300Sstevel@tonic-gate 
9310Sstevel@tonic-gate 	case DDI_CTLOPS_IOMIN:
9320Sstevel@tonic-gate 		/*
9330Sstevel@tonic-gate 		 * Return DDI_SUCCESS, so that consistent buf alloc
9340Sstevel@tonic-gate 		 * gets the default DMA IO minimum for the platform
9350Sstevel@tonic-gate 		 */
9360Sstevel@tonic-gate 		return (DDI_SUCCESS);
9370Sstevel@tonic-gate 
9380Sstevel@tonic-gate 	/*
9390Sstevel@tonic-gate 	 * These ops correspond to functions that "shouldn't" be
9400Sstevel@tonic-gate 	 * called by IB Nexus driver.
9410Sstevel@tonic-gate 	 */
9420Sstevel@tonic-gate 	case DDI_CTLOPS_DMAPMAPC:
9430Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTINT:
9440Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
9450Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
9460Sstevel@tonic-gate 	case DDI_CTLOPS_SLAVEONLY:
9470Sstevel@tonic-gate 	case DDI_CTLOPS_AFFINITY:
9480Sstevel@tonic-gate 	case DDI_CTLOPS_POKE:
9490Sstevel@tonic-gate 	case DDI_CTLOPS_PEEK:
9500Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
9510Sstevel@tonic-gate 		    "%s%d: invalid op (%d) from %s inst%d",
9520Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip),
9530Sstevel@tonic-gate 		    ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
9540Sstevel@tonic-gate 		return (DDI_FAILURE);
9550Sstevel@tonic-gate 
9560Sstevel@tonic-gate 	/*
9570Sstevel@tonic-gate 	 * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we
9580Sstevel@tonic-gate 	 * pass up
9590Sstevel@tonic-gate 	 */
9600Sstevel@tonic-gate 	default:
9610Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
9620Sstevel@tonic-gate 	}
9630Sstevel@tonic-gate }
9640Sstevel@tonic-gate 
9650Sstevel@tonic-gate 
9660Sstevel@tonic-gate /*
9670Sstevel@tonic-gate  * ibnex_init_child()
9680Sstevel@tonic-gate  *
9690Sstevel@tonic-gate  * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD
9700Sstevel@tonic-gate  * entry. Function returns DDI_SUCCESS,  DDI_FAILURE or DDI_NOT_WELL_FORMED.
9710Sstevel@tonic-gate  */
9720Sstevel@tonic-gate static int
9730Sstevel@tonic-gate ibnex_init_child(dev_info_t *child)
9740Sstevel@tonic-gate {
9750Sstevel@tonic-gate 	int			ret;
9760Sstevel@tonic-gate 	char			name[MAXNAMELEN];
9770Sstevel@tonic-gate 
9780Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child);
9790Sstevel@tonic-gate 
9800Sstevel@tonic-gate 	/* Handle Pseudo nodes of client children */
9810Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
9821093Shiremath 		/* Skip nodes without ib-node-type="merge" */
9831093Shiremath 		if (ibnex_is_merge_node(child) != IBNEX_SUCCESS)
9841093Shiremath 			return (DDI_FAILURE);
9851093Shiremath 
9860Sstevel@tonic-gate 		if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS)
9870Sstevel@tonic-gate 			return (DDI_FAILURE);
9880Sstevel@tonic-gate 
9890Sstevel@tonic-gate 		ddi_set_name_addr(child, name);
9900Sstevel@tonic-gate 		/*
9910Sstevel@tonic-gate 		 * Merge the .conf node
9920Sstevel@tonic-gate 		 */
9930Sstevel@tonic-gate 		if (ndi_merge_node(child,
9940Sstevel@tonic-gate 		    ibnex_name_child) == DDI_SUCCESS) {
9950Sstevel@tonic-gate 			ddi_set_name_addr(child, NULL);
9960Sstevel@tonic-gate 			return (DDI_FAILURE);
9970Sstevel@tonic-gate 		}
9980Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
9990Sstevel@tonic-gate 
10000Sstevel@tonic-gate 	}
10010Sstevel@tonic-gate 
10020Sstevel@tonic-gate 	if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS)
10030Sstevel@tonic-gate 		return (ret);
10040Sstevel@tonic-gate 
10050Sstevel@tonic-gate 	ddi_set_name_addr(child, name);
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate 	return (DDI_SUCCESS);
10080Sstevel@tonic-gate }
10090Sstevel@tonic-gate 
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate int
10120Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name)
10130Sstevel@tonic-gate {
10140Sstevel@tonic-gate 	char **unit_addr;
10150Sstevel@tonic-gate 	uint_t n;
10160Sstevel@tonic-gate 	if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
10170Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
10180Sstevel@tonic-gate 	    DDI_PROP_SUCCESS) {
10191093Shiremath 		IBTF_DPRINTF_L4("ibnex",
10201093Shiremath 		    "\tname_pseudo_child: cannot find unit-address in %s.conf",
10210Sstevel@tonic-gate 		    ddi_get_name(child));
10220Sstevel@tonic-gate 		return (DDI_FAILURE);
10230Sstevel@tonic-gate 	}
10240Sstevel@tonic-gate 	if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
10250Sstevel@tonic-gate 		cmn_err(CE_WARN, "unit-address property in %s.conf"
10260Sstevel@tonic-gate 		    " not well-formed", ddi_get_name(child));
10270Sstevel@tonic-gate 		ddi_prop_free(unit_addr);
10280Sstevel@tonic-gate 		return (DDI_FAILURE);
10290Sstevel@tonic-gate 	}
10300Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN, "%s", *unit_addr);
10310Sstevel@tonic-gate 	ddi_prop_free(unit_addr);
10320Sstevel@tonic-gate 	return (DDI_SUCCESS);
10330Sstevel@tonic-gate }
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 
10360Sstevel@tonic-gate /*ARGSUSED*/
10370Sstevel@tonic-gate int
10380Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag)
10390Sstevel@tonic-gate {
10400Sstevel@tonic-gate 	ibnex_pseudo_node_t	*pseudo;
10410Sstevel@tonic-gate 	ibnex_node_data_t	*node_datap;
10420Sstevel@tonic-gate 	ibnex_port_node_t	*port_node;
10430Sstevel@tonic-gate 	ibnex_ioc_node_t	*ioc;
10440Sstevel@tonic-gate 
10450Sstevel@tonic-gate 	node_datap = ddi_get_parent_data(child);
10460Sstevel@tonic-gate 	if (node_datap == NULL) {
10470Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL");
10480Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
10490Sstevel@tonic-gate 	}
10500Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p"
10510Sstevel@tonic-gate 	    "Node type %x", node_datap, node_datap->node_type);
10520Sstevel@tonic-gate 	switch (node_datap->node_type) {
10530Sstevel@tonic-gate 	case IBNEX_PORT_COMMSVC_NODE:
10540Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10550Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10560Sstevel@tonic-gate 		    port_node->port_num,
10570Sstevel@tonic-gate 		    ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]);
10580Sstevel@tonic-gate 		break;
10590Sstevel@tonic-gate 	case IBNEX_VPPA_COMMSVC_NODE:
10600Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10610Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s",
10620Sstevel@tonic-gate 		    port_node->port_num, port_node->port_pkey, ibnex.
10630Sstevel@tonic-gate 		    ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]);
10640Sstevel@tonic-gate 		break;
10650Sstevel@tonic-gate 	case IBNEX_HCASVC_COMMSVC_NODE:
10660Sstevel@tonic-gate 		port_node = &node_datap->node_data.port_node;
10670Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10680Sstevel@tonic-gate 		    port_node->port_num,
10690Sstevel@tonic-gate 		    ibnex.ibnex_hcasvc_comm_svc_names[port_node->
10700Sstevel@tonic-gate 		    port_commsvc_idx]);
10710Sstevel@tonic-gate 		break;
10720Sstevel@tonic-gate 	case IBNEX_IOC_NODE:
10730Sstevel@tonic-gate 		ioc = &node_datap->node_data.ioc_node;
10740Sstevel@tonic-gate 		(void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX",
10750Sstevel@tonic-gate 		    (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid);
10760Sstevel@tonic-gate 		break;
10770Sstevel@tonic-gate 	case IBNEX_PSEUDO_NODE:
10780Sstevel@tonic-gate 		pseudo = &node_datap->node_data.pseudo_node;
10790Sstevel@tonic-gate 		(void) snprintf(name,
10800Sstevel@tonic-gate 		    IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr);
10810Sstevel@tonic-gate 		break;
10820Sstevel@tonic-gate 	default:
10830Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed");
10840Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
10850Sstevel@tonic-gate 	}
10860Sstevel@tonic-gate 
10870Sstevel@tonic-gate 	return (DDI_SUCCESS);
10880Sstevel@tonic-gate }
10890Sstevel@tonic-gate 
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate /*
10920Sstevel@tonic-gate  * ibnex_bus_config()
10930Sstevel@tonic-gate  *
10940Sstevel@tonic-gate  * BUS_CONFIG_ONE:
10950Sstevel@tonic-gate  *	Enumerate the exact instance of the driver. Use the device node name
10960Sstevel@tonic-gate  *	to locate the exact instance.
10970Sstevel@tonic-gate  *	Query IBDM to find whether the hardware exits for the instance of the
10980Sstevel@tonic-gate  *	driver. If exists, create a device node and return NDI_SUCCESS.
10990Sstevel@tonic-gate  *
11000Sstevel@tonic-gate  * BUS_CONFIG_ALL:
11010Sstevel@tonic-gate  *	Enumerate all the instances of all the possible children (seen before
11020Sstevel@tonic-gate  *	and never seen before).
11030Sstevel@tonic-gate  *
11040Sstevel@tonic-gate  * BUS_CONFIG_DRIVER:
11050Sstevel@tonic-gate  *	Enumerate all the instances of a particular driver.
11060Sstevel@tonic-gate  */
11070Sstevel@tonic-gate static int
11080Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag,
11090Sstevel@tonic-gate     ddi_bus_config_op_t op, void *devname, dev_info_t **child)
11100Sstevel@tonic-gate {
11111093Shiremath 	int			ret = IBNEX_SUCCESS, len, circ, need_bus_config;
11120Sstevel@tonic-gate 	char 			*device_name, *cname = NULL, *caddr = NULL;
11131093Shiremath 	char			*device_name1;
11140Sstevel@tonic-gate 	char			*srvname, nameaddr[MAXNAMELEN];
11150Sstevel@tonic-gate 	dev_info_t		*cdip, *pdip = NULL;
11160Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
11170Sstevel@tonic-gate 	ibnex_port_node_t	*port_node;
11182155Scth 	int			use_mdi_devi_locking = 0;
11192155Scth 
1120*8082SRamaswamy.Tummala@Sun.COM 	if (parent != ibnex.ibnex_dip) {
1121*8082SRamaswamy.Tummala@Sun.COM 		/*
1122*8082SRamaswamy.Tummala@Sun.COM 		 * This must be an HCA.In a normal case HCA is setup as a phci.
1123*8082SRamaswamy.Tummala@Sun.COM 		 * If an HCA is in maintenance mode, its phci is not set up
1124*8082SRamaswamy.Tummala@Sun.COM 		 * but the driver is attached to update the firmware. In this
1125*8082SRamaswamy.Tummala@Sun.COM 		 * case, do not configure the MPxIO clients.
1126*8082SRamaswamy.Tummala@Sun.COM 		 */
1127*8082SRamaswamy.Tummala@Sun.COM 		if (mdi_component_is_phci(parent, NULL) == MDI_FAILURE) {
1128*8082SRamaswamy.Tummala@Sun.COM 			if (op == BUS_CONFIG_ALL || op == BUS_CONFIG_DRIVER)
1129*8082SRamaswamy.Tummala@Sun.COM 				return (NDI_SUCCESS);
1130*8082SRamaswamy.Tummala@Sun.COM 			else
1131*8082SRamaswamy.Tummala@Sun.COM 				return (NDI_FAILURE);
1132*8082SRamaswamy.Tummala@Sun.COM 		}
1133*8082SRamaswamy.Tummala@Sun.COM 
1134*8082SRamaswamy.Tummala@Sun.COM 		/* Set use_mdi_devi_locking appropriately */
1135*8082SRamaswamy.Tummala@Sun.COM 		if ((op != BUS_CONFIG_ONE) || (op == BUS_CONFIG_ONE &&
1136*8082SRamaswamy.Tummala@Sun.COM 		    strncmp((char *)devname, IBNEX_IBPORT_CNAME, 6) != 0)) {
1137*8082SRamaswamy.Tummala@Sun.COM 			IBTF_DPRINTF_L4("ibnex",
1138*8082SRamaswamy.Tummala@Sun.COM 			    "\tbus_config: using mdi_devi_enter");
1139*8082SRamaswamy.Tummala@Sun.COM 			use_mdi_devi_locking = 1;
1140*8082SRamaswamy.Tummala@Sun.COM 		}
11412155Scth 	}
11422155Scth 
11432155Scth 	if (use_mdi_devi_locking)
11442155Scth 		mdi_devi_enter(parent, &circ);
11452155Scth 	else
11462155Scth 		ndi_devi_enter(parent, &circ);
11470Sstevel@tonic-gate 
11480Sstevel@tonic-gate 	switch (op) {
11490Sstevel@tonic-gate 	case BUS_CONFIG_ONE:
11501689Spramodbg 		IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, "
11511689Spramodbg 		    "parent %p", parent);
11520Sstevel@tonic-gate 
11530Sstevel@tonic-gate 		len = strlen((char *)devname) + 1;
11540Sstevel@tonic-gate 		device_name = i_ddi_strdup(devname, KM_SLEEP);
11550Sstevel@tonic-gate 		i_ddi_parse_name(device_name, &cname, &caddr, NULL);
11560Sstevel@tonic-gate 
11570Sstevel@tonic-gate 		if (caddr == NULL || (strlen(caddr) == 0)) {
11580Sstevel@tonic-gate 			kmem_free(device_name, len);
11592155Scth 			if (use_mdi_devi_locking)
11602155Scth 				mdi_devi_exit(parent, circ);
11612155Scth 			else
11622155Scth 				ndi_devi_exit(parent, circ);
11630Sstevel@tonic-gate 			return (NDI_FAILURE);
11640Sstevel@tonic-gate 		}
11650Sstevel@tonic-gate 
11661093Shiremath 		/*
11671093Shiremath 		 * i_ddi_parse_name() strips of the address portion
11681093Shiremath 		 * of the device name. Recreate device name for
11691093Shiremath 		 * ndi_devi_findchild
11701093Shiremath 		 */
11711093Shiremath 		device_name1 = i_ddi_strdup(devname, KM_SLEEP);
11721093Shiremath 
11730Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
11740Sstevel@tonic-gate 		    "\tbus_config: cname %s addr %s", cname, caddr);
11750Sstevel@tonic-gate 
11761093Shiremath 		cdip = ndi_devi_findchild(parent, device_name1);
1177*8082SRamaswamy.Tummala@Sun.COM 		if (cdip)
1178*8082SRamaswamy.Tummala@Sun.COM 			node_data = ddi_get_parent_data(cdip);
11791093Shiremath 		kmem_free(device_name1, len);
1180*8082SRamaswamy.Tummala@Sun.COM 		if (cdip == NULL || (node_data != NULL &&
1181*8082SRamaswamy.Tummala@Sun.COM 		    node_data->node_dip == NULL)) {
11820Sstevel@tonic-gate 			/* Node is not present */
11830Sstevel@tonic-gate 			if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) {
11842155Scth 				if (use_mdi_devi_locking)
11852155Scth 					mdi_devi_exit(parent, circ);
11862155Scth 				else
11872155Scth 					ndi_devi_exit(parent, circ);
11882155Scth 
11891093Shiremath 				ret = ibnex_ioc_bus_config_one(&parent, flag,
11901093Shiremath 				    op, devname, child, &need_bus_config);
11911689Spramodbg 				if (!need_bus_config) {
11921689Spramodbg 					kmem_free(device_name, len);
11931093Shiremath 					return (ret);
11941689Spramodbg 				}
11951093Shiremath 
11962155Scth 				if (use_mdi_devi_locking)
11972155Scth 					mdi_devi_enter(parent, &circ);
11982155Scth 				else
11992155Scth 					ndi_devi_enter(parent, &circ);
12000Sstevel@tonic-gate 			} else if ((strncmp(cname,
12010Sstevel@tonic-gate 			    IBNEX_IBPORT_CNAME, 6) == 0) &&
12020Sstevel@tonic-gate 			    (parent != ibnex.ibnex_dip)) { /* parent is HCA */
12030Sstevel@tonic-gate 				cdip = ibnex_config_port_node(parent, devname);
12040Sstevel@tonic-gate 				if (cdip)
12050Sstevel@tonic-gate 					ret = IBNEX_SUCCESS;
12060Sstevel@tonic-gate 				else
12070Sstevel@tonic-gate 					ret = IBNEX_FAILURE;
12081093Shiremath 			} else {
12090Sstevel@tonic-gate 				/*
12100Sstevel@tonic-gate 				 * if not IOC or PORT device then always
12110Sstevel@tonic-gate 				 * assume a Pseudo child
12121093Shiremath 				 *
12131093Shiremath 				 * if IB Nexus is the parent, call MDI.
12141093Shiremath 				 * else if HCA is the parent, enumerate
12151093Shiremath 				 * the Pseudo node.
12160Sstevel@tonic-gate 				 */
12170Sstevel@tonic-gate 				ret = IBNEX_SUCCESS;
12180Sstevel@tonic-gate 				ibnex_pseudo_initnodes();
12191093Shiremath 				if (parent == ibnex.ibnex_dip) {
12202155Scth 					if (use_mdi_devi_locking)
12212155Scth 						mdi_devi_exit(parent, circ);
12222155Scth 					else
12232155Scth 						ndi_devi_exit(parent, circ);
12242155Scth 
12251093Shiremath 					mutex_enter(&ibnex.ibnex_mutex);
12261093Shiremath 					ret = ibnex_pseudo_mdi_config_one(
12271093Shiremath 					    flag, devname, child, cname,
12281093Shiremath 					    caddr);
12291093Shiremath 					mutex_exit(&ibnex.ibnex_mutex);
12301689Spramodbg 					kmem_free(device_name, len);
12311093Shiremath 					return (ret);
12321093Shiremath 				}
12330Sstevel@tonic-gate 				mutex_enter(&ibnex.ibnex_mutex);
12341689Spramodbg 				ret = ibnex_pseudo_config_one(NULL,
12351093Shiremath 				    caddr, parent);
12360Sstevel@tonic-gate 				mutex_exit(&ibnex.ibnex_mutex);
12371093Shiremath 			}
12380Sstevel@tonic-gate 		}
12393826Shiremath 
12403826Shiremath 		if (strncmp(cname, IBNEX_IBPORT_CNAME, 6) == 0) {
12413826Shiremath 			/* Allows enumeration under PHCI */
12423826Shiremath 			flag |= NDI_MDI_FALLBACK;
12433826Shiremath 		}
12440Sstevel@tonic-gate 		kmem_free(device_name, len);
12450Sstevel@tonic-gate 		break;
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate 	case BUS_CONFIG_OBP_ARGS:
12480Sstevel@tonic-gate 		cdip = ibnex_config_obp_args(parent, devname);
12490Sstevel@tonic-gate 		if (cdip) {
12500Sstevel@tonic-gate 			/*
12510Sstevel@tonic-gate 			 * Boot case.
12520Sstevel@tonic-gate 			 * Special handling because the "devname"
12530Sstevel@tonic-gate 			 * format for the enumerated device is
12540Sstevel@tonic-gate 			 * different.
12550Sstevel@tonic-gate 			 */
12560Sstevel@tonic-gate 			node_data = ddi_get_parent_data(cdip);
12570Sstevel@tonic-gate 			port_node = &node_data->node_data.port_node;
12580Sstevel@tonic-gate 			if (node_data->node_type ==
12590Sstevel@tonic-gate 			    IBNEX_VPPA_COMMSVC_NODE) {
12600Sstevel@tonic-gate 				srvname =
12610Sstevel@tonic-gate 				    ibnex.ibnex_vppa_comm_svc_names[
12620Sstevel@tonic-gate 				    port_node->port_commsvc_idx];
12630Sstevel@tonic-gate 				(void) snprintf(nameaddr, MAXNAMELEN,
12640Sstevel@tonic-gate 				    "ibport@%x,%x,%s",
12650Sstevel@tonic-gate 				    port_node->port_num,
12660Sstevel@tonic-gate 				    port_node->port_pkey, srvname);
12670Sstevel@tonic-gate 			}
12680Sstevel@tonic-gate 			devname = (void *)nameaddr;
12690Sstevel@tonic-gate 		} else {
12700Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
12710Sstevel@tonic-gate 			    "\tbus_config: CONFIG_OBP_ARGS : invalid state!!");
12720Sstevel@tonic-gate 
12730Sstevel@tonic-gate 			ret = IBNEX_FAILURE;
12740Sstevel@tonic-gate 		}
12750Sstevel@tonic-gate 		break;
12760Sstevel@tonic-gate 	case BUS_CONFIG_ALL:
12771093Shiremath 		/*FALLTHRU*/
12780Sstevel@tonic-gate 	case BUS_CONFIG_DRIVER:
12791093Shiremath 		if (op == BUS_CONFIG_ALL)
12801689Spramodbg 			IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, "
12811689Spramodbg 			    "parent %p", parent);
12821093Shiremath 		else
12831689Spramodbg 			IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER"
12841689Spramodbg 			    ", parent %p", parent);
12851093Shiremath 
12861093Shiremath 		/*
12872155Scth 		 * No locks to be held while calling mdi_vhci_bus_config()
12882155Scth 		 * ibnex_config_all_children() holds appropriate locks.
12892155Scth 		 */
12902155Scth 		if (use_mdi_devi_locking)
12912155Scth 			mdi_devi_exit(parent, circ);
12922155Scth 		else
12932155Scth 			ndi_devi_exit(parent, circ);
12942155Scth 
12952155Scth 		/*
12961093Shiremath 		 * Drive CONFIG requests for IB Nexus parent through
12971093Shiremath 		 * MDI. This is needed to load the HCA drivers in x86 SRP
12981093Shiremath 		 * boot case.
12991093Shiremath 		 *
13001093Shiremath 		 * CONFIG Requests with HCA parent will probe devices using
13011093Shiremath 		 * ibdm and configure all children.
13021093Shiremath 		 */
13031093Shiremath 		if (parent == ibnex.ibnex_dip) {
1304*8082SRamaswamy.Tummala@Sun.COM 			ibdm_ioc_info_t	*ioc_list;
1305*8082SRamaswamy.Tummala@Sun.COM 
1306*8082SRamaswamy.Tummala@Sun.COM 			/*
1307*8082SRamaswamy.Tummala@Sun.COM 			 * Optimize the calls for each BUS_CONFIG_ALL request
1308*8082SRamaswamy.Tummala@Sun.COM 			 * to the IB Nexus dip. This is currently done for
1309*8082SRamaswamy.Tummala@Sun.COM 			 * each PDIP.
1310*8082SRamaswamy.Tummala@Sun.COM 			 */
1311*8082SRamaswamy.Tummala@Sun.COM 			if (ibnex.ibnex_ioc_list) {
1312*8082SRamaswamy.Tummala@Sun.COM 				IBTF_DPRINTF_L4("ibnex",
1313*8082SRamaswamy.Tummala@Sun.COM 				    "\tbus_config: freeing ioc_list %p",
1314*8082SRamaswamy.Tummala@Sun.COM 				    ibnex.ibnex_ioc_list);
1315*8082SRamaswamy.Tummala@Sun.COM 				ibdm_ibnex_free_ioc_list(ibnex.ibnex_ioc_list);
1316*8082SRamaswamy.Tummala@Sun.COM 				mutex_enter(&ibnex.ibnex_mutex);
1317*8082SRamaswamy.Tummala@Sun.COM 				ibnex.ibnex_ioc_list = NULL;
1318*8082SRamaswamy.Tummala@Sun.COM 				mutex_exit(&ibnex.ibnex_mutex);
1319*8082SRamaswamy.Tummala@Sun.COM 			}
1320*8082SRamaswamy.Tummala@Sun.COM 
1321*8082SRamaswamy.Tummala@Sun.COM 			/* Enumerate all the IOC's */
1322*8082SRamaswamy.Tummala@Sun.COM 			ibdm_ibnex_port_settle_wait(0,
1323*8082SRamaswamy.Tummala@Sun.COM 			    ibnex_port_settling_time);
1324*8082SRamaswamy.Tummala@Sun.COM 
1325*8082SRamaswamy.Tummala@Sun.COM 			ioc_list = ibdm_ibnex_get_ioc_list(
1326*8082SRamaswamy.Tummala@Sun.COM 			    IBDM_IBNEX_NORMAL_PROBE);
1327*8082SRamaswamy.Tummala@Sun.COM 			IBTF_DPRINTF_L4("ibnex",
1328*8082SRamaswamy.Tummala@Sun.COM 			    "\tbus_config: alloc ioc_list %p", ioc_list);
1329*8082SRamaswamy.Tummala@Sun.COM 			mutex_enter(&ibnex.ibnex_mutex);
1330*8082SRamaswamy.Tummala@Sun.COM 			ibnex.ibnex_ioc_list = ioc_list;
1331*8082SRamaswamy.Tummala@Sun.COM 			mutex_exit(&ibnex.ibnex_mutex);
1332*8082SRamaswamy.Tummala@Sun.COM 
13331093Shiremath 			ret = mdi_vhci_bus_config(parent,
13341093Shiremath 			    flag, op, devname, child, NULL);
13351093Shiremath 			return (ret);
13361093Shiremath 		} else {
13371093Shiremath 			ibnex_config_all_children(parent);
13382155Scth 
13392155Scth 			if (use_mdi_devi_locking)
13402155Scth 				mdi_devi_enter(parent, &circ);
13412155Scth 			else
13422155Scth 				ndi_devi_enter(parent, &circ);
13431093Shiremath 		}
13440Sstevel@tonic-gate 		break;
13450Sstevel@tonic-gate 	default:
13460Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tbus_config: error");
13470Sstevel@tonic-gate 		ret = IBNEX_FAILURE;
13480Sstevel@tonic-gate 		break;
13490Sstevel@tonic-gate 	}
13502155Scth 
13512155Scth 	if (use_mdi_devi_locking)
13522155Scth 		mdi_devi_exit(parent, circ);
13532155Scth 	else
13542155Scth 		ndi_devi_exit(parent, circ);
13552155Scth 
13560Sstevel@tonic-gate 	if (ret == IBNEX_SUCCESS) {
13570Sstevel@tonic-gate 		if (op == BUS_CONFIG_OBP_ARGS)
13580Sstevel@tonic-gate 			op = BUS_CONFIG_ONE;
13590Sstevel@tonic-gate 
13600Sstevel@tonic-gate 		if (pdip == NULL)
13610Sstevel@tonic-gate 			pdip = parent;
13620Sstevel@tonic-gate 
13630Sstevel@tonic-gate 		ret = ndi_busop_bus_config(
13640Sstevel@tonic-gate 		    pdip, flag, op, devname, child, 0);
13650Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tbus_config:"
13660Sstevel@tonic-gate 		    "ndi_busop_bus_config : retval %d", ret);
13670Sstevel@tonic-gate 		return (ret);
13680Sstevel@tonic-gate 	}
13690Sstevel@tonic-gate 
13700Sstevel@tonic-gate 	return (NDI_FAILURE);
13710Sstevel@tonic-gate }
13720Sstevel@tonic-gate 
13730Sstevel@tonic-gate 
13740Sstevel@tonic-gate /*
13750Sstevel@tonic-gate  * ibnex_config_root_iocnode()
13760Sstevel@tonic-gate  *	Configures one particular instance of the IOC driver.
13770Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
13780Sstevel@tonic-gate  */
13790Sstevel@tonic-gate static int
13800Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name)
13810Sstevel@tonic-gate {
13820Sstevel@tonic-gate 	int			ret, port = 0, iter = 0;
13830Sstevel@tonic-gate 	boolean_t		displayed = B_FALSE;
13840Sstevel@tonic-gate 	char			*portstr;
13850Sstevel@tonic-gate 	ib_guid_t		hca_guid, iou_guid, ioc_guid;
13860Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
13870Sstevel@tonic-gate 	ibdm_port_attr_t	*port_attr;
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
13900Sstevel@tonic-gate 	    "\tconfig_root_iocnode: name %s", device_name);
13910Sstevel@tonic-gate 
13920Sstevel@tonic-gate 	portstr = strstr(device_name, ":port=");
13930Sstevel@tonic-gate 	if (portstr == NULL) {
13940Sstevel@tonic-gate 		return (IBNEX_FAILURE);
13950Sstevel@tonic-gate 	}
13960Sstevel@tonic-gate 
13970Sstevel@tonic-gate 	portstr[0] = 0; portstr++;
13980Sstevel@tonic-gate 	if (ibnex_devname2port(portstr, &port)) {
13990Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port");
14000Sstevel@tonic-gate 		return (IBNEX_FAILURE);
14010Sstevel@tonic-gate 	}
14020Sstevel@tonic-gate 
14030Sstevel@tonic-gate 	if (ibnex_devname_to_node_n_ioc_guids(
14041093Shiremath 	    device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
14050Sstevel@tonic-gate 		return (IBNEX_FAILURE);
14060Sstevel@tonic-gate 	}
14070Sstevel@tonic-gate 
14080Sstevel@tonic-gate 	(void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4),
14090Sstevel@tonic-gate 	    "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid);
14100Sstevel@tonic-gate 
14110Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
14120Sstevel@tonic-gate 	if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) {
14130Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
14140Sstevel@tonic-gate 		    "\tconfig_root_iocnode: Port does not exist");
14150Sstevel@tonic-gate 		return (IBNEX_FAILURE);
14160Sstevel@tonic-gate 	}
14170Sstevel@tonic-gate 
14180Sstevel@tonic-gate 	/* Wait until "port is up" */
14190Sstevel@tonic-gate 	while (port_attr->pa_state != IBT_PORT_ACTIVE) {
14200Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
14210Sstevel@tonic-gate 		delay(drv_usectohz(10000));
14220Sstevel@tonic-gate 		if ((port_attr = ibdm_ibnex_probe_hcaport(
14230Sstevel@tonic-gate 		    hca_guid, port)) == NULL) {
14240Sstevel@tonic-gate 			return (IBNEX_FAILURE);
14250Sstevel@tonic-gate 		}
14260Sstevel@tonic-gate 
14270Sstevel@tonic-gate 		if (iter++ == 400) {
14280Sstevel@tonic-gate 			if (displayed == B_FALSE) {
14290Sstevel@tonic-gate 				cmn_err(CE_NOTE, "\tWaiting for Port %d "
14300Sstevel@tonic-gate 				    "initialization", port_attr->pa_port_num);
14310Sstevel@tonic-gate 				displayed = B_TRUE;
14320Sstevel@tonic-gate 			}
14330Sstevel@tonic-gate 		}
14340Sstevel@tonic-gate 	}
14350Sstevel@tonic-gate 	ibdm_ibnex_free_port_attr(port_attr);
14360Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:"
14370Sstevel@tonic-gate 	    "Port is initialized");
14380Sstevel@tonic-gate 
14390Sstevel@tonic-gate 	if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) {
14400Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc_info);
14410Sstevel@tonic-gate 		return (IBNEX_FAILURE);
14420Sstevel@tonic-gate 	}
14430Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
1444*8082SRamaswamy.Tummala@Sun.COM 	if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) !=
1445*8082SRamaswamy.Tummala@Sun.COM 	    IBNEX_SUCCESS) {
1446*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex",
1447*8082SRamaswamy.Tummala@Sun.COM 		    "\tconfig_root_ioc_node failed for pdip %p", parent);
1448*8082SRamaswamy.Tummala@Sun.COM 	}
14490Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
14500Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
14510Sstevel@tonic-gate 	return (ret);
14520Sstevel@tonic-gate }
14530Sstevel@tonic-gate 
14540Sstevel@tonic-gate 
14550Sstevel@tonic-gate static int
14560Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port)
14570Sstevel@tonic-gate {
14580Sstevel@tonic-gate 	char	*temp;
14590Sstevel@tonic-gate 	int	ret = IBNEX_FAILURE;
14600Sstevel@tonic-gate 
14610Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin");
14620Sstevel@tonic-gate 
14630Sstevel@tonic-gate 	temp = strchr(portstr, '=');
14640Sstevel@tonic-gate 	if (temp != NULL) {
14650Sstevel@tonic-gate 		temp++;
14660Sstevel@tonic-gate 		*port = ibnex_str2int(temp, strlen(temp), &ret);
14670Sstevel@tonic-gate 	}
14680Sstevel@tonic-gate 	return (ret);
14690Sstevel@tonic-gate }
14700Sstevel@tonic-gate 
14710Sstevel@tonic-gate 
14720Sstevel@tonic-gate /*
14730Sstevel@tonic-gate  * ibnex_config_all_children()
14740Sstevel@tonic-gate  *	Wait for lata SM initialization case before enumerating the nodes
14750Sstevel@tonic-gate  *	Get list of HCA's and HCA port information
14760Sstevel@tonic-gate  *		Create device device nodes and its node properties
14770Sstevel@tonic-gate  *		for port nodes and VPPA nodes
14780Sstevel@tonic-gate  *	Get list of all the IOC node information
14790Sstevel@tonic-gate  *		Create device nodes and its properties for all the IOCs
14800Sstevel@tonic-gate  *		if not created already
14810Sstevel@tonic-gate  *	Bind drivers for all the newly created device nodes
14820Sstevel@tonic-gate  *	Support Pseudo nodes enumerated using their .conf file
14830Sstevel@tonic-gate  */
14840Sstevel@tonic-gate static void
14850Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent)
14860Sstevel@tonic-gate {
14870Sstevel@tonic-gate 	int			ii;
1488*8082SRamaswamy.Tummala@Sun.COM 	ibdm_ioc_info_t		*ioc_list;
14890Sstevel@tonic-gate 	ibdm_hca_list_t		*hca_list;
14900Sstevel@tonic-gate 	ib_guid_t		hca_guid;
14912155Scth 	int			circ;
14920Sstevel@tonic-gate 
14930Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin");
14940Sstevel@tonic-gate 
14951093Shiremath 	/*
14961093Shiremath 	 * Enumerate children of this HCA, port nodes,
14972155Scth 	 * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for
14982155Scth 	 * locking. IB Nexus is enumerating the children
14992155Scth 	 * of HCA, not MPXIO clients.
15001093Shiremath 	 */
15012155Scth 	ndi_devi_enter(parent, &circ);
15021093Shiremath 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
1503*8082SRamaswamy.Tummala@Sun.COM 	ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time);
15041093Shiremath 	hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
15055470Spramodbg 	if (hca_list == NULL) {
15065470Spramodbg 		ndi_devi_exit(parent, circ);
15071093Shiremath 		return;
15085470Spramodbg 	}
15091093Shiremath 	ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr);
15101093Shiremath 	for (ii = 0; ii < hca_list->hl_nports; ii++) {
15111093Shiremath 		ibnex_create_port_nodes(
15121093Shiremath 		    parent, &hca_list->hl_port_attr[ii]);
15131093Shiremath 		ibnex_create_vppa_nodes(
15141093Shiremath 		    parent, &hca_list->hl_port_attr[ii]);
15151093Shiremath 	}
15161093Shiremath 	ibdm_ibnex_free_hca_list(hca_list);
15172155Scth 	ndi_devi_exit(parent, circ);
15182155Scth 
15192155Scth 	/*
15202155Scth 	 * Use mdi_devi_enter() for locking. IB Nexus is
15216601Seota 	 * enumerating MPxIO clients.
15222155Scth 	 */
15232155Scth 	mdi_devi_enter(parent, &circ);
15241093Shiremath 
15251093Shiremath 	ibnex_pseudo_initnodes();
15261093Shiremath 
1527*8082SRamaswamy.Tummala@Sun.COM 	ioc_list = ibnex.ibnex_ioc_list;
15281093Shiremath 
15291093Shiremath 	mutex_enter(&ibnex.ibnex_mutex);
15301093Shiremath 
15311093Shiremath 	while (ioc_list) {
1532*8082SRamaswamy.Tummala@Sun.COM 		(void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0);
15331093Shiremath 		ioc_list = ioc_list->ioc_next;
15340Sstevel@tonic-gate 	}
15351093Shiremath 
15361093Shiremath 	/* Config IBTF Pseudo clients */
15371093Shiremath 	ibnex_config_pseudo_all(parent);
15381093Shiremath 
15391093Shiremath 	mutex_exit(&ibnex.ibnex_mutex);
15402155Scth 	mdi_devi_exit(parent, circ);
15411093Shiremath 
15420Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End");
15430Sstevel@tonic-gate }
15440Sstevel@tonic-gate 
15450Sstevel@tonic-gate 
15460Sstevel@tonic-gate /*
15470Sstevel@tonic-gate  * ibnex_create_port_nodes:
15480Sstevel@tonic-gate  *	Creates a device node per each communication service defined
15490Sstevel@tonic-gate  *	in the "port-commsvc-list" property per HCA port
15500Sstevel@tonic-gate  */
15510Sstevel@tonic-gate static void
15520Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
15530Sstevel@tonic-gate {
15540Sstevel@tonic-gate 	int		idx;
15550Sstevel@tonic-gate 	dev_info_t	*dip;
15560Sstevel@tonic-gate 	int		rval;
15570Sstevel@tonic-gate 
15580Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
15590Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) {
15600Sstevel@tonic-gate 		rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
15610Sstevel@tonic-gate 		    idx, 0, &dip);
15620Sstevel@tonic-gate 		if (rval != IBNEX_SUCCESS) {
15630Sstevel@tonic-gate 			(void) ibnex_commsvc_initnode(parent, port_attr, idx,
15640Sstevel@tonic-gate 			    IBNEX_PORT_COMMSVC_NODE, 0, &rval,
15650Sstevel@tonic-gate 			    IBNEX_DEVFS_ENUMERATE);
15660Sstevel@tonic-gate 		}
15670Sstevel@tonic-gate 	}
15680Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
15690Sstevel@tonic-gate }
15700Sstevel@tonic-gate 
15710Sstevel@tonic-gate 
15720Sstevel@tonic-gate /*
15730Sstevel@tonic-gate  * ibnex_create_vppa_nodes:
15740Sstevel@tonic-gate  *	Creates a device node per each communication service defined
15750Sstevel@tonic-gate  *	in the "vppa-commsvc-list" property and per each PKEY that
15760Sstevel@tonic-gate  *	this particular port supports and per HCA port
15770Sstevel@tonic-gate  */
15780Sstevel@tonic-gate static void
15790Sstevel@tonic-gate ibnex_create_vppa_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
15800Sstevel@tonic-gate {
15810Sstevel@tonic-gate 	int 		idx, ii;
15820Sstevel@tonic-gate 	int		rval;
15830Sstevel@tonic-gate 	ib_pkey_t 	pkey;
15840Sstevel@tonic-gate 	dev_info_t	*dip;
15850Sstevel@tonic-gate 
15860Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin");
15870Sstevel@tonic-gate 
15880Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
15890Sstevel@tonic-gate 	if (port_attr->pa_state != IBT_PORT_ACTIVE) {
15900Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: "
15910Sstevel@tonic-gate 		    "Port %d is down", port_attr->pa_port_num);
15920Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
15930Sstevel@tonic-gate 		return;
15940Sstevel@tonic-gate 	}
15950Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) {
15960Sstevel@tonic-gate 		for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
15970Sstevel@tonic-gate 			pkey = port_attr->pa_pkey_tbl[ii].pt_pkey;
15980Sstevel@tonic-gate 
15990Sstevel@tonic-gate 			if (IBNEX_INVALID_PKEY(pkey)) {
16000Sstevel@tonic-gate 				continue;
16010Sstevel@tonic-gate 			}
16020Sstevel@tonic-gate 			rval = ibnex_get_dip_from_guid(
16030Sstevel@tonic-gate 			    port_attr->pa_port_guid, idx, pkey, &dip);
1604*8082SRamaswamy.Tummala@Sun.COM 			if ((rval != IBNEX_SUCCESS) || (dip == NULL)) {
16050Sstevel@tonic-gate 				(void) ibnex_commsvc_initnode(parent, port_attr,
16065470Spramodbg 				    idx, IBNEX_VPPA_COMMSVC_NODE,
16075470Spramodbg 				    pkey, &rval, IBNEX_CFGADM_ENUMERATE);
16080Sstevel@tonic-gate 				IBTF_DPRINTF_L5("ibnex", "\tcreate_vppa_nodes: "
16090Sstevel@tonic-gate 				    "commsvc_initnode failed rval %x", rval);
16100Sstevel@tonic-gate 			}
16110Sstevel@tonic-gate 		}
16120Sstevel@tonic-gate 	}
16130Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
16140Sstevel@tonic-gate }
16150Sstevel@tonic-gate 
16160Sstevel@tonic-gate 
16170Sstevel@tonic-gate /*
16180Sstevel@tonic-gate  * ibnex_create_hcasvc_nodes:
16190Sstevel@tonic-gate  *	Creates a device node per each communication service defined
16200Sstevel@tonic-gate  *	in the "port-commsvc-list" property per HCA port
16210Sstevel@tonic-gate  */
16220Sstevel@tonic-gate static void
16230Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
16240Sstevel@tonic-gate {
16250Sstevel@tonic-gate 	int		idx;
16260Sstevel@tonic-gate 	dev_info_t	*dip;
16270Sstevel@tonic-gate 	int		rval;
16280Sstevel@tonic-gate 
16290Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
16300Sstevel@tonic-gate 	for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) {
16310Sstevel@tonic-gate 		rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
16320Sstevel@tonic-gate 		    idx, 0, &dip);
16330Sstevel@tonic-gate 		if (rval != IBNEX_SUCCESS) {
16340Sstevel@tonic-gate 			(void) ibnex_commsvc_initnode(parent, port_attr, idx,
16350Sstevel@tonic-gate 			    IBNEX_HCASVC_COMMSVC_NODE, 0, &rval,
16360Sstevel@tonic-gate 			    IBNEX_DEVFS_ENUMERATE);
16370Sstevel@tonic-gate 			IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: "
16380Sstevel@tonic-gate 			    "commsvc_initnode failed, rval %x", rval);
16390Sstevel@tonic-gate 		}
16400Sstevel@tonic-gate 	}
16410Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
16420Sstevel@tonic-gate }
16430Sstevel@tonic-gate 
16440Sstevel@tonic-gate 
16450Sstevel@tonic-gate /*
16460Sstevel@tonic-gate  * ibnex_bus_unconfig()
16470Sstevel@tonic-gate  *
16480Sstevel@tonic-gate  *	Unconfigure a particular device node or all instance of a device
16490Sstevel@tonic-gate  *	driver device or all children of IBnex
16500Sstevel@tonic-gate  */
16510Sstevel@tonic-gate static int
16520Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent,
16530Sstevel@tonic-gate     uint_t flag, ddi_bus_config_op_t op, void *device_name)
16540Sstevel@tonic-gate {
1655*8082SRamaswamy.Tummala@Sun.COM 	ibnex_node_data_t	*ndp;
1656*8082SRamaswamy.Tummala@Sun.COM 	major_t			major = (major_t)(uintptr_t)device_name;
1657*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t		*dip = NULL;
1658*8082SRamaswamy.Tummala@Sun.COM 
1659*8082SRamaswamy.Tummala@Sun.COM 	if (ndi_busop_bus_unconfig(parent, flag, op, device_name) !=
1660*8082SRamaswamy.Tummala@Sun.COM 	    DDI_SUCCESS)
1661*8082SRamaswamy.Tummala@Sun.COM 		return (DDI_FAILURE);
1662*8082SRamaswamy.Tummala@Sun.COM 
1663*8082SRamaswamy.Tummala@Sun.COM 	/*
1664*8082SRamaswamy.Tummala@Sun.COM 	 * We can come into this routine with dip as ibnexus dip or hca dip.
1665*8082SRamaswamy.Tummala@Sun.COM 	 * When the dip is that of ib nexus we need to clean up the IOC and
1666*8082SRamaswamy.Tummala@Sun.COM 	 * pseudo nodes. When the dip is that of an HCA (not IB nexus dip)
1667*8082SRamaswamy.Tummala@Sun.COM 	 * cleanup the port nodes.
1668*8082SRamaswamy.Tummala@Sun.COM 	 */
1669*8082SRamaswamy.Tummala@Sun.COM 	if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) &&
1670*8082SRamaswamy.Tummala@Sun.COM 	    (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) {
1671*8082SRamaswamy.Tummala@Sun.COM 		mutex_enter(&ibnex.ibnex_mutex);
1672*8082SRamaswamy.Tummala@Sun.COM 		if (parent != ibnex.ibnex_dip) {
1673*8082SRamaswamy.Tummala@Sun.COM 			if (major == -1) {
1674*8082SRamaswamy.Tummala@Sun.COM 				/*
1675*8082SRamaswamy.Tummala@Sun.COM 				 * HCA dip. When major number is -1 HCA is
1676*8082SRamaswamy.Tummala@Sun.COM 				 * going away cleanup all the port nodes.
1677*8082SRamaswamy.Tummala@Sun.COM 				 */
1678*8082SRamaswamy.Tummala@Sun.COM 				for (ndp = ibnex.ibnex_port_node_head;
1679*8082SRamaswamy.Tummala@Sun.COM 				    ndp; ndp = ndp->node_next) {
1680*8082SRamaswamy.Tummala@Sun.COM 					ibnex_port_node_t	*port_node;
1681*8082SRamaswamy.Tummala@Sun.COM 
1682*8082SRamaswamy.Tummala@Sun.COM 					port_node = &ndp->node_data.port_node;
1683*8082SRamaswamy.Tummala@Sun.COM 					if (port_node->port_pdip == parent) {
1684*8082SRamaswamy.Tummala@Sun.COM 						port_node->port_pdip = NULL;
1685*8082SRamaswamy.Tummala@Sun.COM 						ndp->node_dip = NULL;
1686*8082SRamaswamy.Tummala@Sun.COM 						ndp->node_state =
1687*8082SRamaswamy.Tummala@Sun.COM 						    IBNEX_CFGADM_UNCONFIGURED;
1688*8082SRamaswamy.Tummala@Sun.COM 					}
1689*8082SRamaswamy.Tummala@Sun.COM 				}
1690*8082SRamaswamy.Tummala@Sun.COM 			} else {
1691*8082SRamaswamy.Tummala@Sun.COM 				/*
1692*8082SRamaswamy.Tummala@Sun.COM 				 * HCA dip. Cleanup only the port nodes that
1693*8082SRamaswamy.Tummala@Sun.COM 				 * match the major number.
1694*8082SRamaswamy.Tummala@Sun.COM 				 */
1695*8082SRamaswamy.Tummala@Sun.COM 				for (ndp = ibnex.ibnex_port_node_head;
1696*8082SRamaswamy.Tummala@Sun.COM 				    ndp; ndp = ndp->node_next) {
1697*8082SRamaswamy.Tummala@Sun.COM 					ibnex_port_node_t	*port_node;
1698*8082SRamaswamy.Tummala@Sun.COM 
1699*8082SRamaswamy.Tummala@Sun.COM 					port_node = &ndp->node_data.port_node;
1700*8082SRamaswamy.Tummala@Sun.COM 					dip = ndp->node_dip;
1701*8082SRamaswamy.Tummala@Sun.COM 					if (dip && (ddi_driver_major(dip) ==
1702*8082SRamaswamy.Tummala@Sun.COM 					    major) && port_node->port_pdip ==
1703*8082SRamaswamy.Tummala@Sun.COM 					    parent) {
1704*8082SRamaswamy.Tummala@Sun.COM 						port_node->port_pdip = NULL;
1705*8082SRamaswamy.Tummala@Sun.COM 						ndp->node_dip = NULL;
1706*8082SRamaswamy.Tummala@Sun.COM 						ndp->node_state =
1707*8082SRamaswamy.Tummala@Sun.COM 						    IBNEX_CFGADM_UNCONFIGURED;
1708*8082SRamaswamy.Tummala@Sun.COM 					}
1709*8082SRamaswamy.Tummala@Sun.COM 				}
1710*8082SRamaswamy.Tummala@Sun.COM 			}
1711*8082SRamaswamy.Tummala@Sun.COM 		} else {
1712*8082SRamaswamy.Tummala@Sun.COM 			/*
1713*8082SRamaswamy.Tummala@Sun.COM 			 * IB dip. here we handle IOC and pseudo nodes which
1714*8082SRamaswamy.Tummala@Sun.COM 			 * are the children of IB nexus. Cleanup only the nodes
1715*8082SRamaswamy.Tummala@Sun.COM 			 * with matching major number. We also need to cleanup
1716*8082SRamaswamy.Tummala@Sun.COM 			 * the PathInfo links to the PHCI here.
1717*8082SRamaswamy.Tummala@Sun.COM 			 */
1718*8082SRamaswamy.Tummala@Sun.COM 			for (ndp = ibnex.ibnex_ioc_node_head;
1719*8082SRamaswamy.Tummala@Sun.COM 			    ndp; ndp = ndp->node_next) {
1720*8082SRamaswamy.Tummala@Sun.COM 				dip = ndp->node_dip;
1721*8082SRamaswamy.Tummala@Sun.COM 				if (dip && (ddi_driver_major(dip) == major)) {
1722*8082SRamaswamy.Tummala@Sun.COM 					ibnex_offline_childdip(dip);
1723*8082SRamaswamy.Tummala@Sun.COM 				}
1724*8082SRamaswamy.Tummala@Sun.COM 			}
1725*8082SRamaswamy.Tummala@Sun.COM 			for (ndp = ibnex.ibnex_pseudo_node_head;
1726*8082SRamaswamy.Tummala@Sun.COM 			    ndp; ndp = ndp->node_next) {
1727*8082SRamaswamy.Tummala@Sun.COM 				dip = ndp->node_dip;
1728*8082SRamaswamy.Tummala@Sun.COM 				if (dip && (ddi_driver_major(dip) == major)) {
1729*8082SRamaswamy.Tummala@Sun.COM 					ibnex_offline_childdip(dip);
1730*8082SRamaswamy.Tummala@Sun.COM 				}
1731*8082SRamaswamy.Tummala@Sun.COM 			}
1732*8082SRamaswamy.Tummala@Sun.COM 		}
1733*8082SRamaswamy.Tummala@Sun.COM 		mutex_exit(&ibnex.ibnex_mutex);
1734*8082SRamaswamy.Tummala@Sun.COM 	}
1735*8082SRamaswamy.Tummala@Sun.COM 	return (DDI_SUCCESS);
17360Sstevel@tonic-gate }
17370Sstevel@tonic-gate 
17380Sstevel@tonic-gate 
17390Sstevel@tonic-gate /*
17400Sstevel@tonic-gate  * ibnex_config_port_node()
17410Sstevel@tonic-gate  *
17420Sstevel@tonic-gate  *	Configures a particular port / HCA  node for a particular
17430Sstevel@tonic-gate  *	communication service.
17440Sstevel@tonic-gate  *	The format of the device_name is
17450Sstevel@tonic-gate  *		ibport@<Port#>,<pkey>,<service name>
17460Sstevel@tonic-gate  *	where pkey = 0 for port communication service nodes
17470Sstevel@tonic-gate  *		  Port# = 0 for HCA_SVC communication service nodes
17480Sstevel@tonic-gate  *	Returns "dev_info_t" of the "child" node just created
17490Sstevel@tonic-gate  *	NULL when failed to enumerate the child node
17500Sstevel@tonic-gate  */
17510Sstevel@tonic-gate static dev_info_t *
17520Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname)
17530Sstevel@tonic-gate {
17540Sstevel@tonic-gate 	int			ii, index;
17550Sstevel@tonic-gate 	int			rval;
17560Sstevel@tonic-gate 	uint8_t			port_num;
17570Sstevel@tonic-gate 	ib_guid_t		hca_guid, port_guid;
17580Sstevel@tonic-gate 	ib_pkey_t		pkey;
17590Sstevel@tonic-gate 	dev_info_t		*cdip;
17600Sstevel@tonic-gate 	ibdm_port_attr_t	*port_attr;
17610Sstevel@tonic-gate 	ibdm_hca_list_t		*hca_list;
17620Sstevel@tonic-gate 
17630Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname);
17640Sstevel@tonic-gate 
17650Sstevel@tonic-gate 	if (ibnex_get_pkey_commsvc_index_portnum(devname,
17660Sstevel@tonic-gate 	    &index, &pkey, &port_num) != IBNEX_SUCCESS) {
17670Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
17680Sstevel@tonic-gate 		    "\tconfig_port_node: Invalid Service Name");
17690Sstevel@tonic-gate 		return (NULL);
17700Sstevel@tonic-gate 	}
17710Sstevel@tonic-gate 
17720Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
17730Sstevel@tonic-gate 	if (port_num == 0) {
17740Sstevel@tonic-gate 		/*
17750Sstevel@tonic-gate 		 * Use the dummy port attribute for HCA node in hca_list
17760Sstevel@tonic-gate 		 * Note : pa_state is always IBT_PORT_ACTIVE.
17770Sstevel@tonic-gate 		 */
17780Sstevel@tonic-gate 		hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
17790Sstevel@tonic-gate 		ASSERT(hca_list != NULL);
17800Sstevel@tonic-gate 		port_attr = hca_list->hl_hca_port_attr;
17810Sstevel@tonic-gate 	} else {
17820Sstevel@tonic-gate 		if ((port_attr = ibdm_ibnex_probe_hcaport(
17830Sstevel@tonic-gate 		    hca_guid, port_num)) == NULL) {
17840Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
17850Sstevel@tonic-gate 			    "\tconfig_port_node: Port does not exist");
17860Sstevel@tonic-gate 			return (NULL);
17870Sstevel@tonic-gate 		}
17880Sstevel@tonic-gate 
17890Sstevel@tonic-gate 		if (port_attr->pa_state != IBT_PORT_ACTIVE) {
1790*8082SRamaswamy.Tummala@Sun.COM 			ibdm_ibnex_port_settle_wait(
1791*8082SRamaswamy.Tummala@Sun.COM 			    hca_guid, ibnex_port_settling_time);
17920Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
17930Sstevel@tonic-gate 			if ((port_attr = ibdm_ibnex_probe_hcaport(
17940Sstevel@tonic-gate 			    hca_guid, port_num)) == NULL) {
17950Sstevel@tonic-gate 				return (NULL);
17960Sstevel@tonic-gate 			}
17970Sstevel@tonic-gate 		}
17980Sstevel@tonic-gate 	}
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 	port_guid = port_attr->pa_port_guid;
18010Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
18020Sstevel@tonic-gate 	if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey,
18030Sstevel@tonic-gate 	    &cdip)) == IBNEX_SUCCESS) {
18040Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists");
18050Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
18060Sstevel@tonic-gate 		if (port_num != 0)
18070Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
18080Sstevel@tonic-gate 		else
18090Sstevel@tonic-gate 			ibdm_ibnex_free_hca_list(hca_list);
18100Sstevel@tonic-gate 		return (cdip);
18110Sstevel@tonic-gate 	}
18120Sstevel@tonic-gate 
18130Sstevel@tonic-gate 	if (pkey == 0 && port_num != 0) {
18140Sstevel@tonic-gate 		cdip = ibnex_commsvc_initnode(parent,
18150Sstevel@tonic-gate 		    port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval,
18160Sstevel@tonic-gate 		    IBNEX_DEVFS_ENUMERATE);
18170Sstevel@tonic-gate 		IBTF_DPRINTF_L5("ibnex",
18180Sstevel@tonic-gate 		    "\t ibnex_commsvc_initnode rval %x", rval);
18190Sstevel@tonic-gate 	} else if (pkey == 0 && port_num == 0) {
18200Sstevel@tonic-gate 		cdip = ibnex_commsvc_initnode(parent,
18210Sstevel@tonic-gate 		    port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval,
18220Sstevel@tonic-gate 		    IBNEX_DEVFS_ENUMERATE);
18230Sstevel@tonic-gate 		IBTF_DPRINTF_L5("ibnex",
18240Sstevel@tonic-gate 		    "\t ibnex_commsvc_initnode rval %x", rval);
18250Sstevel@tonic-gate 	} else {
18260Sstevel@tonic-gate 		if (port_attr->pa_state != IBT_PORT_ACTIVE) {
18270Sstevel@tonic-gate 			IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: "
18280Sstevel@tonic-gate 			    "Port %d is down", port_attr->pa_port_num);
18290Sstevel@tonic-gate 			ibdm_ibnex_free_port_attr(port_attr);
18300Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
18310Sstevel@tonic-gate 			return (NULL);
18320Sstevel@tonic-gate 		}
18330Sstevel@tonic-gate 		for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
18340Sstevel@tonic-gate 			if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) {
18350Sstevel@tonic-gate 				cdip = ibnex_commsvc_initnode(parent, port_attr,
18360Sstevel@tonic-gate 				    index, IBNEX_VPPA_COMMSVC_NODE,
18370Sstevel@tonic-gate 				    pkey, &rval, IBNEX_CFGADM_ENUMERATE);
18380Sstevel@tonic-gate 				IBTF_DPRINTF_L5("ibnex",
18390Sstevel@tonic-gate 				    "\t ibnex_commsvc_initnode rval %x", rval);
18400Sstevel@tonic-gate 				break;
18410Sstevel@tonic-gate 			}
18420Sstevel@tonic-gate 		}
18430Sstevel@tonic-gate 	}
18440Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
18450Sstevel@tonic-gate 	if (port_num != 0)
18460Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
18470Sstevel@tonic-gate 	else
18480Sstevel@tonic-gate 		ibdm_ibnex_free_hca_list(hca_list);
18490Sstevel@tonic-gate 	return (cdip);
18500Sstevel@tonic-gate }
18510Sstevel@tonic-gate 
18520Sstevel@tonic-gate 
18530Sstevel@tonic-gate /*
18540Sstevel@tonic-gate  * ibnex_config_obp_args()
18550Sstevel@tonic-gate  *	Configures a particular port node for a IP over IB communication
18560Sstevel@tonic-gate  *	service.
18570Sstevel@tonic-gate  *	The format of the input string "devname" is
18580Sstevel@tonic-gate  *		port=x,pkey=y,protocol=ip,<wanboot options>
18590Sstevel@tonic-gate  *	Thr format of the node name created here is
18600Sstevel@tonic-gate  *		ibport@<Port#>,<pkey>,<service name>
18610Sstevel@tonic-gate  *	where pkey = 0 for port communication service nodes
18620Sstevel@tonic-gate  *	Returns "dev_info_t" of the "child" node just created
18630Sstevel@tonic-gate  *	NULL when failed to enumerate the child node
18640Sstevel@tonic-gate  *
18650Sstevel@tonic-gate  */
18660Sstevel@tonic-gate static dev_info_t *
18670Sstevel@tonic-gate ibnex_config_obp_args(dev_info_t *parent, char *devname)
18680Sstevel@tonic-gate {
18690Sstevel@tonic-gate 	int			ii, index;
18700Sstevel@tonic-gate 	int			rval, iter = 0;
18710Sstevel@tonic-gate 	char			*temp;
18720Sstevel@tonic-gate 	uint8_t			port_num;
18730Sstevel@tonic-gate 	ib_guid_t		hca_guid, port_guid;
18740Sstevel@tonic-gate 	ib_pkey_t		pkey;
18750Sstevel@tonic-gate 	dev_info_t		*cdip;
18760Sstevel@tonic-gate 	boolean_t		displayed = B_FALSE;
18770Sstevel@tonic-gate 	ibdm_port_attr_t	*port_attr;
18780Sstevel@tonic-gate 
18790Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_obp_args: %s", devname);
18800Sstevel@tonic-gate 
18810Sstevel@tonic-gate 	/* Is this OBP node for IPoIB ? */
18820Sstevel@tonic-gate 	temp = devname;
18830Sstevel@tonic-gate 	do {
18840Sstevel@tonic-gate 		temp = strstr(temp, ",protocol=ip");
18850Sstevel@tonic-gate 		if (temp == NULL)
18860Sstevel@tonic-gate 			break;
18870Sstevel@tonic-gate 
18880Sstevel@tonic-gate 		if (strlen(devname) > (int)((temp - devname) + 12)) {
18890Sstevel@tonic-gate 			if (temp[12] == ',')
18900Sstevel@tonic-gate 				break;
18910Sstevel@tonic-gate 		} else {
18920Sstevel@tonic-gate 			break;
18930Sstevel@tonic-gate 		}
18940Sstevel@tonic-gate 		temp++;
18950Sstevel@tonic-gate 	} while (temp);
18960Sstevel@tonic-gate 
18970Sstevel@tonic-gate 	if (temp == NULL)
18980Sstevel@tonic-gate 		return (NULL);
18990Sstevel@tonic-gate 	if (ibnex_prom_devname_to_pkey_n_portnum(
19000Sstevel@tonic-gate 	    devname, &pkey, &port_num) != IBNEX_SUCCESS) {
19010Sstevel@tonic-gate 		return (NULL);
19020Sstevel@tonic-gate 	}
19030Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) {
19040Sstevel@tonic-gate 		if (strcmp(ibnex.ibnex_vppa_comm_svc_names[index],
19055470Spramodbg 		    "ipib") == 0) {
19060Sstevel@tonic-gate 			break;
19070Sstevel@tonic-gate 		}
19080Sstevel@tonic-gate 	}
19090Sstevel@tonic-gate 
19100Sstevel@tonic-gate 	hca_guid = ibtl_ibnex_hcadip2guid(parent);
19110Sstevel@tonic-gate 	if ((port_attr = ibdm_ibnex_probe_hcaport(
19120Sstevel@tonic-gate 	    hca_guid, port_num)) == NULL) {
19130Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
19140Sstevel@tonic-gate 		    "\tconfig_port_node: Port does not exist");
19150Sstevel@tonic-gate 		return (NULL);
19160Sstevel@tonic-gate 	}
19170Sstevel@tonic-gate 
19180Sstevel@tonic-gate 	/* Wait until "port is up" */
19190Sstevel@tonic-gate 	while (port_attr->pa_state != IBT_PORT_ACTIVE) {
19200Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
19210Sstevel@tonic-gate 		delay(drv_usectohz(10000));
19220Sstevel@tonic-gate 		if ((port_attr = ibdm_ibnex_probe_hcaport(
19230Sstevel@tonic-gate 		    hca_guid, port_num)) == NULL) {
19240Sstevel@tonic-gate 			return (NULL);
19250Sstevel@tonic-gate 		}
19260Sstevel@tonic-gate 		if (iter++ == 400) {
19270Sstevel@tonic-gate 			if (displayed == B_FALSE) {
19280Sstevel@tonic-gate 				cmn_err(CE_NOTE, "\tWaiting for Port %d "
19290Sstevel@tonic-gate 				    "initialization", port_attr->pa_port_num);
19300Sstevel@tonic-gate 				displayed = B_TRUE;
19310Sstevel@tonic-gate 			}
19320Sstevel@tonic-gate 		}
19330Sstevel@tonic-gate 	}
19340Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tPort is initialized");
19350Sstevel@tonic-gate 
19360Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
19370Sstevel@tonic-gate 	port_guid = port_attr->pa_port_guid;
19380Sstevel@tonic-gate 	if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey,
19390Sstevel@tonic-gate 	    &cdip)) == IBNEX_SUCCESS) {
19400Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists");
19410Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
19420Sstevel@tonic-gate 		ibdm_ibnex_free_port_attr(port_attr);
19430Sstevel@tonic-gate 		return (cdip);
19440Sstevel@tonic-gate 	}
19450Sstevel@tonic-gate 	for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
19460Sstevel@tonic-gate 		if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) {
19470Sstevel@tonic-gate 			cdip = ibnex_commsvc_initnode(parent, port_attr,
19480Sstevel@tonic-gate 			    index, IBNEX_VPPA_COMMSVC_NODE, pkey, &rval,
19490Sstevel@tonic-gate 			    IBNEX_CFGADM_ENUMERATE);
19500Sstevel@tonic-gate 			IBTF_DPRINTF_L5("ibnex",
19510Sstevel@tonic-gate 			    "\t ibnex_commsvc_initnode rval %x", rval);
19520Sstevel@tonic-gate 			break;
19530Sstevel@tonic-gate 		}
19540Sstevel@tonic-gate 	}
19550Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
19560Sstevel@tonic-gate 
19570Sstevel@tonic-gate 	ibdm_ibnex_free_port_attr(port_attr);
19580Sstevel@tonic-gate 	return (cdip);
19590Sstevel@tonic-gate }
19600Sstevel@tonic-gate 
19610Sstevel@tonic-gate 
19620Sstevel@tonic-gate /*
19630Sstevel@tonic-gate  * ibnex_prom_devname_to_pkey_n_portnum()
19640Sstevel@tonic-gate  *	Parses the device node name and extracts "PKEY" and "port#"
19650Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
19660Sstevel@tonic-gate  */
19670Sstevel@tonic-gate static int
19680Sstevel@tonic-gate ibnex_prom_devname_to_pkey_n_portnum(
19690Sstevel@tonic-gate     char *devname, ib_pkey_t *pkey, uint8_t *port)
19700Sstevel@tonic-gate {
19710Sstevel@tonic-gate 	int	ret = IBNEX_SUCCESS;
19720Sstevel@tonic-gate 	char	*tmp, *tmp1;
19730Sstevel@tonic-gate 
19740Sstevel@tonic-gate 	if ((tmp = strstr(devname, "port=")) != NULL) {
19750Sstevel@tonic-gate 		if ((tmp = strchr(++tmp, '=')) != NULL)
19760Sstevel@tonic-gate 			if ((tmp1 = strchr(++tmp, ',')) != NULL)
19770Sstevel@tonic-gate 				*port = ibnex_str2int(tmp, (tmp1 - tmp), &ret);
19780Sstevel@tonic-gate 	} else
19790Sstevel@tonic-gate 		ret = IBNEX_FAILURE;
19800Sstevel@tonic-gate 
19810Sstevel@tonic-gate 	if ((ret == IBNEX_SUCCESS) &&
19820Sstevel@tonic-gate 	    (tmp = strstr(devname, "pkey=")) != NULL) {
19830Sstevel@tonic-gate 		if ((tmp = strchr(++tmp, '=')) != NULL)
19840Sstevel@tonic-gate 			if ((tmp1 = strchr(++tmp, ',')) != NULL)
19850Sstevel@tonic-gate 				*pkey = ibnex_str2hex(tmp, (tmp1 - tmp), &ret);
19860Sstevel@tonic-gate 	} else
19870Sstevel@tonic-gate 		ret = IBNEX_FAILURE;
19880Sstevel@tonic-gate 
19890Sstevel@tonic-gate 	return (ret);
19900Sstevel@tonic-gate }
19910Sstevel@tonic-gate 
19920Sstevel@tonic-gate 
19930Sstevel@tonic-gate /*
19940Sstevel@tonic-gate  * ibnex_get_pkey_commsvc_index_portnum()
19950Sstevel@tonic-gate  *	Parses the device node name and extracts PKEY, communication
19960Sstevel@tonic-gate  *	service index & Port #.
19970Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
19980Sstevel@tonic-gate  */
19990Sstevel@tonic-gate static int
20000Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index,
20010Sstevel@tonic-gate     ib_pkey_t *pkey, uint8_t *port_num)
20020Sstevel@tonic-gate {
20030Sstevel@tonic-gate 	char 	*srv, **service_name, *temp;
20040Sstevel@tonic-gate 	int  	ii, ncommsvcs, ret;
20050Sstevel@tonic-gate 
20060Sstevel@tonic-gate 	if (ibnex_devname_to_portnum(device_name, port_num) !=
20075470Spramodbg 	    IBNEX_SUCCESS) {
20080Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
20090Sstevel@tonic-gate 		    "\tget_pkey_commsvc_index_portnum: Invalid PortGuid");
20100Sstevel@tonic-gate 		return (NULL);
20110Sstevel@tonic-gate 	}
20120Sstevel@tonic-gate 	srv = strchr(device_name, ',');
20130Sstevel@tonic-gate 	if (srv == 0)
20140Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20150Sstevel@tonic-gate 
20160Sstevel@tonic-gate 	srv++;
20170Sstevel@tonic-gate 	temp = strchr(srv, ',');
20180Sstevel@tonic-gate 	if (temp == 0)
20190Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20200Sstevel@tonic-gate 	temp++;
20210Sstevel@tonic-gate 	*pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret);
20220Sstevel@tonic-gate 	if (ret != IBNEX_SUCCESS)
20230Sstevel@tonic-gate 		return (ret);
20240Sstevel@tonic-gate 
20250Sstevel@tonic-gate 	if (*pkey == 0 && *port_num != 0) {
20260Sstevel@tonic-gate 		service_name = ibnex.ibnex_comm_svc_names;
20270Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_num_comm_svcs;
20280Sstevel@tonic-gate 	} else if (*pkey == 0 && *port_num == 0) {
20290Sstevel@tonic-gate 		service_name = ibnex.ibnex_hcasvc_comm_svc_names;
20300Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs;
20310Sstevel@tonic-gate 	} else {
20320Sstevel@tonic-gate 		service_name = ibnex.ibnex_vppa_comm_svc_names;
20330Sstevel@tonic-gate 		ncommsvcs = ibnex.ibnex_nvppa_comm_svcs;
20340Sstevel@tonic-gate 	}
20350Sstevel@tonic-gate 
20360Sstevel@tonic-gate 	for (ii = 0; ii < ncommsvcs; ii++) {
20370Sstevel@tonic-gate 		if (strcmp(service_name[ii], temp) == 0) {
20380Sstevel@tonic-gate 			break;
20390Sstevel@tonic-gate 		}
20400Sstevel@tonic-gate 	}
20410Sstevel@tonic-gate 	if (ii == ncommsvcs)
20420Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20430Sstevel@tonic-gate 
20440Sstevel@tonic-gate 	*index = ii;
20450Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
20460Sstevel@tonic-gate }
20470Sstevel@tonic-gate 
20480Sstevel@tonic-gate 
20490Sstevel@tonic-gate /*
20500Sstevel@tonic-gate  * ibnex_devname_to_portnum()
20510Sstevel@tonic-gate  *	Get portguid from device name
20520Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
20530Sstevel@tonic-gate  */
20540Sstevel@tonic-gate static int
20550Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum)
20560Sstevel@tonic-gate {
20570Sstevel@tonic-gate 	int	ret;
20580Sstevel@tonic-gate 	char	*temp1, *temp2;
20590Sstevel@tonic-gate 
20600Sstevel@tonic-gate 	temp1 = strchr(device_name, '@');
20610Sstevel@tonic-gate 	if (temp1 == NULL) {
20620Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20630Sstevel@tonic-gate 	}
20640Sstevel@tonic-gate 	temp2 = strchr(temp1, ',');
20650Sstevel@tonic-gate 	if (temp2 == NULL)
20660Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20670Sstevel@tonic-gate 	temp1++;
20680Sstevel@tonic-gate 	*portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret);
20690Sstevel@tonic-gate 	return (ret);
20700Sstevel@tonic-gate }
20710Sstevel@tonic-gate 
20720Sstevel@tonic-gate 
20730Sstevel@tonic-gate /*
20740Sstevel@tonic-gate  * ibnex_config_ioc_node()
20750Sstevel@tonic-gate  *	Configures one particular instance of the IOC driver.
20760Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
20770Sstevel@tonic-gate  */
20780Sstevel@tonic-gate static int
20791093Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip)
20800Sstevel@tonic-gate {
20810Sstevel@tonic-gate 	int			ret;
20820Sstevel@tonic-gate 	ib_guid_t		iou_guid, ioc_guid;
20830Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
20840Sstevel@tonic-gate 
20850Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin");
20860Sstevel@tonic-gate 
20870Sstevel@tonic-gate 	if (ibnex_devname_to_node_n_ioc_guids(
20881093Shiremath 	    device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
20890Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20900Sstevel@tonic-gate 	}
20910Sstevel@tonic-gate 
2092*8082SRamaswamy.Tummala@Sun.COM 	ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
20930Sstevel@tonic-gate 
20940Sstevel@tonic-gate 	if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) ==
20950Sstevel@tonic-gate 	    NULL) {
20960Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc_info);
20970Sstevel@tonic-gate 		return (IBNEX_FAILURE);
20980Sstevel@tonic-gate 	}
20990Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
2100*8082SRamaswamy.Tummala@Sun.COM 	ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0);
21010Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
21020Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
2103*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x",
2104*8082SRamaswamy.Tummala@Sun.COM 	    ret);
21050Sstevel@tonic-gate 	return (ret);
21060Sstevel@tonic-gate }
21070Sstevel@tonic-gate 
21080Sstevel@tonic-gate 
21090Sstevel@tonic-gate /*
21100Sstevel@tonic-gate  * ibnex_devname_to_node_n_ioc_guids()
21110Sstevel@tonic-gate  *	Get node guid and ioc guid from the device name
21120Sstevel@tonic-gate  *	Format of the device node name is:
21130Sstevel@tonic-gate  *		ioc@<IOC GUID>,<IOU GUID>
21140Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
21150Sstevel@tonic-gate  */
21160Sstevel@tonic-gate static int
21170Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids(
21181093Shiremath     char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid,
21191093Shiremath     char **ioc_guid_strp)
21200Sstevel@tonic-gate {
21210Sstevel@tonic-gate 	char	*temp1, *temp;
21220Sstevel@tonic-gate 	int	len, ret;
21231093Shiremath 	char	*ioc_guid_str;
21240Sstevel@tonic-gate 
21250Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:"
21260Sstevel@tonic-gate 	    "Device Name %s", device_name);
21270Sstevel@tonic-gate 
21280Sstevel@tonic-gate 	if ((temp = strchr(device_name, '@')) == NULL) {
21290Sstevel@tonic-gate 		return (IBNEX_FAILURE);
21300Sstevel@tonic-gate 	}
21310Sstevel@tonic-gate 	if ((temp1 = strchr(++temp, ',')) == NULL) {
21320Sstevel@tonic-gate 		return (IBNEX_FAILURE);
21330Sstevel@tonic-gate 	}
21340Sstevel@tonic-gate 	*ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret);
21350Sstevel@tonic-gate 	if (ret == IBNEX_SUCCESS) {
21361093Shiremath 		if (ioc_guid_strp) {
21371093Shiremath 			ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1
21381093Shiremath 			    - temp) + 1, KM_SLEEP);
21391093Shiremath 			(void) strncpy(ioc_guid_str, temp, temp1 - temp + 1);
21401093Shiremath 			ioc_guid_str[temp1 - temp] = '\0';
21411093Shiremath 		}
21420Sstevel@tonic-gate 		len = device_name + strlen(device_name) - ++temp1;
21430Sstevel@tonic-gate 		*iou_guid = ibnex_str2hex(temp1, len, &ret);
21440Sstevel@tonic-gate 	}
21450Sstevel@tonic-gate 	return (ret);
21460Sstevel@tonic-gate }
21470Sstevel@tonic-gate 
21480Sstevel@tonic-gate 
21490Sstevel@tonic-gate /*
21500Sstevel@tonic-gate  * ibnex_ioc_initnode()
21510Sstevel@tonic-gate  *	Allocate a pathinfo node for the IOC
21520Sstevel@tonic-gate  *	Initialize the device node
21530Sstevel@tonic-gate  *	Bind driver to the node
21540Sstevel@tonic-gate  *	Update IBnex global data
21550Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY
21560Sstevel@tonic-gate  */
2157*8082SRamaswamy.Tummala@Sun.COM static int
2158*8082SRamaswamy.Tummala@Sun.COM ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data,
2159*8082SRamaswamy.Tummala@Sun.COM     ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
21600Sstevel@tonic-gate {
2161*8082SRamaswamy.Tummala@Sun.COM 	int			rval, node_valid;
2162*8082SRamaswamy.Tummala@Sun.COM 	ibnex_node_state_t	prev_state;
21630Sstevel@tonic-gate 
21640Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
2165*8082SRamaswamy.Tummala@Sun.COM 	ASSERT(node_data);
2166*8082SRamaswamy.Tummala@Sun.COM 
21670Sstevel@tonic-gate 
21680Sstevel@tonic-gate 	/*
21690Sstevel@tonic-gate 	 * Return EBUSY if another configure/unconfigure
21700Sstevel@tonic-gate 	 * operation is in progress
21710Sstevel@tonic-gate 	 */
21720Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
2173*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2174*8082SRamaswamy.Tummala@Sun.COM 		    "\tioc_initnode_pdip : BUSY");
21750Sstevel@tonic-gate 		return (IBNEX_BUSY);
21760Sstevel@tonic-gate 	}
21770Sstevel@tonic-gate 
2178*8082SRamaswamy.Tummala@Sun.COM 	prev_state = node_data->node_state;
21790Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
21800Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
21810Sstevel@tonic-gate 
2182*8082SRamaswamy.Tummala@Sun.COM 	rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid);
21830Sstevel@tonic-gate 
21840Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
21850Sstevel@tonic-gate 	if (rval == IBNEX_SUCCESS)
21860Sstevel@tonic-gate 		node_data->node_state = IBNEX_CFGADM_CONFIGURED;
2187*8082SRamaswamy.Tummala@Sun.COM 	else if (node_valid)
2188*8082SRamaswamy.Tummala@Sun.COM 		node_data->node_state = prev_state;
21890Sstevel@tonic-gate 
21900Sstevel@tonic-gate 	return (rval);
21910Sstevel@tonic-gate }
21920Sstevel@tonic-gate 
21930Sstevel@tonic-gate /*
21940Sstevel@tonic-gate  * ibnex_config_pseudo_all()
21950Sstevel@tonic-gate  *	Configure all the pseudo nodes
21960Sstevel@tonic-gate  */
21970Sstevel@tonic-gate static void
21981093Shiremath ibnex_config_pseudo_all(dev_info_t *pdip)
21990Sstevel@tonic-gate {
22000Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
22010Sstevel@tonic-gate 
22020Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
22030Sstevel@tonic-gate 
22040Sstevel@tonic-gate 	for (nodep = ibnex.ibnex_pseudo_node_head;
22050Sstevel@tonic-gate 	    nodep; nodep = nodep->node_next) {
22061689Spramodbg 		(void) ibnex_pseudo_config_one(nodep, NULL, pdip);
22070Sstevel@tonic-gate 	}
22080Sstevel@tonic-gate }
22090Sstevel@tonic-gate 
22100Sstevel@tonic-gate 
22110Sstevel@tonic-gate /*
22120Sstevel@tonic-gate  * ibnex_pseudo_config_one()
22130Sstevel@tonic-gate  */
22141689Spramodbg static int
22151689Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr,
22161093Shiremath     dev_info_t *pdip)
22170Sstevel@tonic-gate {
22181689Spramodbg 	int			rval;
2219*8082SRamaswamy.Tummala@Sun.COM 	ibnex_pseudo_node_t	*pseudo;
2220*8082SRamaswamy.Tummala@Sun.COM 	ibnex_node_state_t	prev_state;
2221*8082SRamaswamy.Tummala@Sun.COM 
2222*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)",
22231689Spramodbg 	    node_data, caddr, pdip);
22240Sstevel@tonic-gate 
22250Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
22260Sstevel@tonic-gate 
22270Sstevel@tonic-gate 	if (node_data == NULL) {
2228*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2229*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: caddr = %s", caddr);
22301689Spramodbg 
22311689Spramodbg 		/*
22321689Spramodbg 		 * This function is now called with PHCI / HCA driver
22331689Spramodbg 		 * as parent. The format of devicename is :
22341689Spramodbg 		 * 	<driver_name>@<driver_name>,<unit_address>
22351689Spramodbg 		 * The "caddr" part of the devicename matches the
22361689Spramodbg 		 * format of pseudo_node_addr.
22371689Spramodbg 		 *
22381689Spramodbg 		 * Use "caddr" to find a matching Pseudo node entry.
22391689Spramodbg 		 */
22400Sstevel@tonic-gate 		node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
22411689Spramodbg 		    (void *)caddr, 0, 0);
22420Sstevel@tonic-gate 	}
22430Sstevel@tonic-gate 
2244*8082SRamaswamy.Tummala@Sun.COM 	if (node_data == NULL) {
2245*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex",
2246*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: Invalid node");
2247*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_FAILURE);
2248*8082SRamaswamy.Tummala@Sun.COM 	}
2249*8082SRamaswamy.Tummala@Sun.COM 
2250*8082SRamaswamy.Tummala@Sun.COM 	if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) {
2251*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2252*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: Unconfigured node");
2253*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_FAILURE);
2254*8082SRamaswamy.Tummala@Sun.COM 	}
2255*8082SRamaswamy.Tummala@Sun.COM 
2256*8082SRamaswamy.Tummala@Sun.COM 	pseudo = &node_data->node_data.pseudo_node;
2257*8082SRamaswamy.Tummala@Sun.COM 
22580Sstevel@tonic-gate 	/*
22591093Shiremath 	 * Do not enumerate nodes with ib-node-type set as "merge"
22601093Shiremath 	 */
2261*8082SRamaswamy.Tummala@Sun.COM 	if (pseudo->pseudo_merge_node == 1) {
2262*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2263*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: merge_node");
22640Sstevel@tonic-gate 		return (IBNEX_FAILURE);
22650Sstevel@tonic-gate 	}
22660Sstevel@tonic-gate 
22670Sstevel@tonic-gate 	/*
2268*8082SRamaswamy.Tummala@Sun.COM 	 * Check if a PI has already been created for the PDIP.
2269*8082SRamaswamy.Tummala@Sun.COM 	 * If so, return SUCCESS.
2270*8082SRamaswamy.Tummala@Sun.COM 	 */
2271*8082SRamaswamy.Tummala@Sun.COM 	if (node_data->node_dip != NULL && mdi_pi_find(pdip,
2272*8082SRamaswamy.Tummala@Sun.COM 	    pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) {
2273*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2274*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: PI created,"
2275*8082SRamaswamy.Tummala@Sun.COM 		    " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr);
2276*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_SUCCESS);
2277*8082SRamaswamy.Tummala@Sun.COM 	}
2278*8082SRamaswamy.Tummala@Sun.COM 
2279*8082SRamaswamy.Tummala@Sun.COM 	/*
2280*8082SRamaswamy.Tummala@Sun.COM 	 * Return EBUSY if another unconfigure
22810Sstevel@tonic-gate 	 * operation is in progress
22820Sstevel@tonic-gate 	 */
22830Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
2284*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2285*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_config_one: BUSY");
22860Sstevel@tonic-gate 		return (IBNEX_BUSY);
22870Sstevel@tonic-gate 	}
22880Sstevel@tonic-gate 
2289*8082SRamaswamy.Tummala@Sun.COM 
2290*8082SRamaswamy.Tummala@Sun.COM 	prev_state = node_data->node_state;
22910Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
22920Sstevel@tonic-gate 
22930Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
2294*8082SRamaswamy.Tummala@Sun.COM 	rval = ibnex_pseudo_create_pi_pdip(node_data, pdip);
22950Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
22960Sstevel@tonic-gate 
2297*8082SRamaswamy.Tummala@Sun.COM 	if (rval == IBNEX_SUCCESS) {
22980Sstevel@tonic-gate 		node_data->node_state = IBNEX_CFGADM_CONFIGURED;
2299*8082SRamaswamy.Tummala@Sun.COM 	} else {
2300*8082SRamaswamy.Tummala@Sun.COM 		node_data->node_state = prev_state;
23010Sstevel@tonic-gate 	}
23020Sstevel@tonic-gate 
2303*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x",
2304*8082SRamaswamy.Tummala@Sun.COM 	    rval);
23050Sstevel@tonic-gate 	return (rval);
23060Sstevel@tonic-gate }
23070Sstevel@tonic-gate 
23080Sstevel@tonic-gate 
23091093Shiremath /*
23101093Shiremath  * ibnex_pseudo_mdi_config_one()
23111093Shiremath  *	This is similar to ibnex_pseudo_config_one. Few
23121093Shiremath  *	differences :
23131093Shiremath  *	1. parent device lock not held(no ndi_devi_enter)
23141093Shiremath  *	2. Called for IB Nexus as parent, not IB HCA as
23151093Shiremath  *	   parent.
23161093Shiremath  *	3. Calls mdi_vhci_bus_config()
23171689Spramodbg  * This function skips checks for node_state, initializing
23181689Spramodbg  * node_state, node_dip, etc. These checks and initializations
23191689Spramodbg  * are done when BUS_CONFIG is called with PHCI as the parent.
23201093Shiremath  */
23211093Shiremath static int
23221093Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child,
23231093Shiremath     char *cname, char *caddr)
23241093Shiremath {
23251093Shiremath 	int			rval, len;
23261093Shiremath 	char			*node_addr;
23271093Shiremath 	ibnex_node_data_t	*node_data;
23281093Shiremath 
23291093Shiremath 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:"
23301093Shiremath 	    "cname = %s caddr = %s", cname, caddr);
23311093Shiremath 
23321093Shiremath 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
23331093Shiremath 
23341093Shiremath 	len = strlen(cname) + strlen(caddr) + 2;
23351093Shiremath 	node_addr = (char *)kmem_alloc(len, KM_SLEEP);
23361093Shiremath 
23371093Shiremath 	(void) snprintf(node_addr, len, "%s,%s", cname, caddr);
23381093Shiremath 	node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
23391093Shiremath 	    (void *)node_addr, 0, 0);
23401093Shiremath 	kmem_free(node_addr, len);
23411093Shiremath 
23421689Spramodbg 	if (node_data == NULL) {
23431093Shiremath 		IBTF_DPRINTF_L2("ibnex",
23441093Shiremath 		    "\tpseudo_mdi_config_one: Invalid node");
23451093Shiremath 		return (IBNEX_FAILURE);
23461093Shiremath 	}
23471093Shiremath 
23481093Shiremath 	mutex_exit(&ibnex.ibnex_mutex);
23491093Shiremath 	rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE,
23501093Shiremath 	    devname, child, node_data->node_data.pseudo_node.pseudo_node_addr);
23511093Shiremath 	mutex_enter(&ibnex.ibnex_mutex);
23521093Shiremath 
23531093Shiremath 	return (rval);
23541093Shiremath }
23551093Shiremath 
2356*8082SRamaswamy.Tummala@Sun.COM 
23570Sstevel@tonic-gate /*
2358*8082SRamaswamy.Tummala@Sun.COM  * ibnex_pseudo_create_all_pi()
2359*8082SRamaswamy.Tummala@Sun.COM  *	Create all path infos node for a pseudo entry
23600Sstevel@tonic-gate  */
23610Sstevel@tonic-gate int
2362*8082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep)
23630Sstevel@tonic-gate {
2364*8082SRamaswamy.Tummala@Sun.COM 	int		hcacnt, rc;
2365*8082SRamaswamy.Tummala@Sun.COM 	int		hcafailcnt = 0;
2366*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t	*hca_dip;
2367*8082SRamaswamy.Tummala@Sun.COM 	ibdm_hca_list_t	*hca_list, *head;
2368*8082SRamaswamy.Tummala@Sun.COM 
2369*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)",
2370*8082SRamaswamy.Tummala@Sun.COM 	    nodep);
23710Sstevel@tonic-gate 	ibdm_ibnex_get_hca_list(&hca_list, &hcacnt);
23720Sstevel@tonic-gate 
23730Sstevel@tonic-gate 	head = hca_list;
23740Sstevel@tonic-gate 
2375*8082SRamaswamy.Tummala@Sun.COM 	/*
2376*8082SRamaswamy.Tummala@Sun.COM 	 * We return failure even if we fail for all HCAs.
2377*8082SRamaswamy.Tummala@Sun.COM 	 */
23780Sstevel@tonic-gate 	for (; hca_list != NULL; hca_list = hca_list->hl_next) {
23790Sstevel@tonic-gate 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
2380*8082SRamaswamy.Tummala@Sun.COM 		rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip);
2381*8082SRamaswamy.Tummala@Sun.COM 		if (rc != IBNEX_SUCCESS)
2382*8082SRamaswamy.Tummala@Sun.COM 			hcafailcnt++;
23830Sstevel@tonic-gate 	}
23840Sstevel@tonic-gate 	if (head)
23850Sstevel@tonic-gate 		ibdm_ibnex_free_hca_list(head);
2386*8082SRamaswamy.Tummala@Sun.COM 
2387*8082SRamaswamy.Tummala@Sun.COM 	if (hcafailcnt == hcacnt)
2388*8082SRamaswamy.Tummala@Sun.COM 		rc = IBNEX_FAILURE;
2389*8082SRamaswamy.Tummala@Sun.COM 	else
2390*8082SRamaswamy.Tummala@Sun.COM 		rc = IBNEX_SUCCESS;
2391*8082SRamaswamy.Tummala@Sun.COM 
2392*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x",
2393*8082SRamaswamy.Tummala@Sun.COM 	    rc);
2394*8082SRamaswamy.Tummala@Sun.COM 	return (rc);
2395*8082SRamaswamy.Tummala@Sun.COM }
2396*8082SRamaswamy.Tummala@Sun.COM 
2397*8082SRamaswamy.Tummala@Sun.COM static int
2398*8082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip)
2399*8082SRamaswamy.Tummala@Sun.COM {
2400*8082SRamaswamy.Tummala@Sun.COM 	mdi_pathinfo_t		*pip;
2401*8082SRamaswamy.Tummala@Sun.COM 	int			rval;
2402*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t		*cdip = NULL;
2403*8082SRamaswamy.Tummala@Sun.COM 	ibnex_pseudo_node_t	*pseudo;
2404*8082SRamaswamy.Tummala@Sun.COM 	int			first_pi = 0;
2405*8082SRamaswamy.Tummala@Sun.COM 
2406*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p",
2407*8082SRamaswamy.Tummala@Sun.COM 	    nodep, hca_dip);
2408*8082SRamaswamy.Tummala@Sun.COM 
2409*8082SRamaswamy.Tummala@Sun.COM 	pseudo = &nodep->node_data.pseudo_node;
2410*8082SRamaswamy.Tummala@Sun.COM 
2411*8082SRamaswamy.Tummala@Sun.COM 	rval = mdi_pi_alloc(hca_dip,
2412*8082SRamaswamy.Tummala@Sun.COM 	    pseudo->pseudo_devi_name, pseudo->pseudo_node_addr,
2413*8082SRamaswamy.Tummala@Sun.COM 	    pseudo->pseudo_node_addr, 0, &pip);
2414*8082SRamaswamy.Tummala@Sun.COM 
2415*8082SRamaswamy.Tummala@Sun.COM 	if (rval != MDI_SUCCESS) {
2416*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:"
2417*8082SRamaswamy.Tummala@Sun.COM 		    " mdi_pi_alloc failed");
2418*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_FAILURE);
2419*8082SRamaswamy.Tummala@Sun.COM 	}
2420*8082SRamaswamy.Tummala@Sun.COM 	cdip = mdi_pi_get_client(pip);
2421*8082SRamaswamy.Tummala@Sun.COM 
2422*8082SRamaswamy.Tummala@Sun.COM 	if (nodep->node_dip == NULL) {
2423*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2424*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_create_pi: New dip %p", cdip);
2425*8082SRamaswamy.Tummala@Sun.COM 
2426*8082SRamaswamy.Tummala@Sun.COM 		first_pi = 1;
2427*8082SRamaswamy.Tummala@Sun.COM 		nodep->node_dip = cdip;
2428*8082SRamaswamy.Tummala@Sun.COM 		ddi_set_parent_data(cdip, nodep);
2429*8082SRamaswamy.Tummala@Sun.COM 	}
2430*8082SRamaswamy.Tummala@Sun.COM 
2431*8082SRamaswamy.Tummala@Sun.COM 	rval = mdi_pi_online(pip, 0);
2432*8082SRamaswamy.Tummala@Sun.COM 
2433*8082SRamaswamy.Tummala@Sun.COM 	if (rval != MDI_SUCCESS) {
2434*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex",
2435*8082SRamaswamy.Tummala@Sun.COM 		    "\tpseudo_create_pi: "
2436*8082SRamaswamy.Tummala@Sun.COM 		    "mdi_pi_online: failed for pseudo dip %p,"
2437*8082SRamaswamy.Tummala@Sun.COM 		    " rval %d", cdip, rval);
2438*8082SRamaswamy.Tummala@Sun.COM 		rval = IBNEX_FAILURE;
2439*8082SRamaswamy.Tummala@Sun.COM 		if (first_pi == 1) {
2440*8082SRamaswamy.Tummala@Sun.COM 			ddi_set_parent_data(cdip, NULL);
2441*8082SRamaswamy.Tummala@Sun.COM 			(void) ibnex_offline_childdip(cdip);
2442*8082SRamaswamy.Tummala@Sun.COM 			nodep->node_dip = NULL;
2443*8082SRamaswamy.Tummala@Sun.COM 		} else
2444*8082SRamaswamy.Tummala@Sun.COM 			(void) mdi_pi_free(pip, 0);
2445*8082SRamaswamy.Tummala@Sun.COM 	} else
2446*8082SRamaswamy.Tummala@Sun.COM 		rval = IBNEX_SUCCESS;
24470Sstevel@tonic-gate 	return (rval);
24480Sstevel@tonic-gate }
24490Sstevel@tonic-gate 
24500Sstevel@tonic-gate /*
24510Sstevel@tonic-gate  * ibnex_ioc_create_pi()
24520Sstevel@tonic-gate  *	Create a pathinfo node for the ioc node
24530Sstevel@tonic-gate  */
24540Sstevel@tonic-gate static int
24551093Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data,
2456*8082SRamaswamy.Tummala@Sun.COM     dev_info_t *pdip, int *node_valid)
24570Sstevel@tonic-gate {
24580Sstevel@tonic-gate 	mdi_pathinfo_t		*pip;
24591093Shiremath 	int			rval = DDI_FAILURE;
2460*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t		*cdip = NULL;
2461*8082SRamaswamy.Tummala@Sun.COM 	int			create_prop = 0;
2462*8082SRamaswamy.Tummala@Sun.COM 	ibnex_ioc_node_t	*ioc = &node_data->node_data.ioc_node;
2463*8082SRamaswamy.Tummala@Sun.COM 
2464*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex",
2465*8082SRamaswamy.Tummala@Sun.COM 	    "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip);
2466*8082SRamaswamy.Tummala@Sun.COM 	*node_valid = 1;
2467*8082SRamaswamy.Tummala@Sun.COM 
2468*8082SRamaswamy.Tummala@Sun.COM 	/*
2469*8082SRamaswamy.Tummala@Sun.COM 	 * For CONFIG_ONE requests through HCA dip, alloc
2470*8082SRamaswamy.Tummala@Sun.COM 	 * for HCA dip driving BUS_CONFIG request.
2471*8082SRamaswamy.Tummala@Sun.COM 	 */
2472*8082SRamaswamy.Tummala@Sun.COM 	rval =  mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str,
2473*8082SRamaswamy.Tummala@Sun.COM 	    ioc->ioc_phci_guid, 0, &pip);
2474*8082SRamaswamy.Tummala@Sun.COM 	if (rval != MDI_SUCCESS) {
2475*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex",
2476*8082SRamaswamy.Tummala@Sun.COM 		    "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed",
2477*8082SRamaswamy.Tummala@Sun.COM 		    pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid);
2478*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_FAILURE);
2479*8082SRamaswamy.Tummala@Sun.COM 	}
2480*8082SRamaswamy.Tummala@Sun.COM 	cdip = mdi_pi_get_client(pip);
2481*8082SRamaswamy.Tummala@Sun.COM 
2482*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p",
2483*8082SRamaswamy.Tummala@Sun.COM 	    cdip);
2484*8082SRamaswamy.Tummala@Sun.COM 
2485*8082SRamaswamy.Tummala@Sun.COM 	if (node_data->node_dip == NULL) {
2486*8082SRamaswamy.Tummala@Sun.COM 		node_data->node_dip = cdip;
2487*8082SRamaswamy.Tummala@Sun.COM 		ddi_set_parent_data(cdip, node_data);
2488*8082SRamaswamy.Tummala@Sun.COM 		create_prop = 1;
2489*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
2490*8082SRamaswamy.Tummala@Sun.COM 		    "\tioc_create_pi: creating prop");
2491*8082SRamaswamy.Tummala@Sun.COM 		if ((rval = ibnex_create_ioc_node_prop(
2492*8082SRamaswamy.Tummala@Sun.COM 		    ioc_info, cdip)) != IBNEX_SUCCESS) {
2493*8082SRamaswamy.Tummala@Sun.COM 			IBTF_DPRINTF_L4("ibnex",
2494*8082SRamaswamy.Tummala@Sun.COM 			    "\tioc_create_pi: creating prop failed");
2495*8082SRamaswamy.Tummala@Sun.COM 			ibnex_delete_ioc_node_data(node_data);
2496*8082SRamaswamy.Tummala@Sun.COM 			*node_valid = 0;
2497*8082SRamaswamy.Tummala@Sun.COM 			ddi_prop_remove_all(cdip);
2498*8082SRamaswamy.Tummala@Sun.COM 			ddi_set_parent_data(cdip, NULL);
2499*8082SRamaswamy.Tummala@Sun.COM 
25000Sstevel@tonic-gate 			(void) ibnex_offline_childdip(cdip);
25010Sstevel@tonic-gate 			return (IBNEX_FAILURE);
25020Sstevel@tonic-gate 		}
2503*8082SRamaswamy.Tummala@Sun.COM 	}
2504*8082SRamaswamy.Tummala@Sun.COM 
2505*8082SRamaswamy.Tummala@Sun.COM 	rval = mdi_pi_online(pip, 0);
2506*8082SRamaswamy.Tummala@Sun.COM 
2507*8082SRamaswamy.Tummala@Sun.COM 	if (rval != MDI_SUCCESS) {
2508*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: "
2509*8082SRamaswamy.Tummala@Sun.COM 		    "mdi_pi_online() failed ioc dip %p, rval %d",
2510*8082SRamaswamy.Tummala@Sun.COM 		    cdip, rval);
2511*8082SRamaswamy.Tummala@Sun.COM 		rval = IBNEX_FAILURE;
2512*8082SRamaswamy.Tummala@Sun.COM 		if (create_prop) {
2513*8082SRamaswamy.Tummala@Sun.COM 			ddi_set_parent_data(cdip, NULL);
2514*8082SRamaswamy.Tummala@Sun.COM 			ddi_prop_remove_all(cdip);
25150Sstevel@tonic-gate 			ibnex_delete_ioc_node_data(node_data);
2516*8082SRamaswamy.Tummala@Sun.COM 			*node_valid = 0;
25170Sstevel@tonic-gate 			(void) ibnex_offline_childdip(cdip);
25180Sstevel@tonic-gate 		} else
2519*8082SRamaswamy.Tummala@Sun.COM 			(void) mdi_pi_free(pip, 0);
2520*8082SRamaswamy.Tummala@Sun.COM 	} else
2521*8082SRamaswamy.Tummala@Sun.COM 		rval = IBNEX_SUCCESS;
2522*8082SRamaswamy.Tummala@Sun.COM 
2523*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval);
25240Sstevel@tonic-gate 	return (rval);
25250Sstevel@tonic-gate }
25260Sstevel@tonic-gate 
25270Sstevel@tonic-gate 
25280Sstevel@tonic-gate /*
25290Sstevel@tonic-gate  * ibnex_create_ioc_node_prop()
25300Sstevel@tonic-gate  *	Create IOC device node properties
25310Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
25320Sstevel@tonic-gate  */
25330Sstevel@tonic-gate static int
25340Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip)
25350Sstevel@tonic-gate {
25360Sstevel@tonic-gate 	uint16_t		 capabilities;
25370Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile;
25380Sstevel@tonic-gate 
25390Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop");
25400Sstevel@tonic-gate 
25410Sstevel@tonic-gate 	if (ibnex_create_ioc_compatible_prop(cdip,
25420Sstevel@tonic-gate 	    ioc_profile) != IBNEX_SUCCESS) {
25430Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25440Sstevel@tonic-gate 	}
25450Sstevel@tonic-gate 	if ((ioc_info->ioc_iou_dc_valid) &&
25460Sstevel@tonic-gate 	    (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode",
25470Sstevel@tonic-gate 	    ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) {
25480Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25490Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: iou-diagcode create failed");
25500Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25510Sstevel@tonic-gate 	}
25520Sstevel@tonic-gate 	if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) {
25530Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode",
25540Sstevel@tonic-gate 		    ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) {
25550Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
25560Sstevel@tonic-gate 			    "ioc-diagcode create failed");
25570Sstevel@tonic-gate 			return (IBNEX_FAILURE);
25580Sstevel@tonic-gate 		}
25590Sstevel@tonic-gate 	}
25600Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth",
25610Sstevel@tonic-gate 	    ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) {
25620Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25630Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: rdma-queue-depth create failed");
25640Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25650Sstevel@tonic-gate 	}
25660Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size",
25670Sstevel@tonic-gate 	    ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) {
25680Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
25690Sstevel@tonic-gate 		    "rdma-transfer-size create failed");
25700Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25710Sstevel@tonic-gate 	}
25720Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size",
25730Sstevel@tonic-gate 	    ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) {
25740Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25750Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: send-message-size create failed");
25760Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25770Sstevel@tonic-gate 	}
25780Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth",
25790Sstevel@tonic-gate 	    ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) {
25800Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25810Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: send-queue-depth create failed");
25820Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25830Sstevel@tonic-gate 	}
25840Sstevel@tonic-gate 
25850Sstevel@tonic-gate 	capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8);
25860Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip,
25875470Spramodbg 	    "capabilities", capabilities) != DDI_PROP_SUCCESS) {
25880Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25890Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: capabilities create failed");
25900Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25910Sstevel@tonic-gate 	}
25920Sstevel@tonic-gate 	if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string",
25930Sstevel@tonic-gate 	    (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) {
25940Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
25950Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: id-string failed");
25960Sstevel@tonic-gate 		return (IBNEX_FAILURE);
25970Sstevel@tonic-gate 	}
25980Sstevel@tonic-gate 
25990Sstevel@tonic-gate 	/*
26000Sstevel@tonic-gate 	 * Create properties to represent all the service entries supported
26010Sstevel@tonic-gate 	 * by the IOC. Each service entry consists of 1) Service ID (64 bits)
26020Sstevel@tonic-gate 	 * and 2) Service name (40 bytes). The service entry table is
26030Sstevel@tonic-gate 	 * represented by two properties, service-ids and service-names. The
26040Sstevel@tonic-gate 	 * service-id property is a array of int64's and service names is
26050Sstevel@tonic-gate 	 * array of strings. The first element in the "service-ids" property
26060Sstevel@tonic-gate 	 * corresponds to first string in the "service-names" and so on.
26070Sstevel@tonic-gate 	 */
26080Sstevel@tonic-gate 	if ((ioc_profile->ioc_service_entries != 0) &&
26090Sstevel@tonic-gate 	    (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS))
26100Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26110Sstevel@tonic-gate 
26120Sstevel@tonic-gate 	/* Create destination port GID properties */
26130Sstevel@tonic-gate 	if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS)
26140Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26150Sstevel@tonic-gate 
26160Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version",
26170Sstevel@tonic-gate 	    ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) {
26180Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26190Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol-version create failed");
26200Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26210Sstevel@tonic-gate 	}
26220Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol",
26230Sstevel@tonic-gate 	    ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) {
26240Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26250Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol create failed");
26260Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26270Sstevel@tonic-gate 	}
26280Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass",
26290Sstevel@tonic-gate 	    ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) {
26300Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26310Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subclass create failed");
26320Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26330Sstevel@tonic-gate 	}
26340Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class",
26350Sstevel@tonic-gate 	    ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) {
26360Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26370Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: class prop create failed");
26380Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26390Sstevel@tonic-gate 	}
26400Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id",
26410Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) {
26420Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26430Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subsys_id create failed");
26440Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26450Sstevel@tonic-gate 	}
26460Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id",
26470Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) {
26480Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26490Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: subsystem vendor create failed");
26500Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26510Sstevel@tonic-gate 	}
26520Sstevel@tonic-gate 	if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid",
26530Sstevel@tonic-gate 	    ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) {
26540Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26550Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: protocol create failed");
26560Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26570Sstevel@tonic-gate 	}
26580Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version",
26590Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) {
26600Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26610Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: product-id create failed");
26620Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26630Sstevel@tonic-gate 	}
26640Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id",
26650Sstevel@tonic-gate 	    ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) {
26660Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26670Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: product-id create failed");
26680Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26690Sstevel@tonic-gate 	}
26700Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id",
26710Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) {
26720Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
26730Sstevel@tonic-gate 		    "\tcreate_ioc_node_prop: vendor-id create failed");
26740Sstevel@tonic-gate 		return (IBNEX_FAILURE);
26750Sstevel@tonic-gate 	}
26760Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
26770Sstevel@tonic-gate }
26780Sstevel@tonic-gate 
26790Sstevel@tonic-gate 
26800Sstevel@tonic-gate /*
26810Sstevel@tonic-gate  * ibnex_create_ioc_portgid_prop()
26820Sstevel@tonic-gate  *	Creates "port-entries", "port-list" properties
26830Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
26840Sstevel@tonic-gate  */
26850Sstevel@tonic-gate static int
26860Sstevel@tonic-gate ibnex_create_ioc_portgid_prop(
26870Sstevel@tonic-gate     dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
26880Sstevel@tonic-gate {
26890Sstevel@tonic-gate 	uint64_t	*port_gids;
26900Sstevel@tonic-gate 	int		length, ii, jj;
26910Sstevel@tonic-gate 	int		prop_len;
26920Sstevel@tonic-gate 	ibnex_node_data_t *node_data;
26930Sstevel@tonic-gate 
26940Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop");
26950Sstevel@tonic-gate 
26960Sstevel@tonic-gate 	node_data = ddi_get_parent_data(cdip);
26970Sstevel@tonic-gate 	ASSERT(node_data);
26980Sstevel@tonic-gate 
26990Sstevel@tonic-gate 	prop_len = (ioc_info->ioc_nportgids != 0) ?
27000Sstevel@tonic-gate 	    (2 * ioc_info->ioc_nportgids) : 1;
27010Sstevel@tonic-gate 	length = sizeof (uint64_t) * prop_len;
27020Sstevel@tonic-gate 	port_gids = kmem_zalloc(length, KM_SLEEP);
27030Sstevel@tonic-gate 
27040Sstevel@tonic-gate 	for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) {
27050Sstevel@tonic-gate 		port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi;
27060Sstevel@tonic-gate 		port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo;
27070Sstevel@tonic-gate 	}
27080Sstevel@tonic-gate 	if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list",
27090Sstevel@tonic-gate 	    (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) {
27100Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
27110Sstevel@tonic-gate 		    "\tcreate_ioc_portgid_prop: port-list create failed");
27120Sstevel@tonic-gate 		kmem_free(port_gids, length);
27130Sstevel@tonic-gate 		return (IBNEX_FAILURE);
27140Sstevel@tonic-gate 	}
27150Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries",
27160Sstevel@tonic-gate 	    ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) {
27170Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
27180Sstevel@tonic-gate 		    "\tcreate_ioc_portgid_prop: port-entries create failed");
27190Sstevel@tonic-gate 		kmem_free(port_gids, length);
27200Sstevel@tonic-gate 		return (IBNEX_FAILURE);
27210Sstevel@tonic-gate 	}
27220Sstevel@tonic-gate 
27230Sstevel@tonic-gate 	kmem_free(port_gids, length);
27240Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
27250Sstevel@tonic-gate }
27260Sstevel@tonic-gate 
27270Sstevel@tonic-gate 
27280Sstevel@tonic-gate /*
27290Sstevel@tonic-gate  * ibnex_create_ioc_srv_props()
27300Sstevel@tonic-gate  *	Creates "service-name" and "service-id" properties
27310Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
27320Sstevel@tonic-gate  */
27330Sstevel@tonic-gate static int
27340Sstevel@tonic-gate ibnex_create_ioc_srv_props(
27350Sstevel@tonic-gate     dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
27360Sstevel@tonic-gate {
27370Sstevel@tonic-gate 	int			length, ii;
27380Sstevel@tonic-gate 	uint64_t		*srv_id;
27390Sstevel@tonic-gate 	char			*temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU];
27400Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile;
27410Sstevel@tonic-gate 	ibdm_srvents_info_t	 *srvents = ioc_info->ioc_serv;
27420Sstevel@tonic-gate 
27430Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props");
27440Sstevel@tonic-gate 
27450Sstevel@tonic-gate 	length = profile->ioc_service_entries * sizeof (ib_dm_srv_t);
27460Sstevel@tonic-gate 	srv_id = kmem_zalloc(length, KM_SLEEP);
27470Sstevel@tonic-gate 	temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries));
27480Sstevel@tonic-gate 	for (ii = 0; ii < profile->ioc_service_entries; ii++) {
27490Sstevel@tonic-gate 		srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN);
27500Sstevel@tonic-gate 	}
27510Sstevel@tonic-gate 
27520Sstevel@tonic-gate 	for (ii = 0; ii < profile->ioc_service_entries; ii++) {
27530Sstevel@tonic-gate 		srv_id[ii] = srvents[ii].se_attr.srv_id;
27540Sstevel@tonic-gate 		bcopy(srvents[ii].se_attr.srv_name,
27550Sstevel@tonic-gate 		    srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1));
27560Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
27570Sstevel@tonic-gate 		    "Service Names : %s", srv_names[ii]);
27580Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
27591093Shiremath 		    "Service ID : %llX", srv_id[ii]);
27600Sstevel@tonic-gate 	}
27610Sstevel@tonic-gate 
27620Sstevel@tonic-gate 	if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip,
27630Sstevel@tonic-gate 	    "service-id", (int64_t *)srv_id,
27640Sstevel@tonic-gate 	    profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
27650Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
27660Sstevel@tonic-gate 		    "\tcreate_ioc_srv_props: service-id create failed");
27670Sstevel@tonic-gate 		kmem_free(srv_id, length);
27680Sstevel@tonic-gate 		return (IBNEX_FAILURE);
27690Sstevel@tonic-gate 	}
27700Sstevel@tonic-gate 
27710Sstevel@tonic-gate 	if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
27720Sstevel@tonic-gate 	    "service-name", (char **)srv_names,
27730Sstevel@tonic-gate 	    profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
27740Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
27750Sstevel@tonic-gate 		    "\tcreate_ioc_srv_props: service-name create failed");
27760Sstevel@tonic-gate 		kmem_free(srv_id, length);
27770Sstevel@tonic-gate 		return (IBNEX_FAILURE);
27780Sstevel@tonic-gate 	}
27790Sstevel@tonic-gate 	kmem_free(srv_id, length);
27800Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
27810Sstevel@tonic-gate }
27820Sstevel@tonic-gate 
27830Sstevel@tonic-gate 
27840Sstevel@tonic-gate /*
27850Sstevel@tonic-gate  * ibnex_create_ioc_compatible_prop()
27860Sstevel@tonic-gate  *	Creates "compatible" property values
27870Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
27880Sstevel@tonic-gate  */
27890Sstevel@tonic-gate static int
27900Sstevel@tonic-gate ibnex_create_ioc_compatible_prop(
27910Sstevel@tonic-gate     dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile)
27920Sstevel@tonic-gate {
27930Sstevel@tonic-gate 	char		*temp;
27940Sstevel@tonic-gate 	int		rval, ii;
27950Sstevel@tonic-gate 	char		*compatible[IBNEX_MAX_COMPAT_NAMES];
27960Sstevel@tonic-gate 
27970Sstevel@tonic-gate 	/*
27980Sstevel@tonic-gate 	 * Initialize the "compatible" property string as below:
27990Sstevel@tonic-gate 	 * Compatible Strings :
28000Sstevel@tonic-gate 	 *	1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver>
28010Sstevel@tonic-gate 	 *	2. ib.V<vid>P<pid>S<subsys vid>s<subsys id>
28020Sstevel@tonic-gate 	 *	3. ib.V<vid>P<pid>v<ver>
28030Sstevel@tonic-gate 	 *	4. ib.V<vid>P<pid>
28040Sstevel@tonic-gate 	 *	5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver>
28050Sstevel@tonic-gate 	 *	6. ib.C<Class>c<Subclass>p<protocol>
28060Sstevel@tonic-gate 	 *
28070Sstevel@tonic-gate 	 * Note:
28080Sstevel@tonic-gate 	 *	All leading zeros must be present
28090Sstevel@tonic-gate 	 *	All numeric values must specified in hex without prefix "0x"
28100Sstevel@tonic-gate 	 */
28110Sstevel@tonic-gate 
28120Sstevel@tonic-gate 	temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP);
28130Sstevel@tonic-gate 	for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
28140Sstevel@tonic-gate 		compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN);
28150Sstevel@tonic-gate 
28160Sstevel@tonic-gate 	(void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
28170Sstevel@tonic-gate 	    "ib.V%06xP%08xS%06xs%08xv%04x",
28180Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
28190Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id,
28200Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver);
28210Sstevel@tonic-gate 
28220Sstevel@tonic-gate 	(void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
28230Sstevel@tonic-gate 	    "ib.V%06xP%08xS%06xs%08x",
28240Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
28250Sstevel@tonic-gate 	    ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id);
28260Sstevel@tonic-gate 
28270Sstevel@tonic-gate 	(void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
28280Sstevel@tonic-gate 	    "ib.V%06xP%08xv%04x",
28290Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
28300Sstevel@tonic-gate 	    ioc_profile->ioc_device_ver);
28310Sstevel@tonic-gate 
28320Sstevel@tonic-gate 	(void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN,
28330Sstevel@tonic-gate 	    "ib.V%06xP%08x",
28340Sstevel@tonic-gate 	    ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid);
28350Sstevel@tonic-gate 
28360Sstevel@tonic-gate 	(void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN,
28370Sstevel@tonic-gate 	    "ib.C%04xc%04xp%04xr%04x",
28380Sstevel@tonic-gate 	    ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
28390Sstevel@tonic-gate 	    ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver);
28400Sstevel@tonic-gate 
28410Sstevel@tonic-gate 	(void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN,
28420Sstevel@tonic-gate 	    "ib.C%04xc%04xp%04x",
28430Sstevel@tonic-gate 	    ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
28440Sstevel@tonic-gate 	    ioc_profile->ioc_protocol);
28450Sstevel@tonic-gate 	for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
28460Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]);
28470Sstevel@tonic-gate 
28480Sstevel@tonic-gate 	/* Create the compatible property for child cdip */
28490Sstevel@tonic-gate 	rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
28500Sstevel@tonic-gate 	    "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES);
28510Sstevel@tonic-gate 
28520Sstevel@tonic-gate 	if (rval != DDI_PROP_SUCCESS) {
28530Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed");
28540Sstevel@tonic-gate 		kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
28550Sstevel@tonic-gate 		return (IBNEX_FAILURE);
28560Sstevel@tonic-gate 	}
28570Sstevel@tonic-gate 
28580Sstevel@tonic-gate 	kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
28590Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
28600Sstevel@tonic-gate }
28610Sstevel@tonic-gate 
28620Sstevel@tonic-gate 
28630Sstevel@tonic-gate static void
28640Sstevel@tonic-gate ibnex_ioc_node_cleanup()
28650Sstevel@tonic-gate {
28660Sstevel@tonic-gate 	ibnex_node_data_t *node, *delete;
28670Sstevel@tonic-gate 
28680Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
28690Sstevel@tonic-gate 	for (node = ibnex.ibnex_ioc_node_head; node; ) {
28700Sstevel@tonic-gate 		delete = node;
28710Sstevel@tonic-gate 		node = node->node_next;
28720Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
28730Sstevel@tonic-gate 		ibnex_delete_ioc_node_data(delete);
28740Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
28750Sstevel@tonic-gate 	}
28760Sstevel@tonic-gate }
28770Sstevel@tonic-gate 
28780Sstevel@tonic-gate /*
28790Sstevel@tonic-gate  * ibnex_delete_ioc_node_data()
28800Sstevel@tonic-gate  *	Delete IOC node from the list
28810Sstevel@tonic-gate  */
28820Sstevel@tonic-gate static void
28830Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node)
28840Sstevel@tonic-gate {
28850Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:");
28860Sstevel@tonic-gate 
28870Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
28880Sstevel@tonic-gate 	if ((node->node_next == NULL) && (node->node_prev == NULL)) {
28890Sstevel@tonic-gate 		ASSERT(ibnex.ibnex_ioc_node_head == node);
28900Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = NULL;
28910Sstevel@tonic-gate 	} else if (node->node_next == NULL)
28920Sstevel@tonic-gate 		node->node_prev->node_next = NULL;
28930Sstevel@tonic-gate 	else if (node->node_prev == NULL) {
28940Sstevel@tonic-gate 		node->node_next->node_prev = NULL;
28950Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = node->node_next;
28960Sstevel@tonic-gate 	} else {
28970Sstevel@tonic-gate 		node->node_prev->node_next = node->node_next;
28980Sstevel@tonic-gate 		node->node_next->node_prev = node->node_prev;
28990Sstevel@tonic-gate 	}
29000Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p",
29010Sstevel@tonic-gate 	    ibnex.ibnex_ioc_node_head);
29020Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
29030Sstevel@tonic-gate 	kmem_free(node, sizeof (ibnex_node_data_t));
29040Sstevel@tonic-gate }
29050Sstevel@tonic-gate 
29060Sstevel@tonic-gate 
29070Sstevel@tonic-gate /*
29080Sstevel@tonic-gate  * ibnex_dm_callback()
29090Sstevel@tonic-gate  *
29100Sstevel@tonic-gate  *	This routine is registered with the IBDM during IB nexus attach. It
29110Sstevel@tonic-gate  *	is called by the IBDM module when it discovers
29120Sstevel@tonic-gate  *		New HCA port
29130Sstevel@tonic-gate  *		HCA port removal
29140Sstevel@tonic-gate  *		New HCA added
29150Sstevel@tonic-gate  *		HCA removed
29160Sstevel@tonic-gate  */
29170Sstevel@tonic-gate void
29180Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag)
29190Sstevel@tonic-gate {
29200Sstevel@tonic-gate 	char	hca_guid[IBNEX_HCAGUID_STRSZ];
29210Sstevel@tonic-gate 	ibdm_ioc_info_t	*ioc_list, *ioc;
29220Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
29230Sstevel@tonic-gate 
29240Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag);
29250Sstevel@tonic-gate 
29260Sstevel@tonic-gate 	switch (flag) {
29270Sstevel@tonic-gate 	case IBDM_EVENT_HCA_ADDED:
29280Sstevel@tonic-gate 		(void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
29290Sstevel@tonic-gate 		    (*(longlong_t *)arg));
29300Sstevel@tonic-gate 		/* Create a devctl minor node for the HCA's port  */
29310Sstevel@tonic-gate 		if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR,
29320Sstevel@tonic-gate 		    ddi_get_instance(ibnex.ibnex_dip),
29330Sstevel@tonic-gate 		    DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
29340Sstevel@tonic-gate 			IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
29350Sstevel@tonic-gate 			    "create minor node for port w/ guid %s", hca_guid);
29360Sstevel@tonic-gate 		}
29370Sstevel@tonic-gate 
29380Sstevel@tonic-gate 		break;
29390Sstevel@tonic-gate 
29400Sstevel@tonic-gate 	case IBDM_EVENT_HCA_REMOVED:
29410Sstevel@tonic-gate 		(void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
29420Sstevel@tonic-gate 		    (*(longlong_t *)arg));
29430Sstevel@tonic-gate 		ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid);
29440Sstevel@tonic-gate 		break;
29450Sstevel@tonic-gate 
29460Sstevel@tonic-gate 	case IBDM_EVENT_IOC_PROP_UPDATE:
29470Sstevel@tonic-gate 		ioc = ioc_list = (ibdm_ioc_info_t *)arg;
29480Sstevel@tonic-gate 		if (ioc_list == NULL)
29490Sstevel@tonic-gate 			break;
29500Sstevel@tonic-gate 
29510Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
29520Sstevel@tonic-gate 		while (ioc_list) {
29530Sstevel@tonic-gate 			if ((node_data = ibnex_is_node_data_present(
29540Sstevel@tonic-gate 			    IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL &&
29550Sstevel@tonic-gate 			    node_data->node_dip != NULL) {
29560Sstevel@tonic-gate 				ibnex_update_prop(node_data, ioc_list);
29570Sstevel@tonic-gate 			}
29580Sstevel@tonic-gate 			ioc_list = ioc_list->ioc_next;
29590Sstevel@tonic-gate 		}
29600Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
29610Sstevel@tonic-gate 		ibdm_ibnex_free_ioc_list(ioc);
29620Sstevel@tonic-gate 	}
29630Sstevel@tonic-gate }
29640Sstevel@tonic-gate 
29650Sstevel@tonic-gate 
29660Sstevel@tonic-gate /*
29670Sstevel@tonic-gate  * ibnex_get_dip_from_guid()
29680Sstevel@tonic-gate  *
29690Sstevel@tonic-gate  *	Searches the linked list of the port nodes and returns the dip for
29700Sstevel@tonic-gate  *	the of the Port / Node guid requested.
29710Sstevel@tonic-gate  *	Returns NULL if not found
29720Sstevel@tonic-gate  */
29730Sstevel@tonic-gate int
29740Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
29750Sstevel@tonic-gate     dev_info_t **dip)
29760Sstevel@tonic-gate {
29770Sstevel@tonic-gate 	int			node_index;
29780Sstevel@tonic-gate 	ib_guid_t		node_guid;
29790Sstevel@tonic-gate 	ib_pkey_t		node_pkey;
29800Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
29810Sstevel@tonic-gate 
29820Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
29831093Shiremath 	    "\tget_dip_from_guid: guid = %llX", guid);
29840Sstevel@tonic-gate 
29850Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
29860Sstevel@tonic-gate 	/* Search for a matching entry in internal lists */
29870Sstevel@tonic-gate 	node_data = ibnex.ibnex_port_node_head;
29880Sstevel@tonic-gate 	while (node_data) {
29890Sstevel@tonic-gate 		node_guid = node_data->node_data.port_node.port_guid;
29900Sstevel@tonic-gate 		node_index = node_data->node_data.port_node.port_commsvc_idx;
29910Sstevel@tonic-gate 		node_pkey = node_data->node_data.port_node.port_pkey;
29920Sstevel@tonic-gate 		if ((node_guid == guid) && (index == node_index) &&
29930Sstevel@tonic-gate 		    (node_pkey == pkey)) {
29940Sstevel@tonic-gate 			break;
29950Sstevel@tonic-gate 		}
29960Sstevel@tonic-gate 		node_data = node_data->node_next;
29970Sstevel@tonic-gate 	}
29980Sstevel@tonic-gate 
29990Sstevel@tonic-gate 	/* matching found with a valid dip */
30000Sstevel@tonic-gate 	if (node_data && node_data->node_dip) {
30010Sstevel@tonic-gate 		*dip = node_data->node_dip;
30020Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
30030Sstevel@tonic-gate 	} else if (node_data && !node_data->node_dip) {	/* dip is invalid */
30040Sstevel@tonic-gate 		*dip = NULL;
30050Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
30060Sstevel@tonic-gate 	}
30070Sstevel@tonic-gate 
30080Sstevel@tonic-gate 	/* no match found */
30090Sstevel@tonic-gate 	*dip = NULL;
30100Sstevel@tonic-gate 	return (IBNEX_FAILURE);
30110Sstevel@tonic-gate }
30120Sstevel@tonic-gate 
30130Sstevel@tonic-gate 
30140Sstevel@tonic-gate /*
30150Sstevel@tonic-gate  * ibnex_comm_svc_init()
30160Sstevel@tonic-gate  *	Read the property and cache the values in the global
30170Sstevel@tonic-gate  *	structure.
30180Sstevel@tonic-gate  *	Check for max allowed length (4 bytes) of service name
30190Sstevel@tonic-gate  *	(each element of the property)
30200Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
30210Sstevel@tonic-gate  */
30220Sstevel@tonic-gate static ibnex_rval_t
30230Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type)
30240Sstevel@tonic-gate {
30250Sstevel@tonic-gate 	int		i, len, count;
30260Sstevel@tonic-gate 	int		ncomm_svcs;
30270Sstevel@tonic-gate 	char		**comm_svcp;
30280Sstevel@tonic-gate 	char		**servicep = NULL;
30290Sstevel@tonic-gate 	uint_t		nservices = 0;
30300Sstevel@tonic-gate 	int			*valid = NULL;
30310Sstevel@tonic-gate 
30320Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x",
30330Sstevel@tonic-gate 	    property, type);
30340Sstevel@tonic-gate 
30350Sstevel@tonic-gate 	/* lookup the string array property */
30360Sstevel@tonic-gate 	if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip,
30370Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, property, &servicep, &nservices) !=
30380Sstevel@tonic-gate 	    DDI_PROP_SUCCESS) {
30390Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property);
30400Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
30410Sstevel@tonic-gate 	}
30420Sstevel@tonic-gate 
30430Sstevel@tonic-gate 	if (nservices)
30440Sstevel@tonic-gate 		valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP);
30450Sstevel@tonic-gate 
30460Sstevel@tonic-gate 
30470Sstevel@tonic-gate 	/* first read the file to get a count of valid service entries */
30480Sstevel@tonic-gate 	for (ncomm_svcs = 0, count = 0; count < nservices; count++) {
30490Sstevel@tonic-gate 		int j;
30500Sstevel@tonic-gate 
30510Sstevel@tonic-gate 		len = strlen(servicep[count]);
3052*8082SRamaswamy.Tummala@Sun.COM 		/*
3053*8082SRamaswamy.Tummala@Sun.COM 		 * ib.conf has NULL strings for port-svc-list &
3054*8082SRamaswamy.Tummala@Sun.COM 		 * hca-svc-list, by default. Do not have L2 message
3055*8082SRamaswamy.Tummala@Sun.COM 		 * for these.
3056*8082SRamaswamy.Tummala@Sun.COM 		 */
3057*8082SRamaswamy.Tummala@Sun.COM 		if (len == 1 || len > 4) {
30580Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
3059*8082SRamaswamy.Tummala@Sun.COM 			    "Service name %s for property %s invalid : "
3060*8082SRamaswamy.Tummala@Sun.COM 			    "length %d", servicep[count], property, len);
3061*8082SRamaswamy.Tummala@Sun.COM 			continue;
3062*8082SRamaswamy.Tummala@Sun.COM 		} else if (len == 0) {
30630Sstevel@tonic-gate 			continue;
30640Sstevel@tonic-gate 		}
30650Sstevel@tonic-gate 		if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) {
30660Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
30670Sstevel@tonic-gate 			    "Service name %s invalid : Not unique",
30680Sstevel@tonic-gate 			    servicep[count]);
30690Sstevel@tonic-gate 			continue;
30700Sstevel@tonic-gate 		}
30710Sstevel@tonic-gate 
30720Sstevel@tonic-gate 		/*
30730Sstevel@tonic-gate 		 * ibnex_unique_svcname checks for uniqueness in service names
30740Sstevel@tonic-gate 		 * communication services fully initialized. Check uniqueness
30750Sstevel@tonic-gate 		 * in service names currently initialized.
30760Sstevel@tonic-gate 		 */
30770Sstevel@tonic-gate 		for (j = 0; j < count; j++)
30780Sstevel@tonic-gate 			if (valid[j] && strncmp(servicep[count],
30790Sstevel@tonic-gate 			    servicep[j], 4) == 0) {
30800Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
30810Sstevel@tonic-gate 				    "Service name %s invalid : Not unique",
30820Sstevel@tonic-gate 				    servicep[count]);
30830Sstevel@tonic-gate 					continue;
30840Sstevel@tonic-gate 			}
30850Sstevel@tonic-gate 
30860Sstevel@tonic-gate 		valid[count] = 1;
30870Sstevel@tonic-gate 		ncomm_svcs++;
30880Sstevel@tonic-gate 	}
30890Sstevel@tonic-gate 
30900Sstevel@tonic-gate 	/* if no valid entries found, bailout */
30910Sstevel@tonic-gate 	if (nservices == 0 || ncomm_svcs == 0) {
30920Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property);
30930Sstevel@tonic-gate 		ddi_prop_free(servicep); /* free the property */
30940Sstevel@tonic-gate 		if (valid)
30950Sstevel@tonic-gate 			kmem_free(valid, nservices * sizeof (int));
30960Sstevel@tonic-gate 		return (IBNEX_SUCCESS);
30970Sstevel@tonic-gate 	}
30980Sstevel@tonic-gate 
30990Sstevel@tonic-gate 	comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP);
31000Sstevel@tonic-gate 	if (type == IBNEX_PORT_COMMSVC_NODE) {
31010Sstevel@tonic-gate 		ibnex.ibnex_comm_svc_names = comm_svcp;
31020Sstevel@tonic-gate 		ibnex.ibnex_num_comm_svcs = ncomm_svcs;
31030Sstevel@tonic-gate 	} else if (type == IBNEX_VPPA_COMMSVC_NODE) {
31040Sstevel@tonic-gate 		ibnex.ibnex_vppa_comm_svc_names = comm_svcp;
31050Sstevel@tonic-gate 		ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs;
31060Sstevel@tonic-gate 	} else if (type == IBNEX_HCASVC_COMMSVC_NODE) {
31070Sstevel@tonic-gate 		ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp;
31080Sstevel@tonic-gate 		ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs;
31090Sstevel@tonic-gate 	}
31100Sstevel@tonic-gate 
31110Sstevel@tonic-gate 	/* copy the services into an array of strings */
31120Sstevel@tonic-gate 	for (i = 0, count = 0; count < nservices; count++) {
31130Sstevel@tonic-gate 		if (valid[count] == 0)	/* Skip invalid ones */
31140Sstevel@tonic-gate 			continue;
31150Sstevel@tonic-gate 		comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP);
31160Sstevel@tonic-gate 		(void) strcpy(comm_svcp[i], servicep[count]);
31170Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
31180Sstevel@tonic-gate 		    "\t\tService [%d]: %s", i, comm_svcp[i]);
31190Sstevel@tonic-gate 		++i;
31200Sstevel@tonic-gate 	}
31210Sstevel@tonic-gate 	ddi_prop_free(servicep);
31220Sstevel@tonic-gate 	kmem_free(valid, nservices * sizeof (int));
31230Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
31240Sstevel@tonic-gate }
31250Sstevel@tonic-gate 
31260Sstevel@tonic-gate 
31270Sstevel@tonic-gate /*
31280Sstevel@tonic-gate  * ibnex_comm_svc_fini()
31290Sstevel@tonic-gate  *	Deallocate all the memory allocated for the communication
31300Sstevel@tonic-gate  *	service arrays.
31310Sstevel@tonic-gate  */
31320Sstevel@tonic-gate static void
31330Sstevel@tonic-gate ibnex_comm_svc_fini()
31340Sstevel@tonic-gate {
31350Sstevel@tonic-gate 	int	index;
31360Sstevel@tonic-gate 
31370Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) {
31380Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_comm_svc_names[index],
31390Sstevel@tonic-gate 		    (strlen(ibnex.ibnex_comm_svc_names[index]) + 1));
31400Sstevel@tonic-gate 	}
31410Sstevel@tonic-gate 	if (ibnex.ibnex_comm_svc_names) {
31420Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_comm_svc_names,
31430Sstevel@tonic-gate 		    ibnex.ibnex_num_comm_svcs * sizeof (char *));
31440Sstevel@tonic-gate 	}
31450Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) {
31460Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_vppa_comm_svc_names[index],
31470Sstevel@tonic-gate 		    strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1);
31480Sstevel@tonic-gate 	}
31490Sstevel@tonic-gate 	if (ibnex.ibnex_vppa_comm_svc_names) {
31500Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_vppa_comm_svc_names,
31510Sstevel@tonic-gate 		    ibnex.ibnex_nvppa_comm_svcs * sizeof (char *));
31520Sstevel@tonic-gate 	}
31530Sstevel@tonic-gate 	for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) {
31540Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index],
31550Sstevel@tonic-gate 		    strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1);
31560Sstevel@tonic-gate 	}
31570Sstevel@tonic-gate 	if (ibnex.ibnex_hcasvc_comm_svc_names) {
31580Sstevel@tonic-gate 		kmem_free(ibnex.ibnex_hcasvc_comm_svc_names,
31590Sstevel@tonic-gate 		    ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *));
31600Sstevel@tonic-gate 	}
31610Sstevel@tonic-gate 	ibnex.ibnex_comm_svc_names = NULL;
31620Sstevel@tonic-gate 	ibnex.ibnex_num_comm_svcs = 0;
31630Sstevel@tonic-gate 	ibnex.ibnex_vppa_comm_svc_names = NULL;
31640Sstevel@tonic-gate 	ibnex.ibnex_nvppa_comm_svcs = 0;
31650Sstevel@tonic-gate 	ibnex.ibnex_hcasvc_comm_svc_names = NULL;
31660Sstevel@tonic-gate 	ibnex.ibnex_nhcasvc_comm_svcs = 0;
31670Sstevel@tonic-gate }
31680Sstevel@tonic-gate 
31690Sstevel@tonic-gate 
31700Sstevel@tonic-gate /*
31710Sstevel@tonic-gate  * ibnex_commsvc_initnode()
31720Sstevel@tonic-gate  *	This routine is specific to port/VPPA node creation
31730Sstevel@tonic-gate  *	Creates a device node for the comm service specified by commsvc_index
31740Sstevel@tonic-gate  *	Creates all the device node properties
31750Sstevel@tonic-gate  *	Allocates and initializes the node specific data
31760Sstevel@tonic-gate  *	Binds the device driver of the device node
31770Sstevel@tonic-gate  *	Returns "dev_info_t" of the child node or NULL in case of failure
31780Sstevel@tonic-gate  *	Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect
31790Sstevel@tonic-gate  *	if the operation was successful, failed or was not performed.
31800Sstevel@tonic-gate  */
31810Sstevel@tonic-gate dev_info_t *
31820Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr,
31830Sstevel@tonic-gate     int index, int node_type, ib_pkey_t pkey, int *rval, int flag)
31840Sstevel@tonic-gate {
31850Sstevel@tonic-gate 	int			ret;
31860Sstevel@tonic-gate 	char			*svcname;
31870Sstevel@tonic-gate 	dev_info_t		*cdip;
31880Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
3189*8082SRamaswamy.Tummala@Sun.COM 	ibnex_port_node_t	*port_node;
3190*8082SRamaswamy.Tummala@Sun.COM 	char devname[MAXNAMELEN];
31910Sstevel@tonic-gate 
31920Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
31930Sstevel@tonic-gate 
31940Sstevel@tonic-gate 	*rval = IBNEX_SUCCESS;
31950Sstevel@tonic-gate 
31960Sstevel@tonic-gate 	/*
31970Sstevel@tonic-gate 	 * prevent any races
31980Sstevel@tonic-gate 	 * we have seen this node_data and it has been initialized
31990Sstevel@tonic-gate 	 * Note that node_dip is already NULL if unconfigure is in
32000Sstevel@tonic-gate 	 * progress.
32010Sstevel@tonic-gate 	 */
32020Sstevel@tonic-gate 	node_data = ibnex_is_node_data_present(node_type, (void *)port_attr,
32030Sstevel@tonic-gate 	    index, pkey);
3204*8082SRamaswamy.Tummala@Sun.COM 
3205*8082SRamaswamy.Tummala@Sun.COM 	/*
3206*8082SRamaswamy.Tummala@Sun.COM 	 * If this node has been explicity unconfigured by cfgadm, then it can
3207*8082SRamaswamy.Tummala@Sun.COM 	 * be configured back again only by cfgadm configure.
3208*8082SRamaswamy.Tummala@Sun.COM 	 */
3209*8082SRamaswamy.Tummala@Sun.COM 	if (node_data && (node_data->node_ap_state ==
3210*8082SRamaswamy.Tummala@Sun.COM 	    IBNEX_NODE_AP_UNCONFIGURED)) {
3211*8082SRamaswamy.Tummala@Sun.COM 		*rval = IBNEX_FAILURE;
3212*8082SRamaswamy.Tummala@Sun.COM 		return (NULL);
3213*8082SRamaswamy.Tummala@Sun.COM 	}
3214*8082SRamaswamy.Tummala@Sun.COM 
32150Sstevel@tonic-gate 	if (node_data && node_data->node_dip) {
32160Sstevel@tonic-gate 		/*
32170Sstevel@tonic-gate 		 * Return NULL if another configure
32180Sstevel@tonic-gate 		 * operation is in progress
32190Sstevel@tonic-gate 		 */
32200Sstevel@tonic-gate 		if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) {
32210Sstevel@tonic-gate 			*rval = IBNEX_BUSY;
32220Sstevel@tonic-gate 			return (NULL);
32230Sstevel@tonic-gate 		} else {
32240Sstevel@tonic-gate 			return (node_data->node_dip);
32250Sstevel@tonic-gate 		}
32260Sstevel@tonic-gate 	} else if (node_data == NULL) {
32270Sstevel@tonic-gate 		/* allocate a new ibnex_node_data_t */
32280Sstevel@tonic-gate 		node_data = ibnex_init_child_nodedata(node_type, port_attr,
32290Sstevel@tonic-gate 		    index, pkey);
3230*8082SRamaswamy.Tummala@Sun.COM 		node_data->node_data.port_node.port_pdip = parent;
32310Sstevel@tonic-gate 	}
32320Sstevel@tonic-gate 
32330Sstevel@tonic-gate 	/*
32340Sstevel@tonic-gate 	 * Return NULL if another unconfigure operation is in progress
32350Sstevel@tonic-gate 	 */
32360Sstevel@tonic-gate 	if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
32370Sstevel@tonic-gate 		*rval = IBNEX_BUSY;
32380Sstevel@tonic-gate 		return (NULL);
32390Sstevel@tonic-gate 	}
32400Sstevel@tonic-gate 
32410Sstevel@tonic-gate 	ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED);
32420Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
32430Sstevel@tonic-gate 
32440Sstevel@tonic-gate 	switch (node_type) {
32450Sstevel@tonic-gate 		case IBNEX_VPPA_COMMSVC_NODE :
32460Sstevel@tonic-gate 			svcname = ibnex.ibnex_vppa_comm_svc_names[index];
3247*8082SRamaswamy.Tummala@Sun.COM 			port_node = &node_data->node_data.port_node;
3248*8082SRamaswamy.Tummala@Sun.COM 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s",
3249*8082SRamaswamy.Tummala@Sun.COM 			    IBNEX_IBPORT_CNAME, port_node->port_num,
3250*8082SRamaswamy.Tummala@Sun.COM 			    port_node->port_pkey, svcname);
32510Sstevel@tonic-gate 			break;
32520Sstevel@tonic-gate 		case IBNEX_HCASVC_COMMSVC_NODE :
32530Sstevel@tonic-gate 			svcname = ibnex.ibnex_hcasvc_comm_svc_names[index];
3254*8082SRamaswamy.Tummala@Sun.COM 			port_node = &node_data->node_data.port_node;
3255*8082SRamaswamy.Tummala@Sun.COM 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
3256*8082SRamaswamy.Tummala@Sun.COM 			    IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
32570Sstevel@tonic-gate 			break;
32580Sstevel@tonic-gate 		case IBNEX_PORT_COMMSVC_NODE :
32590Sstevel@tonic-gate 			svcname = ibnex.ibnex_comm_svc_names[index];
3260*8082SRamaswamy.Tummala@Sun.COM 			port_node = &node_data->node_data.port_node;
3261*8082SRamaswamy.Tummala@Sun.COM 			(void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
3262*8082SRamaswamy.Tummala@Sun.COM 			    IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
32630Sstevel@tonic-gate 			break;
32640Sstevel@tonic-gate 		default :
32650Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:"
32660Sstevel@tonic-gate 			    "\tInvalid Node type");
32670Sstevel@tonic-gate 			*rval = IBNEX_FAILURE;
3268*8082SRamaswamy.Tummala@Sun.COM 			mutex_exit(&ibnex.ibnex_mutex);
32690Sstevel@tonic-gate 			ibnex_delete_port_node_data(node_data);
32700Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
32710Sstevel@tonic-gate 			return (NULL);
32720Sstevel@tonic-gate 	}
32730Sstevel@tonic-gate 
3274*8082SRamaswamy.Tummala@Sun.COM 	if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) {
3275*8082SRamaswamy.Tummala@Sun.COM 		if (i_ddi_devi_attached(cdip)) {
3276*8082SRamaswamy.Tummala@Sun.COM 			node_data->node_dip	= cdip;
3277*8082SRamaswamy.Tummala@Sun.COM 			node_data->node_data.port_node.port_pdip = parent;
3278*8082SRamaswamy.Tummala@Sun.COM 			node_data->node_state = IBNEX_CFGADM_CONFIGURED;
3279*8082SRamaswamy.Tummala@Sun.COM 			ddi_set_parent_data(cdip, node_data);
3280*8082SRamaswamy.Tummala@Sun.COM 			return (cdip);
3281*8082SRamaswamy.Tummala@Sun.COM 		}
3282*8082SRamaswamy.Tummala@Sun.COM 	} else {
3283*8082SRamaswamy.Tummala@Sun.COM 		ndi_devi_alloc_sleep(parent,
3284*8082SRamaswamy.Tummala@Sun.COM 		    IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip);
3285*8082SRamaswamy.Tummala@Sun.COM 	}
3286*8082SRamaswamy.Tummala@Sun.COM 
3287*8082SRamaswamy.Tummala@Sun.COM 	node_data->node_dip	= cdip;
3288*8082SRamaswamy.Tummala@Sun.COM 	ddi_set_parent_data(cdip, node_data);
3289*8082SRamaswamy.Tummala@Sun.COM 	mutex_exit(&ibnex.ibnex_mutex);
3290*8082SRamaswamy.Tummala@Sun.COM 
3291*8082SRamaswamy.Tummala@Sun.COM 
32920Sstevel@tonic-gate 	if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) ==
32930Sstevel@tonic-gate 	    IBNEX_SUCCESS) {
32940Sstevel@tonic-gate 		if (flag == IBNEX_DEVFS_ENUMERATE)
32950Sstevel@tonic-gate 			ret = ndi_devi_bind_driver(cdip, 0);
32960Sstevel@tonic-gate 		else
32970Sstevel@tonic-gate 			ret = ndi_devi_online(cdip, 0);
32980Sstevel@tonic-gate 		if (ret == NDI_SUCCESS) {
32990Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
33000Sstevel@tonic-gate 			node_data->node_state	= IBNEX_CFGADM_CONFIGURED;
3301*8082SRamaswamy.Tummala@Sun.COM 			node_data->node_data.port_node.port_pdip = parent;
33020Sstevel@tonic-gate 			return (cdip);
33030Sstevel@tonic-gate 		}
33040Sstevel@tonic-gate 	}
3305*8082SRamaswamy.Tummala@Sun.COM 
33060Sstevel@tonic-gate 	*rval = IBNEX_FAILURE;
33070Sstevel@tonic-gate 	ibnex_delete_port_node_data(node_data);
33080Sstevel@tonic-gate 	(void) ndi_devi_free(cdip);
33090Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
33100Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit");
33110Sstevel@tonic-gate 	return (NULL);
33120Sstevel@tonic-gate }
33130Sstevel@tonic-gate 
33140Sstevel@tonic-gate 
33150Sstevel@tonic-gate /*
33160Sstevel@tonic-gate  * ibnex_create_port_node_prop()
33170Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
33180Sstevel@tonic-gate  */
33190Sstevel@tonic-gate static int
33200Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr,
33210Sstevel@tonic-gate     dev_info_t *child_dip, char *srvname, ib_pkey_t pkey)
33220Sstevel@tonic-gate {
33230Sstevel@tonic-gate 	if (ibnex_create_port_compatible_prop(child_dip,
33240Sstevel@tonic-gate 	    srvname, port_attr) != DDI_PROP_SUCCESS) {
33250Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
33260Sstevel@tonic-gate 		    "\tcreate_port_node_prop: compatible update failed");
33270Sstevel@tonic-gate 		return (IBNEX_FAILURE);
33280Sstevel@tonic-gate 	}
33290Sstevel@tonic-gate 	if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
33300Sstevel@tonic-gate 	    "port-pkey", pkey) != DDI_PROP_SUCCESS)) {
33310Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
33320Sstevel@tonic-gate 		    "\tcreate_port_node_prop: port-num update failed");
33330Sstevel@tonic-gate 		return (IBNEX_FAILURE);
33340Sstevel@tonic-gate 	}
33350Sstevel@tonic-gate 
33360Sstevel@tonic-gate 	/*
33370Sstevel@tonic-gate 	 * For HCA_SVC device nodes, port_num will be 0.
33380Sstevel@tonic-gate 	 * Do not create the "port-number" & "port-guid" properties.
33390Sstevel@tonic-gate 	 */
33400Sstevel@tonic-gate 	if (port_attr->pa_port_num != 0) {
33410Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
33425470Spramodbg 		    "port-number", port_attr->pa_port_num) !=
33430Sstevel@tonic-gate 		    DDI_PROP_SUCCESS) {
33440Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
33450Sstevel@tonic-gate 			    "\tcreate_port_node_prop: port-num update failed");
33460Sstevel@tonic-gate 			return (IBNEX_FAILURE);
33470Sstevel@tonic-gate 		}
33480Sstevel@tonic-gate 		if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
33495470Spramodbg 		    "port-guid", port_attr->pa_port_guid) !=
33500Sstevel@tonic-gate 		    DDI_PROP_SUCCESS) {
33510Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
33520Sstevel@tonic-gate 			    "\tcreate_port_node_prop: port-guid update failed");
33530Sstevel@tonic-gate 			return (IBNEX_FAILURE);
33540Sstevel@tonic-gate 		}
33550Sstevel@tonic-gate 	} else {
33560Sstevel@tonic-gate 		ibdm_hca_list_t	*hca_list;
33570Sstevel@tonic-gate 
33580Sstevel@tonic-gate 		/*
33590Sstevel@tonic-gate 		 * HCA_SVC nodes require "num-ports" & "port-guids"
33600Sstevel@tonic-gate 		 * properties.
33610Sstevel@tonic-gate 		 *
33620Sstevel@tonic-gate 		 * To create the num-ports & port-guids attribute :
33630Sstevel@tonic-gate 		 * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid)
33640Sstevel@tonic-gate 		 * 2. Form the array of port GUIDs.
33650Sstevel@tonic-gate 		 */
33660Sstevel@tonic-gate 		if ((hca_list = ibdm_ibnex_get_hca_info_by_guid(
33670Sstevel@tonic-gate 		    port_attr->pa_hca_guid)) == NULL) {
33680Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
33690Sstevel@tonic-gate 			    "\tcreate_port_node_prop: hca_info_by_guid failed");
33700Sstevel@tonic-gate 			return (IBNEX_FAILURE);
33710Sstevel@tonic-gate 		}
33720Sstevel@tonic-gate 
33730Sstevel@tonic-gate 		if (hca_list->hl_nports != 0) {
33740Sstevel@tonic-gate 			ib_guid_t	*port_guids;
33750Sstevel@tonic-gate 			uint8_t		portnum;
33760Sstevel@tonic-gate 
33770Sstevel@tonic-gate 			ASSERT(hca_list->hl_port_attr != NULL);
33780Sstevel@tonic-gate 
33790Sstevel@tonic-gate 			port_guids = kmem_zalloc(
33800Sstevel@tonic-gate 			    hca_list->hl_nports * sizeof (ib_guid_t),
33810Sstevel@tonic-gate 			    KM_SLEEP);
33820Sstevel@tonic-gate 
33830Sstevel@tonic-gate 			for (portnum = 0; portnum < hca_list->hl_nports;
33840Sstevel@tonic-gate 			    portnum++) {
33850Sstevel@tonic-gate 				port_guids[portnum] = (hca_list->
33860Sstevel@tonic-gate 				    hl_port_attr[portnum]).pa_port_guid;
33870Sstevel@tonic-gate 			}
33880Sstevel@tonic-gate 
33890Sstevel@tonic-gate 			if (ndi_prop_update_int64_array(DDI_DEV_T_NONE,
33900Sstevel@tonic-gate 			    child_dip, "port-guids", (int64_t *)port_guids,
33910Sstevel@tonic-gate 			    hca_list->hl_nports) != DDI_PROP_SUCCESS) {
33920Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
33930Sstevel@tonic-gate 				    "\tcreate_port_node_prop: port-guids "
33940Sstevel@tonic-gate 				    "create failed");
33950Sstevel@tonic-gate 				kmem_free(port_guids, hca_list->hl_nports *
33960Sstevel@tonic-gate 				    sizeof (ib_guid_t));
33970Sstevel@tonic-gate 				ibdm_ibnex_free_hca_list(hca_list);
33980Sstevel@tonic-gate 				return (IBNEX_FAILURE);
33990Sstevel@tonic-gate 			}
34000Sstevel@tonic-gate 			kmem_free(port_guids, hca_list->hl_nports *
34010Sstevel@tonic-gate 			    sizeof (ib_guid_t));
34020Sstevel@tonic-gate 		}
34030Sstevel@tonic-gate 
34040Sstevel@tonic-gate 		if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
34055470Spramodbg 		    "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) {
34060Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
34070Sstevel@tonic-gate 			    "\tcreate_port_node_prop: num-ports update failed");
34080Sstevel@tonic-gate 			ibdm_ibnex_free_hca_list(hca_list);
34090Sstevel@tonic-gate 			return (IBNEX_FAILURE);
34100Sstevel@tonic-gate 		}
34110Sstevel@tonic-gate 		ibdm_ibnex_free_hca_list(hca_list);
34120Sstevel@tonic-gate 	}
34130Sstevel@tonic-gate 
34140Sstevel@tonic-gate 	if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
34155470Spramodbg 	    "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) {
34160Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
34170Sstevel@tonic-gate 		    "\tcreate_port_node_prop: hca-guid update failed");
34180Sstevel@tonic-gate 		return (IBNEX_FAILURE);
34190Sstevel@tonic-gate 	}
34200Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
34215470Spramodbg 	    "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) {
34220Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
34230Sstevel@tonic-gate 		    "\tcreate_port_node_prop: product-id update failed");
34240Sstevel@tonic-gate 		return (IBNEX_FAILURE);
34250Sstevel@tonic-gate 	}
34260Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
34275470Spramodbg 	    "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) {
34280Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
34290Sstevel@tonic-gate 		    "\tcreate_port_node_prop: vendor-id update failed");
34300Sstevel@tonic-gate 		return (IBNEX_FAILURE);
34310Sstevel@tonic-gate 	}
34320Sstevel@tonic-gate 	if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version",
34330Sstevel@tonic-gate 	    port_attr->pa_dev_version) != DDI_PROP_SUCCESS) {
34340Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex",
34350Sstevel@tonic-gate 		    "\tcreate_port_node_prop: device-version update failed");
34360Sstevel@tonic-gate 		return (IBNEX_FAILURE);
34370Sstevel@tonic-gate 	}
34380Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
34390Sstevel@tonic-gate }
34400Sstevel@tonic-gate 
34410Sstevel@tonic-gate 
34420Sstevel@tonic-gate /*
34430Sstevel@tonic-gate  * ibnex_str2int()
34440Sstevel@tonic-gate  *	Utility function that converts a string of length  "len" to
34450Sstevel@tonic-gate  *	integer.
34460Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
34470Sstevel@tonic-gate  */
34480Sstevel@tonic-gate static int
34490Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret)
34500Sstevel@tonic-gate {
34510Sstevel@tonic-gate 	int intval = 0, ii;
34520Sstevel@tonic-gate 
34530Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c);
34540Sstevel@tonic-gate 	*ret = IBNEX_SUCCESS;
34550Sstevel@tonic-gate 	for (ii = 0; ii < len; ii ++) {
34560Sstevel@tonic-gate 		if ((c[ii] >= '0') && (c[ii] <= '9'))
34570Sstevel@tonic-gate 			intval = intval * 10 +c[ii] - '0';
34580Sstevel@tonic-gate 		else {
34590Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
34600Sstevel@tonic-gate 			    "\tstr2int: Invalid integer string %s..", c);
34610Sstevel@tonic-gate 			*ret = IBNEX_FAILURE;
34620Sstevel@tonic-gate 			break;
34630Sstevel@tonic-gate 		}
34640Sstevel@tonic-gate 	}
34650Sstevel@tonic-gate 
34660Sstevel@tonic-gate 	return (intval);
34670Sstevel@tonic-gate }
34680Sstevel@tonic-gate 
34690Sstevel@tonic-gate 
34700Sstevel@tonic-gate /*
34710Sstevel@tonic-gate  * ibnex_str2hex()
34720Sstevel@tonic-gate  *	Utility functions that converts a string of length  "len" to
34730Sstevel@tonic-gate  *	hex value. Note. This function does not handle strings which
34740Sstevel@tonic-gate  *	string length more than 8 bytes.
34750Sstevel@tonic-gate  *
34760Sstevel@tonic-gate  */
34770Sstevel@tonic-gate uint64_t
34780Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret)
34790Sstevel@tonic-gate {
34800Sstevel@tonic-gate 	uint64_t hex = 0, ii;
34810Sstevel@tonic-gate 
34820Sstevel@tonic-gate 	*ret = IBNEX_SUCCESS;
34830Sstevel@tonic-gate 	for (ii = 0; ii < len; ii ++) {
34840Sstevel@tonic-gate 		hex = (ii == 0) ? hex : (hex << 4);
34850Sstevel@tonic-gate 		if ((c[ii] >= '0') && (c[ii] <= '9'))
34860Sstevel@tonic-gate 			hex |= c[ii] - '0';
34870Sstevel@tonic-gate 		else if ((c[ii] >= 'a') && (c[ii] <= 'f'))
34880Sstevel@tonic-gate 			hex |= c[ii] - 'a' + 10;
34890Sstevel@tonic-gate 		else if ((c[ii] >= 'A') && (c[ii] <= 'F'))
34900Sstevel@tonic-gate 			hex |= c[ii] - 'A' + 10;
34910Sstevel@tonic-gate 		else {
34920Sstevel@tonic-gate 			IBTF_DPRINTF_L2("ibnex",
34930Sstevel@tonic-gate 			    "\tstr2hex: Invalid integer string");
34940Sstevel@tonic-gate 			*ret = IBNEX_FAILURE;
34950Sstevel@tonic-gate 			break;
34960Sstevel@tonic-gate 		}
34970Sstevel@tonic-gate 	}
34980Sstevel@tonic-gate 
34990Sstevel@tonic-gate 	return (hex);
35000Sstevel@tonic-gate }
35010Sstevel@tonic-gate 
35020Sstevel@tonic-gate 
35030Sstevel@tonic-gate /*
35040Sstevel@tonic-gate  * ibnex_create_port_compatible_prop()
35050Sstevel@tonic-gate  *	Creates 'Compatibility' property for port / HCA_SVC device nodes
35060Sstevel@tonic-gate  *	Returns IBNEX_SUCCESS/IBNEX_FAILURE
35070Sstevel@tonic-gate  */
35080Sstevel@tonic-gate static int
35090Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip,
35100Sstevel@tonic-gate     char *comm_svcp, ibdm_port_attr_t *port_attr)
35110Sstevel@tonic-gate {
35120Sstevel@tonic-gate 	int 	rval, i;
35130Sstevel@tonic-gate 	char	*temp;
35140Sstevel@tonic-gate 	char	*compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES];
35150Sstevel@tonic-gate 
35160Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin");
35170Sstevel@tonic-gate 	/*
35180Sstevel@tonic-gate 	 * Initialize the "compatible" property string as below:
35190Sstevel@tonic-gate 	 * Compatible Strings :
35200Sstevel@tonic-gate 	 * 1. ib.V<vid>P<pid>v<revision>.<service name>.
35210Sstevel@tonic-gate 	 * 2. ib.V<vid>P<pid>.<service name>.
35220Sstevel@tonic-gate 	 * 3. ib.<service name>
35230Sstevel@tonic-gate 	 * Leading zeros must be present
35240Sstevel@tonic-gate 	 */
35250Sstevel@tonic-gate 	temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP);
35260Sstevel@tonic-gate 	for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) {
35270Sstevel@tonic-gate 		compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN);
35280Sstevel@tonic-gate 	}
35290Sstevel@tonic-gate 
35300Sstevel@tonic-gate 	(void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
35310Sstevel@tonic-gate 	    "ib.V%06xP%08xv%04x.%s",
35320Sstevel@tonic-gate 	    port_attr->pa_vendorid, port_attr->pa_productid,
35330Sstevel@tonic-gate 	    port_attr->pa_dev_version, comm_svcp);
35340Sstevel@tonic-gate 	(void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
35350Sstevel@tonic-gate 	    "ib.V%06xP%08x.%s",
35360Sstevel@tonic-gate 	    port_attr->pa_vendorid, port_attr->pa_productid,
35370Sstevel@tonic-gate 	    comm_svcp);
35380Sstevel@tonic-gate 	(void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
35390Sstevel@tonic-gate 	    "ib.%s", comm_svcp);
35400Sstevel@tonic-gate 
35410Sstevel@tonic-gate 	for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++)
35420Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]);
35430Sstevel@tonic-gate 
35440Sstevel@tonic-gate 	rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip,
35450Sstevel@tonic-gate 	    "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES);
35460Sstevel@tonic-gate 
35470Sstevel@tonic-gate 	if (rval != DDI_PROP_SUCCESS) {
35480Sstevel@tonic-gate 		kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
35490Sstevel@tonic-gate 		return (IBNEX_FAILURE);
35500Sstevel@tonic-gate 	}
35510Sstevel@tonic-gate 	kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
35520Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
35530Sstevel@tonic-gate }
35540Sstevel@tonic-gate 
35550Sstevel@tonic-gate 
35560Sstevel@tonic-gate /*
35570Sstevel@tonic-gate  * ibnex_delete_port_node_data()
35580Sstevel@tonic-gate  *	Delete the parent private node data from the linked list
35590Sstevel@tonic-gate  *	Deallocate the memory of the port/ioc attributes
35600Sstevel@tonic-gate  *	Deallocate the memory of the node data
35610Sstevel@tonic-gate  */
35620Sstevel@tonic-gate static void
35630Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node)
35640Sstevel@tonic-gate {
35650Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
35660Sstevel@tonic-gate 	if ((node->node_next == NULL) && (node->node_prev == NULL))
35670Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = NULL;
35680Sstevel@tonic-gate 	else if (node->node_next == NULL)
35690Sstevel@tonic-gate 		node->node_prev->node_next = NULL;
35700Sstevel@tonic-gate 	else if (node->node_prev == NULL) {
35710Sstevel@tonic-gate 		node->node_next->node_prev = NULL;
35720Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = node->node_next;
35730Sstevel@tonic-gate 	} else {
35740Sstevel@tonic-gate 		node->node_prev->node_next = node->node_next;
35750Sstevel@tonic-gate 		node->node_next->node_prev = node->node_prev;
35760Sstevel@tonic-gate 	}
35770Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
35780Sstevel@tonic-gate 	kmem_free(node, sizeof (ibnex_node_data_t));
35790Sstevel@tonic-gate }
35800Sstevel@tonic-gate 
35810Sstevel@tonic-gate 
35820Sstevel@tonic-gate /*
35830Sstevel@tonic-gate  * ibnex_is_node_data_present()
35840Sstevel@tonic-gate  *	Checks whether ibnex_node_t is created already
35850Sstevel@tonic-gate  *	Returns ibnex_node_data_t if found, otherwise NULL
35860Sstevel@tonic-gate  */
35870Sstevel@tonic-gate static ibnex_node_data_t *
35880Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr,
35890Sstevel@tonic-gate     int index, ib_pkey_t pkey)
35900Sstevel@tonic-gate {
35910Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
35920Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
35930Sstevel@tonic-gate 	if (node_type == IBNEX_IOC_NODE) {
35940Sstevel@tonic-gate 		ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr;
35950Sstevel@tonic-gate 
35960Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL;
35970Sstevel@tonic-gate 		    nodep = nodep->node_next) {
35980Sstevel@tonic-gate 			if (nodep->node_data.ioc_node.ioc_guid ==
35990Sstevel@tonic-gate 			    ioc_infop->ioc_profile.ioc_guid) {
36000Sstevel@tonic-gate 				return (nodep);
36010Sstevel@tonic-gate 			}
36020Sstevel@tonic-gate 		}
36030Sstevel@tonic-gate 
36040Sstevel@tonic-gate 	} else if (node_type == IBNEX_PSEUDO_NODE) {
36050Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
36060Sstevel@tonic-gate 		    nodep = nodep->node_next)
36070Sstevel@tonic-gate 			if (strcmp(nodep->node_data.pseudo_node.
36080Sstevel@tonic-gate 			    pseudo_node_addr, (char *)attr) == 0)
36090Sstevel@tonic-gate 				return (nodep);
36100Sstevel@tonic-gate 
36110Sstevel@tonic-gate 	} else {
36120Sstevel@tonic-gate 		ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr;
36130Sstevel@tonic-gate 
36140Sstevel@tonic-gate 		for (nodep = ibnex.ibnex_port_node_head; nodep != NULL;
36150Sstevel@tonic-gate 		    nodep = nodep->node_next) {
36160Sstevel@tonic-gate 			if ((nodep->node_data.port_node.port_guid ==
36170Sstevel@tonic-gate 			    pattrp->pa_port_guid) &&
36180Sstevel@tonic-gate 			    (nodep->node_data.port_node.port_commsvc_idx ==
36190Sstevel@tonic-gate 			    index) &&
36200Sstevel@tonic-gate 			    (nodep->node_data.port_node.port_pkey == pkey)) {
36210Sstevel@tonic-gate 				return (nodep);
36220Sstevel@tonic-gate 			}
36230Sstevel@tonic-gate 		}
36240Sstevel@tonic-gate 	}
36250Sstevel@tonic-gate 	return (NULL);
36260Sstevel@tonic-gate }
36270Sstevel@tonic-gate 
36280Sstevel@tonic-gate /*
36290Sstevel@tonic-gate  * ibnex_lookup_unit_address_prop:
36300Sstevel@tonic-gate  *
36311093Shiremath  *	If property with name is found, return its value
36320Sstevel@tonic-gate  *	otherwise return NULL.
36330Sstevel@tonic-gate  */
36340Sstevel@tonic-gate static char *
36351093Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name)
36360Sstevel@tonic-gate {
36370Sstevel@tonic-gate 	ddi_prop_t	*propp;
36380Sstevel@tonic-gate 
36391093Shiremath 	/* Search the list of properties for name */
36400Sstevel@tonic-gate 	for (propp = head; propp != NULL; propp = propp->prop_next)  {
36411093Shiremath 		if (strcmp(propp->prop_name, name) != 0)
36420Sstevel@tonic-gate 			continue;
36431093Shiremath 		/* named property should be valid and have a value */
36440Sstevel@tonic-gate 		if (propp->prop_len <= 1)
36450Sstevel@tonic-gate 			break;
36460Sstevel@tonic-gate 		return ((char *)propp->prop_val);
36470Sstevel@tonic-gate 	}
36480Sstevel@tonic-gate 
36490Sstevel@tonic-gate 	return ((char *)0);
36500Sstevel@tonic-gate }
36510Sstevel@tonic-gate 
36520Sstevel@tonic-gate 
36530Sstevel@tonic-gate /*
36540Sstevel@tonic-gate  * ibnex_pseudo_initnodes()
36550Sstevel@tonic-gate  *	This routine is specific to pseudo node information handling
36560Sstevel@tonic-gate  *	Creates a ibnex_node_data_t all pseudo nodes children of ibnex
36570Sstevel@tonic-gate  */
36580Sstevel@tonic-gate void
36590Sstevel@tonic-gate ibnex_pseudo_initnodes()
36600Sstevel@tonic-gate {
36610Sstevel@tonic-gate 	int			pnam_len, len;
36620Sstevel@tonic-gate 	ibnex_node_data_t	*nodep;
36630Sstevel@tonic-gate 	struct hwc_spec		*list, *spec;
36640Sstevel@tonic-gate 	char			*node_addr, *temp, *unit_addr;
36651093Shiremath 	char			*node_type;
36660Sstevel@tonic-gate 
36670Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes");
36680Sstevel@tonic-gate 
36690Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
36700Sstevel@tonic-gate 	/*
36710Sstevel@tonic-gate 	 * get a list of all "pseudo" children of "ib".
36720Sstevel@tonic-gate 	 * for these children initialize/allocate an internal
36730Sstevel@tonic-gate 	 * ibnex_node_data_t.
36740Sstevel@tonic-gate 	 */
36750Sstevel@tonic-gate 	list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1);
36760Sstevel@tonic-gate 	for (spec = list; spec != NULL; spec = spec->hwc_next) {
36770Sstevel@tonic-gate 		if (spec->hwc_devi_sys_prop_ptr == NULL)
36780Sstevel@tonic-gate 			continue;
36790Sstevel@tonic-gate 
36801093Shiremath 		/* Check "ib-node-type" property for IOC .conf */
36811093Shiremath 		node_type = ibnex_lookup_named_prop(
36821093Shiremath 		    spec->hwc_devi_sys_prop_ptr, "ib-node-type");
36831093Shiremath 
36840Sstevel@tonic-gate 		/* "unit-address" property should be present */
36851093Shiremath 		temp = ibnex_lookup_named_prop(
36861093Shiremath 		    spec->hwc_devi_sys_prop_ptr, "unit-address");
36870Sstevel@tonic-gate 		if (temp == NULL)
36880Sstevel@tonic-gate 			continue;
36890Sstevel@tonic-gate 
36900Sstevel@tonic-gate 		pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2;
36910Sstevel@tonic-gate 
36920Sstevel@tonic-gate 		node_addr = kmem_zalloc(pnam_len, KM_SLEEP);
36930Sstevel@tonic-gate 
36940Sstevel@tonic-gate 		(void) snprintf(node_addr,
36950Sstevel@tonic-gate 		    pnam_len, "%s,%s", spec->hwc_devi_name, temp);
36960Sstevel@tonic-gate 
36970Sstevel@tonic-gate 		nodep = ibnex_is_node_data_present(
36980Sstevel@tonic-gate 		    IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0);
36990Sstevel@tonic-gate 
37000Sstevel@tonic-gate 		if (nodep) {
37010Sstevel@tonic-gate 			kmem_free(node_addr, pnam_len);
37020Sstevel@tonic-gate 			continue;
37030Sstevel@tonic-gate 		}
37040Sstevel@tonic-gate 
37050Sstevel@tonic-gate 		nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE,
37060Sstevel@tonic-gate 		    (void *)spec->hwc_devi_name, 0, 0);
37070Sstevel@tonic-gate 
37080Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_node_addr = node_addr;
37090Sstevel@tonic-gate 		(void) snprintf(nodep->node_data.
37100Sstevel@tonic-gate 		    pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr);
37110Sstevel@tonic-gate 
37120Sstevel@tonic-gate 		len = strlen(temp) + 1;
37130Sstevel@tonic-gate 		unit_addr = (char *)kmem_alloc(len, KM_SLEEP);
37140Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr;
37150Sstevel@tonic-gate 		(void) snprintf(unit_addr, len, "%s", temp);
37160Sstevel@tonic-gate 		nodep->node_data.pseudo_node.pseudo_unit_addr_len = len;
37170Sstevel@tonic-gate 
37181093Shiremath 		if (node_type && strcmp(node_type, "merge") == 0)
37191093Shiremath 			nodep->node_data.pseudo_node.pseudo_merge_node = 1;
37201093Shiremath 
37210Sstevel@tonic-gate 		IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s"
37220Sstevel@tonic-gate 		    " : drv name = %s", unit_addr, spec->hwc_devi_name);
37230Sstevel@tonic-gate 	}
37240Sstevel@tonic-gate 	hwc_free_spec_list(list);
37250Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
37260Sstevel@tonic-gate }
37270Sstevel@tonic-gate 
37280Sstevel@tonic-gate 
37290Sstevel@tonic-gate /*
37300Sstevel@tonic-gate  * ibnex_init_child_nodedata()
37310Sstevel@tonic-gate  *
37320Sstevel@tonic-gate  *	Allocate memory for the parent private data for device node
37330Sstevel@tonic-gate  *	Initializes the parent private child device node data.
37340Sstevel@tonic-gate  *	Returns pointer to the parent private data
37350Sstevel@tonic-gate  */
37360Sstevel@tonic-gate static ibnex_node_data_t *
37370Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index,
37380Sstevel@tonic-gate     ib_pkey_t pkey)
37390Sstevel@tonic-gate {
37400Sstevel@tonic-gate 	char			 *devi_name;
37410Sstevel@tonic-gate 	ibdm_ioc_info_t		 *ioc_info;
37420Sstevel@tonic-gate 	ibnex_ioc_node_t	 *ioc_node;
37430Sstevel@tonic-gate 	ibnex_node_data_t	 *node_data;
37440Sstevel@tonic-gate 	ib_dm_ioc_ctrl_profile_t *ioc_profile;
37450Sstevel@tonic-gate 
37460Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
37470Sstevel@tonic-gate 
37480Sstevel@tonic-gate 	node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP);
3749*8082SRamaswamy.Tummala@Sun.COM 	node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED;
37500Sstevel@tonic-gate 	node_data->node_state = IBNEX_CFGADM_CONFIGURING;
37510Sstevel@tonic-gate 	node_data->node_type	= node_type;
37520Sstevel@tonic-gate 
37530Sstevel@tonic-gate 	if (node_type == IBNEX_IOC_NODE) {
37540Sstevel@tonic-gate 		ioc_info	= (ibdm_ioc_info_t *)attr;
37550Sstevel@tonic-gate 		ioc_profile	= &ioc_info->ioc_profile;
37560Sstevel@tonic-gate 		ioc_node	= &node_data->node_data.ioc_node;
37570Sstevel@tonic-gate 
37580Sstevel@tonic-gate 		ioc_node->iou_guid = ioc_info->ioc_iou_guid;
37590Sstevel@tonic-gate 		ioc_node->ioc_guid = ioc_profile->ioc_guid;
37600Sstevel@tonic-gate 		(void) strncpy(ioc_node->ioc_id_string,
37610Sstevel@tonic-gate 		    (char *)ioc_profile->ioc_id_string,
37620Sstevel@tonic-gate 		    IB_DM_IOC_ID_STRING_LEN);
37630Sstevel@tonic-gate 		ioc_node->ioc_ngids = ioc_info->ioc_nportgids;
37640Sstevel@tonic-gate 
37650Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_ioc_node_head;
37660Sstevel@tonic-gate 		node_data->node_prev = NULL;
37670Sstevel@tonic-gate 		if (ibnex.ibnex_ioc_node_head)
37680Sstevel@tonic-gate 			ibnex.ibnex_ioc_node_head->node_prev = node_data;
37690Sstevel@tonic-gate 		ibnex.ibnex_ioc_node_head = node_data;
37700Sstevel@tonic-gate 	} else if (node_type == IBNEX_PSEUDO_NODE) {
37710Sstevel@tonic-gate 		devi_name = (char *)attr;
37720Sstevel@tonic-gate 		node_data->node_data.pseudo_node.pseudo_devi_name =
37730Sstevel@tonic-gate 		    kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP);
37740Sstevel@tonic-gate 		(void) strncpy(node_data->node_data.pseudo_node.
37750Sstevel@tonic-gate 		    pseudo_devi_name, devi_name, strlen(devi_name));
37760Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_pseudo_node_head;
37770Sstevel@tonic-gate 		node_data->node_prev = NULL;
37780Sstevel@tonic-gate 		if (ibnex.ibnex_pseudo_node_head)
37790Sstevel@tonic-gate 			ibnex.ibnex_pseudo_node_head->node_prev = node_data;
37800Sstevel@tonic-gate 		ibnex.ibnex_pseudo_node_head = node_data;
37810Sstevel@tonic-gate 	} else {
37820Sstevel@tonic-gate 		node_data->node_data.port_node.port_hcaguid =
37830Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_hca_guid;
37840Sstevel@tonic-gate 		node_data->node_data.port_node.port_guid =
37850Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_port_guid;
37860Sstevel@tonic-gate 		node_data->node_data.port_node.port_num =
37870Sstevel@tonic-gate 		    ((ibdm_port_attr_t *)attr)->pa_port_num;
37880Sstevel@tonic-gate 		node_data->node_data.port_node.port_commsvc_idx = index;
37890Sstevel@tonic-gate 		node_data->node_data.port_node.port_pkey = pkey;
37900Sstevel@tonic-gate 
37910Sstevel@tonic-gate 		node_data->node_next = ibnex.ibnex_port_node_head;
37920Sstevel@tonic-gate 		node_data->node_prev = NULL;
37930Sstevel@tonic-gate 		if (ibnex.ibnex_port_node_head)
37940Sstevel@tonic-gate 			ibnex.ibnex_port_node_head->node_prev = node_data;
37950Sstevel@tonic-gate 		ibnex.ibnex_port_node_head = node_data;
37960Sstevel@tonic-gate 	}
37970Sstevel@tonic-gate 	return (node_data);
37980Sstevel@tonic-gate }
37990Sstevel@tonic-gate 
38000Sstevel@tonic-gate static int
38010Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
38020Sstevel@tonic-gate     char *eventname, ddi_eventcookie_t *cookie)
38030Sstevel@tonic-gate {
38040Sstevel@tonic-gate 	int rc;
38050Sstevel@tonic-gate 
38060Sstevel@tonic-gate 
38070Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)",
38080Sstevel@tonic-gate 	    dip, rdip, eventname, cookie);
38090Sstevel@tonic-gate 
38100Sstevel@tonic-gate 	rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl,
38110Sstevel@tonic-gate 	    rdip, eventname, cookie, NDI_EVENT_NOPASS);
38120Sstevel@tonic-gate 	if (rc == NDI_SUCCESS) {
38130Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
38140Sstevel@tonic-gate 		ibnex.ibnex_prop_update_evt_cookie = *cookie;
38150Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
38160Sstevel@tonic-gate 	}
38170Sstevel@tonic-gate 
38180Sstevel@tonic-gate 	return (rc);
38190Sstevel@tonic-gate }
38200Sstevel@tonic-gate 
38210Sstevel@tonic-gate static int
38220Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
38230Sstevel@tonic-gate     ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip,
38240Sstevel@tonic-gate     ddi_eventcookie_t cookie, void *arg, void *bus_impldata),
38250Sstevel@tonic-gate     void *arg, ddi_callback_id_t *cb_id)
38260Sstevel@tonic-gate {
38270Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
38280Sstevel@tonic-gate 	    "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)",
38290Sstevel@tonic-gate 	    dip, rdip, cookie, callback, arg, cb_id);
38300Sstevel@tonic-gate 
38310Sstevel@tonic-gate 	return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl,
38320Sstevel@tonic-gate 	    rdip, cookie, callback, arg, NDI_SLEEP, cb_id));
38330Sstevel@tonic-gate }
38340Sstevel@tonic-gate 
38350Sstevel@tonic-gate static int
38360Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
38370Sstevel@tonic-gate {
38380Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)",
38390Sstevel@tonic-gate 	    dip, cb_id);
38400Sstevel@tonic-gate 
38410Sstevel@tonic-gate 	return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl,
38420Sstevel@tonic-gate 	    cb_id));
38430Sstevel@tonic-gate }
38440Sstevel@tonic-gate 
38450Sstevel@tonic-gate static int
38460Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip,
38470Sstevel@tonic-gate     ddi_eventcookie_t cookie, void *bus_impldata)
38480Sstevel@tonic-gate {
38490Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)",
38500Sstevel@tonic-gate 	    dip, rdip, cookie, bus_impldata);
38510Sstevel@tonic-gate 
38520Sstevel@tonic-gate 	return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip,
38530Sstevel@tonic-gate 	    cookie, bus_impldata));
38540Sstevel@tonic-gate }
38550Sstevel@tonic-gate 
38560Sstevel@tonic-gate /*
38570Sstevel@tonic-gate  * ibnex_reprobe_ioc_dev()
38580Sstevel@tonic-gate  *
38590Sstevel@tonic-gate  * This could be called as a result of ibt_reprobe_dev request or
38600Sstevel@tonic-gate  * cfgadm command. The function is called from a taskq in case of
38610Sstevel@tonic-gate  * ibt_reprobe_dev and from user context for cfgadm command.
38620Sstevel@tonic-gate  *
38630Sstevel@tonic-gate  * This function reprobes the properties for one IOC dip.
38640Sstevel@tonic-gate  *
38650Sstevel@tonic-gate  * node_reprobe_state should be set before calling this function.
38660Sstevel@tonic-gate  */
38670Sstevel@tonic-gate void
38680Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg)
38690Sstevel@tonic-gate {
38700Sstevel@tonic-gate 	dev_info_t	*dip = (dev_info_t *)arg;
38710Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
38720Sstevel@tonic-gate 	ibnex_ioc_node_t	*ioc_data;
38730Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info;
38740Sstevel@tonic-gate 
38750Sstevel@tonic-gate 	/* ASSERT(NO_LOCKS_HELD); */
38760Sstevel@tonic-gate 	ASSERT(dip != NULL);
38770Sstevel@tonic-gate 
38780Sstevel@tonic-gate 	node_data = ddi_get_parent_data(dip);
38790Sstevel@tonic-gate 	ASSERT(node_data);
38800Sstevel@tonic-gate 
38810Sstevel@tonic-gate 	if (node_data->node_dip == NULL) {
38820Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip");
38830Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
38840Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 0);
38850Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
38860Sstevel@tonic-gate 		return;
38870Sstevel@tonic-gate 	}
38880Sstevel@tonic-gate 	ioc_data = &(node_data->node_data.ioc_node);
38890Sstevel@tonic-gate 
38900Sstevel@tonic-gate 	/* Reprobe the IOC */
38910Sstevel@tonic-gate 	ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid,
38920Sstevel@tonic-gate 	    1);
38930Sstevel@tonic-gate 	if (ioc_info == NULL) {
38940Sstevel@tonic-gate 		IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe");
38950Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
38960Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 1);
38970Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
38980Sstevel@tonic-gate 		return;
38990Sstevel@tonic-gate 	}
39000Sstevel@tonic-gate 
39010Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
39020Sstevel@tonic-gate 	if (node_data->node_dip)
39030Sstevel@tonic-gate 		ibnex_update_prop(node_data, ioc_info);
39040Sstevel@tonic-gate 	ibnex_wakeup_reprobe_ioc(node_data, 0);
39050Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
39060Sstevel@tonic-gate 
39070Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc_info);
39080Sstevel@tonic-gate }
39090Sstevel@tonic-gate 
39100Sstevel@tonic-gate /*
39110Sstevel@tonic-gate  * ibnex_reprobe_all()
39120Sstevel@tonic-gate  *
39130Sstevel@tonic-gate  * This could be called as a result of cfgadm command. The function
39140Sstevel@tonic-gate  * is called from user context.
39150Sstevel@tonic-gate  *
39160Sstevel@tonic-gate  * This function reprobes the properties for all IOC dips.
39170Sstevel@tonic-gate  *
39180Sstevel@tonic-gate  * ibnex_reprobe_state should be set before calling this function.
39190Sstevel@tonic-gate  */
39200Sstevel@tonic-gate void
39210Sstevel@tonic-gate ibnex_reprobe_ioc_all()
39220Sstevel@tonic-gate {
39230Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
39240Sstevel@tonic-gate 	ibdm_ioc_info_t		*ioc_info_list, *ioc;
39250Sstevel@tonic-gate 
39260Sstevel@tonic-gate 	/* ASSERT(NO_LOCKS_HELD); */
39270Sstevel@tonic-gate 
39280Sstevel@tonic-gate 	/* Sweep the fabric */
39290Sstevel@tonic-gate 	ioc = ioc_info_list = ibdm_ibnex_get_ioc_list(
39300Sstevel@tonic-gate 	    IBDM_IBNEX_REPROBE_ALL);
39310Sstevel@tonic-gate 	if (ioc_info_list == NULL) {
39320Sstevel@tonic-gate 		mutex_enter(&ibnex.ibnex_mutex);
39330Sstevel@tonic-gate 		ibnex_wakeup_reprobe_all();
39340Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
39350Sstevel@tonic-gate 		return;
39360Sstevel@tonic-gate 	}
39370Sstevel@tonic-gate 
39380Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
39390Sstevel@tonic-gate 	while (ioc_info_list) {
39400Sstevel@tonic-gate 		if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
39410Sstevel@tonic-gate 		    ioc_info_list, 0, 0)) != NULL &&
39420Sstevel@tonic-gate 		    node_data->node_dip != NULL) {
39430Sstevel@tonic-gate 			ibnex_update_prop(node_data, ioc_info_list);
39440Sstevel@tonic-gate 		}
39450Sstevel@tonic-gate 		ioc_info_list = ioc_info_list->ioc_next;
39460Sstevel@tonic-gate 	}
39470Sstevel@tonic-gate 	ibnex_wakeup_reprobe_all();
39480Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
39490Sstevel@tonic-gate 
39500Sstevel@tonic-gate 	ibdm_ibnex_free_ioc_list(ioc);
39510Sstevel@tonic-gate }
39520Sstevel@tonic-gate 
39530Sstevel@tonic-gate /*
39540Sstevel@tonic-gate  * Update the properties, if it has modified and notify IBTF client.
39550Sstevel@tonic-gate  */
39560Sstevel@tonic-gate static void
39570Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info)
39580Sstevel@tonic-gate {
39590Sstevel@tonic-gate 	ibt_prop_update_payload_t	evt_data;
39600Sstevel@tonic-gate 	dev_info_t	*dip = node_data->node_dip;
39610Sstevel@tonic-gate 	ddi_eventcookie_t	evt_cookie;
39620Sstevel@tonic-gate 	ibnex_ioc_node_t *ioc;
39630Sstevel@tonic-gate 
39640Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
39650Sstevel@tonic-gate 
39660Sstevel@tonic-gate 	ASSERT(dip != NULL);
39670Sstevel@tonic-gate 
39680Sstevel@tonic-gate 	ioc = &node_data->node_data.ioc_node;
39690Sstevel@tonic-gate 
39700Sstevel@tonic-gate 	evt_data = ioc_info->ioc_info_updated;
39710Sstevel@tonic-gate 	evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
39720Sstevel@tonic-gate 
39730Sstevel@tonic-gate 	/*
39740Sstevel@tonic-gate 	 * For a disconnected IOC :
39750Sstevel@tonic-gate 	 *	Store the ioc_profile for supplying cfgadm info
39760Sstevel@tonic-gate 	 *	ibdm maintains no info of disconnected IOC
39770Sstevel@tonic-gate 	 *
39780Sstevel@tonic-gate 	 * For reconnected IOC :
39790Sstevel@tonic-gate 	 *	ibdm has info of previous service entries
39800Sstevel@tonic-gate 	 *	ioc_profile maintained by ibnexus is used to
39810Sstevel@tonic-gate 	 *	update ib_srv_prop_updated.
39820Sstevel@tonic-gate 	 *	Free the ibnex maintained ioc_profile
39830Sstevel@tonic-gate 	 */
39840Sstevel@tonic-gate 	if (ioc_info->ioc_nportgids == 0) {
39850Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
39860Sstevel@tonic-gate 		    "\tupdate_prop:  IOC disconnected");
39870Sstevel@tonic-gate 		ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc(
39880Sstevel@tonic-gate 		    sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP);
39890Sstevel@tonic-gate 		bcopy(&ioc_info->ioc_profile, ioc->ioc_profile,
39900Sstevel@tonic-gate 		    sizeof (ib_dm_ioc_ctrl_profile_t));
39910Sstevel@tonic-gate 
39920Sstevel@tonic-gate 		ibnex.ibnex_num_disconnect_iocs++;
39930Sstevel@tonic-gate 	} else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 &&
39940Sstevel@tonic-gate 	    ioc->ioc_profile != NULL) {
39950Sstevel@tonic-gate 		IBTF_DPRINTF_L4("ibnex",
39960Sstevel@tonic-gate 		    "\tupdate_prop: IOC reconnected");
39970Sstevel@tonic-gate 		if (ioc->ioc_profile->ioc_service_entries !=
39980Sstevel@tonic-gate 		    ioc_info->ioc_profile.ioc_service_entries)
39990Sstevel@tonic-gate 			evt_data.ib_srv_prop_updated = 1;
40000Sstevel@tonic-gate 
40010Sstevel@tonic-gate 		ibnex.ibnex_num_disconnect_iocs--;
40020Sstevel@tonic-gate 		kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t));
40030Sstevel@tonic-gate 		ioc->ioc_profile = NULL;
40040Sstevel@tonic-gate 	}
40050Sstevel@tonic-gate 
40060Sstevel@tonic-gate 	/* Update the properties that have changed */
40070Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
40080Sstevel@tonic-gate 	if (evt_data.ib_gid_prop_updated) {
40090Sstevel@tonic-gate 		if (ibnex_create_ioc_portgid_prop(dip, ioc_info) !=
40100Sstevel@tonic-gate 		    IBNEX_SUCCESS) {
40110Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
40120Sstevel@tonic-gate 			return;
40130Sstevel@tonic-gate 		}
40140Sstevel@tonic-gate 	}
40150Sstevel@tonic-gate 	if (evt_data.ib_srv_prop_updated) {
40160Sstevel@tonic-gate 		if (ioc_info->ioc_profile.ioc_service_entries != 0 &&
40170Sstevel@tonic-gate 		    (ibnex_create_ioc_srv_props(dip, ioc_info) !=
40180Sstevel@tonic-gate 		    IBNEX_SUCCESS)) {
40190Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
40200Sstevel@tonic-gate 			return;
40210Sstevel@tonic-gate 		} else if (ioc_info->ioc_profile.ioc_service_entries == 0) {
40220Sstevel@tonic-gate 			(void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
40230Sstevel@tonic-gate 			    "service-id");
40240Sstevel@tonic-gate 			(void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
40250Sstevel@tonic-gate 			    "service-name");
40260Sstevel@tonic-gate 		}
40270Sstevel@tonic-gate 	}
40280Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
40290Sstevel@tonic-gate 	ioc->ioc_ngids = ioc_info->ioc_nportgids;
40300Sstevel@tonic-gate 
40310Sstevel@tonic-gate 	/*
40320Sstevel@tonic-gate 	 * Post an event if :
40330Sstevel@tonic-gate 	 *	1. Properites have changed or NOTIFY_ALWAYS is set.
40340Sstevel@tonic-gate 	 *	2. child dip is configured and a valid cookie for
40350Sstevel@tonic-gate 	 *	   IB_PROP_UPDATE_EVENT.
40360Sstevel@tonic-gate 	 */
40370Sstevel@tonic-gate 	if ((evt_data.ib_prop_updated != 0 ||
40380Sstevel@tonic-gate 	    (node_data->node_reprobe_state &
40390Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) &&
40400Sstevel@tonic-gate 	    ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) &&
40415470Spramodbg 	    (evt_cookie != NULL))) {
40420Sstevel@tonic-gate 			mutex_exit(&ibnex.ibnex_mutex);
40430Sstevel@tonic-gate 
40440Sstevel@tonic-gate 			if (ndi_post_event(ibnex.ibnex_dip, dip,
40450Sstevel@tonic-gate 			    evt_cookie, &evt_data) != NDI_SUCCESS)
40460Sstevel@tonic-gate 				IBTF_DPRINTF_L2("ibnex",
40470Sstevel@tonic-gate 				    "\tndi_post_event failed\n");
40480Sstevel@tonic-gate 
40490Sstevel@tonic-gate 			mutex_enter(&ibnex.ibnex_mutex);
40500Sstevel@tonic-gate 	}
40510Sstevel@tonic-gate 
40520Sstevel@tonic-gate 	/*
40530Sstevel@tonic-gate 	 * Cleanup node_reprobe_state, for ibt_reprobe_dev
40540Sstevel@tonic-gate 	 * requests, when reprobe all / node reprobe is in
40550Sstevel@tonic-gate 	 * progress. ibnex_reprobe_ioc_dev is not called
40560Sstevel@tonic-gate 	 * in this case.
40570Sstevel@tonic-gate 	 */
40580Sstevel@tonic-gate 	if (node_data->node_reprobe_state ==
40590Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)
40600Sstevel@tonic-gate 		ibnex_wakeup_reprobe_ioc(node_data, 0);
40610Sstevel@tonic-gate }
40620Sstevel@tonic-gate 
40630Sstevel@tonic-gate static ibnex_rval_t
40640Sstevel@tonic-gate ibnex_unique_svcname(char *svcname)
40650Sstevel@tonic-gate {
40660Sstevel@tonic-gate 	int i;
40670Sstevel@tonic-gate 
40680Sstevel@tonic-gate 	/* Check Port Services */
40690Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++)
40700Sstevel@tonic-gate 		if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname,
40710Sstevel@tonic-gate 		    ibnex.ibnex_comm_svc_names[i], 4) == 0)
40720Sstevel@tonic-gate 			return (IBNEX_FAILURE);
40730Sstevel@tonic-gate 
40740Sstevel@tonic-gate 	/* Check VPPA Services */
40750Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++)
40760Sstevel@tonic-gate 		if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname,
40770Sstevel@tonic-gate 		    ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0)
40780Sstevel@tonic-gate 			return (IBNEX_FAILURE);
40790Sstevel@tonic-gate 
40800Sstevel@tonic-gate 	/* Check HCA_SVC Services */
40810Sstevel@tonic-gate 	for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++)
40820Sstevel@tonic-gate 		if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname,
40830Sstevel@tonic-gate 		    ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0)
40840Sstevel@tonic-gate 			return (IBNEX_FAILURE);
40850Sstevel@tonic-gate 
40860Sstevel@tonic-gate 	return (IBNEX_SUCCESS);
40870Sstevel@tonic-gate }
40880Sstevel@tonic-gate 
40890Sstevel@tonic-gate static void
40900Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg)
40910Sstevel@tonic-gate {
40920Sstevel@tonic-gate 	dev_info_t	*dip = (dev_info_t *)arg;
40930Sstevel@tonic-gate 	ibnex_node_data_t	*node_data;
40940Sstevel@tonic-gate 
40950Sstevel@tonic-gate 	ASSERT(dip != NULL);
40960Sstevel@tonic-gate 	node_data = ddi_get_parent_data(dip);
40970Sstevel@tonic-gate 	ASSERT(node_data);
40980Sstevel@tonic-gate 
40990Sstevel@tonic-gate 	/*
41000Sstevel@tonic-gate 	 * Return success if:
41010Sstevel@tonic-gate 	 *	1. Reprobe for all nodes are in progress
41020Sstevel@tonic-gate 	 *	2. Reprobe for this node is in progress.
41030Sstevel@tonic-gate 	 * The reprobe in progress will complete eventually and
41040Sstevel@tonic-gate 	 * update the properties, if required.
41050Sstevel@tonic-gate 	 */
41060Sstevel@tonic-gate 	mutex_enter(&ibnex.ibnex_mutex);
41070Sstevel@tonic-gate 	if (ibnex.ibnex_reprobe_state != 0 ||
41080Sstevel@tonic-gate 	    node_data->node_reprobe_state != 0) {
41090Sstevel@tonic-gate 		/*
41100Sstevel@tonic-gate 		 * Setting NOTIFY_ALWAYS to ensure that
41110Sstevel@tonic-gate 		 * DDI event is delivered always for
41120Sstevel@tonic-gate 		 * ibt_reprobe_dev
41130Sstevel@tonic-gate 		 */
41140Sstevel@tonic-gate 		node_data->node_reprobe_state |=
41150Sstevel@tonic-gate 		    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
41160Sstevel@tonic-gate 		mutex_exit(&ibnex.ibnex_mutex);
41170Sstevel@tonic-gate 		return;
41180Sstevel@tonic-gate 	}
41190Sstevel@tonic-gate 	node_data->node_reprobe_state =
41200Sstevel@tonic-gate 	    IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
41210Sstevel@tonic-gate 	mutex_exit(&ibnex.ibnex_mutex);
41220Sstevel@tonic-gate 	ibnex_reprobe_ioc_dev(arg);
41230Sstevel@tonic-gate }
41240Sstevel@tonic-gate 
41250Sstevel@tonic-gate 
41260Sstevel@tonic-gate /*
41270Sstevel@tonic-gate  * MPxIO pathmangement routines. Currently IB nexus does not support
41280Sstevel@tonic-gate  * any kind of pathmangement. So, just return success to make MPxIO
41290Sstevel@tonic-gate  * framework happy.
41300Sstevel@tonic-gate  */
41310Sstevel@tonic-gate /*ARGSUSED*/
41320Sstevel@tonic-gate static int
4133*8082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
41340Sstevel@tonic-gate {
4135*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip);
41360Sstevel@tonic-gate 	return (MDI_SUCCESS);
41370Sstevel@tonic-gate }
41380Sstevel@tonic-gate 
41390Sstevel@tonic-gate 
41400Sstevel@tonic-gate /*ARGSUSED*/
41410Sstevel@tonic-gate static int
4142*8082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
41430Sstevel@tonic-gate {
4144*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t *cdip;
4145*8082SRamaswamy.Tummala@Sun.COM 	ibnex_node_data_t *node_data;
4146*8082SRamaswamy.Tummala@Sun.COM 	int clnt_num_pi;
4147*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip);
4148*8082SRamaswamy.Tummala@Sun.COM 
4149*8082SRamaswamy.Tummala@Sun.COM 	if (pip == NULL)
4150*8082SRamaswamy.Tummala@Sun.COM 		return (MDI_FAILURE);
4151*8082SRamaswamy.Tummala@Sun.COM 	/*
4152*8082SRamaswamy.Tummala@Sun.COM 	 * Get the Client dev_info from the pathinfo.
4153*8082SRamaswamy.Tummala@Sun.COM 	 */
4154*8082SRamaswamy.Tummala@Sun.COM 	cdip = mdi_pi_get_client(pip);
4155*8082SRamaswamy.Tummala@Sun.COM 	if (cdip == NULL)
4156*8082SRamaswamy.Tummala@Sun.COM 		return (MDI_FAILURE);
4157*8082SRamaswamy.Tummala@Sun.COM 
4158*8082SRamaswamy.Tummala@Sun.COM 	/*
4159*8082SRamaswamy.Tummala@Sun.COM 	 * How many PIs do we have from this cdip ?
4160*8082SRamaswamy.Tummala@Sun.COM 	 */
4161*8082SRamaswamy.Tummala@Sun.COM 	clnt_num_pi = mdi_client_get_path_count(cdip);
4162*8082SRamaswamy.Tummala@Sun.COM 
4163*8082SRamaswamy.Tummala@Sun.COM 	/*
4164*8082SRamaswamy.Tummala@Sun.COM 	 * If this is the last PI that is being free'd ( called from
4165*8082SRamaswamy.Tummala@Sun.COM 	 * mdi_pi_free) we have to clean up the node data for the cdip since
4166*8082SRamaswamy.Tummala@Sun.COM 	 * the client would have been detached by mdi_devi_offline.
4167*8082SRamaswamy.Tummala@Sun.COM 	 */
4168*8082SRamaswamy.Tummala@Sun.COM 	if (clnt_num_pi == 1) {
4169*8082SRamaswamy.Tummala@Sun.COM 		for (node_data = ibnex.ibnex_ioc_node_head;
4170*8082SRamaswamy.Tummala@Sun.COM 		    node_data; node_data = node_data->node_next) {
4171*8082SRamaswamy.Tummala@Sun.COM 			if (node_data->node_dip == cdip) {
4172*8082SRamaswamy.Tummala@Sun.COM 				node_data->node_dip = NULL;
4173*8082SRamaswamy.Tummala@Sun.COM 				node_data->node_state =
4174*8082SRamaswamy.Tummala@Sun.COM 				    IBNEX_CFGADM_UNCONFIGURED;
4175*8082SRamaswamy.Tummala@Sun.COM 				return (MDI_SUCCESS);
4176*8082SRamaswamy.Tummala@Sun.COM 			}
4177*8082SRamaswamy.Tummala@Sun.COM 		}
4178*8082SRamaswamy.Tummala@Sun.COM 		for (node_data = ibnex.ibnex_pseudo_node_head;
4179*8082SRamaswamy.Tummala@Sun.COM 		    node_data; node_data = node_data->node_next) {
4180*8082SRamaswamy.Tummala@Sun.COM 			if (node_data->node_dip == cdip) {
4181*8082SRamaswamy.Tummala@Sun.COM 				node_data->node_dip = NULL;
4182*8082SRamaswamy.Tummala@Sun.COM 				node_data->node_state =
4183*8082SRamaswamy.Tummala@Sun.COM 				    IBNEX_CFGADM_UNCONFIGURED;
4184*8082SRamaswamy.Tummala@Sun.COM 				return (MDI_SUCCESS);
4185*8082SRamaswamy.Tummala@Sun.COM 			}
4186*8082SRamaswamy.Tummala@Sun.COM 		}
4187*8082SRamaswamy.Tummala@Sun.COM 	}
41880Sstevel@tonic-gate 	return (MDI_SUCCESS);
41890Sstevel@tonic-gate }
41900Sstevel@tonic-gate 
41910Sstevel@tonic-gate 
41920Sstevel@tonic-gate /*ARGSUSED*/
41930Sstevel@tonic-gate static int
4194*8082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip,
41950Sstevel@tonic-gate 		mdi_pathinfo_state_t state, uint32_t arg1, int arg2)
41960Sstevel@tonic-gate {
41970Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex",
4198*8082SRamaswamy.Tummala@Sun.COM 	    "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state);
41990Sstevel@tonic-gate 	return (MDI_SUCCESS);
42000Sstevel@tonic-gate }
42010Sstevel@tonic-gate 
42020Sstevel@tonic-gate 
42030Sstevel@tonic-gate /*ARGSUSED*/
42040Sstevel@tonic-gate static int
42050Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg)
42060Sstevel@tonic-gate {
42070Sstevel@tonic-gate 	return (MDI_SUCCESS);
42080Sstevel@tonic-gate }
42090Sstevel@tonic-gate 
42100Sstevel@tonic-gate 
42110Sstevel@tonic-gate static int
42120Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg,
42130Sstevel@tonic-gate     pm_bus_power_op_t op, void *arg, void *result)
42140Sstevel@tonic-gate {
42150Sstevel@tonic-gate 
42160Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
42170Sstevel@tonic-gate 
42180Sstevel@tonic-gate 	IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op);
42190Sstevel@tonic-gate 
42200Sstevel@tonic-gate 	/*
42210Sstevel@tonic-gate 	 * Generic processing in MPxIO framework
42220Sstevel@tonic-gate 	 */
42230Sstevel@tonic-gate 	ret = mdi_bus_power(parent, impl_arg, op, arg, result);
42240Sstevel@tonic-gate 
42250Sstevel@tonic-gate 	switch (ret) {
42260Sstevel@tonic-gate 	case MDI_SUCCESS:
42270Sstevel@tonic-gate 		ret = DDI_SUCCESS;
42280Sstevel@tonic-gate 		break;
42290Sstevel@tonic-gate 	case MDI_FAILURE:
42300Sstevel@tonic-gate 		ret = DDI_FAILURE;
42310Sstevel@tonic-gate 		break;
42320Sstevel@tonic-gate 	default:
42330Sstevel@tonic-gate 		break;
42340Sstevel@tonic-gate 	}
42350Sstevel@tonic-gate 
42360Sstevel@tonic-gate 	return (ret);
42370Sstevel@tonic-gate }
42381093Shiremath 
42391093Shiremath 
42401093Shiremath /*
42411093Shiremath  * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config.
42421093Shiremath  * ndi_devi_enter is not held during this call. mdi_vhci_bus_config()
42431093Shiremath  * will have called ndi_busop_bus_config(), no need for the caller to call
42441093Shiremath  * ndi_busop_bus_config() again.
42451093Shiremath  *
42461093Shiremath  * If enumerated as a child of HCA device, this could be a case for
42471093Shiremath  * Sparc boot or device enumeration from PHCI, driven by MDI.
42481093Shiremath  * Hold parent lock (ndi_devi_enter). The caller will have to call
42491093Shiremath  * ndi_busop_bus_config() if this function returns SUCCESS.
42501093Shiremath  *
42511093Shiremath  * if the device name contains ":port", then it is the Sparc boot case.
42521093Shiremath  * Handle this as before.
42531093Shiremath  *
42541093Shiremath  * If the device name does *not* contain the ":port", then :
42551093Shiremath  *	1. ibdm to probe IOC
42561093Shiremath  *	2. Create a pathinfo only if the IOC is reachable from the parent dip.
42571093Shiremath  */
42581093Shiremath static int
42591093Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag,
42601093Shiremath     ddi_bus_config_op_t op, void *devname, dev_info_t **child,
42611093Shiremath     int *need_bus_config)
42621093Shiremath {
42631093Shiremath 	int ret = DDI_FAILURE, circ;
42641093Shiremath 	dev_info_t *pdip = *pdipp;
42651093Shiremath 	ib_guid_t	iou_guid, ioc_guid;
42661093Shiremath 	char *ioc_guid_str;
42671093Shiremath 
42681093Shiremath 
42691093Shiremath 	*need_bus_config = 1;
42701093Shiremath 
42711093Shiremath 	if (pdip == ibnex.ibnex_dip) {
42721093Shiremath 		if (ibnex_devname_to_node_n_ioc_guids(
42731093Shiremath 		    (char *)devname, &iou_guid, &ioc_guid,
42741093Shiremath 		    &ioc_guid_str) != IBNEX_SUCCESS) {
42751093Shiremath 			return (ret);
42761093Shiremath 		}
42771093Shiremath 		ret = mdi_vhci_bus_config(pdip, flag, op, devname, child,
42781093Shiremath 		    ioc_guid_str);
42791093Shiremath 		kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1);
42801093Shiremath 		if (ret == MDI_SUCCESS)
42811093Shiremath 			*need_bus_config = 0;
42821093Shiremath 	} else {
42832155Scth 		mdi_devi_enter(pdip, &circ);
42841093Shiremath 		if (strstr((char *)devname, ":port=") != NULL) {
42851093Shiremath 			ret = ibnex_config_root_iocnode(pdip, devname);
42861093Shiremath 			ASSERT(ibnex.ibnex_dip == NULL);
42871093Shiremath 			*pdipp = ibnex.ibnex_dip;
42881093Shiremath 		} else {
42891093Shiremath 			ret = ibnex_config_ioc_node(devname, pdip);
42901093Shiremath 		}
42912155Scth 		mdi_devi_exit(pdip, circ);
42921093Shiremath 	}
42931093Shiremath 	return (ret);
42941093Shiremath }
42951093Shiremath 
42961093Shiremath static int
42971093Shiremath ibnex_is_merge_node(dev_info_t *child)
42981093Shiremath {
42991093Shiremath 	char	*node;
43001093Shiremath 	int	ret = IBNEX_INVALID_NODE;
43011093Shiremath 
43021093Shiremath 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child,
43031093Shiremath 	    DDI_PROP_DONTPASS, "ib-node-type", &node) !=
43041093Shiremath 	    DDI_PROP_SUCCESS) {
43051093Shiremath 		return (IBNEX_FAILURE);
43061093Shiremath 	}
43071093Shiremath 
43081093Shiremath 	if (node != NULL && *node != 0) {
43091093Shiremath 		if (strcmp(node, "merge") == 0)
43101093Shiremath 			ret = IBNEX_SUCCESS;
43111093Shiremath 		else {
43121093Shiremath 			IBTF_DPRINTF_L4("ibnex",
43131093Shiremath 			    "\tis_merge_node: ib-node-type = %s", node);
43141093Shiremath 		}
43151093Shiremath 	}
43161093Shiremath 
43171093Shiremath 	ddi_prop_free(node);
43181093Shiremath 	return (ret);
43191093Shiremath }
43201093Shiremath 
43211093Shiremath /*
43221093Shiremath  * Checks if the dn_head for the driver has already
43231093Shiremath  * initialized by the prom tree.
43241093Shiremath  */
43252402Spramodbg void
43261093Shiremath ibnex_hw_in_dev_tree(char *driver_name)
43271093Shiremath {
43281093Shiremath 	major_t	major;
43291093Shiremath 
43302402Spramodbg 	IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name);
43312402Spramodbg 
43321093Shiremath 	if (devnamesp == NULL)
43332402Spramodbg 		return;
43341093Shiremath 
43351093Shiremath 	major = ddi_name_to_major(driver_name);
43361093Shiremath 	if (major == -1)
43372402Spramodbg 		return;
43382402Spramodbg 
43392402Spramodbg 	if (devnamesp[major].dn_head != (dev_info_t *)NULL)
43402402Spramodbg 		ibnex_hw_status = IBNEX_HW_IN_DEVTREE;
43411093Shiremath }
4342*8082SRamaswamy.Tummala@Sun.COM 
4343*8082SRamaswamy.Tummala@Sun.COM int
4344*8082SRamaswamy.Tummala@Sun.COM ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info)
4345*8082SRamaswamy.Tummala@Sun.COM {
4346*8082SRamaswamy.Tummala@Sun.COM 	ibdm_hca_list_t	*hca_list;
4347*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t	*hca_dip;
4348*8082SRamaswamy.Tummala@Sun.COM 	int	rc = IBNEX_FAILURE;
4349*8082SRamaswamy.Tummala@Sun.COM 
4350*8082SRamaswamy.Tummala@Sun.COM 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
4351*8082SRamaswamy.Tummala@Sun.COM 	/*
4352*8082SRamaswamy.Tummala@Sun.COM 	 * We return failure even if we fail for all HCAs
4353*8082SRamaswamy.Tummala@Sun.COM 	 */
4354*8082SRamaswamy.Tummala@Sun.COM 	for (hca_list = ioc_info->ioc_hca_list; hca_list;
4355*8082SRamaswamy.Tummala@Sun.COM 	    hca_list = hca_list->hl_next) {
4356*8082SRamaswamy.Tummala@Sun.COM 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
4357*8082SRamaswamy.Tummala@Sun.COM 		if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) ==
4358*8082SRamaswamy.Tummala@Sun.COM 		    IBNEX_SUCCESS)
4359*8082SRamaswamy.Tummala@Sun.COM 			rc = IBNEX_SUCCESS;
4360*8082SRamaswamy.Tummala@Sun.COM 	}
4361*8082SRamaswamy.Tummala@Sun.COM 	return (rc);
4362*8082SRamaswamy.Tummala@Sun.COM }
4363*8082SRamaswamy.Tummala@Sun.COM 
4364*8082SRamaswamy.Tummala@Sun.COM static int
4365*8082SRamaswamy.Tummala@Sun.COM ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip,
4366*8082SRamaswamy.Tummala@Sun.COM     int pdip_reachable_checked)
4367*8082SRamaswamy.Tummala@Sun.COM {
4368*8082SRamaswamy.Tummala@Sun.COM 	ibnex_node_data_t	*node_data;
4369*8082SRamaswamy.Tummala@Sun.COM 	int			create_pdip = 0;
4370*8082SRamaswamy.Tummala@Sun.COM 	int			rc = IBNEX_SUCCESS;
4371*8082SRamaswamy.Tummala@Sun.COM 
4372*8082SRamaswamy.Tummala@Sun.COM 
4373*8082SRamaswamy.Tummala@Sun.COM 	ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
4374*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex",
4375*8082SRamaswamy.Tummala@Sun.COM 	    "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip,
4376*8082SRamaswamy.Tummala@Sun.COM 	    pdip_reachable_checked);
4377*8082SRamaswamy.Tummala@Sun.COM 
4378*8082SRamaswamy.Tummala@Sun.COM 	if (pdip_reachable_checked == 0) {
4379*8082SRamaswamy.Tummala@Sun.COM 		if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) {
4380*8082SRamaswamy.Tummala@Sun.COM 			IBTF_DPRINTF_L4("ibnex",
4381*8082SRamaswamy.Tummala@Sun.COM 			    "/tioc_config_from_pdip: ioc %p not reachable"
4382*8082SRamaswamy.Tummala@Sun.COM 			    "from %p", ioc_info, pdip);
4383*8082SRamaswamy.Tummala@Sun.COM 			return (IBNEX_FAILURE);
4384*8082SRamaswamy.Tummala@Sun.COM 		}
4385*8082SRamaswamy.Tummala@Sun.COM 	}
4386*8082SRamaswamy.Tummala@Sun.COM 
4387*8082SRamaswamy.Tummala@Sun.COM 	node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
4388*8082SRamaswamy.Tummala@Sun.COM 	    (void *)ioc_info, 0, 0);
4389*8082SRamaswamy.Tummala@Sun.COM 
4390*8082SRamaswamy.Tummala@Sun.COM 	if (node_data && node_data->node_ap_state ==
4391*8082SRamaswamy.Tummala@Sun.COM 	    IBNEX_NODE_AP_UNCONFIGURED) {
4392*8082SRamaswamy.Tummala@Sun.COM 		IBTF_DPRINTF_L4("ibnex",
4393*8082SRamaswamy.Tummala@Sun.COM 		    "\tioc_config_from_pdip: Unconfigured node");
4394*8082SRamaswamy.Tummala@Sun.COM 		return (IBNEX_FAILURE);
4395*8082SRamaswamy.Tummala@Sun.COM 	}
4396*8082SRamaswamy.Tummala@Sun.COM 
4397*8082SRamaswamy.Tummala@Sun.COM 
4398*8082SRamaswamy.Tummala@Sun.COM 	if (node_data == NULL) {
4399*8082SRamaswamy.Tummala@Sun.COM 		ibnex_ioc_node_t	*ioc;
4400*8082SRamaswamy.Tummala@Sun.COM 
4401*8082SRamaswamy.Tummala@Sun.COM 		create_pdip = 1;
4402*8082SRamaswamy.Tummala@Sun.COM 
4403*8082SRamaswamy.Tummala@Sun.COM 		node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE,
4404*8082SRamaswamy.Tummala@Sun.COM 		    ioc_info, 0, 0);
4405*8082SRamaswamy.Tummala@Sun.COM 		ASSERT(node_data);
4406*8082SRamaswamy.Tummala@Sun.COM 		ioc = &node_data->node_data.ioc_node;
4407*8082SRamaswamy.Tummala@Sun.COM 		(void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN,
4408*8082SRamaswamy.Tummala@Sun.COM 		    "%llX",
4409*8082SRamaswamy.Tummala@Sun.COM 		    (longlong_t)ioc_info->ioc_profile.ioc_guid);
4410*8082SRamaswamy.Tummala@Sun.COM 		(void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN,
4411*8082SRamaswamy.Tummala@Sun.COM 		    "%llX,%llX",
4412*8082SRamaswamy.Tummala@Sun.COM 		    (longlong_t)ioc_info->ioc_profile.ioc_guid,
4413*8082SRamaswamy.Tummala@Sun.COM 		    (longlong_t)ioc_info->ioc_iou_guid);
4414*8082SRamaswamy.Tummala@Sun.COM 	} else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) {
4415*8082SRamaswamy.Tummala@Sun.COM 		create_pdip = 1;
4416*8082SRamaswamy.Tummala@Sun.COM 	}
4417*8082SRamaswamy.Tummala@Sun.COM 
4418*8082SRamaswamy.Tummala@Sun.COM 	if (create_pdip) {
4419*8082SRamaswamy.Tummala@Sun.COM 		rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip);
4420*8082SRamaswamy.Tummala@Sun.COM 	}
4421*8082SRamaswamy.Tummala@Sun.COM 
4422*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x",
4423*8082SRamaswamy.Tummala@Sun.COM 	    rc);
4424*8082SRamaswamy.Tummala@Sun.COM 	return (rc);
4425*8082SRamaswamy.Tummala@Sun.COM }
4426*8082SRamaswamy.Tummala@Sun.COM 
4427*8082SRamaswamy.Tummala@Sun.COM /*
4428*8082SRamaswamy.Tummala@Sun.COM  * This function checks if a pathinfo has already been created
4429*8082SRamaswamy.Tummala@Sun.COM  * for the HCA parent. The function returns SUCCESS if a pathinfo
4430*8082SRamaswamy.Tummala@Sun.COM  * has already been created, FAILURE if not.
4431*8082SRamaswamy.Tummala@Sun.COM  */
4432*8082SRamaswamy.Tummala@Sun.COM static int
4433*8082SRamaswamy.Tummala@Sun.COM ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent)
4434*8082SRamaswamy.Tummala@Sun.COM {
4435*8082SRamaswamy.Tummala@Sun.COM 	int	rc;
4436*8082SRamaswamy.Tummala@Sun.COM 	ibnex_ioc_node_t	*ioc;
4437*8082SRamaswamy.Tummala@Sun.COM 
4438*8082SRamaswamy.Tummala@Sun.COM 	ioc = &node_data->node_data.ioc_node;
4439*8082SRamaswamy.Tummala@Sun.COM 	if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str,
4440*8082SRamaswamy.Tummala@Sun.COM 	    (char *)ioc->ioc_phci_guid) != NULL)
4441*8082SRamaswamy.Tummala@Sun.COM 		rc = IBNEX_SUCCESS;
4442*8082SRamaswamy.Tummala@Sun.COM 	else
4443*8082SRamaswamy.Tummala@Sun.COM 		rc = IBNEX_FAILURE;
4444*8082SRamaswamy.Tummala@Sun.COM 
4445*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, "
4446*8082SRamaswamy.Tummala@Sun.COM 	    "phci_guid %s, parent %p, rc %x",
4447*8082SRamaswamy.Tummala@Sun.COM 	    ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc);
4448*8082SRamaswamy.Tummala@Sun.COM 	return (rc);
4449*8082SRamaswamy.Tummala@Sun.COM }
4450*8082SRamaswamy.Tummala@Sun.COM 
4451*8082SRamaswamy.Tummala@Sun.COM static int
4452*8082SRamaswamy.Tummala@Sun.COM ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
4453*8082SRamaswamy.Tummala@Sun.COM {
4454*8082SRamaswamy.Tummala@Sun.COM 	ibdm_hca_list_t	*hca_list;
4455*8082SRamaswamy.Tummala@Sun.COM 	dev_info_t	*hca_dip;
4456*8082SRamaswamy.Tummala@Sun.COM 
4457*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)",
4458*8082SRamaswamy.Tummala@Sun.COM 	    ioc_info, pdip);
4459*8082SRamaswamy.Tummala@Sun.COM 	for (hca_list = ioc_info->ioc_hca_list; hca_list;
4460*8082SRamaswamy.Tummala@Sun.COM 	    hca_list = hca_list->hl_next) {
4461*8082SRamaswamy.Tummala@Sun.COM 		hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
4462*8082SRamaswamy.Tummala@Sun.COM 		if (hca_dip == pdip) {
4463*8082SRamaswamy.Tummala@Sun.COM 			IBTF_DPRINTF_L4("ibnex",
4464*8082SRamaswamy.Tummala@Sun.COM 			    "\tioc_pi_reachable FAILURE");
4465*8082SRamaswamy.Tummala@Sun.COM 			return (IBNEX_SUCCESS);
4466*8082SRamaswamy.Tummala@Sun.COM 		}
4467*8082SRamaswamy.Tummala@Sun.COM 	}
4468*8082SRamaswamy.Tummala@Sun.COM 
4469*8082SRamaswamy.Tummala@Sun.COM 	IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE");
4470*8082SRamaswamy.Tummala@Sun.COM 	return (IBNEX_FAILURE);
4471*8082SRamaswamy.Tummala@Sun.COM }
4472