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 /* 2212163SRamaswamy.Tummala@Sun.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate /* 260Sstevel@tonic-gate * The InfiniBand Nexus driver (IB nexus) is a bus nexus driver for IB bus. 270Sstevel@tonic-gate * It supports Port nodes, Virtual Physical Point of Attachment nodes (VPPA) 280Sstevel@tonic-gate * for HCAs registered with IBTL and IOC nodes for all the IOCs present in 290Sstevel@tonic-gate * the IB fabric (that are accessible to the host). It also supports Pseudo 300Sstevel@tonic-gate * device children to be enumerated using their .conf file(s). All Port nodes 310Sstevel@tonic-gate * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo 320Sstevel@tonic-gate * device nodes are children of the IB nexus driver. 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * IB nexus driver provides bus nexus entry points to all the HCA drivers. 350Sstevel@tonic-gate * 360Sstevel@tonic-gate * IB nexus driver registers with InfiniBand Device Manager (IBDM) to get 370Sstevel@tonic-gate * information about all the HCA ports and I/O Controllers (IOCs) connected 380Sstevel@tonic-gate * to the IB fabric. Based on that information, IB nexus will create all the 390Sstevel@tonic-gate * device tree nodes. 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <sys/conf.h> 430Sstevel@tonic-gate #include <sys/stat.h> 440Sstevel@tonic-gate #include <sys/modctl.h> 450Sstevel@tonic-gate #include <sys/taskq.h> 460Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 470Sstevel@tonic-gate #include <sys/sunmdi.h> 480Sstevel@tonic-gate #include <sys/sunpm.h> 490Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h> 500Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h> 510Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h> 520Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h> 530Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h> 540Sstevel@tonic-gate #include <sys/file.h> 550Sstevel@tonic-gate #include <sys/hwconf.h> 5610096SSudhakar.Dindukurti@Sun.COM #include <sys/fs/dv_node.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); 6312163SRamaswamy.Tummala@Sun.COM int ibnex_busctl(dev_info_t *, 640Sstevel@tonic-gate dev_info_t *, ddi_ctl_enum_t, void *, void *); 6512163SRamaswamy.Tummala@Sun.COM 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 **); 7712163SRamaswamy.Tummala@Sun.COM int ibnex_get_node_and_dip_from_guid(ib_guid_t, int, 7812163SRamaswamy.Tummala@Sun.COM ib_pkey_t, ibnex_node_data_t **, dev_info_t **); 790Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t, 800Sstevel@tonic-gate void *, int, ib_pkey_t); 810Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *, 820Sstevel@tonic-gate int, ib_pkey_t); 830Sstevel@tonic-gate static int ibnex_create_port_node_prop(ibdm_port_attr_t *, 840Sstevel@tonic-gate dev_info_t *, char *, ib_pkey_t); 850Sstevel@tonic-gate void ibnex_dm_callback(void *, ibdm_events_t); 860Sstevel@tonic-gate static int ibnex_create_port_compatible_prop(dev_info_t *, 870Sstevel@tonic-gate char *, ibdm_port_attr_t *); 880Sstevel@tonic-gate static int ibnex_create_ioc_srv_props( 890Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 900Sstevel@tonic-gate static int ibnex_get_eventcookie(dev_info_t *, 910Sstevel@tonic-gate dev_info_t *, char *, ddi_eventcookie_t *); 920Sstevel@tonic-gate static int ibnex_add_eventcall(dev_info_t *, dev_info_t *, 930Sstevel@tonic-gate ddi_eventcookie_t, void (*)(dev_info_t *, 940Sstevel@tonic-gate ddi_eventcookie_t, void *, void *), 950Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id); 960Sstevel@tonic-gate static int ibnex_remove_eventcall(dev_info_t *, 970Sstevel@tonic-gate ddi_callback_id_t); 980Sstevel@tonic-gate static int ibnex_post_event(dev_info_t *, dev_info_t *, 990Sstevel@tonic-gate ddi_eventcookie_t, void *); 1000Sstevel@tonic-gate static int ibnex_bus_config(dev_info_t *, uint_t, 1010Sstevel@tonic-gate ddi_bus_config_op_t, void *, dev_info_t **); 1020Sstevel@tonic-gate static int ibnex_bus_unconfig(dev_info_t *, 1030Sstevel@tonic-gate uint_t, ddi_bus_config_op_t, void *); 10412163SRamaswamy.Tummala@Sun.COM dev_info_t *ibnex_config_port_node(dev_info_t *, char *); 10512163SRamaswamy.Tummala@Sun.COM int ibnex_get_pkey_commsvc_index_portnum( 1060Sstevel@tonic-gate char *, int *, ib_pkey_t *, uint8_t *); 10712163SRamaswamy.Tummala@Sun.COM void ibnex_config_all_children(dev_info_t *); 1080Sstevel@tonic-gate static int ibnex_devname_to_portnum(char *, uint8_t *); 10912163SRamaswamy.Tummala@Sun.COM void ibnex_create_vppa_nodes(dev_info_t *, ibdm_port_attr_t *); 11012163SRamaswamy.Tummala@Sun.COM void ibnex_create_port_nodes( 1110Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 11212163SRamaswamy.Tummala@Sun.COM 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 *); 1218082SRamaswamy.Tummala@Sun.COM int ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *); 1228082SRamaswamy.Tummala@Sun.COM static int ibnex_ioc_initnode_pdip(ibnex_node_data_t *, 1238082SRamaswamy.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 *); 12912163SRamaswamy.Tummala@Sun.COM 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 void ibnex_pseudo_initnodes(void); 1361093Shiremath static char *ibnex_lookup_named_prop(ddi_prop_t *, char *); 1370Sstevel@tonic-gate static void ibnex_pseudo_node_cleanup(void); 1380Sstevel@tonic-gate static int ibnex_name_child(dev_info_t *, char *, int); 1390Sstevel@tonic-gate static int ibnex_name_pseudo_child(dev_info_t *, char *); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate void ibnex_reprobe_ioc_dev(void *); 1420Sstevel@tonic-gate void ibnex_reprobe_ioc_all(); 1430Sstevel@tonic-gate static void ibnex_update_prop(ibnex_node_data_t *, 1440Sstevel@tonic-gate ibdm_ioc_info_t *); 1450Sstevel@tonic-gate static ibnex_rval_t ibnex_unique_svcname(char *); 1460Sstevel@tonic-gate static void ibnex_handle_reprobe_dev(void *arg); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate extern int ibnex_open(dev_t *, int, int, cred_t *); 1490Sstevel@tonic-gate extern int ibnex_close(dev_t, int, int, cred_t *); 1500Sstevel@tonic-gate extern int ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1510Sstevel@tonic-gate extern int ibnex_offline_childdip(dev_info_t *); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate static int ibnex_ioc_create_pi( 1541093Shiremath ibdm_ioc_info_t *, ibnex_node_data_t *, 1558082SRamaswamy.Tummala@Sun.COM dev_info_t *, int *); 1560Sstevel@tonic-gate static int ibnex_bus_power(dev_info_t *, void *, 1570Sstevel@tonic-gate pm_bus_power_op_t, void *, void *); 1588082SRamaswamy.Tummala@Sun.COM int ibnex_pseudo_create_all_pi(ibnex_node_data_t *); 1598082SRamaswamy.Tummala@Sun.COM static int ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *, 1601093Shiremath dev_info_t *); 16112163SRamaswamy.Tummala@Sun.COM int ibnex_pseudo_config_one( 1621689Spramodbg ibnex_node_data_t *, char *, dev_info_t *); 16312163SRamaswamy.Tummala@Sun.COM int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **, 1641093Shiremath char *, char *); 1651093Shiremath static void ibnex_config_pseudo_all(dev_info_t *); 16612163SRamaswamy.Tummala@Sun.COM int ibnex_ioc_bus_config_one(dev_info_t **, uint_t, 1671093Shiremath ddi_bus_config_op_t, void *, dev_info_t **, int *); 1681093Shiremath static int ibnex_is_merge_node(dev_info_t *); 1692402Spramodbg static void ibnex_hw_in_dev_tree(char *); 1708082SRamaswamy.Tummala@Sun.COM static int ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *, 1718082SRamaswamy.Tummala@Sun.COM dev_info_t *, int); 1728082SRamaswamy.Tummala@Sun.COM static int ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *); 1738082SRamaswamy.Tummala@Sun.COM static int ibnex_ioc_pi_reachable(ibdm_ioc_info_t *, 1748082SRamaswamy.Tummala@Sun.COM dev_info_t *); 1751093Shiremath 17612163SRamaswamy.Tummala@Sun.COM extern void ibnex_handle_hca_attach(void *); 17712163SRamaswamy.Tummala@Sun.COM 17812163SRamaswamy.Tummala@Sun.COM extern struct bus_ops ibnex_ci_busops; 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Prototype declarations for the VHCI options 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * Functions registered with the mpxio framework 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int); 1860Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int); 1870Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *, 1880Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int); 1890Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = { 1930Sstevel@tonic-gate MDI_VHCI_OPS_REV, 1940Sstevel@tonic-gate ib_vhci_pi_init, 1950Sstevel@tonic-gate ib_vhci_pi_uninit, 1960Sstevel@tonic-gate ib_vhci_pi_state_change, 1970Sstevel@tonic-gate ib_vhci_failover 1980Sstevel@tonic-gate }; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * The bus_ops structure defines the capabilities of IB nexus driver. 2030Sstevel@tonic-gate * IB nexus drivers does not support any DMA operations for its children 2040Sstevel@tonic-gate * as there is no such concept in Infiniband. All the memory operations 2050Sstevel@tonic-gate * and DMA operations required by the child drivers can be performed using 2060Sstevel@tonic-gate * the IBTF API. 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = { 2090Sstevel@tonic-gate BUSO_REV, 2100Sstevel@tonic-gate nullbusmap, /* bus_map */ 2110Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 2120Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 2130Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 2140Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 2150Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 2160Sstevel@tonic-gate ddi_no_dma_allochdl, 2170Sstevel@tonic-gate NULL, 2180Sstevel@tonic-gate NULL, 2190Sstevel@tonic-gate NULL, 2200Sstevel@tonic-gate NULL, 2210Sstevel@tonic-gate NULL, 2220Sstevel@tonic-gate NULL, 2230Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 2240Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 2250Sstevel@tonic-gate ibnex_get_eventcookie, /* bus_get_eventcookie */ 2260Sstevel@tonic-gate ibnex_add_eventcall, /* bus_add_eventcall */ 2270Sstevel@tonic-gate ibnex_remove_eventcall, /* bus_remove_eventcall */ 2280Sstevel@tonic-gate ibnex_post_event, /* bus_post_event */ 2290Sstevel@tonic-gate NULL, 2300Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2310Sstevel@tonic-gate ibnex_bus_unconfig, /* bus unconfig */ 2320Sstevel@tonic-gate NULL, /* bus fm init */ 2330Sstevel@tonic-gate NULL, /* bus fm fini */ 2340Sstevel@tonic-gate NULL, /* bus fm access enter */ 2350Sstevel@tonic-gate NULL, /* bus fm access exit */ 2360Sstevel@tonic-gate ibnex_bus_power /* bus power */ 2370Sstevel@tonic-gate }; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* ibnex cb_ops */ 2400Sstevel@tonic-gate static struct cb_ops ibnex_cbops = { 2410Sstevel@tonic-gate ibnex_open, /* open */ 2420Sstevel@tonic-gate ibnex_close, /* close */ 2430Sstevel@tonic-gate nodev, /* strategy */ 2440Sstevel@tonic-gate nodev, /* print */ 2450Sstevel@tonic-gate nodev, /* dump */ 2460Sstevel@tonic-gate nodev, /* read */ 2470Sstevel@tonic-gate nodev, /* write */ 2480Sstevel@tonic-gate ibnex_ioctl, /* ioctl */ 2490Sstevel@tonic-gate nodev, /* devmap */ 2500Sstevel@tonic-gate nodev, /* mmap */ 2510Sstevel@tonic-gate nodev, /* segmap */ 2520Sstevel@tonic-gate nochpoll, /* poll */ 2530Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 2540Sstevel@tonic-gate NULL, /* stream */ 2550Sstevel@tonic-gate D_MP, /* cb_flag */ 2560Sstevel@tonic-gate CB_REV, /* rev */ 2570Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 2580Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 2590Sstevel@tonic-gate }; 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* 2620Sstevel@tonic-gate * Device options 2630Sstevel@tonic-gate * Note: ddi_no_info needs to change during devfs time frame. The drivers 2640Sstevel@tonic-gate * with 1 to 1 mapping between minor node and instance should use 2650Sstevel@tonic-gate * ddi_1to1_info. (See bug id 4424752) 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate static struct dev_ops ibnex_ops = { 2680Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 2690Sstevel@tonic-gate 0, /* refcnt */ 2700Sstevel@tonic-gate ibnex_getinfo, /* info */ 2710Sstevel@tonic-gate nulldev, /* identify */ 2720Sstevel@tonic-gate nulldev, /* probe */ 2730Sstevel@tonic-gate ibnex_attach, /* attach */ 2740Sstevel@tonic-gate ibnex_detach, /* detach */ 2750Sstevel@tonic-gate nodev, /* reset */ 2760Sstevel@tonic-gate &ibnex_cbops, /* driver ops - devctl interfaces */ 2770Sstevel@tonic-gate &ibnex_bus_ops, /* bus operations */ 2787656SSherry.Moore@Sun.COM nulldev, /* power */ 2797656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */ 2800Sstevel@tonic-gate }; 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* Module linkage information for the kernel. */ 2830Sstevel@tonic-gate static struct modldrv modldrv = { 2840Sstevel@tonic-gate &mod_driverops, /* Driver module */ 2857656SSherry.Moore@Sun.COM "IB nexus", /* Driver name and version */ 2860Sstevel@tonic-gate &ibnex_ops, /* driver ops */ 2870Sstevel@tonic-gate }; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate static struct modlinkage modlinkage = { 2900Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 2910Sstevel@tonic-gate }; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * Global per-instance IB Nexus data. 2950Sstevel@tonic-gate * There is only one instance of IB Nexus supported. 2960Sstevel@tonic-gate */ 2970Sstevel@tonic-gate ibnex_t ibnex; 2980Sstevel@tonic-gate #ifdef __lock_lint 2990Sstevel@tonic-gate extern ibdm_t ibdm; 3000Sstevel@tonic-gate #endif 3010Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s)) 3020Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs 3030Sstevel@tonic-gate ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs 3040Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs 3058082SRamaswamy.Tummala@Sun.COM ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list)) 3060Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s)) 3070Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex)) 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* The port settling time in seconds */ 3108082SRamaswamy.Tummala@Sun.COM int ibnex_port_settling_time = 30; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */ 3130Sstevel@tonic-gate static struct ibnex_property { 3140Sstevel@tonic-gate char *name; 3150Sstevel@tonic-gate ibnex_node_type_t type; 3160Sstevel@tonic-gate } ibnex_properties[] = { 3170Sstevel@tonic-gate { "port-svc-list", IBNEX_PORT_COMMSVC_NODE}, 3180Sstevel@tonic-gate { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE}, 3190Sstevel@tonic-gate { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE} 3200Sstevel@tonic-gate }; 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \ 3230Sstevel@tonic-gate (sizeof (struct ibnex_property)) 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Event Definition 3270Sstevel@tonic-gate * Single event, event name defined in ibti_common.h. 3280Sstevel@tonic-gate * Event posted to specific child handler. Event posted 3290Sstevel@tonic-gate * at kernel priority. 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = { 3320Sstevel@tonic-gate {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL, 3330Sstevel@tonic-gate NDI_EVENT_POST_TO_TGT} 3340Sstevel@tonic-gate }; 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate #define IB_N_NDI_EVENTS \ 3370Sstevel@tonic-gate (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t)) 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = { 3400Sstevel@tonic-gate NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs}; 3411093Shiremath static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED; 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * _init 3460Sstevel@tonic-gate * Loadable module init, called before any other module. 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate int 3490Sstevel@tonic-gate _init(void) 3500Sstevel@tonic-gate { 3510Sstevel@tonic-gate int error; 3522402Spramodbg char **hca_driver_list; 3532402Spramodbg int i, ndrivers; 3540Sstevel@tonic-gate 3551093Shiremath if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) { 3562402Spramodbg ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE; 3572402Spramodbg hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers); 3582402Spramodbg for (i = 0; i < ndrivers; i++) { 3592402Spramodbg ibnex_hw_in_dev_tree(hca_driver_list[i]); 3602402Spramodbg if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE) 3612402Spramodbg break; 3622402Spramodbg } 3632402Spramodbg mdi_free_phci_driver_list(hca_driver_list, ndrivers); 3641093Shiremath } 3651093Shiremath 3661093Shiremath /* 3671093Shiremath * IB Nexus _init can be called while force attaching 3681093Shiremath * IB Nexus driver or when a HCA is hotplugged. 3691093Shiremath * 3701093Shiremath * If IB HW is not in device tree or if no HCA driver 3711093Shiremath * has been attached, fail IB Nexus _init(). 3721093Shiremath */ 3731093Shiremath if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE && 3741093Shiremath ibt_hw_is_present() == 0) { 3751093Shiremath IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW"); 3761093Shiremath return (DDI_FAILURE); 3771093Shiremath } 3781093Shiremath 3790Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_init"); 3800Sstevel@tonic-gate mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL); 3810Sstevel@tonic-gate cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL); 3828695SRajkumar.Sivaprakasam@Sun.COM cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL); 3830Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 3840Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed"); 3850Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 3860Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 3878695SRajkumar.Sivaprakasam@Sun.COM cv_destroy(&ibnex.ibnex_ioc_list_cv); 3880Sstevel@tonic-gate } else { 3890Sstevel@tonic-gate ibdm_ibnex_register_callback(ibnex_dm_callback); 3900Sstevel@tonic-gate ibtl_ibnex_register_callback(ibnex_ibtl_callback); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate return (error); 3930Sstevel@tonic-gate } 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * _fini 3980Sstevel@tonic-gate * Prepares a module for unloading. 3990Sstevel@tonic-gate */ 4000Sstevel@tonic-gate int 4010Sstevel@tonic-gate _fini(void) 4020Sstevel@tonic-gate { 4030Sstevel@tonic-gate int error; 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_fini"); 4060Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) { 4070Sstevel@tonic-gate return (error); 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate ibdm_ibnex_unregister_callback(); 4100Sstevel@tonic-gate ibtl_ibnex_unregister_callback(); 4110Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4120Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 4138695SRajkumar.Sivaprakasam@Sun.COM cv_destroy(&ibnex.ibnex_ioc_list_cv); 4140Sstevel@tonic-gate return (0); 4150Sstevel@tonic-gate } 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate /* 4190Sstevel@tonic-gate * _info 4200Sstevel@tonic-gate * Returns information about loadable module. 4210Sstevel@tonic-gate */ 4220Sstevel@tonic-gate int 4230Sstevel@tonic-gate _info(struct modinfo *modinfop) 4240Sstevel@tonic-gate { 4250Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_info"); 4260Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * ibnex_attach 4320Sstevel@tonic-gate * Configure and attach an instance of the IB Nexus driver 4330Sstevel@tonic-gate * Only one instance of IB Nexus is supported 4340Sstevel@tonic-gate * Create a minor node for cfgadm purpose 4350Sstevel@tonic-gate * Initialize communication services 4360Sstevel@tonic-gate * Register callback with IBDM 4370Sstevel@tonic-gate * Register callback with IBTL 4380Sstevel@tonic-gate */ 4390Sstevel@tonic-gate static int 4400Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 4410Sstevel@tonic-gate { 4420Sstevel@tonic-gate int i; 4430Sstevel@tonic-gate int instance = ddi_get_instance(dip); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate switch (cmd) { 4480Sstevel@tonic-gate case DDI_ATTACH: 4490Sstevel@tonic-gate break; 4500Sstevel@tonic-gate case DDI_RESUME: 4510Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME"); 4520Sstevel@tonic-gate return (DDI_SUCCESS); 4530Sstevel@tonic-gate default: 4540Sstevel@tonic-gate return (DDI_FAILURE); 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /* Fail attach for more than one instance */ 4580Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 4590Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) { 4600Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4610Sstevel@tonic-gate return (DDI_FAILURE); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4640Sstevel@tonic-gate 46512163SRamaswamy.Tummala@Sun.COM /* 46612163SRamaswamy.Tummala@Sun.COM * Create a IB nexus taskq 46712163SRamaswamy.Tummala@Sun.COM */ 46812163SRamaswamy.Tummala@Sun.COM 46912163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = ddi_taskq_create(dip, 47012163SRamaswamy.Tummala@Sun.COM "ibnex-enum-taskq", 1, TASKQ_DEFAULTPRI, 0); 47112163SRamaswamy.Tummala@Sun.COM if (ibnex.ibnex_taskq_id == NULL) { 47212163SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 47312163SRamaswamy.Tummala@Sun.COM "\tattach: ddi_taskq_create() failed"); 47412163SRamaswamy.Tummala@Sun.COM return (DDI_FAILURE); 47512163SRamaswamy.Tummala@Sun.COM 47612163SRamaswamy.Tummala@Sun.COM } 47712163SRamaswamy.Tummala@Sun.COM 4780Sstevel@tonic-gate /* Register with MPxIO framework */ 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0) 4810Sstevel@tonic-gate != MDI_SUCCESS) { 4820Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 4830Sstevel@tonic-gate "\tattach: mdi_vhci_register() failed"); 48412163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 48512163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 4860Sstevel@tonic-gate return (DDI_FAILURE); 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate /* 4910Sstevel@tonic-gate * Create the "fabric" devctl minor-node for IB DR support. 4920Sstevel@tonic-gate * The minor number for the "devctl" node is in the same format 4930Sstevel@tonic-gate * as the AP minor nodes. 4940Sstevel@tonic-gate */ 4950Sstevel@tonic-gate if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance, 4960Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 4970Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 4980Sstevel@tonic-gate "\tattach: failed to create fabric minornode"); 49912163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 50012163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5010Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5020Sstevel@tonic-gate return (DDI_FAILURE); 5030Sstevel@tonic-gate } 5040Sstevel@tonic-gate 5059879SRamaswamy.Tummala@Sun.COM /* 5069879SRamaswamy.Tummala@Sun.COM * Create "devctl" minor node for general ioctl interface to the 5079879SRamaswamy.Tummala@Sun.COM * ib nexus. 5089879SRamaswamy.Tummala@Sun.COM */ 5099879SRamaswamy.Tummala@Sun.COM if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance, 5109879SRamaswamy.Tummala@Sun.COM DDI_NT_IB_NEXUS, 0) != DDI_SUCCESS) { 5119879SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 5129879SRamaswamy.Tummala@Sun.COM "\tattach: failed to create devctl minornode"); 5139879SRamaswamy.Tummala@Sun.COM (void) ddi_remove_minor_node(dip, NULL); 51412163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 51512163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5169879SRamaswamy.Tummala@Sun.COM (void) mdi_vhci_unregister(dip, 0); 5179879SRamaswamy.Tummala@Sun.COM return (DDI_FAILURE); 5189879SRamaswamy.Tummala@Sun.COM } 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate /* 5210Sstevel@tonic-gate * Set pm-want-child-notification property for 5220Sstevel@tonic-gate * power management of the phci and client 5230Sstevel@tonic-gate */ 5240Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 5250Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 5260Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5270Sstevel@tonic-gate "_attach: create pm-want-child-notification failed"); 5280Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 52912163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 53012163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5310Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5320Sstevel@tonic-gate return (DDI_FAILURE); 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 5360Sstevel@tonic-gate ibnex.ibnex_dip = dip; 5370Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate /* 5400Sstevel@tonic-gate * Event Handling: Definition and Binding. 5410Sstevel@tonic-gate */ 5420Sstevel@tonic-gate if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl, 5430Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5440Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5450Sstevel@tonic-gate "_attach: ndi_event_alloc_hdl failed"); 54612163SRamaswamy.Tummala@Sun.COM (void) ddi_remove_minor_node(dip, NULL); 54712163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 54812163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5490Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5500Sstevel@tonic-gate return (DDI_FAILURE); 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events, 5530Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5540Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5550Sstevel@tonic-gate (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl); 5560Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5570Sstevel@tonic-gate "_attach: ndi_event_bind_set failed"); 55812163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 55912163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5600Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5610Sstevel@tonic-gate return (DDI_FAILURE); 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate for (i = 0; i < N_IBNEX_PROPS; i++) { 5650Sstevel@tonic-gate if (ibnex_comm_svc_init(ibnex_properties[i].name, 5660Sstevel@tonic-gate ibnex_properties[i].type) != IBNEX_SUCCESS) { 5670Sstevel@tonic-gate ibnex_comm_svc_fini(); 5680Sstevel@tonic-gate (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl, 5690Sstevel@tonic-gate &ib_ndi_events, NDI_SLEEP); 5700Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5710Sstevel@tonic-gate (void) ndi_event_free_hdl( 5720Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl); 5730Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 5740Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init" 5750Sstevel@tonic-gate " failed %s", ibnex_properties[i].name); 57612163SRamaswamy.Tummala@Sun.COM (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id); 57712163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 5780Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5790Sstevel@tonic-gate return (DDI_FAILURE); 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate } 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate /* 5840Sstevel@tonic-gate * before anything else comes up: 5850Sstevel@tonic-gate * Initialize the internal list of pseudo device nodes by 5860Sstevel@tonic-gate * getting all pseudo children of "ib" and processing them. 5870Sstevel@tonic-gate */ 5880Sstevel@tonic-gate ibnex_pseudo_initnodes(); 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate return (DDI_SUCCESS); 5910Sstevel@tonic-gate } 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate /* 5950Sstevel@tonic-gate * ibnex_getinfo() 5960Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 5970Sstevel@tonic-gate * instance number. 5980Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 5990Sstevel@tonic-gate */ 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /*ARGSUSED*/ 6020Sstevel@tonic-gate static int 6030Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 6040Sstevel@tonic-gate { 6050Sstevel@tonic-gate int ret = DDI_SUCCESS; 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin"); 6080Sstevel@tonic-gate switch (cmd) { 6090Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 6100Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) 6110Sstevel@tonic-gate *result = ibnex.ibnex_dip; 6120Sstevel@tonic-gate else { 6130Sstevel@tonic-gate *result = NULL; 6140Sstevel@tonic-gate ret = DDI_FAILURE; 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate break; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 6190Sstevel@tonic-gate *result = 0; 6200Sstevel@tonic-gate break; 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate default: 6230Sstevel@tonic-gate ret = DDI_FAILURE; 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate return (ret); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * ibnex_detach 6310Sstevel@tonic-gate * Unregister callback with the IBDM 6320Sstevel@tonic-gate * Unregister callback with the IBTL 6330Sstevel@tonic-gate * Uninitialize the communication entries 6340Sstevel@tonic-gate * Remove all the minor nodes created by this instance 6350Sstevel@tonic-gate */ 6360Sstevel@tonic-gate static int 6370Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 6380Sstevel@tonic-gate { 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate switch (cmd) { 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate case DDI_DETACH: 6450Sstevel@tonic-gate break; 6460Sstevel@tonic-gate case DDI_SUSPEND: 6470Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend"); 6480Sstevel@tonic-gate return (DDI_SUCCESS); 6490Sstevel@tonic-gate default: 6500Sstevel@tonic-gate return (DDI_FAILURE); 6510Sstevel@tonic-gate } 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 6540Sstevel@tonic-gate if (ibt_hw_is_present()) { 6550Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6560Sstevel@tonic-gate "\tdetach: IB HW is present "); 6570Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6580Sstevel@tonic-gate return (DDI_FAILURE); 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) { 6610Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6620Sstevel@tonic-gate "\tdetach: ndi_event_free_hdl() failed"); 6630Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6640Sstevel@tonic-gate return (DDI_FAILURE); 6650Sstevel@tonic-gate } 6660Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 6670Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = NULL; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate ibnex_pseudo_node_cleanup(); 6700Sstevel@tonic-gate ibnex_comm_svc_fini(); 6710Sstevel@tonic-gate ibnex_ioc_node_cleanup(); 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 6740Sstevel@tonic-gate ibnex.ibnex_dip = NULL; 6750Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6760Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 67712163SRamaswamy.Tummala@Sun.COM 67812163SRamaswamy.Tummala@Sun.COM if (ibnex.ibnex_taskq_id != NULL) { 67912163SRamaswamy.Tummala@Sun.COM ddi_taskq_destroy(ibnex.ibnex_taskq_id); 68012163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_taskq_id = NULL; 68112163SRamaswamy.Tummala@Sun.COM } 68212163SRamaswamy.Tummala@Sun.COM 6830Sstevel@tonic-gate return (DDI_SUCCESS); 6840Sstevel@tonic-gate } 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate /* 6880Sstevel@tonic-gate * ibnex_pseudo_node_cleanup() 6890Sstevel@tonic-gate * This checks if all the "dips" have been deallocated (implying 6900Sstevel@tonic-gate * that all the children have been unconfigured) first. 6910Sstevel@tonic-gate * If not, it just returns. 6920Sstevel@tonic-gate * If yes, then it frees up memory allocated for devi_name, 6930Sstevel@tonic-gate * node_addr, and property list. 6940Sstevel@tonic-gate */ 6950Sstevel@tonic-gate static void 6960Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void) 6970Sstevel@tonic-gate { 6980Sstevel@tonic-gate ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head; 6990Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:"); 7020Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate for (; nodep; nodep = nodep->node_next) 7050Sstevel@tonic-gate if (nodep->node_dip) 7060Sstevel@tonic-gate return; 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory"); 7090Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 7100Sstevel@tonic-gate nodep = nodep->node_next) { 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node; 7130Sstevel@tonic-gate if (pseudo->pseudo_node_addr) { 7140Sstevel@tonic-gate kmem_free(pseudo->pseudo_node_addr, 7150Sstevel@tonic-gate strlen(pseudo-> pseudo_node_addr) + 1); 7160Sstevel@tonic-gate pseudo->pseudo_node_addr = NULL; 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate if (pseudo->pseudo_devi_name) { 7200Sstevel@tonic-gate kmem_free(pseudo->pseudo_devi_name, 7210Sstevel@tonic-gate strlen(pseudo-> pseudo_devi_name) + 1); 7220Sstevel@tonic-gate pseudo->pseudo_devi_name = NULL; 7230Sstevel@tonic-gate } 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate if (pseudo->pseudo_unit_addr) { 7260Sstevel@tonic-gate kmem_free(pseudo->pseudo_unit_addr, 7270Sstevel@tonic-gate pseudo->pseudo_unit_addr_len); 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate } 7300Sstevel@tonic-gate } 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate /* 7340Sstevel@tonic-gate * This functions wakes up any reprobe requests waiting for completion 7350Sstevel@tonic-gate * of reprobe of this IOC. It also send an NDI event, if : 7360Sstevel@tonic-gate * 7370Sstevel@tonic-gate * notify_flag is set. This is set if : 7380Sstevel@tonic-gate * ibt_reprobe_ioc has returned with SUCCESS 7390Sstevel@tonic-gate * IBTF client has not been notified for this node. 7400Sstevel@tonic-gate * node_data->node_dip != NULL 7410Sstevel@tonic-gate * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set 7420Sstevel@tonic-gate * An NDI event cookie has been registered. 7430Sstevel@tonic-gate */ 7440Sstevel@tonic-gate static void 7450Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag) 7460Sstevel@tonic-gate { 7470Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7500Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) || 7530Sstevel@tonic-gate (node_data->node_reprobe_state != 0)) { 7540Sstevel@tonic-gate if (notify_flag && (node_data->node_dip != NULL) && 7550Sstevel@tonic-gate (node_data->node_state & 7560Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) && 7570Sstevel@tonic-gate (evt_cookie != NULL)) { 7580Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate bzero(&evt_data, sizeof (evt_data)); 7630Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, 7640Sstevel@tonic-gate node_data->node_dip, 7650Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 7660Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 7670Sstevel@tonic-gate "\tndi_post_event failed\n"); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 7700Sstevel@tonic-gate } 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7730Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate /* 7790Sstevel@tonic-gate * This function wakes up any reprobe request waiting for completion 7800Sstevel@tonic-gate * of reprobe of all IOCs. 7810Sstevel@tonic-gate */ 7820Sstevel@tonic-gate static void 7830Sstevel@tonic-gate ibnex_wakeup_reprobe_all() 7840Sstevel@tonic-gate { 7850Sstevel@tonic-gate ibnex_node_data_t *ioc_node; 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate /* Notify if another reprobe_all is pending */ 7900Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) { 7910Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7920Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7930Sstevel@tonic-gate } 7940Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate /* 7970Sstevel@tonic-gate * The IOC may be hot-removed after the reprobe request. 7980Sstevel@tonic-gate * Reset the reprobe states for such IOCs. 7990Sstevel@tonic-gate */ 8000Sstevel@tonic-gate for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node; 8010Sstevel@tonic-gate ioc_node = ioc_node->node_next) { 8020Sstevel@tonic-gate if (ioc_node->node_reprobe_state != 0) { 8030Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ioc_node, 1); 8040Sstevel@tonic-gate } 8050Sstevel@tonic-gate } 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * ibnex_ibnex_callback: 8100Sstevel@tonic-gate * IBTL_IBNEX_IBC_INIT: 8110Sstevel@tonic-gate * Called from ibc_init() which is called from 8120Sstevel@tonic-gate * HCA driver _init entry point 8130Sstevel@tonic-gate * Initializes the HCA dev_ops structure with default 8140Sstevel@tonic-gate * IB nexus structure. 8150Sstevel@tonic-gate * IBTL_IBNEX_IBC_FINI: 8160Sstevel@tonic-gate * Called from ibc_fini() which is called from 8170Sstevel@tonic-gate * HCA driver _fini entry point 8180Sstevel@tonic-gate * Un-Initializes the HCA dev_ops structure with default 8190Sstevel@tonic-gate * IB nexus strucuture. 8200Sstevel@tonic-gate * Returns IBT_SUCCESS 8210Sstevel@tonic-gate */ 8220Sstevel@tonic-gate ibt_status_t 8230Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args) 8240Sstevel@tonic-gate { 8250Sstevel@tonic-gate int retval = IBT_SUCCESS; 8260Sstevel@tonic-gate struct dev_ops *hca_dev_ops; 8270Sstevel@tonic-gate dev_info_t *clnt_dip; 8280Sstevel@tonic-gate ibnex_node_data_t *node_data; 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tibtl_callback"); 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate switch (cb_args->cb_flag) { 8330Sstevel@tonic-gate case IBTL_IBNEX_IBC_INIT: 8340Sstevel@tonic-gate /* 8350Sstevel@tonic-gate * Get the devops structure of the HCA, 8360Sstevel@tonic-gate * and put IB nexus default busops vector in its place. 8370Sstevel@tonic-gate */ 8380Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8395470Spramodbg (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8400Sstevel@tonic-gate ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL)); 8410Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = &ibnex_ci_busops; 8420Sstevel@tonic-gate break; 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate case IBTL_IBNEX_IBC_FINI: 8450Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8465470Spramodbg (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8470Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = NULL; 8480Sstevel@tonic-gate break; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate case IBTL_IBNEX_REPROBE_DEV_REQ: 8510Sstevel@tonic-gate /* IBTL pass down request for ibt_reprobe_dev */ 8520Sstevel@tonic-gate clnt_dip = cb_args->cb_dip; 8530Sstevel@tonic-gate ASSERT(clnt_dip); 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate node_data = ddi_get_parent_data(clnt_dip); 8560Sstevel@tonic-gate ASSERT(node_data); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate /* Reprobe for IOC nodes only */ 8590Sstevel@tonic-gate ASSERT(node_data->node_type == IBNEX_IOC_NODE); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 8620Sstevel@tonic-gate * Start the reprobe. This could sleep as it is not 8630Sstevel@tonic-gate * from interrupt context. 8640Sstevel@tonic-gate */ 8650Sstevel@tonic-gate if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev, 8660Sstevel@tonic-gate clnt_dip, TQ_SLEEP) == 0) { 8670Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 8680Sstevel@tonic-gate "ibnex_ibtl_callback: taskq_dispatch failed"); 8690Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 8700Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 8710Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 8720Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE); 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate return (IBT_SUCCESS); 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate return (retval); 8780Sstevel@tonic-gate } 8790Sstevel@tonic-gate 8800Sstevel@tonic-gate 8810Sstevel@tonic-gate /* 8820Sstevel@tonic-gate * Bus-ops entry points 8830Sstevel@tonic-gate */ 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate /* 8860Sstevel@tonic-gate * ibnex_map_fault 8870Sstevel@tonic-gate * IOC drivers need not map memory. Return failure to fail any 8880Sstevel@tonic-gate * such calls. 8890Sstevel@tonic-gate */ 8900Sstevel@tonic-gate /*ARGSUSED*/ 89112163SRamaswamy.Tummala@Sun.COM int 8920Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat, 8930Sstevel@tonic-gate struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn, 8940Sstevel@tonic-gate uint_t prot, uint_t lock) 8950Sstevel@tonic-gate { 8960Sstevel@tonic-gate return (DDI_FAILURE); 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate /* 9010Sstevel@tonic-gate * ibnex_busctl 9020Sstevel@tonic-gate * bus_ctl bus_ops entry point 9030Sstevel@tonic-gate */ 9040Sstevel@tonic-gate /*ARGSUSED*/ 90512163SRamaswamy.Tummala@Sun.COM int 9060Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip, 9070Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 9080Sstevel@tonic-gate { 9090Sstevel@tonic-gate dev_info_t *child_dip; 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 9120Sstevel@tonic-gate "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop); 9130Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result); 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate switch (ctlop) { 9160Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 9170Sstevel@tonic-gate if (rdip == NULL) { 9180Sstevel@tonic-gate return (DDI_FAILURE); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate /* Log the relevant details of dip to sysbuf */ 9220Sstevel@tonic-gate cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n", 9230Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 9240Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate return (DDI_SUCCESS); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 9290Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9300Sstevel@tonic-gate return (ibnex_init_child(child_dip)); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 9330Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9340Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL); 9350Sstevel@tonic-gate return (DDI_SUCCESS); 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 9380Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 9390Sstevel@tonic-gate case DDI_CTLOPS_POWER : 9400Sstevel@tonic-gate return (DDI_SUCCESS); 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 9430Sstevel@tonic-gate /* 9440Sstevel@tonic-gate * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and 9450Sstevel@tonic-gate * DDI_FAILURE for the nodes enumerated by a Pseudo file. 9460Sstevel@tonic-gate */ 9470Sstevel@tonic-gate return (ndi_dev_is_persistent_node(rdip) ? 9480Sstevel@tonic-gate DDI_SUCCESS : DDI_FAILURE); 9490Sstevel@tonic-gate 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 9520Sstevel@tonic-gate /* 9530Sstevel@tonic-gate * Return DDI_SUCCESS, so that consistent buf alloc 9540Sstevel@tonic-gate * gets the default DMA IO minimum for the platform 9550Sstevel@tonic-gate */ 9560Sstevel@tonic-gate return (DDI_SUCCESS); 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate /* 9590Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be 9600Sstevel@tonic-gate * called by IB Nexus driver. 9610Sstevel@tonic-gate */ 9620Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 9630Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 9640Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 9650Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 9660Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 9670Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 9680Sstevel@tonic-gate case DDI_CTLOPS_POKE: 9690Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 9700Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 9710Sstevel@tonic-gate "%s%d: invalid op (%d) from %s inst%d", 9720Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 9730Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 9740Sstevel@tonic-gate return (DDI_FAILURE); 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate /* 9770Sstevel@tonic-gate * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we 9780Sstevel@tonic-gate * pass up 9790Sstevel@tonic-gate */ 9800Sstevel@tonic-gate default: 9810Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate } 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate /* 9870Sstevel@tonic-gate * ibnex_init_child() 9880Sstevel@tonic-gate * 9890Sstevel@tonic-gate * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD 9900Sstevel@tonic-gate * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED. 9910Sstevel@tonic-gate */ 9920Sstevel@tonic-gate static int 9930Sstevel@tonic-gate ibnex_init_child(dev_info_t *child) 9940Sstevel@tonic-gate { 9950Sstevel@tonic-gate int ret; 9960Sstevel@tonic-gate char name[MAXNAMELEN]; 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child); 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate /* Handle Pseudo nodes of client children */ 10010Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 10021093Shiremath /* Skip nodes without ib-node-type="merge" */ 10031093Shiremath if (ibnex_is_merge_node(child) != IBNEX_SUCCESS) 10041093Shiremath return (DDI_FAILURE); 10051093Shiremath 10060Sstevel@tonic-gate if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS) 10070Sstevel@tonic-gate return (DDI_FAILURE); 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate ddi_set_name_addr(child, name); 10100Sstevel@tonic-gate /* 10110Sstevel@tonic-gate * Merge the .conf node 10120Sstevel@tonic-gate */ 10130Sstevel@tonic-gate if (ndi_merge_node(child, 10140Sstevel@tonic-gate ibnex_name_child) == DDI_SUCCESS) { 10150Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 10160Sstevel@tonic-gate return (DDI_FAILURE); 10170Sstevel@tonic-gate } 10180Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS) 10230Sstevel@tonic-gate return (ret); 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate ddi_set_name_addr(child, name); 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate return (DDI_SUCCESS); 10280Sstevel@tonic-gate } 10290Sstevel@tonic-gate 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate int 10320Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name) 10330Sstevel@tonic-gate { 10340Sstevel@tonic-gate char **unit_addr; 10350Sstevel@tonic-gate uint_t n; 10360Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 10370Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 10380Sstevel@tonic-gate DDI_PROP_SUCCESS) { 10391093Shiremath IBTF_DPRINTF_L4("ibnex", 10401093Shiremath "\tname_pseudo_child: cannot find unit-address in %s.conf", 10410Sstevel@tonic-gate ddi_get_name(child)); 10420Sstevel@tonic-gate return (DDI_FAILURE); 10430Sstevel@tonic-gate } 10440Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 10450Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 10460Sstevel@tonic-gate " not well-formed", ddi_get_name(child)); 10470Sstevel@tonic-gate ddi_prop_free(unit_addr); 10480Sstevel@tonic-gate return (DDI_FAILURE); 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr); 10510Sstevel@tonic-gate ddi_prop_free(unit_addr); 10520Sstevel@tonic-gate return (DDI_SUCCESS); 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate /*ARGSUSED*/ 10570Sstevel@tonic-gate int 10580Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag) 10590Sstevel@tonic-gate { 10600Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 10610Sstevel@tonic-gate ibnex_node_data_t *node_datap; 10620Sstevel@tonic-gate ibnex_port_node_t *port_node; 10630Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate node_datap = ddi_get_parent_data(child); 10660Sstevel@tonic-gate if (node_datap == NULL) { 10670Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL"); 10680Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10690Sstevel@tonic-gate } 10700Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p" 10710Sstevel@tonic-gate "Node type %x", node_datap, node_datap->node_type); 10720Sstevel@tonic-gate switch (node_datap->node_type) { 10730Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE: 10740Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10750Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10760Sstevel@tonic-gate port_node->port_num, 10770Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]); 10780Sstevel@tonic-gate break; 10790Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE: 10800Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10810Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s", 10820Sstevel@tonic-gate port_node->port_num, port_node->port_pkey, ibnex. 10830Sstevel@tonic-gate ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]); 10840Sstevel@tonic-gate break; 10850Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE: 10860Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10870Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10880Sstevel@tonic-gate port_node->port_num, 10890Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[port_node-> 10900Sstevel@tonic-gate port_commsvc_idx]); 10910Sstevel@tonic-gate break; 10920Sstevel@tonic-gate case IBNEX_IOC_NODE: 10930Sstevel@tonic-gate ioc = &node_datap->node_data.ioc_node; 10940Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX", 10950Sstevel@tonic-gate (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid); 10960Sstevel@tonic-gate break; 10970Sstevel@tonic-gate case IBNEX_PSEUDO_NODE: 10980Sstevel@tonic-gate pseudo = &node_datap->node_data.pseudo_node; 10990Sstevel@tonic-gate (void) snprintf(name, 11000Sstevel@tonic-gate IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr); 11010Sstevel@tonic-gate break; 11020Sstevel@tonic-gate default: 11030Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed"); 11040Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 11050Sstevel@tonic-gate } 11060Sstevel@tonic-gate 11070Sstevel@tonic-gate return (DDI_SUCCESS); 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate /* 11120Sstevel@tonic-gate * ibnex_bus_config() 11130Sstevel@tonic-gate * 11140Sstevel@tonic-gate * BUS_CONFIG_ONE: 11150Sstevel@tonic-gate * Enumerate the exact instance of the driver. Use the device node name 11160Sstevel@tonic-gate * to locate the exact instance. 11170Sstevel@tonic-gate * Query IBDM to find whether the hardware exits for the instance of the 11180Sstevel@tonic-gate * driver. If exists, create a device node and return NDI_SUCCESS. 11190Sstevel@tonic-gate * 11200Sstevel@tonic-gate * BUS_CONFIG_ALL: 11210Sstevel@tonic-gate * Enumerate all the instances of all the possible children (seen before 11220Sstevel@tonic-gate * and never seen before). 11230Sstevel@tonic-gate * 11240Sstevel@tonic-gate * BUS_CONFIG_DRIVER: 11250Sstevel@tonic-gate * Enumerate all the instances of a particular driver. 11260Sstevel@tonic-gate */ 112712163SRamaswamy.Tummala@Sun.COM 11280Sstevel@tonic-gate static int 11290Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag, 11300Sstevel@tonic-gate ddi_bus_config_op_t op, void *devname, dev_info_t **child) 11310Sstevel@tonic-gate { 11321093Shiremath int ret = IBNEX_SUCCESS, len, circ, need_bus_config; 11330Sstevel@tonic-gate char *device_name, *cname = NULL, *caddr = NULL; 113412163SRamaswamy.Tummala@Sun.COM dev_info_t *cdip; 11350Sstevel@tonic-gate ibnex_node_data_t *node_data; 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate switch (op) { 11380Sstevel@tonic-gate case BUS_CONFIG_ONE: 11391689Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, " 11401689Spramodbg "parent %p", parent); 11410Sstevel@tonic-gate 114212163SRamaswamy.Tummala@Sun.COM ndi_devi_enter(parent, &circ); 114312163SRamaswamy.Tummala@Sun.COM 11440Sstevel@tonic-gate len = strlen((char *)devname) + 1; 11450Sstevel@tonic-gate device_name = i_ddi_strdup(devname, KM_SLEEP); 11460Sstevel@tonic-gate i_ddi_parse_name(device_name, &cname, &caddr, NULL); 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate if (caddr == NULL || (strlen(caddr) == 0)) { 11490Sstevel@tonic-gate kmem_free(device_name, len); 115012163SRamaswamy.Tummala@Sun.COM ndi_devi_exit(parent, circ); 11510Sstevel@tonic-gate return (NDI_FAILURE); 11520Sstevel@tonic-gate } 11530Sstevel@tonic-gate 115412163SRamaswamy.Tummala@Sun.COM cdip = ndi_devi_findchild(parent, devname); 11558082SRamaswamy.Tummala@Sun.COM if (cdip) 11568082SRamaswamy.Tummala@Sun.COM node_data = ddi_get_parent_data(cdip); 115712163SRamaswamy.Tummala@Sun.COM 115812163SRamaswamy.Tummala@Sun.COM ndi_devi_exit(parent, circ); 115912163SRamaswamy.Tummala@Sun.COM 11608082SRamaswamy.Tummala@Sun.COM if (cdip == NULL || (node_data != NULL && 11618082SRamaswamy.Tummala@Sun.COM node_data->node_dip == NULL)) { 11620Sstevel@tonic-gate /* Node is not present */ 11630Sstevel@tonic-gate if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) { 11641093Shiremath ret = ibnex_ioc_bus_config_one(&parent, flag, 11651093Shiremath op, devname, child, &need_bus_config); 11661689Spramodbg if (!need_bus_config) { 11671689Spramodbg kmem_free(device_name, len); 11681093Shiremath return (ret); 11691689Spramodbg } 11701093Shiremath } else { 11710Sstevel@tonic-gate /* 117212163SRamaswamy.Tummala@Sun.COM * if IB Nexus is the parent, call MDI. Bus 117312163SRamaswamy.Tummala@Sun.COM * config with HCA as the parent would have 117412163SRamaswamy.Tummala@Sun.COM * enumerated the Pseudo node. 11750Sstevel@tonic-gate */ 11760Sstevel@tonic-gate ret = IBNEX_SUCCESS; 11770Sstevel@tonic-gate ibnex_pseudo_initnodes(); 11780Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 117912163SRamaswamy.Tummala@Sun.COM ret = ibnex_pseudo_mdi_config_one(flag, devname, 118012163SRamaswamy.Tummala@Sun.COM child, cname, caddr); 11810Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 118212163SRamaswamy.Tummala@Sun.COM kmem_free(device_name, len); 118312163SRamaswamy.Tummala@Sun.COM return (ret); 11841093Shiremath } 11850Sstevel@tonic-gate } 11860Sstevel@tonic-gate kmem_free(device_name, len); 11870Sstevel@tonic-gate break; 11880Sstevel@tonic-gate 11890Sstevel@tonic-gate case BUS_CONFIG_ALL: 11901093Shiremath /*FALLTHRU*/ 11910Sstevel@tonic-gate case BUS_CONFIG_DRIVER: 11921093Shiremath if (op == BUS_CONFIG_ALL) 11931689Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, " 11941689Spramodbg "parent %p", parent); 11951093Shiremath else 11961689Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER" 11971689Spramodbg ", parent %p", parent); 11981093Shiremath 11991093Shiremath /* 12001093Shiremath * Drive CONFIG requests for IB Nexus parent through 12011093Shiremath * MDI. This is needed to load the HCA drivers in x86 SRP 12021093Shiremath * boot case. 12031093Shiremath * 12041093Shiremath * CONFIG Requests with HCA parent will probe devices using 12051093Shiremath * ibdm and configure all children. 12061093Shiremath */ 120712163SRamaswamy.Tummala@Sun.COM ibdm_ioc_info_t *ioc_list, *new_ioc_list; 120812163SRamaswamy.Tummala@Sun.COM 120912163SRamaswamy.Tummala@Sun.COM mutex_enter(&ibnex.ibnex_mutex); 121012163SRamaswamy.Tummala@Sun.COM while (ibnex.ibnex_ioc_list_state != 121112163SRamaswamy.Tummala@Sun.COM IBNEX_IOC_LIST_READY) { 121212163SRamaswamy.Tummala@Sun.COM cv_wait(&ibnex.ibnex_ioc_list_cv, 121312163SRamaswamy.Tummala@Sun.COM &ibnex.ibnex_mutex); 121412163SRamaswamy.Tummala@Sun.COM } 121512163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW; 121612163SRamaswamy.Tummala@Sun.COM mutex_exit(&ibnex.ibnex_mutex); 121712163SRamaswamy.Tummala@Sun.COM /* Enumerate all the IOC's */ 121812163SRamaswamy.Tummala@Sun.COM ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time); 121912163SRamaswamy.Tummala@Sun.COM 122012163SRamaswamy.Tummala@Sun.COM new_ioc_list = ibdm_ibnex_get_ioc_list( 122112163SRamaswamy.Tummala@Sun.COM IBDM_IBNEX_NORMAL_PROBE); 122212163SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 122312163SRamaswamy.Tummala@Sun.COM "\tbus_config: alloc ioc_list %p", new_ioc_list); 122412163SRamaswamy.Tummala@Sun.COM /* 122512163SRamaswamy.Tummala@Sun.COM * Optimize the calls for each BUS_CONFIG_ALL request 122612163SRamaswamy.Tummala@Sun.COM * to the IB Nexus dip. This is currently done for 122712163SRamaswamy.Tummala@Sun.COM * each PDIP. 122812163SRamaswamy.Tummala@Sun.COM */ 122912163SRamaswamy.Tummala@Sun.COM mutex_enter(&ibnex.ibnex_mutex); 123012163SRamaswamy.Tummala@Sun.COM ioc_list = ibnex.ibnex_ioc_list; 123112163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_ioc_list = new_ioc_list; 123212163SRamaswamy.Tummala@Sun.COM ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 123312163SRamaswamy.Tummala@Sun.COM cv_broadcast(&ibnex.ibnex_ioc_list_cv); 123412163SRamaswamy.Tummala@Sun.COM mutex_exit(&ibnex.ibnex_mutex); 123512163SRamaswamy.Tummala@Sun.COM 123612163SRamaswamy.Tummala@Sun.COM if (ioc_list) { 12378695SRajkumar.Sivaprakasam@Sun.COM IBTF_DPRINTF_L4("ibnex", 123812163SRamaswamy.Tummala@Sun.COM "\tbus_config: freeing ioc_list %p", 123912163SRamaswamy.Tummala@Sun.COM ioc_list); 124012163SRamaswamy.Tummala@Sun.COM ibdm_ibnex_free_ioc_list(ioc_list); 12411093Shiremath } 124212163SRamaswamy.Tummala@Sun.COM 124312163SRamaswamy.Tummala@Sun.COM 124412163SRamaswamy.Tummala@Sun.COM ret = mdi_vhci_bus_config(parent, 124512163SRamaswamy.Tummala@Sun.COM flag, op, devname, child, NULL); 124612163SRamaswamy.Tummala@Sun.COM return (ret); 12470Sstevel@tonic-gate default: 12480Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config: error"); 12490Sstevel@tonic-gate ret = IBNEX_FAILURE; 12500Sstevel@tonic-gate break; 12510Sstevel@tonic-gate } 12522155Scth 12530Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 12540Sstevel@tonic-gate ret = ndi_busop_bus_config( 125512163SRamaswamy.Tummala@Sun.COM parent, flag, op, devname, child, 0); 12560Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config:" 12570Sstevel@tonic-gate "ndi_busop_bus_config : retval %d", ret); 12580Sstevel@tonic-gate return (ret); 12590Sstevel@tonic-gate } 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate return (NDI_FAILURE); 12620Sstevel@tonic-gate } 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate /* 12660Sstevel@tonic-gate * ibnex_config_root_iocnode() 12670Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 12680Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 12690Sstevel@tonic-gate */ 12700Sstevel@tonic-gate static int 12710Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name) 12720Sstevel@tonic-gate { 12730Sstevel@tonic-gate int ret, port = 0, iter = 0; 12740Sstevel@tonic-gate boolean_t displayed = B_FALSE; 12750Sstevel@tonic-gate char *portstr; 12760Sstevel@tonic-gate ib_guid_t hca_guid, iou_guid, ioc_guid; 12770Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 12780Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 12790Sstevel@tonic-gate 12800Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 12810Sstevel@tonic-gate "\tconfig_root_iocnode: name %s", device_name); 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate portstr = strstr(device_name, ":port="); 12840Sstevel@tonic-gate if (portstr == NULL) { 12850Sstevel@tonic-gate return (IBNEX_FAILURE); 12860Sstevel@tonic-gate } 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate portstr[0] = 0; portstr++; 12890Sstevel@tonic-gate if (ibnex_devname2port(portstr, &port)) { 12900Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port"); 12910Sstevel@tonic-gate return (IBNEX_FAILURE); 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate 12940Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 12951093Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 12960Sstevel@tonic-gate return (IBNEX_FAILURE); 12970Sstevel@tonic-gate } 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4), 13000Sstevel@tonic-gate "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid); 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 13030Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) { 13040Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 13050Sstevel@tonic-gate "\tconfig_root_iocnode: Port does not exist"); 13060Sstevel@tonic-gate return (IBNEX_FAILURE); 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate /* Wait until "port is up" */ 13100Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 13110Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 13120Sstevel@tonic-gate delay(drv_usectohz(10000)); 13130Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 13140Sstevel@tonic-gate hca_guid, port)) == NULL) { 13150Sstevel@tonic-gate return (IBNEX_FAILURE); 13160Sstevel@tonic-gate } 13170Sstevel@tonic-gate 13180Sstevel@tonic-gate if (iter++ == 400) { 13190Sstevel@tonic-gate if (displayed == B_FALSE) { 13200Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 13210Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 13220Sstevel@tonic-gate displayed = B_TRUE; 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate } 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 13270Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:" 13280Sstevel@tonic-gate "Port is initialized"); 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) { 13310Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 13320Sstevel@tonic-gate return (IBNEX_FAILURE); 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 13358082SRamaswamy.Tummala@Sun.COM if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) != 13368082SRamaswamy.Tummala@Sun.COM IBNEX_SUCCESS) { 13378082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 13388082SRamaswamy.Tummala@Sun.COM "\tconfig_root_ioc_node failed for pdip %p", parent); 13398082SRamaswamy.Tummala@Sun.COM } 13400Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 13410Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 13420Sstevel@tonic-gate return (ret); 13430Sstevel@tonic-gate } 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate static int 13470Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port) 13480Sstevel@tonic-gate { 13490Sstevel@tonic-gate char *temp; 13500Sstevel@tonic-gate int ret = IBNEX_FAILURE; 13510Sstevel@tonic-gate 13520Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin"); 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate temp = strchr(portstr, '='); 13550Sstevel@tonic-gate if (temp != NULL) { 13560Sstevel@tonic-gate temp++; 13570Sstevel@tonic-gate *port = ibnex_str2int(temp, strlen(temp), &ret); 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate return (ret); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate /* 13640Sstevel@tonic-gate * ibnex_config_all_children() 13650Sstevel@tonic-gate * Wait for lata SM initialization case before enumerating the nodes 13660Sstevel@tonic-gate * Get list of HCA's and HCA port information 13670Sstevel@tonic-gate * Create device device nodes and its node properties 13680Sstevel@tonic-gate * for port nodes and VPPA nodes 13690Sstevel@tonic-gate * Get list of all the IOC node information 13700Sstevel@tonic-gate * Create device nodes and its properties for all the IOCs 13710Sstevel@tonic-gate * if not created already 13720Sstevel@tonic-gate * Bind drivers for all the newly created device nodes 13730Sstevel@tonic-gate * Support Pseudo nodes enumerated using their .conf file 13740Sstevel@tonic-gate */ 137512163SRamaswamy.Tummala@Sun.COM void 13760Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent) 13770Sstevel@tonic-gate { 13780Sstevel@tonic-gate int ii; 13798082SRamaswamy.Tummala@Sun.COM ibdm_ioc_info_t *ioc_list; 13800Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 13810Sstevel@tonic-gate ib_guid_t hca_guid; 13822155Scth int circ; 13830Sstevel@tonic-gate 13840Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin"); 13850Sstevel@tonic-gate 138612163SRamaswamy.Tummala@Sun.COM 13871093Shiremath /* 13881093Shiremath * Enumerate children of this HCA, port nodes, 13892155Scth * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for 13902155Scth * locking. IB Nexus is enumerating the children 13912155Scth * of HCA, not MPXIO clients. 13921093Shiremath */ 13932155Scth ndi_devi_enter(parent, &circ); 13941093Shiremath hca_guid = ibtl_ibnex_hcadip2guid(parent); 13958082SRamaswamy.Tummala@Sun.COM ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time); 13961093Shiremath hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 13975470Spramodbg if (hca_list == NULL) { 13985470Spramodbg ndi_devi_exit(parent, circ); 13991093Shiremath return; 14005470Spramodbg } 14011093Shiremath ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr); 14021093Shiremath for (ii = 0; ii < hca_list->hl_nports; ii++) { 14031093Shiremath ibnex_create_port_nodes( 14041093Shiremath parent, &hca_list->hl_port_attr[ii]); 140512163SRamaswamy.Tummala@Sun.COM ibnex_create_vppa_nodes(parent, &hca_list->hl_port_attr[ii]); 14061093Shiremath } 14071093Shiremath ibdm_ibnex_free_hca_list(hca_list); 14082155Scth ndi_devi_exit(parent, circ); 14092155Scth 14102155Scth /* 14112155Scth * Use mdi_devi_enter() for locking. IB Nexus is 14126601Seota * enumerating MPxIO clients. 14132155Scth */ 14142155Scth mdi_devi_enter(parent, &circ); 14151093Shiremath 14161093Shiremath ibnex_pseudo_initnodes(); 14171093Shiremath 14188695SRajkumar.Sivaprakasam@Sun.COM mutex_enter(&ibnex.ibnex_mutex); 14198695SRajkumar.Sivaprakasam@Sun.COM while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) { 14208695SRajkumar.Sivaprakasam@Sun.COM cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex); 14218695SRajkumar.Sivaprakasam@Sun.COM } 14228695SRajkumar.Sivaprakasam@Sun.COM ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS; 14238082SRamaswamy.Tummala@Sun.COM ioc_list = ibnex.ibnex_ioc_list; 14241093Shiremath while (ioc_list) { 14258082SRamaswamy.Tummala@Sun.COM (void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0); 14261093Shiremath ioc_list = ioc_list->ioc_next; 14270Sstevel@tonic-gate } 14288695SRajkumar.Sivaprakasam@Sun.COM ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 14298695SRajkumar.Sivaprakasam@Sun.COM cv_broadcast(&ibnex.ibnex_ioc_list_cv); 14301093Shiremath 14311093Shiremath /* Config IBTF Pseudo clients */ 14321093Shiremath ibnex_config_pseudo_all(parent); 14331093Shiremath 14341093Shiremath mutex_exit(&ibnex.ibnex_mutex); 14352155Scth mdi_devi_exit(parent, circ); 14361093Shiremath 14370Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End"); 14380Sstevel@tonic-gate } 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate /* 14420Sstevel@tonic-gate * ibnex_create_port_nodes: 14430Sstevel@tonic-gate * Creates a device node per each communication service defined 14440Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 14450Sstevel@tonic-gate */ 144612163SRamaswamy.Tummala@Sun.COM void 14470Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 14480Sstevel@tonic-gate { 14490Sstevel@tonic-gate int idx; 14500Sstevel@tonic-gate dev_info_t *dip; 14510Sstevel@tonic-gate int rval; 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 14540Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) { 14550Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 14560Sstevel@tonic-gate idx, 0, &dip); 145712163SRamaswamy.Tummala@Sun.COM if (rval != IBNEX_SUCCESS || dip == NULL) { 14580Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 14590Sstevel@tonic-gate IBNEX_PORT_COMMSVC_NODE, 0, &rval, 14600Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 14610Sstevel@tonic-gate } 14620Sstevel@tonic-gate } 14630Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 14640Sstevel@tonic-gate } 14650Sstevel@tonic-gate 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate /* 14680Sstevel@tonic-gate * ibnex_create_vppa_nodes: 14690Sstevel@tonic-gate * Creates a device node per each communication service defined 14700Sstevel@tonic-gate * in the "vppa-commsvc-list" property and per each PKEY that 14710Sstevel@tonic-gate * this particular port supports and per HCA port 14720Sstevel@tonic-gate */ 147312163SRamaswamy.Tummala@Sun.COM void 147412163SRamaswamy.Tummala@Sun.COM ibnex_create_vppa_nodes( 147512163SRamaswamy.Tummala@Sun.COM dev_info_t *parent, ibdm_port_attr_t *port_attr) 14760Sstevel@tonic-gate { 14770Sstevel@tonic-gate int idx, ii; 14780Sstevel@tonic-gate int rval; 14790Sstevel@tonic-gate ib_pkey_t pkey; 14800Sstevel@tonic-gate dev_info_t *dip; 14810Sstevel@tonic-gate 14820Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin"); 14830Sstevel@tonic-gate 14840Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 14850Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 14860Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: " 14870Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 14880Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 14890Sstevel@tonic-gate return; 14900Sstevel@tonic-gate } 14910Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) { 149212163SRamaswamy.Tummala@Sun.COM if (strcmp("ipib", ibnex.ibnex_vppa_comm_svc_names[idx]) == 0) { 149312163SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", "Skipping IBD devices..."); 149412163SRamaswamy.Tummala@Sun.COM continue; 149512163SRamaswamy.Tummala@Sun.COM } 14960Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 14970Sstevel@tonic-gate pkey = port_attr->pa_pkey_tbl[ii].pt_pkey; 14980Sstevel@tonic-gate 14990Sstevel@tonic-gate if (IBNEX_INVALID_PKEY(pkey)) { 15000Sstevel@tonic-gate continue; 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate rval = ibnex_get_dip_from_guid( 15030Sstevel@tonic-gate port_attr->pa_port_guid, idx, pkey, &dip); 15048082SRamaswamy.Tummala@Sun.COM if ((rval != IBNEX_SUCCESS) || (dip == NULL)) { 15050Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, 15065470Spramodbg idx, IBNEX_VPPA_COMMSVC_NODE, 15075470Spramodbg pkey, &rval, IBNEX_CFGADM_ENUMERATE); 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate } 15100Sstevel@tonic-gate } 15110Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15120Sstevel@tonic-gate } 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate 15150Sstevel@tonic-gate /* 15160Sstevel@tonic-gate * ibnex_create_hcasvc_nodes: 15170Sstevel@tonic-gate * Creates a device node per each communication service defined 15180Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 15190Sstevel@tonic-gate */ 152012163SRamaswamy.Tummala@Sun.COM void 15210Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15220Sstevel@tonic-gate { 15230Sstevel@tonic-gate int idx; 15240Sstevel@tonic-gate dev_info_t *dip; 15250Sstevel@tonic-gate int rval; 15260Sstevel@tonic-gate 15270Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15280Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) { 15290Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 15300Sstevel@tonic-gate idx, 0, &dip); 153112163SRamaswamy.Tummala@Sun.COM if (rval != IBNEX_SUCCESS || dip == NULL) { 15320Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 15330Sstevel@tonic-gate IBNEX_HCASVC_COMMSVC_NODE, 0, &rval, 15340Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 15350Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: " 15360Sstevel@tonic-gate "commsvc_initnode failed, rval %x", rval); 15370Sstevel@tonic-gate } 15380Sstevel@tonic-gate } 15390Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15400Sstevel@tonic-gate } 15410Sstevel@tonic-gate 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate /* 15440Sstevel@tonic-gate * ibnex_bus_unconfig() 15450Sstevel@tonic-gate * 15460Sstevel@tonic-gate * Unconfigure a particular device node or all instance of a device 15470Sstevel@tonic-gate * driver device or all children of IBnex 15480Sstevel@tonic-gate */ 15490Sstevel@tonic-gate static int 15500Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent, 15510Sstevel@tonic-gate uint_t flag, ddi_bus_config_op_t op, void *device_name) 15520Sstevel@tonic-gate { 15538082SRamaswamy.Tummala@Sun.COM ibnex_node_data_t *ndp; 15548082SRamaswamy.Tummala@Sun.COM major_t major = (major_t)(uintptr_t)device_name; 15558082SRamaswamy.Tummala@Sun.COM dev_info_t *dip = NULL; 15568082SRamaswamy.Tummala@Sun.COM 15578082SRamaswamy.Tummala@Sun.COM if (ndi_busop_bus_unconfig(parent, flag, op, device_name) != 15588082SRamaswamy.Tummala@Sun.COM DDI_SUCCESS) 15598082SRamaswamy.Tummala@Sun.COM return (DDI_FAILURE); 15608082SRamaswamy.Tummala@Sun.COM 15618082SRamaswamy.Tummala@Sun.COM if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) && 15628082SRamaswamy.Tummala@Sun.COM (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) { 15638082SRamaswamy.Tummala@Sun.COM mutex_enter(&ibnex.ibnex_mutex); 156412163SRamaswamy.Tummala@Sun.COM /* 156512163SRamaswamy.Tummala@Sun.COM * IB dip. here we handle IOC and pseudo nodes which 156612163SRamaswamy.Tummala@Sun.COM * are the children of IB nexus. Cleanup only the nodes 156712163SRamaswamy.Tummala@Sun.COM * with matching major number. We also need to cleanup 156812163SRamaswamy.Tummala@Sun.COM * the PathInfo links to the PHCI here. 156912163SRamaswamy.Tummala@Sun.COM */ 157012163SRamaswamy.Tummala@Sun.COM for (ndp = ibnex.ibnex_ioc_node_head; 157112163SRamaswamy.Tummala@Sun.COM ndp; ndp = ndp->node_next) { 157212163SRamaswamy.Tummala@Sun.COM dip = ndp->node_dip; 157312163SRamaswamy.Tummala@Sun.COM if (dip && (ddi_driver_major(dip) == major)) { 157412163SRamaswamy.Tummala@Sun.COM (void) ibnex_offline_childdip(dip); 15758082SRamaswamy.Tummala@Sun.COM } 157612163SRamaswamy.Tummala@Sun.COM } 157712163SRamaswamy.Tummala@Sun.COM for (ndp = ibnex.ibnex_pseudo_node_head; 157812163SRamaswamy.Tummala@Sun.COM ndp; ndp = ndp->node_next) { 157912163SRamaswamy.Tummala@Sun.COM dip = ndp->node_dip; 158012163SRamaswamy.Tummala@Sun.COM if (dip && (ddi_driver_major(dip) == major)) { 158112163SRamaswamy.Tummala@Sun.COM (void) ibnex_offline_childdip(dip); 15828082SRamaswamy.Tummala@Sun.COM } 15838082SRamaswamy.Tummala@Sun.COM } 15848082SRamaswamy.Tummala@Sun.COM mutex_exit(&ibnex.ibnex_mutex); 15858082SRamaswamy.Tummala@Sun.COM } 15868082SRamaswamy.Tummala@Sun.COM return (DDI_SUCCESS); 15870Sstevel@tonic-gate } 15880Sstevel@tonic-gate 15890Sstevel@tonic-gate 15900Sstevel@tonic-gate /* 15910Sstevel@tonic-gate * ibnex_config_port_node() 15920Sstevel@tonic-gate * 15930Sstevel@tonic-gate * Configures a particular port / HCA node for a particular 15940Sstevel@tonic-gate * communication service. 15950Sstevel@tonic-gate * The format of the device_name is 15960Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 15970Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 15980Sstevel@tonic-gate * Port# = 0 for HCA_SVC communication service nodes 15990Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 16000Sstevel@tonic-gate * NULL when failed to enumerate the child node 16010Sstevel@tonic-gate */ 160212163SRamaswamy.Tummala@Sun.COM dev_info_t * 16030Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname) 16040Sstevel@tonic-gate { 16050Sstevel@tonic-gate int ii, index; 16060Sstevel@tonic-gate int rval; 16070Sstevel@tonic-gate uint8_t port_num; 16080Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 16090Sstevel@tonic-gate ib_pkey_t pkey; 16100Sstevel@tonic-gate dev_info_t *cdip; 16110Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 16120Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 16130Sstevel@tonic-gate 16140Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname); 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate if (ibnex_get_pkey_commsvc_index_portnum(devname, 16170Sstevel@tonic-gate &index, &pkey, &port_num) != IBNEX_SUCCESS) { 16180Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 16190Sstevel@tonic-gate "\tconfig_port_node: Invalid Service Name"); 16200Sstevel@tonic-gate return (NULL); 16210Sstevel@tonic-gate } 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 16240Sstevel@tonic-gate if (port_num == 0) { 16250Sstevel@tonic-gate /* 16260Sstevel@tonic-gate * Use the dummy port attribute for HCA node in hca_list 16270Sstevel@tonic-gate * Note : pa_state is always IBT_PORT_ACTIVE. 16280Sstevel@tonic-gate */ 16290Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 16300Sstevel@tonic-gate ASSERT(hca_list != NULL); 16310Sstevel@tonic-gate port_attr = hca_list->hl_hca_port_attr; 16320Sstevel@tonic-gate } else { 16330Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 16340Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 16350Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 16360Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 16370Sstevel@tonic-gate return (NULL); 16380Sstevel@tonic-gate } 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 16418082SRamaswamy.Tummala@Sun.COM ibdm_ibnex_port_settle_wait( 16428082SRamaswamy.Tummala@Sun.COM hca_guid, ibnex_port_settling_time); 16430Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 16440Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 16450Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 16460Sstevel@tonic-gate return (NULL); 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate } 16490Sstevel@tonic-gate } 16500Sstevel@tonic-gate 16510Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 16520Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 165312163SRamaswamy.Tummala@Sun.COM rval = ibnex_get_dip_from_guid(port_guid, index, pkey, &cdip); 165412163SRamaswamy.Tummala@Sun.COM if ((rval == IBNEX_SUCCESS) && cdip != NULL) { 16550Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 16560Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16570Sstevel@tonic-gate if (port_num != 0) 16580Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 16590Sstevel@tonic-gate else 16600Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 16610Sstevel@tonic-gate return (cdip); 16620Sstevel@tonic-gate } 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate if (pkey == 0 && port_num != 0) { 16650Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 16660Sstevel@tonic-gate port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval, 16670Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 16680Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 16690Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 16700Sstevel@tonic-gate } else if (pkey == 0 && port_num == 0) { 16710Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 16720Sstevel@tonic-gate port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval, 16730Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 16740Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 16750Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 16760Sstevel@tonic-gate } else { 16770Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 16780Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: " 16790Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 16800Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 16810Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16820Sstevel@tonic-gate return (NULL); 16830Sstevel@tonic-gate } 16840Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 16850Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 16860Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 16870Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, 16880Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 16890Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 16900Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 16910Sstevel@tonic-gate break; 16920Sstevel@tonic-gate } 16930Sstevel@tonic-gate } 16940Sstevel@tonic-gate } 16950Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16960Sstevel@tonic-gate if (port_num != 0) 16970Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 16980Sstevel@tonic-gate else 16990Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 17000Sstevel@tonic-gate return (cdip); 17010Sstevel@tonic-gate } 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate 17040Sstevel@tonic-gate /* 17050Sstevel@tonic-gate * ibnex_get_pkey_commsvc_index_portnum() 17060Sstevel@tonic-gate * Parses the device node name and extracts PKEY, communication 17070Sstevel@tonic-gate * service index & Port #. 17080Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 17090Sstevel@tonic-gate */ 171012163SRamaswamy.Tummala@Sun.COM int 17110Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index, 17120Sstevel@tonic-gate ib_pkey_t *pkey, uint8_t *port_num) 17130Sstevel@tonic-gate { 17140Sstevel@tonic-gate char *srv, **service_name, *temp; 17150Sstevel@tonic-gate int ii, ncommsvcs, ret; 17160Sstevel@tonic-gate 17170Sstevel@tonic-gate if (ibnex_devname_to_portnum(device_name, port_num) != 17185470Spramodbg IBNEX_SUCCESS) { 17190Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 1720*12533SRajkumar.Sivaprakasam@Sun.COM "\tget_pkey_commsvc_index_portnum: Invalid Service Name"); 1721*12533SRajkumar.Sivaprakasam@Sun.COM return (IBNEX_FAILURE); 17220Sstevel@tonic-gate } 17230Sstevel@tonic-gate srv = strchr(device_name, ','); 17240Sstevel@tonic-gate if (srv == 0) 17250Sstevel@tonic-gate return (IBNEX_FAILURE); 17260Sstevel@tonic-gate 17270Sstevel@tonic-gate srv++; 17280Sstevel@tonic-gate temp = strchr(srv, ','); 17290Sstevel@tonic-gate if (temp == 0) 17300Sstevel@tonic-gate return (IBNEX_FAILURE); 17310Sstevel@tonic-gate temp++; 17320Sstevel@tonic-gate *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret); 17330Sstevel@tonic-gate if (ret != IBNEX_SUCCESS) 17340Sstevel@tonic-gate return (ret); 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate if (*pkey == 0 && *port_num != 0) { 17370Sstevel@tonic-gate service_name = ibnex.ibnex_comm_svc_names; 17380Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_num_comm_svcs; 17390Sstevel@tonic-gate } else if (*pkey == 0 && *port_num == 0) { 17400Sstevel@tonic-gate service_name = ibnex.ibnex_hcasvc_comm_svc_names; 17410Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs; 17420Sstevel@tonic-gate } else { 17430Sstevel@tonic-gate service_name = ibnex.ibnex_vppa_comm_svc_names; 17440Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nvppa_comm_svcs; 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate for (ii = 0; ii < ncommsvcs; ii++) { 17480Sstevel@tonic-gate if (strcmp(service_name[ii], temp) == 0) { 17490Sstevel@tonic-gate break; 17500Sstevel@tonic-gate } 17510Sstevel@tonic-gate } 17520Sstevel@tonic-gate if (ii == ncommsvcs) 17530Sstevel@tonic-gate return (IBNEX_FAILURE); 17540Sstevel@tonic-gate 17550Sstevel@tonic-gate *index = ii; 17560Sstevel@tonic-gate return (IBNEX_SUCCESS); 17570Sstevel@tonic-gate } 17580Sstevel@tonic-gate 17590Sstevel@tonic-gate 17600Sstevel@tonic-gate /* 17610Sstevel@tonic-gate * ibnex_devname_to_portnum() 17620Sstevel@tonic-gate * Get portguid from device name 17630Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 17640Sstevel@tonic-gate */ 17650Sstevel@tonic-gate static int 17660Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum) 17670Sstevel@tonic-gate { 17680Sstevel@tonic-gate int ret; 17690Sstevel@tonic-gate char *temp1, *temp2; 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate temp1 = strchr(device_name, '@'); 17720Sstevel@tonic-gate if (temp1 == NULL) { 17730Sstevel@tonic-gate return (IBNEX_FAILURE); 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate temp2 = strchr(temp1, ','); 17760Sstevel@tonic-gate if (temp2 == NULL) 17770Sstevel@tonic-gate return (IBNEX_FAILURE); 17780Sstevel@tonic-gate temp1++; 17790Sstevel@tonic-gate *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret); 17800Sstevel@tonic-gate return (ret); 17810Sstevel@tonic-gate } 17820Sstevel@tonic-gate 17830Sstevel@tonic-gate 17840Sstevel@tonic-gate /* 17850Sstevel@tonic-gate * ibnex_config_ioc_node() 17860Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 17870Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 17880Sstevel@tonic-gate */ 17890Sstevel@tonic-gate static int 17901093Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip) 17910Sstevel@tonic-gate { 17920Sstevel@tonic-gate int ret; 17930Sstevel@tonic-gate ib_guid_t iou_guid, ioc_guid; 17940Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 17950Sstevel@tonic-gate 17960Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin"); 17970Sstevel@tonic-gate 17980Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 17991093Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 18000Sstevel@tonic-gate return (IBNEX_FAILURE); 18010Sstevel@tonic-gate } 18020Sstevel@tonic-gate 18038082SRamaswamy.Tummala@Sun.COM ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time); 18040Sstevel@tonic-gate 18050Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == 18060Sstevel@tonic-gate NULL) { 18070Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 18080Sstevel@tonic-gate return (IBNEX_FAILURE); 18090Sstevel@tonic-gate } 18100Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 18118082SRamaswamy.Tummala@Sun.COM ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0); 18120Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18130Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 18148082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x", 18158082SRamaswamy.Tummala@Sun.COM ret); 18160Sstevel@tonic-gate return (ret); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate /* 18210Sstevel@tonic-gate * ibnex_devname_to_node_n_ioc_guids() 18220Sstevel@tonic-gate * Get node guid and ioc guid from the device name 18230Sstevel@tonic-gate * Format of the device node name is: 18240Sstevel@tonic-gate * ioc@<IOC GUID>,<IOU GUID> 18250Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 18260Sstevel@tonic-gate */ 18270Sstevel@tonic-gate static int 18280Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids( 18291093Shiremath char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid, 18301093Shiremath char **ioc_guid_strp) 18310Sstevel@tonic-gate { 18320Sstevel@tonic-gate char *temp1, *temp; 18330Sstevel@tonic-gate int len, ret; 18341093Shiremath char *ioc_guid_str; 18350Sstevel@tonic-gate 18360Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:" 18370Sstevel@tonic-gate "Device Name %s", device_name); 18380Sstevel@tonic-gate 18390Sstevel@tonic-gate if ((temp = strchr(device_name, '@')) == NULL) { 18400Sstevel@tonic-gate return (IBNEX_FAILURE); 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate if ((temp1 = strchr(++temp, ',')) == NULL) { 18430Sstevel@tonic-gate return (IBNEX_FAILURE); 18440Sstevel@tonic-gate } 18450Sstevel@tonic-gate *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret); 18460Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 18471093Shiremath if (ioc_guid_strp) { 18481093Shiremath ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1 18491093Shiremath - temp) + 1, KM_SLEEP); 18501093Shiremath (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1); 18511093Shiremath ioc_guid_str[temp1 - temp] = '\0'; 18521093Shiremath } 18530Sstevel@tonic-gate len = device_name + strlen(device_name) - ++temp1; 18540Sstevel@tonic-gate *iou_guid = ibnex_str2hex(temp1, len, &ret); 18550Sstevel@tonic-gate } 18560Sstevel@tonic-gate return (ret); 18570Sstevel@tonic-gate } 18580Sstevel@tonic-gate 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate /* 18610Sstevel@tonic-gate * ibnex_ioc_initnode() 18620Sstevel@tonic-gate * Allocate a pathinfo node for the IOC 18630Sstevel@tonic-gate * Initialize the device node 18640Sstevel@tonic-gate * Bind driver to the node 18650Sstevel@tonic-gate * Update IBnex global data 18660Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY 18670Sstevel@tonic-gate */ 18688082SRamaswamy.Tummala@Sun.COM static int 18698082SRamaswamy.Tummala@Sun.COM ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data, 18708082SRamaswamy.Tummala@Sun.COM ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 18710Sstevel@tonic-gate { 18728082SRamaswamy.Tummala@Sun.COM int rval, node_valid; 18738082SRamaswamy.Tummala@Sun.COM ibnex_node_state_t prev_state; 18740Sstevel@tonic-gate 18750Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 18768082SRamaswamy.Tummala@Sun.COM ASSERT(node_data); 18778082SRamaswamy.Tummala@Sun.COM 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate /* 18800Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure 18810Sstevel@tonic-gate * operation is in progress 18820Sstevel@tonic-gate */ 18830Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 18848082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 18858082SRamaswamy.Tummala@Sun.COM "\tioc_initnode_pdip : BUSY"); 18860Sstevel@tonic-gate return (IBNEX_BUSY); 18870Sstevel@tonic-gate } 18880Sstevel@tonic-gate 18898082SRamaswamy.Tummala@Sun.COM prev_state = node_data->node_state; 18900Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 18910Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18920Sstevel@tonic-gate 18938082SRamaswamy.Tummala@Sun.COM rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid); 18940Sstevel@tonic-gate 18950Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 18960Sstevel@tonic-gate if (rval == IBNEX_SUCCESS) 18970Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 18988082SRamaswamy.Tummala@Sun.COM else if (node_valid) 18998082SRamaswamy.Tummala@Sun.COM node_data->node_state = prev_state; 19000Sstevel@tonic-gate 19010Sstevel@tonic-gate return (rval); 19020Sstevel@tonic-gate } 19030Sstevel@tonic-gate 19040Sstevel@tonic-gate /* 19050Sstevel@tonic-gate * ibnex_config_pseudo_all() 19060Sstevel@tonic-gate * Configure all the pseudo nodes 19070Sstevel@tonic-gate */ 19080Sstevel@tonic-gate static void 19091093Shiremath ibnex_config_pseudo_all(dev_info_t *pdip) 19100Sstevel@tonic-gate { 19110Sstevel@tonic-gate ibnex_node_data_t *nodep; 19120Sstevel@tonic-gate 19130Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 19140Sstevel@tonic-gate 19150Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; 19160Sstevel@tonic-gate nodep; nodep = nodep->node_next) { 19171689Spramodbg (void) ibnex_pseudo_config_one(nodep, NULL, pdip); 19180Sstevel@tonic-gate } 19190Sstevel@tonic-gate } 19200Sstevel@tonic-gate 19210Sstevel@tonic-gate 19220Sstevel@tonic-gate /* 19230Sstevel@tonic-gate * ibnex_pseudo_config_one() 19240Sstevel@tonic-gate */ 192512163SRamaswamy.Tummala@Sun.COM int 19261689Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr, 19271093Shiremath dev_info_t *pdip) 19280Sstevel@tonic-gate { 19291689Spramodbg int rval; 19308082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_node_t *pseudo; 19318082SRamaswamy.Tummala@Sun.COM ibnex_node_state_t prev_state; 19328082SRamaswamy.Tummala@Sun.COM 19338082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)", 19341689Spramodbg node_data, caddr, pdip); 19350Sstevel@tonic-gate 19360Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 19370Sstevel@tonic-gate 19380Sstevel@tonic-gate if (node_data == NULL) { 19398082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 19408082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: caddr = %s", caddr); 19411689Spramodbg 19421689Spramodbg /* 19431689Spramodbg * This function is now called with PHCI / HCA driver 19441689Spramodbg * as parent. The format of devicename is : 19451689Spramodbg * <driver_name>@<driver_name>,<unit_address> 19461689Spramodbg * The "caddr" part of the devicename matches the 19471689Spramodbg * format of pseudo_node_addr. 19481689Spramodbg * 19491689Spramodbg * Use "caddr" to find a matching Pseudo node entry. 19501689Spramodbg */ 19510Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 19521689Spramodbg (void *)caddr, 0, 0); 19530Sstevel@tonic-gate } 19540Sstevel@tonic-gate 19558082SRamaswamy.Tummala@Sun.COM if (node_data == NULL) { 19568082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 19578082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: Invalid node"); 19588082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 19598082SRamaswamy.Tummala@Sun.COM } 19608082SRamaswamy.Tummala@Sun.COM 19618082SRamaswamy.Tummala@Sun.COM if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) { 19628082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 19638082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: Unconfigured node"); 19648082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 19658082SRamaswamy.Tummala@Sun.COM } 19668082SRamaswamy.Tummala@Sun.COM 19678082SRamaswamy.Tummala@Sun.COM pseudo = &node_data->node_data.pseudo_node; 19688082SRamaswamy.Tummala@Sun.COM 19690Sstevel@tonic-gate /* 19701093Shiremath * Do not enumerate nodes with ib-node-type set as "merge" 19711093Shiremath */ 19728082SRamaswamy.Tummala@Sun.COM if (pseudo->pseudo_merge_node == 1) { 19738082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 19748082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: merge_node"); 19750Sstevel@tonic-gate return (IBNEX_FAILURE); 19760Sstevel@tonic-gate } 19770Sstevel@tonic-gate 19780Sstevel@tonic-gate /* 19798082SRamaswamy.Tummala@Sun.COM * Check if a PI has already been created for the PDIP. 19808082SRamaswamy.Tummala@Sun.COM * If so, return SUCCESS. 19818082SRamaswamy.Tummala@Sun.COM */ 19828082SRamaswamy.Tummala@Sun.COM if (node_data->node_dip != NULL && mdi_pi_find(pdip, 19838082SRamaswamy.Tummala@Sun.COM pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) { 19848082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 19858082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: PI created," 19868082SRamaswamy.Tummala@Sun.COM " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr); 19878082SRamaswamy.Tummala@Sun.COM return (IBNEX_SUCCESS); 19888082SRamaswamy.Tummala@Sun.COM } 19898082SRamaswamy.Tummala@Sun.COM 19908082SRamaswamy.Tummala@Sun.COM /* 19918082SRamaswamy.Tummala@Sun.COM * Return EBUSY if another unconfigure 19920Sstevel@tonic-gate * operation is in progress 19930Sstevel@tonic-gate */ 19940Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 19958082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 19968082SRamaswamy.Tummala@Sun.COM "\tpseudo_config_one: BUSY"); 19970Sstevel@tonic-gate return (IBNEX_BUSY); 19980Sstevel@tonic-gate } 19990Sstevel@tonic-gate 20008082SRamaswamy.Tummala@Sun.COM 20018082SRamaswamy.Tummala@Sun.COM prev_state = node_data->node_state; 20020Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 20030Sstevel@tonic-gate 20040Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 20058082SRamaswamy.Tummala@Sun.COM rval = ibnex_pseudo_create_pi_pdip(node_data, pdip); 20060Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 20070Sstevel@tonic-gate 20088082SRamaswamy.Tummala@Sun.COM if (rval == IBNEX_SUCCESS) { 20090Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 20108082SRamaswamy.Tummala@Sun.COM } else { 20118082SRamaswamy.Tummala@Sun.COM node_data->node_state = prev_state; 20120Sstevel@tonic-gate } 20130Sstevel@tonic-gate 20148082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x", 20158082SRamaswamy.Tummala@Sun.COM rval); 20160Sstevel@tonic-gate return (rval); 20170Sstevel@tonic-gate } 20180Sstevel@tonic-gate 20190Sstevel@tonic-gate 20201093Shiremath /* 20211093Shiremath * ibnex_pseudo_mdi_config_one() 20221093Shiremath * This is similar to ibnex_pseudo_config_one. Few 20231093Shiremath * differences : 20241093Shiremath * 1. parent device lock not held(no ndi_devi_enter) 20251093Shiremath * 2. Called for IB Nexus as parent, not IB HCA as 20261093Shiremath * parent. 20271093Shiremath * 3. Calls mdi_vhci_bus_config() 20281689Spramodbg * This function skips checks for node_state, initializing 20291689Spramodbg * node_state, node_dip, etc. These checks and initializations 20301689Spramodbg * are done when BUS_CONFIG is called with PHCI as the parent. 20311093Shiremath */ 203212163SRamaswamy.Tummala@Sun.COM int 20331093Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child, 20341093Shiremath char *cname, char *caddr) 20351093Shiremath { 20361093Shiremath int rval, len; 20371093Shiremath char *node_addr; 20381093Shiremath ibnex_node_data_t *node_data; 20391093Shiremath 20401093Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:" 20411093Shiremath "cname = %s caddr = %s", cname, caddr); 20421093Shiremath 20431093Shiremath ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 20441093Shiremath 20451093Shiremath len = strlen(cname) + strlen(caddr) + 2; 20461093Shiremath node_addr = (char *)kmem_alloc(len, KM_SLEEP); 20471093Shiremath 20481093Shiremath (void) snprintf(node_addr, len, "%s,%s", cname, caddr); 20491093Shiremath node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 20501093Shiremath (void *)node_addr, 0, 0); 20511093Shiremath kmem_free(node_addr, len); 20521093Shiremath 20531689Spramodbg if (node_data == NULL) { 20541093Shiremath IBTF_DPRINTF_L2("ibnex", 20551093Shiremath "\tpseudo_mdi_config_one: Invalid node"); 20561093Shiremath return (IBNEX_FAILURE); 20571093Shiremath } 20581093Shiremath 20591093Shiremath mutex_exit(&ibnex.ibnex_mutex); 20601093Shiremath rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE, 20611093Shiremath devname, child, node_data->node_data.pseudo_node.pseudo_node_addr); 20621093Shiremath mutex_enter(&ibnex.ibnex_mutex); 20631093Shiremath 20641093Shiremath return (rval); 20651093Shiremath } 20661093Shiremath 20678082SRamaswamy.Tummala@Sun.COM 20680Sstevel@tonic-gate /* 20698082SRamaswamy.Tummala@Sun.COM * ibnex_pseudo_create_all_pi() 20708082SRamaswamy.Tummala@Sun.COM * Create all path infos node for a pseudo entry 20710Sstevel@tonic-gate */ 20720Sstevel@tonic-gate int 20738082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep) 20740Sstevel@tonic-gate { 20758082SRamaswamy.Tummala@Sun.COM int hcacnt, rc; 20768082SRamaswamy.Tummala@Sun.COM int hcafailcnt = 0; 20778082SRamaswamy.Tummala@Sun.COM dev_info_t *hca_dip; 20788082SRamaswamy.Tummala@Sun.COM ibdm_hca_list_t *hca_list, *head; 20798082SRamaswamy.Tummala@Sun.COM 20808082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)", 20818082SRamaswamy.Tummala@Sun.COM nodep); 20820Sstevel@tonic-gate ibdm_ibnex_get_hca_list(&hca_list, &hcacnt); 20830Sstevel@tonic-gate 20840Sstevel@tonic-gate head = hca_list; 20850Sstevel@tonic-gate 20868082SRamaswamy.Tummala@Sun.COM /* 20878082SRamaswamy.Tummala@Sun.COM * We return failure even if we fail for all HCAs. 20888082SRamaswamy.Tummala@Sun.COM */ 20890Sstevel@tonic-gate for (; hca_list != NULL; hca_list = hca_list->hl_next) { 20900Sstevel@tonic-gate hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 20918082SRamaswamy.Tummala@Sun.COM rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip); 20928082SRamaswamy.Tummala@Sun.COM if (rc != IBNEX_SUCCESS) 20938082SRamaswamy.Tummala@Sun.COM hcafailcnt++; 20940Sstevel@tonic-gate } 20950Sstevel@tonic-gate if (head) 20960Sstevel@tonic-gate ibdm_ibnex_free_hca_list(head); 20978082SRamaswamy.Tummala@Sun.COM 20988082SRamaswamy.Tummala@Sun.COM if (hcafailcnt == hcacnt) 20998082SRamaswamy.Tummala@Sun.COM rc = IBNEX_FAILURE; 21008082SRamaswamy.Tummala@Sun.COM else 21018082SRamaswamy.Tummala@Sun.COM rc = IBNEX_SUCCESS; 21028082SRamaswamy.Tummala@Sun.COM 21038082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x", 21048082SRamaswamy.Tummala@Sun.COM rc); 21058082SRamaswamy.Tummala@Sun.COM return (rc); 21068082SRamaswamy.Tummala@Sun.COM } 21078082SRamaswamy.Tummala@Sun.COM 21088082SRamaswamy.Tummala@Sun.COM static int 21098082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip) 21108082SRamaswamy.Tummala@Sun.COM { 21118082SRamaswamy.Tummala@Sun.COM mdi_pathinfo_t *pip; 21128082SRamaswamy.Tummala@Sun.COM int rval; 21138082SRamaswamy.Tummala@Sun.COM dev_info_t *cdip = NULL; 21148082SRamaswamy.Tummala@Sun.COM ibnex_pseudo_node_t *pseudo; 21158082SRamaswamy.Tummala@Sun.COM int first_pi = 0; 21168082SRamaswamy.Tummala@Sun.COM 21178082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p", 21188082SRamaswamy.Tummala@Sun.COM nodep, hca_dip); 21198082SRamaswamy.Tummala@Sun.COM 21208082SRamaswamy.Tummala@Sun.COM pseudo = &nodep->node_data.pseudo_node; 21218082SRamaswamy.Tummala@Sun.COM 21228082SRamaswamy.Tummala@Sun.COM rval = mdi_pi_alloc(hca_dip, 21238082SRamaswamy.Tummala@Sun.COM pseudo->pseudo_devi_name, pseudo->pseudo_node_addr, 21248082SRamaswamy.Tummala@Sun.COM pseudo->pseudo_node_addr, 0, &pip); 21258082SRamaswamy.Tummala@Sun.COM 21268082SRamaswamy.Tummala@Sun.COM if (rval != MDI_SUCCESS) { 21278082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:" 21288082SRamaswamy.Tummala@Sun.COM " mdi_pi_alloc failed"); 21298082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 21308082SRamaswamy.Tummala@Sun.COM } 21318082SRamaswamy.Tummala@Sun.COM cdip = mdi_pi_get_client(pip); 21328082SRamaswamy.Tummala@Sun.COM 21338082SRamaswamy.Tummala@Sun.COM if (nodep->node_dip == NULL) { 21348082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 21358082SRamaswamy.Tummala@Sun.COM "\tpseudo_create_pi: New dip %p", cdip); 21368082SRamaswamy.Tummala@Sun.COM 21378082SRamaswamy.Tummala@Sun.COM first_pi = 1; 21388082SRamaswamy.Tummala@Sun.COM nodep->node_dip = cdip; 21398082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, nodep); 21408082SRamaswamy.Tummala@Sun.COM } 21418082SRamaswamy.Tummala@Sun.COM 21428082SRamaswamy.Tummala@Sun.COM rval = mdi_pi_online(pip, 0); 21438082SRamaswamy.Tummala@Sun.COM 21448082SRamaswamy.Tummala@Sun.COM if (rval != MDI_SUCCESS) { 21458082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 21468082SRamaswamy.Tummala@Sun.COM "\tpseudo_create_pi: " 21478082SRamaswamy.Tummala@Sun.COM "mdi_pi_online: failed for pseudo dip %p," 21488082SRamaswamy.Tummala@Sun.COM " rval %d", cdip, rval); 21498082SRamaswamy.Tummala@Sun.COM rval = IBNEX_FAILURE; 21508082SRamaswamy.Tummala@Sun.COM if (first_pi == 1) { 21518082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, NULL); 21528082SRamaswamy.Tummala@Sun.COM (void) ibnex_offline_childdip(cdip); 21538082SRamaswamy.Tummala@Sun.COM nodep->node_dip = NULL; 21548082SRamaswamy.Tummala@Sun.COM } else 21558082SRamaswamy.Tummala@Sun.COM (void) mdi_pi_free(pip, 0); 21568082SRamaswamy.Tummala@Sun.COM } else 21578082SRamaswamy.Tummala@Sun.COM rval = IBNEX_SUCCESS; 21580Sstevel@tonic-gate return (rval); 21590Sstevel@tonic-gate } 21600Sstevel@tonic-gate 21610Sstevel@tonic-gate /* 21620Sstevel@tonic-gate * ibnex_ioc_create_pi() 21630Sstevel@tonic-gate * Create a pathinfo node for the ioc node 21640Sstevel@tonic-gate */ 21650Sstevel@tonic-gate static int 21661093Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data, 21678082SRamaswamy.Tummala@Sun.COM dev_info_t *pdip, int *node_valid) 21680Sstevel@tonic-gate { 21690Sstevel@tonic-gate mdi_pathinfo_t *pip; 21701093Shiremath int rval = DDI_FAILURE; 21718082SRamaswamy.Tummala@Sun.COM dev_info_t *cdip = NULL; 21728082SRamaswamy.Tummala@Sun.COM int create_prop = 0; 21738082SRamaswamy.Tummala@Sun.COM ibnex_ioc_node_t *ioc = &node_data->node_data.ioc_node; 21748082SRamaswamy.Tummala@Sun.COM 21758082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 21768082SRamaswamy.Tummala@Sun.COM "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip); 21778082SRamaswamy.Tummala@Sun.COM *node_valid = 1; 21788082SRamaswamy.Tummala@Sun.COM 21798082SRamaswamy.Tummala@Sun.COM /* 21808082SRamaswamy.Tummala@Sun.COM * For CONFIG_ONE requests through HCA dip, alloc 21818082SRamaswamy.Tummala@Sun.COM * for HCA dip driving BUS_CONFIG request. 21828082SRamaswamy.Tummala@Sun.COM */ 21838082SRamaswamy.Tummala@Sun.COM rval = mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str, 21848082SRamaswamy.Tummala@Sun.COM ioc->ioc_phci_guid, 0, &pip); 21858082SRamaswamy.Tummala@Sun.COM if (rval != MDI_SUCCESS) { 21868082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", 21878082SRamaswamy.Tummala@Sun.COM "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed", 21888082SRamaswamy.Tummala@Sun.COM pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid); 21898082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 21908082SRamaswamy.Tummala@Sun.COM } 21918082SRamaswamy.Tummala@Sun.COM cdip = mdi_pi_get_client(pip); 21928082SRamaswamy.Tummala@Sun.COM 21938082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p", 21948082SRamaswamy.Tummala@Sun.COM cdip); 21958082SRamaswamy.Tummala@Sun.COM 21968082SRamaswamy.Tummala@Sun.COM if (node_data->node_dip == NULL) { 21978082SRamaswamy.Tummala@Sun.COM node_data->node_dip = cdip; 21988082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, node_data); 21998082SRamaswamy.Tummala@Sun.COM create_prop = 1; 22008082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 22018082SRamaswamy.Tummala@Sun.COM "\tioc_create_pi: creating prop"); 22028082SRamaswamy.Tummala@Sun.COM if ((rval = ibnex_create_ioc_node_prop( 22038082SRamaswamy.Tummala@Sun.COM ioc_info, cdip)) != IBNEX_SUCCESS) { 22048082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 22058082SRamaswamy.Tummala@Sun.COM "\tioc_create_pi: creating prop failed"); 22068082SRamaswamy.Tummala@Sun.COM ibnex_delete_ioc_node_data(node_data); 22078082SRamaswamy.Tummala@Sun.COM *node_valid = 0; 22088082SRamaswamy.Tummala@Sun.COM ddi_prop_remove_all(cdip); 22098082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, NULL); 22108082SRamaswamy.Tummala@Sun.COM 22110Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 22120Sstevel@tonic-gate return (IBNEX_FAILURE); 22130Sstevel@tonic-gate } 22148082SRamaswamy.Tummala@Sun.COM } 22158082SRamaswamy.Tummala@Sun.COM 22168082SRamaswamy.Tummala@Sun.COM rval = mdi_pi_online(pip, 0); 22178082SRamaswamy.Tummala@Sun.COM 22188082SRamaswamy.Tummala@Sun.COM if (rval != MDI_SUCCESS) { 22198082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: " 22208082SRamaswamy.Tummala@Sun.COM "mdi_pi_online() failed ioc dip %p, rval %d", 22218082SRamaswamy.Tummala@Sun.COM cdip, rval); 22228082SRamaswamy.Tummala@Sun.COM rval = IBNEX_FAILURE; 22238082SRamaswamy.Tummala@Sun.COM if (create_prop) { 22248082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, NULL); 22258082SRamaswamy.Tummala@Sun.COM ddi_prop_remove_all(cdip); 22260Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data); 22278082SRamaswamy.Tummala@Sun.COM *node_valid = 0; 22280Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 22290Sstevel@tonic-gate } else 22308082SRamaswamy.Tummala@Sun.COM (void) mdi_pi_free(pip, 0); 22318082SRamaswamy.Tummala@Sun.COM } else 22328082SRamaswamy.Tummala@Sun.COM rval = IBNEX_SUCCESS; 22338082SRamaswamy.Tummala@Sun.COM 22348082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval); 22350Sstevel@tonic-gate return (rval); 22360Sstevel@tonic-gate } 22370Sstevel@tonic-gate 22380Sstevel@tonic-gate 22390Sstevel@tonic-gate /* 22400Sstevel@tonic-gate * ibnex_create_ioc_node_prop() 22410Sstevel@tonic-gate * Create IOC device node properties 22420Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 22430Sstevel@tonic-gate */ 22440Sstevel@tonic-gate static int 22450Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip) 22460Sstevel@tonic-gate { 22470Sstevel@tonic-gate uint16_t capabilities; 22480Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile; 22490Sstevel@tonic-gate 22500Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop"); 22510Sstevel@tonic-gate 22520Sstevel@tonic-gate if (ibnex_create_ioc_compatible_prop(cdip, 22530Sstevel@tonic-gate ioc_profile) != IBNEX_SUCCESS) { 22540Sstevel@tonic-gate return (IBNEX_FAILURE); 22550Sstevel@tonic-gate } 22560Sstevel@tonic-gate if ((ioc_info->ioc_iou_dc_valid) && 22570Sstevel@tonic-gate (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode", 22580Sstevel@tonic-gate ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) { 22590Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 22600Sstevel@tonic-gate "\tcreate_ioc_node_prop: iou-diagcode create failed"); 22610Sstevel@tonic-gate return (IBNEX_FAILURE); 22620Sstevel@tonic-gate } 22630Sstevel@tonic-gate if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) { 22640Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode", 22650Sstevel@tonic-gate ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) { 22660Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 22670Sstevel@tonic-gate "ioc-diagcode create failed"); 22680Sstevel@tonic-gate return (IBNEX_FAILURE); 22690Sstevel@tonic-gate } 22700Sstevel@tonic-gate } 22710Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth", 22720Sstevel@tonic-gate ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) { 22730Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 22740Sstevel@tonic-gate "\tcreate_ioc_node_prop: rdma-queue-depth create failed"); 22750Sstevel@tonic-gate return (IBNEX_FAILURE); 22760Sstevel@tonic-gate } 22770Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size", 22780Sstevel@tonic-gate ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) { 22790Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 22800Sstevel@tonic-gate "rdma-transfer-size create failed"); 22810Sstevel@tonic-gate return (IBNEX_FAILURE); 22820Sstevel@tonic-gate } 22830Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size", 22840Sstevel@tonic-gate ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) { 22850Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 22860Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-message-size create failed"); 22870Sstevel@tonic-gate return (IBNEX_FAILURE); 22880Sstevel@tonic-gate } 22890Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth", 22900Sstevel@tonic-gate ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) { 22910Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 22920Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-queue-depth create failed"); 22930Sstevel@tonic-gate return (IBNEX_FAILURE); 22940Sstevel@tonic-gate } 22950Sstevel@tonic-gate 22960Sstevel@tonic-gate capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8); 22970Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, 22985470Spramodbg "capabilities", capabilities) != DDI_PROP_SUCCESS) { 22990Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23000Sstevel@tonic-gate "\tcreate_ioc_node_prop: capabilities create failed"); 23010Sstevel@tonic-gate return (IBNEX_FAILURE); 23020Sstevel@tonic-gate } 23030Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string", 23040Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) { 23050Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23060Sstevel@tonic-gate "\tcreate_ioc_node_prop: id-string failed"); 23070Sstevel@tonic-gate return (IBNEX_FAILURE); 23080Sstevel@tonic-gate } 23090Sstevel@tonic-gate 23100Sstevel@tonic-gate /* 23110Sstevel@tonic-gate * Create properties to represent all the service entries supported 23120Sstevel@tonic-gate * by the IOC. Each service entry consists of 1) Service ID (64 bits) 23130Sstevel@tonic-gate * and 2) Service name (40 bytes). The service entry table is 23140Sstevel@tonic-gate * represented by two properties, service-ids and service-names. The 23150Sstevel@tonic-gate * service-id property is a array of int64's and service names is 23160Sstevel@tonic-gate * array of strings. The first element in the "service-ids" property 23170Sstevel@tonic-gate * corresponds to first string in the "service-names" and so on. 23180Sstevel@tonic-gate */ 23190Sstevel@tonic-gate if ((ioc_profile->ioc_service_entries != 0) && 23200Sstevel@tonic-gate (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS)) 23210Sstevel@tonic-gate return (IBNEX_FAILURE); 23220Sstevel@tonic-gate 23230Sstevel@tonic-gate /* Create destination port GID properties */ 23240Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS) 23250Sstevel@tonic-gate return (IBNEX_FAILURE); 23260Sstevel@tonic-gate 23270Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version", 23280Sstevel@tonic-gate ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) { 23290Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23300Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol-version create failed"); 23310Sstevel@tonic-gate return (IBNEX_FAILURE); 23320Sstevel@tonic-gate } 23330Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol", 23340Sstevel@tonic-gate ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) { 23350Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23360Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 23370Sstevel@tonic-gate return (IBNEX_FAILURE); 23380Sstevel@tonic-gate } 23390Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass", 23400Sstevel@tonic-gate ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) { 23410Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23420Sstevel@tonic-gate "\tcreate_ioc_node_prop: subclass create failed"); 23430Sstevel@tonic-gate return (IBNEX_FAILURE); 23440Sstevel@tonic-gate } 23450Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class", 23460Sstevel@tonic-gate ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) { 23470Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23480Sstevel@tonic-gate "\tcreate_ioc_node_prop: class prop create failed"); 23490Sstevel@tonic-gate return (IBNEX_FAILURE); 23500Sstevel@tonic-gate } 23510Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id", 23520Sstevel@tonic-gate ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) { 23530Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23540Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsys_id create failed"); 23550Sstevel@tonic-gate return (IBNEX_FAILURE); 23560Sstevel@tonic-gate } 23570Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id", 23580Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) { 23590Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23600Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsystem vendor create failed"); 23610Sstevel@tonic-gate return (IBNEX_FAILURE); 23620Sstevel@tonic-gate } 23630Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid", 23640Sstevel@tonic-gate ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) { 23650Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23660Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 23670Sstevel@tonic-gate return (IBNEX_FAILURE); 23680Sstevel@tonic-gate } 23690Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version", 23700Sstevel@tonic-gate ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) { 23710Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23720Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 23730Sstevel@tonic-gate return (IBNEX_FAILURE); 23740Sstevel@tonic-gate } 23750Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id", 23760Sstevel@tonic-gate ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) { 23770Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23780Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 23790Sstevel@tonic-gate return (IBNEX_FAILURE); 23800Sstevel@tonic-gate } 23810Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id", 23820Sstevel@tonic-gate ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) { 23830Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 23840Sstevel@tonic-gate "\tcreate_ioc_node_prop: vendor-id create failed"); 23850Sstevel@tonic-gate return (IBNEX_FAILURE); 23860Sstevel@tonic-gate } 23870Sstevel@tonic-gate return (IBNEX_SUCCESS); 23880Sstevel@tonic-gate } 23890Sstevel@tonic-gate 23900Sstevel@tonic-gate 23910Sstevel@tonic-gate /* 23920Sstevel@tonic-gate * ibnex_create_ioc_portgid_prop() 23930Sstevel@tonic-gate * Creates "port-entries", "port-list" properties 23940Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 23950Sstevel@tonic-gate */ 23960Sstevel@tonic-gate static int 23970Sstevel@tonic-gate ibnex_create_ioc_portgid_prop( 23980Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 23990Sstevel@tonic-gate { 24000Sstevel@tonic-gate uint64_t *port_gids; 24010Sstevel@tonic-gate int length, ii, jj; 24020Sstevel@tonic-gate int prop_len; 24030Sstevel@tonic-gate ibnex_node_data_t *node_data; 24040Sstevel@tonic-gate 24050Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop"); 24060Sstevel@tonic-gate 24070Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 24080Sstevel@tonic-gate ASSERT(node_data); 24090Sstevel@tonic-gate 24100Sstevel@tonic-gate prop_len = (ioc_info->ioc_nportgids != 0) ? 24110Sstevel@tonic-gate (2 * ioc_info->ioc_nportgids) : 1; 24120Sstevel@tonic-gate length = sizeof (uint64_t) * prop_len; 24130Sstevel@tonic-gate port_gids = kmem_zalloc(length, KM_SLEEP); 24140Sstevel@tonic-gate 24150Sstevel@tonic-gate for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) { 24160Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi; 24170Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo; 24180Sstevel@tonic-gate } 24190Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list", 24200Sstevel@tonic-gate (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) { 24210Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24220Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-list create failed"); 24230Sstevel@tonic-gate kmem_free(port_gids, length); 24240Sstevel@tonic-gate return (IBNEX_FAILURE); 24250Sstevel@tonic-gate } 24260Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries", 24270Sstevel@tonic-gate ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) { 24280Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24290Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-entries create failed"); 24300Sstevel@tonic-gate kmem_free(port_gids, length); 24310Sstevel@tonic-gate return (IBNEX_FAILURE); 24320Sstevel@tonic-gate } 24330Sstevel@tonic-gate 24340Sstevel@tonic-gate kmem_free(port_gids, length); 24350Sstevel@tonic-gate return (IBNEX_SUCCESS); 24360Sstevel@tonic-gate } 24370Sstevel@tonic-gate 24380Sstevel@tonic-gate 24390Sstevel@tonic-gate /* 24400Sstevel@tonic-gate * ibnex_create_ioc_srv_props() 24410Sstevel@tonic-gate * Creates "service-name" and "service-id" properties 24420Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 24430Sstevel@tonic-gate */ 24440Sstevel@tonic-gate static int 24450Sstevel@tonic-gate ibnex_create_ioc_srv_props( 24460Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 24470Sstevel@tonic-gate { 24480Sstevel@tonic-gate int length, ii; 24490Sstevel@tonic-gate uint64_t *srv_id; 24500Sstevel@tonic-gate char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU]; 24510Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile; 24520Sstevel@tonic-gate ibdm_srvents_info_t *srvents = ioc_info->ioc_serv; 24530Sstevel@tonic-gate 24540Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props"); 24550Sstevel@tonic-gate 24560Sstevel@tonic-gate length = profile->ioc_service_entries * sizeof (ib_dm_srv_t); 24570Sstevel@tonic-gate srv_id = kmem_zalloc(length, KM_SLEEP); 24580Sstevel@tonic-gate temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries)); 24590Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 24600Sstevel@tonic-gate srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN); 24610Sstevel@tonic-gate } 24620Sstevel@tonic-gate 24630Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 24640Sstevel@tonic-gate srv_id[ii] = srvents[ii].se_attr.srv_id; 24650Sstevel@tonic-gate bcopy(srvents[ii].se_attr.srv_name, 24660Sstevel@tonic-gate srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1)); 24670Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 24680Sstevel@tonic-gate "Service Names : %s", srv_names[ii]); 24690Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 24701093Shiremath "Service ID : %llX", srv_id[ii]); 24710Sstevel@tonic-gate } 24720Sstevel@tonic-gate 24730Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, 24740Sstevel@tonic-gate "service-id", (int64_t *)srv_id, 24750Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 24760Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24770Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-id create failed"); 24780Sstevel@tonic-gate kmem_free(srv_id, length); 24790Sstevel@tonic-gate return (IBNEX_FAILURE); 24800Sstevel@tonic-gate } 24810Sstevel@tonic-gate 24820Sstevel@tonic-gate if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 24830Sstevel@tonic-gate "service-name", (char **)srv_names, 24840Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 24850Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24860Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-name create failed"); 24870Sstevel@tonic-gate kmem_free(srv_id, length); 24880Sstevel@tonic-gate return (IBNEX_FAILURE); 24890Sstevel@tonic-gate } 24900Sstevel@tonic-gate kmem_free(srv_id, length); 24910Sstevel@tonic-gate return (IBNEX_SUCCESS); 24920Sstevel@tonic-gate } 24930Sstevel@tonic-gate 24940Sstevel@tonic-gate 24950Sstevel@tonic-gate /* 24960Sstevel@tonic-gate * ibnex_create_ioc_compatible_prop() 24970Sstevel@tonic-gate * Creates "compatible" property values 24980Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 24990Sstevel@tonic-gate */ 25000Sstevel@tonic-gate static int 25010Sstevel@tonic-gate ibnex_create_ioc_compatible_prop( 25020Sstevel@tonic-gate dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile) 25030Sstevel@tonic-gate { 25040Sstevel@tonic-gate char *temp; 25050Sstevel@tonic-gate int rval, ii; 25060Sstevel@tonic-gate char *compatible[IBNEX_MAX_COMPAT_NAMES]; 25070Sstevel@tonic-gate 25080Sstevel@tonic-gate /* 25090Sstevel@tonic-gate * Initialize the "compatible" property string as below: 25100Sstevel@tonic-gate * Compatible Strings : 25110Sstevel@tonic-gate * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver> 25120Sstevel@tonic-gate * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id> 25130Sstevel@tonic-gate * 3. ib.V<vid>P<pid>v<ver> 25140Sstevel@tonic-gate * 4. ib.V<vid>P<pid> 25150Sstevel@tonic-gate * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver> 25160Sstevel@tonic-gate * 6. ib.C<Class>c<Subclass>p<protocol> 25170Sstevel@tonic-gate * 25180Sstevel@tonic-gate * Note: 25190Sstevel@tonic-gate * All leading zeros must be present 25200Sstevel@tonic-gate * All numeric values must specified in hex without prefix "0x" 25210Sstevel@tonic-gate */ 25220Sstevel@tonic-gate 25230Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP); 25240Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 25250Sstevel@tonic-gate compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN); 25260Sstevel@tonic-gate 25270Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 25280Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08xv%04x", 25290Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 25300Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id, 25310Sstevel@tonic-gate ioc_profile->ioc_device_ver); 25320Sstevel@tonic-gate 25330Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 25340Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08x", 25350Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 25360Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id); 25370Sstevel@tonic-gate 25380Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 25390Sstevel@tonic-gate "ib.V%06xP%08xv%04x", 25400Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 25410Sstevel@tonic-gate ioc_profile->ioc_device_ver); 25420Sstevel@tonic-gate 25430Sstevel@tonic-gate (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN, 25440Sstevel@tonic-gate "ib.V%06xP%08x", 25450Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid); 25460Sstevel@tonic-gate 25470Sstevel@tonic-gate (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN, 25480Sstevel@tonic-gate "ib.C%04xc%04xp%04xr%04x", 25490Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 25500Sstevel@tonic-gate ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver); 25510Sstevel@tonic-gate 25520Sstevel@tonic-gate (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN, 25530Sstevel@tonic-gate "ib.C%04xc%04xp%04x", 25540Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 25550Sstevel@tonic-gate ioc_profile->ioc_protocol); 25560Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 25570Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]); 25580Sstevel@tonic-gate 25590Sstevel@tonic-gate /* Create the compatible property for child cdip */ 25600Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 25610Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES); 25620Sstevel@tonic-gate 25630Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 25640Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed"); 25650Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 25660Sstevel@tonic-gate return (IBNEX_FAILURE); 25670Sstevel@tonic-gate } 25680Sstevel@tonic-gate 25690Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 25700Sstevel@tonic-gate return (IBNEX_SUCCESS); 25710Sstevel@tonic-gate } 25720Sstevel@tonic-gate 25730Sstevel@tonic-gate 25740Sstevel@tonic-gate static void 25750Sstevel@tonic-gate ibnex_ioc_node_cleanup() 25760Sstevel@tonic-gate { 25770Sstevel@tonic-gate ibnex_node_data_t *node, *delete; 25780Sstevel@tonic-gate 25790Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 25800Sstevel@tonic-gate for (node = ibnex.ibnex_ioc_node_head; node; ) { 25810Sstevel@tonic-gate delete = node; 25820Sstevel@tonic-gate node = node->node_next; 25830Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 25840Sstevel@tonic-gate ibnex_delete_ioc_node_data(delete); 25850Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 25860Sstevel@tonic-gate } 25870Sstevel@tonic-gate } 25880Sstevel@tonic-gate 25890Sstevel@tonic-gate /* 25900Sstevel@tonic-gate * ibnex_delete_ioc_node_data() 25910Sstevel@tonic-gate * Delete IOC node from the list 25920Sstevel@tonic-gate */ 25930Sstevel@tonic-gate static void 25940Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node) 25950Sstevel@tonic-gate { 25960Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:"); 25970Sstevel@tonic-gate 25980Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 25990Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) { 26000Sstevel@tonic-gate ASSERT(ibnex.ibnex_ioc_node_head == node); 26010Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = NULL; 26020Sstevel@tonic-gate } else if (node->node_next == NULL) 26030Sstevel@tonic-gate node->node_prev->node_next = NULL; 26040Sstevel@tonic-gate else if (node->node_prev == NULL) { 26050Sstevel@tonic-gate node->node_next->node_prev = NULL; 26060Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node->node_next; 26070Sstevel@tonic-gate } else { 26080Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 26090Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 26100Sstevel@tonic-gate } 26110Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p", 26120Sstevel@tonic-gate ibnex.ibnex_ioc_node_head); 26130Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 26140Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 26150Sstevel@tonic-gate } 26160Sstevel@tonic-gate 26170Sstevel@tonic-gate 26180Sstevel@tonic-gate /* 26190Sstevel@tonic-gate * ibnex_dm_callback() 26200Sstevel@tonic-gate * 26210Sstevel@tonic-gate * This routine is registered with the IBDM during IB nexus attach. It 26220Sstevel@tonic-gate * is called by the IBDM module when it discovers 26230Sstevel@tonic-gate * New HCA port 26240Sstevel@tonic-gate * HCA port removal 26250Sstevel@tonic-gate * New HCA added 26260Sstevel@tonic-gate * HCA removed 26270Sstevel@tonic-gate */ 26280Sstevel@tonic-gate void 26290Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag) 26300Sstevel@tonic-gate { 26310Sstevel@tonic-gate char hca_guid[IBNEX_HCAGUID_STRSZ]; 26320Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc; 26330Sstevel@tonic-gate ibnex_node_data_t *node_data; 263410096SSudhakar.Dindukurti@Sun.COM dev_info_t *phci; 263512163SRamaswamy.Tummala@Sun.COM ib_guid_t *guid; 26360Sstevel@tonic-gate 26370Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag); 26380Sstevel@tonic-gate 26390Sstevel@tonic-gate switch (flag) { 26400Sstevel@tonic-gate case IBDM_EVENT_HCA_ADDED: 26410Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 26420Sstevel@tonic-gate (*(longlong_t *)arg)); 26430Sstevel@tonic-gate /* Create a devctl minor node for the HCA's port */ 26440Sstevel@tonic-gate if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR, 26450Sstevel@tonic-gate ddi_get_instance(ibnex.ibnex_dip), 26460Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 26470Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to " 26480Sstevel@tonic-gate "create minor node for port w/ guid %s", hca_guid); 26490Sstevel@tonic-gate } 26500Sstevel@tonic-gate 265112163SRamaswamy.Tummala@Sun.COM guid = kmem_alloc(sizeof (ib_guid_t), KM_SLEEP); 265212163SRamaswamy.Tummala@Sun.COM *guid = *(ib_guid_t *)arg; 265312163SRamaswamy.Tummala@Sun.COM if (ddi_taskq_dispatch(ibnex.ibnex_taskq_id, 265412163SRamaswamy.Tummala@Sun.COM ibnex_handle_hca_attach, guid, DDI_NOSLEEP) 265512163SRamaswamy.Tummala@Sun.COM != DDI_SUCCESS) { 265612229SRajkumar.Sivaprakasam@Sun.COM kmem_free(guid, sizeof (ib_guid_t)); 265712163SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to " 265812163SRamaswamy.Tummala@Sun.COM "dispatch HCA add event for guid %s", hca_guid); 265912163SRamaswamy.Tummala@Sun.COM } 266012163SRamaswamy.Tummala@Sun.COM 26610Sstevel@tonic-gate break; 26620Sstevel@tonic-gate 26630Sstevel@tonic-gate case IBDM_EVENT_HCA_REMOVED: 26640Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 26650Sstevel@tonic-gate (*(longlong_t *)arg)); 26660Sstevel@tonic-gate ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid); 26670Sstevel@tonic-gate break; 26680Sstevel@tonic-gate 26690Sstevel@tonic-gate case IBDM_EVENT_IOC_PROP_UPDATE: 26700Sstevel@tonic-gate ioc = ioc_list = (ibdm_ioc_info_t *)arg; 26710Sstevel@tonic-gate if (ioc_list == NULL) 26720Sstevel@tonic-gate break; 26730Sstevel@tonic-gate 26740Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 26750Sstevel@tonic-gate while (ioc_list) { 26760Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present( 26770Sstevel@tonic-gate IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL && 26780Sstevel@tonic-gate node_data->node_dip != NULL) { 26790Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_list); 26800Sstevel@tonic-gate } 26810Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 26820Sstevel@tonic-gate } 26830Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 26840Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 268510096SSudhakar.Dindukurti@Sun.COM break; 268610096SSudhakar.Dindukurti@Sun.COM 268710096SSudhakar.Dindukurti@Sun.COM case IBDM_EVENT_PORT_UP: 268810096SSudhakar.Dindukurti@Sun.COM case IBDM_EVENT_PORT_PKEY_CHANGE: 268910096SSudhakar.Dindukurti@Sun.COM phci = ibtl_ibnex_hcaguid2dip(*(longlong_t *)arg); 269011387SSurya.Prakki@Sun.COM (void) devfs_clean(phci, NULL, 0); 269110096SSudhakar.Dindukurti@Sun.COM break; 269210096SSudhakar.Dindukurti@Sun.COM default: 269310096SSudhakar.Dindukurti@Sun.COM break; 269410096SSudhakar.Dindukurti@Sun.COM 26950Sstevel@tonic-gate } 26960Sstevel@tonic-gate } 26970Sstevel@tonic-gate 26980Sstevel@tonic-gate 26990Sstevel@tonic-gate /* 270012163SRamaswamy.Tummala@Sun.COM * ibnex_get_node_and_dip_from_guid() 270112163SRamaswamy.Tummala@Sun.COM * 270212163SRamaswamy.Tummala@Sun.COM * Searches the linked list of the port nodes and returns the dip for 270312163SRamaswamy.Tummala@Sun.COM * the of the Port / Node guid requested. 270412163SRamaswamy.Tummala@Sun.COM * Returns NULL if not found 270512163SRamaswamy.Tummala@Sun.COM */ 270612163SRamaswamy.Tummala@Sun.COM int 270712163SRamaswamy.Tummala@Sun.COM ibnex_get_node_and_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey, 270812163SRamaswamy.Tummala@Sun.COM ibnex_node_data_t **nodep, dev_info_t **dip) 270912163SRamaswamy.Tummala@Sun.COM { 271012163SRamaswamy.Tummala@Sun.COM int node_index; 271112163SRamaswamy.Tummala@Sun.COM ib_guid_t node_guid; 271212163SRamaswamy.Tummala@Sun.COM ib_pkey_t node_pkey; 271312163SRamaswamy.Tummala@Sun.COM ibnex_node_data_t *node_data; 271412163SRamaswamy.Tummala@Sun.COM 271512163SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 271612163SRamaswamy.Tummala@Sun.COM "\tget_node_and_dip_from_guid: guid = %llX", guid); 271712163SRamaswamy.Tummala@Sun.COM 271812163SRamaswamy.Tummala@Sun.COM ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 271912163SRamaswamy.Tummala@Sun.COM /* Search for a matching entry in internal lists */ 272012163SRamaswamy.Tummala@Sun.COM node_data = ibnex.ibnex_port_node_head; 272112163SRamaswamy.Tummala@Sun.COM while (node_data) { 272212163SRamaswamy.Tummala@Sun.COM node_guid = node_data->node_data.port_node.port_guid; 272312163SRamaswamy.Tummala@Sun.COM node_index = node_data->node_data.port_node.port_commsvc_idx; 272412163SRamaswamy.Tummala@Sun.COM node_pkey = node_data->node_data.port_node.port_pkey; 272512163SRamaswamy.Tummala@Sun.COM if ((node_guid == guid) && (index == node_index) && 272612163SRamaswamy.Tummala@Sun.COM (node_pkey == pkey)) { 272712163SRamaswamy.Tummala@Sun.COM break; 272812163SRamaswamy.Tummala@Sun.COM } 272912163SRamaswamy.Tummala@Sun.COM node_data = node_data->node_next; 273012163SRamaswamy.Tummala@Sun.COM } 273112163SRamaswamy.Tummala@Sun.COM 273212163SRamaswamy.Tummala@Sun.COM /* matching found with a valid dip */ 273312163SRamaswamy.Tummala@Sun.COM if (node_data && node_data->node_dip) { 273412163SRamaswamy.Tummala@Sun.COM *nodep = node_data; 273512163SRamaswamy.Tummala@Sun.COM *dip = node_data->node_dip; 273612163SRamaswamy.Tummala@Sun.COM return (IBNEX_SUCCESS); 273712163SRamaswamy.Tummala@Sun.COM } else if (node_data && !node_data->node_dip) { /* dip is invalid */ 273812163SRamaswamy.Tummala@Sun.COM *nodep = node_data; 273912163SRamaswamy.Tummala@Sun.COM *dip = NULL; 274012163SRamaswamy.Tummala@Sun.COM return (IBNEX_SUCCESS); 274112163SRamaswamy.Tummala@Sun.COM } 274212163SRamaswamy.Tummala@Sun.COM 274312163SRamaswamy.Tummala@Sun.COM /* no match found */ 274412163SRamaswamy.Tummala@Sun.COM *nodep = NULL; 274512163SRamaswamy.Tummala@Sun.COM *dip = NULL; 274612163SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 274712163SRamaswamy.Tummala@Sun.COM } 274812163SRamaswamy.Tummala@Sun.COM 274912163SRamaswamy.Tummala@Sun.COM /* 27500Sstevel@tonic-gate * ibnex_get_dip_from_guid() 27510Sstevel@tonic-gate * 27520Sstevel@tonic-gate * Searches the linked list of the port nodes and returns the dip for 27530Sstevel@tonic-gate * the of the Port / Node guid requested. 27540Sstevel@tonic-gate * Returns NULL if not found 27550Sstevel@tonic-gate */ 27560Sstevel@tonic-gate int 27570Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey, 27580Sstevel@tonic-gate dev_info_t **dip) 27590Sstevel@tonic-gate { 27600Sstevel@tonic-gate int node_index; 27610Sstevel@tonic-gate ib_guid_t node_guid; 27620Sstevel@tonic-gate ib_pkey_t node_pkey; 27630Sstevel@tonic-gate ibnex_node_data_t *node_data; 27640Sstevel@tonic-gate 27650Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 27661093Shiremath "\tget_dip_from_guid: guid = %llX", guid); 27670Sstevel@tonic-gate 27680Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 27690Sstevel@tonic-gate /* Search for a matching entry in internal lists */ 27700Sstevel@tonic-gate node_data = ibnex.ibnex_port_node_head; 27710Sstevel@tonic-gate while (node_data) { 27720Sstevel@tonic-gate node_guid = node_data->node_data.port_node.port_guid; 27730Sstevel@tonic-gate node_index = node_data->node_data.port_node.port_commsvc_idx; 27740Sstevel@tonic-gate node_pkey = node_data->node_data.port_node.port_pkey; 27750Sstevel@tonic-gate if ((node_guid == guid) && (index == node_index) && 27760Sstevel@tonic-gate (node_pkey == pkey)) { 27770Sstevel@tonic-gate break; 27780Sstevel@tonic-gate } 27790Sstevel@tonic-gate node_data = node_data->node_next; 27800Sstevel@tonic-gate } 27810Sstevel@tonic-gate 27820Sstevel@tonic-gate /* matching found with a valid dip */ 27830Sstevel@tonic-gate if (node_data && node_data->node_dip) { 27840Sstevel@tonic-gate *dip = node_data->node_dip; 27850Sstevel@tonic-gate return (IBNEX_SUCCESS); 27860Sstevel@tonic-gate } else if (node_data && !node_data->node_dip) { /* dip is invalid */ 27870Sstevel@tonic-gate *dip = NULL; 27880Sstevel@tonic-gate return (IBNEX_SUCCESS); 27890Sstevel@tonic-gate } 27900Sstevel@tonic-gate 27910Sstevel@tonic-gate /* no match found */ 27920Sstevel@tonic-gate *dip = NULL; 27930Sstevel@tonic-gate return (IBNEX_FAILURE); 27940Sstevel@tonic-gate } 27950Sstevel@tonic-gate 27960Sstevel@tonic-gate 27970Sstevel@tonic-gate /* 27980Sstevel@tonic-gate * ibnex_comm_svc_init() 27990Sstevel@tonic-gate * Read the property and cache the values in the global 28000Sstevel@tonic-gate * structure. 28010Sstevel@tonic-gate * Check for max allowed length (4 bytes) of service name 28020Sstevel@tonic-gate * (each element of the property) 28030Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 28040Sstevel@tonic-gate */ 28050Sstevel@tonic-gate static ibnex_rval_t 28060Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type) 28070Sstevel@tonic-gate { 28080Sstevel@tonic-gate int i, len, count; 28090Sstevel@tonic-gate int ncomm_svcs; 28100Sstevel@tonic-gate char **comm_svcp; 28110Sstevel@tonic-gate char **servicep = NULL; 28120Sstevel@tonic-gate uint_t nservices = 0; 28130Sstevel@tonic-gate int *valid = NULL; 28140Sstevel@tonic-gate 28150Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x", 28160Sstevel@tonic-gate property, type); 28170Sstevel@tonic-gate 28180Sstevel@tonic-gate /* lookup the string array property */ 28190Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip, 28200Sstevel@tonic-gate DDI_PROP_DONTPASS, property, &servicep, &nservices) != 28210Sstevel@tonic-gate DDI_PROP_SUCCESS) { 28220Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property); 28230Sstevel@tonic-gate return (IBNEX_SUCCESS); 28240Sstevel@tonic-gate } 28250Sstevel@tonic-gate 28260Sstevel@tonic-gate if (nservices) 28270Sstevel@tonic-gate valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP); 28280Sstevel@tonic-gate 28290Sstevel@tonic-gate 28300Sstevel@tonic-gate /* first read the file to get a count of valid service entries */ 28310Sstevel@tonic-gate for (ncomm_svcs = 0, count = 0; count < nservices; count++) { 28320Sstevel@tonic-gate int j; 28330Sstevel@tonic-gate 28340Sstevel@tonic-gate len = strlen(servicep[count]); 28358082SRamaswamy.Tummala@Sun.COM /* 28368082SRamaswamy.Tummala@Sun.COM * ib.conf has NULL strings for port-svc-list & 28378082SRamaswamy.Tummala@Sun.COM * hca-svc-list, by default. Do not have L2 message 28388082SRamaswamy.Tummala@Sun.COM * for these. 28398082SRamaswamy.Tummala@Sun.COM */ 28408082SRamaswamy.Tummala@Sun.COM if (len == 1 || len > 4) { 28410Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 28428082SRamaswamy.Tummala@Sun.COM "Service name %s for property %s invalid : " 28438082SRamaswamy.Tummala@Sun.COM "length %d", servicep[count], property, len); 28448082SRamaswamy.Tummala@Sun.COM continue; 28458082SRamaswamy.Tummala@Sun.COM } else if (len == 0) { 28460Sstevel@tonic-gate continue; 28470Sstevel@tonic-gate } 28480Sstevel@tonic-gate if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) { 28490Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 28500Sstevel@tonic-gate "Service name %s invalid : Not unique", 28510Sstevel@tonic-gate servicep[count]); 28520Sstevel@tonic-gate continue; 28530Sstevel@tonic-gate } 28540Sstevel@tonic-gate 28550Sstevel@tonic-gate /* 28560Sstevel@tonic-gate * ibnex_unique_svcname checks for uniqueness in service names 28570Sstevel@tonic-gate * communication services fully initialized. Check uniqueness 28580Sstevel@tonic-gate * in service names currently initialized. 28590Sstevel@tonic-gate */ 28600Sstevel@tonic-gate for (j = 0; j < count; j++) 28610Sstevel@tonic-gate if (valid[j] && strncmp(servicep[count], 28620Sstevel@tonic-gate servicep[j], 4) == 0) { 28630Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 28640Sstevel@tonic-gate "Service name %s invalid : Not unique", 28650Sstevel@tonic-gate servicep[count]); 28660Sstevel@tonic-gate continue; 28670Sstevel@tonic-gate } 28680Sstevel@tonic-gate 28690Sstevel@tonic-gate valid[count] = 1; 28700Sstevel@tonic-gate ncomm_svcs++; 28710Sstevel@tonic-gate } 28720Sstevel@tonic-gate 28730Sstevel@tonic-gate /* if no valid entries found, bailout */ 28740Sstevel@tonic-gate if (nservices == 0 || ncomm_svcs == 0) { 28750Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property); 28760Sstevel@tonic-gate ddi_prop_free(servicep); /* free the property */ 28770Sstevel@tonic-gate if (valid) 28780Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 28790Sstevel@tonic-gate return (IBNEX_SUCCESS); 28800Sstevel@tonic-gate } 28810Sstevel@tonic-gate 28820Sstevel@tonic-gate comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP); 28830Sstevel@tonic-gate if (type == IBNEX_PORT_COMMSVC_NODE) { 28840Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = comm_svcp; 28850Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = ncomm_svcs; 28860Sstevel@tonic-gate } else if (type == IBNEX_VPPA_COMMSVC_NODE) { 28870Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = comm_svcp; 28880Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs; 28890Sstevel@tonic-gate } else if (type == IBNEX_HCASVC_COMMSVC_NODE) { 28900Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp; 28910Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs; 28920Sstevel@tonic-gate } 28930Sstevel@tonic-gate 28940Sstevel@tonic-gate /* copy the services into an array of strings */ 28950Sstevel@tonic-gate for (i = 0, count = 0; count < nservices; count++) { 28960Sstevel@tonic-gate if (valid[count] == 0) /* Skip invalid ones */ 28970Sstevel@tonic-gate continue; 28980Sstevel@tonic-gate comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP); 28990Sstevel@tonic-gate (void) strcpy(comm_svcp[i], servicep[count]); 29000Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 29010Sstevel@tonic-gate "\t\tService [%d]: %s", i, comm_svcp[i]); 29020Sstevel@tonic-gate ++i; 29030Sstevel@tonic-gate } 29040Sstevel@tonic-gate ddi_prop_free(servicep); 29050Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 29060Sstevel@tonic-gate return (IBNEX_SUCCESS); 29070Sstevel@tonic-gate } 29080Sstevel@tonic-gate 29090Sstevel@tonic-gate 29100Sstevel@tonic-gate /* 29110Sstevel@tonic-gate * ibnex_comm_svc_fini() 29120Sstevel@tonic-gate * Deallocate all the memory allocated for the communication 29130Sstevel@tonic-gate * service arrays. 29140Sstevel@tonic-gate */ 29150Sstevel@tonic-gate static void 29160Sstevel@tonic-gate ibnex_comm_svc_fini() 29170Sstevel@tonic-gate { 29180Sstevel@tonic-gate int index; 29190Sstevel@tonic-gate 29200Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) { 29210Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names[index], 29220Sstevel@tonic-gate (strlen(ibnex.ibnex_comm_svc_names[index]) + 1)); 29230Sstevel@tonic-gate } 29240Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names) { 29250Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names, 29260Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs * sizeof (char *)); 29270Sstevel@tonic-gate } 29280Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 29290Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names[index], 29300Sstevel@tonic-gate strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1); 29310Sstevel@tonic-gate } 29320Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names) { 29330Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names, 29340Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs * sizeof (char *)); 29350Sstevel@tonic-gate } 29360Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) { 29370Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index], 29380Sstevel@tonic-gate strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1); 29390Sstevel@tonic-gate } 29400Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names) { 29410Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names, 29420Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *)); 29430Sstevel@tonic-gate } 29440Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = NULL; 29450Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = 0; 29460Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = NULL; 29470Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = 0; 29480Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = NULL; 29490Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = 0; 29500Sstevel@tonic-gate } 29510Sstevel@tonic-gate 29520Sstevel@tonic-gate 29530Sstevel@tonic-gate /* 29540Sstevel@tonic-gate * ibnex_commsvc_initnode() 29550Sstevel@tonic-gate * This routine is specific to port/VPPA node creation 29560Sstevel@tonic-gate * Creates a device node for the comm service specified by commsvc_index 29570Sstevel@tonic-gate * Creates all the device node properties 29580Sstevel@tonic-gate * Allocates and initializes the node specific data 29590Sstevel@tonic-gate * Binds the device driver of the device node 29600Sstevel@tonic-gate * Returns "dev_info_t" of the child node or NULL in case of failure 29610Sstevel@tonic-gate * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect 29620Sstevel@tonic-gate * if the operation was successful, failed or was not performed. 29630Sstevel@tonic-gate */ 29640Sstevel@tonic-gate dev_info_t * 29650Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr, 29660Sstevel@tonic-gate int index, int node_type, ib_pkey_t pkey, int *rval, int flag) 29670Sstevel@tonic-gate { 29680Sstevel@tonic-gate int ret; 29690Sstevel@tonic-gate char *svcname; 29700Sstevel@tonic-gate dev_info_t *cdip; 29710Sstevel@tonic-gate ibnex_node_data_t *node_data; 29728082SRamaswamy.Tummala@Sun.COM ibnex_port_node_t *port_node; 29738082SRamaswamy.Tummala@Sun.COM char devname[MAXNAMELEN]; 29748695SRajkumar.Sivaprakasam@Sun.COM int cdip_allocated = 0; 29750Sstevel@tonic-gate 29760Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 29770Sstevel@tonic-gate 29780Sstevel@tonic-gate *rval = IBNEX_SUCCESS; 29790Sstevel@tonic-gate 29800Sstevel@tonic-gate /* 29810Sstevel@tonic-gate * prevent any races 29820Sstevel@tonic-gate * we have seen this node_data and it has been initialized 29830Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 29840Sstevel@tonic-gate * progress. 29850Sstevel@tonic-gate */ 29860Sstevel@tonic-gate node_data = ibnex_is_node_data_present(node_type, (void *)port_attr, 29870Sstevel@tonic-gate index, pkey); 29888082SRamaswamy.Tummala@Sun.COM 29898082SRamaswamy.Tummala@Sun.COM /* 29908082SRamaswamy.Tummala@Sun.COM * If this node has been explicity unconfigured by cfgadm, then it can 29918082SRamaswamy.Tummala@Sun.COM * be configured back again only by cfgadm configure. 29928082SRamaswamy.Tummala@Sun.COM */ 29938082SRamaswamy.Tummala@Sun.COM if (node_data && (node_data->node_ap_state == 29948082SRamaswamy.Tummala@Sun.COM IBNEX_NODE_AP_UNCONFIGURED)) { 29958082SRamaswamy.Tummala@Sun.COM *rval = IBNEX_FAILURE; 29968082SRamaswamy.Tummala@Sun.COM return (NULL); 29978082SRamaswamy.Tummala@Sun.COM } 29988082SRamaswamy.Tummala@Sun.COM 29990Sstevel@tonic-gate if (node_data && node_data->node_dip) { 30000Sstevel@tonic-gate /* 30010Sstevel@tonic-gate * Return NULL if another configure 30020Sstevel@tonic-gate * operation is in progress 30030Sstevel@tonic-gate */ 30040Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) { 30050Sstevel@tonic-gate *rval = IBNEX_BUSY; 30060Sstevel@tonic-gate return (NULL); 30070Sstevel@tonic-gate } else { 30080Sstevel@tonic-gate return (node_data->node_dip); 30090Sstevel@tonic-gate } 30100Sstevel@tonic-gate } else if (node_data == NULL) { 30110Sstevel@tonic-gate /* allocate a new ibnex_node_data_t */ 30120Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(node_type, port_attr, 30130Sstevel@tonic-gate index, pkey); 30148082SRamaswamy.Tummala@Sun.COM node_data->node_data.port_node.port_pdip = parent; 30150Sstevel@tonic-gate } 30160Sstevel@tonic-gate 30170Sstevel@tonic-gate /* 30180Sstevel@tonic-gate * Return NULL if another unconfigure operation is in progress 30190Sstevel@tonic-gate */ 30200Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 30210Sstevel@tonic-gate *rval = IBNEX_BUSY; 30220Sstevel@tonic-gate return (NULL); 30230Sstevel@tonic-gate } 30240Sstevel@tonic-gate 30250Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED); 30260Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 30270Sstevel@tonic-gate 30280Sstevel@tonic-gate switch (node_type) { 30290Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE : 30300Sstevel@tonic-gate svcname = ibnex.ibnex_vppa_comm_svc_names[index]; 30318082SRamaswamy.Tummala@Sun.COM port_node = &node_data->node_data.port_node; 30328082SRamaswamy.Tummala@Sun.COM (void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s", 30338082SRamaswamy.Tummala@Sun.COM IBNEX_IBPORT_CNAME, port_node->port_num, 30348082SRamaswamy.Tummala@Sun.COM port_node->port_pkey, svcname); 30350Sstevel@tonic-gate break; 30360Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE : 30370Sstevel@tonic-gate svcname = ibnex.ibnex_hcasvc_comm_svc_names[index]; 30388082SRamaswamy.Tummala@Sun.COM port_node = &node_data->node_data.port_node; 30398082SRamaswamy.Tummala@Sun.COM (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 30408082SRamaswamy.Tummala@Sun.COM IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 30410Sstevel@tonic-gate break; 30420Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE : 30430Sstevel@tonic-gate svcname = ibnex.ibnex_comm_svc_names[index]; 30448082SRamaswamy.Tummala@Sun.COM port_node = &node_data->node_data.port_node; 30458082SRamaswamy.Tummala@Sun.COM (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 30468082SRamaswamy.Tummala@Sun.COM IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 30470Sstevel@tonic-gate break; 30480Sstevel@tonic-gate default : 30490Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:" 30500Sstevel@tonic-gate "\tInvalid Node type"); 30510Sstevel@tonic-gate *rval = IBNEX_FAILURE; 30520Sstevel@tonic-gate ibnex_delete_port_node_data(node_data); 30530Sstevel@tonic-gate return (NULL); 30540Sstevel@tonic-gate } 30550Sstevel@tonic-gate 30568082SRamaswamy.Tummala@Sun.COM if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) { 30578082SRamaswamy.Tummala@Sun.COM if (i_ddi_devi_attached(cdip)) { 30588082SRamaswamy.Tummala@Sun.COM node_data->node_dip = cdip; 30598082SRamaswamy.Tummala@Sun.COM node_data->node_data.port_node.port_pdip = parent; 30608082SRamaswamy.Tummala@Sun.COM node_data->node_state = IBNEX_CFGADM_CONFIGURED; 30618082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, node_data); 30628695SRajkumar.Sivaprakasam@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found " 30638695SRajkumar.Sivaprakasam@Sun.COM "attached cdip 0x%p for devname %s", cdip, devname); 30648082SRamaswamy.Tummala@Sun.COM return (cdip); 30658082SRamaswamy.Tummala@Sun.COM } 30668082SRamaswamy.Tummala@Sun.COM } else { 30678082SRamaswamy.Tummala@Sun.COM ndi_devi_alloc_sleep(parent, 30688082SRamaswamy.Tummala@Sun.COM IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip); 30698695SRajkumar.Sivaprakasam@Sun.COM cdip_allocated = 1; 30708082SRamaswamy.Tummala@Sun.COM } 30718082SRamaswamy.Tummala@Sun.COM 30728082SRamaswamy.Tummala@Sun.COM node_data->node_dip = cdip; 30738082SRamaswamy.Tummala@Sun.COM ddi_set_parent_data(cdip, node_data); 30748082SRamaswamy.Tummala@Sun.COM mutex_exit(&ibnex.ibnex_mutex); 30758082SRamaswamy.Tummala@Sun.COM 30768082SRamaswamy.Tummala@Sun.COM 30770Sstevel@tonic-gate if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) == 30780Sstevel@tonic-gate IBNEX_SUCCESS) { 30790Sstevel@tonic-gate if (flag == IBNEX_DEVFS_ENUMERATE) 30800Sstevel@tonic-gate ret = ndi_devi_bind_driver(cdip, 0); 30810Sstevel@tonic-gate else 30820Sstevel@tonic-gate ret = ndi_devi_online(cdip, 0); 30830Sstevel@tonic-gate if (ret == NDI_SUCCESS) { 30840Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 30850Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 30868082SRamaswamy.Tummala@Sun.COM node_data->node_data.port_node.port_pdip = parent; 30870Sstevel@tonic-gate return (cdip); 30880Sstevel@tonic-gate } 30898695SRajkumar.Sivaprakasam@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE " 30908695SRajkumar.Sivaprakasam@Sun.COM "of cdip 0x%p for devname %s and flag %d failed", cdip, 30918695SRajkumar.Sivaprakasam@Sun.COM devname, flag); 30920Sstevel@tonic-gate } 30938082SRamaswamy.Tummala@Sun.COM 30940Sstevel@tonic-gate *rval = IBNEX_FAILURE; 30958695SRajkumar.Sivaprakasam@Sun.COM node_data->node_dip = NULL; 30968695SRajkumar.Sivaprakasam@Sun.COM ddi_set_parent_data(cdip, NULL); 30978695SRajkumar.Sivaprakasam@Sun.COM if (cdip_allocated) 30988695SRajkumar.Sivaprakasam@Sun.COM (void) ndi_devi_free(cdip); 30990Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 31000Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit"); 31010Sstevel@tonic-gate return (NULL); 31020Sstevel@tonic-gate } 31030Sstevel@tonic-gate 31040Sstevel@tonic-gate 31050Sstevel@tonic-gate /* 31060Sstevel@tonic-gate * ibnex_create_port_node_prop() 31070Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 31080Sstevel@tonic-gate */ 31090Sstevel@tonic-gate static int 31100Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr, 31110Sstevel@tonic-gate dev_info_t *child_dip, char *srvname, ib_pkey_t pkey) 31120Sstevel@tonic-gate { 31130Sstevel@tonic-gate if (ibnex_create_port_compatible_prop(child_dip, 31140Sstevel@tonic-gate srvname, port_attr) != DDI_PROP_SUCCESS) { 31150Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31160Sstevel@tonic-gate "\tcreate_port_node_prop: compatible update failed"); 31170Sstevel@tonic-gate return (IBNEX_FAILURE); 31180Sstevel@tonic-gate } 31190Sstevel@tonic-gate if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 31200Sstevel@tonic-gate "port-pkey", pkey) != DDI_PROP_SUCCESS)) { 31210Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31220Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 31230Sstevel@tonic-gate return (IBNEX_FAILURE); 31240Sstevel@tonic-gate } 31250Sstevel@tonic-gate 31260Sstevel@tonic-gate /* 31270Sstevel@tonic-gate * For HCA_SVC device nodes, port_num will be 0. 31280Sstevel@tonic-gate * Do not create the "port-number" & "port-guid" properties. 31290Sstevel@tonic-gate */ 31300Sstevel@tonic-gate if (port_attr->pa_port_num != 0) { 31310Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 31325470Spramodbg "port-number", port_attr->pa_port_num) != 31330Sstevel@tonic-gate DDI_PROP_SUCCESS) { 31340Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31350Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 31360Sstevel@tonic-gate return (IBNEX_FAILURE); 31370Sstevel@tonic-gate } 31380Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 31395470Spramodbg "port-guid", port_attr->pa_port_guid) != 31400Sstevel@tonic-gate DDI_PROP_SUCCESS) { 31410Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31420Sstevel@tonic-gate "\tcreate_port_node_prop: port-guid update failed"); 31430Sstevel@tonic-gate return (IBNEX_FAILURE); 31440Sstevel@tonic-gate } 31450Sstevel@tonic-gate } else { 31460Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 31470Sstevel@tonic-gate 31480Sstevel@tonic-gate /* 31490Sstevel@tonic-gate * HCA_SVC nodes require "num-ports" & "port-guids" 31500Sstevel@tonic-gate * properties. 31510Sstevel@tonic-gate * 31520Sstevel@tonic-gate * To create the num-ports & port-guids attribute : 31530Sstevel@tonic-gate * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid) 31540Sstevel@tonic-gate * 2. Form the array of port GUIDs. 31550Sstevel@tonic-gate */ 31560Sstevel@tonic-gate if ((hca_list = ibdm_ibnex_get_hca_info_by_guid( 31570Sstevel@tonic-gate port_attr->pa_hca_guid)) == NULL) { 31580Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31590Sstevel@tonic-gate "\tcreate_port_node_prop: hca_info_by_guid failed"); 31600Sstevel@tonic-gate return (IBNEX_FAILURE); 31610Sstevel@tonic-gate } 31620Sstevel@tonic-gate 31630Sstevel@tonic-gate if (hca_list->hl_nports != 0) { 31640Sstevel@tonic-gate ib_guid_t *port_guids; 31650Sstevel@tonic-gate uint8_t portnum; 31660Sstevel@tonic-gate 31670Sstevel@tonic-gate ASSERT(hca_list->hl_port_attr != NULL); 31680Sstevel@tonic-gate 31690Sstevel@tonic-gate port_guids = kmem_zalloc( 31700Sstevel@tonic-gate hca_list->hl_nports * sizeof (ib_guid_t), 31710Sstevel@tonic-gate KM_SLEEP); 31720Sstevel@tonic-gate 31730Sstevel@tonic-gate for (portnum = 0; portnum < hca_list->hl_nports; 31740Sstevel@tonic-gate portnum++) { 31750Sstevel@tonic-gate port_guids[portnum] = (hca_list-> 31760Sstevel@tonic-gate hl_port_attr[portnum]).pa_port_guid; 31770Sstevel@tonic-gate } 31780Sstevel@tonic-gate 31790Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, 31800Sstevel@tonic-gate child_dip, "port-guids", (int64_t *)port_guids, 31810Sstevel@tonic-gate hca_list->hl_nports) != DDI_PROP_SUCCESS) { 31820Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31830Sstevel@tonic-gate "\tcreate_port_node_prop: port-guids " 31840Sstevel@tonic-gate "create failed"); 31850Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 31860Sstevel@tonic-gate sizeof (ib_guid_t)); 31870Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 31880Sstevel@tonic-gate return (IBNEX_FAILURE); 31890Sstevel@tonic-gate } 31900Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 31910Sstevel@tonic-gate sizeof (ib_guid_t)); 31920Sstevel@tonic-gate } 31930Sstevel@tonic-gate 31940Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 31955470Spramodbg "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) { 31960Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 31970Sstevel@tonic-gate "\tcreate_port_node_prop: num-ports update failed"); 31980Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 31990Sstevel@tonic-gate return (IBNEX_FAILURE); 32000Sstevel@tonic-gate } 32010Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 32020Sstevel@tonic-gate } 32030Sstevel@tonic-gate 32040Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 32055470Spramodbg "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) { 32060Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32070Sstevel@tonic-gate "\tcreate_port_node_prop: hca-guid update failed"); 32080Sstevel@tonic-gate return (IBNEX_FAILURE); 32090Sstevel@tonic-gate } 32100Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 32115470Spramodbg "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) { 32120Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32130Sstevel@tonic-gate "\tcreate_port_node_prop: product-id update failed"); 32140Sstevel@tonic-gate return (IBNEX_FAILURE); 32150Sstevel@tonic-gate } 32160Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 32175470Spramodbg "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) { 32180Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32190Sstevel@tonic-gate "\tcreate_port_node_prop: vendor-id update failed"); 32200Sstevel@tonic-gate return (IBNEX_FAILURE); 32210Sstevel@tonic-gate } 32220Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version", 32230Sstevel@tonic-gate port_attr->pa_dev_version) != DDI_PROP_SUCCESS) { 32240Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32250Sstevel@tonic-gate "\tcreate_port_node_prop: device-version update failed"); 32260Sstevel@tonic-gate return (IBNEX_FAILURE); 32270Sstevel@tonic-gate } 32280Sstevel@tonic-gate return (IBNEX_SUCCESS); 32290Sstevel@tonic-gate } 32300Sstevel@tonic-gate 32310Sstevel@tonic-gate 32320Sstevel@tonic-gate /* 32330Sstevel@tonic-gate * ibnex_str2int() 32340Sstevel@tonic-gate * Utility function that converts a string of length "len" to 32350Sstevel@tonic-gate * integer. 32360Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 32370Sstevel@tonic-gate */ 323812163SRamaswamy.Tummala@Sun.COM int 32390Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret) 32400Sstevel@tonic-gate { 32410Sstevel@tonic-gate int intval = 0, ii; 32420Sstevel@tonic-gate 32430Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c); 32440Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 32450Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 32460Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 32470Sstevel@tonic-gate intval = intval * 10 +c[ii] - '0'; 32480Sstevel@tonic-gate else { 32490Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32500Sstevel@tonic-gate "\tstr2int: Invalid integer string %s..", c); 32510Sstevel@tonic-gate *ret = IBNEX_FAILURE; 32520Sstevel@tonic-gate break; 32530Sstevel@tonic-gate } 32540Sstevel@tonic-gate } 32550Sstevel@tonic-gate 32560Sstevel@tonic-gate return (intval); 32570Sstevel@tonic-gate } 32580Sstevel@tonic-gate 32590Sstevel@tonic-gate 32600Sstevel@tonic-gate /* 32610Sstevel@tonic-gate * ibnex_str2hex() 32620Sstevel@tonic-gate * Utility functions that converts a string of length "len" to 32630Sstevel@tonic-gate * hex value. Note. This function does not handle strings which 32640Sstevel@tonic-gate * string length more than 8 bytes. 32650Sstevel@tonic-gate * 32660Sstevel@tonic-gate */ 32670Sstevel@tonic-gate uint64_t 32680Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret) 32690Sstevel@tonic-gate { 32700Sstevel@tonic-gate uint64_t hex = 0, ii; 32710Sstevel@tonic-gate 32720Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 32730Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 32740Sstevel@tonic-gate hex = (ii == 0) ? hex : (hex << 4); 32750Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 32760Sstevel@tonic-gate hex |= c[ii] - '0'; 32770Sstevel@tonic-gate else if ((c[ii] >= 'a') && (c[ii] <= 'f')) 32780Sstevel@tonic-gate hex |= c[ii] - 'a' + 10; 32790Sstevel@tonic-gate else if ((c[ii] >= 'A') && (c[ii] <= 'F')) 32800Sstevel@tonic-gate hex |= c[ii] - 'A' + 10; 32810Sstevel@tonic-gate else { 32820Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32830Sstevel@tonic-gate "\tstr2hex: Invalid integer string"); 32840Sstevel@tonic-gate *ret = IBNEX_FAILURE; 32850Sstevel@tonic-gate break; 32860Sstevel@tonic-gate } 32870Sstevel@tonic-gate } 32880Sstevel@tonic-gate 32890Sstevel@tonic-gate return (hex); 32900Sstevel@tonic-gate } 32910Sstevel@tonic-gate 32920Sstevel@tonic-gate 32930Sstevel@tonic-gate /* 32940Sstevel@tonic-gate * ibnex_create_port_compatible_prop() 32950Sstevel@tonic-gate * Creates 'Compatibility' property for port / HCA_SVC device nodes 32960Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 32970Sstevel@tonic-gate */ 32980Sstevel@tonic-gate static int 32990Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip, 33000Sstevel@tonic-gate char *comm_svcp, ibdm_port_attr_t *port_attr) 33010Sstevel@tonic-gate { 33020Sstevel@tonic-gate int rval, i; 33030Sstevel@tonic-gate char *temp; 33040Sstevel@tonic-gate char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES]; 33050Sstevel@tonic-gate 33060Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin"); 33070Sstevel@tonic-gate /* 33080Sstevel@tonic-gate * Initialize the "compatible" property string as below: 33090Sstevel@tonic-gate * Compatible Strings : 33100Sstevel@tonic-gate * 1. ib.V<vid>P<pid>v<revision>.<service name>. 33110Sstevel@tonic-gate * 2. ib.V<vid>P<pid>.<service name>. 33120Sstevel@tonic-gate * 3. ib.<service name> 33130Sstevel@tonic-gate * Leading zeros must be present 33140Sstevel@tonic-gate */ 33150Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP); 33160Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) { 33170Sstevel@tonic-gate compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN); 33180Sstevel@tonic-gate } 33190Sstevel@tonic-gate 33200Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 33210Sstevel@tonic-gate "ib.V%06xP%08xv%04x.%s", 33220Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 33230Sstevel@tonic-gate port_attr->pa_dev_version, comm_svcp); 33240Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 33250Sstevel@tonic-gate "ib.V%06xP%08x.%s", 33260Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 33270Sstevel@tonic-gate comm_svcp); 33280Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 33290Sstevel@tonic-gate "ib.%s", comm_svcp); 33300Sstevel@tonic-gate 33310Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) 33320Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]); 33330Sstevel@tonic-gate 33340Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 33350Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES); 33360Sstevel@tonic-gate 33370Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 33380Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 33390Sstevel@tonic-gate return (IBNEX_FAILURE); 33400Sstevel@tonic-gate } 33410Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 33420Sstevel@tonic-gate return (IBNEX_SUCCESS); 33430Sstevel@tonic-gate } 33440Sstevel@tonic-gate 33450Sstevel@tonic-gate 33460Sstevel@tonic-gate /* 33470Sstevel@tonic-gate * ibnex_delete_port_node_data() 33480Sstevel@tonic-gate * Delete the parent private node data from the linked list 33490Sstevel@tonic-gate * Deallocate the memory of the port/ioc attributes 33500Sstevel@tonic-gate * Deallocate the memory of the node data 33510Sstevel@tonic-gate */ 33520Sstevel@tonic-gate static void 33530Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node) 33540Sstevel@tonic-gate { 33550Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) 33560Sstevel@tonic-gate ibnex.ibnex_port_node_head = NULL; 33570Sstevel@tonic-gate else if (node->node_next == NULL) 33580Sstevel@tonic-gate node->node_prev->node_next = NULL; 33590Sstevel@tonic-gate else if (node->node_prev == NULL) { 33600Sstevel@tonic-gate node->node_next->node_prev = NULL; 33610Sstevel@tonic-gate ibnex.ibnex_port_node_head = node->node_next; 33620Sstevel@tonic-gate } else { 33630Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 33640Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 33650Sstevel@tonic-gate } 33660Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 33670Sstevel@tonic-gate } 33680Sstevel@tonic-gate 33690Sstevel@tonic-gate 33700Sstevel@tonic-gate /* 33710Sstevel@tonic-gate * ibnex_is_node_data_present() 33720Sstevel@tonic-gate * Checks whether ibnex_node_t is created already 33730Sstevel@tonic-gate * Returns ibnex_node_data_t if found, otherwise NULL 33740Sstevel@tonic-gate */ 33750Sstevel@tonic-gate static ibnex_node_data_t * 33760Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr, 33770Sstevel@tonic-gate int index, ib_pkey_t pkey) 33780Sstevel@tonic-gate { 33790Sstevel@tonic-gate ibnex_node_data_t *nodep; 33800Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 33810Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 33820Sstevel@tonic-gate ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr; 33830Sstevel@tonic-gate 33840Sstevel@tonic-gate for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL; 33850Sstevel@tonic-gate nodep = nodep->node_next) { 33860Sstevel@tonic-gate if (nodep->node_data.ioc_node.ioc_guid == 33870Sstevel@tonic-gate ioc_infop->ioc_profile.ioc_guid) { 33880Sstevel@tonic-gate return (nodep); 33890Sstevel@tonic-gate } 33900Sstevel@tonic-gate } 33910Sstevel@tonic-gate 33920Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 33930Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 33940Sstevel@tonic-gate nodep = nodep->node_next) 33950Sstevel@tonic-gate if (strcmp(nodep->node_data.pseudo_node. 33960Sstevel@tonic-gate pseudo_node_addr, (char *)attr) == 0) 33970Sstevel@tonic-gate return (nodep); 33980Sstevel@tonic-gate 33990Sstevel@tonic-gate } else { 34000Sstevel@tonic-gate ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr; 34010Sstevel@tonic-gate 34020Sstevel@tonic-gate for (nodep = ibnex.ibnex_port_node_head; nodep != NULL; 34030Sstevel@tonic-gate nodep = nodep->node_next) { 34040Sstevel@tonic-gate if ((nodep->node_data.port_node.port_guid == 34050Sstevel@tonic-gate pattrp->pa_port_guid) && 34060Sstevel@tonic-gate (nodep->node_data.port_node.port_commsvc_idx == 34070Sstevel@tonic-gate index) && 34080Sstevel@tonic-gate (nodep->node_data.port_node.port_pkey == pkey)) { 34090Sstevel@tonic-gate return (nodep); 34100Sstevel@tonic-gate } 34110Sstevel@tonic-gate } 34120Sstevel@tonic-gate } 34130Sstevel@tonic-gate return (NULL); 34140Sstevel@tonic-gate } 34150Sstevel@tonic-gate 34160Sstevel@tonic-gate /* 34170Sstevel@tonic-gate * ibnex_lookup_unit_address_prop: 34180Sstevel@tonic-gate * 34191093Shiremath * If property with name is found, return its value 34200Sstevel@tonic-gate * otherwise return NULL. 34210Sstevel@tonic-gate */ 34220Sstevel@tonic-gate static char * 34231093Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name) 34240Sstevel@tonic-gate { 34250Sstevel@tonic-gate ddi_prop_t *propp; 34260Sstevel@tonic-gate 34271093Shiremath /* Search the list of properties for name */ 34280Sstevel@tonic-gate for (propp = head; propp != NULL; propp = propp->prop_next) { 34291093Shiremath if (strcmp(propp->prop_name, name) != 0) 34300Sstevel@tonic-gate continue; 34311093Shiremath /* named property should be valid and have a value */ 34320Sstevel@tonic-gate if (propp->prop_len <= 1) 34330Sstevel@tonic-gate break; 34340Sstevel@tonic-gate return ((char *)propp->prop_val); 34350Sstevel@tonic-gate } 34360Sstevel@tonic-gate 34370Sstevel@tonic-gate return ((char *)0); 34380Sstevel@tonic-gate } 34390Sstevel@tonic-gate 34400Sstevel@tonic-gate 34410Sstevel@tonic-gate /* 34420Sstevel@tonic-gate * ibnex_pseudo_initnodes() 34430Sstevel@tonic-gate * This routine is specific to pseudo node information handling 34440Sstevel@tonic-gate * Creates a ibnex_node_data_t all pseudo nodes children of ibnex 34450Sstevel@tonic-gate */ 34460Sstevel@tonic-gate void 34470Sstevel@tonic-gate ibnex_pseudo_initnodes() 34480Sstevel@tonic-gate { 34490Sstevel@tonic-gate int pnam_len, len; 34500Sstevel@tonic-gate ibnex_node_data_t *nodep; 34510Sstevel@tonic-gate struct hwc_spec *list, *spec; 34520Sstevel@tonic-gate char *node_addr, *temp, *unit_addr; 34531093Shiremath char *node_type; 34540Sstevel@tonic-gate 34550Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes"); 34560Sstevel@tonic-gate 34570Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 34580Sstevel@tonic-gate /* 34590Sstevel@tonic-gate * get a list of all "pseudo" children of "ib". 34600Sstevel@tonic-gate * for these children initialize/allocate an internal 34610Sstevel@tonic-gate * ibnex_node_data_t. 34620Sstevel@tonic-gate */ 34630Sstevel@tonic-gate list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1); 34640Sstevel@tonic-gate for (spec = list; spec != NULL; spec = spec->hwc_next) { 34650Sstevel@tonic-gate if (spec->hwc_devi_sys_prop_ptr == NULL) 34660Sstevel@tonic-gate continue; 34670Sstevel@tonic-gate 34681093Shiremath /* Check "ib-node-type" property for IOC .conf */ 34691093Shiremath node_type = ibnex_lookup_named_prop( 34701093Shiremath spec->hwc_devi_sys_prop_ptr, "ib-node-type"); 34711093Shiremath 34720Sstevel@tonic-gate /* "unit-address" property should be present */ 34731093Shiremath temp = ibnex_lookup_named_prop( 34741093Shiremath spec->hwc_devi_sys_prop_ptr, "unit-address"); 34750Sstevel@tonic-gate if (temp == NULL) 34760Sstevel@tonic-gate continue; 34770Sstevel@tonic-gate 34780Sstevel@tonic-gate pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2; 34790Sstevel@tonic-gate 34800Sstevel@tonic-gate node_addr = kmem_zalloc(pnam_len, KM_SLEEP); 34810Sstevel@tonic-gate 34820Sstevel@tonic-gate (void) snprintf(node_addr, 34830Sstevel@tonic-gate pnam_len, "%s,%s", spec->hwc_devi_name, temp); 34840Sstevel@tonic-gate 34850Sstevel@tonic-gate nodep = ibnex_is_node_data_present( 34860Sstevel@tonic-gate IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0); 34870Sstevel@tonic-gate 34880Sstevel@tonic-gate if (nodep) { 34890Sstevel@tonic-gate kmem_free(node_addr, pnam_len); 34900Sstevel@tonic-gate continue; 34910Sstevel@tonic-gate } 34920Sstevel@tonic-gate 34930Sstevel@tonic-gate nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE, 34940Sstevel@tonic-gate (void *)spec->hwc_devi_name, 0, 0); 34950Sstevel@tonic-gate 34960Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_node_addr = node_addr; 34970Sstevel@tonic-gate (void) snprintf(nodep->node_data. 34980Sstevel@tonic-gate pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr); 34990Sstevel@tonic-gate 35000Sstevel@tonic-gate len = strlen(temp) + 1; 35010Sstevel@tonic-gate unit_addr = (char *)kmem_alloc(len, KM_SLEEP); 35020Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr; 35030Sstevel@tonic-gate (void) snprintf(unit_addr, len, "%s", temp); 35040Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr_len = len; 35050Sstevel@tonic-gate 35061093Shiremath if (node_type && strcmp(node_type, "merge") == 0) 35071093Shiremath nodep->node_data.pseudo_node.pseudo_merge_node = 1; 35081093Shiremath 35090Sstevel@tonic-gate IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s" 35100Sstevel@tonic-gate " : drv name = %s", unit_addr, spec->hwc_devi_name); 35110Sstevel@tonic-gate } 35120Sstevel@tonic-gate hwc_free_spec_list(list); 35130Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 35140Sstevel@tonic-gate } 35150Sstevel@tonic-gate 35160Sstevel@tonic-gate 35170Sstevel@tonic-gate /* 35180Sstevel@tonic-gate * ibnex_init_child_nodedata() 35190Sstevel@tonic-gate * 35200Sstevel@tonic-gate * Allocate memory for the parent private data for device node 35210Sstevel@tonic-gate * Initializes the parent private child device node data. 35220Sstevel@tonic-gate * Returns pointer to the parent private data 35230Sstevel@tonic-gate */ 35240Sstevel@tonic-gate static ibnex_node_data_t * 35250Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index, 35260Sstevel@tonic-gate ib_pkey_t pkey) 35270Sstevel@tonic-gate { 35280Sstevel@tonic-gate char *devi_name; 35290Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 35300Sstevel@tonic-gate ibnex_ioc_node_t *ioc_node; 35310Sstevel@tonic-gate ibnex_node_data_t *node_data; 35320Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile; 35330Sstevel@tonic-gate 35340Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 35350Sstevel@tonic-gate 35360Sstevel@tonic-gate node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP); 35378082SRamaswamy.Tummala@Sun.COM node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED; 35380Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 35390Sstevel@tonic-gate node_data->node_type = node_type; 35400Sstevel@tonic-gate 35410Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 35420Sstevel@tonic-gate ioc_info = (ibdm_ioc_info_t *)attr; 35430Sstevel@tonic-gate ioc_profile = &ioc_info->ioc_profile; 35440Sstevel@tonic-gate ioc_node = &node_data->node_data.ioc_node; 35450Sstevel@tonic-gate 35460Sstevel@tonic-gate ioc_node->iou_guid = ioc_info->ioc_iou_guid; 35470Sstevel@tonic-gate ioc_node->ioc_guid = ioc_profile->ioc_guid; 35480Sstevel@tonic-gate (void) strncpy(ioc_node->ioc_id_string, 35490Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string, 35500Sstevel@tonic-gate IB_DM_IOC_ID_STRING_LEN); 35510Sstevel@tonic-gate ioc_node->ioc_ngids = ioc_info->ioc_nportgids; 35520Sstevel@tonic-gate 35530Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_ioc_node_head; 35540Sstevel@tonic-gate node_data->node_prev = NULL; 35550Sstevel@tonic-gate if (ibnex.ibnex_ioc_node_head) 35560Sstevel@tonic-gate ibnex.ibnex_ioc_node_head->node_prev = node_data; 35570Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node_data; 35580Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 35590Sstevel@tonic-gate devi_name = (char *)attr; 35600Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_devi_name = 35610Sstevel@tonic-gate kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP); 35620Sstevel@tonic-gate (void) strncpy(node_data->node_data.pseudo_node. 35630Sstevel@tonic-gate pseudo_devi_name, devi_name, strlen(devi_name)); 35640Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_pseudo_node_head; 35650Sstevel@tonic-gate node_data->node_prev = NULL; 35660Sstevel@tonic-gate if (ibnex.ibnex_pseudo_node_head) 35670Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head->node_prev = node_data; 35680Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head = node_data; 35690Sstevel@tonic-gate } else { 35700Sstevel@tonic-gate node_data->node_data.port_node.port_hcaguid = 35710Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_hca_guid; 35720Sstevel@tonic-gate node_data->node_data.port_node.port_guid = 35730Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_guid; 35740Sstevel@tonic-gate node_data->node_data.port_node.port_num = 35750Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_num; 35760Sstevel@tonic-gate node_data->node_data.port_node.port_commsvc_idx = index; 35770Sstevel@tonic-gate node_data->node_data.port_node.port_pkey = pkey; 35780Sstevel@tonic-gate 35790Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_port_node_head; 35800Sstevel@tonic-gate node_data->node_prev = NULL; 35810Sstevel@tonic-gate if (ibnex.ibnex_port_node_head) 35820Sstevel@tonic-gate ibnex.ibnex_port_node_head->node_prev = node_data; 35830Sstevel@tonic-gate ibnex.ibnex_port_node_head = node_data; 35840Sstevel@tonic-gate } 35850Sstevel@tonic-gate return (node_data); 35860Sstevel@tonic-gate } 35870Sstevel@tonic-gate 35880Sstevel@tonic-gate static int 35890Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, 35900Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *cookie) 35910Sstevel@tonic-gate { 35920Sstevel@tonic-gate int rc; 35930Sstevel@tonic-gate 35940Sstevel@tonic-gate 35950Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)", 35960Sstevel@tonic-gate dip, rdip, eventname, cookie); 35970Sstevel@tonic-gate 35980Sstevel@tonic-gate rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl, 35990Sstevel@tonic-gate rdip, eventname, cookie, NDI_EVENT_NOPASS); 36000Sstevel@tonic-gate if (rc == NDI_SUCCESS) { 36010Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36020Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = *cookie; 36030Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 36040Sstevel@tonic-gate } 36050Sstevel@tonic-gate 36060Sstevel@tonic-gate return (rc); 36070Sstevel@tonic-gate } 36080Sstevel@tonic-gate 36090Sstevel@tonic-gate static int 36100Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 36110Sstevel@tonic-gate ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip, 36120Sstevel@tonic-gate ddi_eventcookie_t cookie, void *arg, void *bus_impldata), 36130Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id) 36140Sstevel@tonic-gate { 36150Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 36160Sstevel@tonic-gate "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)", 36170Sstevel@tonic-gate dip, rdip, cookie, callback, arg, cb_id); 36180Sstevel@tonic-gate 36190Sstevel@tonic-gate return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl, 36200Sstevel@tonic-gate rdip, cookie, callback, arg, NDI_SLEEP, cb_id)); 36210Sstevel@tonic-gate } 36220Sstevel@tonic-gate 36230Sstevel@tonic-gate static int 36240Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) 36250Sstevel@tonic-gate { 36260Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)", 36270Sstevel@tonic-gate dip, cb_id); 36280Sstevel@tonic-gate 36290Sstevel@tonic-gate return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl, 36300Sstevel@tonic-gate cb_id)); 36310Sstevel@tonic-gate } 36320Sstevel@tonic-gate 36330Sstevel@tonic-gate static int 36340Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip, 36350Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata) 36360Sstevel@tonic-gate { 36370Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)", 36380Sstevel@tonic-gate dip, rdip, cookie, bus_impldata); 36390Sstevel@tonic-gate 36400Sstevel@tonic-gate return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip, 36410Sstevel@tonic-gate cookie, bus_impldata)); 36420Sstevel@tonic-gate } 36430Sstevel@tonic-gate 36440Sstevel@tonic-gate /* 36450Sstevel@tonic-gate * ibnex_reprobe_ioc_dev() 36460Sstevel@tonic-gate * 36470Sstevel@tonic-gate * This could be called as a result of ibt_reprobe_dev request or 36480Sstevel@tonic-gate * cfgadm command. The function is called from a taskq in case of 36490Sstevel@tonic-gate * ibt_reprobe_dev and from user context for cfgadm command. 36500Sstevel@tonic-gate * 36510Sstevel@tonic-gate * This function reprobes the properties for one IOC dip. 36520Sstevel@tonic-gate * 36530Sstevel@tonic-gate * node_reprobe_state should be set before calling this function. 36540Sstevel@tonic-gate */ 36550Sstevel@tonic-gate void 36560Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg) 36570Sstevel@tonic-gate { 36580Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 36590Sstevel@tonic-gate ibnex_node_data_t *node_data; 36600Sstevel@tonic-gate ibnex_ioc_node_t *ioc_data; 36610Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 36620Sstevel@tonic-gate 36630Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 36640Sstevel@tonic-gate ASSERT(dip != NULL); 36650Sstevel@tonic-gate 36660Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 36670Sstevel@tonic-gate ASSERT(node_data); 36680Sstevel@tonic-gate 36690Sstevel@tonic-gate if (node_data->node_dip == NULL) { 36700Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip"); 36710Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36720Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 36730Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 36740Sstevel@tonic-gate return; 36750Sstevel@tonic-gate } 36760Sstevel@tonic-gate ioc_data = &(node_data->node_data.ioc_node); 36770Sstevel@tonic-gate 36780Sstevel@tonic-gate /* Reprobe the IOC */ 36790Sstevel@tonic-gate ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid, 36800Sstevel@tonic-gate 1); 36810Sstevel@tonic-gate if (ioc_info == NULL) { 36820Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe"); 36830Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36840Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 1); 36850Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 36860Sstevel@tonic-gate return; 36870Sstevel@tonic-gate } 36880Sstevel@tonic-gate 36890Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36900Sstevel@tonic-gate if (node_data->node_dip) 36910Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info); 36920Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 36930Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 36940Sstevel@tonic-gate 36950Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 36960Sstevel@tonic-gate } 36970Sstevel@tonic-gate 36980Sstevel@tonic-gate /* 36990Sstevel@tonic-gate * ibnex_reprobe_all() 37000Sstevel@tonic-gate * 37010Sstevel@tonic-gate * This could be called as a result of cfgadm command. The function 37020Sstevel@tonic-gate * is called from user context. 37030Sstevel@tonic-gate * 37040Sstevel@tonic-gate * This function reprobes the properties for all IOC dips. 37050Sstevel@tonic-gate * 37060Sstevel@tonic-gate * ibnex_reprobe_state should be set before calling this function. 37070Sstevel@tonic-gate */ 37080Sstevel@tonic-gate void 37090Sstevel@tonic-gate ibnex_reprobe_ioc_all() 37100Sstevel@tonic-gate { 37110Sstevel@tonic-gate ibnex_node_data_t *node_data; 37120Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info_list, *ioc; 37130Sstevel@tonic-gate 37140Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 37150Sstevel@tonic-gate 37160Sstevel@tonic-gate /* Sweep the fabric */ 37170Sstevel@tonic-gate ioc = ioc_info_list = ibdm_ibnex_get_ioc_list( 37180Sstevel@tonic-gate IBDM_IBNEX_REPROBE_ALL); 37190Sstevel@tonic-gate if (ioc_info_list == NULL) { 37200Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37210Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 37220Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37230Sstevel@tonic-gate return; 37240Sstevel@tonic-gate } 37250Sstevel@tonic-gate 37260Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37270Sstevel@tonic-gate while (ioc_info_list) { 37280Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 37290Sstevel@tonic-gate ioc_info_list, 0, 0)) != NULL && 37300Sstevel@tonic-gate node_data->node_dip != NULL) { 37310Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info_list); 37320Sstevel@tonic-gate } 37330Sstevel@tonic-gate ioc_info_list = ioc_info_list->ioc_next; 37340Sstevel@tonic-gate } 37350Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 37360Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37370Sstevel@tonic-gate 37380Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 37390Sstevel@tonic-gate } 37400Sstevel@tonic-gate 37410Sstevel@tonic-gate /* 37420Sstevel@tonic-gate * Update the properties, if it has modified and notify IBTF client. 37430Sstevel@tonic-gate */ 37440Sstevel@tonic-gate static void 37450Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info) 37460Sstevel@tonic-gate { 37470Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 37480Sstevel@tonic-gate dev_info_t *dip = node_data->node_dip; 37490Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 37500Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 37510Sstevel@tonic-gate 37520Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 37530Sstevel@tonic-gate 37540Sstevel@tonic-gate ASSERT(dip != NULL); 37550Sstevel@tonic-gate 37560Sstevel@tonic-gate ioc = &node_data->node_data.ioc_node; 37570Sstevel@tonic-gate 37580Sstevel@tonic-gate evt_data = ioc_info->ioc_info_updated; 37590Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 37600Sstevel@tonic-gate 37610Sstevel@tonic-gate /* 37620Sstevel@tonic-gate * For a disconnected IOC : 37630Sstevel@tonic-gate * Store the ioc_profile for supplying cfgadm info 37640Sstevel@tonic-gate * ibdm maintains no info of disconnected IOC 37650Sstevel@tonic-gate * 37660Sstevel@tonic-gate * For reconnected IOC : 37670Sstevel@tonic-gate * ibdm has info of previous service entries 37680Sstevel@tonic-gate * ioc_profile maintained by ibnexus is used to 37690Sstevel@tonic-gate * update ib_srv_prop_updated. 37700Sstevel@tonic-gate * Free the ibnex maintained ioc_profile 37710Sstevel@tonic-gate */ 37720Sstevel@tonic-gate if (ioc_info->ioc_nportgids == 0) { 37730Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 37740Sstevel@tonic-gate "\tupdate_prop: IOC disconnected"); 37750Sstevel@tonic-gate ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc( 37760Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP); 37770Sstevel@tonic-gate bcopy(&ioc_info->ioc_profile, ioc->ioc_profile, 37780Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t)); 37790Sstevel@tonic-gate 37800Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs++; 37810Sstevel@tonic-gate } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 && 37820Sstevel@tonic-gate ioc->ioc_profile != NULL) { 37830Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 37840Sstevel@tonic-gate "\tupdate_prop: IOC reconnected"); 37850Sstevel@tonic-gate if (ioc->ioc_profile->ioc_service_entries != 37860Sstevel@tonic-gate ioc_info->ioc_profile.ioc_service_entries) 37870Sstevel@tonic-gate evt_data.ib_srv_prop_updated = 1; 37880Sstevel@tonic-gate 37890Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs--; 37900Sstevel@tonic-gate kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t)); 37910Sstevel@tonic-gate ioc->ioc_profile = NULL; 37920Sstevel@tonic-gate } 37930Sstevel@tonic-gate 37940Sstevel@tonic-gate /* Update the properties that have changed */ 37950Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37960Sstevel@tonic-gate if (evt_data.ib_gid_prop_updated) { 37970Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(dip, ioc_info) != 37980Sstevel@tonic-gate IBNEX_SUCCESS) { 37990Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38000Sstevel@tonic-gate return; 38010Sstevel@tonic-gate } 38020Sstevel@tonic-gate } 38030Sstevel@tonic-gate if (evt_data.ib_srv_prop_updated) { 38040Sstevel@tonic-gate if (ioc_info->ioc_profile.ioc_service_entries != 0 && 38050Sstevel@tonic-gate (ibnex_create_ioc_srv_props(dip, ioc_info) != 38060Sstevel@tonic-gate IBNEX_SUCCESS)) { 38070Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38080Sstevel@tonic-gate return; 38090Sstevel@tonic-gate } else if (ioc_info->ioc_profile.ioc_service_entries == 0) { 38100Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 38110Sstevel@tonic-gate "service-id"); 38120Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 38130Sstevel@tonic-gate "service-name"); 38140Sstevel@tonic-gate } 38150Sstevel@tonic-gate } 38160Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38170Sstevel@tonic-gate ioc->ioc_ngids = ioc_info->ioc_nportgids; 38180Sstevel@tonic-gate 38190Sstevel@tonic-gate /* 38200Sstevel@tonic-gate * Post an event if : 38210Sstevel@tonic-gate * 1. Properites have changed or NOTIFY_ALWAYS is set. 38220Sstevel@tonic-gate * 2. child dip is configured and a valid cookie for 38230Sstevel@tonic-gate * IB_PROP_UPDATE_EVENT. 38240Sstevel@tonic-gate */ 38250Sstevel@tonic-gate if ((evt_data.ib_prop_updated != 0 || 38260Sstevel@tonic-gate (node_data->node_reprobe_state & 38270Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) && 38280Sstevel@tonic-gate ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) && 38295470Spramodbg (evt_cookie != NULL))) { 38300Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38310Sstevel@tonic-gate 38320Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, dip, 38330Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 38340Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 38350Sstevel@tonic-gate "\tndi_post_event failed\n"); 38360Sstevel@tonic-gate 38370Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38380Sstevel@tonic-gate } 38390Sstevel@tonic-gate 38400Sstevel@tonic-gate /* 38410Sstevel@tonic-gate * Cleanup node_reprobe_state, for ibt_reprobe_dev 38420Sstevel@tonic-gate * requests, when reprobe all / node reprobe is in 38430Sstevel@tonic-gate * progress. ibnex_reprobe_ioc_dev is not called 38440Sstevel@tonic-gate * in this case. 38450Sstevel@tonic-gate */ 38460Sstevel@tonic-gate if (node_data->node_reprobe_state == 38470Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) 38480Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 38490Sstevel@tonic-gate } 38500Sstevel@tonic-gate 38510Sstevel@tonic-gate static ibnex_rval_t 38520Sstevel@tonic-gate ibnex_unique_svcname(char *svcname) 38530Sstevel@tonic-gate { 38540Sstevel@tonic-gate int i; 38550Sstevel@tonic-gate 38560Sstevel@tonic-gate /* Check Port Services */ 38570Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++) 38580Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname, 38590Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[i], 4) == 0) 38600Sstevel@tonic-gate return (IBNEX_FAILURE); 38610Sstevel@tonic-gate 38620Sstevel@tonic-gate /* Check VPPA Services */ 38630Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++) 38640Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname, 38650Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0) 38660Sstevel@tonic-gate return (IBNEX_FAILURE); 38670Sstevel@tonic-gate 38680Sstevel@tonic-gate /* Check HCA_SVC Services */ 38690Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++) 38700Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname, 38710Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0) 38720Sstevel@tonic-gate return (IBNEX_FAILURE); 38730Sstevel@tonic-gate 38740Sstevel@tonic-gate return (IBNEX_SUCCESS); 38750Sstevel@tonic-gate } 38760Sstevel@tonic-gate 38770Sstevel@tonic-gate static void 38780Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg) 38790Sstevel@tonic-gate { 38800Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 38810Sstevel@tonic-gate ibnex_node_data_t *node_data; 38820Sstevel@tonic-gate 38830Sstevel@tonic-gate ASSERT(dip != NULL); 38840Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 38850Sstevel@tonic-gate ASSERT(node_data); 38860Sstevel@tonic-gate 38870Sstevel@tonic-gate /* 38880Sstevel@tonic-gate * Return success if: 38890Sstevel@tonic-gate * 1. Reprobe for all nodes are in progress 38900Sstevel@tonic-gate * 2. Reprobe for this node is in progress. 38910Sstevel@tonic-gate * The reprobe in progress will complete eventually and 38920Sstevel@tonic-gate * update the properties, if required. 38930Sstevel@tonic-gate */ 38940Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38950Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state != 0 || 38960Sstevel@tonic-gate node_data->node_reprobe_state != 0) { 38970Sstevel@tonic-gate /* 38980Sstevel@tonic-gate * Setting NOTIFY_ALWAYS to ensure that 38990Sstevel@tonic-gate * DDI event is delivered always for 39000Sstevel@tonic-gate * ibt_reprobe_dev 39010Sstevel@tonic-gate */ 39020Sstevel@tonic-gate node_data->node_reprobe_state |= 39030Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 39040Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39050Sstevel@tonic-gate return; 39060Sstevel@tonic-gate } 39070Sstevel@tonic-gate node_data->node_reprobe_state = 39080Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 39090Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39100Sstevel@tonic-gate ibnex_reprobe_ioc_dev(arg); 39110Sstevel@tonic-gate } 39120Sstevel@tonic-gate 39130Sstevel@tonic-gate 39140Sstevel@tonic-gate /* 39150Sstevel@tonic-gate * MPxIO pathmangement routines. Currently IB nexus does not support 39160Sstevel@tonic-gate * any kind of pathmangement. So, just return success to make MPxIO 39170Sstevel@tonic-gate * framework happy. 39180Sstevel@tonic-gate */ 39190Sstevel@tonic-gate /*ARGSUSED*/ 39200Sstevel@tonic-gate static int 39218082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 39220Sstevel@tonic-gate { 39238082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip); 39240Sstevel@tonic-gate return (MDI_SUCCESS); 39250Sstevel@tonic-gate } 39260Sstevel@tonic-gate 39270Sstevel@tonic-gate 39280Sstevel@tonic-gate /*ARGSUSED*/ 39290Sstevel@tonic-gate static int 39308082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 39310Sstevel@tonic-gate { 39328082SRamaswamy.Tummala@Sun.COM dev_info_t *cdip; 39338082SRamaswamy.Tummala@Sun.COM ibnex_node_data_t *node_data; 39348082SRamaswamy.Tummala@Sun.COM int clnt_num_pi; 39358082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip); 39368082SRamaswamy.Tummala@Sun.COM 39378082SRamaswamy.Tummala@Sun.COM if (pip == NULL) 39388082SRamaswamy.Tummala@Sun.COM return (MDI_FAILURE); 39398082SRamaswamy.Tummala@Sun.COM /* 39408082SRamaswamy.Tummala@Sun.COM * Get the Client dev_info from the pathinfo. 39418082SRamaswamy.Tummala@Sun.COM */ 39428082SRamaswamy.Tummala@Sun.COM cdip = mdi_pi_get_client(pip); 39438082SRamaswamy.Tummala@Sun.COM if (cdip == NULL) 39448082SRamaswamy.Tummala@Sun.COM return (MDI_FAILURE); 39458082SRamaswamy.Tummala@Sun.COM 39468082SRamaswamy.Tummala@Sun.COM /* 39478082SRamaswamy.Tummala@Sun.COM * How many PIs do we have from this cdip ? 39488082SRamaswamy.Tummala@Sun.COM */ 39498082SRamaswamy.Tummala@Sun.COM clnt_num_pi = mdi_client_get_path_count(cdip); 39508082SRamaswamy.Tummala@Sun.COM 39518082SRamaswamy.Tummala@Sun.COM /* 39528082SRamaswamy.Tummala@Sun.COM * If this is the last PI that is being free'd ( called from 39538082SRamaswamy.Tummala@Sun.COM * mdi_pi_free) we have to clean up the node data for the cdip since 39548082SRamaswamy.Tummala@Sun.COM * the client would have been detached by mdi_devi_offline. 39558082SRamaswamy.Tummala@Sun.COM */ 39568082SRamaswamy.Tummala@Sun.COM if (clnt_num_pi == 1) { 395712163SRamaswamy.Tummala@Sun.COM node_data = ddi_get_parent_data(cdip); 395812163SRamaswamy.Tummala@Sun.COM if (node_data == NULL) 395912163SRamaswamy.Tummala@Sun.COM return (MDI_SUCCESS); 396012163SRamaswamy.Tummala@Sun.COM if (node_data->node_dip == cdip) { 396112163SRamaswamy.Tummala@Sun.COM node_data->node_dip = NULL; 396212163SRamaswamy.Tummala@Sun.COM node_data->node_state = IBNEX_CFGADM_UNCONFIGURED; 396312163SRamaswamy.Tummala@Sun.COM return (MDI_SUCCESS); 39648082SRamaswamy.Tummala@Sun.COM } 39658082SRamaswamy.Tummala@Sun.COM } 39660Sstevel@tonic-gate return (MDI_SUCCESS); 39670Sstevel@tonic-gate } 39680Sstevel@tonic-gate 39690Sstevel@tonic-gate 39700Sstevel@tonic-gate /*ARGSUSED*/ 39710Sstevel@tonic-gate static int 39728082SRamaswamy.Tummala@Sun.COM ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip, 39730Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t arg1, int arg2) 39740Sstevel@tonic-gate { 39750Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 39768082SRamaswamy.Tummala@Sun.COM "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state); 39770Sstevel@tonic-gate return (MDI_SUCCESS); 39780Sstevel@tonic-gate } 39790Sstevel@tonic-gate 39800Sstevel@tonic-gate 39810Sstevel@tonic-gate /*ARGSUSED*/ 39820Sstevel@tonic-gate static int 39830Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg) 39840Sstevel@tonic-gate { 39850Sstevel@tonic-gate return (MDI_SUCCESS); 39860Sstevel@tonic-gate } 39870Sstevel@tonic-gate 39880Sstevel@tonic-gate 39890Sstevel@tonic-gate static int 39900Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg, 39910Sstevel@tonic-gate pm_bus_power_op_t op, void *arg, void *result) 39920Sstevel@tonic-gate { 39930Sstevel@tonic-gate 39940Sstevel@tonic-gate int ret = DDI_SUCCESS; 39950Sstevel@tonic-gate 39960Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op); 39970Sstevel@tonic-gate 39980Sstevel@tonic-gate /* 39990Sstevel@tonic-gate * Generic processing in MPxIO framework 40000Sstevel@tonic-gate */ 40010Sstevel@tonic-gate ret = mdi_bus_power(parent, impl_arg, op, arg, result); 40020Sstevel@tonic-gate 40030Sstevel@tonic-gate switch (ret) { 40040Sstevel@tonic-gate case MDI_SUCCESS: 40050Sstevel@tonic-gate ret = DDI_SUCCESS; 40060Sstevel@tonic-gate break; 40070Sstevel@tonic-gate case MDI_FAILURE: 40080Sstevel@tonic-gate ret = DDI_FAILURE; 40090Sstevel@tonic-gate break; 40100Sstevel@tonic-gate default: 40110Sstevel@tonic-gate break; 40120Sstevel@tonic-gate } 40130Sstevel@tonic-gate 40140Sstevel@tonic-gate return (ret); 40150Sstevel@tonic-gate } 40161093Shiremath 40171093Shiremath 40181093Shiremath /* 40191093Shiremath * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config. 40201093Shiremath * ndi_devi_enter is not held during this call. mdi_vhci_bus_config() 40211093Shiremath * will have called ndi_busop_bus_config(), no need for the caller to call 40221093Shiremath * ndi_busop_bus_config() again. 40231093Shiremath * 40241093Shiremath * If enumerated as a child of HCA device, this could be a case for 40251093Shiremath * Sparc boot or device enumeration from PHCI, driven by MDI. 40261093Shiremath * Hold parent lock (ndi_devi_enter). The caller will have to call 40271093Shiremath * ndi_busop_bus_config() if this function returns SUCCESS. 40281093Shiremath * 40291093Shiremath * if the device name contains ":port", then it is the Sparc boot case. 40301093Shiremath * Handle this as before. 40311093Shiremath * 40321093Shiremath * If the device name does *not* contain the ":port", then : 40331093Shiremath * 1. ibdm to probe IOC 40341093Shiremath * 2. Create a pathinfo only if the IOC is reachable from the parent dip. 40351093Shiremath */ 403612163SRamaswamy.Tummala@Sun.COM int 40371093Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag, 40381093Shiremath ddi_bus_config_op_t op, void *devname, dev_info_t **child, 40391093Shiremath int *need_bus_config) 40401093Shiremath { 40411093Shiremath int ret = DDI_FAILURE, circ; 40421093Shiremath dev_info_t *pdip = *pdipp; 40431093Shiremath ib_guid_t iou_guid, ioc_guid; 40441093Shiremath char *ioc_guid_str; 40451093Shiremath 40461093Shiremath 40471093Shiremath *need_bus_config = 1; 40481093Shiremath 40491093Shiremath if (pdip == ibnex.ibnex_dip) { 40501093Shiremath if (ibnex_devname_to_node_n_ioc_guids( 40511093Shiremath (char *)devname, &iou_guid, &ioc_guid, 40521093Shiremath &ioc_guid_str) != IBNEX_SUCCESS) { 40531093Shiremath return (ret); 40541093Shiremath } 40551093Shiremath ret = mdi_vhci_bus_config(pdip, flag, op, devname, child, 40561093Shiremath ioc_guid_str); 40571093Shiremath kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1); 40581093Shiremath if (ret == MDI_SUCCESS) 40591093Shiremath *need_bus_config = 0; 40601093Shiremath } else { 40612155Scth mdi_devi_enter(pdip, &circ); 40621093Shiremath if (strstr((char *)devname, ":port=") != NULL) { 40631093Shiremath ret = ibnex_config_root_iocnode(pdip, devname); 40641093Shiremath ASSERT(ibnex.ibnex_dip == NULL); 40651093Shiremath *pdipp = ibnex.ibnex_dip; 40661093Shiremath } else { 40671093Shiremath ret = ibnex_config_ioc_node(devname, pdip); 40681093Shiremath } 40692155Scth mdi_devi_exit(pdip, circ); 40701093Shiremath } 40711093Shiremath return (ret); 40721093Shiremath } 40731093Shiremath 40741093Shiremath static int 40751093Shiremath ibnex_is_merge_node(dev_info_t *child) 40761093Shiremath { 40771093Shiremath char *node; 40781093Shiremath int ret = IBNEX_INVALID_NODE; 40791093Shiremath 40801093Shiremath if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 40811093Shiremath DDI_PROP_DONTPASS, "ib-node-type", &node) != 40821093Shiremath DDI_PROP_SUCCESS) { 40831093Shiremath return (IBNEX_FAILURE); 40841093Shiremath } 40851093Shiremath 40861093Shiremath if (node != NULL && *node != 0) { 40871093Shiremath if (strcmp(node, "merge") == 0) 40881093Shiremath ret = IBNEX_SUCCESS; 40891093Shiremath else { 40901093Shiremath IBTF_DPRINTF_L4("ibnex", 40911093Shiremath "\tis_merge_node: ib-node-type = %s", node); 40921093Shiremath } 40931093Shiremath } 40941093Shiremath 40951093Shiremath ddi_prop_free(node); 40961093Shiremath return (ret); 40971093Shiremath } 40981093Shiremath 40991093Shiremath /* 41001093Shiremath * Checks if the dn_head for the driver has already 41011093Shiremath * initialized by the prom tree. 41021093Shiremath */ 41032402Spramodbg void 41041093Shiremath ibnex_hw_in_dev_tree(char *driver_name) 41051093Shiremath { 41061093Shiremath major_t major; 41071093Shiremath 41082402Spramodbg IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name); 41092402Spramodbg 41101093Shiremath if (devnamesp == NULL) 41112402Spramodbg return; 41121093Shiremath 41131093Shiremath major = ddi_name_to_major(driver_name); 41141093Shiremath if (major == -1) 41152402Spramodbg return; 41162402Spramodbg 41172402Spramodbg if (devnamesp[major].dn_head != (dev_info_t *)NULL) 41182402Spramodbg ibnex_hw_status = IBNEX_HW_IN_DEVTREE; 41191093Shiremath } 41208082SRamaswamy.Tummala@Sun.COM 41218082SRamaswamy.Tummala@Sun.COM int 41228082SRamaswamy.Tummala@Sun.COM ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info) 41238082SRamaswamy.Tummala@Sun.COM { 41248082SRamaswamy.Tummala@Sun.COM ibdm_hca_list_t *hca_list; 41258082SRamaswamy.Tummala@Sun.COM dev_info_t *hca_dip; 41268082SRamaswamy.Tummala@Sun.COM int rc = IBNEX_FAILURE; 41278082SRamaswamy.Tummala@Sun.COM 41288082SRamaswamy.Tummala@Sun.COM ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 41298082SRamaswamy.Tummala@Sun.COM /* 41308082SRamaswamy.Tummala@Sun.COM * We return failure even if we fail for all HCAs 41318082SRamaswamy.Tummala@Sun.COM */ 41328082SRamaswamy.Tummala@Sun.COM for (hca_list = ioc_info->ioc_hca_list; hca_list; 41338082SRamaswamy.Tummala@Sun.COM hca_list = hca_list->hl_next) { 41348082SRamaswamy.Tummala@Sun.COM hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 41358082SRamaswamy.Tummala@Sun.COM if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) == 41368082SRamaswamy.Tummala@Sun.COM IBNEX_SUCCESS) 41378082SRamaswamy.Tummala@Sun.COM rc = IBNEX_SUCCESS; 41388082SRamaswamy.Tummala@Sun.COM } 41398082SRamaswamy.Tummala@Sun.COM return (rc); 41408082SRamaswamy.Tummala@Sun.COM } 41418082SRamaswamy.Tummala@Sun.COM 41428082SRamaswamy.Tummala@Sun.COM static int 41438082SRamaswamy.Tummala@Sun.COM ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip, 41448082SRamaswamy.Tummala@Sun.COM int pdip_reachable_checked) 41458082SRamaswamy.Tummala@Sun.COM { 41468082SRamaswamy.Tummala@Sun.COM ibnex_node_data_t *node_data; 41478082SRamaswamy.Tummala@Sun.COM int create_pdip = 0; 41488082SRamaswamy.Tummala@Sun.COM int rc = IBNEX_SUCCESS; 41498082SRamaswamy.Tummala@Sun.COM 41508082SRamaswamy.Tummala@Sun.COM 41518082SRamaswamy.Tummala@Sun.COM ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 41528082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 41538082SRamaswamy.Tummala@Sun.COM "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip, 41548082SRamaswamy.Tummala@Sun.COM pdip_reachable_checked); 41558082SRamaswamy.Tummala@Sun.COM 41568082SRamaswamy.Tummala@Sun.COM if (pdip_reachable_checked == 0) { 41578082SRamaswamy.Tummala@Sun.COM if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) { 41588082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 41598082SRamaswamy.Tummala@Sun.COM "/tioc_config_from_pdip: ioc %p not reachable" 41608082SRamaswamy.Tummala@Sun.COM "from %p", ioc_info, pdip); 41618082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 41628082SRamaswamy.Tummala@Sun.COM } 41638082SRamaswamy.Tummala@Sun.COM } 41648082SRamaswamy.Tummala@Sun.COM 41658082SRamaswamy.Tummala@Sun.COM node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 41668082SRamaswamy.Tummala@Sun.COM (void *)ioc_info, 0, 0); 41678082SRamaswamy.Tummala@Sun.COM 41688082SRamaswamy.Tummala@Sun.COM if (node_data && node_data->node_ap_state == 41698082SRamaswamy.Tummala@Sun.COM IBNEX_NODE_AP_UNCONFIGURED) { 41708082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 41718082SRamaswamy.Tummala@Sun.COM "\tioc_config_from_pdip: Unconfigured node"); 41728082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 41738082SRamaswamy.Tummala@Sun.COM } 41748082SRamaswamy.Tummala@Sun.COM 41758082SRamaswamy.Tummala@Sun.COM 41768082SRamaswamy.Tummala@Sun.COM if (node_data == NULL) { 41778082SRamaswamy.Tummala@Sun.COM ibnex_ioc_node_t *ioc; 41788082SRamaswamy.Tummala@Sun.COM 41798082SRamaswamy.Tummala@Sun.COM create_pdip = 1; 41808082SRamaswamy.Tummala@Sun.COM 41818082SRamaswamy.Tummala@Sun.COM node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE, 41828082SRamaswamy.Tummala@Sun.COM ioc_info, 0, 0); 41838082SRamaswamy.Tummala@Sun.COM ASSERT(node_data); 41848082SRamaswamy.Tummala@Sun.COM ioc = &node_data->node_data.ioc_node; 41858082SRamaswamy.Tummala@Sun.COM (void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN, 41868082SRamaswamy.Tummala@Sun.COM "%llX", 41878082SRamaswamy.Tummala@Sun.COM (longlong_t)ioc_info->ioc_profile.ioc_guid); 41888082SRamaswamy.Tummala@Sun.COM (void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN, 41898082SRamaswamy.Tummala@Sun.COM "%llX,%llX", 41908082SRamaswamy.Tummala@Sun.COM (longlong_t)ioc_info->ioc_profile.ioc_guid, 41918082SRamaswamy.Tummala@Sun.COM (longlong_t)ioc_info->ioc_iou_guid); 41928082SRamaswamy.Tummala@Sun.COM } else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) { 41938082SRamaswamy.Tummala@Sun.COM create_pdip = 1; 41948082SRamaswamy.Tummala@Sun.COM } 41958082SRamaswamy.Tummala@Sun.COM 41968082SRamaswamy.Tummala@Sun.COM if (create_pdip) { 41978082SRamaswamy.Tummala@Sun.COM rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip); 41988082SRamaswamy.Tummala@Sun.COM } 41998082SRamaswamy.Tummala@Sun.COM 42008082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x", 42018082SRamaswamy.Tummala@Sun.COM rc); 42028082SRamaswamy.Tummala@Sun.COM return (rc); 42038082SRamaswamy.Tummala@Sun.COM } 42048082SRamaswamy.Tummala@Sun.COM 42058082SRamaswamy.Tummala@Sun.COM /* 42068082SRamaswamy.Tummala@Sun.COM * This function checks if a pathinfo has already been created 42078082SRamaswamy.Tummala@Sun.COM * for the HCA parent. The function returns SUCCESS if a pathinfo 42088082SRamaswamy.Tummala@Sun.COM * has already been created, FAILURE if not. 42098082SRamaswamy.Tummala@Sun.COM */ 42108082SRamaswamy.Tummala@Sun.COM static int 42118082SRamaswamy.Tummala@Sun.COM ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent) 42128082SRamaswamy.Tummala@Sun.COM { 42138082SRamaswamy.Tummala@Sun.COM int rc; 42148082SRamaswamy.Tummala@Sun.COM ibnex_ioc_node_t *ioc; 42158082SRamaswamy.Tummala@Sun.COM 42168082SRamaswamy.Tummala@Sun.COM ioc = &node_data->node_data.ioc_node; 42178082SRamaswamy.Tummala@Sun.COM if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str, 42188082SRamaswamy.Tummala@Sun.COM (char *)ioc->ioc_phci_guid) != NULL) 42198082SRamaswamy.Tummala@Sun.COM rc = IBNEX_SUCCESS; 42208082SRamaswamy.Tummala@Sun.COM else 42218082SRamaswamy.Tummala@Sun.COM rc = IBNEX_FAILURE; 42228082SRamaswamy.Tummala@Sun.COM 42238082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, " 42248082SRamaswamy.Tummala@Sun.COM "phci_guid %s, parent %p, rc %x", 42258082SRamaswamy.Tummala@Sun.COM ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc); 42268082SRamaswamy.Tummala@Sun.COM return (rc); 42278082SRamaswamy.Tummala@Sun.COM } 42288082SRamaswamy.Tummala@Sun.COM 42298082SRamaswamy.Tummala@Sun.COM static int 42308082SRamaswamy.Tummala@Sun.COM ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 42318082SRamaswamy.Tummala@Sun.COM { 42328082SRamaswamy.Tummala@Sun.COM ibdm_hca_list_t *hca_list; 42338082SRamaswamy.Tummala@Sun.COM dev_info_t *hca_dip; 42348082SRamaswamy.Tummala@Sun.COM 42358082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)", 42368082SRamaswamy.Tummala@Sun.COM ioc_info, pdip); 42378082SRamaswamy.Tummala@Sun.COM for (hca_list = ioc_info->ioc_hca_list; hca_list; 42388082SRamaswamy.Tummala@Sun.COM hca_list = hca_list->hl_next) { 42398082SRamaswamy.Tummala@Sun.COM hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 42408082SRamaswamy.Tummala@Sun.COM if (hca_dip == pdip) { 42418082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", 42428082SRamaswamy.Tummala@Sun.COM "\tioc_pi_reachable FAILURE"); 42438082SRamaswamy.Tummala@Sun.COM return (IBNEX_SUCCESS); 42448082SRamaswamy.Tummala@Sun.COM } 42458082SRamaswamy.Tummala@Sun.COM } 42468082SRamaswamy.Tummala@Sun.COM 42478082SRamaswamy.Tummala@Sun.COM IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE"); 42488082SRamaswamy.Tummala@Sun.COM return (IBNEX_FAILURE); 42498082SRamaswamy.Tummala@Sun.COM } 4250