17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 505fa0d51Spramodbg * Common Development and Distribution License (the "License"). 605fa0d51Spramodbg * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2251f34d4bSRajkumar Sivaprakasam * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * The InfiniBand Nexus driver (IB nexus) is a bus nexus driver for IB bus. 287c478bd9Sstevel@tonic-gate * It supports Port nodes, Virtual Physical Point of Attachment nodes (VPPA) 297c478bd9Sstevel@tonic-gate * for HCAs registered with IBTL and IOC nodes for all the IOCs present in 307c478bd9Sstevel@tonic-gate * the IB fabric (that are accessible to the host). It also supports Pseudo 317c478bd9Sstevel@tonic-gate * device children to be enumerated using their .conf file(s). All Port nodes 327c478bd9Sstevel@tonic-gate * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo 337c478bd9Sstevel@tonic-gate * device nodes are children of the IB nexus driver. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * IB nexus driver provides bus nexus entry points to all the HCA drivers. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * IB nexus driver registers with InfiniBand Device Manager (IBDM) to get 387c478bd9Sstevel@tonic-gate * information about all the HCA ports and I/O Controllers (IOCs) connected 397c478bd9Sstevel@tonic-gate * to the IB fabric. Based on that information, IB nexus will create all the 407c478bd9Sstevel@tonic-gate * device tree nodes. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <sys/conf.h> 447c478bd9Sstevel@tonic-gate #include <sys/stat.h> 457c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 467c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 477c478bd9Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 487c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h> 497c478bd9Sstevel@tonic-gate #include <sys/sunpm.h> 507c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h> 517c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h> 527c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h> 537c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h> 547c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h> 557c478bd9Sstevel@tonic-gate #include <sys/file.h> 567c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 57*dcf1eb70SSudhakar Dindukurti #include <sys/fs/dv_node.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* Function prototypes */ 607c478bd9Sstevel@tonic-gate static int ibnex_attach(dev_info_t *, ddi_attach_cmd_t); 617c478bd9Sstevel@tonic-gate static int ibnex_getinfo(dev_info_t *, ddi_info_cmd_t, 627c478bd9Sstevel@tonic-gate void *, void **); 637c478bd9Sstevel@tonic-gate static int ibnex_detach(dev_info_t *, ddi_detach_cmd_t); 647c478bd9Sstevel@tonic-gate static int ibnex_busctl(dev_info_t *, 657c478bd9Sstevel@tonic-gate dev_info_t *, ddi_ctl_enum_t, void *, void *); 667c478bd9Sstevel@tonic-gate static int ibnex_map_fault(dev_info_t *, 677c478bd9Sstevel@tonic-gate dev_info_t *, struct hat *, struct seg *, 687c478bd9Sstevel@tonic-gate caddr_t, struct devpage *, pfn_t, uint_t, uint_t); 697c478bd9Sstevel@tonic-gate static int ibnex_init_child(dev_info_t *); 707c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_comm_svc_init(char *, ibnex_node_type_t); 717c478bd9Sstevel@tonic-gate static void ibnex_comm_svc_fini(); 727c478bd9Sstevel@tonic-gate dev_info_t *ibnex_commsvc_initnode(dev_info_t *, 737c478bd9Sstevel@tonic-gate ibdm_port_attr_t *, int, int, ib_pkey_t, int *, 747c478bd9Sstevel@tonic-gate int); 757c478bd9Sstevel@tonic-gate static void ibnex_delete_port_node_data(ibnex_node_data_t *); 767c478bd9Sstevel@tonic-gate int ibnex_get_dip_from_guid(ib_guid_t, int, 777c478bd9Sstevel@tonic-gate ib_pkey_t, dev_info_t **); 787c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t, 797c478bd9Sstevel@tonic-gate void *, int, ib_pkey_t); 807c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *, 817c478bd9Sstevel@tonic-gate int, ib_pkey_t); 827c478bd9Sstevel@tonic-gate static int ibnex_create_port_node_prop(ibdm_port_attr_t *, 837c478bd9Sstevel@tonic-gate dev_info_t *, char *, ib_pkey_t); 847c478bd9Sstevel@tonic-gate void ibnex_dm_callback(void *, ibdm_events_t); 857c478bd9Sstevel@tonic-gate static int ibnex_create_port_compatible_prop(dev_info_t *, 867c478bd9Sstevel@tonic-gate char *, ibdm_port_attr_t *); 877c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_srv_props( 887c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 897c478bd9Sstevel@tonic-gate static int ibnex_get_eventcookie(dev_info_t *, 907c478bd9Sstevel@tonic-gate dev_info_t *, char *, ddi_eventcookie_t *); 917c478bd9Sstevel@tonic-gate static int ibnex_add_eventcall(dev_info_t *, dev_info_t *, 927c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void (*)(dev_info_t *, 937c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *, void *), 947c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id); 957c478bd9Sstevel@tonic-gate static int ibnex_remove_eventcall(dev_info_t *, 967c478bd9Sstevel@tonic-gate ddi_callback_id_t); 977c478bd9Sstevel@tonic-gate static int ibnex_post_event(dev_info_t *, dev_info_t *, 987c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *); 997c478bd9Sstevel@tonic-gate static int ibnex_bus_config(dev_info_t *, uint_t, 1007c478bd9Sstevel@tonic-gate ddi_bus_config_op_t, void *, dev_info_t **); 1017c478bd9Sstevel@tonic-gate static int ibnex_bus_unconfig(dev_info_t *, 1027c478bd9Sstevel@tonic-gate uint_t, ddi_bus_config_op_t, void *); 1037c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_port_node(dev_info_t *, char *); 1047c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_obp_args(dev_info_t *, char *); 1057c478bd9Sstevel@tonic-gate static int ibnex_get_pkey_commsvc_index_portnum( 1067c478bd9Sstevel@tonic-gate char *, int *, ib_pkey_t *, uint8_t *); 1077c478bd9Sstevel@tonic-gate static void ibnex_config_all_children(dev_info_t *); 1087c478bd9Sstevel@tonic-gate static int ibnex_devname_to_portnum(char *, uint8_t *); 1097c478bd9Sstevel@tonic-gate static void ibnex_create_vppa_nodes( 1107c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1117c478bd9Sstevel@tonic-gate static void ibnex_create_port_nodes( 1127c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1137c478bd9Sstevel@tonic-gate static void ibnex_create_hcasvc_nodes( 1147c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1157c478bd9Sstevel@tonic-gate static int ibnex_config_root_iocnode(dev_info_t *, char *); 1167c478bd9Sstevel@tonic-gate static int ibnex_devname2port(char *, int *); 1179d3d2ed0Shiremath static int ibnex_config_ioc_node(char *, dev_info_t *); 1187c478bd9Sstevel@tonic-gate static int ibnex_devname_to_node_n_ioc_guids( 1199d3d2ed0Shiremath char *, ib_guid_t *, ib_guid_t *, char **); 1207c478bd9Sstevel@tonic-gate static void ibnex_ioc_node_cleanup(); 1217c478bd9Sstevel@tonic-gate static void ibnex_delete_ioc_node_data(ibnex_node_data_t *); 12200a3eaf3SRamaswamy Tummala int ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *); 12300a3eaf3SRamaswamy Tummala static int ibnex_ioc_initnode_pdip(ibnex_node_data_t *, 12400a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *, dev_info_t *); 1257c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_node_prop( 1267c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *, dev_info_t *); 1277c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_compatible_prop( 1287c478bd9Sstevel@tonic-gate dev_info_t *, ib_dm_ioc_ctrl_profile_t *); 1297c478bd9Sstevel@tonic-gate uint64_t ibnex_str2hex(char *, int, int *); 1307c478bd9Sstevel@tonic-gate static int ibnex_str2int(char *, int, int *); 1317c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_portgid_prop( 1327c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 1337c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int); 1347c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_all(); 1357c478bd9Sstevel@tonic-gate ibt_status_t ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *); 1367c478bd9Sstevel@tonic-gate static int ibnex_prom_devname_to_pkey_n_portnum( 1377c478bd9Sstevel@tonic-gate char *, ib_pkey_t *, uint8_t *); 1387c478bd9Sstevel@tonic-gate void ibnex_pseudo_initnodes(void); 1399d3d2ed0Shiremath static char *ibnex_lookup_named_prop(ddi_prop_t *, char *); 1407c478bd9Sstevel@tonic-gate static void ibnex_pseudo_node_cleanup(void); 1417c478bd9Sstevel@tonic-gate static int ibnex_name_child(dev_info_t *, char *, int); 1427c478bd9Sstevel@tonic-gate static int ibnex_name_pseudo_child(dev_info_t *, char *); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_dev(void *); 1457c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_all(); 1467c478bd9Sstevel@tonic-gate static void ibnex_update_prop(ibnex_node_data_t *, 1477c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *); 1487c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_unique_svcname(char *); 1497c478bd9Sstevel@tonic-gate static void ibnex_handle_reprobe_dev(void *arg); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate extern int ibnex_open(dev_t *, int, int, cred_t *); 1527c478bd9Sstevel@tonic-gate extern int ibnex_close(dev_t, int, int, cred_t *); 1537c478bd9Sstevel@tonic-gate extern int ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1547c478bd9Sstevel@tonic-gate extern int ibnex_offline_childdip(dev_info_t *); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate static int ibnex_ioc_create_pi( 1579d3d2ed0Shiremath ibdm_ioc_info_t *, ibnex_node_data_t *, 15800a3eaf3SRamaswamy Tummala dev_info_t *, int *); 1597c478bd9Sstevel@tonic-gate static int ibnex_bus_power(dev_info_t *, void *, 1607c478bd9Sstevel@tonic-gate pm_bus_power_op_t, void *, void *); 16100a3eaf3SRamaswamy Tummala int ibnex_pseudo_create_all_pi(ibnex_node_data_t *); 16200a3eaf3SRamaswamy Tummala static int ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *, 1639d3d2ed0Shiremath dev_info_t *); 16405fa0d51Spramodbg static int ibnex_pseudo_config_one( 16505fa0d51Spramodbg ibnex_node_data_t *, char *, dev_info_t *); 1669d3d2ed0Shiremath static int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **, 1679d3d2ed0Shiremath char *, char *); 1689d3d2ed0Shiremath static void ibnex_config_pseudo_all(dev_info_t *); 1699d3d2ed0Shiremath static int ibnex_ioc_bus_config_one(dev_info_t **, uint_t, 1709d3d2ed0Shiremath ddi_bus_config_op_t, void *, dev_info_t **, int *); 1719d3d2ed0Shiremath static int ibnex_is_merge_node(dev_info_t *); 172f7209cf2Spramodbg static void ibnex_hw_in_dev_tree(char *); 17300a3eaf3SRamaswamy Tummala static int ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *, 17400a3eaf3SRamaswamy Tummala dev_info_t *, int); 17500a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *); 17600a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_reachable(ibdm_ioc_info_t *, 17700a3eaf3SRamaswamy Tummala dev_info_t *); 1789d3d2ed0Shiremath 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of HCA nexus driver. 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate struct bus_ops ibnex_ci_busops = { 1837c478bd9Sstevel@tonic-gate BUSO_REV, 1847c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 1857c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 1867c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 1877c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 1887c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 1897c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 1907c478bd9Sstevel@tonic-gate NULL, 1917c478bd9Sstevel@tonic-gate NULL, 1927c478bd9Sstevel@tonic-gate NULL, 1937c478bd9Sstevel@tonic-gate NULL, 1947c478bd9Sstevel@tonic-gate NULL, 1957c478bd9Sstevel@tonic-gate NULL, 1967c478bd9Sstevel@tonic-gate NULL, 1977c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 1987c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 1997c478bd9Sstevel@tonic-gate NULL, /* bus_get_eventcookie */ 2007c478bd9Sstevel@tonic-gate NULL, /* bus_add_eventcall */ 2017c478bd9Sstevel@tonic-gate NULL, /* bus_remove_eventcall */ 2027c478bd9Sstevel@tonic-gate NULL, /* bus_post_event */ 2037c478bd9Sstevel@tonic-gate NULL, 2047c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2057c478bd9Sstevel@tonic-gate ibnex_bus_unconfig /* bus unconfig */ 2067c478bd9Sstevel@tonic-gate }; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * Prototype declarations for the VHCI options 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * Functions registered with the mpxio framework 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int); 2157c478bd9Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int); 2167c478bd9Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *, 2177c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int); 2187c478bd9Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = { 2227c478bd9Sstevel@tonic-gate MDI_VHCI_OPS_REV, 2237c478bd9Sstevel@tonic-gate ib_vhci_pi_init, 2247c478bd9Sstevel@tonic-gate ib_vhci_pi_uninit, 2257c478bd9Sstevel@tonic-gate ib_vhci_pi_state_change, 2267c478bd9Sstevel@tonic-gate ib_vhci_failover 2277c478bd9Sstevel@tonic-gate }; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of IB nexus driver. 2327c478bd9Sstevel@tonic-gate * IB nexus drivers does not support any DMA operations for its children 2337c478bd9Sstevel@tonic-gate * as there is no such concept in Infiniband. All the memory operations 2347c478bd9Sstevel@tonic-gate * and DMA operations required by the child drivers can be performed using 2357c478bd9Sstevel@tonic-gate * the IBTF API. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = { 2387c478bd9Sstevel@tonic-gate BUSO_REV, 2397c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 2407c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 2417c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 2427c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 2437c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 2447c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 2457c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl, 2467c478bd9Sstevel@tonic-gate NULL, 2477c478bd9Sstevel@tonic-gate NULL, 2487c478bd9Sstevel@tonic-gate NULL, 2497c478bd9Sstevel@tonic-gate NULL, 2507c478bd9Sstevel@tonic-gate NULL, 2517c478bd9Sstevel@tonic-gate NULL, 2527c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 2537c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 2547c478bd9Sstevel@tonic-gate ibnex_get_eventcookie, /* bus_get_eventcookie */ 2557c478bd9Sstevel@tonic-gate ibnex_add_eventcall, /* bus_add_eventcall */ 2567c478bd9Sstevel@tonic-gate ibnex_remove_eventcall, /* bus_remove_eventcall */ 2577c478bd9Sstevel@tonic-gate ibnex_post_event, /* bus_post_event */ 2587c478bd9Sstevel@tonic-gate NULL, 2597c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2607c478bd9Sstevel@tonic-gate ibnex_bus_unconfig, /* bus unconfig */ 2617c478bd9Sstevel@tonic-gate NULL, /* bus fm init */ 2627c478bd9Sstevel@tonic-gate NULL, /* bus fm fini */ 2637c478bd9Sstevel@tonic-gate NULL, /* bus fm access enter */ 2647c478bd9Sstevel@tonic-gate NULL, /* bus fm access exit */ 2657c478bd9Sstevel@tonic-gate ibnex_bus_power /* bus power */ 2667c478bd9Sstevel@tonic-gate }; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* ibnex cb_ops */ 2697c478bd9Sstevel@tonic-gate static struct cb_ops ibnex_cbops = { 2707c478bd9Sstevel@tonic-gate ibnex_open, /* open */ 2717c478bd9Sstevel@tonic-gate ibnex_close, /* close */ 2727c478bd9Sstevel@tonic-gate nodev, /* strategy */ 2737c478bd9Sstevel@tonic-gate nodev, /* print */ 2747c478bd9Sstevel@tonic-gate nodev, /* dump */ 2757c478bd9Sstevel@tonic-gate nodev, /* read */ 2767c478bd9Sstevel@tonic-gate nodev, /* write */ 2777c478bd9Sstevel@tonic-gate ibnex_ioctl, /* ioctl */ 2787c478bd9Sstevel@tonic-gate nodev, /* devmap */ 2797c478bd9Sstevel@tonic-gate nodev, /* mmap */ 2807c478bd9Sstevel@tonic-gate nodev, /* segmap */ 2817c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 2827c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 2837c478bd9Sstevel@tonic-gate NULL, /* stream */ 2847c478bd9Sstevel@tonic-gate D_MP, /* cb_flag */ 2857c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 2867c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 2877c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 2887c478bd9Sstevel@tonic-gate }; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* 2917c478bd9Sstevel@tonic-gate * Device options 2927c478bd9Sstevel@tonic-gate * Note: ddi_no_info needs to change during devfs time frame. The drivers 2937c478bd9Sstevel@tonic-gate * with 1 to 1 mapping between minor node and instance should use 2947c478bd9Sstevel@tonic-gate * ddi_1to1_info. (See bug id 4424752) 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate static struct dev_ops ibnex_ops = { 2977c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 2987c478bd9Sstevel@tonic-gate 0, /* refcnt */ 2997c478bd9Sstevel@tonic-gate ibnex_getinfo, /* info */ 3007c478bd9Sstevel@tonic-gate nulldev, /* identify */ 3017c478bd9Sstevel@tonic-gate nulldev, /* probe */ 3027c478bd9Sstevel@tonic-gate ibnex_attach, /* attach */ 3037c478bd9Sstevel@tonic-gate ibnex_detach, /* detach */ 3047c478bd9Sstevel@tonic-gate nodev, /* reset */ 3057c478bd9Sstevel@tonic-gate &ibnex_cbops, /* driver ops - devctl interfaces */ 3067c478bd9Sstevel@tonic-gate &ibnex_bus_ops, /* bus operations */ 30719397407SSherry Moore nulldev, /* power */ 30819397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 3097c478bd9Sstevel@tonic-gate }; 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* Module linkage information for the kernel. */ 3127c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3137c478bd9Sstevel@tonic-gate &mod_driverops, /* Driver module */ 31419397407SSherry Moore "IB nexus", /* Driver name and version */ 3157c478bd9Sstevel@tonic-gate &ibnex_ops, /* driver ops */ 3167c478bd9Sstevel@tonic-gate }; 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3197c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 3207c478bd9Sstevel@tonic-gate }; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* 3237c478bd9Sstevel@tonic-gate * Global per-instance IB Nexus data. 3247c478bd9Sstevel@tonic-gate * There is only one instance of IB Nexus supported. 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate ibnex_t ibnex; 3277c478bd9Sstevel@tonic-gate #ifdef __lock_lint 3287c478bd9Sstevel@tonic-gate extern ibdm_t ibdm; 3297c478bd9Sstevel@tonic-gate #endif 3307c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s)) 3317c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs 3327c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs 3337c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs 33400a3eaf3SRamaswamy Tummala ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list)) 3357c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s)) 3367c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex)) 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* The port settling time in seconds */ 33900a3eaf3SRamaswamy Tummala int ibnex_port_settling_time = 30; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */ 3427c478bd9Sstevel@tonic-gate static struct ibnex_property { 3437c478bd9Sstevel@tonic-gate char *name; 3447c478bd9Sstevel@tonic-gate ibnex_node_type_t type; 3457c478bd9Sstevel@tonic-gate } ibnex_properties[] = { 3467c478bd9Sstevel@tonic-gate { "port-svc-list", IBNEX_PORT_COMMSVC_NODE}, 3477c478bd9Sstevel@tonic-gate { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE}, 3487c478bd9Sstevel@tonic-gate { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE} 3497c478bd9Sstevel@tonic-gate }; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \ 3527c478bd9Sstevel@tonic-gate (sizeof (struct ibnex_property)) 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate /* 3557c478bd9Sstevel@tonic-gate * Event Definition 3567c478bd9Sstevel@tonic-gate * Single event, event name defined in ibti_common.h. 3577c478bd9Sstevel@tonic-gate * Event posted to specific child handler. Event posted 3587c478bd9Sstevel@tonic-gate * at kernel priority. 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = { 3617c478bd9Sstevel@tonic-gate {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL, 3627c478bd9Sstevel@tonic-gate NDI_EVENT_POST_TO_TGT} 3637c478bd9Sstevel@tonic-gate }; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate #define IB_N_NDI_EVENTS \ 3667c478bd9Sstevel@tonic-gate (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t)) 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = { 3697c478bd9Sstevel@tonic-gate NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs}; 3709d3d2ed0Shiremath static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* 3747c478bd9Sstevel@tonic-gate * _init 3757c478bd9Sstevel@tonic-gate * Loadable module init, called before any other module. 3767c478bd9Sstevel@tonic-gate */ 3777c478bd9Sstevel@tonic-gate int 3787c478bd9Sstevel@tonic-gate _init(void) 3797c478bd9Sstevel@tonic-gate { 3807c478bd9Sstevel@tonic-gate int error; 381f7209cf2Spramodbg char **hca_driver_list; 382f7209cf2Spramodbg int i, ndrivers; 3837c478bd9Sstevel@tonic-gate 3849d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) { 385f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE; 386f7209cf2Spramodbg hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers); 387f7209cf2Spramodbg for (i = 0; i < ndrivers; i++) { 388f7209cf2Spramodbg ibnex_hw_in_dev_tree(hca_driver_list[i]); 389f7209cf2Spramodbg if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE) 390f7209cf2Spramodbg break; 391f7209cf2Spramodbg } 392f7209cf2Spramodbg mdi_free_phci_driver_list(hca_driver_list, ndrivers); 3939d3d2ed0Shiremath } 3949d3d2ed0Shiremath 3959d3d2ed0Shiremath /* 3969d3d2ed0Shiremath * IB Nexus _init can be called while force attaching 3979d3d2ed0Shiremath * IB Nexus driver or when a HCA is hotplugged. 3989d3d2ed0Shiremath * 3999d3d2ed0Shiremath * If IB HW is not in device tree or if no HCA driver 4009d3d2ed0Shiremath * has been attached, fail IB Nexus _init(). 4019d3d2ed0Shiremath */ 4029d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE && 4039d3d2ed0Shiremath ibt_hw_is_present() == 0) { 4049d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW"); 4059d3d2ed0Shiremath return (DDI_FAILURE); 4069d3d2ed0Shiremath } 4079d3d2ed0Shiremath 4087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_init"); 4097c478bd9Sstevel@tonic-gate mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL); 4107c478bd9Sstevel@tonic-gate cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL); 41151f34d4bSRajkumar Sivaprakasam cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL); 4127c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 4137c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed"); 4147c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4157c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 41651f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv); 4177c478bd9Sstevel@tonic-gate } else { 4187c478bd9Sstevel@tonic-gate ibdm_ibnex_register_callback(ibnex_dm_callback); 4197c478bd9Sstevel@tonic-gate ibtl_ibnex_register_callback(ibnex_ibtl_callback); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate return (error); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate * _fini 4277c478bd9Sstevel@tonic-gate * Prepares a module for unloading. 4287c478bd9Sstevel@tonic-gate */ 4297c478bd9Sstevel@tonic-gate int 4307c478bd9Sstevel@tonic-gate _fini(void) 4317c478bd9Sstevel@tonic-gate { 4327c478bd9Sstevel@tonic-gate int error; 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_fini"); 4357c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) { 4367c478bd9Sstevel@tonic-gate return (error); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate ibdm_ibnex_unregister_callback(); 4397c478bd9Sstevel@tonic-gate ibtl_ibnex_unregister_callback(); 4407c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4417c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 44251f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv); 4437c478bd9Sstevel@tonic-gate return (0); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate /* 4487c478bd9Sstevel@tonic-gate * _info 4497c478bd9Sstevel@tonic-gate * Returns information about loadable module. 4507c478bd9Sstevel@tonic-gate */ 4517c478bd9Sstevel@tonic-gate int 4527c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4537c478bd9Sstevel@tonic-gate { 4547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_info"); 4557c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* 4607c478bd9Sstevel@tonic-gate * ibnex_attach 4617c478bd9Sstevel@tonic-gate * Configure and attach an instance of the IB Nexus driver 4627c478bd9Sstevel@tonic-gate * Only one instance of IB Nexus is supported 4637c478bd9Sstevel@tonic-gate * Create a minor node for cfgadm purpose 4647c478bd9Sstevel@tonic-gate * Initialize communication services 4657c478bd9Sstevel@tonic-gate * Register callback with IBDM 4667c478bd9Sstevel@tonic-gate * Register callback with IBTL 4677c478bd9Sstevel@tonic-gate */ 4687c478bd9Sstevel@tonic-gate static int 4697c478bd9Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 4707c478bd9Sstevel@tonic-gate { 4717c478bd9Sstevel@tonic-gate int i; 4727c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd); 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate switch (cmd) { 4777c478bd9Sstevel@tonic-gate case DDI_ATTACH: 4787c478bd9Sstevel@tonic-gate break; 4797c478bd9Sstevel@tonic-gate case DDI_RESUME: 4807c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME"); 4817c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4827c478bd9Sstevel@tonic-gate default: 4837c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* Fail attach for more than one instance */ 4877c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 4887c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) { 4897c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4907c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4917c478bd9Sstevel@tonic-gate } 4927c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* Register with MPxIO framework */ 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0) 4977c478bd9Sstevel@tonic-gate != MDI_SUCCESS) { 4987c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 4997c478bd9Sstevel@tonic-gate "\tattach: mdi_vhci_register() failed"); 5007c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* 5057c478bd9Sstevel@tonic-gate * Create the "fabric" devctl minor-node for IB DR support. 5067c478bd9Sstevel@tonic-gate * The minor number for the "devctl" node is in the same format 5077c478bd9Sstevel@tonic-gate * as the AP minor nodes. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance, 5107c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 5117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5127c478bd9Sstevel@tonic-gate "\tattach: failed to create fabric minornode"); 5137c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5147c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 517d1a5c838SRamaswamy Tummala /* 518d1a5c838SRamaswamy Tummala * Create "devctl" minor node for general ioctl interface to the 519d1a5c838SRamaswamy Tummala * ib nexus. 520d1a5c838SRamaswamy Tummala */ 521d1a5c838SRamaswamy Tummala if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance, 522d1a5c838SRamaswamy Tummala DDI_NT_IB_NEXUS, 0) != DDI_SUCCESS) { 523d1a5c838SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 524d1a5c838SRamaswamy Tummala "\tattach: failed to create devctl minornode"); 525d1a5c838SRamaswamy Tummala (void) ddi_remove_minor_node(dip, NULL); 526d1a5c838SRamaswamy Tummala (void) mdi_vhci_unregister(dip, 0); 527d1a5c838SRamaswamy Tummala return (DDI_FAILURE); 528d1a5c838SRamaswamy Tummala } 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate /* 5317c478bd9Sstevel@tonic-gate * Set pm-want-child-notification property for 5327c478bd9Sstevel@tonic-gate * power management of the phci and client 5337c478bd9Sstevel@tonic-gate */ 5347c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 5357c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 5367c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5377c478bd9Sstevel@tonic-gate "_attach: create pm-want-child-notification failed"); 5387c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5397c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5407c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 5447c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = dip; 5457c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate /* 5487c478bd9Sstevel@tonic-gate * Event Handling: Definition and Binding. 5497c478bd9Sstevel@tonic-gate */ 5507c478bd9Sstevel@tonic-gate if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl, 5517c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5527c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5547c478bd9Sstevel@tonic-gate "_attach: ndi_event_alloc_hdl failed"); 5557c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5567c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events, 5597c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5607c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5617c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl); 5627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5637c478bd9Sstevel@tonic-gate "_attach: ndi_event_bind_set failed"); 5647c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5657c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate for (i = 0; i < N_IBNEX_PROPS; i++) { 5697c478bd9Sstevel@tonic-gate if (ibnex_comm_svc_init(ibnex_properties[i].name, 5707c478bd9Sstevel@tonic-gate ibnex_properties[i].type) != IBNEX_SUCCESS) { 5717c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 5727c478bd9Sstevel@tonic-gate (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl, 5737c478bd9Sstevel@tonic-gate &ib_ndi_events, NDI_SLEEP); 5747c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5757c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl( 5767c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl); 5777c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 5787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init" 5797c478bd9Sstevel@tonic-gate " failed %s", ibnex_properties[i].name); 5807c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5817c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * before anything else comes up: 5877c478bd9Sstevel@tonic-gate * Initialize the internal list of pseudo device nodes by 5887c478bd9Sstevel@tonic-gate * getting all pseudo children of "ib" and processing them. 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate /* 5977c478bd9Sstevel@tonic-gate * ibnex_getinfo() 5987c478bd9Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 5997c478bd9Sstevel@tonic-gate * instance number. 6007c478bd9Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 6017c478bd9Sstevel@tonic-gate */ 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6047c478bd9Sstevel@tonic-gate static int 6057c478bd9Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 6067c478bd9Sstevel@tonic-gate { 6077c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin"); 6107c478bd9Sstevel@tonic-gate switch (cmd) { 6117c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 6127c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) 6137c478bd9Sstevel@tonic-gate *result = ibnex.ibnex_dip; 6147c478bd9Sstevel@tonic-gate else { 6157c478bd9Sstevel@tonic-gate *result = NULL; 6167c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate break; 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 6217c478bd9Sstevel@tonic-gate *result = 0; 6227c478bd9Sstevel@tonic-gate break; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate default: 6257c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate return (ret); 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate /* 6327c478bd9Sstevel@tonic-gate * ibnex_detach 6337c478bd9Sstevel@tonic-gate * Unregister callback with the IBDM 6347c478bd9Sstevel@tonic-gate * Unregister callback with the IBTL 6357c478bd9Sstevel@tonic-gate * Uninitialize the communication entries 6367c478bd9Sstevel@tonic-gate * Remove all the minor nodes created by this instance 6377c478bd9Sstevel@tonic-gate */ 6387c478bd9Sstevel@tonic-gate static int 6397c478bd9Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 6407c478bd9Sstevel@tonic-gate { 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd); 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate switch (cmd) { 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate case DDI_DETACH: 6477c478bd9Sstevel@tonic-gate break; 6487c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 6497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend"); 6507c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6517c478bd9Sstevel@tonic-gate default: 6527c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 6567c478bd9Sstevel@tonic-gate if (ibt_hw_is_present()) { 6577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6587c478bd9Sstevel@tonic-gate "\tdetach: IB HW is present "); 6597c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6607c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) { 6637c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6647c478bd9Sstevel@tonic-gate "\tdetach: ndi_event_free_hdl() failed"); 6657c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6667c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 6697c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = NULL; 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(); 6727c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 6737c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup(); 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 6767c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = NULL; 6777c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6787c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 6797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6807c478bd9Sstevel@tonic-gate } 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate /* 6847c478bd9Sstevel@tonic-gate * ibnex_pseudo_node_cleanup() 6857c478bd9Sstevel@tonic-gate * This checks if all the "dips" have been deallocated (implying 6867c478bd9Sstevel@tonic-gate * that all the children have been unconfigured) first. 6877c478bd9Sstevel@tonic-gate * If not, it just returns. 6887c478bd9Sstevel@tonic-gate * If yes, then it frees up memory allocated for devi_name, 6897c478bd9Sstevel@tonic-gate * node_addr, and property list. 6907c478bd9Sstevel@tonic-gate */ 6917c478bd9Sstevel@tonic-gate static void 6927c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void) 6937c478bd9Sstevel@tonic-gate { 6947c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head; 6957c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:"); 6987c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate for (; nodep; nodep = nodep->node_next) 7017c478bd9Sstevel@tonic-gate if (nodep->node_dip) 7027c478bd9Sstevel@tonic-gate return; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory"); 7057c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 7067c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node; 7097c478bd9Sstevel@tonic-gate if (pseudo->pseudo_node_addr) { 7107c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_node_addr, 7117c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_node_addr) + 1); 7127c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr = NULL; 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate if (pseudo->pseudo_devi_name) { 7167c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_devi_name, 7177c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_devi_name) + 1); 7187c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name = NULL; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate if (pseudo->pseudo_unit_addr) { 7227c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_unit_addr, 7237c478bd9Sstevel@tonic-gate pseudo->pseudo_unit_addr_len); 7247c478bd9Sstevel@tonic-gate } 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate /* 7307c478bd9Sstevel@tonic-gate * This functions wakes up any reprobe requests waiting for completion 7317c478bd9Sstevel@tonic-gate * of reprobe of this IOC. It also send an NDI event, if : 7327c478bd9Sstevel@tonic-gate * 7337c478bd9Sstevel@tonic-gate * notify_flag is set. This is set if : 7347c478bd9Sstevel@tonic-gate * ibt_reprobe_ioc has returned with SUCCESS 7357c478bd9Sstevel@tonic-gate * IBTF client has not been notified for this node. 7367c478bd9Sstevel@tonic-gate * node_data->node_dip != NULL 7377c478bd9Sstevel@tonic-gate * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set 7387c478bd9Sstevel@tonic-gate * An NDI event cookie has been registered. 7397c478bd9Sstevel@tonic-gate */ 7407c478bd9Sstevel@tonic-gate static void 7417c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag) 7427c478bd9Sstevel@tonic-gate { 7437c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7467c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) || 7497c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state != 0)) { 7507c478bd9Sstevel@tonic-gate if (notify_flag && (node_data->node_dip != NULL) && 7517c478bd9Sstevel@tonic-gate (node_data->node_state & 7527c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) && 7537c478bd9Sstevel@tonic-gate (evt_cookie != NULL)) { 7547c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate bzero(&evt_data, sizeof (evt_data)); 7597c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, 7607c478bd9Sstevel@tonic-gate node_data->node_dip, 7617c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 7627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 7637c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7697c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * This function wakes up any reprobe request waiting for completion 7767c478bd9Sstevel@tonic-gate * of reprobe of all IOCs. 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate static void 7797c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all() 7807c478bd9Sstevel@tonic-gate { 7817c478bd9Sstevel@tonic-gate ibnex_node_data_t *ioc_node; 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate /* Notify if another reprobe_all is pending */ 7867c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) { 7877c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7887c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate /* 7937c478bd9Sstevel@tonic-gate * The IOC may be hot-removed after the reprobe request. 7947c478bd9Sstevel@tonic-gate * Reset the reprobe states for such IOCs. 7957c478bd9Sstevel@tonic-gate */ 7967c478bd9Sstevel@tonic-gate for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node; 7977c478bd9Sstevel@tonic-gate ioc_node = ioc_node->node_next) { 7987c478bd9Sstevel@tonic-gate if (ioc_node->node_reprobe_state != 0) { 7997c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ioc_node, 1); 8007c478bd9Sstevel@tonic-gate } 8017c478bd9Sstevel@tonic-gate } 8027c478bd9Sstevel@tonic-gate } 8037c478bd9Sstevel@tonic-gate 8047c478bd9Sstevel@tonic-gate /* 8057c478bd9Sstevel@tonic-gate * ibnex_ibnex_callback: 8067c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_INIT: 8077c478bd9Sstevel@tonic-gate * Called from ibc_init() which is called from 8087c478bd9Sstevel@tonic-gate * HCA driver _init entry point 8097c478bd9Sstevel@tonic-gate * Initializes the HCA dev_ops structure with default 8107c478bd9Sstevel@tonic-gate * IB nexus structure. 8117c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_FINI: 8127c478bd9Sstevel@tonic-gate * Called from ibc_fini() which is called from 8137c478bd9Sstevel@tonic-gate * HCA driver _fini entry point 8147c478bd9Sstevel@tonic-gate * Un-Initializes the HCA dev_ops structure with default 8157c478bd9Sstevel@tonic-gate * IB nexus strucuture. 8167c478bd9Sstevel@tonic-gate * Returns IBT_SUCCESS 8177c478bd9Sstevel@tonic-gate */ 8187c478bd9Sstevel@tonic-gate ibt_status_t 8197c478bd9Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args) 8207c478bd9Sstevel@tonic-gate { 8217c478bd9Sstevel@tonic-gate int retval = IBT_SUCCESS; 8227c478bd9Sstevel@tonic-gate struct dev_ops *hca_dev_ops; 8237c478bd9Sstevel@tonic-gate dev_info_t *clnt_dip; 8247c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tibtl_callback"); 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate switch (cb_args->cb_flag) { 8297c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_INIT: 8307c478bd9Sstevel@tonic-gate /* 8317c478bd9Sstevel@tonic-gate * Get the devops structure of the HCA, 8327c478bd9Sstevel@tonic-gate * and put IB nexus default busops vector in its place. 8337c478bd9Sstevel@tonic-gate */ 8347c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8357c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8367c478bd9Sstevel@tonic-gate ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL)); 8377c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = &ibnex_ci_busops; 8387c478bd9Sstevel@tonic-gate break; 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_FINI: 8417c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8427c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8437c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = NULL; 8447c478bd9Sstevel@tonic-gate break; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate case IBTL_IBNEX_REPROBE_DEV_REQ: 8477c478bd9Sstevel@tonic-gate /* IBTL pass down request for ibt_reprobe_dev */ 8487c478bd9Sstevel@tonic-gate clnt_dip = cb_args->cb_dip; 8497c478bd9Sstevel@tonic-gate ASSERT(clnt_dip); 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(clnt_dip); 8527c478bd9Sstevel@tonic-gate ASSERT(node_data); 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate /* Reprobe for IOC nodes only */ 8557c478bd9Sstevel@tonic-gate ASSERT(node_data->node_type == IBNEX_IOC_NODE); 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate /* 8587c478bd9Sstevel@tonic-gate * Start the reprobe. This could sleep as it is not 8597c478bd9Sstevel@tonic-gate * from interrupt context. 8607c478bd9Sstevel@tonic-gate */ 8617c478bd9Sstevel@tonic-gate if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev, 8627c478bd9Sstevel@tonic-gate clnt_dip, TQ_SLEEP) == 0) { 8637c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 8647c478bd9Sstevel@tonic-gate "ibnex_ibtl_callback: taskq_dispatch failed"); 8657c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 8667c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 8677c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 8687c478bd9Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE); 8697c478bd9Sstevel@tonic-gate } 8707c478bd9Sstevel@tonic-gate return (IBT_SUCCESS); 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate return (retval); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate /* 8787c478bd9Sstevel@tonic-gate * Bus-ops entry points 8797c478bd9Sstevel@tonic-gate */ 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate /* 8827c478bd9Sstevel@tonic-gate * ibnex_map_fault 8837c478bd9Sstevel@tonic-gate * IOC drivers need not map memory. Return failure to fail any 8847c478bd9Sstevel@tonic-gate * such calls. 8857c478bd9Sstevel@tonic-gate */ 8867c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8877c478bd9Sstevel@tonic-gate static int 8887c478bd9Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat, 8897c478bd9Sstevel@tonic-gate struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn, 8907c478bd9Sstevel@tonic-gate uint_t prot, uint_t lock) 8917c478bd9Sstevel@tonic-gate { 8927c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate /* 8977c478bd9Sstevel@tonic-gate * ibnex_busctl 8987c478bd9Sstevel@tonic-gate * bus_ctl bus_ops entry point 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 9017c478bd9Sstevel@tonic-gate static int 9027c478bd9Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip, 9037c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 9047c478bd9Sstevel@tonic-gate { 9057c478bd9Sstevel@tonic-gate dev_info_t *child_dip; 9067c478bd9Sstevel@tonic-gate 9077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 9087c478bd9Sstevel@tonic-gate "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop); 9097c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result); 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate switch (ctlop) { 9127c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 9137c478bd9Sstevel@tonic-gate if (rdip == NULL) { 9147c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate /* Log the relevant details of dip to sysbuf */ 9187c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n", 9197c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 9207c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 9257c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9267c478bd9Sstevel@tonic-gate return (ibnex_init_child(child_dip)); 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 9297c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9307c478bd9Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL); 9317c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 9347c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 9357c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POWER : 9367c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 9397c478bd9Sstevel@tonic-gate /* 9407c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and 9417c478bd9Sstevel@tonic-gate * DDI_FAILURE for the nodes enumerated by a Pseudo file. 9427c478bd9Sstevel@tonic-gate */ 9437c478bd9Sstevel@tonic-gate return (ndi_dev_is_persistent_node(rdip) ? 9447c478bd9Sstevel@tonic-gate DDI_SUCCESS : DDI_FAILURE); 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 9487c478bd9Sstevel@tonic-gate /* 9497c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS, so that consistent buf alloc 9507c478bd9Sstevel@tonic-gate * gets the default DMA IO minimum for the platform 9517c478bd9Sstevel@tonic-gate */ 9527c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate /* 9557c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be 9567c478bd9Sstevel@tonic-gate * called by IB Nexus driver. 9577c478bd9Sstevel@tonic-gate */ 9587c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 9597c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 9607c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 9617c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 9627c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 9637c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 9647c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: 9657c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 9667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 9677c478bd9Sstevel@tonic-gate "%s%d: invalid op (%d) from %s inst%d", 9687c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 9697c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 9707c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate /* 9737c478bd9Sstevel@tonic-gate * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we 9747c478bd9Sstevel@tonic-gate * pass up 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate default: 9777c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 9787c478bd9Sstevel@tonic-gate } 9797c478bd9Sstevel@tonic-gate } 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate /* 9837c478bd9Sstevel@tonic-gate * ibnex_init_child() 9847c478bd9Sstevel@tonic-gate * 9857c478bd9Sstevel@tonic-gate * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD 9867c478bd9Sstevel@tonic-gate * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED. 9877c478bd9Sstevel@tonic-gate */ 9887c478bd9Sstevel@tonic-gate static int 9897c478bd9Sstevel@tonic-gate ibnex_init_child(dev_info_t *child) 9907c478bd9Sstevel@tonic-gate { 9917c478bd9Sstevel@tonic-gate int ret; 9927c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate /* Handle Pseudo nodes of client children */ 9977c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 9989d3d2ed0Shiremath /* Skip nodes without ib-node-type="merge" */ 9999d3d2ed0Shiremath if (ibnex_is_merge_node(child) != IBNEX_SUCCESS) 10009d3d2ed0Shiremath return (DDI_FAILURE); 10019d3d2ed0Shiremath 10027c478bd9Sstevel@tonic-gate if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS) 10037c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 10067c478bd9Sstevel@tonic-gate /* 10077c478bd9Sstevel@tonic-gate * Merge the .conf node 10087c478bd9Sstevel@tonic-gate */ 10097c478bd9Sstevel@tonic-gate if (ndi_merge_node(child, 10107c478bd9Sstevel@tonic-gate ibnex_name_child) == DDI_SUCCESS) { 10117c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 10127c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10137c478bd9Sstevel@tonic-gate } 10147c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate } 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS) 10197c478bd9Sstevel@tonic-gate return (ret); 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate int 10287c478bd9Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name) 10297c478bd9Sstevel@tonic-gate { 10307c478bd9Sstevel@tonic-gate char **unit_addr; 10317c478bd9Sstevel@tonic-gate uint_t n; 10327c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 10337c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 10347c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 10359d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 10369d3d2ed0Shiremath "\tname_pseudo_child: cannot find unit-address in %s.conf", 10377c478bd9Sstevel@tonic-gate ddi_get_name(child)); 10387c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 10417c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 10427c478bd9Sstevel@tonic-gate " not well-formed", ddi_get_name(child)); 10437c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10447c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr); 10477c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10487c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10497c478bd9Sstevel@tonic-gate } 10507c478bd9Sstevel@tonic-gate 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10537c478bd9Sstevel@tonic-gate int 10547c478bd9Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag) 10557c478bd9Sstevel@tonic-gate { 10567c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 10577c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_datap; 10587c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 10597c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate node_datap = ddi_get_parent_data(child); 10627c478bd9Sstevel@tonic-gate if (node_datap == NULL) { 10637c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL"); 10647c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10657c478bd9Sstevel@tonic-gate } 10667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p" 10677c478bd9Sstevel@tonic-gate "Node type %x", node_datap, node_datap->node_type); 10687c478bd9Sstevel@tonic-gate switch (node_datap->node_type) { 10697c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE: 10707c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10717c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10727c478bd9Sstevel@tonic-gate port_node->port_num, 10737c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]); 10747c478bd9Sstevel@tonic-gate break; 10757c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE: 10767c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10777c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s", 10787c478bd9Sstevel@tonic-gate port_node->port_num, port_node->port_pkey, ibnex. 10797c478bd9Sstevel@tonic-gate ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]); 10807c478bd9Sstevel@tonic-gate break; 10817c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE: 10827c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10837c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10847c478bd9Sstevel@tonic-gate port_node->port_num, 10857c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[port_node-> 10867c478bd9Sstevel@tonic-gate port_commsvc_idx]); 10877c478bd9Sstevel@tonic-gate break; 10887c478bd9Sstevel@tonic-gate case IBNEX_IOC_NODE: 10897c478bd9Sstevel@tonic-gate ioc = &node_datap->node_data.ioc_node; 10907c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX", 10917c478bd9Sstevel@tonic-gate (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid); 10927c478bd9Sstevel@tonic-gate break; 10937c478bd9Sstevel@tonic-gate case IBNEX_PSEUDO_NODE: 10947c478bd9Sstevel@tonic-gate pseudo = &node_datap->node_data.pseudo_node; 10957c478bd9Sstevel@tonic-gate (void) snprintf(name, 10967c478bd9Sstevel@tonic-gate IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr); 10977c478bd9Sstevel@tonic-gate break; 10987c478bd9Sstevel@tonic-gate default: 10997c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed"); 11007c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate /* 11087c478bd9Sstevel@tonic-gate * ibnex_bus_config() 11097c478bd9Sstevel@tonic-gate * 11107c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE: 11117c478bd9Sstevel@tonic-gate * Enumerate the exact instance of the driver. Use the device node name 11127c478bd9Sstevel@tonic-gate * to locate the exact instance. 11137c478bd9Sstevel@tonic-gate * Query IBDM to find whether the hardware exits for the instance of the 11147c478bd9Sstevel@tonic-gate * driver. If exists, create a device node and return NDI_SUCCESS. 11157c478bd9Sstevel@tonic-gate * 11167c478bd9Sstevel@tonic-gate * BUS_CONFIG_ALL: 11177c478bd9Sstevel@tonic-gate * Enumerate all the instances of all the possible children (seen before 11187c478bd9Sstevel@tonic-gate * and never seen before). 11197c478bd9Sstevel@tonic-gate * 11207c478bd9Sstevel@tonic-gate * BUS_CONFIG_DRIVER: 11217c478bd9Sstevel@tonic-gate * Enumerate all the instances of a particular driver. 11227c478bd9Sstevel@tonic-gate */ 11237c478bd9Sstevel@tonic-gate static int 11247c478bd9Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag, 11257c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *devname, dev_info_t **child) 11267c478bd9Sstevel@tonic-gate { 11279d3d2ed0Shiremath int ret = IBNEX_SUCCESS, len, circ, need_bus_config; 11287c478bd9Sstevel@tonic-gate char *device_name, *cname = NULL, *caddr = NULL; 11299d3d2ed0Shiremath char *device_name1; 11307c478bd9Sstevel@tonic-gate char *srvname, nameaddr[MAXNAMELEN]; 11317c478bd9Sstevel@tonic-gate dev_info_t *cdip, *pdip = NULL; 11327c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 11337c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 11345e3986cbScth int use_mdi_devi_locking = 0; 11357c478bd9Sstevel@tonic-gate 113600a3eaf3SRamaswamy Tummala if (parent != ibnex.ibnex_dip) { 113700a3eaf3SRamaswamy Tummala /* 113800a3eaf3SRamaswamy Tummala * This must be an HCA.In a normal case HCA is setup as a phci. 113900a3eaf3SRamaswamy Tummala * If an HCA is in maintenance mode, its phci is not set up 114000a3eaf3SRamaswamy Tummala * but the driver is attached to update the firmware. In this 114100a3eaf3SRamaswamy Tummala * case, do not configure the MPxIO clients. 114200a3eaf3SRamaswamy Tummala */ 114300a3eaf3SRamaswamy Tummala if (mdi_component_is_phci(parent, NULL) == MDI_FAILURE) { 114400a3eaf3SRamaswamy Tummala if (op == BUS_CONFIG_ALL || op == BUS_CONFIG_DRIVER) 114500a3eaf3SRamaswamy Tummala return (NDI_SUCCESS); 114600a3eaf3SRamaswamy Tummala else 114700a3eaf3SRamaswamy Tummala return (NDI_FAILURE); 114800a3eaf3SRamaswamy Tummala } 11495e3986cbScth 11505e3986cbScth /* Set use_mdi_devi_locking appropriately */ 115100a3eaf3SRamaswamy Tummala if ((op != BUS_CONFIG_ONE) || (op == BUS_CONFIG_ONE && 115200a3eaf3SRamaswamy Tummala strncmp((char *)devname, IBNEX_IBPORT_CNAME, 6) != 0)) { 115300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 115400a3eaf3SRamaswamy Tummala "\tbus_config: using mdi_devi_enter"); 11555e3986cbScth use_mdi_devi_locking = 1; 11565e3986cbScth } 115700a3eaf3SRamaswamy Tummala } 11585e3986cbScth 11595e3986cbScth if (use_mdi_devi_locking) 11605e3986cbScth mdi_devi_enter(parent, &circ); 11615e3986cbScth else 11627c478bd9Sstevel@tonic-gate ndi_devi_enter(parent, &circ); 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate switch (op) { 11657c478bd9Sstevel@tonic-gate case BUS_CONFIG_ONE: 116605fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, " 116705fa0d51Spramodbg "parent %p", parent); 11687c478bd9Sstevel@tonic-gate 11697c478bd9Sstevel@tonic-gate len = strlen((char *)devname) + 1; 11707c478bd9Sstevel@tonic-gate device_name = i_ddi_strdup(devname, KM_SLEEP); 11717c478bd9Sstevel@tonic-gate i_ddi_parse_name(device_name, &cname, &caddr, NULL); 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate if (caddr == NULL || (strlen(caddr) == 0)) { 11747c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 11755e3986cbScth if (use_mdi_devi_locking) 11765e3986cbScth mdi_devi_exit(parent, circ); 11775e3986cbScth else 11787c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 11797c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 11807c478bd9Sstevel@tonic-gate } 11817c478bd9Sstevel@tonic-gate 11829d3d2ed0Shiremath /* 11839d3d2ed0Shiremath * i_ddi_parse_name() strips of the address portion 11849d3d2ed0Shiremath * of the device name. Recreate device name for 11859d3d2ed0Shiremath * ndi_devi_findchild 11869d3d2ed0Shiremath */ 11879d3d2ed0Shiremath device_name1 = i_ddi_strdup(devname, KM_SLEEP); 11889d3d2ed0Shiremath 11897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 11907c478bd9Sstevel@tonic-gate "\tbus_config: cname %s addr %s", cname, caddr); 11917c478bd9Sstevel@tonic-gate 11929d3d2ed0Shiremath cdip = ndi_devi_findchild(parent, device_name1); 119300a3eaf3SRamaswamy Tummala if (cdip) 119400a3eaf3SRamaswamy Tummala node_data = ddi_get_parent_data(cdip); 11959d3d2ed0Shiremath kmem_free(device_name1, len); 119600a3eaf3SRamaswamy Tummala if (cdip == NULL || (node_data != NULL && 119700a3eaf3SRamaswamy Tummala node_data->node_dip == NULL)) { 11987c478bd9Sstevel@tonic-gate /* Node is not present */ 11997c478bd9Sstevel@tonic-gate if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) { 12005e3986cbScth if (use_mdi_devi_locking) 12015e3986cbScth mdi_devi_exit(parent, circ); 12025e3986cbScth else 12039d3d2ed0Shiremath ndi_devi_exit(parent, circ); 12045e3986cbScth 12059d3d2ed0Shiremath ret = ibnex_ioc_bus_config_one(&parent, flag, 12069d3d2ed0Shiremath op, devname, child, &need_bus_config); 120705fa0d51Spramodbg if (!need_bus_config) { 120805fa0d51Spramodbg kmem_free(device_name, len); 12099d3d2ed0Shiremath return (ret); 121005fa0d51Spramodbg } 12119d3d2ed0Shiremath 12125e3986cbScth if (use_mdi_devi_locking) 12135e3986cbScth mdi_devi_enter(parent, &circ); 12145e3986cbScth else 12159d3d2ed0Shiremath ndi_devi_enter(parent, &circ); 12167c478bd9Sstevel@tonic-gate } else if ((strncmp(cname, 12177c478bd9Sstevel@tonic-gate IBNEX_IBPORT_CNAME, 6) == 0) && 12187c478bd9Sstevel@tonic-gate (parent != ibnex.ibnex_dip)) { /* parent is HCA */ 12197c478bd9Sstevel@tonic-gate cdip = ibnex_config_port_node(parent, devname); 12207c478bd9Sstevel@tonic-gate if (cdip) 12217c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 12227c478bd9Sstevel@tonic-gate else 12237c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12249d3d2ed0Shiremath } else { 12257c478bd9Sstevel@tonic-gate /* 12267c478bd9Sstevel@tonic-gate * if not IOC or PORT device then always 12277c478bd9Sstevel@tonic-gate * assume a Pseudo child 12289d3d2ed0Shiremath * 12299d3d2ed0Shiremath * if IB Nexus is the parent, call MDI. 12309d3d2ed0Shiremath * else if HCA is the parent, enumerate 12319d3d2ed0Shiremath * the Pseudo node. 12327c478bd9Sstevel@tonic-gate */ 12337c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 12347c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 12359d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 12365e3986cbScth if (use_mdi_devi_locking) 12375e3986cbScth mdi_devi_exit(parent, circ); 12385e3986cbScth else 12399d3d2ed0Shiremath ndi_devi_exit(parent, circ); 12405e3986cbScth 12417c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 12429d3d2ed0Shiremath ret = ibnex_pseudo_mdi_config_one( 12439d3d2ed0Shiremath flag, devname, child, cname, 12449d3d2ed0Shiremath caddr); 12457c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 124605fa0d51Spramodbg kmem_free(device_name, len); 12479d3d2ed0Shiremath return (ret); 12489d3d2ed0Shiremath } 12499d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 125005fa0d51Spramodbg ret = ibnex_pseudo_config_one(NULL, 12519d3d2ed0Shiremath caddr, parent); 12529d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 12539d3d2ed0Shiremath } 12547c478bd9Sstevel@tonic-gate } 1255a1e3386eShiremath 1256a1e3386eShiremath if (strncmp(cname, IBNEX_IBPORT_CNAME, 6) == 0) { 1257a1e3386eShiremath /* Allows enumeration under PHCI */ 1258a1e3386eShiremath flag |= NDI_MDI_FALLBACK; 1259a1e3386eShiremath } 12607c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate case BUS_CONFIG_OBP_ARGS: 12647c478bd9Sstevel@tonic-gate cdip = ibnex_config_obp_args(parent, devname); 12657c478bd9Sstevel@tonic-gate if (cdip) { 12667c478bd9Sstevel@tonic-gate /* 12677c478bd9Sstevel@tonic-gate * Boot case. 12687c478bd9Sstevel@tonic-gate * Special handling because the "devname" 12697c478bd9Sstevel@tonic-gate * format for the enumerated device is 12707c478bd9Sstevel@tonic-gate * different. 12717c478bd9Sstevel@tonic-gate */ 12727c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 12737c478bd9Sstevel@tonic-gate port_node = &node_data->node_data.port_node; 12747c478bd9Sstevel@tonic-gate if (node_data->node_type == 12757c478bd9Sstevel@tonic-gate IBNEX_VPPA_COMMSVC_NODE) { 12767c478bd9Sstevel@tonic-gate srvname = 12777c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[ 12787c478bd9Sstevel@tonic-gate port_node->port_commsvc_idx]; 12797c478bd9Sstevel@tonic-gate (void) snprintf(nameaddr, MAXNAMELEN, 12807c478bd9Sstevel@tonic-gate "ibport@%x,%x,%s", 12817c478bd9Sstevel@tonic-gate port_node->port_num, 12827c478bd9Sstevel@tonic-gate port_node->port_pkey, srvname); 12837c478bd9Sstevel@tonic-gate } 12847c478bd9Sstevel@tonic-gate devname = (void *)nameaddr; 12857c478bd9Sstevel@tonic-gate } else { 12867c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 12877c478bd9Sstevel@tonic-gate "\tbus_config: CONFIG_OBP_ARGS : invalid state!!"); 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate break; 12927c478bd9Sstevel@tonic-gate case BUS_CONFIG_ALL: 12939d3d2ed0Shiremath /*FALLTHRU*/ 12947c478bd9Sstevel@tonic-gate case BUS_CONFIG_DRIVER: 12959d3d2ed0Shiremath if (op == BUS_CONFIG_ALL) 129605fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, " 129705fa0d51Spramodbg "parent %p", parent); 12989d3d2ed0Shiremath else 129905fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER" 130005fa0d51Spramodbg ", parent %p", parent); 13017c478bd9Sstevel@tonic-gate 13029d3d2ed0Shiremath /* 13035e3986cbScth * No locks to be held while calling mdi_vhci_bus_config() 13045e3986cbScth * ibnex_config_all_children() holds appropriate locks. 13055e3986cbScth */ 13065e3986cbScth if (use_mdi_devi_locking) 13075e3986cbScth mdi_devi_exit(parent, circ); 13085e3986cbScth else 13095e3986cbScth ndi_devi_exit(parent, circ); 13105e3986cbScth 13115e3986cbScth /* 13129d3d2ed0Shiremath * Drive CONFIG requests for IB Nexus parent through 13139d3d2ed0Shiremath * MDI. This is needed to load the HCA drivers in x86 SRP 13149d3d2ed0Shiremath * boot case. 13159d3d2ed0Shiremath * 13169d3d2ed0Shiremath * CONFIG Requests with HCA parent will probe devices using 13179d3d2ed0Shiremath * ibdm and configure all children. 13189d3d2ed0Shiremath */ 13199d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 132051f34d4bSRajkumar Sivaprakasam ibdm_ioc_info_t *ioc_list, *new_ioc_list; 132100a3eaf3SRamaswamy Tummala 132251f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex); 132351f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state != 132451f34d4bSRajkumar Sivaprakasam IBNEX_IOC_LIST_READY) { 132551f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv, 132651f34d4bSRajkumar Sivaprakasam &ibnex.ibnex_mutex); 132751f34d4bSRajkumar Sivaprakasam } 132851f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW; 132951f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex); 133051f34d4bSRajkumar Sivaprakasam /* Enumerate all the IOC's */ 133151f34d4bSRajkumar Sivaprakasam ibdm_ibnex_port_settle_wait(0, 133251f34d4bSRajkumar Sivaprakasam ibnex_port_settling_time); 133351f34d4bSRajkumar Sivaprakasam 133451f34d4bSRajkumar Sivaprakasam new_ioc_list = ibdm_ibnex_get_ioc_list( 133551f34d4bSRajkumar Sivaprakasam IBDM_IBNEX_NORMAL_PROBE); 133651f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", 133751f34d4bSRajkumar Sivaprakasam "\tbus_config: alloc ioc_list %p", new_ioc_list); 133800a3eaf3SRamaswamy Tummala /* 133900a3eaf3SRamaswamy Tummala * Optimize the calls for each BUS_CONFIG_ALL request 134000a3eaf3SRamaswamy Tummala * to the IB Nexus dip. This is currently done for 134100a3eaf3SRamaswamy Tummala * each PDIP. 134200a3eaf3SRamaswamy Tummala */ 134351f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex); 134451f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list; 134551f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list = new_ioc_list; 134651f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 134751f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv); 134851f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex); 134951f34d4bSRajkumar Sivaprakasam 135051f34d4bSRajkumar Sivaprakasam if (ioc_list) { 135100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 135200a3eaf3SRamaswamy Tummala "\tbus_config: freeing ioc_list %p", 135351f34d4bSRajkumar Sivaprakasam ioc_list); 135451f34d4bSRajkumar Sivaprakasam ibdm_ibnex_free_ioc_list(ioc_list); 135500a3eaf3SRamaswamy Tummala } 135600a3eaf3SRamaswamy Tummala 135700a3eaf3SRamaswamy Tummala 13589d3d2ed0Shiremath ret = mdi_vhci_bus_config(parent, 13599d3d2ed0Shiremath flag, op, devname, child, NULL); 13609d3d2ed0Shiremath return (ret); 13619d3d2ed0Shiremath } else { 13629d3d2ed0Shiremath ibnex_config_all_children(parent); 13635e3986cbScth 13645e3986cbScth if (use_mdi_devi_locking) 13655e3986cbScth mdi_devi_enter(parent, &circ); 13665e3986cbScth else 13675e3986cbScth ndi_devi_enter(parent, &circ); 13689d3d2ed0Shiremath } 13699d3d2ed0Shiremath break; 13707c478bd9Sstevel@tonic-gate default: 13717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config: error"); 13727c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 13737c478bd9Sstevel@tonic-gate break; 13747c478bd9Sstevel@tonic-gate } 13755e3986cbScth 13765e3986cbScth if (use_mdi_devi_locking) 13775e3986cbScth mdi_devi_exit(parent, circ); 13785e3986cbScth else 13797c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 13805e3986cbScth 13817c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 13827c478bd9Sstevel@tonic-gate if (op == BUS_CONFIG_OBP_ARGS) 13837c478bd9Sstevel@tonic-gate op = BUS_CONFIG_ONE; 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate if (pdip == NULL) 13867c478bd9Sstevel@tonic-gate pdip = parent; 13877c478bd9Sstevel@tonic-gate 13887c478bd9Sstevel@tonic-gate ret = ndi_busop_bus_config( 13897c478bd9Sstevel@tonic-gate pdip, flag, op, devname, child, 0); 13907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config:" 13917c478bd9Sstevel@tonic-gate "ndi_busop_bus_config : retval %d", ret); 13927c478bd9Sstevel@tonic-gate return (ret); 13937c478bd9Sstevel@tonic-gate } 13947c478bd9Sstevel@tonic-gate 13957c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate /* 14007c478bd9Sstevel@tonic-gate * ibnex_config_root_iocnode() 14017c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 14027c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 14037c478bd9Sstevel@tonic-gate */ 14047c478bd9Sstevel@tonic-gate static int 14057c478bd9Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name) 14067c478bd9Sstevel@tonic-gate { 14077c478bd9Sstevel@tonic-gate int ret, port = 0, iter = 0; 14087c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 14097c478bd9Sstevel@tonic-gate char *portstr; 14107c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, iou_guid, ioc_guid; 14117c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 14127c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 14157c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: name %s", device_name); 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate portstr = strstr(device_name, ":port="); 14187c478bd9Sstevel@tonic-gate if (portstr == NULL) { 14197c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14207c478bd9Sstevel@tonic-gate } 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate portstr[0] = 0; portstr++; 14237c478bd9Sstevel@tonic-gate if (ibnex_devname2port(portstr, &port)) { 14247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port"); 14257c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14267c478bd9Sstevel@tonic-gate } 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 14299d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 14307c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14317c478bd9Sstevel@tonic-gate } 14327c478bd9Sstevel@tonic-gate 14337c478bd9Sstevel@tonic-gate (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4), 14347c478bd9Sstevel@tonic-gate "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid); 14357c478bd9Sstevel@tonic-gate 14367c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 14377c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) { 14387c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 14397c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: Port does not exist"); 14407c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate 14437c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 14447c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 14457c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 14467c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 14477c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 14487c478bd9Sstevel@tonic-gate hca_guid, port)) == NULL) { 14497c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14507c478bd9Sstevel@tonic-gate } 14517c478bd9Sstevel@tonic-gate 14527c478bd9Sstevel@tonic-gate if (iter++ == 400) { 14537c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 14547c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 14557c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 14567c478bd9Sstevel@tonic-gate displayed = B_TRUE; 14577c478bd9Sstevel@tonic-gate } 14587c478bd9Sstevel@tonic-gate } 14597c478bd9Sstevel@tonic-gate } 14607c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 14617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:" 14627c478bd9Sstevel@tonic-gate "Port is initialized"); 14637c478bd9Sstevel@tonic-gate 14647c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) { 14657c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 14667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 146900a3eaf3SRamaswamy Tummala if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) != 147000a3eaf3SRamaswamy Tummala IBNEX_SUCCESS) { 147100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 147200a3eaf3SRamaswamy Tummala "\tconfig_root_ioc_node failed for pdip %p", parent); 147300a3eaf3SRamaswamy Tummala } 14747c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 14757c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 14767c478bd9Sstevel@tonic-gate return (ret); 14777c478bd9Sstevel@tonic-gate } 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate static int 14817c478bd9Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port) 14827c478bd9Sstevel@tonic-gate { 14837c478bd9Sstevel@tonic-gate char *temp; 14847c478bd9Sstevel@tonic-gate int ret = IBNEX_FAILURE; 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin"); 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate temp = strchr(portstr, '='); 14897c478bd9Sstevel@tonic-gate if (temp != NULL) { 14907c478bd9Sstevel@tonic-gate temp++; 14917c478bd9Sstevel@tonic-gate *port = ibnex_str2int(temp, strlen(temp), &ret); 14927c478bd9Sstevel@tonic-gate } 14937c478bd9Sstevel@tonic-gate return (ret); 14947c478bd9Sstevel@tonic-gate } 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate /* 14987c478bd9Sstevel@tonic-gate * ibnex_config_all_children() 14997c478bd9Sstevel@tonic-gate * Wait for lata SM initialization case before enumerating the nodes 15007c478bd9Sstevel@tonic-gate * Get list of HCA's and HCA port information 15017c478bd9Sstevel@tonic-gate * Create device device nodes and its node properties 15027c478bd9Sstevel@tonic-gate * for port nodes and VPPA nodes 15037c478bd9Sstevel@tonic-gate * Get list of all the IOC node information 15047c478bd9Sstevel@tonic-gate * Create device nodes and its properties for all the IOCs 15057c478bd9Sstevel@tonic-gate * if not created already 15067c478bd9Sstevel@tonic-gate * Bind drivers for all the newly created device nodes 15077c478bd9Sstevel@tonic-gate * Support Pseudo nodes enumerated using their .conf file 15087c478bd9Sstevel@tonic-gate */ 15097c478bd9Sstevel@tonic-gate static void 15107c478bd9Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent) 15117c478bd9Sstevel@tonic-gate { 15127c478bd9Sstevel@tonic-gate int ii; 151300a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_list; 15147c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 15157c478bd9Sstevel@tonic-gate ib_guid_t hca_guid; 15165e3986cbScth int circ; 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin"); 15197c478bd9Sstevel@tonic-gate 15207c478bd9Sstevel@tonic-gate /* 15219d3d2ed0Shiremath * Enumerate children of this HCA, port nodes, 15225e3986cbScth * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for 15235e3986cbScth * locking. IB Nexus is enumerating the children 15245e3986cbScth * of HCA, not MPXIO clients. 15257c478bd9Sstevel@tonic-gate */ 15265e3986cbScth ndi_devi_enter(parent, &circ); 15277c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 152800a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time); 15297c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 1530f9edfba4Spramodbg if (hca_list == NULL) { 1531f9edfba4Spramodbg ndi_devi_exit(parent, circ); 15327c478bd9Sstevel@tonic-gate return; 1533f9edfba4Spramodbg } 15347c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr); 15357c478bd9Sstevel@tonic-gate for (ii = 0; ii < hca_list->hl_nports; ii++) { 15367c478bd9Sstevel@tonic-gate ibnex_create_port_nodes( 15377c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 15387c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes( 15397c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 15407c478bd9Sstevel@tonic-gate } 15417c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 15425e3986cbScth ndi_devi_exit(parent, circ); 15435e3986cbScth 15445e3986cbScth /* 15455e3986cbScth * Use mdi_devi_enter() for locking. IB Nexus is 15468b2e16e7Seota * enumerating MPxIO clients. 15475e3986cbScth */ 15485e3986cbScth mdi_devi_enter(parent, &circ); 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 155351f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) { 155451f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex); 155551f34d4bSRajkumar Sivaprakasam } 155651f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS; 155751f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list; 15587c478bd9Sstevel@tonic-gate while (ioc_list) { 155900a3eaf3SRamaswamy Tummala (void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0); 15607c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 15617c478bd9Sstevel@tonic-gate } 156251f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 156351f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv); 15649d3d2ed0Shiremath 15659d3d2ed0Shiremath /* Config IBTF Pseudo clients */ 15669d3d2ed0Shiremath ibnex_config_pseudo_all(parent); 15679d3d2ed0Shiremath 15687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15695e3986cbScth mdi_devi_exit(parent, circ); 15709d3d2ed0Shiremath 15717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End"); 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate /* 15767c478bd9Sstevel@tonic-gate * ibnex_create_port_nodes: 15777c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15787c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 15797c478bd9Sstevel@tonic-gate */ 15807c478bd9Sstevel@tonic-gate static void 15817c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15827c478bd9Sstevel@tonic-gate { 15837c478bd9Sstevel@tonic-gate int idx; 15847c478bd9Sstevel@tonic-gate dev_info_t *dip; 15857c478bd9Sstevel@tonic-gate int rval; 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15887c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) { 15897c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 15907c478bd9Sstevel@tonic-gate idx, 0, &dip); 15917c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 15927c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 15937c478bd9Sstevel@tonic-gate IBNEX_PORT_COMMSVC_NODE, 0, &rval, 15947c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 15957c478bd9Sstevel@tonic-gate } 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15987c478bd9Sstevel@tonic-gate } 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate 16017c478bd9Sstevel@tonic-gate /* 16027c478bd9Sstevel@tonic-gate * ibnex_create_vppa_nodes: 16037c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 16047c478bd9Sstevel@tonic-gate * in the "vppa-commsvc-list" property and per each PKEY that 16057c478bd9Sstevel@tonic-gate * this particular port supports and per HCA port 16067c478bd9Sstevel@tonic-gate */ 16077c478bd9Sstevel@tonic-gate static void 16087c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 16097c478bd9Sstevel@tonic-gate { 16107c478bd9Sstevel@tonic-gate int idx, ii; 16117c478bd9Sstevel@tonic-gate int rval; 16127c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 16137c478bd9Sstevel@tonic-gate dev_info_t *dip; 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin"); 16167c478bd9Sstevel@tonic-gate 16177c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 16187c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 16197c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: " 16207c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 16217c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16227c478bd9Sstevel@tonic-gate return; 16237c478bd9Sstevel@tonic-gate } 16247c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) { 16257c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 16267c478bd9Sstevel@tonic-gate pkey = port_attr->pa_pkey_tbl[ii].pt_pkey; 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate if (IBNEX_INVALID_PKEY(pkey)) { 16297c478bd9Sstevel@tonic-gate continue; 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid( 16327c478bd9Sstevel@tonic-gate port_attr->pa_port_guid, idx, pkey, &dip); 163300a3eaf3SRamaswamy Tummala if ((rval != IBNEX_SUCCESS) || (dip == NULL)) { 16347c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, 16357c478bd9Sstevel@tonic-gate idx, IBNEX_VPPA_COMMSVC_NODE, 16367c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate } 16407c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16417c478bd9Sstevel@tonic-gate } 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate 16447c478bd9Sstevel@tonic-gate /* 16457c478bd9Sstevel@tonic-gate * ibnex_create_hcasvc_nodes: 16467c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 16477c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 16487c478bd9Sstevel@tonic-gate */ 16497c478bd9Sstevel@tonic-gate static void 16507c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 16517c478bd9Sstevel@tonic-gate { 16527c478bd9Sstevel@tonic-gate int idx; 16537c478bd9Sstevel@tonic-gate dev_info_t *dip; 16547c478bd9Sstevel@tonic-gate int rval; 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 16577c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) { 16587c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 16597c478bd9Sstevel@tonic-gate idx, 0, &dip); 16607c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 16617c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 16627c478bd9Sstevel@tonic-gate IBNEX_HCASVC_COMMSVC_NODE, 0, &rval, 16637c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 16647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: " 16657c478bd9Sstevel@tonic-gate "commsvc_initnode failed, rval %x", rval); 16667c478bd9Sstevel@tonic-gate } 16677c478bd9Sstevel@tonic-gate } 16687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16697c478bd9Sstevel@tonic-gate } 16707c478bd9Sstevel@tonic-gate 16717c478bd9Sstevel@tonic-gate 16727c478bd9Sstevel@tonic-gate /* 16737c478bd9Sstevel@tonic-gate * ibnex_bus_unconfig() 16747c478bd9Sstevel@tonic-gate * 16757c478bd9Sstevel@tonic-gate * Unconfigure a particular device node or all instance of a device 16767c478bd9Sstevel@tonic-gate * driver device or all children of IBnex 16777c478bd9Sstevel@tonic-gate */ 16787c478bd9Sstevel@tonic-gate static int 16797c478bd9Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent, 16807c478bd9Sstevel@tonic-gate uint_t flag, ddi_bus_config_op_t op, void *device_name) 16817c478bd9Sstevel@tonic-gate { 168200a3eaf3SRamaswamy Tummala ibnex_node_data_t *ndp; 168300a3eaf3SRamaswamy Tummala major_t major = (major_t)(uintptr_t)device_name; 168400a3eaf3SRamaswamy Tummala dev_info_t *dip = NULL; 168500a3eaf3SRamaswamy Tummala 168600a3eaf3SRamaswamy Tummala if (ndi_busop_bus_unconfig(parent, flag, op, device_name) != 168700a3eaf3SRamaswamy Tummala DDI_SUCCESS) 168800a3eaf3SRamaswamy Tummala return (DDI_FAILURE); 168900a3eaf3SRamaswamy Tummala 169000a3eaf3SRamaswamy Tummala /* 169100a3eaf3SRamaswamy Tummala * We can come into this routine with dip as ibnexus dip or hca dip. 169200a3eaf3SRamaswamy Tummala * When the dip is that of ib nexus we need to clean up the IOC and 169300a3eaf3SRamaswamy Tummala * pseudo nodes. When the dip is that of an HCA (not IB nexus dip) 169400a3eaf3SRamaswamy Tummala * cleanup the port nodes. 169500a3eaf3SRamaswamy Tummala */ 169600a3eaf3SRamaswamy Tummala if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) && 169700a3eaf3SRamaswamy Tummala (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) { 169800a3eaf3SRamaswamy Tummala mutex_enter(&ibnex.ibnex_mutex); 169900a3eaf3SRamaswamy Tummala if (parent != ibnex.ibnex_dip) { 170000a3eaf3SRamaswamy Tummala if (major == -1) { 170100a3eaf3SRamaswamy Tummala /* 170200a3eaf3SRamaswamy Tummala * HCA dip. When major number is -1 HCA is 170300a3eaf3SRamaswamy Tummala * going away cleanup all the port nodes. 170400a3eaf3SRamaswamy Tummala */ 170500a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_port_node_head; 170600a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 170700a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 170800a3eaf3SRamaswamy Tummala 170900a3eaf3SRamaswamy Tummala port_node = &ndp->node_data.port_node; 171000a3eaf3SRamaswamy Tummala if (port_node->port_pdip == parent) { 171100a3eaf3SRamaswamy Tummala port_node->port_pdip = NULL; 171200a3eaf3SRamaswamy Tummala ndp->node_dip = NULL; 171300a3eaf3SRamaswamy Tummala ndp->node_state = 171400a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 171500a3eaf3SRamaswamy Tummala } 171600a3eaf3SRamaswamy Tummala } 171700a3eaf3SRamaswamy Tummala } else { 171800a3eaf3SRamaswamy Tummala /* 171900a3eaf3SRamaswamy Tummala * HCA dip. Cleanup only the port nodes that 172000a3eaf3SRamaswamy Tummala * match the major number. 172100a3eaf3SRamaswamy Tummala */ 172200a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_port_node_head; 172300a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 172400a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 172500a3eaf3SRamaswamy Tummala 172600a3eaf3SRamaswamy Tummala port_node = &ndp->node_data.port_node; 172700a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 172800a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == 172900a3eaf3SRamaswamy Tummala major) && port_node->port_pdip == 173000a3eaf3SRamaswamy Tummala parent) { 173100a3eaf3SRamaswamy Tummala port_node->port_pdip = NULL; 173200a3eaf3SRamaswamy Tummala ndp->node_dip = NULL; 173300a3eaf3SRamaswamy Tummala ndp->node_state = 173400a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 173500a3eaf3SRamaswamy Tummala } 173600a3eaf3SRamaswamy Tummala } 173700a3eaf3SRamaswamy Tummala } 173800a3eaf3SRamaswamy Tummala } else { 173900a3eaf3SRamaswamy Tummala /* 174000a3eaf3SRamaswamy Tummala * IB dip. here we handle IOC and pseudo nodes which 174100a3eaf3SRamaswamy Tummala * are the children of IB nexus. Cleanup only the nodes 174200a3eaf3SRamaswamy Tummala * with matching major number. We also need to cleanup 174300a3eaf3SRamaswamy Tummala * the PathInfo links to the PHCI here. 174400a3eaf3SRamaswamy Tummala */ 174500a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_ioc_node_head; 174600a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 174700a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 174800a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) { 1749332f545bSEiji Ota (void) ibnex_offline_childdip(dip); 175000a3eaf3SRamaswamy Tummala } 175100a3eaf3SRamaswamy Tummala } 175200a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_pseudo_node_head; 175300a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 175400a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 175500a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) { 1756332f545bSEiji Ota (void) ibnex_offline_childdip(dip); 175700a3eaf3SRamaswamy Tummala } 175800a3eaf3SRamaswamy Tummala } 175900a3eaf3SRamaswamy Tummala } 176000a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex); 176100a3eaf3SRamaswamy Tummala } 176200a3eaf3SRamaswamy Tummala return (DDI_SUCCESS); 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate 17667c478bd9Sstevel@tonic-gate /* 17677c478bd9Sstevel@tonic-gate * ibnex_config_port_node() 17687c478bd9Sstevel@tonic-gate * 17697c478bd9Sstevel@tonic-gate * Configures a particular port / HCA node for a particular 17707c478bd9Sstevel@tonic-gate * communication service. 17717c478bd9Sstevel@tonic-gate * The format of the device_name is 17727c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 17737c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 17747c478bd9Sstevel@tonic-gate * Port# = 0 for HCA_SVC communication service nodes 17757c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 17767c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 17777c478bd9Sstevel@tonic-gate */ 17787c478bd9Sstevel@tonic-gate static dev_info_t * 17797c478bd9Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname) 17807c478bd9Sstevel@tonic-gate { 17817c478bd9Sstevel@tonic-gate int ii, index; 17827c478bd9Sstevel@tonic-gate int rval; 17837c478bd9Sstevel@tonic-gate uint8_t port_num; 17847c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 17857c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 17867c478bd9Sstevel@tonic-gate dev_info_t *cdip; 17877c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 17887c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 17897c478bd9Sstevel@tonic-gate 17907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname); 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate if (ibnex_get_pkey_commsvc_index_portnum(devname, 17937c478bd9Sstevel@tonic-gate &index, &pkey, &port_num) != IBNEX_SUCCESS) { 17947c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 17957c478bd9Sstevel@tonic-gate "\tconfig_port_node: Invalid Service Name"); 17967c478bd9Sstevel@tonic-gate return (NULL); 17977c478bd9Sstevel@tonic-gate } 17987c478bd9Sstevel@tonic-gate 17997c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 18007c478bd9Sstevel@tonic-gate if (port_num == 0) { 18017c478bd9Sstevel@tonic-gate /* 18027c478bd9Sstevel@tonic-gate * Use the dummy port attribute for HCA node in hca_list 18037c478bd9Sstevel@tonic-gate * Note : pa_state is always IBT_PORT_ACTIVE. 18047c478bd9Sstevel@tonic-gate */ 18057c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 18067c478bd9Sstevel@tonic-gate ASSERT(hca_list != NULL); 18077c478bd9Sstevel@tonic-gate port_attr = hca_list->hl_hca_port_attr; 18087c478bd9Sstevel@tonic-gate } else { 18097c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 18107c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 18127c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 18137c478bd9Sstevel@tonic-gate return (NULL); 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 181700a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait( 181800a3eaf3SRamaswamy Tummala hca_guid, ibnex_port_settling_time); 18197c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18207c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 18217c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18227c478bd9Sstevel@tonic-gate return (NULL); 18237c478bd9Sstevel@tonic-gate } 18247c478bd9Sstevel@tonic-gate } 18257c478bd9Sstevel@tonic-gate } 18267c478bd9Sstevel@tonic-gate 18277c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 18287c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 18297c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 18307c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 18317c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 18327c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18337c478bd9Sstevel@tonic-gate if (port_num != 0) 18347c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18357c478bd9Sstevel@tonic-gate else 18367c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 18377c478bd9Sstevel@tonic-gate return (cdip); 18387c478bd9Sstevel@tonic-gate } 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate if (pkey == 0 && port_num != 0) { 18417c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 18427c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval, 18437c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 18447c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18457c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18467c478bd9Sstevel@tonic-gate } else if (pkey == 0 && port_num == 0) { 18477c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 18487c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval, 18497c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 18507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18517c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18527c478bd9Sstevel@tonic-gate } else { 18537c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 18547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: " 18557c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 18567c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18577c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18587c478bd9Sstevel@tonic-gate return (NULL); 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 18617c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 18627c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 18637c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, 18647c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 18657c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18667c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18677c478bd9Sstevel@tonic-gate break; 18687c478bd9Sstevel@tonic-gate } 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate } 18717c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18727c478bd9Sstevel@tonic-gate if (port_num != 0) 18737c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18747c478bd9Sstevel@tonic-gate else 18757c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 18767c478bd9Sstevel@tonic-gate return (cdip); 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate /* 18817c478bd9Sstevel@tonic-gate * ibnex_config_obp_args() 18827c478bd9Sstevel@tonic-gate * Configures a particular port node for a IP over IB communication 18837c478bd9Sstevel@tonic-gate * service. 18847c478bd9Sstevel@tonic-gate * The format of the input string "devname" is 18857c478bd9Sstevel@tonic-gate * port=x,pkey=y,protocol=ip,<wanboot options> 18867c478bd9Sstevel@tonic-gate * Thr format of the node name created here is 18877c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 18887c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 18897c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 18907c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 18917c478bd9Sstevel@tonic-gate * 18927c478bd9Sstevel@tonic-gate */ 18937c478bd9Sstevel@tonic-gate static dev_info_t * 18947c478bd9Sstevel@tonic-gate ibnex_config_obp_args(dev_info_t *parent, char *devname) 18957c478bd9Sstevel@tonic-gate { 18967c478bd9Sstevel@tonic-gate int ii, index; 18977c478bd9Sstevel@tonic-gate int rval, iter = 0; 18987c478bd9Sstevel@tonic-gate char *temp; 18997c478bd9Sstevel@tonic-gate uint8_t port_num; 19007c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 19017c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 19027c478bd9Sstevel@tonic-gate dev_info_t *cdip; 19037c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 19047c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 19057c478bd9Sstevel@tonic-gate 19067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_obp_args: %s", devname); 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate /* Is this OBP node for IPoIB ? */ 19097c478bd9Sstevel@tonic-gate temp = devname; 19107c478bd9Sstevel@tonic-gate do { 19117c478bd9Sstevel@tonic-gate temp = strstr(temp, ",protocol=ip"); 19127c478bd9Sstevel@tonic-gate if (temp == NULL) 19137c478bd9Sstevel@tonic-gate break; 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate if (strlen(devname) > (int)((temp - devname) + 12)) { 19167c478bd9Sstevel@tonic-gate if (temp[12] == ',') 19177c478bd9Sstevel@tonic-gate break; 19187c478bd9Sstevel@tonic-gate } else { 19197c478bd9Sstevel@tonic-gate break; 19207c478bd9Sstevel@tonic-gate } 19217c478bd9Sstevel@tonic-gate temp++; 19227c478bd9Sstevel@tonic-gate } while (temp); 19237c478bd9Sstevel@tonic-gate 19247c478bd9Sstevel@tonic-gate if (temp == NULL) 19257c478bd9Sstevel@tonic-gate return (NULL); 19267c478bd9Sstevel@tonic-gate if (ibnex_prom_devname_to_pkey_n_portnum( 19277c478bd9Sstevel@tonic-gate devname, &pkey, &port_num) != IBNEX_SUCCESS) { 19287c478bd9Sstevel@tonic-gate return (NULL); 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 19317c478bd9Sstevel@tonic-gate if (strcmp(ibnex.ibnex_vppa_comm_svc_names[index], 19327c478bd9Sstevel@tonic-gate "ipib") == 0) { 19337c478bd9Sstevel@tonic-gate break; 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate } 19367c478bd9Sstevel@tonic-gate 19377c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 19387c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 19397c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 19407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 19417c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 19427c478bd9Sstevel@tonic-gate return (NULL); 19437c478bd9Sstevel@tonic-gate } 19447c478bd9Sstevel@tonic-gate 19457c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 19467c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 19477c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19487c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 19497c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 19507c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 19517c478bd9Sstevel@tonic-gate return (NULL); 19527c478bd9Sstevel@tonic-gate } 19537c478bd9Sstevel@tonic-gate if (iter++ == 400) { 19547c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 19557c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 19567c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 19577c478bd9Sstevel@tonic-gate displayed = B_TRUE; 19587c478bd9Sstevel@tonic-gate } 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tPort is initialized"); 19627c478bd9Sstevel@tonic-gate 19637c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 19647c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 19657c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 19667c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 19677c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 19687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 19697c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19707c478bd9Sstevel@tonic-gate return (cdip); 19717c478bd9Sstevel@tonic-gate } 19727c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 19737c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 19747c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 19757c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, pkey, &rval, 19767c478bd9Sstevel@tonic-gate IBNEX_CFGADM_ENUMERATE); 19777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 19787c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 19797c478bd9Sstevel@tonic-gate break; 19807c478bd9Sstevel@tonic-gate } 19817c478bd9Sstevel@tonic-gate } 19827c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 19837c478bd9Sstevel@tonic-gate 19847c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19857c478bd9Sstevel@tonic-gate return (cdip); 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate /* 19907c478bd9Sstevel@tonic-gate * ibnex_prom_devname_to_pkey_n_portnum() 19917c478bd9Sstevel@tonic-gate * Parses the device node name and extracts "PKEY" and "port#" 19927c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 19937c478bd9Sstevel@tonic-gate */ 19947c478bd9Sstevel@tonic-gate static int 19957c478bd9Sstevel@tonic-gate ibnex_prom_devname_to_pkey_n_portnum( 19967c478bd9Sstevel@tonic-gate char *devname, ib_pkey_t *pkey, uint8_t *port) 19977c478bd9Sstevel@tonic-gate { 19987c478bd9Sstevel@tonic-gate int ret = IBNEX_SUCCESS; 19997c478bd9Sstevel@tonic-gate char *tmp, *tmp1; 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate if ((tmp = strstr(devname, "port=")) != NULL) { 20027c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 20037c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 20047c478bd9Sstevel@tonic-gate *port = ibnex_str2int(tmp, (tmp1 - tmp), &ret); 20057c478bd9Sstevel@tonic-gate } else 20067c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 20077c478bd9Sstevel@tonic-gate 20087c478bd9Sstevel@tonic-gate if ((ret == IBNEX_SUCCESS) && 20097c478bd9Sstevel@tonic-gate (tmp = strstr(devname, "pkey=")) != NULL) { 20107c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 20117c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 20127c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(tmp, (tmp1 - tmp), &ret); 20137c478bd9Sstevel@tonic-gate } else 20147c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate return (ret); 20177c478bd9Sstevel@tonic-gate } 20187c478bd9Sstevel@tonic-gate 20197c478bd9Sstevel@tonic-gate 20207c478bd9Sstevel@tonic-gate /* 20217c478bd9Sstevel@tonic-gate * ibnex_get_pkey_commsvc_index_portnum() 20227c478bd9Sstevel@tonic-gate * Parses the device node name and extracts PKEY, communication 20237c478bd9Sstevel@tonic-gate * service index & Port #. 20247c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20257c478bd9Sstevel@tonic-gate */ 20267c478bd9Sstevel@tonic-gate static int 20277c478bd9Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index, 20287c478bd9Sstevel@tonic-gate ib_pkey_t *pkey, uint8_t *port_num) 20297c478bd9Sstevel@tonic-gate { 20307c478bd9Sstevel@tonic-gate char *srv, **service_name, *temp; 20317c478bd9Sstevel@tonic-gate int ii, ncommsvcs, ret; 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate if (ibnex_devname_to_portnum(device_name, port_num) != 20347c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 20357c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 20367c478bd9Sstevel@tonic-gate "\tget_pkey_commsvc_index_portnum: Invalid PortGuid"); 20377c478bd9Sstevel@tonic-gate return (NULL); 20387c478bd9Sstevel@tonic-gate } 20397c478bd9Sstevel@tonic-gate srv = strchr(device_name, ','); 20407c478bd9Sstevel@tonic-gate if (srv == 0) 20417c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20427c478bd9Sstevel@tonic-gate 20437c478bd9Sstevel@tonic-gate srv++; 20447c478bd9Sstevel@tonic-gate temp = strchr(srv, ','); 20457c478bd9Sstevel@tonic-gate if (temp == 0) 20467c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20477c478bd9Sstevel@tonic-gate temp++; 20487c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret); 20497c478bd9Sstevel@tonic-gate if (ret != IBNEX_SUCCESS) 20507c478bd9Sstevel@tonic-gate return (ret); 20517c478bd9Sstevel@tonic-gate 20527c478bd9Sstevel@tonic-gate if (*pkey == 0 && *port_num != 0) { 20537c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_comm_svc_names; 20547c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_num_comm_svcs; 20557c478bd9Sstevel@tonic-gate } else if (*pkey == 0 && *port_num == 0) { 20567c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_hcasvc_comm_svc_names; 20577c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs; 20587c478bd9Sstevel@tonic-gate } else { 20597c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_vppa_comm_svc_names; 20607c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nvppa_comm_svcs; 20617c478bd9Sstevel@tonic-gate } 20627c478bd9Sstevel@tonic-gate 20637c478bd9Sstevel@tonic-gate for (ii = 0; ii < ncommsvcs; ii++) { 20647c478bd9Sstevel@tonic-gate if (strcmp(service_name[ii], temp) == 0) { 20657c478bd9Sstevel@tonic-gate break; 20667c478bd9Sstevel@tonic-gate } 20677c478bd9Sstevel@tonic-gate } 20687c478bd9Sstevel@tonic-gate if (ii == ncommsvcs) 20697c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20707c478bd9Sstevel@tonic-gate 20717c478bd9Sstevel@tonic-gate *index = ii; 20727c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 20737c478bd9Sstevel@tonic-gate } 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate /* 20777c478bd9Sstevel@tonic-gate * ibnex_devname_to_portnum() 20787c478bd9Sstevel@tonic-gate * Get portguid from device name 20797c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20807c478bd9Sstevel@tonic-gate */ 20817c478bd9Sstevel@tonic-gate static int 20827c478bd9Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum) 20837c478bd9Sstevel@tonic-gate { 20847c478bd9Sstevel@tonic-gate int ret; 20857c478bd9Sstevel@tonic-gate char *temp1, *temp2; 20867c478bd9Sstevel@tonic-gate 20877c478bd9Sstevel@tonic-gate temp1 = strchr(device_name, '@'); 20887c478bd9Sstevel@tonic-gate if (temp1 == NULL) { 20897c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20907c478bd9Sstevel@tonic-gate } 20917c478bd9Sstevel@tonic-gate temp2 = strchr(temp1, ','); 20927c478bd9Sstevel@tonic-gate if (temp2 == NULL) 20937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20947c478bd9Sstevel@tonic-gate temp1++; 20957c478bd9Sstevel@tonic-gate *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret); 20967c478bd9Sstevel@tonic-gate return (ret); 20977c478bd9Sstevel@tonic-gate } 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate /* 21017c478bd9Sstevel@tonic-gate * ibnex_config_ioc_node() 21027c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 21037c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 21047c478bd9Sstevel@tonic-gate */ 21057c478bd9Sstevel@tonic-gate static int 21069d3d2ed0Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip) 21077c478bd9Sstevel@tonic-gate { 21087c478bd9Sstevel@tonic-gate int ret; 21097c478bd9Sstevel@tonic-gate ib_guid_t iou_guid, ioc_guid; 21107c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 21117c478bd9Sstevel@tonic-gate 21127c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin"); 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 21159d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 21167c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21177c478bd9Sstevel@tonic-gate } 21187c478bd9Sstevel@tonic-gate 211900a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time); 21207c478bd9Sstevel@tonic-gate 21217c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == 21227c478bd9Sstevel@tonic-gate NULL) { 21237c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 21247c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21257c478bd9Sstevel@tonic-gate } 21267c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 212700a3eaf3SRamaswamy Tummala ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0); 21287c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 21297c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 213000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x", 213100a3eaf3SRamaswamy Tummala ret); 21327c478bd9Sstevel@tonic-gate return (ret); 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate 21367c478bd9Sstevel@tonic-gate /* 21377c478bd9Sstevel@tonic-gate * ibnex_devname_to_node_n_ioc_guids() 21387c478bd9Sstevel@tonic-gate * Get node guid and ioc guid from the device name 21397c478bd9Sstevel@tonic-gate * Format of the device node name is: 21407c478bd9Sstevel@tonic-gate * ioc@<IOC GUID>,<IOU GUID> 21417c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 21427c478bd9Sstevel@tonic-gate */ 21437c478bd9Sstevel@tonic-gate static int 21447c478bd9Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids( 21459d3d2ed0Shiremath char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid, 21469d3d2ed0Shiremath char **ioc_guid_strp) 21477c478bd9Sstevel@tonic-gate { 21487c478bd9Sstevel@tonic-gate char *temp1, *temp; 21497c478bd9Sstevel@tonic-gate int len, ret; 21509d3d2ed0Shiremath char *ioc_guid_str; 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:" 21537c478bd9Sstevel@tonic-gate "Device Name %s", device_name); 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate if ((temp = strchr(device_name, '@')) == NULL) { 21567c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21577c478bd9Sstevel@tonic-gate } 21587c478bd9Sstevel@tonic-gate if ((temp1 = strchr(++temp, ',')) == NULL) { 21597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret); 21627c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 21639d3d2ed0Shiremath if (ioc_guid_strp) { 21649d3d2ed0Shiremath ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1 21659d3d2ed0Shiremath - temp) + 1, KM_SLEEP); 21669d3d2ed0Shiremath (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1); 21679d3d2ed0Shiremath ioc_guid_str[temp1 - temp] = '\0'; 21689d3d2ed0Shiremath } 21697c478bd9Sstevel@tonic-gate len = device_name + strlen(device_name) - ++temp1; 21707c478bd9Sstevel@tonic-gate *iou_guid = ibnex_str2hex(temp1, len, &ret); 21717c478bd9Sstevel@tonic-gate } 21727c478bd9Sstevel@tonic-gate return (ret); 21737c478bd9Sstevel@tonic-gate } 21747c478bd9Sstevel@tonic-gate 21757c478bd9Sstevel@tonic-gate 21767c478bd9Sstevel@tonic-gate /* 21777c478bd9Sstevel@tonic-gate * ibnex_ioc_initnode() 21787c478bd9Sstevel@tonic-gate * Allocate a pathinfo node for the IOC 21797c478bd9Sstevel@tonic-gate * Initialize the device node 21807c478bd9Sstevel@tonic-gate * Bind driver to the node 21817c478bd9Sstevel@tonic-gate * Update IBnex global data 21827c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY 21837c478bd9Sstevel@tonic-gate */ 218400a3eaf3SRamaswamy Tummala static int 218500a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data, 218600a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 21877c478bd9Sstevel@tonic-gate { 218800a3eaf3SRamaswamy Tummala int rval, node_valid; 218900a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state; 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 219200a3eaf3SRamaswamy Tummala ASSERT(node_data); 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate /* 21967c478bd9Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure 21977c478bd9Sstevel@tonic-gate * operation is in progress 21987c478bd9Sstevel@tonic-gate */ 21997c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 220000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 220100a3eaf3SRamaswamy Tummala "\tioc_initnode_pdip : BUSY"); 22027c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 22037c478bd9Sstevel@tonic-gate } 22047c478bd9Sstevel@tonic-gate 220500a3eaf3SRamaswamy Tummala prev_state = node_data->node_state; 22067c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 22077c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 22087c478bd9Sstevel@tonic-gate 220900a3eaf3SRamaswamy Tummala rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid); 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 22127c478bd9Sstevel@tonic-gate if (rval == IBNEX_SUCCESS) 22137c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 221400a3eaf3SRamaswamy Tummala else if (node_valid) 221500a3eaf3SRamaswamy Tummala node_data->node_state = prev_state; 22167c478bd9Sstevel@tonic-gate 22177c478bd9Sstevel@tonic-gate return (rval); 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate /* 22217c478bd9Sstevel@tonic-gate * ibnex_config_pseudo_all() 22227c478bd9Sstevel@tonic-gate * Configure all the pseudo nodes 22237c478bd9Sstevel@tonic-gate */ 22247c478bd9Sstevel@tonic-gate static void 22259d3d2ed0Shiremath ibnex_config_pseudo_all(dev_info_t *pdip) 22267c478bd9Sstevel@tonic-gate { 22277c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 22287c478bd9Sstevel@tonic-gate 22297c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 22307c478bd9Sstevel@tonic-gate 22317c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; 22327c478bd9Sstevel@tonic-gate nodep; nodep = nodep->node_next) { 223305fa0d51Spramodbg (void) ibnex_pseudo_config_one(nodep, NULL, pdip); 22347c478bd9Sstevel@tonic-gate } 22357c478bd9Sstevel@tonic-gate } 22367c478bd9Sstevel@tonic-gate 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate /* 22397c478bd9Sstevel@tonic-gate * ibnex_pseudo_config_one() 22407c478bd9Sstevel@tonic-gate */ 224105fa0d51Spramodbg static int 224205fa0d51Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr, 22439d3d2ed0Shiremath dev_info_t *pdip) 22447c478bd9Sstevel@tonic-gate { 224505fa0d51Spramodbg int rval; 224600a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo; 224700a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state; 22487c478bd9Sstevel@tonic-gate 224900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)", 225005fa0d51Spramodbg node_data, caddr, pdip); 22517c478bd9Sstevel@tonic-gate 22527c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 22537c478bd9Sstevel@tonic-gate 22547c478bd9Sstevel@tonic-gate if (node_data == NULL) { 225500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 225600a3eaf3SRamaswamy Tummala "\tpseudo_config_one: caddr = %s", caddr); 22577c478bd9Sstevel@tonic-gate 225805fa0d51Spramodbg /* 225905fa0d51Spramodbg * This function is now called with PHCI / HCA driver 226005fa0d51Spramodbg * as parent. The format of devicename is : 226105fa0d51Spramodbg * <driver_name>@<driver_name>,<unit_address> 226205fa0d51Spramodbg * The "caddr" part of the devicename matches the 226305fa0d51Spramodbg * format of pseudo_node_addr. 226405fa0d51Spramodbg * 226505fa0d51Spramodbg * Use "caddr" to find a matching Pseudo node entry. 226605fa0d51Spramodbg */ 22677c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 226805fa0d51Spramodbg (void *)caddr, 0, 0); 22697c478bd9Sstevel@tonic-gate } 22707c478bd9Sstevel@tonic-gate 227100a3eaf3SRamaswamy Tummala if (node_data == NULL) { 227200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 227300a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Invalid node"); 227400a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 227500a3eaf3SRamaswamy Tummala } 227600a3eaf3SRamaswamy Tummala 227700a3eaf3SRamaswamy Tummala if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) { 227800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 227900a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Unconfigured node"); 228000a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 228100a3eaf3SRamaswamy Tummala } 228200a3eaf3SRamaswamy Tummala 228300a3eaf3SRamaswamy Tummala pseudo = &node_data->node_data.pseudo_node; 228400a3eaf3SRamaswamy Tummala 22857c478bd9Sstevel@tonic-gate /* 22869d3d2ed0Shiremath * Do not enumerate nodes with ib-node-type set as "merge" 22879d3d2ed0Shiremath */ 228800a3eaf3SRamaswamy Tummala if (pseudo->pseudo_merge_node == 1) { 228900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 229000a3eaf3SRamaswamy Tummala "\tpseudo_config_one: merge_node"); 22919d3d2ed0Shiremath return (IBNEX_FAILURE); 22929d3d2ed0Shiremath } 22939d3d2ed0Shiremath 22949d3d2ed0Shiremath /* 229500a3eaf3SRamaswamy Tummala * Check if a PI has already been created for the PDIP. 229600a3eaf3SRamaswamy Tummala * If so, return SUCCESS. 22977c478bd9Sstevel@tonic-gate */ 229800a3eaf3SRamaswamy Tummala if (node_data->node_dip != NULL && mdi_pi_find(pdip, 229900a3eaf3SRamaswamy Tummala pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) { 230000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 230100a3eaf3SRamaswamy Tummala "\tpseudo_config_one: PI created," 230200a3eaf3SRamaswamy Tummala " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr); 230300a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS); 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate 23067c478bd9Sstevel@tonic-gate /* 230700a3eaf3SRamaswamy Tummala * Return EBUSY if another unconfigure 23087c478bd9Sstevel@tonic-gate * operation is in progress 23097c478bd9Sstevel@tonic-gate */ 23107c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 231100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 231200a3eaf3SRamaswamy Tummala "\tpseudo_config_one: BUSY"); 23137c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 23147c478bd9Sstevel@tonic-gate } 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate 231700a3eaf3SRamaswamy Tummala prev_state = node_data->node_state; 23187c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 23197c478bd9Sstevel@tonic-gate 23207c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 232100a3eaf3SRamaswamy Tummala rval = ibnex_pseudo_create_pi_pdip(node_data, pdip); 23227c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 23237c478bd9Sstevel@tonic-gate 232400a3eaf3SRamaswamy Tummala if (rval == IBNEX_SUCCESS) { 23257c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 232600a3eaf3SRamaswamy Tummala } else { 232700a3eaf3SRamaswamy Tummala node_data->node_state = prev_state; 23287c478bd9Sstevel@tonic-gate } 23297c478bd9Sstevel@tonic-gate 233000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x", 233100a3eaf3SRamaswamy Tummala rval); 23327c478bd9Sstevel@tonic-gate return (rval); 23337c478bd9Sstevel@tonic-gate } 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate 23369d3d2ed0Shiremath /* 23379d3d2ed0Shiremath * ibnex_pseudo_mdi_config_one() 23389d3d2ed0Shiremath * This is similar to ibnex_pseudo_config_one. Few 23399d3d2ed0Shiremath * differences : 23409d3d2ed0Shiremath * 1. parent device lock not held(no ndi_devi_enter) 23419d3d2ed0Shiremath * 2. Called for IB Nexus as parent, not IB HCA as 23429d3d2ed0Shiremath * parent. 23439d3d2ed0Shiremath * 3. Calls mdi_vhci_bus_config() 234405fa0d51Spramodbg * This function skips checks for node_state, initializing 234505fa0d51Spramodbg * node_state, node_dip, etc. These checks and initializations 234605fa0d51Spramodbg * are done when BUS_CONFIG is called with PHCI as the parent. 23479d3d2ed0Shiremath */ 23489d3d2ed0Shiremath static int 23499d3d2ed0Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child, 23509d3d2ed0Shiremath char *cname, char *caddr) 23519d3d2ed0Shiremath { 23529d3d2ed0Shiremath int rval, len; 23539d3d2ed0Shiremath char *node_addr; 23549d3d2ed0Shiremath ibnex_node_data_t *node_data; 23559d3d2ed0Shiremath 23569d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:" 23579d3d2ed0Shiremath "cname = %s caddr = %s", cname, caddr); 23589d3d2ed0Shiremath 23599d3d2ed0Shiremath ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 23609d3d2ed0Shiremath 23619d3d2ed0Shiremath len = strlen(cname) + strlen(caddr) + 2; 23629d3d2ed0Shiremath node_addr = (char *)kmem_alloc(len, KM_SLEEP); 23639d3d2ed0Shiremath 23649d3d2ed0Shiremath (void) snprintf(node_addr, len, "%s,%s", cname, caddr); 23659d3d2ed0Shiremath node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 23669d3d2ed0Shiremath (void *)node_addr, 0, 0); 23679d3d2ed0Shiremath kmem_free(node_addr, len); 23689d3d2ed0Shiremath 236905fa0d51Spramodbg if (node_data == NULL) { 23709d3d2ed0Shiremath IBTF_DPRINTF_L2("ibnex", 23719d3d2ed0Shiremath "\tpseudo_mdi_config_one: Invalid node"); 23729d3d2ed0Shiremath return (IBNEX_FAILURE); 23739d3d2ed0Shiremath } 23749d3d2ed0Shiremath 23759d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 23769d3d2ed0Shiremath rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE, 23779d3d2ed0Shiremath devname, child, node_data->node_data.pseudo_node.pseudo_node_addr); 23789d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 23799d3d2ed0Shiremath 23809d3d2ed0Shiremath return (rval); 23819d3d2ed0Shiremath } 23829d3d2ed0Shiremath 238300a3eaf3SRamaswamy Tummala 23847c478bd9Sstevel@tonic-gate /* 238500a3eaf3SRamaswamy Tummala * ibnex_pseudo_create_all_pi() 238600a3eaf3SRamaswamy Tummala * Create all path infos node for a pseudo entry 23877c478bd9Sstevel@tonic-gate */ 23887c478bd9Sstevel@tonic-gate int 238900a3eaf3SRamaswamy Tummala ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep) 23907c478bd9Sstevel@tonic-gate { 239100a3eaf3SRamaswamy Tummala int hcacnt, rc; 239200a3eaf3SRamaswamy Tummala int hcafailcnt = 0; 239300a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 23947c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list, *head; 23957c478bd9Sstevel@tonic-gate 239600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)", 239700a3eaf3SRamaswamy Tummala nodep); 23987c478bd9Sstevel@tonic-gate ibdm_ibnex_get_hca_list(&hca_list, &hcacnt); 23997c478bd9Sstevel@tonic-gate 24007c478bd9Sstevel@tonic-gate head = hca_list; 24017c478bd9Sstevel@tonic-gate 24029d3d2ed0Shiremath /* 240300a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs. 24049d3d2ed0Shiremath */ 240500a3eaf3SRamaswamy Tummala for (; hca_list != NULL; hca_list = hca_list->hl_next) { 240600a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 240700a3eaf3SRamaswamy Tummala rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip); 240800a3eaf3SRamaswamy Tummala if (rc != IBNEX_SUCCESS) 240900a3eaf3SRamaswamy Tummala hcafailcnt++; 241000a3eaf3SRamaswamy Tummala } 241100a3eaf3SRamaswamy Tummala if (head) 241200a3eaf3SRamaswamy Tummala ibdm_ibnex_free_hca_list(head); 241300a3eaf3SRamaswamy Tummala 241400a3eaf3SRamaswamy Tummala if (hcafailcnt == hcacnt) 241500a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE; 241600a3eaf3SRamaswamy Tummala else 241700a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 241800a3eaf3SRamaswamy Tummala 241900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x", 242000a3eaf3SRamaswamy Tummala rc); 242100a3eaf3SRamaswamy Tummala return (rc); 242200a3eaf3SRamaswamy Tummala } 242300a3eaf3SRamaswamy Tummala 242400a3eaf3SRamaswamy Tummala static int 242500a3eaf3SRamaswamy Tummala ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip) 242600a3eaf3SRamaswamy Tummala { 242700a3eaf3SRamaswamy Tummala mdi_pathinfo_t *pip; 242800a3eaf3SRamaswamy Tummala int rval; 242900a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL; 243000a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo; 243100a3eaf3SRamaswamy Tummala int first_pi = 0; 243200a3eaf3SRamaswamy Tummala 243300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p", 243400a3eaf3SRamaswamy Tummala nodep, hca_dip); 243500a3eaf3SRamaswamy Tummala 243600a3eaf3SRamaswamy Tummala pseudo = &nodep->node_data.pseudo_node; 24379d3d2ed0Shiremath 24387c478bd9Sstevel@tonic-gate rval = mdi_pi_alloc(hca_dip, 24397c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name, pseudo->pseudo_node_addr, 24407c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr, 0, &pip); 24417c478bd9Sstevel@tonic-gate 24427c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 244300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:" 244400a3eaf3SRamaswamy Tummala " mdi_pi_alloc failed"); 24457c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 24487c478bd9Sstevel@tonic-gate 244900a3eaf3SRamaswamy Tummala if (nodep->node_dip == NULL) { 24507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 24517c478bd9Sstevel@tonic-gate "\tpseudo_create_pi: New dip %p", cdip); 24527c478bd9Sstevel@tonic-gate 245300a3eaf3SRamaswamy Tummala first_pi = 1; 24547c478bd9Sstevel@tonic-gate nodep->node_dip = cdip; 24557c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, nodep); 245600a3eaf3SRamaswamy Tummala } 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 246100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 246200a3eaf3SRamaswamy Tummala "\tpseudo_create_pi: " 24637c478bd9Sstevel@tonic-gate "mdi_pi_online: failed for pseudo dip %p," 24647c478bd9Sstevel@tonic-gate " rval %d", cdip, rval); 24657c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 246600a3eaf3SRamaswamy Tummala if (first_pi == 1) { 246700a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL); 246800a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip); 246900a3eaf3SRamaswamy Tummala nodep->node_dip = NULL; 247000a3eaf3SRamaswamy Tummala } else 247100a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0); 24727c478bd9Sstevel@tonic-gate } else 24737c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 24747c478bd9Sstevel@tonic-gate return (rval); 24757c478bd9Sstevel@tonic-gate } 24767c478bd9Sstevel@tonic-gate 24777c478bd9Sstevel@tonic-gate /* 24787c478bd9Sstevel@tonic-gate * ibnex_ioc_create_pi() 24797c478bd9Sstevel@tonic-gate * Create a pathinfo node for the ioc node 24807c478bd9Sstevel@tonic-gate */ 24817c478bd9Sstevel@tonic-gate static int 24829d3d2ed0Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data, 248300a3eaf3SRamaswamy Tummala dev_info_t *pdip, int *node_valid) 24847c478bd9Sstevel@tonic-gate { 24857c478bd9Sstevel@tonic-gate mdi_pathinfo_t *pip; 24869d3d2ed0Shiremath int rval = DDI_FAILURE; 248700a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL; 248800a3eaf3SRamaswamy Tummala int create_prop = 0; 248900a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc = &node_data->node_data.ioc_node; 24907c478bd9Sstevel@tonic-gate 249100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 249200a3eaf3SRamaswamy Tummala "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip); 249300a3eaf3SRamaswamy Tummala *node_valid = 1; 24947c478bd9Sstevel@tonic-gate 24959d3d2ed0Shiremath /* 24969d3d2ed0Shiremath * For CONFIG_ONE requests through HCA dip, alloc 24979d3d2ed0Shiremath * for HCA dip driving BUS_CONFIG request. 24989d3d2ed0Shiremath */ 249900a3eaf3SRamaswamy Tummala rval = mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str, 250000a3eaf3SRamaswamy Tummala ioc->ioc_phci_guid, 0, &pip); 25017c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 250200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 250300a3eaf3SRamaswamy Tummala "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed", 250400a3eaf3SRamaswamy Tummala pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid); 25057c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25067c478bd9Sstevel@tonic-gate } 25077c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 25087c478bd9Sstevel@tonic-gate 250900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p", 251000a3eaf3SRamaswamy Tummala cdip); 25117c478bd9Sstevel@tonic-gate 251200a3eaf3SRamaswamy Tummala if (node_data->node_dip == NULL) { 25137c478bd9Sstevel@tonic-gate node_data->node_dip = cdip; 25147c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, node_data); 251500a3eaf3SRamaswamy Tummala create_prop = 1; 251600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 251700a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop"); 25187c478bd9Sstevel@tonic-gate if ((rval = ibnex_create_ioc_node_prop( 25197c478bd9Sstevel@tonic-gate ioc_info, cdip)) != IBNEX_SUCCESS) { 252000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 252100a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop failed"); 25227c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data); 252300a3eaf3SRamaswamy Tummala *node_valid = 0; 25247c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 25257c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 25287c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25297c478bd9Sstevel@tonic-gate } 25307c478bd9Sstevel@tonic-gate } 25317c478bd9Sstevel@tonic-gate 25327c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 25357c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: " 25367c478bd9Sstevel@tonic-gate "mdi_pi_online() failed ioc dip %p, rval %d", 25377c478bd9Sstevel@tonic-gate cdip, rval); 25387c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 253900a3eaf3SRamaswamy Tummala if (create_prop) { 254000a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL); 254100a3eaf3SRamaswamy Tummala ddi_prop_remove_all(cdip); 254200a3eaf3SRamaswamy Tummala ibnex_delete_ioc_node_data(node_data); 254300a3eaf3SRamaswamy Tummala *node_valid = 0; 254400a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip); 254500a3eaf3SRamaswamy Tummala } else 254600a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0); 25477c478bd9Sstevel@tonic-gate } else 25487c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 25499d3d2ed0Shiremath 255000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval); 25517c478bd9Sstevel@tonic-gate return (rval); 25527c478bd9Sstevel@tonic-gate } 25537c478bd9Sstevel@tonic-gate 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate /* 25567c478bd9Sstevel@tonic-gate * ibnex_create_ioc_node_prop() 25577c478bd9Sstevel@tonic-gate * Create IOC device node properties 25587c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 25597c478bd9Sstevel@tonic-gate */ 25607c478bd9Sstevel@tonic-gate static int 25617c478bd9Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip) 25627c478bd9Sstevel@tonic-gate { 25637c478bd9Sstevel@tonic-gate uint16_t capabilities; 25647c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile; 25657c478bd9Sstevel@tonic-gate 25667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop"); 25677c478bd9Sstevel@tonic-gate 25687c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_compatible_prop(cdip, 25697c478bd9Sstevel@tonic-gate ioc_profile) != IBNEX_SUCCESS) { 25707c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25717c478bd9Sstevel@tonic-gate } 25727c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_iou_dc_valid) && 25737c478bd9Sstevel@tonic-gate (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode", 25747c478bd9Sstevel@tonic-gate ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) { 25757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25767c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: iou-diagcode create failed"); 25777c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25787c478bd9Sstevel@tonic-gate } 25797c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) { 25807c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode", 25817c478bd9Sstevel@tonic-gate ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) { 25827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 25837c478bd9Sstevel@tonic-gate "ioc-diagcode create failed"); 25847c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25857c478bd9Sstevel@tonic-gate } 25867c478bd9Sstevel@tonic-gate } 25877c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth", 25887c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) { 25897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25907c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: rdma-queue-depth create failed"); 25917c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size", 25947c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) { 25957c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 25967c478bd9Sstevel@tonic-gate "rdma-transfer-size create failed"); 25977c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25987c478bd9Sstevel@tonic-gate } 25997c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size", 26007c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) { 26017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26027c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-message-size create failed"); 26037c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26047c478bd9Sstevel@tonic-gate } 26057c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth", 26067c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) { 26077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26087c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-queue-depth create failed"); 26097c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26107c478bd9Sstevel@tonic-gate } 26117c478bd9Sstevel@tonic-gate 26127c478bd9Sstevel@tonic-gate capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8); 26137c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, 26147c478bd9Sstevel@tonic-gate "capabilities", capabilities) != DDI_PROP_SUCCESS) { 26157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26167c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: capabilities create failed"); 26177c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26187c478bd9Sstevel@tonic-gate } 26197c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string", 26207c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) { 26217c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26227c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: id-string failed"); 26237c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26247c478bd9Sstevel@tonic-gate } 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate /* 26277c478bd9Sstevel@tonic-gate * Create properties to represent all the service entries supported 26287c478bd9Sstevel@tonic-gate * by the IOC. Each service entry consists of 1) Service ID (64 bits) 26297c478bd9Sstevel@tonic-gate * and 2) Service name (40 bytes). The service entry table is 26307c478bd9Sstevel@tonic-gate * represented by two properties, service-ids and service-names. The 26317c478bd9Sstevel@tonic-gate * service-id property is a array of int64's and service names is 26327c478bd9Sstevel@tonic-gate * array of strings. The first element in the "service-ids" property 26337c478bd9Sstevel@tonic-gate * corresponds to first string in the "service-names" and so on. 26347c478bd9Sstevel@tonic-gate */ 26357c478bd9Sstevel@tonic-gate if ((ioc_profile->ioc_service_entries != 0) && 26367c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS)) 26377c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26387c478bd9Sstevel@tonic-gate 26397c478bd9Sstevel@tonic-gate /* Create destination port GID properties */ 26407c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS) 26417c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26427c478bd9Sstevel@tonic-gate 26437c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version", 26447c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) { 26457c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26467c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol-version create failed"); 26477c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26487c478bd9Sstevel@tonic-gate } 26497c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol", 26507c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) { 26517c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26527c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 26537c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass", 26567c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) { 26577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26587c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subclass create failed"); 26597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26607c478bd9Sstevel@tonic-gate } 26617c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class", 26627c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) { 26637c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26647c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: class prop create failed"); 26657c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26667c478bd9Sstevel@tonic-gate } 26677c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id", 26687c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) { 26697c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26707c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsys_id create failed"); 26717c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26727c478bd9Sstevel@tonic-gate } 26737c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id", 26747c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) { 26757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26767c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsystem vendor create failed"); 26777c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26787c478bd9Sstevel@tonic-gate } 26797c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid", 26807c478bd9Sstevel@tonic-gate ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) { 26817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26827c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 26837c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26847c478bd9Sstevel@tonic-gate } 26857c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version", 26867c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) { 26877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26887c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 26897c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26907c478bd9Sstevel@tonic-gate } 26917c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id", 26927c478bd9Sstevel@tonic-gate ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) { 26937c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26947c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 26957c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26967c478bd9Sstevel@tonic-gate } 26977c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id", 26987c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) { 26997c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27007c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: vendor-id create failed"); 27017c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27027c478bd9Sstevel@tonic-gate } 27037c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27047c478bd9Sstevel@tonic-gate } 27057c478bd9Sstevel@tonic-gate 27067c478bd9Sstevel@tonic-gate 27077c478bd9Sstevel@tonic-gate /* 27087c478bd9Sstevel@tonic-gate * ibnex_create_ioc_portgid_prop() 27097c478bd9Sstevel@tonic-gate * Creates "port-entries", "port-list" properties 27107c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 27117c478bd9Sstevel@tonic-gate */ 27127c478bd9Sstevel@tonic-gate static int 27137c478bd9Sstevel@tonic-gate ibnex_create_ioc_portgid_prop( 27147c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 27157c478bd9Sstevel@tonic-gate { 27167c478bd9Sstevel@tonic-gate uint64_t *port_gids; 27177c478bd9Sstevel@tonic-gate int length, ii, jj; 27187c478bd9Sstevel@tonic-gate int prop_len; 27197c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 27207c478bd9Sstevel@tonic-gate 27217c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop"); 27227c478bd9Sstevel@tonic-gate 27237c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 27247c478bd9Sstevel@tonic-gate ASSERT(node_data); 27257c478bd9Sstevel@tonic-gate 27267c478bd9Sstevel@tonic-gate prop_len = (ioc_info->ioc_nportgids != 0) ? 27277c478bd9Sstevel@tonic-gate (2 * ioc_info->ioc_nportgids) : 1; 27287c478bd9Sstevel@tonic-gate length = sizeof (uint64_t) * prop_len; 27297c478bd9Sstevel@tonic-gate port_gids = kmem_zalloc(length, KM_SLEEP); 27307c478bd9Sstevel@tonic-gate 27317c478bd9Sstevel@tonic-gate for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) { 27327c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi; 27337c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo; 27347c478bd9Sstevel@tonic-gate } 27357c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list", 27367c478bd9Sstevel@tonic-gate (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) { 27377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27387c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-list create failed"); 27397c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27407c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27417c478bd9Sstevel@tonic-gate } 27427c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries", 27437c478bd9Sstevel@tonic-gate ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) { 27447c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27457c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-entries create failed"); 27467c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27477c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27487c478bd9Sstevel@tonic-gate } 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27517c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27527c478bd9Sstevel@tonic-gate } 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate 27557c478bd9Sstevel@tonic-gate /* 27567c478bd9Sstevel@tonic-gate * ibnex_create_ioc_srv_props() 27577c478bd9Sstevel@tonic-gate * Creates "service-name" and "service-id" properties 27587c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 27597c478bd9Sstevel@tonic-gate */ 27607c478bd9Sstevel@tonic-gate static int 27617c478bd9Sstevel@tonic-gate ibnex_create_ioc_srv_props( 27627c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 27637c478bd9Sstevel@tonic-gate { 27647c478bd9Sstevel@tonic-gate int length, ii; 27657c478bd9Sstevel@tonic-gate uint64_t *srv_id; 27667c478bd9Sstevel@tonic-gate char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU]; 27677c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile; 27687c478bd9Sstevel@tonic-gate ibdm_srvents_info_t *srvents = ioc_info->ioc_serv; 27697c478bd9Sstevel@tonic-gate 27707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props"); 27717c478bd9Sstevel@tonic-gate 27727c478bd9Sstevel@tonic-gate length = profile->ioc_service_entries * sizeof (ib_dm_srv_t); 27737c478bd9Sstevel@tonic-gate srv_id = kmem_zalloc(length, KM_SLEEP); 27747c478bd9Sstevel@tonic-gate temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries)); 27757c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 27767c478bd9Sstevel@tonic-gate srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN); 27777c478bd9Sstevel@tonic-gate } 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 27807c478bd9Sstevel@tonic-gate srv_id[ii] = srvents[ii].se_attr.srv_id; 27817c478bd9Sstevel@tonic-gate bcopy(srvents[ii].se_attr.srv_name, 27827c478bd9Sstevel@tonic-gate srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1)); 27837c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 27847c478bd9Sstevel@tonic-gate "Service Names : %s", srv_names[ii]); 27857c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 27869d3d2ed0Shiremath "Service ID : %llX", srv_id[ii]); 27877c478bd9Sstevel@tonic-gate } 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, 27907c478bd9Sstevel@tonic-gate "service-id", (int64_t *)srv_id, 27917c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 27927c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27937c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-id create failed"); 27947c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27957c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27967c478bd9Sstevel@tonic-gate } 27977c478bd9Sstevel@tonic-gate 27987c478bd9Sstevel@tonic-gate if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 27997c478bd9Sstevel@tonic-gate "service-name", (char **)srv_names, 28007c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 28017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 28027c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-name create failed"); 28037c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 28047c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 28057c478bd9Sstevel@tonic-gate } 28067c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 28077c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 28087c478bd9Sstevel@tonic-gate } 28097c478bd9Sstevel@tonic-gate 28107c478bd9Sstevel@tonic-gate 28117c478bd9Sstevel@tonic-gate /* 28127c478bd9Sstevel@tonic-gate * ibnex_create_ioc_compatible_prop() 28137c478bd9Sstevel@tonic-gate * Creates "compatible" property values 28147c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 28157c478bd9Sstevel@tonic-gate */ 28167c478bd9Sstevel@tonic-gate static int 28177c478bd9Sstevel@tonic-gate ibnex_create_ioc_compatible_prop( 28187c478bd9Sstevel@tonic-gate dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile) 28197c478bd9Sstevel@tonic-gate { 28207c478bd9Sstevel@tonic-gate char *temp; 28217c478bd9Sstevel@tonic-gate int rval, ii; 28227c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_COMPAT_NAMES]; 28237c478bd9Sstevel@tonic-gate 28247c478bd9Sstevel@tonic-gate /* 28257c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 28267c478bd9Sstevel@tonic-gate * Compatible Strings : 28277c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver> 28287c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id> 28297c478bd9Sstevel@tonic-gate * 3. ib.V<vid>P<pid>v<ver> 28307c478bd9Sstevel@tonic-gate * 4. ib.V<vid>P<pid> 28317c478bd9Sstevel@tonic-gate * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver> 28327c478bd9Sstevel@tonic-gate * 6. ib.C<Class>c<Subclass>p<protocol> 28337c478bd9Sstevel@tonic-gate * 28347c478bd9Sstevel@tonic-gate * Note: 28357c478bd9Sstevel@tonic-gate * All leading zeros must be present 28367c478bd9Sstevel@tonic-gate * All numeric values must specified in hex without prefix "0x" 28377c478bd9Sstevel@tonic-gate */ 28387c478bd9Sstevel@tonic-gate 28397c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP); 28407c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 28417c478bd9Sstevel@tonic-gate compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN); 28427c478bd9Sstevel@tonic-gate 28437c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 28447c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08xv%04x", 28457c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28467c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id, 28477c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 28507c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08x", 28517c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28527c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id); 28537c478bd9Sstevel@tonic-gate 28547c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 28557c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x", 28567c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28577c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 28587c478bd9Sstevel@tonic-gate 28597c478bd9Sstevel@tonic-gate (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN, 28607c478bd9Sstevel@tonic-gate "ib.V%06xP%08x", 28617c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid); 28627c478bd9Sstevel@tonic-gate 28637c478bd9Sstevel@tonic-gate (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN, 28647c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04xr%04x", 28657c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 28667c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver); 28677c478bd9Sstevel@tonic-gate 28687c478bd9Sstevel@tonic-gate (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN, 28697c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04x", 28707c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 28717c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol); 28727c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 28737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]); 28747c478bd9Sstevel@tonic-gate 28757c478bd9Sstevel@tonic-gate /* Create the compatible property for child cdip */ 28767c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 28777c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES); 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 28807c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed"); 28817c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 28827c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 28837c478bd9Sstevel@tonic-gate } 28847c478bd9Sstevel@tonic-gate 28857c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 28867c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 28877c478bd9Sstevel@tonic-gate } 28887c478bd9Sstevel@tonic-gate 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate static void 28917c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup() 28927c478bd9Sstevel@tonic-gate { 28937c478bd9Sstevel@tonic-gate ibnex_node_data_t *node, *delete; 28947c478bd9Sstevel@tonic-gate 28957c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 28967c478bd9Sstevel@tonic-gate for (node = ibnex.ibnex_ioc_node_head; node; ) { 28977c478bd9Sstevel@tonic-gate delete = node; 28987c478bd9Sstevel@tonic-gate node = node->node_next; 28997c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 29007c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(delete); 29017c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 29027c478bd9Sstevel@tonic-gate } 29037c478bd9Sstevel@tonic-gate } 29047c478bd9Sstevel@tonic-gate 29057c478bd9Sstevel@tonic-gate /* 29067c478bd9Sstevel@tonic-gate * ibnex_delete_ioc_node_data() 29077c478bd9Sstevel@tonic-gate * Delete IOC node from the list 29087c478bd9Sstevel@tonic-gate */ 29097c478bd9Sstevel@tonic-gate static void 29107c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node) 29117c478bd9Sstevel@tonic-gate { 29127c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:"); 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 29157c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) { 29167c478bd9Sstevel@tonic-gate ASSERT(ibnex.ibnex_ioc_node_head == node); 29177c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = NULL; 29187c478bd9Sstevel@tonic-gate } else if (node->node_next == NULL) 29197c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 29207c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 29217c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 29227c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node->node_next; 29237c478bd9Sstevel@tonic-gate } else { 29247c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 29257c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 29267c478bd9Sstevel@tonic-gate } 29277c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p", 29287c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head); 29297c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 29307c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 29317c478bd9Sstevel@tonic-gate } 29327c478bd9Sstevel@tonic-gate 29337c478bd9Sstevel@tonic-gate 29347c478bd9Sstevel@tonic-gate /* 29357c478bd9Sstevel@tonic-gate * ibnex_dm_callback() 29367c478bd9Sstevel@tonic-gate * 29377c478bd9Sstevel@tonic-gate * This routine is registered with the IBDM during IB nexus attach. It 29387c478bd9Sstevel@tonic-gate * is called by the IBDM module when it discovers 29397c478bd9Sstevel@tonic-gate * New HCA port 29407c478bd9Sstevel@tonic-gate * HCA port removal 29417c478bd9Sstevel@tonic-gate * New HCA added 29427c478bd9Sstevel@tonic-gate * HCA removed 29437c478bd9Sstevel@tonic-gate */ 29447c478bd9Sstevel@tonic-gate void 29457c478bd9Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag) 29467c478bd9Sstevel@tonic-gate { 29477c478bd9Sstevel@tonic-gate char hca_guid[IBNEX_HCAGUID_STRSZ]; 29487c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc; 29497c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 2950*dcf1eb70SSudhakar Dindukurti dev_info_t *phci; 29517c478bd9Sstevel@tonic-gate 29527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag); 29537c478bd9Sstevel@tonic-gate 29547c478bd9Sstevel@tonic-gate switch (flag) { 29557c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_ADDED: 29567c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 29577c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 29587c478bd9Sstevel@tonic-gate /* Create a devctl minor node for the HCA's port */ 29597c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR, 29607c478bd9Sstevel@tonic-gate ddi_get_instance(ibnex.ibnex_dip), 29617c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 29627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to " 29637c478bd9Sstevel@tonic-gate "create minor node for port w/ guid %s", hca_guid); 29647c478bd9Sstevel@tonic-gate } 29657c478bd9Sstevel@tonic-gate 29667c478bd9Sstevel@tonic-gate break; 29677c478bd9Sstevel@tonic-gate 29687c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_REMOVED: 29697c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 29707c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 29717c478bd9Sstevel@tonic-gate ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid); 29727c478bd9Sstevel@tonic-gate break; 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate case IBDM_EVENT_IOC_PROP_UPDATE: 29757c478bd9Sstevel@tonic-gate ioc = ioc_list = (ibdm_ioc_info_t *)arg; 29767c478bd9Sstevel@tonic-gate if (ioc_list == NULL) 29777c478bd9Sstevel@tonic-gate break; 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 29807c478bd9Sstevel@tonic-gate while (ioc_list) { 29817c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present( 29827c478bd9Sstevel@tonic-gate IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL && 29837c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 29847c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_list); 29857c478bd9Sstevel@tonic-gate } 29867c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 29877c478bd9Sstevel@tonic-gate } 29887c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 29897c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 2990*dcf1eb70SSudhakar Dindukurti break; 2991*dcf1eb70SSudhakar Dindukurti 2992*dcf1eb70SSudhakar Dindukurti case IBDM_EVENT_PORT_UP: 2993*dcf1eb70SSudhakar Dindukurti case IBDM_EVENT_PORT_PKEY_CHANGE: 2994*dcf1eb70SSudhakar Dindukurti phci = ibtl_ibnex_hcaguid2dip(*(longlong_t *)arg); 2995*dcf1eb70SSudhakar Dindukurti devfs_clean(phci, NULL, 0); 2996*dcf1eb70SSudhakar Dindukurti break; 2997*dcf1eb70SSudhakar Dindukurti default: 2998*dcf1eb70SSudhakar Dindukurti break; 2999*dcf1eb70SSudhakar Dindukurti 30007c478bd9Sstevel@tonic-gate } 30017c478bd9Sstevel@tonic-gate } 30027c478bd9Sstevel@tonic-gate 30037c478bd9Sstevel@tonic-gate 30047c478bd9Sstevel@tonic-gate /* 30057c478bd9Sstevel@tonic-gate * ibnex_get_dip_from_guid() 30067c478bd9Sstevel@tonic-gate * 30077c478bd9Sstevel@tonic-gate * Searches the linked list of the port nodes and returns the dip for 30087c478bd9Sstevel@tonic-gate * the of the Port / Node guid requested. 30097c478bd9Sstevel@tonic-gate * Returns NULL if not found 30107c478bd9Sstevel@tonic-gate */ 30117c478bd9Sstevel@tonic-gate int 30127c478bd9Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey, 30137c478bd9Sstevel@tonic-gate dev_info_t **dip) 30147c478bd9Sstevel@tonic-gate { 30157c478bd9Sstevel@tonic-gate int node_index; 30167c478bd9Sstevel@tonic-gate ib_guid_t node_guid; 30177c478bd9Sstevel@tonic-gate ib_pkey_t node_pkey; 30187c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 30197c478bd9Sstevel@tonic-gate 30207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 30219d3d2ed0Shiremath "\tget_dip_from_guid: guid = %llX", guid); 30227c478bd9Sstevel@tonic-gate 30237c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 30247c478bd9Sstevel@tonic-gate /* Search for a matching entry in internal lists */ 30257c478bd9Sstevel@tonic-gate node_data = ibnex.ibnex_port_node_head; 30267c478bd9Sstevel@tonic-gate while (node_data) { 30277c478bd9Sstevel@tonic-gate node_guid = node_data->node_data.port_node.port_guid; 30287c478bd9Sstevel@tonic-gate node_index = node_data->node_data.port_node.port_commsvc_idx; 30297c478bd9Sstevel@tonic-gate node_pkey = node_data->node_data.port_node.port_pkey; 30307c478bd9Sstevel@tonic-gate if ((node_guid == guid) && (index == node_index) && 30317c478bd9Sstevel@tonic-gate (node_pkey == pkey)) { 30327c478bd9Sstevel@tonic-gate break; 30337c478bd9Sstevel@tonic-gate } 30347c478bd9Sstevel@tonic-gate node_data = node_data->node_next; 30357c478bd9Sstevel@tonic-gate } 30367c478bd9Sstevel@tonic-gate 30377c478bd9Sstevel@tonic-gate /* matching found with a valid dip */ 30387c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 30397c478bd9Sstevel@tonic-gate *dip = node_data->node_dip; 30407c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30417c478bd9Sstevel@tonic-gate } else if (node_data && !node_data->node_dip) { /* dip is invalid */ 30427c478bd9Sstevel@tonic-gate *dip = NULL; 30437c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30447c478bd9Sstevel@tonic-gate } 30457c478bd9Sstevel@tonic-gate 30467c478bd9Sstevel@tonic-gate /* no match found */ 30477c478bd9Sstevel@tonic-gate *dip = NULL; 30487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 30497c478bd9Sstevel@tonic-gate } 30507c478bd9Sstevel@tonic-gate 30517c478bd9Sstevel@tonic-gate 30527c478bd9Sstevel@tonic-gate /* 30537c478bd9Sstevel@tonic-gate * ibnex_comm_svc_init() 30547c478bd9Sstevel@tonic-gate * Read the property and cache the values in the global 30557c478bd9Sstevel@tonic-gate * structure. 30567c478bd9Sstevel@tonic-gate * Check for max allowed length (4 bytes) of service name 30577c478bd9Sstevel@tonic-gate * (each element of the property) 30587c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 30597c478bd9Sstevel@tonic-gate */ 30607c478bd9Sstevel@tonic-gate static ibnex_rval_t 30617c478bd9Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type) 30627c478bd9Sstevel@tonic-gate { 30637c478bd9Sstevel@tonic-gate int i, len, count; 30647c478bd9Sstevel@tonic-gate int ncomm_svcs; 30657c478bd9Sstevel@tonic-gate char **comm_svcp; 30667c478bd9Sstevel@tonic-gate char **servicep = NULL; 30677c478bd9Sstevel@tonic-gate uint_t nservices = 0; 30687c478bd9Sstevel@tonic-gate int *valid = NULL; 30697c478bd9Sstevel@tonic-gate 30707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x", 30717c478bd9Sstevel@tonic-gate property, type); 30727c478bd9Sstevel@tonic-gate 30737c478bd9Sstevel@tonic-gate /* lookup the string array property */ 30747c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip, 30757c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, property, &servicep, &nservices) != 30767c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 30777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property); 30787c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30797c478bd9Sstevel@tonic-gate } 30807c478bd9Sstevel@tonic-gate 30817c478bd9Sstevel@tonic-gate if (nservices) 30827c478bd9Sstevel@tonic-gate valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP); 30837c478bd9Sstevel@tonic-gate 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate /* first read the file to get a count of valid service entries */ 30867c478bd9Sstevel@tonic-gate for (ncomm_svcs = 0, count = 0; count < nservices; count++) { 30877c478bd9Sstevel@tonic-gate int j; 30887c478bd9Sstevel@tonic-gate 30897c478bd9Sstevel@tonic-gate len = strlen(servicep[count]); 309000a3eaf3SRamaswamy Tummala /* 309100a3eaf3SRamaswamy Tummala * ib.conf has NULL strings for port-svc-list & 309200a3eaf3SRamaswamy Tummala * hca-svc-list, by default. Do not have L2 message 309300a3eaf3SRamaswamy Tummala * for these. 309400a3eaf3SRamaswamy Tummala */ 309500a3eaf3SRamaswamy Tummala if (len == 1 || len > 4) { 30967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 309700a3eaf3SRamaswamy Tummala "Service name %s for property %s invalid : " 309800a3eaf3SRamaswamy Tummala "length %d", servicep[count], property, len); 309900a3eaf3SRamaswamy Tummala continue; 310000a3eaf3SRamaswamy Tummala } else if (len == 0) { 31017c478bd9Sstevel@tonic-gate continue; 31027c478bd9Sstevel@tonic-gate } 31037c478bd9Sstevel@tonic-gate if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) { 31047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 31057c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 31067c478bd9Sstevel@tonic-gate servicep[count]); 31077c478bd9Sstevel@tonic-gate continue; 31087c478bd9Sstevel@tonic-gate } 31097c478bd9Sstevel@tonic-gate 31107c478bd9Sstevel@tonic-gate /* 31117c478bd9Sstevel@tonic-gate * ibnex_unique_svcname checks for uniqueness in service names 31127c478bd9Sstevel@tonic-gate * communication services fully initialized. Check uniqueness 31137c478bd9Sstevel@tonic-gate * in service names currently initialized. 31147c478bd9Sstevel@tonic-gate */ 31157c478bd9Sstevel@tonic-gate for (j = 0; j < count; j++) 31167c478bd9Sstevel@tonic-gate if (valid[j] && strncmp(servicep[count], 31177c478bd9Sstevel@tonic-gate servicep[j], 4) == 0) { 31187c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 31197c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 31207c478bd9Sstevel@tonic-gate servicep[count]); 31217c478bd9Sstevel@tonic-gate continue; 31227c478bd9Sstevel@tonic-gate } 31237c478bd9Sstevel@tonic-gate 31247c478bd9Sstevel@tonic-gate valid[count] = 1; 31257c478bd9Sstevel@tonic-gate ncomm_svcs++; 31267c478bd9Sstevel@tonic-gate } 31277c478bd9Sstevel@tonic-gate 31287c478bd9Sstevel@tonic-gate /* if no valid entries found, bailout */ 31297c478bd9Sstevel@tonic-gate if (nservices == 0 || ncomm_svcs == 0) { 31307c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property); 31317c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); /* free the property */ 31327c478bd9Sstevel@tonic-gate if (valid) 31337c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 31347c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP); 31387c478bd9Sstevel@tonic-gate if (type == IBNEX_PORT_COMMSVC_NODE) { 31397c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = comm_svcp; 31407c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = ncomm_svcs; 31417c478bd9Sstevel@tonic-gate } else if (type == IBNEX_VPPA_COMMSVC_NODE) { 31427c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = comm_svcp; 31437c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs; 31447c478bd9Sstevel@tonic-gate } else if (type == IBNEX_HCASVC_COMMSVC_NODE) { 31457c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp; 31467c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs; 31477c478bd9Sstevel@tonic-gate } 31487c478bd9Sstevel@tonic-gate 31497c478bd9Sstevel@tonic-gate /* copy the services into an array of strings */ 31507c478bd9Sstevel@tonic-gate for (i = 0, count = 0; count < nservices; count++) { 31517c478bd9Sstevel@tonic-gate if (valid[count] == 0) /* Skip invalid ones */ 31527c478bd9Sstevel@tonic-gate continue; 31537c478bd9Sstevel@tonic-gate comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP); 31547c478bd9Sstevel@tonic-gate (void) strcpy(comm_svcp[i], servicep[count]); 31557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 31567c478bd9Sstevel@tonic-gate "\t\tService [%d]: %s", i, comm_svcp[i]); 31577c478bd9Sstevel@tonic-gate ++i; 31587c478bd9Sstevel@tonic-gate } 31597c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); 31607c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 31617c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 31627c478bd9Sstevel@tonic-gate } 31637c478bd9Sstevel@tonic-gate 31647c478bd9Sstevel@tonic-gate 31657c478bd9Sstevel@tonic-gate /* 31667c478bd9Sstevel@tonic-gate * ibnex_comm_svc_fini() 31677c478bd9Sstevel@tonic-gate * Deallocate all the memory allocated for the communication 31687c478bd9Sstevel@tonic-gate * service arrays. 31697c478bd9Sstevel@tonic-gate */ 31707c478bd9Sstevel@tonic-gate static void 31717c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini() 31727c478bd9Sstevel@tonic-gate { 31737c478bd9Sstevel@tonic-gate int index; 31747c478bd9Sstevel@tonic-gate 31757c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) { 31767c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names[index], 31777c478bd9Sstevel@tonic-gate (strlen(ibnex.ibnex_comm_svc_names[index]) + 1)); 31787c478bd9Sstevel@tonic-gate } 31797c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names) { 31807c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names, 31817c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs * sizeof (char *)); 31827c478bd9Sstevel@tonic-gate } 31837c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 31847c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names[index], 31857c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1); 31867c478bd9Sstevel@tonic-gate } 31877c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names) { 31887c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names, 31897c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs * sizeof (char *)); 31907c478bd9Sstevel@tonic-gate } 31917c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) { 31927c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index], 31937c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1); 31947c478bd9Sstevel@tonic-gate } 31957c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names) { 31967c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names, 31977c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *)); 31987c478bd9Sstevel@tonic-gate } 31997c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = NULL; 32007c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = 0; 32017c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = NULL; 32027c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = 0; 32037c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = NULL; 32047c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = 0; 32057c478bd9Sstevel@tonic-gate } 32067c478bd9Sstevel@tonic-gate 32077c478bd9Sstevel@tonic-gate 32087c478bd9Sstevel@tonic-gate /* 32097c478bd9Sstevel@tonic-gate * ibnex_commsvc_initnode() 32107c478bd9Sstevel@tonic-gate * This routine is specific to port/VPPA node creation 32117c478bd9Sstevel@tonic-gate * Creates a device node for the comm service specified by commsvc_index 32127c478bd9Sstevel@tonic-gate * Creates all the device node properties 32137c478bd9Sstevel@tonic-gate * Allocates and initializes the node specific data 32147c478bd9Sstevel@tonic-gate * Binds the device driver of the device node 32157c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the child node or NULL in case of failure 32167c478bd9Sstevel@tonic-gate * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect 32177c478bd9Sstevel@tonic-gate * if the operation was successful, failed or was not performed. 32187c478bd9Sstevel@tonic-gate */ 32197c478bd9Sstevel@tonic-gate dev_info_t * 32207c478bd9Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr, 32217c478bd9Sstevel@tonic-gate int index, int node_type, ib_pkey_t pkey, int *rval, int flag) 32227c478bd9Sstevel@tonic-gate { 32237c478bd9Sstevel@tonic-gate int ret; 32247c478bd9Sstevel@tonic-gate char *svcname; 32257c478bd9Sstevel@tonic-gate dev_info_t *cdip; 32267c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 322700a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 322800a3eaf3SRamaswamy Tummala char devname[MAXNAMELEN]; 322951f34d4bSRajkumar Sivaprakasam int cdip_allocated = 0; 32307c478bd9Sstevel@tonic-gate 32317c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 32327c478bd9Sstevel@tonic-gate 32337c478bd9Sstevel@tonic-gate *rval = IBNEX_SUCCESS; 32347c478bd9Sstevel@tonic-gate 32357c478bd9Sstevel@tonic-gate /* 32367c478bd9Sstevel@tonic-gate * prevent any races 32377c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized 32387c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 32397c478bd9Sstevel@tonic-gate * progress. 32407c478bd9Sstevel@tonic-gate */ 32417c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(node_type, (void *)port_attr, 32427c478bd9Sstevel@tonic-gate index, pkey); 324300a3eaf3SRamaswamy Tummala 324400a3eaf3SRamaswamy Tummala /* 324500a3eaf3SRamaswamy Tummala * If this node has been explicity unconfigured by cfgadm, then it can 324600a3eaf3SRamaswamy Tummala * be configured back again only by cfgadm configure. 324700a3eaf3SRamaswamy Tummala */ 324800a3eaf3SRamaswamy Tummala if (node_data && (node_data->node_ap_state == 324900a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED)) { 325000a3eaf3SRamaswamy Tummala *rval = IBNEX_FAILURE; 325100a3eaf3SRamaswamy Tummala return (NULL); 325200a3eaf3SRamaswamy Tummala } 325300a3eaf3SRamaswamy Tummala 32547c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 32557c478bd9Sstevel@tonic-gate /* 32567c478bd9Sstevel@tonic-gate * Return NULL if another configure 32577c478bd9Sstevel@tonic-gate * operation is in progress 32587c478bd9Sstevel@tonic-gate */ 32597c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) { 32607c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 32617c478bd9Sstevel@tonic-gate return (NULL); 32627c478bd9Sstevel@tonic-gate } else { 32637c478bd9Sstevel@tonic-gate return (node_data->node_dip); 32647c478bd9Sstevel@tonic-gate } 32657c478bd9Sstevel@tonic-gate } else if (node_data == NULL) { 32667c478bd9Sstevel@tonic-gate /* allocate a new ibnex_node_data_t */ 32677c478bd9Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(node_type, port_attr, 32687c478bd9Sstevel@tonic-gate index, pkey); 326900a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 32707c478bd9Sstevel@tonic-gate } 32717c478bd9Sstevel@tonic-gate 32727c478bd9Sstevel@tonic-gate /* 32737c478bd9Sstevel@tonic-gate * Return NULL if another unconfigure operation is in progress 32747c478bd9Sstevel@tonic-gate */ 32757c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 32767c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 32777c478bd9Sstevel@tonic-gate return (NULL); 32787c478bd9Sstevel@tonic-gate } 32797c478bd9Sstevel@tonic-gate 32807c478bd9Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED); 32817c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 32827c478bd9Sstevel@tonic-gate 32837c478bd9Sstevel@tonic-gate switch (node_type) { 32847c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE : 32857c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_vppa_comm_svc_names[index]; 328600a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 328700a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s", 328800a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, 328900a3eaf3SRamaswamy Tummala port_node->port_pkey, svcname); 32907c478bd9Sstevel@tonic-gate break; 32917c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE : 32927c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_hcasvc_comm_svc_names[index]; 329300a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 329400a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 329500a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 32967c478bd9Sstevel@tonic-gate break; 32977c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE : 32987c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_comm_svc_names[index]; 329900a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 330000a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 330100a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate default : 33047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:" 33057c478bd9Sstevel@tonic-gate "\tInvalid Node type"); 33067c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 33077c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(node_data); 33087c478bd9Sstevel@tonic-gate return (NULL); 33097c478bd9Sstevel@tonic-gate } 33107c478bd9Sstevel@tonic-gate 331100a3eaf3SRamaswamy Tummala if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) { 331200a3eaf3SRamaswamy Tummala if (i_ddi_devi_attached(cdip)) { 331300a3eaf3SRamaswamy Tummala node_data->node_dip = cdip; 331400a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 331500a3eaf3SRamaswamy Tummala node_data->node_state = IBNEX_CFGADM_CONFIGURED; 331600a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data); 331751f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found " 331851f34d4bSRajkumar Sivaprakasam "attached cdip 0x%p for devname %s", cdip, devname); 331900a3eaf3SRamaswamy Tummala return (cdip); 332000a3eaf3SRamaswamy Tummala } 332100a3eaf3SRamaswamy Tummala } else { 332200a3eaf3SRamaswamy Tummala ndi_devi_alloc_sleep(parent, 332300a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip); 332451f34d4bSRajkumar Sivaprakasam cdip_allocated = 1; 332500a3eaf3SRamaswamy Tummala } 332600a3eaf3SRamaswamy Tummala 332700a3eaf3SRamaswamy Tummala node_data->node_dip = cdip; 332800a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data); 332900a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex); 333000a3eaf3SRamaswamy Tummala 333100a3eaf3SRamaswamy Tummala 33327c478bd9Sstevel@tonic-gate if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) == 33337c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 33347c478bd9Sstevel@tonic-gate if (flag == IBNEX_DEVFS_ENUMERATE) 33357c478bd9Sstevel@tonic-gate ret = ndi_devi_bind_driver(cdip, 0); 33367c478bd9Sstevel@tonic-gate else 33377c478bd9Sstevel@tonic-gate ret = ndi_devi_online(cdip, 0); 33387c478bd9Sstevel@tonic-gate if (ret == NDI_SUCCESS) { 33397c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 33407c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 334100a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 33427c478bd9Sstevel@tonic-gate return (cdip); 33437c478bd9Sstevel@tonic-gate } 334451f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE " 334551f34d4bSRajkumar Sivaprakasam "of cdip 0x%p for devname %s and flag %d failed", cdip, 334651f34d4bSRajkumar Sivaprakasam devname, flag); 33477c478bd9Sstevel@tonic-gate } 334800a3eaf3SRamaswamy Tummala 33497c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 335051f34d4bSRajkumar Sivaprakasam node_data->node_dip = NULL; 335151f34d4bSRajkumar Sivaprakasam ddi_set_parent_data(cdip, NULL); 335251f34d4bSRajkumar Sivaprakasam if (cdip_allocated) 33537c478bd9Sstevel@tonic-gate (void) ndi_devi_free(cdip); 33547c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 33557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit"); 33567c478bd9Sstevel@tonic-gate return (NULL); 33577c478bd9Sstevel@tonic-gate } 33587c478bd9Sstevel@tonic-gate 33597c478bd9Sstevel@tonic-gate 33607c478bd9Sstevel@tonic-gate /* 33617c478bd9Sstevel@tonic-gate * ibnex_create_port_node_prop() 33627c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 33637c478bd9Sstevel@tonic-gate */ 33647c478bd9Sstevel@tonic-gate static int 33657c478bd9Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr, 33667c478bd9Sstevel@tonic-gate dev_info_t *child_dip, char *srvname, ib_pkey_t pkey) 33677c478bd9Sstevel@tonic-gate { 33687c478bd9Sstevel@tonic-gate if (ibnex_create_port_compatible_prop(child_dip, 33697c478bd9Sstevel@tonic-gate srvname, port_attr) != DDI_PROP_SUCCESS) { 33707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33717c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: compatible update failed"); 33727c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33737c478bd9Sstevel@tonic-gate } 33747c478bd9Sstevel@tonic-gate if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33757c478bd9Sstevel@tonic-gate "port-pkey", pkey) != DDI_PROP_SUCCESS)) { 33767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33777c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 33787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33797c478bd9Sstevel@tonic-gate } 33807c478bd9Sstevel@tonic-gate 33817c478bd9Sstevel@tonic-gate /* 33827c478bd9Sstevel@tonic-gate * For HCA_SVC device nodes, port_num will be 0. 33837c478bd9Sstevel@tonic-gate * Do not create the "port-number" & "port-guid" properties. 33847c478bd9Sstevel@tonic-gate */ 33857c478bd9Sstevel@tonic-gate if (port_attr->pa_port_num != 0) { 33867c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33877c478bd9Sstevel@tonic-gate "port-number", port_attr->pa_port_num) != 33887c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 33897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33907c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 33917c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33927c478bd9Sstevel@tonic-gate } 33937c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 33947c478bd9Sstevel@tonic-gate "port-guid", port_attr->pa_port_guid) != 33957c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 33967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33977c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guid update failed"); 33987c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33997c478bd9Sstevel@tonic-gate } 34007c478bd9Sstevel@tonic-gate } else { 34017c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 34027c478bd9Sstevel@tonic-gate 34037c478bd9Sstevel@tonic-gate /* 34047c478bd9Sstevel@tonic-gate * HCA_SVC nodes require "num-ports" & "port-guids" 34057c478bd9Sstevel@tonic-gate * properties. 34067c478bd9Sstevel@tonic-gate * 34077c478bd9Sstevel@tonic-gate * To create the num-ports & port-guids attribute : 34087c478bd9Sstevel@tonic-gate * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid) 34097c478bd9Sstevel@tonic-gate * 2. Form the array of port GUIDs. 34107c478bd9Sstevel@tonic-gate */ 34117c478bd9Sstevel@tonic-gate if ((hca_list = ibdm_ibnex_get_hca_info_by_guid( 34127c478bd9Sstevel@tonic-gate port_attr->pa_hca_guid)) == NULL) { 34137c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34147c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca_info_by_guid failed"); 34157c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34167c478bd9Sstevel@tonic-gate } 34177c478bd9Sstevel@tonic-gate 34187c478bd9Sstevel@tonic-gate if (hca_list->hl_nports != 0) { 34197c478bd9Sstevel@tonic-gate ib_guid_t *port_guids; 34207c478bd9Sstevel@tonic-gate uint8_t portnum; 34217c478bd9Sstevel@tonic-gate 34227c478bd9Sstevel@tonic-gate ASSERT(hca_list->hl_port_attr != NULL); 34237c478bd9Sstevel@tonic-gate 34247c478bd9Sstevel@tonic-gate port_guids = kmem_zalloc( 34257c478bd9Sstevel@tonic-gate hca_list->hl_nports * sizeof (ib_guid_t), 34267c478bd9Sstevel@tonic-gate KM_SLEEP); 34277c478bd9Sstevel@tonic-gate 34287c478bd9Sstevel@tonic-gate for (portnum = 0; portnum < hca_list->hl_nports; 34297c478bd9Sstevel@tonic-gate portnum++) { 34307c478bd9Sstevel@tonic-gate port_guids[portnum] = (hca_list-> 34317c478bd9Sstevel@tonic-gate hl_port_attr[portnum]).pa_port_guid; 34327c478bd9Sstevel@tonic-gate } 34337c478bd9Sstevel@tonic-gate 34347c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, 34357c478bd9Sstevel@tonic-gate child_dip, "port-guids", (int64_t *)port_guids, 34367c478bd9Sstevel@tonic-gate hca_list->hl_nports) != DDI_PROP_SUCCESS) { 34377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34387c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guids " 34397c478bd9Sstevel@tonic-gate "create failed"); 34407c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 34417c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 34427c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34437c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34447c478bd9Sstevel@tonic-gate } 34457c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 34467c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 34477c478bd9Sstevel@tonic-gate } 34487c478bd9Sstevel@tonic-gate 34497c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34507c478bd9Sstevel@tonic-gate "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) { 34517c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34527c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: num-ports update failed"); 34537c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34547c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34557c478bd9Sstevel@tonic-gate } 34567c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34577c478bd9Sstevel@tonic-gate } 34587c478bd9Sstevel@tonic-gate 34597c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 34607c478bd9Sstevel@tonic-gate "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) { 34617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34627c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca-guid update failed"); 34637c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34647c478bd9Sstevel@tonic-gate } 34657c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34667c478bd9Sstevel@tonic-gate "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) { 34677c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34687c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: product-id update failed"); 34697c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34707c478bd9Sstevel@tonic-gate } 34717c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34727c478bd9Sstevel@tonic-gate "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) { 34737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34747c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: vendor-id update failed"); 34757c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34767c478bd9Sstevel@tonic-gate } 34777c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version", 34787c478bd9Sstevel@tonic-gate port_attr->pa_dev_version) != DDI_PROP_SUCCESS) { 34797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34807c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: device-version update failed"); 34817c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34827c478bd9Sstevel@tonic-gate } 34837c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 34847c478bd9Sstevel@tonic-gate } 34857c478bd9Sstevel@tonic-gate 34867c478bd9Sstevel@tonic-gate 34877c478bd9Sstevel@tonic-gate /* 34887c478bd9Sstevel@tonic-gate * ibnex_str2int() 34897c478bd9Sstevel@tonic-gate * Utility function that converts a string of length "len" to 34907c478bd9Sstevel@tonic-gate * integer. 34917c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 34927c478bd9Sstevel@tonic-gate */ 34937c478bd9Sstevel@tonic-gate static int 34947c478bd9Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret) 34957c478bd9Sstevel@tonic-gate { 34967c478bd9Sstevel@tonic-gate int intval = 0, ii; 34977c478bd9Sstevel@tonic-gate 34987c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c); 34997c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 35007c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 35017c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 35027c478bd9Sstevel@tonic-gate intval = intval * 10 +c[ii] - '0'; 35037c478bd9Sstevel@tonic-gate else { 35047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 35057c478bd9Sstevel@tonic-gate "\tstr2int: Invalid integer string %s..", c); 35067c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 35077c478bd9Sstevel@tonic-gate break; 35087c478bd9Sstevel@tonic-gate } 35097c478bd9Sstevel@tonic-gate } 35107c478bd9Sstevel@tonic-gate 35117c478bd9Sstevel@tonic-gate return (intval); 35127c478bd9Sstevel@tonic-gate } 35137c478bd9Sstevel@tonic-gate 35147c478bd9Sstevel@tonic-gate 35157c478bd9Sstevel@tonic-gate /* 35167c478bd9Sstevel@tonic-gate * ibnex_str2hex() 35177c478bd9Sstevel@tonic-gate * Utility functions that converts a string of length "len" to 35187c478bd9Sstevel@tonic-gate * hex value. Note. This function does not handle strings which 35197c478bd9Sstevel@tonic-gate * string length more than 8 bytes. 35207c478bd9Sstevel@tonic-gate * 35217c478bd9Sstevel@tonic-gate */ 35227c478bd9Sstevel@tonic-gate uint64_t 35237c478bd9Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret) 35247c478bd9Sstevel@tonic-gate { 35257c478bd9Sstevel@tonic-gate uint64_t hex = 0, ii; 35267c478bd9Sstevel@tonic-gate 35277c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 35287c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 35297c478bd9Sstevel@tonic-gate hex = (ii == 0) ? hex : (hex << 4); 35307c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 35317c478bd9Sstevel@tonic-gate hex |= c[ii] - '0'; 35327c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'a') && (c[ii] <= 'f')) 35337c478bd9Sstevel@tonic-gate hex |= c[ii] - 'a' + 10; 35347c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'A') && (c[ii] <= 'F')) 35357c478bd9Sstevel@tonic-gate hex |= c[ii] - 'A' + 10; 35367c478bd9Sstevel@tonic-gate else { 35377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 35387c478bd9Sstevel@tonic-gate "\tstr2hex: Invalid integer string"); 35397c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 35407c478bd9Sstevel@tonic-gate break; 35417c478bd9Sstevel@tonic-gate } 35427c478bd9Sstevel@tonic-gate } 35437c478bd9Sstevel@tonic-gate 35447c478bd9Sstevel@tonic-gate return (hex); 35457c478bd9Sstevel@tonic-gate } 35467c478bd9Sstevel@tonic-gate 35477c478bd9Sstevel@tonic-gate 35487c478bd9Sstevel@tonic-gate /* 35497c478bd9Sstevel@tonic-gate * ibnex_create_port_compatible_prop() 35507c478bd9Sstevel@tonic-gate * Creates 'Compatibility' property for port / HCA_SVC device nodes 35517c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 35527c478bd9Sstevel@tonic-gate */ 35537c478bd9Sstevel@tonic-gate static int 35547c478bd9Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip, 35557c478bd9Sstevel@tonic-gate char *comm_svcp, ibdm_port_attr_t *port_attr) 35567c478bd9Sstevel@tonic-gate { 35577c478bd9Sstevel@tonic-gate int rval, i; 35587c478bd9Sstevel@tonic-gate char *temp; 35597c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES]; 35607c478bd9Sstevel@tonic-gate 35617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin"); 35627c478bd9Sstevel@tonic-gate /* 35637c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 35647c478bd9Sstevel@tonic-gate * Compatible Strings : 35657c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>v<revision>.<service name>. 35667c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>.<service name>. 35677c478bd9Sstevel@tonic-gate * 3. ib.<service name> 35687c478bd9Sstevel@tonic-gate * Leading zeros must be present 35697c478bd9Sstevel@tonic-gate */ 35707c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP); 35717c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) { 35727c478bd9Sstevel@tonic-gate compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN); 35737c478bd9Sstevel@tonic-gate } 35747c478bd9Sstevel@tonic-gate 35757c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 35767c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x.%s", 35777c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 35787c478bd9Sstevel@tonic-gate port_attr->pa_dev_version, comm_svcp); 35797c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 35807c478bd9Sstevel@tonic-gate "ib.V%06xP%08x.%s", 35817c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 35827c478bd9Sstevel@tonic-gate comm_svcp); 35837c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 35847c478bd9Sstevel@tonic-gate "ib.%s", comm_svcp); 35857c478bd9Sstevel@tonic-gate 35867c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) 35877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]); 35887c478bd9Sstevel@tonic-gate 35897c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 35907c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES); 35917c478bd9Sstevel@tonic-gate 35927c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 35937c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 35947c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 35957c478bd9Sstevel@tonic-gate } 35967c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 35977c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 35987c478bd9Sstevel@tonic-gate } 35997c478bd9Sstevel@tonic-gate 36007c478bd9Sstevel@tonic-gate 36017c478bd9Sstevel@tonic-gate /* 36027c478bd9Sstevel@tonic-gate * ibnex_delete_port_node_data() 36037c478bd9Sstevel@tonic-gate * Delete the parent private node data from the linked list 36047c478bd9Sstevel@tonic-gate * Deallocate the memory of the port/ioc attributes 36057c478bd9Sstevel@tonic-gate * Deallocate the memory of the node data 36067c478bd9Sstevel@tonic-gate */ 36077c478bd9Sstevel@tonic-gate static void 36087c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node) 36097c478bd9Sstevel@tonic-gate { 36107c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) 36117c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = NULL; 36127c478bd9Sstevel@tonic-gate else if (node->node_next == NULL) 36137c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 36147c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 36157c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 36167c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node->node_next; 36177c478bd9Sstevel@tonic-gate } else { 36187c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 36197c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 36207c478bd9Sstevel@tonic-gate } 36217c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 36227c478bd9Sstevel@tonic-gate } 36237c478bd9Sstevel@tonic-gate 36247c478bd9Sstevel@tonic-gate 36257c478bd9Sstevel@tonic-gate /* 36267c478bd9Sstevel@tonic-gate * ibnex_is_node_data_present() 36277c478bd9Sstevel@tonic-gate * Checks whether ibnex_node_t is created already 36287c478bd9Sstevel@tonic-gate * Returns ibnex_node_data_t if found, otherwise NULL 36297c478bd9Sstevel@tonic-gate */ 36307c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 36317c478bd9Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr, 36327c478bd9Sstevel@tonic-gate int index, ib_pkey_t pkey) 36337c478bd9Sstevel@tonic-gate { 36347c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 36357c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 36367c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 36377c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr; 36387c478bd9Sstevel@tonic-gate 36397c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL; 36407c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 36417c478bd9Sstevel@tonic-gate if (nodep->node_data.ioc_node.ioc_guid == 36427c478bd9Sstevel@tonic-gate ioc_infop->ioc_profile.ioc_guid) { 36437c478bd9Sstevel@tonic-gate return (nodep); 36447c478bd9Sstevel@tonic-gate } 36457c478bd9Sstevel@tonic-gate } 36467c478bd9Sstevel@tonic-gate 36477c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 36487c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 36497c478bd9Sstevel@tonic-gate nodep = nodep->node_next) 36507c478bd9Sstevel@tonic-gate if (strcmp(nodep->node_data.pseudo_node. 36517c478bd9Sstevel@tonic-gate pseudo_node_addr, (char *)attr) == 0) 36527c478bd9Sstevel@tonic-gate return (nodep); 36537c478bd9Sstevel@tonic-gate 36547c478bd9Sstevel@tonic-gate } else { 36557c478bd9Sstevel@tonic-gate ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr; 36567c478bd9Sstevel@tonic-gate 36577c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_port_node_head; nodep != NULL; 36587c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 36597c478bd9Sstevel@tonic-gate if ((nodep->node_data.port_node.port_guid == 36607c478bd9Sstevel@tonic-gate pattrp->pa_port_guid) && 36617c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_commsvc_idx == 36627c478bd9Sstevel@tonic-gate index) && 36637c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_pkey == pkey)) { 36647c478bd9Sstevel@tonic-gate return (nodep); 36657c478bd9Sstevel@tonic-gate } 36667c478bd9Sstevel@tonic-gate } 36677c478bd9Sstevel@tonic-gate } 36687c478bd9Sstevel@tonic-gate return (NULL); 36697c478bd9Sstevel@tonic-gate } 36707c478bd9Sstevel@tonic-gate 36717c478bd9Sstevel@tonic-gate /* 36727c478bd9Sstevel@tonic-gate * ibnex_lookup_unit_address_prop: 36737c478bd9Sstevel@tonic-gate * 36749d3d2ed0Shiremath * If property with name is found, return its value 36757c478bd9Sstevel@tonic-gate * otherwise return NULL. 36767c478bd9Sstevel@tonic-gate */ 36777c478bd9Sstevel@tonic-gate static char * 36789d3d2ed0Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name) 36797c478bd9Sstevel@tonic-gate { 36807c478bd9Sstevel@tonic-gate ddi_prop_t *propp; 36817c478bd9Sstevel@tonic-gate 36829d3d2ed0Shiremath /* Search the list of properties for name */ 36837c478bd9Sstevel@tonic-gate for (propp = head; propp != NULL; propp = propp->prop_next) { 36849d3d2ed0Shiremath if (strcmp(propp->prop_name, name) != 0) 36857c478bd9Sstevel@tonic-gate continue; 36869d3d2ed0Shiremath /* named property should be valid and have a value */ 36877c478bd9Sstevel@tonic-gate if (propp->prop_len <= 1) 36887c478bd9Sstevel@tonic-gate break; 36897c478bd9Sstevel@tonic-gate return ((char *)propp->prop_val); 36907c478bd9Sstevel@tonic-gate } 36917c478bd9Sstevel@tonic-gate 36927c478bd9Sstevel@tonic-gate return ((char *)0); 36937c478bd9Sstevel@tonic-gate } 36947c478bd9Sstevel@tonic-gate 36957c478bd9Sstevel@tonic-gate 36967c478bd9Sstevel@tonic-gate /* 36977c478bd9Sstevel@tonic-gate * ibnex_pseudo_initnodes() 36987c478bd9Sstevel@tonic-gate * This routine is specific to pseudo node information handling 36997c478bd9Sstevel@tonic-gate * Creates a ibnex_node_data_t all pseudo nodes children of ibnex 37007c478bd9Sstevel@tonic-gate */ 37017c478bd9Sstevel@tonic-gate void 37027c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes() 37037c478bd9Sstevel@tonic-gate { 37047c478bd9Sstevel@tonic-gate int pnam_len, len; 37057c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 37067c478bd9Sstevel@tonic-gate struct hwc_spec *list, *spec; 37077c478bd9Sstevel@tonic-gate char *node_addr, *temp, *unit_addr; 37089d3d2ed0Shiremath char *node_type; 37097c478bd9Sstevel@tonic-gate 37107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes"); 37117c478bd9Sstevel@tonic-gate 37127c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37137c478bd9Sstevel@tonic-gate /* 37147c478bd9Sstevel@tonic-gate * get a list of all "pseudo" children of "ib". 37157c478bd9Sstevel@tonic-gate * for these children initialize/allocate an internal 37167c478bd9Sstevel@tonic-gate * ibnex_node_data_t. 37177c478bd9Sstevel@tonic-gate */ 37187c478bd9Sstevel@tonic-gate list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1); 37197c478bd9Sstevel@tonic-gate for (spec = list; spec != NULL; spec = spec->hwc_next) { 37207c478bd9Sstevel@tonic-gate if (spec->hwc_devi_sys_prop_ptr == NULL) 37217c478bd9Sstevel@tonic-gate continue; 37227c478bd9Sstevel@tonic-gate 37239d3d2ed0Shiremath /* Check "ib-node-type" property for IOC .conf */ 37249d3d2ed0Shiremath node_type = ibnex_lookup_named_prop( 37259d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "ib-node-type"); 37269d3d2ed0Shiremath 37277c478bd9Sstevel@tonic-gate /* "unit-address" property should be present */ 37289d3d2ed0Shiremath temp = ibnex_lookup_named_prop( 37299d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "unit-address"); 37307c478bd9Sstevel@tonic-gate if (temp == NULL) 37317c478bd9Sstevel@tonic-gate continue; 37327c478bd9Sstevel@tonic-gate 37337c478bd9Sstevel@tonic-gate pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2; 37347c478bd9Sstevel@tonic-gate 37357c478bd9Sstevel@tonic-gate node_addr = kmem_zalloc(pnam_len, KM_SLEEP); 37367c478bd9Sstevel@tonic-gate 37377c478bd9Sstevel@tonic-gate (void) snprintf(node_addr, 37387c478bd9Sstevel@tonic-gate pnam_len, "%s,%s", spec->hwc_devi_name, temp); 37397c478bd9Sstevel@tonic-gate 37407c478bd9Sstevel@tonic-gate nodep = ibnex_is_node_data_present( 37417c478bd9Sstevel@tonic-gate IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0); 37427c478bd9Sstevel@tonic-gate 37437c478bd9Sstevel@tonic-gate if (nodep) { 37447c478bd9Sstevel@tonic-gate kmem_free(node_addr, pnam_len); 37457c478bd9Sstevel@tonic-gate continue; 37467c478bd9Sstevel@tonic-gate } 37477c478bd9Sstevel@tonic-gate 37487c478bd9Sstevel@tonic-gate nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE, 37497c478bd9Sstevel@tonic-gate (void *)spec->hwc_devi_name, 0, 0); 37507c478bd9Sstevel@tonic-gate 37517c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_node_addr = node_addr; 37527c478bd9Sstevel@tonic-gate (void) snprintf(nodep->node_data. 37537c478bd9Sstevel@tonic-gate pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr); 37547c478bd9Sstevel@tonic-gate 37557c478bd9Sstevel@tonic-gate len = strlen(temp) + 1; 37567c478bd9Sstevel@tonic-gate unit_addr = (char *)kmem_alloc(len, KM_SLEEP); 37577c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr; 37587c478bd9Sstevel@tonic-gate (void) snprintf(unit_addr, len, "%s", temp); 37597c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr_len = len; 37607c478bd9Sstevel@tonic-gate 37619d3d2ed0Shiremath if (node_type && strcmp(node_type, "merge") == 0) 37629d3d2ed0Shiremath nodep->node_data.pseudo_node.pseudo_merge_node = 1; 37639d3d2ed0Shiremath 37647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s" 37657c478bd9Sstevel@tonic-gate " : drv name = %s", unit_addr, spec->hwc_devi_name); 37667c478bd9Sstevel@tonic-gate } 37677c478bd9Sstevel@tonic-gate hwc_free_spec_list(list); 37687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37697c478bd9Sstevel@tonic-gate } 37707c478bd9Sstevel@tonic-gate 37717c478bd9Sstevel@tonic-gate 37727c478bd9Sstevel@tonic-gate /* 37737c478bd9Sstevel@tonic-gate * ibnex_init_child_nodedata() 37747c478bd9Sstevel@tonic-gate * 37757c478bd9Sstevel@tonic-gate * Allocate memory for the parent private data for device node 37767c478bd9Sstevel@tonic-gate * Initializes the parent private child device node data. 37777c478bd9Sstevel@tonic-gate * Returns pointer to the parent private data 37787c478bd9Sstevel@tonic-gate */ 37797c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 37807c478bd9Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index, 37817c478bd9Sstevel@tonic-gate ib_pkey_t pkey) 37827c478bd9Sstevel@tonic-gate { 37837c478bd9Sstevel@tonic-gate char *devi_name; 37847c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 37857c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_node; 37867c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 37877c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile; 37887c478bd9Sstevel@tonic-gate 37897c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 37907c478bd9Sstevel@tonic-gate 37917c478bd9Sstevel@tonic-gate node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP); 379200a3eaf3SRamaswamy Tummala node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED; 37937c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 37947c478bd9Sstevel@tonic-gate node_data->node_type = node_type; 37957c478bd9Sstevel@tonic-gate 37967c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 37977c478bd9Sstevel@tonic-gate ioc_info = (ibdm_ioc_info_t *)attr; 37987c478bd9Sstevel@tonic-gate ioc_profile = &ioc_info->ioc_profile; 37997c478bd9Sstevel@tonic-gate ioc_node = &node_data->node_data.ioc_node; 38007c478bd9Sstevel@tonic-gate 38017c478bd9Sstevel@tonic-gate ioc_node->iou_guid = ioc_info->ioc_iou_guid; 38027c478bd9Sstevel@tonic-gate ioc_node->ioc_guid = ioc_profile->ioc_guid; 38037c478bd9Sstevel@tonic-gate (void) strncpy(ioc_node->ioc_id_string, 38047c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string, 38057c478bd9Sstevel@tonic-gate IB_DM_IOC_ID_STRING_LEN); 38067c478bd9Sstevel@tonic-gate ioc_node->ioc_ngids = ioc_info->ioc_nportgids; 38077c478bd9Sstevel@tonic-gate 38087c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_ioc_node_head; 38097c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 38107c478bd9Sstevel@tonic-gate if (ibnex.ibnex_ioc_node_head) 38117c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head->node_prev = node_data; 38127c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node_data; 38137c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 38147c478bd9Sstevel@tonic-gate devi_name = (char *)attr; 38157c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_devi_name = 38167c478bd9Sstevel@tonic-gate kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP); 38177c478bd9Sstevel@tonic-gate (void) strncpy(node_data->node_data.pseudo_node. 38187c478bd9Sstevel@tonic-gate pseudo_devi_name, devi_name, strlen(devi_name)); 38197c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_pseudo_node_head; 38207c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 38217c478bd9Sstevel@tonic-gate if (ibnex.ibnex_pseudo_node_head) 38227c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head->node_prev = node_data; 38237c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head = node_data; 38247c478bd9Sstevel@tonic-gate } else { 38257c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_hcaguid = 38267c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_hca_guid; 38277c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_guid = 38287c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_guid; 38297c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_num = 38307c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_num; 38317c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_commsvc_idx = index; 38327c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_pkey = pkey; 38337c478bd9Sstevel@tonic-gate 38347c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_port_node_head; 38357c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 38367c478bd9Sstevel@tonic-gate if (ibnex.ibnex_port_node_head) 38377c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head->node_prev = node_data; 38387c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node_data; 38397c478bd9Sstevel@tonic-gate } 38407c478bd9Sstevel@tonic-gate return (node_data); 38417c478bd9Sstevel@tonic-gate } 38427c478bd9Sstevel@tonic-gate 38437c478bd9Sstevel@tonic-gate static int 38447c478bd9Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, 38457c478bd9Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *cookie) 38467c478bd9Sstevel@tonic-gate { 38477c478bd9Sstevel@tonic-gate int rc; 38487c478bd9Sstevel@tonic-gate 38497c478bd9Sstevel@tonic-gate 38507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)", 38517c478bd9Sstevel@tonic-gate dip, rdip, eventname, cookie); 38527c478bd9Sstevel@tonic-gate 38537c478bd9Sstevel@tonic-gate rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl, 38547c478bd9Sstevel@tonic-gate rdip, eventname, cookie, NDI_EVENT_NOPASS); 38557c478bd9Sstevel@tonic-gate if (rc == NDI_SUCCESS) { 38567c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38577c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = *cookie; 38587c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38597c478bd9Sstevel@tonic-gate } 38607c478bd9Sstevel@tonic-gate 38617c478bd9Sstevel@tonic-gate return (rc); 38627c478bd9Sstevel@tonic-gate } 38637c478bd9Sstevel@tonic-gate 38647c478bd9Sstevel@tonic-gate static int 38657c478bd9Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 38667c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip, 38677c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *arg, void *bus_impldata), 38687c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id) 38697c478bd9Sstevel@tonic-gate { 38707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 38717c478bd9Sstevel@tonic-gate "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)", 38727c478bd9Sstevel@tonic-gate dip, rdip, cookie, callback, arg, cb_id); 38737c478bd9Sstevel@tonic-gate 38747c478bd9Sstevel@tonic-gate return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl, 38757c478bd9Sstevel@tonic-gate rdip, cookie, callback, arg, NDI_SLEEP, cb_id)); 38767c478bd9Sstevel@tonic-gate } 38777c478bd9Sstevel@tonic-gate 38787c478bd9Sstevel@tonic-gate static int 38797c478bd9Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) 38807c478bd9Sstevel@tonic-gate { 38817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)", 38827c478bd9Sstevel@tonic-gate dip, cb_id); 38837c478bd9Sstevel@tonic-gate 38847c478bd9Sstevel@tonic-gate return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl, 38857c478bd9Sstevel@tonic-gate cb_id)); 38867c478bd9Sstevel@tonic-gate } 38877c478bd9Sstevel@tonic-gate 38887c478bd9Sstevel@tonic-gate static int 38897c478bd9Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip, 38907c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata) 38917c478bd9Sstevel@tonic-gate { 38927c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)", 38937c478bd9Sstevel@tonic-gate dip, rdip, cookie, bus_impldata); 38947c478bd9Sstevel@tonic-gate 38957c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip, 38967c478bd9Sstevel@tonic-gate cookie, bus_impldata)); 38977c478bd9Sstevel@tonic-gate } 38987c478bd9Sstevel@tonic-gate 38997c478bd9Sstevel@tonic-gate /* 39007c478bd9Sstevel@tonic-gate * ibnex_reprobe_ioc_dev() 39017c478bd9Sstevel@tonic-gate * 39027c478bd9Sstevel@tonic-gate * This could be called as a result of ibt_reprobe_dev request or 39037c478bd9Sstevel@tonic-gate * cfgadm command. The function is called from a taskq in case of 39047c478bd9Sstevel@tonic-gate * ibt_reprobe_dev and from user context for cfgadm command. 39057c478bd9Sstevel@tonic-gate * 39067c478bd9Sstevel@tonic-gate * This function reprobes the properties for one IOC dip. 39077c478bd9Sstevel@tonic-gate * 39087c478bd9Sstevel@tonic-gate * node_reprobe_state should be set before calling this function. 39097c478bd9Sstevel@tonic-gate */ 39107c478bd9Sstevel@tonic-gate void 39117c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg) 39127c478bd9Sstevel@tonic-gate { 39137c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 39147c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 39157c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_data; 39167c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 39177c478bd9Sstevel@tonic-gate 39187c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 39197c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 39207c478bd9Sstevel@tonic-gate 39217c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 39227c478bd9Sstevel@tonic-gate ASSERT(node_data); 39237c478bd9Sstevel@tonic-gate 39247c478bd9Sstevel@tonic-gate if (node_data->node_dip == NULL) { 39257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip"); 39267c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39277c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 39287c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39297c478bd9Sstevel@tonic-gate return; 39307c478bd9Sstevel@tonic-gate } 39317c478bd9Sstevel@tonic-gate ioc_data = &(node_data->node_data.ioc_node); 39327c478bd9Sstevel@tonic-gate 39337c478bd9Sstevel@tonic-gate /* Reprobe the IOC */ 39347c478bd9Sstevel@tonic-gate ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid, 39357c478bd9Sstevel@tonic-gate 1); 39367c478bd9Sstevel@tonic-gate if (ioc_info == NULL) { 39377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe"); 39387c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39397c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 1); 39407c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39417c478bd9Sstevel@tonic-gate return; 39427c478bd9Sstevel@tonic-gate } 39437c478bd9Sstevel@tonic-gate 39447c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39457c478bd9Sstevel@tonic-gate if (node_data->node_dip) 39467c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info); 39477c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 39487c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39497c478bd9Sstevel@tonic-gate 39507c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 39517c478bd9Sstevel@tonic-gate } 39527c478bd9Sstevel@tonic-gate 39537c478bd9Sstevel@tonic-gate /* 39547c478bd9Sstevel@tonic-gate * ibnex_reprobe_all() 39557c478bd9Sstevel@tonic-gate * 39567c478bd9Sstevel@tonic-gate * This could be called as a result of cfgadm command. The function 39577c478bd9Sstevel@tonic-gate * is called from user context. 39587c478bd9Sstevel@tonic-gate * 39597c478bd9Sstevel@tonic-gate * This function reprobes the properties for all IOC dips. 39607c478bd9Sstevel@tonic-gate * 39617c478bd9Sstevel@tonic-gate * ibnex_reprobe_state should be set before calling this function. 39627c478bd9Sstevel@tonic-gate */ 39637c478bd9Sstevel@tonic-gate void 39647c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_all() 39657c478bd9Sstevel@tonic-gate { 39667c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 39677c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info_list, *ioc; 39687c478bd9Sstevel@tonic-gate 39697c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 39707c478bd9Sstevel@tonic-gate 39717c478bd9Sstevel@tonic-gate /* Sweep the fabric */ 39727c478bd9Sstevel@tonic-gate ioc = ioc_info_list = ibdm_ibnex_get_ioc_list( 39737c478bd9Sstevel@tonic-gate IBDM_IBNEX_REPROBE_ALL); 39747c478bd9Sstevel@tonic-gate if (ioc_info_list == NULL) { 39757c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39767c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 39777c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39787c478bd9Sstevel@tonic-gate return; 39797c478bd9Sstevel@tonic-gate } 39807c478bd9Sstevel@tonic-gate 39817c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39827c478bd9Sstevel@tonic-gate while (ioc_info_list) { 39837c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 39847c478bd9Sstevel@tonic-gate ioc_info_list, 0, 0)) != NULL && 39857c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 39867c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info_list); 39877c478bd9Sstevel@tonic-gate } 39887c478bd9Sstevel@tonic-gate ioc_info_list = ioc_info_list->ioc_next; 39897c478bd9Sstevel@tonic-gate } 39907c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 39917c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39927c478bd9Sstevel@tonic-gate 39937c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 39947c478bd9Sstevel@tonic-gate } 39957c478bd9Sstevel@tonic-gate 39967c478bd9Sstevel@tonic-gate /* 39977c478bd9Sstevel@tonic-gate * Update the properties, if it has modified and notify IBTF client. 39987c478bd9Sstevel@tonic-gate */ 39997c478bd9Sstevel@tonic-gate static void 40007c478bd9Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info) 40017c478bd9Sstevel@tonic-gate { 40027c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 40037c478bd9Sstevel@tonic-gate dev_info_t *dip = node_data->node_dip; 40047c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 40057c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 40067c478bd9Sstevel@tonic-gate 40077c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 40087c478bd9Sstevel@tonic-gate 40097c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 40107c478bd9Sstevel@tonic-gate 40117c478bd9Sstevel@tonic-gate ioc = &node_data->node_data.ioc_node; 40127c478bd9Sstevel@tonic-gate 40137c478bd9Sstevel@tonic-gate evt_data = ioc_info->ioc_info_updated; 40147c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 40157c478bd9Sstevel@tonic-gate 40167c478bd9Sstevel@tonic-gate /* 40177c478bd9Sstevel@tonic-gate * For a disconnected IOC : 40187c478bd9Sstevel@tonic-gate * Store the ioc_profile for supplying cfgadm info 40197c478bd9Sstevel@tonic-gate * ibdm maintains no info of disconnected IOC 40207c478bd9Sstevel@tonic-gate * 40217c478bd9Sstevel@tonic-gate * For reconnected IOC : 40227c478bd9Sstevel@tonic-gate * ibdm has info of previous service entries 40237c478bd9Sstevel@tonic-gate * ioc_profile maintained by ibnexus is used to 40247c478bd9Sstevel@tonic-gate * update ib_srv_prop_updated. 40257c478bd9Sstevel@tonic-gate * Free the ibnex maintained ioc_profile 40267c478bd9Sstevel@tonic-gate */ 40277c478bd9Sstevel@tonic-gate if (ioc_info->ioc_nportgids == 0) { 40287c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 40297c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC disconnected"); 40307c478bd9Sstevel@tonic-gate ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc( 40317c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP); 40327c478bd9Sstevel@tonic-gate bcopy(&ioc_info->ioc_profile, ioc->ioc_profile, 40337c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t)); 40347c478bd9Sstevel@tonic-gate 40357c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs++; 40367c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 && 40377c478bd9Sstevel@tonic-gate ioc->ioc_profile != NULL) { 40387c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 40397c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC reconnected"); 40407c478bd9Sstevel@tonic-gate if (ioc->ioc_profile->ioc_service_entries != 40417c478bd9Sstevel@tonic-gate ioc_info->ioc_profile.ioc_service_entries) 40427c478bd9Sstevel@tonic-gate evt_data.ib_srv_prop_updated = 1; 40437c478bd9Sstevel@tonic-gate 40447c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs--; 40457c478bd9Sstevel@tonic-gate kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t)); 40467c478bd9Sstevel@tonic-gate ioc->ioc_profile = NULL; 40477c478bd9Sstevel@tonic-gate } 40487c478bd9Sstevel@tonic-gate 40497c478bd9Sstevel@tonic-gate /* Update the properties that have changed */ 40507c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40517c478bd9Sstevel@tonic-gate if (evt_data.ib_gid_prop_updated) { 40527c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(dip, ioc_info) != 40537c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 40547c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40557c478bd9Sstevel@tonic-gate return; 40567c478bd9Sstevel@tonic-gate } 40577c478bd9Sstevel@tonic-gate } 40587c478bd9Sstevel@tonic-gate if (evt_data.ib_srv_prop_updated) { 40597c478bd9Sstevel@tonic-gate if (ioc_info->ioc_profile.ioc_service_entries != 0 && 40607c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(dip, ioc_info) != 40617c478bd9Sstevel@tonic-gate IBNEX_SUCCESS)) { 40627c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40637c478bd9Sstevel@tonic-gate return; 40647c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_profile.ioc_service_entries == 0) { 40657c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 40667c478bd9Sstevel@tonic-gate "service-id"); 40677c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 40687c478bd9Sstevel@tonic-gate "service-name"); 40697c478bd9Sstevel@tonic-gate } 40707c478bd9Sstevel@tonic-gate } 40717c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40727c478bd9Sstevel@tonic-gate ioc->ioc_ngids = ioc_info->ioc_nportgids; 40737c478bd9Sstevel@tonic-gate 40747c478bd9Sstevel@tonic-gate /* 40757c478bd9Sstevel@tonic-gate * Post an event if : 40767c478bd9Sstevel@tonic-gate * 1. Properites have changed or NOTIFY_ALWAYS is set. 40777c478bd9Sstevel@tonic-gate * 2. child dip is configured and a valid cookie for 40787c478bd9Sstevel@tonic-gate * IB_PROP_UPDATE_EVENT. 40797c478bd9Sstevel@tonic-gate */ 40807c478bd9Sstevel@tonic-gate if ((evt_data.ib_prop_updated != 0 || 40817c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state & 40827c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) && 40837c478bd9Sstevel@tonic-gate ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) && 40847c478bd9Sstevel@tonic-gate (evt_cookie != NULL))) { 40857c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40867c478bd9Sstevel@tonic-gate 40877c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, dip, 40887c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 40897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 40907c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 40917c478bd9Sstevel@tonic-gate 40927c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40937c478bd9Sstevel@tonic-gate } 40947c478bd9Sstevel@tonic-gate 40957c478bd9Sstevel@tonic-gate /* 40967c478bd9Sstevel@tonic-gate * Cleanup node_reprobe_state, for ibt_reprobe_dev 40977c478bd9Sstevel@tonic-gate * requests, when reprobe all / node reprobe is in 40987c478bd9Sstevel@tonic-gate * progress. ibnex_reprobe_ioc_dev is not called 40997c478bd9Sstevel@tonic-gate * in this case. 41007c478bd9Sstevel@tonic-gate */ 41017c478bd9Sstevel@tonic-gate if (node_data->node_reprobe_state == 41027c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) 41037c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 41047c478bd9Sstevel@tonic-gate } 41057c478bd9Sstevel@tonic-gate 41067c478bd9Sstevel@tonic-gate static ibnex_rval_t 41077c478bd9Sstevel@tonic-gate ibnex_unique_svcname(char *svcname) 41087c478bd9Sstevel@tonic-gate { 41097c478bd9Sstevel@tonic-gate int i; 41107c478bd9Sstevel@tonic-gate 41117c478bd9Sstevel@tonic-gate /* Check Port Services */ 41127c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++) 41137c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname, 41147c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[i], 4) == 0) 41157c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 41167c478bd9Sstevel@tonic-gate 41177c478bd9Sstevel@tonic-gate /* Check VPPA Services */ 41187c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++) 41197c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname, 41207c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0) 41217c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 41227c478bd9Sstevel@tonic-gate 41237c478bd9Sstevel@tonic-gate /* Check HCA_SVC Services */ 41247c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++) 41257c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname, 41267c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0) 41277c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 41287c478bd9Sstevel@tonic-gate 41297c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 41307c478bd9Sstevel@tonic-gate } 41317c478bd9Sstevel@tonic-gate 41327c478bd9Sstevel@tonic-gate static void 41337c478bd9Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg) 41347c478bd9Sstevel@tonic-gate { 41357c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 41367c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 41377c478bd9Sstevel@tonic-gate 41387c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 41397c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 41407c478bd9Sstevel@tonic-gate ASSERT(node_data); 41417c478bd9Sstevel@tonic-gate 41427c478bd9Sstevel@tonic-gate /* 41437c478bd9Sstevel@tonic-gate * Return success if: 41447c478bd9Sstevel@tonic-gate * 1. Reprobe for all nodes are in progress 41457c478bd9Sstevel@tonic-gate * 2. Reprobe for this node is in progress. 41467c478bd9Sstevel@tonic-gate * The reprobe in progress will complete eventually and 41477c478bd9Sstevel@tonic-gate * update the properties, if required. 41487c478bd9Sstevel@tonic-gate */ 41497c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 41507c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state != 0 || 41517c478bd9Sstevel@tonic-gate node_data->node_reprobe_state != 0) { 41527c478bd9Sstevel@tonic-gate /* 41537c478bd9Sstevel@tonic-gate * Setting NOTIFY_ALWAYS to ensure that 41547c478bd9Sstevel@tonic-gate * DDI event is delivered always for 41557c478bd9Sstevel@tonic-gate * ibt_reprobe_dev 41567c478bd9Sstevel@tonic-gate */ 41577c478bd9Sstevel@tonic-gate node_data->node_reprobe_state |= 41587c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 41597c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 41607c478bd9Sstevel@tonic-gate return; 41617c478bd9Sstevel@tonic-gate } 41627c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 41637c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 41647c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 41657c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(arg); 41667c478bd9Sstevel@tonic-gate } 41677c478bd9Sstevel@tonic-gate 41687c478bd9Sstevel@tonic-gate 41697c478bd9Sstevel@tonic-gate /* 41707c478bd9Sstevel@tonic-gate * MPxIO pathmangement routines. Currently IB nexus does not support 41717c478bd9Sstevel@tonic-gate * any kind of pathmangement. So, just return success to make MPxIO 41727c478bd9Sstevel@tonic-gate * framework happy. 41737c478bd9Sstevel@tonic-gate */ 41747c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 41757c478bd9Sstevel@tonic-gate static int 417600a3eaf3SRamaswamy Tummala ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 41777c478bd9Sstevel@tonic-gate { 417800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip); 41797c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 41807c478bd9Sstevel@tonic-gate } 41817c478bd9Sstevel@tonic-gate 41827c478bd9Sstevel@tonic-gate 41837c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 41847c478bd9Sstevel@tonic-gate static int 418500a3eaf3SRamaswamy Tummala ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 41867c478bd9Sstevel@tonic-gate { 418700a3eaf3SRamaswamy Tummala dev_info_t *cdip; 418800a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data; 418900a3eaf3SRamaswamy Tummala int clnt_num_pi; 419000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip); 419100a3eaf3SRamaswamy Tummala 419200a3eaf3SRamaswamy Tummala if (pip == NULL) 419300a3eaf3SRamaswamy Tummala return (MDI_FAILURE); 419400a3eaf3SRamaswamy Tummala /* 419500a3eaf3SRamaswamy Tummala * Get the Client dev_info from the pathinfo. 419600a3eaf3SRamaswamy Tummala */ 419700a3eaf3SRamaswamy Tummala cdip = mdi_pi_get_client(pip); 419800a3eaf3SRamaswamy Tummala if (cdip == NULL) 419900a3eaf3SRamaswamy Tummala return (MDI_FAILURE); 420000a3eaf3SRamaswamy Tummala 420100a3eaf3SRamaswamy Tummala /* 420200a3eaf3SRamaswamy Tummala * How many PIs do we have from this cdip ? 420300a3eaf3SRamaswamy Tummala */ 420400a3eaf3SRamaswamy Tummala clnt_num_pi = mdi_client_get_path_count(cdip); 420500a3eaf3SRamaswamy Tummala 420600a3eaf3SRamaswamy Tummala /* 420700a3eaf3SRamaswamy Tummala * If this is the last PI that is being free'd ( called from 420800a3eaf3SRamaswamy Tummala * mdi_pi_free) we have to clean up the node data for the cdip since 420900a3eaf3SRamaswamy Tummala * the client would have been detached by mdi_devi_offline. 421000a3eaf3SRamaswamy Tummala */ 421100a3eaf3SRamaswamy Tummala if (clnt_num_pi == 1) { 421200a3eaf3SRamaswamy Tummala for (node_data = ibnex.ibnex_ioc_node_head; 421300a3eaf3SRamaswamy Tummala node_data; node_data = node_data->node_next) { 421400a3eaf3SRamaswamy Tummala if (node_data->node_dip == cdip) { 421500a3eaf3SRamaswamy Tummala node_data->node_dip = NULL; 421600a3eaf3SRamaswamy Tummala node_data->node_state = 421700a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 421800a3eaf3SRamaswamy Tummala return (MDI_SUCCESS); 421900a3eaf3SRamaswamy Tummala } 422000a3eaf3SRamaswamy Tummala } 422100a3eaf3SRamaswamy Tummala for (node_data = ibnex.ibnex_pseudo_node_head; 422200a3eaf3SRamaswamy Tummala node_data; node_data = node_data->node_next) { 422300a3eaf3SRamaswamy Tummala if (node_data->node_dip == cdip) { 422400a3eaf3SRamaswamy Tummala node_data->node_dip = NULL; 422500a3eaf3SRamaswamy Tummala node_data->node_state = 422600a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 422700a3eaf3SRamaswamy Tummala return (MDI_SUCCESS); 422800a3eaf3SRamaswamy Tummala } 422900a3eaf3SRamaswamy Tummala } 423000a3eaf3SRamaswamy Tummala } 42317c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42327c478bd9Sstevel@tonic-gate } 42337c478bd9Sstevel@tonic-gate 42347c478bd9Sstevel@tonic-gate 42357c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 42367c478bd9Sstevel@tonic-gate static int 423700a3eaf3SRamaswamy Tummala ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip, 42387c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t arg1, int arg2) 42397c478bd9Sstevel@tonic-gate { 42407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 424100a3eaf3SRamaswamy Tummala "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state); 42427c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42437c478bd9Sstevel@tonic-gate } 42447c478bd9Sstevel@tonic-gate 42457c478bd9Sstevel@tonic-gate 42467c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 42477c478bd9Sstevel@tonic-gate static int 42487c478bd9Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg) 42497c478bd9Sstevel@tonic-gate { 42507c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42517c478bd9Sstevel@tonic-gate } 42527c478bd9Sstevel@tonic-gate 42537c478bd9Sstevel@tonic-gate 42547c478bd9Sstevel@tonic-gate static int 42557c478bd9Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg, 42567c478bd9Sstevel@tonic-gate pm_bus_power_op_t op, void *arg, void *result) 42577c478bd9Sstevel@tonic-gate { 42587c478bd9Sstevel@tonic-gate 42597c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 42607c478bd9Sstevel@tonic-gate 42617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op); 42627c478bd9Sstevel@tonic-gate 42637c478bd9Sstevel@tonic-gate /* 42647c478bd9Sstevel@tonic-gate * Generic processing in MPxIO framework 42657c478bd9Sstevel@tonic-gate */ 42667c478bd9Sstevel@tonic-gate ret = mdi_bus_power(parent, impl_arg, op, arg, result); 42677c478bd9Sstevel@tonic-gate 42687c478bd9Sstevel@tonic-gate switch (ret) { 42697c478bd9Sstevel@tonic-gate case MDI_SUCCESS: 42707c478bd9Sstevel@tonic-gate ret = DDI_SUCCESS; 42717c478bd9Sstevel@tonic-gate break; 42727c478bd9Sstevel@tonic-gate case MDI_FAILURE: 42737c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 42747c478bd9Sstevel@tonic-gate break; 42757c478bd9Sstevel@tonic-gate default: 42767c478bd9Sstevel@tonic-gate break; 42777c478bd9Sstevel@tonic-gate } 42787c478bd9Sstevel@tonic-gate 42797c478bd9Sstevel@tonic-gate return (ret); 42807c478bd9Sstevel@tonic-gate } 42819d3d2ed0Shiremath 42829d3d2ed0Shiremath 42839d3d2ed0Shiremath /* 42849d3d2ed0Shiremath * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config. 42859d3d2ed0Shiremath * ndi_devi_enter is not held during this call. mdi_vhci_bus_config() 42869d3d2ed0Shiremath * will have called ndi_busop_bus_config(), no need for the caller to call 42879d3d2ed0Shiremath * ndi_busop_bus_config() again. 42889d3d2ed0Shiremath * 42899d3d2ed0Shiremath * If enumerated as a child of HCA device, this could be a case for 42909d3d2ed0Shiremath * Sparc boot or device enumeration from PHCI, driven by MDI. 42919d3d2ed0Shiremath * Hold parent lock (ndi_devi_enter). The caller will have to call 42929d3d2ed0Shiremath * ndi_busop_bus_config() if this function returns SUCCESS. 42939d3d2ed0Shiremath * 42949d3d2ed0Shiremath * if the device name contains ":port", then it is the Sparc boot case. 42959d3d2ed0Shiremath * Handle this as before. 42969d3d2ed0Shiremath * 42979d3d2ed0Shiremath * If the device name does *not* contain the ":port", then : 42989d3d2ed0Shiremath * 1. ibdm to probe IOC 42999d3d2ed0Shiremath * 2. Create a pathinfo only if the IOC is reachable from the parent dip. 43009d3d2ed0Shiremath */ 43019d3d2ed0Shiremath static int 43029d3d2ed0Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag, 43039d3d2ed0Shiremath ddi_bus_config_op_t op, void *devname, dev_info_t **child, 43049d3d2ed0Shiremath int *need_bus_config) 43059d3d2ed0Shiremath { 43069d3d2ed0Shiremath int ret = DDI_FAILURE, circ; 43079d3d2ed0Shiremath dev_info_t *pdip = *pdipp; 43089d3d2ed0Shiremath ib_guid_t iou_guid, ioc_guid; 43099d3d2ed0Shiremath char *ioc_guid_str; 43109d3d2ed0Shiremath 43119d3d2ed0Shiremath 43129d3d2ed0Shiremath *need_bus_config = 1; 43139d3d2ed0Shiremath 43149d3d2ed0Shiremath if (pdip == ibnex.ibnex_dip) { 43159d3d2ed0Shiremath if (ibnex_devname_to_node_n_ioc_guids( 43169d3d2ed0Shiremath (char *)devname, &iou_guid, &ioc_guid, 43179d3d2ed0Shiremath &ioc_guid_str) != IBNEX_SUCCESS) { 43189d3d2ed0Shiremath return (ret); 43199d3d2ed0Shiremath } 43209d3d2ed0Shiremath ret = mdi_vhci_bus_config(pdip, flag, op, devname, child, 43219d3d2ed0Shiremath ioc_guid_str); 43229d3d2ed0Shiremath kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1); 43239d3d2ed0Shiremath if (ret == MDI_SUCCESS) 43249d3d2ed0Shiremath *need_bus_config = 0; 43259d3d2ed0Shiremath } else { 43265e3986cbScth mdi_devi_enter(pdip, &circ); 43279d3d2ed0Shiremath if (strstr((char *)devname, ":port=") != NULL) { 43289d3d2ed0Shiremath ret = ibnex_config_root_iocnode(pdip, devname); 43299d3d2ed0Shiremath ASSERT(ibnex.ibnex_dip == NULL); 43309d3d2ed0Shiremath *pdipp = ibnex.ibnex_dip; 43319d3d2ed0Shiremath } else { 43329d3d2ed0Shiremath ret = ibnex_config_ioc_node(devname, pdip); 43339d3d2ed0Shiremath } 43345e3986cbScth mdi_devi_exit(pdip, circ); 43359d3d2ed0Shiremath } 43369d3d2ed0Shiremath return (ret); 43379d3d2ed0Shiremath } 43389d3d2ed0Shiremath 43399d3d2ed0Shiremath static int 43409d3d2ed0Shiremath ibnex_is_merge_node(dev_info_t *child) 43419d3d2ed0Shiremath { 43429d3d2ed0Shiremath char *node; 43439d3d2ed0Shiremath int ret = IBNEX_INVALID_NODE; 43449d3d2ed0Shiremath 43459d3d2ed0Shiremath if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 43469d3d2ed0Shiremath DDI_PROP_DONTPASS, "ib-node-type", &node) != 43479d3d2ed0Shiremath DDI_PROP_SUCCESS) { 43489d3d2ed0Shiremath return (IBNEX_FAILURE); 43499d3d2ed0Shiremath } 43509d3d2ed0Shiremath 43519d3d2ed0Shiremath if (node != NULL && *node != 0) { 43529d3d2ed0Shiremath if (strcmp(node, "merge") == 0) 43539d3d2ed0Shiremath ret = IBNEX_SUCCESS; 43549d3d2ed0Shiremath else { 43559d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 43569d3d2ed0Shiremath "\tis_merge_node: ib-node-type = %s", node); 43579d3d2ed0Shiremath } 43589d3d2ed0Shiremath } 43599d3d2ed0Shiremath 43609d3d2ed0Shiremath ddi_prop_free(node); 43619d3d2ed0Shiremath return (ret); 43629d3d2ed0Shiremath } 43639d3d2ed0Shiremath 43649d3d2ed0Shiremath /* 43659d3d2ed0Shiremath * Checks if the dn_head for the driver has already 43669d3d2ed0Shiremath * initialized by the prom tree. 43679d3d2ed0Shiremath */ 4368f7209cf2Spramodbg void 43699d3d2ed0Shiremath ibnex_hw_in_dev_tree(char *driver_name) 43709d3d2ed0Shiremath { 43719d3d2ed0Shiremath major_t major; 43729d3d2ed0Shiremath 4373f7209cf2Spramodbg IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name); 4374f7209cf2Spramodbg 43759d3d2ed0Shiremath if (devnamesp == NULL) 4376f7209cf2Spramodbg return; 43779d3d2ed0Shiremath 43789d3d2ed0Shiremath major = ddi_name_to_major(driver_name); 43799d3d2ed0Shiremath if (major == -1) 4380f7209cf2Spramodbg return; 43819d3d2ed0Shiremath 4382f7209cf2Spramodbg if (devnamesp[major].dn_head != (dev_info_t *)NULL) 4383f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_IN_DEVTREE; 43849d3d2ed0Shiremath } 438500a3eaf3SRamaswamy Tummala 438600a3eaf3SRamaswamy Tummala int 438700a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info) 438800a3eaf3SRamaswamy Tummala { 438900a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list; 439000a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 439100a3eaf3SRamaswamy Tummala int rc = IBNEX_FAILURE; 439200a3eaf3SRamaswamy Tummala 439300a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 439400a3eaf3SRamaswamy Tummala /* 439500a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs 439600a3eaf3SRamaswamy Tummala */ 439700a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list; 439800a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) { 439900a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 440000a3eaf3SRamaswamy Tummala if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) == 440100a3eaf3SRamaswamy Tummala IBNEX_SUCCESS) 440200a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 440300a3eaf3SRamaswamy Tummala } 440400a3eaf3SRamaswamy Tummala return (rc); 440500a3eaf3SRamaswamy Tummala } 440600a3eaf3SRamaswamy Tummala 440700a3eaf3SRamaswamy Tummala static int 440800a3eaf3SRamaswamy Tummala ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip, 440900a3eaf3SRamaswamy Tummala int pdip_reachable_checked) 441000a3eaf3SRamaswamy Tummala { 441100a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data; 441200a3eaf3SRamaswamy Tummala int create_pdip = 0; 441300a3eaf3SRamaswamy Tummala int rc = IBNEX_SUCCESS; 441400a3eaf3SRamaswamy Tummala 441500a3eaf3SRamaswamy Tummala 441600a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 441700a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 441800a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip, 441900a3eaf3SRamaswamy Tummala pdip_reachable_checked); 442000a3eaf3SRamaswamy Tummala 442100a3eaf3SRamaswamy Tummala if (pdip_reachable_checked == 0) { 442200a3eaf3SRamaswamy Tummala if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) { 442300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 442400a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip: ioc %p not reachable" 442500a3eaf3SRamaswamy Tummala "from %p", ioc_info, pdip); 442600a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 442700a3eaf3SRamaswamy Tummala } 442800a3eaf3SRamaswamy Tummala } 442900a3eaf3SRamaswamy Tummala 443000a3eaf3SRamaswamy Tummala node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 443100a3eaf3SRamaswamy Tummala (void *)ioc_info, 0, 0); 443200a3eaf3SRamaswamy Tummala 443300a3eaf3SRamaswamy Tummala if (node_data && node_data->node_ap_state == 443400a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED) { 443500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 443600a3eaf3SRamaswamy Tummala "\tioc_config_from_pdip: Unconfigured node"); 443700a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 443800a3eaf3SRamaswamy Tummala } 443900a3eaf3SRamaswamy Tummala 444000a3eaf3SRamaswamy Tummala 444100a3eaf3SRamaswamy Tummala if (node_data == NULL) { 444200a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc; 444300a3eaf3SRamaswamy Tummala 444400a3eaf3SRamaswamy Tummala create_pdip = 1; 444500a3eaf3SRamaswamy Tummala 444600a3eaf3SRamaswamy Tummala node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE, 444700a3eaf3SRamaswamy Tummala ioc_info, 0, 0); 444800a3eaf3SRamaswamy Tummala ASSERT(node_data); 444900a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node; 445000a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN, 445100a3eaf3SRamaswamy Tummala "%llX", 445200a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid); 445300a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN, 445400a3eaf3SRamaswamy Tummala "%llX,%llX", 445500a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid, 445600a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_iou_guid); 445700a3eaf3SRamaswamy Tummala } else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) { 445800a3eaf3SRamaswamy Tummala create_pdip = 1; 445900a3eaf3SRamaswamy Tummala } 446000a3eaf3SRamaswamy Tummala 446100a3eaf3SRamaswamy Tummala if (create_pdip) { 446200a3eaf3SRamaswamy Tummala rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip); 446300a3eaf3SRamaswamy Tummala } 446400a3eaf3SRamaswamy Tummala 446500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x", 446600a3eaf3SRamaswamy Tummala rc); 446700a3eaf3SRamaswamy Tummala return (rc); 446800a3eaf3SRamaswamy Tummala } 446900a3eaf3SRamaswamy Tummala 447000a3eaf3SRamaswamy Tummala /* 447100a3eaf3SRamaswamy Tummala * This function checks if a pathinfo has already been created 447200a3eaf3SRamaswamy Tummala * for the HCA parent. The function returns SUCCESS if a pathinfo 447300a3eaf3SRamaswamy Tummala * has already been created, FAILURE if not. 447400a3eaf3SRamaswamy Tummala */ 447500a3eaf3SRamaswamy Tummala static int 447600a3eaf3SRamaswamy Tummala ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent) 447700a3eaf3SRamaswamy Tummala { 447800a3eaf3SRamaswamy Tummala int rc; 447900a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc; 448000a3eaf3SRamaswamy Tummala 448100a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node; 448200a3eaf3SRamaswamy Tummala if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str, 448300a3eaf3SRamaswamy Tummala (char *)ioc->ioc_phci_guid) != NULL) 448400a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 448500a3eaf3SRamaswamy Tummala else 448600a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE; 448700a3eaf3SRamaswamy Tummala 448800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, " 448900a3eaf3SRamaswamy Tummala "phci_guid %s, parent %p, rc %x", 449000a3eaf3SRamaswamy Tummala ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc); 449100a3eaf3SRamaswamy Tummala return (rc); 449200a3eaf3SRamaswamy Tummala } 449300a3eaf3SRamaswamy Tummala 449400a3eaf3SRamaswamy Tummala static int 449500a3eaf3SRamaswamy Tummala ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 449600a3eaf3SRamaswamy Tummala { 449700a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list; 449800a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 449900a3eaf3SRamaswamy Tummala 450000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)", 450100a3eaf3SRamaswamy Tummala ioc_info, pdip); 450200a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list; 450300a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) { 450400a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 450500a3eaf3SRamaswamy Tummala if (hca_dip == pdip) { 450600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 450700a3eaf3SRamaswamy Tummala "\tioc_pi_reachable FAILURE"); 450800a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS); 450900a3eaf3SRamaswamy Tummala } 451000a3eaf3SRamaswamy Tummala } 451100a3eaf3SRamaswamy Tummala 451200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE"); 451300a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 451400a3eaf3SRamaswamy Tummala } 4515