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> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* Function prototypes */ 597c478bd9Sstevel@tonic-gate static int ibnex_attach(dev_info_t *, ddi_attach_cmd_t); 607c478bd9Sstevel@tonic-gate static int ibnex_getinfo(dev_info_t *, ddi_info_cmd_t, 617c478bd9Sstevel@tonic-gate void *, void **); 627c478bd9Sstevel@tonic-gate static int ibnex_detach(dev_info_t *, ddi_detach_cmd_t); 637c478bd9Sstevel@tonic-gate static int ibnex_busctl(dev_info_t *, 647c478bd9Sstevel@tonic-gate dev_info_t *, ddi_ctl_enum_t, void *, void *); 657c478bd9Sstevel@tonic-gate static int ibnex_map_fault(dev_info_t *, 667c478bd9Sstevel@tonic-gate dev_info_t *, struct hat *, struct seg *, 677c478bd9Sstevel@tonic-gate caddr_t, struct devpage *, pfn_t, uint_t, uint_t); 687c478bd9Sstevel@tonic-gate static int ibnex_init_child(dev_info_t *); 697c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_comm_svc_init(char *, ibnex_node_type_t); 707c478bd9Sstevel@tonic-gate static void ibnex_comm_svc_fini(); 717c478bd9Sstevel@tonic-gate dev_info_t *ibnex_commsvc_initnode(dev_info_t *, 727c478bd9Sstevel@tonic-gate ibdm_port_attr_t *, int, int, ib_pkey_t, int *, 737c478bd9Sstevel@tonic-gate int); 747c478bd9Sstevel@tonic-gate static void ibnex_delete_port_node_data(ibnex_node_data_t *); 757c478bd9Sstevel@tonic-gate int ibnex_get_dip_from_guid(ib_guid_t, int, 767c478bd9Sstevel@tonic-gate ib_pkey_t, dev_info_t **); 777c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t, 787c478bd9Sstevel@tonic-gate void *, int, ib_pkey_t); 797c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *, 807c478bd9Sstevel@tonic-gate int, ib_pkey_t); 817c478bd9Sstevel@tonic-gate static int ibnex_create_port_node_prop(ibdm_port_attr_t *, 827c478bd9Sstevel@tonic-gate dev_info_t *, char *, ib_pkey_t); 837c478bd9Sstevel@tonic-gate void ibnex_dm_callback(void *, ibdm_events_t); 847c478bd9Sstevel@tonic-gate static int ibnex_create_port_compatible_prop(dev_info_t *, 857c478bd9Sstevel@tonic-gate char *, ibdm_port_attr_t *); 867c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_srv_props( 877c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 887c478bd9Sstevel@tonic-gate static int ibnex_get_eventcookie(dev_info_t *, 897c478bd9Sstevel@tonic-gate dev_info_t *, char *, ddi_eventcookie_t *); 907c478bd9Sstevel@tonic-gate static int ibnex_add_eventcall(dev_info_t *, dev_info_t *, 917c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void (*)(dev_info_t *, 927c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *, void *), 937c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id); 947c478bd9Sstevel@tonic-gate static int ibnex_remove_eventcall(dev_info_t *, 957c478bd9Sstevel@tonic-gate ddi_callback_id_t); 967c478bd9Sstevel@tonic-gate static int ibnex_post_event(dev_info_t *, dev_info_t *, 977c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *); 987c478bd9Sstevel@tonic-gate static int ibnex_bus_config(dev_info_t *, uint_t, 997c478bd9Sstevel@tonic-gate ddi_bus_config_op_t, void *, dev_info_t **); 1007c478bd9Sstevel@tonic-gate static int ibnex_bus_unconfig(dev_info_t *, 1017c478bd9Sstevel@tonic-gate uint_t, ddi_bus_config_op_t, void *); 1027c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_port_node(dev_info_t *, char *); 1037c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_obp_args(dev_info_t *, char *); 1047c478bd9Sstevel@tonic-gate static int ibnex_get_pkey_commsvc_index_portnum( 1057c478bd9Sstevel@tonic-gate char *, int *, ib_pkey_t *, uint8_t *); 1067c478bd9Sstevel@tonic-gate static void ibnex_config_all_children(dev_info_t *); 1077c478bd9Sstevel@tonic-gate static int ibnex_devname_to_portnum(char *, uint8_t *); 1087c478bd9Sstevel@tonic-gate static void ibnex_create_vppa_nodes( 1097c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1107c478bd9Sstevel@tonic-gate static void ibnex_create_port_nodes( 1117c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1127c478bd9Sstevel@tonic-gate static void ibnex_create_hcasvc_nodes( 1137c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1147c478bd9Sstevel@tonic-gate static int ibnex_config_root_iocnode(dev_info_t *, char *); 1157c478bd9Sstevel@tonic-gate static int ibnex_devname2port(char *, int *); 1169d3d2ed0Shiremath static int ibnex_config_ioc_node(char *, dev_info_t *); 1177c478bd9Sstevel@tonic-gate static int ibnex_devname_to_node_n_ioc_guids( 1189d3d2ed0Shiremath char *, ib_guid_t *, ib_guid_t *, char **); 1197c478bd9Sstevel@tonic-gate static void ibnex_ioc_node_cleanup(); 1207c478bd9Sstevel@tonic-gate static void ibnex_delete_ioc_node_data(ibnex_node_data_t *); 12100a3eaf3SRamaswamy Tummala int ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *); 12200a3eaf3SRamaswamy Tummala static int ibnex_ioc_initnode_pdip(ibnex_node_data_t *, 12300a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *, dev_info_t *); 1247c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_node_prop( 1257c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *, dev_info_t *); 1267c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_compatible_prop( 1277c478bd9Sstevel@tonic-gate dev_info_t *, ib_dm_ioc_ctrl_profile_t *); 1287c478bd9Sstevel@tonic-gate uint64_t ibnex_str2hex(char *, int, int *); 1297c478bd9Sstevel@tonic-gate static int ibnex_str2int(char *, int, int *); 1307c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_portgid_prop( 1317c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 1327c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int); 1337c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_all(); 1347c478bd9Sstevel@tonic-gate ibt_status_t ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *); 1357c478bd9Sstevel@tonic-gate static int ibnex_prom_devname_to_pkey_n_portnum( 1367c478bd9Sstevel@tonic-gate char *, ib_pkey_t *, uint8_t *); 1377c478bd9Sstevel@tonic-gate void ibnex_pseudo_initnodes(void); 1389d3d2ed0Shiremath static char *ibnex_lookup_named_prop(ddi_prop_t *, char *); 1397c478bd9Sstevel@tonic-gate static void ibnex_pseudo_node_cleanup(void); 1407c478bd9Sstevel@tonic-gate static int ibnex_name_child(dev_info_t *, char *, int); 1417c478bd9Sstevel@tonic-gate static int ibnex_name_pseudo_child(dev_info_t *, char *); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_dev(void *); 1447c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_all(); 1457c478bd9Sstevel@tonic-gate static void ibnex_update_prop(ibnex_node_data_t *, 1467c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *); 1477c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_unique_svcname(char *); 1487c478bd9Sstevel@tonic-gate static void ibnex_handle_reprobe_dev(void *arg); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate extern int ibnex_open(dev_t *, int, int, cred_t *); 1517c478bd9Sstevel@tonic-gate extern int ibnex_close(dev_t, int, int, cred_t *); 1527c478bd9Sstevel@tonic-gate extern int ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1537c478bd9Sstevel@tonic-gate extern int ibnex_offline_childdip(dev_info_t *); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate static int ibnex_ioc_create_pi( 1569d3d2ed0Shiremath ibdm_ioc_info_t *, ibnex_node_data_t *, 15700a3eaf3SRamaswamy Tummala dev_info_t *, int *); 1587c478bd9Sstevel@tonic-gate static int ibnex_bus_power(dev_info_t *, void *, 1597c478bd9Sstevel@tonic-gate pm_bus_power_op_t, void *, void *); 16000a3eaf3SRamaswamy Tummala int ibnex_pseudo_create_all_pi(ibnex_node_data_t *); 16100a3eaf3SRamaswamy Tummala static int ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *, 1629d3d2ed0Shiremath dev_info_t *); 16305fa0d51Spramodbg static int ibnex_pseudo_config_one( 16405fa0d51Spramodbg ibnex_node_data_t *, char *, dev_info_t *); 1659d3d2ed0Shiremath static int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **, 1669d3d2ed0Shiremath char *, char *); 1679d3d2ed0Shiremath static void ibnex_config_pseudo_all(dev_info_t *); 1689d3d2ed0Shiremath static int ibnex_ioc_bus_config_one(dev_info_t **, uint_t, 1699d3d2ed0Shiremath ddi_bus_config_op_t, void *, dev_info_t **, int *); 1709d3d2ed0Shiremath static int ibnex_is_merge_node(dev_info_t *); 171f7209cf2Spramodbg static void ibnex_hw_in_dev_tree(char *); 17200a3eaf3SRamaswamy Tummala static int ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *, 17300a3eaf3SRamaswamy Tummala dev_info_t *, int); 17400a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *); 17500a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_reachable(ibdm_ioc_info_t *, 17600a3eaf3SRamaswamy Tummala dev_info_t *); 1779d3d2ed0Shiremath 1787c478bd9Sstevel@tonic-gate /* 1797c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of HCA nexus driver. 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate struct bus_ops ibnex_ci_busops = { 1827c478bd9Sstevel@tonic-gate BUSO_REV, 1837c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 1847c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 1857c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 1867c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 1877c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 1887c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 1897c478bd9Sstevel@tonic-gate NULL, 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 ibnex_busctl, /* bus_ctl */ 1977c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 1987c478bd9Sstevel@tonic-gate NULL, /* bus_get_eventcookie */ 1997c478bd9Sstevel@tonic-gate NULL, /* bus_add_eventcall */ 2007c478bd9Sstevel@tonic-gate NULL, /* bus_remove_eventcall */ 2017c478bd9Sstevel@tonic-gate NULL, /* bus_post_event */ 2027c478bd9Sstevel@tonic-gate NULL, 2037c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2047c478bd9Sstevel@tonic-gate ibnex_bus_unconfig /* bus unconfig */ 2057c478bd9Sstevel@tonic-gate }; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Prototype declarations for the VHCI options 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Functions registered with the mpxio framework 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int); 2147c478bd9Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int); 2157c478bd9Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *, 2167c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int); 2177c478bd9Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = { 2217c478bd9Sstevel@tonic-gate MDI_VHCI_OPS_REV, 2227c478bd9Sstevel@tonic-gate ib_vhci_pi_init, 2237c478bd9Sstevel@tonic-gate ib_vhci_pi_uninit, 2247c478bd9Sstevel@tonic-gate ib_vhci_pi_state_change, 2257c478bd9Sstevel@tonic-gate ib_vhci_failover 2267c478bd9Sstevel@tonic-gate }; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of IB nexus driver. 2317c478bd9Sstevel@tonic-gate * IB nexus drivers does not support any DMA operations for its children 2327c478bd9Sstevel@tonic-gate * as there is no such concept in Infiniband. All the memory operations 2337c478bd9Sstevel@tonic-gate * and DMA operations required by the child drivers can be performed using 2347c478bd9Sstevel@tonic-gate * the IBTF API. 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = { 2377c478bd9Sstevel@tonic-gate BUSO_REV, 2387c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 2397c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 2407c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 2417c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 2427c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 2437c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 2447c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl, 2457c478bd9Sstevel@tonic-gate NULL, 2467c478bd9Sstevel@tonic-gate NULL, 2477c478bd9Sstevel@tonic-gate NULL, 2487c478bd9Sstevel@tonic-gate NULL, 2497c478bd9Sstevel@tonic-gate NULL, 2507c478bd9Sstevel@tonic-gate NULL, 2517c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 2527c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 2537c478bd9Sstevel@tonic-gate ibnex_get_eventcookie, /* bus_get_eventcookie */ 2547c478bd9Sstevel@tonic-gate ibnex_add_eventcall, /* bus_add_eventcall */ 2557c478bd9Sstevel@tonic-gate ibnex_remove_eventcall, /* bus_remove_eventcall */ 2567c478bd9Sstevel@tonic-gate ibnex_post_event, /* bus_post_event */ 2577c478bd9Sstevel@tonic-gate NULL, 2587c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2597c478bd9Sstevel@tonic-gate ibnex_bus_unconfig, /* bus unconfig */ 2607c478bd9Sstevel@tonic-gate NULL, /* bus fm init */ 2617c478bd9Sstevel@tonic-gate NULL, /* bus fm fini */ 2627c478bd9Sstevel@tonic-gate NULL, /* bus fm access enter */ 2637c478bd9Sstevel@tonic-gate NULL, /* bus fm access exit */ 2647c478bd9Sstevel@tonic-gate ibnex_bus_power /* bus power */ 2657c478bd9Sstevel@tonic-gate }; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* ibnex cb_ops */ 2687c478bd9Sstevel@tonic-gate static struct cb_ops ibnex_cbops = { 2697c478bd9Sstevel@tonic-gate ibnex_open, /* open */ 2707c478bd9Sstevel@tonic-gate ibnex_close, /* close */ 2717c478bd9Sstevel@tonic-gate nodev, /* strategy */ 2727c478bd9Sstevel@tonic-gate nodev, /* print */ 2737c478bd9Sstevel@tonic-gate nodev, /* dump */ 2747c478bd9Sstevel@tonic-gate nodev, /* read */ 2757c478bd9Sstevel@tonic-gate nodev, /* write */ 2767c478bd9Sstevel@tonic-gate ibnex_ioctl, /* ioctl */ 2777c478bd9Sstevel@tonic-gate nodev, /* devmap */ 2787c478bd9Sstevel@tonic-gate nodev, /* mmap */ 2797c478bd9Sstevel@tonic-gate nodev, /* segmap */ 2807c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 2817c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 2827c478bd9Sstevel@tonic-gate NULL, /* stream */ 2837c478bd9Sstevel@tonic-gate D_MP, /* cb_flag */ 2847c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 2857c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 2867c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 2877c478bd9Sstevel@tonic-gate }; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate /* 2907c478bd9Sstevel@tonic-gate * Device options 2917c478bd9Sstevel@tonic-gate * Note: ddi_no_info needs to change during devfs time frame. The drivers 2927c478bd9Sstevel@tonic-gate * with 1 to 1 mapping between minor node and instance should use 2937c478bd9Sstevel@tonic-gate * ddi_1to1_info. (See bug id 4424752) 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate static struct dev_ops ibnex_ops = { 2967c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 2977c478bd9Sstevel@tonic-gate 0, /* refcnt */ 2987c478bd9Sstevel@tonic-gate ibnex_getinfo, /* info */ 2997c478bd9Sstevel@tonic-gate nulldev, /* identify */ 3007c478bd9Sstevel@tonic-gate nulldev, /* probe */ 3017c478bd9Sstevel@tonic-gate ibnex_attach, /* attach */ 3027c478bd9Sstevel@tonic-gate ibnex_detach, /* detach */ 3037c478bd9Sstevel@tonic-gate nodev, /* reset */ 3047c478bd9Sstevel@tonic-gate &ibnex_cbops, /* driver ops - devctl interfaces */ 3057c478bd9Sstevel@tonic-gate &ibnex_bus_ops, /* bus operations */ 30619397407SSherry Moore nulldev, /* power */ 30719397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 3087c478bd9Sstevel@tonic-gate }; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* Module linkage information for the kernel. */ 3117c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3127c478bd9Sstevel@tonic-gate &mod_driverops, /* Driver module */ 31319397407SSherry Moore "IB nexus", /* Driver name and version */ 3147c478bd9Sstevel@tonic-gate &ibnex_ops, /* driver ops */ 3157c478bd9Sstevel@tonic-gate }; 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3187c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 3197c478bd9Sstevel@tonic-gate }; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 3227c478bd9Sstevel@tonic-gate * Global per-instance IB Nexus data. 3237c478bd9Sstevel@tonic-gate * There is only one instance of IB Nexus supported. 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate ibnex_t ibnex; 3267c478bd9Sstevel@tonic-gate #ifdef __lock_lint 3277c478bd9Sstevel@tonic-gate extern ibdm_t ibdm; 3287c478bd9Sstevel@tonic-gate #endif 3297c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s)) 3307c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs 3317c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs 3327c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs 33300a3eaf3SRamaswamy Tummala ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list)) 3347c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s)) 3357c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex)) 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* The port settling time in seconds */ 33800a3eaf3SRamaswamy Tummala int ibnex_port_settling_time = 30; 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */ 3417c478bd9Sstevel@tonic-gate static struct ibnex_property { 3427c478bd9Sstevel@tonic-gate char *name; 3437c478bd9Sstevel@tonic-gate ibnex_node_type_t type; 3447c478bd9Sstevel@tonic-gate } ibnex_properties[] = { 3457c478bd9Sstevel@tonic-gate { "port-svc-list", IBNEX_PORT_COMMSVC_NODE}, 3467c478bd9Sstevel@tonic-gate { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE}, 3477c478bd9Sstevel@tonic-gate { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE} 3487c478bd9Sstevel@tonic-gate }; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \ 3517c478bd9Sstevel@tonic-gate (sizeof (struct ibnex_property)) 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* 3547c478bd9Sstevel@tonic-gate * Event Definition 3557c478bd9Sstevel@tonic-gate * Single event, event name defined in ibti_common.h. 3567c478bd9Sstevel@tonic-gate * Event posted to specific child handler. Event posted 3577c478bd9Sstevel@tonic-gate * at kernel priority. 3587c478bd9Sstevel@tonic-gate */ 3597c478bd9Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = { 3607c478bd9Sstevel@tonic-gate {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL, 3617c478bd9Sstevel@tonic-gate NDI_EVENT_POST_TO_TGT} 3627c478bd9Sstevel@tonic-gate }; 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate #define IB_N_NDI_EVENTS \ 3657c478bd9Sstevel@tonic-gate (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t)) 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = { 3687c478bd9Sstevel@tonic-gate NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs}; 3699d3d2ed0Shiremath static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate /* 3737c478bd9Sstevel@tonic-gate * _init 3747c478bd9Sstevel@tonic-gate * Loadable module init, called before any other module. 3757c478bd9Sstevel@tonic-gate */ 3767c478bd9Sstevel@tonic-gate int 3777c478bd9Sstevel@tonic-gate _init(void) 3787c478bd9Sstevel@tonic-gate { 3797c478bd9Sstevel@tonic-gate int error; 380f7209cf2Spramodbg char **hca_driver_list; 381f7209cf2Spramodbg int i, ndrivers; 3827c478bd9Sstevel@tonic-gate 3839d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) { 384f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE; 385f7209cf2Spramodbg hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers); 386f7209cf2Spramodbg for (i = 0; i < ndrivers; i++) { 387f7209cf2Spramodbg ibnex_hw_in_dev_tree(hca_driver_list[i]); 388f7209cf2Spramodbg if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE) 389f7209cf2Spramodbg break; 390f7209cf2Spramodbg } 391f7209cf2Spramodbg mdi_free_phci_driver_list(hca_driver_list, ndrivers); 3929d3d2ed0Shiremath } 3939d3d2ed0Shiremath 3949d3d2ed0Shiremath /* 3959d3d2ed0Shiremath * IB Nexus _init can be called while force attaching 3969d3d2ed0Shiremath * IB Nexus driver or when a HCA is hotplugged. 3979d3d2ed0Shiremath * 3989d3d2ed0Shiremath * If IB HW is not in device tree or if no HCA driver 3999d3d2ed0Shiremath * has been attached, fail IB Nexus _init(). 4009d3d2ed0Shiremath */ 4019d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE && 4029d3d2ed0Shiremath ibt_hw_is_present() == 0) { 4039d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW"); 4049d3d2ed0Shiremath return (DDI_FAILURE); 4059d3d2ed0Shiremath } 4069d3d2ed0Shiremath 4077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_init"); 4087c478bd9Sstevel@tonic-gate mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL); 4097c478bd9Sstevel@tonic-gate cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL); 41051f34d4bSRajkumar Sivaprakasam cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL); 4117c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 4127c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed"); 4137c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4147c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 41551f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv); 4167c478bd9Sstevel@tonic-gate } else { 4177c478bd9Sstevel@tonic-gate ibdm_ibnex_register_callback(ibnex_dm_callback); 4187c478bd9Sstevel@tonic-gate ibtl_ibnex_register_callback(ibnex_ibtl_callback); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate return (error); 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* 4257c478bd9Sstevel@tonic-gate * _fini 4267c478bd9Sstevel@tonic-gate * Prepares a module for unloading. 4277c478bd9Sstevel@tonic-gate */ 4287c478bd9Sstevel@tonic-gate int 4297c478bd9Sstevel@tonic-gate _fini(void) 4307c478bd9Sstevel@tonic-gate { 4317c478bd9Sstevel@tonic-gate int error; 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_fini"); 4347c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) { 4357c478bd9Sstevel@tonic-gate return (error); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate ibdm_ibnex_unregister_callback(); 4387c478bd9Sstevel@tonic-gate ibtl_ibnex_unregister_callback(); 4397c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4407c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 44151f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv); 4427c478bd9Sstevel@tonic-gate return (0); 4437c478bd9Sstevel@tonic-gate } 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * _info 4487c478bd9Sstevel@tonic-gate * Returns information about loadable module. 4497c478bd9Sstevel@tonic-gate */ 4507c478bd9Sstevel@tonic-gate int 4517c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4527c478bd9Sstevel@tonic-gate { 4537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_info"); 4547c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * ibnex_attach 4607c478bd9Sstevel@tonic-gate * Configure and attach an instance of the IB Nexus driver 4617c478bd9Sstevel@tonic-gate * Only one instance of IB Nexus is supported 4627c478bd9Sstevel@tonic-gate * Create a minor node for cfgadm purpose 4637c478bd9Sstevel@tonic-gate * Initialize communication services 4647c478bd9Sstevel@tonic-gate * Register callback with IBDM 4657c478bd9Sstevel@tonic-gate * Register callback with IBTL 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate static int 4687c478bd9Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 4697c478bd9Sstevel@tonic-gate { 4707c478bd9Sstevel@tonic-gate int i; 4717c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd); 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate switch (cmd) { 4767c478bd9Sstevel@tonic-gate case DDI_ATTACH: 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate case DDI_RESUME: 4797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME"); 4807c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4817c478bd9Sstevel@tonic-gate default: 4827c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate /* Fail attach for more than one instance */ 4867c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 4877c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) { 4887c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* Register with MPxIO framework */ 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0) 4967c478bd9Sstevel@tonic-gate != MDI_SUCCESS) { 4977c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 4987c478bd9Sstevel@tonic-gate "\tattach: mdi_vhci_register() failed"); 4997c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate * Create the "fabric" devctl minor-node for IB DR support. 5057c478bd9Sstevel@tonic-gate * The minor number for the "devctl" node is in the same format 5067c478bd9Sstevel@tonic-gate * as the AP minor nodes. 5077c478bd9Sstevel@tonic-gate */ 5087c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance, 5097c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 5107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5117c478bd9Sstevel@tonic-gate "\tattach: failed to create fabric minornode"); 5127c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5137c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate /* 5187c478bd9Sstevel@tonic-gate * Set pm-want-child-notification property for 5197c478bd9Sstevel@tonic-gate * power management of the phci and client 5207c478bd9Sstevel@tonic-gate */ 5217c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 5227c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 5237c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5247c478bd9Sstevel@tonic-gate "_attach: create pm-want-child-notification failed"); 5257c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5267c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5277c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 5317c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = dip; 5327c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* 5357c478bd9Sstevel@tonic-gate * Event Handling: Definition and Binding. 5367c478bd9Sstevel@tonic-gate */ 5377c478bd9Sstevel@tonic-gate if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl, 5387c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5397c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5417c478bd9Sstevel@tonic-gate "_attach: ndi_event_alloc_hdl failed"); 5427c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5437c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events, 5467c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5477c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5487c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl); 5497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5507c478bd9Sstevel@tonic-gate "_attach: ndi_event_bind_set failed"); 5517c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5527c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate for (i = 0; i < N_IBNEX_PROPS; i++) { 5567c478bd9Sstevel@tonic-gate if (ibnex_comm_svc_init(ibnex_properties[i].name, 5577c478bd9Sstevel@tonic-gate ibnex_properties[i].type) != IBNEX_SUCCESS) { 5587c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 5597c478bd9Sstevel@tonic-gate (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl, 5607c478bd9Sstevel@tonic-gate &ib_ndi_events, NDI_SLEEP); 5617c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5627c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl( 5637c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl); 5647c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 5657c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init" 5667c478bd9Sstevel@tonic-gate " failed %s", ibnex_properties[i].name); 5677c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5687c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate /* 5737c478bd9Sstevel@tonic-gate * before anything else comes up: 5747c478bd9Sstevel@tonic-gate * Initialize the internal list of pseudo device nodes by 5757c478bd9Sstevel@tonic-gate * getting all pseudo children of "ib" and processing them. 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate /* 5847c478bd9Sstevel@tonic-gate * ibnex_getinfo() 5857c478bd9Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 5867c478bd9Sstevel@tonic-gate * instance number. 5877c478bd9Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5917c478bd9Sstevel@tonic-gate static int 5927c478bd9Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 5937c478bd9Sstevel@tonic-gate { 5947c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin"); 5977c478bd9Sstevel@tonic-gate switch (cmd) { 5987c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 5997c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) 6007c478bd9Sstevel@tonic-gate *result = ibnex.ibnex_dip; 6017c478bd9Sstevel@tonic-gate else { 6027c478bd9Sstevel@tonic-gate *result = NULL; 6037c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate break; 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 6087c478bd9Sstevel@tonic-gate *result = 0; 6097c478bd9Sstevel@tonic-gate break; 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate default: 6127c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate return (ret); 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate /* 6197c478bd9Sstevel@tonic-gate * ibnex_detach 6207c478bd9Sstevel@tonic-gate * Unregister callback with the IBDM 6217c478bd9Sstevel@tonic-gate * Unregister callback with the IBTL 6227c478bd9Sstevel@tonic-gate * Uninitialize the communication entries 6237c478bd9Sstevel@tonic-gate * Remove all the minor nodes created by this instance 6247c478bd9Sstevel@tonic-gate */ 6257c478bd9Sstevel@tonic-gate static int 6267c478bd9Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 6277c478bd9Sstevel@tonic-gate { 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd); 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate switch (cmd) { 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate case DDI_DETACH: 6347c478bd9Sstevel@tonic-gate break; 6357c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 6367c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend"); 6377c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6387c478bd9Sstevel@tonic-gate default: 6397c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 6437c478bd9Sstevel@tonic-gate if (ibt_hw_is_present()) { 6447c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6457c478bd9Sstevel@tonic-gate "\tdetach: IB HW is present "); 6467c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6477c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) { 6507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6517c478bd9Sstevel@tonic-gate "\tdetach: ndi_event_free_hdl() failed"); 6527c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6537c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6547c478bd9Sstevel@tonic-gate } 6557c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 6567c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = NULL; 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(); 6597c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 6607c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup(); 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 6637c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = NULL; 6647c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6657c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 6667c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * ibnex_pseudo_node_cleanup() 6727c478bd9Sstevel@tonic-gate * This checks if all the "dips" have been deallocated (implying 6737c478bd9Sstevel@tonic-gate * that all the children have been unconfigured) first. 6747c478bd9Sstevel@tonic-gate * If not, it just returns. 6757c478bd9Sstevel@tonic-gate * If yes, then it frees up memory allocated for devi_name, 6767c478bd9Sstevel@tonic-gate * node_addr, and property list. 6777c478bd9Sstevel@tonic-gate */ 6787c478bd9Sstevel@tonic-gate static void 6797c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void) 6807c478bd9Sstevel@tonic-gate { 6817c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head; 6827c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:"); 6857c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate for (; nodep; nodep = nodep->node_next) 6887c478bd9Sstevel@tonic-gate if (nodep->node_dip) 6897c478bd9Sstevel@tonic-gate return; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory"); 6927c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 6937c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node; 6967c478bd9Sstevel@tonic-gate if (pseudo->pseudo_node_addr) { 6977c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_node_addr, 6987c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_node_addr) + 1); 6997c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr = NULL; 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate if (pseudo->pseudo_devi_name) { 7037c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_devi_name, 7047c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_devi_name) + 1); 7057c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name = NULL; 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate if (pseudo->pseudo_unit_addr) { 7097c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_unit_addr, 7107c478bd9Sstevel@tonic-gate pseudo->pseudo_unit_addr_len); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * This functions wakes up any reprobe requests waiting for completion 7187c478bd9Sstevel@tonic-gate * of reprobe of this IOC. It also send an NDI event, if : 7197c478bd9Sstevel@tonic-gate * 7207c478bd9Sstevel@tonic-gate * notify_flag is set. This is set if : 7217c478bd9Sstevel@tonic-gate * ibt_reprobe_ioc has returned with SUCCESS 7227c478bd9Sstevel@tonic-gate * IBTF client has not been notified for this node. 7237c478bd9Sstevel@tonic-gate * node_data->node_dip != NULL 7247c478bd9Sstevel@tonic-gate * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set 7257c478bd9Sstevel@tonic-gate * An NDI event cookie has been registered. 7267c478bd9Sstevel@tonic-gate */ 7277c478bd9Sstevel@tonic-gate static void 7287c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag) 7297c478bd9Sstevel@tonic-gate { 7307c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7337c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) || 7367c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state != 0)) { 7377c478bd9Sstevel@tonic-gate if (notify_flag && (node_data->node_dip != NULL) && 7387c478bd9Sstevel@tonic-gate (node_data->node_state & 7397c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) && 7407c478bd9Sstevel@tonic-gate (evt_cookie != NULL)) { 7417c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate bzero(&evt_data, sizeof (evt_data)); 7467c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, 7477c478bd9Sstevel@tonic-gate node_data->node_dip, 7487c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 7497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 7507c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7567c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate * This function wakes up any reprobe request waiting for completion 7637c478bd9Sstevel@tonic-gate * of reprobe of all IOCs. 7647c478bd9Sstevel@tonic-gate */ 7657c478bd9Sstevel@tonic-gate static void 7667c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all() 7677c478bd9Sstevel@tonic-gate { 7687c478bd9Sstevel@tonic-gate ibnex_node_data_t *ioc_node; 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate /* Notify if another reprobe_all is pending */ 7737c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) { 7747c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7757c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7767c478bd9Sstevel@tonic-gate } 7777c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate /* 7807c478bd9Sstevel@tonic-gate * The IOC may be hot-removed after the reprobe request. 7817c478bd9Sstevel@tonic-gate * Reset the reprobe states for such IOCs. 7827c478bd9Sstevel@tonic-gate */ 7837c478bd9Sstevel@tonic-gate for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node; 7847c478bd9Sstevel@tonic-gate ioc_node = ioc_node->node_next) { 7857c478bd9Sstevel@tonic-gate if (ioc_node->node_reprobe_state != 0) { 7867c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ioc_node, 1); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate /* 7927c478bd9Sstevel@tonic-gate * ibnex_ibnex_callback: 7937c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_INIT: 7947c478bd9Sstevel@tonic-gate * Called from ibc_init() which is called from 7957c478bd9Sstevel@tonic-gate * HCA driver _init entry point 7967c478bd9Sstevel@tonic-gate * Initializes the HCA dev_ops structure with default 7977c478bd9Sstevel@tonic-gate * IB nexus structure. 7987c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_FINI: 7997c478bd9Sstevel@tonic-gate * Called from ibc_fini() which is called from 8007c478bd9Sstevel@tonic-gate * HCA driver _fini entry point 8017c478bd9Sstevel@tonic-gate * Un-Initializes the HCA dev_ops structure with default 8027c478bd9Sstevel@tonic-gate * IB nexus strucuture. 8037c478bd9Sstevel@tonic-gate * Returns IBT_SUCCESS 8047c478bd9Sstevel@tonic-gate */ 8057c478bd9Sstevel@tonic-gate ibt_status_t 8067c478bd9Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args) 8077c478bd9Sstevel@tonic-gate { 8087c478bd9Sstevel@tonic-gate int retval = IBT_SUCCESS; 8097c478bd9Sstevel@tonic-gate struct dev_ops *hca_dev_ops; 8107c478bd9Sstevel@tonic-gate dev_info_t *clnt_dip; 8117c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tibtl_callback"); 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate switch (cb_args->cb_flag) { 8167c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_INIT: 8177c478bd9Sstevel@tonic-gate /* 8187c478bd9Sstevel@tonic-gate * Get the devops structure of the HCA, 8197c478bd9Sstevel@tonic-gate * and put IB nexus default busops vector in its place. 8207c478bd9Sstevel@tonic-gate */ 8217c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8227c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8237c478bd9Sstevel@tonic-gate ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL)); 8247c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = &ibnex_ci_busops; 8257c478bd9Sstevel@tonic-gate break; 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_FINI: 8287c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8297c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8307c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = NULL; 8317c478bd9Sstevel@tonic-gate break; 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate case IBTL_IBNEX_REPROBE_DEV_REQ: 8347c478bd9Sstevel@tonic-gate /* IBTL pass down request for ibt_reprobe_dev */ 8357c478bd9Sstevel@tonic-gate clnt_dip = cb_args->cb_dip; 8367c478bd9Sstevel@tonic-gate ASSERT(clnt_dip); 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(clnt_dip); 8397c478bd9Sstevel@tonic-gate ASSERT(node_data); 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate /* Reprobe for IOC nodes only */ 8427c478bd9Sstevel@tonic-gate ASSERT(node_data->node_type == IBNEX_IOC_NODE); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate /* 8457c478bd9Sstevel@tonic-gate * Start the reprobe. This could sleep as it is not 8467c478bd9Sstevel@tonic-gate * from interrupt context. 8477c478bd9Sstevel@tonic-gate */ 8487c478bd9Sstevel@tonic-gate if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev, 8497c478bd9Sstevel@tonic-gate clnt_dip, TQ_SLEEP) == 0) { 8507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 8517c478bd9Sstevel@tonic-gate "ibnex_ibtl_callback: taskq_dispatch failed"); 8527c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 8537c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 8547c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 8557c478bd9Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE); 8567c478bd9Sstevel@tonic-gate } 8577c478bd9Sstevel@tonic-gate return (IBT_SUCCESS); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate return (retval); 8617c478bd9Sstevel@tonic-gate } 8627c478bd9Sstevel@tonic-gate 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * Bus-ops entry points 8667c478bd9Sstevel@tonic-gate */ 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 8697c478bd9Sstevel@tonic-gate * ibnex_map_fault 8707c478bd9Sstevel@tonic-gate * IOC drivers need not map memory. Return failure to fail any 8717c478bd9Sstevel@tonic-gate * such calls. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8747c478bd9Sstevel@tonic-gate static int 8757c478bd9Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat, 8767c478bd9Sstevel@tonic-gate struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn, 8777c478bd9Sstevel@tonic-gate uint_t prot, uint_t lock) 8787c478bd9Sstevel@tonic-gate { 8797c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8807c478bd9Sstevel@tonic-gate } 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate /* 8847c478bd9Sstevel@tonic-gate * ibnex_busctl 8857c478bd9Sstevel@tonic-gate * bus_ctl bus_ops entry point 8867c478bd9Sstevel@tonic-gate */ 8877c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8887c478bd9Sstevel@tonic-gate static int 8897c478bd9Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip, 8907c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 8917c478bd9Sstevel@tonic-gate { 8927c478bd9Sstevel@tonic-gate dev_info_t *child_dip; 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 8957c478bd9Sstevel@tonic-gate "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop); 8967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result); 8977c478bd9Sstevel@tonic-gate 8987c478bd9Sstevel@tonic-gate switch (ctlop) { 8997c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 9007c478bd9Sstevel@tonic-gate if (rdip == NULL) { 9017c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate /* Log the relevant details of dip to sysbuf */ 9057c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n", 9067c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 9077c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 9127c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9137c478bd9Sstevel@tonic-gate return (ibnex_init_child(child_dip)); 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 9167c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9177c478bd9Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL); 9187c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 9217c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 9227c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POWER : 9237c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 9267c478bd9Sstevel@tonic-gate /* 9277c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and 9287c478bd9Sstevel@tonic-gate * DDI_FAILURE for the nodes enumerated by a Pseudo file. 9297c478bd9Sstevel@tonic-gate */ 9307c478bd9Sstevel@tonic-gate return (ndi_dev_is_persistent_node(rdip) ? 9317c478bd9Sstevel@tonic-gate DDI_SUCCESS : DDI_FAILURE); 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 9357c478bd9Sstevel@tonic-gate /* 9367c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS, so that consistent buf alloc 9377c478bd9Sstevel@tonic-gate * gets the default DMA IO minimum for the platform 9387c478bd9Sstevel@tonic-gate */ 9397c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate /* 9427c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be 9437c478bd9Sstevel@tonic-gate * called by IB Nexus driver. 9447c478bd9Sstevel@tonic-gate */ 9457c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 9467c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 9477c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 9487c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 9497c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 9507c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 9517c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: 9527c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 9537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 9547c478bd9Sstevel@tonic-gate "%s%d: invalid op (%d) from %s inst%d", 9557c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 9567c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 9577c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate /* 9607c478bd9Sstevel@tonic-gate * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we 9617c478bd9Sstevel@tonic-gate * pass up 9627c478bd9Sstevel@tonic-gate */ 9637c478bd9Sstevel@tonic-gate default: 9647c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate /* 9707c478bd9Sstevel@tonic-gate * ibnex_init_child() 9717c478bd9Sstevel@tonic-gate * 9727c478bd9Sstevel@tonic-gate * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD 9737c478bd9Sstevel@tonic-gate * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED. 9747c478bd9Sstevel@tonic-gate */ 9757c478bd9Sstevel@tonic-gate static int 9767c478bd9Sstevel@tonic-gate ibnex_init_child(dev_info_t *child) 9777c478bd9Sstevel@tonic-gate { 9787c478bd9Sstevel@tonic-gate int ret; 9797c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child); 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate /* Handle Pseudo nodes of client children */ 9847c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 9859d3d2ed0Shiremath /* Skip nodes without ib-node-type="merge" */ 9869d3d2ed0Shiremath if (ibnex_is_merge_node(child) != IBNEX_SUCCESS) 9879d3d2ed0Shiremath return (DDI_FAILURE); 9889d3d2ed0Shiremath 9897c478bd9Sstevel@tonic-gate if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS) 9907c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 9937c478bd9Sstevel@tonic-gate /* 9947c478bd9Sstevel@tonic-gate * Merge the .conf node 9957c478bd9Sstevel@tonic-gate */ 9967c478bd9Sstevel@tonic-gate if (ndi_merge_node(child, 9977c478bd9Sstevel@tonic-gate ibnex_name_child) == DDI_SUCCESS) { 9987c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 9997c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate } 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS) 10067c478bd9Sstevel@tonic-gate return (ret); 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10117c478bd9Sstevel@tonic-gate } 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate int 10157c478bd9Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name) 10167c478bd9Sstevel@tonic-gate { 10177c478bd9Sstevel@tonic-gate char **unit_addr; 10187c478bd9Sstevel@tonic-gate uint_t n; 10197c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 10207c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 10217c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 10229d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 10239d3d2ed0Shiremath "\tname_pseudo_child: cannot find unit-address in %s.conf", 10247c478bd9Sstevel@tonic-gate ddi_get_name(child)); 10257c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 10287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 10297c478bd9Sstevel@tonic-gate " not well-formed", ddi_get_name(child)); 10307c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10317c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr); 10347c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10357c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10367c478bd9Sstevel@tonic-gate } 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate 10397c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10407c478bd9Sstevel@tonic-gate int 10417c478bd9Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag) 10427c478bd9Sstevel@tonic-gate { 10437c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 10447c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_datap; 10457c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 10467c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate node_datap = ddi_get_parent_data(child); 10497c478bd9Sstevel@tonic-gate if (node_datap == NULL) { 10507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL"); 10517c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10527c478bd9Sstevel@tonic-gate } 10537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p" 10547c478bd9Sstevel@tonic-gate "Node type %x", node_datap, node_datap->node_type); 10557c478bd9Sstevel@tonic-gate switch (node_datap->node_type) { 10567c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE: 10577c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10587c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10597c478bd9Sstevel@tonic-gate port_node->port_num, 10607c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]); 10617c478bd9Sstevel@tonic-gate break; 10627c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE: 10637c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10647c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s", 10657c478bd9Sstevel@tonic-gate port_node->port_num, port_node->port_pkey, ibnex. 10667c478bd9Sstevel@tonic-gate ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]); 10677c478bd9Sstevel@tonic-gate break; 10687c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE: 10697c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10707c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10717c478bd9Sstevel@tonic-gate port_node->port_num, 10727c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[port_node-> 10737c478bd9Sstevel@tonic-gate port_commsvc_idx]); 10747c478bd9Sstevel@tonic-gate break; 10757c478bd9Sstevel@tonic-gate case IBNEX_IOC_NODE: 10767c478bd9Sstevel@tonic-gate ioc = &node_datap->node_data.ioc_node; 10777c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX", 10787c478bd9Sstevel@tonic-gate (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid); 10797c478bd9Sstevel@tonic-gate break; 10807c478bd9Sstevel@tonic-gate case IBNEX_PSEUDO_NODE: 10817c478bd9Sstevel@tonic-gate pseudo = &node_datap->node_data.pseudo_node; 10827c478bd9Sstevel@tonic-gate (void) snprintf(name, 10837c478bd9Sstevel@tonic-gate IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr); 10847c478bd9Sstevel@tonic-gate break; 10857c478bd9Sstevel@tonic-gate default: 10867c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed"); 10877c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10887c478bd9Sstevel@tonic-gate } 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate /* 10957c478bd9Sstevel@tonic-gate * ibnex_bus_config() 10967c478bd9Sstevel@tonic-gate * 10977c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE: 10987c478bd9Sstevel@tonic-gate * Enumerate the exact instance of the driver. Use the device node name 10997c478bd9Sstevel@tonic-gate * to locate the exact instance. 11007c478bd9Sstevel@tonic-gate * Query IBDM to find whether the hardware exits for the instance of the 11017c478bd9Sstevel@tonic-gate * driver. If exists, create a device node and return NDI_SUCCESS. 11027c478bd9Sstevel@tonic-gate * 11037c478bd9Sstevel@tonic-gate * BUS_CONFIG_ALL: 11047c478bd9Sstevel@tonic-gate * Enumerate all the instances of all the possible children (seen before 11057c478bd9Sstevel@tonic-gate * and never seen before). 11067c478bd9Sstevel@tonic-gate * 11077c478bd9Sstevel@tonic-gate * BUS_CONFIG_DRIVER: 11087c478bd9Sstevel@tonic-gate * Enumerate all the instances of a particular driver. 11097c478bd9Sstevel@tonic-gate */ 11107c478bd9Sstevel@tonic-gate static int 11117c478bd9Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag, 11127c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *devname, dev_info_t **child) 11137c478bd9Sstevel@tonic-gate { 11149d3d2ed0Shiremath int ret = IBNEX_SUCCESS, len, circ, need_bus_config; 11157c478bd9Sstevel@tonic-gate char *device_name, *cname = NULL, *caddr = NULL; 11169d3d2ed0Shiremath char *device_name1; 11177c478bd9Sstevel@tonic-gate char *srvname, nameaddr[MAXNAMELEN]; 11187c478bd9Sstevel@tonic-gate dev_info_t *cdip, *pdip = NULL; 11197c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 11207c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 11215e3986cbScth int use_mdi_devi_locking = 0; 11227c478bd9Sstevel@tonic-gate 112300a3eaf3SRamaswamy Tummala if (parent != ibnex.ibnex_dip) { 112400a3eaf3SRamaswamy Tummala /* 112500a3eaf3SRamaswamy Tummala * This must be an HCA.In a normal case HCA is setup as a phci. 112600a3eaf3SRamaswamy Tummala * If an HCA is in maintenance mode, its phci is not set up 112700a3eaf3SRamaswamy Tummala * but the driver is attached to update the firmware. In this 112800a3eaf3SRamaswamy Tummala * case, do not configure the MPxIO clients. 112900a3eaf3SRamaswamy Tummala */ 113000a3eaf3SRamaswamy Tummala if (mdi_component_is_phci(parent, NULL) == MDI_FAILURE) { 113100a3eaf3SRamaswamy Tummala if (op == BUS_CONFIG_ALL || op == BUS_CONFIG_DRIVER) 113200a3eaf3SRamaswamy Tummala return (NDI_SUCCESS); 113300a3eaf3SRamaswamy Tummala else 113400a3eaf3SRamaswamy Tummala return (NDI_FAILURE); 113500a3eaf3SRamaswamy Tummala } 11365e3986cbScth 11375e3986cbScth /* Set use_mdi_devi_locking appropriately */ 113800a3eaf3SRamaswamy Tummala if ((op != BUS_CONFIG_ONE) || (op == BUS_CONFIG_ONE && 113900a3eaf3SRamaswamy Tummala strncmp((char *)devname, IBNEX_IBPORT_CNAME, 6) != 0)) { 114000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 114100a3eaf3SRamaswamy Tummala "\tbus_config: using mdi_devi_enter"); 11425e3986cbScth use_mdi_devi_locking = 1; 11435e3986cbScth } 114400a3eaf3SRamaswamy Tummala } 11455e3986cbScth 11465e3986cbScth if (use_mdi_devi_locking) 11475e3986cbScth mdi_devi_enter(parent, &circ); 11485e3986cbScth else 11497c478bd9Sstevel@tonic-gate ndi_devi_enter(parent, &circ); 11507c478bd9Sstevel@tonic-gate 11517c478bd9Sstevel@tonic-gate switch (op) { 11527c478bd9Sstevel@tonic-gate case BUS_CONFIG_ONE: 115305fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, " 115405fa0d51Spramodbg "parent %p", parent); 11557c478bd9Sstevel@tonic-gate 11567c478bd9Sstevel@tonic-gate len = strlen((char *)devname) + 1; 11577c478bd9Sstevel@tonic-gate device_name = i_ddi_strdup(devname, KM_SLEEP); 11587c478bd9Sstevel@tonic-gate i_ddi_parse_name(device_name, &cname, &caddr, NULL); 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate if (caddr == NULL || (strlen(caddr) == 0)) { 11617c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 11625e3986cbScth if (use_mdi_devi_locking) 11635e3986cbScth mdi_devi_exit(parent, circ); 11645e3986cbScth else 11657c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 11667c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 11677c478bd9Sstevel@tonic-gate } 11687c478bd9Sstevel@tonic-gate 11699d3d2ed0Shiremath /* 11709d3d2ed0Shiremath * i_ddi_parse_name() strips of the address portion 11719d3d2ed0Shiremath * of the device name. Recreate device name for 11729d3d2ed0Shiremath * ndi_devi_findchild 11739d3d2ed0Shiremath */ 11749d3d2ed0Shiremath device_name1 = i_ddi_strdup(devname, KM_SLEEP); 11759d3d2ed0Shiremath 11767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 11777c478bd9Sstevel@tonic-gate "\tbus_config: cname %s addr %s", cname, caddr); 11787c478bd9Sstevel@tonic-gate 11799d3d2ed0Shiremath cdip = ndi_devi_findchild(parent, device_name1); 118000a3eaf3SRamaswamy Tummala if (cdip) 118100a3eaf3SRamaswamy Tummala node_data = ddi_get_parent_data(cdip); 11829d3d2ed0Shiremath kmem_free(device_name1, len); 118300a3eaf3SRamaswamy Tummala if (cdip == NULL || (node_data != NULL && 118400a3eaf3SRamaswamy Tummala node_data->node_dip == NULL)) { 11857c478bd9Sstevel@tonic-gate /* Node is not present */ 11867c478bd9Sstevel@tonic-gate if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) { 11875e3986cbScth if (use_mdi_devi_locking) 11885e3986cbScth mdi_devi_exit(parent, circ); 11895e3986cbScth else 11909d3d2ed0Shiremath ndi_devi_exit(parent, circ); 11915e3986cbScth 11929d3d2ed0Shiremath ret = ibnex_ioc_bus_config_one(&parent, flag, 11939d3d2ed0Shiremath op, devname, child, &need_bus_config); 119405fa0d51Spramodbg if (!need_bus_config) { 119505fa0d51Spramodbg kmem_free(device_name, len); 11969d3d2ed0Shiremath return (ret); 119705fa0d51Spramodbg } 11989d3d2ed0Shiremath 11995e3986cbScth if (use_mdi_devi_locking) 12005e3986cbScth mdi_devi_enter(parent, &circ); 12015e3986cbScth else 12029d3d2ed0Shiremath ndi_devi_enter(parent, &circ); 12037c478bd9Sstevel@tonic-gate } else if ((strncmp(cname, 12047c478bd9Sstevel@tonic-gate IBNEX_IBPORT_CNAME, 6) == 0) && 12057c478bd9Sstevel@tonic-gate (parent != ibnex.ibnex_dip)) { /* parent is HCA */ 12067c478bd9Sstevel@tonic-gate cdip = ibnex_config_port_node(parent, devname); 12077c478bd9Sstevel@tonic-gate if (cdip) 12087c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 12097c478bd9Sstevel@tonic-gate else 12107c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12119d3d2ed0Shiremath } else { 12127c478bd9Sstevel@tonic-gate /* 12137c478bd9Sstevel@tonic-gate * if not IOC or PORT device then always 12147c478bd9Sstevel@tonic-gate * assume a Pseudo child 12159d3d2ed0Shiremath * 12169d3d2ed0Shiremath * if IB Nexus is the parent, call MDI. 12179d3d2ed0Shiremath * else if HCA is the parent, enumerate 12189d3d2ed0Shiremath * the Pseudo node. 12197c478bd9Sstevel@tonic-gate */ 12207c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 12217c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 12229d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 12235e3986cbScth if (use_mdi_devi_locking) 12245e3986cbScth mdi_devi_exit(parent, circ); 12255e3986cbScth else 12269d3d2ed0Shiremath ndi_devi_exit(parent, circ); 12275e3986cbScth 12287c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 12299d3d2ed0Shiremath ret = ibnex_pseudo_mdi_config_one( 12309d3d2ed0Shiremath flag, devname, child, cname, 12319d3d2ed0Shiremath caddr); 12327c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 123305fa0d51Spramodbg kmem_free(device_name, len); 12349d3d2ed0Shiremath return (ret); 12359d3d2ed0Shiremath } 12369d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 123705fa0d51Spramodbg ret = ibnex_pseudo_config_one(NULL, 12389d3d2ed0Shiremath caddr, parent); 12399d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 12409d3d2ed0Shiremath } 12417c478bd9Sstevel@tonic-gate } 1242a1e3386eShiremath 1243a1e3386eShiremath if (strncmp(cname, IBNEX_IBPORT_CNAME, 6) == 0) { 1244a1e3386eShiremath /* Allows enumeration under PHCI */ 1245a1e3386eShiremath flag |= NDI_MDI_FALLBACK; 1246a1e3386eShiremath } 12477c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 12487c478bd9Sstevel@tonic-gate break; 12497c478bd9Sstevel@tonic-gate 12507c478bd9Sstevel@tonic-gate case BUS_CONFIG_OBP_ARGS: 12517c478bd9Sstevel@tonic-gate cdip = ibnex_config_obp_args(parent, devname); 12527c478bd9Sstevel@tonic-gate if (cdip) { 12537c478bd9Sstevel@tonic-gate /* 12547c478bd9Sstevel@tonic-gate * Boot case. 12557c478bd9Sstevel@tonic-gate * Special handling because the "devname" 12567c478bd9Sstevel@tonic-gate * format for the enumerated device is 12577c478bd9Sstevel@tonic-gate * different. 12587c478bd9Sstevel@tonic-gate */ 12597c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 12607c478bd9Sstevel@tonic-gate port_node = &node_data->node_data.port_node; 12617c478bd9Sstevel@tonic-gate if (node_data->node_type == 12627c478bd9Sstevel@tonic-gate IBNEX_VPPA_COMMSVC_NODE) { 12637c478bd9Sstevel@tonic-gate srvname = 12647c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[ 12657c478bd9Sstevel@tonic-gate port_node->port_commsvc_idx]; 12667c478bd9Sstevel@tonic-gate (void) snprintf(nameaddr, MAXNAMELEN, 12677c478bd9Sstevel@tonic-gate "ibport@%x,%x,%s", 12687c478bd9Sstevel@tonic-gate port_node->port_num, 12697c478bd9Sstevel@tonic-gate port_node->port_pkey, srvname); 12707c478bd9Sstevel@tonic-gate } 12717c478bd9Sstevel@tonic-gate devname = (void *)nameaddr; 12727c478bd9Sstevel@tonic-gate } else { 12737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 12747c478bd9Sstevel@tonic-gate "\tbus_config: CONFIG_OBP_ARGS : invalid state!!"); 12757c478bd9Sstevel@tonic-gate 12767c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate break; 12797c478bd9Sstevel@tonic-gate case BUS_CONFIG_ALL: 12809d3d2ed0Shiremath /*FALLTHRU*/ 12817c478bd9Sstevel@tonic-gate case BUS_CONFIG_DRIVER: 12829d3d2ed0Shiremath if (op == BUS_CONFIG_ALL) 128305fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, " 128405fa0d51Spramodbg "parent %p", parent); 12859d3d2ed0Shiremath else 128605fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER" 128705fa0d51Spramodbg ", parent %p", parent); 12887c478bd9Sstevel@tonic-gate 12899d3d2ed0Shiremath /* 12905e3986cbScth * No locks to be held while calling mdi_vhci_bus_config() 12915e3986cbScth * ibnex_config_all_children() holds appropriate locks. 12925e3986cbScth */ 12935e3986cbScth if (use_mdi_devi_locking) 12945e3986cbScth mdi_devi_exit(parent, circ); 12955e3986cbScth else 12965e3986cbScth ndi_devi_exit(parent, circ); 12975e3986cbScth 12985e3986cbScth /* 12999d3d2ed0Shiremath * Drive CONFIG requests for IB Nexus parent through 13009d3d2ed0Shiremath * MDI. This is needed to load the HCA drivers in x86 SRP 13019d3d2ed0Shiremath * boot case. 13029d3d2ed0Shiremath * 13039d3d2ed0Shiremath * CONFIG Requests with HCA parent will probe devices using 13049d3d2ed0Shiremath * ibdm and configure all children. 13059d3d2ed0Shiremath */ 13069d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 130751f34d4bSRajkumar Sivaprakasam ibdm_ioc_info_t *ioc_list, *new_ioc_list; 130800a3eaf3SRamaswamy Tummala 130951f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex); 131051f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state != 131151f34d4bSRajkumar Sivaprakasam IBNEX_IOC_LIST_READY) { 131251f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv, 131351f34d4bSRajkumar Sivaprakasam &ibnex.ibnex_mutex); 131451f34d4bSRajkumar Sivaprakasam } 131551f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW; 131651f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex); 131751f34d4bSRajkumar Sivaprakasam /* Enumerate all the IOC's */ 131851f34d4bSRajkumar Sivaprakasam ibdm_ibnex_port_settle_wait(0, 131951f34d4bSRajkumar Sivaprakasam ibnex_port_settling_time); 132051f34d4bSRajkumar Sivaprakasam 132151f34d4bSRajkumar Sivaprakasam new_ioc_list = ibdm_ibnex_get_ioc_list( 132251f34d4bSRajkumar Sivaprakasam IBDM_IBNEX_NORMAL_PROBE); 132351f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", 132451f34d4bSRajkumar Sivaprakasam "\tbus_config: alloc ioc_list %p", new_ioc_list); 132500a3eaf3SRamaswamy Tummala /* 132600a3eaf3SRamaswamy Tummala * Optimize the calls for each BUS_CONFIG_ALL request 132700a3eaf3SRamaswamy Tummala * to the IB Nexus dip. This is currently done for 132800a3eaf3SRamaswamy Tummala * each PDIP. 132900a3eaf3SRamaswamy Tummala */ 133051f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex); 133151f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list; 133251f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list = new_ioc_list; 133351f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 133451f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv); 133551f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex); 133651f34d4bSRajkumar Sivaprakasam 133751f34d4bSRajkumar Sivaprakasam if (ioc_list) { 133800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 133900a3eaf3SRamaswamy Tummala "\tbus_config: freeing ioc_list %p", 134051f34d4bSRajkumar Sivaprakasam ioc_list); 134151f34d4bSRajkumar Sivaprakasam ibdm_ibnex_free_ioc_list(ioc_list); 134200a3eaf3SRamaswamy Tummala } 134300a3eaf3SRamaswamy Tummala 134400a3eaf3SRamaswamy Tummala 13459d3d2ed0Shiremath ret = mdi_vhci_bus_config(parent, 13469d3d2ed0Shiremath flag, op, devname, child, NULL); 13479d3d2ed0Shiremath return (ret); 13489d3d2ed0Shiremath } else { 13499d3d2ed0Shiremath ibnex_config_all_children(parent); 13505e3986cbScth 13515e3986cbScth if (use_mdi_devi_locking) 13525e3986cbScth mdi_devi_enter(parent, &circ); 13535e3986cbScth else 13545e3986cbScth ndi_devi_enter(parent, &circ); 13559d3d2ed0Shiremath } 13569d3d2ed0Shiremath break; 13577c478bd9Sstevel@tonic-gate default: 13587c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config: error"); 13597c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 13607c478bd9Sstevel@tonic-gate break; 13617c478bd9Sstevel@tonic-gate } 13625e3986cbScth 13635e3986cbScth if (use_mdi_devi_locking) 13645e3986cbScth mdi_devi_exit(parent, circ); 13655e3986cbScth else 13667c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 13675e3986cbScth 13687c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 13697c478bd9Sstevel@tonic-gate if (op == BUS_CONFIG_OBP_ARGS) 13707c478bd9Sstevel@tonic-gate op = BUS_CONFIG_ONE; 13717c478bd9Sstevel@tonic-gate 13727c478bd9Sstevel@tonic-gate if (pdip == NULL) 13737c478bd9Sstevel@tonic-gate pdip = parent; 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate ret = ndi_busop_bus_config( 13767c478bd9Sstevel@tonic-gate pdip, flag, op, devname, child, 0); 13777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config:" 13787c478bd9Sstevel@tonic-gate "ndi_busop_bus_config : retval %d", ret); 13797c478bd9Sstevel@tonic-gate return (ret); 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 13837c478bd9Sstevel@tonic-gate } 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate /* 13877c478bd9Sstevel@tonic-gate * ibnex_config_root_iocnode() 13887c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 13897c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 13907c478bd9Sstevel@tonic-gate */ 13917c478bd9Sstevel@tonic-gate static int 13927c478bd9Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name) 13937c478bd9Sstevel@tonic-gate { 13947c478bd9Sstevel@tonic-gate int ret, port = 0, iter = 0; 13957c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 13967c478bd9Sstevel@tonic-gate char *portstr; 13977c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, iou_guid, ioc_guid; 13987c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 13997c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 14027c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: name %s", device_name); 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate portstr = strstr(device_name, ":port="); 14057c478bd9Sstevel@tonic-gate if (portstr == NULL) { 14067c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate portstr[0] = 0; portstr++; 14107c478bd9Sstevel@tonic-gate if (ibnex_devname2port(portstr, &port)) { 14117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port"); 14127c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14137c478bd9Sstevel@tonic-gate } 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 14169d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 14177c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14187c478bd9Sstevel@tonic-gate } 14197c478bd9Sstevel@tonic-gate 14207c478bd9Sstevel@tonic-gate (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4), 14217c478bd9Sstevel@tonic-gate "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid); 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 14247c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) { 14257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 14267c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: Port does not exist"); 14277c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14287c478bd9Sstevel@tonic-gate } 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 14317c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 14327c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 14337c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 14347c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 14357c478bd9Sstevel@tonic-gate hca_guid, port)) == NULL) { 14367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate 14397c478bd9Sstevel@tonic-gate if (iter++ == 400) { 14407c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 14417c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 14427c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 14437c478bd9Sstevel@tonic-gate displayed = B_TRUE; 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate } 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 14487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:" 14497c478bd9Sstevel@tonic-gate "Port is initialized"); 14507c478bd9Sstevel@tonic-gate 14517c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) { 14527c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 14537c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 14547c478bd9Sstevel@tonic-gate } 14557c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 145600a3eaf3SRamaswamy Tummala if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) != 145700a3eaf3SRamaswamy Tummala IBNEX_SUCCESS) { 145800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 145900a3eaf3SRamaswamy Tummala "\tconfig_root_ioc_node failed for pdip %p", parent); 146000a3eaf3SRamaswamy Tummala } 14617c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 14627c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 14637c478bd9Sstevel@tonic-gate return (ret); 14647c478bd9Sstevel@tonic-gate } 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate 14677c478bd9Sstevel@tonic-gate static int 14687c478bd9Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port) 14697c478bd9Sstevel@tonic-gate { 14707c478bd9Sstevel@tonic-gate char *temp; 14717c478bd9Sstevel@tonic-gate int ret = IBNEX_FAILURE; 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin"); 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate temp = strchr(portstr, '='); 14767c478bd9Sstevel@tonic-gate if (temp != NULL) { 14777c478bd9Sstevel@tonic-gate temp++; 14787c478bd9Sstevel@tonic-gate *port = ibnex_str2int(temp, strlen(temp), &ret); 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate return (ret); 14817c478bd9Sstevel@tonic-gate } 14827c478bd9Sstevel@tonic-gate 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* 14857c478bd9Sstevel@tonic-gate * ibnex_config_all_children() 14867c478bd9Sstevel@tonic-gate * Wait for lata SM initialization case before enumerating the nodes 14877c478bd9Sstevel@tonic-gate * Get list of HCA's and HCA port information 14887c478bd9Sstevel@tonic-gate * Create device device nodes and its node properties 14897c478bd9Sstevel@tonic-gate * for port nodes and VPPA nodes 14907c478bd9Sstevel@tonic-gate * Get list of all the IOC node information 14917c478bd9Sstevel@tonic-gate * Create device nodes and its properties for all the IOCs 14927c478bd9Sstevel@tonic-gate * if not created already 14937c478bd9Sstevel@tonic-gate * Bind drivers for all the newly created device nodes 14947c478bd9Sstevel@tonic-gate * Support Pseudo nodes enumerated using their .conf file 14957c478bd9Sstevel@tonic-gate */ 14967c478bd9Sstevel@tonic-gate static void 14977c478bd9Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent) 14987c478bd9Sstevel@tonic-gate { 14997c478bd9Sstevel@tonic-gate int ii; 150000a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_list; 15017c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 15027c478bd9Sstevel@tonic-gate ib_guid_t hca_guid; 15035e3986cbScth int circ; 15047c478bd9Sstevel@tonic-gate 15057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin"); 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate /* 15089d3d2ed0Shiremath * Enumerate children of this HCA, port nodes, 15095e3986cbScth * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for 15105e3986cbScth * locking. IB Nexus is enumerating the children 15115e3986cbScth * of HCA, not MPXIO clients. 15127c478bd9Sstevel@tonic-gate */ 15135e3986cbScth ndi_devi_enter(parent, &circ); 15147c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 151500a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time); 15167c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 1517f9edfba4Spramodbg if (hca_list == NULL) { 1518f9edfba4Spramodbg ndi_devi_exit(parent, circ); 15197c478bd9Sstevel@tonic-gate return; 1520f9edfba4Spramodbg } 15217c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr); 15227c478bd9Sstevel@tonic-gate for (ii = 0; ii < hca_list->hl_nports; ii++) { 15237c478bd9Sstevel@tonic-gate ibnex_create_port_nodes( 15247c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 15257c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes( 15267c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 15277c478bd9Sstevel@tonic-gate } 15287c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 15295e3986cbScth ndi_devi_exit(parent, circ); 15305e3986cbScth 15315e3986cbScth /* 15325e3986cbScth * Use mdi_devi_enter() for locking. IB Nexus is 15338b2e16e7Seota * enumerating MPxIO clients. 15345e3986cbScth */ 15355e3986cbScth mdi_devi_enter(parent, &circ); 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 15387c478bd9Sstevel@tonic-gate 15397c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 154051f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) { 154151f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex); 154251f34d4bSRajkumar Sivaprakasam } 154351f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS; 154451f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list; 15457c478bd9Sstevel@tonic-gate while (ioc_list) { 154600a3eaf3SRamaswamy Tummala (void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0); 15477c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 15487c478bd9Sstevel@tonic-gate } 154951f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY; 155051f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv); 15519d3d2ed0Shiremath 15529d3d2ed0Shiremath /* Config IBTF Pseudo clients */ 15539d3d2ed0Shiremath ibnex_config_pseudo_all(parent); 15549d3d2ed0Shiremath 15557c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15565e3986cbScth mdi_devi_exit(parent, circ); 15579d3d2ed0Shiremath 15587c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End"); 15597c478bd9Sstevel@tonic-gate } 15607c478bd9Sstevel@tonic-gate 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate /* 15637c478bd9Sstevel@tonic-gate * ibnex_create_port_nodes: 15647c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15657c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 15667c478bd9Sstevel@tonic-gate */ 15677c478bd9Sstevel@tonic-gate static void 15687c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15697c478bd9Sstevel@tonic-gate { 15707c478bd9Sstevel@tonic-gate int idx; 15717c478bd9Sstevel@tonic-gate dev_info_t *dip; 15727c478bd9Sstevel@tonic-gate int rval; 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15757c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) { 15767c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 15777c478bd9Sstevel@tonic-gate idx, 0, &dip); 15787c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 15797c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 15807c478bd9Sstevel@tonic-gate IBNEX_PORT_COMMSVC_NODE, 0, &rval, 15817c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate } 15847c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate 15887c478bd9Sstevel@tonic-gate /* 15897c478bd9Sstevel@tonic-gate * ibnex_create_vppa_nodes: 15907c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15917c478bd9Sstevel@tonic-gate * in the "vppa-commsvc-list" property and per each PKEY that 15927c478bd9Sstevel@tonic-gate * this particular port supports and per HCA port 15937c478bd9Sstevel@tonic-gate */ 15947c478bd9Sstevel@tonic-gate static void 15957c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15967c478bd9Sstevel@tonic-gate { 15977c478bd9Sstevel@tonic-gate int idx, ii; 15987c478bd9Sstevel@tonic-gate int rval; 15997c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 16007c478bd9Sstevel@tonic-gate dev_info_t *dip; 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin"); 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 16057c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 16067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: " 16077c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 16087c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16097c478bd9Sstevel@tonic-gate return; 16107c478bd9Sstevel@tonic-gate } 16117c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) { 16127c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 16137c478bd9Sstevel@tonic-gate pkey = port_attr->pa_pkey_tbl[ii].pt_pkey; 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate if (IBNEX_INVALID_PKEY(pkey)) { 16167c478bd9Sstevel@tonic-gate continue; 16177c478bd9Sstevel@tonic-gate } 16187c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid( 16197c478bd9Sstevel@tonic-gate port_attr->pa_port_guid, idx, pkey, &dip); 162000a3eaf3SRamaswamy Tummala if ((rval != IBNEX_SUCCESS) || (dip == NULL)) { 16217c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, 16227c478bd9Sstevel@tonic-gate idx, IBNEX_VPPA_COMMSVC_NODE, 16237c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 16247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tcreate_vppa_nodes: " 16257c478bd9Sstevel@tonic-gate "commsvc_initnode failed rval %x", rval); 16267c478bd9Sstevel@tonic-gate } 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate /* 16347c478bd9Sstevel@tonic-gate * ibnex_create_hcasvc_nodes: 16357c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 16367c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 16377c478bd9Sstevel@tonic-gate */ 16387c478bd9Sstevel@tonic-gate static void 16397c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 16407c478bd9Sstevel@tonic-gate { 16417c478bd9Sstevel@tonic-gate int idx; 16427c478bd9Sstevel@tonic-gate dev_info_t *dip; 16437c478bd9Sstevel@tonic-gate int rval; 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 16467c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) { 16477c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 16487c478bd9Sstevel@tonic-gate idx, 0, &dip); 16497c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 16507c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 16517c478bd9Sstevel@tonic-gate IBNEX_HCASVC_COMMSVC_NODE, 0, &rval, 16527c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 16537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: " 16547c478bd9Sstevel@tonic-gate "commsvc_initnode failed, rval %x", rval); 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate } 16577c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16587c478bd9Sstevel@tonic-gate } 16597c478bd9Sstevel@tonic-gate 16607c478bd9Sstevel@tonic-gate 16617c478bd9Sstevel@tonic-gate /* 16627c478bd9Sstevel@tonic-gate * ibnex_bus_unconfig() 16637c478bd9Sstevel@tonic-gate * 16647c478bd9Sstevel@tonic-gate * Unconfigure a particular device node or all instance of a device 16657c478bd9Sstevel@tonic-gate * driver device or all children of IBnex 16667c478bd9Sstevel@tonic-gate */ 16677c478bd9Sstevel@tonic-gate static int 16687c478bd9Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent, 16697c478bd9Sstevel@tonic-gate uint_t flag, ddi_bus_config_op_t op, void *device_name) 16707c478bd9Sstevel@tonic-gate { 167100a3eaf3SRamaswamy Tummala ibnex_node_data_t *ndp; 167200a3eaf3SRamaswamy Tummala major_t major = (major_t)(uintptr_t)device_name; 167300a3eaf3SRamaswamy Tummala dev_info_t *dip = NULL; 167400a3eaf3SRamaswamy Tummala 167500a3eaf3SRamaswamy Tummala if (ndi_busop_bus_unconfig(parent, flag, op, device_name) != 167600a3eaf3SRamaswamy Tummala DDI_SUCCESS) 167700a3eaf3SRamaswamy Tummala return (DDI_FAILURE); 167800a3eaf3SRamaswamy Tummala 167900a3eaf3SRamaswamy Tummala /* 168000a3eaf3SRamaswamy Tummala * We can come into this routine with dip as ibnexus dip or hca dip. 168100a3eaf3SRamaswamy Tummala * When the dip is that of ib nexus we need to clean up the IOC and 168200a3eaf3SRamaswamy Tummala * pseudo nodes. When the dip is that of an HCA (not IB nexus dip) 168300a3eaf3SRamaswamy Tummala * cleanup the port nodes. 168400a3eaf3SRamaswamy Tummala */ 168500a3eaf3SRamaswamy Tummala if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) && 168600a3eaf3SRamaswamy Tummala (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) { 168700a3eaf3SRamaswamy Tummala mutex_enter(&ibnex.ibnex_mutex); 168800a3eaf3SRamaswamy Tummala if (parent != ibnex.ibnex_dip) { 168900a3eaf3SRamaswamy Tummala if (major == -1) { 169000a3eaf3SRamaswamy Tummala /* 169100a3eaf3SRamaswamy Tummala * HCA dip. When major number is -1 HCA is 169200a3eaf3SRamaswamy Tummala * going away cleanup all the port nodes. 169300a3eaf3SRamaswamy Tummala */ 169400a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_port_node_head; 169500a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 169600a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 169700a3eaf3SRamaswamy Tummala 169800a3eaf3SRamaswamy Tummala port_node = &ndp->node_data.port_node; 169900a3eaf3SRamaswamy Tummala if (port_node->port_pdip == parent) { 170000a3eaf3SRamaswamy Tummala port_node->port_pdip = NULL; 170100a3eaf3SRamaswamy Tummala ndp->node_dip = NULL; 170200a3eaf3SRamaswamy Tummala ndp->node_state = 170300a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 170400a3eaf3SRamaswamy Tummala } 170500a3eaf3SRamaswamy Tummala } 170600a3eaf3SRamaswamy Tummala } else { 170700a3eaf3SRamaswamy Tummala /* 170800a3eaf3SRamaswamy Tummala * HCA dip. Cleanup only the port nodes that 170900a3eaf3SRamaswamy Tummala * match the major number. 171000a3eaf3SRamaswamy Tummala */ 171100a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_port_node_head; 171200a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 171300a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 171400a3eaf3SRamaswamy Tummala 171500a3eaf3SRamaswamy Tummala port_node = &ndp->node_data.port_node; 171600a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 171700a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == 171800a3eaf3SRamaswamy Tummala major) && port_node->port_pdip == 171900a3eaf3SRamaswamy Tummala parent) { 172000a3eaf3SRamaswamy Tummala port_node->port_pdip = NULL; 172100a3eaf3SRamaswamy Tummala ndp->node_dip = NULL; 172200a3eaf3SRamaswamy Tummala ndp->node_state = 172300a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 172400a3eaf3SRamaswamy Tummala } 172500a3eaf3SRamaswamy Tummala } 172600a3eaf3SRamaswamy Tummala } 172700a3eaf3SRamaswamy Tummala } else { 172800a3eaf3SRamaswamy Tummala /* 172900a3eaf3SRamaswamy Tummala * IB dip. here we handle IOC and pseudo nodes which 173000a3eaf3SRamaswamy Tummala * are the children of IB nexus. Cleanup only the nodes 173100a3eaf3SRamaswamy Tummala * with matching major number. We also need to cleanup 173200a3eaf3SRamaswamy Tummala * the PathInfo links to the PHCI here. 173300a3eaf3SRamaswamy Tummala */ 173400a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_ioc_node_head; 173500a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 173600a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 173700a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) { 1738*332f545bSEiji Ota (void) ibnex_offline_childdip(dip); 173900a3eaf3SRamaswamy Tummala } 174000a3eaf3SRamaswamy Tummala } 174100a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_pseudo_node_head; 174200a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) { 174300a3eaf3SRamaswamy Tummala dip = ndp->node_dip; 174400a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) { 1745*332f545bSEiji Ota (void) ibnex_offline_childdip(dip); 174600a3eaf3SRamaswamy Tummala } 174700a3eaf3SRamaswamy Tummala } 174800a3eaf3SRamaswamy Tummala } 174900a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex); 175000a3eaf3SRamaswamy Tummala } 175100a3eaf3SRamaswamy Tummala return (DDI_SUCCESS); 17527c478bd9Sstevel@tonic-gate } 17537c478bd9Sstevel@tonic-gate 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate /* 17567c478bd9Sstevel@tonic-gate * ibnex_config_port_node() 17577c478bd9Sstevel@tonic-gate * 17587c478bd9Sstevel@tonic-gate * Configures a particular port / HCA node for a particular 17597c478bd9Sstevel@tonic-gate * communication service. 17607c478bd9Sstevel@tonic-gate * The format of the device_name is 17617c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 17627c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 17637c478bd9Sstevel@tonic-gate * Port# = 0 for HCA_SVC communication service nodes 17647c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 17657c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 17667c478bd9Sstevel@tonic-gate */ 17677c478bd9Sstevel@tonic-gate static dev_info_t * 17687c478bd9Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname) 17697c478bd9Sstevel@tonic-gate { 17707c478bd9Sstevel@tonic-gate int ii, index; 17717c478bd9Sstevel@tonic-gate int rval; 17727c478bd9Sstevel@tonic-gate uint8_t port_num; 17737c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 17747c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 17757c478bd9Sstevel@tonic-gate dev_info_t *cdip; 17767c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 17777c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname); 17807c478bd9Sstevel@tonic-gate 17817c478bd9Sstevel@tonic-gate if (ibnex_get_pkey_commsvc_index_portnum(devname, 17827c478bd9Sstevel@tonic-gate &index, &pkey, &port_num) != IBNEX_SUCCESS) { 17837c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 17847c478bd9Sstevel@tonic-gate "\tconfig_port_node: Invalid Service Name"); 17857c478bd9Sstevel@tonic-gate return (NULL); 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 17897c478bd9Sstevel@tonic-gate if (port_num == 0) { 17907c478bd9Sstevel@tonic-gate /* 17917c478bd9Sstevel@tonic-gate * Use the dummy port attribute for HCA node in hca_list 17927c478bd9Sstevel@tonic-gate * Note : pa_state is always IBT_PORT_ACTIVE. 17937c478bd9Sstevel@tonic-gate */ 17947c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 17957c478bd9Sstevel@tonic-gate ASSERT(hca_list != NULL); 17967c478bd9Sstevel@tonic-gate port_attr = hca_list->hl_hca_port_attr; 17977c478bd9Sstevel@tonic-gate } else { 17987c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 17997c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18007c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 18017c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 18027c478bd9Sstevel@tonic-gate return (NULL); 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 180600a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait( 180700a3eaf3SRamaswamy Tummala hca_guid, ibnex_port_settling_time); 18087c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18097c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 18107c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18117c478bd9Sstevel@tonic-gate return (NULL); 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 18177c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 18187c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 18197c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 18207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 18217c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18227c478bd9Sstevel@tonic-gate if (port_num != 0) 18237c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18247c478bd9Sstevel@tonic-gate else 18257c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 18267c478bd9Sstevel@tonic-gate return (cdip); 18277c478bd9Sstevel@tonic-gate } 18287c478bd9Sstevel@tonic-gate 18297c478bd9Sstevel@tonic-gate if (pkey == 0 && port_num != 0) { 18307c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 18317c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval, 18327c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 18337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18347c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18357c478bd9Sstevel@tonic-gate } else if (pkey == 0 && port_num == 0) { 18367c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 18377c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval, 18387c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 18397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18407c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18417c478bd9Sstevel@tonic-gate } else { 18427c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 18437c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: " 18447c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 18457c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18467c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18477c478bd9Sstevel@tonic-gate return (NULL); 18487c478bd9Sstevel@tonic-gate } 18497c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 18507c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 18517c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 18527c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, 18537c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 18547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18557c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18567c478bd9Sstevel@tonic-gate break; 18577c478bd9Sstevel@tonic-gate } 18587c478bd9Sstevel@tonic-gate } 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18617c478bd9Sstevel@tonic-gate if (port_num != 0) 18627c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18637c478bd9Sstevel@tonic-gate else 18647c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 18657c478bd9Sstevel@tonic-gate return (cdip); 18667c478bd9Sstevel@tonic-gate } 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate /* 18707c478bd9Sstevel@tonic-gate * ibnex_config_obp_args() 18717c478bd9Sstevel@tonic-gate * Configures a particular port node for a IP over IB communication 18727c478bd9Sstevel@tonic-gate * service. 18737c478bd9Sstevel@tonic-gate * The format of the input string "devname" is 18747c478bd9Sstevel@tonic-gate * port=x,pkey=y,protocol=ip,<wanboot options> 18757c478bd9Sstevel@tonic-gate * Thr format of the node name created here is 18767c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 18777c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 18787c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 18797c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 18807c478bd9Sstevel@tonic-gate * 18817c478bd9Sstevel@tonic-gate */ 18827c478bd9Sstevel@tonic-gate static dev_info_t * 18837c478bd9Sstevel@tonic-gate ibnex_config_obp_args(dev_info_t *parent, char *devname) 18847c478bd9Sstevel@tonic-gate { 18857c478bd9Sstevel@tonic-gate int ii, index; 18867c478bd9Sstevel@tonic-gate int rval, iter = 0; 18877c478bd9Sstevel@tonic-gate char *temp; 18887c478bd9Sstevel@tonic-gate uint8_t port_num; 18897c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 18907c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 18917c478bd9Sstevel@tonic-gate dev_info_t *cdip; 18927c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 18937c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_obp_args: %s", devname); 18967c478bd9Sstevel@tonic-gate 18977c478bd9Sstevel@tonic-gate /* Is this OBP node for IPoIB ? */ 18987c478bd9Sstevel@tonic-gate temp = devname; 18997c478bd9Sstevel@tonic-gate do { 19007c478bd9Sstevel@tonic-gate temp = strstr(temp, ",protocol=ip"); 19017c478bd9Sstevel@tonic-gate if (temp == NULL) 19027c478bd9Sstevel@tonic-gate break; 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate if (strlen(devname) > (int)((temp - devname) + 12)) { 19057c478bd9Sstevel@tonic-gate if (temp[12] == ',') 19067c478bd9Sstevel@tonic-gate break; 19077c478bd9Sstevel@tonic-gate } else { 19087c478bd9Sstevel@tonic-gate break; 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate temp++; 19117c478bd9Sstevel@tonic-gate } while (temp); 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate if (temp == NULL) 19147c478bd9Sstevel@tonic-gate return (NULL); 19157c478bd9Sstevel@tonic-gate if (ibnex_prom_devname_to_pkey_n_portnum( 19167c478bd9Sstevel@tonic-gate devname, &pkey, &port_num) != IBNEX_SUCCESS) { 19177c478bd9Sstevel@tonic-gate return (NULL); 19187c478bd9Sstevel@tonic-gate } 19197c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 19207c478bd9Sstevel@tonic-gate if (strcmp(ibnex.ibnex_vppa_comm_svc_names[index], 19217c478bd9Sstevel@tonic-gate "ipib") == 0) { 19227c478bd9Sstevel@tonic-gate break; 19237c478bd9Sstevel@tonic-gate } 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 19277c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 19287c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 19297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 19307c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 19317c478bd9Sstevel@tonic-gate return (NULL); 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 19357c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 19367c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19377c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 19387c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 19397c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 19407c478bd9Sstevel@tonic-gate return (NULL); 19417c478bd9Sstevel@tonic-gate } 19427c478bd9Sstevel@tonic-gate if (iter++ == 400) { 19437c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 19447c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 19457c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 19467c478bd9Sstevel@tonic-gate displayed = B_TRUE; 19477c478bd9Sstevel@tonic-gate } 19487c478bd9Sstevel@tonic-gate } 19497c478bd9Sstevel@tonic-gate } 19507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tPort is initialized"); 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 19537c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 19547c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 19557c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 19567c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 19577c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 19587c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19597c478bd9Sstevel@tonic-gate return (cdip); 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 19627c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 19637c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 19647c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, pkey, &rval, 19657c478bd9Sstevel@tonic-gate IBNEX_CFGADM_ENUMERATE); 19667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 19677c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 19687c478bd9Sstevel@tonic-gate break; 19697c478bd9Sstevel@tonic-gate } 19707c478bd9Sstevel@tonic-gate } 19717c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 19747c478bd9Sstevel@tonic-gate return (cdip); 19757c478bd9Sstevel@tonic-gate } 19767c478bd9Sstevel@tonic-gate 19777c478bd9Sstevel@tonic-gate 19787c478bd9Sstevel@tonic-gate /* 19797c478bd9Sstevel@tonic-gate * ibnex_prom_devname_to_pkey_n_portnum() 19807c478bd9Sstevel@tonic-gate * Parses the device node name and extracts "PKEY" and "port#" 19817c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 19827c478bd9Sstevel@tonic-gate */ 19837c478bd9Sstevel@tonic-gate static int 19847c478bd9Sstevel@tonic-gate ibnex_prom_devname_to_pkey_n_portnum( 19857c478bd9Sstevel@tonic-gate char *devname, ib_pkey_t *pkey, uint8_t *port) 19867c478bd9Sstevel@tonic-gate { 19877c478bd9Sstevel@tonic-gate int ret = IBNEX_SUCCESS; 19887c478bd9Sstevel@tonic-gate char *tmp, *tmp1; 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate if ((tmp = strstr(devname, "port=")) != NULL) { 19917c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 19927c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 19937c478bd9Sstevel@tonic-gate *port = ibnex_str2int(tmp, (tmp1 - tmp), &ret); 19947c478bd9Sstevel@tonic-gate } else 19957c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 19967c478bd9Sstevel@tonic-gate 19977c478bd9Sstevel@tonic-gate if ((ret == IBNEX_SUCCESS) && 19987c478bd9Sstevel@tonic-gate (tmp = strstr(devname, "pkey=")) != NULL) { 19997c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 20007c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 20017c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(tmp, (tmp1 - tmp), &ret); 20027c478bd9Sstevel@tonic-gate } else 20037c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 20047c478bd9Sstevel@tonic-gate 20057c478bd9Sstevel@tonic-gate return (ret); 20067c478bd9Sstevel@tonic-gate } 20077c478bd9Sstevel@tonic-gate 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate /* 20107c478bd9Sstevel@tonic-gate * ibnex_get_pkey_commsvc_index_portnum() 20117c478bd9Sstevel@tonic-gate * Parses the device node name and extracts PKEY, communication 20127c478bd9Sstevel@tonic-gate * service index & Port #. 20137c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20147c478bd9Sstevel@tonic-gate */ 20157c478bd9Sstevel@tonic-gate static int 20167c478bd9Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index, 20177c478bd9Sstevel@tonic-gate ib_pkey_t *pkey, uint8_t *port_num) 20187c478bd9Sstevel@tonic-gate { 20197c478bd9Sstevel@tonic-gate char *srv, **service_name, *temp; 20207c478bd9Sstevel@tonic-gate int ii, ncommsvcs, ret; 20217c478bd9Sstevel@tonic-gate 20227c478bd9Sstevel@tonic-gate if (ibnex_devname_to_portnum(device_name, port_num) != 20237c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 20247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 20257c478bd9Sstevel@tonic-gate "\tget_pkey_commsvc_index_portnum: Invalid PortGuid"); 20267c478bd9Sstevel@tonic-gate return (NULL); 20277c478bd9Sstevel@tonic-gate } 20287c478bd9Sstevel@tonic-gate srv = strchr(device_name, ','); 20297c478bd9Sstevel@tonic-gate if (srv == 0) 20307c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20317c478bd9Sstevel@tonic-gate 20327c478bd9Sstevel@tonic-gate srv++; 20337c478bd9Sstevel@tonic-gate temp = strchr(srv, ','); 20347c478bd9Sstevel@tonic-gate if (temp == 0) 20357c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20367c478bd9Sstevel@tonic-gate temp++; 20377c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret); 20387c478bd9Sstevel@tonic-gate if (ret != IBNEX_SUCCESS) 20397c478bd9Sstevel@tonic-gate return (ret); 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate if (*pkey == 0 && *port_num != 0) { 20427c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_comm_svc_names; 20437c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_num_comm_svcs; 20447c478bd9Sstevel@tonic-gate } else if (*pkey == 0 && *port_num == 0) { 20457c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_hcasvc_comm_svc_names; 20467c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs; 20477c478bd9Sstevel@tonic-gate } else { 20487c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_vppa_comm_svc_names; 20497c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nvppa_comm_svcs; 20507c478bd9Sstevel@tonic-gate } 20517c478bd9Sstevel@tonic-gate 20527c478bd9Sstevel@tonic-gate for (ii = 0; ii < ncommsvcs; ii++) { 20537c478bd9Sstevel@tonic-gate if (strcmp(service_name[ii], temp) == 0) { 20547c478bd9Sstevel@tonic-gate break; 20557c478bd9Sstevel@tonic-gate } 20567c478bd9Sstevel@tonic-gate } 20577c478bd9Sstevel@tonic-gate if (ii == ncommsvcs) 20587c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20597c478bd9Sstevel@tonic-gate 20607c478bd9Sstevel@tonic-gate *index = ii; 20617c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 20627c478bd9Sstevel@tonic-gate } 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate 20657c478bd9Sstevel@tonic-gate /* 20667c478bd9Sstevel@tonic-gate * ibnex_devname_to_portnum() 20677c478bd9Sstevel@tonic-gate * Get portguid from device name 20687c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20697c478bd9Sstevel@tonic-gate */ 20707c478bd9Sstevel@tonic-gate static int 20717c478bd9Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum) 20727c478bd9Sstevel@tonic-gate { 20737c478bd9Sstevel@tonic-gate int ret; 20747c478bd9Sstevel@tonic-gate char *temp1, *temp2; 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate temp1 = strchr(device_name, '@'); 20777c478bd9Sstevel@tonic-gate if (temp1 == NULL) { 20787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20797c478bd9Sstevel@tonic-gate } 20807c478bd9Sstevel@tonic-gate temp2 = strchr(temp1, ','); 20817c478bd9Sstevel@tonic-gate if (temp2 == NULL) 20827c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20837c478bd9Sstevel@tonic-gate temp1++; 20847c478bd9Sstevel@tonic-gate *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret); 20857c478bd9Sstevel@tonic-gate return (ret); 20867c478bd9Sstevel@tonic-gate } 20877c478bd9Sstevel@tonic-gate 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate /* 20907c478bd9Sstevel@tonic-gate * ibnex_config_ioc_node() 20917c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 20927c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20937c478bd9Sstevel@tonic-gate */ 20947c478bd9Sstevel@tonic-gate static int 20959d3d2ed0Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip) 20967c478bd9Sstevel@tonic-gate { 20977c478bd9Sstevel@tonic-gate int ret; 20987c478bd9Sstevel@tonic-gate ib_guid_t iou_guid, ioc_guid; 20997c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 21007c478bd9Sstevel@tonic-gate 21017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin"); 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 21049d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 21057c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate 210800a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time); 21097c478bd9Sstevel@tonic-gate 21107c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == 21117c478bd9Sstevel@tonic-gate NULL) { 21127c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 21137c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21147c478bd9Sstevel@tonic-gate } 21157c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 211600a3eaf3SRamaswamy Tummala ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0); 21177c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 21187c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 211900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x", 212000a3eaf3SRamaswamy Tummala ret); 21217c478bd9Sstevel@tonic-gate return (ret); 21227c478bd9Sstevel@tonic-gate } 21237c478bd9Sstevel@tonic-gate 21247c478bd9Sstevel@tonic-gate 21257c478bd9Sstevel@tonic-gate /* 21267c478bd9Sstevel@tonic-gate * ibnex_devname_to_node_n_ioc_guids() 21277c478bd9Sstevel@tonic-gate * Get node guid and ioc guid from the device name 21287c478bd9Sstevel@tonic-gate * Format of the device node name is: 21297c478bd9Sstevel@tonic-gate * ioc@<IOC GUID>,<IOU GUID> 21307c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 21317c478bd9Sstevel@tonic-gate */ 21327c478bd9Sstevel@tonic-gate static int 21337c478bd9Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids( 21349d3d2ed0Shiremath char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid, 21359d3d2ed0Shiremath char **ioc_guid_strp) 21367c478bd9Sstevel@tonic-gate { 21377c478bd9Sstevel@tonic-gate char *temp1, *temp; 21387c478bd9Sstevel@tonic-gate int len, ret; 21399d3d2ed0Shiremath char *ioc_guid_str; 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:" 21427c478bd9Sstevel@tonic-gate "Device Name %s", device_name); 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate if ((temp = strchr(device_name, '@')) == NULL) { 21457c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21467c478bd9Sstevel@tonic-gate } 21477c478bd9Sstevel@tonic-gate if ((temp1 = strchr(++temp, ',')) == NULL) { 21487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 21497c478bd9Sstevel@tonic-gate } 21507c478bd9Sstevel@tonic-gate *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret); 21517c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 21529d3d2ed0Shiremath if (ioc_guid_strp) { 21539d3d2ed0Shiremath ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1 21549d3d2ed0Shiremath - temp) + 1, KM_SLEEP); 21559d3d2ed0Shiremath (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1); 21569d3d2ed0Shiremath ioc_guid_str[temp1 - temp] = '\0'; 21579d3d2ed0Shiremath } 21587c478bd9Sstevel@tonic-gate len = device_name + strlen(device_name) - ++temp1; 21597c478bd9Sstevel@tonic-gate *iou_guid = ibnex_str2hex(temp1, len, &ret); 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate return (ret); 21627c478bd9Sstevel@tonic-gate } 21637c478bd9Sstevel@tonic-gate 21647c478bd9Sstevel@tonic-gate 21657c478bd9Sstevel@tonic-gate /* 21667c478bd9Sstevel@tonic-gate * ibnex_ioc_initnode() 21677c478bd9Sstevel@tonic-gate * Allocate a pathinfo node for the IOC 21687c478bd9Sstevel@tonic-gate * Initialize the device node 21697c478bd9Sstevel@tonic-gate * Bind driver to the node 21707c478bd9Sstevel@tonic-gate * Update IBnex global data 21717c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY 21727c478bd9Sstevel@tonic-gate */ 217300a3eaf3SRamaswamy Tummala static int 217400a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data, 217500a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 21767c478bd9Sstevel@tonic-gate { 217700a3eaf3SRamaswamy Tummala int rval, node_valid; 217800a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state; 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 218100a3eaf3SRamaswamy Tummala ASSERT(node_data); 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate 21847c478bd9Sstevel@tonic-gate /* 21857c478bd9Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure 21867c478bd9Sstevel@tonic-gate * operation is in progress 21877c478bd9Sstevel@tonic-gate */ 21887c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 218900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 219000a3eaf3SRamaswamy Tummala "\tioc_initnode_pdip : BUSY"); 21917c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate 219400a3eaf3SRamaswamy Tummala prev_state = node_data->node_state; 21957c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 21967c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 21977c478bd9Sstevel@tonic-gate 219800a3eaf3SRamaswamy Tummala rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid); 21997c478bd9Sstevel@tonic-gate 22007c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 22017c478bd9Sstevel@tonic-gate if (rval == IBNEX_SUCCESS) 22027c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 220300a3eaf3SRamaswamy Tummala else if (node_valid) 220400a3eaf3SRamaswamy Tummala node_data->node_state = prev_state; 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate return (rval); 22077c478bd9Sstevel@tonic-gate } 22087c478bd9Sstevel@tonic-gate 22097c478bd9Sstevel@tonic-gate /* 22107c478bd9Sstevel@tonic-gate * ibnex_config_pseudo_all() 22117c478bd9Sstevel@tonic-gate * Configure all the pseudo nodes 22127c478bd9Sstevel@tonic-gate */ 22137c478bd9Sstevel@tonic-gate static void 22149d3d2ed0Shiremath ibnex_config_pseudo_all(dev_info_t *pdip) 22157c478bd9Sstevel@tonic-gate { 22167c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; 22217c478bd9Sstevel@tonic-gate nodep; nodep = nodep->node_next) { 222205fa0d51Spramodbg (void) ibnex_pseudo_config_one(nodep, NULL, pdip); 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate } 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate /* 22287c478bd9Sstevel@tonic-gate * ibnex_pseudo_config_one() 22297c478bd9Sstevel@tonic-gate */ 223005fa0d51Spramodbg static int 223105fa0d51Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr, 22329d3d2ed0Shiremath dev_info_t *pdip) 22337c478bd9Sstevel@tonic-gate { 223405fa0d51Spramodbg int rval; 223500a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo; 223600a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state; 22377c478bd9Sstevel@tonic-gate 223800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)", 223905fa0d51Spramodbg node_data, caddr, pdip); 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate if (node_data == NULL) { 224400a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 224500a3eaf3SRamaswamy Tummala "\tpseudo_config_one: caddr = %s", caddr); 22467c478bd9Sstevel@tonic-gate 224705fa0d51Spramodbg /* 224805fa0d51Spramodbg * This function is now called with PHCI / HCA driver 224905fa0d51Spramodbg * as parent. The format of devicename is : 225005fa0d51Spramodbg * <driver_name>@<driver_name>,<unit_address> 225105fa0d51Spramodbg * The "caddr" part of the devicename matches the 225205fa0d51Spramodbg * format of pseudo_node_addr. 225305fa0d51Spramodbg * 225405fa0d51Spramodbg * Use "caddr" to find a matching Pseudo node entry. 225505fa0d51Spramodbg */ 22567c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 225705fa0d51Spramodbg (void *)caddr, 0, 0); 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate 226000a3eaf3SRamaswamy Tummala if (node_data == NULL) { 226100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 226200a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Invalid node"); 226300a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 226400a3eaf3SRamaswamy Tummala } 226500a3eaf3SRamaswamy Tummala 226600a3eaf3SRamaswamy Tummala if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) { 226700a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 226800a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Unconfigured node"); 226900a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 227000a3eaf3SRamaswamy Tummala } 227100a3eaf3SRamaswamy Tummala 227200a3eaf3SRamaswamy Tummala pseudo = &node_data->node_data.pseudo_node; 227300a3eaf3SRamaswamy Tummala 22747c478bd9Sstevel@tonic-gate /* 22759d3d2ed0Shiremath * Do not enumerate nodes with ib-node-type set as "merge" 22769d3d2ed0Shiremath */ 227700a3eaf3SRamaswamy Tummala if (pseudo->pseudo_merge_node == 1) { 227800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 227900a3eaf3SRamaswamy Tummala "\tpseudo_config_one: merge_node"); 22809d3d2ed0Shiremath return (IBNEX_FAILURE); 22819d3d2ed0Shiremath } 22829d3d2ed0Shiremath 22839d3d2ed0Shiremath /* 228400a3eaf3SRamaswamy Tummala * Check if a PI has already been created for the PDIP. 228500a3eaf3SRamaswamy Tummala * If so, return SUCCESS. 22867c478bd9Sstevel@tonic-gate */ 228700a3eaf3SRamaswamy Tummala if (node_data->node_dip != NULL && mdi_pi_find(pdip, 228800a3eaf3SRamaswamy Tummala pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) { 228900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 229000a3eaf3SRamaswamy Tummala "\tpseudo_config_one: PI created," 229100a3eaf3SRamaswamy Tummala " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr); 229200a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS); 22937c478bd9Sstevel@tonic-gate } 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate /* 229600a3eaf3SRamaswamy Tummala * Return EBUSY if another unconfigure 22977c478bd9Sstevel@tonic-gate * operation is in progress 22987c478bd9Sstevel@tonic-gate */ 22997c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 230000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 230100a3eaf3SRamaswamy Tummala "\tpseudo_config_one: BUSY"); 23027c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 23037c478bd9Sstevel@tonic-gate } 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate 230600a3eaf3SRamaswamy Tummala prev_state = node_data->node_state; 23077c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 231000a3eaf3SRamaswamy Tummala rval = ibnex_pseudo_create_pi_pdip(node_data, pdip); 23117c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 23127c478bd9Sstevel@tonic-gate 231300a3eaf3SRamaswamy Tummala if (rval == IBNEX_SUCCESS) { 23147c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 231500a3eaf3SRamaswamy Tummala } else { 231600a3eaf3SRamaswamy Tummala node_data->node_state = prev_state; 23177c478bd9Sstevel@tonic-gate } 23187c478bd9Sstevel@tonic-gate 231900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x", 232000a3eaf3SRamaswamy Tummala rval); 23217c478bd9Sstevel@tonic-gate return (rval); 23227c478bd9Sstevel@tonic-gate } 23237c478bd9Sstevel@tonic-gate 23247c478bd9Sstevel@tonic-gate 23259d3d2ed0Shiremath /* 23269d3d2ed0Shiremath * ibnex_pseudo_mdi_config_one() 23279d3d2ed0Shiremath * This is similar to ibnex_pseudo_config_one. Few 23289d3d2ed0Shiremath * differences : 23299d3d2ed0Shiremath * 1. parent device lock not held(no ndi_devi_enter) 23309d3d2ed0Shiremath * 2. Called for IB Nexus as parent, not IB HCA as 23319d3d2ed0Shiremath * parent. 23329d3d2ed0Shiremath * 3. Calls mdi_vhci_bus_config() 233305fa0d51Spramodbg * This function skips checks for node_state, initializing 233405fa0d51Spramodbg * node_state, node_dip, etc. These checks and initializations 233505fa0d51Spramodbg * are done when BUS_CONFIG is called with PHCI as the parent. 23369d3d2ed0Shiremath */ 23379d3d2ed0Shiremath static int 23389d3d2ed0Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child, 23399d3d2ed0Shiremath char *cname, char *caddr) 23409d3d2ed0Shiremath { 23419d3d2ed0Shiremath int rval, len; 23429d3d2ed0Shiremath char *node_addr; 23439d3d2ed0Shiremath ibnex_node_data_t *node_data; 23449d3d2ed0Shiremath 23459d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:" 23469d3d2ed0Shiremath "cname = %s caddr = %s", cname, caddr); 23479d3d2ed0Shiremath 23489d3d2ed0Shiremath ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 23499d3d2ed0Shiremath 23509d3d2ed0Shiremath len = strlen(cname) + strlen(caddr) + 2; 23519d3d2ed0Shiremath node_addr = (char *)kmem_alloc(len, KM_SLEEP); 23529d3d2ed0Shiremath 23539d3d2ed0Shiremath (void) snprintf(node_addr, len, "%s,%s", cname, caddr); 23549d3d2ed0Shiremath node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 23559d3d2ed0Shiremath (void *)node_addr, 0, 0); 23569d3d2ed0Shiremath kmem_free(node_addr, len); 23579d3d2ed0Shiremath 235805fa0d51Spramodbg if (node_data == NULL) { 23599d3d2ed0Shiremath IBTF_DPRINTF_L2("ibnex", 23609d3d2ed0Shiremath "\tpseudo_mdi_config_one: Invalid node"); 23619d3d2ed0Shiremath return (IBNEX_FAILURE); 23629d3d2ed0Shiremath } 23639d3d2ed0Shiremath 23649d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 23659d3d2ed0Shiremath rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE, 23669d3d2ed0Shiremath devname, child, node_data->node_data.pseudo_node.pseudo_node_addr); 23679d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 23689d3d2ed0Shiremath 23699d3d2ed0Shiremath return (rval); 23709d3d2ed0Shiremath } 23719d3d2ed0Shiremath 237200a3eaf3SRamaswamy Tummala 23737c478bd9Sstevel@tonic-gate /* 237400a3eaf3SRamaswamy Tummala * ibnex_pseudo_create_all_pi() 237500a3eaf3SRamaswamy Tummala * Create all path infos node for a pseudo entry 23767c478bd9Sstevel@tonic-gate */ 23777c478bd9Sstevel@tonic-gate int 237800a3eaf3SRamaswamy Tummala ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep) 23797c478bd9Sstevel@tonic-gate { 238000a3eaf3SRamaswamy Tummala int hcacnt, rc; 238100a3eaf3SRamaswamy Tummala int hcafailcnt = 0; 238200a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 23837c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list, *head; 23847c478bd9Sstevel@tonic-gate 238500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)", 238600a3eaf3SRamaswamy Tummala nodep); 23877c478bd9Sstevel@tonic-gate ibdm_ibnex_get_hca_list(&hca_list, &hcacnt); 23887c478bd9Sstevel@tonic-gate 23897c478bd9Sstevel@tonic-gate head = hca_list; 23907c478bd9Sstevel@tonic-gate 23919d3d2ed0Shiremath /* 239200a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs. 23939d3d2ed0Shiremath */ 239400a3eaf3SRamaswamy Tummala for (; hca_list != NULL; hca_list = hca_list->hl_next) { 239500a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 239600a3eaf3SRamaswamy Tummala rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip); 239700a3eaf3SRamaswamy Tummala if (rc != IBNEX_SUCCESS) 239800a3eaf3SRamaswamy Tummala hcafailcnt++; 239900a3eaf3SRamaswamy Tummala } 240000a3eaf3SRamaswamy Tummala if (head) 240100a3eaf3SRamaswamy Tummala ibdm_ibnex_free_hca_list(head); 240200a3eaf3SRamaswamy Tummala 240300a3eaf3SRamaswamy Tummala if (hcafailcnt == hcacnt) 240400a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE; 240500a3eaf3SRamaswamy Tummala else 240600a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 240700a3eaf3SRamaswamy Tummala 240800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x", 240900a3eaf3SRamaswamy Tummala rc); 241000a3eaf3SRamaswamy Tummala return (rc); 241100a3eaf3SRamaswamy Tummala } 241200a3eaf3SRamaswamy Tummala 241300a3eaf3SRamaswamy Tummala static int 241400a3eaf3SRamaswamy Tummala ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip) 241500a3eaf3SRamaswamy Tummala { 241600a3eaf3SRamaswamy Tummala mdi_pathinfo_t *pip; 241700a3eaf3SRamaswamy Tummala int rval; 241800a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL; 241900a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo; 242000a3eaf3SRamaswamy Tummala int first_pi = 0; 242100a3eaf3SRamaswamy Tummala 242200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p", 242300a3eaf3SRamaswamy Tummala nodep, hca_dip); 242400a3eaf3SRamaswamy Tummala 242500a3eaf3SRamaswamy Tummala pseudo = &nodep->node_data.pseudo_node; 24269d3d2ed0Shiremath 24277c478bd9Sstevel@tonic-gate rval = mdi_pi_alloc(hca_dip, 24287c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name, pseudo->pseudo_node_addr, 24297c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr, 0, &pip); 24307c478bd9Sstevel@tonic-gate 24317c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 243200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:" 243300a3eaf3SRamaswamy Tummala " mdi_pi_alloc failed"); 24347c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24357c478bd9Sstevel@tonic-gate } 24367c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 24377c478bd9Sstevel@tonic-gate 243800a3eaf3SRamaswamy Tummala if (nodep->node_dip == NULL) { 24397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 24407c478bd9Sstevel@tonic-gate "\tpseudo_create_pi: New dip %p", cdip); 24417c478bd9Sstevel@tonic-gate 244200a3eaf3SRamaswamy Tummala first_pi = 1; 24437c478bd9Sstevel@tonic-gate nodep->node_dip = cdip; 24447c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, nodep); 244500a3eaf3SRamaswamy Tummala } 24467c478bd9Sstevel@tonic-gate 24477c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 245000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 245100a3eaf3SRamaswamy Tummala "\tpseudo_create_pi: " 24527c478bd9Sstevel@tonic-gate "mdi_pi_online: failed for pseudo dip %p," 24537c478bd9Sstevel@tonic-gate " rval %d", cdip, rval); 24547c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 245500a3eaf3SRamaswamy Tummala if (first_pi == 1) { 245600a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL); 245700a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip); 245800a3eaf3SRamaswamy Tummala nodep->node_dip = NULL; 245900a3eaf3SRamaswamy Tummala } else 246000a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0); 24617c478bd9Sstevel@tonic-gate } else 24627c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 24637c478bd9Sstevel@tonic-gate return (rval); 24647c478bd9Sstevel@tonic-gate } 24657c478bd9Sstevel@tonic-gate 24667c478bd9Sstevel@tonic-gate /* 24677c478bd9Sstevel@tonic-gate * ibnex_ioc_create_pi() 24687c478bd9Sstevel@tonic-gate * Create a pathinfo node for the ioc node 24697c478bd9Sstevel@tonic-gate */ 24707c478bd9Sstevel@tonic-gate static int 24719d3d2ed0Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data, 247200a3eaf3SRamaswamy Tummala dev_info_t *pdip, int *node_valid) 24737c478bd9Sstevel@tonic-gate { 24747c478bd9Sstevel@tonic-gate mdi_pathinfo_t *pip; 24759d3d2ed0Shiremath int rval = DDI_FAILURE; 247600a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL; 247700a3eaf3SRamaswamy Tummala int create_prop = 0; 247800a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc = &node_data->node_data.ioc_node; 24797c478bd9Sstevel@tonic-gate 248000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 248100a3eaf3SRamaswamy Tummala "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip); 248200a3eaf3SRamaswamy Tummala *node_valid = 1; 24837c478bd9Sstevel@tonic-gate 24849d3d2ed0Shiremath /* 24859d3d2ed0Shiremath * For CONFIG_ONE requests through HCA dip, alloc 24869d3d2ed0Shiremath * for HCA dip driving BUS_CONFIG request. 24879d3d2ed0Shiremath */ 248800a3eaf3SRamaswamy Tummala rval = mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str, 248900a3eaf3SRamaswamy Tummala ioc->ioc_phci_guid, 0, &pip); 24907c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 249100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", 249200a3eaf3SRamaswamy Tummala "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed", 249300a3eaf3SRamaswamy Tummala pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid); 24947c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24957c478bd9Sstevel@tonic-gate } 24967c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 24977c478bd9Sstevel@tonic-gate 249800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p", 249900a3eaf3SRamaswamy Tummala cdip); 25007c478bd9Sstevel@tonic-gate 250100a3eaf3SRamaswamy Tummala if (node_data->node_dip == NULL) { 25027c478bd9Sstevel@tonic-gate node_data->node_dip = cdip; 25037c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, node_data); 250400a3eaf3SRamaswamy Tummala create_prop = 1; 250500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 250600a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop"); 25077c478bd9Sstevel@tonic-gate if ((rval = ibnex_create_ioc_node_prop( 25087c478bd9Sstevel@tonic-gate ioc_info, cdip)) != IBNEX_SUCCESS) { 250900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 251000a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop failed"); 25117c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data); 251200a3eaf3SRamaswamy Tummala *node_valid = 0; 25137c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 25147c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 25157c478bd9Sstevel@tonic-gate 25167c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 25177c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25187c478bd9Sstevel@tonic-gate } 25197c478bd9Sstevel@tonic-gate } 25207c478bd9Sstevel@tonic-gate 25217c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 25227c478bd9Sstevel@tonic-gate 25237c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 25247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: " 25257c478bd9Sstevel@tonic-gate "mdi_pi_online() failed ioc dip %p, rval %d", 25267c478bd9Sstevel@tonic-gate cdip, rval); 25277c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 252800a3eaf3SRamaswamy Tummala if (create_prop) { 252900a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL); 253000a3eaf3SRamaswamy Tummala ddi_prop_remove_all(cdip); 253100a3eaf3SRamaswamy Tummala ibnex_delete_ioc_node_data(node_data); 253200a3eaf3SRamaswamy Tummala *node_valid = 0; 253300a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip); 253400a3eaf3SRamaswamy Tummala } else 253500a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0); 25367c478bd9Sstevel@tonic-gate } else 25377c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 25389d3d2ed0Shiremath 253900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval); 25407c478bd9Sstevel@tonic-gate return (rval); 25417c478bd9Sstevel@tonic-gate } 25427c478bd9Sstevel@tonic-gate 25437c478bd9Sstevel@tonic-gate 25447c478bd9Sstevel@tonic-gate /* 25457c478bd9Sstevel@tonic-gate * ibnex_create_ioc_node_prop() 25467c478bd9Sstevel@tonic-gate * Create IOC device node properties 25477c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 25487c478bd9Sstevel@tonic-gate */ 25497c478bd9Sstevel@tonic-gate static int 25507c478bd9Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip) 25517c478bd9Sstevel@tonic-gate { 25527c478bd9Sstevel@tonic-gate uint16_t capabilities; 25537c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile; 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop"); 25567c478bd9Sstevel@tonic-gate 25577c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_compatible_prop(cdip, 25587c478bd9Sstevel@tonic-gate ioc_profile) != IBNEX_SUCCESS) { 25597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25607c478bd9Sstevel@tonic-gate } 25617c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_iou_dc_valid) && 25627c478bd9Sstevel@tonic-gate (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode", 25637c478bd9Sstevel@tonic-gate ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) { 25647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25657c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: iou-diagcode create failed"); 25667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25677c478bd9Sstevel@tonic-gate } 25687c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) { 25697c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode", 25707c478bd9Sstevel@tonic-gate ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) { 25717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 25727c478bd9Sstevel@tonic-gate "ioc-diagcode create failed"); 25737c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25747c478bd9Sstevel@tonic-gate } 25757c478bd9Sstevel@tonic-gate } 25767c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth", 25777c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) { 25787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25797c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: rdma-queue-depth create failed"); 25807c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25817c478bd9Sstevel@tonic-gate } 25827c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size", 25837c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) { 25847c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 25857c478bd9Sstevel@tonic-gate "rdma-transfer-size create failed"); 25867c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25877c478bd9Sstevel@tonic-gate } 25887c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size", 25897c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) { 25907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25917c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-message-size create failed"); 25927c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth", 25957c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) { 25967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25977c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-queue-depth create failed"); 25987c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25997c478bd9Sstevel@tonic-gate } 26007c478bd9Sstevel@tonic-gate 26017c478bd9Sstevel@tonic-gate capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8); 26027c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, 26037c478bd9Sstevel@tonic-gate "capabilities", capabilities) != DDI_PROP_SUCCESS) { 26047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26057c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: capabilities create failed"); 26067c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26077c478bd9Sstevel@tonic-gate } 26087c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string", 26097c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) { 26107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26117c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: id-string failed"); 26127c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26137c478bd9Sstevel@tonic-gate } 26147c478bd9Sstevel@tonic-gate 26157c478bd9Sstevel@tonic-gate /* 26167c478bd9Sstevel@tonic-gate * Create properties to represent all the service entries supported 26177c478bd9Sstevel@tonic-gate * by the IOC. Each service entry consists of 1) Service ID (64 bits) 26187c478bd9Sstevel@tonic-gate * and 2) Service name (40 bytes). The service entry table is 26197c478bd9Sstevel@tonic-gate * represented by two properties, service-ids and service-names. The 26207c478bd9Sstevel@tonic-gate * service-id property is a array of int64's and service names is 26217c478bd9Sstevel@tonic-gate * array of strings. The first element in the "service-ids" property 26227c478bd9Sstevel@tonic-gate * corresponds to first string in the "service-names" and so on. 26237c478bd9Sstevel@tonic-gate */ 26247c478bd9Sstevel@tonic-gate if ((ioc_profile->ioc_service_entries != 0) && 26257c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS)) 26267c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26277c478bd9Sstevel@tonic-gate 26287c478bd9Sstevel@tonic-gate /* Create destination port GID properties */ 26297c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS) 26307c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26317c478bd9Sstevel@tonic-gate 26327c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version", 26337c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) { 26347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26357c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol-version create failed"); 26367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol", 26397c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) { 26407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26417c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 26427c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass", 26457c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) { 26467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26477c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subclass create failed"); 26487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26497c478bd9Sstevel@tonic-gate } 26507c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class", 26517c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) { 26527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26537c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: class prop create failed"); 26547c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26557c478bd9Sstevel@tonic-gate } 26567c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id", 26577c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) { 26587c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26597c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsys_id create failed"); 26607c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id", 26637c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) { 26647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26657c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsystem vendor create failed"); 26667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26677c478bd9Sstevel@tonic-gate } 26687c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid", 26697c478bd9Sstevel@tonic-gate ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) { 26707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26717c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 26727c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26737c478bd9Sstevel@tonic-gate } 26747c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version", 26757c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) { 26767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26777c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 26787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26797c478bd9Sstevel@tonic-gate } 26807c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id", 26817c478bd9Sstevel@tonic-gate ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) { 26827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26837c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 26847c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26857c478bd9Sstevel@tonic-gate } 26867c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id", 26877c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) { 26887c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26897c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: vendor-id create failed"); 26907c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26917c478bd9Sstevel@tonic-gate } 26927c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 26937c478bd9Sstevel@tonic-gate } 26947c478bd9Sstevel@tonic-gate 26957c478bd9Sstevel@tonic-gate 26967c478bd9Sstevel@tonic-gate /* 26977c478bd9Sstevel@tonic-gate * ibnex_create_ioc_portgid_prop() 26987c478bd9Sstevel@tonic-gate * Creates "port-entries", "port-list" properties 26997c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 27007c478bd9Sstevel@tonic-gate */ 27017c478bd9Sstevel@tonic-gate static int 27027c478bd9Sstevel@tonic-gate ibnex_create_ioc_portgid_prop( 27037c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 27047c478bd9Sstevel@tonic-gate { 27057c478bd9Sstevel@tonic-gate uint64_t *port_gids; 27067c478bd9Sstevel@tonic-gate int length, ii, jj; 27077c478bd9Sstevel@tonic-gate int prop_len; 27087c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 27097c478bd9Sstevel@tonic-gate 27107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop"); 27117c478bd9Sstevel@tonic-gate 27127c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 27137c478bd9Sstevel@tonic-gate ASSERT(node_data); 27147c478bd9Sstevel@tonic-gate 27157c478bd9Sstevel@tonic-gate prop_len = (ioc_info->ioc_nportgids != 0) ? 27167c478bd9Sstevel@tonic-gate (2 * ioc_info->ioc_nportgids) : 1; 27177c478bd9Sstevel@tonic-gate length = sizeof (uint64_t) * prop_len; 27187c478bd9Sstevel@tonic-gate port_gids = kmem_zalloc(length, KM_SLEEP); 27197c478bd9Sstevel@tonic-gate 27207c478bd9Sstevel@tonic-gate for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) { 27217c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi; 27227c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo; 27237c478bd9Sstevel@tonic-gate } 27247c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list", 27257c478bd9Sstevel@tonic-gate (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) { 27267c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27277c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-list create failed"); 27287c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27297c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27307c478bd9Sstevel@tonic-gate } 27317c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries", 27327c478bd9Sstevel@tonic-gate ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) { 27337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27347c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-entries create failed"); 27357c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27377c478bd9Sstevel@tonic-gate } 27387c478bd9Sstevel@tonic-gate 27397c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 27407c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27417c478bd9Sstevel@tonic-gate } 27427c478bd9Sstevel@tonic-gate 27437c478bd9Sstevel@tonic-gate 27447c478bd9Sstevel@tonic-gate /* 27457c478bd9Sstevel@tonic-gate * ibnex_create_ioc_srv_props() 27467c478bd9Sstevel@tonic-gate * Creates "service-name" and "service-id" properties 27477c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 27487c478bd9Sstevel@tonic-gate */ 27497c478bd9Sstevel@tonic-gate static int 27507c478bd9Sstevel@tonic-gate ibnex_create_ioc_srv_props( 27517c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 27527c478bd9Sstevel@tonic-gate { 27537c478bd9Sstevel@tonic-gate int length, ii; 27547c478bd9Sstevel@tonic-gate uint64_t *srv_id; 27557c478bd9Sstevel@tonic-gate char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU]; 27567c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile; 27577c478bd9Sstevel@tonic-gate ibdm_srvents_info_t *srvents = ioc_info->ioc_serv; 27587c478bd9Sstevel@tonic-gate 27597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props"); 27607c478bd9Sstevel@tonic-gate 27617c478bd9Sstevel@tonic-gate length = profile->ioc_service_entries * sizeof (ib_dm_srv_t); 27627c478bd9Sstevel@tonic-gate srv_id = kmem_zalloc(length, KM_SLEEP); 27637c478bd9Sstevel@tonic-gate temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries)); 27647c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 27657c478bd9Sstevel@tonic-gate srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN); 27667c478bd9Sstevel@tonic-gate } 27677c478bd9Sstevel@tonic-gate 27687c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 27697c478bd9Sstevel@tonic-gate srv_id[ii] = srvents[ii].se_attr.srv_id; 27707c478bd9Sstevel@tonic-gate bcopy(srvents[ii].se_attr.srv_name, 27717c478bd9Sstevel@tonic-gate srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1)); 27727c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 27737c478bd9Sstevel@tonic-gate "Service Names : %s", srv_names[ii]); 27747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 27759d3d2ed0Shiremath "Service ID : %llX", srv_id[ii]); 27767c478bd9Sstevel@tonic-gate } 27777c478bd9Sstevel@tonic-gate 27787c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, 27797c478bd9Sstevel@tonic-gate "service-id", (int64_t *)srv_id, 27807c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 27817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27827c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-id create failed"); 27837c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27847c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27857c478bd9Sstevel@tonic-gate } 27867c478bd9Sstevel@tonic-gate 27877c478bd9Sstevel@tonic-gate if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 27887c478bd9Sstevel@tonic-gate "service-name", (char **)srv_names, 27897c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 27907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 27917c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-name create failed"); 27927c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27947c478bd9Sstevel@tonic-gate } 27957c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27967c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27977c478bd9Sstevel@tonic-gate } 27987c478bd9Sstevel@tonic-gate 27997c478bd9Sstevel@tonic-gate 28007c478bd9Sstevel@tonic-gate /* 28017c478bd9Sstevel@tonic-gate * ibnex_create_ioc_compatible_prop() 28027c478bd9Sstevel@tonic-gate * Creates "compatible" property values 28037c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 28047c478bd9Sstevel@tonic-gate */ 28057c478bd9Sstevel@tonic-gate static int 28067c478bd9Sstevel@tonic-gate ibnex_create_ioc_compatible_prop( 28077c478bd9Sstevel@tonic-gate dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile) 28087c478bd9Sstevel@tonic-gate { 28097c478bd9Sstevel@tonic-gate char *temp; 28107c478bd9Sstevel@tonic-gate int rval, ii; 28117c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_COMPAT_NAMES]; 28127c478bd9Sstevel@tonic-gate 28137c478bd9Sstevel@tonic-gate /* 28147c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 28157c478bd9Sstevel@tonic-gate * Compatible Strings : 28167c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver> 28177c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id> 28187c478bd9Sstevel@tonic-gate * 3. ib.V<vid>P<pid>v<ver> 28197c478bd9Sstevel@tonic-gate * 4. ib.V<vid>P<pid> 28207c478bd9Sstevel@tonic-gate * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver> 28217c478bd9Sstevel@tonic-gate * 6. ib.C<Class>c<Subclass>p<protocol> 28227c478bd9Sstevel@tonic-gate * 28237c478bd9Sstevel@tonic-gate * Note: 28247c478bd9Sstevel@tonic-gate * All leading zeros must be present 28257c478bd9Sstevel@tonic-gate * All numeric values must specified in hex without prefix "0x" 28267c478bd9Sstevel@tonic-gate */ 28277c478bd9Sstevel@tonic-gate 28287c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP); 28297c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 28307c478bd9Sstevel@tonic-gate compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN); 28317c478bd9Sstevel@tonic-gate 28327c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 28337c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08xv%04x", 28347c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28357c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id, 28367c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 28377c478bd9Sstevel@tonic-gate 28387c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 28397c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08x", 28407c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28417c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id); 28427c478bd9Sstevel@tonic-gate 28437c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 28447c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x", 28457c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 28467c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 28477c478bd9Sstevel@tonic-gate 28487c478bd9Sstevel@tonic-gate (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN, 28497c478bd9Sstevel@tonic-gate "ib.V%06xP%08x", 28507c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid); 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN, 28537c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04xr%04x", 28547c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 28557c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver); 28567c478bd9Sstevel@tonic-gate 28577c478bd9Sstevel@tonic-gate (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN, 28587c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04x", 28597c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 28607c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol); 28617c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 28627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]); 28637c478bd9Sstevel@tonic-gate 28647c478bd9Sstevel@tonic-gate /* Create the compatible property for child cdip */ 28657c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 28667c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES); 28677c478bd9Sstevel@tonic-gate 28687c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 28697c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed"); 28707c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 28717c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 28727c478bd9Sstevel@tonic-gate } 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 28757c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 28767c478bd9Sstevel@tonic-gate } 28777c478bd9Sstevel@tonic-gate 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate static void 28807c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup() 28817c478bd9Sstevel@tonic-gate { 28827c478bd9Sstevel@tonic-gate ibnex_node_data_t *node, *delete; 28837c478bd9Sstevel@tonic-gate 28847c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 28857c478bd9Sstevel@tonic-gate for (node = ibnex.ibnex_ioc_node_head; node; ) { 28867c478bd9Sstevel@tonic-gate delete = node; 28877c478bd9Sstevel@tonic-gate node = node->node_next; 28887c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 28897c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(delete); 28907c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 28917c478bd9Sstevel@tonic-gate } 28927c478bd9Sstevel@tonic-gate } 28937c478bd9Sstevel@tonic-gate 28947c478bd9Sstevel@tonic-gate /* 28957c478bd9Sstevel@tonic-gate * ibnex_delete_ioc_node_data() 28967c478bd9Sstevel@tonic-gate * Delete IOC node from the list 28977c478bd9Sstevel@tonic-gate */ 28987c478bd9Sstevel@tonic-gate static void 28997c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node) 29007c478bd9Sstevel@tonic-gate { 29017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:"); 29027c478bd9Sstevel@tonic-gate 29037c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 29047c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) { 29057c478bd9Sstevel@tonic-gate ASSERT(ibnex.ibnex_ioc_node_head == node); 29067c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = NULL; 29077c478bd9Sstevel@tonic-gate } else if (node->node_next == NULL) 29087c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 29097c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 29107c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 29117c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node->node_next; 29127c478bd9Sstevel@tonic-gate } else { 29137c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 29147c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 29157c478bd9Sstevel@tonic-gate } 29167c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p", 29177c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head); 29187c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 29197c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 29207c478bd9Sstevel@tonic-gate } 29217c478bd9Sstevel@tonic-gate 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate /* 29247c478bd9Sstevel@tonic-gate * ibnex_dm_callback() 29257c478bd9Sstevel@tonic-gate * 29267c478bd9Sstevel@tonic-gate * This routine is registered with the IBDM during IB nexus attach. It 29277c478bd9Sstevel@tonic-gate * is called by the IBDM module when it discovers 29287c478bd9Sstevel@tonic-gate * New HCA port 29297c478bd9Sstevel@tonic-gate * HCA port removal 29307c478bd9Sstevel@tonic-gate * New HCA added 29317c478bd9Sstevel@tonic-gate * HCA removed 29327c478bd9Sstevel@tonic-gate */ 29337c478bd9Sstevel@tonic-gate void 29347c478bd9Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag) 29357c478bd9Sstevel@tonic-gate { 29367c478bd9Sstevel@tonic-gate char hca_guid[IBNEX_HCAGUID_STRSZ]; 29377c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc; 29387c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag); 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate switch (flag) { 29437c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_ADDED: 29447c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 29457c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 29467c478bd9Sstevel@tonic-gate /* Create a devctl minor node for the HCA's port */ 29477c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR, 29487c478bd9Sstevel@tonic-gate ddi_get_instance(ibnex.ibnex_dip), 29497c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 29507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to " 29517c478bd9Sstevel@tonic-gate "create minor node for port w/ guid %s", hca_guid); 29527c478bd9Sstevel@tonic-gate } 29537c478bd9Sstevel@tonic-gate 29547c478bd9Sstevel@tonic-gate break; 29557c478bd9Sstevel@tonic-gate 29567c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_REMOVED: 29577c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 29587c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 29597c478bd9Sstevel@tonic-gate ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid); 29607c478bd9Sstevel@tonic-gate break; 29617c478bd9Sstevel@tonic-gate 29627c478bd9Sstevel@tonic-gate case IBDM_EVENT_IOC_PROP_UPDATE: 29637c478bd9Sstevel@tonic-gate ioc = ioc_list = (ibdm_ioc_info_t *)arg; 29647c478bd9Sstevel@tonic-gate if (ioc_list == NULL) 29657c478bd9Sstevel@tonic-gate break; 29667c478bd9Sstevel@tonic-gate 29677c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 29687c478bd9Sstevel@tonic-gate while (ioc_list) { 29697c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present( 29707c478bd9Sstevel@tonic-gate IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL && 29717c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 29727c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_list); 29737c478bd9Sstevel@tonic-gate } 29747c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 29757c478bd9Sstevel@tonic-gate } 29767c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 29777c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 29787c478bd9Sstevel@tonic-gate } 29797c478bd9Sstevel@tonic-gate } 29807c478bd9Sstevel@tonic-gate 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate /* 29837c478bd9Sstevel@tonic-gate * ibnex_get_dip_from_guid() 29847c478bd9Sstevel@tonic-gate * 29857c478bd9Sstevel@tonic-gate * Searches the linked list of the port nodes and returns the dip for 29867c478bd9Sstevel@tonic-gate * the of the Port / Node guid requested. 29877c478bd9Sstevel@tonic-gate * Returns NULL if not found 29887c478bd9Sstevel@tonic-gate */ 29897c478bd9Sstevel@tonic-gate int 29907c478bd9Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey, 29917c478bd9Sstevel@tonic-gate dev_info_t **dip) 29927c478bd9Sstevel@tonic-gate { 29937c478bd9Sstevel@tonic-gate int node_index; 29947c478bd9Sstevel@tonic-gate ib_guid_t node_guid; 29957c478bd9Sstevel@tonic-gate ib_pkey_t node_pkey; 29967c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 29999d3d2ed0Shiremath "\tget_dip_from_guid: guid = %llX", guid); 30007c478bd9Sstevel@tonic-gate 30017c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 30027c478bd9Sstevel@tonic-gate /* Search for a matching entry in internal lists */ 30037c478bd9Sstevel@tonic-gate node_data = ibnex.ibnex_port_node_head; 30047c478bd9Sstevel@tonic-gate while (node_data) { 30057c478bd9Sstevel@tonic-gate node_guid = node_data->node_data.port_node.port_guid; 30067c478bd9Sstevel@tonic-gate node_index = node_data->node_data.port_node.port_commsvc_idx; 30077c478bd9Sstevel@tonic-gate node_pkey = node_data->node_data.port_node.port_pkey; 30087c478bd9Sstevel@tonic-gate if ((node_guid == guid) && (index == node_index) && 30097c478bd9Sstevel@tonic-gate (node_pkey == pkey)) { 30107c478bd9Sstevel@tonic-gate break; 30117c478bd9Sstevel@tonic-gate } 30127c478bd9Sstevel@tonic-gate node_data = node_data->node_next; 30137c478bd9Sstevel@tonic-gate } 30147c478bd9Sstevel@tonic-gate 30157c478bd9Sstevel@tonic-gate /* matching found with a valid dip */ 30167c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 30177c478bd9Sstevel@tonic-gate *dip = node_data->node_dip; 30187c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30197c478bd9Sstevel@tonic-gate } else if (node_data && !node_data->node_dip) { /* dip is invalid */ 30207c478bd9Sstevel@tonic-gate *dip = NULL; 30217c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30227c478bd9Sstevel@tonic-gate } 30237c478bd9Sstevel@tonic-gate 30247c478bd9Sstevel@tonic-gate /* no match found */ 30257c478bd9Sstevel@tonic-gate *dip = NULL; 30267c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 30277c478bd9Sstevel@tonic-gate } 30287c478bd9Sstevel@tonic-gate 30297c478bd9Sstevel@tonic-gate 30307c478bd9Sstevel@tonic-gate /* 30317c478bd9Sstevel@tonic-gate * ibnex_comm_svc_init() 30327c478bd9Sstevel@tonic-gate * Read the property and cache the values in the global 30337c478bd9Sstevel@tonic-gate * structure. 30347c478bd9Sstevel@tonic-gate * Check for max allowed length (4 bytes) of service name 30357c478bd9Sstevel@tonic-gate * (each element of the property) 30367c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 30377c478bd9Sstevel@tonic-gate */ 30387c478bd9Sstevel@tonic-gate static ibnex_rval_t 30397c478bd9Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type) 30407c478bd9Sstevel@tonic-gate { 30417c478bd9Sstevel@tonic-gate int i, len, count; 30427c478bd9Sstevel@tonic-gate int ncomm_svcs; 30437c478bd9Sstevel@tonic-gate char **comm_svcp; 30447c478bd9Sstevel@tonic-gate char **servicep = NULL; 30457c478bd9Sstevel@tonic-gate uint_t nservices = 0; 30467c478bd9Sstevel@tonic-gate int *valid = NULL; 30477c478bd9Sstevel@tonic-gate 30487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x", 30497c478bd9Sstevel@tonic-gate property, type); 30507c478bd9Sstevel@tonic-gate 30517c478bd9Sstevel@tonic-gate /* lookup the string array property */ 30527c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip, 30537c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, property, &servicep, &nservices) != 30547c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 30557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property); 30567c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30577c478bd9Sstevel@tonic-gate } 30587c478bd9Sstevel@tonic-gate 30597c478bd9Sstevel@tonic-gate if (nservices) 30607c478bd9Sstevel@tonic-gate valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP); 30617c478bd9Sstevel@tonic-gate 30627c478bd9Sstevel@tonic-gate 30637c478bd9Sstevel@tonic-gate /* first read the file to get a count of valid service entries */ 30647c478bd9Sstevel@tonic-gate for (ncomm_svcs = 0, count = 0; count < nservices; count++) { 30657c478bd9Sstevel@tonic-gate int j; 30667c478bd9Sstevel@tonic-gate 30677c478bd9Sstevel@tonic-gate len = strlen(servicep[count]); 306800a3eaf3SRamaswamy Tummala /* 306900a3eaf3SRamaswamy Tummala * ib.conf has NULL strings for port-svc-list & 307000a3eaf3SRamaswamy Tummala * hca-svc-list, by default. Do not have L2 message 307100a3eaf3SRamaswamy Tummala * for these. 307200a3eaf3SRamaswamy Tummala */ 307300a3eaf3SRamaswamy Tummala if (len == 1 || len > 4) { 30747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 307500a3eaf3SRamaswamy Tummala "Service name %s for property %s invalid : " 307600a3eaf3SRamaswamy Tummala "length %d", servicep[count], property, len); 307700a3eaf3SRamaswamy Tummala continue; 307800a3eaf3SRamaswamy Tummala } else if (len == 0) { 30797c478bd9Sstevel@tonic-gate continue; 30807c478bd9Sstevel@tonic-gate } 30817c478bd9Sstevel@tonic-gate if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) { 30827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 30837c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 30847c478bd9Sstevel@tonic-gate servicep[count]); 30857c478bd9Sstevel@tonic-gate continue; 30867c478bd9Sstevel@tonic-gate } 30877c478bd9Sstevel@tonic-gate 30887c478bd9Sstevel@tonic-gate /* 30897c478bd9Sstevel@tonic-gate * ibnex_unique_svcname checks for uniqueness in service names 30907c478bd9Sstevel@tonic-gate * communication services fully initialized. Check uniqueness 30917c478bd9Sstevel@tonic-gate * in service names currently initialized. 30927c478bd9Sstevel@tonic-gate */ 30937c478bd9Sstevel@tonic-gate for (j = 0; j < count; j++) 30947c478bd9Sstevel@tonic-gate if (valid[j] && strncmp(servicep[count], 30957c478bd9Sstevel@tonic-gate servicep[j], 4) == 0) { 30967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 30977c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 30987c478bd9Sstevel@tonic-gate servicep[count]); 30997c478bd9Sstevel@tonic-gate continue; 31007c478bd9Sstevel@tonic-gate } 31017c478bd9Sstevel@tonic-gate 31027c478bd9Sstevel@tonic-gate valid[count] = 1; 31037c478bd9Sstevel@tonic-gate ncomm_svcs++; 31047c478bd9Sstevel@tonic-gate } 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate /* if no valid entries found, bailout */ 31077c478bd9Sstevel@tonic-gate if (nservices == 0 || ncomm_svcs == 0) { 31087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property); 31097c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); /* free the property */ 31107c478bd9Sstevel@tonic-gate if (valid) 31117c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 31127c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 31137c478bd9Sstevel@tonic-gate } 31147c478bd9Sstevel@tonic-gate 31157c478bd9Sstevel@tonic-gate comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP); 31167c478bd9Sstevel@tonic-gate if (type == IBNEX_PORT_COMMSVC_NODE) { 31177c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = comm_svcp; 31187c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = ncomm_svcs; 31197c478bd9Sstevel@tonic-gate } else if (type == IBNEX_VPPA_COMMSVC_NODE) { 31207c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = comm_svcp; 31217c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs; 31227c478bd9Sstevel@tonic-gate } else if (type == IBNEX_HCASVC_COMMSVC_NODE) { 31237c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp; 31247c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs; 31257c478bd9Sstevel@tonic-gate } 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate /* copy the services into an array of strings */ 31287c478bd9Sstevel@tonic-gate for (i = 0, count = 0; count < nservices; count++) { 31297c478bd9Sstevel@tonic-gate if (valid[count] == 0) /* Skip invalid ones */ 31307c478bd9Sstevel@tonic-gate continue; 31317c478bd9Sstevel@tonic-gate comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP); 31327c478bd9Sstevel@tonic-gate (void) strcpy(comm_svcp[i], servicep[count]); 31337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 31347c478bd9Sstevel@tonic-gate "\t\tService [%d]: %s", i, comm_svcp[i]); 31357c478bd9Sstevel@tonic-gate ++i; 31367c478bd9Sstevel@tonic-gate } 31377c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); 31387c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 31397c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 31407c478bd9Sstevel@tonic-gate } 31417c478bd9Sstevel@tonic-gate 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate /* 31447c478bd9Sstevel@tonic-gate * ibnex_comm_svc_fini() 31457c478bd9Sstevel@tonic-gate * Deallocate all the memory allocated for the communication 31467c478bd9Sstevel@tonic-gate * service arrays. 31477c478bd9Sstevel@tonic-gate */ 31487c478bd9Sstevel@tonic-gate static void 31497c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini() 31507c478bd9Sstevel@tonic-gate { 31517c478bd9Sstevel@tonic-gate int index; 31527c478bd9Sstevel@tonic-gate 31537c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) { 31547c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names[index], 31557c478bd9Sstevel@tonic-gate (strlen(ibnex.ibnex_comm_svc_names[index]) + 1)); 31567c478bd9Sstevel@tonic-gate } 31577c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names) { 31587c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names, 31597c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs * sizeof (char *)); 31607c478bd9Sstevel@tonic-gate } 31617c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 31627c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names[index], 31637c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1); 31647c478bd9Sstevel@tonic-gate } 31657c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names) { 31667c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names, 31677c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs * sizeof (char *)); 31687c478bd9Sstevel@tonic-gate } 31697c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) { 31707c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index], 31717c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1); 31727c478bd9Sstevel@tonic-gate } 31737c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names) { 31747c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names, 31757c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *)); 31767c478bd9Sstevel@tonic-gate } 31777c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = NULL; 31787c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = 0; 31797c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = NULL; 31807c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = 0; 31817c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = NULL; 31827c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = 0; 31837c478bd9Sstevel@tonic-gate } 31847c478bd9Sstevel@tonic-gate 31857c478bd9Sstevel@tonic-gate 31867c478bd9Sstevel@tonic-gate /* 31877c478bd9Sstevel@tonic-gate * ibnex_commsvc_initnode() 31887c478bd9Sstevel@tonic-gate * This routine is specific to port/VPPA node creation 31897c478bd9Sstevel@tonic-gate * Creates a device node for the comm service specified by commsvc_index 31907c478bd9Sstevel@tonic-gate * Creates all the device node properties 31917c478bd9Sstevel@tonic-gate * Allocates and initializes the node specific data 31927c478bd9Sstevel@tonic-gate * Binds the device driver of the device node 31937c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the child node or NULL in case of failure 31947c478bd9Sstevel@tonic-gate * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect 31957c478bd9Sstevel@tonic-gate * if the operation was successful, failed or was not performed. 31967c478bd9Sstevel@tonic-gate */ 31977c478bd9Sstevel@tonic-gate dev_info_t * 31987c478bd9Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr, 31997c478bd9Sstevel@tonic-gate int index, int node_type, ib_pkey_t pkey, int *rval, int flag) 32007c478bd9Sstevel@tonic-gate { 32017c478bd9Sstevel@tonic-gate int ret; 32027c478bd9Sstevel@tonic-gate char *svcname; 32037c478bd9Sstevel@tonic-gate dev_info_t *cdip; 32047c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 320500a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node; 320600a3eaf3SRamaswamy Tummala char devname[MAXNAMELEN]; 320751f34d4bSRajkumar Sivaprakasam int cdip_allocated = 0; 32087c478bd9Sstevel@tonic-gate 32097c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 32107c478bd9Sstevel@tonic-gate 32117c478bd9Sstevel@tonic-gate *rval = IBNEX_SUCCESS; 32127c478bd9Sstevel@tonic-gate 32137c478bd9Sstevel@tonic-gate /* 32147c478bd9Sstevel@tonic-gate * prevent any races 32157c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized 32167c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 32177c478bd9Sstevel@tonic-gate * progress. 32187c478bd9Sstevel@tonic-gate */ 32197c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(node_type, (void *)port_attr, 32207c478bd9Sstevel@tonic-gate index, pkey); 322100a3eaf3SRamaswamy Tummala 322200a3eaf3SRamaswamy Tummala /* 322300a3eaf3SRamaswamy Tummala * If this node has been explicity unconfigured by cfgadm, then it can 322400a3eaf3SRamaswamy Tummala * be configured back again only by cfgadm configure. 322500a3eaf3SRamaswamy Tummala */ 322600a3eaf3SRamaswamy Tummala if (node_data && (node_data->node_ap_state == 322700a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED)) { 322800a3eaf3SRamaswamy Tummala *rval = IBNEX_FAILURE; 322900a3eaf3SRamaswamy Tummala return (NULL); 323000a3eaf3SRamaswamy Tummala } 323100a3eaf3SRamaswamy Tummala 32327c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 32337c478bd9Sstevel@tonic-gate /* 32347c478bd9Sstevel@tonic-gate * Return NULL if another configure 32357c478bd9Sstevel@tonic-gate * operation is in progress 32367c478bd9Sstevel@tonic-gate */ 32377c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) { 32387c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 32397c478bd9Sstevel@tonic-gate return (NULL); 32407c478bd9Sstevel@tonic-gate } else { 32417c478bd9Sstevel@tonic-gate return (node_data->node_dip); 32427c478bd9Sstevel@tonic-gate } 32437c478bd9Sstevel@tonic-gate } else if (node_data == NULL) { 32447c478bd9Sstevel@tonic-gate /* allocate a new ibnex_node_data_t */ 32457c478bd9Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(node_type, port_attr, 32467c478bd9Sstevel@tonic-gate index, pkey); 324700a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 32487c478bd9Sstevel@tonic-gate } 32497c478bd9Sstevel@tonic-gate 32507c478bd9Sstevel@tonic-gate /* 32517c478bd9Sstevel@tonic-gate * Return NULL if another unconfigure operation is in progress 32527c478bd9Sstevel@tonic-gate */ 32537c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 32547c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 32557c478bd9Sstevel@tonic-gate return (NULL); 32567c478bd9Sstevel@tonic-gate } 32577c478bd9Sstevel@tonic-gate 32587c478bd9Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED); 32597c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 32607c478bd9Sstevel@tonic-gate 32617c478bd9Sstevel@tonic-gate switch (node_type) { 32627c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE : 32637c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_vppa_comm_svc_names[index]; 326400a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 326500a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s", 326600a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, 326700a3eaf3SRamaswamy Tummala port_node->port_pkey, svcname); 32687c478bd9Sstevel@tonic-gate break; 32697c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE : 32707c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_hcasvc_comm_svc_names[index]; 327100a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 327200a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 327300a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 32747c478bd9Sstevel@tonic-gate break; 32757c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE : 32767c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_comm_svc_names[index]; 327700a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node; 327800a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s", 327900a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname); 32807c478bd9Sstevel@tonic-gate break; 32817c478bd9Sstevel@tonic-gate default : 32827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:" 32837c478bd9Sstevel@tonic-gate "\tInvalid Node type"); 32847c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 32857c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(node_data); 32867c478bd9Sstevel@tonic-gate return (NULL); 32877c478bd9Sstevel@tonic-gate } 32887c478bd9Sstevel@tonic-gate 328900a3eaf3SRamaswamy Tummala if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) { 329000a3eaf3SRamaswamy Tummala if (i_ddi_devi_attached(cdip)) { 329100a3eaf3SRamaswamy Tummala node_data->node_dip = cdip; 329200a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 329300a3eaf3SRamaswamy Tummala node_data->node_state = IBNEX_CFGADM_CONFIGURED; 329400a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data); 329551f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found " 329651f34d4bSRajkumar Sivaprakasam "attached cdip 0x%p for devname %s", cdip, devname); 329700a3eaf3SRamaswamy Tummala return (cdip); 329800a3eaf3SRamaswamy Tummala } 329900a3eaf3SRamaswamy Tummala } else { 330000a3eaf3SRamaswamy Tummala ndi_devi_alloc_sleep(parent, 330100a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip); 330251f34d4bSRajkumar Sivaprakasam cdip_allocated = 1; 330300a3eaf3SRamaswamy Tummala } 330400a3eaf3SRamaswamy Tummala 330500a3eaf3SRamaswamy Tummala node_data->node_dip = cdip; 330600a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data); 330700a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex); 330800a3eaf3SRamaswamy Tummala 330900a3eaf3SRamaswamy Tummala 33107c478bd9Sstevel@tonic-gate if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) == 33117c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 33127c478bd9Sstevel@tonic-gate if (flag == IBNEX_DEVFS_ENUMERATE) 33137c478bd9Sstevel@tonic-gate ret = ndi_devi_bind_driver(cdip, 0); 33147c478bd9Sstevel@tonic-gate else 33157c478bd9Sstevel@tonic-gate ret = ndi_devi_online(cdip, 0); 33167c478bd9Sstevel@tonic-gate if (ret == NDI_SUCCESS) { 33177c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 33187c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 331900a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent; 33207c478bd9Sstevel@tonic-gate return (cdip); 33217c478bd9Sstevel@tonic-gate } 332251f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE " 332351f34d4bSRajkumar Sivaprakasam "of cdip 0x%p for devname %s and flag %d failed", cdip, 332451f34d4bSRajkumar Sivaprakasam devname, flag); 33257c478bd9Sstevel@tonic-gate } 332600a3eaf3SRamaswamy Tummala 33277c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 332851f34d4bSRajkumar Sivaprakasam node_data->node_dip = NULL; 332951f34d4bSRajkumar Sivaprakasam ddi_set_parent_data(cdip, NULL); 333051f34d4bSRajkumar Sivaprakasam if (cdip_allocated) 33317c478bd9Sstevel@tonic-gate (void) ndi_devi_free(cdip); 33327c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 33337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit"); 33347c478bd9Sstevel@tonic-gate return (NULL); 33357c478bd9Sstevel@tonic-gate } 33367c478bd9Sstevel@tonic-gate 33377c478bd9Sstevel@tonic-gate 33387c478bd9Sstevel@tonic-gate /* 33397c478bd9Sstevel@tonic-gate * ibnex_create_port_node_prop() 33407c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 33417c478bd9Sstevel@tonic-gate */ 33427c478bd9Sstevel@tonic-gate static int 33437c478bd9Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr, 33447c478bd9Sstevel@tonic-gate dev_info_t *child_dip, char *srvname, ib_pkey_t pkey) 33457c478bd9Sstevel@tonic-gate { 33467c478bd9Sstevel@tonic-gate if (ibnex_create_port_compatible_prop(child_dip, 33477c478bd9Sstevel@tonic-gate srvname, port_attr) != DDI_PROP_SUCCESS) { 33487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33497c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: compatible update failed"); 33507c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33517c478bd9Sstevel@tonic-gate } 33527c478bd9Sstevel@tonic-gate if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33537c478bd9Sstevel@tonic-gate "port-pkey", pkey) != DDI_PROP_SUCCESS)) { 33547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33557c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 33567c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33577c478bd9Sstevel@tonic-gate } 33587c478bd9Sstevel@tonic-gate 33597c478bd9Sstevel@tonic-gate /* 33607c478bd9Sstevel@tonic-gate * For HCA_SVC device nodes, port_num will be 0. 33617c478bd9Sstevel@tonic-gate * Do not create the "port-number" & "port-guid" properties. 33627c478bd9Sstevel@tonic-gate */ 33637c478bd9Sstevel@tonic-gate if (port_attr->pa_port_num != 0) { 33647c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33657c478bd9Sstevel@tonic-gate "port-number", port_attr->pa_port_num) != 33667c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 33677c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33687c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 33697c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33707c478bd9Sstevel@tonic-gate } 33717c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 33727c478bd9Sstevel@tonic-gate "port-guid", port_attr->pa_port_guid) != 33737c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 33747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33757c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guid update failed"); 33767c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33777c478bd9Sstevel@tonic-gate } 33787c478bd9Sstevel@tonic-gate } else { 33797c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 33807c478bd9Sstevel@tonic-gate 33817c478bd9Sstevel@tonic-gate /* 33827c478bd9Sstevel@tonic-gate * HCA_SVC nodes require "num-ports" & "port-guids" 33837c478bd9Sstevel@tonic-gate * properties. 33847c478bd9Sstevel@tonic-gate * 33857c478bd9Sstevel@tonic-gate * To create the num-ports & port-guids attribute : 33867c478bd9Sstevel@tonic-gate * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid) 33877c478bd9Sstevel@tonic-gate * 2. Form the array of port GUIDs. 33887c478bd9Sstevel@tonic-gate */ 33897c478bd9Sstevel@tonic-gate if ((hca_list = ibdm_ibnex_get_hca_info_by_guid( 33907c478bd9Sstevel@tonic-gate port_attr->pa_hca_guid)) == NULL) { 33917c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33927c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca_info_by_guid failed"); 33937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33947c478bd9Sstevel@tonic-gate } 33957c478bd9Sstevel@tonic-gate 33967c478bd9Sstevel@tonic-gate if (hca_list->hl_nports != 0) { 33977c478bd9Sstevel@tonic-gate ib_guid_t *port_guids; 33987c478bd9Sstevel@tonic-gate uint8_t portnum; 33997c478bd9Sstevel@tonic-gate 34007c478bd9Sstevel@tonic-gate ASSERT(hca_list->hl_port_attr != NULL); 34017c478bd9Sstevel@tonic-gate 34027c478bd9Sstevel@tonic-gate port_guids = kmem_zalloc( 34037c478bd9Sstevel@tonic-gate hca_list->hl_nports * sizeof (ib_guid_t), 34047c478bd9Sstevel@tonic-gate KM_SLEEP); 34057c478bd9Sstevel@tonic-gate 34067c478bd9Sstevel@tonic-gate for (portnum = 0; portnum < hca_list->hl_nports; 34077c478bd9Sstevel@tonic-gate portnum++) { 34087c478bd9Sstevel@tonic-gate port_guids[portnum] = (hca_list-> 34097c478bd9Sstevel@tonic-gate hl_port_attr[portnum]).pa_port_guid; 34107c478bd9Sstevel@tonic-gate } 34117c478bd9Sstevel@tonic-gate 34127c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, 34137c478bd9Sstevel@tonic-gate child_dip, "port-guids", (int64_t *)port_guids, 34147c478bd9Sstevel@tonic-gate hca_list->hl_nports) != DDI_PROP_SUCCESS) { 34157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34167c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guids " 34177c478bd9Sstevel@tonic-gate "create failed"); 34187c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 34197c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 34207c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34217c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34227c478bd9Sstevel@tonic-gate } 34237c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 34247c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 34257c478bd9Sstevel@tonic-gate } 34267c478bd9Sstevel@tonic-gate 34277c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34287c478bd9Sstevel@tonic-gate "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) { 34297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34307c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: num-ports update failed"); 34317c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34327c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34337c478bd9Sstevel@tonic-gate } 34347c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 34357c478bd9Sstevel@tonic-gate } 34367c478bd9Sstevel@tonic-gate 34377c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 34387c478bd9Sstevel@tonic-gate "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) { 34397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34407c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca-guid update failed"); 34417c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34427c478bd9Sstevel@tonic-gate } 34437c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34447c478bd9Sstevel@tonic-gate "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) { 34457c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34467c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: product-id update failed"); 34477c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34487c478bd9Sstevel@tonic-gate } 34497c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 34507c478bd9Sstevel@tonic-gate "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) { 34517c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34527c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: vendor-id update failed"); 34537c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34547c478bd9Sstevel@tonic-gate } 34557c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version", 34567c478bd9Sstevel@tonic-gate port_attr->pa_dev_version) != DDI_PROP_SUCCESS) { 34577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34587c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: device-version update failed"); 34597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34607c478bd9Sstevel@tonic-gate } 34617c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 34627c478bd9Sstevel@tonic-gate } 34637c478bd9Sstevel@tonic-gate 34647c478bd9Sstevel@tonic-gate 34657c478bd9Sstevel@tonic-gate /* 34667c478bd9Sstevel@tonic-gate * ibnex_str2int() 34677c478bd9Sstevel@tonic-gate * Utility function that converts a string of length "len" to 34687c478bd9Sstevel@tonic-gate * integer. 34697c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 34707c478bd9Sstevel@tonic-gate */ 34717c478bd9Sstevel@tonic-gate static int 34727c478bd9Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret) 34737c478bd9Sstevel@tonic-gate { 34747c478bd9Sstevel@tonic-gate int intval = 0, ii; 34757c478bd9Sstevel@tonic-gate 34767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c); 34777c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 34787c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 34797c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 34807c478bd9Sstevel@tonic-gate intval = intval * 10 +c[ii] - '0'; 34817c478bd9Sstevel@tonic-gate else { 34827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 34837c478bd9Sstevel@tonic-gate "\tstr2int: Invalid integer string %s..", c); 34847c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 34857c478bd9Sstevel@tonic-gate break; 34867c478bd9Sstevel@tonic-gate } 34877c478bd9Sstevel@tonic-gate } 34887c478bd9Sstevel@tonic-gate 34897c478bd9Sstevel@tonic-gate return (intval); 34907c478bd9Sstevel@tonic-gate } 34917c478bd9Sstevel@tonic-gate 34927c478bd9Sstevel@tonic-gate 34937c478bd9Sstevel@tonic-gate /* 34947c478bd9Sstevel@tonic-gate * ibnex_str2hex() 34957c478bd9Sstevel@tonic-gate * Utility functions that converts a string of length "len" to 34967c478bd9Sstevel@tonic-gate * hex value. Note. This function does not handle strings which 34977c478bd9Sstevel@tonic-gate * string length more than 8 bytes. 34987c478bd9Sstevel@tonic-gate * 34997c478bd9Sstevel@tonic-gate */ 35007c478bd9Sstevel@tonic-gate uint64_t 35017c478bd9Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret) 35027c478bd9Sstevel@tonic-gate { 35037c478bd9Sstevel@tonic-gate uint64_t hex = 0, ii; 35047c478bd9Sstevel@tonic-gate 35057c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 35067c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 35077c478bd9Sstevel@tonic-gate hex = (ii == 0) ? hex : (hex << 4); 35087c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 35097c478bd9Sstevel@tonic-gate hex |= c[ii] - '0'; 35107c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'a') && (c[ii] <= 'f')) 35117c478bd9Sstevel@tonic-gate hex |= c[ii] - 'a' + 10; 35127c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'A') && (c[ii] <= 'F')) 35137c478bd9Sstevel@tonic-gate hex |= c[ii] - 'A' + 10; 35147c478bd9Sstevel@tonic-gate else { 35157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 35167c478bd9Sstevel@tonic-gate "\tstr2hex: Invalid integer string"); 35177c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 35187c478bd9Sstevel@tonic-gate break; 35197c478bd9Sstevel@tonic-gate } 35207c478bd9Sstevel@tonic-gate } 35217c478bd9Sstevel@tonic-gate 35227c478bd9Sstevel@tonic-gate return (hex); 35237c478bd9Sstevel@tonic-gate } 35247c478bd9Sstevel@tonic-gate 35257c478bd9Sstevel@tonic-gate 35267c478bd9Sstevel@tonic-gate /* 35277c478bd9Sstevel@tonic-gate * ibnex_create_port_compatible_prop() 35287c478bd9Sstevel@tonic-gate * Creates 'Compatibility' property for port / HCA_SVC device nodes 35297c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 35307c478bd9Sstevel@tonic-gate */ 35317c478bd9Sstevel@tonic-gate static int 35327c478bd9Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip, 35337c478bd9Sstevel@tonic-gate char *comm_svcp, ibdm_port_attr_t *port_attr) 35347c478bd9Sstevel@tonic-gate { 35357c478bd9Sstevel@tonic-gate int rval, i; 35367c478bd9Sstevel@tonic-gate char *temp; 35377c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES]; 35387c478bd9Sstevel@tonic-gate 35397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin"); 35407c478bd9Sstevel@tonic-gate /* 35417c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 35427c478bd9Sstevel@tonic-gate * Compatible Strings : 35437c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>v<revision>.<service name>. 35447c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>.<service name>. 35457c478bd9Sstevel@tonic-gate * 3. ib.<service name> 35467c478bd9Sstevel@tonic-gate * Leading zeros must be present 35477c478bd9Sstevel@tonic-gate */ 35487c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP); 35497c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) { 35507c478bd9Sstevel@tonic-gate compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN); 35517c478bd9Sstevel@tonic-gate } 35527c478bd9Sstevel@tonic-gate 35537c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 35547c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x.%s", 35557c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 35567c478bd9Sstevel@tonic-gate port_attr->pa_dev_version, comm_svcp); 35577c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 35587c478bd9Sstevel@tonic-gate "ib.V%06xP%08x.%s", 35597c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 35607c478bd9Sstevel@tonic-gate comm_svcp); 35617c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 35627c478bd9Sstevel@tonic-gate "ib.%s", comm_svcp); 35637c478bd9Sstevel@tonic-gate 35647c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) 35657c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]); 35667c478bd9Sstevel@tonic-gate 35677c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 35687c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES); 35697c478bd9Sstevel@tonic-gate 35707c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 35717c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 35727c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 35737c478bd9Sstevel@tonic-gate } 35747c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 35757c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 35767c478bd9Sstevel@tonic-gate } 35777c478bd9Sstevel@tonic-gate 35787c478bd9Sstevel@tonic-gate 35797c478bd9Sstevel@tonic-gate /* 35807c478bd9Sstevel@tonic-gate * ibnex_delete_port_node_data() 35817c478bd9Sstevel@tonic-gate * Delete the parent private node data from the linked list 35827c478bd9Sstevel@tonic-gate * Deallocate the memory of the port/ioc attributes 35837c478bd9Sstevel@tonic-gate * Deallocate the memory of the node data 35847c478bd9Sstevel@tonic-gate */ 35857c478bd9Sstevel@tonic-gate static void 35867c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node) 35877c478bd9Sstevel@tonic-gate { 35887c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) 35897c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = NULL; 35907c478bd9Sstevel@tonic-gate else if (node->node_next == NULL) 35917c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 35927c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 35937c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 35947c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node->node_next; 35957c478bd9Sstevel@tonic-gate } else { 35967c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 35977c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 35987c478bd9Sstevel@tonic-gate } 35997c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 36007c478bd9Sstevel@tonic-gate } 36017c478bd9Sstevel@tonic-gate 36027c478bd9Sstevel@tonic-gate 36037c478bd9Sstevel@tonic-gate /* 36047c478bd9Sstevel@tonic-gate * ibnex_is_node_data_present() 36057c478bd9Sstevel@tonic-gate * Checks whether ibnex_node_t is created already 36067c478bd9Sstevel@tonic-gate * Returns ibnex_node_data_t if found, otherwise NULL 36077c478bd9Sstevel@tonic-gate */ 36087c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 36097c478bd9Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr, 36107c478bd9Sstevel@tonic-gate int index, ib_pkey_t pkey) 36117c478bd9Sstevel@tonic-gate { 36127c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 36137c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 36147c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 36157c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr; 36167c478bd9Sstevel@tonic-gate 36177c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL; 36187c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 36197c478bd9Sstevel@tonic-gate if (nodep->node_data.ioc_node.ioc_guid == 36207c478bd9Sstevel@tonic-gate ioc_infop->ioc_profile.ioc_guid) { 36217c478bd9Sstevel@tonic-gate return (nodep); 36227c478bd9Sstevel@tonic-gate } 36237c478bd9Sstevel@tonic-gate } 36247c478bd9Sstevel@tonic-gate 36257c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 36267c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 36277c478bd9Sstevel@tonic-gate nodep = nodep->node_next) 36287c478bd9Sstevel@tonic-gate if (strcmp(nodep->node_data.pseudo_node. 36297c478bd9Sstevel@tonic-gate pseudo_node_addr, (char *)attr) == 0) 36307c478bd9Sstevel@tonic-gate return (nodep); 36317c478bd9Sstevel@tonic-gate 36327c478bd9Sstevel@tonic-gate } else { 36337c478bd9Sstevel@tonic-gate ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr; 36347c478bd9Sstevel@tonic-gate 36357c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_port_node_head; nodep != NULL; 36367c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 36377c478bd9Sstevel@tonic-gate if ((nodep->node_data.port_node.port_guid == 36387c478bd9Sstevel@tonic-gate pattrp->pa_port_guid) && 36397c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_commsvc_idx == 36407c478bd9Sstevel@tonic-gate index) && 36417c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_pkey == pkey)) { 36427c478bd9Sstevel@tonic-gate return (nodep); 36437c478bd9Sstevel@tonic-gate } 36447c478bd9Sstevel@tonic-gate } 36457c478bd9Sstevel@tonic-gate } 36467c478bd9Sstevel@tonic-gate return (NULL); 36477c478bd9Sstevel@tonic-gate } 36487c478bd9Sstevel@tonic-gate 36497c478bd9Sstevel@tonic-gate /* 36507c478bd9Sstevel@tonic-gate * ibnex_lookup_unit_address_prop: 36517c478bd9Sstevel@tonic-gate * 36529d3d2ed0Shiremath * If property with name is found, return its value 36537c478bd9Sstevel@tonic-gate * otherwise return NULL. 36547c478bd9Sstevel@tonic-gate */ 36557c478bd9Sstevel@tonic-gate static char * 36569d3d2ed0Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name) 36577c478bd9Sstevel@tonic-gate { 36587c478bd9Sstevel@tonic-gate ddi_prop_t *propp; 36597c478bd9Sstevel@tonic-gate 36609d3d2ed0Shiremath /* Search the list of properties for name */ 36617c478bd9Sstevel@tonic-gate for (propp = head; propp != NULL; propp = propp->prop_next) { 36629d3d2ed0Shiremath if (strcmp(propp->prop_name, name) != 0) 36637c478bd9Sstevel@tonic-gate continue; 36649d3d2ed0Shiremath /* named property should be valid and have a value */ 36657c478bd9Sstevel@tonic-gate if (propp->prop_len <= 1) 36667c478bd9Sstevel@tonic-gate break; 36677c478bd9Sstevel@tonic-gate return ((char *)propp->prop_val); 36687c478bd9Sstevel@tonic-gate } 36697c478bd9Sstevel@tonic-gate 36707c478bd9Sstevel@tonic-gate return ((char *)0); 36717c478bd9Sstevel@tonic-gate } 36727c478bd9Sstevel@tonic-gate 36737c478bd9Sstevel@tonic-gate 36747c478bd9Sstevel@tonic-gate /* 36757c478bd9Sstevel@tonic-gate * ibnex_pseudo_initnodes() 36767c478bd9Sstevel@tonic-gate * This routine is specific to pseudo node information handling 36777c478bd9Sstevel@tonic-gate * Creates a ibnex_node_data_t all pseudo nodes children of ibnex 36787c478bd9Sstevel@tonic-gate */ 36797c478bd9Sstevel@tonic-gate void 36807c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes() 36817c478bd9Sstevel@tonic-gate { 36827c478bd9Sstevel@tonic-gate int pnam_len, len; 36837c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 36847c478bd9Sstevel@tonic-gate struct hwc_spec *list, *spec; 36857c478bd9Sstevel@tonic-gate char *node_addr, *temp, *unit_addr; 36869d3d2ed0Shiremath char *node_type; 36877c478bd9Sstevel@tonic-gate 36887c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes"); 36897c478bd9Sstevel@tonic-gate 36907c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36917c478bd9Sstevel@tonic-gate /* 36927c478bd9Sstevel@tonic-gate * get a list of all "pseudo" children of "ib". 36937c478bd9Sstevel@tonic-gate * for these children initialize/allocate an internal 36947c478bd9Sstevel@tonic-gate * ibnex_node_data_t. 36957c478bd9Sstevel@tonic-gate */ 36967c478bd9Sstevel@tonic-gate list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1); 36977c478bd9Sstevel@tonic-gate for (spec = list; spec != NULL; spec = spec->hwc_next) { 36987c478bd9Sstevel@tonic-gate if (spec->hwc_devi_sys_prop_ptr == NULL) 36997c478bd9Sstevel@tonic-gate continue; 37007c478bd9Sstevel@tonic-gate 37019d3d2ed0Shiremath /* Check "ib-node-type" property for IOC .conf */ 37029d3d2ed0Shiremath node_type = ibnex_lookup_named_prop( 37039d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "ib-node-type"); 37049d3d2ed0Shiremath 37057c478bd9Sstevel@tonic-gate /* "unit-address" property should be present */ 37069d3d2ed0Shiremath temp = ibnex_lookup_named_prop( 37079d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "unit-address"); 37087c478bd9Sstevel@tonic-gate if (temp == NULL) 37097c478bd9Sstevel@tonic-gate continue; 37107c478bd9Sstevel@tonic-gate 37117c478bd9Sstevel@tonic-gate pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2; 37127c478bd9Sstevel@tonic-gate 37137c478bd9Sstevel@tonic-gate node_addr = kmem_zalloc(pnam_len, KM_SLEEP); 37147c478bd9Sstevel@tonic-gate 37157c478bd9Sstevel@tonic-gate (void) snprintf(node_addr, 37167c478bd9Sstevel@tonic-gate pnam_len, "%s,%s", spec->hwc_devi_name, temp); 37177c478bd9Sstevel@tonic-gate 37187c478bd9Sstevel@tonic-gate nodep = ibnex_is_node_data_present( 37197c478bd9Sstevel@tonic-gate IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0); 37207c478bd9Sstevel@tonic-gate 37217c478bd9Sstevel@tonic-gate if (nodep) { 37227c478bd9Sstevel@tonic-gate kmem_free(node_addr, pnam_len); 37237c478bd9Sstevel@tonic-gate continue; 37247c478bd9Sstevel@tonic-gate } 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE, 37277c478bd9Sstevel@tonic-gate (void *)spec->hwc_devi_name, 0, 0); 37287c478bd9Sstevel@tonic-gate 37297c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_node_addr = node_addr; 37307c478bd9Sstevel@tonic-gate (void) snprintf(nodep->node_data. 37317c478bd9Sstevel@tonic-gate pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr); 37327c478bd9Sstevel@tonic-gate 37337c478bd9Sstevel@tonic-gate len = strlen(temp) + 1; 37347c478bd9Sstevel@tonic-gate unit_addr = (char *)kmem_alloc(len, KM_SLEEP); 37357c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr; 37367c478bd9Sstevel@tonic-gate (void) snprintf(unit_addr, len, "%s", temp); 37377c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr_len = len; 37387c478bd9Sstevel@tonic-gate 37399d3d2ed0Shiremath if (node_type && strcmp(node_type, "merge") == 0) 37409d3d2ed0Shiremath nodep->node_data.pseudo_node.pseudo_merge_node = 1; 37419d3d2ed0Shiremath 37427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s" 37437c478bd9Sstevel@tonic-gate " : drv name = %s", unit_addr, spec->hwc_devi_name); 37447c478bd9Sstevel@tonic-gate } 37457c478bd9Sstevel@tonic-gate hwc_free_spec_list(list); 37467c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37477c478bd9Sstevel@tonic-gate } 37487c478bd9Sstevel@tonic-gate 37497c478bd9Sstevel@tonic-gate 37507c478bd9Sstevel@tonic-gate /* 37517c478bd9Sstevel@tonic-gate * ibnex_init_child_nodedata() 37527c478bd9Sstevel@tonic-gate * 37537c478bd9Sstevel@tonic-gate * Allocate memory for the parent private data for device node 37547c478bd9Sstevel@tonic-gate * Initializes the parent private child device node data. 37557c478bd9Sstevel@tonic-gate * Returns pointer to the parent private data 37567c478bd9Sstevel@tonic-gate */ 37577c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 37587c478bd9Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index, 37597c478bd9Sstevel@tonic-gate ib_pkey_t pkey) 37607c478bd9Sstevel@tonic-gate { 37617c478bd9Sstevel@tonic-gate char *devi_name; 37627c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 37637c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_node; 37647c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 37657c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile; 37667c478bd9Sstevel@tonic-gate 37677c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 37687c478bd9Sstevel@tonic-gate 37697c478bd9Sstevel@tonic-gate node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP); 377000a3eaf3SRamaswamy Tummala node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED; 37717c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 37727c478bd9Sstevel@tonic-gate node_data->node_type = node_type; 37737c478bd9Sstevel@tonic-gate 37747c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 37757c478bd9Sstevel@tonic-gate ioc_info = (ibdm_ioc_info_t *)attr; 37767c478bd9Sstevel@tonic-gate ioc_profile = &ioc_info->ioc_profile; 37777c478bd9Sstevel@tonic-gate ioc_node = &node_data->node_data.ioc_node; 37787c478bd9Sstevel@tonic-gate 37797c478bd9Sstevel@tonic-gate ioc_node->iou_guid = ioc_info->ioc_iou_guid; 37807c478bd9Sstevel@tonic-gate ioc_node->ioc_guid = ioc_profile->ioc_guid; 37817c478bd9Sstevel@tonic-gate (void) strncpy(ioc_node->ioc_id_string, 37827c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string, 37837c478bd9Sstevel@tonic-gate IB_DM_IOC_ID_STRING_LEN); 37847c478bd9Sstevel@tonic-gate ioc_node->ioc_ngids = ioc_info->ioc_nportgids; 37857c478bd9Sstevel@tonic-gate 37867c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_ioc_node_head; 37877c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 37887c478bd9Sstevel@tonic-gate if (ibnex.ibnex_ioc_node_head) 37897c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head->node_prev = node_data; 37907c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node_data; 37917c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 37927c478bd9Sstevel@tonic-gate devi_name = (char *)attr; 37937c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_devi_name = 37947c478bd9Sstevel@tonic-gate kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP); 37957c478bd9Sstevel@tonic-gate (void) strncpy(node_data->node_data.pseudo_node. 37967c478bd9Sstevel@tonic-gate pseudo_devi_name, devi_name, strlen(devi_name)); 37977c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_pseudo_node_head; 37987c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 37997c478bd9Sstevel@tonic-gate if (ibnex.ibnex_pseudo_node_head) 38007c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head->node_prev = node_data; 38017c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head = node_data; 38027c478bd9Sstevel@tonic-gate } else { 38037c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_hcaguid = 38047c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_hca_guid; 38057c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_guid = 38067c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_guid; 38077c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_num = 38087c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_num; 38097c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_commsvc_idx = index; 38107c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_pkey = pkey; 38117c478bd9Sstevel@tonic-gate 38127c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_port_node_head; 38137c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 38147c478bd9Sstevel@tonic-gate if (ibnex.ibnex_port_node_head) 38157c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head->node_prev = node_data; 38167c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node_data; 38177c478bd9Sstevel@tonic-gate } 38187c478bd9Sstevel@tonic-gate return (node_data); 38197c478bd9Sstevel@tonic-gate } 38207c478bd9Sstevel@tonic-gate 38217c478bd9Sstevel@tonic-gate static int 38227c478bd9Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, 38237c478bd9Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *cookie) 38247c478bd9Sstevel@tonic-gate { 38257c478bd9Sstevel@tonic-gate int rc; 38267c478bd9Sstevel@tonic-gate 38277c478bd9Sstevel@tonic-gate 38287c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)", 38297c478bd9Sstevel@tonic-gate dip, rdip, eventname, cookie); 38307c478bd9Sstevel@tonic-gate 38317c478bd9Sstevel@tonic-gate rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl, 38327c478bd9Sstevel@tonic-gate rdip, eventname, cookie, NDI_EVENT_NOPASS); 38337c478bd9Sstevel@tonic-gate if (rc == NDI_SUCCESS) { 38347c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38357c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = *cookie; 38367c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38377c478bd9Sstevel@tonic-gate } 38387c478bd9Sstevel@tonic-gate 38397c478bd9Sstevel@tonic-gate return (rc); 38407c478bd9Sstevel@tonic-gate } 38417c478bd9Sstevel@tonic-gate 38427c478bd9Sstevel@tonic-gate static int 38437c478bd9Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 38447c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip, 38457c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *arg, void *bus_impldata), 38467c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id) 38477c478bd9Sstevel@tonic-gate { 38487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 38497c478bd9Sstevel@tonic-gate "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)", 38507c478bd9Sstevel@tonic-gate dip, rdip, cookie, callback, arg, cb_id); 38517c478bd9Sstevel@tonic-gate 38527c478bd9Sstevel@tonic-gate return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl, 38537c478bd9Sstevel@tonic-gate rdip, cookie, callback, arg, NDI_SLEEP, cb_id)); 38547c478bd9Sstevel@tonic-gate } 38557c478bd9Sstevel@tonic-gate 38567c478bd9Sstevel@tonic-gate static int 38577c478bd9Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) 38587c478bd9Sstevel@tonic-gate { 38597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)", 38607c478bd9Sstevel@tonic-gate dip, cb_id); 38617c478bd9Sstevel@tonic-gate 38627c478bd9Sstevel@tonic-gate return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl, 38637c478bd9Sstevel@tonic-gate cb_id)); 38647c478bd9Sstevel@tonic-gate } 38657c478bd9Sstevel@tonic-gate 38667c478bd9Sstevel@tonic-gate static int 38677c478bd9Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip, 38687c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata) 38697c478bd9Sstevel@tonic-gate { 38707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)", 38717c478bd9Sstevel@tonic-gate dip, rdip, cookie, bus_impldata); 38727c478bd9Sstevel@tonic-gate 38737c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip, 38747c478bd9Sstevel@tonic-gate cookie, bus_impldata)); 38757c478bd9Sstevel@tonic-gate } 38767c478bd9Sstevel@tonic-gate 38777c478bd9Sstevel@tonic-gate /* 38787c478bd9Sstevel@tonic-gate * ibnex_reprobe_ioc_dev() 38797c478bd9Sstevel@tonic-gate * 38807c478bd9Sstevel@tonic-gate * This could be called as a result of ibt_reprobe_dev request or 38817c478bd9Sstevel@tonic-gate * cfgadm command. The function is called from a taskq in case of 38827c478bd9Sstevel@tonic-gate * ibt_reprobe_dev and from user context for cfgadm command. 38837c478bd9Sstevel@tonic-gate * 38847c478bd9Sstevel@tonic-gate * This function reprobes the properties for one IOC dip. 38857c478bd9Sstevel@tonic-gate * 38867c478bd9Sstevel@tonic-gate * node_reprobe_state should be set before calling this function. 38877c478bd9Sstevel@tonic-gate */ 38887c478bd9Sstevel@tonic-gate void 38897c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg) 38907c478bd9Sstevel@tonic-gate { 38917c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 38927c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 38937c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_data; 38947c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 38957c478bd9Sstevel@tonic-gate 38967c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 38977c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 38987c478bd9Sstevel@tonic-gate 38997c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 39007c478bd9Sstevel@tonic-gate ASSERT(node_data); 39017c478bd9Sstevel@tonic-gate 39027c478bd9Sstevel@tonic-gate if (node_data->node_dip == NULL) { 39037c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip"); 39047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39057c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 39067c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39077c478bd9Sstevel@tonic-gate return; 39087c478bd9Sstevel@tonic-gate } 39097c478bd9Sstevel@tonic-gate ioc_data = &(node_data->node_data.ioc_node); 39107c478bd9Sstevel@tonic-gate 39117c478bd9Sstevel@tonic-gate /* Reprobe the IOC */ 39127c478bd9Sstevel@tonic-gate ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid, 39137c478bd9Sstevel@tonic-gate 1); 39147c478bd9Sstevel@tonic-gate if (ioc_info == NULL) { 39157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe"); 39167c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39177c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 1); 39187c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39197c478bd9Sstevel@tonic-gate return; 39207c478bd9Sstevel@tonic-gate } 39217c478bd9Sstevel@tonic-gate 39227c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39237c478bd9Sstevel@tonic-gate if (node_data->node_dip) 39247c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info); 39257c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 39267c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39277c478bd9Sstevel@tonic-gate 39287c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 39297c478bd9Sstevel@tonic-gate } 39307c478bd9Sstevel@tonic-gate 39317c478bd9Sstevel@tonic-gate /* 39327c478bd9Sstevel@tonic-gate * ibnex_reprobe_all() 39337c478bd9Sstevel@tonic-gate * 39347c478bd9Sstevel@tonic-gate * This could be called as a result of cfgadm command. The function 39357c478bd9Sstevel@tonic-gate * is called from user context. 39367c478bd9Sstevel@tonic-gate * 39377c478bd9Sstevel@tonic-gate * This function reprobes the properties for all IOC dips. 39387c478bd9Sstevel@tonic-gate * 39397c478bd9Sstevel@tonic-gate * ibnex_reprobe_state should be set before calling this function. 39407c478bd9Sstevel@tonic-gate */ 39417c478bd9Sstevel@tonic-gate void 39427c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_all() 39437c478bd9Sstevel@tonic-gate { 39447c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 39457c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info_list, *ioc; 39467c478bd9Sstevel@tonic-gate 39477c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 39487c478bd9Sstevel@tonic-gate 39497c478bd9Sstevel@tonic-gate /* Sweep the fabric */ 39507c478bd9Sstevel@tonic-gate ioc = ioc_info_list = ibdm_ibnex_get_ioc_list( 39517c478bd9Sstevel@tonic-gate IBDM_IBNEX_REPROBE_ALL); 39527c478bd9Sstevel@tonic-gate if (ioc_info_list == NULL) { 39537c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39547c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 39557c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39567c478bd9Sstevel@tonic-gate return; 39577c478bd9Sstevel@tonic-gate } 39587c478bd9Sstevel@tonic-gate 39597c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39607c478bd9Sstevel@tonic-gate while (ioc_info_list) { 39617c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 39627c478bd9Sstevel@tonic-gate ioc_info_list, 0, 0)) != NULL && 39637c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 39647c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info_list); 39657c478bd9Sstevel@tonic-gate } 39667c478bd9Sstevel@tonic-gate ioc_info_list = ioc_info_list->ioc_next; 39677c478bd9Sstevel@tonic-gate } 39687c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 39697c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39707c478bd9Sstevel@tonic-gate 39717c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 39727c478bd9Sstevel@tonic-gate } 39737c478bd9Sstevel@tonic-gate 39747c478bd9Sstevel@tonic-gate /* 39757c478bd9Sstevel@tonic-gate * Update the properties, if it has modified and notify IBTF client. 39767c478bd9Sstevel@tonic-gate */ 39777c478bd9Sstevel@tonic-gate static void 39787c478bd9Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info) 39797c478bd9Sstevel@tonic-gate { 39807c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 39817c478bd9Sstevel@tonic-gate dev_info_t *dip = node_data->node_dip; 39827c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 39837c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 39847c478bd9Sstevel@tonic-gate 39857c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 39867c478bd9Sstevel@tonic-gate 39877c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 39887c478bd9Sstevel@tonic-gate 39897c478bd9Sstevel@tonic-gate ioc = &node_data->node_data.ioc_node; 39907c478bd9Sstevel@tonic-gate 39917c478bd9Sstevel@tonic-gate evt_data = ioc_info->ioc_info_updated; 39927c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 39937c478bd9Sstevel@tonic-gate 39947c478bd9Sstevel@tonic-gate /* 39957c478bd9Sstevel@tonic-gate * For a disconnected IOC : 39967c478bd9Sstevel@tonic-gate * Store the ioc_profile for supplying cfgadm info 39977c478bd9Sstevel@tonic-gate * ibdm maintains no info of disconnected IOC 39987c478bd9Sstevel@tonic-gate * 39997c478bd9Sstevel@tonic-gate * For reconnected IOC : 40007c478bd9Sstevel@tonic-gate * ibdm has info of previous service entries 40017c478bd9Sstevel@tonic-gate * ioc_profile maintained by ibnexus is used to 40027c478bd9Sstevel@tonic-gate * update ib_srv_prop_updated. 40037c478bd9Sstevel@tonic-gate * Free the ibnex maintained ioc_profile 40047c478bd9Sstevel@tonic-gate */ 40057c478bd9Sstevel@tonic-gate if (ioc_info->ioc_nportgids == 0) { 40067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 40077c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC disconnected"); 40087c478bd9Sstevel@tonic-gate ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc( 40097c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP); 40107c478bd9Sstevel@tonic-gate bcopy(&ioc_info->ioc_profile, ioc->ioc_profile, 40117c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t)); 40127c478bd9Sstevel@tonic-gate 40137c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs++; 40147c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 && 40157c478bd9Sstevel@tonic-gate ioc->ioc_profile != NULL) { 40167c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 40177c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC reconnected"); 40187c478bd9Sstevel@tonic-gate if (ioc->ioc_profile->ioc_service_entries != 40197c478bd9Sstevel@tonic-gate ioc_info->ioc_profile.ioc_service_entries) 40207c478bd9Sstevel@tonic-gate evt_data.ib_srv_prop_updated = 1; 40217c478bd9Sstevel@tonic-gate 40227c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs--; 40237c478bd9Sstevel@tonic-gate kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t)); 40247c478bd9Sstevel@tonic-gate ioc->ioc_profile = NULL; 40257c478bd9Sstevel@tonic-gate } 40267c478bd9Sstevel@tonic-gate 40277c478bd9Sstevel@tonic-gate /* Update the properties that have changed */ 40287c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40297c478bd9Sstevel@tonic-gate if (evt_data.ib_gid_prop_updated) { 40307c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(dip, ioc_info) != 40317c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 40327c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40337c478bd9Sstevel@tonic-gate return; 40347c478bd9Sstevel@tonic-gate } 40357c478bd9Sstevel@tonic-gate } 40367c478bd9Sstevel@tonic-gate if (evt_data.ib_srv_prop_updated) { 40377c478bd9Sstevel@tonic-gate if (ioc_info->ioc_profile.ioc_service_entries != 0 && 40387c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(dip, ioc_info) != 40397c478bd9Sstevel@tonic-gate IBNEX_SUCCESS)) { 40407c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40417c478bd9Sstevel@tonic-gate return; 40427c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_profile.ioc_service_entries == 0) { 40437c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 40447c478bd9Sstevel@tonic-gate "service-id"); 40457c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 40467c478bd9Sstevel@tonic-gate "service-name"); 40477c478bd9Sstevel@tonic-gate } 40487c478bd9Sstevel@tonic-gate } 40497c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40507c478bd9Sstevel@tonic-gate ioc->ioc_ngids = ioc_info->ioc_nportgids; 40517c478bd9Sstevel@tonic-gate 40527c478bd9Sstevel@tonic-gate /* 40537c478bd9Sstevel@tonic-gate * Post an event if : 40547c478bd9Sstevel@tonic-gate * 1. Properites have changed or NOTIFY_ALWAYS is set. 40557c478bd9Sstevel@tonic-gate * 2. child dip is configured and a valid cookie for 40567c478bd9Sstevel@tonic-gate * IB_PROP_UPDATE_EVENT. 40577c478bd9Sstevel@tonic-gate */ 40587c478bd9Sstevel@tonic-gate if ((evt_data.ib_prop_updated != 0 || 40597c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state & 40607c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) && 40617c478bd9Sstevel@tonic-gate ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) && 40627c478bd9Sstevel@tonic-gate (evt_cookie != NULL))) { 40637c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40647c478bd9Sstevel@tonic-gate 40657c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, dip, 40667c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 40677c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 40687c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 40697c478bd9Sstevel@tonic-gate 40707c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 40717c478bd9Sstevel@tonic-gate } 40727c478bd9Sstevel@tonic-gate 40737c478bd9Sstevel@tonic-gate /* 40747c478bd9Sstevel@tonic-gate * Cleanup node_reprobe_state, for ibt_reprobe_dev 40757c478bd9Sstevel@tonic-gate * requests, when reprobe all / node reprobe is in 40767c478bd9Sstevel@tonic-gate * progress. ibnex_reprobe_ioc_dev is not called 40777c478bd9Sstevel@tonic-gate * in this case. 40787c478bd9Sstevel@tonic-gate */ 40797c478bd9Sstevel@tonic-gate if (node_data->node_reprobe_state == 40807c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) 40817c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 40827c478bd9Sstevel@tonic-gate } 40837c478bd9Sstevel@tonic-gate 40847c478bd9Sstevel@tonic-gate static ibnex_rval_t 40857c478bd9Sstevel@tonic-gate ibnex_unique_svcname(char *svcname) 40867c478bd9Sstevel@tonic-gate { 40877c478bd9Sstevel@tonic-gate int i; 40887c478bd9Sstevel@tonic-gate 40897c478bd9Sstevel@tonic-gate /* Check Port Services */ 40907c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++) 40917c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname, 40927c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[i], 4) == 0) 40937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 40947c478bd9Sstevel@tonic-gate 40957c478bd9Sstevel@tonic-gate /* Check VPPA Services */ 40967c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++) 40977c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname, 40987c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0) 40997c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 41007c478bd9Sstevel@tonic-gate 41017c478bd9Sstevel@tonic-gate /* Check HCA_SVC Services */ 41027c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++) 41037c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname, 41047c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0) 41057c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 41067c478bd9Sstevel@tonic-gate 41077c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 41087c478bd9Sstevel@tonic-gate } 41097c478bd9Sstevel@tonic-gate 41107c478bd9Sstevel@tonic-gate static void 41117c478bd9Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg) 41127c478bd9Sstevel@tonic-gate { 41137c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 41147c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 41157c478bd9Sstevel@tonic-gate 41167c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 41177c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 41187c478bd9Sstevel@tonic-gate ASSERT(node_data); 41197c478bd9Sstevel@tonic-gate 41207c478bd9Sstevel@tonic-gate /* 41217c478bd9Sstevel@tonic-gate * Return success if: 41227c478bd9Sstevel@tonic-gate * 1. Reprobe for all nodes are in progress 41237c478bd9Sstevel@tonic-gate * 2. Reprobe for this node is in progress. 41247c478bd9Sstevel@tonic-gate * The reprobe in progress will complete eventually and 41257c478bd9Sstevel@tonic-gate * update the properties, if required. 41267c478bd9Sstevel@tonic-gate */ 41277c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 41287c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state != 0 || 41297c478bd9Sstevel@tonic-gate node_data->node_reprobe_state != 0) { 41307c478bd9Sstevel@tonic-gate /* 41317c478bd9Sstevel@tonic-gate * Setting NOTIFY_ALWAYS to ensure that 41327c478bd9Sstevel@tonic-gate * DDI event is delivered always for 41337c478bd9Sstevel@tonic-gate * ibt_reprobe_dev 41347c478bd9Sstevel@tonic-gate */ 41357c478bd9Sstevel@tonic-gate node_data->node_reprobe_state |= 41367c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 41377c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 41387c478bd9Sstevel@tonic-gate return; 41397c478bd9Sstevel@tonic-gate } 41407c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 41417c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 41427c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 41437c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(arg); 41447c478bd9Sstevel@tonic-gate } 41457c478bd9Sstevel@tonic-gate 41467c478bd9Sstevel@tonic-gate 41477c478bd9Sstevel@tonic-gate /* 41487c478bd9Sstevel@tonic-gate * MPxIO pathmangement routines. Currently IB nexus does not support 41497c478bd9Sstevel@tonic-gate * any kind of pathmangement. So, just return success to make MPxIO 41507c478bd9Sstevel@tonic-gate * framework happy. 41517c478bd9Sstevel@tonic-gate */ 41527c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 41537c478bd9Sstevel@tonic-gate static int 415400a3eaf3SRamaswamy Tummala ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 41557c478bd9Sstevel@tonic-gate { 415600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip); 41577c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 41587c478bd9Sstevel@tonic-gate } 41597c478bd9Sstevel@tonic-gate 41607c478bd9Sstevel@tonic-gate 41617c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 41627c478bd9Sstevel@tonic-gate static int 416300a3eaf3SRamaswamy Tummala ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag) 41647c478bd9Sstevel@tonic-gate { 416500a3eaf3SRamaswamy Tummala dev_info_t *cdip; 416600a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data; 416700a3eaf3SRamaswamy Tummala int clnt_num_pi; 416800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip); 416900a3eaf3SRamaswamy Tummala 417000a3eaf3SRamaswamy Tummala if (pip == NULL) 417100a3eaf3SRamaswamy Tummala return (MDI_FAILURE); 417200a3eaf3SRamaswamy Tummala /* 417300a3eaf3SRamaswamy Tummala * Get the Client dev_info from the pathinfo. 417400a3eaf3SRamaswamy Tummala */ 417500a3eaf3SRamaswamy Tummala cdip = mdi_pi_get_client(pip); 417600a3eaf3SRamaswamy Tummala if (cdip == NULL) 417700a3eaf3SRamaswamy Tummala return (MDI_FAILURE); 417800a3eaf3SRamaswamy Tummala 417900a3eaf3SRamaswamy Tummala /* 418000a3eaf3SRamaswamy Tummala * How many PIs do we have from this cdip ? 418100a3eaf3SRamaswamy Tummala */ 418200a3eaf3SRamaswamy Tummala clnt_num_pi = mdi_client_get_path_count(cdip); 418300a3eaf3SRamaswamy Tummala 418400a3eaf3SRamaswamy Tummala /* 418500a3eaf3SRamaswamy Tummala * If this is the last PI that is being free'd ( called from 418600a3eaf3SRamaswamy Tummala * mdi_pi_free) we have to clean up the node data for the cdip since 418700a3eaf3SRamaswamy Tummala * the client would have been detached by mdi_devi_offline. 418800a3eaf3SRamaswamy Tummala */ 418900a3eaf3SRamaswamy Tummala if (clnt_num_pi == 1) { 419000a3eaf3SRamaswamy Tummala for (node_data = ibnex.ibnex_ioc_node_head; 419100a3eaf3SRamaswamy Tummala node_data; node_data = node_data->node_next) { 419200a3eaf3SRamaswamy Tummala if (node_data->node_dip == cdip) { 419300a3eaf3SRamaswamy Tummala node_data->node_dip = NULL; 419400a3eaf3SRamaswamy Tummala node_data->node_state = 419500a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 419600a3eaf3SRamaswamy Tummala return (MDI_SUCCESS); 419700a3eaf3SRamaswamy Tummala } 419800a3eaf3SRamaswamy Tummala } 419900a3eaf3SRamaswamy Tummala for (node_data = ibnex.ibnex_pseudo_node_head; 420000a3eaf3SRamaswamy Tummala node_data; node_data = node_data->node_next) { 420100a3eaf3SRamaswamy Tummala if (node_data->node_dip == cdip) { 420200a3eaf3SRamaswamy Tummala node_data->node_dip = NULL; 420300a3eaf3SRamaswamy Tummala node_data->node_state = 420400a3eaf3SRamaswamy Tummala IBNEX_CFGADM_UNCONFIGURED; 420500a3eaf3SRamaswamy Tummala return (MDI_SUCCESS); 420600a3eaf3SRamaswamy Tummala } 420700a3eaf3SRamaswamy Tummala } 420800a3eaf3SRamaswamy Tummala } 42097c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42107c478bd9Sstevel@tonic-gate } 42117c478bd9Sstevel@tonic-gate 42127c478bd9Sstevel@tonic-gate 42137c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 42147c478bd9Sstevel@tonic-gate static int 421500a3eaf3SRamaswamy Tummala ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip, 42167c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t arg1, int arg2) 42177c478bd9Sstevel@tonic-gate { 42187c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 421900a3eaf3SRamaswamy Tummala "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state); 42207c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42217c478bd9Sstevel@tonic-gate } 42227c478bd9Sstevel@tonic-gate 42237c478bd9Sstevel@tonic-gate 42247c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 42257c478bd9Sstevel@tonic-gate static int 42267c478bd9Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg) 42277c478bd9Sstevel@tonic-gate { 42287c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 42297c478bd9Sstevel@tonic-gate } 42307c478bd9Sstevel@tonic-gate 42317c478bd9Sstevel@tonic-gate 42327c478bd9Sstevel@tonic-gate static int 42337c478bd9Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg, 42347c478bd9Sstevel@tonic-gate pm_bus_power_op_t op, void *arg, void *result) 42357c478bd9Sstevel@tonic-gate { 42367c478bd9Sstevel@tonic-gate 42377c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 42387c478bd9Sstevel@tonic-gate 42397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op); 42407c478bd9Sstevel@tonic-gate 42417c478bd9Sstevel@tonic-gate /* 42427c478bd9Sstevel@tonic-gate * Generic processing in MPxIO framework 42437c478bd9Sstevel@tonic-gate */ 42447c478bd9Sstevel@tonic-gate ret = mdi_bus_power(parent, impl_arg, op, arg, result); 42457c478bd9Sstevel@tonic-gate 42467c478bd9Sstevel@tonic-gate switch (ret) { 42477c478bd9Sstevel@tonic-gate case MDI_SUCCESS: 42487c478bd9Sstevel@tonic-gate ret = DDI_SUCCESS; 42497c478bd9Sstevel@tonic-gate break; 42507c478bd9Sstevel@tonic-gate case MDI_FAILURE: 42517c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 42527c478bd9Sstevel@tonic-gate break; 42537c478bd9Sstevel@tonic-gate default: 42547c478bd9Sstevel@tonic-gate break; 42557c478bd9Sstevel@tonic-gate } 42567c478bd9Sstevel@tonic-gate 42577c478bd9Sstevel@tonic-gate return (ret); 42587c478bd9Sstevel@tonic-gate } 42599d3d2ed0Shiremath 42609d3d2ed0Shiremath 42619d3d2ed0Shiremath /* 42629d3d2ed0Shiremath * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config. 42639d3d2ed0Shiremath * ndi_devi_enter is not held during this call. mdi_vhci_bus_config() 42649d3d2ed0Shiremath * will have called ndi_busop_bus_config(), no need for the caller to call 42659d3d2ed0Shiremath * ndi_busop_bus_config() again. 42669d3d2ed0Shiremath * 42679d3d2ed0Shiremath * If enumerated as a child of HCA device, this could be a case for 42689d3d2ed0Shiremath * Sparc boot or device enumeration from PHCI, driven by MDI. 42699d3d2ed0Shiremath * Hold parent lock (ndi_devi_enter). The caller will have to call 42709d3d2ed0Shiremath * ndi_busop_bus_config() if this function returns SUCCESS. 42719d3d2ed0Shiremath * 42729d3d2ed0Shiremath * if the device name contains ":port", then it is the Sparc boot case. 42739d3d2ed0Shiremath * Handle this as before. 42749d3d2ed0Shiremath * 42759d3d2ed0Shiremath * If the device name does *not* contain the ":port", then : 42769d3d2ed0Shiremath * 1. ibdm to probe IOC 42779d3d2ed0Shiremath * 2. Create a pathinfo only if the IOC is reachable from the parent dip. 42789d3d2ed0Shiremath */ 42799d3d2ed0Shiremath static int 42809d3d2ed0Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag, 42819d3d2ed0Shiremath ddi_bus_config_op_t op, void *devname, dev_info_t **child, 42829d3d2ed0Shiremath int *need_bus_config) 42839d3d2ed0Shiremath { 42849d3d2ed0Shiremath int ret = DDI_FAILURE, circ; 42859d3d2ed0Shiremath dev_info_t *pdip = *pdipp; 42869d3d2ed0Shiremath ib_guid_t iou_guid, ioc_guid; 42879d3d2ed0Shiremath char *ioc_guid_str; 42889d3d2ed0Shiremath 42899d3d2ed0Shiremath 42909d3d2ed0Shiremath *need_bus_config = 1; 42919d3d2ed0Shiremath 42929d3d2ed0Shiremath if (pdip == ibnex.ibnex_dip) { 42939d3d2ed0Shiremath if (ibnex_devname_to_node_n_ioc_guids( 42949d3d2ed0Shiremath (char *)devname, &iou_guid, &ioc_guid, 42959d3d2ed0Shiremath &ioc_guid_str) != IBNEX_SUCCESS) { 42969d3d2ed0Shiremath return (ret); 42979d3d2ed0Shiremath } 42989d3d2ed0Shiremath ret = mdi_vhci_bus_config(pdip, flag, op, devname, child, 42999d3d2ed0Shiremath ioc_guid_str); 43009d3d2ed0Shiremath kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1); 43019d3d2ed0Shiremath if (ret == MDI_SUCCESS) 43029d3d2ed0Shiremath *need_bus_config = 0; 43039d3d2ed0Shiremath } else { 43045e3986cbScth mdi_devi_enter(pdip, &circ); 43059d3d2ed0Shiremath if (strstr((char *)devname, ":port=") != NULL) { 43069d3d2ed0Shiremath ret = ibnex_config_root_iocnode(pdip, devname); 43079d3d2ed0Shiremath ASSERT(ibnex.ibnex_dip == NULL); 43089d3d2ed0Shiremath *pdipp = ibnex.ibnex_dip; 43099d3d2ed0Shiremath } else { 43109d3d2ed0Shiremath ret = ibnex_config_ioc_node(devname, pdip); 43119d3d2ed0Shiremath } 43125e3986cbScth mdi_devi_exit(pdip, circ); 43139d3d2ed0Shiremath } 43149d3d2ed0Shiremath return (ret); 43159d3d2ed0Shiremath } 43169d3d2ed0Shiremath 43179d3d2ed0Shiremath static int 43189d3d2ed0Shiremath ibnex_is_merge_node(dev_info_t *child) 43199d3d2ed0Shiremath { 43209d3d2ed0Shiremath char *node; 43219d3d2ed0Shiremath int ret = IBNEX_INVALID_NODE; 43229d3d2ed0Shiremath 43239d3d2ed0Shiremath if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 43249d3d2ed0Shiremath DDI_PROP_DONTPASS, "ib-node-type", &node) != 43259d3d2ed0Shiremath DDI_PROP_SUCCESS) { 43269d3d2ed0Shiremath return (IBNEX_FAILURE); 43279d3d2ed0Shiremath } 43289d3d2ed0Shiremath 43299d3d2ed0Shiremath if (node != NULL && *node != 0) { 43309d3d2ed0Shiremath if (strcmp(node, "merge") == 0) 43319d3d2ed0Shiremath ret = IBNEX_SUCCESS; 43329d3d2ed0Shiremath else { 43339d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 43349d3d2ed0Shiremath "\tis_merge_node: ib-node-type = %s", node); 43359d3d2ed0Shiremath } 43369d3d2ed0Shiremath } 43379d3d2ed0Shiremath 43389d3d2ed0Shiremath ddi_prop_free(node); 43399d3d2ed0Shiremath return (ret); 43409d3d2ed0Shiremath } 43419d3d2ed0Shiremath 43429d3d2ed0Shiremath /* 43439d3d2ed0Shiremath * Checks if the dn_head for the driver has already 43449d3d2ed0Shiremath * initialized by the prom tree. 43459d3d2ed0Shiremath */ 4346f7209cf2Spramodbg void 43479d3d2ed0Shiremath ibnex_hw_in_dev_tree(char *driver_name) 43489d3d2ed0Shiremath { 43499d3d2ed0Shiremath major_t major; 43509d3d2ed0Shiremath 4351f7209cf2Spramodbg IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name); 4352f7209cf2Spramodbg 43539d3d2ed0Shiremath if (devnamesp == NULL) 4354f7209cf2Spramodbg return; 43559d3d2ed0Shiremath 43569d3d2ed0Shiremath major = ddi_name_to_major(driver_name); 43579d3d2ed0Shiremath if (major == -1) 4358f7209cf2Spramodbg return; 43599d3d2ed0Shiremath 4360f7209cf2Spramodbg if (devnamesp[major].dn_head != (dev_info_t *)NULL) 4361f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_IN_DEVTREE; 43629d3d2ed0Shiremath } 436300a3eaf3SRamaswamy Tummala 436400a3eaf3SRamaswamy Tummala int 436500a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info) 436600a3eaf3SRamaswamy Tummala { 436700a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list; 436800a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 436900a3eaf3SRamaswamy Tummala int rc = IBNEX_FAILURE; 437000a3eaf3SRamaswamy Tummala 437100a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 437200a3eaf3SRamaswamy Tummala /* 437300a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs 437400a3eaf3SRamaswamy Tummala */ 437500a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list; 437600a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) { 437700a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 437800a3eaf3SRamaswamy Tummala if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) == 437900a3eaf3SRamaswamy Tummala IBNEX_SUCCESS) 438000a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 438100a3eaf3SRamaswamy Tummala } 438200a3eaf3SRamaswamy Tummala return (rc); 438300a3eaf3SRamaswamy Tummala } 438400a3eaf3SRamaswamy Tummala 438500a3eaf3SRamaswamy Tummala static int 438600a3eaf3SRamaswamy Tummala ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip, 438700a3eaf3SRamaswamy Tummala int pdip_reachable_checked) 438800a3eaf3SRamaswamy Tummala { 438900a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data; 439000a3eaf3SRamaswamy Tummala int create_pdip = 0; 439100a3eaf3SRamaswamy Tummala int rc = IBNEX_SUCCESS; 439200a3eaf3SRamaswamy Tummala 439300a3eaf3SRamaswamy Tummala 439400a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 439500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 439600a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip, 439700a3eaf3SRamaswamy Tummala pdip_reachable_checked); 439800a3eaf3SRamaswamy Tummala 439900a3eaf3SRamaswamy Tummala if (pdip_reachable_checked == 0) { 440000a3eaf3SRamaswamy Tummala if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) { 440100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 440200a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip: ioc %p not reachable" 440300a3eaf3SRamaswamy Tummala "from %p", ioc_info, pdip); 440400a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 440500a3eaf3SRamaswamy Tummala } 440600a3eaf3SRamaswamy Tummala } 440700a3eaf3SRamaswamy Tummala 440800a3eaf3SRamaswamy Tummala node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 440900a3eaf3SRamaswamy Tummala (void *)ioc_info, 0, 0); 441000a3eaf3SRamaswamy Tummala 441100a3eaf3SRamaswamy Tummala if (node_data && node_data->node_ap_state == 441200a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED) { 441300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 441400a3eaf3SRamaswamy Tummala "\tioc_config_from_pdip: Unconfigured node"); 441500a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 441600a3eaf3SRamaswamy Tummala } 441700a3eaf3SRamaswamy Tummala 441800a3eaf3SRamaswamy Tummala 441900a3eaf3SRamaswamy Tummala if (node_data == NULL) { 442000a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc; 442100a3eaf3SRamaswamy Tummala 442200a3eaf3SRamaswamy Tummala create_pdip = 1; 442300a3eaf3SRamaswamy Tummala 442400a3eaf3SRamaswamy Tummala node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE, 442500a3eaf3SRamaswamy Tummala ioc_info, 0, 0); 442600a3eaf3SRamaswamy Tummala ASSERT(node_data); 442700a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node; 442800a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN, 442900a3eaf3SRamaswamy Tummala "%llX", 443000a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid); 443100a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN, 443200a3eaf3SRamaswamy Tummala "%llX,%llX", 443300a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid, 443400a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_iou_guid); 443500a3eaf3SRamaswamy Tummala } else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) { 443600a3eaf3SRamaswamy Tummala create_pdip = 1; 443700a3eaf3SRamaswamy Tummala } 443800a3eaf3SRamaswamy Tummala 443900a3eaf3SRamaswamy Tummala if (create_pdip) { 444000a3eaf3SRamaswamy Tummala rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip); 444100a3eaf3SRamaswamy Tummala } 444200a3eaf3SRamaswamy Tummala 444300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x", 444400a3eaf3SRamaswamy Tummala rc); 444500a3eaf3SRamaswamy Tummala return (rc); 444600a3eaf3SRamaswamy Tummala } 444700a3eaf3SRamaswamy Tummala 444800a3eaf3SRamaswamy Tummala /* 444900a3eaf3SRamaswamy Tummala * This function checks if a pathinfo has already been created 445000a3eaf3SRamaswamy Tummala * for the HCA parent. The function returns SUCCESS if a pathinfo 445100a3eaf3SRamaswamy Tummala * has already been created, FAILURE if not. 445200a3eaf3SRamaswamy Tummala */ 445300a3eaf3SRamaswamy Tummala static int 445400a3eaf3SRamaswamy Tummala ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent) 445500a3eaf3SRamaswamy Tummala { 445600a3eaf3SRamaswamy Tummala int rc; 445700a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc; 445800a3eaf3SRamaswamy Tummala 445900a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node; 446000a3eaf3SRamaswamy Tummala if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str, 446100a3eaf3SRamaswamy Tummala (char *)ioc->ioc_phci_guid) != NULL) 446200a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS; 446300a3eaf3SRamaswamy Tummala else 446400a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE; 446500a3eaf3SRamaswamy Tummala 446600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, " 446700a3eaf3SRamaswamy Tummala "phci_guid %s, parent %p, rc %x", 446800a3eaf3SRamaswamy Tummala ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc); 446900a3eaf3SRamaswamy Tummala return (rc); 447000a3eaf3SRamaswamy Tummala } 447100a3eaf3SRamaswamy Tummala 447200a3eaf3SRamaswamy Tummala static int 447300a3eaf3SRamaswamy Tummala ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip) 447400a3eaf3SRamaswamy Tummala { 447500a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list; 447600a3eaf3SRamaswamy Tummala dev_info_t *hca_dip; 447700a3eaf3SRamaswamy Tummala 447800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)", 447900a3eaf3SRamaswamy Tummala ioc_info, pdip); 448000a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list; 448100a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) { 448200a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 448300a3eaf3SRamaswamy Tummala if (hca_dip == pdip) { 448400a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", 448500a3eaf3SRamaswamy Tummala "\tioc_pi_reachable FAILURE"); 448600a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS); 448700a3eaf3SRamaswamy Tummala } 448800a3eaf3SRamaswamy Tummala } 448900a3eaf3SRamaswamy Tummala 449000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE"); 449100a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE); 449200a3eaf3SRamaswamy Tummala } 4493