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 /*
221cfa752fSRamaswamy Tummala * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
2615c07adcSJohn Levon * Copyright (c) 2018, Joyent, Inc.
27*3fe80ca4SDan Cross * Copyright 2023 Oxide Computer Company
2815c07adcSJohn Levon */
2915c07adcSJohn Levon
3015c07adcSJohn Levon /*
317c478bd9Sstevel@tonic-gate * The InfiniBand Nexus driver (IB nexus) is a bus nexus driver for IB bus.
327c478bd9Sstevel@tonic-gate * It supports Port nodes, Virtual Physical Point of Attachment nodes (VPPA)
337c478bd9Sstevel@tonic-gate * for HCAs registered with IBTL and IOC nodes for all the IOCs present in
347c478bd9Sstevel@tonic-gate * the IB fabric (that are accessible to the host). It also supports Pseudo
357c478bd9Sstevel@tonic-gate * device children to be enumerated using their .conf file(s). All Port nodes
367c478bd9Sstevel@tonic-gate * and VPPA nodes are children of HCA drivers. All the IOC nodes and the Pseudo
377c478bd9Sstevel@tonic-gate * device nodes are children of the IB nexus driver.
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate * IB nexus driver provides bus nexus entry points to all the HCA drivers.
407c478bd9Sstevel@tonic-gate *
417c478bd9Sstevel@tonic-gate * IB nexus driver registers with InfiniBand Device Manager (IBDM) to get
427c478bd9Sstevel@tonic-gate * information about all the HCA ports and I/O Controllers (IOCs) connected
437c478bd9Sstevel@tonic-gate * to the IB fabric. Based on that information, IB nexus will create all the
447c478bd9Sstevel@tonic-gate * device tree nodes.
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #include <sys/conf.h>
487c478bd9Sstevel@tonic-gate #include <sys/stat.h>
497c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
507c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
517c478bd9Sstevel@tonic-gate #include <sys/mdi_impldefs.h>
527c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h>
537c478bd9Sstevel@tonic-gate #include <sys/sunpm.h>
547c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibdm/ibdm_impl.h>
557c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex.h>
567c478bd9Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h>
577c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibti.h>
587c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/impl/ibtl_ibnex.h>
597c478bd9Sstevel@tonic-gate #include <sys/file.h>
607c478bd9Sstevel@tonic-gate #include <sys/hwconf.h>
61dcf1eb70SSudhakar Dindukurti #include <sys/fs/dv_node.h>
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate /* Function prototypes */
647c478bd9Sstevel@tonic-gate static int ibnex_attach(dev_info_t *, ddi_attach_cmd_t);
657c478bd9Sstevel@tonic-gate static int ibnex_getinfo(dev_info_t *, ddi_info_cmd_t,
667c478bd9Sstevel@tonic-gate void *, void **);
677c478bd9Sstevel@tonic-gate static int ibnex_detach(dev_info_t *, ddi_detach_cmd_t);
681cfa752fSRamaswamy Tummala int ibnex_busctl(dev_info_t *,
697c478bd9Sstevel@tonic-gate dev_info_t *, ddi_ctl_enum_t, void *, void *);
701cfa752fSRamaswamy Tummala int ibnex_map_fault(dev_info_t *,
717c478bd9Sstevel@tonic-gate dev_info_t *, struct hat *, struct seg *,
727c478bd9Sstevel@tonic-gate caddr_t, struct devpage *, pfn_t, uint_t, uint_t);
737c478bd9Sstevel@tonic-gate static int ibnex_init_child(dev_info_t *);
747c478bd9Sstevel@tonic-gate static ibnex_rval_t ibnex_comm_svc_init(char *, ibnex_node_type_t);
757c478bd9Sstevel@tonic-gate static void ibnex_comm_svc_fini();
767c478bd9Sstevel@tonic-gate dev_info_t *ibnex_commsvc_initnode(dev_info_t *,
777c478bd9Sstevel@tonic-gate ibdm_port_attr_t *, int, int, ib_pkey_t, int *,
787c478bd9Sstevel@tonic-gate int);
797c478bd9Sstevel@tonic-gate static void ibnex_delete_port_node_data(ibnex_node_data_t *);
807c478bd9Sstevel@tonic-gate int ibnex_get_dip_from_guid(ib_guid_t, int,
817c478bd9Sstevel@tonic-gate ib_pkey_t, dev_info_t **);
821cfa752fSRamaswamy Tummala int ibnex_get_node_and_dip_from_guid(ib_guid_t, int,
831cfa752fSRamaswamy Tummala ib_pkey_t, ibnex_node_data_t **, dev_info_t **);
847c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_is_node_data_present(ibnex_node_type_t,
857c478bd9Sstevel@tonic-gate void *, int, ib_pkey_t);
867c478bd9Sstevel@tonic-gate static ibnex_node_data_t *ibnex_init_child_nodedata(ibnex_node_type_t, void *,
877c478bd9Sstevel@tonic-gate int, ib_pkey_t);
887c478bd9Sstevel@tonic-gate static int ibnex_create_port_node_prop(ibdm_port_attr_t *,
897c478bd9Sstevel@tonic-gate dev_info_t *, char *, ib_pkey_t);
907c478bd9Sstevel@tonic-gate void ibnex_dm_callback(void *, ibdm_events_t);
917c478bd9Sstevel@tonic-gate static int ibnex_create_port_compatible_prop(dev_info_t *,
927c478bd9Sstevel@tonic-gate char *, ibdm_port_attr_t *);
937c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_srv_props(
947c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *);
957c478bd9Sstevel@tonic-gate static int ibnex_get_eventcookie(dev_info_t *,
967c478bd9Sstevel@tonic-gate dev_info_t *, char *, ddi_eventcookie_t *);
977c478bd9Sstevel@tonic-gate static int ibnex_add_eventcall(dev_info_t *, dev_info_t *,
987c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void (*)(dev_info_t *,
997c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *, void *),
1007c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id);
1017c478bd9Sstevel@tonic-gate static int ibnex_remove_eventcall(dev_info_t *,
1027c478bd9Sstevel@tonic-gate ddi_callback_id_t);
1037c478bd9Sstevel@tonic-gate static int ibnex_post_event(dev_info_t *, dev_info_t *,
1047c478bd9Sstevel@tonic-gate ddi_eventcookie_t, void *);
1057c478bd9Sstevel@tonic-gate static int ibnex_bus_config(dev_info_t *, uint_t,
1067c478bd9Sstevel@tonic-gate ddi_bus_config_op_t, void *, dev_info_t **);
1077c478bd9Sstevel@tonic-gate static int ibnex_bus_unconfig(dev_info_t *,
1087c478bd9Sstevel@tonic-gate uint_t, ddi_bus_config_op_t, void *);
1091cfa752fSRamaswamy Tummala dev_info_t *ibnex_config_port_node(dev_info_t *, char *);
1101cfa752fSRamaswamy Tummala int ibnex_get_pkey_commsvc_index_portnum(
1117c478bd9Sstevel@tonic-gate char *, int *, ib_pkey_t *, uint8_t *);
1121cfa752fSRamaswamy Tummala void ibnex_config_all_children(dev_info_t *);
1137c478bd9Sstevel@tonic-gate static int ibnex_devname_to_portnum(char *, uint8_t *);
1141cfa752fSRamaswamy Tummala void ibnex_create_vppa_nodes(dev_info_t *, ibdm_port_attr_t *);
1151cfa752fSRamaswamy Tummala void ibnex_create_port_nodes(
1167c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *);
1171cfa752fSRamaswamy Tummala void ibnex_create_hcasvc_nodes(
1187c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_port_attr_t *);
1197c478bd9Sstevel@tonic-gate static int ibnex_config_root_iocnode(dev_info_t *, char *);
1207c478bd9Sstevel@tonic-gate static int ibnex_devname2port(char *, int *);
1219d3d2ed0Shiremath static int ibnex_config_ioc_node(char *, dev_info_t *);
1227c478bd9Sstevel@tonic-gate static int ibnex_devname_to_node_n_ioc_guids(
1239d3d2ed0Shiremath char *, ib_guid_t *, ib_guid_t *, char **);
1247c478bd9Sstevel@tonic-gate static void ibnex_ioc_node_cleanup();
1257c478bd9Sstevel@tonic-gate static void ibnex_delete_ioc_node_data(ibnex_node_data_t *);
12600a3eaf3SRamaswamy Tummala int ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *);
12700a3eaf3SRamaswamy Tummala static int ibnex_ioc_initnode_pdip(ibnex_node_data_t *,
12800a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *, dev_info_t *);
1297c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_node_prop(
1307c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *, dev_info_t *);
1317c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_compatible_prop(
1327c478bd9Sstevel@tonic-gate dev_info_t *, ib_dm_ioc_ctrl_profile_t *);
1337c478bd9Sstevel@tonic-gate uint64_t ibnex_str2hex(char *, int, int *);
1341cfa752fSRamaswamy Tummala int ibnex_str2int(char *, int, int *);
1357c478bd9Sstevel@tonic-gate static int ibnex_create_ioc_portgid_prop(
1367c478bd9Sstevel@tonic-gate dev_info_t *, ibdm_ioc_info_t *);
1377c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *, int);
1387c478bd9Sstevel@tonic-gate static void ibnex_wakeup_reprobe_all();
1397c478bd9Sstevel@tonic-gate ibt_status_t ibnex_ibtl_callback(ibtl_ibnex_cb_args_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 *,
16000a3eaf3SRamaswamy Tummala dev_info_t *, int *);
1617c478bd9Sstevel@tonic-gate static int ibnex_bus_power(dev_info_t *, void *,
1627c478bd9Sstevel@tonic-gate pm_bus_power_op_t, void *, void *);
16300a3eaf3SRamaswamy Tummala int ibnex_pseudo_create_all_pi(ibnex_node_data_t *);
16400a3eaf3SRamaswamy Tummala static int ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *,
1659d3d2ed0Shiremath dev_info_t *);
1661cfa752fSRamaswamy Tummala int ibnex_pseudo_config_one(
16705fa0d51Spramodbg ibnex_node_data_t *, char *, dev_info_t *);
1681cfa752fSRamaswamy Tummala int ibnex_pseudo_mdi_config_one(int, void *, dev_info_t **,
1699d3d2ed0Shiremath char *, char *);
1709d3d2ed0Shiremath static void ibnex_config_pseudo_all(dev_info_t *);
1711cfa752fSRamaswamy Tummala int ibnex_ioc_bus_config_one(dev_info_t **, uint_t,
1729d3d2ed0Shiremath ddi_bus_config_op_t, void *, dev_info_t **, int *);
1739d3d2ed0Shiremath static int ibnex_is_merge_node(dev_info_t *);
174f7209cf2Spramodbg static void ibnex_hw_in_dev_tree(char *);
17500a3eaf3SRamaswamy Tummala static int ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *,
17600a3eaf3SRamaswamy Tummala dev_info_t *, int);
17700a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_exists(ibnex_node_data_t *, dev_info_t *);
17800a3eaf3SRamaswamy Tummala static int ibnex_ioc_pi_reachable(ibdm_ioc_info_t *,
17900a3eaf3SRamaswamy Tummala dev_info_t *);
1809d3d2ed0Shiremath
1811cfa752fSRamaswamy Tummala extern void ibnex_handle_hca_attach(void *);
1827c478bd9Sstevel@tonic-gate
1831cfa752fSRamaswamy Tummala extern struct bus_ops ibnex_ci_busops;
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * Prototype declarations for the VHCI options
1867c478bd9Sstevel@tonic-gate */
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * Functions registered with the mpxio framework
1897c478bd9Sstevel@tonic-gate */
1907c478bd9Sstevel@tonic-gate static int ib_vhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int);
1917c478bd9Sstevel@tonic-gate static int ib_vhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int);
1927c478bd9Sstevel@tonic-gate static int ib_vhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *,
1937c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int);
1947c478bd9Sstevel@tonic-gate static int ib_vhci_failover(dev_info_t *, dev_info_t *, int);
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate static mdi_vhci_ops_t ibnex_vhci_ops = {
1987c478bd9Sstevel@tonic-gate MDI_VHCI_OPS_REV,
1997c478bd9Sstevel@tonic-gate ib_vhci_pi_init,
2007c478bd9Sstevel@tonic-gate ib_vhci_pi_uninit,
2017c478bd9Sstevel@tonic-gate ib_vhci_pi_state_change,
2027c478bd9Sstevel@tonic-gate ib_vhci_failover
2037c478bd9Sstevel@tonic-gate };
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate * The bus_ops structure defines the capabilities of IB nexus driver.
2087c478bd9Sstevel@tonic-gate * IB nexus drivers does not support any DMA operations for its children
2097c478bd9Sstevel@tonic-gate * as there is no such concept in Infiniband. All the memory operations
2107c478bd9Sstevel@tonic-gate * and DMA operations required by the child drivers can be performed using
2117c478bd9Sstevel@tonic-gate * the IBTF API.
2127c478bd9Sstevel@tonic-gate */
2137c478bd9Sstevel@tonic-gate struct bus_ops ibnex_bus_ops = {
2147c478bd9Sstevel@tonic-gate BUSO_REV,
2157c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */
2167c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */
2177c478bd9Sstevel@tonic-gate NULL, /* bus_add_intrspec */
2187c478bd9Sstevel@tonic-gate NULL, /* bus_remove_intrspec */
2197c478bd9Sstevel@tonic-gate ibnex_map_fault, /* Map Fault */
2207c478bd9Sstevel@tonic-gate ddi_no_dma_map, /* DMA related entry points */
2217c478bd9Sstevel@tonic-gate ddi_no_dma_allochdl,
2227c478bd9Sstevel@tonic-gate NULL,
2237c478bd9Sstevel@tonic-gate NULL,
2247c478bd9Sstevel@tonic-gate NULL,
2257c478bd9Sstevel@tonic-gate NULL,
2267c478bd9Sstevel@tonic-gate NULL,
2277c478bd9Sstevel@tonic-gate NULL,
2287c478bd9Sstevel@tonic-gate ibnex_busctl, /* bus_ctl */
2297c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */
2307c478bd9Sstevel@tonic-gate ibnex_get_eventcookie, /* bus_get_eventcookie */
2317c478bd9Sstevel@tonic-gate ibnex_add_eventcall, /* bus_add_eventcall */
2327c478bd9Sstevel@tonic-gate ibnex_remove_eventcall, /* bus_remove_eventcall */
2337c478bd9Sstevel@tonic-gate ibnex_post_event, /* bus_post_event */
2347c478bd9Sstevel@tonic-gate NULL,
2357c478bd9Sstevel@tonic-gate ibnex_bus_config, /* bus config */
2367c478bd9Sstevel@tonic-gate ibnex_bus_unconfig, /* bus unconfig */
2377c478bd9Sstevel@tonic-gate NULL, /* bus fm init */
2387c478bd9Sstevel@tonic-gate NULL, /* bus fm fini */
2397c478bd9Sstevel@tonic-gate NULL, /* bus fm access enter */
2407c478bd9Sstevel@tonic-gate NULL, /* bus fm access exit */
2417c478bd9Sstevel@tonic-gate ibnex_bus_power /* bus power */
2427c478bd9Sstevel@tonic-gate };
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate /* ibnex cb_ops */
2457c478bd9Sstevel@tonic-gate static struct cb_ops ibnex_cbops = {
2467c478bd9Sstevel@tonic-gate ibnex_open, /* open */
2477c478bd9Sstevel@tonic-gate ibnex_close, /* close */
2487c478bd9Sstevel@tonic-gate nodev, /* strategy */
2497c478bd9Sstevel@tonic-gate nodev, /* print */
2507c478bd9Sstevel@tonic-gate nodev, /* dump */
2517c478bd9Sstevel@tonic-gate nodev, /* read */
2527c478bd9Sstevel@tonic-gate nodev, /* write */
2537c478bd9Sstevel@tonic-gate ibnex_ioctl, /* ioctl */
2547c478bd9Sstevel@tonic-gate nodev, /* devmap */
2557c478bd9Sstevel@tonic-gate nodev, /* mmap */
2567c478bd9Sstevel@tonic-gate nodev, /* segmap */
2577c478bd9Sstevel@tonic-gate nochpoll, /* poll */
2587c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */
2597c478bd9Sstevel@tonic-gate NULL, /* stream */
2607c478bd9Sstevel@tonic-gate D_MP, /* cb_flag */
2617c478bd9Sstevel@tonic-gate CB_REV, /* rev */
2627c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
2637c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
2647c478bd9Sstevel@tonic-gate };
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate * Device options
2687c478bd9Sstevel@tonic-gate * Note: ddi_no_info needs to change during devfs time frame. The drivers
2697c478bd9Sstevel@tonic-gate * with 1 to 1 mapping between minor node and instance should use
2707c478bd9Sstevel@tonic-gate * ddi_1to1_info. (See bug id 4424752)
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate static struct dev_ops ibnex_ops = {
2737c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */
2747c478bd9Sstevel@tonic-gate 0, /* refcnt */
2757c478bd9Sstevel@tonic-gate ibnex_getinfo, /* info */
2767c478bd9Sstevel@tonic-gate nulldev, /* identify */
2777c478bd9Sstevel@tonic-gate nulldev, /* probe */
2787c478bd9Sstevel@tonic-gate ibnex_attach, /* attach */
2797c478bd9Sstevel@tonic-gate ibnex_detach, /* detach */
2807c478bd9Sstevel@tonic-gate nodev, /* reset */
2817c478bd9Sstevel@tonic-gate &ibnex_cbops, /* driver ops - devctl interfaces */
2827c478bd9Sstevel@tonic-gate &ibnex_bus_ops, /* bus operations */
28319397407SSherry Moore nulldev, /* power */
28419397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */
2857c478bd9Sstevel@tonic-gate };
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate /* Module linkage information for the kernel. */
2887c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
2897c478bd9Sstevel@tonic-gate &mod_driverops, /* Driver module */
29019397407SSherry Moore "IB nexus", /* Driver name and version */
2917c478bd9Sstevel@tonic-gate &ibnex_ops, /* driver ops */
2927c478bd9Sstevel@tonic-gate };
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
2957c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
2967c478bd9Sstevel@tonic-gate };
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate * Global per-instance IB Nexus data.
3007c478bd9Sstevel@tonic-gate * There is only one instance of IB Nexus supported.
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate ibnex_t ibnex;
3037c478bd9Sstevel@tonic-gate #ifdef __lock_lint
3047c478bd9Sstevel@tonic-gate extern ibdm_t ibdm;
3057c478bd9Sstevel@tonic-gate #endif
3067c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_s))
3077c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ibnex.ibnex_num_comm_svcs
3087c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names ibnex.ibnex_nvppa_comm_svcs
3097c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names ibnex.ibnex_nhcasvc_comm_svcs
31000a3eaf3SRamaswamy Tummala ibnex.ibnex_hcasvc_comm_svc_names ibnex.ibnex_ioc_list))
3117c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibnex.ibnex_mutex, ibnex_node_data_s))
3127c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(ibdm.ibdm_hl_mutex ibnex.ibnex_mutex))
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate /* The port settling time in seconds */
3151aae5cd0SRajkumar Sivaprakasam int ibnex_port_settling_time = 8;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate /* create an array of properties supported, easier to add new ones here */
3187c478bd9Sstevel@tonic-gate static struct ibnex_property {
3197c478bd9Sstevel@tonic-gate char *name;
3207c478bd9Sstevel@tonic-gate ibnex_node_type_t type;
3217c478bd9Sstevel@tonic-gate } ibnex_properties[] = {
3227c478bd9Sstevel@tonic-gate { "port-svc-list", IBNEX_PORT_COMMSVC_NODE},
3237c478bd9Sstevel@tonic-gate { "vppa-svc-list", IBNEX_VPPA_COMMSVC_NODE},
3247c478bd9Sstevel@tonic-gate { "hca-svc-list", IBNEX_HCASVC_COMMSVC_NODE}
3257c478bd9Sstevel@tonic-gate };
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate #define N_IBNEX_PROPS (sizeof (ibnex_properties))/ \
3287c478bd9Sstevel@tonic-gate (sizeof (struct ibnex_property))
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate * Event Definition
3327c478bd9Sstevel@tonic-gate * Single event, event name defined in ibti_common.h.
3337c478bd9Sstevel@tonic-gate * Event posted to specific child handler. Event posted
3347c478bd9Sstevel@tonic-gate * at kernel priority.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate static ndi_event_definition_t ibnex_ndi_event_defs[] = {
3377c478bd9Sstevel@tonic-gate {IB_EVENT_TAG_PROP_UPDATE, IB_PROP_UPDATE_EVENT, EPL_KERNEL,
3387c478bd9Sstevel@tonic-gate NDI_EVENT_POST_TO_TGT}
3397c478bd9Sstevel@tonic-gate };
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate #define IB_N_NDI_EVENTS \
3427c478bd9Sstevel@tonic-gate (sizeof (ibnex_ndi_event_defs) / sizeof (ndi_event_definition_t))
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate static ndi_event_set_t ib_ndi_events = {
3457c478bd9Sstevel@tonic-gate NDI_EVENTS_REV1, IB_N_NDI_EVENTS, ibnex_ndi_event_defs};
3469d3d2ed0Shiremath static int ibnex_hw_status = IBNEX_DEVTREE_NOT_CHECKED;
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate * _init
3517c478bd9Sstevel@tonic-gate * Loadable module init, called before any other module.
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate int
_init(void)3547c478bd9Sstevel@tonic-gate _init(void)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate int error;
357f7209cf2Spramodbg char **hca_driver_list;
358f7209cf2Spramodbg int i, ndrivers;
3597c478bd9Sstevel@tonic-gate
3609d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_DEVTREE_NOT_CHECKED) {
361f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_NOT_IN_DEVTREE;
362f7209cf2Spramodbg hca_driver_list = mdi_get_phci_driver_list("ib", &ndrivers);
363f7209cf2Spramodbg for (i = 0; i < ndrivers; i++) {
364f7209cf2Spramodbg ibnex_hw_in_dev_tree(hca_driver_list[i]);
365f7209cf2Spramodbg if (ibnex_hw_status == IBNEX_HW_IN_DEVTREE)
366f7209cf2Spramodbg break;
367f7209cf2Spramodbg }
368f7209cf2Spramodbg mdi_free_phci_driver_list(hca_driver_list, ndrivers);
3699d3d2ed0Shiremath }
3709d3d2ed0Shiremath
3719d3d2ed0Shiremath /*
3729d3d2ed0Shiremath * IB Nexus _init can be called while force attaching
3739d3d2ed0Shiremath * IB Nexus driver or when a HCA is hotplugged.
3749d3d2ed0Shiremath *
3759d3d2ed0Shiremath * If IB HW is not in device tree or if no HCA driver
3769d3d2ed0Shiremath * has been attached, fail IB Nexus _init().
3779d3d2ed0Shiremath */
3789d3d2ed0Shiremath if (ibnex_hw_status == IBNEX_HW_NOT_IN_DEVTREE &&
3799d3d2ed0Shiremath ibt_hw_is_present() == 0) {
3809d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\t_init: NO IB HW");
3819d3d2ed0Shiremath return (DDI_FAILURE);
3829d3d2ed0Shiremath }
3839d3d2ed0Shiremath
3847c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_init");
3857c478bd9Sstevel@tonic-gate mutex_init(&ibnex.ibnex_mutex, NULL, MUTEX_DRIVER, NULL);
3867c478bd9Sstevel@tonic-gate cv_init(&ibnex.ibnex_reprobe_cv, NULL, CV_DRIVER, NULL);
38751f34d4bSRajkumar Sivaprakasam cv_init(&ibnex.ibnex_ioc_list_cv, NULL, CV_DRIVER, NULL);
3887c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) {
3897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t_init: mod_install failed");
3907c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex);
3917c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv);
39251f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv);
3937c478bd9Sstevel@tonic-gate } else {
3947c478bd9Sstevel@tonic-gate ibdm_ibnex_register_callback(ibnex_dm_callback);
3957c478bd9Sstevel@tonic-gate ibtl_ibnex_register_callback(ibnex_ibtl_callback);
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate return (error);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate * _fini
4037c478bd9Sstevel@tonic-gate * Prepares a module for unloading.
4047c478bd9Sstevel@tonic-gate */
4057c478bd9Sstevel@tonic-gate int
_fini(void)4067c478bd9Sstevel@tonic-gate _fini(void)
4077c478bd9Sstevel@tonic-gate {
4087c478bd9Sstevel@tonic-gate int error;
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_fini");
4117c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) {
4127c478bd9Sstevel@tonic-gate return (error);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate ibdm_ibnex_unregister_callback();
4157c478bd9Sstevel@tonic-gate ibtl_ibnex_unregister_callback();
4167c478bd9Sstevel@tonic-gate mutex_destroy(&ibnex.ibnex_mutex);
4177c478bd9Sstevel@tonic-gate cv_destroy(&ibnex.ibnex_reprobe_cv);
41851f34d4bSRajkumar Sivaprakasam cv_destroy(&ibnex.ibnex_ioc_list_cv);
4197c478bd9Sstevel@tonic-gate return (0);
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate /*
4247c478bd9Sstevel@tonic-gate * _info
4257c478bd9Sstevel@tonic-gate * Returns information about loadable module.
4267c478bd9Sstevel@tonic-gate */
4277c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)4287c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
4297c478bd9Sstevel@tonic-gate {
4307c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_info");
4317c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate /*
4367c478bd9Sstevel@tonic-gate * ibnex_attach
4377c478bd9Sstevel@tonic-gate * Configure and attach an instance of the IB Nexus driver
4387c478bd9Sstevel@tonic-gate * Only one instance of IB Nexus is supported
4397c478bd9Sstevel@tonic-gate * Create a minor node for cfgadm purpose
4407c478bd9Sstevel@tonic-gate * Initialize communication services
4417c478bd9Sstevel@tonic-gate * Register callback with IBDM
4427c478bd9Sstevel@tonic-gate * Register callback with IBTL
4437c478bd9Sstevel@tonic-gate */
4447c478bd9Sstevel@tonic-gate static int
ibnex_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)4457c478bd9Sstevel@tonic-gate ibnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
4467c478bd9Sstevel@tonic-gate {
4477c478bd9Sstevel@tonic-gate int i;
4487c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: device = %p cmd = %x)", dip, cmd);
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate switch (cmd) {
4537c478bd9Sstevel@tonic-gate case DDI_ATTACH:
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate case DDI_RESUME:
4567c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tattach: RESUME");
4577c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
4587c478bd9Sstevel@tonic-gate default:
4597c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate /* Fail attach for more than one instance */
4637c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
4647c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL) {
4657c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
4667c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
4697c478bd9Sstevel@tonic-gate
4701cfa752fSRamaswamy Tummala /*
4711cfa752fSRamaswamy Tummala * Create a IB nexus taskq
4721cfa752fSRamaswamy Tummala */
4731cfa752fSRamaswamy Tummala
4741cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = ddi_taskq_create(dip,
4751cfa752fSRamaswamy Tummala "ibnex-enum-taskq", 1, TASKQ_DEFAULTPRI, 0);
4761cfa752fSRamaswamy Tummala if (ibnex.ibnex_taskq_id == NULL) {
4771cfa752fSRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
4781cfa752fSRamaswamy Tummala "\tattach: ddi_taskq_create() failed");
4791cfa752fSRamaswamy Tummala return (DDI_FAILURE);
4801cfa752fSRamaswamy Tummala
4811cfa752fSRamaswamy Tummala }
4821cfa752fSRamaswamy Tummala
4837c478bd9Sstevel@tonic-gate /* Register with MPxIO framework */
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate if (mdi_vhci_register(MDI_HCI_CLASS_IB, dip, &ibnex_vhci_ops, 0)
4867c478bd9Sstevel@tonic-gate != MDI_SUCCESS) {
4877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
4887c478bd9Sstevel@tonic-gate "\tattach: mdi_vhci_register() failed");
4891cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
4901cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
4917c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate /*
4967c478bd9Sstevel@tonic-gate * Create the "fabric" devctl minor-node for IB DR support.
4977c478bd9Sstevel@tonic-gate * The minor number for the "devctl" node is in the same format
4987c478bd9Sstevel@tonic-gate * as the AP minor nodes.
4997c478bd9Sstevel@tonic-gate */
5007c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, IBNEX_FABRIC, S_IFCHR, instance,
5017c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
5027c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
5037c478bd9Sstevel@tonic-gate "\tattach: failed to create fabric minornode");
5041cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5051cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
5067c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
5077c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5087c478bd9Sstevel@tonic-gate }
5097c478bd9Sstevel@tonic-gate
510d1a5c838SRamaswamy Tummala /*
511d1a5c838SRamaswamy Tummala * Create "devctl" minor node for general ioctl interface to the
512d1a5c838SRamaswamy Tummala * ib nexus.
513d1a5c838SRamaswamy Tummala */
514d1a5c838SRamaswamy Tummala if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance,
515d1a5c838SRamaswamy Tummala DDI_NT_IB_NEXUS, 0) != DDI_SUCCESS) {
516d1a5c838SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
517d1a5c838SRamaswamy Tummala "\tattach: failed to create devctl minornode");
518d1a5c838SRamaswamy Tummala (void) ddi_remove_minor_node(dip, NULL);
5191cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5201cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
521d1a5c838SRamaswamy Tummala (void) mdi_vhci_unregister(dip, 0);
522d1a5c838SRamaswamy Tummala return (DDI_FAILURE);
523d1a5c838SRamaswamy Tummala }
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate /*
5267c478bd9Sstevel@tonic-gate * Set pm-want-child-notification property for
5277c478bd9Sstevel@tonic-gate * power management of the phci and client
5287c478bd9Sstevel@tonic-gate */
5297c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
530bf8d275aSToomas Soome "pm-want-child-notification?", NULL, 0) != DDI_PROP_SUCCESS) {
5317c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
5327c478bd9Sstevel@tonic-gate "_attach: create pm-want-child-notification failed");
5337c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL);
5341cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5351cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
5367c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
5377c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate
5407c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
5417c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = dip;
5427c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate /*
5457c478bd9Sstevel@tonic-gate * Event Handling: Definition and Binding.
5467c478bd9Sstevel@tonic-gate */
5477c478bd9Sstevel@tonic-gate if (ndi_event_alloc_hdl(dip, 0, &ibnex.ibnex_ndi_event_hdl,
5487c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) {
5497c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
5507c478bd9Sstevel@tonic-gate "_attach: ndi_event_alloc_hdl failed");
5511cfa752fSRamaswamy Tummala (void) ddi_remove_minor_node(dip, NULL);
5521cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5531cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
5547c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
5557c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate if (ndi_event_bind_set(ibnex.ibnex_ndi_event_hdl, &ib_ndi_events,
5587c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) {
5597c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL);
5607c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl);
5617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
5627c478bd9Sstevel@tonic-gate "_attach: ndi_event_bind_set failed");
5631cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5641cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
5657c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
5667c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate for (i = 0; i < N_IBNEX_PROPS; i++) {
5707c478bd9Sstevel@tonic-gate if (ibnex_comm_svc_init(ibnex_properties[i].name,
5717c478bd9Sstevel@tonic-gate ibnex_properties[i].type) != IBNEX_SUCCESS) {
5727c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini();
5737c478bd9Sstevel@tonic-gate (void) ndi_event_unbind_set(ibnex.ibnex_ndi_event_hdl,
5747c478bd9Sstevel@tonic-gate &ib_ndi_events, NDI_SLEEP);
5757c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL);
5767c478bd9Sstevel@tonic-gate (void) ndi_event_free_hdl(
5777c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl);
5787c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL;
5797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "_attach: ibnex_comm_svc_init"
5807c478bd9Sstevel@tonic-gate " failed %s", ibnex_properties[i].name);
5811cfa752fSRamaswamy Tummala (void) ddi_taskq_destroy(ibnex.ibnex_taskq_id);
5821cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
5837c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
5847c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate /*
5897c478bd9Sstevel@tonic-gate * before anything else comes up:
5907c478bd9Sstevel@tonic-gate * Initialize the internal list of pseudo device nodes by
5917c478bd9Sstevel@tonic-gate * getting all pseudo children of "ib" and processing them.
5927c478bd9Sstevel@tonic-gate */
5937c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes();
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate /*
6007c478bd9Sstevel@tonic-gate * ibnex_getinfo()
6017c478bd9Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the
6027c478bd9Sstevel@tonic-gate * instance number.
6037c478bd9Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
6047c478bd9Sstevel@tonic-gate */
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6077c478bd9Sstevel@tonic-gate static int
ibnex_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)6087c478bd9Sstevel@tonic-gate ibnex_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
6097c478bd9Sstevel@tonic-gate {
6107c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS;
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tgetinfo: Begin");
6137c478bd9Sstevel@tonic-gate switch (cmd) {
6147c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
6157c478bd9Sstevel@tonic-gate if (ibnex.ibnex_dip != NULL)
6167c478bd9Sstevel@tonic-gate *result = ibnex.ibnex_dip;
6177c478bd9Sstevel@tonic-gate else {
6187c478bd9Sstevel@tonic-gate *result = NULL;
6197c478bd9Sstevel@tonic-gate ret = DDI_FAILURE;
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate break;
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
6247c478bd9Sstevel@tonic-gate *result = 0;
6257c478bd9Sstevel@tonic-gate break;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate default:
6287c478bd9Sstevel@tonic-gate ret = DDI_FAILURE;
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate return (ret);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate /*
6357c478bd9Sstevel@tonic-gate * ibnex_detach
6367c478bd9Sstevel@tonic-gate * Unregister callback with the IBDM
6377c478bd9Sstevel@tonic-gate * Unregister callback with the IBTL
6387c478bd9Sstevel@tonic-gate * Uninitialize the communication entries
6397c478bd9Sstevel@tonic-gate * Remove all the minor nodes created by this instance
6407c478bd9Sstevel@tonic-gate */
6417c478bd9Sstevel@tonic-gate static int
ibnex_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)6427c478bd9Sstevel@tonic-gate ibnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
6437c478bd9Sstevel@tonic-gate {
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdetach: dip = %p cmd = %x)", dip, cmd);
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate switch (cmd) {
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate case DDI_DETACH:
6507c478bd9Sstevel@tonic-gate break;
6517c478bd9Sstevel@tonic-gate case DDI_SUSPEND:
6527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\t_detach: Suspend");
6537c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6547c478bd9Sstevel@tonic-gate default:
6557c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
6597c478bd9Sstevel@tonic-gate if (ibt_hw_is_present()) {
6607c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
6617c478bd9Sstevel@tonic-gate "\tdetach: IB HW is present ");
6627c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
6637c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate if (ndi_event_free_hdl(ibnex.ibnex_ndi_event_hdl)) {
6667c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
6677c478bd9Sstevel@tonic-gate "\tdetach: ndi_event_free_hdl() failed");
6687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
6697c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate ibnex.ibnex_ndi_event_hdl = NULL;
6727c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = NULL;
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup();
6757c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini();
6767c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup();
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate (void) ddi_remove_minor_node(dip, NULL);
6797c478bd9Sstevel@tonic-gate ibnex.ibnex_dip = NULL;
6807c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
6817c478bd9Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0);
6821cfa752fSRamaswamy Tummala
6831cfa752fSRamaswamy Tummala if (ibnex.ibnex_taskq_id != NULL) {
6841cfa752fSRamaswamy Tummala ddi_taskq_destroy(ibnex.ibnex_taskq_id);
6851cfa752fSRamaswamy Tummala ibnex.ibnex_taskq_id = NULL;
6861cfa752fSRamaswamy Tummala }
6871cfa752fSRamaswamy Tummala
6887c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate * ibnex_pseudo_node_cleanup()
6947c478bd9Sstevel@tonic-gate * This checks if all the "dips" have been deallocated (implying
6957c478bd9Sstevel@tonic-gate * that all the children have been unconfigured) first.
6967c478bd9Sstevel@tonic-gate * If not, it just returns.
6977c478bd9Sstevel@tonic-gate * If yes, then it frees up memory allocated for devi_name,
6987c478bd9Sstevel@tonic-gate * node_addr, and property list.
6997c478bd9Sstevel@tonic-gate */
7007c478bd9Sstevel@tonic-gate static void
ibnex_pseudo_node_cleanup(void)7017c478bd9Sstevel@tonic-gate ibnex_pseudo_node_cleanup(void)
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep = ibnex.ibnex_pseudo_node_head;
7047c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo;
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup:");
7077c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7087c478bd9Sstevel@tonic-gate
7097c478bd9Sstevel@tonic-gate for (; nodep; nodep = nodep->node_next)
7107c478bd9Sstevel@tonic-gate if (nodep->node_dip)
7117c478bd9Sstevel@tonic-gate return;
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_node_cleanup: freeing up memory");
7147c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
7157c478bd9Sstevel@tonic-gate nodep = nodep->node_next) {
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate pseudo = &nodep->node_data.pseudo_node;
7187c478bd9Sstevel@tonic-gate if (pseudo->pseudo_node_addr) {
7197c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_node_addr,
7207c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_node_addr) + 1);
7217c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr = NULL;
7227c478bd9Sstevel@tonic-gate }
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate if (pseudo->pseudo_devi_name) {
7257c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_devi_name,
7267c478bd9Sstevel@tonic-gate strlen(pseudo-> pseudo_devi_name) + 1);
7277c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name = NULL;
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate
7307c478bd9Sstevel@tonic-gate if (pseudo->pseudo_unit_addr) {
7317c478bd9Sstevel@tonic-gate kmem_free(pseudo->pseudo_unit_addr,
7327c478bd9Sstevel@tonic-gate pseudo->pseudo_unit_addr_len);
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate }
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate /*
7397c478bd9Sstevel@tonic-gate * This functions wakes up any reprobe requests waiting for completion
7407c478bd9Sstevel@tonic-gate * of reprobe of this IOC. It also send an NDI event, if :
7417c478bd9Sstevel@tonic-gate *
7427c478bd9Sstevel@tonic-gate * notify_flag is set. This is set if :
7437c478bd9Sstevel@tonic-gate * ibt_reprobe_ioc has returned with SUCCESS
7447c478bd9Sstevel@tonic-gate * IBTF client has not been notified for this node.
7457c478bd9Sstevel@tonic-gate * node_data->node_dip != NULL
7467c478bd9Sstevel@tonic-gate * node_state has IBNEX_NODE_REPROBE_NOTIFY_ALWAYS set
7477c478bd9Sstevel@tonic-gate * An NDI event cookie has been registered.
7487c478bd9Sstevel@tonic-gate */
7497c478bd9Sstevel@tonic-gate static void
ibnex_wakeup_reprobe_ioc(ibnex_node_data_t * node_data,int notify_flag)7507c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ibnex_node_data_t *node_data, int notify_flag)
7517c478bd9Sstevel@tonic-gate {
7527c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie;
7537c478bd9Sstevel@tonic-gate
7547c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7557c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
7567c478bd9Sstevel@tonic-gate
7577c478bd9Sstevel@tonic-gate if ((ibnex.ibnex_reprobe_state == IBNEX_REPROBE_IOC_WAIT) ||
7587c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state != 0)) {
7597c478bd9Sstevel@tonic-gate if (notify_flag && (node_data->node_dip != NULL) &&
7607c478bd9Sstevel@tonic-gate (node_data->node_state &
7617c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS) &&
7627c478bd9Sstevel@tonic-gate (evt_cookie != NULL)) {
7637c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data;
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate bzero(&evt_data, sizeof (evt_data));
7687c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip,
7697c478bd9Sstevel@tonic-gate node_data->node_dip,
7707c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS)
7717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
7727c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n");
7737c478bd9Sstevel@tonic-gate
7747c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0;
7787c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv);
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate node_data->node_reprobe_state = 0;
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate /*
7847c478bd9Sstevel@tonic-gate * This function wakes up any reprobe request waiting for completion
7857c478bd9Sstevel@tonic-gate * of reprobe of all IOCs.
7867c478bd9Sstevel@tonic-gate */
7877c478bd9Sstevel@tonic-gate static void
ibnex_wakeup_reprobe_all()7887c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all()
7897c478bd9Sstevel@tonic-gate {
7907c478bd9Sstevel@tonic-gate ibnex_node_data_t *ioc_node;
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate /* Notify if another reprobe_all is pending */
7957c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state == IBNEX_REPROBE_ALL_WAIT) {
7967c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0;
7977c478bd9Sstevel@tonic-gate cv_broadcast(&ibnex.ibnex_reprobe_cv);
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate ibnex.ibnex_reprobe_state = 0;
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate /*
8027c478bd9Sstevel@tonic-gate * The IOC may be hot-removed after the reprobe request.
8037c478bd9Sstevel@tonic-gate * Reset the reprobe states for such IOCs.
8047c478bd9Sstevel@tonic-gate */
8057c478bd9Sstevel@tonic-gate for (ioc_node = ibnex.ibnex_ioc_node_head; ioc_node;
8067c478bd9Sstevel@tonic-gate ioc_node = ioc_node->node_next) {
8077c478bd9Sstevel@tonic-gate if (ioc_node->node_reprobe_state != 0) {
8087c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(ioc_node, 1);
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate }
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate /*
8147c478bd9Sstevel@tonic-gate * ibnex_ibnex_callback:
8157c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_INIT:
8167c478bd9Sstevel@tonic-gate * Called from ibc_init() which is called from
8177c478bd9Sstevel@tonic-gate * HCA driver _init entry point
8187c478bd9Sstevel@tonic-gate * Initializes the HCA dev_ops structure with default
8197c478bd9Sstevel@tonic-gate * IB nexus structure.
8207c478bd9Sstevel@tonic-gate * IBTL_IBNEX_IBC_FINI:
8217c478bd9Sstevel@tonic-gate * Called from ibc_fini() which is called from
8227c478bd9Sstevel@tonic-gate * HCA driver _fini entry point
8237c478bd9Sstevel@tonic-gate * Un-Initializes the HCA dev_ops structure with default
8247c478bd9Sstevel@tonic-gate * IB nexus strucuture.
8257c478bd9Sstevel@tonic-gate * Returns IBT_SUCCESS
8267c478bd9Sstevel@tonic-gate */
8277c478bd9Sstevel@tonic-gate ibt_status_t
ibnex_ibtl_callback(ibtl_ibnex_cb_args_t * cb_args)8287c478bd9Sstevel@tonic-gate ibnex_ibtl_callback(ibtl_ibnex_cb_args_t *cb_args)
8297c478bd9Sstevel@tonic-gate {
8307c478bd9Sstevel@tonic-gate int retval = IBT_SUCCESS;
8317c478bd9Sstevel@tonic-gate struct dev_ops *hca_dev_ops;
8327c478bd9Sstevel@tonic-gate dev_info_t *clnt_dip;
8337c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
8347c478bd9Sstevel@tonic-gate
8357c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "\tibtl_callback");
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate switch (cb_args->cb_flag) {
8387c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_INIT:
8397c478bd9Sstevel@tonic-gate /*
8407c478bd9Sstevel@tonic-gate * Get the devops structure of the HCA,
8417c478bd9Sstevel@tonic-gate * and put IB nexus default busops vector in its place.
8427c478bd9Sstevel@tonic-gate */
8437c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *)
8447c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8457c478bd9Sstevel@tonic-gate ASSERT((hca_dev_ops) && (hca_dev_ops->devo_bus_ops == NULL));
8467c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = &ibnex_ci_busops;
8477c478bd9Sstevel@tonic-gate break;
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate case IBTL_IBNEX_IBC_FINI:
8507c478bd9Sstevel@tonic-gate hca_dev_ops = ((struct modldrv *)
8517c478bd9Sstevel@tonic-gate (cb_args->cb_modlp->ml_linkage[0]))->drv_dev_ops;
8527c478bd9Sstevel@tonic-gate hca_dev_ops->devo_bus_ops = NULL;
8537c478bd9Sstevel@tonic-gate break;
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate case IBTL_IBNEX_REPROBE_DEV_REQ:
8567c478bd9Sstevel@tonic-gate /* IBTL pass down request for ibt_reprobe_dev */
8577c478bd9Sstevel@tonic-gate clnt_dip = cb_args->cb_dip;
8587c478bd9Sstevel@tonic-gate ASSERT(clnt_dip);
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(clnt_dip);
8617c478bd9Sstevel@tonic-gate ASSERT(node_data);
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate /* Reprobe for IOC nodes only */
8647c478bd9Sstevel@tonic-gate ASSERT(node_data->node_type == IBNEX_IOC_NODE);
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate /*
8677c478bd9Sstevel@tonic-gate * Start the reprobe. This could sleep as it is not
8687c478bd9Sstevel@tonic-gate * from interrupt context.
8697c478bd9Sstevel@tonic-gate */
8707c478bd9Sstevel@tonic-gate if (taskq_dispatch(system_taskq, ibnex_handle_reprobe_dev,
871fc8ae2ecSToomas Soome clnt_dip, TQ_SLEEP) == TASKQID_INVALID) {
8727c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
8737c478bd9Sstevel@tonic-gate "ibnex_ibtl_callback: taskq_dispatch failed");
8747c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
8757c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0);
8767c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
8777c478bd9Sstevel@tonic-gate return (IBT_INSUFF_KERNEL_RESOURCE);
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate return (IBT_SUCCESS);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate return (retval);
8837c478bd9Sstevel@tonic-gate }
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate /*
8877c478bd9Sstevel@tonic-gate * Bus-ops entry points
8887c478bd9Sstevel@tonic-gate */
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate /*
8917c478bd9Sstevel@tonic-gate * ibnex_map_fault
8927c478bd9Sstevel@tonic-gate * IOC drivers need not map memory. Return failure to fail any
8937c478bd9Sstevel@tonic-gate * such calls.
8947c478bd9Sstevel@tonic-gate */
8957c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8961cfa752fSRamaswamy Tummala int
ibnex_map_fault(dev_info_t * dip,dev_info_t * rdip,struct hat * hat,struct seg * seg,caddr_t addr,struct devpage * dp,pfn_t pfn,uint_t prot,uint_t lock)8977c478bd9Sstevel@tonic-gate ibnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat,
8987c478bd9Sstevel@tonic-gate struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn,
8997c478bd9Sstevel@tonic-gate uint_t prot, uint_t lock)
9007c478bd9Sstevel@tonic-gate {
9017c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate /*
9067c478bd9Sstevel@tonic-gate * ibnex_busctl
9077c478bd9Sstevel@tonic-gate * bus_ctl bus_ops entry point
9087c478bd9Sstevel@tonic-gate */
9097c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9101cfa752fSRamaswamy Tummala int
ibnex_busctl(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)9117c478bd9Sstevel@tonic-gate ibnex_busctl(dev_info_t *dip, dev_info_t *rdip,
9127c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result)
9137c478bd9Sstevel@tonic-gate {
9147c478bd9Sstevel@tonic-gate dev_info_t *child_dip;
9157c478bd9Sstevel@tonic-gate
9167c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
9177c478bd9Sstevel@tonic-gate "\tbusctl: dip = %p, rdip = %p, ctlop = %x,", dip, rdip, ctlop);
9187c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbusctl: targ = %p, result %p", arg, result);
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate switch (ctlop) {
9217c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV:
9227c478bd9Sstevel@tonic-gate if (rdip == NULL) {
9237c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate /* Log the relevant details of dip to sysbuf */
9277c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?IB device: %s@%s, %s%d\n",
9287c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip),
9297c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip));
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD:
9347c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg;
9357c478bd9Sstevel@tonic-gate return (ibnex_init_child(child_dip));
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD:
9387c478bd9Sstevel@tonic-gate child_dip = (dev_info_t *)arg;
9397c478bd9Sstevel@tonic-gate ddi_set_name_addr(child_dip, NULL);
9407c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH:
9437c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH:
9447c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POWER :
9457c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV:
9487c478bd9Sstevel@tonic-gate /*
9497c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS for IOC/PORT/VPPA nodes and
9507c478bd9Sstevel@tonic-gate * DDI_FAILURE for the nodes enumerated by a Pseudo file.
9517c478bd9Sstevel@tonic-gate */
9527c478bd9Sstevel@tonic-gate return (ndi_dev_is_persistent_node(rdip) ?
9537c478bd9Sstevel@tonic-gate DDI_SUCCESS : DDI_FAILURE);
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN:
9577c478bd9Sstevel@tonic-gate /*
9587c478bd9Sstevel@tonic-gate * Return DDI_SUCCESS, so that consistent buf alloc
9597c478bd9Sstevel@tonic-gate * gets the default DMA IO minimum for the platform
9607c478bd9Sstevel@tonic-gate */
9617c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate /*
9647c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be
9657c478bd9Sstevel@tonic-gate * called by IB Nexus driver.
9667c478bd9Sstevel@tonic-gate */
9677c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC:
9687c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT:
9697c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE:
9707c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS:
9717c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY:
9727c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY:
9737c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE:
9747c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK:
9757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
9767c478bd9Sstevel@tonic-gate "%s%d: invalid op (%d) from %s inst%d",
9777c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip),
9787c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
9797c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate /*
9827c478bd9Sstevel@tonic-gate * Everything else (PTOB/BTOP/BTOPR/DVMAPAGESIZE requests) we
9837c478bd9Sstevel@tonic-gate * pass up
9847c478bd9Sstevel@tonic-gate */
9857c478bd9Sstevel@tonic-gate default:
9867c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result));
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate }
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate /*
9927c478bd9Sstevel@tonic-gate * ibnex_init_child()
9937c478bd9Sstevel@tonic-gate *
9947c478bd9Sstevel@tonic-gate * Initialize a child device node. This is called for the DDI_CTLOPS_INITCHILD
9957c478bd9Sstevel@tonic-gate * entry. Function returns DDI_SUCCESS, DDI_FAILURE or DDI_NOT_WELL_FORMED.
9967c478bd9Sstevel@tonic-gate */
9977c478bd9Sstevel@tonic-gate static int
ibnex_init_child(dev_info_t * child)9987c478bd9Sstevel@tonic-gate ibnex_init_child(dev_info_t *child)
9997c478bd9Sstevel@tonic-gate {
10007c478bd9Sstevel@tonic-gate int ret;
10017c478bd9Sstevel@tonic-gate char name[MAXNAMELEN];
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tinit_child: child = %p", child);
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate /* Handle Pseudo nodes of client children */
10067c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) {
10079d3d2ed0Shiremath /* Skip nodes without ib-node-type="merge" */
10089d3d2ed0Shiremath if (ibnex_is_merge_node(child) != IBNEX_SUCCESS)
10099d3d2ed0Shiremath return (DDI_FAILURE);
10109d3d2ed0Shiremath
10117c478bd9Sstevel@tonic-gate if (ibnex_name_pseudo_child(child, name) != DDI_SUCCESS)
10127c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name);
10157c478bd9Sstevel@tonic-gate /*
10167c478bd9Sstevel@tonic-gate * Merge the .conf node
10177c478bd9Sstevel@tonic-gate */
10187c478bd9Sstevel@tonic-gate if (ndi_merge_node(child,
10197c478bd9Sstevel@tonic-gate ibnex_name_child) == DDI_SUCCESS) {
10207c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL);
10217c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10227c478bd9Sstevel@tonic-gate }
10237c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED);
10247c478bd9Sstevel@tonic-gate
10257c478bd9Sstevel@tonic-gate }
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate if ((ret = ibnex_name_child(child, name, 0)) != DDI_SUCCESS)
10287c478bd9Sstevel@tonic-gate return (ret);
10297c478bd9Sstevel@tonic-gate
10307c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name);
10317c478bd9Sstevel@tonic-gate
10327c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
10337c478bd9Sstevel@tonic-gate }
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gate
10367c478bd9Sstevel@tonic-gate int
ibnex_name_pseudo_child(dev_info_t * child,char * name)10377c478bd9Sstevel@tonic-gate ibnex_name_pseudo_child(dev_info_t *child, char *name)
10387c478bd9Sstevel@tonic-gate {
10397c478bd9Sstevel@tonic-gate char **unit_addr;
10407c478bd9Sstevel@tonic-gate uint_t n;
10417c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
10427c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
10437c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) {
10449d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex",
10459d3d2ed0Shiremath "\tname_pseudo_child: cannot find unit-address in %s.conf",
10467c478bd9Sstevel@tonic-gate ddi_get_name(child));
10477c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10487c478bd9Sstevel@tonic-gate }
10497c478bd9Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
10507c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf"
10517c478bd9Sstevel@tonic-gate " not well-formed", ddi_get_name(child));
10527c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr);
10537c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10547c478bd9Sstevel@tonic-gate }
10557c478bd9Sstevel@tonic-gate (void) snprintf(name, MAXNAMELEN, "%s", *unit_addr);
10567c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr);
10577c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10627c478bd9Sstevel@tonic-gate int
ibnex_name_child(dev_info_t * child,char * name,int flag)10637c478bd9Sstevel@tonic-gate ibnex_name_child(dev_info_t *child, char *name, int flag)
10647c478bd9Sstevel@tonic-gate {
10657c478bd9Sstevel@tonic-gate ibnex_pseudo_node_t *pseudo;
10667c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_datap;
10677c478bd9Sstevel@tonic-gate ibnex_port_node_t *port_node;
10687c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc;
10697c478bd9Sstevel@tonic-gate
10707c478bd9Sstevel@tonic-gate node_datap = ddi_get_parent_data(child);
10717c478bd9Sstevel@tonic-gate if (node_datap == NULL) {
10727c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tname_child: Node data is NULL");
10737c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED);
10747c478bd9Sstevel@tonic-gate }
10757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tname_sid_child: Node data %p"
10767c478bd9Sstevel@tonic-gate "Node type %x", node_datap, node_datap->node_type);
10777c478bd9Sstevel@tonic-gate switch (node_datap->node_type) {
10787c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE:
10797c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node;
10807c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10817c478bd9Sstevel@tonic-gate port_node->port_num,
10827c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[port_node->port_commsvc_idx]);
10837c478bd9Sstevel@tonic-gate break;
10847c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE:
10857c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node;
10867c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,%x,%s",
10877c478bd9Sstevel@tonic-gate port_node->port_num, port_node->port_pkey, ibnex.
10887c478bd9Sstevel@tonic-gate ibnex_vppa_comm_svc_names[port_node->port_commsvc_idx]);
10897c478bd9Sstevel@tonic-gate break;
10907c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE:
10917c478bd9Sstevel@tonic-gate port_node = &node_datap->node_data.port_node;
10927c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%x,0,%s",
10937c478bd9Sstevel@tonic-gate port_node->port_num,
10947c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[port_node->
10957c478bd9Sstevel@tonic-gate port_commsvc_idx]);
10967c478bd9Sstevel@tonic-gate break;
10977c478bd9Sstevel@tonic-gate case IBNEX_IOC_NODE:
10987c478bd9Sstevel@tonic-gate ioc = &node_datap->node_data.ioc_node;
10997c478bd9Sstevel@tonic-gate (void) snprintf(name, IBNEX_MAX_NODEADDR_SZ, "%llX,%llX",
11007c478bd9Sstevel@tonic-gate (longlong_t)ioc->ioc_guid, (longlong_t)ioc->iou_guid);
11017c478bd9Sstevel@tonic-gate break;
11027c478bd9Sstevel@tonic-gate case IBNEX_PSEUDO_NODE:
11037c478bd9Sstevel@tonic-gate pseudo = &node_datap->node_data.pseudo_node;
11047c478bd9Sstevel@tonic-gate (void) snprintf(name,
11057c478bd9Sstevel@tonic-gate IBNEX_MAX_NODEADDR_SZ, pseudo->pseudo_unit_addr);
11067c478bd9Sstevel@tonic-gate break;
11077c478bd9Sstevel@tonic-gate default:
11087c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\name_child: Not well formed");
11097c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
11137c478bd9Sstevel@tonic-gate }
11147c478bd9Sstevel@tonic-gate
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate /*
11177c478bd9Sstevel@tonic-gate * ibnex_bus_config()
11187c478bd9Sstevel@tonic-gate *
11197c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE:
11207c478bd9Sstevel@tonic-gate * Enumerate the exact instance of the driver. Use the device node name
11217c478bd9Sstevel@tonic-gate * to locate the exact instance.
11227c478bd9Sstevel@tonic-gate * Query IBDM to find whether the hardware exits for the instance of the
11237c478bd9Sstevel@tonic-gate * driver. If exists, create a device node and return NDI_SUCCESS.
11247c478bd9Sstevel@tonic-gate *
11257c478bd9Sstevel@tonic-gate * BUS_CONFIG_ALL:
11267c478bd9Sstevel@tonic-gate * Enumerate all the instances of all the possible children (seen before
11277c478bd9Sstevel@tonic-gate * and never seen before).
11287c478bd9Sstevel@tonic-gate *
11297c478bd9Sstevel@tonic-gate * BUS_CONFIG_DRIVER:
11307c478bd9Sstevel@tonic-gate * Enumerate all the instances of a particular driver.
11317c478bd9Sstevel@tonic-gate */
11321cfa752fSRamaswamy Tummala
11337c478bd9Sstevel@tonic-gate static int
ibnex_bus_config(dev_info_t * parent,uint_t flag,ddi_bus_config_op_t op,void * devname,dev_info_t ** child)11347c478bd9Sstevel@tonic-gate ibnex_bus_config(dev_info_t *parent, uint_t flag,
11357c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *devname, dev_info_t **child)
11367c478bd9Sstevel@tonic-gate {
1137*3fe80ca4SDan Cross int ret = IBNEX_SUCCESS, len, need_bus_config;
11387c478bd9Sstevel@tonic-gate char *device_name, *cname = NULL, *caddr = NULL;
11391cfa752fSRamaswamy Tummala dev_info_t *cdip;
11407c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate switch (op) {
11437c478bd9Sstevel@tonic-gate case BUS_CONFIG_ONE:
114405fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ONE, "
114505fa0d51Spramodbg "parent %p", parent);
11467c478bd9Sstevel@tonic-gate
1147*3fe80ca4SDan Cross ndi_devi_enter(parent);
11481cfa752fSRamaswamy Tummala
11497c478bd9Sstevel@tonic-gate len = strlen((char *)devname) + 1;
11507c478bd9Sstevel@tonic-gate device_name = i_ddi_strdup(devname, KM_SLEEP);
11517c478bd9Sstevel@tonic-gate i_ddi_parse_name(device_name, &cname, &caddr, NULL);
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate if (caddr == NULL || (strlen(caddr) == 0)) {
11547c478bd9Sstevel@tonic-gate kmem_free(device_name, len);
1155*3fe80ca4SDan Cross ndi_devi_exit(parent);
11567c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
11577c478bd9Sstevel@tonic-gate }
11587c478bd9Sstevel@tonic-gate
11591cfa752fSRamaswamy Tummala cdip = ndi_devi_findchild(parent, devname);
116000a3eaf3SRamaswamy Tummala if (cdip)
116100a3eaf3SRamaswamy Tummala node_data = ddi_get_parent_data(cdip);
11621cfa752fSRamaswamy Tummala
1163*3fe80ca4SDan Cross ndi_devi_exit(parent);
11641cfa752fSRamaswamy Tummala
116500a3eaf3SRamaswamy Tummala if (cdip == NULL || (node_data != NULL &&
116600a3eaf3SRamaswamy Tummala node_data->node_dip == NULL)) {
11677c478bd9Sstevel@tonic-gate /* Node is not present */
11687c478bd9Sstevel@tonic-gate if (strncmp(cname, IBNEX_IOC_CNAME, 3) == 0) {
11699d3d2ed0Shiremath ret = ibnex_ioc_bus_config_one(&parent, flag,
11709d3d2ed0Shiremath op, devname, child, &need_bus_config);
117105fa0d51Spramodbg if (!need_bus_config) {
117205fa0d51Spramodbg kmem_free(device_name, len);
11739d3d2ed0Shiremath return (ret);
117405fa0d51Spramodbg }
11759d3d2ed0Shiremath } else {
11767c478bd9Sstevel@tonic-gate /*
11771cfa752fSRamaswamy Tummala * if IB Nexus is the parent, call MDI. Bus
11781cfa752fSRamaswamy Tummala * config with HCA as the parent would have
11791cfa752fSRamaswamy Tummala * enumerated the Pseudo node.
11807c478bd9Sstevel@tonic-gate */
11817c478bd9Sstevel@tonic-gate ret = IBNEX_SUCCESS;
11827c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes();
11837c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
11841cfa752fSRamaswamy Tummala ret = ibnex_pseudo_mdi_config_one(flag, devname,
11851cfa752fSRamaswamy Tummala child, cname, caddr);
11867c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
118705fa0d51Spramodbg kmem_free(device_name, len);
11889d3d2ed0Shiremath return (ret);
11899d3d2ed0Shiremath }
1190a1e3386eShiremath }
11917c478bd9Sstevel@tonic-gate kmem_free(device_name, len);
11927c478bd9Sstevel@tonic-gate break;
11937c478bd9Sstevel@tonic-gate
11947c478bd9Sstevel@tonic-gate case BUS_CONFIG_ALL:
11959d3d2ed0Shiremath /*FALLTHRU*/
11967c478bd9Sstevel@tonic-gate case BUS_CONFIG_DRIVER:
11979d3d2ed0Shiremath if (op == BUS_CONFIG_ALL)
119805fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_ALL, "
119905fa0d51Spramodbg "parent %p", parent);
12009d3d2ed0Shiremath else
120105fa0d51Spramodbg IBTF_DPRINTF_L4("ibnex", "\tbus_config: CONFIG_DRIVER"
120205fa0d51Spramodbg ", parent %p", parent);
12037c478bd9Sstevel@tonic-gate
12049d3d2ed0Shiremath /*
12059d3d2ed0Shiremath * Drive CONFIG requests for IB Nexus parent through
12069d3d2ed0Shiremath * MDI. This is needed to load the HCA drivers in x86 SRP
12079d3d2ed0Shiremath * boot case.
12089d3d2ed0Shiremath *
12099d3d2ed0Shiremath * CONFIG Requests with HCA parent will probe devices using
12109d3d2ed0Shiremath * ibdm and configure all children.
12119d3d2ed0Shiremath */
121251f34d4bSRajkumar Sivaprakasam ibdm_ioc_info_t *ioc_list, *new_ioc_list;
121300a3eaf3SRamaswamy Tummala
121451f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex);
121551f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state !=
121651f34d4bSRajkumar Sivaprakasam IBNEX_IOC_LIST_READY) {
121751f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv,
121851f34d4bSRajkumar Sivaprakasam &ibnex.ibnex_mutex);
121951f34d4bSRajkumar Sivaprakasam }
122051f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_RENEW;
122151f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex);
122251f34d4bSRajkumar Sivaprakasam /* Enumerate all the IOC's */
12231cfa752fSRamaswamy Tummala ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
122451f34d4bSRajkumar Sivaprakasam
122551f34d4bSRajkumar Sivaprakasam new_ioc_list = ibdm_ibnex_get_ioc_list(
122651f34d4bSRajkumar Sivaprakasam IBDM_IBNEX_NORMAL_PROBE);
122751f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex",
122851f34d4bSRajkumar Sivaprakasam "\tbus_config: alloc ioc_list %p", new_ioc_list);
122900a3eaf3SRamaswamy Tummala /*
123000a3eaf3SRamaswamy Tummala * Optimize the calls for each BUS_CONFIG_ALL request
123100a3eaf3SRamaswamy Tummala * to the IB Nexus dip. This is currently done for
123200a3eaf3SRamaswamy Tummala * each PDIP.
123300a3eaf3SRamaswamy Tummala */
123451f34d4bSRajkumar Sivaprakasam mutex_enter(&ibnex.ibnex_mutex);
123551f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list;
123651f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list = new_ioc_list;
123751f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
123851f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv);
123951f34d4bSRajkumar Sivaprakasam mutex_exit(&ibnex.ibnex_mutex);
124051f34d4bSRajkumar Sivaprakasam
124151f34d4bSRajkumar Sivaprakasam if (ioc_list) {
124200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
124300a3eaf3SRamaswamy Tummala "\tbus_config: freeing ioc_list %p",
124451f34d4bSRajkumar Sivaprakasam ioc_list);
124551f34d4bSRajkumar Sivaprakasam ibdm_ibnex_free_ioc_list(ioc_list);
124600a3eaf3SRamaswamy Tummala }
124700a3eaf3SRamaswamy Tummala
124800a3eaf3SRamaswamy Tummala
12499d3d2ed0Shiremath ret = mdi_vhci_bus_config(parent,
12509d3d2ed0Shiremath flag, op, devname, child, NULL);
12519d3d2ed0Shiremath return (ret);
12527c478bd9Sstevel@tonic-gate default:
12537c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config: error");
12547c478bd9Sstevel@tonic-gate ret = IBNEX_FAILURE;
12557c478bd9Sstevel@tonic-gate break;
12567c478bd9Sstevel@tonic-gate }
12575e3986cbScth
12587c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) {
12597c478bd9Sstevel@tonic-gate ret = ndi_busop_bus_config(
12601cfa752fSRamaswamy Tummala parent, flag, op, devname, child, 0);
12617c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_config:"
12627c478bd9Sstevel@tonic-gate "ndi_busop_bus_config : retval %d", ret);
12637c478bd9Sstevel@tonic-gate return (ret);
12647c478bd9Sstevel@tonic-gate }
12657c478bd9Sstevel@tonic-gate
12667c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
12677c478bd9Sstevel@tonic-gate }
12687c478bd9Sstevel@tonic-gate
12697c478bd9Sstevel@tonic-gate
12707c478bd9Sstevel@tonic-gate /*
12717c478bd9Sstevel@tonic-gate * ibnex_config_root_iocnode()
12727c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver.
12737c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
12747c478bd9Sstevel@tonic-gate */
12757c478bd9Sstevel@tonic-gate static int
ibnex_config_root_iocnode(dev_info_t * parent,char * device_name)12767c478bd9Sstevel@tonic-gate ibnex_config_root_iocnode(dev_info_t *parent, char *device_name)
12777c478bd9Sstevel@tonic-gate {
12787c478bd9Sstevel@tonic-gate int ret, port = 0, iter = 0;
12797c478bd9Sstevel@tonic-gate boolean_t displayed = B_FALSE;
12807c478bd9Sstevel@tonic-gate char *portstr;
12817c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, iou_guid, ioc_guid;
12827c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info;
12837c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr;
12847c478bd9Sstevel@tonic-gate
12857c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
12867c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: name %s", device_name);
12877c478bd9Sstevel@tonic-gate
12887c478bd9Sstevel@tonic-gate portstr = strstr(device_name, ":port=");
12897c478bd9Sstevel@tonic-gate if (portstr == NULL) {
12907c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
12917c478bd9Sstevel@tonic-gate }
12927c478bd9Sstevel@tonic-gate
12937c478bd9Sstevel@tonic-gate portstr[0] = 0; portstr++;
12947c478bd9Sstevel@tonic-gate if (ibnex_devname2port(portstr, &port)) {
12957c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_root_iocnode: invalid port");
12967c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
12977c478bd9Sstevel@tonic-gate }
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids(
13009d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
13017c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
13027c478bd9Sstevel@tonic-gate }
13037c478bd9Sstevel@tonic-gate
13047c478bd9Sstevel@tonic-gate (void) snprintf(device_name, (IBNEX_MAX_NODEADDR_SZ + 4),
13057c478bd9Sstevel@tonic-gate "ioc@%llX,%llX", (longlong_t)ioc_guid, (longlong_t)iou_guid);
13067c478bd9Sstevel@tonic-gate
13077c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent);
13087c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(hca_guid, port)) == NULL) {
13097c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
13107c478bd9Sstevel@tonic-gate "\tconfig_root_iocnode: Port does not exist");
13117c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
13127c478bd9Sstevel@tonic-gate }
13137c478bd9Sstevel@tonic-gate
13147c478bd9Sstevel@tonic-gate /* Wait until "port is up" */
13157c478bd9Sstevel@tonic-gate while (port_attr->pa_state != IBT_PORT_ACTIVE) {
13167c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
13177c478bd9Sstevel@tonic-gate delay(drv_usectohz(10000));
13187c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(
13197c478bd9Sstevel@tonic-gate hca_guid, port)) == NULL) {
13207c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
13217c478bd9Sstevel@tonic-gate }
13227c478bd9Sstevel@tonic-gate
13237c478bd9Sstevel@tonic-gate if (iter++ == 400) {
13247c478bd9Sstevel@tonic-gate if (displayed == B_FALSE) {
13257c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "\tWaiting for Port %d "
13267c478bd9Sstevel@tonic-gate "initialization", port_attr->pa_port_num);
13277c478bd9Sstevel@tonic-gate displayed = B_TRUE;
13287c478bd9Sstevel@tonic-gate }
13297c478bd9Sstevel@tonic-gate }
13307c478bd9Sstevel@tonic-gate }
13317c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
13327c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_rootioc_node:"
13337c478bd9Sstevel@tonic-gate "Port is initialized");
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) == NULL) {
13367c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info);
13377c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
13387c478bd9Sstevel@tonic-gate }
13397c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
134000a3eaf3SRamaswamy Tummala if ((ret = ibnex_ioc_config_from_pdip(ioc_info, parent, 0)) !=
134100a3eaf3SRamaswamy Tummala IBNEX_SUCCESS) {
134200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
134300a3eaf3SRamaswamy Tummala "\tconfig_root_ioc_node failed for pdip %p", parent);
134400a3eaf3SRamaswamy Tummala }
13457c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
13467c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info);
13477c478bd9Sstevel@tonic-gate return (ret);
13487c478bd9Sstevel@tonic-gate }
13497c478bd9Sstevel@tonic-gate
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate static int
ibnex_devname2port(char * portstr,int * port)13527c478bd9Sstevel@tonic-gate ibnex_devname2port(char *portstr, int *port)
13537c478bd9Sstevel@tonic-gate {
13547c478bd9Sstevel@tonic-gate char *temp;
13557c478bd9Sstevel@tonic-gate int ret = IBNEX_FAILURE;
13567c478bd9Sstevel@tonic-gate
13577c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname2port: Begin");
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate temp = strchr(portstr, '=');
13607c478bd9Sstevel@tonic-gate if (temp != NULL) {
13617c478bd9Sstevel@tonic-gate temp++;
13627c478bd9Sstevel@tonic-gate *port = ibnex_str2int(temp, strlen(temp), &ret);
13637c478bd9Sstevel@tonic-gate }
13647c478bd9Sstevel@tonic-gate return (ret);
13657c478bd9Sstevel@tonic-gate }
13667c478bd9Sstevel@tonic-gate
13677c478bd9Sstevel@tonic-gate
13687c478bd9Sstevel@tonic-gate /*
13697c478bd9Sstevel@tonic-gate * ibnex_config_all_children()
13707c478bd9Sstevel@tonic-gate * Wait for lata SM initialization case before enumerating the nodes
13717c478bd9Sstevel@tonic-gate * Get list of HCA's and HCA port information
13727c478bd9Sstevel@tonic-gate * Create device device nodes and its node properties
13737c478bd9Sstevel@tonic-gate * for port nodes and VPPA nodes
13747c478bd9Sstevel@tonic-gate * Get list of all the IOC node information
13757c478bd9Sstevel@tonic-gate * Create device nodes and its properties for all the IOCs
13767c478bd9Sstevel@tonic-gate * if not created already
13777c478bd9Sstevel@tonic-gate * Bind drivers for all the newly created device nodes
13787c478bd9Sstevel@tonic-gate * Support Pseudo nodes enumerated using their .conf file
13797c478bd9Sstevel@tonic-gate */
13801cfa752fSRamaswamy Tummala void
ibnex_config_all_children(dev_info_t * parent)13817c478bd9Sstevel@tonic-gate ibnex_config_all_children(dev_info_t *parent)
13827c478bd9Sstevel@tonic-gate {
13837c478bd9Sstevel@tonic-gate int ii;
138400a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_list;
13857c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list;
13867c478bd9Sstevel@tonic-gate ib_guid_t hca_guid;
1387*3fe80ca4SDan Cross boolean_t enteredv;
13887c478bd9Sstevel@tonic-gate
13897c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: Begin");
13907c478bd9Sstevel@tonic-gate
13911cfa752fSRamaswamy Tummala
13927c478bd9Sstevel@tonic-gate /*
13939d3d2ed0Shiremath * Enumerate children of this HCA, port nodes,
13945e3986cbScth * VPPA & HCA_SVC nodes. Use ndi_devi_enter() for
13955e3986cbScth * locking. IB Nexus is enumerating the children
13965e3986cbScth * of HCA, not MPXIO clients.
13977c478bd9Sstevel@tonic-gate */
1398*3fe80ca4SDan Cross ndi_devi_enter(parent);
13997c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent);
140000a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(hca_guid, ibnex_port_settling_time);
14017c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
1402f9edfba4Spramodbg if (hca_list == NULL) {
1403*3fe80ca4SDan Cross ndi_devi_exit(parent);
14047c478bd9Sstevel@tonic-gate return;
1405f9edfba4Spramodbg }
14067c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(parent, hca_list->hl_hca_port_attr);
14077c478bd9Sstevel@tonic-gate for (ii = 0; ii < hca_list->hl_nports; ii++) {
14087c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(
14097c478bd9Sstevel@tonic-gate parent, &hca_list->hl_port_attr[ii]);
14101cfa752fSRamaswamy Tummala ibnex_create_vppa_nodes(parent, &hca_list->hl_port_attr[ii]);
14117c478bd9Sstevel@tonic-gate }
14127c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
1413*3fe80ca4SDan Cross ndi_devi_exit(parent);
14145e3986cbScth
14155e3986cbScth /*
14165e3986cbScth * Use mdi_devi_enter() for locking. IB Nexus is
14178b2e16e7Seota * enumerating MPxIO clients.
14185e3986cbScth */
1419*3fe80ca4SDan Cross mdi_devi_enter(parent, &enteredv);
14207c478bd9Sstevel@tonic-gate
14217c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes();
14227c478bd9Sstevel@tonic-gate
14237c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
142451f34d4bSRajkumar Sivaprakasam while (ibnex.ibnex_ioc_list_state != IBNEX_IOC_LIST_READY) {
142551f34d4bSRajkumar Sivaprakasam cv_wait(&ibnex.ibnex_ioc_list_cv, &ibnex.ibnex_mutex);
142651f34d4bSRajkumar Sivaprakasam }
142751f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_ACCESS;
142851f34d4bSRajkumar Sivaprakasam ioc_list = ibnex.ibnex_ioc_list;
14297c478bd9Sstevel@tonic-gate while (ioc_list) {
143000a3eaf3SRamaswamy Tummala (void) ibnex_ioc_config_from_pdip(ioc_list, parent, 0);
14317c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next;
14327c478bd9Sstevel@tonic-gate }
143351f34d4bSRajkumar Sivaprakasam ibnex.ibnex_ioc_list_state = IBNEX_IOC_LIST_READY;
143451f34d4bSRajkumar Sivaprakasam cv_broadcast(&ibnex.ibnex_ioc_list_cv);
14359d3d2ed0Shiremath
14369d3d2ed0Shiremath /* Config IBTF Pseudo clients */
14379d3d2ed0Shiremath ibnex_config_pseudo_all(parent);
14389d3d2ed0Shiremath
14397c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
1440*3fe80ca4SDan Cross mdi_devi_exit(parent, enteredv);
14419d3d2ed0Shiremath
14427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_all_children: End");
14437c478bd9Sstevel@tonic-gate }
14447c478bd9Sstevel@tonic-gate
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate /*
14477c478bd9Sstevel@tonic-gate * ibnex_create_port_nodes:
14487c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined
14497c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port
14507c478bd9Sstevel@tonic-gate */
14511cfa752fSRamaswamy Tummala void
ibnex_create_port_nodes(dev_info_t * parent,ibdm_port_attr_t * port_attr)14527c478bd9Sstevel@tonic-gate ibnex_create_port_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
14537c478bd9Sstevel@tonic-gate {
14547c478bd9Sstevel@tonic-gate int idx;
14557c478bd9Sstevel@tonic-gate dev_info_t *dip;
14567c478bd9Sstevel@tonic-gate int rval;
14577c478bd9Sstevel@tonic-gate
14587c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
14597c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_num_comm_svcs; idx++) {
14607c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
14617c478bd9Sstevel@tonic-gate idx, 0, &dip);
14621cfa752fSRamaswamy Tummala if (rval != IBNEX_SUCCESS || dip == NULL) {
14637c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx,
14647c478bd9Sstevel@tonic-gate IBNEX_PORT_COMMSVC_NODE, 0, &rval,
14657c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE);
14667c478bd9Sstevel@tonic-gate }
14677c478bd9Sstevel@tonic-gate }
14687c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
14697c478bd9Sstevel@tonic-gate }
14707c478bd9Sstevel@tonic-gate
14717c478bd9Sstevel@tonic-gate
14727c478bd9Sstevel@tonic-gate /*
14737c478bd9Sstevel@tonic-gate * ibnex_create_vppa_nodes:
14747c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined
14757c478bd9Sstevel@tonic-gate * in the "vppa-commsvc-list" property and per each PKEY that
14767c478bd9Sstevel@tonic-gate * this particular port supports and per HCA port
14777c478bd9Sstevel@tonic-gate */
14781cfa752fSRamaswamy Tummala void
ibnex_create_vppa_nodes(dev_info_t * parent,ibdm_port_attr_t * port_attr)14791cfa752fSRamaswamy Tummala ibnex_create_vppa_nodes(
14801cfa752fSRamaswamy Tummala dev_info_t *parent, ibdm_port_attr_t *port_attr)
14817c478bd9Sstevel@tonic-gate {
14827c478bd9Sstevel@tonic-gate int idx, ii;
14837c478bd9Sstevel@tonic-gate int rval;
14847c478bd9Sstevel@tonic-gate ib_pkey_t pkey;
14857c478bd9Sstevel@tonic-gate dev_info_t *dip;
14867c478bd9Sstevel@tonic-gate
14877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: Begin");
14887c478bd9Sstevel@tonic-gate
14897c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
14907c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) {
14917c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_vppa_nodes: "
14927c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num);
14937c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
14947c478bd9Sstevel@tonic-gate return;
14957c478bd9Sstevel@tonic-gate }
14967c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nvppa_comm_svcs; idx++) {
14971cfa752fSRamaswamy Tummala if (strcmp("ipib", ibnex.ibnex_vppa_comm_svc_names[idx]) == 0) {
14981cfa752fSRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", "Skipping IBD devices...");
14991cfa752fSRamaswamy Tummala continue;
15001cfa752fSRamaswamy Tummala }
15017c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
15027c478bd9Sstevel@tonic-gate pkey = port_attr->pa_pkey_tbl[ii].pt_pkey;
15037c478bd9Sstevel@tonic-gate
15047c478bd9Sstevel@tonic-gate if (IBNEX_INVALID_PKEY(pkey)) {
15057c478bd9Sstevel@tonic-gate continue;
15067c478bd9Sstevel@tonic-gate }
15077c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(
15087c478bd9Sstevel@tonic-gate port_attr->pa_port_guid, idx, pkey, &dip);
150900a3eaf3SRamaswamy Tummala if ((rval != IBNEX_SUCCESS) || (dip == NULL)) {
15107c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr,
15117c478bd9Sstevel@tonic-gate idx, IBNEX_VPPA_COMMSVC_NODE,
15127c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE);
15137c478bd9Sstevel@tonic-gate }
15147c478bd9Sstevel@tonic-gate }
15157c478bd9Sstevel@tonic-gate }
15167c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
15177c478bd9Sstevel@tonic-gate }
15187c478bd9Sstevel@tonic-gate
15197c478bd9Sstevel@tonic-gate
15207c478bd9Sstevel@tonic-gate /*
15217c478bd9Sstevel@tonic-gate * ibnex_create_hcasvc_nodes:
15227c478bd9Sstevel@tonic-gate * Creates a device node per each communication service defined
15237c478bd9Sstevel@tonic-gate * in the "port-commsvc-list" property per HCA port
15247c478bd9Sstevel@tonic-gate */
15251cfa752fSRamaswamy Tummala void
ibnex_create_hcasvc_nodes(dev_info_t * parent,ibdm_port_attr_t * port_attr)15267c478bd9Sstevel@tonic-gate ibnex_create_hcasvc_nodes(dev_info_t *parent, ibdm_port_attr_t *port_attr)
15277c478bd9Sstevel@tonic-gate {
15287c478bd9Sstevel@tonic-gate int idx;
15297c478bd9Sstevel@tonic-gate dev_info_t *dip;
15307c478bd9Sstevel@tonic-gate int rval;
15317c478bd9Sstevel@tonic-gate
15327c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
15337c478bd9Sstevel@tonic-gate for (idx = 0; idx < ibnex.ibnex_nhcasvc_comm_svcs; idx++) {
15347c478bd9Sstevel@tonic-gate rval = ibnex_get_dip_from_guid(port_attr->pa_port_guid,
15357c478bd9Sstevel@tonic-gate idx, 0, &dip);
15361cfa752fSRamaswamy Tummala if (rval != IBNEX_SUCCESS || dip == NULL) {
15377c478bd9Sstevel@tonic-gate (void) ibnex_commsvc_initnode(parent, port_attr, idx,
15387c478bd9Sstevel@tonic-gate IBNEX_HCASVC_COMMSVC_NODE, 0, &rval,
15397c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE);
15407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex", "create_hcasvc_nodes: "
15417c478bd9Sstevel@tonic-gate "commsvc_initnode failed, rval %x", rval);
15427c478bd9Sstevel@tonic-gate }
15437c478bd9Sstevel@tonic-gate }
15447c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
15457c478bd9Sstevel@tonic-gate }
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gate
15487c478bd9Sstevel@tonic-gate /*
15497c478bd9Sstevel@tonic-gate * ibnex_bus_unconfig()
15507c478bd9Sstevel@tonic-gate *
15517c478bd9Sstevel@tonic-gate * Unconfigure a particular device node or all instance of a device
15527c478bd9Sstevel@tonic-gate * driver device or all children of IBnex
15537c478bd9Sstevel@tonic-gate */
15547c478bd9Sstevel@tonic-gate static int
ibnex_bus_unconfig(dev_info_t * parent,uint_t flag,ddi_bus_config_op_t op,void * device_name)15557c478bd9Sstevel@tonic-gate ibnex_bus_unconfig(dev_info_t *parent,
15567c478bd9Sstevel@tonic-gate uint_t flag, ddi_bus_config_op_t op, void *device_name)
15577c478bd9Sstevel@tonic-gate {
155800a3eaf3SRamaswamy Tummala ibnex_node_data_t *ndp;
155900a3eaf3SRamaswamy Tummala major_t major = (major_t)(uintptr_t)device_name;
156000a3eaf3SRamaswamy Tummala dev_info_t *dip = NULL;
156100a3eaf3SRamaswamy Tummala
156200a3eaf3SRamaswamy Tummala if (ndi_busop_bus_unconfig(parent, flag, op, device_name) !=
156300a3eaf3SRamaswamy Tummala DDI_SUCCESS)
156400a3eaf3SRamaswamy Tummala return (DDI_FAILURE);
156500a3eaf3SRamaswamy Tummala
156600a3eaf3SRamaswamy Tummala if ((op == BUS_UNCONFIG_ALL || op == BUS_UNCONFIG_DRIVER) &&
156700a3eaf3SRamaswamy Tummala (flag & (NDI_UNCONFIG | NDI_DETACH_DRIVER))) {
156800a3eaf3SRamaswamy Tummala mutex_enter(&ibnex.ibnex_mutex);
156900a3eaf3SRamaswamy Tummala /*
157000a3eaf3SRamaswamy Tummala * IB dip. here we handle IOC and pseudo nodes which
157100a3eaf3SRamaswamy Tummala * are the children of IB nexus. Cleanup only the nodes
157200a3eaf3SRamaswamy Tummala * with matching major number. We also need to cleanup
157300a3eaf3SRamaswamy Tummala * the PathInfo links to the PHCI here.
157400a3eaf3SRamaswamy Tummala */
157500a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_ioc_node_head;
157600a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) {
157700a3eaf3SRamaswamy Tummala dip = ndp->node_dip;
157800a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) {
1579332f545bSEiji Ota (void) ibnex_offline_childdip(dip);
158000a3eaf3SRamaswamy Tummala }
158100a3eaf3SRamaswamy Tummala }
158200a3eaf3SRamaswamy Tummala for (ndp = ibnex.ibnex_pseudo_node_head;
158300a3eaf3SRamaswamy Tummala ndp; ndp = ndp->node_next) {
158400a3eaf3SRamaswamy Tummala dip = ndp->node_dip;
158500a3eaf3SRamaswamy Tummala if (dip && (ddi_driver_major(dip) == major)) {
1586332f545bSEiji Ota (void) ibnex_offline_childdip(dip);
158700a3eaf3SRamaswamy Tummala }
158800a3eaf3SRamaswamy Tummala }
158900a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex);
159000a3eaf3SRamaswamy Tummala }
159100a3eaf3SRamaswamy Tummala return (DDI_SUCCESS);
15927c478bd9Sstevel@tonic-gate }
15937c478bd9Sstevel@tonic-gate
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate /*
15967c478bd9Sstevel@tonic-gate * ibnex_config_port_node()
15977c478bd9Sstevel@tonic-gate *
15987c478bd9Sstevel@tonic-gate * Configures a particular port / HCA node for a particular
15997c478bd9Sstevel@tonic-gate * communication service.
16007c478bd9Sstevel@tonic-gate * The format of the device_name is
16017c478bd9Sstevel@tonic-gate * ibport@<Port#>,<pkey>,<service name>
16027c478bd9Sstevel@tonic-gate * where pkey = 0 for port communication service nodes
16037c478bd9Sstevel@tonic-gate * Port# = 0 for HCA_SVC communication service nodes
16047c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the "child" node just created
16057c478bd9Sstevel@tonic-gate * NULL when failed to enumerate the child node
16067c478bd9Sstevel@tonic-gate */
16071cfa752fSRamaswamy Tummala dev_info_t *
ibnex_config_port_node(dev_info_t * parent,char * devname)16087c478bd9Sstevel@tonic-gate ibnex_config_port_node(dev_info_t *parent, char *devname)
16097c478bd9Sstevel@tonic-gate {
16107c478bd9Sstevel@tonic-gate int ii, index;
16117c478bd9Sstevel@tonic-gate int rval;
16127c478bd9Sstevel@tonic-gate uint8_t port_num;
16137c478bd9Sstevel@tonic-gate ib_guid_t hca_guid, port_guid;
16147c478bd9Sstevel@tonic-gate ib_pkey_t pkey;
16157c478bd9Sstevel@tonic-gate dev_info_t *cdip;
16167c478bd9Sstevel@tonic-gate ibdm_port_attr_t *port_attr;
16177c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list;
16187c478bd9Sstevel@tonic-gate
16197c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: %s", devname);
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gate if (ibnex_get_pkey_commsvc_index_portnum(devname,
16227c478bd9Sstevel@tonic-gate &index, &pkey, &port_num) != IBNEX_SUCCESS) {
16237c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
16247c478bd9Sstevel@tonic-gate "\tconfig_port_node: Invalid Service Name");
16257c478bd9Sstevel@tonic-gate return (NULL);
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate hca_guid = ibtl_ibnex_hcadip2guid(parent);
16297c478bd9Sstevel@tonic-gate if (port_num == 0) {
16307c478bd9Sstevel@tonic-gate /*
16317c478bd9Sstevel@tonic-gate * Use the dummy port attribute for HCA node in hca_list
16327c478bd9Sstevel@tonic-gate * Note : pa_state is always IBT_PORT_ACTIVE.
16337c478bd9Sstevel@tonic-gate */
16347c478bd9Sstevel@tonic-gate hca_list = ibdm_ibnex_get_hca_info_by_guid(hca_guid);
16357c478bd9Sstevel@tonic-gate ASSERT(hca_list != NULL);
16367c478bd9Sstevel@tonic-gate port_attr = hca_list->hl_hca_port_attr;
16377c478bd9Sstevel@tonic-gate } else {
16387c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(
16397c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) {
16407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
16417c478bd9Sstevel@tonic-gate "\tconfig_port_node: Port does not exist");
16427c478bd9Sstevel@tonic-gate return (NULL);
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate
16457c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) {
164600a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(
164700a3eaf3SRamaswamy Tummala hca_guid, ibnex_port_settling_time);
16487c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
16497c478bd9Sstevel@tonic-gate if ((port_attr = ibdm_ibnex_probe_hcaport(
16507c478bd9Sstevel@tonic-gate hca_guid, port_num)) == NULL) {
16517c478bd9Sstevel@tonic-gate return (NULL);
16527c478bd9Sstevel@tonic-gate }
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate }
16557c478bd9Sstevel@tonic-gate
16567c478bd9Sstevel@tonic-gate port_guid = port_attr->pa_port_guid;
16577c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
16581cfa752fSRamaswamy Tummala rval = ibnex_get_dip_from_guid(port_guid, index, pkey, &cdip);
16591cfa752fSRamaswamy Tummala if ((rval == IBNEX_SUCCESS) && cdip != NULL) {
16607c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_node: Node exists");
16617c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
16627c478bd9Sstevel@tonic-gate if (port_num != 0)
16637c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
16647c478bd9Sstevel@tonic-gate else
16657c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
16667c478bd9Sstevel@tonic-gate return (cdip);
16677c478bd9Sstevel@tonic-gate }
16687c478bd9Sstevel@tonic-gate
16697c478bd9Sstevel@tonic-gate if (pkey == 0 && port_num != 0) {
16707c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent,
16717c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_PORT_COMMSVC_NODE, pkey, &rval,
16727c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE);
16737c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex",
16747c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval);
16757c478bd9Sstevel@tonic-gate } else if (pkey == 0 && port_num == 0) {
16767c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent,
16777c478bd9Sstevel@tonic-gate port_attr, index, IBNEX_HCASVC_COMMSVC_NODE, pkey, &rval,
16787c478bd9Sstevel@tonic-gate IBNEX_DEVFS_ENUMERATE);
16797c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex",
16807c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval);
16817c478bd9Sstevel@tonic-gate } else {
16827c478bd9Sstevel@tonic-gate if (port_attr->pa_state != IBT_PORT_ACTIVE) {
16837c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_port_nodes: "
16847c478bd9Sstevel@tonic-gate "Port %d is down", port_attr->pa_port_num);
16857c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
16867c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
16877c478bd9Sstevel@tonic-gate return (NULL);
16887c478bd9Sstevel@tonic-gate }
16897c478bd9Sstevel@tonic-gate for (ii = 0; ii < port_attr->pa_npkeys; ii++) {
16907c478bd9Sstevel@tonic-gate if (pkey == port_attr->pa_pkey_tbl[ii].pt_pkey) {
16917c478bd9Sstevel@tonic-gate cdip = ibnex_commsvc_initnode(parent, port_attr,
16927c478bd9Sstevel@tonic-gate index, IBNEX_VPPA_COMMSVC_NODE,
16937c478bd9Sstevel@tonic-gate pkey, &rval, IBNEX_CFGADM_ENUMERATE);
16947c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L5("ibnex",
16957c478bd9Sstevel@tonic-gate "\t ibnex_commsvc_initnode rval %x", rval);
16967c478bd9Sstevel@tonic-gate break;
16977c478bd9Sstevel@tonic-gate }
16987c478bd9Sstevel@tonic-gate }
16997c478bd9Sstevel@tonic-gate }
17007c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
17017c478bd9Sstevel@tonic-gate if (port_num != 0)
17027c478bd9Sstevel@tonic-gate ibdm_ibnex_free_port_attr(port_attr);
17037c478bd9Sstevel@tonic-gate else
17047c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
17057c478bd9Sstevel@tonic-gate return (cdip);
17067c478bd9Sstevel@tonic-gate }
17077c478bd9Sstevel@tonic-gate
17087c478bd9Sstevel@tonic-gate
17097c478bd9Sstevel@tonic-gate /*
17107c478bd9Sstevel@tonic-gate * ibnex_get_pkey_commsvc_index_portnum()
17117c478bd9Sstevel@tonic-gate * Parses the device node name and extracts PKEY, communication
17127c478bd9Sstevel@tonic-gate * service index & Port #.
17137c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
17147c478bd9Sstevel@tonic-gate */
17151cfa752fSRamaswamy Tummala int
ibnex_get_pkey_commsvc_index_portnum(char * device_name,int * index,ib_pkey_t * pkey,uint8_t * port_num)17167c478bd9Sstevel@tonic-gate ibnex_get_pkey_commsvc_index_portnum(char *device_name, int *index,
17177c478bd9Sstevel@tonic-gate ib_pkey_t *pkey, uint8_t *port_num)
17187c478bd9Sstevel@tonic-gate {
17197c478bd9Sstevel@tonic-gate char *srv, **service_name, *temp;
17207c478bd9Sstevel@tonic-gate int ii, ncommsvcs, ret;
17217c478bd9Sstevel@tonic-gate
17227c478bd9Sstevel@tonic-gate if (ibnex_devname_to_portnum(device_name, port_num) !=
17237c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) {
17247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
1725d88af761SRajkumar Sivaprakasam "\tget_pkey_commsvc_index_portnum: Invalid Service Name");
1726d88af761SRajkumar Sivaprakasam return (IBNEX_FAILURE);
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate srv = strchr(device_name, ',');
17297c478bd9Sstevel@tonic-gate if (srv == 0)
17307c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
17317c478bd9Sstevel@tonic-gate
17327c478bd9Sstevel@tonic-gate srv++;
17337c478bd9Sstevel@tonic-gate temp = strchr(srv, ',');
17347c478bd9Sstevel@tonic-gate if (temp == 0)
17357c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
17367c478bd9Sstevel@tonic-gate temp++;
17377c478bd9Sstevel@tonic-gate *pkey = ibnex_str2hex(srv, (temp - srv - 1), &ret);
17387c478bd9Sstevel@tonic-gate if (ret != IBNEX_SUCCESS)
17397c478bd9Sstevel@tonic-gate return (ret);
17407c478bd9Sstevel@tonic-gate
17417c478bd9Sstevel@tonic-gate if (*pkey == 0 && *port_num != 0) {
17427c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_comm_svc_names;
17437c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_num_comm_svcs;
17447c478bd9Sstevel@tonic-gate } else if (*pkey == 0 && *port_num == 0) {
17457c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_hcasvc_comm_svc_names;
17467c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nhcasvc_comm_svcs;
17477c478bd9Sstevel@tonic-gate } else {
17487c478bd9Sstevel@tonic-gate service_name = ibnex.ibnex_vppa_comm_svc_names;
17497c478bd9Sstevel@tonic-gate ncommsvcs = ibnex.ibnex_nvppa_comm_svcs;
17507c478bd9Sstevel@tonic-gate }
17517c478bd9Sstevel@tonic-gate
17527c478bd9Sstevel@tonic-gate for (ii = 0; ii < ncommsvcs; ii++) {
17537c478bd9Sstevel@tonic-gate if (strcmp(service_name[ii], temp) == 0) {
17547c478bd9Sstevel@tonic-gate break;
17557c478bd9Sstevel@tonic-gate }
17567c478bd9Sstevel@tonic-gate }
17577c478bd9Sstevel@tonic-gate if (ii == ncommsvcs)
17587c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
17597c478bd9Sstevel@tonic-gate
17607c478bd9Sstevel@tonic-gate *index = ii;
17617c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
17627c478bd9Sstevel@tonic-gate }
17637c478bd9Sstevel@tonic-gate
17647c478bd9Sstevel@tonic-gate
17657c478bd9Sstevel@tonic-gate /*
17667c478bd9Sstevel@tonic-gate * ibnex_devname_to_portnum()
17677c478bd9Sstevel@tonic-gate * Get portguid from device name
17687c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
17697c478bd9Sstevel@tonic-gate */
17707c478bd9Sstevel@tonic-gate static int
ibnex_devname_to_portnum(char * device_name,uint8_t * portnum)17717c478bd9Sstevel@tonic-gate ibnex_devname_to_portnum(char *device_name, uint8_t *portnum)
17727c478bd9Sstevel@tonic-gate {
17737c478bd9Sstevel@tonic-gate int ret;
17747c478bd9Sstevel@tonic-gate char *temp1, *temp2;
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gate temp1 = strchr(device_name, '@');
17777c478bd9Sstevel@tonic-gate if (temp1 == NULL) {
17787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
17797c478bd9Sstevel@tonic-gate }
17807c478bd9Sstevel@tonic-gate temp2 = strchr(temp1, ',');
17817c478bd9Sstevel@tonic-gate if (temp2 == NULL)
17827c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
17837c478bd9Sstevel@tonic-gate temp1++;
17847c478bd9Sstevel@tonic-gate *portnum = ibnex_str2hex(temp1, (temp2 - temp1), &ret);
17857c478bd9Sstevel@tonic-gate return (ret);
17867c478bd9Sstevel@tonic-gate }
17877c478bd9Sstevel@tonic-gate
17887c478bd9Sstevel@tonic-gate
17897c478bd9Sstevel@tonic-gate /*
17907c478bd9Sstevel@tonic-gate * ibnex_config_ioc_node()
17917c478bd9Sstevel@tonic-gate * Configures one particular instance of the IOC driver.
17927c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
17937c478bd9Sstevel@tonic-gate */
17947c478bd9Sstevel@tonic-gate static int
ibnex_config_ioc_node(char * device_name,dev_info_t * pdip)17959d3d2ed0Shiremath ibnex_config_ioc_node(char *device_name, dev_info_t *pdip)
17967c478bd9Sstevel@tonic-gate {
17977c478bd9Sstevel@tonic-gate int ret;
17987c478bd9Sstevel@tonic-gate ib_guid_t iou_guid, ioc_guid;
17997c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info;
18007c478bd9Sstevel@tonic-gate
18017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: Begin");
18027c478bd9Sstevel@tonic-gate
18037c478bd9Sstevel@tonic-gate if (ibnex_devname_to_node_n_ioc_guids(
18049d3d2ed0Shiremath device_name, &iou_guid, &ioc_guid, NULL) != IBNEX_SUCCESS) {
18057c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
18067c478bd9Sstevel@tonic-gate }
18077c478bd9Sstevel@tonic-gate
180800a3eaf3SRamaswamy Tummala ibdm_ibnex_port_settle_wait(0, ibnex_port_settling_time);
18097c478bd9Sstevel@tonic-gate
18107c478bd9Sstevel@tonic-gate if ((ioc_info = ibdm_ibnex_probe_ioc(iou_guid, ioc_guid, 0)) ==
18117c478bd9Sstevel@tonic-gate NULL) {
18127c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info);
18137c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
18147c478bd9Sstevel@tonic-gate }
18157c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
181600a3eaf3SRamaswamy Tummala ret = ibnex_ioc_config_from_pdip(ioc_info, pdip, 0);
18177c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
18187c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info);
181900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tconfig_ioc_node: ret %x",
182000a3eaf3SRamaswamy Tummala ret);
18217c478bd9Sstevel@tonic-gate return (ret);
18227c478bd9Sstevel@tonic-gate }
18237c478bd9Sstevel@tonic-gate
18247c478bd9Sstevel@tonic-gate
18257c478bd9Sstevel@tonic-gate /*
18267c478bd9Sstevel@tonic-gate * ibnex_devname_to_node_n_ioc_guids()
18277c478bd9Sstevel@tonic-gate * Get node guid and ioc guid from the device name
18287c478bd9Sstevel@tonic-gate * Format of the device node name is:
18297c478bd9Sstevel@tonic-gate * ioc@<IOC GUID>,<IOU GUID>
18307c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
18317c478bd9Sstevel@tonic-gate */
18327c478bd9Sstevel@tonic-gate static int
ibnex_devname_to_node_n_ioc_guids(char * device_name,ib_guid_t * iou_guid,ib_guid_t * ioc_guid,char ** ioc_guid_strp)18337c478bd9Sstevel@tonic-gate ibnex_devname_to_node_n_ioc_guids(
18349d3d2ed0Shiremath char *device_name, ib_guid_t *iou_guid, ib_guid_t *ioc_guid,
18359d3d2ed0Shiremath char **ioc_guid_strp)
18367c478bd9Sstevel@tonic-gate {
18377c478bd9Sstevel@tonic-gate char *temp1, *temp;
18387c478bd9Sstevel@tonic-gate int len, ret;
18399d3d2ed0Shiremath char *ioc_guid_str;
18407c478bd9Sstevel@tonic-gate
18417c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdevname_to_node_n_ioc_guids:"
18427c478bd9Sstevel@tonic-gate "Device Name %s", device_name);
18437c478bd9Sstevel@tonic-gate
18447c478bd9Sstevel@tonic-gate if ((temp = strchr(device_name, '@')) == NULL) {
18457c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
18467c478bd9Sstevel@tonic-gate }
18477c478bd9Sstevel@tonic-gate if ((temp1 = strchr(++temp, ',')) == NULL) {
18487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
18497c478bd9Sstevel@tonic-gate }
18507c478bd9Sstevel@tonic-gate *ioc_guid = ibnex_str2hex(temp, (temp1 - temp), &ret);
18517c478bd9Sstevel@tonic-gate if (ret == IBNEX_SUCCESS) {
18529d3d2ed0Shiremath if (ioc_guid_strp) {
18539d3d2ed0Shiremath ioc_guid_str = *ioc_guid_strp = kmem_zalloc((temp1
18549d3d2ed0Shiremath - temp) + 1, KM_SLEEP);
18559d3d2ed0Shiremath (void) strncpy(ioc_guid_str, temp, temp1 - temp + 1);
18569d3d2ed0Shiremath ioc_guid_str[temp1 - temp] = '\0';
18579d3d2ed0Shiremath }
18587c478bd9Sstevel@tonic-gate len = device_name + strlen(device_name) - ++temp1;
18597c478bd9Sstevel@tonic-gate *iou_guid = ibnex_str2hex(temp1, len, &ret);
18607c478bd9Sstevel@tonic-gate }
18617c478bd9Sstevel@tonic-gate return (ret);
18627c478bd9Sstevel@tonic-gate }
18637c478bd9Sstevel@tonic-gate
18647c478bd9Sstevel@tonic-gate
18657c478bd9Sstevel@tonic-gate /*
18667c478bd9Sstevel@tonic-gate * ibnex_ioc_initnode()
18677c478bd9Sstevel@tonic-gate * Allocate a pathinfo node for the IOC
18687c478bd9Sstevel@tonic-gate * Initialize the device node
18697c478bd9Sstevel@tonic-gate * Bind driver to the node
18707c478bd9Sstevel@tonic-gate * Update IBnex global data
18717c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY
18727c478bd9Sstevel@tonic-gate */
187300a3eaf3SRamaswamy Tummala static int
ibnex_ioc_initnode_pdip(ibnex_node_data_t * node_data,ibdm_ioc_info_t * ioc_info,dev_info_t * pdip)187400a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_pdip(ibnex_node_data_t *node_data,
187500a3eaf3SRamaswamy Tummala ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
18767c478bd9Sstevel@tonic-gate {
187700a3eaf3SRamaswamy Tummala int rval, node_valid;
187800a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state;
18797c478bd9Sstevel@tonic-gate
18807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
188100a3eaf3SRamaswamy Tummala ASSERT(node_data);
18827c478bd9Sstevel@tonic-gate
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate /*
18857c478bd9Sstevel@tonic-gate * Return EBUSY if another configure/unconfigure
18867c478bd9Sstevel@tonic-gate * operation is in progress
18877c478bd9Sstevel@tonic-gate */
18887c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
188900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
189000a3eaf3SRamaswamy Tummala "\tioc_initnode_pdip : BUSY");
18917c478bd9Sstevel@tonic-gate return (IBNEX_BUSY);
18927c478bd9Sstevel@tonic-gate }
18937c478bd9Sstevel@tonic-gate
189400a3eaf3SRamaswamy Tummala prev_state = node_data->node_state;
18957c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING;
18967c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
18977c478bd9Sstevel@tonic-gate
189800a3eaf3SRamaswamy Tummala rval = ibnex_ioc_create_pi(ioc_info, node_data, pdip, &node_valid);
18997c478bd9Sstevel@tonic-gate
19007c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
19017c478bd9Sstevel@tonic-gate if (rval == IBNEX_SUCCESS)
19027c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED;
190300a3eaf3SRamaswamy Tummala else if (node_valid)
190400a3eaf3SRamaswamy Tummala node_data->node_state = prev_state;
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate return (rval);
19077c478bd9Sstevel@tonic-gate }
19087c478bd9Sstevel@tonic-gate
19097c478bd9Sstevel@tonic-gate /*
19107c478bd9Sstevel@tonic-gate * ibnex_config_pseudo_all()
19117c478bd9Sstevel@tonic-gate * Configure all the pseudo nodes
19127c478bd9Sstevel@tonic-gate */
19137c478bd9Sstevel@tonic-gate static void
ibnex_config_pseudo_all(dev_info_t * pdip)19149d3d2ed0Shiremath ibnex_config_pseudo_all(dev_info_t *pdip)
19157c478bd9Sstevel@tonic-gate {
19167c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep;
19177c478bd9Sstevel@tonic-gate
19187c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
19197c478bd9Sstevel@tonic-gate
19207c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head;
19217c478bd9Sstevel@tonic-gate nodep; nodep = nodep->node_next) {
192205fa0d51Spramodbg (void) ibnex_pseudo_config_one(nodep, NULL, pdip);
19237c478bd9Sstevel@tonic-gate }
19247c478bd9Sstevel@tonic-gate }
19257c478bd9Sstevel@tonic-gate
19267c478bd9Sstevel@tonic-gate
19277c478bd9Sstevel@tonic-gate /*
19287c478bd9Sstevel@tonic-gate * ibnex_pseudo_config_one()
19297c478bd9Sstevel@tonic-gate */
19301cfa752fSRamaswamy Tummala int
ibnex_pseudo_config_one(ibnex_node_data_t * node_data,char * caddr,dev_info_t * pdip)193105fa0d51Spramodbg ibnex_pseudo_config_one(ibnex_node_data_t *node_data, char *caddr,
19329d3d2ed0Shiremath dev_info_t *pdip)
19337c478bd9Sstevel@tonic-gate {
193405fa0d51Spramodbg int rval;
193500a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo;
193600a3eaf3SRamaswamy Tummala ibnex_node_state_t prev_state;
19377c478bd9Sstevel@tonic-gate
193800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one(%p, %p, %p)",
193905fa0d51Spramodbg node_data, caddr, pdip);
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
19427c478bd9Sstevel@tonic-gate
19437c478bd9Sstevel@tonic-gate if (node_data == NULL) {
194400a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
194500a3eaf3SRamaswamy Tummala "\tpseudo_config_one: caddr = %s", caddr);
19467c478bd9Sstevel@tonic-gate
194705fa0d51Spramodbg /*
194805fa0d51Spramodbg * This function is now called with PHCI / HCA driver
194905fa0d51Spramodbg * as parent. The format of devicename is :
195005fa0d51Spramodbg * <driver_name>@<driver_name>,<unit_address>
195105fa0d51Spramodbg * The "caddr" part of the devicename matches the
195205fa0d51Spramodbg * format of pseudo_node_addr.
195305fa0d51Spramodbg *
195405fa0d51Spramodbg * Use "caddr" to find a matching Pseudo node entry.
195505fa0d51Spramodbg */
19567c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
195705fa0d51Spramodbg (void *)caddr, 0, 0);
19587c478bd9Sstevel@tonic-gate }
19597c478bd9Sstevel@tonic-gate
196000a3eaf3SRamaswamy Tummala if (node_data == NULL) {
196100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
196200a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Invalid node");
196300a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE);
196400a3eaf3SRamaswamy Tummala }
196500a3eaf3SRamaswamy Tummala
196600a3eaf3SRamaswamy Tummala if (node_data->node_ap_state == IBNEX_NODE_AP_UNCONFIGURED) {
196700a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
196800a3eaf3SRamaswamy Tummala "\tpseudo_config_one: Unconfigured node");
196900a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE);
197000a3eaf3SRamaswamy Tummala }
197100a3eaf3SRamaswamy Tummala
197200a3eaf3SRamaswamy Tummala pseudo = &node_data->node_data.pseudo_node;
197300a3eaf3SRamaswamy Tummala
19747c478bd9Sstevel@tonic-gate /*
19759d3d2ed0Shiremath * Do not enumerate nodes with ib-node-type set as "merge"
19769d3d2ed0Shiremath */
197700a3eaf3SRamaswamy Tummala if (pseudo->pseudo_merge_node == 1) {
197800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
197900a3eaf3SRamaswamy Tummala "\tpseudo_config_one: merge_node");
19809d3d2ed0Shiremath return (IBNEX_FAILURE);
19819d3d2ed0Shiremath }
19829d3d2ed0Shiremath
19839d3d2ed0Shiremath /*
198400a3eaf3SRamaswamy Tummala * Check if a PI has already been created for the PDIP.
198500a3eaf3SRamaswamy Tummala * If so, return SUCCESS.
19867c478bd9Sstevel@tonic-gate */
198700a3eaf3SRamaswamy Tummala if (node_data->node_dip != NULL && mdi_pi_find(pdip,
198800a3eaf3SRamaswamy Tummala pseudo->pseudo_node_addr, pseudo->pseudo_node_addr) != NULL) {
198900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
199000a3eaf3SRamaswamy Tummala "\tpseudo_config_one: PI created,"
199100a3eaf3SRamaswamy Tummala " pdip %p, addr %s", pdip, pseudo->pseudo_node_addr);
199200a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS);
19937c478bd9Sstevel@tonic-gate }
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate /*
199600a3eaf3SRamaswamy Tummala * Return EBUSY if another unconfigure
19977c478bd9Sstevel@tonic-gate * operation is in progress
19987c478bd9Sstevel@tonic-gate */
19997c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
200000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
200100a3eaf3SRamaswamy Tummala "\tpseudo_config_one: BUSY");
20027c478bd9Sstevel@tonic-gate return (IBNEX_BUSY);
20037c478bd9Sstevel@tonic-gate }
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gate
200600a3eaf3SRamaswamy Tummala prev_state = node_data->node_state;
20077c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING;
20087c478bd9Sstevel@tonic-gate
20097c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
201000a3eaf3SRamaswamy Tummala rval = ibnex_pseudo_create_pi_pdip(node_data, pdip);
20117c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
20127c478bd9Sstevel@tonic-gate
201300a3eaf3SRamaswamy Tummala if (rval == IBNEX_SUCCESS) {
20147c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED;
201500a3eaf3SRamaswamy Tummala } else {
201600a3eaf3SRamaswamy Tummala node_data->node_state = prev_state;
20177c478bd9Sstevel@tonic-gate }
20187c478bd9Sstevel@tonic-gate
201900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_config_one: ret %x",
202000a3eaf3SRamaswamy Tummala rval);
20217c478bd9Sstevel@tonic-gate return (rval);
20227c478bd9Sstevel@tonic-gate }
20237c478bd9Sstevel@tonic-gate
20247c478bd9Sstevel@tonic-gate
20259d3d2ed0Shiremath /*
20269d3d2ed0Shiremath * ibnex_pseudo_mdi_config_one()
20279d3d2ed0Shiremath * This is similar to ibnex_pseudo_config_one. Few
20289d3d2ed0Shiremath * differences :
20299d3d2ed0Shiremath * 1. parent device lock not held(no ndi_devi_enter)
20309d3d2ed0Shiremath * 2. Called for IB Nexus as parent, not IB HCA as
20319d3d2ed0Shiremath * parent.
20329d3d2ed0Shiremath * 3. Calls mdi_vhci_bus_config()
203305fa0d51Spramodbg * This function skips checks for node_state, initializing
203405fa0d51Spramodbg * node_state, node_dip, etc. These checks and initializations
203505fa0d51Spramodbg * are done when BUS_CONFIG is called with PHCI as the parent.
20369d3d2ed0Shiremath */
20371cfa752fSRamaswamy Tummala int
ibnex_pseudo_mdi_config_one(int flag,void * devname,dev_info_t ** child,char * cname,char * caddr)20389d3d2ed0Shiremath ibnex_pseudo_mdi_config_one(int flag, void *devname, dev_info_t **child,
20399d3d2ed0Shiremath char *cname, char *caddr)
20409d3d2ed0Shiremath {
20419d3d2ed0Shiremath int rval, len;
20429d3d2ed0Shiremath char *node_addr;
20439d3d2ed0Shiremath ibnex_node_data_t *node_data;
20449d3d2ed0Shiremath
20459d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex", "\tpseudo_mdi_config_one:"
20469d3d2ed0Shiremath "cname = %s caddr = %s", cname, caddr);
20479d3d2ed0Shiremath
20489d3d2ed0Shiremath ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
20499d3d2ed0Shiremath
20509d3d2ed0Shiremath len = strlen(cname) + strlen(caddr) + 2;
20519d3d2ed0Shiremath node_addr = (char *)kmem_alloc(len, KM_SLEEP);
20529d3d2ed0Shiremath
20539d3d2ed0Shiremath (void) snprintf(node_addr, len, "%s,%s", cname, caddr);
20549d3d2ed0Shiremath node_data = ibnex_is_node_data_present(IBNEX_PSEUDO_NODE,
20559d3d2ed0Shiremath (void *)node_addr, 0, 0);
20569d3d2ed0Shiremath kmem_free(node_addr, len);
20579d3d2ed0Shiremath
205805fa0d51Spramodbg if (node_data == NULL) {
20599d3d2ed0Shiremath IBTF_DPRINTF_L2("ibnex",
20609d3d2ed0Shiremath "\tpseudo_mdi_config_one: Invalid node");
20619d3d2ed0Shiremath return (IBNEX_FAILURE);
20629d3d2ed0Shiremath }
20639d3d2ed0Shiremath
20649d3d2ed0Shiremath mutex_exit(&ibnex.ibnex_mutex);
20659d3d2ed0Shiremath rval = mdi_vhci_bus_config(ibnex.ibnex_dip, flag, BUS_CONFIG_ONE,
20669d3d2ed0Shiremath devname, child, node_data->node_data.pseudo_node.pseudo_node_addr);
20679d3d2ed0Shiremath mutex_enter(&ibnex.ibnex_mutex);
20689d3d2ed0Shiremath
20699d3d2ed0Shiremath return (rval);
20709d3d2ed0Shiremath }
20719d3d2ed0Shiremath
207200a3eaf3SRamaswamy Tummala
20737c478bd9Sstevel@tonic-gate /*
207400a3eaf3SRamaswamy Tummala * ibnex_pseudo_create_all_pi()
207500a3eaf3SRamaswamy Tummala * Create all path infos node for a pseudo entry
20767c478bd9Sstevel@tonic-gate */
20777c478bd9Sstevel@tonic-gate int
ibnex_pseudo_create_all_pi(ibnex_node_data_t * nodep)207800a3eaf3SRamaswamy Tummala ibnex_pseudo_create_all_pi(ibnex_node_data_t *nodep)
20797c478bd9Sstevel@tonic-gate {
208000a3eaf3SRamaswamy Tummala int hcacnt, rc;
208100a3eaf3SRamaswamy Tummala int hcafailcnt = 0;
208200a3eaf3SRamaswamy Tummala dev_info_t *hca_dip;
20837c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list, *head;
20847c478bd9Sstevel@tonic-gate
208500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi(%p)",
208600a3eaf3SRamaswamy Tummala nodep);
20877c478bd9Sstevel@tonic-gate ibdm_ibnex_get_hca_list(&hca_list, &hcacnt);
20887c478bd9Sstevel@tonic-gate
20897c478bd9Sstevel@tonic-gate head = hca_list;
20907c478bd9Sstevel@tonic-gate
20919d3d2ed0Shiremath /*
209200a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs.
20939d3d2ed0Shiremath */
209400a3eaf3SRamaswamy Tummala for (; hca_list != NULL; hca_list = hca_list->hl_next) {
209500a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
209600a3eaf3SRamaswamy Tummala rc = ibnex_pseudo_create_pi_pdip(nodep, hca_dip);
209700a3eaf3SRamaswamy Tummala if (rc != IBNEX_SUCCESS)
209800a3eaf3SRamaswamy Tummala hcafailcnt++;
209900a3eaf3SRamaswamy Tummala }
210000a3eaf3SRamaswamy Tummala if (head)
210100a3eaf3SRamaswamy Tummala ibdm_ibnex_free_hca_list(head);
210200a3eaf3SRamaswamy Tummala
210300a3eaf3SRamaswamy Tummala if (hcafailcnt == hcacnt)
210400a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE;
210500a3eaf3SRamaswamy Tummala else
210600a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS;
210700a3eaf3SRamaswamy Tummala
210800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_all_pi rc %x",
210900a3eaf3SRamaswamy Tummala rc);
211000a3eaf3SRamaswamy Tummala return (rc);
211100a3eaf3SRamaswamy Tummala }
211200a3eaf3SRamaswamy Tummala
211300a3eaf3SRamaswamy Tummala static int
ibnex_pseudo_create_pi_pdip(ibnex_node_data_t * nodep,dev_info_t * hca_dip)211400a3eaf3SRamaswamy Tummala ibnex_pseudo_create_pi_pdip(ibnex_node_data_t *nodep, dev_info_t *hca_dip)
211500a3eaf3SRamaswamy Tummala {
211600a3eaf3SRamaswamy Tummala mdi_pathinfo_t *pip;
211700a3eaf3SRamaswamy Tummala int rval;
211800a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL;
211900a3eaf3SRamaswamy Tummala ibnex_pseudo_node_t *pseudo;
212000a3eaf3SRamaswamy Tummala int first_pi = 0;
212100a3eaf3SRamaswamy Tummala
212200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpseudo_create_pi_pdip: %p, %p",
212300a3eaf3SRamaswamy Tummala nodep, hca_dip);
212400a3eaf3SRamaswamy Tummala
212500a3eaf3SRamaswamy Tummala pseudo = &nodep->node_data.pseudo_node;
21269d3d2ed0Shiremath
21277c478bd9Sstevel@tonic-gate rval = mdi_pi_alloc(hca_dip,
21287c478bd9Sstevel@tonic-gate pseudo->pseudo_devi_name, pseudo->pseudo_node_addr,
21297c478bd9Sstevel@tonic-gate pseudo->pseudo_node_addr, 0, &pip);
21307c478bd9Sstevel@tonic-gate
21317c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) {
213200a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex", "\tpseudo_create_pi_pdip:"
213300a3eaf3SRamaswamy Tummala " mdi_pi_alloc failed");
21347c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
21357c478bd9Sstevel@tonic-gate }
21367c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip);
21377c478bd9Sstevel@tonic-gate
213800a3eaf3SRamaswamy Tummala if (nodep->node_dip == NULL) {
21397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
21407c478bd9Sstevel@tonic-gate "\tpseudo_create_pi: New dip %p", cdip);
21417c478bd9Sstevel@tonic-gate
214200a3eaf3SRamaswamy Tummala first_pi = 1;
21437c478bd9Sstevel@tonic-gate nodep->node_dip = cdip;
21447c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, nodep);
214500a3eaf3SRamaswamy Tummala }
21467c478bd9Sstevel@tonic-gate
21477c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0);
21487c478bd9Sstevel@tonic-gate
21497c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) {
215000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
215100a3eaf3SRamaswamy Tummala "\tpseudo_create_pi: "
21527c478bd9Sstevel@tonic-gate "mdi_pi_online: failed for pseudo dip %p,"
21537c478bd9Sstevel@tonic-gate " rval %d", cdip, rval);
21547c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE;
215500a3eaf3SRamaswamy Tummala if (first_pi == 1) {
215600a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL);
215700a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip);
215800a3eaf3SRamaswamy Tummala nodep->node_dip = NULL;
215900a3eaf3SRamaswamy Tummala } else
216000a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0);
21617c478bd9Sstevel@tonic-gate } else
21627c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS;
21637c478bd9Sstevel@tonic-gate return (rval);
21647c478bd9Sstevel@tonic-gate }
21657c478bd9Sstevel@tonic-gate
21667c478bd9Sstevel@tonic-gate /*
21677c478bd9Sstevel@tonic-gate * ibnex_ioc_create_pi()
21687c478bd9Sstevel@tonic-gate * Create a pathinfo node for the ioc node
21697c478bd9Sstevel@tonic-gate */
21707c478bd9Sstevel@tonic-gate static int
ibnex_ioc_create_pi(ibdm_ioc_info_t * ioc_info,ibnex_node_data_t * node_data,dev_info_t * pdip,int * node_valid)21719d3d2ed0Shiremath ibnex_ioc_create_pi(ibdm_ioc_info_t *ioc_info, ibnex_node_data_t *node_data,
217200a3eaf3SRamaswamy Tummala dev_info_t *pdip, int *node_valid)
21737c478bd9Sstevel@tonic-gate {
21747c478bd9Sstevel@tonic-gate mdi_pathinfo_t *pip;
21759d3d2ed0Shiremath int rval = DDI_FAILURE;
217600a3eaf3SRamaswamy Tummala dev_info_t *cdip = NULL;
217700a3eaf3SRamaswamy Tummala int create_prop = 0;
217800a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc = &node_data->node_data.ioc_node;
21797c478bd9Sstevel@tonic-gate
218000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
218100a3eaf3SRamaswamy Tummala "\tibnex_ioc_create_pi(%p, %p, %p)", ioc_info, node_data, pdip);
218200a3eaf3SRamaswamy Tummala *node_valid = 1;
21837c478bd9Sstevel@tonic-gate
21849d3d2ed0Shiremath /*
21859d3d2ed0Shiremath * For CONFIG_ONE requests through HCA dip, alloc
21869d3d2ed0Shiremath * for HCA dip driving BUS_CONFIG request.
21879d3d2ed0Shiremath */
218800a3eaf3SRamaswamy Tummala rval = mdi_pi_alloc(pdip, IBNEX_IOC_CNAME, ioc->ioc_guid_str,
218900a3eaf3SRamaswamy Tummala ioc->ioc_phci_guid, 0, &pip);
21907c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) {
219100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L2("ibnex",
219200a3eaf3SRamaswamy Tummala "\tioc_create_pi: mdi_pi_alloc(%p, %s. %s) failed",
219300a3eaf3SRamaswamy Tummala pdip, ioc->ioc_guid_str, ioc->ioc_phci_guid);
21947c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
21957c478bd9Sstevel@tonic-gate }
21967c478bd9Sstevel@tonic-gate cdip = mdi_pi_get_client(pip);
21977c478bd9Sstevel@tonic-gate
219800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi: IOC dip %p",
219900a3eaf3SRamaswamy Tummala cdip);
22007c478bd9Sstevel@tonic-gate
220100a3eaf3SRamaswamy Tummala if (node_data->node_dip == NULL) {
22027c478bd9Sstevel@tonic-gate node_data->node_dip = cdip;
22037c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, node_data);
220400a3eaf3SRamaswamy Tummala create_prop = 1;
220500a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
220600a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop");
22077c478bd9Sstevel@tonic-gate if ((rval = ibnex_create_ioc_node_prop(
22087c478bd9Sstevel@tonic-gate ioc_info, cdip)) != IBNEX_SUCCESS) {
220900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
221000a3eaf3SRamaswamy Tummala "\tioc_create_pi: creating prop failed");
22117c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(node_data);
221200a3eaf3SRamaswamy Tummala *node_valid = 0;
22137c478bd9Sstevel@tonic-gate ddi_prop_remove_all(cdip);
22147c478bd9Sstevel@tonic-gate ddi_set_parent_data(cdip, NULL);
22157c478bd9Sstevel@tonic-gate
22167c478bd9Sstevel@tonic-gate (void) ibnex_offline_childdip(cdip);
22177c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22187c478bd9Sstevel@tonic-gate }
22197c478bd9Sstevel@tonic-gate }
22207c478bd9Sstevel@tonic-gate
22217c478bd9Sstevel@tonic-gate rval = mdi_pi_online(pip, 0);
22227c478bd9Sstevel@tonic-gate
22237c478bd9Sstevel@tonic-gate if (rval != MDI_SUCCESS) {
22247c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tioc_create_pi: "
22257c478bd9Sstevel@tonic-gate "mdi_pi_online() failed ioc dip %p, rval %d",
22267c478bd9Sstevel@tonic-gate cdip, rval);
22277c478bd9Sstevel@tonic-gate rval = IBNEX_FAILURE;
222800a3eaf3SRamaswamy Tummala if (create_prop) {
222900a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, NULL);
223000a3eaf3SRamaswamy Tummala ddi_prop_remove_all(cdip);
223100a3eaf3SRamaswamy Tummala ibnex_delete_ioc_node_data(node_data);
223200a3eaf3SRamaswamy Tummala *node_valid = 0;
223300a3eaf3SRamaswamy Tummala (void) ibnex_offline_childdip(cdip);
223400a3eaf3SRamaswamy Tummala } else
223500a3eaf3SRamaswamy Tummala (void) mdi_pi_free(pip, 0);
22367c478bd9Sstevel@tonic-gate } else
22377c478bd9Sstevel@tonic-gate rval = IBNEX_SUCCESS;
22389d3d2ed0Shiremath
223900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_create_pi ret %x", rval);
22407c478bd9Sstevel@tonic-gate return (rval);
22417c478bd9Sstevel@tonic-gate }
22427c478bd9Sstevel@tonic-gate
22437c478bd9Sstevel@tonic-gate
22447c478bd9Sstevel@tonic-gate /*
22457c478bd9Sstevel@tonic-gate * ibnex_create_ioc_node_prop()
22467c478bd9Sstevel@tonic-gate * Create IOC device node properties
22477c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
22487c478bd9Sstevel@tonic-gate */
22497c478bd9Sstevel@tonic-gate static int
ibnex_create_ioc_node_prop(ibdm_ioc_info_t * ioc_info,dev_info_t * cdip)22507c478bd9Sstevel@tonic-gate ibnex_create_ioc_node_prop(ibdm_ioc_info_t *ioc_info, dev_info_t *cdip)
22517c478bd9Sstevel@tonic-gate {
22527c478bd9Sstevel@tonic-gate uint16_t capabilities;
22537c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile = &ioc_info->ioc_profile;
22547c478bd9Sstevel@tonic-gate
22557c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_node_prop");
22567c478bd9Sstevel@tonic-gate
22577c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_compatible_prop(cdip,
22587c478bd9Sstevel@tonic-gate ioc_profile) != IBNEX_SUCCESS) {
22597c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22607c478bd9Sstevel@tonic-gate }
22617c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_iou_dc_valid) &&
22627c478bd9Sstevel@tonic-gate (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "iou-diagcode",
22637c478bd9Sstevel@tonic-gate ioc_info->ioc_iou_diagcode)) != DDI_PROP_SUCCESS) {
22647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
22657c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: iou-diagcode create failed");
22667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22677c478bd9Sstevel@tonic-gate }
22687c478bd9Sstevel@tonic-gate if ((ioc_info->ioc_diagdeviceid) && (ioc_info->ioc_dc_valid)) {
22697c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "ioc-diagcode",
22707c478bd9Sstevel@tonic-gate ioc_info->ioc_diagcode) != DDI_PROP_SUCCESS) {
22717c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
22727c478bd9Sstevel@tonic-gate "ioc-diagcode create failed");
22737c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22747c478bd9Sstevel@tonic-gate }
22757c478bd9Sstevel@tonic-gate }
22767c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-queue-depth",
22777c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_read_qdepth) != DDI_PROP_SUCCESS) {
22787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
22797c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: rdma-queue-depth create failed");
22807c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22817c478bd9Sstevel@tonic-gate }
22827c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "rdma-transfer-size",
22837c478bd9Sstevel@tonic-gate ioc_profile->ioc_rdma_xfer_sz) != DDI_PROP_SUCCESS) {
22847c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcreate_ioc_node_prop: "
22857c478bd9Sstevel@tonic-gate "rdma-transfer-size create failed");
22867c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22877c478bd9Sstevel@tonic-gate }
22887c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-message-size",
22897c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_sz) != DDI_PROP_SUCCESS) {
22907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
22917c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-message-size create failed");
22927c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22937c478bd9Sstevel@tonic-gate }
22947c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "send-queue-depth",
22957c478bd9Sstevel@tonic-gate ioc_profile->ioc_send_msg_qdepth) != DDI_PROP_SUCCESS) {
22967c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
22977c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: send-queue-depth create failed");
22987c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
22997c478bd9Sstevel@tonic-gate }
23007c478bd9Sstevel@tonic-gate
23017c478bd9Sstevel@tonic-gate capabilities = (ioc_profile->ioc_ctrl_opcap_mask << 8);
23027c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip,
23037c478bd9Sstevel@tonic-gate "capabilities", capabilities) != DDI_PROP_SUCCESS) {
23047c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23057c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: capabilities create failed");
23067c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23077c478bd9Sstevel@tonic-gate }
23087c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, cdip, "id-string",
23097c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string) != DDI_PROP_SUCCESS) {
23107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23117c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: id-string failed");
23127c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23137c478bd9Sstevel@tonic-gate }
23147c478bd9Sstevel@tonic-gate
23157c478bd9Sstevel@tonic-gate /*
23167c478bd9Sstevel@tonic-gate * Create properties to represent all the service entries supported
23177c478bd9Sstevel@tonic-gate * by the IOC. Each service entry consists of 1) Service ID (64 bits)
23187c478bd9Sstevel@tonic-gate * and 2) Service name (40 bytes). The service entry table is
23197c478bd9Sstevel@tonic-gate * represented by two properties, service-ids and service-names. The
23207c478bd9Sstevel@tonic-gate * service-id property is a array of int64's and service names is
23217c478bd9Sstevel@tonic-gate * array of strings. The first element in the "service-ids" property
23227c478bd9Sstevel@tonic-gate * corresponds to first string in the "service-names" and so on.
23237c478bd9Sstevel@tonic-gate */
23247c478bd9Sstevel@tonic-gate if ((ioc_profile->ioc_service_entries != 0) &&
23257c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(cdip, ioc_info) != IBNEX_SUCCESS))
23267c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23277c478bd9Sstevel@tonic-gate
23287c478bd9Sstevel@tonic-gate /* Create destination port GID properties */
23297c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(cdip, ioc_info) != IBNEX_SUCCESS)
23307c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23317c478bd9Sstevel@tonic-gate
23327c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol-version",
23337c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol_ver) != DDI_PROP_SUCCESS) {
23347c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23357c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol-version create failed");
23367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23377c478bd9Sstevel@tonic-gate }
23387c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "protocol",
23397c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol) != DDI_PROP_SUCCESS) {
23407c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23417c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed");
23427c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23437c478bd9Sstevel@tonic-gate }
23447c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-subclass",
23457c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_subclass) != DDI_PROP_SUCCESS) {
23467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23477c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subclass create failed");
23487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23497c478bd9Sstevel@tonic-gate }
23507c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "io-class",
23517c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class) != DDI_PROP_SUCCESS) {
23527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23537c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: class prop create failed");
23547c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23557c478bd9Sstevel@tonic-gate }
23567c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-id",
23577c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_id) != DDI_PROP_SUCCESS) {
23587c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23597c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsys_id create failed");
23607c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23617c478bd9Sstevel@tonic-gate }
23627c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "subsystem-vendor-id",
23637c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid) != DDI_PROP_SUCCESS) {
23647c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23657c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: subsystem vendor create failed");
23667c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23677c478bd9Sstevel@tonic-gate }
23687c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, cdip, "ioc-guid",
23697c478bd9Sstevel@tonic-gate ioc_profile->ioc_guid) != DDI_PROP_SUCCESS) {
23707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23717c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: protocol create failed");
23727c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23737c478bd9Sstevel@tonic-gate }
23747c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-version",
23757c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver) != DDI_PROP_SUCCESS) {
23767c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23777c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed");
23787c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23797c478bd9Sstevel@tonic-gate }
23807c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "device-id",
23817c478bd9Sstevel@tonic-gate ioc_profile->ioc_deviceid) != DDI_PROP_SUCCESS) {
23827c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23837c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: product-id create failed");
23847c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23857c478bd9Sstevel@tonic-gate }
23867c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "vendor-id",
23877c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid) != DDI_PROP_SUCCESS) {
23887c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
23897c478bd9Sstevel@tonic-gate "\tcreate_ioc_node_prop: vendor-id create failed");
23907c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
23917c478bd9Sstevel@tonic-gate }
23927c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
23937c478bd9Sstevel@tonic-gate }
23947c478bd9Sstevel@tonic-gate
23957c478bd9Sstevel@tonic-gate
23967c478bd9Sstevel@tonic-gate /*
23977c478bd9Sstevel@tonic-gate * ibnex_create_ioc_portgid_prop()
23987c478bd9Sstevel@tonic-gate * Creates "port-entries", "port-list" properties
23997c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
24007c478bd9Sstevel@tonic-gate */
24017c478bd9Sstevel@tonic-gate static int
ibnex_create_ioc_portgid_prop(dev_info_t * cdip,ibdm_ioc_info_t * ioc_info)24027c478bd9Sstevel@tonic-gate ibnex_create_ioc_portgid_prop(
24037c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
24047c478bd9Sstevel@tonic-gate {
24057c478bd9Sstevel@tonic-gate uint64_t *port_gids;
24067c478bd9Sstevel@tonic-gate int length, ii, jj;
24077c478bd9Sstevel@tonic-gate int prop_len;
24087c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
24097c478bd9Sstevel@tonic-gate
24107c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_portgid_prop");
24117c478bd9Sstevel@tonic-gate
24127c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(cdip);
24137c478bd9Sstevel@tonic-gate ASSERT(node_data);
24147c478bd9Sstevel@tonic-gate
24157c478bd9Sstevel@tonic-gate prop_len = (ioc_info->ioc_nportgids != 0) ?
24167c478bd9Sstevel@tonic-gate (2 * ioc_info->ioc_nportgids) : 1;
24177c478bd9Sstevel@tonic-gate length = sizeof (uint64_t) * prop_len;
24187c478bd9Sstevel@tonic-gate port_gids = kmem_zalloc(length, KM_SLEEP);
24197c478bd9Sstevel@tonic-gate
24207c478bd9Sstevel@tonic-gate for (ii = 0, jj = 0; ii < ioc_info->ioc_nportgids; ii++) {
24217c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_hi;
24227c478bd9Sstevel@tonic-gate port_gids[jj++] = ioc_info->ioc_gid_list[ii].gid_dgid_lo;
24237c478bd9Sstevel@tonic-gate }
24247c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip, "port-list",
24257c478bd9Sstevel@tonic-gate (int64_t *)port_gids, prop_len) != DDI_PROP_SUCCESS) {
24267c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
24277c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-list create failed");
24287c478bd9Sstevel@tonic-gate kmem_free(port_gids, length);
24297c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
24307c478bd9Sstevel@tonic-gate }
24317c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, cdip, "port-entries",
24327c478bd9Sstevel@tonic-gate ioc_info->ioc_nportgids) != DDI_PROP_SUCCESS) {
24337c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
24347c478bd9Sstevel@tonic-gate "\tcreate_ioc_portgid_prop: port-entries create failed");
24357c478bd9Sstevel@tonic-gate kmem_free(port_gids, length);
24367c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
24377c478bd9Sstevel@tonic-gate }
24387c478bd9Sstevel@tonic-gate
24397c478bd9Sstevel@tonic-gate kmem_free(port_gids, length);
24407c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
24417c478bd9Sstevel@tonic-gate }
24427c478bd9Sstevel@tonic-gate
24437c478bd9Sstevel@tonic-gate
24447c478bd9Sstevel@tonic-gate /*
24457c478bd9Sstevel@tonic-gate * ibnex_create_ioc_srv_props()
24467c478bd9Sstevel@tonic-gate * Creates "service-name" and "service-id" properties
24477c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
24487c478bd9Sstevel@tonic-gate */
24497c478bd9Sstevel@tonic-gate static int
ibnex_create_ioc_srv_props(dev_info_t * cdip,ibdm_ioc_info_t * ioc_info)24507c478bd9Sstevel@tonic-gate ibnex_create_ioc_srv_props(
24517c478bd9Sstevel@tonic-gate dev_info_t *cdip, ibdm_ioc_info_t *ioc_info)
24527c478bd9Sstevel@tonic-gate {
24537c478bd9Sstevel@tonic-gate int length, ii;
24547c478bd9Sstevel@tonic-gate uint64_t *srv_id;
24557c478bd9Sstevel@tonic-gate char *temp, *srv_names[IB_DM_MAX_IOCS_IN_IOU];
24567c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *profile = &ioc_info->ioc_profile;
24577c478bd9Sstevel@tonic-gate ibdm_srvents_info_t *srvents = ioc_info->ioc_serv;
24587c478bd9Sstevel@tonic-gate
24597c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props");
24607c478bd9Sstevel@tonic-gate
24617c478bd9Sstevel@tonic-gate length = profile->ioc_service_entries * sizeof (ib_dm_srv_t);
24627c478bd9Sstevel@tonic-gate srv_id = kmem_zalloc(length, KM_SLEEP);
24637c478bd9Sstevel@tonic-gate temp = (char *)((char *)srv_id + (8 * profile->ioc_service_entries));
24647c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) {
24657c478bd9Sstevel@tonic-gate srv_names[ii] = (char *)temp + (ii * IB_DM_MAX_SVC_NAME_LEN);
24667c478bd9Sstevel@tonic-gate }
24677c478bd9Sstevel@tonic-gate
24687c478bd9Sstevel@tonic-gate for (ii = 0; ii < profile->ioc_service_entries; ii++) {
24697c478bd9Sstevel@tonic-gate srv_id[ii] = srvents[ii].se_attr.srv_id;
24707c478bd9Sstevel@tonic-gate bcopy(srvents[ii].se_attr.srv_name,
24717c478bd9Sstevel@tonic-gate srv_names[ii], (IB_DM_MAX_SVC_NAME_LEN - 1));
24727c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
24737c478bd9Sstevel@tonic-gate "Service Names : %s", srv_names[ii]);
24747c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_ioc_srv_props "
24759d3d2ed0Shiremath "Service ID : %llX", srv_id[ii]);
24767c478bd9Sstevel@tonic-gate }
24777c478bd9Sstevel@tonic-gate
24787c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE, cdip,
24797c478bd9Sstevel@tonic-gate "service-id", (int64_t *)srv_id,
24807c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
24817c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
24827c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-id create failed");
24837c478bd9Sstevel@tonic-gate kmem_free(srv_id, length);
24847c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
24857c478bd9Sstevel@tonic-gate }
24867c478bd9Sstevel@tonic-gate
24877c478bd9Sstevel@tonic-gate if (ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
24887c478bd9Sstevel@tonic-gate "service-name", (char **)srv_names,
24897c478bd9Sstevel@tonic-gate profile->ioc_service_entries) != DDI_PROP_SUCCESS) {
24907c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
24917c478bd9Sstevel@tonic-gate "\tcreate_ioc_srv_props: service-name create failed");
24927c478bd9Sstevel@tonic-gate kmem_free(srv_id, length);
24937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
24947c478bd9Sstevel@tonic-gate }
24957c478bd9Sstevel@tonic-gate kmem_free(srv_id, length);
24967c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
24977c478bd9Sstevel@tonic-gate }
24987c478bd9Sstevel@tonic-gate
24997c478bd9Sstevel@tonic-gate
25007c478bd9Sstevel@tonic-gate /*
25017c478bd9Sstevel@tonic-gate * ibnex_create_ioc_compatible_prop()
25027c478bd9Sstevel@tonic-gate * Creates "compatible" property values
25037c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
25047c478bd9Sstevel@tonic-gate */
25057c478bd9Sstevel@tonic-gate static int
ibnex_create_ioc_compatible_prop(dev_info_t * cdip,ib_dm_ioc_ctrl_profile_t * ioc_profile)25067c478bd9Sstevel@tonic-gate ibnex_create_ioc_compatible_prop(
25077c478bd9Sstevel@tonic-gate dev_info_t *cdip, ib_dm_ioc_ctrl_profile_t *ioc_profile)
25087c478bd9Sstevel@tonic-gate {
25097c478bd9Sstevel@tonic-gate char *temp;
25107c478bd9Sstevel@tonic-gate int rval, ii;
25117c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_COMPAT_NAMES];
25127c478bd9Sstevel@tonic-gate
25137c478bd9Sstevel@tonic-gate /*
25147c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below:
25157c478bd9Sstevel@tonic-gate * Compatible Strings :
25167c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>S<subsys vid>s<subsys id>v<ver>
25177c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>S<subsys vid>s<subsys id>
25187c478bd9Sstevel@tonic-gate * 3. ib.V<vid>P<pid>v<ver>
25197c478bd9Sstevel@tonic-gate * 4. ib.V<vid>P<pid>
25207c478bd9Sstevel@tonic-gate * 5. ib.C<Class>c<Subclass>p<protocol>r<protocol ver>
25217c478bd9Sstevel@tonic-gate * 6. ib.C<Class>c<Subclass>p<protocol>
25227c478bd9Sstevel@tonic-gate *
25237c478bd9Sstevel@tonic-gate * Note:
25247c478bd9Sstevel@tonic-gate * All leading zeros must be present
25257c478bd9Sstevel@tonic-gate * All numeric values must specified in hex without prefix "0x"
25267c478bd9Sstevel@tonic-gate */
25277c478bd9Sstevel@tonic-gate
25287c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_COMPAT_PROP_SZ, KM_SLEEP);
25297c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
25307c478bd9Sstevel@tonic-gate compatible[ii] = temp + (ii * IBNEX_MAX_COMPAT_LEN);
25317c478bd9Sstevel@tonic-gate
25327c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
25337c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08xv%04x",
25347c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25357c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id,
25367c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver);
25377c478bd9Sstevel@tonic-gate
25387c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
25397c478bd9Sstevel@tonic-gate "ib.V%06xP%08xS%06xs%08x",
25407c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25417c478bd9Sstevel@tonic-gate ioc_profile->ioc_subsys_vendorid, ioc_profile->ioc_subsys_id);
25427c478bd9Sstevel@tonic-gate
25437c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
25447c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x",
25457c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid,
25467c478bd9Sstevel@tonic-gate ioc_profile->ioc_device_ver);
25477c478bd9Sstevel@tonic-gate
25487c478bd9Sstevel@tonic-gate (void) snprintf(compatible[3], IBNEX_MAX_COMPAT_LEN,
25497c478bd9Sstevel@tonic-gate "ib.V%06xP%08x",
25507c478bd9Sstevel@tonic-gate ioc_profile->ioc_vendorid, ioc_profile->ioc_deviceid);
25517c478bd9Sstevel@tonic-gate
25527c478bd9Sstevel@tonic-gate (void) snprintf(compatible[4], IBNEX_MAX_COMPAT_LEN,
25537c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04xr%04x",
25547c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
25557c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol, ioc_profile->ioc_protocol_ver);
25567c478bd9Sstevel@tonic-gate
25577c478bd9Sstevel@tonic-gate (void) snprintf(compatible[5], IBNEX_MAX_COMPAT_LEN,
25587c478bd9Sstevel@tonic-gate "ib.C%04xc%04xp%04x",
25597c478bd9Sstevel@tonic-gate ioc_profile->ioc_io_class, ioc_profile->ioc_io_subclass,
25607c478bd9Sstevel@tonic-gate ioc_profile->ioc_protocol);
25617c478bd9Sstevel@tonic-gate for (ii = 0; ii < IBNEX_MAX_COMPAT_NAMES; ii++)
25627c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[ii]);
25637c478bd9Sstevel@tonic-gate
25647c478bd9Sstevel@tonic-gate /* Create the compatible property for child cdip */
25657c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, cdip,
25667c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_COMPAT_NAMES);
25677c478bd9Sstevel@tonic-gate
25687c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) {
25697c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcompatible prop_create failed");
25707c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
25717c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
25727c478bd9Sstevel@tonic-gate }
25737c478bd9Sstevel@tonic-gate
25747c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_COMPAT_PROP_SZ);
25757c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
25767c478bd9Sstevel@tonic-gate }
25777c478bd9Sstevel@tonic-gate
25787c478bd9Sstevel@tonic-gate
25797c478bd9Sstevel@tonic-gate static void
ibnex_ioc_node_cleanup()25807c478bd9Sstevel@tonic-gate ibnex_ioc_node_cleanup()
25817c478bd9Sstevel@tonic-gate {
25827c478bd9Sstevel@tonic-gate ibnex_node_data_t *node, *delete;
25837c478bd9Sstevel@tonic-gate
25847c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
25857c478bd9Sstevel@tonic-gate for (node = ibnex.ibnex_ioc_node_head; node; ) {
25867c478bd9Sstevel@tonic-gate delete = node;
25877c478bd9Sstevel@tonic-gate node = node->node_next;
25887c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
25897c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(delete);
25907c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
25917c478bd9Sstevel@tonic-gate }
25927c478bd9Sstevel@tonic-gate }
25937c478bd9Sstevel@tonic-gate
25947c478bd9Sstevel@tonic-gate /*
25957c478bd9Sstevel@tonic-gate * ibnex_delete_ioc_node_data()
25967c478bd9Sstevel@tonic-gate * Delete IOC node from the list
25977c478bd9Sstevel@tonic-gate */
25987c478bd9Sstevel@tonic-gate static void
ibnex_delete_ioc_node_data(ibnex_node_data_t * node)25997c478bd9Sstevel@tonic-gate ibnex_delete_ioc_node_data(ibnex_node_data_t *node)
26007c478bd9Sstevel@tonic-gate {
26017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data:");
26027c478bd9Sstevel@tonic-gate
26037c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
26047c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL)) {
26057c478bd9Sstevel@tonic-gate ASSERT(ibnex.ibnex_ioc_node_head == node);
26067c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = NULL;
26077c478bd9Sstevel@tonic-gate } else if (node->node_next == NULL)
26087c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL;
26097c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) {
26107c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL;
26117c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node->node_next;
26127c478bd9Sstevel@tonic-gate } else {
26137c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next;
26147c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev;
26157c478bd9Sstevel@tonic-gate }
26167c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdelete_ioc_node_data: head %p",
26177c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head);
26187c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
26197c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t));
26207c478bd9Sstevel@tonic-gate }
26217c478bd9Sstevel@tonic-gate
26227c478bd9Sstevel@tonic-gate
26237c478bd9Sstevel@tonic-gate /*
26247c478bd9Sstevel@tonic-gate * ibnex_dm_callback()
26257c478bd9Sstevel@tonic-gate *
26267c478bd9Sstevel@tonic-gate * This routine is registered with the IBDM during IB nexus attach. It
26277c478bd9Sstevel@tonic-gate * is called by the IBDM module when it discovers
26287c478bd9Sstevel@tonic-gate * New HCA port
26297c478bd9Sstevel@tonic-gate * HCA port removal
26307c478bd9Sstevel@tonic-gate * New HCA added
26317c478bd9Sstevel@tonic-gate * HCA removed
26327c478bd9Sstevel@tonic-gate */
26337c478bd9Sstevel@tonic-gate void
ibnex_dm_callback(void * arg,ibdm_events_t flag)26347c478bd9Sstevel@tonic-gate ibnex_dm_callback(void *arg, ibdm_events_t flag)
26357c478bd9Sstevel@tonic-gate {
26367c478bd9Sstevel@tonic-gate char hca_guid[IBNEX_HCAGUID_STRSZ];
26377c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_list, *ioc;
26387c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
2639dcf1eb70SSudhakar Dindukurti dev_info_t *phci;
26401cfa752fSRamaswamy Tummala ib_guid_t *guid;
26417c478bd9Sstevel@tonic-gate
26427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: attr %p event %x", arg, flag);
26437c478bd9Sstevel@tonic-gate
26447c478bd9Sstevel@tonic-gate switch (flag) {
26457c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_ADDED:
26467c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
26477c478bd9Sstevel@tonic-gate (*(longlong_t *)arg));
26487c478bd9Sstevel@tonic-gate /* Create a devctl minor node for the HCA's port */
26497c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(ibnex.ibnex_dip, hca_guid, S_IFCHR,
26507c478bd9Sstevel@tonic-gate ddi_get_instance(ibnex.ibnex_dip),
26517c478bd9Sstevel@tonic-gate DDI_NT_IB_ATTACHMENT_POINT, 0) != DDI_SUCCESS) {
26527c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
26537c478bd9Sstevel@tonic-gate "create minor node for port w/ guid %s", hca_guid);
26547c478bd9Sstevel@tonic-gate }
26557c478bd9Sstevel@tonic-gate
26561cfa752fSRamaswamy Tummala guid = kmem_alloc(sizeof (ib_guid_t), KM_SLEEP);
26571cfa752fSRamaswamy Tummala *guid = *(ib_guid_t *)arg;
26581cfa752fSRamaswamy Tummala if (ddi_taskq_dispatch(ibnex.ibnex_taskq_id,
26591cfa752fSRamaswamy Tummala ibnex_handle_hca_attach, guid, DDI_NOSLEEP)
26601cfa752fSRamaswamy Tummala != DDI_SUCCESS) {
266103c76a6eSRajkumar Sivaprakasam kmem_free(guid, sizeof (ib_guid_t));
26621cfa752fSRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tdm_callback: failed to "
26631cfa752fSRamaswamy Tummala "dispatch HCA add event for guid %s", hca_guid);
26641cfa752fSRamaswamy Tummala }
26651cfa752fSRamaswamy Tummala
26667c478bd9Sstevel@tonic-gate break;
26677c478bd9Sstevel@tonic-gate
26687c478bd9Sstevel@tonic-gate case IBDM_EVENT_HCA_REMOVED:
26697c478bd9Sstevel@tonic-gate (void) snprintf(hca_guid, IBNEX_HCAGUID_STRSZ, "%llX",
26707c478bd9Sstevel@tonic-gate (*(longlong_t *)arg));
26717c478bd9Sstevel@tonic-gate ddi_remove_minor_node(ibnex.ibnex_dip, hca_guid);
26727c478bd9Sstevel@tonic-gate break;
26737c478bd9Sstevel@tonic-gate
26747c478bd9Sstevel@tonic-gate case IBDM_EVENT_IOC_PROP_UPDATE:
26757c478bd9Sstevel@tonic-gate ioc = ioc_list = (ibdm_ioc_info_t *)arg;
26767c478bd9Sstevel@tonic-gate if (ioc_list == NULL)
26777c478bd9Sstevel@tonic-gate break;
26787c478bd9Sstevel@tonic-gate
26797c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
26807c478bd9Sstevel@tonic-gate while (ioc_list) {
26817c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(
26827c478bd9Sstevel@tonic-gate IBNEX_IOC_NODE, ioc_list, 0, 0)) != NULL &&
26837c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) {
26847c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_list);
26857c478bd9Sstevel@tonic-gate }
26867c478bd9Sstevel@tonic-gate ioc_list = ioc_list->ioc_next;
26877c478bd9Sstevel@tonic-gate }
26887c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
26897c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc);
2690dcf1eb70SSudhakar Dindukurti break;
2691dcf1eb70SSudhakar Dindukurti
2692dcf1eb70SSudhakar Dindukurti case IBDM_EVENT_PORT_UP:
2693dcf1eb70SSudhakar Dindukurti case IBDM_EVENT_PORT_PKEY_CHANGE:
2694dcf1eb70SSudhakar Dindukurti phci = ibtl_ibnex_hcaguid2dip(*(longlong_t *)arg);
2695c1374a13SSurya Prakki (void) devfs_clean(phci, NULL, 0);
2696dcf1eb70SSudhakar Dindukurti break;
2697dcf1eb70SSudhakar Dindukurti default:
2698dcf1eb70SSudhakar Dindukurti break;
2699dcf1eb70SSudhakar Dindukurti
27007c478bd9Sstevel@tonic-gate }
27017c478bd9Sstevel@tonic-gate }
27027c478bd9Sstevel@tonic-gate
27037c478bd9Sstevel@tonic-gate
27047c478bd9Sstevel@tonic-gate /*
27051cfa752fSRamaswamy Tummala * ibnex_get_node_and_dip_from_guid()
27061cfa752fSRamaswamy Tummala *
27071cfa752fSRamaswamy Tummala * Searches the linked list of the port nodes and returns the dip for
27081cfa752fSRamaswamy Tummala * the of the Port / Node guid requested.
27091cfa752fSRamaswamy Tummala * Returns NULL if not found
27101cfa752fSRamaswamy Tummala */
27111cfa752fSRamaswamy Tummala int
ibnex_get_node_and_dip_from_guid(ib_guid_t guid,int index,ib_pkey_t pkey,ibnex_node_data_t ** nodep,dev_info_t ** dip)27121cfa752fSRamaswamy Tummala ibnex_get_node_and_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
27131cfa752fSRamaswamy Tummala ibnex_node_data_t **nodep, dev_info_t **dip)
27141cfa752fSRamaswamy Tummala {
27151cfa752fSRamaswamy Tummala int node_index;
27161cfa752fSRamaswamy Tummala ib_guid_t node_guid;
27171cfa752fSRamaswamy Tummala ib_pkey_t node_pkey;
27181cfa752fSRamaswamy Tummala ibnex_node_data_t *node_data;
27191cfa752fSRamaswamy Tummala
27201cfa752fSRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
27211cfa752fSRamaswamy Tummala "\tget_node_and_dip_from_guid: guid = %llX", guid);
27221cfa752fSRamaswamy Tummala
27231cfa752fSRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
27241cfa752fSRamaswamy Tummala /* Search for a matching entry in internal lists */
27251cfa752fSRamaswamy Tummala node_data = ibnex.ibnex_port_node_head;
27261cfa752fSRamaswamy Tummala while (node_data) {
27271cfa752fSRamaswamy Tummala node_guid = node_data->node_data.port_node.port_guid;
27281cfa752fSRamaswamy Tummala node_index = node_data->node_data.port_node.port_commsvc_idx;
27291cfa752fSRamaswamy Tummala node_pkey = node_data->node_data.port_node.port_pkey;
27301cfa752fSRamaswamy Tummala if ((node_guid == guid) && (index == node_index) &&
27311cfa752fSRamaswamy Tummala (node_pkey == pkey)) {
27321cfa752fSRamaswamy Tummala break;
27331cfa752fSRamaswamy Tummala }
27341cfa752fSRamaswamy Tummala node_data = node_data->node_next;
27351cfa752fSRamaswamy Tummala }
27361cfa752fSRamaswamy Tummala
27371cfa752fSRamaswamy Tummala /* matching found with a valid dip */
27381cfa752fSRamaswamy Tummala if (node_data && node_data->node_dip) {
27391cfa752fSRamaswamy Tummala *nodep = node_data;
27401cfa752fSRamaswamy Tummala *dip = node_data->node_dip;
27411cfa752fSRamaswamy Tummala return (IBNEX_SUCCESS);
27421cfa752fSRamaswamy Tummala } else if (node_data && !node_data->node_dip) { /* dip is invalid */
27431cfa752fSRamaswamy Tummala *nodep = node_data;
27441cfa752fSRamaswamy Tummala *dip = NULL;
27451cfa752fSRamaswamy Tummala return (IBNEX_SUCCESS);
27461cfa752fSRamaswamy Tummala }
27471cfa752fSRamaswamy Tummala
27481cfa752fSRamaswamy Tummala /* no match found */
27491cfa752fSRamaswamy Tummala *nodep = NULL;
27501cfa752fSRamaswamy Tummala *dip = NULL;
27511cfa752fSRamaswamy Tummala return (IBNEX_FAILURE);
27521cfa752fSRamaswamy Tummala }
27531cfa752fSRamaswamy Tummala
27541cfa752fSRamaswamy Tummala /*
27557c478bd9Sstevel@tonic-gate * ibnex_get_dip_from_guid()
27567c478bd9Sstevel@tonic-gate *
27577c478bd9Sstevel@tonic-gate * Searches the linked list of the port nodes and returns the dip for
27587c478bd9Sstevel@tonic-gate * the of the Port / Node guid requested.
27597c478bd9Sstevel@tonic-gate * Returns NULL if not found
27607c478bd9Sstevel@tonic-gate */
27617c478bd9Sstevel@tonic-gate int
ibnex_get_dip_from_guid(ib_guid_t guid,int index,ib_pkey_t pkey,dev_info_t ** dip)27627c478bd9Sstevel@tonic-gate ibnex_get_dip_from_guid(ib_guid_t guid, int index, ib_pkey_t pkey,
27637c478bd9Sstevel@tonic-gate dev_info_t **dip)
27647c478bd9Sstevel@tonic-gate {
27657c478bd9Sstevel@tonic-gate int node_index;
27667c478bd9Sstevel@tonic-gate ib_guid_t node_guid;
27677c478bd9Sstevel@tonic-gate ib_pkey_t node_pkey;
27687c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
27697c478bd9Sstevel@tonic-gate
27707c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
27719d3d2ed0Shiremath "\tget_dip_from_guid: guid = %llX", guid);
27727c478bd9Sstevel@tonic-gate
27737c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
27747c478bd9Sstevel@tonic-gate /* Search for a matching entry in internal lists */
27757c478bd9Sstevel@tonic-gate node_data = ibnex.ibnex_port_node_head;
27767c478bd9Sstevel@tonic-gate while (node_data) {
27777c478bd9Sstevel@tonic-gate node_guid = node_data->node_data.port_node.port_guid;
27787c478bd9Sstevel@tonic-gate node_index = node_data->node_data.port_node.port_commsvc_idx;
27797c478bd9Sstevel@tonic-gate node_pkey = node_data->node_data.port_node.port_pkey;
27807c478bd9Sstevel@tonic-gate if ((node_guid == guid) && (index == node_index) &&
27817c478bd9Sstevel@tonic-gate (node_pkey == pkey)) {
27827c478bd9Sstevel@tonic-gate break;
27837c478bd9Sstevel@tonic-gate }
27847c478bd9Sstevel@tonic-gate node_data = node_data->node_next;
27857c478bd9Sstevel@tonic-gate }
27867c478bd9Sstevel@tonic-gate
27877c478bd9Sstevel@tonic-gate /* matching found with a valid dip */
27887c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) {
27897c478bd9Sstevel@tonic-gate *dip = node_data->node_dip;
27907c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
27917c478bd9Sstevel@tonic-gate } else if (node_data && !node_data->node_dip) { /* dip is invalid */
27927c478bd9Sstevel@tonic-gate *dip = NULL;
27937c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
27947c478bd9Sstevel@tonic-gate }
27957c478bd9Sstevel@tonic-gate
27967c478bd9Sstevel@tonic-gate /* no match found */
27977c478bd9Sstevel@tonic-gate *dip = NULL;
27987c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
27997c478bd9Sstevel@tonic-gate }
28007c478bd9Sstevel@tonic-gate
28017c478bd9Sstevel@tonic-gate
28027c478bd9Sstevel@tonic-gate /*
28037c478bd9Sstevel@tonic-gate * ibnex_comm_svc_init()
28047c478bd9Sstevel@tonic-gate * Read the property and cache the values in the global
28057c478bd9Sstevel@tonic-gate * structure.
28067c478bd9Sstevel@tonic-gate * Check for max allowed length (4 bytes) of service name
28077c478bd9Sstevel@tonic-gate * (each element of the property)
28087c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
28097c478bd9Sstevel@tonic-gate */
28107c478bd9Sstevel@tonic-gate static ibnex_rval_t
ibnex_comm_svc_init(char * property,ibnex_node_type_t type)28117c478bd9Sstevel@tonic-gate ibnex_comm_svc_init(char *property, ibnex_node_type_t type)
28127c478bd9Sstevel@tonic-gate {
28137c478bd9Sstevel@tonic-gate int i, len, count;
28147c478bd9Sstevel@tonic-gate int ncomm_svcs;
28157c478bd9Sstevel@tonic-gate char **comm_svcp;
28167c478bd9Sstevel@tonic-gate char **servicep = NULL;
28177c478bd9Sstevel@tonic-gate uint_t nservices = 0;
28187c478bd9Sstevel@tonic-gate int *valid = NULL;
28197c478bd9Sstevel@tonic-gate
28207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcomm_svc_init : %s property, type = %x",
28217c478bd9Sstevel@tonic-gate property, type);
28227c478bd9Sstevel@tonic-gate
28237c478bd9Sstevel@tonic-gate /* lookup the string array property */
28247c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, ibnex.ibnex_dip,
28257c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, property, &servicep, &nservices) !=
28267c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) {
28277c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\t%s property undefined", property);
28287c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
28297c478bd9Sstevel@tonic-gate }
28307c478bd9Sstevel@tonic-gate
28317c478bd9Sstevel@tonic-gate if (nservices)
28327c478bd9Sstevel@tonic-gate valid = kmem_zalloc(nservices * sizeof (int), KM_SLEEP);
28337c478bd9Sstevel@tonic-gate
28347c478bd9Sstevel@tonic-gate
28357c478bd9Sstevel@tonic-gate /* first read the file to get a count of valid service entries */
28367c478bd9Sstevel@tonic-gate for (ncomm_svcs = 0, count = 0; count < nservices; count++) {
28377c478bd9Sstevel@tonic-gate int j;
28387c478bd9Sstevel@tonic-gate
28397c478bd9Sstevel@tonic-gate len = strlen(servicep[count]);
284000a3eaf3SRamaswamy Tummala /*
284100a3eaf3SRamaswamy Tummala * ib.conf has NULL strings for port-svc-list &
284200a3eaf3SRamaswamy Tummala * hca-svc-list, by default. Do not have L2 message
284300a3eaf3SRamaswamy Tummala * for these.
284400a3eaf3SRamaswamy Tummala */
284500a3eaf3SRamaswamy Tummala if (len == 1 || len > 4) {
28467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
284700a3eaf3SRamaswamy Tummala "Service name %s for property %s invalid : "
284800a3eaf3SRamaswamy Tummala "length %d", servicep[count], property, len);
284900a3eaf3SRamaswamy Tummala continue;
285000a3eaf3SRamaswamy Tummala } else if (len == 0) {
28517c478bd9Sstevel@tonic-gate continue;
28527c478bd9Sstevel@tonic-gate }
28537c478bd9Sstevel@tonic-gate if (ibnex_unique_svcname(servicep[count]) != IBNEX_SUCCESS) {
28547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
28557c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique",
28567c478bd9Sstevel@tonic-gate servicep[count]);
28577c478bd9Sstevel@tonic-gate continue;
28587c478bd9Sstevel@tonic-gate }
28597c478bd9Sstevel@tonic-gate
28607c478bd9Sstevel@tonic-gate /*
28617c478bd9Sstevel@tonic-gate * ibnex_unique_svcname checks for uniqueness in service names
28627c478bd9Sstevel@tonic-gate * communication services fully initialized. Check uniqueness
28637c478bd9Sstevel@tonic-gate * in service names currently initialized.
28647c478bd9Sstevel@tonic-gate */
28657c478bd9Sstevel@tonic-gate for (j = 0; j < count; j++)
28667c478bd9Sstevel@tonic-gate if (valid[j] && strncmp(servicep[count],
28677c478bd9Sstevel@tonic-gate servicep[j], 4) == 0) {
28687c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcomm_svc_init : "
28697c478bd9Sstevel@tonic-gate "Service name %s invalid : Not unique",
28707c478bd9Sstevel@tonic-gate servicep[count]);
28717c478bd9Sstevel@tonic-gate continue;
28727c478bd9Sstevel@tonic-gate }
28737c478bd9Sstevel@tonic-gate
28747c478bd9Sstevel@tonic-gate valid[count] = 1;
28757c478bd9Sstevel@tonic-gate ncomm_svcs++;
28767c478bd9Sstevel@tonic-gate }
28777c478bd9Sstevel@tonic-gate
28787c478bd9Sstevel@tonic-gate /* if no valid entries found, bailout */
28797c478bd9Sstevel@tonic-gate if (nservices == 0 || ncomm_svcs == 0) {
28807c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tNo %s entries found", property);
28817c478bd9Sstevel@tonic-gate ddi_prop_free(servicep); /* free the property */
28827c478bd9Sstevel@tonic-gate if (valid)
28837c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int));
28847c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
28857c478bd9Sstevel@tonic-gate }
28867c478bd9Sstevel@tonic-gate
28877c478bd9Sstevel@tonic-gate comm_svcp = kmem_zalloc((ncomm_svcs * sizeof (char *)), KM_SLEEP);
28887c478bd9Sstevel@tonic-gate if (type == IBNEX_PORT_COMMSVC_NODE) {
28897c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = comm_svcp;
28907c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = ncomm_svcs;
28917c478bd9Sstevel@tonic-gate } else if (type == IBNEX_VPPA_COMMSVC_NODE) {
28927c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = comm_svcp;
28937c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = ncomm_svcs;
28947c478bd9Sstevel@tonic-gate } else if (type == IBNEX_HCASVC_COMMSVC_NODE) {
28957c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = comm_svcp;
28967c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = ncomm_svcs;
28977c478bd9Sstevel@tonic-gate }
28987c478bd9Sstevel@tonic-gate
28997c478bd9Sstevel@tonic-gate /* copy the services into an array of strings */
29007c478bd9Sstevel@tonic-gate for (i = 0, count = 0; count < nservices; count++) {
29017c478bd9Sstevel@tonic-gate if (valid[count] == 0) /* Skip invalid ones */
29027c478bd9Sstevel@tonic-gate continue;
29037c478bd9Sstevel@tonic-gate comm_svcp[i] = kmem_alloc(len + 1, KM_SLEEP);
29047c478bd9Sstevel@tonic-gate (void) strcpy(comm_svcp[i], servicep[count]);
29057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
29067c478bd9Sstevel@tonic-gate "\t\tService [%d]: %s", i, comm_svcp[i]);
29077c478bd9Sstevel@tonic-gate ++i;
29087c478bd9Sstevel@tonic-gate }
29097c478bd9Sstevel@tonic-gate ddi_prop_free(servicep);
29107c478bd9Sstevel@tonic-gate kmem_free(valid, nservices * sizeof (int));
29117c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
29127c478bd9Sstevel@tonic-gate }
29137c478bd9Sstevel@tonic-gate
29147c478bd9Sstevel@tonic-gate
29157c478bd9Sstevel@tonic-gate /*
29167c478bd9Sstevel@tonic-gate * ibnex_comm_svc_fini()
29177c478bd9Sstevel@tonic-gate * Deallocate all the memory allocated for the communication
29187c478bd9Sstevel@tonic-gate * service arrays.
29197c478bd9Sstevel@tonic-gate */
29207c478bd9Sstevel@tonic-gate static void
ibnex_comm_svc_fini()29217c478bd9Sstevel@tonic-gate ibnex_comm_svc_fini()
29227c478bd9Sstevel@tonic-gate {
29237c478bd9Sstevel@tonic-gate int index;
29247c478bd9Sstevel@tonic-gate
29257c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_num_comm_svcs; index++) {
29267c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names[index],
29277c478bd9Sstevel@tonic-gate (strlen(ibnex.ibnex_comm_svc_names[index]) + 1));
29287c478bd9Sstevel@tonic-gate }
29297c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names) {
29307c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_comm_svc_names,
29317c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs * sizeof (char *));
29327c478bd9Sstevel@tonic-gate }
29337c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nvppa_comm_svcs; index++) {
29347c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names[index],
29357c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_vppa_comm_svc_names[index]) +1);
29367c478bd9Sstevel@tonic-gate }
29377c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names) {
29387c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_vppa_comm_svc_names,
29397c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs * sizeof (char *));
29407c478bd9Sstevel@tonic-gate }
29417c478bd9Sstevel@tonic-gate for (index = 0; index < ibnex.ibnex_nhcasvc_comm_svcs; index++) {
29427c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names[index],
29437c478bd9Sstevel@tonic-gate strlen(ibnex.ibnex_hcasvc_comm_svc_names[index]) +1);
29447c478bd9Sstevel@tonic-gate }
29457c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names) {
29467c478bd9Sstevel@tonic-gate kmem_free(ibnex.ibnex_hcasvc_comm_svc_names,
29477c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs * sizeof (char *));
29487c478bd9Sstevel@tonic-gate }
29497c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names = NULL;
29507c478bd9Sstevel@tonic-gate ibnex.ibnex_num_comm_svcs = 0;
29517c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names = NULL;
29527c478bd9Sstevel@tonic-gate ibnex.ibnex_nvppa_comm_svcs = 0;
29537c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names = NULL;
29547c478bd9Sstevel@tonic-gate ibnex.ibnex_nhcasvc_comm_svcs = 0;
29557c478bd9Sstevel@tonic-gate }
29567c478bd9Sstevel@tonic-gate
29577c478bd9Sstevel@tonic-gate
29587c478bd9Sstevel@tonic-gate /*
29597c478bd9Sstevel@tonic-gate * ibnex_commsvc_initnode()
29607c478bd9Sstevel@tonic-gate * This routine is specific to port/VPPA node creation
29617c478bd9Sstevel@tonic-gate * Creates a device node for the comm service specified by commsvc_index
29627c478bd9Sstevel@tonic-gate * Creates all the device node properties
29637c478bd9Sstevel@tonic-gate * Allocates and initializes the node specific data
29647c478bd9Sstevel@tonic-gate * Binds the device driver of the device node
29657c478bd9Sstevel@tonic-gate * Returns "dev_info_t" of the child node or NULL in case of failure
29667c478bd9Sstevel@tonic-gate * Sets IBNEX_SUCCESS/IBNEX_FAILURE/IBNEX_BUSY in "rval" to reflect
29677c478bd9Sstevel@tonic-gate * if the operation was successful, failed or was not performed.
29687c478bd9Sstevel@tonic-gate */
29697c478bd9Sstevel@tonic-gate dev_info_t *
ibnex_commsvc_initnode(dev_info_t * parent,ibdm_port_attr_t * port_attr,int index,int node_type,ib_pkey_t pkey,int * rval,int flag)29707c478bd9Sstevel@tonic-gate ibnex_commsvc_initnode(dev_info_t *parent, ibdm_port_attr_t *port_attr,
29717c478bd9Sstevel@tonic-gate int index, int node_type, ib_pkey_t pkey, int *rval, int flag)
29727c478bd9Sstevel@tonic-gate {
29737c478bd9Sstevel@tonic-gate int ret;
29747c478bd9Sstevel@tonic-gate char *svcname;
29757c478bd9Sstevel@tonic-gate dev_info_t *cdip;
29767c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
297700a3eaf3SRamaswamy Tummala ibnex_port_node_t *port_node;
297800a3eaf3SRamaswamy Tummala char devname[MAXNAMELEN];
297951f34d4bSRajkumar Sivaprakasam int cdip_allocated = 0;
29807c478bd9Sstevel@tonic-gate
29817c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
29827c478bd9Sstevel@tonic-gate
29837c478bd9Sstevel@tonic-gate *rval = IBNEX_SUCCESS;
29847c478bd9Sstevel@tonic-gate
29857c478bd9Sstevel@tonic-gate /*
29867c478bd9Sstevel@tonic-gate * prevent any races
29877c478bd9Sstevel@tonic-gate * we have seen this node_data and it has been initialized
29887c478bd9Sstevel@tonic-gate * Note that node_dip is already NULL if unconfigure is in
29897c478bd9Sstevel@tonic-gate * progress.
29907c478bd9Sstevel@tonic-gate */
29917c478bd9Sstevel@tonic-gate node_data = ibnex_is_node_data_present(node_type, (void *)port_attr,
29927c478bd9Sstevel@tonic-gate index, pkey);
299300a3eaf3SRamaswamy Tummala
299400a3eaf3SRamaswamy Tummala /*
299500a3eaf3SRamaswamy Tummala * If this node has been explicity unconfigured by cfgadm, then it can
299600a3eaf3SRamaswamy Tummala * be configured back again only by cfgadm configure.
299700a3eaf3SRamaswamy Tummala */
299800a3eaf3SRamaswamy Tummala if (node_data && (node_data->node_ap_state ==
299900a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED)) {
300000a3eaf3SRamaswamy Tummala *rval = IBNEX_FAILURE;
300100a3eaf3SRamaswamy Tummala return (NULL);
300200a3eaf3SRamaswamy Tummala }
300300a3eaf3SRamaswamy Tummala
30047c478bd9Sstevel@tonic-gate if (node_data && node_data->node_dip) {
30057c478bd9Sstevel@tonic-gate /*
30067c478bd9Sstevel@tonic-gate * Return NULL if another configure
30077c478bd9Sstevel@tonic-gate * operation is in progress
30087c478bd9Sstevel@tonic-gate */
30097c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_CONFIGURING) {
30107c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY;
30117c478bd9Sstevel@tonic-gate return (NULL);
30127c478bd9Sstevel@tonic-gate } else {
30137c478bd9Sstevel@tonic-gate return (node_data->node_dip);
30147c478bd9Sstevel@tonic-gate }
30157c478bd9Sstevel@tonic-gate } else if (node_data == NULL) {
30167c478bd9Sstevel@tonic-gate /* allocate a new ibnex_node_data_t */
30177c478bd9Sstevel@tonic-gate node_data = ibnex_init_child_nodedata(node_type, port_attr,
30187c478bd9Sstevel@tonic-gate index, pkey);
301900a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent;
30207c478bd9Sstevel@tonic-gate }
30217c478bd9Sstevel@tonic-gate
30227c478bd9Sstevel@tonic-gate /*
30237c478bd9Sstevel@tonic-gate * Return NULL if another unconfigure operation is in progress
30247c478bd9Sstevel@tonic-gate */
30257c478bd9Sstevel@tonic-gate if (node_data->node_state == IBNEX_CFGADM_UNCONFIGURING) {
30267c478bd9Sstevel@tonic-gate *rval = IBNEX_BUSY;
30277c478bd9Sstevel@tonic-gate return (NULL);
30287c478bd9Sstevel@tonic-gate }
30297c478bd9Sstevel@tonic-gate
30307c478bd9Sstevel@tonic-gate ASSERT(node_data->node_state != IBNEX_CFGADM_CONFIGURED);
30317c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING;
30327c478bd9Sstevel@tonic-gate
30337c478bd9Sstevel@tonic-gate switch (node_type) {
30347c478bd9Sstevel@tonic-gate case IBNEX_VPPA_COMMSVC_NODE :
30357c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_vppa_comm_svc_names[index];
303600a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node;
303700a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,%x,%s",
303800a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num,
303900a3eaf3SRamaswamy Tummala port_node->port_pkey, svcname);
30407c478bd9Sstevel@tonic-gate break;
30417c478bd9Sstevel@tonic-gate case IBNEX_HCASVC_COMMSVC_NODE :
30427c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_hcasvc_comm_svc_names[index];
304300a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node;
304400a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
304500a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
30467c478bd9Sstevel@tonic-gate break;
30477c478bd9Sstevel@tonic-gate case IBNEX_PORT_COMMSVC_NODE :
30487c478bd9Sstevel@tonic-gate svcname = ibnex.ibnex_comm_svc_names[index];
304900a3eaf3SRamaswamy Tummala port_node = &node_data->node_data.port_node;
305000a3eaf3SRamaswamy Tummala (void) snprintf(devname, MAXNAMELEN, "%s@%x,0,%s",
305100a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, port_node->port_num, svcname);
30527c478bd9Sstevel@tonic-gate break;
30537c478bd9Sstevel@tonic-gate default :
30547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "\tcommsvc_initnode:"
30557c478bd9Sstevel@tonic-gate "\tInvalid Node type");
30567c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE;
30577c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(node_data);
30587c478bd9Sstevel@tonic-gate return (NULL);
30597c478bd9Sstevel@tonic-gate }
30607c478bd9Sstevel@tonic-gate
306100a3eaf3SRamaswamy Tummala if ((cdip = ndi_devi_findchild(parent, devname)) != NULL) {
306200a3eaf3SRamaswamy Tummala if (i_ddi_devi_attached(cdip)) {
306300a3eaf3SRamaswamy Tummala node_data->node_dip = cdip;
306400a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent;
306500a3eaf3SRamaswamy Tummala node_data->node_state = IBNEX_CFGADM_CONFIGURED;
306600a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data);
306751f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: found "
306851f34d4bSRajkumar Sivaprakasam "attached cdip 0x%p for devname %s", cdip, devname);
306900a3eaf3SRamaswamy Tummala return (cdip);
307000a3eaf3SRamaswamy Tummala }
307100a3eaf3SRamaswamy Tummala } else {
307200a3eaf3SRamaswamy Tummala ndi_devi_alloc_sleep(parent,
307300a3eaf3SRamaswamy Tummala IBNEX_IBPORT_CNAME, (pnode_t)DEVI_SID_NODEID, &cdip);
307451f34d4bSRajkumar Sivaprakasam cdip_allocated = 1;
307500a3eaf3SRamaswamy Tummala }
307600a3eaf3SRamaswamy Tummala
307700a3eaf3SRamaswamy Tummala node_data->node_dip = cdip;
307800a3eaf3SRamaswamy Tummala ddi_set_parent_data(cdip, node_data);
307900a3eaf3SRamaswamy Tummala mutex_exit(&ibnex.ibnex_mutex);
308000a3eaf3SRamaswamy Tummala
308100a3eaf3SRamaswamy Tummala
30827c478bd9Sstevel@tonic-gate if (ibnex_create_port_node_prop(port_attr, cdip, svcname, pkey) ==
30837c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) {
30847c478bd9Sstevel@tonic-gate if (flag == IBNEX_DEVFS_ENUMERATE)
30857c478bd9Sstevel@tonic-gate ret = ndi_devi_bind_driver(cdip, 0);
30867c478bd9Sstevel@tonic-gate else
30877c478bd9Sstevel@tonic-gate ret = ndi_devi_online(cdip, 0);
30887c478bd9Sstevel@tonic-gate if (ret == NDI_SUCCESS) {
30897c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
30907c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURED;
309100a3eaf3SRamaswamy Tummala node_data->node_data.port_node.port_pdip = parent;
30927c478bd9Sstevel@tonic-gate return (cdip);
30937c478bd9Sstevel@tonic-gate }
309451f34d4bSRajkumar Sivaprakasam IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: BIND/ONLINE "
309551f34d4bSRajkumar Sivaprakasam "of cdip 0x%p for devname %s and flag %d failed", cdip,
309651f34d4bSRajkumar Sivaprakasam devname, flag);
30977c478bd9Sstevel@tonic-gate }
309800a3eaf3SRamaswamy Tummala
30997c478bd9Sstevel@tonic-gate *rval = IBNEX_FAILURE;
310051f34d4bSRajkumar Sivaprakasam node_data->node_dip = NULL;
310151f34d4bSRajkumar Sivaprakasam ddi_set_parent_data(cdip, NULL);
310251f34d4bSRajkumar Sivaprakasam if (cdip_allocated)
31037c478bd9Sstevel@tonic-gate (void) ndi_devi_free(cdip);
31047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
31057c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcommsvc_initnode: failure exit");
31067c478bd9Sstevel@tonic-gate return (NULL);
31077c478bd9Sstevel@tonic-gate }
31087c478bd9Sstevel@tonic-gate
31097c478bd9Sstevel@tonic-gate
31107c478bd9Sstevel@tonic-gate /*
31117c478bd9Sstevel@tonic-gate * ibnex_create_port_node_prop()
31127c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
31137c478bd9Sstevel@tonic-gate */
31147c478bd9Sstevel@tonic-gate static int
ibnex_create_port_node_prop(ibdm_port_attr_t * port_attr,dev_info_t * child_dip,char * srvname,ib_pkey_t pkey)31157c478bd9Sstevel@tonic-gate ibnex_create_port_node_prop(ibdm_port_attr_t *port_attr,
31167c478bd9Sstevel@tonic-gate dev_info_t *child_dip, char *srvname, ib_pkey_t pkey)
31177c478bd9Sstevel@tonic-gate {
31187c478bd9Sstevel@tonic-gate if (ibnex_create_port_compatible_prop(child_dip,
31197c478bd9Sstevel@tonic-gate srvname, port_attr) != DDI_PROP_SUCCESS) {
31207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31217c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: compatible update failed");
31227c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31237c478bd9Sstevel@tonic-gate }
31247c478bd9Sstevel@tonic-gate if ((pkey != 0) && (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
31257c478bd9Sstevel@tonic-gate "port-pkey", pkey) != DDI_PROP_SUCCESS)) {
31267c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31277c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed");
31287c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31297c478bd9Sstevel@tonic-gate }
31307c478bd9Sstevel@tonic-gate
31317c478bd9Sstevel@tonic-gate /*
31327c478bd9Sstevel@tonic-gate * For HCA_SVC device nodes, port_num will be 0.
31337c478bd9Sstevel@tonic-gate * Do not create the "port-number" & "port-guid" properties.
31347c478bd9Sstevel@tonic-gate */
31357c478bd9Sstevel@tonic-gate if (port_attr->pa_port_num != 0) {
31367c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
31377c478bd9Sstevel@tonic-gate "port-number", port_attr->pa_port_num) !=
31387c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) {
31397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31407c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-num update failed");
31417c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31427c478bd9Sstevel@tonic-gate }
31437c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
31447c478bd9Sstevel@tonic-gate "port-guid", port_attr->pa_port_guid) !=
31457c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) {
31467c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31477c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guid update failed");
31487c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31497c478bd9Sstevel@tonic-gate }
31507c478bd9Sstevel@tonic-gate } else {
31517c478bd9Sstevel@tonic-gate ibdm_hca_list_t *hca_list;
31527c478bd9Sstevel@tonic-gate
31537c478bd9Sstevel@tonic-gate /*
31547c478bd9Sstevel@tonic-gate * HCA_SVC nodes require "num-ports" & "port-guids"
31557c478bd9Sstevel@tonic-gate * properties.
31567c478bd9Sstevel@tonic-gate *
31577c478bd9Sstevel@tonic-gate * To create the num-ports & port-guids attribute :
31587c478bd9Sstevel@tonic-gate * 1. Get HCA list (ibdm_ibnex_get_hca_info_by_guid)
31597c478bd9Sstevel@tonic-gate * 2. Form the array of port GUIDs.
31607c478bd9Sstevel@tonic-gate */
31617c478bd9Sstevel@tonic-gate if ((hca_list = ibdm_ibnex_get_hca_info_by_guid(
31627c478bd9Sstevel@tonic-gate port_attr->pa_hca_guid)) == NULL) {
31637c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31647c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca_info_by_guid failed");
31657c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31667c478bd9Sstevel@tonic-gate }
31677c478bd9Sstevel@tonic-gate
31687c478bd9Sstevel@tonic-gate if (hca_list->hl_nports != 0) {
31697c478bd9Sstevel@tonic-gate ib_guid_t *port_guids;
31707c478bd9Sstevel@tonic-gate uint8_t portnum;
31717c478bd9Sstevel@tonic-gate
31727c478bd9Sstevel@tonic-gate ASSERT(hca_list->hl_port_attr != NULL);
31737c478bd9Sstevel@tonic-gate
31747c478bd9Sstevel@tonic-gate port_guids = kmem_zalloc(
31757c478bd9Sstevel@tonic-gate hca_list->hl_nports * sizeof (ib_guid_t),
31767c478bd9Sstevel@tonic-gate KM_SLEEP);
31777c478bd9Sstevel@tonic-gate
31787c478bd9Sstevel@tonic-gate for (portnum = 0; portnum < hca_list->hl_nports;
31797c478bd9Sstevel@tonic-gate portnum++) {
31807c478bd9Sstevel@tonic-gate port_guids[portnum] = (hca_list->
31817c478bd9Sstevel@tonic-gate hl_port_attr[portnum]).pa_port_guid;
31827c478bd9Sstevel@tonic-gate }
31837c478bd9Sstevel@tonic-gate
31847c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64_array(DDI_DEV_T_NONE,
31857c478bd9Sstevel@tonic-gate child_dip, "port-guids", (int64_t *)port_guids,
31867c478bd9Sstevel@tonic-gate hca_list->hl_nports) != DDI_PROP_SUCCESS) {
31877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
31887c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: port-guids "
31897c478bd9Sstevel@tonic-gate "create failed");
31907c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports *
31917c478bd9Sstevel@tonic-gate sizeof (ib_guid_t));
31927c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
31937c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
31947c478bd9Sstevel@tonic-gate }
31957c478bd9Sstevel@tonic-gate kmem_free(port_guids, hca_list->hl_nports *
31967c478bd9Sstevel@tonic-gate sizeof (ib_guid_t));
31977c478bd9Sstevel@tonic-gate }
31987c478bd9Sstevel@tonic-gate
31997c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
32007c478bd9Sstevel@tonic-gate "num-ports", hca_list->hl_nports) != DDI_PROP_SUCCESS) {
32017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32027c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: num-ports update failed");
32037c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
32047c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
32057c478bd9Sstevel@tonic-gate }
32067c478bd9Sstevel@tonic-gate ibdm_ibnex_free_hca_list(hca_list);
32077c478bd9Sstevel@tonic-gate }
32087c478bd9Sstevel@tonic-gate
32097c478bd9Sstevel@tonic-gate if (ndi_prop_update_int64(DDI_DEV_T_NONE, child_dip,
32107c478bd9Sstevel@tonic-gate "hca-guid", port_attr->pa_hca_guid) != DDI_PROP_SUCCESS) {
32117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32127c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: hca-guid update failed");
32137c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
32147c478bd9Sstevel@tonic-gate }
32157c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
32167c478bd9Sstevel@tonic-gate "product-id", port_attr->pa_productid) != DDI_PROP_SUCCESS) {
32177c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32187c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: product-id update failed");
32197c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
32207c478bd9Sstevel@tonic-gate }
32217c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip,
32227c478bd9Sstevel@tonic-gate "vendor-id", port_attr->pa_vendorid) != DDI_PROP_SUCCESS) {
32237c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32247c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: vendor-id update failed");
32257c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
32267c478bd9Sstevel@tonic-gate }
32277c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child_dip, "device-version",
32287c478bd9Sstevel@tonic-gate port_attr->pa_dev_version) != DDI_PROP_SUCCESS) {
32297c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32307c478bd9Sstevel@tonic-gate "\tcreate_port_node_prop: device-version update failed");
32317c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
32327c478bd9Sstevel@tonic-gate }
32337c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
32347c478bd9Sstevel@tonic-gate }
32357c478bd9Sstevel@tonic-gate
32367c478bd9Sstevel@tonic-gate
32377c478bd9Sstevel@tonic-gate /*
32387c478bd9Sstevel@tonic-gate * ibnex_str2int()
32397c478bd9Sstevel@tonic-gate * Utility function that converts a string of length "len" to
32407c478bd9Sstevel@tonic-gate * integer.
32417c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
32427c478bd9Sstevel@tonic-gate */
32431cfa752fSRamaswamy Tummala int
ibnex_str2int(char * c,int len,int * ret)32447c478bd9Sstevel@tonic-gate ibnex_str2int(char *c, int len, int *ret)
32457c478bd9Sstevel@tonic-gate {
32467c478bd9Sstevel@tonic-gate int intval = 0, ii;
32477c478bd9Sstevel@tonic-gate
32487c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tstr2int: Int string %s..", c);
32497c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS;
32507c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) {
32517c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9'))
32527c478bd9Sstevel@tonic-gate intval = intval * 10 +c[ii] - '0';
32537c478bd9Sstevel@tonic-gate else {
32547c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32557c478bd9Sstevel@tonic-gate "\tstr2int: Invalid integer string %s..", c);
32567c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE;
32577c478bd9Sstevel@tonic-gate break;
32587c478bd9Sstevel@tonic-gate }
32597c478bd9Sstevel@tonic-gate }
32607c478bd9Sstevel@tonic-gate
32617c478bd9Sstevel@tonic-gate return (intval);
32627c478bd9Sstevel@tonic-gate }
32637c478bd9Sstevel@tonic-gate
32647c478bd9Sstevel@tonic-gate
32657c478bd9Sstevel@tonic-gate /*
32667c478bd9Sstevel@tonic-gate * ibnex_str2hex()
32677c478bd9Sstevel@tonic-gate * Utility functions that converts a string of length "len" to
32687c478bd9Sstevel@tonic-gate * hex value. Note. This function does not handle strings which
32697c478bd9Sstevel@tonic-gate * string length more than 8 bytes.
32707c478bd9Sstevel@tonic-gate *
32717c478bd9Sstevel@tonic-gate */
32727c478bd9Sstevel@tonic-gate uint64_t
ibnex_str2hex(char * c,int len,int * ret)32737c478bd9Sstevel@tonic-gate ibnex_str2hex(char *c, int len, int *ret)
32747c478bd9Sstevel@tonic-gate {
32757c478bd9Sstevel@tonic-gate uint64_t hex = 0, ii;
32767c478bd9Sstevel@tonic-gate
32777c478bd9Sstevel@tonic-gate *ret = IBNEX_SUCCESS;
32787c478bd9Sstevel@tonic-gate for (ii = 0; ii < len; ii ++) {
32797c478bd9Sstevel@tonic-gate hex = (ii == 0) ? hex : (hex << 4);
32807c478bd9Sstevel@tonic-gate if ((c[ii] >= '0') && (c[ii] <= '9'))
32817c478bd9Sstevel@tonic-gate hex |= c[ii] - '0';
32827c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'a') && (c[ii] <= 'f'))
32837c478bd9Sstevel@tonic-gate hex |= c[ii] - 'a' + 10;
32847c478bd9Sstevel@tonic-gate else if ((c[ii] >= 'A') && (c[ii] <= 'F'))
32857c478bd9Sstevel@tonic-gate hex |= c[ii] - 'A' + 10;
32867c478bd9Sstevel@tonic-gate else {
32877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
32887c478bd9Sstevel@tonic-gate "\tstr2hex: Invalid integer string");
32897c478bd9Sstevel@tonic-gate *ret = IBNEX_FAILURE;
32907c478bd9Sstevel@tonic-gate break;
32917c478bd9Sstevel@tonic-gate }
32927c478bd9Sstevel@tonic-gate }
32937c478bd9Sstevel@tonic-gate
32947c478bd9Sstevel@tonic-gate return (hex);
32957c478bd9Sstevel@tonic-gate }
32967c478bd9Sstevel@tonic-gate
32977c478bd9Sstevel@tonic-gate
32987c478bd9Sstevel@tonic-gate /*
32997c478bd9Sstevel@tonic-gate * ibnex_create_port_compatible_prop()
33007c478bd9Sstevel@tonic-gate * Creates 'Compatibility' property for port / HCA_SVC device nodes
33017c478bd9Sstevel@tonic-gate * Returns IBNEX_SUCCESS/IBNEX_FAILURE
33027c478bd9Sstevel@tonic-gate */
33037c478bd9Sstevel@tonic-gate static int
ibnex_create_port_compatible_prop(dev_info_t * child_dip,char * comm_svcp,ibdm_port_attr_t * port_attr)33047c478bd9Sstevel@tonic-gate ibnex_create_port_compatible_prop(dev_info_t *child_dip,
33057c478bd9Sstevel@tonic-gate char *comm_svcp, ibdm_port_attr_t *port_attr)
33067c478bd9Sstevel@tonic-gate {
33077c478bd9Sstevel@tonic-gate int rval, i;
33087c478bd9Sstevel@tonic-gate char *temp;
33097c478bd9Sstevel@tonic-gate char *compatible[IBNEX_MAX_IBPORT_COMPAT_NAMES];
33107c478bd9Sstevel@tonic-gate
33117c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcreate_port_compatible_prop: Begin");
33127c478bd9Sstevel@tonic-gate /*
33137c478bd9Sstevel@tonic-gate * Initialize the "compatible" property string as below:
33147c478bd9Sstevel@tonic-gate * Compatible Strings :
33157c478bd9Sstevel@tonic-gate * 1. ib.V<vid>P<pid>v<revision>.<service name>.
33167c478bd9Sstevel@tonic-gate * 2. ib.V<vid>P<pid>.<service name>.
33177c478bd9Sstevel@tonic-gate * 3. ib.<service name>
33187c478bd9Sstevel@tonic-gate * Leading zeros must be present
33197c478bd9Sstevel@tonic-gate */
33207c478bd9Sstevel@tonic-gate temp = kmem_alloc(IBNEX_MAX_IBPORT_COMPAT_PROP_SZ, KM_SLEEP);
33217c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++) {
33227c478bd9Sstevel@tonic-gate compatible[i] = temp + (i * IBNEX_MAX_COMPAT_LEN);
33237c478bd9Sstevel@tonic-gate }
33247c478bd9Sstevel@tonic-gate
33257c478bd9Sstevel@tonic-gate (void) snprintf(compatible[0], IBNEX_MAX_COMPAT_LEN,
33267c478bd9Sstevel@tonic-gate "ib.V%06xP%08xv%04x.%s",
33277c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid,
33287c478bd9Sstevel@tonic-gate port_attr->pa_dev_version, comm_svcp);
33297c478bd9Sstevel@tonic-gate (void) snprintf(compatible[1], IBNEX_MAX_COMPAT_LEN,
33307c478bd9Sstevel@tonic-gate "ib.V%06xP%08x.%s",
33317c478bd9Sstevel@tonic-gate port_attr->pa_vendorid, port_attr->pa_productid,
33327c478bd9Sstevel@tonic-gate comm_svcp);
33337c478bd9Sstevel@tonic-gate (void) snprintf(compatible[2], IBNEX_MAX_COMPAT_LEN,
33347c478bd9Sstevel@tonic-gate "ib.%s", comm_svcp);
33357c478bd9Sstevel@tonic-gate
33367c478bd9Sstevel@tonic-gate for (i = 0; i < IBNEX_MAX_IBPORT_COMPAT_NAMES; i++)
33377c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tcompatible: %s", compatible[i]);
33387c478bd9Sstevel@tonic-gate
33397c478bd9Sstevel@tonic-gate rval = ndi_prop_update_string_array(DDI_DEV_T_NONE, child_dip,
33407c478bd9Sstevel@tonic-gate "compatible", (char **)compatible, IBNEX_MAX_IBPORT_COMPAT_NAMES);
33417c478bd9Sstevel@tonic-gate
33427c478bd9Sstevel@tonic-gate if (rval != DDI_PROP_SUCCESS) {
33437c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
33447c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
33457c478bd9Sstevel@tonic-gate }
33467c478bd9Sstevel@tonic-gate kmem_free(temp, IBNEX_MAX_IBPORT_COMPAT_PROP_SZ);
33477c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
33487c478bd9Sstevel@tonic-gate }
33497c478bd9Sstevel@tonic-gate
33507c478bd9Sstevel@tonic-gate
33517c478bd9Sstevel@tonic-gate /*
33527c478bd9Sstevel@tonic-gate * ibnex_delete_port_node_data()
33537c478bd9Sstevel@tonic-gate * Delete the parent private node data from the linked list
33547c478bd9Sstevel@tonic-gate * Deallocate the memory of the port/ioc attributes
33557c478bd9Sstevel@tonic-gate * Deallocate the memory of the node data
33567c478bd9Sstevel@tonic-gate */
33577c478bd9Sstevel@tonic-gate static void
ibnex_delete_port_node_data(ibnex_node_data_t * node)33587c478bd9Sstevel@tonic-gate ibnex_delete_port_node_data(ibnex_node_data_t *node)
33597c478bd9Sstevel@tonic-gate {
33607c478bd9Sstevel@tonic-gate if ((node->node_next == NULL) && (node->node_prev == NULL))
33617c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = NULL;
33627c478bd9Sstevel@tonic-gate else if (node->node_next == NULL)
33637c478bd9Sstevel@tonic-gate node->node_prev->node_next = NULL;
33647c478bd9Sstevel@tonic-gate else if (node->node_prev == NULL) {
33657c478bd9Sstevel@tonic-gate node->node_next->node_prev = NULL;
33667c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node->node_next;
33677c478bd9Sstevel@tonic-gate } else {
33687c478bd9Sstevel@tonic-gate node->node_prev->node_next = node->node_next;
33697c478bd9Sstevel@tonic-gate node->node_next->node_prev = node->node_prev;
33707c478bd9Sstevel@tonic-gate }
33717c478bd9Sstevel@tonic-gate kmem_free(node, sizeof (ibnex_node_data_t));
33727c478bd9Sstevel@tonic-gate }
33737c478bd9Sstevel@tonic-gate
33747c478bd9Sstevel@tonic-gate
33757c478bd9Sstevel@tonic-gate /*
33767c478bd9Sstevel@tonic-gate * ibnex_is_node_data_present()
33777c478bd9Sstevel@tonic-gate * Checks whether ibnex_node_t is created already
33787c478bd9Sstevel@tonic-gate * Returns ibnex_node_data_t if found, otherwise NULL
33797c478bd9Sstevel@tonic-gate */
33807c478bd9Sstevel@tonic-gate static ibnex_node_data_t *
ibnex_is_node_data_present(ibnex_node_type_t node_type,void * attr,int index,ib_pkey_t pkey)33817c478bd9Sstevel@tonic-gate ibnex_is_node_data_present(ibnex_node_type_t node_type, void *attr,
33827c478bd9Sstevel@tonic-gate int index, ib_pkey_t pkey)
33837c478bd9Sstevel@tonic-gate {
33847c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep;
33857c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
33867c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) {
33877c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_infop = (ibdm_ioc_info_t *)attr;
33887c478bd9Sstevel@tonic-gate
33897c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_ioc_node_head; nodep != NULL;
33907c478bd9Sstevel@tonic-gate nodep = nodep->node_next) {
33917c478bd9Sstevel@tonic-gate if (nodep->node_data.ioc_node.ioc_guid ==
33927c478bd9Sstevel@tonic-gate ioc_infop->ioc_profile.ioc_guid) {
33937c478bd9Sstevel@tonic-gate return (nodep);
33947c478bd9Sstevel@tonic-gate }
33957c478bd9Sstevel@tonic-gate }
33967c478bd9Sstevel@tonic-gate
33977c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) {
33987c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_pseudo_node_head; nodep;
33997c478bd9Sstevel@tonic-gate nodep = nodep->node_next)
34007c478bd9Sstevel@tonic-gate if (strcmp(nodep->node_data.pseudo_node.
34017c478bd9Sstevel@tonic-gate pseudo_node_addr, (char *)attr) == 0)
34027c478bd9Sstevel@tonic-gate return (nodep);
34037c478bd9Sstevel@tonic-gate
34047c478bd9Sstevel@tonic-gate } else {
34057c478bd9Sstevel@tonic-gate ibdm_port_attr_t *pattrp = (ibdm_port_attr_t *)attr;
34067c478bd9Sstevel@tonic-gate
34077c478bd9Sstevel@tonic-gate for (nodep = ibnex.ibnex_port_node_head; nodep != NULL;
34087c478bd9Sstevel@tonic-gate nodep = nodep->node_next) {
34097c478bd9Sstevel@tonic-gate if ((nodep->node_data.port_node.port_guid ==
34107c478bd9Sstevel@tonic-gate pattrp->pa_port_guid) &&
34117c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_commsvc_idx ==
34127c478bd9Sstevel@tonic-gate index) &&
34137c478bd9Sstevel@tonic-gate (nodep->node_data.port_node.port_pkey == pkey)) {
34147c478bd9Sstevel@tonic-gate return (nodep);
34157c478bd9Sstevel@tonic-gate }
34167c478bd9Sstevel@tonic-gate }
34177c478bd9Sstevel@tonic-gate }
34187c478bd9Sstevel@tonic-gate return (NULL);
34197c478bd9Sstevel@tonic-gate }
34207c478bd9Sstevel@tonic-gate
34217c478bd9Sstevel@tonic-gate /*
34227c478bd9Sstevel@tonic-gate * ibnex_lookup_unit_address_prop:
34237c478bd9Sstevel@tonic-gate *
34249d3d2ed0Shiremath * If property with name is found, return its value
34257c478bd9Sstevel@tonic-gate * otherwise return NULL.
34267c478bd9Sstevel@tonic-gate */
34277c478bd9Sstevel@tonic-gate static char *
ibnex_lookup_named_prop(ddi_prop_t * head,char * name)34289d3d2ed0Shiremath ibnex_lookup_named_prop(ddi_prop_t *head, char *name)
34297c478bd9Sstevel@tonic-gate {
34307c478bd9Sstevel@tonic-gate ddi_prop_t *propp;
34317c478bd9Sstevel@tonic-gate
34329d3d2ed0Shiremath /* Search the list of properties for name */
34337c478bd9Sstevel@tonic-gate for (propp = head; propp != NULL; propp = propp->prop_next) {
34349d3d2ed0Shiremath if (strcmp(propp->prop_name, name) != 0)
34357c478bd9Sstevel@tonic-gate continue;
34369d3d2ed0Shiremath /* named property should be valid and have a value */
34377c478bd9Sstevel@tonic-gate if (propp->prop_len <= 1)
34387c478bd9Sstevel@tonic-gate break;
34397c478bd9Sstevel@tonic-gate return ((char *)propp->prop_val);
34407c478bd9Sstevel@tonic-gate }
34417c478bd9Sstevel@tonic-gate
34427c478bd9Sstevel@tonic-gate return ((char *)0);
34437c478bd9Sstevel@tonic-gate }
34447c478bd9Sstevel@tonic-gate
34457c478bd9Sstevel@tonic-gate
34467c478bd9Sstevel@tonic-gate /*
34477c478bd9Sstevel@tonic-gate * ibnex_pseudo_initnodes()
34487c478bd9Sstevel@tonic-gate * This routine is specific to pseudo node information handling
34497c478bd9Sstevel@tonic-gate * Creates a ibnex_node_data_t all pseudo nodes children of ibnex
34507c478bd9Sstevel@tonic-gate */
34517c478bd9Sstevel@tonic-gate void
ibnex_pseudo_initnodes()34527c478bd9Sstevel@tonic-gate ibnex_pseudo_initnodes()
34537c478bd9Sstevel@tonic-gate {
34547c478bd9Sstevel@tonic-gate int pnam_len, len;
34557c478bd9Sstevel@tonic-gate ibnex_node_data_t *nodep;
34567c478bd9Sstevel@tonic-gate struct hwc_spec *list, *spec;
34577c478bd9Sstevel@tonic-gate char *node_addr, *temp, *unit_addr;
34589d3d2ed0Shiremath char *node_type;
34597c478bd9Sstevel@tonic-gate
34607c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tpseudo_initnodes");
34617c478bd9Sstevel@tonic-gate
34627c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
34637c478bd9Sstevel@tonic-gate /*
34647c478bd9Sstevel@tonic-gate * get a list of all "pseudo" children of "ib".
34657c478bd9Sstevel@tonic-gate * for these children initialize/allocate an internal
34667c478bd9Sstevel@tonic-gate * ibnex_node_data_t.
34677c478bd9Sstevel@tonic-gate */
34687c478bd9Sstevel@tonic-gate list = hwc_get_child_spec(ibnex.ibnex_dip, (major_t)-1);
34697c478bd9Sstevel@tonic-gate for (spec = list; spec != NULL; spec = spec->hwc_next) {
34707c478bd9Sstevel@tonic-gate if (spec->hwc_devi_sys_prop_ptr == NULL)
34717c478bd9Sstevel@tonic-gate continue;
34727c478bd9Sstevel@tonic-gate
34739d3d2ed0Shiremath /* Check "ib-node-type" property for IOC .conf */
34749d3d2ed0Shiremath node_type = ibnex_lookup_named_prop(
34759d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "ib-node-type");
34769d3d2ed0Shiremath
34777c478bd9Sstevel@tonic-gate /* "unit-address" property should be present */
34789d3d2ed0Shiremath temp = ibnex_lookup_named_prop(
34799d3d2ed0Shiremath spec->hwc_devi_sys_prop_ptr, "unit-address");
34807c478bd9Sstevel@tonic-gate if (temp == NULL)
34817c478bd9Sstevel@tonic-gate continue;
34827c478bd9Sstevel@tonic-gate
34837c478bd9Sstevel@tonic-gate pnam_len = strlen(spec->hwc_devi_name) + strlen(temp) + 2;
34847c478bd9Sstevel@tonic-gate
34857c478bd9Sstevel@tonic-gate node_addr = kmem_zalloc(pnam_len, KM_SLEEP);
34867c478bd9Sstevel@tonic-gate
34877c478bd9Sstevel@tonic-gate (void) snprintf(node_addr,
34887c478bd9Sstevel@tonic-gate pnam_len, "%s,%s", spec->hwc_devi_name, temp);
34897c478bd9Sstevel@tonic-gate
34907c478bd9Sstevel@tonic-gate nodep = ibnex_is_node_data_present(
34917c478bd9Sstevel@tonic-gate IBNEX_PSEUDO_NODE, (void *)node_addr, 0, 0);
34927c478bd9Sstevel@tonic-gate
34937c478bd9Sstevel@tonic-gate if (nodep) {
34947c478bd9Sstevel@tonic-gate kmem_free(node_addr, pnam_len);
34957c478bd9Sstevel@tonic-gate continue;
34967c478bd9Sstevel@tonic-gate }
34977c478bd9Sstevel@tonic-gate
34987c478bd9Sstevel@tonic-gate nodep = ibnex_init_child_nodedata(IBNEX_PSEUDO_NODE,
34997c478bd9Sstevel@tonic-gate (void *)spec->hwc_devi_name, 0, 0);
35007c478bd9Sstevel@tonic-gate
35017c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_node_addr = node_addr;
35027c478bd9Sstevel@tonic-gate (void) snprintf(nodep->node_data.
35037c478bd9Sstevel@tonic-gate pseudo_node.pseudo_node_addr, pnam_len, "%s", node_addr);
35047c478bd9Sstevel@tonic-gate
35057c478bd9Sstevel@tonic-gate len = strlen(temp) + 1;
35067c478bd9Sstevel@tonic-gate unit_addr = (char *)kmem_alloc(len, KM_SLEEP);
35077c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr = unit_addr;
35087c478bd9Sstevel@tonic-gate (void) snprintf(unit_addr, len, "%s", temp);
35097c478bd9Sstevel@tonic-gate nodep->node_data.pseudo_node.pseudo_unit_addr_len = len;
35107c478bd9Sstevel@tonic-gate
35119d3d2ed0Shiremath if (node_type && strcmp(node_type, "merge") == 0)
35129d3d2ed0Shiremath nodep->node_data.pseudo_node.pseudo_merge_node = 1;
35139d3d2ed0Shiremath
35147c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L3("ibnex", "\tpseudo_initnodes: unit addr = %s"
35157c478bd9Sstevel@tonic-gate " : drv name = %s", unit_addr, spec->hwc_devi_name);
35167c478bd9Sstevel@tonic-gate }
35177c478bd9Sstevel@tonic-gate hwc_free_spec_list(list);
35187c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
35197c478bd9Sstevel@tonic-gate }
35207c478bd9Sstevel@tonic-gate
35217c478bd9Sstevel@tonic-gate
35227c478bd9Sstevel@tonic-gate /*
35237c478bd9Sstevel@tonic-gate * ibnex_init_child_nodedata()
35247c478bd9Sstevel@tonic-gate *
35257c478bd9Sstevel@tonic-gate * Allocate memory for the parent private data for device node
35267c478bd9Sstevel@tonic-gate * Initializes the parent private child device node data.
35277c478bd9Sstevel@tonic-gate * Returns pointer to the parent private data
35287c478bd9Sstevel@tonic-gate */
35297c478bd9Sstevel@tonic-gate static ibnex_node_data_t *
ibnex_init_child_nodedata(ibnex_node_type_t node_type,void * attr,int index,ib_pkey_t pkey)35307c478bd9Sstevel@tonic-gate ibnex_init_child_nodedata(ibnex_node_type_t node_type, void *attr, int index,
35317c478bd9Sstevel@tonic-gate ib_pkey_t pkey)
35327c478bd9Sstevel@tonic-gate {
35337c478bd9Sstevel@tonic-gate char *devi_name;
35347c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info;
35357c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_node;
35367c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
35377c478bd9Sstevel@tonic-gate ib_dm_ioc_ctrl_profile_t *ioc_profile;
35387c478bd9Sstevel@tonic-gate
35397c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
35407c478bd9Sstevel@tonic-gate
35417c478bd9Sstevel@tonic-gate node_data = kmem_zalloc(sizeof (ibnex_node_data_t), KM_SLEEP);
354200a3eaf3SRamaswamy Tummala node_data->node_ap_state = IBNEX_NODE_AP_CONFIGURED;
35437c478bd9Sstevel@tonic-gate node_data->node_state = IBNEX_CFGADM_CONFIGURING;
35447c478bd9Sstevel@tonic-gate node_data->node_type = node_type;
35457c478bd9Sstevel@tonic-gate
35467c478bd9Sstevel@tonic-gate if (node_type == IBNEX_IOC_NODE) {
35477c478bd9Sstevel@tonic-gate ioc_info = (ibdm_ioc_info_t *)attr;
35487c478bd9Sstevel@tonic-gate ioc_profile = &ioc_info->ioc_profile;
35497c478bd9Sstevel@tonic-gate ioc_node = &node_data->node_data.ioc_node;
35507c478bd9Sstevel@tonic-gate
35517c478bd9Sstevel@tonic-gate ioc_node->iou_guid = ioc_info->ioc_iou_guid;
35527c478bd9Sstevel@tonic-gate ioc_node->ioc_guid = ioc_profile->ioc_guid;
35537c478bd9Sstevel@tonic-gate (void) strncpy(ioc_node->ioc_id_string,
35547c478bd9Sstevel@tonic-gate (char *)ioc_profile->ioc_id_string,
35557c478bd9Sstevel@tonic-gate IB_DM_IOC_ID_STRING_LEN);
35567c478bd9Sstevel@tonic-gate ioc_node->ioc_ngids = ioc_info->ioc_nportgids;
35577c478bd9Sstevel@tonic-gate
35587c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_ioc_node_head;
35597c478bd9Sstevel@tonic-gate node_data->node_prev = NULL;
35607c478bd9Sstevel@tonic-gate if (ibnex.ibnex_ioc_node_head)
35617c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head->node_prev = node_data;
35627c478bd9Sstevel@tonic-gate ibnex.ibnex_ioc_node_head = node_data;
35637c478bd9Sstevel@tonic-gate } else if (node_type == IBNEX_PSEUDO_NODE) {
35647c478bd9Sstevel@tonic-gate devi_name = (char *)attr;
35657c478bd9Sstevel@tonic-gate node_data->node_data.pseudo_node.pseudo_devi_name =
35667c478bd9Sstevel@tonic-gate kmem_zalloc(strlen(devi_name) + 1, KM_SLEEP);
35677c478bd9Sstevel@tonic-gate (void) strncpy(node_data->node_data.pseudo_node.
35687c478bd9Sstevel@tonic-gate pseudo_devi_name, devi_name, strlen(devi_name));
35697c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_pseudo_node_head;
35707c478bd9Sstevel@tonic-gate node_data->node_prev = NULL;
35717c478bd9Sstevel@tonic-gate if (ibnex.ibnex_pseudo_node_head)
35727c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head->node_prev = node_data;
35737c478bd9Sstevel@tonic-gate ibnex.ibnex_pseudo_node_head = node_data;
35747c478bd9Sstevel@tonic-gate } else {
35757c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_hcaguid =
35767c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_hca_guid;
35777c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_guid =
35787c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_guid;
35797c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_num =
35807c478bd9Sstevel@tonic-gate ((ibdm_port_attr_t *)attr)->pa_port_num;
35817c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_commsvc_idx = index;
35827c478bd9Sstevel@tonic-gate node_data->node_data.port_node.port_pkey = pkey;
35837c478bd9Sstevel@tonic-gate
35847c478bd9Sstevel@tonic-gate node_data->node_next = ibnex.ibnex_port_node_head;
35857c478bd9Sstevel@tonic-gate node_data->node_prev = NULL;
35867c478bd9Sstevel@tonic-gate if (ibnex.ibnex_port_node_head)
35877c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head->node_prev = node_data;
35887c478bd9Sstevel@tonic-gate ibnex.ibnex_port_node_head = node_data;
35897c478bd9Sstevel@tonic-gate }
35907c478bd9Sstevel@tonic-gate return (node_data);
35917c478bd9Sstevel@tonic-gate }
35927c478bd9Sstevel@tonic-gate
35937c478bd9Sstevel@tonic-gate static int
ibnex_get_eventcookie(dev_info_t * dip,dev_info_t * rdip,char * eventname,ddi_eventcookie_t * cookie)35947c478bd9Sstevel@tonic-gate ibnex_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
35957c478bd9Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *cookie)
35967c478bd9Sstevel@tonic-gate {
35977c478bd9Sstevel@tonic-gate int rc;
35987c478bd9Sstevel@tonic-gate
35997c478bd9Sstevel@tonic-gate
36007c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_get_eventcookie(%p, %p, %s, 0x%X)",
36017c478bd9Sstevel@tonic-gate dip, rdip, eventname, cookie);
36027c478bd9Sstevel@tonic-gate
36037c478bd9Sstevel@tonic-gate rc = ndi_event_retrieve_cookie(ibnex.ibnex_ndi_event_hdl,
36047c478bd9Sstevel@tonic-gate rdip, eventname, cookie, NDI_EVENT_NOPASS);
36057c478bd9Sstevel@tonic-gate if (rc == NDI_SUCCESS) {
36067c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
36077c478bd9Sstevel@tonic-gate ibnex.ibnex_prop_update_evt_cookie = *cookie;
36087c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
36097c478bd9Sstevel@tonic-gate }
36107c478bd9Sstevel@tonic-gate
36117c478bd9Sstevel@tonic-gate return (rc);
36127c478bd9Sstevel@tonic-gate }
36137c478bd9Sstevel@tonic-gate
36147c478bd9Sstevel@tonic-gate static int
ibnex_add_eventcall(dev_info_t * dip,dev_info_t * rdip,ddi_eventcookie_t cookie,void (* callback)(dev_info_t * dip,ddi_eventcookie_t cookie,void * arg,void * bus_impldata),void * arg,ddi_callback_id_t * cb_id)36157c478bd9Sstevel@tonic-gate ibnex_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
36167c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void (*callback)(dev_info_t *dip,
36177c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *arg, void *bus_impldata),
36187c478bd9Sstevel@tonic-gate void *arg, ddi_callback_id_t *cb_id)
36197c478bd9Sstevel@tonic-gate {
36207c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
36217c478bd9Sstevel@tonic-gate "ibnex_add_eventcall(%p, %p, 0x%X, %p, %p, %p)",
36227c478bd9Sstevel@tonic-gate dip, rdip, cookie, callback, arg, cb_id);
36237c478bd9Sstevel@tonic-gate
36247c478bd9Sstevel@tonic-gate return (ndi_event_add_callback(ibnex.ibnex_ndi_event_hdl,
36257c478bd9Sstevel@tonic-gate rdip, cookie, callback, arg, NDI_SLEEP, cb_id));
36267c478bd9Sstevel@tonic-gate }
36277c478bd9Sstevel@tonic-gate
36287c478bd9Sstevel@tonic-gate static int
ibnex_remove_eventcall(dev_info_t * dip,ddi_callback_id_t cb_id)36297c478bd9Sstevel@tonic-gate ibnex_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
36307c478bd9Sstevel@tonic-gate {
36317c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_remove_eventcall(%p, 0x%X)",
36327c478bd9Sstevel@tonic-gate dip, cb_id);
36337c478bd9Sstevel@tonic-gate
36347c478bd9Sstevel@tonic-gate return (ndi_event_remove_callback(ibnex.ibnex_ndi_event_hdl,
36357c478bd9Sstevel@tonic-gate cb_id));
36367c478bd9Sstevel@tonic-gate }
36377c478bd9Sstevel@tonic-gate
36387c478bd9Sstevel@tonic-gate static int
ibnex_post_event(dev_info_t * dip,dev_info_t * rdip,ddi_eventcookie_t cookie,void * bus_impldata)36397c478bd9Sstevel@tonic-gate ibnex_post_event(dev_info_t *dip, dev_info_t *rdip,
36407c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata)
36417c478bd9Sstevel@tonic-gate {
36427c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "ibnex_post_event(%p, %p, 0x%X, %p)",
36437c478bd9Sstevel@tonic-gate dip, rdip, cookie, bus_impldata);
36447c478bd9Sstevel@tonic-gate
36457c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(ibnex.ibnex_ndi_event_hdl, rdip,
36467c478bd9Sstevel@tonic-gate cookie, bus_impldata));
36477c478bd9Sstevel@tonic-gate }
36487c478bd9Sstevel@tonic-gate
36497c478bd9Sstevel@tonic-gate /*
36507c478bd9Sstevel@tonic-gate * ibnex_reprobe_ioc_dev()
36517c478bd9Sstevel@tonic-gate *
36527c478bd9Sstevel@tonic-gate * This could be called as a result of ibt_reprobe_dev request or
36537c478bd9Sstevel@tonic-gate * cfgadm command. The function is called from a taskq in case of
36547c478bd9Sstevel@tonic-gate * ibt_reprobe_dev and from user context for cfgadm command.
36557c478bd9Sstevel@tonic-gate *
36567c478bd9Sstevel@tonic-gate * This function reprobes the properties for one IOC dip.
36577c478bd9Sstevel@tonic-gate *
36587c478bd9Sstevel@tonic-gate * node_reprobe_state should be set before calling this function.
36597c478bd9Sstevel@tonic-gate */
36607c478bd9Sstevel@tonic-gate void
ibnex_reprobe_ioc_dev(void * arg)36617c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(void *arg)
36627c478bd9Sstevel@tonic-gate {
36637c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg;
36647c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
36657c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc_data;
36667c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info;
36677c478bd9Sstevel@tonic-gate
36687c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */
36697c478bd9Sstevel@tonic-gate ASSERT(dip != NULL);
36707c478bd9Sstevel@tonic-gate
36717c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip);
36727c478bd9Sstevel@tonic-gate ASSERT(node_data);
36737c478bd9Sstevel@tonic-gate
36747c478bd9Sstevel@tonic-gate if (node_data->node_dip == NULL) {
36757c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "reprobe for unconfigured dip");
36767c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
36777c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0);
36787c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
36797c478bd9Sstevel@tonic-gate return;
36807c478bd9Sstevel@tonic-gate }
36817c478bd9Sstevel@tonic-gate ioc_data = &(node_data->node_data.ioc_node);
36827c478bd9Sstevel@tonic-gate
36837c478bd9Sstevel@tonic-gate /* Reprobe the IOC */
36847c478bd9Sstevel@tonic-gate ioc_info = ibdm_ibnex_probe_ioc(ioc_data->iou_guid, ioc_data->ioc_guid,
36857c478bd9Sstevel@tonic-gate 1);
36867c478bd9Sstevel@tonic-gate if (ioc_info == NULL) {
36877c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex", "Null ioc_info from reprobe");
36887c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
36897c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 1);
36907c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
36917c478bd9Sstevel@tonic-gate return;
36927c478bd9Sstevel@tonic-gate }
36937c478bd9Sstevel@tonic-gate
36947c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
36957c478bd9Sstevel@tonic-gate if (node_data->node_dip)
36967c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info);
36977c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0);
36987c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
36997c478bd9Sstevel@tonic-gate
37007c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc_info);
37017c478bd9Sstevel@tonic-gate }
37027c478bd9Sstevel@tonic-gate
37037c478bd9Sstevel@tonic-gate /*
37047c478bd9Sstevel@tonic-gate * ibnex_reprobe_all()
37057c478bd9Sstevel@tonic-gate *
37067c478bd9Sstevel@tonic-gate * This could be called as a result of cfgadm command. The function
37077c478bd9Sstevel@tonic-gate * is called from user context.
37087c478bd9Sstevel@tonic-gate *
37097c478bd9Sstevel@tonic-gate * This function reprobes the properties for all IOC dips.
37107c478bd9Sstevel@tonic-gate *
37117c478bd9Sstevel@tonic-gate * ibnex_reprobe_state should be set before calling this function.
37127c478bd9Sstevel@tonic-gate */
37137c478bd9Sstevel@tonic-gate void
ibnex_reprobe_ioc_all()37147c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_all()
37157c478bd9Sstevel@tonic-gate {
37167c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
37177c478bd9Sstevel@tonic-gate ibdm_ioc_info_t *ioc_info_list, *ioc;
37187c478bd9Sstevel@tonic-gate
37197c478bd9Sstevel@tonic-gate /* ASSERT(NO_LOCKS_HELD); */
37207c478bd9Sstevel@tonic-gate
37217c478bd9Sstevel@tonic-gate /* Sweep the fabric */
37227c478bd9Sstevel@tonic-gate ioc = ioc_info_list = ibdm_ibnex_get_ioc_list(
37237c478bd9Sstevel@tonic-gate IBDM_IBNEX_REPROBE_ALL);
37247c478bd9Sstevel@tonic-gate if (ioc_info_list == NULL) {
37257c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
37267c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all();
37277c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
37287c478bd9Sstevel@tonic-gate return;
37297c478bd9Sstevel@tonic-gate }
37307c478bd9Sstevel@tonic-gate
37317c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
37327c478bd9Sstevel@tonic-gate while (ioc_info_list) {
37337c478bd9Sstevel@tonic-gate if ((node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
37347c478bd9Sstevel@tonic-gate ioc_info_list, 0, 0)) != NULL &&
37357c478bd9Sstevel@tonic-gate node_data->node_dip != NULL) {
37367c478bd9Sstevel@tonic-gate ibnex_update_prop(node_data, ioc_info_list);
37377c478bd9Sstevel@tonic-gate }
37387c478bd9Sstevel@tonic-gate ioc_info_list = ioc_info_list->ioc_next;
37397c478bd9Sstevel@tonic-gate }
37407c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_all();
37417c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
37427c478bd9Sstevel@tonic-gate
37437c478bd9Sstevel@tonic-gate ibdm_ibnex_free_ioc_list(ioc);
37447c478bd9Sstevel@tonic-gate }
37457c478bd9Sstevel@tonic-gate
37467c478bd9Sstevel@tonic-gate /*
37477c478bd9Sstevel@tonic-gate * Update the properties, if it has modified and notify IBTF client.
37487c478bd9Sstevel@tonic-gate */
37497c478bd9Sstevel@tonic-gate static void
ibnex_update_prop(ibnex_node_data_t * node_data,ibdm_ioc_info_t * ioc_info)37507c478bd9Sstevel@tonic-gate ibnex_update_prop(ibnex_node_data_t *node_data, ibdm_ioc_info_t *ioc_info)
37517c478bd9Sstevel@tonic-gate {
37527c478bd9Sstevel@tonic-gate ibt_prop_update_payload_t evt_data;
37537c478bd9Sstevel@tonic-gate dev_info_t *dip = node_data->node_dip;
37547c478bd9Sstevel@tonic-gate ddi_eventcookie_t evt_cookie;
37557c478bd9Sstevel@tonic-gate ibnex_ioc_node_t *ioc;
37567c478bd9Sstevel@tonic-gate
37577c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
37587c478bd9Sstevel@tonic-gate
37597c478bd9Sstevel@tonic-gate ASSERT(dip != NULL);
37607c478bd9Sstevel@tonic-gate
37617c478bd9Sstevel@tonic-gate ioc = &node_data->node_data.ioc_node;
37627c478bd9Sstevel@tonic-gate
37637c478bd9Sstevel@tonic-gate evt_data = ioc_info->ioc_info_updated;
37647c478bd9Sstevel@tonic-gate evt_cookie = ibnex.ibnex_prop_update_evt_cookie;
37657c478bd9Sstevel@tonic-gate
37667c478bd9Sstevel@tonic-gate /*
37677c478bd9Sstevel@tonic-gate * For a disconnected IOC :
37687c478bd9Sstevel@tonic-gate * Store the ioc_profile for supplying cfgadm info
37697c478bd9Sstevel@tonic-gate * ibdm maintains no info of disconnected IOC
37707c478bd9Sstevel@tonic-gate *
37717c478bd9Sstevel@tonic-gate * For reconnected IOC :
37727c478bd9Sstevel@tonic-gate * ibdm has info of previous service entries
37737c478bd9Sstevel@tonic-gate * ioc_profile maintained by ibnexus is used to
37747c478bd9Sstevel@tonic-gate * update ib_srv_prop_updated.
37757c478bd9Sstevel@tonic-gate * Free the ibnex maintained ioc_profile
37767c478bd9Sstevel@tonic-gate */
37777c478bd9Sstevel@tonic-gate if (ioc_info->ioc_nportgids == 0) {
37787c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
37797c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC disconnected");
37807c478bd9Sstevel@tonic-gate ioc->ioc_profile = (ib_dm_ioc_ctrl_profile_t *)kmem_zalloc(
37817c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t), KM_SLEEP);
37827c478bd9Sstevel@tonic-gate bcopy(&ioc_info->ioc_profile, ioc->ioc_profile,
37837c478bd9Sstevel@tonic-gate sizeof (ib_dm_ioc_ctrl_profile_t));
37847c478bd9Sstevel@tonic-gate
37857c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs++;
37867c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_nportgids != 0 && ioc->ioc_ngids == 0 &&
37877c478bd9Sstevel@tonic-gate ioc->ioc_profile != NULL) {
37887c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
37897c478bd9Sstevel@tonic-gate "\tupdate_prop: IOC reconnected");
37907c478bd9Sstevel@tonic-gate if (ioc->ioc_profile->ioc_service_entries !=
37917c478bd9Sstevel@tonic-gate ioc_info->ioc_profile.ioc_service_entries)
37927c478bd9Sstevel@tonic-gate evt_data.ib_srv_prop_updated = 1;
37937c478bd9Sstevel@tonic-gate
37947c478bd9Sstevel@tonic-gate ibnex.ibnex_num_disconnect_iocs--;
37957c478bd9Sstevel@tonic-gate kmem_free(ioc->ioc_profile, sizeof (ib_dm_ioc_ctrl_profile_t));
37967c478bd9Sstevel@tonic-gate ioc->ioc_profile = NULL;
37977c478bd9Sstevel@tonic-gate }
37987c478bd9Sstevel@tonic-gate
37997c478bd9Sstevel@tonic-gate /* Update the properties that have changed */
38007c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
38017c478bd9Sstevel@tonic-gate if (evt_data.ib_gid_prop_updated) {
38027c478bd9Sstevel@tonic-gate if (ibnex_create_ioc_portgid_prop(dip, ioc_info) !=
38037c478bd9Sstevel@tonic-gate IBNEX_SUCCESS) {
38047c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
38057c478bd9Sstevel@tonic-gate return;
38067c478bd9Sstevel@tonic-gate }
38077c478bd9Sstevel@tonic-gate }
38087c478bd9Sstevel@tonic-gate if (evt_data.ib_srv_prop_updated) {
38097c478bd9Sstevel@tonic-gate if (ioc_info->ioc_profile.ioc_service_entries != 0 &&
38107c478bd9Sstevel@tonic-gate (ibnex_create_ioc_srv_props(dip, ioc_info) !=
38117c478bd9Sstevel@tonic-gate IBNEX_SUCCESS)) {
38127c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
38137c478bd9Sstevel@tonic-gate return;
38147c478bd9Sstevel@tonic-gate } else if (ioc_info->ioc_profile.ioc_service_entries == 0) {
38157c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
38167c478bd9Sstevel@tonic-gate "service-id");
38177c478bd9Sstevel@tonic-gate (void) ndi_prop_remove(DDI_DEV_T_NONE, dip,
38187c478bd9Sstevel@tonic-gate "service-name");
38197c478bd9Sstevel@tonic-gate }
38207c478bd9Sstevel@tonic-gate }
38217c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
38227c478bd9Sstevel@tonic-gate ioc->ioc_ngids = ioc_info->ioc_nportgids;
38237c478bd9Sstevel@tonic-gate
38247c478bd9Sstevel@tonic-gate /*
38257c478bd9Sstevel@tonic-gate * Post an event if :
38267c478bd9Sstevel@tonic-gate * 1. Properites have changed or NOTIFY_ALWAYS is set.
38277c478bd9Sstevel@tonic-gate * 2. child dip is configured and a valid cookie for
38287c478bd9Sstevel@tonic-gate * IB_PROP_UPDATE_EVENT.
38297c478bd9Sstevel@tonic-gate */
38307c478bd9Sstevel@tonic-gate if ((evt_data.ib_prop_updated != 0 ||
38317c478bd9Sstevel@tonic-gate (node_data->node_reprobe_state &
38327c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)) &&
38337c478bd9Sstevel@tonic-gate ((node_data->node_state == IBNEX_CFGADM_CONFIGURED) &&
38347c478bd9Sstevel@tonic-gate (evt_cookie != NULL))) {
38357c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
38367c478bd9Sstevel@tonic-gate
38377c478bd9Sstevel@tonic-gate if (ndi_post_event(ibnex.ibnex_dip, dip,
38387c478bd9Sstevel@tonic-gate evt_cookie, &evt_data) != NDI_SUCCESS)
38397c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L2("ibnex",
38407c478bd9Sstevel@tonic-gate "\tndi_post_event failed\n");
38417c478bd9Sstevel@tonic-gate
38427c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
38437c478bd9Sstevel@tonic-gate }
38447c478bd9Sstevel@tonic-gate
38457c478bd9Sstevel@tonic-gate /*
38467c478bd9Sstevel@tonic-gate * Cleanup node_reprobe_state, for ibt_reprobe_dev
38477c478bd9Sstevel@tonic-gate * requests, when reprobe all / node reprobe is in
38487c478bd9Sstevel@tonic-gate * progress. ibnex_reprobe_ioc_dev is not called
38497c478bd9Sstevel@tonic-gate * in this case.
38507c478bd9Sstevel@tonic-gate */
38517c478bd9Sstevel@tonic-gate if (node_data->node_reprobe_state ==
38527c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS)
38537c478bd9Sstevel@tonic-gate ibnex_wakeup_reprobe_ioc(node_data, 0);
38547c478bd9Sstevel@tonic-gate }
38557c478bd9Sstevel@tonic-gate
38567c478bd9Sstevel@tonic-gate static ibnex_rval_t
ibnex_unique_svcname(char * svcname)38577c478bd9Sstevel@tonic-gate ibnex_unique_svcname(char *svcname)
38587c478bd9Sstevel@tonic-gate {
38597c478bd9Sstevel@tonic-gate int i;
38607c478bd9Sstevel@tonic-gate
38617c478bd9Sstevel@tonic-gate /* Check Port Services */
38627c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_num_comm_svcs; i++)
38637c478bd9Sstevel@tonic-gate if (ibnex.ibnex_comm_svc_names[i] && strncmp(svcname,
38647c478bd9Sstevel@tonic-gate ibnex.ibnex_comm_svc_names[i], 4) == 0)
38657c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
38667c478bd9Sstevel@tonic-gate
38677c478bd9Sstevel@tonic-gate /* Check VPPA Services */
38687c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nvppa_comm_svcs; i++)
38697c478bd9Sstevel@tonic-gate if (ibnex.ibnex_vppa_comm_svc_names[i] && strncmp(svcname,
38707c478bd9Sstevel@tonic-gate ibnex.ibnex_vppa_comm_svc_names[i], 4) == 0)
38717c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
38727c478bd9Sstevel@tonic-gate
38737c478bd9Sstevel@tonic-gate /* Check HCA_SVC Services */
38747c478bd9Sstevel@tonic-gate for (i = 0; i < ibnex.ibnex_nhcasvc_comm_svcs; i++)
38757c478bd9Sstevel@tonic-gate if (ibnex.ibnex_hcasvc_comm_svc_names[i] && strncmp(svcname,
38767c478bd9Sstevel@tonic-gate ibnex.ibnex_hcasvc_comm_svc_names[i], 4) == 0)
38777c478bd9Sstevel@tonic-gate return (IBNEX_FAILURE);
38787c478bd9Sstevel@tonic-gate
38797c478bd9Sstevel@tonic-gate return (IBNEX_SUCCESS);
38807c478bd9Sstevel@tonic-gate }
38817c478bd9Sstevel@tonic-gate
38827c478bd9Sstevel@tonic-gate static void
ibnex_handle_reprobe_dev(void * arg)38837c478bd9Sstevel@tonic-gate ibnex_handle_reprobe_dev(void *arg)
38847c478bd9Sstevel@tonic-gate {
38857c478bd9Sstevel@tonic-gate dev_info_t *dip = (dev_info_t *)arg;
38867c478bd9Sstevel@tonic-gate ibnex_node_data_t *node_data;
38877c478bd9Sstevel@tonic-gate
38887c478bd9Sstevel@tonic-gate ASSERT(dip != NULL);
38897c478bd9Sstevel@tonic-gate node_data = ddi_get_parent_data(dip);
38907c478bd9Sstevel@tonic-gate ASSERT(node_data);
38917c478bd9Sstevel@tonic-gate
38927c478bd9Sstevel@tonic-gate /*
38937c478bd9Sstevel@tonic-gate * Return success if:
38947c478bd9Sstevel@tonic-gate * 1. Reprobe for all nodes are in progress
38957c478bd9Sstevel@tonic-gate * 2. Reprobe for this node is in progress.
38967c478bd9Sstevel@tonic-gate * The reprobe in progress will complete eventually and
38977c478bd9Sstevel@tonic-gate * update the properties, if required.
38987c478bd9Sstevel@tonic-gate */
38997c478bd9Sstevel@tonic-gate mutex_enter(&ibnex.ibnex_mutex);
39007c478bd9Sstevel@tonic-gate if (ibnex.ibnex_reprobe_state != 0 ||
39017c478bd9Sstevel@tonic-gate node_data->node_reprobe_state != 0) {
39027c478bd9Sstevel@tonic-gate /*
39037c478bd9Sstevel@tonic-gate * Setting NOTIFY_ALWAYS to ensure that
39047c478bd9Sstevel@tonic-gate * DDI event is delivered always for
39057c478bd9Sstevel@tonic-gate * ibt_reprobe_dev
39067c478bd9Sstevel@tonic-gate */
39077c478bd9Sstevel@tonic-gate node_data->node_reprobe_state |=
39087c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
39097c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
39107c478bd9Sstevel@tonic-gate return;
39117c478bd9Sstevel@tonic-gate }
39127c478bd9Sstevel@tonic-gate node_data->node_reprobe_state =
39137c478bd9Sstevel@tonic-gate IBNEX_NODE_REPROBE_NOTIFY_ALWAYS;
39147c478bd9Sstevel@tonic-gate mutex_exit(&ibnex.ibnex_mutex);
39157c478bd9Sstevel@tonic-gate ibnex_reprobe_ioc_dev(arg);
39167c478bd9Sstevel@tonic-gate }
39177c478bd9Sstevel@tonic-gate
39187c478bd9Sstevel@tonic-gate
39197c478bd9Sstevel@tonic-gate /*
39207c478bd9Sstevel@tonic-gate * MPxIO pathmangement routines. Currently IB nexus does not support
39217c478bd9Sstevel@tonic-gate * any kind of pathmangement. So, just return success to make MPxIO
39227c478bd9Sstevel@tonic-gate * framework happy.
39237c478bd9Sstevel@tonic-gate */
39247c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39257c478bd9Sstevel@tonic-gate static int
ib_vhci_pi_init(dev_info_t * vdip,mdi_pathinfo_t * pip,int flag)392600a3eaf3SRamaswamy Tummala ib_vhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
39277c478bd9Sstevel@tonic-gate {
392800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_init: dip %p pip %p", vdip, pip);
39297c478bd9Sstevel@tonic-gate return (MDI_SUCCESS);
39307c478bd9Sstevel@tonic-gate }
39317c478bd9Sstevel@tonic-gate
39327c478bd9Sstevel@tonic-gate
39337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39347c478bd9Sstevel@tonic-gate static int
ib_vhci_pi_uninit(dev_info_t * vdip,mdi_pathinfo_t * pip,int flag)393500a3eaf3SRamaswamy Tummala ib_vhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flag)
39367c478bd9Sstevel@tonic-gate {
393700a3eaf3SRamaswamy Tummala dev_info_t *cdip;
393800a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data;
393900a3eaf3SRamaswamy Tummala int clnt_num_pi;
394000a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tpi_uninit: dip %p pip %p", vdip, pip);
394100a3eaf3SRamaswamy Tummala
394200a3eaf3SRamaswamy Tummala if (pip == NULL)
394300a3eaf3SRamaswamy Tummala return (MDI_FAILURE);
394400a3eaf3SRamaswamy Tummala /*
394500a3eaf3SRamaswamy Tummala * Get the Client dev_info from the pathinfo.
394600a3eaf3SRamaswamy Tummala */
394700a3eaf3SRamaswamy Tummala cdip = mdi_pi_get_client(pip);
394800a3eaf3SRamaswamy Tummala if (cdip == NULL)
394900a3eaf3SRamaswamy Tummala return (MDI_FAILURE);
395000a3eaf3SRamaswamy Tummala
395100a3eaf3SRamaswamy Tummala /*
395200a3eaf3SRamaswamy Tummala * How many PIs do we have from this cdip ?
395300a3eaf3SRamaswamy Tummala */
395400a3eaf3SRamaswamy Tummala clnt_num_pi = mdi_client_get_path_count(cdip);
395500a3eaf3SRamaswamy Tummala
395600a3eaf3SRamaswamy Tummala /*
395700a3eaf3SRamaswamy Tummala * If this is the last PI that is being free'd ( called from
395800a3eaf3SRamaswamy Tummala * mdi_pi_free) we have to clean up the node data for the cdip since
395900a3eaf3SRamaswamy Tummala * the client would have been detached by mdi_devi_offline.
396000a3eaf3SRamaswamy Tummala */
396100a3eaf3SRamaswamy Tummala if (clnt_num_pi == 1) {
39621cfa752fSRamaswamy Tummala node_data = ddi_get_parent_data(cdip);
39631cfa752fSRamaswamy Tummala if (node_data == NULL)
39641cfa752fSRamaswamy Tummala return (MDI_SUCCESS);
396500a3eaf3SRamaswamy Tummala if (node_data->node_dip == cdip) {
396600a3eaf3SRamaswamy Tummala node_data->node_dip = NULL;
39671cfa752fSRamaswamy Tummala node_data->node_state = IBNEX_CFGADM_UNCONFIGURED;
396800a3eaf3SRamaswamy Tummala return (MDI_SUCCESS);
396900a3eaf3SRamaswamy Tummala }
397000a3eaf3SRamaswamy Tummala }
39717c478bd9Sstevel@tonic-gate return (MDI_SUCCESS);
39727c478bd9Sstevel@tonic-gate }
39737c478bd9Sstevel@tonic-gate
39747c478bd9Sstevel@tonic-gate
39757c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39767c478bd9Sstevel@tonic-gate static int
ib_vhci_pi_state_change(dev_info_t * vdip,mdi_pathinfo_t * pip,mdi_pathinfo_state_t state,uint32_t arg1,int arg2)397700a3eaf3SRamaswamy Tummala ib_vhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip,
39787c478bd9Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t arg1, int arg2)
39797c478bd9Sstevel@tonic-gate {
39807c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex",
398100a3eaf3SRamaswamy Tummala "\tpi_state_change: dip %p pip %p state %x", vdip, pip, state);
39827c478bd9Sstevel@tonic-gate return (MDI_SUCCESS);
39837c478bd9Sstevel@tonic-gate }
39847c478bd9Sstevel@tonic-gate
39857c478bd9Sstevel@tonic-gate
39867c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39877c478bd9Sstevel@tonic-gate static int
ib_vhci_failover(dev_info_t * dip1,dev_info_t * dip2,int arg)39887c478bd9Sstevel@tonic-gate ib_vhci_failover(dev_info_t *dip1, dev_info_t *dip2, int arg)
39897c478bd9Sstevel@tonic-gate {
39907c478bd9Sstevel@tonic-gate return (MDI_SUCCESS);
39917c478bd9Sstevel@tonic-gate }
39927c478bd9Sstevel@tonic-gate
39937c478bd9Sstevel@tonic-gate
39947c478bd9Sstevel@tonic-gate static int
ibnex_bus_power(dev_info_t * parent,void * impl_arg,pm_bus_power_op_t op,void * arg,void * result)39957c478bd9Sstevel@tonic-gate ibnex_bus_power(dev_info_t *parent, void *impl_arg,
39967c478bd9Sstevel@tonic-gate pm_bus_power_op_t op, void *arg, void *result)
39977c478bd9Sstevel@tonic-gate {
39987c478bd9Sstevel@tonic-gate
39997c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS;
40007c478bd9Sstevel@tonic-gate
40017c478bd9Sstevel@tonic-gate IBTF_DPRINTF_L4("ibnex", "\tbus_power: begin: op = %d", op);
40027c478bd9Sstevel@tonic-gate
40037c478bd9Sstevel@tonic-gate /*
40047c478bd9Sstevel@tonic-gate * Generic processing in MPxIO framework
40057c478bd9Sstevel@tonic-gate */
40067c478bd9Sstevel@tonic-gate ret = mdi_bus_power(parent, impl_arg, op, arg, result);
40077c478bd9Sstevel@tonic-gate
40087c478bd9Sstevel@tonic-gate switch (ret) {
40097c478bd9Sstevel@tonic-gate case MDI_SUCCESS:
40107c478bd9Sstevel@tonic-gate ret = DDI_SUCCESS;
40117c478bd9Sstevel@tonic-gate break;
40127c478bd9Sstevel@tonic-gate case MDI_FAILURE:
40137c478bd9Sstevel@tonic-gate ret = DDI_FAILURE;
40147c478bd9Sstevel@tonic-gate break;
40157c478bd9Sstevel@tonic-gate default:
40167c478bd9Sstevel@tonic-gate break;
40177c478bd9Sstevel@tonic-gate }
40187c478bd9Sstevel@tonic-gate
40197c478bd9Sstevel@tonic-gate return (ret);
40207c478bd9Sstevel@tonic-gate }
40219d3d2ed0Shiremath
40229d3d2ed0Shiremath
40239d3d2ed0Shiremath /*
40249d3d2ed0Shiremath * If enumerated as a child of IB Nexus / VHCI, call mdi_vhci_bus_config.
40259d3d2ed0Shiremath * ndi_devi_enter is not held during this call. mdi_vhci_bus_config()
40269d3d2ed0Shiremath * will have called ndi_busop_bus_config(), no need for the caller to call
40279d3d2ed0Shiremath * ndi_busop_bus_config() again.
40289d3d2ed0Shiremath *
40299d3d2ed0Shiremath * If enumerated as a child of HCA device, this could be a case for
40309d3d2ed0Shiremath * Sparc boot or device enumeration from PHCI, driven by MDI.
40319d3d2ed0Shiremath * Hold parent lock (ndi_devi_enter). The caller will have to call
40329d3d2ed0Shiremath * ndi_busop_bus_config() if this function returns SUCCESS.
40339d3d2ed0Shiremath *
40349d3d2ed0Shiremath * if the device name contains ":port", then it is the Sparc boot case.
40359d3d2ed0Shiremath * Handle this as before.
40369d3d2ed0Shiremath *
40379d3d2ed0Shiremath * If the device name does *not* contain the ":port", then :
40389d3d2ed0Shiremath * 1. ibdm to probe IOC
40399d3d2ed0Shiremath * 2. Create a pathinfo only if the IOC is reachable from the parent dip.
40409d3d2ed0Shiremath */
40411cfa752fSRamaswamy Tummala int
ibnex_ioc_bus_config_one(dev_info_t ** pdipp,uint_t flag,ddi_bus_config_op_t op,void * devname,dev_info_t ** child,int * need_bus_config)40429d3d2ed0Shiremath ibnex_ioc_bus_config_one(dev_info_t **pdipp, uint_t flag,
40439d3d2ed0Shiremath ddi_bus_config_op_t op, void *devname, dev_info_t **child,
40449d3d2ed0Shiremath int *need_bus_config)
40459d3d2ed0Shiremath {
4046*3fe80ca4SDan Cross int ret = DDI_FAILURE;
4047*3fe80ca4SDan Cross boolean_t enteredv;
40489d3d2ed0Shiremath dev_info_t *pdip = *pdipp;
40499d3d2ed0Shiremath ib_guid_t iou_guid, ioc_guid;
40509d3d2ed0Shiremath char *ioc_guid_str;
40519d3d2ed0Shiremath
40529d3d2ed0Shiremath
40539d3d2ed0Shiremath *need_bus_config = 1;
40549d3d2ed0Shiremath
40559d3d2ed0Shiremath if (pdip == ibnex.ibnex_dip) {
40569d3d2ed0Shiremath if (ibnex_devname_to_node_n_ioc_guids(
40579d3d2ed0Shiremath (char *)devname, &iou_guid, &ioc_guid,
40589d3d2ed0Shiremath &ioc_guid_str) != IBNEX_SUCCESS) {
40599d3d2ed0Shiremath return (ret);
40609d3d2ed0Shiremath }
40619d3d2ed0Shiremath ret = mdi_vhci_bus_config(pdip, flag, op, devname, child,
40629d3d2ed0Shiremath ioc_guid_str);
40639d3d2ed0Shiremath kmem_free(ioc_guid_str, strlen(ioc_guid_str) + 1);
40649d3d2ed0Shiremath if (ret == MDI_SUCCESS)
40659d3d2ed0Shiremath *need_bus_config = 0;
40669d3d2ed0Shiremath } else {
4067*3fe80ca4SDan Cross mdi_devi_enter(pdip, &enteredv);
40689d3d2ed0Shiremath if (strstr((char *)devname, ":port=") != NULL) {
40699d3d2ed0Shiremath ret = ibnex_config_root_iocnode(pdip, devname);
40709d3d2ed0Shiremath ASSERT(ibnex.ibnex_dip == NULL);
40719d3d2ed0Shiremath *pdipp = ibnex.ibnex_dip;
40729d3d2ed0Shiremath } else {
40739d3d2ed0Shiremath ret = ibnex_config_ioc_node(devname, pdip);
40749d3d2ed0Shiremath }
4075*3fe80ca4SDan Cross mdi_devi_exit(pdip, enteredv);
40769d3d2ed0Shiremath }
40779d3d2ed0Shiremath return (ret);
40789d3d2ed0Shiremath }
40799d3d2ed0Shiremath
40809d3d2ed0Shiremath static int
ibnex_is_merge_node(dev_info_t * child)40819d3d2ed0Shiremath ibnex_is_merge_node(dev_info_t *child)
40829d3d2ed0Shiremath {
40839d3d2ed0Shiremath char *node;
40849d3d2ed0Shiremath int ret = IBNEX_INVALID_NODE;
40859d3d2ed0Shiremath
40869d3d2ed0Shiremath if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child,
40879d3d2ed0Shiremath DDI_PROP_DONTPASS, "ib-node-type", &node) !=
40889d3d2ed0Shiremath DDI_PROP_SUCCESS) {
40899d3d2ed0Shiremath return (IBNEX_FAILURE);
40909d3d2ed0Shiremath }
40919d3d2ed0Shiremath
40929d3d2ed0Shiremath if (node != NULL && *node != 0) {
40939d3d2ed0Shiremath if (strcmp(node, "merge") == 0)
40949d3d2ed0Shiremath ret = IBNEX_SUCCESS;
40959d3d2ed0Shiremath else {
40969d3d2ed0Shiremath IBTF_DPRINTF_L4("ibnex",
40979d3d2ed0Shiremath "\tis_merge_node: ib-node-type = %s", node);
40989d3d2ed0Shiremath }
40999d3d2ed0Shiremath }
41009d3d2ed0Shiremath
41019d3d2ed0Shiremath ddi_prop_free(node);
41029d3d2ed0Shiremath return (ret);
41039d3d2ed0Shiremath }
41049d3d2ed0Shiremath
41059d3d2ed0Shiremath /*
41069d3d2ed0Shiremath * Checks if the dn_head for the driver has already
41079d3d2ed0Shiremath * initialized by the prom tree.
41089d3d2ed0Shiremath */
4109f7209cf2Spramodbg void
ibnex_hw_in_dev_tree(char * driver_name)41109d3d2ed0Shiremath ibnex_hw_in_dev_tree(char *driver_name)
41119d3d2ed0Shiremath {
41129d3d2ed0Shiremath major_t major;
41139d3d2ed0Shiremath
4114f7209cf2Spramodbg IBTF_DPRINTF_L4("ibnex", "\thw_in_dev_tree(%s)", driver_name);
4115f7209cf2Spramodbg
41169d3d2ed0Shiremath if (devnamesp == NULL)
4117f7209cf2Spramodbg return;
41189d3d2ed0Shiremath
41199d3d2ed0Shiremath major = ddi_name_to_major(driver_name);
41209d3d2ed0Shiremath if (major == -1)
4121f7209cf2Spramodbg return;
41229d3d2ed0Shiremath
4123f7209cf2Spramodbg if (devnamesp[major].dn_head != (dev_info_t *)NULL)
4124f7209cf2Spramodbg ibnex_hw_status = IBNEX_HW_IN_DEVTREE;
41259d3d2ed0Shiremath }
412600a3eaf3SRamaswamy Tummala
412700a3eaf3SRamaswamy Tummala int
ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t * ioc_info)412800a3eaf3SRamaswamy Tummala ibnex_ioc_initnode_all_pi(ibdm_ioc_info_t *ioc_info)
412900a3eaf3SRamaswamy Tummala {
413000a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list;
413100a3eaf3SRamaswamy Tummala dev_info_t *hca_dip;
413200a3eaf3SRamaswamy Tummala int rc = IBNEX_FAILURE;
413300a3eaf3SRamaswamy Tummala
413400a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
413500a3eaf3SRamaswamy Tummala /*
413600a3eaf3SRamaswamy Tummala * We return failure even if we fail for all HCAs
413700a3eaf3SRamaswamy Tummala */
413800a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list;
413900a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) {
414000a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
414100a3eaf3SRamaswamy Tummala if (ibnex_ioc_config_from_pdip(ioc_info, hca_dip, 1) ==
414200a3eaf3SRamaswamy Tummala IBNEX_SUCCESS)
414300a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS;
414400a3eaf3SRamaswamy Tummala }
414500a3eaf3SRamaswamy Tummala return (rc);
414600a3eaf3SRamaswamy Tummala }
414700a3eaf3SRamaswamy Tummala
414800a3eaf3SRamaswamy Tummala static int
ibnex_ioc_config_from_pdip(ibdm_ioc_info_t * ioc_info,dev_info_t * pdip,int pdip_reachable_checked)414900a3eaf3SRamaswamy Tummala ibnex_ioc_config_from_pdip(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip,
415000a3eaf3SRamaswamy Tummala int pdip_reachable_checked)
415100a3eaf3SRamaswamy Tummala {
415200a3eaf3SRamaswamy Tummala ibnex_node_data_t *node_data;
415300a3eaf3SRamaswamy Tummala int create_pdip = 0;
415400a3eaf3SRamaswamy Tummala int rc = IBNEX_SUCCESS;
415500a3eaf3SRamaswamy Tummala
415600a3eaf3SRamaswamy Tummala
415700a3eaf3SRamaswamy Tummala ASSERT(MUTEX_HELD(&ibnex.ibnex_mutex));
415800a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
415900a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip(%p, %p, %d)", ioc_info, pdip,
416000a3eaf3SRamaswamy Tummala pdip_reachable_checked);
416100a3eaf3SRamaswamy Tummala
416200a3eaf3SRamaswamy Tummala if (pdip_reachable_checked == 0) {
416300a3eaf3SRamaswamy Tummala if (ibnex_ioc_pi_reachable(ioc_info, pdip) == IBNEX_FAILURE) {
416400a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
416500a3eaf3SRamaswamy Tummala "/tioc_config_from_pdip: ioc %p not reachable"
416600a3eaf3SRamaswamy Tummala "from %p", ioc_info, pdip);
416700a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE);
416800a3eaf3SRamaswamy Tummala }
416900a3eaf3SRamaswamy Tummala }
417000a3eaf3SRamaswamy Tummala
417100a3eaf3SRamaswamy Tummala node_data = ibnex_is_node_data_present(IBNEX_IOC_NODE,
417200a3eaf3SRamaswamy Tummala (void *)ioc_info, 0, 0);
417300a3eaf3SRamaswamy Tummala
417400a3eaf3SRamaswamy Tummala if (node_data && node_data->node_ap_state ==
417500a3eaf3SRamaswamy Tummala IBNEX_NODE_AP_UNCONFIGURED) {
417600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
417700a3eaf3SRamaswamy Tummala "\tioc_config_from_pdip: Unconfigured node");
417800a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE);
417900a3eaf3SRamaswamy Tummala }
418000a3eaf3SRamaswamy Tummala
418100a3eaf3SRamaswamy Tummala
418200a3eaf3SRamaswamy Tummala if (node_data == NULL) {
418300a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc;
418400a3eaf3SRamaswamy Tummala
418500a3eaf3SRamaswamy Tummala create_pdip = 1;
418600a3eaf3SRamaswamy Tummala
418700a3eaf3SRamaswamy Tummala node_data = ibnex_init_child_nodedata(IBNEX_IOC_NODE,
418800a3eaf3SRamaswamy Tummala ioc_info, 0, 0);
418900a3eaf3SRamaswamy Tummala ASSERT(node_data);
419000a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node;
419100a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_guid_str, IBNEX_IOC_GUID_LEN,
419200a3eaf3SRamaswamy Tummala "%llX",
419300a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid);
419400a3eaf3SRamaswamy Tummala (void) snprintf(ioc->ioc_phci_guid, IBNEX_PHCI_GUID_LEN,
419500a3eaf3SRamaswamy Tummala "%llX,%llX",
419600a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_profile.ioc_guid,
419700a3eaf3SRamaswamy Tummala (longlong_t)ioc_info->ioc_iou_guid);
419800a3eaf3SRamaswamy Tummala } else if (ibnex_ioc_pi_exists(node_data, pdip) == IBNEX_FAILURE) {
419900a3eaf3SRamaswamy Tummala create_pdip = 1;
420000a3eaf3SRamaswamy Tummala }
420100a3eaf3SRamaswamy Tummala
420200a3eaf3SRamaswamy Tummala if (create_pdip) {
420300a3eaf3SRamaswamy Tummala rc = ibnex_ioc_initnode_pdip(node_data, ioc_info, pdip);
420400a3eaf3SRamaswamy Tummala }
420500a3eaf3SRamaswamy Tummala
420600a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_config_from_pdip ret %x",
420700a3eaf3SRamaswamy Tummala rc);
420800a3eaf3SRamaswamy Tummala return (rc);
420900a3eaf3SRamaswamy Tummala }
421000a3eaf3SRamaswamy Tummala
421100a3eaf3SRamaswamy Tummala /*
421200a3eaf3SRamaswamy Tummala * This function checks if a pathinfo has already been created
421300a3eaf3SRamaswamy Tummala * for the HCA parent. The function returns SUCCESS if a pathinfo
421400a3eaf3SRamaswamy Tummala * has already been created, FAILURE if not.
421500a3eaf3SRamaswamy Tummala */
421600a3eaf3SRamaswamy Tummala static int
ibnex_ioc_pi_exists(ibnex_node_data_t * node_data,dev_info_t * parent)421700a3eaf3SRamaswamy Tummala ibnex_ioc_pi_exists(ibnex_node_data_t *node_data, dev_info_t *parent)
421800a3eaf3SRamaswamy Tummala {
421900a3eaf3SRamaswamy Tummala int rc;
422000a3eaf3SRamaswamy Tummala ibnex_ioc_node_t *ioc;
422100a3eaf3SRamaswamy Tummala
422200a3eaf3SRamaswamy Tummala ioc = &node_data->node_data.ioc_node;
422300a3eaf3SRamaswamy Tummala if (mdi_pi_find(parent, (char *)ioc->ioc_guid_str,
422400a3eaf3SRamaswamy Tummala (char *)ioc->ioc_phci_guid) != NULL)
422500a3eaf3SRamaswamy Tummala rc = IBNEX_SUCCESS;
422600a3eaf3SRamaswamy Tummala else
422700a3eaf3SRamaswamy Tummala rc = IBNEX_FAILURE;
422800a3eaf3SRamaswamy Tummala
422900a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_created- client_guid %s, "
423000a3eaf3SRamaswamy Tummala "phci_guid %s, parent %p, rc %x",
423100a3eaf3SRamaswamy Tummala ioc->ioc_guid_str, ioc->ioc_phci_guid, parent, rc);
423200a3eaf3SRamaswamy Tummala return (rc);
423300a3eaf3SRamaswamy Tummala }
423400a3eaf3SRamaswamy Tummala
423500a3eaf3SRamaswamy Tummala static int
ibnex_ioc_pi_reachable(ibdm_ioc_info_t * ioc_info,dev_info_t * pdip)423600a3eaf3SRamaswamy Tummala ibnex_ioc_pi_reachable(ibdm_ioc_info_t *ioc_info, dev_info_t *pdip)
423700a3eaf3SRamaswamy Tummala {
423800a3eaf3SRamaswamy Tummala ibdm_hca_list_t *hca_list;
423900a3eaf3SRamaswamy Tummala dev_info_t *hca_dip;
424000a3eaf3SRamaswamy Tummala
424100a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable(%p, %p)",
424200a3eaf3SRamaswamy Tummala ioc_info, pdip);
424300a3eaf3SRamaswamy Tummala for (hca_list = ioc_info->ioc_hca_list; hca_list;
424400a3eaf3SRamaswamy Tummala hca_list = hca_list->hl_next) {
424500a3eaf3SRamaswamy Tummala hca_dip = ibtl_ibnex_hcaguid2dip(hca_list->hl_hca_guid);
424600a3eaf3SRamaswamy Tummala if (hca_dip == pdip) {
424700a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex",
424800a3eaf3SRamaswamy Tummala "\tioc_pi_reachable FAILURE");
424900a3eaf3SRamaswamy Tummala return (IBNEX_SUCCESS);
425000a3eaf3SRamaswamy Tummala }
425100a3eaf3SRamaswamy Tummala }
425200a3eaf3SRamaswamy Tummala
425300a3eaf3SRamaswamy Tummala IBTF_DPRINTF_L4("ibnex", "\tioc_pi_reachable FAILURE");
425400a3eaf3SRamaswamy Tummala return (IBNEX_FAILURE);
425500a3eaf3SRamaswamy Tummala }
4256