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 /* 22a1e3386eShiremath * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <sys/conf.h> 477c478bd9Sstevel@tonic-gate #include <sys/stat.h> 487c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 497c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 507c478bd9Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 517c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h> 527c478bd9Sstevel@tonic-gate #include <sys/sunpm.h> 537c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h> 547c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h> 557c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h> 567c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h> 577c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h> 587c478bd9Sstevel@tonic-gate #include <sys/file.h> 597c478bd9Sstevel@tonic-gate #include <sys/hwconf.h> 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* Function prototypes */ 627c478bd9Sstevel@tonic-gate static int ibnex_attach(dev_info_t *, ddi_attach_cmd_t); 637c478bd9Sstevel@tonic-gate static int ibnex_getinfo(dev_info_t *, ddi_info_cmd_t, 647c478bd9Sstevel@tonic-gate void *, void **); 657c478bd9Sstevel@tonic-gate static int ibnex_detach(dev_info_t *, ddi_detach_cmd_t); 667c478bd9Sstevel@tonic-gate static int ibnex_busctl(dev_info_t *, 677c478bd9Sstevel@tonic-gate dev_info_t *, ddi_ctl_enum_t, void *, void *); 687c478bd9Sstevel@tonic-gate static int ibnex_map_fault(dev_info_t *, 697c478bd9Sstevel@tonic-gate dev_info_t *, struct hat *, struct seg *, 707c478bd9Sstevel@tonic-gate caddr_t, struct devpage *, pfn_t, uint_t, uint_t); 717c478bd9Sstevel@tonic-gate static int ibnex_init_child(dev_info_t *); 727c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_comm_svc_init(char *, ibnex_node_type_t); 737c478bd9Sstevel@tonic-gate static void ibnex_comm_svc_fini(); 747c478bd9Sstevel@tonic-gate dev_info_t *ibnex_commsvc_initnode(dev_info_t *, 757c478bd9Sstevel@tonic-gate ibdm_port_attr_t *, int, int, ib_pkey_t, int *, 767c478bd9Sstevel@tonic-gate int); 777c478bd9Sstevel@tonic-gate static void ibnex_delete_port_node_data(ibnex_node_data_t *); 787c478bd9Sstevel@tonic-gate int ibnex_get_dip_from_guid(ib_guid_t, int, 797c478bd9Sstevel@tonic-gate ib_pkey_t, dev_info_t **); 807c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t, 817c478bd9Sstevel@tonic-gate void *, int, ib_pkey_t); 827c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *, 837c478bd9Sstevel@tonic-gate int, ib_pkey_t); 847c478bd9Sstevel@tonic-gate static int ibnex_create_port_node_prop(ibdm_port_attr_t *, 857c478bd9Sstevel@tonic-gate dev_info_t *, char *, ib_pkey_t); 867c478bd9Sstevel@tonic-gate void ibnex_dm_callback(void *, ibdm_events_t); 877c478bd9Sstevel@tonic-gate static int ibnex_create_port_compatible_prop(dev_info_t *, 887c478bd9Sstevel@tonic-gate char *, ibdm_port_attr_t *); 897c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_srv_props( 907c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 917c478bd9Sstevel@tonic-gate static int ibnex_get_eventcookie(dev_info_t *, 927c478bd9Sstevel@tonic-gate dev_info_t *, char *, ddi_eventcookie_t *); 937c478bd9Sstevel@tonic-gate static int ibnex_add_eventcall(dev_info_t *, dev_info_t *, 947c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void (*)(dev_info_t *, 957c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *, void *), 967c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id); 977c478bd9Sstevel@tonic-gate static int ibnex_remove_eventcall(dev_info_t *, 987c478bd9Sstevel@tonic-gate ddi_callback_id_t); 997c478bd9Sstevel@tonic-gate static int ibnex_post_event(dev_info_t *, dev_info_t *, 1007c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *); 1017c478bd9Sstevel@tonic-gate static int ibnex_bus_config(dev_info_t *, uint_t, 1027c478bd9Sstevel@tonic-gate ddi_bus_config_op_t, void *, dev_info_t **); 1037c478bd9Sstevel@tonic-gate static int ibnex_bus_unconfig(dev_info_t *, 1047c478bd9Sstevel@tonic-gate uint_t, ddi_bus_config_op_t, void *); 1057c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_port_node(dev_info_t *, char *); 1067c478bd9Sstevel@tonic-gate static dev_info_t *ibnex_config_obp_args(dev_info_t *, char *); 1077c478bd9Sstevel@tonic-gate static int ibnex_get_pkey_commsvc_index_portnum( 1087c478bd9Sstevel@tonic-gate char *, int *, ib_pkey_t *, uint8_t *); 1097c478bd9Sstevel@tonic-gate static void ibnex_config_all_children(dev_info_t *); 1107c478bd9Sstevel@tonic-gate static int ibnex_devname_to_portnum(char *, uint8_t *); 1117c478bd9Sstevel@tonic-gate static void ibnex_create_vppa_nodes( 1127c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1137c478bd9Sstevel@tonic-gate static void ibnex_create_port_nodes( 1147c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1157c478bd9Sstevel@tonic-gate static void ibnex_create_hcasvc_nodes( 1167c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *); 1177c478bd9Sstevel@tonic-gate static int ibnex_config_root_iocnode(dev_info_t *, char *); 1187c478bd9Sstevel@tonic-gate static int ibnex_devname2port(char *, int *); 1199d3d2ed0Shiremath static int ibnex_config_ioc_node(char *, dev_info_t *); 1207c478bd9Sstevel@tonic-gate static int ibnex_devname_to_node_n_ioc_guids( 1219d3d2ed0Shiremath char *, ib_guid_t *, ib_guid_t *, char **); 1227c478bd9Sstevel@tonic-gate static int ibnex_is_ioc_present(ib_guid_t); 1237c478bd9Sstevel@tonic-gate static void ibnex_ioc_node_cleanup(); 1247c478bd9Sstevel@tonic-gate static void ibnex_delete_ioc_node_data(ibnex_node_data_t *); 1259d3d2ed0Shiremath int ibnex_ioc_initnode(ibdm_ioc_info_t *, int, 1269d3d2ed0Shiremath dev_info_t *); 1277c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_node_prop( 1287c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *, dev_info_t *); 1297c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_compatible_prop( 1307c478bd9Sstevel@tonic-gate dev_info_t *, ib_dm_ioc_ctrl_profile_t *); 1317c478bd9Sstevel@tonic-gate uint64_t ibnex_str2hex(char *, int, int *); 1327c478bd9Sstevel@tonic-gate static int ibnex_str2int(char *, int, int *); 1337c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_portgid_prop( 1347c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *); 1357c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int); 1367c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_all(); 1377c478bd9Sstevel@tonic-gate ibt_status_t ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *); 1387c478bd9Sstevel@tonic-gate static int ibnex_prom_devname_to_pkey_n_portnum( 1397c478bd9Sstevel@tonic-gate char *, ib_pkey_t *, uint8_t *); 1407c478bd9Sstevel@tonic-gate void ibnex_pseudo_initnodes(void); 1419d3d2ed0Shiremath static char *ibnex_lookup_named_prop(ddi_prop_t *, char *); 1427c478bd9Sstevel@tonic-gate static void ibnex_pseudo_node_cleanup(void); 1437c478bd9Sstevel@tonic-gate static int ibnex_name_child(dev_info_t *, char *, int); 1447c478bd9Sstevel@tonic-gate static int ibnex_name_pseudo_child(dev_info_t *, char *); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_dev(void *); 1477c478bd9Sstevel@tonic-gate void ibnex_reprobe_ioc_all(); 1487c478bd9Sstevel@tonic-gate static void ibnex_update_prop(ibnex_node_data_t *, 1497c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *); 1507c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_unique_svcname(char *); 1517c478bd9Sstevel@tonic-gate static void ibnex_handle_reprobe_dev(void *arg); 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate extern int ibnex_open(dev_t *, int, int, cred_t *); 1547c478bd9Sstevel@tonic-gate extern int ibnex_close(dev_t, int, int, cred_t *); 1557c478bd9Sstevel@tonic-gate extern int ibnex_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1567c478bd9Sstevel@tonic-gate extern int ibnex_offline_childdip(dev_info_t *); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate static int ibnex_ioc_create_pi( 1599d3d2ed0Shiremath ibdm_ioc_info_t *, ibnex_node_data_t *, 1609d3d2ed0Shiremath dev_info_t *); 1617c478bd9Sstevel@tonic-gate static int ibnex_bus_power(dev_info_t *, void *, 1627c478bd9Sstevel@tonic-gate pm_bus_power_op_t, void *, void *); 1639d3d2ed0Shiremath int ibnex_pseudo_create_pi(ibnex_node_data_t *, 1649d3d2ed0Shiremath dev_info_t *); 16505fa0d51Spramodbg static int ibnex_pseudo_config_one( 16605fa0d51Spramodbg ibnex_node_data_t *, char *, dev_info_t *); 1679d3d2ed0Shiremath static int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **, 1689d3d2ed0Shiremath char *, char *); 1699d3d2ed0Shiremath static void ibnex_config_pseudo_all(dev_info_t *); 1709d3d2ed0Shiremath static int ibnex_ioc_bus_config_one(dev_info_t **, uint_t, 1719d3d2ed0Shiremath ddi_bus_config_op_t, void *, dev_info_t **, int *); 1729d3d2ed0Shiremath static int ibnex_is_merge_node(dev_info_t *); 173f7209cf2Spramodbg static void ibnex_hw_in_dev_tree(char *); 1749d3d2ed0Shiremath 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of HCA nexus driver. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate struct bus_ops ibnex_ci_busops = { 1797c478bd9Sstevel@tonic-gate BUSO_REV, 1807c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 1817c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 1827c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 1837c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 1847c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 1857c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 1867c478bd9Sstevel@tonic-gate NULL, 1877c478bd9Sstevel@tonic-gate NULL, 1887c478bd9Sstevel@tonic-gate NULL, 1897c478bd9Sstevel@tonic-gate NULL, 1907c478bd9Sstevel@tonic-gate NULL, 1917c478bd9Sstevel@tonic-gate NULL, 1927c478bd9Sstevel@tonic-gate NULL, 1937c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 1947c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 1957c478bd9Sstevel@tonic-gate NULL, /* bus_get_eventcookie */ 1967c478bd9Sstevel@tonic-gate NULL, /* bus_add_eventcall */ 1977c478bd9Sstevel@tonic-gate NULL, /* bus_remove_eventcall */ 1987c478bd9Sstevel@tonic-gate NULL, /* bus_post_event */ 1997c478bd9Sstevel@tonic-gate NULL, 2007c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2017c478bd9Sstevel@tonic-gate ibnex_bus_unconfig /* bus unconfig */ 2027c478bd9Sstevel@tonic-gate }; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Prototype declarations for the VHCI options 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Functions registered with the mpxio framework 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int); 2117c478bd9Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int); 2127c478bd9Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *, 2137c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int); 2147c478bd9Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = { 2187c478bd9Sstevel@tonic-gate MDI_VHCI_OPS_REV, 2197c478bd9Sstevel@tonic-gate ib_vhci_pi_init, 2207c478bd9Sstevel@tonic-gate ib_vhci_pi_uninit, 2217c478bd9Sstevel@tonic-gate ib_vhci_pi_state_change, 2227c478bd9Sstevel@tonic-gate ib_vhci_failover 2237c478bd9Sstevel@tonic-gate }; 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of IB nexus driver. 2287c478bd9Sstevel@tonic-gate * IB nexus drivers does not support any DMA operations for its children 2297c478bd9Sstevel@tonic-gate * as there is no such concept in Infiniband. All the memory operations 2307c478bd9Sstevel@tonic-gate * and DMA operations required by the child drivers can be performed using 2317c478bd9Sstevel@tonic-gate * the IBTF API. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = { 2347c478bd9Sstevel@tonic-gate BUSO_REV, 2357c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */ 2367c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 2377c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */ 2387c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */ 2397c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */ 2407c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */ 2417c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl, 2427c478bd9Sstevel@tonic-gate NULL, 2437c478bd9Sstevel@tonic-gate NULL, 2447c478bd9Sstevel@tonic-gate NULL, 2457c478bd9Sstevel@tonic-gate NULL, 2467c478bd9Sstevel@tonic-gate NULL, 2477c478bd9Sstevel@tonic-gate NULL, 2487c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */ 2497c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 2507c478bd9Sstevel@tonic-gate ibnex_get_eventcookie, /* bus_get_eventcookie */ 2517c478bd9Sstevel@tonic-gate ibnex_add_eventcall, /* bus_add_eventcall */ 2527c478bd9Sstevel@tonic-gate ibnex_remove_eventcall, /* bus_remove_eventcall */ 2537c478bd9Sstevel@tonic-gate ibnex_post_event, /* bus_post_event */ 2547c478bd9Sstevel@tonic-gate NULL, 2557c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */ 2567c478bd9Sstevel@tonic-gate ibnex_bus_unconfig, /* bus unconfig */ 2577c478bd9Sstevel@tonic-gate NULL, /* bus fm init */ 2587c478bd9Sstevel@tonic-gate NULL, /* bus fm fini */ 2597c478bd9Sstevel@tonic-gate NULL, /* bus fm access enter */ 2607c478bd9Sstevel@tonic-gate NULL, /* bus fm access exit */ 2617c478bd9Sstevel@tonic-gate ibnex_bus_power /* bus power */ 2627c478bd9Sstevel@tonic-gate }; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* ibnex cb_ops */ 2657c478bd9Sstevel@tonic-gate static struct cb_ops ibnex_cbops = { 2667c478bd9Sstevel@tonic-gate ibnex_open, /* open */ 2677c478bd9Sstevel@tonic-gate ibnex_close, /* close */ 2687c478bd9Sstevel@tonic-gate nodev, /* strategy */ 2697c478bd9Sstevel@tonic-gate nodev, /* print */ 2707c478bd9Sstevel@tonic-gate nodev, /* dump */ 2717c478bd9Sstevel@tonic-gate nodev, /* read */ 2727c478bd9Sstevel@tonic-gate nodev, /* write */ 2737c478bd9Sstevel@tonic-gate ibnex_ioctl, /* ioctl */ 2747c478bd9Sstevel@tonic-gate nodev, /* devmap */ 2757c478bd9Sstevel@tonic-gate nodev, /* mmap */ 2767c478bd9Sstevel@tonic-gate nodev, /* segmap */ 2777c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 2787c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 2797c478bd9Sstevel@tonic-gate NULL, /* stream */ 2807c478bd9Sstevel@tonic-gate D_MP, /* cb_flag */ 2817c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 2827c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 2837c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 2847c478bd9Sstevel@tonic-gate }; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Device options 2887c478bd9Sstevel@tonic-gate * Note: ddi_no_info needs to change during devfs time frame. The drivers 2897c478bd9Sstevel@tonic-gate * with 1 to 1 mapping between minor node and instance should use 2907c478bd9Sstevel@tonic-gate * ddi_1to1_info. (See bug id 4424752) 2917c478bd9Sstevel@tonic-gate */ 2927c478bd9Sstevel@tonic-gate static struct dev_ops ibnex_ops = { 2937c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 2947c478bd9Sstevel@tonic-gate 0, /* refcnt */ 2957c478bd9Sstevel@tonic-gate ibnex_getinfo, /* info */ 2967c478bd9Sstevel@tonic-gate nulldev, /* identify */ 2977c478bd9Sstevel@tonic-gate nulldev, /* probe */ 2987c478bd9Sstevel@tonic-gate ibnex_attach, /* attach */ 2997c478bd9Sstevel@tonic-gate ibnex_detach, /* detach */ 3007c478bd9Sstevel@tonic-gate nodev, /* reset */ 3017c478bd9Sstevel@tonic-gate &ibnex_cbops, /* driver ops - devctl interfaces */ 3027c478bd9Sstevel@tonic-gate &ibnex_bus_ops, /* bus operations */ 3037c478bd9Sstevel@tonic-gate nulldev /* power */ 3047c478bd9Sstevel@tonic-gate }; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate /* Module linkage information for the kernel. */ 3077c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3087c478bd9Sstevel@tonic-gate &mod_driverops, /* Driver module */ 3097c478bd9Sstevel@tonic-gate "IB nexus %I%", /* Driver name and version */ 3107c478bd9Sstevel@tonic-gate &ibnex_ops, /* driver ops */ 3117c478bd9Sstevel@tonic-gate }; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3147c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 3157c478bd9Sstevel@tonic-gate }; 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Global per-instance IB Nexus data. 3197c478bd9Sstevel@tonic-gate * There is only one instance of IB Nexus supported. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate ibnex_t ibnex; 3227c478bd9Sstevel@tonic-gate #ifdef __lock_lint 3237c478bd9Sstevel@tonic-gate extern ibdm_t ibdm; 3247c478bd9Sstevel@tonic-gate #endif 3257c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s)) 3267c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs 3277c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs 3287c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs 3297c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names)) 3307c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s)) 3317c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex)) 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* The port settling time in seconds */ 3347c478bd9Sstevel@tonic-gate int ibnex_port_settling_time = 8; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */ 3377c478bd9Sstevel@tonic-gate static struct ibnex_property { 3387c478bd9Sstevel@tonic-gate char *name; 3397c478bd9Sstevel@tonic-gate ibnex_node_type_t type; 3407c478bd9Sstevel@tonic-gate } ibnex_properties[] = { 3417c478bd9Sstevel@tonic-gate { "port-svc-list", IBNEX_PORT_COMMSVC_NODE}, 3427c478bd9Sstevel@tonic-gate { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE}, 3437c478bd9Sstevel@tonic-gate { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE} 3447c478bd9Sstevel@tonic-gate }; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \ 3477c478bd9Sstevel@tonic-gate (sizeof (struct ibnex_property)) 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate /* 3507c478bd9Sstevel@tonic-gate * Event Definition 3517c478bd9Sstevel@tonic-gate * Single event, event name defined in ibti_common.h. 3527c478bd9Sstevel@tonic-gate * Event posted to specific child handler. Event posted 3537c478bd9Sstevel@tonic-gate * at kernel priority. 3547c478bd9Sstevel@tonic-gate */ 3557c478bd9Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = { 3567c478bd9Sstevel@tonic-gate {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL, 3577c478bd9Sstevel@tonic-gate NDI_EVENT_POST_TO_TGT} 3587c478bd9Sstevel@tonic-gate }; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate #define IB_N_NDI_EVENTS \ 3617c478bd9Sstevel@tonic-gate (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t)) 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = { 3647c478bd9Sstevel@tonic-gate NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs}; 3659d3d2ed0Shiremath static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED; 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* 3697c478bd9Sstevel@tonic-gate * _init 3707c478bd9Sstevel@tonic-gate * Loadable module init, called before any other module. 3717c478bd9Sstevel@tonic-gate */ 3727c478bd9Sstevel@tonic-gate int 3737c478bd9Sstevel@tonic-gate _init(void) 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate int error; 376f7209cf2Spramodbg char **hca_driver_list; 377f7209cf2Spramodbg int i, ndrivers; 3787c478bd9Sstevel@tonic-gate 3799d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) { 380f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE; 381f7209cf2Spramodbg hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers); 382f7209cf2Spramodbg for (i = 0; i < ndrivers; i++) { 383f7209cf2Spramodbg ibnex_hw_in_dev_tree(hca_driver_list[i]); 384f7209cf2Spramodbg if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE) 385f7209cf2Spramodbg break; 386f7209cf2Spramodbg } 387f7209cf2Spramodbg mdi_free_phci_driver_list(hca_driver_list, ndrivers); 3889d3d2ed0Shiremath } 3899d3d2ed0Shiremath 3909d3d2ed0Shiremath /* 3919d3d2ed0Shiremath * IB Nexus _init can be called while force attaching 3929d3d2ed0Shiremath * IB Nexus driver or when a HCA is hotplugged. 3939d3d2ed0Shiremath * 3949d3d2ed0Shiremath * If IB HW is not in device tree or if no HCA driver 3959d3d2ed0Shiremath * has been attached, fail IB Nexus _init(). 3969d3d2ed0Shiremath */ 3979d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE && 3989d3d2ed0Shiremath ibt_hw_is_present() == 0) { 3999d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW"); 4009d3d2ed0Shiremath return (DDI_FAILURE); 4019d3d2ed0Shiremath } 4029d3d2ed0Shiremath 4037c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_init"); 4047c478bd9Sstevel@tonic-gate mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL); 4057c478bd9Sstevel@tonic-gate cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL); 4067c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 4077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed"); 4087c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4097c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 4107c478bd9Sstevel@tonic-gate } else { 4117c478bd9Sstevel@tonic-gate ibdm_ibnex_register_callback(ibnex_dm_callback); 4127c478bd9Sstevel@tonic-gate ibtl_ibnex_register_callback(ibnex_ibtl_callback); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate return (error); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate /* 4197c478bd9Sstevel@tonic-gate * _fini 4207c478bd9Sstevel@tonic-gate * Prepares a module for unloading. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate int 4237c478bd9Sstevel@tonic-gate _fini(void) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate int error; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_fini"); 4287c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) { 4297c478bd9Sstevel@tonic-gate return (error); 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate ibdm_ibnex_unregister_callback(); 4327c478bd9Sstevel@tonic-gate ibtl_ibnex_unregister_callback(); 4337c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex); 4347c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv); 4357c478bd9Sstevel@tonic-gate return (0); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate /* 4407c478bd9Sstevel@tonic-gate * _info 4417c478bd9Sstevel@tonic-gate * Returns information about loadable module. 4427c478bd9Sstevel@tonic-gate */ 4437c478bd9Sstevel@tonic-gate int 4447c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4457c478bd9Sstevel@tonic-gate { 4467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_info"); 4477c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate /* 4527c478bd9Sstevel@tonic-gate * ibnex_attach 4537c478bd9Sstevel@tonic-gate * Configure and attach an instance of the IB Nexus driver 4547c478bd9Sstevel@tonic-gate * Only one instance of IB Nexus is supported 4557c478bd9Sstevel@tonic-gate * Create a minor node for cfgadm purpose 4567c478bd9Sstevel@tonic-gate * Initialize communication services 4577c478bd9Sstevel@tonic-gate * Register callback with IBDM 4587c478bd9Sstevel@tonic-gate * Register callback with IBTL 4597c478bd9Sstevel@tonic-gate */ 4607c478bd9Sstevel@tonic-gate static int 4617c478bd9Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 4627c478bd9Sstevel@tonic-gate { 4637c478bd9Sstevel@tonic-gate int i; 4647c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd); 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate switch (cmd) { 4697c478bd9Sstevel@tonic-gate case DDI_ATTACH: 4707c478bd9Sstevel@tonic-gate break; 4717c478bd9Sstevel@tonic-gate case DDI_RESUME: 4727c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME"); 4737c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4747c478bd9Sstevel@tonic-gate default: 4757c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* Fail attach for more than one instance */ 4797c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 4807c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) { 4817c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4827c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* Register with MPxIO framework */ 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0) 4897c478bd9Sstevel@tonic-gate != MDI_SUCCESS) { 4907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 4917c478bd9Sstevel@tonic-gate "\tattach: mdi_vhci_register() failed"); 4927c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4937c478bd9Sstevel@tonic-gate } 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate /* 4977c478bd9Sstevel@tonic-gate * Create the "fabric" devctl minor-node for IB DR support. 4987c478bd9Sstevel@tonic-gate * The minor number for the "devctl" node is in the same format 4997c478bd9Sstevel@tonic-gate * as the AP minor nodes. 5007c478bd9Sstevel@tonic-gate */ 5017c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance, 5027c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 5037c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5047c478bd9Sstevel@tonic-gate "\tattach: failed to create fabric minornode"); 5057c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5067c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* 5117c478bd9Sstevel@tonic-gate * Set pm-want-child-notification property for 5127c478bd9Sstevel@tonic-gate * power management of the phci and client 5137c478bd9Sstevel@tonic-gate */ 5147c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 5157c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 5167c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5177c478bd9Sstevel@tonic-gate "_attach: create pm-want-child-notification failed"); 5187c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5197c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5207c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 5247c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = dip; 5257c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * Event Handling: Definition and Binding. 5297c478bd9Sstevel@tonic-gate */ 5307c478bd9Sstevel@tonic-gate if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl, 5317c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5327c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5347c478bd9Sstevel@tonic-gate "_attach: ndi_event_alloc_hdl failed"); 5357c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5367c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events, 5397c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 5407c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5417c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl); 5427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 5437c478bd9Sstevel@tonic-gate "_attach: ndi_event_bind_set failed"); 5447c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5457c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate for (i = 0; i < N_IBNEX_PROPS; i++) { 5497c478bd9Sstevel@tonic-gate if (ibnex_comm_svc_init(ibnex_properties[i].name, 5507c478bd9Sstevel@tonic-gate ibnex_properties[i].type) != IBNEX_SUCCESS) { 5517c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 5527c478bd9Sstevel@tonic-gate (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl, 5537c478bd9Sstevel@tonic-gate &ib_ndi_events, NDI_SLEEP); 5547c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 5557c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl( 5567c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl); 5577c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 5587c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init" 5597c478bd9Sstevel@tonic-gate " failed %s", ibnex_properties[i].name); 5607c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 5617c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* 5667c478bd9Sstevel@tonic-gate * before anything else comes up: 5677c478bd9Sstevel@tonic-gate * Initialize the internal list of pseudo device nodes by 5687c478bd9Sstevel@tonic-gate * getting all pseudo children of "ib" and processing them. 5697c478bd9Sstevel@tonic-gate */ 5707c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate /* 5777c478bd9Sstevel@tonic-gate * ibnex_getinfo() 5787c478bd9Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 5797c478bd9Sstevel@tonic-gate * instance number. 5807c478bd9Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 5817c478bd9Sstevel@tonic-gate */ 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5847c478bd9Sstevel@tonic-gate static int 5857c478bd9Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 5867c478bd9Sstevel@tonic-gate { 5877c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin"); 5907c478bd9Sstevel@tonic-gate switch (cmd) { 5917c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 5927c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) 5937c478bd9Sstevel@tonic-gate *result = ibnex.ibnex_dip; 5947c478bd9Sstevel@tonic-gate else { 5957c478bd9Sstevel@tonic-gate *result = NULL; 5967c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate break; 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 6017c478bd9Sstevel@tonic-gate *result = 0; 6027c478bd9Sstevel@tonic-gate break; 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate default: 6057c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate return (ret); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate * ibnex_detach 6137c478bd9Sstevel@tonic-gate * Unregister callback with the IBDM 6147c478bd9Sstevel@tonic-gate * Unregister callback with the IBTL 6157c478bd9Sstevel@tonic-gate * Uninitialize the communication entries 6167c478bd9Sstevel@tonic-gate * Remove all the minor nodes created by this instance 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate static int 6197c478bd9Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 6207c478bd9Sstevel@tonic-gate { 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd); 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate switch (cmd) { 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate case DDI_DETACH: 6277c478bd9Sstevel@tonic-gate break; 6287c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 6297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend"); 6307c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6317c478bd9Sstevel@tonic-gate default: 6327c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 6367c478bd9Sstevel@tonic-gate if (ibt_hw_is_present()) { 6377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6387c478bd9Sstevel@tonic-gate "\tdetach: IB HW is present "); 6397c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6407c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) { 6437c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 6447c478bd9Sstevel@tonic-gate "\tdetach: ndi_event_free_hdl() failed"); 6457c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6467c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL; 6497c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = NULL; 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(); 6527c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini(); 6537c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup(); 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL); 6567c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = NULL; 6577c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 6587c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 6597c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * ibnex_pseudo_node_cleanup() 6657c478bd9Sstevel@tonic-gate * This checks if all the "dips" have been deallocated (implying 6667c478bd9Sstevel@tonic-gate * that all the children have been unconfigured) first. 6677c478bd9Sstevel@tonic-gate * If not, it just returns. 6687c478bd9Sstevel@tonic-gate * If yes, then it frees up memory allocated for devi_name, 6697c478bd9Sstevel@tonic-gate * node_addr, and property list. 6707c478bd9Sstevel@tonic-gate */ 6717c478bd9Sstevel@tonic-gate static void 6727c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void) 6737c478bd9Sstevel@tonic-gate { 6747c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head; 6757c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:"); 6787c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate for (; nodep; nodep = nodep->node_next) 6817c478bd9Sstevel@tonic-gate if (nodep->node_dip) 6827c478bd9Sstevel@tonic-gate return; 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory"); 6857c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 6867c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node; 6897c478bd9Sstevel@tonic-gate if (pseudo->pseudo_node_addr) { 6907c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_node_addr, 6917c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_node_addr) + 1); 6927c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr = NULL; 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate if (pseudo->pseudo_devi_name) { 6967c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_devi_name, 6977c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_devi_name) + 1); 6987c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name = NULL; 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate if (pseudo->pseudo_unit_addr) { 7027c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_unit_addr, 7037c478bd9Sstevel@tonic-gate pseudo->pseudo_unit_addr_len); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate /* 7107c478bd9Sstevel@tonic-gate * This functions wakes up any reprobe requests waiting for completion 7117c478bd9Sstevel@tonic-gate * of reprobe of this IOC. It also send an NDI event, if : 7127c478bd9Sstevel@tonic-gate * 7137c478bd9Sstevel@tonic-gate * notify_flag is set. This is set if : 7147c478bd9Sstevel@tonic-gate * ibt_reprobe_ioc has returned with SUCCESS 7157c478bd9Sstevel@tonic-gate * IBTF client has not been notified for this node. 7167c478bd9Sstevel@tonic-gate * node_data->node_dip != NULL 7177c478bd9Sstevel@tonic-gate * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set 7187c478bd9Sstevel@tonic-gate * An NDI event cookie has been registered. 7197c478bd9Sstevel@tonic-gate */ 7207c478bd9Sstevel@tonic-gate static void 7217c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag) 7227c478bd9Sstevel@tonic-gate { 7237c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7267c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) || 7297c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state != 0)) { 7307c478bd9Sstevel@tonic-gate if (notify_flag && (node_data->node_dip != NULL) && 7317c478bd9Sstevel@tonic-gate (node_data->node_state & 7327c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) && 7337c478bd9Sstevel@tonic-gate (evt_cookie != NULL)) { 7347c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate bzero(&evt_data, sizeof (evt_data)); 7397c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, 7407c478bd9Sstevel@tonic-gate node_data->node_dip, 7417c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 7427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 7437c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7497c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0; 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate /* 7557c478bd9Sstevel@tonic-gate * This function wakes up any reprobe request waiting for completion 7567c478bd9Sstevel@tonic-gate * of reprobe of all IOCs. 7577c478bd9Sstevel@tonic-gate */ 7587c478bd9Sstevel@tonic-gate static void 7597c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all() 7607c478bd9Sstevel@tonic-gate { 7617c478bd9Sstevel@tonic-gate ibnex_node_data_t *ioc_node; 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate /* Notify if another reprobe_all is pending */ 7667c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) { 7677c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7687c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv); 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0; 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate /* 7737c478bd9Sstevel@tonic-gate * The IOC may be hot-removed after the reprobe request. 7747c478bd9Sstevel@tonic-gate * Reset the reprobe states for such IOCs. 7757c478bd9Sstevel@tonic-gate */ 7767c478bd9Sstevel@tonic-gate for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node; 7777c478bd9Sstevel@tonic-gate ioc_node = ioc_node->node_next) { 7787c478bd9Sstevel@tonic-gate if (ioc_node->node_reprobe_state != 0) { 7797c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ioc_node, 1); 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * ibnex_ibnex_callback: 7867c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_INIT: 7877c478bd9Sstevel@tonic-gate * Called from ibc_init() which is called from 7887c478bd9Sstevel@tonic-gate * HCA driver _init entry point 7897c478bd9Sstevel@tonic-gate * Initializes the HCA dev_ops structure with default 7907c478bd9Sstevel@tonic-gate * IB nexus structure. 7917c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_FINI: 7927c478bd9Sstevel@tonic-gate * Called from ibc_fini() which is called from 7937c478bd9Sstevel@tonic-gate * HCA driver _fini entry point 7947c478bd9Sstevel@tonic-gate * Un-Initializes the HCA dev_ops structure with default 7957c478bd9Sstevel@tonic-gate * IB nexus strucuture. 7967c478bd9Sstevel@tonic-gate * Returns IBT_SUCCESS 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate ibt_status_t 7997c478bd9Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args) 8007c478bd9Sstevel@tonic-gate { 8017c478bd9Sstevel@tonic-gate int retval = IBT_SUCCESS; 8027c478bd9Sstevel@tonic-gate struct dev_ops *hca_dev_ops; 8037c478bd9Sstevel@tonic-gate dev_info_t *clnt_dip; 8047c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tibtl_callback"); 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate switch (cb_args->cb_flag) { 8097c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_INIT: 8107c478bd9Sstevel@tonic-gate /* 8117c478bd9Sstevel@tonic-gate * Get the devops structure of the HCA, 8127c478bd9Sstevel@tonic-gate * and put IB nexus default busops vector in its place. 8137c478bd9Sstevel@tonic-gate */ 8147c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8157c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8167c478bd9Sstevel@tonic-gate ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL)); 8177c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = &ibnex_ci_busops; 8187c478bd9Sstevel@tonic-gate break; 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_FINI: 8217c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *) 8227c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops; 8237c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = NULL; 8247c478bd9Sstevel@tonic-gate break; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate case IBTL_IBNEX_REPROBE_DEV_REQ: 8277c478bd9Sstevel@tonic-gate /* IBTL pass down request for ibt_reprobe_dev */ 8287c478bd9Sstevel@tonic-gate clnt_dip = cb_args->cb_dip; 8297c478bd9Sstevel@tonic-gate ASSERT(clnt_dip); 8307c478bd9Sstevel@tonic-gate 8317c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(clnt_dip); 8327c478bd9Sstevel@tonic-gate ASSERT(node_data); 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate /* Reprobe for IOC nodes only */ 8357c478bd9Sstevel@tonic-gate ASSERT(node_data->node_type == IBNEX_IOC_NODE); 8367c478bd9Sstevel@tonic-gate 8377c478bd9Sstevel@tonic-gate /* 8387c478bd9Sstevel@tonic-gate * Start the reprobe. This could sleep as it is not 8397c478bd9Sstevel@tonic-gate * from interrupt context. 8407c478bd9Sstevel@tonic-gate */ 8417c478bd9Sstevel@tonic-gate if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev, 8427c478bd9Sstevel@tonic-gate clnt_dip, TQ_SLEEP) == 0) { 8437c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 8447c478bd9Sstevel@tonic-gate "ibnex_ibtl_callback: taskq_dispatch failed"); 8457c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 8467c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 8477c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 8487c478bd9Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate return (IBT_SUCCESS); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate return (retval); 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate /* 8587c478bd9Sstevel@tonic-gate * Bus-ops entry points 8597c478bd9Sstevel@tonic-gate */ 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate /* 8627c478bd9Sstevel@tonic-gate * ibnex_map_fault 8637c478bd9Sstevel@tonic-gate * IOC drivers need not map memory. Return failure to fail any 8647c478bd9Sstevel@tonic-gate * such calls. 8657c478bd9Sstevel@tonic-gate */ 8667c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8677c478bd9Sstevel@tonic-gate static int 8687c478bd9Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat, 8697c478bd9Sstevel@tonic-gate struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn, 8707c478bd9Sstevel@tonic-gate uint_t prot, uint_t lock) 8717c478bd9Sstevel@tonic-gate { 8727c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * ibnex_busctl 8787c478bd9Sstevel@tonic-gate * bus_ctl bus_ops entry point 8797c478bd9Sstevel@tonic-gate */ 8807c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8817c478bd9Sstevel@tonic-gate static int 8827c478bd9Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip, 8837c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 8847c478bd9Sstevel@tonic-gate { 8857c478bd9Sstevel@tonic-gate dev_info_t *child_dip; 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 8887c478bd9Sstevel@tonic-gate "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop); 8897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result); 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate switch (ctlop) { 8927c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 8937c478bd9Sstevel@tonic-gate if (rdip == NULL) { 8947c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate /* Log the relevant details of dip to sysbuf */ 8987c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n", 8997c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 9007c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 9057c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9067c478bd9Sstevel@tonic-gate return (ibnex_init_child(child_dip)); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 9097c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg; 9107c478bd9Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL); 9117c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 9147c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 9157c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POWER : 9167c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 9197c478bd9Sstevel@tonic-gate /* 9207c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and 9217c478bd9Sstevel@tonic-gate * DDI_FAILURE for the nodes enumerated by a Pseudo file. 9227c478bd9Sstevel@tonic-gate */ 9237c478bd9Sstevel@tonic-gate return (ndi_dev_is_persistent_node(rdip) ? 9247c478bd9Sstevel@tonic-gate DDI_SUCCESS : DDI_FAILURE); 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 9287c478bd9Sstevel@tonic-gate /* 9297c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS, so that consistent buf alloc 9307c478bd9Sstevel@tonic-gate * gets the default DMA IO minimum for the platform 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate /* 9357c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be 9367c478bd9Sstevel@tonic-gate * called by IB Nexus driver. 9377c478bd9Sstevel@tonic-gate */ 9387c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 9397c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 9407c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 9417c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 9427c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 9437c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 9447c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: 9457c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 9467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 9477c478bd9Sstevel@tonic-gate "%s%d: invalid op (%d) from %s inst%d", 9487c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 9497c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 9507c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate /* 9537c478bd9Sstevel@tonic-gate * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we 9547c478bd9Sstevel@tonic-gate * pass up 9557c478bd9Sstevel@tonic-gate */ 9567c478bd9Sstevel@tonic-gate default: 9577c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* 9637c478bd9Sstevel@tonic-gate * ibnex_init_child() 9647c478bd9Sstevel@tonic-gate * 9657c478bd9Sstevel@tonic-gate * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD 9667c478bd9Sstevel@tonic-gate * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED. 9677c478bd9Sstevel@tonic-gate */ 9687c478bd9Sstevel@tonic-gate static int 9697c478bd9Sstevel@tonic-gate ibnex_init_child(dev_info_t *child) 9707c478bd9Sstevel@tonic-gate { 9717c478bd9Sstevel@tonic-gate int ret; 9727c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child); 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate /* Handle Pseudo nodes of client children */ 9777c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 9789d3d2ed0Shiremath /* Skip nodes without ib-node-type="merge" */ 9799d3d2ed0Shiremath if (ibnex_is_merge_node(child) != IBNEX_SUCCESS) 9809d3d2ed0Shiremath return (DDI_FAILURE); 9819d3d2ed0Shiremath 9827c478bd9Sstevel@tonic-gate if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS) 9837c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 9867c478bd9Sstevel@tonic-gate /* 9877c478bd9Sstevel@tonic-gate * Merge the .conf node 9887c478bd9Sstevel@tonic-gate */ 9897c478bd9Sstevel@tonic-gate if (ndi_merge_node(child, 9907c478bd9Sstevel@tonic-gate ibnex_name_child) == DDI_SUCCESS) { 9917c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 9927c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS) 9997c478bd9Sstevel@tonic-gate return (ret); 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate 10077c478bd9Sstevel@tonic-gate int 10087c478bd9Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name) 10097c478bd9Sstevel@tonic-gate { 10107c478bd9Sstevel@tonic-gate char **unit_addr; 10117c478bd9Sstevel@tonic-gate uint_t n; 10127c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 10137c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 10147c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 10159d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 10169d3d2ed0Shiremath "\tname_pseudo_child: cannot find unit-address in %s.conf", 10177c478bd9Sstevel@tonic-gate ddi_get_name(child)); 10187c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10197c478bd9Sstevel@tonic-gate } 10207c478bd9Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 10217c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 10227c478bd9Sstevel@tonic-gate " not well-formed", ddi_get_name(child)); 10237c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10247c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr); 10277c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 10287c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate 10327c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10337c478bd9Sstevel@tonic-gate int 10347c478bd9Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag) 10357c478bd9Sstevel@tonic-gate { 10367c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 10377c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_datap; 10387c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 10397c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate node_datap = ddi_get_parent_data(child); 10427c478bd9Sstevel@tonic-gate if (node_datap == NULL) { 10437c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL"); 10447c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p" 10477c478bd9Sstevel@tonic-gate "Node type %x", node_datap, node_datap->node_type); 10487c478bd9Sstevel@tonic-gate switch (node_datap->node_type) { 10497c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE: 10507c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10517c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10527c478bd9Sstevel@tonic-gate port_node->port_num, 10537c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]); 10547c478bd9Sstevel@tonic-gate break; 10557c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE: 10567c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10577c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s", 10587c478bd9Sstevel@tonic-gate port_node->port_num, port_node->port_pkey, ibnex. 10597c478bd9Sstevel@tonic-gate ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]); 10607c478bd9Sstevel@tonic-gate break; 10617c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE: 10627c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node; 10637c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s", 10647c478bd9Sstevel@tonic-gate port_node->port_num, 10657c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[port_node-> 10667c478bd9Sstevel@tonic-gate port_commsvc_idx]); 10677c478bd9Sstevel@tonic-gate break; 10687c478bd9Sstevel@tonic-gate case IBNEX_IOC_NODE: 10697c478bd9Sstevel@tonic-gate ioc = &node_datap->node_data.ioc_node; 10707c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX", 10717c478bd9Sstevel@tonic-gate (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid); 10727c478bd9Sstevel@tonic-gate break; 10737c478bd9Sstevel@tonic-gate case IBNEX_PSEUDO_NODE: 10747c478bd9Sstevel@tonic-gate pseudo = &node_datap->node_data.pseudo_node; 10757c478bd9Sstevel@tonic-gate (void) snprintf(name, 10767c478bd9Sstevel@tonic-gate IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr); 10777c478bd9Sstevel@tonic-gate break; 10787c478bd9Sstevel@tonic-gate default: 10797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed"); 10807c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 10817c478bd9Sstevel@tonic-gate } 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate 10877c478bd9Sstevel@tonic-gate /* 10887c478bd9Sstevel@tonic-gate * ibnex_bus_config() 10897c478bd9Sstevel@tonic-gate * 10907c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE: 10917c478bd9Sstevel@tonic-gate * Enumerate the exact instance of the driver. Use the device node name 10927c478bd9Sstevel@tonic-gate * to locate the exact instance. 10937c478bd9Sstevel@tonic-gate * Query IBDM to find whether the hardware exits for the instance of the 10947c478bd9Sstevel@tonic-gate * driver. If exists, create a device node and return NDI_SUCCESS. 10957c478bd9Sstevel@tonic-gate * 10967c478bd9Sstevel@tonic-gate * BUS_CONFIG_ALL: 10977c478bd9Sstevel@tonic-gate * Enumerate all the instances of all the possible children (seen before 10987c478bd9Sstevel@tonic-gate * and never seen before). 10997c478bd9Sstevel@tonic-gate * 11007c478bd9Sstevel@tonic-gate * BUS_CONFIG_DRIVER: 11017c478bd9Sstevel@tonic-gate * Enumerate all the instances of a particular driver. 11027c478bd9Sstevel@tonic-gate */ 11037c478bd9Sstevel@tonic-gate static int 11047c478bd9Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag, 11057c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *devname, dev_info_t **child) 11067c478bd9Sstevel@tonic-gate { 11079d3d2ed0Shiremath int ret = IBNEX_SUCCESS, len, circ, need_bus_config; 11087c478bd9Sstevel@tonic-gate char *device_name, *cname = NULL, *caddr = NULL; 11099d3d2ed0Shiremath char *device_name1; 11107c478bd9Sstevel@tonic-gate char *srvname, nameaddr[MAXNAMELEN]; 11117c478bd9Sstevel@tonic-gate dev_info_t *cdip, *pdip = NULL; 11127c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 11137c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node; 11145e3986cbScth int use_mdi_devi_locking = 0; 11157c478bd9Sstevel@tonic-gate 11165e3986cbScth 11175e3986cbScth /* Set use_mdi_devi_locking appropriately */ 11185e3986cbScth if ((mdi_component_is_phci(parent, NULL) == MDI_SUCCESS) && 11195e3986cbScth ((op != BUS_CONFIG_ONE) || (op == BUS_CONFIG_ONE && 11205e3986cbScth strncmp((char *)devname, IBNEX_IBPORT_CNAME, 6) != 0))) { 11215e3986cbScth IBTF_DPRINTF_L4("ibnex", "\tbus_config: using mdi_devi_enter"); 11225e3986cbScth use_mdi_devi_locking = 1; 11235e3986cbScth } 11245e3986cbScth 11255e3986cbScth if (use_mdi_devi_locking) 11265e3986cbScth mdi_devi_enter(parent, &circ); 11275e3986cbScth else 11287c478bd9Sstevel@tonic-gate ndi_devi_enter(parent, &circ); 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate switch (op) { 11317c478bd9Sstevel@tonic-gate case BUS_CONFIG_ONE: 113205fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, " 113305fa0d51Spramodbg "parent %p", parent); 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate len = strlen((char *)devname) + 1; 11367c478bd9Sstevel@tonic-gate device_name = i_ddi_strdup(devname, KM_SLEEP); 11377c478bd9Sstevel@tonic-gate i_ddi_parse_name(device_name, &cname, &caddr, NULL); 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate if (caddr == NULL || (strlen(caddr) == 0)) { 11407c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 11415e3986cbScth if (use_mdi_devi_locking) 11425e3986cbScth mdi_devi_exit(parent, circ); 11435e3986cbScth else 11447c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 11457c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 11467c478bd9Sstevel@tonic-gate } 11477c478bd9Sstevel@tonic-gate 11489d3d2ed0Shiremath /* 11499d3d2ed0Shiremath * i_ddi_parse_name() strips of the address portion 11509d3d2ed0Shiremath * of the device name. Recreate device name for 11519d3d2ed0Shiremath * ndi_devi_findchild 11529d3d2ed0Shiremath */ 11539d3d2ed0Shiremath device_name1 = i_ddi_strdup(devname, KM_SLEEP); 11549d3d2ed0Shiremath 11557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 11567c478bd9Sstevel@tonic-gate "\tbus_config: cname %s addr %s", cname, caddr); 11577c478bd9Sstevel@tonic-gate 11589d3d2ed0Shiremath cdip = ndi_devi_findchild(parent, device_name1); 11599d3d2ed0Shiremath kmem_free(device_name1, len); 11607c478bd9Sstevel@tonic-gate if (cdip == NULL) { 11617c478bd9Sstevel@tonic-gate /* Node is not present */ 11627c478bd9Sstevel@tonic-gate if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) { 11635e3986cbScth if (use_mdi_devi_locking) 11645e3986cbScth mdi_devi_exit(parent, circ); 11655e3986cbScth else 11669d3d2ed0Shiremath ndi_devi_exit(parent, circ); 11675e3986cbScth 11689d3d2ed0Shiremath ret = ibnex_ioc_bus_config_one(&parent, flag, 11699d3d2ed0Shiremath op, devname, child, &need_bus_config); 117005fa0d51Spramodbg if (!need_bus_config) { 117105fa0d51Spramodbg kmem_free(device_name, len); 11729d3d2ed0Shiremath return (ret); 117305fa0d51Spramodbg } 11749d3d2ed0Shiremath 11755e3986cbScth if (use_mdi_devi_locking) 11765e3986cbScth mdi_devi_enter(parent, &circ); 11775e3986cbScth else 11789d3d2ed0Shiremath ndi_devi_enter(parent, &circ); 11797c478bd9Sstevel@tonic-gate } else if ((strncmp(cname, 11807c478bd9Sstevel@tonic-gate IBNEX_IBPORT_CNAME, 6) == 0) && 11817c478bd9Sstevel@tonic-gate (parent != ibnex.ibnex_dip)) { /* parent is HCA */ 11827c478bd9Sstevel@tonic-gate cdip = ibnex_config_port_node(parent, devname); 11837c478bd9Sstevel@tonic-gate if (cdip) 11847c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 11857c478bd9Sstevel@tonic-gate else 11867c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 11879d3d2ed0Shiremath } else { 11887c478bd9Sstevel@tonic-gate /* 11897c478bd9Sstevel@tonic-gate * if not IOC or PORT device then always 11907c478bd9Sstevel@tonic-gate * assume a Pseudo child 11919d3d2ed0Shiremath * 11929d3d2ed0Shiremath * if IB Nexus is the parent, call MDI. 11939d3d2ed0Shiremath * else if HCA is the parent, enumerate 11949d3d2ed0Shiremath * the Pseudo node. 11957c478bd9Sstevel@tonic-gate */ 11967c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 11977c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 11989d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 11995e3986cbScth if (use_mdi_devi_locking) 12005e3986cbScth mdi_devi_exit(parent, circ); 12015e3986cbScth else 12029d3d2ed0Shiremath ndi_devi_exit(parent, circ); 12035e3986cbScth 12047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 12059d3d2ed0Shiremath ret = ibnex_pseudo_mdi_config_one( 12069d3d2ed0Shiremath flag, devname, child, cname, 12079d3d2ed0Shiremath caddr); 12087c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 120905fa0d51Spramodbg kmem_free(device_name, len); 12109d3d2ed0Shiremath return (ret); 12119d3d2ed0Shiremath } 12129d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 121305fa0d51Spramodbg ret = ibnex_pseudo_config_one(NULL, 12149d3d2ed0Shiremath caddr, parent); 12159d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 12169d3d2ed0Shiremath } 12177c478bd9Sstevel@tonic-gate } 1218a1e3386eShiremath 1219a1e3386eShiremath if (strncmp(cname, IBNEX_IBPORT_CNAME, 6) == 0) { 1220a1e3386eShiremath /* Allows enumeration under PHCI */ 1221a1e3386eShiremath flag |= NDI_MDI_FALLBACK; 1222a1e3386eShiremath } 12237c478bd9Sstevel@tonic-gate kmem_free(device_name, len); 12247c478bd9Sstevel@tonic-gate break; 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate case BUS_CONFIG_OBP_ARGS: 12277c478bd9Sstevel@tonic-gate cdip = ibnex_config_obp_args(parent, devname); 12287c478bd9Sstevel@tonic-gate if (cdip) { 12297c478bd9Sstevel@tonic-gate /* 12307c478bd9Sstevel@tonic-gate * Boot case. 12317c478bd9Sstevel@tonic-gate * Special handling because the "devname" 12327c478bd9Sstevel@tonic-gate * format for the enumerated device is 12337c478bd9Sstevel@tonic-gate * different. 12347c478bd9Sstevel@tonic-gate */ 12357c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 12367c478bd9Sstevel@tonic-gate port_node = &node_data->node_data.port_node; 12377c478bd9Sstevel@tonic-gate if (node_data->node_type == 12387c478bd9Sstevel@tonic-gate IBNEX_VPPA_COMMSVC_NODE) { 12397c478bd9Sstevel@tonic-gate srvname = 12407c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[ 12417c478bd9Sstevel@tonic-gate port_node->port_commsvc_idx]; 12427c478bd9Sstevel@tonic-gate (void) snprintf(nameaddr, MAXNAMELEN, 12437c478bd9Sstevel@tonic-gate "ibport@%x,%x,%s", 12447c478bd9Sstevel@tonic-gate port_node->port_num, 12457c478bd9Sstevel@tonic-gate port_node->port_pkey, srvname); 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate devname = (void *)nameaddr; 12487c478bd9Sstevel@tonic-gate } else { 12497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 12507c478bd9Sstevel@tonic-gate "\tbus_config: CONFIG_OBP_ARGS : invalid state!!"); 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12537c478bd9Sstevel@tonic-gate } 12547c478bd9Sstevel@tonic-gate break; 12557c478bd9Sstevel@tonic-gate case BUS_CONFIG_ALL: 12569d3d2ed0Shiremath /*FALLTHRU*/ 12577c478bd9Sstevel@tonic-gate case BUS_CONFIG_DRIVER: 12589d3d2ed0Shiremath if (op == BUS_CONFIG_ALL) 125905fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, " 126005fa0d51Spramodbg "parent %p", parent); 12619d3d2ed0Shiremath else 126205fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER" 126305fa0d51Spramodbg ", parent %p", parent); 12647c478bd9Sstevel@tonic-gate 12659d3d2ed0Shiremath /* 12665e3986cbScth * No locks to be held while calling mdi_vhci_bus_config() 12675e3986cbScth * ibnex_config_all_children() holds appropriate locks. 12685e3986cbScth */ 12695e3986cbScth if (use_mdi_devi_locking) 12705e3986cbScth mdi_devi_exit(parent, circ); 12715e3986cbScth else 12725e3986cbScth ndi_devi_exit(parent, circ); 12735e3986cbScth 12745e3986cbScth /* 12759d3d2ed0Shiremath * Drive CONFIG requests for IB Nexus parent through 12769d3d2ed0Shiremath * MDI. This is needed to load the HCA drivers in x86 SRP 12779d3d2ed0Shiremath * boot case. 12789d3d2ed0Shiremath * 12799d3d2ed0Shiremath * CONFIG Requests with HCA parent will probe devices using 12809d3d2ed0Shiremath * ibdm and configure all children. 12819d3d2ed0Shiremath */ 12829d3d2ed0Shiremath if (parent == ibnex.ibnex_dip) { 12839d3d2ed0Shiremath ret = mdi_vhci_bus_config(parent, 12849d3d2ed0Shiremath flag, op, devname, child, NULL); 12859d3d2ed0Shiremath return (ret); 12869d3d2ed0Shiremath } else { 12879d3d2ed0Shiremath ibnex_config_all_children(parent); 12885e3986cbScth 12895e3986cbScth if (use_mdi_devi_locking) 12905e3986cbScth mdi_devi_enter(parent, &circ); 12915e3986cbScth else 12925e3986cbScth ndi_devi_enter(parent, &circ); 12939d3d2ed0Shiremath } 12949d3d2ed0Shiremath break; 12957c478bd9Sstevel@tonic-gate default: 12967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config: error"); 12977c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 12987c478bd9Sstevel@tonic-gate break; 12997c478bd9Sstevel@tonic-gate } 13005e3986cbScth 13015e3986cbScth if (use_mdi_devi_locking) 13025e3986cbScth mdi_devi_exit(parent, circ); 13035e3986cbScth else 13047c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ); 13055e3986cbScth 13067c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 13077c478bd9Sstevel@tonic-gate if (op == BUS_CONFIG_OBP_ARGS) 13087c478bd9Sstevel@tonic-gate op = BUS_CONFIG_ONE; 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate if (pdip == NULL) 13117c478bd9Sstevel@tonic-gate pdip = parent; 13127c478bd9Sstevel@tonic-gate 13137c478bd9Sstevel@tonic-gate ret = ndi_busop_bus_config( 13147c478bd9Sstevel@tonic-gate pdip, flag, op, devname, child, 0); 13157c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config:" 13167c478bd9Sstevel@tonic-gate "ndi_busop_bus_config : retval %d", ret); 13177c478bd9Sstevel@tonic-gate return (ret); 13187c478bd9Sstevel@tonic-gate } 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tbus_config: Failure End"); 13217c478bd9Sstevel@tonic-gate return (NDI_FAILURE); 13227c478bd9Sstevel@tonic-gate } 13237c478bd9Sstevel@tonic-gate 13247c478bd9Sstevel@tonic-gate 13257c478bd9Sstevel@tonic-gate /* 13267c478bd9Sstevel@tonic-gate * ibnex_config_root_iocnode() 13277c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 13287c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 13297c478bd9Sstevel@tonic-gate */ 13307c478bd9Sstevel@tonic-gate static int 13317c478bd9Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name) 13327c478bd9Sstevel@tonic-gate { 13337c478bd9Sstevel@tonic-gate int ret, port = 0, iter = 0; 13347c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 13357c478bd9Sstevel@tonic-gate char *portstr; 13367c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, iou_guid, ioc_guid; 13377c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 13387c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 13397c478bd9Sstevel@tonic-gate 13407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 13417c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: name %s", device_name); 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate portstr = strstr(device_name, ":port="); 13447c478bd9Sstevel@tonic-gate if (portstr == NULL) { 13457c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate portstr[0] = 0; portstr++; 13497c478bd9Sstevel@tonic-gate if (ibnex_devname2port(portstr, &port)) { 13507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port"); 13517c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 13559d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 13567c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13577c478bd9Sstevel@tonic-gate } 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4), 13607c478bd9Sstevel@tonic-gate "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid); 13617c478bd9Sstevel@tonic-gate 13627c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 13637c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) { 13647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 13657c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: Port does not exist"); 13667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13677c478bd9Sstevel@tonic-gate } 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 13707c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 13717c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 13727c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 13737c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 13747c478bd9Sstevel@tonic-gate hca_guid, port)) == NULL) { 13757c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13767c478bd9Sstevel@tonic-gate } 13777c478bd9Sstevel@tonic-gate 13787c478bd9Sstevel@tonic-gate if (iter++ == 400) { 13797c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 13807c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 13817c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 13827c478bd9Sstevel@tonic-gate displayed = B_TRUE; 13837c478bd9Sstevel@tonic-gate } 13847c478bd9Sstevel@tonic-gate } 13857c478bd9Sstevel@tonic-gate } 13867c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 13877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:" 13887c478bd9Sstevel@tonic-gate "Port is initialized"); 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) { 13917c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 13927c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 13937c478bd9Sstevel@tonic-gate } 13947c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 13957c478bd9Sstevel@tonic-gate if (ibnex_is_ioc_present(ioc_guid) == IBNEX_SUCCESS) { 13967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: IOC present"); 13977c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 13987c478bd9Sstevel@tonic-gate } else 13999d3d2ed0Shiremath ret = ibnex_ioc_initnode(ioc_info, IBNEX_DEVFS_ENUMERATE, 14009d3d2ed0Shiremath parent); 14017c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 14027c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 14037c478bd9Sstevel@tonic-gate return (ret); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate 14067c478bd9Sstevel@tonic-gate 14077c478bd9Sstevel@tonic-gate static int 14087c478bd9Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port) 14097c478bd9Sstevel@tonic-gate { 14107c478bd9Sstevel@tonic-gate char *temp; 14117c478bd9Sstevel@tonic-gate int ret = IBNEX_FAILURE; 14127c478bd9Sstevel@tonic-gate 14137c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin"); 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate temp = strchr(portstr, '='); 14167c478bd9Sstevel@tonic-gate if (temp != NULL) { 14177c478bd9Sstevel@tonic-gate temp++; 14187c478bd9Sstevel@tonic-gate *port = ibnex_str2int(temp, strlen(temp), &ret); 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate return (ret); 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate 14247c478bd9Sstevel@tonic-gate /* 14257c478bd9Sstevel@tonic-gate * ibnex_config_all_children() 14267c478bd9Sstevel@tonic-gate * Wait for lata SM initialization case before enumerating the nodes 14277c478bd9Sstevel@tonic-gate * Get list of HCA's and HCA port information 14287c478bd9Sstevel@tonic-gate * Create device device nodes and its node properties 14297c478bd9Sstevel@tonic-gate * for port nodes and VPPA nodes 14307c478bd9Sstevel@tonic-gate * Get list of all the IOC node information 14317c478bd9Sstevel@tonic-gate * Create device nodes and its properties for all the IOCs 14327c478bd9Sstevel@tonic-gate * if not created already 14337c478bd9Sstevel@tonic-gate * Bind drivers for all the newly created device nodes 14347c478bd9Sstevel@tonic-gate * Support Pseudo nodes enumerated using their .conf file 14357c478bd9Sstevel@tonic-gate */ 14367c478bd9Sstevel@tonic-gate static void 14377c478bd9Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent) 14387c478bd9Sstevel@tonic-gate { 14397c478bd9Sstevel@tonic-gate int ii; 14407c478bd9Sstevel@tonic-gate time_t wait_time; 14417c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc; 14427c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 14437c478bd9Sstevel@tonic-gate ib_guid_t hca_guid; 14445e3986cbScth int circ; 14457c478bd9Sstevel@tonic-gate 14467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin"); 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate /* 14499d3d2ed0Shiremath * Enumerate children of this HCA, port nodes, 14505e3986cbScth * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for 14515e3986cbScth * locking. IB Nexus is enumerating the children 14525e3986cbScth * of HCA, not MPXIO clients. 14537c478bd9Sstevel@tonic-gate */ 14545e3986cbScth ndi_devi_enter(parent, &circ); 14557c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 14567c478bd9Sstevel@tonic-gate wait_time = ibdm_ibnex_get_waittime( 14577c478bd9Sstevel@tonic-gate hca_guid, &ibnex_port_settling_time); 14587c478bd9Sstevel@tonic-gate if (wait_time) { 14597c478bd9Sstevel@tonic-gate delay(drv_usectohz(wait_time * 1000000)); 14607c478bd9Sstevel@tonic-gate } 14617c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 1462*f9edfba4Spramodbg if (hca_list == NULL) { 1463*f9edfba4Spramodbg ndi_devi_exit(parent, circ); 14647c478bd9Sstevel@tonic-gate return; 1465*f9edfba4Spramodbg } 14667c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr); 14677c478bd9Sstevel@tonic-gate for (ii = 0; ii < hca_list->hl_nports; ii++) { 14687c478bd9Sstevel@tonic-gate ibnex_create_port_nodes( 14697c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 14707c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes( 14717c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]); 14727c478bd9Sstevel@tonic-gate } 14737c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 14745e3986cbScth ndi_devi_exit(parent, circ); 14755e3986cbScth 14765e3986cbScth /* 14775e3986cbScth * Use mdi_devi_enter() for locking. IB Nexus is 14785e3986cbScth * enumerating MPXIO clients. 14795e3986cbScth */ 14805e3986cbScth mdi_devi_enter(parent, &circ); 14817c478bd9Sstevel@tonic-gate 14827c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes(); 14837c478bd9Sstevel@tonic-gate 14849d3d2ed0Shiremath /* Enumerate all the IOC's */ 14857c478bd9Sstevel@tonic-gate wait_time = ibdm_ibnex_get_waittime( 14867c478bd9Sstevel@tonic-gate 0, &ibnex_port_settling_time); 14877c478bd9Sstevel@tonic-gate if (wait_time) 14887c478bd9Sstevel@tonic-gate delay(drv_usectohz(wait_time * 1000000)); 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate ioc_list = ibdm_ibnex_get_ioc_list(IBDM_IBNEX_NORMAL_PROBE); 14917c478bd9Sstevel@tonic-gate ioc = ioc_list; 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate while (ioc_list) { 14967c478bd9Sstevel@tonic-gate if (ibnex_is_ioc_present( 14977c478bd9Sstevel@tonic-gate ioc_list->ioc_profile.ioc_guid) != IBNEX_SUCCESS) { 14987c478bd9Sstevel@tonic-gate (void) ibnex_ioc_initnode(ioc_list, 14999d3d2ed0Shiremath IBNEX_DEVFS_ENUMERATE, parent); 15007c478bd9Sstevel@tonic-gate } 15017c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 15027c478bd9Sstevel@tonic-gate } 15039d3d2ed0Shiremath 15049d3d2ed0Shiremath /* Config IBTF Pseudo clients */ 15059d3d2ed0Shiremath ibnex_config_pseudo_all(parent); 15069d3d2ed0Shiremath 15077c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15087c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 15095e3986cbScth mdi_devi_exit(parent, circ); 15109d3d2ed0Shiremath 15117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End"); 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate /* 15167c478bd9Sstevel@tonic-gate * ibnex_create_port_nodes: 15177c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15187c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 15197c478bd9Sstevel@tonic-gate */ 15207c478bd9Sstevel@tonic-gate static void 15217c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15227c478bd9Sstevel@tonic-gate { 15237c478bd9Sstevel@tonic-gate int idx; 15247c478bd9Sstevel@tonic-gate dev_info_t *dip; 15257c478bd9Sstevel@tonic-gate int rval; 15267c478bd9Sstevel@tonic-gate 15277c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15287c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) { 15297c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 15307c478bd9Sstevel@tonic-gate idx, 0, &dip); 15317c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 15327c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 15337c478bd9Sstevel@tonic-gate IBNEX_PORT_COMMSVC_NODE, 0, &rval, 15347c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate } 15377c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15387c478bd9Sstevel@tonic-gate } 15397c478bd9Sstevel@tonic-gate 15407c478bd9Sstevel@tonic-gate 15417c478bd9Sstevel@tonic-gate /* 15427c478bd9Sstevel@tonic-gate * ibnex_create_vppa_nodes: 15437c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15447c478bd9Sstevel@tonic-gate * in the "vppa-commsvc-list" property and per each PKEY that 15457c478bd9Sstevel@tonic-gate * this particular port supports and per HCA port 15467c478bd9Sstevel@tonic-gate */ 15477c478bd9Sstevel@tonic-gate static void 15487c478bd9Sstevel@tonic-gate ibnex_create_vppa_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15497c478bd9Sstevel@tonic-gate { 15507c478bd9Sstevel@tonic-gate int idx, ii; 15517c478bd9Sstevel@tonic-gate int rval; 15527c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 15537c478bd9Sstevel@tonic-gate dev_info_t *dip; 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin"); 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15587c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 15597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: " 15607c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 15617c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15627c478bd9Sstevel@tonic-gate return; 15637c478bd9Sstevel@tonic-gate } 15647c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) { 15657c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 15667c478bd9Sstevel@tonic-gate pkey = port_attr->pa_pkey_tbl[ii].pt_pkey; 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate if (IBNEX_INVALID_PKEY(pkey)) { 15697c478bd9Sstevel@tonic-gate continue; 15707c478bd9Sstevel@tonic-gate } 15717c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid( 15727c478bd9Sstevel@tonic-gate port_attr->pa_port_guid, idx, pkey, &dip); 15737c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 15747c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, 15757c478bd9Sstevel@tonic-gate idx, IBNEX_VPPA_COMMSVC_NODE, 15767c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 15777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tcreate_vppa_nodes: " 15787c478bd9Sstevel@tonic-gate "commsvc_initnode failed rval %x", rval); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate } 15827c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 15837c478bd9Sstevel@tonic-gate } 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate /* 15877c478bd9Sstevel@tonic-gate * ibnex_create_hcasvc_nodes: 15887c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined 15897c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port 15907c478bd9Sstevel@tonic-gate */ 15917c478bd9Sstevel@tonic-gate static void 15927c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr) 15937c478bd9Sstevel@tonic-gate { 15947c478bd9Sstevel@tonic-gate int idx; 15957c478bd9Sstevel@tonic-gate dev_info_t *dip; 15967c478bd9Sstevel@tonic-gate int rval; 15977c478bd9Sstevel@tonic-gate 15987c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 15997c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) { 16007c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid, 16017c478bd9Sstevel@tonic-gate idx, 0, &dip); 16027c478bd9Sstevel@tonic-gate if (rval != IBNEX_SUCCESS) { 16037c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx, 16047c478bd9Sstevel@tonic-gate IBNEX_HCASVC_COMMSVC_NODE, 0, &rval, 16057c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 16067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: " 16077c478bd9Sstevel@tonic-gate "commsvc_initnode failed, rval %x", rval); 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 16117c478bd9Sstevel@tonic-gate } 16127c478bd9Sstevel@tonic-gate 16137c478bd9Sstevel@tonic-gate /* 16147c478bd9Sstevel@tonic-gate * ibnex_is_ioc_present() 16157c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS if an entry found in the global linked list 16167c478bd9Sstevel@tonic-gate * Returns IBNEX_FAILURE, if no match found 16177c478bd9Sstevel@tonic-gate */ 16187c478bd9Sstevel@tonic-gate static int 16197c478bd9Sstevel@tonic-gate ibnex_is_ioc_present(ib_guid_t ioc_guid) 16207c478bd9Sstevel@tonic-gate { 16217c478bd9Sstevel@tonic-gate ibnex_node_data_t *head; 16227c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 16237c478bd9Sstevel@tonic-gate int ret = IBNEX_FAILURE; 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tis_ioc_present: Begin"); 16267c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate head = ibnex.ibnex_ioc_node_head; 16297c478bd9Sstevel@tonic-gate while (head) { 16307c478bd9Sstevel@tonic-gate ioc = &head->node_data.ioc_node; 16317c478bd9Sstevel@tonic-gate if (ioc->ioc_guid == ioc_guid) 16327c478bd9Sstevel@tonic-gate break; 16337c478bd9Sstevel@tonic-gate head = head->node_next; 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate if (head) 16367c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate return (ret); 16397c478bd9Sstevel@tonic-gate } 16407c478bd9Sstevel@tonic-gate 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate /* 16437c478bd9Sstevel@tonic-gate * ibnex_bus_unconfig() 16447c478bd9Sstevel@tonic-gate * 16457c478bd9Sstevel@tonic-gate * Unconfigure a particular device node or all instance of a device 16467c478bd9Sstevel@tonic-gate * driver device or all children of IBnex 16477c478bd9Sstevel@tonic-gate */ 16487c478bd9Sstevel@tonic-gate static int 16497c478bd9Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent, 16507c478bd9Sstevel@tonic-gate uint_t flag, ddi_bus_config_op_t op, void *device_name) 16517c478bd9Sstevel@tonic-gate { 16527c478bd9Sstevel@tonic-gate return (ndi_busop_bus_unconfig(parent, flag, op, device_name)); 16537c478bd9Sstevel@tonic-gate } 16547c478bd9Sstevel@tonic-gate 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate /* 16577c478bd9Sstevel@tonic-gate * ibnex_config_port_node() 16587c478bd9Sstevel@tonic-gate * 16597c478bd9Sstevel@tonic-gate * Configures a particular port / HCA node for a particular 16607c478bd9Sstevel@tonic-gate * communication service. 16617c478bd9Sstevel@tonic-gate * The format of the device_name is 16627c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 16637c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 16647c478bd9Sstevel@tonic-gate * Port# = 0 for HCA_SVC communication service nodes 16657c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 16667c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 16677c478bd9Sstevel@tonic-gate */ 16687c478bd9Sstevel@tonic-gate static dev_info_t * 16697c478bd9Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname) 16707c478bd9Sstevel@tonic-gate { 16717c478bd9Sstevel@tonic-gate int ii, index; 16727c478bd9Sstevel@tonic-gate int rval; 16737c478bd9Sstevel@tonic-gate time_t wait_time; 16747c478bd9Sstevel@tonic-gate uint8_t port_num; 16757c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 16767c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 16777c478bd9Sstevel@tonic-gate dev_info_t *cdip; 16787c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 16797c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname); 16827c478bd9Sstevel@tonic-gate 16837c478bd9Sstevel@tonic-gate if (ibnex_get_pkey_commsvc_index_portnum(devname, 16847c478bd9Sstevel@tonic-gate &index, &pkey, &port_num) != IBNEX_SUCCESS) { 16857c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 16867c478bd9Sstevel@tonic-gate "\tconfig_port_node: Invalid Service Name"); 16877c478bd9Sstevel@tonic-gate return (NULL); 16887c478bd9Sstevel@tonic-gate } 16897c478bd9Sstevel@tonic-gate 16907c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 16917c478bd9Sstevel@tonic-gate if (port_num == 0) { 16927c478bd9Sstevel@tonic-gate /* 16937c478bd9Sstevel@tonic-gate * Use the dummy port attribute for HCA node in hca_list 16947c478bd9Sstevel@tonic-gate * Note : pa_state is always IBT_PORT_ACTIVE. 16957c478bd9Sstevel@tonic-gate */ 16967c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid); 16977c478bd9Sstevel@tonic-gate ASSERT(hca_list != NULL); 16987c478bd9Sstevel@tonic-gate port_attr = hca_list->hl_hca_port_attr; 16997c478bd9Sstevel@tonic-gate } else { 17007c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 17017c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 17027c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 17037c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 17047c478bd9Sstevel@tonic-gate return (NULL); 17057c478bd9Sstevel@tonic-gate } 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 17087c478bd9Sstevel@tonic-gate wait_time = ibdm_ibnex_get_waittime( 17097c478bd9Sstevel@tonic-gate hca_guid, &ibnex_port_settling_time); 17107c478bd9Sstevel@tonic-gate if (wait_time) { 17117c478bd9Sstevel@tonic-gate delay(drv_usectohz(wait_time * 1000000)); 17127c478bd9Sstevel@tonic-gate } 17137c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 17147c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 17157c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 17167c478bd9Sstevel@tonic-gate return (NULL); 17177c478bd9Sstevel@tonic-gate } 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate 17217c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 17227c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 17237c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 17247c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 17257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 17267c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 17277c478bd9Sstevel@tonic-gate if (port_num != 0) 17287c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 17297c478bd9Sstevel@tonic-gate else 17307c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 17317c478bd9Sstevel@tonic-gate return (cdip); 17327c478bd9Sstevel@tonic-gate } 17337c478bd9Sstevel@tonic-gate 17347c478bd9Sstevel@tonic-gate if (pkey == 0 && port_num != 0) { 17357c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 17367c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval, 17377c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 17387c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 17397c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 17407c478bd9Sstevel@tonic-gate } else if (pkey == 0 && port_num == 0) { 17417c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, 17427c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval, 17437c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE); 17447c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 17457c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 17467c478bd9Sstevel@tonic-gate } else { 17477c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) { 17487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: " 17497c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num); 17507c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 17517c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 17527c478bd9Sstevel@tonic-gate return (NULL); 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 17557c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 17567c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 17577c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, 17587c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE); 17597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 17607c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 17617c478bd9Sstevel@tonic-gate break; 17627c478bd9Sstevel@tonic-gate } 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate } 17657c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 17667c478bd9Sstevel@tonic-gate if (port_num != 0) 17677c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 17687c478bd9Sstevel@tonic-gate else 17697c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 17707c478bd9Sstevel@tonic-gate return (cdip); 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate 17747c478bd9Sstevel@tonic-gate /* 17757c478bd9Sstevel@tonic-gate * ibnex_config_obp_args() 17767c478bd9Sstevel@tonic-gate * Configures a particular port node for a IP over IB communication 17777c478bd9Sstevel@tonic-gate * service. 17787c478bd9Sstevel@tonic-gate * The format of the input string "devname" is 17797c478bd9Sstevel@tonic-gate * port=x,pkey=y,protocol=ip,<wanboot options> 17807c478bd9Sstevel@tonic-gate * Thr format of the node name created here is 17817c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name> 17827c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes 17837c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created 17847c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node 17857c478bd9Sstevel@tonic-gate * 17867c478bd9Sstevel@tonic-gate */ 17877c478bd9Sstevel@tonic-gate static dev_info_t * 17887c478bd9Sstevel@tonic-gate ibnex_config_obp_args(dev_info_t *parent, char *devname) 17897c478bd9Sstevel@tonic-gate { 17907c478bd9Sstevel@tonic-gate int ii, index; 17917c478bd9Sstevel@tonic-gate int rval, iter = 0; 17927c478bd9Sstevel@tonic-gate char *temp; 17937c478bd9Sstevel@tonic-gate uint8_t port_num; 17947c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid; 17957c478bd9Sstevel@tonic-gate ib_pkey_t pkey; 17967c478bd9Sstevel@tonic-gate dev_info_t *cdip; 17977c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE; 17987c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr; 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_obp_args: %s", devname); 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate /* Is this OBP node for IPoIB ? */ 18037c478bd9Sstevel@tonic-gate temp = devname; 18047c478bd9Sstevel@tonic-gate do { 18057c478bd9Sstevel@tonic-gate temp = strstr(temp, ",protocol=ip"); 18067c478bd9Sstevel@tonic-gate if (temp == NULL) 18077c478bd9Sstevel@tonic-gate break; 18087c478bd9Sstevel@tonic-gate 18097c478bd9Sstevel@tonic-gate if (strlen(devname) > (int)((temp - devname) + 12)) { 18107c478bd9Sstevel@tonic-gate if (temp[12] == ',') 18117c478bd9Sstevel@tonic-gate break; 18127c478bd9Sstevel@tonic-gate } else { 18137c478bd9Sstevel@tonic-gate break; 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate temp++; 18167c478bd9Sstevel@tonic-gate } while (temp); 18177c478bd9Sstevel@tonic-gate 18187c478bd9Sstevel@tonic-gate if (temp == NULL) 18197c478bd9Sstevel@tonic-gate return (NULL); 18207c478bd9Sstevel@tonic-gate if (ibnex_prom_devname_to_pkey_n_portnum( 18217c478bd9Sstevel@tonic-gate devname, &pkey, &port_num) != IBNEX_SUCCESS) { 18227c478bd9Sstevel@tonic-gate return (NULL); 18237c478bd9Sstevel@tonic-gate } 18247c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 18257c478bd9Sstevel@tonic-gate if (strcmp(ibnex.ibnex_vppa_comm_svc_names[index], 18267c478bd9Sstevel@tonic-gate "ipib") == 0) { 18277c478bd9Sstevel@tonic-gate break; 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate 18317c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent); 18327c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 18337c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 18357c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist"); 18367c478bd9Sstevel@tonic-gate return (NULL); 18377c478bd9Sstevel@tonic-gate } 18387c478bd9Sstevel@tonic-gate 18397c478bd9Sstevel@tonic-gate /* Wait until "port is up" */ 18407c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) { 18417c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18427c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000)); 18437c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport( 18447c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) { 18457c478bd9Sstevel@tonic-gate return (NULL); 18467c478bd9Sstevel@tonic-gate } 18477c478bd9Sstevel@tonic-gate if (iter++ == 400) { 18487c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) { 18497c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d " 18507c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num); 18517c478bd9Sstevel@tonic-gate displayed = B_TRUE; 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate } 18547c478bd9Sstevel@tonic-gate } 18557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tPort is initialized"); 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 18587c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid; 18597c478bd9Sstevel@tonic-gate if ((rval = ibnex_get_dip_from_guid(port_guid, index, pkey, 18607c478bd9Sstevel@tonic-gate &cdip)) == IBNEX_SUCCESS) { 18617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists"); 18627c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18637c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18647c478bd9Sstevel@tonic-gate return (cdip); 18657c478bd9Sstevel@tonic-gate } 18667c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) { 18677c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) { 18687c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr, 18697c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE, pkey, &rval, 18707c478bd9Sstevel@tonic-gate IBNEX_CFGADM_ENUMERATE); 18717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", 18727c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval); 18737c478bd9Sstevel@tonic-gate break; 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate } 18767c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr); 18797c478bd9Sstevel@tonic-gate return (cdip); 18807c478bd9Sstevel@tonic-gate } 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate 18837c478bd9Sstevel@tonic-gate /* 18847c478bd9Sstevel@tonic-gate * ibnex_prom_devname_to_pkey_n_portnum() 18857c478bd9Sstevel@tonic-gate * Parses the device node name and extracts "PKEY" and "port#" 18867c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 18877c478bd9Sstevel@tonic-gate */ 18887c478bd9Sstevel@tonic-gate static int 18897c478bd9Sstevel@tonic-gate ibnex_prom_devname_to_pkey_n_portnum( 18907c478bd9Sstevel@tonic-gate char *devname, ib_pkey_t *pkey, uint8_t *port) 18917c478bd9Sstevel@tonic-gate { 18927c478bd9Sstevel@tonic-gate int ret = IBNEX_SUCCESS; 18937c478bd9Sstevel@tonic-gate char *tmp, *tmp1; 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate if ((tmp = strstr(devname, "port=")) != NULL) { 18967c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 18977c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 18987c478bd9Sstevel@tonic-gate *port = ibnex_str2int(tmp, (tmp1 - tmp), &ret); 18997c478bd9Sstevel@tonic-gate } else 19007c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 19017c478bd9Sstevel@tonic-gate 19027c478bd9Sstevel@tonic-gate if ((ret == IBNEX_SUCCESS) && 19037c478bd9Sstevel@tonic-gate (tmp = strstr(devname, "pkey=")) != NULL) { 19047c478bd9Sstevel@tonic-gate if ((tmp = strchr(++tmp, '=')) != NULL) 19057c478bd9Sstevel@tonic-gate if ((tmp1 = strchr(++tmp, ',')) != NULL) 19067c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(tmp, (tmp1 - tmp), &ret); 19077c478bd9Sstevel@tonic-gate } else 19087c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE; 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate return (ret); 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate 19137c478bd9Sstevel@tonic-gate 19147c478bd9Sstevel@tonic-gate /* 19157c478bd9Sstevel@tonic-gate * ibnex_get_pkey_commsvc_index_portnum() 19167c478bd9Sstevel@tonic-gate * Parses the device node name and extracts PKEY, communication 19177c478bd9Sstevel@tonic-gate * service index & Port #. 19187c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 19197c478bd9Sstevel@tonic-gate */ 19207c478bd9Sstevel@tonic-gate static int 19217c478bd9Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index, 19227c478bd9Sstevel@tonic-gate ib_pkey_t *pkey, uint8_t *port_num) 19237c478bd9Sstevel@tonic-gate { 19247c478bd9Sstevel@tonic-gate char *srv, **service_name, *temp; 19257c478bd9Sstevel@tonic-gate int ii, ncommsvcs, ret; 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate if (ibnex_devname_to_portnum(device_name, port_num) != 19287c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 19297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 19307c478bd9Sstevel@tonic-gate "\tget_pkey_commsvc_index_portnum: Invalid PortGuid"); 19317c478bd9Sstevel@tonic-gate return (NULL); 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate srv = strchr(device_name, ','); 19347c478bd9Sstevel@tonic-gate if (srv == 0) 19357c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 19367c478bd9Sstevel@tonic-gate 19377c478bd9Sstevel@tonic-gate srv++; 19387c478bd9Sstevel@tonic-gate temp = strchr(srv, ','); 19397c478bd9Sstevel@tonic-gate if (temp == 0) 19407c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 19417c478bd9Sstevel@tonic-gate temp++; 19427c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret); 19437c478bd9Sstevel@tonic-gate if (ret != IBNEX_SUCCESS) 19447c478bd9Sstevel@tonic-gate return (ret); 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate if (*pkey == 0 && *port_num != 0) { 19477c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_comm_svc_names; 19487c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_num_comm_svcs; 19497c478bd9Sstevel@tonic-gate } else if (*pkey == 0 && *port_num == 0) { 19507c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_hcasvc_comm_svc_names; 19517c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs; 19527c478bd9Sstevel@tonic-gate } else { 19537c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_vppa_comm_svc_names; 19547c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nvppa_comm_svcs; 19557c478bd9Sstevel@tonic-gate } 19567c478bd9Sstevel@tonic-gate 19577c478bd9Sstevel@tonic-gate for (ii = 0; ii < ncommsvcs; ii++) { 19587c478bd9Sstevel@tonic-gate if (strcmp(service_name[ii], temp) == 0) { 19597c478bd9Sstevel@tonic-gate break; 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate } 19627c478bd9Sstevel@tonic-gate if (ii == ncommsvcs) 19637c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate *index = ii; 19667c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate 19707c478bd9Sstevel@tonic-gate /* 19717c478bd9Sstevel@tonic-gate * ibnex_devname_to_portnum() 19727c478bd9Sstevel@tonic-gate * Get portguid from device name 19737c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 19747c478bd9Sstevel@tonic-gate */ 19757c478bd9Sstevel@tonic-gate static int 19767c478bd9Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum) 19777c478bd9Sstevel@tonic-gate { 19787c478bd9Sstevel@tonic-gate int ret; 19797c478bd9Sstevel@tonic-gate char *temp1, *temp2; 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate temp1 = strchr(device_name, '@'); 19827c478bd9Sstevel@tonic-gate if (temp1 == NULL) { 19837c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate temp2 = strchr(temp1, ','); 19867c478bd9Sstevel@tonic-gate if (temp2 == NULL) 19877c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 19887c478bd9Sstevel@tonic-gate temp1++; 19897c478bd9Sstevel@tonic-gate *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret); 19907c478bd9Sstevel@tonic-gate return (ret); 19917c478bd9Sstevel@tonic-gate } 19927c478bd9Sstevel@tonic-gate 19937c478bd9Sstevel@tonic-gate 19947c478bd9Sstevel@tonic-gate /* 19957c478bd9Sstevel@tonic-gate * ibnex_config_ioc_node() 19967c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver. 19977c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 19987c478bd9Sstevel@tonic-gate */ 19997c478bd9Sstevel@tonic-gate static int 20009d3d2ed0Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip) 20017c478bd9Sstevel@tonic-gate { 20027c478bd9Sstevel@tonic-gate int ret; 20037c478bd9Sstevel@tonic-gate time_t wait_time; 20047c478bd9Sstevel@tonic-gate ib_guid_t iou_guid, ioc_guid; 20057c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 20067c478bd9Sstevel@tonic-gate 20077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin"); 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids( 20109d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) { 20117c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate 20147c478bd9Sstevel@tonic-gate wait_time = ibdm_ibnex_get_waittime(0, &ibnex_port_settling_time); 20157c478bd9Sstevel@tonic-gate if (wait_time) 20167c478bd9Sstevel@tonic-gate delay(drv_usectohz(wait_time * 1000000)); 20177c478bd9Sstevel@tonic-gate 20187c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == 20197c478bd9Sstevel@tonic-gate NULL) { 20207c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 20217c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20227c478bd9Sstevel@tonic-gate } 20237c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 20247c478bd9Sstevel@tonic-gate if (ibnex_is_ioc_present(ioc_guid) == IBNEX_SUCCESS) { 20257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: IOC present"); 20267c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS; 20277c478bd9Sstevel@tonic-gate } else 20289d3d2ed0Shiremath ret = ibnex_ioc_initnode(ioc_info, IBNEX_DEVFS_ENUMERATE, 20299d3d2ed0Shiremath pdip); 20307c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 20317c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 20327c478bd9Sstevel@tonic-gate return (ret); 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate /* 20377c478bd9Sstevel@tonic-gate * ibnex_devname_to_node_n_ioc_guids() 20387c478bd9Sstevel@tonic-gate * Get node guid and ioc guid from the device name 20397c478bd9Sstevel@tonic-gate * Format of the device node name is: 20407c478bd9Sstevel@tonic-gate * ioc@<IOC GUID>,<IOU GUID> 20417c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 20427c478bd9Sstevel@tonic-gate */ 20437c478bd9Sstevel@tonic-gate static int 20447c478bd9Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids( 20459d3d2ed0Shiremath char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid, 20469d3d2ed0Shiremath char **ioc_guid_strp) 20477c478bd9Sstevel@tonic-gate { 20487c478bd9Sstevel@tonic-gate char *temp1, *temp; 20497c478bd9Sstevel@tonic-gate int len, ret; 20509d3d2ed0Shiremath char *ioc_guid_str; 20517c478bd9Sstevel@tonic-gate 20527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:" 20537c478bd9Sstevel@tonic-gate "Device Name %s", device_name); 20547c478bd9Sstevel@tonic-gate 20557c478bd9Sstevel@tonic-gate if ((temp = strchr(device_name, '@')) == NULL) { 20567c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20577c478bd9Sstevel@tonic-gate } 20587c478bd9Sstevel@tonic-gate if ((temp1 = strchr(++temp, ',')) == NULL) { 20597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 20607c478bd9Sstevel@tonic-gate } 20617c478bd9Sstevel@tonic-gate *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret); 20627c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) { 20639d3d2ed0Shiremath if (ioc_guid_strp) { 20649d3d2ed0Shiremath ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1 20659d3d2ed0Shiremath - temp) + 1, KM_SLEEP); 20669d3d2ed0Shiremath (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1); 20679d3d2ed0Shiremath ioc_guid_str[temp1 - temp] = '\0'; 20689d3d2ed0Shiremath } 20697c478bd9Sstevel@tonic-gate len = device_name + strlen(device_name) - ++temp1; 20707c478bd9Sstevel@tonic-gate *iou_guid = ibnex_str2hex(temp1, len, &ret); 20717c478bd9Sstevel@tonic-gate } 20727c478bd9Sstevel@tonic-gate return (ret); 20737c478bd9Sstevel@tonic-gate } 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 20777c478bd9Sstevel@tonic-gate /* 20787c478bd9Sstevel@tonic-gate * ibnex_ioc_initnode() 20797c478bd9Sstevel@tonic-gate * Allocate a pathinfo node for the IOC 20807c478bd9Sstevel@tonic-gate * Initialize the device node 20817c478bd9Sstevel@tonic-gate * Bind driver to the node 20827c478bd9Sstevel@tonic-gate * Update IBnex global data 20837c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY 20847c478bd9Sstevel@tonic-gate */ 20857c478bd9Sstevel@tonic-gate int 20869d3d2ed0Shiremath ibnex_ioc_initnode(ibdm_ioc_info_t *ioc_info, int flag, dev_info_t *pdip) 20877c478bd9Sstevel@tonic-gate { 20887c478bd9Sstevel@tonic-gate int rval; 20897c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 20907c478bd9Sstevel@tonic-gate 20917c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 20927c478bd9Sstevel@tonic-gate 20937c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 20947c478bd9Sstevel@tonic-gate (void *)ioc_info, 0, 0); 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate /* 20977c478bd9Sstevel@tonic-gate * prevent any races 20987c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized 20997c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 21007c478bd9Sstevel@tonic-gate * progress. 21017c478bd9Sstevel@tonic-gate */ 21027c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 21037c478bd9Sstevel@tonic-gate return ((node_data->node_state == IBNEX_CFGADM_CONFIGURING) ? 21047c478bd9Sstevel@tonic-gate IBNEX_BUSY : IBNEX_SUCCESS); 21057c478bd9Sstevel@tonic-gate } else if (node_data == NULL) { 21067c478bd9Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE, 21077c478bd9Sstevel@tonic-gate ioc_info, 0, 0); 21087c478bd9Sstevel@tonic-gate } 21097c478bd9Sstevel@tonic-gate 21107c478bd9Sstevel@tonic-gate /* 21117c478bd9Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure 21127c478bd9Sstevel@tonic-gate * operation is in progress 21137c478bd9Sstevel@tonic-gate */ 21147c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 21157c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 21167c478bd9Sstevel@tonic-gate } 21177c478bd9Sstevel@tonic-gate 21187c478bd9Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED); 21197c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 21207c478bd9Sstevel@tonic-gate 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 21237c478bd9Sstevel@tonic-gate 21249d3d2ed0Shiremath rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip); 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 21277c478bd9Sstevel@tonic-gate if (rval == IBNEX_SUCCESS) 21287c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 21297c478bd9Sstevel@tonic-gate 21307c478bd9Sstevel@tonic-gate return (rval); 21317c478bd9Sstevel@tonic-gate } 21327c478bd9Sstevel@tonic-gate 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate /* 21357c478bd9Sstevel@tonic-gate * ibnex_config_pseudo_all() 21367c478bd9Sstevel@tonic-gate * Configure all the pseudo nodes 21377c478bd9Sstevel@tonic-gate */ 21387c478bd9Sstevel@tonic-gate static void 21399d3d2ed0Shiremath ibnex_config_pseudo_all(dev_info_t *pdip) 21407c478bd9Sstevel@tonic-gate { 21417c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 21427c478bd9Sstevel@tonic-gate 21437c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 21447c478bd9Sstevel@tonic-gate 21457c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; 21467c478bd9Sstevel@tonic-gate nodep; nodep = nodep->node_next) { 214705fa0d51Spramodbg (void) ibnex_pseudo_config_one(nodep, NULL, pdip); 21487c478bd9Sstevel@tonic-gate } 21497c478bd9Sstevel@tonic-gate } 21507c478bd9Sstevel@tonic-gate 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate /* 21537c478bd9Sstevel@tonic-gate * ibnex_pseudo_config_one() 21547c478bd9Sstevel@tonic-gate */ 215505fa0d51Spramodbg static int 215605fa0d51Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr, 21579d3d2ed0Shiremath dev_info_t *pdip) 21587c478bd9Sstevel@tonic-gate { 215905fa0d51Spramodbg int rval; 21607c478bd9Sstevel@tonic-gate 216105fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p):Begin", 216205fa0d51Spramodbg node_data, caddr, pdip); 21637c478bd9Sstevel@tonic-gate 21647c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 21657c478bd9Sstevel@tonic-gate 21667c478bd9Sstevel@tonic-gate if (node_data == NULL) { 216705fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: caddr = %s", 216805fa0d51Spramodbg caddr); 21697c478bd9Sstevel@tonic-gate 217005fa0d51Spramodbg /* 217105fa0d51Spramodbg * This function is now called with PHCI / HCA driver 217205fa0d51Spramodbg * as parent. The format of devicename is : 217305fa0d51Spramodbg * <driver_name>@<driver_name>,<unit_address> 217405fa0d51Spramodbg * The "caddr" part of the devicename matches the 217505fa0d51Spramodbg * format of pseudo_node_addr. 217605fa0d51Spramodbg * 217705fa0d51Spramodbg * Use "caddr" to find a matching Pseudo node entry. 217805fa0d51Spramodbg */ 21797c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 218005fa0d51Spramodbg (void *)caddr, 0, 0); 21817c478bd9Sstevel@tonic-gate } 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate /* 21849d3d2ed0Shiremath * Do not enumerate nodes with ib-node-type set as "merge" 21859d3d2ed0Shiremath */ 21869d3d2ed0Shiremath if (node_data && node_data->node_data.pseudo_node.pseudo_merge_node 21879d3d2ed0Shiremath == 1) { 21889d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: merge_node"); 21899d3d2ed0Shiremath return (IBNEX_FAILURE); 21909d3d2ed0Shiremath } 21919d3d2ed0Shiremath 21929d3d2ed0Shiremath /* 21937c478bd9Sstevel@tonic-gate * prevent any races 21947c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized 21957c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 21967c478bd9Sstevel@tonic-gate * progress. 21977c478bd9Sstevel@tonic-gate */ 21987c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 21997c478bd9Sstevel@tonic-gate return ((node_data->node_state == IBNEX_CFGADM_CONFIGURING) ? 22007c478bd9Sstevel@tonic-gate IBNEX_BUSY : IBNEX_SUCCESS); 22017c478bd9Sstevel@tonic-gate } else if (node_data == NULL) { 22027c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tpseudo_config_one: Invalid node"); 22037c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 22047c478bd9Sstevel@tonic-gate } 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate /* 22077c478bd9Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure 22087c478bd9Sstevel@tonic-gate * operation is in progress 22097c478bd9Sstevel@tonic-gate */ 22107c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 22117c478bd9Sstevel@tonic-gate return (IBNEX_BUSY); 22127c478bd9Sstevel@tonic-gate } 22137c478bd9Sstevel@tonic-gate 22147c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURED) 22157c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 22167c478bd9Sstevel@tonic-gate 22177c478bd9Sstevel@tonic-gate /* 22187c478bd9Sstevel@tonic-gate * Prevent configuring pseudo nodes specifically unconfigured 22197c478bd9Sstevel@tonic-gate * by cfgadm. This is done by checking if this is a newly 22207c478bd9Sstevel@tonic-gate * created node, not yet configured by BUS_CONFIG or cfgadm 22217c478bd9Sstevel@tonic-gate */ 22227c478bd9Sstevel@tonic-gate if (node_data->node_data.pseudo_node.pseudo_new_node != 1) 22237c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 22247c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_new_node = 0; 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 22277c478bd9Sstevel@tonic-gate 22287c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 22299d3d2ed0Shiremath rval = ibnex_pseudo_create_pi(node_data, pdip); 22307c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 22317c478bd9Sstevel@tonic-gate 22327c478bd9Sstevel@tonic-gate if (rval == IBNEX_SUCCESS) 22337c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 22347c478bd9Sstevel@tonic-gate else { 22357c478bd9Sstevel@tonic-gate node_data->node_dip = NULL; 22367c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_UNCONFIGURED; 22377c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_new_node = 1; 22387c478bd9Sstevel@tonic-gate } 22397c478bd9Sstevel@tonic-gate 22407c478bd9Sstevel@tonic-gate return (rval); 22417c478bd9Sstevel@tonic-gate } 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate 22449d3d2ed0Shiremath 22459d3d2ed0Shiremath /* 22469d3d2ed0Shiremath * ibnex_pseudo_mdi_config_one() 22479d3d2ed0Shiremath * This is similar to ibnex_pseudo_config_one. Few 22489d3d2ed0Shiremath * differences : 22499d3d2ed0Shiremath * 1. parent device lock not held(no ndi_devi_enter) 22509d3d2ed0Shiremath * 2. Called for IB Nexus as parent, not IB HCA as 22519d3d2ed0Shiremath * parent. 22529d3d2ed0Shiremath * 3. Calls mdi_vhci_bus_config() 225305fa0d51Spramodbg * This function skips checks for node_state, initializing 225405fa0d51Spramodbg * node_state, node_dip, etc. These checks and initializations 225505fa0d51Spramodbg * are done when BUS_CONFIG is called with PHCI as the parent. 22569d3d2ed0Shiremath */ 22579d3d2ed0Shiremath static int 22589d3d2ed0Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child, 22599d3d2ed0Shiremath char *cname, char *caddr) 22609d3d2ed0Shiremath { 22619d3d2ed0Shiremath int rval, len; 22629d3d2ed0Shiremath char *node_addr; 22639d3d2ed0Shiremath ibnex_node_data_t *node_data; 22649d3d2ed0Shiremath 22659d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:" 22669d3d2ed0Shiremath "cname = %s caddr = %s", cname, caddr); 22679d3d2ed0Shiremath 22689d3d2ed0Shiremath ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 22699d3d2ed0Shiremath 22709d3d2ed0Shiremath len = strlen(cname) + strlen(caddr) + 2; 22719d3d2ed0Shiremath node_addr = (char *)kmem_alloc(len, KM_SLEEP); 22729d3d2ed0Shiremath 22739d3d2ed0Shiremath (void) snprintf(node_addr, len, "%s,%s", cname, caddr); 22749d3d2ed0Shiremath node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE, 22759d3d2ed0Shiremath (void *)node_addr, 0, 0); 22769d3d2ed0Shiremath kmem_free(node_addr, len); 22779d3d2ed0Shiremath 227805fa0d51Spramodbg if (node_data == NULL) { 22799d3d2ed0Shiremath IBTF_DPRINTF_L2("ibnex", 22809d3d2ed0Shiremath "\tpseudo_mdi_config_one: Invalid node"); 22819d3d2ed0Shiremath return (IBNEX_FAILURE); 22829d3d2ed0Shiremath } 22839d3d2ed0Shiremath 22849d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex); 22859d3d2ed0Shiremath rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE, 22869d3d2ed0Shiremath devname, child, node_data->node_data.pseudo_node.pseudo_node_addr); 22879d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex); 22889d3d2ed0Shiremath 22899d3d2ed0Shiremath return (rval); 22909d3d2ed0Shiremath } 22919d3d2ed0Shiremath 22927c478bd9Sstevel@tonic-gate /* 22937c478bd9Sstevel@tonic-gate * ibnex_pseudo_create_pi() 22947c478bd9Sstevel@tonic-gate * Create a path info node for each pseudo entry 22957c478bd9Sstevel@tonic-gate */ 22967c478bd9Sstevel@tonic-gate int 22979d3d2ed0Shiremath ibnex_pseudo_create_pi(ibnex_node_data_t *nodep, dev_info_t *parent) 22987c478bd9Sstevel@tonic-gate { 22997c478bd9Sstevel@tonic-gate mdi_pathinfo_t *pip; 23007c478bd9Sstevel@tonic-gate int rval, hcacnt; 23017c478bd9Sstevel@tonic-gate dev_info_t *hca_dip, *cdip = NULL; 23027c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list, *head; 23037c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo; 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tibnex_pseudo_create_pi: %p", nodep); 23067c478bd9Sstevel@tonic-gate 23077c478bd9Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node; 23087c478bd9Sstevel@tonic-gate 23099d3d2ed0Shiremath 23107c478bd9Sstevel@tonic-gate ibdm_ibnex_get_hca_list(&hca_list, &hcacnt); 23117c478bd9Sstevel@tonic-gate 23127c478bd9Sstevel@tonic-gate head = hca_list; 23137c478bd9Sstevel@tonic-gate 23147c478bd9Sstevel@tonic-gate for (; hca_list != NULL; hca_list = hca_list->hl_next) { 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 23177c478bd9Sstevel@tonic-gate 23189d3d2ed0Shiremath /* 23199d3d2ed0Shiremath * For CONFIG_ONE requests through HCA dip, alloc 23209d3d2ed0Shiremath * for HCA dip driving BUS_CONFIG request. 23219d3d2ed0Shiremath */ 23229d3d2ed0Shiremath if (parent != NULL && hca_dip != parent) 23239d3d2ed0Shiremath continue; 23249d3d2ed0Shiremath 23257c478bd9Sstevel@tonic-gate rval = mdi_pi_alloc(hca_dip, 23267c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name, pseudo->pseudo_node_addr, 23277c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr, 0, &pip); 23287c478bd9Sstevel@tonic-gate 23297c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 23307c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 23317c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 23327c478bd9Sstevel@tonic-gate } 23337c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 23367c478bd9Sstevel@tonic-gate "\tpseudo_create_pi: New dip %p", cdip); 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate nodep->node_dip = cdip; 23397c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, nodep); 23407c478bd9Sstevel@tonic-gate 23417c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 23427c478bd9Sstevel@tonic-gate 23437c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 23447c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 23457c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi:" 23467c478bd9Sstevel@tonic-gate "mdi_pi_online: failed for pseudo dip %p," 23477c478bd9Sstevel@tonic-gate " rval %d", cdip, rval); 23487c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 23497c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 23507c478bd9Sstevel@tonic-gate break; 23517c478bd9Sstevel@tonic-gate } else 23527c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 23539d3d2ed0Shiremath 23549d3d2ed0Shiremath if (parent != NULL && hca_dip != parent) 23559d3d2ed0Shiremath break; 23567c478bd9Sstevel@tonic-gate } 23577c478bd9Sstevel@tonic-gate if (head) 23587c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(head); 23597c478bd9Sstevel@tonic-gate return (rval); 23607c478bd9Sstevel@tonic-gate } 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate 23637c478bd9Sstevel@tonic-gate /* 23647c478bd9Sstevel@tonic-gate * ibnex_ioc_create_pi() 23657c478bd9Sstevel@tonic-gate * Create a pathinfo node for the ioc node 23667c478bd9Sstevel@tonic-gate */ 23677c478bd9Sstevel@tonic-gate static int 23689d3d2ed0Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data, 23699d3d2ed0Shiremath dev_info_t *pdip) 23707c478bd9Sstevel@tonic-gate { 23719d3d2ed0Shiremath char ioc_guid[33], phci_guid[66]; 23727c478bd9Sstevel@tonic-gate mdi_pathinfo_t *pip; 23739d3d2ed0Shiremath int rval = DDI_FAILURE; 23747c478bd9Sstevel@tonic-gate dev_info_t *hca_dip, *cdip = NULL; 23757c478bd9Sstevel@tonic-gate int flag = 1; 23767c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 23777c478bd9Sstevel@tonic-gate 23787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tibnex_ioc_create_pi Begin"); 23797c478bd9Sstevel@tonic-gate 23809d3d2ed0Shiremath (void) snprintf(ioc_guid, 33, "%llX", 23817c478bd9Sstevel@tonic-gate (longlong_t)ioc_info->ioc_profile.ioc_guid); 23829d3d2ed0Shiremath (void) snprintf(phci_guid, 66, "%llX,%llX", 23839d3d2ed0Shiremath (longlong_t)ioc_info->ioc_profile.ioc_guid, 23847c478bd9Sstevel@tonic-gate (longlong_t)ioc_info->ioc_iou_guid); 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate hca_list = ioc_info->ioc_hca_list; 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate for (; hca_list != NULL; hca_list = hca_list->hl_next) { 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid); 23917c478bd9Sstevel@tonic-gate 23929d3d2ed0Shiremath /* 23939d3d2ed0Shiremath * For CONFIG_ONE requests through HCA dip, alloc 23949d3d2ed0Shiremath * for HCA dip driving BUS_CONFIG request. 23959d3d2ed0Shiremath */ 23969d3d2ed0Shiremath if (pdip != NULL && hca_dip != pdip) 23979d3d2ed0Shiremath continue; 23989d3d2ed0Shiremath 23997c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi " 24009d3d2ed0Shiremath "hca guid %llX", hca_list->hl_hca_guid); 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate rval = mdi_pi_alloc(hca_dip, 24039d3d2ed0Shiremath IBNEX_IOC_CNAME, ioc_guid, phci_guid, 0, &pip); 24047c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 24057c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 24067c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24077c478bd9Sstevel@tonic-gate } 24087c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip); 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 24117c478bd9Sstevel@tonic-gate "\tioc_create_pi: New IOC dip %p", cdip); 24127c478bd9Sstevel@tonic-gate 24137c478bd9Sstevel@tonic-gate node_data->node_dip = cdip; 24147c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, node_data); 24157c478bd9Sstevel@tonic-gate 24167c478bd9Sstevel@tonic-gate if (flag) { 24177c478bd9Sstevel@tonic-gate if ((rval = ibnex_create_ioc_node_prop( 24187c478bd9Sstevel@tonic-gate ioc_info, cdip)) != IBNEX_SUCCESS) { 24197c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data); 24207c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 24217c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 24247c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24257c478bd9Sstevel@tonic-gate } 24267c478bd9Sstevel@tonic-gate flag = 0; 24277c478bd9Sstevel@tonic-gate } 24287c478bd9Sstevel@tonic-gate 24297c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0); 24307c478bd9Sstevel@tonic-gate 24317c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) { 24327c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data); 24337c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 24347c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 24357c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: " 24367c478bd9Sstevel@tonic-gate "mdi_pi_online() failed ioc dip %p, rval %d", 24377c478bd9Sstevel@tonic-gate cdip, rval); 24387c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip); 24397c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE; 24407c478bd9Sstevel@tonic-gate break; 24417c478bd9Sstevel@tonic-gate } else 24427c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS; 24439d3d2ed0Shiremath 24449d3d2ed0Shiremath if (pdip != NULL && hca_dip != pdip) 24459d3d2ed0Shiremath break; 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate return (rval); 24487c478bd9Sstevel@tonic-gate } 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate 24517c478bd9Sstevel@tonic-gate /* 24527c478bd9Sstevel@tonic-gate * ibnex_create_ioc_node_prop() 24537c478bd9Sstevel@tonic-gate * Create IOC device node properties 24547c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 24557c478bd9Sstevel@tonic-gate */ 24567c478bd9Sstevel@tonic-gate static int 24577c478bd9Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip) 24587c478bd9Sstevel@tonic-gate { 24597c478bd9Sstevel@tonic-gate uint16_t capabilities; 24607c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile; 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop"); 24637c478bd9Sstevel@tonic-gate 24647c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_compatible_prop(cdip, 24657c478bd9Sstevel@tonic-gate ioc_profile) != IBNEX_SUCCESS) { 24667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24677c478bd9Sstevel@tonic-gate } 24687c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_iou_dc_valid) && 24697c478bd9Sstevel@tonic-gate (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode", 24707c478bd9Sstevel@tonic-gate ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) { 24717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24727c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: iou-diagcode create failed"); 24737c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24747c478bd9Sstevel@tonic-gate } 24757c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) { 24767c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode", 24777c478bd9Sstevel@tonic-gate ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) { 24787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 24797c478bd9Sstevel@tonic-gate "ioc-diagcode create failed"); 24807c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24817c478bd9Sstevel@tonic-gate } 24827c478bd9Sstevel@tonic-gate } 24837c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth", 24847c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) { 24857c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24867c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: rdma-queue-depth create failed"); 24877c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24887c478bd9Sstevel@tonic-gate } 24897c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size", 24907c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) { 24917c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: " 24927c478bd9Sstevel@tonic-gate "rdma-transfer-size create failed"); 24937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size", 24967c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) { 24977c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 24987c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-message-size create failed"); 24997c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25007c478bd9Sstevel@tonic-gate } 25017c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth", 25027c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) { 25037c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25047c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-queue-depth create failed"); 25057c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25067c478bd9Sstevel@tonic-gate } 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8); 25097c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, 25107c478bd9Sstevel@tonic-gate "capabilities", capabilities) != DDI_PROP_SUCCESS) { 25117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25127c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: capabilities create failed"); 25137c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25147c478bd9Sstevel@tonic-gate } 25157c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string", 25167c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) { 25177c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25187c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: id-string failed"); 25197c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25207c478bd9Sstevel@tonic-gate } 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate /* 25237c478bd9Sstevel@tonic-gate * Create properties to represent all the service entries supported 25247c478bd9Sstevel@tonic-gate * by the IOC. Each service entry consists of 1) Service ID (64 bits) 25257c478bd9Sstevel@tonic-gate * and 2) Service name (40 bytes). The service entry table is 25267c478bd9Sstevel@tonic-gate * represented by two properties, service-ids and service-names. The 25277c478bd9Sstevel@tonic-gate * service-id property is a array of int64's and service names is 25287c478bd9Sstevel@tonic-gate * array of strings. The first element in the "service-ids" property 25297c478bd9Sstevel@tonic-gate * corresponds to first string in the "service-names" and so on. 25307c478bd9Sstevel@tonic-gate */ 25317c478bd9Sstevel@tonic-gate if ((ioc_profile->ioc_service_entries != 0) && 25327c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS)) 25337c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate /* Create destination port GID properties */ 25367c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS) 25377c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version", 25407c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) { 25417c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25427c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol-version create failed"); 25437c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25447c478bd9Sstevel@tonic-gate } 25457c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol", 25467c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) { 25477c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25487c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 25497c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25507c478bd9Sstevel@tonic-gate } 25517c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass", 25527c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) { 25537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25547c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subclass create failed"); 25557c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25567c478bd9Sstevel@tonic-gate } 25577c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class", 25587c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) { 25597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25607c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: class prop create failed"); 25617c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25627c478bd9Sstevel@tonic-gate } 25637c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id", 25647c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) { 25657c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25667c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsys_id create failed"); 25677c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25687c478bd9Sstevel@tonic-gate } 25697c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id", 25707c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) { 25717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25727c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsystem vendor create failed"); 25737c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25747c478bd9Sstevel@tonic-gate } 25757c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid", 25767c478bd9Sstevel@tonic-gate ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) { 25777c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25787c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed"); 25797c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25807c478bd9Sstevel@tonic-gate } 25817c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version", 25827c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) { 25837c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25847c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 25857c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25867c478bd9Sstevel@tonic-gate } 25877c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id", 25887c478bd9Sstevel@tonic-gate ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) { 25897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25907c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed"); 25917c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id", 25947c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) { 25957c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 25967c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: vendor-id create failed"); 25977c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 25987c478bd9Sstevel@tonic-gate } 25997c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 26007c478bd9Sstevel@tonic-gate } 26017c478bd9Sstevel@tonic-gate 26027c478bd9Sstevel@tonic-gate 26037c478bd9Sstevel@tonic-gate /* 26047c478bd9Sstevel@tonic-gate * ibnex_create_ioc_portgid_prop() 26057c478bd9Sstevel@tonic-gate * Creates "port-entries", "port-list" properties 26067c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 26077c478bd9Sstevel@tonic-gate */ 26087c478bd9Sstevel@tonic-gate static int 26097c478bd9Sstevel@tonic-gate ibnex_create_ioc_portgid_prop( 26107c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 26117c478bd9Sstevel@tonic-gate { 26127c478bd9Sstevel@tonic-gate uint64_t *port_gids; 26137c478bd9Sstevel@tonic-gate int length, ii, jj; 26147c478bd9Sstevel@tonic-gate int prop_len; 26157c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 26167c478bd9Sstevel@tonic-gate 26177c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop"); 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip); 26207c478bd9Sstevel@tonic-gate ASSERT(node_data); 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate prop_len = (ioc_info->ioc_nportgids != 0) ? 26237c478bd9Sstevel@tonic-gate (2 * ioc_info->ioc_nportgids) : 1; 26247c478bd9Sstevel@tonic-gate length = sizeof (uint64_t) * prop_len; 26257c478bd9Sstevel@tonic-gate port_gids = kmem_zalloc(length, KM_SLEEP); 26267c478bd9Sstevel@tonic-gate 26277c478bd9Sstevel@tonic-gate for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) { 26287c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi; 26297c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo; 26307c478bd9Sstevel@tonic-gate } 26317c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list", 26327c478bd9Sstevel@tonic-gate (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) { 26337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26347c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-list create failed"); 26357c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 26367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries", 26397c478bd9Sstevel@tonic-gate ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) { 26407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26417c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-entries create failed"); 26427c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 26437c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26447c478bd9Sstevel@tonic-gate } 26457c478bd9Sstevel@tonic-gate 26467c478bd9Sstevel@tonic-gate kmem_free(port_gids, length); 26477c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 26487c478bd9Sstevel@tonic-gate } 26497c478bd9Sstevel@tonic-gate 26507c478bd9Sstevel@tonic-gate 26517c478bd9Sstevel@tonic-gate /* 26527c478bd9Sstevel@tonic-gate * ibnex_create_ioc_srv_props() 26537c478bd9Sstevel@tonic-gate * Creates "service-name" and "service-id" properties 26547c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 26557c478bd9Sstevel@tonic-gate */ 26567c478bd9Sstevel@tonic-gate static int 26577c478bd9Sstevel@tonic-gate ibnex_create_ioc_srv_props( 26587c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info) 26597c478bd9Sstevel@tonic-gate { 26607c478bd9Sstevel@tonic-gate int length, ii; 26617c478bd9Sstevel@tonic-gate uint64_t *srv_id; 26627c478bd9Sstevel@tonic-gate char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU]; 26637c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile; 26647c478bd9Sstevel@tonic-gate ibdm_srvents_info_t *srvents = ioc_info->ioc_serv; 26657c478bd9Sstevel@tonic-gate 26667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props"); 26677c478bd9Sstevel@tonic-gate 26687c478bd9Sstevel@tonic-gate length = profile->ioc_service_entries * sizeof (ib_dm_srv_t); 26697c478bd9Sstevel@tonic-gate srv_id = kmem_zalloc(length, KM_SLEEP); 26707c478bd9Sstevel@tonic-gate temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries)); 26717c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 26727c478bd9Sstevel@tonic-gate srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN); 26737c478bd9Sstevel@tonic-gate } 26747c478bd9Sstevel@tonic-gate 26757c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) { 26767c478bd9Sstevel@tonic-gate srv_id[ii] = srvents[ii].se_attr.srv_id; 26777c478bd9Sstevel@tonic-gate bcopy(srvents[ii].se_attr.srv_name, 26787c478bd9Sstevel@tonic-gate srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1)); 26797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 26807c478bd9Sstevel@tonic-gate "Service Names : %s", srv_names[ii]); 26817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props " 26829d3d2ed0Shiremath "Service ID : %llX", srv_id[ii]); 26837c478bd9Sstevel@tonic-gate } 26847c478bd9Sstevel@tonic-gate 26857c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, 26867c478bd9Sstevel@tonic-gate "service-id", (int64_t *)srv_id, 26877c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 26887c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26897c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-id create failed"); 26907c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 26917c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 26927c478bd9Sstevel@tonic-gate } 26937c478bd9Sstevel@tonic-gate 26947c478bd9Sstevel@tonic-gate if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 26957c478bd9Sstevel@tonic-gate "service-name", (char **)srv_names, 26967c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) { 26977c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 26987c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-name create failed"); 26997c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27007c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27017c478bd9Sstevel@tonic-gate } 27027c478bd9Sstevel@tonic-gate kmem_free(srv_id, length); 27037c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27047c478bd9Sstevel@tonic-gate } 27057c478bd9Sstevel@tonic-gate 27067c478bd9Sstevel@tonic-gate 27077c478bd9Sstevel@tonic-gate /* 27087c478bd9Sstevel@tonic-gate * ibnex_create_ioc_compatible_prop() 27097c478bd9Sstevel@tonic-gate * Creates "compatible" property values 27107c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 27117c478bd9Sstevel@tonic-gate */ 27127c478bd9Sstevel@tonic-gate static int 27137c478bd9Sstevel@tonic-gate ibnex_create_ioc_compatible_prop( 27147c478bd9Sstevel@tonic-gate dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile) 27157c478bd9Sstevel@tonic-gate { 27167c478bd9Sstevel@tonic-gate char *temp; 27177c478bd9Sstevel@tonic-gate int rval, ii; 27187c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_COMPAT_NAMES]; 27197c478bd9Sstevel@tonic-gate 27207c478bd9Sstevel@tonic-gate /* 27217c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 27227c478bd9Sstevel@tonic-gate * Compatible Strings : 27237c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver> 27247c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id> 27257c478bd9Sstevel@tonic-gate * 3. ib.V<vid>P<pid>v<ver> 27267c478bd9Sstevel@tonic-gate * 4. ib.V<vid>P<pid> 27277c478bd9Sstevel@tonic-gate * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver> 27287c478bd9Sstevel@tonic-gate * 6. ib.C<Class>c<Subclass>p<protocol> 27297c478bd9Sstevel@tonic-gate * 27307c478bd9Sstevel@tonic-gate * Note: 27317c478bd9Sstevel@tonic-gate * All leading zeros must be present 27327c478bd9Sstevel@tonic-gate * All numeric values must specified in hex without prefix "0x" 27337c478bd9Sstevel@tonic-gate */ 27347c478bd9Sstevel@tonic-gate 27357c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP); 27367c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 27377c478bd9Sstevel@tonic-gate compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN); 27387c478bd9Sstevel@tonic-gate 27397c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 27407c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08xv%04x", 27417c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 27427c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id, 27437c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 27447c478bd9Sstevel@tonic-gate 27457c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 27467c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08x", 27477c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 27487c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id); 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 27517c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x", 27527c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid, 27537c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver); 27547c478bd9Sstevel@tonic-gate 27557c478bd9Sstevel@tonic-gate (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN, 27567c478bd9Sstevel@tonic-gate "ib.V%06xP%08x", 27577c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid); 27587c478bd9Sstevel@tonic-gate 27597c478bd9Sstevel@tonic-gate (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN, 27607c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04xr%04x", 27617c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 27627c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver); 27637c478bd9Sstevel@tonic-gate 27647c478bd9Sstevel@tonic-gate (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN, 27657c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04x", 27667c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass, 27677c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol); 27687c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++) 27697c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]); 27707c478bd9Sstevel@tonic-gate 27717c478bd9Sstevel@tonic-gate /* Create the compatible property for child cdip */ 27727c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip, 27737c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES); 27747c478bd9Sstevel@tonic-gate 27757c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 27767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed"); 27777c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 27787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 27797c478bd9Sstevel@tonic-gate } 27807c478bd9Sstevel@tonic-gate 27817c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ); 27827c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 27837c478bd9Sstevel@tonic-gate } 27847c478bd9Sstevel@tonic-gate 27857c478bd9Sstevel@tonic-gate 27867c478bd9Sstevel@tonic-gate static void 27877c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup() 27887c478bd9Sstevel@tonic-gate { 27897c478bd9Sstevel@tonic-gate ibnex_node_data_t *node, *delete; 27907c478bd9Sstevel@tonic-gate 27917c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 27927c478bd9Sstevel@tonic-gate for (node = ibnex.ibnex_ioc_node_head; node; ) { 27937c478bd9Sstevel@tonic-gate delete = node; 27947c478bd9Sstevel@tonic-gate node = node->node_next; 27957c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 27967c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(delete); 27977c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 27987c478bd9Sstevel@tonic-gate } 27997c478bd9Sstevel@tonic-gate } 28007c478bd9Sstevel@tonic-gate 28017c478bd9Sstevel@tonic-gate /* 28027c478bd9Sstevel@tonic-gate * ibnex_delete_ioc_node_data() 28037c478bd9Sstevel@tonic-gate * Delete IOC node from the list 28047c478bd9Sstevel@tonic-gate */ 28057c478bd9Sstevel@tonic-gate static void 28067c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node) 28077c478bd9Sstevel@tonic-gate { 28087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:"); 28097c478bd9Sstevel@tonic-gate 28107c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 28117c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) { 28127c478bd9Sstevel@tonic-gate ASSERT(ibnex.ibnex_ioc_node_head == node); 28137c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = NULL; 28147c478bd9Sstevel@tonic-gate } else if (node->node_next == NULL) 28157c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 28167c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 28177c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 28187c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node->node_next; 28197c478bd9Sstevel@tonic-gate } else { 28207c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 28217c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 28227c478bd9Sstevel@tonic-gate } 28237c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p", 28247c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head); 28257c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 28267c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 28277c478bd9Sstevel@tonic-gate } 28287c478bd9Sstevel@tonic-gate 28297c478bd9Sstevel@tonic-gate 28307c478bd9Sstevel@tonic-gate /* 28317c478bd9Sstevel@tonic-gate * ibnex_dm_callback() 28327c478bd9Sstevel@tonic-gate * 28337c478bd9Sstevel@tonic-gate * This routine is registered with the IBDM during IB nexus attach. It 28347c478bd9Sstevel@tonic-gate * is called by the IBDM module when it discovers 28357c478bd9Sstevel@tonic-gate * New HCA port 28367c478bd9Sstevel@tonic-gate * HCA port removal 28377c478bd9Sstevel@tonic-gate * New HCA added 28387c478bd9Sstevel@tonic-gate * HCA removed 28397c478bd9Sstevel@tonic-gate */ 28407c478bd9Sstevel@tonic-gate void 28417c478bd9Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag) 28427c478bd9Sstevel@tonic-gate { 28437c478bd9Sstevel@tonic-gate char hca_guid[IBNEX_HCAGUID_STRSZ]; 28447c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc; 28457c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 28467c478bd9Sstevel@tonic-gate 28477c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag); 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate switch (flag) { 28507c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_ADDED: 28517c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 28527c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 28537c478bd9Sstevel@tonic-gate /* Create a devctl minor node for the HCA's port */ 28547c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR, 28557c478bd9Sstevel@tonic-gate ddi_get_instance(ibnex.ibnex_dip), 28567c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) { 28577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to " 28587c478bd9Sstevel@tonic-gate "create minor node for port w/ guid %s", hca_guid); 28597c478bd9Sstevel@tonic-gate } 28607c478bd9Sstevel@tonic-gate 28617c478bd9Sstevel@tonic-gate break; 28627c478bd9Sstevel@tonic-gate 28637c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_REMOVED: 28647c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX", 28657c478bd9Sstevel@tonic-gate (*(longlong_t *)arg)); 28667c478bd9Sstevel@tonic-gate ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid); 28677c478bd9Sstevel@tonic-gate break; 28687c478bd9Sstevel@tonic-gate 28697c478bd9Sstevel@tonic-gate case IBDM_EVENT_IOC_PROP_UPDATE: 28707c478bd9Sstevel@tonic-gate ioc = ioc_list = (ibdm_ioc_info_t *)arg; 28717c478bd9Sstevel@tonic-gate if (ioc_list == NULL) 28727c478bd9Sstevel@tonic-gate break; 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 28757c478bd9Sstevel@tonic-gate while (ioc_list) { 28767c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present( 28777c478bd9Sstevel@tonic-gate IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL && 28787c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 28797c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_list); 28807c478bd9Sstevel@tonic-gate } 28817c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next; 28827c478bd9Sstevel@tonic-gate } 28837c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 28847c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 28857c478bd9Sstevel@tonic-gate } 28867c478bd9Sstevel@tonic-gate } 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate 28897c478bd9Sstevel@tonic-gate /* 28907c478bd9Sstevel@tonic-gate * ibnex_get_dip_from_guid() 28917c478bd9Sstevel@tonic-gate * 28927c478bd9Sstevel@tonic-gate * Searches the linked list of the port nodes and returns the dip for 28937c478bd9Sstevel@tonic-gate * the of the Port / Node guid requested. 28947c478bd9Sstevel@tonic-gate * Returns NULL if not found 28957c478bd9Sstevel@tonic-gate */ 28967c478bd9Sstevel@tonic-gate int 28977c478bd9Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey, 28987c478bd9Sstevel@tonic-gate dev_info_t **dip) 28997c478bd9Sstevel@tonic-gate { 29007c478bd9Sstevel@tonic-gate int node_index; 29017c478bd9Sstevel@tonic-gate ib_guid_t node_guid; 29027c478bd9Sstevel@tonic-gate ib_pkey_t node_pkey; 29037c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 29047c478bd9Sstevel@tonic-gate 29057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 29069d3d2ed0Shiremath "\tget_dip_from_guid: guid = %llX", guid); 29077c478bd9Sstevel@tonic-gate 29087c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 29097c478bd9Sstevel@tonic-gate /* Search for a matching entry in internal lists */ 29107c478bd9Sstevel@tonic-gate node_data = ibnex.ibnex_port_node_head; 29117c478bd9Sstevel@tonic-gate while (node_data) { 29127c478bd9Sstevel@tonic-gate node_guid = node_data->node_data.port_node.port_guid; 29137c478bd9Sstevel@tonic-gate node_index = node_data->node_data.port_node.port_commsvc_idx; 29147c478bd9Sstevel@tonic-gate node_pkey = node_data->node_data.port_node.port_pkey; 29157c478bd9Sstevel@tonic-gate if ((node_guid == guid) && (index == node_index) && 29167c478bd9Sstevel@tonic-gate (node_pkey == pkey)) { 29177c478bd9Sstevel@tonic-gate break; 29187c478bd9Sstevel@tonic-gate } 29197c478bd9Sstevel@tonic-gate node_data = node_data->node_next; 29207c478bd9Sstevel@tonic-gate } 29217c478bd9Sstevel@tonic-gate 29227c478bd9Sstevel@tonic-gate /* matching found with a valid dip */ 29237c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 29247c478bd9Sstevel@tonic-gate *dip = node_data->node_dip; 29257c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 29267c478bd9Sstevel@tonic-gate } else if (node_data && !node_data->node_dip) { /* dip is invalid */ 29277c478bd9Sstevel@tonic-gate *dip = NULL; 29287c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 29297c478bd9Sstevel@tonic-gate } 29307c478bd9Sstevel@tonic-gate 29317c478bd9Sstevel@tonic-gate /* no match found */ 29327c478bd9Sstevel@tonic-gate *dip = NULL; 29337c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 29347c478bd9Sstevel@tonic-gate } 29357c478bd9Sstevel@tonic-gate 29367c478bd9Sstevel@tonic-gate 29377c478bd9Sstevel@tonic-gate /* 29387c478bd9Sstevel@tonic-gate * ibnex_comm_svc_init() 29397c478bd9Sstevel@tonic-gate * Read the property and cache the values in the global 29407c478bd9Sstevel@tonic-gate * structure. 29417c478bd9Sstevel@tonic-gate * Check for max allowed length (4 bytes) of service name 29427c478bd9Sstevel@tonic-gate * (each element of the property) 29437c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 29447c478bd9Sstevel@tonic-gate */ 29457c478bd9Sstevel@tonic-gate static ibnex_rval_t 29467c478bd9Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type) 29477c478bd9Sstevel@tonic-gate { 29487c478bd9Sstevel@tonic-gate int i, len, count; 29497c478bd9Sstevel@tonic-gate int ncomm_svcs; 29507c478bd9Sstevel@tonic-gate char **comm_svcp; 29517c478bd9Sstevel@tonic-gate char **servicep = NULL; 29527c478bd9Sstevel@tonic-gate uint_t nservices = 0; 29537c478bd9Sstevel@tonic-gate int *valid = NULL; 29547c478bd9Sstevel@tonic-gate 29557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x", 29567c478bd9Sstevel@tonic-gate property, type); 29577c478bd9Sstevel@tonic-gate 29587c478bd9Sstevel@tonic-gate /* lookup the string array property */ 29597c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip, 29607c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, property, &servicep, &nservices) != 29617c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 29627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property); 29637c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 29647c478bd9Sstevel@tonic-gate } 29657c478bd9Sstevel@tonic-gate 29667c478bd9Sstevel@tonic-gate if (nservices) 29677c478bd9Sstevel@tonic-gate valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP); 29687c478bd9Sstevel@tonic-gate 29697c478bd9Sstevel@tonic-gate 29707c478bd9Sstevel@tonic-gate /* first read the file to get a count of valid service entries */ 29717c478bd9Sstevel@tonic-gate for (ncomm_svcs = 0, count = 0; count < nservices; count++) { 29727c478bd9Sstevel@tonic-gate int j; 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate len = strlen(servicep[count]); 29757c478bd9Sstevel@tonic-gate if (len == 0 || len > 4) { 29767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 29777c478bd9Sstevel@tonic-gate "Service name %s invalid : length %d", 29787c478bd9Sstevel@tonic-gate servicep[count], len); 29797c478bd9Sstevel@tonic-gate continue; 29807c478bd9Sstevel@tonic-gate } 29817c478bd9Sstevel@tonic-gate if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) { 29827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 29837c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 29847c478bd9Sstevel@tonic-gate servicep[count]); 29857c478bd9Sstevel@tonic-gate continue; 29867c478bd9Sstevel@tonic-gate } 29877c478bd9Sstevel@tonic-gate 29887c478bd9Sstevel@tonic-gate /* 29897c478bd9Sstevel@tonic-gate * ibnex_unique_svcname checks for uniqueness in service names 29907c478bd9Sstevel@tonic-gate * communication services fully initialized. Check uniqueness 29917c478bd9Sstevel@tonic-gate * in service names currently initialized. 29927c478bd9Sstevel@tonic-gate */ 29937c478bd9Sstevel@tonic-gate for (j = 0; j < count; j++) 29947c478bd9Sstevel@tonic-gate if (valid[j] && strncmp(servicep[count], 29957c478bd9Sstevel@tonic-gate servicep[j], 4) == 0) { 29967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : " 29977c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique", 29987c478bd9Sstevel@tonic-gate servicep[count]); 29997c478bd9Sstevel@tonic-gate continue; 30007c478bd9Sstevel@tonic-gate } 30017c478bd9Sstevel@tonic-gate 30027c478bd9Sstevel@tonic-gate valid[count] = 1; 30037c478bd9Sstevel@tonic-gate ncomm_svcs++; 30047c478bd9Sstevel@tonic-gate } 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate /* if no valid entries found, bailout */ 30077c478bd9Sstevel@tonic-gate if (nservices == 0 || ncomm_svcs == 0) { 30087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property); 30097c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); /* free the property */ 30107c478bd9Sstevel@tonic-gate if (valid) 30117c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 30127c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30137c478bd9Sstevel@tonic-gate } 30147c478bd9Sstevel@tonic-gate 30157c478bd9Sstevel@tonic-gate comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP); 30167c478bd9Sstevel@tonic-gate if (type == IBNEX_PORT_COMMSVC_NODE) { 30177c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = comm_svcp; 30187c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = ncomm_svcs; 30197c478bd9Sstevel@tonic-gate } else if (type == IBNEX_VPPA_COMMSVC_NODE) { 30207c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = comm_svcp; 30217c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs; 30227c478bd9Sstevel@tonic-gate } else if (type == IBNEX_HCASVC_COMMSVC_NODE) { 30237c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp; 30247c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs; 30257c478bd9Sstevel@tonic-gate } 30267c478bd9Sstevel@tonic-gate 30277c478bd9Sstevel@tonic-gate /* copy the services into an array of strings */ 30287c478bd9Sstevel@tonic-gate for (i = 0, count = 0; count < nservices; count++) { 30297c478bd9Sstevel@tonic-gate if (valid[count] == 0) /* Skip invalid ones */ 30307c478bd9Sstevel@tonic-gate continue; 30317c478bd9Sstevel@tonic-gate comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP); 30327c478bd9Sstevel@tonic-gate (void) strcpy(comm_svcp[i], servicep[count]); 30337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 30347c478bd9Sstevel@tonic-gate "\t\tService [%d]: %s", i, comm_svcp[i]); 30357c478bd9Sstevel@tonic-gate ++i; 30367c478bd9Sstevel@tonic-gate } 30377c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); 30387c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int)); 30397c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 30407c478bd9Sstevel@tonic-gate } 30417c478bd9Sstevel@tonic-gate 30427c478bd9Sstevel@tonic-gate 30437c478bd9Sstevel@tonic-gate /* 30447c478bd9Sstevel@tonic-gate * ibnex_comm_svc_fini() 30457c478bd9Sstevel@tonic-gate * Deallocate all the memory allocated for the communication 30467c478bd9Sstevel@tonic-gate * service arrays. 30477c478bd9Sstevel@tonic-gate */ 30487c478bd9Sstevel@tonic-gate static void 30497c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini() 30507c478bd9Sstevel@tonic-gate { 30517c478bd9Sstevel@tonic-gate int index; 30527c478bd9Sstevel@tonic-gate 30537c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) { 30547c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names[index], 30557c478bd9Sstevel@tonic-gate (strlen(ibnex.ibnex_comm_svc_names[index]) + 1)); 30567c478bd9Sstevel@tonic-gate } 30577c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names) { 30587c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names, 30597c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs * sizeof (char *)); 30607c478bd9Sstevel@tonic-gate } 30617c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) { 30627c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names[index], 30637c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1); 30647c478bd9Sstevel@tonic-gate } 30657c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names) { 30667c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names, 30677c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs * sizeof (char *)); 30687c478bd9Sstevel@tonic-gate } 30697c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) { 30707c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index], 30717c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1); 30727c478bd9Sstevel@tonic-gate } 30737c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names) { 30747c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names, 30757c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *)); 30767c478bd9Sstevel@tonic-gate } 30777c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = NULL; 30787c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = 0; 30797c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = NULL; 30807c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = 0; 30817c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = NULL; 30827c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = 0; 30837c478bd9Sstevel@tonic-gate } 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate 30867c478bd9Sstevel@tonic-gate /* 30877c478bd9Sstevel@tonic-gate * ibnex_commsvc_initnode() 30887c478bd9Sstevel@tonic-gate * This routine is specific to port/VPPA node creation 30897c478bd9Sstevel@tonic-gate * Creates a device node for the comm service specified by commsvc_index 30907c478bd9Sstevel@tonic-gate * Creates all the device node properties 30917c478bd9Sstevel@tonic-gate * Allocates and initializes the node specific data 30927c478bd9Sstevel@tonic-gate * Binds the device driver of the device node 30937c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the child node or NULL in case of failure 30947c478bd9Sstevel@tonic-gate * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect 30957c478bd9Sstevel@tonic-gate * if the operation was successful, failed or was not performed. 30967c478bd9Sstevel@tonic-gate */ 30977c478bd9Sstevel@tonic-gate dev_info_t * 30987c478bd9Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr, 30997c478bd9Sstevel@tonic-gate int index, int node_type, ib_pkey_t pkey, int *rval, int flag) 31007c478bd9Sstevel@tonic-gate { 31017c478bd9Sstevel@tonic-gate int ret; 31027c478bd9Sstevel@tonic-gate char *svcname; 31037c478bd9Sstevel@tonic-gate dev_info_t *cdip; 31047c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 31077c478bd9Sstevel@tonic-gate 31087c478bd9Sstevel@tonic-gate *rval = IBNEX_SUCCESS; 31097c478bd9Sstevel@tonic-gate 31107c478bd9Sstevel@tonic-gate /* 31117c478bd9Sstevel@tonic-gate * prevent any races 31127c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized 31137c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in 31147c478bd9Sstevel@tonic-gate * progress. 31157c478bd9Sstevel@tonic-gate */ 31167c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(node_type, (void *)port_attr, 31177c478bd9Sstevel@tonic-gate index, pkey); 31187c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) { 31197c478bd9Sstevel@tonic-gate /* 31207c478bd9Sstevel@tonic-gate * Return NULL if another configure 31217c478bd9Sstevel@tonic-gate * operation is in progress 31227c478bd9Sstevel@tonic-gate */ 31237c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) { 31247c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 31257c478bd9Sstevel@tonic-gate return (NULL); 31267c478bd9Sstevel@tonic-gate } else { 31277c478bd9Sstevel@tonic-gate return (node_data->node_dip); 31287c478bd9Sstevel@tonic-gate } 31297c478bd9Sstevel@tonic-gate } else if (node_data == NULL) { 31307c478bd9Sstevel@tonic-gate /* allocate a new ibnex_node_data_t */ 31317c478bd9Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(node_type, port_attr, 31327c478bd9Sstevel@tonic-gate index, pkey); 31337c478bd9Sstevel@tonic-gate } 31347c478bd9Sstevel@tonic-gate 31357c478bd9Sstevel@tonic-gate /* 31367c478bd9Sstevel@tonic-gate * Return NULL if another unconfigure operation is in progress 31377c478bd9Sstevel@tonic-gate */ 31387c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) { 31397c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY; 31407c478bd9Sstevel@tonic-gate return (NULL); 31417c478bd9Sstevel@tonic-gate } 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED); 31447c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 31457c478bd9Sstevel@tonic-gate 31467c478bd9Sstevel@tonic-gate ndi_devi_alloc_sleep(parent, 3147fa9e4066Sahrens IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip); 31487c478bd9Sstevel@tonic-gate 31497c478bd9Sstevel@tonic-gate node_data->node_dip = cdip; 31507c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, node_data); 31517c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 31527c478bd9Sstevel@tonic-gate 31537c478bd9Sstevel@tonic-gate switch (node_type) { 31547c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE : 31557c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_vppa_comm_svc_names[index]; 31567c478bd9Sstevel@tonic-gate break; 31577c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE : 31587c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_hcasvc_comm_svc_names[index]; 31597c478bd9Sstevel@tonic-gate break; 31607c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE : 31617c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_comm_svc_names[index]; 31627c478bd9Sstevel@tonic-gate break; 31637c478bd9Sstevel@tonic-gate default : 31647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:" 31657c478bd9Sstevel@tonic-gate "\tInvalid Node type"); 31667c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 31677c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(node_data); 31687c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 31697c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 31707c478bd9Sstevel@tonic-gate (void) ndi_devi_free(cdip); 31717c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 31727c478bd9Sstevel@tonic-gate return (NULL); 31737c478bd9Sstevel@tonic-gate } 31747c478bd9Sstevel@tonic-gate 31757c478bd9Sstevel@tonic-gate if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) == 31767c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 31777c478bd9Sstevel@tonic-gate if (flag == IBNEX_DEVFS_ENUMERATE) 31787c478bd9Sstevel@tonic-gate ret = ndi_devi_bind_driver(cdip, 0); 31797c478bd9Sstevel@tonic-gate else 31807c478bd9Sstevel@tonic-gate ret = ndi_devi_online(cdip, 0); 31817c478bd9Sstevel@tonic-gate if (ret == NDI_SUCCESS) { 31827c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 31837c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED; 31847c478bd9Sstevel@tonic-gate return (cdip); 31857c478bd9Sstevel@tonic-gate } 31867c478bd9Sstevel@tonic-gate } 31877c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE; 31887c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(node_data); 31897c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip); 31907c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL); 31917c478bd9Sstevel@tonic-gate (void) ndi_devi_free(cdip); 31927c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 31937c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit"); 31947c478bd9Sstevel@tonic-gate return (NULL); 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate 31977c478bd9Sstevel@tonic-gate 31987c478bd9Sstevel@tonic-gate /* 31997c478bd9Sstevel@tonic-gate * ibnex_create_port_node_prop() 32007c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 32017c478bd9Sstevel@tonic-gate */ 32027c478bd9Sstevel@tonic-gate static int 32037c478bd9Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr, 32047c478bd9Sstevel@tonic-gate dev_info_t *child_dip, char *srvname, ib_pkey_t pkey) 32057c478bd9Sstevel@tonic-gate { 32067c478bd9Sstevel@tonic-gate if (ibnex_create_port_compatible_prop(child_dip, 32077c478bd9Sstevel@tonic-gate srvname, port_attr) != DDI_PROP_SUCCESS) { 32087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32097c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: compatible update failed"); 32107c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32117c478bd9Sstevel@tonic-gate } 32127c478bd9Sstevel@tonic-gate if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 32137c478bd9Sstevel@tonic-gate "port-pkey", pkey) != DDI_PROP_SUCCESS)) { 32147c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32157c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 32167c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32177c478bd9Sstevel@tonic-gate } 32187c478bd9Sstevel@tonic-gate 32197c478bd9Sstevel@tonic-gate /* 32207c478bd9Sstevel@tonic-gate * For HCA_SVC device nodes, port_num will be 0. 32217c478bd9Sstevel@tonic-gate * Do not create the "port-number" & "port-guid" properties. 32227c478bd9Sstevel@tonic-gate */ 32237c478bd9Sstevel@tonic-gate if (port_attr->pa_port_num != 0) { 32247c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 32257c478bd9Sstevel@tonic-gate "port-number", port_attr->pa_port_num) != 32267c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 32277c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32287c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed"); 32297c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32307c478bd9Sstevel@tonic-gate } 32317c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 32327c478bd9Sstevel@tonic-gate "port-guid", port_attr->pa_port_guid) != 32337c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 32347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32357c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guid update failed"); 32367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32377c478bd9Sstevel@tonic-gate } 32387c478bd9Sstevel@tonic-gate } else { 32397c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list; 32407c478bd9Sstevel@tonic-gate 32417c478bd9Sstevel@tonic-gate /* 32427c478bd9Sstevel@tonic-gate * HCA_SVC nodes require "num-ports" & "port-guids" 32437c478bd9Sstevel@tonic-gate * properties. 32447c478bd9Sstevel@tonic-gate * 32457c478bd9Sstevel@tonic-gate * To create the num-ports & port-guids attribute : 32467c478bd9Sstevel@tonic-gate * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid) 32477c478bd9Sstevel@tonic-gate * 2. Form the array of port GUIDs. 32487c478bd9Sstevel@tonic-gate */ 32497c478bd9Sstevel@tonic-gate if ((hca_list = ibdm_ibnex_get_hca_info_by_guid( 32507c478bd9Sstevel@tonic-gate port_attr->pa_hca_guid)) == NULL) { 32517c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32527c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca_info_by_guid failed"); 32537c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32547c478bd9Sstevel@tonic-gate } 32557c478bd9Sstevel@tonic-gate 32567c478bd9Sstevel@tonic-gate if (hca_list->hl_nports != 0) { 32577c478bd9Sstevel@tonic-gate ib_guid_t *port_guids; 32587c478bd9Sstevel@tonic-gate uint8_t portnum; 32597c478bd9Sstevel@tonic-gate 32607c478bd9Sstevel@tonic-gate ASSERT(hca_list->hl_port_attr != NULL); 32617c478bd9Sstevel@tonic-gate 32627c478bd9Sstevel@tonic-gate port_guids = kmem_zalloc( 32637c478bd9Sstevel@tonic-gate hca_list->hl_nports * sizeof (ib_guid_t), 32647c478bd9Sstevel@tonic-gate KM_SLEEP); 32657c478bd9Sstevel@tonic-gate 32667c478bd9Sstevel@tonic-gate for (portnum = 0; portnum < hca_list->hl_nports; 32677c478bd9Sstevel@tonic-gate portnum++) { 32687c478bd9Sstevel@tonic-gate port_guids[portnum] = (hca_list-> 32697c478bd9Sstevel@tonic-gate hl_port_attr[portnum]).pa_port_guid; 32707c478bd9Sstevel@tonic-gate } 32717c478bd9Sstevel@tonic-gate 32727c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, 32737c478bd9Sstevel@tonic-gate child_dip, "port-guids", (int64_t *)port_guids, 32747c478bd9Sstevel@tonic-gate hca_list->hl_nports) != DDI_PROP_SUCCESS) { 32757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32767c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guids " 32777c478bd9Sstevel@tonic-gate "create failed"); 32787c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 32797c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 32807c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 32817c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32827c478bd9Sstevel@tonic-gate } 32837c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports * 32847c478bd9Sstevel@tonic-gate sizeof (ib_guid_t)); 32857c478bd9Sstevel@tonic-gate } 32867c478bd9Sstevel@tonic-gate 32877c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 32887c478bd9Sstevel@tonic-gate "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) { 32897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 32907c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: num-ports update failed"); 32917c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 32927c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 32937c478bd9Sstevel@tonic-gate } 32947c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list); 32957c478bd9Sstevel@tonic-gate } 32967c478bd9Sstevel@tonic-gate 32977c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip, 32987c478bd9Sstevel@tonic-gate "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) { 32997c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33007c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca-guid update failed"); 33017c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33027c478bd9Sstevel@tonic-gate } 33037c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33047c478bd9Sstevel@tonic-gate "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) { 33057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33067c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: product-id update failed"); 33077c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33087c478bd9Sstevel@tonic-gate } 33097c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, 33107c478bd9Sstevel@tonic-gate "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) { 33117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33127c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: vendor-id update failed"); 33137c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33147c478bd9Sstevel@tonic-gate } 33157c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version", 33167c478bd9Sstevel@tonic-gate port_attr->pa_dev_version) != DDI_PROP_SUCCESS) { 33177c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33187c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: device-version update failed"); 33197c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 33207c478bd9Sstevel@tonic-gate } 33217c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 33227c478bd9Sstevel@tonic-gate } 33237c478bd9Sstevel@tonic-gate 33247c478bd9Sstevel@tonic-gate 33257c478bd9Sstevel@tonic-gate /* 33267c478bd9Sstevel@tonic-gate * ibnex_str2int() 33277c478bd9Sstevel@tonic-gate * Utility function that converts a string of length "len" to 33287c478bd9Sstevel@tonic-gate * integer. 33297c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 33307c478bd9Sstevel@tonic-gate */ 33317c478bd9Sstevel@tonic-gate static int 33327c478bd9Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret) 33337c478bd9Sstevel@tonic-gate { 33347c478bd9Sstevel@tonic-gate int intval = 0, ii; 33357c478bd9Sstevel@tonic-gate 33367c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c); 33377c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 33387c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 33397c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 33407c478bd9Sstevel@tonic-gate intval = intval * 10 +c[ii] - '0'; 33417c478bd9Sstevel@tonic-gate else { 33427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33437c478bd9Sstevel@tonic-gate "\tstr2int: Invalid integer string %s..", c); 33447c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 33457c478bd9Sstevel@tonic-gate break; 33467c478bd9Sstevel@tonic-gate } 33477c478bd9Sstevel@tonic-gate } 33487c478bd9Sstevel@tonic-gate 33497c478bd9Sstevel@tonic-gate return (intval); 33507c478bd9Sstevel@tonic-gate } 33517c478bd9Sstevel@tonic-gate 33527c478bd9Sstevel@tonic-gate 33537c478bd9Sstevel@tonic-gate /* 33547c478bd9Sstevel@tonic-gate * ibnex_str2hex() 33557c478bd9Sstevel@tonic-gate * Utility functions that converts a string of length "len" to 33567c478bd9Sstevel@tonic-gate * hex value. Note. This function does not handle strings which 33577c478bd9Sstevel@tonic-gate * string length more than 8 bytes. 33587c478bd9Sstevel@tonic-gate * 33597c478bd9Sstevel@tonic-gate */ 33607c478bd9Sstevel@tonic-gate uint64_t 33617c478bd9Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret) 33627c478bd9Sstevel@tonic-gate { 33637c478bd9Sstevel@tonic-gate uint64_t hex = 0, ii; 33647c478bd9Sstevel@tonic-gate 33657c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS; 33667c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) { 33677c478bd9Sstevel@tonic-gate hex = (ii == 0) ? hex : (hex << 4); 33687c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9')) 33697c478bd9Sstevel@tonic-gate hex |= c[ii] - '0'; 33707c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'a') && (c[ii] <= 'f')) 33717c478bd9Sstevel@tonic-gate hex |= c[ii] - 'a' + 10; 33727c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'A') && (c[ii] <= 'F')) 33737c478bd9Sstevel@tonic-gate hex |= c[ii] - 'A' + 10; 33747c478bd9Sstevel@tonic-gate else { 33757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 33767c478bd9Sstevel@tonic-gate "\tstr2hex: Invalid integer string"); 33777c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE; 33787c478bd9Sstevel@tonic-gate break; 33797c478bd9Sstevel@tonic-gate } 33807c478bd9Sstevel@tonic-gate } 33817c478bd9Sstevel@tonic-gate 33827c478bd9Sstevel@tonic-gate return (hex); 33837c478bd9Sstevel@tonic-gate } 33847c478bd9Sstevel@tonic-gate 33857c478bd9Sstevel@tonic-gate 33867c478bd9Sstevel@tonic-gate /* 33877c478bd9Sstevel@tonic-gate * ibnex_create_port_compatible_prop() 33887c478bd9Sstevel@tonic-gate * Creates 'Compatibility' property for port / HCA_SVC device nodes 33897c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE 33907c478bd9Sstevel@tonic-gate */ 33917c478bd9Sstevel@tonic-gate static int 33927c478bd9Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip, 33937c478bd9Sstevel@tonic-gate char *comm_svcp, ibdm_port_attr_t *port_attr) 33947c478bd9Sstevel@tonic-gate { 33957c478bd9Sstevel@tonic-gate int rval, i; 33967c478bd9Sstevel@tonic-gate char *temp; 33977c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES]; 33987c478bd9Sstevel@tonic-gate 33997c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin"); 34007c478bd9Sstevel@tonic-gate /* 34017c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below: 34027c478bd9Sstevel@tonic-gate * Compatible Strings : 34037c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>v<revision>.<service name>. 34047c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>.<service name>. 34057c478bd9Sstevel@tonic-gate * 3. ib.<service name> 34067c478bd9Sstevel@tonic-gate * Leading zeros must be present 34077c478bd9Sstevel@tonic-gate */ 34087c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP); 34097c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) { 34107c478bd9Sstevel@tonic-gate compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN); 34117c478bd9Sstevel@tonic-gate } 34127c478bd9Sstevel@tonic-gate 34137c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN, 34147c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x.%s", 34157c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 34167c478bd9Sstevel@tonic-gate port_attr->pa_dev_version, comm_svcp); 34177c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN, 34187c478bd9Sstevel@tonic-gate "ib.V%06xP%08x.%s", 34197c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid, 34207c478bd9Sstevel@tonic-gate comm_svcp); 34217c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN, 34227c478bd9Sstevel@tonic-gate "ib.%s", comm_svcp); 34237c478bd9Sstevel@tonic-gate 34247c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) 34257c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]); 34267c478bd9Sstevel@tonic-gate 34277c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip, 34287c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES); 34297c478bd9Sstevel@tonic-gate 34307c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) { 34317c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 34327c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 34337c478bd9Sstevel@tonic-gate } 34347c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ); 34357c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 34367c478bd9Sstevel@tonic-gate } 34377c478bd9Sstevel@tonic-gate 34387c478bd9Sstevel@tonic-gate 34397c478bd9Sstevel@tonic-gate /* 34407c478bd9Sstevel@tonic-gate * ibnex_delete_port_node_data() 34417c478bd9Sstevel@tonic-gate * Delete the parent private node data from the linked list 34427c478bd9Sstevel@tonic-gate * Deallocate the memory of the port/ioc attributes 34437c478bd9Sstevel@tonic-gate * Deallocate the memory of the node data 34447c478bd9Sstevel@tonic-gate */ 34457c478bd9Sstevel@tonic-gate static void 34467c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node) 34477c478bd9Sstevel@tonic-gate { 34487c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 34497c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) 34507c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = NULL; 34517c478bd9Sstevel@tonic-gate else if (node->node_next == NULL) 34527c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL; 34537c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) { 34547c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL; 34557c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node->node_next; 34567c478bd9Sstevel@tonic-gate } else { 34577c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next; 34587c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev; 34597c478bd9Sstevel@tonic-gate } 34607c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 34617c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t)); 34627c478bd9Sstevel@tonic-gate } 34637c478bd9Sstevel@tonic-gate 34647c478bd9Sstevel@tonic-gate 34657c478bd9Sstevel@tonic-gate /* 34667c478bd9Sstevel@tonic-gate * ibnex_is_node_data_present() 34677c478bd9Sstevel@tonic-gate * Checks whether ibnex_node_t is created already 34687c478bd9Sstevel@tonic-gate * Returns ibnex_node_data_t if found, otherwise NULL 34697c478bd9Sstevel@tonic-gate */ 34707c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 34717c478bd9Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr, 34727c478bd9Sstevel@tonic-gate int index, ib_pkey_t pkey) 34737c478bd9Sstevel@tonic-gate { 34747c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 34757c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 34767c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 34777c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr; 34787c478bd9Sstevel@tonic-gate 34797c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL; 34807c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 34817c478bd9Sstevel@tonic-gate if (nodep->node_data.ioc_node.ioc_guid == 34827c478bd9Sstevel@tonic-gate ioc_infop->ioc_profile.ioc_guid) { 34837c478bd9Sstevel@tonic-gate return (nodep); 34847c478bd9Sstevel@tonic-gate } 34857c478bd9Sstevel@tonic-gate } 34867c478bd9Sstevel@tonic-gate 34877c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 34887c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep; 34897c478bd9Sstevel@tonic-gate nodep = nodep->node_next) 34907c478bd9Sstevel@tonic-gate if (strcmp(nodep->node_data.pseudo_node. 34917c478bd9Sstevel@tonic-gate pseudo_node_addr, (char *)attr) == 0) 34927c478bd9Sstevel@tonic-gate return (nodep); 34937c478bd9Sstevel@tonic-gate 34947c478bd9Sstevel@tonic-gate } else { 34957c478bd9Sstevel@tonic-gate ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr; 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_port_node_head; nodep != NULL; 34987c478bd9Sstevel@tonic-gate nodep = nodep->node_next) { 34997c478bd9Sstevel@tonic-gate if ((nodep->node_data.port_node.port_guid == 35007c478bd9Sstevel@tonic-gate pattrp->pa_port_guid) && 35017c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_commsvc_idx == 35027c478bd9Sstevel@tonic-gate index) && 35037c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_pkey == pkey)) { 35047c478bd9Sstevel@tonic-gate return (nodep); 35057c478bd9Sstevel@tonic-gate } 35067c478bd9Sstevel@tonic-gate } 35077c478bd9Sstevel@tonic-gate } 35087c478bd9Sstevel@tonic-gate return (NULL); 35097c478bd9Sstevel@tonic-gate } 35107c478bd9Sstevel@tonic-gate 35117c478bd9Sstevel@tonic-gate /* 35127c478bd9Sstevel@tonic-gate * ibnex_lookup_unit_address_prop: 35137c478bd9Sstevel@tonic-gate * 35149d3d2ed0Shiremath * If property with name is found, return its value 35157c478bd9Sstevel@tonic-gate * otherwise return NULL. 35167c478bd9Sstevel@tonic-gate */ 35177c478bd9Sstevel@tonic-gate static char * 35189d3d2ed0Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name) 35197c478bd9Sstevel@tonic-gate { 35207c478bd9Sstevel@tonic-gate ddi_prop_t *propp; 35217c478bd9Sstevel@tonic-gate 35229d3d2ed0Shiremath /* Search the list of properties for name */ 35237c478bd9Sstevel@tonic-gate for (propp = head; propp != NULL; propp = propp->prop_next) { 35249d3d2ed0Shiremath if (strcmp(propp->prop_name, name) != 0) 35257c478bd9Sstevel@tonic-gate continue; 35269d3d2ed0Shiremath /* named property should be valid and have a value */ 35277c478bd9Sstevel@tonic-gate if (propp->prop_len <= 1) 35287c478bd9Sstevel@tonic-gate break; 35297c478bd9Sstevel@tonic-gate return ((char *)propp->prop_val); 35307c478bd9Sstevel@tonic-gate } 35317c478bd9Sstevel@tonic-gate 35327c478bd9Sstevel@tonic-gate return ((char *)0); 35337c478bd9Sstevel@tonic-gate } 35347c478bd9Sstevel@tonic-gate 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate /* 35377c478bd9Sstevel@tonic-gate * ibnex_pseudo_initnodes() 35387c478bd9Sstevel@tonic-gate * This routine is specific to pseudo node information handling 35397c478bd9Sstevel@tonic-gate * Creates a ibnex_node_data_t all pseudo nodes children of ibnex 35407c478bd9Sstevel@tonic-gate */ 35417c478bd9Sstevel@tonic-gate void 35427c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes() 35437c478bd9Sstevel@tonic-gate { 35447c478bd9Sstevel@tonic-gate int pnam_len, len; 35457c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep; 35467c478bd9Sstevel@tonic-gate struct hwc_spec *list, *spec; 35477c478bd9Sstevel@tonic-gate char *node_addr, *temp, *unit_addr; 35489d3d2ed0Shiremath char *node_type; 35497c478bd9Sstevel@tonic-gate 35507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes"); 35517c478bd9Sstevel@tonic-gate 35527c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 35537c478bd9Sstevel@tonic-gate /* 35547c478bd9Sstevel@tonic-gate * get a list of all "pseudo" children of "ib". 35557c478bd9Sstevel@tonic-gate * for these children initialize/allocate an internal 35567c478bd9Sstevel@tonic-gate * ibnex_node_data_t. 35577c478bd9Sstevel@tonic-gate */ 35587c478bd9Sstevel@tonic-gate list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1); 35597c478bd9Sstevel@tonic-gate for (spec = list; spec != NULL; spec = spec->hwc_next) { 35607c478bd9Sstevel@tonic-gate if (spec->hwc_devi_sys_prop_ptr == NULL) 35617c478bd9Sstevel@tonic-gate continue; 35627c478bd9Sstevel@tonic-gate 35639d3d2ed0Shiremath /* Check "ib-node-type" property for IOC .conf */ 35649d3d2ed0Shiremath node_type = ibnex_lookup_named_prop( 35659d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "ib-node-type"); 35669d3d2ed0Shiremath 35677c478bd9Sstevel@tonic-gate /* "unit-address" property should be present */ 35689d3d2ed0Shiremath temp = ibnex_lookup_named_prop( 35699d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "unit-address"); 35707c478bd9Sstevel@tonic-gate if (temp == NULL) 35717c478bd9Sstevel@tonic-gate continue; 35727c478bd9Sstevel@tonic-gate 35737c478bd9Sstevel@tonic-gate pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2; 35747c478bd9Sstevel@tonic-gate 35757c478bd9Sstevel@tonic-gate node_addr = kmem_zalloc(pnam_len, KM_SLEEP); 35767c478bd9Sstevel@tonic-gate 35777c478bd9Sstevel@tonic-gate (void) snprintf(node_addr, 35787c478bd9Sstevel@tonic-gate pnam_len, "%s,%s", spec->hwc_devi_name, temp); 35797c478bd9Sstevel@tonic-gate 35807c478bd9Sstevel@tonic-gate nodep = ibnex_is_node_data_present( 35817c478bd9Sstevel@tonic-gate IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0); 35827c478bd9Sstevel@tonic-gate 35837c478bd9Sstevel@tonic-gate if (nodep) { 35847c478bd9Sstevel@tonic-gate kmem_free(node_addr, pnam_len); 35857c478bd9Sstevel@tonic-gate continue; 35867c478bd9Sstevel@tonic-gate } 35877c478bd9Sstevel@tonic-gate 35887c478bd9Sstevel@tonic-gate nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE, 35897c478bd9Sstevel@tonic-gate (void *)spec->hwc_devi_name, 0, 0); 35907c478bd9Sstevel@tonic-gate 35917c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_node_addr = node_addr; 35927c478bd9Sstevel@tonic-gate (void) snprintf(nodep->node_data. 35937c478bd9Sstevel@tonic-gate pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr); 35947c478bd9Sstevel@tonic-gate 35957c478bd9Sstevel@tonic-gate len = strlen(temp) + 1; 35967c478bd9Sstevel@tonic-gate unit_addr = (char *)kmem_alloc(len, KM_SLEEP); 35977c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr; 35987c478bd9Sstevel@tonic-gate (void) snprintf(unit_addr, len, "%s", temp); 35997c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr_len = len; 36007c478bd9Sstevel@tonic-gate 36019d3d2ed0Shiremath if (node_type && strcmp(node_type, "merge") == 0) 36029d3d2ed0Shiremath nodep->node_data.pseudo_node.pseudo_merge_node = 1; 36039d3d2ed0Shiremath 36047c478bd9Sstevel@tonic-gate /* Mark this as a new psuedo node */ 36057c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_new_node = 1; 36067c478bd9Sstevel@tonic-gate 36077c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s" 36087c478bd9Sstevel@tonic-gate " : drv name = %s", unit_addr, spec->hwc_devi_name); 36097c478bd9Sstevel@tonic-gate } 36107c478bd9Sstevel@tonic-gate hwc_free_spec_list(list); 36117c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 36127c478bd9Sstevel@tonic-gate } 36137c478bd9Sstevel@tonic-gate 36147c478bd9Sstevel@tonic-gate 36157c478bd9Sstevel@tonic-gate /* 36167c478bd9Sstevel@tonic-gate * ibnex_init_child_nodedata() 36177c478bd9Sstevel@tonic-gate * 36187c478bd9Sstevel@tonic-gate * Allocate memory for the parent private data for device node 36197c478bd9Sstevel@tonic-gate * Initializes the parent private child device node data. 36207c478bd9Sstevel@tonic-gate * Returns pointer to the parent private data 36217c478bd9Sstevel@tonic-gate */ 36227c478bd9Sstevel@tonic-gate static ibnex_node_data_t * 36237c478bd9Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index, 36247c478bd9Sstevel@tonic-gate ib_pkey_t pkey) 36257c478bd9Sstevel@tonic-gate { 36267c478bd9Sstevel@tonic-gate char *devi_name; 36277c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 36287c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_node; 36297c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 36307c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile; 36317c478bd9Sstevel@tonic-gate 36327c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 36337c478bd9Sstevel@tonic-gate 36347c478bd9Sstevel@tonic-gate node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP); 36357c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING; 36367c478bd9Sstevel@tonic-gate node_data->node_type = node_type; 36377c478bd9Sstevel@tonic-gate 36387c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) { 36397c478bd9Sstevel@tonic-gate ioc_info = (ibdm_ioc_info_t *)attr; 36407c478bd9Sstevel@tonic-gate ioc_profile = &ioc_info->ioc_profile; 36417c478bd9Sstevel@tonic-gate ioc_node = &node_data->node_data.ioc_node; 36427c478bd9Sstevel@tonic-gate 36437c478bd9Sstevel@tonic-gate ioc_node->iou_guid = ioc_info->ioc_iou_guid; 36447c478bd9Sstevel@tonic-gate ioc_node->ioc_guid = ioc_profile->ioc_guid; 36457c478bd9Sstevel@tonic-gate (void) strncpy(ioc_node->ioc_id_string, 36467c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string, 36477c478bd9Sstevel@tonic-gate IB_DM_IOC_ID_STRING_LEN); 36487c478bd9Sstevel@tonic-gate ioc_node->ioc_ngids = ioc_info->ioc_nportgids; 36497c478bd9Sstevel@tonic-gate 36507c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_ioc_node_head; 36517c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 36527c478bd9Sstevel@tonic-gate if (ibnex.ibnex_ioc_node_head) 36537c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head->node_prev = node_data; 36547c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node_data; 36557c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) { 36567c478bd9Sstevel@tonic-gate devi_name = (char *)attr; 36577c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_devi_name = 36587c478bd9Sstevel@tonic-gate kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP); 36597c478bd9Sstevel@tonic-gate (void) strncpy(node_data->node_data.pseudo_node. 36607c478bd9Sstevel@tonic-gate pseudo_devi_name, devi_name, strlen(devi_name)); 36617c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_pseudo_node_head; 36627c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 36637c478bd9Sstevel@tonic-gate if (ibnex.ibnex_pseudo_node_head) 36647c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head->node_prev = node_data; 36657c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head = node_data; 36667c478bd9Sstevel@tonic-gate } else { 36677c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_hcaguid = 36687c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_hca_guid; 36697c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_guid = 36707c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_guid; 36717c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_num = 36727c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_num; 36737c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_commsvc_idx = index; 36747c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_pkey = pkey; 36757c478bd9Sstevel@tonic-gate 36767c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_port_node_head; 36777c478bd9Sstevel@tonic-gate node_data->node_prev = NULL; 36787c478bd9Sstevel@tonic-gate if (ibnex.ibnex_port_node_head) 36797c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head->node_prev = node_data; 36807c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node_data; 36817c478bd9Sstevel@tonic-gate } 36827c478bd9Sstevel@tonic-gate return (node_data); 36837c478bd9Sstevel@tonic-gate } 36847c478bd9Sstevel@tonic-gate 36857c478bd9Sstevel@tonic-gate static int 36867c478bd9Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, 36877c478bd9Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *cookie) 36887c478bd9Sstevel@tonic-gate { 36897c478bd9Sstevel@tonic-gate int rc; 36907c478bd9Sstevel@tonic-gate 36917c478bd9Sstevel@tonic-gate 36927c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)", 36937c478bd9Sstevel@tonic-gate dip, rdip, eventname, cookie); 36947c478bd9Sstevel@tonic-gate 36957c478bd9Sstevel@tonic-gate rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl, 36967c478bd9Sstevel@tonic-gate rdip, eventname, cookie, NDI_EVENT_NOPASS); 36977c478bd9Sstevel@tonic-gate if (rc == NDI_SUCCESS) { 36987c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 36997c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = *cookie; 37007c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37017c478bd9Sstevel@tonic-gate } 37027c478bd9Sstevel@tonic-gate 37037c478bd9Sstevel@tonic-gate return (rc); 37047c478bd9Sstevel@tonic-gate } 37057c478bd9Sstevel@tonic-gate 37067c478bd9Sstevel@tonic-gate static int 37077c478bd9Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 37087c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip, 37097c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *arg, void *bus_impldata), 37107c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id) 37117c478bd9Sstevel@tonic-gate { 37127c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 37137c478bd9Sstevel@tonic-gate "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)", 37147c478bd9Sstevel@tonic-gate dip, rdip, cookie, callback, arg, cb_id); 37157c478bd9Sstevel@tonic-gate 37167c478bd9Sstevel@tonic-gate return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl, 37177c478bd9Sstevel@tonic-gate rdip, cookie, callback, arg, NDI_SLEEP, cb_id)); 37187c478bd9Sstevel@tonic-gate } 37197c478bd9Sstevel@tonic-gate 37207c478bd9Sstevel@tonic-gate static int 37217c478bd9Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) 37227c478bd9Sstevel@tonic-gate { 37237c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)", 37247c478bd9Sstevel@tonic-gate dip, cb_id); 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl, 37277c478bd9Sstevel@tonic-gate cb_id)); 37287c478bd9Sstevel@tonic-gate } 37297c478bd9Sstevel@tonic-gate 37307c478bd9Sstevel@tonic-gate static int 37317c478bd9Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip, 37327c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata) 37337c478bd9Sstevel@tonic-gate { 37347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)", 37357c478bd9Sstevel@tonic-gate dip, rdip, cookie, bus_impldata); 37367c478bd9Sstevel@tonic-gate 37377c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip, 37387c478bd9Sstevel@tonic-gate cookie, bus_impldata)); 37397c478bd9Sstevel@tonic-gate } 37407c478bd9Sstevel@tonic-gate 37417c478bd9Sstevel@tonic-gate /* 37427c478bd9Sstevel@tonic-gate * ibnex_reprobe_ioc_dev() 37437c478bd9Sstevel@tonic-gate * 37447c478bd9Sstevel@tonic-gate * This could be called as a result of ibt_reprobe_dev request or 37457c478bd9Sstevel@tonic-gate * cfgadm command. The function is called from a taskq in case of 37467c478bd9Sstevel@tonic-gate * ibt_reprobe_dev and from user context for cfgadm command. 37477c478bd9Sstevel@tonic-gate * 37487c478bd9Sstevel@tonic-gate * This function reprobes the properties for one IOC dip. 37497c478bd9Sstevel@tonic-gate * 37507c478bd9Sstevel@tonic-gate * node_reprobe_state should be set before calling this function. 37517c478bd9Sstevel@tonic-gate */ 37527c478bd9Sstevel@tonic-gate void 37537c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg) 37547c478bd9Sstevel@tonic-gate { 37557c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 37567c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 37577c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_data; 37587c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info; 37597c478bd9Sstevel@tonic-gate 37607c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 37617c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 37627c478bd9Sstevel@tonic-gate 37637c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 37647c478bd9Sstevel@tonic-gate ASSERT(node_data); 37657c478bd9Sstevel@tonic-gate 37667c478bd9Sstevel@tonic-gate if (node_data->node_dip == NULL) { 37677c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip"); 37687c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37697c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 37707c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37717c478bd9Sstevel@tonic-gate return; 37727c478bd9Sstevel@tonic-gate } 37737c478bd9Sstevel@tonic-gate ioc_data = &(node_data->node_data.ioc_node); 37747c478bd9Sstevel@tonic-gate 37757c478bd9Sstevel@tonic-gate /* Reprobe the IOC */ 37767c478bd9Sstevel@tonic-gate ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid, 37777c478bd9Sstevel@tonic-gate 1); 37787c478bd9Sstevel@tonic-gate if (ioc_info == NULL) { 37797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe"); 37807c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37817c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 1); 37827c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37837c478bd9Sstevel@tonic-gate return; 37847c478bd9Sstevel@tonic-gate } 37857c478bd9Sstevel@tonic-gate 37867c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 37877c478bd9Sstevel@tonic-gate if (node_data->node_dip) 37887c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info); 37897c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 37907c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 37917c478bd9Sstevel@tonic-gate 37927c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info); 37937c478bd9Sstevel@tonic-gate } 37947c478bd9Sstevel@tonic-gate 37957c478bd9Sstevel@tonic-gate /* 37967c478bd9Sstevel@tonic-gate * ibnex_reprobe_all() 37977c478bd9Sstevel@tonic-gate * 37987c478bd9Sstevel@tonic-gate * This could be called as a result of cfgadm command. The function 37997c478bd9Sstevel@tonic-gate * is called from user context. 38007c478bd9Sstevel@tonic-gate * 38017c478bd9Sstevel@tonic-gate * This function reprobes the properties for all IOC dips. 38027c478bd9Sstevel@tonic-gate * 38037c478bd9Sstevel@tonic-gate * ibnex_reprobe_state should be set before calling this function. 38047c478bd9Sstevel@tonic-gate */ 38057c478bd9Sstevel@tonic-gate void 38067c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_all() 38077c478bd9Sstevel@tonic-gate { 38087c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 38097c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info_list, *ioc; 38107c478bd9Sstevel@tonic-gate 38117c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */ 38127c478bd9Sstevel@tonic-gate 38137c478bd9Sstevel@tonic-gate /* Sweep the fabric */ 38147c478bd9Sstevel@tonic-gate ioc = ioc_info_list = ibdm_ibnex_get_ioc_list( 38157c478bd9Sstevel@tonic-gate IBDM_IBNEX_REPROBE_ALL); 38167c478bd9Sstevel@tonic-gate if (ioc_info_list == NULL) { 38177c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38187c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 38197c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38207c478bd9Sstevel@tonic-gate return; 38217c478bd9Sstevel@tonic-gate } 38227c478bd9Sstevel@tonic-gate 38237c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38247c478bd9Sstevel@tonic-gate while (ioc_info_list) { 38257c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE, 38267c478bd9Sstevel@tonic-gate ioc_info_list, 0, 0)) != NULL && 38277c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) { 38287c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info_list); 38297c478bd9Sstevel@tonic-gate } 38307c478bd9Sstevel@tonic-gate ioc_info_list = ioc_info_list->ioc_next; 38317c478bd9Sstevel@tonic-gate } 38327c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all(); 38337c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38347c478bd9Sstevel@tonic-gate 38357c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc); 38367c478bd9Sstevel@tonic-gate } 38377c478bd9Sstevel@tonic-gate 38387c478bd9Sstevel@tonic-gate /* 38397c478bd9Sstevel@tonic-gate * Update the properties, if it has modified and notify IBTF client. 38407c478bd9Sstevel@tonic-gate */ 38417c478bd9Sstevel@tonic-gate static void 38427c478bd9Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info) 38437c478bd9Sstevel@tonic-gate { 38447c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data; 38457c478bd9Sstevel@tonic-gate dev_info_t *dip = node_data->node_dip; 38467c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie; 38477c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc; 38487c478bd9Sstevel@tonic-gate 38497c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex)); 38507c478bd9Sstevel@tonic-gate 38517c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 38527c478bd9Sstevel@tonic-gate 38537c478bd9Sstevel@tonic-gate ioc = &node_data->node_data.ioc_node; 38547c478bd9Sstevel@tonic-gate 38557c478bd9Sstevel@tonic-gate evt_data = ioc_info->ioc_info_updated; 38567c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie; 38577c478bd9Sstevel@tonic-gate 38587c478bd9Sstevel@tonic-gate /* 38597c478bd9Sstevel@tonic-gate * For a disconnected IOC : 38607c478bd9Sstevel@tonic-gate * Store the ioc_profile for supplying cfgadm info 38617c478bd9Sstevel@tonic-gate * ibdm maintains no info of disconnected IOC 38627c478bd9Sstevel@tonic-gate * 38637c478bd9Sstevel@tonic-gate * For reconnected IOC : 38647c478bd9Sstevel@tonic-gate * ibdm has info of previous service entries 38657c478bd9Sstevel@tonic-gate * ioc_profile maintained by ibnexus is used to 38667c478bd9Sstevel@tonic-gate * update ib_srv_prop_updated. 38677c478bd9Sstevel@tonic-gate * Free the ibnex maintained ioc_profile 38687c478bd9Sstevel@tonic-gate */ 38697c478bd9Sstevel@tonic-gate if (ioc_info->ioc_nportgids == 0) { 38707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 38717c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC disconnected"); 38727c478bd9Sstevel@tonic-gate ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc( 38737c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP); 38747c478bd9Sstevel@tonic-gate bcopy(&ioc_info->ioc_profile, ioc->ioc_profile, 38757c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t)); 38767c478bd9Sstevel@tonic-gate 38777c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs++; 38787c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 && 38797c478bd9Sstevel@tonic-gate ioc->ioc_profile != NULL) { 38807c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 38817c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC reconnected"); 38827c478bd9Sstevel@tonic-gate if (ioc->ioc_profile->ioc_service_entries != 38837c478bd9Sstevel@tonic-gate ioc_info->ioc_profile.ioc_service_entries) 38847c478bd9Sstevel@tonic-gate evt_data.ib_srv_prop_updated = 1; 38857c478bd9Sstevel@tonic-gate 38867c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs--; 38877c478bd9Sstevel@tonic-gate kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t)); 38887c478bd9Sstevel@tonic-gate ioc->ioc_profile = NULL; 38897c478bd9Sstevel@tonic-gate } 38907c478bd9Sstevel@tonic-gate 38917c478bd9Sstevel@tonic-gate /* Update the properties that have changed */ 38927c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 38937c478bd9Sstevel@tonic-gate if (evt_data.ib_gid_prop_updated) { 38947c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(dip, ioc_info) != 38957c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) { 38967c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 38977c478bd9Sstevel@tonic-gate return; 38987c478bd9Sstevel@tonic-gate } 38997c478bd9Sstevel@tonic-gate } 39007c478bd9Sstevel@tonic-gate if (evt_data.ib_srv_prop_updated) { 39017c478bd9Sstevel@tonic-gate if (ioc_info->ioc_profile.ioc_service_entries != 0 && 39027c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(dip, ioc_info) != 39037c478bd9Sstevel@tonic-gate IBNEX_SUCCESS)) { 39047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39057c478bd9Sstevel@tonic-gate return; 39067c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_profile.ioc_service_entries == 0) { 39077c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 39087c478bd9Sstevel@tonic-gate "service-id"); 39097c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip, 39107c478bd9Sstevel@tonic-gate "service-name"); 39117c478bd9Sstevel@tonic-gate } 39127c478bd9Sstevel@tonic-gate } 39137c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39147c478bd9Sstevel@tonic-gate ioc->ioc_ngids = ioc_info->ioc_nportgids; 39157c478bd9Sstevel@tonic-gate 39167c478bd9Sstevel@tonic-gate /* 39177c478bd9Sstevel@tonic-gate * Post an event if : 39187c478bd9Sstevel@tonic-gate * 1. Properites have changed or NOTIFY_ALWAYS is set. 39197c478bd9Sstevel@tonic-gate * 2. child dip is configured and a valid cookie for 39207c478bd9Sstevel@tonic-gate * IB_PROP_UPDATE_EVENT. 39217c478bd9Sstevel@tonic-gate */ 39227c478bd9Sstevel@tonic-gate if ((evt_data.ib_prop_updated != 0 || 39237c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state & 39247c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) && 39257c478bd9Sstevel@tonic-gate ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) && 39267c478bd9Sstevel@tonic-gate (evt_cookie != NULL))) { 39277c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 39287c478bd9Sstevel@tonic-gate 39297c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, dip, 39307c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS) 39317c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", 39327c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n"); 39337c478bd9Sstevel@tonic-gate 39347c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39357c478bd9Sstevel@tonic-gate } 39367c478bd9Sstevel@tonic-gate 39377c478bd9Sstevel@tonic-gate /* 39387c478bd9Sstevel@tonic-gate * Cleanup node_reprobe_state, for ibt_reprobe_dev 39397c478bd9Sstevel@tonic-gate * requests, when reprobe all / node reprobe is in 39407c478bd9Sstevel@tonic-gate * progress. ibnex_reprobe_ioc_dev is not called 39417c478bd9Sstevel@tonic-gate * in this case. 39427c478bd9Sstevel@tonic-gate */ 39437c478bd9Sstevel@tonic-gate if (node_data->node_reprobe_state == 39447c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) 39457c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0); 39467c478bd9Sstevel@tonic-gate } 39477c478bd9Sstevel@tonic-gate 39487c478bd9Sstevel@tonic-gate static ibnex_rval_t 39497c478bd9Sstevel@tonic-gate ibnex_unique_svcname(char *svcname) 39507c478bd9Sstevel@tonic-gate { 39517c478bd9Sstevel@tonic-gate int i; 39527c478bd9Sstevel@tonic-gate 39537c478bd9Sstevel@tonic-gate /* Check Port Services */ 39547c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++) 39557c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname, 39567c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[i], 4) == 0) 39577c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 39587c478bd9Sstevel@tonic-gate 39597c478bd9Sstevel@tonic-gate /* Check VPPA Services */ 39607c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++) 39617c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname, 39627c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0) 39637c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 39647c478bd9Sstevel@tonic-gate 39657c478bd9Sstevel@tonic-gate /* Check HCA_SVC Services */ 39667c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++) 39677c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname, 39687c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0) 39697c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE); 39707c478bd9Sstevel@tonic-gate 39717c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS); 39727c478bd9Sstevel@tonic-gate } 39737c478bd9Sstevel@tonic-gate 39747c478bd9Sstevel@tonic-gate static void 39757c478bd9Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg) 39767c478bd9Sstevel@tonic-gate { 39777c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg; 39787c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data; 39797c478bd9Sstevel@tonic-gate 39807c478bd9Sstevel@tonic-gate ASSERT(dip != NULL); 39817c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip); 39827c478bd9Sstevel@tonic-gate ASSERT(node_data); 39837c478bd9Sstevel@tonic-gate 39847c478bd9Sstevel@tonic-gate /* 39857c478bd9Sstevel@tonic-gate * Return success if: 39867c478bd9Sstevel@tonic-gate * 1. Reprobe for all nodes are in progress 39877c478bd9Sstevel@tonic-gate * 2. Reprobe for this node is in progress. 39887c478bd9Sstevel@tonic-gate * The reprobe in progress will complete eventually and 39897c478bd9Sstevel@tonic-gate * update the properties, if required. 39907c478bd9Sstevel@tonic-gate */ 39917c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex); 39927c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state != 0 || 39937c478bd9Sstevel@tonic-gate node_data->node_reprobe_state != 0) { 39947c478bd9Sstevel@tonic-gate /* 39957c478bd9Sstevel@tonic-gate * Setting NOTIFY_ALWAYS to ensure that 39967c478bd9Sstevel@tonic-gate * DDI event is delivered always for 39977c478bd9Sstevel@tonic-gate * ibt_reprobe_dev 39987c478bd9Sstevel@tonic-gate */ 39997c478bd9Sstevel@tonic-gate node_data->node_reprobe_state |= 40007c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 40017c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40027c478bd9Sstevel@tonic-gate return; 40037c478bd9Sstevel@tonic-gate } 40047c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 40057c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS; 40067c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex); 40077c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(arg); 40087c478bd9Sstevel@tonic-gate } 40097c478bd9Sstevel@tonic-gate 40107c478bd9Sstevel@tonic-gate 40117c478bd9Sstevel@tonic-gate /* 40127c478bd9Sstevel@tonic-gate * MPxIO pathmangement routines. Currently IB nexus does not support 40137c478bd9Sstevel@tonic-gate * any kind of pathmangement. So, just return success to make MPxIO 40147c478bd9Sstevel@tonic-gate * framework happy. 40157c478bd9Sstevel@tonic-gate */ 40167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 40177c478bd9Sstevel@tonic-gate static int 40187c478bd9Sstevel@tonic-gate ib_vhci_pi_init(dev_info_t *dip, mdi_pathinfo_t *pip, int flag) 40197c478bd9Sstevel@tonic-gate { 40207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", dip, pip); 40217c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 40227c478bd9Sstevel@tonic-gate } 40237c478bd9Sstevel@tonic-gate 40247c478bd9Sstevel@tonic-gate 40257c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 40267c478bd9Sstevel@tonic-gate static int 40277c478bd9Sstevel@tonic-gate ib_vhci_pi_uninit(dev_info_t *dip, mdi_pathinfo_t *pip, int flag) 40287c478bd9Sstevel@tonic-gate { 40297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", dip, pip); 40307c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 40317c478bd9Sstevel@tonic-gate } 40327c478bd9Sstevel@tonic-gate 40337c478bd9Sstevel@tonic-gate 40347c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 40357c478bd9Sstevel@tonic-gate static int 40367c478bd9Sstevel@tonic-gate ib_vhci_pi_state_change(dev_info_t *dip, mdi_pathinfo_t *pip, 40377c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t arg1, int arg2) 40387c478bd9Sstevel@tonic-gate { 40397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", 40407c478bd9Sstevel@tonic-gate "\tpi_state_change: dip %p pip %p state %x", dip, pip, state); 40417c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 40427c478bd9Sstevel@tonic-gate } 40437c478bd9Sstevel@tonic-gate 40447c478bd9Sstevel@tonic-gate 40457c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 40467c478bd9Sstevel@tonic-gate static int 40477c478bd9Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg) 40487c478bd9Sstevel@tonic-gate { 40497c478bd9Sstevel@tonic-gate return (MDI_SUCCESS); 40507c478bd9Sstevel@tonic-gate } 40517c478bd9Sstevel@tonic-gate 40527c478bd9Sstevel@tonic-gate 40537c478bd9Sstevel@tonic-gate static int 40547c478bd9Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg, 40557c478bd9Sstevel@tonic-gate pm_bus_power_op_t op, void *arg, void *result) 40567c478bd9Sstevel@tonic-gate { 40577c478bd9Sstevel@tonic-gate 40587c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 40597c478bd9Sstevel@tonic-gate 40607c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op); 40617c478bd9Sstevel@tonic-gate 40627c478bd9Sstevel@tonic-gate /* 40637c478bd9Sstevel@tonic-gate * Generic processing in MPxIO framework 40647c478bd9Sstevel@tonic-gate */ 40657c478bd9Sstevel@tonic-gate ret = mdi_bus_power(parent, impl_arg, op, arg, result); 40667c478bd9Sstevel@tonic-gate 40677c478bd9Sstevel@tonic-gate switch (ret) { 40687c478bd9Sstevel@tonic-gate case MDI_SUCCESS: 40697c478bd9Sstevel@tonic-gate ret = DDI_SUCCESS; 40707c478bd9Sstevel@tonic-gate break; 40717c478bd9Sstevel@tonic-gate case MDI_FAILURE: 40727c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 40737c478bd9Sstevel@tonic-gate break; 40747c478bd9Sstevel@tonic-gate default: 40757c478bd9Sstevel@tonic-gate break; 40767c478bd9Sstevel@tonic-gate } 40777c478bd9Sstevel@tonic-gate 40787c478bd9Sstevel@tonic-gate return (ret); 40797c478bd9Sstevel@tonic-gate } 40809d3d2ed0Shiremath 40819d3d2ed0Shiremath 40829d3d2ed0Shiremath /* 40839d3d2ed0Shiremath * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config. 40849d3d2ed0Shiremath * ndi_devi_enter is not held during this call. mdi_vhci_bus_config() 40859d3d2ed0Shiremath * will have called ndi_busop_bus_config(), no need for the caller to call 40869d3d2ed0Shiremath * ndi_busop_bus_config() again. 40879d3d2ed0Shiremath * 40889d3d2ed0Shiremath * If enumerated as a child of HCA device, this could be a case for 40899d3d2ed0Shiremath * Sparc boot or device enumeration from PHCI, driven by MDI. 40909d3d2ed0Shiremath * Hold parent lock (ndi_devi_enter). The caller will have to call 40919d3d2ed0Shiremath * ndi_busop_bus_config() if this function returns SUCCESS. 40929d3d2ed0Shiremath * 40939d3d2ed0Shiremath * if the device name contains ":port", then it is the Sparc boot case. 40949d3d2ed0Shiremath * Handle this as before. 40959d3d2ed0Shiremath * 40969d3d2ed0Shiremath * If the device name does *not* contain the ":port", then : 40979d3d2ed0Shiremath * 1. ibdm to probe IOC 40989d3d2ed0Shiremath * 2. Create a pathinfo only if the IOC is reachable from the parent dip. 40999d3d2ed0Shiremath */ 41009d3d2ed0Shiremath static int 41019d3d2ed0Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag, 41029d3d2ed0Shiremath ddi_bus_config_op_t op, void *devname, dev_info_t **child, 41039d3d2ed0Shiremath int *need_bus_config) 41049d3d2ed0Shiremath { 41059d3d2ed0Shiremath int ret = DDI_FAILURE, circ; 41069d3d2ed0Shiremath dev_info_t *pdip = *pdipp; 41079d3d2ed0Shiremath ib_guid_t iou_guid, ioc_guid; 41089d3d2ed0Shiremath char *ioc_guid_str; 41099d3d2ed0Shiremath 41109d3d2ed0Shiremath 41119d3d2ed0Shiremath *need_bus_config = 1; 41129d3d2ed0Shiremath 41139d3d2ed0Shiremath if (pdip == ibnex.ibnex_dip) { 41149d3d2ed0Shiremath if (ibnex_devname_to_node_n_ioc_guids( 41159d3d2ed0Shiremath (char *)devname, &iou_guid, &ioc_guid, 41169d3d2ed0Shiremath &ioc_guid_str) != IBNEX_SUCCESS) { 41179d3d2ed0Shiremath return (ret); 41189d3d2ed0Shiremath } 41199d3d2ed0Shiremath ret = mdi_vhci_bus_config(pdip, flag, op, devname, child, 41209d3d2ed0Shiremath ioc_guid_str); 41219d3d2ed0Shiremath kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1); 41229d3d2ed0Shiremath if (ret == MDI_SUCCESS) 41239d3d2ed0Shiremath *need_bus_config = 0; 41249d3d2ed0Shiremath } else { 41255e3986cbScth mdi_devi_enter(pdip, &circ); 41269d3d2ed0Shiremath if (strstr((char *)devname, ":port=") != NULL) { 41279d3d2ed0Shiremath ret = ibnex_config_root_iocnode(pdip, devname); 41289d3d2ed0Shiremath ASSERT(ibnex.ibnex_dip == NULL); 41299d3d2ed0Shiremath *pdipp = ibnex.ibnex_dip; 41309d3d2ed0Shiremath } else { 41319d3d2ed0Shiremath ret = ibnex_config_ioc_node(devname, pdip); 41329d3d2ed0Shiremath } 41335e3986cbScth mdi_devi_exit(pdip, circ); 41349d3d2ed0Shiremath } 41359d3d2ed0Shiremath return (ret); 41369d3d2ed0Shiremath } 41379d3d2ed0Shiremath 41389d3d2ed0Shiremath static int 41399d3d2ed0Shiremath ibnex_is_merge_node(dev_info_t *child) 41409d3d2ed0Shiremath { 41419d3d2ed0Shiremath char *node; 41429d3d2ed0Shiremath int ret = IBNEX_INVALID_NODE; 41439d3d2ed0Shiremath 41449d3d2ed0Shiremath if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 41459d3d2ed0Shiremath DDI_PROP_DONTPASS, "ib-node-type", &node) != 41469d3d2ed0Shiremath DDI_PROP_SUCCESS) { 41479d3d2ed0Shiremath return (IBNEX_FAILURE); 41489d3d2ed0Shiremath } 41499d3d2ed0Shiremath 41509d3d2ed0Shiremath if (node != NULL && *node != 0) { 41519d3d2ed0Shiremath if (strcmp(node, "merge") == 0) 41529d3d2ed0Shiremath ret = IBNEX_SUCCESS; 41539d3d2ed0Shiremath else { 41549d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", 41559d3d2ed0Shiremath "\tis_merge_node: ib-node-type = %s", node); 41569d3d2ed0Shiremath } 41579d3d2ed0Shiremath } 41589d3d2ed0Shiremath 41599d3d2ed0Shiremath ddi_prop_free(node); 41609d3d2ed0Shiremath return (ret); 41619d3d2ed0Shiremath } 41629d3d2ed0Shiremath 41639d3d2ed0Shiremath /* 41649d3d2ed0Shiremath * Checks if the dn_head for the driver has already 41659d3d2ed0Shiremath * initialized by the prom tree. 41669d3d2ed0Shiremath */ 4167f7209cf2Spramodbg void 41689d3d2ed0Shiremath ibnex_hw_in_dev_tree(char *driver_name) 41699d3d2ed0Shiremath { 41709d3d2ed0Shiremath major_t major; 41719d3d2ed0Shiremath 4172f7209cf2Spramodbg IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name); 4173f7209cf2Spramodbg 41749d3d2ed0Shiremath if (devnamesp == NULL) 4175f7209cf2Spramodbg return; 41769d3d2ed0Shiremath 41779d3d2ed0Shiremath major = ddi_name_to_major(driver_name); 41789d3d2ed0Shiremath if (major == -1) 4179f7209cf2Spramodbg return; 41809d3d2ed0Shiremath 4181f7209cf2Spramodbg if (devnamesp[major].dn_head != (dev_info_t *)NULL) 4182f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_IN_DEVTREE; 41839d3d2ed0Shiremath } 4184